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_GAME_ENGINE_TYPE 21
72 #define SETUP_MODE_CHOOSE_BD_PALETTE_C64 22
73 #define SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV 23
74 #define SETUP_MODE_CHOOSE_BD_PALETTE_ATARI 24
75 #define SETUP_MODE_CHOOSE_BD_COLOR_TYPE 25
76 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 26
77 #define SETUP_MODE_CHOOSE_SCALING_TYPE 27
78 #define SETUP_MODE_CHOOSE_RENDERING 28
79 #define SETUP_MODE_CHOOSE_VSYNC 29
80 #define SETUP_MODE_CHOOSE_GRAPHICS 30
81 #define SETUP_MODE_CHOOSE_SOUNDS 31
82 #define SETUP_MODE_CHOOSE_MUSIC 32
83 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 33
84 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 34
85 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 35
86 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 36
87 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 37
88 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 38
89 #define SETUP_MODE_CHOOSE_TRANSPARENCY 39
90 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 40
91 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 41
92 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 42
93 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 43
94 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 44
96 #define MAX_SETUP_MODES 45
98 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
100 // info screen titles
101 #define STR_INFO_MAIN "Info Screen"
102 #define STR_INFO_TITLE "Title Screen"
103 #define STR_INFO_ELEMENTS "Game Elements"
104 #define STR_INFO_MUSIC "Music Info"
105 #define STR_INFO_CREDITS "Credits"
106 #define STR_INFO_PROGRAM "Program Info"
107 #define STR_INFO_VERSION "Version Info"
108 #define STR_INFO_LEVELSET "Level Set Info"
109 #define STR_INFO_EXIT "Exit"
111 // setup screen titles
112 #define STR_SETUP_MAIN "Setup"
113 #define STR_SETUP_GAME "Game & Menu"
114 #define STR_SETUP_ENGINES "Game Engines"
115 #define STR_SETUP_EDITOR "Editor"
116 #define STR_SETUP_GRAPHICS "Graphics"
117 #define STR_SETUP_SOUND "Sound & Music"
118 #define STR_SETUP_ARTWORK "Custom Artwork"
119 #define STR_SETUP_INPUT "Input Devices"
120 #define STR_SETUP_TOUCH "Touch Controls"
121 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
122 #define STR_SETUP_EXIT "Exit"
123 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
125 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
126 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
127 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
128 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
129 #define STR_SETUP_CHOOSE_GAME_ENGINE_TYPE "Game Engine"
130 #define STR_SETUP_CHOOSE_BD_PALETTE_C64 "Palette (C64)"
131 #define STR_SETUP_CHOOSE_BD_PALETTE_C64DTV "Palette (C64DTV)"
132 #define STR_SETUP_CHOOSE_BD_PALETTE_ATARI "Palette (Atari)"
133 #define STR_SETUP_CHOOSE_BD_COLOR_TYPE "Color Type"
134 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
135 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
136 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
137 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
138 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
139 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
140 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
141 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
142 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
143 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
144 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
145 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
146 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
147 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
148 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
150 // other screen text constants
151 #define STR_CHOOSE_TREE_EDIT "Edit"
152 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
153 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
155 #define TEXT_MAIN_MENU "Press any key or button for main menu"
156 #define TEXT_INFO_MENU "Press any key or button for info menu"
157 #define TEXT_NEXT_PAGE "Press any key or button for next page"
158 #define TEXT_NEXT_MENU (info_screens_from_main ? \
159 TEXT_MAIN_MENU : TEXT_INFO_MENU)
161 // for input setup functions
162 #define SETUPINPUT_SCREEN_POS_START 0
163 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
164 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
165 #define SETUPINPUT_SCREEN_POS_END 13
167 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
168 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
170 #define MAX_SETUP_TEXT_INPUT_LEN 28
172 // for various menu stuff
173 #define MENU_SCREEN_START_XPOS 1
174 #define MENU_SCREEN_START_YPOS 2
175 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
176 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
177 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
178 #define MENU_TITLE1_YPOS 8
179 #define MENU_TITLE2_YPOS 46
180 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
181 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
182 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
183 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
184 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
185 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
186 #define MENU_SCREEN_INFO_SPACE_MIDDLE (menu.middle_spacing_info[info_mode])
187 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
188 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
189 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
190 #define MENU_SCREEN_INFO_SPACE_LINE (menu.line_spacing_info[info_mode])
191 #define MENU_SCREEN_INFO_SPACE_EXTRA (menu.extra_spacing_info[info_mode])
192 #define MENU_SCREEN_INFO_TILE_SIZE_RAW (menu.tile_size_info[info_mode])
193 #define MENU_SCREEN_INFO_TILE_SIZE (MENU_SCREEN_INFO_TILE_SIZE_RAW > 0 ? \
194 MENU_SCREEN_INFO_TILE_SIZE_RAW : TILEY)
195 #define MENU_SCREEN_INFO_ENTRY_SIZE_RAW (menu.list_entry_size_info[info_mode])
196 #define MENU_SCREEN_INFO_ENTRY_SIZE (MAX(MENU_SCREEN_INFO_ENTRY_SIZE_RAW, \
197 MENU_SCREEN_INFO_TILE_SIZE))
198 #define MENU_SCREEN_INFO_YSTART MENU_SCREEN_INFO_SPACE_TOP
199 #define MENU_SCREEN_INFO_YSTEP (MENU_SCREEN_INFO_ENTRY_SIZE + \
200 MENU_SCREEN_INFO_SPACE_EXTRA)
201 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
202 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
203 MENU_SCREEN_INFO_YSTART - TILEY / 2)
204 #define MAX_INFO_ELEMENTS_IN_ARRAY 128
205 #define MAX_INFO_ELEMENTS_ON_SCREEN (SYSIZE / TILEY)
206 #define MAX_INFO_ELEMENTS MIN(MAX_INFO_ELEMENTS_IN_ARRAY, \
207 MAX_INFO_ELEMENTS_ON_SCREEN)
208 #define STD_INFO_ELEMENTS_ON_SCREEN 10
209 #define DYN_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / MENU_SCREEN_INFO_YSTEP)
210 #define DEFAULT_INFO_ELEMENTS MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
211 DYN_INFO_ELEMENTS_ON_SCREEN)
212 #define NUM_INFO_ELEMENTS_FROM_CONF \
213 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
214 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
215 DEFAULT_INFO_ELEMENTS)
216 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(NUM_INFO_ELEMENTS_FROM_CONF, MAX_INFO_ELEMENTS)
217 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
218 #define MAX_MENU_TEXT_LENGTH_BIG 13
219 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
221 // screen gadget identifiers
222 #define SCREEN_CTRL_ID_PREV_LEVEL 0
223 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
224 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
225 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
226 #define SCREEN_CTRL_ID_PREV_SCORE 4
227 #define SCREEN_CTRL_ID_NEXT_SCORE 5
228 #define SCREEN_CTRL_ID_PLAY_TAPE 6
229 #define SCREEN_CTRL_ID_FIRST_LEVEL 7
230 #define SCREEN_CTRL_ID_LAST_LEVEL 8
231 #define SCREEN_CTRL_ID_LEVEL_NUMBER 9
232 #define SCREEN_CTRL_ID_PREV_PLAYER 10
233 #define SCREEN_CTRL_ID_NEXT_PLAYER 11
234 #define SCREEN_CTRL_ID_INSERT_SOLUTION 12
235 #define SCREEN_CTRL_ID_PLAY_SOLUTION 13
236 #define SCREEN_CTRL_ID_LEVELSET_INFO 14
237 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 15
238 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 16
239 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 17
240 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 18
241 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 19
243 #define NUM_SCREEN_MENUBUTTONS 20
245 #define SCREEN_CTRL_ID_SCROLL_UP 20
246 #define SCREEN_CTRL_ID_SCROLL_DOWN 21
247 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 22
248 #define SCREEN_CTRL_ID_NETWORK_SERVER 23
250 #define NUM_SCREEN_GADGETS 24
252 #define NUM_SCREEN_SCROLLBUTTONS 2
253 #define NUM_SCREEN_SCROLLBARS 1
254 #define NUM_SCREEN_TEXTINPUT 1
256 #define SCREEN_MASK_MAIN (1 << 0)
257 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
258 #define SCREEN_MASK_MAIN_HAS_SET_INFO (1 << 2)
259 #define SCREEN_MASK_INPUT (1 << 3)
260 #define SCREEN_MASK_TOUCH (1 << 4)
261 #define SCREEN_MASK_TOUCH2 (1 << 5)
262 #define SCREEN_MASK_SCORES (1 << 6)
263 #define SCREEN_MASK_SCORES_INFO (1 << 7)
265 // graphic position and size values for buttons and scrollbars
266 #define SC_MENUBUTTON_XSIZE TILEX
267 #define SC_MENUBUTTON_YSIZE TILEY
269 #define SC_SCROLLBUTTON_XSIZE TILEX
270 #define SC_SCROLLBUTTON_YSIZE TILEY
272 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
274 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
275 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
276 SC_SCROLLBUTTON_YSIZE)
278 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
279 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
281 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
282 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
283 SC_SCROLLBUTTON_YSIZE)
285 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
286 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
287 SC_SCROLL_VERTICAL_YSIZE)
289 #define SC_BORDER_SIZE 14
292 // forward declarations of internal functions
293 static void HandleScreenGadgets(struct GadgetInfo *);
294 static void HandleSetupScreen_Generic(int, int, int, int, int);
295 static void HandleSetupScreen_Input(int, int, int, int, int);
296 static void CustomizeKeyboard(int);
297 static void ConfigureJoystick(int);
298 static void ConfigureVirtualButtons(void);
299 static void execSetupGame(void);
300 static void execSetupEngines(void);
301 static void execSetupEditor(void);
302 static void execSetupGraphics(void);
303 static void execSetupSound(void);
304 static void execSetupTouch(void);
305 static void execSetupArtwork(void);
306 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
308 static void DrawChoosePlayerName(void);
309 static void DrawChooseLevelSet(void);
310 static void DrawChooseLevelNr(void);
311 static void DrawScoreInfo(int);
312 static void DrawScoreInfo_Content(int);
313 static void DrawInfoScreen(void);
314 static void DrawSetupScreen(void);
315 static void DrawTypeName(void);
317 static void DrawInfoScreen_NotAvailable(char *, char *);
318 static void DrawInfoScreen_HelpAnim(int, int, boolean);
319 static void DrawInfoScreen_HelpText(int, int, int, int);
320 static void HandleInfoScreen_Main(int, int, int, int, int);
321 static void HandleInfoScreen_TitleScreen(int, int, int);
322 static void HandleInfoScreen_Elements(int, int, int);
323 static void HandleInfoScreen_Music(int, int, int);
324 static void HandleInfoScreen_Version(int);
325 static void HandleInfoScreen_Generic(int, int, int);
327 static void ModifyGameSpeedIfNeeded(void);
328 static void DisableVsyncIfNeeded(void);
330 static void RedrawScreenMenuGadgets(int);
331 static void MapScreenMenuGadgets(int);
332 static void UnmapScreenMenuGadgets(int);
333 static void MapScreenGadgets(int);
334 static void UnmapScreenGadgets(void);
335 static void MapScreenTreeGadgets(TreeInfo *);
336 static void UnmapScreenTreeGadgets(void);
338 static void UpdateScreenMenuGadgets(int, boolean);
339 static void AdjustScoreInfoButtons_SelectScore(int, int, int);
340 static void AdjustScoreInfoButtons_PlayTape(int, int, boolean);
342 static boolean OfferUploadTapes(void);
343 static void execOfferUploadTapes(void);
345 static void DrawHallOfFame_setScoreEntries(void);
346 static void HandleHallOfFame_SelectLevel(int, int);
347 static char *getHallOfFameRankText(int, int);
348 static char *getHallOfFameScoreText(int, int);
349 static char *getInfoScreenTitle_Generic(void);
350 static int getInfoScreenBackgroundImage_Generic(void);
351 static int getInfoScreenBackgroundSound_Generic(void);
352 static int getInfoScreenBackgroundMusic_Generic(void);
354 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *);
356 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
358 static int info_mode = INFO_MODE_MAIN;
359 static int setup_mode = SETUP_MODE_MAIN;
361 static boolean info_screens_from_main = FALSE;
363 static TreeInfo *window_sizes = NULL;
364 static TreeInfo *window_size_current = NULL;
366 static TreeInfo *scaling_types = NULL;
367 static TreeInfo *scaling_type_current = NULL;
369 static TreeInfo *rendering_modes = NULL;
370 static TreeInfo *rendering_mode_current = NULL;
372 static TreeInfo *vsync_modes = NULL;
373 static TreeInfo *vsync_mode_current = NULL;
375 static TreeInfo *scroll_delays = NULL;
376 static TreeInfo *scroll_delay_current = NULL;
378 static TreeInfo *snapshot_modes = NULL;
379 static TreeInfo *snapshot_mode_current = NULL;
381 static TreeInfo *game_engine_types = NULL;
382 static TreeInfo *game_engine_type_current = NULL;
384 static TreeInfo *bd_palettes_c64 = NULL;
385 static TreeInfo *bd_palette_c64_current = NULL;
387 static TreeInfo *bd_palettes_c64dtv = NULL;
388 static TreeInfo *bd_palette_c64dtv_current = NULL;
390 static TreeInfo *bd_palettes_atari = NULL;
391 static TreeInfo *bd_palette_atari_current = NULL;
393 static TreeInfo *bd_color_types = NULL;
394 static TreeInfo *bd_color_type_current = NULL;
396 static TreeInfo *scores_types = NULL;
397 static TreeInfo *scores_type_current = NULL;
399 static TreeInfo *game_speeds_normal = NULL;
400 static TreeInfo *game_speeds_extended = NULL;
401 static TreeInfo *game_speeds = NULL;
402 static TreeInfo *game_speed_current = NULL;
404 static TreeInfo *volumes_simple = NULL;
405 static TreeInfo *volume_simple_current = NULL;
407 static TreeInfo *volumes_loops = NULL;
408 static TreeInfo *volume_loops_current = NULL;
410 static TreeInfo *volumes_music = NULL;
411 static TreeInfo *volume_music_current = NULL;
413 static TreeInfo *touch_controls = NULL;
414 static TreeInfo *touch_control_current = NULL;
416 static TreeInfo *move_distances = NULL;
417 static TreeInfo *move_distance_current = NULL;
419 static TreeInfo *drop_distances = NULL;
420 static TreeInfo *drop_distance_current = NULL;
422 static TreeInfo *transparencies = NULL;
423 static TreeInfo *transparency_current = NULL;
425 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
426 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
428 static TreeInfo *player_name = NULL;
429 static TreeInfo *player_name_current = NULL;
431 static TreeInfo *level_number = NULL;
432 static TreeInfo *level_number_current = NULL;
434 static TreeInfo *score_entries = NULL;
435 static TreeInfo *score_entry_current = NULL;
437 static struct ValueTextInfo window_sizes_list[] =
442 { 100, "100 % (Default)" },
455 static struct StringValueTextInfo scaling_types_list[] =
457 { SCALING_QUALITY_NEAREST, "Off" },
458 { SCALING_QUALITY_LINEAR, "Linear" },
459 { SCALING_QUALITY_BEST, "Anisotropic" },
464 static struct StringValueTextInfo rendering_modes_list[] =
466 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)"},
467 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
469 // this mode may work under certain conditions, but does not work on Windows
470 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
472 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
477 static struct StringValueTextInfo vsync_modes_list[] =
479 { STR_VSYNC_MODE_OFF, "Off" },
480 { STR_VSYNC_MODE_NORMAL, "Normal" },
481 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
486 static struct StringValueTextInfo scores_types_list[] =
488 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
489 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
490 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
495 static struct ValueTextInfo game_speeds_list_normal[] =
506 static struct ValueTextInfo game_speeds_list_extended[] =
508 { 1000, "1 fps (Extremely Slow)" },
513 { 29, "35 fps (Original Supaplex)" },
515 { 20, "50 fps (=== Normal Speed ===)" },
516 { 16, "60 fps (60 Hz VSync Speed)" },
517 { 14, "70 fps (Maximum Supaplex)" },
521 { 1, "1000 fps (Extremely Fast)" },
526 static struct ValueTextInfo *game_speeds_list;
528 static struct ValueTextInfo scroll_delays_list[] =
530 { 0, "0 Tiles (No Scroll Delay)" },
533 { 3, "3 Tiles (Default)" },
538 { 8, "8 Tiles (Maximum Scroll Delay)"},
543 static struct StringValueTextInfo snapshot_modes_list[] =
545 { STR_SNAPSHOT_MODE_OFF, "Off" },
546 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
547 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
548 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
553 static struct ValueTextInfo game_engine_types_list[] =
555 { GAME_ENGINE_TYPE_RND, "Rocks'n'Diamonds" },
556 { GAME_ENGINE_TYPE_BD, "Boulder Dash" },
557 { GAME_ENGINE_TYPE_EM, "Emerald Mine" },
558 { GAME_ENGINE_TYPE_SP, "Supaplex" },
559 { GAME_ENGINE_TYPE_MM, "Mirror Magic" },
564 static struct ValueTextInfo bd_palettes_c64_list[] =
566 { GD_PALETTE_C64_VICE_NEW, "Vice new" },
567 { GD_PALETTE_C64_VICE_OLD, "Vice old" },
568 { GD_PALETTE_C64_VIDE_DEFAULT, "Vice default" },
569 { GD_PALETTE_C64_C64HQ, "C64HQ" },
570 { GD_PALETTE_C64_C64S, "C64S" },
571 { GD_PALETTE_C64_CCS64, "CCS64" },
572 { GD_PALETTE_C64_FRODO, "Frodo" },
573 { GD_PALETTE_C64_GODOT, "GoDot" },
574 { GD_PALETTE_C64_PC64, "PC64" },
575 { GD_PALETTE_C64_RTADASH, "RTADash" },
580 static struct ValueTextInfo bd_palettes_c64dtv_list[] =
582 { GD_PALETTE_C64DTV_SPIFF, "Spiff" },
583 { GD_PALETTE_C64DTV_MURRAY, "Murray" },
588 static struct ValueTextInfo bd_palettes_atari_list[] =
590 { GD_PALETTE_ATARI_BUILTIN, "BuiltIn" },
591 { GD_PALETTE_ATARI_BUILTIN_CONTRAST, "BuiltIn contrast" },
592 { GD_PALETTE_ATARI_DEFAULT, "Default" },
593 { GD_PALETTE_ATARI_JAKUB, "Jakub" },
594 { GD_PALETTE_ATARI_JAKUB_CONTRAST, "Jakub contrast" },
595 { GD_PALETTE_ATARI_REAL, "Real" },
596 { GD_PALETTE_ATARI_REAL_CONTRAST, "Real contrast" },
597 { GD_PALETTE_ATARI_XFORMER, "XFormer" },
602 static struct ValueTextInfo bd_color_types_list[] =
604 { GD_COLOR_TYPE_RGB, "RGB colors" },
605 { GD_COLOR_TYPE_C64, "C64 colors" },
606 { GD_COLOR_TYPE_C64DTV, "C64DTV colors" },
607 { GD_COLOR_TYPE_ATARI, "Atari colors" },
612 static struct ValueTextInfo volumes_list[] =
632 static struct StringValueTextInfo touch_controls_list[] =
634 { TOUCH_CONTROL_OFF, "Off" },
635 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
636 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
637 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
642 static struct ValueTextInfo distances_list[] =
657 static struct ValueTextInfo transparencies_list[] =
659 { 0, "0 % (Opaque)" },
669 { 100, "100 % (Invisible)" },
674 static struct ValueTextInfo grid_sizes_list[] =
710 static int align_xoffset = 0;
711 static int align_yoffset = 0;
713 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
714 (s) <= GAME_MODE_SETUP ? (s) : \
715 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
717 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
718 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
720 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
721 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
722 (i) <= INFO_MODE_LEVELSET ? (i) : \
725 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
726 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
727 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
728 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
729 SETUP_MODE_CHOOSE_ARTWORK : \
730 SETUP_MODE_CHOOSE_OTHER)
732 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
733 menu.draw_xoffset[GAME_MODE_INFO] : \
734 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
735 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
736 menu.draw_yoffset[GAME_MODE_INFO] : \
737 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
738 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
739 menu.extra_spacing[GAME_MODE_INFO] : \
740 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
742 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
743 menu.draw_xoffset[GAME_MODE_SETUP] : \
744 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
745 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
746 menu.draw_yoffset[GAME_MODE_SETUP] : \
747 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
748 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
749 menu.extra_spacing[GAME_MODE_SETUP] : \
750 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
752 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
754 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
756 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? DRAW_XOFFSET_INFO(info_mode) : \
757 (s) == GAME_MODE_SETUP ? DRAW_XOFFSET_SETUP(setup_mode) : \
758 menu.draw_xoffset[DRAW_MODE(s)])
760 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? DRAW_YOFFSET_INFO(info_mode) : \
761 (s) == GAME_MODE_SETUP ? DRAW_YOFFSET_SETUP(setup_mode) : \
762 menu.draw_yoffset[DRAW_MODE(s)])
764 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? EXTRA_SPACING_INFO(info_mode) : \
765 (s) == GAME_MODE_SETUP ? EXTRA_SPACING_SETUP(setup_mode) : \
766 (s) == GAME_MODE_SCORES ? EXTRA_SPACING_SCORES(info_mode) : \
767 menu.extra_spacing[DRAW_MODE(s)])
769 #define mSX (SX + DRAW_XOFFSET(game_status))
770 #define mSY (SY + DRAW_YOFFSET(game_status))
772 #define amSX (mSX + align_xoffset)
773 #define amSY (mSY + align_yoffset)
775 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
776 menu.list_size[game_status] : \
777 MAX_MENU_ENTRIES_ON_SCREEN)
779 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, NUM_MENU_ENTRIES_ON_SCREEN)
782 // title display and control definitions
784 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + 2 * MAX_NUM_TITLE_MESSAGES)
786 #define NO_DIRECT_LEVEL_SELECT (-1)
789 static int num_title_screens = 0;
791 struct TitleControlInfo
800 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
803 // main menu display and control definitions
805 #define MAIN_CONTROL_NAME 0
806 #define MAIN_CONTROL_LEVELS 1
807 #define MAIN_CONTROL_SCORES 2
808 #define MAIN_CONTROL_EDITOR 3
809 #define MAIN_CONTROL_INFO 4
810 #define MAIN_CONTROL_GAME 5
811 #define MAIN_CONTROL_SETUP 6
812 #define MAIN_CONTROL_QUIT 7
813 #define MAIN_CONTROL_PREV_LEVEL 8
814 #define MAIN_CONTROL_NEXT_LEVEL 9
815 #define MAIN_CONTROL_FIRST_LEVEL 10
816 #define MAIN_CONTROL_LAST_LEVEL 11
817 #define MAIN_CONTROL_LEVEL_NUMBER 12
818 #define MAIN_CONTROL_LEVEL_INFO_1 13
819 #define MAIN_CONTROL_LEVEL_INFO_2 14
820 #define MAIN_CONTROL_LEVEL_NAME 15
821 #define MAIN_CONTROL_LEVEL_AUTHOR 16
822 #define MAIN_CONTROL_LEVEL_YEAR 17
823 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
824 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
825 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
826 #define MAIN_CONTROL_TITLE_1 21
827 #define MAIN_CONTROL_TITLE_2 22
828 #define MAIN_CONTROL_TITLE_3 23
830 static char str_main_text_name[10];
831 static char str_main_text_first_level[10];
832 static char str_main_text_last_level[10];
833 static char str_main_text_level_number[10];
835 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
837 static char *main_text_name = str_main_text_name;
838 static char *main_text_first_level = str_main_text_first_level;
839 static char *main_text_last_level = str_main_text_last_level;
840 static char *main_text_level_number = str_main_text_level_number;
841 static char *main_text_levels = "Levelset";
842 static char *main_text_scores = "Hall Of Fame";
843 static char *main_text_editor = "Level Creator";
844 static char *main_text_info = "Info Screen";
845 static char *main_text_game = "Start Game";
846 static char *main_text_setup = "Setup";
847 static char *main_text_quit = "Quit";
848 static char *main_text_level_name = level.name;
849 static char *main_text_level_author = level.author;
850 static char *main_text_level_year = NULL;
851 static char *main_text_level_imported_from = NULL;
852 static char *main_text_level_imported_by = NULL;
853 static char *main_text_level_tested_by = NULL;
854 static char *main_text_title_1 = NULL;
855 static char *main_text_title_2 = NULL;
856 static char *main_text_title_3 = NULL;
858 extern char debug_xsn_mode[];
860 struct MainControlInfo
864 struct MenuPosInfo *pos_button;
867 struct TextPosInfo *pos_text;
870 struct TextPosInfo *pos_input;
874 static struct MainControlInfo main_controls[] =
878 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
879 &menu.main.text.name, &main_text_name,
880 &menu.main.input.name, &setup.player_name,
884 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
885 &menu.main.text.levels, &main_text_levels,
890 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
891 &menu.main.text.scores, &main_text_scores,
896 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
897 &menu.main.text.editor, &main_text_editor,
902 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
903 &menu.main.text.info, &main_text_info,
908 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
909 &menu.main.text.game, &main_text_game,
914 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
915 &menu.main.text.setup, &main_text_setup,
920 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
921 &menu.main.text.quit, &main_text_quit,
925 MAIN_CONTROL_PREV_LEVEL,
931 MAIN_CONTROL_NEXT_LEVEL,
937 MAIN_CONTROL_FIRST_LEVEL,
939 &menu.main.text.first_level, &main_text_first_level,
943 MAIN_CONTROL_LAST_LEVEL,
945 &menu.main.text.last_level, &main_text_last_level,
949 MAIN_CONTROL_LEVEL_NUMBER,
951 &menu.main.text.level_number, &main_text_level_number,
955 MAIN_CONTROL_LEVEL_INFO_1,
957 &menu.main.text.level_info_1, NULL,
961 MAIN_CONTROL_LEVEL_INFO_2,
963 &menu.main.text.level_info_2, NULL,
967 MAIN_CONTROL_LEVEL_NAME,
969 &menu.main.text.level_name, &main_text_level_name,
973 MAIN_CONTROL_LEVEL_AUTHOR,
975 &menu.main.text.level_author, &main_text_level_author,
979 MAIN_CONTROL_LEVEL_YEAR,
981 &menu.main.text.level_year, &main_text_level_year,
985 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
987 &menu.main.text.level_imported_from, &main_text_level_imported_from,
991 MAIN_CONTROL_LEVEL_IMPORTED_BY,
993 &menu.main.text.level_imported_by, &main_text_level_imported_by,
997 MAIN_CONTROL_LEVEL_TESTED_BY,
999 &menu.main.text.level_tested_by, &main_text_level_tested_by,
1003 MAIN_CONTROL_TITLE_1,
1005 &menu.main.text.title_1, &main_text_title_1,
1009 MAIN_CONTROL_TITLE_2,
1011 &menu.main.text.title_2, &main_text_title_2,
1015 MAIN_CONTROL_TITLE_3,
1017 &menu.main.text.title_3, &main_text_title_3,
1030 static boolean hasLevelSetInfo(void)
1032 return (getLevelSetInfoFilename(0) != NULL);
1035 static int getTitleScreenGraphic(int nr, boolean initial)
1037 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
1040 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
1042 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
1046 static int getTitleScreenGameMode(boolean initial)
1048 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1052 static int getTitleMessageGameMode(boolean initial)
1054 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1057 static int getTitleAnimMode(struct TitleControlInfo *tci)
1059 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
1061 return base + tci->local_nr;
1065 static int getTitleScreenBackground(boolean initial)
1067 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
1072 static int getTitleMessageBackground(int nr, boolean initial)
1074 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
1078 static int getTitleBackground(int nr, boolean initial, boolean is_image)
1080 int base = (is_image ?
1081 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
1082 IMG_BACKGROUND_TITLESCREEN_1) :
1083 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1084 IMG_BACKGROUND_TITLEMESSAGE_1));
1085 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
1086 IMG_BACKGROUND_TITLE);
1087 int graphic_local = base + nr;
1089 if (graphic_info[graphic_local].bitmap != NULL)
1090 return graphic_local;
1092 if (graphic_info[graphic_global].bitmap != NULL)
1093 return graphic_global;
1095 return IMG_UNDEFINED;
1098 static int getTitleSound(struct TitleControlInfo *tci)
1100 boolean is_image = tci->is_image;
1101 int initial = tci->initial;
1102 int nr = tci->local_nr;
1103 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1104 int base = (is_image ?
1105 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
1106 SND_BACKGROUND_TITLESCREEN_1) :
1107 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1108 SND_BACKGROUND_TITLEMESSAGE_1));
1109 int sound_global = menu.sound[mode];
1110 int sound_local = base + nr;
1113 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
1114 nr, initial, is_image,
1115 sound_global, getSoundListEntry(sound_global)->filename,
1116 sound_local, getSoundListEntry(sound_local)->filename);
1119 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1122 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1123 return sound_global;
1125 return SND_UNDEFINED;
1128 static int getTitleMusic(struct TitleControlInfo *tci)
1130 boolean is_image = tci->is_image;
1131 int initial = tci->initial;
1132 int nr = tci->local_nr;
1133 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1134 int base = (is_image ?
1135 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1136 MUS_BACKGROUND_TITLESCREEN_1) :
1137 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1138 MUS_BACKGROUND_TITLEMESSAGE_1));
1139 int music_global = menu.music[mode];
1140 int music_local = base + nr;
1143 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1144 nr, initial, is_image,
1145 music_global, getMusicListEntry(music_global)->filename,
1146 music_local, getMusicListEntry(music_local)->filename);
1149 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1152 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1153 return music_global;
1155 return MUS_UNDEFINED;
1158 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1160 boolean is_image = tci->is_image;
1161 boolean initial = tci->initial;
1162 boolean first = tci->first;
1163 int nr = tci->local_nr;
1164 struct TitleMessageInfo tmi;
1165 struct TitleFadingInfo ti;
1167 tmi = (is_image ? (initial ? (first ?
1168 titlescreen_initial_first[nr] :
1169 titlescreen_initial[nr])
1171 titlescreen_first[nr] :
1173 : (initial ? (first ?
1174 titlemessage_initial_first[nr] :
1175 titlemessage_initial[nr])
1177 titlemessage_first[nr] :
1178 titlemessage[nr])));
1180 ti.fade_mode = tmi.fade_mode;
1181 ti.fade_delay = tmi.fade_delay;
1182 ti.post_delay = tmi.post_delay;
1183 ti.auto_delay = tmi.auto_delay;
1184 ti.auto_delay_unit = tmi.auto_delay_unit;
1189 static int compareTitleControlInfo(const void *object1, const void *object2)
1191 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1192 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1195 if (tci1->initial != tci2->initial)
1196 compare_result = (tci1->initial ? -1 : +1);
1197 else if (tci1->sort_priority != tci2->sort_priority)
1198 compare_result = tci1->sort_priority - tci2->sort_priority;
1199 else if (tci1->is_image != tci2->is_image)
1200 compare_result = (tci1->is_image ? -1 : +1);
1202 compare_result = tci1->local_nr - tci2->local_nr;
1204 return compare_result;
1207 static boolean CheckTitleScreen_BD(int nr, boolean initial)
1209 // only show BD style title screen for native BD level sets
1210 if (level.game_engine_type != GAME_ENGINE_TYPE_BD)
1213 // only show BD style title screen for first title screen of a level set
1214 if (initial || nr != 0)
1217 int graphic = getTitleScreenGraphic(nr, initial);
1218 Bitmap *bitmap = graphic_info[graphic].bitmap;
1220 // only show BD style title screen if no other title screen defined
1224 // check if BD style title screen defined
1225 return (GetTitleScreenBitmaps_BD() != NULL);
1228 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1230 int nr, int sort_priority)
1232 title_controls[num_title_screens].is_image = is_image;
1233 title_controls[num_title_screens].initial = initial;
1234 title_controls[num_title_screens].local_nr = nr;
1235 title_controls[num_title_screens].sort_priority = sort_priority;
1237 title_controls[num_title_screens].first = FALSE; // will be set later
1239 num_title_screens++;
1242 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1246 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1248 int graphic = getTitleScreenGraphic(i, initial);
1249 Bitmap *bitmap = graphic_info[graphic].bitmap;
1250 int sort_priority = graphic_info[graphic].sort_priority;
1251 boolean has_title_screen = (bitmap != NULL);
1253 // check for optional title screen of native BD style level set
1254 if (CheckTitleScreen_BD(i, initial))
1255 has_title_screen = TRUE;
1257 if (has_title_screen)
1258 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1261 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1263 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1264 char *filename = getLevelSetTitleMessageFilename(i, initial);
1265 int sort_priority = tmi->sort_priority;
1267 if (filename != NULL)
1268 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1272 static void InitializeTitleControls(boolean show_title_initial)
1274 num_title_screens = 0;
1276 // 1st step: initialize title screens for game start (only when starting)
1277 if (show_title_initial)
1278 InitializeTitleControls_CheckTitleInfo(TRUE);
1280 // 2nd step: initialize title screens for current level set
1281 InitializeTitleControls_CheckTitleInfo(FALSE);
1283 // sort title screens according to sort_priority and title number
1284 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1285 compareTitleControlInfo);
1287 // mark first title screen
1288 title_controls[0].first = TRUE;
1291 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1293 return (pos != NULL && pos->x != -1 && pos->y != -1);
1296 static boolean visibleTextPos(struct TextPosInfo *pos)
1298 return (pos != NULL && pos->x != -1 && pos->y != -1);
1301 static void InitializeMainControls(void)
1303 boolean local_team_mode = (!network.enabled && setup.team_mode);
1306 // set main control text values to dynamically determined values
1307 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1309 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1310 menu.main.text.first_level.size));
1311 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1312 menu.main.text.last_level.size));
1313 strcpy(main_text_level_number, int2str(level_nr,
1314 menu.main.text.level_number.size));
1316 main_text_level_year = leveldir_current->year;
1317 main_text_level_imported_from = leveldir_current->imported_from;
1318 main_text_level_imported_by = leveldir_current->imported_by;
1319 main_text_level_tested_by = leveldir_current->tested_by;
1321 main_text_title_1 = getConfigProgramTitleString();
1322 main_text_title_2 = getConfigProgramCopyrightString();
1323 main_text_title_3 = getConfigProgramCompanyString();
1325 // set main control screen positions to dynamically determined values
1326 for (i = 0; main_controls[i].nr != -1; i++)
1328 struct MainControlInfo *mci = &main_controls[i];
1330 struct MenuPosInfo *pos_button = mci->pos_button;
1331 struct TextPosInfo *pos_text = mci->pos_text;
1332 struct TextPosInfo *pos_input = mci->pos_input;
1333 char *text = (mci->text ? *mci->text : NULL);
1334 char *input = (mci->input ? *mci->input : NULL);
1335 int button_graphic = mci->button_graphic;
1336 int font_text = (pos_text ? pos_text->font : -1);
1337 int font_input = (pos_input ? pos_input->font : -1);
1339 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1340 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1341 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1342 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1343 int text_chars = (text != NULL ? strlen(text) : 0);
1344 int input_chars = (input != NULL ? strlen(input) : 0);
1347 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1349 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1350 int text_width = font_text_width * text_chars;
1351 int text_height = font_text_height;
1352 int input_width = font_input_width * input_chars;
1353 int input_height = font_input_height;
1355 if (nr == MAIN_CONTROL_NAME)
1357 menu.main.input.name.width = input_width;
1358 menu.main.input.name.height = input_height;
1361 if (pos_button != NULL) // (x/y may be -1/-1 here)
1363 pos_button->width = button_width;
1364 pos_button->height = button_height;
1367 if (pos_text != NULL) // (x/y may be -1/-1 here)
1369 // calculate text size -- needed for text alignment
1370 boolean calculate_text_size = (text != NULL);
1372 if (pos_text->width == -1 || calculate_text_size)
1373 pos_text->width = text_width;
1374 if (pos_text->height == -1 || calculate_text_size)
1375 pos_text->height = text_height;
1377 if (visibleMenuPos(pos_button))
1379 if (pos_text->x == -1)
1380 pos_text->x = pos_button->x + pos_button->width;
1381 if (pos_text->y == -1)
1383 pos_button->y + (pos_button->height - pos_text->height) / 2;
1387 if (pos_input != NULL) // (x/y may be -1/-1 here)
1389 if (visibleTextPos(pos_text))
1391 if (pos_input->x == -1)
1392 pos_input->x = pos_text->x + pos_text->width;
1393 if (pos_input->y == -1)
1394 pos_input->y = pos_text->y;
1397 if (pos_input->width == -1)
1398 pos_input->width = input_width;
1399 if (pos_input->height == -1)
1400 pos_input->height = input_height;
1405 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1406 int graphic, boolean pressed)
1408 struct GraphicInfo *g = &graphic_info[graphic];
1411 int xoffset = (pressed ? g->pressed_xoffset : 0);
1412 int yoffset = (pressed ? g->pressed_yoffset : 0);
1414 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1416 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1417 g->width, g->height, dst_x, dst_y);
1420 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1421 boolean active_input,
1422 boolean pressed_button)
1426 for (i = 0; main_controls[i].nr != -1; i++)
1428 struct MainControlInfo *mci = &main_controls[i];
1430 if (mci->nr == nr || nr == -1)
1432 struct MenuPosInfo *pos_button = mci->pos_button;
1433 struct TextPosInfo *pos_text = mci->pos_text;
1434 struct TextPosInfo *pos_input = mci->pos_input;
1435 char *text = (mci->text ? *mci->text : NULL);
1436 char *input = (mci->input ? *mci->input : NULL);
1437 int button_graphic = mci->button_graphic;
1438 int font_text = (pos_text ? pos_text->font : -1);
1439 int font_input = (pos_input ? pos_input->font : -1);
1443 button_graphic = BUTTON_ACTIVE(button_graphic);
1444 font_text = FONT_ACTIVE(font_text);
1449 font_input = FONT_ACTIVE(font_input);
1452 if (visibleMenuPos(pos_button))
1454 struct MenuPosInfo *pos = pos_button;
1455 int x = mSX + pos->x;
1456 int y = mSY + pos->y;
1458 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1459 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1462 if (visibleTextPos(pos_text) && text != NULL)
1464 struct TextPosInfo *pos = pos_text;
1465 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1466 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1469 // (check why/if this is needed)
1470 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1472 DrawText(x, y, text, font_text);
1475 if (visibleTextPos(pos_input) && input != NULL)
1477 struct TextPosInfo *pos = pos_input;
1478 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1479 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1482 // (check why/if this is needed)
1483 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1485 DrawText(x, y, input, font_input);
1491 static void DrawCursorAndText_Main(int nr, boolean active_text,
1492 boolean pressed_button)
1494 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1498 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1499 boolean pressed_button)
1501 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1505 static struct MainControlInfo *getMainControlInfo(int nr)
1509 for (i = 0; main_controls[i].nr != -1; i++)
1510 if (main_controls[i].nr == nr)
1511 return &main_controls[i];
1516 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1521 int rect_x = ALIGNED_TEXT_XPOS(rect);
1522 int rect_y = ALIGNED_TEXT_YPOS(rect);
1524 return (x >= rect_x && x < rect_x + rect->width &&
1525 y >= rect_y && y < rect_y + rect->height);
1528 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1533 int rect_x = ALIGNED_TEXT_XPOS(rect);
1534 int rect_y = ALIGNED_TEXT_YPOS(rect);
1537 Debug("screens:insideTextPosRect",
1538 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1539 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1540 (x >= rect_x && x < rect_x + rect->width &&
1541 y >= rect_y && y < rect_y + rect->height));
1544 return (x >= rect_x && x < rect_x + rect->width &&
1545 y >= rect_y && y < rect_y + rect->height);
1548 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1550 int rect_width = preview->xsize * preview->tile_size;
1551 int rect_height = preview->ysize * preview->tile_size;
1552 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1553 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1555 return (x >= rect_x && x < rect_x + rect_width &&
1556 y >= rect_y && y < rect_y + rect_height);
1559 static void AdjustScrollbar(int id, int items_max, int items_visible,
1562 struct GadgetInfo *gi = screen_gadget[id];
1564 if (item_position > items_max - items_visible)
1565 item_position = items_max - items_visible;
1567 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1568 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1569 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1572 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1574 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1578 static void clearMenuListArea(void)
1580 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1582 // correct scrollbar position if placed outside menu (playfield) area
1583 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1584 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1586 // clear menu list area, but not title or scrollbar
1587 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1588 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1590 // special compatibility handling for "Snake Bite" graphics set
1591 if (strPrefix(leveldir_current->identifier, "snake_bite"))
1592 ClearRectangle(drawto, mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1593 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1596 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1598 static int cursor_array[MAX_LEV_FIELDY];
1599 int x = amSX + TILEX * xpos;
1600 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1605 cursor_array[ypos] = graphic;
1607 graphic = cursor_array[ypos];
1611 graphic = BUTTON_ACTIVE(graphic);
1613 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1614 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1617 static void initCursor(int ypos, int graphic)
1619 drawCursorExt(0, ypos, FALSE, graphic);
1622 static void drawCursor(int ypos, boolean active)
1624 drawCursorExt(0, ypos, active, -1);
1627 static void drawCursorXY(int xpos, int ypos, int graphic)
1629 drawCursorExt(xpos, ypos, FALSE, graphic);
1632 static void drawChooseTreeCursor(int ypos, boolean active)
1634 drawCursorExt(0, ypos, active, -1);
1637 static int getChooseTreeEditFont(boolean active)
1639 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1642 static int getChooseTreeEditXPos(int pos)
1644 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1645 int xoffset = (has_scrollbar ? -1 : 0);
1646 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1647 int sx = amSX + xpos * TILEX;
1648 int font_nr = getChooseTreeEditFont(FALSE);
1649 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1651 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1654 static int getChooseTreeEditYPos(int ypos_raw)
1656 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1657 int sy = amSY + ypos * TILEY;
1662 static int getChooseTreeEditXPosReal(int pos)
1664 int xpos = getChooseTreeEditXPos(pos);
1665 int font_nr = getChooseTreeEditFont(FALSE);
1666 int font_xoffset = getFontDrawOffsetX(font_nr);
1668 return xpos + font_xoffset;
1671 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1673 int sx = getChooseTreeEditXPos(POS_LEFT);
1674 int sy = getChooseTreeEditYPos(ypos_raw);
1675 int font_nr = getChooseTreeEditFont(active);
1677 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1680 static void DrawInfoScreen_Headline(int screen_nr, int num_screens,
1681 int use_global_screens)
1683 char *info_text_title_1 = getInfoScreenTitle_Generic();
1684 char info_text_title_2[MAX_LINE_LEN + 1];
1686 if (num_screens > 1)
1688 sprintf(info_text_title_2, "Page %d of %d", screen_nr + 1, num_screens);
1692 char *text_format = (use_global_screens ? "for %s" : "for \"%s\"");
1693 int text_format_len = strlen(text_format) - strlen("%s");
1694 int max_text_len = SXSIZE / getFontWidth(FONT_TITLE_2);
1695 int max_name_len = max_text_len - text_format_len;
1696 char name_cut[max_name_len];
1697 char *name_full = (use_global_screens ? getProgramTitleString() :
1698 leveldir_current->name);
1700 snprintf(name_cut, max_name_len, "%s", name_full);
1701 snprintf(info_text_title_2, max_text_len, text_format, name_cut);
1704 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, info_text_title_1);
1705 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, info_text_title_2);
1708 static void DrawTitleScreenImage(int nr, boolean initial)
1710 static int frame_counter = 0;
1711 int graphic = getTitleScreenGraphic(nr, initial);
1712 Bitmap *bitmap = graphic_info[graphic].bitmap;
1713 Bitmap *bitmap_background = NULL;
1714 int draw_masked = graphic_info[graphic].draw_masked;
1715 int width = graphic_info[graphic].width;
1716 int height = graphic_info[graphic].height;
1717 int src_x = graphic_info[graphic].src_x;
1718 int src_y = graphic_info[graphic].src_y;
1721 // check for optional title screen of native BD style level set
1722 if (CheckTitleScreen_BD(nr, initial))
1724 Bitmap **title_screen_bitmaps = GetTitleScreenBitmaps_BD();
1726 bitmap = title_screen_bitmaps[0];
1727 bitmap_background = title_screen_bitmaps[1];
1731 width = bitmap->width;
1732 height = bitmap->height;
1741 if (width > WIN_XSIZE)
1743 // image width too large for window => center image horizontally
1744 src_x = (width - WIN_XSIZE) / 2;
1748 if (height > WIN_YSIZE)
1750 // image height too large for window => center image vertically
1751 src_y = (height - WIN_YSIZE) / 2;
1755 // always display title screens centered
1756 dst_x = (WIN_XSIZE - width) / 2;
1757 dst_y = (WIN_YSIZE - height) / 2;
1759 SetDrawBackgroundMask(REDRAW_ALL);
1760 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1762 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1764 boolean draw_masked_final = (DrawingOnBackground(dst_x, dst_y) && draw_masked);
1766 if (bitmap_background != NULL)
1768 int size = bitmap_background->height - bitmap->height;
1769 int offset = frame_counter++ % size;
1771 BlitBitmap(bitmap_background, drawto, src_x, src_y + offset, width, height, dst_x, dst_y);
1773 draw_masked_final = TRUE;
1776 if (draw_masked_final)
1777 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1779 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1781 redraw_mask = REDRAW_ALL;
1784 static void DrawTitleScreenMessage(int nr, boolean initial)
1786 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1787 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1789 if (filename == NULL)
1792 // force TITLE font on title message screen
1793 SetFontStatus(getTitleMessageGameMode(initial));
1795 // if chars *and* width set to "-1", automatically determine width
1796 if (tmi->chars == -1 && tmi->width == -1)
1797 tmi->width = viewport.window[game_status].width;
1799 // if lines *and* height set to "-1", automatically determine height
1800 if (tmi->lines == -1 && tmi->height == -1)
1801 tmi->height = viewport.window[game_status].height;
1803 // if chars set to "-1", automatically determine by text and font width
1804 if (tmi->chars == -1)
1805 tmi->chars = tmi->width / getFontWidth(tmi->font);
1807 tmi->width = tmi->chars * getFontWidth(tmi->font);
1809 // if lines set to "-1", automatically determine by text and font height
1810 if (tmi->lines == -1)
1811 tmi->lines = tmi->height / getFontHeight(tmi->font);
1813 tmi->height = tmi->lines * getFontHeight(tmi->font);
1815 // if x set to "-1", automatically determine by width and alignment
1817 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1819 // if y set to "-1", automatically determine by height and alignment
1821 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1823 SetDrawBackgroundMask(REDRAW_ALL);
1824 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1826 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1828 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1829 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1830 tmi->autowrap, tmi->centered, tmi->parse_comments);
1835 static void DrawTitleScreen(void)
1837 KeyboardAutoRepeatOff();
1839 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1842 static boolean CheckTitleScreen(boolean levelset_has_changed)
1844 static boolean show_title_initial = TRUE;
1845 boolean show_titlescreen = FALSE;
1847 // needed to be able to skip title screen, if no image or message defined
1848 InitializeTitleControls(show_title_initial);
1850 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1851 show_titlescreen = TRUE;
1853 // show initial title images and messages only once at program start
1854 show_title_initial = FALSE;
1856 return (show_titlescreen && num_title_screens > 0);
1859 void DrawMainMenu(void)
1861 static LevelDirTree *leveldir_last_valid = NULL;
1862 boolean levelset_has_changed = FALSE;
1863 int fade_mask = REDRAW_FIELD;
1865 LimitScreenUpdates(FALSE);
1867 FadeSetLeaveScreen();
1869 // do not fade out here -- function may continue and fade on editor screen
1872 FadeMenuSoundsAndMusic();
1874 ExpireSoundLoops(FALSE);
1876 KeyboardAutoRepeatOn();
1878 audio.sound_deactivated = FALSE;
1882 // needed if last screen was the playing screen, invoked from level editor
1883 if (level_editor_test_game)
1885 CloseDoor(DOOR_CLOSE_ALL);
1887 SetGameStatus(GAME_MODE_EDITOR);
1894 // needed if last screen was the playing screen, invoked from hall of fame
1895 if (score_info_tape_play)
1897 CloseDoor(DOOR_CLOSE_ALL);
1899 SetGameStatus(GAME_MODE_SCOREINFO);
1901 DrawScoreInfo(scores.last_entry_nr);
1906 // reset flag to continue playing next level from hall of fame
1907 scores.continue_playing = FALSE;
1909 // leveldir_current may be invalid (level group, parent link, node copy)
1910 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1912 if (leveldir_current != leveldir_last_valid)
1914 // level setup config may have been loaded to "last played" tree node copy,
1915 // but "leveldir_current" now points to the "original" level set tree node,
1916 // in which case "handicap_level" may still default to the first level
1917 LoadLevelSetup_SeriesInfo();
1919 UpdateLastPlayedLevels_TreeInfo();
1921 levelset_has_changed = TRUE;
1924 // store valid level series information
1925 leveldir_last_valid = leveldir_current;
1927 // store first level of this level set for "level_nr" style animations
1928 SetAnimationFirstLevel(leveldir_current->first_level);
1930 // level_nr may have been set to value over handicap with level editor
1931 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1932 level_nr = leveldir_current->handicap_level;
1934 LoadLevel(level_nr);
1935 LoadScore(level_nr);
1937 SaveLevelSetup_SeriesInfo();
1939 // needed if last screen (level choice) changed graphics, sounds or music
1940 ReloadCustomArtwork(0);
1942 if (CheckTitleScreen(levelset_has_changed))
1944 SetGameStatus(GAME_MODE_TITLE);
1951 if (redraw_mask & REDRAW_ALL)
1952 fade_mask = REDRAW_ALL;
1955 fade_mask = REDRAW_ALL;
1959 // needed if different viewport properties defined for menues
1960 ChangeViewportPropertiesIfNeeded();
1962 SetDrawtoField(DRAW_TO_BACKBUFFER);
1964 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1965 SetDrawDeactivationMask(REDRAW_NONE);
1966 SetDrawBackgroundMask(REDRAW_FIELD);
1968 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1971 if (fade_mask == REDRAW_ALL)
1972 RedrawGlobalBorder();
1977 InitializeMainControls();
1979 DrawCursorAndText_Main(-1, FALSE, FALSE);
1980 DrawPreviewLevelInitial();
1981 DrawNetworkPlayers();
1983 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1986 if (TAPE_IS_EMPTY(tape))
1988 DrawCompleteVideoDisplay();
1990 PlayMenuSoundsAndMusic();
1992 // create gadgets for main menu screen
1993 FreeScreenGadgets();
1994 CreateScreenGadgets();
1996 // may be required if audio buttons shown on tape and changed in setup menu
1998 CreateGameButtons();
2000 // map gadgets for main menu screen
2002 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
2003 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2004 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SET_INFO, hasLevelSetInfo());
2006 // copy actual game door content to door double buffer for OpenDoor()
2007 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
2008 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
2010 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2012 DrawMaskedBorder(fade_mask);
2017 // update screen area with special editor door
2018 redraw_mask |= REDRAW_ALL;
2021 SetMouseCursor(CURSOR_DEFAULT);
2023 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
2025 SyncEmscriptenFilesystem();
2027 // needed once after program start or after user change
2028 CheckApiServerTasks();
2031 static void gotoTopLevelDir(void)
2033 // move upwards until inside (but not above) top level directory
2034 while (leveldir_current->node_parent &&
2035 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
2037 // write a "path" into level tree for easy navigation to last level
2038 if (leveldir_current->node_parent->node_group->cl_first == -1)
2040 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
2041 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
2042 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
2043 int cl_first, cl_cursor;
2045 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
2046 cl_cursor = leveldir_pos - cl_first;
2048 leveldir_current->node_parent->node_group->cl_first = cl_first;
2049 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
2052 leveldir_current = leveldir_current->node_parent;
2056 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
2058 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
2060 return (use_frame_counter ? video.frame_counter : Counter());
2063 static boolean TitleAutoDelayReached(unsigned int *counter_var,
2064 struct TitleFadingInfo *fi)
2066 return DelayReachedExt2(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
2069 static void ResetTitleAutoDelay(unsigned int *counter_var,
2070 struct TitleFadingInfo *fi)
2072 *counter_var = getAutoDelayCounter(fi);
2075 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
2077 static unsigned int title_delay = 0;
2078 static int title_screen_nr = 0;
2079 static int last_sound = -1, last_music = -1;
2080 boolean return_to_main_menu = FALSE;
2081 struct TitleControlInfo *tci;
2084 if (button == MB_MENU_INITIALIZE)
2087 title_screen_nr = 0;
2088 tci = &title_controls[title_screen_nr];
2090 SetAnimStatus(getTitleAnimMode(tci));
2092 last_sound = SND_UNDEFINED;
2093 last_music = MUS_UNDEFINED;
2095 if (num_title_screens != 0)
2097 FadeSetEnterScreen();
2099 // use individual title fading instead of global "enter screen" fading
2100 fading = getTitleFading(tci);
2103 if (game_status_last_screen == GAME_MODE_INFO)
2105 if (num_title_screens == 0)
2107 // switch game mode from title screen mode back to info screen mode
2108 SetGameStatus(GAME_MODE_INFO);
2110 // store that last screen was info screen, not main menu screen
2111 game_status_last_screen = GAME_MODE_INFO;
2113 DrawInfoScreen_NotAvailable("Title screen information:",
2114 "No title screen for this level set.");
2119 FadeMenuSoundsAndMusic();
2121 FadeOut(REDRAW_ALL);
2123 // title screens may have different window size
2124 ChangeViewportPropertiesIfNeeded();
2126 // only required to update logic for redrawing global border
2130 DrawTitleScreenImage(tci->local_nr, tci->initial);
2132 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2134 sound = getTitleSound(tci);
2135 music = getTitleMusic(tci);
2137 if (sound != last_sound)
2138 PlayMenuSoundExt(sound);
2139 if (music != last_music)
2140 PlayMenuMusicExt(music);
2145 SetMouseCursor(CURSOR_NONE);
2149 ResetTitleAutoDelay(&title_delay, &fading);
2154 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
2155 button = MB_MENU_CHOICE;
2157 if (button == MB_MENU_LEAVE)
2159 return_to_main_menu = TRUE;
2161 else if (button == MB_MENU_CHOICE || dx)
2163 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
2165 SetGameStatus(GAME_MODE_INFO);
2167 info_mode = INFO_MODE_MAIN;
2175 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
2177 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
2179 tci = &title_controls[title_screen_nr];
2181 SetAnimStatus(getTitleAnimMode(tci));
2183 sound = getTitleSound(tci);
2184 music = getTitleMusic(tci);
2186 if (last_sound != SND_UNDEFINED && sound != last_sound)
2187 FadeSound(last_sound);
2188 if (last_music != MUS_UNDEFINED && music != last_music)
2191 fading = getTitleFading(tci);
2193 FadeOut(REDRAW_ALL);
2196 DrawTitleScreenImage(tci->local_nr, tci->initial);
2198 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2200 sound = getTitleSound(tci);
2201 music = getTitleMusic(tci);
2203 if (sound != last_sound)
2204 PlayMenuSoundExt(sound);
2205 if (music != last_music)
2206 PlayMenuMusicExt(music);
2213 ResetTitleAutoDelay(&title_delay, &fading);
2217 FadeMenuSoundsAndMusic();
2219 return_to_main_menu = TRUE;
2224 tci = &title_controls[title_screen_nr];
2226 // check for optional title screen of native BD style level set
2227 if (tci->is_image && CheckTitleScreen_BD(tci->local_nr, tci->initial))
2229 Bitmap **title_screen_bitmaps = GetTitleScreenBitmaps_BD();
2231 // if title screen is animated, draw title screen animation
2232 if (title_screen_bitmaps[0] != NULL &&
2233 title_screen_bitmaps[1] != NULL)
2234 DrawTitleScreenImage(tci->local_nr, tci->initial);
2238 if (return_to_main_menu)
2240 SetMouseCursor(CURSOR_DEFAULT);
2242 // force full menu screen redraw after displaying title screens
2243 redraw_mask = REDRAW_ALL;
2245 if (game_status_last_screen == GAME_MODE_INFO)
2247 SetGameStatus(GAME_MODE_INFO);
2249 info_mode = INFO_MODE_MAIN;
2253 else // default: return to main menu
2255 SetGameStatus(GAME_MODE_MAIN);
2262 static void HandleMainMenu_ToggleTeamMode(void)
2264 setup.team_mode = !setup.team_mode;
2266 InitializeMainControls();
2267 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2269 DrawPreviewPlayers();
2272 static void HandleMainMenu_SelectLevel(int step, int direction,
2273 int selected_level_nr)
2275 int old_level_nr = level_nr;
2278 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2279 new_level_nr = selected_level_nr;
2281 new_level_nr = old_level_nr + step * direction;
2283 if (new_level_nr < leveldir_current->first_level)
2284 new_level_nr = leveldir_current->first_level;
2285 if (new_level_nr > leveldir_current->last_level)
2286 new_level_nr = leveldir_current->last_level;
2288 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2290 // skipping levels is only allowed when trying to skip single level
2291 // (also, skipping BD style intermission levels is always possible)
2292 if (new_level_nr == old_level_nr + 1 &&
2293 (level.bd_intermission ||
2294 (setup.skip_levels && Request("Level still unsolved! Skip it anyway?", REQ_ASK))))
2296 leveldir_current->handicap_level++;
2297 SaveLevelSetup_SeriesInfo();
2300 new_level_nr = leveldir_current->handicap_level;
2303 if (new_level_nr != old_level_nr)
2305 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2307 PlaySound(SND_MENU_ITEM_SELECTING);
2309 level_nr = new_level_nr;
2311 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2312 int2str(level_nr, menu.main.text.level_number.size),
2313 mci->pos_text->font);
2315 LoadLevel(level_nr);
2316 DrawPreviewLevelInitial();
2320 DrawCompleteVideoDisplay();
2322 SaveLevelSetup_SeriesInfo();
2324 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2326 // force redraw of playfield area (may be reset at this point)
2327 redraw_mask |= REDRAW_FIELD;
2331 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2333 static int choice = MAIN_CONTROL_GAME;
2334 static boolean button_pressed_last = FALSE;
2335 boolean button_pressed = FALSE;
2337 int i = 0; // needed to prevent compiler warning due to bad code below
2339 if (button == MB_MENU_INITIALIZE)
2341 DrawCursorAndText_Main(choice, TRUE, FALSE);
2346 if (mx || my) // mouse input
2350 for (i = 0; main_controls[i].nr != -1; i++)
2352 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2353 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2354 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2356 pos = main_controls[i].nr;
2362 // check if level preview was clicked
2363 if (insidePreviewRect(&preview, mx - SX, my - SY))
2364 pos = MAIN_CONTROL_GAME;
2366 // handle pressed/unpressed state for active/inactive menu buttons
2367 // (if pos != -1, "i" contains index position corresponding to "pos")
2369 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2370 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2371 button_pressed = TRUE;
2373 if (button_pressed != button_pressed_last)
2375 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2378 PlaySound(SND_MENU_BUTTON_PRESSING);
2380 PlaySound(SND_MENU_BUTTON_RELEASING);
2383 else if (dx || dy) // keyboard input
2385 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2386 choice == MAIN_CONTROL_SETUP))
2387 button = MB_MENU_CHOICE;
2392 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2394 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2396 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2398 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2400 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2402 CloseDoor(DOOR_CLOSE_2);
2404 SetGameStatus(GAME_MODE_LEVELNR);
2406 DrawChooseLevelNr();
2408 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2414 PlaySound(SND_MENU_ITEM_ACTIVATING);
2416 DrawCursorAndText_Main(choice, FALSE, FALSE);
2417 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2423 if (choice == MAIN_CONTROL_NAME)
2425 // special case: cursor left or right pressed -- toggle team mode
2426 HandleMainMenu_ToggleTeamMode();
2428 else if (choice != MAIN_CONTROL_INFO &&
2429 choice != MAIN_CONTROL_SETUP)
2431 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2437 PlaySound(SND_MENU_ITEM_SELECTING);
2439 if (pos == MAIN_CONTROL_NAME)
2442 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2444 // special case: menu text "name/team" clicked -- toggle team mode
2445 HandleMainMenu_ToggleTeamMode();
2449 if (setup.multiple_users)
2451 CloseDoor(DOOR_CLOSE_2);
2453 SetGameStatus(GAME_MODE_NAMES);
2455 DrawChoosePlayerName();
2459 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2465 else if (pos == MAIN_CONTROL_LEVELS)
2469 CloseDoor(DOOR_CLOSE_2);
2471 SetGameStatus(GAME_MODE_LEVELS);
2473 SaveLevelSetup_LastSeries();
2474 SaveLevelSetup_SeriesInfo();
2476 // restore level set if chosen from "last played level set" menu
2477 RestoreLastPlayedLevels(&leveldir_current);
2479 if (setup.internal.choose_from_top_leveldir)
2482 DrawChooseLevelSet();
2485 else if (pos == MAIN_CONTROL_SCORES)
2487 CloseDoor(DOOR_CLOSE_2);
2489 SetGameStatus(GAME_MODE_SCORES);
2491 DrawHallOfFame(level_nr);
2493 else if (pos == MAIN_CONTROL_EDITOR)
2495 if (leveldir_current->readonly &&
2496 setup.editor.show_read_only_warning)
2497 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2499 CloseDoor(DOOR_CLOSE_ALL);
2501 SetGameStatus(GAME_MODE_EDITOR);
2503 FadeSetEnterScreen();
2507 else if (pos == MAIN_CONTROL_INFO)
2509 CloseDoor(DOOR_CLOSE_2);
2511 SetGameStatus(GAME_MODE_INFO);
2513 info_mode = INFO_MODE_MAIN;
2517 else if (pos == MAIN_CONTROL_GAME)
2519 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2521 else if (pos == MAIN_CONTROL_SETUP)
2523 CloseDoor(DOOR_CLOSE_2);
2525 SetGameStatus(GAME_MODE_SETUP);
2527 setup_mode = SETUP_MODE_MAIN;
2531 else if (pos == MAIN_CONTROL_QUIT)
2533 SaveLevelSetup_LastSeries();
2534 SaveLevelSetup_SeriesInfo();
2536 #if defined(PLATFORM_EMSCRIPTEN)
2537 Request("Close the browser window to quit!", REQ_CONFIRM);
2539 if (!setup.ask_on_quit_program ||
2540 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2541 SetGameStatus(GAME_MODE_QUIT);
2547 button_pressed_last = button_pressed;
2551 // ============================================================================
2552 // info screen functions
2553 // ============================================================================
2555 static struct TokenInfo *info_info;
2556 static int num_info_info; // number of info entries shown on screen
2557 static int max_info_info; // total number of info entries in list
2559 static void execInfoTitleScreen(void)
2561 info_mode = INFO_MODE_TITLE;
2566 static void execInfoElements(void)
2568 info_mode = INFO_MODE_ELEMENTS;
2573 static void execInfoMusic(void)
2575 info_mode = INFO_MODE_MUSIC;
2580 static void execInfoCredits(void)
2582 info_mode = INFO_MODE_CREDITS;
2587 static void execInfoProgram(void)
2589 info_mode = INFO_MODE_PROGRAM;
2594 static void execInfoVersion(void)
2596 info_mode = INFO_MODE_VERSION;
2601 static void execInfoLevelSet(void)
2603 info_mode = INFO_MODE_LEVELSET;
2608 static void execExitInfo(void)
2610 SetGameStatus(GAME_MODE_MAIN);
2615 static struct TokenInfo info_info_main[] =
2617 { TYPE_ENTER_SCREEN, execInfoTitleScreen, STR_INFO_TITLE },
2618 { TYPE_ENTER_SCREEN, execInfoElements, STR_INFO_ELEMENTS },
2619 { TYPE_ENTER_SCREEN, execInfoMusic, STR_INFO_MUSIC },
2620 { TYPE_ENTER_SCREEN, execInfoCredits, STR_INFO_CREDITS },
2621 { TYPE_ENTER_SCREEN, execInfoProgram, STR_INFO_PROGRAM },
2622 { TYPE_ENTER_SCREEN, execInfoVersion, STR_INFO_VERSION },
2623 { TYPE_ENTER_SCREEN, execInfoLevelSet, STR_INFO_LEVELSET },
2624 { TYPE_EMPTY, NULL, "" },
2625 { TYPE_LEAVE_MENU, execExitInfo, STR_INFO_EXIT },
2630 static int getMenuTextFont(int type)
2632 if (type & (TYPE_SWITCH |
2646 static struct TokenInfo *setup_info;
2647 static struct TokenInfo setup_info_input[];
2649 static struct TokenInfo *menu_info;
2651 static void PlayInfoSound(void)
2653 int info_sound = getInfoScreenBackgroundSound_Generic();
2654 char *next_sound = getSoundInfoEntryFilename(info_sound);
2656 if (next_sound != NULL)
2657 PlayMenuSoundExt(info_sound);
2662 static void PlayInfoSoundIfLoop(void)
2664 int info_sound = getInfoScreenBackgroundSound_Generic();
2665 char *next_sound = getSoundInfoEntryFilename(info_sound);
2667 if (next_sound != NULL)
2668 PlayMenuSoundIfLoopExt(info_sound);
2670 PlayMenuSoundIfLoop();
2673 static void PlayInfoMusic(void)
2675 int info_music = getInfoScreenBackgroundMusic_Generic();
2676 char *curr_music = getCurrentlyPlayingMusicFilename();
2677 char *next_music = getMusicInfoEntryFilename(info_music);
2679 if (next_music != NULL)
2681 // play music if info screen music differs from current music
2682 if (!strEqual(curr_music, next_music))
2683 PlayMenuMusicExt(info_music);
2687 // only needed if info screen was directly invoked from main menu
2692 static void PlayInfoSoundsAndMusic(void)
2698 static void FadeInfoSounds(void)
2703 static void FadeInfoMusic(void)
2705 int info_music = getInfoScreenBackgroundMusic_Generic();
2706 char *curr_music = getCurrentlyPlayingMusicFilename();
2707 char *next_music = getMusicInfoEntryFilename(info_music);
2709 if (next_music != NULL)
2711 // fade music if info screen music differs from current music
2712 if (!strEqual(curr_music, next_music))
2717 static void FadeInfoSoundsAndMusic(void)
2723 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2724 int screen_pos, int menu_info_pos_raw,
2727 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2728 struct TokenInfo *ti = &token_info[pos];
2729 int xpos = MENU_SCREEN_START_XPOS;
2730 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2731 int font_nr = getMenuTextFont(ti->type);
2733 if (setup_mode == SETUP_MODE_INPUT)
2734 font_nr = FONT_MENU_1;
2737 font_nr = FONT_ACTIVE(font_nr);
2739 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2741 if (ti->type & ~TYPE_SKIP_ENTRY)
2742 drawCursor(screen_pos, active);
2745 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2748 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2751 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2754 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2757 static char *window_size_text;
2758 static char *scaling_type_text;
2759 static char *network_server_text;
2761 static void drawSetupValue(int, int);
2763 static void drawMenuInfoList(int first_entry, int num_page_entries,
2764 int max_page_entries)
2768 if (first_entry + num_page_entries > max_page_entries)
2771 clearMenuListArea();
2773 for (i = 0; i < num_page_entries; i++)
2775 int menu_info_pos = first_entry + i;
2776 struct TokenInfo *si = &menu_info[menu_info_pos];
2777 void *value_ptr = si->value;
2779 // set some entries to "unchangeable" according to other variables
2780 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2781 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2782 (value_ptr == &setup.sound_music && !audio.music_available) ||
2783 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2784 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2785 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2786 si->type |= TYPE_GHOSTED;
2788 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2789 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2790 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2791 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2792 else if (si->type & ~TYPE_SKIP_ENTRY)
2793 initCursor(i, IMG_MENU_BUTTON);
2795 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2797 if (si->type & TYPE_STRING)
2801 if (value_ptr == &network_server_text)
2802 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2804 if (gadget_id != -1)
2806 struct GadgetInfo *gi = screen_gadget[gadget_id];
2807 int xpos = MENU_SCREEN_START_XPOS;
2808 int ypos = MENU_SCREEN_START_YPOS + i;
2809 int x = mSX + xpos * 32;
2810 int y = mSY + ypos * 32;
2812 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2816 if (si->type & TYPE_VALUE &&
2817 menu_info == setup_info)
2818 drawSetupValue(i, menu_info_pos);
2822 static void DrawInfoScreen_Main(void)
2824 int fade_mask = REDRAW_FIELD;
2827 // (needed after displaying info sub-screens directly from main menu)
2828 if (info_screens_from_main)
2830 info_screens_from_main = FALSE;
2832 SetGameStatus(GAME_MODE_MAIN);
2839 if (redraw_mask & REDRAW_ALL)
2840 fade_mask = REDRAW_ALL;
2843 fade_mask = REDRAW_ALL;
2846 FadeMenuSoundsAndMusic();
2848 FreeScreenGadgets();
2849 CreateScreenGadgets();
2851 // (needed after displaying title screens which disable auto repeat)
2852 KeyboardAutoRepeatOn();
2854 FadeSetLeaveScreen();
2858 // needed if different viewport properties defined for info screen
2859 ChangeViewportPropertiesIfNeeded();
2861 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2865 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2867 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_INFO_MAIN);
2869 info_info = info_info_main;
2871 // use modified info screen info without info screen entries marked as hidden
2872 info_info = getSetupInfoFinal(info_info);
2874 // determine maximal number of info entries that can be displayed on screen
2876 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2879 // determine maximal number of info entries available for menu of info screen
2881 for (i = 0; info_info[i].type != 0; i++)
2884 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2886 MapScreenGadgets(max_info_info);
2888 PlayMenuSoundsAndMusic();
2890 DrawMaskedBorder(fade_mask);
2895 static void changeSetupValue(int, int, int);
2897 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2898 int mode, int num_page_entries,
2899 int max_page_entries)
2901 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2902 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2903 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2904 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2905 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2906 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2907 int *num_page_entries_last = num_page_entries_all_last[game_status];
2908 int *choice_store = choice_stores[game_status];
2909 int *first_entry_store = first_entry_stores[game_status];
2910 int choice = choice_store[mode]; // starts with 0
2911 int first_entry = first_entry_store[mode]; // starts with 0
2913 int y = choice - first_entry;
2915 boolean position_set_by_scrollbar = (dx == 999);
2916 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2919 if (button == MB_MENU_INITIALIZE)
2921 // check if number of menu page entries has changed (may happen by change
2922 // of custom artwork definition value for 'list_size' for this menu screen)
2923 // (in this case, the last menu position most probably has to be corrected)
2924 if (num_page_entries != num_page_entries_last[mode])
2926 choice_store[mode] = first_entry_store[mode] = 0;
2928 choice = first_entry = 0;
2931 num_page_entries_last[mode] = num_page_entries;
2934 // advance to first valid menu entry
2935 while (choice < num_page_entries &&
2936 menu_info[choice].type & TYPE_SKIP_ENTRY)
2939 if (position_set_by_scrollbar)
2940 first_entry = first_entry_store[mode] = dy;
2942 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2943 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2945 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2947 if (choice < first_entry)
2949 choice = first_entry;
2951 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2954 else if (choice > first_entry + num_page_entries - 1)
2956 choice = first_entry + num_page_entries - 1;
2958 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2962 choice_store[mode] = choice;
2964 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2968 else if (button == MB_MENU_LEAVE)
2970 PlaySound(SND_MENU_ITEM_SELECTING);
2972 for (i = 0; i < max_page_entries; i++)
2974 if (menu_info[i].type & TYPE_LEAVE_MENU)
2976 void (*menu_callback_function)(void) = menu_info[i].value;
2980 menu_callback_function();
2982 break; // absolutely needed because function changes 'menu_info'!
2989 if (mx || my) // mouse input
2991 x = (mx - mSX) / 32;
2992 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2994 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2996 // move cursor instead of scrolling when already at start/end of list
2997 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2999 else if (dy == +1 * SCROLL_LINE &&
3000 first_entry + num_page_entries == max_page_entries)
3003 // handle scrolling screen one line or page
3005 y + dy > num_page_entries - 1)
3007 boolean redraw = FALSE;
3009 if (ABS(dy) == SCROLL_PAGE)
3010 step = num_page_entries - 1;
3012 if (dy < 0 && first_entry > 0)
3014 // scroll page/line up
3016 first_entry -= step;
3017 if (first_entry < 0)
3022 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
3024 // scroll page/line down
3026 first_entry += step;
3027 if (first_entry + num_page_entries > max_page_entries)
3028 first_entry = MAX(0, max_page_entries - num_page_entries);
3035 choice += first_entry - first_entry_store[mode];
3037 if (choice < first_entry)
3039 choice = first_entry;
3041 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
3044 else if (choice > first_entry + num_page_entries - 1)
3046 choice = first_entry + num_page_entries - 1;
3048 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
3051 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
3055 if (choice < first_entry ||
3056 choice > first_entry + num_page_entries - 1)
3057 first_entry += SIGN(dy);
3060 first_entry_store[mode] = first_entry;
3061 choice_store[mode] = choice;
3063 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
3065 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
3067 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
3068 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
3076 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
3078 if (menu_info[choice].type & menu_navigation_type ||
3079 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
3080 menu_info[choice].type & TYPE_YES_NO_AUTO ||
3081 menu_info[choice].type & TYPE_PLAYER)
3082 button = MB_MENU_CHOICE;
3087 // jump to next non-empty menu entry (up or down)
3088 while (first_entry + y > 0 &&
3089 first_entry + y < max_page_entries - 1 &&
3090 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
3093 if (!IN_VIS_MENU(x, y))
3095 choice += y - y_old;
3097 if (choice < first_entry)
3098 first_entry = choice;
3099 else if (choice > first_entry + num_page_entries - 1)
3100 first_entry = choice - num_page_entries + 1;
3102 if (first_entry >= 0 &&
3103 first_entry + num_page_entries <= max_page_entries)
3105 first_entry_store[mode] = first_entry;
3107 if (choice < first_entry)
3108 choice = first_entry;
3109 else if (choice > first_entry + num_page_entries - 1)
3110 choice = first_entry + num_page_entries - 1;
3112 choice_store[mode] = choice;
3114 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
3116 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
3118 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
3119 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
3126 if (!anyScrollbarGadgetActive() &&
3127 IN_VIS_MENU(x, y) &&
3128 mx < mx_right_border &&
3129 y >= 0 && y < num_page_entries)
3133 if (first_entry + y != choice &&
3134 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
3136 PlaySound(SND_MENU_ITEM_ACTIVATING);
3138 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
3139 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
3141 choice = choice_store[mode] = first_entry + y;
3145 PlaySound(SND_MENU_ITEM_SELECTING);
3147 for (i = 0; menu_info[i].type != 0; i++)
3149 if (menu_info[i].type & TYPE_LEAVE_MENU)
3151 void (*menu_callback_function)(void) = menu_info[i].value;
3155 menu_callback_function();
3157 // absolutely needed because function changes 'menu_info'!
3165 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
3167 PlaySound(SND_MENU_ITEM_SELECTING);
3169 // when selecting key headline, execute function for key value change
3170 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
3171 menu_info[first_entry + y + 1].type & TYPE_KEY)
3174 // when selecting string value, execute function for list selection
3175 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3176 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
3179 // when selecting string value, execute function for text input gadget
3180 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3181 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
3184 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
3186 void (*menu_callback_function)(void) =
3187 menu_info[first_entry + y].value;
3189 FadeSetFromType(menu_info[first_entry + y].type);
3191 menu_callback_function();
3193 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
3195 void (*gadget_callback_function)(void) =
3196 menu_info[first_entry + y].value;
3198 gadget_callback_function();
3200 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
3201 menu_info == setup_info)
3203 changeSetupValue(y, first_entry + y, dx);
3209 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
3211 menu_info = info_info;
3213 HandleMenuScreen(mx, my, dx, dy, button,
3214 info_mode, num_info_info, max_info_info);
3217 static int getMenuFontSpacing(int spacing_height, int font_nr)
3219 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
3221 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
3225 static int getMenuTextSpacing(int spacing_height, int font_nr)
3227 return (getMenuFontSpacing(spacing_height, font_nr) +
3228 EXTRA_SPACING(game_status));
3231 static int getMenuTextStep(int spacing_height, int font_nr)
3233 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
3236 static int getHeadlineSpacing(void)
3238 // special compatibility handling for "R'n'D jue 2022" game editions
3239 int spacing_check = menu.headline1_spacing[GAME_MODE_SCOREINFO];
3240 int spacing = (game_status == GAME_MODE_SCOREINFO ?
3241 menu.headline1_spacing[GAME_MODE_SCOREINFO] :
3242 menu.headline1_spacing_info[info_mode]);
3243 int font = MENU_INFO_FONT_TITLE;
3245 return (spacing_check != -2 ? getMenuTextStep(spacing, font) : 0);
3248 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
3250 int font_error = FONT_TEXT_2;
3251 int font_foot = MENU_INFO_FONT_FOOT;
3252 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3253 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3255 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
3257 FadeOut(REDRAW_FIELD);
3261 DrawInfoScreen_Headline(0, 1, FALSE);
3263 DrawTextSCentered(ystart, font_error, text_error);
3264 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3266 FadeIn(REDRAW_FIELD);
3269 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
3271 static int infoscreen_step[MAX_INFO_ELEMENTS_IN_ARRAY];
3272 static int infoscreen_frame[MAX_INFO_ELEMENTS_IN_ARRAY];
3273 int font_foot = MENU_INFO_FONT_FOOT;
3274 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
3275 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3276 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3277 int ystep = MENU_SCREEN_INFO_YSTEP;
3278 int row_height = MENU_SCREEN_INFO_ENTRY_SIZE;
3279 int tilesize = MENU_SCREEN_INFO_TILE_SIZE;
3280 int yoffset = (row_height - tilesize) / 2;
3281 int element, action, direction;
3289 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
3290 infoscreen_step[i] = infoscreen_frame[i] = 0;
3292 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3298 while (helpanim_info[j].element != HELPANIM_LIST_END)
3300 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
3305 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3314 int ypos = i - start;
3315 int ystart_pos = ystart + ypos * ystep + yoffset;
3317 j += infoscreen_step[ypos];
3319 element = helpanim_info[j].element;
3320 action = helpanim_info[j].action;
3321 direction = helpanim_info[j].direction;
3324 element = EL_UNKNOWN;
3326 if (action != -1 && direction != -1)
3327 graphic = el_act_dir2img(element, action, direction);
3328 else if (action != -1)
3329 graphic = el_act2img(element, action);
3330 else if (direction != -1)
3331 graphic = el_dir2img(element, direction);
3333 graphic = el2img(element);
3335 delay = helpanim_info[j++].delay;
3340 if (infoscreen_frame[ypos] == 0)
3343 infoscreen_frame[ypos] = delay - 1;
3347 sync_frame = delay - infoscreen_frame[ypos];
3348 infoscreen_frame[ypos]--;
3351 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3353 if (!infoscreen_frame[ypos])
3354 infoscreen_step[ypos] = 0;
3358 if (!infoscreen_frame[ypos])
3359 infoscreen_step[ypos]++;
3360 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3366 ClearRectangleOnBackground(drawto, xstart, ystart_pos, tilesize, tilesize);
3367 DrawSizedGraphicAnimationExt(drawto, xstart, ystart_pos,
3368 graphic, sync_frame, tilesize, USE_MASKING);
3371 DrawInfoScreen_HelpText(element, action, direction, ypos);
3376 redraw_mask |= REDRAW_FIELD;
3381 static char *getHelpText(int element, int action, int direction)
3383 char token[MAX_LINE_LEN];
3385 strcpy(token, element_info[element].token_name);
3388 strcat(token, element_action_info[action].suffix);
3390 if (direction != -1)
3391 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3393 return getHashEntry(helptext_info, token);
3396 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3398 int font_nr = FONT_INFO_ELEMENTS;
3399 int font_width = getFontWidth(font_nr);
3400 int font_height = getFontHeight(font_nr);
3401 int line_spacing = MENU_SCREEN_INFO_SPACE_LINE;
3402 int left_spacing = MENU_SCREEN_INFO_SPACE_LEFT;
3403 int middle_spacing = MENU_SCREEN_INFO_SPACE_MIDDLE;
3404 int right_spacing = MENU_SCREEN_INFO_SPACE_RIGHT;
3405 int line_height = font_height + line_spacing;
3406 int row_height = MENU_SCREEN_INFO_ENTRY_SIZE;
3407 int tilesize = MENU_SCREEN_INFO_TILE_SIZE;
3408 int xstart = mSX + left_spacing + tilesize + middle_spacing;
3409 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3410 int ystep = MENU_SCREEN_INFO_YSTEP;
3411 int pad_left = xstart - SX;
3412 int pad_right = right_spacing;
3413 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3414 int max_lines_per_text = (row_height + line_spacing) / line_height;
3416 boolean autowrap = TRUE;
3417 boolean centered = FALSE;
3418 boolean parse_comments = FALSE;
3420 if (action != -1 && direction != -1) // element.action.direction
3421 text = getHelpText(element, action, direction);
3423 if (text == NULL && action != -1) // element.action
3424 text = getHelpText(element, action, -1);
3426 if (text == NULL && direction != -1) // element.direction
3427 text = getHelpText(element, -1, direction);
3429 if (text == NULL) // base element
3430 text = getHelpText(element, -1, -1);
3432 if (text == NULL) // not found
3433 text = "No description available";
3435 DisableDrawingText();
3437 // first get number of text lines to calculate offset for centering text
3438 int num_lines_printed =
3439 DrawTextBuffer(0, 0, text, font_nr,
3440 max_chars_per_line, -1, max_lines_per_text, line_spacing, -1,
3441 autowrap, centered, parse_comments);
3443 EnableDrawingText();
3445 int size_lines_printed = num_lines_printed * line_height - line_spacing;
3446 int yoffset = (row_height - size_lines_printed) / 2;
3448 DrawTextBuffer(xstart, ystart + ypos * ystep + yoffset, text, font_nr,
3449 max_chars_per_line, -1, max_lines_per_text, line_spacing, -1,
3450 autowrap, centered, parse_comments);
3453 static void DrawInfoScreen_TitleScreen(void)
3455 SetGameStatus(GAME_MODE_TITLE);
3462 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3464 HandleTitleScreen(0, 0, dx, dy, button);
3467 static void DrawInfoScreen_Elements(void)
3469 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3472 FadeInfoSoundsAndMusic();
3474 FadeOut(REDRAW_FIELD);
3479 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3481 PlayInfoSoundsAndMusic();
3483 FadeIn(REDRAW_FIELD);
3486 void HandleInfoScreen_Elements(int dx, int dy, int button)
3488 static DelayCounter info_delay = { 0 };
3489 static int num_anims;
3490 static int num_pages;
3492 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3495 info_delay.value = GameFrameDelay;
3497 if (button == MB_MENU_INITIALIZE)
3499 boolean new_element = TRUE;
3503 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3505 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3507 else if (new_element)
3510 new_element = FALSE;
3514 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3518 if (button == MB_MENU_LEAVE)
3520 PlaySound(SND_MENU_ITEM_SELECTING);
3522 info_mode = INFO_MODE_MAIN;
3527 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3529 if (button != MB_MENU_INITIALIZE)
3531 PlaySound(SND_MENU_ITEM_SELECTING);
3533 page += (dx < 0 ? -1 : +1);
3536 if (page < 0 || page >= num_pages)
3538 FadeInfoSoundsAndMusic();
3540 info_mode = INFO_MODE_MAIN;
3546 if (button != MB_MENU_INITIALIZE)
3547 FadeSetNextScreen();
3549 if (button != MB_MENU_INITIALIZE)
3550 FadeOut(REDRAW_FIELD);
3554 DrawInfoScreen_Headline(page, num_pages, TRUE);
3555 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3557 if (button != MB_MENU_INITIALIZE)
3558 FadeIn(REDRAW_FIELD);
3562 if (DelayReached(&info_delay))
3563 if (page < num_pages)
3564 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3566 PlayInfoSoundIfLoop();
3570 static void DrawInfoScreen_Music(void)
3572 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3576 FadeOut(REDRAW_FIELD);
3580 DrawInfoScreen_Headline(0, 1, TRUE);
3584 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3586 FadeIn(REDRAW_FIELD);
3589 void HandleInfoScreen_Music(int dx, int dy, int button)
3591 static struct MusicFileInfo *list = NULL;
3592 static int num_screens = 0;
3593 static int screen_nr = 0;
3594 int font_title = MENU_INFO_FONT_TITLE;
3595 int font_head = MENU_INFO_FONT_HEAD;
3596 int font_text = MENU_INFO_FONT_TEXT;
3597 int font_foot = MENU_INFO_FONT_FOOT;
3598 int spacing_head = menu.headline2_spacing_info[info_mode];
3599 int ystep_head = getMenuTextStep(spacing_head, font_head);
3600 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3601 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3603 if (button == MB_MENU_INITIALIZE)
3605 struct MusicFileInfo *list_ptr = music_file_info;
3610 while (list_ptr != NULL)
3612 list_ptr = list_ptr->next;
3616 list = music_file_info;
3620 FadeMenuSoundsAndMusic();
3624 DrawInfoScreen_Headline(0, 1, TRUE);
3626 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3627 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3633 if (button == MB_MENU_LEAVE)
3635 PlaySound(SND_MENU_ITEM_SELECTING);
3637 FadeMenuSoundsAndMusic();
3639 info_mode = INFO_MODE_MAIN;
3644 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3646 if (button != MB_MENU_INITIALIZE)
3648 PlaySound(SND_MENU_ITEM_SELECTING);
3652 list = (dx < 0 ? list->prev : list->next);
3653 screen_nr += (dx < 0 ? -1 : +1);
3659 FadeMenuSoundsAndMusic();
3661 info_mode = INFO_MODE_MAIN;
3667 FadeMenuSoundsAndMusic();
3669 if (list != music_file_info)
3670 FadeSetNextScreen();
3672 if (button != MB_MENU_INITIALIZE)
3673 FadeOut(REDRAW_FIELD);
3677 DrawInfoScreen_Headline(screen_nr, num_screens, TRUE);
3681 int sound = list->music;
3683 if (IS_LOOP_SOUND(sound))
3684 PlaySoundLoop(sound);
3690 int music = list->music;
3692 if (IS_LOOP_MUSIC(music))
3693 PlayMusicLoop(music);
3698 if (!strEqual(list->title, UNKNOWN_NAME))
3700 if (!strEqual(list->title_header, UNKNOWN_NAME))
3701 DrawTextSCentered(ystart, font_head, list->title_header);
3703 DrawTextSCentered(ystart, font_head, "Track");
3705 ystart += ystep_head;
3707 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3708 ystart += ystep_head;
3711 if (!strEqual(list->artist, UNKNOWN_NAME))
3713 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3714 DrawTextSCentered(ystart, font_head, list->artist_header);
3716 DrawTextSCentered(ystart, font_head, "by");
3718 ystart += ystep_head;
3720 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3721 ystart += ystep_head;
3724 if (!strEqual(list->album, UNKNOWN_NAME))
3726 if (!strEqual(list->album_header, UNKNOWN_NAME))
3727 DrawTextSCentered(ystart, font_head, list->album_header);
3729 DrawTextSCentered(ystart, font_head, "from the album");
3731 ystart += ystep_head;
3733 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3734 ystart += ystep_head;
3737 if (!strEqual(list->year, UNKNOWN_NAME))
3739 if (!strEqual(list->year_header, UNKNOWN_NAME))
3740 DrawTextSCentered(ystart, font_head, list->year_header);
3742 DrawTextSCentered(ystart, font_head, "from the year");
3744 ystart += ystep_head;
3746 DrawTextFCentered(ystart, font_text, "%s", list->year);
3747 ystart += ystep_head;
3750 if (!strEqual(list->played, UNKNOWN_NAME))
3752 if (!strEqual(list->played_header, UNKNOWN_NAME))
3753 DrawTextSCentered(ystart, font_head, list->played_header);
3755 DrawTextSCentered(ystart, font_head, "played in");
3757 ystart += ystep_head;
3759 DrawTextFCentered(ystart, font_text, "%s", list->played);
3760 ystart += ystep_head;
3762 else if (!list->is_sound)
3764 int music_level_nr = -1;
3767 // check if this music is configured for a certain level
3768 for (i = leveldir_current->first_level;
3769 i <= leveldir_current->last_level; i++)
3771 // (special case: "list->music" may be negative for unconfigured music)
3772 if (levelset.music[i] != MUS_UNDEFINED &&
3773 levelset.music[i] == list->music)
3781 if (music_level_nr != -1)
3783 if (!strEqual(list->played_header, UNKNOWN_NAME))
3784 DrawTextSCentered(ystart, font_head, list->played_header);
3786 DrawTextSCentered(ystart, font_head, "played in");
3788 ystart += ystep_head;
3790 DrawTextFCentered(ystart, font_text, "level %03d", music_level_nr);
3791 ystart += ystep_head;
3795 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3797 if (button != MB_MENU_INITIALIZE)
3798 FadeIn(REDRAW_FIELD);
3801 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3802 PlaySoundLoop(list->music);
3805 static void DrawInfoScreen_Version(void)
3807 int font_head = MENU_INFO_FONT_HEAD;
3808 int font_text = MENU_INFO_FONT_TEXT;
3809 int font_foot = MENU_INFO_FONT_FOOT;
3810 int spacing_head = menu.headline2_spacing_info[info_mode];
3811 int spacing_para = menu.paragraph_spacing_info[info_mode];
3812 int spacing_line = menu.line_spacing_info[info_mode];
3813 int xstep = getFontWidth(font_text);
3814 int ystep_head = getMenuTextStep(spacing_head, font_head);
3815 int ystep_para = getMenuTextStep(spacing_para, font_text);
3816 int ystep_line = getMenuTextStep(spacing_line, font_text);
3817 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3818 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3819 int xstart1 = mSX - SX + 2 * xstep;
3820 int xstart2 = mSX - SX + 18 * xstep;
3821 int xstart3 = mSX - SX + 28 * xstep;
3822 SDL_version sdl_version_compiled;
3823 const SDL_version *sdl_version_linked;
3824 int driver_name_len = 10;
3825 SDL_version sdl_version_linked_ext;
3826 const char *driver_name = NULL;
3828 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3831 FadeInfoSoundsAndMusic();
3833 FadeOut(REDRAW_FIELD);
3837 DrawInfoScreen_Headline(0, 1, TRUE);
3839 DrawTextF(xstart1, ystart, font_head, "Name");
3840 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3841 ystart += ystep_line;
3843 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3845 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3846 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3847 ystart += ystep_line;
3849 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3850 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3851 ystart += ystep_line;
3855 DrawTextF(xstart1, ystart, font_head, "Version");
3856 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3857 ystart += ystep_line;
3860 DrawTextF(xstart1, ystart, font_head, "Platform");
3861 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3863 PLATFORM_XX_BIT_STRING);
3864 ystart += ystep_line;
3866 DrawTextF(xstart1, ystart, font_head, "Target");
3867 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3868 ystart += ystep_line;
3870 DrawTextF(xstart1, ystart, font_head, "Source date");
3871 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3872 ystart += ystep_line;
3874 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3875 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3876 ystart += ystep_para;
3878 DrawTextF(xstart1, ystart, font_head, "Library");
3879 DrawTextF(xstart2, ystart, font_head, "compiled");
3880 DrawTextF(xstart3, ystart, font_head, "linked");
3881 ystart += ystep_head;
3883 SDL_VERSION(&sdl_version_compiled);
3884 SDL_GetVersion(&sdl_version_linked_ext);
3885 sdl_version_linked = &sdl_version_linked_ext;
3887 DrawTextF(xstart1, ystart, font_text, "SDL");
3888 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3889 sdl_version_compiled.major,
3890 sdl_version_compiled.minor,
3891 sdl_version_compiled.patch);
3892 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3893 sdl_version_linked->major,
3894 sdl_version_linked->minor,
3895 sdl_version_linked->patch);
3896 ystart += ystep_line;
3898 SDL_IMAGE_VERSION(&sdl_version_compiled);
3899 sdl_version_linked = IMG_Linked_Version();
3901 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3902 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3903 sdl_version_compiled.major,
3904 sdl_version_compiled.minor,
3905 sdl_version_compiled.patch);
3906 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3907 sdl_version_linked->major,
3908 sdl_version_linked->minor,
3909 sdl_version_linked->patch);
3910 ystart += ystep_line;
3912 SDL_MIXER_VERSION(&sdl_version_compiled);
3913 sdl_version_linked = Mix_Linked_Version();
3915 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3916 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3917 sdl_version_compiled.major,
3918 sdl_version_compiled.minor,
3919 sdl_version_compiled.patch);
3920 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3921 sdl_version_linked->major,
3922 sdl_version_linked->minor,
3923 sdl_version_linked->patch);
3924 ystart += ystep_line;
3926 SDL_NET_VERSION(&sdl_version_compiled);
3927 sdl_version_linked = SDLNet_Linked_Version();
3929 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3930 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3931 sdl_version_compiled.major,
3932 sdl_version_compiled.minor,
3933 sdl_version_compiled.patch);
3934 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3935 sdl_version_linked->major,
3936 sdl_version_linked->minor,
3937 sdl_version_linked->patch);
3938 ystart += ystep_para;
3940 DrawTextF(xstart1, ystart, font_head, "Driver");
3941 DrawTextF(xstart2, ystart, font_head, "Requested");
3942 DrawTextF(xstart3, ystart, font_head, "Used");
3943 ystart += ystep_head;
3946 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3948 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3949 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3950 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3951 ystart += ystep_line;
3954 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3956 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3957 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3958 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3959 ystart += ystep_line;
3962 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3964 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3965 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3966 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3968 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3970 PlayInfoSoundsAndMusic();
3972 FadeIn(REDRAW_FIELD);
3975 void HandleInfoScreen_Version(int button)
3977 if (button == MB_MENU_LEAVE)
3979 PlaySound(SND_MENU_ITEM_SELECTING);
3981 info_mode = INFO_MODE_MAIN;
3986 else if (button == MB_MENU_CHOICE)
3988 PlaySound(SND_MENU_ITEM_SELECTING);
3990 FadeMenuSoundsAndMusic();
3992 info_mode = INFO_MODE_MAIN;
3997 PlayMenuSoundIfLoop();
4001 static char *getInfoScreenTitle_Generic(void)
4003 return (info_mode == INFO_MODE_MAIN ? STR_INFO_MAIN :
4004 info_mode == INFO_MODE_TITLE ? STR_INFO_TITLE :
4005 info_mode == INFO_MODE_ELEMENTS ? STR_INFO_ELEMENTS :
4006 info_mode == INFO_MODE_MUSIC ? STR_INFO_MUSIC :
4007 info_mode == INFO_MODE_CREDITS ? STR_INFO_CREDITS :
4008 info_mode == INFO_MODE_PROGRAM ? STR_INFO_PROGRAM :
4009 info_mode == INFO_MODE_VERSION ? STR_INFO_VERSION :
4010 info_mode == INFO_MODE_LEVELSET ? STR_INFO_LEVELSET :
4014 static int getInfoScreenBackgroundImage_Generic(void)
4016 return (info_mode == INFO_MODE_ELEMENTS ? IMG_BACKGROUND_INFO_ELEMENTS :
4017 info_mode == INFO_MODE_MUSIC ? IMG_BACKGROUND_INFO_MUSIC :
4018 info_mode == INFO_MODE_CREDITS ? IMG_BACKGROUND_INFO_CREDITS :
4019 info_mode == INFO_MODE_PROGRAM ? IMG_BACKGROUND_INFO_PROGRAM :
4020 info_mode == INFO_MODE_VERSION ? IMG_BACKGROUND_INFO_VERSION :
4021 info_mode == INFO_MODE_LEVELSET ? IMG_BACKGROUND_INFO_LEVELSET :
4022 IMG_BACKGROUND_INFO);
4025 static int getInfoScreenBackgroundSound_Generic(void)
4027 return (info_mode == INFO_MODE_ELEMENTS ? SND_BACKGROUND_INFO_ELEMENTS :
4028 info_mode == INFO_MODE_CREDITS ? SND_BACKGROUND_INFO_CREDITS :
4029 info_mode == INFO_MODE_PROGRAM ? SND_BACKGROUND_INFO_PROGRAM :
4030 info_mode == INFO_MODE_VERSION ? SND_BACKGROUND_INFO_VERSION :
4031 info_mode == INFO_MODE_LEVELSET ? SND_BACKGROUND_INFO_LEVELSET :
4032 SND_BACKGROUND_INFO);
4035 static int getInfoScreenBackgroundMusic_Generic(void)
4037 return (info_mode == INFO_MODE_ELEMENTS ? MUS_BACKGROUND_INFO_ELEMENTS :
4038 info_mode == INFO_MODE_CREDITS ? MUS_BACKGROUND_INFO_CREDITS :
4039 info_mode == INFO_MODE_PROGRAM ? MUS_BACKGROUND_INFO_PROGRAM :
4040 info_mode == INFO_MODE_VERSION ? MUS_BACKGROUND_INFO_VERSION :
4041 info_mode == INFO_MODE_LEVELSET ? MUS_BACKGROUND_INFO_LEVELSET :
4042 MUS_BACKGROUND_INFO);
4045 static char *getInfoScreenFilename_Generic(int nr, boolean global)
4047 return (info_mode == INFO_MODE_CREDITS ? getCreditsFilename(nr, global) :
4048 info_mode == INFO_MODE_PROGRAM ? getProgramInfoFilename(nr) :
4049 info_mode == INFO_MODE_LEVELSET ? getLevelSetInfoFilename(nr) :
4053 static void DrawInfoScreen_GenericScreen(int screen_nr, int num_screens,
4054 int use_global_screens)
4056 char *filename = getInfoScreenFilename_Generic(screen_nr, use_global_screens);
4057 int font_text = MENU_INFO_FONT_TEXT;
4058 int font_foot = MENU_INFO_FONT_FOOT;
4059 int spacing_line = menu.line_spacing_info[info_mode];
4060 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4064 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
4066 if (info_mode == INFO_MODE_CREDITS ||
4067 info_mode == INFO_MODE_PROGRAM)
4070 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART;
4071 int chars = width / getFontWidth(font_text);
4072 int lines = height / getFontHeight(font_text);
4073 int padx = (width - chars * getFontWidth(font_text)) / 2;
4074 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
4075 int xstart = mSX + padx;
4076 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
4077 boolean autowrap = FALSE;
4078 boolean centered = TRUE;
4079 boolean parse_comments = TRUE;
4081 DrawTextFile(xstart, ystart,
4082 filename, font_text, chars, -1, lines, line_spacing, -1,
4083 autowrap, centered, parse_comments);
4085 else if (info_mode == INFO_MODE_LEVELSET)
4087 struct TitleMessageInfo *tmi = &readme;
4089 // if x position set to "-1", automatically determine by playfield width
4091 tmi->x = SXSIZE / 2;
4093 // if y position set to "-1", use static default value
4095 tmi->y = MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
4097 // if width set to "-1", automatically determine by playfield width
4098 if (tmi->width == -1)
4099 tmi->width = SXSIZE - 2 * TILEX;
4101 // if height set to "-1", automatically determine by playfield height
4102 if (tmi->height == -1)
4103 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
4105 // if chars set to "-1", automatically determine by text and font width
4106 if (tmi->chars == -1)
4107 tmi->chars = tmi->width / getFontWidth(tmi->font);
4109 tmi->width = tmi->chars * getFontWidth(tmi->font);
4111 // if lines set to "-1", automatically determine by text and font height
4112 if (tmi->lines == -1)
4113 tmi->lines = tmi->height / getFontHeight(tmi->font);
4115 tmi->height = tmi->lines * getFontHeight(tmi->font);
4117 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
4118 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
4119 tmi->autowrap, tmi->centered, tmi->parse_comments);
4122 boolean last_screen = (screen_nr == num_screens - 1);
4123 char *text_foot = (last_screen ? TEXT_NEXT_MENU : TEXT_NEXT_PAGE);
4125 DrawTextSCentered(ybottom, font_foot, text_foot);
4128 static void DrawInfoScreen_Generic(void)
4130 SetMainBackgroundImageIfDefined(getInfoScreenBackgroundImage_Generic());
4133 FadeInfoSoundsAndMusic();
4135 FadeOut(REDRAW_FIELD);
4137 HandleInfoScreen_Generic(0, 0, MB_MENU_INITIALIZE);
4139 PlayInfoSoundsAndMusic();
4141 FadeIn(REDRAW_FIELD);
4144 void HandleInfoScreen_Generic(int dx, int dy, int button)
4146 static char *text_no_info = "";
4147 static int num_screens = 0;
4148 static int screen_nr = 0;
4149 static boolean use_global_screens = FALSE;
4151 if (button == MB_MENU_INITIALIZE)
4156 if (info_mode == INFO_MODE_CREDITS)
4160 for (i = 0; i < 2; i++)
4162 use_global_screens = i; // check for "FALSE", then "TRUE"
4164 // determine number of (global or level set specific) credits screens
4165 while (getCreditsFilename(num_screens, use_global_screens) != NULL)
4168 if (num_screens > 0)
4172 text_no_info = "No credits available.";
4174 else if (info_mode == INFO_MODE_PROGRAM)
4176 use_global_screens = TRUE;
4178 // determine number of program info screens
4179 while (getProgramInfoFilename(num_screens) != NULL)
4182 text_no_info = "No program info available.";
4184 else if (info_mode == INFO_MODE_LEVELSET)
4186 use_global_screens = FALSE;
4188 // determine number of levelset info screens
4189 while (getLevelSetInfoFilename(num_screens) != NULL)
4192 text_no_info = "No level set info available.";
4195 if (num_screens == 0)
4197 int font_title = MENU_INFO_FONT_TITLE;
4198 int font_foot = MENU_INFO_FONT_FOOT;
4199 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
4200 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4204 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
4206 DrawTextSCentered(ystart, font_title, text_no_info);
4207 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
4212 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
4214 else if (button == MB_MENU_LEAVE)
4216 PlaySound(SND_MENU_ITEM_SELECTING);
4218 info_mode = INFO_MODE_MAIN;
4221 else if (button == MB_MENU_CHOICE || dx)
4223 PlaySound(SND_MENU_ITEM_SELECTING);
4225 screen_nr += (dx < 0 ? -1 : +1);
4227 if (screen_nr < 0 || screen_nr >= num_screens)
4229 FadeInfoSoundsAndMusic();
4231 info_mode = INFO_MODE_MAIN;
4236 FadeSetNextScreen();
4238 FadeOut(REDRAW_FIELD);
4240 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
4242 FadeIn(REDRAW_FIELD);
4247 PlayInfoSoundIfLoop();
4251 static void DrawInfoScreen(void)
4253 if (info_mode == INFO_MODE_TITLE)
4254 DrawInfoScreen_TitleScreen();
4255 else if (info_mode == INFO_MODE_ELEMENTS)
4256 DrawInfoScreen_Elements();
4257 else if (info_mode == INFO_MODE_MUSIC)
4258 DrawInfoScreen_Music();
4259 else if (info_mode == INFO_MODE_CREDITS)
4260 DrawInfoScreen_Generic();
4261 else if (info_mode == INFO_MODE_PROGRAM)
4262 DrawInfoScreen_Generic();
4263 else if (info_mode == INFO_MODE_VERSION)
4264 DrawInfoScreen_Version();
4265 else if (info_mode == INFO_MODE_LEVELSET)
4266 DrawInfoScreen_Generic();
4268 DrawInfoScreen_Main();
4271 void DrawInfoScreen_FromMainMenu(int nr)
4273 int fade_mask = REDRAW_FIELD;
4275 if (nr < INFO_MODE_MAIN || nr >= MAX_INFO_MODES)
4278 CloseDoor(DOOR_CLOSE_2);
4280 SetGameStatus(GAME_MODE_INFO);
4283 info_screens_from_main = TRUE;
4285 if (redraw_mask & REDRAW_ALL)
4286 fade_mask = REDRAW_ALL;
4289 fade_mask = REDRAW_ALL;
4292 FadeMenuSoundsAndMusic();
4294 FadeSetEnterScreen();
4298 FadeSkipNextFadeOut();
4300 // needed if different viewport properties defined for info screen
4301 ChangeViewportPropertiesIfNeeded();
4303 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
4308 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4310 if (info_mode == INFO_MODE_TITLE)
4311 HandleInfoScreen_TitleScreen(dx, dy, button);
4312 else if (info_mode == INFO_MODE_ELEMENTS)
4313 HandleInfoScreen_Elements(dx, dy, button);
4314 else if (info_mode == INFO_MODE_MUSIC)
4315 HandleInfoScreen_Music(dx, dy, button);
4316 else if (info_mode == INFO_MODE_CREDITS)
4317 HandleInfoScreen_Generic(dx, dy, button);
4318 else if (info_mode == INFO_MODE_PROGRAM)
4319 HandleInfoScreen_Generic(dx, dy, button);
4320 else if (info_mode == INFO_MODE_VERSION)
4321 HandleInfoScreen_Version(button);
4322 else if (info_mode == INFO_MODE_LEVELSET)
4323 HandleInfoScreen_Generic(dx, dy, button);
4325 HandleInfoScreen_Main(mx, my, dx, dy, button);
4329 // ============================================================================
4330 // type name functions
4331 // ============================================================================
4333 static TreeInfo *type_name_node = NULL;
4334 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4335 static int type_name_nr = 0;
4337 static int getPlayerNameColor(char *name)
4339 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4342 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4345 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4346 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4347 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4348 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4349 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4350 int font_width = getFontWidth(font_nr);
4351 int font_xoffset = getFontDrawOffsetX(font_nr);
4352 int font_yoffset = getFontDrawOffsetY(font_nr);
4353 int font_sx = sx + font_xoffset;
4354 int font_sy = sy + font_yoffset;
4356 DrawBackgroundForFont(font_sx, font_sy, pos->width, pos->height, font_nr);
4358 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4360 pos->width = strlen(text) * font_width;
4361 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4363 DrawText(sx, sy, text, font_nr);
4366 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4368 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4370 *pos = *mci->pos_input;
4372 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4374 TreeInfo *ti = player_name_current;
4375 int first_entry = ti->cl_first;
4376 int entry_pos = first_entry + ti->cl_cursor;
4377 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4378 int xpos = MENU_SCREEN_START_XPOS;
4379 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4381 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4382 type_name_nr = entry_pos;
4384 strcpy(name, type_name_node->name);
4388 pos->width = MAX_PLAYER_NAME_LEN * 32;
4392 type_name_nr = user.nr;
4394 strcpy(name, setup.player_name);
4397 strcpy(type_name_last, name);
4399 if (strEqual(name, EMPTY_PLAYER_NAME))
4402 *xpos = strlen(name);
4405 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4407 // change name of edited user in global list of user names
4408 setString(&global.user_names[type_name_nr], name);
4410 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4412 TreeInfo *node = type_name_node;
4414 // change name of edited user in local menu tree structure
4415 setString(&node->name, name);
4416 setString(&node->name_sorting, name);
4418 node->color = getPlayerNameColor(name);
4419 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4423 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4426 boolean reset_setup = strEqual(name, "");
4427 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4428 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4431 strcpy(name, type_name_last);
4433 if (strEqual(name, ""))
4434 strcpy(name, EMPTY_PLAYER_NAME);
4436 setTypeNameValues_Name(name, pos);
4438 // if player name not changed, no further action required
4439 if (strEqual(name, type_name_last))
4442 // redraw player name before (possibly) opening request dialogs
4443 drawTypeNameText(name, pos, FALSE);
4445 int last_user_nr = user.nr;
4447 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4449 // save setup of currently active user (may differ from edited user)
4452 // temporarily change active user to edited user
4453 user.nr = type_name_nr;
4456 Request("Use current setup values for the new player?", REQ_ASK))
4458 // use current setup values for new user, but create new player UUID
4459 setup.player_uuid = getStringCopy(getUUID());
4463 // load setup for existing user (or start with defaults for new user)
4468 char *setup_filename = getSetupFilename();
4469 boolean setup_exists = fileExists(setup_filename);
4471 // change name of edited user in setup structure
4472 strcpy(setup.player_name, name);
4474 // save setup of edited user
4477 // change name of edited user on score server
4478 ApiRenamePlayerAsThread();
4480 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4484 if (Request("Reset setup values for this player?", REQ_ASK))
4486 // remove setup config file
4487 unlink(setup_filename);
4489 // set player name to default player name
4492 // update player name used by name typing functions
4493 strcpy(name, setup.player_name);
4495 setTypeNameValues_Name(name, pos);
4498 else if (remove_user && type_name_nr != 0)
4500 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4502 char *user_dir = getUserGameDataDir();
4503 char *user_dir_removed =
4504 getStringCat3WithSeparator(user_dir, "REMOVED",
4505 getCurrentTimestamp(), ".");
4507 if (rename(user_dir, user_dir_removed) != 0)
4508 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4510 checked_free(user_dir_removed);
4513 else if (create_user && type_name_nr != 0 && !setup_exists)
4515 if (Request("Create empty level set for the new player?", REQ_ASK))
4517 char *levelset_subdir = getNewUserLevelSubdir();
4519 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4521 AddUserLevelSetToLevelInfo(levelset_subdir);
4523 LevelDirTree *leveldir_current_last = leveldir_current;
4525 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4528 // set level number of newly created level set to default value
4529 LoadLevelSetup_SeriesInfo();
4531 // set newly created level set as current level set for new user
4532 SaveLevelSetup_LastSeries();
4533 SaveLevelSetup_SeriesInfo();
4535 leveldir_current = leveldir_current_last;
4539 Request("Creating new level set failed!", REQ_CONFIRM);
4544 // restore currently active user
4545 user.nr = last_user_nr;
4547 // restore setup of currently active user
4550 // restore last level set of currently active user
4551 LoadLevelSetup_LastSeries();
4552 LoadLevelSetup_SeriesInfo();
4556 static void HandleTypeNameExt(boolean initialize, Key key)
4558 static struct TextPosInfo pos_name = { 0 };
4559 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4560 static int xpos = 0;
4561 struct TextPosInfo *pos = &pos_name;
4562 char key_char = getValidConfigValueChar(getCharFromKey(key));
4563 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4564 boolean active = TRUE;
4568 getTypeNameValues(name, pos, &xpos);
4570 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4571 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4573 StartTextInput(sx, sy, pos->width, pos->height);
4575 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4577 name[xpos] = key_char;
4582 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4588 else if (key == KSYM_Return || key == KSYM_Escape)
4590 boolean changed = (key == KSYM_Return);
4594 setTypeNameValues(name, pos, changed);
4599 drawTypeNameText(name, pos, active);
4603 SetGameStatus(game_status_last_screen);
4605 if (game_status == GAME_MODE_MAIN)
4606 InitializeMainControls();
4610 static void DrawTypeName(void)
4612 HandleTypeNameExt(TRUE, 0);
4615 void HandleTypeName(Key key)
4617 HandleTypeNameExt(FALSE, key);
4621 // ============================================================================
4622 // tree menu functions
4623 // ============================================================================
4625 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4627 if (game_status != GAME_MODE_SETUP ||
4628 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4631 int max_text_size = 0;
4634 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4635 max_text_size = MAX(max_text_size, strlen(node->name));
4637 int num_entries = numTreeInfoInGroup(ti);
4638 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4639 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4640 int text_width = max_text_size * getFontWidth(font_nr);
4641 int button_width = SC_MENUBUTTON_XSIZE;
4642 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4643 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4644 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4645 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4646 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4647 int align_xoffset = MAX(0, align_xoffset_raw);
4649 return align_xoffset;
4652 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4654 if (game_status != GAME_MODE_SETUP ||
4655 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4658 int num_entries = numTreeInfoInGroup(ti);
4659 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4660 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4661 int font_height = getFontHeight(font_nr);
4662 int text_height = font_height * num_page_entries;
4663 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4664 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4665 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4666 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4667 int align_yoffset = MAX(0, align_yoffset_raw);
4669 return align_yoffset;
4672 static void StartPlayingFromHallOfFame(void)
4674 level_nr = scores.next_level_nr;
4675 LoadLevel(level_nr);
4677 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4680 static void DrawChooseTree(TreeInfo **ti_ptr)
4682 int fade_mask = REDRAW_FIELD;
4683 boolean restart_music = (game_status != game_status_last_screen &&
4684 game_status_last_screen != GAME_MODE_SCOREINFO);
4686 scores.continue_on_return = (game_status == GAME_MODE_SCORES &&
4687 game_status_last_screen == GAME_MODE_PLAYING);
4690 fade_mask = REDRAW_ALL;
4692 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4694 if (game_status == GAME_MODE_SETUP)
4698 else if (game_status == GAME_MODE_SCORES && scores.continue_playing)
4700 StartPlayingFromHallOfFame();
4704 SetGameStatus(GAME_MODE_MAIN);
4714 FreeScreenGadgets();
4715 CreateScreenGadgets();
4718 FadeMenuSoundsAndMusic();
4722 // needed if different viewport properties defined for this screen
4723 ChangeViewportPropertiesIfNeeded();
4725 if (game_status == GAME_MODE_NAMES)
4726 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4727 else if (game_status == GAME_MODE_LEVELNR)
4728 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4729 else if (game_status == GAME_MODE_LEVELS)
4730 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4731 else if (game_status == GAME_MODE_SCORES)
4732 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4736 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4738 // map gadgets for high score screen
4739 if (game_status == GAME_MODE_SCORES)
4740 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4742 MapScreenTreeGadgets(*ti_ptr);
4744 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4746 DrawMaskedBorder(fade_mask);
4749 PlayMenuSoundsAndMusic();
4754 static int getChooseTreeFont(TreeInfo *node, boolean active)
4756 if (game_status == GAME_MODE_SCORES)
4757 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4759 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4762 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4764 int num_entries = numTreeInfoInGroup(ti);
4765 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4766 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4767 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4768 int first_entry = ti->cl_first;
4769 int entry_pos = first_entry + y;
4770 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4771 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4772 int font_nr = getChooseTreeFont(node, active);
4773 int font_xoffset = getFontDrawOffsetX(font_nr);
4774 int xpos = MENU_SCREEN_START_XPOS;
4775 int ypos = MENU_SCREEN_START_YPOS + y;
4776 int startdx = xpos * 32;
4777 int startdy = ypos * 32;
4778 int startx = amSX + startdx;
4779 int starty = amSY + startdy;
4780 int startx_text = startx + font_xoffset;
4781 int endx_text = amSX + screen_width;
4782 int max_text_size = endx_text - startx_text;
4783 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4784 char buffer[max_buffer_len + 1];
4786 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4788 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4789 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4790 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4791 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4792 int font_size_1 = getFontWidth(font_nr1);
4793 int font_size_3 = getFontWidth(font_nr3);
4794 int font_size_4 = getFontWidth(font_nr4);
4795 int text_size_1 = 4 * font_size_1;
4796 int text_size_4 = 5 * font_size_4;
4797 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4799 int dx3 = text_size_1;
4800 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4801 int num_dots = (dx4 - dx3) / font_size_3;
4802 int startx1 = startx + dx1;
4803 int startx3 = startx + dx3;
4804 int startx4 = startx + dx4;
4805 int pos = node->pos;
4806 char *pos_text = getHallOfFameRankText(pos, 3);
4809 // highlight all high score entries of the current player
4810 if (strEqual(scores.entry[pos].name, setup.player_name))
4811 font_nr2 = FONT_TEXT_2_ACTIVE;
4813 DrawText(startx1, starty, pos_text, font_nr1);
4815 for (i = 0; i < num_dots; i++)
4816 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4818 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4819 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4821 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4825 strncpy(buffer, node->name, max_buffer_len);
4826 buffer[max_buffer_len] = '\0';
4828 DrawText(startx, starty, buffer, font_nr);
4832 static void drawChooseTreeHeadExt(int type, char *title_string)
4834 int yoffset_sets = MENU_TITLE1_YPOS;
4835 int yoffset_setup = 16;
4836 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4837 type == TREE_TYPE_LEVEL_DIR ||
4838 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4840 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4843 static void drawChooseTreeHead(TreeInfo *ti)
4845 drawChooseTreeHeadExt(ti->type, ti->infotext);
4848 static void drawChooseTreeList(TreeInfo *ti)
4850 int first_entry = ti->cl_first;
4851 int num_entries = numTreeInfoInGroup(ti);
4852 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4855 clearMenuListArea();
4857 for (i = 0; i < num_page_entries; i++)
4859 TreeInfo *node, *node_first;
4860 int entry_pos = first_entry + i;
4862 node_first = getTreeInfoFirstGroupEntry(ti);
4863 node = getTreeInfoFromPos(node_first, entry_pos);
4865 drawChooseTreeText(ti, i, FALSE);
4867 if (node->parent_link)
4868 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4869 else if (node->level_group)
4870 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4872 initCursor(i, IMG_MENU_BUTTON);
4874 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4875 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4877 if (game_status == GAME_MODE_NAMES)
4878 drawChooseTreeEdit(i, FALSE);
4881 redraw_mask |= REDRAW_FIELD;
4884 static void drawChooseTreeInfo(TreeInfo *ti)
4886 int entry_pos = ti->cl_first + ti->cl_cursor;
4887 int last_redraw_mask = redraw_mask;
4888 int ypos = MENU_TITLE2_YPOS;
4889 int font_nr = FONT_TITLE_2;
4892 if (ti->type == TREE_TYPE_LEVEL_NR)
4893 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4895 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4896 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4897 scores.last_level_nr);
4899 if (ti->type != TREE_TYPE_LEVEL_DIR)
4902 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4903 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4905 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4907 if (node->parent_link)
4908 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4909 node->node_parent->name);
4910 else if (node->level_group)
4911 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4913 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4914 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4915 node->levels, (node->levels > 1 ? "levels" : "level"),
4918 // let BackToFront() redraw only what is needed
4919 redraw_mask = last_redraw_mask;
4920 for (x = 0; x < SCR_FIELDX; x++)
4921 MarkTileDirty(x, 1);
4924 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4926 drawChooseTreeCursor(ti->cl_cursor, active);
4927 drawChooseTreeText(ti, ti->cl_cursor, active);
4930 static void drawChooseTreeScreen(TreeInfo *ti)
4932 drawChooseTreeHead(ti);
4933 drawChooseTreeList(ti);
4934 drawChooseTreeInfo(ti);
4935 drawChooseTreeCursorAndText(ti, TRUE);
4937 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4939 // scroll bar and buttons may just have been added after reloading scores
4940 if (game_status == GAME_MODE_SCORES)
4941 MapScreenTreeGadgets(ti);
4944 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4946 int score_pos = scores.last_added;
4948 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4949 score_pos = scores.last_entry_nr;
4951 // set current tree entry to last added score entry
4952 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4954 // if that fails, set current tree entry to first entry (back link)
4955 if (*ti_ptr == NULL)
4956 *ti_ptr = score_entries->node_group;
4958 int num_entries = numTreeInfoInGroup(*ti_ptr);
4959 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4960 int pos_score = getPosFromTreeInfo(*ti_ptr);
4961 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4962 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4964 (*ti_ptr)->cl_first = pos_first;
4965 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4970 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4973 TreeInfo *ti = *ti_ptr;
4974 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4975 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4976 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4977 int sx1_edit_name = getChooseTreeEditXPosReal(POS_LEFT);
4978 int sx2_edit_name = getChooseTreeEditXPosReal(POS_RIGHT);
4980 int y = (ti != NULL ? ti->cl_cursor : 0);
4981 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4982 int num_entries = numTreeInfoInGroup(ti);
4983 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4984 boolean position_set_by_scrollbar = (dx == 999);
4986 if (game_status == GAME_MODE_SCORES)
4988 if (server_scores.updated)
4990 // reload scores, using updated server score cache file
4991 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4993 server_scores.updated = FALSE;
4995 DrawHallOfFame_setScoreEntries();
4997 ti = setHallOfFameActiveEntry(ti_ptr);
4999 if (button != MB_MENU_INITIALIZE)
5000 drawChooseTreeScreen(ti);
5004 if (button == MB_MENU_INITIALIZE)
5006 int num_entries = numTreeInfoInGroup(ti);
5007 int entry_pos = getPosFromTreeInfo(ti);
5009 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5010 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5012 if (game_status == GAME_MODE_SCORES)
5014 ti = setHallOfFameActiveEntry(ti_ptr);
5016 else if (ti->cl_first == -1)
5018 // only on initialization
5019 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5020 ti->cl_cursor = entry_pos - ti->cl_first;
5023 else if (ti->cl_cursor >= num_page_entries ||
5024 (num_entries > num_page_entries &&
5025 num_entries - ti->cl_first < num_page_entries))
5027 // only after change of list size (by custom graphic configuration)
5028 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5029 ti->cl_cursor = entry_pos - ti->cl_first;
5032 if (position_set_by_scrollbar)
5035 drawChooseTreeScreen(ti);
5039 else if (button == MB_MENU_LEAVE)
5041 if (game_status != GAME_MODE_SCORES)
5044 PlaySound(SND_MENU_ITEM_SELECTING);
5046 if (ti->node_parent)
5048 *ti_ptr = ti->node_parent;
5049 DrawChooseTree(ti_ptr);
5051 else if (game_status == GAME_MODE_SETUP)
5053 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5054 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5055 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5056 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5058 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_ENGINE_TYPE ||
5059 setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64 ||
5060 setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV ||
5061 setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI ||
5062 setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE)
5064 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5065 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5066 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5067 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5068 execSetupGraphics();
5069 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5070 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5071 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5073 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5074 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5075 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5076 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5077 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5078 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5079 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5080 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5087 if (game_status == GAME_MODE_LEVELNR)
5089 int new_level_nr = atoi(level_number_current->identifier);
5091 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5094 SetGameStatus(GAME_MODE_MAIN);
5102 #if defined(PLATFORM_ANDROID)
5103 // directly continue when touching the screen after playing
5104 if ((mx || my) && scores.continue_on_return)
5106 // ignore touch events until released
5111 // any mouse click or cursor key stops leaving scores by "Return" key
5112 if ((mx || my || dx || dy) && scores.continue_on_return)
5114 scores.continue_on_return = FALSE;
5115 level_nr = scores.last_level_nr;
5116 LoadLevel(level_nr);
5119 if (mx || my) // mouse input
5121 x = (mx - amSX) / 32;
5122 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5124 if (game_status == GAME_MODE_NAMES)
5125 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5127 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5129 // move cursor instead of scrolling when already at start/end of list
5130 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5132 else if (dy == +1 * SCROLL_LINE &&
5133 ti->cl_first + num_page_entries == num_entries)
5136 // handle scrolling screen one line or page
5137 if (ti->cl_cursor + dy < 0 ||
5138 ti->cl_cursor + dy > num_page_entries - 1)
5140 boolean redraw = FALSE;
5142 if (ABS(dy) == SCROLL_PAGE)
5143 step = num_page_entries - 1;
5145 if (dy < 0 && ti->cl_first > 0)
5147 // scroll page/line up
5149 ti->cl_first -= step;
5150 if (ti->cl_first < 0)
5155 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5157 // scroll page/line down
5159 ti->cl_first += step;
5160 if (ti->cl_first + num_page_entries > num_entries)
5161 ti->cl_first = MAX(0, num_entries - num_page_entries);
5167 drawChooseTreeScreen(ti);
5172 // handle moving cursor one line
5173 y = ti->cl_cursor + dy;
5176 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5178 HandleHallOfFame_SelectLevel(1, dx);
5182 else if (game_status == GAME_MODE_NAMES && dx == 1)
5184 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5192 TreeInfo *node_first, *node_cursor;
5193 int entry_pos = ti->cl_first + y;
5195 node_first = getTreeInfoFirstGroupEntry(ti);
5196 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5198 if (node_cursor->node_group)
5202 PlaySound(SND_MENU_ITEM_SELECTING);
5204 node_cursor->cl_first = ti->cl_first;
5205 node_cursor->cl_cursor = ti->cl_cursor;
5207 *ti_ptr = node_cursor->node_group;
5208 DrawChooseTree(ti_ptr);
5213 else if ((dx == -1 || button == MB_MENU_CONTINUE) && ti->node_parent)
5215 if (game_status != GAME_MODE_SCORES)
5218 PlaySound(SND_MENU_ITEM_SELECTING);
5220 *ti_ptr = ti->node_parent;
5221 DrawChooseTree(ti_ptr);
5226 if (!anyScrollbarGadgetActive() &&
5227 IN_VIS_MENU(x, y) &&
5228 mx < mx_right_border &&
5229 y >= 0 && y < num_page_entries)
5233 if (game_status == GAME_MODE_NAMES)
5235 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5236 drawChooseTreeEdit(y, TRUE);
5239 if (y != ti->cl_cursor)
5241 PlaySound(SND_MENU_ITEM_ACTIVATING);
5243 drawChooseTreeCursorAndText(ti, FALSE);
5247 drawChooseTreeCursorAndText(ti, TRUE);
5249 drawChooseTreeInfo(ti);
5253 if (game_status == GAME_MODE_SETUP)
5255 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5256 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5257 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5258 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5260 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_ENGINE_TYPE ||
5261 setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64 ||
5262 setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV ||
5263 setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI ||
5264 setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE)
5266 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5267 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5268 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5269 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5270 execSetupGraphics();
5271 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5272 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5273 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5275 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5276 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5277 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5278 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5279 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5280 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5281 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5282 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5291 TreeInfo *node_first, *node_cursor;
5292 int entry_pos = ti->cl_first + y;
5294 PlaySound(SND_MENU_ITEM_SELECTING);
5296 node_first = getTreeInfoFirstGroupEntry(ti);
5297 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5299 if (node_cursor->node_group)
5303 node_cursor->cl_first = ti->cl_first;
5304 node_cursor->cl_cursor = ti->cl_cursor;
5306 *ti_ptr = node_cursor->node_group;
5307 DrawChooseTree(ti_ptr);
5309 else if (node_cursor->parent_link)
5311 if (game_status != GAME_MODE_SCORES)
5314 *ti_ptr = node_cursor->node_parent;
5315 DrawChooseTree(ti_ptr);
5319 if (game_status != GAME_MODE_SCORES)
5322 node_cursor->cl_first = ti->cl_first;
5323 node_cursor->cl_cursor = ti->cl_cursor;
5325 *ti_ptr = node_cursor;
5327 if (ti->type == TREE_TYPE_LEVEL_DIR)
5329 LoadLevelSetup_SeriesInfo();
5331 SaveLevelSetup_LastSeries();
5332 SaveLevelSetup_SeriesInfo();
5336 if (game_status == GAME_MODE_SETUP)
5338 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5339 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5340 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5341 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5343 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_ENGINE_TYPE ||
5344 setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64 ||
5345 setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV ||
5346 setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI ||
5347 setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE)
5349 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5350 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5351 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5352 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5353 execSetupGraphics();
5354 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5355 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5356 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5358 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5359 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5360 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5361 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5362 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5363 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5364 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5365 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5372 if (game_status == GAME_MODE_LEVELNR)
5374 int new_level_nr = atoi(level_number_current->identifier);
5376 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5378 else if (game_status == GAME_MODE_LEVELS)
5380 // store level set if chosen from "last played level set" menu
5381 StoreLastPlayedLevels(leveldir_current);
5383 // store if level set chosen from "last played level set" menu
5384 SaveLevelSetup_LastSeries();
5386 else if (game_status == GAME_MODE_NAMES)
5388 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5390 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5397 // change active user to selected user
5398 user.nr = entry_pos;
5400 // save number of new active user
5403 // load setup of new active user
5406 // load last level set of new active user
5407 LoadLevelSetup_LastSeries();
5408 LoadLevelSetup_SeriesInfo();
5410 // update list of last played level sets
5411 UpdateLastPlayedLevels_TreeInfo();
5415 ToggleFullscreenIfNeeded();
5416 ChangeWindowScalingIfNeeded();
5418 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5419 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5420 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5422 else if (game_status == GAME_MODE_SCORES)
5424 if (scores.continue_playing && scores.continue_on_return)
5426 StartPlayingFromHallOfFame();
5430 else if (!scores.continue_on_return)
5432 SetGameStatus(GAME_MODE_SCOREINFO);
5434 DrawScoreInfo(node_cursor->pos);
5440 SetGameStatus(GAME_MODE_MAIN);
5448 if (game_status == GAME_MODE_SCORES)
5449 PlayMenuSoundIfLoop();
5452 void DrawChoosePlayerName(void)
5456 if (player_name != NULL)
5458 freeTreeInfo(player_name);
5463 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5465 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5466 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5469 ti->node_top = &player_name;
5470 ti->sort_priority = 10000 + value;
5471 ti->color = getPlayerNameColor(global.user_names[i]);
5473 snprintf(identifier, sizeof(identifier), "%d", value);
5474 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5476 setString(&ti->identifier, identifier);
5477 setString(&ti->name, name);
5478 setString(&ti->name_sorting, name);
5480 pushTreeInfo(&player_name, ti);
5483 // sort player entries by player number
5484 sortTreeInfo(&player_name);
5486 // set current player entry to selected player entry
5487 player_name_current =
5488 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5490 // if that fails, set current player name to first available name
5491 if (player_name_current == NULL)
5492 player_name_current = player_name;
5494 // set text size for main name input (also used on name selection screen)
5495 InitializeMainControls();
5497 DrawChooseTree(&player_name_current);
5500 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5502 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5505 void DrawChooseLevelSet(void)
5507 DrawChooseTree(&leveldir_current);
5510 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5512 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5515 void DrawChooseLevelNr(void)
5519 if (level_number != NULL)
5521 freeTreeInfo(level_number);
5523 level_number = NULL;
5526 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5528 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5529 char identifier[32], name[64];
5532 // temporarily load level info to get level name
5533 LoadLevelInfoOnly(i);
5535 ti->node_top = &level_number;
5536 ti->sort_priority = 10000 + value;
5537 ti->color = (level.no_level_file ? FC_BLUE :
5538 LevelStats_getSolved(i) ? FC_GREEN :
5539 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5541 snprintf(identifier, sizeof(identifier), "%d", value);
5542 snprintf(name, sizeof(name), "%03d: %s", value,
5543 (level.no_level_file ? "(no file)" : level.name));
5545 setString(&ti->identifier, identifier);
5546 setString(&ti->name, name);
5547 setString(&ti->name_sorting, name);
5549 pushTreeInfo(&level_number, ti);
5552 // sort level number values to start with lowest level number
5553 sortTreeInfo(&level_number);
5555 // set current level number to current level number
5556 level_number_current =
5557 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5559 // if that also fails, set current level number to first available level
5560 if (level_number_current == NULL)
5561 level_number_current = level_number;
5563 DrawChooseTree(&level_number_current);
5566 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5568 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5571 static void DrawHallOfFame_setScoreEntries(void)
5573 int max_empty_entries = 10; // at least show "top ten" list, if empty
5574 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5575 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5576 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5579 if (score_entries != NULL)
5581 freeTreeInfo(score_entries);
5583 score_entries = NULL;
5586 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5588 // do not add empty score entries if off-screen
5589 if (scores.entry[i].score == 0 &&
5590 scores.entry[i].time == 0 &&
5591 i >= min_score_entries)
5594 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5595 char identifier[32], name[64];
5598 ti->node_top = &score_entries;
5599 ti->sort_priority = 10000 + value;
5600 ti->color = FC_YELLOW;
5603 snprintf(identifier, sizeof(identifier), "%d", value);
5604 snprintf(name, sizeof(name), "%03d.", value + 1);
5606 setString(&ti->identifier, identifier);
5607 setString(&ti->name, name);
5608 setString(&ti->name_sorting, name);
5610 pushTreeInfo(&score_entries, ti);
5613 // sort score entries to start with highest score entry
5614 sortTreeInfo(&score_entries);
5616 // add top tree node to create back link to main menu
5617 score_entries = addTopTreeInfoNode(score_entries);
5619 // set current score entry to last added or highest score entry
5620 score_entry_current =
5621 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5623 // if that fails, set current score entry to first valid score entry
5624 if (score_entry_current == NULL)
5625 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5627 if (score_entries != NULL && scores.continue_playing)
5628 setString(&score_entries->node_group->name, BACKLINK_TEXT_NEXT);
5631 void DrawHallOfFame(int nr)
5633 scores.last_level_nr = nr;
5635 // (this is needed when called from GameEnd() after winning a game)
5636 KeyboardAutoRepeatOn();
5638 // (this is needed when called from GameEnd() after winning a game)
5639 SetDrawDeactivationMask(REDRAW_NONE);
5640 SetDrawBackgroundMask(REDRAW_FIELD);
5642 LoadLocalAndServerScore(scores.last_level_nr, TRUE);
5644 DrawHallOfFame_setScoreEntries();
5646 if (scores.last_added >= 0)
5647 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5649 FadeSetEnterScreen();
5651 DrawChooseTree(&score_entry_current);
5654 static char *getHallOfFameRankText(int nr, int size)
5656 static char rank_text[10];
5657 boolean forced = (scores.force_last_added && nr == scores.last_added);
5658 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5660 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5665 static char *getHallOfFameTimeText(int nr)
5667 static char score_text[10];
5668 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5669 int mm = (time_seconds / 60) % 60;
5670 int ss = (time_seconds % 60);
5672 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5677 static char *getHallOfFameScoreText(int nr, int size)
5679 if (!level.rate_time_over_score)
5680 return int2str(scores.entry[nr].score, size); // show normal score
5681 else if (level.use_step_counter)
5682 return int2str(scores.entry[nr].time, size); // show number of steps
5684 return getHallOfFameTimeText(nr); // show playing time
5687 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5689 static char tape_date[MAX_ISO_DATE_LEN + 1];
5692 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5693 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5694 return entry->tape_date;
5696 for (i = 0, j = 0; i < 8; i++, j++)
5698 tape_date[j] = entry->tape_basename[i];
5700 if (i == 3 || i == 5)
5701 tape_date[++j] = '-';
5704 tape_date[MAX_ISO_DATE_LEN] = '\0';
5709 static void HandleHallOfFame_SelectLevel(int step, int direction)
5711 int old_level_nr = scores.last_level_nr;
5712 int new_level_nr = old_level_nr + step * direction;
5714 if (new_level_nr < leveldir_current->first_level)
5715 new_level_nr = leveldir_current->first_level;
5716 if (new_level_nr > leveldir_current->last_level)
5717 new_level_nr = leveldir_current->last_level;
5719 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5720 new_level_nr = leveldir_current->handicap_level;
5722 if (new_level_nr != old_level_nr)
5724 PlaySound(SND_MENU_ITEM_SELECTING);
5726 scores.last_level_nr = level_nr = new_level_nr;
5727 scores.last_entry_nr = 0;
5729 LoadLevel(level_nr);
5730 LoadLocalAndServerScore(level_nr, TRUE);
5732 DrawHallOfFame_setScoreEntries();
5734 if (game_status == GAME_MODE_SCORES)
5736 // force remapping optional gadgets (especially scroll bar)
5737 UnmapScreenTreeGadgets();
5739 // redraw complete high score screen, as sub-title has changed
5742 // redraw level selection buttons (which have just been erased)
5743 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5745 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5749 DrawScoreInfo_Content(scores.last_entry_nr);
5752 SaveLevelSetup_SeriesInfo();
5756 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5758 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5761 static void DrawScoreInfo_Content(int entry_nr)
5763 struct ScoreEntry *entry = &scores.entry[entry_nr];
5764 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5765 char *tape_date = getHallOfFameTapeDateText(entry);
5766 int font_head = MENU_INFO_FONT_HEAD;
5767 int font_text = MENU_INFO_FONT_TEXT;
5768 int font_foot = MENU_INFO_FONT_FOOT;
5769 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5770 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5771 int spacing_left = menu.left_spacing[GAME_MODE_SCOREINFO];
5772 int spacing_top = menu.top_spacing[GAME_MODE_SCOREINFO];
5773 int xstep = getFontWidth(font_text);
5774 int ystep_para = getMenuTextStep(spacing_para, font_text);
5775 int ystep_line = getMenuTextStep(spacing_line, font_text);
5776 int xstart = mSX - SX + spacing_left;
5777 int ystart = mSY - SY + spacing_top + getHeadlineSpacing();
5778 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5779 int xstart1 = xstart + xstep;
5780 int xstart2 = xstart + xstep * 12;
5781 int select_x = SX + xstart1;
5782 int select_y1, select_y2;
5784 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5785 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5786 int font_width = getFontWidth(font_text);
5787 int font_height = getFontHeight(font_text);
5788 int tape_date_width = getTextWidth(tape_date, font_text);
5789 int pad_left = xstart2;
5790 int pad_right = menu.right_spacing[GAME_MODE_SCOREINFO];
5791 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5792 int max_lines_per_text = 5;
5797 // redraw level selection buttons (which have just been erased)
5798 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5800 drawChooseTreeHead(score_entries);
5801 drawChooseTreeInfo(score_entries);
5803 DrawTextF(xstart1, ystart, font_head, "Level Set");
5804 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5805 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5806 TRUE, FALSE, FALSE);
5807 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5809 DrawTextF(xstart1, ystart, font_head, "Level");
5810 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5811 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5812 TRUE, FALSE, FALSE);
5813 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5815 select_y1 = SY + ystart;
5816 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5818 DrawTextF(xstart1, ystart, font_head, "Rank");
5819 DrawTextF(xstart2, ystart, font_text, pos_text);
5820 ystart += ystep_line;
5822 DrawTextF(xstart1, ystart, font_head, "Player");
5823 DrawTextF(xstart2, ystart, font_text, entry->name);
5824 ystart += ystep_line;
5826 if (level.use_step_counter)
5828 DrawTextF(xstart1, ystart, font_head, "Steps");
5829 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5830 ystart += ystep_line;
5834 DrawTextF(xstart1, ystart, font_head, "Time");
5835 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5836 ystart += ystep_line;
5839 if (!level.rate_time_over_score || entry->score > 0)
5841 DrawTextF(xstart1, ystart, font_head, "Score");
5842 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5843 ystart += ystep_line;
5846 ystart += ystep_line;
5848 play_x = SX + xstart2 + tape_date_width + font_width;
5849 play_y = SY + ystart + (font_height - play_height) / 2;
5851 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5852 DrawTextF(xstart2, ystart, font_text, tape_date);
5853 ystart += ystep_line;
5855 DrawTextF(xstart1, ystart, font_head, "Platform");
5856 DrawTextF(xstart2, ystart, font_text, entry->platform);
5857 ystart += ystep_line;
5859 DrawTextF(xstart1, ystart, font_head, "Version");
5860 DrawTextF(xstart2, ystart, font_text, entry->version);
5861 ystart += ystep_line;
5863 DrawTextF(xstart1, ystart, font_head, "Country");
5864 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5865 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5866 TRUE, FALSE, FALSE);
5867 ystart += ystep_line;
5869 select_y2 = SY + ystart;
5871 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5873 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5874 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5877 static void DrawScoreInfo(int entry_nr)
5879 scores.last_entry_nr = entry_nr;
5880 score_info_tape_play = FALSE;
5884 FreeScreenGadgets();
5885 CreateScreenGadgets();
5887 FadeOut(REDRAW_FIELD);
5889 // needed if different viewport properties defined after playing score tape
5890 ChangeViewportPropertiesIfNeeded();
5892 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
5893 SetDrawDeactivationMask(REDRAW_NONE);
5894 SetDrawBackgroundMask(REDRAW_FIELD);
5896 // needed if different background image defined after playing score tape
5897 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5898 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5900 // special compatibility handling for "Snake Bite" graphics set
5901 if (strPrefix(leveldir_current->identifier, "snake_bite"))
5902 ClearRectangle(gfx.background_bitmap, gfx.real_sx, gfx.real_sy + 64,
5903 gfx.full_sxsize, gfx.full_sysize - 64);
5905 DrawScoreInfo_Content(entry_nr);
5907 // map gadgets for score info screen
5908 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5910 FadeIn(REDRAW_FIELD);
5913 static void HandleScoreInfo_SelectScore(int step, int direction)
5915 int old_entry_nr = scores.last_entry_nr;
5916 int new_entry_nr = old_entry_nr + step * direction;
5917 int num_nodes = numTreeInfoInGroup(score_entry_current);
5918 int num_entries = num_nodes - 1; // score nodes only, without back link
5920 if (new_entry_nr < 0)
5922 if (new_entry_nr > num_entries - 1)
5923 new_entry_nr = num_entries - 1;
5925 if (new_entry_nr != old_entry_nr)
5927 scores.last_entry_nr = new_entry_nr;
5929 DrawScoreInfo_Content(new_entry_nr);
5933 static void HandleScoreInfo_PlayTape(void)
5935 if (!PlayScoreTape(scores.last_entry_nr))
5937 DrawScoreInfo_Content(scores.last_entry_nr);
5939 FadeIn(REDRAW_FIELD);
5943 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5945 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5946 boolean button_is_valid = (mx >= 0 && my >= 0);
5947 boolean button_screen_clicked = (button_action && button_is_valid);
5949 if (server_scores.updated)
5951 // reload scores, using updated server score cache file
5952 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5954 server_scores.updated = FALSE;
5956 DrawHallOfFame_setScoreEntries();
5958 DrawScoreInfo_Content(scores.last_entry_nr);
5961 if (button_screen_clicked)
5963 PlaySound(SND_MENU_ITEM_SELECTING);
5965 SetGameStatus(GAME_MODE_SCORES);
5967 DrawHallOfFame(scores.last_level_nr);
5971 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5975 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5980 // ============================================================================
5981 // setup screen functions
5982 // ============================================================================
5984 static struct TokenInfo *setup_info;
5985 static int num_setup_info; // number of setup entries shown on screen
5986 static int max_setup_info; // total number of setup entries in list
5988 static char *window_size_text;
5989 static char *scaling_type_text;
5990 static char *rendering_mode_text;
5991 static char *vsync_mode_text;
5992 static char *scroll_delay_text;
5993 static char *snapshot_mode_text;
5994 static char *game_engine_type_text;
5995 static char *bd_palette_c64_text;
5996 static char *bd_palette_c64dtv_text;
5997 static char *bd_palette_atari_text;
5998 static char *bd_color_type_text;
5999 static char *game_speed_text;
6000 static char *scores_type_text;
6001 static char *network_server_text;
6002 static char *graphics_set_name;
6003 static char *sounds_set_name;
6004 static char *music_set_name;
6005 static char *volume_simple_text;
6006 static char *volume_loops_text;
6007 static char *volume_music_text;
6008 static char *touch_controls_text;
6009 static char *move_distance_text;
6010 static char *drop_distance_text;
6011 static char *transparency_text;
6012 static char *grid_size_text[2][2];
6014 static void execSetupMain(void)
6016 setup_mode = SETUP_MODE_MAIN;
6021 static void execSetupGame_setScoresType(void)
6023 if (scores_types == NULL)
6027 for (i = 0; scores_types_list[i].value != NULL; i++)
6029 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6030 char identifier[32], name[32];
6031 char *value = scores_types_list[i].value;
6032 char *text = scores_types_list[i].text;
6034 ti->node_top = &scores_types;
6035 ti->sort_priority = i;
6037 sprintf(identifier, "%s", value);
6038 sprintf(name, "%s", text);
6040 setString(&ti->identifier, identifier);
6041 setString(&ti->name, name);
6042 setString(&ti->name_sorting, name);
6043 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
6045 pushTreeInfo(&scores_types, ti);
6048 // sort scores type values to start with lowest scores type value
6049 sortTreeInfo(&scores_types);
6051 // set current scores type value to configured scores type value
6052 scores_type_current =
6053 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
6055 // if that fails, set current scores type to reliable default value
6056 if (scores_type_current == NULL)
6057 scores_type_current =
6058 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
6060 // if that also fails, set current scores type to first available value
6061 if (scores_type_current == NULL)
6062 scores_type_current = scores_types;
6065 setup.scores_in_highscore_list = scores_type_current->identifier;
6067 // needed for displaying scores type text instead of identifier
6068 scores_type_text = scores_type_current->name;
6071 static void execSetupGame_setGameSpeeds(boolean update_value)
6073 if (setup.game_speed_extended)
6075 game_speeds_list = game_speeds_list_extended;
6076 game_speeds = game_speeds_extended;
6080 game_speeds_list = game_speeds_list_normal;
6081 game_speeds = game_speeds_normal;
6084 if (game_speeds == NULL)
6088 for (i = 0; game_speeds_list[i].value != -1; i++)
6090 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6091 char identifier[32], name[32];
6092 int value = game_speeds_list[i].value;
6093 char *text = game_speeds_list[i].text;
6095 ti->node_top = &game_speeds;
6096 ti->sort_priority = 10000 - value;
6098 sprintf(identifier, "%d", value);
6099 sprintf(name, "%s", text);
6101 setString(&ti->identifier, identifier);
6102 setString(&ti->name, name);
6103 setString(&ti->name_sorting, name);
6104 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
6106 pushTreeInfo(&game_speeds, ti);
6109 // sort game speed values to start with slowest game speed
6110 sortTreeInfo(&game_speeds);
6112 update_value = TRUE;
6117 // set current game speed to configured game speed value
6118 game_speed_current =
6119 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6121 // if that fails, set current game speed to reliable default value
6122 if (game_speed_current == NULL)
6123 game_speed_current =
6124 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6126 // if that also fails, set current game speed to first available speed
6127 if (game_speed_current == NULL)
6128 game_speed_current = game_speeds;
6130 if (setup.game_speed_extended)
6131 game_speeds_extended = game_speeds;
6133 game_speeds_normal = game_speeds;
6136 setup.game_frame_delay = atoi(game_speed_current->identifier);
6138 // needed for displaying game speed text instead of identifier
6139 game_speed_text = game_speed_current->name;
6142 static void execSetupGame_setScrollDelays(void)
6144 if (scroll_delays == NULL)
6148 for (i = 0; scroll_delays_list[i].value != -1; i++)
6150 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6151 char identifier[32], name[32];
6152 int value = scroll_delays_list[i].value;
6153 char *text = scroll_delays_list[i].text;
6155 ti->node_top = &scroll_delays;
6156 ti->sort_priority = value;
6158 sprintf(identifier, "%d", value);
6159 sprintf(name, "%s", text);
6161 setString(&ti->identifier, identifier);
6162 setString(&ti->name, name);
6163 setString(&ti->name_sorting, name);
6164 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6166 pushTreeInfo(&scroll_delays, ti);
6169 // sort scroll delay values to start with lowest scroll delay value
6170 sortTreeInfo(&scroll_delays);
6172 // set current scroll delay value to configured scroll delay value
6173 scroll_delay_current =
6174 getTreeInfoFromIdentifier(scroll_delays, i_to_a(setup.scroll_delay_value));
6176 // if that fails, set current scroll delay to reliable default value
6177 if (scroll_delay_current == NULL)
6178 scroll_delay_current =
6179 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6181 // if that also fails, set current scroll delay to first available value
6182 if (scroll_delay_current == NULL)
6183 scroll_delay_current = scroll_delays;
6186 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6188 // needed for displaying scroll delay text instead of identifier
6189 scroll_delay_text = scroll_delay_current->name;
6192 static void execSetupGame_setSnapshotModes(void)
6194 if (snapshot_modes == NULL)
6198 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6200 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6201 char identifier[32], name[32];
6202 char *value = snapshot_modes_list[i].value;
6203 char *text = snapshot_modes_list[i].text;
6205 ti->node_top = &snapshot_modes;
6206 ti->sort_priority = i;
6208 sprintf(identifier, "%s", value);
6209 sprintf(name, "%s", text);
6211 setString(&ti->identifier, identifier);
6212 setString(&ti->name, name);
6213 setString(&ti->name_sorting, name);
6214 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6216 pushTreeInfo(&snapshot_modes, ti);
6219 // sort snapshot mode values to start with lowest snapshot mode value
6220 sortTreeInfo(&snapshot_modes);
6222 // set current snapshot mode value to configured snapshot mode value
6223 snapshot_mode_current =
6224 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6226 // if that fails, set current snapshot mode to reliable default value
6227 if (snapshot_mode_current == NULL)
6228 snapshot_mode_current =
6229 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6231 // if that also fails, set current snapshot mode to first available value
6232 if (snapshot_mode_current == NULL)
6233 snapshot_mode_current = snapshot_modes;
6236 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6238 // needed for displaying snapshot mode text instead of identifier
6239 snapshot_mode_text = snapshot_mode_current->name;
6242 static void execSetupGame_setNetworkServerText(void)
6244 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6246 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6250 strncpy(network_server_hostname, setup.network_server_hostname,
6251 MAX_SETUP_TEXT_INPUT_LEN);
6252 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6255 // needed for displaying network server text instead of identifier
6256 network_server_text = network_server_hostname;
6259 static void execSetupGame(void)
6261 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6263 execSetupGame_setGameSpeeds(FALSE);
6264 execSetupGame_setScoresType();
6265 execSetupGame_setScrollDelays();
6266 execSetupGame_setSnapshotModes();
6268 execSetupGame_setNetworkServerText();
6270 if (!setup.provide_uploading_tapes)
6271 setHideSetupEntry(execOfferUploadTapes);
6273 setup_mode = SETUP_MODE_GAME;
6277 // check if vsync needs to be disabled for this game speed to work
6278 if (check_vsync_mode)
6279 DisableVsyncIfNeeded();
6282 static void execSetupChooseScoresType(void)
6284 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6289 static void execSetupChooseGameSpeed(void)
6291 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6296 static void execSetupChooseScrollDelay(void)
6298 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6303 static void execSetupChooseSnapshotMode(void)
6305 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6310 static void execSetupEngines_setGameEngineType(void)
6312 if (game_engine_types == NULL)
6316 for (i = 0; game_engine_types_list[i].value != -1; i++)
6318 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6319 char identifier[32], name[32];
6320 int value = game_engine_types_list[i].value;
6321 char *text = game_engine_types_list[i].text;
6323 ti->node_top = &game_engine_types;
6324 ti->sort_priority = value;
6326 sprintf(identifier, "%d", value);
6327 sprintf(name, "%s", text);
6329 setString(&ti->identifier, identifier);
6330 setString(&ti->name, name);
6331 setString(&ti->name_sorting, name);
6332 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_ENGINE_TYPE);
6334 pushTreeInfo(&game_engine_types, ti);
6337 // sort game engine type values to start with lowest game engine type value
6338 sortTreeInfo(&game_engine_types);
6340 // set current game engine type value to configured game engine type value
6341 game_engine_type_current =
6342 getTreeInfoFromIdentifier(game_engine_types, i_to_a(setup.default_game_engine_type));
6344 // if that fails, set current game engine type to reliable default value
6345 if (game_engine_type_current == NULL)
6346 game_engine_type_current =
6347 getTreeInfoFromIdentifier(game_engine_types, i_to_a(GAME_ENGINE_TYPE_RND));
6349 // if that also fails, set current game engine type to first available value
6350 if (game_engine_type_current == NULL)
6351 game_engine_type_current = game_engine_types;
6354 setup.default_game_engine_type = atoi(game_engine_type_current->identifier);
6356 // needed for displaying game engine type text instead of identifier
6357 game_engine_type_text = game_engine_type_current->name;
6360 static void execSetupEngines_setPalettesC64(void)
6362 if (bd_palettes_c64 == NULL)
6366 for (i = 0; bd_palettes_c64_list[i].value != -1; i++)
6368 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6369 char identifier[32], name[32];
6370 int value = bd_palettes_c64_list[i].value;
6371 char *text = bd_palettes_c64_list[i].text;
6373 ti->node_top = &bd_palettes_c64;
6374 ti->sort_priority = value;
6376 sprintf(identifier, "%d", value);
6377 sprintf(name, "%s", text);
6379 setString(&ti->identifier, identifier);
6380 setString(&ti->name, name);
6381 setString(&ti->name_sorting, name);
6382 setString(&ti->infotext, STR_SETUP_CHOOSE_BD_PALETTE_C64);
6384 pushTreeInfo(&bd_palettes_c64, ti);
6387 // sort palette values to start with lowest palette value
6388 sortTreeInfo(&bd_palettes_c64);
6390 // set current palette value to configured palette value
6391 bd_palette_c64_current =
6392 getTreeInfoFromIdentifier(bd_palettes_c64, i_to_a(setup.bd_palette_c64));
6394 // if that fails, set current palette to reliable default value
6395 if (bd_palette_c64_current == NULL)
6396 bd_palette_c64_current =
6397 getTreeInfoFromIdentifier(bd_palettes_c64, i_to_a(GD_DEFAULT_PALETTE_C64));
6399 // if that also fails, set current palette to first available value
6400 if (bd_palette_c64_current == NULL)
6401 bd_palette_c64_current = bd_palettes_c64;
6404 setup.bd_palette_c64 = atoi(bd_palette_c64_current->identifier);
6406 // needed for displaying palette text instead of identifier
6407 bd_palette_c64_text = bd_palette_c64_current->name;
6410 static void execSetupEngines_setPalettesC64DTV(void)
6412 if (bd_palettes_c64dtv == NULL)
6416 for (i = 0; bd_palettes_c64dtv_list[i].value != -1; i++)
6418 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6419 char identifier[32], name[32];
6420 int value = bd_palettes_c64dtv_list[i].value;
6421 char *text = bd_palettes_c64dtv_list[i].text;
6423 ti->node_top = &bd_palettes_c64dtv;
6424 ti->sort_priority = value;
6426 sprintf(identifier, "%d", value);
6427 sprintf(name, "%s", text);
6429 setString(&ti->identifier, identifier);
6430 setString(&ti->name, name);
6431 setString(&ti->name_sorting, name);
6432 setString(&ti->infotext, STR_SETUP_CHOOSE_BD_PALETTE_C64DTV);
6434 pushTreeInfo(&bd_palettes_c64dtv, ti);
6437 // sort palette values to start with lowest palette value
6438 sortTreeInfo(&bd_palettes_c64dtv);
6440 // set current palette value to configured palette value
6441 bd_palette_c64dtv_current =
6442 getTreeInfoFromIdentifier(bd_palettes_c64dtv, i_to_a(setup.bd_palette_c64dtv));
6444 // if that fails, set current palette to reliable default value
6445 if (bd_palette_c64dtv_current == NULL)
6446 bd_palette_c64dtv_current =
6447 getTreeInfoFromIdentifier(bd_palettes_c64dtv, i_to_a(GD_DEFAULT_PALETTE_C64DTV));
6449 // if that also fails, set current palette to first available value
6450 if (bd_palette_c64dtv_current == NULL)
6451 bd_palette_c64dtv_current = bd_palettes_c64dtv;
6454 setup.bd_palette_c64dtv = atoi(bd_palette_c64dtv_current->identifier);
6456 // needed for displaying palette text instead of identifier
6457 bd_palette_c64dtv_text = bd_palette_c64dtv_current->name;
6460 static void execSetupEngines_setPalettesAtari(void)
6462 if (bd_palettes_atari == NULL)
6466 for (i = 0; bd_palettes_atari_list[i].value != -1; i++)
6468 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6469 char identifier[32], name[32];
6470 int value = bd_palettes_atari_list[i].value;
6471 char *text = bd_palettes_atari_list[i].text;
6473 ti->node_top = &bd_palettes_atari;
6474 ti->sort_priority = value;
6476 sprintf(identifier, "%d", value);
6477 sprintf(name, "%s", text);
6479 setString(&ti->identifier, identifier);
6480 setString(&ti->name, name);
6481 setString(&ti->name_sorting, name);
6482 setString(&ti->infotext, STR_SETUP_CHOOSE_BD_PALETTE_ATARI);
6484 pushTreeInfo(&bd_palettes_atari, ti);
6487 // sort palette values to start with lowest palette value
6488 sortTreeInfo(&bd_palettes_atari);
6490 // set current palette value to configured palette value
6491 bd_palette_atari_current =
6492 getTreeInfoFromIdentifier(bd_palettes_atari, i_to_a(setup.bd_palette_atari));
6494 // if that fails, set current palette to reliable default value
6495 if (bd_palette_atari_current == NULL)
6496 bd_palette_atari_current =
6497 getTreeInfoFromIdentifier(bd_palettes_atari, i_to_a(GD_DEFAULT_PALETTE_ATARI));
6499 // if that also fails, set current palette to first available value
6500 if (bd_palette_atari_current == NULL)
6501 bd_palette_atari_current = bd_palettes_atari;
6504 setup.bd_palette_atari = atoi(bd_palette_atari_current->identifier);
6506 // needed for displaying palette text instead of identifier
6507 bd_palette_atari_text = bd_palette_atari_current->name;
6510 static void execSetupEngines_setColorType(void)
6512 if (bd_color_types == NULL)
6516 for (i = 0; bd_color_types_list[i].value != -1; i++)
6518 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6519 char identifier[32], name[32];
6520 int value = bd_color_types_list[i].value;
6521 char *text = bd_color_types_list[i].text;
6523 ti->node_top = &bd_color_types;
6524 ti->sort_priority = value;
6526 sprintf(identifier, "%d", value);
6527 sprintf(name, "%s", text);
6529 setString(&ti->identifier, identifier);
6530 setString(&ti->name, name);
6531 setString(&ti->name_sorting, name);
6532 setString(&ti->infotext, STR_SETUP_CHOOSE_BD_COLOR_TYPE);
6534 pushTreeInfo(&bd_color_types, ti);
6537 // sort color type values to start with lowest color type value
6538 sortTreeInfo(&bd_color_types);
6540 // set current color type value to configured color type value
6541 bd_color_type_current =
6542 getTreeInfoFromIdentifier(bd_color_types, i_to_a(setup.bd_default_color_type));
6544 // if that fails, set current color type to reliable default value
6545 if (bd_color_type_current == NULL)
6546 bd_color_type_current =
6547 getTreeInfoFromIdentifier(bd_color_types, i_to_a(GD_DEFAULT_COLOR_TYPE));
6549 // if that also fails, set current color type to first available value
6550 if (bd_color_type_current == NULL)
6551 bd_color_type_current = bd_color_types;
6554 setup.bd_default_color_type = atoi(bd_color_type_current->identifier);
6556 // needed for displaying color type text instead of identifier
6557 bd_color_type_text = bd_color_type_current->name;
6560 static void execSetupEngines(void)
6562 setup_mode = SETUP_MODE_ENGINES;
6564 execSetupEngines_setGameEngineType();
6565 execSetupEngines_setPalettesC64();
6566 execSetupEngines_setPalettesC64DTV();
6567 execSetupEngines_setPalettesAtari();
6568 execSetupEngines_setColorType();
6573 static void execSetupChooseGameEngineType(void)
6575 setup_mode = SETUP_MODE_CHOOSE_GAME_ENGINE_TYPE;
6580 static void execSetupChoosePaletteC64(void)
6582 setup_mode = SETUP_MODE_CHOOSE_BD_PALETTE_C64;
6587 static void execSetupChoosePaletteC64DTV(void)
6589 setup_mode = SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV;
6594 static void execSetupChoosePaletteAtari(void)
6596 setup_mode = SETUP_MODE_CHOOSE_BD_PALETTE_ATARI;
6601 static void execSetupChooseColorType(void)
6603 setup_mode = SETUP_MODE_CHOOSE_BD_COLOR_TYPE;
6608 static void execSetupEditor(void)
6610 setup_mode = SETUP_MODE_EDITOR;
6615 static void execSetupGraphics_setWindowSizes(boolean update_list)
6617 if (window_sizes != NULL && update_list)
6619 freeTreeInfo(window_sizes);
6621 window_sizes = NULL;
6624 if (window_sizes == NULL)
6626 boolean current_window_size_found = FALSE;
6629 for (i = 0; window_sizes_list[i].value != -1; i++)
6631 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6632 char identifier[32], name[32];
6633 int value = window_sizes_list[i].value;
6634 char *text = window_sizes_list[i].text;
6636 ti->node_top = &window_sizes;
6637 ti->sort_priority = value;
6639 sprintf(identifier, "%d", value);
6640 sprintf(name, "%s", text);
6642 setString(&ti->identifier, identifier);
6643 setString(&ti->name, name);
6644 setString(&ti->name_sorting, name);
6645 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6647 pushTreeInfo(&window_sizes, ti);
6649 if (value == setup.window_scaling_percent)
6650 current_window_size_found = TRUE;
6653 if (!current_window_size_found)
6655 // add entry for non-preset window scaling value
6657 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6658 char identifier[32], name[32];
6659 int value = setup.window_scaling_percent;
6661 ti->node_top = &window_sizes;
6662 ti->sort_priority = value;
6664 sprintf(identifier, "%d", value);
6665 sprintf(name, "%d %% (Current)", value);
6667 setString(&ti->identifier, identifier);
6668 setString(&ti->name, name);
6669 setString(&ti->name_sorting, name);
6670 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6672 pushTreeInfo(&window_sizes, ti);
6675 // sort window size values to start with lowest window size value
6676 sortTreeInfo(&window_sizes);
6678 // set current window size value to configured window size value
6679 window_size_current =
6680 getTreeInfoFromIdentifier(window_sizes,
6681 i_to_a(setup.window_scaling_percent));
6683 // if that fails, set current window size to reliable default value
6684 if (window_size_current == NULL)
6685 window_size_current =
6686 getTreeInfoFromIdentifier(window_sizes,
6687 i_to_a(STD_WINDOW_SCALING_PERCENT));
6689 // if that also fails, set current window size to first available value
6690 if (window_size_current == NULL)
6691 window_size_current = window_sizes;
6694 setup.window_scaling_percent = atoi(window_size_current->identifier);
6696 // needed for displaying window size text instead of identifier
6697 window_size_text = window_size_current->name;
6700 static void execSetupGraphics_setScalingTypes(void)
6702 if (scaling_types == NULL)
6706 for (i = 0; scaling_types_list[i].value != NULL; i++)
6708 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6709 char identifier[32], name[32];
6710 char *value = scaling_types_list[i].value;
6711 char *text = scaling_types_list[i].text;
6713 ti->node_top = &scaling_types;
6714 ti->sort_priority = i;
6716 sprintf(identifier, "%s", value);
6717 sprintf(name, "%s", text);
6719 setString(&ti->identifier, identifier);
6720 setString(&ti->name, name);
6721 setString(&ti->name_sorting, name);
6722 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6724 pushTreeInfo(&scaling_types, ti);
6727 // sort scaling type values to start with lowest scaling type value
6728 sortTreeInfo(&scaling_types);
6730 // set current scaling type value to configured scaling type value
6731 scaling_type_current =
6732 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6734 // if that fails, set current scaling type to reliable default value
6735 if (scaling_type_current == NULL)
6736 scaling_type_current =
6737 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6739 // if that also fails, set current scaling type to first available value
6740 if (scaling_type_current == NULL)
6741 scaling_type_current = scaling_types;
6744 setup.window_scaling_quality = scaling_type_current->identifier;
6746 // needed for displaying scaling type text instead of identifier
6747 scaling_type_text = scaling_type_current->name;
6750 static void execSetupGraphics_setRenderingModes(void)
6752 if (rendering_modes == NULL)
6756 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6758 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6759 char identifier[32], name[32];
6760 char *value = rendering_modes_list[i].value;
6761 char *text = rendering_modes_list[i].text;
6763 ti->node_top = &rendering_modes;
6764 ti->sort_priority = i;
6766 sprintf(identifier, "%s", value);
6767 sprintf(name, "%s", text);
6769 setString(&ti->identifier, identifier);
6770 setString(&ti->name, name);
6771 setString(&ti->name_sorting, name);
6772 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6774 pushTreeInfo(&rendering_modes, ti);
6777 // sort rendering mode values to start with lowest rendering mode value
6778 sortTreeInfo(&rendering_modes);
6780 // set current rendering mode value to configured rendering mode value
6781 rendering_mode_current =
6782 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6784 // if that fails, set current rendering mode to reliable default value
6785 if (rendering_mode_current == NULL)
6786 rendering_mode_current =
6787 getTreeInfoFromIdentifier(rendering_modes,
6788 STR_SPECIAL_RENDERING_DEFAULT);
6790 // if that also fails, set current rendering mode to first available one
6791 if (rendering_mode_current == NULL)
6792 rendering_mode_current = rendering_modes;
6795 setup.screen_rendering_mode = rendering_mode_current->identifier;
6797 // needed for displaying rendering mode text instead of identifier
6798 rendering_mode_text = rendering_mode_current->name;
6801 static void execSetupGraphics_setVsyncModes(boolean update_value)
6803 if (vsync_modes == NULL)
6807 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6809 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6810 char identifier[32], name[32];
6811 char *value = vsync_modes_list[i].value;
6812 char *text = vsync_modes_list[i].text;
6814 ti->node_top = &vsync_modes;
6815 ti->sort_priority = i;
6817 sprintf(identifier, "%s", value);
6818 sprintf(name, "%s", text);
6820 setString(&ti->identifier, identifier);
6821 setString(&ti->name, name);
6822 setString(&ti->name_sorting, name);
6823 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6825 pushTreeInfo(&vsync_modes, ti);
6828 // sort vsync mode values to start with lowest vsync mode value
6829 sortTreeInfo(&vsync_modes);
6831 update_value = TRUE;
6836 // set current vsync mode value to configured vsync mode value
6837 vsync_mode_current =
6838 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6840 // if that fails, set current vsync mode to reliable default value
6841 if (vsync_mode_current == NULL)
6842 vsync_mode_current =
6843 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6845 // if that also fails, set current vsync mode to first available one
6846 if (vsync_mode_current == NULL)
6847 vsync_mode_current = vsync_modes;
6850 setup.vsync_mode = vsync_mode_current->identifier;
6852 // needed for displaying vsync mode text instead of identifier
6853 vsync_mode_text = vsync_mode_current->name;
6856 static void execSetupGraphics(void)
6858 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6860 // update "setup.window_scaling_percent" from list selection
6861 // (in this case, window scaling was changed on setup screen)
6862 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6863 execSetupGraphics_setWindowSizes(FALSE);
6865 // update "setup.vsync_mode" from list selection
6866 // (in this case, vsync mode was changed on setup screen)
6867 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6868 execSetupGraphics_setVsyncModes(FALSE);
6870 // update list selection from "setup.window_scaling_percent"
6871 // (window scaling may have changed by resizing the window)
6872 execSetupGraphics_setWindowSizes(TRUE);
6874 // update list selection from "setup.vsync_mode"
6875 // (vsync_mode may have changed by re-creating the renderer)
6876 execSetupGraphics_setVsyncModes(TRUE);
6878 execSetupGraphics_setScalingTypes();
6879 execSetupGraphics_setRenderingModes();
6881 setup_mode = SETUP_MODE_GRAPHICS;
6885 // check if game speed is high enough for 60 Hz vsync to work
6886 if (check_game_speed)
6887 ModifyGameSpeedIfNeeded();
6889 // window scaling may have changed at this point
6890 ChangeWindowScalingIfNeeded();
6892 // window scaling quality may have changed at this point
6893 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6894 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6896 // screen rendering mode may have changed at this point
6897 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6899 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6900 int video_vsync_mode = video.vsync_mode;
6902 // screen vsync mode may have changed at this point
6903 ChangeVsyncModeIfNeeded();
6905 // check if setting vsync mode to selected value failed
6906 if (setup_vsync_mode != video_vsync_mode &&
6907 setup_vsync_mode != video.vsync_mode)
6909 // changing vsync mode to selected value failed -- reset displayed value
6910 execSetupGraphics_setVsyncModes(TRUE);
6912 Request("Setting VSync failed!", REQ_CONFIRM);
6918 static void execSetupChooseWindowSize(void)
6920 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6925 static void execSetupChooseScalingType(void)
6927 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6932 static void execSetupChooseRenderingMode(void)
6934 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6939 static void execSetupChooseVsyncMode(void)
6941 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6946 static void execSetupChooseVolumeSimple(void)
6948 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6953 static void execSetupChooseVolumeLoops(void)
6955 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6960 static void execSetupChooseVolumeMusic(void)
6962 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6967 static void execSetupSound(void)
6969 if (volumes_simple == NULL)
6971 boolean current_volume_simple_found = FALSE;
6974 for (i = 0; volumes_list[i].value != -1; i++)
6976 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6977 char identifier[32], name[32];
6978 int value = volumes_list[i].value;
6979 char *text = volumes_list[i].text;
6981 ti->node_top = &volumes_simple;
6982 ti->sort_priority = value;
6984 sprintf(identifier, "%d", value);
6985 sprintf(name, "%s", text);
6987 setString(&ti->identifier, identifier);
6988 setString(&ti->name, name);
6989 setString(&ti->name_sorting, name);
6990 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6992 pushTreeInfo(&volumes_simple, ti);
6994 if (value == setup.volume_simple)
6995 current_volume_simple_found = TRUE;
6998 if (!current_volume_simple_found)
7000 // add entry for non-preset volume value
7002 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7003 char identifier[32], name[32];
7004 int value = setup.volume_simple;
7006 ti->node_top = &volumes_simple;
7007 ti->sort_priority = value;
7009 sprintf(identifier, "%d", value);
7010 sprintf(name, "%d %% (Current)", value);
7012 setString(&ti->identifier, identifier);
7013 setString(&ti->name, name);
7014 setString(&ti->name_sorting, name);
7015 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
7017 pushTreeInfo(&volumes_simple, ti);
7020 // sort volume values to start with lowest volume value
7021 sortTreeInfo(&volumes_simple);
7023 // set current volume value to configured volume value
7024 volume_simple_current =
7025 getTreeInfoFromIdentifier(volumes_simple, i_to_a(setup.volume_simple));
7027 // if that fails, set current volume to reliable default value
7028 if (volume_simple_current == NULL)
7029 volume_simple_current =
7030 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
7032 // if that also fails, set current volume to first available value
7033 if (volume_simple_current == NULL)
7034 volume_simple_current = volumes_simple;
7037 if (volumes_loops == NULL)
7039 boolean current_volume_loops_found = FALSE;
7042 for (i = 0; volumes_list[i].value != -1; i++)
7044 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7045 char identifier[32], name[32];
7046 int value = volumes_list[i].value;
7047 char *text = volumes_list[i].text;
7049 ti->node_top = &volumes_loops;
7050 ti->sort_priority = value;
7052 sprintf(identifier, "%d", value);
7053 sprintf(name, "%s", text);
7055 setString(&ti->identifier, identifier);
7056 setString(&ti->name, name);
7057 setString(&ti->name_sorting, name);
7058 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
7060 pushTreeInfo(&volumes_loops, ti);
7062 if (value == setup.volume_loops)
7063 current_volume_loops_found = TRUE;
7066 if (!current_volume_loops_found)
7068 // add entry for non-preset volume value
7070 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7071 char identifier[32], name[32];
7072 int value = setup.volume_loops;
7074 ti->node_top = &volumes_loops;
7075 ti->sort_priority = value;
7077 sprintf(identifier, "%d", value);
7078 sprintf(name, "%d %% (Current)", value);
7080 setString(&ti->identifier, identifier);
7081 setString(&ti->name, name);
7082 setString(&ti->name_sorting, name);
7083 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
7085 pushTreeInfo(&volumes_loops, ti);
7088 // sort volume values to start with lowest volume value
7089 sortTreeInfo(&volumes_loops);
7091 // set current volume value to configured volume value
7092 volume_loops_current =
7093 getTreeInfoFromIdentifier(volumes_loops, i_to_a(setup.volume_loops));
7095 // if that fails, set current volume to reliable default value
7096 if (volume_loops_current == NULL)
7097 volume_loops_current =
7098 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
7100 // if that also fails, set current volume to first available value
7101 if (volume_loops_current == NULL)
7102 volume_loops_current = volumes_loops;
7105 if (volumes_music == NULL)
7107 boolean current_volume_music_found = FALSE;
7110 for (i = 0; volumes_list[i].value != -1; i++)
7112 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7113 char identifier[32], name[32];
7114 int value = volumes_list[i].value;
7115 char *text = volumes_list[i].text;
7117 ti->node_top = &volumes_music;
7118 ti->sort_priority = value;
7120 sprintf(identifier, "%d", value);
7121 sprintf(name, "%s", text);
7123 setString(&ti->identifier, identifier);
7124 setString(&ti->name, name);
7125 setString(&ti->name_sorting, name);
7126 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
7128 pushTreeInfo(&volumes_music, ti);
7130 if (value == setup.volume_music)
7131 current_volume_music_found = TRUE;
7134 if (!current_volume_music_found)
7136 // add entry for non-preset volume value
7138 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7139 char identifier[32], name[32];
7140 int value = setup.volume_music;
7142 ti->node_top = &volumes_music;
7143 ti->sort_priority = value;
7145 sprintf(identifier, "%d", value);
7146 sprintf(name, "%d %% (Current)", value);
7148 setString(&ti->identifier, identifier);
7149 setString(&ti->name, name);
7150 setString(&ti->name_sorting, name);
7151 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
7153 pushTreeInfo(&volumes_music, ti);
7156 // sort volume values to start with lowest volume value
7157 sortTreeInfo(&volumes_music);
7159 // set current volume value to configured volume value
7160 volume_music_current =
7161 getTreeInfoFromIdentifier(volumes_music, i_to_a(setup.volume_music));
7163 // if that fails, set current volume to reliable default value
7164 if (volume_music_current == NULL)
7165 volume_music_current =
7166 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
7168 // if that also fails, set current volume to first available value
7169 if (volume_music_current == NULL)
7170 volume_music_current = volumes_music;
7173 setup.volume_simple = atoi(volume_simple_current->identifier);
7174 setup.volume_loops = atoi(volume_loops_current->identifier);
7175 setup.volume_music = atoi(volume_music_current->identifier);
7177 // needed for displaying volume text instead of identifier
7178 volume_simple_text = volume_simple_current->name;
7179 volume_loops_text = volume_loops_current->name;
7180 volume_music_text = volume_music_current->name;
7182 setup_mode = SETUP_MODE_SOUND;
7187 static void execSetupChooseTouchControls(void)
7189 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
7194 static void execSetupChooseMoveDistance(void)
7196 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
7201 static void execSetupChooseDropDistance(void)
7203 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
7208 static void execSetupChooseTransparency(void)
7210 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
7215 static void execSetupChooseGridXSize_0(void)
7217 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
7222 static void execSetupChooseGridYSize_0(void)
7224 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
7229 static void execSetupChooseGridXSize_1(void)
7231 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
7236 static void execSetupChooseGridYSize_1(void)
7238 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
7243 static void execSetupConfigureVirtualButtons(void)
7245 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
7247 ConfigureVirtualButtons();
7249 setup_mode = SETUP_MODE_TOUCH;
7254 static void execSetupTouch(void)
7258 if (touch_controls == NULL)
7260 for (i = 0; touch_controls_list[i].value != NULL; i++)
7262 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7263 char identifier[32], name[32];
7264 char *value = touch_controls_list[i].value;
7265 char *text = touch_controls_list[i].text;
7267 ti->node_top = &touch_controls;
7268 ti->sort_priority = i;
7270 sprintf(identifier, "%s", value);
7271 sprintf(name, "%s", text);
7273 setString(&ti->identifier, identifier);
7274 setString(&ti->name, name);
7275 setString(&ti->name_sorting, name);
7276 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
7278 pushTreeInfo(&touch_controls, ti);
7281 // sort touch control values to start with lowest touch control value
7282 sortTreeInfo(&touch_controls);
7284 // set current touch control value to configured touch control value
7285 touch_control_current =
7286 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
7288 // if that fails, set current touch control to reliable default value
7289 if (touch_control_current == NULL)
7290 touch_control_current =
7291 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
7293 // if that also fails, set current touch control to first available value
7294 if (touch_control_current == NULL)
7295 touch_control_current = touch_controls;
7298 if (move_distances == NULL)
7300 for (i = 0; distances_list[i].value != -1; i++)
7302 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7303 char identifier[32], name[32];
7304 int value = distances_list[i].value;
7305 char *text = distances_list[i].text;
7307 ti->node_top = &move_distances;
7308 ti->sort_priority = value;
7310 sprintf(identifier, "%d", value);
7311 sprintf(name, "%s", text);
7313 setString(&ti->identifier, identifier);
7314 setString(&ti->name, name);
7315 setString(&ti->name_sorting, name);
7316 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
7318 pushTreeInfo(&move_distances, ti);
7321 // sort distance values to start with lowest distance value
7322 sortTreeInfo(&move_distances);
7324 // set current distance value to configured distance value
7325 move_distance_current =
7326 getTreeInfoFromIdentifier(move_distances,
7327 i_to_a(setup.touch.move_distance));
7329 // if that fails, set current distance to reliable default value
7330 if (move_distance_current == NULL)
7331 move_distance_current =
7332 getTreeInfoFromIdentifier(move_distances,
7333 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
7335 // if that also fails, set current distance to first available value
7336 if (move_distance_current == NULL)
7337 move_distance_current = move_distances;
7340 if (drop_distances == NULL)
7342 for (i = 0; distances_list[i].value != -1; i++)
7344 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7345 char identifier[32], name[32];
7346 int value = distances_list[i].value;
7347 char *text = distances_list[i].text;
7349 ti->node_top = &drop_distances;
7350 ti->sort_priority = value;
7352 sprintf(identifier, "%d", value);
7353 sprintf(name, "%s", text);
7355 setString(&ti->identifier, identifier);
7356 setString(&ti->name, name);
7357 setString(&ti->name_sorting, name);
7358 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
7360 pushTreeInfo(&drop_distances, ti);
7363 // sort distance values to start with lowest distance value
7364 sortTreeInfo(&drop_distances);
7366 // set current distance value to configured distance value
7367 drop_distance_current =
7368 getTreeInfoFromIdentifier(drop_distances,
7369 i_to_a(setup.touch.drop_distance));
7371 // if that fails, set current distance to reliable default value
7372 if (drop_distance_current == NULL)
7373 drop_distance_current =
7374 getTreeInfoFromIdentifier(drop_distances,
7375 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
7377 // if that also fails, set current distance to first available value
7378 if (drop_distance_current == NULL)
7379 drop_distance_current = drop_distances;
7382 if (transparencies == NULL)
7384 for (i = 0; transparencies_list[i].value != -1; i++)
7386 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7387 char identifier[32], name[32];
7388 int value = transparencies_list[i].value;
7389 char *text = transparencies_list[i].text;
7391 ti->node_top = &transparencies;
7392 ti->sort_priority = value;
7394 sprintf(identifier, "%d", value);
7395 sprintf(name, "%s", text);
7397 setString(&ti->identifier, identifier);
7398 setString(&ti->name, name);
7399 setString(&ti->name_sorting, name);
7400 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
7402 pushTreeInfo(&transparencies, ti);
7405 // sort transparency values to start with lowest transparency value
7406 sortTreeInfo(&transparencies);
7408 // set current transparency value to configured transparency value
7409 transparency_current =
7410 getTreeInfoFromIdentifier(transparencies,
7411 i_to_a(setup.touch.transparency));
7413 // if that fails, set current transparency to reliable default value
7414 if (transparency_current == NULL)
7415 transparency_current =
7416 getTreeInfoFromIdentifier(transparencies,
7417 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7419 // if that also fails, set current transparency to first available value
7420 if (transparency_current == NULL)
7421 transparency_current = transparencies;
7424 for (i = 0; i < 2; i++)
7426 for (j = 0; j < 2; j++)
7428 if (grid_sizes[i][j] == NULL)
7430 for (k = 0; grid_sizes_list[k].value != -1; k++)
7432 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7433 char identifier[32], name[32];
7434 int value = grid_sizes_list[k].value;
7435 char *text = grid_sizes_list[k].text;
7437 ti->node_top = &grid_sizes[i][j];
7438 ti->sort_priority = value;
7440 sprintf(identifier, "%d", value);
7441 sprintf(name, "%s", text);
7443 setString(&ti->identifier, identifier);
7444 setString(&ti->name, name);
7445 setString(&ti->name_sorting, name);
7446 setString(&ti->infotext,
7449 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7450 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7452 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7453 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7455 pushTreeInfo(&grid_sizes[i][j], ti);
7458 // sort grid size values to start with lowest grid size value
7459 sortTreeInfo(&grid_sizes[i][j]);
7461 // set current grid size value to configured grid size value
7462 grid_size_current[i][j] =
7463 getTreeInfoFromIdentifier(grid_sizes[i][j],
7465 setup.touch.grid_xsize[i] :
7466 setup.touch.grid_ysize[i]));
7468 // if that fails, set current grid size to reliable default value
7469 if (grid_size_current[i][j] == NULL)
7470 grid_size_current[i][j] =
7471 getTreeInfoFromIdentifier(grid_sizes[i][j],
7473 DEFAULT_GRID_XSIZE(i) :
7474 DEFAULT_GRID_YSIZE(i)));
7476 // if that also fails, set current grid size to first available value
7477 if (grid_size_current[i][j] == NULL)
7478 grid_size_current[i][j] = grid_sizes[i][j];
7483 setup.touch.control_type = touch_control_current->identifier;
7484 setup.touch.move_distance = atoi(move_distance_current->identifier);
7485 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7486 setup.touch.transparency = atoi(transparency_current->identifier);
7488 for (i = 0; i < 2; i++)
7490 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7491 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7493 if (i == GRID_ACTIVE_NR())
7495 overlay.grid_xsize = setup.touch.grid_xsize[i];
7496 overlay.grid_ysize = setup.touch.grid_ysize[i];
7500 // needed for displaying value text instead of identifier
7501 touch_controls_text = touch_control_current->name;
7502 move_distance_text = move_distance_current->name;
7503 drop_distance_text = drop_distance_current->name;
7504 transparency_text = transparency_current->name;
7506 for (i = 0; i < 2; i++)
7507 for (j = 0; j < 2; j++)
7508 grid_size_text[i][j] = grid_size_current[i][j]->name;
7510 setup_mode = SETUP_MODE_TOUCH;
7515 static void execSetupArtwork(void)
7517 static ArtworkDirTree *gfx_last_valid = NULL;
7518 static ArtworkDirTree *snd_last_valid = NULL;
7519 static ArtworkDirTree *mus_last_valid = NULL;
7521 // current artwork directory may be invalid (level group, parent link)
7522 if (!validLevelSeries(artwork.gfx_current))
7523 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7524 if (!validLevelSeries(artwork.snd_current))
7525 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7526 if (!validLevelSeries(artwork.mus_current))
7527 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7529 // store valid artwork directory information
7530 gfx_last_valid = artwork.gfx_current;
7531 snd_last_valid = artwork.snd_current;
7532 mus_last_valid = artwork.mus_current;
7535 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7536 artwork.gfx_current->subdir,
7537 artwork.gfx_current->fullpath,
7538 artwork.gfx_current->basepath);
7541 setup.graphics_set = artwork.gfx_current->identifier;
7542 setup.sounds_set = artwork.snd_current->identifier;
7543 setup.music_set = artwork.mus_current->identifier;
7545 // needed if last screen (setup choice) changed graphics, sounds or music
7546 ReloadCustomArtwork(0);
7548 // needed for displaying artwork name instead of artwork identifier
7549 graphics_set_name = artwork.gfx_current->name;
7550 sounds_set_name = artwork.snd_current->name;
7551 music_set_name = artwork.mus_current->name;
7553 setup_mode = SETUP_MODE_ARTWORK;
7558 static void execSetupChooseGraphics(void)
7560 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7565 static void execSetupChooseSounds(void)
7567 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7572 static void execSetupChooseMusic(void)
7574 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7579 static void execSetupInput(void)
7581 setup_mode = SETUP_MODE_INPUT;
7586 static void execSetupShortcuts(void)
7588 setup_mode = SETUP_MODE_SHORTCUTS;
7593 static void execSetupShortcuts1(void)
7595 setup_mode = SETUP_MODE_SHORTCUTS_1;
7600 static void execSetupShortcuts2(void)
7602 setup_mode = SETUP_MODE_SHORTCUTS_2;
7607 static void execSetupShortcuts3(void)
7609 setup_mode = SETUP_MODE_SHORTCUTS_3;
7614 static void execSetupShortcuts4(void)
7616 setup_mode = SETUP_MODE_SHORTCUTS_4;
7621 static void execSetupShortcuts5(void)
7623 setup_mode = SETUP_MODE_SHORTCUTS_5;
7628 static void execExitSetup(void)
7630 SetGameStatus(GAME_MODE_MAIN);
7635 static void execSaveAndExitSetup(void)
7641 static void execGadgetNetworkServer(void)
7643 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7644 struct GadgetInfo *gi = screen_gadget[gadget_id];
7646 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7647 network_server_hostname[0] = '\0';
7649 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7653 ClickOnGadget(gi, MB_LEFTBUTTON);
7656 static void execOfferUploadTapes(void)
7661 static void ToggleNetworkModeIfNeeded(void)
7663 int font_title = FONT_TITLE_1;
7664 int font_foot = FC_BLUE;
7665 int ystart = mSY - SY + 16;
7666 int ybottom = mSY - SY + SYSIZE - 20;
7667 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7669 if (setup.network_mode == network.enabled)
7672 network.enabled = setup.network_mode;
7674 FadeOut(REDRAW_ALL);
7678 DrawTextSCentered(ystart, font_title, text);
7682 if (network.enabled)
7683 InitNetworkServer();
7685 DisconnectFromNetworkServer();
7687 DrawTextSCentered(ybottom, font_foot,
7688 "Press any key or button for setup menu");
7690 WaitForEventToContinue();
7695 static void ToggleGameSpeedsListIfNeeded(void)
7697 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7699 if (setup.game_speed_extended == using_game_speeds_extended)
7702 // try to match similar values when changing game speeds list
7703 if (setup.game_speed_extended)
7704 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7705 setup.game_frame_delay == 30 ? 29 :
7706 setup.game_frame_delay);
7708 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7709 setup.game_frame_delay == 16 ? 15 :
7710 setup.game_frame_delay >= 29 ? 30 :
7711 setup.game_frame_delay <= 10 ? 10 :
7712 setup.game_frame_delay);
7714 execSetupGame_setGameSpeeds(TRUE);
7719 static void ToggleUseApiServerIfNeeded(void)
7721 if (runtime.use_api_server == setup.use_api_server)
7724 runtime.use_api_server = setup.use_api_server;
7726 if (runtime.use_api_server)
7728 if (setup.has_remaining_tapes)
7729 setup.ask_for_uploading_tapes = TRUE;
7731 CheckApiServerTasks();
7735 static void ModifyGameSpeedIfNeeded(void)
7737 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7738 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7742 char *game_speed_text = "Fast";
7743 int game_speed_value = 15;
7745 if (setup.game_speed_extended)
7747 game_speed_text = "60 fps";
7748 game_speed_value = 16;
7751 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7753 // set game speed to existing list value that is fast enough for vsync
7754 setup.game_frame_delay = game_speed_value;
7756 execSetupGame_setGameSpeeds(TRUE);
7758 Request(message, REQ_CONFIRM);
7761 static void DisableVsyncIfNeeded(void)
7763 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7764 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7765 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7768 // disable vsync for the selected game speed to work
7769 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7771 execSetupGraphics_setVsyncModes(TRUE);
7773 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7779 void *related_value;
7780 } hide_related_entry_list[] =
7782 { &setup.network_server_hostname, execGadgetNetworkServer },
7783 { &setup.network_server_hostname, &network_server_text },
7785 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7786 { &setup.scores_in_highscore_list, &scores_type_text },
7788 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7789 { &setup.game_frame_delay, &game_speed_text },
7791 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7792 { &setup.scroll_delay_value, &scroll_delay_text },
7794 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7795 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7797 { &setup.default_game_engine_type, execSetupChooseGameEngineType },
7798 { &setup.default_game_engine_type, &game_engine_type_text },
7800 { &setup.bd_palette_c64, execSetupChoosePaletteC64 },
7801 { &setup.bd_palette_c64, &bd_palette_c64_text },
7803 { &setup.bd_palette_c64dtv, execSetupChoosePaletteC64DTV },
7804 { &setup.bd_palette_c64dtv, &bd_palette_c64dtv_text },
7806 { &setup.bd_palette_atari, execSetupChoosePaletteAtari },
7807 { &setup.bd_palette_atari, &bd_palette_atari_text },
7809 { &setup.bd_default_color_type, execSetupChooseColorType },
7810 { &setup.bd_default_color_type, &bd_color_type_text },
7812 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7813 { &setup.window_scaling_percent, &window_size_text },
7815 { &setup.window_scaling_quality, execSetupChooseScalingType },
7816 { &setup.window_scaling_quality, &scaling_type_text },
7818 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7819 { &setup.screen_rendering_mode, &rendering_mode_text },
7821 { &setup.vsync_mode, execSetupChooseVsyncMode },
7822 { &setup.vsync_mode, &vsync_mode_text },
7824 { &setup.graphics_set, execSetupChooseGraphics },
7825 { &setup.graphics_set, &graphics_set_name },
7827 { &setup.sounds_set, execSetupChooseSounds },
7828 { &setup.sounds_set, &sounds_set_name },
7830 { &setup.music_set, execSetupChooseMusic },
7831 { &setup.music_set, &music_set_name },
7833 { &setup.volume_simple, execSetupChooseVolumeSimple },
7834 { &setup.volume_simple, &volume_simple_text },
7836 { &setup.volume_loops, execSetupChooseVolumeLoops },
7837 { &setup.volume_loops, &volume_loops_text },
7839 { &setup.volume_music, execSetupChooseVolumeMusic },
7840 { &setup.volume_music, &volume_music_text },
7842 { &setup.touch.control_type, execSetupChooseTouchControls },
7843 { &setup.touch.control_type, &touch_controls_text },
7845 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7846 { &setup.touch.move_distance, &move_distance_text },
7848 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7849 { &setup.touch.drop_distance, &drop_distance_text },
7851 { &setup.touch.transparency, execSetupChooseTransparency },
7852 { &setup.touch.transparency, &transparency_text },
7854 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7855 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7857 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7858 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7860 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7861 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7863 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7864 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7866 { &setup.internal.menu_game, execSetupGame },
7867 { &setup.internal.menu_engines, execSetupEngines },
7868 { &setup.internal.menu_editor, execSetupEditor },
7869 { &setup.internal.menu_graphics, execSetupGraphics },
7870 { &setup.internal.menu_sound, execSetupSound },
7871 { &setup.internal.menu_artwork, execSetupArtwork },
7872 { &setup.internal.menu_input, execSetupInput },
7873 { &setup.internal.menu_touch, execSetupTouch },
7874 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7875 { &setup.internal.menu_exit, execExitSetup },
7876 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7878 { &setup.internal.menu_shortcuts_various, execSetupShortcuts1 },
7879 { &setup.internal.menu_shortcuts_focus, execSetupShortcuts2 },
7880 { &setup.internal.menu_shortcuts_tape, execSetupShortcuts3 },
7881 { &setup.internal.menu_shortcuts_sound, execSetupShortcuts4 },
7882 { &setup.internal.menu_shortcuts_snap, execSetupShortcuts5 },
7884 { &setup.internal.info_title, execInfoTitleScreen },
7885 { &setup.internal.info_elements, execInfoElements },
7886 { &setup.internal.info_music, execInfoMusic },
7887 { &setup.internal.info_credits, execInfoCredits },
7888 { &setup.internal.info_program, execInfoProgram },
7889 { &setup.internal.info_version, execInfoVersion },
7890 { &setup.internal.info_levelset, execInfoLevelSet },
7891 { &setup.internal.info_exit, execExitInfo },
7896 void setHideRelatedSetupEntries(void)
7900 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7901 if (hideSetupEntry(hide_related_entry_list[i].value))
7902 setHideSetupEntry(hide_related_entry_list[i].related_value);
7905 static struct TokenInfo setup_info_main[] =
7907 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7908 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7909 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7910 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7911 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7912 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7913 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7914 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7915 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7916 { TYPE_EMPTY, NULL, "" },
7917 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7918 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7923 static struct TokenInfo setup_info_game[] =
7925 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7926 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7927 { TYPE_PLAYER, &setup.network_player_nr, "Preferred Network Player:" },
7928 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7929 { TYPE_STRING, &network_server_text, "" },
7930 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7931 { TYPE_ENTER_LIST, execSetupChooseScoresType, "Scores in Highscore List:" },
7932 { TYPE_STRING, &scores_type_text, "" },
7933 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7934 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7935 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7936 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7937 { TYPE_SWITCH, &setup.handicap, "Force Solving Levels:" },
7938 { TYPE_SWITCH, &setup.skip_levels, "Allow Skipping Levels:" },
7939 { TYPE_SWITCH, &setup.increment_levels, "Increment Solved Levels:" },
7940 { TYPE_SWITCH, &setup.auto_play_next_level, "Auto-play Next Level:" },
7941 { TYPE_SWITCH, &setup.count_score_after_game, "Count Score After Game:" },
7942 { TYPE_SWITCH, &setup.show_scores_after_game, "Show Scores After Game:" },
7943 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7944 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7945 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7946 { TYPE_SWITCH, &setup.autorecord, "Auto-Record When Playing:" },
7947 { TYPE_SWITCH, &setup.autorecord_after_replay, "Auto-Record After Replay:" },
7948 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7949 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7950 { TYPE_STRING, &game_speed_text, "" },
7951 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7953 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7954 { TYPE_STRING, &scroll_delay_text, "" },
7956 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode, "Game Engine Snapshot Mode:" },
7957 { TYPE_STRING, &snapshot_mode_text, "" },
7958 { TYPE_SWITCH, &setup.show_load_save_buttons, "Show Load/Save Buttons:" },
7959 { TYPE_SWITCH, &setup.show_undo_redo_buttons, "Show Undo/Redo Buttons:" },
7960 { TYPE_EMPTY, NULL, "" },
7961 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7966 static struct TokenInfo setup_info_engines[] =
7968 { TYPE_ENTER_LIST, &execSetupChooseGameEngineType, "Default Game Engine:" },
7969 { TYPE_STRING, &game_engine_type_text, "" },
7970 { TYPE_EMPTY, NULL, "" },
7971 { TYPE_HEADLINE, NULL, "Boulder Dash" },
7972 { TYPE_SWITCH, &setup.bd_skip_uncovering, "Skip (un)covering screen:" },
7973 { TYPE_SWITCH, &setup.bd_skip_hatching, "Skip hatching player:" },
7974 { TYPE_SWITCH, &setup.bd_scroll_delay, "Scroll Delay:" },
7975 { TYPE_YES_NO_AUTO, &setup.bd_smooth_movements, "Smooth Element Movement:" },
7976 { TYPE_YES_NO_AUTO, &setup.bd_pushing_graphics, "Use Player Pushing Graphics:" },
7977 { TYPE_YES_NO_AUTO, &setup.bd_up_down_graphics, "Use Player Up/Down Graphics:" },
7978 { TYPE_ENTER_LIST, &execSetupChoosePaletteC64, "Color Palette (C64):" },
7979 { TYPE_STRING, &bd_palette_c64_text, "" },
7980 { TYPE_ENTER_LIST, &execSetupChoosePaletteC64DTV, "Color Palette (C64DTV):" },
7981 { TYPE_STRING, &bd_palette_c64dtv_text, "" },
7982 { TYPE_ENTER_LIST, &execSetupChoosePaletteAtari, "Color Palette (Atari):" },
7983 { TYPE_STRING, &bd_palette_atari_text, "" },
7984 { TYPE_ENTER_LIST, &execSetupChooseColorType, "Preferred Color Type:" },
7985 { TYPE_STRING, &bd_color_type_text, "" },
7986 { TYPE_SWITCH, &setup.bd_random_colors, "Random Colors:" },
7987 { TYPE_EMPTY, NULL, "" },
7988 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7989 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7990 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7991 { TYPE_SWITCH, &setup.prefer_lowpass_sounds, "Low-Pass Filter Sounds:" },
7992 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7993 { TYPE_EMPTY, NULL, "" },
7994 { TYPE_HEADLINE, NULL, "Supaplex" },
7995 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7996 { TYPE_EMPTY, NULL, "" },
7997 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8002 static struct TokenInfo setup_info_editor[] =
8005 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
8006 { TYPE_SWITCH, &setup.editor.el_boulderdash_native, "Boulder Dash Native:" },
8007 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
8008 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
8009 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
8010 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
8011 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
8012 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
8013 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
8014 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
8015 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
8017 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
8018 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
8020 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
8022 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
8023 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
8024 { TYPE_EMPTY, NULL, "" },
8026 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
8027 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
8028 { TYPE_EMPTY, NULL, "" },
8030 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
8031 { TYPE_EMPTY, NULL, "" },
8032 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
8033 { TYPE_EMPTY, NULL, "" },
8034 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8039 static struct TokenInfo setup_info_graphics[] =
8041 #if !defined(PLATFORM_ANDROID) && !defined(PLATFORM_EMSCRIPTEN)
8042 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
8043 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
8044 { TYPE_STRING, &window_size_text, "" },
8045 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
8046 { TYPE_STRING, &scaling_type_text, "" },
8047 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
8048 { TYPE_STRING, &rendering_mode_text, "" },
8051 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
8052 { TYPE_STRING, &scroll_delay_text, "" },
8054 #if !defined(PLATFORM_EMSCRIPTEN)
8055 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
8056 { TYPE_STRING, &vsync_mode_text, "" },
8058 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
8059 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
8060 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
8061 { TYPE_SWITCH, &setup.show_titlescreen, "Show Title Screens:" },
8062 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
8063 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
8064 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
8065 { TYPE_EMPTY, NULL, "" },
8066 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8071 static struct TokenInfo setup_info_sound[] =
8073 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
8074 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
8075 { TYPE_SWITCH, &setup.sound_music, "Music:" },
8076 { TYPE_EMPTY, NULL, "" },
8077 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
8078 { TYPE_STRING, &volume_simple_text, "" },
8079 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
8080 { TYPE_STRING, &volume_loops_text, "" },
8081 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
8082 { TYPE_STRING, &volume_music_text, "" },
8083 { TYPE_EMPTY, NULL, "" },
8084 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8089 static struct TokenInfo setup_info_artwork[] =
8091 { TYPE_ENTER_LIST, execSetupChooseGraphics, "Custom Graphics:" },
8092 { TYPE_STRING, &graphics_set_name, "" },
8093 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
8094 { TYPE_STRING, &sounds_set_name, "" },
8095 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
8096 { TYPE_STRING, &music_set_name, "" },
8097 { TYPE_EMPTY, NULL, "" },
8098 { TYPE_YES_NO_AUTO, &setup.override_level_graphics,"Override Level Graphics:" },
8099 { TYPE_YES_NO_AUTO, &setup.override_level_sounds, "Override Level Sounds:" },
8100 { TYPE_YES_NO_AUTO, &setup.override_level_music, "Override Level Music:" },
8101 { TYPE_EMPTY, NULL, "" },
8102 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8107 static struct TokenInfo setup_info_input[] =
8109 { TYPE_SWITCH, NULL, "Player:" },
8110 { TYPE_SWITCH, NULL, "Device:" },
8111 { TYPE_SWITCH, NULL, "" },
8112 { TYPE_SKIPPABLE, NULL, "" },
8113 { TYPE_EMPTY, NULL, "" },
8114 { TYPE_EMPTY, NULL, "" },
8115 { TYPE_EMPTY, NULL, "" },
8116 { TYPE_EMPTY, NULL, "" },
8117 { TYPE_EMPTY, NULL, "" },
8118 { TYPE_EMPTY, NULL, "" },
8119 { TYPE_EMPTY, NULL, "" },
8120 { TYPE_EMPTY, NULL, "" },
8121 { TYPE_SKIPPABLE, NULL, "" },
8122 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8127 static struct TokenInfo setup_info_touch[] =
8129 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
8130 { TYPE_STRING, &touch_controls_text, "" },
8131 { TYPE_EMPTY, NULL, "" },
8132 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8137 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
8139 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
8140 { TYPE_STRING, &touch_controls_text, "" },
8141 { TYPE_EMPTY, NULL, "" },
8142 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
8143 { TYPE_STRING, &grid_size_text[0][0], "" },
8144 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
8145 { TYPE_STRING, &grid_size_text[0][1], "" },
8146 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
8147 { TYPE_STRING, &transparency_text, "" },
8148 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
8149 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
8150 { TYPE_EMPTY, NULL, "" },
8151 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
8152 { TYPE_EMPTY, NULL, "" },
8153 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8158 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
8160 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
8161 { TYPE_STRING, &touch_controls_text, "" },
8162 { TYPE_EMPTY, NULL, "" },
8163 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
8164 { TYPE_STRING, &grid_size_text[1][0], "" },
8165 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
8166 { TYPE_STRING, &grid_size_text[1][1], "" },
8167 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
8168 { TYPE_STRING, &transparency_text, "" },
8169 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
8170 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
8171 { TYPE_EMPTY, NULL, "" },
8172 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
8173 { TYPE_EMPTY, NULL, "" },
8174 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8179 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
8181 setup_info_touch_virtual_buttons_0,
8182 setup_info_touch_virtual_buttons_1
8185 static struct TokenInfo setup_info_touch_wipe_gestures[] =
8187 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
8188 { TYPE_STRING, &touch_controls_text, "" },
8189 { TYPE_EMPTY, NULL, "" },
8190 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
8191 { TYPE_STRING, &move_distance_text, "" },
8192 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
8193 { TYPE_STRING, &drop_distance_text, "" },
8194 { TYPE_EMPTY, NULL, "" },
8195 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8200 static struct TokenInfo setup_info_shortcuts[] =
8202 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
8203 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
8204 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
8205 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
8206 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
8207 { TYPE_EMPTY, NULL, "" },
8208 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
8213 static struct TokenInfo setup_info_shortcuts_1[] =
8215 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:" },
8216 { TYPE_KEY, &setup.shortcut.save_game, "" },
8217 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:" },
8218 { TYPE_KEY, &setup.shortcut.load_game, "" },
8219 { TYPE_KEYTEXT, NULL, "Restart Game:" },
8220 { TYPE_KEY, &setup.shortcut.restart_game, "" },
8221 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:" },
8222 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
8223 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:" },
8224 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
8225 { TYPE_EMPTY, NULL, "" },
8226 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
8227 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
8228 { TYPE_EMPTY, NULL, "" },
8229 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8234 static struct TokenInfo setup_info_shortcuts_2[] =
8236 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:" },
8237 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
8238 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:" },
8239 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
8240 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:" },
8241 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
8242 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:" },
8243 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
8244 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:" },
8245 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
8246 { TYPE_EMPTY, NULL, "" },
8247 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8252 static struct TokenInfo setup_info_shortcuts_3[] =
8254 { TYPE_KEYTEXT, NULL, "Eject Tape:" },
8255 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
8256 { TYPE_KEYTEXT, NULL, "Warp / Single Step:" },
8257 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
8258 { TYPE_KEYTEXT, NULL, "Stop Tape:" },
8259 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
8260 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:" },
8261 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
8262 { TYPE_KEYTEXT, NULL, "Record Tape:" },
8263 { TYPE_KEY, &setup.shortcut.tape_record, "" },
8264 { TYPE_KEYTEXT, NULL, "Play Tape:" },
8265 { TYPE_KEY, &setup.shortcut.tape_play, "" },
8266 { TYPE_EMPTY, NULL, "" },
8267 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8272 static struct TokenInfo setup_info_shortcuts_4[] =
8274 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):" },
8275 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
8276 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):" },
8277 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
8278 { TYPE_KEYTEXT, NULL, "Toggle Music:" },
8279 { TYPE_KEY, &setup.shortcut.sound_music, "" },
8280 { TYPE_EMPTY, NULL, "" },
8281 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8286 static struct TokenInfo setup_info_shortcuts_5[] =
8288 { TYPE_KEYTEXT, NULL, "Snap Left:" },
8289 { TYPE_KEY, &setup.shortcut.snap_left, "" },
8290 { TYPE_KEYTEXT, NULL, "Snap Right:" },
8291 { TYPE_KEY, &setup.shortcut.snap_right, "" },
8292 { TYPE_KEYTEXT, NULL, "Snap Up:" },
8293 { TYPE_KEY, &setup.shortcut.snap_up, "" },
8294 { TYPE_KEYTEXT, NULL, "Snap Down:" },
8295 { TYPE_KEY, &setup.shortcut.snap_down, "" },
8296 { TYPE_EMPTY, NULL, "" },
8297 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8302 static Key getSetupKey(void)
8304 Key key = KSYM_UNDEFINED;
8305 boolean got_key_event = FALSE;
8307 while (!got_key_event)
8311 if (NextValidEvent(&event))
8315 case EVENT_KEYPRESS:
8317 key = GetEventKey((KeyEvent *)&event);
8319 // press 'Escape' or 'Enter' to keep the existing key binding
8320 if (key == KSYM_Escape || key == KSYM_Return)
8321 key = KSYM_UNDEFINED; // keep old value
8323 got_key_event = TRUE;
8327 case EVENT_KEYRELEASE:
8328 key_joystick_mapping = 0;
8332 HandleOtherEvents(&event);
8343 static int getSetupValueFont(int type, void *value)
8345 if (type & TYPE_GHOSTED)
8346 return FONT_OPTION_OFF;
8347 else if (type & TYPE_KEY)
8348 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
8349 else if (type & TYPE_STRING)
8350 return FONT_VALUE_2;
8351 else if (type & TYPE_ECS_AGA)
8352 return FONT_VALUE_1;
8353 else if (type & TYPE_BOOLEAN_STYLE)
8354 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
8355 else if (type & TYPE_YES_NO_AUTO)
8356 return (*(int *)value == AUTO ? FONT_OPTION_ON :
8357 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
8358 else if (type & TYPE_PLAYER)
8359 return FONT_VALUE_1;
8361 return FONT_VALUE_1;
8364 static int getSetupValueFontNarrow(int type, int font_nr)
8366 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
8367 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
8368 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
8372 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
8374 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8375 struct TokenInfo *si = &setup_info[si_pos];
8376 boolean font_draw_xoffset_modified = FALSE;
8377 boolean scrollbar_needed = (num_setup_info < max_setup_info);
8378 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
8379 int mx_right_border = (scrollbar_needed ? mx_scrollbar : SX + SXSIZE);
8380 int font_draw_xoffset_old = -1;
8381 int xoffset = (scrollbar_needed ? 0 : 1);
8382 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
8383 int xpos = menu_screen_value_xpos;
8384 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
8385 int startx = mSX + xpos * 32;
8386 int starty = mSY + ypos * 32;
8387 int type = si->type;
8388 void *value = si->value;
8389 char *value_string = getSetupValue(type, value);
8390 int font_nr_default = getSetupValueFont(type, value);
8391 int font_width_default = getFontWidth(font_nr_default);
8392 int font_nr = font_nr_default;
8394 if (value_string == NULL)
8397 if (type & TYPE_KEY)
8399 xpos = MENU_SCREEN_START_XPOS;
8401 if (type & TYPE_QUERY)
8402 value_string = "<press key>";
8404 else if (type & TYPE_STRING)
8406 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
8408 xpos = MENU_SCREEN_START_XPOS;
8410 if (strlen(value_string) > max_value_len)
8411 value_string[max_value_len] = '\0';
8413 else if (type & TYPE_PLAYER)
8415 int displayed_player_nr = *(int *)value + 1;
8417 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
8420 startx = mSX + xpos * 32;
8421 starty = mSY + ypos * 32;
8423 // always use narrow font for setup values on right screen side
8424 if (xpos > MENU_SCREEN_START_XPOS)
8425 font_nr = getSetupValueFontNarrow(type, font_nr);
8427 // downward compatibility correction for Juergen Bonhagen's menu settings
8428 if (setup_mode != SETUP_MODE_INPUT)
8430 int max_menu_text_length_big = (menu_screen_value_xpos -
8431 MENU_SCREEN_START_XPOS);
8432 int max_menu_text_length_medium = max_menu_text_length_big * 2;
8433 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
8434 int font1_xoffset = getFontDrawOffsetX(font_nr);
8435 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
8436 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8437 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8438 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8439 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8440 boolean correct_font_draw_xoffset = FALSE;
8442 if (xpos == MENU_SCREEN_START_XPOS &&
8443 startx + font1_xoffset < text_startx + text_font_xoffset)
8444 correct_font_draw_xoffset = TRUE;
8446 if (xpos == menu_screen_value_xpos &&
8447 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8448 correct_font_draw_xoffset = TRUE;
8450 // check if setup value would overlap with setup text when printed
8451 // (this can happen for extreme/wrong values for font draw offset)
8452 if (correct_font_draw_xoffset)
8454 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8455 font_draw_xoffset_modified = TRUE;
8457 if (type & TYPE_KEY)
8458 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8459 else if (!(type & TYPE_STRING))
8460 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8461 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8465 DrawBackground(startx, starty, mx_right_border - startx, getFontHeight(font_nr));
8466 DrawText(startx, starty, value_string, font_nr);
8468 if (type & TYPE_PLAYER)
8470 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8471 int player_nr = *(int *)value;
8472 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8473 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8474 int startx2 = startx + xoff;
8475 int starty2 = starty + yoff;
8477 if (DrawingOnBackground(startx2, starty2))
8478 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8480 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8481 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8484 if (font_draw_xoffset_modified)
8485 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8488 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8490 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8491 struct TokenInfo *si = &setup_info[si_pos];
8493 if (si->type & TYPE_BOOLEAN_STYLE)
8495 *(boolean *)si->value ^= TRUE;
8497 else if (si->type & TYPE_YES_NO_AUTO)
8501 (*(int *)si->value == AUTO ? TRUE :
8502 *(int *)si->value == TRUE ? FALSE : AUTO) :
8503 (*(int *)si->value == TRUE ? AUTO :
8504 *(int *)si->value == AUTO ? FALSE : TRUE));
8506 else if (si->type & TYPE_KEY)
8510 si->type |= TYPE_QUERY;
8511 drawSetupValue(screen_pos, setup_info_pos_raw);
8512 si->type &= ~TYPE_QUERY;
8514 key = getSetupKey();
8515 if (key != KSYM_UNDEFINED)
8516 *(Key *)si->value = key;
8518 else if (si->type & TYPE_PLAYER)
8520 int player_nr = *(int *)si->value;
8525 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8527 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8530 drawSetupValue(screen_pos, setup_info_pos_raw);
8532 // fullscreen state may have changed at this point
8533 if (si->value == &setup.fullscreen)
8534 ToggleFullscreenIfNeeded();
8536 // network mode may have changed at this point
8537 if (si->value == &setup.network_mode)
8538 ToggleNetworkModeIfNeeded();
8540 // API server mode may have changed at this point
8541 if (si->value == &setup.use_api_server)
8542 ToggleUseApiServerIfNeeded();
8544 // game speed list may have changed at this point
8545 if (si->value == &setup.game_speed_extended)
8546 ToggleGameSpeedsListIfNeeded();
8549 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8551 static struct TokenInfo *setup_info_final = NULL;
8556 // determine maximum list size of target list
8557 while (setup_info_orig[list_size++].type != 0);
8559 // free, allocate and clear memory for target list
8560 checked_free(setup_info_final);
8561 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8563 // copy setup info list without setup entries marked as hidden
8564 for (i = 0; setup_info_orig[i].type != 0; i++)
8566 // skip setup entries configured to be hidden
8567 if (hideSetupEntry(setup_info_orig[i].value))
8570 // skip skippable setup entries if screen is lower than usual
8571 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8572 setup_info_orig[i].type == TYPE_SKIPPABLE)
8575 setup_info_final[list_pos++] = setup_info_orig[i];
8578 return setup_info_final;
8581 static void DrawSetupScreen_Generic(void)
8583 int fade_mask = REDRAW_FIELD;
8584 boolean redraw_all = FALSE;
8585 char *title_string = NULL;
8589 fade_mask = REDRAW_ALL;
8592 FadeMenuSoundsAndMusic();
8594 FreeScreenGadgets();
8595 CreateScreenGadgets();
8597 if (redraw_mask & REDRAW_ALL)
8602 // needed if different viewport properties defined for setup screen
8603 ChangeViewportPropertiesIfNeeded();
8605 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8609 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8611 if (setup_mode == SETUP_MODE_MAIN)
8613 setup_info = setup_info_main;
8614 title_string = STR_SETUP_MAIN;
8616 else if (setup_mode == SETUP_MODE_GAME)
8618 setup_info = setup_info_game;
8619 title_string = STR_SETUP_GAME;
8621 else if (setup_mode == SETUP_MODE_ENGINES)
8623 setup_info = setup_info_engines;
8624 title_string = STR_SETUP_ENGINES;
8626 else if (setup_mode == SETUP_MODE_EDITOR)
8628 setup_info = setup_info_editor;
8629 title_string = STR_SETUP_EDITOR;
8631 else if (setup_mode == SETUP_MODE_GRAPHICS)
8633 setup_info = setup_info_graphics;
8634 title_string = STR_SETUP_GRAPHICS;
8636 else if (setup_mode == SETUP_MODE_SOUND)
8638 setup_info = setup_info_sound;
8639 title_string = STR_SETUP_SOUND;
8641 else if (setup_mode == SETUP_MODE_ARTWORK)
8643 setup_info = setup_info_artwork;
8644 title_string = STR_SETUP_ARTWORK;
8646 else if (setup_mode == SETUP_MODE_TOUCH)
8648 setup_info = setup_info_touch;
8649 title_string = STR_SETUP_TOUCH;
8651 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8652 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8653 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8654 setup_info = setup_info_touch_wipe_gestures;
8656 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8658 setup_info = setup_info_shortcuts;
8659 title_string = STR_SETUP_SHORTCUTS;
8661 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8663 setup_info = setup_info_shortcuts_1;
8664 title_string = STR_SETUP_SHORTCUTS;
8666 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8668 setup_info = setup_info_shortcuts_2;
8669 title_string = STR_SETUP_SHORTCUTS;
8671 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8673 setup_info = setup_info_shortcuts_3;
8674 title_string = STR_SETUP_SHORTCUTS;
8676 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8678 setup_info = setup_info_shortcuts_4;
8679 title_string = STR_SETUP_SHORTCUTS;
8681 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8683 setup_info = setup_info_shortcuts_5;
8684 title_string = STR_SETUP_SHORTCUTS;
8687 // use modified setup info without setup entries marked as hidden
8688 setup_info = getSetupInfoFinal(setup_info);
8690 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8692 // determine maximal number of setup entries that can be displayed on screen
8694 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8697 // determine maximal number of setup entries available for this setup screen
8699 for (i = 0; setup_info[i].type != 0; i++)
8702 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8704 MapScreenGadgets(max_setup_info);
8707 redraw_mask = fade_mask = REDRAW_ALL;
8709 DrawMaskedBorder(fade_mask);
8714 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8716 menu_info = setup_info;
8718 HandleMenuScreen(mx, my, dx, dy, button,
8719 setup_mode, num_setup_info, max_setup_info);
8722 static void DrawSetupScreen_Input(void)
8726 FadeOut(REDRAW_FIELD);
8730 setup_info = getSetupInfoFinal(setup_info_input);
8732 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8734 for (i = 0; setup_info[i].type != 0; i++)
8736 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8737 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8738 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8739 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8740 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8741 initCursor(i, IMG_MENU_BUTTON);
8743 DrawCursorAndText_Setup(i, -1, FALSE);
8746 // create gadgets for setup input menu screen
8747 FreeScreenGadgets();
8748 CreateScreenGadgets();
8750 // map gadgets for setup input menu screen
8751 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8753 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8755 FadeIn(REDRAW_FIELD);
8758 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8760 if (device_name == NULL)
8763 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8766 if (strlen(device_name) > 1)
8768 char c1 = device_name[strlen(device_name) - 1];
8769 char c2 = device_name[strlen(device_name) - 2];
8771 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8772 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8775 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8776 strlen(device_name));
8779 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8782 static struct SetupKeyboardInfo custom_key;
8789 { &custom_key.left, "Axis/Pad Left" },
8790 { &custom_key.right, "Axis/Pad Right" },
8791 { &custom_key.up, "Axis/Pad Up" },
8792 { &custom_key.down, "Axis/Pad Down" },
8793 { &custom_key.snap, "Button 1/A/X" },
8794 { &custom_key.drop, "Button 2/B/Y" }
8796 static char *joystick_name[MAX_PLAYERS] =
8803 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8804 int font_nr_info = FONT_MENU_1;
8805 int font_nr_name = FONT_VALUE_OLD;
8806 int font_nr_on = FONT_VALUE_1;
8807 int font_nr_off = FONT_VALUE_OLD;
8810 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8812 font_nr_info = FONT_MENU_2;
8813 font_nr_on = FONT_VALUE_NARROW;
8814 font_nr_off = FONT_VALUE_OLD_NARROW;
8817 custom_key = setup.input[player_nr].key;
8819 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8820 FONT_INPUT_1_ACTIVE);
8822 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8824 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8825 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8827 if (setup.input[player_nr].use_joystick)
8829 char *device_name = setup.input[player_nr].joy.device_name;
8830 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8831 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8832 char *text = joystick_name[joystick_nr];
8833 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8835 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8836 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8840 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8841 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8844 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8845 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8849 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8850 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8851 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8852 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8854 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8855 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8856 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8857 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8858 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8859 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8861 for (i = 0; i < 6; i++)
8863 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8865 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8867 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8868 (setup.input[player_nr].use_joystick ?
8870 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8874 static int input_player_nr = 0;
8876 static void HandleSetupScreen_Input_Player(int step, int direction)
8878 int old_player_nr = input_player_nr;
8881 new_player_nr = old_player_nr + step * direction;
8882 if (new_player_nr < 0)
8884 if (new_player_nr > MAX_PLAYERS - 1)
8885 new_player_nr = MAX_PLAYERS - 1;
8887 if (new_player_nr != old_player_nr)
8889 input_player_nr = new_player_nr;
8891 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8895 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8897 static int choice = 0;
8900 int pos_start = SETUPINPUT_SCREEN_POS_START;
8901 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8902 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8903 int pos_end = SETUPINPUT_SCREEN_POS_END;
8905 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8909 for (i = 0; setup_info_input[i].type != 0; i++)
8911 // adjust menu structure according to skipped setup entries
8912 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8920 if (button == MB_MENU_INITIALIZE)
8922 // input setup menu may have changed size due to graphics configuration
8923 if (choice >= pos_empty1)
8926 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8928 DrawCursorAndText_Setup(choice, -1, TRUE);
8932 else if (button == MB_MENU_LEAVE)
8934 setup_mode = SETUP_MODE_MAIN;
8941 if (mx || my) // mouse input
8943 x = (mx - mSX) / 32;
8944 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8946 else if (dx || dy) // keyboard input
8948 if (dx && choice == 0)
8949 x = (dx < 0 ? 10 : 12);
8950 else if ((dx && choice == 1) ||
8951 (dx == -1 && choice == pos_end))
8952 button = MB_MENU_CHOICE;
8956 if (y >= pos_empty1 && y <= pos_empty2)
8957 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8960 if (y == 0 && dx != 0 && button)
8962 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8964 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8965 y >= pos_start && y <= pos_end &&
8966 !(y >= pos_empty1 && y <= pos_empty2))
8972 DrawCursorAndText_Setup(choice, -1, FALSE);
8973 DrawCursorAndText_Setup(y, -1, TRUE);
8975 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8984 char *device_name = setup.input[input_player_nr].joy.device_name;
8986 if (!setup.input[input_player_nr].use_joystick)
8988 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8990 setJoystickDeviceToNr(device_name, new_device_nr);
8991 setup.input[input_player_nr].use_joystick = TRUE;
8995 int device_nr = getJoystickNrFromDeviceName(device_name);
8996 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8998 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8999 setup.input[input_player_nr].use_joystick = FALSE;
9001 setJoystickDeviceToNr(device_name, new_device_nr);
9004 drawPlayerSetupInputInfo(input_player_nr, FALSE);
9008 if (setup.input[input_player_nr].use_joystick)
9009 ConfigureJoystick(input_player_nr);
9011 CustomizeKeyboard(input_player_nr);
9013 else if (y == pos_end)
9019 setup_mode = SETUP_MODE_MAIN;
9026 static boolean CustomizeKeyboardMain(int player_nr)
9030 boolean finished = FALSE;
9031 static struct SetupKeyboardInfo custom_key;
9036 } customize_step[] =
9038 { &custom_key.left, "Move Left" },
9039 { &custom_key.right, "Move Right" },
9040 { &custom_key.up, "Move Up" },
9041 { &custom_key.down, "Move Down" },
9042 { &custom_key.snap, "Snap Field" },
9043 { &custom_key.drop, "Drop Element" }
9045 int font_nr_old = FONT_VALUE_OLD;
9046 int font_nr_new = FONT_VALUE_1;
9047 boolean success = FALSE;
9049 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
9051 font_nr_old = FONT_VALUE_OLD_NARROW;
9052 font_nr_new = FONT_VALUE_NARROW;
9055 // read existing key bindings from player setup
9056 custom_key = setup.input[player_nr].key;
9059 FadeOut(REDRAW_FIELD);
9063 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
9066 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
9067 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
9068 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
9069 "Key:", FONT_INPUT_1_ACTIVE);
9070 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
9071 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
9073 FadeIn(REDRAW_FIELD);
9078 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
9080 // reset frame delay counter directly after updating screen
9081 ResetDelayCounter(&event_frame_delay);
9083 while (NextValidEvent(&event))
9087 case EVENT_KEYPRESS:
9089 Key key = GetEventKey((KeyEvent *)&event);
9091 // press 'Escape' to abort and keep the old key bindings
9092 if (key == KSYM_Escape)
9094 FadeSkipNextFadeIn();
9101 // press 'Enter' to keep the existing key binding
9102 if (key == KSYM_Return)
9103 key = *customize_step[step_nr].key;
9105 // check if key already used
9106 for (i = 0; i < step_nr; i++)
9107 if (*customize_step[i].key == key)
9112 // got new key binding
9113 *customize_step[step_nr].key = key;
9114 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
9116 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
9117 getKeyNameFromKey(key), font_nr_new);
9120 // un-highlight last query
9121 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
9122 customize_step[step_nr - 1].text, FONT_MENU_1);
9123 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
9124 "Key:", FONT_MENU_1);
9126 // all keys configured
9135 // query next key binding
9136 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
9137 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
9138 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
9139 "Key:", FONT_INPUT_1_ACTIVE);
9140 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
9141 getKeyNameFromKey(*customize_step[step_nr].key),
9146 case EVENT_KEYRELEASE:
9147 key_joystick_mapping = 0;
9151 HandleOtherEvents(&event);
9155 // do not handle events for longer than standard frame delay period
9156 if (DelayReached(&event_frame_delay))
9163 // write new key bindings back to player setup, if successfully finished
9165 setup.input[player_nr].key = custom_key;
9170 void CustomizeKeyboard(int player_nr)
9172 boolean success = CustomizeKeyboardMain(player_nr);
9176 int font_nr = FONT_TITLE_1;
9177 int font_height = getFontHeight(font_nr);
9178 int ypos1 = SYSIZE / 2 - font_height * 2;
9179 int ypos2 = SYSIZE / 2 - font_height * 1;
9180 DelayCounter wait_frame_delay = { 2000 };
9182 ResetDelayCounter(&wait_frame_delay);
9186 DrawTextSCentered(ypos1, font_nr, "Keyboard");
9187 DrawTextSCentered(ypos2, font_nr, "configured!");
9189 while (!DelayReached(&wait_frame_delay))
9195 DrawSetupScreen_Input();
9198 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
9200 #define MARKER_BUTTON 1
9201 #define MARKER_AXIS_X 2
9202 #define MARKER_AXIS_Y 3
9204 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
9206 static boolean bitmaps_initialized = FALSE;
9207 boolean screen_initialized = FALSE;
9208 static Bitmap *controller, *button, *axis_x, *axis_y;
9210 boolean success = TRUE;
9211 boolean done = FALSE, next = FALSE;
9213 int alpha = 200, alpha_step = -1;
9214 int alpha_ticks = 0;
9215 char mapping[4096], temp[256];
9216 int font_name = MENU_SETUP_FONT_TITLE;
9217 int font_info = MENU_SETUP_FONT_TEXT;
9218 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
9219 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
9220 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
9221 int ystep_name = getMenuTextStep(spacing_name, font_name);
9222 int ystep_line = getMenuTextStep(spacing_line, font_info);
9223 int ystep_para = getMenuTextStep(spacing_para, font_info);
9231 int axis, button, hat, hat_value;
9234 *step, *prev_step, steps[] =
9236 { 356, 155, MARKER_BUTTON, "a", },
9237 { 396, 122, MARKER_BUTTON, "b", },
9238 { 320, 125, MARKER_BUTTON, "x", },
9239 { 358, 95, MARKER_BUTTON, "y", },
9240 { 162, 125, MARKER_BUTTON, "back", },
9241 { 216, 125, MARKER_BUTTON, "guide", },
9242 { 271, 125, MARKER_BUTTON, "start", },
9243 { 110, 200, MARKER_BUTTON, "dpleft", },
9244 { 146, 228, MARKER_BUTTON, "dpdown", },
9245 { 178, 200, MARKER_BUTTON, "dpright", },
9246 { 146, 172, MARKER_BUTTON, "dpup", },
9247 { 50, 40, MARKER_BUTTON, "leftshoulder", },
9248 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
9249 { 382, 40, MARKER_BUTTON, "rightshoulder", },
9250 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
9251 { 73, 141, MARKER_BUTTON, "leftstick", },
9252 { 282, 210, MARKER_BUTTON, "rightstick", },
9253 { 73, 141, MARKER_AXIS_X, "leftx", },
9254 { 73, 141, MARKER_AXIS_Y, "lefty", },
9255 { 282, 210, MARKER_AXIS_X, "rightx", },
9256 { 282, 210, MARKER_AXIS_Y, "righty", },
9259 if (!bitmaps_initialized)
9261 controller = LoadCustomImage("joystick/controller.png");
9262 button = LoadCustomImage("joystick/button.png");
9263 axis_x = LoadCustomImage("joystick/axis_x.png");
9264 axis_y = LoadCustomImage("joystick/axis_y.png");
9266 bitmaps_initialized = TRUE;
9269 name = getFormattedJoystickName(SDL_JoystickName(joystick));
9272 // print info about the joystick we are watching
9273 Debug("joystick", "watching joystick %d: (%s)",
9274 SDL_JoystickInstanceID(joystick), name);
9275 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
9276 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
9277 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
9280 // initialize mapping with GUID and name
9281 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
9283 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
9284 temp, name, SDL_GetPlatform());
9286 // loop through all steps (buttons and axes), getting joystick events
9287 for (i = 0; i < SDL_arraysize(steps) && !done;)
9289 Bitmap *marker = button; // initialize with reliable default value
9292 strcpy(step->mapping, mapping);
9296 step->hat_value = -1;
9298 marker = (step->marker == MARKER_BUTTON ? button :
9299 step->marker == MARKER_AXIS_X ? axis_x :
9300 step->marker == MARKER_AXIS_Y ? axis_y : marker);
9304 while (!done && !next)
9306 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
9307 alpha_ticks = SDL_GetTicks();
9314 else if (alpha < 128)
9320 int controller_x = SX + (SXSIZE - controller->width) / 2;
9321 int controller_y = SY + ystep_line;
9323 int marker_x = controller_x + step->x;
9324 int marker_y = controller_y + step->y;
9326 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
9327 int ystart2 = ystart1 + ystep_name + ystep_line;
9331 DrawTextSCentered(ystart1, font_name, name);
9333 DrawTextSCentered(ystart2, font_info,
9334 "Press buttons and move axes on");
9335 ystart2 += ystep_line;
9336 DrawTextSCentered(ystart2, font_info,
9337 "your controller when indicated.");
9338 ystart2 += ystep_line;
9339 DrawTextSCentered(ystart2, font_info,
9340 "(Your controller may look different.)");
9341 ystart2 += ystep_para;
9343 #if defined(PLATFORM_ANDROID)
9344 DrawTextSCentered(ystart2, font_info,
9345 "To correct a mistake,");
9346 ystart2 += ystep_line;
9347 DrawTextSCentered(ystart2, font_info,
9348 "press the 'back' button.");
9349 ystart2 += ystep_line;
9350 DrawTextSCentered(ystart2, font_info,
9351 "To skip a button or axis,");
9352 ystart2 += ystep_line;
9353 DrawTextSCentered(ystart2, font_info,
9354 "press the 'menu' button.");
9356 DrawTextSCentered(ystart2, font_info,
9357 "To correct a mistake,");
9358 ystart2 += ystep_line;
9359 DrawTextSCentered(ystart2, font_info,
9360 "press the 'backspace' key.");
9361 ystart2 += ystep_line;
9362 DrawTextSCentered(ystart2, font_info,
9363 "To skip a button or axis,");
9364 ystart2 += ystep_line;
9365 DrawTextSCentered(ystart2, font_info,
9366 "press the 'return' key.");
9367 ystart2 += ystep_line;
9368 DrawTextSCentered(ystart2, font_info,
9369 "To exit, press the 'escape' key.");
9372 BlitBitmapMasked(controller, drawto, 0, 0,
9373 controller->width, controller->height,
9374 controller_x, controller_y);
9376 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
9377 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
9379 BlitBitmapMasked(marker, drawto, 0, 0,
9380 marker->width, marker->height,
9381 marker_x, marker_y);
9383 if (!screen_initialized)
9384 FadeIn(REDRAW_FIELD);
9388 screen_initialized = TRUE;
9390 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
9392 // reset frame delay counter directly after updating screen
9393 ResetDelayCounter(&event_frame_delay);
9395 while (NextValidEvent(&event))
9399 case SDL_JOYAXISMOTION:
9400 if (event.jaxis.value > 20000 ||
9401 event.jaxis.value < -20000)
9403 for (j = 0; j < i; j++)
9404 if (steps[j].axis == event.jaxis.axis)
9409 if (step->marker != MARKER_AXIS_X &&
9410 step->marker != MARKER_AXIS_Y)
9413 step->axis = event.jaxis.axis;
9414 strcat(mapping, step->field);
9415 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
9416 strcat(mapping, temp);
9424 case SDL_JOYHATMOTION:
9425 // ignore centering; we're probably just coming back
9426 // to the center from the previous item we set
9427 if (event.jhat.value == SDL_HAT_CENTERED)
9430 for (j = 0; j < i; j++)
9431 if (steps[j].hat == event.jhat.hat &&
9432 steps[j].hat_value == event.jhat.value)
9437 step->hat = event.jhat.hat;
9438 step->hat_value = event.jhat.value;
9439 strcat(mapping, step->field);
9440 snprintf(temp, sizeof(temp), ":h%u.%u,",
9441 event.jhat.hat, event.jhat.value );
9442 strcat(mapping, temp);
9449 case SDL_JOYBALLMOTION:
9452 case SDL_JOYBUTTONUP:
9453 for (j = 0; j < i; j++)
9454 if (steps[j].button == event.jbutton.button)
9459 step->button = event.jbutton.button;
9460 strcat(mapping, step->field);
9461 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9462 strcat(mapping, temp);
9469 case SDL_FINGERDOWN:
9470 case SDL_MOUSEBUTTONDOWN:
9478 if (event.key.keysym.sym == KSYM_BackSpace ||
9479 event.key.keysym.sym == KSYM_Back)
9491 prev_step = &steps[i - 1];
9492 strcpy(mapping, prev_step->mapping);
9499 if (event.key.keysym.sym == KSYM_space ||
9500 event.key.keysym.sym == KSYM_Return ||
9501 event.key.keysym.sym == KSYM_Menu)
9510 if (event.key.keysym.sym == KSYM_Escape)
9520 program.exit_function(0);
9527 // do not handle events for longer than standard frame delay period
9528 if (DelayReached(&event_frame_delay))
9537 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9540 // activate mapping for this game
9541 SDL_GameControllerAddMapping(mapping);
9543 // save mapping to personal mappings
9544 SaveSetup_AddGameControllerMapping(mapping);
9547 // wait until the last pending event was removed from event queue
9548 while (NextValidEvent(&event));
9553 static int ConfigureJoystickMain(int player_nr)
9555 char *device_name = setup.input[player_nr].joy.device_name;
9556 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9557 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9558 int success = FALSE;
9561 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9562 return JOYSTICK_NOT_AVAILABLE;
9564 if (!joystick_active || !setup.input[player_nr].use_joystick)
9565 return JOYSTICK_NOT_AVAILABLE;
9568 FadeOut(REDRAW_FIELD);
9570 // close all joystick devices (potentially opened as game controllers)
9571 for (i = 0; i < SDL_NumJoysticks(); i++)
9572 SDLCloseJoystick(i);
9574 // open joystick device as plain joystick to configure as game controller
9575 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9577 // as the joystick was successfully opened before, this should not happen
9578 if (joystick == NULL)
9581 // create new game controller mapping (buttons and axes) for joystick device
9582 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9584 // close joystick (and maybe re-open as configured game controller later)
9585 SDL_JoystickClose(joystick);
9587 // re-open all joystick devices (potentially as game controllers)
9588 for (i = 0; i < SDL_NumJoysticks(); i++)
9591 // clear all joystick input actions for all joystick devices
9592 SDLClearJoystickState();
9594 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9597 void ConfigureJoystick(int player_nr)
9599 boolean state = ConfigureJoystickMain(player_nr);
9601 if (state != JOYSTICK_NOT_CONFIGURED)
9603 boolean success = (state == JOYSTICK_CONFIGURED);
9604 char message1[MAX_OUTPUT_LINESIZE + 1];
9605 char *message2 = (success ? "configured!" : "not available!");
9606 char *device_name = setup.input[player_nr].joy.device_name;
9607 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9608 int font_nr = FONT_TITLE_1;
9609 int font_height = getFontHeight(font_nr);
9610 int ypos1 = SYSIZE / 2 - font_height * 2;
9611 int ypos2 = SYSIZE / 2 - font_height * 1;
9612 DelayCounter wait_frame_delay = { 2000 };
9614 ResetDelayCounter(&wait_frame_delay);
9618 sprintf(message1, "Joystick %d", nr);
9620 DrawTextSCentered(ypos1, font_nr, message1);
9621 DrawTextSCentered(ypos2, font_nr, message2);
9623 while (!DelayReached(&wait_frame_delay))
9629 DrawSetupScreen_Input();
9632 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9634 if (y < video.screen_height / 3)
9636 // remap touch gadgets to access upper part of the screen
9637 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9638 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9640 else if (y > 2 * video.screen_height / 3)
9642 // remap touch gadgets to access lower part of the screen
9643 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9644 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9648 static boolean ConfigureVirtualButtonsMain(void)
9650 static char *customize_step_text[] =
9659 char grid_button[] =
9661 CHAR_GRID_BUTTON_LEFT,
9662 CHAR_GRID_BUTTON_RIGHT,
9663 CHAR_GRID_BUTTON_UP,
9664 CHAR_GRID_BUTTON_DOWN,
9665 CHAR_GRID_BUTTON_SNAP,
9666 CHAR_GRID_BUTTON_DROP
9675 int font_nr = FONT_INPUT_1_ACTIVE;
9676 int font_height = getFontHeight(font_nr);
9677 int ypos1 = SYSIZE / 2 - font_height * 2;
9678 int ypos2 = SYSIZE / 2 - font_height * 1;
9679 boolean success = FALSE;
9680 boolean finished = FALSE;
9682 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9683 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9684 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9685 boolean set_grid_button = FALSE;
9686 int nr = GRID_ACTIVE_NR();
9689 for (x = 0; x < MAX_GRID_XSIZE; x++)
9690 for (y = 0; y < MAX_GRID_YSIZE; y++)
9691 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9693 overlay.grid_button_highlight = grid_button[step_nr];
9698 FadeOut(REDRAW_FIELD);
9702 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9703 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9704 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9706 FadeIn(REDRAW_FIELD);
9708 SetOverlayShowGrid(TRUE);
9710 // map gadgets for setup touch buttons menu screen
9711 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9717 while (NextValidEvent(&event))
9719 int action = ACTION_NONE;
9721 // ---------- handle events and set the resulting action ----------
9727 UserEvent *user = (UserEvent *)&event;
9728 int id = user->value1;
9730 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9731 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9732 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9733 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9738 case EVENT_KEYPRESS:
9740 Key key = GetEventKey((KeyEvent *)&event);
9742 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9743 key == KSYM_BackSpace ||
9744 key == KSYM_Back ? ACTION_BACK :
9745 key == KSYM_Return ||
9747 key == KSYM_space ? ACTION_NEXT :
9752 case EVENT_KEYRELEASE:
9753 key_joystick_mapping = 0;
9756 case EVENT_BUTTONPRESS:
9757 case EVENT_BUTTONRELEASE:
9759 ButtonEvent *button = (ButtonEvent *)&event;
9761 motion_status = FALSE;
9763 if (button->type == EVENT_BUTTONPRESS)
9764 button_status = button->button;
9766 button_status = MB_RELEASED;
9768 if (HandleGadgets(button->x, button->y, button_status))
9770 // do not handle this button event anymore
9774 button->x += video.screen_xoffset;
9775 button->y += video.screen_yoffset;
9777 x = button->x * overlay.grid_xsize / video.screen_width;
9778 y = button->y * overlay.grid_ysize / video.screen_height;
9780 if (button->type == EVENT_BUTTONPRESS)
9783 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9784 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9786 set_grid_button = TRUE;
9789 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9793 case EVENT_MOTIONNOTIFY:
9795 MotionEvent *motion = (MotionEvent *)&event;
9797 motion_status = TRUE;
9799 if (HandleGadgets(motion->x, motion->y, button_status))
9801 // do not handle this button event anymore
9805 motion->x += video.screen_xoffset;
9806 motion->y += video.screen_yoffset;
9808 x = motion->x * overlay.grid_xsize / video.screen_width;
9809 y = motion->y * overlay.grid_ysize / video.screen_height;
9811 set_grid_button = TRUE;
9813 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9817 case SDL_WINDOWEVENT:
9818 HandleWindowEvent((WindowEvent *) &event);
9820 // check if device has been rotated
9821 if (nr != GRID_ACTIVE_NR())
9823 nr = GRID_ACTIVE_NR();
9825 for (x = 0; x < MAX_GRID_XSIZE; x++)
9826 for (y = 0; y < MAX_GRID_YSIZE; y++)
9827 grid_button_old[x][y] = grid_button_tmp[x][y] =
9828 overlay.grid_button[x][y];
9833 case SDL_APP_WILLENTERBACKGROUND:
9834 case SDL_APP_DIDENTERBACKGROUND:
9835 case SDL_APP_WILLENTERFOREGROUND:
9836 case SDL_APP_DIDENTERFOREGROUND:
9837 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9841 HandleOtherEvents(&event);
9845 // ---------- perform action set by handling events ----------
9847 if (action == ACTION_ESCAPE)
9849 // abort and restore the old key bindings
9851 for (x = 0; x < MAX_GRID_XSIZE; x++)
9852 for (y = 0; y < MAX_GRID_YSIZE; y++)
9853 overlay.grid_button[x][y] = grid_button_old[x][y];
9855 FadeSkipNextFadeIn();
9859 else if (action == ACTION_BACK)
9861 // keep the configured key bindings and go to previous page
9867 FadeSkipNextFadeIn();
9872 else if (action == ACTION_NEXT)
9874 // keep the configured key bindings and go to next page
9878 // all virtual buttons configured
9886 if (action != ACTION_NONE && !finished)
9888 for (x = 0; x < MAX_GRID_XSIZE; x++)
9889 for (y = 0; y < MAX_GRID_YSIZE; y++)
9890 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9892 overlay.grid_button_highlight = grid_button[step_nr];
9894 // configure next virtual button
9898 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9899 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9900 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9903 if (set_grid_button)
9905 overlay.grid_button[x][y] =
9906 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9907 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9908 grid_button_tmp[x][y]);
9910 set_grid_button = FALSE;
9917 for (x = 0; x < MAX_GRID_XSIZE; x++)
9918 for (y = 0; y < MAX_GRID_YSIZE; y++)
9919 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9921 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9923 SetOverlayShowGrid(FALSE);
9928 void ConfigureVirtualButtons(void)
9930 boolean success = ConfigureVirtualButtonsMain();
9932 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9933 SCREEN_MASK_TOUCH2);
9937 int font_nr = FONT_TITLE_1;
9938 int font_height = getFontHeight(font_nr);
9939 int ypos1 = SYSIZE / 2 - font_height * 2;
9940 int ypos2 = SYSIZE / 2 - font_height * 1;
9941 DelayCounter wait_frame_delay = { 2000 };
9943 ResetDelayCounter(&wait_frame_delay);
9947 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9948 DrawTextSCentered(ypos2, font_nr, "configured!");
9950 while (!DelayReached(&wait_frame_delay))
9957 void DrawSetupScreen(void)
9962 if (setup_mode == SETUP_MODE_INPUT)
9963 DrawSetupScreen_Input();
9964 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9965 DrawChooseTree(&scores_type_current);
9966 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9967 DrawChooseTree(&game_speed_current);
9968 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9969 DrawChooseTree(&scroll_delay_current);
9970 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9971 DrawChooseTree(&snapshot_mode_current);
9972 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_ENGINE_TYPE)
9973 DrawChooseTree(&game_engine_type_current);
9974 else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64)
9975 DrawChooseTree(&bd_palette_c64_current);
9976 else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV)
9977 DrawChooseTree(&bd_palette_c64dtv_current);
9978 else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI)
9979 DrawChooseTree(&bd_palette_atari_current);
9980 else if (setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE)
9981 DrawChooseTree(&bd_color_type_current);
9982 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9983 DrawChooseTree(&window_size_current);
9984 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9985 DrawChooseTree(&scaling_type_current);
9986 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9987 DrawChooseTree(&rendering_mode_current);
9988 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9989 DrawChooseTree(&vsync_mode_current);
9990 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9991 DrawChooseTree(&artwork.gfx_current);
9992 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9993 DrawChooseTree(&artwork.snd_current);
9994 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9995 DrawChooseTree(&artwork.mus_current);
9996 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9997 DrawChooseTree(&volume_simple_current);
9998 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9999 DrawChooseTree(&volume_loops_current);
10000 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
10001 DrawChooseTree(&volume_music_current);
10002 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
10003 DrawChooseTree(&touch_control_current);
10004 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
10005 DrawChooseTree(&move_distance_current);
10006 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
10007 DrawChooseTree(&drop_distance_current);
10008 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
10009 DrawChooseTree(&transparency_current);
10010 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
10011 DrawChooseTree(&grid_size_current[0][0]);
10012 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
10013 DrawChooseTree(&grid_size_current[0][1]);
10014 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
10015 DrawChooseTree(&grid_size_current[1][0]);
10016 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
10017 DrawChooseTree(&grid_size_current[1][1]);
10019 DrawSetupScreen_Generic();
10021 PlayMenuSoundsAndMusic();
10024 void RedrawSetupScreenAfterFullscreenToggle(void)
10026 if (setup_mode == SETUP_MODE_GRAPHICS ||
10027 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
10029 // update list selection from "setup.window_scaling_percent"
10030 execSetupGraphics_setWindowSizes(TRUE);
10036 void RedrawSetupScreenAfterScreenRotation(int nr)
10040 if (setup_mode == SETUP_MODE_TOUCH)
10042 // update virtual button settings (depending on screen orientation)
10045 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
10047 // save already configured virtual buttons
10048 for (x = 0; x < MAX_GRID_XSIZE; x++)
10049 for (y = 0; y < MAX_GRID_YSIZE; y++)
10050 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
10054 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
10056 if (setup_mode == SETUP_MODE_INPUT)
10057 HandleSetupScreen_Input(mx, my, dx, dy, button);
10058 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
10059 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
10060 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
10061 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
10062 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
10063 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
10064 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
10065 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
10066 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_ENGINE_TYPE)
10067 HandleChooseTree(mx, my, dx, dy, button, &game_engine_type_current);
10068 else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64)
10069 HandleChooseTree(mx, my, dx, dy, button, &bd_palette_c64_current);
10070 else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV)
10071 HandleChooseTree(mx, my, dx, dy, button, &bd_palette_c64dtv_current);
10072 else if (setup_mode == SETUP_MODE_CHOOSE_BD_PALETTE_ATARI)
10073 HandleChooseTree(mx, my, dx, dy, button, &bd_palette_atari_current);
10074 else if (setup_mode == SETUP_MODE_CHOOSE_BD_COLOR_TYPE)
10075 HandleChooseTree(mx, my, dx, dy, button, &bd_color_type_current);
10076 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
10077 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
10078 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
10079 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
10080 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
10081 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
10082 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
10083 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
10084 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
10085 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
10086 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
10087 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
10088 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
10089 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
10090 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
10091 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
10092 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
10093 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
10094 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
10095 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
10096 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
10097 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
10098 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
10099 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
10100 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
10101 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
10102 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
10103 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
10104 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
10105 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
10106 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
10107 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
10108 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
10109 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
10110 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
10111 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
10113 HandleSetupScreen_Generic(mx, my, dx, dy, button);
10116 void HandleGameActions(void)
10118 if (CheckRestartGame())
10121 if (game_status != GAME_MODE_PLAYING)
10124 GameActions(); // main game loop
10126 if (tape.auto_play && !tape.playing)
10127 AutoPlayTapesContinue(); // continue automatically playing next tape
10131 // ---------- new screen button stuff --------------------------------------
10135 int gfx_unpressed, gfx_pressed, gfx_active;
10136 struct MenuPosInfo *pos;
10137 boolean *check_value;
10140 unsigned int event_mask;
10141 boolean is_touch_button;
10143 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
10146 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE, -1,
10147 &menu.main.button.prev_level, NULL,
10148 SCREEN_CTRL_ID_PREV_LEVEL,
10150 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
10151 FALSE, "previous level"
10154 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE, -1,
10155 &menu.main.button.next_level, NULL,
10156 SCREEN_CTRL_ID_NEXT_LEVEL,
10158 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
10159 FALSE, "next level"
10162 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE, -1,
10163 &menu.scores.button.prev_level, NULL,
10164 SCREEN_CTRL_ID_PREV_LEVEL2,
10165 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
10166 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
10167 FALSE, "previous level"
10170 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE, -1,
10171 &menu.scores.button.next_level, NULL,
10172 SCREEN_CTRL_ID_NEXT_LEVEL2,
10173 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
10174 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
10175 FALSE, "next level"
10178 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE, -1,
10179 &menu.scores.button.prev_score, NULL,
10180 SCREEN_CTRL_ID_PREV_SCORE,
10181 SCREEN_MASK_SCORES_INFO,
10182 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
10183 FALSE, "previous score"
10186 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE, -1,
10187 &menu.scores.button.next_score, NULL,
10188 SCREEN_CTRL_ID_NEXT_SCORE,
10189 SCREEN_MASK_SCORES_INFO,
10190 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
10191 FALSE, "next score"
10194 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE, -1,
10195 &menu.scores.button.play_tape, NULL,
10196 SCREEN_CTRL_ID_PLAY_TAPE,
10197 SCREEN_MASK_SCORES_INFO,
10202 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE, -1,
10203 &menu.main.button.first_level, NULL,
10204 SCREEN_CTRL_ID_FIRST_LEVEL,
10207 FALSE, "first level"
10210 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE, -1,
10211 &menu.main.button.last_level, NULL,
10212 SCREEN_CTRL_ID_LAST_LEVEL,
10215 FALSE, "last level"
10218 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE, -1,
10219 &menu.main.button.level_number, NULL,
10220 SCREEN_CTRL_ID_LEVEL_NUMBER,
10223 FALSE, "level number"
10226 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE, -1,
10227 &menu.setup.button.prev_player, NULL,
10228 SCREEN_CTRL_ID_PREV_PLAYER,
10230 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
10231 FALSE, "previous player"
10234 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE, -1,
10235 &menu.setup.button.next_player, NULL,
10236 SCREEN_CTRL_ID_NEXT_PLAYER,
10238 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
10239 FALSE, "next player"
10242 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE, -1,
10243 &menu.main.button.insert_solution, NULL,
10244 SCREEN_CTRL_ID_INSERT_SOLUTION,
10245 SCREEN_MASK_MAIN_HAS_SOLUTION,
10247 FALSE, "insert solution tape"
10250 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE, -1,
10251 &menu.main.button.play_solution, NULL,
10252 SCREEN_CTRL_ID_PLAY_SOLUTION,
10253 SCREEN_MASK_MAIN_HAS_SOLUTION,
10255 FALSE, "play solution tape"
10258 IMG_MENU_BUTTON_LEVELSET_INFO, IMG_MENU_BUTTON_LEVELSET_INFO_PRESSED,
10259 IMG_MENU_BUTTON_LEVELSET_INFO_ACTIVE,
10260 &menu.main.button.levelset_info, NULL,
10261 SCREEN_CTRL_ID_LEVELSET_INFO,
10262 SCREEN_MASK_MAIN_HAS_SET_INFO,
10264 FALSE, "show level set info"
10267 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE, -1,
10268 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
10269 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
10271 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
10272 FALSE, "switch ECS/AGA chipset"
10275 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK, -1,
10276 &menu.setup.button.touch_back, NULL,
10277 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
10280 TRUE, "previous page"
10283 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT, -1,
10284 &menu.setup.button.touch_next, NULL,
10285 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
10291 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2, -1,
10292 &menu.setup.button.touch_back2, NULL,
10293 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
10294 SCREEN_MASK_TOUCH2,
10296 TRUE, "previous page"
10299 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2, -1,
10300 &menu.setup.button.touch_next2, NULL,
10301 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
10302 SCREEN_MASK_TOUCH2,
10310 int gfx_unpressed, gfx_pressed;
10314 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
10317 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
10318 -1, -1, // these values are not constant, but can change at runtime
10319 SCREEN_CTRL_ID_SCROLL_UP,
10323 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
10324 -1, -1, // these values are not constant, but can change at runtime
10325 SCREEN_CTRL_ID_SCROLL_DOWN,
10332 int gfx_unpressed, gfx_pressed;
10338 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
10341 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
10342 -1, -1, // these values are not constant, but can change at runtime
10343 -1, -1, // these values are not constant, but can change at runtime
10344 GD_TYPE_SCROLLBAR_VERTICAL,
10345 SCREEN_CTRL_ID_SCROLL_VERTICAL,
10346 "scroll level series vertically"
10358 } textinput_info[NUM_SCREEN_TEXTINPUT] =
10361 IMG_SETUP_INPUT_TEXT,
10362 SCREEN_CTRL_ID_NETWORK_SERVER,
10363 -1, -1, // these values are not constant, but can change at runtime
10364 MAX_SETUP_TEXT_INPUT_LEN,
10365 network_server_hostname,
10366 "Network Server Hostname / IP"
10370 static void CreateScreenMenubuttons(void)
10372 struct GadgetInfo *gi;
10373 unsigned int event_mask;
10376 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10378 struct MenuPosInfo *pos = menubutton_info[i].pos;
10379 int screen_mask = menubutton_info[i].screen_mask;
10380 boolean is_touch_button = menubutton_info[i].is_touch_button;
10381 boolean is_check_button = menubutton_info[i].check_value != NULL;
10382 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
10383 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
10384 menubutton_info[i].gfx_unpressed);
10385 boolean has_gfx_active = (menubutton_info[i].gfx_active != -1);
10386 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10387 Bitmap *gd_bitmap_unpressed_alt, *gd_bitmap_pressed_alt;
10388 int gfx_unpressed, gfx_pressed;
10389 int gfx_unpressed_alt, gfx_pressed_alt;
10390 int x, y, width, height;
10391 int gd_x1, gd_x2, gd_y1, gd_y2;
10392 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
10393 int id = menubutton_info[i].gadget_id;
10394 int type = GD_TYPE_NORMAL_BUTTON;
10395 boolean checked = FALSE;
10397 // do not use touch buttons if overlay touch buttons are disabled
10398 if (is_touch_button && !setup.touch.overlay_buttons)
10401 event_mask = menubutton_info[i].event_mask;
10403 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
10404 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
10406 width = graphic_info[menubutton_info[i].gfx_pressed].width;
10407 height = graphic_info[menubutton_info[i].gfx_pressed].height;
10409 gfx_unpressed = menubutton_info[i].gfx_unpressed;
10410 gfx_pressed = menubutton_info[i].gfx_pressed;
10411 gfx_unpressed_alt = gfx_unpressed;
10412 gfx_pressed_alt = gfx_pressed;
10414 if (has_gfx_active)
10416 gfx_unpressed_alt = menubutton_info[i].gfx_active;
10418 type = GD_TYPE_CHECK_BUTTON_2;
10420 if (menubutton_info[i].check_value != NULL)
10421 checked = *menubutton_info[i].check_value;
10424 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10425 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10426 gd_bitmap_unpressed_alt = graphic_info[gfx_unpressed_alt].bitmap;
10427 gd_bitmap_pressed_alt = graphic_info[gfx_pressed_alt].bitmap;
10429 gd_x1 = graphic_info[gfx_unpressed].src_x;
10430 gd_y1 = graphic_info[gfx_unpressed].src_y;
10431 gd_x2 = graphic_info[gfx_pressed].src_x;
10432 gd_y2 = graphic_info[gfx_pressed].src_y;
10434 gd_x1a = graphic_info[gfx_unpressed_alt].src_x;
10435 gd_y1a = graphic_info[gfx_unpressed_alt].src_y;
10436 gd_x2a = graphic_info[gfx_pressed_alt].src_x;
10437 gd_y2a = graphic_info[gfx_pressed_alt].src_y;
10439 if (has_gfx_pressed)
10441 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
10442 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
10445 if (is_check_button)
10447 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
10448 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
10449 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
10450 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
10452 type = GD_TYPE_CHECK_BUTTON;
10454 if (menubutton_info[i].check_value != NULL)
10455 checked = *menubutton_info[i].check_value;
10458 if (is_score_button)
10460 // if x/y set to -1, dynamically place buttons next to title text
10461 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10463 // special compatibility handling for "Snake Bite" graphics set
10464 if (strPrefix(leveldir_current->identifier, "snake_bite"))
10465 title_width = strlen(INFOTEXT_SCORE_ENTRY) * 32;
10467 // use "SX" here to center buttons (ignore horizontal draw offset)
10469 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10470 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10471 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10472 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10474 // use "mSY" here to place buttons (respect vertical draw offset)
10476 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
10477 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
10480 if (id == SCREEN_CTRL_ID_LEVELSET_INFO)
10482 if (pos->x == -1 && pos->y == -1)
10484 // use "SX" here to place button (ignore draw offsets)
10485 x = SX + SXSIZE - 2 * TILESIZE;
10486 y = SY + SYSIZE - 2 * TILESIZE;
10488 // special compatibility handling for "BD2K3" graphics set
10489 if (strPrefix(leveldir_current->identifier, "BD2K3"))
10490 x = SX + TILESIZE + MINI_TILESIZE;
10492 // special compatibility handling for "jue0" graphics set
10493 if (strPrefix(artwork.gfx_current_identifier, "jue0"))
10495 x = SX + SXSIZE - 4 * TILESIZE;
10496 y = SY + SYSIZE - 3 * TILESIZE;
10501 gi = CreateGadget(GDI_CUSTOM_ID, id,
10502 GDI_CUSTOM_TYPE_ID, i,
10503 GDI_IMAGE_ID, gfx_unpressed,
10504 GDI_INFO_TEXT, menubutton_info[i].infotext,
10508 GDI_HEIGHT, height,
10510 GDI_STATE, GD_BUTTON_UNPRESSED,
10511 GDI_CHECKED, checked,
10512 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10513 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10514 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed_alt, gd_x1a, gd_y1a,
10515 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed_alt, gd_x2a, gd_y2a,
10516 GDI_DIRECT_DRAW, FALSE,
10517 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10518 GDI_EVENT_MASK, event_mask,
10519 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10523 Fail("cannot create gadget");
10525 screen_gadget[id] = gi;
10529 static void CreateScreenScrollbuttons(void)
10531 struct GadgetInfo *gi;
10532 unsigned int event_mask;
10535 // these values are not constant, but can change at runtime
10536 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10537 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10538 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10539 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10541 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10543 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10544 int gfx_unpressed, gfx_pressed;
10545 int x, y, width, height;
10546 int gd_x1, gd_x2, gd_y1, gd_y2;
10547 int id = scrollbutton_info[i].gadget_id;
10549 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10551 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10552 y = mSY + scrollbutton_info[i].y;
10553 width = SC_SCROLLBUTTON_XSIZE;
10554 height = SC_SCROLLBUTTON_YSIZE;
10556 // correct scrollbar position if placed outside menu (playfield) area
10557 if (x > SX + SC_SCROLL_UP_XPOS)
10558 x = SX + SC_SCROLL_UP_XPOS;
10560 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10561 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10562 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10564 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10565 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10566 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10567 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10568 gd_x1 = graphic_info[gfx_unpressed].src_x;
10569 gd_y1 = graphic_info[gfx_unpressed].src_y;
10570 gd_x2 = graphic_info[gfx_pressed].src_x;
10571 gd_y2 = graphic_info[gfx_pressed].src_y;
10573 gi = CreateGadget(GDI_CUSTOM_ID, id,
10574 GDI_CUSTOM_TYPE_ID, i,
10575 GDI_IMAGE_ID, gfx_unpressed,
10576 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10580 GDI_HEIGHT, height,
10581 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10582 GDI_STATE, GD_BUTTON_UNPRESSED,
10583 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10584 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10585 GDI_DIRECT_DRAW, FALSE,
10586 GDI_EVENT_MASK, event_mask,
10587 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10591 Fail("cannot create gadget");
10593 screen_gadget[id] = gi;
10597 static void CreateScreenScrollbars(void)
10601 // these values are not constant, but can change at runtime
10602 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10603 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10604 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10605 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10607 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10609 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10610 int gfx_unpressed, gfx_pressed;
10611 int x, y, width, height;
10612 int gd_x1, gd_x2, gd_y1, gd_y2;
10613 struct GadgetInfo *gi;
10614 int items_max, items_visible, item_position;
10615 unsigned int event_mask;
10616 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10617 int id = scrollbar_info[i].gadget_id;
10619 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10621 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10622 y = mSY + scrollbar_info[i].y;
10623 width = scrollbar_info[i].width;
10624 height = scrollbar_info[i].height;
10626 // correct scrollbar position if placed outside menu (playfield) area
10627 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10628 x = SX + SC_SCROLL_VERTICAL_XPOS;
10630 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10631 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10633 items_max = num_page_entries;
10634 items_visible = num_page_entries;
10637 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10638 gfx_pressed = scrollbar_info[i].gfx_pressed;
10639 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10640 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10641 gd_x1 = graphic_info[gfx_unpressed].src_x;
10642 gd_y1 = graphic_info[gfx_unpressed].src_y;
10643 gd_x2 = graphic_info[gfx_pressed].src_x;
10644 gd_y2 = graphic_info[gfx_pressed].src_y;
10646 gi = CreateGadget(GDI_CUSTOM_ID, id,
10647 GDI_CUSTOM_TYPE_ID, i,
10648 GDI_IMAGE_ID, gfx_unpressed,
10649 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10653 GDI_HEIGHT, height,
10654 GDI_TYPE, scrollbar_info[i].type,
10655 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10656 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10657 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10658 GDI_WHEEL_AREA_X, SX,
10659 GDI_WHEEL_AREA_Y, SY,
10660 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10661 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10662 GDI_STATE, GD_BUTTON_UNPRESSED,
10663 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10664 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10665 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10666 GDI_DIRECT_DRAW, FALSE,
10667 GDI_EVENT_MASK, event_mask,
10668 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10672 Fail("cannot create gadget");
10674 screen_gadget[id] = gi;
10678 static void CreateScreenTextInputGadgets(void)
10682 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10684 int graphic = textinput_info[i].graphic;
10685 struct GraphicInfo *gd = &graphic_info[graphic];
10686 int gd_x1 = gd->src_x;
10687 int gd_y1 = gd->src_y;
10688 int gd_x2 = gd->src_x + gd->active_xoffset;
10689 int gd_y2 = gd->src_y + gd->active_yoffset;
10690 struct GadgetInfo *gi;
10691 unsigned int event_mask;
10692 int id = textinput_info[i].gadget_id;
10693 int x = textinput_info[i].x;
10694 int y = textinput_info[i].y;
10696 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10698 gi = CreateGadget(GDI_CUSTOM_ID, id,
10699 GDI_CUSTOM_TYPE_ID, i,
10700 GDI_INFO_TEXT, textinput_info[i].infotext,
10703 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10704 GDI_TEXT_VALUE, textinput_info[i].value,
10705 GDI_TEXT_SIZE, textinput_info[i].size,
10706 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10707 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10708 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10709 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10710 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10711 GDI_DESIGN_WIDTH, gd->width,
10712 GDI_EVENT_MASK, event_mask,
10713 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10714 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10718 Fail("cannot create gadget");
10720 screen_gadget[id] = gi;
10724 void CreateScreenGadgets(void)
10726 CreateScreenMenubuttons();
10728 CreateScreenScrollbuttons();
10729 CreateScreenScrollbars();
10731 CreateScreenTextInputGadgets();
10734 void FreeScreenGadgets(void)
10738 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10739 FreeGadget(screen_gadget[i]);
10742 static void RedrawScreenMenuGadgets(int screen_mask)
10746 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10747 if (screen_mask & menubutton_info[i].screen_mask)
10748 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10751 static void MapScreenMenuGadgets(int screen_mask)
10755 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10756 if (screen_mask & menubutton_info[i].screen_mask)
10757 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10760 static void UnmapScreenMenuGadgets(int screen_mask)
10764 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10766 if (screen_mask & menubutton_info[i].screen_mask)
10768 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10770 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10771 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10772 screen_gadget[menubutton_info[i].gadget_id]->y,
10773 screen_gadget[menubutton_info[i].gadget_id]->width,
10774 screen_gadget[menubutton_info[i].gadget_id]->height);
10779 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10782 MapScreenMenuGadgets(screen_mask);
10784 UnmapScreenMenuGadgets(screen_mask);
10787 static void MapScreenGadgets(int num_entries)
10791 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10794 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10795 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10797 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10798 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10801 static void UnmapScreenGadgets(void)
10805 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10806 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10808 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10809 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10812 static void MapScreenTreeGadgets(TreeInfo *ti)
10814 MapScreenGadgets(numTreeInfoInGroup(ti));
10817 static void UnmapScreenTreeGadgets(void)
10819 UnmapScreenGadgets();
10822 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10824 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10825 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10826 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10827 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10829 if (pos_1->x == -1 && pos_1->y == -1)
10830 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10832 if (pos_2->x == -1 && pos_2->y == -1)
10833 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10836 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10838 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10839 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10841 // set gadget position dynamically, pre-defined or off-screen
10842 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10843 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10845 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10846 MapGadget(gi); // (needed if deactivated on last score page)
10849 static void HandleScreenGadgets(struct GadgetInfo *gi)
10851 int id = gi->custom_id;
10852 int button = gi->event.button;
10853 int step = (button == MB_LEFTBUTTON ? 1 :
10854 button == MB_MIDDLEBUTTON ? 5 :
10855 button == MB_RIGHTBUTTON ? 10 : 1);
10859 case SCREEN_CTRL_ID_PREV_LEVEL:
10860 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10863 case SCREEN_CTRL_ID_NEXT_LEVEL:
10864 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10867 case SCREEN_CTRL_ID_PREV_LEVEL2:
10868 HandleHallOfFame_SelectLevel(step, -1);
10871 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10872 HandleHallOfFame_SelectLevel(step, +1);
10875 case SCREEN_CTRL_ID_PREV_SCORE:
10876 HandleScoreInfo_SelectScore(step, -1);
10879 case SCREEN_CTRL_ID_NEXT_SCORE:
10880 HandleScoreInfo_SelectScore(step, +1);
10883 case SCREEN_CTRL_ID_PLAY_TAPE:
10884 HandleScoreInfo_PlayTape();
10887 case SCREEN_CTRL_ID_FIRST_LEVEL:
10888 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10891 case SCREEN_CTRL_ID_LAST_LEVEL:
10892 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10895 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10896 CloseDoor(DOOR_CLOSE_2);
10897 SetGameStatus(GAME_MODE_LEVELNR);
10898 DrawChooseLevelNr();
10901 case SCREEN_CTRL_ID_PREV_PLAYER:
10902 HandleSetupScreen_Input_Player(step, -1);
10905 case SCREEN_CTRL_ID_NEXT_PLAYER:
10906 HandleSetupScreen_Input_Player(step, +1);
10909 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10910 InsertSolutionTape();
10913 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10914 PlaySolutionTape();
10917 case SCREEN_CTRL_ID_LEVELSET_INFO:
10918 DrawInfoScreen_FromMainMenu(INFO_MODE_LEVELSET);
10921 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10922 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10926 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10927 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10928 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10929 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10930 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10933 case SCREEN_CTRL_ID_SCROLL_UP:
10934 if (game_status == GAME_MODE_NAMES)
10935 HandleChoosePlayerName(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10936 else if (game_status == GAME_MODE_LEVELS)
10937 HandleChooseLevelSet(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10938 else if (game_status == GAME_MODE_LEVELNR)
10939 HandleChooseLevelNr(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10940 else if (game_status == GAME_MODE_SETUP)
10941 HandleSetupScreen(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10942 else if (game_status == GAME_MODE_INFO)
10943 HandleInfoScreen(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10944 else if (game_status == GAME_MODE_SCORES)
10945 HandleHallOfFame(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10948 case SCREEN_CTRL_ID_SCROLL_DOWN:
10949 if (game_status == GAME_MODE_NAMES)
10950 HandleChoosePlayerName(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10951 else if (game_status == GAME_MODE_LEVELS)
10952 HandleChooseLevelSet(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10953 else if (game_status == GAME_MODE_LEVELNR)
10954 HandleChooseLevelNr(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10955 else if (game_status == GAME_MODE_SETUP)
10956 HandleSetupScreen(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10957 else if (game_status == GAME_MODE_INFO)
10958 HandleInfoScreen(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10959 else if (game_status == GAME_MODE_SCORES)
10960 HandleHallOfFame(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10963 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10964 if (game_status == GAME_MODE_NAMES)
10965 HandleChoosePlayerName(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10966 else if (game_status == GAME_MODE_LEVELS)
10967 HandleChooseLevelSet(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10968 else if (game_status == GAME_MODE_LEVELNR)
10969 HandleChooseLevelNr(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10970 else if (game_status == GAME_MODE_SETUP)
10971 HandleSetupScreen(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10972 else if (game_status == GAME_MODE_INFO)
10973 HandleInfoScreen(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10974 else if (game_status == GAME_MODE_SCORES)
10975 HandleHallOfFame(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10978 case SCREEN_CTRL_ID_NETWORK_SERVER:
10980 if (!strEqual(gi->textinput.value, ""))
10982 setString(&setup.network_server_hostname, gi->textinput.value);
10984 network.server_host = setup.network_server_hostname;
10988 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10990 network.server_host = NULL;
10993 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10994 network.server_host = NULL;
10996 execSetupGame_setNetworkServerText();
11008 void HandleScreenGadgetKeys(Key key)
11010 if (key == setup.shortcut.tape_play || key == KSYM_Return)
11011 HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
11014 void DumpScreenIdentifiers(void)
11018 Print("Active screen elements on current screen:\n");
11020 for (i = 0; main_controls[i].nr != -1; i++)
11022 struct MainControlInfo *mci = &main_controls[i];
11024 if (mci->button_graphic != -1)
11026 char *token = getTokenFromImageID(mci->button_graphic);
11028 Print("- '%s'\n", token);
11035 boolean DoScreenAction(int image_id)
11039 if (game_status != GAME_MODE_MAIN)
11042 for (i = 0; main_controls[i].nr != -1; i++)
11044 struct MainControlInfo *mci = &main_controls[i];
11045 struct MenuPosInfo *pos = mci->pos_button;
11047 if (mci->button_graphic == image_id)
11049 int x = mSX + pos->x;
11050 int y = mSY + pos->y;
11052 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
11061 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
11063 // get tree info node of newly added level or artwork set
11064 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
11065 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
11067 if (tree_node_new == NULL) // should not happen
11070 // if request dialog is active, do nothing
11071 if (game.request_active)
11074 if (game_status == GAME_MODE_MAIN &&
11075 tree_type == TREE_TYPE_LEVEL_DIR)
11077 // when adding new level set in main menu, select it as current level set
11079 // change current level set to newly added level set from zip file
11080 leveldir_current = tree_node_new;
11082 // change current level number to first level of newly added level set
11083 level_nr = leveldir_current->first_level;
11085 // redraw screen to reflect changed level set
11088 // save this level set and level number as last selected level set
11089 SaveLevelSetup_LastSeries();
11090 SaveLevelSetup_SeriesInfo();
11092 else if (game_status == GAME_MODE_LEVELS &&
11093 tree_type == TREE_TYPE_LEVEL_DIR)
11095 // when adding new level set in level set menu, set cursor and update screen
11097 leveldir_current = tree_node_new;
11099 DrawChooseTree(&leveldir_current);
11101 else if (game_status == GAME_MODE_SETUP)
11103 // when adding new artwork set in setup menu, set cursor and update screen
11105 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
11106 tree_type == TREE_TYPE_GRAPHICS_DIR)
11108 artwork.gfx_current = tree_node_new;
11110 DrawChooseTree(&artwork.gfx_current);
11112 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
11113 tree_type == TREE_TYPE_SOUNDS_DIR)
11115 artwork.snd_current = tree_node_new;
11117 DrawChooseTree(&artwork.snd_current);
11119 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
11120 tree_type == TREE_TYPE_MUSIC_DIR)
11122 artwork.mus_current = tree_node_new;
11124 DrawChooseTree(&artwork.mus_current);
11129 static int UploadTapes(void)
11131 SetGameStatus(GAME_MODE_LOADING);
11133 FadeSetEnterScreen();
11134 FadeOut(REDRAW_ALL);
11136 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
11138 FadeIn(REDRAW_ALL);
11140 DrawInitTextHead("Uploading tapes");
11142 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
11143 global.autoplay_leveldir = "ALL";
11144 global.autoplay_all = TRUE;
11146 int num_tapes_uploaded = AutoPlayTapes();
11148 global.autoplay_mode = AUTOPLAY_MODE_NONE;
11149 global.autoplay_leveldir = NULL;
11150 global.autoplay_all = FALSE;
11152 SetGameStatus(GAME_MODE_MAIN);
11156 return num_tapes_uploaded;
11159 static boolean OfferUploadTapes(void)
11161 if (!Request(setup.has_remaining_tapes ?
11162 "Upload missing tapes to the high score server now?" :
11163 "Upload all your tapes to the high score server now?", REQ_ASK))
11166 // when uploading tapes, make sure that high score server is enabled
11167 runtime.use_api_server = setup.use_api_server = TRUE;
11169 int num_tapes_uploaded = UploadTapes();
11172 if (num_tapes_uploaded < 0)
11174 num_tapes_uploaded = -num_tapes_uploaded - 1;
11176 if (num_tapes_uploaded == 0)
11177 sprintf(message, "Upload failed! No tapes uploaded!");
11178 else if (num_tapes_uploaded == 1)
11179 sprintf(message, "Upload failed! Only 1 tape uploaded!");
11181 sprintf(message, "Upload failed! Only %d tapes uploaded!",
11182 num_tapes_uploaded);
11184 Request(message, REQ_CONFIRM);
11186 // if uploading tapes failed, add tape upload entry to setup menu
11187 setup.provide_uploading_tapes = TRUE;
11188 setup.has_remaining_tapes = TRUE;
11190 SaveSetup_ServerSetup();
11195 if (num_tapes_uploaded == 0)
11196 sprintf(message, "No tapes uploaded!");
11197 else if (num_tapes_uploaded == 1)
11198 sprintf(message, "1 tape uploaded!");
11200 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
11202 Request(message, REQ_CONFIRM);
11204 if (num_tapes_uploaded > 0)
11205 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
11207 // after all tapes have been uploaded, remove entry from setup menu
11208 setup.provide_uploading_tapes = FALSE;
11209 setup.has_remaining_tapes = FALSE;
11211 SaveSetup_ServerSetup();
11216 static void CheckUploadTapes(void)
11218 if (!setup.ask_for_uploading_tapes)
11221 // after asking for uploading tapes, do not ask again
11222 setup.ask_for_uploading_tapes = FALSE;
11223 setup.ask_for_remaining_tapes = FALSE;
11225 if (directoryExists(getTapeDir(NULL)))
11227 boolean tapes_uploaded = OfferUploadTapes();
11229 if (!tapes_uploaded)
11231 Request(setup.has_remaining_tapes ?
11232 "You can upload missing tapes from the setup menu later!" :
11233 "You can upload your tapes from the setup menu later!",
11239 // if tapes directory does not exist yet, never offer uploading all tapes
11240 setup.provide_uploading_tapes = FALSE;
11243 SaveSetup_ServerSetup();
11246 static void UpgradePlayerUUID(void)
11248 ApiResetUUIDAsThread(getUUID());
11251 static void CheckUpgradePlayerUUID(void)
11253 if (setup.player_version > 1)
11256 UpgradePlayerUUID();
11259 void CheckApiServerTasks(void)
11261 // check if the player's UUID has to be upgraded
11262 CheckUpgradePlayerUUID();
11264 // check if there are any tapes to be uploaded
11265 CheckUploadTapes();