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 width = graphic_info[graphic].width;
1602 int height = graphic_info[graphic].height;
1603 int src_x = graphic_info[graphic].src_x;
1604 int src_y = graphic_info[graphic].src_y;
1610 if (width > WIN_XSIZE)
1612 // image width too large for window => center image horizontally
1613 src_x = (width - WIN_XSIZE) / 2;
1617 if (height > WIN_YSIZE)
1619 // image height too large for window => center image vertically
1620 src_y = (height - WIN_YSIZE) / 2;
1624 // always display title screens centered
1625 dst_x = (WIN_XSIZE - width) / 2;
1626 dst_y = (WIN_YSIZE - height) / 2;
1628 SetDrawBackgroundMask(REDRAW_ALL);
1629 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1631 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1633 if (DrawingOnBackground(dst_x, dst_y))
1634 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1636 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1638 redraw_mask = REDRAW_ALL;
1641 static void DrawTitleScreenMessage(int nr, boolean initial)
1643 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1644 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1646 if (filename == NULL)
1649 // force TITLE font on title message screen
1650 SetFontStatus(getTitleMessageGameMode(initial));
1652 // if chars *and* width set to "-1", automatically determine width
1653 if (tmi->chars == -1 && tmi->width == -1)
1654 tmi->width = viewport.window[game_status].width;
1656 // if lines *and* height set to "-1", automatically determine height
1657 if (tmi->lines == -1 && tmi->height == -1)
1658 tmi->height = viewport.window[game_status].height;
1660 // if chars set to "-1", automatically determine by text and font width
1661 if (tmi->chars == -1)
1662 tmi->chars = tmi->width / getFontWidth(tmi->font);
1664 tmi->width = tmi->chars * getFontWidth(tmi->font);
1666 // if lines set to "-1", automatically determine by text and font height
1667 if (tmi->lines == -1)
1668 tmi->lines = tmi->height / getFontHeight(tmi->font);
1670 tmi->height = tmi->lines * getFontHeight(tmi->font);
1672 // if x set to "-1", automatically determine by width and alignment
1674 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1676 // if y set to "-1", automatically determine by height and alignment
1678 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1680 SetDrawBackgroundMask(REDRAW_ALL);
1681 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1683 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1685 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1686 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1687 tmi->autowrap, tmi->centered, tmi->parse_comments);
1692 static void DrawTitleScreen(void)
1694 KeyboardAutoRepeatOff();
1696 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1699 static boolean CheckTitleScreen(boolean levelset_has_changed)
1701 static boolean show_title_initial = TRUE;
1702 boolean show_titlescreen = FALSE;
1704 // needed to be able to skip title screen, if no image or message defined
1705 InitializeTitleControls(show_title_initial);
1707 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1708 show_titlescreen = TRUE;
1710 // show initial title images and messages only once at program start
1711 show_title_initial = FALSE;
1713 return (show_titlescreen && num_title_screens > 0);
1716 void DrawMainMenu(void)
1718 static LevelDirTree *leveldir_last_valid = NULL;
1719 boolean levelset_has_changed = FALSE;
1720 int fade_mask = REDRAW_FIELD;
1722 LimitScreenUpdates(FALSE);
1724 FadeSetLeaveScreen();
1726 // do not fade out here -- function may continue and fade on editor screen
1729 FadeMenuSoundsAndMusic();
1731 ExpireSoundLoops(FALSE);
1733 KeyboardAutoRepeatOn();
1735 audio.sound_deactivated = FALSE;
1739 // needed if last screen was the playing screen, invoked from level editor
1740 if (level_editor_test_game)
1742 CloseDoor(DOOR_CLOSE_ALL);
1744 SetGameStatus(GAME_MODE_EDITOR);
1751 // needed if last screen was the playing screen, invoked from hall of fame
1752 if (score_info_tape_play)
1754 CloseDoor(DOOR_CLOSE_ALL);
1756 SetGameStatus(GAME_MODE_SCOREINFO);
1758 DrawScoreInfo(scores.last_entry_nr);
1763 // reset flag to continue playing next level from hall of fame
1764 scores.continue_playing = FALSE;
1766 // leveldir_current may be invalid (level group, parent link, node copy)
1767 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1769 if (leveldir_current != leveldir_last_valid)
1771 // level setup config may have been loaded to "last played" tree node copy,
1772 // but "leveldir_current" now points to the "original" level set tree node,
1773 // in which case "handicap_level" may still default to the first level
1774 LoadLevelSetup_SeriesInfo();
1776 UpdateLastPlayedLevels_TreeInfo();
1778 levelset_has_changed = TRUE;
1781 // store valid level series information
1782 leveldir_last_valid = leveldir_current;
1784 // needed if last screen (level choice) changed graphics, sounds or music
1785 ReloadCustomArtwork(0);
1787 if (CheckTitleScreen(levelset_has_changed))
1789 SetGameStatus(GAME_MODE_TITLE);
1796 if (redraw_mask & REDRAW_ALL)
1797 fade_mask = REDRAW_ALL;
1800 fade_mask = REDRAW_ALL;
1804 // needed if different viewport properties defined for menues
1805 ChangeViewportPropertiesIfNeeded();
1807 SetDrawtoField(DRAW_TO_BACKBUFFER);
1809 // level_nr may have been set to value over handicap with level editor
1810 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1811 level_nr = leveldir_current->handicap_level;
1813 LoadLevel(level_nr);
1814 LoadScore(level_nr);
1816 SaveLevelSetup_SeriesInfo();
1818 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1819 SetDrawDeactivationMask(REDRAW_NONE);
1820 SetDrawBackgroundMask(REDRAW_FIELD);
1822 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1825 if (fade_mask == REDRAW_ALL)
1826 RedrawGlobalBorder();
1831 InitializeMainControls();
1833 DrawCursorAndText_Main(-1, FALSE, FALSE);
1834 DrawPreviewLevelInitial();
1835 DrawNetworkPlayers();
1837 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1840 if (TAPE_IS_EMPTY(tape))
1842 DrawCompleteVideoDisplay();
1844 PlayMenuSoundsAndMusic();
1846 // create gadgets for main menu screen
1847 FreeScreenGadgets();
1848 CreateScreenGadgets();
1850 // may be required if audio buttons shown on tape and changed in setup menu
1852 CreateGameButtons();
1854 // map gadgets for main menu screen
1856 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1857 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1858 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SET_INFO, hasLevelSetInfo());
1860 // copy actual game door content to door double buffer for OpenDoor()
1861 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1862 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1864 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1866 DrawMaskedBorder(fade_mask);
1871 // update screen area with special editor door
1872 redraw_mask |= REDRAW_ALL;
1875 SetMouseCursor(CURSOR_DEFAULT);
1877 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1879 SyncEmscriptenFilesystem();
1881 // needed once after program start or after user change
1882 CheckApiServerTasks();
1885 static void gotoTopLevelDir(void)
1887 // move upwards until inside (but not above) top level directory
1888 while (leveldir_current->node_parent &&
1889 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1891 // write a "path" into level tree for easy navigation to last level
1892 if (leveldir_current->node_parent->node_group->cl_first == -1)
1894 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1895 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1896 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1897 int cl_first, cl_cursor;
1899 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1900 cl_cursor = leveldir_pos - cl_first;
1902 leveldir_current->node_parent->node_group->cl_first = cl_first;
1903 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1906 leveldir_current = leveldir_current->node_parent;
1910 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1912 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1914 return (use_frame_counter ? video.frame_counter : Counter());
1917 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1918 struct TitleFadingInfo *fi)
1920 return DelayReachedExt2(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1923 static void ResetTitleAutoDelay(unsigned int *counter_var,
1924 struct TitleFadingInfo *fi)
1926 *counter_var = getAutoDelayCounter(fi);
1929 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1931 static unsigned int title_delay = 0;
1932 static int title_screen_nr = 0;
1933 static int last_sound = -1, last_music = -1;
1934 boolean return_to_main_menu = FALSE;
1935 struct TitleControlInfo *tci;
1938 if (button == MB_MENU_INITIALIZE)
1941 title_screen_nr = 0;
1942 tci = &title_controls[title_screen_nr];
1944 SetAnimStatus(getTitleAnimMode(tci));
1946 last_sound = SND_UNDEFINED;
1947 last_music = MUS_UNDEFINED;
1949 if (num_title_screens != 0)
1951 FadeSetEnterScreen();
1953 // use individual title fading instead of global "enter screen" fading
1954 fading = getTitleFading(tci);
1957 if (game_status_last_screen == GAME_MODE_INFO)
1959 if (num_title_screens == 0)
1961 // switch game mode from title screen mode back to info screen mode
1962 SetGameStatus(GAME_MODE_INFO);
1964 // store that last screen was info screen, not main menu screen
1965 game_status_last_screen = GAME_MODE_INFO;
1967 DrawInfoScreen_NotAvailable("Title screen information:",
1968 "No title screen for this level set.");
1973 FadeMenuSoundsAndMusic();
1975 FadeOut(REDRAW_ALL);
1977 // title screens may have different window size
1978 ChangeViewportPropertiesIfNeeded();
1980 // only required to update logic for redrawing global border
1984 DrawTitleScreenImage(tci->local_nr, tci->initial);
1986 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1988 sound = getTitleSound(tci);
1989 music = getTitleMusic(tci);
1991 if (sound != last_sound)
1992 PlayMenuSoundExt(sound);
1993 if (music != last_music)
1994 PlayMenuMusicExt(music);
1999 SetMouseCursor(CURSOR_NONE);
2003 ResetTitleAutoDelay(&title_delay, &fading);
2008 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
2009 button = MB_MENU_CHOICE;
2011 if (button == MB_MENU_LEAVE)
2013 return_to_main_menu = TRUE;
2015 else if (button == MB_MENU_CHOICE || dx)
2017 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
2019 SetGameStatus(GAME_MODE_INFO);
2021 info_mode = INFO_MODE_MAIN;
2029 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
2031 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
2033 tci = &title_controls[title_screen_nr];
2035 SetAnimStatus(getTitleAnimMode(tci));
2037 sound = getTitleSound(tci);
2038 music = getTitleMusic(tci);
2040 if (last_sound != SND_UNDEFINED && sound != last_sound)
2041 FadeSound(last_sound);
2042 if (last_music != MUS_UNDEFINED && music != last_music)
2045 fading = getTitleFading(tci);
2047 FadeOut(REDRAW_ALL);
2050 DrawTitleScreenImage(tci->local_nr, tci->initial);
2052 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2054 sound = getTitleSound(tci);
2055 music = getTitleMusic(tci);
2057 if (sound != last_sound)
2058 PlayMenuSoundExt(sound);
2059 if (music != last_music)
2060 PlayMenuMusicExt(music);
2067 ResetTitleAutoDelay(&title_delay, &fading);
2071 FadeMenuSoundsAndMusic();
2073 return_to_main_menu = TRUE;
2077 if (return_to_main_menu)
2079 SetMouseCursor(CURSOR_DEFAULT);
2081 // force full menu screen redraw after displaying title screens
2082 redraw_mask = REDRAW_ALL;
2084 if (game_status_last_screen == GAME_MODE_INFO)
2086 SetGameStatus(GAME_MODE_INFO);
2088 info_mode = INFO_MODE_MAIN;
2092 else // default: return to main menu
2094 SetGameStatus(GAME_MODE_MAIN);
2101 static void HandleMainMenu_ToggleTeamMode(void)
2103 setup.team_mode = !setup.team_mode;
2105 InitializeMainControls();
2106 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2108 DrawPreviewPlayers();
2111 static void HandleMainMenu_SelectLevel(int step, int direction,
2112 int selected_level_nr)
2114 int old_level_nr = level_nr;
2117 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2118 new_level_nr = selected_level_nr;
2120 new_level_nr = old_level_nr + step * direction;
2122 if (new_level_nr < leveldir_current->first_level)
2123 new_level_nr = leveldir_current->first_level;
2124 if (new_level_nr > leveldir_current->last_level)
2125 new_level_nr = leveldir_current->last_level;
2127 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2129 // skipping levels is only allowed when trying to skip single level
2130 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2131 Request("Level still unsolved! Skip it anyway?", REQ_ASK))
2133 leveldir_current->handicap_level++;
2134 SaveLevelSetup_SeriesInfo();
2137 new_level_nr = leveldir_current->handicap_level;
2140 if (new_level_nr != old_level_nr)
2142 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2144 PlaySound(SND_MENU_ITEM_SELECTING);
2146 level_nr = new_level_nr;
2148 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2149 int2str(level_nr, menu.main.text.level_number.size),
2150 mci->pos_text->font);
2152 LoadLevel(level_nr);
2153 DrawPreviewLevelInitial();
2157 DrawCompleteVideoDisplay();
2159 SaveLevelSetup_SeriesInfo();
2161 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2163 // force redraw of playfield area (may be reset at this point)
2164 redraw_mask |= REDRAW_FIELD;
2168 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2170 static int choice = MAIN_CONTROL_GAME;
2171 static boolean button_pressed_last = FALSE;
2172 boolean button_pressed = FALSE;
2174 int i = 0; // needed to prevent compiler warning due to bad code below
2176 if (button == MB_MENU_INITIALIZE)
2178 DrawCursorAndText_Main(choice, TRUE, FALSE);
2183 if (mx || my) // mouse input
2187 for (i = 0; main_controls[i].nr != -1; i++)
2189 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2190 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2191 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2193 pos = main_controls[i].nr;
2199 // check if level preview was clicked
2200 if (insidePreviewRect(&preview, mx - SX, my - SY))
2201 pos = MAIN_CONTROL_GAME;
2203 // handle pressed/unpressed state for active/inactive menu buttons
2204 // (if pos != -1, "i" contains index position corresponding to "pos")
2206 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2207 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2208 button_pressed = TRUE;
2210 if (button_pressed != button_pressed_last)
2212 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2215 PlaySound(SND_MENU_BUTTON_PRESSING);
2217 PlaySound(SND_MENU_BUTTON_RELEASING);
2220 else if (dx || dy) // keyboard input
2222 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2223 choice == MAIN_CONTROL_SETUP))
2224 button = MB_MENU_CHOICE;
2229 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2231 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2233 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2235 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2237 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2239 CloseDoor(DOOR_CLOSE_2);
2241 SetGameStatus(GAME_MODE_LEVELNR);
2243 DrawChooseLevelNr();
2245 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2251 PlaySound(SND_MENU_ITEM_ACTIVATING);
2253 DrawCursorAndText_Main(choice, FALSE, FALSE);
2254 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2260 if (choice == MAIN_CONTROL_NAME)
2262 // special case: cursor left or right pressed -- toggle team mode
2263 HandleMainMenu_ToggleTeamMode();
2265 else if (choice != MAIN_CONTROL_INFO &&
2266 choice != MAIN_CONTROL_SETUP)
2268 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2274 PlaySound(SND_MENU_ITEM_SELECTING);
2276 if (pos == MAIN_CONTROL_NAME)
2279 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2281 // special case: menu text "name/team" clicked -- toggle team mode
2282 HandleMainMenu_ToggleTeamMode();
2286 if (setup.multiple_users)
2288 CloseDoor(DOOR_CLOSE_2);
2290 SetGameStatus(GAME_MODE_NAMES);
2292 DrawChoosePlayerName();
2296 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2302 else if (pos == MAIN_CONTROL_LEVELS)
2306 CloseDoor(DOOR_CLOSE_2);
2308 SetGameStatus(GAME_MODE_LEVELS);
2310 SaveLevelSetup_LastSeries();
2311 SaveLevelSetup_SeriesInfo();
2313 // restore level set if chosen from "last played level set" menu
2314 RestoreLastPlayedLevels(&leveldir_current);
2316 if (setup.internal.choose_from_top_leveldir)
2319 DrawChooseLevelSet();
2322 else if (pos == MAIN_CONTROL_SCORES)
2324 CloseDoor(DOOR_CLOSE_2);
2326 SetGameStatus(GAME_MODE_SCORES);
2328 DrawHallOfFame(level_nr);
2330 else if (pos == MAIN_CONTROL_EDITOR)
2332 if (leveldir_current->readonly &&
2333 setup.editor.show_read_only_warning)
2334 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2336 CloseDoor(DOOR_CLOSE_ALL);
2338 SetGameStatus(GAME_MODE_EDITOR);
2340 FadeSetEnterScreen();
2344 else if (pos == MAIN_CONTROL_INFO)
2346 CloseDoor(DOOR_CLOSE_2);
2348 SetGameStatus(GAME_MODE_INFO);
2350 info_mode = INFO_MODE_MAIN;
2354 else if (pos == MAIN_CONTROL_GAME)
2356 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2358 else if (pos == MAIN_CONTROL_SETUP)
2360 CloseDoor(DOOR_CLOSE_2);
2362 SetGameStatus(GAME_MODE_SETUP);
2364 setup_mode = SETUP_MODE_MAIN;
2368 else if (pos == MAIN_CONTROL_QUIT)
2370 SaveLevelSetup_LastSeries();
2371 SaveLevelSetup_SeriesInfo();
2373 #if defined(PLATFORM_EMSCRIPTEN)
2374 Request("Close the browser window to quit!", REQ_CONFIRM);
2376 if (!setup.ask_on_quit_program ||
2377 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2378 SetGameStatus(GAME_MODE_QUIT);
2384 button_pressed_last = button_pressed;
2388 // ============================================================================
2389 // info screen functions
2390 // ============================================================================
2392 static struct TokenInfo *info_info;
2393 static int num_info_info; // number of info entries shown on screen
2394 static int max_info_info; // total number of info entries in list
2396 static void execInfoTitleScreen(void)
2398 info_mode = INFO_MODE_TITLE;
2403 static void execInfoElements(void)
2405 info_mode = INFO_MODE_ELEMENTS;
2410 static void execInfoMusic(void)
2412 info_mode = INFO_MODE_MUSIC;
2417 static void execInfoCredits(void)
2419 info_mode = INFO_MODE_CREDITS;
2424 static void execInfoProgram(void)
2426 info_mode = INFO_MODE_PROGRAM;
2431 static void execInfoVersion(void)
2433 info_mode = INFO_MODE_VERSION;
2438 static void execInfoLevelSet(void)
2440 info_mode = INFO_MODE_LEVELSET;
2445 static void execExitInfo(void)
2447 SetGameStatus(GAME_MODE_MAIN);
2452 static struct TokenInfo info_info_main[] =
2454 { TYPE_ENTER_SCREEN, execInfoTitleScreen, STR_INFO_TITLE },
2455 { TYPE_ENTER_SCREEN, execInfoElements, STR_INFO_ELEMENTS },
2456 { TYPE_ENTER_SCREEN, execInfoMusic, STR_INFO_MUSIC },
2457 { TYPE_ENTER_SCREEN, execInfoCredits, STR_INFO_CREDITS },
2458 { TYPE_ENTER_SCREEN, execInfoProgram, STR_INFO_PROGRAM },
2459 { TYPE_ENTER_SCREEN, execInfoVersion, STR_INFO_VERSION },
2460 { TYPE_ENTER_SCREEN, execInfoLevelSet, STR_INFO_LEVELSET },
2461 { TYPE_EMPTY, NULL, "" },
2462 { TYPE_LEAVE_MENU, execExitInfo, STR_INFO_EXIT },
2467 static int getMenuTextFont(int type)
2469 if (type & (TYPE_SWITCH |
2483 static struct TokenInfo *setup_info;
2484 static struct TokenInfo setup_info_input[];
2486 static struct TokenInfo *menu_info;
2488 static void PlayInfoSound(void)
2490 int info_sound = getInfoScreenBackgroundSound_Generic();
2491 char *next_sound = getSoundInfoEntryFilename(info_sound);
2493 if (next_sound != NULL)
2494 PlayMenuSoundExt(info_sound);
2499 static void PlayInfoSoundIfLoop(void)
2501 int info_sound = getInfoScreenBackgroundSound_Generic();
2502 char *next_sound = getSoundInfoEntryFilename(info_sound);
2504 if (next_sound != NULL)
2505 PlayMenuSoundIfLoopExt(info_sound);
2507 PlayMenuSoundIfLoop();
2510 static void PlayInfoMusic(void)
2512 int info_music = getInfoScreenBackgroundMusic_Generic();
2513 char *curr_music = getCurrentlyPlayingMusicFilename();
2514 char *next_music = getMusicInfoEntryFilename(info_music);
2516 if (next_music != NULL)
2518 // play music if info screen music differs from current music
2519 if (!strEqual(curr_music, next_music))
2520 PlayMenuMusicExt(info_music);
2524 // only needed if info screen was directly invoked from main menu
2529 static void PlayInfoSoundsAndMusic(void)
2535 static void FadeInfoSounds(void)
2540 static void FadeInfoMusic(void)
2542 int info_music = getInfoScreenBackgroundMusic_Generic();
2543 char *curr_music = getCurrentlyPlayingMusicFilename();
2544 char *next_music = getMusicInfoEntryFilename(info_music);
2546 if (next_music != NULL)
2548 // fade music if info screen music differs from current music
2549 if (!strEqual(curr_music, next_music))
2554 static void FadeInfoSoundsAndMusic(void)
2560 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2561 int screen_pos, int menu_info_pos_raw,
2564 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2565 struct TokenInfo *ti = &token_info[pos];
2566 int xpos = MENU_SCREEN_START_XPOS;
2567 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2568 int font_nr = getMenuTextFont(ti->type);
2570 if (setup_mode == SETUP_MODE_INPUT)
2571 font_nr = FONT_MENU_1;
2574 font_nr = FONT_ACTIVE(font_nr);
2576 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2578 if (ti->type & ~TYPE_SKIP_ENTRY)
2579 drawCursor(screen_pos, active);
2582 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2585 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2588 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2591 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2594 static char *window_size_text;
2595 static char *scaling_type_text;
2596 static char *network_server_text;
2598 static void drawSetupValue(int, int);
2600 static void drawMenuInfoList(int first_entry, int num_page_entries,
2601 int max_page_entries)
2605 if (first_entry + num_page_entries > max_page_entries)
2608 clearMenuListArea();
2610 for (i = 0; i < num_page_entries; i++)
2612 int menu_info_pos = first_entry + i;
2613 struct TokenInfo *si = &menu_info[menu_info_pos];
2614 void *value_ptr = si->value;
2616 // set some entries to "unchangeable" according to other variables
2617 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2618 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2619 (value_ptr == &setup.sound_music && !audio.music_available) ||
2620 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2621 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2622 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2623 si->type |= TYPE_GHOSTED;
2625 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2626 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2627 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2628 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2629 else if (si->type & ~TYPE_SKIP_ENTRY)
2630 initCursor(i, IMG_MENU_BUTTON);
2632 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2634 if (si->type & TYPE_STRING)
2638 if (value_ptr == &network_server_text)
2639 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2641 if (gadget_id != -1)
2643 struct GadgetInfo *gi = screen_gadget[gadget_id];
2644 int xpos = MENU_SCREEN_START_XPOS;
2645 int ypos = MENU_SCREEN_START_YPOS + i;
2646 int x = mSX + xpos * 32;
2647 int y = mSY + ypos * 32;
2649 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2653 if (si->type & TYPE_VALUE &&
2654 menu_info == setup_info)
2655 drawSetupValue(i, menu_info_pos);
2659 static void DrawInfoScreen_Main(void)
2661 int fade_mask = REDRAW_FIELD;
2664 // (needed after displaying info sub-screens directly from main menu)
2665 if (info_screens_from_main)
2667 info_screens_from_main = FALSE;
2669 SetGameStatus(GAME_MODE_MAIN);
2676 if (redraw_mask & REDRAW_ALL)
2677 fade_mask = REDRAW_ALL;
2680 fade_mask = REDRAW_ALL;
2683 FadeMenuSoundsAndMusic();
2685 FreeScreenGadgets();
2686 CreateScreenGadgets();
2688 // (needed after displaying title screens which disable auto repeat)
2689 KeyboardAutoRepeatOn();
2691 FadeSetLeaveScreen();
2695 // needed if different viewport properties defined for info screen
2696 ChangeViewportPropertiesIfNeeded();
2698 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2702 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2704 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_INFO_MAIN);
2706 info_info = info_info_main;
2708 // use modified info screen info without info screen entries marked as hidden
2709 info_info = getSetupInfoFinal(info_info);
2711 // determine maximal number of info entries that can be displayed on screen
2713 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2716 // determine maximal number of info entries available for menu of info screen
2718 for (i = 0; info_info[i].type != 0; i++)
2721 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2723 MapScreenGadgets(max_info_info);
2725 PlayMenuSoundsAndMusic();
2727 DrawMaskedBorder(fade_mask);
2732 static void changeSetupValue(int, int, int);
2734 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2735 int mode, int num_page_entries,
2736 int max_page_entries)
2738 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2739 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2740 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2741 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2742 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2743 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2744 int *num_page_entries_last = num_page_entries_all_last[game_status];
2745 int *choice_store = choice_stores[game_status];
2746 int *first_entry_store = first_entry_stores[game_status];
2747 int choice = choice_store[mode]; // starts with 0
2748 int first_entry = first_entry_store[mode]; // starts with 0
2750 int y = choice - first_entry;
2752 boolean position_set_by_scrollbar = (dx == 999);
2753 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2756 if (button == MB_MENU_INITIALIZE)
2758 // check if number of menu page entries has changed (may happen by change
2759 // of custom artwork definition value for 'list_size' for this menu screen)
2760 // (in this case, the last menu position most probably has to be corrected)
2761 if (num_page_entries != num_page_entries_last[mode])
2763 choice_store[mode] = first_entry_store[mode] = 0;
2765 choice = first_entry = 0;
2768 num_page_entries_last[mode] = num_page_entries;
2771 // advance to first valid menu entry
2772 while (choice < num_page_entries &&
2773 menu_info[choice].type & TYPE_SKIP_ENTRY)
2776 if (position_set_by_scrollbar)
2777 first_entry = first_entry_store[mode] = dy;
2779 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2780 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2782 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2784 if (choice < first_entry)
2786 choice = first_entry;
2788 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2791 else if (choice > first_entry + num_page_entries - 1)
2793 choice = first_entry + num_page_entries - 1;
2795 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2799 choice_store[mode] = choice;
2801 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2805 else if (button == MB_MENU_LEAVE)
2807 PlaySound(SND_MENU_ITEM_SELECTING);
2809 for (i = 0; i < max_page_entries; i++)
2811 if (menu_info[i].type & TYPE_LEAVE_MENU)
2813 void (*menu_callback_function)(void) = menu_info[i].value;
2817 menu_callback_function();
2819 break; // absolutely needed because function changes 'menu_info'!
2826 if (mx || my) // mouse input
2828 x = (mx - mSX) / 32;
2829 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2831 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2833 // move cursor instead of scrolling when already at start/end of list
2834 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2836 else if (dy == +1 * SCROLL_LINE &&
2837 first_entry + num_page_entries == max_page_entries)
2840 // handle scrolling screen one line or page
2842 y + dy > num_page_entries - 1)
2844 boolean redraw = FALSE;
2846 if (ABS(dy) == SCROLL_PAGE)
2847 step = num_page_entries - 1;
2849 if (dy < 0 && first_entry > 0)
2851 // scroll page/line up
2853 first_entry -= step;
2854 if (first_entry < 0)
2859 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2861 // scroll page/line down
2863 first_entry += step;
2864 if (first_entry + num_page_entries > max_page_entries)
2865 first_entry = MAX(0, max_page_entries - num_page_entries);
2872 choice += first_entry - first_entry_store[mode];
2874 if (choice < first_entry)
2876 choice = first_entry;
2878 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2881 else if (choice > first_entry + num_page_entries - 1)
2883 choice = first_entry + num_page_entries - 1;
2885 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2888 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2892 if (choice < first_entry ||
2893 choice > first_entry + num_page_entries - 1)
2894 first_entry += SIGN(dy);
2897 first_entry_store[mode] = first_entry;
2898 choice_store[mode] = choice;
2900 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2902 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2904 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2905 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2913 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2915 if (menu_info[choice].type & menu_navigation_type ||
2916 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2917 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2918 menu_info[choice].type & TYPE_PLAYER)
2919 button = MB_MENU_CHOICE;
2924 // jump to next non-empty menu entry (up or down)
2925 while (first_entry + y > 0 &&
2926 first_entry + y < max_page_entries - 1 &&
2927 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2930 if (!IN_VIS_MENU(x, y))
2932 choice += y - y_old;
2934 if (choice < first_entry)
2935 first_entry = choice;
2936 else if (choice > first_entry + num_page_entries - 1)
2937 first_entry = choice - num_page_entries + 1;
2939 if (first_entry >= 0 &&
2940 first_entry + num_page_entries <= max_page_entries)
2942 first_entry_store[mode] = first_entry;
2944 if (choice < first_entry)
2945 choice = first_entry;
2946 else if (choice > first_entry + num_page_entries - 1)
2947 choice = first_entry + num_page_entries - 1;
2949 choice_store[mode] = choice;
2951 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2953 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2955 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2956 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2963 if (!anyScrollbarGadgetActive() &&
2964 IN_VIS_MENU(x, y) &&
2965 mx < mx_right_border &&
2966 y >= 0 && y < num_page_entries)
2970 if (first_entry + y != choice &&
2971 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2973 PlaySound(SND_MENU_ITEM_ACTIVATING);
2975 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2976 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2978 choice = choice_store[mode] = first_entry + y;
2982 PlaySound(SND_MENU_ITEM_SELECTING);
2984 for (i = 0; menu_info[i].type != 0; i++)
2986 if (menu_info[i].type & TYPE_LEAVE_MENU)
2988 void (*menu_callback_function)(void) = menu_info[i].value;
2992 menu_callback_function();
2994 // absolutely needed because function changes 'menu_info'!
3002 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
3004 PlaySound(SND_MENU_ITEM_SELECTING);
3006 // when selecting key headline, execute function for key value change
3007 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
3008 menu_info[first_entry + y + 1].type & TYPE_KEY)
3011 // when selecting string value, execute function for list selection
3012 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3013 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
3016 // when selecting string value, execute function for text input gadget
3017 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3018 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
3021 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
3023 void (*menu_callback_function)(void) =
3024 menu_info[first_entry + y].value;
3026 FadeSetFromType(menu_info[first_entry + y].type);
3028 menu_callback_function();
3030 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
3032 void (*gadget_callback_function)(void) =
3033 menu_info[first_entry + y].value;
3035 gadget_callback_function();
3037 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
3038 menu_info == setup_info)
3040 changeSetupValue(y, first_entry + y, dx);
3046 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
3048 menu_info = info_info;
3050 HandleMenuScreen(mx, my, dx, dy, button,
3051 info_mode, num_info_info, max_info_info);
3054 static int getMenuFontSpacing(int spacing_height, int font_nr)
3056 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
3058 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
3062 static int getMenuTextSpacing(int spacing_height, int font_nr)
3064 return (getMenuFontSpacing(spacing_height, font_nr) +
3065 EXTRA_SPACING(game_status));
3068 static int getMenuTextStep(int spacing_height, int font_nr)
3070 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
3073 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
3075 int font_error = FONT_TEXT_2;
3076 int font_foot = MENU_INFO_FONT_FOOT;
3077 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3078 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3080 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
3082 FadeOut(REDRAW_FIELD);
3086 DrawInfoScreen_Headline(0, 1, FALSE);
3088 DrawTextSCentered(ystart, font_error, text_error);
3089 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3091 FadeIn(REDRAW_FIELD);
3094 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
3096 static int infoscreen_step[MAX_INFO_ELEMENTS_IN_ARRAY];
3097 static int infoscreen_frame[MAX_INFO_ELEMENTS_IN_ARRAY];
3098 int font_foot = MENU_INFO_FONT_FOOT;
3099 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
3100 int ystart = mSY + MENU_SCREEN_INFO_YSTART;
3101 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3102 int ystep = MENU_SCREEN_INFO_YSTEP;
3103 int element, action, direction;
3111 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
3112 infoscreen_step[i] = infoscreen_frame[i] = 0;
3114 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3120 while (helpanim_info[j].element != HELPANIM_LIST_END)
3122 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
3127 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3136 j += infoscreen_step[i - start];
3138 element = helpanim_info[j].element;
3139 action = helpanim_info[j].action;
3140 direction = helpanim_info[j].direction;
3143 element = EL_UNKNOWN;
3145 if (action != -1 && direction != -1)
3146 graphic = el_act_dir2img(element, action, direction);
3147 else if (action != -1)
3148 graphic = el_act2img(element, action);
3149 else if (direction != -1)
3150 graphic = el_dir2img(element, direction);
3152 graphic = el2img(element);
3154 delay = helpanim_info[j++].delay;
3159 if (infoscreen_frame[i - start] == 0)
3162 infoscreen_frame[i - start] = delay - 1;
3166 sync_frame = delay - infoscreen_frame[i - start];
3167 infoscreen_frame[i - start]--;
3170 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3172 if (!infoscreen_frame[i - start])
3173 infoscreen_step[i - start] = 0;
3177 if (!infoscreen_frame[i - start])
3178 infoscreen_step[i - start]++;
3179 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3185 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
3187 DrawFixedGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
3188 graphic, sync_frame, USE_MASKING);
3191 DrawInfoScreen_HelpText(element, action, direction, i - start);
3196 redraw_mask |= REDRAW_FIELD;
3201 static char *getHelpText(int element, int action, int direction)
3203 char token[MAX_LINE_LEN];
3205 strcpy(token, element_info[element].token_name);
3208 strcat(token, element_action_info[action].suffix);
3210 if (direction != -1)
3211 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3213 return getHashEntry(helptext_info, token);
3216 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3218 int font_nr = FONT_INFO_ELEMENTS;
3219 int font_width = getFontWidth(font_nr);
3220 int font_height = getFontHeight(font_nr);
3221 int yoffset = (TILEX - 2 * font_height) / 2;
3222 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3223 int ystart = mSY + MENU_SCREEN_INFO_YSTART + yoffset;
3224 int ystep = TILEY + 4;
3225 int pad_left = xstart - SX;
3226 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3227 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3228 int max_lines_per_text = 2;
3231 if (action != -1 && direction != -1) // element.action.direction
3232 text = getHelpText(element, action, direction);
3234 if (text == NULL && action != -1) // element.action
3235 text = getHelpText(element, action, -1);
3237 if (text == NULL && direction != -1) // element.direction
3238 text = getHelpText(element, -1, direction);
3240 if (text == NULL) // base element
3241 text = getHelpText(element, -1, -1);
3243 if (text == NULL) // not found
3244 text = "No description available";
3246 if (strlen(text) <= max_chars_per_line) // only one line of text
3247 ystart += getFontHeight(font_nr) / 2;
3249 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3250 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3251 TRUE, FALSE, FALSE);
3254 static void DrawInfoScreen_TitleScreen(void)
3256 SetGameStatus(GAME_MODE_TITLE);
3261 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3263 HandleTitleScreen(0, 0, dx, dy, button);
3266 static void DrawInfoScreen_Elements(void)
3268 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3270 FadeInfoSoundsAndMusic();
3272 FadeOut(REDRAW_FIELD);
3277 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3279 PlayInfoSoundsAndMusic();
3281 FadeIn(REDRAW_FIELD);
3284 void HandleInfoScreen_Elements(int dx, int dy, int button)
3286 static DelayCounter info_delay = { 0 };
3287 static int num_anims;
3288 static int num_pages;
3290 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3293 info_delay.value = GameFrameDelay;
3295 if (button == MB_MENU_INITIALIZE)
3297 boolean new_element = TRUE;
3301 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3303 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3305 else if (new_element)
3308 new_element = FALSE;
3312 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3316 if (button == MB_MENU_LEAVE)
3318 PlaySound(SND_MENU_ITEM_SELECTING);
3320 info_mode = INFO_MODE_MAIN;
3325 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3327 if (button != MB_MENU_INITIALIZE)
3329 PlaySound(SND_MENU_ITEM_SELECTING);
3331 page += (dx < 0 ? -1 : +1);
3334 if (page < 0 || page >= num_pages)
3336 FadeInfoSoundsAndMusic();
3338 info_mode = INFO_MODE_MAIN;
3344 if (button != MB_MENU_INITIALIZE)
3345 FadeSetNextScreen();
3347 if (button != MB_MENU_INITIALIZE)
3348 FadeOut(REDRAW_FIELD);
3352 DrawInfoScreen_Headline(page, num_pages, TRUE);
3353 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3355 if (button != MB_MENU_INITIALIZE)
3356 FadeIn(REDRAW_FIELD);
3360 if (DelayReached(&info_delay))
3361 if (page < num_pages)
3362 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3364 PlayInfoSoundIfLoop();
3368 static void DrawInfoScreen_Music(void)
3370 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3372 FadeOut(REDRAW_FIELD);
3376 DrawInfoScreen_Headline(0, 1, TRUE);
3380 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3382 FadeIn(REDRAW_FIELD);
3385 void HandleInfoScreen_Music(int dx, int dy, int button)
3387 static struct MusicFileInfo *list = NULL;
3388 static int num_screens = 0;
3389 static int screen_nr = 0;
3390 int font_title = MENU_INFO_FONT_TITLE;
3391 int font_head = MENU_INFO_FONT_HEAD;
3392 int font_text = MENU_INFO_FONT_TEXT;
3393 int font_foot = MENU_INFO_FONT_FOOT;
3394 int spacing_head = menu.headline2_spacing_info[info_mode];
3395 int ystep_head = getMenuTextStep(spacing_head, font_head);
3396 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3397 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3399 if (button == MB_MENU_INITIALIZE)
3401 struct MusicFileInfo *list_ptr = music_file_info;
3406 while (list_ptr != NULL)
3408 list_ptr = list_ptr->next;
3412 list = music_file_info;
3416 FadeMenuSoundsAndMusic();
3420 DrawInfoScreen_Headline(0, 1, TRUE);
3422 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3423 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3429 if (button == MB_MENU_LEAVE)
3431 PlaySound(SND_MENU_ITEM_SELECTING);
3433 FadeMenuSoundsAndMusic();
3435 info_mode = INFO_MODE_MAIN;
3440 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3442 if (button != MB_MENU_INITIALIZE)
3444 PlaySound(SND_MENU_ITEM_SELECTING);
3448 list = (dx < 0 ? list->prev : list->next);
3449 screen_nr += (dx < 0 ? -1 : +1);
3455 FadeMenuSoundsAndMusic();
3457 info_mode = INFO_MODE_MAIN;
3463 FadeMenuSoundsAndMusic();
3465 if (list != music_file_info)
3466 FadeSetNextScreen();
3468 if (button != MB_MENU_INITIALIZE)
3469 FadeOut(REDRAW_FIELD);
3473 DrawInfoScreen_Headline(screen_nr, num_screens, TRUE);
3477 int sound = list->music;
3479 if (IS_LOOP_SOUND(sound))
3480 PlaySoundLoop(sound);
3486 int music = list->music;
3488 if (IS_LOOP_MUSIC(music))
3489 PlayMusicLoop(music);
3494 if (!strEqual(list->title, UNKNOWN_NAME))
3496 if (!strEqual(list->title_header, UNKNOWN_NAME))
3497 DrawTextSCentered(ystart, font_head, list->title_header);
3499 DrawTextSCentered(ystart, font_head, "Track");
3501 ystart += ystep_head;
3503 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3504 ystart += ystep_head;
3507 if (!strEqual(list->artist, UNKNOWN_NAME))
3509 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3510 DrawTextSCentered(ystart, font_head, list->artist_header);
3512 DrawTextSCentered(ystart, font_head, "by");
3514 ystart += ystep_head;
3516 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3517 ystart += ystep_head;
3520 if (!strEqual(list->album, UNKNOWN_NAME))
3522 if (!strEqual(list->album_header, UNKNOWN_NAME))
3523 DrawTextSCentered(ystart, font_head, list->album_header);
3525 DrawTextSCentered(ystart, font_head, "from the album");
3527 ystart += ystep_head;
3529 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3530 ystart += ystep_head;
3533 if (!strEqual(list->year, UNKNOWN_NAME))
3535 if (!strEqual(list->year_header, UNKNOWN_NAME))
3536 DrawTextSCentered(ystart, font_head, list->year_header);
3538 DrawTextSCentered(ystart, font_head, "from the year");
3540 ystart += ystep_head;
3542 DrawTextFCentered(ystart, font_text, "%s", list->year);
3543 ystart += ystep_head;
3546 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3548 if (button != MB_MENU_INITIALIZE)
3549 FadeIn(REDRAW_FIELD);
3552 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3553 PlaySoundLoop(list->music);
3556 static void DrawInfoScreen_Version(void)
3558 int font_head = MENU_INFO_FONT_HEAD;
3559 int font_text = MENU_INFO_FONT_TEXT;
3560 int font_foot = MENU_INFO_FONT_FOOT;
3561 int spacing_head = menu.headline2_spacing_info[info_mode];
3562 int spacing_para = menu.paragraph_spacing_info[info_mode];
3563 int spacing_line = menu.line_spacing_info[info_mode];
3564 int xstep = getFontWidth(font_text);
3565 int ystep_head = getMenuTextStep(spacing_head, font_head);
3566 int ystep_para = getMenuTextStep(spacing_para, font_text);
3567 int ystep_line = getMenuTextStep(spacing_line, font_text);
3568 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3569 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3570 int xstart1 = mSX - SX + 2 * xstep;
3571 int xstart2 = mSX - SX + 18 * xstep;
3572 int xstart3 = mSX - SX + 28 * xstep;
3573 SDL_version sdl_version_compiled;
3574 const SDL_version *sdl_version_linked;
3575 int driver_name_len = 10;
3576 SDL_version sdl_version_linked_ext;
3577 const char *driver_name = NULL;
3579 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3581 FadeInfoSoundsAndMusic();
3583 FadeOut(REDRAW_FIELD);
3587 DrawInfoScreen_Headline(0, 1, TRUE);
3589 DrawTextF(xstart1, ystart, font_head, "Name");
3590 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3591 ystart += ystep_line;
3593 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3595 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3596 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3597 ystart += ystep_line;
3599 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3600 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3601 ystart += ystep_line;
3605 DrawTextF(xstart1, ystart, font_head, "Version");
3606 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3607 ystart += ystep_line;
3610 DrawTextF(xstart1, ystart, font_head, "Platform");
3611 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3613 PLATFORM_XX_BIT_STRING);
3614 ystart += ystep_line;
3616 DrawTextF(xstart1, ystart, font_head, "Target");
3617 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3618 ystart += ystep_line;
3620 DrawTextF(xstart1, ystart, font_head, "Source date");
3621 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3622 ystart += ystep_line;
3624 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3625 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3626 ystart += ystep_para;
3628 DrawTextF(xstart1, ystart, font_head, "Library");
3629 DrawTextF(xstart2, ystart, font_head, "compiled");
3630 DrawTextF(xstart3, ystart, font_head, "linked");
3631 ystart += ystep_head;
3633 SDL_VERSION(&sdl_version_compiled);
3634 SDL_GetVersion(&sdl_version_linked_ext);
3635 sdl_version_linked = &sdl_version_linked_ext;
3637 DrawTextF(xstart1, ystart, font_text, "SDL");
3638 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3639 sdl_version_compiled.major,
3640 sdl_version_compiled.minor,
3641 sdl_version_compiled.patch);
3642 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3643 sdl_version_linked->major,
3644 sdl_version_linked->minor,
3645 sdl_version_linked->patch);
3646 ystart += ystep_line;
3648 SDL_IMAGE_VERSION(&sdl_version_compiled);
3649 sdl_version_linked = IMG_Linked_Version();
3651 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3652 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3653 sdl_version_compiled.major,
3654 sdl_version_compiled.minor,
3655 sdl_version_compiled.patch);
3656 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3657 sdl_version_linked->major,
3658 sdl_version_linked->minor,
3659 sdl_version_linked->patch);
3660 ystart += ystep_line;
3662 SDL_MIXER_VERSION(&sdl_version_compiled);
3663 sdl_version_linked = Mix_Linked_Version();
3665 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3666 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3667 sdl_version_compiled.major,
3668 sdl_version_compiled.minor,
3669 sdl_version_compiled.patch);
3670 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3671 sdl_version_linked->major,
3672 sdl_version_linked->minor,
3673 sdl_version_linked->patch);
3674 ystart += ystep_line;
3676 SDL_NET_VERSION(&sdl_version_compiled);
3677 sdl_version_linked = SDLNet_Linked_Version();
3679 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3680 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3681 sdl_version_compiled.major,
3682 sdl_version_compiled.minor,
3683 sdl_version_compiled.patch);
3684 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3685 sdl_version_linked->major,
3686 sdl_version_linked->minor,
3687 sdl_version_linked->patch);
3688 ystart += ystep_para;
3690 DrawTextF(xstart1, ystart, font_head, "Driver");
3691 DrawTextF(xstart2, ystart, font_head, "Requested");
3692 DrawTextF(xstart3, ystart, font_head, "Used");
3693 ystart += ystep_head;
3696 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3698 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3699 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3700 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3701 ystart += ystep_line;
3704 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3706 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3707 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3708 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3709 ystart += ystep_line;
3712 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3714 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3715 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3716 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3718 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3720 PlayInfoSoundsAndMusic();
3722 FadeIn(REDRAW_FIELD);
3725 void HandleInfoScreen_Version(int button)
3727 if (button == MB_MENU_LEAVE)
3729 PlaySound(SND_MENU_ITEM_SELECTING);
3731 info_mode = INFO_MODE_MAIN;
3736 else if (button == MB_MENU_CHOICE)
3738 PlaySound(SND_MENU_ITEM_SELECTING);
3740 FadeMenuSoundsAndMusic();
3742 info_mode = INFO_MODE_MAIN;
3747 PlayMenuSoundIfLoop();
3751 static char *getInfoScreenTitle_Generic(void)
3753 return (info_mode == INFO_MODE_MAIN ? STR_INFO_MAIN :
3754 info_mode == INFO_MODE_TITLE ? STR_INFO_TITLE :
3755 info_mode == INFO_MODE_ELEMENTS ? STR_INFO_ELEMENTS :
3756 info_mode == INFO_MODE_MUSIC ? STR_INFO_MUSIC :
3757 info_mode == INFO_MODE_CREDITS ? STR_INFO_CREDITS :
3758 info_mode == INFO_MODE_PROGRAM ? STR_INFO_PROGRAM :
3759 info_mode == INFO_MODE_VERSION ? STR_INFO_VERSION :
3760 info_mode == INFO_MODE_LEVELSET ? STR_INFO_LEVELSET :
3764 static int getInfoScreenBackgroundImage_Generic(void)
3766 return (info_mode == INFO_MODE_ELEMENTS ? IMG_BACKGROUND_INFO_ELEMENTS :
3767 info_mode == INFO_MODE_MUSIC ? IMG_BACKGROUND_INFO_MUSIC :
3768 info_mode == INFO_MODE_CREDITS ? IMG_BACKGROUND_INFO_CREDITS :
3769 info_mode == INFO_MODE_PROGRAM ? IMG_BACKGROUND_INFO_PROGRAM :
3770 info_mode == INFO_MODE_VERSION ? IMG_BACKGROUND_INFO_VERSION :
3771 info_mode == INFO_MODE_LEVELSET ? IMG_BACKGROUND_INFO_LEVELSET :
3772 IMG_BACKGROUND_INFO);
3775 static int getInfoScreenBackgroundSound_Generic(void)
3777 return (info_mode == INFO_MODE_ELEMENTS ? SND_BACKGROUND_INFO_ELEMENTS :
3778 info_mode == INFO_MODE_CREDITS ? SND_BACKGROUND_INFO_CREDITS :
3779 info_mode == INFO_MODE_PROGRAM ? SND_BACKGROUND_INFO_PROGRAM :
3780 info_mode == INFO_MODE_VERSION ? SND_BACKGROUND_INFO_VERSION :
3781 info_mode == INFO_MODE_LEVELSET ? SND_BACKGROUND_INFO_LEVELSET :
3782 SND_BACKGROUND_INFO);
3785 static int getInfoScreenBackgroundMusic_Generic(void)
3787 return (info_mode == INFO_MODE_ELEMENTS ? MUS_BACKGROUND_INFO_ELEMENTS :
3788 info_mode == INFO_MODE_CREDITS ? MUS_BACKGROUND_INFO_CREDITS :
3789 info_mode == INFO_MODE_PROGRAM ? MUS_BACKGROUND_INFO_PROGRAM :
3790 info_mode == INFO_MODE_VERSION ? MUS_BACKGROUND_INFO_VERSION :
3791 info_mode == INFO_MODE_LEVELSET ? MUS_BACKGROUND_INFO_LEVELSET :
3792 MUS_BACKGROUND_INFO);
3795 static char *getInfoScreenFilename_Generic(int nr, boolean global)
3797 return (info_mode == INFO_MODE_CREDITS ? getCreditsFilename(nr, global) :
3798 info_mode == INFO_MODE_PROGRAM ? getProgramInfoFilename(nr) :
3799 info_mode == INFO_MODE_LEVELSET ? getLevelSetInfoFilename(nr) :
3803 static void DrawInfoScreen_GenericScreen(int screen_nr, int num_screens,
3804 int use_global_screens)
3806 char *filename = getInfoScreenFilename_Generic(screen_nr, use_global_screens);
3807 int font_text = MENU_INFO_FONT_TEXT;
3808 int font_foot = MENU_INFO_FONT_FOOT;
3809 int spacing_line = menu.line_spacing_info[info_mode];
3810 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3814 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
3816 if (info_mode == INFO_MODE_CREDITS ||
3817 info_mode == INFO_MODE_PROGRAM)
3820 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART;
3821 int chars = width / getFontWidth(font_text);
3822 int lines = height / getFontHeight(font_text);
3823 int padx = (width - chars * getFontWidth(font_text)) / 2;
3824 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3825 boolean autowrap = FALSE;
3826 boolean centered = TRUE;
3827 boolean parse_comments = TRUE;
3829 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART,
3830 filename, font_text, chars, -1, lines, line_spacing, -1,
3831 autowrap, centered, parse_comments);
3833 else if (info_mode == INFO_MODE_LEVELSET)
3835 struct TitleMessageInfo *tmi = &readme;
3837 // if x position set to "-1", automatically determine by playfield width
3839 tmi->x = SXSIZE / 2;
3841 // if y position set to "-1", use static default value
3843 tmi->y = MENU_SCREEN_INFO_YSTART;
3845 // if width set to "-1", automatically determine by playfield width
3846 if (tmi->width == -1)
3847 tmi->width = SXSIZE - 2 * TILEX;
3849 // if height set to "-1", automatically determine by playfield height
3850 if (tmi->height == -1)
3851 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3853 // if chars set to "-1", automatically determine by text and font width
3854 if (tmi->chars == -1)
3855 tmi->chars = tmi->width / getFontWidth(tmi->font);
3857 tmi->width = tmi->chars * getFontWidth(tmi->font);
3859 // if lines set to "-1", automatically determine by text and font height
3860 if (tmi->lines == -1)
3861 tmi->lines = tmi->height / getFontHeight(tmi->font);
3863 tmi->height = tmi->lines * getFontHeight(tmi->font);
3865 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3866 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3867 tmi->autowrap, tmi->centered, tmi->parse_comments);
3870 boolean last_screen = (screen_nr == num_screens - 1);
3871 char *text_foot = (last_screen ? TEXT_NEXT_MENU : TEXT_NEXT_PAGE);
3873 DrawTextSCentered(ybottom, font_foot, text_foot);
3876 static void DrawInfoScreen_Generic(void)
3878 SetMainBackgroundImageIfDefined(getInfoScreenBackgroundImage_Generic());
3880 FadeInfoSoundsAndMusic();
3882 FadeOut(REDRAW_FIELD);
3884 HandleInfoScreen_Generic(0, 0, MB_MENU_INITIALIZE);
3886 PlayInfoSoundsAndMusic();
3888 FadeIn(REDRAW_FIELD);
3891 void HandleInfoScreen_Generic(int dx, int dy, int button)
3893 static char *text_no_info = "";
3894 static int num_screens = 0;
3895 static int screen_nr = 0;
3896 static boolean use_global_screens = FALSE;
3898 if (button == MB_MENU_INITIALIZE)
3903 if (info_mode == INFO_MODE_CREDITS)
3907 for (i = 0; i < 2; i++)
3909 use_global_screens = i; // check for "FALSE", then "TRUE"
3911 // determine number of (global or level set specific) credits screens
3912 while (getCreditsFilename(num_screens, use_global_screens) != NULL)
3915 if (num_screens > 0)
3919 text_no_info = "No credits available.";
3921 else if (info_mode == INFO_MODE_PROGRAM)
3923 use_global_screens = TRUE;
3925 // determine number of program info screens
3926 while (getProgramInfoFilename(num_screens) != NULL)
3929 text_no_info = "No program info available.";
3931 else if (info_mode == INFO_MODE_LEVELSET)
3933 use_global_screens = FALSE;
3935 // determine number of levelset info screens
3936 while (getLevelSetInfoFilename(num_screens) != NULL)
3939 text_no_info = "No level set info available.";
3942 if (num_screens == 0)
3944 int font_title = MENU_INFO_FONT_TITLE;
3945 int font_foot = MENU_INFO_FONT_FOOT;
3946 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3947 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3951 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
3953 DrawTextSCentered(ystart, font_title, text_no_info);
3954 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3959 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
3961 else if (button == MB_MENU_LEAVE)
3963 PlaySound(SND_MENU_ITEM_SELECTING);
3965 info_mode = INFO_MODE_MAIN;
3968 else if (button == MB_MENU_CHOICE || dx)
3970 PlaySound(SND_MENU_ITEM_SELECTING);
3972 screen_nr += (dx < 0 ? -1 : +1);
3974 if (screen_nr < 0 || screen_nr >= num_screens)
3976 FadeInfoSoundsAndMusic();
3978 info_mode = INFO_MODE_MAIN;
3983 FadeSetNextScreen();
3985 FadeOut(REDRAW_FIELD);
3987 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
3989 FadeIn(REDRAW_FIELD);
3994 PlayInfoSoundIfLoop();
3998 static void DrawInfoScreen(void)
4000 if (info_mode == INFO_MODE_TITLE)
4001 DrawInfoScreen_TitleScreen();
4002 else if (info_mode == INFO_MODE_ELEMENTS)
4003 DrawInfoScreen_Elements();
4004 else if (info_mode == INFO_MODE_MUSIC)
4005 DrawInfoScreen_Music();
4006 else if (info_mode == INFO_MODE_CREDITS)
4007 DrawInfoScreen_Generic();
4008 else if (info_mode == INFO_MODE_PROGRAM)
4009 DrawInfoScreen_Generic();
4010 else if (info_mode == INFO_MODE_VERSION)
4011 DrawInfoScreen_Version();
4012 else if (info_mode == INFO_MODE_LEVELSET)
4013 DrawInfoScreen_Generic();
4015 DrawInfoScreen_Main();
4018 void DrawInfoScreen_FromMainMenu(int nr)
4020 int fade_mask = REDRAW_FIELD;
4022 if (nr < INFO_MODE_MAIN || nr >= MAX_INFO_MODES)
4025 CloseDoor(DOOR_CLOSE_2);
4027 SetGameStatus(GAME_MODE_INFO);
4030 info_screens_from_main = TRUE;
4032 if (redraw_mask & REDRAW_ALL)
4033 fade_mask = REDRAW_ALL;
4036 fade_mask = REDRAW_ALL;
4039 FadeMenuSoundsAndMusic();
4041 FadeSetEnterScreen();
4045 FadeSkipNextFadeOut();
4047 // needed if different viewport properties defined for info screen
4048 ChangeViewportPropertiesIfNeeded();
4050 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
4055 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4057 if (info_mode == INFO_MODE_TITLE)
4058 HandleInfoScreen_TitleScreen(dx, dy, button);
4059 else if (info_mode == INFO_MODE_ELEMENTS)
4060 HandleInfoScreen_Elements(dx, dy, button);
4061 else if (info_mode == INFO_MODE_MUSIC)
4062 HandleInfoScreen_Music(dx, dy, button);
4063 else if (info_mode == INFO_MODE_CREDITS)
4064 HandleInfoScreen_Generic(dx, dy, button);
4065 else if (info_mode == INFO_MODE_PROGRAM)
4066 HandleInfoScreen_Generic(dx, dy, button);
4067 else if (info_mode == INFO_MODE_VERSION)
4068 HandleInfoScreen_Version(button);
4069 else if (info_mode == INFO_MODE_LEVELSET)
4070 HandleInfoScreen_Generic(dx, dy, button);
4072 HandleInfoScreen_Main(mx, my, dx, dy, button);
4076 // ============================================================================
4077 // type name functions
4078 // ============================================================================
4080 static TreeInfo *type_name_node = NULL;
4081 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4082 static int type_name_nr = 0;
4084 static int getPlayerNameColor(char *name)
4086 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4089 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4092 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4093 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4094 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4095 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4096 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4097 int font_width = getFontWidth(font_nr);
4098 int font_xoffset = getFontDrawOffsetX(font_nr);
4099 int font_yoffset = getFontDrawOffsetY(font_nr);
4100 int font_sx = sx + font_xoffset;
4101 int font_sy = sy + font_yoffset;
4103 DrawBackgroundForFont(font_sx, font_sy, pos->width, pos->height, font_nr);
4105 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4107 pos->width = strlen(text) * font_width;
4108 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4110 DrawText(sx, sy, text, font_nr);
4113 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4115 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4117 *pos = *mci->pos_input;
4119 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4121 TreeInfo *ti = player_name_current;
4122 int first_entry = ti->cl_first;
4123 int entry_pos = first_entry + ti->cl_cursor;
4124 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4125 int xpos = MENU_SCREEN_START_XPOS;
4126 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4128 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4129 type_name_nr = entry_pos;
4131 strcpy(name, type_name_node->name);
4135 pos->width = MAX_PLAYER_NAME_LEN * 32;
4139 type_name_nr = user.nr;
4141 strcpy(name, setup.player_name);
4144 strcpy(type_name_last, name);
4146 if (strEqual(name, EMPTY_PLAYER_NAME))
4149 *xpos = strlen(name);
4152 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4154 // change name of edited user in global list of user names
4155 setString(&global.user_names[type_name_nr], name);
4157 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4159 TreeInfo *node = type_name_node;
4161 // change name of edited user in local menu tree structure
4162 setString(&node->name, name);
4163 setString(&node->name_sorting, name);
4165 node->color = getPlayerNameColor(name);
4166 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4170 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4173 boolean reset_setup = strEqual(name, "");
4174 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4175 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4178 strcpy(name, type_name_last);
4180 if (strEqual(name, ""))
4181 strcpy(name, EMPTY_PLAYER_NAME);
4183 setTypeNameValues_Name(name, pos);
4185 // if player name not changed, no further action required
4186 if (strEqual(name, type_name_last))
4189 // redraw player name before (possibly) opening request dialogs
4190 drawTypeNameText(name, pos, FALSE);
4192 int last_user_nr = user.nr;
4194 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4196 // save setup of currently active user (may differ from edited user)
4199 // temporarily change active user to edited user
4200 user.nr = type_name_nr;
4203 Request("Use current setup values for the new player?", REQ_ASK))
4205 // use current setup values for new user, but create new player UUID
4206 setup.player_uuid = getStringCopy(getUUID());
4210 // load setup for existing user (or start with defaults for new user)
4215 char *setup_filename = getSetupFilename();
4216 boolean setup_exists = fileExists(setup_filename);
4218 // change name of edited user in setup structure
4219 strcpy(setup.player_name, name);
4221 // save setup of edited user
4224 // change name of edited user on score server
4225 ApiRenamePlayerAsThread();
4227 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4231 if (Request("Reset setup values for this player?", REQ_ASK))
4233 // remove setup config file
4234 unlink(setup_filename);
4236 // set player name to default player name
4239 // update player name used by name typing functions
4240 strcpy(name, setup.player_name);
4242 setTypeNameValues_Name(name, pos);
4245 else if (remove_user && type_name_nr != 0)
4247 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4249 char *user_dir = getUserGameDataDir();
4250 char *user_dir_removed =
4251 getStringCat3WithSeparator(user_dir, "REMOVED",
4252 getCurrentTimestamp(), ".");
4254 if (rename(user_dir, user_dir_removed) != 0)
4255 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4257 checked_free(user_dir_removed);
4260 else if (create_user && type_name_nr != 0 && !setup_exists)
4262 if (Request("Create empty level set for the new player?", REQ_ASK))
4264 char *levelset_subdir = getNewUserLevelSubdir();
4266 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4268 AddUserLevelSetToLevelInfo(levelset_subdir);
4270 LevelDirTree *leveldir_current_last = leveldir_current;
4272 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4275 // set level number of newly created level set to default value
4276 LoadLevelSetup_SeriesInfo();
4278 // set newly created level set as current level set for new user
4279 SaveLevelSetup_LastSeries();
4280 SaveLevelSetup_SeriesInfo();
4282 leveldir_current = leveldir_current_last;
4286 Request("Creating new level set failed!", REQ_CONFIRM);
4291 // restore currently active user
4292 user.nr = last_user_nr;
4294 // restore setup of currently active user
4297 // restore last level set of currently active user
4298 LoadLevelSetup_LastSeries();
4299 LoadLevelSetup_SeriesInfo();
4303 static void HandleTypeNameExt(boolean initialize, Key key)
4305 static struct TextPosInfo pos_name = { 0 };
4306 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4307 static int xpos = 0;
4308 struct TextPosInfo *pos = &pos_name;
4309 char key_char = getValidConfigValueChar(getCharFromKey(key));
4310 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4311 boolean active = TRUE;
4315 getTypeNameValues(name, pos, &xpos);
4317 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4318 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4320 StartTextInput(sx, sy, pos->width, pos->height);
4322 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4324 name[xpos] = key_char;
4329 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4335 else if (key == KSYM_Return || key == KSYM_Escape)
4337 boolean changed = (key == KSYM_Return);
4341 setTypeNameValues(name, pos, changed);
4346 drawTypeNameText(name, pos, active);
4350 SetGameStatus(game_status_last_screen);
4352 if (game_status == GAME_MODE_MAIN)
4353 InitializeMainControls();
4357 static void DrawTypeName(void)
4359 HandleTypeNameExt(TRUE, 0);
4362 void HandleTypeName(Key key)
4364 HandleTypeNameExt(FALSE, key);
4368 // ============================================================================
4369 // tree menu functions
4370 // ============================================================================
4372 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4374 if (game_status != GAME_MODE_SETUP ||
4375 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4378 int max_text_size = 0;
4381 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4382 max_text_size = MAX(max_text_size, strlen(node->name));
4384 int num_entries = numTreeInfoInGroup(ti);
4385 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4386 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4387 int text_width = max_text_size * getFontWidth(font_nr);
4388 int button_width = SC_MENUBUTTON_XSIZE;
4389 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4390 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4391 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4392 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4393 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4394 int align_xoffset = MAX(0, align_xoffset_raw);
4396 return align_xoffset;
4399 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4401 if (game_status != GAME_MODE_SETUP ||
4402 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4405 int num_entries = numTreeInfoInGroup(ti);
4406 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4407 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4408 int font_height = getFontHeight(font_nr);
4409 int text_height = font_height * num_page_entries;
4410 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4411 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4412 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4413 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4414 int align_yoffset = MAX(0, align_yoffset_raw);
4416 return align_yoffset;
4419 static void StartPlayingFromHallOfFame(void)
4421 level_nr = scores.next_level_nr;
4422 LoadLevel(level_nr);
4424 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4427 static void DrawChooseTree(TreeInfo **ti_ptr)
4429 int fade_mask = REDRAW_FIELD;
4430 boolean restart_music = (game_status != game_status_last_screen &&
4431 game_status_last_screen != GAME_MODE_SCOREINFO);
4433 scores.continue_on_return = (game_status == GAME_MODE_SCORES &&
4434 game_status_last_screen == GAME_MODE_PLAYING);
4437 fade_mask = REDRAW_ALL;
4439 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4441 if (game_status == GAME_MODE_SETUP)
4445 else if (game_status == GAME_MODE_SCORES && scores.continue_playing)
4447 StartPlayingFromHallOfFame();
4451 SetGameStatus(GAME_MODE_MAIN);
4461 FreeScreenGadgets();
4462 CreateScreenGadgets();
4465 FadeMenuSoundsAndMusic();
4469 // needed if different viewport properties defined for this screen
4470 ChangeViewportPropertiesIfNeeded();
4472 if (game_status == GAME_MODE_NAMES)
4473 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4474 else if (game_status == GAME_MODE_LEVELNR)
4475 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4476 else if (game_status == GAME_MODE_LEVELS)
4477 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4478 else if (game_status == GAME_MODE_SCORES)
4479 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4483 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4485 // map gadgets for high score screen
4486 if (game_status == GAME_MODE_SCORES)
4487 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4489 MapScreenTreeGadgets(*ti_ptr);
4491 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4493 DrawMaskedBorder(fade_mask);
4496 PlayMenuSoundsAndMusic();
4501 static int getChooseTreeFont(TreeInfo *node, boolean active)
4503 if (game_status == GAME_MODE_SCORES)
4504 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4506 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4509 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4511 int num_entries = numTreeInfoInGroup(ti);
4512 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4513 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4514 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4515 int first_entry = ti->cl_first;
4516 int entry_pos = first_entry + y;
4517 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4518 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4519 int font_nr = getChooseTreeFont(node, active);
4520 int font_xoffset = getFontDrawOffsetX(font_nr);
4521 int xpos = MENU_SCREEN_START_XPOS;
4522 int ypos = MENU_SCREEN_START_YPOS + y;
4523 int startdx = xpos * 32;
4524 int startdy = ypos * 32;
4525 int startx = amSX + startdx;
4526 int starty = amSY + startdy;
4527 int startx_text = startx + font_xoffset;
4528 int endx_text = amSX + screen_width;
4529 int max_text_size = endx_text - startx_text;
4530 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4531 char buffer[max_buffer_len + 1];
4533 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4535 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4536 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4537 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4538 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4539 int font_size_1 = getFontWidth(font_nr1);
4540 int font_size_3 = getFontWidth(font_nr3);
4541 int font_size_4 = getFontWidth(font_nr4);
4542 int text_size_1 = 4 * font_size_1;
4543 int text_size_4 = 5 * font_size_4;
4544 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4546 int dx3 = text_size_1;
4547 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4548 int num_dots = (dx4 - dx3) / font_size_3;
4549 int startx1 = startx + dx1;
4550 int startx3 = startx + dx3;
4551 int startx4 = startx + dx4;
4552 int pos = node->pos;
4553 char *pos_text = getHallOfFameRankText(pos, 3);
4556 DrawText(startx1, starty, pos_text, font_nr1);
4558 for (i = 0; i < num_dots; i++)
4559 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4561 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4562 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4564 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4568 strncpy(buffer, node->name, max_buffer_len);
4569 buffer[max_buffer_len] = '\0';
4571 DrawText(startx, starty, buffer, font_nr);
4575 static void drawChooseTreeHeadExt(int type, char *title_string)
4577 int yoffset_sets = MENU_TITLE1_YPOS;
4578 int yoffset_setup = 16;
4579 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4580 type == TREE_TYPE_LEVEL_DIR ||
4581 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4583 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4586 static void drawChooseTreeHead(TreeInfo *ti)
4588 drawChooseTreeHeadExt(ti->type, ti->infotext);
4591 static void drawChooseTreeList(TreeInfo *ti)
4593 int first_entry = ti->cl_first;
4594 int num_entries = numTreeInfoInGroup(ti);
4595 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4598 clearMenuListArea();
4600 for (i = 0; i < num_page_entries; i++)
4602 TreeInfo *node, *node_first;
4603 int entry_pos = first_entry + i;
4605 node_first = getTreeInfoFirstGroupEntry(ti);
4606 node = getTreeInfoFromPos(node_first, entry_pos);
4608 drawChooseTreeText(ti, i, FALSE);
4610 if (node->parent_link)
4611 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4612 else if (node->level_group)
4613 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4615 initCursor(i, IMG_MENU_BUTTON);
4617 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4618 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4620 if (game_status == GAME_MODE_NAMES)
4621 drawChooseTreeEdit(i, FALSE);
4624 redraw_mask |= REDRAW_FIELD;
4627 static void drawChooseTreeInfo(TreeInfo *ti)
4629 int entry_pos = ti->cl_first + ti->cl_cursor;
4630 int last_redraw_mask = redraw_mask;
4631 int ypos = MENU_TITLE2_YPOS;
4632 int font_nr = FONT_TITLE_2;
4635 if (ti->type == TREE_TYPE_LEVEL_NR)
4636 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4638 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4639 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4640 scores.last_level_nr);
4642 if (ti->type != TREE_TYPE_LEVEL_DIR)
4645 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4646 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4648 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4650 if (node->parent_link)
4651 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4652 node->node_parent->name);
4653 else if (node->level_group)
4654 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4656 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4657 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4658 node->levels, (node->levels > 1 ? "levels" : "level"),
4661 // let BackToFront() redraw only what is needed
4662 redraw_mask = last_redraw_mask;
4663 for (x = 0; x < SCR_FIELDX; x++)
4664 MarkTileDirty(x, 1);
4667 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4669 drawChooseTreeCursor(ti->cl_cursor, active);
4670 drawChooseTreeText(ti, ti->cl_cursor, active);
4673 static void drawChooseTreeScreen(TreeInfo *ti)
4675 drawChooseTreeHead(ti);
4676 drawChooseTreeList(ti);
4677 drawChooseTreeInfo(ti);
4678 drawChooseTreeCursorAndText(ti, TRUE);
4680 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4682 // scroll bar and buttons may just have been added after reloading scores
4683 if (game_status == GAME_MODE_SCORES)
4684 MapScreenTreeGadgets(ti);
4687 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4689 int score_pos = scores.last_added;
4691 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4692 score_pos = scores.last_entry_nr;
4694 // set current tree entry to last added score entry
4695 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4697 // if that fails, set current tree entry to first entry (back link)
4698 if (*ti_ptr == NULL)
4699 *ti_ptr = score_entries->node_group;
4701 int num_entries = numTreeInfoInGroup(*ti_ptr);
4702 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4703 int pos_score = getPosFromTreeInfo(*ti_ptr);
4704 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4705 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4707 (*ti_ptr)->cl_first = pos_first;
4708 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4713 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4716 TreeInfo *ti = *ti_ptr;
4717 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4718 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4719 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4720 int sx1_edit_name = getChooseTreeEditXPosReal(POS_LEFT);
4721 int sx2_edit_name = getChooseTreeEditXPosReal(POS_RIGHT);
4723 int y = (ti != NULL ? ti->cl_cursor : 0);
4724 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4725 int num_entries = numTreeInfoInGroup(ti);
4726 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4727 boolean position_set_by_scrollbar = (dx == 999);
4729 if (game_status == GAME_MODE_SCORES)
4731 if (server_scores.updated)
4733 // reload scores, using updated server score cache file
4734 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4736 server_scores.updated = FALSE;
4738 DrawHallOfFame_setScoreEntries();
4740 ti = setHallOfFameActiveEntry(ti_ptr);
4742 if (button != MB_MENU_INITIALIZE)
4743 drawChooseTreeScreen(ti);
4747 if (button == MB_MENU_INITIALIZE)
4749 int num_entries = numTreeInfoInGroup(ti);
4750 int entry_pos = getPosFromTreeInfo(ti);
4752 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4753 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4755 if (game_status == GAME_MODE_SCORES)
4757 ti = setHallOfFameActiveEntry(ti_ptr);
4759 else if (ti->cl_first == -1)
4761 // only on initialization
4762 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4763 ti->cl_cursor = entry_pos - ti->cl_first;
4766 else if (ti->cl_cursor >= num_page_entries ||
4767 (num_entries > num_page_entries &&
4768 num_entries - ti->cl_first < num_page_entries))
4770 // only after change of list size (by custom graphic configuration)
4771 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4772 ti->cl_cursor = entry_pos - ti->cl_first;
4775 if (position_set_by_scrollbar)
4778 drawChooseTreeScreen(ti);
4782 else if (button == MB_MENU_LEAVE)
4784 if (game_status != GAME_MODE_SCORES)
4787 PlaySound(SND_MENU_ITEM_SELECTING);
4789 if (ti->node_parent)
4791 *ti_ptr = ti->node_parent;
4792 DrawChooseTree(ti_ptr);
4794 else if (game_status == GAME_MODE_SETUP)
4796 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4797 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4798 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4799 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4801 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4802 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4803 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4804 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4805 execSetupGraphics();
4806 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4807 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4808 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4810 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4811 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4812 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4813 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4814 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4815 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4816 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4817 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4824 if (game_status == GAME_MODE_LEVELNR)
4826 int new_level_nr = atoi(level_number_current->identifier);
4828 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4831 SetGameStatus(GAME_MODE_MAIN);
4839 #if defined(PLATFORM_ANDROID)
4840 // directly continue when touching the screen after playing
4841 if ((mx || my) && scores.continue_on_return)
4843 // ignore touch events until released
4848 // any mouse click or cursor key stops leaving scores by "Return" key
4849 if ((mx || my || dx || dy) && scores.continue_on_return)
4851 scores.continue_on_return = FALSE;
4852 level_nr = scores.last_level_nr;
4853 LoadLevel(level_nr);
4856 if (mx || my) // mouse input
4858 x = (mx - amSX) / 32;
4859 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4861 if (game_status == GAME_MODE_NAMES)
4862 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4864 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4866 // move cursor instead of scrolling when already at start/end of list
4867 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4869 else if (dy == +1 * SCROLL_LINE &&
4870 ti->cl_first + num_page_entries == num_entries)
4873 // handle scrolling screen one line or page
4874 if (ti->cl_cursor + dy < 0 ||
4875 ti->cl_cursor + dy > num_page_entries - 1)
4877 boolean redraw = FALSE;
4879 if (ABS(dy) == SCROLL_PAGE)
4880 step = num_page_entries - 1;
4882 if (dy < 0 && ti->cl_first > 0)
4884 // scroll page/line up
4886 ti->cl_first -= step;
4887 if (ti->cl_first < 0)
4892 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4894 // scroll page/line down
4896 ti->cl_first += step;
4897 if (ti->cl_first + num_page_entries > num_entries)
4898 ti->cl_first = MAX(0, num_entries - num_page_entries);
4904 drawChooseTreeScreen(ti);
4909 // handle moving cursor one line
4910 y = ti->cl_cursor + dy;
4913 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
4915 HandleHallOfFame_SelectLevel(1, dx);
4921 TreeInfo *node_first, *node_cursor;
4922 int entry_pos = ti->cl_first + y;
4924 node_first = getTreeInfoFirstGroupEntry(ti);
4925 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4927 if (node_cursor->node_group)
4931 PlaySound(SND_MENU_ITEM_SELECTING);
4933 node_cursor->cl_first = ti->cl_first;
4934 node_cursor->cl_cursor = ti->cl_cursor;
4936 *ti_ptr = node_cursor->node_group;
4937 DrawChooseTree(ti_ptr);
4942 else if ((dx == -1 || button == MB_MENU_CONTINUE) && ti->node_parent)
4944 if (game_status != GAME_MODE_SCORES)
4947 PlaySound(SND_MENU_ITEM_SELECTING);
4949 *ti_ptr = ti->node_parent;
4950 DrawChooseTree(ti_ptr);
4955 if (!anyScrollbarGadgetActive() &&
4956 IN_VIS_MENU(x, y) &&
4957 mx < mx_right_border &&
4958 y >= 0 && y < num_page_entries)
4962 if (game_status == GAME_MODE_NAMES)
4964 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4965 drawChooseTreeEdit(y, TRUE);
4968 if (y != ti->cl_cursor)
4970 PlaySound(SND_MENU_ITEM_ACTIVATING);
4972 drawChooseTreeCursorAndText(ti, FALSE);
4976 drawChooseTreeCursorAndText(ti, TRUE);
4978 drawChooseTreeInfo(ti);
4982 if (game_status == GAME_MODE_SETUP)
4984 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4985 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4986 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4987 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4989 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4990 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4991 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4992 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4993 execSetupGraphics();
4994 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4995 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4996 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4998 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4999 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5000 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5001 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5002 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5003 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5004 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5005 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5014 TreeInfo *node_first, *node_cursor;
5015 int entry_pos = ti->cl_first + y;
5017 PlaySound(SND_MENU_ITEM_SELECTING);
5019 node_first = getTreeInfoFirstGroupEntry(ti);
5020 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5022 if (node_cursor->node_group)
5026 node_cursor->cl_first = ti->cl_first;
5027 node_cursor->cl_cursor = ti->cl_cursor;
5029 *ti_ptr = node_cursor->node_group;
5030 DrawChooseTree(ti_ptr);
5032 else if (node_cursor->parent_link)
5034 if (game_status != GAME_MODE_SCORES)
5037 *ti_ptr = node_cursor->node_parent;
5038 DrawChooseTree(ti_ptr);
5042 if (game_status != GAME_MODE_SCORES)
5045 node_cursor->cl_first = ti->cl_first;
5046 node_cursor->cl_cursor = ti->cl_cursor;
5048 *ti_ptr = node_cursor;
5050 if (ti->type == TREE_TYPE_LEVEL_DIR)
5052 LoadLevelSetup_SeriesInfo();
5054 SaveLevelSetup_LastSeries();
5055 SaveLevelSetup_SeriesInfo();
5059 if (game_status == GAME_MODE_SETUP)
5061 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5062 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5063 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5064 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5066 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5067 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5068 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5069 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5070 execSetupGraphics();
5071 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5072 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5073 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5075 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5076 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5077 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5078 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5079 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5080 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5081 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5082 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5089 if (game_status == GAME_MODE_LEVELNR)
5091 int new_level_nr = atoi(level_number_current->identifier);
5093 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5095 else if (game_status == GAME_MODE_LEVELS)
5097 // store level set if chosen from "last played level set" menu
5098 StoreLastPlayedLevels(leveldir_current);
5100 else if (game_status == GAME_MODE_NAMES)
5102 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5104 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5111 // change active user to selected user
5112 user.nr = entry_pos;
5114 // save number of new active user
5117 // load setup of new active user
5120 // load last level set of new active user
5121 LoadLevelSetup_LastSeries();
5122 LoadLevelSetup_SeriesInfo();
5124 // update list of last played level sets
5125 UpdateLastPlayedLevels_TreeInfo();
5129 ToggleFullscreenIfNeeded();
5130 ChangeWindowScalingIfNeeded();
5132 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5133 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5134 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5136 else if (game_status == GAME_MODE_SCORES)
5138 if (scores.continue_playing && scores.continue_on_return)
5140 StartPlayingFromHallOfFame();
5144 else if (!scores.continue_on_return)
5146 SetGameStatus(GAME_MODE_SCOREINFO);
5148 DrawScoreInfo(node_cursor->pos);
5154 SetGameStatus(GAME_MODE_MAIN);
5162 if (game_status == GAME_MODE_SCORES)
5163 PlayMenuSoundIfLoop();
5166 void DrawChoosePlayerName(void)
5170 if (player_name != NULL)
5172 freeTreeInfo(player_name);
5177 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5179 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5180 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5183 ti->node_top = &player_name;
5184 ti->sort_priority = 10000 + value;
5185 ti->color = getPlayerNameColor(global.user_names[i]);
5187 snprintf(identifier, sizeof(identifier), "%d", value);
5188 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5190 setString(&ti->identifier, identifier);
5191 setString(&ti->name, name);
5192 setString(&ti->name_sorting, name);
5194 pushTreeInfo(&player_name, ti);
5197 // sort player entries by player number
5198 sortTreeInfo(&player_name);
5200 // set current player entry to selected player entry
5201 player_name_current =
5202 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5204 // if that fails, set current player name to first available name
5205 if (player_name_current == NULL)
5206 player_name_current = player_name;
5208 // set text size for main name input (also used on name selection screen)
5209 InitializeMainControls();
5211 DrawChooseTree(&player_name_current);
5214 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5216 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5219 void DrawChooseLevelSet(void)
5221 DrawChooseTree(&leveldir_current);
5224 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5226 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5229 void DrawChooseLevelNr(void)
5233 if (level_number != NULL)
5235 freeTreeInfo(level_number);
5237 level_number = NULL;
5240 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5242 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5243 char identifier[32], name[64];
5246 // temporarily load level info to get level name
5247 LoadLevelInfoOnly(i);
5249 ti->node_top = &level_number;
5250 ti->sort_priority = 10000 + value;
5251 ti->color = (level.no_level_file ? FC_BLUE :
5252 LevelStats_getSolved(i) ? FC_GREEN :
5253 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5255 snprintf(identifier, sizeof(identifier), "%d", value);
5256 snprintf(name, sizeof(name), "%03d: %s", value,
5257 (level.no_level_file ? "(no file)" : level.name));
5259 setString(&ti->identifier, identifier);
5260 setString(&ti->name, name);
5261 setString(&ti->name_sorting, name);
5263 pushTreeInfo(&level_number, ti);
5266 // sort level number values to start with lowest level number
5267 sortTreeInfo(&level_number);
5269 // set current level number to current level number
5270 level_number_current =
5271 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5273 // if that also fails, set current level number to first available level
5274 if (level_number_current == NULL)
5275 level_number_current = level_number;
5277 DrawChooseTree(&level_number_current);
5280 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5282 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5285 static void DrawHallOfFame_setScoreEntries(void)
5287 int max_empty_entries = 10; // at least show "top ten" list, if empty
5288 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5289 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5290 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5293 if (score_entries != NULL)
5295 freeTreeInfo(score_entries);
5297 score_entries = NULL;
5300 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5302 // do not add empty score entries if off-screen
5303 if (scores.entry[i].score == 0 &&
5304 scores.entry[i].time == 0 &&
5305 i >= min_score_entries)
5308 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5309 char identifier[32], name[64];
5312 ti->node_top = &score_entries;
5313 ti->sort_priority = 10000 + value;
5314 ti->color = FC_YELLOW;
5317 snprintf(identifier, sizeof(identifier), "%d", value);
5318 snprintf(name, sizeof(name), "%03d.", value + 1);
5320 setString(&ti->identifier, identifier);
5321 setString(&ti->name, name);
5322 setString(&ti->name_sorting, name);
5324 pushTreeInfo(&score_entries, ti);
5327 // sort score entries to start with highest score entry
5328 sortTreeInfo(&score_entries);
5330 // add top tree node to create back link to main menu
5331 score_entries = addTopTreeInfoNode(score_entries);
5333 // set current score entry to last added or highest score entry
5334 score_entry_current =
5335 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5337 // if that fails, set current score entry to first valid score entry
5338 if (score_entry_current == NULL)
5339 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5341 if (score_entries != NULL && scores.continue_playing)
5342 setString(&score_entries->node_group->name, BACKLINK_TEXT_NEXT);
5345 void DrawHallOfFame(int nr)
5347 scores.last_level_nr = nr;
5349 // (this is needed when called from GameEnd() after winning a game)
5350 KeyboardAutoRepeatOn();
5352 // (this is needed when called from GameEnd() after winning a game)
5353 SetDrawDeactivationMask(REDRAW_NONE);
5354 SetDrawBackgroundMask(REDRAW_FIELD);
5356 LoadLocalAndServerScore(scores.last_level_nr, TRUE);
5358 DrawHallOfFame_setScoreEntries();
5360 if (scores.last_added >= 0)
5361 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5363 FadeSetEnterScreen();
5365 DrawChooseTree(&score_entry_current);
5368 static char *getHallOfFameRankText(int nr, int size)
5370 static char rank_text[10];
5371 boolean forced = (scores.force_last_added && nr == scores.last_added);
5372 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5374 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5379 static char *getHallOfFameTimeText(int nr)
5381 static char score_text[10];
5382 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5383 int mm = (time_seconds / 60) % 60;
5384 int ss = (time_seconds % 60);
5386 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5391 static char *getHallOfFameScoreText(int nr, int size)
5393 if (!level.rate_time_over_score)
5394 return int2str(scores.entry[nr].score, size); // show normal score
5395 else if (level.use_step_counter)
5396 return int2str(scores.entry[nr].time, size); // show number of steps
5398 return getHallOfFameTimeText(nr); // show playing time
5401 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5403 static char tape_date[MAX_ISO_DATE_LEN + 1];
5406 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5407 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5408 return entry->tape_date;
5410 for (i = 0, j = 0; i < 8; i++, j++)
5412 tape_date[j] = entry->tape_basename[i];
5414 if (i == 3 || i == 5)
5415 tape_date[++j] = '-';
5418 tape_date[MAX_ISO_DATE_LEN] = '\0';
5423 static void HandleHallOfFame_SelectLevel(int step, int direction)
5425 int old_level_nr = scores.last_level_nr;
5426 int new_level_nr = old_level_nr + step * direction;
5428 if (new_level_nr < leveldir_current->first_level)
5429 new_level_nr = leveldir_current->first_level;
5430 if (new_level_nr > leveldir_current->last_level)
5431 new_level_nr = leveldir_current->last_level;
5433 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5434 new_level_nr = leveldir_current->handicap_level;
5436 if (new_level_nr != old_level_nr)
5438 PlaySound(SND_MENU_ITEM_SELECTING);
5440 scores.last_level_nr = level_nr = new_level_nr;
5441 scores.last_entry_nr = 0;
5443 LoadLevel(level_nr);
5444 LoadLocalAndServerScore(level_nr, TRUE);
5446 DrawHallOfFame_setScoreEntries();
5448 if (game_status == GAME_MODE_SCORES)
5450 // force remapping optional gadgets (especially scroll bar)
5451 UnmapScreenTreeGadgets();
5453 // redraw complete high score screen, as sub-title has changed
5456 // redraw level selection buttons (which have just been erased)
5457 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5459 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5463 DrawScoreInfo_Content(scores.last_entry_nr);
5466 SaveLevelSetup_SeriesInfo();
5470 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5472 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5475 static void DrawScoreInfo_Content(int entry_nr)
5477 struct ScoreEntry *entry = &scores.entry[entry_nr];
5478 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5479 char *tape_date = getHallOfFameTapeDateText(entry);
5480 int font_head = MENU_INFO_FONT_HEAD;
5481 int font_text = MENU_INFO_FONT_TEXT;
5482 int font_foot = MENU_INFO_FONT_FOOT;
5483 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5484 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5485 int xstep = getFontWidth(font_text);
5486 int ystep_para = getMenuTextStep(spacing_para, font_text);
5487 int ystep_line = getMenuTextStep(spacing_line, font_text);
5488 int xstart = mSX - SX + menu.left_spacing[GAME_MODE_SCOREINFO];
5489 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5490 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5491 int xstart1 = xstart + xstep;
5492 int xstart2 = xstart + xstep * 12;
5493 int select_x = SX + xstart1;
5494 int select_y1, select_y2;
5496 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5497 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5498 int font_width = getFontWidth(font_text);
5499 int font_height = getFontHeight(font_text);
5500 int tape_date_width = getTextWidth(tape_date, font_text);
5501 int pad_left = xstart2;
5502 int pad_right = menu.right_spacing[GAME_MODE_SCOREINFO];
5503 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5504 int max_lines_per_text = 5;
5509 // redraw level selection buttons (which have just been erased)
5510 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5512 drawChooseTreeHead(score_entries);
5513 drawChooseTreeInfo(score_entries);
5515 DrawTextF(xstart1, ystart, font_head, "Level Set");
5516 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5517 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5518 TRUE, FALSE, FALSE);
5519 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5521 DrawTextF(xstart1, ystart, font_head, "Level");
5522 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5523 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5524 TRUE, FALSE, FALSE);
5525 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5527 select_y1 = SY + ystart;
5528 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5530 DrawTextF(xstart1, ystart, font_head, "Rank");
5531 DrawTextF(xstart2, ystart, font_text, pos_text);
5532 ystart += ystep_line;
5534 DrawTextF(xstart1, ystart, font_head, "Player");
5535 DrawTextF(xstart2, ystart, font_text, entry->name);
5536 ystart += ystep_line;
5538 if (level.use_step_counter)
5540 DrawTextF(xstart1, ystart, font_head, "Steps");
5541 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5542 ystart += ystep_line;
5546 DrawTextF(xstart1, ystart, font_head, "Time");
5547 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5548 ystart += ystep_line;
5551 if (!level.rate_time_over_score || entry->score > 0)
5553 DrawTextF(xstart1, ystart, font_head, "Score");
5554 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5555 ystart += ystep_line;
5558 ystart += ystep_line;
5560 play_x = SX + xstart2 + tape_date_width + font_width;
5561 play_y = SY + ystart + (font_height - play_height) / 2;
5563 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5564 DrawTextF(xstart2, ystart, font_text, tape_date);
5565 ystart += ystep_line;
5567 DrawTextF(xstart1, ystart, font_head, "Platform");
5568 DrawTextF(xstart2, ystart, font_text, entry->platform);
5569 ystart += ystep_line;
5571 DrawTextF(xstart1, ystart, font_head, "Version");
5572 DrawTextF(xstart2, ystart, font_text, entry->version);
5573 ystart += ystep_line;
5575 DrawTextF(xstart1, ystart, font_head, "Country");
5576 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5577 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5578 TRUE, FALSE, FALSE);
5579 ystart += ystep_line;
5581 select_y2 = SY + ystart;
5583 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5585 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5586 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5589 static void DrawScoreInfo(int entry_nr)
5591 scores.last_entry_nr = entry_nr;
5592 score_info_tape_play = FALSE;
5596 FreeScreenGadgets();
5597 CreateScreenGadgets();
5599 FadeOut(REDRAW_FIELD);
5601 // needed if different viewport properties defined after playing score tape
5602 ChangeViewportPropertiesIfNeeded();
5604 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
5605 SetDrawDeactivationMask(REDRAW_NONE);
5606 SetDrawBackgroundMask(REDRAW_FIELD);
5608 // needed if different background image defined after playing score tape
5609 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5610 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5612 // special compatibility handling for "Snake Bite" graphics set
5613 if (strPrefix(leveldir_current->identifier, "snake_bite"))
5614 ClearRectangle(gfx.background_bitmap, gfx.real_sx, gfx.real_sy + 64,
5615 gfx.full_sxsize, gfx.full_sysize - 64);
5617 DrawScoreInfo_Content(entry_nr);
5619 // map gadgets for score info screen
5620 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5622 FadeIn(REDRAW_FIELD);
5625 static void HandleScoreInfo_SelectScore(int step, int direction)
5627 int old_entry_nr = scores.last_entry_nr;
5628 int new_entry_nr = old_entry_nr + step * direction;
5629 int num_nodes = numTreeInfoInGroup(score_entry_current);
5630 int num_entries = num_nodes - 1; // score nodes only, without back link
5632 if (new_entry_nr < 0)
5634 if (new_entry_nr > num_entries - 1)
5635 new_entry_nr = num_entries - 1;
5637 if (new_entry_nr != old_entry_nr)
5639 scores.last_entry_nr = new_entry_nr;
5641 DrawScoreInfo_Content(new_entry_nr);
5645 static void HandleScoreInfo_PlayTape(void)
5647 if (!PlayScoreTape(scores.last_entry_nr))
5649 DrawScoreInfo_Content(scores.last_entry_nr);
5651 FadeIn(REDRAW_FIELD);
5655 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5657 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5658 boolean button_is_valid = (mx >= 0 && my >= 0);
5659 boolean button_screen_clicked = (button_action && button_is_valid);
5661 if (server_scores.updated)
5663 // reload scores, using updated server score cache file
5664 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5666 server_scores.updated = FALSE;
5668 DrawHallOfFame_setScoreEntries();
5670 DrawScoreInfo_Content(scores.last_entry_nr);
5673 if (button_screen_clicked)
5675 PlaySound(SND_MENU_ITEM_SELECTING);
5677 SetGameStatus(GAME_MODE_SCORES);
5679 DrawHallOfFame(scores.last_level_nr);
5683 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5687 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5692 // ============================================================================
5693 // setup screen functions
5694 // ============================================================================
5696 static struct TokenInfo *setup_info;
5697 static int num_setup_info; // number of setup entries shown on screen
5698 static int max_setup_info; // total number of setup entries in list
5700 static char *window_size_text;
5701 static char *scaling_type_text;
5702 static char *rendering_mode_text;
5703 static char *vsync_mode_text;
5704 static char *scroll_delay_text;
5705 static char *snapshot_mode_text;
5706 static char *game_speed_text;
5707 static char *scores_type_text;
5708 static char *network_server_text;
5709 static char *graphics_set_name;
5710 static char *sounds_set_name;
5711 static char *music_set_name;
5712 static char *volume_simple_text;
5713 static char *volume_loops_text;
5714 static char *volume_music_text;
5715 static char *touch_controls_text;
5716 static char *move_distance_text;
5717 static char *drop_distance_text;
5718 static char *transparency_text;
5719 static char *grid_size_text[2][2];
5721 static void execSetupMain(void)
5723 setup_mode = SETUP_MODE_MAIN;
5728 static void execSetupGame_setScoresType(void)
5730 if (scores_types == NULL)
5734 for (i = 0; scores_types_list[i].value != NULL; i++)
5736 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5737 char identifier[32], name[32];
5738 char *value = scores_types_list[i].value;
5739 char *text = scores_types_list[i].text;
5741 ti->node_top = &scores_types;
5742 ti->sort_priority = i;
5744 sprintf(identifier, "%s", value);
5745 sprintf(name, "%s", text);
5747 setString(&ti->identifier, identifier);
5748 setString(&ti->name, name);
5749 setString(&ti->name_sorting, name);
5750 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5752 pushTreeInfo(&scores_types, ti);
5755 // sort scores type values to start with lowest scores type value
5756 sortTreeInfo(&scores_types);
5758 // set current scores type value to configured scores type value
5759 scores_type_current =
5760 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5762 // if that fails, set current scores type to reliable default value
5763 if (scores_type_current == NULL)
5764 scores_type_current =
5765 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5767 // if that also fails, set current scores type to first available value
5768 if (scores_type_current == NULL)
5769 scores_type_current = scores_types;
5772 setup.scores_in_highscore_list = scores_type_current->identifier;
5774 // needed for displaying scores type text instead of identifier
5775 scores_type_text = scores_type_current->name;
5778 static void execSetupGame_setGameSpeeds(boolean update_value)
5780 if (setup.game_speed_extended)
5782 game_speeds_list = game_speeds_list_extended;
5783 game_speeds = game_speeds_extended;
5787 game_speeds_list = game_speeds_list_normal;
5788 game_speeds = game_speeds_normal;
5791 if (game_speeds == NULL)
5795 for (i = 0; game_speeds_list[i].value != -1; i++)
5797 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5798 char identifier[32], name[32];
5799 int value = game_speeds_list[i].value;
5800 char *text = game_speeds_list[i].text;
5802 ti->node_top = &game_speeds;
5803 ti->sort_priority = 10000 - value;
5805 sprintf(identifier, "%d", value);
5806 sprintf(name, "%s", text);
5808 setString(&ti->identifier, identifier);
5809 setString(&ti->name, name);
5810 setString(&ti->name_sorting, name);
5811 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5813 pushTreeInfo(&game_speeds, ti);
5816 // sort game speed values to start with slowest game speed
5817 sortTreeInfo(&game_speeds);
5819 update_value = TRUE;
5824 // set current game speed to configured game speed value
5825 game_speed_current =
5826 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5828 // if that fails, set current game speed to reliable default value
5829 if (game_speed_current == NULL)
5830 game_speed_current =
5831 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5833 // if that also fails, set current game speed to first available speed
5834 if (game_speed_current == NULL)
5835 game_speed_current = game_speeds;
5837 if (setup.game_speed_extended)
5838 game_speeds_extended = game_speeds;
5840 game_speeds_normal = game_speeds;
5843 setup.game_frame_delay = atoi(game_speed_current->identifier);
5845 // needed for displaying game speed text instead of identifier
5846 game_speed_text = game_speed_current->name;
5849 static void execSetupGame_setScrollDelays(void)
5851 if (scroll_delays == NULL)
5855 for (i = 0; scroll_delays_list[i].value != -1; i++)
5857 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5858 char identifier[32], name[32];
5859 int value = scroll_delays_list[i].value;
5860 char *text = scroll_delays_list[i].text;
5862 ti->node_top = &scroll_delays;
5863 ti->sort_priority = value;
5865 sprintf(identifier, "%d", value);
5866 sprintf(name, "%s", text);
5868 setString(&ti->identifier, identifier);
5869 setString(&ti->name, name);
5870 setString(&ti->name_sorting, name);
5871 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5873 pushTreeInfo(&scroll_delays, ti);
5876 // sort scroll delay values to start with lowest scroll delay value
5877 sortTreeInfo(&scroll_delays);
5879 // set current scroll delay value to configured scroll delay value
5880 scroll_delay_current =
5881 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5883 // if that fails, set current scroll delay to reliable default value
5884 if (scroll_delay_current == NULL)
5885 scroll_delay_current =
5886 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5888 // if that also fails, set current scroll delay to first available value
5889 if (scroll_delay_current == NULL)
5890 scroll_delay_current = scroll_delays;
5893 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5895 // needed for displaying scroll delay text instead of identifier
5896 scroll_delay_text = scroll_delay_current->name;
5899 static void execSetupGame_setSnapshotModes(void)
5901 if (snapshot_modes == NULL)
5905 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5907 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5908 char identifier[32], name[32];
5909 char *value = snapshot_modes_list[i].value;
5910 char *text = snapshot_modes_list[i].text;
5912 ti->node_top = &snapshot_modes;
5913 ti->sort_priority = i;
5915 sprintf(identifier, "%s", value);
5916 sprintf(name, "%s", text);
5918 setString(&ti->identifier, identifier);
5919 setString(&ti->name, name);
5920 setString(&ti->name_sorting, name);
5921 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5923 pushTreeInfo(&snapshot_modes, ti);
5926 // sort snapshot mode values to start with lowest snapshot mode value
5927 sortTreeInfo(&snapshot_modes);
5929 // set current snapshot mode value to configured snapshot mode value
5930 snapshot_mode_current =
5931 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5933 // if that fails, set current snapshot mode to reliable default value
5934 if (snapshot_mode_current == NULL)
5935 snapshot_mode_current =
5936 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5938 // if that also fails, set current snapshot mode to first available value
5939 if (snapshot_mode_current == NULL)
5940 snapshot_mode_current = snapshot_modes;
5943 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5945 // needed for displaying snapshot mode text instead of identifier
5946 snapshot_mode_text = snapshot_mode_current->name;
5949 static void execSetupGame_setNetworkServerText(void)
5951 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5953 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5957 strncpy(network_server_hostname, setup.network_server_hostname,
5958 MAX_SETUP_TEXT_INPUT_LEN);
5959 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5962 // needed for displaying network server text instead of identifier
5963 network_server_text = network_server_hostname;
5966 static void execSetupGame(void)
5968 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5970 execSetupGame_setGameSpeeds(FALSE);
5971 execSetupGame_setScoresType();
5972 execSetupGame_setScrollDelays();
5973 execSetupGame_setSnapshotModes();
5975 execSetupGame_setNetworkServerText();
5977 if (!setup.provide_uploading_tapes)
5978 setHideSetupEntry(execOfferUploadTapes);
5980 setup_mode = SETUP_MODE_GAME;
5984 // check if vsync needs to be disabled for this game speed to work
5985 if (check_vsync_mode)
5986 DisableVsyncIfNeeded();
5989 static void execSetupChooseScoresType(void)
5991 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
5996 static void execSetupChooseGameSpeed(void)
5998 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6003 static void execSetupChooseScrollDelay(void)
6005 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6010 static void execSetupChooseSnapshotMode(void)
6012 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6017 static void execSetupEngines(void)
6019 setup_mode = SETUP_MODE_ENGINES;
6024 static void execSetupEditor(void)
6026 setup_mode = SETUP_MODE_EDITOR;
6031 static void execSetupGraphics_setWindowSizes(boolean update_list)
6033 if (window_sizes != NULL && update_list)
6035 freeTreeInfo(window_sizes);
6037 window_sizes = NULL;
6040 if (window_sizes == NULL)
6042 boolean current_window_size_found = FALSE;
6045 for (i = 0; window_sizes_list[i].value != -1; i++)
6047 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6048 char identifier[32], name[32];
6049 int value = window_sizes_list[i].value;
6050 char *text = window_sizes_list[i].text;
6052 ti->node_top = &window_sizes;
6053 ti->sort_priority = value;
6055 sprintf(identifier, "%d", value);
6056 sprintf(name, "%s", text);
6058 setString(&ti->identifier, identifier);
6059 setString(&ti->name, name);
6060 setString(&ti->name_sorting, name);
6061 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6063 pushTreeInfo(&window_sizes, ti);
6065 if (value == setup.window_scaling_percent)
6066 current_window_size_found = TRUE;
6069 if (!current_window_size_found)
6071 // add entry for non-preset window scaling value
6073 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6074 char identifier[32], name[32];
6075 int value = setup.window_scaling_percent;
6077 ti->node_top = &window_sizes;
6078 ti->sort_priority = value;
6080 sprintf(identifier, "%d", value);
6081 sprintf(name, "%d %% (Current)", value);
6083 setString(&ti->identifier, identifier);
6084 setString(&ti->name, name);
6085 setString(&ti->name_sorting, name);
6086 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6088 pushTreeInfo(&window_sizes, ti);
6091 // sort window size values to start with lowest window size value
6092 sortTreeInfo(&window_sizes);
6094 // set current window size value to configured window size value
6095 window_size_current =
6096 getTreeInfoFromIdentifier(window_sizes,
6097 i_to_a(setup.window_scaling_percent));
6099 // if that fails, set current window size to reliable default value
6100 if (window_size_current == NULL)
6101 window_size_current =
6102 getTreeInfoFromIdentifier(window_sizes,
6103 i_to_a(STD_WINDOW_SCALING_PERCENT));
6105 // if that also fails, set current window size to first available value
6106 if (window_size_current == NULL)
6107 window_size_current = window_sizes;
6110 setup.window_scaling_percent = atoi(window_size_current->identifier);
6112 // needed for displaying window size text instead of identifier
6113 window_size_text = window_size_current->name;
6116 static void execSetupGraphics_setScalingTypes(void)
6118 if (scaling_types == NULL)
6122 for (i = 0; scaling_types_list[i].value != NULL; i++)
6124 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6125 char identifier[32], name[32];
6126 char *value = scaling_types_list[i].value;
6127 char *text = scaling_types_list[i].text;
6129 ti->node_top = &scaling_types;
6130 ti->sort_priority = i;
6132 sprintf(identifier, "%s", value);
6133 sprintf(name, "%s", text);
6135 setString(&ti->identifier, identifier);
6136 setString(&ti->name, name);
6137 setString(&ti->name_sorting, name);
6138 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6140 pushTreeInfo(&scaling_types, ti);
6143 // sort scaling type values to start with lowest scaling type value
6144 sortTreeInfo(&scaling_types);
6146 // set current scaling type value to configured scaling type value
6147 scaling_type_current =
6148 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6150 // if that fails, set current scaling type to reliable default value
6151 if (scaling_type_current == NULL)
6152 scaling_type_current =
6153 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6155 // if that also fails, set current scaling type to first available value
6156 if (scaling_type_current == NULL)
6157 scaling_type_current = scaling_types;
6160 setup.window_scaling_quality = scaling_type_current->identifier;
6162 // needed for displaying scaling type text instead of identifier
6163 scaling_type_text = scaling_type_current->name;
6166 static void execSetupGraphics_setRenderingModes(void)
6168 if (rendering_modes == NULL)
6172 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6174 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6175 char identifier[32], name[32];
6176 char *value = rendering_modes_list[i].value;
6177 char *text = rendering_modes_list[i].text;
6179 ti->node_top = &rendering_modes;
6180 ti->sort_priority = i;
6182 sprintf(identifier, "%s", value);
6183 sprintf(name, "%s", text);
6185 setString(&ti->identifier, identifier);
6186 setString(&ti->name, name);
6187 setString(&ti->name_sorting, name);
6188 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6190 pushTreeInfo(&rendering_modes, ti);
6193 // sort rendering mode values to start with lowest rendering mode value
6194 sortTreeInfo(&rendering_modes);
6196 // set current rendering mode value to configured rendering mode value
6197 rendering_mode_current =
6198 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6200 // if that fails, set current rendering mode to reliable default value
6201 if (rendering_mode_current == NULL)
6202 rendering_mode_current =
6203 getTreeInfoFromIdentifier(rendering_modes,
6204 STR_SPECIAL_RENDERING_DEFAULT);
6206 // if that also fails, set current rendering mode to first available one
6207 if (rendering_mode_current == NULL)
6208 rendering_mode_current = rendering_modes;
6211 setup.screen_rendering_mode = rendering_mode_current->identifier;
6213 // needed for displaying rendering mode text instead of identifier
6214 rendering_mode_text = rendering_mode_current->name;
6217 static void execSetupGraphics_setVsyncModes(boolean update_value)
6219 if (vsync_modes == NULL)
6223 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6225 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6226 char identifier[32], name[32];
6227 char *value = vsync_modes_list[i].value;
6228 char *text = vsync_modes_list[i].text;
6230 ti->node_top = &vsync_modes;
6231 ti->sort_priority = i;
6233 sprintf(identifier, "%s", value);
6234 sprintf(name, "%s", text);
6236 setString(&ti->identifier, identifier);
6237 setString(&ti->name, name);
6238 setString(&ti->name_sorting, name);
6239 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6241 pushTreeInfo(&vsync_modes, ti);
6244 // sort vsync mode values to start with lowest vsync mode value
6245 sortTreeInfo(&vsync_modes);
6247 update_value = TRUE;
6252 // set current vsync mode value to configured vsync mode value
6253 vsync_mode_current =
6254 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6256 // if that fails, set current vsync mode to reliable default value
6257 if (vsync_mode_current == NULL)
6258 vsync_mode_current =
6259 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6261 // if that also fails, set current vsync mode to first available one
6262 if (vsync_mode_current == NULL)
6263 vsync_mode_current = vsync_modes;
6266 setup.vsync_mode = vsync_mode_current->identifier;
6268 // needed for displaying vsync mode text instead of identifier
6269 vsync_mode_text = vsync_mode_current->name;
6272 static void execSetupGraphics(void)
6274 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6276 // update "setup.window_scaling_percent" from list selection
6277 // (in this case, window scaling was changed on setup screen)
6278 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6279 execSetupGraphics_setWindowSizes(FALSE);
6281 // update "setup.vsync_mode" from list selection
6282 // (in this case, vsync mode was changed on setup screen)
6283 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6284 execSetupGraphics_setVsyncModes(FALSE);
6286 // update list selection from "setup.window_scaling_percent"
6287 // (window scaling may have changed by resizing the window)
6288 execSetupGraphics_setWindowSizes(TRUE);
6290 // update list selection from "setup.vsync_mode"
6291 // (vsync_mode may have changed by re-creating the renderer)
6292 execSetupGraphics_setVsyncModes(TRUE);
6294 execSetupGraphics_setScalingTypes();
6295 execSetupGraphics_setRenderingModes();
6297 setup_mode = SETUP_MODE_GRAPHICS;
6301 // check if game speed is high enough for 60 Hz vsync to work
6302 if (check_game_speed)
6303 ModifyGameSpeedIfNeeded();
6305 // window scaling may have changed at this point
6306 ChangeWindowScalingIfNeeded();
6308 // window scaling quality may have changed at this point
6309 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6310 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6312 // screen rendering mode may have changed at this point
6313 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6315 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6316 int video_vsync_mode = video.vsync_mode;
6318 // screen vsync mode may have changed at this point
6319 ChangeVsyncModeIfNeeded();
6321 // check if setting vsync mode to selected value failed
6322 if (setup_vsync_mode != video_vsync_mode &&
6323 setup_vsync_mode != video.vsync_mode)
6325 // changing vsync mode to selected value failed -- reset displayed value
6326 execSetupGraphics_setVsyncModes(TRUE);
6328 Request("Setting VSync failed!", REQ_CONFIRM);
6334 static void execSetupChooseWindowSize(void)
6336 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6341 static void execSetupChooseScalingType(void)
6343 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6348 static void execSetupChooseRenderingMode(void)
6350 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6355 static void execSetupChooseVsyncMode(void)
6357 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6362 static void execSetupChooseVolumeSimple(void)
6364 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6369 static void execSetupChooseVolumeLoops(void)
6371 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6376 static void execSetupChooseVolumeMusic(void)
6378 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6383 static void execSetupSound(void)
6385 if (volumes_simple == NULL)
6387 boolean current_volume_simple_found = FALSE;
6390 for (i = 0; volumes_list[i].value != -1; i++)
6392 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6393 char identifier[32], name[32];
6394 int value = volumes_list[i].value;
6395 char *text = volumes_list[i].text;
6397 ti->node_top = &volumes_simple;
6398 ti->sort_priority = value;
6400 sprintf(identifier, "%d", value);
6401 sprintf(name, "%s", text);
6403 setString(&ti->identifier, identifier);
6404 setString(&ti->name, name);
6405 setString(&ti->name_sorting, name);
6406 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6408 pushTreeInfo(&volumes_simple, ti);
6410 if (value == setup.volume_simple)
6411 current_volume_simple_found = TRUE;
6414 if (!current_volume_simple_found)
6416 // add entry for non-preset volume value
6418 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6419 char identifier[32], name[32];
6420 int value = setup.volume_simple;
6422 ti->node_top = &volumes_simple;
6423 ti->sort_priority = value;
6425 sprintf(identifier, "%d", value);
6426 sprintf(name, "%d %% (Current)", value);
6428 setString(&ti->identifier, identifier);
6429 setString(&ti->name, name);
6430 setString(&ti->name_sorting, name);
6431 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6433 pushTreeInfo(&volumes_simple, ti);
6436 // sort volume values to start with lowest volume value
6437 sortTreeInfo(&volumes_simple);
6439 // set current volume value to configured volume value
6440 volume_simple_current =
6441 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6443 // if that fails, set current volume to reliable default value
6444 if (volume_simple_current == NULL)
6445 volume_simple_current =
6446 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6448 // if that also fails, set current volume to first available value
6449 if (volume_simple_current == NULL)
6450 volume_simple_current = volumes_simple;
6453 if (volumes_loops == NULL)
6455 boolean current_volume_loops_found = FALSE;
6458 for (i = 0; volumes_list[i].value != -1; i++)
6460 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6461 char identifier[32], name[32];
6462 int value = volumes_list[i].value;
6463 char *text = volumes_list[i].text;
6465 ti->node_top = &volumes_loops;
6466 ti->sort_priority = value;
6468 sprintf(identifier, "%d", value);
6469 sprintf(name, "%s", text);
6471 setString(&ti->identifier, identifier);
6472 setString(&ti->name, name);
6473 setString(&ti->name_sorting, name);
6474 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6476 pushTreeInfo(&volumes_loops, ti);
6478 if (value == setup.volume_loops)
6479 current_volume_loops_found = TRUE;
6482 if (!current_volume_loops_found)
6484 // add entry for non-preset volume value
6486 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6487 char identifier[32], name[32];
6488 int value = setup.volume_loops;
6490 ti->node_top = &volumes_loops;
6491 ti->sort_priority = value;
6493 sprintf(identifier, "%d", value);
6494 sprintf(name, "%d %% (Current)", value);
6496 setString(&ti->identifier, identifier);
6497 setString(&ti->name, name);
6498 setString(&ti->name_sorting, name);
6499 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6501 pushTreeInfo(&volumes_loops, ti);
6504 // sort volume values to start with lowest volume value
6505 sortTreeInfo(&volumes_loops);
6507 // set current volume value to configured volume value
6508 volume_loops_current =
6509 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6511 // if that fails, set current volume to reliable default value
6512 if (volume_loops_current == NULL)
6513 volume_loops_current =
6514 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6516 // if that also fails, set current volume to first available value
6517 if (volume_loops_current == NULL)
6518 volume_loops_current = volumes_loops;
6521 if (volumes_music == NULL)
6523 boolean current_volume_music_found = FALSE;
6526 for (i = 0; volumes_list[i].value != -1; i++)
6528 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6529 char identifier[32], name[32];
6530 int value = volumes_list[i].value;
6531 char *text = volumes_list[i].text;
6533 ti->node_top = &volumes_music;
6534 ti->sort_priority = value;
6536 sprintf(identifier, "%d", value);
6537 sprintf(name, "%s", text);
6539 setString(&ti->identifier, identifier);
6540 setString(&ti->name, name);
6541 setString(&ti->name_sorting, name);
6542 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6544 pushTreeInfo(&volumes_music, ti);
6546 if (value == setup.volume_music)
6547 current_volume_music_found = TRUE;
6550 if (!current_volume_music_found)
6552 // add entry for non-preset volume value
6554 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6555 char identifier[32], name[32];
6556 int value = setup.volume_music;
6558 ti->node_top = &volumes_music;
6559 ti->sort_priority = value;
6561 sprintf(identifier, "%d", value);
6562 sprintf(name, "%d %% (Current)", value);
6564 setString(&ti->identifier, identifier);
6565 setString(&ti->name, name);
6566 setString(&ti->name_sorting, name);
6567 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6569 pushTreeInfo(&volumes_music, ti);
6572 // sort volume values to start with lowest volume value
6573 sortTreeInfo(&volumes_music);
6575 // set current volume value to configured volume value
6576 volume_music_current =
6577 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6579 // if that fails, set current volume to reliable default value
6580 if (volume_music_current == NULL)
6581 volume_music_current =
6582 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6584 // if that also fails, set current volume to first available value
6585 if (volume_music_current == NULL)
6586 volume_music_current = volumes_music;
6589 setup.volume_simple = atoi(volume_simple_current->identifier);
6590 setup.volume_loops = atoi(volume_loops_current->identifier);
6591 setup.volume_music = atoi(volume_music_current->identifier);
6593 // needed for displaying volume text instead of identifier
6594 volume_simple_text = volume_simple_current->name;
6595 volume_loops_text = volume_loops_current->name;
6596 volume_music_text = volume_music_current->name;
6598 setup_mode = SETUP_MODE_SOUND;
6603 static void execSetupChooseTouchControls(void)
6605 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6610 static void execSetupChooseMoveDistance(void)
6612 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6617 static void execSetupChooseDropDistance(void)
6619 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6624 static void execSetupChooseTransparency(void)
6626 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6631 static void execSetupChooseGridXSize_0(void)
6633 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6638 static void execSetupChooseGridYSize_0(void)
6640 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6645 static void execSetupChooseGridXSize_1(void)
6647 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6652 static void execSetupChooseGridYSize_1(void)
6654 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6659 static void execSetupConfigureVirtualButtons(void)
6661 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6663 ConfigureVirtualButtons();
6665 setup_mode = SETUP_MODE_TOUCH;
6670 static void execSetupTouch(void)
6674 if (touch_controls == NULL)
6676 for (i = 0; touch_controls_list[i].value != NULL; i++)
6678 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6679 char identifier[32], name[32];
6680 char *value = touch_controls_list[i].value;
6681 char *text = touch_controls_list[i].text;
6683 ti->node_top = &touch_controls;
6684 ti->sort_priority = i;
6686 sprintf(identifier, "%s", value);
6687 sprintf(name, "%s", text);
6689 setString(&ti->identifier, identifier);
6690 setString(&ti->name, name);
6691 setString(&ti->name_sorting, name);
6692 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6694 pushTreeInfo(&touch_controls, ti);
6697 // sort touch control values to start with lowest touch control value
6698 sortTreeInfo(&touch_controls);
6700 // set current touch control value to configured touch control value
6701 touch_control_current =
6702 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6704 // if that fails, set current touch control to reliable default value
6705 if (touch_control_current == NULL)
6706 touch_control_current =
6707 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6709 // if that also fails, set current touch control to first available value
6710 if (touch_control_current == NULL)
6711 touch_control_current = touch_controls;
6714 if (move_distances == NULL)
6716 for (i = 0; distances_list[i].value != -1; i++)
6718 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6719 char identifier[32], name[32];
6720 int value = distances_list[i].value;
6721 char *text = distances_list[i].text;
6723 ti->node_top = &move_distances;
6724 ti->sort_priority = value;
6726 sprintf(identifier, "%d", value);
6727 sprintf(name, "%s", text);
6729 setString(&ti->identifier, identifier);
6730 setString(&ti->name, name);
6731 setString(&ti->name_sorting, name);
6732 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6734 pushTreeInfo(&move_distances, ti);
6737 // sort distance values to start with lowest distance value
6738 sortTreeInfo(&move_distances);
6740 // set current distance value to configured distance value
6741 move_distance_current =
6742 getTreeInfoFromIdentifier(move_distances,
6743 i_to_a(setup.touch.move_distance));
6745 // if that fails, set current distance to reliable default value
6746 if (move_distance_current == NULL)
6747 move_distance_current =
6748 getTreeInfoFromIdentifier(move_distances,
6749 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6751 // if that also fails, set current distance to first available value
6752 if (move_distance_current == NULL)
6753 move_distance_current = move_distances;
6756 if (drop_distances == NULL)
6758 for (i = 0; distances_list[i].value != -1; i++)
6760 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6761 char identifier[32], name[32];
6762 int value = distances_list[i].value;
6763 char *text = distances_list[i].text;
6765 ti->node_top = &drop_distances;
6766 ti->sort_priority = value;
6768 sprintf(identifier, "%d", value);
6769 sprintf(name, "%s", text);
6771 setString(&ti->identifier, identifier);
6772 setString(&ti->name, name);
6773 setString(&ti->name_sorting, name);
6774 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6776 pushTreeInfo(&drop_distances, ti);
6779 // sort distance values to start with lowest distance value
6780 sortTreeInfo(&drop_distances);
6782 // set current distance value to configured distance value
6783 drop_distance_current =
6784 getTreeInfoFromIdentifier(drop_distances,
6785 i_to_a(setup.touch.drop_distance));
6787 // if that fails, set current distance to reliable default value
6788 if (drop_distance_current == NULL)
6789 drop_distance_current =
6790 getTreeInfoFromIdentifier(drop_distances,
6791 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6793 // if that also fails, set current distance to first available value
6794 if (drop_distance_current == NULL)
6795 drop_distance_current = drop_distances;
6798 if (transparencies == NULL)
6800 for (i = 0; transparencies_list[i].value != -1; i++)
6802 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6803 char identifier[32], name[32];
6804 int value = transparencies_list[i].value;
6805 char *text = transparencies_list[i].text;
6807 ti->node_top = &transparencies;
6808 ti->sort_priority = value;
6810 sprintf(identifier, "%d", value);
6811 sprintf(name, "%s", text);
6813 setString(&ti->identifier, identifier);
6814 setString(&ti->name, name);
6815 setString(&ti->name_sorting, name);
6816 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6818 pushTreeInfo(&transparencies, ti);
6821 // sort transparency values to start with lowest transparency value
6822 sortTreeInfo(&transparencies);
6824 // set current transparency value to configured transparency value
6825 transparency_current =
6826 getTreeInfoFromIdentifier(transparencies,
6827 i_to_a(setup.touch.transparency));
6829 // if that fails, set current transparency to reliable default value
6830 if (transparency_current == NULL)
6831 transparency_current =
6832 getTreeInfoFromIdentifier(transparencies,
6833 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6835 // if that also fails, set current transparency to first available value
6836 if (transparency_current == NULL)
6837 transparency_current = transparencies;
6840 for (i = 0; i < 2; i++)
6842 for (j = 0; j < 2; j++)
6844 if (grid_sizes[i][j] == NULL)
6846 for (k = 0; grid_sizes_list[k].value != -1; k++)
6848 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6849 char identifier[32], name[32];
6850 int value = grid_sizes_list[k].value;
6851 char *text = grid_sizes_list[k].text;
6853 ti->node_top = &grid_sizes[i][j];
6854 ti->sort_priority = value;
6856 sprintf(identifier, "%d", value);
6857 sprintf(name, "%s", text);
6859 setString(&ti->identifier, identifier);
6860 setString(&ti->name, name);
6861 setString(&ti->name_sorting, name);
6862 setString(&ti->infotext,
6865 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6866 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6868 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6869 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6871 pushTreeInfo(&grid_sizes[i][j], ti);
6874 // sort grid size values to start with lowest grid size value
6875 sortTreeInfo(&grid_sizes[i][j]);
6877 // set current grid size value to configured grid size value
6878 grid_size_current[i][j] =
6879 getTreeInfoFromIdentifier(grid_sizes[i][j],
6881 setup.touch.grid_xsize[i] :
6882 setup.touch.grid_ysize[i]));
6884 // if that fails, set current grid size to reliable default value
6885 if (grid_size_current[i][j] == NULL)
6886 grid_size_current[i][j] =
6887 getTreeInfoFromIdentifier(grid_sizes[i][j],
6889 DEFAULT_GRID_XSIZE(i) :
6890 DEFAULT_GRID_YSIZE(i)));
6892 // if that also fails, set current grid size to first available value
6893 if (grid_size_current[i][j] == NULL)
6894 grid_size_current[i][j] = grid_sizes[i][j];
6899 setup.touch.control_type = touch_control_current->identifier;
6900 setup.touch.move_distance = atoi(move_distance_current->identifier);
6901 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6902 setup.touch.transparency = atoi(transparency_current->identifier);
6904 for (i = 0; i < 2; i++)
6906 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6907 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6909 if (i == GRID_ACTIVE_NR())
6911 overlay.grid_xsize = setup.touch.grid_xsize[i];
6912 overlay.grid_ysize = setup.touch.grid_ysize[i];
6916 // needed for displaying value text instead of identifier
6917 touch_controls_text = touch_control_current->name;
6918 move_distance_text = move_distance_current->name;
6919 drop_distance_text = drop_distance_current->name;
6920 transparency_text = transparency_current->name;
6922 for (i = 0; i < 2; i++)
6923 for (j = 0; j < 2; j++)
6924 grid_size_text[i][j] = grid_size_current[i][j]->name;
6926 setup_mode = SETUP_MODE_TOUCH;
6931 static void execSetupArtwork(void)
6933 static ArtworkDirTree *gfx_last_valid = NULL;
6934 static ArtworkDirTree *snd_last_valid = NULL;
6935 static ArtworkDirTree *mus_last_valid = NULL;
6937 // current artwork directory may be invalid (level group, parent link)
6938 if (!validLevelSeries(artwork.gfx_current))
6939 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6940 if (!validLevelSeries(artwork.snd_current))
6941 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6942 if (!validLevelSeries(artwork.mus_current))
6943 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6945 // store valid artwork directory information
6946 gfx_last_valid = artwork.gfx_current;
6947 snd_last_valid = artwork.snd_current;
6948 mus_last_valid = artwork.mus_current;
6951 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6952 artwork.gfx_current->subdir,
6953 artwork.gfx_current->fullpath,
6954 artwork.gfx_current->basepath);
6957 setup.graphics_set = artwork.gfx_current->identifier;
6958 setup.sounds_set = artwork.snd_current->identifier;
6959 setup.music_set = artwork.mus_current->identifier;
6961 // needed if last screen (setup choice) changed graphics, sounds or music
6962 ReloadCustomArtwork(0);
6964 // needed for displaying artwork name instead of artwork identifier
6965 graphics_set_name = artwork.gfx_current->name;
6966 sounds_set_name = artwork.snd_current->name;
6967 music_set_name = artwork.mus_current->name;
6969 setup_mode = SETUP_MODE_ARTWORK;
6974 static void execSetupChooseGraphics(void)
6976 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6981 static void execSetupChooseSounds(void)
6983 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6988 static void execSetupChooseMusic(void)
6990 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6995 static void execSetupInput(void)
6997 setup_mode = SETUP_MODE_INPUT;
7002 static void execSetupShortcuts(void)
7004 setup_mode = SETUP_MODE_SHORTCUTS;
7009 static void execSetupShortcuts1(void)
7011 setup_mode = SETUP_MODE_SHORTCUTS_1;
7016 static void execSetupShortcuts2(void)
7018 setup_mode = SETUP_MODE_SHORTCUTS_2;
7023 static void execSetupShortcuts3(void)
7025 setup_mode = SETUP_MODE_SHORTCUTS_3;
7030 static void execSetupShortcuts4(void)
7032 setup_mode = SETUP_MODE_SHORTCUTS_4;
7037 static void execSetupShortcuts5(void)
7039 setup_mode = SETUP_MODE_SHORTCUTS_5;
7044 static void execExitSetup(void)
7046 SetGameStatus(GAME_MODE_MAIN);
7051 static void execSaveAndExitSetup(void)
7057 static void execGadgetNetworkServer(void)
7059 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7060 struct GadgetInfo *gi = screen_gadget[gadget_id];
7062 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7063 network_server_hostname[0] = '\0';
7065 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7069 ClickOnGadget(gi, MB_LEFTBUTTON);
7072 static void execOfferUploadTapes(void)
7077 static void ToggleNetworkModeIfNeeded(void)
7079 int font_title = FONT_TITLE_1;
7080 int font_foot = FC_BLUE;
7081 int ystart = mSY - SY + 16;
7082 int ybottom = mSY - SY + SYSIZE - 20;
7083 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7085 if (setup.network_mode == network.enabled)
7088 network.enabled = setup.network_mode;
7090 FadeOut(REDRAW_ALL);
7094 DrawTextSCentered(ystart, font_title, text);
7098 if (network.enabled)
7099 InitNetworkServer();
7101 DisconnectFromNetworkServer();
7103 DrawTextSCentered(ybottom, font_foot,
7104 "Press any key or button for setup menu");
7106 WaitForEventToContinue();
7111 static void ToggleGameSpeedsListIfNeeded(void)
7113 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7115 if (setup.game_speed_extended == using_game_speeds_extended)
7118 // try to match similar values when changing game speeds list
7119 if (setup.game_speed_extended)
7120 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7121 setup.game_frame_delay == 30 ? 29 :
7122 setup.game_frame_delay);
7124 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7125 setup.game_frame_delay == 16 ? 15 :
7126 setup.game_frame_delay >= 29 ? 30 :
7127 setup.game_frame_delay <= 10 ? 10 :
7128 setup.game_frame_delay);
7130 execSetupGame_setGameSpeeds(TRUE);
7135 static void ToggleUseApiServerIfNeeded(void)
7137 if (runtime.use_api_server == setup.use_api_server)
7140 runtime.use_api_server = setup.use_api_server;
7142 if (runtime.use_api_server)
7144 if (setup.has_remaining_tapes)
7145 setup.ask_for_uploading_tapes = TRUE;
7147 CheckApiServerTasks();
7151 static void ModifyGameSpeedIfNeeded(void)
7153 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7154 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7158 char *game_speed_text = "Fast";
7159 int game_speed_value = 15;
7161 if (setup.game_speed_extended)
7163 game_speed_text = "60 fps";
7164 game_speed_value = 16;
7167 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7169 // set game speed to existing list value that is fast enough for vsync
7170 setup.game_frame_delay = game_speed_value;
7172 execSetupGame_setGameSpeeds(TRUE);
7174 Request(message, REQ_CONFIRM);
7177 static void DisableVsyncIfNeeded(void)
7179 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7180 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7181 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7184 // disable vsync for the selected game speed to work
7185 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7187 execSetupGraphics_setVsyncModes(TRUE);
7189 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7195 void *related_value;
7196 } hide_related_entry_list[] =
7198 { &setup.network_server_hostname, execGadgetNetworkServer },
7199 { &setup.network_server_hostname, &network_server_text },
7201 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7202 { &setup.scores_in_highscore_list, &scores_type_text },
7204 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7205 { &setup.game_frame_delay, &game_speed_text },
7207 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7208 { &setup.scroll_delay_value, &scroll_delay_text },
7210 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7211 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7213 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7214 { &setup.window_scaling_percent, &window_size_text },
7216 { &setup.window_scaling_quality, execSetupChooseScalingType },
7217 { &setup.window_scaling_quality, &scaling_type_text },
7219 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7220 { &setup.screen_rendering_mode, &rendering_mode_text },
7222 { &setup.vsync_mode, execSetupChooseVsyncMode },
7223 { &setup.vsync_mode, &vsync_mode_text },
7225 { &setup.graphics_set, execSetupChooseGraphics },
7226 { &setup.graphics_set, &graphics_set_name },
7228 { &setup.sounds_set, execSetupChooseSounds },
7229 { &setup.sounds_set, &sounds_set_name },
7231 { &setup.music_set, execSetupChooseMusic },
7232 { &setup.music_set, &music_set_name },
7234 { &setup.volume_simple, execSetupChooseVolumeSimple },
7235 { &setup.volume_simple, &volume_simple_text },
7237 { &setup.volume_loops, execSetupChooseVolumeLoops },
7238 { &setup.volume_loops, &volume_loops_text },
7240 { &setup.volume_music, execSetupChooseVolumeMusic },
7241 { &setup.volume_music, &volume_music_text },
7243 { &setup.touch.control_type, execSetupChooseTouchControls },
7244 { &setup.touch.control_type, &touch_controls_text },
7246 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7247 { &setup.touch.move_distance, &move_distance_text },
7249 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7250 { &setup.touch.drop_distance, &drop_distance_text },
7252 { &setup.touch.transparency, execSetupChooseTransparency },
7253 { &setup.touch.transparency, &transparency_text },
7255 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7256 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7258 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7259 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7261 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7262 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7264 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7265 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7267 { &setup.internal.menu_game, execSetupGame },
7268 { &setup.internal.menu_engines, execSetupEngines },
7269 { &setup.internal.menu_editor, execSetupEditor },
7270 { &setup.internal.menu_graphics, execSetupGraphics },
7271 { &setup.internal.menu_sound, execSetupSound },
7272 { &setup.internal.menu_artwork, execSetupArtwork },
7273 { &setup.internal.menu_input, execSetupInput },
7274 { &setup.internal.menu_touch, execSetupTouch },
7275 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7276 { &setup.internal.menu_exit, execExitSetup },
7277 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7279 { &setup.internal.menu_shortcuts_various, execSetupShortcuts1 },
7280 { &setup.internal.menu_shortcuts_focus, execSetupShortcuts2 },
7281 { &setup.internal.menu_shortcuts_tape, execSetupShortcuts3 },
7282 { &setup.internal.menu_shortcuts_sound, execSetupShortcuts4 },
7283 { &setup.internal.menu_shortcuts_snap, execSetupShortcuts5 },
7285 { &setup.internal.info_title, execInfoTitleScreen },
7286 { &setup.internal.info_elements, execInfoElements },
7287 { &setup.internal.info_music, execInfoMusic },
7288 { &setup.internal.info_credits, execInfoCredits },
7289 { &setup.internal.info_program, execInfoProgram },
7290 { &setup.internal.info_version, execInfoVersion },
7291 { &setup.internal.info_levelset, execInfoLevelSet },
7292 { &setup.internal.info_exit, execExitInfo },
7297 void setHideRelatedSetupEntries(void)
7301 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7302 if (hideSetupEntry(hide_related_entry_list[i].value))
7303 setHideSetupEntry(hide_related_entry_list[i].related_value);
7306 static struct TokenInfo setup_info_main[] =
7308 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7309 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7310 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7311 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7312 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7313 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7314 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7315 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7316 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7317 { TYPE_EMPTY, NULL, "" },
7318 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7319 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7324 static struct TokenInfo setup_info_game[] =
7326 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7327 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7328 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7329 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7330 { TYPE_STRING, &network_server_text, "" },
7331 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7332 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7333 { TYPE_STRING, &scores_type_text, "" },
7334 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7335 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7336 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7337 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7338 { TYPE_SWITCH, &setup.handicap, "Force Solving Levels:" },
7339 { TYPE_SWITCH, &setup.skip_levels, "Allow Skipping Levels:" },
7340 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7341 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7342 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7343 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7344 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7345 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7346 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7347 { TYPE_SWITCH, &setup.autorecord, "Auto-Record When Playing:" },
7348 { TYPE_SWITCH, &setup.autorecord_after_replay, "Auto-Record After Replay:" },
7349 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7350 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7351 { TYPE_STRING, &game_speed_text, "" },
7352 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7354 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7355 { TYPE_STRING, &scroll_delay_text, "" },
7357 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7358 { TYPE_STRING, &snapshot_mode_text, "" },
7359 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7360 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7361 { TYPE_EMPTY, NULL, "" },
7362 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7367 static struct TokenInfo setup_info_engines[] =
7369 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7370 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7371 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7372 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7373 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7374 { TYPE_EMPTY, NULL, "" },
7375 { TYPE_HEADLINE, NULL, "Supaplex" },
7376 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7377 { TYPE_EMPTY, NULL, "" },
7378 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7383 static struct TokenInfo setup_info_editor[] =
7386 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7387 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7388 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7389 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7390 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7391 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7392 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7393 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7394 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7395 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7397 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7398 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7400 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7402 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7403 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7404 { TYPE_EMPTY, NULL, "" },
7406 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7407 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7408 { TYPE_EMPTY, NULL, "" },
7410 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7411 { TYPE_EMPTY, NULL, "" },
7412 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7413 { TYPE_EMPTY, NULL, "" },
7414 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7419 static struct TokenInfo setup_info_graphics[] =
7421 #if !defined(PLATFORM_ANDROID) && !defined(PLATFORM_EMSCRIPTEN)
7422 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7423 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7424 { TYPE_STRING, &window_size_text, "" },
7425 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7426 { TYPE_STRING, &scaling_type_text, "" },
7427 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7428 { TYPE_STRING, &rendering_mode_text, "" },
7431 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7432 { TYPE_STRING, &scroll_delay_text, "" },
7434 #if !defined(PLATFORM_EMSCRIPTEN)
7435 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7436 { TYPE_STRING, &vsync_mode_text, "" },
7438 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7439 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7440 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7441 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7442 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7443 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7444 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7445 { TYPE_EMPTY, NULL, "" },
7446 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7451 static struct TokenInfo setup_info_sound[] =
7453 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7454 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7455 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7456 { TYPE_EMPTY, NULL, "" },
7457 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7458 { TYPE_STRING, &volume_simple_text, "" },
7459 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7460 { TYPE_STRING, &volume_loops_text, "" },
7461 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7462 { TYPE_STRING, &volume_music_text, "" },
7463 { TYPE_EMPTY, NULL, "" },
7464 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7469 static struct TokenInfo setup_info_artwork[] =
7471 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7472 { TYPE_STRING, &graphics_set_name, "" },
7473 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7474 { TYPE_STRING, &sounds_set_name, "" },
7475 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7476 { TYPE_STRING, &music_set_name, "" },
7477 { TYPE_EMPTY, NULL, "" },
7478 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7479 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7480 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7481 { TYPE_EMPTY, NULL, "" },
7482 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7487 static struct TokenInfo setup_info_input[] =
7489 { TYPE_SWITCH, NULL, "Player:" },
7490 { TYPE_SWITCH, NULL, "Device:" },
7491 { TYPE_SWITCH, NULL, "" },
7492 { TYPE_SKIPPABLE, NULL, "" },
7493 { TYPE_EMPTY, NULL, "" },
7494 { TYPE_EMPTY, NULL, "" },
7495 { TYPE_EMPTY, NULL, "" },
7496 { TYPE_EMPTY, NULL, "" },
7497 { TYPE_EMPTY, NULL, "" },
7498 { TYPE_EMPTY, NULL, "" },
7499 { TYPE_EMPTY, NULL, "" },
7500 { TYPE_EMPTY, NULL, "" },
7501 { TYPE_SKIPPABLE, NULL, "" },
7502 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7507 static struct TokenInfo setup_info_touch[] =
7509 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7510 { TYPE_STRING, &touch_controls_text, "" },
7511 { TYPE_EMPTY, NULL, "" },
7512 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7517 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7519 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7520 { TYPE_STRING, &touch_controls_text, "" },
7521 { TYPE_EMPTY, NULL, "" },
7522 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7523 { TYPE_STRING, &grid_size_text[0][0], "" },
7524 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7525 { TYPE_STRING, &grid_size_text[0][1], "" },
7526 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7527 { TYPE_STRING, &transparency_text, "" },
7528 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7529 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7530 { TYPE_EMPTY, NULL, "" },
7531 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7532 { TYPE_EMPTY, NULL, "" },
7533 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7538 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7540 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7541 { TYPE_STRING, &touch_controls_text, "" },
7542 { TYPE_EMPTY, NULL, "" },
7543 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7544 { TYPE_STRING, &grid_size_text[1][0], "" },
7545 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7546 { TYPE_STRING, &grid_size_text[1][1], "" },
7547 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7548 { TYPE_STRING, &transparency_text, "" },
7549 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7550 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7551 { TYPE_EMPTY, NULL, "" },
7552 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7553 { TYPE_EMPTY, NULL, "" },
7554 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7559 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7561 setup_info_touch_virtual_buttons_0,
7562 setup_info_touch_virtual_buttons_1
7565 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7567 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7568 { TYPE_STRING, &touch_controls_text, "" },
7569 { TYPE_EMPTY, NULL, "" },
7570 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7571 { TYPE_STRING, &move_distance_text, "" },
7572 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7573 { TYPE_STRING, &drop_distance_text, "" },
7574 { TYPE_EMPTY, NULL, "" },
7575 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7580 static struct TokenInfo setup_info_shortcuts[] =
7582 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7583 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7584 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7585 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7586 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7587 { TYPE_EMPTY, NULL, "" },
7588 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7593 static struct TokenInfo setup_info_shortcuts_1[] =
7595 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7596 { TYPE_KEY, &setup.shortcut.save_game, "" },
7597 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7598 { TYPE_KEY, &setup.shortcut.load_game, "" },
7599 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7600 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7601 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7602 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7603 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7604 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7605 { TYPE_EMPTY, NULL, "" },
7606 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7607 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7608 { TYPE_EMPTY, NULL, "" },
7609 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7614 static struct TokenInfo setup_info_shortcuts_2[] =
7616 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7617 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7618 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7619 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7620 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7621 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7622 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7623 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7624 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7625 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7626 { TYPE_EMPTY, NULL, "" },
7627 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7632 static struct TokenInfo setup_info_shortcuts_3[] =
7634 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7635 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7636 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7637 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7638 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7639 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7640 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7641 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7642 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7643 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7644 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7645 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7646 { TYPE_EMPTY, NULL, "" },
7647 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7652 static struct TokenInfo setup_info_shortcuts_4[] =
7654 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7655 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7656 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7657 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7658 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7659 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7660 { TYPE_EMPTY, NULL, "" },
7661 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7666 static struct TokenInfo setup_info_shortcuts_5[] =
7668 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7669 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7670 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7671 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7672 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7673 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7674 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7675 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7676 { TYPE_EMPTY, NULL, "" },
7677 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7682 static Key getSetupKey(void)
7684 Key key = KSYM_UNDEFINED;
7685 boolean got_key_event = FALSE;
7687 while (!got_key_event)
7691 if (NextValidEvent(&event))
7695 case EVENT_KEYPRESS:
7697 key = GetEventKey((KeyEvent *)&event);
7699 // press 'Escape' or 'Enter' to keep the existing key binding
7700 if (key == KSYM_Escape || key == KSYM_Return)
7701 key = KSYM_UNDEFINED; // keep old value
7703 got_key_event = TRUE;
7707 case EVENT_KEYRELEASE:
7708 key_joystick_mapping = 0;
7712 HandleOtherEvents(&event);
7723 static int getSetupValueFont(int type, void *value)
7725 if (type & TYPE_GHOSTED)
7726 return FONT_OPTION_OFF;
7727 else if (type & TYPE_KEY)
7728 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7729 else if (type & TYPE_STRING)
7730 return FONT_VALUE_2;
7731 else if (type & TYPE_ECS_AGA)
7732 return FONT_VALUE_1;
7733 else if (type & TYPE_BOOLEAN_STYLE)
7734 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7735 else if (type & TYPE_YES_NO_AUTO)
7736 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7737 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7738 else if (type & TYPE_PLAYER)
7739 return FONT_VALUE_1;
7741 return FONT_VALUE_1;
7744 static int getSetupValueFontNarrow(int type, int font_nr)
7746 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7747 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7748 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7752 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7754 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7755 struct TokenInfo *si = &setup_info[si_pos];
7756 boolean font_draw_xoffset_modified = FALSE;
7757 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7758 int font_draw_xoffset_old = -1;
7759 int xoffset = (scrollbar_needed ? -1 : 0);
7760 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7761 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7762 int xpos = menu_screen_value_xpos;
7763 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7764 int startx = mSX + xpos * 32;
7765 int starty = mSY + ypos * 32;
7766 int type = si->type;
7767 void *value = si->value;
7768 char *value_string = getSetupValue(type, value);
7769 int font_nr_default = getSetupValueFont(type, value);
7770 int font_width_default = getFontWidth(font_nr_default);
7771 int font_nr = font_nr_default;
7774 if (value_string == NULL)
7777 if (type & TYPE_KEY)
7779 xpos = MENU_SCREEN_START_XPOS;
7781 if (type & TYPE_QUERY)
7782 value_string = "<press key>";
7784 else if (type & TYPE_STRING)
7786 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7788 xpos = MENU_SCREEN_START_XPOS;
7790 if (strlen(value_string) > max_value_len)
7791 value_string[max_value_len] = '\0';
7793 else if (type & TYPE_YES_NO_AUTO)
7795 xpos = menu_screen_value_xpos - 1;
7797 else if (type & TYPE_PLAYER)
7799 int displayed_player_nr = *(int *)value + 1;
7801 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7804 startx = mSX + xpos * 32;
7805 starty = mSY + ypos * 32;
7807 // special check if right-side setup values moved left due to scrollbar
7808 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7810 int max_menu_text_length = 26; // maximum text length for classic menu
7811 int font_xoffset = getFontDrawOffsetX(font_nr);
7812 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7813 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7814 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7815 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7817 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7819 // when using narrow font, left-shifting text "auto" not needed
7820 if (type & TYPE_YES_NO_AUTO)
7824 startx = mSX + xpos * 32;
7826 font_nr = getSetupValueFontNarrow(type, font_nr);
7830 // downward compatibility correction for Juergen Bonhagen's menu settings
7831 if (setup_mode != SETUP_MODE_INPUT)
7833 int max_menu_text_length_big = (menu_screen_value_xpos -
7834 MENU_SCREEN_START_XPOS);
7835 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7836 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7837 int font1_xoffset = getFontDrawOffsetX(font_nr);
7838 int font2_xoffset = getFontDrawOffsetX(check_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_medium * getFontWidth(text_font_nr);
7843 boolean correct_font_draw_xoffset = FALSE;
7845 if (xpos == MENU_SCREEN_START_XPOS &&
7846 startx + font1_xoffset < text_startx + text_font_xoffset)
7847 correct_font_draw_xoffset = TRUE;
7849 if (xpos == menu_screen_value_xpos &&
7850 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7851 correct_font_draw_xoffset = TRUE;
7853 // check if setup value would overlap with setup text when printed
7854 // (this can happen for extreme/wrong values for font draw offset)
7855 if (correct_font_draw_xoffset)
7857 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7858 font_draw_xoffset_modified = TRUE;
7860 if (type & TYPE_KEY)
7861 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7862 else if (!(type & TYPE_STRING))
7863 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7864 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7868 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7869 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7871 DrawText(startx, starty, value_string, font_nr);
7873 if (type & TYPE_PLAYER)
7875 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7876 int player_nr = *(int *)value;
7877 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7878 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7879 int startx2 = startx + xoff;
7880 int starty2 = starty + yoff;
7882 if (DrawingOnBackground(startx2, starty2))
7883 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7885 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7886 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7889 if (font_draw_xoffset_modified)
7890 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7893 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7895 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7896 struct TokenInfo *si = &setup_info[si_pos];
7898 if (si->type & TYPE_BOOLEAN_STYLE)
7900 *(boolean *)si->value ^= TRUE;
7902 else if (si->type & TYPE_YES_NO_AUTO)
7906 (*(int *)si->value == AUTO ? TRUE :
7907 *(int *)si->value == TRUE ? FALSE : AUTO) :
7908 (*(int *)si->value == TRUE ? AUTO :
7909 *(int *)si->value == AUTO ? FALSE : TRUE));
7911 else if (si->type & TYPE_KEY)
7915 si->type |= TYPE_QUERY;
7916 drawSetupValue(screen_pos, setup_info_pos_raw);
7917 si->type &= ~TYPE_QUERY;
7919 key = getSetupKey();
7920 if (key != KSYM_UNDEFINED)
7921 *(Key *)si->value = key;
7923 else if (si->type & TYPE_PLAYER)
7925 int player_nr = *(int *)si->value;
7930 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7932 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7935 drawSetupValue(screen_pos, setup_info_pos_raw);
7937 // fullscreen state may have changed at this point
7938 if (si->value == &setup.fullscreen)
7939 ToggleFullscreenIfNeeded();
7941 // network mode may have changed at this point
7942 if (si->value == &setup.network_mode)
7943 ToggleNetworkModeIfNeeded();
7945 // API server mode may have changed at this point
7946 if (si->value == &setup.use_api_server)
7947 ToggleUseApiServerIfNeeded();
7949 // game speed list may have changed at this point
7950 if (si->value == &setup.game_speed_extended)
7951 ToggleGameSpeedsListIfNeeded();
7954 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7956 static struct TokenInfo *setup_info_final = NULL;
7961 // determine maximum list size of target list
7962 while (setup_info_orig[list_size++].type != 0);
7964 // free, allocate and clear memory for target list
7965 checked_free(setup_info_final);
7966 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7968 // copy setup info list without setup entries marked as hidden
7969 for (i = 0; setup_info_orig[i].type != 0; i++)
7971 // skip setup entries configured to be hidden
7972 if (hideSetupEntry(setup_info_orig[i].value))
7975 // skip skippable setup entries if screen is lower than usual
7976 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7977 setup_info_orig[i].type == TYPE_SKIPPABLE)
7980 setup_info_final[list_pos++] = setup_info_orig[i];
7983 return setup_info_final;
7986 static void DrawSetupScreen_Generic(void)
7988 int fade_mask = REDRAW_FIELD;
7989 boolean redraw_all = FALSE;
7990 char *title_string = NULL;
7994 fade_mask = REDRAW_ALL;
7997 FadeMenuSoundsAndMusic();
7999 FreeScreenGadgets();
8000 CreateScreenGadgets();
8002 if (redraw_mask & REDRAW_ALL)
8007 // needed if different viewport properties defined for setup screen
8008 ChangeViewportPropertiesIfNeeded();
8010 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8014 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8016 if (setup_mode == SETUP_MODE_MAIN)
8018 setup_info = setup_info_main;
8019 title_string = STR_SETUP_MAIN;
8021 else if (setup_mode == SETUP_MODE_GAME)
8023 setup_info = setup_info_game;
8024 title_string = STR_SETUP_GAME;
8026 else if (setup_mode == SETUP_MODE_ENGINES)
8028 setup_info = setup_info_engines;
8029 title_string = STR_SETUP_ENGINES;
8031 else if (setup_mode == SETUP_MODE_EDITOR)
8033 setup_info = setup_info_editor;
8034 title_string = STR_SETUP_EDITOR;
8036 else if (setup_mode == SETUP_MODE_GRAPHICS)
8038 setup_info = setup_info_graphics;
8039 title_string = STR_SETUP_GRAPHICS;
8041 else if (setup_mode == SETUP_MODE_SOUND)
8043 setup_info = setup_info_sound;
8044 title_string = STR_SETUP_SOUND;
8046 else if (setup_mode == SETUP_MODE_ARTWORK)
8048 setup_info = setup_info_artwork;
8049 title_string = STR_SETUP_ARTWORK;
8051 else if (setup_mode == SETUP_MODE_TOUCH)
8053 setup_info = setup_info_touch;
8054 title_string = STR_SETUP_TOUCH;
8056 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8057 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8058 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8059 setup_info = setup_info_touch_wipe_gestures;
8061 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8063 setup_info = setup_info_shortcuts;
8064 title_string = STR_SETUP_SHORTCUTS;
8066 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8068 setup_info = setup_info_shortcuts_1;
8069 title_string = STR_SETUP_SHORTCUTS;
8071 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8073 setup_info = setup_info_shortcuts_2;
8074 title_string = STR_SETUP_SHORTCUTS;
8076 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8078 setup_info = setup_info_shortcuts_3;
8079 title_string = STR_SETUP_SHORTCUTS;
8081 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8083 setup_info = setup_info_shortcuts_4;
8084 title_string = STR_SETUP_SHORTCUTS;
8086 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8088 setup_info = setup_info_shortcuts_5;
8089 title_string = STR_SETUP_SHORTCUTS;
8092 // use modified setup info without setup entries marked as hidden
8093 setup_info = getSetupInfoFinal(setup_info);
8095 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8097 // determine maximal number of setup entries that can be displayed on screen
8099 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8102 // determine maximal number of setup entries available for this setup screen
8104 for (i = 0; setup_info[i].type != 0; i++)
8107 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8109 MapScreenGadgets(max_setup_info);
8112 redraw_mask = fade_mask = REDRAW_ALL;
8114 DrawMaskedBorder(fade_mask);
8119 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8121 menu_info = setup_info;
8123 HandleMenuScreen(mx, my, dx, dy, button,
8124 setup_mode, num_setup_info, max_setup_info);
8127 static void DrawSetupScreen_Input(void)
8131 FadeOut(REDRAW_FIELD);
8135 setup_info = getSetupInfoFinal(setup_info_input);
8137 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8139 for (i = 0; setup_info[i].type != 0; i++)
8141 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8142 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8143 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8144 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8145 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8146 initCursor(i, IMG_MENU_BUTTON);
8148 DrawCursorAndText_Setup(i, -1, FALSE);
8151 // create gadgets for setup input menu screen
8152 FreeScreenGadgets();
8153 CreateScreenGadgets();
8155 // map gadgets for setup input menu screen
8156 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8158 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8160 FadeIn(REDRAW_FIELD);
8163 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8165 if (device_name == NULL)
8168 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8171 if (strlen(device_name) > 1)
8173 char c1 = device_name[strlen(device_name) - 1];
8174 char c2 = device_name[strlen(device_name) - 2];
8176 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8177 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8180 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8181 strlen(device_name));
8184 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8187 static struct SetupKeyboardInfo custom_key;
8194 { &custom_key.left, "Axis/Pad Left" },
8195 { &custom_key.right, "Axis/Pad Right" },
8196 { &custom_key.up, "Axis/Pad Up" },
8197 { &custom_key.down, "Axis/Pad Down" },
8198 { &custom_key.snap, "Button 1/A/X" },
8199 { &custom_key.drop, "Button 2/B/Y" }
8201 static char *joystick_name[MAX_PLAYERS] =
8208 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8209 int font_nr_info = FONT_MENU_1;
8210 int font_nr_name = FONT_VALUE_OLD;
8211 int font_nr_on = FONT_VALUE_1;
8212 int font_nr_off = FONT_VALUE_OLD;
8215 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8217 font_nr_info = FONT_MENU_2;
8218 font_nr_on = FONT_VALUE_NARROW;
8219 font_nr_off = FONT_VALUE_OLD_NARROW;
8222 custom_key = setup.input[player_nr].key;
8224 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8225 FONT_INPUT_1_ACTIVE);
8227 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8229 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8230 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8232 if (setup.input[player_nr].use_joystick)
8234 char *device_name = setup.input[player_nr].joy.device_name;
8235 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8236 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8237 char *text = joystick_name[joystick_nr];
8238 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8240 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8241 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8245 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8246 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8249 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8250 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8254 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8255 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8256 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8257 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8259 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8260 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8261 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8262 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8263 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8264 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8266 for (i = 0; i < 6; i++)
8268 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8270 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8272 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8273 (setup.input[player_nr].use_joystick ?
8275 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8279 static int input_player_nr = 0;
8281 static void HandleSetupScreen_Input_Player(int step, int direction)
8283 int old_player_nr = input_player_nr;
8286 new_player_nr = old_player_nr + step * direction;
8287 if (new_player_nr < 0)
8289 if (new_player_nr > MAX_PLAYERS - 1)
8290 new_player_nr = MAX_PLAYERS - 1;
8292 if (new_player_nr != old_player_nr)
8294 input_player_nr = new_player_nr;
8296 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8300 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8302 static int choice = 0;
8305 int pos_start = SETUPINPUT_SCREEN_POS_START;
8306 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8307 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8308 int pos_end = SETUPINPUT_SCREEN_POS_END;
8310 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8314 for (i = 0; setup_info_input[i].type != 0; i++)
8316 // adjust menu structure according to skipped setup entries
8317 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8325 if (button == MB_MENU_INITIALIZE)
8327 // input setup menu may have changed size due to graphics configuration
8328 if (choice >= pos_empty1)
8331 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8333 DrawCursorAndText_Setup(choice, -1, TRUE);
8337 else if (button == MB_MENU_LEAVE)
8339 setup_mode = SETUP_MODE_MAIN;
8346 if (mx || my) // mouse input
8348 x = (mx - mSX) / 32;
8349 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8351 else if (dx || dy) // keyboard input
8353 if (dx && choice == 0)
8354 x = (dx < 0 ? 10 : 12);
8355 else if ((dx && choice == 1) ||
8356 (dx == -1 && choice == pos_end))
8357 button = MB_MENU_CHOICE;
8361 if (y >= pos_empty1 && y <= pos_empty2)
8362 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8365 if (y == 0 && dx != 0 && button)
8367 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8369 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8370 y >= pos_start && y <= pos_end &&
8371 !(y >= pos_empty1 && y <= pos_empty2))
8377 DrawCursorAndText_Setup(choice, -1, FALSE);
8378 DrawCursorAndText_Setup(y, -1, TRUE);
8380 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8389 char *device_name = setup.input[input_player_nr].joy.device_name;
8391 if (!setup.input[input_player_nr].use_joystick)
8393 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8395 setJoystickDeviceToNr(device_name, new_device_nr);
8396 setup.input[input_player_nr].use_joystick = TRUE;
8400 int device_nr = getJoystickNrFromDeviceName(device_name);
8401 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8403 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8404 setup.input[input_player_nr].use_joystick = FALSE;
8406 setJoystickDeviceToNr(device_name, new_device_nr);
8409 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8413 if (setup.input[input_player_nr].use_joystick)
8414 ConfigureJoystick(input_player_nr);
8416 CustomizeKeyboard(input_player_nr);
8418 else if (y == pos_end)
8424 setup_mode = SETUP_MODE_MAIN;
8431 static boolean CustomizeKeyboardMain(int player_nr)
8435 boolean finished = FALSE;
8436 static struct SetupKeyboardInfo custom_key;
8441 } customize_step[] =
8443 { &custom_key.left, "Move Left" },
8444 { &custom_key.right, "Move Right" },
8445 { &custom_key.up, "Move Up" },
8446 { &custom_key.down, "Move Down" },
8447 { &custom_key.snap, "Snap Field" },
8448 { &custom_key.drop, "Drop Element" }
8450 int font_nr_old = FONT_VALUE_OLD;
8451 int font_nr_new = FONT_VALUE_1;
8452 boolean success = FALSE;
8454 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8456 font_nr_old = FONT_VALUE_OLD_NARROW;
8457 font_nr_new = FONT_VALUE_NARROW;
8460 // read existing key bindings from player setup
8461 custom_key = setup.input[player_nr].key;
8464 FadeOut(REDRAW_FIELD);
8468 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8471 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8472 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8473 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8474 "Key:", FONT_INPUT_1_ACTIVE);
8475 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8476 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8478 FadeIn(REDRAW_FIELD);
8483 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8485 // reset frame delay counter directly after updating screen
8486 ResetDelayCounter(&event_frame_delay);
8488 while (NextValidEvent(&event))
8492 case EVENT_KEYPRESS:
8494 Key key = GetEventKey((KeyEvent *)&event);
8496 // press 'Escape' to abort and keep the old key bindings
8497 if (key == KSYM_Escape)
8499 FadeSkipNextFadeIn();
8506 // press 'Enter' to keep the existing key binding
8507 if (key == KSYM_Return)
8508 key = *customize_step[step_nr].key;
8510 // check if key already used
8511 for (i = 0; i < step_nr; i++)
8512 if (*customize_step[i].key == key)
8517 // got new key binding
8518 *customize_step[step_nr].key = key;
8519 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8521 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8522 getKeyNameFromKey(key), font_nr_new);
8525 // un-highlight last query
8526 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8527 customize_step[step_nr - 1].text, FONT_MENU_1);
8528 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8529 "Key:", FONT_MENU_1);
8531 // all keys configured
8540 // query next key binding
8541 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8542 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8543 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8544 "Key:", FONT_INPUT_1_ACTIVE);
8545 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8546 getKeyNameFromKey(*customize_step[step_nr].key),
8551 case EVENT_KEYRELEASE:
8552 key_joystick_mapping = 0;
8556 HandleOtherEvents(&event);
8560 // do not handle events for longer than standard frame delay period
8561 if (DelayReached(&event_frame_delay))
8568 // write new key bindings back to player setup, if successfully finished
8570 setup.input[player_nr].key = custom_key;
8575 void CustomizeKeyboard(int player_nr)
8577 boolean success = CustomizeKeyboardMain(player_nr);
8581 int font_nr = FONT_TITLE_1;
8582 int font_height = getFontHeight(font_nr);
8583 int ypos1 = SYSIZE / 2 - font_height * 2;
8584 int ypos2 = SYSIZE / 2 - font_height * 1;
8585 DelayCounter wait_frame_delay = { 2000 };
8587 ResetDelayCounter(&wait_frame_delay);
8591 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8592 DrawTextSCentered(ypos2, font_nr, "configured!");
8594 while (!DelayReached(&wait_frame_delay))
8600 DrawSetupScreen_Input();
8603 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8605 #define MARKER_BUTTON 1
8606 #define MARKER_AXIS_X 2
8607 #define MARKER_AXIS_Y 3
8609 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8611 static boolean bitmaps_initialized = FALSE;
8612 boolean screen_initialized = FALSE;
8613 static Bitmap *controller, *button, *axis_x, *axis_y;
8615 boolean success = TRUE;
8616 boolean done = FALSE, next = FALSE;
8618 int alpha = 200, alpha_step = -1;
8619 int alpha_ticks = 0;
8620 char mapping[4096], temp[256];
8621 int font_name = MENU_SETUP_FONT_TITLE;
8622 int font_info = MENU_SETUP_FONT_TEXT;
8623 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8624 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8625 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8626 int ystep_name = getMenuTextStep(spacing_name, font_name);
8627 int ystep_line = getMenuTextStep(spacing_line, font_info);
8628 int ystep_para = getMenuTextStep(spacing_para, font_info);
8636 int axis, button, hat, hat_value;
8639 *step, *prev_step, steps[] =
8641 { 356, 155, MARKER_BUTTON, "a", },
8642 { 396, 122, MARKER_BUTTON, "b", },
8643 { 320, 125, MARKER_BUTTON, "x", },
8644 { 358, 95, MARKER_BUTTON, "y", },
8645 { 162, 125, MARKER_BUTTON, "back", },
8646 { 216, 125, MARKER_BUTTON, "guide", },
8647 { 271, 125, MARKER_BUTTON, "start", },
8648 { 110, 200, MARKER_BUTTON, "dpleft", },
8649 { 146, 228, MARKER_BUTTON, "dpdown", },
8650 { 178, 200, MARKER_BUTTON, "dpright", },
8651 { 146, 172, MARKER_BUTTON, "dpup", },
8652 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8653 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8654 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8655 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8656 { 73, 141, MARKER_BUTTON, "leftstick", },
8657 { 282, 210, MARKER_BUTTON, "rightstick", },
8658 { 73, 141, MARKER_AXIS_X, "leftx", },
8659 { 73, 141, MARKER_AXIS_Y, "lefty", },
8660 { 282, 210, MARKER_AXIS_X, "rightx", },
8661 { 282, 210, MARKER_AXIS_Y, "righty", },
8664 if (!bitmaps_initialized)
8666 controller = LoadCustomImage("joystick/controller.png");
8667 button = LoadCustomImage("joystick/button.png");
8668 axis_x = LoadCustomImage("joystick/axis_x.png");
8669 axis_y = LoadCustomImage("joystick/axis_y.png");
8671 bitmaps_initialized = TRUE;
8674 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8677 // print info about the joystick we are watching
8678 Debug("joystick", "watching joystick %d: (%s)",
8679 SDL_JoystickInstanceID(joystick), name);
8680 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8681 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8682 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8685 // initialize mapping with GUID and name
8686 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8688 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8689 temp, name, SDL_GetPlatform());
8691 // loop through all steps (buttons and axes), getting joystick events
8692 for (i = 0; i < SDL_arraysize(steps) && !done;)
8694 Bitmap *marker = button; // initialize with reliable default value
8697 strcpy(step->mapping, mapping);
8701 step->hat_value = -1;
8703 marker = (step->marker == MARKER_BUTTON ? button :
8704 step->marker == MARKER_AXIS_X ? axis_x :
8705 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8709 while (!done && !next)
8711 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8712 alpha_ticks = SDL_GetTicks();
8719 else if (alpha < 128)
8725 int controller_x = SX + (SXSIZE - controller->width) / 2;
8726 int controller_y = SY + ystep_line;
8728 int marker_x = controller_x + step->x;
8729 int marker_y = controller_y + step->y;
8731 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8732 int ystart2 = ystart1 + ystep_name + ystep_line;
8736 DrawTextSCentered(ystart1, font_name, name);
8738 DrawTextSCentered(ystart2, font_info,
8739 "Press buttons and move axes on");
8740 ystart2 += ystep_line;
8741 DrawTextSCentered(ystart2, font_info,
8742 "your controller when indicated.");
8743 ystart2 += ystep_line;
8744 DrawTextSCentered(ystart2, font_info,
8745 "(Your controller may look different.)");
8746 ystart2 += ystep_para;
8748 #if defined(PLATFORM_ANDROID)
8749 DrawTextSCentered(ystart2, font_info,
8750 "To correct a mistake,");
8751 ystart2 += ystep_line;
8752 DrawTextSCentered(ystart2, font_info,
8753 "press the 'back' button.");
8754 ystart2 += ystep_line;
8755 DrawTextSCentered(ystart2, font_info,
8756 "To skip a button or axis,");
8757 ystart2 += ystep_line;
8758 DrawTextSCentered(ystart2, font_info,
8759 "press the 'menu' button.");
8761 DrawTextSCentered(ystart2, font_info,
8762 "To correct a mistake,");
8763 ystart2 += ystep_line;
8764 DrawTextSCentered(ystart2, font_info,
8765 "press the 'backspace' key.");
8766 ystart2 += ystep_line;
8767 DrawTextSCentered(ystart2, font_info,
8768 "To skip a button or axis,");
8769 ystart2 += ystep_line;
8770 DrawTextSCentered(ystart2, font_info,
8771 "press the 'return' key.");
8772 ystart2 += ystep_line;
8773 DrawTextSCentered(ystart2, font_info,
8774 "To exit, press the 'escape' key.");
8777 BlitBitmapMasked(controller, drawto, 0, 0,
8778 controller->width, controller->height,
8779 controller_x, controller_y);
8781 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8782 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8784 BlitBitmapMasked(marker, drawto, 0, 0,
8785 marker->width, marker->height,
8786 marker_x, marker_y);
8788 if (!screen_initialized)
8789 FadeIn(REDRAW_FIELD);
8793 screen_initialized = TRUE;
8795 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8797 // reset frame delay counter directly after updating screen
8798 ResetDelayCounter(&event_frame_delay);
8800 while (NextValidEvent(&event))
8804 case SDL_JOYAXISMOTION:
8805 if (event.jaxis.value > 20000 ||
8806 event.jaxis.value < -20000)
8808 for (j = 0; j < i; j++)
8809 if (steps[j].axis == event.jaxis.axis)
8814 if (step->marker != MARKER_AXIS_X &&
8815 step->marker != MARKER_AXIS_Y)
8818 step->axis = event.jaxis.axis;
8819 strcat(mapping, step->field);
8820 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8821 strcat(mapping, temp);
8829 case SDL_JOYHATMOTION:
8830 // ignore centering; we're probably just coming back
8831 // to the center from the previous item we set
8832 if (event.jhat.value == SDL_HAT_CENTERED)
8835 for (j = 0; j < i; j++)
8836 if (steps[j].hat == event.jhat.hat &&
8837 steps[j].hat_value == event.jhat.value)
8842 step->hat = event.jhat.hat;
8843 step->hat_value = event.jhat.value;
8844 strcat(mapping, step->field);
8845 snprintf(temp, sizeof(temp), ":h%u.%u,",
8846 event.jhat.hat, event.jhat.value );
8847 strcat(mapping, temp);
8854 case SDL_JOYBALLMOTION:
8857 case SDL_JOYBUTTONUP:
8858 for (j = 0; j < i; j++)
8859 if (steps[j].button == event.jbutton.button)
8864 step->button = event.jbutton.button;
8865 strcat(mapping, step->field);
8866 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8867 strcat(mapping, temp);
8874 case SDL_FINGERDOWN:
8875 case SDL_MOUSEBUTTONDOWN:
8883 if (event.key.keysym.sym == KSYM_BackSpace ||
8884 event.key.keysym.sym == KSYM_Back)
8896 prev_step = &steps[i - 1];
8897 strcpy(mapping, prev_step->mapping);
8904 if (event.key.keysym.sym == KSYM_space ||
8905 event.key.keysym.sym == KSYM_Return ||
8906 event.key.keysym.sym == KSYM_Menu)
8915 if (event.key.keysym.sym == KSYM_Escape)
8925 program.exit_function(0);
8932 // do not handle events for longer than standard frame delay period
8933 if (DelayReached(&event_frame_delay))
8942 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8945 // activate mapping for this game
8946 SDL_GameControllerAddMapping(mapping);
8948 // save mapping to personal mappings
8949 SaveSetup_AddGameControllerMapping(mapping);
8952 // wait until the last pending event was removed from event queue
8953 while (NextValidEvent(&event));
8958 static int ConfigureJoystickMain(int player_nr)
8960 char *device_name = setup.input[player_nr].joy.device_name;
8961 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8962 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8963 int success = FALSE;
8966 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8967 return JOYSTICK_NOT_AVAILABLE;
8969 if (!joystick_active || !setup.input[player_nr].use_joystick)
8970 return JOYSTICK_NOT_AVAILABLE;
8973 FadeOut(REDRAW_FIELD);
8975 // close all joystick devices (potentially opened as game controllers)
8976 for (i = 0; i < SDL_NumJoysticks(); i++)
8977 SDLCloseJoystick(i);
8979 // open joystick device as plain joystick to configure as game controller
8980 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8982 // as the joystick was successfully opened before, this should not happen
8983 if (joystick == NULL)
8986 // create new game controller mapping (buttons and axes) for joystick device
8987 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8989 // close joystick (and maybe re-open as configured game controller later)
8990 SDL_JoystickClose(joystick);
8992 // re-open all joystick devices (potentially as game controllers)
8993 for (i = 0; i < SDL_NumJoysticks(); i++)
8996 // clear all joystick input actions for all joystick devices
8997 SDLClearJoystickState();
8999 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9002 void ConfigureJoystick(int player_nr)
9004 boolean state = ConfigureJoystickMain(player_nr);
9006 if (state != JOYSTICK_NOT_CONFIGURED)
9008 boolean success = (state == JOYSTICK_CONFIGURED);
9009 char message1[MAX_OUTPUT_LINESIZE + 1];
9010 char *message2 = (success ? "configured!" : "not available!");
9011 char *device_name = setup.input[player_nr].joy.device_name;
9012 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9013 int font_nr = FONT_TITLE_1;
9014 int font_height = getFontHeight(font_nr);
9015 int ypos1 = SYSIZE / 2 - font_height * 2;
9016 int ypos2 = SYSIZE / 2 - font_height * 1;
9017 DelayCounter wait_frame_delay = { 2000 };
9019 ResetDelayCounter(&wait_frame_delay);
9023 sprintf(message1, "Joystick %d", nr);
9025 DrawTextSCentered(ypos1, font_nr, message1);
9026 DrawTextSCentered(ypos2, font_nr, message2);
9028 while (!DelayReached(&wait_frame_delay))
9034 DrawSetupScreen_Input();
9037 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9039 if (y < video.screen_height / 3)
9041 // remap touch gadgets to access upper part of the screen
9042 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9043 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9045 else if (y > 2 * video.screen_height / 3)
9047 // remap touch gadgets to access lower part of the screen
9048 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9049 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9053 static boolean ConfigureVirtualButtonsMain(void)
9055 static char *customize_step_text[] =
9064 char grid_button[] =
9066 CHAR_GRID_BUTTON_LEFT,
9067 CHAR_GRID_BUTTON_RIGHT,
9068 CHAR_GRID_BUTTON_UP,
9069 CHAR_GRID_BUTTON_DOWN,
9070 CHAR_GRID_BUTTON_SNAP,
9071 CHAR_GRID_BUTTON_DROP
9080 int font_nr = FONT_INPUT_1_ACTIVE;
9081 int font_height = getFontHeight(font_nr);
9082 int ypos1 = SYSIZE / 2 - font_height * 2;
9083 int ypos2 = SYSIZE / 2 - font_height * 1;
9084 boolean success = FALSE;
9085 boolean finished = FALSE;
9087 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9088 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9089 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9090 boolean set_grid_button = FALSE;
9091 int nr = GRID_ACTIVE_NR();
9094 for (x = 0; x < MAX_GRID_XSIZE; x++)
9095 for (y = 0; y < MAX_GRID_YSIZE; y++)
9096 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9098 overlay.grid_button_highlight = grid_button[step_nr];
9103 FadeOut(REDRAW_FIELD);
9107 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9108 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9109 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9111 FadeIn(REDRAW_FIELD);
9113 SetOverlayShowGrid(TRUE);
9115 // map gadgets for setup touch buttons menu screen
9116 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9122 while (NextValidEvent(&event))
9124 int action = ACTION_NONE;
9126 // ---------- handle events and set the resulting action ----------
9132 UserEvent *user = (UserEvent *)&event;
9133 int id = user->value1;
9135 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9136 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9137 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9138 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9143 case EVENT_KEYPRESS:
9145 Key key = GetEventKey((KeyEvent *)&event);
9147 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9148 key == KSYM_BackSpace ||
9149 key == KSYM_Back ? ACTION_BACK :
9150 key == KSYM_Return ||
9152 key == KSYM_space ? ACTION_NEXT :
9157 case EVENT_KEYRELEASE:
9158 key_joystick_mapping = 0;
9161 case EVENT_BUTTONPRESS:
9162 case EVENT_BUTTONRELEASE:
9164 ButtonEvent *button = (ButtonEvent *)&event;
9166 motion_status = FALSE;
9168 if (button->type == EVENT_BUTTONPRESS)
9169 button_status = button->button;
9171 button_status = MB_RELEASED;
9173 if (HandleGadgets(button->x, button->y, button_status))
9175 // do not handle this button event anymore
9179 button->x += video.screen_xoffset;
9180 button->y += video.screen_yoffset;
9182 x = button->x * overlay.grid_xsize / video.screen_width;
9183 y = button->y * overlay.grid_ysize / video.screen_height;
9185 if (button->type == EVENT_BUTTONPRESS)
9188 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9189 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9191 set_grid_button = TRUE;
9194 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9198 case EVENT_MOTIONNOTIFY:
9200 MotionEvent *motion = (MotionEvent *)&event;
9202 motion_status = TRUE;
9204 if (HandleGadgets(motion->x, motion->y, button_status))
9206 // do not handle this button event anymore
9210 motion->x += video.screen_xoffset;
9211 motion->y += video.screen_yoffset;
9213 x = motion->x * overlay.grid_xsize / video.screen_width;
9214 y = motion->y * overlay.grid_ysize / video.screen_height;
9216 set_grid_button = TRUE;
9218 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9222 case SDL_WINDOWEVENT:
9223 HandleWindowEvent((WindowEvent *) &event);
9225 // check if device has been rotated
9226 if (nr != GRID_ACTIVE_NR())
9228 nr = GRID_ACTIVE_NR();
9230 for (x = 0; x < MAX_GRID_XSIZE; x++)
9231 for (y = 0; y < MAX_GRID_YSIZE; y++)
9232 grid_button_old[x][y] = grid_button_tmp[x][y] =
9233 overlay.grid_button[x][y];
9238 case SDL_APP_WILLENTERBACKGROUND:
9239 case SDL_APP_DIDENTERBACKGROUND:
9240 case SDL_APP_WILLENTERFOREGROUND:
9241 case SDL_APP_DIDENTERFOREGROUND:
9242 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9246 HandleOtherEvents(&event);
9250 // ---------- perform action set by handling events ----------
9252 if (action == ACTION_ESCAPE)
9254 // abort and restore the old key bindings
9256 for (x = 0; x < MAX_GRID_XSIZE; x++)
9257 for (y = 0; y < MAX_GRID_YSIZE; y++)
9258 overlay.grid_button[x][y] = grid_button_old[x][y];
9260 FadeSkipNextFadeIn();
9264 else if (action == ACTION_BACK)
9266 // keep the configured key bindings and go to previous page
9272 FadeSkipNextFadeIn();
9277 else if (action == ACTION_NEXT)
9279 // keep the configured key bindings and go to next page
9283 // all virtual buttons configured
9291 if (action != ACTION_NONE && !finished)
9293 for (x = 0; x < MAX_GRID_XSIZE; x++)
9294 for (y = 0; y < MAX_GRID_YSIZE; y++)
9295 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9297 overlay.grid_button_highlight = grid_button[step_nr];
9299 // configure next virtual button
9303 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9304 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9305 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9308 if (set_grid_button)
9310 overlay.grid_button[x][y] =
9311 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9312 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9313 grid_button_tmp[x][y]);
9315 set_grid_button = FALSE;
9322 for (x = 0; x < MAX_GRID_XSIZE; x++)
9323 for (y = 0; y < MAX_GRID_YSIZE; y++)
9324 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9326 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9328 SetOverlayShowGrid(FALSE);
9333 void ConfigureVirtualButtons(void)
9335 boolean success = ConfigureVirtualButtonsMain();
9337 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9338 SCREEN_MASK_TOUCH2);
9342 int font_nr = FONT_TITLE_1;
9343 int font_height = getFontHeight(font_nr);
9344 int ypos1 = SYSIZE / 2 - font_height * 2;
9345 int ypos2 = SYSIZE / 2 - font_height * 1;
9346 DelayCounter wait_frame_delay = { 2000 };
9348 ResetDelayCounter(&wait_frame_delay);
9352 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9353 DrawTextSCentered(ypos2, font_nr, "configured!");
9355 while (!DelayReached(&wait_frame_delay))
9362 void DrawSetupScreen(void)
9367 if (setup_mode == SETUP_MODE_INPUT)
9368 DrawSetupScreen_Input();
9369 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9370 DrawChooseTree(&scores_type_current);
9371 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9372 DrawChooseTree(&game_speed_current);
9373 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9374 DrawChooseTree(&scroll_delay_current);
9375 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9376 DrawChooseTree(&snapshot_mode_current);
9377 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9378 DrawChooseTree(&window_size_current);
9379 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9380 DrawChooseTree(&scaling_type_current);
9381 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9382 DrawChooseTree(&rendering_mode_current);
9383 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9384 DrawChooseTree(&vsync_mode_current);
9385 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9386 DrawChooseTree(&artwork.gfx_current);
9387 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9388 DrawChooseTree(&artwork.snd_current);
9389 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9390 DrawChooseTree(&artwork.mus_current);
9391 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9392 DrawChooseTree(&volume_simple_current);
9393 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9394 DrawChooseTree(&volume_loops_current);
9395 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9396 DrawChooseTree(&volume_music_current);
9397 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9398 DrawChooseTree(&touch_control_current);
9399 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9400 DrawChooseTree(&move_distance_current);
9401 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9402 DrawChooseTree(&drop_distance_current);
9403 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9404 DrawChooseTree(&transparency_current);
9405 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9406 DrawChooseTree(&grid_size_current[0][0]);
9407 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9408 DrawChooseTree(&grid_size_current[0][1]);
9409 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9410 DrawChooseTree(&grid_size_current[1][0]);
9411 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9412 DrawChooseTree(&grid_size_current[1][1]);
9414 DrawSetupScreen_Generic();
9416 PlayMenuSoundsAndMusic();
9419 void RedrawSetupScreenAfterFullscreenToggle(void)
9421 if (setup_mode == SETUP_MODE_GRAPHICS ||
9422 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9424 // update list selection from "setup.window_scaling_percent"
9425 execSetupGraphics_setWindowSizes(TRUE);
9431 void RedrawSetupScreenAfterScreenRotation(int nr)
9435 if (setup_mode == SETUP_MODE_TOUCH)
9437 // update virtual button settings (depending on screen orientation)
9440 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9442 // save already configured virtual buttons
9443 for (x = 0; x < MAX_GRID_XSIZE; x++)
9444 for (y = 0; y < MAX_GRID_YSIZE; y++)
9445 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9449 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9451 if (setup_mode == SETUP_MODE_INPUT)
9452 HandleSetupScreen_Input(mx, my, dx, dy, button);
9453 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9454 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9455 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9456 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9457 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9458 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9459 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9460 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9461 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9462 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9463 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9464 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9465 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9466 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9467 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9468 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9469 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9470 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9471 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9472 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9473 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9474 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9475 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9476 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9477 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9478 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9479 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9480 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9481 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9482 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9483 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9484 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9485 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9486 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9487 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9488 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9489 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9490 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9491 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9492 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9493 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9494 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9495 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9496 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9498 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9501 void HandleGameActions(void)
9503 if (setup.ask_on_game_over)
9506 if (game.restart_game_message != NULL)
9508 RequestRestartGame(game.restart_game_message);
9513 if (game_status != GAME_MODE_PLAYING)
9516 GameActions(); // main game loop
9518 if (tape.auto_play && !tape.playing)
9519 AutoPlayTapesContinue(); // continue automatically playing next tape
9523 // ---------- new screen button stuff --------------------------------------
9527 int gfx_unpressed, gfx_pressed;
9528 struct MenuPosInfo *pos;
9529 boolean *check_value;
9532 unsigned int event_mask;
9533 boolean is_touch_button;
9535 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9538 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9539 &menu.main.button.prev_level, NULL,
9540 SCREEN_CTRL_ID_PREV_LEVEL,
9542 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9543 FALSE, "previous level"
9546 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9547 &menu.main.button.next_level, NULL,
9548 SCREEN_CTRL_ID_NEXT_LEVEL,
9550 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9554 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9555 &menu.scores.button.prev_level, NULL,
9556 SCREEN_CTRL_ID_PREV_LEVEL2,
9557 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9558 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9559 FALSE, "previous level"
9562 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9563 &menu.scores.button.next_level, NULL,
9564 SCREEN_CTRL_ID_NEXT_LEVEL2,
9565 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9566 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9570 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9571 &menu.scores.button.prev_score, NULL,
9572 SCREEN_CTRL_ID_PREV_SCORE,
9573 SCREEN_MASK_SCORES_INFO,
9574 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9575 FALSE, "previous score"
9578 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9579 &menu.scores.button.next_score, NULL,
9580 SCREEN_CTRL_ID_NEXT_SCORE,
9581 SCREEN_MASK_SCORES_INFO,
9582 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9586 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE,
9587 &menu.scores.button.play_tape, NULL,
9588 SCREEN_CTRL_ID_PLAY_TAPE,
9589 SCREEN_MASK_SCORES_INFO,
9594 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9595 &menu.main.button.first_level, NULL,
9596 SCREEN_CTRL_ID_FIRST_LEVEL,
9599 FALSE, "first level"
9602 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9603 &menu.main.button.last_level, NULL,
9604 SCREEN_CTRL_ID_LAST_LEVEL,
9610 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9611 &menu.main.button.level_number, NULL,
9612 SCREEN_CTRL_ID_LEVEL_NUMBER,
9615 FALSE, "level number"
9618 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9619 &menu.setup.button.prev_player, NULL,
9620 SCREEN_CTRL_ID_PREV_PLAYER,
9622 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9623 FALSE, "previous player"
9626 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9627 &menu.setup.button.next_player, NULL,
9628 SCREEN_CTRL_ID_NEXT_PLAYER,
9630 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9631 FALSE, "next player"
9634 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9635 &menu.main.button.insert_solution, NULL,
9636 SCREEN_CTRL_ID_INSERT_SOLUTION,
9637 SCREEN_MASK_MAIN_HAS_SOLUTION,
9639 FALSE, "insert solution tape"
9642 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9643 &menu.main.button.play_solution, NULL,
9644 SCREEN_CTRL_ID_PLAY_SOLUTION,
9645 SCREEN_MASK_MAIN_HAS_SOLUTION,
9647 FALSE, "play solution tape"
9650 IMG_MENU_BUTTON_LEVELSET_INFO, IMG_MENU_BUTTON_LEVELSET_INFO_ACTIVE,
9651 &menu.main.button.levelset_info, NULL,
9652 SCREEN_CTRL_ID_LEVELSET_INFO,
9653 SCREEN_MASK_MAIN_HAS_SET_INFO,
9655 FALSE, "show level set info"
9658 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9659 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9660 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9662 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9663 FALSE, "switch ECS/AGA chipset"
9666 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9667 &menu.setup.button.touch_back, NULL,
9668 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9671 TRUE, "previous page"
9674 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9675 &menu.setup.button.touch_next, NULL,
9676 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9682 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9683 &menu.setup.button.touch_back2, NULL,
9684 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9687 TRUE, "previous page"
9690 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9691 &menu.setup.button.touch_next2, NULL,
9692 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9701 int gfx_unpressed, gfx_pressed;
9705 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9708 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9709 -1, -1, // these values are not constant, but can change at runtime
9710 SCREEN_CTRL_ID_SCROLL_UP,
9714 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9715 -1, -1, // these values are not constant, but can change at runtime
9716 SCREEN_CTRL_ID_SCROLL_DOWN,
9723 int gfx_unpressed, gfx_pressed;
9729 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9732 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9733 -1, -1, // these values are not constant, but can change at runtime
9734 -1, -1, // these values are not constant, but can change at runtime
9735 GD_TYPE_SCROLLBAR_VERTICAL,
9736 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9737 "scroll level series vertically"
9749 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9752 IMG_SETUP_INPUT_TEXT,
9753 SCREEN_CTRL_ID_NETWORK_SERVER,
9754 -1, -1, // these values are not constant, but can change at runtime
9755 MAX_SETUP_TEXT_INPUT_LEN,
9756 network_server_hostname,
9757 "Network Server Hostname / IP"
9761 static void CreateScreenMenubuttons(void)
9763 struct GadgetInfo *gi;
9764 unsigned int event_mask;
9767 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9769 struct MenuPosInfo *pos = menubutton_info[i].pos;
9770 int screen_mask = menubutton_info[i].screen_mask;
9771 boolean is_touch_button = menubutton_info[i].is_touch_button;
9772 boolean is_check_button = menubutton_info[i].check_value != NULL;
9773 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9774 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9775 menubutton_info[i].gfx_unpressed);
9776 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9777 int gfx_unpressed, gfx_pressed;
9778 int x, y, width, height;
9779 int gd_x1, gd_x2, gd_y1, gd_y2;
9780 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9781 int id = menubutton_info[i].gadget_id;
9782 int type = GD_TYPE_NORMAL_BUTTON;
9783 boolean checked = FALSE;
9785 // do not use touch buttons if overlay touch buttons are disabled
9786 if (is_touch_button && !setup.touch.overlay_buttons)
9789 event_mask = menubutton_info[i].event_mask;
9791 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9792 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9794 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9795 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9797 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9798 gfx_pressed = menubutton_info[i].gfx_pressed;
9799 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9800 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9801 gd_x1 = graphic_info[gfx_unpressed].src_x;
9802 gd_y1 = graphic_info[gfx_unpressed].src_y;
9803 gd_x2 = graphic_info[gfx_pressed].src_x;
9804 gd_y2 = graphic_info[gfx_pressed].src_y;
9810 if (has_gfx_pressed)
9812 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9813 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9816 if (is_check_button)
9818 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9819 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9820 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9821 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9823 type = GD_TYPE_CHECK_BUTTON;
9824 checked = *menubutton_info[i].check_value;
9827 if (is_score_button)
9829 // if x/y set to -1, dynamically place buttons next to title text
9830 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9832 // special compatibility handling for "Snake Bite" graphics set
9833 if (strPrefix(leveldir_current->identifier, "snake_bite"))
9834 title_width = strlen(INFOTEXT_SCORE_ENTRY) * 32;
9836 // use "SX" here to center buttons (ignore horizontal draw offset)
9838 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9839 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9840 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9841 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9843 // use "mSY" here to place buttons (respect vertical draw offset)
9845 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
9846 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
9849 if (id == SCREEN_CTRL_ID_LEVELSET_INFO)
9851 if (pos->x == -1 && pos->y == -1)
9853 // use "SX" here to place button (ignore draw offsets)
9854 x = SX + SXSIZE - 2 * TILESIZE;
9855 y = SY + SYSIZE - 2 * TILESIZE;
9857 // special compatibility handling for "BD2K3" graphics set
9858 if (strPrefix(leveldir_current->identifier, "BD2K3"))
9859 x = SX + TILESIZE + MINI_TILESIZE;
9861 // special compatibility handling for "jue0" graphics set
9862 if (strPrefix(artwork.gfx_current_identifier, "jue0"))
9864 x = SX + SXSIZE - 4 * TILESIZE;
9865 y = SY + SYSIZE - 3 * TILESIZE;
9870 gi = CreateGadget(GDI_CUSTOM_ID, id,
9871 GDI_CUSTOM_TYPE_ID, i,
9872 GDI_IMAGE_ID, gfx_unpressed,
9873 GDI_INFO_TEXT, menubutton_info[i].infotext,
9879 GDI_STATE, GD_BUTTON_UNPRESSED,
9880 GDI_CHECKED, checked,
9881 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9882 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9883 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9884 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9885 GDI_DIRECT_DRAW, FALSE,
9886 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9887 GDI_EVENT_MASK, event_mask,
9888 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9892 Fail("cannot create gadget");
9894 screen_gadget[id] = gi;
9898 static void CreateScreenScrollbuttons(void)
9900 struct GadgetInfo *gi;
9901 unsigned int event_mask;
9904 // these values are not constant, but can change at runtime
9905 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9906 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9907 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9908 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9910 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9912 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9913 int gfx_unpressed, gfx_pressed;
9914 int x, y, width, height;
9915 int gd_x1, gd_x2, gd_y1, gd_y2;
9916 int id = scrollbutton_info[i].gadget_id;
9918 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9920 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9921 y = mSY + scrollbutton_info[i].y;
9922 width = SC_SCROLLBUTTON_XSIZE;
9923 height = SC_SCROLLBUTTON_YSIZE;
9925 // correct scrollbar position if placed outside menu (playfield) area
9926 if (x > SX + SC_SCROLL_UP_XPOS)
9927 x = SX + SC_SCROLL_UP_XPOS;
9929 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9930 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9931 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9933 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9934 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9935 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9936 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9937 gd_x1 = graphic_info[gfx_unpressed].src_x;
9938 gd_y1 = graphic_info[gfx_unpressed].src_y;
9939 gd_x2 = graphic_info[gfx_pressed].src_x;
9940 gd_y2 = graphic_info[gfx_pressed].src_y;
9942 gi = CreateGadget(GDI_CUSTOM_ID, id,
9943 GDI_CUSTOM_TYPE_ID, i,
9944 GDI_IMAGE_ID, gfx_unpressed,
9945 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9950 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9951 GDI_STATE, GD_BUTTON_UNPRESSED,
9952 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9953 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9954 GDI_DIRECT_DRAW, FALSE,
9955 GDI_EVENT_MASK, event_mask,
9956 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9960 Fail("cannot create gadget");
9962 screen_gadget[id] = gi;
9966 static void CreateScreenScrollbars(void)
9970 // these values are not constant, but can change at runtime
9971 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9972 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9973 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9974 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9976 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9978 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9979 int gfx_unpressed, gfx_pressed;
9980 int x, y, width, height;
9981 int gd_x1, gd_x2, gd_y1, gd_y2;
9982 struct GadgetInfo *gi;
9983 int items_max, items_visible, item_position;
9984 unsigned int event_mask;
9985 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9986 int id = scrollbar_info[i].gadget_id;
9988 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9990 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9991 y = mSY + scrollbar_info[i].y;
9992 width = scrollbar_info[i].width;
9993 height = scrollbar_info[i].height;
9995 // correct scrollbar position if placed outside menu (playfield) area
9996 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9997 x = SX + SC_SCROLL_VERTICAL_XPOS;
9999 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10000 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10002 items_max = num_page_entries;
10003 items_visible = num_page_entries;
10006 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10007 gfx_pressed = scrollbar_info[i].gfx_pressed;
10008 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10009 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10010 gd_x1 = graphic_info[gfx_unpressed].src_x;
10011 gd_y1 = graphic_info[gfx_unpressed].src_y;
10012 gd_x2 = graphic_info[gfx_pressed].src_x;
10013 gd_y2 = graphic_info[gfx_pressed].src_y;
10015 gi = CreateGadget(GDI_CUSTOM_ID, id,
10016 GDI_CUSTOM_TYPE_ID, i,
10017 GDI_IMAGE_ID, gfx_unpressed,
10018 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10022 GDI_HEIGHT, height,
10023 GDI_TYPE, scrollbar_info[i].type,
10024 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10025 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10026 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10027 GDI_WHEEL_AREA_X, SX,
10028 GDI_WHEEL_AREA_Y, SY,
10029 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10030 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10031 GDI_STATE, GD_BUTTON_UNPRESSED,
10032 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10033 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10034 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10035 GDI_DIRECT_DRAW, FALSE,
10036 GDI_EVENT_MASK, event_mask,
10037 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10041 Fail("cannot create gadget");
10043 screen_gadget[id] = gi;
10047 static void CreateScreenTextInputGadgets(void)
10051 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10053 int graphic = textinput_info[i].graphic;
10054 struct GraphicInfo *gd = &graphic_info[graphic];
10055 int gd_x1 = gd->src_x;
10056 int gd_y1 = gd->src_y;
10057 int gd_x2 = gd->src_x + gd->active_xoffset;
10058 int gd_y2 = gd->src_y + gd->active_yoffset;
10059 struct GadgetInfo *gi;
10060 unsigned int event_mask;
10061 int id = textinput_info[i].gadget_id;
10062 int x = textinput_info[i].x;
10063 int y = textinput_info[i].y;
10065 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10067 gi = CreateGadget(GDI_CUSTOM_ID, id,
10068 GDI_CUSTOM_TYPE_ID, i,
10069 GDI_INFO_TEXT, textinput_info[i].infotext,
10072 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10073 GDI_TEXT_VALUE, textinput_info[i].value,
10074 GDI_TEXT_SIZE, textinput_info[i].size,
10075 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10076 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10077 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10078 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10079 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10080 GDI_DESIGN_WIDTH, gd->width,
10081 GDI_EVENT_MASK, event_mask,
10082 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10083 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10087 Fail("cannot create gadget");
10089 screen_gadget[id] = gi;
10093 void CreateScreenGadgets(void)
10095 CreateScreenMenubuttons();
10097 CreateScreenScrollbuttons();
10098 CreateScreenScrollbars();
10100 CreateScreenTextInputGadgets();
10103 void FreeScreenGadgets(void)
10107 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10108 FreeGadget(screen_gadget[i]);
10111 static void RedrawScreenMenuGadgets(int screen_mask)
10115 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10116 if (screen_mask & menubutton_info[i].screen_mask)
10117 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10120 static void MapScreenMenuGadgets(int screen_mask)
10124 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10125 if (screen_mask & menubutton_info[i].screen_mask)
10126 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10129 static void UnmapScreenMenuGadgets(int screen_mask)
10133 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10135 if (screen_mask & menubutton_info[i].screen_mask)
10137 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10139 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10140 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10141 screen_gadget[menubutton_info[i].gadget_id]->y,
10142 screen_gadget[menubutton_info[i].gadget_id]->width,
10143 screen_gadget[menubutton_info[i].gadget_id]->height);
10148 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10151 MapScreenMenuGadgets(screen_mask);
10153 UnmapScreenMenuGadgets(screen_mask);
10156 static void MapScreenGadgets(int num_entries)
10160 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10163 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10164 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10166 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10167 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10170 static void UnmapScreenGadgets()
10174 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10175 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10177 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10178 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10181 static void MapScreenTreeGadgets(TreeInfo *ti)
10183 MapScreenGadgets(numTreeInfoInGroup(ti));
10186 static void UnmapScreenTreeGadgets(void)
10188 UnmapScreenGadgets();
10191 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10193 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10194 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10195 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10196 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10198 if (pos_1->x == -1 && pos_1->y == -1)
10199 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10201 if (pos_2->x == -1 && pos_2->y == -1)
10202 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10205 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10207 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10208 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10210 // set gadget position dynamically, pre-defined or off-screen
10211 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10212 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10214 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10215 MapGadget(gi); // (needed if deactivated on last score page)
10218 static void HandleScreenGadgets(struct GadgetInfo *gi)
10220 int id = gi->custom_id;
10221 int button = gi->event.button;
10222 int step = (button == MB_LEFTBUTTON ? 1 :
10223 button == MB_MIDDLEBUTTON ? 5 :
10224 button == MB_RIGHTBUTTON ? 10 : 1);
10228 case SCREEN_CTRL_ID_PREV_LEVEL:
10229 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10232 case SCREEN_CTRL_ID_NEXT_LEVEL:
10233 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10236 case SCREEN_CTRL_ID_PREV_LEVEL2:
10237 HandleHallOfFame_SelectLevel(step, -1);
10240 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10241 HandleHallOfFame_SelectLevel(step, +1);
10244 case SCREEN_CTRL_ID_PREV_SCORE:
10245 HandleScoreInfo_SelectScore(step, -1);
10248 case SCREEN_CTRL_ID_NEXT_SCORE:
10249 HandleScoreInfo_SelectScore(step, +1);
10252 case SCREEN_CTRL_ID_PLAY_TAPE:
10253 HandleScoreInfo_PlayTape();
10256 case SCREEN_CTRL_ID_FIRST_LEVEL:
10257 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10260 case SCREEN_CTRL_ID_LAST_LEVEL:
10261 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10264 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10265 CloseDoor(DOOR_CLOSE_2);
10266 SetGameStatus(GAME_MODE_LEVELNR);
10267 DrawChooseLevelNr();
10270 case SCREEN_CTRL_ID_PREV_PLAYER:
10271 HandleSetupScreen_Input_Player(step, -1);
10274 case SCREEN_CTRL_ID_NEXT_PLAYER:
10275 HandleSetupScreen_Input_Player(step, +1);
10278 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10279 InsertSolutionTape();
10282 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10283 PlaySolutionTape();
10286 case SCREEN_CTRL_ID_LEVELSET_INFO:
10287 DrawInfoScreen_FromMainMenu(INFO_MODE_LEVELSET);
10290 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10291 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10295 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10296 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10297 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10298 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10299 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10302 case SCREEN_CTRL_ID_SCROLL_UP:
10303 if (game_status == GAME_MODE_NAMES)
10304 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10305 else if (game_status == GAME_MODE_LEVELS)
10306 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10307 else if (game_status == GAME_MODE_LEVELNR)
10308 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10309 else if (game_status == GAME_MODE_SETUP)
10310 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10311 else if (game_status == GAME_MODE_INFO)
10312 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10313 else if (game_status == GAME_MODE_SCORES)
10314 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10317 case SCREEN_CTRL_ID_SCROLL_DOWN:
10318 if (game_status == GAME_MODE_NAMES)
10319 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10320 else if (game_status == GAME_MODE_LEVELS)
10321 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10322 else if (game_status == GAME_MODE_LEVELNR)
10323 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10324 else if (game_status == GAME_MODE_SETUP)
10325 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10326 else if (game_status == GAME_MODE_INFO)
10327 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10328 else if (game_status == GAME_MODE_SCORES)
10329 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10332 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10333 if (game_status == GAME_MODE_NAMES)
10334 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10335 else if (game_status == GAME_MODE_LEVELS)
10336 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10337 else if (game_status == GAME_MODE_LEVELNR)
10338 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10339 else if (game_status == GAME_MODE_SETUP)
10340 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10341 else if (game_status == GAME_MODE_INFO)
10342 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10343 else if (game_status == GAME_MODE_SCORES)
10344 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10347 case SCREEN_CTRL_ID_NETWORK_SERVER:
10349 if (!strEqual(gi->textinput.value, ""))
10351 setString(&setup.network_server_hostname, gi->textinput.value);
10353 network.server_host = setup.network_server_hostname;
10357 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10359 network.server_host = NULL;
10362 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10363 network.server_host = NULL;
10365 execSetupGame_setNetworkServerText();
10377 void HandleScreenGadgetKeys(Key key)
10379 if (key == setup.shortcut.tape_play)
10380 HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
10383 void DumpScreenIdentifiers(void)
10387 Print("Active screen elements on current screen:\n");
10389 for (i = 0; main_controls[i].nr != -1; i++)
10391 struct MainControlInfo *mci = &main_controls[i];
10393 if (mci->button_graphic != -1)
10395 char *token = getTokenFromImageID(mci->button_graphic);
10397 Print("- '%s'\n", token);
10404 boolean DoScreenAction(int image_id)
10408 if (game_status != GAME_MODE_MAIN)
10411 for (i = 0; main_controls[i].nr != -1; i++)
10413 struct MainControlInfo *mci = &main_controls[i];
10414 struct MenuPosInfo *pos = mci->pos_button;
10416 if (mci->button_graphic == image_id)
10418 int x = mSX + pos->x;
10419 int y = mSY + pos->y;
10421 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10430 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10432 // get tree info node of newly added level or artwork set
10433 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10434 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10436 if (tree_node_new == NULL) // should not happen
10439 // if request dialog is active, do nothing
10440 if (game.request_active)
10443 if (game_status == GAME_MODE_MAIN &&
10444 tree_type == TREE_TYPE_LEVEL_DIR)
10446 // when adding new level set in main menu, select it as current level set
10448 // change current level set to newly added level set from zip file
10449 leveldir_current = tree_node_new;
10451 // change current level number to first level of newly added level set
10452 level_nr = leveldir_current->first_level;
10454 // redraw screen to reflect changed level set
10457 // save this level set and level number as last selected level set
10458 SaveLevelSetup_LastSeries();
10459 SaveLevelSetup_SeriesInfo();
10461 else if (game_status == GAME_MODE_LEVELS &&
10462 tree_type == TREE_TYPE_LEVEL_DIR)
10464 // when adding new level set in level set menu, set cursor and update screen
10466 leveldir_current = tree_node_new;
10468 DrawChooseTree(&leveldir_current);
10470 else if (game_status == GAME_MODE_SETUP)
10472 // when adding new artwork set in setup menu, set cursor and update screen
10474 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10475 tree_type == TREE_TYPE_GRAPHICS_DIR)
10477 artwork.gfx_current = tree_node_new;
10479 DrawChooseTree(&artwork.gfx_current);
10481 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10482 tree_type == TREE_TYPE_SOUNDS_DIR)
10484 artwork.snd_current = tree_node_new;
10486 DrawChooseTree(&artwork.snd_current);
10488 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10489 tree_type == TREE_TYPE_MUSIC_DIR)
10491 artwork.mus_current = tree_node_new;
10493 DrawChooseTree(&artwork.mus_current);
10498 static int UploadTapes(void)
10500 SetGameStatus(GAME_MODE_LOADING);
10502 FadeSetEnterScreen();
10503 FadeOut(REDRAW_ALL);
10505 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10507 FadeIn(REDRAW_ALL);
10509 DrawInitTextHead("Uploading tapes");
10511 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10512 global.autoplay_leveldir = "ALL";
10513 global.autoplay_all = TRUE;
10515 int num_tapes_uploaded = AutoPlayTapes();
10517 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10518 global.autoplay_leveldir = NULL;
10519 global.autoplay_all = FALSE;
10521 SetGameStatus(GAME_MODE_MAIN);
10525 return num_tapes_uploaded;
10528 static boolean OfferUploadTapes(void)
10530 if (!Request(setup.has_remaining_tapes ?
10531 "Upload missing tapes to the high score server now?" :
10532 "Upload all your tapes to the high score server now?", REQ_ASK))
10535 // when uploading tapes, make sure that high score server is enabled
10536 runtime.use_api_server = setup.use_api_server = TRUE;
10538 int num_tapes_uploaded = UploadTapes();
10541 if (num_tapes_uploaded < 0)
10543 num_tapes_uploaded = -num_tapes_uploaded - 1;
10545 if (num_tapes_uploaded == 0)
10546 sprintf(message, "Upload failed! No tapes uploaded!");
10547 else if (num_tapes_uploaded == 1)
10548 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10550 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10551 num_tapes_uploaded);
10553 Request(message, REQ_CONFIRM);
10555 // if uploading tapes failed, add tape upload entry to setup menu
10556 setup.provide_uploading_tapes = TRUE;
10557 setup.has_remaining_tapes = TRUE;
10559 SaveSetup_ServerSetup();
10564 if (num_tapes_uploaded == 0)
10565 sprintf(message, "No tapes uploaded!");
10566 else if (num_tapes_uploaded == 1)
10567 sprintf(message, "1 tape uploaded!");
10569 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10571 Request(message, REQ_CONFIRM);
10573 if (num_tapes_uploaded > 0)
10574 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10576 // after all tapes have been uploaded, remove entry from setup menu
10577 setup.provide_uploading_tapes = FALSE;
10578 setup.has_remaining_tapes = FALSE;
10580 SaveSetup_ServerSetup();
10585 static void CheckUploadTapes(void)
10587 if (!setup.ask_for_uploading_tapes)
10590 // after asking for uploading tapes, do not ask again
10591 setup.ask_for_uploading_tapes = FALSE;
10592 setup.ask_for_remaining_tapes = FALSE;
10594 if (directoryExists(getTapeDir(NULL)))
10596 boolean tapes_uploaded = OfferUploadTapes();
10598 if (!tapes_uploaded)
10600 Request(setup.has_remaining_tapes ?
10601 "You can upload missing tapes from the setup menu later!" :
10602 "You can upload your tapes from the setup menu later!",
10608 // if tapes directory does not exist yet, never offer uploading all tapes
10609 setup.provide_uploading_tapes = FALSE;
10612 SaveSetup_ServerSetup();
10615 static void UpgradePlayerUUID(void)
10617 ApiResetUUIDAsThread(getUUID());
10620 static void CheckUpgradePlayerUUID(void)
10622 if (setup.player_version > 1)
10625 UpgradePlayerUUID();
10628 void CheckApiServerTasks(void)
10630 // check if the player's UUID has to be upgraded
10631 CheckUpgradePlayerUUID();
10633 // check if there are any tapes to be uploaded
10634 CheckUploadTapes();