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 void drawChooseTreeEdit(int ypos_raw, boolean active)
1536 int sx = getChooseTreeEditXPos(POS_LEFT);
1537 int sy = getChooseTreeEditYPos(ypos_raw);
1538 int font_nr = getChooseTreeEditFont(active);
1540 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1543 static void DrawHeadline(void)
1545 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1546 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1549 static void DrawTitleScreenImage(int nr, boolean initial)
1551 int graphic = getTitleScreenGraphic(nr, initial);
1552 Bitmap *bitmap = graphic_info[graphic].bitmap;
1553 int width = graphic_info[graphic].width;
1554 int height = graphic_info[graphic].height;
1555 int src_x = graphic_info[graphic].src_x;
1556 int src_y = graphic_info[graphic].src_y;
1562 if (width > WIN_XSIZE)
1564 // image width too large for window => center image horizontally
1565 src_x = (width - WIN_XSIZE) / 2;
1569 if (height > WIN_YSIZE)
1571 // image height too large for window => center image vertically
1572 src_y = (height - WIN_YSIZE) / 2;
1576 // always display title screens centered
1577 dst_x = (WIN_XSIZE - width) / 2;
1578 dst_y = (WIN_YSIZE - height) / 2;
1580 SetDrawBackgroundMask(REDRAW_ALL);
1581 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1583 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1585 if (DrawingOnBackground(dst_x, dst_y))
1586 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1588 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1590 redraw_mask = REDRAW_ALL;
1593 static void DrawTitleScreenMessage(int nr, boolean initial)
1595 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1596 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1598 if (filename == NULL)
1601 // force TITLE font on title message screen
1602 SetFontStatus(getTitleMessageGameMode(initial));
1604 // if chars *and* width set to "-1", automatically determine width
1605 if (tmi->chars == -1 && tmi->width == -1)
1606 tmi->width = viewport.window[game_status].width;
1608 // if lines *and* height set to "-1", automatically determine height
1609 if (tmi->lines == -1 && tmi->height == -1)
1610 tmi->height = viewport.window[game_status].height;
1612 // if chars set to "-1", automatically determine by text and font width
1613 if (tmi->chars == -1)
1614 tmi->chars = tmi->width / getFontWidth(tmi->font);
1616 tmi->width = tmi->chars * getFontWidth(tmi->font);
1618 // if lines set to "-1", automatically determine by text and font height
1619 if (tmi->lines == -1)
1620 tmi->lines = tmi->height / getFontHeight(tmi->font);
1622 tmi->height = tmi->lines * getFontHeight(tmi->font);
1624 // if x set to "-1", automatically determine by width and alignment
1626 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1628 // if y set to "-1", automatically determine by height and alignment
1630 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1632 SetDrawBackgroundMask(REDRAW_ALL);
1633 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1635 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1637 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1638 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1639 tmi->autowrap, tmi->centered, tmi->parse_comments);
1644 static void DrawTitleScreen(void)
1646 KeyboardAutoRepeatOff();
1648 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1651 static boolean CheckTitleScreen(boolean levelset_has_changed)
1653 static boolean show_title_initial = TRUE;
1654 boolean show_titlescreen = FALSE;
1656 // needed to be able to skip title screen, if no image or message defined
1657 InitializeTitleControls(show_title_initial);
1659 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1660 show_titlescreen = TRUE;
1662 // show initial title images and messages only once at program start
1663 show_title_initial = FALSE;
1665 return (show_titlescreen && num_title_screens > 0);
1668 void DrawMainMenu(void)
1670 static LevelDirTree *leveldir_last_valid = NULL;
1671 boolean levelset_has_changed = FALSE;
1672 int fade_mask = REDRAW_FIELD;
1674 LimitScreenUpdates(FALSE);
1676 FadeSetLeaveScreen();
1678 // do not fade out here -- function may continue and fade on editor screen
1681 FadeMenuSoundsAndMusic();
1683 ExpireSoundLoops(FALSE);
1685 KeyboardAutoRepeatOn();
1687 audio.sound_deactivated = FALSE;
1691 // needed if last screen was the playing screen, invoked from level editor
1692 if (level_editor_test_game)
1694 CloseDoor(DOOR_CLOSE_ALL);
1696 SetGameStatus(GAME_MODE_EDITOR);
1703 // needed if last screen was the playing screen, invoked from hall of fame
1704 if (score_info_tape_play)
1706 CloseDoor(DOOR_CLOSE_ALL);
1708 SetGameStatus(GAME_MODE_SCOREINFO);
1710 DrawScoreInfo(scores.last_entry_nr);
1715 // leveldir_current may be invalid (level group, parent link, node copy)
1716 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1718 if (leveldir_current != leveldir_last_valid)
1720 UpdateLastPlayedLevels_TreeInfo();
1722 levelset_has_changed = TRUE;
1725 // store valid level series information
1726 leveldir_last_valid = leveldir_current;
1728 // needed if last screen (level choice) changed graphics, sounds or music
1729 ReloadCustomArtwork(0);
1731 if (CheckTitleScreen(levelset_has_changed))
1733 SetGameStatus(GAME_MODE_TITLE);
1740 if (redraw_mask & REDRAW_ALL)
1741 fade_mask = REDRAW_ALL;
1744 fade_mask = REDRAW_ALL;
1748 // needed if different viewport properties defined for menues
1749 ChangeViewportPropertiesIfNeeded();
1751 SetDrawtoField(DRAW_TO_BACKBUFFER);
1753 // level_nr may have been set to value over handicap with level editor
1754 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1755 level_nr = leveldir_current->handicap_level;
1757 LoadLevel(level_nr);
1758 LoadScore(level_nr);
1760 SaveLevelSetup_SeriesInfo();
1762 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1763 SetDrawDeactivationMask(REDRAW_NONE);
1764 SetDrawBackgroundMask(REDRAW_FIELD);
1766 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1769 if (fade_mask == REDRAW_ALL)
1770 RedrawGlobalBorder();
1775 InitializeMainControls();
1777 DrawCursorAndText_Main(-1, FALSE, FALSE);
1778 DrawPreviewLevelInitial();
1779 DrawNetworkPlayers();
1781 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1784 if (TAPE_IS_EMPTY(tape))
1786 DrawCompleteVideoDisplay();
1788 PlayMenuSoundsAndMusic();
1790 // create gadgets for main menu screen
1791 FreeScreenGadgets();
1792 CreateScreenGadgets();
1794 // may be required if audio buttons shown on tape and changed in setup menu
1796 CreateGameButtons();
1798 // map gadgets for main menu screen
1800 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1801 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1803 // copy actual game door content to door double buffer for OpenDoor()
1804 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1805 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1807 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1809 DrawMaskedBorder(fade_mask);
1814 // update screen area with special editor door
1815 redraw_mask |= REDRAW_ALL;
1818 SetMouseCursor(CURSOR_DEFAULT);
1820 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1822 SyncEmscriptenFilesystem();
1824 // needed once after program start or after user change
1825 CheckApiServerTasks();
1828 static void gotoTopLevelDir(void)
1830 // move upwards until inside (but not above) top level directory
1831 while (leveldir_current->node_parent &&
1832 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1834 // write a "path" into level tree for easy navigation to last level
1835 if (leveldir_current->node_parent->node_group->cl_first == -1)
1837 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1838 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1839 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1840 int cl_first, cl_cursor;
1842 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1843 cl_cursor = leveldir_pos - cl_first;
1845 leveldir_current->node_parent->node_group->cl_first = cl_first;
1846 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1849 leveldir_current = leveldir_current->node_parent;
1853 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1855 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1857 return (use_frame_counter ? video.frame_counter : Counter());
1860 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1861 struct TitleFadingInfo *fi)
1863 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1866 static void ResetTitleAutoDelay(unsigned int *counter_var,
1867 struct TitleFadingInfo *fi)
1869 *counter_var = getAutoDelayCounter(fi);
1872 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1874 static unsigned int title_delay = 0;
1875 static int title_screen_nr = 0;
1876 static int last_sound = -1, last_music = -1;
1877 boolean return_to_main_menu = FALSE;
1878 struct TitleControlInfo *tci;
1881 if (button == MB_MENU_INITIALIZE)
1884 title_screen_nr = 0;
1885 tci = &title_controls[title_screen_nr];
1887 SetAnimStatus(getTitleAnimMode(tci));
1889 last_sound = SND_UNDEFINED;
1890 last_music = MUS_UNDEFINED;
1892 if (num_title_screens != 0)
1894 FadeSetEnterScreen();
1896 // use individual title fading instead of global "enter screen" fading
1897 fading = getTitleFading(tci);
1900 if (game_status_last_screen == GAME_MODE_INFO)
1902 if (num_title_screens == 0)
1904 // switch game mode from title screen mode back to info screen mode
1905 SetGameStatus(GAME_MODE_INFO);
1907 // store that last screen was info screen, not main menu screen
1908 game_status_last_screen = GAME_MODE_INFO;
1910 DrawInfoScreen_NotAvailable("Title screen information:",
1911 "No title screen for this level set.");
1916 FadeMenuSoundsAndMusic();
1918 FadeOut(REDRAW_ALL);
1920 // title screens may have different window size
1921 ChangeViewportPropertiesIfNeeded();
1923 // only required to update logic for redrawing global border
1927 DrawTitleScreenImage(tci->local_nr, tci->initial);
1929 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1931 sound = getTitleSound(tci);
1932 music = getTitleMusic(tci);
1934 if (sound != last_sound)
1935 PlayMenuSoundExt(sound);
1936 if (music != last_music)
1937 PlayMenuMusicExt(music);
1942 SetMouseCursor(CURSOR_NONE);
1946 ResetTitleAutoDelay(&title_delay, &fading);
1951 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1952 button = MB_MENU_CHOICE;
1954 if (button == MB_MENU_LEAVE)
1956 return_to_main_menu = TRUE;
1958 else if (button == MB_MENU_CHOICE || dx)
1960 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1962 SetGameStatus(GAME_MODE_INFO);
1964 info_mode = INFO_MODE_MAIN;
1972 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
1974 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
1976 tci = &title_controls[title_screen_nr];
1978 SetAnimStatus(getTitleAnimMode(tci));
1980 sound = getTitleSound(tci);
1981 music = getTitleMusic(tci);
1983 if (last_sound != SND_UNDEFINED && sound != last_sound)
1984 FadeSound(last_sound);
1985 if (last_music != MUS_UNDEFINED && music != last_music)
1988 fading = getTitleFading(tci);
1990 FadeOut(REDRAW_ALL);
1993 DrawTitleScreenImage(tci->local_nr, tci->initial);
1995 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1997 sound = getTitleSound(tci);
1998 music = getTitleMusic(tci);
2000 if (sound != last_sound)
2001 PlayMenuSoundExt(sound);
2002 if (music != last_music)
2003 PlayMenuMusicExt(music);
2010 ResetTitleAutoDelay(&title_delay, &fading);
2014 FadeMenuSoundsAndMusic();
2016 return_to_main_menu = TRUE;
2020 if (return_to_main_menu)
2022 SetMouseCursor(CURSOR_DEFAULT);
2024 // force full menu screen redraw after displaying title screens
2025 redraw_mask = REDRAW_ALL;
2027 if (game_status_last_screen == GAME_MODE_INFO)
2029 SetGameStatus(GAME_MODE_INFO);
2031 info_mode = INFO_MODE_MAIN;
2035 else // default: return to main menu
2037 SetGameStatus(GAME_MODE_MAIN);
2044 static void HandleMainMenu_ToggleTeamMode(void)
2046 setup.team_mode = !setup.team_mode;
2048 InitializeMainControls();
2049 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2051 DrawPreviewPlayers();
2054 static void HandleMainMenu_SelectLevel(int step, int direction,
2055 int selected_level_nr)
2057 int old_level_nr = level_nr;
2060 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2061 new_level_nr = selected_level_nr;
2063 new_level_nr = old_level_nr + step * direction;
2065 if (new_level_nr < leveldir_current->first_level)
2066 new_level_nr = leveldir_current->first_level;
2067 if (new_level_nr > leveldir_current->last_level)
2068 new_level_nr = leveldir_current->last_level;
2070 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2072 // skipping levels is only allowed when trying to skip single level
2073 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2074 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2076 leveldir_current->handicap_level++;
2077 SaveLevelSetup_SeriesInfo();
2080 new_level_nr = leveldir_current->handicap_level;
2083 if (new_level_nr != old_level_nr)
2085 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2087 PlaySound(SND_MENU_ITEM_SELECTING);
2089 level_nr = new_level_nr;
2091 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2092 int2str(level_nr, menu.main.text.level_number.size),
2093 mci->pos_text->font);
2095 LoadLevel(level_nr);
2096 DrawPreviewLevelInitial();
2100 DrawCompleteVideoDisplay();
2102 SaveLevelSetup_SeriesInfo();
2104 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2106 // force redraw of playfield area (may be reset at this point)
2107 redraw_mask |= REDRAW_FIELD;
2111 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2113 static int choice = MAIN_CONTROL_GAME;
2114 static boolean button_pressed_last = FALSE;
2115 boolean button_pressed = FALSE;
2117 int i = 0; // needed to prevent compiler warning due to bad code below
2119 if (button == MB_MENU_INITIALIZE)
2121 DrawCursorAndText_Main(choice, TRUE, FALSE);
2126 if (mx || my) // mouse input
2130 for (i = 0; main_controls[i].nr != -1; i++)
2132 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2133 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2134 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2136 pos = main_controls[i].nr;
2142 // check if level preview was clicked
2143 if (insidePreviewRect(&preview, mx - SX, my - SY))
2144 pos = MAIN_CONTROL_GAME;
2146 // handle pressed/unpressed state for active/inactive menu buttons
2147 // (if pos != -1, "i" contains index position corresponding to "pos")
2149 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2150 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2151 button_pressed = TRUE;
2153 if (button_pressed != button_pressed_last)
2155 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2158 PlaySound(SND_MENU_BUTTON_PRESSING);
2160 PlaySound(SND_MENU_BUTTON_RELEASING);
2163 else if (dx || dy) // keyboard input
2165 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2166 choice == MAIN_CONTROL_SETUP))
2167 button = MB_MENU_CHOICE;
2172 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2174 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2176 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2178 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2180 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2182 CloseDoor(DOOR_CLOSE_2);
2184 SetGameStatus(GAME_MODE_LEVELNR);
2186 DrawChooseLevelNr();
2188 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2194 PlaySound(SND_MENU_ITEM_ACTIVATING);
2196 DrawCursorAndText_Main(choice, FALSE, FALSE);
2197 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2203 if (choice == MAIN_CONTROL_NAME)
2205 // special case: cursor left or right pressed -- toggle team mode
2206 HandleMainMenu_ToggleTeamMode();
2208 else if (choice != MAIN_CONTROL_INFO &&
2209 choice != MAIN_CONTROL_SETUP)
2211 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2217 PlaySound(SND_MENU_ITEM_SELECTING);
2219 if (pos == MAIN_CONTROL_NAME)
2222 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2224 // special case: menu text "name/team" clicked -- toggle team mode
2225 HandleMainMenu_ToggleTeamMode();
2229 if (setup.multiple_users)
2231 CloseDoor(DOOR_CLOSE_2);
2233 SetGameStatus(GAME_MODE_NAMES);
2235 DrawChoosePlayerName();
2239 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2245 else if (pos == MAIN_CONTROL_LEVELS)
2249 CloseDoor(DOOR_CLOSE_2);
2251 SetGameStatus(GAME_MODE_LEVELS);
2253 SaveLevelSetup_LastSeries();
2254 SaveLevelSetup_SeriesInfo();
2256 // restore level set if chosen from "last played level set" menu
2257 RestoreLastPlayedLevels(&leveldir_current);
2259 if (setup.internal.choose_from_top_leveldir)
2262 DrawChooseLevelSet();
2265 else if (pos == MAIN_CONTROL_SCORES)
2267 CloseDoor(DOOR_CLOSE_2);
2269 SetGameStatus(GAME_MODE_SCORES);
2271 DrawHallOfFame(level_nr);
2273 else if (pos == MAIN_CONTROL_EDITOR)
2275 if (leveldir_current->readonly &&
2276 setup.editor.show_read_only_warning)
2277 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2279 CloseDoor(DOOR_CLOSE_ALL);
2281 SetGameStatus(GAME_MODE_EDITOR);
2283 FadeSetEnterScreen();
2287 else if (pos == MAIN_CONTROL_INFO)
2289 CloseDoor(DOOR_CLOSE_2);
2291 SetGameStatus(GAME_MODE_INFO);
2293 info_mode = INFO_MODE_MAIN;
2297 else if (pos == MAIN_CONTROL_GAME)
2299 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2301 else if (pos == MAIN_CONTROL_SETUP)
2303 CloseDoor(DOOR_CLOSE_2);
2305 SetGameStatus(GAME_MODE_SETUP);
2307 setup_mode = SETUP_MODE_MAIN;
2311 else if (pos == MAIN_CONTROL_QUIT)
2313 SaveLevelSetup_LastSeries();
2314 SaveLevelSetup_SeriesInfo();
2316 #if defined(PLATFORM_EMSCRIPTEN)
2317 Request("Close the browser window to quit!", REQ_CONFIRM);
2319 if (!setup.ask_on_quit_program ||
2320 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2321 SetGameStatus(GAME_MODE_QUIT);
2327 button_pressed_last = button_pressed;
2331 // ============================================================================
2332 // info screen functions
2333 // ============================================================================
2335 static struct TokenInfo *info_info;
2336 static int num_info_info; // number of info entries shown on screen
2337 static int max_info_info; // total number of info entries in list
2339 static void execInfoTitleScreen(void)
2341 info_mode = INFO_MODE_TITLE;
2346 static void execInfoElements(void)
2348 info_mode = INFO_MODE_ELEMENTS;
2353 static void execInfoMusic(void)
2355 info_mode = INFO_MODE_MUSIC;
2360 static void execInfoCredits(void)
2362 info_mode = INFO_MODE_CREDITS;
2367 static void execInfoProgram(void)
2369 info_mode = INFO_MODE_PROGRAM;
2374 static void execInfoVersion(void)
2376 info_mode = INFO_MODE_VERSION;
2381 static void execInfoLevelSet(void)
2383 info_mode = INFO_MODE_LEVELSET;
2388 static void execExitInfo(void)
2390 SetGameStatus(GAME_MODE_MAIN);
2395 static struct TokenInfo info_info_main[] =
2397 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2398 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2399 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2400 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2401 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2402 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2403 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2404 { TYPE_EMPTY, NULL, "" },
2405 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2410 static int getMenuTextFont(int type)
2412 if (type & (TYPE_SWITCH |
2426 static struct TokenInfo *setup_info;
2427 static struct TokenInfo setup_info_input[];
2429 static struct TokenInfo *menu_info;
2431 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2432 int screen_pos, int menu_info_pos_raw,
2435 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2436 struct TokenInfo *ti = &token_info[pos];
2437 int xpos = MENU_SCREEN_START_XPOS;
2438 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2439 int font_nr = getMenuTextFont(ti->type);
2441 if (setup_mode == SETUP_MODE_INPUT)
2442 font_nr = FONT_MENU_1;
2445 font_nr = FONT_ACTIVE(font_nr);
2447 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2449 if (ti->type & ~TYPE_SKIP_ENTRY)
2450 drawCursor(screen_pos, active);
2453 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2456 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2459 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2462 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2465 static char *window_size_text;
2466 static char *scaling_type_text;
2467 static char *network_server_text;
2469 static void drawSetupValue(int, int);
2471 static void drawMenuInfoList(int first_entry, int num_page_entries,
2472 int max_page_entries)
2476 if (first_entry + num_page_entries > max_page_entries)
2479 clearMenuListArea();
2481 for (i = 0; i < num_page_entries; i++)
2483 int menu_info_pos = first_entry + i;
2484 struct TokenInfo *si = &menu_info[menu_info_pos];
2485 void *value_ptr = si->value;
2487 // set some entries to "unchangeable" according to other variables
2488 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2489 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2490 (value_ptr == &setup.sound_music && !audio.music_available) ||
2491 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2492 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2493 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2494 si->type |= TYPE_GHOSTED;
2496 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2497 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2498 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2499 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2500 else if (si->type & ~TYPE_SKIP_ENTRY)
2501 initCursor(i, IMG_MENU_BUTTON);
2503 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2505 if (si->type & TYPE_STRING)
2509 if (value_ptr == &network_server_text)
2510 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2512 if (gadget_id != -1)
2514 struct GadgetInfo *gi = screen_gadget[gadget_id];
2515 int xpos = MENU_SCREEN_START_XPOS;
2516 int ypos = MENU_SCREEN_START_YPOS + i;
2517 int x = mSX + xpos * 32;
2518 int y = mSY + ypos * 32;
2520 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2524 if (si->type & TYPE_VALUE &&
2525 menu_info == setup_info)
2526 drawSetupValue(i, menu_info_pos);
2530 static void DrawInfoScreen_Main(void)
2532 int fade_mask = REDRAW_FIELD;
2535 if (redraw_mask & REDRAW_ALL)
2536 fade_mask = REDRAW_ALL;
2539 fade_mask = REDRAW_ALL;
2542 FadeMenuSoundsAndMusic();
2544 FreeScreenGadgets();
2545 CreateScreenGadgets();
2547 // (needed after displaying title screens which disable auto repeat)
2548 KeyboardAutoRepeatOn();
2550 FadeSetLeaveScreen();
2554 // needed if different viewport properties defined for info screen
2555 ChangeViewportPropertiesIfNeeded();
2557 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2561 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2563 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2565 info_info = info_info_main;
2567 // use modified info screen info without info screen entries marked as hidden
2568 info_info = getSetupInfoFinal(info_info);
2570 // determine maximal number of info entries that can be displayed on screen
2572 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2575 // determine maximal number of info entries available for menu of info screen
2577 for (i = 0; info_info[i].type != 0; i++)
2580 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2582 MapScreenGadgets(max_info_info);
2584 PlayMenuSoundsAndMusic();
2586 DrawMaskedBorder(fade_mask);
2591 static void changeSetupValue(int, int, int);
2593 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2594 int mode, int num_page_entries,
2595 int max_page_entries)
2597 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2598 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2599 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2600 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2601 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2602 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2603 int *num_page_entries_last = num_page_entries_all_last[game_status];
2604 int *choice_store = choice_stores[game_status];
2605 int *first_entry_store = first_entry_stores[game_status];
2606 int choice = choice_store[mode]; // starts with 0
2607 int first_entry = first_entry_store[mode]; // starts with 0
2609 int y = choice - first_entry;
2611 boolean position_set_by_scrollbar = (dx == 999);
2612 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2615 if (button == MB_MENU_INITIALIZE)
2617 // check if number of menu page entries has changed (may happen by change
2618 // of custom artwork definition value for 'list_size' for this menu screen)
2619 // (in this case, the last menu position most probably has to be corrected)
2620 if (num_page_entries != num_page_entries_last[mode])
2622 choice_store[mode] = first_entry_store[mode] = 0;
2624 choice = first_entry = 0;
2627 num_page_entries_last[mode] = num_page_entries;
2630 // advance to first valid menu entry
2631 while (choice < num_page_entries &&
2632 menu_info[choice].type & TYPE_SKIP_ENTRY)
2635 if (position_set_by_scrollbar)
2636 first_entry = first_entry_store[mode] = dy;
2638 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2639 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2641 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2643 if (choice < first_entry)
2645 choice = first_entry;
2647 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2650 else if (choice > first_entry + num_page_entries - 1)
2652 choice = first_entry + num_page_entries - 1;
2654 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2658 choice_store[mode] = choice;
2660 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2664 else if (button == MB_MENU_LEAVE)
2666 PlaySound(SND_MENU_ITEM_SELECTING);
2668 for (i = 0; i < max_page_entries; i++)
2670 if (menu_info[i].type & TYPE_LEAVE_MENU)
2672 void (*menu_callback_function)(void) = menu_info[i].value;
2676 menu_callback_function();
2678 break; // absolutely needed because function changes 'menu_info'!
2685 if (mx || my) // mouse input
2687 x = (mx - mSX) / 32;
2688 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2690 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2692 // move cursor instead of scrolling when already at start/end of list
2693 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2695 else if (dy == +1 * SCROLL_LINE &&
2696 first_entry + num_page_entries == max_page_entries)
2699 // handle scrolling screen one line or page
2701 y + dy > num_page_entries - 1)
2703 boolean redraw = FALSE;
2705 if (ABS(dy) == SCROLL_PAGE)
2706 step = num_page_entries - 1;
2708 if (dy < 0 && first_entry > 0)
2710 // scroll page/line up
2712 first_entry -= step;
2713 if (first_entry < 0)
2718 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2720 // scroll page/line down
2722 first_entry += step;
2723 if (first_entry + num_page_entries > max_page_entries)
2724 first_entry = MAX(0, max_page_entries - num_page_entries);
2731 choice += first_entry - first_entry_store[mode];
2733 if (choice < first_entry)
2735 choice = first_entry;
2737 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2740 else if (choice > first_entry + num_page_entries - 1)
2742 choice = first_entry + num_page_entries - 1;
2744 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2747 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2751 if (choice < first_entry ||
2752 choice > first_entry + num_page_entries - 1)
2753 first_entry += SIGN(dy);
2756 first_entry_store[mode] = first_entry;
2757 choice_store[mode] = choice;
2759 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2761 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2763 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2764 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2772 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2774 if (menu_info[choice].type & menu_navigation_type ||
2775 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2776 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2777 menu_info[choice].type & TYPE_PLAYER)
2778 button = MB_MENU_CHOICE;
2783 // jump to next non-empty menu entry (up or down)
2784 while (first_entry + y > 0 &&
2785 first_entry + y < max_page_entries - 1 &&
2786 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2789 if (!IN_VIS_MENU(x, y))
2791 choice += y - y_old;
2793 if (choice < first_entry)
2794 first_entry = choice;
2795 else if (choice > first_entry + num_page_entries - 1)
2796 first_entry = choice - num_page_entries + 1;
2798 if (first_entry >= 0 &&
2799 first_entry + num_page_entries <= max_page_entries)
2801 first_entry_store[mode] = first_entry;
2803 if (choice < first_entry)
2804 choice = first_entry;
2805 else if (choice > first_entry + num_page_entries - 1)
2806 choice = first_entry + num_page_entries - 1;
2808 choice_store[mode] = choice;
2810 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2812 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2814 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2815 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2822 if (!anyScrollbarGadgetActive() &&
2823 IN_VIS_MENU(x, y) &&
2824 mx < mx_right_border &&
2825 y >= 0 && y < num_page_entries)
2829 if (first_entry + y != choice &&
2830 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2832 PlaySound(SND_MENU_ITEM_ACTIVATING);
2834 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2835 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2837 choice = choice_store[mode] = first_entry + y;
2841 PlaySound(SND_MENU_ITEM_SELECTING);
2843 for (i = 0; menu_info[i].type != 0; i++)
2845 if (menu_info[i].type & TYPE_LEAVE_MENU)
2847 void (*menu_callback_function)(void) = menu_info[i].value;
2851 menu_callback_function();
2853 // absolutely needed because function changes 'menu_info'!
2861 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2863 PlaySound(SND_MENU_ITEM_SELECTING);
2865 // when selecting key headline, execute function for key value change
2866 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2867 menu_info[first_entry + y + 1].type & TYPE_KEY)
2870 // when selecting string value, execute function for list selection
2871 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2872 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2875 // when selecting string value, execute function for text input gadget
2876 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2877 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2880 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2882 void (*menu_callback_function)(void) =
2883 menu_info[first_entry + y].value;
2885 FadeSetFromType(menu_info[first_entry + y].type);
2887 menu_callback_function();
2889 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2891 void (*gadget_callback_function)(void) =
2892 menu_info[first_entry + y].value;
2894 gadget_callback_function();
2896 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2897 menu_info == setup_info)
2899 changeSetupValue(y, first_entry + y, dx);
2905 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2907 menu_info = info_info;
2909 HandleMenuScreen(mx, my, dx, dy, button,
2910 info_mode, num_info_info, max_info_info);
2913 static int getMenuFontSpacing(int spacing_height, int font_nr)
2915 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2917 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2921 static int getMenuTextSpacing(int spacing_height, int font_nr)
2923 return (getMenuFontSpacing(spacing_height, font_nr) +
2924 EXTRA_SPACING(game_status));
2927 static int getMenuTextStep(int spacing_height, int font_nr)
2929 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2932 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2934 int font_title = MENU_INFO_FONT_TITLE;
2935 int font_error = FONT_TEXT_2;
2936 int font_foot = MENU_INFO_FONT_FOOT;
2937 int spacing_title = menu.headline1_spacing_info[info_mode];
2938 int ystep_title = getMenuTextStep(spacing_title, font_title);
2939 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2940 int ystart2 = ystart1 + ystep_title;
2941 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2943 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2945 FadeOut(REDRAW_FIELD);
2950 DrawTextSCentered(ystart1, font_title, text_title);
2951 DrawTextSCentered(ystart2, font_error, text_error);
2953 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
2955 FadeIn(REDRAW_FIELD);
2958 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2960 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2961 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2962 int font_title = MENU_INFO_FONT_TITLE;
2963 int font_foot = MENU_INFO_FONT_FOOT;
2964 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2965 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2966 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2967 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2968 int ystep = MENU_SCREEN_INFO_YSTEP;
2969 int element, action, direction;
2977 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2978 infoscreen_step[i] = infoscreen_frame[i] = 0;
2983 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2984 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
2990 while (helpanim_info[j].element != HELPANIM_LIST_END)
2992 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2997 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3006 j += infoscreen_step[i - start];
3008 element = helpanim_info[j].element;
3009 action = helpanim_info[j].action;
3010 direction = helpanim_info[j].direction;
3013 element = EL_UNKNOWN;
3015 if (action != -1 && direction != -1)
3016 graphic = el_act_dir2img(element, action, direction);
3017 else if (action != -1)
3018 graphic = el_act2img(element, action);
3019 else if (direction != -1)
3020 graphic = el_dir2img(element, direction);
3022 graphic = el2img(element);
3024 delay = helpanim_info[j++].delay;
3029 if (infoscreen_frame[i - start] == 0)
3032 infoscreen_frame[i - start] = delay - 1;
3036 sync_frame = delay - infoscreen_frame[i - start];
3037 infoscreen_frame[i - start]--;
3040 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3042 if (!infoscreen_frame[i - start])
3043 infoscreen_step[i - start] = 0;
3047 if (!infoscreen_frame[i - start])
3048 infoscreen_step[i - start]++;
3049 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3055 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3057 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3058 graphic, sync_frame, USE_MASKING);
3061 DrawInfoScreen_HelpText(element, action, direction, i - start);
3066 redraw_mask |= REDRAW_FIELD;
3071 static char *getHelpText(int element, int action, int direction)
3073 char token[MAX_LINE_LEN];
3075 strcpy(token, element_info[element].token_name);
3078 strcat(token, element_action_info[action].suffix);
3080 if (direction != -1)
3081 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3083 return getHashEntry(helptext_info, token);
3086 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3088 int font_nr = FONT_INFO_ELEMENTS;
3089 int font_width = getFontWidth(font_nr);
3090 int font_height = getFontHeight(font_nr);
3091 int yoffset = (TILEX - 2 * font_height) / 2;
3092 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3093 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3094 int ystep = TILEY + 4;
3095 int pad_left = xstart - SX;
3096 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3097 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3098 int max_lines_per_text = 2;
3101 if (action != -1 && direction != -1) // element.action.direction
3102 text = getHelpText(element, action, direction);
3104 if (text == NULL && action != -1) // element.action
3105 text = getHelpText(element, action, -1);
3107 if (text == NULL && direction != -1) // element.direction
3108 text = getHelpText(element, -1, direction);
3110 if (text == NULL) // base element
3111 text = getHelpText(element, -1, -1);
3113 if (text == NULL) // not found
3114 text = "No description available";
3116 if (strlen(text) <= max_chars_per_line) // only one line of text
3117 ystart += getFontHeight(font_nr) / 2;
3119 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3120 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3121 TRUE, FALSE, FALSE);
3124 static void DrawInfoScreen_TitleScreen(void)
3126 SetGameStatus(GAME_MODE_TITLE);
3131 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3133 HandleTitleScreen(0, 0, dx, dy, button);
3136 static void DrawInfoScreen_Elements(void)
3138 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3140 FadeOut(REDRAW_FIELD);
3145 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3147 FadeIn(REDRAW_FIELD);
3150 void HandleInfoScreen_Elements(int dx, int dy, int button)
3152 static unsigned int info_delay = 0;
3153 static int num_anims;
3154 static int num_pages;
3156 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3159 if (button == MB_MENU_INITIALIZE)
3161 boolean new_element = TRUE;
3165 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3167 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3169 else if (new_element)
3172 new_element = FALSE;
3176 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3180 if (button == MB_MENU_LEAVE)
3182 PlaySound(SND_MENU_ITEM_SELECTING);
3184 info_mode = INFO_MODE_MAIN;
3189 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3191 if (button != MB_MENU_INITIALIZE)
3193 PlaySound(SND_MENU_ITEM_SELECTING);
3195 page += (dx < 0 ? -1 : +1);
3198 if (page < 0 || page >= num_pages)
3200 FadeMenuSoundsAndMusic();
3202 info_mode = INFO_MODE_MAIN;
3208 if (button != MB_MENU_INITIALIZE)
3209 FadeSetNextScreen();
3211 if (button != MB_MENU_INITIALIZE)
3212 FadeOut(REDRAW_FIELD);
3214 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3216 if (button != MB_MENU_INITIALIZE)
3217 FadeIn(REDRAW_FIELD);
3221 if (DelayReached(&info_delay, GameFrameDelay))
3222 if (page < num_pages)
3223 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3225 PlayMenuSoundIfLoop();
3229 static void DrawInfoScreen_Music(void)
3231 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3233 FadeOut(REDRAW_FIELD);
3240 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3242 FadeIn(REDRAW_FIELD);
3245 void HandleInfoScreen_Music(int dx, int dy, int button)
3247 static struct MusicFileInfo *list = NULL;
3248 int font_title = MENU_INFO_FONT_TITLE;
3249 int font_head = MENU_INFO_FONT_HEAD;
3250 int font_text = MENU_INFO_FONT_TEXT;
3251 int font_foot = MENU_INFO_FONT_FOOT;
3252 int spacing_title = menu.headline1_spacing_info[info_mode];
3253 int spacing_head = menu.headline2_spacing_info[info_mode];
3254 int ystep_title = getMenuTextStep(spacing_title, font_title);
3255 int ystep_head = getMenuTextStep(spacing_head, font_head);
3256 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3257 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3259 if (button == MB_MENU_INITIALIZE)
3261 list = music_file_info;
3265 FadeMenuSoundsAndMusic();
3270 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3271 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3277 if (button == MB_MENU_LEAVE)
3279 PlaySound(SND_MENU_ITEM_SELECTING);
3281 FadeMenuSoundsAndMusic();
3283 info_mode = INFO_MODE_MAIN;
3288 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3290 if (button != MB_MENU_INITIALIZE)
3292 PlaySound(SND_MENU_ITEM_SELECTING);
3295 list = (dx < 0 ? list->prev : list->next);
3300 FadeMenuSoundsAndMusic();
3302 info_mode = INFO_MODE_MAIN;
3308 FadeMenuSoundsAndMusic();
3310 if (list != music_file_info)
3311 FadeSetNextScreen();
3313 if (button != MB_MENU_INITIALIZE)
3314 FadeOut(REDRAW_FIELD);
3321 int sound = list->music;
3323 if (IS_LOOP_SOUND(sound))
3324 PlaySoundLoop(sound);
3328 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3332 int music = list->music;
3334 if (IS_LOOP_MUSIC(music))
3335 PlayMusicLoop(music);
3339 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3342 ystart += ystep_title;
3344 if (!strEqual(list->title, UNKNOWN_NAME))
3346 if (!strEqual(list->title_header, UNKNOWN_NAME))
3348 DrawTextSCentered(ystart, font_head, list->title_header);
3349 ystart += ystep_head;
3352 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3353 ystart += ystep_head;
3356 if (!strEqual(list->artist, UNKNOWN_NAME))
3358 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3359 DrawTextSCentered(ystart, font_head, list->artist_header);
3361 DrawTextSCentered(ystart, font_head, "by");
3363 ystart += ystep_head;
3365 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3366 ystart += ystep_head;
3369 if (!strEqual(list->album, UNKNOWN_NAME))
3371 if (!strEqual(list->album_header, UNKNOWN_NAME))
3372 DrawTextSCentered(ystart, font_head, list->album_header);
3374 DrawTextSCentered(ystart, font_head, "from the album");
3376 ystart += ystep_head;
3378 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3379 ystart += ystep_head;
3382 if (!strEqual(list->year, UNKNOWN_NAME))
3384 if (!strEqual(list->year_header, UNKNOWN_NAME))
3385 DrawTextSCentered(ystart, font_head, list->year_header);
3387 DrawTextSCentered(ystart, font_head, "from the year");
3389 ystart += ystep_head;
3391 DrawTextFCentered(ystart, font_text, "%s", list->year);
3392 ystart += ystep_head;
3395 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3397 if (button != MB_MENU_INITIALIZE)
3398 FadeIn(REDRAW_FIELD);
3401 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3402 PlaySoundLoop(list->music);
3405 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3407 int font_title = MENU_INFO_FONT_TITLE;
3408 int font_text = MENU_INFO_FONT_TEXT;
3409 int font_foot = MENU_INFO_FONT_FOOT;
3410 int spacing_title = menu.headline1_spacing_info[info_mode];
3411 int spacing_line = menu.line_spacing_info[info_mode];
3412 int ystep_title = getMenuTextStep(spacing_title, font_title);
3413 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3414 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3419 DrawTextSCentered(ystart, font_title, "Credits:");
3421 char *filename = getCreditsFilename(screen_nr, use_global_credits_screens);
3423 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3424 int chars = width / getFontWidth(font_text);
3425 int lines = height / getFontHeight(font_text);
3426 int padx = (width - chars * getFontWidth(font_text)) / 2;
3427 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3428 boolean autowrap = FALSE;
3429 boolean centered = TRUE;
3430 boolean parse_comments = TRUE;
3432 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3433 filename, font_text, chars, -1, lines, line_spacing, -1,
3434 autowrap, centered, parse_comments);
3436 boolean last_screen = (screen_nr == num_credits_screens - 1);
3437 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3439 DrawTextSCentered(ybottom, font_foot, text_foot);
3442 static void DrawInfoScreen_Credits(void)
3444 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3446 FadeMenuSoundsAndMusic();
3448 FadeOut(REDRAW_FIELD);
3450 HandleInfoScreen_Credits(0, 0, MB_MENU_INITIALIZE);
3452 FadeIn(REDRAW_FIELD);
3455 void HandleInfoScreen_Credits(int dx, int dy, int button)
3457 static int screen_nr = 0;
3459 if (button == MB_MENU_INITIALIZE)
3463 // determine number of (global or level set specific) credits screens
3464 for (i = 0; i < 2; i++)
3466 num_credits_screens = 0;
3467 use_global_credits_screens = i;
3469 while (getCreditsFilename(num_credits_screens,
3470 use_global_credits_screens) != NULL)
3471 num_credits_screens++;
3473 if (num_credits_screens > 0)
3477 if (num_credits_screens == 0)
3479 int font_title = MENU_INFO_FONT_TITLE;
3480 int font_foot = MENU_INFO_FONT_FOOT;
3481 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3482 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3487 DrawTextSCentered(ystart, font_title, "No credits for this level set.");
3488 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3495 DrawInfoScreen_CreditsScreen(screen_nr);
3497 else if (button == MB_MENU_LEAVE)
3499 PlaySound(SND_MENU_ITEM_SELECTING);
3501 info_mode = INFO_MODE_MAIN;
3506 else if (button == MB_MENU_CHOICE || dx)
3508 PlaySound(SND_MENU_ITEM_SELECTING);
3510 screen_nr += (dx < 0 ? -1 : +1);
3512 if (screen_nr < 0 || screen_nr >= num_credits_screens)
3514 FadeMenuSoundsAndMusic();
3516 info_mode = INFO_MODE_MAIN;
3522 FadeSetNextScreen();
3524 FadeOut(REDRAW_FIELD);
3526 DrawInfoScreen_CreditsScreen(screen_nr);
3528 FadeIn(REDRAW_FIELD);
3532 PlayMenuSoundIfLoop();
3536 static void DrawInfoScreen_ProgramScreen(int screen_nr)
3538 int font_title = MENU_INFO_FONT_TITLE;
3539 int font_text = MENU_INFO_FONT_TEXT;
3540 int font_foot = MENU_INFO_FONT_FOOT;
3541 int spacing_title = menu.headline1_spacing_info[info_mode];
3542 int spacing_line = menu.line_spacing_info[info_mode];
3543 int ystep_title = getMenuTextStep(spacing_title, font_title);
3544 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3545 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3550 DrawTextSCentered(ystart, font_title, "Program Information:");
3552 char *filename = getProgramInfoFilename(screen_nr);
3554 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3555 int chars = width / getFontWidth(font_text);
3556 int lines = height / getFontHeight(font_text);
3557 int padx = (width - chars * getFontWidth(font_text)) / 2;
3558 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3559 boolean autowrap = FALSE;
3560 boolean centered = TRUE;
3561 boolean parse_comments = TRUE;
3563 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3564 filename, font_text, chars, -1, lines, line_spacing, -1,
3565 autowrap, centered, parse_comments);
3567 boolean last_screen = (screen_nr == num_program_info_screens - 1);
3568 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3570 DrawTextSCentered(ybottom, font_foot, text_foot);
3573 static void DrawInfoScreen_Program(void)
3575 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3577 FadeMenuSoundsAndMusic();
3579 FadeOut(REDRAW_FIELD);
3581 HandleInfoScreen_Program(0, 0, MB_MENU_INITIALIZE);
3583 FadeIn(REDRAW_FIELD);
3586 void HandleInfoScreen_Program(int dx, int dy, int button)
3588 static int screen_nr = 0;
3590 if (button == MB_MENU_INITIALIZE)
3592 // determine number of program info screens
3593 num_program_info_screens = 0;
3595 while (getProgramInfoFilename(num_program_info_screens) != NULL)
3596 num_program_info_screens++;
3598 if (num_program_info_screens == 0)
3600 int font_title = MENU_INFO_FONT_TITLE;
3601 int font_foot = MENU_INFO_FONT_FOOT;
3602 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3603 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3608 DrawTextSCentered(ystart, font_title, "No program info available.");
3609 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3616 DrawInfoScreen_ProgramScreen(screen_nr);
3618 else if (button == MB_MENU_LEAVE)
3620 PlaySound(SND_MENU_ITEM_SELECTING);
3622 info_mode = INFO_MODE_MAIN;
3627 else if (button == MB_MENU_CHOICE || dx)
3629 PlaySound(SND_MENU_ITEM_SELECTING);
3631 screen_nr += (dx < 0 ? -1 : +1);
3633 if (screen_nr < 0 || screen_nr >= num_program_info_screens)
3635 FadeMenuSoundsAndMusic();
3637 info_mode = INFO_MODE_MAIN;
3643 FadeSetNextScreen();
3645 FadeOut(REDRAW_FIELD);
3647 DrawInfoScreen_ProgramScreen(screen_nr);
3649 FadeIn(REDRAW_FIELD);
3653 PlayMenuSoundIfLoop();
3657 static void DrawInfoScreen_Version(void)
3659 int font_title = MENU_INFO_FONT_TITLE;
3660 int font_head = MENU_INFO_FONT_HEAD;
3661 int font_text = MENU_INFO_FONT_TEXT;
3662 int font_foot = MENU_INFO_FONT_FOOT;
3663 int spacing_title = menu.headline1_spacing_info[info_mode];
3664 int spacing_head = menu.headline2_spacing_info[info_mode];
3665 int spacing_para = menu.paragraph_spacing_info[info_mode];
3666 int spacing_line = menu.line_spacing_info[info_mode];
3667 int xstep = getFontWidth(font_text);
3668 int ystep_title = getMenuTextStep(spacing_title, font_title);
3669 int ystep_head = getMenuTextStep(spacing_head, font_head);
3670 int ystep_para = getMenuTextStep(spacing_para, font_text);
3671 int ystep_line = getMenuTextStep(spacing_line, font_text);
3672 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3673 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3674 int xstart1 = mSX - SX + 2 * xstep;
3675 int xstart2 = mSX - SX + 18 * xstep;
3676 int xstart3 = mSX - SX + 28 * xstep;
3677 SDL_version sdl_version_compiled;
3678 const SDL_version *sdl_version_linked;
3679 int driver_name_len = 10;
3680 SDL_version sdl_version_linked_ext;
3681 const char *driver_name = NULL;
3683 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3685 FadeOut(REDRAW_FIELD);
3690 DrawTextSCentered(ystart, font_title, "Version Information:");
3691 ystart += ystep_title;
3693 DrawTextF(xstart1, ystart, font_head, "Name");
3694 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3695 ystart += ystep_line;
3697 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3699 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3700 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3701 ystart += ystep_line;
3703 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3704 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3705 ystart += ystep_line;
3709 DrawTextF(xstart1, ystart, font_head, "Version");
3710 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3711 ystart += ystep_line;
3714 DrawTextF(xstart1, ystart, font_head, "Platform");
3715 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3717 PLATFORM_XX_BIT_STRING);
3718 ystart += ystep_line;
3720 DrawTextF(xstart1, ystart, font_head, "Target");
3721 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3722 ystart += ystep_line;
3724 DrawTextF(xstart1, ystart, font_head, "Source date");
3725 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3726 ystart += ystep_line;
3728 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3729 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3730 ystart += ystep_para;
3732 DrawTextF(xstart1, ystart, font_head, "Library");
3733 DrawTextF(xstart2, ystart, font_head, "compiled");
3734 DrawTextF(xstart3, ystart, font_head, "linked");
3735 ystart += ystep_head;
3737 SDL_VERSION(&sdl_version_compiled);
3738 SDL_GetVersion(&sdl_version_linked_ext);
3739 sdl_version_linked = &sdl_version_linked_ext;
3741 DrawTextF(xstart1, ystart, font_text, "SDL");
3742 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3743 sdl_version_compiled.major,
3744 sdl_version_compiled.minor,
3745 sdl_version_compiled.patch);
3746 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3747 sdl_version_linked->major,
3748 sdl_version_linked->minor,
3749 sdl_version_linked->patch);
3750 ystart += ystep_line;
3752 SDL_IMAGE_VERSION(&sdl_version_compiled);
3753 sdl_version_linked = IMG_Linked_Version();
3755 DrawTextF(xstart1, ystart, font_text, "SDL_image");
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_MIXER_VERSION(&sdl_version_compiled);
3767 sdl_version_linked = Mix_Linked_Version();
3769 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
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_NET_VERSION(&sdl_version_compiled);
3781 sdl_version_linked = SDLNet_Linked_Version();
3783 DrawTextF(xstart1, ystart, font_text, "SDL_net");
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_para;
3794 DrawTextF(xstart1, ystart, font_head, "Driver");
3795 DrawTextF(xstart2, ystart, font_head, "Requested");
3796 DrawTextF(xstart3, ystart, font_head, "Used");
3797 ystart += ystep_head;
3800 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3802 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3803 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3804 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3805 ystart += ystep_line;
3808 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3810 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3811 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3812 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3813 ystart += ystep_line;
3816 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3818 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3819 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3820 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3822 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3824 FadeIn(REDRAW_FIELD);
3827 void HandleInfoScreen_Version(int button)
3829 if (button == MB_MENU_LEAVE)
3831 PlaySound(SND_MENU_ITEM_SELECTING);
3833 info_mode = INFO_MODE_MAIN;
3838 else if (button == MB_MENU_CHOICE)
3840 PlaySound(SND_MENU_ITEM_SELECTING);
3842 FadeMenuSoundsAndMusic();
3844 info_mode = INFO_MODE_MAIN;
3849 PlayMenuSoundIfLoop();
3853 static void DrawInfoScreen_LevelSet(void)
3855 struct TitleMessageInfo *tmi = &readme;
3856 char *filename = getLevelSetInfoFilename();
3857 char *title = "Level Set Information:";
3858 int font_foot = MENU_INFO_FONT_FOOT;
3859 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3860 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3862 if (filename == NULL)
3864 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3869 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3871 FadeOut(REDRAW_FIELD);
3876 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3878 // if x position set to "-1", automatically determine by playfield width
3880 tmi->x = SXSIZE / 2;
3882 // if y position set to "-1", use static default value
3886 // if width set to "-1", automatically determine by playfield width
3887 if (tmi->width == -1)
3888 tmi->width = SXSIZE - 2 * TILEX;
3890 // if height set to "-1", automatically determine by playfield height
3891 if (tmi->height == -1)
3892 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3894 // if chars set to "-1", automatically determine by text and font width
3895 if (tmi->chars == -1)
3896 tmi->chars = tmi->width / getFontWidth(tmi->font);
3898 tmi->width = tmi->chars * getFontWidth(tmi->font);
3900 // if lines set to "-1", automatically determine by text and font height
3901 if (tmi->lines == -1)
3902 tmi->lines = tmi->height / getFontHeight(tmi->font);
3904 tmi->height = tmi->lines * getFontHeight(tmi->font);
3906 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3907 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3908 tmi->autowrap, tmi->centered, tmi->parse_comments);
3910 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3912 FadeIn(REDRAW_FIELD);
3915 static void HandleInfoScreen_LevelSet(int button)
3917 if (button == MB_MENU_LEAVE)
3919 PlaySound(SND_MENU_ITEM_SELECTING);
3921 info_mode = INFO_MODE_MAIN;
3926 else if (button == MB_MENU_CHOICE)
3928 PlaySound(SND_MENU_ITEM_SELECTING);
3930 FadeMenuSoundsAndMusic();
3932 info_mode = INFO_MODE_MAIN;
3937 PlayMenuSoundIfLoop();
3941 static void DrawInfoScreen(void)
3943 if (info_mode == INFO_MODE_TITLE)
3944 DrawInfoScreen_TitleScreen();
3945 else if (info_mode == INFO_MODE_ELEMENTS)
3946 DrawInfoScreen_Elements();
3947 else if (info_mode == INFO_MODE_MUSIC)
3948 DrawInfoScreen_Music();
3949 else if (info_mode == INFO_MODE_CREDITS)
3950 DrawInfoScreen_Credits();
3951 else if (info_mode == INFO_MODE_PROGRAM)
3952 DrawInfoScreen_Program();
3953 else if (info_mode == INFO_MODE_VERSION)
3954 DrawInfoScreen_Version();
3955 else if (info_mode == INFO_MODE_LEVELSET)
3956 DrawInfoScreen_LevelSet();
3958 DrawInfoScreen_Main();
3960 if (info_mode != INFO_MODE_MAIN &&
3961 info_mode != INFO_MODE_TITLE &&
3962 info_mode != INFO_MODE_MUSIC)
3963 PlayMenuSoundsAndMusic();
3966 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3968 if (info_mode == INFO_MODE_TITLE)
3969 HandleInfoScreen_TitleScreen(dx, dy, button);
3970 else if (info_mode == INFO_MODE_ELEMENTS)
3971 HandleInfoScreen_Elements(dx, dy, button);
3972 else if (info_mode == INFO_MODE_MUSIC)
3973 HandleInfoScreen_Music(dx, dy, button);
3974 else if (info_mode == INFO_MODE_CREDITS)
3975 HandleInfoScreen_Credits(dx, dy, button);
3976 else if (info_mode == INFO_MODE_PROGRAM)
3977 HandleInfoScreen_Program(dx, dy, button);
3978 else if (info_mode == INFO_MODE_VERSION)
3979 HandleInfoScreen_Version(button);
3980 else if (info_mode == INFO_MODE_LEVELSET)
3981 HandleInfoScreen_LevelSet(button);
3983 HandleInfoScreen_Main(mx, my, dx, dy, button);
3987 // ============================================================================
3988 // type name functions
3989 // ============================================================================
3991 static TreeInfo *type_name_node = NULL;
3992 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
3993 static int type_name_nr = 0;
3995 static int getPlayerNameColor(char *name)
3997 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4000 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4003 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4004 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4005 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4006 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4007 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4008 int font_width = getFontWidth(font_nr);
4010 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4012 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4014 pos->width = strlen(text) * font_width;
4015 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4017 DrawText(sx, sy, text, font_nr);
4020 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4022 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4024 *pos = *mci->pos_input;
4026 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4028 TreeInfo *ti = player_name_current;
4029 int first_entry = ti->cl_first;
4030 int entry_pos = first_entry + ti->cl_cursor;
4031 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4032 int xpos = MENU_SCREEN_START_XPOS;
4033 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4035 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4036 type_name_nr = entry_pos;
4038 strcpy(name, type_name_node->name);
4042 pos->width = MAX_PLAYER_NAME_LEN * 32;
4046 type_name_nr = user.nr;
4048 strcpy(name, setup.player_name);
4051 strcpy(type_name_last, name);
4053 if (strEqual(name, EMPTY_PLAYER_NAME))
4056 *xpos = strlen(name);
4059 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4061 // change name of edited user in global list of user names
4062 setString(&global.user_names[type_name_nr], name);
4064 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4066 TreeInfo *node = type_name_node;
4068 // change name of edited user in local menu tree structure
4069 setString(&node->name, name);
4070 setString(&node->name_sorting, name);
4072 node->color = getPlayerNameColor(name);
4073 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4077 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4080 boolean reset_setup = strEqual(name, "");
4081 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4082 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4085 strcpy(name, type_name_last);
4087 if (strEqual(name, ""))
4088 strcpy(name, EMPTY_PLAYER_NAME);
4090 setTypeNameValues_Name(name, pos);
4092 // if player name not changed, no further action required
4093 if (strEqual(name, type_name_last))
4096 // redraw player name before (possibly) opening request dialogs
4097 drawTypeNameText(name, pos, FALSE);
4099 int last_user_nr = user.nr;
4101 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4103 // save setup of currently active user (may differ from edited user)
4106 // temporarily change active user to edited user
4107 user.nr = type_name_nr;
4110 Request("Use current setup values for the new player?", REQ_ASK))
4112 // use current setup values for new user, but create new player UUID
4113 setup.player_uuid = getStringCopy(getUUID());
4117 // load setup for existing user (or start with defaults for new user)
4122 char *setup_filename = getSetupFilename();
4123 boolean setup_exists = fileExists(setup_filename);
4125 // change name of edited user in setup structure
4126 strcpy(setup.player_name, name);
4128 // save setup of edited user
4131 // change name of edited user on score server
4132 ApiRenamePlayerAsThread();
4134 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4138 if (Request("Reset setup values for this player?", REQ_ASK))
4140 // remove setup config file
4141 unlink(setup_filename);
4143 // set player name to default player name
4146 // update player name used by name typing functions
4147 strcpy(name, setup.player_name);
4149 setTypeNameValues_Name(name, pos);
4152 else if (remove_user && type_name_nr != 0)
4154 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4156 char *user_dir = getUserGameDataDir();
4157 char *user_dir_removed =
4158 getStringCat3WithSeparator(user_dir, "REMOVED",
4159 getCurrentTimestamp(), ".");
4161 if (rename(user_dir, user_dir_removed) != 0)
4162 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4164 checked_free(user_dir_removed);
4167 else if (create_user && type_name_nr != 0 && !setup_exists)
4169 if (Request("Create empty level set for the new player?", REQ_ASK))
4171 char *levelset_subdir = getNewUserLevelSubdir();
4173 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4175 AddUserLevelSetToLevelInfo(levelset_subdir);
4177 LevelDirTree *leveldir_current_last = leveldir_current;
4179 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4182 // set level number of newly created level set to default value
4183 LoadLevelSetup_SeriesInfo();
4185 // set newly created level set as current level set for new user
4186 SaveLevelSetup_LastSeries();
4187 SaveLevelSetup_SeriesInfo();
4189 leveldir_current = leveldir_current_last;
4193 Request("Creating new level set failed!", REQ_CONFIRM);
4198 // restore currently active user
4199 user.nr = last_user_nr;
4201 // restore setup of currently active user
4204 // restore last level set of currently active user
4205 LoadLevelSetup_LastSeries();
4206 LoadLevelSetup_SeriesInfo();
4210 static void HandleTypeNameExt(boolean initialize, Key key)
4212 static struct TextPosInfo pos_name = { 0 };
4213 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4214 static int xpos = 0;
4215 struct TextPosInfo *pos = &pos_name;
4216 char key_char = getValidConfigValueChar(getCharFromKey(key));
4217 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4218 boolean active = TRUE;
4222 getTypeNameValues(name, pos, &xpos);
4224 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4225 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4227 StartTextInput(sx, sy, pos->width, pos->height);
4229 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4231 name[xpos] = key_char;
4236 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4242 else if (key == KSYM_Return || key == KSYM_Escape)
4244 boolean changed = (key == KSYM_Return);
4248 setTypeNameValues(name, pos, changed);
4253 drawTypeNameText(name, pos, active);
4257 SetGameStatus(game_status_last_screen);
4259 if (game_status == GAME_MODE_MAIN)
4260 InitializeMainControls();
4264 static void DrawTypeName(void)
4266 HandleTypeNameExt(TRUE, 0);
4269 void HandleTypeName(Key key)
4271 HandleTypeNameExt(FALSE, key);
4275 // ============================================================================
4276 // tree menu functions
4277 // ============================================================================
4279 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4281 if (game_status != GAME_MODE_SETUP ||
4282 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4285 int max_text_size = 0;
4288 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4289 max_text_size = MAX(max_text_size, strlen(node->name));
4291 int num_entries = numTreeInfoInGroup(ti);
4292 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4293 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4294 int text_width = max_text_size * getFontWidth(font_nr);
4295 int button_width = SC_MENUBUTTON_XSIZE;
4296 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4297 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4298 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4299 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4300 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4301 int align_xoffset = MAX(0, align_xoffset_raw);
4303 return align_xoffset;
4306 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4308 if (game_status != GAME_MODE_SETUP ||
4309 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4312 int num_entries = numTreeInfoInGroup(ti);
4313 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4314 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4315 int font_height = getFontHeight(font_nr);
4316 int text_height = font_height * num_page_entries;
4317 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4318 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4319 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4320 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4321 int align_yoffset = MAX(0, align_yoffset_raw);
4323 return align_yoffset;
4326 static void DrawChooseTree(TreeInfo **ti_ptr)
4328 int fade_mask = REDRAW_FIELD;
4329 boolean restart_music = (game_status != game_status_last_screen &&
4330 game_status_last_screen != GAME_MODE_SCOREINFO);
4333 fade_mask = REDRAW_ALL;
4335 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4337 if (game_status == GAME_MODE_SETUP)
4341 else // GAME_MODE_LEVELS
4343 SetGameStatus(GAME_MODE_MAIN);
4353 FreeScreenGadgets();
4354 CreateScreenGadgets();
4357 FadeMenuSoundsAndMusic();
4361 // needed if different viewport properties defined for this screen
4362 ChangeViewportPropertiesIfNeeded();
4364 if (game_status == GAME_MODE_NAMES)
4365 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4366 else if (game_status == GAME_MODE_LEVELNR)
4367 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4368 else if (game_status == GAME_MODE_LEVELS)
4369 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4370 else if (game_status == GAME_MODE_SCORES)
4371 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4375 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4377 // map gadgets for high score screen
4378 if (game_status == GAME_MODE_SCORES)
4379 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4381 MapScreenTreeGadgets(*ti_ptr);
4383 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4385 DrawMaskedBorder(fade_mask);
4388 PlayMenuSoundsAndMusic();
4393 static int getChooseTreeFont(TreeInfo *node, boolean active)
4395 if (game_status == GAME_MODE_SCORES)
4396 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4398 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4401 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4403 int num_entries = numTreeInfoInGroup(ti);
4404 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4405 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4406 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4407 int first_entry = ti->cl_first;
4408 int entry_pos = first_entry + y;
4409 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4410 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4411 int font_nr = getChooseTreeFont(node, active);
4412 int font_xoffset = getFontDrawOffsetX(font_nr);
4413 int xpos = MENU_SCREEN_START_XPOS;
4414 int ypos = MENU_SCREEN_START_YPOS + y;
4415 int startdx = xpos * 32;
4416 int startdy = ypos * 32;
4417 int startx = amSX + startdx;
4418 int starty = amSY + startdy;
4419 int startx_text = startx + font_xoffset;
4420 int endx_text = amSX + screen_width;
4421 int max_text_size = endx_text - startx_text;
4422 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4423 char buffer[max_buffer_len + 1];
4425 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4427 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4428 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4429 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4430 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4431 int font_size_1 = getFontWidth(font_nr1);
4432 int font_size_3 = getFontWidth(font_nr3);
4433 int font_size_4 = getFontWidth(font_nr4);
4434 int text_size_1 = 4 * font_size_1;
4435 int text_size_4 = 5 * font_size_4;
4436 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4438 int dx3 = text_size_1;
4439 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4440 int num_dots = (dx4 - dx3) / font_size_3;
4441 int startx1 = startx + dx1;
4442 int startx3 = startx + dx3;
4443 int startx4 = startx + dx4;
4444 int pos = node->pos;
4445 char *pos_text = getHallOfFameRankText(pos, 3);
4448 DrawText(startx1, starty, pos_text, font_nr1);
4450 for (i = 0; i < num_dots; i++)
4451 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4453 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4454 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4456 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4460 strncpy(buffer, node->name, max_buffer_len);
4461 buffer[max_buffer_len] = '\0';
4463 DrawText(startx, starty, buffer, font_nr);
4467 static void drawChooseTreeHeadExt(int type, char *title_string)
4469 int yoffset_sets = MENU_TITLE1_YPOS;
4470 int yoffset_setup = 16;
4471 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4472 type == TREE_TYPE_LEVEL_DIR ||
4473 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4475 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4478 static void drawChooseTreeHead(TreeInfo *ti)
4480 drawChooseTreeHeadExt(ti->type, ti->infotext);
4483 static void drawChooseTreeList(TreeInfo *ti)
4485 int first_entry = ti->cl_first;
4486 int num_entries = numTreeInfoInGroup(ti);
4487 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4490 clearMenuListArea();
4492 for (i = 0; i < num_page_entries; i++)
4494 TreeInfo *node, *node_first;
4495 int entry_pos = first_entry + i;
4497 node_first = getTreeInfoFirstGroupEntry(ti);
4498 node = getTreeInfoFromPos(node_first, entry_pos);
4500 drawChooseTreeText(ti, i, FALSE);
4502 if (node->parent_link)
4503 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4504 else if (node->level_group)
4505 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4507 initCursor(i, IMG_MENU_BUTTON);
4509 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4510 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4512 if (game_status == GAME_MODE_NAMES)
4513 drawChooseTreeEdit(i, FALSE);
4516 redraw_mask |= REDRAW_FIELD;
4519 static void drawChooseTreeInfo(TreeInfo *ti)
4521 int entry_pos = ti->cl_first + ti->cl_cursor;
4522 int last_redraw_mask = redraw_mask;
4523 int ypos = MENU_TITLE2_YPOS;
4524 int font_nr = FONT_TITLE_2;
4527 if (ti->type == TREE_TYPE_LEVEL_NR)
4528 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4530 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4531 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4532 scores.last_level_nr);
4534 if (ti->type != TREE_TYPE_LEVEL_DIR)
4537 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4538 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4540 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4542 if (node->parent_link)
4543 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4544 node->node_parent->name);
4545 else if (node->level_group)
4546 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4548 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4549 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4550 node->levels, (node->levels > 1 ? "levels" : "level"),
4553 // let BackToFront() redraw only what is needed
4554 redraw_mask = last_redraw_mask;
4555 for (x = 0; x < SCR_FIELDX; x++)
4556 MarkTileDirty(x, 1);
4559 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4561 drawChooseTreeCursor(ti->cl_cursor, active);
4562 drawChooseTreeText(ti, ti->cl_cursor, active);
4565 static void drawChooseTreeScreen(TreeInfo *ti)
4567 drawChooseTreeHead(ti);
4568 drawChooseTreeList(ti);
4569 drawChooseTreeInfo(ti);
4570 drawChooseTreeCursorAndText(ti, TRUE);
4572 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4574 // scroll bar and buttons may just have been added after reloading scores
4575 if (game_status == GAME_MODE_SCORES)
4576 MapScreenTreeGadgets(ti);
4579 static void drawChooseTreeScreen_Scores_NotAvailable(void)
4581 // dirty workaround to use spacing definitions from info screen
4582 info_mode = INFO_MODE_TITLE;
4584 char *text_info = "HighScores of Level %d";
4585 char *text_title = "Score information:";
4586 char *text_error = "No scores for this level.";
4587 char *text_foot = "Press any key or button for main menu";
4588 int font_info = FONT_TITLE_2;
4589 int font_title = FONT_INITIAL_3;
4590 int font_error = FONT_INITIAL_4;
4591 int font_foot = FONT_INITIAL_2;
4592 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
4593 int ystep_title = getMenuTextStep(spacing_title, font_title);
4594 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
4595 int ystart2 = ystart1 + ystep_title;
4596 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4597 int ystart0 = MENU_TITLE2_YPOS;
4599 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
4600 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
4602 DrawTextSCentered(ystart1, font_title, text_title);
4603 DrawTextSCentered(ystart2, font_error, text_error);
4605 DrawTextSCentered(ybottom, font_foot, text_foot);
4608 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4610 int score_pos = scores.last_added;
4612 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4613 score_pos = scores.last_entry_nr;
4615 // set current tree entry to last added score entry
4616 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4618 // if that fails, set current tree entry to first entry (back link)
4619 if (*ti_ptr == NULL)
4620 *ti_ptr = score_entries->node_group;
4622 int num_entries = numTreeInfoInGroup(*ti_ptr);
4623 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4624 int pos_score = getPosFromTreeInfo(*ti_ptr);
4625 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4626 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4628 (*ti_ptr)->cl_first = pos_first;
4629 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4634 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4637 TreeInfo *ti = *ti_ptr;
4638 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4639 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4640 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4641 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4642 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4644 int y = (ti != NULL ? ti->cl_cursor : 0);
4645 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4646 int num_entries = numTreeInfoInGroup(ti);
4647 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4648 boolean position_set_by_scrollbar = (dx == 999);
4649 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
4650 boolean button_is_valid = (mx >= 0 && my >= 0);
4651 boolean button_screen_clicked = (button_action && button_is_valid);
4653 if (game_status == GAME_MODE_SCORES)
4655 if (server_scores.updated)
4657 // reload scores, using updated server score cache file
4658 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4660 server_scores.updated = FALSE;
4662 DrawHallOfFame_setScoreEntries();
4664 if (score_entries != NULL)
4666 ti = setHallOfFameActiveEntry(ti_ptr);
4668 if (button != MB_MENU_INITIALIZE)
4669 drawChooseTreeScreen(ti);
4673 if (score_entries == NULL)
4675 if (button == MB_MENU_INITIALIZE)
4677 drawChooseTreeScreen_Scores_NotAvailable();
4679 else if (button_screen_clicked)
4681 PlaySound(SND_MENU_ITEM_SELECTING);
4683 SetGameStatus(GAME_MODE_MAIN);
4692 if (button == MB_MENU_INITIALIZE)
4694 int num_entries = numTreeInfoInGroup(ti);
4695 int entry_pos = getPosFromTreeInfo(ti);
4697 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4698 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4700 if (game_status == GAME_MODE_SCORES)
4702 ti = setHallOfFameActiveEntry(ti_ptr);
4704 else if (ti->cl_first == -1)
4706 // only on initialization
4707 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4708 ti->cl_cursor = entry_pos - ti->cl_first;
4711 else if (ti->cl_cursor >= num_page_entries ||
4712 (num_entries > num_page_entries &&
4713 num_entries - ti->cl_first < num_page_entries))
4715 // only after change of list size (by custom graphic configuration)
4716 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4717 ti->cl_cursor = entry_pos - ti->cl_first;
4720 if (position_set_by_scrollbar)
4723 drawChooseTreeScreen(ti);
4727 else if (button == MB_MENU_LEAVE)
4729 if (game_status != GAME_MODE_SCORES)
4732 PlaySound(SND_MENU_ITEM_SELECTING);
4734 if (ti->node_parent)
4736 *ti_ptr = ti->node_parent;
4737 DrawChooseTree(ti_ptr);
4739 else if (game_status == GAME_MODE_SETUP)
4741 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4742 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4743 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4744 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4746 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4747 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4748 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4749 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4750 execSetupGraphics();
4751 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4752 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4753 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4755 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4756 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4757 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4758 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4759 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4760 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4761 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4762 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4769 if (game_status == GAME_MODE_LEVELNR)
4771 int new_level_nr = atoi(level_number_current->identifier);
4773 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4776 SetGameStatus(GAME_MODE_MAIN);
4784 #if defined(PLATFORM_ANDROID)
4785 // touching the screen anywhere continues playing the next level
4786 if ((mx || my) && scores.was_just_playing)
4789 button = MB_MENU_CHOICE;
4793 // any mouse click or direction input stops playing the next level
4794 if ((mx || my || dx || dy) && scores.was_just_playing)
4796 scores.was_just_playing = FALSE;
4797 level_nr = scores.last_level_nr;
4798 LoadLevel(level_nr);
4801 if (mx || my) // mouse input
4803 x = (mx - amSX) / 32;
4804 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4806 if (game_status == GAME_MODE_NAMES)
4807 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4809 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4811 // move cursor instead of scrolling when already at start/end of list
4812 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4814 else if (dy == +1 * SCROLL_LINE &&
4815 ti->cl_first + num_page_entries == num_entries)
4818 // handle scrolling screen one line or page
4819 if (ti->cl_cursor + dy < 0 ||
4820 ti->cl_cursor + dy > num_page_entries - 1)
4822 boolean redraw = FALSE;
4824 if (ABS(dy) == SCROLL_PAGE)
4825 step = num_page_entries - 1;
4827 if (dy < 0 && ti->cl_first > 0)
4829 // scroll page/line up
4831 ti->cl_first -= step;
4832 if (ti->cl_first < 0)
4837 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4839 // scroll page/line down
4841 ti->cl_first += step;
4842 if (ti->cl_first + num_page_entries > num_entries)
4843 ti->cl_first = MAX(0, num_entries - num_page_entries);
4849 drawChooseTreeScreen(ti);
4854 // handle moving cursor one line
4855 y = ti->cl_cursor + dy;
4858 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
4860 HandleHallOfFame_SelectLevel(1, dx);
4866 TreeInfo *node_first, *node_cursor;
4867 int entry_pos = ti->cl_first + y;
4869 node_first = getTreeInfoFirstGroupEntry(ti);
4870 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4872 if (node_cursor->node_group)
4876 PlaySound(SND_MENU_ITEM_SELECTING);
4878 node_cursor->cl_first = ti->cl_first;
4879 node_cursor->cl_cursor = ti->cl_cursor;
4880 *ti_ptr = node_cursor->node_group;
4881 DrawChooseTree(ti_ptr);
4886 else if (dx == -1 && ti->node_parent)
4890 PlaySound(SND_MENU_ITEM_SELECTING);
4892 *ti_ptr = ti->node_parent;
4893 DrawChooseTree(ti_ptr);
4898 if (!anyScrollbarGadgetActive() &&
4899 IN_VIS_MENU(x, y) &&
4900 mx < mx_right_border &&
4901 y >= 0 && y < num_page_entries)
4905 if (game_status == GAME_MODE_NAMES)
4907 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4908 drawChooseTreeEdit(y, TRUE);
4911 if (y != ti->cl_cursor)
4913 PlaySound(SND_MENU_ITEM_ACTIVATING);
4915 drawChooseTreeCursorAndText(ti, FALSE);
4919 drawChooseTreeCursorAndText(ti, TRUE);
4921 drawChooseTreeInfo(ti);
4925 if (game_status == GAME_MODE_SETUP)
4927 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4928 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4929 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4930 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4932 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4933 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4934 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4935 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4936 execSetupGraphics();
4937 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4938 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4939 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4941 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4942 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4943 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4944 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4945 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4946 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4947 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4948 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4957 TreeInfo *node_first, *node_cursor;
4958 int entry_pos = ti->cl_first + y;
4960 PlaySound(SND_MENU_ITEM_SELECTING);
4962 node_first = getTreeInfoFirstGroupEntry(ti);
4963 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4965 if (node_cursor->node_group)
4969 node_cursor->cl_first = ti->cl_first;
4970 node_cursor->cl_cursor = ti->cl_cursor;
4971 *ti_ptr = node_cursor->node_group;
4972 DrawChooseTree(ti_ptr);
4974 else if (node_cursor->parent_link)
4976 if (game_status != GAME_MODE_SCORES)
4979 *ti_ptr = node_cursor->node_parent;
4980 DrawChooseTree(ti_ptr);
4984 if (game_status != GAME_MODE_SCORES)
4987 node_cursor->cl_first = ti->cl_first;
4988 node_cursor->cl_cursor = ti->cl_cursor;
4989 *ti_ptr = node_cursor;
4991 if (ti->type == TREE_TYPE_LEVEL_DIR)
4993 LoadLevelSetup_SeriesInfo();
4995 SaveLevelSetup_LastSeries();
4996 SaveLevelSetup_SeriesInfo();
5000 if (game_status == GAME_MODE_SETUP)
5002 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5003 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5004 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5005 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5007 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5008 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5009 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5010 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5011 execSetupGraphics();
5012 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5013 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5014 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5016 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5017 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5018 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5019 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5020 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5021 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5022 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5023 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5030 if (game_status == GAME_MODE_LEVELNR)
5032 int new_level_nr = atoi(level_number_current->identifier);
5034 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5036 else if (game_status == GAME_MODE_LEVELS)
5038 // store level set if chosen from "last played level set" menu
5039 StoreLastPlayedLevels(leveldir_current);
5041 else if (game_status == GAME_MODE_NAMES)
5043 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5045 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5052 // change active user to selected user
5053 user.nr = entry_pos;
5055 // save number of new active user
5058 // load setup of new active user
5061 // load last level set of new active user
5062 LoadLevelSetup_LastSeries();
5063 LoadLevelSetup_SeriesInfo();
5065 // update list of last played level sets
5066 UpdateLastPlayedLevels_TreeInfo();
5070 ToggleFullscreenIfNeeded();
5071 ChangeWindowScalingIfNeeded();
5073 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5074 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5075 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5077 else if (game_status == GAME_MODE_SCORES)
5079 if (setup.auto_play_next_level && setup.increment_levels &&
5080 scores.last_level_nr < leveldir_current->last_level &&
5081 scores.was_just_playing &&
5084 StartGameActions(network.enabled, setup.autorecord,
5088 else if (!scores.was_just_playing)
5090 SetGameStatus(GAME_MODE_SCOREINFO);
5092 DrawScoreInfo(node_cursor->pos);
5098 SetGameStatus(GAME_MODE_MAIN);
5106 if (game_status == GAME_MODE_SCORES)
5107 PlayMenuSoundIfLoop();
5110 void DrawChoosePlayerName(void)
5114 if (player_name != NULL)
5116 freeTreeInfo(player_name);
5121 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5123 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5124 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5127 ti->node_top = &player_name;
5128 ti->sort_priority = 10000 + value;
5129 ti->color = getPlayerNameColor(global.user_names[i]);
5131 snprintf(identifier, sizeof(identifier), "%d", value);
5132 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5134 setString(&ti->identifier, identifier);
5135 setString(&ti->name, name);
5136 setString(&ti->name_sorting, name);
5138 pushTreeInfo(&player_name, ti);
5141 // sort player entries by player number
5142 sortTreeInfo(&player_name);
5144 // set current player entry to selected player entry
5145 player_name_current =
5146 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5148 // if that fails, set current player name to first available name
5149 if (player_name_current == NULL)
5150 player_name_current = player_name;
5152 DrawChooseTree(&player_name_current);
5155 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5157 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5160 void DrawChooseLevelSet(void)
5162 DrawChooseTree(&leveldir_current);
5165 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5167 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5170 void DrawChooseLevelNr(void)
5174 if (level_number != NULL)
5176 freeTreeInfo(level_number);
5178 level_number = NULL;
5181 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5183 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5184 char identifier[32], name[64];
5187 // temporarily load level info to get level name
5188 LoadLevelInfoOnly(i);
5190 ti->node_top = &level_number;
5191 ti->sort_priority = 10000 + value;
5192 ti->color = (level.no_level_file ? FC_BLUE :
5193 LevelStats_getSolved(i) ? FC_GREEN :
5194 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5196 snprintf(identifier, sizeof(identifier), "%d", value);
5197 snprintf(name, sizeof(name), "%03d: %s", value,
5198 (level.no_level_file ? "(no file)" : level.name));
5200 setString(&ti->identifier, identifier);
5201 setString(&ti->name, name);
5202 setString(&ti->name_sorting, name);
5204 pushTreeInfo(&level_number, ti);
5207 // sort level number values to start with lowest level number
5208 sortTreeInfo(&level_number);
5210 // set current level number to current level number
5211 level_number_current =
5212 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5214 // if that also fails, set current level number to first available level
5215 if (level_number_current == NULL)
5216 level_number_current = level_number;
5218 DrawChooseTree(&level_number_current);
5221 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5223 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5226 static void DrawHallOfFame_setScoreEntries(void)
5228 int max_empty_entries = 10; // at least show "top ten" list, if empty
5229 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5230 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5231 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5234 if (score_entries != NULL)
5236 freeTreeInfo(score_entries);
5238 score_entries = NULL;
5241 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5243 // do not add empty score entries if off-screen
5244 if (scores.entry[i].score == 0 &&
5245 scores.entry[i].time == 0 &&
5246 i >= min_score_entries)
5249 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5250 char identifier[32], name[64];
5253 ti->node_top = &score_entries;
5254 ti->sort_priority = 10000 + value;
5255 ti->color = FC_YELLOW;
5258 snprintf(identifier, sizeof(identifier), "%d", value);
5259 snprintf(name, sizeof(name), "%03d.", value + 1);
5261 setString(&ti->identifier, identifier);
5262 setString(&ti->name, name);
5263 setString(&ti->name_sorting, name);
5265 pushTreeInfo(&score_entries, ti);
5268 // sort score entries to start with highest score entry
5269 sortTreeInfo(&score_entries);
5271 // add top tree node to create back link to main menu
5272 score_entries = addTopTreeInfoNode(score_entries);
5274 // set current score entry to last added or highest score entry
5275 score_entry_current =
5276 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5278 // if that fails, set current score entry to first valid score entry
5279 if (score_entry_current == NULL)
5280 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5282 // ("score_entries" and "score_entry_current" may be NULL here)
5285 void DrawHallOfFame(int level_nr)
5287 scores.last_level_nr = level_nr;
5288 scores.was_just_playing = (game_status_last_screen == GAME_MODE_PLAYING);
5290 // (this is needed when called from GameEnd() after winning a game)
5291 KeyboardAutoRepeatOn();
5293 // (this is needed when called from GameEnd() after winning a game)
5294 SetDrawDeactivationMask(REDRAW_NONE);
5295 SetDrawBackgroundMask(REDRAW_FIELD);
5297 LoadLocalAndServerScore(level_nr, TRUE);
5299 DrawHallOfFame_setScoreEntries();
5301 if (scores.last_added >= 0)
5302 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5304 FadeSetEnterScreen();
5306 DrawChooseTree(&score_entry_current);
5309 static char *getHallOfFameRankText(int nr, int size)
5311 static char rank_text[10];
5312 boolean forced = (scores.force_last_added && nr == scores.last_added);
5313 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5315 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5320 static char *getHallOfFameTimeText(int nr)
5322 static char score_text[10];
5323 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5324 int mm = (time_seconds / 60) % 60;
5325 int ss = (time_seconds % 60);
5327 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5332 static char *getHallOfFameScoreText(int nr, int size)
5334 if (!level.rate_time_over_score)
5335 return int2str(scores.entry[nr].score, size); // show normal score
5336 else if (level.use_step_counter)
5337 return int2str(scores.entry[nr].time, size); // show number of steps
5339 return getHallOfFameTimeText(nr); // show playing time
5342 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5344 static char tape_date[MAX_ISO_DATE_LEN + 1];
5347 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5348 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5349 return entry->tape_date;
5351 for (i = 0, j = 0; i < 8; i++, j++)
5353 tape_date[j] = entry->tape_basename[i];
5355 if (i == 3 || i == 5)
5356 tape_date[++j] = '-';
5359 tape_date[MAX_ISO_DATE_LEN] = '\0';
5364 static void HandleHallOfFame_SelectLevel(int step, int direction)
5366 int old_level_nr = scores.last_level_nr;
5367 int new_level_nr = old_level_nr + step * direction;
5369 if (new_level_nr < leveldir_current->first_level)
5370 new_level_nr = leveldir_current->first_level;
5371 if (new_level_nr > leveldir_current->last_level)
5372 new_level_nr = leveldir_current->last_level;
5374 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5375 new_level_nr = leveldir_current->handicap_level;
5377 if (new_level_nr != old_level_nr)
5379 PlaySound(SND_MENU_ITEM_SELECTING);
5381 scores.last_level_nr = level_nr = new_level_nr;
5382 scores.last_entry_nr = 0;
5384 LoadLevel(level_nr);
5385 LoadLocalAndServerScore(level_nr, TRUE);
5387 DrawHallOfFame_setScoreEntries();
5389 if (game_status == GAME_MODE_SCORES)
5391 // force remapping optional gadgets (especially scroll bar)
5392 UnmapScreenTreeGadgets();
5394 // redraw complete high score screen, as sub-title has changed
5397 // redraw level selection buttons (which have just been erased)
5398 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5400 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5404 DrawScoreInfo_Content(scores.last_entry_nr);
5407 SaveLevelSetup_SeriesInfo();
5411 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5413 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5416 static void DrawScoreInfo_Content(int entry_nr)
5418 struct ScoreEntry *entry = &scores.entry[entry_nr];
5419 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5420 char *tape_date = getHallOfFameTapeDateText(entry);
5421 int font_title = MENU_INFO_FONT_TITLE;
5422 int font_head = MENU_INFO_FONT_HEAD;
5423 int font_text = MENU_INFO_FONT_TEXT;
5424 int font_foot = MENU_INFO_FONT_FOOT;
5425 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5426 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5427 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5428 int xstep = getFontWidth(font_text);
5429 int ystep_title = getMenuTextStep(spacing_title, font_title);
5430 int ystep_para = getMenuTextStep(spacing_para, font_text);
5431 int ystep_line = getMenuTextStep(spacing_line, font_text);
5432 int xstart = mSX - SX + menu.left_spacing[GAME_MODE_SCOREINFO];
5433 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5434 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5435 int xstart1 = xstart + xstep;
5436 int xstart2 = xstart + xstep * 12;
5437 int select_x = SX + xstart1;
5438 int select_y1, select_y2;
5440 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5441 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5442 int font_width = getFontWidth(font_text);
5443 int font_height = getFontHeight(font_text);
5444 int tape_date_width = getTextWidth(tape_date, font_text);
5445 int pad_left = xstart2;
5446 int pad_right = menu.right_spacing[GAME_MODE_SCOREINFO];
5447 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5448 int max_lines_per_text = 5;
5453 // redraw level selection buttons (which have just been erased)
5454 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5456 if (score_entries == NULL)
5458 drawChooseTreeScreen_Scores_NotAvailable();
5463 drawChooseTreeHead(score_entries);
5464 drawChooseTreeInfo(score_entries);
5466 DrawTextSCentered(ystart, font_title, "Score Information:");
5467 ystart += ystep_title;
5469 DrawTextF(xstart1, ystart, font_head, "Level Set");
5470 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5471 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5472 TRUE, FALSE, FALSE);
5473 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5475 DrawTextF(xstart1, ystart, font_head, "Level");
5476 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5477 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5478 TRUE, FALSE, FALSE);
5479 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5481 select_y1 = SY + ystart;
5482 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5484 DrawTextF(xstart1, ystart, font_head, "Rank");
5485 DrawTextF(xstart2, ystart, font_text, pos_text);
5486 ystart += ystep_line;
5488 DrawTextF(xstart1, ystart, font_head, "Player");
5489 DrawTextF(xstart2, ystart, font_text, entry->name);
5490 ystart += ystep_line;
5492 if (level.use_step_counter)
5494 DrawTextF(xstart1, ystart, font_head, "Steps");
5495 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5496 ystart += ystep_line;
5500 DrawTextF(xstart1, ystart, font_head, "Time");
5501 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5502 ystart += ystep_line;
5505 if (!level.rate_time_over_score || entry->score > 0)
5507 DrawTextF(xstart1, ystart, font_head, "Score");
5508 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5509 ystart += ystep_line;
5512 ystart += ystep_line;
5514 play_x = SX + xstart2 + tape_date_width + font_width;
5515 play_y = SY + ystart + (font_height - play_height) / 2;
5517 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5518 DrawTextF(xstart2, ystart, font_text, tape_date);
5519 ystart += ystep_line;
5521 DrawTextF(xstart1, ystart, font_head, "Platform");
5522 DrawTextF(xstart2, ystart, font_text, entry->platform);
5523 ystart += ystep_line;
5525 DrawTextF(xstart1, ystart, font_head, "Version");
5526 DrawTextF(xstart2, ystart, font_text, entry->version);
5527 ystart += ystep_line;
5529 DrawTextF(xstart1, ystart, font_head, "Country");
5530 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5531 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5532 TRUE, FALSE, FALSE);
5533 ystart += ystep_line;
5535 select_y2 = SY + ystart;
5537 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5539 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5540 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5543 static void DrawScoreInfo(int entry_nr)
5545 scores.last_entry_nr = entry_nr;
5546 score_info_tape_play = FALSE;
5550 FreeScreenGadgets();
5551 CreateScreenGadgets();
5553 FadeOut(REDRAW_FIELD);
5555 // needed if different viewport properties defined after playing score tape
5556 ChangeViewportPropertiesIfNeeded();
5558 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
5559 SetDrawDeactivationMask(REDRAW_NONE);
5560 SetDrawBackgroundMask(REDRAW_FIELD);
5562 // needed if different background image defined after playing score tape
5563 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5564 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5566 // special compatibility handling for "Snake Bite" graphics set
5567 if (strPrefix(leveldir_current->identifier, "snake_bite"))
5568 ClearRectangle(gfx.background_bitmap, gfx.real_sx, gfx.real_sy + 64,
5569 gfx.full_sxsize, gfx.full_sysize - 64);
5571 DrawScoreInfo_Content(entry_nr);
5573 // map gadgets for score info screen
5574 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5576 FadeIn(REDRAW_FIELD);
5579 static void HandleScoreInfo_SelectScore(int step, int direction)
5581 int old_entry_nr = scores.last_entry_nr;
5582 int new_entry_nr = old_entry_nr + step * direction;
5583 int num_nodes = numTreeInfoInGroup(score_entry_current);
5584 int num_entries = num_nodes - 1; // score nodes only, without back link
5586 if (new_entry_nr < 0)
5588 if (new_entry_nr > num_entries - 1)
5589 new_entry_nr = num_entries - 1;
5591 if (new_entry_nr != old_entry_nr)
5593 scores.last_entry_nr = new_entry_nr;
5595 DrawScoreInfo_Content(new_entry_nr);
5599 static void HandleScoreInfo_PlayTape(void)
5601 if (!PlayScoreTape(scores.last_entry_nr))
5603 DrawScoreInfo_Content(scores.last_entry_nr);
5605 FadeIn(REDRAW_FIELD);
5609 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5611 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5612 boolean button_is_valid = (mx >= 0 && my >= 0);
5613 boolean button_screen_clicked = (button_action && button_is_valid);
5615 if (server_scores.updated)
5617 // reload scores, using updated server score cache file
5618 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5620 server_scores.updated = FALSE;
5622 DrawHallOfFame_setScoreEntries();
5624 DrawScoreInfo_Content(scores.last_entry_nr);
5627 if (button_screen_clicked)
5629 PlaySound(SND_MENU_ITEM_SELECTING);
5631 SetGameStatus(GAME_MODE_SCORES);
5633 DrawHallOfFame(scores.last_level_nr);
5637 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5641 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5646 // ============================================================================
5647 // setup screen functions
5648 // ============================================================================
5650 static struct TokenInfo *setup_info;
5651 static int num_setup_info; // number of setup entries shown on screen
5652 static int max_setup_info; // total number of setup entries in list
5654 static char *window_size_text;
5655 static char *scaling_type_text;
5656 static char *rendering_mode_text;
5657 static char *vsync_mode_text;
5658 static char *scroll_delay_text;
5659 static char *snapshot_mode_text;
5660 static char *game_speed_text;
5661 static char *scores_type_text;
5662 static char *network_server_text;
5663 static char *graphics_set_name;
5664 static char *sounds_set_name;
5665 static char *music_set_name;
5666 static char *volume_simple_text;
5667 static char *volume_loops_text;
5668 static char *volume_music_text;
5669 static char *touch_controls_text;
5670 static char *move_distance_text;
5671 static char *drop_distance_text;
5672 static char *transparency_text;
5673 static char *grid_size_text[2][2];
5675 static void execSetupMain(void)
5677 setup_mode = SETUP_MODE_MAIN;
5682 static void execSetupGame_setScoresType(void)
5684 if (scores_types == NULL)
5688 for (i = 0; scores_types_list[i].value != NULL; i++)
5690 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5691 char identifier[32], name[32];
5692 char *value = scores_types_list[i].value;
5693 char *text = scores_types_list[i].text;
5695 ti->node_top = &scores_types;
5696 ti->sort_priority = i;
5698 sprintf(identifier, "%s", value);
5699 sprintf(name, "%s", text);
5701 setString(&ti->identifier, identifier);
5702 setString(&ti->name, name);
5703 setString(&ti->name_sorting, name);
5704 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5706 pushTreeInfo(&scores_types, ti);
5709 // sort scores type values to start with lowest scores type value
5710 sortTreeInfo(&scores_types);
5712 // set current scores type value to configured scores type value
5713 scores_type_current =
5714 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5716 // if that fails, set current scores type to reliable default value
5717 if (scores_type_current == NULL)
5718 scores_type_current =
5719 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5721 // if that also fails, set current scores type to first available value
5722 if (scores_type_current == NULL)
5723 scores_type_current = scores_types;
5726 setup.scores_in_highscore_list = scores_type_current->identifier;
5728 // needed for displaying scores type text instead of identifier
5729 scores_type_text = scores_type_current->name;
5732 static void execSetupGame_setGameSpeeds(boolean update_value)
5734 if (setup.game_speed_extended)
5736 game_speeds_list = game_speeds_list_extended;
5737 game_speeds = game_speeds_extended;
5741 game_speeds_list = game_speeds_list_normal;
5742 game_speeds = game_speeds_normal;
5745 if (game_speeds == NULL)
5749 for (i = 0; game_speeds_list[i].value != -1; i++)
5751 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5752 char identifier[32], name[32];
5753 int value = game_speeds_list[i].value;
5754 char *text = game_speeds_list[i].text;
5756 ti->node_top = &game_speeds;
5757 ti->sort_priority = 10000 - value;
5759 sprintf(identifier, "%d", value);
5760 sprintf(name, "%s", text);
5762 setString(&ti->identifier, identifier);
5763 setString(&ti->name, name);
5764 setString(&ti->name_sorting, name);
5765 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5767 pushTreeInfo(&game_speeds, ti);
5770 // sort game speed values to start with slowest game speed
5771 sortTreeInfo(&game_speeds);
5773 update_value = TRUE;
5778 // set current game speed to configured game speed value
5779 game_speed_current =
5780 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5782 // if that fails, set current game speed to reliable default value
5783 if (game_speed_current == NULL)
5784 game_speed_current =
5785 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5787 // if that also fails, set current game speed to first available speed
5788 if (game_speed_current == NULL)
5789 game_speed_current = game_speeds;
5791 if (setup.game_speed_extended)
5792 game_speeds_extended = game_speeds;
5794 game_speeds_normal = game_speeds;
5797 setup.game_frame_delay = atoi(game_speed_current->identifier);
5799 // needed for displaying game speed text instead of identifier
5800 game_speed_text = game_speed_current->name;
5803 static void execSetupGame_setScrollDelays(void)
5805 if (scroll_delays == NULL)
5809 for (i = 0; scroll_delays_list[i].value != -1; i++)
5811 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5812 char identifier[32], name[32];
5813 int value = scroll_delays_list[i].value;
5814 char *text = scroll_delays_list[i].text;
5816 ti->node_top = &scroll_delays;
5817 ti->sort_priority = value;
5819 sprintf(identifier, "%d", value);
5820 sprintf(name, "%s", text);
5822 setString(&ti->identifier, identifier);
5823 setString(&ti->name, name);
5824 setString(&ti->name_sorting, name);
5825 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5827 pushTreeInfo(&scroll_delays, ti);
5830 // sort scroll delay values to start with lowest scroll delay value
5831 sortTreeInfo(&scroll_delays);
5833 // set current scroll delay value to configured scroll delay value
5834 scroll_delay_current =
5835 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5837 // if that fails, set current scroll delay to reliable default value
5838 if (scroll_delay_current == NULL)
5839 scroll_delay_current =
5840 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5842 // if that also fails, set current scroll delay to first available value
5843 if (scroll_delay_current == NULL)
5844 scroll_delay_current = scroll_delays;
5847 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5849 // needed for displaying scroll delay text instead of identifier
5850 scroll_delay_text = scroll_delay_current->name;
5853 static void execSetupGame_setSnapshotModes(void)
5855 if (snapshot_modes == NULL)
5859 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5861 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5862 char identifier[32], name[32];
5863 char *value = snapshot_modes_list[i].value;
5864 char *text = snapshot_modes_list[i].text;
5866 ti->node_top = &snapshot_modes;
5867 ti->sort_priority = i;
5869 sprintf(identifier, "%s", value);
5870 sprintf(name, "%s", text);
5872 setString(&ti->identifier, identifier);
5873 setString(&ti->name, name);
5874 setString(&ti->name_sorting, name);
5875 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5877 pushTreeInfo(&snapshot_modes, ti);
5880 // sort snapshot mode values to start with lowest snapshot mode value
5881 sortTreeInfo(&snapshot_modes);
5883 // set current snapshot mode value to configured snapshot mode value
5884 snapshot_mode_current =
5885 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5887 // if that fails, set current snapshot mode to reliable default value
5888 if (snapshot_mode_current == NULL)
5889 snapshot_mode_current =
5890 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5892 // if that also fails, set current snapshot mode to first available value
5893 if (snapshot_mode_current == NULL)
5894 snapshot_mode_current = snapshot_modes;
5897 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5899 // needed for displaying snapshot mode text instead of identifier
5900 snapshot_mode_text = snapshot_mode_current->name;
5903 static void execSetupGame_setNetworkServerText(void)
5905 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5907 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5911 strncpy(network_server_hostname, setup.network_server_hostname,
5912 MAX_SETUP_TEXT_INPUT_LEN);
5913 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5916 // needed for displaying network server text instead of identifier
5917 network_server_text = network_server_hostname;
5920 static void execSetupGame(void)
5922 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5924 execSetupGame_setGameSpeeds(FALSE);
5925 execSetupGame_setScoresType();
5926 execSetupGame_setScrollDelays();
5927 execSetupGame_setSnapshotModes();
5929 execSetupGame_setNetworkServerText();
5931 if (!setup.provide_uploading_tapes)
5932 setHideSetupEntry(execOfferUploadTapes);
5934 setup_mode = SETUP_MODE_GAME;
5938 // check if vsync needs to be disabled for this game speed to work
5939 if (check_vsync_mode)
5940 DisableVsyncIfNeeded();
5943 static void execSetupChooseScoresType(void)
5945 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
5950 static void execSetupChooseGameSpeed(void)
5952 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5957 static void execSetupChooseScrollDelay(void)
5959 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5964 static void execSetupChooseSnapshotMode(void)
5966 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5971 static void execSetupEngines(void)
5973 setup_mode = SETUP_MODE_ENGINES;
5978 static void execSetupEditor(void)
5980 setup_mode = SETUP_MODE_EDITOR;
5985 static void execSetupGraphics_setWindowSizes(boolean update_list)
5987 if (window_sizes != NULL && update_list)
5989 freeTreeInfo(window_sizes);
5991 window_sizes = NULL;
5994 if (window_sizes == NULL)
5996 boolean current_window_size_found = FALSE;
5999 for (i = 0; window_sizes_list[i].value != -1; i++)
6001 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6002 char identifier[32], name[32];
6003 int value = window_sizes_list[i].value;
6004 char *text = window_sizes_list[i].text;
6006 ti->node_top = &window_sizes;
6007 ti->sort_priority = value;
6009 sprintf(identifier, "%d", value);
6010 sprintf(name, "%s", text);
6012 setString(&ti->identifier, identifier);
6013 setString(&ti->name, name);
6014 setString(&ti->name_sorting, name);
6015 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6017 pushTreeInfo(&window_sizes, ti);
6019 if (value == setup.window_scaling_percent)
6020 current_window_size_found = TRUE;
6023 if (!current_window_size_found)
6025 // add entry for non-preset window scaling value
6027 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6028 char identifier[32], name[32];
6029 int value = setup.window_scaling_percent;
6031 ti->node_top = &window_sizes;
6032 ti->sort_priority = value;
6034 sprintf(identifier, "%d", value);
6035 sprintf(name, "%d %% (Current)", value);
6037 setString(&ti->identifier, identifier);
6038 setString(&ti->name, name);
6039 setString(&ti->name_sorting, name);
6040 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6042 pushTreeInfo(&window_sizes, ti);
6045 // sort window size values to start with lowest window size value
6046 sortTreeInfo(&window_sizes);
6048 // set current window size value to configured window size value
6049 window_size_current =
6050 getTreeInfoFromIdentifier(window_sizes,
6051 i_to_a(setup.window_scaling_percent));
6053 // if that fails, set current window size to reliable default value
6054 if (window_size_current == NULL)
6055 window_size_current =
6056 getTreeInfoFromIdentifier(window_sizes,
6057 i_to_a(STD_WINDOW_SCALING_PERCENT));
6059 // if that also fails, set current window size to first available value
6060 if (window_size_current == NULL)
6061 window_size_current = window_sizes;
6064 setup.window_scaling_percent = atoi(window_size_current->identifier);
6066 // needed for displaying window size text instead of identifier
6067 window_size_text = window_size_current->name;
6070 static void execSetupGraphics_setScalingTypes(void)
6072 if (scaling_types == NULL)
6076 for (i = 0; scaling_types_list[i].value != NULL; i++)
6078 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6079 char identifier[32], name[32];
6080 char *value = scaling_types_list[i].value;
6081 char *text = scaling_types_list[i].text;
6083 ti->node_top = &scaling_types;
6084 ti->sort_priority = i;
6086 sprintf(identifier, "%s", value);
6087 sprintf(name, "%s", text);
6089 setString(&ti->identifier, identifier);
6090 setString(&ti->name, name);
6091 setString(&ti->name_sorting, name);
6092 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6094 pushTreeInfo(&scaling_types, ti);
6097 // sort scaling type values to start with lowest scaling type value
6098 sortTreeInfo(&scaling_types);
6100 // set current scaling type value to configured scaling type value
6101 scaling_type_current =
6102 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6104 // if that fails, set current scaling type to reliable default value
6105 if (scaling_type_current == NULL)
6106 scaling_type_current =
6107 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6109 // if that also fails, set current scaling type to first available value
6110 if (scaling_type_current == NULL)
6111 scaling_type_current = scaling_types;
6114 setup.window_scaling_quality = scaling_type_current->identifier;
6116 // needed for displaying scaling type text instead of identifier
6117 scaling_type_text = scaling_type_current->name;
6120 static void execSetupGraphics_setRenderingModes(void)
6122 if (rendering_modes == NULL)
6126 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6128 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6129 char identifier[32], name[32];
6130 char *value = rendering_modes_list[i].value;
6131 char *text = rendering_modes_list[i].text;
6133 ti->node_top = &rendering_modes;
6134 ti->sort_priority = i;
6136 sprintf(identifier, "%s", value);
6137 sprintf(name, "%s", text);
6139 setString(&ti->identifier, identifier);
6140 setString(&ti->name, name);
6141 setString(&ti->name_sorting, name);
6142 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6144 pushTreeInfo(&rendering_modes, ti);
6147 // sort rendering mode values to start with lowest rendering mode value
6148 sortTreeInfo(&rendering_modes);
6150 // set current rendering mode value to configured rendering mode value
6151 rendering_mode_current =
6152 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6154 // if that fails, set current rendering mode to reliable default value
6155 if (rendering_mode_current == NULL)
6156 rendering_mode_current =
6157 getTreeInfoFromIdentifier(rendering_modes,
6158 STR_SPECIAL_RENDERING_DEFAULT);
6160 // if that also fails, set current rendering mode to first available one
6161 if (rendering_mode_current == NULL)
6162 rendering_mode_current = rendering_modes;
6165 setup.screen_rendering_mode = rendering_mode_current->identifier;
6167 // needed for displaying rendering mode text instead of identifier
6168 rendering_mode_text = rendering_mode_current->name;
6171 static void execSetupGraphics_setVsyncModes(boolean update_value)
6173 if (vsync_modes == NULL)
6177 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6179 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6180 char identifier[32], name[32];
6181 char *value = vsync_modes_list[i].value;
6182 char *text = vsync_modes_list[i].text;
6184 ti->node_top = &vsync_modes;
6185 ti->sort_priority = i;
6187 sprintf(identifier, "%s", value);
6188 sprintf(name, "%s", text);
6190 setString(&ti->identifier, identifier);
6191 setString(&ti->name, name);
6192 setString(&ti->name_sorting, name);
6193 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6195 pushTreeInfo(&vsync_modes, ti);
6198 // sort vsync mode values to start with lowest vsync mode value
6199 sortTreeInfo(&vsync_modes);
6201 update_value = TRUE;
6206 // set current vsync mode value to configured vsync mode value
6207 vsync_mode_current =
6208 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6210 // if that fails, set current vsync mode to reliable default value
6211 if (vsync_mode_current == NULL)
6212 vsync_mode_current =
6213 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6215 // if that also fails, set current vsync mode to first available one
6216 if (vsync_mode_current == NULL)
6217 vsync_mode_current = vsync_modes;
6220 setup.vsync_mode = vsync_mode_current->identifier;
6222 // needed for displaying vsync mode text instead of identifier
6223 vsync_mode_text = vsync_mode_current->name;
6226 static void execSetupGraphics(void)
6228 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6230 // update "setup.window_scaling_percent" from list selection
6231 // (in this case, window scaling was changed on setup screen)
6232 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6233 execSetupGraphics_setWindowSizes(FALSE);
6235 // update "setup.vsync_mode" from list selection
6236 // (in this case, vsync mode was changed on setup screen)
6237 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6238 execSetupGraphics_setVsyncModes(FALSE);
6240 // update list selection from "setup.window_scaling_percent"
6241 // (window scaling may have changed by resizing the window)
6242 execSetupGraphics_setWindowSizes(TRUE);
6244 // update list selection from "setup.vsync_mode"
6245 // (vsync_mode may have changed by re-creating the renderer)
6246 execSetupGraphics_setVsyncModes(TRUE);
6248 execSetupGraphics_setScalingTypes();
6249 execSetupGraphics_setRenderingModes();
6251 setup_mode = SETUP_MODE_GRAPHICS;
6255 // check if game speed is high enough for 60 Hz vsync to work
6256 if (check_game_speed)
6257 ModifyGameSpeedIfNeeded();
6259 // window scaling may have changed at this point
6260 ChangeWindowScalingIfNeeded();
6262 // window scaling quality may have changed at this point
6263 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6264 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6266 // screen rendering mode may have changed at this point
6267 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6269 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6270 int video_vsync_mode = video.vsync_mode;
6272 // screen vsync mode may have changed at this point
6273 ChangeVsyncModeIfNeeded();
6275 // check if setting vsync mode to selected value failed
6276 if (setup_vsync_mode != video_vsync_mode &&
6277 setup_vsync_mode != video.vsync_mode)
6279 // changing vsync mode to selected value failed -- reset displayed value
6280 execSetupGraphics_setVsyncModes(TRUE);
6282 Request("Setting VSync failed!", REQ_CONFIRM);
6288 static void execSetupChooseWindowSize(void)
6290 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6295 static void execSetupChooseScalingType(void)
6297 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6302 static void execSetupChooseRenderingMode(void)
6304 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6309 static void execSetupChooseVsyncMode(void)
6311 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6316 static void execSetupChooseVolumeSimple(void)
6318 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6323 static void execSetupChooseVolumeLoops(void)
6325 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6330 static void execSetupChooseVolumeMusic(void)
6332 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6337 static void execSetupSound(void)
6339 if (volumes_simple == NULL)
6341 boolean current_volume_simple_found = FALSE;
6344 for (i = 0; volumes_list[i].value != -1; i++)
6346 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6347 char identifier[32], name[32];
6348 int value = volumes_list[i].value;
6349 char *text = volumes_list[i].text;
6351 ti->node_top = &volumes_simple;
6352 ti->sort_priority = value;
6354 sprintf(identifier, "%d", value);
6355 sprintf(name, "%s", text);
6357 setString(&ti->identifier, identifier);
6358 setString(&ti->name, name);
6359 setString(&ti->name_sorting, name);
6360 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6362 pushTreeInfo(&volumes_simple, ti);
6364 if (value == setup.volume_simple)
6365 current_volume_simple_found = TRUE;
6368 if (!current_volume_simple_found)
6370 // add entry for non-preset volume value
6372 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6373 char identifier[32], name[32];
6374 int value = setup.volume_simple;
6376 ti->node_top = &volumes_simple;
6377 ti->sort_priority = value;
6379 sprintf(identifier, "%d", value);
6380 sprintf(name, "%d %% (Current)", value);
6382 setString(&ti->identifier, identifier);
6383 setString(&ti->name, name);
6384 setString(&ti->name_sorting, name);
6385 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6387 pushTreeInfo(&volumes_simple, ti);
6390 // sort volume values to start with lowest volume value
6391 sortTreeInfo(&volumes_simple);
6393 // set current volume value to configured volume value
6394 volume_simple_current =
6395 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6397 // if that fails, set current volume to reliable default value
6398 if (volume_simple_current == NULL)
6399 volume_simple_current =
6400 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6402 // if that also fails, set current volume to first available value
6403 if (volume_simple_current == NULL)
6404 volume_simple_current = volumes_simple;
6407 if (volumes_loops == NULL)
6409 boolean current_volume_loops_found = FALSE;
6412 for (i = 0; volumes_list[i].value != -1; i++)
6414 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6415 char identifier[32], name[32];
6416 int value = volumes_list[i].value;
6417 char *text = volumes_list[i].text;
6419 ti->node_top = &volumes_loops;
6420 ti->sort_priority = value;
6422 sprintf(identifier, "%d", value);
6423 sprintf(name, "%s", text);
6425 setString(&ti->identifier, identifier);
6426 setString(&ti->name, name);
6427 setString(&ti->name_sorting, name);
6428 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6430 pushTreeInfo(&volumes_loops, ti);
6432 if (value == setup.volume_loops)
6433 current_volume_loops_found = TRUE;
6436 if (!current_volume_loops_found)
6438 // add entry for non-preset volume value
6440 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6441 char identifier[32], name[32];
6442 int value = setup.volume_loops;
6444 ti->node_top = &volumes_loops;
6445 ti->sort_priority = value;
6447 sprintf(identifier, "%d", value);
6448 sprintf(name, "%d %% (Current)", value);
6450 setString(&ti->identifier, identifier);
6451 setString(&ti->name, name);
6452 setString(&ti->name_sorting, name);
6453 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6455 pushTreeInfo(&volumes_loops, ti);
6458 // sort volume values to start with lowest volume value
6459 sortTreeInfo(&volumes_loops);
6461 // set current volume value to configured volume value
6462 volume_loops_current =
6463 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6465 // if that fails, set current volume to reliable default value
6466 if (volume_loops_current == NULL)
6467 volume_loops_current =
6468 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6470 // if that also fails, set current volume to first available value
6471 if (volume_loops_current == NULL)
6472 volume_loops_current = volumes_loops;
6475 if (volumes_music == NULL)
6477 boolean current_volume_music_found = FALSE;
6480 for (i = 0; volumes_list[i].value != -1; i++)
6482 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6483 char identifier[32], name[32];
6484 int value = volumes_list[i].value;
6485 char *text = volumes_list[i].text;
6487 ti->node_top = &volumes_music;
6488 ti->sort_priority = value;
6490 sprintf(identifier, "%d", value);
6491 sprintf(name, "%s", text);
6493 setString(&ti->identifier, identifier);
6494 setString(&ti->name, name);
6495 setString(&ti->name_sorting, name);
6496 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6498 pushTreeInfo(&volumes_music, ti);
6500 if (value == setup.volume_music)
6501 current_volume_music_found = TRUE;
6504 if (!current_volume_music_found)
6506 // add entry for non-preset volume value
6508 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6509 char identifier[32], name[32];
6510 int value = setup.volume_music;
6512 ti->node_top = &volumes_music;
6513 ti->sort_priority = value;
6515 sprintf(identifier, "%d", value);
6516 sprintf(name, "%d %% (Current)", value);
6518 setString(&ti->identifier, identifier);
6519 setString(&ti->name, name);
6520 setString(&ti->name_sorting, name);
6521 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6523 pushTreeInfo(&volumes_music, ti);
6526 // sort volume values to start with lowest volume value
6527 sortTreeInfo(&volumes_music);
6529 // set current volume value to configured volume value
6530 volume_music_current =
6531 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6533 // if that fails, set current volume to reliable default value
6534 if (volume_music_current == NULL)
6535 volume_music_current =
6536 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6538 // if that also fails, set current volume to first available value
6539 if (volume_music_current == NULL)
6540 volume_music_current = volumes_music;
6543 setup.volume_simple = atoi(volume_simple_current->identifier);
6544 setup.volume_loops = atoi(volume_loops_current->identifier);
6545 setup.volume_music = atoi(volume_music_current->identifier);
6547 // needed for displaying volume text instead of identifier
6548 volume_simple_text = volume_simple_current->name;
6549 volume_loops_text = volume_loops_current->name;
6550 volume_music_text = volume_music_current->name;
6552 setup_mode = SETUP_MODE_SOUND;
6557 static void execSetupChooseTouchControls(void)
6559 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6564 static void execSetupChooseMoveDistance(void)
6566 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6571 static void execSetupChooseDropDistance(void)
6573 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6578 static void execSetupChooseTransparency(void)
6580 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6585 static void execSetupChooseGridXSize_0(void)
6587 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6592 static void execSetupChooseGridYSize_0(void)
6594 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6599 static void execSetupChooseGridXSize_1(void)
6601 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6606 static void execSetupChooseGridYSize_1(void)
6608 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6613 static void execSetupConfigureVirtualButtons(void)
6615 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6617 ConfigureVirtualButtons();
6619 setup_mode = SETUP_MODE_TOUCH;
6624 static void execSetupTouch(void)
6628 if (touch_controls == NULL)
6630 for (i = 0; touch_controls_list[i].value != NULL; i++)
6632 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6633 char identifier[32], name[32];
6634 char *value = touch_controls_list[i].value;
6635 char *text = touch_controls_list[i].text;
6637 ti->node_top = &touch_controls;
6638 ti->sort_priority = i;
6640 sprintf(identifier, "%s", value);
6641 sprintf(name, "%s", text);
6643 setString(&ti->identifier, identifier);
6644 setString(&ti->name, name);
6645 setString(&ti->name_sorting, name);
6646 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6648 pushTreeInfo(&touch_controls, ti);
6651 // sort touch control values to start with lowest touch control value
6652 sortTreeInfo(&touch_controls);
6654 // set current touch control value to configured touch control value
6655 touch_control_current =
6656 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6658 // if that fails, set current touch control to reliable default value
6659 if (touch_control_current == NULL)
6660 touch_control_current =
6661 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6663 // if that also fails, set current touch control to first available value
6664 if (touch_control_current == NULL)
6665 touch_control_current = touch_controls;
6668 if (move_distances == NULL)
6670 for (i = 0; distances_list[i].value != -1; i++)
6672 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6673 char identifier[32], name[32];
6674 int value = distances_list[i].value;
6675 char *text = distances_list[i].text;
6677 ti->node_top = &move_distances;
6678 ti->sort_priority = value;
6680 sprintf(identifier, "%d", value);
6681 sprintf(name, "%s", text);
6683 setString(&ti->identifier, identifier);
6684 setString(&ti->name, name);
6685 setString(&ti->name_sorting, name);
6686 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6688 pushTreeInfo(&move_distances, ti);
6691 // sort distance values to start with lowest distance value
6692 sortTreeInfo(&move_distances);
6694 // set current distance value to configured distance value
6695 move_distance_current =
6696 getTreeInfoFromIdentifier(move_distances,
6697 i_to_a(setup.touch.move_distance));
6699 // if that fails, set current distance to reliable default value
6700 if (move_distance_current == NULL)
6701 move_distance_current =
6702 getTreeInfoFromIdentifier(move_distances,
6703 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6705 // if that also fails, set current distance to first available value
6706 if (move_distance_current == NULL)
6707 move_distance_current = move_distances;
6710 if (drop_distances == NULL)
6712 for (i = 0; distances_list[i].value != -1; i++)
6714 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6715 char identifier[32], name[32];
6716 int value = distances_list[i].value;
6717 char *text = distances_list[i].text;
6719 ti->node_top = &drop_distances;
6720 ti->sort_priority = value;
6722 sprintf(identifier, "%d", value);
6723 sprintf(name, "%s", text);
6725 setString(&ti->identifier, identifier);
6726 setString(&ti->name, name);
6727 setString(&ti->name_sorting, name);
6728 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6730 pushTreeInfo(&drop_distances, ti);
6733 // sort distance values to start with lowest distance value
6734 sortTreeInfo(&drop_distances);
6736 // set current distance value to configured distance value
6737 drop_distance_current =
6738 getTreeInfoFromIdentifier(drop_distances,
6739 i_to_a(setup.touch.drop_distance));
6741 // if that fails, set current distance to reliable default value
6742 if (drop_distance_current == NULL)
6743 drop_distance_current =
6744 getTreeInfoFromIdentifier(drop_distances,
6745 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6747 // if that also fails, set current distance to first available value
6748 if (drop_distance_current == NULL)
6749 drop_distance_current = drop_distances;
6752 if (transparencies == NULL)
6754 for (i = 0; transparencies_list[i].value != -1; i++)
6756 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6757 char identifier[32], name[32];
6758 int value = transparencies_list[i].value;
6759 char *text = transparencies_list[i].text;
6761 ti->node_top = &transparencies;
6762 ti->sort_priority = value;
6764 sprintf(identifier, "%d", value);
6765 sprintf(name, "%s", text);
6767 setString(&ti->identifier, identifier);
6768 setString(&ti->name, name);
6769 setString(&ti->name_sorting, name);
6770 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6772 pushTreeInfo(&transparencies, ti);
6775 // sort transparency values to start with lowest transparency value
6776 sortTreeInfo(&transparencies);
6778 // set current transparency value to configured transparency value
6779 transparency_current =
6780 getTreeInfoFromIdentifier(transparencies,
6781 i_to_a(setup.touch.transparency));
6783 // if that fails, set current transparency to reliable default value
6784 if (transparency_current == NULL)
6785 transparency_current =
6786 getTreeInfoFromIdentifier(transparencies,
6787 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6789 // if that also fails, set current transparency to first available value
6790 if (transparency_current == NULL)
6791 transparency_current = transparencies;
6794 for (i = 0; i < 2; i++)
6796 for (j = 0; j < 2; j++)
6798 if (grid_sizes[i][j] == NULL)
6800 for (k = 0; grid_sizes_list[k].value != -1; k++)
6802 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6803 char identifier[32], name[32];
6804 int value = grid_sizes_list[k].value;
6805 char *text = grid_sizes_list[k].text;
6807 ti->node_top = &grid_sizes[i][j];
6808 ti->sort_priority = value;
6810 sprintf(identifier, "%d", value);
6811 sprintf(name, "%s", text);
6813 setString(&ti->identifier, identifier);
6814 setString(&ti->name, name);
6815 setString(&ti->name_sorting, name);
6816 setString(&ti->infotext,
6819 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6820 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6822 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6823 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6825 pushTreeInfo(&grid_sizes[i][j], ti);
6828 // sort grid size values to start with lowest grid size value
6829 sortTreeInfo(&grid_sizes[i][j]);
6831 // set current grid size value to configured grid size value
6832 grid_size_current[i][j] =
6833 getTreeInfoFromIdentifier(grid_sizes[i][j],
6835 setup.touch.grid_xsize[i] :
6836 setup.touch.grid_ysize[i]));
6838 // if that fails, set current grid size to reliable default value
6839 if (grid_size_current[i][j] == NULL)
6840 grid_size_current[i][j] =
6841 getTreeInfoFromIdentifier(grid_sizes[i][j],
6843 DEFAULT_GRID_XSIZE(i) :
6844 DEFAULT_GRID_YSIZE(i)));
6846 // if that also fails, set current grid size to first available value
6847 if (grid_size_current[i][j] == NULL)
6848 grid_size_current[i][j] = grid_sizes[i][j];
6853 setup.touch.control_type = touch_control_current->identifier;
6854 setup.touch.move_distance = atoi(move_distance_current->identifier);
6855 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6856 setup.touch.transparency = atoi(transparency_current->identifier);
6858 for (i = 0; i < 2; i++)
6860 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6861 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6863 if (i == GRID_ACTIVE_NR())
6865 overlay.grid_xsize = setup.touch.grid_xsize[i];
6866 overlay.grid_ysize = setup.touch.grid_ysize[i];
6870 // needed for displaying value text instead of identifier
6871 touch_controls_text = touch_control_current->name;
6872 move_distance_text = move_distance_current->name;
6873 drop_distance_text = drop_distance_current->name;
6874 transparency_text = transparency_current->name;
6876 for (i = 0; i < 2; i++)
6877 for (j = 0; j < 2; j++)
6878 grid_size_text[i][j] = grid_size_current[i][j]->name;
6880 setup_mode = SETUP_MODE_TOUCH;
6885 static void execSetupArtwork(void)
6887 static ArtworkDirTree *gfx_last_valid = NULL;
6888 static ArtworkDirTree *snd_last_valid = NULL;
6889 static ArtworkDirTree *mus_last_valid = NULL;
6891 // current artwork directory may be invalid (level group, parent link)
6892 if (!validLevelSeries(artwork.gfx_current))
6893 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6894 if (!validLevelSeries(artwork.snd_current))
6895 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6896 if (!validLevelSeries(artwork.mus_current))
6897 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6899 // store valid artwork directory information
6900 gfx_last_valid = artwork.gfx_current;
6901 snd_last_valid = artwork.snd_current;
6902 mus_last_valid = artwork.mus_current;
6905 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6906 artwork.gfx_current->subdir,
6907 artwork.gfx_current->fullpath,
6908 artwork.gfx_current->basepath);
6911 setup.graphics_set = artwork.gfx_current->identifier;
6912 setup.sounds_set = artwork.snd_current->identifier;
6913 setup.music_set = artwork.mus_current->identifier;
6915 // needed if last screen (setup choice) changed graphics, sounds or music
6916 ReloadCustomArtwork(0);
6918 // needed for displaying artwork name instead of artwork identifier
6919 graphics_set_name = artwork.gfx_current->name;
6920 sounds_set_name = artwork.snd_current->name;
6921 music_set_name = artwork.mus_current->name;
6923 setup_mode = SETUP_MODE_ARTWORK;
6928 static void execSetupChooseGraphics(void)
6930 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6935 static void execSetupChooseSounds(void)
6937 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6942 static void execSetupChooseMusic(void)
6944 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6949 static void execSetupInput(void)
6951 setup_mode = SETUP_MODE_INPUT;
6956 static void execSetupShortcuts(void)
6958 setup_mode = SETUP_MODE_SHORTCUTS;
6963 static void execSetupShortcuts1(void)
6965 setup_mode = SETUP_MODE_SHORTCUTS_1;
6970 static void execSetupShortcuts2(void)
6972 setup_mode = SETUP_MODE_SHORTCUTS_2;
6977 static void execSetupShortcuts3(void)
6979 setup_mode = SETUP_MODE_SHORTCUTS_3;
6984 static void execSetupShortcuts4(void)
6986 setup_mode = SETUP_MODE_SHORTCUTS_4;
6991 static void execSetupShortcuts5(void)
6993 setup_mode = SETUP_MODE_SHORTCUTS_5;
6998 static void execExitSetup(void)
7000 SetGameStatus(GAME_MODE_MAIN);
7005 static void execSaveAndExitSetup(void)
7011 static void execGadgetNetworkServer(void)
7013 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7014 struct GadgetInfo *gi = screen_gadget[gadget_id];
7016 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7017 network_server_hostname[0] = '\0';
7019 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7023 ClickOnGadget(gi, MB_LEFTBUTTON);
7026 static void execOfferUploadTapes(void)
7031 static void ToggleNetworkModeIfNeeded(void)
7033 int font_title = FONT_TITLE_1;
7034 int font_foot = FC_BLUE;
7035 int ystart = mSY - SY + 16;
7036 int ybottom = mSY - SY + SYSIZE - 20;
7037 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7039 if (setup.network_mode == network.enabled)
7042 network.enabled = setup.network_mode;
7044 FadeOut(REDRAW_ALL);
7048 DrawTextSCentered(ystart, font_title, text);
7052 if (network.enabled)
7053 InitNetworkServer();
7055 DisconnectFromNetworkServer();
7057 DrawTextSCentered(ybottom, font_foot,
7058 "Press any key or button for setup menu");
7060 WaitForEventToContinue();
7065 static void ToggleGameSpeedsListIfNeeded(void)
7067 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7069 if (setup.game_speed_extended == using_game_speeds_extended)
7072 // try to match similar values when changing game speeds list
7073 if (setup.game_speed_extended)
7074 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7075 setup.game_frame_delay == 30 ? 29 :
7076 setup.game_frame_delay);
7078 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7079 setup.game_frame_delay == 16 ? 15 :
7080 setup.game_frame_delay >= 29 ? 30 :
7081 setup.game_frame_delay <= 10 ? 10 :
7082 setup.game_frame_delay);
7084 execSetupGame_setGameSpeeds(TRUE);
7089 static void ToggleUseApiServerIfNeeded(void)
7091 if (runtime.use_api_server == setup.use_api_server)
7094 runtime.use_api_server = setup.use_api_server;
7096 if (runtime.use_api_server)
7097 CheckApiServerTasks();
7100 static void ModifyGameSpeedIfNeeded(void)
7102 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7103 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7107 char *game_speed_text = "Fast";
7108 int game_speed_value = 15;
7110 if (setup.game_speed_extended)
7112 game_speed_text = "60 fps";
7113 game_speed_value = 16;
7116 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7118 // set game speed to existing list value that is fast enough for vsync
7119 setup.game_frame_delay = game_speed_value;
7121 execSetupGame_setGameSpeeds(TRUE);
7123 Request(message, REQ_CONFIRM);
7126 static void DisableVsyncIfNeeded(void)
7128 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7129 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7130 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7133 // disable vsync for the selected game speed to work
7134 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7136 execSetupGraphics_setVsyncModes(TRUE);
7138 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7144 void *related_value;
7145 } hide_related_entry_list[] =
7147 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7148 { &setup.scores_in_highscore_list, &scores_type_text },
7150 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7151 { &setup.game_frame_delay, &game_speed_text },
7153 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7154 { &setup.scroll_delay_value, &scroll_delay_text },
7156 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7157 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7159 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7160 { &setup.window_scaling_percent, &window_size_text },
7162 { &setup.window_scaling_quality, execSetupChooseScalingType },
7163 { &setup.window_scaling_quality, &scaling_type_text },
7165 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7166 { &setup.screen_rendering_mode, &rendering_mode_text },
7168 { &setup.vsync_mode, execSetupChooseVsyncMode },
7169 { &setup.vsync_mode, &vsync_mode_text },
7171 { &setup.graphics_set, execSetupChooseGraphics },
7172 { &setup.graphics_set, &graphics_set_name },
7174 { &setup.sounds_set, execSetupChooseSounds },
7175 { &setup.sounds_set, &sounds_set_name },
7177 { &setup.music_set, execSetupChooseMusic },
7178 { &setup.music_set, &music_set_name },
7180 { &setup.volume_simple, execSetupChooseVolumeSimple },
7181 { &setup.volume_simple, &volume_simple_text },
7183 { &setup.volume_loops, execSetupChooseVolumeLoops },
7184 { &setup.volume_loops, &volume_loops_text },
7186 { &setup.volume_music, execSetupChooseVolumeMusic },
7187 { &setup.volume_music, &volume_music_text },
7189 { &setup.touch.control_type, execSetupChooseTouchControls },
7190 { &setup.touch.control_type, &touch_controls_text },
7192 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7193 { &setup.touch.move_distance, &move_distance_text },
7195 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7196 { &setup.touch.drop_distance, &drop_distance_text },
7198 { &setup.touch.transparency, execSetupChooseTransparency },
7199 { &setup.touch.transparency, &transparency_text },
7201 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7202 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7204 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7205 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7207 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7208 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7210 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7211 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7213 { &setup.internal.menu_game, execSetupGame },
7214 { &setup.internal.menu_engines, execSetupEngines },
7215 { &setup.internal.menu_editor, execSetupEditor },
7216 { &setup.internal.menu_graphics, execSetupGraphics },
7217 { &setup.internal.menu_sound, execSetupSound },
7218 { &setup.internal.menu_artwork, execSetupArtwork },
7219 { &setup.internal.menu_input, execSetupInput },
7220 { &setup.internal.menu_touch, execSetupTouch },
7221 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7222 { &setup.internal.menu_exit, execExitSetup },
7223 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7225 { &setup.internal.info_title, execInfoTitleScreen },
7226 { &setup.internal.info_elements, execInfoElements },
7227 { &setup.internal.info_music, execInfoMusic },
7228 { &setup.internal.info_credits, execInfoCredits },
7229 { &setup.internal.info_program, execInfoProgram },
7230 { &setup.internal.info_version, execInfoVersion },
7231 { &setup.internal.info_levelset, execInfoLevelSet },
7232 { &setup.internal.info_exit, execExitInfo },
7237 void setHideRelatedSetupEntries(void)
7241 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7242 if (hideSetupEntry(hide_related_entry_list[i].value))
7243 setHideSetupEntry(hide_related_entry_list[i].related_value);
7246 static struct TokenInfo setup_info_main[] =
7248 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7249 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7250 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7251 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7252 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7253 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7254 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7255 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7256 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7257 { TYPE_EMPTY, NULL, "" },
7258 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7259 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7264 static struct TokenInfo setup_info_game[] =
7266 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7267 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7268 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7269 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7270 { TYPE_STRING, &network_server_text, "" },
7271 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7272 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7273 { TYPE_STRING, &scores_type_text, "" },
7274 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7275 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7276 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7277 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7278 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7279 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7280 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7281 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7282 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7283 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7284 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7285 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7286 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7287 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7288 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7289 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7290 { TYPE_STRING, &game_speed_text, "" },
7291 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7293 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7294 { TYPE_STRING, &scroll_delay_text, "" },
7296 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7297 { TYPE_STRING, &snapshot_mode_text, "" },
7298 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7299 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7300 { TYPE_EMPTY, NULL, "" },
7301 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7306 static struct TokenInfo setup_info_engines[] =
7308 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7309 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7310 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7311 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7312 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7313 { TYPE_EMPTY, NULL, "" },
7314 { TYPE_HEADLINE, NULL, "Supaplex" },
7315 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7316 { TYPE_EMPTY, NULL, "" },
7317 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7322 static struct TokenInfo setup_info_editor[] =
7325 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7326 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7327 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7328 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7329 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7330 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7331 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7332 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7333 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7334 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7336 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7337 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7339 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7341 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7342 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7343 { TYPE_EMPTY, NULL, "" },
7345 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7346 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7347 { TYPE_EMPTY, NULL, "" },
7349 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7350 { TYPE_EMPTY, NULL, "" },
7351 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7352 { TYPE_EMPTY, NULL, "" },
7353 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7358 static struct TokenInfo setup_info_graphics[] =
7360 #if !defined(PLATFORM_ANDROID)
7361 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7362 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7363 { TYPE_STRING, &window_size_text, "" },
7364 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7365 { TYPE_STRING, &scaling_type_text, "" },
7366 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7367 { TYPE_STRING, &rendering_mode_text, "" },
7370 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7371 { TYPE_STRING, &scroll_delay_text, "" },
7373 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7374 { TYPE_STRING, &vsync_mode_text, "" },
7375 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7376 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7377 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7378 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7379 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7380 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7381 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7382 { TYPE_EMPTY, NULL, "" },
7383 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7388 static struct TokenInfo setup_info_sound[] =
7390 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7391 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7392 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7393 { TYPE_EMPTY, NULL, "" },
7394 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7395 { TYPE_STRING, &volume_simple_text, "" },
7396 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7397 { TYPE_STRING, &volume_loops_text, "" },
7398 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7399 { TYPE_STRING, &volume_music_text, "" },
7400 { TYPE_EMPTY, NULL, "" },
7401 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7406 static struct TokenInfo setup_info_artwork[] =
7408 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7409 { TYPE_STRING, &graphics_set_name, "" },
7410 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7411 { TYPE_STRING, &sounds_set_name, "" },
7412 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7413 { TYPE_STRING, &music_set_name, "" },
7414 { TYPE_EMPTY, NULL, "" },
7415 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7416 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7417 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7418 { TYPE_EMPTY, NULL, "" },
7419 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7424 static struct TokenInfo setup_info_input[] =
7426 { TYPE_SWITCH, NULL, "Player:" },
7427 { TYPE_SWITCH, NULL, "Device:" },
7428 { TYPE_SWITCH, NULL, "" },
7429 { TYPE_SKIPPABLE, NULL, "" },
7430 { TYPE_EMPTY, NULL, "" },
7431 { TYPE_EMPTY, NULL, "" },
7432 { TYPE_EMPTY, NULL, "" },
7433 { TYPE_EMPTY, NULL, "" },
7434 { TYPE_EMPTY, NULL, "" },
7435 { TYPE_EMPTY, NULL, "" },
7436 { TYPE_EMPTY, NULL, "" },
7437 { TYPE_EMPTY, NULL, "" },
7438 { TYPE_SKIPPABLE, NULL, "" },
7439 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7444 static struct TokenInfo setup_info_touch[] =
7446 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7447 { TYPE_STRING, &touch_controls_text, "" },
7448 { TYPE_EMPTY, NULL, "" },
7449 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7454 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7456 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7457 { TYPE_STRING, &touch_controls_text, "" },
7458 { TYPE_EMPTY, NULL, "" },
7459 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7460 { TYPE_STRING, &grid_size_text[0][0], "" },
7461 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7462 { TYPE_STRING, &grid_size_text[0][1], "" },
7463 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7464 { TYPE_STRING, &transparency_text, "" },
7465 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7466 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7467 { TYPE_EMPTY, NULL, "" },
7468 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7469 { TYPE_EMPTY, NULL, "" },
7470 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7475 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7477 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7478 { TYPE_STRING, &touch_controls_text, "" },
7479 { TYPE_EMPTY, NULL, "" },
7480 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7481 { TYPE_STRING, &grid_size_text[1][0], "" },
7482 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7483 { TYPE_STRING, &grid_size_text[1][1], "" },
7484 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7485 { TYPE_STRING, &transparency_text, "" },
7486 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7487 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7488 { TYPE_EMPTY, NULL, "" },
7489 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7490 { TYPE_EMPTY, NULL, "" },
7491 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7496 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7498 setup_info_touch_virtual_buttons_0,
7499 setup_info_touch_virtual_buttons_1
7502 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7504 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7505 { TYPE_STRING, &touch_controls_text, "" },
7506 { TYPE_EMPTY, NULL, "" },
7507 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7508 { TYPE_STRING, &move_distance_text, "" },
7509 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7510 { TYPE_STRING, &drop_distance_text, "" },
7511 { TYPE_EMPTY, NULL, "" },
7512 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7517 static struct TokenInfo setup_info_shortcuts[] =
7519 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7520 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7521 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7522 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7523 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7524 { TYPE_EMPTY, NULL, "" },
7525 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7530 static struct TokenInfo setup_info_shortcuts_1[] =
7532 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7533 { TYPE_KEY, &setup.shortcut.save_game, "" },
7534 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7535 { TYPE_KEY, &setup.shortcut.load_game, "" },
7536 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7537 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7538 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7539 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7540 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7541 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7542 { TYPE_EMPTY, NULL, "" },
7543 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7544 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7545 { TYPE_EMPTY, NULL, "" },
7546 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7551 static struct TokenInfo setup_info_shortcuts_2[] =
7553 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7554 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7555 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7556 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7557 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7558 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7559 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7560 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7561 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7562 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7563 { TYPE_EMPTY, NULL, "" },
7564 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7569 static struct TokenInfo setup_info_shortcuts_3[] =
7571 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7572 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7573 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7574 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7575 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7576 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7577 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7578 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7579 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7580 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7581 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7582 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7583 { TYPE_EMPTY, NULL, "" },
7584 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7589 static struct TokenInfo setup_info_shortcuts_4[] =
7591 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7592 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7593 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7594 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7595 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7596 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7597 { TYPE_EMPTY, NULL, "" },
7598 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7603 static struct TokenInfo setup_info_shortcuts_5[] =
7605 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7606 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7607 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7608 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7609 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7610 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7611 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7612 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7613 { TYPE_EMPTY, NULL, "" },
7614 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7619 static Key getSetupKey(void)
7621 Key key = KSYM_UNDEFINED;
7622 boolean got_key_event = FALSE;
7624 while (!got_key_event)
7628 if (NextValidEvent(&event))
7632 case EVENT_KEYPRESS:
7634 key = GetEventKey((KeyEvent *)&event, TRUE);
7636 // press 'Escape' or 'Enter' to keep the existing key binding
7637 if (key == KSYM_Escape || key == KSYM_Return)
7638 key = KSYM_UNDEFINED; // keep old value
7640 got_key_event = TRUE;
7644 case EVENT_KEYRELEASE:
7645 key_joystick_mapping = 0;
7649 HandleOtherEvents(&event);
7660 static int getSetupValueFont(int type, void *value)
7662 if (type & TYPE_GHOSTED)
7663 return FONT_OPTION_OFF;
7664 else if (type & TYPE_KEY)
7665 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7666 else if (type & TYPE_STRING)
7667 return FONT_VALUE_2;
7668 else if (type & TYPE_ECS_AGA)
7669 return FONT_VALUE_1;
7670 else if (type & TYPE_BOOLEAN_STYLE)
7671 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7672 else if (type & TYPE_YES_NO_AUTO)
7673 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7674 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7675 else if (type & TYPE_PLAYER)
7676 return FONT_VALUE_1;
7678 return FONT_VALUE_1;
7681 static int getSetupValueFontNarrow(int type, int font_nr)
7683 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7684 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7685 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7689 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7691 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7692 struct TokenInfo *si = &setup_info[si_pos];
7693 boolean font_draw_xoffset_modified = FALSE;
7694 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7695 int font_draw_xoffset_old = -1;
7696 int xoffset = (scrollbar_needed ? -1 : 0);
7697 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7698 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7699 int xpos = menu_screen_value_xpos;
7700 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7701 int startx = mSX + xpos * 32;
7702 int starty = mSY + ypos * 32;
7703 int type = si->type;
7704 void *value = si->value;
7705 char *value_string = getSetupValue(type, value);
7706 int font_nr_default = getSetupValueFont(type, value);
7707 int font_width_default = getFontWidth(font_nr_default);
7708 int font_nr = font_nr_default;
7711 if (value_string == NULL)
7714 if (type & TYPE_KEY)
7716 xpos = MENU_SCREEN_START_XPOS;
7718 if (type & TYPE_QUERY)
7719 value_string = "<press key>";
7721 else if (type & TYPE_STRING)
7723 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7725 xpos = MENU_SCREEN_START_XPOS;
7727 if (strlen(value_string) > max_value_len)
7728 value_string[max_value_len] = '\0';
7730 else if (type & TYPE_YES_NO_AUTO)
7732 xpos = menu_screen_value_xpos - 1;
7734 else if (type & TYPE_PLAYER)
7736 int displayed_player_nr = *(int *)value + 1;
7738 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7741 startx = mSX + xpos * 32;
7742 starty = mSY + ypos * 32;
7744 // special check if right-side setup values moved left due to scrollbar
7745 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7747 int max_menu_text_length = 26; // maximum text length for classic menu
7748 int font_xoffset = getFontDrawOffsetX(font_nr);
7749 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7750 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7751 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7752 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7754 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7756 // when using narrow font, left-shifting text "auto" not needed
7757 if (type & TYPE_YES_NO_AUTO)
7761 startx = mSX + xpos * 32;
7763 font_nr = getSetupValueFontNarrow(type, font_nr);
7767 // downward compatibility correction for Juergen Bonhagen's menu settings
7768 if (setup_mode != SETUP_MODE_INPUT)
7770 int max_menu_text_length_big = (menu_screen_value_xpos -
7771 MENU_SCREEN_START_XPOS);
7772 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7773 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7774 int font1_xoffset = getFontDrawOffsetX(font_nr);
7775 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7776 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7777 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7778 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7779 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7780 boolean correct_font_draw_xoffset = FALSE;
7782 if (xpos == MENU_SCREEN_START_XPOS &&
7783 startx + font1_xoffset < text_startx + text_font_xoffset)
7784 correct_font_draw_xoffset = TRUE;
7786 if (xpos == menu_screen_value_xpos &&
7787 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7788 correct_font_draw_xoffset = TRUE;
7790 // check if setup value would overlap with setup text when printed
7791 // (this can happen for extreme/wrong values for font draw offset)
7792 if (correct_font_draw_xoffset)
7794 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7795 font_draw_xoffset_modified = TRUE;
7797 if (type & TYPE_KEY)
7798 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7799 else if (!(type & TYPE_STRING))
7800 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7801 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7805 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7806 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7808 DrawText(startx, starty, value_string, font_nr);
7810 if (type & TYPE_PLAYER)
7812 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7813 int player_nr = *(int *)value;
7814 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7815 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7816 int startx2 = startx + xoff;
7817 int starty2 = starty + yoff;
7819 if (DrawingOnBackground(startx2, starty2))
7820 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7822 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7823 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7826 if (font_draw_xoffset_modified)
7827 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7830 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7832 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7833 struct TokenInfo *si = &setup_info[si_pos];
7835 if (si->type & TYPE_BOOLEAN_STYLE)
7837 *(boolean *)si->value ^= TRUE;
7839 else if (si->type & TYPE_YES_NO_AUTO)
7843 (*(int *)si->value == AUTO ? TRUE :
7844 *(int *)si->value == TRUE ? FALSE : AUTO) :
7845 (*(int *)si->value == TRUE ? AUTO :
7846 *(int *)si->value == AUTO ? FALSE : TRUE));
7848 else if (si->type & TYPE_KEY)
7852 si->type |= TYPE_QUERY;
7853 drawSetupValue(screen_pos, setup_info_pos_raw);
7854 si->type &= ~TYPE_QUERY;
7856 key = getSetupKey();
7857 if (key != KSYM_UNDEFINED)
7858 *(Key *)si->value = key;
7860 else if (si->type & TYPE_PLAYER)
7862 int player_nr = *(int *)si->value;
7867 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7869 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7872 drawSetupValue(screen_pos, setup_info_pos_raw);
7874 // fullscreen state may have changed at this point
7875 if (si->value == &setup.fullscreen)
7876 ToggleFullscreenIfNeeded();
7878 // network mode may have changed at this point
7879 if (si->value == &setup.network_mode)
7880 ToggleNetworkModeIfNeeded();
7882 // API server mode may have changed at this point
7883 if (si->value == &setup.use_api_server)
7884 ToggleUseApiServerIfNeeded();
7886 // game speed list may have changed at this point
7887 if (si->value == &setup.game_speed_extended)
7888 ToggleGameSpeedsListIfNeeded();
7891 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7893 static struct TokenInfo *setup_info_final = NULL;
7898 // determine maximum list size of target list
7899 while (setup_info_orig[list_size++].type != 0);
7901 // free, allocate and clear memory for target list
7902 checked_free(setup_info_final);
7903 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7905 // copy setup info list without setup entries marked as hidden
7906 for (i = 0; setup_info_orig[i].type != 0; i++)
7908 // skip setup entries configured to be hidden
7909 if (hideSetupEntry(setup_info_orig[i].value))
7912 // skip skippable setup entries if screen is lower than usual
7913 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7914 setup_info_orig[i].type == TYPE_SKIPPABLE)
7917 setup_info_final[list_pos++] = setup_info_orig[i];
7920 return setup_info_final;
7923 static void DrawSetupScreen_Generic(void)
7925 int fade_mask = REDRAW_FIELD;
7926 boolean redraw_all = FALSE;
7927 char *title_string = NULL;
7931 fade_mask = REDRAW_ALL;
7934 FadeMenuSoundsAndMusic();
7936 FreeScreenGadgets();
7937 CreateScreenGadgets();
7939 if (redraw_mask & REDRAW_ALL)
7944 // needed if different viewport properties defined for setup screen
7945 ChangeViewportPropertiesIfNeeded();
7947 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7951 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7953 if (setup_mode == SETUP_MODE_MAIN)
7955 setup_info = setup_info_main;
7956 title_string = STR_SETUP_MAIN;
7958 else if (setup_mode == SETUP_MODE_GAME)
7960 setup_info = setup_info_game;
7961 title_string = STR_SETUP_GAME;
7963 else if (setup_mode == SETUP_MODE_ENGINES)
7965 setup_info = setup_info_engines;
7966 title_string = STR_SETUP_ENGINES;
7968 else if (setup_mode == SETUP_MODE_EDITOR)
7970 setup_info = setup_info_editor;
7971 title_string = STR_SETUP_EDITOR;
7973 else if (setup_mode == SETUP_MODE_GRAPHICS)
7975 setup_info = setup_info_graphics;
7976 title_string = STR_SETUP_GRAPHICS;
7978 else if (setup_mode == SETUP_MODE_SOUND)
7980 setup_info = setup_info_sound;
7981 title_string = STR_SETUP_SOUND;
7983 else if (setup_mode == SETUP_MODE_ARTWORK)
7985 setup_info = setup_info_artwork;
7986 title_string = STR_SETUP_ARTWORK;
7988 else if (setup_mode == SETUP_MODE_TOUCH)
7990 setup_info = setup_info_touch;
7991 title_string = STR_SETUP_TOUCH;
7993 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7994 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7995 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7996 setup_info = setup_info_touch_wipe_gestures;
7998 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8000 setup_info = setup_info_shortcuts;
8001 title_string = STR_SETUP_SHORTCUTS;
8003 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8005 setup_info = setup_info_shortcuts_1;
8006 title_string = STR_SETUP_SHORTCUTS;
8008 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8010 setup_info = setup_info_shortcuts_2;
8011 title_string = STR_SETUP_SHORTCUTS;
8013 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8015 setup_info = setup_info_shortcuts_3;
8016 title_string = STR_SETUP_SHORTCUTS;
8018 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8020 setup_info = setup_info_shortcuts_4;
8021 title_string = STR_SETUP_SHORTCUTS;
8023 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8025 setup_info = setup_info_shortcuts_5;
8026 title_string = STR_SETUP_SHORTCUTS;
8029 // use modified setup info without setup entries marked as hidden
8030 setup_info = getSetupInfoFinal(setup_info);
8032 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8034 // determine maximal number of setup entries that can be displayed on screen
8036 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8039 // determine maximal number of setup entries available for this setup screen
8041 for (i = 0; setup_info[i].type != 0; i++)
8044 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8046 MapScreenGadgets(max_setup_info);
8049 redraw_mask = fade_mask = REDRAW_ALL;
8051 DrawMaskedBorder(fade_mask);
8056 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8058 menu_info = setup_info;
8060 HandleMenuScreen(mx, my, dx, dy, button,
8061 setup_mode, num_setup_info, max_setup_info);
8064 static void DrawSetupScreen_Input(void)
8068 FadeOut(REDRAW_FIELD);
8072 setup_info = getSetupInfoFinal(setup_info_input);
8074 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8076 for (i = 0; setup_info[i].type != 0; i++)
8078 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8079 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8080 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8081 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8082 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8083 initCursor(i, IMG_MENU_BUTTON);
8085 DrawCursorAndText_Setup(i, -1, FALSE);
8088 // create gadgets for setup input menu screen
8089 FreeScreenGadgets();
8090 CreateScreenGadgets();
8092 // map gadgets for setup input menu screen
8093 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8095 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8097 FadeIn(REDRAW_FIELD);
8100 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8102 if (device_name == NULL)
8105 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8108 if (strlen(device_name) > 1)
8110 char c1 = device_name[strlen(device_name) - 1];
8111 char c2 = device_name[strlen(device_name) - 2];
8113 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8114 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8117 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8118 strlen(device_name));
8121 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8124 static struct SetupKeyboardInfo custom_key;
8131 { &custom_key.left, "Axis/Pad Left" },
8132 { &custom_key.right, "Axis/Pad Right" },
8133 { &custom_key.up, "Axis/Pad Up" },
8134 { &custom_key.down, "Axis/Pad Down" },
8135 { &custom_key.snap, "Button 1/A/X" },
8136 { &custom_key.drop, "Button 2/B/Y" }
8138 static char *joystick_name[MAX_PLAYERS] =
8145 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8146 int font_nr_info = FONT_MENU_1;
8147 int font_nr_name = FONT_VALUE_OLD;
8148 int font_nr_on = FONT_VALUE_1;
8149 int font_nr_off = FONT_VALUE_OLD;
8152 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8154 font_nr_info = FONT_MENU_2;
8155 font_nr_on = FONT_VALUE_NARROW;
8156 font_nr_off = FONT_VALUE_OLD_NARROW;
8159 custom_key = setup.input[player_nr].key;
8161 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8162 FONT_INPUT_1_ACTIVE);
8164 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8166 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8167 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8169 if (setup.input[player_nr].use_joystick)
8171 char *device_name = setup.input[player_nr].joy.device_name;
8172 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8173 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8174 char *text = joystick_name[joystick_nr];
8175 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8177 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8178 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8182 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8183 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8186 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8187 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8191 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8192 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8193 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8194 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8196 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8197 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8198 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8199 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8200 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8201 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8203 for (i = 0; i < 6; i++)
8205 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8207 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8209 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8210 (setup.input[player_nr].use_joystick ?
8212 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8216 static int input_player_nr = 0;
8218 static void HandleSetupScreen_Input_Player(int step, int direction)
8220 int old_player_nr = input_player_nr;
8223 new_player_nr = old_player_nr + step * direction;
8224 if (new_player_nr < 0)
8226 if (new_player_nr > MAX_PLAYERS - 1)
8227 new_player_nr = MAX_PLAYERS - 1;
8229 if (new_player_nr != old_player_nr)
8231 input_player_nr = new_player_nr;
8233 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8237 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8239 static int choice = 0;
8242 int pos_start = SETUPINPUT_SCREEN_POS_START;
8243 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8244 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8245 int pos_end = SETUPINPUT_SCREEN_POS_END;
8247 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8251 for (i = 0; setup_info_input[i].type != 0; i++)
8253 // adjust menu structure according to skipped setup entries
8254 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8262 if (button == MB_MENU_INITIALIZE)
8264 // input setup menu may have changed size due to graphics configuration
8265 if (choice >= pos_empty1)
8268 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8270 DrawCursorAndText_Setup(choice, -1, TRUE);
8274 else if (button == MB_MENU_LEAVE)
8276 setup_mode = SETUP_MODE_MAIN;
8283 if (mx || my) // mouse input
8285 x = (mx - mSX) / 32;
8286 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8288 else if (dx || dy) // keyboard input
8290 if (dx && choice == 0)
8291 x = (dx < 0 ? 10 : 12);
8292 else if ((dx && choice == 1) ||
8293 (dx == -1 && choice == pos_end))
8294 button = MB_MENU_CHOICE;
8298 if (y >= pos_empty1 && y <= pos_empty2)
8299 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8302 if (y == 0 && dx != 0 && button)
8304 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8306 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8307 y >= pos_start && y <= pos_end &&
8308 !(y >= pos_empty1 && y <= pos_empty2))
8314 DrawCursorAndText_Setup(choice, -1, FALSE);
8315 DrawCursorAndText_Setup(y, -1, TRUE);
8317 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8326 char *device_name = setup.input[input_player_nr].joy.device_name;
8328 if (!setup.input[input_player_nr].use_joystick)
8330 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8332 setJoystickDeviceToNr(device_name, new_device_nr);
8333 setup.input[input_player_nr].use_joystick = TRUE;
8337 int device_nr = getJoystickNrFromDeviceName(device_name);
8338 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8340 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8341 setup.input[input_player_nr].use_joystick = FALSE;
8343 setJoystickDeviceToNr(device_name, new_device_nr);
8346 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8350 if (setup.input[input_player_nr].use_joystick)
8351 ConfigureJoystick(input_player_nr);
8353 CustomizeKeyboard(input_player_nr);
8355 else if (y == pos_end)
8361 setup_mode = SETUP_MODE_MAIN;
8368 static boolean CustomizeKeyboardMain(int player_nr)
8372 boolean finished = FALSE;
8373 static struct SetupKeyboardInfo custom_key;
8378 } customize_step[] =
8380 { &custom_key.left, "Move Left" },
8381 { &custom_key.right, "Move Right" },
8382 { &custom_key.up, "Move Up" },
8383 { &custom_key.down, "Move Down" },
8384 { &custom_key.snap, "Snap Field" },
8385 { &custom_key.drop, "Drop Element" }
8387 int font_nr_old = FONT_VALUE_OLD;
8388 int font_nr_new = FONT_VALUE_1;
8389 boolean success = FALSE;
8391 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8393 font_nr_old = FONT_VALUE_OLD_NARROW;
8394 font_nr_new = FONT_VALUE_NARROW;
8397 // read existing key bindings from player setup
8398 custom_key = setup.input[player_nr].key;
8401 FadeOut(REDRAW_FIELD);
8405 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8408 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8409 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8410 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8411 "Key:", FONT_INPUT_1_ACTIVE);
8412 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8413 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8415 FadeIn(REDRAW_FIELD);
8421 if (NextValidEvent(&event))
8425 case EVENT_KEYPRESS:
8427 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8429 // press 'Escape' to abort and keep the old key bindings
8430 if (key == KSYM_Escape)
8432 FadeSkipNextFadeIn();
8439 // press 'Enter' to keep the existing key binding
8440 if (key == KSYM_Return)
8441 key = *customize_step[step_nr].key;
8443 // check if key already used
8444 for (i = 0; i < step_nr; i++)
8445 if (*customize_step[i].key == key)
8450 // got new key binding
8451 *customize_step[step_nr].key = key;
8452 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8454 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8455 getKeyNameFromKey(key), font_nr_new);
8458 // un-highlight last query
8459 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8460 customize_step[step_nr - 1].text, FONT_MENU_1);
8461 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8462 "Key:", FONT_MENU_1);
8464 // all keys configured
8473 // query next key binding
8474 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8475 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8476 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8477 "Key:", FONT_INPUT_1_ACTIVE);
8478 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8479 getKeyNameFromKey(*customize_step[step_nr].key),
8484 case EVENT_KEYRELEASE:
8485 key_joystick_mapping = 0;
8489 HandleOtherEvents(&event);
8497 // write new key bindings back to player setup, if successfully finished
8499 setup.input[player_nr].key = custom_key;
8504 void CustomizeKeyboard(int player_nr)
8506 boolean success = CustomizeKeyboardMain(player_nr);
8510 int font_nr = FONT_TITLE_1;
8511 int font_height = getFontHeight(font_nr);
8512 int ypos1 = SYSIZE / 2 - font_height * 2;
8513 int ypos2 = SYSIZE / 2 - font_height * 1;
8514 unsigned int wait_frame_delay = 0;
8515 unsigned int wait_frame_delay_value = 2000;
8517 ResetDelayCounter(&wait_frame_delay);
8521 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8522 DrawTextSCentered(ypos2, font_nr, "configured!");
8524 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8530 DrawSetupScreen_Input();
8533 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8535 #define MARKER_BUTTON 1
8536 #define MARKER_AXIS_X 2
8537 #define MARKER_AXIS_Y 3
8539 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8541 static boolean bitmaps_initialized = FALSE;
8542 boolean screen_initialized = FALSE;
8543 static Bitmap *controller, *button, *axis_x, *axis_y;
8545 boolean success = TRUE;
8546 boolean done = FALSE, next = FALSE;
8548 int alpha = 200, alpha_step = -1;
8549 int alpha_ticks = 0;
8550 char mapping[4096], temp[256];
8551 int font_name = MENU_SETUP_FONT_TITLE;
8552 int font_info = MENU_SETUP_FONT_TEXT;
8553 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8554 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8555 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8556 int ystep_name = getMenuTextStep(spacing_name, font_name);
8557 int ystep_line = getMenuTextStep(spacing_line, font_info);
8558 int ystep_para = getMenuTextStep(spacing_para, font_info);
8566 int axis, button, hat, hat_value;
8569 *step, *prev_step, steps[] =
8571 { 356, 155, MARKER_BUTTON, "a", },
8572 { 396, 122, MARKER_BUTTON, "b", },
8573 { 320, 125, MARKER_BUTTON, "x", },
8574 { 358, 95, MARKER_BUTTON, "y", },
8575 { 162, 125, MARKER_BUTTON, "back", },
8576 { 216, 125, MARKER_BUTTON, "guide", },
8577 { 271, 125, MARKER_BUTTON, "start", },
8578 { 110, 200, MARKER_BUTTON, "dpleft", },
8579 { 146, 228, MARKER_BUTTON, "dpdown", },
8580 { 178, 200, MARKER_BUTTON, "dpright", },
8581 { 146, 172, MARKER_BUTTON, "dpup", },
8582 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8583 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8584 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8585 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8586 { 73, 141, MARKER_BUTTON, "leftstick", },
8587 { 282, 210, MARKER_BUTTON, "rightstick", },
8588 { 73, 141, MARKER_AXIS_X, "leftx", },
8589 { 73, 141, MARKER_AXIS_Y, "lefty", },
8590 { 282, 210, MARKER_AXIS_X, "rightx", },
8591 { 282, 210, MARKER_AXIS_Y, "righty", },
8594 unsigned int event_frame_delay = 0;
8595 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8597 ResetDelayCounter(&event_frame_delay);
8599 if (!bitmaps_initialized)
8601 controller = LoadCustomImage("joystick/controller.png");
8602 button = LoadCustomImage("joystick/button.png");
8603 axis_x = LoadCustomImage("joystick/axis_x.png");
8604 axis_y = LoadCustomImage("joystick/axis_y.png");
8606 bitmaps_initialized = TRUE;
8609 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8612 // print info about the joystick we are watching
8613 Debug("joystick", "watching joystick %d: (%s)",
8614 SDL_JoystickInstanceID(joystick), name);
8615 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8616 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8617 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8620 // initialize mapping with GUID and name
8621 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8623 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8624 temp, name, SDL_GetPlatform());
8626 // loop through all steps (buttons and axes), getting joystick events
8627 for (i = 0; i < SDL_arraysize(steps) && !done;)
8629 Bitmap *marker = button; // initialize with reliable default value
8632 strcpy(step->mapping, mapping);
8636 step->hat_value = -1;
8638 marker = (step->marker == MARKER_BUTTON ? button :
8639 step->marker == MARKER_AXIS_X ? axis_x :
8640 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8644 while (!done && !next)
8646 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8647 alpha_ticks = SDL_GetTicks();
8654 else if (alpha < 128)
8660 int controller_x = SX + (SXSIZE - controller->width) / 2;
8661 int controller_y = SY + ystep_line;
8663 int marker_x = controller_x + step->x;
8664 int marker_y = controller_y + step->y;
8666 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8667 int ystart2 = ystart1 + ystep_name + ystep_line;
8671 DrawTextSCentered(ystart1, font_name, name);
8673 DrawTextSCentered(ystart2, font_info,
8674 "Press buttons and move axes on");
8675 ystart2 += ystep_line;
8676 DrawTextSCentered(ystart2, font_info,
8677 "your controller when indicated.");
8678 ystart2 += ystep_line;
8679 DrawTextSCentered(ystart2, font_info,
8680 "(Your controller may look different.)");
8681 ystart2 += ystep_para;
8683 #if defined(PLATFORM_ANDROID)
8684 DrawTextSCentered(ystart2, font_info,
8685 "To correct a mistake,");
8686 ystart2 += ystep_line;
8687 DrawTextSCentered(ystart2, font_info,
8688 "press the 'back' button.");
8689 ystart2 += ystep_line;
8690 DrawTextSCentered(ystart2, font_info,
8691 "To skip a button or axis,");
8692 ystart2 += ystep_line;
8693 DrawTextSCentered(ystart2, font_info,
8694 "press the 'menu' button.");
8696 DrawTextSCentered(ystart2, font_info,
8697 "To correct a mistake,");
8698 ystart2 += ystep_line;
8699 DrawTextSCentered(ystart2, font_info,
8700 "press the 'backspace' key.");
8701 ystart2 += ystep_line;
8702 DrawTextSCentered(ystart2, font_info,
8703 "To skip a button or axis,");
8704 ystart2 += ystep_line;
8705 DrawTextSCentered(ystart2, font_info,
8706 "press the 'return' key.");
8707 ystart2 += ystep_line;
8708 DrawTextSCentered(ystart2, font_info,
8709 "To exit, press the 'escape' key.");
8712 BlitBitmapMasked(controller, drawto, 0, 0,
8713 controller->width, controller->height,
8714 controller_x, controller_y);
8716 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8717 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8719 BlitBitmapMasked(marker, drawto, 0, 0,
8720 marker->width, marker->height,
8721 marker_x, marker_y);
8723 if (!screen_initialized)
8724 FadeIn(REDRAW_FIELD);
8728 screen_initialized = TRUE;
8730 while (NextValidEvent(&event))
8734 case SDL_JOYAXISMOTION:
8735 if (event.jaxis.value > 20000 ||
8736 event.jaxis.value < -20000)
8738 for (j = 0; j < i; j++)
8739 if (steps[j].axis == event.jaxis.axis)
8744 if (step->marker != MARKER_AXIS_X &&
8745 step->marker != MARKER_AXIS_Y)
8748 step->axis = event.jaxis.axis;
8749 strcat(mapping, step->field);
8750 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8751 strcat(mapping, temp);
8759 case SDL_JOYHATMOTION:
8760 // ignore centering; we're probably just coming back
8761 // to the center from the previous item we set
8762 if (event.jhat.value == SDL_HAT_CENTERED)
8765 for (j = 0; j < i; j++)
8766 if (steps[j].hat == event.jhat.hat &&
8767 steps[j].hat_value == event.jhat.value)
8772 step->hat = event.jhat.hat;
8773 step->hat_value = event.jhat.value;
8774 strcat(mapping, step->field);
8775 snprintf(temp, sizeof(temp), ":h%u.%u,",
8776 event.jhat.hat, event.jhat.value );
8777 strcat(mapping, temp);
8784 case SDL_JOYBALLMOTION:
8787 case SDL_JOYBUTTONUP:
8788 for (j = 0; j < i; j++)
8789 if (steps[j].button == event.jbutton.button)
8794 step->button = event.jbutton.button;
8795 strcat(mapping, step->field);
8796 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8797 strcat(mapping, temp);
8804 case SDL_FINGERDOWN:
8805 case SDL_MOUSEBUTTONDOWN:
8813 if (event.key.keysym.sym == KSYM_BackSpace ||
8814 event.key.keysym.sym == KSYM_Back)
8826 prev_step = &steps[i - 1];
8827 strcpy(mapping, prev_step->mapping);
8834 if (event.key.keysym.sym == KSYM_space ||
8835 event.key.keysym.sym == KSYM_Return ||
8836 event.key.keysym.sym == KSYM_Menu)
8845 if (event.key.keysym.sym == KSYM_Escape)
8855 program.exit_function(0);
8862 // do not handle events for longer than standard frame delay period
8863 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8872 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8875 // activate mapping for this game
8876 SDL_GameControllerAddMapping(mapping);
8878 // save mapping to personal mappings
8879 SaveSetup_AddGameControllerMapping(mapping);
8882 // wait until the last pending event was removed from event queue
8883 while (NextValidEvent(&event));
8888 static int ConfigureJoystickMain(int player_nr)
8890 char *device_name = setup.input[player_nr].joy.device_name;
8891 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8892 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8893 int success = FALSE;
8896 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8897 return JOYSTICK_NOT_AVAILABLE;
8899 if (!joystick_active || !setup.input[player_nr].use_joystick)
8900 return JOYSTICK_NOT_AVAILABLE;
8903 FadeOut(REDRAW_FIELD);
8905 // close all joystick devices (potentially opened as game controllers)
8906 for (i = 0; i < SDL_NumJoysticks(); i++)
8907 SDLCloseJoystick(i);
8909 // open joystick device as plain joystick to configure as game controller
8910 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8912 // as the joystick was successfully opened before, this should not happen
8913 if (joystick == NULL)
8916 // create new game controller mapping (buttons and axes) for joystick device
8917 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8919 // close joystick (and maybe re-open as configured game controller later)
8920 SDL_JoystickClose(joystick);
8922 // re-open all joystick devices (potentially as game controllers)
8923 for (i = 0; i < SDL_NumJoysticks(); i++)
8926 // clear all joystick input actions for all joystick devices
8927 SDLClearJoystickState();
8929 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8932 void ConfigureJoystick(int player_nr)
8934 boolean state = ConfigureJoystickMain(player_nr);
8936 if (state != JOYSTICK_NOT_CONFIGURED)
8938 boolean success = (state == JOYSTICK_CONFIGURED);
8939 char message1[MAX_OUTPUT_LINESIZE + 1];
8940 char *message2 = (success ? "configured!" : "not available!");
8941 char *device_name = setup.input[player_nr].joy.device_name;
8942 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8943 int font_nr = FONT_TITLE_1;
8944 int font_height = getFontHeight(font_nr);
8945 int ypos1 = SYSIZE / 2 - font_height * 2;
8946 int ypos2 = SYSIZE / 2 - font_height * 1;
8947 unsigned int wait_frame_delay = 0;
8948 unsigned int wait_frame_delay_value = 2000;
8950 ResetDelayCounter(&wait_frame_delay);
8954 sprintf(message1, "Joystick %d", nr);
8956 DrawTextSCentered(ypos1, font_nr, message1);
8957 DrawTextSCentered(ypos2, font_nr, message2);
8959 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8965 DrawSetupScreen_Input();
8968 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8970 if (y < video.screen_height / 3)
8972 // remap touch gadgets to access upper part of the screen
8973 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8974 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8976 else if (y > 2 * video.screen_height / 3)
8978 // remap touch gadgets to access lower part of the screen
8979 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8980 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8984 static boolean ConfigureVirtualButtonsMain(void)
8986 static char *customize_step_text[] =
8995 char grid_button[] =
8997 CHAR_GRID_BUTTON_LEFT,
8998 CHAR_GRID_BUTTON_RIGHT,
8999 CHAR_GRID_BUTTON_UP,
9000 CHAR_GRID_BUTTON_DOWN,
9001 CHAR_GRID_BUTTON_SNAP,
9002 CHAR_GRID_BUTTON_DROP
9011 int font_nr = FONT_INPUT_1_ACTIVE;
9012 int font_height = getFontHeight(font_nr);
9013 int ypos1 = SYSIZE / 2 - font_height * 2;
9014 int ypos2 = SYSIZE / 2 - font_height * 1;
9015 boolean success = FALSE;
9016 boolean finished = FALSE;
9018 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9019 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9020 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9021 boolean set_grid_button = FALSE;
9022 int nr = GRID_ACTIVE_NR();
9025 for (x = 0; x < MAX_GRID_XSIZE; x++)
9026 for (y = 0; y < MAX_GRID_YSIZE; y++)
9027 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9029 overlay.grid_button_highlight = grid_button[step_nr];
9034 FadeOut(REDRAW_FIELD);
9038 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9039 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9040 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9042 FadeIn(REDRAW_FIELD);
9044 SetOverlayShowGrid(TRUE);
9046 // map gadgets for setup touch buttons menu screen
9047 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9053 while (NextValidEvent(&event))
9055 int action = ACTION_NONE;
9057 // ---------- handle events and set the resulting action ----------
9063 UserEvent *user = (UserEvent *)&event;
9064 int id = user->value1;
9066 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9067 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9068 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9069 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9074 case EVENT_KEYPRESS:
9076 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9078 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9079 key == KSYM_BackSpace ||
9080 key == KSYM_Back ? ACTION_BACK :
9081 key == KSYM_Return ||
9083 key == KSYM_space ? ACTION_NEXT :
9088 case EVENT_KEYRELEASE:
9089 key_joystick_mapping = 0;
9092 case EVENT_BUTTONPRESS:
9093 case EVENT_BUTTONRELEASE:
9095 ButtonEvent *button = (ButtonEvent *)&event;
9097 motion_status = FALSE;
9099 if (button->type == EVENT_BUTTONPRESS)
9100 button_status = button->button;
9102 button_status = MB_RELEASED;
9104 if (HandleGadgets(button->x, button->y, button_status))
9106 // do not handle this button event anymore
9110 button->x += video.screen_xoffset;
9111 button->y += video.screen_yoffset;
9113 x = button->x * overlay.grid_xsize / video.screen_width;
9114 y = button->y * overlay.grid_ysize / video.screen_height;
9116 if (button->type == EVENT_BUTTONPRESS)
9119 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9120 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9122 set_grid_button = TRUE;
9125 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9129 case EVENT_MOTIONNOTIFY:
9131 MotionEvent *motion = (MotionEvent *)&event;
9133 motion_status = TRUE;
9135 if (HandleGadgets(motion->x, motion->y, button_status))
9137 // do not handle this button event anymore
9141 motion->x += video.screen_xoffset;
9142 motion->y += video.screen_yoffset;
9144 x = motion->x * overlay.grid_xsize / video.screen_width;
9145 y = motion->y * overlay.grid_ysize / video.screen_height;
9147 set_grid_button = TRUE;
9149 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9153 case SDL_WINDOWEVENT:
9154 HandleWindowEvent((WindowEvent *) &event);
9156 // check if device has been rotated
9157 if (nr != GRID_ACTIVE_NR())
9159 nr = GRID_ACTIVE_NR();
9161 for (x = 0; x < MAX_GRID_XSIZE; x++)
9162 for (y = 0; y < MAX_GRID_YSIZE; y++)
9163 grid_button_old[x][y] = grid_button_tmp[x][y] =
9164 overlay.grid_button[x][y];
9169 case SDL_APP_WILLENTERBACKGROUND:
9170 case SDL_APP_DIDENTERBACKGROUND:
9171 case SDL_APP_WILLENTERFOREGROUND:
9172 case SDL_APP_DIDENTERFOREGROUND:
9173 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9177 HandleOtherEvents(&event);
9181 // ---------- perform action set by handling events ----------
9183 if (action == ACTION_ESCAPE)
9185 // abort and restore the old key bindings
9187 for (x = 0; x < MAX_GRID_XSIZE; x++)
9188 for (y = 0; y < MAX_GRID_YSIZE; y++)
9189 overlay.grid_button[x][y] = grid_button_old[x][y];
9191 FadeSkipNextFadeIn();
9195 else if (action == ACTION_BACK)
9197 // keep the configured key bindings and go to previous page
9203 FadeSkipNextFadeIn();
9208 else if (action == ACTION_NEXT)
9210 // keep the configured key bindings and go to next page
9214 // all virtual buttons configured
9222 if (action != ACTION_NONE && !finished)
9224 for (x = 0; x < MAX_GRID_XSIZE; x++)
9225 for (y = 0; y < MAX_GRID_YSIZE; y++)
9226 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9228 overlay.grid_button_highlight = grid_button[step_nr];
9230 // configure next virtual button
9234 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9235 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9236 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9239 if (set_grid_button)
9241 overlay.grid_button[x][y] =
9242 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9243 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9244 grid_button_tmp[x][y]);
9246 set_grid_button = FALSE;
9253 for (x = 0; x < MAX_GRID_XSIZE; x++)
9254 for (y = 0; y < MAX_GRID_YSIZE; y++)
9255 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9257 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9259 SetOverlayShowGrid(FALSE);
9264 void ConfigureVirtualButtons(void)
9266 boolean success = ConfigureVirtualButtonsMain();
9268 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9269 SCREEN_MASK_TOUCH2);
9273 int font_nr = FONT_TITLE_1;
9274 int font_height = getFontHeight(font_nr);
9275 int ypos1 = SYSIZE / 2 - font_height * 2;
9276 int ypos2 = SYSIZE / 2 - font_height * 1;
9277 unsigned int wait_frame_delay = 0;
9278 unsigned int wait_frame_delay_value = 2000;
9280 ResetDelayCounter(&wait_frame_delay);
9284 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9285 DrawTextSCentered(ypos2, font_nr, "configured!");
9287 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9294 void DrawSetupScreen(void)
9299 if (setup_mode == SETUP_MODE_INPUT)
9300 DrawSetupScreen_Input();
9301 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9302 DrawChooseTree(&scores_type_current);
9303 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9304 DrawChooseTree(&game_speed_current);
9305 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9306 DrawChooseTree(&scroll_delay_current);
9307 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9308 DrawChooseTree(&snapshot_mode_current);
9309 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9310 DrawChooseTree(&window_size_current);
9311 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9312 DrawChooseTree(&scaling_type_current);
9313 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9314 DrawChooseTree(&rendering_mode_current);
9315 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9316 DrawChooseTree(&vsync_mode_current);
9317 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9318 DrawChooseTree(&artwork.gfx_current);
9319 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9320 DrawChooseTree(&artwork.snd_current);
9321 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9322 DrawChooseTree(&artwork.mus_current);
9323 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9324 DrawChooseTree(&volume_simple_current);
9325 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9326 DrawChooseTree(&volume_loops_current);
9327 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9328 DrawChooseTree(&volume_music_current);
9329 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9330 DrawChooseTree(&touch_control_current);
9331 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9332 DrawChooseTree(&move_distance_current);
9333 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9334 DrawChooseTree(&drop_distance_current);
9335 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9336 DrawChooseTree(&transparency_current);
9337 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9338 DrawChooseTree(&grid_size_current[0][0]);
9339 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9340 DrawChooseTree(&grid_size_current[0][1]);
9341 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9342 DrawChooseTree(&grid_size_current[1][0]);
9343 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9344 DrawChooseTree(&grid_size_current[1][1]);
9346 DrawSetupScreen_Generic();
9348 PlayMenuSoundsAndMusic();
9351 void RedrawSetupScreenAfterFullscreenToggle(void)
9353 if (setup_mode == SETUP_MODE_GRAPHICS ||
9354 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9356 // update list selection from "setup.window_scaling_percent"
9357 execSetupGraphics_setWindowSizes(TRUE);
9363 void RedrawSetupScreenAfterScreenRotation(int nr)
9367 if (setup_mode == SETUP_MODE_TOUCH)
9369 // update virtual button settings (depending on screen orientation)
9372 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9374 // save already configured virtual buttons
9375 for (x = 0; x < MAX_GRID_XSIZE; x++)
9376 for (y = 0; y < MAX_GRID_YSIZE; y++)
9377 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9381 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9383 if (setup_mode == SETUP_MODE_INPUT)
9384 HandleSetupScreen_Input(mx, my, dx, dy, button);
9385 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9386 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9387 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9388 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9389 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9390 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9391 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9392 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9393 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9394 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9395 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9396 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9397 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9398 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9399 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9400 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9401 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9402 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9403 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9404 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9405 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9406 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9407 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9408 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9409 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9410 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9411 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9412 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9413 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9414 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9415 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9416 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9417 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9418 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9419 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9420 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9421 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9422 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9423 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9424 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9425 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9426 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9427 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9428 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9430 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9433 void HandleGameActions(void)
9435 if (setup.ask_on_game_over)
9438 if (game.restart_game_message != NULL)
9440 RequestRestartGame(game.restart_game_message);
9445 if (game_status != GAME_MODE_PLAYING)
9448 GameActions(); // main game loop
9450 if (tape.auto_play && !tape.playing)
9451 AutoPlayTapesContinue(); // continue automatically playing next tape
9455 // ---------- new screen button stuff --------------------------------------
9459 int gfx_unpressed, gfx_pressed;
9460 struct MenuPosInfo *pos;
9461 boolean *check_value;
9464 unsigned int event_mask;
9465 boolean is_touch_button;
9467 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9470 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9471 &menu.main.button.prev_level, NULL,
9472 SCREEN_CTRL_ID_PREV_LEVEL,
9474 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9475 FALSE, "previous level"
9478 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9479 &menu.main.button.next_level, NULL,
9480 SCREEN_CTRL_ID_NEXT_LEVEL,
9482 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9486 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9487 &menu.scores.button.prev_level, NULL,
9488 SCREEN_CTRL_ID_PREV_LEVEL2,
9489 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9490 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9491 FALSE, "previous level"
9494 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9495 &menu.scores.button.next_level, NULL,
9496 SCREEN_CTRL_ID_NEXT_LEVEL2,
9497 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9498 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9502 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9503 &menu.scores.button.prev_score, NULL,
9504 SCREEN_CTRL_ID_PREV_SCORE,
9505 SCREEN_MASK_SCORES_INFO,
9506 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9507 FALSE, "previous score"
9510 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9511 &menu.scores.button.next_score, NULL,
9512 SCREEN_CTRL_ID_NEXT_SCORE,
9513 SCREEN_MASK_SCORES_INFO,
9514 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9518 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE,
9519 &menu.scores.button.play_tape, NULL,
9520 SCREEN_CTRL_ID_PLAY_TAPE,
9521 SCREEN_MASK_SCORES_INFO,
9526 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9527 &menu.main.button.first_level, NULL,
9528 SCREEN_CTRL_ID_FIRST_LEVEL,
9531 FALSE, "first level"
9534 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9535 &menu.main.button.last_level, NULL,
9536 SCREEN_CTRL_ID_LAST_LEVEL,
9542 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9543 &menu.main.button.level_number, NULL,
9544 SCREEN_CTRL_ID_LEVEL_NUMBER,
9547 FALSE, "level number"
9550 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9551 &menu.setup.button.prev_player, NULL,
9552 SCREEN_CTRL_ID_PREV_PLAYER,
9554 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9555 FALSE, "previous player"
9558 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9559 &menu.setup.button.next_player, NULL,
9560 SCREEN_CTRL_ID_NEXT_PLAYER,
9562 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9563 FALSE, "next player"
9566 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9567 &menu.main.button.insert_solution, NULL,
9568 SCREEN_CTRL_ID_INSERT_SOLUTION,
9569 SCREEN_MASK_MAIN_HAS_SOLUTION,
9571 FALSE, "insert solution tape"
9574 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9575 &menu.main.button.play_solution, NULL,
9576 SCREEN_CTRL_ID_PLAY_SOLUTION,
9577 SCREEN_MASK_MAIN_HAS_SOLUTION,
9579 FALSE, "play solution tape"
9582 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9583 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9584 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9586 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9587 FALSE, "switch ECS/AGA chipset"
9590 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9591 &menu.setup.button.touch_back, NULL,
9592 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9595 TRUE, "previous page"
9598 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9599 &menu.setup.button.touch_next, NULL,
9600 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9606 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9607 &menu.setup.button.touch_back2, NULL,
9608 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9611 TRUE, "previous page"
9614 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9615 &menu.setup.button.touch_next2, NULL,
9616 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9625 int gfx_unpressed, gfx_pressed;
9629 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9632 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9633 -1, -1, // these values are not constant, but can change at runtime
9634 SCREEN_CTRL_ID_SCROLL_UP,
9638 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9639 -1, -1, // these values are not constant, but can change at runtime
9640 SCREEN_CTRL_ID_SCROLL_DOWN,
9647 int gfx_unpressed, gfx_pressed;
9653 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9656 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9657 -1, -1, // these values are not constant, but can change at runtime
9658 -1, -1, // these values are not constant, but can change at runtime
9659 GD_TYPE_SCROLLBAR_VERTICAL,
9660 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9661 "scroll level series vertically"
9673 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9676 IMG_SETUP_INPUT_TEXT,
9677 SCREEN_CTRL_ID_NETWORK_SERVER,
9678 -1, -1, // these values are not constant, but can change at runtime
9679 MAX_SETUP_TEXT_INPUT_LEN,
9680 network_server_hostname,
9681 "Network Server Hostname / IP"
9685 static void CreateScreenMenubuttons(void)
9687 struct GadgetInfo *gi;
9688 unsigned int event_mask;
9691 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9693 struct MenuPosInfo *pos = menubutton_info[i].pos;
9694 int screen_mask = menubutton_info[i].screen_mask;
9695 boolean is_touch_button = menubutton_info[i].is_touch_button;
9696 boolean is_check_button = menubutton_info[i].check_value != NULL;
9697 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9698 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9699 menubutton_info[i].gfx_unpressed);
9700 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9701 int gfx_unpressed, gfx_pressed;
9702 int x, y, width, height;
9703 int gd_x1, gd_x2, gd_y1, gd_y2;
9704 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9705 int id = menubutton_info[i].gadget_id;
9706 int type = GD_TYPE_NORMAL_BUTTON;
9707 boolean checked = FALSE;
9709 event_mask = menubutton_info[i].event_mask;
9711 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9712 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9714 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9715 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9717 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9718 gfx_pressed = menubutton_info[i].gfx_pressed;
9719 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9720 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9721 gd_x1 = graphic_info[gfx_unpressed].src_x;
9722 gd_y1 = graphic_info[gfx_unpressed].src_y;
9723 gd_x2 = graphic_info[gfx_pressed].src_x;
9724 gd_y2 = graphic_info[gfx_pressed].src_y;
9730 if (has_gfx_pressed)
9732 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9733 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9736 if (is_check_button)
9738 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9739 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9740 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9741 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9743 type = GD_TYPE_CHECK_BUTTON;
9744 checked = *menubutton_info[i].check_value;
9747 if (is_score_button)
9749 // if x/y set to -1, dynamically place buttons next to title text
9750 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9752 // special compatibility handling for "Snake Bite" graphics set
9753 if (strPrefix(leveldir_current->identifier, "snake_bite"))
9754 title_width = strlen(INFOTEXT_SCORE_ENTRY) * 32;
9756 // use "SX" here to center buttons (ignore horizontal draw offset)
9758 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9759 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9760 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9761 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9763 // use "mSY" here to place buttons (respect vertical draw offset)
9765 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
9766 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
9769 gi = CreateGadget(GDI_CUSTOM_ID, id,
9770 GDI_CUSTOM_TYPE_ID, i,
9771 GDI_IMAGE_ID, gfx_unpressed,
9772 GDI_INFO_TEXT, menubutton_info[i].infotext,
9778 GDI_STATE, GD_BUTTON_UNPRESSED,
9779 GDI_CHECKED, checked,
9780 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9781 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9782 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9783 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9784 GDI_DIRECT_DRAW, FALSE,
9785 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9786 GDI_EVENT_MASK, event_mask,
9787 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9791 Fail("cannot create gadget");
9793 screen_gadget[id] = gi;
9797 static void CreateScreenScrollbuttons(void)
9799 struct GadgetInfo *gi;
9800 unsigned int event_mask;
9803 // these values are not constant, but can change at runtime
9804 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9805 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9806 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9807 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9809 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9811 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9812 int gfx_unpressed, gfx_pressed;
9813 int x, y, width, height;
9814 int gd_x1, gd_x2, gd_y1, gd_y2;
9815 int id = scrollbutton_info[i].gadget_id;
9817 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9819 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9820 y = mSY + scrollbutton_info[i].y;
9821 width = SC_SCROLLBUTTON_XSIZE;
9822 height = SC_SCROLLBUTTON_YSIZE;
9824 // correct scrollbar position if placed outside menu (playfield) area
9825 if (x > SX + SC_SCROLL_UP_XPOS)
9826 x = SX + SC_SCROLL_UP_XPOS;
9828 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9829 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9830 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9832 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9833 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9834 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9835 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9836 gd_x1 = graphic_info[gfx_unpressed].src_x;
9837 gd_y1 = graphic_info[gfx_unpressed].src_y;
9838 gd_x2 = graphic_info[gfx_pressed].src_x;
9839 gd_y2 = graphic_info[gfx_pressed].src_y;
9841 gi = CreateGadget(GDI_CUSTOM_ID, id,
9842 GDI_CUSTOM_TYPE_ID, i,
9843 GDI_IMAGE_ID, gfx_unpressed,
9844 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9849 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9850 GDI_STATE, GD_BUTTON_UNPRESSED,
9851 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9852 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9853 GDI_DIRECT_DRAW, FALSE,
9854 GDI_EVENT_MASK, event_mask,
9855 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9859 Fail("cannot create gadget");
9861 screen_gadget[id] = gi;
9865 static void CreateScreenScrollbars(void)
9869 // these values are not constant, but can change at runtime
9870 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9871 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9872 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9873 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9875 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9877 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9878 int gfx_unpressed, gfx_pressed;
9879 int x, y, width, height;
9880 int gd_x1, gd_x2, gd_y1, gd_y2;
9881 struct GadgetInfo *gi;
9882 int items_max, items_visible, item_position;
9883 unsigned int event_mask;
9884 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9885 int id = scrollbar_info[i].gadget_id;
9887 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9889 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9890 y = mSY + scrollbar_info[i].y;
9891 width = scrollbar_info[i].width;
9892 height = scrollbar_info[i].height;
9894 // correct scrollbar position if placed outside menu (playfield) area
9895 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9896 x = SX + SC_SCROLL_VERTICAL_XPOS;
9898 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9899 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9901 items_max = num_page_entries;
9902 items_visible = num_page_entries;
9905 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9906 gfx_pressed = scrollbar_info[i].gfx_pressed;
9907 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9908 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9909 gd_x1 = graphic_info[gfx_unpressed].src_x;
9910 gd_y1 = graphic_info[gfx_unpressed].src_y;
9911 gd_x2 = graphic_info[gfx_pressed].src_x;
9912 gd_y2 = graphic_info[gfx_pressed].src_y;
9914 gi = CreateGadget(GDI_CUSTOM_ID, id,
9915 GDI_CUSTOM_TYPE_ID, i,
9916 GDI_IMAGE_ID, gfx_unpressed,
9917 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9922 GDI_TYPE, scrollbar_info[i].type,
9923 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9924 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9925 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9926 GDI_WHEEL_AREA_X, SX,
9927 GDI_WHEEL_AREA_Y, SY,
9928 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9929 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9930 GDI_STATE, GD_BUTTON_UNPRESSED,
9931 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9932 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9933 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9934 GDI_DIRECT_DRAW, FALSE,
9935 GDI_EVENT_MASK, event_mask,
9936 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9940 Fail("cannot create gadget");
9942 screen_gadget[id] = gi;
9946 static void CreateScreenTextInputGadgets(void)
9950 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9952 int graphic = textinput_info[i].graphic;
9953 struct GraphicInfo *gd = &graphic_info[graphic];
9954 int gd_x1 = gd->src_x;
9955 int gd_y1 = gd->src_y;
9956 int gd_x2 = gd->src_x + gd->active_xoffset;
9957 int gd_y2 = gd->src_y + gd->active_yoffset;
9958 struct GadgetInfo *gi;
9959 unsigned int event_mask;
9960 int id = textinput_info[i].gadget_id;
9961 int x = textinput_info[i].x;
9962 int y = textinput_info[i].y;
9964 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9966 gi = CreateGadget(GDI_CUSTOM_ID, id,
9967 GDI_CUSTOM_TYPE_ID, i,
9968 GDI_INFO_TEXT, textinput_info[i].infotext,
9971 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9972 GDI_TEXT_VALUE, textinput_info[i].value,
9973 GDI_TEXT_SIZE, textinput_info[i].size,
9974 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9975 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9976 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9977 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9978 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9979 GDI_DESIGN_WIDTH, gd->width,
9980 GDI_EVENT_MASK, event_mask,
9981 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9982 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9986 Fail("cannot create gadget");
9988 screen_gadget[id] = gi;
9992 void CreateScreenGadgets(void)
9994 CreateScreenMenubuttons();
9996 CreateScreenScrollbuttons();
9997 CreateScreenScrollbars();
9999 CreateScreenTextInputGadgets();
10002 void FreeScreenGadgets(void)
10006 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10007 FreeGadget(screen_gadget[i]);
10010 static void RedrawScreenMenuGadgets(int screen_mask)
10014 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10015 if (screen_mask & menubutton_info[i].screen_mask)
10016 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10019 static void MapScreenMenuGadgets(int screen_mask)
10023 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10024 if (screen_mask & menubutton_info[i].screen_mask)
10025 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10028 static void UnmapScreenMenuGadgets(int screen_mask)
10032 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10034 if (screen_mask & menubutton_info[i].screen_mask)
10036 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10038 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10039 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10040 screen_gadget[menubutton_info[i].gadget_id]->y,
10041 screen_gadget[menubutton_info[i].gadget_id]->width,
10042 screen_gadget[menubutton_info[i].gadget_id]->height);
10047 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10050 MapScreenMenuGadgets(screen_mask);
10052 UnmapScreenMenuGadgets(screen_mask);
10055 static void MapScreenGadgets(int num_entries)
10059 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10062 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10063 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10065 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10066 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10069 static void UnmapScreenGadgets()
10073 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10074 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10076 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10077 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10080 static void MapScreenTreeGadgets(TreeInfo *ti)
10082 MapScreenGadgets(numTreeInfoInGroup(ti));
10085 static void UnmapScreenTreeGadgets(void)
10087 UnmapScreenGadgets();
10090 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10092 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10093 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10094 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10095 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10097 if (pos_1->x == -1 && pos_1->y == -1)
10098 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10100 if (pos_2->x == -1 && pos_2->y == -1)
10101 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10104 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10106 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10107 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10109 // set gadget position dynamically, pre-defined or off-screen
10110 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10111 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10113 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10114 MapGadget(gi); // (needed if deactivated on last score page)
10117 static void HandleScreenGadgets(struct GadgetInfo *gi)
10119 int id = gi->custom_id;
10120 int button = gi->event.button;
10121 int step = (button == MB_LEFTBUTTON ? 1 :
10122 button == MB_MIDDLEBUTTON ? 5 :
10123 button == MB_RIGHTBUTTON ? 10 : 1);
10127 case SCREEN_CTRL_ID_PREV_LEVEL:
10128 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10131 case SCREEN_CTRL_ID_NEXT_LEVEL:
10132 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10135 case SCREEN_CTRL_ID_PREV_LEVEL2:
10136 HandleHallOfFame_SelectLevel(step, -1);
10139 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10140 HandleHallOfFame_SelectLevel(step, +1);
10143 case SCREEN_CTRL_ID_PREV_SCORE:
10144 HandleScoreInfo_SelectScore(step, -1);
10147 case SCREEN_CTRL_ID_NEXT_SCORE:
10148 HandleScoreInfo_SelectScore(step, +1);
10151 case SCREEN_CTRL_ID_PLAY_TAPE:
10152 HandleScoreInfo_PlayTape();
10155 case SCREEN_CTRL_ID_FIRST_LEVEL:
10156 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10159 case SCREEN_CTRL_ID_LAST_LEVEL:
10160 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10163 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10164 CloseDoor(DOOR_CLOSE_2);
10165 SetGameStatus(GAME_MODE_LEVELNR);
10166 DrawChooseLevelNr();
10169 case SCREEN_CTRL_ID_PREV_PLAYER:
10170 HandleSetupScreen_Input_Player(step, -1);
10173 case SCREEN_CTRL_ID_NEXT_PLAYER:
10174 HandleSetupScreen_Input_Player(step, +1);
10177 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10178 InsertSolutionTape();
10181 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10182 PlaySolutionTape();
10185 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10186 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10190 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10191 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10192 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10193 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10194 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10197 case SCREEN_CTRL_ID_SCROLL_UP:
10198 if (game_status == GAME_MODE_NAMES)
10199 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10200 else if (game_status == GAME_MODE_LEVELS)
10201 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10202 else if (game_status == GAME_MODE_LEVELNR)
10203 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10204 else if (game_status == GAME_MODE_SETUP)
10205 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10206 else if (game_status == GAME_MODE_INFO)
10207 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10208 else if (game_status == GAME_MODE_SCORES)
10209 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10212 case SCREEN_CTRL_ID_SCROLL_DOWN:
10213 if (game_status == GAME_MODE_NAMES)
10214 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10215 else if (game_status == GAME_MODE_LEVELS)
10216 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10217 else if (game_status == GAME_MODE_LEVELNR)
10218 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10219 else if (game_status == GAME_MODE_SETUP)
10220 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10221 else if (game_status == GAME_MODE_INFO)
10222 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10223 else if (game_status == GAME_MODE_SCORES)
10224 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10227 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10228 if (game_status == GAME_MODE_NAMES)
10229 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10230 else if (game_status == GAME_MODE_LEVELS)
10231 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10232 else if (game_status == GAME_MODE_LEVELNR)
10233 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10234 else if (game_status == GAME_MODE_SETUP)
10235 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10236 else if (game_status == GAME_MODE_INFO)
10237 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10238 else if (game_status == GAME_MODE_SCORES)
10239 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10242 case SCREEN_CTRL_ID_NETWORK_SERVER:
10244 if (!strEqual(gi->textinput.value, ""))
10246 setString(&setup.network_server_hostname, gi->textinput.value);
10248 network.server_host = setup.network_server_hostname;
10252 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10254 network.server_host = NULL;
10257 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10258 network.server_host = NULL;
10260 execSetupGame_setNetworkServerText();
10272 void HandleScreenGadgetKeys(Key key)
10274 if (key == setup.shortcut.tape_play)
10275 HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
10278 void DumpScreenIdentifiers(void)
10282 Print("Active screen elements on current screen:\n");
10284 for (i = 0; main_controls[i].nr != -1; i++)
10286 struct MainControlInfo *mci = &main_controls[i];
10288 if (mci->button_graphic != -1)
10290 char *token = getTokenFromImageID(mci->button_graphic);
10292 Print("- '%s'\n", token);
10299 boolean DoScreenAction(int image_id)
10303 if (game_status != GAME_MODE_MAIN)
10306 for (i = 0; main_controls[i].nr != -1; i++)
10308 struct MainControlInfo *mci = &main_controls[i];
10309 struct MenuPosInfo *pos = mci->pos_button;
10311 if (mci->button_graphic == image_id)
10313 int x = mSX + pos->x;
10314 int y = mSY + pos->y;
10316 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10325 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10327 // get tree info node of newly added level or artwork set
10328 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10329 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10331 if (tree_node_new == NULL) // should not happen
10334 // if request dialog is active, do nothing
10335 if (game.request_active)
10338 if (game_status == GAME_MODE_MAIN &&
10339 tree_type == TREE_TYPE_LEVEL_DIR)
10341 // when adding new level set in main menu, select it as current level set
10343 // change current level set to newly added level set from zip file
10344 leveldir_current = tree_node_new;
10346 // change current level number to first level of newly added level set
10347 level_nr = leveldir_current->first_level;
10349 // redraw screen to reflect changed level set
10352 // save this level set and level number as last selected level set
10353 SaveLevelSetup_LastSeries();
10354 SaveLevelSetup_SeriesInfo();
10356 else if (game_status == GAME_MODE_LEVELS &&
10357 tree_type == TREE_TYPE_LEVEL_DIR)
10359 // when adding new level set in level set menu, set cursor and update screen
10361 leveldir_current = tree_node_new;
10363 DrawChooseTree(&leveldir_current);
10365 else if (game_status == GAME_MODE_SETUP)
10367 // when adding new artwork set in setup menu, set cursor and update screen
10369 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10370 tree_type == TREE_TYPE_GRAPHICS_DIR)
10372 artwork.gfx_current = tree_node_new;
10374 DrawChooseTree(&artwork.gfx_current);
10376 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10377 tree_type == TREE_TYPE_SOUNDS_DIR)
10379 artwork.snd_current = tree_node_new;
10381 DrawChooseTree(&artwork.snd_current);
10383 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10384 tree_type == TREE_TYPE_MUSIC_DIR)
10386 artwork.mus_current = tree_node_new;
10388 DrawChooseTree(&artwork.mus_current);
10393 static int UploadTapes(void)
10395 SetGameStatus(GAME_MODE_LOADING);
10397 FadeSetEnterScreen();
10398 FadeOut(REDRAW_ALL);
10400 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10402 FadeIn(REDRAW_ALL);
10404 DrawInitTextHead("Uploading tapes");
10406 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10407 global.autoplay_leveldir = "ALL";
10408 global.autoplay_all = TRUE;
10410 int num_tapes_uploaded = AutoPlayTapes();
10412 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10413 global.autoplay_leveldir = NULL;
10414 global.autoplay_all = FALSE;
10416 SetGameStatus(GAME_MODE_MAIN);
10420 return num_tapes_uploaded;
10423 static boolean OfferUploadTapes(void)
10425 if (!Request(setup.has_remaining_tapes ?
10426 "Upload missing tapes to the high score server now?" :
10427 "Upload all your tapes to the high score server now?", REQ_ASK))
10430 int num_tapes_uploaded = UploadTapes();
10433 if (num_tapes_uploaded < 0)
10435 num_tapes_uploaded = -num_tapes_uploaded - 1;
10437 if (num_tapes_uploaded == 0)
10438 sprintf(message, "Upload failed! No tapes uploaded!");
10439 else if (num_tapes_uploaded == 1)
10440 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10442 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10443 num_tapes_uploaded);
10445 Request(message, REQ_CONFIRM);
10447 // if uploading tapes failed, add tape upload entry to setup menu
10448 setup.provide_uploading_tapes = TRUE;
10449 setup.has_remaining_tapes = TRUE;
10451 SaveSetup_ServerSetup();
10456 if (num_tapes_uploaded == 0)
10457 sprintf(message, "No tapes uploaded!");
10458 else if (num_tapes_uploaded == 1)
10459 sprintf(message, "1 tape uploaded!");
10461 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10463 Request(message, REQ_CONFIRM);
10465 if (num_tapes_uploaded > 0)
10466 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10468 // after all tapes have been uploaded, remove entry from setup menu
10469 setup.provide_uploading_tapes = FALSE;
10470 setup.has_remaining_tapes = FALSE;
10472 SaveSetup_ServerSetup();
10477 static void CheckUploadTapes(void)
10479 if (!setup.ask_for_uploading_tapes)
10482 // after asking for uploading tapes, do not ask again
10483 setup.ask_for_uploading_tapes = FALSE;
10484 setup.ask_for_remaining_tapes = FALSE;
10486 if (directoryExists(getTapeDir(NULL)))
10488 boolean tapes_uploaded = OfferUploadTapes();
10490 if (!tapes_uploaded)
10492 Request(setup.has_remaining_tapes ?
10493 "You can upload missing tapes from the setup menu later!" :
10494 "You can upload your tapes from the setup menu later!",
10500 // if tapes directory does not exist yet, never offer uploading all tapes
10501 setup.provide_uploading_tapes = FALSE;
10504 SaveSetup_ServerSetup();
10507 static void UpgradePlayerUUID(void)
10509 ApiResetUUIDAsThread(getUUID());
10512 static void CheckUpgradePlayerUUID(void)
10514 if (setup.player_version > 1)
10517 UpgradePlayerUUID();
10520 void CheckApiServerTasks(void)
10522 // check if the player's UUID has to be upgraded
10523 CheckUpgradePlayerUUID();
10525 // check if there are any tapes to be uploaded
10526 CheckUploadTapes();