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 // reset flag to continue playing next level from hall of fame
1725 scores.continue_playing = FALSE;
1727 // leveldir_current may be invalid (level group, parent link, node copy)
1728 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1730 if (leveldir_current != leveldir_last_valid)
1732 UpdateLastPlayedLevels_TreeInfo();
1734 levelset_has_changed = TRUE;
1737 // store valid level series information
1738 leveldir_last_valid = leveldir_current;
1740 // needed if last screen (level choice) changed graphics, sounds or music
1741 ReloadCustomArtwork(0);
1743 if (CheckTitleScreen(levelset_has_changed))
1745 SetGameStatus(GAME_MODE_TITLE);
1752 if (redraw_mask & REDRAW_ALL)
1753 fade_mask = REDRAW_ALL;
1756 fade_mask = REDRAW_ALL;
1760 // needed if different viewport properties defined for menues
1761 ChangeViewportPropertiesIfNeeded();
1763 SetDrawtoField(DRAW_TO_BACKBUFFER);
1765 // level_nr may have been set to value over handicap with level editor
1766 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1767 level_nr = leveldir_current->handicap_level;
1769 LoadLevel(level_nr);
1770 LoadScore(level_nr);
1772 SaveLevelSetup_SeriesInfo();
1774 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1775 SetDrawDeactivationMask(REDRAW_NONE);
1776 SetDrawBackgroundMask(REDRAW_FIELD);
1778 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1781 if (fade_mask == REDRAW_ALL)
1782 RedrawGlobalBorder();
1787 InitializeMainControls();
1789 DrawCursorAndText_Main(-1, FALSE, FALSE);
1790 DrawPreviewLevelInitial();
1791 DrawNetworkPlayers();
1793 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1796 if (TAPE_IS_EMPTY(tape))
1798 DrawCompleteVideoDisplay();
1800 PlayMenuSoundsAndMusic();
1802 // create gadgets for main menu screen
1803 FreeScreenGadgets();
1804 CreateScreenGadgets();
1806 // may be required if audio buttons shown on tape and changed in setup menu
1808 CreateGameButtons();
1810 // map gadgets for main menu screen
1812 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1813 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1815 // copy actual game door content to door double buffer for OpenDoor()
1816 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1817 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1819 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1821 DrawMaskedBorder(fade_mask);
1826 // update screen area with special editor door
1827 redraw_mask |= REDRAW_ALL;
1830 SetMouseCursor(CURSOR_DEFAULT);
1832 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1834 SyncEmscriptenFilesystem();
1836 // needed once after program start or after user change
1837 CheckApiServerTasks();
1840 static void gotoTopLevelDir(void)
1842 // move upwards until inside (but not above) top level directory
1843 while (leveldir_current->node_parent &&
1844 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1846 // write a "path" into level tree for easy navigation to last level
1847 if (leveldir_current->node_parent->node_group->cl_first == -1)
1849 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1850 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1851 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1852 int cl_first, cl_cursor;
1854 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1855 cl_cursor = leveldir_pos - cl_first;
1857 leveldir_current->node_parent->node_group->cl_first = cl_first;
1858 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1861 leveldir_current = leveldir_current->node_parent;
1865 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1867 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1869 return (use_frame_counter ? video.frame_counter : Counter());
1872 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1873 struct TitleFadingInfo *fi)
1875 return DelayReachedExt2(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1878 static void ResetTitleAutoDelay(unsigned int *counter_var,
1879 struct TitleFadingInfo *fi)
1881 *counter_var = getAutoDelayCounter(fi);
1884 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1886 static unsigned int title_delay = 0;
1887 static int title_screen_nr = 0;
1888 static int last_sound = -1, last_music = -1;
1889 boolean return_to_main_menu = FALSE;
1890 struct TitleControlInfo *tci;
1893 if (button == MB_MENU_INITIALIZE)
1896 title_screen_nr = 0;
1897 tci = &title_controls[title_screen_nr];
1899 SetAnimStatus(getTitleAnimMode(tci));
1901 last_sound = SND_UNDEFINED;
1902 last_music = MUS_UNDEFINED;
1904 if (num_title_screens != 0)
1906 FadeSetEnterScreen();
1908 // use individual title fading instead of global "enter screen" fading
1909 fading = getTitleFading(tci);
1912 if (game_status_last_screen == GAME_MODE_INFO)
1914 if (num_title_screens == 0)
1916 // switch game mode from title screen mode back to info screen mode
1917 SetGameStatus(GAME_MODE_INFO);
1919 // store that last screen was info screen, not main menu screen
1920 game_status_last_screen = GAME_MODE_INFO;
1922 DrawInfoScreen_NotAvailable("Title screen information:",
1923 "No title screen for this level set.");
1928 FadeMenuSoundsAndMusic();
1930 FadeOut(REDRAW_ALL);
1932 // title screens may have different window size
1933 ChangeViewportPropertiesIfNeeded();
1935 // only required to update logic for redrawing global border
1939 DrawTitleScreenImage(tci->local_nr, tci->initial);
1941 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1943 sound = getTitleSound(tci);
1944 music = getTitleMusic(tci);
1946 if (sound != last_sound)
1947 PlayMenuSoundExt(sound);
1948 if (music != last_music)
1949 PlayMenuMusicExt(music);
1954 SetMouseCursor(CURSOR_NONE);
1958 ResetTitleAutoDelay(&title_delay, &fading);
1963 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1964 button = MB_MENU_CHOICE;
1966 if (button == MB_MENU_LEAVE)
1968 return_to_main_menu = TRUE;
1970 else if (button == MB_MENU_CHOICE || dx)
1972 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1974 SetGameStatus(GAME_MODE_INFO);
1976 info_mode = INFO_MODE_MAIN;
1984 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
1986 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
1988 tci = &title_controls[title_screen_nr];
1990 SetAnimStatus(getTitleAnimMode(tci));
1992 sound = getTitleSound(tci);
1993 music = getTitleMusic(tci);
1995 if (last_sound != SND_UNDEFINED && sound != last_sound)
1996 FadeSound(last_sound);
1997 if (last_music != MUS_UNDEFINED && music != last_music)
2000 fading = getTitleFading(tci);
2002 FadeOut(REDRAW_ALL);
2005 DrawTitleScreenImage(tci->local_nr, tci->initial);
2007 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2009 sound = getTitleSound(tci);
2010 music = getTitleMusic(tci);
2012 if (sound != last_sound)
2013 PlayMenuSoundExt(sound);
2014 if (music != last_music)
2015 PlayMenuMusicExt(music);
2022 ResetTitleAutoDelay(&title_delay, &fading);
2026 FadeMenuSoundsAndMusic();
2028 return_to_main_menu = TRUE;
2032 if (return_to_main_menu)
2034 SetMouseCursor(CURSOR_DEFAULT);
2036 // force full menu screen redraw after displaying title screens
2037 redraw_mask = REDRAW_ALL;
2039 if (game_status_last_screen == GAME_MODE_INFO)
2041 SetGameStatus(GAME_MODE_INFO);
2043 info_mode = INFO_MODE_MAIN;
2047 else // default: return to main menu
2049 SetGameStatus(GAME_MODE_MAIN);
2056 static void HandleMainMenu_ToggleTeamMode(void)
2058 setup.team_mode = !setup.team_mode;
2060 InitializeMainControls();
2061 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2063 DrawPreviewPlayers();
2066 static void HandleMainMenu_SelectLevel(int step, int direction,
2067 int selected_level_nr)
2069 int old_level_nr = level_nr;
2072 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2073 new_level_nr = selected_level_nr;
2075 new_level_nr = old_level_nr + step * direction;
2077 if (new_level_nr < leveldir_current->first_level)
2078 new_level_nr = leveldir_current->first_level;
2079 if (new_level_nr > leveldir_current->last_level)
2080 new_level_nr = leveldir_current->last_level;
2082 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2084 // skipping levels is only allowed when trying to skip single level
2085 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2086 Request("Level still unsolved! Skip it anyway?", REQ_ASK))
2088 leveldir_current->handicap_level++;
2089 SaveLevelSetup_SeriesInfo();
2092 new_level_nr = leveldir_current->handicap_level;
2095 if (new_level_nr != old_level_nr)
2097 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2099 PlaySound(SND_MENU_ITEM_SELECTING);
2101 level_nr = new_level_nr;
2103 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2104 int2str(level_nr, menu.main.text.level_number.size),
2105 mci->pos_text->font);
2107 LoadLevel(level_nr);
2108 DrawPreviewLevelInitial();
2112 DrawCompleteVideoDisplay();
2114 SaveLevelSetup_SeriesInfo();
2116 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2118 // force redraw of playfield area (may be reset at this point)
2119 redraw_mask |= REDRAW_FIELD;
2123 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2125 static int choice = MAIN_CONTROL_GAME;
2126 static boolean button_pressed_last = FALSE;
2127 boolean button_pressed = FALSE;
2129 int i = 0; // needed to prevent compiler warning due to bad code below
2131 if (button == MB_MENU_INITIALIZE)
2133 DrawCursorAndText_Main(choice, TRUE, FALSE);
2138 if (mx || my) // mouse input
2142 for (i = 0; main_controls[i].nr != -1; i++)
2144 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2145 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2146 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2148 pos = main_controls[i].nr;
2154 // check if level preview was clicked
2155 if (insidePreviewRect(&preview, mx - SX, my - SY))
2156 pos = MAIN_CONTROL_GAME;
2158 // handle pressed/unpressed state for active/inactive menu buttons
2159 // (if pos != -1, "i" contains index position corresponding to "pos")
2161 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2162 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2163 button_pressed = TRUE;
2165 if (button_pressed != button_pressed_last)
2167 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2170 PlaySound(SND_MENU_BUTTON_PRESSING);
2172 PlaySound(SND_MENU_BUTTON_RELEASING);
2175 else if (dx || dy) // keyboard input
2177 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2178 choice == MAIN_CONTROL_SETUP))
2179 button = MB_MENU_CHOICE;
2184 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2186 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2188 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2190 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2192 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2194 CloseDoor(DOOR_CLOSE_2);
2196 SetGameStatus(GAME_MODE_LEVELNR);
2198 DrawChooseLevelNr();
2200 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2206 PlaySound(SND_MENU_ITEM_ACTIVATING);
2208 DrawCursorAndText_Main(choice, FALSE, FALSE);
2209 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2215 if (choice == MAIN_CONTROL_NAME)
2217 // special case: cursor left or right pressed -- toggle team mode
2218 HandleMainMenu_ToggleTeamMode();
2220 else if (choice != MAIN_CONTROL_INFO &&
2221 choice != MAIN_CONTROL_SETUP)
2223 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2229 PlaySound(SND_MENU_ITEM_SELECTING);
2231 if (pos == MAIN_CONTROL_NAME)
2234 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2236 // special case: menu text "name/team" clicked -- toggle team mode
2237 HandleMainMenu_ToggleTeamMode();
2241 if (setup.multiple_users)
2243 CloseDoor(DOOR_CLOSE_2);
2245 SetGameStatus(GAME_MODE_NAMES);
2247 DrawChoosePlayerName();
2251 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2257 else if (pos == MAIN_CONTROL_LEVELS)
2261 CloseDoor(DOOR_CLOSE_2);
2263 SetGameStatus(GAME_MODE_LEVELS);
2265 SaveLevelSetup_LastSeries();
2266 SaveLevelSetup_SeriesInfo();
2268 // restore level set if chosen from "last played level set" menu
2269 RestoreLastPlayedLevels(&leveldir_current);
2271 if (setup.internal.choose_from_top_leveldir)
2274 DrawChooseLevelSet();
2277 else if (pos == MAIN_CONTROL_SCORES)
2279 CloseDoor(DOOR_CLOSE_2);
2281 SetGameStatus(GAME_MODE_SCORES);
2283 DrawHallOfFame(level_nr);
2285 else if (pos == MAIN_CONTROL_EDITOR)
2287 if (leveldir_current->readonly &&
2288 setup.editor.show_read_only_warning)
2289 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2291 CloseDoor(DOOR_CLOSE_ALL);
2293 SetGameStatus(GAME_MODE_EDITOR);
2295 FadeSetEnterScreen();
2299 else if (pos == MAIN_CONTROL_INFO)
2301 CloseDoor(DOOR_CLOSE_2);
2303 SetGameStatus(GAME_MODE_INFO);
2305 info_mode = INFO_MODE_MAIN;
2309 else if (pos == MAIN_CONTROL_GAME)
2311 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2313 else if (pos == MAIN_CONTROL_SETUP)
2315 CloseDoor(DOOR_CLOSE_2);
2317 SetGameStatus(GAME_MODE_SETUP);
2319 setup_mode = SETUP_MODE_MAIN;
2323 else if (pos == MAIN_CONTROL_QUIT)
2325 SaveLevelSetup_LastSeries();
2326 SaveLevelSetup_SeriesInfo();
2328 #if defined(PLATFORM_EMSCRIPTEN)
2329 Request("Close the browser window to quit!", REQ_CONFIRM);
2331 if (!setup.ask_on_quit_program ||
2332 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2333 SetGameStatus(GAME_MODE_QUIT);
2339 button_pressed_last = button_pressed;
2343 // ============================================================================
2344 // info screen functions
2345 // ============================================================================
2347 static struct TokenInfo *info_info;
2348 static int num_info_info; // number of info entries shown on screen
2349 static int max_info_info; // total number of info entries in list
2351 static void execInfoTitleScreen(void)
2353 info_mode = INFO_MODE_TITLE;
2358 static void execInfoElements(void)
2360 info_mode = INFO_MODE_ELEMENTS;
2365 static void execInfoMusic(void)
2367 info_mode = INFO_MODE_MUSIC;
2372 static void execInfoCredits(void)
2374 info_mode = INFO_MODE_CREDITS;
2379 static void execInfoProgram(void)
2381 info_mode = INFO_MODE_PROGRAM;
2386 static void execInfoVersion(void)
2388 info_mode = INFO_MODE_VERSION;
2393 static void execInfoLevelSet(void)
2395 info_mode = INFO_MODE_LEVELSET;
2400 static void execExitInfo(void)
2402 SetGameStatus(GAME_MODE_MAIN);
2407 static struct TokenInfo info_info_main[] =
2409 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2410 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2411 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2412 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2413 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2414 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2415 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2416 { TYPE_EMPTY, NULL, "" },
2417 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2422 static int getMenuTextFont(int type)
2424 if (type & (TYPE_SWITCH |
2438 static struct TokenInfo *setup_info;
2439 static struct TokenInfo setup_info_input[];
2441 static struct TokenInfo *menu_info;
2443 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2444 int screen_pos, int menu_info_pos_raw,
2447 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2448 struct TokenInfo *ti = &token_info[pos];
2449 int xpos = MENU_SCREEN_START_XPOS;
2450 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2451 int font_nr = getMenuTextFont(ti->type);
2453 if (setup_mode == SETUP_MODE_INPUT)
2454 font_nr = FONT_MENU_1;
2457 font_nr = FONT_ACTIVE(font_nr);
2459 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2461 if (ti->type & ~TYPE_SKIP_ENTRY)
2462 drawCursor(screen_pos, active);
2465 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2468 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2471 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2474 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2477 static char *window_size_text;
2478 static char *scaling_type_text;
2479 static char *network_server_text;
2481 static void drawSetupValue(int, int);
2483 static void drawMenuInfoList(int first_entry, int num_page_entries,
2484 int max_page_entries)
2488 if (first_entry + num_page_entries > max_page_entries)
2491 clearMenuListArea();
2493 for (i = 0; i < num_page_entries; i++)
2495 int menu_info_pos = first_entry + i;
2496 struct TokenInfo *si = &menu_info[menu_info_pos];
2497 void *value_ptr = si->value;
2499 // set some entries to "unchangeable" according to other variables
2500 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2501 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2502 (value_ptr == &setup.sound_music && !audio.music_available) ||
2503 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2504 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2505 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2506 si->type |= TYPE_GHOSTED;
2508 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2509 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2510 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2511 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2512 else if (si->type & ~TYPE_SKIP_ENTRY)
2513 initCursor(i, IMG_MENU_BUTTON);
2515 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2517 if (si->type & TYPE_STRING)
2521 if (value_ptr == &network_server_text)
2522 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2524 if (gadget_id != -1)
2526 struct GadgetInfo *gi = screen_gadget[gadget_id];
2527 int xpos = MENU_SCREEN_START_XPOS;
2528 int ypos = MENU_SCREEN_START_YPOS + i;
2529 int x = mSX + xpos * 32;
2530 int y = mSY + ypos * 32;
2532 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2536 if (si->type & TYPE_VALUE &&
2537 menu_info == setup_info)
2538 drawSetupValue(i, menu_info_pos);
2542 static void DrawInfoScreen_Main(void)
2544 int fade_mask = REDRAW_FIELD;
2547 if (redraw_mask & REDRAW_ALL)
2548 fade_mask = REDRAW_ALL;
2551 fade_mask = REDRAW_ALL;
2554 FadeMenuSoundsAndMusic();
2556 FreeScreenGadgets();
2557 CreateScreenGadgets();
2559 // (needed after displaying title screens which disable auto repeat)
2560 KeyboardAutoRepeatOn();
2562 FadeSetLeaveScreen();
2566 // needed if different viewport properties defined for info screen
2567 ChangeViewportPropertiesIfNeeded();
2569 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2573 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2575 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2577 info_info = info_info_main;
2579 // use modified info screen info without info screen entries marked as hidden
2580 info_info = getSetupInfoFinal(info_info);
2582 // determine maximal number of info entries that can be displayed on screen
2584 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2587 // determine maximal number of info entries available for menu of info screen
2589 for (i = 0; info_info[i].type != 0; i++)
2592 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2594 MapScreenGadgets(max_info_info);
2596 PlayMenuSoundsAndMusic();
2598 DrawMaskedBorder(fade_mask);
2603 static void changeSetupValue(int, int, int);
2605 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2606 int mode, int num_page_entries,
2607 int max_page_entries)
2609 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2610 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2611 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2612 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2613 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2614 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2615 int *num_page_entries_last = num_page_entries_all_last[game_status];
2616 int *choice_store = choice_stores[game_status];
2617 int *first_entry_store = first_entry_stores[game_status];
2618 int choice = choice_store[mode]; // starts with 0
2619 int first_entry = first_entry_store[mode]; // starts with 0
2621 int y = choice - first_entry;
2623 boolean position_set_by_scrollbar = (dx == 999);
2624 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2627 if (button == MB_MENU_INITIALIZE)
2629 // check if number of menu page entries has changed (may happen by change
2630 // of custom artwork definition value for 'list_size' for this menu screen)
2631 // (in this case, the last menu position most probably has to be corrected)
2632 if (num_page_entries != num_page_entries_last[mode])
2634 choice_store[mode] = first_entry_store[mode] = 0;
2636 choice = first_entry = 0;
2639 num_page_entries_last[mode] = num_page_entries;
2642 // advance to first valid menu entry
2643 while (choice < num_page_entries &&
2644 menu_info[choice].type & TYPE_SKIP_ENTRY)
2647 if (position_set_by_scrollbar)
2648 first_entry = first_entry_store[mode] = dy;
2650 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2651 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2653 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2655 if (choice < first_entry)
2657 choice = first_entry;
2659 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2662 else if (choice > first_entry + num_page_entries - 1)
2664 choice = first_entry + num_page_entries - 1;
2666 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2670 choice_store[mode] = choice;
2672 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2676 else if (button == MB_MENU_LEAVE)
2678 PlaySound(SND_MENU_ITEM_SELECTING);
2680 for (i = 0; i < max_page_entries; i++)
2682 if (menu_info[i].type & TYPE_LEAVE_MENU)
2684 void (*menu_callback_function)(void) = menu_info[i].value;
2688 menu_callback_function();
2690 break; // absolutely needed because function changes 'menu_info'!
2697 if (mx || my) // mouse input
2699 x = (mx - mSX) / 32;
2700 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2702 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2704 // move cursor instead of scrolling when already at start/end of list
2705 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2707 else if (dy == +1 * SCROLL_LINE &&
2708 first_entry + num_page_entries == max_page_entries)
2711 // handle scrolling screen one line or page
2713 y + dy > num_page_entries - 1)
2715 boolean redraw = FALSE;
2717 if (ABS(dy) == SCROLL_PAGE)
2718 step = num_page_entries - 1;
2720 if (dy < 0 && first_entry > 0)
2722 // scroll page/line up
2724 first_entry -= step;
2725 if (first_entry < 0)
2730 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2732 // scroll page/line down
2734 first_entry += step;
2735 if (first_entry + num_page_entries > max_page_entries)
2736 first_entry = MAX(0, max_page_entries - num_page_entries);
2743 choice += first_entry - first_entry_store[mode];
2745 if (choice < first_entry)
2747 choice = first_entry;
2749 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2752 else if (choice > first_entry + num_page_entries - 1)
2754 choice = first_entry + num_page_entries - 1;
2756 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2759 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2763 if (choice < first_entry ||
2764 choice > first_entry + num_page_entries - 1)
2765 first_entry += SIGN(dy);
2768 first_entry_store[mode] = first_entry;
2769 choice_store[mode] = choice;
2771 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2773 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2775 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2776 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2784 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2786 if (menu_info[choice].type & menu_navigation_type ||
2787 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2788 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2789 menu_info[choice].type & TYPE_PLAYER)
2790 button = MB_MENU_CHOICE;
2795 // jump to next non-empty menu entry (up or down)
2796 while (first_entry + y > 0 &&
2797 first_entry + y < max_page_entries - 1 &&
2798 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2801 if (!IN_VIS_MENU(x, y))
2803 choice += y - y_old;
2805 if (choice < first_entry)
2806 first_entry = choice;
2807 else if (choice > first_entry + num_page_entries - 1)
2808 first_entry = choice - num_page_entries + 1;
2810 if (first_entry >= 0 &&
2811 first_entry + num_page_entries <= max_page_entries)
2813 first_entry_store[mode] = first_entry;
2815 if (choice < first_entry)
2816 choice = first_entry;
2817 else if (choice > first_entry + num_page_entries - 1)
2818 choice = first_entry + num_page_entries - 1;
2820 choice_store[mode] = choice;
2822 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2824 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2826 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2827 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2834 if (!anyScrollbarGadgetActive() &&
2835 IN_VIS_MENU(x, y) &&
2836 mx < mx_right_border &&
2837 y >= 0 && y < num_page_entries)
2841 if (first_entry + y != choice &&
2842 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2844 PlaySound(SND_MENU_ITEM_ACTIVATING);
2846 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2847 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2849 choice = choice_store[mode] = first_entry + y;
2853 PlaySound(SND_MENU_ITEM_SELECTING);
2855 for (i = 0; menu_info[i].type != 0; i++)
2857 if (menu_info[i].type & TYPE_LEAVE_MENU)
2859 void (*menu_callback_function)(void) = menu_info[i].value;
2863 menu_callback_function();
2865 // absolutely needed because function changes 'menu_info'!
2873 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2875 PlaySound(SND_MENU_ITEM_SELECTING);
2877 // when selecting key headline, execute function for key value change
2878 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2879 menu_info[first_entry + y + 1].type & TYPE_KEY)
2882 // when selecting string value, execute function for list selection
2883 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2884 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2887 // when selecting string value, execute function for text input gadget
2888 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2889 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2892 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2894 void (*menu_callback_function)(void) =
2895 menu_info[first_entry + y].value;
2897 FadeSetFromType(menu_info[first_entry + y].type);
2899 menu_callback_function();
2901 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2903 void (*gadget_callback_function)(void) =
2904 menu_info[first_entry + y].value;
2906 gadget_callback_function();
2908 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2909 menu_info == setup_info)
2911 changeSetupValue(y, first_entry + y, dx);
2917 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2919 menu_info = info_info;
2921 HandleMenuScreen(mx, my, dx, dy, button,
2922 info_mode, num_info_info, max_info_info);
2925 static int getMenuFontSpacing(int spacing_height, int font_nr)
2927 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2929 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2933 static int getMenuTextSpacing(int spacing_height, int font_nr)
2935 return (getMenuFontSpacing(spacing_height, font_nr) +
2936 EXTRA_SPACING(game_status));
2939 static int getMenuTextStep(int spacing_height, int font_nr)
2941 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2944 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2946 int font_title = MENU_INFO_FONT_TITLE;
2947 int font_error = FONT_TEXT_2;
2948 int font_foot = MENU_INFO_FONT_FOOT;
2949 int spacing_title = menu.headline1_spacing_info[info_mode];
2950 int ystep_title = getMenuTextStep(spacing_title, font_title);
2951 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2952 int ystart2 = ystart1 + ystep_title;
2953 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2955 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2957 FadeOut(REDRAW_FIELD);
2962 DrawTextSCentered(ystart1, font_title, text_title);
2963 DrawTextSCentered(ystart2, font_error, text_error);
2965 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
2967 FadeIn(REDRAW_FIELD);
2970 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2972 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2973 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2974 int font_title = MENU_INFO_FONT_TITLE;
2975 int font_foot = MENU_INFO_FONT_FOOT;
2976 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2977 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2978 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2979 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2980 int ystep = MENU_SCREEN_INFO_YSTEP;
2981 int element, action, direction;
2989 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2990 infoscreen_step[i] = infoscreen_frame[i] = 0;
2995 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2996 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3002 while (helpanim_info[j].element != HELPANIM_LIST_END)
3004 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
3009 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3018 j += infoscreen_step[i - start];
3020 element = helpanim_info[j].element;
3021 action = helpanim_info[j].action;
3022 direction = helpanim_info[j].direction;
3025 element = EL_UNKNOWN;
3027 if (action != -1 && direction != -1)
3028 graphic = el_act_dir2img(element, action, direction);
3029 else if (action != -1)
3030 graphic = el_act2img(element, action);
3031 else if (direction != -1)
3032 graphic = el_dir2img(element, direction);
3034 graphic = el2img(element);
3036 delay = helpanim_info[j++].delay;
3041 if (infoscreen_frame[i - start] == 0)
3044 infoscreen_frame[i - start] = delay - 1;
3048 sync_frame = delay - infoscreen_frame[i - start];
3049 infoscreen_frame[i - start]--;
3052 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3054 if (!infoscreen_frame[i - start])
3055 infoscreen_step[i - start] = 0;
3059 if (!infoscreen_frame[i - start])
3060 infoscreen_step[i - start]++;
3061 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3067 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3069 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3070 graphic, sync_frame, USE_MASKING);
3073 DrawInfoScreen_HelpText(element, action, direction, i - start);
3078 redraw_mask |= REDRAW_FIELD;
3083 static char *getHelpText(int element, int action, int direction)
3085 char token[MAX_LINE_LEN];
3087 strcpy(token, element_info[element].token_name);
3090 strcat(token, element_action_info[action].suffix);
3092 if (direction != -1)
3093 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3095 return getHashEntry(helptext_info, token);
3098 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3100 int font_nr = FONT_INFO_ELEMENTS;
3101 int font_width = getFontWidth(font_nr);
3102 int font_height = getFontHeight(font_nr);
3103 int yoffset = (TILEX - 2 * font_height) / 2;
3104 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3105 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3106 int ystep = TILEY + 4;
3107 int pad_left = xstart - SX;
3108 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3109 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3110 int max_lines_per_text = 2;
3113 if (action != -1 && direction != -1) // element.action.direction
3114 text = getHelpText(element, action, direction);
3116 if (text == NULL && action != -1) // element.action
3117 text = getHelpText(element, action, -1);
3119 if (text == NULL && direction != -1) // element.direction
3120 text = getHelpText(element, -1, direction);
3122 if (text == NULL) // base element
3123 text = getHelpText(element, -1, -1);
3125 if (text == NULL) // not found
3126 text = "No description available";
3128 if (strlen(text) <= max_chars_per_line) // only one line of text
3129 ystart += getFontHeight(font_nr) / 2;
3131 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3132 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3133 TRUE, FALSE, FALSE);
3136 static void DrawInfoScreen_TitleScreen(void)
3138 SetGameStatus(GAME_MODE_TITLE);
3143 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3145 HandleTitleScreen(0, 0, dx, dy, button);
3148 static void DrawInfoScreen_Elements(void)
3150 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3152 FadeOut(REDRAW_FIELD);
3157 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3159 FadeIn(REDRAW_FIELD);
3162 void HandleInfoScreen_Elements(int dx, int dy, int button)
3164 static DelayCounter info_delay = { 0 };
3165 static int num_anims;
3166 static int num_pages;
3168 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3171 info_delay.value = GameFrameDelay;
3173 if (button == MB_MENU_INITIALIZE)
3175 boolean new_element = TRUE;
3179 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3181 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3183 else if (new_element)
3186 new_element = FALSE;
3190 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3194 if (button == MB_MENU_LEAVE)
3196 PlaySound(SND_MENU_ITEM_SELECTING);
3198 info_mode = INFO_MODE_MAIN;
3203 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3205 if (button != MB_MENU_INITIALIZE)
3207 PlaySound(SND_MENU_ITEM_SELECTING);
3209 page += (dx < 0 ? -1 : +1);
3212 if (page < 0 || page >= num_pages)
3214 FadeMenuSoundsAndMusic();
3216 info_mode = INFO_MODE_MAIN;
3222 if (button != MB_MENU_INITIALIZE)
3223 FadeSetNextScreen();
3225 if (button != MB_MENU_INITIALIZE)
3226 FadeOut(REDRAW_FIELD);
3228 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3230 if (button != MB_MENU_INITIALIZE)
3231 FadeIn(REDRAW_FIELD);
3235 if (DelayReached(&info_delay))
3236 if (page < num_pages)
3237 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3239 PlayMenuSoundIfLoop();
3243 static void DrawInfoScreen_Music(void)
3245 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3247 FadeOut(REDRAW_FIELD);
3254 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3256 FadeIn(REDRAW_FIELD);
3259 void HandleInfoScreen_Music(int dx, int dy, int button)
3261 static struct MusicFileInfo *list = NULL;
3262 int font_title = MENU_INFO_FONT_TITLE;
3263 int font_head = MENU_INFO_FONT_HEAD;
3264 int font_text = MENU_INFO_FONT_TEXT;
3265 int font_foot = MENU_INFO_FONT_FOOT;
3266 int spacing_title = menu.headline1_spacing_info[info_mode];
3267 int spacing_head = menu.headline2_spacing_info[info_mode];
3268 int ystep_title = getMenuTextStep(spacing_title, font_title);
3269 int ystep_head = getMenuTextStep(spacing_head, font_head);
3270 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3271 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3273 if (button == MB_MENU_INITIALIZE)
3275 list = music_file_info;
3279 FadeMenuSoundsAndMusic();
3284 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3285 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3291 if (button == MB_MENU_LEAVE)
3293 PlaySound(SND_MENU_ITEM_SELECTING);
3295 FadeMenuSoundsAndMusic();
3297 info_mode = INFO_MODE_MAIN;
3302 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3304 if (button != MB_MENU_INITIALIZE)
3306 PlaySound(SND_MENU_ITEM_SELECTING);
3309 list = (dx < 0 ? list->prev : list->next);
3314 FadeMenuSoundsAndMusic();
3316 info_mode = INFO_MODE_MAIN;
3322 FadeMenuSoundsAndMusic();
3324 if (list != music_file_info)
3325 FadeSetNextScreen();
3327 if (button != MB_MENU_INITIALIZE)
3328 FadeOut(REDRAW_FIELD);
3335 int sound = list->music;
3337 if (IS_LOOP_SOUND(sound))
3338 PlaySoundLoop(sound);
3342 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3346 int music = list->music;
3348 if (IS_LOOP_MUSIC(music))
3349 PlayMusicLoop(music);
3353 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3356 ystart += ystep_title;
3358 if (!strEqual(list->title, UNKNOWN_NAME))
3360 if (!strEqual(list->title_header, UNKNOWN_NAME))
3362 DrawTextSCentered(ystart, font_head, list->title_header);
3363 ystart += ystep_head;
3366 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3367 ystart += ystep_head;
3370 if (!strEqual(list->artist, UNKNOWN_NAME))
3372 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3373 DrawTextSCentered(ystart, font_head, list->artist_header);
3375 DrawTextSCentered(ystart, font_head, "by");
3377 ystart += ystep_head;
3379 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3380 ystart += ystep_head;
3383 if (!strEqual(list->album, UNKNOWN_NAME))
3385 if (!strEqual(list->album_header, UNKNOWN_NAME))
3386 DrawTextSCentered(ystart, font_head, list->album_header);
3388 DrawTextSCentered(ystart, font_head, "from the album");
3390 ystart += ystep_head;
3392 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3393 ystart += ystep_head;
3396 if (!strEqual(list->year, UNKNOWN_NAME))
3398 if (!strEqual(list->year_header, UNKNOWN_NAME))
3399 DrawTextSCentered(ystart, font_head, list->year_header);
3401 DrawTextSCentered(ystart, font_head, "from the year");
3403 ystart += ystep_head;
3405 DrawTextFCentered(ystart, font_text, "%s", list->year);
3406 ystart += ystep_head;
3409 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3411 if (button != MB_MENU_INITIALIZE)
3412 FadeIn(REDRAW_FIELD);
3415 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3416 PlaySoundLoop(list->music);
3419 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3421 int font_title = MENU_INFO_FONT_TITLE;
3422 int font_text = MENU_INFO_FONT_TEXT;
3423 int font_foot = MENU_INFO_FONT_FOOT;
3424 int spacing_title = menu.headline1_spacing_info[info_mode];
3425 int spacing_line = menu.line_spacing_info[info_mode];
3426 int ystep_title = getMenuTextStep(spacing_title, font_title);
3427 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3428 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3433 DrawTextSCentered(ystart, font_title, "Credits:");
3435 char *filename = getCreditsFilename(screen_nr, use_global_credits_screens);
3437 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3438 int chars = width / getFontWidth(font_text);
3439 int lines = height / getFontHeight(font_text);
3440 int padx = (width - chars * getFontWidth(font_text)) / 2;
3441 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3442 boolean autowrap = FALSE;
3443 boolean centered = TRUE;
3444 boolean parse_comments = TRUE;
3446 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3447 filename, font_text, chars, -1, lines, line_spacing, -1,
3448 autowrap, centered, parse_comments);
3450 boolean last_screen = (screen_nr == num_credits_screens - 1);
3451 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3453 DrawTextSCentered(ybottom, font_foot, text_foot);
3456 static void DrawInfoScreen_Credits(void)
3458 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3460 FadeMenuSoundsAndMusic();
3462 FadeOut(REDRAW_FIELD);
3464 HandleInfoScreen_Credits(0, 0, MB_MENU_INITIALIZE);
3466 FadeIn(REDRAW_FIELD);
3469 void HandleInfoScreen_Credits(int dx, int dy, int button)
3471 static int screen_nr = 0;
3473 if (button == MB_MENU_INITIALIZE)
3477 // determine number of (global or level set specific) credits screens
3478 for (i = 0; i < 2; i++)
3480 num_credits_screens = 0;
3481 use_global_credits_screens = i;
3483 while (getCreditsFilename(num_credits_screens,
3484 use_global_credits_screens) != NULL)
3485 num_credits_screens++;
3487 if (num_credits_screens > 0)
3491 if (num_credits_screens == 0)
3493 int font_title = MENU_INFO_FONT_TITLE;
3494 int font_foot = MENU_INFO_FONT_FOOT;
3495 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3496 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3501 DrawTextSCentered(ystart, font_title, "No credits for this level set.");
3502 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3509 DrawInfoScreen_CreditsScreen(screen_nr);
3511 else if (button == MB_MENU_LEAVE)
3513 PlaySound(SND_MENU_ITEM_SELECTING);
3515 info_mode = INFO_MODE_MAIN;
3520 else if (button == MB_MENU_CHOICE || dx)
3522 PlaySound(SND_MENU_ITEM_SELECTING);
3524 screen_nr += (dx < 0 ? -1 : +1);
3526 if (screen_nr < 0 || screen_nr >= num_credits_screens)
3528 FadeMenuSoundsAndMusic();
3530 info_mode = INFO_MODE_MAIN;
3536 FadeSetNextScreen();
3538 FadeOut(REDRAW_FIELD);
3540 DrawInfoScreen_CreditsScreen(screen_nr);
3542 FadeIn(REDRAW_FIELD);
3546 PlayMenuSoundIfLoop();
3550 static void DrawInfoScreen_ProgramScreen(int screen_nr)
3552 int font_title = MENU_INFO_FONT_TITLE;
3553 int font_text = MENU_INFO_FONT_TEXT;
3554 int font_foot = MENU_INFO_FONT_FOOT;
3555 int spacing_title = menu.headline1_spacing_info[info_mode];
3556 int spacing_line = menu.line_spacing_info[info_mode];
3557 int ystep_title = getMenuTextStep(spacing_title, font_title);
3558 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3559 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3564 DrawTextSCentered(ystart, font_title, "Program Information:");
3566 char *filename = getProgramInfoFilename(screen_nr);
3568 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3569 int chars = width / getFontWidth(font_text);
3570 int lines = height / getFontHeight(font_text);
3571 int padx = (width - chars * getFontWidth(font_text)) / 2;
3572 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3573 boolean autowrap = FALSE;
3574 boolean centered = TRUE;
3575 boolean parse_comments = TRUE;
3577 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3578 filename, font_text, chars, -1, lines, line_spacing, -1,
3579 autowrap, centered, parse_comments);
3581 boolean last_screen = (screen_nr == num_program_info_screens - 1);
3582 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3584 DrawTextSCentered(ybottom, font_foot, text_foot);
3587 static void DrawInfoScreen_Program(void)
3589 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3591 FadeMenuSoundsAndMusic();
3593 FadeOut(REDRAW_FIELD);
3595 HandleInfoScreen_Program(0, 0, MB_MENU_INITIALIZE);
3597 FadeIn(REDRAW_FIELD);
3600 void HandleInfoScreen_Program(int dx, int dy, int button)
3602 static int screen_nr = 0;
3604 if (button == MB_MENU_INITIALIZE)
3606 // determine number of program info screens
3607 num_program_info_screens = 0;
3609 while (getProgramInfoFilename(num_program_info_screens) != NULL)
3610 num_program_info_screens++;
3612 if (num_program_info_screens == 0)
3614 int font_title = MENU_INFO_FONT_TITLE;
3615 int font_foot = MENU_INFO_FONT_FOOT;
3616 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3617 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3622 DrawTextSCentered(ystart, font_title, "No program info available.");
3623 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3630 DrawInfoScreen_ProgramScreen(screen_nr);
3632 else if (button == MB_MENU_LEAVE)
3634 PlaySound(SND_MENU_ITEM_SELECTING);
3636 info_mode = INFO_MODE_MAIN;
3641 else if (button == MB_MENU_CHOICE || dx)
3643 PlaySound(SND_MENU_ITEM_SELECTING);
3645 screen_nr += (dx < 0 ? -1 : +1);
3647 if (screen_nr < 0 || screen_nr >= num_program_info_screens)
3649 FadeMenuSoundsAndMusic();
3651 info_mode = INFO_MODE_MAIN;
3657 FadeSetNextScreen();
3659 FadeOut(REDRAW_FIELD);
3661 DrawInfoScreen_ProgramScreen(screen_nr);
3663 FadeIn(REDRAW_FIELD);
3667 PlayMenuSoundIfLoop();
3671 static void DrawInfoScreen_Version(void)
3673 int font_title = MENU_INFO_FONT_TITLE;
3674 int font_head = MENU_INFO_FONT_HEAD;
3675 int font_text = MENU_INFO_FONT_TEXT;
3676 int font_foot = MENU_INFO_FONT_FOOT;
3677 int spacing_title = menu.headline1_spacing_info[info_mode];
3678 int spacing_head = menu.headline2_spacing_info[info_mode];
3679 int spacing_para = menu.paragraph_spacing_info[info_mode];
3680 int spacing_line = menu.line_spacing_info[info_mode];
3681 int xstep = getFontWidth(font_text);
3682 int ystep_title = getMenuTextStep(spacing_title, font_title);
3683 int ystep_head = getMenuTextStep(spacing_head, font_head);
3684 int ystep_para = getMenuTextStep(spacing_para, font_text);
3685 int ystep_line = getMenuTextStep(spacing_line, font_text);
3686 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3687 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3688 int xstart1 = mSX - SX + 2 * xstep;
3689 int xstart2 = mSX - SX + 18 * xstep;
3690 int xstart3 = mSX - SX + 28 * xstep;
3691 SDL_version sdl_version_compiled;
3692 const SDL_version *sdl_version_linked;
3693 int driver_name_len = 10;
3694 SDL_version sdl_version_linked_ext;
3695 const char *driver_name = NULL;
3697 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3699 FadeOut(REDRAW_FIELD);
3704 DrawTextSCentered(ystart, font_title, "Version Information:");
3705 ystart += ystep_title;
3707 DrawTextF(xstart1, ystart, font_head, "Name");
3708 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3709 ystart += ystep_line;
3711 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3713 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3714 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3715 ystart += ystep_line;
3717 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3718 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3719 ystart += ystep_line;
3723 DrawTextF(xstart1, ystart, font_head, "Version");
3724 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3725 ystart += ystep_line;
3728 DrawTextF(xstart1, ystart, font_head, "Platform");
3729 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3731 PLATFORM_XX_BIT_STRING);
3732 ystart += ystep_line;
3734 DrawTextF(xstart1, ystart, font_head, "Target");
3735 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3736 ystart += ystep_line;
3738 DrawTextF(xstart1, ystart, font_head, "Source date");
3739 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3740 ystart += ystep_line;
3742 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3743 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3744 ystart += ystep_para;
3746 DrawTextF(xstart1, ystart, font_head, "Library");
3747 DrawTextF(xstart2, ystart, font_head, "compiled");
3748 DrawTextF(xstart3, ystart, font_head, "linked");
3749 ystart += ystep_head;
3751 SDL_VERSION(&sdl_version_compiled);
3752 SDL_GetVersion(&sdl_version_linked_ext);
3753 sdl_version_linked = &sdl_version_linked_ext;
3755 DrawTextF(xstart1, ystart, font_text, "SDL");
3756 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3757 sdl_version_compiled.major,
3758 sdl_version_compiled.minor,
3759 sdl_version_compiled.patch);
3760 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3761 sdl_version_linked->major,
3762 sdl_version_linked->minor,
3763 sdl_version_linked->patch);
3764 ystart += ystep_line;
3766 SDL_IMAGE_VERSION(&sdl_version_compiled);
3767 sdl_version_linked = IMG_Linked_Version();
3769 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3770 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3771 sdl_version_compiled.major,
3772 sdl_version_compiled.minor,
3773 sdl_version_compiled.patch);
3774 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3775 sdl_version_linked->major,
3776 sdl_version_linked->minor,
3777 sdl_version_linked->patch);
3778 ystart += ystep_line;
3780 SDL_MIXER_VERSION(&sdl_version_compiled);
3781 sdl_version_linked = Mix_Linked_Version();
3783 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3784 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3785 sdl_version_compiled.major,
3786 sdl_version_compiled.minor,
3787 sdl_version_compiled.patch);
3788 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3789 sdl_version_linked->major,
3790 sdl_version_linked->minor,
3791 sdl_version_linked->patch);
3792 ystart += ystep_line;
3794 SDL_NET_VERSION(&sdl_version_compiled);
3795 sdl_version_linked = SDLNet_Linked_Version();
3797 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3798 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3799 sdl_version_compiled.major,
3800 sdl_version_compiled.minor,
3801 sdl_version_compiled.patch);
3802 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3803 sdl_version_linked->major,
3804 sdl_version_linked->minor,
3805 sdl_version_linked->patch);
3806 ystart += ystep_para;
3808 DrawTextF(xstart1, ystart, font_head, "Driver");
3809 DrawTextF(xstart2, ystart, font_head, "Requested");
3810 DrawTextF(xstart3, ystart, font_head, "Used");
3811 ystart += ystep_head;
3814 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3816 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3817 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3818 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3819 ystart += ystep_line;
3822 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3824 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3825 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3826 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3827 ystart += ystep_line;
3830 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3832 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3833 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3834 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3836 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3838 FadeIn(REDRAW_FIELD);
3841 void HandleInfoScreen_Version(int button)
3843 if (button == MB_MENU_LEAVE)
3845 PlaySound(SND_MENU_ITEM_SELECTING);
3847 info_mode = INFO_MODE_MAIN;
3852 else if (button == MB_MENU_CHOICE)
3854 PlaySound(SND_MENU_ITEM_SELECTING);
3856 FadeMenuSoundsAndMusic();
3858 info_mode = INFO_MODE_MAIN;
3863 PlayMenuSoundIfLoop();
3867 static void DrawInfoScreen_LevelSet(void)
3869 struct TitleMessageInfo *tmi = &readme;
3870 char *filename = getLevelSetInfoFilename();
3871 char *title = "Level Set Information:";
3872 int font_foot = MENU_INFO_FONT_FOOT;
3873 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3874 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3876 if (filename == NULL)
3878 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3883 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3885 FadeOut(REDRAW_FIELD);
3890 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3892 // if x position set to "-1", automatically determine by playfield width
3894 tmi->x = SXSIZE / 2;
3896 // if y position set to "-1", use static default value
3900 // if width set to "-1", automatically determine by playfield width
3901 if (tmi->width == -1)
3902 tmi->width = SXSIZE - 2 * TILEX;
3904 // if height set to "-1", automatically determine by playfield height
3905 if (tmi->height == -1)
3906 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3908 // if chars set to "-1", automatically determine by text and font width
3909 if (tmi->chars == -1)
3910 tmi->chars = tmi->width / getFontWidth(tmi->font);
3912 tmi->width = tmi->chars * getFontWidth(tmi->font);
3914 // if lines set to "-1", automatically determine by text and font height
3915 if (tmi->lines == -1)
3916 tmi->lines = tmi->height / getFontHeight(tmi->font);
3918 tmi->height = tmi->lines * getFontHeight(tmi->font);
3920 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3921 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3922 tmi->autowrap, tmi->centered, tmi->parse_comments);
3924 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3926 FadeIn(REDRAW_FIELD);
3929 static void HandleInfoScreen_LevelSet(int button)
3931 if (button == MB_MENU_LEAVE)
3933 PlaySound(SND_MENU_ITEM_SELECTING);
3935 info_mode = INFO_MODE_MAIN;
3940 else if (button == MB_MENU_CHOICE)
3942 PlaySound(SND_MENU_ITEM_SELECTING);
3944 FadeMenuSoundsAndMusic();
3946 info_mode = INFO_MODE_MAIN;
3951 PlayMenuSoundIfLoop();
3955 static void DrawInfoScreen(void)
3957 if (info_mode == INFO_MODE_TITLE)
3958 DrawInfoScreen_TitleScreen();
3959 else if (info_mode == INFO_MODE_ELEMENTS)
3960 DrawInfoScreen_Elements();
3961 else if (info_mode == INFO_MODE_MUSIC)
3962 DrawInfoScreen_Music();
3963 else if (info_mode == INFO_MODE_CREDITS)
3964 DrawInfoScreen_Credits();
3965 else if (info_mode == INFO_MODE_PROGRAM)
3966 DrawInfoScreen_Program();
3967 else if (info_mode == INFO_MODE_VERSION)
3968 DrawInfoScreen_Version();
3969 else if (info_mode == INFO_MODE_LEVELSET)
3970 DrawInfoScreen_LevelSet();
3972 DrawInfoScreen_Main();
3974 if (info_mode != INFO_MODE_MAIN &&
3975 info_mode != INFO_MODE_TITLE &&
3976 info_mode != INFO_MODE_MUSIC)
3977 PlayMenuSoundsAndMusic();
3980 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3982 if (info_mode == INFO_MODE_TITLE)
3983 HandleInfoScreen_TitleScreen(dx, dy, button);
3984 else if (info_mode == INFO_MODE_ELEMENTS)
3985 HandleInfoScreen_Elements(dx, dy, button);
3986 else if (info_mode == INFO_MODE_MUSIC)
3987 HandleInfoScreen_Music(dx, dy, button);
3988 else if (info_mode == INFO_MODE_CREDITS)
3989 HandleInfoScreen_Credits(dx, dy, button);
3990 else if (info_mode == INFO_MODE_PROGRAM)
3991 HandleInfoScreen_Program(dx, dy, button);
3992 else if (info_mode == INFO_MODE_VERSION)
3993 HandleInfoScreen_Version(button);
3994 else if (info_mode == INFO_MODE_LEVELSET)
3995 HandleInfoScreen_LevelSet(button);
3997 HandleInfoScreen_Main(mx, my, dx, dy, button);
4001 // ============================================================================
4002 // type name functions
4003 // ============================================================================
4005 static TreeInfo *type_name_node = NULL;
4006 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4007 static int type_name_nr = 0;
4009 static int getPlayerNameColor(char *name)
4011 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4014 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4017 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4018 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4019 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4020 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4021 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4022 int font_width = getFontWidth(font_nr);
4023 int font_xoffset = getFontDrawOffsetX(font_nr);
4024 int font_yoffset = getFontDrawOffsetY(font_nr);
4025 int font_sx = sx + font_xoffset;
4026 int font_sy = sy + font_yoffset;
4028 DrawBackgroundForFont(font_sx, font_sy, pos->width, pos->height, font_nr);
4030 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4032 pos->width = strlen(text) * font_width;
4033 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4035 DrawText(sx, sy, text, font_nr);
4038 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4040 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4042 *pos = *mci->pos_input;
4044 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4046 TreeInfo *ti = player_name_current;
4047 int first_entry = ti->cl_first;
4048 int entry_pos = first_entry + ti->cl_cursor;
4049 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4050 int xpos = MENU_SCREEN_START_XPOS;
4051 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4053 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4054 type_name_nr = entry_pos;
4056 strcpy(name, type_name_node->name);
4060 pos->width = MAX_PLAYER_NAME_LEN * 32;
4064 type_name_nr = user.nr;
4066 strcpy(name, setup.player_name);
4069 strcpy(type_name_last, name);
4071 if (strEqual(name, EMPTY_PLAYER_NAME))
4074 *xpos = strlen(name);
4077 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4079 // change name of edited user in global list of user names
4080 setString(&global.user_names[type_name_nr], name);
4082 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4084 TreeInfo *node = type_name_node;
4086 // change name of edited user in local menu tree structure
4087 setString(&node->name, name);
4088 setString(&node->name_sorting, name);
4090 node->color = getPlayerNameColor(name);
4091 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4095 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4098 boolean reset_setup = strEqual(name, "");
4099 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4100 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4103 strcpy(name, type_name_last);
4105 if (strEqual(name, ""))
4106 strcpy(name, EMPTY_PLAYER_NAME);
4108 setTypeNameValues_Name(name, pos);
4110 // if player name not changed, no further action required
4111 if (strEqual(name, type_name_last))
4114 // redraw player name before (possibly) opening request dialogs
4115 drawTypeNameText(name, pos, FALSE);
4117 int last_user_nr = user.nr;
4119 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4121 // save setup of currently active user (may differ from edited user)
4124 // temporarily change active user to edited user
4125 user.nr = type_name_nr;
4128 Request("Use current setup values for the new player?", REQ_ASK))
4130 // use current setup values for new user, but create new player UUID
4131 setup.player_uuid = getStringCopy(getUUID());
4135 // load setup for existing user (or start with defaults for new user)
4140 char *setup_filename = getSetupFilename();
4141 boolean setup_exists = fileExists(setup_filename);
4143 // change name of edited user in setup structure
4144 strcpy(setup.player_name, name);
4146 // save setup of edited user
4149 // change name of edited user on score server
4150 ApiRenamePlayerAsThread();
4152 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4156 if (Request("Reset setup values for this player?", REQ_ASK))
4158 // remove setup config file
4159 unlink(setup_filename);
4161 // set player name to default player name
4164 // update player name used by name typing functions
4165 strcpy(name, setup.player_name);
4167 setTypeNameValues_Name(name, pos);
4170 else if (remove_user && type_name_nr != 0)
4172 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4174 char *user_dir = getUserGameDataDir();
4175 char *user_dir_removed =
4176 getStringCat3WithSeparator(user_dir, "REMOVED",
4177 getCurrentTimestamp(), ".");
4179 if (rename(user_dir, user_dir_removed) != 0)
4180 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4182 checked_free(user_dir_removed);
4185 else if (create_user && type_name_nr != 0 && !setup_exists)
4187 if (Request("Create empty level set for the new player?", REQ_ASK))
4189 char *levelset_subdir = getNewUserLevelSubdir();
4191 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4193 AddUserLevelSetToLevelInfo(levelset_subdir);
4195 LevelDirTree *leveldir_current_last = leveldir_current;
4197 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4200 // set level number of newly created level set to default value
4201 LoadLevelSetup_SeriesInfo();
4203 // set newly created level set as current level set for new user
4204 SaveLevelSetup_LastSeries();
4205 SaveLevelSetup_SeriesInfo();
4207 leveldir_current = leveldir_current_last;
4211 Request("Creating new level set failed!", REQ_CONFIRM);
4216 // restore currently active user
4217 user.nr = last_user_nr;
4219 // restore setup of currently active user
4222 // restore last level set of currently active user
4223 LoadLevelSetup_LastSeries();
4224 LoadLevelSetup_SeriesInfo();
4228 static void HandleTypeNameExt(boolean initialize, Key key)
4230 static struct TextPosInfo pos_name = { 0 };
4231 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4232 static int xpos = 0;
4233 struct TextPosInfo *pos = &pos_name;
4234 char key_char = getValidConfigValueChar(getCharFromKey(key));
4235 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4236 boolean active = TRUE;
4240 getTypeNameValues(name, pos, &xpos);
4242 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4243 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4245 StartTextInput(sx, sy, pos->width, pos->height);
4247 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4249 name[xpos] = key_char;
4254 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4260 else if (key == KSYM_Return || key == KSYM_Escape)
4262 boolean changed = (key == KSYM_Return);
4266 setTypeNameValues(name, pos, changed);
4271 drawTypeNameText(name, pos, active);
4275 SetGameStatus(game_status_last_screen);
4277 if (game_status == GAME_MODE_MAIN)
4278 InitializeMainControls();
4282 static void DrawTypeName(void)
4284 HandleTypeNameExt(TRUE, 0);
4287 void HandleTypeName(Key key)
4289 HandleTypeNameExt(FALSE, key);
4293 // ============================================================================
4294 // tree menu functions
4295 // ============================================================================
4297 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4299 if (game_status != GAME_MODE_SETUP ||
4300 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4303 int max_text_size = 0;
4306 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4307 max_text_size = MAX(max_text_size, strlen(node->name));
4309 int num_entries = numTreeInfoInGroup(ti);
4310 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4311 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4312 int text_width = max_text_size * getFontWidth(font_nr);
4313 int button_width = SC_MENUBUTTON_XSIZE;
4314 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4315 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4316 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4317 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4318 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4319 int align_xoffset = MAX(0, align_xoffset_raw);
4321 return align_xoffset;
4324 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4326 if (game_status != GAME_MODE_SETUP ||
4327 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4330 int num_entries = numTreeInfoInGroup(ti);
4331 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4332 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4333 int font_height = getFontHeight(font_nr);
4334 int text_height = font_height * num_page_entries;
4335 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4336 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4337 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4338 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4339 int align_yoffset = MAX(0, align_yoffset_raw);
4341 return align_yoffset;
4344 static void StartPlayingFromHallOfFame(void)
4346 level_nr = scores.next_level_nr;
4347 LoadLevel(level_nr);
4349 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4352 static void DrawChooseTree(TreeInfo **ti_ptr)
4354 int fade_mask = REDRAW_FIELD;
4355 boolean restart_music = (game_status != game_status_last_screen &&
4356 game_status_last_screen != GAME_MODE_SCOREINFO);
4358 scores.continue_on_return = (game_status == GAME_MODE_SCORES &&
4359 game_status_last_screen == GAME_MODE_PLAYING);
4362 fade_mask = REDRAW_ALL;
4364 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4366 if (game_status == GAME_MODE_SETUP)
4370 else if (game_status == GAME_MODE_SCORES && scores.continue_playing)
4372 StartPlayingFromHallOfFame();
4376 SetGameStatus(GAME_MODE_MAIN);
4386 FreeScreenGadgets();
4387 CreateScreenGadgets();
4390 FadeMenuSoundsAndMusic();
4394 // needed if different viewport properties defined for this screen
4395 ChangeViewportPropertiesIfNeeded();
4397 if (game_status == GAME_MODE_NAMES)
4398 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4399 else if (game_status == GAME_MODE_LEVELNR)
4400 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4401 else if (game_status == GAME_MODE_LEVELS)
4402 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4403 else if (game_status == GAME_MODE_SCORES)
4404 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4408 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4410 // map gadgets for high score screen
4411 if (game_status == GAME_MODE_SCORES)
4412 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4414 MapScreenTreeGadgets(*ti_ptr);
4416 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4418 DrawMaskedBorder(fade_mask);
4421 PlayMenuSoundsAndMusic();
4426 static int getChooseTreeFont(TreeInfo *node, boolean active)
4428 if (game_status == GAME_MODE_SCORES)
4429 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4431 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4434 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4436 int num_entries = numTreeInfoInGroup(ti);
4437 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4438 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4439 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4440 int first_entry = ti->cl_first;
4441 int entry_pos = first_entry + y;
4442 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4443 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4444 int font_nr = getChooseTreeFont(node, active);
4445 int font_xoffset = getFontDrawOffsetX(font_nr);
4446 int xpos = MENU_SCREEN_START_XPOS;
4447 int ypos = MENU_SCREEN_START_YPOS + y;
4448 int startdx = xpos * 32;
4449 int startdy = ypos * 32;
4450 int startx = amSX + startdx;
4451 int starty = amSY + startdy;
4452 int startx_text = startx + font_xoffset;
4453 int endx_text = amSX + screen_width;
4454 int max_text_size = endx_text - startx_text;
4455 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4456 char buffer[max_buffer_len + 1];
4458 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4460 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4461 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4462 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4463 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4464 int font_size_1 = getFontWidth(font_nr1);
4465 int font_size_3 = getFontWidth(font_nr3);
4466 int font_size_4 = getFontWidth(font_nr4);
4467 int text_size_1 = 4 * font_size_1;
4468 int text_size_4 = 5 * font_size_4;
4469 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4471 int dx3 = text_size_1;
4472 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4473 int num_dots = (dx4 - dx3) / font_size_3;
4474 int startx1 = startx + dx1;
4475 int startx3 = startx + dx3;
4476 int startx4 = startx + dx4;
4477 int pos = node->pos;
4478 char *pos_text = getHallOfFameRankText(pos, 3);
4481 DrawText(startx1, starty, pos_text, font_nr1);
4483 for (i = 0; i < num_dots; i++)
4484 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4486 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4487 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4489 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4493 strncpy(buffer, node->name, max_buffer_len);
4494 buffer[max_buffer_len] = '\0';
4496 DrawText(startx, starty, buffer, font_nr);
4500 static void drawChooseTreeHeadExt(int type, char *title_string)
4502 int yoffset_sets = MENU_TITLE1_YPOS;
4503 int yoffset_setup = 16;
4504 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4505 type == TREE_TYPE_LEVEL_DIR ||
4506 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4508 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4511 static void drawChooseTreeHead(TreeInfo *ti)
4513 drawChooseTreeHeadExt(ti->type, ti->infotext);
4516 static void drawChooseTreeList(TreeInfo *ti)
4518 int first_entry = ti->cl_first;
4519 int num_entries = numTreeInfoInGroup(ti);
4520 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4523 clearMenuListArea();
4525 for (i = 0; i < num_page_entries; i++)
4527 TreeInfo *node, *node_first;
4528 int entry_pos = first_entry + i;
4530 node_first = getTreeInfoFirstGroupEntry(ti);
4531 node = getTreeInfoFromPos(node_first, entry_pos);
4533 drawChooseTreeText(ti, i, FALSE);
4535 if (node->parent_link)
4536 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4537 else if (node->level_group)
4538 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4540 initCursor(i, IMG_MENU_BUTTON);
4542 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4543 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4545 if (game_status == GAME_MODE_NAMES)
4546 drawChooseTreeEdit(i, FALSE);
4549 redraw_mask |= REDRAW_FIELD;
4552 static void drawChooseTreeInfo(TreeInfo *ti)
4554 int entry_pos = ti->cl_first + ti->cl_cursor;
4555 int last_redraw_mask = redraw_mask;
4556 int ypos = MENU_TITLE2_YPOS;
4557 int font_nr = FONT_TITLE_2;
4560 if (ti->type == TREE_TYPE_LEVEL_NR)
4561 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4563 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4564 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4565 scores.last_level_nr);
4567 if (ti->type != TREE_TYPE_LEVEL_DIR)
4570 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4571 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4573 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4575 if (node->parent_link)
4576 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4577 node->node_parent->name);
4578 else if (node->level_group)
4579 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4581 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4582 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4583 node->levels, (node->levels > 1 ? "levels" : "level"),
4586 // let BackToFront() redraw only what is needed
4587 redraw_mask = last_redraw_mask;
4588 for (x = 0; x < SCR_FIELDX; x++)
4589 MarkTileDirty(x, 1);
4592 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4594 drawChooseTreeCursor(ti->cl_cursor, active);
4595 drawChooseTreeText(ti, ti->cl_cursor, active);
4598 static void drawChooseTreeScreen(TreeInfo *ti)
4600 drawChooseTreeHead(ti);
4601 drawChooseTreeList(ti);
4602 drawChooseTreeInfo(ti);
4603 drawChooseTreeCursorAndText(ti, TRUE);
4605 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4607 // scroll bar and buttons may just have been added after reloading scores
4608 if (game_status == GAME_MODE_SCORES)
4609 MapScreenTreeGadgets(ti);
4612 static void drawChooseTreeScreen_Scores_NotAvailable(void)
4614 // dirty workaround to use spacing definitions from info screen
4615 info_mode = INFO_MODE_TITLE;
4617 char *text_info = "HighScores of Level %d";
4618 char *text_title = "Score information:";
4619 char *text_error = "No scores for this level.";
4620 char *text_foot = "Press any key or button for main menu";
4621 int font_info = FONT_TITLE_2;
4622 int font_title = FONT_INITIAL_3;
4623 int font_error = FONT_INITIAL_4;
4624 int font_foot = FONT_INITIAL_2;
4625 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
4626 int ystep_title = getMenuTextStep(spacing_title, font_title);
4627 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
4628 int ystart2 = ystart1 + ystep_title;
4629 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4630 int ystart0 = MENU_TITLE2_YPOS;
4632 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
4633 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
4635 DrawTextSCentered(ystart1, font_title, text_title);
4636 DrawTextSCentered(ystart2, font_error, text_error);
4638 DrawTextSCentered(ybottom, font_foot, text_foot);
4641 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4643 int score_pos = scores.last_added;
4645 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4646 score_pos = scores.last_entry_nr;
4648 // set current tree entry to last added score entry
4649 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4651 // if that fails, set current tree entry to first entry (back link)
4652 if (*ti_ptr == NULL)
4653 *ti_ptr = score_entries->node_group;
4655 int num_entries = numTreeInfoInGroup(*ti_ptr);
4656 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4657 int pos_score = getPosFromTreeInfo(*ti_ptr);
4658 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4659 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4661 (*ti_ptr)->cl_first = pos_first;
4662 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4667 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4670 TreeInfo *ti = *ti_ptr;
4671 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4672 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4673 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4674 int sx1_edit_name = getChooseTreeEditXPosReal(POS_LEFT);
4675 int sx2_edit_name = getChooseTreeEditXPosReal(POS_RIGHT);
4677 int y = (ti != NULL ? ti->cl_cursor : 0);
4678 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4679 int num_entries = numTreeInfoInGroup(ti);
4680 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4681 boolean position_set_by_scrollbar = (dx == 999);
4682 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
4683 boolean button_is_valid = (mx >= 0 && my >= 0);
4684 boolean button_screen_clicked = (button_action && button_is_valid);
4686 if (game_status == GAME_MODE_SCORES)
4688 if (server_scores.updated)
4690 // reload scores, using updated server score cache file
4691 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4693 server_scores.updated = FALSE;
4695 DrawHallOfFame_setScoreEntries();
4697 if (score_entries != NULL)
4699 ti = setHallOfFameActiveEntry(ti_ptr);
4701 if (button != MB_MENU_INITIALIZE)
4702 drawChooseTreeScreen(ti);
4706 if (score_entries == NULL)
4708 if (button == MB_MENU_INITIALIZE)
4710 drawChooseTreeScreen_Scores_NotAvailable();
4712 else if (button_screen_clicked)
4714 PlaySound(SND_MENU_ITEM_SELECTING);
4716 SetGameStatus(GAME_MODE_MAIN);
4725 if (button == MB_MENU_INITIALIZE)
4727 int num_entries = numTreeInfoInGroup(ti);
4728 int entry_pos = getPosFromTreeInfo(ti);
4730 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4731 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4733 if (game_status == GAME_MODE_SCORES)
4735 ti = setHallOfFameActiveEntry(ti_ptr);
4737 else if (ti->cl_first == -1)
4739 // only on initialization
4740 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4741 ti->cl_cursor = entry_pos - ti->cl_first;
4744 else if (ti->cl_cursor >= num_page_entries ||
4745 (num_entries > num_page_entries &&
4746 num_entries - ti->cl_first < num_page_entries))
4748 // only after change of list size (by custom graphic configuration)
4749 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4750 ti->cl_cursor = entry_pos - ti->cl_first;
4753 if (position_set_by_scrollbar)
4756 drawChooseTreeScreen(ti);
4760 else if (button == MB_MENU_LEAVE)
4762 if (game_status != GAME_MODE_SCORES)
4765 PlaySound(SND_MENU_ITEM_SELECTING);
4767 if (ti->node_parent)
4769 *ti_ptr = ti->node_parent;
4770 DrawChooseTree(ti_ptr);
4772 else if (game_status == GAME_MODE_SETUP)
4774 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4775 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4776 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4777 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4779 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4780 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4781 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4782 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4783 execSetupGraphics();
4784 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4785 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4786 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4788 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4789 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4790 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4791 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4792 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4793 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4794 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4795 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4802 if (game_status == GAME_MODE_LEVELNR)
4804 int new_level_nr = atoi(level_number_current->identifier);
4806 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4809 SetGameStatus(GAME_MODE_MAIN);
4817 #if defined(PLATFORM_ANDROID)
4818 // directly continue when touching the screen after playing
4819 if ((mx || my) && scores.continue_on_return)
4821 // ignore touch events until released
4826 // any mouse click or cursor key stops leaving scores by "Return" key
4827 if ((mx || my || dx || dy) && scores.continue_on_return)
4829 scores.continue_on_return = FALSE;
4830 level_nr = scores.last_level_nr;
4831 LoadLevel(level_nr);
4834 if (mx || my) // mouse input
4836 x = (mx - amSX) / 32;
4837 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4839 if (game_status == GAME_MODE_NAMES)
4840 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4842 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4844 // move cursor instead of scrolling when already at start/end of list
4845 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4847 else if (dy == +1 * SCROLL_LINE &&
4848 ti->cl_first + num_page_entries == num_entries)
4851 // handle scrolling screen one line or page
4852 if (ti->cl_cursor + dy < 0 ||
4853 ti->cl_cursor + dy > num_page_entries - 1)
4855 boolean redraw = FALSE;
4857 if (ABS(dy) == SCROLL_PAGE)
4858 step = num_page_entries - 1;
4860 if (dy < 0 && ti->cl_first > 0)
4862 // scroll page/line up
4864 ti->cl_first -= step;
4865 if (ti->cl_first < 0)
4870 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4872 // scroll page/line down
4874 ti->cl_first += step;
4875 if (ti->cl_first + num_page_entries > num_entries)
4876 ti->cl_first = MAX(0, num_entries - num_page_entries);
4882 drawChooseTreeScreen(ti);
4887 // handle moving cursor one line
4888 y = ti->cl_cursor + dy;
4891 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
4893 HandleHallOfFame_SelectLevel(1, dx);
4899 TreeInfo *node_first, *node_cursor;
4900 int entry_pos = ti->cl_first + y;
4902 node_first = getTreeInfoFirstGroupEntry(ti);
4903 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4905 if (node_cursor->node_group)
4909 PlaySound(SND_MENU_ITEM_SELECTING);
4911 node_cursor->cl_first = ti->cl_first;
4912 node_cursor->cl_cursor = ti->cl_cursor;
4914 *ti_ptr = node_cursor->node_group;
4915 DrawChooseTree(ti_ptr);
4920 else if ((dx == -1 || button == MB_MENU_CONTINUE) && ti->node_parent)
4922 if (game_status != GAME_MODE_SCORES)
4925 PlaySound(SND_MENU_ITEM_SELECTING);
4927 *ti_ptr = ti->node_parent;
4928 DrawChooseTree(ti_ptr);
4933 if (!anyScrollbarGadgetActive() &&
4934 IN_VIS_MENU(x, y) &&
4935 mx < mx_right_border &&
4936 y >= 0 && y < num_page_entries)
4940 if (game_status == GAME_MODE_NAMES)
4942 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4943 drawChooseTreeEdit(y, TRUE);
4946 if (y != ti->cl_cursor)
4948 PlaySound(SND_MENU_ITEM_ACTIVATING);
4950 drawChooseTreeCursorAndText(ti, FALSE);
4954 drawChooseTreeCursorAndText(ti, TRUE);
4956 drawChooseTreeInfo(ti);
4960 if (game_status == GAME_MODE_SETUP)
4962 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4963 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4964 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4965 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4967 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4968 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4969 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4970 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4971 execSetupGraphics();
4972 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4973 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4974 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4976 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4977 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4978 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4979 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4980 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4981 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4982 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4983 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4992 TreeInfo *node_first, *node_cursor;
4993 int entry_pos = ti->cl_first + y;
4995 PlaySound(SND_MENU_ITEM_SELECTING);
4997 node_first = getTreeInfoFirstGroupEntry(ti);
4998 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5000 if (node_cursor->node_group)
5004 node_cursor->cl_first = ti->cl_first;
5005 node_cursor->cl_cursor = ti->cl_cursor;
5007 *ti_ptr = node_cursor->node_group;
5008 DrawChooseTree(ti_ptr);
5010 else if (node_cursor->parent_link)
5012 if (game_status != GAME_MODE_SCORES)
5015 *ti_ptr = node_cursor->node_parent;
5016 DrawChooseTree(ti_ptr);
5020 if (game_status != GAME_MODE_SCORES)
5023 node_cursor->cl_first = ti->cl_first;
5024 node_cursor->cl_cursor = ti->cl_cursor;
5026 *ti_ptr = node_cursor;
5028 if (ti->type == TREE_TYPE_LEVEL_DIR)
5030 LoadLevelSetup_SeriesInfo();
5032 SaveLevelSetup_LastSeries();
5033 SaveLevelSetup_SeriesInfo();
5037 if (game_status == GAME_MODE_SETUP)
5039 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5040 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5041 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5042 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5044 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5045 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5046 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5047 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5048 execSetupGraphics();
5049 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5050 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5051 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5053 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5054 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5055 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5056 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5057 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5058 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5059 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5060 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5067 if (game_status == GAME_MODE_LEVELNR)
5069 int new_level_nr = atoi(level_number_current->identifier);
5071 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5073 else if (game_status == GAME_MODE_LEVELS)
5075 // store level set if chosen from "last played level set" menu
5076 StoreLastPlayedLevels(leveldir_current);
5078 else if (game_status == GAME_MODE_NAMES)
5080 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5082 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5089 // change active user to selected user
5090 user.nr = entry_pos;
5092 // save number of new active user
5095 // load setup of new active user
5098 // load last level set of new active user
5099 LoadLevelSetup_LastSeries();
5100 LoadLevelSetup_SeriesInfo();
5102 // update list of last played level sets
5103 UpdateLastPlayedLevels_TreeInfo();
5107 ToggleFullscreenIfNeeded();
5108 ChangeWindowScalingIfNeeded();
5110 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5111 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5112 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5114 else if (game_status == GAME_MODE_SCORES)
5116 if (scores.continue_playing && scores.continue_on_return)
5118 StartPlayingFromHallOfFame();
5122 else if (!scores.continue_on_return)
5124 SetGameStatus(GAME_MODE_SCOREINFO);
5126 DrawScoreInfo(node_cursor->pos);
5132 SetGameStatus(GAME_MODE_MAIN);
5140 if (game_status == GAME_MODE_SCORES)
5141 PlayMenuSoundIfLoop();
5144 void DrawChoosePlayerName(void)
5148 if (player_name != NULL)
5150 freeTreeInfo(player_name);
5155 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5157 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5158 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5161 ti->node_top = &player_name;
5162 ti->sort_priority = 10000 + value;
5163 ti->color = getPlayerNameColor(global.user_names[i]);
5165 snprintf(identifier, sizeof(identifier), "%d", value);
5166 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5168 setString(&ti->identifier, identifier);
5169 setString(&ti->name, name);
5170 setString(&ti->name_sorting, name);
5172 pushTreeInfo(&player_name, ti);
5175 // sort player entries by player number
5176 sortTreeInfo(&player_name);
5178 // set current player entry to selected player entry
5179 player_name_current =
5180 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5182 // if that fails, set current player name to first available name
5183 if (player_name_current == NULL)
5184 player_name_current = player_name;
5186 // set text size for main name input (also used on name selection screen)
5187 InitializeMainControls();
5189 DrawChooseTree(&player_name_current);
5192 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5194 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5197 void DrawChooseLevelSet(void)
5199 DrawChooseTree(&leveldir_current);
5202 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5204 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5207 void DrawChooseLevelNr(void)
5211 if (level_number != NULL)
5213 freeTreeInfo(level_number);
5215 level_number = NULL;
5218 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5220 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5221 char identifier[32], name[64];
5224 // temporarily load level info to get level name
5225 LoadLevelInfoOnly(i);
5227 ti->node_top = &level_number;
5228 ti->sort_priority = 10000 + value;
5229 ti->color = (level.no_level_file ? FC_BLUE :
5230 LevelStats_getSolved(i) ? FC_GREEN :
5231 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5233 snprintf(identifier, sizeof(identifier), "%d", value);
5234 snprintf(name, sizeof(name), "%03d: %s", value,
5235 (level.no_level_file ? "(no file)" : level.name));
5237 setString(&ti->identifier, identifier);
5238 setString(&ti->name, name);
5239 setString(&ti->name_sorting, name);
5241 pushTreeInfo(&level_number, ti);
5244 // sort level number values to start with lowest level number
5245 sortTreeInfo(&level_number);
5247 // set current level number to current level number
5248 level_number_current =
5249 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5251 // if that also fails, set current level number to first available level
5252 if (level_number_current == NULL)
5253 level_number_current = level_number;
5255 DrawChooseTree(&level_number_current);
5258 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5260 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5263 static void DrawHallOfFame_setScoreEntries(void)
5265 int max_empty_entries = 10; // at least show "top ten" list, if empty
5266 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5267 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5268 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5271 if (score_entries != NULL)
5273 freeTreeInfo(score_entries);
5275 score_entries = NULL;
5278 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5280 // do not add empty score entries if off-screen
5281 if (scores.entry[i].score == 0 &&
5282 scores.entry[i].time == 0 &&
5283 i >= min_score_entries)
5286 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5287 char identifier[32], name[64];
5290 ti->node_top = &score_entries;
5291 ti->sort_priority = 10000 + value;
5292 ti->color = FC_YELLOW;
5295 snprintf(identifier, sizeof(identifier), "%d", value);
5296 snprintf(name, sizeof(name), "%03d.", value + 1);
5298 setString(&ti->identifier, identifier);
5299 setString(&ti->name, name);
5300 setString(&ti->name_sorting, name);
5302 pushTreeInfo(&score_entries, ti);
5305 // sort score entries to start with highest score entry
5306 sortTreeInfo(&score_entries);
5308 // add top tree node to create back link to main menu
5309 score_entries = addTopTreeInfoNode(score_entries);
5311 // set current score entry to last added or highest score entry
5312 score_entry_current =
5313 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5315 // if that fails, set current score entry to first valid score entry
5316 if (score_entry_current == NULL)
5317 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5319 if (score_entries != NULL && scores.continue_playing)
5320 setString(&score_entries->node_group->name, BACKLINK_TEXT_NEXT);
5322 // ("score_entries" and "score_entry_current" may be NULL here)
5325 void DrawHallOfFame(int nr)
5327 scores.last_level_nr = nr;
5329 // (this is needed when called from GameEnd() after winning a game)
5330 KeyboardAutoRepeatOn();
5332 // (this is needed when called from GameEnd() after winning a game)
5333 SetDrawDeactivationMask(REDRAW_NONE);
5334 SetDrawBackgroundMask(REDRAW_FIELD);
5336 LoadLocalAndServerScore(scores.last_level_nr, TRUE);
5338 DrawHallOfFame_setScoreEntries();
5340 if (scores.last_added >= 0)
5341 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5343 FadeSetEnterScreen();
5345 DrawChooseTree(&score_entry_current);
5348 static char *getHallOfFameRankText(int nr, int size)
5350 static char rank_text[10];
5351 boolean forced = (scores.force_last_added && nr == scores.last_added);
5352 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5354 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5359 static char *getHallOfFameTimeText(int nr)
5361 static char score_text[10];
5362 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5363 int mm = (time_seconds / 60) % 60;
5364 int ss = (time_seconds % 60);
5366 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5371 static char *getHallOfFameScoreText(int nr, int size)
5373 if (!level.rate_time_over_score)
5374 return int2str(scores.entry[nr].score, size); // show normal score
5375 else if (level.use_step_counter)
5376 return int2str(scores.entry[nr].time, size); // show number of steps
5378 return getHallOfFameTimeText(nr); // show playing time
5381 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5383 static char tape_date[MAX_ISO_DATE_LEN + 1];
5386 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5387 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5388 return entry->tape_date;
5390 for (i = 0, j = 0; i < 8; i++, j++)
5392 tape_date[j] = entry->tape_basename[i];
5394 if (i == 3 || i == 5)
5395 tape_date[++j] = '-';
5398 tape_date[MAX_ISO_DATE_LEN] = '\0';
5403 static void HandleHallOfFame_SelectLevel(int step, int direction)
5405 int old_level_nr = scores.last_level_nr;
5406 int new_level_nr = old_level_nr + step * direction;
5408 if (new_level_nr < leveldir_current->first_level)
5409 new_level_nr = leveldir_current->first_level;
5410 if (new_level_nr > leveldir_current->last_level)
5411 new_level_nr = leveldir_current->last_level;
5413 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5414 new_level_nr = leveldir_current->handicap_level;
5416 if (new_level_nr != old_level_nr)
5418 PlaySound(SND_MENU_ITEM_SELECTING);
5420 scores.last_level_nr = level_nr = new_level_nr;
5421 scores.last_entry_nr = 0;
5423 LoadLevel(level_nr);
5424 LoadLocalAndServerScore(level_nr, TRUE);
5426 DrawHallOfFame_setScoreEntries();
5428 if (game_status == GAME_MODE_SCORES)
5430 // force remapping optional gadgets (especially scroll bar)
5431 UnmapScreenTreeGadgets();
5433 // redraw complete high score screen, as sub-title has changed
5436 // redraw level selection buttons (which have just been erased)
5437 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5439 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5443 DrawScoreInfo_Content(scores.last_entry_nr);
5446 SaveLevelSetup_SeriesInfo();
5450 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5452 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5455 static void DrawScoreInfo_Content(int entry_nr)
5457 struct ScoreEntry *entry = &scores.entry[entry_nr];
5458 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5459 char *tape_date = getHallOfFameTapeDateText(entry);
5460 int font_title = MENU_INFO_FONT_TITLE;
5461 int font_head = MENU_INFO_FONT_HEAD;
5462 int font_text = MENU_INFO_FONT_TEXT;
5463 int font_foot = MENU_INFO_FONT_FOOT;
5464 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5465 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5466 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5467 int xstep = getFontWidth(font_text);
5468 int ystep_title = getMenuTextStep(spacing_title, font_title);
5469 int ystep_para = getMenuTextStep(spacing_para, font_text);
5470 int ystep_line = getMenuTextStep(spacing_line, font_text);
5471 int xstart = mSX - SX + menu.left_spacing[GAME_MODE_SCOREINFO];
5472 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5473 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5474 int xstart1 = xstart + xstep;
5475 int xstart2 = xstart + xstep * 12;
5476 int select_x = SX + xstart1;
5477 int select_y1, select_y2;
5479 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5480 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5481 int font_width = getFontWidth(font_text);
5482 int font_height = getFontHeight(font_text);
5483 int tape_date_width = getTextWidth(tape_date, font_text);
5484 int pad_left = xstart2;
5485 int pad_right = menu.right_spacing[GAME_MODE_SCOREINFO];
5486 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5487 int max_lines_per_text = 5;
5492 // redraw level selection buttons (which have just been erased)
5493 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5495 if (score_entries == NULL)
5497 drawChooseTreeScreen_Scores_NotAvailable();
5502 drawChooseTreeHead(score_entries);
5503 drawChooseTreeInfo(score_entries);
5505 DrawTextSCentered(ystart, font_title, "Score Information:");
5506 ystart += ystep_title;
5508 DrawTextF(xstart1, ystart, font_head, "Level Set");
5509 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5510 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5511 TRUE, FALSE, FALSE);
5512 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5514 DrawTextF(xstart1, ystart, font_head, "Level");
5515 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5516 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5517 TRUE, FALSE, FALSE);
5518 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5520 select_y1 = SY + ystart;
5521 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5523 DrawTextF(xstart1, ystart, font_head, "Rank");
5524 DrawTextF(xstart2, ystart, font_text, pos_text);
5525 ystart += ystep_line;
5527 DrawTextF(xstart1, ystart, font_head, "Player");
5528 DrawTextF(xstart2, ystart, font_text, entry->name);
5529 ystart += ystep_line;
5531 if (level.use_step_counter)
5533 DrawTextF(xstart1, ystart, font_head, "Steps");
5534 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5535 ystart += ystep_line;
5539 DrawTextF(xstart1, ystart, font_head, "Time");
5540 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5541 ystart += ystep_line;
5544 if (!level.rate_time_over_score || entry->score > 0)
5546 DrawTextF(xstart1, ystart, font_head, "Score");
5547 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5548 ystart += ystep_line;
5551 ystart += ystep_line;
5553 play_x = SX + xstart2 + tape_date_width + font_width;
5554 play_y = SY + ystart + (font_height - play_height) / 2;
5556 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5557 DrawTextF(xstart2, ystart, font_text, tape_date);
5558 ystart += ystep_line;
5560 DrawTextF(xstart1, ystart, font_head, "Platform");
5561 DrawTextF(xstart2, ystart, font_text, entry->platform);
5562 ystart += ystep_line;
5564 DrawTextF(xstart1, ystart, font_head, "Version");
5565 DrawTextF(xstart2, ystart, font_text, entry->version);
5566 ystart += ystep_line;
5568 DrawTextF(xstart1, ystart, font_head, "Country");
5569 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5570 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5571 TRUE, FALSE, FALSE);
5572 ystart += ystep_line;
5574 select_y2 = SY + ystart;
5576 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5578 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5579 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5582 static void DrawScoreInfo(int entry_nr)
5584 scores.last_entry_nr = entry_nr;
5585 score_info_tape_play = FALSE;
5589 FreeScreenGadgets();
5590 CreateScreenGadgets();
5592 FadeOut(REDRAW_FIELD);
5594 // needed if different viewport properties defined after playing score tape
5595 ChangeViewportPropertiesIfNeeded();
5597 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
5598 SetDrawDeactivationMask(REDRAW_NONE);
5599 SetDrawBackgroundMask(REDRAW_FIELD);
5601 // needed if different background image defined after playing score tape
5602 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5603 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5605 // special compatibility handling for "Snake Bite" graphics set
5606 if (strPrefix(leveldir_current->identifier, "snake_bite"))
5607 ClearRectangle(gfx.background_bitmap, gfx.real_sx, gfx.real_sy + 64,
5608 gfx.full_sxsize, gfx.full_sysize - 64);
5610 DrawScoreInfo_Content(entry_nr);
5612 // map gadgets for score info screen
5613 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5615 FadeIn(REDRAW_FIELD);
5618 static void HandleScoreInfo_SelectScore(int step, int direction)
5620 int old_entry_nr = scores.last_entry_nr;
5621 int new_entry_nr = old_entry_nr + step * direction;
5622 int num_nodes = numTreeInfoInGroup(score_entry_current);
5623 int num_entries = num_nodes - 1; // score nodes only, without back link
5625 if (new_entry_nr < 0)
5627 if (new_entry_nr > num_entries - 1)
5628 new_entry_nr = num_entries - 1;
5630 if (new_entry_nr != old_entry_nr)
5632 scores.last_entry_nr = new_entry_nr;
5634 DrawScoreInfo_Content(new_entry_nr);
5638 static void HandleScoreInfo_PlayTape(void)
5640 if (!PlayScoreTape(scores.last_entry_nr))
5642 DrawScoreInfo_Content(scores.last_entry_nr);
5644 FadeIn(REDRAW_FIELD);
5648 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5650 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5651 boolean button_is_valid = (mx >= 0 && my >= 0);
5652 boolean button_screen_clicked = (button_action && button_is_valid);
5654 if (server_scores.updated)
5656 // reload scores, using updated server score cache file
5657 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5659 server_scores.updated = FALSE;
5661 DrawHallOfFame_setScoreEntries();
5663 DrawScoreInfo_Content(scores.last_entry_nr);
5666 if (button_screen_clicked)
5668 PlaySound(SND_MENU_ITEM_SELECTING);
5670 SetGameStatus(GAME_MODE_SCORES);
5672 DrawHallOfFame(scores.last_level_nr);
5676 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5680 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5685 // ============================================================================
5686 // setup screen functions
5687 // ============================================================================
5689 static struct TokenInfo *setup_info;
5690 static int num_setup_info; // number of setup entries shown on screen
5691 static int max_setup_info; // total number of setup entries in list
5693 static char *window_size_text;
5694 static char *scaling_type_text;
5695 static char *rendering_mode_text;
5696 static char *vsync_mode_text;
5697 static char *scroll_delay_text;
5698 static char *snapshot_mode_text;
5699 static char *game_speed_text;
5700 static char *scores_type_text;
5701 static char *network_server_text;
5702 static char *graphics_set_name;
5703 static char *sounds_set_name;
5704 static char *music_set_name;
5705 static char *volume_simple_text;
5706 static char *volume_loops_text;
5707 static char *volume_music_text;
5708 static char *touch_controls_text;
5709 static char *move_distance_text;
5710 static char *drop_distance_text;
5711 static char *transparency_text;
5712 static char *grid_size_text[2][2];
5714 static void execSetupMain(void)
5716 setup_mode = SETUP_MODE_MAIN;
5721 static void execSetupGame_setScoresType(void)
5723 if (scores_types == NULL)
5727 for (i = 0; scores_types_list[i].value != NULL; i++)
5729 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5730 char identifier[32], name[32];
5731 char *value = scores_types_list[i].value;
5732 char *text = scores_types_list[i].text;
5734 ti->node_top = &scores_types;
5735 ti->sort_priority = i;
5737 sprintf(identifier, "%s", value);
5738 sprintf(name, "%s", text);
5740 setString(&ti->identifier, identifier);
5741 setString(&ti->name, name);
5742 setString(&ti->name_sorting, name);
5743 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5745 pushTreeInfo(&scores_types, ti);
5748 // sort scores type values to start with lowest scores type value
5749 sortTreeInfo(&scores_types);
5751 // set current scores type value to configured scores type value
5752 scores_type_current =
5753 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5755 // if that fails, set current scores type to reliable default value
5756 if (scores_type_current == NULL)
5757 scores_type_current =
5758 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5760 // if that also fails, set current scores type to first available value
5761 if (scores_type_current == NULL)
5762 scores_type_current = scores_types;
5765 setup.scores_in_highscore_list = scores_type_current->identifier;
5767 // needed for displaying scores type text instead of identifier
5768 scores_type_text = scores_type_current->name;
5771 static void execSetupGame_setGameSpeeds(boolean update_value)
5773 if (setup.game_speed_extended)
5775 game_speeds_list = game_speeds_list_extended;
5776 game_speeds = game_speeds_extended;
5780 game_speeds_list = game_speeds_list_normal;
5781 game_speeds = game_speeds_normal;
5784 if (game_speeds == NULL)
5788 for (i = 0; game_speeds_list[i].value != -1; i++)
5790 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5791 char identifier[32], name[32];
5792 int value = game_speeds_list[i].value;
5793 char *text = game_speeds_list[i].text;
5795 ti->node_top = &game_speeds;
5796 ti->sort_priority = 10000 - value;
5798 sprintf(identifier, "%d", value);
5799 sprintf(name, "%s", text);
5801 setString(&ti->identifier, identifier);
5802 setString(&ti->name, name);
5803 setString(&ti->name_sorting, name);
5804 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5806 pushTreeInfo(&game_speeds, ti);
5809 // sort game speed values to start with slowest game speed
5810 sortTreeInfo(&game_speeds);
5812 update_value = TRUE;
5817 // set current game speed to configured game speed value
5818 game_speed_current =
5819 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5821 // if that fails, set current game speed to reliable default value
5822 if (game_speed_current == NULL)
5823 game_speed_current =
5824 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5826 // if that also fails, set current game speed to first available speed
5827 if (game_speed_current == NULL)
5828 game_speed_current = game_speeds;
5830 if (setup.game_speed_extended)
5831 game_speeds_extended = game_speeds;
5833 game_speeds_normal = game_speeds;
5836 setup.game_frame_delay = atoi(game_speed_current->identifier);
5838 // needed for displaying game speed text instead of identifier
5839 game_speed_text = game_speed_current->name;
5842 static void execSetupGame_setScrollDelays(void)
5844 if (scroll_delays == NULL)
5848 for (i = 0; scroll_delays_list[i].value != -1; i++)
5850 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5851 char identifier[32], name[32];
5852 int value = scroll_delays_list[i].value;
5853 char *text = scroll_delays_list[i].text;
5855 ti->node_top = &scroll_delays;
5856 ti->sort_priority = value;
5858 sprintf(identifier, "%d", value);
5859 sprintf(name, "%s", text);
5861 setString(&ti->identifier, identifier);
5862 setString(&ti->name, name);
5863 setString(&ti->name_sorting, name);
5864 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5866 pushTreeInfo(&scroll_delays, ti);
5869 // sort scroll delay values to start with lowest scroll delay value
5870 sortTreeInfo(&scroll_delays);
5872 // set current scroll delay value to configured scroll delay value
5873 scroll_delay_current =
5874 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5876 // if that fails, set current scroll delay to reliable default value
5877 if (scroll_delay_current == NULL)
5878 scroll_delay_current =
5879 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5881 // if that also fails, set current scroll delay to first available value
5882 if (scroll_delay_current == NULL)
5883 scroll_delay_current = scroll_delays;
5886 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5888 // needed for displaying scroll delay text instead of identifier
5889 scroll_delay_text = scroll_delay_current->name;
5892 static void execSetupGame_setSnapshotModes(void)
5894 if (snapshot_modes == NULL)
5898 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5900 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5901 char identifier[32], name[32];
5902 char *value = snapshot_modes_list[i].value;
5903 char *text = snapshot_modes_list[i].text;
5905 ti->node_top = &snapshot_modes;
5906 ti->sort_priority = i;
5908 sprintf(identifier, "%s", value);
5909 sprintf(name, "%s", text);
5911 setString(&ti->identifier, identifier);
5912 setString(&ti->name, name);
5913 setString(&ti->name_sorting, name);
5914 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5916 pushTreeInfo(&snapshot_modes, ti);
5919 // sort snapshot mode values to start with lowest snapshot mode value
5920 sortTreeInfo(&snapshot_modes);
5922 // set current snapshot mode value to configured snapshot mode value
5923 snapshot_mode_current =
5924 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5926 // if that fails, set current snapshot mode to reliable default value
5927 if (snapshot_mode_current == NULL)
5928 snapshot_mode_current =
5929 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5931 // if that also fails, set current snapshot mode to first available value
5932 if (snapshot_mode_current == NULL)
5933 snapshot_mode_current = snapshot_modes;
5936 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5938 // needed for displaying snapshot mode text instead of identifier
5939 snapshot_mode_text = snapshot_mode_current->name;
5942 static void execSetupGame_setNetworkServerText(void)
5944 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5946 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5950 strncpy(network_server_hostname, setup.network_server_hostname,
5951 MAX_SETUP_TEXT_INPUT_LEN);
5952 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5955 // needed for displaying network server text instead of identifier
5956 network_server_text = network_server_hostname;
5959 static void execSetupGame(void)
5961 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5963 execSetupGame_setGameSpeeds(FALSE);
5964 execSetupGame_setScoresType();
5965 execSetupGame_setScrollDelays();
5966 execSetupGame_setSnapshotModes();
5968 execSetupGame_setNetworkServerText();
5970 if (!setup.provide_uploading_tapes)
5971 setHideSetupEntry(execOfferUploadTapes);
5973 setup_mode = SETUP_MODE_GAME;
5977 // check if vsync needs to be disabled for this game speed to work
5978 if (check_vsync_mode)
5979 DisableVsyncIfNeeded();
5982 static void execSetupChooseScoresType(void)
5984 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
5989 static void execSetupChooseGameSpeed(void)
5991 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5996 static void execSetupChooseScrollDelay(void)
5998 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6003 static void execSetupChooseSnapshotMode(void)
6005 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6010 static void execSetupEngines(void)
6012 setup_mode = SETUP_MODE_ENGINES;
6017 static void execSetupEditor(void)
6019 setup_mode = SETUP_MODE_EDITOR;
6024 static void execSetupGraphics_setWindowSizes(boolean update_list)
6026 if (window_sizes != NULL && update_list)
6028 freeTreeInfo(window_sizes);
6030 window_sizes = NULL;
6033 if (window_sizes == NULL)
6035 boolean current_window_size_found = FALSE;
6038 for (i = 0; window_sizes_list[i].value != -1; i++)
6040 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6041 char identifier[32], name[32];
6042 int value = window_sizes_list[i].value;
6043 char *text = window_sizes_list[i].text;
6045 ti->node_top = &window_sizes;
6046 ti->sort_priority = value;
6048 sprintf(identifier, "%d", value);
6049 sprintf(name, "%s", text);
6051 setString(&ti->identifier, identifier);
6052 setString(&ti->name, name);
6053 setString(&ti->name_sorting, name);
6054 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6056 pushTreeInfo(&window_sizes, ti);
6058 if (value == setup.window_scaling_percent)
6059 current_window_size_found = TRUE;
6062 if (!current_window_size_found)
6064 // add entry for non-preset window scaling value
6066 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6067 char identifier[32], name[32];
6068 int value = setup.window_scaling_percent;
6070 ti->node_top = &window_sizes;
6071 ti->sort_priority = value;
6073 sprintf(identifier, "%d", value);
6074 sprintf(name, "%d %% (Current)", value);
6076 setString(&ti->identifier, identifier);
6077 setString(&ti->name, name);
6078 setString(&ti->name_sorting, name);
6079 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6081 pushTreeInfo(&window_sizes, ti);
6084 // sort window size values to start with lowest window size value
6085 sortTreeInfo(&window_sizes);
6087 // set current window size value to configured window size value
6088 window_size_current =
6089 getTreeInfoFromIdentifier(window_sizes,
6090 i_to_a(setup.window_scaling_percent));
6092 // if that fails, set current window size to reliable default value
6093 if (window_size_current == NULL)
6094 window_size_current =
6095 getTreeInfoFromIdentifier(window_sizes,
6096 i_to_a(STD_WINDOW_SCALING_PERCENT));
6098 // if that also fails, set current window size to first available value
6099 if (window_size_current == NULL)
6100 window_size_current = window_sizes;
6103 setup.window_scaling_percent = atoi(window_size_current->identifier);
6105 // needed for displaying window size text instead of identifier
6106 window_size_text = window_size_current->name;
6109 static void execSetupGraphics_setScalingTypes(void)
6111 if (scaling_types == NULL)
6115 for (i = 0; scaling_types_list[i].value != NULL; i++)
6117 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6118 char identifier[32], name[32];
6119 char *value = scaling_types_list[i].value;
6120 char *text = scaling_types_list[i].text;
6122 ti->node_top = &scaling_types;
6123 ti->sort_priority = i;
6125 sprintf(identifier, "%s", value);
6126 sprintf(name, "%s", text);
6128 setString(&ti->identifier, identifier);
6129 setString(&ti->name, name);
6130 setString(&ti->name_sorting, name);
6131 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6133 pushTreeInfo(&scaling_types, ti);
6136 // sort scaling type values to start with lowest scaling type value
6137 sortTreeInfo(&scaling_types);
6139 // set current scaling type value to configured scaling type value
6140 scaling_type_current =
6141 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6143 // if that fails, set current scaling type to reliable default value
6144 if (scaling_type_current == NULL)
6145 scaling_type_current =
6146 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6148 // if that also fails, set current scaling type to first available value
6149 if (scaling_type_current == NULL)
6150 scaling_type_current = scaling_types;
6153 setup.window_scaling_quality = scaling_type_current->identifier;
6155 // needed for displaying scaling type text instead of identifier
6156 scaling_type_text = scaling_type_current->name;
6159 static void execSetupGraphics_setRenderingModes(void)
6161 if (rendering_modes == NULL)
6165 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6167 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6168 char identifier[32], name[32];
6169 char *value = rendering_modes_list[i].value;
6170 char *text = rendering_modes_list[i].text;
6172 ti->node_top = &rendering_modes;
6173 ti->sort_priority = i;
6175 sprintf(identifier, "%s", value);
6176 sprintf(name, "%s", text);
6178 setString(&ti->identifier, identifier);
6179 setString(&ti->name, name);
6180 setString(&ti->name_sorting, name);
6181 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6183 pushTreeInfo(&rendering_modes, ti);
6186 // sort rendering mode values to start with lowest rendering mode value
6187 sortTreeInfo(&rendering_modes);
6189 // set current rendering mode value to configured rendering mode value
6190 rendering_mode_current =
6191 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6193 // if that fails, set current rendering mode to reliable default value
6194 if (rendering_mode_current == NULL)
6195 rendering_mode_current =
6196 getTreeInfoFromIdentifier(rendering_modes,
6197 STR_SPECIAL_RENDERING_DEFAULT);
6199 // if that also fails, set current rendering mode to first available one
6200 if (rendering_mode_current == NULL)
6201 rendering_mode_current = rendering_modes;
6204 setup.screen_rendering_mode = rendering_mode_current->identifier;
6206 // needed for displaying rendering mode text instead of identifier
6207 rendering_mode_text = rendering_mode_current->name;
6210 static void execSetupGraphics_setVsyncModes(boolean update_value)
6212 if (vsync_modes == NULL)
6216 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6218 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6219 char identifier[32], name[32];
6220 char *value = vsync_modes_list[i].value;
6221 char *text = vsync_modes_list[i].text;
6223 ti->node_top = &vsync_modes;
6224 ti->sort_priority = i;
6226 sprintf(identifier, "%s", value);
6227 sprintf(name, "%s", text);
6229 setString(&ti->identifier, identifier);
6230 setString(&ti->name, name);
6231 setString(&ti->name_sorting, name);
6232 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6234 pushTreeInfo(&vsync_modes, ti);
6237 // sort vsync mode values to start with lowest vsync mode value
6238 sortTreeInfo(&vsync_modes);
6240 update_value = TRUE;
6245 // set current vsync mode value to configured vsync mode value
6246 vsync_mode_current =
6247 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6249 // if that fails, set current vsync mode to reliable default value
6250 if (vsync_mode_current == NULL)
6251 vsync_mode_current =
6252 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6254 // if that also fails, set current vsync mode to first available one
6255 if (vsync_mode_current == NULL)
6256 vsync_mode_current = vsync_modes;
6259 setup.vsync_mode = vsync_mode_current->identifier;
6261 // needed for displaying vsync mode text instead of identifier
6262 vsync_mode_text = vsync_mode_current->name;
6265 static void execSetupGraphics(void)
6267 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6269 // update "setup.window_scaling_percent" from list selection
6270 // (in this case, window scaling was changed on setup screen)
6271 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6272 execSetupGraphics_setWindowSizes(FALSE);
6274 // update "setup.vsync_mode" from list selection
6275 // (in this case, vsync mode was changed on setup screen)
6276 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6277 execSetupGraphics_setVsyncModes(FALSE);
6279 // update list selection from "setup.window_scaling_percent"
6280 // (window scaling may have changed by resizing the window)
6281 execSetupGraphics_setWindowSizes(TRUE);
6283 // update list selection from "setup.vsync_mode"
6284 // (vsync_mode may have changed by re-creating the renderer)
6285 execSetupGraphics_setVsyncModes(TRUE);
6287 execSetupGraphics_setScalingTypes();
6288 execSetupGraphics_setRenderingModes();
6290 setup_mode = SETUP_MODE_GRAPHICS;
6294 // check if game speed is high enough for 60 Hz vsync to work
6295 if (check_game_speed)
6296 ModifyGameSpeedIfNeeded();
6298 // window scaling may have changed at this point
6299 ChangeWindowScalingIfNeeded();
6301 // window scaling quality may have changed at this point
6302 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6303 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6305 // screen rendering mode may have changed at this point
6306 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6308 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6309 int video_vsync_mode = video.vsync_mode;
6311 // screen vsync mode may have changed at this point
6312 ChangeVsyncModeIfNeeded();
6314 // check if setting vsync mode to selected value failed
6315 if (setup_vsync_mode != video_vsync_mode &&
6316 setup_vsync_mode != video.vsync_mode)
6318 // changing vsync mode to selected value failed -- reset displayed value
6319 execSetupGraphics_setVsyncModes(TRUE);
6321 Request("Setting VSync failed!", REQ_CONFIRM);
6327 static void execSetupChooseWindowSize(void)
6329 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6334 static void execSetupChooseScalingType(void)
6336 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6341 static void execSetupChooseRenderingMode(void)
6343 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6348 static void execSetupChooseVsyncMode(void)
6350 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6355 static void execSetupChooseVolumeSimple(void)
6357 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6362 static void execSetupChooseVolumeLoops(void)
6364 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6369 static void execSetupChooseVolumeMusic(void)
6371 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6376 static void execSetupSound(void)
6378 if (volumes_simple == NULL)
6380 boolean current_volume_simple_found = FALSE;
6383 for (i = 0; volumes_list[i].value != -1; i++)
6385 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6386 char identifier[32], name[32];
6387 int value = volumes_list[i].value;
6388 char *text = volumes_list[i].text;
6390 ti->node_top = &volumes_simple;
6391 ti->sort_priority = value;
6393 sprintf(identifier, "%d", value);
6394 sprintf(name, "%s", text);
6396 setString(&ti->identifier, identifier);
6397 setString(&ti->name, name);
6398 setString(&ti->name_sorting, name);
6399 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6401 pushTreeInfo(&volumes_simple, ti);
6403 if (value == setup.volume_simple)
6404 current_volume_simple_found = TRUE;
6407 if (!current_volume_simple_found)
6409 // add entry for non-preset volume value
6411 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6412 char identifier[32], name[32];
6413 int value = setup.volume_simple;
6415 ti->node_top = &volumes_simple;
6416 ti->sort_priority = value;
6418 sprintf(identifier, "%d", value);
6419 sprintf(name, "%d %% (Current)", value);
6421 setString(&ti->identifier, identifier);
6422 setString(&ti->name, name);
6423 setString(&ti->name_sorting, name);
6424 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6426 pushTreeInfo(&volumes_simple, ti);
6429 // sort volume values to start with lowest volume value
6430 sortTreeInfo(&volumes_simple);
6432 // set current volume value to configured volume value
6433 volume_simple_current =
6434 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6436 // if that fails, set current volume to reliable default value
6437 if (volume_simple_current == NULL)
6438 volume_simple_current =
6439 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6441 // if that also fails, set current volume to first available value
6442 if (volume_simple_current == NULL)
6443 volume_simple_current = volumes_simple;
6446 if (volumes_loops == NULL)
6448 boolean current_volume_loops_found = FALSE;
6451 for (i = 0; volumes_list[i].value != -1; i++)
6453 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6454 char identifier[32], name[32];
6455 int value = volumes_list[i].value;
6456 char *text = volumes_list[i].text;
6458 ti->node_top = &volumes_loops;
6459 ti->sort_priority = value;
6461 sprintf(identifier, "%d", value);
6462 sprintf(name, "%s", text);
6464 setString(&ti->identifier, identifier);
6465 setString(&ti->name, name);
6466 setString(&ti->name_sorting, name);
6467 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6469 pushTreeInfo(&volumes_loops, ti);
6471 if (value == setup.volume_loops)
6472 current_volume_loops_found = TRUE;
6475 if (!current_volume_loops_found)
6477 // add entry for non-preset volume value
6479 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6480 char identifier[32], name[32];
6481 int value = setup.volume_loops;
6483 ti->node_top = &volumes_loops;
6484 ti->sort_priority = value;
6486 sprintf(identifier, "%d", value);
6487 sprintf(name, "%d %% (Current)", value);
6489 setString(&ti->identifier, identifier);
6490 setString(&ti->name, name);
6491 setString(&ti->name_sorting, name);
6492 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6494 pushTreeInfo(&volumes_loops, ti);
6497 // sort volume values to start with lowest volume value
6498 sortTreeInfo(&volumes_loops);
6500 // set current volume value to configured volume value
6501 volume_loops_current =
6502 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6504 // if that fails, set current volume to reliable default value
6505 if (volume_loops_current == NULL)
6506 volume_loops_current =
6507 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6509 // if that also fails, set current volume to first available value
6510 if (volume_loops_current == NULL)
6511 volume_loops_current = volumes_loops;
6514 if (volumes_music == NULL)
6516 boolean current_volume_music_found = FALSE;
6519 for (i = 0; volumes_list[i].value != -1; i++)
6521 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6522 char identifier[32], name[32];
6523 int value = volumes_list[i].value;
6524 char *text = volumes_list[i].text;
6526 ti->node_top = &volumes_music;
6527 ti->sort_priority = value;
6529 sprintf(identifier, "%d", value);
6530 sprintf(name, "%s", text);
6532 setString(&ti->identifier, identifier);
6533 setString(&ti->name, name);
6534 setString(&ti->name_sorting, name);
6535 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6537 pushTreeInfo(&volumes_music, ti);
6539 if (value == setup.volume_music)
6540 current_volume_music_found = TRUE;
6543 if (!current_volume_music_found)
6545 // add entry for non-preset volume value
6547 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6548 char identifier[32], name[32];
6549 int value = setup.volume_music;
6551 ti->node_top = &volumes_music;
6552 ti->sort_priority = value;
6554 sprintf(identifier, "%d", value);
6555 sprintf(name, "%d %% (Current)", value);
6557 setString(&ti->identifier, identifier);
6558 setString(&ti->name, name);
6559 setString(&ti->name_sorting, name);
6560 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6562 pushTreeInfo(&volumes_music, ti);
6565 // sort volume values to start with lowest volume value
6566 sortTreeInfo(&volumes_music);
6568 // set current volume value to configured volume value
6569 volume_music_current =
6570 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6572 // if that fails, set current volume to reliable default value
6573 if (volume_music_current == NULL)
6574 volume_music_current =
6575 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6577 // if that also fails, set current volume to first available value
6578 if (volume_music_current == NULL)
6579 volume_music_current = volumes_music;
6582 setup.volume_simple = atoi(volume_simple_current->identifier);
6583 setup.volume_loops = atoi(volume_loops_current->identifier);
6584 setup.volume_music = atoi(volume_music_current->identifier);
6586 // needed for displaying volume text instead of identifier
6587 volume_simple_text = volume_simple_current->name;
6588 volume_loops_text = volume_loops_current->name;
6589 volume_music_text = volume_music_current->name;
6591 setup_mode = SETUP_MODE_SOUND;
6596 static void execSetupChooseTouchControls(void)
6598 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6603 static void execSetupChooseMoveDistance(void)
6605 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6610 static void execSetupChooseDropDistance(void)
6612 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6617 static void execSetupChooseTransparency(void)
6619 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6624 static void execSetupChooseGridXSize_0(void)
6626 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6631 static void execSetupChooseGridYSize_0(void)
6633 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6638 static void execSetupChooseGridXSize_1(void)
6640 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6645 static void execSetupChooseGridYSize_1(void)
6647 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6652 static void execSetupConfigureVirtualButtons(void)
6654 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6656 ConfigureVirtualButtons();
6658 setup_mode = SETUP_MODE_TOUCH;
6663 static void execSetupTouch(void)
6667 if (touch_controls == NULL)
6669 for (i = 0; touch_controls_list[i].value != NULL; i++)
6671 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6672 char identifier[32], name[32];
6673 char *value = touch_controls_list[i].value;
6674 char *text = touch_controls_list[i].text;
6676 ti->node_top = &touch_controls;
6677 ti->sort_priority = i;
6679 sprintf(identifier, "%s", value);
6680 sprintf(name, "%s", text);
6682 setString(&ti->identifier, identifier);
6683 setString(&ti->name, name);
6684 setString(&ti->name_sorting, name);
6685 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6687 pushTreeInfo(&touch_controls, ti);
6690 // sort touch control values to start with lowest touch control value
6691 sortTreeInfo(&touch_controls);
6693 // set current touch control value to configured touch control value
6694 touch_control_current =
6695 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6697 // if that fails, set current touch control to reliable default value
6698 if (touch_control_current == NULL)
6699 touch_control_current =
6700 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6702 // if that also fails, set current touch control to first available value
6703 if (touch_control_current == NULL)
6704 touch_control_current = touch_controls;
6707 if (move_distances == NULL)
6709 for (i = 0; distances_list[i].value != -1; i++)
6711 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6712 char identifier[32], name[32];
6713 int value = distances_list[i].value;
6714 char *text = distances_list[i].text;
6716 ti->node_top = &move_distances;
6717 ti->sort_priority = value;
6719 sprintf(identifier, "%d", value);
6720 sprintf(name, "%s", text);
6722 setString(&ti->identifier, identifier);
6723 setString(&ti->name, name);
6724 setString(&ti->name_sorting, name);
6725 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6727 pushTreeInfo(&move_distances, ti);
6730 // sort distance values to start with lowest distance value
6731 sortTreeInfo(&move_distances);
6733 // set current distance value to configured distance value
6734 move_distance_current =
6735 getTreeInfoFromIdentifier(move_distances,
6736 i_to_a(setup.touch.move_distance));
6738 // if that fails, set current distance to reliable default value
6739 if (move_distance_current == NULL)
6740 move_distance_current =
6741 getTreeInfoFromIdentifier(move_distances,
6742 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6744 // if that also fails, set current distance to first available value
6745 if (move_distance_current == NULL)
6746 move_distance_current = move_distances;
6749 if (drop_distances == NULL)
6751 for (i = 0; distances_list[i].value != -1; i++)
6753 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6754 char identifier[32], name[32];
6755 int value = distances_list[i].value;
6756 char *text = distances_list[i].text;
6758 ti->node_top = &drop_distances;
6759 ti->sort_priority = value;
6761 sprintf(identifier, "%d", value);
6762 sprintf(name, "%s", text);
6764 setString(&ti->identifier, identifier);
6765 setString(&ti->name, name);
6766 setString(&ti->name_sorting, name);
6767 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6769 pushTreeInfo(&drop_distances, ti);
6772 // sort distance values to start with lowest distance value
6773 sortTreeInfo(&drop_distances);
6775 // set current distance value to configured distance value
6776 drop_distance_current =
6777 getTreeInfoFromIdentifier(drop_distances,
6778 i_to_a(setup.touch.drop_distance));
6780 // if that fails, set current distance to reliable default value
6781 if (drop_distance_current == NULL)
6782 drop_distance_current =
6783 getTreeInfoFromIdentifier(drop_distances,
6784 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6786 // if that also fails, set current distance to first available value
6787 if (drop_distance_current == NULL)
6788 drop_distance_current = drop_distances;
6791 if (transparencies == NULL)
6793 for (i = 0; transparencies_list[i].value != -1; i++)
6795 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6796 char identifier[32], name[32];
6797 int value = transparencies_list[i].value;
6798 char *text = transparencies_list[i].text;
6800 ti->node_top = &transparencies;
6801 ti->sort_priority = value;
6803 sprintf(identifier, "%d", value);
6804 sprintf(name, "%s", text);
6806 setString(&ti->identifier, identifier);
6807 setString(&ti->name, name);
6808 setString(&ti->name_sorting, name);
6809 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6811 pushTreeInfo(&transparencies, ti);
6814 // sort transparency values to start with lowest transparency value
6815 sortTreeInfo(&transparencies);
6817 // set current transparency value to configured transparency value
6818 transparency_current =
6819 getTreeInfoFromIdentifier(transparencies,
6820 i_to_a(setup.touch.transparency));
6822 // if that fails, set current transparency to reliable default value
6823 if (transparency_current == NULL)
6824 transparency_current =
6825 getTreeInfoFromIdentifier(transparencies,
6826 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6828 // if that also fails, set current transparency to first available value
6829 if (transparency_current == NULL)
6830 transparency_current = transparencies;
6833 for (i = 0; i < 2; i++)
6835 for (j = 0; j < 2; j++)
6837 if (grid_sizes[i][j] == NULL)
6839 for (k = 0; grid_sizes_list[k].value != -1; k++)
6841 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6842 char identifier[32], name[32];
6843 int value = grid_sizes_list[k].value;
6844 char *text = grid_sizes_list[k].text;
6846 ti->node_top = &grid_sizes[i][j];
6847 ti->sort_priority = value;
6849 sprintf(identifier, "%d", value);
6850 sprintf(name, "%s", text);
6852 setString(&ti->identifier, identifier);
6853 setString(&ti->name, name);
6854 setString(&ti->name_sorting, name);
6855 setString(&ti->infotext,
6858 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6859 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6861 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6862 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6864 pushTreeInfo(&grid_sizes[i][j], ti);
6867 // sort grid size values to start with lowest grid size value
6868 sortTreeInfo(&grid_sizes[i][j]);
6870 // set current grid size value to configured grid size value
6871 grid_size_current[i][j] =
6872 getTreeInfoFromIdentifier(grid_sizes[i][j],
6874 setup.touch.grid_xsize[i] :
6875 setup.touch.grid_ysize[i]));
6877 // if that fails, set current grid size to reliable default value
6878 if (grid_size_current[i][j] == NULL)
6879 grid_size_current[i][j] =
6880 getTreeInfoFromIdentifier(grid_sizes[i][j],
6882 DEFAULT_GRID_XSIZE(i) :
6883 DEFAULT_GRID_YSIZE(i)));
6885 // if that also fails, set current grid size to first available value
6886 if (grid_size_current[i][j] == NULL)
6887 grid_size_current[i][j] = grid_sizes[i][j];
6892 setup.touch.control_type = touch_control_current->identifier;
6893 setup.touch.move_distance = atoi(move_distance_current->identifier);
6894 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6895 setup.touch.transparency = atoi(transparency_current->identifier);
6897 for (i = 0; i < 2; i++)
6899 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6900 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6902 if (i == GRID_ACTIVE_NR())
6904 overlay.grid_xsize = setup.touch.grid_xsize[i];
6905 overlay.grid_ysize = setup.touch.grid_ysize[i];
6909 // needed for displaying value text instead of identifier
6910 touch_controls_text = touch_control_current->name;
6911 move_distance_text = move_distance_current->name;
6912 drop_distance_text = drop_distance_current->name;
6913 transparency_text = transparency_current->name;
6915 for (i = 0; i < 2; i++)
6916 for (j = 0; j < 2; j++)
6917 grid_size_text[i][j] = grid_size_current[i][j]->name;
6919 setup_mode = SETUP_MODE_TOUCH;
6924 static void execSetupArtwork(void)
6926 static ArtworkDirTree *gfx_last_valid = NULL;
6927 static ArtworkDirTree *snd_last_valid = NULL;
6928 static ArtworkDirTree *mus_last_valid = NULL;
6930 // current artwork directory may be invalid (level group, parent link)
6931 if (!validLevelSeries(artwork.gfx_current))
6932 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6933 if (!validLevelSeries(artwork.snd_current))
6934 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6935 if (!validLevelSeries(artwork.mus_current))
6936 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6938 // store valid artwork directory information
6939 gfx_last_valid = artwork.gfx_current;
6940 snd_last_valid = artwork.snd_current;
6941 mus_last_valid = artwork.mus_current;
6944 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6945 artwork.gfx_current->subdir,
6946 artwork.gfx_current->fullpath,
6947 artwork.gfx_current->basepath);
6950 setup.graphics_set = artwork.gfx_current->identifier;
6951 setup.sounds_set = artwork.snd_current->identifier;
6952 setup.music_set = artwork.mus_current->identifier;
6954 // needed if last screen (setup choice) changed graphics, sounds or music
6955 ReloadCustomArtwork(0);
6957 // needed for displaying artwork name instead of artwork identifier
6958 graphics_set_name = artwork.gfx_current->name;
6959 sounds_set_name = artwork.snd_current->name;
6960 music_set_name = artwork.mus_current->name;
6962 setup_mode = SETUP_MODE_ARTWORK;
6967 static void execSetupChooseGraphics(void)
6969 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6974 static void execSetupChooseSounds(void)
6976 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6981 static void execSetupChooseMusic(void)
6983 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6988 static void execSetupInput(void)
6990 setup_mode = SETUP_MODE_INPUT;
6995 static void execSetupShortcuts(void)
6997 setup_mode = SETUP_MODE_SHORTCUTS;
7002 static void execSetupShortcuts1(void)
7004 setup_mode = SETUP_MODE_SHORTCUTS_1;
7009 static void execSetupShortcuts2(void)
7011 setup_mode = SETUP_MODE_SHORTCUTS_2;
7016 static void execSetupShortcuts3(void)
7018 setup_mode = SETUP_MODE_SHORTCUTS_3;
7023 static void execSetupShortcuts4(void)
7025 setup_mode = SETUP_MODE_SHORTCUTS_4;
7030 static void execSetupShortcuts5(void)
7032 setup_mode = SETUP_MODE_SHORTCUTS_5;
7037 static void execExitSetup(void)
7039 SetGameStatus(GAME_MODE_MAIN);
7044 static void execSaveAndExitSetup(void)
7050 static void execGadgetNetworkServer(void)
7052 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7053 struct GadgetInfo *gi = screen_gadget[gadget_id];
7055 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7056 network_server_hostname[0] = '\0';
7058 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7062 ClickOnGadget(gi, MB_LEFTBUTTON);
7065 static void execOfferUploadTapes(void)
7070 static void ToggleNetworkModeIfNeeded(void)
7072 int font_title = FONT_TITLE_1;
7073 int font_foot = FC_BLUE;
7074 int ystart = mSY - SY + 16;
7075 int ybottom = mSY - SY + SYSIZE - 20;
7076 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7078 if (setup.network_mode == network.enabled)
7081 network.enabled = setup.network_mode;
7083 FadeOut(REDRAW_ALL);
7087 DrawTextSCentered(ystart, font_title, text);
7091 if (network.enabled)
7092 InitNetworkServer();
7094 DisconnectFromNetworkServer();
7096 DrawTextSCentered(ybottom, font_foot,
7097 "Press any key or button for setup menu");
7099 WaitForEventToContinue();
7104 static void ToggleGameSpeedsListIfNeeded(void)
7106 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7108 if (setup.game_speed_extended == using_game_speeds_extended)
7111 // try to match similar values when changing game speeds list
7112 if (setup.game_speed_extended)
7113 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7114 setup.game_frame_delay == 30 ? 29 :
7115 setup.game_frame_delay);
7117 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7118 setup.game_frame_delay == 16 ? 15 :
7119 setup.game_frame_delay >= 29 ? 30 :
7120 setup.game_frame_delay <= 10 ? 10 :
7121 setup.game_frame_delay);
7123 execSetupGame_setGameSpeeds(TRUE);
7128 static void ToggleUseApiServerIfNeeded(void)
7130 if (runtime.use_api_server == setup.use_api_server)
7133 runtime.use_api_server = setup.use_api_server;
7135 if (runtime.use_api_server)
7136 CheckApiServerTasks();
7139 static void ModifyGameSpeedIfNeeded(void)
7141 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7142 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7146 char *game_speed_text = "Fast";
7147 int game_speed_value = 15;
7149 if (setup.game_speed_extended)
7151 game_speed_text = "60 fps";
7152 game_speed_value = 16;
7155 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7157 // set game speed to existing list value that is fast enough for vsync
7158 setup.game_frame_delay = game_speed_value;
7160 execSetupGame_setGameSpeeds(TRUE);
7162 Request(message, REQ_CONFIRM);
7165 static void DisableVsyncIfNeeded(void)
7167 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7168 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7169 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7172 // disable vsync for the selected game speed to work
7173 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7175 execSetupGraphics_setVsyncModes(TRUE);
7177 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7183 void *related_value;
7184 } hide_related_entry_list[] =
7186 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7187 { &setup.scores_in_highscore_list, &scores_type_text },
7189 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7190 { &setup.game_frame_delay, &game_speed_text },
7192 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7193 { &setup.scroll_delay_value, &scroll_delay_text },
7195 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7196 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7198 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7199 { &setup.window_scaling_percent, &window_size_text },
7201 { &setup.window_scaling_quality, execSetupChooseScalingType },
7202 { &setup.window_scaling_quality, &scaling_type_text },
7204 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7205 { &setup.screen_rendering_mode, &rendering_mode_text },
7207 { &setup.vsync_mode, execSetupChooseVsyncMode },
7208 { &setup.vsync_mode, &vsync_mode_text },
7210 { &setup.graphics_set, execSetupChooseGraphics },
7211 { &setup.graphics_set, &graphics_set_name },
7213 { &setup.sounds_set, execSetupChooseSounds },
7214 { &setup.sounds_set, &sounds_set_name },
7216 { &setup.music_set, execSetupChooseMusic },
7217 { &setup.music_set, &music_set_name },
7219 { &setup.volume_simple, execSetupChooseVolumeSimple },
7220 { &setup.volume_simple, &volume_simple_text },
7222 { &setup.volume_loops, execSetupChooseVolumeLoops },
7223 { &setup.volume_loops, &volume_loops_text },
7225 { &setup.volume_music, execSetupChooseVolumeMusic },
7226 { &setup.volume_music, &volume_music_text },
7228 { &setup.touch.control_type, execSetupChooseTouchControls },
7229 { &setup.touch.control_type, &touch_controls_text },
7231 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7232 { &setup.touch.move_distance, &move_distance_text },
7234 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7235 { &setup.touch.drop_distance, &drop_distance_text },
7237 { &setup.touch.transparency, execSetupChooseTransparency },
7238 { &setup.touch.transparency, &transparency_text },
7240 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7241 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7243 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7244 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7246 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7247 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7249 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7250 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7252 { &setup.internal.menu_game, execSetupGame },
7253 { &setup.internal.menu_engines, execSetupEngines },
7254 { &setup.internal.menu_editor, execSetupEditor },
7255 { &setup.internal.menu_graphics, execSetupGraphics },
7256 { &setup.internal.menu_sound, execSetupSound },
7257 { &setup.internal.menu_artwork, execSetupArtwork },
7258 { &setup.internal.menu_input, execSetupInput },
7259 { &setup.internal.menu_touch, execSetupTouch },
7260 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7261 { &setup.internal.menu_exit, execExitSetup },
7262 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7264 { &setup.internal.info_title, execInfoTitleScreen },
7265 { &setup.internal.info_elements, execInfoElements },
7266 { &setup.internal.info_music, execInfoMusic },
7267 { &setup.internal.info_credits, execInfoCredits },
7268 { &setup.internal.info_program, execInfoProgram },
7269 { &setup.internal.info_version, execInfoVersion },
7270 { &setup.internal.info_levelset, execInfoLevelSet },
7271 { &setup.internal.info_exit, execExitInfo },
7276 void setHideRelatedSetupEntries(void)
7280 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7281 if (hideSetupEntry(hide_related_entry_list[i].value))
7282 setHideSetupEntry(hide_related_entry_list[i].related_value);
7285 static struct TokenInfo setup_info_main[] =
7287 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7288 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7289 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7290 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7291 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7292 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7293 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7294 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7295 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7296 { TYPE_EMPTY, NULL, "" },
7297 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7298 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7303 static struct TokenInfo setup_info_game[] =
7305 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7306 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7307 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7308 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7309 { TYPE_STRING, &network_server_text, "" },
7310 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7311 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7312 { TYPE_STRING, &scores_type_text, "" },
7313 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7314 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7315 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7316 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7317 { TYPE_SWITCH, &setup.handicap, "Force Solving Levels:" },
7318 { TYPE_SWITCH, &setup.skip_levels, "Allow Skipping Levels:" },
7319 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7320 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7321 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7322 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7323 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7324 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7325 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7326 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7327 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7328 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7329 { TYPE_STRING, &game_speed_text, "" },
7330 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7332 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7333 { TYPE_STRING, &scroll_delay_text, "" },
7335 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7336 { TYPE_STRING, &snapshot_mode_text, "" },
7337 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7338 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7339 { TYPE_EMPTY, NULL, "" },
7340 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7345 static struct TokenInfo setup_info_engines[] =
7347 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7348 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7349 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7350 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7351 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7352 { TYPE_EMPTY, NULL, "" },
7353 { TYPE_HEADLINE, NULL, "Supaplex" },
7354 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7355 { TYPE_EMPTY, NULL, "" },
7356 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7361 static struct TokenInfo setup_info_editor[] =
7364 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7365 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7366 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7367 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7368 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7369 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7370 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7371 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7372 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7373 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7375 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7376 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7378 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7380 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7381 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7382 { TYPE_EMPTY, NULL, "" },
7384 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7385 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7386 { TYPE_EMPTY, NULL, "" },
7388 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7389 { TYPE_EMPTY, NULL, "" },
7390 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7391 { TYPE_EMPTY, NULL, "" },
7392 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7397 static struct TokenInfo setup_info_graphics[] =
7399 #if !defined(PLATFORM_ANDROID) && !defined(PLATFORM_EMSCRIPTEN)
7400 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7401 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7402 { TYPE_STRING, &window_size_text, "" },
7403 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7404 { TYPE_STRING, &scaling_type_text, "" },
7405 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7406 { TYPE_STRING, &rendering_mode_text, "" },
7409 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7410 { TYPE_STRING, &scroll_delay_text, "" },
7412 #if !defined(PLATFORM_EMSCRIPTEN)
7413 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7414 { TYPE_STRING, &vsync_mode_text, "" },
7416 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7417 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7418 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7419 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7420 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7421 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7422 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7423 { TYPE_EMPTY, NULL, "" },
7424 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7429 static struct TokenInfo setup_info_sound[] =
7431 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7432 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7433 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7434 { TYPE_EMPTY, NULL, "" },
7435 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7436 { TYPE_STRING, &volume_simple_text, "" },
7437 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7438 { TYPE_STRING, &volume_loops_text, "" },
7439 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7440 { TYPE_STRING, &volume_music_text, "" },
7441 { TYPE_EMPTY, NULL, "" },
7442 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7447 static struct TokenInfo setup_info_artwork[] =
7449 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7450 { TYPE_STRING, &graphics_set_name, "" },
7451 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7452 { TYPE_STRING, &sounds_set_name, "" },
7453 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7454 { TYPE_STRING, &music_set_name, "" },
7455 { TYPE_EMPTY, NULL, "" },
7456 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7457 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7458 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7459 { TYPE_EMPTY, NULL, "" },
7460 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7465 static struct TokenInfo setup_info_input[] =
7467 { TYPE_SWITCH, NULL, "Player:" },
7468 { TYPE_SWITCH, NULL, "Device:" },
7469 { TYPE_SWITCH, NULL, "" },
7470 { TYPE_SKIPPABLE, NULL, "" },
7471 { TYPE_EMPTY, NULL, "" },
7472 { TYPE_EMPTY, NULL, "" },
7473 { TYPE_EMPTY, NULL, "" },
7474 { TYPE_EMPTY, NULL, "" },
7475 { TYPE_EMPTY, NULL, "" },
7476 { TYPE_EMPTY, NULL, "" },
7477 { TYPE_EMPTY, NULL, "" },
7478 { TYPE_EMPTY, NULL, "" },
7479 { TYPE_SKIPPABLE, NULL, "" },
7480 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7485 static struct TokenInfo setup_info_touch[] =
7487 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7488 { TYPE_STRING, &touch_controls_text, "" },
7489 { TYPE_EMPTY, NULL, "" },
7490 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7495 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7497 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7498 { TYPE_STRING, &touch_controls_text, "" },
7499 { TYPE_EMPTY, NULL, "" },
7500 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7501 { TYPE_STRING, &grid_size_text[0][0], "" },
7502 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7503 { TYPE_STRING, &grid_size_text[0][1], "" },
7504 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7505 { TYPE_STRING, &transparency_text, "" },
7506 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7507 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7508 { TYPE_EMPTY, NULL, "" },
7509 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7510 { TYPE_EMPTY, NULL, "" },
7511 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7516 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7518 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7519 { TYPE_STRING, &touch_controls_text, "" },
7520 { TYPE_EMPTY, NULL, "" },
7521 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7522 { TYPE_STRING, &grid_size_text[1][0], "" },
7523 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7524 { TYPE_STRING, &grid_size_text[1][1], "" },
7525 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7526 { TYPE_STRING, &transparency_text, "" },
7527 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7528 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7529 { TYPE_EMPTY, NULL, "" },
7530 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7531 { TYPE_EMPTY, NULL, "" },
7532 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7537 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7539 setup_info_touch_virtual_buttons_0,
7540 setup_info_touch_virtual_buttons_1
7543 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7545 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7546 { TYPE_STRING, &touch_controls_text, "" },
7547 { TYPE_EMPTY, NULL, "" },
7548 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7549 { TYPE_STRING, &move_distance_text, "" },
7550 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7551 { TYPE_STRING, &drop_distance_text, "" },
7552 { TYPE_EMPTY, NULL, "" },
7553 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7558 static struct TokenInfo setup_info_shortcuts[] =
7560 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7561 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7562 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7563 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7564 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7565 { TYPE_EMPTY, NULL, "" },
7566 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7571 static struct TokenInfo setup_info_shortcuts_1[] =
7573 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7574 { TYPE_KEY, &setup.shortcut.save_game, "" },
7575 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7576 { TYPE_KEY, &setup.shortcut.load_game, "" },
7577 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7578 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7579 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7580 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7581 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7582 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7583 { TYPE_EMPTY, NULL, "" },
7584 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7585 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7586 { TYPE_EMPTY, NULL, "" },
7587 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7592 static struct TokenInfo setup_info_shortcuts_2[] =
7594 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7595 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7596 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7597 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7598 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7599 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7600 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7601 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7602 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7603 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7604 { TYPE_EMPTY, NULL, "" },
7605 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7610 static struct TokenInfo setup_info_shortcuts_3[] =
7612 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7613 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7614 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7615 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7616 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7617 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7618 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7619 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7620 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7621 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7622 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7623 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7624 { TYPE_EMPTY, NULL, "" },
7625 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7630 static struct TokenInfo setup_info_shortcuts_4[] =
7632 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7633 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7634 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7635 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7636 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7637 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7638 { TYPE_EMPTY, NULL, "" },
7639 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7644 static struct TokenInfo setup_info_shortcuts_5[] =
7646 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7647 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7648 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7649 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7650 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7651 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7652 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7653 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7654 { TYPE_EMPTY, NULL, "" },
7655 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7660 static Key getSetupKey(void)
7662 Key key = KSYM_UNDEFINED;
7663 boolean got_key_event = FALSE;
7665 while (!got_key_event)
7669 if (NextValidEvent(&event))
7673 case EVENT_KEYPRESS:
7675 key = GetEventKey((KeyEvent *)&event, TRUE);
7677 // press 'Escape' or 'Enter' to keep the existing key binding
7678 if (key == KSYM_Escape || key == KSYM_Return)
7679 key = KSYM_UNDEFINED; // keep old value
7681 got_key_event = TRUE;
7685 case EVENT_KEYRELEASE:
7686 key_joystick_mapping = 0;
7690 HandleOtherEvents(&event);
7701 static int getSetupValueFont(int type, void *value)
7703 if (type & TYPE_GHOSTED)
7704 return FONT_OPTION_OFF;
7705 else if (type & TYPE_KEY)
7706 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7707 else if (type & TYPE_STRING)
7708 return FONT_VALUE_2;
7709 else if (type & TYPE_ECS_AGA)
7710 return FONT_VALUE_1;
7711 else if (type & TYPE_BOOLEAN_STYLE)
7712 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7713 else if (type & TYPE_YES_NO_AUTO)
7714 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7715 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7716 else if (type & TYPE_PLAYER)
7717 return FONT_VALUE_1;
7719 return FONT_VALUE_1;
7722 static int getSetupValueFontNarrow(int type, int font_nr)
7724 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7725 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7726 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7730 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7732 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7733 struct TokenInfo *si = &setup_info[si_pos];
7734 boolean font_draw_xoffset_modified = FALSE;
7735 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7736 int font_draw_xoffset_old = -1;
7737 int xoffset = (scrollbar_needed ? -1 : 0);
7738 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7739 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7740 int xpos = menu_screen_value_xpos;
7741 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7742 int startx = mSX + xpos * 32;
7743 int starty = mSY + ypos * 32;
7744 int type = si->type;
7745 void *value = si->value;
7746 char *value_string = getSetupValue(type, value);
7747 int font_nr_default = getSetupValueFont(type, value);
7748 int font_width_default = getFontWidth(font_nr_default);
7749 int font_nr = font_nr_default;
7752 if (value_string == NULL)
7755 if (type & TYPE_KEY)
7757 xpos = MENU_SCREEN_START_XPOS;
7759 if (type & TYPE_QUERY)
7760 value_string = "<press key>";
7762 else if (type & TYPE_STRING)
7764 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7766 xpos = MENU_SCREEN_START_XPOS;
7768 if (strlen(value_string) > max_value_len)
7769 value_string[max_value_len] = '\0';
7771 else if (type & TYPE_YES_NO_AUTO)
7773 xpos = menu_screen_value_xpos - 1;
7775 else if (type & TYPE_PLAYER)
7777 int displayed_player_nr = *(int *)value + 1;
7779 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7782 startx = mSX + xpos * 32;
7783 starty = mSY + ypos * 32;
7785 // special check if right-side setup values moved left due to scrollbar
7786 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7788 int max_menu_text_length = 26; // maximum text length for classic menu
7789 int font_xoffset = getFontDrawOffsetX(font_nr);
7790 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7791 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7792 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7793 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7795 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7797 // when using narrow font, left-shifting text "auto" not needed
7798 if (type & TYPE_YES_NO_AUTO)
7802 startx = mSX + xpos * 32;
7804 font_nr = getSetupValueFontNarrow(type, font_nr);
7808 // downward compatibility correction for Juergen Bonhagen's menu settings
7809 if (setup_mode != SETUP_MODE_INPUT)
7811 int max_menu_text_length_big = (menu_screen_value_xpos -
7812 MENU_SCREEN_START_XPOS);
7813 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7814 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7815 int font1_xoffset = getFontDrawOffsetX(font_nr);
7816 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7817 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7818 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7819 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7820 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7821 boolean correct_font_draw_xoffset = FALSE;
7823 if (xpos == MENU_SCREEN_START_XPOS &&
7824 startx + font1_xoffset < text_startx + text_font_xoffset)
7825 correct_font_draw_xoffset = TRUE;
7827 if (xpos == menu_screen_value_xpos &&
7828 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7829 correct_font_draw_xoffset = TRUE;
7831 // check if setup value would overlap with setup text when printed
7832 // (this can happen for extreme/wrong values for font draw offset)
7833 if (correct_font_draw_xoffset)
7835 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7836 font_draw_xoffset_modified = TRUE;
7838 if (type & TYPE_KEY)
7839 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7840 else if (!(type & TYPE_STRING))
7841 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7842 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7846 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7847 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7849 DrawText(startx, starty, value_string, font_nr);
7851 if (type & TYPE_PLAYER)
7853 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7854 int player_nr = *(int *)value;
7855 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7856 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7857 int startx2 = startx + xoff;
7858 int starty2 = starty + yoff;
7860 if (DrawingOnBackground(startx2, starty2))
7861 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7863 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7864 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7867 if (font_draw_xoffset_modified)
7868 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7871 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7873 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7874 struct TokenInfo *si = &setup_info[si_pos];
7876 if (si->type & TYPE_BOOLEAN_STYLE)
7878 *(boolean *)si->value ^= TRUE;
7880 else if (si->type & TYPE_YES_NO_AUTO)
7884 (*(int *)si->value == AUTO ? TRUE :
7885 *(int *)si->value == TRUE ? FALSE : AUTO) :
7886 (*(int *)si->value == TRUE ? AUTO :
7887 *(int *)si->value == AUTO ? FALSE : TRUE));
7889 else if (si->type & TYPE_KEY)
7893 si->type |= TYPE_QUERY;
7894 drawSetupValue(screen_pos, setup_info_pos_raw);
7895 si->type &= ~TYPE_QUERY;
7897 key = getSetupKey();
7898 if (key != KSYM_UNDEFINED)
7899 *(Key *)si->value = key;
7901 else if (si->type & TYPE_PLAYER)
7903 int player_nr = *(int *)si->value;
7908 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7910 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7913 drawSetupValue(screen_pos, setup_info_pos_raw);
7915 // fullscreen state may have changed at this point
7916 if (si->value == &setup.fullscreen)
7917 ToggleFullscreenIfNeeded();
7919 // network mode may have changed at this point
7920 if (si->value == &setup.network_mode)
7921 ToggleNetworkModeIfNeeded();
7923 // API server mode may have changed at this point
7924 if (si->value == &setup.use_api_server)
7925 ToggleUseApiServerIfNeeded();
7927 // game speed list may have changed at this point
7928 if (si->value == &setup.game_speed_extended)
7929 ToggleGameSpeedsListIfNeeded();
7932 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7934 static struct TokenInfo *setup_info_final = NULL;
7939 // determine maximum list size of target list
7940 while (setup_info_orig[list_size++].type != 0);
7942 // free, allocate and clear memory for target list
7943 checked_free(setup_info_final);
7944 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7946 // copy setup info list without setup entries marked as hidden
7947 for (i = 0; setup_info_orig[i].type != 0; i++)
7949 // skip setup entries configured to be hidden
7950 if (hideSetupEntry(setup_info_orig[i].value))
7953 // skip skippable setup entries if screen is lower than usual
7954 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7955 setup_info_orig[i].type == TYPE_SKIPPABLE)
7958 setup_info_final[list_pos++] = setup_info_orig[i];
7961 return setup_info_final;
7964 static void DrawSetupScreen_Generic(void)
7966 int fade_mask = REDRAW_FIELD;
7967 boolean redraw_all = FALSE;
7968 char *title_string = NULL;
7972 fade_mask = REDRAW_ALL;
7975 FadeMenuSoundsAndMusic();
7977 FreeScreenGadgets();
7978 CreateScreenGadgets();
7980 if (redraw_mask & REDRAW_ALL)
7985 // needed if different viewport properties defined for setup screen
7986 ChangeViewportPropertiesIfNeeded();
7988 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7992 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7994 if (setup_mode == SETUP_MODE_MAIN)
7996 setup_info = setup_info_main;
7997 title_string = STR_SETUP_MAIN;
7999 else if (setup_mode == SETUP_MODE_GAME)
8001 setup_info = setup_info_game;
8002 title_string = STR_SETUP_GAME;
8004 else if (setup_mode == SETUP_MODE_ENGINES)
8006 setup_info = setup_info_engines;
8007 title_string = STR_SETUP_ENGINES;
8009 else if (setup_mode == SETUP_MODE_EDITOR)
8011 setup_info = setup_info_editor;
8012 title_string = STR_SETUP_EDITOR;
8014 else if (setup_mode == SETUP_MODE_GRAPHICS)
8016 setup_info = setup_info_graphics;
8017 title_string = STR_SETUP_GRAPHICS;
8019 else if (setup_mode == SETUP_MODE_SOUND)
8021 setup_info = setup_info_sound;
8022 title_string = STR_SETUP_SOUND;
8024 else if (setup_mode == SETUP_MODE_ARTWORK)
8026 setup_info = setup_info_artwork;
8027 title_string = STR_SETUP_ARTWORK;
8029 else if (setup_mode == SETUP_MODE_TOUCH)
8031 setup_info = setup_info_touch;
8032 title_string = STR_SETUP_TOUCH;
8034 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8035 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8036 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8037 setup_info = setup_info_touch_wipe_gestures;
8039 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8041 setup_info = setup_info_shortcuts;
8042 title_string = STR_SETUP_SHORTCUTS;
8044 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8046 setup_info = setup_info_shortcuts_1;
8047 title_string = STR_SETUP_SHORTCUTS;
8049 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8051 setup_info = setup_info_shortcuts_2;
8052 title_string = STR_SETUP_SHORTCUTS;
8054 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8056 setup_info = setup_info_shortcuts_3;
8057 title_string = STR_SETUP_SHORTCUTS;
8059 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8061 setup_info = setup_info_shortcuts_4;
8062 title_string = STR_SETUP_SHORTCUTS;
8064 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8066 setup_info = setup_info_shortcuts_5;
8067 title_string = STR_SETUP_SHORTCUTS;
8070 // use modified setup info without setup entries marked as hidden
8071 setup_info = getSetupInfoFinal(setup_info);
8073 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8075 // determine maximal number of setup entries that can be displayed on screen
8077 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8080 // determine maximal number of setup entries available for this setup screen
8082 for (i = 0; setup_info[i].type != 0; i++)
8085 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8087 MapScreenGadgets(max_setup_info);
8090 redraw_mask = fade_mask = REDRAW_ALL;
8092 DrawMaskedBorder(fade_mask);
8097 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8099 menu_info = setup_info;
8101 HandleMenuScreen(mx, my, dx, dy, button,
8102 setup_mode, num_setup_info, max_setup_info);
8105 static void DrawSetupScreen_Input(void)
8109 FadeOut(REDRAW_FIELD);
8113 setup_info = getSetupInfoFinal(setup_info_input);
8115 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8117 for (i = 0; setup_info[i].type != 0; i++)
8119 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8120 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8121 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8122 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8123 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8124 initCursor(i, IMG_MENU_BUTTON);
8126 DrawCursorAndText_Setup(i, -1, FALSE);
8129 // create gadgets for setup input menu screen
8130 FreeScreenGadgets();
8131 CreateScreenGadgets();
8133 // map gadgets for setup input menu screen
8134 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8136 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8138 FadeIn(REDRAW_FIELD);
8141 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8143 if (device_name == NULL)
8146 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8149 if (strlen(device_name) > 1)
8151 char c1 = device_name[strlen(device_name) - 1];
8152 char c2 = device_name[strlen(device_name) - 2];
8154 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8155 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8158 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8159 strlen(device_name));
8162 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8165 static struct SetupKeyboardInfo custom_key;
8172 { &custom_key.left, "Axis/Pad Left" },
8173 { &custom_key.right, "Axis/Pad Right" },
8174 { &custom_key.up, "Axis/Pad Up" },
8175 { &custom_key.down, "Axis/Pad Down" },
8176 { &custom_key.snap, "Button 1/A/X" },
8177 { &custom_key.drop, "Button 2/B/Y" }
8179 static char *joystick_name[MAX_PLAYERS] =
8186 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8187 int font_nr_info = FONT_MENU_1;
8188 int font_nr_name = FONT_VALUE_OLD;
8189 int font_nr_on = FONT_VALUE_1;
8190 int font_nr_off = FONT_VALUE_OLD;
8193 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8195 font_nr_info = FONT_MENU_2;
8196 font_nr_on = FONT_VALUE_NARROW;
8197 font_nr_off = FONT_VALUE_OLD_NARROW;
8200 custom_key = setup.input[player_nr].key;
8202 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8203 FONT_INPUT_1_ACTIVE);
8205 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8207 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8208 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8210 if (setup.input[player_nr].use_joystick)
8212 char *device_name = setup.input[player_nr].joy.device_name;
8213 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8214 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8215 char *text = joystick_name[joystick_nr];
8216 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8218 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8219 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8223 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8224 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8227 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8228 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8232 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8233 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8234 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8235 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8237 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8238 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8239 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8240 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8241 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8242 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8244 for (i = 0; i < 6; i++)
8246 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8248 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8250 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8251 (setup.input[player_nr].use_joystick ?
8253 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8257 static int input_player_nr = 0;
8259 static void HandleSetupScreen_Input_Player(int step, int direction)
8261 int old_player_nr = input_player_nr;
8264 new_player_nr = old_player_nr + step * direction;
8265 if (new_player_nr < 0)
8267 if (new_player_nr > MAX_PLAYERS - 1)
8268 new_player_nr = MAX_PLAYERS - 1;
8270 if (new_player_nr != old_player_nr)
8272 input_player_nr = new_player_nr;
8274 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8278 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8280 static int choice = 0;
8283 int pos_start = SETUPINPUT_SCREEN_POS_START;
8284 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8285 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8286 int pos_end = SETUPINPUT_SCREEN_POS_END;
8288 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8292 for (i = 0; setup_info_input[i].type != 0; i++)
8294 // adjust menu structure according to skipped setup entries
8295 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8303 if (button == MB_MENU_INITIALIZE)
8305 // input setup menu may have changed size due to graphics configuration
8306 if (choice >= pos_empty1)
8309 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8311 DrawCursorAndText_Setup(choice, -1, TRUE);
8315 else if (button == MB_MENU_LEAVE)
8317 setup_mode = SETUP_MODE_MAIN;
8324 if (mx || my) // mouse input
8326 x = (mx - mSX) / 32;
8327 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8329 else if (dx || dy) // keyboard input
8331 if (dx && choice == 0)
8332 x = (dx < 0 ? 10 : 12);
8333 else if ((dx && choice == 1) ||
8334 (dx == -1 && choice == pos_end))
8335 button = MB_MENU_CHOICE;
8339 if (y >= pos_empty1 && y <= pos_empty2)
8340 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8343 if (y == 0 && dx != 0 && button)
8345 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8347 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8348 y >= pos_start && y <= pos_end &&
8349 !(y >= pos_empty1 && y <= pos_empty2))
8355 DrawCursorAndText_Setup(choice, -1, FALSE);
8356 DrawCursorAndText_Setup(y, -1, TRUE);
8358 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8367 char *device_name = setup.input[input_player_nr].joy.device_name;
8369 if (!setup.input[input_player_nr].use_joystick)
8371 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8373 setJoystickDeviceToNr(device_name, new_device_nr);
8374 setup.input[input_player_nr].use_joystick = TRUE;
8378 int device_nr = getJoystickNrFromDeviceName(device_name);
8379 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8381 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8382 setup.input[input_player_nr].use_joystick = FALSE;
8384 setJoystickDeviceToNr(device_name, new_device_nr);
8387 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8391 if (setup.input[input_player_nr].use_joystick)
8392 ConfigureJoystick(input_player_nr);
8394 CustomizeKeyboard(input_player_nr);
8396 else if (y == pos_end)
8402 setup_mode = SETUP_MODE_MAIN;
8409 static boolean CustomizeKeyboardMain(int player_nr)
8413 boolean finished = FALSE;
8414 static struct SetupKeyboardInfo custom_key;
8419 } customize_step[] =
8421 { &custom_key.left, "Move Left" },
8422 { &custom_key.right, "Move Right" },
8423 { &custom_key.up, "Move Up" },
8424 { &custom_key.down, "Move Down" },
8425 { &custom_key.snap, "Snap Field" },
8426 { &custom_key.drop, "Drop Element" }
8428 int font_nr_old = FONT_VALUE_OLD;
8429 int font_nr_new = FONT_VALUE_1;
8430 boolean success = FALSE;
8432 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8434 font_nr_old = FONT_VALUE_OLD_NARROW;
8435 font_nr_new = FONT_VALUE_NARROW;
8438 // read existing key bindings from player setup
8439 custom_key = setup.input[player_nr].key;
8442 FadeOut(REDRAW_FIELD);
8446 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8449 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8450 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8451 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8452 "Key:", FONT_INPUT_1_ACTIVE);
8453 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8454 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8456 FadeIn(REDRAW_FIELD);
8461 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8463 // reset frame delay counter directly after updating screen
8464 ResetDelayCounter(&event_frame_delay);
8466 while (NextValidEvent(&event))
8470 case EVENT_KEYPRESS:
8472 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8474 // press 'Escape' to abort and keep the old key bindings
8475 if (key == KSYM_Escape)
8477 FadeSkipNextFadeIn();
8484 // press 'Enter' to keep the existing key binding
8485 if (key == KSYM_Return)
8486 key = *customize_step[step_nr].key;
8488 // check if key already used
8489 for (i = 0; i < step_nr; i++)
8490 if (*customize_step[i].key == key)
8495 // got new key binding
8496 *customize_step[step_nr].key = key;
8497 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8499 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8500 getKeyNameFromKey(key), font_nr_new);
8503 // un-highlight last query
8504 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8505 customize_step[step_nr - 1].text, FONT_MENU_1);
8506 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8507 "Key:", FONT_MENU_1);
8509 // all keys configured
8518 // query next key binding
8519 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8520 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8521 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8522 "Key:", FONT_INPUT_1_ACTIVE);
8523 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8524 getKeyNameFromKey(*customize_step[step_nr].key),
8529 case EVENT_KEYRELEASE:
8530 key_joystick_mapping = 0;
8534 HandleOtherEvents(&event);
8538 // do not handle events for longer than standard frame delay period
8539 if (DelayReached(&event_frame_delay))
8546 // write new key bindings back to player setup, if successfully finished
8548 setup.input[player_nr].key = custom_key;
8553 void CustomizeKeyboard(int player_nr)
8555 boolean success = CustomizeKeyboardMain(player_nr);
8559 int font_nr = FONT_TITLE_1;
8560 int font_height = getFontHeight(font_nr);
8561 int ypos1 = SYSIZE / 2 - font_height * 2;
8562 int ypos2 = SYSIZE / 2 - font_height * 1;
8563 DelayCounter wait_frame_delay = { 2000 };
8565 ResetDelayCounter(&wait_frame_delay);
8569 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8570 DrawTextSCentered(ypos2, font_nr, "configured!");
8572 while (!DelayReached(&wait_frame_delay))
8578 DrawSetupScreen_Input();
8581 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8583 #define MARKER_BUTTON 1
8584 #define MARKER_AXIS_X 2
8585 #define MARKER_AXIS_Y 3
8587 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8589 static boolean bitmaps_initialized = FALSE;
8590 boolean screen_initialized = FALSE;
8591 static Bitmap *controller, *button, *axis_x, *axis_y;
8593 boolean success = TRUE;
8594 boolean done = FALSE, next = FALSE;
8596 int alpha = 200, alpha_step = -1;
8597 int alpha_ticks = 0;
8598 char mapping[4096], temp[256];
8599 int font_name = MENU_SETUP_FONT_TITLE;
8600 int font_info = MENU_SETUP_FONT_TEXT;
8601 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8602 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8603 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8604 int ystep_name = getMenuTextStep(spacing_name, font_name);
8605 int ystep_line = getMenuTextStep(spacing_line, font_info);
8606 int ystep_para = getMenuTextStep(spacing_para, font_info);
8614 int axis, button, hat, hat_value;
8617 *step, *prev_step, steps[] =
8619 { 356, 155, MARKER_BUTTON, "a", },
8620 { 396, 122, MARKER_BUTTON, "b", },
8621 { 320, 125, MARKER_BUTTON, "x", },
8622 { 358, 95, MARKER_BUTTON, "y", },
8623 { 162, 125, MARKER_BUTTON, "back", },
8624 { 216, 125, MARKER_BUTTON, "guide", },
8625 { 271, 125, MARKER_BUTTON, "start", },
8626 { 110, 200, MARKER_BUTTON, "dpleft", },
8627 { 146, 228, MARKER_BUTTON, "dpdown", },
8628 { 178, 200, MARKER_BUTTON, "dpright", },
8629 { 146, 172, MARKER_BUTTON, "dpup", },
8630 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8631 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8632 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8633 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8634 { 73, 141, MARKER_BUTTON, "leftstick", },
8635 { 282, 210, MARKER_BUTTON, "rightstick", },
8636 { 73, 141, MARKER_AXIS_X, "leftx", },
8637 { 73, 141, MARKER_AXIS_Y, "lefty", },
8638 { 282, 210, MARKER_AXIS_X, "rightx", },
8639 { 282, 210, MARKER_AXIS_Y, "righty", },
8642 if (!bitmaps_initialized)
8644 controller = LoadCustomImage("joystick/controller.png");
8645 button = LoadCustomImage("joystick/button.png");
8646 axis_x = LoadCustomImage("joystick/axis_x.png");
8647 axis_y = LoadCustomImage("joystick/axis_y.png");
8649 bitmaps_initialized = TRUE;
8652 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8655 // print info about the joystick we are watching
8656 Debug("joystick", "watching joystick %d: (%s)",
8657 SDL_JoystickInstanceID(joystick), name);
8658 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8659 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8660 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8663 // initialize mapping with GUID and name
8664 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8666 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8667 temp, name, SDL_GetPlatform());
8669 // loop through all steps (buttons and axes), getting joystick events
8670 for (i = 0; i < SDL_arraysize(steps) && !done;)
8672 Bitmap *marker = button; // initialize with reliable default value
8675 strcpy(step->mapping, mapping);
8679 step->hat_value = -1;
8681 marker = (step->marker == MARKER_BUTTON ? button :
8682 step->marker == MARKER_AXIS_X ? axis_x :
8683 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8687 while (!done && !next)
8689 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8690 alpha_ticks = SDL_GetTicks();
8697 else if (alpha < 128)
8703 int controller_x = SX + (SXSIZE - controller->width) / 2;
8704 int controller_y = SY + ystep_line;
8706 int marker_x = controller_x + step->x;
8707 int marker_y = controller_y + step->y;
8709 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8710 int ystart2 = ystart1 + ystep_name + ystep_line;
8714 DrawTextSCentered(ystart1, font_name, name);
8716 DrawTextSCentered(ystart2, font_info,
8717 "Press buttons and move axes on");
8718 ystart2 += ystep_line;
8719 DrawTextSCentered(ystart2, font_info,
8720 "your controller when indicated.");
8721 ystart2 += ystep_line;
8722 DrawTextSCentered(ystart2, font_info,
8723 "(Your controller may look different.)");
8724 ystart2 += ystep_para;
8726 #if defined(PLATFORM_ANDROID)
8727 DrawTextSCentered(ystart2, font_info,
8728 "To correct a mistake,");
8729 ystart2 += ystep_line;
8730 DrawTextSCentered(ystart2, font_info,
8731 "press the 'back' button.");
8732 ystart2 += ystep_line;
8733 DrawTextSCentered(ystart2, font_info,
8734 "To skip a button or axis,");
8735 ystart2 += ystep_line;
8736 DrawTextSCentered(ystart2, font_info,
8737 "press the 'menu' button.");
8739 DrawTextSCentered(ystart2, font_info,
8740 "To correct a mistake,");
8741 ystart2 += ystep_line;
8742 DrawTextSCentered(ystart2, font_info,
8743 "press the 'backspace' key.");
8744 ystart2 += ystep_line;
8745 DrawTextSCentered(ystart2, font_info,
8746 "To skip a button or axis,");
8747 ystart2 += ystep_line;
8748 DrawTextSCentered(ystart2, font_info,
8749 "press the 'return' key.");
8750 ystart2 += ystep_line;
8751 DrawTextSCentered(ystart2, font_info,
8752 "To exit, press the 'escape' key.");
8755 BlitBitmapMasked(controller, drawto, 0, 0,
8756 controller->width, controller->height,
8757 controller_x, controller_y);
8759 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8760 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8762 BlitBitmapMasked(marker, drawto, 0, 0,
8763 marker->width, marker->height,
8764 marker_x, marker_y);
8766 if (!screen_initialized)
8767 FadeIn(REDRAW_FIELD);
8771 screen_initialized = TRUE;
8773 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8775 // reset frame delay counter directly after updating screen
8776 ResetDelayCounter(&event_frame_delay);
8778 while (NextValidEvent(&event))
8782 case SDL_JOYAXISMOTION:
8783 if (event.jaxis.value > 20000 ||
8784 event.jaxis.value < -20000)
8786 for (j = 0; j < i; j++)
8787 if (steps[j].axis == event.jaxis.axis)
8792 if (step->marker != MARKER_AXIS_X &&
8793 step->marker != MARKER_AXIS_Y)
8796 step->axis = event.jaxis.axis;
8797 strcat(mapping, step->field);
8798 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8799 strcat(mapping, temp);
8807 case SDL_JOYHATMOTION:
8808 // ignore centering; we're probably just coming back
8809 // to the center from the previous item we set
8810 if (event.jhat.value == SDL_HAT_CENTERED)
8813 for (j = 0; j < i; j++)
8814 if (steps[j].hat == event.jhat.hat &&
8815 steps[j].hat_value == event.jhat.value)
8820 step->hat = event.jhat.hat;
8821 step->hat_value = event.jhat.value;
8822 strcat(mapping, step->field);
8823 snprintf(temp, sizeof(temp), ":h%u.%u,",
8824 event.jhat.hat, event.jhat.value );
8825 strcat(mapping, temp);
8832 case SDL_JOYBALLMOTION:
8835 case SDL_JOYBUTTONUP:
8836 for (j = 0; j < i; j++)
8837 if (steps[j].button == event.jbutton.button)
8842 step->button = event.jbutton.button;
8843 strcat(mapping, step->field);
8844 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8845 strcat(mapping, temp);
8852 case SDL_FINGERDOWN:
8853 case SDL_MOUSEBUTTONDOWN:
8861 if (event.key.keysym.sym == KSYM_BackSpace ||
8862 event.key.keysym.sym == KSYM_Back)
8874 prev_step = &steps[i - 1];
8875 strcpy(mapping, prev_step->mapping);
8882 if (event.key.keysym.sym == KSYM_space ||
8883 event.key.keysym.sym == KSYM_Return ||
8884 event.key.keysym.sym == KSYM_Menu)
8893 if (event.key.keysym.sym == KSYM_Escape)
8903 program.exit_function(0);
8910 // do not handle events for longer than standard frame delay period
8911 if (DelayReached(&event_frame_delay))
8920 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8923 // activate mapping for this game
8924 SDL_GameControllerAddMapping(mapping);
8926 // save mapping to personal mappings
8927 SaveSetup_AddGameControllerMapping(mapping);
8930 // wait until the last pending event was removed from event queue
8931 while (NextValidEvent(&event));
8936 static int ConfigureJoystickMain(int player_nr)
8938 char *device_name = setup.input[player_nr].joy.device_name;
8939 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8940 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8941 int success = FALSE;
8944 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8945 return JOYSTICK_NOT_AVAILABLE;
8947 if (!joystick_active || !setup.input[player_nr].use_joystick)
8948 return JOYSTICK_NOT_AVAILABLE;
8951 FadeOut(REDRAW_FIELD);
8953 // close all joystick devices (potentially opened as game controllers)
8954 for (i = 0; i < SDL_NumJoysticks(); i++)
8955 SDLCloseJoystick(i);
8957 // open joystick device as plain joystick to configure as game controller
8958 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8960 // as the joystick was successfully opened before, this should not happen
8961 if (joystick == NULL)
8964 // create new game controller mapping (buttons and axes) for joystick device
8965 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8967 // close joystick (and maybe re-open as configured game controller later)
8968 SDL_JoystickClose(joystick);
8970 // re-open all joystick devices (potentially as game controllers)
8971 for (i = 0; i < SDL_NumJoysticks(); i++)
8974 // clear all joystick input actions for all joystick devices
8975 SDLClearJoystickState();
8977 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8980 void ConfigureJoystick(int player_nr)
8982 boolean state = ConfigureJoystickMain(player_nr);
8984 if (state != JOYSTICK_NOT_CONFIGURED)
8986 boolean success = (state == JOYSTICK_CONFIGURED);
8987 char message1[MAX_OUTPUT_LINESIZE + 1];
8988 char *message2 = (success ? "configured!" : "not available!");
8989 char *device_name = setup.input[player_nr].joy.device_name;
8990 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8991 int font_nr = FONT_TITLE_1;
8992 int font_height = getFontHeight(font_nr);
8993 int ypos1 = SYSIZE / 2 - font_height * 2;
8994 int ypos2 = SYSIZE / 2 - font_height * 1;
8995 DelayCounter wait_frame_delay = { 2000 };
8997 ResetDelayCounter(&wait_frame_delay);
9001 sprintf(message1, "Joystick %d", nr);
9003 DrawTextSCentered(ypos1, font_nr, message1);
9004 DrawTextSCentered(ypos2, font_nr, message2);
9006 while (!DelayReached(&wait_frame_delay))
9012 DrawSetupScreen_Input();
9015 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9017 if (y < video.screen_height / 3)
9019 // remap touch gadgets to access upper part of the screen
9020 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9021 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9023 else if (y > 2 * video.screen_height / 3)
9025 // remap touch gadgets to access lower part of the screen
9026 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9027 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9031 static boolean ConfigureVirtualButtonsMain(void)
9033 static char *customize_step_text[] =
9042 char grid_button[] =
9044 CHAR_GRID_BUTTON_LEFT,
9045 CHAR_GRID_BUTTON_RIGHT,
9046 CHAR_GRID_BUTTON_UP,
9047 CHAR_GRID_BUTTON_DOWN,
9048 CHAR_GRID_BUTTON_SNAP,
9049 CHAR_GRID_BUTTON_DROP
9058 int font_nr = FONT_INPUT_1_ACTIVE;
9059 int font_height = getFontHeight(font_nr);
9060 int ypos1 = SYSIZE / 2 - font_height * 2;
9061 int ypos2 = SYSIZE / 2 - font_height * 1;
9062 boolean success = FALSE;
9063 boolean finished = FALSE;
9065 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9066 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9067 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9068 boolean set_grid_button = FALSE;
9069 int nr = GRID_ACTIVE_NR();
9072 for (x = 0; x < MAX_GRID_XSIZE; x++)
9073 for (y = 0; y < MAX_GRID_YSIZE; y++)
9074 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9076 overlay.grid_button_highlight = grid_button[step_nr];
9081 FadeOut(REDRAW_FIELD);
9085 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9086 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9087 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9089 FadeIn(REDRAW_FIELD);
9091 SetOverlayShowGrid(TRUE);
9093 // map gadgets for setup touch buttons menu screen
9094 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9100 while (NextValidEvent(&event))
9102 int action = ACTION_NONE;
9104 // ---------- handle events and set the resulting action ----------
9110 UserEvent *user = (UserEvent *)&event;
9111 int id = user->value1;
9113 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9114 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9115 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9116 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9121 case EVENT_KEYPRESS:
9123 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9125 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9126 key == KSYM_BackSpace ||
9127 key == KSYM_Back ? ACTION_BACK :
9128 key == KSYM_Return ||
9130 key == KSYM_space ? ACTION_NEXT :
9135 case EVENT_KEYRELEASE:
9136 key_joystick_mapping = 0;
9139 case EVENT_BUTTONPRESS:
9140 case EVENT_BUTTONRELEASE:
9142 ButtonEvent *button = (ButtonEvent *)&event;
9144 motion_status = FALSE;
9146 if (button->type == EVENT_BUTTONPRESS)
9147 button_status = button->button;
9149 button_status = MB_RELEASED;
9151 if (HandleGadgets(button->x, button->y, button_status))
9153 // do not handle this button event anymore
9157 button->x += video.screen_xoffset;
9158 button->y += video.screen_yoffset;
9160 x = button->x * overlay.grid_xsize / video.screen_width;
9161 y = button->y * overlay.grid_ysize / video.screen_height;
9163 if (button->type == EVENT_BUTTONPRESS)
9166 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9167 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9169 set_grid_button = TRUE;
9172 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9176 case EVENT_MOTIONNOTIFY:
9178 MotionEvent *motion = (MotionEvent *)&event;
9180 motion_status = TRUE;
9182 if (HandleGadgets(motion->x, motion->y, button_status))
9184 // do not handle this button event anymore
9188 motion->x += video.screen_xoffset;
9189 motion->y += video.screen_yoffset;
9191 x = motion->x * overlay.grid_xsize / video.screen_width;
9192 y = motion->y * overlay.grid_ysize / video.screen_height;
9194 set_grid_button = TRUE;
9196 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9200 case SDL_WINDOWEVENT:
9201 HandleWindowEvent((WindowEvent *) &event);
9203 // check if device has been rotated
9204 if (nr != GRID_ACTIVE_NR())
9206 nr = GRID_ACTIVE_NR();
9208 for (x = 0; x < MAX_GRID_XSIZE; x++)
9209 for (y = 0; y < MAX_GRID_YSIZE; y++)
9210 grid_button_old[x][y] = grid_button_tmp[x][y] =
9211 overlay.grid_button[x][y];
9216 case SDL_APP_WILLENTERBACKGROUND:
9217 case SDL_APP_DIDENTERBACKGROUND:
9218 case SDL_APP_WILLENTERFOREGROUND:
9219 case SDL_APP_DIDENTERFOREGROUND:
9220 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9224 HandleOtherEvents(&event);
9228 // ---------- perform action set by handling events ----------
9230 if (action == ACTION_ESCAPE)
9232 // abort and restore the old key bindings
9234 for (x = 0; x < MAX_GRID_XSIZE; x++)
9235 for (y = 0; y < MAX_GRID_YSIZE; y++)
9236 overlay.grid_button[x][y] = grid_button_old[x][y];
9238 FadeSkipNextFadeIn();
9242 else if (action == ACTION_BACK)
9244 // keep the configured key bindings and go to previous page
9250 FadeSkipNextFadeIn();
9255 else if (action == ACTION_NEXT)
9257 // keep the configured key bindings and go to next page
9261 // all virtual buttons configured
9269 if (action != ACTION_NONE && !finished)
9271 for (x = 0; x < MAX_GRID_XSIZE; x++)
9272 for (y = 0; y < MAX_GRID_YSIZE; y++)
9273 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9275 overlay.grid_button_highlight = grid_button[step_nr];
9277 // configure next virtual button
9281 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9282 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9283 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9286 if (set_grid_button)
9288 overlay.grid_button[x][y] =
9289 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9290 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9291 grid_button_tmp[x][y]);
9293 set_grid_button = FALSE;
9300 for (x = 0; x < MAX_GRID_XSIZE; x++)
9301 for (y = 0; y < MAX_GRID_YSIZE; y++)
9302 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9304 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9306 SetOverlayShowGrid(FALSE);
9311 void ConfigureVirtualButtons(void)
9313 boolean success = ConfigureVirtualButtonsMain();
9315 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9316 SCREEN_MASK_TOUCH2);
9320 int font_nr = FONT_TITLE_1;
9321 int font_height = getFontHeight(font_nr);
9322 int ypos1 = SYSIZE / 2 - font_height * 2;
9323 int ypos2 = SYSIZE / 2 - font_height * 1;
9324 DelayCounter wait_frame_delay = { 2000 };
9326 ResetDelayCounter(&wait_frame_delay);
9330 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9331 DrawTextSCentered(ypos2, font_nr, "configured!");
9333 while (!DelayReached(&wait_frame_delay))
9340 void DrawSetupScreen(void)
9345 if (setup_mode == SETUP_MODE_INPUT)
9346 DrawSetupScreen_Input();
9347 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9348 DrawChooseTree(&scores_type_current);
9349 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9350 DrawChooseTree(&game_speed_current);
9351 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9352 DrawChooseTree(&scroll_delay_current);
9353 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9354 DrawChooseTree(&snapshot_mode_current);
9355 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9356 DrawChooseTree(&window_size_current);
9357 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9358 DrawChooseTree(&scaling_type_current);
9359 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9360 DrawChooseTree(&rendering_mode_current);
9361 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9362 DrawChooseTree(&vsync_mode_current);
9363 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9364 DrawChooseTree(&artwork.gfx_current);
9365 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9366 DrawChooseTree(&artwork.snd_current);
9367 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9368 DrawChooseTree(&artwork.mus_current);
9369 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9370 DrawChooseTree(&volume_simple_current);
9371 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9372 DrawChooseTree(&volume_loops_current);
9373 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9374 DrawChooseTree(&volume_music_current);
9375 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9376 DrawChooseTree(&touch_control_current);
9377 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9378 DrawChooseTree(&move_distance_current);
9379 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9380 DrawChooseTree(&drop_distance_current);
9381 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9382 DrawChooseTree(&transparency_current);
9383 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9384 DrawChooseTree(&grid_size_current[0][0]);
9385 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9386 DrawChooseTree(&grid_size_current[0][1]);
9387 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9388 DrawChooseTree(&grid_size_current[1][0]);
9389 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9390 DrawChooseTree(&grid_size_current[1][1]);
9392 DrawSetupScreen_Generic();
9394 PlayMenuSoundsAndMusic();
9397 void RedrawSetupScreenAfterFullscreenToggle(void)
9399 if (setup_mode == SETUP_MODE_GRAPHICS ||
9400 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9402 // update list selection from "setup.window_scaling_percent"
9403 execSetupGraphics_setWindowSizes(TRUE);
9409 void RedrawSetupScreenAfterScreenRotation(int nr)
9413 if (setup_mode == SETUP_MODE_TOUCH)
9415 // update virtual button settings (depending on screen orientation)
9418 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9420 // save already configured virtual buttons
9421 for (x = 0; x < MAX_GRID_XSIZE; x++)
9422 for (y = 0; y < MAX_GRID_YSIZE; y++)
9423 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9427 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9429 if (setup_mode == SETUP_MODE_INPUT)
9430 HandleSetupScreen_Input(mx, my, dx, dy, button);
9431 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9432 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9433 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9434 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9435 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9436 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9437 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9438 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9439 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9440 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9441 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9442 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9443 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9444 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9445 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9446 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9447 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9448 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9449 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9450 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9451 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9452 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9453 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9454 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9455 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9456 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9457 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9458 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9459 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9460 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9461 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9462 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9463 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9464 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9465 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9466 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9467 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9468 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9469 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9470 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9471 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9472 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9473 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9474 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9476 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9479 void HandleGameActions(void)
9481 if (setup.ask_on_game_over)
9484 if (game.restart_game_message != NULL)
9486 RequestRestartGame(game.restart_game_message);
9491 if (game_status != GAME_MODE_PLAYING)
9494 GameActions(); // main game loop
9496 if (tape.auto_play && !tape.playing)
9497 AutoPlayTapesContinue(); // continue automatically playing next tape
9501 // ---------- new screen button stuff --------------------------------------
9505 int gfx_unpressed, gfx_pressed;
9506 struct MenuPosInfo *pos;
9507 boolean *check_value;
9510 unsigned int event_mask;
9511 boolean is_touch_button;
9513 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9516 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9517 &menu.main.button.prev_level, NULL,
9518 SCREEN_CTRL_ID_PREV_LEVEL,
9520 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9521 FALSE, "previous level"
9524 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9525 &menu.main.button.next_level, NULL,
9526 SCREEN_CTRL_ID_NEXT_LEVEL,
9528 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9532 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9533 &menu.scores.button.prev_level, NULL,
9534 SCREEN_CTRL_ID_PREV_LEVEL2,
9535 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9536 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9537 FALSE, "previous level"
9540 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9541 &menu.scores.button.next_level, NULL,
9542 SCREEN_CTRL_ID_NEXT_LEVEL2,
9543 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9544 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9548 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9549 &menu.scores.button.prev_score, NULL,
9550 SCREEN_CTRL_ID_PREV_SCORE,
9551 SCREEN_MASK_SCORES_INFO,
9552 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9553 FALSE, "previous score"
9556 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9557 &menu.scores.button.next_score, NULL,
9558 SCREEN_CTRL_ID_NEXT_SCORE,
9559 SCREEN_MASK_SCORES_INFO,
9560 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9564 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE,
9565 &menu.scores.button.play_tape, NULL,
9566 SCREEN_CTRL_ID_PLAY_TAPE,
9567 SCREEN_MASK_SCORES_INFO,
9572 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9573 &menu.main.button.first_level, NULL,
9574 SCREEN_CTRL_ID_FIRST_LEVEL,
9577 FALSE, "first level"
9580 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9581 &menu.main.button.last_level, NULL,
9582 SCREEN_CTRL_ID_LAST_LEVEL,
9588 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9589 &menu.main.button.level_number, NULL,
9590 SCREEN_CTRL_ID_LEVEL_NUMBER,
9593 FALSE, "level number"
9596 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9597 &menu.setup.button.prev_player, NULL,
9598 SCREEN_CTRL_ID_PREV_PLAYER,
9600 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9601 FALSE, "previous player"
9604 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9605 &menu.setup.button.next_player, NULL,
9606 SCREEN_CTRL_ID_NEXT_PLAYER,
9608 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9609 FALSE, "next player"
9612 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9613 &menu.main.button.insert_solution, NULL,
9614 SCREEN_CTRL_ID_INSERT_SOLUTION,
9615 SCREEN_MASK_MAIN_HAS_SOLUTION,
9617 FALSE, "insert solution tape"
9620 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9621 &menu.main.button.play_solution, NULL,
9622 SCREEN_CTRL_ID_PLAY_SOLUTION,
9623 SCREEN_MASK_MAIN_HAS_SOLUTION,
9625 FALSE, "play solution tape"
9628 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9629 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9630 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9632 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9633 FALSE, "switch ECS/AGA chipset"
9636 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9637 &menu.setup.button.touch_back, NULL,
9638 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9641 TRUE, "previous page"
9644 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9645 &menu.setup.button.touch_next, NULL,
9646 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9652 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9653 &menu.setup.button.touch_back2, NULL,
9654 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9657 TRUE, "previous page"
9660 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9661 &menu.setup.button.touch_next2, NULL,
9662 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9671 int gfx_unpressed, gfx_pressed;
9675 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9678 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9679 -1, -1, // these values are not constant, but can change at runtime
9680 SCREEN_CTRL_ID_SCROLL_UP,
9684 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9685 -1, -1, // these values are not constant, but can change at runtime
9686 SCREEN_CTRL_ID_SCROLL_DOWN,
9693 int gfx_unpressed, gfx_pressed;
9699 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9702 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9703 -1, -1, // these values are not constant, but can change at runtime
9704 -1, -1, // these values are not constant, but can change at runtime
9705 GD_TYPE_SCROLLBAR_VERTICAL,
9706 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9707 "scroll level series vertically"
9719 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9722 IMG_SETUP_INPUT_TEXT,
9723 SCREEN_CTRL_ID_NETWORK_SERVER,
9724 -1, -1, // these values are not constant, but can change at runtime
9725 MAX_SETUP_TEXT_INPUT_LEN,
9726 network_server_hostname,
9727 "Network Server Hostname / IP"
9731 static void CreateScreenMenubuttons(void)
9733 struct GadgetInfo *gi;
9734 unsigned int event_mask;
9737 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9739 struct MenuPosInfo *pos = menubutton_info[i].pos;
9740 int screen_mask = menubutton_info[i].screen_mask;
9741 boolean is_touch_button = menubutton_info[i].is_touch_button;
9742 boolean is_check_button = menubutton_info[i].check_value != NULL;
9743 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9744 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9745 menubutton_info[i].gfx_unpressed);
9746 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9747 int gfx_unpressed, gfx_pressed;
9748 int x, y, width, height;
9749 int gd_x1, gd_x2, gd_y1, gd_y2;
9750 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9751 int id = menubutton_info[i].gadget_id;
9752 int type = GD_TYPE_NORMAL_BUTTON;
9753 boolean checked = FALSE;
9755 // do not use touch buttons if overlay touch buttons are disabled
9756 if (is_touch_button && !setup.touch.overlay_buttons)
9759 event_mask = menubutton_info[i].event_mask;
9761 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9762 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9764 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9765 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9767 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9768 gfx_pressed = menubutton_info[i].gfx_pressed;
9769 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9770 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9771 gd_x1 = graphic_info[gfx_unpressed].src_x;
9772 gd_y1 = graphic_info[gfx_unpressed].src_y;
9773 gd_x2 = graphic_info[gfx_pressed].src_x;
9774 gd_y2 = graphic_info[gfx_pressed].src_y;
9780 if (has_gfx_pressed)
9782 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9783 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9786 if (is_check_button)
9788 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9789 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9790 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9791 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9793 type = GD_TYPE_CHECK_BUTTON;
9794 checked = *menubutton_info[i].check_value;
9797 if (is_score_button)
9799 // if x/y set to -1, dynamically place buttons next to title text
9800 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9802 // special compatibility handling for "Snake Bite" graphics set
9803 if (strPrefix(leveldir_current->identifier, "snake_bite"))
9804 title_width = strlen(INFOTEXT_SCORE_ENTRY) * 32;
9806 // use "SX" here to center buttons (ignore horizontal draw offset)
9808 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9809 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9810 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9811 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9813 // use "mSY" here to place buttons (respect vertical draw offset)
9815 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
9816 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
9819 gi = CreateGadget(GDI_CUSTOM_ID, id,
9820 GDI_CUSTOM_TYPE_ID, i,
9821 GDI_IMAGE_ID, gfx_unpressed,
9822 GDI_INFO_TEXT, menubutton_info[i].infotext,
9828 GDI_STATE, GD_BUTTON_UNPRESSED,
9829 GDI_CHECKED, checked,
9830 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9831 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9832 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9833 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9834 GDI_DIRECT_DRAW, FALSE,
9835 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9836 GDI_EVENT_MASK, event_mask,
9837 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9841 Fail("cannot create gadget");
9843 screen_gadget[id] = gi;
9847 static void CreateScreenScrollbuttons(void)
9849 struct GadgetInfo *gi;
9850 unsigned int event_mask;
9853 // these values are not constant, but can change at runtime
9854 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9855 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9856 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9857 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9859 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9861 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9862 int gfx_unpressed, gfx_pressed;
9863 int x, y, width, height;
9864 int gd_x1, gd_x2, gd_y1, gd_y2;
9865 int id = scrollbutton_info[i].gadget_id;
9867 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9869 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9870 y = mSY + scrollbutton_info[i].y;
9871 width = SC_SCROLLBUTTON_XSIZE;
9872 height = SC_SCROLLBUTTON_YSIZE;
9874 // correct scrollbar position if placed outside menu (playfield) area
9875 if (x > SX + SC_SCROLL_UP_XPOS)
9876 x = SX + SC_SCROLL_UP_XPOS;
9878 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9879 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9880 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9882 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9883 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9884 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9885 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9886 gd_x1 = graphic_info[gfx_unpressed].src_x;
9887 gd_y1 = graphic_info[gfx_unpressed].src_y;
9888 gd_x2 = graphic_info[gfx_pressed].src_x;
9889 gd_y2 = graphic_info[gfx_pressed].src_y;
9891 gi = CreateGadget(GDI_CUSTOM_ID, id,
9892 GDI_CUSTOM_TYPE_ID, i,
9893 GDI_IMAGE_ID, gfx_unpressed,
9894 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9899 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9900 GDI_STATE, GD_BUTTON_UNPRESSED,
9901 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9902 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9903 GDI_DIRECT_DRAW, FALSE,
9904 GDI_EVENT_MASK, event_mask,
9905 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9909 Fail("cannot create gadget");
9911 screen_gadget[id] = gi;
9915 static void CreateScreenScrollbars(void)
9919 // these values are not constant, but can change at runtime
9920 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9921 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9922 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9923 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9925 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9927 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9928 int gfx_unpressed, gfx_pressed;
9929 int x, y, width, height;
9930 int gd_x1, gd_x2, gd_y1, gd_y2;
9931 struct GadgetInfo *gi;
9932 int items_max, items_visible, item_position;
9933 unsigned int event_mask;
9934 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9935 int id = scrollbar_info[i].gadget_id;
9937 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9939 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9940 y = mSY + scrollbar_info[i].y;
9941 width = scrollbar_info[i].width;
9942 height = scrollbar_info[i].height;
9944 // correct scrollbar position if placed outside menu (playfield) area
9945 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9946 x = SX + SC_SCROLL_VERTICAL_XPOS;
9948 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9949 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9951 items_max = num_page_entries;
9952 items_visible = num_page_entries;
9955 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9956 gfx_pressed = scrollbar_info[i].gfx_pressed;
9957 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9958 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9959 gd_x1 = graphic_info[gfx_unpressed].src_x;
9960 gd_y1 = graphic_info[gfx_unpressed].src_y;
9961 gd_x2 = graphic_info[gfx_pressed].src_x;
9962 gd_y2 = graphic_info[gfx_pressed].src_y;
9964 gi = CreateGadget(GDI_CUSTOM_ID, id,
9965 GDI_CUSTOM_TYPE_ID, i,
9966 GDI_IMAGE_ID, gfx_unpressed,
9967 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9972 GDI_TYPE, scrollbar_info[i].type,
9973 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9974 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9975 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9976 GDI_WHEEL_AREA_X, SX,
9977 GDI_WHEEL_AREA_Y, SY,
9978 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9979 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9980 GDI_STATE, GD_BUTTON_UNPRESSED,
9981 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9982 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9983 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9984 GDI_DIRECT_DRAW, FALSE,
9985 GDI_EVENT_MASK, event_mask,
9986 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9990 Fail("cannot create gadget");
9992 screen_gadget[id] = gi;
9996 static void CreateScreenTextInputGadgets(void)
10000 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10002 int graphic = textinput_info[i].graphic;
10003 struct GraphicInfo *gd = &graphic_info[graphic];
10004 int gd_x1 = gd->src_x;
10005 int gd_y1 = gd->src_y;
10006 int gd_x2 = gd->src_x + gd->active_xoffset;
10007 int gd_y2 = gd->src_y + gd->active_yoffset;
10008 struct GadgetInfo *gi;
10009 unsigned int event_mask;
10010 int id = textinput_info[i].gadget_id;
10011 int x = textinput_info[i].x;
10012 int y = textinput_info[i].y;
10014 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10016 gi = CreateGadget(GDI_CUSTOM_ID, id,
10017 GDI_CUSTOM_TYPE_ID, i,
10018 GDI_INFO_TEXT, textinput_info[i].infotext,
10021 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10022 GDI_TEXT_VALUE, textinput_info[i].value,
10023 GDI_TEXT_SIZE, textinput_info[i].size,
10024 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10025 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10026 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10027 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10028 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10029 GDI_DESIGN_WIDTH, gd->width,
10030 GDI_EVENT_MASK, event_mask,
10031 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10032 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10036 Fail("cannot create gadget");
10038 screen_gadget[id] = gi;
10042 void CreateScreenGadgets(void)
10044 CreateScreenMenubuttons();
10046 CreateScreenScrollbuttons();
10047 CreateScreenScrollbars();
10049 CreateScreenTextInputGadgets();
10052 void FreeScreenGadgets(void)
10056 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10057 FreeGadget(screen_gadget[i]);
10060 static void RedrawScreenMenuGadgets(int screen_mask)
10064 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10065 if (screen_mask & menubutton_info[i].screen_mask)
10066 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10069 static void MapScreenMenuGadgets(int screen_mask)
10073 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10074 if (screen_mask & menubutton_info[i].screen_mask)
10075 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10078 static void UnmapScreenMenuGadgets(int screen_mask)
10082 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10084 if (screen_mask & menubutton_info[i].screen_mask)
10086 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10088 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10089 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10090 screen_gadget[menubutton_info[i].gadget_id]->y,
10091 screen_gadget[menubutton_info[i].gadget_id]->width,
10092 screen_gadget[menubutton_info[i].gadget_id]->height);
10097 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10100 MapScreenMenuGadgets(screen_mask);
10102 UnmapScreenMenuGadgets(screen_mask);
10105 static void MapScreenGadgets(int num_entries)
10109 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10112 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10113 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10115 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10116 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10119 static void UnmapScreenGadgets()
10123 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10124 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10126 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10127 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10130 static void MapScreenTreeGadgets(TreeInfo *ti)
10132 MapScreenGadgets(numTreeInfoInGroup(ti));
10135 static void UnmapScreenTreeGadgets(void)
10137 UnmapScreenGadgets();
10140 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10142 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10143 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10144 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10145 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10147 if (pos_1->x == -1 && pos_1->y == -1)
10148 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10150 if (pos_2->x == -1 && pos_2->y == -1)
10151 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10154 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10156 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10157 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10159 // set gadget position dynamically, pre-defined or off-screen
10160 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10161 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10163 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10164 MapGadget(gi); // (needed if deactivated on last score page)
10167 static void HandleScreenGadgets(struct GadgetInfo *gi)
10169 int id = gi->custom_id;
10170 int button = gi->event.button;
10171 int step = (button == MB_LEFTBUTTON ? 1 :
10172 button == MB_MIDDLEBUTTON ? 5 :
10173 button == MB_RIGHTBUTTON ? 10 : 1);
10177 case SCREEN_CTRL_ID_PREV_LEVEL:
10178 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10181 case SCREEN_CTRL_ID_NEXT_LEVEL:
10182 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10185 case SCREEN_CTRL_ID_PREV_LEVEL2:
10186 HandleHallOfFame_SelectLevel(step, -1);
10189 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10190 HandleHallOfFame_SelectLevel(step, +1);
10193 case SCREEN_CTRL_ID_PREV_SCORE:
10194 HandleScoreInfo_SelectScore(step, -1);
10197 case SCREEN_CTRL_ID_NEXT_SCORE:
10198 HandleScoreInfo_SelectScore(step, +1);
10201 case SCREEN_CTRL_ID_PLAY_TAPE:
10202 HandleScoreInfo_PlayTape();
10205 case SCREEN_CTRL_ID_FIRST_LEVEL:
10206 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10209 case SCREEN_CTRL_ID_LAST_LEVEL:
10210 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10213 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10214 CloseDoor(DOOR_CLOSE_2);
10215 SetGameStatus(GAME_MODE_LEVELNR);
10216 DrawChooseLevelNr();
10219 case SCREEN_CTRL_ID_PREV_PLAYER:
10220 HandleSetupScreen_Input_Player(step, -1);
10223 case SCREEN_CTRL_ID_NEXT_PLAYER:
10224 HandleSetupScreen_Input_Player(step, +1);
10227 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10228 InsertSolutionTape();
10231 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10232 PlaySolutionTape();
10235 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10236 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10240 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10241 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10242 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10243 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10244 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10247 case SCREEN_CTRL_ID_SCROLL_UP:
10248 if (game_status == GAME_MODE_NAMES)
10249 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10250 else if (game_status == GAME_MODE_LEVELS)
10251 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10252 else if (game_status == GAME_MODE_LEVELNR)
10253 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10254 else if (game_status == GAME_MODE_SETUP)
10255 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10256 else if (game_status == GAME_MODE_INFO)
10257 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10258 else if (game_status == GAME_MODE_SCORES)
10259 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10262 case SCREEN_CTRL_ID_SCROLL_DOWN:
10263 if (game_status == GAME_MODE_NAMES)
10264 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10265 else if (game_status == GAME_MODE_LEVELS)
10266 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10267 else if (game_status == GAME_MODE_LEVELNR)
10268 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10269 else if (game_status == GAME_MODE_SETUP)
10270 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10271 else if (game_status == GAME_MODE_INFO)
10272 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10273 else if (game_status == GAME_MODE_SCORES)
10274 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10277 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10278 if (game_status == GAME_MODE_NAMES)
10279 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10280 else if (game_status == GAME_MODE_LEVELS)
10281 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10282 else if (game_status == GAME_MODE_LEVELNR)
10283 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10284 else if (game_status == GAME_MODE_SETUP)
10285 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10286 else if (game_status == GAME_MODE_INFO)
10287 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10288 else if (game_status == GAME_MODE_SCORES)
10289 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10292 case SCREEN_CTRL_ID_NETWORK_SERVER:
10294 if (!strEqual(gi->textinput.value, ""))
10296 setString(&setup.network_server_hostname, gi->textinput.value);
10298 network.server_host = setup.network_server_hostname;
10302 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10304 network.server_host = NULL;
10307 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10308 network.server_host = NULL;
10310 execSetupGame_setNetworkServerText();
10322 void HandleScreenGadgetKeys(Key key)
10324 if (key == setup.shortcut.tape_play)
10325 HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
10328 void DumpScreenIdentifiers(void)
10332 Print("Active screen elements on current screen:\n");
10334 for (i = 0; main_controls[i].nr != -1; i++)
10336 struct MainControlInfo *mci = &main_controls[i];
10338 if (mci->button_graphic != -1)
10340 char *token = getTokenFromImageID(mci->button_graphic);
10342 Print("- '%s'\n", token);
10349 boolean DoScreenAction(int image_id)
10353 if (game_status != GAME_MODE_MAIN)
10356 for (i = 0; main_controls[i].nr != -1; i++)
10358 struct MainControlInfo *mci = &main_controls[i];
10359 struct MenuPosInfo *pos = mci->pos_button;
10361 if (mci->button_graphic == image_id)
10363 int x = mSX + pos->x;
10364 int y = mSY + pos->y;
10366 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10375 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10377 // get tree info node of newly added level or artwork set
10378 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10379 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10381 if (tree_node_new == NULL) // should not happen
10384 // if request dialog is active, do nothing
10385 if (game.request_active)
10388 if (game_status == GAME_MODE_MAIN &&
10389 tree_type == TREE_TYPE_LEVEL_DIR)
10391 // when adding new level set in main menu, select it as current level set
10393 // change current level set to newly added level set from zip file
10394 leveldir_current = tree_node_new;
10396 // change current level number to first level of newly added level set
10397 level_nr = leveldir_current->first_level;
10399 // redraw screen to reflect changed level set
10402 // save this level set and level number as last selected level set
10403 SaveLevelSetup_LastSeries();
10404 SaveLevelSetup_SeriesInfo();
10406 else if (game_status == GAME_MODE_LEVELS &&
10407 tree_type == TREE_TYPE_LEVEL_DIR)
10409 // when adding new level set in level set menu, set cursor and update screen
10411 leveldir_current = tree_node_new;
10413 DrawChooseTree(&leveldir_current);
10415 else if (game_status == GAME_MODE_SETUP)
10417 // when adding new artwork set in setup menu, set cursor and update screen
10419 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10420 tree_type == TREE_TYPE_GRAPHICS_DIR)
10422 artwork.gfx_current = tree_node_new;
10424 DrawChooseTree(&artwork.gfx_current);
10426 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10427 tree_type == TREE_TYPE_SOUNDS_DIR)
10429 artwork.snd_current = tree_node_new;
10431 DrawChooseTree(&artwork.snd_current);
10433 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10434 tree_type == TREE_TYPE_MUSIC_DIR)
10436 artwork.mus_current = tree_node_new;
10438 DrawChooseTree(&artwork.mus_current);
10443 static int UploadTapes(void)
10445 SetGameStatus(GAME_MODE_LOADING);
10447 FadeSetEnterScreen();
10448 FadeOut(REDRAW_ALL);
10450 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10452 FadeIn(REDRAW_ALL);
10454 DrawInitTextHead("Uploading tapes");
10456 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10457 global.autoplay_leveldir = "ALL";
10458 global.autoplay_all = TRUE;
10460 int num_tapes_uploaded = AutoPlayTapes();
10462 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10463 global.autoplay_leveldir = NULL;
10464 global.autoplay_all = FALSE;
10466 SetGameStatus(GAME_MODE_MAIN);
10470 return num_tapes_uploaded;
10473 static boolean OfferUploadTapes(void)
10475 if (!Request(setup.has_remaining_tapes ?
10476 "Upload missing tapes to the high score server now?" :
10477 "Upload all your tapes to the high score server now?", REQ_ASK))
10480 int num_tapes_uploaded = UploadTapes();
10483 if (num_tapes_uploaded < 0)
10485 num_tapes_uploaded = -num_tapes_uploaded - 1;
10487 if (num_tapes_uploaded == 0)
10488 sprintf(message, "Upload failed! No tapes uploaded!");
10489 else if (num_tapes_uploaded == 1)
10490 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10492 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10493 num_tapes_uploaded);
10495 Request(message, REQ_CONFIRM);
10497 // if uploading tapes failed, add tape upload entry to setup menu
10498 setup.provide_uploading_tapes = TRUE;
10499 setup.has_remaining_tapes = TRUE;
10501 SaveSetup_ServerSetup();
10506 if (num_tapes_uploaded == 0)
10507 sprintf(message, "No tapes uploaded!");
10508 else if (num_tapes_uploaded == 1)
10509 sprintf(message, "1 tape uploaded!");
10511 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10513 Request(message, REQ_CONFIRM);
10515 if (num_tapes_uploaded > 0)
10516 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10518 // after all tapes have been uploaded, remove entry from setup menu
10519 setup.provide_uploading_tapes = FALSE;
10520 setup.has_remaining_tapes = FALSE;
10522 SaveSetup_ServerSetup();
10527 static void CheckUploadTapes(void)
10529 if (!setup.ask_for_uploading_tapes)
10532 // after asking for uploading tapes, do not ask again
10533 setup.ask_for_uploading_tapes = FALSE;
10534 setup.ask_for_remaining_tapes = FALSE;
10536 if (directoryExists(getTapeDir(NULL)))
10538 boolean tapes_uploaded = OfferUploadTapes();
10540 if (!tapes_uploaded)
10542 Request(setup.has_remaining_tapes ?
10543 "You can upload missing tapes from the setup menu later!" :
10544 "You can upload your tapes from the setup menu later!",
10550 // if tapes directory does not exist yet, never offer uploading all tapes
10551 setup.provide_uploading_tapes = FALSE;
10554 SaveSetup_ServerSetup();
10557 static void UpgradePlayerUUID(void)
10559 ApiResetUUIDAsThread(getUUID());
10562 static void CheckUpgradePlayerUUID(void)
10564 if (setup.player_version > 1)
10567 UpgradePlayerUUID();
10570 void CheckApiServerTasks(void)
10572 // check if the player's UUID has to be upgraded
10573 CheckUpgradePlayerUUID();
10575 // check if there are any tapes to be uploaded
10576 CheckUploadTapes();