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);
333 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *);
335 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
337 static int info_mode = INFO_MODE_MAIN;
338 static int setup_mode = SETUP_MODE_MAIN;
340 static boolean info_screens_from_main = FALSE;
342 static TreeInfo *window_sizes = NULL;
343 static TreeInfo *window_size_current = NULL;
345 static TreeInfo *scaling_types = NULL;
346 static TreeInfo *scaling_type_current = NULL;
348 static TreeInfo *rendering_modes = NULL;
349 static TreeInfo *rendering_mode_current = NULL;
351 static TreeInfo *vsync_modes = NULL;
352 static TreeInfo *vsync_mode_current = NULL;
354 static TreeInfo *scroll_delays = NULL;
355 static TreeInfo *scroll_delay_current = NULL;
357 static TreeInfo *snapshot_modes = NULL;
358 static TreeInfo *snapshot_mode_current = NULL;
360 static TreeInfo *scores_types = NULL;
361 static TreeInfo *scores_type_current = NULL;
363 static TreeInfo *game_speeds_normal = NULL;
364 static TreeInfo *game_speeds_extended = NULL;
365 static TreeInfo *game_speeds = NULL;
366 static TreeInfo *game_speed_current = NULL;
368 static TreeInfo *volumes_simple = NULL;
369 static TreeInfo *volume_simple_current = NULL;
371 static TreeInfo *volumes_loops = NULL;
372 static TreeInfo *volume_loops_current = NULL;
374 static TreeInfo *volumes_music = NULL;
375 static TreeInfo *volume_music_current = NULL;
377 static TreeInfo *touch_controls = NULL;
378 static TreeInfo *touch_control_current = NULL;
380 static TreeInfo *move_distances = NULL;
381 static TreeInfo *move_distance_current = NULL;
383 static TreeInfo *drop_distances = NULL;
384 static TreeInfo *drop_distance_current = NULL;
386 static TreeInfo *transparencies = NULL;
387 static TreeInfo *transparency_current = NULL;
389 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
390 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
392 static TreeInfo *player_name = NULL;
393 static TreeInfo *player_name_current = NULL;
395 static TreeInfo *level_number = NULL;
396 static TreeInfo *level_number_current = NULL;
398 static TreeInfo *score_entries = NULL;
399 static TreeInfo *score_entry_current = NULL;
401 static struct ValueTextInfo window_sizes_list[] =
406 { 100, "100 % (Default)" },
419 static struct StringValueTextInfo scaling_types_list[] =
421 { SCALING_QUALITY_NEAREST, "Off" },
422 { SCALING_QUALITY_LINEAR, "Linear" },
423 { SCALING_QUALITY_BEST, "Anisotropic" },
428 static struct StringValueTextInfo rendering_modes_list[] =
430 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
431 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
433 // this mode may work under certain conditions, but does not work on Windows
434 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
436 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
441 static struct StringValueTextInfo vsync_modes_list[] =
443 { STR_VSYNC_MODE_OFF, "Off" },
444 { STR_VSYNC_MODE_NORMAL, "Normal" },
445 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
450 static struct StringValueTextInfo scores_types_list[] =
452 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
453 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
454 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
459 static struct ValueTextInfo game_speeds_list_normal[] =
470 static struct ValueTextInfo game_speeds_list_extended[] =
472 { 1000, "1 fps (Extremely Slow)" },
477 { 29, "35 fps (Original Supaplex)" },
479 { 20, "50 fps (=== Normal Speed ===)" },
480 { 16, "60 fps (60 Hz VSync Speed)" },
481 { 14, "70 fps (Maximum Supaplex)" },
485 { 1, "1000 fps (Extremely Fast)" },
490 static struct ValueTextInfo *game_speeds_list;
492 static struct ValueTextInfo scroll_delays_list[] =
494 { 0, "0 Tiles (No Scroll Delay)" },
497 { 3, "3 Tiles (Default)" },
502 { 8, "8 Tiles (Maximum Scroll Delay)"},
507 static struct StringValueTextInfo snapshot_modes_list[] =
509 { STR_SNAPSHOT_MODE_OFF, "Off" },
510 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
511 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
512 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
517 static struct ValueTextInfo volumes_list[] =
537 static struct StringValueTextInfo touch_controls_list[] =
539 { TOUCH_CONTROL_OFF, "Off" },
540 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
541 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
542 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
547 static struct ValueTextInfo distances_list[] =
562 static struct ValueTextInfo transparencies_list[] =
564 { 0, "0 % (Opaque)" },
574 { 100, "100 % (Invisible)" },
579 static struct ValueTextInfo grid_sizes_list[] =
615 static int align_xoffset = 0;
616 static int align_yoffset = 0;
618 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
619 (s) <= GAME_MODE_SETUP ? (s) : \
620 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
622 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
623 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
625 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
626 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
627 (i) <= INFO_MODE_LEVELSET ? (i) : \
630 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
631 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
632 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
633 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
634 SETUP_MODE_CHOOSE_ARTWORK : \
635 SETUP_MODE_CHOOSE_OTHER)
637 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
638 menu.draw_xoffset[GAME_MODE_INFO] : \
639 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
640 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
641 menu.draw_yoffset[GAME_MODE_INFO] : \
642 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
643 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
644 menu.extra_spacing[GAME_MODE_INFO] : \
645 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
647 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
648 menu.draw_xoffset[GAME_MODE_SETUP] : \
649 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
650 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
651 menu.draw_yoffset[GAME_MODE_SETUP] : \
652 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
653 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
654 menu.extra_spacing[GAME_MODE_SETUP] : \
655 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
657 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
659 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
661 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
662 DRAW_XOFFSET_INFO(info_mode) : \
663 (s) == GAME_MODE_SETUP ? \
664 DRAW_XOFFSET_SETUP(setup_mode) : \
665 menu.draw_xoffset[DRAW_MODE(s)])
666 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
667 DRAW_YOFFSET_INFO(info_mode) : \
668 (s) == GAME_MODE_SETUP ? \
669 DRAW_YOFFSET_SETUP(setup_mode) : \
670 menu.draw_yoffset[DRAW_MODE(s)])
671 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
672 EXTRA_SPACING_INFO(info_mode) : \
673 (s) == GAME_MODE_SETUP ? \
674 EXTRA_SPACING_SETUP(setup_mode) : \
675 (s) == GAME_MODE_SCORES ? \
676 EXTRA_SPACING_SCORES(info_mode) : \
677 menu.extra_spacing[DRAW_MODE(s)])
679 #define mSX (SX + DRAW_XOFFSET(game_status))
680 #define mSY (SY + DRAW_YOFFSET(game_status))
682 #define amSX (mSX + align_xoffset)
683 #define amSY (mSY + align_yoffset)
685 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
686 menu.list_size[game_status] : \
687 MAX_MENU_ENTRIES_ON_SCREEN)
689 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
690 NUM_MENU_ENTRIES_ON_SCREEN)
693 // title display and control definitions
695 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
696 2 * MAX_NUM_TITLE_MESSAGES)
698 #define NO_DIRECT_LEVEL_SELECT (-1)
701 static int num_title_screens = 0;
703 struct TitleControlInfo
712 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
715 // main menu display and control definitions
717 #define MAIN_CONTROL_NAME 0
718 #define MAIN_CONTROL_LEVELS 1
719 #define MAIN_CONTROL_SCORES 2
720 #define MAIN_CONTROL_EDITOR 3
721 #define MAIN_CONTROL_INFO 4
722 #define MAIN_CONTROL_GAME 5
723 #define MAIN_CONTROL_SETUP 6
724 #define MAIN_CONTROL_QUIT 7
725 #define MAIN_CONTROL_PREV_LEVEL 8
726 #define MAIN_CONTROL_NEXT_LEVEL 9
727 #define MAIN_CONTROL_FIRST_LEVEL 10
728 #define MAIN_CONTROL_LAST_LEVEL 11
729 #define MAIN_CONTROL_LEVEL_NUMBER 12
730 #define MAIN_CONTROL_LEVEL_INFO_1 13
731 #define MAIN_CONTROL_LEVEL_INFO_2 14
732 #define MAIN_CONTROL_LEVEL_NAME 15
733 #define MAIN_CONTROL_LEVEL_AUTHOR 16
734 #define MAIN_CONTROL_LEVEL_YEAR 17
735 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
736 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
737 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
738 #define MAIN_CONTROL_TITLE_1 21
739 #define MAIN_CONTROL_TITLE_2 22
740 #define MAIN_CONTROL_TITLE_3 23
742 static char str_main_text_name[10];
743 static char str_main_text_first_level[10];
744 static char str_main_text_last_level[10];
745 static char str_main_text_level_number[10];
747 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
749 static char *main_text_name = str_main_text_name;
750 static char *main_text_first_level = str_main_text_first_level;
751 static char *main_text_last_level = str_main_text_last_level;
752 static char *main_text_level_number = str_main_text_level_number;
753 static char *main_text_levels = "Levelset";
754 static char *main_text_scores = "Hall Of Fame";
755 static char *main_text_editor = "Level Creator";
756 static char *main_text_info = "Info Screen";
757 static char *main_text_game = "Start Game";
758 static char *main_text_setup = "Setup";
759 static char *main_text_quit = "Quit";
760 static char *main_text_level_name = level.name;
761 static char *main_text_level_author = level.author;
762 static char *main_text_level_year = NULL;
763 static char *main_text_level_imported_from = NULL;
764 static char *main_text_level_imported_by = NULL;
765 static char *main_text_level_tested_by = NULL;
766 static char *main_text_title_1 = NULL;
767 static char *main_text_title_2 = NULL;
768 static char *main_text_title_3 = NULL;
770 extern char debug_xsn_mode[];
772 struct MainControlInfo
776 struct MenuPosInfo *pos_button;
779 struct TextPosInfo *pos_text;
782 struct TextPosInfo *pos_input;
786 static struct MainControlInfo main_controls[] =
790 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
791 &menu.main.text.name, &main_text_name,
792 &menu.main.input.name, &setup.player_name,
796 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
797 &menu.main.text.levels, &main_text_levels,
802 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
803 &menu.main.text.scores, &main_text_scores,
808 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
809 &menu.main.text.editor, &main_text_editor,
814 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
815 &menu.main.text.info, &main_text_info,
820 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
821 &menu.main.text.game, &main_text_game,
826 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
827 &menu.main.text.setup, &main_text_setup,
832 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
833 &menu.main.text.quit, &main_text_quit,
837 MAIN_CONTROL_PREV_LEVEL,
843 MAIN_CONTROL_NEXT_LEVEL,
849 MAIN_CONTROL_FIRST_LEVEL,
851 &menu.main.text.first_level, &main_text_first_level,
855 MAIN_CONTROL_LAST_LEVEL,
857 &menu.main.text.last_level, &main_text_last_level,
861 MAIN_CONTROL_LEVEL_NUMBER,
863 &menu.main.text.level_number, &main_text_level_number,
867 MAIN_CONTROL_LEVEL_INFO_1,
869 &menu.main.text.level_info_1, NULL,
873 MAIN_CONTROL_LEVEL_INFO_2,
875 &menu.main.text.level_info_2, NULL,
879 MAIN_CONTROL_LEVEL_NAME,
881 &menu.main.text.level_name, &main_text_level_name,
885 MAIN_CONTROL_LEVEL_AUTHOR,
887 &menu.main.text.level_author, &main_text_level_author,
891 MAIN_CONTROL_LEVEL_YEAR,
893 &menu.main.text.level_year, &main_text_level_year,
897 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
899 &menu.main.text.level_imported_from, &main_text_level_imported_from,
903 MAIN_CONTROL_LEVEL_IMPORTED_BY,
905 &menu.main.text.level_imported_by, &main_text_level_imported_by,
909 MAIN_CONTROL_LEVEL_TESTED_BY,
911 &menu.main.text.level_tested_by, &main_text_level_tested_by,
915 MAIN_CONTROL_TITLE_1,
917 &menu.main.text.title_1, &main_text_title_1,
921 MAIN_CONTROL_TITLE_2,
923 &menu.main.text.title_2, &main_text_title_2,
927 MAIN_CONTROL_TITLE_3,
929 &menu.main.text.title_3, &main_text_title_3,
942 static boolean hasLevelSetInfo(void)
944 return (getLevelSetInfoFilename(0) != NULL);
947 static int getTitleScreenGraphic(int nr, boolean initial)
949 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
952 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
954 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
958 static int getTitleScreenGameMode(boolean initial)
960 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
964 static int getTitleMessageGameMode(boolean initial)
966 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
969 static int getTitleAnimMode(struct TitleControlInfo *tci)
971 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
973 return base + tci->local_nr;
977 static int getTitleScreenBackground(boolean initial)
979 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
984 static int getTitleMessageBackground(int nr, boolean initial)
986 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
990 static int getTitleBackground(int nr, boolean initial, boolean is_image)
992 int base = (is_image ?
993 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
994 IMG_BACKGROUND_TITLESCREEN_1) :
995 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
996 IMG_BACKGROUND_TITLEMESSAGE_1));
997 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
998 IMG_BACKGROUND_TITLE);
999 int graphic_local = base + nr;
1001 if (graphic_info[graphic_local].bitmap != NULL)
1002 return graphic_local;
1004 if (graphic_info[graphic_global].bitmap != NULL)
1005 return graphic_global;
1007 return IMG_UNDEFINED;
1010 static int getTitleSound(struct TitleControlInfo *tci)
1012 boolean is_image = tci->is_image;
1013 int initial = tci->initial;
1014 int nr = tci->local_nr;
1015 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1016 int base = (is_image ?
1017 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
1018 SND_BACKGROUND_TITLESCREEN_1) :
1019 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1020 SND_BACKGROUND_TITLEMESSAGE_1));
1021 int sound_global = menu.sound[mode];
1022 int sound_local = base + nr;
1025 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
1026 nr, initial, is_image,
1027 sound_global, getSoundListEntry(sound_global)->filename,
1028 sound_local, getSoundListEntry(sound_local)->filename);
1031 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1034 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1035 return sound_global;
1037 return SND_UNDEFINED;
1040 static int getTitleMusic(struct TitleControlInfo *tci)
1042 boolean is_image = tci->is_image;
1043 int initial = tci->initial;
1044 int nr = tci->local_nr;
1045 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1046 int base = (is_image ?
1047 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1048 MUS_BACKGROUND_TITLESCREEN_1) :
1049 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1050 MUS_BACKGROUND_TITLEMESSAGE_1));
1051 int music_global = menu.music[mode];
1052 int music_local = base + nr;
1055 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1056 nr, initial, is_image,
1057 music_global, getMusicListEntry(music_global)->filename,
1058 music_local, getMusicListEntry(music_local)->filename);
1061 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1064 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1065 return music_global;
1067 return MUS_UNDEFINED;
1070 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1072 boolean is_image = tci->is_image;
1073 boolean initial = tci->initial;
1074 boolean first = tci->first;
1075 int nr = tci->local_nr;
1076 struct TitleMessageInfo tmi;
1077 struct TitleFadingInfo ti;
1079 tmi = (is_image ? (initial ? (first ?
1080 titlescreen_initial_first[nr] :
1081 titlescreen_initial[nr])
1083 titlescreen_first[nr] :
1085 : (initial ? (first ?
1086 titlemessage_initial_first[nr] :
1087 titlemessage_initial[nr])
1089 titlemessage_first[nr] :
1090 titlemessage[nr])));
1092 ti.fade_mode = tmi.fade_mode;
1093 ti.fade_delay = tmi.fade_delay;
1094 ti.post_delay = tmi.post_delay;
1095 ti.auto_delay = tmi.auto_delay;
1096 ti.auto_delay_unit = tmi.auto_delay_unit;
1101 static int compareTitleControlInfo(const void *object1, const void *object2)
1103 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1104 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1107 if (tci1->initial != tci2->initial)
1108 compare_result = (tci1->initial ? -1 : +1);
1109 else if (tci1->sort_priority != tci2->sort_priority)
1110 compare_result = tci1->sort_priority - tci2->sort_priority;
1111 else if (tci1->is_image != tci2->is_image)
1112 compare_result = (tci1->is_image ? -1 : +1);
1114 compare_result = tci1->local_nr - tci2->local_nr;
1116 return compare_result;
1119 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1121 int nr, int sort_priority)
1123 title_controls[num_title_screens].is_image = is_image;
1124 title_controls[num_title_screens].initial = initial;
1125 title_controls[num_title_screens].local_nr = nr;
1126 title_controls[num_title_screens].sort_priority = sort_priority;
1128 title_controls[num_title_screens].first = FALSE; // will be set later
1130 num_title_screens++;
1133 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1137 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1139 int graphic = getTitleScreenGraphic(i, initial);
1140 Bitmap *bitmap = graphic_info[graphic].bitmap;
1141 int sort_priority = graphic_info[graphic].sort_priority;
1144 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1147 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1149 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1150 char *filename = getLevelSetTitleMessageFilename(i, initial);
1151 int sort_priority = tmi->sort_priority;
1153 if (filename != NULL)
1154 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1158 static void InitializeTitleControls(boolean show_title_initial)
1160 num_title_screens = 0;
1162 // 1st step: initialize title screens for game start (only when starting)
1163 if (show_title_initial)
1164 InitializeTitleControls_CheckTitleInfo(TRUE);
1166 // 2nd step: initialize title screens for current level set
1167 InitializeTitleControls_CheckTitleInfo(FALSE);
1169 // sort title screens according to sort_priority and title number
1170 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1171 compareTitleControlInfo);
1173 // mark first title screen
1174 title_controls[0].first = TRUE;
1177 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1179 return (pos != NULL && pos->x != -1 && pos->y != -1);
1182 static boolean visibleTextPos(struct TextPosInfo *pos)
1184 return (pos != NULL && pos->x != -1 && pos->y != -1);
1187 static void InitializeMainControls(void)
1189 boolean local_team_mode = (!network.enabled && setup.team_mode);
1192 // set main control text values to dynamically determined values
1193 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1195 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1196 menu.main.text.first_level.size));
1197 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1198 menu.main.text.last_level.size));
1199 strcpy(main_text_level_number, int2str(level_nr,
1200 menu.main.text.level_number.size));
1202 main_text_level_year = leveldir_current->year;
1203 main_text_level_imported_from = leveldir_current->imported_from;
1204 main_text_level_imported_by = leveldir_current->imported_by;
1205 main_text_level_tested_by = leveldir_current->tested_by;
1207 main_text_title_1 = getConfigProgramTitleString();
1208 main_text_title_2 = getConfigProgramCopyrightString();
1209 main_text_title_3 = getConfigProgramCompanyString();
1211 // set main control screen positions to dynamically determined values
1212 for (i = 0; main_controls[i].nr != -1; i++)
1214 struct MainControlInfo *mci = &main_controls[i];
1216 struct MenuPosInfo *pos_button = mci->pos_button;
1217 struct TextPosInfo *pos_text = mci->pos_text;
1218 struct TextPosInfo *pos_input = mci->pos_input;
1219 char *text = (mci->text ? *mci->text : NULL);
1220 char *input = (mci->input ? *mci->input : NULL);
1221 int button_graphic = mci->button_graphic;
1222 int font_text = (pos_text ? pos_text->font : -1);
1223 int font_input = (pos_input ? pos_input->font : -1);
1225 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1226 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1227 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1228 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1229 int text_chars = (text != NULL ? strlen(text) : 0);
1230 int input_chars = (input != NULL ? strlen(input) : 0);
1233 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1235 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1236 int text_width = font_text_width * text_chars;
1237 int text_height = font_text_height;
1238 int input_width = font_input_width * input_chars;
1239 int input_height = font_input_height;
1241 if (nr == MAIN_CONTROL_NAME)
1243 menu.main.input.name.width = input_width;
1244 menu.main.input.name.height = input_height;
1247 if (pos_button != NULL) // (x/y may be -1/-1 here)
1249 pos_button->width = button_width;
1250 pos_button->height = button_height;
1253 if (pos_text != NULL) // (x/y may be -1/-1 here)
1255 // calculate text size -- needed for text alignment
1256 boolean calculate_text_size = (text != NULL);
1258 if (pos_text->width == -1 || calculate_text_size)
1259 pos_text->width = text_width;
1260 if (pos_text->height == -1 || calculate_text_size)
1261 pos_text->height = text_height;
1263 if (visibleMenuPos(pos_button))
1265 if (pos_text->x == -1)
1266 pos_text->x = pos_button->x + pos_button->width;
1267 if (pos_text->y == -1)
1269 pos_button->y + (pos_button->height - pos_text->height) / 2;
1273 if (pos_input != NULL) // (x/y may be -1/-1 here)
1275 if (visibleTextPos(pos_text))
1277 if (pos_input->x == -1)
1278 pos_input->x = pos_text->x + pos_text->width;
1279 if (pos_input->y == -1)
1280 pos_input->y = pos_text->y;
1283 if (pos_input->width == -1)
1284 pos_input->width = input_width;
1285 if (pos_input->height == -1)
1286 pos_input->height = input_height;
1291 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1292 int graphic, boolean pressed)
1294 struct GraphicInfo *g = &graphic_info[graphic];
1297 int xoffset = (pressed ? g->pressed_xoffset : 0);
1298 int yoffset = (pressed ? g->pressed_yoffset : 0);
1300 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1302 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1303 g->width, g->height, dst_x, dst_y);
1306 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1307 boolean active_input,
1308 boolean pressed_button)
1312 for (i = 0; main_controls[i].nr != -1; i++)
1314 struct MainControlInfo *mci = &main_controls[i];
1316 if (mci->nr == nr || nr == -1)
1318 struct MenuPosInfo *pos_button = mci->pos_button;
1319 struct TextPosInfo *pos_text = mci->pos_text;
1320 struct TextPosInfo *pos_input = mci->pos_input;
1321 char *text = (mci->text ? *mci->text : NULL);
1322 char *input = (mci->input ? *mci->input : NULL);
1323 int button_graphic = mci->button_graphic;
1324 int font_text = (pos_text ? pos_text->font : -1);
1325 int font_input = (pos_input ? pos_input->font : -1);
1329 button_graphic = BUTTON_ACTIVE(button_graphic);
1330 font_text = FONT_ACTIVE(font_text);
1335 font_input = FONT_ACTIVE(font_input);
1338 if (visibleMenuPos(pos_button))
1340 struct MenuPosInfo *pos = pos_button;
1341 int x = mSX + pos->x;
1342 int y = mSY + pos->y;
1344 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1345 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1348 if (visibleTextPos(pos_text) && text != NULL)
1350 struct TextPosInfo *pos = pos_text;
1351 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1352 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1355 // (check why/if this is needed)
1356 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1358 DrawText(x, y, text, font_text);
1361 if (visibleTextPos(pos_input) && input != NULL)
1363 struct TextPosInfo *pos = pos_input;
1364 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1365 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1368 // (check why/if this is needed)
1369 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1371 DrawText(x, y, input, font_input);
1377 static void DrawCursorAndText_Main(int nr, boolean active_text,
1378 boolean pressed_button)
1380 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1384 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1385 boolean pressed_button)
1387 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1391 static struct MainControlInfo *getMainControlInfo(int nr)
1395 for (i = 0; main_controls[i].nr != -1; i++)
1396 if (main_controls[i].nr == nr)
1397 return &main_controls[i];
1402 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1407 int rect_x = ALIGNED_TEXT_XPOS(rect);
1408 int rect_y = ALIGNED_TEXT_YPOS(rect);
1410 return (x >= rect_x && x < rect_x + rect->width &&
1411 y >= rect_y && y < rect_y + rect->height);
1414 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1419 int rect_x = ALIGNED_TEXT_XPOS(rect);
1420 int rect_y = ALIGNED_TEXT_YPOS(rect);
1423 Debug("screens:insideTextPosRect",
1424 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1425 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1426 (x >= rect_x && x < rect_x + rect->width &&
1427 y >= rect_y && y < rect_y + rect->height));
1430 return (x >= rect_x && x < rect_x + rect->width &&
1431 y >= rect_y && y < rect_y + rect->height);
1434 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1436 int rect_width = preview->xsize * preview->tile_size;
1437 int rect_height = preview->ysize * preview->tile_size;
1438 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1439 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1441 return (x >= rect_x && x < rect_x + rect_width &&
1442 y >= rect_y && y < rect_y + rect_height);
1445 static void AdjustScrollbar(int id, int items_max, int items_visible,
1448 struct GadgetInfo *gi = screen_gadget[id];
1450 if (item_position > items_max - items_visible)
1451 item_position = items_max - items_visible;
1453 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1454 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1455 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1458 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1460 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1464 static void clearMenuListArea(void)
1466 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1468 // correct scrollbar position if placed outside menu (playfield) area
1469 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1470 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1472 // clear menu list area, but not title or scrollbar
1473 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1474 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1476 // special compatibility handling for "Snake Bite" graphics set
1477 if (strPrefix(leveldir_current->identifier, "snake_bite"))
1478 ClearRectangle(drawto, mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1479 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1482 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1484 static int cursor_array[MAX_LEV_FIELDY];
1485 int x = amSX + TILEX * xpos;
1486 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1491 cursor_array[ypos] = graphic;
1493 graphic = cursor_array[ypos];
1497 graphic = BUTTON_ACTIVE(graphic);
1499 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1500 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1503 static void initCursor(int ypos, int graphic)
1505 drawCursorExt(0, ypos, FALSE, graphic);
1508 static void drawCursor(int ypos, boolean active)
1510 drawCursorExt(0, ypos, active, -1);
1513 static void drawCursorXY(int xpos, int ypos, int graphic)
1515 drawCursorExt(xpos, ypos, FALSE, graphic);
1518 static void drawChooseTreeCursor(int ypos, boolean active)
1520 drawCursorExt(0, ypos, active, -1);
1523 static int getChooseTreeEditFont(boolean active)
1525 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1528 static int getChooseTreeEditXPos(int pos)
1530 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1531 int xoffset = (has_scrollbar ? -1 : 0);
1532 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1533 int sx = amSX + xpos * TILEX;
1534 int font_nr = getChooseTreeEditFont(FALSE);
1535 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1537 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1540 static int getChooseTreeEditYPos(int ypos_raw)
1542 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1543 int sy = amSY + ypos * TILEY;
1548 static int getChooseTreeEditXPosReal(int pos)
1550 int xpos = getChooseTreeEditXPos(pos);
1551 int font_nr = getChooseTreeEditFont(FALSE);
1552 int font_xoffset = getFontDrawOffsetX(font_nr);
1554 return xpos + font_xoffset;
1557 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1559 int sx = getChooseTreeEditXPos(POS_LEFT);
1560 int sy = getChooseTreeEditYPos(ypos_raw);
1561 int font_nr = getChooseTreeEditFont(active);
1563 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1566 static void DrawInfoScreen_Headline(int screen_nr, int num_screens,
1567 int use_global_screens)
1569 char *info_text_title_1 = getInfoScreenTitle_Generic();
1570 char info_text_title_2[MAX_LINE_LEN + 1];
1572 if (num_screens > 1)
1574 sprintf(info_text_title_2, "Page %d of %d", screen_nr + 1, num_screens);
1578 char *text_format = (use_global_screens ? "for %s" : "for \"%s\"");
1579 int max_text_len = SXSIZE / getFontWidth(FONT_TITLE_2);
1580 int max_name_len = max_text_len - strlen(text_format) - strlen("%s");
1581 char name_cut[max_name_len];
1582 char *name_full = (use_global_screens ? getProgramTitleString() :
1583 leveldir_current->name);
1585 snprintf(name_cut, max_name_len, "%s", name_full);
1586 snprintf(info_text_title_2, max_text_len, text_format, name_cut);
1589 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, info_text_title_1);
1590 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, info_text_title_2);
1593 static void DrawTitleScreenImage(int nr, boolean initial)
1595 int graphic = getTitleScreenGraphic(nr, initial);
1596 Bitmap *bitmap = graphic_info[graphic].bitmap;
1597 int width = graphic_info[graphic].width;
1598 int height = graphic_info[graphic].height;
1599 int src_x = graphic_info[graphic].src_x;
1600 int src_y = graphic_info[graphic].src_y;
1606 if (width > WIN_XSIZE)
1608 // image width too large for window => center image horizontally
1609 src_x = (width - WIN_XSIZE) / 2;
1613 if (height > WIN_YSIZE)
1615 // image height too large for window => center image vertically
1616 src_y = (height - WIN_YSIZE) / 2;
1620 // always display title screens centered
1621 dst_x = (WIN_XSIZE - width) / 2;
1622 dst_y = (WIN_YSIZE - height) / 2;
1624 SetDrawBackgroundMask(REDRAW_ALL);
1625 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1627 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1629 if (DrawingOnBackground(dst_x, dst_y))
1630 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1632 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1634 redraw_mask = REDRAW_ALL;
1637 static void DrawTitleScreenMessage(int nr, boolean initial)
1639 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1640 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1642 if (filename == NULL)
1645 // force TITLE font on title message screen
1646 SetFontStatus(getTitleMessageGameMode(initial));
1648 // if chars *and* width set to "-1", automatically determine width
1649 if (tmi->chars == -1 && tmi->width == -1)
1650 tmi->width = viewport.window[game_status].width;
1652 // if lines *and* height set to "-1", automatically determine height
1653 if (tmi->lines == -1 && tmi->height == -1)
1654 tmi->height = viewport.window[game_status].height;
1656 // if chars set to "-1", automatically determine by text and font width
1657 if (tmi->chars == -1)
1658 tmi->chars = tmi->width / getFontWidth(tmi->font);
1660 tmi->width = tmi->chars * getFontWidth(tmi->font);
1662 // if lines set to "-1", automatically determine by text and font height
1663 if (tmi->lines == -1)
1664 tmi->lines = tmi->height / getFontHeight(tmi->font);
1666 tmi->height = tmi->lines * getFontHeight(tmi->font);
1668 // if x set to "-1", automatically determine by width and alignment
1670 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1672 // if y set to "-1", automatically determine by height and alignment
1674 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1676 SetDrawBackgroundMask(REDRAW_ALL);
1677 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1679 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1681 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1682 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1683 tmi->autowrap, tmi->centered, tmi->parse_comments);
1688 static void DrawTitleScreen(void)
1690 KeyboardAutoRepeatOff();
1692 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1695 static boolean CheckTitleScreen(boolean levelset_has_changed)
1697 static boolean show_title_initial = TRUE;
1698 boolean show_titlescreen = FALSE;
1700 // needed to be able to skip title screen, if no image or message defined
1701 InitializeTitleControls(show_title_initial);
1703 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1704 show_titlescreen = TRUE;
1706 // show initial title images and messages only once at program start
1707 show_title_initial = FALSE;
1709 return (show_titlescreen && num_title_screens > 0);
1712 void DrawMainMenu(void)
1714 static LevelDirTree *leveldir_last_valid = NULL;
1715 boolean levelset_has_changed = FALSE;
1716 int fade_mask = REDRAW_FIELD;
1718 LimitScreenUpdates(FALSE);
1720 FadeSetLeaveScreen();
1722 // do not fade out here -- function may continue and fade on editor screen
1725 FadeMenuSoundsAndMusic();
1727 ExpireSoundLoops(FALSE);
1729 KeyboardAutoRepeatOn();
1731 audio.sound_deactivated = FALSE;
1735 // needed if last screen was the playing screen, invoked from level editor
1736 if (level_editor_test_game)
1738 CloseDoor(DOOR_CLOSE_ALL);
1740 SetGameStatus(GAME_MODE_EDITOR);
1747 // needed if last screen was the playing screen, invoked from hall of fame
1748 if (score_info_tape_play)
1750 CloseDoor(DOOR_CLOSE_ALL);
1752 SetGameStatus(GAME_MODE_SCOREINFO);
1754 DrawScoreInfo(scores.last_entry_nr);
1759 // reset flag to continue playing next level from hall of fame
1760 scores.continue_playing = FALSE;
1762 // leveldir_current may be invalid (level group, parent link, node copy)
1763 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1765 if (leveldir_current != leveldir_last_valid)
1767 // level setup config may have been loaded to "last played" tree node copy,
1768 // but "leveldir_current" now points to the "original" level set tree node,
1769 // in which case "handicap_level" may still default to the first level
1770 LoadLevelSetup_SeriesInfo();
1772 UpdateLastPlayedLevels_TreeInfo();
1774 levelset_has_changed = TRUE;
1777 // store valid level series information
1778 leveldir_last_valid = leveldir_current;
1780 // needed if last screen (level choice) changed graphics, sounds or music
1781 ReloadCustomArtwork(0);
1783 if (CheckTitleScreen(levelset_has_changed))
1785 SetGameStatus(GAME_MODE_TITLE);
1792 if (redraw_mask & REDRAW_ALL)
1793 fade_mask = REDRAW_ALL;
1796 fade_mask = REDRAW_ALL;
1800 // needed if different viewport properties defined for menues
1801 ChangeViewportPropertiesIfNeeded();
1803 SetDrawtoField(DRAW_TO_BACKBUFFER);
1805 // level_nr may have been set to value over handicap with level editor
1806 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1807 level_nr = leveldir_current->handicap_level;
1809 LoadLevel(level_nr);
1810 LoadScore(level_nr);
1812 SaveLevelSetup_SeriesInfo();
1814 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1815 SetDrawDeactivationMask(REDRAW_NONE);
1816 SetDrawBackgroundMask(REDRAW_FIELD);
1818 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1821 if (fade_mask == REDRAW_ALL)
1822 RedrawGlobalBorder();
1827 InitializeMainControls();
1829 DrawCursorAndText_Main(-1, FALSE, FALSE);
1830 DrawPreviewLevelInitial();
1831 DrawNetworkPlayers();
1833 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1836 if (TAPE_IS_EMPTY(tape))
1838 DrawCompleteVideoDisplay();
1840 PlayMenuSoundsAndMusic();
1842 // create gadgets for main menu screen
1843 FreeScreenGadgets();
1844 CreateScreenGadgets();
1846 // may be required if audio buttons shown on tape and changed in setup menu
1848 CreateGameButtons();
1850 // map gadgets for main menu screen
1852 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1853 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1854 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SET_INFO, hasLevelSetInfo());
1856 // copy actual game door content to door double buffer for OpenDoor()
1857 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1858 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1860 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1862 DrawMaskedBorder(fade_mask);
1867 // update screen area with special editor door
1868 redraw_mask |= REDRAW_ALL;
1871 SetMouseCursor(CURSOR_DEFAULT);
1873 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1875 SyncEmscriptenFilesystem();
1877 // needed once after program start or after user change
1878 CheckApiServerTasks();
1881 static void gotoTopLevelDir(void)
1883 // move upwards until inside (but not above) top level directory
1884 while (leveldir_current->node_parent &&
1885 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1887 // write a "path" into level tree for easy navigation to last level
1888 if (leveldir_current->node_parent->node_group->cl_first == -1)
1890 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1891 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1892 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1893 int cl_first, cl_cursor;
1895 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1896 cl_cursor = leveldir_pos - cl_first;
1898 leveldir_current->node_parent->node_group->cl_first = cl_first;
1899 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1902 leveldir_current = leveldir_current->node_parent;
1906 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1908 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1910 return (use_frame_counter ? video.frame_counter : Counter());
1913 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1914 struct TitleFadingInfo *fi)
1916 return DelayReachedExt2(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1919 static void ResetTitleAutoDelay(unsigned int *counter_var,
1920 struct TitleFadingInfo *fi)
1922 *counter_var = getAutoDelayCounter(fi);
1925 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1927 static unsigned int title_delay = 0;
1928 static int title_screen_nr = 0;
1929 static int last_sound = -1, last_music = -1;
1930 boolean return_to_main_menu = FALSE;
1931 struct TitleControlInfo *tci;
1934 if (button == MB_MENU_INITIALIZE)
1937 title_screen_nr = 0;
1938 tci = &title_controls[title_screen_nr];
1940 SetAnimStatus(getTitleAnimMode(tci));
1942 last_sound = SND_UNDEFINED;
1943 last_music = MUS_UNDEFINED;
1945 if (num_title_screens != 0)
1947 FadeSetEnterScreen();
1949 // use individual title fading instead of global "enter screen" fading
1950 fading = getTitleFading(tci);
1953 if (game_status_last_screen == GAME_MODE_INFO)
1955 if (num_title_screens == 0)
1957 // switch game mode from title screen mode back to info screen mode
1958 SetGameStatus(GAME_MODE_INFO);
1960 // store that last screen was info screen, not main menu screen
1961 game_status_last_screen = GAME_MODE_INFO;
1963 DrawInfoScreen_NotAvailable("Title screen information:",
1964 "No title screen for this level set.");
1969 FadeMenuSoundsAndMusic();
1971 FadeOut(REDRAW_ALL);
1973 // title screens may have different window size
1974 ChangeViewportPropertiesIfNeeded();
1976 // only required to update logic for redrawing global border
1980 DrawTitleScreenImage(tci->local_nr, tci->initial);
1982 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1984 sound = getTitleSound(tci);
1985 music = getTitleMusic(tci);
1987 if (sound != last_sound)
1988 PlayMenuSoundExt(sound);
1989 if (music != last_music)
1990 PlayMenuMusicExt(music);
1995 SetMouseCursor(CURSOR_NONE);
1999 ResetTitleAutoDelay(&title_delay, &fading);
2004 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
2005 button = MB_MENU_CHOICE;
2007 if (button == MB_MENU_LEAVE)
2009 return_to_main_menu = TRUE;
2011 else if (button == MB_MENU_CHOICE || dx)
2013 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
2015 SetGameStatus(GAME_MODE_INFO);
2017 info_mode = INFO_MODE_MAIN;
2025 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
2027 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
2029 tci = &title_controls[title_screen_nr];
2031 SetAnimStatus(getTitleAnimMode(tci));
2033 sound = getTitleSound(tci);
2034 music = getTitleMusic(tci);
2036 if (last_sound != SND_UNDEFINED && sound != last_sound)
2037 FadeSound(last_sound);
2038 if (last_music != MUS_UNDEFINED && music != last_music)
2041 fading = getTitleFading(tci);
2043 FadeOut(REDRAW_ALL);
2046 DrawTitleScreenImage(tci->local_nr, tci->initial);
2048 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2050 sound = getTitleSound(tci);
2051 music = getTitleMusic(tci);
2053 if (sound != last_sound)
2054 PlayMenuSoundExt(sound);
2055 if (music != last_music)
2056 PlayMenuMusicExt(music);
2063 ResetTitleAutoDelay(&title_delay, &fading);
2067 FadeMenuSoundsAndMusic();
2069 return_to_main_menu = TRUE;
2073 if (return_to_main_menu)
2075 SetMouseCursor(CURSOR_DEFAULT);
2077 // force full menu screen redraw after displaying title screens
2078 redraw_mask = REDRAW_ALL;
2080 if (game_status_last_screen == GAME_MODE_INFO)
2082 SetGameStatus(GAME_MODE_INFO);
2084 info_mode = INFO_MODE_MAIN;
2088 else // default: return to main menu
2090 SetGameStatus(GAME_MODE_MAIN);
2097 static void HandleMainMenu_ToggleTeamMode(void)
2099 setup.team_mode = !setup.team_mode;
2101 InitializeMainControls();
2102 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2104 DrawPreviewPlayers();
2107 static void HandleMainMenu_SelectLevel(int step, int direction,
2108 int selected_level_nr)
2110 int old_level_nr = level_nr;
2113 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2114 new_level_nr = selected_level_nr;
2116 new_level_nr = old_level_nr + step * direction;
2118 if (new_level_nr < leveldir_current->first_level)
2119 new_level_nr = leveldir_current->first_level;
2120 if (new_level_nr > leveldir_current->last_level)
2121 new_level_nr = leveldir_current->last_level;
2123 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2125 // skipping levels is only allowed when trying to skip single level
2126 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2127 Request("Level still unsolved! Skip it anyway?", REQ_ASK))
2129 leveldir_current->handicap_level++;
2130 SaveLevelSetup_SeriesInfo();
2133 new_level_nr = leveldir_current->handicap_level;
2136 if (new_level_nr != old_level_nr)
2138 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2140 PlaySound(SND_MENU_ITEM_SELECTING);
2142 level_nr = new_level_nr;
2144 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2145 int2str(level_nr, menu.main.text.level_number.size),
2146 mci->pos_text->font);
2148 LoadLevel(level_nr);
2149 DrawPreviewLevelInitial();
2153 DrawCompleteVideoDisplay();
2155 SaveLevelSetup_SeriesInfo();
2157 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2159 // force redraw of playfield area (may be reset at this point)
2160 redraw_mask |= REDRAW_FIELD;
2164 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2166 static int choice = MAIN_CONTROL_GAME;
2167 static boolean button_pressed_last = FALSE;
2168 boolean button_pressed = FALSE;
2170 int i = 0; // needed to prevent compiler warning due to bad code below
2172 if (button == MB_MENU_INITIALIZE)
2174 DrawCursorAndText_Main(choice, TRUE, FALSE);
2179 if (mx || my) // mouse input
2183 for (i = 0; main_controls[i].nr != -1; i++)
2185 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2186 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2187 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2189 pos = main_controls[i].nr;
2195 // check if level preview was clicked
2196 if (insidePreviewRect(&preview, mx - SX, my - SY))
2197 pos = MAIN_CONTROL_GAME;
2199 // handle pressed/unpressed state for active/inactive menu buttons
2200 // (if pos != -1, "i" contains index position corresponding to "pos")
2202 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2203 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2204 button_pressed = TRUE;
2206 if (button_pressed != button_pressed_last)
2208 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2211 PlaySound(SND_MENU_BUTTON_PRESSING);
2213 PlaySound(SND_MENU_BUTTON_RELEASING);
2216 else if (dx || dy) // keyboard input
2218 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2219 choice == MAIN_CONTROL_SETUP))
2220 button = MB_MENU_CHOICE;
2225 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2227 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2229 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2231 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2233 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2235 CloseDoor(DOOR_CLOSE_2);
2237 SetGameStatus(GAME_MODE_LEVELNR);
2239 DrawChooseLevelNr();
2241 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2247 PlaySound(SND_MENU_ITEM_ACTIVATING);
2249 DrawCursorAndText_Main(choice, FALSE, FALSE);
2250 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2256 if (choice == MAIN_CONTROL_NAME)
2258 // special case: cursor left or right pressed -- toggle team mode
2259 HandleMainMenu_ToggleTeamMode();
2261 else if (choice != MAIN_CONTROL_INFO &&
2262 choice != MAIN_CONTROL_SETUP)
2264 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2270 PlaySound(SND_MENU_ITEM_SELECTING);
2272 if (pos == MAIN_CONTROL_NAME)
2275 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2277 // special case: menu text "name/team" clicked -- toggle team mode
2278 HandleMainMenu_ToggleTeamMode();
2282 if (setup.multiple_users)
2284 CloseDoor(DOOR_CLOSE_2);
2286 SetGameStatus(GAME_MODE_NAMES);
2288 DrawChoosePlayerName();
2292 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2298 else if (pos == MAIN_CONTROL_LEVELS)
2302 CloseDoor(DOOR_CLOSE_2);
2304 SetGameStatus(GAME_MODE_LEVELS);
2306 SaveLevelSetup_LastSeries();
2307 SaveLevelSetup_SeriesInfo();
2309 // restore level set if chosen from "last played level set" menu
2310 RestoreLastPlayedLevels(&leveldir_current);
2312 if (setup.internal.choose_from_top_leveldir)
2315 DrawChooseLevelSet();
2318 else if (pos == MAIN_CONTROL_SCORES)
2320 CloseDoor(DOOR_CLOSE_2);
2322 SetGameStatus(GAME_MODE_SCORES);
2324 DrawHallOfFame(level_nr);
2326 else if (pos == MAIN_CONTROL_EDITOR)
2328 if (leveldir_current->readonly &&
2329 setup.editor.show_read_only_warning)
2330 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2332 CloseDoor(DOOR_CLOSE_ALL);
2334 SetGameStatus(GAME_MODE_EDITOR);
2336 FadeSetEnterScreen();
2340 else if (pos == MAIN_CONTROL_INFO)
2342 CloseDoor(DOOR_CLOSE_2);
2344 SetGameStatus(GAME_MODE_INFO);
2346 info_mode = INFO_MODE_MAIN;
2350 else if (pos == MAIN_CONTROL_GAME)
2352 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2354 else if (pos == MAIN_CONTROL_SETUP)
2356 CloseDoor(DOOR_CLOSE_2);
2358 SetGameStatus(GAME_MODE_SETUP);
2360 setup_mode = SETUP_MODE_MAIN;
2364 else if (pos == MAIN_CONTROL_QUIT)
2366 SaveLevelSetup_LastSeries();
2367 SaveLevelSetup_SeriesInfo();
2369 #if defined(PLATFORM_EMSCRIPTEN)
2370 Request("Close the browser window to quit!", REQ_CONFIRM);
2372 if (!setup.ask_on_quit_program ||
2373 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2374 SetGameStatus(GAME_MODE_QUIT);
2380 button_pressed_last = button_pressed;
2384 // ============================================================================
2385 // info screen functions
2386 // ============================================================================
2388 static struct TokenInfo *info_info;
2389 static int num_info_info; // number of info entries shown on screen
2390 static int max_info_info; // total number of info entries in list
2392 static void execInfoTitleScreen(void)
2394 info_mode = INFO_MODE_TITLE;
2399 static void execInfoElements(void)
2401 info_mode = INFO_MODE_ELEMENTS;
2406 static void execInfoMusic(void)
2408 info_mode = INFO_MODE_MUSIC;
2413 static void execInfoCredits(void)
2415 info_mode = INFO_MODE_CREDITS;
2420 static void execInfoProgram(void)
2422 info_mode = INFO_MODE_PROGRAM;
2427 static void execInfoVersion(void)
2429 info_mode = INFO_MODE_VERSION;
2434 static void execInfoLevelSet(void)
2436 info_mode = INFO_MODE_LEVELSET;
2441 static void execExitInfo(void)
2443 SetGameStatus(GAME_MODE_MAIN);
2448 static struct TokenInfo info_info_main[] =
2450 { TYPE_ENTER_SCREEN, execInfoTitleScreen, STR_INFO_TITLE },
2451 { TYPE_ENTER_SCREEN, execInfoElements, STR_INFO_ELEMENTS },
2452 { TYPE_ENTER_SCREEN, execInfoMusic, STR_INFO_MUSIC },
2453 { TYPE_ENTER_SCREEN, execInfoCredits, STR_INFO_CREDITS },
2454 { TYPE_ENTER_SCREEN, execInfoProgram, STR_INFO_PROGRAM },
2455 { TYPE_ENTER_SCREEN, execInfoVersion, STR_INFO_VERSION },
2456 { TYPE_ENTER_SCREEN, execInfoLevelSet, STR_INFO_LEVELSET },
2457 { TYPE_EMPTY, NULL, "" },
2458 { TYPE_LEAVE_MENU, execExitInfo, STR_INFO_EXIT },
2463 static int getMenuTextFont(int type)
2465 if (type & (TYPE_SWITCH |
2479 static struct TokenInfo *setup_info;
2480 static struct TokenInfo setup_info_input[];
2482 static struct TokenInfo *menu_info;
2484 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2485 int screen_pos, int menu_info_pos_raw,
2488 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2489 struct TokenInfo *ti = &token_info[pos];
2490 int xpos = MENU_SCREEN_START_XPOS;
2491 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2492 int font_nr = getMenuTextFont(ti->type);
2494 if (setup_mode == SETUP_MODE_INPUT)
2495 font_nr = FONT_MENU_1;
2498 font_nr = FONT_ACTIVE(font_nr);
2500 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2502 if (ti->type & ~TYPE_SKIP_ENTRY)
2503 drawCursor(screen_pos, active);
2506 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2509 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2512 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2515 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2518 static char *window_size_text;
2519 static char *scaling_type_text;
2520 static char *network_server_text;
2522 static void drawSetupValue(int, int);
2524 static void drawMenuInfoList(int first_entry, int num_page_entries,
2525 int max_page_entries)
2529 if (first_entry + num_page_entries > max_page_entries)
2532 clearMenuListArea();
2534 for (i = 0; i < num_page_entries; i++)
2536 int menu_info_pos = first_entry + i;
2537 struct TokenInfo *si = &menu_info[menu_info_pos];
2538 void *value_ptr = si->value;
2540 // set some entries to "unchangeable" according to other variables
2541 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2542 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2543 (value_ptr == &setup.sound_music && !audio.music_available) ||
2544 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2545 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2546 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2547 si->type |= TYPE_GHOSTED;
2549 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2550 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2551 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2552 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2553 else if (si->type & ~TYPE_SKIP_ENTRY)
2554 initCursor(i, IMG_MENU_BUTTON);
2556 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2558 if (si->type & TYPE_STRING)
2562 if (value_ptr == &network_server_text)
2563 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2565 if (gadget_id != -1)
2567 struct GadgetInfo *gi = screen_gadget[gadget_id];
2568 int xpos = MENU_SCREEN_START_XPOS;
2569 int ypos = MENU_SCREEN_START_YPOS + i;
2570 int x = mSX + xpos * 32;
2571 int y = mSY + ypos * 32;
2573 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2577 if (si->type & TYPE_VALUE &&
2578 menu_info == setup_info)
2579 drawSetupValue(i, menu_info_pos);
2583 static void DrawInfoScreen_Main(void)
2585 int fade_mask = REDRAW_FIELD;
2588 // (needed after displaying info sub-screens directly from main menu)
2589 if (info_screens_from_main)
2591 info_screens_from_main = FALSE;
2593 SetGameStatus(GAME_MODE_MAIN);
2600 if (redraw_mask & REDRAW_ALL)
2601 fade_mask = REDRAW_ALL;
2604 fade_mask = REDRAW_ALL;
2607 FadeMenuSoundsAndMusic();
2609 FreeScreenGadgets();
2610 CreateScreenGadgets();
2612 // (needed after displaying title screens which disable auto repeat)
2613 KeyboardAutoRepeatOn();
2615 FadeSetLeaveScreen();
2619 // needed if different viewport properties defined for info screen
2620 ChangeViewportPropertiesIfNeeded();
2622 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2626 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2628 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_INFO_MAIN);
2630 info_info = info_info_main;
2632 // use modified info screen info without info screen entries marked as hidden
2633 info_info = getSetupInfoFinal(info_info);
2635 // determine maximal number of info entries that can be displayed on screen
2637 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2640 // determine maximal number of info entries available for menu of info screen
2642 for (i = 0; info_info[i].type != 0; i++)
2645 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2647 MapScreenGadgets(max_info_info);
2649 PlayMenuSoundsAndMusic();
2651 DrawMaskedBorder(fade_mask);
2656 static void changeSetupValue(int, int, int);
2658 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2659 int mode, int num_page_entries,
2660 int max_page_entries)
2662 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2663 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2664 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2665 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2666 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2667 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2668 int *num_page_entries_last = num_page_entries_all_last[game_status];
2669 int *choice_store = choice_stores[game_status];
2670 int *first_entry_store = first_entry_stores[game_status];
2671 int choice = choice_store[mode]; // starts with 0
2672 int first_entry = first_entry_store[mode]; // starts with 0
2674 int y = choice - first_entry;
2676 boolean position_set_by_scrollbar = (dx == 999);
2677 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2680 if (button == MB_MENU_INITIALIZE)
2682 // check if number of menu page entries has changed (may happen by change
2683 // of custom artwork definition value for 'list_size' for this menu screen)
2684 // (in this case, the last menu position most probably has to be corrected)
2685 if (num_page_entries != num_page_entries_last[mode])
2687 choice_store[mode] = first_entry_store[mode] = 0;
2689 choice = first_entry = 0;
2692 num_page_entries_last[mode] = num_page_entries;
2695 // advance to first valid menu entry
2696 while (choice < num_page_entries &&
2697 menu_info[choice].type & TYPE_SKIP_ENTRY)
2700 if (position_set_by_scrollbar)
2701 first_entry = first_entry_store[mode] = dy;
2703 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2704 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2706 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2708 if (choice < first_entry)
2710 choice = first_entry;
2712 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2715 else if (choice > first_entry + num_page_entries - 1)
2717 choice = first_entry + num_page_entries - 1;
2719 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2723 choice_store[mode] = choice;
2725 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2729 else if (button == MB_MENU_LEAVE)
2731 PlaySound(SND_MENU_ITEM_SELECTING);
2733 for (i = 0; i < max_page_entries; i++)
2735 if (menu_info[i].type & TYPE_LEAVE_MENU)
2737 void (*menu_callback_function)(void) = menu_info[i].value;
2741 menu_callback_function();
2743 break; // absolutely needed because function changes 'menu_info'!
2750 if (mx || my) // mouse input
2752 x = (mx - mSX) / 32;
2753 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2755 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2757 // move cursor instead of scrolling when already at start/end of list
2758 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2760 else if (dy == +1 * SCROLL_LINE &&
2761 first_entry + num_page_entries == max_page_entries)
2764 // handle scrolling screen one line or page
2766 y + dy > num_page_entries - 1)
2768 boolean redraw = FALSE;
2770 if (ABS(dy) == SCROLL_PAGE)
2771 step = num_page_entries - 1;
2773 if (dy < 0 && first_entry > 0)
2775 // scroll page/line up
2777 first_entry -= step;
2778 if (first_entry < 0)
2783 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2785 // scroll page/line down
2787 first_entry += step;
2788 if (first_entry + num_page_entries > max_page_entries)
2789 first_entry = MAX(0, max_page_entries - num_page_entries);
2796 choice += first_entry - first_entry_store[mode];
2798 if (choice < first_entry)
2800 choice = first_entry;
2802 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2805 else if (choice > first_entry + num_page_entries - 1)
2807 choice = first_entry + num_page_entries - 1;
2809 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2812 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2816 if (choice < first_entry ||
2817 choice > first_entry + num_page_entries - 1)
2818 first_entry += SIGN(dy);
2821 first_entry_store[mode] = first_entry;
2822 choice_store[mode] = choice;
2824 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2826 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2828 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2829 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2837 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2839 if (menu_info[choice].type & menu_navigation_type ||
2840 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2841 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2842 menu_info[choice].type & TYPE_PLAYER)
2843 button = MB_MENU_CHOICE;
2848 // jump to next non-empty menu entry (up or down)
2849 while (first_entry + y > 0 &&
2850 first_entry + y < max_page_entries - 1 &&
2851 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2854 if (!IN_VIS_MENU(x, y))
2856 choice += y - y_old;
2858 if (choice < first_entry)
2859 first_entry = choice;
2860 else if (choice > first_entry + num_page_entries - 1)
2861 first_entry = choice - num_page_entries + 1;
2863 if (first_entry >= 0 &&
2864 first_entry + num_page_entries <= max_page_entries)
2866 first_entry_store[mode] = first_entry;
2868 if (choice < first_entry)
2869 choice = first_entry;
2870 else if (choice > first_entry + num_page_entries - 1)
2871 choice = first_entry + num_page_entries - 1;
2873 choice_store[mode] = choice;
2875 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2877 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2879 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2880 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2887 if (!anyScrollbarGadgetActive() &&
2888 IN_VIS_MENU(x, y) &&
2889 mx < mx_right_border &&
2890 y >= 0 && y < num_page_entries)
2894 if (first_entry + y != choice &&
2895 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2897 PlaySound(SND_MENU_ITEM_ACTIVATING);
2899 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2900 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2902 choice = choice_store[mode] = first_entry + y;
2906 PlaySound(SND_MENU_ITEM_SELECTING);
2908 for (i = 0; menu_info[i].type != 0; i++)
2910 if (menu_info[i].type & TYPE_LEAVE_MENU)
2912 void (*menu_callback_function)(void) = menu_info[i].value;
2916 menu_callback_function();
2918 // absolutely needed because function changes 'menu_info'!
2926 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2928 PlaySound(SND_MENU_ITEM_SELECTING);
2930 // when selecting key headline, execute function for key value change
2931 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2932 menu_info[first_entry + y + 1].type & TYPE_KEY)
2935 // when selecting string value, execute function for list selection
2936 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2937 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2940 // when selecting string value, execute function for text input gadget
2941 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2942 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2945 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2947 void (*menu_callback_function)(void) =
2948 menu_info[first_entry + y].value;
2950 FadeSetFromType(menu_info[first_entry + y].type);
2952 menu_callback_function();
2954 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2956 void (*gadget_callback_function)(void) =
2957 menu_info[first_entry + y].value;
2959 gadget_callback_function();
2961 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2962 menu_info == setup_info)
2964 changeSetupValue(y, first_entry + y, dx);
2970 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2972 menu_info = info_info;
2974 HandleMenuScreen(mx, my, dx, dy, button,
2975 info_mode, num_info_info, max_info_info);
2978 static int getMenuFontSpacing(int spacing_height, int font_nr)
2980 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2982 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2986 static int getMenuTextSpacing(int spacing_height, int font_nr)
2988 return (getMenuFontSpacing(spacing_height, font_nr) +
2989 EXTRA_SPACING(game_status));
2992 static int getMenuTextStep(int spacing_height, int font_nr)
2994 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2997 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2999 int font_error = FONT_TEXT_2;
3000 int font_foot = MENU_INFO_FONT_FOOT;
3001 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3002 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3004 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
3006 FadeOut(REDRAW_FIELD);
3010 DrawInfoScreen_Headline(0, 1, FALSE);
3012 DrawTextSCentered(ystart, font_error, text_error);
3013 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3015 FadeIn(REDRAW_FIELD);
3018 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
3020 static int infoscreen_step[MAX_INFO_ELEMENTS_IN_ARRAY];
3021 static int infoscreen_frame[MAX_INFO_ELEMENTS_IN_ARRAY];
3022 int font_foot = MENU_INFO_FONT_FOOT;
3023 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
3024 int ystart = mSY + MENU_SCREEN_INFO_YSTART;
3025 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3026 int ystep = MENU_SCREEN_INFO_YSTEP;
3027 int element, action, direction;
3035 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
3036 infoscreen_step[i] = infoscreen_frame[i] = 0;
3038 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3044 while (helpanim_info[j].element != HELPANIM_LIST_END)
3046 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
3051 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3060 j += infoscreen_step[i - start];
3062 element = helpanim_info[j].element;
3063 action = helpanim_info[j].action;
3064 direction = helpanim_info[j].direction;
3067 element = EL_UNKNOWN;
3069 if (action != -1 && direction != -1)
3070 graphic = el_act_dir2img(element, action, direction);
3071 else if (action != -1)
3072 graphic = el_act2img(element, action);
3073 else if (direction != -1)
3074 graphic = el_dir2img(element, direction);
3076 graphic = el2img(element);
3078 delay = helpanim_info[j++].delay;
3083 if (infoscreen_frame[i - start] == 0)
3086 infoscreen_frame[i - start] = delay - 1;
3090 sync_frame = delay - infoscreen_frame[i - start];
3091 infoscreen_frame[i - start]--;
3094 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3096 if (!infoscreen_frame[i - start])
3097 infoscreen_step[i - start] = 0;
3101 if (!infoscreen_frame[i - start])
3102 infoscreen_step[i - start]++;
3103 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3109 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
3111 DrawFixedGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
3112 graphic, sync_frame, USE_MASKING);
3115 DrawInfoScreen_HelpText(element, action, direction, i - start);
3120 redraw_mask |= REDRAW_FIELD;
3125 static char *getHelpText(int element, int action, int direction)
3127 char token[MAX_LINE_LEN];
3129 strcpy(token, element_info[element].token_name);
3132 strcat(token, element_action_info[action].suffix);
3134 if (direction != -1)
3135 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3137 return getHashEntry(helptext_info, token);
3140 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3142 int font_nr = FONT_INFO_ELEMENTS;
3143 int font_width = getFontWidth(font_nr);
3144 int font_height = getFontHeight(font_nr);
3145 int yoffset = (TILEX - 2 * font_height) / 2;
3146 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3147 int ystart = mSY + MENU_SCREEN_INFO_YSTART + yoffset;
3148 int ystep = TILEY + 4;
3149 int pad_left = xstart - SX;
3150 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3151 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3152 int max_lines_per_text = 2;
3155 if (action != -1 && direction != -1) // element.action.direction
3156 text = getHelpText(element, action, direction);
3158 if (text == NULL && action != -1) // element.action
3159 text = getHelpText(element, action, -1);
3161 if (text == NULL && direction != -1) // element.direction
3162 text = getHelpText(element, -1, direction);
3164 if (text == NULL) // base element
3165 text = getHelpText(element, -1, -1);
3167 if (text == NULL) // not found
3168 text = "No description available";
3170 if (strlen(text) <= max_chars_per_line) // only one line of text
3171 ystart += getFontHeight(font_nr) / 2;
3173 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3174 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3175 TRUE, FALSE, FALSE);
3178 static void DrawInfoScreen_TitleScreen(void)
3180 SetGameStatus(GAME_MODE_TITLE);
3185 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3187 HandleTitleScreen(0, 0, dx, dy, button);
3190 static void DrawInfoScreen_Elements(void)
3192 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3194 FadeOut(REDRAW_FIELD);
3199 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3201 FadeIn(REDRAW_FIELD);
3204 void HandleInfoScreen_Elements(int dx, int dy, int button)
3206 static DelayCounter info_delay = { 0 };
3207 static int num_anims;
3208 static int num_pages;
3210 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3213 info_delay.value = GameFrameDelay;
3215 if (button == MB_MENU_INITIALIZE)
3217 boolean new_element = TRUE;
3221 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3223 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3225 else if (new_element)
3228 new_element = FALSE;
3232 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3236 if (button == MB_MENU_LEAVE)
3238 PlaySound(SND_MENU_ITEM_SELECTING);
3240 info_mode = INFO_MODE_MAIN;
3245 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3247 if (button != MB_MENU_INITIALIZE)
3249 PlaySound(SND_MENU_ITEM_SELECTING);
3251 page += (dx < 0 ? -1 : +1);
3254 if (page < 0 || page >= num_pages)
3256 FadeMenuSoundsAndMusic();
3258 info_mode = INFO_MODE_MAIN;
3264 if (button != MB_MENU_INITIALIZE)
3265 FadeSetNextScreen();
3267 if (button != MB_MENU_INITIALIZE)
3268 FadeOut(REDRAW_FIELD);
3272 DrawInfoScreen_Headline(page, num_pages, TRUE);
3273 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3275 if (button != MB_MENU_INITIALIZE)
3276 FadeIn(REDRAW_FIELD);
3280 if (DelayReached(&info_delay))
3281 if (page < num_pages)
3282 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3284 PlayMenuSoundIfLoop();
3288 static void DrawInfoScreen_Music(void)
3290 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3292 FadeOut(REDRAW_FIELD);
3296 DrawInfoScreen_Headline(0, 1, TRUE);
3300 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3302 FadeIn(REDRAW_FIELD);
3305 void HandleInfoScreen_Music(int dx, int dy, int button)
3307 static struct MusicFileInfo *list = NULL;
3308 static int num_screens = 0;
3309 static int screen_nr = 0;
3310 int font_title = MENU_INFO_FONT_TITLE;
3311 int font_head = MENU_INFO_FONT_HEAD;
3312 int font_text = MENU_INFO_FONT_TEXT;
3313 int font_foot = MENU_INFO_FONT_FOOT;
3314 int spacing_head = menu.headline2_spacing_info[info_mode];
3315 int ystep_head = getMenuTextStep(spacing_head, font_head);
3316 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3317 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3319 if (button == MB_MENU_INITIALIZE)
3321 struct MusicFileInfo *list_ptr = music_file_info;
3326 while (list_ptr != NULL)
3328 list_ptr = list_ptr->next;
3332 list = music_file_info;
3336 FadeMenuSoundsAndMusic();
3340 DrawInfoScreen_Headline(0, 1, TRUE);
3342 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3343 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3349 if (button == MB_MENU_LEAVE)
3351 PlaySound(SND_MENU_ITEM_SELECTING);
3353 FadeMenuSoundsAndMusic();
3355 info_mode = INFO_MODE_MAIN;
3360 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3362 if (button != MB_MENU_INITIALIZE)
3364 PlaySound(SND_MENU_ITEM_SELECTING);
3368 list = (dx < 0 ? list->prev : list->next);
3369 screen_nr += (dx < 0 ? -1 : +1);
3375 FadeMenuSoundsAndMusic();
3377 info_mode = INFO_MODE_MAIN;
3383 FadeMenuSoundsAndMusic();
3385 if (list != music_file_info)
3386 FadeSetNextScreen();
3388 if (button != MB_MENU_INITIALIZE)
3389 FadeOut(REDRAW_FIELD);
3393 DrawInfoScreen_Headline(screen_nr, num_screens, TRUE);
3397 int sound = list->music;
3399 if (IS_LOOP_SOUND(sound))
3400 PlaySoundLoop(sound);
3406 int music = list->music;
3408 if (IS_LOOP_MUSIC(music))
3409 PlayMusicLoop(music);
3414 if (!strEqual(list->title, UNKNOWN_NAME))
3416 if (!strEqual(list->title_header, UNKNOWN_NAME))
3417 DrawTextSCentered(ystart, font_head, list->title_header);
3419 DrawTextSCentered(ystart, font_head, "Track");
3421 ystart += ystep_head;
3423 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3424 ystart += ystep_head;
3427 if (!strEqual(list->artist, UNKNOWN_NAME))
3429 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3430 DrawTextSCentered(ystart, font_head, list->artist_header);
3432 DrawTextSCentered(ystart, font_head, "by");
3434 ystart += ystep_head;
3436 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3437 ystart += ystep_head;
3440 if (!strEqual(list->album, UNKNOWN_NAME))
3442 if (!strEqual(list->album_header, UNKNOWN_NAME))
3443 DrawTextSCentered(ystart, font_head, list->album_header);
3445 DrawTextSCentered(ystart, font_head, "from the album");
3447 ystart += ystep_head;
3449 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3450 ystart += ystep_head;
3453 if (!strEqual(list->year, UNKNOWN_NAME))
3455 if (!strEqual(list->year_header, UNKNOWN_NAME))
3456 DrawTextSCentered(ystart, font_head, list->year_header);
3458 DrawTextSCentered(ystart, font_head, "from the year");
3460 ystart += ystep_head;
3462 DrawTextFCentered(ystart, font_text, "%s", list->year);
3463 ystart += ystep_head;
3466 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3468 if (button != MB_MENU_INITIALIZE)
3469 FadeIn(REDRAW_FIELD);
3472 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3473 PlaySoundLoop(list->music);
3476 static void DrawInfoScreen_Version(void)
3478 int font_head = MENU_INFO_FONT_HEAD;
3479 int font_text = MENU_INFO_FONT_TEXT;
3480 int font_foot = MENU_INFO_FONT_FOOT;
3481 int spacing_head = menu.headline2_spacing_info[info_mode];
3482 int spacing_para = menu.paragraph_spacing_info[info_mode];
3483 int spacing_line = menu.line_spacing_info[info_mode];
3484 int xstep = getFontWidth(font_text);
3485 int ystep_head = getMenuTextStep(spacing_head, font_head);
3486 int ystep_para = getMenuTextStep(spacing_para, font_text);
3487 int ystep_line = getMenuTextStep(spacing_line, font_text);
3488 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3489 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3490 int xstart1 = mSX - SX + 2 * xstep;
3491 int xstart2 = mSX - SX + 18 * xstep;
3492 int xstart3 = mSX - SX + 28 * xstep;
3493 SDL_version sdl_version_compiled;
3494 const SDL_version *sdl_version_linked;
3495 int driver_name_len = 10;
3496 SDL_version sdl_version_linked_ext;
3497 const char *driver_name = NULL;
3499 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3501 FadeOut(REDRAW_FIELD);
3505 DrawInfoScreen_Headline(0, 1, TRUE);
3507 DrawTextF(xstart1, ystart, font_head, "Name");
3508 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3509 ystart += ystep_line;
3511 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3513 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3514 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3515 ystart += ystep_line;
3517 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3518 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3519 ystart += ystep_line;
3523 DrawTextF(xstart1, ystart, font_head, "Version");
3524 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3525 ystart += ystep_line;
3528 DrawTextF(xstart1, ystart, font_head, "Platform");
3529 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3531 PLATFORM_XX_BIT_STRING);
3532 ystart += ystep_line;
3534 DrawTextF(xstart1, ystart, font_head, "Target");
3535 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3536 ystart += ystep_line;
3538 DrawTextF(xstart1, ystart, font_head, "Source date");
3539 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3540 ystart += ystep_line;
3542 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3543 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3544 ystart += ystep_para;
3546 DrawTextF(xstart1, ystart, font_head, "Library");
3547 DrawTextF(xstart2, ystart, font_head, "compiled");
3548 DrawTextF(xstart3, ystart, font_head, "linked");
3549 ystart += ystep_head;
3551 SDL_VERSION(&sdl_version_compiled);
3552 SDL_GetVersion(&sdl_version_linked_ext);
3553 sdl_version_linked = &sdl_version_linked_ext;
3555 DrawTextF(xstart1, ystart, font_text, "SDL");
3556 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3557 sdl_version_compiled.major,
3558 sdl_version_compiled.minor,
3559 sdl_version_compiled.patch);
3560 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3561 sdl_version_linked->major,
3562 sdl_version_linked->minor,
3563 sdl_version_linked->patch);
3564 ystart += ystep_line;
3566 SDL_IMAGE_VERSION(&sdl_version_compiled);
3567 sdl_version_linked = IMG_Linked_Version();
3569 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3570 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3571 sdl_version_compiled.major,
3572 sdl_version_compiled.minor,
3573 sdl_version_compiled.patch);
3574 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3575 sdl_version_linked->major,
3576 sdl_version_linked->minor,
3577 sdl_version_linked->patch);
3578 ystart += ystep_line;
3580 SDL_MIXER_VERSION(&sdl_version_compiled);
3581 sdl_version_linked = Mix_Linked_Version();
3583 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3584 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3585 sdl_version_compiled.major,
3586 sdl_version_compiled.minor,
3587 sdl_version_compiled.patch);
3588 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3589 sdl_version_linked->major,
3590 sdl_version_linked->minor,
3591 sdl_version_linked->patch);
3592 ystart += ystep_line;
3594 SDL_NET_VERSION(&sdl_version_compiled);
3595 sdl_version_linked = SDLNet_Linked_Version();
3597 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3598 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3599 sdl_version_compiled.major,
3600 sdl_version_compiled.minor,
3601 sdl_version_compiled.patch);
3602 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3603 sdl_version_linked->major,
3604 sdl_version_linked->minor,
3605 sdl_version_linked->patch);
3606 ystart += ystep_para;
3608 DrawTextF(xstart1, ystart, font_head, "Driver");
3609 DrawTextF(xstart2, ystart, font_head, "Requested");
3610 DrawTextF(xstart3, ystart, font_head, "Used");
3611 ystart += ystep_head;
3614 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3616 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3617 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3618 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3619 ystart += ystep_line;
3622 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3624 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3625 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3626 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3627 ystart += ystep_line;
3630 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3632 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3633 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3634 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3636 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3638 FadeIn(REDRAW_FIELD);
3641 void HandleInfoScreen_Version(int button)
3643 if (button == MB_MENU_LEAVE)
3645 PlaySound(SND_MENU_ITEM_SELECTING);
3647 info_mode = INFO_MODE_MAIN;
3652 else if (button == MB_MENU_CHOICE)
3654 PlaySound(SND_MENU_ITEM_SELECTING);
3656 FadeMenuSoundsAndMusic();
3658 info_mode = INFO_MODE_MAIN;
3663 PlayMenuSoundIfLoop();
3667 static char *getInfoScreenTitle_Generic(void)
3669 return (info_mode == INFO_MODE_MAIN ? STR_INFO_MAIN :
3670 info_mode == INFO_MODE_TITLE ? STR_INFO_TITLE :
3671 info_mode == INFO_MODE_ELEMENTS ? STR_INFO_ELEMENTS :
3672 info_mode == INFO_MODE_MUSIC ? STR_INFO_MUSIC :
3673 info_mode == INFO_MODE_CREDITS ? STR_INFO_CREDITS :
3674 info_mode == INFO_MODE_PROGRAM ? STR_INFO_PROGRAM :
3675 info_mode == INFO_MODE_VERSION ? STR_INFO_VERSION :
3676 info_mode == INFO_MODE_LEVELSET ? STR_INFO_LEVELSET :
3680 static int getInfoScreenBackground_Generic(void)
3682 return (info_mode == INFO_MODE_CREDITS ? IMG_BACKGROUND_INFO_CREDITS :
3683 info_mode == INFO_MODE_PROGRAM ? IMG_BACKGROUND_INFO_PROGRAM :
3684 info_mode == INFO_MODE_LEVELSET ? IMG_BACKGROUND_INFO_LEVELSET :
3685 IMG_BACKGROUND_INFO);
3688 static char *getInfoScreenFilename_Generic(int nr, boolean global)
3690 return (info_mode == INFO_MODE_CREDITS ? getCreditsFilename(nr, global) :
3691 info_mode == INFO_MODE_PROGRAM ? getProgramInfoFilename(nr) :
3692 info_mode == INFO_MODE_LEVELSET ? getLevelSetInfoFilename(nr) :
3696 static void DrawInfoScreen_GenericScreen(int screen_nr, int num_screens,
3697 int use_global_screens)
3699 char *filename = getInfoScreenFilename_Generic(screen_nr, use_global_screens);
3700 int font_text = MENU_INFO_FONT_TEXT;
3701 int font_foot = MENU_INFO_FONT_FOOT;
3702 int spacing_line = menu.line_spacing_info[info_mode];
3703 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3707 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
3709 if (info_mode == INFO_MODE_CREDITS ||
3710 info_mode == INFO_MODE_PROGRAM)
3713 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART;
3714 int chars = width / getFontWidth(font_text);
3715 int lines = height / getFontHeight(font_text);
3716 int padx = (width - chars * getFontWidth(font_text)) / 2;
3717 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3718 boolean autowrap = FALSE;
3719 boolean centered = TRUE;
3720 boolean parse_comments = TRUE;
3722 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART,
3723 filename, font_text, chars, -1, lines, line_spacing, -1,
3724 autowrap, centered, parse_comments);
3726 else if (info_mode == INFO_MODE_LEVELSET)
3728 struct TitleMessageInfo *tmi = &readme;
3730 // if x position set to "-1", automatically determine by playfield width
3732 tmi->x = SXSIZE / 2;
3734 // if y position set to "-1", use static default value
3736 tmi->y = MENU_SCREEN_INFO_YSTART;
3738 // if width set to "-1", automatically determine by playfield width
3739 if (tmi->width == -1)
3740 tmi->width = SXSIZE - 2 * TILEX;
3742 // if height set to "-1", automatically determine by playfield height
3743 if (tmi->height == -1)
3744 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3746 // if chars set to "-1", automatically determine by text and font width
3747 if (tmi->chars == -1)
3748 tmi->chars = tmi->width / getFontWidth(tmi->font);
3750 tmi->width = tmi->chars * getFontWidth(tmi->font);
3752 // if lines set to "-1", automatically determine by text and font height
3753 if (tmi->lines == -1)
3754 tmi->lines = tmi->height / getFontHeight(tmi->font);
3756 tmi->height = tmi->lines * getFontHeight(tmi->font);
3758 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3759 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3760 tmi->autowrap, tmi->centered, tmi->parse_comments);
3763 boolean last_screen = (screen_nr == num_screens - 1);
3764 char *text_foot = (last_screen ? TEXT_NEXT_MENU : TEXT_NEXT_PAGE);
3766 DrawTextSCentered(ybottom, font_foot, text_foot);
3769 static void DrawInfoScreen_Generic(void)
3771 SetMainBackgroundImageIfDefined(getInfoScreenBackground_Generic());
3773 FadeMenuSoundsAndMusic();
3775 FadeOut(REDRAW_FIELD);
3777 HandleInfoScreen_Generic(0, 0, MB_MENU_INITIALIZE);
3779 FadeIn(REDRAW_FIELD);
3782 void HandleInfoScreen_Generic(int dx, int dy, int button)
3784 static char *text_no_info = "";
3785 static int num_screens = 0;
3786 static int screen_nr = 0;
3787 static boolean use_global_screens = FALSE;
3789 if (button == MB_MENU_INITIALIZE)
3794 if (info_mode == INFO_MODE_CREDITS)
3798 for (i = 0; i < 2; i++)
3800 use_global_screens = i; // check for "FALSE", then "TRUE"
3802 // determine number of (global or level set specific) credits screens
3803 while (getCreditsFilename(num_screens, use_global_screens) != NULL)
3806 if (num_screens > 0)
3810 text_no_info = "No credits available.";
3812 else if (info_mode == INFO_MODE_PROGRAM)
3814 use_global_screens = TRUE;
3816 // determine number of program info screens
3817 while (getProgramInfoFilename(num_screens) != NULL)
3820 text_no_info = "No program info available.";
3822 else if (info_mode == INFO_MODE_LEVELSET)
3824 use_global_screens = FALSE;
3826 // determine number of levelset info screens
3827 while (getLevelSetInfoFilename(num_screens) != NULL)
3830 text_no_info = "No level set info available.";
3833 if (num_screens == 0)
3835 int font_title = MENU_INFO_FONT_TITLE;
3836 int font_foot = MENU_INFO_FONT_FOOT;
3837 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3838 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3842 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
3844 DrawTextSCentered(ystart, font_title, text_no_info);
3845 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3850 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
3852 else if (button == MB_MENU_LEAVE)
3854 PlaySound(SND_MENU_ITEM_SELECTING);
3856 info_mode = INFO_MODE_MAIN;
3859 else if (button == MB_MENU_CHOICE || dx)
3861 PlaySound(SND_MENU_ITEM_SELECTING);
3863 screen_nr += (dx < 0 ? -1 : +1);
3865 if (screen_nr < 0 || screen_nr >= num_screens)
3867 FadeMenuSoundsAndMusic();
3869 info_mode = INFO_MODE_MAIN;
3874 FadeSetNextScreen();
3876 FadeOut(REDRAW_FIELD);
3878 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
3880 FadeIn(REDRAW_FIELD);
3885 PlayMenuSoundIfLoop();
3889 static void DrawInfoScreen(void)
3891 if (info_mode == INFO_MODE_TITLE)
3892 DrawInfoScreen_TitleScreen();
3893 else if (info_mode == INFO_MODE_ELEMENTS)
3894 DrawInfoScreen_Elements();
3895 else if (info_mode == INFO_MODE_MUSIC)
3896 DrawInfoScreen_Music();
3897 else if (info_mode == INFO_MODE_CREDITS)
3898 DrawInfoScreen_Generic();
3899 else if (info_mode == INFO_MODE_PROGRAM)
3900 DrawInfoScreen_Generic();
3901 else if (info_mode == INFO_MODE_VERSION)
3902 DrawInfoScreen_Version();
3903 else if (info_mode == INFO_MODE_LEVELSET)
3904 DrawInfoScreen_Generic();
3906 DrawInfoScreen_Main();
3908 if (info_mode != INFO_MODE_MAIN &&
3909 info_mode != INFO_MODE_TITLE &&
3910 info_mode != INFO_MODE_MUSIC)
3911 PlayMenuSoundsAndMusic();
3914 void DrawInfoScreen_FromMainMenu(int nr)
3916 int fade_mask = REDRAW_FIELD;
3918 if (nr < INFO_MODE_MAIN || nr >= MAX_INFO_MODES)
3921 CloseDoor(DOOR_CLOSE_2);
3923 SetGameStatus(GAME_MODE_INFO);
3926 info_screens_from_main = TRUE;
3928 if (redraw_mask & REDRAW_ALL)
3929 fade_mask = REDRAW_ALL;
3932 fade_mask = REDRAW_ALL;
3935 FadeMenuSoundsAndMusic();
3937 FadeSetEnterScreen();
3941 FadeSkipNextFadeOut();
3943 // needed if different viewport properties defined for info screen
3944 ChangeViewportPropertiesIfNeeded();
3946 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3951 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3953 if (info_mode == INFO_MODE_TITLE)
3954 HandleInfoScreen_TitleScreen(dx, dy, button);
3955 else if (info_mode == INFO_MODE_ELEMENTS)
3956 HandleInfoScreen_Elements(dx, dy, button);
3957 else if (info_mode == INFO_MODE_MUSIC)
3958 HandleInfoScreen_Music(dx, dy, button);
3959 else if (info_mode == INFO_MODE_CREDITS)
3960 HandleInfoScreen_Generic(dx, dy, button);
3961 else if (info_mode == INFO_MODE_PROGRAM)
3962 HandleInfoScreen_Generic(dx, dy, button);
3963 else if (info_mode == INFO_MODE_VERSION)
3964 HandleInfoScreen_Version(button);
3965 else if (info_mode == INFO_MODE_LEVELSET)
3966 HandleInfoScreen_Generic(dx, dy, button);
3968 HandleInfoScreen_Main(mx, my, dx, dy, button);
3972 // ============================================================================
3973 // type name functions
3974 // ============================================================================
3976 static TreeInfo *type_name_node = NULL;
3977 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
3978 static int type_name_nr = 0;
3980 static int getPlayerNameColor(char *name)
3982 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
3985 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
3988 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
3989 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
3990 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
3991 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
3992 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
3993 int font_width = getFontWidth(font_nr);
3994 int font_xoffset = getFontDrawOffsetX(font_nr);
3995 int font_yoffset = getFontDrawOffsetY(font_nr);
3996 int font_sx = sx + font_xoffset;
3997 int font_sy = sy + font_yoffset;
3999 DrawBackgroundForFont(font_sx, font_sy, pos->width, pos->height, font_nr);
4001 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4003 pos->width = strlen(text) * font_width;
4004 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4006 DrawText(sx, sy, text, font_nr);
4009 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4011 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4013 *pos = *mci->pos_input;
4015 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4017 TreeInfo *ti = player_name_current;
4018 int first_entry = ti->cl_first;
4019 int entry_pos = first_entry + ti->cl_cursor;
4020 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4021 int xpos = MENU_SCREEN_START_XPOS;
4022 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4024 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4025 type_name_nr = entry_pos;
4027 strcpy(name, type_name_node->name);
4031 pos->width = MAX_PLAYER_NAME_LEN * 32;
4035 type_name_nr = user.nr;
4037 strcpy(name, setup.player_name);
4040 strcpy(type_name_last, name);
4042 if (strEqual(name, EMPTY_PLAYER_NAME))
4045 *xpos = strlen(name);
4048 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4050 // change name of edited user in global list of user names
4051 setString(&global.user_names[type_name_nr], name);
4053 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4055 TreeInfo *node = type_name_node;
4057 // change name of edited user in local menu tree structure
4058 setString(&node->name, name);
4059 setString(&node->name_sorting, name);
4061 node->color = getPlayerNameColor(name);
4062 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4066 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4069 boolean reset_setup = strEqual(name, "");
4070 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4071 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4074 strcpy(name, type_name_last);
4076 if (strEqual(name, ""))
4077 strcpy(name, EMPTY_PLAYER_NAME);
4079 setTypeNameValues_Name(name, pos);
4081 // if player name not changed, no further action required
4082 if (strEqual(name, type_name_last))
4085 // redraw player name before (possibly) opening request dialogs
4086 drawTypeNameText(name, pos, FALSE);
4088 int last_user_nr = user.nr;
4090 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4092 // save setup of currently active user (may differ from edited user)
4095 // temporarily change active user to edited user
4096 user.nr = type_name_nr;
4099 Request("Use current setup values for the new player?", REQ_ASK))
4101 // use current setup values for new user, but create new player UUID
4102 setup.player_uuid = getStringCopy(getUUID());
4106 // load setup for existing user (or start with defaults for new user)
4111 char *setup_filename = getSetupFilename();
4112 boolean setup_exists = fileExists(setup_filename);
4114 // change name of edited user in setup structure
4115 strcpy(setup.player_name, name);
4117 // save setup of edited user
4120 // change name of edited user on score server
4121 ApiRenamePlayerAsThread();
4123 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4127 if (Request("Reset setup values for this player?", REQ_ASK))
4129 // remove setup config file
4130 unlink(setup_filename);
4132 // set player name to default player name
4135 // update player name used by name typing functions
4136 strcpy(name, setup.player_name);
4138 setTypeNameValues_Name(name, pos);
4141 else if (remove_user && type_name_nr != 0)
4143 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4145 char *user_dir = getUserGameDataDir();
4146 char *user_dir_removed =
4147 getStringCat3WithSeparator(user_dir, "REMOVED",
4148 getCurrentTimestamp(), ".");
4150 if (rename(user_dir, user_dir_removed) != 0)
4151 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4153 checked_free(user_dir_removed);
4156 else if (create_user && type_name_nr != 0 && !setup_exists)
4158 if (Request("Create empty level set for the new player?", REQ_ASK))
4160 char *levelset_subdir = getNewUserLevelSubdir();
4162 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4164 AddUserLevelSetToLevelInfo(levelset_subdir);
4166 LevelDirTree *leveldir_current_last = leveldir_current;
4168 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4171 // set level number of newly created level set to default value
4172 LoadLevelSetup_SeriesInfo();
4174 // set newly created level set as current level set for new user
4175 SaveLevelSetup_LastSeries();
4176 SaveLevelSetup_SeriesInfo();
4178 leveldir_current = leveldir_current_last;
4182 Request("Creating new level set failed!", REQ_CONFIRM);
4187 // restore currently active user
4188 user.nr = last_user_nr;
4190 // restore setup of currently active user
4193 // restore last level set of currently active user
4194 LoadLevelSetup_LastSeries();
4195 LoadLevelSetup_SeriesInfo();
4199 static void HandleTypeNameExt(boolean initialize, Key key)
4201 static struct TextPosInfo pos_name = { 0 };
4202 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4203 static int xpos = 0;
4204 struct TextPosInfo *pos = &pos_name;
4205 char key_char = getValidConfigValueChar(getCharFromKey(key));
4206 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4207 boolean active = TRUE;
4211 getTypeNameValues(name, pos, &xpos);
4213 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4214 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4216 StartTextInput(sx, sy, pos->width, pos->height);
4218 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4220 name[xpos] = key_char;
4225 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4231 else if (key == KSYM_Return || key == KSYM_Escape)
4233 boolean changed = (key == KSYM_Return);
4237 setTypeNameValues(name, pos, changed);
4242 drawTypeNameText(name, pos, active);
4246 SetGameStatus(game_status_last_screen);
4248 if (game_status == GAME_MODE_MAIN)
4249 InitializeMainControls();
4253 static void DrawTypeName(void)
4255 HandleTypeNameExt(TRUE, 0);
4258 void HandleTypeName(Key key)
4260 HandleTypeNameExt(FALSE, key);
4264 // ============================================================================
4265 // tree menu functions
4266 // ============================================================================
4268 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4270 if (game_status != GAME_MODE_SETUP ||
4271 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4274 int max_text_size = 0;
4277 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4278 max_text_size = MAX(max_text_size, strlen(node->name));
4280 int num_entries = numTreeInfoInGroup(ti);
4281 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4282 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4283 int text_width = max_text_size * getFontWidth(font_nr);
4284 int button_width = SC_MENUBUTTON_XSIZE;
4285 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4286 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4287 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4288 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4289 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4290 int align_xoffset = MAX(0, align_xoffset_raw);
4292 return align_xoffset;
4295 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4297 if (game_status != GAME_MODE_SETUP ||
4298 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4301 int num_entries = numTreeInfoInGroup(ti);
4302 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4303 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4304 int font_height = getFontHeight(font_nr);
4305 int text_height = font_height * num_page_entries;
4306 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4307 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4308 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4309 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4310 int align_yoffset = MAX(0, align_yoffset_raw);
4312 return align_yoffset;
4315 static void StartPlayingFromHallOfFame(void)
4317 level_nr = scores.next_level_nr;
4318 LoadLevel(level_nr);
4320 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4323 static void DrawChooseTree(TreeInfo **ti_ptr)
4325 int fade_mask = REDRAW_FIELD;
4326 boolean restart_music = (game_status != game_status_last_screen &&
4327 game_status_last_screen != GAME_MODE_SCOREINFO);
4329 scores.continue_on_return = (game_status == GAME_MODE_SCORES &&
4330 game_status_last_screen == GAME_MODE_PLAYING);
4333 fade_mask = REDRAW_ALL;
4335 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4337 if (game_status == GAME_MODE_SETUP)
4341 else if (game_status == GAME_MODE_SCORES && scores.continue_playing)
4343 StartPlayingFromHallOfFame();
4347 SetGameStatus(GAME_MODE_MAIN);
4357 FreeScreenGadgets();
4358 CreateScreenGadgets();
4361 FadeMenuSoundsAndMusic();
4365 // needed if different viewport properties defined for this screen
4366 ChangeViewportPropertiesIfNeeded();
4368 if (game_status == GAME_MODE_NAMES)
4369 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4370 else if (game_status == GAME_MODE_LEVELNR)
4371 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4372 else if (game_status == GAME_MODE_LEVELS)
4373 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4374 else if (game_status == GAME_MODE_SCORES)
4375 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4379 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4381 // map gadgets for high score screen
4382 if (game_status == GAME_MODE_SCORES)
4383 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4385 MapScreenTreeGadgets(*ti_ptr);
4387 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4389 DrawMaskedBorder(fade_mask);
4392 PlayMenuSoundsAndMusic();
4397 static int getChooseTreeFont(TreeInfo *node, boolean active)
4399 if (game_status == GAME_MODE_SCORES)
4400 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4402 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4405 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4407 int num_entries = numTreeInfoInGroup(ti);
4408 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4409 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4410 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4411 int first_entry = ti->cl_first;
4412 int entry_pos = first_entry + y;
4413 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4414 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4415 int font_nr = getChooseTreeFont(node, active);
4416 int font_xoffset = getFontDrawOffsetX(font_nr);
4417 int xpos = MENU_SCREEN_START_XPOS;
4418 int ypos = MENU_SCREEN_START_YPOS + y;
4419 int startdx = xpos * 32;
4420 int startdy = ypos * 32;
4421 int startx = amSX + startdx;
4422 int starty = amSY + startdy;
4423 int startx_text = startx + font_xoffset;
4424 int endx_text = amSX + screen_width;
4425 int max_text_size = endx_text - startx_text;
4426 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4427 char buffer[max_buffer_len + 1];
4429 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4431 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4432 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4433 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4434 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4435 int font_size_1 = getFontWidth(font_nr1);
4436 int font_size_3 = getFontWidth(font_nr3);
4437 int font_size_4 = getFontWidth(font_nr4);
4438 int text_size_1 = 4 * font_size_1;
4439 int text_size_4 = 5 * font_size_4;
4440 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4442 int dx3 = text_size_1;
4443 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4444 int num_dots = (dx4 - dx3) / font_size_3;
4445 int startx1 = startx + dx1;
4446 int startx3 = startx + dx3;
4447 int startx4 = startx + dx4;
4448 int pos = node->pos;
4449 char *pos_text = getHallOfFameRankText(pos, 3);
4452 DrawText(startx1, starty, pos_text, font_nr1);
4454 for (i = 0; i < num_dots; i++)
4455 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4457 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4458 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4460 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4464 strncpy(buffer, node->name, max_buffer_len);
4465 buffer[max_buffer_len] = '\0';
4467 DrawText(startx, starty, buffer, font_nr);
4471 static void drawChooseTreeHeadExt(int type, char *title_string)
4473 int yoffset_sets = MENU_TITLE1_YPOS;
4474 int yoffset_setup = 16;
4475 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4476 type == TREE_TYPE_LEVEL_DIR ||
4477 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4479 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4482 static void drawChooseTreeHead(TreeInfo *ti)
4484 drawChooseTreeHeadExt(ti->type, ti->infotext);
4487 static void drawChooseTreeList(TreeInfo *ti)
4489 int first_entry = ti->cl_first;
4490 int num_entries = numTreeInfoInGroup(ti);
4491 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4494 clearMenuListArea();
4496 for (i = 0; i < num_page_entries; i++)
4498 TreeInfo *node, *node_first;
4499 int entry_pos = first_entry + i;
4501 node_first = getTreeInfoFirstGroupEntry(ti);
4502 node = getTreeInfoFromPos(node_first, entry_pos);
4504 drawChooseTreeText(ti, i, FALSE);
4506 if (node->parent_link)
4507 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4508 else if (node->level_group)
4509 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4511 initCursor(i, IMG_MENU_BUTTON);
4513 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4514 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4516 if (game_status == GAME_MODE_NAMES)
4517 drawChooseTreeEdit(i, FALSE);
4520 redraw_mask |= REDRAW_FIELD;
4523 static void drawChooseTreeInfo(TreeInfo *ti)
4525 int entry_pos = ti->cl_first + ti->cl_cursor;
4526 int last_redraw_mask = redraw_mask;
4527 int ypos = MENU_TITLE2_YPOS;
4528 int font_nr = FONT_TITLE_2;
4531 if (ti->type == TREE_TYPE_LEVEL_NR)
4532 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4534 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4535 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4536 scores.last_level_nr);
4538 if (ti->type != TREE_TYPE_LEVEL_DIR)
4541 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4542 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4544 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4546 if (node->parent_link)
4547 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4548 node->node_parent->name);
4549 else if (node->level_group)
4550 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4552 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4553 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4554 node->levels, (node->levels > 1 ? "levels" : "level"),
4557 // let BackToFront() redraw only what is needed
4558 redraw_mask = last_redraw_mask;
4559 for (x = 0; x < SCR_FIELDX; x++)
4560 MarkTileDirty(x, 1);
4563 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4565 drawChooseTreeCursor(ti->cl_cursor, active);
4566 drawChooseTreeText(ti, ti->cl_cursor, active);
4569 static void drawChooseTreeScreen(TreeInfo *ti)
4571 drawChooseTreeHead(ti);
4572 drawChooseTreeList(ti);
4573 drawChooseTreeInfo(ti);
4574 drawChooseTreeCursorAndText(ti, TRUE);
4576 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4578 // scroll bar and buttons may just have been added after reloading scores
4579 if (game_status == GAME_MODE_SCORES)
4580 MapScreenTreeGadgets(ti);
4583 static void drawChooseTreeScreen_Scores_NotAvailable(void)
4585 // dirty workaround to use spacing definitions from info screen
4586 info_mode = INFO_MODE_TITLE;
4588 char *text_info = "HighScores of Level %d";
4589 char *text_title = "Score information:";
4590 char *text_error = "No scores for this level.";
4591 char *text_foot = TEXT_MAIN_MENU;
4592 int font_info = FONT_TITLE_2;
4593 int font_title = FONT_INITIAL_3;
4594 int font_error = FONT_INITIAL_4;
4595 int font_foot = FONT_INITIAL_2;
4596 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
4597 int ystep_title = getMenuTextStep(spacing_title, font_title);
4598 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART;
4599 int ystart2 = ystart1 + ystep_title;
4600 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4601 int ystart0 = MENU_TITLE2_YPOS;
4603 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
4604 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
4606 DrawTextSCentered(ystart1, font_title, text_title);
4607 DrawTextSCentered(ystart2, font_error, text_error);
4609 DrawTextSCentered(ybottom, font_foot, text_foot);
4612 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4614 int score_pos = scores.last_added;
4616 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4617 score_pos = scores.last_entry_nr;
4619 // set current tree entry to last added score entry
4620 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4622 // if that fails, set current tree entry to first entry (back link)
4623 if (*ti_ptr == NULL)
4624 *ti_ptr = score_entries->node_group;
4626 int num_entries = numTreeInfoInGroup(*ti_ptr);
4627 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4628 int pos_score = getPosFromTreeInfo(*ti_ptr);
4629 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4630 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4632 (*ti_ptr)->cl_first = pos_first;
4633 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4638 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4641 TreeInfo *ti = *ti_ptr;
4642 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4643 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4644 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4645 int sx1_edit_name = getChooseTreeEditXPosReal(POS_LEFT);
4646 int sx2_edit_name = getChooseTreeEditXPosReal(POS_RIGHT);
4648 int y = (ti != NULL ? ti->cl_cursor : 0);
4649 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4650 int num_entries = numTreeInfoInGroup(ti);
4651 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4652 boolean position_set_by_scrollbar = (dx == 999);
4653 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
4654 boolean button_is_valid = (mx >= 0 && my >= 0);
4655 boolean button_screen_clicked = (button_action && button_is_valid);
4657 if (game_status == GAME_MODE_SCORES)
4659 if (server_scores.updated)
4661 // reload scores, using updated server score cache file
4662 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4664 server_scores.updated = FALSE;
4666 DrawHallOfFame_setScoreEntries();
4668 if (score_entries != NULL)
4670 ti = setHallOfFameActiveEntry(ti_ptr);
4672 if (button != MB_MENU_INITIALIZE)
4673 drawChooseTreeScreen(ti);
4677 if (score_entries == NULL)
4679 if (button == MB_MENU_INITIALIZE)
4681 drawChooseTreeScreen_Scores_NotAvailable();
4683 else if (button_screen_clicked)
4685 PlaySound(SND_MENU_ITEM_SELECTING);
4687 SetGameStatus(GAME_MODE_MAIN);
4696 if (button == MB_MENU_INITIALIZE)
4698 int num_entries = numTreeInfoInGroup(ti);
4699 int entry_pos = getPosFromTreeInfo(ti);
4701 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4702 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4704 if (game_status == GAME_MODE_SCORES)
4706 ti = setHallOfFameActiveEntry(ti_ptr);
4708 else if (ti->cl_first == -1)
4710 // only on initialization
4711 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4712 ti->cl_cursor = entry_pos - ti->cl_first;
4715 else if (ti->cl_cursor >= num_page_entries ||
4716 (num_entries > num_page_entries &&
4717 num_entries - ti->cl_first < num_page_entries))
4719 // only after change of list size (by custom graphic configuration)
4720 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4721 ti->cl_cursor = entry_pos - ti->cl_first;
4724 if (position_set_by_scrollbar)
4727 drawChooseTreeScreen(ti);
4731 else if (button == MB_MENU_LEAVE)
4733 if (game_status != GAME_MODE_SCORES)
4736 PlaySound(SND_MENU_ITEM_SELECTING);
4738 if (ti->node_parent)
4740 *ti_ptr = ti->node_parent;
4741 DrawChooseTree(ti_ptr);
4743 else if (game_status == GAME_MODE_SETUP)
4745 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4746 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4747 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4748 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4750 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4751 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4752 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4753 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4754 execSetupGraphics();
4755 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4756 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4757 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4759 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4760 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4761 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4762 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4763 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4764 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4765 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4766 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4773 if (game_status == GAME_MODE_LEVELNR)
4775 int new_level_nr = atoi(level_number_current->identifier);
4777 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4780 SetGameStatus(GAME_MODE_MAIN);
4788 #if defined(PLATFORM_ANDROID)
4789 // directly continue when touching the screen after playing
4790 if ((mx || my) && scores.continue_on_return)
4792 // ignore touch events until released
4797 // any mouse click or cursor key stops leaving scores by "Return" key
4798 if ((mx || my || dx || dy) && scores.continue_on_return)
4800 scores.continue_on_return = FALSE;
4801 level_nr = scores.last_level_nr;
4802 LoadLevel(level_nr);
4805 if (mx || my) // mouse input
4807 x = (mx - amSX) / 32;
4808 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4810 if (game_status == GAME_MODE_NAMES)
4811 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4813 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4815 // move cursor instead of scrolling when already at start/end of list
4816 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4818 else if (dy == +1 * SCROLL_LINE &&
4819 ti->cl_first + num_page_entries == num_entries)
4822 // handle scrolling screen one line or page
4823 if (ti->cl_cursor + dy < 0 ||
4824 ti->cl_cursor + dy > num_page_entries - 1)
4826 boolean redraw = FALSE;
4828 if (ABS(dy) == SCROLL_PAGE)
4829 step = num_page_entries - 1;
4831 if (dy < 0 && ti->cl_first > 0)
4833 // scroll page/line up
4835 ti->cl_first -= step;
4836 if (ti->cl_first < 0)
4841 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4843 // scroll page/line down
4845 ti->cl_first += step;
4846 if (ti->cl_first + num_page_entries > num_entries)
4847 ti->cl_first = MAX(0, num_entries - num_page_entries);
4853 drawChooseTreeScreen(ti);
4858 // handle moving cursor one line
4859 y = ti->cl_cursor + dy;
4862 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
4864 HandleHallOfFame_SelectLevel(1, dx);
4870 TreeInfo *node_first, *node_cursor;
4871 int entry_pos = ti->cl_first + y;
4873 node_first = getTreeInfoFirstGroupEntry(ti);
4874 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4876 if (node_cursor->node_group)
4880 PlaySound(SND_MENU_ITEM_SELECTING);
4882 node_cursor->cl_first = ti->cl_first;
4883 node_cursor->cl_cursor = ti->cl_cursor;
4885 *ti_ptr = node_cursor->node_group;
4886 DrawChooseTree(ti_ptr);
4891 else if ((dx == -1 || button == MB_MENU_CONTINUE) && ti->node_parent)
4893 if (game_status != GAME_MODE_SCORES)
4896 PlaySound(SND_MENU_ITEM_SELECTING);
4898 *ti_ptr = ti->node_parent;
4899 DrawChooseTree(ti_ptr);
4904 if (!anyScrollbarGadgetActive() &&
4905 IN_VIS_MENU(x, y) &&
4906 mx < mx_right_border &&
4907 y >= 0 && y < num_page_entries)
4911 if (game_status == GAME_MODE_NAMES)
4913 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4914 drawChooseTreeEdit(y, TRUE);
4917 if (y != ti->cl_cursor)
4919 PlaySound(SND_MENU_ITEM_ACTIVATING);
4921 drawChooseTreeCursorAndText(ti, FALSE);
4925 drawChooseTreeCursorAndText(ti, TRUE);
4927 drawChooseTreeInfo(ti);
4931 if (game_status == GAME_MODE_SETUP)
4933 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4934 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4935 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4936 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4938 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4939 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4940 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4941 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4942 execSetupGraphics();
4943 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4944 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4945 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4947 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4948 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4949 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4950 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4951 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4952 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4953 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4954 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4963 TreeInfo *node_first, *node_cursor;
4964 int entry_pos = ti->cl_first + y;
4966 PlaySound(SND_MENU_ITEM_SELECTING);
4968 node_first = getTreeInfoFirstGroupEntry(ti);
4969 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4971 if (node_cursor->node_group)
4975 node_cursor->cl_first = ti->cl_first;
4976 node_cursor->cl_cursor = ti->cl_cursor;
4978 *ti_ptr = node_cursor->node_group;
4979 DrawChooseTree(ti_ptr);
4981 else if (node_cursor->parent_link)
4983 if (game_status != GAME_MODE_SCORES)
4986 *ti_ptr = node_cursor->node_parent;
4987 DrawChooseTree(ti_ptr);
4991 if (game_status != GAME_MODE_SCORES)
4994 node_cursor->cl_first = ti->cl_first;
4995 node_cursor->cl_cursor = ti->cl_cursor;
4997 *ti_ptr = node_cursor;
4999 if (ti->type == TREE_TYPE_LEVEL_DIR)
5001 LoadLevelSetup_SeriesInfo();
5003 SaveLevelSetup_LastSeries();
5004 SaveLevelSetup_SeriesInfo();
5008 if (game_status == GAME_MODE_SETUP)
5010 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5011 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5012 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5013 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5015 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5016 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5017 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5018 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5019 execSetupGraphics();
5020 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5021 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5022 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5024 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5025 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5026 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5027 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5028 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5029 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5030 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5031 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5038 if (game_status == GAME_MODE_LEVELNR)
5040 int new_level_nr = atoi(level_number_current->identifier);
5042 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5044 else if (game_status == GAME_MODE_LEVELS)
5046 // store level set if chosen from "last played level set" menu
5047 StoreLastPlayedLevels(leveldir_current);
5049 else if (game_status == GAME_MODE_NAMES)
5051 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5053 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5060 // change active user to selected user
5061 user.nr = entry_pos;
5063 // save number of new active user
5066 // load setup of new active user
5069 // load last level set of new active user
5070 LoadLevelSetup_LastSeries();
5071 LoadLevelSetup_SeriesInfo();
5073 // update list of last played level sets
5074 UpdateLastPlayedLevels_TreeInfo();
5078 ToggleFullscreenIfNeeded();
5079 ChangeWindowScalingIfNeeded();
5081 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5082 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5083 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5085 else if (game_status == GAME_MODE_SCORES)
5087 if (scores.continue_playing && scores.continue_on_return)
5089 StartPlayingFromHallOfFame();
5093 else if (!scores.continue_on_return)
5095 SetGameStatus(GAME_MODE_SCOREINFO);
5097 DrawScoreInfo(node_cursor->pos);
5103 SetGameStatus(GAME_MODE_MAIN);
5111 if (game_status == GAME_MODE_SCORES)
5112 PlayMenuSoundIfLoop();
5115 void DrawChoosePlayerName(void)
5119 if (player_name != NULL)
5121 freeTreeInfo(player_name);
5126 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5128 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5129 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5132 ti->node_top = &player_name;
5133 ti->sort_priority = 10000 + value;
5134 ti->color = getPlayerNameColor(global.user_names[i]);
5136 snprintf(identifier, sizeof(identifier), "%d", value);
5137 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5139 setString(&ti->identifier, identifier);
5140 setString(&ti->name, name);
5141 setString(&ti->name_sorting, name);
5143 pushTreeInfo(&player_name, ti);
5146 // sort player entries by player number
5147 sortTreeInfo(&player_name);
5149 // set current player entry to selected player entry
5150 player_name_current =
5151 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5153 // if that fails, set current player name to first available name
5154 if (player_name_current == NULL)
5155 player_name_current = player_name;
5157 // set text size for main name input (also used on name selection screen)
5158 InitializeMainControls();
5160 DrawChooseTree(&player_name_current);
5163 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5165 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5168 void DrawChooseLevelSet(void)
5170 DrawChooseTree(&leveldir_current);
5173 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5175 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5178 void DrawChooseLevelNr(void)
5182 if (level_number != NULL)
5184 freeTreeInfo(level_number);
5186 level_number = NULL;
5189 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5191 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5192 char identifier[32], name[64];
5195 // temporarily load level info to get level name
5196 LoadLevelInfoOnly(i);
5198 ti->node_top = &level_number;
5199 ti->sort_priority = 10000 + value;
5200 ti->color = (level.no_level_file ? FC_BLUE :
5201 LevelStats_getSolved(i) ? FC_GREEN :
5202 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5204 snprintf(identifier, sizeof(identifier), "%d", value);
5205 snprintf(name, sizeof(name), "%03d: %s", value,
5206 (level.no_level_file ? "(no file)" : level.name));
5208 setString(&ti->identifier, identifier);
5209 setString(&ti->name, name);
5210 setString(&ti->name_sorting, name);
5212 pushTreeInfo(&level_number, ti);
5215 // sort level number values to start with lowest level number
5216 sortTreeInfo(&level_number);
5218 // set current level number to current level number
5219 level_number_current =
5220 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5222 // if that also fails, set current level number to first available level
5223 if (level_number_current == NULL)
5224 level_number_current = level_number;
5226 DrawChooseTree(&level_number_current);
5229 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5231 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5234 static void DrawHallOfFame_setScoreEntries(void)
5236 int max_empty_entries = 10; // at least show "top ten" list, if empty
5237 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5238 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5239 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5242 if (score_entries != NULL)
5244 freeTreeInfo(score_entries);
5246 score_entries = NULL;
5249 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5251 // do not add empty score entries if off-screen
5252 if (scores.entry[i].score == 0 &&
5253 scores.entry[i].time == 0 &&
5254 i >= min_score_entries)
5257 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5258 char identifier[32], name[64];
5261 ti->node_top = &score_entries;
5262 ti->sort_priority = 10000 + value;
5263 ti->color = FC_YELLOW;
5266 snprintf(identifier, sizeof(identifier), "%d", value);
5267 snprintf(name, sizeof(name), "%03d.", value + 1);
5269 setString(&ti->identifier, identifier);
5270 setString(&ti->name, name);
5271 setString(&ti->name_sorting, name);
5273 pushTreeInfo(&score_entries, ti);
5276 // sort score entries to start with highest score entry
5277 sortTreeInfo(&score_entries);
5279 // add top tree node to create back link to main menu
5280 score_entries = addTopTreeInfoNode(score_entries);
5282 // set current score entry to last added or highest score entry
5283 score_entry_current =
5284 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5286 // if that fails, set current score entry to first valid score entry
5287 if (score_entry_current == NULL)
5288 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5290 if (score_entries != NULL && scores.continue_playing)
5291 setString(&score_entries->node_group->name, BACKLINK_TEXT_NEXT);
5293 // ("score_entries" and "score_entry_current" may be NULL here)
5296 void DrawHallOfFame(int nr)
5298 scores.last_level_nr = nr;
5300 // (this is needed when called from GameEnd() after winning a game)
5301 KeyboardAutoRepeatOn();
5303 // (this is needed when called from GameEnd() after winning a game)
5304 SetDrawDeactivationMask(REDRAW_NONE);
5305 SetDrawBackgroundMask(REDRAW_FIELD);
5307 LoadLocalAndServerScore(scores.last_level_nr, TRUE);
5309 DrawHallOfFame_setScoreEntries();
5311 if (scores.last_added >= 0)
5312 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5314 FadeSetEnterScreen();
5316 DrawChooseTree(&score_entry_current);
5319 static char *getHallOfFameRankText(int nr, int size)
5321 static char rank_text[10];
5322 boolean forced = (scores.force_last_added && nr == scores.last_added);
5323 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5325 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5330 static char *getHallOfFameTimeText(int nr)
5332 static char score_text[10];
5333 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5334 int mm = (time_seconds / 60) % 60;
5335 int ss = (time_seconds % 60);
5337 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5342 static char *getHallOfFameScoreText(int nr, int size)
5344 if (!level.rate_time_over_score)
5345 return int2str(scores.entry[nr].score, size); // show normal score
5346 else if (level.use_step_counter)
5347 return int2str(scores.entry[nr].time, size); // show number of steps
5349 return getHallOfFameTimeText(nr); // show playing time
5352 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5354 static char tape_date[MAX_ISO_DATE_LEN + 1];
5357 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5358 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5359 return entry->tape_date;
5361 for (i = 0, j = 0; i < 8; i++, j++)
5363 tape_date[j] = entry->tape_basename[i];
5365 if (i == 3 || i == 5)
5366 tape_date[++j] = '-';
5369 tape_date[MAX_ISO_DATE_LEN] = '\0';
5374 static void HandleHallOfFame_SelectLevel(int step, int direction)
5376 int old_level_nr = scores.last_level_nr;
5377 int new_level_nr = old_level_nr + step * direction;
5379 if (new_level_nr < leveldir_current->first_level)
5380 new_level_nr = leveldir_current->first_level;
5381 if (new_level_nr > leveldir_current->last_level)
5382 new_level_nr = leveldir_current->last_level;
5384 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5385 new_level_nr = leveldir_current->handicap_level;
5387 if (new_level_nr != old_level_nr)
5389 PlaySound(SND_MENU_ITEM_SELECTING);
5391 scores.last_level_nr = level_nr = new_level_nr;
5392 scores.last_entry_nr = 0;
5394 LoadLevel(level_nr);
5395 LoadLocalAndServerScore(level_nr, TRUE);
5397 DrawHallOfFame_setScoreEntries();
5399 if (game_status == GAME_MODE_SCORES)
5401 // force remapping optional gadgets (especially scroll bar)
5402 UnmapScreenTreeGadgets();
5404 // redraw complete high score screen, as sub-title has changed
5407 // redraw level selection buttons (which have just been erased)
5408 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5410 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5414 DrawScoreInfo_Content(scores.last_entry_nr);
5417 SaveLevelSetup_SeriesInfo();
5421 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5423 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5426 static void DrawScoreInfo_Content(int entry_nr)
5428 struct ScoreEntry *entry = &scores.entry[entry_nr];
5429 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5430 char *tape_date = getHallOfFameTapeDateText(entry);
5431 int font_title = MENU_INFO_FONT_TITLE;
5432 int font_head = MENU_INFO_FONT_HEAD;
5433 int font_text = MENU_INFO_FONT_TEXT;
5434 int font_foot = MENU_INFO_FONT_FOOT;
5435 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5436 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5437 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5438 int xstep = getFontWidth(font_text);
5439 int ystep_title = getMenuTextStep(spacing_title, font_title);
5440 int ystep_para = getMenuTextStep(spacing_para, font_text);
5441 int ystep_line = getMenuTextStep(spacing_line, font_text);
5442 int xstart = mSX - SX + menu.left_spacing[GAME_MODE_SCOREINFO];
5443 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5444 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5445 int xstart1 = xstart + xstep;
5446 int xstart2 = xstart + xstep * 12;
5447 int select_x = SX + xstart1;
5448 int select_y1, select_y2;
5450 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5451 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5452 int font_width = getFontWidth(font_text);
5453 int font_height = getFontHeight(font_text);
5454 int tape_date_width = getTextWidth(tape_date, font_text);
5455 int pad_left = xstart2;
5456 int pad_right = menu.right_spacing[GAME_MODE_SCOREINFO];
5457 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5458 int max_lines_per_text = 5;
5463 // redraw level selection buttons (which have just been erased)
5464 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5466 if (score_entries == NULL)
5468 drawChooseTreeScreen_Scores_NotAvailable();
5473 drawChooseTreeHead(score_entries);
5474 drawChooseTreeInfo(score_entries);
5476 DrawTextSCentered(ystart, font_title, "Score Information:");
5477 ystart += ystep_title;
5479 DrawTextF(xstart1, ystart, font_head, "Level Set");
5480 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5481 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5482 TRUE, FALSE, FALSE);
5483 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5485 DrawTextF(xstart1, ystart, font_head, "Level");
5486 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5487 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5488 TRUE, FALSE, FALSE);
5489 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5491 select_y1 = SY + ystart;
5492 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5494 DrawTextF(xstart1, ystart, font_head, "Rank");
5495 DrawTextF(xstart2, ystart, font_text, pos_text);
5496 ystart += ystep_line;
5498 DrawTextF(xstart1, ystart, font_head, "Player");
5499 DrawTextF(xstart2, ystart, font_text, entry->name);
5500 ystart += ystep_line;
5502 if (level.use_step_counter)
5504 DrawTextF(xstart1, ystart, font_head, "Steps");
5505 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5506 ystart += ystep_line;
5510 DrawTextF(xstart1, ystart, font_head, "Time");
5511 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5512 ystart += ystep_line;
5515 if (!level.rate_time_over_score || entry->score > 0)
5517 DrawTextF(xstart1, ystart, font_head, "Score");
5518 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5519 ystart += ystep_line;
5522 ystart += ystep_line;
5524 play_x = SX + xstart2 + tape_date_width + font_width;
5525 play_y = SY + ystart + (font_height - play_height) / 2;
5527 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5528 DrawTextF(xstart2, ystart, font_text, tape_date);
5529 ystart += ystep_line;
5531 DrawTextF(xstart1, ystart, font_head, "Platform");
5532 DrawTextF(xstart2, ystart, font_text, entry->platform);
5533 ystart += ystep_line;
5535 DrawTextF(xstart1, ystart, font_head, "Version");
5536 DrawTextF(xstart2, ystart, font_text, entry->version);
5537 ystart += ystep_line;
5539 DrawTextF(xstart1, ystart, font_head, "Country");
5540 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5541 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5542 TRUE, FALSE, FALSE);
5543 ystart += ystep_line;
5545 select_y2 = SY + ystart;
5547 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5549 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5550 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5553 static void DrawScoreInfo(int entry_nr)
5555 scores.last_entry_nr = entry_nr;
5556 score_info_tape_play = FALSE;
5560 FreeScreenGadgets();
5561 CreateScreenGadgets();
5563 FadeOut(REDRAW_FIELD);
5565 // needed if different viewport properties defined after playing score tape
5566 ChangeViewportPropertiesIfNeeded();
5568 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
5569 SetDrawDeactivationMask(REDRAW_NONE);
5570 SetDrawBackgroundMask(REDRAW_FIELD);
5572 // needed if different background image defined after playing score tape
5573 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5574 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5576 // special compatibility handling for "Snake Bite" graphics set
5577 if (strPrefix(leveldir_current->identifier, "snake_bite"))
5578 ClearRectangle(gfx.background_bitmap, gfx.real_sx, gfx.real_sy + 64,
5579 gfx.full_sxsize, gfx.full_sysize - 64);
5581 DrawScoreInfo_Content(entry_nr);
5583 // map gadgets for score info screen
5584 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5586 FadeIn(REDRAW_FIELD);
5589 static void HandleScoreInfo_SelectScore(int step, int direction)
5591 int old_entry_nr = scores.last_entry_nr;
5592 int new_entry_nr = old_entry_nr + step * direction;
5593 int num_nodes = numTreeInfoInGroup(score_entry_current);
5594 int num_entries = num_nodes - 1; // score nodes only, without back link
5596 if (new_entry_nr < 0)
5598 if (new_entry_nr > num_entries - 1)
5599 new_entry_nr = num_entries - 1;
5601 if (new_entry_nr != old_entry_nr)
5603 scores.last_entry_nr = new_entry_nr;
5605 DrawScoreInfo_Content(new_entry_nr);
5609 static void HandleScoreInfo_PlayTape(void)
5611 if (!PlayScoreTape(scores.last_entry_nr))
5613 DrawScoreInfo_Content(scores.last_entry_nr);
5615 FadeIn(REDRAW_FIELD);
5619 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5621 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5622 boolean button_is_valid = (mx >= 0 && my >= 0);
5623 boolean button_screen_clicked = (button_action && button_is_valid);
5625 if (server_scores.updated)
5627 // reload scores, using updated server score cache file
5628 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5630 server_scores.updated = FALSE;
5632 DrawHallOfFame_setScoreEntries();
5634 DrawScoreInfo_Content(scores.last_entry_nr);
5637 if (button_screen_clicked)
5639 PlaySound(SND_MENU_ITEM_SELECTING);
5641 SetGameStatus(GAME_MODE_SCORES);
5643 DrawHallOfFame(scores.last_level_nr);
5647 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5651 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5656 // ============================================================================
5657 // setup screen functions
5658 // ============================================================================
5660 static struct TokenInfo *setup_info;
5661 static int num_setup_info; // number of setup entries shown on screen
5662 static int max_setup_info; // total number of setup entries in list
5664 static char *window_size_text;
5665 static char *scaling_type_text;
5666 static char *rendering_mode_text;
5667 static char *vsync_mode_text;
5668 static char *scroll_delay_text;
5669 static char *snapshot_mode_text;
5670 static char *game_speed_text;
5671 static char *scores_type_text;
5672 static char *network_server_text;
5673 static char *graphics_set_name;
5674 static char *sounds_set_name;
5675 static char *music_set_name;
5676 static char *volume_simple_text;
5677 static char *volume_loops_text;
5678 static char *volume_music_text;
5679 static char *touch_controls_text;
5680 static char *move_distance_text;
5681 static char *drop_distance_text;
5682 static char *transparency_text;
5683 static char *grid_size_text[2][2];
5685 static void execSetupMain(void)
5687 setup_mode = SETUP_MODE_MAIN;
5692 static void execSetupGame_setScoresType(void)
5694 if (scores_types == NULL)
5698 for (i = 0; scores_types_list[i].value != NULL; i++)
5700 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5701 char identifier[32], name[32];
5702 char *value = scores_types_list[i].value;
5703 char *text = scores_types_list[i].text;
5705 ti->node_top = &scores_types;
5706 ti->sort_priority = i;
5708 sprintf(identifier, "%s", value);
5709 sprintf(name, "%s", text);
5711 setString(&ti->identifier, identifier);
5712 setString(&ti->name, name);
5713 setString(&ti->name_sorting, name);
5714 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5716 pushTreeInfo(&scores_types, ti);
5719 // sort scores type values to start with lowest scores type value
5720 sortTreeInfo(&scores_types);
5722 // set current scores type value to configured scores type value
5723 scores_type_current =
5724 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5726 // if that fails, set current scores type to reliable default value
5727 if (scores_type_current == NULL)
5728 scores_type_current =
5729 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5731 // if that also fails, set current scores type to first available value
5732 if (scores_type_current == NULL)
5733 scores_type_current = scores_types;
5736 setup.scores_in_highscore_list = scores_type_current->identifier;
5738 // needed for displaying scores type text instead of identifier
5739 scores_type_text = scores_type_current->name;
5742 static void execSetupGame_setGameSpeeds(boolean update_value)
5744 if (setup.game_speed_extended)
5746 game_speeds_list = game_speeds_list_extended;
5747 game_speeds = game_speeds_extended;
5751 game_speeds_list = game_speeds_list_normal;
5752 game_speeds = game_speeds_normal;
5755 if (game_speeds == NULL)
5759 for (i = 0; game_speeds_list[i].value != -1; i++)
5761 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5762 char identifier[32], name[32];
5763 int value = game_speeds_list[i].value;
5764 char *text = game_speeds_list[i].text;
5766 ti->node_top = &game_speeds;
5767 ti->sort_priority = 10000 - value;
5769 sprintf(identifier, "%d", value);
5770 sprintf(name, "%s", text);
5772 setString(&ti->identifier, identifier);
5773 setString(&ti->name, name);
5774 setString(&ti->name_sorting, name);
5775 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5777 pushTreeInfo(&game_speeds, ti);
5780 // sort game speed values to start with slowest game speed
5781 sortTreeInfo(&game_speeds);
5783 update_value = TRUE;
5788 // set current game speed to configured game speed value
5789 game_speed_current =
5790 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5792 // if that fails, set current game speed to reliable default value
5793 if (game_speed_current == NULL)
5794 game_speed_current =
5795 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5797 // if that also fails, set current game speed to first available speed
5798 if (game_speed_current == NULL)
5799 game_speed_current = game_speeds;
5801 if (setup.game_speed_extended)
5802 game_speeds_extended = game_speeds;
5804 game_speeds_normal = game_speeds;
5807 setup.game_frame_delay = atoi(game_speed_current->identifier);
5809 // needed for displaying game speed text instead of identifier
5810 game_speed_text = game_speed_current->name;
5813 static void execSetupGame_setScrollDelays(void)
5815 if (scroll_delays == NULL)
5819 for (i = 0; scroll_delays_list[i].value != -1; i++)
5821 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5822 char identifier[32], name[32];
5823 int value = scroll_delays_list[i].value;
5824 char *text = scroll_delays_list[i].text;
5826 ti->node_top = &scroll_delays;
5827 ti->sort_priority = value;
5829 sprintf(identifier, "%d", value);
5830 sprintf(name, "%s", text);
5832 setString(&ti->identifier, identifier);
5833 setString(&ti->name, name);
5834 setString(&ti->name_sorting, name);
5835 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5837 pushTreeInfo(&scroll_delays, ti);
5840 // sort scroll delay values to start with lowest scroll delay value
5841 sortTreeInfo(&scroll_delays);
5843 // set current scroll delay value to configured scroll delay value
5844 scroll_delay_current =
5845 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5847 // if that fails, set current scroll delay to reliable default value
5848 if (scroll_delay_current == NULL)
5849 scroll_delay_current =
5850 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5852 // if that also fails, set current scroll delay to first available value
5853 if (scroll_delay_current == NULL)
5854 scroll_delay_current = scroll_delays;
5857 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5859 // needed for displaying scroll delay text instead of identifier
5860 scroll_delay_text = scroll_delay_current->name;
5863 static void execSetupGame_setSnapshotModes(void)
5865 if (snapshot_modes == NULL)
5869 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5871 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5872 char identifier[32], name[32];
5873 char *value = snapshot_modes_list[i].value;
5874 char *text = snapshot_modes_list[i].text;
5876 ti->node_top = &snapshot_modes;
5877 ti->sort_priority = i;
5879 sprintf(identifier, "%s", value);
5880 sprintf(name, "%s", text);
5882 setString(&ti->identifier, identifier);
5883 setString(&ti->name, name);
5884 setString(&ti->name_sorting, name);
5885 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5887 pushTreeInfo(&snapshot_modes, ti);
5890 // sort snapshot mode values to start with lowest snapshot mode value
5891 sortTreeInfo(&snapshot_modes);
5893 // set current snapshot mode value to configured snapshot mode value
5894 snapshot_mode_current =
5895 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5897 // if that fails, set current snapshot mode to reliable default value
5898 if (snapshot_mode_current == NULL)
5899 snapshot_mode_current =
5900 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5902 // if that also fails, set current snapshot mode to first available value
5903 if (snapshot_mode_current == NULL)
5904 snapshot_mode_current = snapshot_modes;
5907 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5909 // needed for displaying snapshot mode text instead of identifier
5910 snapshot_mode_text = snapshot_mode_current->name;
5913 static void execSetupGame_setNetworkServerText(void)
5915 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5917 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5921 strncpy(network_server_hostname, setup.network_server_hostname,
5922 MAX_SETUP_TEXT_INPUT_LEN);
5923 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5926 // needed for displaying network server text instead of identifier
5927 network_server_text = network_server_hostname;
5930 static void execSetupGame(void)
5932 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5934 execSetupGame_setGameSpeeds(FALSE);
5935 execSetupGame_setScoresType();
5936 execSetupGame_setScrollDelays();
5937 execSetupGame_setSnapshotModes();
5939 execSetupGame_setNetworkServerText();
5941 if (!setup.provide_uploading_tapes)
5942 setHideSetupEntry(execOfferUploadTapes);
5944 setup_mode = SETUP_MODE_GAME;
5948 // check if vsync needs to be disabled for this game speed to work
5949 if (check_vsync_mode)
5950 DisableVsyncIfNeeded();
5953 static void execSetupChooseScoresType(void)
5955 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
5960 static void execSetupChooseGameSpeed(void)
5962 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5967 static void execSetupChooseScrollDelay(void)
5969 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5974 static void execSetupChooseSnapshotMode(void)
5976 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5981 static void execSetupEngines(void)
5983 setup_mode = SETUP_MODE_ENGINES;
5988 static void execSetupEditor(void)
5990 setup_mode = SETUP_MODE_EDITOR;
5995 static void execSetupGraphics_setWindowSizes(boolean update_list)
5997 if (window_sizes != NULL && update_list)
5999 freeTreeInfo(window_sizes);
6001 window_sizes = NULL;
6004 if (window_sizes == NULL)
6006 boolean current_window_size_found = FALSE;
6009 for (i = 0; window_sizes_list[i].value != -1; i++)
6011 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6012 char identifier[32], name[32];
6013 int value = window_sizes_list[i].value;
6014 char *text = window_sizes_list[i].text;
6016 ti->node_top = &window_sizes;
6017 ti->sort_priority = value;
6019 sprintf(identifier, "%d", value);
6020 sprintf(name, "%s", text);
6022 setString(&ti->identifier, identifier);
6023 setString(&ti->name, name);
6024 setString(&ti->name_sorting, name);
6025 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6027 pushTreeInfo(&window_sizes, ti);
6029 if (value == setup.window_scaling_percent)
6030 current_window_size_found = TRUE;
6033 if (!current_window_size_found)
6035 // add entry for non-preset window scaling value
6037 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6038 char identifier[32], name[32];
6039 int value = setup.window_scaling_percent;
6041 ti->node_top = &window_sizes;
6042 ti->sort_priority = value;
6044 sprintf(identifier, "%d", value);
6045 sprintf(name, "%d %% (Current)", value);
6047 setString(&ti->identifier, identifier);
6048 setString(&ti->name, name);
6049 setString(&ti->name_sorting, name);
6050 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6052 pushTreeInfo(&window_sizes, ti);
6055 // sort window size values to start with lowest window size value
6056 sortTreeInfo(&window_sizes);
6058 // set current window size value to configured window size value
6059 window_size_current =
6060 getTreeInfoFromIdentifier(window_sizes,
6061 i_to_a(setup.window_scaling_percent));
6063 // if that fails, set current window size to reliable default value
6064 if (window_size_current == NULL)
6065 window_size_current =
6066 getTreeInfoFromIdentifier(window_sizes,
6067 i_to_a(STD_WINDOW_SCALING_PERCENT));
6069 // if that also fails, set current window size to first available value
6070 if (window_size_current == NULL)
6071 window_size_current = window_sizes;
6074 setup.window_scaling_percent = atoi(window_size_current->identifier);
6076 // needed for displaying window size text instead of identifier
6077 window_size_text = window_size_current->name;
6080 static void execSetupGraphics_setScalingTypes(void)
6082 if (scaling_types == NULL)
6086 for (i = 0; scaling_types_list[i].value != NULL; i++)
6088 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6089 char identifier[32], name[32];
6090 char *value = scaling_types_list[i].value;
6091 char *text = scaling_types_list[i].text;
6093 ti->node_top = &scaling_types;
6094 ti->sort_priority = i;
6096 sprintf(identifier, "%s", value);
6097 sprintf(name, "%s", text);
6099 setString(&ti->identifier, identifier);
6100 setString(&ti->name, name);
6101 setString(&ti->name_sorting, name);
6102 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6104 pushTreeInfo(&scaling_types, ti);
6107 // sort scaling type values to start with lowest scaling type value
6108 sortTreeInfo(&scaling_types);
6110 // set current scaling type value to configured scaling type value
6111 scaling_type_current =
6112 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6114 // if that fails, set current scaling type to reliable default value
6115 if (scaling_type_current == NULL)
6116 scaling_type_current =
6117 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6119 // if that also fails, set current scaling type to first available value
6120 if (scaling_type_current == NULL)
6121 scaling_type_current = scaling_types;
6124 setup.window_scaling_quality = scaling_type_current->identifier;
6126 // needed for displaying scaling type text instead of identifier
6127 scaling_type_text = scaling_type_current->name;
6130 static void execSetupGraphics_setRenderingModes(void)
6132 if (rendering_modes == NULL)
6136 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6138 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6139 char identifier[32], name[32];
6140 char *value = rendering_modes_list[i].value;
6141 char *text = rendering_modes_list[i].text;
6143 ti->node_top = &rendering_modes;
6144 ti->sort_priority = i;
6146 sprintf(identifier, "%s", value);
6147 sprintf(name, "%s", text);
6149 setString(&ti->identifier, identifier);
6150 setString(&ti->name, name);
6151 setString(&ti->name_sorting, name);
6152 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6154 pushTreeInfo(&rendering_modes, ti);
6157 // sort rendering mode values to start with lowest rendering mode value
6158 sortTreeInfo(&rendering_modes);
6160 // set current rendering mode value to configured rendering mode value
6161 rendering_mode_current =
6162 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6164 // if that fails, set current rendering mode to reliable default value
6165 if (rendering_mode_current == NULL)
6166 rendering_mode_current =
6167 getTreeInfoFromIdentifier(rendering_modes,
6168 STR_SPECIAL_RENDERING_DEFAULT);
6170 // if that also fails, set current rendering mode to first available one
6171 if (rendering_mode_current == NULL)
6172 rendering_mode_current = rendering_modes;
6175 setup.screen_rendering_mode = rendering_mode_current->identifier;
6177 // needed for displaying rendering mode text instead of identifier
6178 rendering_mode_text = rendering_mode_current->name;
6181 static void execSetupGraphics_setVsyncModes(boolean update_value)
6183 if (vsync_modes == NULL)
6187 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6189 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6190 char identifier[32], name[32];
6191 char *value = vsync_modes_list[i].value;
6192 char *text = vsync_modes_list[i].text;
6194 ti->node_top = &vsync_modes;
6195 ti->sort_priority = i;
6197 sprintf(identifier, "%s", value);
6198 sprintf(name, "%s", text);
6200 setString(&ti->identifier, identifier);
6201 setString(&ti->name, name);
6202 setString(&ti->name_sorting, name);
6203 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6205 pushTreeInfo(&vsync_modes, ti);
6208 // sort vsync mode values to start with lowest vsync mode value
6209 sortTreeInfo(&vsync_modes);
6211 update_value = TRUE;
6216 // set current vsync mode value to configured vsync mode value
6217 vsync_mode_current =
6218 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6220 // if that fails, set current vsync mode to reliable default value
6221 if (vsync_mode_current == NULL)
6222 vsync_mode_current =
6223 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6225 // if that also fails, set current vsync mode to first available one
6226 if (vsync_mode_current == NULL)
6227 vsync_mode_current = vsync_modes;
6230 setup.vsync_mode = vsync_mode_current->identifier;
6232 // needed for displaying vsync mode text instead of identifier
6233 vsync_mode_text = vsync_mode_current->name;
6236 static void execSetupGraphics(void)
6238 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6240 // update "setup.window_scaling_percent" from list selection
6241 // (in this case, window scaling was changed on setup screen)
6242 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6243 execSetupGraphics_setWindowSizes(FALSE);
6245 // update "setup.vsync_mode" from list selection
6246 // (in this case, vsync mode was changed on setup screen)
6247 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6248 execSetupGraphics_setVsyncModes(FALSE);
6250 // update list selection from "setup.window_scaling_percent"
6251 // (window scaling may have changed by resizing the window)
6252 execSetupGraphics_setWindowSizes(TRUE);
6254 // update list selection from "setup.vsync_mode"
6255 // (vsync_mode may have changed by re-creating the renderer)
6256 execSetupGraphics_setVsyncModes(TRUE);
6258 execSetupGraphics_setScalingTypes();
6259 execSetupGraphics_setRenderingModes();
6261 setup_mode = SETUP_MODE_GRAPHICS;
6265 // check if game speed is high enough for 60 Hz vsync to work
6266 if (check_game_speed)
6267 ModifyGameSpeedIfNeeded();
6269 // window scaling may have changed at this point
6270 ChangeWindowScalingIfNeeded();
6272 // window scaling quality may have changed at this point
6273 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6274 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6276 // screen rendering mode may have changed at this point
6277 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6279 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6280 int video_vsync_mode = video.vsync_mode;
6282 // screen vsync mode may have changed at this point
6283 ChangeVsyncModeIfNeeded();
6285 // check if setting vsync mode to selected value failed
6286 if (setup_vsync_mode != video_vsync_mode &&
6287 setup_vsync_mode != video.vsync_mode)
6289 // changing vsync mode to selected value failed -- reset displayed value
6290 execSetupGraphics_setVsyncModes(TRUE);
6292 Request("Setting VSync failed!", REQ_CONFIRM);
6298 static void execSetupChooseWindowSize(void)
6300 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6305 static void execSetupChooseScalingType(void)
6307 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6312 static void execSetupChooseRenderingMode(void)
6314 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6319 static void execSetupChooseVsyncMode(void)
6321 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6326 static void execSetupChooseVolumeSimple(void)
6328 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6333 static void execSetupChooseVolumeLoops(void)
6335 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6340 static void execSetupChooseVolumeMusic(void)
6342 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6347 static void execSetupSound(void)
6349 if (volumes_simple == NULL)
6351 boolean current_volume_simple_found = FALSE;
6354 for (i = 0; volumes_list[i].value != -1; i++)
6356 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6357 char identifier[32], name[32];
6358 int value = volumes_list[i].value;
6359 char *text = volumes_list[i].text;
6361 ti->node_top = &volumes_simple;
6362 ti->sort_priority = value;
6364 sprintf(identifier, "%d", value);
6365 sprintf(name, "%s", text);
6367 setString(&ti->identifier, identifier);
6368 setString(&ti->name, name);
6369 setString(&ti->name_sorting, name);
6370 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6372 pushTreeInfo(&volumes_simple, ti);
6374 if (value == setup.volume_simple)
6375 current_volume_simple_found = TRUE;
6378 if (!current_volume_simple_found)
6380 // add entry for non-preset volume value
6382 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6383 char identifier[32], name[32];
6384 int value = setup.volume_simple;
6386 ti->node_top = &volumes_simple;
6387 ti->sort_priority = value;
6389 sprintf(identifier, "%d", value);
6390 sprintf(name, "%d %% (Current)", value);
6392 setString(&ti->identifier, identifier);
6393 setString(&ti->name, name);
6394 setString(&ti->name_sorting, name);
6395 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6397 pushTreeInfo(&volumes_simple, ti);
6400 // sort volume values to start with lowest volume value
6401 sortTreeInfo(&volumes_simple);
6403 // set current volume value to configured volume value
6404 volume_simple_current =
6405 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6407 // if that fails, set current volume to reliable default value
6408 if (volume_simple_current == NULL)
6409 volume_simple_current =
6410 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6412 // if that also fails, set current volume to first available value
6413 if (volume_simple_current == NULL)
6414 volume_simple_current = volumes_simple;
6417 if (volumes_loops == NULL)
6419 boolean current_volume_loops_found = FALSE;
6422 for (i = 0; volumes_list[i].value != -1; i++)
6424 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6425 char identifier[32], name[32];
6426 int value = volumes_list[i].value;
6427 char *text = volumes_list[i].text;
6429 ti->node_top = &volumes_loops;
6430 ti->sort_priority = value;
6432 sprintf(identifier, "%d", value);
6433 sprintf(name, "%s", text);
6435 setString(&ti->identifier, identifier);
6436 setString(&ti->name, name);
6437 setString(&ti->name_sorting, name);
6438 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6440 pushTreeInfo(&volumes_loops, ti);
6442 if (value == setup.volume_loops)
6443 current_volume_loops_found = TRUE;
6446 if (!current_volume_loops_found)
6448 // add entry for non-preset volume value
6450 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6451 char identifier[32], name[32];
6452 int value = setup.volume_loops;
6454 ti->node_top = &volumes_loops;
6455 ti->sort_priority = value;
6457 sprintf(identifier, "%d", value);
6458 sprintf(name, "%d %% (Current)", value);
6460 setString(&ti->identifier, identifier);
6461 setString(&ti->name, name);
6462 setString(&ti->name_sorting, name);
6463 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6465 pushTreeInfo(&volumes_loops, ti);
6468 // sort volume values to start with lowest volume value
6469 sortTreeInfo(&volumes_loops);
6471 // set current volume value to configured volume value
6472 volume_loops_current =
6473 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6475 // if that fails, set current volume to reliable default value
6476 if (volume_loops_current == NULL)
6477 volume_loops_current =
6478 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6480 // if that also fails, set current volume to first available value
6481 if (volume_loops_current == NULL)
6482 volume_loops_current = volumes_loops;
6485 if (volumes_music == NULL)
6487 boolean current_volume_music_found = FALSE;
6490 for (i = 0; volumes_list[i].value != -1; i++)
6492 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6493 char identifier[32], name[32];
6494 int value = volumes_list[i].value;
6495 char *text = volumes_list[i].text;
6497 ti->node_top = &volumes_music;
6498 ti->sort_priority = value;
6500 sprintf(identifier, "%d", value);
6501 sprintf(name, "%s", text);
6503 setString(&ti->identifier, identifier);
6504 setString(&ti->name, name);
6505 setString(&ti->name_sorting, name);
6506 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6508 pushTreeInfo(&volumes_music, ti);
6510 if (value == setup.volume_music)
6511 current_volume_music_found = TRUE;
6514 if (!current_volume_music_found)
6516 // add entry for non-preset volume value
6518 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6519 char identifier[32], name[32];
6520 int value = setup.volume_music;
6522 ti->node_top = &volumes_music;
6523 ti->sort_priority = value;
6525 sprintf(identifier, "%d", value);
6526 sprintf(name, "%d %% (Current)", value);
6528 setString(&ti->identifier, identifier);
6529 setString(&ti->name, name);
6530 setString(&ti->name_sorting, name);
6531 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6533 pushTreeInfo(&volumes_music, ti);
6536 // sort volume values to start with lowest volume value
6537 sortTreeInfo(&volumes_music);
6539 // set current volume value to configured volume value
6540 volume_music_current =
6541 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6543 // if that fails, set current volume to reliable default value
6544 if (volume_music_current == NULL)
6545 volume_music_current =
6546 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6548 // if that also fails, set current volume to first available value
6549 if (volume_music_current == NULL)
6550 volume_music_current = volumes_music;
6553 setup.volume_simple = atoi(volume_simple_current->identifier);
6554 setup.volume_loops = atoi(volume_loops_current->identifier);
6555 setup.volume_music = atoi(volume_music_current->identifier);
6557 // needed for displaying volume text instead of identifier
6558 volume_simple_text = volume_simple_current->name;
6559 volume_loops_text = volume_loops_current->name;
6560 volume_music_text = volume_music_current->name;
6562 setup_mode = SETUP_MODE_SOUND;
6567 static void execSetupChooseTouchControls(void)
6569 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6574 static void execSetupChooseMoveDistance(void)
6576 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6581 static void execSetupChooseDropDistance(void)
6583 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6588 static void execSetupChooseTransparency(void)
6590 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6595 static void execSetupChooseGridXSize_0(void)
6597 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6602 static void execSetupChooseGridYSize_0(void)
6604 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6609 static void execSetupChooseGridXSize_1(void)
6611 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6616 static void execSetupChooseGridYSize_1(void)
6618 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6623 static void execSetupConfigureVirtualButtons(void)
6625 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6627 ConfigureVirtualButtons();
6629 setup_mode = SETUP_MODE_TOUCH;
6634 static void execSetupTouch(void)
6638 if (touch_controls == NULL)
6640 for (i = 0; touch_controls_list[i].value != NULL; i++)
6642 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6643 char identifier[32], name[32];
6644 char *value = touch_controls_list[i].value;
6645 char *text = touch_controls_list[i].text;
6647 ti->node_top = &touch_controls;
6648 ti->sort_priority = i;
6650 sprintf(identifier, "%s", value);
6651 sprintf(name, "%s", text);
6653 setString(&ti->identifier, identifier);
6654 setString(&ti->name, name);
6655 setString(&ti->name_sorting, name);
6656 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6658 pushTreeInfo(&touch_controls, ti);
6661 // sort touch control values to start with lowest touch control value
6662 sortTreeInfo(&touch_controls);
6664 // set current touch control value to configured touch control value
6665 touch_control_current =
6666 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6668 // if that fails, set current touch control to reliable default value
6669 if (touch_control_current == NULL)
6670 touch_control_current =
6671 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6673 // if that also fails, set current touch control to first available value
6674 if (touch_control_current == NULL)
6675 touch_control_current = touch_controls;
6678 if (move_distances == NULL)
6680 for (i = 0; distances_list[i].value != -1; i++)
6682 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6683 char identifier[32], name[32];
6684 int value = distances_list[i].value;
6685 char *text = distances_list[i].text;
6687 ti->node_top = &move_distances;
6688 ti->sort_priority = value;
6690 sprintf(identifier, "%d", value);
6691 sprintf(name, "%s", text);
6693 setString(&ti->identifier, identifier);
6694 setString(&ti->name, name);
6695 setString(&ti->name_sorting, name);
6696 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6698 pushTreeInfo(&move_distances, ti);
6701 // sort distance values to start with lowest distance value
6702 sortTreeInfo(&move_distances);
6704 // set current distance value to configured distance value
6705 move_distance_current =
6706 getTreeInfoFromIdentifier(move_distances,
6707 i_to_a(setup.touch.move_distance));
6709 // if that fails, set current distance to reliable default value
6710 if (move_distance_current == NULL)
6711 move_distance_current =
6712 getTreeInfoFromIdentifier(move_distances,
6713 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6715 // if that also fails, set current distance to first available value
6716 if (move_distance_current == NULL)
6717 move_distance_current = move_distances;
6720 if (drop_distances == NULL)
6722 for (i = 0; distances_list[i].value != -1; i++)
6724 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6725 char identifier[32], name[32];
6726 int value = distances_list[i].value;
6727 char *text = distances_list[i].text;
6729 ti->node_top = &drop_distances;
6730 ti->sort_priority = value;
6732 sprintf(identifier, "%d", value);
6733 sprintf(name, "%s", text);
6735 setString(&ti->identifier, identifier);
6736 setString(&ti->name, name);
6737 setString(&ti->name_sorting, name);
6738 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6740 pushTreeInfo(&drop_distances, ti);
6743 // sort distance values to start with lowest distance value
6744 sortTreeInfo(&drop_distances);
6746 // set current distance value to configured distance value
6747 drop_distance_current =
6748 getTreeInfoFromIdentifier(drop_distances,
6749 i_to_a(setup.touch.drop_distance));
6751 // if that fails, set current distance to reliable default value
6752 if (drop_distance_current == NULL)
6753 drop_distance_current =
6754 getTreeInfoFromIdentifier(drop_distances,
6755 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6757 // if that also fails, set current distance to first available value
6758 if (drop_distance_current == NULL)
6759 drop_distance_current = drop_distances;
6762 if (transparencies == NULL)
6764 for (i = 0; transparencies_list[i].value != -1; i++)
6766 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6767 char identifier[32], name[32];
6768 int value = transparencies_list[i].value;
6769 char *text = transparencies_list[i].text;
6771 ti->node_top = &transparencies;
6772 ti->sort_priority = value;
6774 sprintf(identifier, "%d", value);
6775 sprintf(name, "%s", text);
6777 setString(&ti->identifier, identifier);
6778 setString(&ti->name, name);
6779 setString(&ti->name_sorting, name);
6780 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6782 pushTreeInfo(&transparencies, ti);
6785 // sort transparency values to start with lowest transparency value
6786 sortTreeInfo(&transparencies);
6788 // set current transparency value to configured transparency value
6789 transparency_current =
6790 getTreeInfoFromIdentifier(transparencies,
6791 i_to_a(setup.touch.transparency));
6793 // if that fails, set current transparency to reliable default value
6794 if (transparency_current == NULL)
6795 transparency_current =
6796 getTreeInfoFromIdentifier(transparencies,
6797 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6799 // if that also fails, set current transparency to first available value
6800 if (transparency_current == NULL)
6801 transparency_current = transparencies;
6804 for (i = 0; i < 2; i++)
6806 for (j = 0; j < 2; j++)
6808 if (grid_sizes[i][j] == NULL)
6810 for (k = 0; grid_sizes_list[k].value != -1; k++)
6812 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6813 char identifier[32], name[32];
6814 int value = grid_sizes_list[k].value;
6815 char *text = grid_sizes_list[k].text;
6817 ti->node_top = &grid_sizes[i][j];
6818 ti->sort_priority = value;
6820 sprintf(identifier, "%d", value);
6821 sprintf(name, "%s", text);
6823 setString(&ti->identifier, identifier);
6824 setString(&ti->name, name);
6825 setString(&ti->name_sorting, name);
6826 setString(&ti->infotext,
6829 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6830 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6832 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6833 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6835 pushTreeInfo(&grid_sizes[i][j], ti);
6838 // sort grid size values to start with lowest grid size value
6839 sortTreeInfo(&grid_sizes[i][j]);
6841 // set current grid size value to configured grid size value
6842 grid_size_current[i][j] =
6843 getTreeInfoFromIdentifier(grid_sizes[i][j],
6845 setup.touch.grid_xsize[i] :
6846 setup.touch.grid_ysize[i]));
6848 // if that fails, set current grid size to reliable default value
6849 if (grid_size_current[i][j] == NULL)
6850 grid_size_current[i][j] =
6851 getTreeInfoFromIdentifier(grid_sizes[i][j],
6853 DEFAULT_GRID_XSIZE(i) :
6854 DEFAULT_GRID_YSIZE(i)));
6856 // if that also fails, set current grid size to first available value
6857 if (grid_size_current[i][j] == NULL)
6858 grid_size_current[i][j] = grid_sizes[i][j];
6863 setup.touch.control_type = touch_control_current->identifier;
6864 setup.touch.move_distance = atoi(move_distance_current->identifier);
6865 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6866 setup.touch.transparency = atoi(transparency_current->identifier);
6868 for (i = 0; i < 2; i++)
6870 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6871 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6873 if (i == GRID_ACTIVE_NR())
6875 overlay.grid_xsize = setup.touch.grid_xsize[i];
6876 overlay.grid_ysize = setup.touch.grid_ysize[i];
6880 // needed for displaying value text instead of identifier
6881 touch_controls_text = touch_control_current->name;
6882 move_distance_text = move_distance_current->name;
6883 drop_distance_text = drop_distance_current->name;
6884 transparency_text = transparency_current->name;
6886 for (i = 0; i < 2; i++)
6887 for (j = 0; j < 2; j++)
6888 grid_size_text[i][j] = grid_size_current[i][j]->name;
6890 setup_mode = SETUP_MODE_TOUCH;
6895 static void execSetupArtwork(void)
6897 static ArtworkDirTree *gfx_last_valid = NULL;
6898 static ArtworkDirTree *snd_last_valid = NULL;
6899 static ArtworkDirTree *mus_last_valid = NULL;
6901 // current artwork directory may be invalid (level group, parent link)
6902 if (!validLevelSeries(artwork.gfx_current))
6903 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6904 if (!validLevelSeries(artwork.snd_current))
6905 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6906 if (!validLevelSeries(artwork.mus_current))
6907 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6909 // store valid artwork directory information
6910 gfx_last_valid = artwork.gfx_current;
6911 snd_last_valid = artwork.snd_current;
6912 mus_last_valid = artwork.mus_current;
6915 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6916 artwork.gfx_current->subdir,
6917 artwork.gfx_current->fullpath,
6918 artwork.gfx_current->basepath);
6921 setup.graphics_set = artwork.gfx_current->identifier;
6922 setup.sounds_set = artwork.snd_current->identifier;
6923 setup.music_set = artwork.mus_current->identifier;
6925 // needed if last screen (setup choice) changed graphics, sounds or music
6926 ReloadCustomArtwork(0);
6928 // needed for displaying artwork name instead of artwork identifier
6929 graphics_set_name = artwork.gfx_current->name;
6930 sounds_set_name = artwork.snd_current->name;
6931 music_set_name = artwork.mus_current->name;
6933 setup_mode = SETUP_MODE_ARTWORK;
6938 static void execSetupChooseGraphics(void)
6940 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6945 static void execSetupChooseSounds(void)
6947 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6952 static void execSetupChooseMusic(void)
6954 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6959 static void execSetupInput(void)
6961 setup_mode = SETUP_MODE_INPUT;
6966 static void execSetupShortcuts(void)
6968 setup_mode = SETUP_MODE_SHORTCUTS;
6973 static void execSetupShortcuts1(void)
6975 setup_mode = SETUP_MODE_SHORTCUTS_1;
6980 static void execSetupShortcuts2(void)
6982 setup_mode = SETUP_MODE_SHORTCUTS_2;
6987 static void execSetupShortcuts3(void)
6989 setup_mode = SETUP_MODE_SHORTCUTS_3;
6994 static void execSetupShortcuts4(void)
6996 setup_mode = SETUP_MODE_SHORTCUTS_4;
7001 static void execSetupShortcuts5(void)
7003 setup_mode = SETUP_MODE_SHORTCUTS_5;
7008 static void execExitSetup(void)
7010 SetGameStatus(GAME_MODE_MAIN);
7015 static void execSaveAndExitSetup(void)
7021 static void execGadgetNetworkServer(void)
7023 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7024 struct GadgetInfo *gi = screen_gadget[gadget_id];
7026 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7027 network_server_hostname[0] = '\0';
7029 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7033 ClickOnGadget(gi, MB_LEFTBUTTON);
7036 static void execOfferUploadTapes(void)
7041 static void ToggleNetworkModeIfNeeded(void)
7043 int font_title = FONT_TITLE_1;
7044 int font_foot = FC_BLUE;
7045 int ystart = mSY - SY + 16;
7046 int ybottom = mSY - SY + SYSIZE - 20;
7047 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7049 if (setup.network_mode == network.enabled)
7052 network.enabled = setup.network_mode;
7054 FadeOut(REDRAW_ALL);
7058 DrawTextSCentered(ystart, font_title, text);
7062 if (network.enabled)
7063 InitNetworkServer();
7065 DisconnectFromNetworkServer();
7067 DrawTextSCentered(ybottom, font_foot,
7068 "Press any key or button for setup menu");
7070 WaitForEventToContinue();
7075 static void ToggleGameSpeedsListIfNeeded(void)
7077 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7079 if (setup.game_speed_extended == using_game_speeds_extended)
7082 // try to match similar values when changing game speeds list
7083 if (setup.game_speed_extended)
7084 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7085 setup.game_frame_delay == 30 ? 29 :
7086 setup.game_frame_delay);
7088 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7089 setup.game_frame_delay == 16 ? 15 :
7090 setup.game_frame_delay >= 29 ? 30 :
7091 setup.game_frame_delay <= 10 ? 10 :
7092 setup.game_frame_delay);
7094 execSetupGame_setGameSpeeds(TRUE);
7099 static void ToggleUseApiServerIfNeeded(void)
7101 if (runtime.use_api_server == setup.use_api_server)
7104 runtime.use_api_server = setup.use_api_server;
7106 if (runtime.use_api_server)
7108 if (setup.has_remaining_tapes)
7109 setup.ask_for_uploading_tapes = TRUE;
7111 CheckApiServerTasks();
7115 static void ModifyGameSpeedIfNeeded(void)
7117 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7118 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7122 char *game_speed_text = "Fast";
7123 int game_speed_value = 15;
7125 if (setup.game_speed_extended)
7127 game_speed_text = "60 fps";
7128 game_speed_value = 16;
7131 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7133 // set game speed to existing list value that is fast enough for vsync
7134 setup.game_frame_delay = game_speed_value;
7136 execSetupGame_setGameSpeeds(TRUE);
7138 Request(message, REQ_CONFIRM);
7141 static void DisableVsyncIfNeeded(void)
7143 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7144 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7145 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7148 // disable vsync for the selected game speed to work
7149 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7151 execSetupGraphics_setVsyncModes(TRUE);
7153 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7159 void *related_value;
7160 } hide_related_entry_list[] =
7162 { &setup.network_server_hostname, execGadgetNetworkServer },
7163 { &setup.network_server_hostname, &network_server_text },
7165 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7166 { &setup.scores_in_highscore_list, &scores_type_text },
7168 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7169 { &setup.game_frame_delay, &game_speed_text },
7171 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7172 { &setup.scroll_delay_value, &scroll_delay_text },
7174 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7175 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7177 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7178 { &setup.window_scaling_percent, &window_size_text },
7180 { &setup.window_scaling_quality, execSetupChooseScalingType },
7181 { &setup.window_scaling_quality, &scaling_type_text },
7183 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7184 { &setup.screen_rendering_mode, &rendering_mode_text },
7186 { &setup.vsync_mode, execSetupChooseVsyncMode },
7187 { &setup.vsync_mode, &vsync_mode_text },
7189 { &setup.graphics_set, execSetupChooseGraphics },
7190 { &setup.graphics_set, &graphics_set_name },
7192 { &setup.sounds_set, execSetupChooseSounds },
7193 { &setup.sounds_set, &sounds_set_name },
7195 { &setup.music_set, execSetupChooseMusic },
7196 { &setup.music_set, &music_set_name },
7198 { &setup.volume_simple, execSetupChooseVolumeSimple },
7199 { &setup.volume_simple, &volume_simple_text },
7201 { &setup.volume_loops, execSetupChooseVolumeLoops },
7202 { &setup.volume_loops, &volume_loops_text },
7204 { &setup.volume_music, execSetupChooseVolumeMusic },
7205 { &setup.volume_music, &volume_music_text },
7207 { &setup.touch.control_type, execSetupChooseTouchControls },
7208 { &setup.touch.control_type, &touch_controls_text },
7210 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7211 { &setup.touch.move_distance, &move_distance_text },
7213 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7214 { &setup.touch.drop_distance, &drop_distance_text },
7216 { &setup.touch.transparency, execSetupChooseTransparency },
7217 { &setup.touch.transparency, &transparency_text },
7219 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7220 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7222 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7223 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7225 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7226 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7228 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7229 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7231 { &setup.internal.menu_game, execSetupGame },
7232 { &setup.internal.menu_engines, execSetupEngines },
7233 { &setup.internal.menu_editor, execSetupEditor },
7234 { &setup.internal.menu_graphics, execSetupGraphics },
7235 { &setup.internal.menu_sound, execSetupSound },
7236 { &setup.internal.menu_artwork, execSetupArtwork },
7237 { &setup.internal.menu_input, execSetupInput },
7238 { &setup.internal.menu_touch, execSetupTouch },
7239 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7240 { &setup.internal.menu_exit, execExitSetup },
7241 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7243 { &setup.internal.menu_shortcuts_various, execSetupShortcuts1 },
7244 { &setup.internal.menu_shortcuts_focus, execSetupShortcuts2 },
7245 { &setup.internal.menu_shortcuts_tape, execSetupShortcuts3 },
7246 { &setup.internal.menu_shortcuts_sound, execSetupShortcuts4 },
7247 { &setup.internal.menu_shortcuts_snap, execSetupShortcuts5 },
7249 { &setup.internal.info_title, execInfoTitleScreen },
7250 { &setup.internal.info_elements, execInfoElements },
7251 { &setup.internal.info_music, execInfoMusic },
7252 { &setup.internal.info_credits, execInfoCredits },
7253 { &setup.internal.info_program, execInfoProgram },
7254 { &setup.internal.info_version, execInfoVersion },
7255 { &setup.internal.info_levelset, execInfoLevelSet },
7256 { &setup.internal.info_exit, execExitInfo },
7261 void setHideRelatedSetupEntries(void)
7265 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7266 if (hideSetupEntry(hide_related_entry_list[i].value))
7267 setHideSetupEntry(hide_related_entry_list[i].related_value);
7270 static struct TokenInfo setup_info_main[] =
7272 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7273 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7274 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7275 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7276 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7277 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7278 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7279 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7280 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7281 { TYPE_EMPTY, NULL, "" },
7282 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7283 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7288 static struct TokenInfo setup_info_game[] =
7290 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7291 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7292 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7293 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7294 { TYPE_STRING, &network_server_text, "" },
7295 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7296 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7297 { TYPE_STRING, &scores_type_text, "" },
7298 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7299 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7300 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7301 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7302 { TYPE_SWITCH, &setup.handicap, "Force Solving Levels:" },
7303 { TYPE_SWITCH, &setup.skip_levels, "Allow Skipping Levels:" },
7304 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7305 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7306 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7307 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7308 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7309 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7310 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7311 { TYPE_SWITCH, &setup.autorecord, "Auto-Record When Playing:" },
7312 { TYPE_SWITCH, &setup.autorecord_after_replay, "Auto-Record After Replay:" },
7313 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7314 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7315 { TYPE_STRING, &game_speed_text, "" },
7316 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7318 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7319 { TYPE_STRING, &scroll_delay_text, "" },
7321 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7322 { TYPE_STRING, &snapshot_mode_text, "" },
7323 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7324 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7325 { TYPE_EMPTY, NULL, "" },
7326 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7331 static struct TokenInfo setup_info_engines[] =
7333 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7334 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7335 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7336 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7337 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7338 { TYPE_EMPTY, NULL, "" },
7339 { TYPE_HEADLINE, NULL, "Supaplex" },
7340 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7341 { TYPE_EMPTY, NULL, "" },
7342 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7347 static struct TokenInfo setup_info_editor[] =
7350 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7351 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7352 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7353 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7354 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7355 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7356 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7357 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7358 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7359 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7361 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7362 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7364 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7366 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7367 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7368 { TYPE_EMPTY, NULL, "" },
7370 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7371 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7372 { TYPE_EMPTY, NULL, "" },
7374 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7375 { TYPE_EMPTY, NULL, "" },
7376 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7377 { TYPE_EMPTY, NULL, "" },
7378 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7383 static struct TokenInfo setup_info_graphics[] =
7385 #if !defined(PLATFORM_ANDROID) && !defined(PLATFORM_EMSCRIPTEN)
7386 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7387 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7388 { TYPE_STRING, &window_size_text, "" },
7389 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7390 { TYPE_STRING, &scaling_type_text, "" },
7391 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7392 { TYPE_STRING, &rendering_mode_text, "" },
7395 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7396 { TYPE_STRING, &scroll_delay_text, "" },
7398 #if !defined(PLATFORM_EMSCRIPTEN)
7399 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7400 { TYPE_STRING, &vsync_mode_text, "" },
7402 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7403 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7404 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7405 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7406 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7407 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7408 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7409 { TYPE_EMPTY, NULL, "" },
7410 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7415 static struct TokenInfo setup_info_sound[] =
7417 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7418 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7419 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7420 { TYPE_EMPTY, NULL, "" },
7421 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7422 { TYPE_STRING, &volume_simple_text, "" },
7423 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7424 { TYPE_STRING, &volume_loops_text, "" },
7425 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7426 { TYPE_STRING, &volume_music_text, "" },
7427 { TYPE_EMPTY, NULL, "" },
7428 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7433 static struct TokenInfo setup_info_artwork[] =
7435 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7436 { TYPE_STRING, &graphics_set_name, "" },
7437 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7438 { TYPE_STRING, &sounds_set_name, "" },
7439 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7440 { TYPE_STRING, &music_set_name, "" },
7441 { TYPE_EMPTY, NULL, "" },
7442 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7443 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7444 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7445 { TYPE_EMPTY, NULL, "" },
7446 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7451 static struct TokenInfo setup_info_input[] =
7453 { TYPE_SWITCH, NULL, "Player:" },
7454 { TYPE_SWITCH, NULL, "Device:" },
7455 { TYPE_SWITCH, NULL, "" },
7456 { TYPE_SKIPPABLE, NULL, "" },
7457 { TYPE_EMPTY, NULL, "" },
7458 { TYPE_EMPTY, NULL, "" },
7459 { TYPE_EMPTY, NULL, "" },
7460 { TYPE_EMPTY, NULL, "" },
7461 { TYPE_EMPTY, NULL, "" },
7462 { TYPE_EMPTY, NULL, "" },
7463 { TYPE_EMPTY, NULL, "" },
7464 { TYPE_EMPTY, NULL, "" },
7465 { TYPE_SKIPPABLE, NULL, "" },
7466 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7471 static struct TokenInfo setup_info_touch[] =
7473 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7474 { TYPE_STRING, &touch_controls_text, "" },
7475 { TYPE_EMPTY, NULL, "" },
7476 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7481 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7483 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7484 { TYPE_STRING, &touch_controls_text, "" },
7485 { TYPE_EMPTY, NULL, "" },
7486 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7487 { TYPE_STRING, &grid_size_text[0][0], "" },
7488 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7489 { TYPE_STRING, &grid_size_text[0][1], "" },
7490 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7491 { TYPE_STRING, &transparency_text, "" },
7492 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7493 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7494 { TYPE_EMPTY, NULL, "" },
7495 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7496 { TYPE_EMPTY, NULL, "" },
7497 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7502 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7504 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7505 { TYPE_STRING, &touch_controls_text, "" },
7506 { TYPE_EMPTY, NULL, "" },
7507 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7508 { TYPE_STRING, &grid_size_text[1][0], "" },
7509 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7510 { TYPE_STRING, &grid_size_text[1][1], "" },
7511 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7512 { TYPE_STRING, &transparency_text, "" },
7513 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7514 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7515 { TYPE_EMPTY, NULL, "" },
7516 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7517 { TYPE_EMPTY, NULL, "" },
7518 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7523 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7525 setup_info_touch_virtual_buttons_0,
7526 setup_info_touch_virtual_buttons_1
7529 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7531 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7532 { TYPE_STRING, &touch_controls_text, "" },
7533 { TYPE_EMPTY, NULL, "" },
7534 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7535 { TYPE_STRING, &move_distance_text, "" },
7536 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7537 { TYPE_STRING, &drop_distance_text, "" },
7538 { TYPE_EMPTY, NULL, "" },
7539 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7544 static struct TokenInfo setup_info_shortcuts[] =
7546 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7547 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7548 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7549 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7550 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7551 { TYPE_EMPTY, NULL, "" },
7552 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7557 static struct TokenInfo setup_info_shortcuts_1[] =
7559 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7560 { TYPE_KEY, &setup.shortcut.save_game, "" },
7561 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7562 { TYPE_KEY, &setup.shortcut.load_game, "" },
7563 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7564 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7565 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7566 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7567 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7568 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7569 { TYPE_EMPTY, NULL, "" },
7570 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7571 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7572 { TYPE_EMPTY, NULL, "" },
7573 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7578 static struct TokenInfo setup_info_shortcuts_2[] =
7580 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7581 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7582 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7583 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7584 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7585 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7586 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7587 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7588 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7589 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7590 { TYPE_EMPTY, NULL, "" },
7591 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7596 static struct TokenInfo setup_info_shortcuts_3[] =
7598 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7599 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7600 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7601 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7602 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7603 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7604 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7605 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7606 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7607 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7608 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7609 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7610 { TYPE_EMPTY, NULL, "" },
7611 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7616 static struct TokenInfo setup_info_shortcuts_4[] =
7618 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7619 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7620 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7621 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7622 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7623 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7624 { TYPE_EMPTY, NULL, "" },
7625 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7630 static struct TokenInfo setup_info_shortcuts_5[] =
7632 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7633 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7634 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7635 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7636 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7637 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7638 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7639 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7640 { TYPE_EMPTY, NULL, "" },
7641 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7646 static Key getSetupKey(void)
7648 Key key = KSYM_UNDEFINED;
7649 boolean got_key_event = FALSE;
7651 while (!got_key_event)
7655 if (NextValidEvent(&event))
7659 case EVENT_KEYPRESS:
7661 key = GetEventKey((KeyEvent *)&event);
7663 // press 'Escape' or 'Enter' to keep the existing key binding
7664 if (key == KSYM_Escape || key == KSYM_Return)
7665 key = KSYM_UNDEFINED; // keep old value
7667 got_key_event = TRUE;
7671 case EVENT_KEYRELEASE:
7672 key_joystick_mapping = 0;
7676 HandleOtherEvents(&event);
7687 static int getSetupValueFont(int type, void *value)
7689 if (type & TYPE_GHOSTED)
7690 return FONT_OPTION_OFF;
7691 else if (type & TYPE_KEY)
7692 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7693 else if (type & TYPE_STRING)
7694 return FONT_VALUE_2;
7695 else if (type & TYPE_ECS_AGA)
7696 return FONT_VALUE_1;
7697 else if (type & TYPE_BOOLEAN_STYLE)
7698 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7699 else if (type & TYPE_YES_NO_AUTO)
7700 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7701 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7702 else if (type & TYPE_PLAYER)
7703 return FONT_VALUE_1;
7705 return FONT_VALUE_1;
7708 static int getSetupValueFontNarrow(int type, int font_nr)
7710 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7711 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7712 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7716 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7718 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7719 struct TokenInfo *si = &setup_info[si_pos];
7720 boolean font_draw_xoffset_modified = FALSE;
7721 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7722 int font_draw_xoffset_old = -1;
7723 int xoffset = (scrollbar_needed ? -1 : 0);
7724 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7725 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7726 int xpos = menu_screen_value_xpos;
7727 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7728 int startx = mSX + xpos * 32;
7729 int starty = mSY + ypos * 32;
7730 int type = si->type;
7731 void *value = si->value;
7732 char *value_string = getSetupValue(type, value);
7733 int font_nr_default = getSetupValueFont(type, value);
7734 int font_width_default = getFontWidth(font_nr_default);
7735 int font_nr = font_nr_default;
7738 if (value_string == NULL)
7741 if (type & TYPE_KEY)
7743 xpos = MENU_SCREEN_START_XPOS;
7745 if (type & TYPE_QUERY)
7746 value_string = "<press key>";
7748 else if (type & TYPE_STRING)
7750 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7752 xpos = MENU_SCREEN_START_XPOS;
7754 if (strlen(value_string) > max_value_len)
7755 value_string[max_value_len] = '\0';
7757 else if (type & TYPE_YES_NO_AUTO)
7759 xpos = menu_screen_value_xpos - 1;
7761 else if (type & TYPE_PLAYER)
7763 int displayed_player_nr = *(int *)value + 1;
7765 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7768 startx = mSX + xpos * 32;
7769 starty = mSY + ypos * 32;
7771 // special check if right-side setup values moved left due to scrollbar
7772 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7774 int max_menu_text_length = 26; // maximum text length for classic menu
7775 int font_xoffset = getFontDrawOffsetX(font_nr);
7776 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7777 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7778 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7779 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7781 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7783 // when using narrow font, left-shifting text "auto" not needed
7784 if (type & TYPE_YES_NO_AUTO)
7788 startx = mSX + xpos * 32;
7790 font_nr = getSetupValueFontNarrow(type, font_nr);
7794 // downward compatibility correction for Juergen Bonhagen's menu settings
7795 if (setup_mode != SETUP_MODE_INPUT)
7797 int max_menu_text_length_big = (menu_screen_value_xpos -
7798 MENU_SCREEN_START_XPOS);
7799 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7800 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7801 int font1_xoffset = getFontDrawOffsetX(font_nr);
7802 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7803 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7804 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7805 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7806 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7807 boolean correct_font_draw_xoffset = FALSE;
7809 if (xpos == MENU_SCREEN_START_XPOS &&
7810 startx + font1_xoffset < text_startx + text_font_xoffset)
7811 correct_font_draw_xoffset = TRUE;
7813 if (xpos == menu_screen_value_xpos &&
7814 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7815 correct_font_draw_xoffset = TRUE;
7817 // check if setup value would overlap with setup text when printed
7818 // (this can happen for extreme/wrong values for font draw offset)
7819 if (correct_font_draw_xoffset)
7821 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7822 font_draw_xoffset_modified = TRUE;
7824 if (type & TYPE_KEY)
7825 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7826 else if (!(type & TYPE_STRING))
7827 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7828 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7832 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7833 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7835 DrawText(startx, starty, value_string, font_nr);
7837 if (type & TYPE_PLAYER)
7839 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7840 int player_nr = *(int *)value;
7841 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7842 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7843 int startx2 = startx + xoff;
7844 int starty2 = starty + yoff;
7846 if (DrawingOnBackground(startx2, starty2))
7847 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7849 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7850 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7853 if (font_draw_xoffset_modified)
7854 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7857 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7859 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7860 struct TokenInfo *si = &setup_info[si_pos];
7862 if (si->type & TYPE_BOOLEAN_STYLE)
7864 *(boolean *)si->value ^= TRUE;
7866 else if (si->type & TYPE_YES_NO_AUTO)
7870 (*(int *)si->value == AUTO ? TRUE :
7871 *(int *)si->value == TRUE ? FALSE : AUTO) :
7872 (*(int *)si->value == TRUE ? AUTO :
7873 *(int *)si->value == AUTO ? FALSE : TRUE));
7875 else if (si->type & TYPE_KEY)
7879 si->type |= TYPE_QUERY;
7880 drawSetupValue(screen_pos, setup_info_pos_raw);
7881 si->type &= ~TYPE_QUERY;
7883 key = getSetupKey();
7884 if (key != KSYM_UNDEFINED)
7885 *(Key *)si->value = key;
7887 else if (si->type & TYPE_PLAYER)
7889 int player_nr = *(int *)si->value;
7894 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7896 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7899 drawSetupValue(screen_pos, setup_info_pos_raw);
7901 // fullscreen state may have changed at this point
7902 if (si->value == &setup.fullscreen)
7903 ToggleFullscreenIfNeeded();
7905 // network mode may have changed at this point
7906 if (si->value == &setup.network_mode)
7907 ToggleNetworkModeIfNeeded();
7909 // API server mode may have changed at this point
7910 if (si->value == &setup.use_api_server)
7911 ToggleUseApiServerIfNeeded();
7913 // game speed list may have changed at this point
7914 if (si->value == &setup.game_speed_extended)
7915 ToggleGameSpeedsListIfNeeded();
7918 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7920 static struct TokenInfo *setup_info_final = NULL;
7925 // determine maximum list size of target list
7926 while (setup_info_orig[list_size++].type != 0);
7928 // free, allocate and clear memory for target list
7929 checked_free(setup_info_final);
7930 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7932 // copy setup info list without setup entries marked as hidden
7933 for (i = 0; setup_info_orig[i].type != 0; i++)
7935 // skip setup entries configured to be hidden
7936 if (hideSetupEntry(setup_info_orig[i].value))
7939 // skip skippable setup entries if screen is lower than usual
7940 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7941 setup_info_orig[i].type == TYPE_SKIPPABLE)
7944 setup_info_final[list_pos++] = setup_info_orig[i];
7947 return setup_info_final;
7950 static void DrawSetupScreen_Generic(void)
7952 int fade_mask = REDRAW_FIELD;
7953 boolean redraw_all = FALSE;
7954 char *title_string = NULL;
7958 fade_mask = REDRAW_ALL;
7961 FadeMenuSoundsAndMusic();
7963 FreeScreenGadgets();
7964 CreateScreenGadgets();
7966 if (redraw_mask & REDRAW_ALL)
7971 // needed if different viewport properties defined for setup screen
7972 ChangeViewportPropertiesIfNeeded();
7974 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7978 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7980 if (setup_mode == SETUP_MODE_MAIN)
7982 setup_info = setup_info_main;
7983 title_string = STR_SETUP_MAIN;
7985 else if (setup_mode == SETUP_MODE_GAME)
7987 setup_info = setup_info_game;
7988 title_string = STR_SETUP_GAME;
7990 else if (setup_mode == SETUP_MODE_ENGINES)
7992 setup_info = setup_info_engines;
7993 title_string = STR_SETUP_ENGINES;
7995 else if (setup_mode == SETUP_MODE_EDITOR)
7997 setup_info = setup_info_editor;
7998 title_string = STR_SETUP_EDITOR;
8000 else if (setup_mode == SETUP_MODE_GRAPHICS)
8002 setup_info = setup_info_graphics;
8003 title_string = STR_SETUP_GRAPHICS;
8005 else if (setup_mode == SETUP_MODE_SOUND)
8007 setup_info = setup_info_sound;
8008 title_string = STR_SETUP_SOUND;
8010 else if (setup_mode == SETUP_MODE_ARTWORK)
8012 setup_info = setup_info_artwork;
8013 title_string = STR_SETUP_ARTWORK;
8015 else if (setup_mode == SETUP_MODE_TOUCH)
8017 setup_info = setup_info_touch;
8018 title_string = STR_SETUP_TOUCH;
8020 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8021 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8022 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8023 setup_info = setup_info_touch_wipe_gestures;
8025 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8027 setup_info = setup_info_shortcuts;
8028 title_string = STR_SETUP_SHORTCUTS;
8030 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8032 setup_info = setup_info_shortcuts_1;
8033 title_string = STR_SETUP_SHORTCUTS;
8035 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8037 setup_info = setup_info_shortcuts_2;
8038 title_string = STR_SETUP_SHORTCUTS;
8040 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8042 setup_info = setup_info_shortcuts_3;
8043 title_string = STR_SETUP_SHORTCUTS;
8045 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8047 setup_info = setup_info_shortcuts_4;
8048 title_string = STR_SETUP_SHORTCUTS;
8050 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8052 setup_info = setup_info_shortcuts_5;
8053 title_string = STR_SETUP_SHORTCUTS;
8056 // use modified setup info without setup entries marked as hidden
8057 setup_info = getSetupInfoFinal(setup_info);
8059 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8061 // determine maximal number of setup entries that can be displayed on screen
8063 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8066 // determine maximal number of setup entries available for this setup screen
8068 for (i = 0; setup_info[i].type != 0; i++)
8071 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8073 MapScreenGadgets(max_setup_info);
8076 redraw_mask = fade_mask = REDRAW_ALL;
8078 DrawMaskedBorder(fade_mask);
8083 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8085 menu_info = setup_info;
8087 HandleMenuScreen(mx, my, dx, dy, button,
8088 setup_mode, num_setup_info, max_setup_info);
8091 static void DrawSetupScreen_Input(void)
8095 FadeOut(REDRAW_FIELD);
8099 setup_info = getSetupInfoFinal(setup_info_input);
8101 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8103 for (i = 0; setup_info[i].type != 0; i++)
8105 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8106 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8107 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8108 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8109 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8110 initCursor(i, IMG_MENU_BUTTON);
8112 DrawCursorAndText_Setup(i, -1, FALSE);
8115 // create gadgets for setup input menu screen
8116 FreeScreenGadgets();
8117 CreateScreenGadgets();
8119 // map gadgets for setup input menu screen
8120 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8122 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8124 FadeIn(REDRAW_FIELD);
8127 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8129 if (device_name == NULL)
8132 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8135 if (strlen(device_name) > 1)
8137 char c1 = device_name[strlen(device_name) - 1];
8138 char c2 = device_name[strlen(device_name) - 2];
8140 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8141 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8144 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8145 strlen(device_name));
8148 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8151 static struct SetupKeyboardInfo custom_key;
8158 { &custom_key.left, "Axis/Pad Left" },
8159 { &custom_key.right, "Axis/Pad Right" },
8160 { &custom_key.up, "Axis/Pad Up" },
8161 { &custom_key.down, "Axis/Pad Down" },
8162 { &custom_key.snap, "Button 1/A/X" },
8163 { &custom_key.drop, "Button 2/B/Y" }
8165 static char *joystick_name[MAX_PLAYERS] =
8172 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8173 int font_nr_info = FONT_MENU_1;
8174 int font_nr_name = FONT_VALUE_OLD;
8175 int font_nr_on = FONT_VALUE_1;
8176 int font_nr_off = FONT_VALUE_OLD;
8179 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8181 font_nr_info = FONT_MENU_2;
8182 font_nr_on = FONT_VALUE_NARROW;
8183 font_nr_off = FONT_VALUE_OLD_NARROW;
8186 custom_key = setup.input[player_nr].key;
8188 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8189 FONT_INPUT_1_ACTIVE);
8191 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8193 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8194 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8196 if (setup.input[player_nr].use_joystick)
8198 char *device_name = setup.input[player_nr].joy.device_name;
8199 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8200 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8201 char *text = joystick_name[joystick_nr];
8202 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8204 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8205 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8209 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8210 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8213 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8214 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8218 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8219 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8220 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8221 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8223 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8224 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8225 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8226 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8227 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8228 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8230 for (i = 0; i < 6; i++)
8232 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8234 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8236 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8237 (setup.input[player_nr].use_joystick ?
8239 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8243 static int input_player_nr = 0;
8245 static void HandleSetupScreen_Input_Player(int step, int direction)
8247 int old_player_nr = input_player_nr;
8250 new_player_nr = old_player_nr + step * direction;
8251 if (new_player_nr < 0)
8253 if (new_player_nr > MAX_PLAYERS - 1)
8254 new_player_nr = MAX_PLAYERS - 1;
8256 if (new_player_nr != old_player_nr)
8258 input_player_nr = new_player_nr;
8260 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8264 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8266 static int choice = 0;
8269 int pos_start = SETUPINPUT_SCREEN_POS_START;
8270 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8271 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8272 int pos_end = SETUPINPUT_SCREEN_POS_END;
8274 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8278 for (i = 0; setup_info_input[i].type != 0; i++)
8280 // adjust menu structure according to skipped setup entries
8281 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8289 if (button == MB_MENU_INITIALIZE)
8291 // input setup menu may have changed size due to graphics configuration
8292 if (choice >= pos_empty1)
8295 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8297 DrawCursorAndText_Setup(choice, -1, TRUE);
8301 else if (button == MB_MENU_LEAVE)
8303 setup_mode = SETUP_MODE_MAIN;
8310 if (mx || my) // mouse input
8312 x = (mx - mSX) / 32;
8313 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8315 else if (dx || dy) // keyboard input
8317 if (dx && choice == 0)
8318 x = (dx < 0 ? 10 : 12);
8319 else if ((dx && choice == 1) ||
8320 (dx == -1 && choice == pos_end))
8321 button = MB_MENU_CHOICE;
8325 if (y >= pos_empty1 && y <= pos_empty2)
8326 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8329 if (y == 0 && dx != 0 && button)
8331 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8333 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8334 y >= pos_start && y <= pos_end &&
8335 !(y >= pos_empty1 && y <= pos_empty2))
8341 DrawCursorAndText_Setup(choice, -1, FALSE);
8342 DrawCursorAndText_Setup(y, -1, TRUE);
8344 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8353 char *device_name = setup.input[input_player_nr].joy.device_name;
8355 if (!setup.input[input_player_nr].use_joystick)
8357 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8359 setJoystickDeviceToNr(device_name, new_device_nr);
8360 setup.input[input_player_nr].use_joystick = TRUE;
8364 int device_nr = getJoystickNrFromDeviceName(device_name);
8365 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8367 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8368 setup.input[input_player_nr].use_joystick = FALSE;
8370 setJoystickDeviceToNr(device_name, new_device_nr);
8373 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8377 if (setup.input[input_player_nr].use_joystick)
8378 ConfigureJoystick(input_player_nr);
8380 CustomizeKeyboard(input_player_nr);
8382 else if (y == pos_end)
8388 setup_mode = SETUP_MODE_MAIN;
8395 static boolean CustomizeKeyboardMain(int player_nr)
8399 boolean finished = FALSE;
8400 static struct SetupKeyboardInfo custom_key;
8405 } customize_step[] =
8407 { &custom_key.left, "Move Left" },
8408 { &custom_key.right, "Move Right" },
8409 { &custom_key.up, "Move Up" },
8410 { &custom_key.down, "Move Down" },
8411 { &custom_key.snap, "Snap Field" },
8412 { &custom_key.drop, "Drop Element" }
8414 int font_nr_old = FONT_VALUE_OLD;
8415 int font_nr_new = FONT_VALUE_1;
8416 boolean success = FALSE;
8418 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8420 font_nr_old = FONT_VALUE_OLD_NARROW;
8421 font_nr_new = FONT_VALUE_NARROW;
8424 // read existing key bindings from player setup
8425 custom_key = setup.input[player_nr].key;
8428 FadeOut(REDRAW_FIELD);
8432 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8435 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8436 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8437 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8438 "Key:", FONT_INPUT_1_ACTIVE);
8439 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8440 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8442 FadeIn(REDRAW_FIELD);
8447 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8449 // reset frame delay counter directly after updating screen
8450 ResetDelayCounter(&event_frame_delay);
8452 while (NextValidEvent(&event))
8456 case EVENT_KEYPRESS:
8458 Key key = GetEventKey((KeyEvent *)&event);
8460 // press 'Escape' to abort and keep the old key bindings
8461 if (key == KSYM_Escape)
8463 FadeSkipNextFadeIn();
8470 // press 'Enter' to keep the existing key binding
8471 if (key == KSYM_Return)
8472 key = *customize_step[step_nr].key;
8474 // check if key already used
8475 for (i = 0; i < step_nr; i++)
8476 if (*customize_step[i].key == key)
8481 // got new key binding
8482 *customize_step[step_nr].key = key;
8483 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8485 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8486 getKeyNameFromKey(key), font_nr_new);
8489 // un-highlight last query
8490 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8491 customize_step[step_nr - 1].text, FONT_MENU_1);
8492 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8493 "Key:", FONT_MENU_1);
8495 // all keys configured
8504 // query next key binding
8505 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8506 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8507 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8508 "Key:", FONT_INPUT_1_ACTIVE);
8509 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8510 getKeyNameFromKey(*customize_step[step_nr].key),
8515 case EVENT_KEYRELEASE:
8516 key_joystick_mapping = 0;
8520 HandleOtherEvents(&event);
8524 // do not handle events for longer than standard frame delay period
8525 if (DelayReached(&event_frame_delay))
8532 // write new key bindings back to player setup, if successfully finished
8534 setup.input[player_nr].key = custom_key;
8539 void CustomizeKeyboard(int player_nr)
8541 boolean success = CustomizeKeyboardMain(player_nr);
8545 int font_nr = FONT_TITLE_1;
8546 int font_height = getFontHeight(font_nr);
8547 int ypos1 = SYSIZE / 2 - font_height * 2;
8548 int ypos2 = SYSIZE / 2 - font_height * 1;
8549 DelayCounter wait_frame_delay = { 2000 };
8551 ResetDelayCounter(&wait_frame_delay);
8555 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8556 DrawTextSCentered(ypos2, font_nr, "configured!");
8558 while (!DelayReached(&wait_frame_delay))
8564 DrawSetupScreen_Input();
8567 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8569 #define MARKER_BUTTON 1
8570 #define MARKER_AXIS_X 2
8571 #define MARKER_AXIS_Y 3
8573 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8575 static boolean bitmaps_initialized = FALSE;
8576 boolean screen_initialized = FALSE;
8577 static Bitmap *controller, *button, *axis_x, *axis_y;
8579 boolean success = TRUE;
8580 boolean done = FALSE, next = FALSE;
8582 int alpha = 200, alpha_step = -1;
8583 int alpha_ticks = 0;
8584 char mapping[4096], temp[256];
8585 int font_name = MENU_SETUP_FONT_TITLE;
8586 int font_info = MENU_SETUP_FONT_TEXT;
8587 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8588 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8589 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8590 int ystep_name = getMenuTextStep(spacing_name, font_name);
8591 int ystep_line = getMenuTextStep(spacing_line, font_info);
8592 int ystep_para = getMenuTextStep(spacing_para, font_info);
8600 int axis, button, hat, hat_value;
8603 *step, *prev_step, steps[] =
8605 { 356, 155, MARKER_BUTTON, "a", },
8606 { 396, 122, MARKER_BUTTON, "b", },
8607 { 320, 125, MARKER_BUTTON, "x", },
8608 { 358, 95, MARKER_BUTTON, "y", },
8609 { 162, 125, MARKER_BUTTON, "back", },
8610 { 216, 125, MARKER_BUTTON, "guide", },
8611 { 271, 125, MARKER_BUTTON, "start", },
8612 { 110, 200, MARKER_BUTTON, "dpleft", },
8613 { 146, 228, MARKER_BUTTON, "dpdown", },
8614 { 178, 200, MARKER_BUTTON, "dpright", },
8615 { 146, 172, MARKER_BUTTON, "dpup", },
8616 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8617 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8618 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8619 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8620 { 73, 141, MARKER_BUTTON, "leftstick", },
8621 { 282, 210, MARKER_BUTTON, "rightstick", },
8622 { 73, 141, MARKER_AXIS_X, "leftx", },
8623 { 73, 141, MARKER_AXIS_Y, "lefty", },
8624 { 282, 210, MARKER_AXIS_X, "rightx", },
8625 { 282, 210, MARKER_AXIS_Y, "righty", },
8628 if (!bitmaps_initialized)
8630 controller = LoadCustomImage("joystick/controller.png");
8631 button = LoadCustomImage("joystick/button.png");
8632 axis_x = LoadCustomImage("joystick/axis_x.png");
8633 axis_y = LoadCustomImage("joystick/axis_y.png");
8635 bitmaps_initialized = TRUE;
8638 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8641 // print info about the joystick we are watching
8642 Debug("joystick", "watching joystick %d: (%s)",
8643 SDL_JoystickInstanceID(joystick), name);
8644 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8645 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8646 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8649 // initialize mapping with GUID and name
8650 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8652 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8653 temp, name, SDL_GetPlatform());
8655 // loop through all steps (buttons and axes), getting joystick events
8656 for (i = 0; i < SDL_arraysize(steps) && !done;)
8658 Bitmap *marker = button; // initialize with reliable default value
8661 strcpy(step->mapping, mapping);
8665 step->hat_value = -1;
8667 marker = (step->marker == MARKER_BUTTON ? button :
8668 step->marker == MARKER_AXIS_X ? axis_x :
8669 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8673 while (!done && !next)
8675 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8676 alpha_ticks = SDL_GetTicks();
8683 else if (alpha < 128)
8689 int controller_x = SX + (SXSIZE - controller->width) / 2;
8690 int controller_y = SY + ystep_line;
8692 int marker_x = controller_x + step->x;
8693 int marker_y = controller_y + step->y;
8695 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8696 int ystart2 = ystart1 + ystep_name + ystep_line;
8700 DrawTextSCentered(ystart1, font_name, name);
8702 DrawTextSCentered(ystart2, font_info,
8703 "Press buttons and move axes on");
8704 ystart2 += ystep_line;
8705 DrawTextSCentered(ystart2, font_info,
8706 "your controller when indicated.");
8707 ystart2 += ystep_line;
8708 DrawTextSCentered(ystart2, font_info,
8709 "(Your controller may look different.)");
8710 ystart2 += ystep_para;
8712 #if defined(PLATFORM_ANDROID)
8713 DrawTextSCentered(ystart2, font_info,
8714 "To correct a mistake,");
8715 ystart2 += ystep_line;
8716 DrawTextSCentered(ystart2, font_info,
8717 "press the 'back' button.");
8718 ystart2 += ystep_line;
8719 DrawTextSCentered(ystart2, font_info,
8720 "To skip a button or axis,");
8721 ystart2 += ystep_line;
8722 DrawTextSCentered(ystart2, font_info,
8723 "press the 'menu' button.");
8725 DrawTextSCentered(ystart2, font_info,
8726 "To correct a mistake,");
8727 ystart2 += ystep_line;
8728 DrawTextSCentered(ystart2, font_info,
8729 "press the 'backspace' key.");
8730 ystart2 += ystep_line;
8731 DrawTextSCentered(ystart2, font_info,
8732 "To skip a button or axis,");
8733 ystart2 += ystep_line;
8734 DrawTextSCentered(ystart2, font_info,
8735 "press the 'return' key.");
8736 ystart2 += ystep_line;
8737 DrawTextSCentered(ystart2, font_info,
8738 "To exit, press the 'escape' key.");
8741 BlitBitmapMasked(controller, drawto, 0, 0,
8742 controller->width, controller->height,
8743 controller_x, controller_y);
8745 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8746 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8748 BlitBitmapMasked(marker, drawto, 0, 0,
8749 marker->width, marker->height,
8750 marker_x, marker_y);
8752 if (!screen_initialized)
8753 FadeIn(REDRAW_FIELD);
8757 screen_initialized = TRUE;
8759 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8761 // reset frame delay counter directly after updating screen
8762 ResetDelayCounter(&event_frame_delay);
8764 while (NextValidEvent(&event))
8768 case SDL_JOYAXISMOTION:
8769 if (event.jaxis.value > 20000 ||
8770 event.jaxis.value < -20000)
8772 for (j = 0; j < i; j++)
8773 if (steps[j].axis == event.jaxis.axis)
8778 if (step->marker != MARKER_AXIS_X &&
8779 step->marker != MARKER_AXIS_Y)
8782 step->axis = event.jaxis.axis;
8783 strcat(mapping, step->field);
8784 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8785 strcat(mapping, temp);
8793 case SDL_JOYHATMOTION:
8794 // ignore centering; we're probably just coming back
8795 // to the center from the previous item we set
8796 if (event.jhat.value == SDL_HAT_CENTERED)
8799 for (j = 0; j < i; j++)
8800 if (steps[j].hat == event.jhat.hat &&
8801 steps[j].hat_value == event.jhat.value)
8806 step->hat = event.jhat.hat;
8807 step->hat_value = event.jhat.value;
8808 strcat(mapping, step->field);
8809 snprintf(temp, sizeof(temp), ":h%u.%u,",
8810 event.jhat.hat, event.jhat.value );
8811 strcat(mapping, temp);
8818 case SDL_JOYBALLMOTION:
8821 case SDL_JOYBUTTONUP:
8822 for (j = 0; j < i; j++)
8823 if (steps[j].button == event.jbutton.button)
8828 step->button = event.jbutton.button;
8829 strcat(mapping, step->field);
8830 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8831 strcat(mapping, temp);
8838 case SDL_FINGERDOWN:
8839 case SDL_MOUSEBUTTONDOWN:
8847 if (event.key.keysym.sym == KSYM_BackSpace ||
8848 event.key.keysym.sym == KSYM_Back)
8860 prev_step = &steps[i - 1];
8861 strcpy(mapping, prev_step->mapping);
8868 if (event.key.keysym.sym == KSYM_space ||
8869 event.key.keysym.sym == KSYM_Return ||
8870 event.key.keysym.sym == KSYM_Menu)
8879 if (event.key.keysym.sym == KSYM_Escape)
8889 program.exit_function(0);
8896 // do not handle events for longer than standard frame delay period
8897 if (DelayReached(&event_frame_delay))
8906 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8909 // activate mapping for this game
8910 SDL_GameControllerAddMapping(mapping);
8912 // save mapping to personal mappings
8913 SaveSetup_AddGameControllerMapping(mapping);
8916 // wait until the last pending event was removed from event queue
8917 while (NextValidEvent(&event));
8922 static int ConfigureJoystickMain(int player_nr)
8924 char *device_name = setup.input[player_nr].joy.device_name;
8925 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8926 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8927 int success = FALSE;
8930 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8931 return JOYSTICK_NOT_AVAILABLE;
8933 if (!joystick_active || !setup.input[player_nr].use_joystick)
8934 return JOYSTICK_NOT_AVAILABLE;
8937 FadeOut(REDRAW_FIELD);
8939 // close all joystick devices (potentially opened as game controllers)
8940 for (i = 0; i < SDL_NumJoysticks(); i++)
8941 SDLCloseJoystick(i);
8943 // open joystick device as plain joystick to configure as game controller
8944 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8946 // as the joystick was successfully opened before, this should not happen
8947 if (joystick == NULL)
8950 // create new game controller mapping (buttons and axes) for joystick device
8951 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8953 // close joystick (and maybe re-open as configured game controller later)
8954 SDL_JoystickClose(joystick);
8956 // re-open all joystick devices (potentially as game controllers)
8957 for (i = 0; i < SDL_NumJoysticks(); i++)
8960 // clear all joystick input actions for all joystick devices
8961 SDLClearJoystickState();
8963 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8966 void ConfigureJoystick(int player_nr)
8968 boolean state = ConfigureJoystickMain(player_nr);
8970 if (state != JOYSTICK_NOT_CONFIGURED)
8972 boolean success = (state == JOYSTICK_CONFIGURED);
8973 char message1[MAX_OUTPUT_LINESIZE + 1];
8974 char *message2 = (success ? "configured!" : "not available!");
8975 char *device_name = setup.input[player_nr].joy.device_name;
8976 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8977 int font_nr = FONT_TITLE_1;
8978 int font_height = getFontHeight(font_nr);
8979 int ypos1 = SYSIZE / 2 - font_height * 2;
8980 int ypos2 = SYSIZE / 2 - font_height * 1;
8981 DelayCounter wait_frame_delay = { 2000 };
8983 ResetDelayCounter(&wait_frame_delay);
8987 sprintf(message1, "Joystick %d", nr);
8989 DrawTextSCentered(ypos1, font_nr, message1);
8990 DrawTextSCentered(ypos2, font_nr, message2);
8992 while (!DelayReached(&wait_frame_delay))
8998 DrawSetupScreen_Input();
9001 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9003 if (y < video.screen_height / 3)
9005 // remap touch gadgets to access upper part of the screen
9006 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9007 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9009 else if (y > 2 * video.screen_height / 3)
9011 // remap touch gadgets to access lower part of the screen
9012 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9013 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9017 static boolean ConfigureVirtualButtonsMain(void)
9019 static char *customize_step_text[] =
9028 char grid_button[] =
9030 CHAR_GRID_BUTTON_LEFT,
9031 CHAR_GRID_BUTTON_RIGHT,
9032 CHAR_GRID_BUTTON_UP,
9033 CHAR_GRID_BUTTON_DOWN,
9034 CHAR_GRID_BUTTON_SNAP,
9035 CHAR_GRID_BUTTON_DROP
9044 int font_nr = FONT_INPUT_1_ACTIVE;
9045 int font_height = getFontHeight(font_nr);
9046 int ypos1 = SYSIZE / 2 - font_height * 2;
9047 int ypos2 = SYSIZE / 2 - font_height * 1;
9048 boolean success = FALSE;
9049 boolean finished = FALSE;
9051 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9052 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9053 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9054 boolean set_grid_button = FALSE;
9055 int nr = GRID_ACTIVE_NR();
9058 for (x = 0; x < MAX_GRID_XSIZE; x++)
9059 for (y = 0; y < MAX_GRID_YSIZE; y++)
9060 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9062 overlay.grid_button_highlight = grid_button[step_nr];
9067 FadeOut(REDRAW_FIELD);
9071 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9072 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9073 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9075 FadeIn(REDRAW_FIELD);
9077 SetOverlayShowGrid(TRUE);
9079 // map gadgets for setup touch buttons menu screen
9080 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9086 while (NextValidEvent(&event))
9088 int action = ACTION_NONE;
9090 // ---------- handle events and set the resulting action ----------
9096 UserEvent *user = (UserEvent *)&event;
9097 int id = user->value1;
9099 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9100 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9101 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9102 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9107 case EVENT_KEYPRESS:
9109 Key key = GetEventKey((KeyEvent *)&event);
9111 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9112 key == KSYM_BackSpace ||
9113 key == KSYM_Back ? ACTION_BACK :
9114 key == KSYM_Return ||
9116 key == KSYM_space ? ACTION_NEXT :
9121 case EVENT_KEYRELEASE:
9122 key_joystick_mapping = 0;
9125 case EVENT_BUTTONPRESS:
9126 case EVENT_BUTTONRELEASE:
9128 ButtonEvent *button = (ButtonEvent *)&event;
9130 motion_status = FALSE;
9132 if (button->type == EVENT_BUTTONPRESS)
9133 button_status = button->button;
9135 button_status = MB_RELEASED;
9137 if (HandleGadgets(button->x, button->y, button_status))
9139 // do not handle this button event anymore
9143 button->x += video.screen_xoffset;
9144 button->y += video.screen_yoffset;
9146 x = button->x * overlay.grid_xsize / video.screen_width;
9147 y = button->y * overlay.grid_ysize / video.screen_height;
9149 if (button->type == EVENT_BUTTONPRESS)
9152 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9153 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9155 set_grid_button = TRUE;
9158 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9162 case EVENT_MOTIONNOTIFY:
9164 MotionEvent *motion = (MotionEvent *)&event;
9166 motion_status = TRUE;
9168 if (HandleGadgets(motion->x, motion->y, button_status))
9170 // do not handle this button event anymore
9174 motion->x += video.screen_xoffset;
9175 motion->y += video.screen_yoffset;
9177 x = motion->x * overlay.grid_xsize / video.screen_width;
9178 y = motion->y * overlay.grid_ysize / video.screen_height;
9180 set_grid_button = TRUE;
9182 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9186 case SDL_WINDOWEVENT:
9187 HandleWindowEvent((WindowEvent *) &event);
9189 // check if device has been rotated
9190 if (nr != GRID_ACTIVE_NR())
9192 nr = GRID_ACTIVE_NR();
9194 for (x = 0; x < MAX_GRID_XSIZE; x++)
9195 for (y = 0; y < MAX_GRID_YSIZE; y++)
9196 grid_button_old[x][y] = grid_button_tmp[x][y] =
9197 overlay.grid_button[x][y];
9202 case SDL_APP_WILLENTERBACKGROUND:
9203 case SDL_APP_DIDENTERBACKGROUND:
9204 case SDL_APP_WILLENTERFOREGROUND:
9205 case SDL_APP_DIDENTERFOREGROUND:
9206 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9210 HandleOtherEvents(&event);
9214 // ---------- perform action set by handling events ----------
9216 if (action == ACTION_ESCAPE)
9218 // abort and restore the old key bindings
9220 for (x = 0; x < MAX_GRID_XSIZE; x++)
9221 for (y = 0; y < MAX_GRID_YSIZE; y++)
9222 overlay.grid_button[x][y] = grid_button_old[x][y];
9224 FadeSkipNextFadeIn();
9228 else if (action == ACTION_BACK)
9230 // keep the configured key bindings and go to previous page
9236 FadeSkipNextFadeIn();
9241 else if (action == ACTION_NEXT)
9243 // keep the configured key bindings and go to next page
9247 // all virtual buttons configured
9255 if (action != ACTION_NONE && !finished)
9257 for (x = 0; x < MAX_GRID_XSIZE; x++)
9258 for (y = 0; y < MAX_GRID_YSIZE; y++)
9259 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9261 overlay.grid_button_highlight = grid_button[step_nr];
9263 // configure next virtual button
9267 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9268 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9269 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9272 if (set_grid_button)
9274 overlay.grid_button[x][y] =
9275 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9276 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9277 grid_button_tmp[x][y]);
9279 set_grid_button = FALSE;
9286 for (x = 0; x < MAX_GRID_XSIZE; x++)
9287 for (y = 0; y < MAX_GRID_YSIZE; y++)
9288 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9290 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9292 SetOverlayShowGrid(FALSE);
9297 void ConfigureVirtualButtons(void)
9299 boolean success = ConfigureVirtualButtonsMain();
9301 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9302 SCREEN_MASK_TOUCH2);
9306 int font_nr = FONT_TITLE_1;
9307 int font_height = getFontHeight(font_nr);
9308 int ypos1 = SYSIZE / 2 - font_height * 2;
9309 int ypos2 = SYSIZE / 2 - font_height * 1;
9310 DelayCounter wait_frame_delay = { 2000 };
9312 ResetDelayCounter(&wait_frame_delay);
9316 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9317 DrawTextSCentered(ypos2, font_nr, "configured!");
9319 while (!DelayReached(&wait_frame_delay))
9326 void DrawSetupScreen(void)
9331 if (setup_mode == SETUP_MODE_INPUT)
9332 DrawSetupScreen_Input();
9333 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9334 DrawChooseTree(&scores_type_current);
9335 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9336 DrawChooseTree(&game_speed_current);
9337 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9338 DrawChooseTree(&scroll_delay_current);
9339 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9340 DrawChooseTree(&snapshot_mode_current);
9341 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9342 DrawChooseTree(&window_size_current);
9343 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9344 DrawChooseTree(&scaling_type_current);
9345 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9346 DrawChooseTree(&rendering_mode_current);
9347 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9348 DrawChooseTree(&vsync_mode_current);
9349 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9350 DrawChooseTree(&artwork.gfx_current);
9351 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9352 DrawChooseTree(&artwork.snd_current);
9353 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9354 DrawChooseTree(&artwork.mus_current);
9355 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9356 DrawChooseTree(&volume_simple_current);
9357 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9358 DrawChooseTree(&volume_loops_current);
9359 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9360 DrawChooseTree(&volume_music_current);
9361 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9362 DrawChooseTree(&touch_control_current);
9363 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9364 DrawChooseTree(&move_distance_current);
9365 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9366 DrawChooseTree(&drop_distance_current);
9367 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9368 DrawChooseTree(&transparency_current);
9369 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9370 DrawChooseTree(&grid_size_current[0][0]);
9371 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9372 DrawChooseTree(&grid_size_current[0][1]);
9373 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9374 DrawChooseTree(&grid_size_current[1][0]);
9375 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9376 DrawChooseTree(&grid_size_current[1][1]);
9378 DrawSetupScreen_Generic();
9380 PlayMenuSoundsAndMusic();
9383 void RedrawSetupScreenAfterFullscreenToggle(void)
9385 if (setup_mode == SETUP_MODE_GRAPHICS ||
9386 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9388 // update list selection from "setup.window_scaling_percent"
9389 execSetupGraphics_setWindowSizes(TRUE);
9395 void RedrawSetupScreenAfterScreenRotation(int nr)
9399 if (setup_mode == SETUP_MODE_TOUCH)
9401 // update virtual button settings (depending on screen orientation)
9404 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9406 // save already configured virtual buttons
9407 for (x = 0; x < MAX_GRID_XSIZE; x++)
9408 for (y = 0; y < MAX_GRID_YSIZE; y++)
9409 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9413 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9415 if (setup_mode == SETUP_MODE_INPUT)
9416 HandleSetupScreen_Input(mx, my, dx, dy, button);
9417 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9418 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9419 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9420 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9421 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9422 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9423 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9424 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9425 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9426 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9427 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9428 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9429 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9430 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9431 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9432 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9433 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9434 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9435 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9436 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9437 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9438 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9439 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9440 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9441 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9442 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9443 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9444 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9445 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9446 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9447 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9448 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9449 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9450 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9451 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9452 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9453 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9454 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9455 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9456 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9457 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9458 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9459 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9460 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9462 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9465 void HandleGameActions(void)
9467 if (setup.ask_on_game_over)
9470 if (game.restart_game_message != NULL)
9472 RequestRestartGame(game.restart_game_message);
9477 if (game_status != GAME_MODE_PLAYING)
9480 GameActions(); // main game loop
9482 if (tape.auto_play && !tape.playing)
9483 AutoPlayTapesContinue(); // continue automatically playing next tape
9487 // ---------- new screen button stuff --------------------------------------
9491 int gfx_unpressed, gfx_pressed;
9492 struct MenuPosInfo *pos;
9493 boolean *check_value;
9496 unsigned int event_mask;
9497 boolean is_touch_button;
9499 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9502 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9503 &menu.main.button.prev_level, NULL,
9504 SCREEN_CTRL_ID_PREV_LEVEL,
9506 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9507 FALSE, "previous level"
9510 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9511 &menu.main.button.next_level, NULL,
9512 SCREEN_CTRL_ID_NEXT_LEVEL,
9514 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9518 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9519 &menu.scores.button.prev_level, NULL,
9520 SCREEN_CTRL_ID_PREV_LEVEL2,
9521 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9522 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9523 FALSE, "previous level"
9526 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9527 &menu.scores.button.next_level, NULL,
9528 SCREEN_CTRL_ID_NEXT_LEVEL2,
9529 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9530 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9534 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9535 &menu.scores.button.prev_score, NULL,
9536 SCREEN_CTRL_ID_PREV_SCORE,
9537 SCREEN_MASK_SCORES_INFO,
9538 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9539 FALSE, "previous score"
9542 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9543 &menu.scores.button.next_score, NULL,
9544 SCREEN_CTRL_ID_NEXT_SCORE,
9545 SCREEN_MASK_SCORES_INFO,
9546 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9550 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE,
9551 &menu.scores.button.play_tape, NULL,
9552 SCREEN_CTRL_ID_PLAY_TAPE,
9553 SCREEN_MASK_SCORES_INFO,
9558 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9559 &menu.main.button.first_level, NULL,
9560 SCREEN_CTRL_ID_FIRST_LEVEL,
9563 FALSE, "first level"
9566 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9567 &menu.main.button.last_level, NULL,
9568 SCREEN_CTRL_ID_LAST_LEVEL,
9574 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9575 &menu.main.button.level_number, NULL,
9576 SCREEN_CTRL_ID_LEVEL_NUMBER,
9579 FALSE, "level number"
9582 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9583 &menu.setup.button.prev_player, NULL,
9584 SCREEN_CTRL_ID_PREV_PLAYER,
9586 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9587 FALSE, "previous player"
9590 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9591 &menu.setup.button.next_player, NULL,
9592 SCREEN_CTRL_ID_NEXT_PLAYER,
9594 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9595 FALSE, "next player"
9598 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9599 &menu.main.button.insert_solution, NULL,
9600 SCREEN_CTRL_ID_INSERT_SOLUTION,
9601 SCREEN_MASK_MAIN_HAS_SOLUTION,
9603 FALSE, "insert solution tape"
9606 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9607 &menu.main.button.play_solution, NULL,
9608 SCREEN_CTRL_ID_PLAY_SOLUTION,
9609 SCREEN_MASK_MAIN_HAS_SOLUTION,
9611 FALSE, "play solution tape"
9614 IMG_MENU_BUTTON_LEVELSET_INFO, IMG_MENU_BUTTON_LEVELSET_INFO_ACTIVE,
9615 &menu.main.button.levelset_info, NULL,
9616 SCREEN_CTRL_ID_LEVELSET_INFO,
9617 SCREEN_MASK_MAIN_HAS_SET_INFO,
9619 FALSE, "show level set info"
9622 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9623 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9624 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9626 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9627 FALSE, "switch ECS/AGA chipset"
9630 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9631 &menu.setup.button.touch_back, NULL,
9632 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9635 TRUE, "previous page"
9638 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9639 &menu.setup.button.touch_next, NULL,
9640 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9646 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9647 &menu.setup.button.touch_back2, NULL,
9648 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9651 TRUE, "previous page"
9654 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9655 &menu.setup.button.touch_next2, NULL,
9656 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9665 int gfx_unpressed, gfx_pressed;
9669 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9672 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9673 -1, -1, // these values are not constant, but can change at runtime
9674 SCREEN_CTRL_ID_SCROLL_UP,
9678 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9679 -1, -1, // these values are not constant, but can change at runtime
9680 SCREEN_CTRL_ID_SCROLL_DOWN,
9687 int gfx_unpressed, gfx_pressed;
9693 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9696 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9697 -1, -1, // these values are not constant, but can change at runtime
9698 -1, -1, // these values are not constant, but can change at runtime
9699 GD_TYPE_SCROLLBAR_VERTICAL,
9700 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9701 "scroll level series vertically"
9713 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9716 IMG_SETUP_INPUT_TEXT,
9717 SCREEN_CTRL_ID_NETWORK_SERVER,
9718 -1, -1, // these values are not constant, but can change at runtime
9719 MAX_SETUP_TEXT_INPUT_LEN,
9720 network_server_hostname,
9721 "Network Server Hostname / IP"
9725 static void CreateScreenMenubuttons(void)
9727 struct GadgetInfo *gi;
9728 unsigned int event_mask;
9731 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9733 struct MenuPosInfo *pos = menubutton_info[i].pos;
9734 int screen_mask = menubutton_info[i].screen_mask;
9735 boolean is_touch_button = menubutton_info[i].is_touch_button;
9736 boolean is_check_button = menubutton_info[i].check_value != NULL;
9737 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9738 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9739 menubutton_info[i].gfx_unpressed);
9740 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9741 int gfx_unpressed, gfx_pressed;
9742 int x, y, width, height;
9743 int gd_x1, gd_x2, gd_y1, gd_y2;
9744 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9745 int id = menubutton_info[i].gadget_id;
9746 int type = GD_TYPE_NORMAL_BUTTON;
9747 boolean checked = FALSE;
9749 // do not use touch buttons if overlay touch buttons are disabled
9750 if (is_touch_button && !setup.touch.overlay_buttons)
9753 event_mask = menubutton_info[i].event_mask;
9755 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9756 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9758 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9759 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9761 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9762 gfx_pressed = menubutton_info[i].gfx_pressed;
9763 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9764 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9765 gd_x1 = graphic_info[gfx_unpressed].src_x;
9766 gd_y1 = graphic_info[gfx_unpressed].src_y;
9767 gd_x2 = graphic_info[gfx_pressed].src_x;
9768 gd_y2 = graphic_info[gfx_pressed].src_y;
9774 if (has_gfx_pressed)
9776 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9777 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9780 if (is_check_button)
9782 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9783 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9784 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9785 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9787 type = GD_TYPE_CHECK_BUTTON;
9788 checked = *menubutton_info[i].check_value;
9791 if (is_score_button)
9793 // if x/y set to -1, dynamically place buttons next to title text
9794 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9796 // special compatibility handling for "Snake Bite" graphics set
9797 if (strPrefix(leveldir_current->identifier, "snake_bite"))
9798 title_width = strlen(INFOTEXT_SCORE_ENTRY) * 32;
9800 // use "SX" here to center buttons (ignore horizontal draw offset)
9802 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9803 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9804 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9805 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9807 // use "mSY" here to place buttons (respect vertical draw offset)
9809 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
9810 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
9813 if (id == SCREEN_CTRL_ID_LEVELSET_INFO)
9815 if (pos->x == -1 && pos->y == -1)
9817 // use "SX" here to place button (ignore draw offsets)
9818 x = SX + SXSIZE - 2 * TILESIZE;
9819 y = SY + SYSIZE - 2 * TILESIZE;
9821 // special compatibility handling for "BD2K3" graphics set
9822 if (strPrefix(leveldir_current->identifier, "BD2K3"))
9823 x = SX + TILESIZE + MINI_TILESIZE;
9825 // special compatibility handling for "jue0" graphics set
9826 if (strPrefix(artwork.gfx_current_identifier, "jue0"))
9828 x = SX + SXSIZE - 4 * TILESIZE;
9829 y = SY + SYSIZE - 3 * TILESIZE;
9834 gi = CreateGadget(GDI_CUSTOM_ID, id,
9835 GDI_CUSTOM_TYPE_ID, i,
9836 GDI_IMAGE_ID, gfx_unpressed,
9837 GDI_INFO_TEXT, menubutton_info[i].infotext,
9843 GDI_STATE, GD_BUTTON_UNPRESSED,
9844 GDI_CHECKED, checked,
9845 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9846 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9847 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9848 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9849 GDI_DIRECT_DRAW, FALSE,
9850 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9851 GDI_EVENT_MASK, event_mask,
9852 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9856 Fail("cannot create gadget");
9858 screen_gadget[id] = gi;
9862 static void CreateScreenScrollbuttons(void)
9864 struct GadgetInfo *gi;
9865 unsigned int event_mask;
9868 // these values are not constant, but can change at runtime
9869 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9870 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9871 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9872 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9874 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9876 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9877 int gfx_unpressed, gfx_pressed;
9878 int x, y, width, height;
9879 int gd_x1, gd_x2, gd_y1, gd_y2;
9880 int id = scrollbutton_info[i].gadget_id;
9882 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9884 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9885 y = mSY + scrollbutton_info[i].y;
9886 width = SC_SCROLLBUTTON_XSIZE;
9887 height = SC_SCROLLBUTTON_YSIZE;
9889 // correct scrollbar position if placed outside menu (playfield) area
9890 if (x > SX + SC_SCROLL_UP_XPOS)
9891 x = SX + SC_SCROLL_UP_XPOS;
9893 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9894 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9895 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9897 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9898 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9899 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9900 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9901 gd_x1 = graphic_info[gfx_unpressed].src_x;
9902 gd_y1 = graphic_info[gfx_unpressed].src_y;
9903 gd_x2 = graphic_info[gfx_pressed].src_x;
9904 gd_y2 = graphic_info[gfx_pressed].src_y;
9906 gi = CreateGadget(GDI_CUSTOM_ID, id,
9907 GDI_CUSTOM_TYPE_ID, i,
9908 GDI_IMAGE_ID, gfx_unpressed,
9909 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9914 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9915 GDI_STATE, GD_BUTTON_UNPRESSED,
9916 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9917 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9918 GDI_DIRECT_DRAW, FALSE,
9919 GDI_EVENT_MASK, event_mask,
9920 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9924 Fail("cannot create gadget");
9926 screen_gadget[id] = gi;
9930 static void CreateScreenScrollbars(void)
9934 // these values are not constant, but can change at runtime
9935 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9936 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9937 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9938 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9940 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9942 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9943 int gfx_unpressed, gfx_pressed;
9944 int x, y, width, height;
9945 int gd_x1, gd_x2, gd_y1, gd_y2;
9946 struct GadgetInfo *gi;
9947 int items_max, items_visible, item_position;
9948 unsigned int event_mask;
9949 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9950 int id = scrollbar_info[i].gadget_id;
9952 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9954 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9955 y = mSY + scrollbar_info[i].y;
9956 width = scrollbar_info[i].width;
9957 height = scrollbar_info[i].height;
9959 // correct scrollbar position if placed outside menu (playfield) area
9960 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9961 x = SX + SC_SCROLL_VERTICAL_XPOS;
9963 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9964 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9966 items_max = num_page_entries;
9967 items_visible = num_page_entries;
9970 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9971 gfx_pressed = scrollbar_info[i].gfx_pressed;
9972 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9973 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9974 gd_x1 = graphic_info[gfx_unpressed].src_x;
9975 gd_y1 = graphic_info[gfx_unpressed].src_y;
9976 gd_x2 = graphic_info[gfx_pressed].src_x;
9977 gd_y2 = graphic_info[gfx_pressed].src_y;
9979 gi = CreateGadget(GDI_CUSTOM_ID, id,
9980 GDI_CUSTOM_TYPE_ID, i,
9981 GDI_IMAGE_ID, gfx_unpressed,
9982 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9987 GDI_TYPE, scrollbar_info[i].type,
9988 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9989 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9990 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9991 GDI_WHEEL_AREA_X, SX,
9992 GDI_WHEEL_AREA_Y, SY,
9993 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9994 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9995 GDI_STATE, GD_BUTTON_UNPRESSED,
9996 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9997 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9998 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9999 GDI_DIRECT_DRAW, FALSE,
10000 GDI_EVENT_MASK, event_mask,
10001 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10005 Fail("cannot create gadget");
10007 screen_gadget[id] = gi;
10011 static void CreateScreenTextInputGadgets(void)
10015 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10017 int graphic = textinput_info[i].graphic;
10018 struct GraphicInfo *gd = &graphic_info[graphic];
10019 int gd_x1 = gd->src_x;
10020 int gd_y1 = gd->src_y;
10021 int gd_x2 = gd->src_x + gd->active_xoffset;
10022 int gd_y2 = gd->src_y + gd->active_yoffset;
10023 struct GadgetInfo *gi;
10024 unsigned int event_mask;
10025 int id = textinput_info[i].gadget_id;
10026 int x = textinput_info[i].x;
10027 int y = textinput_info[i].y;
10029 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10031 gi = CreateGadget(GDI_CUSTOM_ID, id,
10032 GDI_CUSTOM_TYPE_ID, i,
10033 GDI_INFO_TEXT, textinput_info[i].infotext,
10036 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10037 GDI_TEXT_VALUE, textinput_info[i].value,
10038 GDI_TEXT_SIZE, textinput_info[i].size,
10039 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10040 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10041 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10042 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10043 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10044 GDI_DESIGN_WIDTH, gd->width,
10045 GDI_EVENT_MASK, event_mask,
10046 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10047 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10051 Fail("cannot create gadget");
10053 screen_gadget[id] = gi;
10057 void CreateScreenGadgets(void)
10059 CreateScreenMenubuttons();
10061 CreateScreenScrollbuttons();
10062 CreateScreenScrollbars();
10064 CreateScreenTextInputGadgets();
10067 void FreeScreenGadgets(void)
10071 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10072 FreeGadget(screen_gadget[i]);
10075 static void RedrawScreenMenuGadgets(int screen_mask)
10079 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10080 if (screen_mask & menubutton_info[i].screen_mask)
10081 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10084 static void MapScreenMenuGadgets(int screen_mask)
10088 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10089 if (screen_mask & menubutton_info[i].screen_mask)
10090 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10093 static void UnmapScreenMenuGadgets(int screen_mask)
10097 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10099 if (screen_mask & menubutton_info[i].screen_mask)
10101 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10103 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10104 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10105 screen_gadget[menubutton_info[i].gadget_id]->y,
10106 screen_gadget[menubutton_info[i].gadget_id]->width,
10107 screen_gadget[menubutton_info[i].gadget_id]->height);
10112 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10115 MapScreenMenuGadgets(screen_mask);
10117 UnmapScreenMenuGadgets(screen_mask);
10120 static void MapScreenGadgets(int num_entries)
10124 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10127 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10128 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10130 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10131 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10134 static void UnmapScreenGadgets()
10138 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10139 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10141 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10142 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10145 static void MapScreenTreeGadgets(TreeInfo *ti)
10147 MapScreenGadgets(numTreeInfoInGroup(ti));
10150 static void UnmapScreenTreeGadgets(void)
10152 UnmapScreenGadgets();
10155 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10157 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10158 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10159 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10160 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10162 if (pos_1->x == -1 && pos_1->y == -1)
10163 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10165 if (pos_2->x == -1 && pos_2->y == -1)
10166 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10169 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10171 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10172 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10174 // set gadget position dynamically, pre-defined or off-screen
10175 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10176 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10178 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10179 MapGadget(gi); // (needed if deactivated on last score page)
10182 static void HandleScreenGadgets(struct GadgetInfo *gi)
10184 int id = gi->custom_id;
10185 int button = gi->event.button;
10186 int step = (button == MB_LEFTBUTTON ? 1 :
10187 button == MB_MIDDLEBUTTON ? 5 :
10188 button == MB_RIGHTBUTTON ? 10 : 1);
10192 case SCREEN_CTRL_ID_PREV_LEVEL:
10193 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10196 case SCREEN_CTRL_ID_NEXT_LEVEL:
10197 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10200 case SCREEN_CTRL_ID_PREV_LEVEL2:
10201 HandleHallOfFame_SelectLevel(step, -1);
10204 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10205 HandleHallOfFame_SelectLevel(step, +1);
10208 case SCREEN_CTRL_ID_PREV_SCORE:
10209 HandleScoreInfo_SelectScore(step, -1);
10212 case SCREEN_CTRL_ID_NEXT_SCORE:
10213 HandleScoreInfo_SelectScore(step, +1);
10216 case SCREEN_CTRL_ID_PLAY_TAPE:
10217 HandleScoreInfo_PlayTape();
10220 case SCREEN_CTRL_ID_FIRST_LEVEL:
10221 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10224 case SCREEN_CTRL_ID_LAST_LEVEL:
10225 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10228 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10229 CloseDoor(DOOR_CLOSE_2);
10230 SetGameStatus(GAME_MODE_LEVELNR);
10231 DrawChooseLevelNr();
10234 case SCREEN_CTRL_ID_PREV_PLAYER:
10235 HandleSetupScreen_Input_Player(step, -1);
10238 case SCREEN_CTRL_ID_NEXT_PLAYER:
10239 HandleSetupScreen_Input_Player(step, +1);
10242 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10243 InsertSolutionTape();
10246 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10247 PlaySolutionTape();
10250 case SCREEN_CTRL_ID_LEVELSET_INFO:
10251 DrawInfoScreen_FromMainMenu(INFO_MODE_LEVELSET);
10254 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10255 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10259 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10260 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10261 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10262 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10263 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10266 case SCREEN_CTRL_ID_SCROLL_UP:
10267 if (game_status == GAME_MODE_NAMES)
10268 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10269 else if (game_status == GAME_MODE_LEVELS)
10270 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10271 else if (game_status == GAME_MODE_LEVELNR)
10272 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10273 else if (game_status == GAME_MODE_SETUP)
10274 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10275 else if (game_status == GAME_MODE_INFO)
10276 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10277 else if (game_status == GAME_MODE_SCORES)
10278 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10281 case SCREEN_CTRL_ID_SCROLL_DOWN:
10282 if (game_status == GAME_MODE_NAMES)
10283 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10284 else if (game_status == GAME_MODE_LEVELS)
10285 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10286 else if (game_status == GAME_MODE_LEVELNR)
10287 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10288 else if (game_status == GAME_MODE_SETUP)
10289 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10290 else if (game_status == GAME_MODE_INFO)
10291 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10292 else if (game_status == GAME_MODE_SCORES)
10293 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10296 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10297 if (game_status == GAME_MODE_NAMES)
10298 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10299 else if (game_status == GAME_MODE_LEVELS)
10300 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10301 else if (game_status == GAME_MODE_LEVELNR)
10302 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10303 else if (game_status == GAME_MODE_SETUP)
10304 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10305 else if (game_status == GAME_MODE_INFO)
10306 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10307 else if (game_status == GAME_MODE_SCORES)
10308 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10311 case SCREEN_CTRL_ID_NETWORK_SERVER:
10313 if (!strEqual(gi->textinput.value, ""))
10315 setString(&setup.network_server_hostname, gi->textinput.value);
10317 network.server_host = setup.network_server_hostname;
10321 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10323 network.server_host = NULL;
10326 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10327 network.server_host = NULL;
10329 execSetupGame_setNetworkServerText();
10341 void HandleScreenGadgetKeys(Key key)
10343 if (key == setup.shortcut.tape_play)
10344 HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
10347 void DumpScreenIdentifiers(void)
10351 Print("Active screen elements on current screen:\n");
10353 for (i = 0; main_controls[i].nr != -1; i++)
10355 struct MainControlInfo *mci = &main_controls[i];
10357 if (mci->button_graphic != -1)
10359 char *token = getTokenFromImageID(mci->button_graphic);
10361 Print("- '%s'\n", token);
10368 boolean DoScreenAction(int image_id)
10372 if (game_status != GAME_MODE_MAIN)
10375 for (i = 0; main_controls[i].nr != -1; i++)
10377 struct MainControlInfo *mci = &main_controls[i];
10378 struct MenuPosInfo *pos = mci->pos_button;
10380 if (mci->button_graphic == image_id)
10382 int x = mSX + pos->x;
10383 int y = mSY + pos->y;
10385 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10394 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10396 // get tree info node of newly added level or artwork set
10397 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10398 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10400 if (tree_node_new == NULL) // should not happen
10403 // if request dialog is active, do nothing
10404 if (game.request_active)
10407 if (game_status == GAME_MODE_MAIN &&
10408 tree_type == TREE_TYPE_LEVEL_DIR)
10410 // when adding new level set in main menu, select it as current level set
10412 // change current level set to newly added level set from zip file
10413 leveldir_current = tree_node_new;
10415 // change current level number to first level of newly added level set
10416 level_nr = leveldir_current->first_level;
10418 // redraw screen to reflect changed level set
10421 // save this level set and level number as last selected level set
10422 SaveLevelSetup_LastSeries();
10423 SaveLevelSetup_SeriesInfo();
10425 else if (game_status == GAME_MODE_LEVELS &&
10426 tree_type == TREE_TYPE_LEVEL_DIR)
10428 // when adding new level set in level set menu, set cursor and update screen
10430 leveldir_current = tree_node_new;
10432 DrawChooseTree(&leveldir_current);
10434 else if (game_status == GAME_MODE_SETUP)
10436 // when adding new artwork set in setup menu, set cursor and update screen
10438 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10439 tree_type == TREE_TYPE_GRAPHICS_DIR)
10441 artwork.gfx_current = tree_node_new;
10443 DrawChooseTree(&artwork.gfx_current);
10445 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10446 tree_type == TREE_TYPE_SOUNDS_DIR)
10448 artwork.snd_current = tree_node_new;
10450 DrawChooseTree(&artwork.snd_current);
10452 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10453 tree_type == TREE_TYPE_MUSIC_DIR)
10455 artwork.mus_current = tree_node_new;
10457 DrawChooseTree(&artwork.mus_current);
10462 static int UploadTapes(void)
10464 SetGameStatus(GAME_MODE_LOADING);
10466 FadeSetEnterScreen();
10467 FadeOut(REDRAW_ALL);
10469 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10471 FadeIn(REDRAW_ALL);
10473 DrawInitTextHead("Uploading tapes");
10475 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10476 global.autoplay_leveldir = "ALL";
10477 global.autoplay_all = TRUE;
10479 int num_tapes_uploaded = AutoPlayTapes();
10481 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10482 global.autoplay_leveldir = NULL;
10483 global.autoplay_all = FALSE;
10485 SetGameStatus(GAME_MODE_MAIN);
10489 return num_tapes_uploaded;
10492 static boolean OfferUploadTapes(void)
10494 if (!Request(setup.has_remaining_tapes ?
10495 "Upload missing tapes to the high score server now?" :
10496 "Upload all your tapes to the high score server now?", REQ_ASK))
10499 // when uploading tapes, make sure that high score server is enabled
10500 runtime.use_api_server = setup.use_api_server = TRUE;
10502 int num_tapes_uploaded = UploadTapes();
10505 if (num_tapes_uploaded < 0)
10507 num_tapes_uploaded = -num_tapes_uploaded - 1;
10509 if (num_tapes_uploaded == 0)
10510 sprintf(message, "Upload failed! No tapes uploaded!");
10511 else if (num_tapes_uploaded == 1)
10512 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10514 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10515 num_tapes_uploaded);
10517 Request(message, REQ_CONFIRM);
10519 // if uploading tapes failed, add tape upload entry to setup menu
10520 setup.provide_uploading_tapes = TRUE;
10521 setup.has_remaining_tapes = TRUE;
10523 SaveSetup_ServerSetup();
10528 if (num_tapes_uploaded == 0)
10529 sprintf(message, "No tapes uploaded!");
10530 else if (num_tapes_uploaded == 1)
10531 sprintf(message, "1 tape uploaded!");
10533 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10535 Request(message, REQ_CONFIRM);
10537 if (num_tapes_uploaded > 0)
10538 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10540 // after all tapes have been uploaded, remove entry from setup menu
10541 setup.provide_uploading_tapes = FALSE;
10542 setup.has_remaining_tapes = FALSE;
10544 SaveSetup_ServerSetup();
10549 static void CheckUploadTapes(void)
10551 if (!setup.ask_for_uploading_tapes)
10554 // after asking for uploading tapes, do not ask again
10555 setup.ask_for_uploading_tapes = FALSE;
10556 setup.ask_for_remaining_tapes = FALSE;
10558 if (directoryExists(getTapeDir(NULL)))
10560 boolean tapes_uploaded = OfferUploadTapes();
10562 if (!tapes_uploaded)
10564 Request(setup.has_remaining_tapes ?
10565 "You can upload missing tapes from the setup menu later!" :
10566 "You can upload your tapes from the setup menu later!",
10572 // if tapes directory does not exist yet, never offer uploading all tapes
10573 setup.provide_uploading_tapes = FALSE;
10576 SaveSetup_ServerSetup();
10579 static void UpgradePlayerUUID(void)
10581 ApiResetUUIDAsThread(getUUID());
10584 static void CheckUpgradePlayerUUID(void)
10586 if (setup.player_version > 1)
10589 UpgradePlayerUUID();
10592 void CheckApiServerTasks(void)
10594 // check if the player's UUID has to be upgraded
10595 CheckUpgradePlayerUUID();
10597 // check if there are any tapes to be uploaded
10598 CheckUploadTapes();