1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
28 #define DEBUG_JOYSTICKS 0
31 // screens on the info screen
32 #define INFO_MODE_MAIN 0
33 #define INFO_MODE_TITLE 1
34 #define INFO_MODE_ELEMENTS 2
35 #define INFO_MODE_MUSIC 3
36 #define INFO_MODE_CREDITS 4
37 #define INFO_MODE_PROGRAM 5
38 #define INFO_MODE_VERSION 6
39 #define INFO_MODE_LEVELSET 7
41 #define MAX_INFO_MODES 8
43 // screens on the setup screen
44 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
45 // (should also match corresponding entries in src/conf_gfx.c)
46 #define SETUP_MODE_MAIN 0
47 #define SETUP_MODE_GAME 1
48 #define SETUP_MODE_ENGINES 2
49 #define SETUP_MODE_EDITOR 3
50 #define SETUP_MODE_GRAPHICS 4
51 #define SETUP_MODE_SOUND 5
52 #define SETUP_MODE_ARTWORK 6
53 #define SETUP_MODE_INPUT 7
54 #define SETUP_MODE_TOUCH 8
55 #define SETUP_MODE_SHORTCUTS 9
56 #define SETUP_MODE_SHORTCUTS_1 10
57 #define SETUP_MODE_SHORTCUTS_2 11
58 #define SETUP_MODE_SHORTCUTS_3 12
59 #define SETUP_MODE_SHORTCUTS_4 13
60 #define SETUP_MODE_SHORTCUTS_5 14
62 // sub-screens on the setup screen (generic)
63 #define SETUP_MODE_CHOOSE_ARTWORK 15
64 #define SETUP_MODE_CHOOSE_OTHER 16
66 // sub-screens on the setup screen (specific)
67 #define SETUP_MODE_CHOOSE_SCORES_TYPE 17
68 #define SETUP_MODE_CHOOSE_GAME_SPEED 18
69 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 19
70 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 20
71 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 21
72 #define SETUP_MODE_CHOOSE_SCALING_TYPE 22
73 #define SETUP_MODE_CHOOSE_RENDERING 23
74 #define SETUP_MODE_CHOOSE_VSYNC 24
75 #define SETUP_MODE_CHOOSE_GRAPHICS 25
76 #define SETUP_MODE_CHOOSE_SOUNDS 26
77 #define SETUP_MODE_CHOOSE_MUSIC 27
78 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 28
79 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 29
80 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 30
81 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 31
82 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 32
83 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 33
84 #define SETUP_MODE_CHOOSE_TRANSPARENCY 34
85 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 35
86 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 36
87 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 37
88 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 38
89 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 39
91 #define MAX_SETUP_MODES 40
93 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
95 // setup screen titles
96 #define STR_SETUP_MAIN "Setup"
97 #define STR_SETUP_GAME "Game & Menu"
98 #define STR_SETUP_ENGINES "Game Engines"
99 #define STR_SETUP_EDITOR "Editor"
100 #define STR_SETUP_GRAPHICS "Graphics"
101 #define STR_SETUP_SOUND "Sound & Music"
102 #define STR_SETUP_ARTWORK "Custom Artwork"
103 #define STR_SETUP_INPUT "Input Devices"
104 #define STR_SETUP_TOUCH "Touch Controls"
105 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
106 #define STR_SETUP_EXIT "Exit"
107 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
109 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
110 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
111 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
112 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
113 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
114 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
115 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
116 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
117 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
118 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
119 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
120 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
121 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
122 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
123 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
124 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
125 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
126 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
127 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
129 // other screen text constants
130 #define STR_CHOOSE_TREE_EDIT "Edit"
131 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
132 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
134 #define TEXT_NEXT_PAGE "Press any key or button for next page"
135 #define TEXT_INFO_MENU "Press any key or button for info menu"
137 // for input setup functions
138 #define SETUPINPUT_SCREEN_POS_START 0
139 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
140 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
141 #define SETUPINPUT_SCREEN_POS_END 13
143 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
144 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
146 #define MAX_SETUP_TEXT_INPUT_LEN 28
148 // for various menu stuff
149 #define MENU_SCREEN_START_XPOS 1
150 #define MENU_SCREEN_START_YPOS 2
151 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
152 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
153 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
154 #define MENU_TITLE1_YPOS 8
155 #define MENU_TITLE2_YPOS 46
156 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
157 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
158 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
159 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
160 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
161 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
162 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
163 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
164 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
165 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
166 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
167 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
168 MENU_INFO_FONT_TITLE))
169 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
170 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
171 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
172 MENU_SCREEN_INFO_YSTART2 - \
174 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
175 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
176 MENU_SCREEN_INFO_YSTEP)
177 #define NUM_INFO_ELEMENTS_FROM_CONF \
178 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
179 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
180 MAX_MENU_ENTRIES_ON_SCREEN)
181 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
182 MAX_INFO_ELEMENTS_ON_SCREEN), \
183 NUM_INFO_ELEMENTS_FROM_CONF)
184 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
185 #define MAX_MENU_TEXT_LENGTH_BIG 13
186 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
188 // screen gadget identifiers
189 #define SCREEN_CTRL_ID_PREV_LEVEL 0
190 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
191 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
192 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
193 #define SCREEN_CTRL_ID_PREV_SCORE 4
194 #define SCREEN_CTRL_ID_NEXT_SCORE 5
195 #define SCREEN_CTRL_ID_PLAY_TAPE 6
196 #define SCREEN_CTRL_ID_FIRST_LEVEL 7
197 #define SCREEN_CTRL_ID_LAST_LEVEL 8
198 #define SCREEN_CTRL_ID_LEVEL_NUMBER 9
199 #define SCREEN_CTRL_ID_PREV_PLAYER 10
200 #define SCREEN_CTRL_ID_NEXT_PLAYER 11
201 #define SCREEN_CTRL_ID_INSERT_SOLUTION 12
202 #define SCREEN_CTRL_ID_PLAY_SOLUTION 13
203 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 14
204 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 15
205 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 16
206 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 17
207 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 18
209 #define NUM_SCREEN_MENUBUTTONS 19
211 #define SCREEN_CTRL_ID_SCROLL_UP 19
212 #define SCREEN_CTRL_ID_SCROLL_DOWN 20
213 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 21
214 #define SCREEN_CTRL_ID_NETWORK_SERVER 22
216 #define NUM_SCREEN_GADGETS 23
218 #define NUM_SCREEN_SCROLLBUTTONS 2
219 #define NUM_SCREEN_SCROLLBARS 1
220 #define NUM_SCREEN_TEXTINPUT 1
222 #define SCREEN_MASK_MAIN (1 << 0)
223 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
224 #define SCREEN_MASK_INPUT (1 << 2)
225 #define SCREEN_MASK_TOUCH (1 << 3)
226 #define SCREEN_MASK_TOUCH2 (1 << 4)
227 #define SCREEN_MASK_SCORES (1 << 5)
228 #define SCREEN_MASK_SCORES_INFO (1 << 6)
230 // graphic position and size values for buttons and scrollbars
231 #define SC_MENUBUTTON_XSIZE TILEX
232 #define SC_MENUBUTTON_YSIZE TILEY
234 #define SC_SCROLLBUTTON_XSIZE TILEX
235 #define SC_SCROLLBUTTON_YSIZE TILEY
237 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
239 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
240 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
241 SC_SCROLLBUTTON_YSIZE)
243 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
244 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
246 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
247 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
248 SC_SCROLLBUTTON_YSIZE)
250 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
251 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
252 SC_SCROLL_VERTICAL_YSIZE)
254 #define SC_BORDER_SIZE 14
257 // forward declarations of internal functions
258 static void HandleScreenGadgets(struct GadgetInfo *);
259 static void HandleSetupScreen_Generic(int, int, int, int, int);
260 static void HandleSetupScreen_Input(int, int, int, int, int);
261 static void CustomizeKeyboard(int);
262 static void ConfigureJoystick(int);
263 static void ConfigureVirtualButtons(void);
264 static void execSetupGame(void);
265 static void execSetupEngines(void);
266 static void execSetupGraphics(void);
267 static void execSetupSound(void);
268 static void execSetupTouch(void);
269 static void execSetupArtwork(void);
270 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
272 static void DrawChoosePlayerName(void);
273 static void DrawChooseLevelSet(void);
274 static void DrawChooseLevelNr(void);
275 static void DrawScoreInfo(int);
276 static void DrawScoreInfo_Content(int);
277 static void DrawInfoScreen(void);
278 static void DrawSetupScreen(void);
279 static void DrawTypeName(void);
281 static void DrawInfoScreen_NotAvailable(char *, char *);
282 static void DrawInfoScreen_HelpAnim(int, int, boolean);
283 static void DrawInfoScreen_HelpText(int, int, int, int);
284 static void HandleInfoScreen_Main(int, int, int, int, int);
285 static void HandleInfoScreen_TitleScreen(int, int, int);
286 static void HandleInfoScreen_Elements(int, int, int);
287 static void HandleInfoScreen_Music(int, int, int);
288 static void HandleInfoScreen_Credits(int, int, int);
289 static void HandleInfoScreen_Program(int, int, int);
290 static void HandleInfoScreen_Version(int);
292 static void ModifyGameSpeedIfNeeded(void);
293 static void DisableVsyncIfNeeded(void);
295 static void RedrawScreenMenuGadgets(int);
296 static void MapScreenMenuGadgets(int);
297 static void UnmapScreenMenuGadgets(int);
298 static void MapScreenGadgets(int);
299 static void UnmapScreenGadgets(void);
300 static void MapScreenTreeGadgets(TreeInfo *);
301 static void UnmapScreenTreeGadgets(void);
303 static void UpdateScreenMenuGadgets(int, boolean);
304 static void AdjustScoreInfoButtons_SelectScore(int, int, int);
305 static void AdjustScoreInfoButtons_PlayTape(int, int, boolean);
307 static boolean OfferUploadTapes(void);
308 static void execOfferUploadTapes(void);
310 static void DrawHallOfFame_setScoreEntries(void);
311 static void HandleHallOfFame_SelectLevel(int, int);
312 static char *getHallOfFameRankText(int, int);
313 static char *getHallOfFameScoreText(int, int);
315 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *);
317 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
319 static int info_mode = INFO_MODE_MAIN;
320 static int setup_mode = SETUP_MODE_MAIN;
322 static TreeInfo *window_sizes = NULL;
323 static TreeInfo *window_size_current = NULL;
325 static TreeInfo *scaling_types = NULL;
326 static TreeInfo *scaling_type_current = NULL;
328 static TreeInfo *rendering_modes = NULL;
329 static TreeInfo *rendering_mode_current = NULL;
331 static TreeInfo *vsync_modes = NULL;
332 static TreeInfo *vsync_mode_current = NULL;
334 static TreeInfo *scroll_delays = NULL;
335 static TreeInfo *scroll_delay_current = NULL;
337 static TreeInfo *snapshot_modes = NULL;
338 static TreeInfo *snapshot_mode_current = NULL;
340 static TreeInfo *scores_types = NULL;
341 static TreeInfo *scores_type_current = NULL;
343 static TreeInfo *game_speeds_normal = NULL;
344 static TreeInfo *game_speeds_extended = NULL;
345 static TreeInfo *game_speeds = NULL;
346 static TreeInfo *game_speed_current = NULL;
348 static TreeInfo *volumes_simple = NULL;
349 static TreeInfo *volume_simple_current = NULL;
351 static TreeInfo *volumes_loops = NULL;
352 static TreeInfo *volume_loops_current = NULL;
354 static TreeInfo *volumes_music = NULL;
355 static TreeInfo *volume_music_current = NULL;
357 static TreeInfo *touch_controls = NULL;
358 static TreeInfo *touch_control_current = NULL;
360 static TreeInfo *move_distances = NULL;
361 static TreeInfo *move_distance_current = NULL;
363 static TreeInfo *drop_distances = NULL;
364 static TreeInfo *drop_distance_current = NULL;
366 static TreeInfo *transparencies = NULL;
367 static TreeInfo *transparency_current = NULL;
369 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
370 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
372 static TreeInfo *player_name = NULL;
373 static TreeInfo *player_name_current = NULL;
375 static TreeInfo *level_number = NULL;
376 static TreeInfo *level_number_current = NULL;
378 static TreeInfo *score_entries = NULL;
379 static TreeInfo *score_entry_current = NULL;
381 static struct ValueTextInfo window_sizes_list[] =
386 { 100, "100 % (Default)" },
399 static struct StringValueTextInfo scaling_types_list[] =
401 { SCALING_QUALITY_NEAREST, "Off" },
402 { SCALING_QUALITY_LINEAR, "Linear" },
403 { SCALING_QUALITY_BEST, "Anisotropic" },
408 static struct StringValueTextInfo rendering_modes_list[] =
410 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
411 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
413 // this mode may work under certain conditions, but does not work on Windows
414 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
416 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
421 static struct StringValueTextInfo vsync_modes_list[] =
423 { STR_VSYNC_MODE_OFF, "Off" },
424 { STR_VSYNC_MODE_NORMAL, "Normal" },
425 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
430 static struct StringValueTextInfo scores_types_list[] =
432 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
433 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
434 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
439 static struct ValueTextInfo game_speeds_list_normal[] =
450 static struct ValueTextInfo game_speeds_list_extended[] =
452 { 1000, "1 fps (Extremely Slow)" },
457 { 29, "35 fps (Original Supaplex)" },
459 { 20, "50 fps (=== Normal Speed ===)" },
460 { 16, "60 fps (60 Hz VSync Speed)" },
461 { 14, "70 fps (Maximum Supaplex)" },
465 { 1, "1000 fps (Extremely Fast)" },
470 static struct ValueTextInfo *game_speeds_list;
472 static struct ValueTextInfo scroll_delays_list[] =
474 { 0, "0 Tiles (No Scroll Delay)" },
477 { 3, "3 Tiles (Default)" },
482 { 8, "8 Tiles (Maximum Scroll Delay)"},
487 static struct StringValueTextInfo snapshot_modes_list[] =
489 { STR_SNAPSHOT_MODE_OFF, "Off" },
490 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
491 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
492 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
497 static struct ValueTextInfo volumes_list[] =
517 static struct StringValueTextInfo touch_controls_list[] =
519 { TOUCH_CONTROL_OFF, "Off" },
520 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
521 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
522 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
527 static struct ValueTextInfo distances_list[] =
542 static struct ValueTextInfo transparencies_list[] =
544 { 0, "0 % (Opaque)" },
554 { 100, "100 % (Invisible)" },
559 static struct ValueTextInfo grid_sizes_list[] =
595 static int align_xoffset = 0;
596 static int align_yoffset = 0;
598 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
599 (s) <= GAME_MODE_SETUP ? (s) : \
600 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
602 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
603 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
605 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
606 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
607 (i) <= INFO_MODE_LEVELSET ? (i) : \
610 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
611 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
612 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
613 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
614 SETUP_MODE_CHOOSE_ARTWORK : \
615 SETUP_MODE_CHOOSE_OTHER)
617 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
618 menu.draw_xoffset[GAME_MODE_INFO] : \
619 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
620 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
621 menu.draw_yoffset[GAME_MODE_INFO] : \
622 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
623 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
624 menu.extra_spacing[GAME_MODE_INFO] : \
625 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
627 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
628 menu.draw_xoffset[GAME_MODE_SETUP] : \
629 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
630 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
631 menu.draw_yoffset[GAME_MODE_SETUP] : \
632 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
633 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
634 menu.extra_spacing[GAME_MODE_SETUP] : \
635 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
637 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
639 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
641 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
642 DRAW_XOFFSET_INFO(info_mode) : \
643 (s) == GAME_MODE_SETUP ? \
644 DRAW_XOFFSET_SETUP(setup_mode) : \
645 menu.draw_xoffset[DRAW_MODE(s)])
646 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
647 DRAW_YOFFSET_INFO(info_mode) : \
648 (s) == GAME_MODE_SETUP ? \
649 DRAW_YOFFSET_SETUP(setup_mode) : \
650 menu.draw_yoffset[DRAW_MODE(s)])
651 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
652 EXTRA_SPACING_INFO(info_mode) : \
653 (s) == GAME_MODE_SETUP ? \
654 EXTRA_SPACING_SETUP(setup_mode) : \
655 (s) == GAME_MODE_SCORES ? \
656 EXTRA_SPACING_SCORES(info_mode) : \
657 menu.extra_spacing[DRAW_MODE(s)])
659 #define mSX (SX + DRAW_XOFFSET(game_status))
660 #define mSY (SY + DRAW_YOFFSET(game_status))
662 #define amSX (mSX + align_xoffset)
663 #define amSY (mSY + align_yoffset)
665 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
666 menu.list_size[game_status] : \
667 MAX_MENU_ENTRIES_ON_SCREEN)
669 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
670 NUM_MENU_ENTRIES_ON_SCREEN)
673 // title display and control definitions
675 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
676 2 * MAX_NUM_TITLE_MESSAGES)
678 #define NO_DIRECT_LEVEL_SELECT (-1)
681 static int num_title_screens = 0;
683 struct TitleControlInfo
692 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
695 // credits screens definitions
697 static int num_credits_screens = 0;
698 static boolean use_global_credits_screens = FALSE;
701 // program info screens definitions
703 static int num_program_info_screens = 0;
706 // main menu display and control definitions
708 #define MAIN_CONTROL_NAME 0
709 #define MAIN_CONTROL_LEVELS 1
710 #define MAIN_CONTROL_SCORES 2
711 #define MAIN_CONTROL_EDITOR 3
712 #define MAIN_CONTROL_INFO 4
713 #define MAIN_CONTROL_GAME 5
714 #define MAIN_CONTROL_SETUP 6
715 #define MAIN_CONTROL_QUIT 7
716 #define MAIN_CONTROL_PREV_LEVEL 8
717 #define MAIN_CONTROL_NEXT_LEVEL 9
718 #define MAIN_CONTROL_FIRST_LEVEL 10
719 #define MAIN_CONTROL_LAST_LEVEL 11
720 #define MAIN_CONTROL_LEVEL_NUMBER 12
721 #define MAIN_CONTROL_LEVEL_INFO_1 13
722 #define MAIN_CONTROL_LEVEL_INFO_2 14
723 #define MAIN_CONTROL_LEVEL_NAME 15
724 #define MAIN_CONTROL_LEVEL_AUTHOR 16
725 #define MAIN_CONTROL_LEVEL_YEAR 17
726 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
727 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
728 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
729 #define MAIN_CONTROL_TITLE_1 21
730 #define MAIN_CONTROL_TITLE_2 22
731 #define MAIN_CONTROL_TITLE_3 23
733 static char str_main_text_name[10];
734 static char str_main_text_first_level[10];
735 static char str_main_text_last_level[10];
736 static char str_main_text_level_number[10];
738 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
740 static char *main_text_name = str_main_text_name;
741 static char *main_text_first_level = str_main_text_first_level;
742 static char *main_text_last_level = str_main_text_last_level;
743 static char *main_text_level_number = str_main_text_level_number;
744 static char *main_text_levels = "Levelset";
745 static char *main_text_scores = "Hall Of Fame";
746 static char *main_text_editor = "Level Creator";
747 static char *main_text_info = "Info Screen";
748 static char *main_text_game = "Start Game";
749 static char *main_text_setup = "Setup";
750 static char *main_text_quit = "Quit";
751 static char *main_text_level_name = level.name;
752 static char *main_text_level_author = level.author;
753 static char *main_text_level_year = NULL;
754 static char *main_text_level_imported_from = NULL;
755 static char *main_text_level_imported_by = NULL;
756 static char *main_text_level_tested_by = NULL;
757 static char *main_text_title_1 = NULL;
758 static char *main_text_title_2 = NULL;
759 static char *main_text_title_3 = NULL;
761 extern char debug_xsn_mode[];
763 struct MainControlInfo
767 struct MenuPosInfo *pos_button;
770 struct TextPosInfo *pos_text;
773 struct TextPosInfo *pos_input;
777 static struct MainControlInfo main_controls[] =
781 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
782 &menu.main.text.name, &main_text_name,
783 &menu.main.input.name, &setup.player_name,
787 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
788 &menu.main.text.levels, &main_text_levels,
793 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
794 &menu.main.text.scores, &main_text_scores,
799 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
800 &menu.main.text.editor, &main_text_editor,
805 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
806 &menu.main.text.info, &main_text_info,
811 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
812 &menu.main.text.game, &main_text_game,
817 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
818 &menu.main.text.setup, &main_text_setup,
823 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
824 &menu.main.text.quit, &main_text_quit,
828 MAIN_CONTROL_PREV_LEVEL,
834 MAIN_CONTROL_NEXT_LEVEL,
840 MAIN_CONTROL_FIRST_LEVEL,
842 &menu.main.text.first_level, &main_text_first_level,
846 MAIN_CONTROL_LAST_LEVEL,
848 &menu.main.text.last_level, &main_text_last_level,
852 MAIN_CONTROL_LEVEL_NUMBER,
854 &menu.main.text.level_number, &main_text_level_number,
858 MAIN_CONTROL_LEVEL_INFO_1,
860 &menu.main.text.level_info_1, NULL,
864 MAIN_CONTROL_LEVEL_INFO_2,
866 &menu.main.text.level_info_2, NULL,
870 MAIN_CONTROL_LEVEL_NAME,
872 &menu.main.text.level_name, &main_text_level_name,
876 MAIN_CONTROL_LEVEL_AUTHOR,
878 &menu.main.text.level_author, &main_text_level_author,
882 MAIN_CONTROL_LEVEL_YEAR,
884 &menu.main.text.level_year, &main_text_level_year,
888 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
890 &menu.main.text.level_imported_from, &main_text_level_imported_from,
894 MAIN_CONTROL_LEVEL_IMPORTED_BY,
896 &menu.main.text.level_imported_by, &main_text_level_imported_by,
900 MAIN_CONTROL_LEVEL_TESTED_BY,
902 &menu.main.text.level_tested_by, &main_text_level_tested_by,
906 MAIN_CONTROL_TITLE_1,
908 &menu.main.text.title_1, &main_text_title_1,
912 MAIN_CONTROL_TITLE_2,
914 &menu.main.text.title_2, &main_text_title_2,
918 MAIN_CONTROL_TITLE_3,
920 &menu.main.text.title_3, &main_text_title_3,
933 static int getTitleScreenGraphic(int nr, boolean initial)
935 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
938 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
940 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
944 static int getTitleScreenGameMode(boolean initial)
946 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
950 static int getTitleMessageGameMode(boolean initial)
952 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
955 static int getTitleAnimMode(struct TitleControlInfo *tci)
957 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
959 return base + tci->local_nr;
963 static int getTitleScreenBackground(boolean initial)
965 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
970 static int getTitleMessageBackground(int nr, boolean initial)
972 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
976 static int getTitleBackground(int nr, boolean initial, boolean is_image)
978 int base = (is_image ?
979 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
980 IMG_BACKGROUND_TITLESCREEN_1) :
981 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
982 IMG_BACKGROUND_TITLEMESSAGE_1));
983 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
984 IMG_BACKGROUND_TITLE);
985 int graphic_local = base + nr;
987 if (graphic_info[graphic_local].bitmap != NULL)
988 return graphic_local;
990 if (graphic_info[graphic_global].bitmap != NULL)
991 return graphic_global;
993 return IMG_UNDEFINED;
996 static int getTitleSound(struct TitleControlInfo *tci)
998 boolean is_image = tci->is_image;
999 int initial = tci->initial;
1000 int nr = tci->local_nr;
1001 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1002 int base = (is_image ?
1003 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
1004 SND_BACKGROUND_TITLESCREEN_1) :
1005 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1006 SND_BACKGROUND_TITLEMESSAGE_1));
1007 int sound_global = menu.sound[mode];
1008 int sound_local = base + nr;
1011 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
1012 nr, initial, is_image,
1013 sound_global, getSoundListEntry(sound_global)->filename,
1014 sound_local, getSoundListEntry(sound_local)->filename);
1017 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1020 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1021 return sound_global;
1023 return SND_UNDEFINED;
1026 static int getTitleMusic(struct TitleControlInfo *tci)
1028 boolean is_image = tci->is_image;
1029 int initial = tci->initial;
1030 int nr = tci->local_nr;
1031 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1032 int base = (is_image ?
1033 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1034 MUS_BACKGROUND_TITLESCREEN_1) :
1035 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1036 MUS_BACKGROUND_TITLEMESSAGE_1));
1037 int music_global = menu.music[mode];
1038 int music_local = base + nr;
1041 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1042 nr, initial, is_image,
1043 music_global, getMusicListEntry(music_global)->filename,
1044 music_local, getMusicListEntry(music_local)->filename);
1047 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1050 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1051 return music_global;
1053 return MUS_UNDEFINED;
1056 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1058 boolean is_image = tci->is_image;
1059 boolean initial = tci->initial;
1060 boolean first = tci->first;
1061 int nr = tci->local_nr;
1062 struct TitleMessageInfo tmi;
1063 struct TitleFadingInfo ti;
1065 tmi = (is_image ? (initial ? (first ?
1066 titlescreen_initial_first[nr] :
1067 titlescreen_initial[nr])
1069 titlescreen_first[nr] :
1071 : (initial ? (first ?
1072 titlemessage_initial_first[nr] :
1073 titlemessage_initial[nr])
1075 titlemessage_first[nr] :
1076 titlemessage[nr])));
1078 ti.fade_mode = tmi.fade_mode;
1079 ti.fade_delay = tmi.fade_delay;
1080 ti.post_delay = tmi.post_delay;
1081 ti.auto_delay = tmi.auto_delay;
1082 ti.auto_delay_unit = tmi.auto_delay_unit;
1087 static int compareTitleControlInfo(const void *object1, const void *object2)
1089 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1090 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1093 if (tci1->initial != tci2->initial)
1094 compare_result = (tci1->initial ? -1 : +1);
1095 else if (tci1->sort_priority != tci2->sort_priority)
1096 compare_result = tci1->sort_priority - tci2->sort_priority;
1097 else if (tci1->is_image != tci2->is_image)
1098 compare_result = (tci1->is_image ? -1 : +1);
1100 compare_result = tci1->local_nr - tci2->local_nr;
1102 return compare_result;
1105 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1107 int nr, int sort_priority)
1109 title_controls[num_title_screens].is_image = is_image;
1110 title_controls[num_title_screens].initial = initial;
1111 title_controls[num_title_screens].local_nr = nr;
1112 title_controls[num_title_screens].sort_priority = sort_priority;
1114 title_controls[num_title_screens].first = FALSE; // will be set later
1116 num_title_screens++;
1119 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1123 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1125 int graphic = getTitleScreenGraphic(i, initial);
1126 Bitmap *bitmap = graphic_info[graphic].bitmap;
1127 int sort_priority = graphic_info[graphic].sort_priority;
1130 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1133 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1135 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1136 char *filename = getLevelSetTitleMessageFilename(i, initial);
1137 int sort_priority = tmi->sort_priority;
1139 if (filename != NULL)
1140 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1144 static void InitializeTitleControls(boolean show_title_initial)
1146 num_title_screens = 0;
1148 // 1st step: initialize title screens for game start (only when starting)
1149 if (show_title_initial)
1150 InitializeTitleControls_CheckTitleInfo(TRUE);
1152 // 2nd step: initialize title screens for current level set
1153 InitializeTitleControls_CheckTitleInfo(FALSE);
1155 // sort title screens according to sort_priority and title number
1156 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1157 compareTitleControlInfo);
1159 // mark first title screen
1160 title_controls[0].first = TRUE;
1163 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1165 return (pos != NULL && pos->x != -1 && pos->y != -1);
1168 static boolean visibleTextPos(struct TextPosInfo *pos)
1170 return (pos != NULL && pos->x != -1 && pos->y != -1);
1173 static void InitializeMainControls(void)
1175 boolean local_team_mode = (!network.enabled && setup.team_mode);
1178 // set main control text values to dynamically determined values
1179 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1181 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1182 menu.main.text.first_level.size));
1183 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1184 menu.main.text.last_level.size));
1185 strcpy(main_text_level_number, int2str(level_nr,
1186 menu.main.text.level_number.size));
1188 main_text_level_year = leveldir_current->year;
1189 main_text_level_imported_from = leveldir_current->imported_from;
1190 main_text_level_imported_by = leveldir_current->imported_by;
1191 main_text_level_tested_by = leveldir_current->tested_by;
1193 main_text_title_1 = getConfigProgramTitleString();
1194 main_text_title_2 = getConfigProgramCopyrightString();
1195 main_text_title_3 = getConfigProgramCompanyString();
1197 // set main control screen positions to dynamically determined values
1198 for (i = 0; main_controls[i].nr != -1; i++)
1200 struct MainControlInfo *mci = &main_controls[i];
1202 struct MenuPosInfo *pos_button = mci->pos_button;
1203 struct TextPosInfo *pos_text = mci->pos_text;
1204 struct TextPosInfo *pos_input = mci->pos_input;
1205 char *text = (mci->text ? *mci->text : NULL);
1206 char *input = (mci->input ? *mci->input : NULL);
1207 int button_graphic = mci->button_graphic;
1208 int font_text = (pos_text ? pos_text->font : -1);
1209 int font_input = (pos_input ? pos_input->font : -1);
1211 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1212 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1213 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1214 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1215 int text_chars = (text != NULL ? strlen(text) : 0);
1216 int input_chars = (input != NULL ? strlen(input) : 0);
1219 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1221 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1222 int text_width = font_text_width * text_chars;
1223 int text_height = font_text_height;
1224 int input_width = font_input_width * input_chars;
1225 int input_height = font_input_height;
1227 if (nr == MAIN_CONTROL_NAME)
1229 menu.main.input.name.width = input_width;
1230 menu.main.input.name.height = input_height;
1233 if (pos_button != NULL) // (x/y may be -1/-1 here)
1235 pos_button->width = button_width;
1236 pos_button->height = button_height;
1239 if (pos_text != NULL) // (x/y may be -1/-1 here)
1241 // calculate text size -- needed for text alignment
1242 boolean calculate_text_size = (text != NULL);
1244 if (pos_text->width == -1 || calculate_text_size)
1245 pos_text->width = text_width;
1246 if (pos_text->height == -1 || calculate_text_size)
1247 pos_text->height = text_height;
1249 if (visibleMenuPos(pos_button))
1251 if (pos_text->x == -1)
1252 pos_text->x = pos_button->x + pos_button->width;
1253 if (pos_text->y == -1)
1255 pos_button->y + (pos_button->height - pos_text->height) / 2;
1259 if (pos_input != NULL) // (x/y may be -1/-1 here)
1261 if (visibleTextPos(pos_text))
1263 if (pos_input->x == -1)
1264 pos_input->x = pos_text->x + pos_text->width;
1265 if (pos_input->y == -1)
1266 pos_input->y = pos_text->y;
1269 if (pos_input->width == -1)
1270 pos_input->width = input_width;
1271 if (pos_input->height == -1)
1272 pos_input->height = input_height;
1277 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1278 int graphic, boolean pressed)
1280 struct GraphicInfo *g = &graphic_info[graphic];
1283 int xoffset = (pressed ? g->pressed_xoffset : 0);
1284 int yoffset = (pressed ? g->pressed_yoffset : 0);
1286 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1288 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1289 g->width, g->height, dst_x, dst_y);
1292 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1293 boolean active_input,
1294 boolean pressed_button)
1298 for (i = 0; main_controls[i].nr != -1; i++)
1300 struct MainControlInfo *mci = &main_controls[i];
1302 if (mci->nr == nr || nr == -1)
1304 struct MenuPosInfo *pos_button = mci->pos_button;
1305 struct TextPosInfo *pos_text = mci->pos_text;
1306 struct TextPosInfo *pos_input = mci->pos_input;
1307 char *text = (mci->text ? *mci->text : NULL);
1308 char *input = (mci->input ? *mci->input : NULL);
1309 int button_graphic = mci->button_graphic;
1310 int font_text = (pos_text ? pos_text->font : -1);
1311 int font_input = (pos_input ? pos_input->font : -1);
1315 button_graphic = BUTTON_ACTIVE(button_graphic);
1316 font_text = FONT_ACTIVE(font_text);
1321 font_input = FONT_ACTIVE(font_input);
1324 if (visibleMenuPos(pos_button))
1326 struct MenuPosInfo *pos = pos_button;
1327 int x = mSX + pos->x;
1328 int y = mSY + pos->y;
1330 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1331 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1334 if (visibleTextPos(pos_text) && text != NULL)
1336 struct TextPosInfo *pos = pos_text;
1337 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1338 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1341 // (check why/if this is needed)
1342 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1344 DrawText(x, y, text, font_text);
1347 if (visibleTextPos(pos_input) && input != NULL)
1349 struct TextPosInfo *pos = pos_input;
1350 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1351 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1354 // (check why/if this is needed)
1355 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1357 DrawText(x, y, input, font_input);
1363 static void DrawCursorAndText_Main(int nr, boolean active_text,
1364 boolean pressed_button)
1366 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1370 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1371 boolean pressed_button)
1373 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1377 static struct MainControlInfo *getMainControlInfo(int nr)
1381 for (i = 0; main_controls[i].nr != -1; i++)
1382 if (main_controls[i].nr == nr)
1383 return &main_controls[i];
1388 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1393 int rect_x = ALIGNED_TEXT_XPOS(rect);
1394 int rect_y = ALIGNED_TEXT_YPOS(rect);
1396 return (x >= rect_x && x < rect_x + rect->width &&
1397 y >= rect_y && y < rect_y + rect->height);
1400 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1405 int rect_x = ALIGNED_TEXT_XPOS(rect);
1406 int rect_y = ALIGNED_TEXT_YPOS(rect);
1409 Debug("screens:insideTextPosRect",
1410 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1411 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1412 (x >= rect_x && x < rect_x + rect->width &&
1413 y >= rect_y && y < rect_y + rect->height));
1416 return (x >= rect_x && x < rect_x + rect->width &&
1417 y >= rect_y && y < rect_y + rect->height);
1420 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1422 int rect_width = preview->xsize * preview->tile_size;
1423 int rect_height = preview->ysize * preview->tile_size;
1424 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1425 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1427 return (x >= rect_x && x < rect_x + rect_width &&
1428 y >= rect_y && y < rect_y + rect_height);
1431 static void AdjustScrollbar(int id, int items_max, int items_visible,
1434 struct GadgetInfo *gi = screen_gadget[id];
1436 if (item_position > items_max - items_visible)
1437 item_position = items_max - items_visible;
1439 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1440 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1441 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1444 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1446 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1450 static void clearMenuListArea(void)
1452 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1454 // correct scrollbar position if placed outside menu (playfield) area
1455 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1456 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1458 // clear menu list area, but not title or scrollbar
1459 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1460 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1462 // special compatibility handling for "Snake Bite" graphics set
1463 if (strPrefix(leveldir_current->identifier, "snake_bite"))
1464 ClearRectangle(drawto, mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1465 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1468 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1470 static int cursor_array[MAX_LEV_FIELDY];
1471 int x = amSX + TILEX * xpos;
1472 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1477 cursor_array[ypos] = graphic;
1479 graphic = cursor_array[ypos];
1483 graphic = BUTTON_ACTIVE(graphic);
1485 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1486 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1489 static void initCursor(int ypos, int graphic)
1491 drawCursorExt(0, ypos, FALSE, graphic);
1494 static void drawCursor(int ypos, boolean active)
1496 drawCursorExt(0, ypos, active, -1);
1499 static void drawCursorXY(int xpos, int ypos, int graphic)
1501 drawCursorExt(xpos, ypos, FALSE, graphic);
1504 static void drawChooseTreeCursor(int ypos, boolean active)
1506 drawCursorExt(0, ypos, active, -1);
1509 static int getChooseTreeEditFont(boolean active)
1511 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1514 static int getChooseTreeEditXPos(int pos)
1516 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1517 int xoffset = (has_scrollbar ? -1 : 0);
1518 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1519 int sx = amSX + xpos * TILEX;
1520 int font_nr = getChooseTreeEditFont(FALSE);
1521 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1523 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1526 static int getChooseTreeEditYPos(int ypos_raw)
1528 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1529 int sy = amSY + ypos * TILEY;
1534 static int getChooseTreeEditXPosReal(int pos)
1536 int xpos = getChooseTreeEditXPos(pos);
1537 int font_nr = getChooseTreeEditFont(FALSE);
1538 int font_xoffset = getFontDrawOffsetX(font_nr);
1540 return xpos + font_xoffset;
1543 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1545 int sx = getChooseTreeEditXPos(POS_LEFT);
1546 int sy = getChooseTreeEditYPos(ypos_raw);
1547 int font_nr = getChooseTreeEditFont(active);
1549 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1552 static void DrawHeadline(void)
1554 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1555 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1558 static void DrawTitleScreenImage(int nr, boolean initial)
1560 int graphic = getTitleScreenGraphic(nr, initial);
1561 Bitmap *bitmap = graphic_info[graphic].bitmap;
1562 int width = graphic_info[graphic].width;
1563 int height = graphic_info[graphic].height;
1564 int src_x = graphic_info[graphic].src_x;
1565 int src_y = graphic_info[graphic].src_y;
1571 if (width > WIN_XSIZE)
1573 // image width too large for window => center image horizontally
1574 src_x = (width - WIN_XSIZE) / 2;
1578 if (height > WIN_YSIZE)
1580 // image height too large for window => center image vertically
1581 src_y = (height - WIN_YSIZE) / 2;
1585 // always display title screens centered
1586 dst_x = (WIN_XSIZE - width) / 2;
1587 dst_y = (WIN_YSIZE - height) / 2;
1589 SetDrawBackgroundMask(REDRAW_ALL);
1590 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1592 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1594 if (DrawingOnBackground(dst_x, dst_y))
1595 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1597 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1599 redraw_mask = REDRAW_ALL;
1602 static void DrawTitleScreenMessage(int nr, boolean initial)
1604 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1605 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1607 if (filename == NULL)
1610 // force TITLE font on title message screen
1611 SetFontStatus(getTitleMessageGameMode(initial));
1613 // if chars *and* width set to "-1", automatically determine width
1614 if (tmi->chars == -1 && tmi->width == -1)
1615 tmi->width = viewport.window[game_status].width;
1617 // if lines *and* height set to "-1", automatically determine height
1618 if (tmi->lines == -1 && tmi->height == -1)
1619 tmi->height = viewport.window[game_status].height;
1621 // if chars set to "-1", automatically determine by text and font width
1622 if (tmi->chars == -1)
1623 tmi->chars = tmi->width / getFontWidth(tmi->font);
1625 tmi->width = tmi->chars * getFontWidth(tmi->font);
1627 // if lines set to "-1", automatically determine by text and font height
1628 if (tmi->lines == -1)
1629 tmi->lines = tmi->height / getFontHeight(tmi->font);
1631 tmi->height = tmi->lines * getFontHeight(tmi->font);
1633 // if x set to "-1", automatically determine by width and alignment
1635 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1637 // if y set to "-1", automatically determine by height and alignment
1639 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1641 SetDrawBackgroundMask(REDRAW_ALL);
1642 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1644 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1646 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1647 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1648 tmi->autowrap, tmi->centered, tmi->parse_comments);
1653 static void DrawTitleScreen(void)
1655 KeyboardAutoRepeatOff();
1657 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1660 static boolean CheckTitleScreen(boolean levelset_has_changed)
1662 static boolean show_title_initial = TRUE;
1663 boolean show_titlescreen = FALSE;
1665 // needed to be able to skip title screen, if no image or message defined
1666 InitializeTitleControls(show_title_initial);
1668 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1669 show_titlescreen = TRUE;
1671 // show initial title images and messages only once at program start
1672 show_title_initial = FALSE;
1674 return (show_titlescreen && num_title_screens > 0);
1677 void DrawMainMenu(void)
1679 static LevelDirTree *leveldir_last_valid = NULL;
1680 boolean levelset_has_changed = FALSE;
1681 int fade_mask = REDRAW_FIELD;
1683 LimitScreenUpdates(FALSE);
1685 FadeSetLeaveScreen();
1687 // do not fade out here -- function may continue and fade on editor screen
1690 FadeMenuSoundsAndMusic();
1692 ExpireSoundLoops(FALSE);
1694 KeyboardAutoRepeatOn();
1696 audio.sound_deactivated = FALSE;
1700 // needed if last screen was the playing screen, invoked from level editor
1701 if (level_editor_test_game)
1703 CloseDoor(DOOR_CLOSE_ALL);
1705 SetGameStatus(GAME_MODE_EDITOR);
1712 // needed if last screen was the playing screen, invoked from hall of fame
1713 if (score_info_tape_play)
1715 CloseDoor(DOOR_CLOSE_ALL);
1717 SetGameStatus(GAME_MODE_SCOREINFO);
1719 DrawScoreInfo(scores.last_entry_nr);
1724 // leveldir_current may be invalid (level group, parent link, node copy)
1725 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1727 if (leveldir_current != leveldir_last_valid)
1729 UpdateLastPlayedLevels_TreeInfo();
1731 levelset_has_changed = TRUE;
1734 // store valid level series information
1735 leveldir_last_valid = leveldir_current;
1737 // needed if last screen (level choice) changed graphics, sounds or music
1738 ReloadCustomArtwork(0);
1740 if (CheckTitleScreen(levelset_has_changed))
1742 SetGameStatus(GAME_MODE_TITLE);
1749 if (redraw_mask & REDRAW_ALL)
1750 fade_mask = REDRAW_ALL;
1753 fade_mask = REDRAW_ALL;
1757 // needed if different viewport properties defined for menues
1758 ChangeViewportPropertiesIfNeeded();
1760 SetDrawtoField(DRAW_TO_BACKBUFFER);
1762 // level_nr may have been set to value over handicap with level editor
1763 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1764 level_nr = leveldir_current->handicap_level;
1766 LoadLevel(level_nr);
1767 LoadScore(level_nr);
1769 SaveLevelSetup_SeriesInfo();
1771 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1772 SetDrawDeactivationMask(REDRAW_NONE);
1773 SetDrawBackgroundMask(REDRAW_FIELD);
1775 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1778 if (fade_mask == REDRAW_ALL)
1779 RedrawGlobalBorder();
1784 InitializeMainControls();
1786 DrawCursorAndText_Main(-1, FALSE, FALSE);
1787 DrawPreviewLevelInitial();
1788 DrawNetworkPlayers();
1790 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1793 if (TAPE_IS_EMPTY(tape))
1795 DrawCompleteVideoDisplay();
1797 PlayMenuSoundsAndMusic();
1799 // create gadgets for main menu screen
1800 FreeScreenGadgets();
1801 CreateScreenGadgets();
1803 // may be required if audio buttons shown on tape and changed in setup menu
1805 CreateGameButtons();
1807 // map gadgets for main menu screen
1809 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1810 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1812 // copy actual game door content to door double buffer for OpenDoor()
1813 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1814 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1816 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1818 DrawMaskedBorder(fade_mask);
1823 // update screen area with special editor door
1824 redraw_mask |= REDRAW_ALL;
1827 SetMouseCursor(CURSOR_DEFAULT);
1829 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1831 SyncEmscriptenFilesystem();
1833 // needed once after program start or after user change
1834 CheckApiServerTasks();
1837 static void gotoTopLevelDir(void)
1839 // move upwards until inside (but not above) top level directory
1840 while (leveldir_current->node_parent &&
1841 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1843 // write a "path" into level tree for easy navigation to last level
1844 if (leveldir_current->node_parent->node_group->cl_first == -1)
1846 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1847 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1848 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1849 int cl_first, cl_cursor;
1851 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1852 cl_cursor = leveldir_pos - cl_first;
1854 leveldir_current->node_parent->node_group->cl_first = cl_first;
1855 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1858 leveldir_current = leveldir_current->node_parent;
1862 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1864 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1866 return (use_frame_counter ? video.frame_counter : Counter());
1869 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1870 struct TitleFadingInfo *fi)
1872 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1875 static void ResetTitleAutoDelay(unsigned int *counter_var,
1876 struct TitleFadingInfo *fi)
1878 *counter_var = getAutoDelayCounter(fi);
1881 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1883 static unsigned int title_delay = 0;
1884 static int title_screen_nr = 0;
1885 static int last_sound = -1, last_music = -1;
1886 boolean return_to_main_menu = FALSE;
1887 struct TitleControlInfo *tci;
1890 if (button == MB_MENU_INITIALIZE)
1893 title_screen_nr = 0;
1894 tci = &title_controls[title_screen_nr];
1896 SetAnimStatus(getTitleAnimMode(tci));
1898 last_sound = SND_UNDEFINED;
1899 last_music = MUS_UNDEFINED;
1901 if (num_title_screens != 0)
1903 FadeSetEnterScreen();
1905 // use individual title fading instead of global "enter screen" fading
1906 fading = getTitleFading(tci);
1909 if (game_status_last_screen == GAME_MODE_INFO)
1911 if (num_title_screens == 0)
1913 // switch game mode from title screen mode back to info screen mode
1914 SetGameStatus(GAME_MODE_INFO);
1916 // store that last screen was info screen, not main menu screen
1917 game_status_last_screen = GAME_MODE_INFO;
1919 DrawInfoScreen_NotAvailable("Title screen information:",
1920 "No title screen for this level set.");
1925 FadeMenuSoundsAndMusic();
1927 FadeOut(REDRAW_ALL);
1929 // title screens may have different window size
1930 ChangeViewportPropertiesIfNeeded();
1932 // only required to update logic for redrawing global border
1936 DrawTitleScreenImage(tci->local_nr, tci->initial);
1938 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1940 sound = getTitleSound(tci);
1941 music = getTitleMusic(tci);
1943 if (sound != last_sound)
1944 PlayMenuSoundExt(sound);
1945 if (music != last_music)
1946 PlayMenuMusicExt(music);
1951 SetMouseCursor(CURSOR_NONE);
1955 ResetTitleAutoDelay(&title_delay, &fading);
1960 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1961 button = MB_MENU_CHOICE;
1963 if (button == MB_MENU_LEAVE)
1965 return_to_main_menu = TRUE;
1967 else if (button == MB_MENU_CHOICE || dx)
1969 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1971 SetGameStatus(GAME_MODE_INFO);
1973 info_mode = INFO_MODE_MAIN;
1981 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
1983 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
1985 tci = &title_controls[title_screen_nr];
1987 SetAnimStatus(getTitleAnimMode(tci));
1989 sound = getTitleSound(tci);
1990 music = getTitleMusic(tci);
1992 if (last_sound != SND_UNDEFINED && sound != last_sound)
1993 FadeSound(last_sound);
1994 if (last_music != MUS_UNDEFINED && music != last_music)
1997 fading = getTitleFading(tci);
1999 FadeOut(REDRAW_ALL);
2002 DrawTitleScreenImage(tci->local_nr, tci->initial);
2004 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2006 sound = getTitleSound(tci);
2007 music = getTitleMusic(tci);
2009 if (sound != last_sound)
2010 PlayMenuSoundExt(sound);
2011 if (music != last_music)
2012 PlayMenuMusicExt(music);
2019 ResetTitleAutoDelay(&title_delay, &fading);
2023 FadeMenuSoundsAndMusic();
2025 return_to_main_menu = TRUE;
2029 if (return_to_main_menu)
2031 SetMouseCursor(CURSOR_DEFAULT);
2033 // force full menu screen redraw after displaying title screens
2034 redraw_mask = REDRAW_ALL;
2036 if (game_status_last_screen == GAME_MODE_INFO)
2038 SetGameStatus(GAME_MODE_INFO);
2040 info_mode = INFO_MODE_MAIN;
2044 else // default: return to main menu
2046 SetGameStatus(GAME_MODE_MAIN);
2053 static void HandleMainMenu_ToggleTeamMode(void)
2055 setup.team_mode = !setup.team_mode;
2057 InitializeMainControls();
2058 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2060 DrawPreviewPlayers();
2063 static void HandleMainMenu_SelectLevel(int step, int direction,
2064 int selected_level_nr)
2066 int old_level_nr = level_nr;
2069 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2070 new_level_nr = selected_level_nr;
2072 new_level_nr = old_level_nr + step * direction;
2074 if (new_level_nr < leveldir_current->first_level)
2075 new_level_nr = leveldir_current->first_level;
2076 if (new_level_nr > leveldir_current->last_level)
2077 new_level_nr = leveldir_current->last_level;
2079 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2081 // skipping levels is only allowed when trying to skip single level
2082 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2083 Request("Level still unsolved! Skip it anyway?", REQ_ASK))
2085 leveldir_current->handicap_level++;
2086 SaveLevelSetup_SeriesInfo();
2089 new_level_nr = leveldir_current->handicap_level;
2092 if (new_level_nr != old_level_nr)
2094 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2096 PlaySound(SND_MENU_ITEM_SELECTING);
2098 level_nr = new_level_nr;
2100 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2101 int2str(level_nr, menu.main.text.level_number.size),
2102 mci->pos_text->font);
2104 LoadLevel(level_nr);
2105 DrawPreviewLevelInitial();
2109 DrawCompleteVideoDisplay();
2111 SaveLevelSetup_SeriesInfo();
2113 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2115 // force redraw of playfield area (may be reset at this point)
2116 redraw_mask |= REDRAW_FIELD;
2120 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2122 static int choice = MAIN_CONTROL_GAME;
2123 static boolean button_pressed_last = FALSE;
2124 boolean button_pressed = FALSE;
2126 int i = 0; // needed to prevent compiler warning due to bad code below
2128 if (button == MB_MENU_INITIALIZE)
2130 DrawCursorAndText_Main(choice, TRUE, FALSE);
2135 if (mx || my) // mouse input
2139 for (i = 0; main_controls[i].nr != -1; i++)
2141 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2142 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2143 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2145 pos = main_controls[i].nr;
2151 // check if level preview was clicked
2152 if (insidePreviewRect(&preview, mx - SX, my - SY))
2153 pos = MAIN_CONTROL_GAME;
2155 // handle pressed/unpressed state for active/inactive menu buttons
2156 // (if pos != -1, "i" contains index position corresponding to "pos")
2158 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2159 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2160 button_pressed = TRUE;
2162 if (button_pressed != button_pressed_last)
2164 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2167 PlaySound(SND_MENU_BUTTON_PRESSING);
2169 PlaySound(SND_MENU_BUTTON_RELEASING);
2172 else if (dx || dy) // keyboard input
2174 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2175 choice == MAIN_CONTROL_SETUP))
2176 button = MB_MENU_CHOICE;
2181 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2183 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2185 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2187 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2189 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2191 CloseDoor(DOOR_CLOSE_2);
2193 SetGameStatus(GAME_MODE_LEVELNR);
2195 DrawChooseLevelNr();
2197 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2203 PlaySound(SND_MENU_ITEM_ACTIVATING);
2205 DrawCursorAndText_Main(choice, FALSE, FALSE);
2206 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2212 if (choice == MAIN_CONTROL_NAME)
2214 // special case: cursor left or right pressed -- toggle team mode
2215 HandleMainMenu_ToggleTeamMode();
2217 else if (choice != MAIN_CONTROL_INFO &&
2218 choice != MAIN_CONTROL_SETUP)
2220 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2226 PlaySound(SND_MENU_ITEM_SELECTING);
2228 if (pos == MAIN_CONTROL_NAME)
2231 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2233 // special case: menu text "name/team" clicked -- toggle team mode
2234 HandleMainMenu_ToggleTeamMode();
2238 if (setup.multiple_users)
2240 CloseDoor(DOOR_CLOSE_2);
2242 SetGameStatus(GAME_MODE_NAMES);
2244 DrawChoosePlayerName();
2248 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2254 else if (pos == MAIN_CONTROL_LEVELS)
2258 CloseDoor(DOOR_CLOSE_2);
2260 SetGameStatus(GAME_MODE_LEVELS);
2262 SaveLevelSetup_LastSeries();
2263 SaveLevelSetup_SeriesInfo();
2265 // restore level set if chosen from "last played level set" menu
2266 RestoreLastPlayedLevels(&leveldir_current);
2268 if (setup.internal.choose_from_top_leveldir)
2271 DrawChooseLevelSet();
2274 else if (pos == MAIN_CONTROL_SCORES)
2276 CloseDoor(DOOR_CLOSE_2);
2278 SetGameStatus(GAME_MODE_SCORES);
2280 DrawHallOfFame(level_nr);
2282 else if (pos == MAIN_CONTROL_EDITOR)
2284 if (leveldir_current->readonly &&
2285 setup.editor.show_read_only_warning)
2286 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2288 CloseDoor(DOOR_CLOSE_ALL);
2290 SetGameStatus(GAME_MODE_EDITOR);
2292 FadeSetEnterScreen();
2296 else if (pos == MAIN_CONTROL_INFO)
2298 CloseDoor(DOOR_CLOSE_2);
2300 SetGameStatus(GAME_MODE_INFO);
2302 info_mode = INFO_MODE_MAIN;
2306 else if (pos == MAIN_CONTROL_GAME)
2308 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2310 else if (pos == MAIN_CONTROL_SETUP)
2312 CloseDoor(DOOR_CLOSE_2);
2314 SetGameStatus(GAME_MODE_SETUP);
2316 setup_mode = SETUP_MODE_MAIN;
2320 else if (pos == MAIN_CONTROL_QUIT)
2322 SaveLevelSetup_LastSeries();
2323 SaveLevelSetup_SeriesInfo();
2325 #if defined(PLATFORM_EMSCRIPTEN)
2326 Request("Close the browser window to quit!", REQ_CONFIRM);
2328 if (!setup.ask_on_quit_program ||
2329 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2330 SetGameStatus(GAME_MODE_QUIT);
2336 button_pressed_last = button_pressed;
2340 // ============================================================================
2341 // info screen functions
2342 // ============================================================================
2344 static struct TokenInfo *info_info;
2345 static int num_info_info; // number of info entries shown on screen
2346 static int max_info_info; // total number of info entries in list
2348 static void execInfoTitleScreen(void)
2350 info_mode = INFO_MODE_TITLE;
2355 static void execInfoElements(void)
2357 info_mode = INFO_MODE_ELEMENTS;
2362 static void execInfoMusic(void)
2364 info_mode = INFO_MODE_MUSIC;
2369 static void execInfoCredits(void)
2371 info_mode = INFO_MODE_CREDITS;
2376 static void execInfoProgram(void)
2378 info_mode = INFO_MODE_PROGRAM;
2383 static void execInfoVersion(void)
2385 info_mode = INFO_MODE_VERSION;
2390 static void execInfoLevelSet(void)
2392 info_mode = INFO_MODE_LEVELSET;
2397 static void execExitInfo(void)
2399 SetGameStatus(GAME_MODE_MAIN);
2404 static struct TokenInfo info_info_main[] =
2406 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2407 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2408 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2409 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2410 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2411 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2412 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2413 { TYPE_EMPTY, NULL, "" },
2414 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2419 static int getMenuTextFont(int type)
2421 if (type & (TYPE_SWITCH |
2435 static struct TokenInfo *setup_info;
2436 static struct TokenInfo setup_info_input[];
2438 static struct TokenInfo *menu_info;
2440 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2441 int screen_pos, int menu_info_pos_raw,
2444 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2445 struct TokenInfo *ti = &token_info[pos];
2446 int xpos = MENU_SCREEN_START_XPOS;
2447 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2448 int font_nr = getMenuTextFont(ti->type);
2450 if (setup_mode == SETUP_MODE_INPUT)
2451 font_nr = FONT_MENU_1;
2454 font_nr = FONT_ACTIVE(font_nr);
2456 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2458 if (ti->type & ~TYPE_SKIP_ENTRY)
2459 drawCursor(screen_pos, active);
2462 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2465 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2468 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2471 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2474 static char *window_size_text;
2475 static char *scaling_type_text;
2476 static char *network_server_text;
2478 static void drawSetupValue(int, int);
2480 static void drawMenuInfoList(int first_entry, int num_page_entries,
2481 int max_page_entries)
2485 if (first_entry + num_page_entries > max_page_entries)
2488 clearMenuListArea();
2490 for (i = 0; i < num_page_entries; i++)
2492 int menu_info_pos = first_entry + i;
2493 struct TokenInfo *si = &menu_info[menu_info_pos];
2494 void *value_ptr = si->value;
2496 // set some entries to "unchangeable" according to other variables
2497 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2498 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2499 (value_ptr == &setup.sound_music && !audio.music_available) ||
2500 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2501 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2502 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2503 si->type |= TYPE_GHOSTED;
2505 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2506 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2507 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2508 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2509 else if (si->type & ~TYPE_SKIP_ENTRY)
2510 initCursor(i, IMG_MENU_BUTTON);
2512 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2514 if (si->type & TYPE_STRING)
2518 if (value_ptr == &network_server_text)
2519 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2521 if (gadget_id != -1)
2523 struct GadgetInfo *gi = screen_gadget[gadget_id];
2524 int xpos = MENU_SCREEN_START_XPOS;
2525 int ypos = MENU_SCREEN_START_YPOS + i;
2526 int x = mSX + xpos * 32;
2527 int y = mSY + ypos * 32;
2529 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2533 if (si->type & TYPE_VALUE &&
2534 menu_info == setup_info)
2535 drawSetupValue(i, menu_info_pos);
2539 static void DrawInfoScreen_Main(void)
2541 int fade_mask = REDRAW_FIELD;
2544 if (redraw_mask & REDRAW_ALL)
2545 fade_mask = REDRAW_ALL;
2548 fade_mask = REDRAW_ALL;
2551 FadeMenuSoundsAndMusic();
2553 FreeScreenGadgets();
2554 CreateScreenGadgets();
2556 // (needed after displaying title screens which disable auto repeat)
2557 KeyboardAutoRepeatOn();
2559 FadeSetLeaveScreen();
2563 // needed if different viewport properties defined for info screen
2564 ChangeViewportPropertiesIfNeeded();
2566 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2570 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2572 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2574 info_info = info_info_main;
2576 // use modified info screen info without info screen entries marked as hidden
2577 info_info = getSetupInfoFinal(info_info);
2579 // determine maximal number of info entries that can be displayed on screen
2581 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2584 // determine maximal number of info entries available for menu of info screen
2586 for (i = 0; info_info[i].type != 0; i++)
2589 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2591 MapScreenGadgets(max_info_info);
2593 PlayMenuSoundsAndMusic();
2595 DrawMaskedBorder(fade_mask);
2600 static void changeSetupValue(int, int, int);
2602 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2603 int mode, int num_page_entries,
2604 int max_page_entries)
2606 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2607 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2608 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2609 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2610 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2611 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2612 int *num_page_entries_last = num_page_entries_all_last[game_status];
2613 int *choice_store = choice_stores[game_status];
2614 int *first_entry_store = first_entry_stores[game_status];
2615 int choice = choice_store[mode]; // starts with 0
2616 int first_entry = first_entry_store[mode]; // starts with 0
2618 int y = choice - first_entry;
2620 boolean position_set_by_scrollbar = (dx == 999);
2621 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2624 if (button == MB_MENU_INITIALIZE)
2626 // check if number of menu page entries has changed (may happen by change
2627 // of custom artwork definition value for 'list_size' for this menu screen)
2628 // (in this case, the last menu position most probably has to be corrected)
2629 if (num_page_entries != num_page_entries_last[mode])
2631 choice_store[mode] = first_entry_store[mode] = 0;
2633 choice = first_entry = 0;
2636 num_page_entries_last[mode] = num_page_entries;
2639 // advance to first valid menu entry
2640 while (choice < num_page_entries &&
2641 menu_info[choice].type & TYPE_SKIP_ENTRY)
2644 if (position_set_by_scrollbar)
2645 first_entry = first_entry_store[mode] = dy;
2647 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2648 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2650 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2652 if (choice < first_entry)
2654 choice = first_entry;
2656 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2659 else if (choice > first_entry + num_page_entries - 1)
2661 choice = first_entry + num_page_entries - 1;
2663 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2667 choice_store[mode] = choice;
2669 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2673 else if (button == MB_MENU_LEAVE)
2675 PlaySound(SND_MENU_ITEM_SELECTING);
2677 for (i = 0; i < max_page_entries; i++)
2679 if (menu_info[i].type & TYPE_LEAVE_MENU)
2681 void (*menu_callback_function)(void) = menu_info[i].value;
2685 menu_callback_function();
2687 break; // absolutely needed because function changes 'menu_info'!
2694 if (mx || my) // mouse input
2696 x = (mx - mSX) / 32;
2697 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2699 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2701 // move cursor instead of scrolling when already at start/end of list
2702 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2704 else if (dy == +1 * SCROLL_LINE &&
2705 first_entry + num_page_entries == max_page_entries)
2708 // handle scrolling screen one line or page
2710 y + dy > num_page_entries - 1)
2712 boolean redraw = FALSE;
2714 if (ABS(dy) == SCROLL_PAGE)
2715 step = num_page_entries - 1;
2717 if (dy < 0 && first_entry > 0)
2719 // scroll page/line up
2721 first_entry -= step;
2722 if (first_entry < 0)
2727 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2729 // scroll page/line down
2731 first_entry += step;
2732 if (first_entry + num_page_entries > max_page_entries)
2733 first_entry = MAX(0, max_page_entries - num_page_entries);
2740 choice += first_entry - first_entry_store[mode];
2742 if (choice < first_entry)
2744 choice = first_entry;
2746 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2749 else if (choice > first_entry + num_page_entries - 1)
2751 choice = first_entry + num_page_entries - 1;
2753 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2756 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2760 if (choice < first_entry ||
2761 choice > first_entry + num_page_entries - 1)
2762 first_entry += SIGN(dy);
2765 first_entry_store[mode] = first_entry;
2766 choice_store[mode] = choice;
2768 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2770 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2772 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2773 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2781 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2783 if (menu_info[choice].type & menu_navigation_type ||
2784 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2785 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2786 menu_info[choice].type & TYPE_PLAYER)
2787 button = MB_MENU_CHOICE;
2792 // jump to next non-empty menu entry (up or down)
2793 while (first_entry + y > 0 &&
2794 first_entry + y < max_page_entries - 1 &&
2795 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2798 if (!IN_VIS_MENU(x, y))
2800 choice += y - y_old;
2802 if (choice < first_entry)
2803 first_entry = choice;
2804 else if (choice > first_entry + num_page_entries - 1)
2805 first_entry = choice - num_page_entries + 1;
2807 if (first_entry >= 0 &&
2808 first_entry + num_page_entries <= max_page_entries)
2810 first_entry_store[mode] = first_entry;
2812 if (choice < first_entry)
2813 choice = first_entry;
2814 else if (choice > first_entry + num_page_entries - 1)
2815 choice = first_entry + num_page_entries - 1;
2817 choice_store[mode] = choice;
2819 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2821 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2823 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2824 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2831 if (!anyScrollbarGadgetActive() &&
2832 IN_VIS_MENU(x, y) &&
2833 mx < mx_right_border &&
2834 y >= 0 && y < num_page_entries)
2838 if (first_entry + y != choice &&
2839 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2841 PlaySound(SND_MENU_ITEM_ACTIVATING);
2843 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2844 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2846 choice = choice_store[mode] = first_entry + y;
2850 PlaySound(SND_MENU_ITEM_SELECTING);
2852 for (i = 0; menu_info[i].type != 0; i++)
2854 if (menu_info[i].type & TYPE_LEAVE_MENU)
2856 void (*menu_callback_function)(void) = menu_info[i].value;
2860 menu_callback_function();
2862 // absolutely needed because function changes 'menu_info'!
2870 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2872 PlaySound(SND_MENU_ITEM_SELECTING);
2874 // when selecting key headline, execute function for key value change
2875 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2876 menu_info[first_entry + y + 1].type & TYPE_KEY)
2879 // when selecting string value, execute function for list selection
2880 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2881 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2884 // when selecting string value, execute function for text input gadget
2885 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2886 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2889 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2891 void (*menu_callback_function)(void) =
2892 menu_info[first_entry + y].value;
2894 FadeSetFromType(menu_info[first_entry + y].type);
2896 menu_callback_function();
2898 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2900 void (*gadget_callback_function)(void) =
2901 menu_info[first_entry + y].value;
2903 gadget_callback_function();
2905 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2906 menu_info == setup_info)
2908 changeSetupValue(y, first_entry + y, dx);
2914 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2916 menu_info = info_info;
2918 HandleMenuScreen(mx, my, dx, dy, button,
2919 info_mode, num_info_info, max_info_info);
2922 static int getMenuFontSpacing(int spacing_height, int font_nr)
2924 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2926 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2930 static int getMenuTextSpacing(int spacing_height, int font_nr)
2932 return (getMenuFontSpacing(spacing_height, font_nr) +
2933 EXTRA_SPACING(game_status));
2936 static int getMenuTextStep(int spacing_height, int font_nr)
2938 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2941 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2943 int font_title = MENU_INFO_FONT_TITLE;
2944 int font_error = FONT_TEXT_2;
2945 int font_foot = MENU_INFO_FONT_FOOT;
2946 int spacing_title = menu.headline1_spacing_info[info_mode];
2947 int ystep_title = getMenuTextStep(spacing_title, font_title);
2948 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2949 int ystart2 = ystart1 + ystep_title;
2950 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2952 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2954 FadeOut(REDRAW_FIELD);
2959 DrawTextSCentered(ystart1, font_title, text_title);
2960 DrawTextSCentered(ystart2, font_error, text_error);
2962 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
2964 FadeIn(REDRAW_FIELD);
2967 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2969 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2970 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2971 int font_title = MENU_INFO_FONT_TITLE;
2972 int font_foot = MENU_INFO_FONT_FOOT;
2973 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2974 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2975 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2976 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2977 int ystep = MENU_SCREEN_INFO_YSTEP;
2978 int element, action, direction;
2986 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2987 infoscreen_step[i] = infoscreen_frame[i] = 0;
2992 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2993 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
2999 while (helpanim_info[j].element != HELPANIM_LIST_END)
3001 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
3006 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3015 j += infoscreen_step[i - start];
3017 element = helpanim_info[j].element;
3018 action = helpanim_info[j].action;
3019 direction = helpanim_info[j].direction;
3022 element = EL_UNKNOWN;
3024 if (action != -1 && direction != -1)
3025 graphic = el_act_dir2img(element, action, direction);
3026 else if (action != -1)
3027 graphic = el_act2img(element, action);
3028 else if (direction != -1)
3029 graphic = el_dir2img(element, direction);
3031 graphic = el2img(element);
3033 delay = helpanim_info[j++].delay;
3038 if (infoscreen_frame[i - start] == 0)
3041 infoscreen_frame[i - start] = delay - 1;
3045 sync_frame = delay - infoscreen_frame[i - start];
3046 infoscreen_frame[i - start]--;
3049 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3051 if (!infoscreen_frame[i - start])
3052 infoscreen_step[i - start] = 0;
3056 if (!infoscreen_frame[i - start])
3057 infoscreen_step[i - start]++;
3058 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3064 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3066 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3067 graphic, sync_frame, USE_MASKING);
3070 DrawInfoScreen_HelpText(element, action, direction, i - start);
3075 redraw_mask |= REDRAW_FIELD;
3080 static char *getHelpText(int element, int action, int direction)
3082 char token[MAX_LINE_LEN];
3084 strcpy(token, element_info[element].token_name);
3087 strcat(token, element_action_info[action].suffix);
3089 if (direction != -1)
3090 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3092 return getHashEntry(helptext_info, token);
3095 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3097 int font_nr = FONT_INFO_ELEMENTS;
3098 int font_width = getFontWidth(font_nr);
3099 int font_height = getFontHeight(font_nr);
3100 int yoffset = (TILEX - 2 * font_height) / 2;
3101 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3102 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3103 int ystep = TILEY + 4;
3104 int pad_left = xstart - SX;
3105 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3106 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3107 int max_lines_per_text = 2;
3110 if (action != -1 && direction != -1) // element.action.direction
3111 text = getHelpText(element, action, direction);
3113 if (text == NULL && action != -1) // element.action
3114 text = getHelpText(element, action, -1);
3116 if (text == NULL && direction != -1) // element.direction
3117 text = getHelpText(element, -1, direction);
3119 if (text == NULL) // base element
3120 text = getHelpText(element, -1, -1);
3122 if (text == NULL) // not found
3123 text = "No description available";
3125 if (strlen(text) <= max_chars_per_line) // only one line of text
3126 ystart += getFontHeight(font_nr) / 2;
3128 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3129 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3130 TRUE, FALSE, FALSE);
3133 static void DrawInfoScreen_TitleScreen(void)
3135 SetGameStatus(GAME_MODE_TITLE);
3140 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3142 HandleTitleScreen(0, 0, dx, dy, button);
3145 static void DrawInfoScreen_Elements(void)
3147 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3149 FadeOut(REDRAW_FIELD);
3154 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3156 FadeIn(REDRAW_FIELD);
3159 void HandleInfoScreen_Elements(int dx, int dy, int button)
3161 static unsigned int info_delay = 0;
3162 static int num_anims;
3163 static int num_pages;
3165 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3168 if (button == MB_MENU_INITIALIZE)
3170 boolean new_element = TRUE;
3174 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3176 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3178 else if (new_element)
3181 new_element = FALSE;
3185 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3189 if (button == MB_MENU_LEAVE)
3191 PlaySound(SND_MENU_ITEM_SELECTING);
3193 info_mode = INFO_MODE_MAIN;
3198 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3200 if (button != MB_MENU_INITIALIZE)
3202 PlaySound(SND_MENU_ITEM_SELECTING);
3204 page += (dx < 0 ? -1 : +1);
3207 if (page < 0 || page >= num_pages)
3209 FadeMenuSoundsAndMusic();
3211 info_mode = INFO_MODE_MAIN;
3217 if (button != MB_MENU_INITIALIZE)
3218 FadeSetNextScreen();
3220 if (button != MB_MENU_INITIALIZE)
3221 FadeOut(REDRAW_FIELD);
3223 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3225 if (button != MB_MENU_INITIALIZE)
3226 FadeIn(REDRAW_FIELD);
3230 if (DelayReached(&info_delay, GameFrameDelay))
3231 if (page < num_pages)
3232 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3234 PlayMenuSoundIfLoop();
3238 static void DrawInfoScreen_Music(void)
3240 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3242 FadeOut(REDRAW_FIELD);
3249 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3251 FadeIn(REDRAW_FIELD);
3254 void HandleInfoScreen_Music(int dx, int dy, int button)
3256 static struct MusicFileInfo *list = NULL;
3257 int font_title = MENU_INFO_FONT_TITLE;
3258 int font_head = MENU_INFO_FONT_HEAD;
3259 int font_text = MENU_INFO_FONT_TEXT;
3260 int font_foot = MENU_INFO_FONT_FOOT;
3261 int spacing_title = menu.headline1_spacing_info[info_mode];
3262 int spacing_head = menu.headline2_spacing_info[info_mode];
3263 int ystep_title = getMenuTextStep(spacing_title, font_title);
3264 int ystep_head = getMenuTextStep(spacing_head, font_head);
3265 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3266 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3268 if (button == MB_MENU_INITIALIZE)
3270 list = music_file_info;
3274 FadeMenuSoundsAndMusic();
3279 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3280 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3286 if (button == MB_MENU_LEAVE)
3288 PlaySound(SND_MENU_ITEM_SELECTING);
3290 FadeMenuSoundsAndMusic();
3292 info_mode = INFO_MODE_MAIN;
3297 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3299 if (button != MB_MENU_INITIALIZE)
3301 PlaySound(SND_MENU_ITEM_SELECTING);
3304 list = (dx < 0 ? list->prev : list->next);
3309 FadeMenuSoundsAndMusic();
3311 info_mode = INFO_MODE_MAIN;
3317 FadeMenuSoundsAndMusic();
3319 if (list != music_file_info)
3320 FadeSetNextScreen();
3322 if (button != MB_MENU_INITIALIZE)
3323 FadeOut(REDRAW_FIELD);
3330 int sound = list->music;
3332 if (IS_LOOP_SOUND(sound))
3333 PlaySoundLoop(sound);
3337 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3341 int music = list->music;
3343 if (IS_LOOP_MUSIC(music))
3344 PlayMusicLoop(music);
3348 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3351 ystart += ystep_title;
3353 if (!strEqual(list->title, UNKNOWN_NAME))
3355 if (!strEqual(list->title_header, UNKNOWN_NAME))
3357 DrawTextSCentered(ystart, font_head, list->title_header);
3358 ystart += ystep_head;
3361 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3362 ystart += ystep_head;
3365 if (!strEqual(list->artist, UNKNOWN_NAME))
3367 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3368 DrawTextSCentered(ystart, font_head, list->artist_header);
3370 DrawTextSCentered(ystart, font_head, "by");
3372 ystart += ystep_head;
3374 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3375 ystart += ystep_head;
3378 if (!strEqual(list->album, UNKNOWN_NAME))
3380 if (!strEqual(list->album_header, UNKNOWN_NAME))
3381 DrawTextSCentered(ystart, font_head, list->album_header);
3383 DrawTextSCentered(ystart, font_head, "from the album");
3385 ystart += ystep_head;
3387 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3388 ystart += ystep_head;
3391 if (!strEqual(list->year, UNKNOWN_NAME))
3393 if (!strEqual(list->year_header, UNKNOWN_NAME))
3394 DrawTextSCentered(ystart, font_head, list->year_header);
3396 DrawTextSCentered(ystart, font_head, "from the year");
3398 ystart += ystep_head;
3400 DrawTextFCentered(ystart, font_text, "%s", list->year);
3401 ystart += ystep_head;
3404 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3406 if (button != MB_MENU_INITIALIZE)
3407 FadeIn(REDRAW_FIELD);
3410 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3411 PlaySoundLoop(list->music);
3414 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3416 int font_title = MENU_INFO_FONT_TITLE;
3417 int font_text = MENU_INFO_FONT_TEXT;
3418 int font_foot = MENU_INFO_FONT_FOOT;
3419 int spacing_title = menu.headline1_spacing_info[info_mode];
3420 int spacing_line = menu.line_spacing_info[info_mode];
3421 int ystep_title = getMenuTextStep(spacing_title, font_title);
3422 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3423 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3428 DrawTextSCentered(ystart, font_title, "Credits:");
3430 char *filename = getCreditsFilename(screen_nr, use_global_credits_screens);
3432 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3433 int chars = width / getFontWidth(font_text);
3434 int lines = height / getFontHeight(font_text);
3435 int padx = (width - chars * getFontWidth(font_text)) / 2;
3436 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3437 boolean autowrap = FALSE;
3438 boolean centered = TRUE;
3439 boolean parse_comments = TRUE;
3441 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3442 filename, font_text, chars, -1, lines, line_spacing, -1,
3443 autowrap, centered, parse_comments);
3445 boolean last_screen = (screen_nr == num_credits_screens - 1);
3446 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3448 DrawTextSCentered(ybottom, font_foot, text_foot);
3451 static void DrawInfoScreen_Credits(void)
3453 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3455 FadeMenuSoundsAndMusic();
3457 FadeOut(REDRAW_FIELD);
3459 HandleInfoScreen_Credits(0, 0, MB_MENU_INITIALIZE);
3461 FadeIn(REDRAW_FIELD);
3464 void HandleInfoScreen_Credits(int dx, int dy, int button)
3466 static int screen_nr = 0;
3468 if (button == MB_MENU_INITIALIZE)
3472 // determine number of (global or level set specific) credits screens
3473 for (i = 0; i < 2; i++)
3475 num_credits_screens = 0;
3476 use_global_credits_screens = i;
3478 while (getCreditsFilename(num_credits_screens,
3479 use_global_credits_screens) != NULL)
3480 num_credits_screens++;
3482 if (num_credits_screens > 0)
3486 if (num_credits_screens == 0)
3488 int font_title = MENU_INFO_FONT_TITLE;
3489 int font_foot = MENU_INFO_FONT_FOOT;
3490 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3491 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3496 DrawTextSCentered(ystart, font_title, "No credits for this level set.");
3497 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3504 DrawInfoScreen_CreditsScreen(screen_nr);
3506 else if (button == MB_MENU_LEAVE)
3508 PlaySound(SND_MENU_ITEM_SELECTING);
3510 info_mode = INFO_MODE_MAIN;
3515 else if (button == MB_MENU_CHOICE || dx)
3517 PlaySound(SND_MENU_ITEM_SELECTING);
3519 screen_nr += (dx < 0 ? -1 : +1);
3521 if (screen_nr < 0 || screen_nr >= num_credits_screens)
3523 FadeMenuSoundsAndMusic();
3525 info_mode = INFO_MODE_MAIN;
3531 FadeSetNextScreen();
3533 FadeOut(REDRAW_FIELD);
3535 DrawInfoScreen_CreditsScreen(screen_nr);
3537 FadeIn(REDRAW_FIELD);
3541 PlayMenuSoundIfLoop();
3545 static void DrawInfoScreen_ProgramScreen(int screen_nr)
3547 int font_title = MENU_INFO_FONT_TITLE;
3548 int font_text = MENU_INFO_FONT_TEXT;
3549 int font_foot = MENU_INFO_FONT_FOOT;
3550 int spacing_title = menu.headline1_spacing_info[info_mode];
3551 int spacing_line = menu.line_spacing_info[info_mode];
3552 int ystep_title = getMenuTextStep(spacing_title, font_title);
3553 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3554 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3559 DrawTextSCentered(ystart, font_title, "Program Information:");
3561 char *filename = getProgramInfoFilename(screen_nr);
3563 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3564 int chars = width / getFontWidth(font_text);
3565 int lines = height / getFontHeight(font_text);
3566 int padx = (width - chars * getFontWidth(font_text)) / 2;
3567 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3568 boolean autowrap = FALSE;
3569 boolean centered = TRUE;
3570 boolean parse_comments = TRUE;
3572 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3573 filename, font_text, chars, -1, lines, line_spacing, -1,
3574 autowrap, centered, parse_comments);
3576 boolean last_screen = (screen_nr == num_program_info_screens - 1);
3577 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3579 DrawTextSCentered(ybottom, font_foot, text_foot);
3582 static void DrawInfoScreen_Program(void)
3584 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3586 FadeMenuSoundsAndMusic();
3588 FadeOut(REDRAW_FIELD);
3590 HandleInfoScreen_Program(0, 0, MB_MENU_INITIALIZE);
3592 FadeIn(REDRAW_FIELD);
3595 void HandleInfoScreen_Program(int dx, int dy, int button)
3597 static int screen_nr = 0;
3599 if (button == MB_MENU_INITIALIZE)
3601 // determine number of program info screens
3602 num_program_info_screens = 0;
3604 while (getProgramInfoFilename(num_program_info_screens) != NULL)
3605 num_program_info_screens++;
3607 if (num_program_info_screens == 0)
3609 int font_title = MENU_INFO_FONT_TITLE;
3610 int font_foot = MENU_INFO_FONT_FOOT;
3611 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3612 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3617 DrawTextSCentered(ystart, font_title, "No program info available.");
3618 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3625 DrawInfoScreen_ProgramScreen(screen_nr);
3627 else if (button == MB_MENU_LEAVE)
3629 PlaySound(SND_MENU_ITEM_SELECTING);
3631 info_mode = INFO_MODE_MAIN;
3636 else if (button == MB_MENU_CHOICE || dx)
3638 PlaySound(SND_MENU_ITEM_SELECTING);
3640 screen_nr += (dx < 0 ? -1 : +1);
3642 if (screen_nr < 0 || screen_nr >= num_program_info_screens)
3644 FadeMenuSoundsAndMusic();
3646 info_mode = INFO_MODE_MAIN;
3652 FadeSetNextScreen();
3654 FadeOut(REDRAW_FIELD);
3656 DrawInfoScreen_ProgramScreen(screen_nr);
3658 FadeIn(REDRAW_FIELD);
3662 PlayMenuSoundIfLoop();
3666 static void DrawInfoScreen_Version(void)
3668 int font_title = MENU_INFO_FONT_TITLE;
3669 int font_head = MENU_INFO_FONT_HEAD;
3670 int font_text = MENU_INFO_FONT_TEXT;
3671 int font_foot = MENU_INFO_FONT_FOOT;
3672 int spacing_title = menu.headline1_spacing_info[info_mode];
3673 int spacing_head = menu.headline2_spacing_info[info_mode];
3674 int spacing_para = menu.paragraph_spacing_info[info_mode];
3675 int spacing_line = menu.line_spacing_info[info_mode];
3676 int xstep = getFontWidth(font_text);
3677 int ystep_title = getMenuTextStep(spacing_title, font_title);
3678 int ystep_head = getMenuTextStep(spacing_head, font_head);
3679 int ystep_para = getMenuTextStep(spacing_para, font_text);
3680 int ystep_line = getMenuTextStep(spacing_line, font_text);
3681 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3682 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3683 int xstart1 = mSX - SX + 2 * xstep;
3684 int xstart2 = mSX - SX + 18 * xstep;
3685 int xstart3 = mSX - SX + 28 * xstep;
3686 SDL_version sdl_version_compiled;
3687 const SDL_version *sdl_version_linked;
3688 int driver_name_len = 10;
3689 SDL_version sdl_version_linked_ext;
3690 const char *driver_name = NULL;
3692 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3694 FadeOut(REDRAW_FIELD);
3699 DrawTextSCentered(ystart, font_title, "Version Information:");
3700 ystart += ystep_title;
3702 DrawTextF(xstart1, ystart, font_head, "Name");
3703 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3704 ystart += ystep_line;
3706 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3708 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3709 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3710 ystart += ystep_line;
3712 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3713 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3714 ystart += ystep_line;
3718 DrawTextF(xstart1, ystart, font_head, "Version");
3719 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3720 ystart += ystep_line;
3723 DrawTextF(xstart1, ystart, font_head, "Platform");
3724 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3726 PLATFORM_XX_BIT_STRING);
3727 ystart += ystep_line;
3729 DrawTextF(xstart1, ystart, font_head, "Target");
3730 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3731 ystart += ystep_line;
3733 DrawTextF(xstart1, ystart, font_head, "Source date");
3734 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3735 ystart += ystep_line;
3737 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3738 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3739 ystart += ystep_para;
3741 DrawTextF(xstart1, ystart, font_head, "Library");
3742 DrawTextF(xstart2, ystart, font_head, "compiled");
3743 DrawTextF(xstart3, ystart, font_head, "linked");
3744 ystart += ystep_head;
3746 SDL_VERSION(&sdl_version_compiled);
3747 SDL_GetVersion(&sdl_version_linked_ext);
3748 sdl_version_linked = &sdl_version_linked_ext;
3750 DrawTextF(xstart1, ystart, font_text, "SDL");
3751 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3752 sdl_version_compiled.major,
3753 sdl_version_compiled.minor,
3754 sdl_version_compiled.patch);
3755 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3756 sdl_version_linked->major,
3757 sdl_version_linked->minor,
3758 sdl_version_linked->patch);
3759 ystart += ystep_line;
3761 SDL_IMAGE_VERSION(&sdl_version_compiled);
3762 sdl_version_linked = IMG_Linked_Version();
3764 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3765 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3766 sdl_version_compiled.major,
3767 sdl_version_compiled.minor,
3768 sdl_version_compiled.patch);
3769 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3770 sdl_version_linked->major,
3771 sdl_version_linked->minor,
3772 sdl_version_linked->patch);
3773 ystart += ystep_line;
3775 SDL_MIXER_VERSION(&sdl_version_compiled);
3776 sdl_version_linked = Mix_Linked_Version();
3778 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3779 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3780 sdl_version_compiled.major,
3781 sdl_version_compiled.minor,
3782 sdl_version_compiled.patch);
3783 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3784 sdl_version_linked->major,
3785 sdl_version_linked->minor,
3786 sdl_version_linked->patch);
3787 ystart += ystep_line;
3789 SDL_NET_VERSION(&sdl_version_compiled);
3790 sdl_version_linked = SDLNet_Linked_Version();
3792 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3793 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3794 sdl_version_compiled.major,
3795 sdl_version_compiled.minor,
3796 sdl_version_compiled.patch);
3797 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3798 sdl_version_linked->major,
3799 sdl_version_linked->minor,
3800 sdl_version_linked->patch);
3801 ystart += ystep_para;
3803 DrawTextF(xstart1, ystart, font_head, "Driver");
3804 DrawTextF(xstart2, ystart, font_head, "Requested");
3805 DrawTextF(xstart3, ystart, font_head, "Used");
3806 ystart += ystep_head;
3809 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3811 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3812 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3813 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3814 ystart += ystep_line;
3817 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3819 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3820 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3821 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3822 ystart += ystep_line;
3825 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3827 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3828 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3829 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3831 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3833 FadeIn(REDRAW_FIELD);
3836 void HandleInfoScreen_Version(int button)
3838 if (button == MB_MENU_LEAVE)
3840 PlaySound(SND_MENU_ITEM_SELECTING);
3842 info_mode = INFO_MODE_MAIN;
3847 else if (button == MB_MENU_CHOICE)
3849 PlaySound(SND_MENU_ITEM_SELECTING);
3851 FadeMenuSoundsAndMusic();
3853 info_mode = INFO_MODE_MAIN;
3858 PlayMenuSoundIfLoop();
3862 static void DrawInfoScreen_LevelSet(void)
3864 struct TitleMessageInfo *tmi = &readme;
3865 char *filename = getLevelSetInfoFilename();
3866 char *title = "Level Set Information:";
3867 int font_foot = MENU_INFO_FONT_FOOT;
3868 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3869 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3871 if (filename == NULL)
3873 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3878 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3880 FadeOut(REDRAW_FIELD);
3885 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3887 // if x position set to "-1", automatically determine by playfield width
3889 tmi->x = SXSIZE / 2;
3891 // if y position set to "-1", use static default value
3895 // if width set to "-1", automatically determine by playfield width
3896 if (tmi->width == -1)
3897 tmi->width = SXSIZE - 2 * TILEX;
3899 // if height set to "-1", automatically determine by playfield height
3900 if (tmi->height == -1)
3901 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3903 // if chars set to "-1", automatically determine by text and font width
3904 if (tmi->chars == -1)
3905 tmi->chars = tmi->width / getFontWidth(tmi->font);
3907 tmi->width = tmi->chars * getFontWidth(tmi->font);
3909 // if lines set to "-1", automatically determine by text and font height
3910 if (tmi->lines == -1)
3911 tmi->lines = tmi->height / getFontHeight(tmi->font);
3913 tmi->height = tmi->lines * getFontHeight(tmi->font);
3915 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3916 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3917 tmi->autowrap, tmi->centered, tmi->parse_comments);
3919 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3921 FadeIn(REDRAW_FIELD);
3924 static void HandleInfoScreen_LevelSet(int button)
3926 if (button == MB_MENU_LEAVE)
3928 PlaySound(SND_MENU_ITEM_SELECTING);
3930 info_mode = INFO_MODE_MAIN;
3935 else if (button == MB_MENU_CHOICE)
3937 PlaySound(SND_MENU_ITEM_SELECTING);
3939 FadeMenuSoundsAndMusic();
3941 info_mode = INFO_MODE_MAIN;
3946 PlayMenuSoundIfLoop();
3950 static void DrawInfoScreen(void)
3952 if (info_mode == INFO_MODE_TITLE)
3953 DrawInfoScreen_TitleScreen();
3954 else if (info_mode == INFO_MODE_ELEMENTS)
3955 DrawInfoScreen_Elements();
3956 else if (info_mode == INFO_MODE_MUSIC)
3957 DrawInfoScreen_Music();
3958 else if (info_mode == INFO_MODE_CREDITS)
3959 DrawInfoScreen_Credits();
3960 else if (info_mode == INFO_MODE_PROGRAM)
3961 DrawInfoScreen_Program();
3962 else if (info_mode == INFO_MODE_VERSION)
3963 DrawInfoScreen_Version();
3964 else if (info_mode == INFO_MODE_LEVELSET)
3965 DrawInfoScreen_LevelSet();
3967 DrawInfoScreen_Main();
3969 if (info_mode != INFO_MODE_MAIN &&
3970 info_mode != INFO_MODE_TITLE &&
3971 info_mode != INFO_MODE_MUSIC)
3972 PlayMenuSoundsAndMusic();
3975 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3977 if (info_mode == INFO_MODE_TITLE)
3978 HandleInfoScreen_TitleScreen(dx, dy, button);
3979 else if (info_mode == INFO_MODE_ELEMENTS)
3980 HandleInfoScreen_Elements(dx, dy, button);
3981 else if (info_mode == INFO_MODE_MUSIC)
3982 HandleInfoScreen_Music(dx, dy, button);
3983 else if (info_mode == INFO_MODE_CREDITS)
3984 HandleInfoScreen_Credits(dx, dy, button);
3985 else if (info_mode == INFO_MODE_PROGRAM)
3986 HandleInfoScreen_Program(dx, dy, button);
3987 else if (info_mode == INFO_MODE_VERSION)
3988 HandleInfoScreen_Version(button);
3989 else if (info_mode == INFO_MODE_LEVELSET)
3990 HandleInfoScreen_LevelSet(button);
3992 HandleInfoScreen_Main(mx, my, dx, dy, button);
3996 // ============================================================================
3997 // type name functions
3998 // ============================================================================
4000 static TreeInfo *type_name_node = NULL;
4001 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4002 static int type_name_nr = 0;
4004 static int getPlayerNameColor(char *name)
4006 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4009 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4012 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4013 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4014 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4015 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4016 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4017 int font_width = getFontWidth(font_nr);
4018 int font_xoffset = getFontDrawOffsetX(font_nr);
4019 int font_yoffset = getFontDrawOffsetY(font_nr);
4020 int font_sx = sx + font_xoffset;
4021 int font_sy = sy + font_yoffset;
4023 DrawBackgroundForFont(font_sx, font_sy, pos->width, pos->height, font_nr);
4025 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4027 pos->width = strlen(text) * font_width;
4028 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4030 DrawText(sx, sy, text, font_nr);
4033 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4035 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4037 *pos = *mci->pos_input;
4039 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4041 TreeInfo *ti = player_name_current;
4042 int first_entry = ti->cl_first;
4043 int entry_pos = first_entry + ti->cl_cursor;
4044 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4045 int xpos = MENU_SCREEN_START_XPOS;
4046 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4048 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4049 type_name_nr = entry_pos;
4051 strcpy(name, type_name_node->name);
4055 pos->width = MAX_PLAYER_NAME_LEN * 32;
4059 type_name_nr = user.nr;
4061 strcpy(name, setup.player_name);
4064 strcpy(type_name_last, name);
4066 if (strEqual(name, EMPTY_PLAYER_NAME))
4069 *xpos = strlen(name);
4072 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4074 // change name of edited user in global list of user names
4075 setString(&global.user_names[type_name_nr], name);
4077 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4079 TreeInfo *node = type_name_node;
4081 // change name of edited user in local menu tree structure
4082 setString(&node->name, name);
4083 setString(&node->name_sorting, name);
4085 node->color = getPlayerNameColor(name);
4086 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4090 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4093 boolean reset_setup = strEqual(name, "");
4094 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4095 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4098 strcpy(name, type_name_last);
4100 if (strEqual(name, ""))
4101 strcpy(name, EMPTY_PLAYER_NAME);
4103 setTypeNameValues_Name(name, pos);
4105 // if player name not changed, no further action required
4106 if (strEqual(name, type_name_last))
4109 // redraw player name before (possibly) opening request dialogs
4110 drawTypeNameText(name, pos, FALSE);
4112 int last_user_nr = user.nr;
4114 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4116 // save setup of currently active user (may differ from edited user)
4119 // temporarily change active user to edited user
4120 user.nr = type_name_nr;
4123 Request("Use current setup values for the new player?", REQ_ASK))
4125 // use current setup values for new user, but create new player UUID
4126 setup.player_uuid = getStringCopy(getUUID());
4130 // load setup for existing user (or start with defaults for new user)
4135 char *setup_filename = getSetupFilename();
4136 boolean setup_exists = fileExists(setup_filename);
4138 // change name of edited user in setup structure
4139 strcpy(setup.player_name, name);
4141 // save setup of edited user
4144 // change name of edited user on score server
4145 ApiRenamePlayerAsThread();
4147 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4151 if (Request("Reset setup values for this player?", REQ_ASK))
4153 // remove setup config file
4154 unlink(setup_filename);
4156 // set player name to default player name
4159 // update player name used by name typing functions
4160 strcpy(name, setup.player_name);
4162 setTypeNameValues_Name(name, pos);
4165 else if (remove_user && type_name_nr != 0)
4167 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4169 char *user_dir = getUserGameDataDir();
4170 char *user_dir_removed =
4171 getStringCat3WithSeparator(user_dir, "REMOVED",
4172 getCurrentTimestamp(), ".");
4174 if (rename(user_dir, user_dir_removed) != 0)
4175 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4177 checked_free(user_dir_removed);
4180 else if (create_user && type_name_nr != 0 && !setup_exists)
4182 if (Request("Create empty level set for the new player?", REQ_ASK))
4184 char *levelset_subdir = getNewUserLevelSubdir();
4186 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4188 AddUserLevelSetToLevelInfo(levelset_subdir);
4190 LevelDirTree *leveldir_current_last = leveldir_current;
4192 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4195 // set level number of newly created level set to default value
4196 LoadLevelSetup_SeriesInfo();
4198 // set newly created level set as current level set for new user
4199 SaveLevelSetup_LastSeries();
4200 SaveLevelSetup_SeriesInfo();
4202 leveldir_current = leveldir_current_last;
4206 Request("Creating new level set failed!", REQ_CONFIRM);
4211 // restore currently active user
4212 user.nr = last_user_nr;
4214 // restore setup of currently active user
4217 // restore last level set of currently active user
4218 LoadLevelSetup_LastSeries();
4219 LoadLevelSetup_SeriesInfo();
4223 static void HandleTypeNameExt(boolean initialize, Key key)
4225 static struct TextPosInfo pos_name = { 0 };
4226 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4227 static int xpos = 0;
4228 struct TextPosInfo *pos = &pos_name;
4229 char key_char = getValidConfigValueChar(getCharFromKey(key));
4230 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4231 boolean active = TRUE;
4235 getTypeNameValues(name, pos, &xpos);
4237 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4238 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4240 StartTextInput(sx, sy, pos->width, pos->height);
4242 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4244 name[xpos] = key_char;
4249 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4255 else if (key == KSYM_Return || key == KSYM_Escape)
4257 boolean changed = (key == KSYM_Return);
4261 setTypeNameValues(name, pos, changed);
4266 drawTypeNameText(name, pos, active);
4270 SetGameStatus(game_status_last_screen);
4272 if (game_status == GAME_MODE_MAIN)
4273 InitializeMainControls();
4277 static void DrawTypeName(void)
4279 HandleTypeNameExt(TRUE, 0);
4282 void HandleTypeName(Key key)
4284 HandleTypeNameExt(FALSE, key);
4288 // ============================================================================
4289 // tree menu functions
4290 // ============================================================================
4292 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4294 if (game_status != GAME_MODE_SETUP ||
4295 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4298 int max_text_size = 0;
4301 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4302 max_text_size = MAX(max_text_size, strlen(node->name));
4304 int num_entries = numTreeInfoInGroup(ti);
4305 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4306 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4307 int text_width = max_text_size * getFontWidth(font_nr);
4308 int button_width = SC_MENUBUTTON_XSIZE;
4309 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4310 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4311 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4312 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4313 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4314 int align_xoffset = MAX(0, align_xoffset_raw);
4316 return align_xoffset;
4319 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4321 if (game_status != GAME_MODE_SETUP ||
4322 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4325 int num_entries = numTreeInfoInGroup(ti);
4326 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4327 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4328 int font_height = getFontHeight(font_nr);
4329 int text_height = font_height * num_page_entries;
4330 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4331 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4332 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4333 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4334 int align_yoffset = MAX(0, align_yoffset_raw);
4336 return align_yoffset;
4339 static void DrawChooseTree(TreeInfo **ti_ptr)
4341 int fade_mask = REDRAW_FIELD;
4342 boolean restart_music = (game_status != game_status_last_screen &&
4343 game_status_last_screen != GAME_MODE_SCOREINFO);
4345 scores.was_just_playing = (game_status == GAME_MODE_SCORES &&
4346 game_status_last_screen == GAME_MODE_PLAYING);
4349 fade_mask = REDRAW_ALL;
4351 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4353 if (game_status == GAME_MODE_SETUP)
4357 else // GAME_MODE_LEVELS
4359 SetGameStatus(GAME_MODE_MAIN);
4369 FreeScreenGadgets();
4370 CreateScreenGadgets();
4373 FadeMenuSoundsAndMusic();
4377 // needed if different viewport properties defined for this screen
4378 ChangeViewportPropertiesIfNeeded();
4380 if (game_status == GAME_MODE_NAMES)
4381 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4382 else if (game_status == GAME_MODE_LEVELNR)
4383 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4384 else if (game_status == GAME_MODE_LEVELS)
4385 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4386 else if (game_status == GAME_MODE_SCORES)
4387 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4391 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4393 // map gadgets for high score screen
4394 if (game_status == GAME_MODE_SCORES)
4395 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4397 MapScreenTreeGadgets(*ti_ptr);
4399 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4401 DrawMaskedBorder(fade_mask);
4404 PlayMenuSoundsAndMusic();
4409 static int getChooseTreeFont(TreeInfo *node, boolean active)
4411 if (game_status == GAME_MODE_SCORES)
4412 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4414 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4417 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4419 int num_entries = numTreeInfoInGroup(ti);
4420 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4421 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4422 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4423 int first_entry = ti->cl_first;
4424 int entry_pos = first_entry + y;
4425 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4426 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4427 int font_nr = getChooseTreeFont(node, active);
4428 int font_xoffset = getFontDrawOffsetX(font_nr);
4429 int xpos = MENU_SCREEN_START_XPOS;
4430 int ypos = MENU_SCREEN_START_YPOS + y;
4431 int startdx = xpos * 32;
4432 int startdy = ypos * 32;
4433 int startx = amSX + startdx;
4434 int starty = amSY + startdy;
4435 int startx_text = startx + font_xoffset;
4436 int endx_text = amSX + screen_width;
4437 int max_text_size = endx_text - startx_text;
4438 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4439 char buffer[max_buffer_len + 1];
4441 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4443 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4444 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4445 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4446 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4447 int font_size_1 = getFontWidth(font_nr1);
4448 int font_size_3 = getFontWidth(font_nr3);
4449 int font_size_4 = getFontWidth(font_nr4);
4450 int text_size_1 = 4 * font_size_1;
4451 int text_size_4 = 5 * font_size_4;
4452 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4454 int dx3 = text_size_1;
4455 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4456 int num_dots = (dx4 - dx3) / font_size_3;
4457 int startx1 = startx + dx1;
4458 int startx3 = startx + dx3;
4459 int startx4 = startx + dx4;
4460 int pos = node->pos;
4461 char *pos_text = getHallOfFameRankText(pos, 3);
4464 DrawText(startx1, starty, pos_text, font_nr1);
4466 for (i = 0; i < num_dots; i++)
4467 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4469 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4470 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4472 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4476 strncpy(buffer, node->name, max_buffer_len);
4477 buffer[max_buffer_len] = '\0';
4479 DrawText(startx, starty, buffer, font_nr);
4483 static void drawChooseTreeHeadExt(int type, char *title_string)
4485 int yoffset_sets = MENU_TITLE1_YPOS;
4486 int yoffset_setup = 16;
4487 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4488 type == TREE_TYPE_LEVEL_DIR ||
4489 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4491 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4494 static void drawChooseTreeHead(TreeInfo *ti)
4496 drawChooseTreeHeadExt(ti->type, ti->infotext);
4499 static void drawChooseTreeList(TreeInfo *ti)
4501 int first_entry = ti->cl_first;
4502 int num_entries = numTreeInfoInGroup(ti);
4503 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4506 clearMenuListArea();
4508 for (i = 0; i < num_page_entries; i++)
4510 TreeInfo *node, *node_first;
4511 int entry_pos = first_entry + i;
4513 node_first = getTreeInfoFirstGroupEntry(ti);
4514 node = getTreeInfoFromPos(node_first, entry_pos);
4516 drawChooseTreeText(ti, i, FALSE);
4518 if (node->parent_link)
4519 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4520 else if (node->level_group)
4521 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4523 initCursor(i, IMG_MENU_BUTTON);
4525 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4526 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4528 if (game_status == GAME_MODE_NAMES)
4529 drawChooseTreeEdit(i, FALSE);
4532 redraw_mask |= REDRAW_FIELD;
4535 static void drawChooseTreeInfo(TreeInfo *ti)
4537 int entry_pos = ti->cl_first + ti->cl_cursor;
4538 int last_redraw_mask = redraw_mask;
4539 int ypos = MENU_TITLE2_YPOS;
4540 int font_nr = FONT_TITLE_2;
4543 if (ti->type == TREE_TYPE_LEVEL_NR)
4544 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4546 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4547 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4548 scores.last_level_nr);
4550 if (ti->type != TREE_TYPE_LEVEL_DIR)
4553 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4554 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4556 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4558 if (node->parent_link)
4559 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4560 node->node_parent->name);
4561 else if (node->level_group)
4562 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4564 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4565 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4566 node->levels, (node->levels > 1 ? "levels" : "level"),
4569 // let BackToFront() redraw only what is needed
4570 redraw_mask = last_redraw_mask;
4571 for (x = 0; x < SCR_FIELDX; x++)
4572 MarkTileDirty(x, 1);
4575 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4577 drawChooseTreeCursor(ti->cl_cursor, active);
4578 drawChooseTreeText(ti, ti->cl_cursor, active);
4581 static void drawChooseTreeScreen(TreeInfo *ti)
4583 drawChooseTreeHead(ti);
4584 drawChooseTreeList(ti);
4585 drawChooseTreeInfo(ti);
4586 drawChooseTreeCursorAndText(ti, TRUE);
4588 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4590 // scroll bar and buttons may just have been added after reloading scores
4591 if (game_status == GAME_MODE_SCORES)
4592 MapScreenTreeGadgets(ti);
4595 static void drawChooseTreeScreen_Scores_NotAvailable(void)
4597 // dirty workaround to use spacing definitions from info screen
4598 info_mode = INFO_MODE_TITLE;
4600 char *text_info = "HighScores of Level %d";
4601 char *text_title = "Score information:";
4602 char *text_error = "No scores for this level.";
4603 char *text_foot = "Press any key or button for main menu";
4604 int font_info = FONT_TITLE_2;
4605 int font_title = FONT_INITIAL_3;
4606 int font_error = FONT_INITIAL_4;
4607 int font_foot = FONT_INITIAL_2;
4608 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
4609 int ystep_title = getMenuTextStep(spacing_title, font_title);
4610 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
4611 int ystart2 = ystart1 + ystep_title;
4612 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4613 int ystart0 = MENU_TITLE2_YPOS;
4615 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
4616 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
4618 DrawTextSCentered(ystart1, font_title, text_title);
4619 DrawTextSCentered(ystart2, font_error, text_error);
4621 DrawTextSCentered(ybottom, font_foot, text_foot);
4624 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4626 int score_pos = scores.last_added;
4628 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4629 score_pos = scores.last_entry_nr;
4631 // set current tree entry to last added score entry
4632 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4634 // if that fails, set current tree entry to first entry (back link)
4635 if (*ti_ptr == NULL)
4636 *ti_ptr = score_entries->node_group;
4638 int num_entries = numTreeInfoInGroup(*ti_ptr);
4639 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4640 int pos_score = getPosFromTreeInfo(*ti_ptr);
4641 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4642 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4644 (*ti_ptr)->cl_first = pos_first;
4645 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4650 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4653 TreeInfo *ti = *ti_ptr;
4654 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4655 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4656 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4657 int sx1_edit_name = getChooseTreeEditXPosReal(POS_LEFT);
4658 int sx2_edit_name = getChooseTreeEditXPosReal(POS_RIGHT);
4660 int y = (ti != NULL ? ti->cl_cursor : 0);
4661 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4662 int num_entries = numTreeInfoInGroup(ti);
4663 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4664 boolean position_set_by_scrollbar = (dx == 999);
4665 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
4666 boolean button_is_valid = (mx >= 0 && my >= 0);
4667 boolean button_screen_clicked = (button_action && button_is_valid);
4669 if (game_status == GAME_MODE_SCORES)
4671 if (server_scores.updated)
4673 // reload scores, using updated server score cache file
4674 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4676 server_scores.updated = FALSE;
4678 DrawHallOfFame_setScoreEntries();
4680 if (score_entries != NULL)
4682 ti = setHallOfFameActiveEntry(ti_ptr);
4684 if (button != MB_MENU_INITIALIZE)
4685 drawChooseTreeScreen(ti);
4689 if (score_entries == NULL)
4691 if (button == MB_MENU_INITIALIZE)
4693 drawChooseTreeScreen_Scores_NotAvailable();
4695 else if (button_screen_clicked)
4697 PlaySound(SND_MENU_ITEM_SELECTING);
4699 SetGameStatus(GAME_MODE_MAIN);
4708 if (button == MB_MENU_INITIALIZE)
4710 int num_entries = numTreeInfoInGroup(ti);
4711 int entry_pos = getPosFromTreeInfo(ti);
4713 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4714 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4716 if (game_status == GAME_MODE_SCORES)
4718 ti = setHallOfFameActiveEntry(ti_ptr);
4720 else if (ti->cl_first == -1)
4722 // only on initialization
4723 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4724 ti->cl_cursor = entry_pos - ti->cl_first;
4727 else if (ti->cl_cursor >= num_page_entries ||
4728 (num_entries > num_page_entries &&
4729 num_entries - ti->cl_first < num_page_entries))
4731 // only after change of list size (by custom graphic configuration)
4732 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4733 ti->cl_cursor = entry_pos - ti->cl_first;
4736 if (position_set_by_scrollbar)
4739 drawChooseTreeScreen(ti);
4743 else if (button == MB_MENU_LEAVE)
4745 if (game_status != GAME_MODE_SCORES)
4748 PlaySound(SND_MENU_ITEM_SELECTING);
4750 if (ti->node_parent)
4752 *ti_ptr = ti->node_parent;
4753 DrawChooseTree(ti_ptr);
4755 else if (game_status == GAME_MODE_SETUP)
4757 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4758 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4759 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4760 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4762 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4763 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4764 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4765 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4766 execSetupGraphics();
4767 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4768 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4769 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4771 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4772 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4773 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4774 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4775 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4776 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4777 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4778 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4785 if (game_status == GAME_MODE_LEVELNR)
4787 int new_level_nr = atoi(level_number_current->identifier);
4789 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4792 SetGameStatus(GAME_MODE_MAIN);
4800 #if defined(PLATFORM_ANDROID)
4801 // touching the screen anywhere continues playing the next level
4802 if ((mx || my) && scores.was_just_playing)
4805 button = MB_MENU_CHOICE;
4809 // any mouse click or direction input stops playing the next level
4810 if ((mx || my || dx || dy) && scores.was_just_playing)
4812 scores.was_just_playing = FALSE;
4813 level_nr = scores.last_level_nr;
4814 LoadLevel(level_nr);
4817 if (mx || my) // mouse input
4819 x = (mx - amSX) / 32;
4820 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4822 if (game_status == GAME_MODE_NAMES)
4823 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4825 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4827 // move cursor instead of scrolling when already at start/end of list
4828 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4830 else if (dy == +1 * SCROLL_LINE &&
4831 ti->cl_first + num_page_entries == num_entries)
4834 // handle scrolling screen one line or page
4835 if (ti->cl_cursor + dy < 0 ||
4836 ti->cl_cursor + dy > num_page_entries - 1)
4838 boolean redraw = FALSE;
4840 if (ABS(dy) == SCROLL_PAGE)
4841 step = num_page_entries - 1;
4843 if (dy < 0 && ti->cl_first > 0)
4845 // scroll page/line up
4847 ti->cl_first -= step;
4848 if (ti->cl_first < 0)
4853 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4855 // scroll page/line down
4857 ti->cl_first += step;
4858 if (ti->cl_first + num_page_entries > num_entries)
4859 ti->cl_first = MAX(0, num_entries - num_page_entries);
4865 drawChooseTreeScreen(ti);
4870 // handle moving cursor one line
4871 y = ti->cl_cursor + dy;
4874 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
4876 HandleHallOfFame_SelectLevel(1, dx);
4882 TreeInfo *node_first, *node_cursor;
4883 int entry_pos = ti->cl_first + y;
4885 node_first = getTreeInfoFirstGroupEntry(ti);
4886 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4888 if (node_cursor->node_group)
4892 PlaySound(SND_MENU_ITEM_SELECTING);
4894 node_cursor->cl_first = ti->cl_first;
4895 node_cursor->cl_cursor = ti->cl_cursor;
4896 *ti_ptr = node_cursor->node_group;
4897 DrawChooseTree(ti_ptr);
4902 else if (dx == -1 && ti->node_parent)
4906 PlaySound(SND_MENU_ITEM_SELECTING);
4908 *ti_ptr = ti->node_parent;
4909 DrawChooseTree(ti_ptr);
4914 if (!anyScrollbarGadgetActive() &&
4915 IN_VIS_MENU(x, y) &&
4916 mx < mx_right_border &&
4917 y >= 0 && y < num_page_entries)
4921 if (game_status == GAME_MODE_NAMES)
4923 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4924 drawChooseTreeEdit(y, TRUE);
4927 if (y != ti->cl_cursor)
4929 PlaySound(SND_MENU_ITEM_ACTIVATING);
4931 drawChooseTreeCursorAndText(ti, FALSE);
4935 drawChooseTreeCursorAndText(ti, TRUE);
4937 drawChooseTreeInfo(ti);
4941 if (game_status == GAME_MODE_SETUP)
4943 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4944 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4945 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4946 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4948 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4949 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4950 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4951 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4952 execSetupGraphics();
4953 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4954 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4955 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4957 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4958 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4959 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4960 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4961 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4962 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4963 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4964 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4973 TreeInfo *node_first, *node_cursor;
4974 int entry_pos = ti->cl_first + y;
4976 PlaySound(SND_MENU_ITEM_SELECTING);
4978 node_first = getTreeInfoFirstGroupEntry(ti);
4979 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4981 if (node_cursor->node_group)
4985 node_cursor->cl_first = ti->cl_first;
4986 node_cursor->cl_cursor = ti->cl_cursor;
4987 *ti_ptr = node_cursor->node_group;
4988 DrawChooseTree(ti_ptr);
4990 else if (node_cursor->parent_link)
4992 if (game_status != GAME_MODE_SCORES)
4995 *ti_ptr = node_cursor->node_parent;
4996 DrawChooseTree(ti_ptr);
5000 if (game_status != GAME_MODE_SCORES)
5003 node_cursor->cl_first = ti->cl_first;
5004 node_cursor->cl_cursor = ti->cl_cursor;
5005 *ti_ptr = node_cursor;
5007 if (ti->type == TREE_TYPE_LEVEL_DIR)
5009 LoadLevelSetup_SeriesInfo();
5011 SaveLevelSetup_LastSeries();
5012 SaveLevelSetup_SeriesInfo();
5016 if (game_status == GAME_MODE_SETUP)
5018 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5019 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5020 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5021 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5023 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5024 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5025 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5026 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5027 execSetupGraphics();
5028 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5029 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5030 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5032 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5033 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5034 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5035 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5036 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5037 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5038 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5039 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5046 if (game_status == GAME_MODE_LEVELNR)
5048 int new_level_nr = atoi(level_number_current->identifier);
5050 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5052 else if (game_status == GAME_MODE_LEVELS)
5054 // store level set if chosen from "last played level set" menu
5055 StoreLastPlayedLevels(leveldir_current);
5057 else if (game_status == GAME_MODE_NAMES)
5059 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5061 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5068 // change active user to selected user
5069 user.nr = entry_pos;
5071 // save number of new active user
5074 // load setup of new active user
5077 // load last level set of new active user
5078 LoadLevelSetup_LastSeries();
5079 LoadLevelSetup_SeriesInfo();
5081 // update list of last played level sets
5082 UpdateLastPlayedLevels_TreeInfo();
5086 ToggleFullscreenIfNeeded();
5087 ChangeWindowScalingIfNeeded();
5089 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5090 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5091 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5093 else if (game_status == GAME_MODE_SCORES)
5095 if (setup.auto_play_next_level && setup.increment_levels &&
5096 scores.last_level_nr < leveldir_current->last_level &&
5097 scores.was_just_playing &&
5100 StartGameActions(network.enabled, setup.autorecord,
5104 else if (!scores.was_just_playing)
5106 SetGameStatus(GAME_MODE_SCOREINFO);
5108 DrawScoreInfo(node_cursor->pos);
5114 SetGameStatus(GAME_MODE_MAIN);
5122 if (game_status == GAME_MODE_SCORES)
5123 PlayMenuSoundIfLoop();
5126 void DrawChoosePlayerName(void)
5130 if (player_name != NULL)
5132 freeTreeInfo(player_name);
5137 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5139 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5140 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5143 ti->node_top = &player_name;
5144 ti->sort_priority = 10000 + value;
5145 ti->color = getPlayerNameColor(global.user_names[i]);
5147 snprintf(identifier, sizeof(identifier), "%d", value);
5148 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5150 setString(&ti->identifier, identifier);
5151 setString(&ti->name, name);
5152 setString(&ti->name_sorting, name);
5154 pushTreeInfo(&player_name, ti);
5157 // sort player entries by player number
5158 sortTreeInfo(&player_name);
5160 // set current player entry to selected player entry
5161 player_name_current =
5162 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5164 // if that fails, set current player name to first available name
5165 if (player_name_current == NULL)
5166 player_name_current = player_name;
5168 DrawChooseTree(&player_name_current);
5171 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5173 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5176 void DrawChooseLevelSet(void)
5178 DrawChooseTree(&leveldir_current);
5181 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5183 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5186 void DrawChooseLevelNr(void)
5190 if (level_number != NULL)
5192 freeTreeInfo(level_number);
5194 level_number = NULL;
5197 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5199 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5200 char identifier[32], name[64];
5203 // temporarily load level info to get level name
5204 LoadLevelInfoOnly(i);
5206 ti->node_top = &level_number;
5207 ti->sort_priority = 10000 + value;
5208 ti->color = (level.no_level_file ? FC_BLUE :
5209 LevelStats_getSolved(i) ? FC_GREEN :
5210 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5212 snprintf(identifier, sizeof(identifier), "%d", value);
5213 snprintf(name, sizeof(name), "%03d: %s", value,
5214 (level.no_level_file ? "(no file)" : level.name));
5216 setString(&ti->identifier, identifier);
5217 setString(&ti->name, name);
5218 setString(&ti->name_sorting, name);
5220 pushTreeInfo(&level_number, ti);
5223 // sort level number values to start with lowest level number
5224 sortTreeInfo(&level_number);
5226 // set current level number to current level number
5227 level_number_current =
5228 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5230 // if that also fails, set current level number to first available level
5231 if (level_number_current == NULL)
5232 level_number_current = level_number;
5234 DrawChooseTree(&level_number_current);
5237 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5239 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5242 static void DrawHallOfFame_setScoreEntries(void)
5244 int max_empty_entries = 10; // at least show "top ten" list, if empty
5245 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5246 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5247 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5250 if (score_entries != NULL)
5252 freeTreeInfo(score_entries);
5254 score_entries = NULL;
5257 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5259 // do not add empty score entries if off-screen
5260 if (scores.entry[i].score == 0 &&
5261 scores.entry[i].time == 0 &&
5262 i >= min_score_entries)
5265 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5266 char identifier[32], name[64];
5269 ti->node_top = &score_entries;
5270 ti->sort_priority = 10000 + value;
5271 ti->color = FC_YELLOW;
5274 snprintf(identifier, sizeof(identifier), "%d", value);
5275 snprintf(name, sizeof(name), "%03d.", value + 1);
5277 setString(&ti->identifier, identifier);
5278 setString(&ti->name, name);
5279 setString(&ti->name_sorting, name);
5281 pushTreeInfo(&score_entries, ti);
5284 // sort score entries to start with highest score entry
5285 sortTreeInfo(&score_entries);
5287 // add top tree node to create back link to main menu
5288 score_entries = addTopTreeInfoNode(score_entries);
5290 // set current score entry to last added or highest score entry
5291 score_entry_current =
5292 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5294 // if that fails, set current score entry to first valid score entry
5295 if (score_entry_current == NULL)
5296 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5298 // ("score_entries" and "score_entry_current" may be NULL here)
5301 void DrawHallOfFame(int level_nr)
5303 scores.last_level_nr = level_nr;
5305 // (this is needed when called from GameEnd() after winning a game)
5306 KeyboardAutoRepeatOn();
5308 // (this is needed when called from GameEnd() after winning a game)
5309 SetDrawDeactivationMask(REDRAW_NONE);
5310 SetDrawBackgroundMask(REDRAW_FIELD);
5312 LoadLocalAndServerScore(level_nr, TRUE);
5314 DrawHallOfFame_setScoreEntries();
5316 if (scores.last_added >= 0)
5317 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5319 FadeSetEnterScreen();
5321 DrawChooseTree(&score_entry_current);
5324 static char *getHallOfFameRankText(int nr, int size)
5326 static char rank_text[10];
5327 boolean forced = (scores.force_last_added && nr == scores.last_added);
5328 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5330 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5335 static char *getHallOfFameTimeText(int nr)
5337 static char score_text[10];
5338 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5339 int mm = (time_seconds / 60) % 60;
5340 int ss = (time_seconds % 60);
5342 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5347 static char *getHallOfFameScoreText(int nr, int size)
5349 if (!level.rate_time_over_score)
5350 return int2str(scores.entry[nr].score, size); // show normal score
5351 else if (level.use_step_counter)
5352 return int2str(scores.entry[nr].time, size); // show number of steps
5354 return getHallOfFameTimeText(nr); // show playing time
5357 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5359 static char tape_date[MAX_ISO_DATE_LEN + 1];
5362 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5363 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5364 return entry->tape_date;
5366 for (i = 0, j = 0; i < 8; i++, j++)
5368 tape_date[j] = entry->tape_basename[i];
5370 if (i == 3 || i == 5)
5371 tape_date[++j] = '-';
5374 tape_date[MAX_ISO_DATE_LEN] = '\0';
5379 static void HandleHallOfFame_SelectLevel(int step, int direction)
5381 int old_level_nr = scores.last_level_nr;
5382 int new_level_nr = old_level_nr + step * direction;
5384 if (new_level_nr < leveldir_current->first_level)
5385 new_level_nr = leveldir_current->first_level;
5386 if (new_level_nr > leveldir_current->last_level)
5387 new_level_nr = leveldir_current->last_level;
5389 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5390 new_level_nr = leveldir_current->handicap_level;
5392 if (new_level_nr != old_level_nr)
5394 PlaySound(SND_MENU_ITEM_SELECTING);
5396 scores.last_level_nr = level_nr = new_level_nr;
5397 scores.last_entry_nr = 0;
5399 LoadLevel(level_nr);
5400 LoadLocalAndServerScore(level_nr, TRUE);
5402 DrawHallOfFame_setScoreEntries();
5404 if (game_status == GAME_MODE_SCORES)
5406 // force remapping optional gadgets (especially scroll bar)
5407 UnmapScreenTreeGadgets();
5409 // redraw complete high score screen, as sub-title has changed
5412 // redraw level selection buttons (which have just been erased)
5413 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5415 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5419 DrawScoreInfo_Content(scores.last_entry_nr);
5422 SaveLevelSetup_SeriesInfo();
5426 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5428 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5431 static void DrawScoreInfo_Content(int entry_nr)
5433 struct ScoreEntry *entry = &scores.entry[entry_nr];
5434 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5435 char *tape_date = getHallOfFameTapeDateText(entry);
5436 int font_title = MENU_INFO_FONT_TITLE;
5437 int font_head = MENU_INFO_FONT_HEAD;
5438 int font_text = MENU_INFO_FONT_TEXT;
5439 int font_foot = MENU_INFO_FONT_FOOT;
5440 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5441 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5442 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5443 int xstep = getFontWidth(font_text);
5444 int ystep_title = getMenuTextStep(spacing_title, font_title);
5445 int ystep_para = getMenuTextStep(spacing_para, font_text);
5446 int ystep_line = getMenuTextStep(spacing_line, font_text);
5447 int xstart = mSX - SX + menu.left_spacing[GAME_MODE_SCOREINFO];
5448 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5449 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5450 int xstart1 = xstart + xstep;
5451 int xstart2 = xstart + xstep * 12;
5452 int select_x = SX + xstart1;
5453 int select_y1, select_y2;
5455 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5456 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5457 int font_width = getFontWidth(font_text);
5458 int font_height = getFontHeight(font_text);
5459 int tape_date_width = getTextWidth(tape_date, font_text);
5460 int pad_left = xstart2;
5461 int pad_right = menu.right_spacing[GAME_MODE_SCOREINFO];
5462 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5463 int max_lines_per_text = 5;
5468 // redraw level selection buttons (which have just been erased)
5469 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5471 if (score_entries == NULL)
5473 drawChooseTreeScreen_Scores_NotAvailable();
5478 drawChooseTreeHead(score_entries);
5479 drawChooseTreeInfo(score_entries);
5481 DrawTextSCentered(ystart, font_title, "Score Information:");
5482 ystart += ystep_title;
5484 DrawTextF(xstart1, ystart, font_head, "Level Set");
5485 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5486 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5487 TRUE, FALSE, FALSE);
5488 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5490 DrawTextF(xstart1, ystart, font_head, "Level");
5491 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5492 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5493 TRUE, FALSE, FALSE);
5494 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5496 select_y1 = SY + ystart;
5497 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5499 DrawTextF(xstart1, ystart, font_head, "Rank");
5500 DrawTextF(xstart2, ystart, font_text, pos_text);
5501 ystart += ystep_line;
5503 DrawTextF(xstart1, ystart, font_head, "Player");
5504 DrawTextF(xstart2, ystart, font_text, entry->name);
5505 ystart += ystep_line;
5507 if (level.use_step_counter)
5509 DrawTextF(xstart1, ystart, font_head, "Steps");
5510 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5511 ystart += ystep_line;
5515 DrawTextF(xstart1, ystart, font_head, "Time");
5516 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5517 ystart += ystep_line;
5520 if (!level.rate_time_over_score || entry->score > 0)
5522 DrawTextF(xstart1, ystart, font_head, "Score");
5523 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5524 ystart += ystep_line;
5527 ystart += ystep_line;
5529 play_x = SX + xstart2 + tape_date_width + font_width;
5530 play_y = SY + ystart + (font_height - play_height) / 2;
5532 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5533 DrawTextF(xstart2, ystart, font_text, tape_date);
5534 ystart += ystep_line;
5536 DrawTextF(xstart1, ystart, font_head, "Platform");
5537 DrawTextF(xstart2, ystart, font_text, entry->platform);
5538 ystart += ystep_line;
5540 DrawTextF(xstart1, ystart, font_head, "Version");
5541 DrawTextF(xstart2, ystart, font_text, entry->version);
5542 ystart += ystep_line;
5544 DrawTextF(xstart1, ystart, font_head, "Country");
5545 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5546 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5547 TRUE, FALSE, FALSE);
5548 ystart += ystep_line;
5550 select_y2 = SY + ystart;
5552 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5554 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5555 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5558 static void DrawScoreInfo(int entry_nr)
5560 scores.last_entry_nr = entry_nr;
5561 score_info_tape_play = FALSE;
5565 FreeScreenGadgets();
5566 CreateScreenGadgets();
5568 FadeOut(REDRAW_FIELD);
5570 // needed if different viewport properties defined after playing score tape
5571 ChangeViewportPropertiesIfNeeded();
5573 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
5574 SetDrawDeactivationMask(REDRAW_NONE);
5575 SetDrawBackgroundMask(REDRAW_FIELD);
5577 // needed if different background image defined after playing score tape
5578 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5579 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5581 // special compatibility handling for "Snake Bite" graphics set
5582 if (strPrefix(leveldir_current->identifier, "snake_bite"))
5583 ClearRectangle(gfx.background_bitmap, gfx.real_sx, gfx.real_sy + 64,
5584 gfx.full_sxsize, gfx.full_sysize - 64);
5586 DrawScoreInfo_Content(entry_nr);
5588 // map gadgets for score info screen
5589 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5591 FadeIn(REDRAW_FIELD);
5594 static void HandleScoreInfo_SelectScore(int step, int direction)
5596 int old_entry_nr = scores.last_entry_nr;
5597 int new_entry_nr = old_entry_nr + step * direction;
5598 int num_nodes = numTreeInfoInGroup(score_entry_current);
5599 int num_entries = num_nodes - 1; // score nodes only, without back link
5601 if (new_entry_nr < 0)
5603 if (new_entry_nr > num_entries - 1)
5604 new_entry_nr = num_entries - 1;
5606 if (new_entry_nr != old_entry_nr)
5608 scores.last_entry_nr = new_entry_nr;
5610 DrawScoreInfo_Content(new_entry_nr);
5614 static void HandleScoreInfo_PlayTape(void)
5616 if (!PlayScoreTape(scores.last_entry_nr))
5618 DrawScoreInfo_Content(scores.last_entry_nr);
5620 FadeIn(REDRAW_FIELD);
5624 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5626 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5627 boolean button_is_valid = (mx >= 0 && my >= 0);
5628 boolean button_screen_clicked = (button_action && button_is_valid);
5630 if (server_scores.updated)
5632 // reload scores, using updated server score cache file
5633 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5635 server_scores.updated = FALSE;
5637 DrawHallOfFame_setScoreEntries();
5639 DrawScoreInfo_Content(scores.last_entry_nr);
5642 if (button_screen_clicked)
5644 PlaySound(SND_MENU_ITEM_SELECTING);
5646 SetGameStatus(GAME_MODE_SCORES);
5648 DrawHallOfFame(scores.last_level_nr);
5652 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5656 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5661 // ============================================================================
5662 // setup screen functions
5663 // ============================================================================
5665 static struct TokenInfo *setup_info;
5666 static int num_setup_info; // number of setup entries shown on screen
5667 static int max_setup_info; // total number of setup entries in list
5669 static char *window_size_text;
5670 static char *scaling_type_text;
5671 static char *rendering_mode_text;
5672 static char *vsync_mode_text;
5673 static char *scroll_delay_text;
5674 static char *snapshot_mode_text;
5675 static char *game_speed_text;
5676 static char *scores_type_text;
5677 static char *network_server_text;
5678 static char *graphics_set_name;
5679 static char *sounds_set_name;
5680 static char *music_set_name;
5681 static char *volume_simple_text;
5682 static char *volume_loops_text;
5683 static char *volume_music_text;
5684 static char *touch_controls_text;
5685 static char *move_distance_text;
5686 static char *drop_distance_text;
5687 static char *transparency_text;
5688 static char *grid_size_text[2][2];
5690 static void execSetupMain(void)
5692 setup_mode = SETUP_MODE_MAIN;
5697 static void execSetupGame_setScoresType(void)
5699 if (scores_types == NULL)
5703 for (i = 0; scores_types_list[i].value != NULL; i++)
5705 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5706 char identifier[32], name[32];
5707 char *value = scores_types_list[i].value;
5708 char *text = scores_types_list[i].text;
5710 ti->node_top = &scores_types;
5711 ti->sort_priority = i;
5713 sprintf(identifier, "%s", value);
5714 sprintf(name, "%s", text);
5716 setString(&ti->identifier, identifier);
5717 setString(&ti->name, name);
5718 setString(&ti->name_sorting, name);
5719 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5721 pushTreeInfo(&scores_types, ti);
5724 // sort scores type values to start with lowest scores type value
5725 sortTreeInfo(&scores_types);
5727 // set current scores type value to configured scores type value
5728 scores_type_current =
5729 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5731 // if that fails, set current scores type to reliable default value
5732 if (scores_type_current == NULL)
5733 scores_type_current =
5734 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5736 // if that also fails, set current scores type to first available value
5737 if (scores_type_current == NULL)
5738 scores_type_current = scores_types;
5741 setup.scores_in_highscore_list = scores_type_current->identifier;
5743 // needed for displaying scores type text instead of identifier
5744 scores_type_text = scores_type_current->name;
5747 static void execSetupGame_setGameSpeeds(boolean update_value)
5749 if (setup.game_speed_extended)
5751 game_speeds_list = game_speeds_list_extended;
5752 game_speeds = game_speeds_extended;
5756 game_speeds_list = game_speeds_list_normal;
5757 game_speeds = game_speeds_normal;
5760 if (game_speeds == NULL)
5764 for (i = 0; game_speeds_list[i].value != -1; i++)
5766 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5767 char identifier[32], name[32];
5768 int value = game_speeds_list[i].value;
5769 char *text = game_speeds_list[i].text;
5771 ti->node_top = &game_speeds;
5772 ti->sort_priority = 10000 - value;
5774 sprintf(identifier, "%d", value);
5775 sprintf(name, "%s", text);
5777 setString(&ti->identifier, identifier);
5778 setString(&ti->name, name);
5779 setString(&ti->name_sorting, name);
5780 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5782 pushTreeInfo(&game_speeds, ti);
5785 // sort game speed values to start with slowest game speed
5786 sortTreeInfo(&game_speeds);
5788 update_value = TRUE;
5793 // set current game speed to configured game speed value
5794 game_speed_current =
5795 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5797 // if that fails, set current game speed to reliable default value
5798 if (game_speed_current == NULL)
5799 game_speed_current =
5800 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5802 // if that also fails, set current game speed to first available speed
5803 if (game_speed_current == NULL)
5804 game_speed_current = game_speeds;
5806 if (setup.game_speed_extended)
5807 game_speeds_extended = game_speeds;
5809 game_speeds_normal = game_speeds;
5812 setup.game_frame_delay = atoi(game_speed_current->identifier);
5814 // needed for displaying game speed text instead of identifier
5815 game_speed_text = game_speed_current->name;
5818 static void execSetupGame_setScrollDelays(void)
5820 if (scroll_delays == NULL)
5824 for (i = 0; scroll_delays_list[i].value != -1; i++)
5826 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5827 char identifier[32], name[32];
5828 int value = scroll_delays_list[i].value;
5829 char *text = scroll_delays_list[i].text;
5831 ti->node_top = &scroll_delays;
5832 ti->sort_priority = value;
5834 sprintf(identifier, "%d", value);
5835 sprintf(name, "%s", text);
5837 setString(&ti->identifier, identifier);
5838 setString(&ti->name, name);
5839 setString(&ti->name_sorting, name);
5840 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5842 pushTreeInfo(&scroll_delays, ti);
5845 // sort scroll delay values to start with lowest scroll delay value
5846 sortTreeInfo(&scroll_delays);
5848 // set current scroll delay value to configured scroll delay value
5849 scroll_delay_current =
5850 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5852 // if that fails, set current scroll delay to reliable default value
5853 if (scroll_delay_current == NULL)
5854 scroll_delay_current =
5855 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5857 // if that also fails, set current scroll delay to first available value
5858 if (scroll_delay_current == NULL)
5859 scroll_delay_current = scroll_delays;
5862 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5864 // needed for displaying scroll delay text instead of identifier
5865 scroll_delay_text = scroll_delay_current->name;
5868 static void execSetupGame_setSnapshotModes(void)
5870 if (snapshot_modes == NULL)
5874 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5876 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5877 char identifier[32], name[32];
5878 char *value = snapshot_modes_list[i].value;
5879 char *text = snapshot_modes_list[i].text;
5881 ti->node_top = &snapshot_modes;
5882 ti->sort_priority = i;
5884 sprintf(identifier, "%s", value);
5885 sprintf(name, "%s", text);
5887 setString(&ti->identifier, identifier);
5888 setString(&ti->name, name);
5889 setString(&ti->name_sorting, name);
5890 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5892 pushTreeInfo(&snapshot_modes, ti);
5895 // sort snapshot mode values to start with lowest snapshot mode value
5896 sortTreeInfo(&snapshot_modes);
5898 // set current snapshot mode value to configured snapshot mode value
5899 snapshot_mode_current =
5900 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5902 // if that fails, set current snapshot mode to reliable default value
5903 if (snapshot_mode_current == NULL)
5904 snapshot_mode_current =
5905 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5907 // if that also fails, set current snapshot mode to first available value
5908 if (snapshot_mode_current == NULL)
5909 snapshot_mode_current = snapshot_modes;
5912 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5914 // needed for displaying snapshot mode text instead of identifier
5915 snapshot_mode_text = snapshot_mode_current->name;
5918 static void execSetupGame_setNetworkServerText(void)
5920 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5922 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5926 strncpy(network_server_hostname, setup.network_server_hostname,
5927 MAX_SETUP_TEXT_INPUT_LEN);
5928 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5931 // needed for displaying network server text instead of identifier
5932 network_server_text = network_server_hostname;
5935 static void execSetupGame(void)
5937 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5939 execSetupGame_setGameSpeeds(FALSE);
5940 execSetupGame_setScoresType();
5941 execSetupGame_setScrollDelays();
5942 execSetupGame_setSnapshotModes();
5944 execSetupGame_setNetworkServerText();
5946 if (!setup.provide_uploading_tapes)
5947 setHideSetupEntry(execOfferUploadTapes);
5949 setup_mode = SETUP_MODE_GAME;
5953 // check if vsync needs to be disabled for this game speed to work
5954 if (check_vsync_mode)
5955 DisableVsyncIfNeeded();
5958 static void execSetupChooseScoresType(void)
5960 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
5965 static void execSetupChooseGameSpeed(void)
5967 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5972 static void execSetupChooseScrollDelay(void)
5974 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5979 static void execSetupChooseSnapshotMode(void)
5981 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5986 static void execSetupEngines(void)
5988 setup_mode = SETUP_MODE_ENGINES;
5993 static void execSetupEditor(void)
5995 setup_mode = SETUP_MODE_EDITOR;
6000 static void execSetupGraphics_setWindowSizes(boolean update_list)
6002 if (window_sizes != NULL && update_list)
6004 freeTreeInfo(window_sizes);
6006 window_sizes = NULL;
6009 if (window_sizes == NULL)
6011 boolean current_window_size_found = FALSE;
6014 for (i = 0; window_sizes_list[i].value != -1; i++)
6016 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6017 char identifier[32], name[32];
6018 int value = window_sizes_list[i].value;
6019 char *text = window_sizes_list[i].text;
6021 ti->node_top = &window_sizes;
6022 ti->sort_priority = value;
6024 sprintf(identifier, "%d", value);
6025 sprintf(name, "%s", text);
6027 setString(&ti->identifier, identifier);
6028 setString(&ti->name, name);
6029 setString(&ti->name_sorting, name);
6030 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6032 pushTreeInfo(&window_sizes, ti);
6034 if (value == setup.window_scaling_percent)
6035 current_window_size_found = TRUE;
6038 if (!current_window_size_found)
6040 // add entry for non-preset window scaling value
6042 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6043 char identifier[32], name[32];
6044 int value = setup.window_scaling_percent;
6046 ti->node_top = &window_sizes;
6047 ti->sort_priority = value;
6049 sprintf(identifier, "%d", value);
6050 sprintf(name, "%d %% (Current)", value);
6052 setString(&ti->identifier, identifier);
6053 setString(&ti->name, name);
6054 setString(&ti->name_sorting, name);
6055 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6057 pushTreeInfo(&window_sizes, ti);
6060 // sort window size values to start with lowest window size value
6061 sortTreeInfo(&window_sizes);
6063 // set current window size value to configured window size value
6064 window_size_current =
6065 getTreeInfoFromIdentifier(window_sizes,
6066 i_to_a(setup.window_scaling_percent));
6068 // if that fails, set current window size to reliable default value
6069 if (window_size_current == NULL)
6070 window_size_current =
6071 getTreeInfoFromIdentifier(window_sizes,
6072 i_to_a(STD_WINDOW_SCALING_PERCENT));
6074 // if that also fails, set current window size to first available value
6075 if (window_size_current == NULL)
6076 window_size_current = window_sizes;
6079 setup.window_scaling_percent = atoi(window_size_current->identifier);
6081 // needed for displaying window size text instead of identifier
6082 window_size_text = window_size_current->name;
6085 static void execSetupGraphics_setScalingTypes(void)
6087 if (scaling_types == NULL)
6091 for (i = 0; scaling_types_list[i].value != NULL; i++)
6093 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6094 char identifier[32], name[32];
6095 char *value = scaling_types_list[i].value;
6096 char *text = scaling_types_list[i].text;
6098 ti->node_top = &scaling_types;
6099 ti->sort_priority = i;
6101 sprintf(identifier, "%s", value);
6102 sprintf(name, "%s", text);
6104 setString(&ti->identifier, identifier);
6105 setString(&ti->name, name);
6106 setString(&ti->name_sorting, name);
6107 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6109 pushTreeInfo(&scaling_types, ti);
6112 // sort scaling type values to start with lowest scaling type value
6113 sortTreeInfo(&scaling_types);
6115 // set current scaling type value to configured scaling type value
6116 scaling_type_current =
6117 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6119 // if that fails, set current scaling type to reliable default value
6120 if (scaling_type_current == NULL)
6121 scaling_type_current =
6122 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6124 // if that also fails, set current scaling type to first available value
6125 if (scaling_type_current == NULL)
6126 scaling_type_current = scaling_types;
6129 setup.window_scaling_quality = scaling_type_current->identifier;
6131 // needed for displaying scaling type text instead of identifier
6132 scaling_type_text = scaling_type_current->name;
6135 static void execSetupGraphics_setRenderingModes(void)
6137 if (rendering_modes == NULL)
6141 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6143 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6144 char identifier[32], name[32];
6145 char *value = rendering_modes_list[i].value;
6146 char *text = rendering_modes_list[i].text;
6148 ti->node_top = &rendering_modes;
6149 ti->sort_priority = i;
6151 sprintf(identifier, "%s", value);
6152 sprintf(name, "%s", text);
6154 setString(&ti->identifier, identifier);
6155 setString(&ti->name, name);
6156 setString(&ti->name_sorting, name);
6157 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6159 pushTreeInfo(&rendering_modes, ti);
6162 // sort rendering mode values to start with lowest rendering mode value
6163 sortTreeInfo(&rendering_modes);
6165 // set current rendering mode value to configured rendering mode value
6166 rendering_mode_current =
6167 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6169 // if that fails, set current rendering mode to reliable default value
6170 if (rendering_mode_current == NULL)
6171 rendering_mode_current =
6172 getTreeInfoFromIdentifier(rendering_modes,
6173 STR_SPECIAL_RENDERING_DEFAULT);
6175 // if that also fails, set current rendering mode to first available one
6176 if (rendering_mode_current == NULL)
6177 rendering_mode_current = rendering_modes;
6180 setup.screen_rendering_mode = rendering_mode_current->identifier;
6182 // needed for displaying rendering mode text instead of identifier
6183 rendering_mode_text = rendering_mode_current->name;
6186 static void execSetupGraphics_setVsyncModes(boolean update_value)
6188 if (vsync_modes == NULL)
6192 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6194 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6195 char identifier[32], name[32];
6196 char *value = vsync_modes_list[i].value;
6197 char *text = vsync_modes_list[i].text;
6199 ti->node_top = &vsync_modes;
6200 ti->sort_priority = i;
6202 sprintf(identifier, "%s", value);
6203 sprintf(name, "%s", text);
6205 setString(&ti->identifier, identifier);
6206 setString(&ti->name, name);
6207 setString(&ti->name_sorting, name);
6208 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6210 pushTreeInfo(&vsync_modes, ti);
6213 // sort vsync mode values to start with lowest vsync mode value
6214 sortTreeInfo(&vsync_modes);
6216 update_value = TRUE;
6221 // set current vsync mode value to configured vsync mode value
6222 vsync_mode_current =
6223 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6225 // if that fails, set current vsync mode to reliable default value
6226 if (vsync_mode_current == NULL)
6227 vsync_mode_current =
6228 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6230 // if that also fails, set current vsync mode to first available one
6231 if (vsync_mode_current == NULL)
6232 vsync_mode_current = vsync_modes;
6235 setup.vsync_mode = vsync_mode_current->identifier;
6237 // needed for displaying vsync mode text instead of identifier
6238 vsync_mode_text = vsync_mode_current->name;
6241 static void execSetupGraphics(void)
6243 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6245 // update "setup.window_scaling_percent" from list selection
6246 // (in this case, window scaling was changed on setup screen)
6247 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6248 execSetupGraphics_setWindowSizes(FALSE);
6250 // update "setup.vsync_mode" from list selection
6251 // (in this case, vsync mode was changed on setup screen)
6252 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6253 execSetupGraphics_setVsyncModes(FALSE);
6255 // update list selection from "setup.window_scaling_percent"
6256 // (window scaling may have changed by resizing the window)
6257 execSetupGraphics_setWindowSizes(TRUE);
6259 // update list selection from "setup.vsync_mode"
6260 // (vsync_mode may have changed by re-creating the renderer)
6261 execSetupGraphics_setVsyncModes(TRUE);
6263 execSetupGraphics_setScalingTypes();
6264 execSetupGraphics_setRenderingModes();
6266 setup_mode = SETUP_MODE_GRAPHICS;
6270 // check if game speed is high enough for 60 Hz vsync to work
6271 if (check_game_speed)
6272 ModifyGameSpeedIfNeeded();
6274 // window scaling may have changed at this point
6275 ChangeWindowScalingIfNeeded();
6277 // window scaling quality may have changed at this point
6278 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6279 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6281 // screen rendering mode may have changed at this point
6282 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6284 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6285 int video_vsync_mode = video.vsync_mode;
6287 // screen vsync mode may have changed at this point
6288 ChangeVsyncModeIfNeeded();
6290 // check if setting vsync mode to selected value failed
6291 if (setup_vsync_mode != video_vsync_mode &&
6292 setup_vsync_mode != video.vsync_mode)
6294 // changing vsync mode to selected value failed -- reset displayed value
6295 execSetupGraphics_setVsyncModes(TRUE);
6297 Request("Setting VSync failed!", REQ_CONFIRM);
6303 static void execSetupChooseWindowSize(void)
6305 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6310 static void execSetupChooseScalingType(void)
6312 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6317 static void execSetupChooseRenderingMode(void)
6319 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6324 static void execSetupChooseVsyncMode(void)
6326 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6331 static void execSetupChooseVolumeSimple(void)
6333 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6338 static void execSetupChooseVolumeLoops(void)
6340 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6345 static void execSetupChooseVolumeMusic(void)
6347 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6352 static void execSetupSound(void)
6354 if (volumes_simple == NULL)
6356 boolean current_volume_simple_found = FALSE;
6359 for (i = 0; volumes_list[i].value != -1; i++)
6361 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6362 char identifier[32], name[32];
6363 int value = volumes_list[i].value;
6364 char *text = volumes_list[i].text;
6366 ti->node_top = &volumes_simple;
6367 ti->sort_priority = value;
6369 sprintf(identifier, "%d", value);
6370 sprintf(name, "%s", text);
6372 setString(&ti->identifier, identifier);
6373 setString(&ti->name, name);
6374 setString(&ti->name_sorting, name);
6375 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6377 pushTreeInfo(&volumes_simple, ti);
6379 if (value == setup.volume_simple)
6380 current_volume_simple_found = TRUE;
6383 if (!current_volume_simple_found)
6385 // add entry for non-preset volume value
6387 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6388 char identifier[32], name[32];
6389 int value = setup.volume_simple;
6391 ti->node_top = &volumes_simple;
6392 ti->sort_priority = value;
6394 sprintf(identifier, "%d", value);
6395 sprintf(name, "%d %% (Current)", value);
6397 setString(&ti->identifier, identifier);
6398 setString(&ti->name, name);
6399 setString(&ti->name_sorting, name);
6400 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6402 pushTreeInfo(&volumes_simple, ti);
6405 // sort volume values to start with lowest volume value
6406 sortTreeInfo(&volumes_simple);
6408 // set current volume value to configured volume value
6409 volume_simple_current =
6410 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6412 // if that fails, set current volume to reliable default value
6413 if (volume_simple_current == NULL)
6414 volume_simple_current =
6415 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6417 // if that also fails, set current volume to first available value
6418 if (volume_simple_current == NULL)
6419 volume_simple_current = volumes_simple;
6422 if (volumes_loops == NULL)
6424 boolean current_volume_loops_found = FALSE;
6427 for (i = 0; volumes_list[i].value != -1; i++)
6429 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6430 char identifier[32], name[32];
6431 int value = volumes_list[i].value;
6432 char *text = volumes_list[i].text;
6434 ti->node_top = &volumes_loops;
6435 ti->sort_priority = value;
6437 sprintf(identifier, "%d", value);
6438 sprintf(name, "%s", text);
6440 setString(&ti->identifier, identifier);
6441 setString(&ti->name, name);
6442 setString(&ti->name_sorting, name);
6443 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6445 pushTreeInfo(&volumes_loops, ti);
6447 if (value == setup.volume_loops)
6448 current_volume_loops_found = TRUE;
6451 if (!current_volume_loops_found)
6453 // add entry for non-preset volume value
6455 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6456 char identifier[32], name[32];
6457 int value = setup.volume_loops;
6459 ti->node_top = &volumes_loops;
6460 ti->sort_priority = value;
6462 sprintf(identifier, "%d", value);
6463 sprintf(name, "%d %% (Current)", value);
6465 setString(&ti->identifier, identifier);
6466 setString(&ti->name, name);
6467 setString(&ti->name_sorting, name);
6468 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6470 pushTreeInfo(&volumes_loops, ti);
6473 // sort volume values to start with lowest volume value
6474 sortTreeInfo(&volumes_loops);
6476 // set current volume value to configured volume value
6477 volume_loops_current =
6478 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6480 // if that fails, set current volume to reliable default value
6481 if (volume_loops_current == NULL)
6482 volume_loops_current =
6483 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6485 // if that also fails, set current volume to first available value
6486 if (volume_loops_current == NULL)
6487 volume_loops_current = volumes_loops;
6490 if (volumes_music == NULL)
6492 boolean current_volume_music_found = FALSE;
6495 for (i = 0; volumes_list[i].value != -1; i++)
6497 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6498 char identifier[32], name[32];
6499 int value = volumes_list[i].value;
6500 char *text = volumes_list[i].text;
6502 ti->node_top = &volumes_music;
6503 ti->sort_priority = value;
6505 sprintf(identifier, "%d", value);
6506 sprintf(name, "%s", text);
6508 setString(&ti->identifier, identifier);
6509 setString(&ti->name, name);
6510 setString(&ti->name_sorting, name);
6511 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6513 pushTreeInfo(&volumes_music, ti);
6515 if (value == setup.volume_music)
6516 current_volume_music_found = TRUE;
6519 if (!current_volume_music_found)
6521 // add entry for non-preset volume value
6523 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6524 char identifier[32], name[32];
6525 int value = setup.volume_music;
6527 ti->node_top = &volumes_music;
6528 ti->sort_priority = value;
6530 sprintf(identifier, "%d", value);
6531 sprintf(name, "%d %% (Current)", value);
6533 setString(&ti->identifier, identifier);
6534 setString(&ti->name, name);
6535 setString(&ti->name_sorting, name);
6536 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6538 pushTreeInfo(&volumes_music, ti);
6541 // sort volume values to start with lowest volume value
6542 sortTreeInfo(&volumes_music);
6544 // set current volume value to configured volume value
6545 volume_music_current =
6546 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6548 // if that fails, set current volume to reliable default value
6549 if (volume_music_current == NULL)
6550 volume_music_current =
6551 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6553 // if that also fails, set current volume to first available value
6554 if (volume_music_current == NULL)
6555 volume_music_current = volumes_music;
6558 setup.volume_simple = atoi(volume_simple_current->identifier);
6559 setup.volume_loops = atoi(volume_loops_current->identifier);
6560 setup.volume_music = atoi(volume_music_current->identifier);
6562 // needed for displaying volume text instead of identifier
6563 volume_simple_text = volume_simple_current->name;
6564 volume_loops_text = volume_loops_current->name;
6565 volume_music_text = volume_music_current->name;
6567 setup_mode = SETUP_MODE_SOUND;
6572 static void execSetupChooseTouchControls(void)
6574 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6579 static void execSetupChooseMoveDistance(void)
6581 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6586 static void execSetupChooseDropDistance(void)
6588 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6593 static void execSetupChooseTransparency(void)
6595 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6600 static void execSetupChooseGridXSize_0(void)
6602 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6607 static void execSetupChooseGridYSize_0(void)
6609 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6614 static void execSetupChooseGridXSize_1(void)
6616 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6621 static void execSetupChooseGridYSize_1(void)
6623 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6628 static void execSetupConfigureVirtualButtons(void)
6630 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6632 ConfigureVirtualButtons();
6634 setup_mode = SETUP_MODE_TOUCH;
6639 static void execSetupTouch(void)
6643 if (touch_controls == NULL)
6645 for (i = 0; touch_controls_list[i].value != NULL; i++)
6647 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6648 char identifier[32], name[32];
6649 char *value = touch_controls_list[i].value;
6650 char *text = touch_controls_list[i].text;
6652 ti->node_top = &touch_controls;
6653 ti->sort_priority = i;
6655 sprintf(identifier, "%s", value);
6656 sprintf(name, "%s", text);
6658 setString(&ti->identifier, identifier);
6659 setString(&ti->name, name);
6660 setString(&ti->name_sorting, name);
6661 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6663 pushTreeInfo(&touch_controls, ti);
6666 // sort touch control values to start with lowest touch control value
6667 sortTreeInfo(&touch_controls);
6669 // set current touch control value to configured touch control value
6670 touch_control_current =
6671 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6673 // if that fails, set current touch control to reliable default value
6674 if (touch_control_current == NULL)
6675 touch_control_current =
6676 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6678 // if that also fails, set current touch control to first available value
6679 if (touch_control_current == NULL)
6680 touch_control_current = touch_controls;
6683 if (move_distances == NULL)
6685 for (i = 0; distances_list[i].value != -1; i++)
6687 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6688 char identifier[32], name[32];
6689 int value = distances_list[i].value;
6690 char *text = distances_list[i].text;
6692 ti->node_top = &move_distances;
6693 ti->sort_priority = value;
6695 sprintf(identifier, "%d", value);
6696 sprintf(name, "%s", text);
6698 setString(&ti->identifier, identifier);
6699 setString(&ti->name, name);
6700 setString(&ti->name_sorting, name);
6701 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6703 pushTreeInfo(&move_distances, ti);
6706 // sort distance values to start with lowest distance value
6707 sortTreeInfo(&move_distances);
6709 // set current distance value to configured distance value
6710 move_distance_current =
6711 getTreeInfoFromIdentifier(move_distances,
6712 i_to_a(setup.touch.move_distance));
6714 // if that fails, set current distance to reliable default value
6715 if (move_distance_current == NULL)
6716 move_distance_current =
6717 getTreeInfoFromIdentifier(move_distances,
6718 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6720 // if that also fails, set current distance to first available value
6721 if (move_distance_current == NULL)
6722 move_distance_current = move_distances;
6725 if (drop_distances == NULL)
6727 for (i = 0; distances_list[i].value != -1; i++)
6729 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6730 char identifier[32], name[32];
6731 int value = distances_list[i].value;
6732 char *text = distances_list[i].text;
6734 ti->node_top = &drop_distances;
6735 ti->sort_priority = value;
6737 sprintf(identifier, "%d", value);
6738 sprintf(name, "%s", text);
6740 setString(&ti->identifier, identifier);
6741 setString(&ti->name, name);
6742 setString(&ti->name_sorting, name);
6743 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6745 pushTreeInfo(&drop_distances, ti);
6748 // sort distance values to start with lowest distance value
6749 sortTreeInfo(&drop_distances);
6751 // set current distance value to configured distance value
6752 drop_distance_current =
6753 getTreeInfoFromIdentifier(drop_distances,
6754 i_to_a(setup.touch.drop_distance));
6756 // if that fails, set current distance to reliable default value
6757 if (drop_distance_current == NULL)
6758 drop_distance_current =
6759 getTreeInfoFromIdentifier(drop_distances,
6760 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6762 // if that also fails, set current distance to first available value
6763 if (drop_distance_current == NULL)
6764 drop_distance_current = drop_distances;
6767 if (transparencies == NULL)
6769 for (i = 0; transparencies_list[i].value != -1; i++)
6771 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6772 char identifier[32], name[32];
6773 int value = transparencies_list[i].value;
6774 char *text = transparencies_list[i].text;
6776 ti->node_top = &transparencies;
6777 ti->sort_priority = value;
6779 sprintf(identifier, "%d", value);
6780 sprintf(name, "%s", text);
6782 setString(&ti->identifier, identifier);
6783 setString(&ti->name, name);
6784 setString(&ti->name_sorting, name);
6785 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6787 pushTreeInfo(&transparencies, ti);
6790 // sort transparency values to start with lowest transparency value
6791 sortTreeInfo(&transparencies);
6793 // set current transparency value to configured transparency value
6794 transparency_current =
6795 getTreeInfoFromIdentifier(transparencies,
6796 i_to_a(setup.touch.transparency));
6798 // if that fails, set current transparency to reliable default value
6799 if (transparency_current == NULL)
6800 transparency_current =
6801 getTreeInfoFromIdentifier(transparencies,
6802 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6804 // if that also fails, set current transparency to first available value
6805 if (transparency_current == NULL)
6806 transparency_current = transparencies;
6809 for (i = 0; i < 2; i++)
6811 for (j = 0; j < 2; j++)
6813 if (grid_sizes[i][j] == NULL)
6815 for (k = 0; grid_sizes_list[k].value != -1; k++)
6817 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6818 char identifier[32], name[32];
6819 int value = grid_sizes_list[k].value;
6820 char *text = grid_sizes_list[k].text;
6822 ti->node_top = &grid_sizes[i][j];
6823 ti->sort_priority = value;
6825 sprintf(identifier, "%d", value);
6826 sprintf(name, "%s", text);
6828 setString(&ti->identifier, identifier);
6829 setString(&ti->name, name);
6830 setString(&ti->name_sorting, name);
6831 setString(&ti->infotext,
6834 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6835 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6837 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6838 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6840 pushTreeInfo(&grid_sizes[i][j], ti);
6843 // sort grid size values to start with lowest grid size value
6844 sortTreeInfo(&grid_sizes[i][j]);
6846 // set current grid size value to configured grid size value
6847 grid_size_current[i][j] =
6848 getTreeInfoFromIdentifier(grid_sizes[i][j],
6850 setup.touch.grid_xsize[i] :
6851 setup.touch.grid_ysize[i]));
6853 // if that fails, set current grid size to reliable default value
6854 if (grid_size_current[i][j] == NULL)
6855 grid_size_current[i][j] =
6856 getTreeInfoFromIdentifier(grid_sizes[i][j],
6858 DEFAULT_GRID_XSIZE(i) :
6859 DEFAULT_GRID_YSIZE(i)));
6861 // if that also fails, set current grid size to first available value
6862 if (grid_size_current[i][j] == NULL)
6863 grid_size_current[i][j] = grid_sizes[i][j];
6868 setup.touch.control_type = touch_control_current->identifier;
6869 setup.touch.move_distance = atoi(move_distance_current->identifier);
6870 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6871 setup.touch.transparency = atoi(transparency_current->identifier);
6873 for (i = 0; i < 2; i++)
6875 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6876 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6878 if (i == GRID_ACTIVE_NR())
6880 overlay.grid_xsize = setup.touch.grid_xsize[i];
6881 overlay.grid_ysize = setup.touch.grid_ysize[i];
6885 // needed for displaying value text instead of identifier
6886 touch_controls_text = touch_control_current->name;
6887 move_distance_text = move_distance_current->name;
6888 drop_distance_text = drop_distance_current->name;
6889 transparency_text = transparency_current->name;
6891 for (i = 0; i < 2; i++)
6892 for (j = 0; j < 2; j++)
6893 grid_size_text[i][j] = grid_size_current[i][j]->name;
6895 setup_mode = SETUP_MODE_TOUCH;
6900 static void execSetupArtwork(void)
6902 static ArtworkDirTree *gfx_last_valid = NULL;
6903 static ArtworkDirTree *snd_last_valid = NULL;
6904 static ArtworkDirTree *mus_last_valid = NULL;
6906 // current artwork directory may be invalid (level group, parent link)
6907 if (!validLevelSeries(artwork.gfx_current))
6908 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6909 if (!validLevelSeries(artwork.snd_current))
6910 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6911 if (!validLevelSeries(artwork.mus_current))
6912 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6914 // store valid artwork directory information
6915 gfx_last_valid = artwork.gfx_current;
6916 snd_last_valid = artwork.snd_current;
6917 mus_last_valid = artwork.mus_current;
6920 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6921 artwork.gfx_current->subdir,
6922 artwork.gfx_current->fullpath,
6923 artwork.gfx_current->basepath);
6926 setup.graphics_set = artwork.gfx_current->identifier;
6927 setup.sounds_set = artwork.snd_current->identifier;
6928 setup.music_set = artwork.mus_current->identifier;
6930 // needed if last screen (setup choice) changed graphics, sounds or music
6931 ReloadCustomArtwork(0);
6933 // needed for displaying artwork name instead of artwork identifier
6934 graphics_set_name = artwork.gfx_current->name;
6935 sounds_set_name = artwork.snd_current->name;
6936 music_set_name = artwork.mus_current->name;
6938 setup_mode = SETUP_MODE_ARTWORK;
6943 static void execSetupChooseGraphics(void)
6945 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6950 static void execSetupChooseSounds(void)
6952 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6957 static void execSetupChooseMusic(void)
6959 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6964 static void execSetupInput(void)
6966 setup_mode = SETUP_MODE_INPUT;
6971 static void execSetupShortcuts(void)
6973 setup_mode = SETUP_MODE_SHORTCUTS;
6978 static void execSetupShortcuts1(void)
6980 setup_mode = SETUP_MODE_SHORTCUTS_1;
6985 static void execSetupShortcuts2(void)
6987 setup_mode = SETUP_MODE_SHORTCUTS_2;
6992 static void execSetupShortcuts3(void)
6994 setup_mode = SETUP_MODE_SHORTCUTS_3;
6999 static void execSetupShortcuts4(void)
7001 setup_mode = SETUP_MODE_SHORTCUTS_4;
7006 static void execSetupShortcuts5(void)
7008 setup_mode = SETUP_MODE_SHORTCUTS_5;
7013 static void execExitSetup(void)
7015 SetGameStatus(GAME_MODE_MAIN);
7020 static void execSaveAndExitSetup(void)
7026 static void execGadgetNetworkServer(void)
7028 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7029 struct GadgetInfo *gi = screen_gadget[gadget_id];
7031 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7032 network_server_hostname[0] = '\0';
7034 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7038 ClickOnGadget(gi, MB_LEFTBUTTON);
7041 static void execOfferUploadTapes(void)
7046 static void ToggleNetworkModeIfNeeded(void)
7048 int font_title = FONT_TITLE_1;
7049 int font_foot = FC_BLUE;
7050 int ystart = mSY - SY + 16;
7051 int ybottom = mSY - SY + SYSIZE - 20;
7052 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7054 if (setup.network_mode == network.enabled)
7057 network.enabled = setup.network_mode;
7059 FadeOut(REDRAW_ALL);
7063 DrawTextSCentered(ystart, font_title, text);
7067 if (network.enabled)
7068 InitNetworkServer();
7070 DisconnectFromNetworkServer();
7072 DrawTextSCentered(ybottom, font_foot,
7073 "Press any key or button for setup menu");
7075 WaitForEventToContinue();
7080 static void ToggleGameSpeedsListIfNeeded(void)
7082 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7084 if (setup.game_speed_extended == using_game_speeds_extended)
7087 // try to match similar values when changing game speeds list
7088 if (setup.game_speed_extended)
7089 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7090 setup.game_frame_delay == 30 ? 29 :
7091 setup.game_frame_delay);
7093 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7094 setup.game_frame_delay == 16 ? 15 :
7095 setup.game_frame_delay >= 29 ? 30 :
7096 setup.game_frame_delay <= 10 ? 10 :
7097 setup.game_frame_delay);
7099 execSetupGame_setGameSpeeds(TRUE);
7104 static void ToggleUseApiServerIfNeeded(void)
7106 if (runtime.use_api_server == setup.use_api_server)
7109 runtime.use_api_server = setup.use_api_server;
7111 if (runtime.use_api_server)
7112 CheckApiServerTasks();
7115 static void ModifyGameSpeedIfNeeded(void)
7117 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7118 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7122 char *game_speed_text = "Fast";
7123 int game_speed_value = 15;
7125 if (setup.game_speed_extended)
7127 game_speed_text = "60 fps";
7128 game_speed_value = 16;
7131 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7133 // set game speed to existing list value that is fast enough for vsync
7134 setup.game_frame_delay = game_speed_value;
7136 execSetupGame_setGameSpeeds(TRUE);
7138 Request(message, REQ_CONFIRM);
7141 static void DisableVsyncIfNeeded(void)
7143 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7144 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7145 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7148 // disable vsync for the selected game speed to work
7149 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7151 execSetupGraphics_setVsyncModes(TRUE);
7153 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7159 void *related_value;
7160 } hide_related_entry_list[] =
7162 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7163 { &setup.scores_in_highscore_list, &scores_type_text },
7165 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7166 { &setup.game_frame_delay, &game_speed_text },
7168 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7169 { &setup.scroll_delay_value, &scroll_delay_text },
7171 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7172 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7174 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7175 { &setup.window_scaling_percent, &window_size_text },
7177 { &setup.window_scaling_quality, execSetupChooseScalingType },
7178 { &setup.window_scaling_quality, &scaling_type_text },
7180 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7181 { &setup.screen_rendering_mode, &rendering_mode_text },
7183 { &setup.vsync_mode, execSetupChooseVsyncMode },
7184 { &setup.vsync_mode, &vsync_mode_text },
7186 { &setup.graphics_set, execSetupChooseGraphics },
7187 { &setup.graphics_set, &graphics_set_name },
7189 { &setup.sounds_set, execSetupChooseSounds },
7190 { &setup.sounds_set, &sounds_set_name },
7192 { &setup.music_set, execSetupChooseMusic },
7193 { &setup.music_set, &music_set_name },
7195 { &setup.volume_simple, execSetupChooseVolumeSimple },
7196 { &setup.volume_simple, &volume_simple_text },
7198 { &setup.volume_loops, execSetupChooseVolumeLoops },
7199 { &setup.volume_loops, &volume_loops_text },
7201 { &setup.volume_music, execSetupChooseVolumeMusic },
7202 { &setup.volume_music, &volume_music_text },
7204 { &setup.touch.control_type, execSetupChooseTouchControls },
7205 { &setup.touch.control_type, &touch_controls_text },
7207 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7208 { &setup.touch.move_distance, &move_distance_text },
7210 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7211 { &setup.touch.drop_distance, &drop_distance_text },
7213 { &setup.touch.transparency, execSetupChooseTransparency },
7214 { &setup.touch.transparency, &transparency_text },
7216 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7217 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7219 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7220 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7222 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7223 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7225 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7226 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7228 { &setup.internal.menu_game, execSetupGame },
7229 { &setup.internal.menu_engines, execSetupEngines },
7230 { &setup.internal.menu_editor, execSetupEditor },
7231 { &setup.internal.menu_graphics, execSetupGraphics },
7232 { &setup.internal.menu_sound, execSetupSound },
7233 { &setup.internal.menu_artwork, execSetupArtwork },
7234 { &setup.internal.menu_input, execSetupInput },
7235 { &setup.internal.menu_touch, execSetupTouch },
7236 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7237 { &setup.internal.menu_exit, execExitSetup },
7238 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7240 { &setup.internal.info_title, execInfoTitleScreen },
7241 { &setup.internal.info_elements, execInfoElements },
7242 { &setup.internal.info_music, execInfoMusic },
7243 { &setup.internal.info_credits, execInfoCredits },
7244 { &setup.internal.info_program, execInfoProgram },
7245 { &setup.internal.info_version, execInfoVersion },
7246 { &setup.internal.info_levelset, execInfoLevelSet },
7247 { &setup.internal.info_exit, execExitInfo },
7252 void setHideRelatedSetupEntries(void)
7256 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7257 if (hideSetupEntry(hide_related_entry_list[i].value))
7258 setHideSetupEntry(hide_related_entry_list[i].related_value);
7261 static struct TokenInfo setup_info_main[] =
7263 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7264 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7265 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7266 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7267 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7268 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7269 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7270 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7271 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7272 { TYPE_EMPTY, NULL, "" },
7273 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7274 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7279 static struct TokenInfo setup_info_game[] =
7281 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7282 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7283 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7284 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7285 { TYPE_STRING, &network_server_text, "" },
7286 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7287 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7288 { TYPE_STRING, &scores_type_text, "" },
7289 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7290 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7291 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7292 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7293 { TYPE_SWITCH, &setup.handicap, "Force Solving Levels:" },
7294 { TYPE_SWITCH, &setup.skip_levels, "Allow Skipping Levels:" },
7295 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7296 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7297 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7298 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7299 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7300 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7301 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7302 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7303 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7304 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7305 { TYPE_STRING, &game_speed_text, "" },
7306 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7308 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7309 { TYPE_STRING, &scroll_delay_text, "" },
7311 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7312 { TYPE_STRING, &snapshot_mode_text, "" },
7313 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7314 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7315 { TYPE_EMPTY, NULL, "" },
7316 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7321 static struct TokenInfo setup_info_engines[] =
7323 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7324 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7325 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7326 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7327 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7328 { TYPE_EMPTY, NULL, "" },
7329 { TYPE_HEADLINE, NULL, "Supaplex" },
7330 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7331 { TYPE_EMPTY, NULL, "" },
7332 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7337 static struct TokenInfo setup_info_editor[] =
7340 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7341 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7342 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7343 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7344 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7345 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7346 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7347 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7348 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7349 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7351 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7352 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7354 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7356 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7357 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7358 { TYPE_EMPTY, NULL, "" },
7360 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7361 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7362 { TYPE_EMPTY, NULL, "" },
7364 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7365 { TYPE_EMPTY, NULL, "" },
7366 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7367 { TYPE_EMPTY, NULL, "" },
7368 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7373 static struct TokenInfo setup_info_graphics[] =
7375 #if !defined(PLATFORM_ANDROID)
7376 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7377 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7378 { TYPE_STRING, &window_size_text, "" },
7379 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7380 { TYPE_STRING, &scaling_type_text, "" },
7381 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7382 { TYPE_STRING, &rendering_mode_text, "" },
7385 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7386 { TYPE_STRING, &scroll_delay_text, "" },
7388 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7389 { TYPE_STRING, &vsync_mode_text, "" },
7390 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7391 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7392 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7393 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7394 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7395 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7396 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7397 { TYPE_EMPTY, NULL, "" },
7398 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7403 static struct TokenInfo setup_info_sound[] =
7405 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7406 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7407 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7408 { TYPE_EMPTY, NULL, "" },
7409 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7410 { TYPE_STRING, &volume_simple_text, "" },
7411 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7412 { TYPE_STRING, &volume_loops_text, "" },
7413 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7414 { TYPE_STRING, &volume_music_text, "" },
7415 { TYPE_EMPTY, NULL, "" },
7416 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7421 static struct TokenInfo setup_info_artwork[] =
7423 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7424 { TYPE_STRING, &graphics_set_name, "" },
7425 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7426 { TYPE_STRING, &sounds_set_name, "" },
7427 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7428 { TYPE_STRING, &music_set_name, "" },
7429 { TYPE_EMPTY, NULL, "" },
7430 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7431 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7432 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7433 { TYPE_EMPTY, NULL, "" },
7434 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7439 static struct TokenInfo setup_info_input[] =
7441 { TYPE_SWITCH, NULL, "Player:" },
7442 { TYPE_SWITCH, NULL, "Device:" },
7443 { TYPE_SWITCH, NULL, "" },
7444 { TYPE_SKIPPABLE, NULL, "" },
7445 { TYPE_EMPTY, NULL, "" },
7446 { TYPE_EMPTY, NULL, "" },
7447 { TYPE_EMPTY, NULL, "" },
7448 { TYPE_EMPTY, NULL, "" },
7449 { TYPE_EMPTY, NULL, "" },
7450 { TYPE_EMPTY, NULL, "" },
7451 { TYPE_EMPTY, NULL, "" },
7452 { TYPE_EMPTY, NULL, "" },
7453 { TYPE_SKIPPABLE, NULL, "" },
7454 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7459 static struct TokenInfo setup_info_touch[] =
7461 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7462 { TYPE_STRING, &touch_controls_text, "" },
7463 { TYPE_EMPTY, NULL, "" },
7464 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7469 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7471 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7472 { TYPE_STRING, &touch_controls_text, "" },
7473 { TYPE_EMPTY, NULL, "" },
7474 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7475 { TYPE_STRING, &grid_size_text[0][0], "" },
7476 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7477 { TYPE_STRING, &grid_size_text[0][1], "" },
7478 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7479 { TYPE_STRING, &transparency_text, "" },
7480 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7481 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7482 { TYPE_EMPTY, NULL, "" },
7483 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7484 { TYPE_EMPTY, NULL, "" },
7485 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7490 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7492 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7493 { TYPE_STRING, &touch_controls_text, "" },
7494 { TYPE_EMPTY, NULL, "" },
7495 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7496 { TYPE_STRING, &grid_size_text[1][0], "" },
7497 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7498 { TYPE_STRING, &grid_size_text[1][1], "" },
7499 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7500 { TYPE_STRING, &transparency_text, "" },
7501 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7502 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7503 { TYPE_EMPTY, NULL, "" },
7504 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7505 { TYPE_EMPTY, NULL, "" },
7506 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7511 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7513 setup_info_touch_virtual_buttons_0,
7514 setup_info_touch_virtual_buttons_1
7517 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7519 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7520 { TYPE_STRING, &touch_controls_text, "" },
7521 { TYPE_EMPTY, NULL, "" },
7522 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7523 { TYPE_STRING, &move_distance_text, "" },
7524 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7525 { TYPE_STRING, &drop_distance_text, "" },
7526 { TYPE_EMPTY, NULL, "" },
7527 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7532 static struct TokenInfo setup_info_shortcuts[] =
7534 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7535 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7536 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7537 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7538 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7539 { TYPE_EMPTY, NULL, "" },
7540 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7545 static struct TokenInfo setup_info_shortcuts_1[] =
7547 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7548 { TYPE_KEY, &setup.shortcut.save_game, "" },
7549 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7550 { TYPE_KEY, &setup.shortcut.load_game, "" },
7551 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7552 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7553 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7554 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7555 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7556 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7557 { TYPE_EMPTY, NULL, "" },
7558 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7559 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7560 { TYPE_EMPTY, NULL, "" },
7561 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7566 static struct TokenInfo setup_info_shortcuts_2[] =
7568 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7569 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7570 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7571 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7572 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7573 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7574 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7575 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7576 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7577 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7578 { TYPE_EMPTY, NULL, "" },
7579 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7584 static struct TokenInfo setup_info_shortcuts_3[] =
7586 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7587 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7588 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7589 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7590 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7591 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7592 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7593 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7594 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7595 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7596 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7597 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7598 { TYPE_EMPTY, NULL, "" },
7599 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7604 static struct TokenInfo setup_info_shortcuts_4[] =
7606 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7607 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7608 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7609 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7610 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7611 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7612 { TYPE_EMPTY, NULL, "" },
7613 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7618 static struct TokenInfo setup_info_shortcuts_5[] =
7620 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7621 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7622 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7623 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7624 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7625 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7626 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7627 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7628 { TYPE_EMPTY, NULL, "" },
7629 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7634 static Key getSetupKey(void)
7636 Key key = KSYM_UNDEFINED;
7637 boolean got_key_event = FALSE;
7639 while (!got_key_event)
7643 if (NextValidEvent(&event))
7647 case EVENT_KEYPRESS:
7649 key = GetEventKey((KeyEvent *)&event, TRUE);
7651 // press 'Escape' or 'Enter' to keep the existing key binding
7652 if (key == KSYM_Escape || key == KSYM_Return)
7653 key = KSYM_UNDEFINED; // keep old value
7655 got_key_event = TRUE;
7659 case EVENT_KEYRELEASE:
7660 key_joystick_mapping = 0;
7664 HandleOtherEvents(&event);
7675 static int getSetupValueFont(int type, void *value)
7677 if (type & TYPE_GHOSTED)
7678 return FONT_OPTION_OFF;
7679 else if (type & TYPE_KEY)
7680 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7681 else if (type & TYPE_STRING)
7682 return FONT_VALUE_2;
7683 else if (type & TYPE_ECS_AGA)
7684 return FONT_VALUE_1;
7685 else if (type & TYPE_BOOLEAN_STYLE)
7686 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7687 else if (type & TYPE_YES_NO_AUTO)
7688 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7689 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7690 else if (type & TYPE_PLAYER)
7691 return FONT_VALUE_1;
7693 return FONT_VALUE_1;
7696 static int getSetupValueFontNarrow(int type, int font_nr)
7698 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7699 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7700 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7704 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7706 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7707 struct TokenInfo *si = &setup_info[si_pos];
7708 boolean font_draw_xoffset_modified = FALSE;
7709 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7710 int font_draw_xoffset_old = -1;
7711 int xoffset = (scrollbar_needed ? -1 : 0);
7712 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7713 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7714 int xpos = menu_screen_value_xpos;
7715 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7716 int startx = mSX + xpos * 32;
7717 int starty = mSY + ypos * 32;
7718 int type = si->type;
7719 void *value = si->value;
7720 char *value_string = getSetupValue(type, value);
7721 int font_nr_default = getSetupValueFont(type, value);
7722 int font_width_default = getFontWidth(font_nr_default);
7723 int font_nr = font_nr_default;
7726 if (value_string == NULL)
7729 if (type & TYPE_KEY)
7731 xpos = MENU_SCREEN_START_XPOS;
7733 if (type & TYPE_QUERY)
7734 value_string = "<press key>";
7736 else if (type & TYPE_STRING)
7738 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7740 xpos = MENU_SCREEN_START_XPOS;
7742 if (strlen(value_string) > max_value_len)
7743 value_string[max_value_len] = '\0';
7745 else if (type & TYPE_YES_NO_AUTO)
7747 xpos = menu_screen_value_xpos - 1;
7749 else if (type & TYPE_PLAYER)
7751 int displayed_player_nr = *(int *)value + 1;
7753 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7756 startx = mSX + xpos * 32;
7757 starty = mSY + ypos * 32;
7759 // special check if right-side setup values moved left due to scrollbar
7760 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7762 int max_menu_text_length = 26; // maximum text length for classic menu
7763 int font_xoffset = getFontDrawOffsetX(font_nr);
7764 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7765 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7766 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7767 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7769 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7771 // when using narrow font, left-shifting text "auto" not needed
7772 if (type & TYPE_YES_NO_AUTO)
7776 startx = mSX + xpos * 32;
7778 font_nr = getSetupValueFontNarrow(type, font_nr);
7782 // downward compatibility correction for Juergen Bonhagen's menu settings
7783 if (setup_mode != SETUP_MODE_INPUT)
7785 int max_menu_text_length_big = (menu_screen_value_xpos -
7786 MENU_SCREEN_START_XPOS);
7787 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7788 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7789 int font1_xoffset = getFontDrawOffsetX(font_nr);
7790 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7791 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7792 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7793 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7794 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7795 boolean correct_font_draw_xoffset = FALSE;
7797 if (xpos == MENU_SCREEN_START_XPOS &&
7798 startx + font1_xoffset < text_startx + text_font_xoffset)
7799 correct_font_draw_xoffset = TRUE;
7801 if (xpos == menu_screen_value_xpos &&
7802 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7803 correct_font_draw_xoffset = TRUE;
7805 // check if setup value would overlap with setup text when printed
7806 // (this can happen for extreme/wrong values for font draw offset)
7807 if (correct_font_draw_xoffset)
7809 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7810 font_draw_xoffset_modified = TRUE;
7812 if (type & TYPE_KEY)
7813 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7814 else if (!(type & TYPE_STRING))
7815 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7816 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7820 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7821 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7823 DrawText(startx, starty, value_string, font_nr);
7825 if (type & TYPE_PLAYER)
7827 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7828 int player_nr = *(int *)value;
7829 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7830 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7831 int startx2 = startx + xoff;
7832 int starty2 = starty + yoff;
7834 if (DrawingOnBackground(startx2, starty2))
7835 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7837 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7838 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7841 if (font_draw_xoffset_modified)
7842 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7845 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7847 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7848 struct TokenInfo *si = &setup_info[si_pos];
7850 if (si->type & TYPE_BOOLEAN_STYLE)
7852 *(boolean *)si->value ^= TRUE;
7854 else if (si->type & TYPE_YES_NO_AUTO)
7858 (*(int *)si->value == AUTO ? TRUE :
7859 *(int *)si->value == TRUE ? FALSE : AUTO) :
7860 (*(int *)si->value == TRUE ? AUTO :
7861 *(int *)si->value == AUTO ? FALSE : TRUE));
7863 else if (si->type & TYPE_KEY)
7867 si->type |= TYPE_QUERY;
7868 drawSetupValue(screen_pos, setup_info_pos_raw);
7869 si->type &= ~TYPE_QUERY;
7871 key = getSetupKey();
7872 if (key != KSYM_UNDEFINED)
7873 *(Key *)si->value = key;
7875 else if (si->type & TYPE_PLAYER)
7877 int player_nr = *(int *)si->value;
7882 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7884 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7887 drawSetupValue(screen_pos, setup_info_pos_raw);
7889 // fullscreen state may have changed at this point
7890 if (si->value == &setup.fullscreen)
7891 ToggleFullscreenIfNeeded();
7893 // network mode may have changed at this point
7894 if (si->value == &setup.network_mode)
7895 ToggleNetworkModeIfNeeded();
7897 // API server mode may have changed at this point
7898 if (si->value == &setup.use_api_server)
7899 ToggleUseApiServerIfNeeded();
7901 // game speed list may have changed at this point
7902 if (si->value == &setup.game_speed_extended)
7903 ToggleGameSpeedsListIfNeeded();
7906 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7908 static struct TokenInfo *setup_info_final = NULL;
7913 // determine maximum list size of target list
7914 while (setup_info_orig[list_size++].type != 0);
7916 // free, allocate and clear memory for target list
7917 checked_free(setup_info_final);
7918 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7920 // copy setup info list without setup entries marked as hidden
7921 for (i = 0; setup_info_orig[i].type != 0; i++)
7923 // skip setup entries configured to be hidden
7924 if (hideSetupEntry(setup_info_orig[i].value))
7927 // skip skippable setup entries if screen is lower than usual
7928 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7929 setup_info_orig[i].type == TYPE_SKIPPABLE)
7932 setup_info_final[list_pos++] = setup_info_orig[i];
7935 return setup_info_final;
7938 static void DrawSetupScreen_Generic(void)
7940 int fade_mask = REDRAW_FIELD;
7941 boolean redraw_all = FALSE;
7942 char *title_string = NULL;
7946 fade_mask = REDRAW_ALL;
7949 FadeMenuSoundsAndMusic();
7951 FreeScreenGadgets();
7952 CreateScreenGadgets();
7954 if (redraw_mask & REDRAW_ALL)
7959 // needed if different viewport properties defined for setup screen
7960 ChangeViewportPropertiesIfNeeded();
7962 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7966 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7968 if (setup_mode == SETUP_MODE_MAIN)
7970 setup_info = setup_info_main;
7971 title_string = STR_SETUP_MAIN;
7973 else if (setup_mode == SETUP_MODE_GAME)
7975 setup_info = setup_info_game;
7976 title_string = STR_SETUP_GAME;
7978 else if (setup_mode == SETUP_MODE_ENGINES)
7980 setup_info = setup_info_engines;
7981 title_string = STR_SETUP_ENGINES;
7983 else if (setup_mode == SETUP_MODE_EDITOR)
7985 setup_info = setup_info_editor;
7986 title_string = STR_SETUP_EDITOR;
7988 else if (setup_mode == SETUP_MODE_GRAPHICS)
7990 setup_info = setup_info_graphics;
7991 title_string = STR_SETUP_GRAPHICS;
7993 else if (setup_mode == SETUP_MODE_SOUND)
7995 setup_info = setup_info_sound;
7996 title_string = STR_SETUP_SOUND;
7998 else if (setup_mode == SETUP_MODE_ARTWORK)
8000 setup_info = setup_info_artwork;
8001 title_string = STR_SETUP_ARTWORK;
8003 else if (setup_mode == SETUP_MODE_TOUCH)
8005 setup_info = setup_info_touch;
8006 title_string = STR_SETUP_TOUCH;
8008 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8009 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8010 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8011 setup_info = setup_info_touch_wipe_gestures;
8013 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8015 setup_info = setup_info_shortcuts;
8016 title_string = STR_SETUP_SHORTCUTS;
8018 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8020 setup_info = setup_info_shortcuts_1;
8021 title_string = STR_SETUP_SHORTCUTS;
8023 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8025 setup_info = setup_info_shortcuts_2;
8026 title_string = STR_SETUP_SHORTCUTS;
8028 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8030 setup_info = setup_info_shortcuts_3;
8031 title_string = STR_SETUP_SHORTCUTS;
8033 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8035 setup_info = setup_info_shortcuts_4;
8036 title_string = STR_SETUP_SHORTCUTS;
8038 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8040 setup_info = setup_info_shortcuts_5;
8041 title_string = STR_SETUP_SHORTCUTS;
8044 // use modified setup info without setup entries marked as hidden
8045 setup_info = getSetupInfoFinal(setup_info);
8047 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8049 // determine maximal number of setup entries that can be displayed on screen
8051 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8054 // determine maximal number of setup entries available for this setup screen
8056 for (i = 0; setup_info[i].type != 0; i++)
8059 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8061 MapScreenGadgets(max_setup_info);
8064 redraw_mask = fade_mask = REDRAW_ALL;
8066 DrawMaskedBorder(fade_mask);
8071 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8073 menu_info = setup_info;
8075 HandleMenuScreen(mx, my, dx, dy, button,
8076 setup_mode, num_setup_info, max_setup_info);
8079 static void DrawSetupScreen_Input(void)
8083 FadeOut(REDRAW_FIELD);
8087 setup_info = getSetupInfoFinal(setup_info_input);
8089 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8091 for (i = 0; setup_info[i].type != 0; i++)
8093 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8094 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8095 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8096 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8097 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8098 initCursor(i, IMG_MENU_BUTTON);
8100 DrawCursorAndText_Setup(i, -1, FALSE);
8103 // create gadgets for setup input menu screen
8104 FreeScreenGadgets();
8105 CreateScreenGadgets();
8107 // map gadgets for setup input menu screen
8108 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8110 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8112 FadeIn(REDRAW_FIELD);
8115 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8117 if (device_name == NULL)
8120 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8123 if (strlen(device_name) > 1)
8125 char c1 = device_name[strlen(device_name) - 1];
8126 char c2 = device_name[strlen(device_name) - 2];
8128 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8129 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8132 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8133 strlen(device_name));
8136 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8139 static struct SetupKeyboardInfo custom_key;
8146 { &custom_key.left, "Axis/Pad Left" },
8147 { &custom_key.right, "Axis/Pad Right" },
8148 { &custom_key.up, "Axis/Pad Up" },
8149 { &custom_key.down, "Axis/Pad Down" },
8150 { &custom_key.snap, "Button 1/A/X" },
8151 { &custom_key.drop, "Button 2/B/Y" }
8153 static char *joystick_name[MAX_PLAYERS] =
8160 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8161 int font_nr_info = FONT_MENU_1;
8162 int font_nr_name = FONT_VALUE_OLD;
8163 int font_nr_on = FONT_VALUE_1;
8164 int font_nr_off = FONT_VALUE_OLD;
8167 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8169 font_nr_info = FONT_MENU_2;
8170 font_nr_on = FONT_VALUE_NARROW;
8171 font_nr_off = FONT_VALUE_OLD_NARROW;
8174 custom_key = setup.input[player_nr].key;
8176 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8177 FONT_INPUT_1_ACTIVE);
8179 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8181 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8182 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8184 if (setup.input[player_nr].use_joystick)
8186 char *device_name = setup.input[player_nr].joy.device_name;
8187 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8188 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8189 char *text = joystick_name[joystick_nr];
8190 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8192 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8193 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8197 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8198 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8201 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8202 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8206 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8207 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8208 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8209 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8211 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8212 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8213 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8214 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8215 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8216 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8218 for (i = 0; i < 6; i++)
8220 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8222 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8224 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8225 (setup.input[player_nr].use_joystick ?
8227 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8231 static int input_player_nr = 0;
8233 static void HandleSetupScreen_Input_Player(int step, int direction)
8235 int old_player_nr = input_player_nr;
8238 new_player_nr = old_player_nr + step * direction;
8239 if (new_player_nr < 0)
8241 if (new_player_nr > MAX_PLAYERS - 1)
8242 new_player_nr = MAX_PLAYERS - 1;
8244 if (new_player_nr != old_player_nr)
8246 input_player_nr = new_player_nr;
8248 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8252 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8254 static int choice = 0;
8257 int pos_start = SETUPINPUT_SCREEN_POS_START;
8258 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8259 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8260 int pos_end = SETUPINPUT_SCREEN_POS_END;
8262 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8266 for (i = 0; setup_info_input[i].type != 0; i++)
8268 // adjust menu structure according to skipped setup entries
8269 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8277 if (button == MB_MENU_INITIALIZE)
8279 // input setup menu may have changed size due to graphics configuration
8280 if (choice >= pos_empty1)
8283 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8285 DrawCursorAndText_Setup(choice, -1, TRUE);
8289 else if (button == MB_MENU_LEAVE)
8291 setup_mode = SETUP_MODE_MAIN;
8298 if (mx || my) // mouse input
8300 x = (mx - mSX) / 32;
8301 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8303 else if (dx || dy) // keyboard input
8305 if (dx && choice == 0)
8306 x = (dx < 0 ? 10 : 12);
8307 else if ((dx && choice == 1) ||
8308 (dx == -1 && choice == pos_end))
8309 button = MB_MENU_CHOICE;
8313 if (y >= pos_empty1 && y <= pos_empty2)
8314 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8317 if (y == 0 && dx != 0 && button)
8319 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8321 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8322 y >= pos_start && y <= pos_end &&
8323 !(y >= pos_empty1 && y <= pos_empty2))
8329 DrawCursorAndText_Setup(choice, -1, FALSE);
8330 DrawCursorAndText_Setup(y, -1, TRUE);
8332 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8341 char *device_name = setup.input[input_player_nr].joy.device_name;
8343 if (!setup.input[input_player_nr].use_joystick)
8345 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8347 setJoystickDeviceToNr(device_name, new_device_nr);
8348 setup.input[input_player_nr].use_joystick = TRUE;
8352 int device_nr = getJoystickNrFromDeviceName(device_name);
8353 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8355 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8356 setup.input[input_player_nr].use_joystick = FALSE;
8358 setJoystickDeviceToNr(device_name, new_device_nr);
8361 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8365 if (setup.input[input_player_nr].use_joystick)
8366 ConfigureJoystick(input_player_nr);
8368 CustomizeKeyboard(input_player_nr);
8370 else if (y == pos_end)
8376 setup_mode = SETUP_MODE_MAIN;
8383 static boolean CustomizeKeyboardMain(int player_nr)
8387 boolean finished = FALSE;
8388 static struct SetupKeyboardInfo custom_key;
8393 } customize_step[] =
8395 { &custom_key.left, "Move Left" },
8396 { &custom_key.right, "Move Right" },
8397 { &custom_key.up, "Move Up" },
8398 { &custom_key.down, "Move Down" },
8399 { &custom_key.snap, "Snap Field" },
8400 { &custom_key.drop, "Drop Element" }
8402 int font_nr_old = FONT_VALUE_OLD;
8403 int font_nr_new = FONT_VALUE_1;
8404 boolean success = FALSE;
8406 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8408 font_nr_old = FONT_VALUE_OLD_NARROW;
8409 font_nr_new = FONT_VALUE_NARROW;
8412 // read existing key bindings from player setup
8413 custom_key = setup.input[player_nr].key;
8416 FadeOut(REDRAW_FIELD);
8420 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8423 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8424 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8425 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8426 "Key:", FONT_INPUT_1_ACTIVE);
8427 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8428 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8430 FadeIn(REDRAW_FIELD);
8436 if (NextValidEvent(&event))
8440 case EVENT_KEYPRESS:
8442 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8444 // press 'Escape' to abort and keep the old key bindings
8445 if (key == KSYM_Escape)
8447 FadeSkipNextFadeIn();
8454 // press 'Enter' to keep the existing key binding
8455 if (key == KSYM_Return)
8456 key = *customize_step[step_nr].key;
8458 // check if key already used
8459 for (i = 0; i < step_nr; i++)
8460 if (*customize_step[i].key == key)
8465 // got new key binding
8466 *customize_step[step_nr].key = key;
8467 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8469 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8470 getKeyNameFromKey(key), font_nr_new);
8473 // un-highlight last query
8474 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8475 customize_step[step_nr - 1].text, FONT_MENU_1);
8476 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8477 "Key:", FONT_MENU_1);
8479 // all keys configured
8488 // query next key binding
8489 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8490 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8491 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8492 "Key:", FONT_INPUT_1_ACTIVE);
8493 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8494 getKeyNameFromKey(*customize_step[step_nr].key),
8499 case EVENT_KEYRELEASE:
8500 key_joystick_mapping = 0;
8504 HandleOtherEvents(&event);
8512 // write new key bindings back to player setup, if successfully finished
8514 setup.input[player_nr].key = custom_key;
8519 void CustomizeKeyboard(int player_nr)
8521 boolean success = CustomizeKeyboardMain(player_nr);
8525 int font_nr = FONT_TITLE_1;
8526 int font_height = getFontHeight(font_nr);
8527 int ypos1 = SYSIZE / 2 - font_height * 2;
8528 int ypos2 = SYSIZE / 2 - font_height * 1;
8529 unsigned int wait_frame_delay = 0;
8530 unsigned int wait_frame_delay_value = 2000;
8532 ResetDelayCounter(&wait_frame_delay);
8536 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8537 DrawTextSCentered(ypos2, font_nr, "configured!");
8539 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8545 DrawSetupScreen_Input();
8548 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8550 #define MARKER_BUTTON 1
8551 #define MARKER_AXIS_X 2
8552 #define MARKER_AXIS_Y 3
8554 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8556 static boolean bitmaps_initialized = FALSE;
8557 boolean screen_initialized = FALSE;
8558 static Bitmap *controller, *button, *axis_x, *axis_y;
8560 boolean success = TRUE;
8561 boolean done = FALSE, next = FALSE;
8563 int alpha = 200, alpha_step = -1;
8564 int alpha_ticks = 0;
8565 char mapping[4096], temp[256];
8566 int font_name = MENU_SETUP_FONT_TITLE;
8567 int font_info = MENU_SETUP_FONT_TEXT;
8568 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8569 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8570 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8571 int ystep_name = getMenuTextStep(spacing_name, font_name);
8572 int ystep_line = getMenuTextStep(spacing_line, font_info);
8573 int ystep_para = getMenuTextStep(spacing_para, font_info);
8581 int axis, button, hat, hat_value;
8584 *step, *prev_step, steps[] =
8586 { 356, 155, MARKER_BUTTON, "a", },
8587 { 396, 122, MARKER_BUTTON, "b", },
8588 { 320, 125, MARKER_BUTTON, "x", },
8589 { 358, 95, MARKER_BUTTON, "y", },
8590 { 162, 125, MARKER_BUTTON, "back", },
8591 { 216, 125, MARKER_BUTTON, "guide", },
8592 { 271, 125, MARKER_BUTTON, "start", },
8593 { 110, 200, MARKER_BUTTON, "dpleft", },
8594 { 146, 228, MARKER_BUTTON, "dpdown", },
8595 { 178, 200, MARKER_BUTTON, "dpright", },
8596 { 146, 172, MARKER_BUTTON, "dpup", },
8597 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8598 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8599 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8600 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8601 { 73, 141, MARKER_BUTTON, "leftstick", },
8602 { 282, 210, MARKER_BUTTON, "rightstick", },
8603 { 73, 141, MARKER_AXIS_X, "leftx", },
8604 { 73, 141, MARKER_AXIS_Y, "lefty", },
8605 { 282, 210, MARKER_AXIS_X, "rightx", },
8606 { 282, 210, MARKER_AXIS_Y, "righty", },
8609 unsigned int event_frame_delay = 0;
8610 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8612 ResetDelayCounter(&event_frame_delay);
8614 if (!bitmaps_initialized)
8616 controller = LoadCustomImage("joystick/controller.png");
8617 button = LoadCustomImage("joystick/button.png");
8618 axis_x = LoadCustomImage("joystick/axis_x.png");
8619 axis_y = LoadCustomImage("joystick/axis_y.png");
8621 bitmaps_initialized = TRUE;
8624 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8627 // print info about the joystick we are watching
8628 Debug("joystick", "watching joystick %d: (%s)",
8629 SDL_JoystickInstanceID(joystick), name);
8630 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8631 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8632 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8635 // initialize mapping with GUID and name
8636 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8638 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8639 temp, name, SDL_GetPlatform());
8641 // loop through all steps (buttons and axes), getting joystick events
8642 for (i = 0; i < SDL_arraysize(steps) && !done;)
8644 Bitmap *marker = button; // initialize with reliable default value
8647 strcpy(step->mapping, mapping);
8651 step->hat_value = -1;
8653 marker = (step->marker == MARKER_BUTTON ? button :
8654 step->marker == MARKER_AXIS_X ? axis_x :
8655 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8659 while (!done && !next)
8661 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8662 alpha_ticks = SDL_GetTicks();
8669 else if (alpha < 128)
8675 int controller_x = SX + (SXSIZE - controller->width) / 2;
8676 int controller_y = SY + ystep_line;
8678 int marker_x = controller_x + step->x;
8679 int marker_y = controller_y + step->y;
8681 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8682 int ystart2 = ystart1 + ystep_name + ystep_line;
8686 DrawTextSCentered(ystart1, font_name, name);
8688 DrawTextSCentered(ystart2, font_info,
8689 "Press buttons and move axes on");
8690 ystart2 += ystep_line;
8691 DrawTextSCentered(ystart2, font_info,
8692 "your controller when indicated.");
8693 ystart2 += ystep_line;
8694 DrawTextSCentered(ystart2, font_info,
8695 "(Your controller may look different.)");
8696 ystart2 += ystep_para;
8698 #if defined(PLATFORM_ANDROID)
8699 DrawTextSCentered(ystart2, font_info,
8700 "To correct a mistake,");
8701 ystart2 += ystep_line;
8702 DrawTextSCentered(ystart2, font_info,
8703 "press the 'back' button.");
8704 ystart2 += ystep_line;
8705 DrawTextSCentered(ystart2, font_info,
8706 "To skip a button or axis,");
8707 ystart2 += ystep_line;
8708 DrawTextSCentered(ystart2, font_info,
8709 "press the 'menu' button.");
8711 DrawTextSCentered(ystart2, font_info,
8712 "To correct a mistake,");
8713 ystart2 += ystep_line;
8714 DrawTextSCentered(ystart2, font_info,
8715 "press the 'backspace' key.");
8716 ystart2 += ystep_line;
8717 DrawTextSCentered(ystart2, font_info,
8718 "To skip a button or axis,");
8719 ystart2 += ystep_line;
8720 DrawTextSCentered(ystart2, font_info,
8721 "press the 'return' key.");
8722 ystart2 += ystep_line;
8723 DrawTextSCentered(ystart2, font_info,
8724 "To exit, press the 'escape' key.");
8727 BlitBitmapMasked(controller, drawto, 0, 0,
8728 controller->width, controller->height,
8729 controller_x, controller_y);
8731 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8732 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8734 BlitBitmapMasked(marker, drawto, 0, 0,
8735 marker->width, marker->height,
8736 marker_x, marker_y);
8738 if (!screen_initialized)
8739 FadeIn(REDRAW_FIELD);
8743 screen_initialized = TRUE;
8745 while (NextValidEvent(&event))
8749 case SDL_JOYAXISMOTION:
8750 if (event.jaxis.value > 20000 ||
8751 event.jaxis.value < -20000)
8753 for (j = 0; j < i; j++)
8754 if (steps[j].axis == event.jaxis.axis)
8759 if (step->marker != MARKER_AXIS_X &&
8760 step->marker != MARKER_AXIS_Y)
8763 step->axis = event.jaxis.axis;
8764 strcat(mapping, step->field);
8765 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8766 strcat(mapping, temp);
8774 case SDL_JOYHATMOTION:
8775 // ignore centering; we're probably just coming back
8776 // to the center from the previous item we set
8777 if (event.jhat.value == SDL_HAT_CENTERED)
8780 for (j = 0; j < i; j++)
8781 if (steps[j].hat == event.jhat.hat &&
8782 steps[j].hat_value == event.jhat.value)
8787 step->hat = event.jhat.hat;
8788 step->hat_value = event.jhat.value;
8789 strcat(mapping, step->field);
8790 snprintf(temp, sizeof(temp), ":h%u.%u,",
8791 event.jhat.hat, event.jhat.value );
8792 strcat(mapping, temp);
8799 case SDL_JOYBALLMOTION:
8802 case SDL_JOYBUTTONUP:
8803 for (j = 0; j < i; j++)
8804 if (steps[j].button == event.jbutton.button)
8809 step->button = event.jbutton.button;
8810 strcat(mapping, step->field);
8811 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8812 strcat(mapping, temp);
8819 case SDL_FINGERDOWN:
8820 case SDL_MOUSEBUTTONDOWN:
8828 if (event.key.keysym.sym == KSYM_BackSpace ||
8829 event.key.keysym.sym == KSYM_Back)
8841 prev_step = &steps[i - 1];
8842 strcpy(mapping, prev_step->mapping);
8849 if (event.key.keysym.sym == KSYM_space ||
8850 event.key.keysym.sym == KSYM_Return ||
8851 event.key.keysym.sym == KSYM_Menu)
8860 if (event.key.keysym.sym == KSYM_Escape)
8870 program.exit_function(0);
8877 // do not handle events for longer than standard frame delay period
8878 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8887 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8890 // activate mapping for this game
8891 SDL_GameControllerAddMapping(mapping);
8893 // save mapping to personal mappings
8894 SaveSetup_AddGameControllerMapping(mapping);
8897 // wait until the last pending event was removed from event queue
8898 while (NextValidEvent(&event));
8903 static int ConfigureJoystickMain(int player_nr)
8905 char *device_name = setup.input[player_nr].joy.device_name;
8906 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8907 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8908 int success = FALSE;
8911 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8912 return JOYSTICK_NOT_AVAILABLE;
8914 if (!joystick_active || !setup.input[player_nr].use_joystick)
8915 return JOYSTICK_NOT_AVAILABLE;
8918 FadeOut(REDRAW_FIELD);
8920 // close all joystick devices (potentially opened as game controllers)
8921 for (i = 0; i < SDL_NumJoysticks(); i++)
8922 SDLCloseJoystick(i);
8924 // open joystick device as plain joystick to configure as game controller
8925 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8927 // as the joystick was successfully opened before, this should not happen
8928 if (joystick == NULL)
8931 // create new game controller mapping (buttons and axes) for joystick device
8932 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8934 // close joystick (and maybe re-open as configured game controller later)
8935 SDL_JoystickClose(joystick);
8937 // re-open all joystick devices (potentially as game controllers)
8938 for (i = 0; i < SDL_NumJoysticks(); i++)
8941 // clear all joystick input actions for all joystick devices
8942 SDLClearJoystickState();
8944 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8947 void ConfigureJoystick(int player_nr)
8949 boolean state = ConfigureJoystickMain(player_nr);
8951 if (state != JOYSTICK_NOT_CONFIGURED)
8953 boolean success = (state == JOYSTICK_CONFIGURED);
8954 char message1[MAX_OUTPUT_LINESIZE + 1];
8955 char *message2 = (success ? "configured!" : "not available!");
8956 char *device_name = setup.input[player_nr].joy.device_name;
8957 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8958 int font_nr = FONT_TITLE_1;
8959 int font_height = getFontHeight(font_nr);
8960 int ypos1 = SYSIZE / 2 - font_height * 2;
8961 int ypos2 = SYSIZE / 2 - font_height * 1;
8962 unsigned int wait_frame_delay = 0;
8963 unsigned int wait_frame_delay_value = 2000;
8965 ResetDelayCounter(&wait_frame_delay);
8969 sprintf(message1, "Joystick %d", nr);
8971 DrawTextSCentered(ypos1, font_nr, message1);
8972 DrawTextSCentered(ypos2, font_nr, message2);
8974 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8980 DrawSetupScreen_Input();
8983 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8985 if (y < video.screen_height / 3)
8987 // remap touch gadgets to access upper part of the screen
8988 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8989 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8991 else if (y > 2 * video.screen_height / 3)
8993 // remap touch gadgets to access lower part of the screen
8994 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8995 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8999 static boolean ConfigureVirtualButtonsMain(void)
9001 static char *customize_step_text[] =
9010 char grid_button[] =
9012 CHAR_GRID_BUTTON_LEFT,
9013 CHAR_GRID_BUTTON_RIGHT,
9014 CHAR_GRID_BUTTON_UP,
9015 CHAR_GRID_BUTTON_DOWN,
9016 CHAR_GRID_BUTTON_SNAP,
9017 CHAR_GRID_BUTTON_DROP
9026 int font_nr = FONT_INPUT_1_ACTIVE;
9027 int font_height = getFontHeight(font_nr);
9028 int ypos1 = SYSIZE / 2 - font_height * 2;
9029 int ypos2 = SYSIZE / 2 - font_height * 1;
9030 boolean success = FALSE;
9031 boolean finished = FALSE;
9033 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9034 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9035 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9036 boolean set_grid_button = FALSE;
9037 int nr = GRID_ACTIVE_NR();
9040 for (x = 0; x < MAX_GRID_XSIZE; x++)
9041 for (y = 0; y < MAX_GRID_YSIZE; y++)
9042 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9044 overlay.grid_button_highlight = grid_button[step_nr];
9049 FadeOut(REDRAW_FIELD);
9053 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9054 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9055 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9057 FadeIn(REDRAW_FIELD);
9059 SetOverlayShowGrid(TRUE);
9061 // map gadgets for setup touch buttons menu screen
9062 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9068 while (NextValidEvent(&event))
9070 int action = ACTION_NONE;
9072 // ---------- handle events and set the resulting action ----------
9078 UserEvent *user = (UserEvent *)&event;
9079 int id = user->value1;
9081 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9082 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9083 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9084 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9089 case EVENT_KEYPRESS:
9091 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9093 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9094 key == KSYM_BackSpace ||
9095 key == KSYM_Back ? ACTION_BACK :
9096 key == KSYM_Return ||
9098 key == KSYM_space ? ACTION_NEXT :
9103 case EVENT_KEYRELEASE:
9104 key_joystick_mapping = 0;
9107 case EVENT_BUTTONPRESS:
9108 case EVENT_BUTTONRELEASE:
9110 ButtonEvent *button = (ButtonEvent *)&event;
9112 motion_status = FALSE;
9114 if (button->type == EVENT_BUTTONPRESS)
9115 button_status = button->button;
9117 button_status = MB_RELEASED;
9119 if (HandleGadgets(button->x, button->y, button_status))
9121 // do not handle this button event anymore
9125 button->x += video.screen_xoffset;
9126 button->y += video.screen_yoffset;
9128 x = button->x * overlay.grid_xsize / video.screen_width;
9129 y = button->y * overlay.grid_ysize / video.screen_height;
9131 if (button->type == EVENT_BUTTONPRESS)
9134 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9135 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9137 set_grid_button = TRUE;
9140 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9144 case EVENT_MOTIONNOTIFY:
9146 MotionEvent *motion = (MotionEvent *)&event;
9148 motion_status = TRUE;
9150 if (HandleGadgets(motion->x, motion->y, button_status))
9152 // do not handle this button event anymore
9156 motion->x += video.screen_xoffset;
9157 motion->y += video.screen_yoffset;
9159 x = motion->x * overlay.grid_xsize / video.screen_width;
9160 y = motion->y * overlay.grid_ysize / video.screen_height;
9162 set_grid_button = TRUE;
9164 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9168 case SDL_WINDOWEVENT:
9169 HandleWindowEvent((WindowEvent *) &event);
9171 // check if device has been rotated
9172 if (nr != GRID_ACTIVE_NR())
9174 nr = GRID_ACTIVE_NR();
9176 for (x = 0; x < MAX_GRID_XSIZE; x++)
9177 for (y = 0; y < MAX_GRID_YSIZE; y++)
9178 grid_button_old[x][y] = grid_button_tmp[x][y] =
9179 overlay.grid_button[x][y];
9184 case SDL_APP_WILLENTERBACKGROUND:
9185 case SDL_APP_DIDENTERBACKGROUND:
9186 case SDL_APP_WILLENTERFOREGROUND:
9187 case SDL_APP_DIDENTERFOREGROUND:
9188 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9192 HandleOtherEvents(&event);
9196 // ---------- perform action set by handling events ----------
9198 if (action == ACTION_ESCAPE)
9200 // abort and restore the old key bindings
9202 for (x = 0; x < MAX_GRID_XSIZE; x++)
9203 for (y = 0; y < MAX_GRID_YSIZE; y++)
9204 overlay.grid_button[x][y] = grid_button_old[x][y];
9206 FadeSkipNextFadeIn();
9210 else if (action == ACTION_BACK)
9212 // keep the configured key bindings and go to previous page
9218 FadeSkipNextFadeIn();
9223 else if (action == ACTION_NEXT)
9225 // keep the configured key bindings and go to next page
9229 // all virtual buttons configured
9237 if (action != ACTION_NONE && !finished)
9239 for (x = 0; x < MAX_GRID_XSIZE; x++)
9240 for (y = 0; y < MAX_GRID_YSIZE; y++)
9241 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9243 overlay.grid_button_highlight = grid_button[step_nr];
9245 // configure next virtual button
9249 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9250 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9251 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9254 if (set_grid_button)
9256 overlay.grid_button[x][y] =
9257 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9258 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9259 grid_button_tmp[x][y]);
9261 set_grid_button = FALSE;
9268 for (x = 0; x < MAX_GRID_XSIZE; x++)
9269 for (y = 0; y < MAX_GRID_YSIZE; y++)
9270 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9272 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9274 SetOverlayShowGrid(FALSE);
9279 void ConfigureVirtualButtons(void)
9281 boolean success = ConfigureVirtualButtonsMain();
9283 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9284 SCREEN_MASK_TOUCH2);
9288 int font_nr = FONT_TITLE_1;
9289 int font_height = getFontHeight(font_nr);
9290 int ypos1 = SYSIZE / 2 - font_height * 2;
9291 int ypos2 = SYSIZE / 2 - font_height * 1;
9292 unsigned int wait_frame_delay = 0;
9293 unsigned int wait_frame_delay_value = 2000;
9295 ResetDelayCounter(&wait_frame_delay);
9299 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9300 DrawTextSCentered(ypos2, font_nr, "configured!");
9302 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9309 void DrawSetupScreen(void)
9314 if (setup_mode == SETUP_MODE_INPUT)
9315 DrawSetupScreen_Input();
9316 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9317 DrawChooseTree(&scores_type_current);
9318 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9319 DrawChooseTree(&game_speed_current);
9320 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9321 DrawChooseTree(&scroll_delay_current);
9322 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9323 DrawChooseTree(&snapshot_mode_current);
9324 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9325 DrawChooseTree(&window_size_current);
9326 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9327 DrawChooseTree(&scaling_type_current);
9328 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9329 DrawChooseTree(&rendering_mode_current);
9330 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9331 DrawChooseTree(&vsync_mode_current);
9332 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9333 DrawChooseTree(&artwork.gfx_current);
9334 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9335 DrawChooseTree(&artwork.snd_current);
9336 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9337 DrawChooseTree(&artwork.mus_current);
9338 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9339 DrawChooseTree(&volume_simple_current);
9340 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9341 DrawChooseTree(&volume_loops_current);
9342 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9343 DrawChooseTree(&volume_music_current);
9344 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9345 DrawChooseTree(&touch_control_current);
9346 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9347 DrawChooseTree(&move_distance_current);
9348 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9349 DrawChooseTree(&drop_distance_current);
9350 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9351 DrawChooseTree(&transparency_current);
9352 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9353 DrawChooseTree(&grid_size_current[0][0]);
9354 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9355 DrawChooseTree(&grid_size_current[0][1]);
9356 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9357 DrawChooseTree(&grid_size_current[1][0]);
9358 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9359 DrawChooseTree(&grid_size_current[1][1]);
9361 DrawSetupScreen_Generic();
9363 PlayMenuSoundsAndMusic();
9366 void RedrawSetupScreenAfterFullscreenToggle(void)
9368 if (setup_mode == SETUP_MODE_GRAPHICS ||
9369 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9371 // update list selection from "setup.window_scaling_percent"
9372 execSetupGraphics_setWindowSizes(TRUE);
9378 void RedrawSetupScreenAfterScreenRotation(int nr)
9382 if (setup_mode == SETUP_MODE_TOUCH)
9384 // update virtual button settings (depending on screen orientation)
9387 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9389 // save already configured virtual buttons
9390 for (x = 0; x < MAX_GRID_XSIZE; x++)
9391 for (y = 0; y < MAX_GRID_YSIZE; y++)
9392 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9396 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9398 if (setup_mode == SETUP_MODE_INPUT)
9399 HandleSetupScreen_Input(mx, my, dx, dy, button);
9400 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9401 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9402 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9403 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9404 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9405 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9406 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9407 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9408 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9409 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9410 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9411 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9412 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9413 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9414 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9415 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9416 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9417 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9418 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9419 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9420 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9421 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9422 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9423 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9424 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9425 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9426 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9427 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9428 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9429 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9430 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9431 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9432 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9433 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9434 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9435 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9436 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9437 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9438 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9439 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9440 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9441 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9442 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9443 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9445 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9448 void HandleGameActions(void)
9450 if (setup.ask_on_game_over)
9453 if (game.restart_game_message != NULL)
9455 RequestRestartGame(game.restart_game_message);
9460 if (game_status != GAME_MODE_PLAYING)
9463 GameActions(); // main game loop
9465 if (tape.auto_play && !tape.playing)
9466 AutoPlayTapesContinue(); // continue automatically playing next tape
9470 // ---------- new screen button stuff --------------------------------------
9474 int gfx_unpressed, gfx_pressed;
9475 struct MenuPosInfo *pos;
9476 boolean *check_value;
9479 unsigned int event_mask;
9480 boolean is_touch_button;
9482 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9485 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9486 &menu.main.button.prev_level, NULL,
9487 SCREEN_CTRL_ID_PREV_LEVEL,
9489 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9490 FALSE, "previous level"
9493 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9494 &menu.main.button.next_level, NULL,
9495 SCREEN_CTRL_ID_NEXT_LEVEL,
9497 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9501 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9502 &menu.scores.button.prev_level, NULL,
9503 SCREEN_CTRL_ID_PREV_LEVEL2,
9504 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9505 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9506 FALSE, "previous level"
9509 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9510 &menu.scores.button.next_level, NULL,
9511 SCREEN_CTRL_ID_NEXT_LEVEL2,
9512 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9513 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9517 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9518 &menu.scores.button.prev_score, NULL,
9519 SCREEN_CTRL_ID_PREV_SCORE,
9520 SCREEN_MASK_SCORES_INFO,
9521 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9522 FALSE, "previous score"
9525 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9526 &menu.scores.button.next_score, NULL,
9527 SCREEN_CTRL_ID_NEXT_SCORE,
9528 SCREEN_MASK_SCORES_INFO,
9529 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9533 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE,
9534 &menu.scores.button.play_tape, NULL,
9535 SCREEN_CTRL_ID_PLAY_TAPE,
9536 SCREEN_MASK_SCORES_INFO,
9541 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9542 &menu.main.button.first_level, NULL,
9543 SCREEN_CTRL_ID_FIRST_LEVEL,
9546 FALSE, "first level"
9549 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9550 &menu.main.button.last_level, NULL,
9551 SCREEN_CTRL_ID_LAST_LEVEL,
9557 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9558 &menu.main.button.level_number, NULL,
9559 SCREEN_CTRL_ID_LEVEL_NUMBER,
9562 FALSE, "level number"
9565 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9566 &menu.setup.button.prev_player, NULL,
9567 SCREEN_CTRL_ID_PREV_PLAYER,
9569 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9570 FALSE, "previous player"
9573 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9574 &menu.setup.button.next_player, NULL,
9575 SCREEN_CTRL_ID_NEXT_PLAYER,
9577 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9578 FALSE, "next player"
9581 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9582 &menu.main.button.insert_solution, NULL,
9583 SCREEN_CTRL_ID_INSERT_SOLUTION,
9584 SCREEN_MASK_MAIN_HAS_SOLUTION,
9586 FALSE, "insert solution tape"
9589 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9590 &menu.main.button.play_solution, NULL,
9591 SCREEN_CTRL_ID_PLAY_SOLUTION,
9592 SCREEN_MASK_MAIN_HAS_SOLUTION,
9594 FALSE, "play solution tape"
9597 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9598 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9599 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9601 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9602 FALSE, "switch ECS/AGA chipset"
9605 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9606 &menu.setup.button.touch_back, NULL,
9607 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9610 TRUE, "previous page"
9613 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9614 &menu.setup.button.touch_next, NULL,
9615 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9621 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9622 &menu.setup.button.touch_back2, NULL,
9623 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9626 TRUE, "previous page"
9629 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9630 &menu.setup.button.touch_next2, NULL,
9631 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9640 int gfx_unpressed, gfx_pressed;
9644 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9647 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9648 -1, -1, // these values are not constant, but can change at runtime
9649 SCREEN_CTRL_ID_SCROLL_UP,
9653 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9654 -1, -1, // these values are not constant, but can change at runtime
9655 SCREEN_CTRL_ID_SCROLL_DOWN,
9662 int gfx_unpressed, gfx_pressed;
9668 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9671 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9672 -1, -1, // these values are not constant, but can change at runtime
9673 -1, -1, // these values are not constant, but can change at runtime
9674 GD_TYPE_SCROLLBAR_VERTICAL,
9675 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9676 "scroll level series vertically"
9688 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9691 IMG_SETUP_INPUT_TEXT,
9692 SCREEN_CTRL_ID_NETWORK_SERVER,
9693 -1, -1, // these values are not constant, but can change at runtime
9694 MAX_SETUP_TEXT_INPUT_LEN,
9695 network_server_hostname,
9696 "Network Server Hostname / IP"
9700 static void CreateScreenMenubuttons(void)
9702 struct GadgetInfo *gi;
9703 unsigned int event_mask;
9706 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9708 struct MenuPosInfo *pos = menubutton_info[i].pos;
9709 int screen_mask = menubutton_info[i].screen_mask;
9710 boolean is_touch_button = menubutton_info[i].is_touch_button;
9711 boolean is_check_button = menubutton_info[i].check_value != NULL;
9712 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9713 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9714 menubutton_info[i].gfx_unpressed);
9715 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9716 int gfx_unpressed, gfx_pressed;
9717 int x, y, width, height;
9718 int gd_x1, gd_x2, gd_y1, gd_y2;
9719 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9720 int id = menubutton_info[i].gadget_id;
9721 int type = GD_TYPE_NORMAL_BUTTON;
9722 boolean checked = FALSE;
9724 event_mask = menubutton_info[i].event_mask;
9726 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9727 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9729 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9730 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9732 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9733 gfx_pressed = menubutton_info[i].gfx_pressed;
9734 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9735 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9736 gd_x1 = graphic_info[gfx_unpressed].src_x;
9737 gd_y1 = graphic_info[gfx_unpressed].src_y;
9738 gd_x2 = graphic_info[gfx_pressed].src_x;
9739 gd_y2 = graphic_info[gfx_pressed].src_y;
9745 if (has_gfx_pressed)
9747 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9748 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9751 if (is_check_button)
9753 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9754 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9755 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9756 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9758 type = GD_TYPE_CHECK_BUTTON;
9759 checked = *menubutton_info[i].check_value;
9762 if (is_score_button)
9764 // if x/y set to -1, dynamically place buttons next to title text
9765 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9767 // special compatibility handling for "Snake Bite" graphics set
9768 if (strPrefix(leveldir_current->identifier, "snake_bite"))
9769 title_width = strlen(INFOTEXT_SCORE_ENTRY) * 32;
9771 // use "SX" here to center buttons (ignore horizontal draw offset)
9773 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9774 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9775 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9776 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9778 // use "mSY" here to place buttons (respect vertical draw offset)
9780 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
9781 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
9784 gi = CreateGadget(GDI_CUSTOM_ID, id,
9785 GDI_CUSTOM_TYPE_ID, i,
9786 GDI_IMAGE_ID, gfx_unpressed,
9787 GDI_INFO_TEXT, menubutton_info[i].infotext,
9793 GDI_STATE, GD_BUTTON_UNPRESSED,
9794 GDI_CHECKED, checked,
9795 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9796 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9797 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9798 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9799 GDI_DIRECT_DRAW, FALSE,
9800 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9801 GDI_EVENT_MASK, event_mask,
9802 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9806 Fail("cannot create gadget");
9808 screen_gadget[id] = gi;
9812 static void CreateScreenScrollbuttons(void)
9814 struct GadgetInfo *gi;
9815 unsigned int event_mask;
9818 // these values are not constant, but can change at runtime
9819 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9820 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9821 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9822 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9824 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9826 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9827 int gfx_unpressed, gfx_pressed;
9828 int x, y, width, height;
9829 int gd_x1, gd_x2, gd_y1, gd_y2;
9830 int id = scrollbutton_info[i].gadget_id;
9832 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9834 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9835 y = mSY + scrollbutton_info[i].y;
9836 width = SC_SCROLLBUTTON_XSIZE;
9837 height = SC_SCROLLBUTTON_YSIZE;
9839 // correct scrollbar position if placed outside menu (playfield) area
9840 if (x > SX + SC_SCROLL_UP_XPOS)
9841 x = SX + SC_SCROLL_UP_XPOS;
9843 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9844 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9845 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9847 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9848 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9849 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9850 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9851 gd_x1 = graphic_info[gfx_unpressed].src_x;
9852 gd_y1 = graphic_info[gfx_unpressed].src_y;
9853 gd_x2 = graphic_info[gfx_pressed].src_x;
9854 gd_y2 = graphic_info[gfx_pressed].src_y;
9856 gi = CreateGadget(GDI_CUSTOM_ID, id,
9857 GDI_CUSTOM_TYPE_ID, i,
9858 GDI_IMAGE_ID, gfx_unpressed,
9859 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9864 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9865 GDI_STATE, GD_BUTTON_UNPRESSED,
9866 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9867 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9868 GDI_DIRECT_DRAW, FALSE,
9869 GDI_EVENT_MASK, event_mask,
9870 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9874 Fail("cannot create gadget");
9876 screen_gadget[id] = gi;
9880 static void CreateScreenScrollbars(void)
9884 // these values are not constant, but can change at runtime
9885 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9886 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9887 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9888 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9890 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9892 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9893 int gfx_unpressed, gfx_pressed;
9894 int x, y, width, height;
9895 int gd_x1, gd_x2, gd_y1, gd_y2;
9896 struct GadgetInfo *gi;
9897 int items_max, items_visible, item_position;
9898 unsigned int event_mask;
9899 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9900 int id = scrollbar_info[i].gadget_id;
9902 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9904 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9905 y = mSY + scrollbar_info[i].y;
9906 width = scrollbar_info[i].width;
9907 height = scrollbar_info[i].height;
9909 // correct scrollbar position if placed outside menu (playfield) area
9910 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9911 x = SX + SC_SCROLL_VERTICAL_XPOS;
9913 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9914 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9916 items_max = num_page_entries;
9917 items_visible = num_page_entries;
9920 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9921 gfx_pressed = scrollbar_info[i].gfx_pressed;
9922 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9923 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9924 gd_x1 = graphic_info[gfx_unpressed].src_x;
9925 gd_y1 = graphic_info[gfx_unpressed].src_y;
9926 gd_x2 = graphic_info[gfx_pressed].src_x;
9927 gd_y2 = graphic_info[gfx_pressed].src_y;
9929 gi = CreateGadget(GDI_CUSTOM_ID, id,
9930 GDI_CUSTOM_TYPE_ID, i,
9931 GDI_IMAGE_ID, gfx_unpressed,
9932 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9937 GDI_TYPE, scrollbar_info[i].type,
9938 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9939 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9940 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9941 GDI_WHEEL_AREA_X, SX,
9942 GDI_WHEEL_AREA_Y, SY,
9943 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9944 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9945 GDI_STATE, GD_BUTTON_UNPRESSED,
9946 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9947 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9948 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9949 GDI_DIRECT_DRAW, FALSE,
9950 GDI_EVENT_MASK, event_mask,
9951 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9955 Fail("cannot create gadget");
9957 screen_gadget[id] = gi;
9961 static void CreateScreenTextInputGadgets(void)
9965 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9967 int graphic = textinput_info[i].graphic;
9968 struct GraphicInfo *gd = &graphic_info[graphic];
9969 int gd_x1 = gd->src_x;
9970 int gd_y1 = gd->src_y;
9971 int gd_x2 = gd->src_x + gd->active_xoffset;
9972 int gd_y2 = gd->src_y + gd->active_yoffset;
9973 struct GadgetInfo *gi;
9974 unsigned int event_mask;
9975 int id = textinput_info[i].gadget_id;
9976 int x = textinput_info[i].x;
9977 int y = textinput_info[i].y;
9979 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9981 gi = CreateGadget(GDI_CUSTOM_ID, id,
9982 GDI_CUSTOM_TYPE_ID, i,
9983 GDI_INFO_TEXT, textinput_info[i].infotext,
9986 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9987 GDI_TEXT_VALUE, textinput_info[i].value,
9988 GDI_TEXT_SIZE, textinput_info[i].size,
9989 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9990 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9991 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9992 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9993 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9994 GDI_DESIGN_WIDTH, gd->width,
9995 GDI_EVENT_MASK, event_mask,
9996 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9997 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10001 Fail("cannot create gadget");
10003 screen_gadget[id] = gi;
10007 void CreateScreenGadgets(void)
10009 CreateScreenMenubuttons();
10011 CreateScreenScrollbuttons();
10012 CreateScreenScrollbars();
10014 CreateScreenTextInputGadgets();
10017 void FreeScreenGadgets(void)
10021 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10022 FreeGadget(screen_gadget[i]);
10025 static void RedrawScreenMenuGadgets(int screen_mask)
10029 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10030 if (screen_mask & menubutton_info[i].screen_mask)
10031 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10034 static void MapScreenMenuGadgets(int screen_mask)
10038 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10039 if (screen_mask & menubutton_info[i].screen_mask)
10040 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10043 static void UnmapScreenMenuGadgets(int screen_mask)
10047 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10049 if (screen_mask & menubutton_info[i].screen_mask)
10051 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10053 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10054 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10055 screen_gadget[menubutton_info[i].gadget_id]->y,
10056 screen_gadget[menubutton_info[i].gadget_id]->width,
10057 screen_gadget[menubutton_info[i].gadget_id]->height);
10062 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10065 MapScreenMenuGadgets(screen_mask);
10067 UnmapScreenMenuGadgets(screen_mask);
10070 static void MapScreenGadgets(int num_entries)
10074 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10077 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10078 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10080 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10081 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10084 static void UnmapScreenGadgets()
10088 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10089 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10091 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10092 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10095 static void MapScreenTreeGadgets(TreeInfo *ti)
10097 MapScreenGadgets(numTreeInfoInGroup(ti));
10100 static void UnmapScreenTreeGadgets(void)
10102 UnmapScreenGadgets();
10105 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10107 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10108 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10109 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10110 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10112 if (pos_1->x == -1 && pos_1->y == -1)
10113 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10115 if (pos_2->x == -1 && pos_2->y == -1)
10116 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10119 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10121 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10122 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10124 // set gadget position dynamically, pre-defined or off-screen
10125 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10126 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10128 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10129 MapGadget(gi); // (needed if deactivated on last score page)
10132 static void HandleScreenGadgets(struct GadgetInfo *gi)
10134 int id = gi->custom_id;
10135 int button = gi->event.button;
10136 int step = (button == MB_LEFTBUTTON ? 1 :
10137 button == MB_MIDDLEBUTTON ? 5 :
10138 button == MB_RIGHTBUTTON ? 10 : 1);
10142 case SCREEN_CTRL_ID_PREV_LEVEL:
10143 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10146 case SCREEN_CTRL_ID_NEXT_LEVEL:
10147 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10150 case SCREEN_CTRL_ID_PREV_LEVEL2:
10151 HandleHallOfFame_SelectLevel(step, -1);
10154 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10155 HandleHallOfFame_SelectLevel(step, +1);
10158 case SCREEN_CTRL_ID_PREV_SCORE:
10159 HandleScoreInfo_SelectScore(step, -1);
10162 case SCREEN_CTRL_ID_NEXT_SCORE:
10163 HandleScoreInfo_SelectScore(step, +1);
10166 case SCREEN_CTRL_ID_PLAY_TAPE:
10167 HandleScoreInfo_PlayTape();
10170 case SCREEN_CTRL_ID_FIRST_LEVEL:
10171 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10174 case SCREEN_CTRL_ID_LAST_LEVEL:
10175 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10178 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10179 CloseDoor(DOOR_CLOSE_2);
10180 SetGameStatus(GAME_MODE_LEVELNR);
10181 DrawChooseLevelNr();
10184 case SCREEN_CTRL_ID_PREV_PLAYER:
10185 HandleSetupScreen_Input_Player(step, -1);
10188 case SCREEN_CTRL_ID_NEXT_PLAYER:
10189 HandleSetupScreen_Input_Player(step, +1);
10192 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10193 InsertSolutionTape();
10196 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10197 PlaySolutionTape();
10200 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10201 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10205 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10206 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10207 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10208 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10209 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10212 case SCREEN_CTRL_ID_SCROLL_UP:
10213 if (game_status == GAME_MODE_NAMES)
10214 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10215 else if (game_status == GAME_MODE_LEVELS)
10216 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10217 else if (game_status == GAME_MODE_LEVELNR)
10218 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10219 else if (game_status == GAME_MODE_SETUP)
10220 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10221 else if (game_status == GAME_MODE_INFO)
10222 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10223 else if (game_status == GAME_MODE_SCORES)
10224 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10227 case SCREEN_CTRL_ID_SCROLL_DOWN:
10228 if (game_status == GAME_MODE_NAMES)
10229 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10230 else if (game_status == GAME_MODE_LEVELS)
10231 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10232 else if (game_status == GAME_MODE_LEVELNR)
10233 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10234 else if (game_status == GAME_MODE_SETUP)
10235 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10236 else if (game_status == GAME_MODE_INFO)
10237 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10238 else if (game_status == GAME_MODE_SCORES)
10239 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10242 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10243 if (game_status == GAME_MODE_NAMES)
10244 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10245 else if (game_status == GAME_MODE_LEVELS)
10246 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10247 else if (game_status == GAME_MODE_LEVELNR)
10248 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10249 else if (game_status == GAME_MODE_SETUP)
10250 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10251 else if (game_status == GAME_MODE_INFO)
10252 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10253 else if (game_status == GAME_MODE_SCORES)
10254 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10257 case SCREEN_CTRL_ID_NETWORK_SERVER:
10259 if (!strEqual(gi->textinput.value, ""))
10261 setString(&setup.network_server_hostname, gi->textinput.value);
10263 network.server_host = setup.network_server_hostname;
10267 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10269 network.server_host = NULL;
10272 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10273 network.server_host = NULL;
10275 execSetupGame_setNetworkServerText();
10287 void HandleScreenGadgetKeys(Key key)
10289 if (key == setup.shortcut.tape_play)
10290 HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
10293 void DumpScreenIdentifiers(void)
10297 Print("Active screen elements on current screen:\n");
10299 for (i = 0; main_controls[i].nr != -1; i++)
10301 struct MainControlInfo *mci = &main_controls[i];
10303 if (mci->button_graphic != -1)
10305 char *token = getTokenFromImageID(mci->button_graphic);
10307 Print("- '%s'\n", token);
10314 boolean DoScreenAction(int image_id)
10318 if (game_status != GAME_MODE_MAIN)
10321 for (i = 0; main_controls[i].nr != -1; i++)
10323 struct MainControlInfo *mci = &main_controls[i];
10324 struct MenuPosInfo *pos = mci->pos_button;
10326 if (mci->button_graphic == image_id)
10328 int x = mSX + pos->x;
10329 int y = mSY + pos->y;
10331 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10340 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10342 // get tree info node of newly added level or artwork set
10343 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10344 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10346 if (tree_node_new == NULL) // should not happen
10349 // if request dialog is active, do nothing
10350 if (game.request_active)
10353 if (game_status == GAME_MODE_MAIN &&
10354 tree_type == TREE_TYPE_LEVEL_DIR)
10356 // when adding new level set in main menu, select it as current level set
10358 // change current level set to newly added level set from zip file
10359 leveldir_current = tree_node_new;
10361 // change current level number to first level of newly added level set
10362 level_nr = leveldir_current->first_level;
10364 // redraw screen to reflect changed level set
10367 // save this level set and level number as last selected level set
10368 SaveLevelSetup_LastSeries();
10369 SaveLevelSetup_SeriesInfo();
10371 else if (game_status == GAME_MODE_LEVELS &&
10372 tree_type == TREE_TYPE_LEVEL_DIR)
10374 // when adding new level set in level set menu, set cursor and update screen
10376 leveldir_current = tree_node_new;
10378 DrawChooseTree(&leveldir_current);
10380 else if (game_status == GAME_MODE_SETUP)
10382 // when adding new artwork set in setup menu, set cursor and update screen
10384 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10385 tree_type == TREE_TYPE_GRAPHICS_DIR)
10387 artwork.gfx_current = tree_node_new;
10389 DrawChooseTree(&artwork.gfx_current);
10391 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10392 tree_type == TREE_TYPE_SOUNDS_DIR)
10394 artwork.snd_current = tree_node_new;
10396 DrawChooseTree(&artwork.snd_current);
10398 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10399 tree_type == TREE_TYPE_MUSIC_DIR)
10401 artwork.mus_current = tree_node_new;
10403 DrawChooseTree(&artwork.mus_current);
10408 static int UploadTapes(void)
10410 SetGameStatus(GAME_MODE_LOADING);
10412 FadeSetEnterScreen();
10413 FadeOut(REDRAW_ALL);
10415 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10417 FadeIn(REDRAW_ALL);
10419 DrawInitTextHead("Uploading tapes");
10421 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10422 global.autoplay_leveldir = "ALL";
10423 global.autoplay_all = TRUE;
10425 int num_tapes_uploaded = AutoPlayTapes();
10427 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10428 global.autoplay_leveldir = NULL;
10429 global.autoplay_all = FALSE;
10431 SetGameStatus(GAME_MODE_MAIN);
10435 return num_tapes_uploaded;
10438 static boolean OfferUploadTapes(void)
10440 if (!Request(setup.has_remaining_tapes ?
10441 "Upload missing tapes to the high score server now?" :
10442 "Upload all your tapes to the high score server now?", REQ_ASK))
10445 int num_tapes_uploaded = UploadTapes();
10448 if (num_tapes_uploaded < 0)
10450 num_tapes_uploaded = -num_tapes_uploaded - 1;
10452 if (num_tapes_uploaded == 0)
10453 sprintf(message, "Upload failed! No tapes uploaded!");
10454 else if (num_tapes_uploaded == 1)
10455 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10457 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10458 num_tapes_uploaded);
10460 Request(message, REQ_CONFIRM);
10462 // if uploading tapes failed, add tape upload entry to setup menu
10463 setup.provide_uploading_tapes = TRUE;
10464 setup.has_remaining_tapes = TRUE;
10466 SaveSetup_ServerSetup();
10471 if (num_tapes_uploaded == 0)
10472 sprintf(message, "No tapes uploaded!");
10473 else if (num_tapes_uploaded == 1)
10474 sprintf(message, "1 tape uploaded!");
10476 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10478 Request(message, REQ_CONFIRM);
10480 if (num_tapes_uploaded > 0)
10481 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10483 // after all tapes have been uploaded, remove entry from setup menu
10484 setup.provide_uploading_tapes = FALSE;
10485 setup.has_remaining_tapes = FALSE;
10487 SaveSetup_ServerSetup();
10492 static void CheckUploadTapes(void)
10494 if (!setup.ask_for_uploading_tapes)
10497 // after asking for uploading tapes, do not ask again
10498 setup.ask_for_uploading_tapes = FALSE;
10499 setup.ask_for_remaining_tapes = FALSE;
10501 if (directoryExists(getTapeDir(NULL)))
10503 boolean tapes_uploaded = OfferUploadTapes();
10505 if (!tapes_uploaded)
10507 Request(setup.has_remaining_tapes ?
10508 "You can upload missing tapes from the setup menu later!" :
10509 "You can upload your tapes from the setup menu later!",
10515 // if tapes directory does not exist yet, never offer uploading all tapes
10516 setup.provide_uploading_tapes = FALSE;
10519 SaveSetup_ServerSetup();
10522 static void UpgradePlayerUUID(void)
10524 ApiResetUUIDAsThread(getUUID());
10527 static void CheckUpgradePlayerUUID(void)
10529 if (setup.player_version > 1)
10532 UpgradePlayerUUID();
10535 void CheckApiServerTasks(void)
10537 // check if the player's UUID has to be upgraded
10538 CheckUpgradePlayerUUID();
10540 // check if there are any tapes to be uploaded
10541 CheckUploadTapes();