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"
27 #define DEBUG_JOYSTICKS 0
30 // screens on the info screen
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 // screens on the setup screen
43 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
44 // (should also match corresponding entries in src/conf_gfx.c)
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_ENGINES 2
48 #define SETUP_MODE_EDITOR 3
49 #define SETUP_MODE_GRAPHICS 4
50 #define SETUP_MODE_SOUND 5
51 #define SETUP_MODE_ARTWORK 6
52 #define SETUP_MODE_INPUT 7
53 #define SETUP_MODE_TOUCH 8
54 #define SETUP_MODE_SHORTCUTS 9
55 #define SETUP_MODE_SHORTCUTS_1 10
56 #define SETUP_MODE_SHORTCUTS_2 11
57 #define SETUP_MODE_SHORTCUTS_3 12
58 #define SETUP_MODE_SHORTCUTS_4 13
59 #define SETUP_MODE_SHORTCUTS_5 14
61 // sub-screens on the setup screen (generic)
62 #define SETUP_MODE_CHOOSE_ARTWORK 15
63 #define SETUP_MODE_CHOOSE_OTHER 16
65 // sub-screens on the setup screen (specific)
66 #define SETUP_MODE_CHOOSE_SCORES_TYPE 17
67 #define SETUP_MODE_CHOOSE_GAME_SPEED 18
68 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 19
69 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 20
70 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 21
71 #define SETUP_MODE_CHOOSE_SCALING_TYPE 22
72 #define SETUP_MODE_CHOOSE_RENDERING 23
73 #define SETUP_MODE_CHOOSE_VSYNC 24
74 #define SETUP_MODE_CHOOSE_GRAPHICS 25
75 #define SETUP_MODE_CHOOSE_SOUNDS 26
76 #define SETUP_MODE_CHOOSE_MUSIC 27
77 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 28
78 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 29
79 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 30
80 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 31
81 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 33
83 #define SETUP_MODE_CHOOSE_TRANSPARENCY 34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 36
86 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 37
87 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 38
88 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 39
90 #define MAX_SETUP_MODES 40
92 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
94 // setup screen titles
95 #define STR_SETUP_MAIN "Setup"
96 #define STR_SETUP_GAME "Game & Menu"
97 #define STR_SETUP_ENGINES "Game Engines"
98 #define STR_SETUP_EDITOR "Editor"
99 #define STR_SETUP_GRAPHICS "Graphics"
100 #define STR_SETUP_SOUND "Sound & Music"
101 #define STR_SETUP_ARTWORK "Custom Artwork"
102 #define STR_SETUP_INPUT "Input Devices"
103 #define STR_SETUP_TOUCH "Touch Controls"
104 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
105 #define STR_SETUP_EXIT "Exit"
106 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
108 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
109 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
110 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
111 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
112 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
113 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
114 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
115 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
116 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
117 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
118 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
119 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
120 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
121 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
122 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
125 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
126 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
128 // other screen text constants
129 #define STR_CHOOSE_TREE_EDIT "Edit"
130 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
131 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
133 #define TEXT_NEXT_PAGE "Press any key or button for next page"
134 #define TEXT_INFO_MENU "Press any key or button for info menu"
136 // for input setup functions
137 #define SETUPINPUT_SCREEN_POS_START 0
138 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
139 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
140 #define SETUPINPUT_SCREEN_POS_END 13
142 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
143 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
145 #define MAX_SETUP_TEXT_INPUT_LEN 28
147 // for various menu stuff
148 #define MENU_SCREEN_START_XPOS 1
149 #define MENU_SCREEN_START_YPOS 2
150 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
151 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
152 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
153 #define MENU_TITLE1_YPOS 8
154 #define MENU_TITLE2_YPOS 46
155 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
156 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
157 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
158 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
159 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
160 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
161 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
162 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
163 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
164 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
165 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
166 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
167 MENU_INFO_FONT_TITLE))
168 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
169 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
170 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
171 MENU_SCREEN_INFO_YSTART2 - \
173 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
174 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
175 MENU_SCREEN_INFO_YSTEP)
176 #define NUM_INFO_ELEMENTS_FROM_CONF \
177 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
178 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
179 MAX_MENU_ENTRIES_ON_SCREEN)
180 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
181 MAX_INFO_ELEMENTS_ON_SCREEN), \
182 NUM_INFO_ELEMENTS_FROM_CONF)
183 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
184 #define MAX_MENU_TEXT_LENGTH_BIG 13
185 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
187 // screen gadget identifiers
188 #define SCREEN_CTRL_ID_PREV_LEVEL 0
189 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
190 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
191 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
192 #define SCREEN_CTRL_ID_PREV_SCORE 4
193 #define SCREEN_CTRL_ID_NEXT_SCORE 5
194 #define SCREEN_CTRL_ID_FIRST_LEVEL 6
195 #define SCREEN_CTRL_ID_LAST_LEVEL 7
196 #define SCREEN_CTRL_ID_LEVEL_NUMBER 8
197 #define SCREEN_CTRL_ID_PREV_PLAYER 9
198 #define SCREEN_CTRL_ID_NEXT_PLAYER 10
199 #define SCREEN_CTRL_ID_INSERT_SOLUTION 11
200 #define SCREEN_CTRL_ID_PLAY_SOLUTION 12
201 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 13
202 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 14
203 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 15
204 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 16
205 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 17
207 #define NUM_SCREEN_MENUBUTTONS 18
209 #define SCREEN_CTRL_ID_SCROLL_UP 18
210 #define SCREEN_CTRL_ID_SCROLL_DOWN 19
211 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 20
212 #define SCREEN_CTRL_ID_NETWORK_SERVER 21
214 #define NUM_SCREEN_GADGETS 22
216 #define NUM_SCREEN_SCROLLBUTTONS 2
217 #define NUM_SCREEN_SCROLLBARS 1
218 #define NUM_SCREEN_TEXTINPUT 1
220 #define SCREEN_MASK_MAIN (1 << 0)
221 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
222 #define SCREEN_MASK_INPUT (1 << 2)
223 #define SCREEN_MASK_TOUCH (1 << 3)
224 #define SCREEN_MASK_TOUCH2 (1 << 4)
225 #define SCREEN_MASK_SCORES (1 << 5)
226 #define SCREEN_MASK_SCORES_INFO (1 << 6)
228 // graphic position and size values for buttons and scrollbars
229 #define SC_MENUBUTTON_XSIZE TILEX
230 #define SC_MENUBUTTON_YSIZE TILEY
232 #define SC_SCROLLBUTTON_XSIZE TILEX
233 #define SC_SCROLLBUTTON_YSIZE TILEY
235 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
237 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
238 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
239 SC_SCROLLBUTTON_YSIZE)
241 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
242 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
244 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
245 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
246 SC_SCROLLBUTTON_YSIZE)
248 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
249 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
250 SC_SCROLL_VERTICAL_YSIZE)
252 #define SC_BORDER_SIZE 14
255 // forward declarations of internal functions
256 static void HandleScreenGadgets(struct GadgetInfo *);
257 static void HandleSetupScreen_Generic(int, int, int, int, int);
258 static void HandleSetupScreen_Input(int, int, int, int, int);
259 static void CustomizeKeyboard(int);
260 static void ConfigureJoystick(int);
261 static void ConfigureVirtualButtons(void);
262 static void execSetupGame(void);
263 static void execSetupEngines(void);
264 static void execSetupGraphics(void);
265 static void execSetupSound(void);
266 static void execSetupTouch(void);
267 static void execSetupArtwork(void);
268 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
270 static void DrawChoosePlayerName(void);
271 static void DrawChooseLevelSet(void);
272 static void DrawChooseLevelNr(void);
273 static void DrawScoreInfo(int);
274 static void DrawScoreInfo_Content(int);
275 static void DrawInfoScreen(void);
276 static void DrawSetupScreen(void);
277 static void DrawTypeName(void);
279 static void DrawInfoScreen_NotAvailable(char *, char *);
280 static void DrawInfoScreen_HelpAnim(int, int, boolean);
281 static void DrawInfoScreen_HelpText(int, int, int, int);
282 static void HandleInfoScreen_Main(int, int, int, int, int);
283 static void HandleInfoScreen_TitleScreen(int, int, int);
284 static void HandleInfoScreen_Elements(int, int, int);
285 static void HandleInfoScreen_Music(int, int, int);
286 static void HandleInfoScreen_Credits(int, int, int);
287 static void HandleInfoScreen_Program(int, int, int);
288 static void HandleInfoScreen_Version(int);
290 static void ModifyGameSpeedIfNeeded(void);
291 static void DisableVsyncIfNeeded(void);
293 static void RedrawScreenMenuGadgets(int);
294 static void MapScreenMenuGadgets(int);
295 static void UnmapScreenMenuGadgets(int);
296 static void MapScreenGadgets(int);
297 static void UnmapScreenGadgets(void);
298 static void MapScreenTreeGadgets(TreeInfo *);
299 static void UnmapScreenTreeGadgets(void);
301 static void UpdateScreenMenuGadgets(int, boolean);
302 static void AdjustScoreInfoButtons_SelectScore(int, int, int);
304 static boolean OfferUploadTapes(void);
305 static void execOfferUploadTapes(void);
307 static void DrawHallOfFame_setScoreEntries(void);
308 static void HandleHallOfFame_SelectLevel(int, int);
309 static char *getHallOfFameRankText(int, int);
310 static char *getHallOfFameScoreText(int, int);
312 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
314 static int info_mode = INFO_MODE_MAIN;
315 static int setup_mode = SETUP_MODE_MAIN;
317 static TreeInfo *window_sizes = NULL;
318 static TreeInfo *window_size_current = NULL;
320 static TreeInfo *scaling_types = NULL;
321 static TreeInfo *scaling_type_current = NULL;
323 static TreeInfo *rendering_modes = NULL;
324 static TreeInfo *rendering_mode_current = NULL;
326 static TreeInfo *vsync_modes = NULL;
327 static TreeInfo *vsync_mode_current = NULL;
329 static TreeInfo *scroll_delays = NULL;
330 static TreeInfo *scroll_delay_current = NULL;
332 static TreeInfo *snapshot_modes = NULL;
333 static TreeInfo *snapshot_mode_current = NULL;
335 static TreeInfo *scores_types = NULL;
336 static TreeInfo *scores_type_current = NULL;
338 static TreeInfo *game_speeds_normal = NULL;
339 static TreeInfo *game_speeds_extended = NULL;
340 static TreeInfo *game_speeds = NULL;
341 static TreeInfo *game_speed_current = NULL;
343 static TreeInfo *volumes_simple = NULL;
344 static TreeInfo *volume_simple_current = NULL;
346 static TreeInfo *volumes_loops = NULL;
347 static TreeInfo *volume_loops_current = NULL;
349 static TreeInfo *volumes_music = NULL;
350 static TreeInfo *volume_music_current = NULL;
352 static TreeInfo *touch_controls = NULL;
353 static TreeInfo *touch_control_current = NULL;
355 static TreeInfo *move_distances = NULL;
356 static TreeInfo *move_distance_current = NULL;
358 static TreeInfo *drop_distances = NULL;
359 static TreeInfo *drop_distance_current = NULL;
361 static TreeInfo *transparencies = NULL;
362 static TreeInfo *transparency_current = NULL;
364 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
365 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
367 static TreeInfo *player_name = NULL;
368 static TreeInfo *player_name_current = NULL;
370 static TreeInfo *level_number = NULL;
371 static TreeInfo *level_number_current = NULL;
373 static TreeInfo *score_entries = NULL;
374 static TreeInfo *score_entry_current = NULL;
376 static struct ValueTextInfo window_sizes_list[] =
381 { 100, "100 % (Default)" },
394 static struct StringValueTextInfo scaling_types_list[] =
396 { SCALING_QUALITY_NEAREST, "Off" },
397 { SCALING_QUALITY_LINEAR, "Linear" },
398 { SCALING_QUALITY_BEST, "Anisotropic" },
403 static struct StringValueTextInfo rendering_modes_list[] =
405 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
406 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
408 // this mode may work under certain conditions, but does not work on Windows
409 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
411 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
416 static struct StringValueTextInfo vsync_modes_list[] =
418 { STR_VSYNC_MODE_OFF, "Off" },
419 { STR_VSYNC_MODE_NORMAL, "Normal" },
420 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
425 static struct StringValueTextInfo scores_types_list[] =
427 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
428 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
429 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
434 static struct ValueTextInfo game_speeds_list_normal[] =
445 static struct ValueTextInfo game_speeds_list_extended[] =
447 { 1000, "1 fps (Extremely Slow)" },
452 { 29, "35 fps (Original Supaplex)" },
454 { 20, "50 fps (=== Normal Speed ===)" },
455 { 16, "60 fps (60 Hz VSync Speed)" },
456 { 14, "70 fps (Maximum Supaplex)" },
460 { 1, "1000 fps (Extremely Fast)" },
465 static struct ValueTextInfo *game_speeds_list;
467 static struct ValueTextInfo scroll_delays_list[] =
469 { 0, "0 Tiles (No Scroll Delay)" },
472 { 3, "3 Tiles (Default)" },
477 { 8, "8 Tiles (Maximum Scroll Delay)"},
482 static struct StringValueTextInfo snapshot_modes_list[] =
484 { STR_SNAPSHOT_MODE_OFF, "Off" },
485 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
486 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
487 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
492 static struct ValueTextInfo volumes_list[] =
512 static struct StringValueTextInfo touch_controls_list[] =
514 { TOUCH_CONTROL_OFF, "Off" },
515 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
516 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
517 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
522 static struct ValueTextInfo distances_list[] =
537 static struct ValueTextInfo transparencies_list[] =
539 { 0, "0 % (Opaque)" },
549 { 100, "100 % (Invisible)" },
554 static struct ValueTextInfo grid_sizes_list[] =
590 static int align_xoffset = 0;
591 static int align_yoffset = 0;
593 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
594 (s) <= GAME_MODE_SETUP ? (s) : \
595 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
597 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
598 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
600 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
601 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
602 (i) <= INFO_MODE_LEVELSET ? (i) : \
605 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
606 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
607 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
608 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
609 SETUP_MODE_CHOOSE_ARTWORK : \
610 SETUP_MODE_CHOOSE_OTHER)
612 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
613 menu.draw_xoffset[GAME_MODE_INFO] : \
614 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
615 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
616 menu.draw_yoffset[GAME_MODE_INFO] : \
617 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
618 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
619 menu.extra_spacing[GAME_MODE_INFO] : \
620 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
622 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
623 menu.draw_xoffset[GAME_MODE_SETUP] : \
624 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
625 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
626 menu.draw_yoffset[GAME_MODE_SETUP] : \
627 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
628 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
629 menu.extra_spacing[GAME_MODE_SETUP] : \
630 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
632 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
634 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
636 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
637 DRAW_XOFFSET_INFO(info_mode) : \
638 (s) == GAME_MODE_SETUP ? \
639 DRAW_XOFFSET_SETUP(setup_mode) : \
640 menu.draw_xoffset[DRAW_MODE(s)])
641 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
642 DRAW_YOFFSET_INFO(info_mode) : \
643 (s) == GAME_MODE_SETUP ? \
644 DRAW_YOFFSET_SETUP(setup_mode) : \
645 menu.draw_yoffset[DRAW_MODE(s)])
646 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
647 EXTRA_SPACING_INFO(info_mode) : \
648 (s) == GAME_MODE_SETUP ? \
649 EXTRA_SPACING_SETUP(setup_mode) : \
650 (s) == GAME_MODE_SCORES ? \
651 EXTRA_SPACING_SCORES(info_mode) : \
652 menu.extra_spacing[DRAW_MODE(s)])
654 #define mSX (SX + DRAW_XOFFSET(game_status))
655 #define mSY (SY + DRAW_YOFFSET(game_status))
657 #define amSX (mSX + align_xoffset)
658 #define amSY (mSY + align_yoffset)
660 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
661 menu.list_size[game_status] : \
662 MAX_MENU_ENTRIES_ON_SCREEN)
664 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
665 NUM_MENU_ENTRIES_ON_SCREEN)
668 // title display and control definitions
670 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
671 2 * MAX_NUM_TITLE_MESSAGES)
673 #define NO_DIRECT_LEVEL_SELECT (-1)
676 static int num_title_screens = 0;
678 struct TitleControlInfo
687 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
690 // credits screens definitions
692 static int num_credits_screens = 0;
693 static boolean use_global_credits_screens = FALSE;
696 // program info screens definitions
698 static int num_program_info_screens = 0;
701 // main menu display and control definitions
703 #define MAIN_CONTROL_NAME 0
704 #define MAIN_CONTROL_LEVELS 1
705 #define MAIN_CONTROL_SCORES 2
706 #define MAIN_CONTROL_EDITOR 3
707 #define MAIN_CONTROL_INFO 4
708 #define MAIN_CONTROL_GAME 5
709 #define MAIN_CONTROL_SETUP 6
710 #define MAIN_CONTROL_QUIT 7
711 #define MAIN_CONTROL_PREV_LEVEL 8
712 #define MAIN_CONTROL_NEXT_LEVEL 9
713 #define MAIN_CONTROL_FIRST_LEVEL 10
714 #define MAIN_CONTROL_LAST_LEVEL 11
715 #define MAIN_CONTROL_LEVEL_NUMBER 12
716 #define MAIN_CONTROL_LEVEL_INFO_1 13
717 #define MAIN_CONTROL_LEVEL_INFO_2 14
718 #define MAIN_CONTROL_LEVEL_NAME 15
719 #define MAIN_CONTROL_LEVEL_AUTHOR 16
720 #define MAIN_CONTROL_LEVEL_YEAR 17
721 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
722 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
723 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
724 #define MAIN_CONTROL_TITLE_1 21
725 #define MAIN_CONTROL_TITLE_2 22
726 #define MAIN_CONTROL_TITLE_3 23
728 static char str_main_text_name[10];
729 static char str_main_text_first_level[10];
730 static char str_main_text_last_level[10];
731 static char str_main_text_level_number[10];
733 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
735 static char *main_text_name = str_main_text_name;
736 static char *main_text_first_level = str_main_text_first_level;
737 static char *main_text_last_level = str_main_text_last_level;
738 static char *main_text_level_number = str_main_text_level_number;
739 static char *main_text_levels = "Levelset";
740 static char *main_text_scores = "Hall Of Fame";
741 static char *main_text_editor = "Level Creator";
742 static char *main_text_info = "Info Screen";
743 static char *main_text_game = "Start Game";
744 static char *main_text_setup = "Setup";
745 static char *main_text_quit = "Quit";
746 static char *main_text_level_name = level.name;
747 static char *main_text_level_author = level.author;
748 static char *main_text_level_year = NULL;
749 static char *main_text_level_imported_from = NULL;
750 static char *main_text_level_imported_by = NULL;
751 static char *main_text_level_tested_by = NULL;
752 static char *main_text_title_1 = NULL;
753 static char *main_text_title_2 = NULL;
754 static char *main_text_title_3 = NULL;
756 extern char debug_xsn_mode[];
758 struct MainControlInfo
762 struct MenuPosInfo *pos_button;
765 struct TextPosInfo *pos_text;
768 struct TextPosInfo *pos_input;
772 static struct MainControlInfo main_controls[] =
776 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
777 &menu.main.text.name, &main_text_name,
778 &menu.main.input.name, &setup.player_name,
782 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
783 &menu.main.text.levels, &main_text_levels,
788 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
789 &menu.main.text.scores, &main_text_scores,
794 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
795 &menu.main.text.editor, &main_text_editor,
800 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
801 &menu.main.text.info, &main_text_info,
806 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
807 &menu.main.text.game, &main_text_game,
812 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
813 &menu.main.text.setup, &main_text_setup,
818 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
819 &menu.main.text.quit, &main_text_quit,
823 MAIN_CONTROL_PREV_LEVEL,
829 MAIN_CONTROL_NEXT_LEVEL,
835 MAIN_CONTROL_FIRST_LEVEL,
837 &menu.main.text.first_level, &main_text_first_level,
841 MAIN_CONTROL_LAST_LEVEL,
843 &menu.main.text.last_level, &main_text_last_level,
847 MAIN_CONTROL_LEVEL_NUMBER,
849 &menu.main.text.level_number, &main_text_level_number,
853 MAIN_CONTROL_LEVEL_INFO_1,
855 &menu.main.text.level_info_1, NULL,
859 MAIN_CONTROL_LEVEL_INFO_2,
861 &menu.main.text.level_info_2, NULL,
865 MAIN_CONTROL_LEVEL_NAME,
867 &menu.main.text.level_name, &main_text_level_name,
871 MAIN_CONTROL_LEVEL_AUTHOR,
873 &menu.main.text.level_author, &main_text_level_author,
877 MAIN_CONTROL_LEVEL_YEAR,
879 &menu.main.text.level_year, &main_text_level_year,
883 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
885 &menu.main.text.level_imported_from, &main_text_level_imported_from,
889 MAIN_CONTROL_LEVEL_IMPORTED_BY,
891 &menu.main.text.level_imported_by, &main_text_level_imported_by,
895 MAIN_CONTROL_LEVEL_TESTED_BY,
897 &menu.main.text.level_tested_by, &main_text_level_tested_by,
901 MAIN_CONTROL_TITLE_1,
903 &menu.main.text.title_1, &main_text_title_1,
907 MAIN_CONTROL_TITLE_2,
909 &menu.main.text.title_2, &main_text_title_2,
913 MAIN_CONTROL_TITLE_3,
915 &menu.main.text.title_3, &main_text_title_3,
928 static int getTitleScreenGraphic(int nr, boolean initial)
930 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
933 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
935 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
939 static int getTitleScreenGameMode(boolean initial)
941 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
945 static int getTitleMessageGameMode(boolean initial)
947 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
950 static int getTitleAnimMode(struct TitleControlInfo *tci)
952 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
954 return base + tci->local_nr;
958 static int getTitleScreenBackground(boolean initial)
960 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
965 static int getTitleMessageBackground(int nr, boolean initial)
967 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
971 static int getTitleBackground(int nr, boolean initial, boolean is_image)
973 int base = (is_image ?
974 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
975 IMG_BACKGROUND_TITLESCREEN_1) :
976 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
977 IMG_BACKGROUND_TITLEMESSAGE_1));
978 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
979 IMG_BACKGROUND_TITLE);
980 int graphic_local = base + nr;
982 if (graphic_info[graphic_local].bitmap != NULL)
983 return graphic_local;
985 if (graphic_info[graphic_global].bitmap != NULL)
986 return graphic_global;
988 return IMG_UNDEFINED;
991 static int getTitleSound(struct TitleControlInfo *tci)
993 boolean is_image = tci->is_image;
994 int initial = tci->initial;
995 int nr = tci->local_nr;
996 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
997 int base = (is_image ?
998 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
999 SND_BACKGROUND_TITLESCREEN_1) :
1000 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1001 SND_BACKGROUND_TITLEMESSAGE_1));
1002 int sound_global = menu.sound[mode];
1003 int sound_local = base + nr;
1006 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
1007 nr, initial, is_image,
1008 sound_global, getSoundListEntry(sound_global)->filename,
1009 sound_local, getSoundListEntry(sound_local)->filename);
1012 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1015 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1016 return sound_global;
1018 return SND_UNDEFINED;
1021 static int getTitleMusic(struct TitleControlInfo *tci)
1023 boolean is_image = tci->is_image;
1024 int initial = tci->initial;
1025 int nr = tci->local_nr;
1026 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1027 int base = (is_image ?
1028 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1029 MUS_BACKGROUND_TITLESCREEN_1) :
1030 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1031 MUS_BACKGROUND_TITLEMESSAGE_1));
1032 int music_global = menu.music[mode];
1033 int music_local = base + nr;
1036 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1037 nr, initial, is_image,
1038 music_global, getMusicListEntry(music_global)->filename,
1039 music_local, getMusicListEntry(music_local)->filename);
1042 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1045 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1046 return music_global;
1048 return MUS_UNDEFINED;
1051 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1053 boolean is_image = tci->is_image;
1054 boolean initial = tci->initial;
1055 boolean first = tci->first;
1056 int nr = tci->local_nr;
1057 struct TitleMessageInfo tmi;
1058 struct TitleFadingInfo ti;
1060 tmi = (is_image ? (initial ? (first ?
1061 titlescreen_initial_first[nr] :
1062 titlescreen_initial[nr])
1064 titlescreen_first[nr] :
1066 : (initial ? (first ?
1067 titlemessage_initial_first[nr] :
1068 titlemessage_initial[nr])
1070 titlemessage_first[nr] :
1071 titlemessage[nr])));
1073 ti.fade_mode = tmi.fade_mode;
1074 ti.fade_delay = tmi.fade_delay;
1075 ti.post_delay = tmi.post_delay;
1076 ti.auto_delay = tmi.auto_delay;
1077 ti.auto_delay_unit = tmi.auto_delay_unit;
1082 static int compareTitleControlInfo(const void *object1, const void *object2)
1084 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1085 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1088 if (tci1->initial != tci2->initial)
1089 compare_result = (tci1->initial ? -1 : +1);
1090 else if (tci1->sort_priority != tci2->sort_priority)
1091 compare_result = tci1->sort_priority - tci2->sort_priority;
1092 else if (tci1->is_image != tci2->is_image)
1093 compare_result = (tci1->is_image ? -1 : +1);
1095 compare_result = tci1->local_nr - tci2->local_nr;
1097 return compare_result;
1100 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1102 int nr, int sort_priority)
1104 title_controls[num_title_screens].is_image = is_image;
1105 title_controls[num_title_screens].initial = initial;
1106 title_controls[num_title_screens].local_nr = nr;
1107 title_controls[num_title_screens].sort_priority = sort_priority;
1109 title_controls[num_title_screens].first = FALSE; // will be set later
1111 num_title_screens++;
1114 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1118 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1120 int graphic = getTitleScreenGraphic(i, initial);
1121 Bitmap *bitmap = graphic_info[graphic].bitmap;
1122 int sort_priority = graphic_info[graphic].sort_priority;
1125 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1128 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1130 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1131 char *filename = getLevelSetTitleMessageFilename(i, initial);
1132 int sort_priority = tmi->sort_priority;
1134 if (filename != NULL)
1135 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1139 static void InitializeTitleControls(boolean show_title_initial)
1141 num_title_screens = 0;
1143 // 1st step: initialize title screens for game start (only when starting)
1144 if (show_title_initial)
1145 InitializeTitleControls_CheckTitleInfo(TRUE);
1147 // 2nd step: initialize title screens for current level set
1148 InitializeTitleControls_CheckTitleInfo(FALSE);
1150 // sort title screens according to sort_priority and title number
1151 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1152 compareTitleControlInfo);
1154 // mark first title screen
1155 title_controls[0].first = TRUE;
1158 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1160 return (pos != NULL && pos->x != -1 && pos->y != -1);
1163 static boolean visibleTextPos(struct TextPosInfo *pos)
1165 return (pos != NULL && pos->x != -1 && pos->y != -1);
1168 static void InitializeMainControls(void)
1170 boolean local_team_mode = (!network.enabled && setup.team_mode);
1173 // set main control text values to dynamically determined values
1174 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1176 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1177 menu.main.text.first_level.size));
1178 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1179 menu.main.text.last_level.size));
1180 strcpy(main_text_level_number, int2str(level_nr,
1181 menu.main.text.level_number.size));
1183 main_text_level_year = leveldir_current->year;
1184 main_text_level_imported_from = leveldir_current->imported_from;
1185 main_text_level_imported_by = leveldir_current->imported_by;
1186 main_text_level_tested_by = leveldir_current->tested_by;
1188 main_text_title_1 = getConfigProgramTitleString();
1189 main_text_title_2 = getConfigProgramCopyrightString();
1190 main_text_title_3 = getConfigProgramCompanyString();
1192 // set main control screen positions to dynamically determined values
1193 for (i = 0; main_controls[i].nr != -1; i++)
1195 struct MainControlInfo *mci = &main_controls[i];
1197 struct MenuPosInfo *pos_button = mci->pos_button;
1198 struct TextPosInfo *pos_text = mci->pos_text;
1199 struct TextPosInfo *pos_input = mci->pos_input;
1200 char *text = (mci->text ? *mci->text : NULL);
1201 char *input = (mci->input ? *mci->input : NULL);
1202 int button_graphic = mci->button_graphic;
1203 int font_text = (pos_text ? pos_text->font : -1);
1204 int font_input = (pos_input ? pos_input->font : -1);
1206 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1207 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1208 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1209 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1210 int text_chars = (text != NULL ? strlen(text) : 0);
1211 int input_chars = (input != NULL ? strlen(input) : 0);
1214 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1216 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1217 int text_width = font_text_width * text_chars;
1218 int text_height = font_text_height;
1219 int input_width = font_input_width * input_chars;
1220 int input_height = font_input_height;
1222 if (nr == MAIN_CONTROL_NAME)
1224 menu.main.input.name.width = input_width;
1225 menu.main.input.name.height = input_height;
1228 if (pos_button != NULL) // (x/y may be -1/-1 here)
1230 pos_button->width = button_width;
1231 pos_button->height = button_height;
1234 if (pos_text != NULL) // (x/y may be -1/-1 here)
1236 // calculate text size -- needed for text alignment
1237 boolean calculate_text_size = (text != NULL);
1239 if (pos_text->width == -1 || calculate_text_size)
1240 pos_text->width = text_width;
1241 if (pos_text->height == -1 || calculate_text_size)
1242 pos_text->height = text_height;
1244 if (visibleMenuPos(pos_button))
1246 if (pos_text->x == -1)
1247 pos_text->x = pos_button->x + pos_button->width;
1248 if (pos_text->y == -1)
1250 pos_button->y + (pos_button->height - pos_text->height) / 2;
1254 if (pos_input != NULL) // (x/y may be -1/-1 here)
1256 if (visibleTextPos(pos_text))
1258 if (pos_input->x == -1)
1259 pos_input->x = pos_text->x + pos_text->width;
1260 if (pos_input->y == -1)
1261 pos_input->y = pos_text->y;
1264 if (pos_input->width == -1)
1265 pos_input->width = input_width;
1266 if (pos_input->height == -1)
1267 pos_input->height = input_height;
1272 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1273 int graphic, boolean pressed)
1275 struct GraphicInfo *g = &graphic_info[graphic];
1278 int xoffset = (pressed ? g->pressed_xoffset : 0);
1279 int yoffset = (pressed ? g->pressed_yoffset : 0);
1281 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1283 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1284 g->width, g->height, dst_x, dst_y);
1287 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1288 boolean active_input,
1289 boolean pressed_button)
1293 for (i = 0; main_controls[i].nr != -1; i++)
1295 struct MainControlInfo *mci = &main_controls[i];
1297 if (mci->nr == nr || nr == -1)
1299 struct MenuPosInfo *pos_button = mci->pos_button;
1300 struct TextPosInfo *pos_text = mci->pos_text;
1301 struct TextPosInfo *pos_input = mci->pos_input;
1302 char *text = (mci->text ? *mci->text : NULL);
1303 char *input = (mci->input ? *mci->input : NULL);
1304 int button_graphic = mci->button_graphic;
1305 int font_text = (pos_text ? pos_text->font : -1);
1306 int font_input = (pos_input ? pos_input->font : -1);
1310 button_graphic = BUTTON_ACTIVE(button_graphic);
1311 font_text = FONT_ACTIVE(font_text);
1316 font_input = FONT_ACTIVE(font_input);
1319 if (visibleMenuPos(pos_button))
1321 struct MenuPosInfo *pos = pos_button;
1322 int x = mSX + pos->x;
1323 int y = mSY + pos->y;
1325 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1326 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1329 if (visibleTextPos(pos_text) && text != NULL)
1331 struct TextPosInfo *pos = pos_text;
1332 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1333 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1336 // (check why/if this is needed)
1337 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1339 DrawText(x, y, text, font_text);
1342 if (visibleTextPos(pos_input) && input != NULL)
1344 struct TextPosInfo *pos = pos_input;
1345 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1346 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1349 // (check why/if this is needed)
1350 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1352 DrawText(x, y, input, font_input);
1358 static void DrawCursorAndText_Main(int nr, boolean active_text,
1359 boolean pressed_button)
1361 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1365 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1366 boolean pressed_button)
1368 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1372 static struct MainControlInfo *getMainControlInfo(int nr)
1376 for (i = 0; main_controls[i].nr != -1; i++)
1377 if (main_controls[i].nr == nr)
1378 return &main_controls[i];
1383 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1388 int rect_x = ALIGNED_TEXT_XPOS(rect);
1389 int rect_y = ALIGNED_TEXT_YPOS(rect);
1391 return (x >= rect_x && x < rect_x + rect->width &&
1392 y >= rect_y && y < rect_y + rect->height);
1395 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1400 int rect_x = ALIGNED_TEXT_XPOS(rect);
1401 int rect_y = ALIGNED_TEXT_YPOS(rect);
1404 Debug("screens:insideTextPosRect",
1405 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1406 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1407 (x >= rect_x && x < rect_x + rect->width &&
1408 y >= rect_y && y < rect_y + rect->height));
1411 return (x >= rect_x && x < rect_x + rect->width &&
1412 y >= rect_y && y < rect_y + rect->height);
1415 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1417 int rect_width = preview->xsize * preview->tile_size;
1418 int rect_height = preview->ysize * preview->tile_size;
1419 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1420 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1422 return (x >= rect_x && x < rect_x + rect_width &&
1423 y >= rect_y && y < rect_y + rect_height);
1426 static void AdjustScrollbar(int id, int items_max, int items_visible,
1429 struct GadgetInfo *gi = screen_gadget[id];
1431 if (item_position > items_max - items_visible)
1432 item_position = items_max - items_visible;
1434 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1435 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1436 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1439 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1441 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1445 static void clearMenuListArea(void)
1447 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1449 // correct scrollbar position if placed outside menu (playfield) area
1450 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1451 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1453 // clear menu list area, but not title or scrollbar
1454 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1455 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1458 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1460 static int cursor_array[MAX_LEV_FIELDY];
1461 int x = amSX + TILEX * xpos;
1462 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1467 cursor_array[ypos] = graphic;
1469 graphic = cursor_array[ypos];
1473 graphic = BUTTON_ACTIVE(graphic);
1475 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1476 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1479 static void initCursor(int ypos, int graphic)
1481 drawCursorExt(0, ypos, FALSE, graphic);
1484 static void drawCursor(int ypos, boolean active)
1486 drawCursorExt(0, ypos, active, -1);
1489 static void drawCursorXY(int xpos, int ypos, int graphic)
1491 drawCursorExt(xpos, ypos, FALSE, graphic);
1494 static void drawChooseTreeCursor(int ypos, boolean active)
1496 drawCursorExt(0, ypos, active, -1);
1499 static int getChooseTreeEditFont(boolean active)
1501 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1504 static int getChooseTreeEditXPos(int pos)
1506 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1507 int xoffset = (has_scrollbar ? -1 : 0);
1508 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1509 int sx = amSX + xpos * TILEX;
1510 int font_nr = getChooseTreeEditFont(FALSE);
1511 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1513 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1516 static int getChooseTreeEditYPos(int ypos_raw)
1518 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1519 int sy = amSY + ypos * TILEY;
1524 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1526 int sx = getChooseTreeEditXPos(POS_LEFT);
1527 int sy = getChooseTreeEditYPos(ypos_raw);
1528 int font_nr = getChooseTreeEditFont(active);
1530 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1533 static void DrawHeadline(void)
1535 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1536 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1539 static void DrawTitleScreenImage(int nr, boolean initial)
1541 int graphic = getTitleScreenGraphic(nr, initial);
1542 Bitmap *bitmap = graphic_info[graphic].bitmap;
1543 int width = graphic_info[graphic].width;
1544 int height = graphic_info[graphic].height;
1545 int src_x = graphic_info[graphic].src_x;
1546 int src_y = graphic_info[graphic].src_y;
1552 if (width > WIN_XSIZE)
1554 // image width too large for window => center image horizontally
1555 src_x = (width - WIN_XSIZE) / 2;
1559 if (height > WIN_YSIZE)
1561 // image height too large for window => center image vertically
1562 src_y = (height - WIN_YSIZE) / 2;
1566 // always display title screens centered
1567 dst_x = (WIN_XSIZE - width) / 2;
1568 dst_y = (WIN_YSIZE - height) / 2;
1570 SetDrawBackgroundMask(REDRAW_ALL);
1571 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1573 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1575 if (DrawingOnBackground(dst_x, dst_y))
1576 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1578 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1580 redraw_mask = REDRAW_ALL;
1583 static void DrawTitleScreenMessage(int nr, boolean initial)
1585 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1586 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1588 if (filename == NULL)
1591 // force TITLE font on title message screen
1592 SetFontStatus(getTitleMessageGameMode(initial));
1594 // if chars *and* width set to "-1", automatically determine width
1595 if (tmi->chars == -1 && tmi->width == -1)
1596 tmi->width = viewport.window[game_status].width;
1598 // if lines *and* height set to "-1", automatically determine height
1599 if (tmi->lines == -1 && tmi->height == -1)
1600 tmi->height = viewport.window[game_status].height;
1602 // if chars set to "-1", automatically determine by text and font width
1603 if (tmi->chars == -1)
1604 tmi->chars = tmi->width / getFontWidth(tmi->font);
1606 tmi->width = tmi->chars * getFontWidth(tmi->font);
1608 // if lines set to "-1", automatically determine by text and font height
1609 if (tmi->lines == -1)
1610 tmi->lines = tmi->height / getFontHeight(tmi->font);
1612 tmi->height = tmi->lines * getFontHeight(tmi->font);
1614 // if x set to "-1", automatically determine by width and alignment
1616 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1618 // if y set to "-1", automatically determine by height and alignment
1620 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1622 SetDrawBackgroundMask(REDRAW_ALL);
1623 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1625 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1627 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1628 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1629 tmi->autowrap, tmi->centered, tmi->parse_comments);
1634 static void DrawTitleScreen(void)
1636 KeyboardAutoRepeatOff();
1638 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1641 static boolean CheckTitleScreen(boolean levelset_has_changed)
1643 static boolean show_title_initial = TRUE;
1644 boolean show_titlescreen = FALSE;
1646 // needed to be able to skip title screen, if no image or message defined
1647 InitializeTitleControls(show_title_initial);
1649 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1650 show_titlescreen = TRUE;
1652 // show initial title images and messages only once at program start
1653 show_title_initial = FALSE;
1655 return (show_titlescreen && num_title_screens > 0);
1658 void DrawMainMenu(void)
1660 static LevelDirTree *leveldir_last_valid = NULL;
1661 boolean levelset_has_changed = FALSE;
1662 int fade_mask = REDRAW_FIELD;
1664 LimitScreenUpdates(FALSE);
1666 FadeSetLeaveScreen();
1668 // do not fade out here -- function may continue and fade on editor screen
1671 FadeMenuSoundsAndMusic();
1673 ExpireSoundLoops(FALSE);
1675 KeyboardAutoRepeatOn();
1677 audio.sound_deactivated = FALSE;
1681 // needed if last screen was the playing screen, invoked from level editor
1682 if (level_editor_test_game)
1684 CloseDoor(DOOR_CLOSE_ALL);
1686 SetGameStatus(GAME_MODE_EDITOR);
1693 // leveldir_current may be invalid (level group, parent link, node copy)
1694 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1696 if (leveldir_current != leveldir_last_valid)
1698 UpdateLastPlayedLevels_TreeInfo();
1700 levelset_has_changed = TRUE;
1703 // store valid level series information
1704 leveldir_last_valid = leveldir_current;
1706 // needed if last screen (level choice) changed graphics, sounds or music
1707 ReloadCustomArtwork(0);
1709 if (CheckTitleScreen(levelset_has_changed))
1711 SetGameStatus(GAME_MODE_TITLE);
1718 if (redraw_mask & REDRAW_ALL)
1719 fade_mask = REDRAW_ALL;
1722 fade_mask = REDRAW_ALL;
1726 // needed if different viewport properties defined for menues
1727 ChangeViewportPropertiesIfNeeded();
1729 SetDrawtoField(DRAW_TO_BACKBUFFER);
1731 // level_nr may have been set to value over handicap with level editor
1732 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1733 level_nr = leveldir_current->handicap_level;
1735 LoadLevel(level_nr);
1736 LoadScore(level_nr);
1738 SaveLevelSetup_SeriesInfo();
1740 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1741 SetDrawDeactivationMask(REDRAW_NONE);
1742 SetDrawBackgroundMask(REDRAW_FIELD);
1744 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1747 if (fade_mask == REDRAW_ALL)
1748 RedrawGlobalBorder();
1753 InitializeMainControls();
1755 DrawCursorAndText_Main(-1, FALSE, FALSE);
1756 DrawPreviewLevelInitial();
1757 DrawNetworkPlayers();
1759 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1762 if (TAPE_IS_EMPTY(tape))
1764 DrawCompleteVideoDisplay();
1766 PlayMenuSoundsAndMusic();
1768 // create gadgets for main menu screen
1769 FreeScreenGadgets();
1770 CreateScreenGadgets();
1772 // may be required if audio buttons shown on tape and changed in setup menu
1774 CreateGameButtons();
1776 // map gadgets for main menu screen
1778 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1779 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1781 // copy actual game door content to door double buffer for OpenDoor()
1782 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1783 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1785 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1787 DrawMaskedBorder(fade_mask);
1792 // update screen area with special editor door
1793 redraw_mask |= REDRAW_ALL;
1796 SetMouseCursor(CURSOR_DEFAULT);
1798 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1800 SyncEmscriptenFilesystem();
1802 // needed once after program start or after user change
1803 CheckApiServerTasks();
1806 static void gotoTopLevelDir(void)
1808 // move upwards until inside (but not above) top level directory
1809 while (leveldir_current->node_parent &&
1810 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1812 // write a "path" into level tree for easy navigation to last level
1813 if (leveldir_current->node_parent->node_group->cl_first == -1)
1815 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1816 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1817 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1818 int cl_first, cl_cursor;
1820 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1821 cl_cursor = leveldir_pos - cl_first;
1823 leveldir_current->node_parent->node_group->cl_first = cl_first;
1824 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1827 leveldir_current = leveldir_current->node_parent;
1831 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1833 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1835 return (use_frame_counter ? video.frame_counter : Counter());
1838 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1839 struct TitleFadingInfo *fi)
1841 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1844 static void ResetTitleAutoDelay(unsigned int *counter_var,
1845 struct TitleFadingInfo *fi)
1847 *counter_var = getAutoDelayCounter(fi);
1850 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1852 static unsigned int title_delay = 0;
1853 static int title_screen_nr = 0;
1854 static int last_sound = -1, last_music = -1;
1855 boolean return_to_main_menu = FALSE;
1856 struct TitleControlInfo *tci;
1859 if (button == MB_MENU_INITIALIZE)
1862 title_screen_nr = 0;
1863 tci = &title_controls[title_screen_nr];
1865 SetAnimStatus(getTitleAnimMode(tci));
1867 last_sound = SND_UNDEFINED;
1868 last_music = MUS_UNDEFINED;
1870 if (num_title_screens != 0)
1872 FadeSetEnterScreen();
1874 // use individual title fading instead of global "enter screen" fading
1875 fading = getTitleFading(tci);
1878 if (game_status_last_screen == GAME_MODE_INFO)
1880 if (num_title_screens == 0)
1882 // switch game mode from title screen mode back to info screen mode
1883 SetGameStatus(GAME_MODE_INFO);
1885 // store that last screen was info screen, not main menu screen
1886 game_status_last_screen = GAME_MODE_INFO;
1888 DrawInfoScreen_NotAvailable("Title screen information:",
1889 "No title screen for this level set.");
1894 FadeMenuSoundsAndMusic();
1896 FadeOut(REDRAW_ALL);
1898 // title screens may have different window size
1899 ChangeViewportPropertiesIfNeeded();
1901 // only required to update logic for redrawing global border
1905 DrawTitleScreenImage(tci->local_nr, tci->initial);
1907 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1909 sound = getTitleSound(tci);
1910 music = getTitleMusic(tci);
1912 if (sound != last_sound)
1913 PlayMenuSoundExt(sound);
1914 if (music != last_music)
1915 PlayMenuMusicExt(music);
1920 SetMouseCursor(CURSOR_NONE);
1924 ResetTitleAutoDelay(&title_delay, &fading);
1929 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1930 button = MB_MENU_CHOICE;
1932 if (button == MB_MENU_LEAVE)
1934 return_to_main_menu = TRUE;
1936 else if (button == MB_MENU_CHOICE || dx)
1938 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1940 SetGameStatus(GAME_MODE_INFO);
1942 info_mode = INFO_MODE_MAIN;
1950 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
1952 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
1954 tci = &title_controls[title_screen_nr];
1956 SetAnimStatus(getTitleAnimMode(tci));
1958 sound = getTitleSound(tci);
1959 music = getTitleMusic(tci);
1961 if (last_sound != SND_UNDEFINED && sound != last_sound)
1962 FadeSound(last_sound);
1963 if (last_music != MUS_UNDEFINED && music != last_music)
1966 fading = getTitleFading(tci);
1968 FadeOut(REDRAW_ALL);
1971 DrawTitleScreenImage(tci->local_nr, tci->initial);
1973 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1975 sound = getTitleSound(tci);
1976 music = getTitleMusic(tci);
1978 if (sound != last_sound)
1979 PlayMenuSoundExt(sound);
1980 if (music != last_music)
1981 PlayMenuMusicExt(music);
1988 ResetTitleAutoDelay(&title_delay, &fading);
1992 FadeMenuSoundsAndMusic();
1994 return_to_main_menu = TRUE;
1998 if (return_to_main_menu)
2000 SetMouseCursor(CURSOR_DEFAULT);
2002 // force full menu screen redraw after displaying title screens
2003 redraw_mask = REDRAW_ALL;
2005 if (game_status_last_screen == GAME_MODE_INFO)
2007 SetGameStatus(GAME_MODE_INFO);
2009 info_mode = INFO_MODE_MAIN;
2013 else // default: return to main menu
2015 SetGameStatus(GAME_MODE_MAIN);
2022 static void HandleMainMenu_ToggleTeamMode(void)
2024 setup.team_mode = !setup.team_mode;
2026 InitializeMainControls();
2027 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2029 DrawPreviewPlayers();
2032 static void HandleMainMenu_SelectLevel(int step, int direction,
2033 int selected_level_nr)
2035 int old_level_nr = level_nr;
2038 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2039 new_level_nr = selected_level_nr;
2041 new_level_nr = old_level_nr + step * direction;
2043 if (new_level_nr < leveldir_current->first_level)
2044 new_level_nr = leveldir_current->first_level;
2045 if (new_level_nr > leveldir_current->last_level)
2046 new_level_nr = leveldir_current->last_level;
2048 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2050 // skipping levels is only allowed when trying to skip single level
2051 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2052 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2054 leveldir_current->handicap_level++;
2055 SaveLevelSetup_SeriesInfo();
2058 new_level_nr = leveldir_current->handicap_level;
2061 if (new_level_nr != old_level_nr)
2063 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2065 PlaySound(SND_MENU_ITEM_SELECTING);
2067 level_nr = new_level_nr;
2069 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2070 int2str(level_nr, menu.main.text.level_number.size),
2071 mci->pos_text->font);
2073 LoadLevel(level_nr);
2074 DrawPreviewLevelInitial();
2078 DrawCompleteVideoDisplay();
2080 SaveLevelSetup_SeriesInfo();
2082 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2084 // force redraw of playfield area (may be reset at this point)
2085 redraw_mask |= REDRAW_FIELD;
2089 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2091 static int choice = MAIN_CONTROL_GAME;
2092 static boolean button_pressed_last = FALSE;
2093 boolean button_pressed = FALSE;
2095 int i = 0; // needed to prevent compiler warning due to bad code below
2097 if (button == MB_MENU_INITIALIZE)
2099 DrawCursorAndText_Main(choice, TRUE, FALSE);
2104 if (mx || my) // mouse input
2108 for (i = 0; main_controls[i].nr != -1; i++)
2110 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2111 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2112 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2114 pos = main_controls[i].nr;
2120 // check if level preview was clicked
2121 if (insidePreviewRect(&preview, mx - SX, my - SY))
2122 pos = MAIN_CONTROL_GAME;
2124 // handle pressed/unpressed state for active/inactive menu buttons
2125 // (if pos != -1, "i" contains index position corresponding to "pos")
2127 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2128 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2129 button_pressed = TRUE;
2131 if (button_pressed != button_pressed_last)
2133 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2136 PlaySound(SND_MENU_BUTTON_PRESSING);
2138 PlaySound(SND_MENU_BUTTON_RELEASING);
2141 else if (dx || dy) // keyboard input
2143 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2144 choice == MAIN_CONTROL_SETUP))
2145 button = MB_MENU_CHOICE;
2150 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2152 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2154 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2156 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2158 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2160 CloseDoor(DOOR_CLOSE_2);
2162 SetGameStatus(GAME_MODE_LEVELNR);
2164 DrawChooseLevelNr();
2166 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2172 PlaySound(SND_MENU_ITEM_ACTIVATING);
2174 DrawCursorAndText_Main(choice, FALSE, FALSE);
2175 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2181 if (choice == MAIN_CONTROL_NAME)
2183 // special case: cursor left or right pressed -- toggle team mode
2184 HandleMainMenu_ToggleTeamMode();
2186 else if (choice != MAIN_CONTROL_INFO &&
2187 choice != MAIN_CONTROL_SETUP)
2189 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2195 PlaySound(SND_MENU_ITEM_SELECTING);
2197 if (pos == MAIN_CONTROL_NAME)
2200 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2202 // special case: menu text "name/team" clicked -- toggle team mode
2203 HandleMainMenu_ToggleTeamMode();
2207 if (setup.multiple_users)
2209 CloseDoor(DOOR_CLOSE_2);
2211 SetGameStatus(GAME_MODE_NAMES);
2213 DrawChoosePlayerName();
2217 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2223 else if (pos == MAIN_CONTROL_LEVELS)
2227 CloseDoor(DOOR_CLOSE_2);
2229 SetGameStatus(GAME_MODE_LEVELS);
2231 SaveLevelSetup_LastSeries();
2232 SaveLevelSetup_SeriesInfo();
2234 // restore level set if chosen from "last played level set" menu
2235 RestoreLastPlayedLevels(&leveldir_current);
2237 if (setup.internal.choose_from_top_leveldir)
2240 DrawChooseLevelSet();
2243 else if (pos == MAIN_CONTROL_SCORES)
2245 CloseDoor(DOOR_CLOSE_2);
2247 SetGameStatus(GAME_MODE_SCORES);
2249 DrawHallOfFame(level_nr);
2251 else if (pos == MAIN_CONTROL_EDITOR)
2253 if (leveldir_current->readonly &&
2254 setup.editor.show_read_only_warning)
2255 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2257 CloseDoor(DOOR_CLOSE_ALL);
2259 SetGameStatus(GAME_MODE_EDITOR);
2261 FadeSetEnterScreen();
2265 else if (pos == MAIN_CONTROL_INFO)
2267 CloseDoor(DOOR_CLOSE_2);
2269 SetGameStatus(GAME_MODE_INFO);
2271 info_mode = INFO_MODE_MAIN;
2275 else if (pos == MAIN_CONTROL_GAME)
2277 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2279 else if (pos == MAIN_CONTROL_SETUP)
2281 CloseDoor(DOOR_CLOSE_2);
2283 SetGameStatus(GAME_MODE_SETUP);
2285 setup_mode = SETUP_MODE_MAIN;
2289 else if (pos == MAIN_CONTROL_QUIT)
2291 SaveLevelSetup_LastSeries();
2292 SaveLevelSetup_SeriesInfo();
2294 #if defined(PLATFORM_EMSCRIPTEN)
2295 Request("Close the browser window to quit!", REQ_CONFIRM);
2297 if (!setup.ask_on_quit_program ||
2298 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2299 SetGameStatus(GAME_MODE_QUIT);
2305 button_pressed_last = button_pressed;
2309 // ============================================================================
2310 // info screen functions
2311 // ============================================================================
2313 static struct TokenInfo *info_info;
2314 static int num_info_info; // number of info entries shown on screen
2315 static int max_info_info; // total number of info entries in list
2317 static void execInfoTitleScreen(void)
2319 info_mode = INFO_MODE_TITLE;
2324 static void execInfoElements(void)
2326 info_mode = INFO_MODE_ELEMENTS;
2331 static void execInfoMusic(void)
2333 info_mode = INFO_MODE_MUSIC;
2338 static void execInfoCredits(void)
2340 info_mode = INFO_MODE_CREDITS;
2345 static void execInfoProgram(void)
2347 info_mode = INFO_MODE_PROGRAM;
2352 static void execInfoVersion(void)
2354 info_mode = INFO_MODE_VERSION;
2359 static void execInfoLevelSet(void)
2361 info_mode = INFO_MODE_LEVELSET;
2366 static void execExitInfo(void)
2368 SetGameStatus(GAME_MODE_MAIN);
2373 static struct TokenInfo info_info_main[] =
2375 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2376 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2377 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2378 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2379 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2380 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2381 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2382 { TYPE_EMPTY, NULL, "" },
2383 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2388 static int getMenuTextFont(int type)
2390 if (type & (TYPE_SWITCH |
2404 static struct TokenInfo *setup_info;
2405 static struct TokenInfo setup_info_input[];
2407 static struct TokenInfo *menu_info;
2409 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2410 int screen_pos, int menu_info_pos_raw,
2413 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2414 struct TokenInfo *ti = &token_info[pos];
2415 int xpos = MENU_SCREEN_START_XPOS;
2416 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2417 int font_nr = getMenuTextFont(ti->type);
2419 if (setup_mode == SETUP_MODE_INPUT)
2420 font_nr = FONT_MENU_1;
2423 font_nr = FONT_ACTIVE(font_nr);
2425 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2427 if (ti->type & ~TYPE_SKIP_ENTRY)
2428 drawCursor(screen_pos, active);
2431 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2434 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2437 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2440 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2443 static char *window_size_text;
2444 static char *scaling_type_text;
2445 static char *network_server_text;
2447 static void drawSetupValue(int, int);
2449 static void drawMenuInfoList(int first_entry, int num_page_entries,
2450 int max_page_entries)
2454 if (first_entry + num_page_entries > max_page_entries)
2457 clearMenuListArea();
2459 for (i = 0; i < num_page_entries; i++)
2461 int menu_info_pos = first_entry + i;
2462 struct TokenInfo *si = &menu_info[menu_info_pos];
2463 void *value_ptr = si->value;
2465 // set some entries to "unchangeable" according to other variables
2466 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2467 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2468 (value_ptr == &setup.sound_music && !audio.music_available) ||
2469 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2470 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2471 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2472 si->type |= TYPE_GHOSTED;
2474 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2475 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2476 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2477 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2478 else if (si->type & ~TYPE_SKIP_ENTRY)
2479 initCursor(i, IMG_MENU_BUTTON);
2481 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2483 if (si->type & TYPE_STRING)
2487 if (value_ptr == &network_server_text)
2488 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2490 if (gadget_id != -1)
2492 struct GadgetInfo *gi = screen_gadget[gadget_id];
2493 int xpos = MENU_SCREEN_START_XPOS;
2494 int ypos = MENU_SCREEN_START_YPOS + i;
2495 int x = mSX + xpos * 32;
2496 int y = mSY + ypos * 32;
2498 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2502 if (si->type & TYPE_VALUE &&
2503 menu_info == setup_info)
2504 drawSetupValue(i, menu_info_pos);
2508 static void DrawInfoScreen_Main(void)
2510 int fade_mask = REDRAW_FIELD;
2513 if (redraw_mask & REDRAW_ALL)
2514 fade_mask = REDRAW_ALL;
2517 fade_mask = REDRAW_ALL;
2520 FadeMenuSoundsAndMusic();
2522 FreeScreenGadgets();
2523 CreateScreenGadgets();
2525 // (needed after displaying title screens which disable auto repeat)
2526 KeyboardAutoRepeatOn();
2528 FadeSetLeaveScreen();
2532 // needed if different viewport properties defined for info screen
2533 ChangeViewportPropertiesIfNeeded();
2535 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2539 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2541 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2543 info_info = info_info_main;
2545 // determine maximal number of info entries that can be displayed on screen
2547 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2550 // determine maximal number of info entries available for menu of info screen
2552 for (i = 0; info_info[i].type != 0; i++)
2555 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2557 MapScreenGadgets(max_info_info);
2559 PlayMenuSoundsAndMusic();
2561 DrawMaskedBorder(fade_mask);
2566 static void changeSetupValue(int, int, int);
2568 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2569 int mode, int num_page_entries,
2570 int max_page_entries)
2572 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2573 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2574 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2575 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2576 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2577 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2578 int *num_page_entries_last = num_page_entries_all_last[game_status];
2579 int *choice_store = choice_stores[game_status];
2580 int *first_entry_store = first_entry_stores[game_status];
2581 int choice = choice_store[mode]; // starts with 0
2582 int first_entry = first_entry_store[mode]; // starts with 0
2584 int y = choice - first_entry;
2586 boolean position_set_by_scrollbar = (dx == 999);
2587 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2590 if (button == MB_MENU_INITIALIZE)
2592 // check if number of menu page entries has changed (may happen by change
2593 // of custom artwork definition value for 'list_size' for this menu screen)
2594 // (in this case, the last menu position most probably has to be corrected)
2595 if (num_page_entries != num_page_entries_last[mode])
2597 choice_store[mode] = first_entry_store[mode] = 0;
2599 choice = first_entry = 0;
2602 num_page_entries_last[mode] = num_page_entries;
2605 // advance to first valid menu entry
2606 while (choice < num_page_entries &&
2607 menu_info[choice].type & TYPE_SKIP_ENTRY)
2610 if (position_set_by_scrollbar)
2611 first_entry = first_entry_store[mode] = dy;
2613 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2614 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2616 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2618 if (choice < first_entry)
2620 choice = first_entry;
2622 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2625 else if (choice > first_entry + num_page_entries - 1)
2627 choice = first_entry + num_page_entries - 1;
2629 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2633 choice_store[mode] = choice;
2635 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2639 else if (button == MB_MENU_LEAVE)
2641 PlaySound(SND_MENU_ITEM_SELECTING);
2643 for (i = 0; i < max_page_entries; i++)
2645 if (menu_info[i].type & TYPE_LEAVE_MENU)
2647 void (*menu_callback_function)(void) = menu_info[i].value;
2651 menu_callback_function();
2653 break; // absolutely needed because function changes 'menu_info'!
2660 if (mx || my) // mouse input
2662 x = (mx - mSX) / 32;
2663 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2665 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2667 // move cursor instead of scrolling when already at start/end of list
2668 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2670 else if (dy == +1 * SCROLL_LINE &&
2671 first_entry + num_page_entries == max_page_entries)
2674 // handle scrolling screen one line or page
2676 y + dy > num_page_entries - 1)
2678 boolean redraw = FALSE;
2680 if (ABS(dy) == SCROLL_PAGE)
2681 step = num_page_entries - 1;
2683 if (dy < 0 && first_entry > 0)
2685 // scroll page/line up
2687 first_entry -= step;
2688 if (first_entry < 0)
2693 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2695 // scroll page/line down
2697 first_entry += step;
2698 if (first_entry + num_page_entries > max_page_entries)
2699 first_entry = MAX(0, max_page_entries - num_page_entries);
2706 choice += first_entry - first_entry_store[mode];
2708 if (choice < first_entry)
2710 choice = first_entry;
2712 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2715 else if (choice > first_entry + num_page_entries - 1)
2717 choice = first_entry + num_page_entries - 1;
2719 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2722 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2726 if (choice < first_entry ||
2727 choice > first_entry + num_page_entries - 1)
2728 first_entry += SIGN(dy);
2731 first_entry_store[mode] = first_entry;
2732 choice_store[mode] = choice;
2734 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2736 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2738 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2739 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2747 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2749 if (menu_info[choice].type & menu_navigation_type ||
2750 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2751 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2752 menu_info[choice].type & TYPE_PLAYER)
2753 button = MB_MENU_CHOICE;
2758 // jump to next non-empty menu entry (up or down)
2759 while (first_entry + y > 0 &&
2760 first_entry + y < max_page_entries - 1 &&
2761 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2764 if (!IN_VIS_MENU(x, y))
2766 choice += y - y_old;
2768 if (choice < first_entry)
2769 first_entry = choice;
2770 else if (choice > first_entry + num_page_entries - 1)
2771 first_entry = choice - num_page_entries + 1;
2773 if (first_entry >= 0 &&
2774 first_entry + num_page_entries <= max_page_entries)
2776 first_entry_store[mode] = first_entry;
2778 if (choice < first_entry)
2779 choice = first_entry;
2780 else if (choice > first_entry + num_page_entries - 1)
2781 choice = first_entry + num_page_entries - 1;
2783 choice_store[mode] = choice;
2785 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2787 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2789 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2790 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2797 if (!anyScrollbarGadgetActive() &&
2798 IN_VIS_MENU(x, y) &&
2799 mx < mx_right_border &&
2800 y >= 0 && y < num_page_entries)
2804 if (first_entry + y != choice &&
2805 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2807 PlaySound(SND_MENU_ITEM_ACTIVATING);
2809 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2810 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2812 choice = choice_store[mode] = first_entry + y;
2816 PlaySound(SND_MENU_ITEM_SELECTING);
2818 for (i = 0; menu_info[i].type != 0; i++)
2820 if (menu_info[i].type & TYPE_LEAVE_MENU)
2822 void (*menu_callback_function)(void) = menu_info[i].value;
2826 menu_callback_function();
2828 // absolutely needed because function changes 'menu_info'!
2836 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2838 PlaySound(SND_MENU_ITEM_SELECTING);
2840 // when selecting key headline, execute function for key value change
2841 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2842 menu_info[first_entry + y + 1].type & TYPE_KEY)
2845 // when selecting string value, execute function for list selection
2846 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2847 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2850 // when selecting string value, execute function for text input gadget
2851 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2852 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2855 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2857 void (*menu_callback_function)(void) =
2858 menu_info[first_entry + y].value;
2860 FadeSetFromType(menu_info[first_entry + y].type);
2862 menu_callback_function();
2864 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2866 void (*gadget_callback_function)(void) =
2867 menu_info[first_entry + y].value;
2869 gadget_callback_function();
2871 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2872 menu_info == setup_info)
2874 changeSetupValue(y, first_entry + y, dx);
2880 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2882 menu_info = info_info;
2884 HandleMenuScreen(mx, my, dx, dy, button,
2885 info_mode, num_info_info, max_info_info);
2888 static int getMenuFontSpacing(int spacing_height, int font_nr)
2890 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2892 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2896 static int getMenuTextSpacing(int spacing_height, int font_nr)
2898 return (getMenuFontSpacing(spacing_height, font_nr) +
2899 EXTRA_SPACING(game_status));
2902 static int getMenuTextStep(int spacing_height, int font_nr)
2904 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2907 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2909 int font_title = MENU_INFO_FONT_TITLE;
2910 int font_error = FONT_TEXT_2;
2911 int font_foot = MENU_INFO_FONT_FOOT;
2912 int spacing_title = menu.headline1_spacing_info[info_mode];
2913 int ystep_title = getMenuTextStep(spacing_title, font_title);
2914 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2915 int ystart2 = ystart1 + ystep_title;
2916 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2918 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2920 FadeOut(REDRAW_FIELD);
2925 DrawTextSCentered(ystart1, font_title, text_title);
2926 DrawTextSCentered(ystart2, font_error, text_error);
2928 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
2930 FadeIn(REDRAW_FIELD);
2933 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2935 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2936 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2937 int font_title = MENU_INFO_FONT_TITLE;
2938 int font_foot = MENU_INFO_FONT_FOOT;
2939 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2940 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2941 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2942 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2943 int ystep = MENU_SCREEN_INFO_YSTEP;
2944 int element, action, direction;
2952 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2953 infoscreen_step[i] = infoscreen_frame[i] = 0;
2958 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2959 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
2965 while (helpanim_info[j].element != HELPANIM_LIST_END)
2967 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2972 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2981 j += infoscreen_step[i - start];
2983 element = helpanim_info[j].element;
2984 action = helpanim_info[j].action;
2985 direction = helpanim_info[j].direction;
2988 element = EL_UNKNOWN;
2990 if (action != -1 && direction != -1)
2991 graphic = el_act_dir2img(element, action, direction);
2992 else if (action != -1)
2993 graphic = el_act2img(element, action);
2994 else if (direction != -1)
2995 graphic = el_dir2img(element, direction);
2997 graphic = el2img(element);
2999 delay = helpanim_info[j++].delay;
3004 if (infoscreen_frame[i - start] == 0)
3007 infoscreen_frame[i - start] = delay - 1;
3011 sync_frame = delay - infoscreen_frame[i - start];
3012 infoscreen_frame[i - start]--;
3015 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3017 if (!infoscreen_frame[i - start])
3018 infoscreen_step[i - start] = 0;
3022 if (!infoscreen_frame[i - start])
3023 infoscreen_step[i - start]++;
3024 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3030 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3032 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3033 graphic, sync_frame, USE_MASKING);
3036 DrawInfoScreen_HelpText(element, action, direction, i - start);
3041 redraw_mask |= REDRAW_FIELD;
3046 static char *getHelpText(int element, int action, int direction)
3048 char token[MAX_LINE_LEN];
3050 strcpy(token, element_info[element].token_name);
3053 strcat(token, element_action_info[action].suffix);
3055 if (direction != -1)
3056 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3058 return getHashEntry(helptext_info, token);
3061 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3063 int font_nr = FONT_INFO_ELEMENTS;
3064 int font_width = getFontWidth(font_nr);
3065 int font_height = getFontHeight(font_nr);
3066 int yoffset = (TILEX - 2 * font_height) / 2;
3067 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3068 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3069 int ystep = TILEY + 4;
3070 int pad_left = xstart - SX;
3071 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3072 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3073 int max_lines_per_text = 2;
3076 if (action != -1 && direction != -1) // element.action.direction
3077 text = getHelpText(element, action, direction);
3079 if (text == NULL && action != -1) // element.action
3080 text = getHelpText(element, action, -1);
3082 if (text == NULL && direction != -1) // element.direction
3083 text = getHelpText(element, -1, direction);
3085 if (text == NULL) // base element
3086 text = getHelpText(element, -1, -1);
3088 if (text == NULL) // not found
3089 text = "No description available";
3091 if (strlen(text) <= max_chars_per_line) // only one line of text
3092 ystart += getFontHeight(font_nr) / 2;
3094 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3095 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3096 TRUE, FALSE, FALSE);
3099 static void DrawInfoScreen_TitleScreen(void)
3101 SetGameStatus(GAME_MODE_TITLE);
3106 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3108 HandleTitleScreen(0, 0, dx, dy, button);
3111 static void DrawInfoScreen_Elements(void)
3113 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3115 FadeOut(REDRAW_FIELD);
3120 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3122 FadeIn(REDRAW_FIELD);
3125 void HandleInfoScreen_Elements(int dx, int dy, int button)
3127 static unsigned int info_delay = 0;
3128 static int num_anims;
3129 static int num_pages;
3131 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3134 if (button == MB_MENU_INITIALIZE)
3136 boolean new_element = TRUE;
3140 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3142 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3144 else if (new_element)
3147 new_element = FALSE;
3151 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3155 if (button == MB_MENU_LEAVE)
3157 PlaySound(SND_MENU_ITEM_SELECTING);
3159 info_mode = INFO_MODE_MAIN;
3164 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3166 if (button != MB_MENU_INITIALIZE)
3168 PlaySound(SND_MENU_ITEM_SELECTING);
3170 page += (dx < 0 ? -1 : +1);
3173 if (page < 0 || page >= num_pages)
3175 FadeMenuSoundsAndMusic();
3177 info_mode = INFO_MODE_MAIN;
3183 if (button != MB_MENU_INITIALIZE)
3184 FadeSetNextScreen();
3186 if (button != MB_MENU_INITIALIZE)
3187 FadeOut(REDRAW_FIELD);
3189 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3191 if (button != MB_MENU_INITIALIZE)
3192 FadeIn(REDRAW_FIELD);
3196 if (DelayReached(&info_delay, GameFrameDelay))
3197 if (page < num_pages)
3198 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3200 PlayMenuSoundIfLoop();
3204 static void DrawInfoScreen_Music(void)
3206 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3208 FadeOut(REDRAW_FIELD);
3215 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3217 FadeIn(REDRAW_FIELD);
3220 void HandleInfoScreen_Music(int dx, int dy, int button)
3222 static struct MusicFileInfo *list = NULL;
3223 int font_title = MENU_INFO_FONT_TITLE;
3224 int font_head = MENU_INFO_FONT_HEAD;
3225 int font_text = MENU_INFO_FONT_TEXT;
3226 int font_foot = MENU_INFO_FONT_FOOT;
3227 int spacing_title = menu.headline1_spacing_info[info_mode];
3228 int spacing_head = menu.headline2_spacing_info[info_mode];
3229 int ystep_title = getMenuTextStep(spacing_title, font_title);
3230 int ystep_head = getMenuTextStep(spacing_head, font_head);
3231 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3232 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3234 if (button == MB_MENU_INITIALIZE)
3236 list = music_file_info;
3240 FadeMenuSoundsAndMusic();
3245 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3246 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3252 if (button == MB_MENU_LEAVE)
3254 PlaySound(SND_MENU_ITEM_SELECTING);
3256 FadeMenuSoundsAndMusic();
3258 info_mode = INFO_MODE_MAIN;
3263 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3265 if (button != MB_MENU_INITIALIZE)
3267 PlaySound(SND_MENU_ITEM_SELECTING);
3270 list = (dx < 0 ? list->prev : list->next);
3275 FadeMenuSoundsAndMusic();
3277 info_mode = INFO_MODE_MAIN;
3283 FadeMenuSoundsAndMusic();
3285 if (list != music_file_info)
3286 FadeSetNextScreen();
3288 if (button != MB_MENU_INITIALIZE)
3289 FadeOut(REDRAW_FIELD);
3296 int sound = list->music;
3298 if (IS_LOOP_SOUND(sound))
3299 PlaySoundLoop(sound);
3303 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3307 int music = list->music;
3309 if (IS_LOOP_MUSIC(music))
3310 PlayMusicLoop(music);
3314 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3317 ystart += ystep_title;
3319 if (!strEqual(list->title, UNKNOWN_NAME))
3321 if (!strEqual(list->title_header, UNKNOWN_NAME))
3323 DrawTextSCentered(ystart, font_head, list->title_header);
3324 ystart += ystep_head;
3327 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3328 ystart += ystep_head;
3331 if (!strEqual(list->artist, UNKNOWN_NAME))
3333 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3334 DrawTextSCentered(ystart, font_head, list->artist_header);
3336 DrawTextSCentered(ystart, font_head, "by");
3338 ystart += ystep_head;
3340 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3341 ystart += ystep_head;
3344 if (!strEqual(list->album, UNKNOWN_NAME))
3346 if (!strEqual(list->album_header, UNKNOWN_NAME))
3347 DrawTextSCentered(ystart, font_head, list->album_header);
3349 DrawTextSCentered(ystart, font_head, "from the album");
3351 ystart += ystep_head;
3353 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3354 ystart += ystep_head;
3357 if (!strEqual(list->year, UNKNOWN_NAME))
3359 if (!strEqual(list->year_header, UNKNOWN_NAME))
3360 DrawTextSCentered(ystart, font_head, list->year_header);
3362 DrawTextSCentered(ystart, font_head, "from the year");
3364 ystart += ystep_head;
3366 DrawTextFCentered(ystart, font_text, "%s", list->year);
3367 ystart += ystep_head;
3370 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3372 if (button != MB_MENU_INITIALIZE)
3373 FadeIn(REDRAW_FIELD);
3376 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3377 PlaySoundLoop(list->music);
3380 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3382 int font_title = MENU_INFO_FONT_TITLE;
3383 int font_text = MENU_INFO_FONT_TEXT;
3384 int font_foot = MENU_INFO_FONT_FOOT;
3385 int spacing_title = menu.headline1_spacing_info[info_mode];
3386 int spacing_line = menu.line_spacing_info[info_mode];
3387 int ystep_title = getMenuTextStep(spacing_title, font_title);
3388 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3389 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3394 DrawTextSCentered(ystart, font_title, "Credits:");
3396 char *filename = getCreditsFilename(screen_nr, use_global_credits_screens);
3398 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3399 int chars = width / getFontWidth(font_text);
3400 int lines = height / getFontHeight(font_text);
3401 int padx = (width - chars * getFontWidth(font_text)) / 2;
3402 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3403 boolean autowrap = FALSE;
3404 boolean centered = TRUE;
3405 boolean parse_comments = TRUE;
3407 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3408 filename, font_text, chars, -1, lines, line_spacing, -1,
3409 autowrap, centered, parse_comments);
3411 boolean last_screen = (screen_nr == num_credits_screens - 1);
3412 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3414 DrawTextSCentered(ybottom, font_foot, text_foot);
3417 static void DrawInfoScreen_Credits(void)
3419 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3421 FadeMenuSoundsAndMusic();
3423 FadeOut(REDRAW_FIELD);
3425 HandleInfoScreen_Credits(0, 0, MB_MENU_INITIALIZE);
3427 FadeIn(REDRAW_FIELD);
3430 void HandleInfoScreen_Credits(int dx, int dy, int button)
3432 static int screen_nr = 0;
3434 if (button == MB_MENU_INITIALIZE)
3438 // determine number of (global or level set specific) credits screens
3439 for (i = 0; i < 2; i++)
3441 num_credits_screens = 0;
3442 use_global_credits_screens = i;
3444 while (getCreditsFilename(num_credits_screens,
3445 use_global_credits_screens) != NULL)
3446 num_credits_screens++;
3448 if (num_credits_screens > 0)
3452 if (num_credits_screens == 0)
3454 int font_title = MENU_INFO_FONT_TITLE;
3455 int font_foot = MENU_INFO_FONT_FOOT;
3456 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3457 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3462 DrawTextSCentered(ystart, font_title, "No credits for this level set.");
3463 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3470 DrawInfoScreen_CreditsScreen(screen_nr);
3472 else if (button == MB_MENU_LEAVE)
3474 PlaySound(SND_MENU_ITEM_SELECTING);
3476 info_mode = INFO_MODE_MAIN;
3481 else if (button == MB_MENU_CHOICE || dx)
3483 PlaySound(SND_MENU_ITEM_SELECTING);
3485 screen_nr += (dx < 0 ? -1 : +1);
3487 if (screen_nr < 0 || screen_nr >= num_credits_screens)
3489 FadeMenuSoundsAndMusic();
3491 info_mode = INFO_MODE_MAIN;
3497 FadeSetNextScreen();
3499 FadeOut(REDRAW_FIELD);
3501 DrawInfoScreen_CreditsScreen(screen_nr);
3503 FadeIn(REDRAW_FIELD);
3507 PlayMenuSoundIfLoop();
3511 static void DrawInfoScreen_ProgramScreen(int screen_nr)
3513 int font_title = MENU_INFO_FONT_TITLE;
3514 int font_text = MENU_INFO_FONT_TEXT;
3515 int font_foot = MENU_INFO_FONT_FOOT;
3516 int spacing_title = menu.headline1_spacing_info[info_mode];
3517 int spacing_line = menu.line_spacing_info[info_mode];
3518 int ystep_title = getMenuTextStep(spacing_title, font_title);
3519 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3520 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3525 DrawTextSCentered(ystart, font_title, "Program Information:");
3527 char *filename = getProgramInfoFilename(screen_nr);
3529 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3530 int chars = width / getFontWidth(font_text);
3531 int lines = height / getFontHeight(font_text);
3532 int padx = (width - chars * getFontWidth(font_text)) / 2;
3533 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3534 boolean autowrap = FALSE;
3535 boolean centered = TRUE;
3536 boolean parse_comments = TRUE;
3538 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3539 filename, font_text, chars, -1, lines, line_spacing, -1,
3540 autowrap, centered, parse_comments);
3542 boolean last_screen = (screen_nr == num_program_info_screens - 1);
3543 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3545 DrawTextSCentered(ybottom, font_foot, text_foot);
3548 static void DrawInfoScreen_Program(void)
3550 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3552 FadeMenuSoundsAndMusic();
3554 FadeOut(REDRAW_FIELD);
3556 HandleInfoScreen_Program(0, 0, MB_MENU_INITIALIZE);
3558 FadeIn(REDRAW_FIELD);
3561 void HandleInfoScreen_Program(int dx, int dy, int button)
3563 static int screen_nr = 0;
3565 if (button == MB_MENU_INITIALIZE)
3567 // determine number of program info screens
3568 num_program_info_screens = 0;
3570 while (getProgramInfoFilename(num_program_info_screens) != NULL)
3571 num_program_info_screens++;
3573 if (num_program_info_screens == 0)
3575 int font_title = MENU_INFO_FONT_TITLE;
3576 int font_foot = MENU_INFO_FONT_FOOT;
3577 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3578 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3583 DrawTextSCentered(ystart, font_title, "No program info available.");
3584 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3591 DrawInfoScreen_ProgramScreen(screen_nr);
3593 else if (button == MB_MENU_LEAVE)
3595 PlaySound(SND_MENU_ITEM_SELECTING);
3597 info_mode = INFO_MODE_MAIN;
3602 else if (button == MB_MENU_CHOICE || dx)
3604 PlaySound(SND_MENU_ITEM_SELECTING);
3606 screen_nr += (dx < 0 ? -1 : +1);
3608 if (screen_nr < 0 || screen_nr >= num_program_info_screens)
3610 FadeMenuSoundsAndMusic();
3612 info_mode = INFO_MODE_MAIN;
3618 FadeSetNextScreen();
3620 FadeOut(REDRAW_FIELD);
3622 DrawInfoScreen_ProgramScreen(screen_nr);
3624 FadeIn(REDRAW_FIELD);
3628 PlayMenuSoundIfLoop();
3632 static void DrawInfoScreen_Version(void)
3634 int font_title = MENU_INFO_FONT_TITLE;
3635 int font_head = MENU_INFO_FONT_HEAD;
3636 int font_text = MENU_INFO_FONT_TEXT;
3637 int font_foot = MENU_INFO_FONT_FOOT;
3638 int spacing_title = menu.headline1_spacing_info[info_mode];
3639 int spacing_head = menu.headline2_spacing_info[info_mode];
3640 int spacing_para = menu.paragraph_spacing_info[info_mode];
3641 int spacing_line = menu.line_spacing_info[info_mode];
3642 int xstep = getFontWidth(font_text);
3643 int ystep_title = getMenuTextStep(spacing_title, font_title);
3644 int ystep_head = getMenuTextStep(spacing_head, font_head);
3645 int ystep_para = getMenuTextStep(spacing_para, font_text);
3646 int ystep_line = getMenuTextStep(spacing_line, font_text);
3647 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3648 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3649 int xstart1 = mSX - SX + 2 * xstep;
3650 int xstart2 = mSX - SX + 18 * xstep;
3651 int xstart3 = mSX - SX + 28 * xstep;
3652 SDL_version sdl_version_compiled;
3653 const SDL_version *sdl_version_linked;
3654 int driver_name_len = 10;
3655 SDL_version sdl_version_linked_ext;
3656 const char *driver_name = NULL;
3658 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3660 FadeOut(REDRAW_FIELD);
3665 DrawTextSCentered(ystart, font_title, "Version Information:");
3666 ystart += ystep_title;
3668 DrawTextF(xstart1, ystart, font_head, "Name");
3669 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3670 ystart += ystep_line;
3672 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3674 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3675 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3676 ystart += ystep_line;
3678 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3679 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3680 ystart += ystep_line;
3684 DrawTextF(xstart1, ystart, font_head, "Version");
3685 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3686 ystart += ystep_line;
3689 DrawTextF(xstart1, ystart, font_head, "Platform");
3690 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3692 PLATFORM_XX_BIT_STRING);
3693 ystart += ystep_line;
3695 DrawTextF(xstart1, ystart, font_head, "Target");
3696 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3697 ystart += ystep_line;
3699 DrawTextF(xstart1, ystart, font_head, "Source date");
3700 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3701 ystart += ystep_line;
3703 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3704 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3705 ystart += ystep_para;
3707 DrawTextF(xstart1, ystart, font_head, "Library");
3708 DrawTextF(xstart2, ystart, font_head, "compiled");
3709 DrawTextF(xstart3, ystart, font_head, "linked");
3710 ystart += ystep_head;
3712 SDL_VERSION(&sdl_version_compiled);
3713 SDL_GetVersion(&sdl_version_linked_ext);
3714 sdl_version_linked = &sdl_version_linked_ext;
3716 DrawTextF(xstart1, ystart, font_text, "SDL");
3717 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3718 sdl_version_compiled.major,
3719 sdl_version_compiled.minor,
3720 sdl_version_compiled.patch);
3721 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3722 sdl_version_linked->major,
3723 sdl_version_linked->minor,
3724 sdl_version_linked->patch);
3725 ystart += ystep_line;
3727 SDL_IMAGE_VERSION(&sdl_version_compiled);
3728 sdl_version_linked = IMG_Linked_Version();
3730 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3731 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3732 sdl_version_compiled.major,
3733 sdl_version_compiled.minor,
3734 sdl_version_compiled.patch);
3735 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3736 sdl_version_linked->major,
3737 sdl_version_linked->minor,
3738 sdl_version_linked->patch);
3739 ystart += ystep_line;
3741 SDL_MIXER_VERSION(&sdl_version_compiled);
3742 sdl_version_linked = Mix_Linked_Version();
3744 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3745 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3746 sdl_version_compiled.major,
3747 sdl_version_compiled.minor,
3748 sdl_version_compiled.patch);
3749 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3750 sdl_version_linked->major,
3751 sdl_version_linked->minor,
3752 sdl_version_linked->patch);
3753 ystart += ystep_line;
3755 SDL_NET_VERSION(&sdl_version_compiled);
3756 sdl_version_linked = SDLNet_Linked_Version();
3758 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3759 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3760 sdl_version_compiled.major,
3761 sdl_version_compiled.minor,
3762 sdl_version_compiled.patch);
3763 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3764 sdl_version_linked->major,
3765 sdl_version_linked->minor,
3766 sdl_version_linked->patch);
3767 ystart += ystep_para;
3769 DrawTextF(xstart1, ystart, font_head, "Driver");
3770 DrawTextF(xstart2, ystart, font_head, "Requested");
3771 DrawTextF(xstart3, ystart, font_head, "Used");
3772 ystart += ystep_head;
3775 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3777 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3778 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3779 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3780 ystart += ystep_line;
3783 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3785 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3786 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3787 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3788 ystart += ystep_line;
3791 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3793 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3794 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3795 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3797 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3799 FadeIn(REDRAW_FIELD);
3802 void HandleInfoScreen_Version(int button)
3804 if (button == MB_MENU_LEAVE)
3806 PlaySound(SND_MENU_ITEM_SELECTING);
3808 info_mode = INFO_MODE_MAIN;
3813 else if (button == MB_MENU_CHOICE)
3815 PlaySound(SND_MENU_ITEM_SELECTING);
3817 FadeMenuSoundsAndMusic();
3819 info_mode = INFO_MODE_MAIN;
3824 PlayMenuSoundIfLoop();
3828 static void DrawInfoScreen_LevelSet(void)
3830 struct TitleMessageInfo *tmi = &readme;
3831 char *filename = getLevelSetInfoFilename();
3832 char *title = "Level Set Information:";
3833 int font_foot = MENU_INFO_FONT_FOOT;
3834 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3835 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3837 if (filename == NULL)
3839 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3844 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3846 FadeOut(REDRAW_FIELD);
3851 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3853 // if x position set to "-1", automatically determine by playfield width
3855 tmi->x = SXSIZE / 2;
3857 // if y position set to "-1", use static default value
3861 // if width set to "-1", automatically determine by playfield width
3862 if (tmi->width == -1)
3863 tmi->width = SXSIZE - 2 * TILEX;
3865 // if height set to "-1", automatically determine by playfield height
3866 if (tmi->height == -1)
3867 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3869 // if chars set to "-1", automatically determine by text and font width
3870 if (tmi->chars == -1)
3871 tmi->chars = tmi->width / getFontWidth(tmi->font);
3873 tmi->width = tmi->chars * getFontWidth(tmi->font);
3875 // if lines set to "-1", automatically determine by text and font height
3876 if (tmi->lines == -1)
3877 tmi->lines = tmi->height / getFontHeight(tmi->font);
3879 tmi->height = tmi->lines * getFontHeight(tmi->font);
3881 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3882 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3883 tmi->autowrap, tmi->centered, tmi->parse_comments);
3885 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3887 FadeIn(REDRAW_FIELD);
3890 static void HandleInfoScreen_LevelSet(int button)
3892 if (button == MB_MENU_LEAVE)
3894 PlaySound(SND_MENU_ITEM_SELECTING);
3896 info_mode = INFO_MODE_MAIN;
3901 else if (button == MB_MENU_CHOICE)
3903 PlaySound(SND_MENU_ITEM_SELECTING);
3905 FadeMenuSoundsAndMusic();
3907 info_mode = INFO_MODE_MAIN;
3912 PlayMenuSoundIfLoop();
3916 static void DrawInfoScreen(void)
3918 if (info_mode == INFO_MODE_TITLE)
3919 DrawInfoScreen_TitleScreen();
3920 else if (info_mode == INFO_MODE_ELEMENTS)
3921 DrawInfoScreen_Elements();
3922 else if (info_mode == INFO_MODE_MUSIC)
3923 DrawInfoScreen_Music();
3924 else if (info_mode == INFO_MODE_CREDITS)
3925 DrawInfoScreen_Credits();
3926 else if (info_mode == INFO_MODE_PROGRAM)
3927 DrawInfoScreen_Program();
3928 else if (info_mode == INFO_MODE_VERSION)
3929 DrawInfoScreen_Version();
3930 else if (info_mode == INFO_MODE_LEVELSET)
3931 DrawInfoScreen_LevelSet();
3933 DrawInfoScreen_Main();
3935 if (info_mode != INFO_MODE_MAIN &&
3936 info_mode != INFO_MODE_TITLE &&
3937 info_mode != INFO_MODE_MUSIC)
3938 PlayMenuSoundsAndMusic();
3941 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3943 if (info_mode == INFO_MODE_TITLE)
3944 HandleInfoScreen_TitleScreen(dx, dy, button);
3945 else if (info_mode == INFO_MODE_ELEMENTS)
3946 HandleInfoScreen_Elements(dx, dy, button);
3947 else if (info_mode == INFO_MODE_MUSIC)
3948 HandleInfoScreen_Music(dx, dy, button);
3949 else if (info_mode == INFO_MODE_CREDITS)
3950 HandleInfoScreen_Credits(dx, dy, button);
3951 else if (info_mode == INFO_MODE_PROGRAM)
3952 HandleInfoScreen_Program(dx, dy, button);
3953 else if (info_mode == INFO_MODE_VERSION)
3954 HandleInfoScreen_Version(button);
3955 else if (info_mode == INFO_MODE_LEVELSET)
3956 HandleInfoScreen_LevelSet(button);
3958 HandleInfoScreen_Main(mx, my, dx, dy, button);
3962 // ============================================================================
3963 // rename player API functions
3964 // ============================================================================
3966 struct ApiRenamePlayerThreadData
3972 static void *CreateThreadData_ApiRenamePlayer(void)
3974 struct ApiRenamePlayerThreadData *data =
3975 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
3977 data->player_name = getStringCopy(setup.player_name);
3978 data->player_uuid = getStringCopy(setup.player_uuid);
3983 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
3985 struct ApiRenamePlayerThreadData *data = data_raw;
3987 checked_free(data->player_name);
3988 checked_free(data->player_uuid);
3992 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
3995 struct ApiRenamePlayerThreadData *data = data_raw;
3996 char *player_name_raw = data->player_name;
3997 char *player_uuid_raw = data->player_uuid;
3999 request->hostname = setup.api_server_hostname;
4000 request->port = API_SERVER_PORT;
4001 request->method = API_SERVER_METHOD;
4002 request->uri = API_SERVER_URI_RENAME;
4004 char *player_name = getEscapedJSON(player_name_raw);
4005 char *player_uuid = getEscapedJSON(player_uuid_raw);
4007 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4010 " \"game_version\": \"%s\",\n"
4011 " \"game_platform\": \"%s\",\n"
4012 " \"name\": \"%s\",\n"
4013 " \"uuid\": \"%s\"\n"
4015 getPasswordJSON(setup.api_server_password),
4016 getProgramRealVersionString(),
4017 getProgramPlatformString(),
4021 checked_free(player_name);
4022 checked_free(player_uuid);
4024 ConvertHttpRequestBodyToServerEncoding(request);
4029 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4032 // nothing to do here
4035 #if defined(PLATFORM_EMSCRIPTEN)
4036 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4037 void *buffer, unsigned int size)
4039 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4041 if (response != NULL)
4043 HandleResponse_ApiRenamePlayer(response, data_raw);
4045 checked_free(response);
4049 Error("server response too large to handle (%d bytes)", size);
4052 FreeThreadData_ApiRenamePlayer(data_raw);
4055 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4056 int code, const char *status)
4058 Error("server failed to handle request: %d %s", code, status);
4060 FreeThreadData_ApiRenamePlayer(data_raw);
4063 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4064 int bytes, int size)
4066 // nothing to do here
4069 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4072 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4074 FreeThreadData_ApiRenamePlayer(data_raw);
4079 emscripten_async_wget2_data(request->uri,
4084 Emscripten_ApiRenamePlayer_Loaded,
4085 Emscripten_ApiRenamePlayer_Failed,
4086 Emscripten_ApiRenamePlayer_Progress);
4091 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4092 struct HttpResponse *response,
4095 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4098 if (!DoHttpRequest(request, response))
4100 Error("HTTP request failed: %s", GetHttpError());
4105 if (!HTTP_SUCCESS(response->status_code))
4107 Error("server failed to handle request: %d %s",
4108 response->status_code,
4109 response->status_text);
4114 HandleResponse_ApiRenamePlayer(response, data_raw);
4117 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4118 struct HttpResponse *response,
4121 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4123 FreeThreadData_ApiRenamePlayer(data_raw);
4127 static int ApiRenamePlayerThread(void *data_raw)
4129 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4130 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4132 program.api_thread_count++;
4134 #if defined(PLATFORM_EMSCRIPTEN)
4135 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4137 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4140 program.api_thread_count--;
4142 checked_free(request);
4143 checked_free(response);
4148 static void ApiRenamePlayerAsThread(void)
4150 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4152 ExecuteAsThread(ApiRenamePlayerThread,
4153 "ApiRenamePlayer", data,
4154 "rename player on server");
4158 // ============================================================================
4159 // reset player UUID API functions
4160 // ============================================================================
4162 struct ApiResetUUIDThreadData
4165 char *player_uuid_old;
4166 char *player_uuid_new;
4169 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4171 struct ApiResetUUIDThreadData *data =
4172 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4174 data->player_name = getStringCopy(setup.player_name);
4175 data->player_uuid_old = getStringCopy(setup.player_uuid);
4176 data->player_uuid_new = getStringCopy(uuid_new);
4181 static void FreeThreadData_ApiResetUUID(void *data_raw)
4183 struct ApiResetUUIDThreadData *data = data_raw;
4185 checked_free(data->player_name);
4186 checked_free(data->player_uuid_old);
4187 checked_free(data->player_uuid_new);
4191 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4194 struct ApiResetUUIDThreadData *data = data_raw;
4195 char *player_name_raw = data->player_name;
4196 char *player_uuid_old_raw = data->player_uuid_old;
4197 char *player_uuid_new_raw = data->player_uuid_new;
4199 request->hostname = setup.api_server_hostname;
4200 request->port = API_SERVER_PORT;
4201 request->method = API_SERVER_METHOD;
4202 request->uri = API_SERVER_URI_RESETUUID;
4204 char *player_name = getEscapedJSON(player_name_raw);
4205 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4206 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4208 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4211 " \"game_version\": \"%s\",\n"
4212 " \"game_platform\": \"%s\",\n"
4213 " \"name\": \"%s\",\n"
4214 " \"uuid_old\": \"%s\",\n"
4215 " \"uuid_new\": \"%s\"\n"
4217 getPasswordJSON(setup.api_server_password),
4218 getProgramRealVersionString(),
4219 getProgramPlatformString(),
4224 checked_free(player_name);
4225 checked_free(player_uuid_old);
4226 checked_free(player_uuid_new);
4228 ConvertHttpRequestBodyToServerEncoding(request);
4233 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4236 struct ApiResetUUIDThreadData *data = data_raw;
4238 // upgrade player UUID in server setup file
4239 setup.player_uuid = getStringCopy(data->player_uuid_new);
4240 setup.player_version = 2;
4242 SaveSetup_ServerSetup();
4245 #if defined(PLATFORM_EMSCRIPTEN)
4246 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4247 void *buffer, unsigned int size)
4249 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4251 if (response != NULL)
4253 HandleResponse_ApiResetUUID(response, data_raw);
4255 checked_free(response);
4259 Error("server response too large to handle (%d bytes)", size);
4262 FreeThreadData_ApiResetUUID(data_raw);
4265 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4266 int code, const char *status)
4268 Error("server failed to handle request: %d %s", code, status);
4270 FreeThreadData_ApiResetUUID(data_raw);
4273 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4274 int bytes, int size)
4276 // nothing to do here
4279 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4282 if (!SetRequest_ApiResetUUID(request, data_raw))
4284 FreeThreadData_ApiResetUUID(data_raw);
4289 emscripten_async_wget2_data(request->uri,
4294 Emscripten_ApiResetUUID_Loaded,
4295 Emscripten_ApiResetUUID_Failed,
4296 Emscripten_ApiResetUUID_Progress);
4301 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4302 struct HttpResponse *response,
4305 if (!SetRequest_ApiResetUUID(request, data_raw))
4308 if (!DoHttpRequest(request, response))
4310 Error("HTTP request failed: %s", GetHttpError());
4315 if (!HTTP_SUCCESS(response->status_code))
4317 Error("server failed to handle request: %d %s",
4318 response->status_code,
4319 response->status_text);
4324 HandleResponse_ApiResetUUID(response, data_raw);
4327 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4328 struct HttpResponse *response,
4331 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4333 FreeThreadData_ApiResetUUID(data_raw);
4337 static int ApiResetUUIDThread(void *data_raw)
4339 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4340 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4342 program.api_thread_count++;
4344 #if defined(PLATFORM_EMSCRIPTEN)
4345 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4347 ApiResetUUID_HttpRequest(request, response, data_raw);
4350 program.api_thread_count--;
4352 checked_free(request);
4353 checked_free(response);
4358 static void ApiResetUUIDAsThread(char *uuid_new)
4360 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4362 ExecuteAsThread(ApiResetUUIDThread,
4363 "ApiResetUUID", data,
4364 "reset UUID on server");
4368 // ============================================================================
4369 // type name functions
4370 // ============================================================================
4372 static TreeInfo *type_name_node = NULL;
4373 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4374 static int type_name_nr = 0;
4376 static int getPlayerNameColor(char *name)
4378 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4381 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4384 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4385 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4386 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4387 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4388 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4389 int font_width = getFontWidth(font_nr);
4391 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4393 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4395 pos->width = strlen(text) * font_width;
4396 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4398 DrawText(sx, sy, text, font_nr);
4401 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4403 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4405 *pos = *mci->pos_input;
4407 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4409 TreeInfo *ti = player_name_current;
4410 int first_entry = ti->cl_first;
4411 int entry_pos = first_entry + ti->cl_cursor;
4412 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4413 int xpos = MENU_SCREEN_START_XPOS;
4414 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4416 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4417 type_name_nr = entry_pos;
4419 strcpy(name, type_name_node->name);
4423 pos->width = MAX_PLAYER_NAME_LEN * 32;
4427 type_name_nr = user.nr;
4429 strcpy(name, setup.player_name);
4432 strcpy(type_name_last, name);
4434 if (strEqual(name, EMPTY_PLAYER_NAME))
4437 *xpos = strlen(name);
4440 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4442 // change name of edited user in global list of user names
4443 setString(&global.user_names[type_name_nr], name);
4445 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4447 TreeInfo *node = type_name_node;
4449 // change name of edited user in local menu tree structure
4450 setString(&node->name, name);
4451 setString(&node->name_sorting, name);
4453 node->color = getPlayerNameColor(name);
4454 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4458 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4461 boolean reset_setup = strEqual(name, "");
4462 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4463 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4466 strcpy(name, type_name_last);
4468 if (strEqual(name, ""))
4469 strcpy(name, EMPTY_PLAYER_NAME);
4471 setTypeNameValues_Name(name, pos);
4473 // if player name not changed, no further action required
4474 if (strEqual(name, type_name_last))
4477 // redraw player name before (possibly) opening request dialogs
4478 drawTypeNameText(name, pos, FALSE);
4480 int last_user_nr = user.nr;
4482 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4484 // save setup of currently active user (may differ from edited user)
4487 // temporarily change active user to edited user
4488 user.nr = type_name_nr;
4491 Request("Use current setup values for the new player?", REQ_ASK))
4493 // use current setup values for new user, but create new player UUID
4494 setup.player_uuid = getStringCopy(getUUID());
4498 // load setup for existing user (or start with defaults for new user)
4503 char *setup_filename = getSetupFilename();
4504 boolean setup_exists = fileExists(setup_filename);
4506 // change name of edited user in setup structure
4507 strcpy(setup.player_name, name);
4509 // save setup of edited user
4512 // change name of edited user on score server
4513 ApiRenamePlayerAsThread();
4515 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4519 if (Request("Reset setup values for this player?", REQ_ASK))
4521 // remove setup config file
4522 unlink(setup_filename);
4524 // set player name to default player name
4527 // update player name used by name typing functions
4528 strcpy(name, setup.player_name);
4530 setTypeNameValues_Name(name, pos);
4533 else if (remove_user && type_name_nr != 0)
4535 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4537 char *user_dir = getUserGameDataDir();
4538 char *user_dir_removed =
4539 getStringCat3WithSeparator(user_dir, "REMOVED",
4540 getCurrentTimestamp(), ".");
4542 if (rename(user_dir, user_dir_removed) != 0)
4543 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4545 checked_free(user_dir_removed);
4548 else if (create_user && type_name_nr != 0 && !setup_exists)
4550 if (Request("Create empty level set for the new player?", REQ_ASK))
4552 char *levelset_subdir = getNewUserLevelSubdir();
4554 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4556 AddUserLevelSetToLevelInfo(levelset_subdir);
4558 LevelDirTree *leveldir_current_last = leveldir_current;
4560 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4563 // set level number of newly created level set to default value
4564 LoadLevelSetup_SeriesInfo();
4566 // set newly created level set as current level set for new user
4567 SaveLevelSetup_LastSeries();
4568 SaveLevelSetup_SeriesInfo();
4570 leveldir_current = leveldir_current_last;
4574 Request("Creating new level set failed!", REQ_CONFIRM);
4579 // restore currently active user
4580 user.nr = last_user_nr;
4582 // restore setup of currently active user
4585 // restore last level set of currently active user
4586 LoadLevelSetup_LastSeries();
4587 LoadLevelSetup_SeriesInfo();
4591 static void HandleTypeNameExt(boolean initialize, Key key)
4593 static struct TextPosInfo pos_name = { 0 };
4594 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4595 static int xpos = 0;
4596 struct TextPosInfo *pos = &pos_name;
4597 char key_char = getValidConfigValueChar(getCharFromKey(key));
4598 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4599 boolean active = TRUE;
4603 getTypeNameValues(name, pos, &xpos);
4605 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4606 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4608 StartTextInput(sx, sy, pos->width, pos->height);
4610 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4612 name[xpos] = key_char;
4617 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4623 else if (key == KSYM_Return || key == KSYM_Escape)
4625 boolean changed = (key == KSYM_Return);
4629 setTypeNameValues(name, pos, changed);
4634 drawTypeNameText(name, pos, active);
4638 SetGameStatus(game_status_last_screen);
4640 if (game_status == GAME_MODE_MAIN)
4641 InitializeMainControls();
4645 static void DrawTypeName(void)
4647 HandleTypeNameExt(TRUE, 0);
4650 void HandleTypeName(Key key)
4652 HandleTypeNameExt(FALSE, key);
4656 // ============================================================================
4657 // tree menu functions
4658 // ============================================================================
4660 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4662 if (game_status != GAME_MODE_SETUP ||
4663 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4666 int max_text_size = 0;
4669 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4670 max_text_size = MAX(max_text_size, strlen(node->name));
4672 int num_entries = numTreeInfoInGroup(ti);
4673 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4674 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4675 int text_width = max_text_size * getFontWidth(font_nr);
4676 int button_width = SC_MENUBUTTON_XSIZE;
4677 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4678 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4679 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4680 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4681 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4682 int align_xoffset = MAX(0, align_xoffset_raw);
4684 return align_xoffset;
4687 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4689 if (game_status != GAME_MODE_SETUP ||
4690 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4693 int num_entries = numTreeInfoInGroup(ti);
4694 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4695 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4696 int font_height = getFontHeight(font_nr);
4697 int text_height = font_height * num_page_entries;
4698 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4699 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4700 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4701 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4702 int align_yoffset = MAX(0, align_yoffset_raw);
4704 return align_yoffset;
4707 static void DrawChooseTree(TreeInfo **ti_ptr)
4709 int fade_mask = REDRAW_FIELD;
4710 boolean restart_music = (game_status != game_status_last_screen &&
4711 game_status_last_screen != GAME_MODE_SCOREINFO);
4714 fade_mask = REDRAW_ALL;
4716 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4718 if (game_status == GAME_MODE_SETUP)
4722 else // GAME_MODE_LEVELS
4724 SetGameStatus(GAME_MODE_MAIN);
4734 FreeScreenGadgets();
4735 CreateScreenGadgets();
4738 FadeMenuSoundsAndMusic();
4742 // needed if different viewport properties defined for this screen
4743 ChangeViewportPropertiesIfNeeded();
4745 if (game_status == GAME_MODE_NAMES)
4746 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4747 else if (game_status == GAME_MODE_LEVELNR)
4748 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4749 else if (game_status == GAME_MODE_LEVELS)
4750 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4751 else if (game_status == GAME_MODE_SCORES)
4752 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4756 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4758 // map gadgets for high score screen
4759 if (game_status == GAME_MODE_SCORES)
4760 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4762 MapScreenTreeGadgets(*ti_ptr);
4764 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4766 DrawMaskedBorder(fade_mask);
4769 PlayMenuSoundsAndMusic();
4774 static int getChooseTreeFont(TreeInfo *node, boolean active)
4776 if (game_status == GAME_MODE_SCORES)
4777 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4779 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4782 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4784 int num_entries = numTreeInfoInGroup(ti);
4785 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4786 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4787 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4788 int first_entry = ti->cl_first;
4789 int entry_pos = first_entry + y;
4790 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4791 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4792 int font_nr = getChooseTreeFont(node, active);
4793 int font_xoffset = getFontDrawOffsetX(font_nr);
4794 int xpos = MENU_SCREEN_START_XPOS;
4795 int ypos = MENU_SCREEN_START_YPOS + y;
4796 int startdx = xpos * 32;
4797 int startdy = ypos * 32;
4798 int startx = amSX + startdx;
4799 int starty = amSY + startdy;
4800 int startx_text = startx + font_xoffset;
4801 int endx_text = amSX + screen_width;
4802 int max_text_size = endx_text - startx_text;
4803 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4804 char buffer[max_buffer_len + 1];
4806 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4808 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4809 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4810 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4811 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4812 int font_size_1 = getFontWidth(font_nr1);
4813 int font_size_3 = getFontWidth(font_nr3);
4814 int font_size_4 = getFontWidth(font_nr4);
4815 int text_size_1 = 4 * font_size_1;
4816 int text_size_4 = 5 * font_size_4;
4817 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4819 int dx3 = text_size_1;
4820 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4821 int num_dots = (dx4 - dx3) / font_size_3;
4822 int startx1 = startx + dx1;
4823 int startx3 = startx + dx3;
4824 int startx4 = startx + dx4;
4825 int pos = node->pos;
4826 char *pos_text = getHallOfFameRankText(pos, 3);
4829 DrawText(startx1, starty, pos_text, font_nr1);
4831 for (i = 0; i < num_dots; i++)
4832 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4834 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4835 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4837 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4841 strncpy(buffer, node->name, max_buffer_len);
4842 buffer[max_buffer_len] = '\0';
4844 DrawText(startx, starty, buffer, font_nr);
4848 static void drawChooseTreeHeadExt(int type, char *title_string)
4850 int yoffset_sets = MENU_TITLE1_YPOS;
4851 int yoffset_setup = 16;
4852 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4853 type == TREE_TYPE_LEVEL_DIR ||
4854 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4856 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4859 static void drawChooseTreeHead(TreeInfo *ti)
4861 drawChooseTreeHeadExt(ti->type, ti->infotext);
4864 static void drawChooseTreeList(TreeInfo *ti)
4866 int first_entry = ti->cl_first;
4867 int num_entries = numTreeInfoInGroup(ti);
4868 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4871 clearMenuListArea();
4873 for (i = 0; i < num_page_entries; i++)
4875 TreeInfo *node, *node_first;
4876 int entry_pos = first_entry + i;
4878 node_first = getTreeInfoFirstGroupEntry(ti);
4879 node = getTreeInfoFromPos(node_first, entry_pos);
4881 drawChooseTreeText(ti, i, FALSE);
4883 if (node->parent_link)
4884 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4885 else if (node->level_group)
4886 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4888 initCursor(i, IMG_MENU_BUTTON);
4890 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4891 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4893 if (game_status == GAME_MODE_NAMES)
4894 drawChooseTreeEdit(i, FALSE);
4897 redraw_mask |= REDRAW_FIELD;
4900 static void drawChooseTreeInfo(TreeInfo *ti)
4902 int entry_pos = ti->cl_first + ti->cl_cursor;
4903 int last_redraw_mask = redraw_mask;
4904 int ypos = MENU_TITLE2_YPOS;
4905 int font_nr = FONT_TITLE_2;
4908 if (ti->type == TREE_TYPE_LEVEL_NR)
4909 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4911 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4912 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4913 scores.last_level_nr);
4915 if (ti->type != TREE_TYPE_LEVEL_DIR)
4918 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4919 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4921 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4923 if (node->parent_link)
4924 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4925 node->node_parent->name);
4926 else if (node->level_group)
4927 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4929 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4930 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4931 node->levels, (node->levels > 1 ? "levels" : "level"),
4934 // let BackToFront() redraw only what is needed
4935 redraw_mask = last_redraw_mask;
4936 for (x = 0; x < SCR_FIELDX; x++)
4937 MarkTileDirty(x, 1);
4940 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4942 drawChooseTreeCursor(ti->cl_cursor, active);
4943 drawChooseTreeText(ti, ti->cl_cursor, active);
4946 static void drawChooseTreeScreen(TreeInfo *ti)
4948 drawChooseTreeHead(ti);
4949 drawChooseTreeList(ti);
4950 drawChooseTreeInfo(ti);
4951 drawChooseTreeCursorAndText(ti, TRUE);
4953 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4955 // scroll bar and buttons may just have been added after reloading scores
4956 if (game_status == GAME_MODE_SCORES)
4957 MapScreenTreeGadgets(ti);
4960 static void drawChooseTreeScreen_Scores_NotAvailable(void)
4962 // dirty workaround to use spacing definitions from info screen
4963 info_mode = INFO_MODE_TITLE;
4965 char *text_info = "HighScores of Level %d";
4966 char *text_title = "Score information:";
4967 char *text_error = "No scores for this level.";
4968 char *text_foot = "Press any key or button for main menu";
4969 int font_info = FONT_TITLE_2;
4970 int font_title = FONT_INITIAL_3;
4971 int font_error = FONT_INITIAL_4;
4972 int font_foot = FONT_INITIAL_2;
4973 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
4974 int ystep_title = getMenuTextStep(spacing_title, font_title);
4975 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
4976 int ystart2 = ystart1 + ystep_title;
4977 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4978 int ystart0 = MENU_TITLE2_YPOS;
4980 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
4981 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
4983 DrawTextSCentered(ystart1, font_title, text_title);
4984 DrawTextSCentered(ystart2, font_error, text_error);
4986 DrawTextSCentered(ybottom, font_foot, text_foot);
4989 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4991 int score_pos = scores.last_added;
4993 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4994 score_pos = scores.last_entry_nr;
4996 // set current tree entry to last added score entry
4997 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4999 // if that fails, set current tree entry to first entry (back link)
5000 if (*ti_ptr == NULL)
5001 *ti_ptr = score_entries->node_group;
5003 int num_entries = numTreeInfoInGroup(*ti_ptr);
5004 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5005 int pos_score = getPosFromTreeInfo(*ti_ptr);
5006 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5007 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5009 (*ti_ptr)->cl_first = pos_first;
5010 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5015 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5018 TreeInfo *ti = *ti_ptr;
5019 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5020 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5021 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5022 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5023 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5025 int y = (ti != NULL ? ti->cl_cursor : 0);
5026 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5027 int num_entries = numTreeInfoInGroup(ti);
5028 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5029 boolean position_set_by_scrollbar = (dx == 999);
5030 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5031 boolean button_is_valid = (mx >= 0 && my >= 0);
5032 boolean button_screen_clicked = (button_action && button_is_valid);
5034 if (game_status == GAME_MODE_SCORES)
5036 if (server_scores.updated)
5038 // reload scores, using updated server score cache file
5039 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5041 server_scores.updated = FALSE;
5043 DrawHallOfFame_setScoreEntries();
5045 if (score_entries != NULL)
5047 ti = setHallOfFameActiveEntry(ti_ptr);
5049 if (button != MB_MENU_INITIALIZE)
5050 drawChooseTreeScreen(ti);
5054 if (score_entries == NULL)
5056 if (button == MB_MENU_INITIALIZE)
5058 drawChooseTreeScreen_Scores_NotAvailable();
5060 else if (button_screen_clicked)
5062 PlaySound(SND_MENU_ITEM_SELECTING);
5064 SetGameStatus(GAME_MODE_MAIN);
5073 if (button == MB_MENU_INITIALIZE)
5075 int num_entries = numTreeInfoInGroup(ti);
5076 int entry_pos = getPosFromTreeInfo(ti);
5078 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5079 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5081 if (game_status == GAME_MODE_SCORES)
5083 ti = setHallOfFameActiveEntry(ti_ptr);
5085 else if (ti->cl_first == -1)
5087 // only on initialization
5088 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5089 ti->cl_cursor = entry_pos - ti->cl_first;
5092 else if (ti->cl_cursor >= num_page_entries ||
5093 (num_entries > num_page_entries &&
5094 num_entries - ti->cl_first < num_page_entries))
5096 // only after change of list size (by custom graphic configuration)
5097 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5098 ti->cl_cursor = entry_pos - ti->cl_first;
5101 if (position_set_by_scrollbar)
5104 drawChooseTreeScreen(ti);
5108 else if (button == MB_MENU_LEAVE)
5110 if (game_status != GAME_MODE_SCORES)
5113 PlaySound(SND_MENU_ITEM_SELECTING);
5115 if (ti->node_parent)
5117 *ti_ptr = ti->node_parent;
5118 DrawChooseTree(ti_ptr);
5120 else if (game_status == GAME_MODE_SETUP)
5122 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5123 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5124 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5125 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5127 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5128 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5129 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5130 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5131 execSetupGraphics();
5132 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5133 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5134 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5136 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5137 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5138 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5139 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5140 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5141 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5142 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5143 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5150 if (game_status == GAME_MODE_LEVELNR)
5152 int new_level_nr = atoi(level_number_current->identifier);
5154 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5157 SetGameStatus(GAME_MODE_MAIN);
5165 if (mx || my) // mouse input
5167 x = (mx - amSX) / 32;
5168 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5170 if (game_status == GAME_MODE_NAMES)
5171 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5173 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5175 // move cursor instead of scrolling when already at start/end of list
5176 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5178 else if (dy == +1 * SCROLL_LINE &&
5179 ti->cl_first + num_page_entries == num_entries)
5182 // handle scrolling screen one line or page
5183 if (ti->cl_cursor + dy < 0 ||
5184 ti->cl_cursor + dy > num_page_entries - 1)
5186 boolean redraw = FALSE;
5188 if (ABS(dy) == SCROLL_PAGE)
5189 step = num_page_entries - 1;
5191 if (dy < 0 && ti->cl_first > 0)
5193 // scroll page/line up
5195 ti->cl_first -= step;
5196 if (ti->cl_first < 0)
5201 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5203 // scroll page/line down
5205 ti->cl_first += step;
5206 if (ti->cl_first + num_page_entries > num_entries)
5207 ti->cl_first = MAX(0, num_entries - num_page_entries);
5213 drawChooseTreeScreen(ti);
5218 // handle moving cursor one line
5219 y = ti->cl_cursor + dy;
5222 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5224 HandleHallOfFame_SelectLevel(1, dx);
5230 TreeInfo *node_first, *node_cursor;
5231 int entry_pos = ti->cl_first + y;
5233 node_first = getTreeInfoFirstGroupEntry(ti);
5234 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5236 if (node_cursor->node_group)
5240 PlaySound(SND_MENU_ITEM_SELECTING);
5242 node_cursor->cl_first = ti->cl_first;
5243 node_cursor->cl_cursor = ti->cl_cursor;
5244 *ti_ptr = node_cursor->node_group;
5245 DrawChooseTree(ti_ptr);
5250 else if (dx == -1 && ti->node_parent)
5254 PlaySound(SND_MENU_ITEM_SELECTING);
5256 *ti_ptr = ti->node_parent;
5257 DrawChooseTree(ti_ptr);
5262 if (!anyScrollbarGadgetActive() &&
5263 IN_VIS_MENU(x, y) &&
5264 mx < mx_right_border &&
5265 y >= 0 && y < num_page_entries)
5269 if (game_status == GAME_MODE_NAMES)
5271 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5272 drawChooseTreeEdit(y, TRUE);
5275 if (y != ti->cl_cursor)
5277 PlaySound(SND_MENU_ITEM_ACTIVATING);
5279 drawChooseTreeCursorAndText(ti, FALSE);
5283 drawChooseTreeCursorAndText(ti, TRUE);
5285 drawChooseTreeInfo(ti);
5289 if (game_status == GAME_MODE_SETUP)
5291 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5292 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5293 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5294 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5296 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5297 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5298 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5299 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5300 execSetupGraphics();
5301 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5302 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5303 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5305 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5306 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5307 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5308 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5309 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5310 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5311 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5312 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5321 TreeInfo *node_first, *node_cursor;
5322 int entry_pos = ti->cl_first + y;
5324 PlaySound(SND_MENU_ITEM_SELECTING);
5326 node_first = getTreeInfoFirstGroupEntry(ti);
5327 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5329 if (node_cursor->node_group)
5333 node_cursor->cl_first = ti->cl_first;
5334 node_cursor->cl_cursor = ti->cl_cursor;
5335 *ti_ptr = node_cursor->node_group;
5336 DrawChooseTree(ti_ptr);
5338 else if (node_cursor->parent_link)
5340 if (game_status != GAME_MODE_SCORES)
5343 *ti_ptr = node_cursor->node_parent;
5344 DrawChooseTree(ti_ptr);
5348 if (game_status != GAME_MODE_SCORES)
5351 node_cursor->cl_first = ti->cl_first;
5352 node_cursor->cl_cursor = ti->cl_cursor;
5353 *ti_ptr = node_cursor;
5355 if (ti->type == TREE_TYPE_LEVEL_DIR)
5357 LoadLevelSetup_SeriesInfo();
5359 SaveLevelSetup_LastSeries();
5360 SaveLevelSetup_SeriesInfo();
5364 if (game_status == GAME_MODE_SETUP)
5366 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5367 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5368 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5369 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5371 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5372 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5373 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5374 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5375 execSetupGraphics();
5376 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5377 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5378 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5380 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5381 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5382 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5383 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5384 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5385 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5386 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5387 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5394 if (game_status == GAME_MODE_LEVELNR)
5396 int new_level_nr = atoi(level_number_current->identifier);
5398 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5400 else if (game_status == GAME_MODE_LEVELS)
5402 // store level set if chosen from "last played level set" menu
5403 StoreLastPlayedLevels(leveldir_current);
5405 else if (game_status == GAME_MODE_NAMES)
5407 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5409 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5416 // change active user to selected user
5417 user.nr = entry_pos;
5419 // save number of new active user
5422 // load setup of new active user
5425 // load last level set of new active user
5426 LoadLevelSetup_LastSeries();
5427 LoadLevelSetup_SeriesInfo();
5429 // update list of last played level sets
5430 UpdateLastPlayedLevels_TreeInfo();
5434 ToggleFullscreenIfNeeded();
5435 ChangeWindowScalingIfNeeded();
5437 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5438 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5439 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5441 else if (game_status == GAME_MODE_SCORES)
5443 if (game_status_last_screen == GAME_MODE_PLAYING &&
5444 setup.auto_play_next_level && setup.increment_levels &&
5445 scores.last_level_nr < leveldir_current->last_level &&
5448 StartGameActions(network.enabled, setup.autorecord,
5454 SetGameStatus(GAME_MODE_SCOREINFO);
5456 DrawScoreInfo(node_cursor->pos);
5462 SetGameStatus(GAME_MODE_MAIN);
5470 if (game_status == GAME_MODE_SCORES)
5471 PlayMenuSoundIfLoop();
5474 void DrawChoosePlayerName(void)
5478 if (player_name != NULL)
5480 freeTreeInfo(player_name);
5485 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5487 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5488 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5491 ti->node_top = &player_name;
5492 ti->sort_priority = 10000 + value;
5493 ti->color = getPlayerNameColor(global.user_names[i]);
5495 snprintf(identifier, sizeof(identifier), "%d", value);
5496 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5498 setString(&ti->identifier, identifier);
5499 setString(&ti->name, name);
5500 setString(&ti->name_sorting, name);
5502 pushTreeInfo(&player_name, ti);
5505 // sort player entries by player number
5506 sortTreeInfo(&player_name);
5508 // set current player entry to selected player entry
5509 player_name_current =
5510 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5512 // if that fails, set current player name to first available name
5513 if (player_name_current == NULL)
5514 player_name_current = player_name;
5516 DrawChooseTree(&player_name_current);
5519 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5521 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5524 void DrawChooseLevelSet(void)
5526 DrawChooseTree(&leveldir_current);
5529 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5531 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5534 void DrawChooseLevelNr(void)
5538 if (level_number != NULL)
5540 freeTreeInfo(level_number);
5542 level_number = NULL;
5545 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5547 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5548 char identifier[32], name[64];
5551 // temporarily load level info to get level name
5552 LoadLevelInfoOnly(i);
5554 ti->node_top = &level_number;
5555 ti->sort_priority = 10000 + value;
5556 ti->color = (level.no_level_file ? FC_BLUE :
5557 LevelStats_getSolved(i) ? FC_GREEN :
5558 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5560 snprintf(identifier, sizeof(identifier), "%d", value);
5561 snprintf(name, sizeof(name), "%03d: %s", value,
5562 (level.no_level_file ? "(no file)" : level.name));
5564 setString(&ti->identifier, identifier);
5565 setString(&ti->name, name);
5566 setString(&ti->name_sorting, name);
5568 pushTreeInfo(&level_number, ti);
5571 // sort level number values to start with lowest level number
5572 sortTreeInfo(&level_number);
5574 // set current level number to current level number
5575 level_number_current =
5576 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5578 // if that also fails, set current level number to first available level
5579 if (level_number_current == NULL)
5580 level_number_current = level_number;
5582 DrawChooseTree(&level_number_current);
5585 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5587 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5590 static void DrawHallOfFame_setScoreEntries(void)
5592 int max_empty_entries = 10; // at least show "top ten" list, if empty
5593 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5594 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5595 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5598 if (score_entries != NULL)
5600 freeTreeInfo(score_entries);
5602 score_entries = NULL;
5605 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5607 // do not add empty score entries if off-screen
5608 if (scores.entry[i].score == 0 &&
5609 scores.entry[i].time == 0 &&
5610 i >= min_score_entries)
5613 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5614 char identifier[32], name[64];
5617 ti->node_top = &score_entries;
5618 ti->sort_priority = 10000 + value;
5619 ti->color = FC_YELLOW;
5622 snprintf(identifier, sizeof(identifier), "%d", value);
5623 snprintf(name, sizeof(name), "%03d.", value + 1);
5625 setString(&ti->identifier, identifier);
5626 setString(&ti->name, name);
5627 setString(&ti->name_sorting, name);
5629 pushTreeInfo(&score_entries, ti);
5632 // sort score entries to start with highest score entry
5633 sortTreeInfo(&score_entries);
5635 // add top tree node to create back link to main menu
5636 score_entries = addTopTreeInfoNode(score_entries);
5638 // set current score entry to last added or highest score entry
5639 score_entry_current =
5640 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5642 // if that fails, set current score entry to first valid score entry
5643 if (score_entry_current == NULL)
5644 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5646 // ("score_entries" and "score_entry_current" may be NULL here)
5649 void DrawHallOfFame(int level_nr)
5651 scores.last_level_nr = level_nr;
5653 // (this is needed when called from GameEnd() after winning a game)
5654 KeyboardAutoRepeatOn();
5656 // (this is needed when called from GameEnd() after winning a game)
5657 SetDrawDeactivationMask(REDRAW_NONE);
5658 SetDrawBackgroundMask(REDRAW_FIELD);
5660 LoadLocalAndServerScore(level_nr, TRUE);
5662 DrawHallOfFame_setScoreEntries();
5664 if (scores.last_added >= 0)
5665 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5667 FadeSetEnterScreen();
5669 DrawChooseTree(&score_entry_current);
5672 static char *getHallOfFameRankText(int nr, int size)
5674 static char rank_text[10];
5675 boolean forced = (scores.force_last_added && nr == scores.last_added);
5676 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5678 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5683 static char *getHallOfFameTimeText(int nr)
5685 static char score_text[10];
5686 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5687 int mm = (time_seconds / 60) % 60;
5688 int ss = (time_seconds % 60);
5690 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5695 static char *getHallOfFameScoreText(int nr, int size)
5697 if (!level.rate_time_over_score)
5698 return int2str(scores.entry[nr].score, size); // show normal score
5699 else if (level.use_step_counter)
5700 return int2str(scores.entry[nr].time, size); // show number of steps
5702 return getHallOfFameTimeText(nr); // show playing time
5705 static void HandleHallOfFame_SelectLevel(int step, int direction)
5707 int old_level_nr = scores.last_level_nr;
5708 int new_level_nr = old_level_nr + step * direction;
5710 if (new_level_nr < leveldir_current->first_level)
5711 new_level_nr = leveldir_current->first_level;
5712 if (new_level_nr > leveldir_current->last_level)
5713 new_level_nr = leveldir_current->last_level;
5715 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5716 new_level_nr = leveldir_current->handicap_level;
5718 if (new_level_nr != old_level_nr)
5720 PlaySound(SND_MENU_ITEM_SELECTING);
5722 scores.last_level_nr = level_nr = new_level_nr;
5723 scores.last_entry_nr = 0;
5725 LoadLevel(level_nr);
5726 LoadLocalAndServerScore(level_nr, TRUE);
5728 DrawHallOfFame_setScoreEntries();
5730 if (game_status == GAME_MODE_SCORES)
5732 // force remapping optional gadgets (especially scroll bar)
5733 UnmapScreenTreeGadgets();
5735 // redraw complete high score screen, as sub-title has changed
5738 // redraw level selection buttons (which have just been erased)
5739 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5741 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5745 DrawScoreInfo_Content(scores.last_entry_nr);
5748 SaveLevelSetup_SeriesInfo();
5752 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5754 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5757 static void DrawScoreInfo_Content(int entry_nr)
5759 struct ScoreEntry *entry = &scores.entry[entry_nr];
5760 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5761 int font_title = MENU_INFO_FONT_TITLE;
5762 int font_head = MENU_INFO_FONT_HEAD;
5763 int font_text = MENU_INFO_FONT_TEXT;
5764 int font_foot = MENU_INFO_FONT_FOOT;
5765 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5766 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5767 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5768 int xstep = getFontWidth(font_text);
5769 int ystep_title = getMenuTextStep(spacing_title, font_title);
5770 int ystep_para = getMenuTextStep(spacing_para, font_text);
5771 int ystep_line = getMenuTextStep(spacing_line, font_text);
5772 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5773 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5774 int xstart1 = mSX - SX + 2 * xstep;
5775 int xstart2 = mSX - SX + 13 * xstep;
5776 int select_x = SX + xstart1;
5777 int select_y1, select_y2;
5778 int font_width = getFontWidth(font_text);
5779 int font_height = getFontHeight(font_text);
5780 int pad_left = xstart2;
5781 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
5782 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5783 int max_lines_per_text = 5;
5788 // redraw score selection buttons (which have just been erased)
5789 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5791 if (score_entries == NULL)
5793 drawChooseTreeScreen_Scores_NotAvailable();
5798 drawChooseTreeHead(score_entries);
5799 drawChooseTreeInfo(score_entries);
5801 DrawTextSCentered(ystart, font_title, "Score Information:");
5802 ystart += ystep_title;
5804 DrawTextF(xstart1, ystart, font_head, "Level Set");
5805 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5806 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5807 TRUE, FALSE, FALSE);
5808 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5810 DrawTextF(xstart1, ystart, font_head, "Level");
5811 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5812 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5813 TRUE, FALSE, FALSE);
5814 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5816 select_y1 = SY + ystart;
5817 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5819 DrawTextF(xstart1, ystart, font_head, "Rank");
5820 DrawTextF(xstart2, ystart, font_text, pos_text);
5821 ystart += ystep_line;
5823 DrawTextF(xstart1, ystart, font_head, "Player");
5824 DrawTextF(xstart2, ystart, font_text, entry->name);
5825 ystart += ystep_line;
5827 if (level.use_step_counter)
5829 DrawTextF(xstart1, ystart, font_head, "Steps");
5830 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5831 ystart += ystep_line;
5835 DrawTextF(xstart1, ystart, font_head, "Time");
5836 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5837 ystart += ystep_line;
5840 if (!level.rate_time_over_score || entry->score > 0)
5842 DrawTextF(xstart1, ystart, font_head, "Score");
5843 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5844 ystart += ystep_line;
5847 ystart += ystep_line;
5849 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5850 DrawTextF(xstart2, ystart, font_text, entry->tape_date);
5851 ystart += ystep_line;
5853 DrawTextF(xstart1, ystart, font_head, "Platform");
5854 DrawTextF(xstart2, ystart, font_text, entry->platform);
5855 ystart += ystep_line;
5857 DrawTextF(xstart1, ystart, font_head, "Version");
5858 DrawTextF(xstart2, ystart, font_text, entry->version);
5859 ystart += ystep_line;
5861 DrawTextF(xstart1, ystart, font_head, "Country");
5862 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5863 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5864 TRUE, FALSE, FALSE);
5865 ystart += ystep_line;
5867 select_y2 = SY + ystart;
5869 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5871 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5874 static void DrawScoreInfo(int entry_nr)
5876 scores.last_entry_nr = entry_nr;
5878 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5882 FadeOut(REDRAW_FIELD);
5884 DrawScoreInfo_Content(entry_nr);
5886 // map gadgets for score info screen
5887 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5889 FadeIn(REDRAW_FIELD);
5892 static void HandleScoreInfo_SelectScore(int step, int direction)
5894 int old_entry_nr = scores.last_entry_nr;
5895 int new_entry_nr = old_entry_nr + step * direction;
5896 int num_nodes = numTreeInfoInGroup(score_entry_current);
5897 int num_entries = num_nodes - 1; // score nodes only, without back link
5899 if (new_entry_nr < 0)
5901 if (new_entry_nr > num_entries - 1)
5902 new_entry_nr = num_entries - 1;
5904 if (new_entry_nr != old_entry_nr)
5906 scores.last_entry_nr = new_entry_nr;
5908 DrawScoreInfo_Content(new_entry_nr);
5912 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5914 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5915 boolean button_is_valid = (mx >= 0 && my >= 0);
5916 boolean button_screen_clicked = (button_action && button_is_valid);
5918 if (server_scores.updated)
5920 // reload scores, using updated server score cache file
5921 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5923 server_scores.updated = FALSE;
5925 DrawHallOfFame_setScoreEntries();
5927 DrawScoreInfo_Content(scores.last_entry_nr);
5930 if (button_screen_clicked)
5932 PlaySound(SND_MENU_ITEM_SELECTING);
5934 SetGameStatus(GAME_MODE_SCORES);
5936 DrawHallOfFame(level_nr);
5940 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5944 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5949 // ============================================================================
5950 // setup screen functions
5951 // ============================================================================
5953 static struct TokenInfo *setup_info;
5954 static int num_setup_info; // number of setup entries shown on screen
5955 static int max_setup_info; // total number of setup entries in list
5957 static char *window_size_text;
5958 static char *scaling_type_text;
5959 static char *rendering_mode_text;
5960 static char *vsync_mode_text;
5961 static char *scroll_delay_text;
5962 static char *snapshot_mode_text;
5963 static char *game_speed_text;
5964 static char *scores_type_text;
5965 static char *network_server_text;
5966 static char *graphics_set_name;
5967 static char *sounds_set_name;
5968 static char *music_set_name;
5969 static char *volume_simple_text;
5970 static char *volume_loops_text;
5971 static char *volume_music_text;
5972 static char *touch_controls_text;
5973 static char *move_distance_text;
5974 static char *drop_distance_text;
5975 static char *transparency_text;
5976 static char *grid_size_text[2][2];
5978 static void execSetupMain(void)
5980 setup_mode = SETUP_MODE_MAIN;
5985 static void execSetupGame_setScoresType(void)
5987 if (scores_types == NULL)
5991 for (i = 0; scores_types_list[i].value != NULL; i++)
5993 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5994 char identifier[32], name[32];
5995 char *value = scores_types_list[i].value;
5996 char *text = scores_types_list[i].text;
5998 ti->node_top = &scores_types;
5999 ti->sort_priority = i;
6001 sprintf(identifier, "%s", value);
6002 sprintf(name, "%s", text);
6004 setString(&ti->identifier, identifier);
6005 setString(&ti->name, name);
6006 setString(&ti->name_sorting, name);
6007 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
6009 pushTreeInfo(&scores_types, ti);
6012 // sort scores type values to start with lowest scores type value
6013 sortTreeInfo(&scores_types);
6015 // set current scores type value to configured scores type value
6016 scores_type_current =
6017 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
6019 // if that fails, set current scores type to reliable default value
6020 if (scores_type_current == NULL)
6021 scores_type_current =
6022 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
6024 // if that also fails, set current scores type to first available value
6025 if (scores_type_current == NULL)
6026 scores_type_current = scores_types;
6029 setup.scores_in_highscore_list = scores_type_current->identifier;
6031 // needed for displaying scores type text instead of identifier
6032 scores_type_text = scores_type_current->name;
6035 static void execSetupGame_setGameSpeeds(boolean update_value)
6037 if (setup.game_speed_extended)
6039 game_speeds_list = game_speeds_list_extended;
6040 game_speeds = game_speeds_extended;
6044 game_speeds_list = game_speeds_list_normal;
6045 game_speeds = game_speeds_normal;
6048 if (game_speeds == NULL)
6052 for (i = 0; game_speeds_list[i].value != -1; i++)
6054 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6055 char identifier[32], name[32];
6056 int value = game_speeds_list[i].value;
6057 char *text = game_speeds_list[i].text;
6059 ti->node_top = &game_speeds;
6060 ti->sort_priority = 10000 - value;
6062 sprintf(identifier, "%d", value);
6063 sprintf(name, "%s", text);
6065 setString(&ti->identifier, identifier);
6066 setString(&ti->name, name);
6067 setString(&ti->name_sorting, name);
6068 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
6070 pushTreeInfo(&game_speeds, ti);
6073 // sort game speed values to start with slowest game speed
6074 sortTreeInfo(&game_speeds);
6076 update_value = TRUE;
6081 // set current game speed to configured game speed value
6082 game_speed_current =
6083 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6085 // if that fails, set current game speed to reliable default value
6086 if (game_speed_current == NULL)
6087 game_speed_current =
6088 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6090 // if that also fails, set current game speed to first available speed
6091 if (game_speed_current == NULL)
6092 game_speed_current = game_speeds;
6094 if (setup.game_speed_extended)
6095 game_speeds_extended = game_speeds;
6097 game_speeds_normal = game_speeds;
6100 setup.game_frame_delay = atoi(game_speed_current->identifier);
6102 // needed for displaying game speed text instead of identifier
6103 game_speed_text = game_speed_current->name;
6106 static void execSetupGame_setScrollDelays(void)
6108 if (scroll_delays == NULL)
6112 for (i = 0; scroll_delays_list[i].value != -1; i++)
6114 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6115 char identifier[32], name[32];
6116 int value = scroll_delays_list[i].value;
6117 char *text = scroll_delays_list[i].text;
6119 ti->node_top = &scroll_delays;
6120 ti->sort_priority = value;
6122 sprintf(identifier, "%d", value);
6123 sprintf(name, "%s", text);
6125 setString(&ti->identifier, identifier);
6126 setString(&ti->name, name);
6127 setString(&ti->name_sorting, name);
6128 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6130 pushTreeInfo(&scroll_delays, ti);
6133 // sort scroll delay values to start with lowest scroll delay value
6134 sortTreeInfo(&scroll_delays);
6136 // set current scroll delay value to configured scroll delay value
6137 scroll_delay_current =
6138 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6140 // if that fails, set current scroll delay to reliable default value
6141 if (scroll_delay_current == NULL)
6142 scroll_delay_current =
6143 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6145 // if that also fails, set current scroll delay to first available value
6146 if (scroll_delay_current == NULL)
6147 scroll_delay_current = scroll_delays;
6150 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6152 // needed for displaying scroll delay text instead of identifier
6153 scroll_delay_text = scroll_delay_current->name;
6156 static void execSetupGame_setSnapshotModes(void)
6158 if (snapshot_modes == NULL)
6162 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6164 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6165 char identifier[32], name[32];
6166 char *value = snapshot_modes_list[i].value;
6167 char *text = snapshot_modes_list[i].text;
6169 ti->node_top = &snapshot_modes;
6170 ti->sort_priority = i;
6172 sprintf(identifier, "%s", value);
6173 sprintf(name, "%s", text);
6175 setString(&ti->identifier, identifier);
6176 setString(&ti->name, name);
6177 setString(&ti->name_sorting, name);
6178 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6180 pushTreeInfo(&snapshot_modes, ti);
6183 // sort snapshot mode values to start with lowest snapshot mode value
6184 sortTreeInfo(&snapshot_modes);
6186 // set current snapshot mode value to configured snapshot mode value
6187 snapshot_mode_current =
6188 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6190 // if that fails, set current snapshot mode to reliable default value
6191 if (snapshot_mode_current == NULL)
6192 snapshot_mode_current =
6193 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6195 // if that also fails, set current snapshot mode to first available value
6196 if (snapshot_mode_current == NULL)
6197 snapshot_mode_current = snapshot_modes;
6200 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6202 // needed for displaying snapshot mode text instead of identifier
6203 snapshot_mode_text = snapshot_mode_current->name;
6206 static void execSetupGame_setNetworkServerText(void)
6208 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6210 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6214 strncpy(network_server_hostname, setup.network_server_hostname,
6215 MAX_SETUP_TEXT_INPUT_LEN);
6216 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6219 // needed for displaying network server text instead of identifier
6220 network_server_text = network_server_hostname;
6223 static void execSetupGame(void)
6225 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6227 execSetupGame_setGameSpeeds(FALSE);
6228 execSetupGame_setScoresType();
6229 execSetupGame_setScrollDelays();
6230 execSetupGame_setSnapshotModes();
6232 execSetupGame_setNetworkServerText();
6234 if (!setup.provide_uploading_tapes)
6235 setHideSetupEntry(execOfferUploadTapes);
6237 setup_mode = SETUP_MODE_GAME;
6241 // check if vsync needs to be disabled for this game speed to work
6242 if (check_vsync_mode)
6243 DisableVsyncIfNeeded();
6246 static void execSetupChooseScoresType(void)
6248 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6253 static void execSetupChooseGameSpeed(void)
6255 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6260 static void execSetupChooseScrollDelay(void)
6262 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6267 static void execSetupChooseSnapshotMode(void)
6269 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6274 static void execSetupEngines(void)
6276 setup_mode = SETUP_MODE_ENGINES;
6281 static void execSetupEditor(void)
6283 setup_mode = SETUP_MODE_EDITOR;
6288 static void execSetupGraphics_setWindowSizes(boolean update_list)
6290 if (window_sizes != NULL && update_list)
6292 freeTreeInfo(window_sizes);
6294 window_sizes = NULL;
6297 if (window_sizes == NULL)
6299 boolean current_window_size_found = FALSE;
6302 for (i = 0; window_sizes_list[i].value != -1; i++)
6304 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6305 char identifier[32], name[32];
6306 int value = window_sizes_list[i].value;
6307 char *text = window_sizes_list[i].text;
6309 ti->node_top = &window_sizes;
6310 ti->sort_priority = value;
6312 sprintf(identifier, "%d", value);
6313 sprintf(name, "%s", text);
6315 setString(&ti->identifier, identifier);
6316 setString(&ti->name, name);
6317 setString(&ti->name_sorting, name);
6318 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6320 pushTreeInfo(&window_sizes, ti);
6322 if (value == setup.window_scaling_percent)
6323 current_window_size_found = TRUE;
6326 if (!current_window_size_found)
6328 // add entry for non-preset window scaling value
6330 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6331 char identifier[32], name[32];
6332 int value = setup.window_scaling_percent;
6334 ti->node_top = &window_sizes;
6335 ti->sort_priority = value;
6337 sprintf(identifier, "%d", value);
6338 sprintf(name, "%d %% (Current)", value);
6340 setString(&ti->identifier, identifier);
6341 setString(&ti->name, name);
6342 setString(&ti->name_sorting, name);
6343 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6345 pushTreeInfo(&window_sizes, ti);
6348 // sort window size values to start with lowest window size value
6349 sortTreeInfo(&window_sizes);
6351 // set current window size value to configured window size value
6352 window_size_current =
6353 getTreeInfoFromIdentifier(window_sizes,
6354 i_to_a(setup.window_scaling_percent));
6356 // if that fails, set current window size to reliable default value
6357 if (window_size_current == NULL)
6358 window_size_current =
6359 getTreeInfoFromIdentifier(window_sizes,
6360 i_to_a(STD_WINDOW_SCALING_PERCENT));
6362 // if that also fails, set current window size to first available value
6363 if (window_size_current == NULL)
6364 window_size_current = window_sizes;
6367 setup.window_scaling_percent = atoi(window_size_current->identifier);
6369 // needed for displaying window size text instead of identifier
6370 window_size_text = window_size_current->name;
6373 static void execSetupGraphics_setScalingTypes(void)
6375 if (scaling_types == NULL)
6379 for (i = 0; scaling_types_list[i].value != NULL; i++)
6381 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6382 char identifier[32], name[32];
6383 char *value = scaling_types_list[i].value;
6384 char *text = scaling_types_list[i].text;
6386 ti->node_top = &scaling_types;
6387 ti->sort_priority = i;
6389 sprintf(identifier, "%s", value);
6390 sprintf(name, "%s", text);
6392 setString(&ti->identifier, identifier);
6393 setString(&ti->name, name);
6394 setString(&ti->name_sorting, name);
6395 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6397 pushTreeInfo(&scaling_types, ti);
6400 // sort scaling type values to start with lowest scaling type value
6401 sortTreeInfo(&scaling_types);
6403 // set current scaling type value to configured scaling type value
6404 scaling_type_current =
6405 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6407 // if that fails, set current scaling type to reliable default value
6408 if (scaling_type_current == NULL)
6409 scaling_type_current =
6410 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6412 // if that also fails, set current scaling type to first available value
6413 if (scaling_type_current == NULL)
6414 scaling_type_current = scaling_types;
6417 setup.window_scaling_quality = scaling_type_current->identifier;
6419 // needed for displaying scaling type text instead of identifier
6420 scaling_type_text = scaling_type_current->name;
6423 static void execSetupGraphics_setRenderingModes(void)
6425 if (rendering_modes == NULL)
6429 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6431 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6432 char identifier[32], name[32];
6433 char *value = rendering_modes_list[i].value;
6434 char *text = rendering_modes_list[i].text;
6436 ti->node_top = &rendering_modes;
6437 ti->sort_priority = i;
6439 sprintf(identifier, "%s", value);
6440 sprintf(name, "%s", text);
6442 setString(&ti->identifier, identifier);
6443 setString(&ti->name, name);
6444 setString(&ti->name_sorting, name);
6445 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6447 pushTreeInfo(&rendering_modes, ti);
6450 // sort rendering mode values to start with lowest rendering mode value
6451 sortTreeInfo(&rendering_modes);
6453 // set current rendering mode value to configured rendering mode value
6454 rendering_mode_current =
6455 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6457 // if that fails, set current rendering mode to reliable default value
6458 if (rendering_mode_current == NULL)
6459 rendering_mode_current =
6460 getTreeInfoFromIdentifier(rendering_modes,
6461 STR_SPECIAL_RENDERING_DEFAULT);
6463 // if that also fails, set current rendering mode to first available one
6464 if (rendering_mode_current == NULL)
6465 rendering_mode_current = rendering_modes;
6468 setup.screen_rendering_mode = rendering_mode_current->identifier;
6470 // needed for displaying rendering mode text instead of identifier
6471 rendering_mode_text = rendering_mode_current->name;
6474 static void execSetupGraphics_setVsyncModes(boolean update_value)
6476 if (vsync_modes == NULL)
6480 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6482 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6483 char identifier[32], name[32];
6484 char *value = vsync_modes_list[i].value;
6485 char *text = vsync_modes_list[i].text;
6487 ti->node_top = &vsync_modes;
6488 ti->sort_priority = i;
6490 sprintf(identifier, "%s", 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_VSYNC);
6498 pushTreeInfo(&vsync_modes, ti);
6501 // sort vsync mode values to start with lowest vsync mode value
6502 sortTreeInfo(&vsync_modes);
6504 update_value = TRUE;
6509 // set current vsync mode value to configured vsync mode value
6510 vsync_mode_current =
6511 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6513 // if that fails, set current vsync mode to reliable default value
6514 if (vsync_mode_current == NULL)
6515 vsync_mode_current =
6516 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6518 // if that also fails, set current vsync mode to first available one
6519 if (vsync_mode_current == NULL)
6520 vsync_mode_current = vsync_modes;
6523 setup.vsync_mode = vsync_mode_current->identifier;
6525 // needed for displaying vsync mode text instead of identifier
6526 vsync_mode_text = vsync_mode_current->name;
6529 static void execSetupGraphics(void)
6531 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6533 // update "setup.window_scaling_percent" from list selection
6534 // (in this case, window scaling was changed on setup screen)
6535 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6536 execSetupGraphics_setWindowSizes(FALSE);
6538 // update "setup.vsync_mode" from list selection
6539 // (in this case, vsync mode was changed on setup screen)
6540 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6541 execSetupGraphics_setVsyncModes(FALSE);
6543 // update list selection from "setup.window_scaling_percent"
6544 // (window scaling may have changed by resizing the window)
6545 execSetupGraphics_setWindowSizes(TRUE);
6547 // update list selection from "setup.vsync_mode"
6548 // (vsync_mode may have changed by re-creating the renderer)
6549 execSetupGraphics_setVsyncModes(TRUE);
6551 execSetupGraphics_setScalingTypes();
6552 execSetupGraphics_setRenderingModes();
6554 setup_mode = SETUP_MODE_GRAPHICS;
6558 // check if game speed is high enough for 60 Hz vsync to work
6559 if (check_game_speed)
6560 ModifyGameSpeedIfNeeded();
6562 // window scaling may have changed at this point
6563 ChangeWindowScalingIfNeeded();
6565 // window scaling quality may have changed at this point
6566 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6567 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6569 // screen rendering mode may have changed at this point
6570 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6572 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6573 int video_vsync_mode = video.vsync_mode;
6575 // screen vsync mode may have changed at this point
6576 ChangeVsyncModeIfNeeded();
6578 // check if setting vsync mode to selected value failed
6579 if (setup_vsync_mode != video_vsync_mode &&
6580 setup_vsync_mode != video.vsync_mode)
6582 // changing vsync mode to selected value failed -- reset displayed value
6583 execSetupGraphics_setVsyncModes(TRUE);
6585 Request("Setting VSync failed!", REQ_CONFIRM);
6591 static void execSetupChooseWindowSize(void)
6593 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6598 static void execSetupChooseScalingType(void)
6600 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6605 static void execSetupChooseRenderingMode(void)
6607 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6612 static void execSetupChooseVsyncMode(void)
6614 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6619 static void execSetupChooseVolumeSimple(void)
6621 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6626 static void execSetupChooseVolumeLoops(void)
6628 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6633 static void execSetupChooseVolumeMusic(void)
6635 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6640 static void execSetupSound(void)
6642 if (volumes_simple == NULL)
6644 boolean current_volume_simple_found = FALSE;
6647 for (i = 0; volumes_list[i].value != -1; i++)
6649 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6650 char identifier[32], name[32];
6651 int value = volumes_list[i].value;
6652 char *text = volumes_list[i].text;
6654 ti->node_top = &volumes_simple;
6655 ti->sort_priority = value;
6657 sprintf(identifier, "%d", value);
6658 sprintf(name, "%s", text);
6660 setString(&ti->identifier, identifier);
6661 setString(&ti->name, name);
6662 setString(&ti->name_sorting, name);
6663 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6665 pushTreeInfo(&volumes_simple, ti);
6667 if (value == setup.volume_simple)
6668 current_volume_simple_found = TRUE;
6671 if (!current_volume_simple_found)
6673 // add entry for non-preset volume value
6675 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6676 char identifier[32], name[32];
6677 int value = setup.volume_simple;
6679 ti->node_top = &volumes_simple;
6680 ti->sort_priority = value;
6682 sprintf(identifier, "%d", value);
6683 sprintf(name, "%d %% (Current)", value);
6685 setString(&ti->identifier, identifier);
6686 setString(&ti->name, name);
6687 setString(&ti->name_sorting, name);
6688 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6690 pushTreeInfo(&volumes_simple, ti);
6693 // sort volume values to start with lowest volume value
6694 sortTreeInfo(&volumes_simple);
6696 // set current volume value to configured volume value
6697 volume_simple_current =
6698 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6700 // if that fails, set current volume to reliable default value
6701 if (volume_simple_current == NULL)
6702 volume_simple_current =
6703 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6705 // if that also fails, set current volume to first available value
6706 if (volume_simple_current == NULL)
6707 volume_simple_current = volumes_simple;
6710 if (volumes_loops == NULL)
6712 boolean current_volume_loops_found = FALSE;
6715 for (i = 0; volumes_list[i].value != -1; i++)
6717 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6718 char identifier[32], name[32];
6719 int value = volumes_list[i].value;
6720 char *text = volumes_list[i].text;
6722 ti->node_top = &volumes_loops;
6723 ti->sort_priority = value;
6725 sprintf(identifier, "%d", value);
6726 sprintf(name, "%s", text);
6728 setString(&ti->identifier, identifier);
6729 setString(&ti->name, name);
6730 setString(&ti->name_sorting, name);
6731 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6733 pushTreeInfo(&volumes_loops, ti);
6735 if (value == setup.volume_loops)
6736 current_volume_loops_found = TRUE;
6739 if (!current_volume_loops_found)
6741 // add entry for non-preset volume value
6743 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6744 char identifier[32], name[32];
6745 int value = setup.volume_loops;
6747 ti->node_top = &volumes_loops;
6748 ti->sort_priority = value;
6750 sprintf(identifier, "%d", value);
6751 sprintf(name, "%d %% (Current)", value);
6753 setString(&ti->identifier, identifier);
6754 setString(&ti->name, name);
6755 setString(&ti->name_sorting, name);
6756 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6758 pushTreeInfo(&volumes_loops, ti);
6761 // sort volume values to start with lowest volume value
6762 sortTreeInfo(&volumes_loops);
6764 // set current volume value to configured volume value
6765 volume_loops_current =
6766 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6768 // if that fails, set current volume to reliable default value
6769 if (volume_loops_current == NULL)
6770 volume_loops_current =
6771 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6773 // if that also fails, set current volume to first available value
6774 if (volume_loops_current == NULL)
6775 volume_loops_current = volumes_loops;
6778 if (volumes_music == NULL)
6780 boolean current_volume_music_found = FALSE;
6783 for (i = 0; volumes_list[i].value != -1; i++)
6785 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6786 char identifier[32], name[32];
6787 int value = volumes_list[i].value;
6788 char *text = volumes_list[i].text;
6790 ti->node_top = &volumes_music;
6791 ti->sort_priority = value;
6793 sprintf(identifier, "%d", value);
6794 sprintf(name, "%s", text);
6796 setString(&ti->identifier, identifier);
6797 setString(&ti->name, name);
6798 setString(&ti->name_sorting, name);
6799 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6801 pushTreeInfo(&volumes_music, ti);
6803 if (value == setup.volume_music)
6804 current_volume_music_found = TRUE;
6807 if (!current_volume_music_found)
6809 // add entry for non-preset volume value
6811 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6812 char identifier[32], name[32];
6813 int value = setup.volume_music;
6815 ti->node_top = &volumes_music;
6816 ti->sort_priority = value;
6818 sprintf(identifier, "%d", value);
6819 sprintf(name, "%d %% (Current)", value);
6821 setString(&ti->identifier, identifier);
6822 setString(&ti->name, name);
6823 setString(&ti->name_sorting, name);
6824 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6826 pushTreeInfo(&volumes_music, ti);
6829 // sort volume values to start with lowest volume value
6830 sortTreeInfo(&volumes_music);
6832 // set current volume value to configured volume value
6833 volume_music_current =
6834 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6836 // if that fails, set current volume to reliable default value
6837 if (volume_music_current == NULL)
6838 volume_music_current =
6839 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6841 // if that also fails, set current volume to first available value
6842 if (volume_music_current == NULL)
6843 volume_music_current = volumes_music;
6846 setup.volume_simple = atoi(volume_simple_current->identifier);
6847 setup.volume_loops = atoi(volume_loops_current->identifier);
6848 setup.volume_music = atoi(volume_music_current->identifier);
6850 // needed for displaying volume text instead of identifier
6851 volume_simple_text = volume_simple_current->name;
6852 volume_loops_text = volume_loops_current->name;
6853 volume_music_text = volume_music_current->name;
6855 setup_mode = SETUP_MODE_SOUND;
6860 static void execSetupChooseTouchControls(void)
6862 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6867 static void execSetupChooseMoveDistance(void)
6869 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6874 static void execSetupChooseDropDistance(void)
6876 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6881 static void execSetupChooseTransparency(void)
6883 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6888 static void execSetupChooseGridXSize_0(void)
6890 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6895 static void execSetupChooseGridYSize_0(void)
6897 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6902 static void execSetupChooseGridXSize_1(void)
6904 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6909 static void execSetupChooseGridYSize_1(void)
6911 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6916 static void execSetupConfigureVirtualButtons(void)
6918 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6920 ConfigureVirtualButtons();
6922 setup_mode = SETUP_MODE_TOUCH;
6927 static void execSetupTouch(void)
6931 if (touch_controls == NULL)
6933 for (i = 0; touch_controls_list[i].value != NULL; i++)
6935 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6936 char identifier[32], name[32];
6937 char *value = touch_controls_list[i].value;
6938 char *text = touch_controls_list[i].text;
6940 ti->node_top = &touch_controls;
6941 ti->sort_priority = i;
6943 sprintf(identifier, "%s", value);
6944 sprintf(name, "%s", text);
6946 setString(&ti->identifier, identifier);
6947 setString(&ti->name, name);
6948 setString(&ti->name_sorting, name);
6949 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6951 pushTreeInfo(&touch_controls, ti);
6954 // sort touch control values to start with lowest touch control value
6955 sortTreeInfo(&touch_controls);
6957 // set current touch control value to configured touch control value
6958 touch_control_current =
6959 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6961 // if that fails, set current touch control to reliable default value
6962 if (touch_control_current == NULL)
6963 touch_control_current =
6964 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6966 // if that also fails, set current touch control to first available value
6967 if (touch_control_current == NULL)
6968 touch_control_current = touch_controls;
6971 if (move_distances == NULL)
6973 for (i = 0; distances_list[i].value != -1; i++)
6975 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6976 char identifier[32], name[32];
6977 int value = distances_list[i].value;
6978 char *text = distances_list[i].text;
6980 ti->node_top = &move_distances;
6981 ti->sort_priority = value;
6983 sprintf(identifier, "%d", value);
6984 sprintf(name, "%s", text);
6986 setString(&ti->identifier, identifier);
6987 setString(&ti->name, name);
6988 setString(&ti->name_sorting, name);
6989 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6991 pushTreeInfo(&move_distances, ti);
6994 // sort distance values to start with lowest distance value
6995 sortTreeInfo(&move_distances);
6997 // set current distance value to configured distance value
6998 move_distance_current =
6999 getTreeInfoFromIdentifier(move_distances,
7000 i_to_a(setup.touch.move_distance));
7002 // if that fails, set current distance to reliable default value
7003 if (move_distance_current == NULL)
7004 move_distance_current =
7005 getTreeInfoFromIdentifier(move_distances,
7006 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
7008 // if that also fails, set current distance to first available value
7009 if (move_distance_current == NULL)
7010 move_distance_current = move_distances;
7013 if (drop_distances == NULL)
7015 for (i = 0; distances_list[i].value != -1; i++)
7017 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7018 char identifier[32], name[32];
7019 int value = distances_list[i].value;
7020 char *text = distances_list[i].text;
7022 ti->node_top = &drop_distances;
7023 ti->sort_priority = value;
7025 sprintf(identifier, "%d", value);
7026 sprintf(name, "%s", text);
7028 setString(&ti->identifier, identifier);
7029 setString(&ti->name, name);
7030 setString(&ti->name_sorting, name);
7031 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
7033 pushTreeInfo(&drop_distances, ti);
7036 // sort distance values to start with lowest distance value
7037 sortTreeInfo(&drop_distances);
7039 // set current distance value to configured distance value
7040 drop_distance_current =
7041 getTreeInfoFromIdentifier(drop_distances,
7042 i_to_a(setup.touch.drop_distance));
7044 // if that fails, set current distance to reliable default value
7045 if (drop_distance_current == NULL)
7046 drop_distance_current =
7047 getTreeInfoFromIdentifier(drop_distances,
7048 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
7050 // if that also fails, set current distance to first available value
7051 if (drop_distance_current == NULL)
7052 drop_distance_current = drop_distances;
7055 if (transparencies == NULL)
7057 for (i = 0; transparencies_list[i].value != -1; i++)
7059 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7060 char identifier[32], name[32];
7061 int value = transparencies_list[i].value;
7062 char *text = transparencies_list[i].text;
7064 ti->node_top = &transparencies;
7065 ti->sort_priority = value;
7067 sprintf(identifier, "%d", value);
7068 sprintf(name, "%s", text);
7070 setString(&ti->identifier, identifier);
7071 setString(&ti->name, name);
7072 setString(&ti->name_sorting, name);
7073 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
7075 pushTreeInfo(&transparencies, ti);
7078 // sort transparency values to start with lowest transparency value
7079 sortTreeInfo(&transparencies);
7081 // set current transparency value to configured transparency value
7082 transparency_current =
7083 getTreeInfoFromIdentifier(transparencies,
7084 i_to_a(setup.touch.transparency));
7086 // if that fails, set current transparency to reliable default value
7087 if (transparency_current == NULL)
7088 transparency_current =
7089 getTreeInfoFromIdentifier(transparencies,
7090 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7092 // if that also fails, set current transparency to first available value
7093 if (transparency_current == NULL)
7094 transparency_current = transparencies;
7097 for (i = 0; i < 2; i++)
7099 for (j = 0; j < 2; j++)
7101 if (grid_sizes[i][j] == NULL)
7103 for (k = 0; grid_sizes_list[k].value != -1; k++)
7105 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7106 char identifier[32], name[32];
7107 int value = grid_sizes_list[k].value;
7108 char *text = grid_sizes_list[k].text;
7110 ti->node_top = &grid_sizes[i][j];
7111 ti->sort_priority = value;
7113 sprintf(identifier, "%d", value);
7114 sprintf(name, "%s", text);
7116 setString(&ti->identifier, identifier);
7117 setString(&ti->name, name);
7118 setString(&ti->name_sorting, name);
7119 setString(&ti->infotext,
7122 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7123 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7125 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7126 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7128 pushTreeInfo(&grid_sizes[i][j], ti);
7131 // sort grid size values to start with lowest grid size value
7132 sortTreeInfo(&grid_sizes[i][j]);
7134 // set current grid size value to configured grid size value
7135 grid_size_current[i][j] =
7136 getTreeInfoFromIdentifier(grid_sizes[i][j],
7138 setup.touch.grid_xsize[i] :
7139 setup.touch.grid_ysize[i]));
7141 // if that fails, set current grid size to reliable default value
7142 if (grid_size_current[i][j] == NULL)
7143 grid_size_current[i][j] =
7144 getTreeInfoFromIdentifier(grid_sizes[i][j],
7146 DEFAULT_GRID_XSIZE(i) :
7147 DEFAULT_GRID_YSIZE(i)));
7149 // if that also fails, set current grid size to first available value
7150 if (grid_size_current[i][j] == NULL)
7151 grid_size_current[i][j] = grid_sizes[i][j];
7156 setup.touch.control_type = touch_control_current->identifier;
7157 setup.touch.move_distance = atoi(move_distance_current->identifier);
7158 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7159 setup.touch.transparency = atoi(transparency_current->identifier);
7161 for (i = 0; i < 2; i++)
7163 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7164 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7166 if (i == GRID_ACTIVE_NR())
7168 overlay.grid_xsize = setup.touch.grid_xsize[i];
7169 overlay.grid_ysize = setup.touch.grid_ysize[i];
7173 // needed for displaying value text instead of identifier
7174 touch_controls_text = touch_control_current->name;
7175 move_distance_text = move_distance_current->name;
7176 drop_distance_text = drop_distance_current->name;
7177 transparency_text = transparency_current->name;
7179 for (i = 0; i < 2; i++)
7180 for (j = 0; j < 2; j++)
7181 grid_size_text[i][j] = grid_size_current[i][j]->name;
7183 setup_mode = SETUP_MODE_TOUCH;
7188 static void execSetupArtwork(void)
7190 static ArtworkDirTree *gfx_last_valid = NULL;
7191 static ArtworkDirTree *snd_last_valid = NULL;
7192 static ArtworkDirTree *mus_last_valid = NULL;
7194 // current artwork directory may be invalid (level group, parent link)
7195 if (!validLevelSeries(artwork.gfx_current))
7196 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7197 if (!validLevelSeries(artwork.snd_current))
7198 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7199 if (!validLevelSeries(artwork.mus_current))
7200 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7202 // store valid artwork directory information
7203 gfx_last_valid = artwork.gfx_current;
7204 snd_last_valid = artwork.snd_current;
7205 mus_last_valid = artwork.mus_current;
7208 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7209 artwork.gfx_current->subdir,
7210 artwork.gfx_current->fullpath,
7211 artwork.gfx_current->basepath);
7214 setup.graphics_set = artwork.gfx_current->identifier;
7215 setup.sounds_set = artwork.snd_current->identifier;
7216 setup.music_set = artwork.mus_current->identifier;
7218 // needed if last screen (setup choice) changed graphics, sounds or music
7219 ReloadCustomArtwork(0);
7221 // needed for displaying artwork name instead of artwork identifier
7222 graphics_set_name = artwork.gfx_current->name;
7223 sounds_set_name = artwork.snd_current->name;
7224 music_set_name = artwork.mus_current->name;
7226 setup_mode = SETUP_MODE_ARTWORK;
7231 static void execSetupChooseGraphics(void)
7233 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7238 static void execSetupChooseSounds(void)
7240 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7245 static void execSetupChooseMusic(void)
7247 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7252 static void execSetupInput(void)
7254 setup_mode = SETUP_MODE_INPUT;
7259 static void execSetupShortcuts(void)
7261 setup_mode = SETUP_MODE_SHORTCUTS;
7266 static void execSetupShortcuts1(void)
7268 setup_mode = SETUP_MODE_SHORTCUTS_1;
7273 static void execSetupShortcuts2(void)
7275 setup_mode = SETUP_MODE_SHORTCUTS_2;
7280 static void execSetupShortcuts3(void)
7282 setup_mode = SETUP_MODE_SHORTCUTS_3;
7287 static void execSetupShortcuts4(void)
7289 setup_mode = SETUP_MODE_SHORTCUTS_4;
7294 static void execSetupShortcuts5(void)
7296 setup_mode = SETUP_MODE_SHORTCUTS_5;
7301 static void execExitSetup(void)
7303 SetGameStatus(GAME_MODE_MAIN);
7308 static void execSaveAndExitSetup(void)
7314 static void execGadgetNetworkServer(void)
7316 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7317 struct GadgetInfo *gi = screen_gadget[gadget_id];
7319 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7320 network_server_hostname[0] = '\0';
7322 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7326 ClickOnGadget(gi, MB_LEFTBUTTON);
7329 static void execOfferUploadTapes(void)
7334 static void ToggleNetworkModeIfNeeded(void)
7336 int font_title = FONT_TITLE_1;
7337 int font_foot = FC_BLUE;
7338 int ystart = mSY - SY + 16;
7339 int ybottom = mSY - SY + SYSIZE - 20;
7340 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7342 if (setup.network_mode == network.enabled)
7345 network.enabled = setup.network_mode;
7347 FadeOut(REDRAW_ALL);
7351 DrawTextSCentered(ystart, font_title, text);
7355 if (network.enabled)
7356 InitNetworkServer();
7358 DisconnectFromNetworkServer();
7360 DrawTextSCentered(ybottom, font_foot,
7361 "Press any key or button for setup menu");
7363 WaitForEventToContinue();
7368 static void ToggleGameSpeedsListIfNeeded(void)
7370 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7372 if (setup.game_speed_extended == using_game_speeds_extended)
7375 // try to match similar values when changing game speeds list
7376 if (setup.game_speed_extended)
7377 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7378 setup.game_frame_delay == 30 ? 29 :
7379 setup.game_frame_delay);
7381 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7382 setup.game_frame_delay == 16 ? 15 :
7383 setup.game_frame_delay >= 29 ? 30 :
7384 setup.game_frame_delay <= 10 ? 10 :
7385 setup.game_frame_delay);
7387 execSetupGame_setGameSpeeds(TRUE);
7392 static void ToggleUseApiServerIfNeeded(void)
7394 if (runtime.use_api_server == setup.use_api_server)
7397 runtime.use_api_server = setup.use_api_server;
7399 if (runtime.use_api_server)
7400 CheckApiServerTasks();
7403 static void ModifyGameSpeedIfNeeded(void)
7405 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7406 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7410 char *game_speed_text = "Fast";
7411 int game_speed_value = 15;
7413 if (setup.game_speed_extended)
7415 game_speed_text = "60 fps";
7416 game_speed_value = 16;
7419 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7421 // set game speed to existing list value that is fast enough for vsync
7422 setup.game_frame_delay = game_speed_value;
7424 execSetupGame_setGameSpeeds(TRUE);
7426 Request(message, REQ_CONFIRM);
7429 static void DisableVsyncIfNeeded(void)
7431 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7432 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7433 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7436 // disable vsync for the selected game speed to work
7437 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7439 execSetupGraphics_setVsyncModes(TRUE);
7441 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7447 void *related_value;
7448 } hide_related_entry_list[] =
7450 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7451 { &setup.scores_in_highscore_list, &scores_type_text },
7453 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7454 { &setup.game_frame_delay, &game_speed_text },
7456 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7457 { &setup.scroll_delay_value, &scroll_delay_text },
7459 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7460 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7462 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7463 { &setup.window_scaling_percent, &window_size_text },
7465 { &setup.window_scaling_quality, execSetupChooseScalingType },
7466 { &setup.window_scaling_quality, &scaling_type_text },
7468 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7469 { &setup.screen_rendering_mode, &rendering_mode_text },
7471 { &setup.vsync_mode, execSetupChooseVsyncMode },
7472 { &setup.vsync_mode, &vsync_mode_text },
7474 { &setup.graphics_set, execSetupChooseGraphics },
7475 { &setup.graphics_set, &graphics_set_name },
7477 { &setup.sounds_set, execSetupChooseSounds },
7478 { &setup.sounds_set, &sounds_set_name },
7480 { &setup.music_set, execSetupChooseMusic },
7481 { &setup.music_set, &music_set_name },
7483 { &setup.volume_simple, execSetupChooseVolumeSimple },
7484 { &setup.volume_simple, &volume_simple_text },
7486 { &setup.volume_loops, execSetupChooseVolumeLoops },
7487 { &setup.volume_loops, &volume_loops_text },
7489 { &setup.volume_music, execSetupChooseVolumeMusic },
7490 { &setup.volume_music, &volume_music_text },
7492 { &setup.touch.control_type, execSetupChooseTouchControls },
7493 { &setup.touch.control_type, &touch_controls_text },
7495 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7496 { &setup.touch.move_distance, &move_distance_text },
7498 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7499 { &setup.touch.drop_distance, &drop_distance_text },
7501 { &setup.touch.transparency, execSetupChooseTransparency },
7502 { &setup.touch.transparency, &transparency_text },
7504 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7505 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7507 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7508 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7510 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7511 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7513 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7514 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7516 { &setup.internal.menu_game, execSetupGame },
7517 { &setup.internal.menu_engines, execSetupEngines },
7518 { &setup.internal.menu_editor, execSetupEditor },
7519 { &setup.internal.menu_graphics, execSetupGraphics },
7520 { &setup.internal.menu_sound, execSetupSound },
7521 { &setup.internal.menu_artwork, execSetupArtwork },
7522 { &setup.internal.menu_input, execSetupInput },
7523 { &setup.internal.menu_touch, execSetupTouch },
7524 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7525 { &setup.internal.menu_exit, execExitSetup },
7526 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7531 void setHideRelatedSetupEntries(void)
7535 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7536 if (hideSetupEntry(hide_related_entry_list[i].value))
7537 setHideSetupEntry(hide_related_entry_list[i].related_value);
7540 static struct TokenInfo setup_info_main[] =
7542 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7543 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7544 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7545 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7546 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7547 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7548 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7549 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7550 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7551 { TYPE_EMPTY, NULL, "" },
7552 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7553 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7558 static struct TokenInfo setup_info_game[] =
7560 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7561 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7562 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7563 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7564 { TYPE_STRING, &network_server_text, "" },
7565 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7566 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7567 { TYPE_STRING, &scores_type_text, "" },
7568 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7569 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7570 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7571 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7572 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7573 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7574 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7575 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7576 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7577 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7578 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7579 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7580 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7581 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7582 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7583 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7584 { TYPE_STRING, &game_speed_text, "" },
7585 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7587 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7588 { TYPE_STRING, &scroll_delay_text, "" },
7590 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7591 { TYPE_STRING, &snapshot_mode_text, "" },
7592 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7593 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7594 { TYPE_EMPTY, NULL, "" },
7595 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7600 static struct TokenInfo setup_info_engines[] =
7602 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7603 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7604 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7605 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7606 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7607 { TYPE_EMPTY, NULL, "" },
7608 { TYPE_HEADLINE, NULL, "Supaplex" },
7609 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7610 { TYPE_EMPTY, NULL, "" },
7611 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7616 static struct TokenInfo setup_info_editor[] =
7619 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7620 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7621 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7622 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7623 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7624 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7625 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7626 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7627 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7628 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7630 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7631 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7633 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7635 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7636 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7637 { TYPE_EMPTY, NULL, "" },
7639 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7640 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7641 { TYPE_EMPTY, NULL, "" },
7643 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7644 { TYPE_EMPTY, NULL, "" },
7645 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7646 { TYPE_EMPTY, NULL, "" },
7647 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7652 static struct TokenInfo setup_info_graphics[] =
7654 #if !defined(PLATFORM_ANDROID)
7655 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7656 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7657 { TYPE_STRING, &window_size_text, "" },
7658 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7659 { TYPE_STRING, &scaling_type_text, "" },
7660 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7661 { TYPE_STRING, &rendering_mode_text, "" },
7664 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7665 { TYPE_STRING, &scroll_delay_text, "" },
7667 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7668 { TYPE_STRING, &vsync_mode_text, "" },
7669 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7670 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7671 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7672 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7673 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7674 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7675 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7676 { TYPE_EMPTY, NULL, "" },
7677 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7682 static struct TokenInfo setup_info_sound[] =
7684 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7685 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7686 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7687 { TYPE_EMPTY, NULL, "" },
7688 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7689 { TYPE_STRING, &volume_simple_text, "" },
7690 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7691 { TYPE_STRING, &volume_loops_text, "" },
7692 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7693 { TYPE_STRING, &volume_music_text, "" },
7694 { TYPE_EMPTY, NULL, "" },
7695 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7700 static struct TokenInfo setup_info_artwork[] =
7702 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7703 { TYPE_STRING, &graphics_set_name, "" },
7704 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7705 { TYPE_STRING, &sounds_set_name, "" },
7706 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7707 { TYPE_STRING, &music_set_name, "" },
7708 { TYPE_EMPTY, NULL, "" },
7709 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7710 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7711 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7712 { TYPE_EMPTY, NULL, "" },
7713 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7718 static struct TokenInfo setup_info_input[] =
7720 { TYPE_SWITCH, NULL, "Player:" },
7721 { TYPE_SWITCH, NULL, "Device:" },
7722 { TYPE_SWITCH, NULL, "" },
7723 { TYPE_SKIPPABLE, NULL, "" },
7724 { TYPE_EMPTY, NULL, "" },
7725 { TYPE_EMPTY, NULL, "" },
7726 { TYPE_EMPTY, NULL, "" },
7727 { TYPE_EMPTY, NULL, "" },
7728 { TYPE_EMPTY, NULL, "" },
7729 { TYPE_EMPTY, NULL, "" },
7730 { TYPE_EMPTY, NULL, "" },
7731 { TYPE_EMPTY, NULL, "" },
7732 { TYPE_SKIPPABLE, NULL, "" },
7733 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7738 static struct TokenInfo setup_info_touch[] =
7740 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7741 { TYPE_STRING, &touch_controls_text, "" },
7742 { TYPE_EMPTY, NULL, "" },
7743 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7748 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7750 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7751 { TYPE_STRING, &touch_controls_text, "" },
7752 { TYPE_EMPTY, NULL, "" },
7753 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7754 { TYPE_STRING, &grid_size_text[0][0], "" },
7755 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7756 { TYPE_STRING, &grid_size_text[0][1], "" },
7757 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7758 { TYPE_STRING, &transparency_text, "" },
7759 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7760 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7761 { TYPE_EMPTY, NULL, "" },
7762 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7763 { TYPE_EMPTY, NULL, "" },
7764 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7769 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7771 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7772 { TYPE_STRING, &touch_controls_text, "" },
7773 { TYPE_EMPTY, NULL, "" },
7774 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7775 { TYPE_STRING, &grid_size_text[1][0], "" },
7776 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7777 { TYPE_STRING, &grid_size_text[1][1], "" },
7778 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7779 { TYPE_STRING, &transparency_text, "" },
7780 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7781 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7782 { TYPE_EMPTY, NULL, "" },
7783 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7784 { TYPE_EMPTY, NULL, "" },
7785 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7790 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7792 setup_info_touch_virtual_buttons_0,
7793 setup_info_touch_virtual_buttons_1
7796 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7798 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7799 { TYPE_STRING, &touch_controls_text, "" },
7800 { TYPE_EMPTY, NULL, "" },
7801 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7802 { TYPE_STRING, &move_distance_text, "" },
7803 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7804 { TYPE_STRING, &drop_distance_text, "" },
7805 { TYPE_EMPTY, NULL, "" },
7806 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7811 static struct TokenInfo setup_info_shortcuts[] =
7813 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7814 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7815 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7816 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7817 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7818 { TYPE_EMPTY, NULL, "" },
7819 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7824 static struct TokenInfo setup_info_shortcuts_1[] =
7826 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7827 { TYPE_KEY, &setup.shortcut.save_game, "" },
7828 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7829 { TYPE_KEY, &setup.shortcut.load_game, "" },
7830 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7831 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7832 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7833 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7834 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7835 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7836 { TYPE_EMPTY, NULL, "" },
7837 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7838 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7839 { TYPE_EMPTY, NULL, "" },
7840 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7845 static struct TokenInfo setup_info_shortcuts_2[] =
7847 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7848 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7849 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7850 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7851 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7852 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7853 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7854 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7855 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7856 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7857 { TYPE_EMPTY, NULL, "" },
7858 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7863 static struct TokenInfo setup_info_shortcuts_3[] =
7865 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7866 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7867 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7868 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7869 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7870 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7871 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7872 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7873 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7874 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7875 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7876 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7877 { TYPE_EMPTY, NULL, "" },
7878 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7883 static struct TokenInfo setup_info_shortcuts_4[] =
7885 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7886 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7887 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7888 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7889 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7890 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7891 { TYPE_EMPTY, NULL, "" },
7892 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7897 static struct TokenInfo setup_info_shortcuts_5[] =
7899 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7900 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7901 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7902 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7903 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7904 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7905 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7906 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7907 { TYPE_EMPTY, NULL, "" },
7908 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7913 static Key getSetupKey(void)
7915 Key key = KSYM_UNDEFINED;
7916 boolean got_key_event = FALSE;
7918 while (!got_key_event)
7922 if (NextValidEvent(&event))
7926 case EVENT_KEYPRESS:
7928 key = GetEventKey((KeyEvent *)&event, TRUE);
7930 // press 'Escape' or 'Enter' to keep the existing key binding
7931 if (key == KSYM_Escape || key == KSYM_Return)
7932 key = KSYM_UNDEFINED; // keep old value
7934 got_key_event = TRUE;
7938 case EVENT_KEYRELEASE:
7939 key_joystick_mapping = 0;
7943 HandleOtherEvents(&event);
7954 static int getSetupValueFont(int type, void *value)
7956 if (type & TYPE_GHOSTED)
7957 return FONT_OPTION_OFF;
7958 else if (type & TYPE_KEY)
7959 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7960 else if (type & TYPE_STRING)
7961 return FONT_VALUE_2;
7962 else if (type & TYPE_ECS_AGA)
7963 return FONT_VALUE_1;
7964 else if (type & TYPE_BOOLEAN_STYLE)
7965 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7966 else if (type & TYPE_YES_NO_AUTO)
7967 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7968 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7969 else if (type & TYPE_PLAYER)
7970 return FONT_VALUE_1;
7972 return FONT_VALUE_1;
7975 static int getSetupValueFontNarrow(int type, int font_nr)
7977 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7978 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7979 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7983 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7985 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7986 struct TokenInfo *si = &setup_info[si_pos];
7987 boolean font_draw_xoffset_modified = FALSE;
7988 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7989 int font_draw_xoffset_old = -1;
7990 int xoffset = (scrollbar_needed ? -1 : 0);
7991 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7992 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7993 int xpos = menu_screen_value_xpos;
7994 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7995 int startx = mSX + xpos * 32;
7996 int starty = mSY + ypos * 32;
7997 int type = si->type;
7998 void *value = si->value;
7999 char *value_string = getSetupValue(type, value);
8000 int font_nr_default = getSetupValueFont(type, value);
8001 int font_width_default = getFontWidth(font_nr_default);
8002 int font_nr = font_nr_default;
8005 if (value_string == NULL)
8008 if (type & TYPE_KEY)
8010 xpos = MENU_SCREEN_START_XPOS;
8012 if (type & TYPE_QUERY)
8013 value_string = "<press key>";
8015 else if (type & TYPE_STRING)
8017 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
8019 xpos = MENU_SCREEN_START_XPOS;
8021 if (strlen(value_string) > max_value_len)
8022 value_string[max_value_len] = '\0';
8024 else if (type & TYPE_YES_NO_AUTO)
8026 xpos = menu_screen_value_xpos - 1;
8028 else if (type & TYPE_PLAYER)
8030 int displayed_player_nr = *(int *)value + 1;
8032 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
8035 startx = mSX + xpos * 32;
8036 starty = mSY + ypos * 32;
8038 // special check if right-side setup values moved left due to scrollbar
8039 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
8041 int max_menu_text_length = 26; // maximum text length for classic menu
8042 int font_xoffset = getFontDrawOffsetX(font_nr);
8043 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8044 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8045 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8046 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
8048 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
8050 // when using narrow font, left-shifting text "auto" not needed
8051 if (type & TYPE_YES_NO_AUTO)
8055 startx = mSX + xpos * 32;
8057 font_nr = getSetupValueFontNarrow(type, font_nr);
8061 // downward compatibility correction for Juergen Bonhagen's menu settings
8062 if (setup_mode != SETUP_MODE_INPUT)
8064 int max_menu_text_length_big = (menu_screen_value_xpos -
8065 MENU_SCREEN_START_XPOS);
8066 int max_menu_text_length_medium = max_menu_text_length_big * 2;
8067 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
8068 int font1_xoffset = getFontDrawOffsetX(font_nr);
8069 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
8070 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8071 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8072 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8073 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8074 boolean correct_font_draw_xoffset = FALSE;
8076 if (xpos == MENU_SCREEN_START_XPOS &&
8077 startx + font1_xoffset < text_startx + text_font_xoffset)
8078 correct_font_draw_xoffset = TRUE;
8080 if (xpos == menu_screen_value_xpos &&
8081 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8082 correct_font_draw_xoffset = TRUE;
8084 // check if setup value would overlap with setup text when printed
8085 // (this can happen for extreme/wrong values for font draw offset)
8086 if (correct_font_draw_xoffset)
8088 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8089 font_draw_xoffset_modified = TRUE;
8091 if (type & TYPE_KEY)
8092 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8093 else if (!(type & TYPE_STRING))
8094 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8095 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8099 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
8100 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
8102 DrawText(startx, starty, value_string, font_nr);
8104 if (type & TYPE_PLAYER)
8106 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8107 int player_nr = *(int *)value;
8108 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8109 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8110 int startx2 = startx + xoff;
8111 int starty2 = starty + yoff;
8113 if (DrawingOnBackground(startx2, starty2))
8114 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8116 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8117 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8120 if (font_draw_xoffset_modified)
8121 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8124 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8126 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8127 struct TokenInfo *si = &setup_info[si_pos];
8129 if (si->type & TYPE_BOOLEAN_STYLE)
8131 *(boolean *)si->value ^= TRUE;
8133 else if (si->type & TYPE_YES_NO_AUTO)
8137 (*(int *)si->value == AUTO ? TRUE :
8138 *(int *)si->value == TRUE ? FALSE : AUTO) :
8139 (*(int *)si->value == TRUE ? AUTO :
8140 *(int *)si->value == AUTO ? FALSE : TRUE));
8142 else if (si->type & TYPE_KEY)
8146 si->type |= TYPE_QUERY;
8147 drawSetupValue(screen_pos, setup_info_pos_raw);
8148 si->type &= ~TYPE_QUERY;
8150 key = getSetupKey();
8151 if (key != KSYM_UNDEFINED)
8152 *(Key *)si->value = key;
8154 else if (si->type & TYPE_PLAYER)
8156 int player_nr = *(int *)si->value;
8161 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8163 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8166 drawSetupValue(screen_pos, setup_info_pos_raw);
8168 // fullscreen state may have changed at this point
8169 if (si->value == &setup.fullscreen)
8170 ToggleFullscreenIfNeeded();
8172 // network mode may have changed at this point
8173 if (si->value == &setup.network_mode)
8174 ToggleNetworkModeIfNeeded();
8176 // API server mode may have changed at this point
8177 if (si->value == &setup.use_api_server)
8178 ToggleUseApiServerIfNeeded();
8180 // game speed list may have changed at this point
8181 if (si->value == &setup.game_speed_extended)
8182 ToggleGameSpeedsListIfNeeded();
8185 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8187 static struct TokenInfo *setup_info_final = NULL;
8192 // determine maximum list size of target list
8193 while (setup_info_orig[list_size++].type != 0);
8195 // free, allocate and clear memory for target list
8196 checked_free(setup_info_final);
8197 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8199 // copy setup info list without setup entries marked as hidden
8200 for (i = 0; setup_info_orig[i].type != 0; i++)
8202 // skip setup entries configured to be hidden
8203 if (hideSetupEntry(setup_info_orig[i].value))
8206 // skip skippable setup entries if screen is lower than usual
8207 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8208 setup_info_orig[i].type == TYPE_SKIPPABLE)
8211 setup_info_final[list_pos++] = setup_info_orig[i];
8214 return setup_info_final;
8217 static void DrawSetupScreen_Generic(void)
8219 int fade_mask = REDRAW_FIELD;
8220 boolean redraw_all = FALSE;
8221 char *title_string = NULL;
8225 fade_mask = REDRAW_ALL;
8228 FadeMenuSoundsAndMusic();
8230 FreeScreenGadgets();
8231 CreateScreenGadgets();
8233 if (redraw_mask & REDRAW_ALL)
8238 // needed if different viewport properties defined for setup screen
8239 ChangeViewportPropertiesIfNeeded();
8241 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8245 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8247 if (setup_mode == SETUP_MODE_MAIN)
8249 setup_info = setup_info_main;
8250 title_string = STR_SETUP_MAIN;
8252 else if (setup_mode == SETUP_MODE_GAME)
8254 setup_info = setup_info_game;
8255 title_string = STR_SETUP_GAME;
8257 else if (setup_mode == SETUP_MODE_ENGINES)
8259 setup_info = setup_info_engines;
8260 title_string = STR_SETUP_ENGINES;
8262 else if (setup_mode == SETUP_MODE_EDITOR)
8264 setup_info = setup_info_editor;
8265 title_string = STR_SETUP_EDITOR;
8267 else if (setup_mode == SETUP_MODE_GRAPHICS)
8269 setup_info = setup_info_graphics;
8270 title_string = STR_SETUP_GRAPHICS;
8272 else if (setup_mode == SETUP_MODE_SOUND)
8274 setup_info = setup_info_sound;
8275 title_string = STR_SETUP_SOUND;
8277 else if (setup_mode == SETUP_MODE_ARTWORK)
8279 setup_info = setup_info_artwork;
8280 title_string = STR_SETUP_ARTWORK;
8282 else if (setup_mode == SETUP_MODE_TOUCH)
8284 setup_info = setup_info_touch;
8285 title_string = STR_SETUP_TOUCH;
8287 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8288 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8289 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8290 setup_info = setup_info_touch_wipe_gestures;
8292 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8294 setup_info = setup_info_shortcuts;
8295 title_string = STR_SETUP_SHORTCUTS;
8297 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8299 setup_info = setup_info_shortcuts_1;
8300 title_string = STR_SETUP_SHORTCUTS;
8302 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8304 setup_info = setup_info_shortcuts_2;
8305 title_string = STR_SETUP_SHORTCUTS;
8307 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8309 setup_info = setup_info_shortcuts_3;
8310 title_string = STR_SETUP_SHORTCUTS;
8312 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8314 setup_info = setup_info_shortcuts_4;
8315 title_string = STR_SETUP_SHORTCUTS;
8317 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8319 setup_info = setup_info_shortcuts_5;
8320 title_string = STR_SETUP_SHORTCUTS;
8323 // use modified setup info without setup entries marked as hidden
8324 setup_info = getSetupInfoFinal(setup_info);
8326 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8328 // determine maximal number of setup entries that can be displayed on screen
8330 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8333 // determine maximal number of setup entries available for this setup screen
8335 for (i = 0; setup_info[i].type != 0; i++)
8338 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8340 MapScreenGadgets(max_setup_info);
8343 redraw_mask = fade_mask = REDRAW_ALL;
8345 DrawMaskedBorder(fade_mask);
8350 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8352 menu_info = setup_info;
8354 HandleMenuScreen(mx, my, dx, dy, button,
8355 setup_mode, num_setup_info, max_setup_info);
8358 static void DrawSetupScreen_Input(void)
8362 FadeOut(REDRAW_FIELD);
8366 setup_info = getSetupInfoFinal(setup_info_input);
8368 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8370 for (i = 0; setup_info[i].type != 0; i++)
8372 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8373 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8374 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8375 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8376 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8377 initCursor(i, IMG_MENU_BUTTON);
8379 DrawCursorAndText_Setup(i, -1, FALSE);
8382 // create gadgets for setup input menu screen
8383 FreeScreenGadgets();
8384 CreateScreenGadgets();
8386 // map gadgets for setup input menu screen
8387 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8389 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8391 FadeIn(REDRAW_FIELD);
8394 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8396 if (device_name == NULL)
8399 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8402 if (strlen(device_name) > 1)
8404 char c1 = device_name[strlen(device_name) - 1];
8405 char c2 = device_name[strlen(device_name) - 2];
8407 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8408 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8411 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8412 strlen(device_name));
8415 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8418 static struct SetupKeyboardInfo custom_key;
8425 { &custom_key.left, "Axis/Pad Left" },
8426 { &custom_key.right, "Axis/Pad Right" },
8427 { &custom_key.up, "Axis/Pad Up" },
8428 { &custom_key.down, "Axis/Pad Down" },
8429 { &custom_key.snap, "Button 1/A/X" },
8430 { &custom_key.drop, "Button 2/B/Y" }
8432 static char *joystick_name[MAX_PLAYERS] =
8439 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8440 int font_nr_info = FONT_MENU_1;
8441 int font_nr_name = FONT_VALUE_OLD;
8442 int font_nr_on = FONT_VALUE_1;
8443 int font_nr_off = FONT_VALUE_OLD;
8446 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8448 font_nr_info = FONT_MENU_2;
8449 font_nr_on = FONT_VALUE_NARROW;
8450 font_nr_off = FONT_VALUE_OLD_NARROW;
8453 custom_key = setup.input[player_nr].key;
8455 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8456 FONT_INPUT_1_ACTIVE);
8458 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8460 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8461 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8463 if (setup.input[player_nr].use_joystick)
8465 char *device_name = setup.input[player_nr].joy.device_name;
8466 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8467 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8468 char *text = joystick_name[joystick_nr];
8469 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8471 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8472 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8476 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8477 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8480 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8481 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8485 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8486 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8487 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8488 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8490 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8491 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8492 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8493 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8494 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8495 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8497 for (i = 0; i < 6; i++)
8499 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8501 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8503 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8504 (setup.input[player_nr].use_joystick ?
8506 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8510 static int input_player_nr = 0;
8512 static void HandleSetupScreen_Input_Player(int step, int direction)
8514 int old_player_nr = input_player_nr;
8517 new_player_nr = old_player_nr + step * direction;
8518 if (new_player_nr < 0)
8520 if (new_player_nr > MAX_PLAYERS - 1)
8521 new_player_nr = MAX_PLAYERS - 1;
8523 if (new_player_nr != old_player_nr)
8525 input_player_nr = new_player_nr;
8527 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8531 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8533 static int choice = 0;
8536 int pos_start = SETUPINPUT_SCREEN_POS_START;
8537 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8538 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8539 int pos_end = SETUPINPUT_SCREEN_POS_END;
8541 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8545 for (i = 0; setup_info_input[i].type != 0; i++)
8547 // adjust menu structure according to skipped setup entries
8548 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8556 if (button == MB_MENU_INITIALIZE)
8558 // input setup menu may have changed size due to graphics configuration
8559 if (choice >= pos_empty1)
8562 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8564 DrawCursorAndText_Setup(choice, -1, TRUE);
8568 else if (button == MB_MENU_LEAVE)
8570 setup_mode = SETUP_MODE_MAIN;
8577 if (mx || my) // mouse input
8579 x = (mx - mSX) / 32;
8580 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8582 else if (dx || dy) // keyboard input
8584 if (dx && choice == 0)
8585 x = (dx < 0 ? 10 : 12);
8586 else if ((dx && choice == 1) ||
8587 (dx == -1 && choice == pos_end))
8588 button = MB_MENU_CHOICE;
8592 if (y >= pos_empty1 && y <= pos_empty2)
8593 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8596 if (y == 0 && dx != 0 && button)
8598 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8600 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8601 y >= pos_start && y <= pos_end &&
8602 !(y >= pos_empty1 && y <= pos_empty2))
8608 DrawCursorAndText_Setup(choice, -1, FALSE);
8609 DrawCursorAndText_Setup(y, -1, TRUE);
8611 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8620 char *device_name = setup.input[input_player_nr].joy.device_name;
8622 if (!setup.input[input_player_nr].use_joystick)
8624 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8626 setJoystickDeviceToNr(device_name, new_device_nr);
8627 setup.input[input_player_nr].use_joystick = TRUE;
8631 int device_nr = getJoystickNrFromDeviceName(device_name);
8632 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8634 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8635 setup.input[input_player_nr].use_joystick = FALSE;
8637 setJoystickDeviceToNr(device_name, new_device_nr);
8640 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8644 if (setup.input[input_player_nr].use_joystick)
8645 ConfigureJoystick(input_player_nr);
8647 CustomizeKeyboard(input_player_nr);
8649 else if (y == pos_end)
8655 setup_mode = SETUP_MODE_MAIN;
8662 static boolean CustomizeKeyboardMain(int player_nr)
8666 boolean finished = FALSE;
8667 static struct SetupKeyboardInfo custom_key;
8672 } customize_step[] =
8674 { &custom_key.left, "Move Left" },
8675 { &custom_key.right, "Move Right" },
8676 { &custom_key.up, "Move Up" },
8677 { &custom_key.down, "Move Down" },
8678 { &custom_key.snap, "Snap Field" },
8679 { &custom_key.drop, "Drop Element" }
8681 int font_nr_old = FONT_VALUE_OLD;
8682 int font_nr_new = FONT_VALUE_1;
8683 boolean success = FALSE;
8685 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8687 font_nr_old = FONT_VALUE_OLD_NARROW;
8688 font_nr_new = FONT_VALUE_NARROW;
8691 // read existing key bindings from player setup
8692 custom_key = setup.input[player_nr].key;
8695 FadeOut(REDRAW_FIELD);
8699 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8702 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8703 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8704 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8705 "Key:", FONT_INPUT_1_ACTIVE);
8706 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8707 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8709 FadeIn(REDRAW_FIELD);
8715 if (NextValidEvent(&event))
8719 case EVENT_KEYPRESS:
8721 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8723 // press 'Escape' to abort and keep the old key bindings
8724 if (key == KSYM_Escape)
8726 FadeSkipNextFadeIn();
8733 // press 'Enter' to keep the existing key binding
8734 if (key == KSYM_Return)
8735 key = *customize_step[step_nr].key;
8737 // check if key already used
8738 for (i = 0; i < step_nr; i++)
8739 if (*customize_step[i].key == key)
8744 // got new key binding
8745 *customize_step[step_nr].key = key;
8746 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8748 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8749 getKeyNameFromKey(key), font_nr_new);
8752 // un-highlight last query
8753 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8754 customize_step[step_nr - 1].text, FONT_MENU_1);
8755 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8756 "Key:", FONT_MENU_1);
8758 // all keys configured
8767 // query next key binding
8768 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8769 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8770 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8771 "Key:", FONT_INPUT_1_ACTIVE);
8772 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8773 getKeyNameFromKey(*customize_step[step_nr].key),
8778 case EVENT_KEYRELEASE:
8779 key_joystick_mapping = 0;
8783 HandleOtherEvents(&event);
8791 // write new key bindings back to player setup, if successfully finished
8793 setup.input[player_nr].key = custom_key;
8798 void CustomizeKeyboard(int player_nr)
8800 boolean success = CustomizeKeyboardMain(player_nr);
8804 int font_nr = FONT_TITLE_1;
8805 int font_height = getFontHeight(font_nr);
8806 int ypos1 = SYSIZE / 2 - font_height * 2;
8807 int ypos2 = SYSIZE / 2 - font_height * 1;
8808 unsigned int wait_frame_delay = 0;
8809 unsigned int wait_frame_delay_value = 2000;
8811 ResetDelayCounter(&wait_frame_delay);
8815 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8816 DrawTextSCentered(ypos2, font_nr, "configured!");
8818 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8824 DrawSetupScreen_Input();
8827 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8829 #define MARKER_BUTTON 1
8830 #define MARKER_AXIS_X 2
8831 #define MARKER_AXIS_Y 3
8833 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8835 static boolean bitmaps_initialized = FALSE;
8836 boolean screen_initialized = FALSE;
8837 static Bitmap *controller, *button, *axis_x, *axis_y;
8839 boolean success = TRUE;
8840 boolean done = FALSE, next = FALSE;
8842 int alpha = 200, alpha_step = -1;
8843 int alpha_ticks = 0;
8844 char mapping[4096], temp[256];
8845 int font_name = MENU_SETUP_FONT_TITLE;
8846 int font_info = MENU_SETUP_FONT_TEXT;
8847 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8848 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8849 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8850 int ystep_name = getMenuTextStep(spacing_name, font_name);
8851 int ystep_line = getMenuTextStep(spacing_line, font_info);
8852 int ystep_para = getMenuTextStep(spacing_para, font_info);
8860 int axis, button, hat, hat_value;
8863 *step, *prev_step, steps[] =
8865 { 356, 155, MARKER_BUTTON, "a", },
8866 { 396, 122, MARKER_BUTTON, "b", },
8867 { 320, 125, MARKER_BUTTON, "x", },
8868 { 358, 95, MARKER_BUTTON, "y", },
8869 { 162, 125, MARKER_BUTTON, "back", },
8870 { 216, 125, MARKER_BUTTON, "guide", },
8871 { 271, 125, MARKER_BUTTON, "start", },
8872 { 110, 200, MARKER_BUTTON, "dpleft", },
8873 { 146, 228, MARKER_BUTTON, "dpdown", },
8874 { 178, 200, MARKER_BUTTON, "dpright", },
8875 { 146, 172, MARKER_BUTTON, "dpup", },
8876 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8877 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8878 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8879 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8880 { 73, 141, MARKER_BUTTON, "leftstick", },
8881 { 282, 210, MARKER_BUTTON, "rightstick", },
8882 { 73, 141, MARKER_AXIS_X, "leftx", },
8883 { 73, 141, MARKER_AXIS_Y, "lefty", },
8884 { 282, 210, MARKER_AXIS_X, "rightx", },
8885 { 282, 210, MARKER_AXIS_Y, "righty", },
8888 unsigned int event_frame_delay = 0;
8889 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8891 ResetDelayCounter(&event_frame_delay);
8893 if (!bitmaps_initialized)
8895 controller = LoadCustomImage("joystick/controller.png");
8896 button = LoadCustomImage("joystick/button.png");
8897 axis_x = LoadCustomImage("joystick/axis_x.png");
8898 axis_y = LoadCustomImage("joystick/axis_y.png");
8900 bitmaps_initialized = TRUE;
8903 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8906 // print info about the joystick we are watching
8907 Debug("joystick", "watching joystick %d: (%s)",
8908 SDL_JoystickInstanceID(joystick), name);
8909 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8910 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8911 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8914 // initialize mapping with GUID and name
8915 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8917 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8918 temp, name, SDL_GetPlatform());
8920 // loop through all steps (buttons and axes), getting joystick events
8921 for (i = 0; i < SDL_arraysize(steps) && !done;)
8923 Bitmap *marker = button; // initialize with reliable default value
8926 strcpy(step->mapping, mapping);
8930 step->hat_value = -1;
8932 marker = (step->marker == MARKER_BUTTON ? button :
8933 step->marker == MARKER_AXIS_X ? axis_x :
8934 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8938 while (!done && !next)
8940 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8941 alpha_ticks = SDL_GetTicks();
8948 else if (alpha < 128)
8954 int controller_x = SX + (SXSIZE - controller->width) / 2;
8955 int controller_y = SY + ystep_line;
8957 int marker_x = controller_x + step->x;
8958 int marker_y = controller_y + step->y;
8960 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8961 int ystart2 = ystart1 + ystep_name + ystep_line;
8965 DrawTextSCentered(ystart1, font_name, name);
8967 DrawTextSCentered(ystart2, font_info,
8968 "Press buttons and move axes on");
8969 ystart2 += ystep_line;
8970 DrawTextSCentered(ystart2, font_info,
8971 "your controller when indicated.");
8972 ystart2 += ystep_line;
8973 DrawTextSCentered(ystart2, font_info,
8974 "(Your controller may look different.)");
8975 ystart2 += ystep_para;
8977 #if defined(PLATFORM_ANDROID)
8978 DrawTextSCentered(ystart2, font_info,
8979 "To correct a mistake,");
8980 ystart2 += ystep_line;
8981 DrawTextSCentered(ystart2, font_info,
8982 "press the 'back' button.");
8983 ystart2 += ystep_line;
8984 DrawTextSCentered(ystart2, font_info,
8985 "To skip a button or axis,");
8986 ystart2 += ystep_line;
8987 DrawTextSCentered(ystart2, font_info,
8988 "press the 'menu' button.");
8990 DrawTextSCentered(ystart2, font_info,
8991 "To correct a mistake,");
8992 ystart2 += ystep_line;
8993 DrawTextSCentered(ystart2, font_info,
8994 "press the 'backspace' key.");
8995 ystart2 += ystep_line;
8996 DrawTextSCentered(ystart2, font_info,
8997 "To skip a button or axis,");
8998 ystart2 += ystep_line;
8999 DrawTextSCentered(ystart2, font_info,
9000 "press the 'return' key.");
9001 ystart2 += ystep_line;
9002 DrawTextSCentered(ystart2, font_info,
9003 "To exit, press the 'escape' key.");
9006 BlitBitmapMasked(controller, drawto, 0, 0,
9007 controller->width, controller->height,
9008 controller_x, controller_y);
9010 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
9011 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
9013 BlitBitmapMasked(marker, drawto, 0, 0,
9014 marker->width, marker->height,
9015 marker_x, marker_y);
9017 if (!screen_initialized)
9018 FadeIn(REDRAW_FIELD);
9022 screen_initialized = TRUE;
9024 while (NextValidEvent(&event))
9028 case SDL_JOYAXISMOTION:
9029 if (event.jaxis.value > 20000 ||
9030 event.jaxis.value < -20000)
9032 for (j = 0; j < i; j++)
9033 if (steps[j].axis == event.jaxis.axis)
9038 if (step->marker != MARKER_AXIS_X &&
9039 step->marker != MARKER_AXIS_Y)
9042 step->axis = event.jaxis.axis;
9043 strcat(mapping, step->field);
9044 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
9045 strcat(mapping, temp);
9053 case SDL_JOYHATMOTION:
9054 // ignore centering; we're probably just coming back
9055 // to the center from the previous item we set
9056 if (event.jhat.value == SDL_HAT_CENTERED)
9059 for (j = 0; j < i; j++)
9060 if (steps[j].hat == event.jhat.hat &&
9061 steps[j].hat_value == event.jhat.value)
9066 step->hat = event.jhat.hat;
9067 step->hat_value = event.jhat.value;
9068 strcat(mapping, step->field);
9069 snprintf(temp, sizeof(temp), ":h%u.%u,",
9070 event.jhat.hat, event.jhat.value );
9071 strcat(mapping, temp);
9078 case SDL_JOYBALLMOTION:
9081 case SDL_JOYBUTTONUP:
9082 for (j = 0; j < i; j++)
9083 if (steps[j].button == event.jbutton.button)
9088 step->button = event.jbutton.button;
9089 strcat(mapping, step->field);
9090 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9091 strcat(mapping, temp);
9098 case SDL_FINGERDOWN:
9099 case SDL_MOUSEBUTTONDOWN:
9107 if (event.key.keysym.sym == KSYM_BackSpace ||
9108 event.key.keysym.sym == KSYM_Back)
9120 prev_step = &steps[i - 1];
9121 strcpy(mapping, prev_step->mapping);
9128 if (event.key.keysym.sym == KSYM_space ||
9129 event.key.keysym.sym == KSYM_Return ||
9130 event.key.keysym.sym == KSYM_Menu)
9139 if (event.key.keysym.sym == KSYM_Escape)
9149 program.exit_function(0);
9156 // do not handle events for longer than standard frame delay period
9157 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9166 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9169 // activate mapping for this game
9170 SDL_GameControllerAddMapping(mapping);
9172 // save mapping to personal mappings
9173 SaveSetup_AddGameControllerMapping(mapping);
9176 // wait until the last pending event was removed from event queue
9177 while (NextValidEvent(&event));
9182 static int ConfigureJoystickMain(int player_nr)
9184 char *device_name = setup.input[player_nr].joy.device_name;
9185 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9186 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9187 int success = FALSE;
9190 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9191 return JOYSTICK_NOT_AVAILABLE;
9193 if (!joystick_active || !setup.input[player_nr].use_joystick)
9194 return JOYSTICK_NOT_AVAILABLE;
9197 FadeOut(REDRAW_FIELD);
9199 // close all joystick devices (potentially opened as game controllers)
9200 for (i = 0; i < SDL_NumJoysticks(); i++)
9201 SDLCloseJoystick(i);
9203 // open joystick device as plain joystick to configure as game controller
9204 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9206 // as the joystick was successfully opened before, this should not happen
9207 if (joystick == NULL)
9210 // create new game controller mapping (buttons and axes) for joystick device
9211 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9213 // close joystick (and maybe re-open as configured game controller later)
9214 SDL_JoystickClose(joystick);
9216 // re-open all joystick devices (potentially as game controllers)
9217 for (i = 0; i < SDL_NumJoysticks(); i++)
9220 // clear all joystick input actions for all joystick devices
9221 SDLClearJoystickState();
9223 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9226 void ConfigureJoystick(int player_nr)
9228 boolean state = ConfigureJoystickMain(player_nr);
9230 if (state != JOYSTICK_NOT_CONFIGURED)
9232 boolean success = (state == JOYSTICK_CONFIGURED);
9233 char message1[MAX_OUTPUT_LINESIZE + 1];
9234 char *message2 = (success ? "configured!" : "not available!");
9235 char *device_name = setup.input[player_nr].joy.device_name;
9236 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9237 int font_nr = FONT_TITLE_1;
9238 int font_height = getFontHeight(font_nr);
9239 int ypos1 = SYSIZE / 2 - font_height * 2;
9240 int ypos2 = SYSIZE / 2 - font_height * 1;
9241 unsigned int wait_frame_delay = 0;
9242 unsigned int wait_frame_delay_value = 2000;
9244 ResetDelayCounter(&wait_frame_delay);
9248 sprintf(message1, "Joystick %d", nr);
9250 DrawTextSCentered(ypos1, font_nr, message1);
9251 DrawTextSCentered(ypos2, font_nr, message2);
9253 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9259 DrawSetupScreen_Input();
9262 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9264 if (y < video.screen_height / 3)
9266 // remap touch gadgets to access upper part of the screen
9267 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9268 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9270 else if (y > 2 * video.screen_height / 3)
9272 // remap touch gadgets to access lower part of the screen
9273 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9274 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9278 static boolean ConfigureVirtualButtonsMain(void)
9280 static char *customize_step_text[] =
9289 char grid_button[] =
9291 CHAR_GRID_BUTTON_LEFT,
9292 CHAR_GRID_BUTTON_RIGHT,
9293 CHAR_GRID_BUTTON_UP,
9294 CHAR_GRID_BUTTON_DOWN,
9295 CHAR_GRID_BUTTON_SNAP,
9296 CHAR_GRID_BUTTON_DROP
9305 int font_nr = FONT_INPUT_1_ACTIVE;
9306 int font_height = getFontHeight(font_nr);
9307 int ypos1 = SYSIZE / 2 - font_height * 2;
9308 int ypos2 = SYSIZE / 2 - font_height * 1;
9309 boolean success = FALSE;
9310 boolean finished = FALSE;
9312 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9313 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9314 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9315 boolean set_grid_button = FALSE;
9316 int nr = GRID_ACTIVE_NR();
9319 for (x = 0; x < MAX_GRID_XSIZE; x++)
9320 for (y = 0; y < MAX_GRID_YSIZE; y++)
9321 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9323 overlay.grid_button_highlight = grid_button[step_nr];
9328 FadeOut(REDRAW_FIELD);
9332 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9333 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9334 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9336 FadeIn(REDRAW_FIELD);
9338 SetOverlayShowGrid(TRUE);
9340 // map gadgets for setup touch buttons menu screen
9341 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9347 while (NextValidEvent(&event))
9349 int action = ACTION_NONE;
9351 // ---------- handle events and set the resulting action ----------
9357 UserEvent *user = (UserEvent *)&event;
9358 int id = user->value1;
9360 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9361 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9362 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9363 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9368 case EVENT_KEYPRESS:
9370 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9372 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9373 key == KSYM_BackSpace ||
9374 key == KSYM_Back ? ACTION_BACK :
9375 key == KSYM_Return ||
9377 key == KSYM_space ? ACTION_NEXT :
9382 case EVENT_KEYRELEASE:
9383 key_joystick_mapping = 0;
9386 case EVENT_BUTTONPRESS:
9387 case EVENT_BUTTONRELEASE:
9389 ButtonEvent *button = (ButtonEvent *)&event;
9391 motion_status = FALSE;
9393 if (button->type == EVENT_BUTTONPRESS)
9394 button_status = button->button;
9396 button_status = MB_RELEASED;
9398 if (HandleGadgets(button->x, button->y, button_status))
9400 // do not handle this button event anymore
9404 button->x += video.screen_xoffset;
9405 button->y += video.screen_yoffset;
9407 x = button->x * overlay.grid_xsize / video.screen_width;
9408 y = button->y * overlay.grid_ysize / video.screen_height;
9410 if (button->type == EVENT_BUTTONPRESS)
9413 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9414 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9416 set_grid_button = TRUE;
9419 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9423 case EVENT_MOTIONNOTIFY:
9425 MotionEvent *motion = (MotionEvent *)&event;
9427 motion_status = TRUE;
9429 if (HandleGadgets(motion->x, motion->y, button_status))
9431 // do not handle this button event anymore
9435 motion->x += video.screen_xoffset;
9436 motion->y += video.screen_yoffset;
9438 x = motion->x * overlay.grid_xsize / video.screen_width;
9439 y = motion->y * overlay.grid_ysize / video.screen_height;
9441 set_grid_button = TRUE;
9443 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9447 case SDL_WINDOWEVENT:
9448 HandleWindowEvent((WindowEvent *) &event);
9450 // check if device has been rotated
9451 if (nr != GRID_ACTIVE_NR())
9453 nr = GRID_ACTIVE_NR();
9455 for (x = 0; x < MAX_GRID_XSIZE; x++)
9456 for (y = 0; y < MAX_GRID_YSIZE; y++)
9457 grid_button_old[x][y] = grid_button_tmp[x][y] =
9458 overlay.grid_button[x][y];
9463 case SDL_APP_WILLENTERBACKGROUND:
9464 case SDL_APP_DIDENTERBACKGROUND:
9465 case SDL_APP_WILLENTERFOREGROUND:
9466 case SDL_APP_DIDENTERFOREGROUND:
9467 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9471 HandleOtherEvents(&event);
9475 // ---------- perform action set by handling events ----------
9477 if (action == ACTION_ESCAPE)
9479 // abort and restore the old key bindings
9481 for (x = 0; x < MAX_GRID_XSIZE; x++)
9482 for (y = 0; y < MAX_GRID_YSIZE; y++)
9483 overlay.grid_button[x][y] = grid_button_old[x][y];
9485 FadeSkipNextFadeIn();
9489 else if (action == ACTION_BACK)
9491 // keep the configured key bindings and go to previous page
9497 FadeSkipNextFadeIn();
9502 else if (action == ACTION_NEXT)
9504 // keep the configured key bindings and go to next page
9508 // all virtual buttons configured
9516 if (action != ACTION_NONE && !finished)
9518 for (x = 0; x < MAX_GRID_XSIZE; x++)
9519 for (y = 0; y < MAX_GRID_YSIZE; y++)
9520 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9522 overlay.grid_button_highlight = grid_button[step_nr];
9524 // configure next virtual button
9528 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9529 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9530 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9533 if (set_grid_button)
9535 overlay.grid_button[x][y] =
9536 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9537 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9538 grid_button_tmp[x][y]);
9540 set_grid_button = FALSE;
9547 for (x = 0; x < MAX_GRID_XSIZE; x++)
9548 for (y = 0; y < MAX_GRID_YSIZE; y++)
9549 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9551 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9553 SetOverlayShowGrid(FALSE);
9558 void ConfigureVirtualButtons(void)
9560 boolean success = ConfigureVirtualButtonsMain();
9562 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9563 SCREEN_MASK_TOUCH2);
9567 int font_nr = FONT_TITLE_1;
9568 int font_height = getFontHeight(font_nr);
9569 int ypos1 = SYSIZE / 2 - font_height * 2;
9570 int ypos2 = SYSIZE / 2 - font_height * 1;
9571 unsigned int wait_frame_delay = 0;
9572 unsigned int wait_frame_delay_value = 2000;
9574 ResetDelayCounter(&wait_frame_delay);
9578 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9579 DrawTextSCentered(ypos2, font_nr, "configured!");
9581 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9588 void DrawSetupScreen(void)
9593 if (setup_mode == SETUP_MODE_INPUT)
9594 DrawSetupScreen_Input();
9595 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9596 DrawChooseTree(&scores_type_current);
9597 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9598 DrawChooseTree(&game_speed_current);
9599 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9600 DrawChooseTree(&scroll_delay_current);
9601 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9602 DrawChooseTree(&snapshot_mode_current);
9603 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9604 DrawChooseTree(&window_size_current);
9605 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9606 DrawChooseTree(&scaling_type_current);
9607 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9608 DrawChooseTree(&rendering_mode_current);
9609 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9610 DrawChooseTree(&vsync_mode_current);
9611 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9612 DrawChooseTree(&artwork.gfx_current);
9613 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9614 DrawChooseTree(&artwork.snd_current);
9615 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9616 DrawChooseTree(&artwork.mus_current);
9617 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9618 DrawChooseTree(&volume_simple_current);
9619 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9620 DrawChooseTree(&volume_loops_current);
9621 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9622 DrawChooseTree(&volume_music_current);
9623 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9624 DrawChooseTree(&touch_control_current);
9625 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9626 DrawChooseTree(&move_distance_current);
9627 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9628 DrawChooseTree(&drop_distance_current);
9629 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9630 DrawChooseTree(&transparency_current);
9631 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9632 DrawChooseTree(&grid_size_current[0][0]);
9633 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9634 DrawChooseTree(&grid_size_current[0][1]);
9635 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9636 DrawChooseTree(&grid_size_current[1][0]);
9637 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9638 DrawChooseTree(&grid_size_current[1][1]);
9640 DrawSetupScreen_Generic();
9642 PlayMenuSoundsAndMusic();
9645 void RedrawSetupScreenAfterFullscreenToggle(void)
9647 if (setup_mode == SETUP_MODE_GRAPHICS ||
9648 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9650 // update list selection from "setup.window_scaling_percent"
9651 execSetupGraphics_setWindowSizes(TRUE);
9657 void RedrawSetupScreenAfterScreenRotation(int nr)
9661 if (setup_mode == SETUP_MODE_TOUCH)
9663 // update virtual button settings (depending on screen orientation)
9666 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9668 // save already configured virtual buttons
9669 for (x = 0; x < MAX_GRID_XSIZE; x++)
9670 for (y = 0; y < MAX_GRID_YSIZE; y++)
9671 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9675 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9677 if (setup_mode == SETUP_MODE_INPUT)
9678 HandleSetupScreen_Input(mx, my, dx, dy, button);
9679 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9680 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9681 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9682 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9683 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9684 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9685 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9686 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9687 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9688 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9689 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9690 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9691 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9692 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9693 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9694 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9695 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9696 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9697 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9698 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9699 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9700 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9701 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9702 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9703 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9704 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9705 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9706 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9707 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9708 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9709 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9710 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9711 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9712 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9713 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9714 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9715 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9716 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9717 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9718 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9719 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9720 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9721 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9722 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9724 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9727 void HandleGameActions(void)
9729 if (setup.ask_on_game_over)
9732 if (game.restart_game_message != NULL)
9734 RequestRestartGame(game.restart_game_message);
9739 if (game_status != GAME_MODE_PLAYING)
9742 GameActions(); // main game loop
9744 if (tape.auto_play && !tape.playing)
9745 AutoPlayTapesContinue(); // continue automatically playing next tape
9749 // ---------- new screen button stuff --------------------------------------
9753 int gfx_unpressed, gfx_pressed;
9754 struct MenuPosInfo *pos;
9755 boolean *check_value;
9758 unsigned int event_mask;
9759 boolean is_touch_button;
9761 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9764 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9765 &menu.main.button.prev_level, NULL,
9766 SCREEN_CTRL_ID_PREV_LEVEL,
9768 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9769 FALSE, "previous level"
9772 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9773 &menu.main.button.next_level, NULL,
9774 SCREEN_CTRL_ID_NEXT_LEVEL,
9776 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9780 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9781 &menu.scores.button.prev_level, NULL,
9782 SCREEN_CTRL_ID_PREV_LEVEL2,
9783 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9784 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9785 FALSE, "previous level"
9788 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9789 &menu.scores.button.next_level, NULL,
9790 SCREEN_CTRL_ID_NEXT_LEVEL2,
9791 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9792 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9796 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9797 &menu.scores.button.prev_score, NULL,
9798 SCREEN_CTRL_ID_PREV_SCORE,
9799 SCREEN_MASK_SCORES_INFO,
9800 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9801 FALSE, "previous score"
9804 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9805 &menu.scores.button.next_score, NULL,
9806 SCREEN_CTRL_ID_NEXT_SCORE,
9807 SCREEN_MASK_SCORES_INFO,
9808 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9812 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9813 &menu.main.button.first_level, NULL,
9814 SCREEN_CTRL_ID_FIRST_LEVEL,
9817 FALSE, "first level"
9820 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9821 &menu.main.button.last_level, NULL,
9822 SCREEN_CTRL_ID_LAST_LEVEL,
9828 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9829 &menu.main.button.level_number, NULL,
9830 SCREEN_CTRL_ID_LEVEL_NUMBER,
9833 FALSE, "level number"
9836 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9837 &menu.setup.button.prev_player, NULL,
9838 SCREEN_CTRL_ID_PREV_PLAYER,
9840 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9841 FALSE, "previous player"
9844 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9845 &menu.setup.button.next_player, NULL,
9846 SCREEN_CTRL_ID_NEXT_PLAYER,
9848 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9849 FALSE, "next player"
9852 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9853 &menu.main.button.insert_solution, NULL,
9854 SCREEN_CTRL_ID_INSERT_SOLUTION,
9855 SCREEN_MASK_MAIN_HAS_SOLUTION,
9857 FALSE, "insert solution tape"
9860 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9861 &menu.main.button.play_solution, NULL,
9862 SCREEN_CTRL_ID_PLAY_SOLUTION,
9863 SCREEN_MASK_MAIN_HAS_SOLUTION,
9865 FALSE, "play solution tape"
9868 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9869 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9870 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9872 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9873 FALSE, "switch ECS/AGA chipset"
9876 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9877 &menu.setup.button.touch_back, NULL,
9878 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9881 TRUE, "previous page"
9884 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9885 &menu.setup.button.touch_next, NULL,
9886 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9892 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9893 &menu.setup.button.touch_back2, NULL,
9894 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9897 TRUE, "previous page"
9900 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9901 &menu.setup.button.touch_next2, NULL,
9902 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9911 int gfx_unpressed, gfx_pressed;
9915 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9918 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9919 -1, -1, // these values are not constant, but can change at runtime
9920 SCREEN_CTRL_ID_SCROLL_UP,
9924 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9925 -1, -1, // these values are not constant, but can change at runtime
9926 SCREEN_CTRL_ID_SCROLL_DOWN,
9933 int gfx_unpressed, gfx_pressed;
9939 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9942 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9943 -1, -1, // these values are not constant, but can change at runtime
9944 -1, -1, // these values are not constant, but can change at runtime
9945 GD_TYPE_SCROLLBAR_VERTICAL,
9946 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9947 "scroll level series vertically"
9959 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9962 IMG_SETUP_INPUT_TEXT,
9963 SCREEN_CTRL_ID_NETWORK_SERVER,
9964 -1, -1, // these values are not constant, but can change at runtime
9965 MAX_SETUP_TEXT_INPUT_LEN,
9966 network_server_hostname,
9967 "Network Server Hostname / IP"
9971 static void CreateScreenMenubuttons(void)
9973 struct GadgetInfo *gi;
9974 unsigned int event_mask;
9977 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9979 struct MenuPosInfo *pos = menubutton_info[i].pos;
9980 int screen_mask = menubutton_info[i].screen_mask;
9981 boolean is_touch_button = menubutton_info[i].is_touch_button;
9982 boolean is_check_button = menubutton_info[i].check_value != NULL;
9983 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9984 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9985 int gfx_unpressed, gfx_pressed;
9986 int x, y, width, height;
9987 int gd_x1, gd_x2, gd_y1, gd_y2;
9988 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9989 int id = menubutton_info[i].gadget_id;
9990 int type = GD_TYPE_NORMAL_BUTTON;
9991 boolean checked = FALSE;
9993 event_mask = menubutton_info[i].event_mask;
9995 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9996 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9998 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9999 height = graphic_info[menubutton_info[i].gfx_pressed].height;
10001 gfx_unpressed = menubutton_info[i].gfx_unpressed;
10002 gfx_pressed = menubutton_info[i].gfx_pressed;
10003 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10004 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10005 gd_x1 = graphic_info[gfx_unpressed].src_x;
10006 gd_y1 = graphic_info[gfx_unpressed].src_y;
10007 gd_x2 = graphic_info[gfx_pressed].src_x;
10008 gd_y2 = graphic_info[gfx_pressed].src_y;
10014 if (is_touch_button)
10016 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
10017 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
10020 if (is_check_button)
10022 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
10023 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
10024 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
10025 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
10027 type = GD_TYPE_CHECK_BUTTON;
10028 checked = *menubutton_info[i].check_value;
10031 if (is_score_button)
10033 // if x/y set to -1, dynamically place buttons next to title text
10034 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10037 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10038 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10039 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10040 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10043 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
10044 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
10047 gi = CreateGadget(GDI_CUSTOM_ID, id,
10048 GDI_CUSTOM_TYPE_ID, i,
10049 GDI_IMAGE_ID, gfx_unpressed,
10050 GDI_INFO_TEXT, menubutton_info[i].infotext,
10054 GDI_HEIGHT, height,
10056 GDI_STATE, GD_BUTTON_UNPRESSED,
10057 GDI_CHECKED, checked,
10058 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10059 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10060 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
10061 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
10062 GDI_DIRECT_DRAW, FALSE,
10063 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10064 GDI_EVENT_MASK, event_mask,
10065 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10069 Fail("cannot create gadget");
10071 screen_gadget[id] = gi;
10075 static void CreateScreenScrollbuttons(void)
10077 struct GadgetInfo *gi;
10078 unsigned int event_mask;
10081 // these values are not constant, but can change at runtime
10082 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10083 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10084 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10085 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10087 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10089 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10090 int gfx_unpressed, gfx_pressed;
10091 int x, y, width, height;
10092 int gd_x1, gd_x2, gd_y1, gd_y2;
10093 int id = scrollbutton_info[i].gadget_id;
10095 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10097 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10098 y = mSY + scrollbutton_info[i].y;
10099 width = SC_SCROLLBUTTON_XSIZE;
10100 height = SC_SCROLLBUTTON_YSIZE;
10102 // correct scrollbar position if placed outside menu (playfield) area
10103 if (x > SX + SC_SCROLL_UP_XPOS)
10104 x = SX + SC_SCROLL_UP_XPOS;
10106 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10107 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10108 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10110 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10111 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10112 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10113 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10114 gd_x1 = graphic_info[gfx_unpressed].src_x;
10115 gd_y1 = graphic_info[gfx_unpressed].src_y;
10116 gd_x2 = graphic_info[gfx_pressed].src_x;
10117 gd_y2 = graphic_info[gfx_pressed].src_y;
10119 gi = CreateGadget(GDI_CUSTOM_ID, id,
10120 GDI_CUSTOM_TYPE_ID, i,
10121 GDI_IMAGE_ID, gfx_unpressed,
10122 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10126 GDI_HEIGHT, height,
10127 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10128 GDI_STATE, GD_BUTTON_UNPRESSED,
10129 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10130 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10131 GDI_DIRECT_DRAW, FALSE,
10132 GDI_EVENT_MASK, event_mask,
10133 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10137 Fail("cannot create gadget");
10139 screen_gadget[id] = gi;
10143 static void CreateScreenScrollbars(void)
10147 // these values are not constant, but can change at runtime
10148 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10149 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10150 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10151 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10153 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10155 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10156 int gfx_unpressed, gfx_pressed;
10157 int x, y, width, height;
10158 int gd_x1, gd_x2, gd_y1, gd_y2;
10159 struct GadgetInfo *gi;
10160 int items_max, items_visible, item_position;
10161 unsigned int event_mask;
10162 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10163 int id = scrollbar_info[i].gadget_id;
10165 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10167 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10168 y = mSY + scrollbar_info[i].y;
10169 width = scrollbar_info[i].width;
10170 height = scrollbar_info[i].height;
10172 // correct scrollbar position if placed outside menu (playfield) area
10173 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10174 x = SX + SC_SCROLL_VERTICAL_XPOS;
10176 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10177 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10179 items_max = num_page_entries;
10180 items_visible = num_page_entries;
10183 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10184 gfx_pressed = scrollbar_info[i].gfx_pressed;
10185 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10186 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10187 gd_x1 = graphic_info[gfx_unpressed].src_x;
10188 gd_y1 = graphic_info[gfx_unpressed].src_y;
10189 gd_x2 = graphic_info[gfx_pressed].src_x;
10190 gd_y2 = graphic_info[gfx_pressed].src_y;
10192 gi = CreateGadget(GDI_CUSTOM_ID, id,
10193 GDI_CUSTOM_TYPE_ID, i,
10194 GDI_IMAGE_ID, gfx_unpressed,
10195 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10199 GDI_HEIGHT, height,
10200 GDI_TYPE, scrollbar_info[i].type,
10201 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10202 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10203 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10204 GDI_WHEEL_AREA_X, SX,
10205 GDI_WHEEL_AREA_Y, SY,
10206 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10207 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10208 GDI_STATE, GD_BUTTON_UNPRESSED,
10209 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10210 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10211 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10212 GDI_DIRECT_DRAW, FALSE,
10213 GDI_EVENT_MASK, event_mask,
10214 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10218 Fail("cannot create gadget");
10220 screen_gadget[id] = gi;
10224 static void CreateScreenTextInputGadgets(void)
10228 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10230 int graphic = textinput_info[i].graphic;
10231 struct GraphicInfo *gd = &graphic_info[graphic];
10232 int gd_x1 = gd->src_x;
10233 int gd_y1 = gd->src_y;
10234 int gd_x2 = gd->src_x + gd->active_xoffset;
10235 int gd_y2 = gd->src_y + gd->active_yoffset;
10236 struct GadgetInfo *gi;
10237 unsigned int event_mask;
10238 int id = textinput_info[i].gadget_id;
10239 int x = textinput_info[i].x;
10240 int y = textinput_info[i].y;
10242 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10244 gi = CreateGadget(GDI_CUSTOM_ID, id,
10245 GDI_CUSTOM_TYPE_ID, i,
10246 GDI_INFO_TEXT, textinput_info[i].infotext,
10249 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10250 GDI_TEXT_VALUE, textinput_info[i].value,
10251 GDI_TEXT_SIZE, textinput_info[i].size,
10252 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10253 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10254 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10255 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10256 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10257 GDI_DESIGN_WIDTH, gd->width,
10258 GDI_EVENT_MASK, event_mask,
10259 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10260 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10264 Fail("cannot create gadget");
10266 screen_gadget[id] = gi;
10270 void CreateScreenGadgets(void)
10272 CreateScreenMenubuttons();
10274 CreateScreenScrollbuttons();
10275 CreateScreenScrollbars();
10277 CreateScreenTextInputGadgets();
10280 void FreeScreenGadgets(void)
10284 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10285 FreeGadget(screen_gadget[i]);
10288 static void RedrawScreenMenuGadgets(int screen_mask)
10292 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10293 if (screen_mask & menubutton_info[i].screen_mask)
10294 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10297 static void MapScreenMenuGadgets(int screen_mask)
10301 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10302 if (screen_mask & menubutton_info[i].screen_mask)
10303 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10306 static void UnmapScreenMenuGadgets(int screen_mask)
10310 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10312 if (screen_mask & menubutton_info[i].screen_mask)
10314 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10316 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10317 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10318 screen_gadget[menubutton_info[i].gadget_id]->y,
10319 screen_gadget[menubutton_info[i].gadget_id]->width,
10320 screen_gadget[menubutton_info[i].gadget_id]->height);
10325 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10328 MapScreenMenuGadgets(screen_mask);
10330 UnmapScreenMenuGadgets(screen_mask);
10333 static void MapScreenGadgets(int num_entries)
10337 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10340 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10341 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10343 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10344 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10347 static void UnmapScreenGadgets()
10351 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10352 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10354 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10355 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10358 static void MapScreenTreeGadgets(TreeInfo *ti)
10360 MapScreenGadgets(numTreeInfoInGroup(ti));
10363 static void UnmapScreenTreeGadgets(void)
10365 UnmapScreenGadgets();
10368 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10370 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10371 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10372 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10373 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10375 if (pos_1->x == -1 && pos_1->y == -1)
10376 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10378 if (pos_2->x == -1 && pos_2->y == -1)
10379 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10382 static void HandleScreenGadgets(struct GadgetInfo *gi)
10384 int id = gi->custom_id;
10385 int button = gi->event.button;
10386 int step = (button == MB_LEFTBUTTON ? 1 :
10387 button == MB_MIDDLEBUTTON ? 5 :
10388 button == MB_RIGHTBUTTON ? 10 : 1);
10392 case SCREEN_CTRL_ID_PREV_LEVEL:
10393 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10396 case SCREEN_CTRL_ID_NEXT_LEVEL:
10397 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10400 case SCREEN_CTRL_ID_PREV_LEVEL2:
10401 HandleHallOfFame_SelectLevel(step, -1);
10404 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10405 HandleHallOfFame_SelectLevel(step, +1);
10408 case SCREEN_CTRL_ID_PREV_SCORE:
10409 HandleScoreInfo_SelectScore(step, -1);
10412 case SCREEN_CTRL_ID_NEXT_SCORE:
10413 HandleScoreInfo_SelectScore(step, +1);
10416 case SCREEN_CTRL_ID_FIRST_LEVEL:
10417 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10420 case SCREEN_CTRL_ID_LAST_LEVEL:
10421 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10424 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10425 CloseDoor(DOOR_CLOSE_2);
10426 SetGameStatus(GAME_MODE_LEVELNR);
10427 DrawChooseLevelNr();
10430 case SCREEN_CTRL_ID_PREV_PLAYER:
10431 HandleSetupScreen_Input_Player(step, -1);
10434 case SCREEN_CTRL_ID_NEXT_PLAYER:
10435 HandleSetupScreen_Input_Player(step, +1);
10438 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10439 InsertSolutionTape();
10442 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10443 PlaySolutionTape();
10446 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10447 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10451 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10452 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10453 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10454 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10455 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10458 case SCREEN_CTRL_ID_SCROLL_UP:
10459 if (game_status == GAME_MODE_NAMES)
10460 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10461 else if (game_status == GAME_MODE_LEVELS)
10462 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10463 else if (game_status == GAME_MODE_LEVELNR)
10464 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10465 else if (game_status == GAME_MODE_SETUP)
10466 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10467 else if (game_status == GAME_MODE_INFO)
10468 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10469 else if (game_status == GAME_MODE_SCORES)
10470 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10473 case SCREEN_CTRL_ID_SCROLL_DOWN:
10474 if (game_status == GAME_MODE_NAMES)
10475 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10476 else if (game_status == GAME_MODE_LEVELS)
10477 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10478 else if (game_status == GAME_MODE_LEVELNR)
10479 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10480 else if (game_status == GAME_MODE_SETUP)
10481 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10482 else if (game_status == GAME_MODE_INFO)
10483 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10484 else if (game_status == GAME_MODE_SCORES)
10485 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10488 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10489 if (game_status == GAME_MODE_NAMES)
10490 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10491 else if (game_status == GAME_MODE_LEVELS)
10492 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10493 else if (game_status == GAME_MODE_LEVELNR)
10494 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10495 else if (game_status == GAME_MODE_SETUP)
10496 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10497 else if (game_status == GAME_MODE_INFO)
10498 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10499 else if (game_status == GAME_MODE_SCORES)
10500 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10503 case SCREEN_CTRL_ID_NETWORK_SERVER:
10505 if (!strEqual(gi->textinput.value, ""))
10507 setString(&setup.network_server_hostname, gi->textinput.value);
10509 network.server_host = setup.network_server_hostname;
10513 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10515 network.server_host = NULL;
10518 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10519 network.server_host = NULL;
10521 execSetupGame_setNetworkServerText();
10533 void DumpScreenIdentifiers(void)
10537 Print("Active screen elements on current screen:\n");
10539 for (i = 0; main_controls[i].nr != -1; i++)
10541 struct MainControlInfo *mci = &main_controls[i];
10543 if (mci->button_graphic != -1)
10545 char *token = getTokenFromImageID(mci->button_graphic);
10547 Print("- '%s'\n", token);
10554 boolean DoScreenAction(int image_id)
10558 if (game_status != GAME_MODE_MAIN)
10561 for (i = 0; main_controls[i].nr != -1; i++)
10563 struct MainControlInfo *mci = &main_controls[i];
10564 struct MenuPosInfo *pos = mci->pos_button;
10566 if (mci->button_graphic == image_id)
10568 int x = mSX + pos->x;
10569 int y = mSY + pos->y;
10571 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10580 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10582 // get tree info node of newly added level or artwork set
10583 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10584 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10586 if (tree_node_new == NULL) // should not happen
10589 // if request dialog is active, do nothing
10590 if (game.request_active)
10593 if (game_status == GAME_MODE_MAIN &&
10594 tree_type == TREE_TYPE_LEVEL_DIR)
10596 // when adding new level set in main menu, select it as current level set
10598 // change current level set to newly added level set from zip file
10599 leveldir_current = tree_node_new;
10601 // change current level number to first level of newly added level set
10602 level_nr = leveldir_current->first_level;
10604 // redraw screen to reflect changed level set
10607 // save this level set and level number as last selected level set
10608 SaveLevelSetup_LastSeries();
10609 SaveLevelSetup_SeriesInfo();
10611 else if (game_status == GAME_MODE_LEVELS &&
10612 tree_type == TREE_TYPE_LEVEL_DIR)
10614 // when adding new level set in level set menu, set cursor and update screen
10616 leveldir_current = tree_node_new;
10618 DrawChooseTree(&leveldir_current);
10620 else if (game_status == GAME_MODE_SETUP)
10622 // when adding new artwork set in setup menu, set cursor and update screen
10624 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10625 tree_type == TREE_TYPE_GRAPHICS_DIR)
10627 artwork.gfx_current = tree_node_new;
10629 DrawChooseTree(&artwork.gfx_current);
10631 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10632 tree_type == TREE_TYPE_SOUNDS_DIR)
10634 artwork.snd_current = tree_node_new;
10636 DrawChooseTree(&artwork.snd_current);
10638 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10639 tree_type == TREE_TYPE_MUSIC_DIR)
10641 artwork.mus_current = tree_node_new;
10643 DrawChooseTree(&artwork.mus_current);
10648 static int UploadTapes(void)
10650 SetGameStatus(GAME_MODE_LOADING);
10652 FadeSetEnterScreen();
10653 FadeOut(REDRAW_ALL);
10655 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10657 FadeIn(REDRAW_ALL);
10659 DrawInitTextHead("Uploading tapes");
10661 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10662 global.autoplay_leveldir = "ALL";
10663 global.autoplay_all = TRUE;
10665 int num_tapes_uploaded = AutoPlayTapes();
10667 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10668 global.autoplay_leveldir = NULL;
10669 global.autoplay_all = FALSE;
10671 SetGameStatus(GAME_MODE_MAIN);
10675 return num_tapes_uploaded;
10678 static boolean OfferUploadTapes(void)
10680 if (!Request(setup.has_remaining_tapes ?
10681 "Upload missing tapes to the high score server now?" :
10682 "Upload all your tapes to the high score server now?", REQ_ASK))
10685 int num_tapes_uploaded = UploadTapes();
10688 if (num_tapes_uploaded < 0)
10690 num_tapes_uploaded = -num_tapes_uploaded - 1;
10692 if (num_tapes_uploaded == 0)
10693 sprintf(message, "Upload failed! No tapes uploaded!");
10694 else if (num_tapes_uploaded == 1)
10695 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10697 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10698 num_tapes_uploaded);
10700 Request(message, REQ_CONFIRM);
10702 // if uploading tapes failed, add tape upload entry to setup menu
10703 setup.provide_uploading_tapes = TRUE;
10704 setup.has_remaining_tapes = TRUE;
10706 SaveSetup_ServerSetup();
10711 if (num_tapes_uploaded == 0)
10712 sprintf(message, "No tapes uploaded!");
10713 else if (num_tapes_uploaded == 1)
10714 sprintf(message, "1 tape uploaded!");
10716 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10718 Request(message, REQ_CONFIRM);
10720 if (num_tapes_uploaded > 0)
10721 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10723 // after all tapes have been uploaded, remove entry from setup menu
10724 setup.provide_uploading_tapes = FALSE;
10725 setup.has_remaining_tapes = FALSE;
10727 SaveSetup_ServerSetup();
10732 static void CheckUploadTapes(void)
10734 if (!setup.ask_for_uploading_tapes)
10737 // after asking for uploading tapes, do not ask again
10738 setup.ask_for_uploading_tapes = FALSE;
10739 setup.ask_for_remaining_tapes = FALSE;
10741 if (directoryExists(getTapeDir(NULL)))
10743 boolean tapes_uploaded = OfferUploadTapes();
10745 if (!tapes_uploaded)
10747 Request(setup.has_remaining_tapes ?
10748 "You can upload missing tapes from the setup menu later!" :
10749 "You can upload your tapes from the setup menu later!",
10755 // if tapes directory does not exist yet, never offer uploading all tapes
10756 setup.provide_uploading_tapes = FALSE;
10759 SaveSetup_ServerSetup();
10762 static void UpgradePlayerUUID(void)
10764 ApiResetUUIDAsThread(getUUID());
10767 static void CheckUpgradePlayerUUID(void)
10769 if (setup.player_version > 1)
10772 UpgradePlayerUUID();
10775 void CheckApiServerTasks(void)
10777 // check if the player's UUID has to be upgraded
10778 CheckUpgradePlayerUUID();
10780 // check if there are any tapes to be uploaded
10781 CheckUploadTapes();