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 // for input setup functions
134 #define SETUPINPUT_SCREEN_POS_START 0
135 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
136 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
137 #define SETUPINPUT_SCREEN_POS_END 13
139 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
140 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
142 #define MAX_SETUP_TEXT_INPUT_LEN 28
144 // for various menu stuff
145 #define MENU_SCREEN_START_XPOS 1
146 #define MENU_SCREEN_START_YPOS 2
147 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
148 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
149 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
150 #define MENU_TITLE1_YPOS 8
151 #define MENU_TITLE2_YPOS 46
152 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
153 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
154 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
155 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
156 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
159 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
160 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
161 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
162 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
163 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
164 MENU_INFO_FONT_TITLE))
165 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
166 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
167 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
168 MENU_SCREEN_INFO_YSTART2 - \
170 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
171 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
172 MENU_SCREEN_INFO_YSTEP)
173 #define NUM_INFO_ELEMENTS_FROM_CONF \
174 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
175 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
176 MAX_MENU_ENTRIES_ON_SCREEN)
177 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
178 MAX_INFO_ELEMENTS_ON_SCREEN), \
179 NUM_INFO_ELEMENTS_FROM_CONF)
180 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
181 #define MAX_MENU_TEXT_LENGTH_BIG 13
182 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
184 // screen gadget identifiers
185 #define SCREEN_CTRL_ID_PREV_LEVEL 0
186 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
187 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
188 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
189 #define SCREEN_CTRL_ID_PREV_SCORE 4
190 #define SCREEN_CTRL_ID_NEXT_SCORE 5
191 #define SCREEN_CTRL_ID_FIRST_LEVEL 6
192 #define SCREEN_CTRL_ID_LAST_LEVEL 7
193 #define SCREEN_CTRL_ID_LEVEL_NUMBER 8
194 #define SCREEN_CTRL_ID_PREV_PLAYER 9
195 #define SCREEN_CTRL_ID_NEXT_PLAYER 10
196 #define SCREEN_CTRL_ID_INSERT_SOLUTION 11
197 #define SCREEN_CTRL_ID_PLAY_SOLUTION 12
198 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 13
199 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 14
200 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 15
201 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 16
202 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 17
204 #define NUM_SCREEN_MENUBUTTONS 18
206 #define SCREEN_CTRL_ID_SCROLL_UP 18
207 #define SCREEN_CTRL_ID_SCROLL_DOWN 19
208 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 20
209 #define SCREEN_CTRL_ID_NETWORK_SERVER 21
211 #define NUM_SCREEN_GADGETS 22
213 #define NUM_SCREEN_SCROLLBUTTONS 2
214 #define NUM_SCREEN_SCROLLBARS 1
215 #define NUM_SCREEN_TEXTINPUT 1
217 #define SCREEN_MASK_MAIN (1 << 0)
218 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
219 #define SCREEN_MASK_INPUT (1 << 2)
220 #define SCREEN_MASK_TOUCH (1 << 3)
221 #define SCREEN_MASK_TOUCH2 (1 << 4)
222 #define SCREEN_MASK_SCORES (1 << 5)
223 #define SCREEN_MASK_SCORES_INFO (1 << 6)
225 // graphic position and size values for buttons and scrollbars
226 #define SC_MENUBUTTON_XSIZE TILEX
227 #define SC_MENUBUTTON_YSIZE TILEY
229 #define SC_SCROLLBUTTON_XSIZE TILEX
230 #define SC_SCROLLBUTTON_YSIZE TILEY
232 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
234 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
235 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
236 SC_SCROLLBUTTON_YSIZE)
238 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
239 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
241 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
242 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
243 SC_SCROLLBUTTON_YSIZE)
245 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
246 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
247 SC_SCROLL_VERTICAL_YSIZE)
249 #define SC_BORDER_SIZE 14
252 // forward declarations of internal functions
253 static void HandleScreenGadgets(struct GadgetInfo *);
254 static void HandleSetupScreen_Generic(int, int, int, int, int);
255 static void HandleSetupScreen_Input(int, int, int, int, int);
256 static void CustomizeKeyboard(int);
257 static void ConfigureJoystick(int);
258 static void ConfigureVirtualButtons(void);
259 static void execSetupGame(void);
260 static void execSetupEngines(void);
261 static void execSetupGraphics(void);
262 static void execSetupSound(void);
263 static void execSetupTouch(void);
264 static void execSetupArtwork(void);
265 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
267 static void DrawChoosePlayerName(void);
268 static void DrawChooseLevelSet(void);
269 static void DrawChooseLevelNr(void);
270 static void DrawScoreInfo(int);
271 static void DrawScoreInfo_Content(int);
272 static void DrawInfoScreen(void);
273 static void DrawSetupScreen(void);
274 static void DrawTypeName(void);
276 static void DrawInfoScreen_NotAvailable(char *, char *);
277 static void DrawInfoScreen_HelpAnim(int, int, boolean);
278 static void DrawInfoScreen_HelpText(int, int, int, int);
279 static void HandleInfoScreen_Main(int, int, int, int, int);
280 static void HandleInfoScreen_TitleScreen(int, int, int);
281 static void HandleInfoScreen_Elements(int, int, int);
282 static void HandleInfoScreen_Music(int, int, int);
283 static void HandleInfoScreen_Credits(int, int, int);
284 static void HandleInfoScreen_Program(int);
285 static void HandleInfoScreen_Version(int);
287 static void ModifyGameSpeedIfNeeded(void);
288 static void DisableVsyncIfNeeded(void);
290 static void RedrawScreenMenuGadgets(int);
291 static void MapScreenMenuGadgets(int);
292 static void UnmapScreenMenuGadgets(int);
293 static void MapScreenGadgets(int);
294 static void UnmapScreenGadgets(void);
295 static void MapScreenTreeGadgets(TreeInfo *);
296 static void UnmapScreenTreeGadgets(void);
298 static void UpdateScreenMenuGadgets(int, boolean);
299 static void AdjustScoreInfoButtons(int, int, int);
301 static boolean OfferUploadTapes(void);
302 static void execOfferUploadTapes(void);
304 static void DrawHallOfFame_setScoreEntries(void);
305 static void HandleHallOfFame_SelectLevel(int, int);
306 static char *getHallOfFameRankText(int, int);
307 static char *getHallOfFameScoreText(int, int);
309 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
311 static int info_mode = INFO_MODE_MAIN;
312 static int setup_mode = SETUP_MODE_MAIN;
314 static TreeInfo *window_sizes = NULL;
315 static TreeInfo *window_size_current = NULL;
317 static TreeInfo *scaling_types = NULL;
318 static TreeInfo *scaling_type_current = NULL;
320 static TreeInfo *rendering_modes = NULL;
321 static TreeInfo *rendering_mode_current = NULL;
323 static TreeInfo *vsync_modes = NULL;
324 static TreeInfo *vsync_mode_current = NULL;
326 static TreeInfo *scroll_delays = NULL;
327 static TreeInfo *scroll_delay_current = NULL;
329 static TreeInfo *snapshot_modes = NULL;
330 static TreeInfo *snapshot_mode_current = NULL;
332 static TreeInfo *scores_types = NULL;
333 static TreeInfo *scores_type_current = NULL;
335 static TreeInfo *game_speeds_normal = NULL;
336 static TreeInfo *game_speeds_extended = NULL;
337 static TreeInfo *game_speeds = NULL;
338 static TreeInfo *game_speed_current = NULL;
340 static TreeInfo *volumes_simple = NULL;
341 static TreeInfo *volume_simple_current = NULL;
343 static TreeInfo *volumes_loops = NULL;
344 static TreeInfo *volume_loops_current = NULL;
346 static TreeInfo *volumes_music = NULL;
347 static TreeInfo *volume_music_current = NULL;
349 static TreeInfo *touch_controls = NULL;
350 static TreeInfo *touch_control_current = NULL;
352 static TreeInfo *move_distances = NULL;
353 static TreeInfo *move_distance_current = NULL;
355 static TreeInfo *drop_distances = NULL;
356 static TreeInfo *drop_distance_current = NULL;
358 static TreeInfo *transparencies = NULL;
359 static TreeInfo *transparency_current = NULL;
361 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
362 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
364 static TreeInfo *player_name = NULL;
365 static TreeInfo *player_name_current = NULL;
367 static TreeInfo *level_number = NULL;
368 static TreeInfo *level_number_current = NULL;
370 static TreeInfo *score_entries = NULL;
371 static TreeInfo *score_entry_current = NULL;
373 static struct ValueTextInfo window_sizes_list[] =
378 { 100, "100 % (Default)" },
391 static struct StringValueTextInfo scaling_types_list[] =
393 { SCALING_QUALITY_NEAREST, "Off" },
394 { SCALING_QUALITY_LINEAR, "Linear" },
395 { SCALING_QUALITY_BEST, "Anisotropic" },
400 static struct StringValueTextInfo rendering_modes_list[] =
402 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
403 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
405 // this mode may work under certain conditions, but does not work on Windows
406 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
408 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
413 static struct StringValueTextInfo vsync_modes_list[] =
415 { STR_VSYNC_MODE_OFF, "Off" },
416 { STR_VSYNC_MODE_NORMAL, "Normal" },
417 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
422 static struct StringValueTextInfo scores_types_list[] =
424 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
425 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
426 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
431 static struct ValueTextInfo game_speeds_list_normal[] =
442 static struct ValueTextInfo game_speeds_list_extended[] =
444 { 1000, "1 fps (Extremely Slow)" },
449 { 29, "35 fps (Original Supaplex)" },
451 { 20, "50 fps (=== Normal Speed ===)" },
452 { 16, "60 fps (60 Hz VSync Speed)" },
453 { 14, "70 fps (Maximum Supaplex)" },
457 { 1, "1000 fps (Extremely Fast)" },
462 static struct ValueTextInfo *game_speeds_list;
464 static struct ValueTextInfo scroll_delays_list[] =
466 { 0, "0 Tiles (No Scroll Delay)" },
469 { 3, "3 Tiles (Default)" },
474 { 8, "8 Tiles (Maximum Scroll Delay)"},
479 static struct StringValueTextInfo snapshot_modes_list[] =
481 { STR_SNAPSHOT_MODE_OFF, "Off" },
482 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
483 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
484 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
489 static struct ValueTextInfo volumes_list[] =
509 static struct StringValueTextInfo touch_controls_list[] =
511 { TOUCH_CONTROL_OFF, "Off" },
512 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
513 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
514 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
519 static struct ValueTextInfo distances_list[] =
534 static struct ValueTextInfo transparencies_list[] =
536 { 0, "0 % (Opaque)" },
546 { 100, "100 % (Invisible)" },
551 static struct ValueTextInfo grid_sizes_list[] =
587 static int align_xoffset = 0;
588 static int align_yoffset = 0;
590 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
591 (s) <= GAME_MODE_SETUP ? (s) : \
592 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
594 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
595 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
597 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
598 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
599 (i) <= INFO_MODE_LEVELSET ? (i) : \
602 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
603 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
604 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
605 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
606 SETUP_MODE_CHOOSE_ARTWORK : \
607 SETUP_MODE_CHOOSE_OTHER)
609 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
610 menu.draw_xoffset[GAME_MODE_INFO] : \
611 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
612 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
613 menu.draw_yoffset[GAME_MODE_INFO] : \
614 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
615 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
616 menu.extra_spacing[GAME_MODE_INFO] : \
617 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
619 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
620 menu.draw_xoffset[GAME_MODE_SETUP] : \
621 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
622 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
623 menu.draw_yoffset[GAME_MODE_SETUP] : \
624 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
625 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
626 menu.extra_spacing[GAME_MODE_SETUP] : \
627 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
629 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
631 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
633 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
634 DRAW_XOFFSET_INFO(info_mode) : \
635 (s) == GAME_MODE_SETUP ? \
636 DRAW_XOFFSET_SETUP(setup_mode) : \
637 menu.draw_xoffset[DRAW_MODE(s)])
638 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
639 DRAW_YOFFSET_INFO(info_mode) : \
640 (s) == GAME_MODE_SETUP ? \
641 DRAW_YOFFSET_SETUP(setup_mode) : \
642 menu.draw_yoffset[DRAW_MODE(s)])
643 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
644 EXTRA_SPACING_INFO(info_mode) : \
645 (s) == GAME_MODE_SETUP ? \
646 EXTRA_SPACING_SETUP(setup_mode) : \
647 (s) == GAME_MODE_SCORES ? \
648 EXTRA_SPACING_SCORES(info_mode) : \
649 menu.extra_spacing[DRAW_MODE(s)])
651 #define mSX (SX + DRAW_XOFFSET(game_status))
652 #define mSY (SY + DRAW_YOFFSET(game_status))
654 #define amSX (mSX + align_xoffset)
655 #define amSY (mSY + align_yoffset)
657 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
658 menu.list_size[game_status] : \
659 MAX_MENU_ENTRIES_ON_SCREEN)
661 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
662 NUM_MENU_ENTRIES_ON_SCREEN)
665 // title display and control definitions
667 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
668 2 * MAX_NUM_TITLE_MESSAGES)
670 #define NO_DIRECT_LEVEL_SELECT (-1)
673 static int num_title_screens = 0;
675 struct TitleControlInfo
684 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
687 // credits screens definitions
689 static int num_credits_screens = 0;
690 static boolean use_global_credits_screens = FALSE;
693 // main menu display and control definitions
695 #define MAIN_CONTROL_NAME 0
696 #define MAIN_CONTROL_LEVELS 1
697 #define MAIN_CONTROL_SCORES 2
698 #define MAIN_CONTROL_EDITOR 3
699 #define MAIN_CONTROL_INFO 4
700 #define MAIN_CONTROL_GAME 5
701 #define MAIN_CONTROL_SETUP 6
702 #define MAIN_CONTROL_QUIT 7
703 #define MAIN_CONTROL_PREV_LEVEL 8
704 #define MAIN_CONTROL_NEXT_LEVEL 9
705 #define MAIN_CONTROL_FIRST_LEVEL 10
706 #define MAIN_CONTROL_LAST_LEVEL 11
707 #define MAIN_CONTROL_LEVEL_NUMBER 12
708 #define MAIN_CONTROL_LEVEL_INFO_1 13
709 #define MAIN_CONTROL_LEVEL_INFO_2 14
710 #define MAIN_CONTROL_LEVEL_NAME 15
711 #define MAIN_CONTROL_LEVEL_AUTHOR 16
712 #define MAIN_CONTROL_LEVEL_YEAR 17
713 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
714 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
715 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
716 #define MAIN_CONTROL_TITLE_1 21
717 #define MAIN_CONTROL_TITLE_2 22
718 #define MAIN_CONTROL_TITLE_3 23
720 static char str_main_text_name[10];
721 static char str_main_text_first_level[10];
722 static char str_main_text_last_level[10];
723 static char str_main_text_level_number[10];
725 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
727 static char *main_text_name = str_main_text_name;
728 static char *main_text_first_level = str_main_text_first_level;
729 static char *main_text_last_level = str_main_text_last_level;
730 static char *main_text_level_number = str_main_text_level_number;
731 static char *main_text_levels = "Levelset";
732 static char *main_text_scores = "Hall Of Fame";
733 static char *main_text_editor = "Level Creator";
734 static char *main_text_info = "Info Screen";
735 static char *main_text_game = "Start Game";
736 static char *main_text_setup = "Setup";
737 static char *main_text_quit = "Quit";
738 static char *main_text_level_name = level.name;
739 static char *main_text_level_author = level.author;
740 static char *main_text_level_year = NULL;
741 static char *main_text_level_imported_from = NULL;
742 static char *main_text_level_imported_by = NULL;
743 static char *main_text_level_tested_by = NULL;
744 static char *main_text_title_1 = NULL;
745 static char *main_text_title_2 = NULL;
746 static char *main_text_title_3 = NULL;
748 extern char debug_xsn_mode[];
750 struct MainControlInfo
754 struct MenuPosInfo *pos_button;
757 struct TextPosInfo *pos_text;
760 struct TextPosInfo *pos_input;
764 static struct MainControlInfo main_controls[] =
768 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
769 &menu.main.text.name, &main_text_name,
770 &menu.main.input.name, &setup.player_name,
774 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
775 &menu.main.text.levels, &main_text_levels,
780 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
781 &menu.main.text.scores, &main_text_scores,
786 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
787 &menu.main.text.editor, &main_text_editor,
792 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
793 &menu.main.text.info, &main_text_info,
798 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
799 &menu.main.text.game, &main_text_game,
804 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
805 &menu.main.text.setup, &main_text_setup,
810 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
811 &menu.main.text.quit, &main_text_quit,
815 MAIN_CONTROL_PREV_LEVEL,
821 MAIN_CONTROL_NEXT_LEVEL,
827 MAIN_CONTROL_FIRST_LEVEL,
829 &menu.main.text.first_level, &main_text_first_level,
833 MAIN_CONTROL_LAST_LEVEL,
835 &menu.main.text.last_level, &main_text_last_level,
839 MAIN_CONTROL_LEVEL_NUMBER,
841 &menu.main.text.level_number, &main_text_level_number,
845 MAIN_CONTROL_LEVEL_INFO_1,
847 &menu.main.text.level_info_1, NULL,
851 MAIN_CONTROL_LEVEL_INFO_2,
853 &menu.main.text.level_info_2, NULL,
857 MAIN_CONTROL_LEVEL_NAME,
859 &menu.main.text.level_name, &main_text_level_name,
863 MAIN_CONTROL_LEVEL_AUTHOR,
865 &menu.main.text.level_author, &main_text_level_author,
869 MAIN_CONTROL_LEVEL_YEAR,
871 &menu.main.text.level_year, &main_text_level_year,
875 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
877 &menu.main.text.level_imported_from, &main_text_level_imported_from,
881 MAIN_CONTROL_LEVEL_IMPORTED_BY,
883 &menu.main.text.level_imported_by, &main_text_level_imported_by,
887 MAIN_CONTROL_LEVEL_TESTED_BY,
889 &menu.main.text.level_tested_by, &main_text_level_tested_by,
893 MAIN_CONTROL_TITLE_1,
895 &menu.main.text.title_1, &main_text_title_1,
899 MAIN_CONTROL_TITLE_2,
901 &menu.main.text.title_2, &main_text_title_2,
905 MAIN_CONTROL_TITLE_3,
907 &menu.main.text.title_3, &main_text_title_3,
920 static int getTitleScreenGraphic(int nr, boolean initial)
922 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
925 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
927 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
931 static int getTitleScreenGameMode(boolean initial)
933 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
937 static int getTitleMessageGameMode(boolean initial)
939 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
942 static int getTitleAnimMode(struct TitleControlInfo *tci)
944 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
946 return base + tci->local_nr;
950 static int getTitleScreenBackground(boolean initial)
952 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
957 static int getTitleMessageBackground(int nr, boolean initial)
959 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
963 static int getTitleBackground(int nr, boolean initial, boolean is_image)
965 int base = (is_image ?
966 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
967 IMG_BACKGROUND_TITLESCREEN_1) :
968 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
969 IMG_BACKGROUND_TITLEMESSAGE_1));
970 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
971 IMG_BACKGROUND_TITLE);
972 int graphic_local = base + nr;
974 if (graphic_info[graphic_local].bitmap != NULL)
975 return graphic_local;
977 if (graphic_info[graphic_global].bitmap != NULL)
978 return graphic_global;
980 return IMG_UNDEFINED;
983 static int getTitleSound(struct TitleControlInfo *tci)
985 boolean is_image = tci->is_image;
986 int initial = tci->initial;
987 int nr = tci->local_nr;
988 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
989 int base = (is_image ?
990 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
991 SND_BACKGROUND_TITLESCREEN_1) :
992 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
993 SND_BACKGROUND_TITLEMESSAGE_1));
994 int sound_global = menu.sound[mode];
995 int sound_local = base + nr;
998 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
999 nr, initial, is_image,
1000 sound_global, getSoundListEntry(sound_global)->filename,
1001 sound_local, getSoundListEntry(sound_local)->filename);
1004 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1007 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1008 return sound_global;
1010 return SND_UNDEFINED;
1013 static int getTitleMusic(struct TitleControlInfo *tci)
1015 boolean is_image = tci->is_image;
1016 int initial = tci->initial;
1017 int nr = tci->local_nr;
1018 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1019 int base = (is_image ?
1020 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1021 MUS_BACKGROUND_TITLESCREEN_1) :
1022 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1023 MUS_BACKGROUND_TITLEMESSAGE_1));
1024 int music_global = menu.music[mode];
1025 int music_local = base + nr;
1028 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1029 nr, initial, is_image,
1030 music_global, getMusicListEntry(music_global)->filename,
1031 music_local, getMusicListEntry(music_local)->filename);
1034 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1037 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1038 return music_global;
1040 return MUS_UNDEFINED;
1043 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1045 boolean is_image = tci->is_image;
1046 boolean initial = tci->initial;
1047 boolean first = tci->first;
1048 int nr = tci->local_nr;
1049 struct TitleMessageInfo tmi;
1050 struct TitleFadingInfo ti;
1052 tmi = (is_image ? (initial ? (first ?
1053 titlescreen_initial_first[nr] :
1054 titlescreen_initial[nr])
1056 titlescreen_first[nr] :
1058 : (initial ? (first ?
1059 titlemessage_initial_first[nr] :
1060 titlemessage_initial[nr])
1062 titlemessage_first[nr] :
1063 titlemessage[nr])));
1065 ti.fade_mode = tmi.fade_mode;
1066 ti.fade_delay = tmi.fade_delay;
1067 ti.post_delay = tmi.post_delay;
1068 ti.auto_delay = tmi.auto_delay;
1069 ti.auto_delay_unit = tmi.auto_delay_unit;
1074 static int compareTitleControlInfo(const void *object1, const void *object2)
1076 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1077 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1080 if (tci1->initial != tci2->initial)
1081 compare_result = (tci1->initial ? -1 : +1);
1082 else if (tci1->sort_priority != tci2->sort_priority)
1083 compare_result = tci1->sort_priority - tci2->sort_priority;
1084 else if (tci1->is_image != tci2->is_image)
1085 compare_result = (tci1->is_image ? -1 : +1);
1087 compare_result = tci1->local_nr - tci2->local_nr;
1089 return compare_result;
1092 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1094 int nr, int sort_priority)
1096 title_controls[num_title_screens].is_image = is_image;
1097 title_controls[num_title_screens].initial = initial;
1098 title_controls[num_title_screens].local_nr = nr;
1099 title_controls[num_title_screens].sort_priority = sort_priority;
1101 title_controls[num_title_screens].first = FALSE; // will be set later
1103 num_title_screens++;
1106 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1110 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1112 int graphic = getTitleScreenGraphic(i, initial);
1113 Bitmap *bitmap = graphic_info[graphic].bitmap;
1114 int sort_priority = graphic_info[graphic].sort_priority;
1117 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1120 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1122 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1123 char *filename = getLevelSetTitleMessageFilename(i, initial);
1124 int sort_priority = tmi->sort_priority;
1126 if (filename != NULL)
1127 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1131 static void InitializeTitleControls(boolean show_title_initial)
1133 num_title_screens = 0;
1135 // 1st step: initialize title screens for game start (only when starting)
1136 if (show_title_initial)
1137 InitializeTitleControls_CheckTitleInfo(TRUE);
1139 // 2nd step: initialize title screens for current level set
1140 InitializeTitleControls_CheckTitleInfo(FALSE);
1142 // sort title screens according to sort_priority and title number
1143 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1144 compareTitleControlInfo);
1146 // mark first title screen
1147 title_controls[0].first = TRUE;
1150 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1152 return (pos != NULL && pos->x != -1 && pos->y != -1);
1155 static boolean visibleTextPos(struct TextPosInfo *pos)
1157 return (pos != NULL && pos->x != -1 && pos->y != -1);
1160 static void InitializeMainControls(void)
1162 boolean local_team_mode = (!network.enabled && setup.team_mode);
1165 // set main control text values to dynamically determined values
1166 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1168 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1169 menu.main.text.first_level.size));
1170 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1171 menu.main.text.last_level.size));
1172 strcpy(main_text_level_number, int2str(level_nr,
1173 menu.main.text.level_number.size));
1175 main_text_level_year = leveldir_current->year;
1176 main_text_level_imported_from = leveldir_current->imported_from;
1177 main_text_level_imported_by = leveldir_current->imported_by;
1178 main_text_level_tested_by = leveldir_current->tested_by;
1180 main_text_title_1 = getConfigProgramTitleString();
1181 main_text_title_2 = getConfigProgramCopyrightString();
1182 main_text_title_3 = getConfigProgramCompanyString();
1184 // set main control screen positions to dynamically determined values
1185 for (i = 0; main_controls[i].nr != -1; i++)
1187 struct MainControlInfo *mci = &main_controls[i];
1189 struct MenuPosInfo *pos_button = mci->pos_button;
1190 struct TextPosInfo *pos_text = mci->pos_text;
1191 struct TextPosInfo *pos_input = mci->pos_input;
1192 char *text = (mci->text ? *mci->text : NULL);
1193 char *input = (mci->input ? *mci->input : NULL);
1194 int button_graphic = mci->button_graphic;
1195 int font_text = (pos_text ? pos_text->font : -1);
1196 int font_input = (pos_input ? pos_input->font : -1);
1198 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1199 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1200 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1201 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1202 int text_chars = (text != NULL ? strlen(text) : 0);
1203 int input_chars = (input != NULL ? strlen(input) : 0);
1206 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1208 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1209 int text_width = font_text_width * text_chars;
1210 int text_height = font_text_height;
1211 int input_width = font_input_width * input_chars;
1212 int input_height = font_input_height;
1214 if (nr == MAIN_CONTROL_NAME)
1216 menu.main.input.name.width = input_width;
1217 menu.main.input.name.height = input_height;
1220 if (pos_button != NULL) // (x/y may be -1/-1 here)
1222 pos_button->width = button_width;
1223 pos_button->height = button_height;
1226 if (pos_text != NULL) // (x/y may be -1/-1 here)
1228 // calculate text size -- needed for text alignment
1229 boolean calculate_text_size = (text != NULL);
1231 if (pos_text->width == -1 || calculate_text_size)
1232 pos_text->width = text_width;
1233 if (pos_text->height == -1 || calculate_text_size)
1234 pos_text->height = text_height;
1236 if (visibleMenuPos(pos_button))
1238 if (pos_text->x == -1)
1239 pos_text->x = pos_button->x + pos_button->width;
1240 if (pos_text->y == -1)
1242 pos_button->y + (pos_button->height - pos_text->height) / 2;
1246 if (pos_input != NULL) // (x/y may be -1/-1 here)
1248 if (visibleTextPos(pos_text))
1250 if (pos_input->x == -1)
1251 pos_input->x = pos_text->x + pos_text->width;
1252 if (pos_input->y == -1)
1253 pos_input->y = pos_text->y;
1256 if (pos_input->width == -1)
1257 pos_input->width = input_width;
1258 if (pos_input->height == -1)
1259 pos_input->height = input_height;
1264 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1265 int graphic, boolean pressed)
1267 struct GraphicInfo *g = &graphic_info[graphic];
1270 int xoffset = (pressed ? g->pressed_xoffset : 0);
1271 int yoffset = (pressed ? g->pressed_yoffset : 0);
1273 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1275 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1276 g->width, g->height, dst_x, dst_y);
1279 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1280 boolean active_input,
1281 boolean pressed_button)
1285 for (i = 0; main_controls[i].nr != -1; i++)
1287 struct MainControlInfo *mci = &main_controls[i];
1289 if (mci->nr == nr || nr == -1)
1291 struct MenuPosInfo *pos_button = mci->pos_button;
1292 struct TextPosInfo *pos_text = mci->pos_text;
1293 struct TextPosInfo *pos_input = mci->pos_input;
1294 char *text = (mci->text ? *mci->text : NULL);
1295 char *input = (mci->input ? *mci->input : NULL);
1296 int button_graphic = mci->button_graphic;
1297 int font_text = (pos_text ? pos_text->font : -1);
1298 int font_input = (pos_input ? pos_input->font : -1);
1302 button_graphic = BUTTON_ACTIVE(button_graphic);
1303 font_text = FONT_ACTIVE(font_text);
1308 font_input = FONT_ACTIVE(font_input);
1311 if (visibleMenuPos(pos_button))
1313 struct MenuPosInfo *pos = pos_button;
1314 int x = mSX + pos->x;
1315 int y = mSY + pos->y;
1317 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1318 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1321 if (visibleTextPos(pos_text) && text != NULL)
1323 struct TextPosInfo *pos = pos_text;
1324 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1325 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1328 // (check why/if this is needed)
1329 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1331 DrawText(x, y, text, font_text);
1334 if (visibleTextPos(pos_input) && input != NULL)
1336 struct TextPosInfo *pos = pos_input;
1337 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1338 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1341 // (check why/if this is needed)
1342 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1344 DrawText(x, y, input, font_input);
1350 static void DrawCursorAndText_Main(int nr, boolean active_text,
1351 boolean pressed_button)
1353 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1357 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1358 boolean pressed_button)
1360 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1364 static struct MainControlInfo *getMainControlInfo(int nr)
1368 for (i = 0; main_controls[i].nr != -1; i++)
1369 if (main_controls[i].nr == nr)
1370 return &main_controls[i];
1375 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1380 int rect_x = ALIGNED_TEXT_XPOS(rect);
1381 int rect_y = ALIGNED_TEXT_YPOS(rect);
1383 return (x >= rect_x && x < rect_x + rect->width &&
1384 y >= rect_y && y < rect_y + rect->height);
1387 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1392 int rect_x = ALIGNED_TEXT_XPOS(rect);
1393 int rect_y = ALIGNED_TEXT_YPOS(rect);
1396 Debug("screens:insideTextPosRect",
1397 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1398 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1399 (x >= rect_x && x < rect_x + rect->width &&
1400 y >= rect_y && y < rect_y + rect->height));
1403 return (x >= rect_x && x < rect_x + rect->width &&
1404 y >= rect_y && y < rect_y + rect->height);
1407 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1409 int rect_width = preview->xsize * preview->tile_size;
1410 int rect_height = preview->ysize * preview->tile_size;
1411 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1412 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1414 return (x >= rect_x && x < rect_x + rect_width &&
1415 y >= rect_y && y < rect_y + rect_height);
1418 static void AdjustScrollbar(int id, int items_max, int items_visible,
1421 struct GadgetInfo *gi = screen_gadget[id];
1423 if (item_position > items_max - items_visible)
1424 item_position = items_max - items_visible;
1426 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1427 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1428 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1431 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1433 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1437 static void clearMenuListArea(void)
1439 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1441 // correct scrollbar position if placed outside menu (playfield) area
1442 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1443 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1445 // clear menu list area, but not title or scrollbar
1446 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1447 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1450 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1452 static int cursor_array[MAX_LEV_FIELDY];
1453 int x = amSX + TILEX * xpos;
1454 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1459 cursor_array[ypos] = graphic;
1461 graphic = cursor_array[ypos];
1465 graphic = BUTTON_ACTIVE(graphic);
1467 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1468 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1471 static void initCursor(int ypos, int graphic)
1473 drawCursorExt(0, ypos, FALSE, graphic);
1476 static void drawCursor(int ypos, boolean active)
1478 drawCursorExt(0, ypos, active, -1);
1481 static void drawCursorXY(int xpos, int ypos, int graphic)
1483 drawCursorExt(xpos, ypos, FALSE, graphic);
1486 static void drawChooseTreeCursor(int ypos, boolean active)
1488 drawCursorExt(0, ypos, active, -1);
1491 static int getChooseTreeEditFont(boolean active)
1493 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1496 static int getChooseTreeEditXPos(int pos)
1498 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1499 int xoffset = (has_scrollbar ? -1 : 0);
1500 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1501 int sx = amSX + xpos * TILEX;
1502 int font_nr = getChooseTreeEditFont(FALSE);
1503 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1505 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1508 static int getChooseTreeEditYPos(int ypos_raw)
1510 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1511 int sy = amSY + ypos * TILEY;
1516 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1518 int sx = getChooseTreeEditXPos(POS_LEFT);
1519 int sy = getChooseTreeEditYPos(ypos_raw);
1520 int font_nr = getChooseTreeEditFont(active);
1522 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1525 static void DrawHeadline(void)
1527 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1528 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1531 static void DrawTitleScreenImage(int nr, boolean initial)
1533 int graphic = getTitleScreenGraphic(nr, initial);
1534 Bitmap *bitmap = graphic_info[graphic].bitmap;
1535 int width = graphic_info[graphic].width;
1536 int height = graphic_info[graphic].height;
1537 int src_x = graphic_info[graphic].src_x;
1538 int src_y = graphic_info[graphic].src_y;
1544 if (width > WIN_XSIZE)
1546 // image width too large for window => center image horizontally
1547 src_x = (width - WIN_XSIZE) / 2;
1551 if (height > WIN_YSIZE)
1553 // image height too large for window => center image vertically
1554 src_y = (height - WIN_YSIZE) / 2;
1558 // always display title screens centered
1559 dst_x = (WIN_XSIZE - width) / 2;
1560 dst_y = (WIN_YSIZE - height) / 2;
1562 SetDrawBackgroundMask(REDRAW_ALL);
1563 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1565 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1567 if (DrawingOnBackground(dst_x, dst_y))
1568 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1570 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1572 redraw_mask = REDRAW_ALL;
1575 static void DrawTitleScreenMessage(int nr, boolean initial)
1577 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1578 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1580 if (filename == NULL)
1583 // force TITLE font on title message screen
1584 SetFontStatus(getTitleMessageGameMode(initial));
1586 // if chars *and* width set to "-1", automatically determine width
1587 if (tmi->chars == -1 && tmi->width == -1)
1588 tmi->width = viewport.window[game_status].width;
1590 // if lines *and* height set to "-1", automatically determine height
1591 if (tmi->lines == -1 && tmi->height == -1)
1592 tmi->height = viewport.window[game_status].height;
1594 // if chars set to "-1", automatically determine by text and font width
1595 if (tmi->chars == -1)
1596 tmi->chars = tmi->width / getFontWidth(tmi->font);
1598 tmi->width = tmi->chars * getFontWidth(tmi->font);
1600 // if lines set to "-1", automatically determine by text and font height
1601 if (tmi->lines == -1)
1602 tmi->lines = tmi->height / getFontHeight(tmi->font);
1604 tmi->height = tmi->lines * getFontHeight(tmi->font);
1606 // if x set to "-1", automatically determine by width and alignment
1608 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1610 // if y set to "-1", automatically determine by height and alignment
1612 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1614 SetDrawBackgroundMask(REDRAW_ALL);
1615 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1617 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1619 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1620 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1621 tmi->autowrap, tmi->centered, tmi->parse_comments);
1626 static void DrawTitleScreen(void)
1628 KeyboardAutoRepeatOff();
1630 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1633 static boolean CheckTitleScreen(boolean levelset_has_changed)
1635 static boolean show_title_initial = TRUE;
1636 boolean show_titlescreen = FALSE;
1638 // needed to be able to skip title screen, if no image or message defined
1639 InitializeTitleControls(show_title_initial);
1641 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1642 show_titlescreen = TRUE;
1644 // show initial title images and messages only once at program start
1645 show_title_initial = FALSE;
1647 return (show_titlescreen && num_title_screens > 0);
1650 void DrawMainMenu(void)
1652 static LevelDirTree *leveldir_last_valid = NULL;
1653 boolean levelset_has_changed = FALSE;
1654 int fade_mask = REDRAW_FIELD;
1656 LimitScreenUpdates(FALSE);
1658 FadeSetLeaveScreen();
1660 // do not fade out here -- function may continue and fade on editor screen
1663 FadeMenuSoundsAndMusic();
1665 ExpireSoundLoops(FALSE);
1667 KeyboardAutoRepeatOn();
1669 audio.sound_deactivated = FALSE;
1673 // needed if last screen was the playing screen, invoked from level editor
1674 if (level_editor_test_game)
1676 CloseDoor(DOOR_CLOSE_ALL);
1678 SetGameStatus(GAME_MODE_EDITOR);
1685 // leveldir_current may be invalid (level group, parent link, node copy)
1686 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1688 if (leveldir_current != leveldir_last_valid)
1690 UpdateLastPlayedLevels_TreeInfo();
1692 levelset_has_changed = TRUE;
1695 // store valid level series information
1696 leveldir_last_valid = leveldir_current;
1698 // needed if last screen (level choice) changed graphics, sounds or music
1699 ReloadCustomArtwork(0);
1701 if (CheckTitleScreen(levelset_has_changed))
1703 SetGameStatus(GAME_MODE_TITLE);
1710 if (redraw_mask & REDRAW_ALL)
1711 fade_mask = REDRAW_ALL;
1714 fade_mask = REDRAW_ALL;
1718 // needed if different viewport properties defined for menues
1719 ChangeViewportPropertiesIfNeeded();
1721 SetDrawtoField(DRAW_TO_BACKBUFFER);
1723 // level_nr may have been set to value over handicap with level editor
1724 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1725 level_nr = leveldir_current->handicap_level;
1727 LoadLevel(level_nr);
1728 LoadScore(level_nr);
1730 SaveLevelSetup_SeriesInfo();
1732 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1733 SetDrawDeactivationMask(REDRAW_NONE);
1734 SetDrawBackgroundMask(REDRAW_FIELD);
1736 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1739 if (fade_mask == REDRAW_ALL)
1740 RedrawGlobalBorder();
1745 InitializeMainControls();
1747 DrawCursorAndText_Main(-1, FALSE, FALSE);
1748 DrawPreviewLevelInitial();
1749 DrawNetworkPlayers();
1751 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1754 if (TAPE_IS_EMPTY(tape))
1756 DrawCompleteVideoDisplay();
1758 PlayMenuSoundsAndMusic();
1760 // create gadgets for main menu screen
1761 FreeScreenGadgets();
1762 CreateScreenGadgets();
1764 // may be required if audio buttons shown on tape and changed in setup menu
1766 CreateGameButtons();
1768 // map gadgets for main menu screen
1770 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1771 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1773 // copy actual game door content to door double buffer for OpenDoor()
1774 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1775 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1777 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1779 DrawMaskedBorder(fade_mask);
1784 // update screen area with special editor door
1785 redraw_mask |= REDRAW_ALL;
1788 SetMouseCursor(CURSOR_DEFAULT);
1790 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1792 SyncEmscriptenFilesystem();
1794 // needed once after program start or after user change
1795 CheckApiServerTasks();
1798 static void gotoTopLevelDir(void)
1800 // move upwards until inside (but not above) top level directory
1801 while (leveldir_current->node_parent &&
1802 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1804 // write a "path" into level tree for easy navigation to last level
1805 if (leveldir_current->node_parent->node_group->cl_first == -1)
1807 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1808 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1809 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1810 int cl_first, cl_cursor;
1812 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1813 cl_cursor = leveldir_pos - cl_first;
1815 leveldir_current->node_parent->node_group->cl_first = cl_first;
1816 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1819 leveldir_current = leveldir_current->node_parent;
1823 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1825 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1827 return (use_frame_counter ? video.frame_counter : Counter());
1830 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1831 struct TitleFadingInfo *fi)
1833 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1836 static void ResetTitleAutoDelay(unsigned int *counter_var,
1837 struct TitleFadingInfo *fi)
1839 *counter_var = getAutoDelayCounter(fi);
1842 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1844 static unsigned int title_delay = 0;
1845 static int title_screen_nr = 0;
1846 static int last_sound = -1, last_music = -1;
1847 boolean return_to_main_menu = FALSE;
1848 struct TitleControlInfo *tci;
1851 if (button == MB_MENU_INITIALIZE)
1854 title_screen_nr = 0;
1855 tci = &title_controls[title_screen_nr];
1857 SetAnimStatus(getTitleAnimMode(tci));
1859 last_sound = SND_UNDEFINED;
1860 last_music = MUS_UNDEFINED;
1862 if (num_title_screens != 0)
1864 FadeSetEnterScreen();
1866 // use individual title fading instead of global "enter screen" fading
1867 fading = getTitleFading(tci);
1870 if (game_status_last_screen == GAME_MODE_INFO)
1872 if (num_title_screens == 0)
1874 // switch game mode from title screen mode back to info screen mode
1875 SetGameStatus(GAME_MODE_INFO);
1877 // store that last screen was info screen, not main menu screen
1878 game_status_last_screen = GAME_MODE_INFO;
1880 DrawInfoScreen_NotAvailable("Title screen information:",
1881 "No title screen for this level set.");
1886 FadeMenuSoundsAndMusic();
1888 FadeOut(REDRAW_ALL);
1890 // title screens may have different window size
1891 ChangeViewportPropertiesIfNeeded();
1893 // only required to update logic for redrawing global border
1897 DrawTitleScreenImage(tci->local_nr, tci->initial);
1899 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1901 sound = getTitleSound(tci);
1902 music = getTitleMusic(tci);
1904 if (sound != last_sound)
1905 PlayMenuSoundExt(sound);
1906 if (music != last_music)
1907 PlayMenuMusicExt(music);
1912 SetMouseCursor(CURSOR_NONE);
1916 ResetTitleAutoDelay(&title_delay, &fading);
1921 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1922 button = MB_MENU_CHOICE;
1924 if (button == MB_MENU_LEAVE)
1926 return_to_main_menu = TRUE;
1928 else if (button == MB_MENU_CHOICE || dx)
1930 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1932 SetGameStatus(GAME_MODE_INFO);
1934 info_mode = INFO_MODE_MAIN;
1942 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
1944 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
1946 tci = &title_controls[title_screen_nr];
1948 SetAnimStatus(getTitleAnimMode(tci));
1950 sound = getTitleSound(tci);
1951 music = getTitleMusic(tci);
1953 if (last_sound != SND_UNDEFINED && sound != last_sound)
1954 FadeSound(last_sound);
1955 if (last_music != MUS_UNDEFINED && music != last_music)
1958 fading = getTitleFading(tci);
1960 FadeOut(REDRAW_ALL);
1963 DrawTitleScreenImage(tci->local_nr, tci->initial);
1965 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1967 sound = getTitleSound(tci);
1968 music = getTitleMusic(tci);
1970 if (sound != last_sound)
1971 PlayMenuSoundExt(sound);
1972 if (music != last_music)
1973 PlayMenuMusicExt(music);
1980 ResetTitleAutoDelay(&title_delay, &fading);
1984 FadeMenuSoundsAndMusic();
1986 return_to_main_menu = TRUE;
1990 if (return_to_main_menu)
1992 SetMouseCursor(CURSOR_DEFAULT);
1994 // force full menu screen redraw after displaying title screens
1995 redraw_mask = REDRAW_ALL;
1997 if (game_status_last_screen == GAME_MODE_INFO)
1999 SetGameStatus(GAME_MODE_INFO);
2001 info_mode = INFO_MODE_MAIN;
2005 else // default: return to main menu
2007 SetGameStatus(GAME_MODE_MAIN);
2014 static void HandleMainMenu_ToggleTeamMode(void)
2016 setup.team_mode = !setup.team_mode;
2018 InitializeMainControls();
2019 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2021 DrawPreviewPlayers();
2024 static void HandleMainMenu_SelectLevel(int step, int direction,
2025 int selected_level_nr)
2027 int old_level_nr = level_nr;
2030 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2031 new_level_nr = selected_level_nr;
2033 new_level_nr = old_level_nr + step * direction;
2035 if (new_level_nr < leveldir_current->first_level)
2036 new_level_nr = leveldir_current->first_level;
2037 if (new_level_nr > leveldir_current->last_level)
2038 new_level_nr = leveldir_current->last_level;
2040 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2042 // skipping levels is only allowed when trying to skip single level
2043 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2044 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2046 leveldir_current->handicap_level++;
2047 SaveLevelSetup_SeriesInfo();
2050 new_level_nr = leveldir_current->handicap_level;
2053 if (new_level_nr != old_level_nr)
2055 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2057 PlaySound(SND_MENU_ITEM_SELECTING);
2059 level_nr = new_level_nr;
2061 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2062 int2str(level_nr, menu.main.text.level_number.size),
2063 mci->pos_text->font);
2065 LoadLevel(level_nr);
2066 DrawPreviewLevelInitial();
2070 DrawCompleteVideoDisplay();
2072 SaveLevelSetup_SeriesInfo();
2074 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2076 // force redraw of playfield area (may be reset at this point)
2077 redraw_mask |= REDRAW_FIELD;
2081 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2083 static int choice = MAIN_CONTROL_GAME;
2084 static boolean button_pressed_last = FALSE;
2085 boolean button_pressed = FALSE;
2087 int i = 0; // needed to prevent compiler warning due to bad code below
2089 if (button == MB_MENU_INITIALIZE)
2091 DrawCursorAndText_Main(choice, TRUE, FALSE);
2096 if (mx || my) // mouse input
2100 for (i = 0; main_controls[i].nr != -1; i++)
2102 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2103 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2104 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2106 pos = main_controls[i].nr;
2112 // check if level preview was clicked
2113 if (insidePreviewRect(&preview, mx - SX, my - SY))
2114 pos = MAIN_CONTROL_GAME;
2116 // handle pressed/unpressed state for active/inactive menu buttons
2117 // (if pos != -1, "i" contains index position corresponding to "pos")
2119 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2120 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2121 button_pressed = TRUE;
2123 if (button_pressed != button_pressed_last)
2125 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2128 PlaySound(SND_MENU_BUTTON_PRESSING);
2130 PlaySound(SND_MENU_BUTTON_RELEASING);
2133 else if (dx || dy) // keyboard input
2135 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2136 choice == MAIN_CONTROL_SETUP))
2137 button = MB_MENU_CHOICE;
2142 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2144 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2146 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2148 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2150 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2152 CloseDoor(DOOR_CLOSE_2);
2154 SetGameStatus(GAME_MODE_LEVELNR);
2156 DrawChooseLevelNr();
2158 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2164 PlaySound(SND_MENU_ITEM_ACTIVATING);
2166 DrawCursorAndText_Main(choice, FALSE, FALSE);
2167 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2173 if (choice == MAIN_CONTROL_NAME)
2175 // special case: cursor left or right pressed -- toggle team mode
2176 HandleMainMenu_ToggleTeamMode();
2178 else if (choice != MAIN_CONTROL_INFO &&
2179 choice != MAIN_CONTROL_SETUP)
2181 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2187 PlaySound(SND_MENU_ITEM_SELECTING);
2189 if (pos == MAIN_CONTROL_NAME)
2192 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2194 // special case: menu text "name/team" clicked -- toggle team mode
2195 HandleMainMenu_ToggleTeamMode();
2199 if (setup.multiple_users)
2201 CloseDoor(DOOR_CLOSE_2);
2203 SetGameStatus(GAME_MODE_NAMES);
2205 DrawChoosePlayerName();
2209 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2215 else if (pos == MAIN_CONTROL_LEVELS)
2219 CloseDoor(DOOR_CLOSE_2);
2221 SetGameStatus(GAME_MODE_LEVELS);
2223 SaveLevelSetup_LastSeries();
2224 SaveLevelSetup_SeriesInfo();
2226 // restore level set if chosen from "last played level set" menu
2227 RestoreLastPlayedLevels(&leveldir_current);
2229 if (setup.internal.choose_from_top_leveldir)
2232 DrawChooseLevelSet();
2235 else if (pos == MAIN_CONTROL_SCORES)
2237 CloseDoor(DOOR_CLOSE_2);
2239 SetGameStatus(GAME_MODE_SCORES);
2241 DrawHallOfFame(level_nr);
2243 else if (pos == MAIN_CONTROL_EDITOR)
2245 if (leveldir_current->readonly &&
2246 setup.editor.show_read_only_warning)
2247 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2249 CloseDoor(DOOR_CLOSE_ALL);
2251 SetGameStatus(GAME_MODE_EDITOR);
2253 FadeSetEnterScreen();
2257 else if (pos == MAIN_CONTROL_INFO)
2259 CloseDoor(DOOR_CLOSE_2);
2261 SetGameStatus(GAME_MODE_INFO);
2263 info_mode = INFO_MODE_MAIN;
2267 else if (pos == MAIN_CONTROL_GAME)
2269 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2271 else if (pos == MAIN_CONTROL_SETUP)
2273 CloseDoor(DOOR_CLOSE_2);
2275 SetGameStatus(GAME_MODE_SETUP);
2277 setup_mode = SETUP_MODE_MAIN;
2281 else if (pos == MAIN_CONTROL_QUIT)
2283 SaveLevelSetup_LastSeries();
2284 SaveLevelSetup_SeriesInfo();
2286 #if defined(PLATFORM_EMSCRIPTEN)
2287 Request("Close the browser window to quit!", REQ_CONFIRM);
2289 if (!setup.ask_on_quit_program ||
2290 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2291 SetGameStatus(GAME_MODE_QUIT);
2297 button_pressed_last = button_pressed;
2301 // ============================================================================
2302 // info screen functions
2303 // ============================================================================
2305 static struct TokenInfo *info_info;
2306 static int num_info_info; // number of info entries shown on screen
2307 static int max_info_info; // total number of info entries in list
2309 static void execInfoTitleScreen(void)
2311 info_mode = INFO_MODE_TITLE;
2316 static void execInfoElements(void)
2318 info_mode = INFO_MODE_ELEMENTS;
2323 static void execInfoMusic(void)
2325 info_mode = INFO_MODE_MUSIC;
2330 static void execInfoCredits(void)
2332 info_mode = INFO_MODE_CREDITS;
2337 static void execInfoProgram(void)
2339 info_mode = INFO_MODE_PROGRAM;
2344 static void execInfoVersion(void)
2346 info_mode = INFO_MODE_VERSION;
2351 static void execInfoLevelSet(void)
2353 info_mode = INFO_MODE_LEVELSET;
2358 static void execExitInfo(void)
2360 SetGameStatus(GAME_MODE_MAIN);
2365 static struct TokenInfo info_info_main[] =
2367 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2368 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2369 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2370 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2371 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2372 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2373 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2374 { TYPE_EMPTY, NULL, "" },
2375 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2380 static int getMenuTextFont(int type)
2382 if (type & (TYPE_SWITCH |
2396 static struct TokenInfo *setup_info;
2397 static struct TokenInfo setup_info_input[];
2399 static struct TokenInfo *menu_info;
2401 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2402 int screen_pos, int menu_info_pos_raw,
2405 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2406 struct TokenInfo *ti = &token_info[pos];
2407 int xpos = MENU_SCREEN_START_XPOS;
2408 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2409 int font_nr = getMenuTextFont(ti->type);
2411 if (setup_mode == SETUP_MODE_INPUT)
2412 font_nr = FONT_MENU_1;
2415 font_nr = FONT_ACTIVE(font_nr);
2417 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2419 if (ti->type & ~TYPE_SKIP_ENTRY)
2420 drawCursor(screen_pos, active);
2423 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2426 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2429 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2432 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2435 static char *window_size_text;
2436 static char *scaling_type_text;
2437 static char *network_server_text;
2439 static void drawSetupValue(int, int);
2441 static void drawMenuInfoList(int first_entry, int num_page_entries,
2442 int max_page_entries)
2446 if (first_entry + num_page_entries > max_page_entries)
2449 clearMenuListArea();
2451 for (i = 0; i < num_page_entries; i++)
2453 int menu_info_pos = first_entry + i;
2454 struct TokenInfo *si = &menu_info[menu_info_pos];
2455 void *value_ptr = si->value;
2457 // set some entries to "unchangeable" according to other variables
2458 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2459 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2460 (value_ptr == &setup.sound_music && !audio.music_available) ||
2461 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2462 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2463 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2464 si->type |= TYPE_GHOSTED;
2466 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2467 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2468 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2469 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2470 else if (si->type & ~TYPE_SKIP_ENTRY)
2471 initCursor(i, IMG_MENU_BUTTON);
2473 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2475 if (si->type & TYPE_STRING)
2479 if (value_ptr == &network_server_text)
2480 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2482 if (gadget_id != -1)
2484 struct GadgetInfo *gi = screen_gadget[gadget_id];
2485 int xpos = MENU_SCREEN_START_XPOS;
2486 int ypos = MENU_SCREEN_START_YPOS + i;
2487 int x = mSX + xpos * 32;
2488 int y = mSY + ypos * 32;
2490 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2494 if (si->type & TYPE_VALUE &&
2495 menu_info == setup_info)
2496 drawSetupValue(i, menu_info_pos);
2500 static void DrawInfoScreen_Main(void)
2502 int fade_mask = REDRAW_FIELD;
2505 if (redraw_mask & REDRAW_ALL)
2506 fade_mask = REDRAW_ALL;
2509 fade_mask = REDRAW_ALL;
2512 FadeMenuSoundsAndMusic();
2514 FreeScreenGadgets();
2515 CreateScreenGadgets();
2517 // (needed after displaying title screens which disable auto repeat)
2518 KeyboardAutoRepeatOn();
2520 FadeSetLeaveScreen();
2524 // needed if different viewport properties defined for info screen
2525 ChangeViewportPropertiesIfNeeded();
2527 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2531 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2533 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2535 info_info = info_info_main;
2537 // determine maximal number of info entries that can be displayed on screen
2539 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2542 // determine maximal number of info entries available for menu of info screen
2544 for (i = 0; info_info[i].type != 0; i++)
2547 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2549 MapScreenGadgets(max_info_info);
2551 PlayMenuSoundsAndMusic();
2553 DrawMaskedBorder(fade_mask);
2558 static void changeSetupValue(int, int, int);
2560 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2561 int mode, int num_page_entries,
2562 int max_page_entries)
2564 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2565 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2566 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2567 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2568 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2569 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2570 int *num_page_entries_last = num_page_entries_all_last[game_status];
2571 int *choice_store = choice_stores[game_status];
2572 int *first_entry_store = first_entry_stores[game_status];
2573 int choice = choice_store[mode]; // starts with 0
2574 int first_entry = first_entry_store[mode]; // starts with 0
2576 int y = choice - first_entry;
2578 boolean position_set_by_scrollbar = (dx == 999);
2579 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2582 if (button == MB_MENU_INITIALIZE)
2584 // check if number of menu page entries has changed (may happen by change
2585 // of custom artwork definition value for 'list_size' for this menu screen)
2586 // (in this case, the last menu position most probably has to be corrected)
2587 if (num_page_entries != num_page_entries_last[mode])
2589 choice_store[mode] = first_entry_store[mode] = 0;
2591 choice = first_entry = 0;
2594 num_page_entries_last[mode] = num_page_entries;
2597 // advance to first valid menu entry
2598 while (choice < num_page_entries &&
2599 menu_info[choice].type & TYPE_SKIP_ENTRY)
2602 if (position_set_by_scrollbar)
2603 first_entry = first_entry_store[mode] = dy;
2605 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2606 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2608 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2610 if (choice < first_entry)
2612 choice = first_entry;
2614 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2617 else if (choice > first_entry + num_page_entries - 1)
2619 choice = first_entry + num_page_entries - 1;
2621 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2625 choice_store[mode] = choice;
2627 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2631 else if (button == MB_MENU_LEAVE)
2633 PlaySound(SND_MENU_ITEM_SELECTING);
2635 for (i = 0; i < max_page_entries; i++)
2637 if (menu_info[i].type & TYPE_LEAVE_MENU)
2639 void (*menu_callback_function)(void) = menu_info[i].value;
2643 menu_callback_function();
2645 break; // absolutely needed because function changes 'menu_info'!
2652 if (mx || my) // mouse input
2654 x = (mx - mSX) / 32;
2655 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2657 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2659 // move cursor instead of scrolling when already at start/end of list
2660 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2662 else if (dy == +1 * SCROLL_LINE &&
2663 first_entry + num_page_entries == max_page_entries)
2666 // handle scrolling screen one line or page
2668 y + dy > num_page_entries - 1)
2670 boolean redraw = FALSE;
2672 if (ABS(dy) == SCROLL_PAGE)
2673 step = num_page_entries - 1;
2675 if (dy < 0 && first_entry > 0)
2677 // scroll page/line up
2679 first_entry -= step;
2680 if (first_entry < 0)
2685 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2687 // scroll page/line down
2689 first_entry += step;
2690 if (first_entry + num_page_entries > max_page_entries)
2691 first_entry = MAX(0, max_page_entries - num_page_entries);
2698 choice += first_entry - first_entry_store[mode];
2700 if (choice < first_entry)
2702 choice = first_entry;
2704 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2707 else if (choice > first_entry + num_page_entries - 1)
2709 choice = first_entry + num_page_entries - 1;
2711 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2714 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2718 if (choice < first_entry ||
2719 choice > first_entry + num_page_entries - 1)
2720 first_entry += SIGN(dy);
2723 first_entry_store[mode] = first_entry;
2724 choice_store[mode] = choice;
2726 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2728 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2730 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2731 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2739 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2741 if (menu_info[choice].type & menu_navigation_type ||
2742 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2743 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2744 menu_info[choice].type & TYPE_PLAYER)
2745 button = MB_MENU_CHOICE;
2750 // jump to next non-empty menu entry (up or down)
2751 while (first_entry + y > 0 &&
2752 first_entry + y < max_page_entries - 1 &&
2753 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2756 if (!IN_VIS_MENU(x, y))
2758 choice += y - y_old;
2760 if (choice < first_entry)
2761 first_entry = choice;
2762 else if (choice > first_entry + num_page_entries - 1)
2763 first_entry = choice - num_page_entries + 1;
2765 if (first_entry >= 0 &&
2766 first_entry + num_page_entries <= max_page_entries)
2768 first_entry_store[mode] = first_entry;
2770 if (choice < first_entry)
2771 choice = first_entry;
2772 else if (choice > first_entry + num_page_entries - 1)
2773 choice = first_entry + num_page_entries - 1;
2775 choice_store[mode] = choice;
2777 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2779 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2781 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2782 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2789 if (!anyScrollbarGadgetActive() &&
2790 IN_VIS_MENU(x, y) &&
2791 mx < mx_right_border &&
2792 y >= 0 && y < num_page_entries)
2796 if (first_entry + y != choice &&
2797 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2799 PlaySound(SND_MENU_ITEM_ACTIVATING);
2801 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2802 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2804 choice = choice_store[mode] = first_entry + y;
2808 PlaySound(SND_MENU_ITEM_SELECTING);
2810 for (i = 0; menu_info[i].type != 0; i++)
2812 if (menu_info[i].type & TYPE_LEAVE_MENU)
2814 void (*menu_callback_function)(void) = menu_info[i].value;
2818 menu_callback_function();
2820 // absolutely needed because function changes 'menu_info'!
2828 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2830 PlaySound(SND_MENU_ITEM_SELECTING);
2832 // when selecting key headline, execute function for key value change
2833 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2834 menu_info[first_entry + y + 1].type & TYPE_KEY)
2837 // when selecting string value, execute function for list selection
2838 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2839 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2842 // when selecting string value, execute function for text input gadget
2843 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2844 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2847 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2849 void (*menu_callback_function)(void) =
2850 menu_info[first_entry + y].value;
2852 FadeSetFromType(menu_info[first_entry + y].type);
2854 menu_callback_function();
2856 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2858 void (*gadget_callback_function)(void) =
2859 menu_info[first_entry + y].value;
2861 gadget_callback_function();
2863 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2864 menu_info == setup_info)
2866 changeSetupValue(y, first_entry + y, dx);
2872 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2874 menu_info = info_info;
2876 HandleMenuScreen(mx, my, dx, dy, button,
2877 info_mode, num_info_info, max_info_info);
2880 static int getMenuFontSpacing(int spacing_height, int font_nr)
2882 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2884 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2888 static int getMenuTextSpacing(int spacing_height, int font_nr)
2890 return (getMenuFontSpacing(spacing_height, font_nr) +
2891 EXTRA_SPACING(game_status));
2894 static int getMenuTextStep(int spacing_height, int font_nr)
2896 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2899 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2901 int font_title = MENU_INFO_FONT_TITLE;
2902 int font_error = FONT_TEXT_2;
2903 int font_foot = MENU_INFO_FONT_FOOT;
2904 int spacing_title = menu.headline1_spacing_info[info_mode];
2905 int ystep_title = getMenuTextStep(spacing_title, font_title);
2906 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2907 int ystart2 = ystart1 + ystep_title;
2908 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2910 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2912 FadeOut(REDRAW_FIELD);
2917 DrawTextSCentered(ystart1, font_title, text_title);
2918 DrawTextSCentered(ystart2, font_error, text_error);
2920 DrawTextSCentered(ybottom, font_foot,
2921 "Press any key or button for info menu");
2923 FadeIn(REDRAW_FIELD);
2926 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2928 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2929 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2930 int font_title = MENU_INFO_FONT_TITLE;
2931 int font_foot = MENU_INFO_FONT_FOOT;
2932 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2933 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2934 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2935 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2936 int ystep = MENU_SCREEN_INFO_YSTEP;
2937 int element, action, direction;
2945 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2946 infoscreen_step[i] = infoscreen_frame[i] = 0;
2951 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2953 DrawTextSCentered(ybottom, font_foot,
2954 "Press any key or button for next page");
2960 while (helpanim_info[j].element != HELPANIM_LIST_END)
2962 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2967 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2976 j += infoscreen_step[i - start];
2978 element = helpanim_info[j].element;
2979 action = helpanim_info[j].action;
2980 direction = helpanim_info[j].direction;
2983 element = EL_UNKNOWN;
2985 if (action != -1 && direction != -1)
2986 graphic = el_act_dir2img(element, action, direction);
2987 else if (action != -1)
2988 graphic = el_act2img(element, action);
2989 else if (direction != -1)
2990 graphic = el_dir2img(element, direction);
2992 graphic = el2img(element);
2994 delay = helpanim_info[j++].delay;
2999 if (infoscreen_frame[i - start] == 0)
3002 infoscreen_frame[i - start] = delay - 1;
3006 sync_frame = delay - infoscreen_frame[i - start];
3007 infoscreen_frame[i - start]--;
3010 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3012 if (!infoscreen_frame[i - start])
3013 infoscreen_step[i - start] = 0;
3017 if (!infoscreen_frame[i - start])
3018 infoscreen_step[i - start]++;
3019 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3025 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3027 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3028 graphic, sync_frame, USE_MASKING);
3031 DrawInfoScreen_HelpText(element, action, direction, i - start);
3036 redraw_mask |= REDRAW_FIELD;
3041 static char *getHelpText(int element, int action, int direction)
3043 char token[MAX_LINE_LEN];
3045 strcpy(token, element_info[element].token_name);
3048 strcat(token, element_action_info[action].suffix);
3050 if (direction != -1)
3051 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3053 return getHashEntry(helptext_info, token);
3056 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3058 int font_nr = FONT_INFO_ELEMENTS;
3059 int font_width = getFontWidth(font_nr);
3060 int font_height = getFontHeight(font_nr);
3061 int yoffset = (TILEX - 2 * font_height) / 2;
3062 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3063 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3064 int ystep = TILEY + 4;
3065 int pad_left = xstart - SX;
3066 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3067 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3068 int max_lines_per_text = 2;
3071 if (action != -1 && direction != -1) // element.action.direction
3072 text = getHelpText(element, action, direction);
3074 if (text == NULL && action != -1) // element.action
3075 text = getHelpText(element, action, -1);
3077 if (text == NULL && direction != -1) // element.direction
3078 text = getHelpText(element, -1, direction);
3080 if (text == NULL) // base element
3081 text = getHelpText(element, -1, -1);
3083 if (text == NULL) // not found
3084 text = "No description available";
3086 if (strlen(text) <= max_chars_per_line) // only one line of text
3087 ystart += getFontHeight(font_nr) / 2;
3089 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3090 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3091 TRUE, FALSE, FALSE);
3094 static void DrawInfoScreen_TitleScreen(void)
3096 SetGameStatus(GAME_MODE_TITLE);
3101 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3103 HandleTitleScreen(0, 0, dx, dy, button);
3106 static void DrawInfoScreen_Elements(void)
3108 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3110 FadeOut(REDRAW_FIELD);
3115 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3117 FadeIn(REDRAW_FIELD);
3120 void HandleInfoScreen_Elements(int dx, int dy, int button)
3122 static unsigned int info_delay = 0;
3123 static int num_anims;
3124 static int num_pages;
3126 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3129 if (button == MB_MENU_INITIALIZE)
3131 boolean new_element = TRUE;
3135 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3137 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3139 else if (new_element)
3142 new_element = FALSE;
3146 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3150 if (button == MB_MENU_LEAVE)
3152 PlaySound(SND_MENU_ITEM_SELECTING);
3154 info_mode = INFO_MODE_MAIN;
3159 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3161 if (button != MB_MENU_INITIALIZE)
3163 PlaySound(SND_MENU_ITEM_SELECTING);
3165 page += (dx < 0 ? -1 : +1);
3168 if (page < 0 || page >= num_pages)
3170 FadeMenuSoundsAndMusic();
3172 info_mode = INFO_MODE_MAIN;
3178 if (button != MB_MENU_INITIALIZE)
3179 FadeSetNextScreen();
3181 if (button != MB_MENU_INITIALIZE)
3182 FadeOut(REDRAW_FIELD);
3184 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3186 if (button != MB_MENU_INITIALIZE)
3187 FadeIn(REDRAW_FIELD);
3191 if (DelayReached(&info_delay, GameFrameDelay))
3192 if (page < num_pages)
3193 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3195 PlayMenuSoundIfLoop();
3199 static void DrawInfoScreen_Music(void)
3201 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3203 FadeOut(REDRAW_FIELD);
3210 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3212 FadeIn(REDRAW_FIELD);
3215 void HandleInfoScreen_Music(int dx, int dy, int button)
3217 static struct MusicFileInfo *list = NULL;
3218 int font_title = MENU_INFO_FONT_TITLE;
3219 int font_head = MENU_INFO_FONT_HEAD;
3220 int font_text = MENU_INFO_FONT_TEXT;
3221 int font_foot = MENU_INFO_FONT_FOOT;
3222 int spacing_title = menu.headline1_spacing_info[info_mode];
3223 int spacing_head = menu.headline2_spacing_info[info_mode];
3224 int ystep_title = getMenuTextStep(spacing_title, font_title);
3225 int ystep_head = getMenuTextStep(spacing_head, font_head);
3226 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3227 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3229 if (button == MB_MENU_INITIALIZE)
3231 list = music_file_info;
3235 FadeMenuSoundsAndMusic();
3240 DrawTextSCentered(ystart, font_title,
3241 "No music info for this level set.");
3243 DrawTextSCentered(ybottom, font_foot,
3244 "Press any key or button for info menu");
3250 if (button == MB_MENU_LEAVE)
3252 PlaySound(SND_MENU_ITEM_SELECTING);
3254 FadeMenuSoundsAndMusic();
3256 info_mode = INFO_MODE_MAIN;
3261 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3263 if (button != MB_MENU_INITIALIZE)
3265 PlaySound(SND_MENU_ITEM_SELECTING);
3268 list = (dx < 0 ? list->prev : list->next);
3273 FadeMenuSoundsAndMusic();
3275 info_mode = INFO_MODE_MAIN;
3281 FadeMenuSoundsAndMusic();
3283 if (list != music_file_info)
3284 FadeSetNextScreen();
3286 if (button != MB_MENU_INITIALIZE)
3287 FadeOut(REDRAW_FIELD);
3294 int sound = list->music;
3296 if (IS_LOOP_SOUND(sound))
3297 PlaySoundLoop(sound);
3301 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3305 int music = list->music;
3307 if (IS_LOOP_MUSIC(music))
3308 PlayMusicLoop(music);
3312 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3315 ystart += ystep_title;
3317 if (!strEqual(list->title, UNKNOWN_NAME))
3319 if (!strEqual(list->title_header, UNKNOWN_NAME))
3321 DrawTextSCentered(ystart, font_head, list->title_header);
3322 ystart += ystep_head;
3325 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3326 ystart += ystep_head;
3329 if (!strEqual(list->artist, UNKNOWN_NAME))
3331 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3332 DrawTextSCentered(ystart, font_head, list->artist_header);
3334 DrawTextSCentered(ystart, font_head, "by");
3336 ystart += ystep_head;
3338 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3339 ystart += ystep_head;
3342 if (!strEqual(list->album, UNKNOWN_NAME))
3344 if (!strEqual(list->album_header, UNKNOWN_NAME))
3345 DrawTextSCentered(ystart, font_head, list->album_header);
3347 DrawTextSCentered(ystart, font_head, "from the album");
3349 ystart += ystep_head;
3351 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3352 ystart += ystep_head;
3355 if (!strEqual(list->year, UNKNOWN_NAME))
3357 if (!strEqual(list->year_header, UNKNOWN_NAME))
3358 DrawTextSCentered(ystart, font_head, list->year_header);
3360 DrawTextSCentered(ystart, font_head, "from the year");
3362 ystart += ystep_head;
3364 DrawTextFCentered(ystart, font_text, "%s", list->year);
3365 ystart += ystep_head;
3368 DrawTextSCentered(ybottom, FONT_TEXT_4,
3369 "Press any key or button for next page");
3371 if (button != MB_MENU_INITIALIZE)
3372 FadeIn(REDRAW_FIELD);
3375 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3376 PlaySoundLoop(list->music);
3379 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3381 int font_title = MENU_INFO_FONT_TITLE;
3382 int font_text = MENU_INFO_FONT_TEXT;
3383 int font_foot = MENU_INFO_FONT_FOOT;
3384 int spacing_title = menu.headline1_spacing_info[info_mode];
3385 int spacing_line = menu.line_spacing_info[info_mode];
3386 int ystep_title = getMenuTextStep(spacing_title, font_title);
3387 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3388 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3393 DrawTextSCentered(ystart, font_title, "Credits:");
3395 char *filename = getCreditsFilename(screen_nr, use_global_credits_screens);
3397 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3398 int chars = width / getFontWidth(font_text);
3399 int lines = height / getFontHeight(font_text);
3400 int padx = (width - chars * getFontWidth(font_text)) / 2;
3401 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3402 boolean autowrap = FALSE;
3403 boolean centered = TRUE;
3404 boolean parse_comments = TRUE;
3406 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3407 filename, font_text, chars, -1, lines, line_spacing, -1,
3408 autowrap, centered, parse_comments);
3410 DrawTextSCentered(ybottom, font_foot,
3411 "Press any key or button for next page");
3414 static void DrawInfoScreen_Credits(void)
3416 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3418 FadeMenuSoundsAndMusic();
3420 FadeOut(REDRAW_FIELD);
3422 HandleInfoScreen_Credits(0, 0, MB_MENU_INITIALIZE);
3424 FadeIn(REDRAW_FIELD);
3427 void HandleInfoScreen_Credits(int dx, int dy, int button)
3429 static int screen_nr = 0;
3431 if (button == MB_MENU_INITIALIZE)
3435 // determine number of (global or level set specific) credits screens
3436 for (i = 0; i < 2; i++)
3438 num_credits_screens = 0;
3439 use_global_credits_screens = i;
3441 while (getCreditsFilename(num_credits_screens,
3442 use_global_credits_screens) != NULL)
3443 num_credits_screens++;
3445 if (num_credits_screens > 0)
3449 if (num_credits_screens == 0)
3451 int font_title = MENU_INFO_FONT_TITLE;
3452 int font_foot = MENU_INFO_FONT_FOOT;
3453 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3454 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3459 DrawTextSCentered(ystart, font_title,
3460 "No credits for this level set.");
3462 DrawTextSCentered(ybottom, font_foot,
3463 "Press any key or button for 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_Program(void)
3513 int font_title = MENU_INFO_FONT_TITLE;
3514 int font_head = MENU_INFO_FONT_HEAD;
3515 int font_text = MENU_INFO_FONT_TEXT;
3516 int font_foot = MENU_INFO_FONT_FOOT;
3517 int spacing_title = menu.headline1_spacing_info[info_mode];
3518 int spacing_head = menu.headline2_spacing_info[info_mode];
3519 int spacing_para = menu.paragraph_spacing_info[info_mode];
3520 int spacing_line = menu.line_spacing_info[info_mode];
3521 int ystep_title = getMenuTextStep(spacing_title, font_title);
3522 int ystep_head = getMenuTextStep(spacing_head, font_head);
3523 int ystep_para = getMenuTextStep(spacing_para, font_text);
3524 int ystep_line = getMenuTextStep(spacing_line, font_text);
3525 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3526 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3528 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3530 FadeOut(REDRAW_FIELD);
3535 DrawTextSCentered(ystart, font_title, "Program Information:");
3536 ystart += ystep_title;
3538 DrawTextSCentered(ystart, font_head,
3539 "This game is Freeware!");
3540 ystart += ystep_head;
3541 DrawTextSCentered(ystart, font_head,
3542 "If you like it, send e-mail to:");
3543 ystart += ystep_head;
3544 DrawTextSCentered(ystart, font_text,
3545 setup.internal.program_email);
3546 ystart += ystep_para;
3548 DrawTextSCentered(ystart, font_head,
3549 "More information and levels:");
3550 ystart += ystep_head;
3551 DrawTextSCentered(ystart, font_text,
3552 setup.internal.program_website);
3553 ystart += ystep_para;
3555 DrawTextSCentered(ystart, font_head,
3556 "If you have created new levels,");
3557 ystart += ystep_line;
3558 DrawTextSCentered(ystart, font_head,
3559 "send them to me to include them!");
3560 ystart += ystep_head;
3561 DrawTextSCentered(ystart, font_head,
3564 DrawTextSCentered(ybottom, font_foot,
3565 "Press any key or button for info menu");
3567 FadeIn(REDRAW_FIELD);
3570 void HandleInfoScreen_Program(int button)
3572 if (button == MB_MENU_LEAVE)
3574 PlaySound(SND_MENU_ITEM_SELECTING);
3576 info_mode = INFO_MODE_MAIN;
3581 else if (button == MB_MENU_CHOICE)
3583 PlaySound(SND_MENU_ITEM_SELECTING);
3585 FadeMenuSoundsAndMusic();
3587 info_mode = INFO_MODE_MAIN;
3592 PlayMenuSoundIfLoop();
3596 static void DrawInfoScreen_Version(void)
3598 int font_title = MENU_INFO_FONT_TITLE;
3599 int font_head = MENU_INFO_FONT_HEAD;
3600 int font_text = MENU_INFO_FONT_TEXT;
3601 int font_foot = MENU_INFO_FONT_FOOT;
3602 int spacing_title = menu.headline1_spacing_info[info_mode];
3603 int spacing_head = menu.headline2_spacing_info[info_mode];
3604 int spacing_para = menu.paragraph_spacing_info[info_mode];
3605 int spacing_line = menu.line_spacing_info[info_mode];
3606 int xstep = getFontWidth(font_text);
3607 int ystep_title = getMenuTextStep(spacing_title, font_title);
3608 int ystep_head = getMenuTextStep(spacing_head, font_head);
3609 int ystep_para = getMenuTextStep(spacing_para, font_text);
3610 int ystep_line = getMenuTextStep(spacing_line, font_text);
3611 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3612 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3613 int xstart1 = mSX - SX + 2 * xstep;
3614 int xstart2 = mSX - SX + 18 * xstep;
3615 int xstart3 = mSX - SX + 28 * xstep;
3616 SDL_version sdl_version_compiled;
3617 const SDL_version *sdl_version_linked;
3618 int driver_name_len = 10;
3619 SDL_version sdl_version_linked_ext;
3620 const char *driver_name = NULL;
3622 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3624 FadeOut(REDRAW_FIELD);
3629 DrawTextSCentered(ystart, font_title, "Version Information:");
3630 ystart += ystep_title;
3632 DrawTextF(xstart1, ystart, font_head, "Name");
3633 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3634 ystart += ystep_line;
3636 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3638 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3639 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3640 ystart += ystep_line;
3642 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3643 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3644 ystart += ystep_line;
3648 DrawTextF(xstart1, ystart, font_head, "Version");
3649 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3650 ystart += ystep_line;
3653 DrawTextF(xstart1, ystart, font_head, "Platform");
3654 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3656 PLATFORM_XX_BIT_STRING);
3657 ystart += ystep_line;
3659 DrawTextF(xstart1, ystart, font_head, "Target");
3660 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3661 ystart += ystep_line;
3663 DrawTextF(xstart1, ystart, font_head, "Source date");
3664 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3665 ystart += ystep_line;
3667 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3668 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3669 ystart += ystep_para;
3671 DrawTextF(xstart1, ystart, font_head, "Library");
3672 DrawTextF(xstart2, ystart, font_head, "compiled");
3673 DrawTextF(xstart3, ystart, font_head, "linked");
3674 ystart += ystep_head;
3676 SDL_VERSION(&sdl_version_compiled);
3677 SDL_GetVersion(&sdl_version_linked_ext);
3678 sdl_version_linked = &sdl_version_linked_ext;
3680 DrawTextF(xstart1, ystart, font_text, "SDL");
3681 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3682 sdl_version_compiled.major,
3683 sdl_version_compiled.minor,
3684 sdl_version_compiled.patch);
3685 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3686 sdl_version_linked->major,
3687 sdl_version_linked->minor,
3688 sdl_version_linked->patch);
3689 ystart += ystep_line;
3691 SDL_IMAGE_VERSION(&sdl_version_compiled);
3692 sdl_version_linked = IMG_Linked_Version();
3694 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3695 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3696 sdl_version_compiled.major,
3697 sdl_version_compiled.minor,
3698 sdl_version_compiled.patch);
3699 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3700 sdl_version_linked->major,
3701 sdl_version_linked->minor,
3702 sdl_version_linked->patch);
3703 ystart += ystep_line;
3705 SDL_MIXER_VERSION(&sdl_version_compiled);
3706 sdl_version_linked = Mix_Linked_Version();
3708 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3709 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3710 sdl_version_compiled.major,
3711 sdl_version_compiled.minor,
3712 sdl_version_compiled.patch);
3713 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3714 sdl_version_linked->major,
3715 sdl_version_linked->minor,
3716 sdl_version_linked->patch);
3717 ystart += ystep_line;
3719 SDL_NET_VERSION(&sdl_version_compiled);
3720 sdl_version_linked = SDLNet_Linked_Version();
3722 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3723 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3724 sdl_version_compiled.major,
3725 sdl_version_compiled.minor,
3726 sdl_version_compiled.patch);
3727 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3728 sdl_version_linked->major,
3729 sdl_version_linked->minor,
3730 sdl_version_linked->patch);
3731 ystart += ystep_para;
3733 DrawTextF(xstart1, ystart, font_head, "Driver");
3734 DrawTextF(xstart2, ystart, font_head, "Requested");
3735 DrawTextF(xstart3, ystart, font_head, "Used");
3736 ystart += ystep_head;
3739 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3741 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3742 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3743 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3744 ystart += ystep_line;
3747 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3749 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3750 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3751 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3752 ystart += ystep_line;
3755 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3757 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3758 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3759 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3761 DrawTextSCentered(ybottom, font_foot,
3762 "Press any key or button for info menu");
3764 FadeIn(REDRAW_FIELD);
3767 void HandleInfoScreen_Version(int button)
3769 if (button == MB_MENU_LEAVE)
3771 PlaySound(SND_MENU_ITEM_SELECTING);
3773 info_mode = INFO_MODE_MAIN;
3778 else if (button == MB_MENU_CHOICE)
3780 PlaySound(SND_MENU_ITEM_SELECTING);
3782 FadeMenuSoundsAndMusic();
3784 info_mode = INFO_MODE_MAIN;
3789 PlayMenuSoundIfLoop();
3793 static void DrawInfoScreen_LevelSet(void)
3795 struct TitleMessageInfo *tmi = &readme;
3796 char *filename = getLevelSetInfoFilename();
3797 char *title = "Level Set Information:";
3798 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3799 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3801 if (filename == NULL)
3803 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3808 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3810 FadeOut(REDRAW_FIELD);
3815 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3817 // if x position set to "-1", automatically determine by playfield width
3819 tmi->x = SXSIZE / 2;
3821 // if y position set to "-1", use static default value
3825 // if width set to "-1", automatically determine by playfield width
3826 if (tmi->width == -1)
3827 tmi->width = SXSIZE - 2 * TILEX;
3829 // if height set to "-1", automatically determine by playfield height
3830 if (tmi->height == -1)
3831 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3833 // if chars set to "-1", automatically determine by text and font width
3834 if (tmi->chars == -1)
3835 tmi->chars = tmi->width / getFontWidth(tmi->font);
3837 tmi->width = tmi->chars * getFontWidth(tmi->font);
3839 // if lines set to "-1", automatically determine by text and font height
3840 if (tmi->lines == -1)
3841 tmi->lines = tmi->height / getFontHeight(tmi->font);
3843 tmi->height = tmi->lines * getFontHeight(tmi->font);
3845 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3846 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3847 tmi->autowrap, tmi->centered, tmi->parse_comments);
3849 DrawTextSCentered(ybottom, FONT_TEXT_4,
3850 "Press any key or button for info menu");
3852 FadeIn(REDRAW_FIELD);
3855 static void HandleInfoScreen_LevelSet(int button)
3857 if (button == MB_MENU_LEAVE)
3859 PlaySound(SND_MENU_ITEM_SELECTING);
3861 info_mode = INFO_MODE_MAIN;
3866 else if (button == MB_MENU_CHOICE)
3868 PlaySound(SND_MENU_ITEM_SELECTING);
3870 FadeMenuSoundsAndMusic();
3872 info_mode = INFO_MODE_MAIN;
3877 PlayMenuSoundIfLoop();
3881 static void DrawInfoScreen(void)
3883 if (info_mode == INFO_MODE_TITLE)
3884 DrawInfoScreen_TitleScreen();
3885 else if (info_mode == INFO_MODE_ELEMENTS)
3886 DrawInfoScreen_Elements();
3887 else if (info_mode == INFO_MODE_MUSIC)
3888 DrawInfoScreen_Music();
3889 else if (info_mode == INFO_MODE_CREDITS)
3890 DrawInfoScreen_Credits();
3891 else if (info_mode == INFO_MODE_PROGRAM)
3892 DrawInfoScreen_Program();
3893 else if (info_mode == INFO_MODE_VERSION)
3894 DrawInfoScreen_Version();
3895 else if (info_mode == INFO_MODE_LEVELSET)
3896 DrawInfoScreen_LevelSet();
3898 DrawInfoScreen_Main();
3900 if (info_mode != INFO_MODE_MAIN &&
3901 info_mode != INFO_MODE_TITLE &&
3902 info_mode != INFO_MODE_MUSIC)
3903 PlayMenuSoundsAndMusic();
3906 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3908 if (info_mode == INFO_MODE_TITLE)
3909 HandleInfoScreen_TitleScreen(dx, dy, button);
3910 else if (info_mode == INFO_MODE_ELEMENTS)
3911 HandleInfoScreen_Elements(dx, dy, button);
3912 else if (info_mode == INFO_MODE_MUSIC)
3913 HandleInfoScreen_Music(dx, dy, button);
3914 else if (info_mode == INFO_MODE_CREDITS)
3915 HandleInfoScreen_Credits(dx, dy, button);
3916 else if (info_mode == INFO_MODE_PROGRAM)
3917 HandleInfoScreen_Program(button);
3918 else if (info_mode == INFO_MODE_VERSION)
3919 HandleInfoScreen_Version(button);
3920 else if (info_mode == INFO_MODE_LEVELSET)
3921 HandleInfoScreen_LevelSet(button);
3923 HandleInfoScreen_Main(mx, my, dx, dy, button);
3927 // ============================================================================
3928 // rename player API functions
3929 // ============================================================================
3931 struct ApiRenamePlayerThreadData
3937 static void *CreateThreadData_ApiRenamePlayer(void)
3939 struct ApiRenamePlayerThreadData *data =
3940 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
3942 data->player_name = getStringCopy(setup.player_name);
3943 data->player_uuid = getStringCopy(setup.player_uuid);
3948 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
3950 struct ApiRenamePlayerThreadData *data = data_raw;
3952 checked_free(data->player_name);
3953 checked_free(data->player_uuid);
3957 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
3960 struct ApiRenamePlayerThreadData *data = data_raw;
3961 char *player_name_raw = data->player_name;
3962 char *player_uuid_raw = data->player_uuid;
3964 request->hostname = setup.api_server_hostname;
3965 request->port = API_SERVER_PORT;
3966 request->method = API_SERVER_METHOD;
3967 request->uri = API_SERVER_URI_RENAME;
3969 char *player_name = getEscapedJSON(player_name_raw);
3970 char *player_uuid = getEscapedJSON(player_uuid_raw);
3972 snprintf(request->body, MAX_HTTP_BODY_SIZE,
3975 " \"game_version\": \"%s\",\n"
3976 " \"game_platform\": \"%s\",\n"
3977 " \"name\": \"%s\",\n"
3978 " \"uuid\": \"%s\"\n"
3980 getPasswordJSON(setup.api_server_password),
3981 getProgramRealVersionString(),
3982 getProgramPlatformString(),
3986 checked_free(player_name);
3987 checked_free(player_uuid);
3989 ConvertHttpRequestBodyToServerEncoding(request);
3994 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
3997 // nothing to do here
4000 #if defined(PLATFORM_EMSCRIPTEN)
4001 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4002 void *buffer, unsigned int size)
4004 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4006 if (response != NULL)
4008 HandleResponse_ApiRenamePlayer(response, data_raw);
4010 checked_free(response);
4014 Error("server response too large to handle (%d bytes)", size);
4017 FreeThreadData_ApiRenamePlayer(data_raw);
4020 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4021 int code, const char *status)
4023 Error("server failed to handle request: %d %s", code, status);
4025 FreeThreadData_ApiRenamePlayer(data_raw);
4028 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4029 int bytes, int size)
4031 // nothing to do here
4034 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4037 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4039 FreeThreadData_ApiRenamePlayer(data_raw);
4044 emscripten_async_wget2_data(request->uri,
4049 Emscripten_ApiRenamePlayer_Loaded,
4050 Emscripten_ApiRenamePlayer_Failed,
4051 Emscripten_ApiRenamePlayer_Progress);
4056 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4057 struct HttpResponse *response,
4060 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4063 if (!DoHttpRequest(request, response))
4065 Error("HTTP request failed: %s", GetHttpError());
4070 if (!HTTP_SUCCESS(response->status_code))
4072 Error("server failed to handle request: %d %s",
4073 response->status_code,
4074 response->status_text);
4079 HandleResponse_ApiRenamePlayer(response, data_raw);
4082 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4083 struct HttpResponse *response,
4086 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4088 FreeThreadData_ApiRenamePlayer(data_raw);
4092 static int ApiRenamePlayerThread(void *data_raw)
4094 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4095 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4097 program.api_thread_count++;
4099 #if defined(PLATFORM_EMSCRIPTEN)
4100 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4102 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4105 program.api_thread_count--;
4107 checked_free(request);
4108 checked_free(response);
4113 static void ApiRenamePlayerAsThread(void)
4115 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4117 ExecuteAsThread(ApiRenamePlayerThread,
4118 "ApiRenamePlayer", data,
4119 "rename player on server");
4123 // ============================================================================
4124 // reset player UUID API functions
4125 // ============================================================================
4127 struct ApiResetUUIDThreadData
4130 char *player_uuid_old;
4131 char *player_uuid_new;
4134 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4136 struct ApiResetUUIDThreadData *data =
4137 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4139 data->player_name = getStringCopy(setup.player_name);
4140 data->player_uuid_old = getStringCopy(setup.player_uuid);
4141 data->player_uuid_new = getStringCopy(uuid_new);
4146 static void FreeThreadData_ApiResetUUID(void *data_raw)
4148 struct ApiResetUUIDThreadData *data = data_raw;
4150 checked_free(data->player_name);
4151 checked_free(data->player_uuid_old);
4152 checked_free(data->player_uuid_new);
4156 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4159 struct ApiResetUUIDThreadData *data = data_raw;
4160 char *player_name_raw = data->player_name;
4161 char *player_uuid_old_raw = data->player_uuid_old;
4162 char *player_uuid_new_raw = data->player_uuid_new;
4164 request->hostname = setup.api_server_hostname;
4165 request->port = API_SERVER_PORT;
4166 request->method = API_SERVER_METHOD;
4167 request->uri = API_SERVER_URI_RESETUUID;
4169 char *player_name = getEscapedJSON(player_name_raw);
4170 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4171 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4173 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4176 " \"game_version\": \"%s\",\n"
4177 " \"game_platform\": \"%s\",\n"
4178 " \"name\": \"%s\",\n"
4179 " \"uuid_old\": \"%s\",\n"
4180 " \"uuid_new\": \"%s\"\n"
4182 getPasswordJSON(setup.api_server_password),
4183 getProgramRealVersionString(),
4184 getProgramPlatformString(),
4189 checked_free(player_name);
4190 checked_free(player_uuid_old);
4191 checked_free(player_uuid_new);
4193 ConvertHttpRequestBodyToServerEncoding(request);
4198 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4201 struct ApiResetUUIDThreadData *data = data_raw;
4203 // upgrade player UUID in server setup file
4204 setup.player_uuid = getStringCopy(data->player_uuid_new);
4205 setup.player_version = 2;
4207 SaveSetup_ServerSetup();
4210 #if defined(PLATFORM_EMSCRIPTEN)
4211 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4212 void *buffer, unsigned int size)
4214 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4216 if (response != NULL)
4218 HandleResponse_ApiResetUUID(response, data_raw);
4220 checked_free(response);
4224 Error("server response too large to handle (%d bytes)", size);
4227 FreeThreadData_ApiResetUUID(data_raw);
4230 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4231 int code, const char *status)
4233 Error("server failed to handle request: %d %s", code, status);
4235 FreeThreadData_ApiResetUUID(data_raw);
4238 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4239 int bytes, int size)
4241 // nothing to do here
4244 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4247 if (!SetRequest_ApiResetUUID(request, data_raw))
4249 FreeThreadData_ApiResetUUID(data_raw);
4254 emscripten_async_wget2_data(request->uri,
4259 Emscripten_ApiResetUUID_Loaded,
4260 Emscripten_ApiResetUUID_Failed,
4261 Emscripten_ApiResetUUID_Progress);
4266 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4267 struct HttpResponse *response,
4270 if (!SetRequest_ApiResetUUID(request, data_raw))
4273 if (!DoHttpRequest(request, response))
4275 Error("HTTP request failed: %s", GetHttpError());
4280 if (!HTTP_SUCCESS(response->status_code))
4282 Error("server failed to handle request: %d %s",
4283 response->status_code,
4284 response->status_text);
4289 HandleResponse_ApiResetUUID(response, data_raw);
4292 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4293 struct HttpResponse *response,
4296 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4298 FreeThreadData_ApiResetUUID(data_raw);
4302 static int ApiResetUUIDThread(void *data_raw)
4304 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4305 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4307 program.api_thread_count++;
4309 #if defined(PLATFORM_EMSCRIPTEN)
4310 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4312 ApiResetUUID_HttpRequest(request, response, data_raw);
4315 program.api_thread_count--;
4317 checked_free(request);
4318 checked_free(response);
4323 static void ApiResetUUIDAsThread(char *uuid_new)
4325 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4327 ExecuteAsThread(ApiResetUUIDThread,
4328 "ApiResetUUID", data,
4329 "reset UUID on server");
4333 // ============================================================================
4334 // type name functions
4335 // ============================================================================
4337 static TreeInfo *type_name_node = NULL;
4338 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4339 static int type_name_nr = 0;
4341 static int getPlayerNameColor(char *name)
4343 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4346 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4349 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4350 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4351 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4352 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4353 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4354 int font_width = getFontWidth(font_nr);
4356 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4358 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4360 pos->width = strlen(text) * font_width;
4361 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4363 DrawText(sx, sy, text, font_nr);
4366 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4368 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4370 *pos = *mci->pos_input;
4372 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4374 TreeInfo *ti = player_name_current;
4375 int first_entry = ti->cl_first;
4376 int entry_pos = first_entry + ti->cl_cursor;
4377 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4378 int xpos = MENU_SCREEN_START_XPOS;
4379 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4381 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4382 type_name_nr = entry_pos;
4384 strcpy(name, type_name_node->name);
4388 pos->width = MAX_PLAYER_NAME_LEN * 32;
4392 type_name_nr = user.nr;
4394 strcpy(name, setup.player_name);
4397 strcpy(type_name_last, name);
4399 if (strEqual(name, EMPTY_PLAYER_NAME))
4402 *xpos = strlen(name);
4405 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4407 // change name of edited user in global list of user names
4408 setString(&global.user_names[type_name_nr], name);
4410 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4412 TreeInfo *node = type_name_node;
4414 // change name of edited user in local menu tree structure
4415 setString(&node->name, name);
4416 setString(&node->name_sorting, name);
4418 node->color = getPlayerNameColor(name);
4419 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4423 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4426 boolean reset_setup = strEqual(name, "");
4427 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4428 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4431 strcpy(name, type_name_last);
4433 if (strEqual(name, ""))
4434 strcpy(name, EMPTY_PLAYER_NAME);
4436 setTypeNameValues_Name(name, pos);
4438 // if player name not changed, no further action required
4439 if (strEqual(name, type_name_last))
4442 // redraw player name before (possibly) opening request dialogs
4443 drawTypeNameText(name, pos, FALSE);
4445 int last_user_nr = user.nr;
4447 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4449 // save setup of currently active user (may differ from edited user)
4452 // temporarily change active user to edited user
4453 user.nr = type_name_nr;
4456 Request("Use current setup values for the new player?", REQ_ASK))
4458 // use current setup values for new user, but create new player UUID
4459 setup.player_uuid = getStringCopy(getUUID());
4463 // load setup for existing user (or start with defaults for new user)
4468 char *setup_filename = getSetupFilename();
4469 boolean setup_exists = fileExists(setup_filename);
4471 // change name of edited user in setup structure
4472 strcpy(setup.player_name, name);
4474 // save setup of edited user
4477 // change name of edited user on score server
4478 ApiRenamePlayerAsThread();
4480 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4484 if (Request("Reset setup values for this player?", REQ_ASK))
4486 // remove setup config file
4487 unlink(setup_filename);
4489 // set player name to default player name
4492 // update player name used by name typing functions
4493 strcpy(name, setup.player_name);
4495 setTypeNameValues_Name(name, pos);
4498 else if (remove_user && type_name_nr != 0)
4500 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4502 char *user_dir = getUserGameDataDir();
4503 char *user_dir_removed =
4504 getStringCat3WithSeparator(user_dir, "REMOVED",
4505 getCurrentTimestamp(), ".");
4507 if (rename(user_dir, user_dir_removed) != 0)
4508 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4510 checked_free(user_dir_removed);
4513 else if (create_user && type_name_nr != 0 && !setup_exists)
4515 if (Request("Create empty level set for the new player?", REQ_ASK))
4517 char *levelset_subdir = getNewUserLevelSubdir();
4519 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4521 AddUserLevelSetToLevelInfo(levelset_subdir);
4523 LevelDirTree *leveldir_current_last = leveldir_current;
4525 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4528 // set level number of newly created level set to default value
4529 LoadLevelSetup_SeriesInfo();
4531 // set newly created level set as current level set for new user
4532 SaveLevelSetup_LastSeries();
4533 SaveLevelSetup_SeriesInfo();
4535 leveldir_current = leveldir_current_last;
4539 Request("Creating new level set failed!", REQ_CONFIRM);
4544 // restore currently active user
4545 user.nr = last_user_nr;
4547 // restore setup of currently active user
4550 // restore last level set of currently active user
4551 LoadLevelSetup_LastSeries();
4552 LoadLevelSetup_SeriesInfo();
4556 static void HandleTypeNameExt(boolean initialize, Key key)
4558 static struct TextPosInfo pos_name = { 0 };
4559 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4560 static int xpos = 0;
4561 struct TextPosInfo *pos = &pos_name;
4562 char key_char = getValidConfigValueChar(getCharFromKey(key));
4563 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4564 boolean active = TRUE;
4568 getTypeNameValues(name, pos, &xpos);
4570 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4571 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4573 StartTextInput(sx, sy, pos->width, pos->height);
4575 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4577 name[xpos] = key_char;
4582 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4588 else if (key == KSYM_Return || key == KSYM_Escape)
4590 boolean changed = (key == KSYM_Return);
4594 setTypeNameValues(name, pos, changed);
4599 drawTypeNameText(name, pos, active);
4603 SetGameStatus(game_status_last_screen);
4605 if (game_status == GAME_MODE_MAIN)
4606 InitializeMainControls();
4610 static void DrawTypeName(void)
4612 HandleTypeNameExt(TRUE, 0);
4615 void HandleTypeName(Key key)
4617 HandleTypeNameExt(FALSE, key);
4621 // ============================================================================
4622 // tree menu functions
4623 // ============================================================================
4625 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4627 if (game_status != GAME_MODE_SETUP ||
4628 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4631 int max_text_size = 0;
4634 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4635 max_text_size = MAX(max_text_size, strlen(node->name));
4637 int num_entries = numTreeInfoInGroup(ti);
4638 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4639 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4640 int text_width = max_text_size * getFontWidth(font_nr);
4641 int button_width = SC_MENUBUTTON_XSIZE;
4642 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4643 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4644 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4645 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4646 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4647 int align_xoffset = MAX(0, align_xoffset_raw);
4649 return align_xoffset;
4652 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4654 if (game_status != GAME_MODE_SETUP ||
4655 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4658 int num_entries = numTreeInfoInGroup(ti);
4659 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4660 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4661 int font_height = getFontHeight(font_nr);
4662 int text_height = font_height * num_page_entries;
4663 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4664 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4665 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4666 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4667 int align_yoffset = MAX(0, align_yoffset_raw);
4669 return align_yoffset;
4672 static void DrawChooseTree(TreeInfo **ti_ptr)
4674 int fade_mask = REDRAW_FIELD;
4675 boolean restart_music = (game_status != game_status_last_screen &&
4676 game_status_last_screen != GAME_MODE_SCOREINFO);
4679 fade_mask = REDRAW_ALL;
4681 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4683 if (game_status == GAME_MODE_SETUP)
4687 else // GAME_MODE_LEVELS
4689 SetGameStatus(GAME_MODE_MAIN);
4699 FreeScreenGadgets();
4700 CreateScreenGadgets();
4703 FadeMenuSoundsAndMusic();
4707 // needed if different viewport properties defined for this screen
4708 ChangeViewportPropertiesIfNeeded();
4710 if (game_status == GAME_MODE_NAMES)
4711 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4712 else if (game_status == GAME_MODE_LEVELNR)
4713 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4714 else if (game_status == GAME_MODE_LEVELS)
4715 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4716 else if (game_status == GAME_MODE_SCORES)
4717 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4721 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4723 // map gadgets for high score screen
4724 if (game_status == GAME_MODE_SCORES)
4725 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4727 MapScreenTreeGadgets(*ti_ptr);
4729 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4731 DrawMaskedBorder(fade_mask);
4734 PlayMenuSoundsAndMusic();
4739 static int getChooseTreeFont(TreeInfo *node, boolean active)
4741 if (game_status == GAME_MODE_SCORES)
4742 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4744 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4747 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4749 int num_entries = numTreeInfoInGroup(ti);
4750 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4751 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4752 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4753 int first_entry = ti->cl_first;
4754 int entry_pos = first_entry + y;
4755 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4756 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4757 int font_nr = getChooseTreeFont(node, active);
4758 int font_xoffset = getFontDrawOffsetX(font_nr);
4759 int xpos = MENU_SCREEN_START_XPOS;
4760 int ypos = MENU_SCREEN_START_YPOS + y;
4761 int startdx = xpos * 32;
4762 int startdy = ypos * 32;
4763 int startx = amSX + startdx;
4764 int starty = amSY + startdy;
4765 int startx_text = startx + font_xoffset;
4766 int endx_text = amSX + screen_width;
4767 int max_text_size = endx_text - startx_text;
4768 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4769 char buffer[max_buffer_len + 1];
4771 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4773 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4774 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4775 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4776 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4777 int font_size_1 = getFontWidth(font_nr1);
4778 int font_size_3 = getFontWidth(font_nr3);
4779 int font_size_4 = getFontWidth(font_nr4);
4780 int text_size_1 = 4 * font_size_1;
4781 int text_size_4 = 5 * font_size_4;
4782 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4784 int dx3 = text_size_1;
4785 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4786 int num_dots = (dx4 - dx3) / font_size_3;
4787 int startx1 = startx + dx1;
4788 int startx3 = startx + dx3;
4789 int startx4 = startx + dx4;
4790 int pos = node->pos;
4791 char *pos_text = getHallOfFameRankText(pos, 3);
4794 DrawText(startx1, starty, pos_text, font_nr1);
4796 for (i = 0; i < num_dots; i++)
4797 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4799 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4800 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4802 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4806 strncpy(buffer, node->name, max_buffer_len);
4807 buffer[max_buffer_len] = '\0';
4809 DrawText(startx, starty, buffer, font_nr);
4813 static void drawChooseTreeHeadExt(int type, char *title_string)
4815 int yoffset_sets = MENU_TITLE1_YPOS;
4816 int yoffset_setup = 16;
4817 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4818 type == TREE_TYPE_LEVEL_DIR ||
4819 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4821 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4824 static void drawChooseTreeHead(TreeInfo *ti)
4826 drawChooseTreeHeadExt(ti->type, ti->infotext);
4829 static void drawChooseTreeList(TreeInfo *ti)
4831 int first_entry = ti->cl_first;
4832 int num_entries = numTreeInfoInGroup(ti);
4833 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4836 clearMenuListArea();
4838 for (i = 0; i < num_page_entries; i++)
4840 TreeInfo *node, *node_first;
4841 int entry_pos = first_entry + i;
4843 node_first = getTreeInfoFirstGroupEntry(ti);
4844 node = getTreeInfoFromPos(node_first, entry_pos);
4846 drawChooseTreeText(ti, i, FALSE);
4848 if (node->parent_link)
4849 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4850 else if (node->level_group)
4851 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4853 initCursor(i, IMG_MENU_BUTTON);
4855 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4856 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4858 if (game_status == GAME_MODE_NAMES)
4859 drawChooseTreeEdit(i, FALSE);
4862 redraw_mask |= REDRAW_FIELD;
4865 static void drawChooseTreeInfo(TreeInfo *ti)
4867 int entry_pos = ti->cl_first + ti->cl_cursor;
4868 int last_redraw_mask = redraw_mask;
4869 int ypos = MENU_TITLE2_YPOS;
4870 int font_nr = FONT_TITLE_2;
4873 if (ti->type == TREE_TYPE_LEVEL_NR)
4874 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4876 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4877 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4878 scores.last_level_nr);
4880 if (ti->type != TREE_TYPE_LEVEL_DIR)
4883 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4884 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4886 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4888 if (node->parent_link)
4889 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4890 node->node_parent->name);
4891 else if (node->level_group)
4892 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4894 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4895 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4896 node->levels, (node->levels > 1 ? "levels" : "level"),
4899 // let BackToFront() redraw only what is needed
4900 redraw_mask = last_redraw_mask;
4901 for (x = 0; x < SCR_FIELDX; x++)
4902 MarkTileDirty(x, 1);
4905 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4907 drawChooseTreeCursor(ti->cl_cursor, active);
4908 drawChooseTreeText(ti, ti->cl_cursor, active);
4911 static void drawChooseTreeScreen(TreeInfo *ti)
4913 drawChooseTreeHead(ti);
4914 drawChooseTreeList(ti);
4915 drawChooseTreeInfo(ti);
4916 drawChooseTreeCursorAndText(ti, TRUE);
4918 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4920 // scroll bar and buttons may just have been added after reloading scores
4921 if (game_status == GAME_MODE_SCORES)
4922 MapScreenTreeGadgets(ti);
4925 static void drawChooseTreeScreen_Scores_NotAvailable(void)
4927 // dirty workaround to use spacing definitions from info screen
4928 info_mode = INFO_MODE_TITLE;
4930 char *text_info = "HighScores of Level %d";
4931 char *text_title = "Score information:";
4932 char *text_error = "No scores for this level.";
4933 char *text_foot = "Press any key or button for main menu";
4934 int font_info = FONT_TITLE_2;
4935 int font_title = FONT_INITIAL_3;
4936 int font_error = FONT_INITIAL_4;
4937 int font_foot = FONT_INITIAL_2;
4938 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
4939 int ystep_title = getMenuTextStep(spacing_title, font_title);
4940 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
4941 int ystart2 = ystart1 + ystep_title;
4942 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4943 int ystart0 = MENU_TITLE2_YPOS;
4945 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
4946 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
4948 DrawTextSCentered(ystart1, font_title, text_title);
4949 DrawTextSCentered(ystart2, font_error, text_error);
4951 DrawTextSCentered(ybottom, font_foot, text_foot);
4954 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4956 int score_pos = scores.last_added;
4958 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4959 score_pos = scores.last_entry_nr;
4961 // set current tree entry to last added score entry
4962 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4964 // if that fails, set current tree entry to first entry (back link)
4965 if (*ti_ptr == NULL)
4966 *ti_ptr = score_entries->node_group;
4968 int num_entries = numTreeInfoInGroup(*ti_ptr);
4969 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4970 int pos_score = getPosFromTreeInfo(*ti_ptr);
4971 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4972 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4974 (*ti_ptr)->cl_first = pos_first;
4975 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4980 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4983 TreeInfo *ti = *ti_ptr;
4984 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4985 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4986 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4987 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4988 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4990 int y = (ti != NULL ? ti->cl_cursor : 0);
4991 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4992 int num_entries = numTreeInfoInGroup(ti);
4993 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4994 boolean position_set_by_scrollbar = (dx == 999);
4995 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
4996 boolean button_is_valid = (mx >= 0 && my >= 0);
4997 boolean button_screen_clicked = (button_action && button_is_valid);
4999 if (game_status == GAME_MODE_SCORES)
5001 if (server_scores.updated)
5003 // reload scores, using updated server score cache file
5004 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5006 server_scores.updated = FALSE;
5008 DrawHallOfFame_setScoreEntries();
5010 if (score_entries != NULL)
5012 ti = setHallOfFameActiveEntry(ti_ptr);
5014 if (button != MB_MENU_INITIALIZE)
5015 drawChooseTreeScreen(ti);
5019 if (score_entries == NULL)
5021 if (button == MB_MENU_INITIALIZE)
5023 drawChooseTreeScreen_Scores_NotAvailable();
5025 else if (button_screen_clicked)
5027 PlaySound(SND_MENU_ITEM_SELECTING);
5029 SetGameStatus(GAME_MODE_MAIN);
5038 if (button == MB_MENU_INITIALIZE)
5040 int num_entries = numTreeInfoInGroup(ti);
5041 int entry_pos = getPosFromTreeInfo(ti);
5043 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5044 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5046 if (game_status == GAME_MODE_SCORES)
5048 ti = setHallOfFameActiveEntry(ti_ptr);
5050 else if (ti->cl_first == -1)
5052 // only on initialization
5053 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5054 ti->cl_cursor = entry_pos - ti->cl_first;
5057 else if (ti->cl_cursor >= num_page_entries ||
5058 (num_entries > num_page_entries &&
5059 num_entries - ti->cl_first < num_page_entries))
5061 // only after change of list size (by custom graphic configuration)
5062 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5063 ti->cl_cursor = entry_pos - ti->cl_first;
5066 if (position_set_by_scrollbar)
5069 drawChooseTreeScreen(ti);
5073 else if (button == MB_MENU_LEAVE)
5075 if (game_status != GAME_MODE_SCORES)
5078 PlaySound(SND_MENU_ITEM_SELECTING);
5080 if (ti->node_parent)
5082 *ti_ptr = ti->node_parent;
5083 DrawChooseTree(ti_ptr);
5085 else if (game_status == GAME_MODE_SETUP)
5087 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5088 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5089 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5090 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5092 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5093 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5094 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5095 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5096 execSetupGraphics();
5097 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5098 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5099 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5101 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5102 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5103 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5104 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5105 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5106 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5107 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5108 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5115 if (game_status == GAME_MODE_LEVELNR)
5117 int new_level_nr = atoi(level_number_current->identifier);
5119 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5122 SetGameStatus(GAME_MODE_MAIN);
5130 if (mx || my) // mouse input
5132 x = (mx - amSX) / 32;
5133 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5135 if (game_status == GAME_MODE_NAMES)
5136 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5138 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5140 // move cursor instead of scrolling when already at start/end of list
5141 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5143 else if (dy == +1 * SCROLL_LINE &&
5144 ti->cl_first + num_page_entries == num_entries)
5147 // handle scrolling screen one line or page
5148 if (ti->cl_cursor + dy < 0 ||
5149 ti->cl_cursor + dy > num_page_entries - 1)
5151 boolean redraw = FALSE;
5153 if (ABS(dy) == SCROLL_PAGE)
5154 step = num_page_entries - 1;
5156 if (dy < 0 && ti->cl_first > 0)
5158 // scroll page/line up
5160 ti->cl_first -= step;
5161 if (ti->cl_first < 0)
5166 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5168 // scroll page/line down
5170 ti->cl_first += step;
5171 if (ti->cl_first + num_page_entries > num_entries)
5172 ti->cl_first = MAX(0, num_entries - num_page_entries);
5178 drawChooseTreeScreen(ti);
5183 // handle moving cursor one line
5184 y = ti->cl_cursor + dy;
5187 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5189 HandleHallOfFame_SelectLevel(1, dx);
5195 TreeInfo *node_first, *node_cursor;
5196 int entry_pos = ti->cl_first + y;
5198 node_first = getTreeInfoFirstGroupEntry(ti);
5199 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5201 if (node_cursor->node_group)
5205 PlaySound(SND_MENU_ITEM_SELECTING);
5207 node_cursor->cl_first = ti->cl_first;
5208 node_cursor->cl_cursor = ti->cl_cursor;
5209 *ti_ptr = node_cursor->node_group;
5210 DrawChooseTree(ti_ptr);
5215 else if (dx == -1 && ti->node_parent)
5219 PlaySound(SND_MENU_ITEM_SELECTING);
5221 *ti_ptr = ti->node_parent;
5222 DrawChooseTree(ti_ptr);
5227 if (!anyScrollbarGadgetActive() &&
5228 IN_VIS_MENU(x, y) &&
5229 mx < mx_right_border &&
5230 y >= 0 && y < num_page_entries)
5234 if (game_status == GAME_MODE_NAMES)
5236 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5237 drawChooseTreeEdit(y, TRUE);
5240 if (y != ti->cl_cursor)
5242 PlaySound(SND_MENU_ITEM_ACTIVATING);
5244 drawChooseTreeCursorAndText(ti, FALSE);
5248 drawChooseTreeCursorAndText(ti, TRUE);
5250 drawChooseTreeInfo(ti);
5254 if (game_status == GAME_MODE_SETUP)
5256 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5257 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5258 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5259 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5261 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5262 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5263 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5264 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5265 execSetupGraphics();
5266 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5267 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5268 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5270 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5271 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5272 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5273 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5274 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5275 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5276 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5277 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5286 TreeInfo *node_first, *node_cursor;
5287 int entry_pos = ti->cl_first + y;
5289 PlaySound(SND_MENU_ITEM_SELECTING);
5291 node_first = getTreeInfoFirstGroupEntry(ti);
5292 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5294 if (node_cursor->node_group)
5298 node_cursor->cl_first = ti->cl_first;
5299 node_cursor->cl_cursor = ti->cl_cursor;
5300 *ti_ptr = node_cursor->node_group;
5301 DrawChooseTree(ti_ptr);
5303 else if (node_cursor->parent_link)
5305 if (game_status != GAME_MODE_SCORES)
5308 *ti_ptr = node_cursor->node_parent;
5309 DrawChooseTree(ti_ptr);
5313 if (game_status != GAME_MODE_SCORES)
5316 node_cursor->cl_first = ti->cl_first;
5317 node_cursor->cl_cursor = ti->cl_cursor;
5318 *ti_ptr = node_cursor;
5320 if (ti->type == TREE_TYPE_LEVEL_DIR)
5322 LoadLevelSetup_SeriesInfo();
5324 SaveLevelSetup_LastSeries();
5325 SaveLevelSetup_SeriesInfo();
5329 if (game_status == GAME_MODE_SETUP)
5331 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5332 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5333 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5334 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5336 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5337 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5338 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5339 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5340 execSetupGraphics();
5341 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5342 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5343 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5345 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5346 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5347 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5348 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5349 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5350 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5351 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5352 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5359 if (game_status == GAME_MODE_LEVELNR)
5361 int new_level_nr = atoi(level_number_current->identifier);
5363 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5365 else if (game_status == GAME_MODE_LEVELS)
5367 // store level set if chosen from "last played level set" menu
5368 StoreLastPlayedLevels(leveldir_current);
5370 else if (game_status == GAME_MODE_NAMES)
5372 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5374 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5381 // change active user to selected user
5382 user.nr = entry_pos;
5384 // save number of new active user
5387 // load setup of new active user
5390 // load last level set of new active user
5391 LoadLevelSetup_LastSeries();
5392 LoadLevelSetup_SeriesInfo();
5394 // update list of last played level sets
5395 UpdateLastPlayedLevels_TreeInfo();
5399 ToggleFullscreenIfNeeded();
5400 ChangeWindowScalingIfNeeded();
5402 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5403 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5404 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5406 else if (game_status == GAME_MODE_SCORES)
5408 if (game_status_last_screen == GAME_MODE_PLAYING &&
5409 setup.auto_play_next_level && setup.increment_levels &&
5410 scores.last_level_nr < leveldir_current->last_level &&
5413 StartGameActions(network.enabled, setup.autorecord,
5419 SetGameStatus(GAME_MODE_SCOREINFO);
5421 DrawScoreInfo(node_cursor->pos);
5427 SetGameStatus(GAME_MODE_MAIN);
5435 if (game_status == GAME_MODE_SCORES)
5436 PlayMenuSoundIfLoop();
5439 void DrawChoosePlayerName(void)
5443 if (player_name != NULL)
5445 freeTreeInfo(player_name);
5450 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5452 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5453 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5456 ti->node_top = &player_name;
5457 ti->sort_priority = 10000 + value;
5458 ti->color = getPlayerNameColor(global.user_names[i]);
5460 snprintf(identifier, sizeof(identifier), "%d", value);
5461 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5463 setString(&ti->identifier, identifier);
5464 setString(&ti->name, name);
5465 setString(&ti->name_sorting, name);
5467 pushTreeInfo(&player_name, ti);
5470 // sort player entries by player number
5471 sortTreeInfo(&player_name);
5473 // set current player entry to selected player entry
5474 player_name_current =
5475 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5477 // if that fails, set current player name to first available name
5478 if (player_name_current == NULL)
5479 player_name_current = player_name;
5481 DrawChooseTree(&player_name_current);
5484 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5486 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5489 void DrawChooseLevelSet(void)
5491 DrawChooseTree(&leveldir_current);
5494 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5496 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5499 void DrawChooseLevelNr(void)
5503 if (level_number != NULL)
5505 freeTreeInfo(level_number);
5507 level_number = NULL;
5510 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5512 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5513 char identifier[32], name[64];
5516 // temporarily load level info to get level name
5517 LoadLevelInfoOnly(i);
5519 ti->node_top = &level_number;
5520 ti->sort_priority = 10000 + value;
5521 ti->color = (level.no_level_file ? FC_BLUE :
5522 LevelStats_getSolved(i) ? FC_GREEN :
5523 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5525 snprintf(identifier, sizeof(identifier), "%d", value);
5526 snprintf(name, sizeof(name), "%03d: %s", value,
5527 (level.no_level_file ? "(no file)" : level.name));
5529 setString(&ti->identifier, identifier);
5530 setString(&ti->name, name);
5531 setString(&ti->name_sorting, name);
5533 pushTreeInfo(&level_number, ti);
5536 // sort level number values to start with lowest level number
5537 sortTreeInfo(&level_number);
5539 // set current level number to current level number
5540 level_number_current =
5541 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5543 // if that also fails, set current level number to first available level
5544 if (level_number_current == NULL)
5545 level_number_current = level_number;
5547 DrawChooseTree(&level_number_current);
5550 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5552 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5555 static void DrawHallOfFame_setScoreEntries(void)
5557 int max_empty_entries = 10; // at least show "top ten" list, if empty
5558 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5559 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5560 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5563 if (score_entries != NULL)
5565 freeTreeInfo(score_entries);
5567 score_entries = NULL;
5570 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5572 // do not add empty score entries if off-screen
5573 if (scores.entry[i].score == 0 &&
5574 scores.entry[i].time == 0 &&
5575 i >= min_score_entries)
5578 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5579 char identifier[32], name[64];
5582 ti->node_top = &score_entries;
5583 ti->sort_priority = 10000 + value;
5584 ti->color = FC_YELLOW;
5587 snprintf(identifier, sizeof(identifier), "%d", value);
5588 snprintf(name, sizeof(name), "%03d.", value + 1);
5590 setString(&ti->identifier, identifier);
5591 setString(&ti->name, name);
5592 setString(&ti->name_sorting, name);
5594 pushTreeInfo(&score_entries, ti);
5597 // sort score entries to start with highest score entry
5598 sortTreeInfo(&score_entries);
5600 // add top tree node to create back link to main menu
5601 score_entries = addTopTreeInfoNode(score_entries);
5603 // set current score entry to last added or highest score entry
5604 score_entry_current =
5605 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5607 // if that fails, set current score entry to first valid score entry
5608 if (score_entry_current == NULL)
5609 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5611 // ("score_entries" and "score_entry_current" may be NULL here)
5614 void DrawHallOfFame(int level_nr)
5616 scores.last_level_nr = level_nr;
5618 // (this is needed when called from GameEnd() after winning a game)
5619 KeyboardAutoRepeatOn();
5621 // (this is needed when called from GameEnd() after winning a game)
5622 SetDrawDeactivationMask(REDRAW_NONE);
5623 SetDrawBackgroundMask(REDRAW_FIELD);
5625 LoadLocalAndServerScore(level_nr, TRUE);
5627 DrawHallOfFame_setScoreEntries();
5629 if (scores.last_added >= 0)
5630 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5632 FadeSetEnterScreen();
5634 DrawChooseTree(&score_entry_current);
5637 static char *getHallOfFameRankText(int nr, int size)
5639 static char rank_text[10];
5640 boolean forced = (scores.force_last_added && nr == scores.last_added);
5641 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5643 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5648 static char *getHallOfFameTimeText(int nr)
5650 static char score_text[10];
5651 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5652 int mm = (time_seconds / 60) % 60;
5653 int ss = (time_seconds % 60);
5655 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5660 static char *getHallOfFameScoreText(int nr, int size)
5662 if (!level.rate_time_over_score)
5663 return int2str(scores.entry[nr].score, size); // show normal score
5664 else if (level.use_step_counter)
5665 return int2str(scores.entry[nr].time, size); // show number of steps
5667 return getHallOfFameTimeText(nr); // show playing time
5670 static void HandleHallOfFame_SelectLevel(int step, int direction)
5672 int old_level_nr = scores.last_level_nr;
5673 int new_level_nr = old_level_nr + step * direction;
5675 if (new_level_nr < leveldir_current->first_level)
5676 new_level_nr = leveldir_current->first_level;
5677 if (new_level_nr > leveldir_current->last_level)
5678 new_level_nr = leveldir_current->last_level;
5680 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5681 new_level_nr = leveldir_current->handicap_level;
5683 if (new_level_nr != old_level_nr)
5685 PlaySound(SND_MENU_ITEM_SELECTING);
5687 scores.last_level_nr = level_nr = new_level_nr;
5688 scores.last_entry_nr = 0;
5690 LoadLevel(level_nr);
5691 LoadLocalAndServerScore(level_nr, TRUE);
5693 DrawHallOfFame_setScoreEntries();
5695 if (game_status == GAME_MODE_SCORES)
5697 // force remapping optional gadgets (especially scroll bar)
5698 UnmapScreenTreeGadgets();
5700 // redraw complete high score screen, as sub-title has changed
5703 // redraw level selection buttons (which have just been erased)
5704 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5706 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5710 DrawScoreInfo_Content(scores.last_entry_nr);
5713 SaveLevelSetup_SeriesInfo();
5717 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5719 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5722 static void DrawScoreInfo_Content(int entry_nr)
5724 struct ScoreEntry *entry = &scores.entry[entry_nr];
5725 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5726 int font_title = MENU_INFO_FONT_TITLE;
5727 int font_head = MENU_INFO_FONT_HEAD;
5728 int font_text = MENU_INFO_FONT_TEXT;
5729 int font_foot = MENU_INFO_FONT_FOOT;
5730 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5731 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5732 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5733 int xstep = getFontWidth(font_text);
5734 int ystep_title = getMenuTextStep(spacing_title, font_title);
5735 int ystep_para = getMenuTextStep(spacing_para, font_text);
5736 int ystep_line = getMenuTextStep(spacing_line, font_text);
5737 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5738 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5739 int xstart1 = mSX - SX + 2 * xstep;
5740 int xstart2 = mSX - SX + 13 * xstep;
5741 int button_x = SX + xstart1;
5742 int button_y1, button_y2;
5743 int font_width = getFontWidth(font_text);
5744 int font_height = getFontHeight(font_text);
5745 int pad_left = xstart2;
5746 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
5747 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5748 int max_lines_per_text = 5;
5753 // redraw score selection buttons (which have just been erased)
5754 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5756 if (score_entries == NULL)
5758 drawChooseTreeScreen_Scores_NotAvailable();
5763 drawChooseTreeHead(score_entries);
5764 drawChooseTreeInfo(score_entries);
5766 DrawTextSCentered(ystart, font_title, "Score Information:");
5767 ystart += ystep_title;
5769 DrawTextF(xstart1, ystart, font_head, "Level Set");
5770 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5771 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5772 TRUE, FALSE, FALSE);
5773 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5775 DrawTextF(xstart1, ystart, font_head, "Level");
5776 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5777 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5778 TRUE, FALSE, FALSE);
5779 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5781 button_y1 = SY + ystart;
5782 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5784 DrawTextF(xstart1, ystart, font_head, "Rank");
5785 DrawTextF(xstart2, ystart, font_text, pos_text);
5786 ystart += ystep_line;
5788 DrawTextF(xstart1, ystart, font_head, "Player");
5789 DrawTextF(xstart2, ystart, font_text, entry->name);
5790 ystart += ystep_line;
5792 if (level.use_step_counter)
5794 DrawTextF(xstart1, ystart, font_head, "Steps");
5795 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5796 ystart += ystep_line;
5800 DrawTextF(xstart1, ystart, font_head, "Time");
5801 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5802 ystart += ystep_line;
5805 if (!level.rate_time_over_score || entry->score > 0)
5807 DrawTextF(xstart1, ystart, font_head, "Score");
5808 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5809 ystart += ystep_line;
5812 ystart += ystep_line;
5814 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5815 DrawTextF(xstart2, ystart, font_text, entry->tape_date);
5816 ystart += ystep_line;
5818 DrawTextF(xstart1, ystart, font_head, "Platform");
5819 DrawTextF(xstart2, ystart, font_text, entry->platform);
5820 ystart += ystep_line;
5822 DrawTextF(xstart1, ystart, font_head, "Version");
5823 DrawTextF(xstart2, ystart, font_text, entry->version);
5824 ystart += ystep_line;
5826 DrawTextF(xstart1, ystart, font_head, "Country");
5827 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5828 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5829 TRUE, FALSE, FALSE);
5830 ystart += ystep_line;
5832 button_y2 = SY + ystart;
5834 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5836 AdjustScoreInfoButtons(button_x, button_y1, button_y2);
5839 static void DrawScoreInfo(int entry_nr)
5841 scores.last_entry_nr = entry_nr;
5843 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5847 FadeOut(REDRAW_FIELD);
5849 DrawScoreInfo_Content(entry_nr);
5851 // map gadgets for score info screen
5852 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5854 FadeIn(REDRAW_FIELD);
5857 static void HandleScoreInfo_SelectScore(int step, int direction)
5859 int old_entry_nr = scores.last_entry_nr;
5860 int new_entry_nr = old_entry_nr + step * direction;
5861 int num_nodes = numTreeInfoInGroup(score_entry_current);
5862 int num_entries = num_nodes - 1; // score nodes only, without back link
5864 if (new_entry_nr < 0)
5866 if (new_entry_nr > num_entries - 1)
5867 new_entry_nr = num_entries - 1;
5869 if (new_entry_nr != old_entry_nr)
5871 scores.last_entry_nr = new_entry_nr;
5873 DrawScoreInfo_Content(new_entry_nr);
5877 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5879 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5880 boolean button_is_valid = (mx >= 0 && my >= 0);
5881 boolean button_screen_clicked = (button_action && button_is_valid);
5883 if (server_scores.updated)
5885 // reload scores, using updated server score cache file
5886 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5888 server_scores.updated = FALSE;
5890 DrawHallOfFame_setScoreEntries();
5892 DrawScoreInfo_Content(scores.last_entry_nr);
5895 if (button_screen_clicked)
5897 PlaySound(SND_MENU_ITEM_SELECTING);
5899 SetGameStatus(GAME_MODE_SCORES);
5901 DrawHallOfFame(level_nr);
5905 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5909 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5914 // ============================================================================
5915 // setup screen functions
5916 // ============================================================================
5918 static struct TokenInfo *setup_info;
5919 static int num_setup_info; // number of setup entries shown on screen
5920 static int max_setup_info; // total number of setup entries in list
5922 static char *window_size_text;
5923 static char *scaling_type_text;
5924 static char *rendering_mode_text;
5925 static char *vsync_mode_text;
5926 static char *scroll_delay_text;
5927 static char *snapshot_mode_text;
5928 static char *game_speed_text;
5929 static char *scores_type_text;
5930 static char *network_server_text;
5931 static char *graphics_set_name;
5932 static char *sounds_set_name;
5933 static char *music_set_name;
5934 static char *volume_simple_text;
5935 static char *volume_loops_text;
5936 static char *volume_music_text;
5937 static char *touch_controls_text;
5938 static char *move_distance_text;
5939 static char *drop_distance_text;
5940 static char *transparency_text;
5941 static char *grid_size_text[2][2];
5943 static void execSetupMain(void)
5945 setup_mode = SETUP_MODE_MAIN;
5950 static void execSetupGame_setScoresType(void)
5952 if (scores_types == NULL)
5956 for (i = 0; scores_types_list[i].value != NULL; i++)
5958 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5959 char identifier[32], name[32];
5960 char *value = scores_types_list[i].value;
5961 char *text = scores_types_list[i].text;
5963 ti->node_top = &scores_types;
5964 ti->sort_priority = i;
5966 sprintf(identifier, "%s", value);
5967 sprintf(name, "%s", text);
5969 setString(&ti->identifier, identifier);
5970 setString(&ti->name, name);
5971 setString(&ti->name_sorting, name);
5972 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5974 pushTreeInfo(&scores_types, ti);
5977 // sort scores type values to start with lowest scores type value
5978 sortTreeInfo(&scores_types);
5980 // set current scores type value to configured scores type value
5981 scores_type_current =
5982 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5984 // if that fails, set current scores type to reliable default value
5985 if (scores_type_current == NULL)
5986 scores_type_current =
5987 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5989 // if that also fails, set current scores type to first available value
5990 if (scores_type_current == NULL)
5991 scores_type_current = scores_types;
5994 setup.scores_in_highscore_list = scores_type_current->identifier;
5996 // needed for displaying scores type text instead of identifier
5997 scores_type_text = scores_type_current->name;
6000 static void execSetupGame_setGameSpeeds(boolean update_value)
6002 if (setup.game_speed_extended)
6004 game_speeds_list = game_speeds_list_extended;
6005 game_speeds = game_speeds_extended;
6009 game_speeds_list = game_speeds_list_normal;
6010 game_speeds = game_speeds_normal;
6013 if (game_speeds == NULL)
6017 for (i = 0; game_speeds_list[i].value != -1; i++)
6019 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6020 char identifier[32], name[32];
6021 int value = game_speeds_list[i].value;
6022 char *text = game_speeds_list[i].text;
6024 ti->node_top = &game_speeds;
6025 ti->sort_priority = 10000 - value;
6027 sprintf(identifier, "%d", value);
6028 sprintf(name, "%s", text);
6030 setString(&ti->identifier, identifier);
6031 setString(&ti->name, name);
6032 setString(&ti->name_sorting, name);
6033 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
6035 pushTreeInfo(&game_speeds, ti);
6038 // sort game speed values to start with slowest game speed
6039 sortTreeInfo(&game_speeds);
6041 update_value = TRUE;
6046 // set current game speed to configured game speed value
6047 game_speed_current =
6048 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6050 // if that fails, set current game speed to reliable default value
6051 if (game_speed_current == NULL)
6052 game_speed_current =
6053 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6055 // if that also fails, set current game speed to first available speed
6056 if (game_speed_current == NULL)
6057 game_speed_current = game_speeds;
6059 if (setup.game_speed_extended)
6060 game_speeds_extended = game_speeds;
6062 game_speeds_normal = game_speeds;
6065 setup.game_frame_delay = atoi(game_speed_current->identifier);
6067 // needed for displaying game speed text instead of identifier
6068 game_speed_text = game_speed_current->name;
6071 static void execSetupGame_setScrollDelays(void)
6073 if (scroll_delays == NULL)
6077 for (i = 0; scroll_delays_list[i].value != -1; i++)
6079 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6080 char identifier[32], name[32];
6081 int value = scroll_delays_list[i].value;
6082 char *text = scroll_delays_list[i].text;
6084 ti->node_top = &scroll_delays;
6085 ti->sort_priority = value;
6087 sprintf(identifier, "%d", value);
6088 sprintf(name, "%s", text);
6090 setString(&ti->identifier, identifier);
6091 setString(&ti->name, name);
6092 setString(&ti->name_sorting, name);
6093 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6095 pushTreeInfo(&scroll_delays, ti);
6098 // sort scroll delay values to start with lowest scroll delay value
6099 sortTreeInfo(&scroll_delays);
6101 // set current scroll delay value to configured scroll delay value
6102 scroll_delay_current =
6103 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6105 // if that fails, set current scroll delay to reliable default value
6106 if (scroll_delay_current == NULL)
6107 scroll_delay_current =
6108 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6110 // if that also fails, set current scroll delay to first available value
6111 if (scroll_delay_current == NULL)
6112 scroll_delay_current = scroll_delays;
6115 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6117 // needed for displaying scroll delay text instead of identifier
6118 scroll_delay_text = scroll_delay_current->name;
6121 static void execSetupGame_setSnapshotModes(void)
6123 if (snapshot_modes == NULL)
6127 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6129 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6130 char identifier[32], name[32];
6131 char *value = snapshot_modes_list[i].value;
6132 char *text = snapshot_modes_list[i].text;
6134 ti->node_top = &snapshot_modes;
6135 ti->sort_priority = i;
6137 sprintf(identifier, "%s", value);
6138 sprintf(name, "%s", text);
6140 setString(&ti->identifier, identifier);
6141 setString(&ti->name, name);
6142 setString(&ti->name_sorting, name);
6143 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6145 pushTreeInfo(&snapshot_modes, ti);
6148 // sort snapshot mode values to start with lowest snapshot mode value
6149 sortTreeInfo(&snapshot_modes);
6151 // set current snapshot mode value to configured snapshot mode value
6152 snapshot_mode_current =
6153 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6155 // if that fails, set current snapshot mode to reliable default value
6156 if (snapshot_mode_current == NULL)
6157 snapshot_mode_current =
6158 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6160 // if that also fails, set current snapshot mode to first available value
6161 if (snapshot_mode_current == NULL)
6162 snapshot_mode_current = snapshot_modes;
6165 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6167 // needed for displaying snapshot mode text instead of identifier
6168 snapshot_mode_text = snapshot_mode_current->name;
6171 static void execSetupGame_setNetworkServerText(void)
6173 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6175 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6179 strncpy(network_server_hostname, setup.network_server_hostname,
6180 MAX_SETUP_TEXT_INPUT_LEN);
6181 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6184 // needed for displaying network server text instead of identifier
6185 network_server_text = network_server_hostname;
6188 static void execSetupGame(void)
6190 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6192 execSetupGame_setGameSpeeds(FALSE);
6193 execSetupGame_setScoresType();
6194 execSetupGame_setScrollDelays();
6195 execSetupGame_setSnapshotModes();
6197 execSetupGame_setNetworkServerText();
6199 if (!setup.provide_uploading_tapes)
6200 setHideSetupEntry(execOfferUploadTapes);
6202 setup_mode = SETUP_MODE_GAME;
6206 // check if vsync needs to be disabled for this game speed to work
6207 if (check_vsync_mode)
6208 DisableVsyncIfNeeded();
6211 static void execSetupChooseScoresType(void)
6213 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6218 static void execSetupChooseGameSpeed(void)
6220 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6225 static void execSetupChooseScrollDelay(void)
6227 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6232 static void execSetupChooseSnapshotMode(void)
6234 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6239 static void execSetupEngines(void)
6241 setup_mode = SETUP_MODE_ENGINES;
6246 static void execSetupEditor(void)
6248 setup_mode = SETUP_MODE_EDITOR;
6253 static void execSetupGraphics_setWindowSizes(boolean update_list)
6255 if (window_sizes != NULL && update_list)
6257 freeTreeInfo(window_sizes);
6259 window_sizes = NULL;
6262 if (window_sizes == NULL)
6264 boolean current_window_size_found = FALSE;
6267 for (i = 0; window_sizes_list[i].value != -1; i++)
6269 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6270 char identifier[32], name[32];
6271 int value = window_sizes_list[i].value;
6272 char *text = window_sizes_list[i].text;
6274 ti->node_top = &window_sizes;
6275 ti->sort_priority = value;
6277 sprintf(identifier, "%d", value);
6278 sprintf(name, "%s", text);
6280 setString(&ti->identifier, identifier);
6281 setString(&ti->name, name);
6282 setString(&ti->name_sorting, name);
6283 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6285 pushTreeInfo(&window_sizes, ti);
6287 if (value == setup.window_scaling_percent)
6288 current_window_size_found = TRUE;
6291 if (!current_window_size_found)
6293 // add entry for non-preset window scaling value
6295 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6296 char identifier[32], name[32];
6297 int value = setup.window_scaling_percent;
6299 ti->node_top = &window_sizes;
6300 ti->sort_priority = value;
6302 sprintf(identifier, "%d", value);
6303 sprintf(name, "%d %% (Current)", value);
6305 setString(&ti->identifier, identifier);
6306 setString(&ti->name, name);
6307 setString(&ti->name_sorting, name);
6308 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6310 pushTreeInfo(&window_sizes, ti);
6313 // sort window size values to start with lowest window size value
6314 sortTreeInfo(&window_sizes);
6316 // set current window size value to configured window size value
6317 window_size_current =
6318 getTreeInfoFromIdentifier(window_sizes,
6319 i_to_a(setup.window_scaling_percent));
6321 // if that fails, set current window size to reliable default value
6322 if (window_size_current == NULL)
6323 window_size_current =
6324 getTreeInfoFromIdentifier(window_sizes,
6325 i_to_a(STD_WINDOW_SCALING_PERCENT));
6327 // if that also fails, set current window size to first available value
6328 if (window_size_current == NULL)
6329 window_size_current = window_sizes;
6332 setup.window_scaling_percent = atoi(window_size_current->identifier);
6334 // needed for displaying window size text instead of identifier
6335 window_size_text = window_size_current->name;
6338 static void execSetupGraphics_setScalingTypes(void)
6340 if (scaling_types == NULL)
6344 for (i = 0; scaling_types_list[i].value != NULL; i++)
6346 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6347 char identifier[32], name[32];
6348 char *value = scaling_types_list[i].value;
6349 char *text = scaling_types_list[i].text;
6351 ti->node_top = &scaling_types;
6352 ti->sort_priority = i;
6354 sprintf(identifier, "%s", value);
6355 sprintf(name, "%s", text);
6357 setString(&ti->identifier, identifier);
6358 setString(&ti->name, name);
6359 setString(&ti->name_sorting, name);
6360 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6362 pushTreeInfo(&scaling_types, ti);
6365 // sort scaling type values to start with lowest scaling type value
6366 sortTreeInfo(&scaling_types);
6368 // set current scaling type value to configured scaling type value
6369 scaling_type_current =
6370 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6372 // if that fails, set current scaling type to reliable default value
6373 if (scaling_type_current == NULL)
6374 scaling_type_current =
6375 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6377 // if that also fails, set current scaling type to first available value
6378 if (scaling_type_current == NULL)
6379 scaling_type_current = scaling_types;
6382 setup.window_scaling_quality = scaling_type_current->identifier;
6384 // needed for displaying scaling type text instead of identifier
6385 scaling_type_text = scaling_type_current->name;
6388 static void execSetupGraphics_setRenderingModes(void)
6390 if (rendering_modes == NULL)
6394 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6396 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6397 char identifier[32], name[32];
6398 char *value = rendering_modes_list[i].value;
6399 char *text = rendering_modes_list[i].text;
6401 ti->node_top = &rendering_modes;
6402 ti->sort_priority = i;
6404 sprintf(identifier, "%s", value);
6405 sprintf(name, "%s", text);
6407 setString(&ti->identifier, identifier);
6408 setString(&ti->name, name);
6409 setString(&ti->name_sorting, name);
6410 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6412 pushTreeInfo(&rendering_modes, ti);
6415 // sort rendering mode values to start with lowest rendering mode value
6416 sortTreeInfo(&rendering_modes);
6418 // set current rendering mode value to configured rendering mode value
6419 rendering_mode_current =
6420 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6422 // if that fails, set current rendering mode to reliable default value
6423 if (rendering_mode_current == NULL)
6424 rendering_mode_current =
6425 getTreeInfoFromIdentifier(rendering_modes,
6426 STR_SPECIAL_RENDERING_DEFAULT);
6428 // if that also fails, set current rendering mode to first available one
6429 if (rendering_mode_current == NULL)
6430 rendering_mode_current = rendering_modes;
6433 setup.screen_rendering_mode = rendering_mode_current->identifier;
6435 // needed for displaying rendering mode text instead of identifier
6436 rendering_mode_text = rendering_mode_current->name;
6439 static void execSetupGraphics_setVsyncModes(boolean update_value)
6441 if (vsync_modes == NULL)
6445 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6447 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6448 char identifier[32], name[32];
6449 char *value = vsync_modes_list[i].value;
6450 char *text = vsync_modes_list[i].text;
6452 ti->node_top = &vsync_modes;
6453 ti->sort_priority = i;
6455 sprintf(identifier, "%s", value);
6456 sprintf(name, "%s", text);
6458 setString(&ti->identifier, identifier);
6459 setString(&ti->name, name);
6460 setString(&ti->name_sorting, name);
6461 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6463 pushTreeInfo(&vsync_modes, ti);
6466 // sort vsync mode values to start with lowest vsync mode value
6467 sortTreeInfo(&vsync_modes);
6469 update_value = TRUE;
6474 // set current vsync mode value to configured vsync mode value
6475 vsync_mode_current =
6476 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6478 // if that fails, set current vsync mode to reliable default value
6479 if (vsync_mode_current == NULL)
6480 vsync_mode_current =
6481 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6483 // if that also fails, set current vsync mode to first available one
6484 if (vsync_mode_current == NULL)
6485 vsync_mode_current = vsync_modes;
6488 setup.vsync_mode = vsync_mode_current->identifier;
6490 // needed for displaying vsync mode text instead of identifier
6491 vsync_mode_text = vsync_mode_current->name;
6494 static void execSetupGraphics(void)
6496 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6498 // update "setup.window_scaling_percent" from list selection
6499 // (in this case, window scaling was changed on setup screen)
6500 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6501 execSetupGraphics_setWindowSizes(FALSE);
6503 // update "setup.vsync_mode" from list selection
6504 // (in this case, vsync mode was changed on setup screen)
6505 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6506 execSetupGraphics_setVsyncModes(FALSE);
6508 // update list selection from "setup.window_scaling_percent"
6509 // (window scaling may have changed by resizing the window)
6510 execSetupGraphics_setWindowSizes(TRUE);
6512 // update list selection from "setup.vsync_mode"
6513 // (vsync_mode may have changed by re-creating the renderer)
6514 execSetupGraphics_setVsyncModes(TRUE);
6516 execSetupGraphics_setScalingTypes();
6517 execSetupGraphics_setRenderingModes();
6519 setup_mode = SETUP_MODE_GRAPHICS;
6523 // check if game speed is high enough for 60 Hz vsync to work
6524 if (check_game_speed)
6525 ModifyGameSpeedIfNeeded();
6527 // window scaling may have changed at this point
6528 ChangeWindowScalingIfNeeded();
6530 // window scaling quality may have changed at this point
6531 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6532 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6534 // screen rendering mode may have changed at this point
6535 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6537 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6538 int video_vsync_mode = video.vsync_mode;
6540 // screen vsync mode may have changed at this point
6541 ChangeVsyncModeIfNeeded();
6543 // check if setting vsync mode to selected value failed
6544 if (setup_vsync_mode != video_vsync_mode &&
6545 setup_vsync_mode != video.vsync_mode)
6547 // changing vsync mode to selected value failed -- reset displayed value
6548 execSetupGraphics_setVsyncModes(TRUE);
6550 Request("Setting VSync failed!", REQ_CONFIRM);
6556 static void execSetupChooseWindowSize(void)
6558 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6563 static void execSetupChooseScalingType(void)
6565 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6570 static void execSetupChooseRenderingMode(void)
6572 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6577 static void execSetupChooseVsyncMode(void)
6579 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6584 static void execSetupChooseVolumeSimple(void)
6586 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6591 static void execSetupChooseVolumeLoops(void)
6593 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6598 static void execSetupChooseVolumeMusic(void)
6600 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6605 static void execSetupSound(void)
6607 if (volumes_simple == NULL)
6609 boolean current_volume_simple_found = FALSE;
6612 for (i = 0; volumes_list[i].value != -1; i++)
6614 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6615 char identifier[32], name[32];
6616 int value = volumes_list[i].value;
6617 char *text = volumes_list[i].text;
6619 ti->node_top = &volumes_simple;
6620 ti->sort_priority = value;
6622 sprintf(identifier, "%d", value);
6623 sprintf(name, "%s", text);
6625 setString(&ti->identifier, identifier);
6626 setString(&ti->name, name);
6627 setString(&ti->name_sorting, name);
6628 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6630 pushTreeInfo(&volumes_simple, ti);
6632 if (value == setup.volume_simple)
6633 current_volume_simple_found = TRUE;
6636 if (!current_volume_simple_found)
6638 // add entry for non-preset volume value
6640 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6641 char identifier[32], name[32];
6642 int value = setup.volume_simple;
6644 ti->node_top = &volumes_simple;
6645 ti->sort_priority = value;
6647 sprintf(identifier, "%d", value);
6648 sprintf(name, "%d %% (Current)", value);
6650 setString(&ti->identifier, identifier);
6651 setString(&ti->name, name);
6652 setString(&ti->name_sorting, name);
6653 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6655 pushTreeInfo(&volumes_simple, ti);
6658 // sort volume values to start with lowest volume value
6659 sortTreeInfo(&volumes_simple);
6661 // set current volume value to configured volume value
6662 volume_simple_current =
6663 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6665 // if that fails, set current volume to reliable default value
6666 if (volume_simple_current == NULL)
6667 volume_simple_current =
6668 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6670 // if that also fails, set current volume to first available value
6671 if (volume_simple_current == NULL)
6672 volume_simple_current = volumes_simple;
6675 if (volumes_loops == NULL)
6677 boolean current_volume_loops_found = FALSE;
6680 for (i = 0; volumes_list[i].value != -1; i++)
6682 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6683 char identifier[32], name[32];
6684 int value = volumes_list[i].value;
6685 char *text = volumes_list[i].text;
6687 ti->node_top = &volumes_loops;
6688 ti->sort_priority = value;
6690 sprintf(identifier, "%d", value);
6691 sprintf(name, "%s", text);
6693 setString(&ti->identifier, identifier);
6694 setString(&ti->name, name);
6695 setString(&ti->name_sorting, name);
6696 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6698 pushTreeInfo(&volumes_loops, ti);
6700 if (value == setup.volume_loops)
6701 current_volume_loops_found = TRUE;
6704 if (!current_volume_loops_found)
6706 // add entry for non-preset volume value
6708 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6709 char identifier[32], name[32];
6710 int value = setup.volume_loops;
6712 ti->node_top = &volumes_loops;
6713 ti->sort_priority = value;
6715 sprintf(identifier, "%d", value);
6716 sprintf(name, "%d %% (Current)", value);
6718 setString(&ti->identifier, identifier);
6719 setString(&ti->name, name);
6720 setString(&ti->name_sorting, name);
6721 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6723 pushTreeInfo(&volumes_loops, ti);
6726 // sort volume values to start with lowest volume value
6727 sortTreeInfo(&volumes_loops);
6729 // set current volume value to configured volume value
6730 volume_loops_current =
6731 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6733 // if that fails, set current volume to reliable default value
6734 if (volume_loops_current == NULL)
6735 volume_loops_current =
6736 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6738 // if that also fails, set current volume to first available value
6739 if (volume_loops_current == NULL)
6740 volume_loops_current = volumes_loops;
6743 if (volumes_music == NULL)
6745 boolean current_volume_music_found = FALSE;
6748 for (i = 0; volumes_list[i].value != -1; i++)
6750 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6751 char identifier[32], name[32];
6752 int value = volumes_list[i].value;
6753 char *text = volumes_list[i].text;
6755 ti->node_top = &volumes_music;
6756 ti->sort_priority = value;
6758 sprintf(identifier, "%d", value);
6759 sprintf(name, "%s", text);
6761 setString(&ti->identifier, identifier);
6762 setString(&ti->name, name);
6763 setString(&ti->name_sorting, name);
6764 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6766 pushTreeInfo(&volumes_music, ti);
6768 if (value == setup.volume_music)
6769 current_volume_music_found = TRUE;
6772 if (!current_volume_music_found)
6774 // add entry for non-preset volume value
6776 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6777 char identifier[32], name[32];
6778 int value = setup.volume_music;
6780 ti->node_top = &volumes_music;
6781 ti->sort_priority = value;
6783 sprintf(identifier, "%d", value);
6784 sprintf(name, "%d %% (Current)", value);
6786 setString(&ti->identifier, identifier);
6787 setString(&ti->name, name);
6788 setString(&ti->name_sorting, name);
6789 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6791 pushTreeInfo(&volumes_music, ti);
6794 // sort volume values to start with lowest volume value
6795 sortTreeInfo(&volumes_music);
6797 // set current volume value to configured volume value
6798 volume_music_current =
6799 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6801 // if that fails, set current volume to reliable default value
6802 if (volume_music_current == NULL)
6803 volume_music_current =
6804 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6806 // if that also fails, set current volume to first available value
6807 if (volume_music_current == NULL)
6808 volume_music_current = volumes_music;
6811 setup.volume_simple = atoi(volume_simple_current->identifier);
6812 setup.volume_loops = atoi(volume_loops_current->identifier);
6813 setup.volume_music = atoi(volume_music_current->identifier);
6815 // needed for displaying volume text instead of identifier
6816 volume_simple_text = volume_simple_current->name;
6817 volume_loops_text = volume_loops_current->name;
6818 volume_music_text = volume_music_current->name;
6820 setup_mode = SETUP_MODE_SOUND;
6825 static void execSetupChooseTouchControls(void)
6827 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6832 static void execSetupChooseMoveDistance(void)
6834 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6839 static void execSetupChooseDropDistance(void)
6841 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6846 static void execSetupChooseTransparency(void)
6848 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6853 static void execSetupChooseGridXSize_0(void)
6855 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6860 static void execSetupChooseGridYSize_0(void)
6862 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6867 static void execSetupChooseGridXSize_1(void)
6869 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6874 static void execSetupChooseGridYSize_1(void)
6876 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6881 static void execSetupConfigureVirtualButtons(void)
6883 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6885 ConfigureVirtualButtons();
6887 setup_mode = SETUP_MODE_TOUCH;
6892 static void execSetupTouch(void)
6896 if (touch_controls == NULL)
6898 for (i = 0; touch_controls_list[i].value != NULL; i++)
6900 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6901 char identifier[32], name[32];
6902 char *value = touch_controls_list[i].value;
6903 char *text = touch_controls_list[i].text;
6905 ti->node_top = &touch_controls;
6906 ti->sort_priority = i;
6908 sprintf(identifier, "%s", value);
6909 sprintf(name, "%s", text);
6911 setString(&ti->identifier, identifier);
6912 setString(&ti->name, name);
6913 setString(&ti->name_sorting, name);
6914 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6916 pushTreeInfo(&touch_controls, ti);
6919 // sort touch control values to start with lowest touch control value
6920 sortTreeInfo(&touch_controls);
6922 // set current touch control value to configured touch control value
6923 touch_control_current =
6924 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6926 // if that fails, set current touch control to reliable default value
6927 if (touch_control_current == NULL)
6928 touch_control_current =
6929 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6931 // if that also fails, set current touch control to first available value
6932 if (touch_control_current == NULL)
6933 touch_control_current = touch_controls;
6936 if (move_distances == NULL)
6938 for (i = 0; distances_list[i].value != -1; i++)
6940 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6941 char identifier[32], name[32];
6942 int value = distances_list[i].value;
6943 char *text = distances_list[i].text;
6945 ti->node_top = &move_distances;
6946 ti->sort_priority = value;
6948 sprintf(identifier, "%d", value);
6949 sprintf(name, "%s", text);
6951 setString(&ti->identifier, identifier);
6952 setString(&ti->name, name);
6953 setString(&ti->name_sorting, name);
6954 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6956 pushTreeInfo(&move_distances, ti);
6959 // sort distance values to start with lowest distance value
6960 sortTreeInfo(&move_distances);
6962 // set current distance value to configured distance value
6963 move_distance_current =
6964 getTreeInfoFromIdentifier(move_distances,
6965 i_to_a(setup.touch.move_distance));
6967 // if that fails, set current distance to reliable default value
6968 if (move_distance_current == NULL)
6969 move_distance_current =
6970 getTreeInfoFromIdentifier(move_distances,
6971 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6973 // if that also fails, set current distance to first available value
6974 if (move_distance_current == NULL)
6975 move_distance_current = move_distances;
6978 if (drop_distances == NULL)
6980 for (i = 0; distances_list[i].value != -1; i++)
6982 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6983 char identifier[32], name[32];
6984 int value = distances_list[i].value;
6985 char *text = distances_list[i].text;
6987 ti->node_top = &drop_distances;
6988 ti->sort_priority = value;
6990 sprintf(identifier, "%d", value);
6991 sprintf(name, "%s", text);
6993 setString(&ti->identifier, identifier);
6994 setString(&ti->name, name);
6995 setString(&ti->name_sorting, name);
6996 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6998 pushTreeInfo(&drop_distances, ti);
7001 // sort distance values to start with lowest distance value
7002 sortTreeInfo(&drop_distances);
7004 // set current distance value to configured distance value
7005 drop_distance_current =
7006 getTreeInfoFromIdentifier(drop_distances,
7007 i_to_a(setup.touch.drop_distance));
7009 // if that fails, set current distance to reliable default value
7010 if (drop_distance_current == NULL)
7011 drop_distance_current =
7012 getTreeInfoFromIdentifier(drop_distances,
7013 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
7015 // if that also fails, set current distance to first available value
7016 if (drop_distance_current == NULL)
7017 drop_distance_current = drop_distances;
7020 if (transparencies == NULL)
7022 for (i = 0; transparencies_list[i].value != -1; i++)
7024 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7025 char identifier[32], name[32];
7026 int value = transparencies_list[i].value;
7027 char *text = transparencies_list[i].text;
7029 ti->node_top = &transparencies;
7030 ti->sort_priority = value;
7032 sprintf(identifier, "%d", value);
7033 sprintf(name, "%s", text);
7035 setString(&ti->identifier, identifier);
7036 setString(&ti->name, name);
7037 setString(&ti->name_sorting, name);
7038 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
7040 pushTreeInfo(&transparencies, ti);
7043 // sort transparency values to start with lowest transparency value
7044 sortTreeInfo(&transparencies);
7046 // set current transparency value to configured transparency value
7047 transparency_current =
7048 getTreeInfoFromIdentifier(transparencies,
7049 i_to_a(setup.touch.transparency));
7051 // if that fails, set current transparency to reliable default value
7052 if (transparency_current == NULL)
7053 transparency_current =
7054 getTreeInfoFromIdentifier(transparencies,
7055 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7057 // if that also fails, set current transparency to first available value
7058 if (transparency_current == NULL)
7059 transparency_current = transparencies;
7062 for (i = 0; i < 2; i++)
7064 for (j = 0; j < 2; j++)
7066 if (grid_sizes[i][j] == NULL)
7068 for (k = 0; grid_sizes_list[k].value != -1; k++)
7070 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7071 char identifier[32], name[32];
7072 int value = grid_sizes_list[k].value;
7073 char *text = grid_sizes_list[k].text;
7075 ti->node_top = &grid_sizes[i][j];
7076 ti->sort_priority = value;
7078 sprintf(identifier, "%d", value);
7079 sprintf(name, "%s", text);
7081 setString(&ti->identifier, identifier);
7082 setString(&ti->name, name);
7083 setString(&ti->name_sorting, name);
7084 setString(&ti->infotext,
7087 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7088 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7090 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7091 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7093 pushTreeInfo(&grid_sizes[i][j], ti);
7096 // sort grid size values to start with lowest grid size value
7097 sortTreeInfo(&grid_sizes[i][j]);
7099 // set current grid size value to configured grid size value
7100 grid_size_current[i][j] =
7101 getTreeInfoFromIdentifier(grid_sizes[i][j],
7103 setup.touch.grid_xsize[i] :
7104 setup.touch.grid_ysize[i]));
7106 // if that fails, set current grid size to reliable default value
7107 if (grid_size_current[i][j] == NULL)
7108 grid_size_current[i][j] =
7109 getTreeInfoFromIdentifier(grid_sizes[i][j],
7111 DEFAULT_GRID_XSIZE(i) :
7112 DEFAULT_GRID_YSIZE(i)));
7114 // if that also fails, set current grid size to first available value
7115 if (grid_size_current[i][j] == NULL)
7116 grid_size_current[i][j] = grid_sizes[i][j];
7121 setup.touch.control_type = touch_control_current->identifier;
7122 setup.touch.move_distance = atoi(move_distance_current->identifier);
7123 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7124 setup.touch.transparency = atoi(transparency_current->identifier);
7126 for (i = 0; i < 2; i++)
7128 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7129 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7131 if (i == GRID_ACTIVE_NR())
7133 overlay.grid_xsize = setup.touch.grid_xsize[i];
7134 overlay.grid_ysize = setup.touch.grid_ysize[i];
7138 // needed for displaying value text instead of identifier
7139 touch_controls_text = touch_control_current->name;
7140 move_distance_text = move_distance_current->name;
7141 drop_distance_text = drop_distance_current->name;
7142 transparency_text = transparency_current->name;
7144 for (i = 0; i < 2; i++)
7145 for (j = 0; j < 2; j++)
7146 grid_size_text[i][j] = grid_size_current[i][j]->name;
7148 setup_mode = SETUP_MODE_TOUCH;
7153 static void execSetupArtwork(void)
7155 static ArtworkDirTree *gfx_last_valid = NULL;
7156 static ArtworkDirTree *snd_last_valid = NULL;
7157 static ArtworkDirTree *mus_last_valid = NULL;
7159 // current artwork directory may be invalid (level group, parent link)
7160 if (!validLevelSeries(artwork.gfx_current))
7161 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7162 if (!validLevelSeries(artwork.snd_current))
7163 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7164 if (!validLevelSeries(artwork.mus_current))
7165 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7167 // store valid artwork directory information
7168 gfx_last_valid = artwork.gfx_current;
7169 snd_last_valid = artwork.snd_current;
7170 mus_last_valid = artwork.mus_current;
7173 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7174 artwork.gfx_current->subdir,
7175 artwork.gfx_current->fullpath,
7176 artwork.gfx_current->basepath);
7179 setup.graphics_set = artwork.gfx_current->identifier;
7180 setup.sounds_set = artwork.snd_current->identifier;
7181 setup.music_set = artwork.mus_current->identifier;
7183 // needed if last screen (setup choice) changed graphics, sounds or music
7184 ReloadCustomArtwork(0);
7186 // needed for displaying artwork name instead of artwork identifier
7187 graphics_set_name = artwork.gfx_current->name;
7188 sounds_set_name = artwork.snd_current->name;
7189 music_set_name = artwork.mus_current->name;
7191 setup_mode = SETUP_MODE_ARTWORK;
7196 static void execSetupChooseGraphics(void)
7198 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7203 static void execSetupChooseSounds(void)
7205 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7210 static void execSetupChooseMusic(void)
7212 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7217 static void execSetupInput(void)
7219 setup_mode = SETUP_MODE_INPUT;
7224 static void execSetupShortcuts(void)
7226 setup_mode = SETUP_MODE_SHORTCUTS;
7231 static void execSetupShortcuts1(void)
7233 setup_mode = SETUP_MODE_SHORTCUTS_1;
7238 static void execSetupShortcuts2(void)
7240 setup_mode = SETUP_MODE_SHORTCUTS_2;
7245 static void execSetupShortcuts3(void)
7247 setup_mode = SETUP_MODE_SHORTCUTS_3;
7252 static void execSetupShortcuts4(void)
7254 setup_mode = SETUP_MODE_SHORTCUTS_4;
7259 static void execSetupShortcuts5(void)
7261 setup_mode = SETUP_MODE_SHORTCUTS_5;
7266 static void execExitSetup(void)
7268 SetGameStatus(GAME_MODE_MAIN);
7273 static void execSaveAndExitSetup(void)
7279 static void execGadgetNetworkServer(void)
7281 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7282 struct GadgetInfo *gi = screen_gadget[gadget_id];
7284 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7285 network_server_hostname[0] = '\0';
7287 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7291 ClickOnGadget(gi, MB_LEFTBUTTON);
7294 static void execOfferUploadTapes(void)
7299 static void ToggleNetworkModeIfNeeded(void)
7301 int font_title = FONT_TITLE_1;
7302 int font_foot = FC_BLUE;
7303 int ystart = mSY - SY + 16;
7304 int ybottom = mSY - SY + SYSIZE - 20;
7305 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7307 if (setup.network_mode == network.enabled)
7310 network.enabled = setup.network_mode;
7312 FadeOut(REDRAW_ALL);
7316 DrawTextSCentered(ystart, font_title, text);
7320 if (network.enabled)
7321 InitNetworkServer();
7323 DisconnectFromNetworkServer();
7325 DrawTextSCentered(ybottom, font_foot,
7326 "Press any key or button for setup menu");
7328 WaitForEventToContinue();
7333 static void ToggleGameSpeedsListIfNeeded(void)
7335 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7337 if (setup.game_speed_extended == using_game_speeds_extended)
7340 // try to match similar values when changing game speeds list
7341 if (setup.game_speed_extended)
7342 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7343 setup.game_frame_delay == 30 ? 29 :
7344 setup.game_frame_delay);
7346 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7347 setup.game_frame_delay == 16 ? 15 :
7348 setup.game_frame_delay >= 29 ? 30 :
7349 setup.game_frame_delay <= 10 ? 10 :
7350 setup.game_frame_delay);
7352 execSetupGame_setGameSpeeds(TRUE);
7357 static void ToggleUseApiServerIfNeeded(void)
7359 if (runtime.use_api_server == setup.use_api_server)
7362 runtime.use_api_server = setup.use_api_server;
7364 if (runtime.use_api_server)
7365 CheckApiServerTasks();
7368 static void ModifyGameSpeedIfNeeded(void)
7370 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7371 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7375 char *game_speed_text = "Fast";
7376 int game_speed_value = 15;
7378 if (setup.game_speed_extended)
7380 game_speed_text = "60 fps";
7381 game_speed_value = 16;
7384 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7386 // set game speed to existing list value that is fast enough for vsync
7387 setup.game_frame_delay = game_speed_value;
7389 execSetupGame_setGameSpeeds(TRUE);
7391 Request(message, REQ_CONFIRM);
7394 static void DisableVsyncIfNeeded(void)
7396 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7397 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7398 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7401 // disable vsync for the selected game speed to work
7402 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7404 execSetupGraphics_setVsyncModes(TRUE);
7406 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7412 void *related_value;
7413 } hide_related_entry_list[] =
7415 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7416 { &setup.scores_in_highscore_list, &scores_type_text },
7418 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7419 { &setup.game_frame_delay, &game_speed_text },
7421 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7422 { &setup.scroll_delay_value, &scroll_delay_text },
7424 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7425 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7427 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7428 { &setup.window_scaling_percent, &window_size_text },
7430 { &setup.window_scaling_quality, execSetupChooseScalingType },
7431 { &setup.window_scaling_quality, &scaling_type_text },
7433 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7434 { &setup.screen_rendering_mode, &rendering_mode_text },
7436 { &setup.vsync_mode, execSetupChooseVsyncMode },
7437 { &setup.vsync_mode, &vsync_mode_text },
7439 { &setup.graphics_set, execSetupChooseGraphics },
7440 { &setup.graphics_set, &graphics_set_name },
7442 { &setup.sounds_set, execSetupChooseSounds },
7443 { &setup.sounds_set, &sounds_set_name },
7445 { &setup.music_set, execSetupChooseMusic },
7446 { &setup.music_set, &music_set_name },
7448 { &setup.volume_simple, execSetupChooseVolumeSimple },
7449 { &setup.volume_simple, &volume_simple_text },
7451 { &setup.volume_loops, execSetupChooseVolumeLoops },
7452 { &setup.volume_loops, &volume_loops_text },
7454 { &setup.volume_music, execSetupChooseVolumeMusic },
7455 { &setup.volume_music, &volume_music_text },
7457 { &setup.touch.control_type, execSetupChooseTouchControls },
7458 { &setup.touch.control_type, &touch_controls_text },
7460 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7461 { &setup.touch.move_distance, &move_distance_text },
7463 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7464 { &setup.touch.drop_distance, &drop_distance_text },
7466 { &setup.touch.transparency, execSetupChooseTransparency },
7467 { &setup.touch.transparency, &transparency_text },
7469 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7470 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7472 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7473 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7475 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7476 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7478 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7479 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7481 { &setup.internal.menu_game, execSetupGame },
7482 { &setup.internal.menu_engines, execSetupEngines },
7483 { &setup.internal.menu_editor, execSetupEditor },
7484 { &setup.internal.menu_graphics, execSetupGraphics },
7485 { &setup.internal.menu_sound, execSetupSound },
7486 { &setup.internal.menu_artwork, execSetupArtwork },
7487 { &setup.internal.menu_input, execSetupInput },
7488 { &setup.internal.menu_touch, execSetupTouch },
7489 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7490 { &setup.internal.menu_exit, execExitSetup },
7491 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7496 void setHideRelatedSetupEntries(void)
7500 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7501 if (hideSetupEntry(hide_related_entry_list[i].value))
7502 setHideSetupEntry(hide_related_entry_list[i].related_value);
7505 static struct TokenInfo setup_info_main[] =
7507 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7508 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7509 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7510 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7511 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7512 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7513 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7514 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7515 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7516 { TYPE_EMPTY, NULL, "" },
7517 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7518 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7523 static struct TokenInfo setup_info_game[] =
7525 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7526 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7527 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7528 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7529 { TYPE_STRING, &network_server_text, "" },
7530 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7531 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7532 { TYPE_STRING, &scores_type_text, "" },
7533 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7534 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7535 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7536 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7537 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7538 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7539 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7540 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7541 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7542 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7543 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7544 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7545 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7546 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7547 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7548 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7549 { TYPE_STRING, &game_speed_text, "" },
7550 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7552 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7553 { TYPE_STRING, &scroll_delay_text, "" },
7555 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7556 { TYPE_STRING, &snapshot_mode_text, "" },
7557 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7558 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7559 { TYPE_EMPTY, NULL, "" },
7560 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7565 static struct TokenInfo setup_info_engines[] =
7567 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7568 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7569 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7570 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7571 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7572 { TYPE_EMPTY, NULL, "" },
7573 { TYPE_HEADLINE, NULL, "Supaplex" },
7574 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7575 { TYPE_EMPTY, NULL, "" },
7576 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7581 static struct TokenInfo setup_info_editor[] =
7584 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7585 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7586 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7587 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7588 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7589 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7590 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7591 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7592 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7593 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7595 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7596 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7598 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7600 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7601 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7602 { TYPE_EMPTY, NULL, "" },
7604 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7605 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7606 { TYPE_EMPTY, NULL, "" },
7608 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7609 { TYPE_EMPTY, NULL, "" },
7610 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7611 { TYPE_EMPTY, NULL, "" },
7612 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7617 static struct TokenInfo setup_info_graphics[] =
7619 #if !defined(PLATFORM_ANDROID)
7620 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7621 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7622 { TYPE_STRING, &window_size_text, "" },
7623 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7624 { TYPE_STRING, &scaling_type_text, "" },
7625 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7626 { TYPE_STRING, &rendering_mode_text, "" },
7629 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7630 { TYPE_STRING, &scroll_delay_text, "" },
7632 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7633 { TYPE_STRING, &vsync_mode_text, "" },
7634 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7635 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7636 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7637 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7638 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7639 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7640 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7641 { TYPE_EMPTY, NULL, "" },
7642 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7647 static struct TokenInfo setup_info_sound[] =
7649 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7650 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7651 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7652 { TYPE_EMPTY, NULL, "" },
7653 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7654 { TYPE_STRING, &volume_simple_text, "" },
7655 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7656 { TYPE_STRING, &volume_loops_text, "" },
7657 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7658 { TYPE_STRING, &volume_music_text, "" },
7659 { TYPE_EMPTY, NULL, "" },
7660 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7665 static struct TokenInfo setup_info_artwork[] =
7667 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7668 { TYPE_STRING, &graphics_set_name, "" },
7669 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7670 { TYPE_STRING, &sounds_set_name, "" },
7671 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7672 { TYPE_STRING, &music_set_name, "" },
7673 { TYPE_EMPTY, NULL, "" },
7674 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7675 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7676 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7677 { TYPE_EMPTY, NULL, "" },
7678 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7683 static struct TokenInfo setup_info_input[] =
7685 { TYPE_SWITCH, NULL, "Player:" },
7686 { TYPE_SWITCH, NULL, "Device:" },
7687 { TYPE_SWITCH, NULL, "" },
7688 { TYPE_SKIPPABLE, NULL, "" },
7689 { TYPE_EMPTY, NULL, "" },
7690 { TYPE_EMPTY, NULL, "" },
7691 { TYPE_EMPTY, NULL, "" },
7692 { TYPE_EMPTY, NULL, "" },
7693 { TYPE_EMPTY, NULL, "" },
7694 { TYPE_EMPTY, NULL, "" },
7695 { TYPE_EMPTY, NULL, "" },
7696 { TYPE_EMPTY, NULL, "" },
7697 { TYPE_SKIPPABLE, NULL, "" },
7698 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7703 static struct TokenInfo setup_info_touch[] =
7705 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7706 { TYPE_STRING, &touch_controls_text, "" },
7707 { TYPE_EMPTY, NULL, "" },
7708 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7713 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7715 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7716 { TYPE_STRING, &touch_controls_text, "" },
7717 { TYPE_EMPTY, NULL, "" },
7718 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7719 { TYPE_STRING, &grid_size_text[0][0], "" },
7720 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7721 { TYPE_STRING, &grid_size_text[0][1], "" },
7722 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7723 { TYPE_STRING, &transparency_text, "" },
7724 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7725 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7726 { TYPE_EMPTY, NULL, "" },
7727 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7728 { TYPE_EMPTY, NULL, "" },
7729 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7734 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7736 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7737 { TYPE_STRING, &touch_controls_text, "" },
7738 { TYPE_EMPTY, NULL, "" },
7739 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7740 { TYPE_STRING, &grid_size_text[1][0], "" },
7741 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7742 { TYPE_STRING, &grid_size_text[1][1], "" },
7743 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7744 { TYPE_STRING, &transparency_text, "" },
7745 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7746 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7747 { TYPE_EMPTY, NULL, "" },
7748 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7749 { TYPE_EMPTY, NULL, "" },
7750 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7755 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7757 setup_info_touch_virtual_buttons_0,
7758 setup_info_touch_virtual_buttons_1
7761 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7763 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7764 { TYPE_STRING, &touch_controls_text, "" },
7765 { TYPE_EMPTY, NULL, "" },
7766 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7767 { TYPE_STRING, &move_distance_text, "" },
7768 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7769 { TYPE_STRING, &drop_distance_text, "" },
7770 { TYPE_EMPTY, NULL, "" },
7771 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7776 static struct TokenInfo setup_info_shortcuts[] =
7778 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7779 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7780 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7781 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7782 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7783 { TYPE_EMPTY, NULL, "" },
7784 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7789 static struct TokenInfo setup_info_shortcuts_1[] =
7791 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7792 { TYPE_KEY, &setup.shortcut.save_game, "" },
7793 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7794 { TYPE_KEY, &setup.shortcut.load_game, "" },
7795 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7796 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7797 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7798 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7799 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7800 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7801 { TYPE_EMPTY, NULL, "" },
7802 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7803 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7804 { TYPE_EMPTY, NULL, "" },
7805 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7810 static struct TokenInfo setup_info_shortcuts_2[] =
7812 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7813 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7814 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7815 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7816 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7817 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7818 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7819 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7820 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7821 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7822 { TYPE_EMPTY, NULL, "" },
7823 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7828 static struct TokenInfo setup_info_shortcuts_3[] =
7830 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7831 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7832 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7833 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7834 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7835 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7836 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7837 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7838 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7839 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7840 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7841 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7842 { TYPE_EMPTY, NULL, "" },
7843 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7848 static struct TokenInfo setup_info_shortcuts_4[] =
7850 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7851 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7852 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7853 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7854 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7855 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7856 { TYPE_EMPTY, NULL, "" },
7857 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7862 static struct TokenInfo setup_info_shortcuts_5[] =
7864 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7865 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7866 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7867 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7868 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7869 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7870 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7871 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7872 { TYPE_EMPTY, NULL, "" },
7873 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7878 static Key getSetupKey(void)
7880 Key key = KSYM_UNDEFINED;
7881 boolean got_key_event = FALSE;
7883 while (!got_key_event)
7887 if (NextValidEvent(&event))
7891 case EVENT_KEYPRESS:
7893 key = GetEventKey((KeyEvent *)&event, TRUE);
7895 // press 'Escape' or 'Enter' to keep the existing key binding
7896 if (key == KSYM_Escape || key == KSYM_Return)
7897 key = KSYM_UNDEFINED; // keep old value
7899 got_key_event = TRUE;
7903 case EVENT_KEYRELEASE:
7904 key_joystick_mapping = 0;
7908 HandleOtherEvents(&event);
7919 static int getSetupValueFont(int type, void *value)
7921 if (type & TYPE_GHOSTED)
7922 return FONT_OPTION_OFF;
7923 else if (type & TYPE_KEY)
7924 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7925 else if (type & TYPE_STRING)
7926 return FONT_VALUE_2;
7927 else if (type & TYPE_ECS_AGA)
7928 return FONT_VALUE_1;
7929 else if (type & TYPE_BOOLEAN_STYLE)
7930 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7931 else if (type & TYPE_YES_NO_AUTO)
7932 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7933 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7934 else if (type & TYPE_PLAYER)
7935 return FONT_VALUE_1;
7937 return FONT_VALUE_1;
7940 static int getSetupValueFontNarrow(int type, int font_nr)
7942 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7943 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7944 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7948 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7950 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7951 struct TokenInfo *si = &setup_info[si_pos];
7952 boolean font_draw_xoffset_modified = FALSE;
7953 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7954 int font_draw_xoffset_old = -1;
7955 int xoffset = (scrollbar_needed ? -1 : 0);
7956 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7957 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7958 int xpos = menu_screen_value_xpos;
7959 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7960 int startx = mSX + xpos * 32;
7961 int starty = mSY + ypos * 32;
7962 int type = si->type;
7963 void *value = si->value;
7964 char *value_string = getSetupValue(type, value);
7965 int font_nr_default = getSetupValueFont(type, value);
7966 int font_width_default = getFontWidth(font_nr_default);
7967 int font_nr = font_nr_default;
7970 if (value_string == NULL)
7973 if (type & TYPE_KEY)
7975 xpos = MENU_SCREEN_START_XPOS;
7977 if (type & TYPE_QUERY)
7978 value_string = "<press key>";
7980 else if (type & TYPE_STRING)
7982 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7984 xpos = MENU_SCREEN_START_XPOS;
7986 if (strlen(value_string) > max_value_len)
7987 value_string[max_value_len] = '\0';
7989 else if (type & TYPE_YES_NO_AUTO)
7991 xpos = menu_screen_value_xpos - 1;
7993 else if (type & TYPE_PLAYER)
7995 int displayed_player_nr = *(int *)value + 1;
7997 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
8000 startx = mSX + xpos * 32;
8001 starty = mSY + ypos * 32;
8003 // special check if right-side setup values moved left due to scrollbar
8004 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
8006 int max_menu_text_length = 26; // maximum text length for classic menu
8007 int font_xoffset = getFontDrawOffsetX(font_nr);
8008 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8009 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8010 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8011 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
8013 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
8015 // when using narrow font, left-shifting text "auto" not needed
8016 if (type & TYPE_YES_NO_AUTO)
8020 startx = mSX + xpos * 32;
8022 font_nr = getSetupValueFontNarrow(type, font_nr);
8026 // downward compatibility correction for Juergen Bonhagen's menu settings
8027 if (setup_mode != SETUP_MODE_INPUT)
8029 int max_menu_text_length_big = (menu_screen_value_xpos -
8030 MENU_SCREEN_START_XPOS);
8031 int max_menu_text_length_medium = max_menu_text_length_big * 2;
8032 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
8033 int font1_xoffset = getFontDrawOffsetX(font_nr);
8034 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
8035 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8036 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8037 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8038 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8039 boolean correct_font_draw_xoffset = FALSE;
8041 if (xpos == MENU_SCREEN_START_XPOS &&
8042 startx + font1_xoffset < text_startx + text_font_xoffset)
8043 correct_font_draw_xoffset = TRUE;
8045 if (xpos == menu_screen_value_xpos &&
8046 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8047 correct_font_draw_xoffset = TRUE;
8049 // check if setup value would overlap with setup text when printed
8050 // (this can happen for extreme/wrong values for font draw offset)
8051 if (correct_font_draw_xoffset)
8053 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8054 font_draw_xoffset_modified = TRUE;
8056 if (type & TYPE_KEY)
8057 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8058 else if (!(type & TYPE_STRING))
8059 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8060 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8064 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
8065 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
8067 DrawText(startx, starty, value_string, font_nr);
8069 if (type & TYPE_PLAYER)
8071 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8072 int player_nr = *(int *)value;
8073 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8074 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8075 int startx2 = startx + xoff;
8076 int starty2 = starty + yoff;
8078 if (DrawingOnBackground(startx2, starty2))
8079 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8081 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8082 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8085 if (font_draw_xoffset_modified)
8086 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8089 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8091 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8092 struct TokenInfo *si = &setup_info[si_pos];
8094 if (si->type & TYPE_BOOLEAN_STYLE)
8096 *(boolean *)si->value ^= TRUE;
8098 else if (si->type & TYPE_YES_NO_AUTO)
8102 (*(int *)si->value == AUTO ? TRUE :
8103 *(int *)si->value == TRUE ? FALSE : AUTO) :
8104 (*(int *)si->value == TRUE ? AUTO :
8105 *(int *)si->value == AUTO ? FALSE : TRUE));
8107 else if (si->type & TYPE_KEY)
8111 si->type |= TYPE_QUERY;
8112 drawSetupValue(screen_pos, setup_info_pos_raw);
8113 si->type &= ~TYPE_QUERY;
8115 key = getSetupKey();
8116 if (key != KSYM_UNDEFINED)
8117 *(Key *)si->value = key;
8119 else if (si->type & TYPE_PLAYER)
8121 int player_nr = *(int *)si->value;
8126 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8128 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8131 drawSetupValue(screen_pos, setup_info_pos_raw);
8133 // fullscreen state may have changed at this point
8134 if (si->value == &setup.fullscreen)
8135 ToggleFullscreenIfNeeded();
8137 // network mode may have changed at this point
8138 if (si->value == &setup.network_mode)
8139 ToggleNetworkModeIfNeeded();
8141 // API server mode may have changed at this point
8142 if (si->value == &setup.use_api_server)
8143 ToggleUseApiServerIfNeeded();
8145 // game speed list may have changed at this point
8146 if (si->value == &setup.game_speed_extended)
8147 ToggleGameSpeedsListIfNeeded();
8150 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8152 static struct TokenInfo *setup_info_final = NULL;
8157 // determine maximum list size of target list
8158 while (setup_info_orig[list_size++].type != 0);
8160 // free, allocate and clear memory for target list
8161 checked_free(setup_info_final);
8162 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8164 // copy setup info list without setup entries marked as hidden
8165 for (i = 0; setup_info_orig[i].type != 0; i++)
8167 // skip setup entries configured to be hidden
8168 if (hideSetupEntry(setup_info_orig[i].value))
8171 // skip skippable setup entries if screen is lower than usual
8172 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8173 setup_info_orig[i].type == TYPE_SKIPPABLE)
8176 setup_info_final[list_pos++] = setup_info_orig[i];
8179 return setup_info_final;
8182 static void DrawSetupScreen_Generic(void)
8184 int fade_mask = REDRAW_FIELD;
8185 boolean redraw_all = FALSE;
8186 char *title_string = NULL;
8190 fade_mask = REDRAW_ALL;
8193 FadeMenuSoundsAndMusic();
8195 FreeScreenGadgets();
8196 CreateScreenGadgets();
8198 if (redraw_mask & REDRAW_ALL)
8203 // needed if different viewport properties defined for setup screen
8204 ChangeViewportPropertiesIfNeeded();
8206 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8210 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8212 if (setup_mode == SETUP_MODE_MAIN)
8214 setup_info = setup_info_main;
8215 title_string = STR_SETUP_MAIN;
8217 else if (setup_mode == SETUP_MODE_GAME)
8219 setup_info = setup_info_game;
8220 title_string = STR_SETUP_GAME;
8222 else if (setup_mode == SETUP_MODE_ENGINES)
8224 setup_info = setup_info_engines;
8225 title_string = STR_SETUP_ENGINES;
8227 else if (setup_mode == SETUP_MODE_EDITOR)
8229 setup_info = setup_info_editor;
8230 title_string = STR_SETUP_EDITOR;
8232 else if (setup_mode == SETUP_MODE_GRAPHICS)
8234 setup_info = setup_info_graphics;
8235 title_string = STR_SETUP_GRAPHICS;
8237 else if (setup_mode == SETUP_MODE_SOUND)
8239 setup_info = setup_info_sound;
8240 title_string = STR_SETUP_SOUND;
8242 else if (setup_mode == SETUP_MODE_ARTWORK)
8244 setup_info = setup_info_artwork;
8245 title_string = STR_SETUP_ARTWORK;
8247 else if (setup_mode == SETUP_MODE_TOUCH)
8249 setup_info = setup_info_touch;
8250 title_string = STR_SETUP_TOUCH;
8252 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8253 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8254 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8255 setup_info = setup_info_touch_wipe_gestures;
8257 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8259 setup_info = setup_info_shortcuts;
8260 title_string = STR_SETUP_SHORTCUTS;
8262 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8264 setup_info = setup_info_shortcuts_1;
8265 title_string = STR_SETUP_SHORTCUTS;
8267 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8269 setup_info = setup_info_shortcuts_2;
8270 title_string = STR_SETUP_SHORTCUTS;
8272 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8274 setup_info = setup_info_shortcuts_3;
8275 title_string = STR_SETUP_SHORTCUTS;
8277 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8279 setup_info = setup_info_shortcuts_4;
8280 title_string = STR_SETUP_SHORTCUTS;
8282 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8284 setup_info = setup_info_shortcuts_5;
8285 title_string = STR_SETUP_SHORTCUTS;
8288 // use modified setup info without setup entries marked as hidden
8289 setup_info = getSetupInfoFinal(setup_info);
8291 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8293 // determine maximal number of setup entries that can be displayed on screen
8295 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8298 // determine maximal number of setup entries available for this setup screen
8300 for (i = 0; setup_info[i].type != 0; i++)
8303 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8305 MapScreenGadgets(max_setup_info);
8308 redraw_mask = fade_mask = REDRAW_ALL;
8310 DrawMaskedBorder(fade_mask);
8315 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8317 menu_info = setup_info;
8319 HandleMenuScreen(mx, my, dx, dy, button,
8320 setup_mode, num_setup_info, max_setup_info);
8323 static void DrawSetupScreen_Input(void)
8327 FadeOut(REDRAW_FIELD);
8331 setup_info = getSetupInfoFinal(setup_info_input);
8333 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8335 for (i = 0; setup_info[i].type != 0; i++)
8337 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8338 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8339 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8340 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8341 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8342 initCursor(i, IMG_MENU_BUTTON);
8344 DrawCursorAndText_Setup(i, -1, FALSE);
8347 // create gadgets for setup input menu screen
8348 FreeScreenGadgets();
8349 CreateScreenGadgets();
8351 // map gadgets for setup input menu screen
8352 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8354 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8356 FadeIn(REDRAW_FIELD);
8359 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8361 if (device_name == NULL)
8364 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8367 if (strlen(device_name) > 1)
8369 char c1 = device_name[strlen(device_name) - 1];
8370 char c2 = device_name[strlen(device_name) - 2];
8372 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8373 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8376 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8377 strlen(device_name));
8380 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8383 static struct SetupKeyboardInfo custom_key;
8390 { &custom_key.left, "Axis/Pad Left" },
8391 { &custom_key.right, "Axis/Pad Right" },
8392 { &custom_key.up, "Axis/Pad Up" },
8393 { &custom_key.down, "Axis/Pad Down" },
8394 { &custom_key.snap, "Button 1/A/X" },
8395 { &custom_key.drop, "Button 2/B/Y" }
8397 static char *joystick_name[MAX_PLAYERS] =
8404 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8405 int font_nr_info = FONT_MENU_1;
8406 int font_nr_name = FONT_VALUE_OLD;
8407 int font_nr_on = FONT_VALUE_1;
8408 int font_nr_off = FONT_VALUE_OLD;
8411 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8413 font_nr_info = FONT_MENU_2;
8414 font_nr_on = FONT_VALUE_NARROW;
8415 font_nr_off = FONT_VALUE_OLD_NARROW;
8418 custom_key = setup.input[player_nr].key;
8420 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8421 FONT_INPUT_1_ACTIVE);
8423 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8425 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8426 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8428 if (setup.input[player_nr].use_joystick)
8430 char *device_name = setup.input[player_nr].joy.device_name;
8431 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8432 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8433 char *text = joystick_name[joystick_nr];
8434 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8436 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8437 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8441 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8442 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8445 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8446 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8450 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8451 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8452 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8453 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8455 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8456 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8457 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8458 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8459 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8460 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8462 for (i = 0; i < 6; i++)
8464 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8466 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8468 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8469 (setup.input[player_nr].use_joystick ?
8471 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8475 static int input_player_nr = 0;
8477 static void HandleSetupScreen_Input_Player(int step, int direction)
8479 int old_player_nr = input_player_nr;
8482 new_player_nr = old_player_nr + step * direction;
8483 if (new_player_nr < 0)
8485 if (new_player_nr > MAX_PLAYERS - 1)
8486 new_player_nr = MAX_PLAYERS - 1;
8488 if (new_player_nr != old_player_nr)
8490 input_player_nr = new_player_nr;
8492 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8496 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8498 static int choice = 0;
8501 int pos_start = SETUPINPUT_SCREEN_POS_START;
8502 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8503 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8504 int pos_end = SETUPINPUT_SCREEN_POS_END;
8506 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8510 for (i = 0; setup_info_input[i].type != 0; i++)
8512 // adjust menu structure according to skipped setup entries
8513 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8521 if (button == MB_MENU_INITIALIZE)
8523 // input setup menu may have changed size due to graphics configuration
8524 if (choice >= pos_empty1)
8527 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8529 DrawCursorAndText_Setup(choice, -1, TRUE);
8533 else if (button == MB_MENU_LEAVE)
8535 setup_mode = SETUP_MODE_MAIN;
8542 if (mx || my) // mouse input
8544 x = (mx - mSX) / 32;
8545 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8547 else if (dx || dy) // keyboard input
8549 if (dx && choice == 0)
8550 x = (dx < 0 ? 10 : 12);
8551 else if ((dx && choice == 1) ||
8552 (dx == -1 && choice == pos_end))
8553 button = MB_MENU_CHOICE;
8557 if (y >= pos_empty1 && y <= pos_empty2)
8558 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8561 if (y == 0 && dx != 0 && button)
8563 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8565 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8566 y >= pos_start && y <= pos_end &&
8567 !(y >= pos_empty1 && y <= pos_empty2))
8573 DrawCursorAndText_Setup(choice, -1, FALSE);
8574 DrawCursorAndText_Setup(y, -1, TRUE);
8576 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8585 char *device_name = setup.input[input_player_nr].joy.device_name;
8587 if (!setup.input[input_player_nr].use_joystick)
8589 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8591 setJoystickDeviceToNr(device_name, new_device_nr);
8592 setup.input[input_player_nr].use_joystick = TRUE;
8596 int device_nr = getJoystickNrFromDeviceName(device_name);
8597 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8599 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8600 setup.input[input_player_nr].use_joystick = FALSE;
8602 setJoystickDeviceToNr(device_name, new_device_nr);
8605 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8609 if (setup.input[input_player_nr].use_joystick)
8610 ConfigureJoystick(input_player_nr);
8612 CustomizeKeyboard(input_player_nr);
8614 else if (y == pos_end)
8620 setup_mode = SETUP_MODE_MAIN;
8627 static boolean CustomizeKeyboardMain(int player_nr)
8631 boolean finished = FALSE;
8632 static struct SetupKeyboardInfo custom_key;
8637 } customize_step[] =
8639 { &custom_key.left, "Move Left" },
8640 { &custom_key.right, "Move Right" },
8641 { &custom_key.up, "Move Up" },
8642 { &custom_key.down, "Move Down" },
8643 { &custom_key.snap, "Snap Field" },
8644 { &custom_key.drop, "Drop Element" }
8646 int font_nr_old = FONT_VALUE_OLD;
8647 int font_nr_new = FONT_VALUE_1;
8648 boolean success = FALSE;
8650 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8652 font_nr_old = FONT_VALUE_OLD_NARROW;
8653 font_nr_new = FONT_VALUE_NARROW;
8656 // read existing key bindings from player setup
8657 custom_key = setup.input[player_nr].key;
8660 FadeOut(REDRAW_FIELD);
8664 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8667 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8668 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8669 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8670 "Key:", FONT_INPUT_1_ACTIVE);
8671 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8672 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8674 FadeIn(REDRAW_FIELD);
8680 if (NextValidEvent(&event))
8684 case EVENT_KEYPRESS:
8686 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8688 // press 'Escape' to abort and keep the old key bindings
8689 if (key == KSYM_Escape)
8691 FadeSkipNextFadeIn();
8698 // press 'Enter' to keep the existing key binding
8699 if (key == KSYM_Return)
8700 key = *customize_step[step_nr].key;
8702 // check if key already used
8703 for (i = 0; i < step_nr; i++)
8704 if (*customize_step[i].key == key)
8709 // got new key binding
8710 *customize_step[step_nr].key = key;
8711 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8713 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8714 getKeyNameFromKey(key), font_nr_new);
8717 // un-highlight last query
8718 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8719 customize_step[step_nr - 1].text, FONT_MENU_1);
8720 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8721 "Key:", FONT_MENU_1);
8723 // all keys configured
8732 // query next key binding
8733 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8734 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8735 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8736 "Key:", FONT_INPUT_1_ACTIVE);
8737 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8738 getKeyNameFromKey(*customize_step[step_nr].key),
8743 case EVENT_KEYRELEASE:
8744 key_joystick_mapping = 0;
8748 HandleOtherEvents(&event);
8756 // write new key bindings back to player setup, if successfully finished
8758 setup.input[player_nr].key = custom_key;
8763 void CustomizeKeyboard(int player_nr)
8765 boolean success = CustomizeKeyboardMain(player_nr);
8769 int font_nr = FONT_TITLE_1;
8770 int font_height = getFontHeight(font_nr);
8771 int ypos1 = SYSIZE / 2 - font_height * 2;
8772 int ypos2 = SYSIZE / 2 - font_height * 1;
8773 unsigned int wait_frame_delay = 0;
8774 unsigned int wait_frame_delay_value = 2000;
8776 ResetDelayCounter(&wait_frame_delay);
8780 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8781 DrawTextSCentered(ypos2, font_nr, "configured!");
8783 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8789 DrawSetupScreen_Input();
8792 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8794 #define MARKER_BUTTON 1
8795 #define MARKER_AXIS_X 2
8796 #define MARKER_AXIS_Y 3
8798 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8800 static boolean bitmaps_initialized = FALSE;
8801 boolean screen_initialized = FALSE;
8802 static Bitmap *controller, *button, *axis_x, *axis_y;
8804 boolean success = TRUE;
8805 boolean done = FALSE, next = FALSE;
8807 int alpha = 200, alpha_step = -1;
8808 int alpha_ticks = 0;
8809 char mapping[4096], temp[256];
8810 int font_name = MENU_SETUP_FONT_TITLE;
8811 int font_info = MENU_SETUP_FONT_TEXT;
8812 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8813 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8814 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8815 int ystep_name = getMenuTextStep(spacing_name, font_name);
8816 int ystep_line = getMenuTextStep(spacing_line, font_info);
8817 int ystep_para = getMenuTextStep(spacing_para, font_info);
8825 int axis, button, hat, hat_value;
8828 *step, *prev_step, steps[] =
8830 { 356, 155, MARKER_BUTTON, "a", },
8831 { 396, 122, MARKER_BUTTON, "b", },
8832 { 320, 125, MARKER_BUTTON, "x", },
8833 { 358, 95, MARKER_BUTTON, "y", },
8834 { 162, 125, MARKER_BUTTON, "back", },
8835 { 216, 125, MARKER_BUTTON, "guide", },
8836 { 271, 125, MARKER_BUTTON, "start", },
8837 { 110, 200, MARKER_BUTTON, "dpleft", },
8838 { 146, 228, MARKER_BUTTON, "dpdown", },
8839 { 178, 200, MARKER_BUTTON, "dpright", },
8840 { 146, 172, MARKER_BUTTON, "dpup", },
8841 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8842 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8843 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8844 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8845 { 73, 141, MARKER_BUTTON, "leftstick", },
8846 { 282, 210, MARKER_BUTTON, "rightstick", },
8847 { 73, 141, MARKER_AXIS_X, "leftx", },
8848 { 73, 141, MARKER_AXIS_Y, "lefty", },
8849 { 282, 210, MARKER_AXIS_X, "rightx", },
8850 { 282, 210, MARKER_AXIS_Y, "righty", },
8853 unsigned int event_frame_delay = 0;
8854 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8856 ResetDelayCounter(&event_frame_delay);
8858 if (!bitmaps_initialized)
8860 controller = LoadCustomImage("joystick/controller.png");
8861 button = LoadCustomImage("joystick/button.png");
8862 axis_x = LoadCustomImage("joystick/axis_x.png");
8863 axis_y = LoadCustomImage("joystick/axis_y.png");
8865 bitmaps_initialized = TRUE;
8868 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8871 // print info about the joystick we are watching
8872 Debug("joystick", "watching joystick %d: (%s)",
8873 SDL_JoystickInstanceID(joystick), name);
8874 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8875 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8876 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8879 // initialize mapping with GUID and name
8880 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8882 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8883 temp, name, SDL_GetPlatform());
8885 // loop through all steps (buttons and axes), getting joystick events
8886 for (i = 0; i < SDL_arraysize(steps) && !done;)
8888 Bitmap *marker = button; // initialize with reliable default value
8891 strcpy(step->mapping, mapping);
8895 step->hat_value = -1;
8897 marker = (step->marker == MARKER_BUTTON ? button :
8898 step->marker == MARKER_AXIS_X ? axis_x :
8899 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8903 while (!done && !next)
8905 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8906 alpha_ticks = SDL_GetTicks();
8913 else if (alpha < 128)
8919 int controller_x = SX + (SXSIZE - controller->width) / 2;
8920 int controller_y = SY + ystep_line;
8922 int marker_x = controller_x + step->x;
8923 int marker_y = controller_y + step->y;
8925 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8926 int ystart2 = ystart1 + ystep_name + ystep_line;
8930 DrawTextSCentered(ystart1, font_name, name);
8932 DrawTextSCentered(ystart2, font_info,
8933 "Press buttons and move axes on");
8934 ystart2 += ystep_line;
8935 DrawTextSCentered(ystart2, font_info,
8936 "your controller when indicated.");
8937 ystart2 += ystep_line;
8938 DrawTextSCentered(ystart2, font_info,
8939 "(Your controller may look different.)");
8940 ystart2 += ystep_para;
8942 #if defined(PLATFORM_ANDROID)
8943 DrawTextSCentered(ystart2, font_info,
8944 "To correct a mistake,");
8945 ystart2 += ystep_line;
8946 DrawTextSCentered(ystart2, font_info,
8947 "press the 'back' button.");
8948 ystart2 += ystep_line;
8949 DrawTextSCentered(ystart2, font_info,
8950 "To skip a button or axis,");
8951 ystart2 += ystep_line;
8952 DrawTextSCentered(ystart2, font_info,
8953 "press the 'menu' button.");
8955 DrawTextSCentered(ystart2, font_info,
8956 "To correct a mistake,");
8957 ystart2 += ystep_line;
8958 DrawTextSCentered(ystart2, font_info,
8959 "press the 'backspace' key.");
8960 ystart2 += ystep_line;
8961 DrawTextSCentered(ystart2, font_info,
8962 "To skip a button or axis,");
8963 ystart2 += ystep_line;
8964 DrawTextSCentered(ystart2, font_info,
8965 "press the 'return' key.");
8966 ystart2 += ystep_line;
8967 DrawTextSCentered(ystart2, font_info,
8968 "To exit, press the 'escape' key.");
8971 BlitBitmapMasked(controller, drawto, 0, 0,
8972 controller->width, controller->height,
8973 controller_x, controller_y);
8975 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8976 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8978 BlitBitmapMasked(marker, drawto, 0, 0,
8979 marker->width, marker->height,
8980 marker_x, marker_y);
8982 if (!screen_initialized)
8983 FadeIn(REDRAW_FIELD);
8987 screen_initialized = TRUE;
8989 while (NextValidEvent(&event))
8993 case SDL_JOYAXISMOTION:
8994 if (event.jaxis.value > 20000 ||
8995 event.jaxis.value < -20000)
8997 for (j = 0; j < i; j++)
8998 if (steps[j].axis == event.jaxis.axis)
9003 if (step->marker != MARKER_AXIS_X &&
9004 step->marker != MARKER_AXIS_Y)
9007 step->axis = event.jaxis.axis;
9008 strcat(mapping, step->field);
9009 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
9010 strcat(mapping, temp);
9018 case SDL_JOYHATMOTION:
9019 // ignore centering; we're probably just coming back
9020 // to the center from the previous item we set
9021 if (event.jhat.value == SDL_HAT_CENTERED)
9024 for (j = 0; j < i; j++)
9025 if (steps[j].hat == event.jhat.hat &&
9026 steps[j].hat_value == event.jhat.value)
9031 step->hat = event.jhat.hat;
9032 step->hat_value = event.jhat.value;
9033 strcat(mapping, step->field);
9034 snprintf(temp, sizeof(temp), ":h%u.%u,",
9035 event.jhat.hat, event.jhat.value );
9036 strcat(mapping, temp);
9043 case SDL_JOYBALLMOTION:
9046 case SDL_JOYBUTTONUP:
9047 for (j = 0; j < i; j++)
9048 if (steps[j].button == event.jbutton.button)
9053 step->button = event.jbutton.button;
9054 strcat(mapping, step->field);
9055 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9056 strcat(mapping, temp);
9063 case SDL_FINGERDOWN:
9064 case SDL_MOUSEBUTTONDOWN:
9072 if (event.key.keysym.sym == KSYM_BackSpace ||
9073 event.key.keysym.sym == KSYM_Back)
9085 prev_step = &steps[i - 1];
9086 strcpy(mapping, prev_step->mapping);
9093 if (event.key.keysym.sym == KSYM_space ||
9094 event.key.keysym.sym == KSYM_Return ||
9095 event.key.keysym.sym == KSYM_Menu)
9104 if (event.key.keysym.sym == KSYM_Escape)
9114 program.exit_function(0);
9121 // do not handle events for longer than standard frame delay period
9122 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9131 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9134 // activate mapping for this game
9135 SDL_GameControllerAddMapping(mapping);
9137 // save mapping to personal mappings
9138 SaveSetup_AddGameControllerMapping(mapping);
9141 // wait until the last pending event was removed from event queue
9142 while (NextValidEvent(&event));
9147 static int ConfigureJoystickMain(int player_nr)
9149 char *device_name = setup.input[player_nr].joy.device_name;
9150 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9151 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9152 int success = FALSE;
9155 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9156 return JOYSTICK_NOT_AVAILABLE;
9158 if (!joystick_active || !setup.input[player_nr].use_joystick)
9159 return JOYSTICK_NOT_AVAILABLE;
9162 FadeOut(REDRAW_FIELD);
9164 // close all joystick devices (potentially opened as game controllers)
9165 for (i = 0; i < SDL_NumJoysticks(); i++)
9166 SDLCloseJoystick(i);
9168 // open joystick device as plain joystick to configure as game controller
9169 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9171 // as the joystick was successfully opened before, this should not happen
9172 if (joystick == NULL)
9175 // create new game controller mapping (buttons and axes) for joystick device
9176 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9178 // close joystick (and maybe re-open as configured game controller later)
9179 SDL_JoystickClose(joystick);
9181 // re-open all joystick devices (potentially as game controllers)
9182 for (i = 0; i < SDL_NumJoysticks(); i++)
9185 // clear all joystick input actions for all joystick devices
9186 SDLClearJoystickState();
9188 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9191 void ConfigureJoystick(int player_nr)
9193 boolean state = ConfigureJoystickMain(player_nr);
9195 if (state != JOYSTICK_NOT_CONFIGURED)
9197 boolean success = (state == JOYSTICK_CONFIGURED);
9198 char message1[MAX_OUTPUT_LINESIZE + 1];
9199 char *message2 = (success ? "configured!" : "not available!");
9200 char *device_name = setup.input[player_nr].joy.device_name;
9201 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9202 int font_nr = FONT_TITLE_1;
9203 int font_height = getFontHeight(font_nr);
9204 int ypos1 = SYSIZE / 2 - font_height * 2;
9205 int ypos2 = SYSIZE / 2 - font_height * 1;
9206 unsigned int wait_frame_delay = 0;
9207 unsigned int wait_frame_delay_value = 2000;
9209 ResetDelayCounter(&wait_frame_delay);
9213 sprintf(message1, "Joystick %d", nr);
9215 DrawTextSCentered(ypos1, font_nr, message1);
9216 DrawTextSCentered(ypos2, font_nr, message2);
9218 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9224 DrawSetupScreen_Input();
9227 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9229 if (y < video.screen_height / 3)
9231 // remap touch gadgets to access upper part of the screen
9232 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9233 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9235 else if (y > 2 * video.screen_height / 3)
9237 // remap touch gadgets to access lower part of the screen
9238 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9239 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9243 static boolean ConfigureVirtualButtonsMain(void)
9245 static char *customize_step_text[] =
9254 char grid_button[] =
9256 CHAR_GRID_BUTTON_LEFT,
9257 CHAR_GRID_BUTTON_RIGHT,
9258 CHAR_GRID_BUTTON_UP,
9259 CHAR_GRID_BUTTON_DOWN,
9260 CHAR_GRID_BUTTON_SNAP,
9261 CHAR_GRID_BUTTON_DROP
9270 int font_nr = FONT_INPUT_1_ACTIVE;
9271 int font_height = getFontHeight(font_nr);
9272 int ypos1 = SYSIZE / 2 - font_height * 2;
9273 int ypos2 = SYSIZE / 2 - font_height * 1;
9274 boolean success = FALSE;
9275 boolean finished = FALSE;
9277 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9278 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9279 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9280 boolean set_grid_button = FALSE;
9281 int nr = GRID_ACTIVE_NR();
9284 for (x = 0; x < MAX_GRID_XSIZE; x++)
9285 for (y = 0; y < MAX_GRID_YSIZE; y++)
9286 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9288 overlay.grid_button_highlight = grid_button[step_nr];
9293 FadeOut(REDRAW_FIELD);
9297 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9298 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9299 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9301 FadeIn(REDRAW_FIELD);
9303 SetOverlayShowGrid(TRUE);
9305 // map gadgets for setup touch buttons menu screen
9306 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9312 while (NextValidEvent(&event))
9314 int action = ACTION_NONE;
9316 // ---------- handle events and set the resulting action ----------
9322 UserEvent *user = (UserEvent *)&event;
9323 int id = user->value1;
9325 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9326 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9327 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9328 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9333 case EVENT_KEYPRESS:
9335 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9337 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9338 key == KSYM_BackSpace ||
9339 key == KSYM_Back ? ACTION_BACK :
9340 key == KSYM_Return ||
9342 key == KSYM_space ? ACTION_NEXT :
9347 case EVENT_KEYRELEASE:
9348 key_joystick_mapping = 0;
9351 case EVENT_BUTTONPRESS:
9352 case EVENT_BUTTONRELEASE:
9354 ButtonEvent *button = (ButtonEvent *)&event;
9356 motion_status = FALSE;
9358 if (button->type == EVENT_BUTTONPRESS)
9359 button_status = button->button;
9361 button_status = MB_RELEASED;
9363 if (HandleGadgets(button->x, button->y, button_status))
9365 // do not handle this button event anymore
9369 button->x += video.screen_xoffset;
9370 button->y += video.screen_yoffset;
9372 x = button->x * overlay.grid_xsize / video.screen_width;
9373 y = button->y * overlay.grid_ysize / video.screen_height;
9375 if (button->type == EVENT_BUTTONPRESS)
9378 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9379 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9381 set_grid_button = TRUE;
9384 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9388 case EVENT_MOTIONNOTIFY:
9390 MotionEvent *motion = (MotionEvent *)&event;
9392 motion_status = TRUE;
9394 if (HandleGadgets(motion->x, motion->y, button_status))
9396 // do not handle this button event anymore
9400 motion->x += video.screen_xoffset;
9401 motion->y += video.screen_yoffset;
9403 x = motion->x * overlay.grid_xsize / video.screen_width;
9404 y = motion->y * overlay.grid_ysize / video.screen_height;
9406 set_grid_button = TRUE;
9408 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9412 case SDL_WINDOWEVENT:
9413 HandleWindowEvent((WindowEvent *) &event);
9415 // check if device has been rotated
9416 if (nr != GRID_ACTIVE_NR())
9418 nr = GRID_ACTIVE_NR();
9420 for (x = 0; x < MAX_GRID_XSIZE; x++)
9421 for (y = 0; y < MAX_GRID_YSIZE; y++)
9422 grid_button_old[x][y] = grid_button_tmp[x][y] =
9423 overlay.grid_button[x][y];
9428 case SDL_APP_WILLENTERBACKGROUND:
9429 case SDL_APP_DIDENTERBACKGROUND:
9430 case SDL_APP_WILLENTERFOREGROUND:
9431 case SDL_APP_DIDENTERFOREGROUND:
9432 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9436 HandleOtherEvents(&event);
9440 // ---------- perform action set by handling events ----------
9442 if (action == ACTION_ESCAPE)
9444 // abort and restore the old key bindings
9446 for (x = 0; x < MAX_GRID_XSIZE; x++)
9447 for (y = 0; y < MAX_GRID_YSIZE; y++)
9448 overlay.grid_button[x][y] = grid_button_old[x][y];
9450 FadeSkipNextFadeIn();
9454 else if (action == ACTION_BACK)
9456 // keep the configured key bindings and go to previous page
9462 FadeSkipNextFadeIn();
9467 else if (action == ACTION_NEXT)
9469 // keep the configured key bindings and go to next page
9473 // all virtual buttons configured
9481 if (action != ACTION_NONE && !finished)
9483 for (x = 0; x < MAX_GRID_XSIZE; x++)
9484 for (y = 0; y < MAX_GRID_YSIZE; y++)
9485 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9487 overlay.grid_button_highlight = grid_button[step_nr];
9489 // configure next virtual button
9493 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9494 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9495 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9498 if (set_grid_button)
9500 overlay.grid_button[x][y] =
9501 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9502 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9503 grid_button_tmp[x][y]);
9505 set_grid_button = FALSE;
9512 for (x = 0; x < MAX_GRID_XSIZE; x++)
9513 for (y = 0; y < MAX_GRID_YSIZE; y++)
9514 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9516 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9518 SetOverlayShowGrid(FALSE);
9523 void ConfigureVirtualButtons(void)
9525 boolean success = ConfigureVirtualButtonsMain();
9527 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9528 SCREEN_MASK_TOUCH2);
9532 int font_nr = FONT_TITLE_1;
9533 int font_height = getFontHeight(font_nr);
9534 int ypos1 = SYSIZE / 2 - font_height * 2;
9535 int ypos2 = SYSIZE / 2 - font_height * 1;
9536 unsigned int wait_frame_delay = 0;
9537 unsigned int wait_frame_delay_value = 2000;
9539 ResetDelayCounter(&wait_frame_delay);
9543 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9544 DrawTextSCentered(ypos2, font_nr, "configured!");
9546 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9553 void DrawSetupScreen(void)
9558 if (setup_mode == SETUP_MODE_INPUT)
9559 DrawSetupScreen_Input();
9560 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9561 DrawChooseTree(&scores_type_current);
9562 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9563 DrawChooseTree(&game_speed_current);
9564 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9565 DrawChooseTree(&scroll_delay_current);
9566 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9567 DrawChooseTree(&snapshot_mode_current);
9568 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9569 DrawChooseTree(&window_size_current);
9570 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9571 DrawChooseTree(&scaling_type_current);
9572 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9573 DrawChooseTree(&rendering_mode_current);
9574 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9575 DrawChooseTree(&vsync_mode_current);
9576 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9577 DrawChooseTree(&artwork.gfx_current);
9578 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9579 DrawChooseTree(&artwork.snd_current);
9580 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9581 DrawChooseTree(&artwork.mus_current);
9582 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9583 DrawChooseTree(&volume_simple_current);
9584 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9585 DrawChooseTree(&volume_loops_current);
9586 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9587 DrawChooseTree(&volume_music_current);
9588 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9589 DrawChooseTree(&touch_control_current);
9590 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9591 DrawChooseTree(&move_distance_current);
9592 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9593 DrawChooseTree(&drop_distance_current);
9594 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9595 DrawChooseTree(&transparency_current);
9596 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9597 DrawChooseTree(&grid_size_current[0][0]);
9598 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9599 DrawChooseTree(&grid_size_current[0][1]);
9600 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9601 DrawChooseTree(&grid_size_current[1][0]);
9602 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9603 DrawChooseTree(&grid_size_current[1][1]);
9605 DrawSetupScreen_Generic();
9607 PlayMenuSoundsAndMusic();
9610 void RedrawSetupScreenAfterFullscreenToggle(void)
9612 if (setup_mode == SETUP_MODE_GRAPHICS ||
9613 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9615 // update list selection from "setup.window_scaling_percent"
9616 execSetupGraphics_setWindowSizes(TRUE);
9622 void RedrawSetupScreenAfterScreenRotation(int nr)
9626 if (setup_mode == SETUP_MODE_TOUCH)
9628 // update virtual button settings (depending on screen orientation)
9631 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9633 // save already configured virtual buttons
9634 for (x = 0; x < MAX_GRID_XSIZE; x++)
9635 for (y = 0; y < MAX_GRID_YSIZE; y++)
9636 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9640 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9642 if (setup_mode == SETUP_MODE_INPUT)
9643 HandleSetupScreen_Input(mx, my, dx, dy, button);
9644 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9645 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9646 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9647 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9648 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9649 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9650 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9651 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9652 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9653 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9654 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9655 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9656 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9657 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9658 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9659 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9660 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9661 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9662 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9663 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9664 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9665 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9666 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9667 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9668 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9669 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9670 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9671 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9672 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9673 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9674 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9675 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9676 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9677 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9678 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9679 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9680 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9681 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9682 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9683 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9684 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9685 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9686 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9687 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9689 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9692 void HandleGameActions(void)
9694 if (setup.ask_on_game_over)
9697 if (game.restart_game_message != NULL)
9699 RequestRestartGame(game.restart_game_message);
9704 if (game_status != GAME_MODE_PLAYING)
9707 GameActions(); // main game loop
9709 if (tape.auto_play && !tape.playing)
9710 AutoPlayTapesContinue(); // continue automatically playing next tape
9714 // ---------- new screen button stuff --------------------------------------
9718 int gfx_unpressed, gfx_pressed;
9719 struct MenuPosInfo *pos;
9720 boolean *check_value;
9723 unsigned int event_mask;
9724 boolean is_touch_button;
9726 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9729 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9730 &menu.main.button.prev_level, NULL,
9731 SCREEN_CTRL_ID_PREV_LEVEL,
9733 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9734 FALSE, "previous level"
9737 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9738 &menu.main.button.next_level, NULL,
9739 SCREEN_CTRL_ID_NEXT_LEVEL,
9741 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9745 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9746 &menu.scores.button.prev_level, NULL,
9747 SCREEN_CTRL_ID_PREV_LEVEL2,
9748 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9749 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9750 FALSE, "previous level"
9753 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9754 &menu.scores.button.next_level, NULL,
9755 SCREEN_CTRL_ID_NEXT_LEVEL2,
9756 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9757 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9761 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9762 &menu.scores.button.prev_score, NULL,
9763 SCREEN_CTRL_ID_PREV_SCORE,
9764 SCREEN_MASK_SCORES_INFO,
9765 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9766 FALSE, "previous score"
9769 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9770 &menu.scores.button.next_score, NULL,
9771 SCREEN_CTRL_ID_NEXT_SCORE,
9772 SCREEN_MASK_SCORES_INFO,
9773 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9777 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9778 &menu.main.button.first_level, NULL,
9779 SCREEN_CTRL_ID_FIRST_LEVEL,
9782 FALSE, "first level"
9785 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9786 &menu.main.button.last_level, NULL,
9787 SCREEN_CTRL_ID_LAST_LEVEL,
9793 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9794 &menu.main.button.level_number, NULL,
9795 SCREEN_CTRL_ID_LEVEL_NUMBER,
9798 FALSE, "level number"
9801 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9802 &menu.setup.button.prev_player, NULL,
9803 SCREEN_CTRL_ID_PREV_PLAYER,
9805 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9806 FALSE, "previous player"
9809 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9810 &menu.setup.button.next_player, NULL,
9811 SCREEN_CTRL_ID_NEXT_PLAYER,
9813 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9814 FALSE, "next player"
9817 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9818 &menu.main.button.insert_solution, NULL,
9819 SCREEN_CTRL_ID_INSERT_SOLUTION,
9820 SCREEN_MASK_MAIN_HAS_SOLUTION,
9822 FALSE, "insert solution tape"
9825 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9826 &menu.main.button.play_solution, NULL,
9827 SCREEN_CTRL_ID_PLAY_SOLUTION,
9828 SCREEN_MASK_MAIN_HAS_SOLUTION,
9830 FALSE, "play solution tape"
9833 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9834 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9835 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9837 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9838 FALSE, "switch ECS/AGA chipset"
9841 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9842 &menu.setup.button.touch_back, NULL,
9843 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9846 TRUE, "previous page"
9849 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9850 &menu.setup.button.touch_next, NULL,
9851 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9857 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9858 &menu.setup.button.touch_back2, NULL,
9859 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9862 TRUE, "previous page"
9865 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9866 &menu.setup.button.touch_next2, NULL,
9867 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9876 int gfx_unpressed, gfx_pressed;
9880 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9883 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9884 -1, -1, // these values are not constant, but can change at runtime
9885 SCREEN_CTRL_ID_SCROLL_UP,
9889 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9890 -1, -1, // these values are not constant, but can change at runtime
9891 SCREEN_CTRL_ID_SCROLL_DOWN,
9898 int gfx_unpressed, gfx_pressed;
9904 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9907 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9908 -1, -1, // these values are not constant, but can change at runtime
9909 -1, -1, // these values are not constant, but can change at runtime
9910 GD_TYPE_SCROLLBAR_VERTICAL,
9911 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9912 "scroll level series vertically"
9924 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9927 IMG_SETUP_INPUT_TEXT,
9928 SCREEN_CTRL_ID_NETWORK_SERVER,
9929 -1, -1, // these values are not constant, but can change at runtime
9930 MAX_SETUP_TEXT_INPUT_LEN,
9931 network_server_hostname,
9932 "Network Server Hostname / IP"
9936 static void CreateScreenMenubuttons(void)
9938 struct GadgetInfo *gi;
9939 unsigned int event_mask;
9942 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9944 struct MenuPosInfo *pos = menubutton_info[i].pos;
9945 int screen_mask = menubutton_info[i].screen_mask;
9946 boolean is_touch_button = menubutton_info[i].is_touch_button;
9947 boolean is_check_button = menubutton_info[i].check_value != NULL;
9948 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9949 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9950 int gfx_unpressed, gfx_pressed;
9951 int x, y, width, height;
9952 int gd_x1, gd_x2, gd_y1, gd_y2;
9953 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9954 int id = menubutton_info[i].gadget_id;
9955 int type = GD_TYPE_NORMAL_BUTTON;
9956 boolean checked = FALSE;
9958 event_mask = menubutton_info[i].event_mask;
9960 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9961 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9963 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9964 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9966 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9967 gfx_pressed = menubutton_info[i].gfx_pressed;
9968 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9969 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9970 gd_x1 = graphic_info[gfx_unpressed].src_x;
9971 gd_y1 = graphic_info[gfx_unpressed].src_y;
9972 gd_x2 = graphic_info[gfx_pressed].src_x;
9973 gd_y2 = graphic_info[gfx_pressed].src_y;
9979 if (is_touch_button)
9981 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9982 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9985 if (is_check_button)
9987 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9988 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9989 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9990 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9992 type = GD_TYPE_CHECK_BUTTON;
9993 checked = *menubutton_info[i].check_value;
9996 if (is_score_button)
9998 // if x/y set to -1, dynamically place buttons next to title text
9999 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10002 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10003 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10004 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10005 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10008 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
10009 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
10012 gi = CreateGadget(GDI_CUSTOM_ID, id,
10013 GDI_CUSTOM_TYPE_ID, i,
10014 GDI_IMAGE_ID, gfx_unpressed,
10015 GDI_INFO_TEXT, menubutton_info[i].infotext,
10019 GDI_HEIGHT, height,
10021 GDI_STATE, GD_BUTTON_UNPRESSED,
10022 GDI_CHECKED, checked,
10023 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10024 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10025 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
10026 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
10027 GDI_DIRECT_DRAW, FALSE,
10028 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10029 GDI_EVENT_MASK, event_mask,
10030 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10034 Fail("cannot create gadget");
10036 screen_gadget[id] = gi;
10040 static void CreateScreenScrollbuttons(void)
10042 struct GadgetInfo *gi;
10043 unsigned int event_mask;
10046 // these values are not constant, but can change at runtime
10047 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10048 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10049 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10050 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10052 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10054 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10055 int gfx_unpressed, gfx_pressed;
10056 int x, y, width, height;
10057 int gd_x1, gd_x2, gd_y1, gd_y2;
10058 int id = scrollbutton_info[i].gadget_id;
10060 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10062 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10063 y = mSY + scrollbutton_info[i].y;
10064 width = SC_SCROLLBUTTON_XSIZE;
10065 height = SC_SCROLLBUTTON_YSIZE;
10067 // correct scrollbar position if placed outside menu (playfield) area
10068 if (x > SX + SC_SCROLL_UP_XPOS)
10069 x = SX + SC_SCROLL_UP_XPOS;
10071 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10072 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10073 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10075 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10076 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10077 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10078 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10079 gd_x1 = graphic_info[gfx_unpressed].src_x;
10080 gd_y1 = graphic_info[gfx_unpressed].src_y;
10081 gd_x2 = graphic_info[gfx_pressed].src_x;
10082 gd_y2 = graphic_info[gfx_pressed].src_y;
10084 gi = CreateGadget(GDI_CUSTOM_ID, id,
10085 GDI_CUSTOM_TYPE_ID, i,
10086 GDI_IMAGE_ID, gfx_unpressed,
10087 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10091 GDI_HEIGHT, height,
10092 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10093 GDI_STATE, GD_BUTTON_UNPRESSED,
10094 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10095 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10096 GDI_DIRECT_DRAW, FALSE,
10097 GDI_EVENT_MASK, event_mask,
10098 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10102 Fail("cannot create gadget");
10104 screen_gadget[id] = gi;
10108 static void CreateScreenScrollbars(void)
10112 // these values are not constant, but can change at runtime
10113 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10114 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10115 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10116 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10118 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10120 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10121 int gfx_unpressed, gfx_pressed;
10122 int x, y, width, height;
10123 int gd_x1, gd_x2, gd_y1, gd_y2;
10124 struct GadgetInfo *gi;
10125 int items_max, items_visible, item_position;
10126 unsigned int event_mask;
10127 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10128 int id = scrollbar_info[i].gadget_id;
10130 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10132 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10133 y = mSY + scrollbar_info[i].y;
10134 width = scrollbar_info[i].width;
10135 height = scrollbar_info[i].height;
10137 // correct scrollbar position if placed outside menu (playfield) area
10138 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10139 x = SX + SC_SCROLL_VERTICAL_XPOS;
10141 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10142 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10144 items_max = num_page_entries;
10145 items_visible = num_page_entries;
10148 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10149 gfx_pressed = scrollbar_info[i].gfx_pressed;
10150 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10151 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10152 gd_x1 = graphic_info[gfx_unpressed].src_x;
10153 gd_y1 = graphic_info[gfx_unpressed].src_y;
10154 gd_x2 = graphic_info[gfx_pressed].src_x;
10155 gd_y2 = graphic_info[gfx_pressed].src_y;
10157 gi = CreateGadget(GDI_CUSTOM_ID, id,
10158 GDI_CUSTOM_TYPE_ID, i,
10159 GDI_IMAGE_ID, gfx_unpressed,
10160 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10164 GDI_HEIGHT, height,
10165 GDI_TYPE, scrollbar_info[i].type,
10166 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10167 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10168 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10169 GDI_WHEEL_AREA_X, SX,
10170 GDI_WHEEL_AREA_Y, SY,
10171 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10172 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10173 GDI_STATE, GD_BUTTON_UNPRESSED,
10174 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10175 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10176 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10177 GDI_DIRECT_DRAW, FALSE,
10178 GDI_EVENT_MASK, event_mask,
10179 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10183 Fail("cannot create gadget");
10185 screen_gadget[id] = gi;
10189 static void CreateScreenTextInputGadgets(void)
10193 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10195 int graphic = textinput_info[i].graphic;
10196 struct GraphicInfo *gd = &graphic_info[graphic];
10197 int gd_x1 = gd->src_x;
10198 int gd_y1 = gd->src_y;
10199 int gd_x2 = gd->src_x + gd->active_xoffset;
10200 int gd_y2 = gd->src_y + gd->active_yoffset;
10201 struct GadgetInfo *gi;
10202 unsigned int event_mask;
10203 int id = textinput_info[i].gadget_id;
10204 int x = textinput_info[i].x;
10205 int y = textinput_info[i].y;
10207 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10209 gi = CreateGadget(GDI_CUSTOM_ID, id,
10210 GDI_CUSTOM_TYPE_ID, i,
10211 GDI_INFO_TEXT, textinput_info[i].infotext,
10214 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10215 GDI_TEXT_VALUE, textinput_info[i].value,
10216 GDI_TEXT_SIZE, textinput_info[i].size,
10217 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10218 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10219 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10220 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10221 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10222 GDI_DESIGN_WIDTH, gd->width,
10223 GDI_EVENT_MASK, event_mask,
10224 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10225 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10229 Fail("cannot create gadget");
10231 screen_gadget[id] = gi;
10235 void CreateScreenGadgets(void)
10237 CreateScreenMenubuttons();
10239 CreateScreenScrollbuttons();
10240 CreateScreenScrollbars();
10242 CreateScreenTextInputGadgets();
10245 void FreeScreenGadgets(void)
10249 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10250 FreeGadget(screen_gadget[i]);
10253 static void RedrawScreenMenuGadgets(int screen_mask)
10257 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10258 if (screen_mask & menubutton_info[i].screen_mask)
10259 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10262 static void MapScreenMenuGadgets(int screen_mask)
10266 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10267 if (screen_mask & menubutton_info[i].screen_mask)
10268 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10271 static void UnmapScreenMenuGadgets(int screen_mask)
10275 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10277 if (screen_mask & menubutton_info[i].screen_mask)
10279 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10281 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10282 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10283 screen_gadget[menubutton_info[i].gadget_id]->y,
10284 screen_gadget[menubutton_info[i].gadget_id]->width,
10285 screen_gadget[menubutton_info[i].gadget_id]->height);
10290 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10293 MapScreenMenuGadgets(screen_mask);
10295 UnmapScreenMenuGadgets(screen_mask);
10298 static void MapScreenGadgets(int num_entries)
10302 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10305 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10306 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10308 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10309 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10312 static void UnmapScreenGadgets()
10316 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10317 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10319 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10320 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10323 static void MapScreenTreeGadgets(TreeInfo *ti)
10325 MapScreenGadgets(numTreeInfoInGroup(ti));
10328 static void UnmapScreenTreeGadgets(void)
10330 UnmapScreenGadgets();
10333 static void AdjustScoreInfoButtons(int x, int y1, int y2)
10335 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10336 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10337 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10338 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10340 if (pos_1->x == -1 && pos_1->y == -1)
10341 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10343 if (pos_2->x == -1 && pos_2->y == -1)
10344 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10347 static void HandleScreenGadgets(struct GadgetInfo *gi)
10349 int id = gi->custom_id;
10350 int button = gi->event.button;
10351 int step = (button == MB_LEFTBUTTON ? 1 :
10352 button == MB_MIDDLEBUTTON ? 5 :
10353 button == MB_RIGHTBUTTON ? 10 : 1);
10357 case SCREEN_CTRL_ID_PREV_LEVEL:
10358 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10361 case SCREEN_CTRL_ID_NEXT_LEVEL:
10362 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10365 case SCREEN_CTRL_ID_PREV_LEVEL2:
10366 HandleHallOfFame_SelectLevel(step, -1);
10369 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10370 HandleHallOfFame_SelectLevel(step, +1);
10373 case SCREEN_CTRL_ID_PREV_SCORE:
10374 HandleScoreInfo_SelectScore(step, -1);
10377 case SCREEN_CTRL_ID_NEXT_SCORE:
10378 HandleScoreInfo_SelectScore(step, +1);
10381 case SCREEN_CTRL_ID_FIRST_LEVEL:
10382 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10385 case SCREEN_CTRL_ID_LAST_LEVEL:
10386 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10389 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10390 CloseDoor(DOOR_CLOSE_2);
10391 SetGameStatus(GAME_MODE_LEVELNR);
10392 DrawChooseLevelNr();
10395 case SCREEN_CTRL_ID_PREV_PLAYER:
10396 HandleSetupScreen_Input_Player(step, -1);
10399 case SCREEN_CTRL_ID_NEXT_PLAYER:
10400 HandleSetupScreen_Input_Player(step, +1);
10403 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10404 InsertSolutionTape();
10407 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10408 PlaySolutionTape();
10411 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10412 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10416 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10417 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10418 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10419 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10420 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10423 case SCREEN_CTRL_ID_SCROLL_UP:
10424 if (game_status == GAME_MODE_NAMES)
10425 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10426 else if (game_status == GAME_MODE_LEVELS)
10427 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10428 else if (game_status == GAME_MODE_LEVELNR)
10429 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10430 else if (game_status == GAME_MODE_SETUP)
10431 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10432 else if (game_status == GAME_MODE_INFO)
10433 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10434 else if (game_status == GAME_MODE_SCORES)
10435 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10438 case SCREEN_CTRL_ID_SCROLL_DOWN:
10439 if (game_status == GAME_MODE_NAMES)
10440 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10441 else if (game_status == GAME_MODE_LEVELS)
10442 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10443 else if (game_status == GAME_MODE_LEVELNR)
10444 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10445 else if (game_status == GAME_MODE_SETUP)
10446 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10447 else if (game_status == GAME_MODE_INFO)
10448 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10449 else if (game_status == GAME_MODE_SCORES)
10450 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10453 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10454 if (game_status == GAME_MODE_NAMES)
10455 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10456 else if (game_status == GAME_MODE_LEVELS)
10457 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10458 else if (game_status == GAME_MODE_LEVELNR)
10459 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10460 else if (game_status == GAME_MODE_SETUP)
10461 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10462 else if (game_status == GAME_MODE_INFO)
10463 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10464 else if (game_status == GAME_MODE_SCORES)
10465 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10468 case SCREEN_CTRL_ID_NETWORK_SERVER:
10470 if (!strEqual(gi->textinput.value, ""))
10472 setString(&setup.network_server_hostname, gi->textinput.value);
10474 network.server_host = setup.network_server_hostname;
10478 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10480 network.server_host = NULL;
10483 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10484 network.server_host = NULL;
10486 execSetupGame_setNetworkServerText();
10498 void DumpScreenIdentifiers(void)
10502 Print("Active screen elements on current screen:\n");
10504 for (i = 0; main_controls[i].nr != -1; i++)
10506 struct MainControlInfo *mci = &main_controls[i];
10508 if (mci->button_graphic != -1)
10510 char *token = getTokenFromImageID(mci->button_graphic);
10512 Print("- '%s'\n", token);
10519 boolean DoScreenAction(int image_id)
10523 if (game_status != GAME_MODE_MAIN)
10526 for (i = 0; main_controls[i].nr != -1; i++)
10528 struct MainControlInfo *mci = &main_controls[i];
10529 struct MenuPosInfo *pos = mci->pos_button;
10531 if (mci->button_graphic == image_id)
10533 int x = mSX + pos->x;
10534 int y = mSY + pos->y;
10536 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10545 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10547 // get tree info node of newly added level or artwork set
10548 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10549 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10551 if (tree_node_new == NULL) // should not happen
10554 // if request dialog is active, do nothing
10555 if (game.request_active)
10558 if (game_status == GAME_MODE_MAIN &&
10559 tree_type == TREE_TYPE_LEVEL_DIR)
10561 // when adding new level set in main menu, select it as current level set
10563 // change current level set to newly added level set from zip file
10564 leveldir_current = tree_node_new;
10566 // change current level number to first level of newly added level set
10567 level_nr = leveldir_current->first_level;
10569 // redraw screen to reflect changed level set
10572 // save this level set and level number as last selected level set
10573 SaveLevelSetup_LastSeries();
10574 SaveLevelSetup_SeriesInfo();
10576 else if (game_status == GAME_MODE_LEVELS &&
10577 tree_type == TREE_TYPE_LEVEL_DIR)
10579 // when adding new level set in level set menu, set cursor and update screen
10581 leveldir_current = tree_node_new;
10583 DrawChooseTree(&leveldir_current);
10585 else if (game_status == GAME_MODE_SETUP)
10587 // when adding new artwork set in setup menu, set cursor and update screen
10589 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10590 tree_type == TREE_TYPE_GRAPHICS_DIR)
10592 artwork.gfx_current = tree_node_new;
10594 DrawChooseTree(&artwork.gfx_current);
10596 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10597 tree_type == TREE_TYPE_SOUNDS_DIR)
10599 artwork.snd_current = tree_node_new;
10601 DrawChooseTree(&artwork.snd_current);
10603 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10604 tree_type == TREE_TYPE_MUSIC_DIR)
10606 artwork.mus_current = tree_node_new;
10608 DrawChooseTree(&artwork.mus_current);
10613 static int UploadTapes(void)
10615 SetGameStatus(GAME_MODE_LOADING);
10617 FadeSetEnterScreen();
10618 FadeOut(REDRAW_ALL);
10620 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10622 FadeIn(REDRAW_ALL);
10624 DrawInitTextHead("Uploading tapes");
10626 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10627 global.autoplay_leveldir = "ALL";
10628 global.autoplay_all = TRUE;
10630 int num_tapes_uploaded = AutoPlayTapes();
10632 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10633 global.autoplay_leveldir = NULL;
10634 global.autoplay_all = FALSE;
10636 SetGameStatus(GAME_MODE_MAIN);
10640 return num_tapes_uploaded;
10643 static boolean OfferUploadTapes(void)
10645 if (!Request(setup.has_remaining_tapes ?
10646 "Upload missing tapes to the high score server now?" :
10647 "Upload all your tapes to the high score server now?", REQ_ASK))
10650 int num_tapes_uploaded = UploadTapes();
10653 if (num_tapes_uploaded < 0)
10655 num_tapes_uploaded = -num_tapes_uploaded - 1;
10657 if (num_tapes_uploaded == 0)
10658 sprintf(message, "Upload failed! No tapes uploaded!");
10659 else if (num_tapes_uploaded == 1)
10660 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10662 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10663 num_tapes_uploaded);
10665 Request(message, REQ_CONFIRM);
10667 // if uploading tapes failed, add tape upload entry to setup menu
10668 setup.provide_uploading_tapes = TRUE;
10669 setup.has_remaining_tapes = TRUE;
10671 SaveSetup_ServerSetup();
10676 if (num_tapes_uploaded == 0)
10677 sprintf(message, "No tapes uploaded!");
10678 else if (num_tapes_uploaded == 1)
10679 sprintf(message, "1 tape uploaded!");
10681 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10683 Request(message, REQ_CONFIRM);
10685 if (num_tapes_uploaded > 0)
10686 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10688 // after all tapes have been uploaded, remove entry from setup menu
10689 setup.provide_uploading_tapes = FALSE;
10690 setup.has_remaining_tapes = FALSE;
10692 SaveSetup_ServerSetup();
10697 static void CheckUploadTapes(void)
10699 if (!setup.ask_for_uploading_tapes)
10702 // after asking for uploading tapes, do not ask again
10703 setup.ask_for_uploading_tapes = FALSE;
10704 setup.ask_for_remaining_tapes = FALSE;
10706 if (directoryExists(getTapeDir(NULL)))
10708 boolean tapes_uploaded = OfferUploadTapes();
10710 if (!tapes_uploaded)
10712 Request(setup.has_remaining_tapes ?
10713 "You can upload missing tapes from the setup menu later!" :
10714 "You can upload your tapes from the setup menu later!",
10720 // if tapes directory does not exist yet, never offer uploading all tapes
10721 setup.provide_uploading_tapes = FALSE;
10724 SaveSetup_ServerSetup();
10727 static void UpgradePlayerUUID(void)
10729 ApiResetUUIDAsThread(getUUID());
10732 static void CheckUpgradePlayerUUID(void)
10734 if (setup.player_version > 1)
10737 UpgradePlayerUUID();
10740 void CheckApiServerTasks(void)
10742 // check if the player's UUID has to be upgraded
10743 CheckUpgradePlayerUUID();
10745 // check if there are any tapes to be uploaded
10746 CheckUploadTapes();