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);
281 static void HandleInfoScreen_Elements(int);
282 static void HandleInfoScreen_Music(int);
283 static void HandleInfoScreen_Credits(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];
686 // main menu display and control definitions
688 #define MAIN_CONTROL_NAME 0
689 #define MAIN_CONTROL_LEVELS 1
690 #define MAIN_CONTROL_SCORES 2
691 #define MAIN_CONTROL_EDITOR 3
692 #define MAIN_CONTROL_INFO 4
693 #define MAIN_CONTROL_GAME 5
694 #define MAIN_CONTROL_SETUP 6
695 #define MAIN_CONTROL_QUIT 7
696 #define MAIN_CONTROL_PREV_LEVEL 8
697 #define MAIN_CONTROL_NEXT_LEVEL 9
698 #define MAIN_CONTROL_FIRST_LEVEL 10
699 #define MAIN_CONTROL_LAST_LEVEL 11
700 #define MAIN_CONTROL_LEVEL_NUMBER 12
701 #define MAIN_CONTROL_LEVEL_INFO_1 13
702 #define MAIN_CONTROL_LEVEL_INFO_2 14
703 #define MAIN_CONTROL_LEVEL_NAME 15
704 #define MAIN_CONTROL_LEVEL_AUTHOR 16
705 #define MAIN_CONTROL_LEVEL_YEAR 17
706 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
707 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
708 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
709 #define MAIN_CONTROL_TITLE_1 21
710 #define MAIN_CONTROL_TITLE_2 22
711 #define MAIN_CONTROL_TITLE_3 23
713 static char str_main_text_name[10];
714 static char str_main_text_first_level[10];
715 static char str_main_text_last_level[10];
716 static char str_main_text_level_number[10];
718 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
720 static char *main_text_name = str_main_text_name;
721 static char *main_text_first_level = str_main_text_first_level;
722 static char *main_text_last_level = str_main_text_last_level;
723 static char *main_text_level_number = str_main_text_level_number;
724 static char *main_text_levels = "Levelset";
725 static char *main_text_scores = "Hall Of Fame";
726 static char *main_text_editor = "Level Creator";
727 static char *main_text_info = "Info Screen";
728 static char *main_text_game = "Start Game";
729 static char *main_text_setup = "Setup";
730 static char *main_text_quit = "Quit";
731 static char *main_text_level_name = level.name;
732 static char *main_text_level_author = level.author;
733 static char *main_text_level_year = NULL;
734 static char *main_text_level_imported_from = NULL;
735 static char *main_text_level_imported_by = NULL;
736 static char *main_text_level_tested_by = NULL;
737 static char *main_text_title_1 = NULL;
738 static char *main_text_title_2 = NULL;
739 static char *main_text_title_3 = NULL;
741 extern char debug_xsn_mode[];
743 struct MainControlInfo
747 struct MenuPosInfo *pos_button;
750 struct TextPosInfo *pos_text;
753 struct TextPosInfo *pos_input;
757 static struct MainControlInfo main_controls[] =
761 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
762 &menu.main.text.name, &main_text_name,
763 &menu.main.input.name, &setup.player_name,
767 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
768 &menu.main.text.levels, &main_text_levels,
773 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
774 &menu.main.text.scores, &main_text_scores,
779 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
780 &menu.main.text.editor, &main_text_editor,
785 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
786 &menu.main.text.info, &main_text_info,
791 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
792 &menu.main.text.game, &main_text_game,
797 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
798 &menu.main.text.setup, &main_text_setup,
803 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
804 &menu.main.text.quit, &main_text_quit,
808 MAIN_CONTROL_PREV_LEVEL,
814 MAIN_CONTROL_NEXT_LEVEL,
820 MAIN_CONTROL_FIRST_LEVEL,
822 &menu.main.text.first_level, &main_text_first_level,
826 MAIN_CONTROL_LAST_LEVEL,
828 &menu.main.text.last_level, &main_text_last_level,
832 MAIN_CONTROL_LEVEL_NUMBER,
834 &menu.main.text.level_number, &main_text_level_number,
838 MAIN_CONTROL_LEVEL_INFO_1,
840 &menu.main.text.level_info_1, NULL,
844 MAIN_CONTROL_LEVEL_INFO_2,
846 &menu.main.text.level_info_2, NULL,
850 MAIN_CONTROL_LEVEL_NAME,
852 &menu.main.text.level_name, &main_text_level_name,
856 MAIN_CONTROL_LEVEL_AUTHOR,
858 &menu.main.text.level_author, &main_text_level_author,
862 MAIN_CONTROL_LEVEL_YEAR,
864 &menu.main.text.level_year, &main_text_level_year,
868 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
870 &menu.main.text.level_imported_from, &main_text_level_imported_from,
874 MAIN_CONTROL_LEVEL_IMPORTED_BY,
876 &menu.main.text.level_imported_by, &main_text_level_imported_by,
880 MAIN_CONTROL_LEVEL_TESTED_BY,
882 &menu.main.text.level_tested_by, &main_text_level_tested_by,
886 MAIN_CONTROL_TITLE_1,
888 &menu.main.text.title_1, &main_text_title_1,
892 MAIN_CONTROL_TITLE_2,
894 &menu.main.text.title_2, &main_text_title_2,
898 MAIN_CONTROL_TITLE_3,
900 &menu.main.text.title_3, &main_text_title_3,
913 static int getTitleScreenGraphic(int nr, boolean initial)
915 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
918 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
920 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
924 static int getTitleScreenGameMode(boolean initial)
926 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
930 static int getTitleMessageGameMode(boolean initial)
932 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
935 static int getTitleAnimMode(struct TitleControlInfo *tci)
937 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
939 return base + tci->local_nr;
943 static int getTitleScreenBackground(boolean initial)
945 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
950 static int getTitleMessageBackground(int nr, boolean initial)
952 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
956 static int getTitleBackground(int nr, boolean initial, boolean is_image)
958 int base = (is_image ?
959 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
960 IMG_BACKGROUND_TITLESCREEN_1) :
961 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
962 IMG_BACKGROUND_TITLEMESSAGE_1));
963 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
964 IMG_BACKGROUND_TITLE);
965 int graphic_local = base + nr;
967 if (graphic_info[graphic_local].bitmap != NULL)
968 return graphic_local;
970 if (graphic_info[graphic_global].bitmap != NULL)
971 return graphic_global;
973 return IMG_UNDEFINED;
976 static int getTitleSound(struct TitleControlInfo *tci)
978 boolean is_image = tci->is_image;
979 int initial = tci->initial;
980 int nr = tci->local_nr;
981 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
982 int base = (is_image ?
983 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
984 SND_BACKGROUND_TITLESCREEN_1) :
985 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
986 SND_BACKGROUND_TITLEMESSAGE_1));
987 int sound_global = menu.sound[mode];
988 int sound_local = base + nr;
991 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
992 nr, initial, is_image,
993 sound_global, getSoundListEntry(sound_global)->filename,
994 sound_local, getSoundListEntry(sound_local)->filename);
997 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1000 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1001 return sound_global;
1003 return SND_UNDEFINED;
1006 static int getTitleMusic(struct TitleControlInfo *tci)
1008 boolean is_image = tci->is_image;
1009 int initial = tci->initial;
1010 int nr = tci->local_nr;
1011 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1012 int base = (is_image ?
1013 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1014 MUS_BACKGROUND_TITLESCREEN_1) :
1015 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1016 MUS_BACKGROUND_TITLEMESSAGE_1));
1017 int music_global = menu.music[mode];
1018 int music_local = base + nr;
1021 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1022 nr, initial, is_image,
1023 music_global, getMusicListEntry(music_global)->filename,
1024 music_local, getMusicListEntry(music_local)->filename);
1027 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1030 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1031 return music_global;
1033 return MUS_UNDEFINED;
1036 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1038 boolean is_image = tci->is_image;
1039 boolean initial = tci->initial;
1040 boolean first = tci->first;
1041 int nr = tci->local_nr;
1042 struct TitleMessageInfo tmi;
1043 struct TitleFadingInfo ti;
1045 tmi = (is_image ? (initial ? (first ?
1046 titlescreen_initial_first[nr] :
1047 titlescreen_initial[nr])
1049 titlescreen_first[nr] :
1051 : (initial ? (first ?
1052 titlemessage_initial_first[nr] :
1053 titlemessage_initial[nr])
1055 titlemessage_first[nr] :
1056 titlemessage[nr])));
1058 ti.fade_mode = tmi.fade_mode;
1059 ti.fade_delay = tmi.fade_delay;
1060 ti.post_delay = tmi.post_delay;
1061 ti.auto_delay = tmi.auto_delay;
1062 ti.auto_delay_unit = tmi.auto_delay_unit;
1067 static int compareTitleControlInfo(const void *object1, const void *object2)
1069 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1070 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1073 if (tci1->initial != tci2->initial)
1074 compare_result = (tci1->initial ? -1 : +1);
1075 else if (tci1->sort_priority != tci2->sort_priority)
1076 compare_result = tci1->sort_priority - tci2->sort_priority;
1077 else if (tci1->is_image != tci2->is_image)
1078 compare_result = (tci1->is_image ? -1 : +1);
1080 compare_result = tci1->local_nr - tci2->local_nr;
1082 return compare_result;
1085 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1087 int nr, int sort_priority)
1089 title_controls[num_title_screens].is_image = is_image;
1090 title_controls[num_title_screens].initial = initial;
1091 title_controls[num_title_screens].local_nr = nr;
1092 title_controls[num_title_screens].sort_priority = sort_priority;
1094 title_controls[num_title_screens].first = FALSE; // will be set later
1096 num_title_screens++;
1099 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1103 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1105 int graphic = getTitleScreenGraphic(i, initial);
1106 Bitmap *bitmap = graphic_info[graphic].bitmap;
1107 int sort_priority = graphic_info[graphic].sort_priority;
1110 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1113 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1115 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1116 char *filename = getLevelSetTitleMessageFilename(i, initial);
1117 int sort_priority = tmi->sort_priority;
1119 if (filename != NULL)
1120 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1124 static void InitializeTitleControls(boolean show_title_initial)
1126 num_title_screens = 0;
1128 // 1st step: initialize title screens for game start (only when starting)
1129 if (show_title_initial)
1130 InitializeTitleControls_CheckTitleInfo(TRUE);
1132 // 2nd step: initialize title screens for current level set
1133 InitializeTitleControls_CheckTitleInfo(FALSE);
1135 // sort title screens according to sort_priority and title number
1136 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1137 compareTitleControlInfo);
1139 // mark first title screen
1140 title_controls[0].first = TRUE;
1143 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1145 return (pos != NULL && pos->x != -1 && pos->y != -1);
1148 static boolean visibleTextPos(struct TextPosInfo *pos)
1150 return (pos != NULL && pos->x != -1 && pos->y != -1);
1153 static void InitializeMainControls(void)
1155 boolean local_team_mode = (!network.enabled && setup.team_mode);
1158 // set main control text values to dynamically determined values
1159 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1161 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1162 menu.main.text.first_level.size));
1163 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1164 menu.main.text.last_level.size));
1165 strcpy(main_text_level_number, int2str(level_nr,
1166 menu.main.text.level_number.size));
1168 main_text_level_year = leveldir_current->year;
1169 main_text_level_imported_from = leveldir_current->imported_from;
1170 main_text_level_imported_by = leveldir_current->imported_by;
1171 main_text_level_tested_by = leveldir_current->tested_by;
1173 main_text_title_1 = getConfigProgramTitleString();
1174 main_text_title_2 = getConfigProgramCopyrightString();
1175 main_text_title_3 = getConfigProgramCompanyString();
1177 // set main control screen positions to dynamically determined values
1178 for (i = 0; main_controls[i].nr != -1; i++)
1180 struct MainControlInfo *mci = &main_controls[i];
1182 struct MenuPosInfo *pos_button = mci->pos_button;
1183 struct TextPosInfo *pos_text = mci->pos_text;
1184 struct TextPosInfo *pos_input = mci->pos_input;
1185 char *text = (mci->text ? *mci->text : NULL);
1186 char *input = (mci->input ? *mci->input : NULL);
1187 int button_graphic = mci->button_graphic;
1188 int font_text = (pos_text ? pos_text->font : -1);
1189 int font_input = (pos_input ? pos_input->font : -1);
1191 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1192 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1193 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1194 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1195 int text_chars = (text != NULL ? strlen(text) : 0);
1196 int input_chars = (input != NULL ? strlen(input) : 0);
1199 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1201 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1202 int text_width = font_text_width * text_chars;
1203 int text_height = font_text_height;
1204 int input_width = font_input_width * input_chars;
1205 int input_height = font_input_height;
1207 if (nr == MAIN_CONTROL_NAME)
1209 menu.main.input.name.width = input_width;
1210 menu.main.input.name.height = input_height;
1213 if (pos_button != NULL) // (x/y may be -1/-1 here)
1215 pos_button->width = button_width;
1216 pos_button->height = button_height;
1219 if (pos_text != NULL) // (x/y may be -1/-1 here)
1221 // calculate text size -- needed for text alignment
1222 boolean calculate_text_size = (text != NULL);
1224 if (pos_text->width == -1 || calculate_text_size)
1225 pos_text->width = text_width;
1226 if (pos_text->height == -1 || calculate_text_size)
1227 pos_text->height = text_height;
1229 if (visibleMenuPos(pos_button))
1231 if (pos_text->x == -1)
1232 pos_text->x = pos_button->x + pos_button->width;
1233 if (pos_text->y == -1)
1235 pos_button->y + (pos_button->height - pos_text->height) / 2;
1239 if (pos_input != NULL) // (x/y may be -1/-1 here)
1241 if (visibleTextPos(pos_text))
1243 if (pos_input->x == -1)
1244 pos_input->x = pos_text->x + pos_text->width;
1245 if (pos_input->y == -1)
1246 pos_input->y = pos_text->y;
1249 if (pos_input->width == -1)
1250 pos_input->width = input_width;
1251 if (pos_input->height == -1)
1252 pos_input->height = input_height;
1257 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1258 int graphic, boolean pressed)
1260 struct GraphicInfo *g = &graphic_info[graphic];
1263 int xoffset = (pressed ? g->pressed_xoffset : 0);
1264 int yoffset = (pressed ? g->pressed_yoffset : 0);
1266 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1268 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1269 g->width, g->height, dst_x, dst_y);
1272 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1273 boolean active_input,
1274 boolean pressed_button)
1278 for (i = 0; main_controls[i].nr != -1; i++)
1280 struct MainControlInfo *mci = &main_controls[i];
1282 if (mci->nr == nr || nr == -1)
1284 struct MenuPosInfo *pos_button = mci->pos_button;
1285 struct TextPosInfo *pos_text = mci->pos_text;
1286 struct TextPosInfo *pos_input = mci->pos_input;
1287 char *text = (mci->text ? *mci->text : NULL);
1288 char *input = (mci->input ? *mci->input : NULL);
1289 int button_graphic = mci->button_graphic;
1290 int font_text = (pos_text ? pos_text->font : -1);
1291 int font_input = (pos_input ? pos_input->font : -1);
1295 button_graphic = BUTTON_ACTIVE(button_graphic);
1296 font_text = FONT_ACTIVE(font_text);
1301 font_input = FONT_ACTIVE(font_input);
1304 if (visibleMenuPos(pos_button))
1306 struct MenuPosInfo *pos = pos_button;
1307 int x = mSX + pos->x;
1308 int y = mSY + pos->y;
1310 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1311 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1314 if (visibleTextPos(pos_text) && text != NULL)
1316 struct TextPosInfo *pos = pos_text;
1317 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1318 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1321 // (check why/if this is needed)
1322 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1324 DrawText(x, y, text, font_text);
1327 if (visibleTextPos(pos_input) && input != NULL)
1329 struct TextPosInfo *pos = pos_input;
1330 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1331 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1334 // (check why/if this is needed)
1335 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1337 DrawText(x, y, input, font_input);
1343 static void DrawCursorAndText_Main(int nr, boolean active_text,
1344 boolean pressed_button)
1346 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1350 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1351 boolean pressed_button)
1353 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1357 static struct MainControlInfo *getMainControlInfo(int nr)
1361 for (i = 0; main_controls[i].nr != -1; i++)
1362 if (main_controls[i].nr == nr)
1363 return &main_controls[i];
1368 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1373 int rect_x = ALIGNED_TEXT_XPOS(rect);
1374 int rect_y = ALIGNED_TEXT_YPOS(rect);
1376 return (x >= rect_x && x < rect_x + rect->width &&
1377 y >= rect_y && y < rect_y + rect->height);
1380 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1385 int rect_x = ALIGNED_TEXT_XPOS(rect);
1386 int rect_y = ALIGNED_TEXT_YPOS(rect);
1389 Debug("screens:insideTextPosRect",
1390 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1391 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1392 (x >= rect_x && x < rect_x + rect->width &&
1393 y >= rect_y && y < rect_y + rect->height));
1396 return (x >= rect_x && x < rect_x + rect->width &&
1397 y >= rect_y && y < rect_y + rect->height);
1400 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1402 int rect_width = preview->xsize * preview->tile_size;
1403 int rect_height = preview->ysize * preview->tile_size;
1404 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1405 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1407 return (x >= rect_x && x < rect_x + rect_width &&
1408 y >= rect_y && y < rect_y + rect_height);
1411 static void AdjustScrollbar(int id, int items_max, int items_visible,
1414 struct GadgetInfo *gi = screen_gadget[id];
1416 if (item_position > items_max - items_visible)
1417 item_position = items_max - items_visible;
1419 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1420 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1421 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1424 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1426 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1430 static void clearMenuListArea(void)
1432 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1434 // correct scrollbar position if placed outside menu (playfield) area
1435 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1436 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1438 // clear menu list area, but not title or scrollbar
1439 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1440 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1443 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1445 static int cursor_array[MAX_LEV_FIELDY];
1446 int x = amSX + TILEX * xpos;
1447 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1452 cursor_array[ypos] = graphic;
1454 graphic = cursor_array[ypos];
1458 graphic = BUTTON_ACTIVE(graphic);
1460 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1461 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1464 static void initCursor(int ypos, int graphic)
1466 drawCursorExt(0, ypos, FALSE, graphic);
1469 static void drawCursor(int ypos, boolean active)
1471 drawCursorExt(0, ypos, active, -1);
1474 static void drawCursorXY(int xpos, int ypos, int graphic)
1476 drawCursorExt(xpos, ypos, FALSE, graphic);
1479 static void drawChooseTreeCursor(int ypos, boolean active)
1481 drawCursorExt(0, ypos, active, -1);
1484 static int getChooseTreeEditFont(boolean active)
1486 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1489 static int getChooseTreeEditXPos(int pos)
1491 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1492 int xoffset = (has_scrollbar ? -1 : 0);
1493 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1494 int sx = amSX + xpos * TILEX;
1495 int font_nr = getChooseTreeEditFont(FALSE);
1496 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1498 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1501 static int getChooseTreeEditYPos(int ypos_raw)
1503 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1504 int sy = amSY + ypos * TILEY;
1509 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1511 int sx = getChooseTreeEditXPos(POS_LEFT);
1512 int sy = getChooseTreeEditYPos(ypos_raw);
1513 int font_nr = getChooseTreeEditFont(active);
1515 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1518 static void DrawHeadline(void)
1520 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1521 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1524 static void DrawTitleScreenImage(int nr, boolean initial)
1526 int graphic = getTitleScreenGraphic(nr, initial);
1527 Bitmap *bitmap = graphic_info[graphic].bitmap;
1528 int width = graphic_info[graphic].width;
1529 int height = graphic_info[graphic].height;
1530 int src_x = graphic_info[graphic].src_x;
1531 int src_y = graphic_info[graphic].src_y;
1537 if (width > WIN_XSIZE)
1539 // image width too large for window => center image horizontally
1540 src_x = (width - WIN_XSIZE) / 2;
1544 if (height > WIN_YSIZE)
1546 // image height too large for window => center image vertically
1547 src_y = (height - WIN_YSIZE) / 2;
1551 // always display title screens centered
1552 dst_x = (WIN_XSIZE - width) / 2;
1553 dst_y = (WIN_YSIZE - height) / 2;
1555 SetDrawBackgroundMask(REDRAW_ALL);
1556 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1558 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1560 if (DrawingOnBackground(dst_x, dst_y))
1561 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1563 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1565 redraw_mask = REDRAW_ALL;
1568 static void DrawTitleScreenMessage(int nr, boolean initial)
1570 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1571 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1573 if (filename == NULL)
1576 // force TITLE font on title message screen
1577 SetFontStatus(getTitleMessageGameMode(initial));
1579 // if chars *and* width set to "-1", automatically determine width
1580 if (tmi->chars == -1 && tmi->width == -1)
1581 tmi->width = viewport.window[game_status].width;
1583 // if lines *and* height set to "-1", automatically determine height
1584 if (tmi->lines == -1 && tmi->height == -1)
1585 tmi->height = viewport.window[game_status].height;
1587 // if chars set to "-1", automatically determine by text and font width
1588 if (tmi->chars == -1)
1589 tmi->chars = tmi->width / getFontWidth(tmi->font);
1591 tmi->width = tmi->chars * getFontWidth(tmi->font);
1593 // if lines set to "-1", automatically determine by text and font height
1594 if (tmi->lines == -1)
1595 tmi->lines = tmi->height / getFontHeight(tmi->font);
1597 tmi->height = tmi->lines * getFontHeight(tmi->font);
1599 // if x set to "-1", automatically determine by width and alignment
1601 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1603 // if y set to "-1", automatically determine by height and alignment
1605 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1607 SetDrawBackgroundMask(REDRAW_ALL);
1608 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1610 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1612 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1613 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1614 tmi->autowrap, tmi->centered, tmi->parse_comments);
1619 static void DrawTitleScreen(void)
1621 KeyboardAutoRepeatOff();
1623 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1626 static boolean CheckTitleScreen(boolean levelset_has_changed)
1628 static boolean show_title_initial = TRUE;
1629 boolean show_titlescreen = FALSE;
1631 // needed to be able to skip title screen, if no image or message defined
1632 InitializeTitleControls(show_title_initial);
1634 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1635 show_titlescreen = TRUE;
1637 // show initial title images and messages only once at program start
1638 show_title_initial = FALSE;
1640 return (show_titlescreen && num_title_screens > 0);
1643 void DrawMainMenu(void)
1645 static LevelDirTree *leveldir_last_valid = NULL;
1646 boolean levelset_has_changed = FALSE;
1647 int fade_mask = REDRAW_FIELD;
1649 LimitScreenUpdates(FALSE);
1651 FadeSetLeaveScreen();
1653 // do not fade out here -- function may continue and fade on editor screen
1656 FadeMenuSoundsAndMusic();
1658 ExpireSoundLoops(FALSE);
1660 KeyboardAutoRepeatOn();
1662 audio.sound_deactivated = FALSE;
1666 // needed if last screen was the playing screen, invoked from level editor
1667 if (level_editor_test_game)
1669 CloseDoor(DOOR_CLOSE_ALL);
1671 SetGameStatus(GAME_MODE_EDITOR);
1678 // leveldir_current may be invalid (level group, parent link, node copy)
1679 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1681 if (leveldir_current != leveldir_last_valid)
1683 UpdateLastPlayedLevels_TreeInfo();
1685 levelset_has_changed = TRUE;
1688 // store valid level series information
1689 leveldir_last_valid = leveldir_current;
1691 // needed if last screen (level choice) changed graphics, sounds or music
1692 ReloadCustomArtwork(0);
1694 if (CheckTitleScreen(levelset_has_changed))
1696 SetGameStatus(GAME_MODE_TITLE);
1703 if (redraw_mask & REDRAW_ALL)
1704 fade_mask = REDRAW_ALL;
1707 fade_mask = REDRAW_ALL;
1711 // needed if different viewport properties defined for menues
1712 ChangeViewportPropertiesIfNeeded();
1714 SetDrawtoField(DRAW_TO_BACKBUFFER);
1716 // level_nr may have been set to value over handicap with level editor
1717 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1718 level_nr = leveldir_current->handicap_level;
1720 LoadLevel(level_nr);
1721 LoadScore(level_nr);
1723 SaveLevelSetup_SeriesInfo();
1725 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1726 SetDrawDeactivationMask(REDRAW_NONE);
1727 SetDrawBackgroundMask(REDRAW_FIELD);
1729 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1732 if (fade_mask == REDRAW_ALL)
1733 RedrawGlobalBorder();
1738 InitializeMainControls();
1740 DrawCursorAndText_Main(-1, FALSE, FALSE);
1741 DrawPreviewLevelInitial();
1742 DrawNetworkPlayers();
1744 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1747 if (TAPE_IS_EMPTY(tape))
1749 DrawCompleteVideoDisplay();
1751 PlayMenuSoundsAndMusic();
1753 // create gadgets for main menu screen
1754 FreeScreenGadgets();
1755 CreateScreenGadgets();
1757 // may be required if audio buttons shown on tape and changed in setup menu
1759 CreateGameButtons();
1761 // map gadgets for main menu screen
1763 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1764 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1766 // copy actual game door content to door double buffer for OpenDoor()
1767 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1768 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1770 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1772 DrawMaskedBorder(fade_mask);
1777 // update screen area with special editor door
1778 redraw_mask |= REDRAW_ALL;
1781 SetMouseCursor(CURSOR_DEFAULT);
1783 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1785 SyncEmscriptenFilesystem();
1787 // needed once after program start or after user change
1788 CheckApiServerTasks();
1791 static void gotoTopLevelDir(void)
1793 // move upwards until inside (but not above) top level directory
1794 while (leveldir_current->node_parent &&
1795 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1797 // write a "path" into level tree for easy navigation to last level
1798 if (leveldir_current->node_parent->node_group->cl_first == -1)
1800 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1801 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1802 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1803 int cl_first, cl_cursor;
1805 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1806 cl_cursor = leveldir_pos - cl_first;
1808 leveldir_current->node_parent->node_group->cl_first = cl_first;
1809 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1812 leveldir_current = leveldir_current->node_parent;
1816 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1818 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1820 return (use_frame_counter ? video.frame_counter : Counter());
1823 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1824 struct TitleFadingInfo *fi)
1826 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1829 static void ResetTitleAutoDelay(unsigned int *counter_var,
1830 struct TitleFadingInfo *fi)
1832 *counter_var = getAutoDelayCounter(fi);
1835 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1837 static unsigned int title_delay = 0;
1838 static int title_screen_nr = 0;
1839 static int last_sound = -1, last_music = -1;
1840 boolean return_to_main_menu = FALSE;
1841 struct TitleControlInfo *tci;
1844 if (button == MB_MENU_INITIALIZE)
1847 title_screen_nr = 0;
1848 tci = &title_controls[title_screen_nr];
1850 SetAnimStatus(getTitleAnimMode(tci));
1852 last_sound = SND_UNDEFINED;
1853 last_music = MUS_UNDEFINED;
1855 if (num_title_screens != 0)
1857 FadeSetEnterScreen();
1859 // use individual title fading instead of global "enter screen" fading
1860 fading = getTitleFading(tci);
1863 if (game_status_last_screen == GAME_MODE_INFO)
1865 if (num_title_screens == 0)
1867 // switch game mode from title screen mode back to info screen mode
1868 SetGameStatus(GAME_MODE_INFO);
1870 // store that last screen was info screen, not main menu screen
1871 game_status_last_screen = GAME_MODE_INFO;
1873 DrawInfoScreen_NotAvailable("Title screen information:",
1874 "No title screen for this level set.");
1879 FadeMenuSoundsAndMusic();
1881 FadeOut(REDRAW_ALL);
1883 // title screens may have different window size
1884 ChangeViewportPropertiesIfNeeded();
1886 // only required to update logic for redrawing global border
1890 DrawTitleScreenImage(tci->local_nr, tci->initial);
1892 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1894 sound = getTitleSound(tci);
1895 music = getTitleMusic(tci);
1897 if (sound != last_sound)
1898 PlayMenuSoundExt(sound);
1899 if (music != last_music)
1900 PlayMenuMusicExt(music);
1905 SetMouseCursor(CURSOR_NONE);
1909 ResetTitleAutoDelay(&title_delay, &fading);
1914 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1915 button = MB_MENU_CHOICE;
1917 if (button == MB_MENU_LEAVE)
1919 return_to_main_menu = TRUE;
1921 else if (button == MB_MENU_CHOICE)
1923 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1925 SetGameStatus(GAME_MODE_INFO);
1927 info_mode = INFO_MODE_MAIN;
1936 if (title_screen_nr < num_title_screens)
1938 tci = &title_controls[title_screen_nr];
1940 SetAnimStatus(getTitleAnimMode(tci));
1942 sound = getTitleSound(tci);
1943 music = getTitleMusic(tci);
1945 if (last_sound != SND_UNDEFINED && sound != last_sound)
1946 FadeSound(last_sound);
1947 if (last_music != MUS_UNDEFINED && music != last_music)
1950 fading = getTitleFading(tci);
1952 FadeOut(REDRAW_ALL);
1955 DrawTitleScreenImage(tci->local_nr, tci->initial);
1957 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1959 sound = getTitleSound(tci);
1960 music = getTitleMusic(tci);
1962 if (sound != last_sound)
1963 PlayMenuSoundExt(sound);
1964 if (music != last_music)
1965 PlayMenuMusicExt(music);
1972 ResetTitleAutoDelay(&title_delay, &fading);
1976 FadeMenuSoundsAndMusic();
1978 return_to_main_menu = TRUE;
1982 if (return_to_main_menu)
1984 SetMouseCursor(CURSOR_DEFAULT);
1986 // force full menu screen redraw after displaying title screens
1987 redraw_mask = REDRAW_ALL;
1989 if (game_status_last_screen == GAME_MODE_INFO)
1991 SetGameStatus(GAME_MODE_INFO);
1993 info_mode = INFO_MODE_MAIN;
1997 else // default: return to main menu
1999 SetGameStatus(GAME_MODE_MAIN);
2006 static void HandleMainMenu_ToggleTeamMode(void)
2008 setup.team_mode = !setup.team_mode;
2010 InitializeMainControls();
2011 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2013 DrawPreviewPlayers();
2016 static void HandleMainMenu_SelectLevel(int step, int direction,
2017 int selected_level_nr)
2019 int old_level_nr = level_nr;
2022 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2023 new_level_nr = selected_level_nr;
2025 new_level_nr = old_level_nr + step * direction;
2027 if (new_level_nr < leveldir_current->first_level)
2028 new_level_nr = leveldir_current->first_level;
2029 if (new_level_nr > leveldir_current->last_level)
2030 new_level_nr = leveldir_current->last_level;
2032 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2034 // skipping levels is only allowed when trying to skip single level
2035 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2036 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2038 leveldir_current->handicap_level++;
2039 SaveLevelSetup_SeriesInfo();
2042 new_level_nr = leveldir_current->handicap_level;
2045 if (new_level_nr != old_level_nr)
2047 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2049 PlaySound(SND_MENU_ITEM_SELECTING);
2051 level_nr = new_level_nr;
2053 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2054 int2str(level_nr, menu.main.text.level_number.size),
2055 mci->pos_text->font);
2057 LoadLevel(level_nr);
2058 DrawPreviewLevelInitial();
2062 DrawCompleteVideoDisplay();
2064 SaveLevelSetup_SeriesInfo();
2066 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2068 // force redraw of playfield area (may be reset at this point)
2069 redraw_mask |= REDRAW_FIELD;
2073 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2075 static int choice = MAIN_CONTROL_GAME;
2076 static boolean button_pressed_last = FALSE;
2077 boolean button_pressed = FALSE;
2079 int i = 0; // needed to prevent compiler warning due to bad code below
2081 if (button == MB_MENU_INITIALIZE)
2083 DrawCursorAndText_Main(choice, TRUE, FALSE);
2088 if (mx || my) // mouse input
2092 for (i = 0; main_controls[i].nr != -1; i++)
2094 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2095 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2096 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2098 pos = main_controls[i].nr;
2104 // check if level preview was clicked
2105 if (insidePreviewRect(&preview, mx - SX, my - SY))
2106 pos = MAIN_CONTROL_GAME;
2108 // handle pressed/unpressed state for active/inactive menu buttons
2109 // (if pos != -1, "i" contains index position corresponding to "pos")
2111 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2112 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2113 button_pressed = TRUE;
2115 if (button_pressed != button_pressed_last)
2117 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2120 PlaySound(SND_MENU_BUTTON_PRESSING);
2122 PlaySound(SND_MENU_BUTTON_RELEASING);
2125 else if (dx || dy) // keyboard input
2127 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2128 choice == MAIN_CONTROL_SETUP))
2129 button = MB_MENU_CHOICE;
2134 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2136 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2138 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2140 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2142 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2144 CloseDoor(DOOR_CLOSE_2);
2146 SetGameStatus(GAME_MODE_LEVELNR);
2148 DrawChooseLevelNr();
2150 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2156 PlaySound(SND_MENU_ITEM_ACTIVATING);
2158 DrawCursorAndText_Main(choice, FALSE, FALSE);
2159 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2165 if (choice == MAIN_CONTROL_NAME)
2167 // special case: cursor left or right pressed -- toggle team mode
2168 HandleMainMenu_ToggleTeamMode();
2170 else if (choice != MAIN_CONTROL_INFO &&
2171 choice != MAIN_CONTROL_SETUP)
2173 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2179 PlaySound(SND_MENU_ITEM_SELECTING);
2181 if (pos == MAIN_CONTROL_NAME)
2184 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2186 // special case: menu text "name/team" clicked -- toggle team mode
2187 HandleMainMenu_ToggleTeamMode();
2191 if (setup.multiple_users)
2193 CloseDoor(DOOR_CLOSE_2);
2195 SetGameStatus(GAME_MODE_NAMES);
2197 DrawChoosePlayerName();
2201 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2207 else if (pos == MAIN_CONTROL_LEVELS)
2211 CloseDoor(DOOR_CLOSE_2);
2213 SetGameStatus(GAME_MODE_LEVELS);
2215 SaveLevelSetup_LastSeries();
2216 SaveLevelSetup_SeriesInfo();
2218 // restore level set if chosen from "last played level set" menu
2219 RestoreLastPlayedLevels(&leveldir_current);
2221 if (setup.internal.choose_from_top_leveldir)
2224 DrawChooseLevelSet();
2227 else if (pos == MAIN_CONTROL_SCORES)
2229 CloseDoor(DOOR_CLOSE_2);
2231 SetGameStatus(GAME_MODE_SCORES);
2233 DrawHallOfFame(level_nr);
2235 else if (pos == MAIN_CONTROL_EDITOR)
2237 if (leveldir_current->readonly &&
2238 setup.editor.show_read_only_warning)
2239 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2241 CloseDoor(DOOR_CLOSE_ALL);
2243 SetGameStatus(GAME_MODE_EDITOR);
2245 FadeSetEnterScreen();
2249 else if (pos == MAIN_CONTROL_INFO)
2251 CloseDoor(DOOR_CLOSE_2);
2253 SetGameStatus(GAME_MODE_INFO);
2255 info_mode = INFO_MODE_MAIN;
2259 else if (pos == MAIN_CONTROL_GAME)
2261 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2263 else if (pos == MAIN_CONTROL_SETUP)
2265 CloseDoor(DOOR_CLOSE_2);
2267 SetGameStatus(GAME_MODE_SETUP);
2269 setup_mode = SETUP_MODE_MAIN;
2273 else if (pos == MAIN_CONTROL_QUIT)
2275 SaveLevelSetup_LastSeries();
2276 SaveLevelSetup_SeriesInfo();
2278 #if defined(PLATFORM_EMSCRIPTEN)
2279 Request("Close the browser window to quit!", REQ_CONFIRM);
2281 if (!setup.ask_on_quit_program ||
2282 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2283 SetGameStatus(GAME_MODE_QUIT);
2289 button_pressed_last = button_pressed;
2293 // ============================================================================
2294 // info screen functions
2295 // ============================================================================
2297 static struct TokenInfo *info_info;
2298 static int num_info_info; // number of info entries shown on screen
2299 static int max_info_info; // total number of info entries in list
2301 static void execInfoTitleScreen(void)
2303 info_mode = INFO_MODE_TITLE;
2308 static void execInfoElements(void)
2310 info_mode = INFO_MODE_ELEMENTS;
2315 static void execInfoMusic(void)
2317 info_mode = INFO_MODE_MUSIC;
2322 static void execInfoCredits(void)
2324 info_mode = INFO_MODE_CREDITS;
2329 static void execInfoProgram(void)
2331 info_mode = INFO_MODE_PROGRAM;
2336 static void execInfoVersion(void)
2338 info_mode = INFO_MODE_VERSION;
2343 static void execInfoLevelSet(void)
2345 info_mode = INFO_MODE_LEVELSET;
2350 static void execExitInfo(void)
2352 SetGameStatus(GAME_MODE_MAIN);
2357 static struct TokenInfo info_info_main[] =
2359 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2360 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2361 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2362 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2363 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2364 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2365 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2366 { TYPE_EMPTY, NULL, "" },
2367 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2372 static int getMenuTextFont(int type)
2374 if (type & (TYPE_SWITCH |
2388 static struct TokenInfo *setup_info;
2389 static struct TokenInfo setup_info_input[];
2391 static struct TokenInfo *menu_info;
2393 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2394 int screen_pos, int menu_info_pos_raw,
2397 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2398 struct TokenInfo *ti = &token_info[pos];
2399 int xpos = MENU_SCREEN_START_XPOS;
2400 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2401 int font_nr = getMenuTextFont(ti->type);
2403 if (setup_mode == SETUP_MODE_INPUT)
2404 font_nr = FONT_MENU_1;
2407 font_nr = FONT_ACTIVE(font_nr);
2409 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2411 if (ti->type & ~TYPE_SKIP_ENTRY)
2412 drawCursor(screen_pos, active);
2415 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2418 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2421 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2424 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2427 static char *window_size_text;
2428 static char *scaling_type_text;
2429 static char *network_server_text;
2431 static void drawSetupValue(int, int);
2433 static void drawMenuInfoList(int first_entry, int num_page_entries,
2434 int max_page_entries)
2438 if (first_entry + num_page_entries > max_page_entries)
2441 clearMenuListArea();
2443 for (i = 0; i < num_page_entries; i++)
2445 int menu_info_pos = first_entry + i;
2446 struct TokenInfo *si = &menu_info[menu_info_pos];
2447 void *value_ptr = si->value;
2449 // set some entries to "unchangeable" according to other variables
2450 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2451 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2452 (value_ptr == &setup.sound_music && !audio.music_available) ||
2453 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2454 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2455 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2456 si->type |= TYPE_GHOSTED;
2458 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2459 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2460 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2461 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2462 else if (si->type & ~TYPE_SKIP_ENTRY)
2463 initCursor(i, IMG_MENU_BUTTON);
2465 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2467 if (si->type & TYPE_STRING)
2471 if (value_ptr == &network_server_text)
2472 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2474 if (gadget_id != -1)
2476 struct GadgetInfo *gi = screen_gadget[gadget_id];
2477 int xpos = MENU_SCREEN_START_XPOS;
2478 int ypos = MENU_SCREEN_START_YPOS + i;
2479 int x = mSX + xpos * 32;
2480 int y = mSY + ypos * 32;
2482 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2486 if (si->type & TYPE_VALUE &&
2487 menu_info == setup_info)
2488 drawSetupValue(i, menu_info_pos);
2492 static void DrawInfoScreen_Main(void)
2494 int fade_mask = REDRAW_FIELD;
2497 if (redraw_mask & REDRAW_ALL)
2498 fade_mask = REDRAW_ALL;
2501 fade_mask = REDRAW_ALL;
2504 FadeMenuSoundsAndMusic();
2506 FreeScreenGadgets();
2507 CreateScreenGadgets();
2509 // (needed after displaying title screens which disable auto repeat)
2510 KeyboardAutoRepeatOn();
2512 FadeSetLeaveScreen();
2516 // needed if different viewport properties defined for info screen
2517 ChangeViewportPropertiesIfNeeded();
2519 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2523 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2525 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2527 info_info = info_info_main;
2529 // determine maximal number of info entries that can be displayed on screen
2531 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2534 // determine maximal number of info entries available for menu of info screen
2536 for (i = 0; info_info[i].type != 0; i++)
2539 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2541 MapScreenGadgets(max_info_info);
2543 PlayMenuSoundsAndMusic();
2545 DrawMaskedBorder(fade_mask);
2550 static void changeSetupValue(int, int, int);
2552 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2553 int mode, int num_page_entries,
2554 int max_page_entries)
2556 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2557 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2558 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2559 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2560 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2561 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2562 int *num_page_entries_last = num_page_entries_all_last[game_status];
2563 int *choice_store = choice_stores[game_status];
2564 int *first_entry_store = first_entry_stores[game_status];
2565 int choice = choice_store[mode]; // starts with 0
2566 int first_entry = first_entry_store[mode]; // starts with 0
2568 int y = choice - first_entry;
2570 boolean position_set_by_scrollbar = (dx == 999);
2571 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2574 if (button == MB_MENU_INITIALIZE)
2576 // check if number of menu page entries has changed (may happen by change
2577 // of custom artwork definition value for 'list_size' for this menu screen)
2578 // (in this case, the last menu position most probably has to be corrected)
2579 if (num_page_entries != num_page_entries_last[mode])
2581 choice_store[mode] = first_entry_store[mode] = 0;
2583 choice = first_entry = 0;
2586 num_page_entries_last[mode] = num_page_entries;
2589 // advance to first valid menu entry
2590 while (choice < num_page_entries &&
2591 menu_info[choice].type & TYPE_SKIP_ENTRY)
2594 if (position_set_by_scrollbar)
2595 first_entry = first_entry_store[mode] = dy;
2597 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2598 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2600 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2602 if (choice < first_entry)
2604 choice = first_entry;
2606 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2609 else if (choice > first_entry + num_page_entries - 1)
2611 choice = first_entry + num_page_entries - 1;
2613 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2617 choice_store[mode] = choice;
2619 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2623 else if (button == MB_MENU_LEAVE)
2625 PlaySound(SND_MENU_ITEM_SELECTING);
2627 for (i = 0; i < max_page_entries; i++)
2629 if (menu_info[i].type & TYPE_LEAVE_MENU)
2631 void (*menu_callback_function)(void) = menu_info[i].value;
2635 menu_callback_function();
2637 break; // absolutely needed because function changes 'menu_info'!
2644 if (mx || my) // mouse input
2646 x = (mx - mSX) / 32;
2647 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2649 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2651 // move cursor instead of scrolling when already at start/end of list
2652 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2654 else if (dy == +1 * SCROLL_LINE &&
2655 first_entry + num_page_entries == max_page_entries)
2658 // handle scrolling screen one line or page
2660 y + dy > num_page_entries - 1)
2662 boolean redraw = FALSE;
2664 if (ABS(dy) == SCROLL_PAGE)
2665 step = num_page_entries - 1;
2667 if (dy < 0 && first_entry > 0)
2669 // scroll page/line up
2671 first_entry -= step;
2672 if (first_entry < 0)
2677 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2679 // scroll page/line down
2681 first_entry += step;
2682 if (first_entry + num_page_entries > max_page_entries)
2683 first_entry = MAX(0, max_page_entries - num_page_entries);
2690 choice += first_entry - first_entry_store[mode];
2692 if (choice < first_entry)
2694 choice = first_entry;
2696 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2699 else if (choice > first_entry + num_page_entries - 1)
2701 choice = first_entry + num_page_entries - 1;
2703 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2706 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2710 if (choice < first_entry ||
2711 choice > first_entry + num_page_entries - 1)
2712 first_entry += SIGN(dy);
2715 first_entry_store[mode] = first_entry;
2716 choice_store[mode] = choice;
2718 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2720 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2722 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2723 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2731 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2733 if (menu_info[choice].type & menu_navigation_type ||
2734 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2735 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2736 menu_info[choice].type & TYPE_PLAYER)
2737 button = MB_MENU_CHOICE;
2742 // jump to next non-empty menu entry (up or down)
2743 while (first_entry + y > 0 &&
2744 first_entry + y < max_page_entries - 1 &&
2745 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2748 if (!IN_VIS_MENU(x, y))
2750 choice += y - y_old;
2752 if (choice < first_entry)
2753 first_entry = choice;
2754 else if (choice > first_entry + num_page_entries - 1)
2755 first_entry = choice - num_page_entries + 1;
2757 if (first_entry >= 0 &&
2758 first_entry + num_page_entries <= max_page_entries)
2760 first_entry_store[mode] = first_entry;
2762 if (choice < first_entry)
2763 choice = first_entry;
2764 else if (choice > first_entry + num_page_entries - 1)
2765 choice = first_entry + num_page_entries - 1;
2767 choice_store[mode] = choice;
2769 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2771 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2773 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2774 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2781 if (!anyScrollbarGadgetActive() &&
2782 IN_VIS_MENU(x, y) &&
2783 mx < mx_right_border &&
2784 y >= 0 && y < num_page_entries)
2788 if (first_entry + y != choice &&
2789 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2791 PlaySound(SND_MENU_ITEM_ACTIVATING);
2793 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2794 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2796 choice = choice_store[mode] = first_entry + y;
2800 PlaySound(SND_MENU_ITEM_SELECTING);
2802 for (i = 0; menu_info[i].type != 0; i++)
2804 if (menu_info[i].type & TYPE_LEAVE_MENU)
2806 void (*menu_callback_function)(void) = menu_info[i].value;
2810 menu_callback_function();
2812 // absolutely needed because function changes 'menu_info'!
2820 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2822 PlaySound(SND_MENU_ITEM_SELECTING);
2824 // when selecting key headline, execute function for key value change
2825 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2826 menu_info[first_entry + y + 1].type & TYPE_KEY)
2829 // when selecting string value, execute function for list selection
2830 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2831 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2834 // when selecting string value, execute function for text input gadget
2835 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2836 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2839 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2841 void (*menu_callback_function)(void) =
2842 menu_info[first_entry + y].value;
2844 FadeSetFromType(menu_info[first_entry + y].type);
2846 menu_callback_function();
2848 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2850 void (*gadget_callback_function)(void) =
2851 menu_info[first_entry + y].value;
2853 gadget_callback_function();
2855 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2856 menu_info == setup_info)
2858 changeSetupValue(y, first_entry + y, dx);
2864 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2866 menu_info = info_info;
2868 HandleMenuScreen(mx, my, dx, dy, button,
2869 info_mode, num_info_info, max_info_info);
2872 static int getMenuFontSpacing(int spacing_height, int font_nr)
2874 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2876 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2880 static int getMenuTextSpacing(int spacing_height, int font_nr)
2882 return (getMenuFontSpacing(spacing_height, font_nr) +
2883 EXTRA_SPACING(game_status));
2886 static int getMenuTextStep(int spacing_height, int font_nr)
2888 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2891 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2893 int font_title = MENU_INFO_FONT_TITLE;
2894 int font_error = FONT_TEXT_2;
2895 int font_foot = MENU_INFO_FONT_FOOT;
2896 int spacing_title = menu.headline1_spacing_info[info_mode];
2897 int ystep_title = getMenuTextStep(spacing_title, font_title);
2898 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2899 int ystart2 = ystart1 + ystep_title;
2900 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2902 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2904 FadeOut(REDRAW_FIELD);
2909 DrawTextSCentered(ystart1, font_title, text_title);
2910 DrawTextSCentered(ystart2, font_error, text_error);
2912 DrawTextSCentered(ybottom, font_foot,
2913 "Press any key or button for info menu");
2915 FadeIn(REDRAW_FIELD);
2918 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2920 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2921 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2922 int font_title = MENU_INFO_FONT_TITLE;
2923 int font_foot = MENU_INFO_FONT_FOOT;
2924 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2925 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2926 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2927 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2928 int ystep = MENU_SCREEN_INFO_YSTEP;
2929 int element, action, direction;
2937 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2938 infoscreen_step[i] = infoscreen_frame[i] = 0;
2943 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2945 DrawTextSCentered(ybottom, font_foot,
2946 "Press any key or button for next page");
2952 while (helpanim_info[j].element != HELPANIM_LIST_END)
2954 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2959 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2968 j += infoscreen_step[i - start];
2970 element = helpanim_info[j].element;
2971 action = helpanim_info[j].action;
2972 direction = helpanim_info[j].direction;
2975 element = EL_UNKNOWN;
2977 if (action != -1 && direction != -1)
2978 graphic = el_act_dir2img(element, action, direction);
2979 else if (action != -1)
2980 graphic = el_act2img(element, action);
2981 else if (direction != -1)
2982 graphic = el_dir2img(element, direction);
2984 graphic = el2img(element);
2986 delay = helpanim_info[j++].delay;
2991 if (infoscreen_frame[i - start] == 0)
2994 infoscreen_frame[i - start] = delay - 1;
2998 sync_frame = delay - infoscreen_frame[i - start];
2999 infoscreen_frame[i - start]--;
3002 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3004 if (!infoscreen_frame[i - start])
3005 infoscreen_step[i - start] = 0;
3009 if (!infoscreen_frame[i - start])
3010 infoscreen_step[i - start]++;
3011 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3017 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3019 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3020 graphic, sync_frame, USE_MASKING);
3023 DrawInfoScreen_HelpText(element, action, direction, i - start);
3028 redraw_mask |= REDRAW_FIELD;
3033 static char *getHelpText(int element, int action, int direction)
3035 char token[MAX_LINE_LEN];
3037 strcpy(token, element_info[element].token_name);
3040 strcat(token, element_action_info[action].suffix);
3042 if (direction != -1)
3043 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3045 return getHashEntry(helptext_info, token);
3048 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3050 int font_nr = FONT_INFO_ELEMENTS;
3051 int font_width = getFontWidth(font_nr);
3052 int font_height = getFontHeight(font_nr);
3053 int yoffset = (TILEX - 2 * font_height) / 2;
3054 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3055 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3056 int ystep = TILEY + 4;
3057 int pad_left = xstart - SX;
3058 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3059 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3060 int max_lines_per_text = 2;
3063 if (action != -1 && direction != -1) // element.action.direction
3064 text = getHelpText(element, action, direction);
3066 if (text == NULL && action != -1) // element.action
3067 text = getHelpText(element, action, -1);
3069 if (text == NULL && direction != -1) // element.direction
3070 text = getHelpText(element, -1, direction);
3072 if (text == NULL) // base element
3073 text = getHelpText(element, -1, -1);
3075 if (text == NULL) // not found
3076 text = "No description available";
3078 if (strlen(text) <= max_chars_per_line) // only one line of text
3079 ystart += getFontHeight(font_nr) / 2;
3081 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3082 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3083 TRUE, FALSE, FALSE);
3086 static void DrawInfoScreen_TitleScreen(void)
3088 SetGameStatus(GAME_MODE_TITLE);
3093 void HandleInfoScreen_TitleScreen(int button)
3095 HandleTitleScreen(0, 0, 0, 0, button);
3098 static void DrawInfoScreen_Elements(void)
3100 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3102 FadeOut(REDRAW_FIELD);
3107 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3109 FadeIn(REDRAW_FIELD);
3112 void HandleInfoScreen_Elements(int button)
3114 static unsigned int info_delay = 0;
3115 static int num_anims;
3116 static int num_pages;
3118 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3121 if (button == MB_MENU_INITIALIZE)
3123 boolean new_element = TRUE;
3127 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3129 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3131 else if (new_element)
3134 new_element = FALSE;
3138 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3142 if (button == MB_MENU_LEAVE)
3144 PlaySound(SND_MENU_ITEM_SELECTING);
3146 info_mode = INFO_MODE_MAIN;
3151 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3153 if (button != MB_MENU_INITIALIZE)
3155 PlaySound(SND_MENU_ITEM_SELECTING);
3160 if (page >= num_pages)
3162 FadeMenuSoundsAndMusic();
3164 info_mode = INFO_MODE_MAIN;
3171 FadeSetNextScreen();
3173 if (button != MB_MENU_INITIALIZE)
3174 FadeOut(REDRAW_FIELD);
3176 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3178 if (button != MB_MENU_INITIALIZE)
3179 FadeIn(REDRAW_FIELD);
3183 if (DelayReached(&info_delay, GameFrameDelay))
3184 if (page < num_pages)
3185 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3187 PlayMenuSoundIfLoop();
3191 static void DrawInfoScreen_Music(void)
3193 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3195 FadeOut(REDRAW_FIELD);
3202 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3204 FadeIn(REDRAW_FIELD);
3207 void HandleInfoScreen_Music(int button)
3209 static struct MusicFileInfo *list = NULL;
3210 int font_title = MENU_INFO_FONT_TITLE;
3211 int font_head = MENU_INFO_FONT_HEAD;
3212 int font_text = MENU_INFO_FONT_TEXT;
3213 int font_foot = MENU_INFO_FONT_FOOT;
3214 int spacing_title = menu.headline1_spacing_info[info_mode];
3215 int spacing_head = menu.headline2_spacing_info[info_mode];
3216 int ystep_title = getMenuTextStep(spacing_title, font_title);
3217 int ystep_head = getMenuTextStep(spacing_head, font_head);
3218 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3219 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3221 if (button == MB_MENU_INITIALIZE)
3223 list = music_file_info;
3227 FadeMenuSoundsAndMusic();
3232 DrawTextSCentered(ystart, font_title,
3233 "No music info for this level set.");
3235 DrawTextSCentered(ybottom, font_foot,
3236 "Press any key or button for info menu");
3242 if (button == MB_MENU_LEAVE)
3244 PlaySound(SND_MENU_ITEM_SELECTING);
3246 FadeMenuSoundsAndMusic();
3248 info_mode = INFO_MODE_MAIN;
3253 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3255 if (button != MB_MENU_INITIALIZE)
3257 PlaySound(SND_MENU_ITEM_SELECTING);
3265 FadeMenuSoundsAndMusic();
3267 info_mode = INFO_MODE_MAIN;
3273 FadeMenuSoundsAndMusic();
3275 if (list != music_file_info)
3276 FadeSetNextScreen();
3278 if (button != MB_MENU_INITIALIZE)
3279 FadeOut(REDRAW_FIELD);
3286 int sound = list->music;
3288 if (IS_LOOP_SOUND(sound))
3289 PlaySoundLoop(sound);
3293 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3297 int music = list->music;
3299 if (IS_LOOP_MUSIC(music))
3300 PlayMusicLoop(music);
3304 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3307 ystart += ystep_title;
3309 if (!strEqual(list->title, UNKNOWN_NAME))
3311 if (!strEqual(list->title_header, UNKNOWN_NAME))
3313 DrawTextSCentered(ystart, font_head, list->title_header);
3314 ystart += ystep_head;
3317 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3318 ystart += ystep_head;
3321 if (!strEqual(list->artist, UNKNOWN_NAME))
3323 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3324 DrawTextSCentered(ystart, font_head, list->artist_header);
3326 DrawTextSCentered(ystart, font_head, "by");
3328 ystart += ystep_head;
3330 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3331 ystart += ystep_head;
3334 if (!strEqual(list->album, UNKNOWN_NAME))
3336 if (!strEqual(list->album_header, UNKNOWN_NAME))
3337 DrawTextSCentered(ystart, font_head, list->album_header);
3339 DrawTextSCentered(ystart, font_head, "from the album");
3341 ystart += ystep_head;
3343 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3344 ystart += ystep_head;
3347 if (!strEqual(list->year, UNKNOWN_NAME))
3349 if (!strEqual(list->year_header, UNKNOWN_NAME))
3350 DrawTextSCentered(ystart, font_head, list->year_header);
3352 DrawTextSCentered(ystart, font_head, "from the year");
3354 ystart += ystep_head;
3356 DrawTextFCentered(ystart, font_text, "%s", list->year);
3357 ystart += ystep_head;
3360 DrawTextSCentered(ybottom, FONT_TEXT_4,
3361 "Press any key or button for next page");
3363 if (button != MB_MENU_INITIALIZE)
3364 FadeIn(REDRAW_FIELD);
3367 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3368 PlaySoundLoop(list->music);
3371 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3373 int font_title = MENU_INFO_FONT_TITLE;
3374 int font_head = MENU_INFO_FONT_HEAD;
3375 int font_text = MENU_INFO_FONT_TEXT;
3376 int font_foot = MENU_INFO_FONT_FOOT;
3377 int spacing_title = menu.headline1_spacing_info[info_mode];
3378 int spacing_head = menu.headline2_spacing_info[info_mode];
3379 int spacing_para = menu.paragraph_spacing_info[info_mode];
3380 int spacing_line = menu.line_spacing_info[info_mode];
3381 int ystep_title = getMenuTextStep(spacing_title, font_title);
3382 int ystep_head = getMenuTextStep(spacing_head, font_head);
3383 int ystep_para = getMenuTextStep(spacing_para, font_text);
3384 int ystep_line = getMenuTextStep(spacing_line, font_text);
3385 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3386 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3391 DrawTextSCentered(ystart, font_title, "Credits:");
3392 ystart += ystep_title;
3396 DrawTextSCentered(ystart, font_head,
3397 "Special thanks to");
3398 ystart += ystep_head;
3399 DrawTextSCentered(ystart, font_text,
3401 ystart += ystep_head;
3402 DrawTextSCentered(ystart, font_head,
3404 ystart += ystep_head;
3405 DrawTextSCentered(ystart, font_text,
3406 "\"Boulder Dash\"");
3407 ystart += ystep_head;
3408 DrawTextSCentered(ystart, font_head,
3410 ystart += ystep_head;
3411 DrawTextSCentered(ystart, font_text,
3413 ystart += ystep_head;
3414 DrawTextSCentered(ystart, font_head,
3416 ystart += ystep_head;
3417 DrawTextSCentered(ystart, font_text,
3418 "First Star Software");
3420 else if (screen_nr == 1)
3422 DrawTextSCentered(ystart, font_head,
3423 "Special thanks to");
3424 ystart += ystep_head;
3425 DrawTextSCentered(ystart, font_text,
3426 "Klaus Heinz & Volker Wertich");
3427 ystart += ystep_head;
3428 DrawTextSCentered(ystart, font_head,
3430 ystart += ystep_head;
3431 DrawTextSCentered(ystart, font_text,
3432 "\"Emerald Mine\"");
3433 ystart += ystep_head;
3434 DrawTextSCentered(ystart, font_head,
3436 ystart += ystep_head;
3437 DrawTextSCentered(ystart, font_text,
3439 ystart += ystep_head;
3440 DrawTextSCentered(ystart, font_head,
3442 ystart += ystep_head;
3443 DrawTextSCentered(ystart, font_text,
3446 else if (screen_nr == 2)
3448 DrawTextSCentered(ystart, font_head,
3449 "Special thanks to");
3450 ystart += ystep_head;
3451 DrawTextSCentered(ystart, font_text,
3452 "Michael Stopp & Philip Jespersen");
3453 ystart += ystep_head;
3454 DrawTextSCentered(ystart, font_head,
3456 ystart += ystep_head;
3457 DrawTextSCentered(ystart, font_text,
3459 ystart += ystep_head;
3460 DrawTextSCentered(ystart, font_head,
3462 ystart += ystep_head;
3463 DrawTextSCentered(ystart, font_text,
3465 ystart += ystep_head;
3466 DrawTextSCentered(ystart, font_head,
3468 ystart += ystep_head;
3469 DrawTextSCentered(ystart, font_text,
3470 "Digital Integration");
3472 else if (screen_nr == 3)
3474 DrawTextSCentered(ystart, font_head,
3475 "Special thanks to");
3476 ystart += ystep_head;
3477 DrawTextSCentered(ystart, font_text,
3478 "Hiroyuki Imabayashi");
3479 ystart += ystep_head;
3480 DrawTextSCentered(ystart, font_head,
3482 ystart += ystep_head;
3483 DrawTextSCentered(ystart, font_text,
3485 ystart += ystep_head;
3486 DrawTextSCentered(ystart, font_head,
3488 ystart += ystep_head;
3489 DrawTextSCentered(ystart, font_text,
3491 ystart += ystep_head;
3492 DrawTextSCentered(ystart, font_head,
3494 ystart += ystep_head;
3495 DrawTextSCentered(ystart, font_text,
3498 else if (screen_nr == 4)
3500 DrawTextSCentered(ystart, font_head,
3501 "Special thanks to");
3502 ystart += ystep_head;
3503 DrawTextSCentered(ystart, font_text,
3505 ystart += ystep_head;
3506 DrawTextSCentered(ystart, font_head,
3508 ystart += ystep_head;
3509 DrawTextSCentered(ystart, font_text,
3510 "J\xfcrgen Bonhagen");
3511 ystart += ystep_head;
3512 DrawTextSCentered(ystart, font_head,
3513 "for the continuous creation");
3514 ystart += ystep_line;
3515 DrawTextSCentered(ystart, font_head,
3516 "of outstanding level sets");
3518 else if (screen_nr == 5)
3520 DrawTextSCentered(ystart, font_head,
3522 ystart += ystep_head;
3523 DrawTextSCentered(ystart, font_text,
3525 ystart += ystep_head;
3526 DrawTextSCentered(ystart, font_head,
3527 "for ideas and inspiration by");
3528 ystart += ystep_head;
3529 DrawTextSCentered(ystart, font_text,
3531 ystart += ystep_para;
3533 DrawTextSCentered(ystart, font_head,
3535 ystart += ystep_head;
3536 DrawTextSCentered(ystart, font_text,
3538 ystart += ystep_head;
3539 DrawTextSCentered(ystart, font_head,
3540 "for ideas and inspiration by");
3541 ystart += ystep_head;
3542 DrawTextSCentered(ystart, font_text,
3545 else if (screen_nr == 6)
3547 DrawTextSCentered(ystart, font_head,
3549 ystart += ystep_head;
3550 DrawTextSCentered(ystart, font_text,
3552 ystart += ystep_head;
3553 DrawTextSCentered(ystart, font_head,
3554 "for the code base used for the");
3555 ystart += ystep_line;
3556 DrawTextSCentered(ystart, font_head,
3557 "native Emerald Mine engine");
3559 else if (screen_nr == 7)
3561 DrawTextSCentered(ystart, font_head,
3563 ystart += ystep_head;
3564 DrawTextSCentered(ystart, font_text,
3566 ystart += ystep_head;
3567 DrawTextSCentered(ystart, font_head,
3568 "for the initial DOS port");
3569 ystart += ystep_para;
3571 DrawTextSCentered(ystart, font_head,
3573 ystart += ystep_head;
3574 DrawTextSCentered(ystart, font_text,
3576 ystart += ystep_head;
3577 DrawTextSCentered(ystart, font_head,
3578 "for some additional toons");
3580 else if (screen_nr == 8)
3582 DrawTextSCentered(ystart, font_head,
3583 "And not to forget:");
3584 ystart += ystep_head;
3585 DrawTextSCentered(ystart, font_head,
3587 ystart += ystep_head;
3588 DrawTextSCentered(ystart, font_text,
3589 "All those who contributed");
3590 ystart += ystep_line;
3591 DrawTextSCentered(ystart, font_text,
3592 "levels to this game");
3593 ystart += ystep_line;
3594 DrawTextSCentered(ystart, font_text,
3598 DrawTextSCentered(ybottom, font_foot,
3599 "Press any key or button for next page");
3602 static void DrawInfoScreen_Credits(void)
3604 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3606 FadeMenuSoundsAndMusic();
3608 FadeOut(REDRAW_FIELD);
3610 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3612 FadeIn(REDRAW_FIELD);
3615 void HandleInfoScreen_Credits(int button)
3617 static int screen_nr = 0;
3618 int num_screens = 9;
3620 if (button == MB_MENU_INITIALIZE)
3624 // DrawInfoScreen_CreditsScreen(screen_nr);
3627 if (button == MB_MENU_LEAVE)
3629 PlaySound(SND_MENU_ITEM_SELECTING);
3631 info_mode = INFO_MODE_MAIN;
3636 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3638 if (button != MB_MENU_INITIALIZE)
3640 PlaySound(SND_MENU_ITEM_SELECTING);
3645 if (screen_nr >= num_screens)
3647 FadeMenuSoundsAndMusic();
3649 info_mode = INFO_MODE_MAIN;
3656 FadeSetNextScreen();
3658 if (button != MB_MENU_INITIALIZE)
3659 FadeOut(REDRAW_FIELD);
3661 DrawInfoScreen_CreditsScreen(screen_nr);
3663 if (button != MB_MENU_INITIALIZE)
3664 FadeIn(REDRAW_FIELD);
3668 PlayMenuSoundIfLoop();
3672 static void DrawInfoScreen_Program(void)
3674 int font_title = MENU_INFO_FONT_TITLE;
3675 int font_head = MENU_INFO_FONT_HEAD;
3676 int font_text = MENU_INFO_FONT_TEXT;
3677 int font_foot = MENU_INFO_FONT_FOOT;
3678 int spacing_title = menu.headline1_spacing_info[info_mode];
3679 int spacing_head = menu.headline2_spacing_info[info_mode];
3680 int spacing_para = menu.paragraph_spacing_info[info_mode];
3681 int spacing_line = menu.line_spacing_info[info_mode];
3682 int ystep_title = getMenuTextStep(spacing_title, font_title);
3683 int ystep_head = getMenuTextStep(spacing_head, font_head);
3684 int ystep_para = getMenuTextStep(spacing_para, font_text);
3685 int ystep_line = getMenuTextStep(spacing_line, font_text);
3686 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3687 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3689 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3691 FadeOut(REDRAW_FIELD);
3696 DrawTextSCentered(ystart, font_title, "Program Information:");
3697 ystart += ystep_title;
3699 DrawTextSCentered(ystart, font_head,
3700 "This game is Freeware!");
3701 ystart += ystep_head;
3702 DrawTextSCentered(ystart, font_head,
3703 "If you like it, send e-mail to:");
3704 ystart += ystep_head;
3705 DrawTextSCentered(ystart, font_text,
3706 setup.internal.program_email);
3707 ystart += ystep_para;
3709 DrawTextSCentered(ystart, font_head,
3710 "More information and levels:");
3711 ystart += ystep_head;
3712 DrawTextSCentered(ystart, font_text,
3713 setup.internal.program_website);
3714 ystart += ystep_para;
3716 DrawTextSCentered(ystart, font_head,
3717 "If you have created new levels,");
3718 ystart += ystep_line;
3719 DrawTextSCentered(ystart, font_head,
3720 "send them to me to include them!");
3721 ystart += ystep_head;
3722 DrawTextSCentered(ystart, font_head,
3725 DrawTextSCentered(ybottom, font_foot,
3726 "Press any key or button for info menu");
3728 FadeIn(REDRAW_FIELD);
3731 void HandleInfoScreen_Program(int button)
3733 if (button == MB_MENU_LEAVE)
3735 PlaySound(SND_MENU_ITEM_SELECTING);
3737 info_mode = INFO_MODE_MAIN;
3742 else if (button == MB_MENU_CHOICE)
3744 PlaySound(SND_MENU_ITEM_SELECTING);
3746 FadeMenuSoundsAndMusic();
3748 info_mode = INFO_MODE_MAIN;
3753 PlayMenuSoundIfLoop();
3757 static void DrawInfoScreen_Version(void)
3759 int font_title = MENU_INFO_FONT_TITLE;
3760 int font_head = MENU_INFO_FONT_HEAD;
3761 int font_text = MENU_INFO_FONT_TEXT;
3762 int font_foot = MENU_INFO_FONT_FOOT;
3763 int spacing_title = menu.headline1_spacing_info[info_mode];
3764 int spacing_head = menu.headline2_spacing_info[info_mode];
3765 int spacing_para = menu.paragraph_spacing_info[info_mode];
3766 int spacing_line = menu.line_spacing_info[info_mode];
3767 int xstep = getFontWidth(font_text);
3768 int ystep_title = getMenuTextStep(spacing_title, font_title);
3769 int ystep_head = getMenuTextStep(spacing_head, font_head);
3770 int ystep_para = getMenuTextStep(spacing_para, font_text);
3771 int ystep_line = getMenuTextStep(spacing_line, font_text);
3772 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3773 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3774 int xstart1 = mSX - SX + 2 * xstep;
3775 int xstart2 = mSX - SX + 18 * xstep;
3776 int xstart3 = mSX - SX + 28 * xstep;
3777 SDL_version sdl_version_compiled;
3778 const SDL_version *sdl_version_linked;
3779 int driver_name_len = 10;
3780 SDL_version sdl_version_linked_ext;
3781 const char *driver_name = NULL;
3783 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3785 FadeOut(REDRAW_FIELD);
3790 DrawTextSCentered(ystart, font_title, "Version Information:");
3791 ystart += ystep_title;
3793 DrawTextF(xstart1, ystart, font_head, "Name");
3794 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3795 ystart += ystep_line;
3797 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3799 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3800 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3801 ystart += ystep_line;
3803 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3804 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3805 ystart += ystep_line;
3809 DrawTextF(xstart1, ystart, font_head, "Version");
3810 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3811 ystart += ystep_line;
3814 DrawTextF(xstart1, ystart, font_head, "Platform");
3815 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3817 PLATFORM_XX_BIT_STRING);
3818 ystart += ystep_line;
3820 DrawTextF(xstart1, ystart, font_head, "Target");
3821 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3822 ystart += ystep_line;
3824 DrawTextF(xstart1, ystart, font_head, "Source date");
3825 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3826 ystart += ystep_line;
3828 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3829 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3830 ystart += ystep_para;
3832 DrawTextF(xstart1, ystart, font_head, "Library");
3833 DrawTextF(xstart2, ystart, font_head, "compiled");
3834 DrawTextF(xstart3, ystart, font_head, "linked");
3835 ystart += ystep_head;
3837 SDL_VERSION(&sdl_version_compiled);
3838 SDL_GetVersion(&sdl_version_linked_ext);
3839 sdl_version_linked = &sdl_version_linked_ext;
3841 DrawTextF(xstart1, ystart, font_text, "SDL");
3842 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3843 sdl_version_compiled.major,
3844 sdl_version_compiled.minor,
3845 sdl_version_compiled.patch);
3846 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3847 sdl_version_linked->major,
3848 sdl_version_linked->minor,
3849 sdl_version_linked->patch);
3850 ystart += ystep_line;
3852 SDL_IMAGE_VERSION(&sdl_version_compiled);
3853 sdl_version_linked = IMG_Linked_Version();
3855 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3856 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3857 sdl_version_compiled.major,
3858 sdl_version_compiled.minor,
3859 sdl_version_compiled.patch);
3860 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3861 sdl_version_linked->major,
3862 sdl_version_linked->minor,
3863 sdl_version_linked->patch);
3864 ystart += ystep_line;
3866 SDL_MIXER_VERSION(&sdl_version_compiled);
3867 sdl_version_linked = Mix_Linked_Version();
3869 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3870 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3871 sdl_version_compiled.major,
3872 sdl_version_compiled.minor,
3873 sdl_version_compiled.patch);
3874 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3875 sdl_version_linked->major,
3876 sdl_version_linked->minor,
3877 sdl_version_linked->patch);
3878 ystart += ystep_line;
3880 SDL_NET_VERSION(&sdl_version_compiled);
3881 sdl_version_linked = SDLNet_Linked_Version();
3883 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3884 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3885 sdl_version_compiled.major,
3886 sdl_version_compiled.minor,
3887 sdl_version_compiled.patch);
3888 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3889 sdl_version_linked->major,
3890 sdl_version_linked->minor,
3891 sdl_version_linked->patch);
3892 ystart += ystep_para;
3894 DrawTextF(xstart1, ystart, font_head, "Driver");
3895 DrawTextF(xstart2, ystart, font_head, "Requested");
3896 DrawTextF(xstart3, ystart, font_head, "Used");
3897 ystart += ystep_head;
3900 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3902 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3903 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3904 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3905 ystart += ystep_line;
3908 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3910 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3911 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3912 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3913 ystart += ystep_line;
3916 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3918 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3919 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3920 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3922 DrawTextSCentered(ybottom, font_foot,
3923 "Press any key or button for info menu");
3925 FadeIn(REDRAW_FIELD);
3928 void HandleInfoScreen_Version(int button)
3930 if (button == MB_MENU_LEAVE)
3932 PlaySound(SND_MENU_ITEM_SELECTING);
3934 info_mode = INFO_MODE_MAIN;
3939 else if (button == MB_MENU_CHOICE)
3941 PlaySound(SND_MENU_ITEM_SELECTING);
3943 FadeMenuSoundsAndMusic();
3945 info_mode = INFO_MODE_MAIN;
3950 PlayMenuSoundIfLoop();
3954 static void DrawInfoScreen_LevelSet(void)
3956 struct TitleMessageInfo *tmi = &readme;
3957 char *filename = getLevelSetInfoFilename();
3958 char *title = "Level Set Information:";
3959 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3960 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3962 if (filename == NULL)
3964 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3969 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3971 FadeOut(REDRAW_FIELD);
3976 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3978 // if x position set to "-1", automatically determine by playfield width
3980 tmi->x = SXSIZE / 2;
3982 // if y position set to "-1", use static default value
3986 // if width set to "-1", automatically determine by playfield width
3987 if (tmi->width == -1)
3988 tmi->width = SXSIZE - 2 * TILEX;
3990 // if height set to "-1", automatically determine by playfield height
3991 if (tmi->height == -1)
3992 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3994 // if chars set to "-1", automatically determine by text and font width
3995 if (tmi->chars == -1)
3996 tmi->chars = tmi->width / getFontWidth(tmi->font);
3998 tmi->width = tmi->chars * getFontWidth(tmi->font);
4000 // if lines set to "-1", automatically determine by text and font height
4001 if (tmi->lines == -1)
4002 tmi->lines = tmi->height / getFontHeight(tmi->font);
4004 tmi->height = tmi->lines * getFontHeight(tmi->font);
4006 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
4007 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
4008 tmi->autowrap, tmi->centered, tmi->parse_comments);
4010 DrawTextSCentered(ybottom, FONT_TEXT_4,
4011 "Press any key or button for info menu");
4013 FadeIn(REDRAW_FIELD);
4016 static void HandleInfoScreen_LevelSet(int button)
4018 if (button == MB_MENU_LEAVE)
4020 PlaySound(SND_MENU_ITEM_SELECTING);
4022 info_mode = INFO_MODE_MAIN;
4027 else if (button == MB_MENU_CHOICE)
4029 PlaySound(SND_MENU_ITEM_SELECTING);
4031 FadeMenuSoundsAndMusic();
4033 info_mode = INFO_MODE_MAIN;
4038 PlayMenuSoundIfLoop();
4042 static void DrawInfoScreen(void)
4044 if (info_mode == INFO_MODE_TITLE)
4045 DrawInfoScreen_TitleScreen();
4046 else if (info_mode == INFO_MODE_ELEMENTS)
4047 DrawInfoScreen_Elements();
4048 else if (info_mode == INFO_MODE_MUSIC)
4049 DrawInfoScreen_Music();
4050 else if (info_mode == INFO_MODE_CREDITS)
4051 DrawInfoScreen_Credits();
4052 else if (info_mode == INFO_MODE_PROGRAM)
4053 DrawInfoScreen_Program();
4054 else if (info_mode == INFO_MODE_VERSION)
4055 DrawInfoScreen_Version();
4056 else if (info_mode == INFO_MODE_LEVELSET)
4057 DrawInfoScreen_LevelSet();
4059 DrawInfoScreen_Main();
4061 if (info_mode != INFO_MODE_MAIN &&
4062 info_mode != INFO_MODE_TITLE &&
4063 info_mode != INFO_MODE_MUSIC)
4064 PlayMenuSoundsAndMusic();
4067 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4069 if (info_mode == INFO_MODE_TITLE)
4070 HandleInfoScreen_TitleScreen(button);
4071 else if (info_mode == INFO_MODE_ELEMENTS)
4072 HandleInfoScreen_Elements(button);
4073 else if (info_mode == INFO_MODE_MUSIC)
4074 HandleInfoScreen_Music(button);
4075 else if (info_mode == INFO_MODE_CREDITS)
4076 HandleInfoScreen_Credits(button);
4077 else if (info_mode == INFO_MODE_PROGRAM)
4078 HandleInfoScreen_Program(button);
4079 else if (info_mode == INFO_MODE_VERSION)
4080 HandleInfoScreen_Version(button);
4081 else if (info_mode == INFO_MODE_LEVELSET)
4082 HandleInfoScreen_LevelSet(button);
4084 HandleInfoScreen_Main(mx, my, dx, dy, button);
4088 // ============================================================================
4089 // rename player API functions
4090 // ============================================================================
4092 struct ApiRenamePlayerThreadData
4098 static void *CreateThreadData_ApiRenamePlayer(void)
4100 struct ApiRenamePlayerThreadData *data =
4101 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4103 data->player_name = getStringCopy(setup.player_name);
4104 data->player_uuid = getStringCopy(setup.player_uuid);
4109 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4111 struct ApiRenamePlayerThreadData *data = data_raw;
4113 checked_free(data->player_name);
4114 checked_free(data->player_uuid);
4118 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4121 struct ApiRenamePlayerThreadData *data = data_raw;
4122 char *player_name_raw = data->player_name;
4123 char *player_uuid_raw = data->player_uuid;
4125 request->hostname = setup.api_server_hostname;
4126 request->port = API_SERVER_PORT;
4127 request->method = API_SERVER_METHOD;
4128 request->uri = API_SERVER_URI_RENAME;
4130 char *player_name = getEscapedJSON(player_name_raw);
4131 char *player_uuid = getEscapedJSON(player_uuid_raw);
4133 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4136 " \"game_version\": \"%s\",\n"
4137 " \"game_platform\": \"%s\",\n"
4138 " \"name\": \"%s\",\n"
4139 " \"uuid\": \"%s\"\n"
4141 getPasswordJSON(setup.api_server_password),
4142 getProgramRealVersionString(),
4143 getProgramPlatformString(),
4147 checked_free(player_name);
4148 checked_free(player_uuid);
4150 ConvertHttpRequestBodyToServerEncoding(request);
4155 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4158 // nothing to do here
4161 #if defined(PLATFORM_EMSCRIPTEN)
4162 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4163 void *buffer, unsigned int size)
4165 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4167 if (response != NULL)
4169 HandleResponse_ApiRenamePlayer(response, data_raw);
4171 checked_free(response);
4175 Error("server response too large to handle (%d bytes)", size);
4178 FreeThreadData_ApiRenamePlayer(data_raw);
4181 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4182 int code, const char *status)
4184 Error("server failed to handle request: %d %s", code, status);
4186 FreeThreadData_ApiRenamePlayer(data_raw);
4189 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4190 int bytes, int size)
4192 // nothing to do here
4195 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4198 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4200 FreeThreadData_ApiRenamePlayer(data_raw);
4205 emscripten_async_wget2_data(request->uri,
4210 Emscripten_ApiRenamePlayer_Loaded,
4211 Emscripten_ApiRenamePlayer_Failed,
4212 Emscripten_ApiRenamePlayer_Progress);
4217 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4218 struct HttpResponse *response,
4221 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4224 if (!DoHttpRequest(request, response))
4226 Error("HTTP request failed: %s", GetHttpError());
4231 if (!HTTP_SUCCESS(response->status_code))
4233 Error("server failed to handle request: %d %s",
4234 response->status_code,
4235 response->status_text);
4240 HandleResponse_ApiRenamePlayer(response, data_raw);
4243 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4244 struct HttpResponse *response,
4247 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4249 FreeThreadData_ApiRenamePlayer(data_raw);
4253 static int ApiRenamePlayerThread(void *data_raw)
4255 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4256 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4258 program.api_thread_count++;
4260 #if defined(PLATFORM_EMSCRIPTEN)
4261 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4263 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4266 program.api_thread_count--;
4268 checked_free(request);
4269 checked_free(response);
4274 static void ApiRenamePlayerAsThread(void)
4276 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4278 ExecuteAsThread(ApiRenamePlayerThread,
4279 "ApiRenamePlayer", data,
4280 "rename player on server");
4284 // ============================================================================
4285 // reset player UUID API functions
4286 // ============================================================================
4288 struct ApiResetUUIDThreadData
4291 char *player_uuid_old;
4292 char *player_uuid_new;
4295 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4297 struct ApiResetUUIDThreadData *data =
4298 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4300 data->player_name = getStringCopy(setup.player_name);
4301 data->player_uuid_old = getStringCopy(setup.player_uuid);
4302 data->player_uuid_new = getStringCopy(uuid_new);
4307 static void FreeThreadData_ApiResetUUID(void *data_raw)
4309 struct ApiResetUUIDThreadData *data = data_raw;
4311 checked_free(data->player_name);
4312 checked_free(data->player_uuid_old);
4313 checked_free(data->player_uuid_new);
4317 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4320 struct ApiResetUUIDThreadData *data = data_raw;
4321 char *player_name_raw = data->player_name;
4322 char *player_uuid_old_raw = data->player_uuid_old;
4323 char *player_uuid_new_raw = data->player_uuid_new;
4325 request->hostname = setup.api_server_hostname;
4326 request->port = API_SERVER_PORT;
4327 request->method = API_SERVER_METHOD;
4328 request->uri = API_SERVER_URI_RESETUUID;
4330 char *player_name = getEscapedJSON(player_name_raw);
4331 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4332 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4334 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4337 " \"game_version\": \"%s\",\n"
4338 " \"game_platform\": \"%s\",\n"
4339 " \"name\": \"%s\",\n"
4340 " \"uuid_old\": \"%s\",\n"
4341 " \"uuid_new\": \"%s\"\n"
4343 getPasswordJSON(setup.api_server_password),
4344 getProgramRealVersionString(),
4345 getProgramPlatformString(),
4350 checked_free(player_name);
4351 checked_free(player_uuid_old);
4352 checked_free(player_uuid_new);
4354 ConvertHttpRequestBodyToServerEncoding(request);
4359 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4362 struct ApiResetUUIDThreadData *data = data_raw;
4364 // upgrade player UUID in server setup file
4365 setup.player_uuid = getStringCopy(data->player_uuid_new);
4366 setup.player_version = 2;
4368 SaveSetup_ServerSetup();
4371 #if defined(PLATFORM_EMSCRIPTEN)
4372 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4373 void *buffer, unsigned int size)
4375 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4377 if (response != NULL)
4379 HandleResponse_ApiResetUUID(response, data_raw);
4381 checked_free(response);
4385 Error("server response too large to handle (%d bytes)", size);
4388 FreeThreadData_ApiResetUUID(data_raw);
4391 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4392 int code, const char *status)
4394 Error("server failed to handle request: %d %s", code, status);
4396 FreeThreadData_ApiResetUUID(data_raw);
4399 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4400 int bytes, int size)
4402 // nothing to do here
4405 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4408 if (!SetRequest_ApiResetUUID(request, data_raw))
4410 FreeThreadData_ApiResetUUID(data_raw);
4415 emscripten_async_wget2_data(request->uri,
4420 Emscripten_ApiResetUUID_Loaded,
4421 Emscripten_ApiResetUUID_Failed,
4422 Emscripten_ApiResetUUID_Progress);
4427 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4428 struct HttpResponse *response,
4431 if (!SetRequest_ApiResetUUID(request, data_raw))
4434 if (!DoHttpRequest(request, response))
4436 Error("HTTP request failed: %s", GetHttpError());
4441 if (!HTTP_SUCCESS(response->status_code))
4443 Error("server failed to handle request: %d %s",
4444 response->status_code,
4445 response->status_text);
4450 HandleResponse_ApiResetUUID(response, data_raw);
4453 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4454 struct HttpResponse *response,
4457 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4459 FreeThreadData_ApiResetUUID(data_raw);
4463 static int ApiResetUUIDThread(void *data_raw)
4465 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4466 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4468 program.api_thread_count++;
4470 #if defined(PLATFORM_EMSCRIPTEN)
4471 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4473 ApiResetUUID_HttpRequest(request, response, data_raw);
4476 program.api_thread_count--;
4478 checked_free(request);
4479 checked_free(response);
4484 static void ApiResetUUIDAsThread(char *uuid_new)
4486 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4488 ExecuteAsThread(ApiResetUUIDThread,
4489 "ApiResetUUID", data,
4490 "reset UUID on server");
4494 // ============================================================================
4495 // type name functions
4496 // ============================================================================
4498 static TreeInfo *type_name_node = NULL;
4499 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4500 static int type_name_nr = 0;
4502 static int getPlayerNameColor(char *name)
4504 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4507 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4510 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4511 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4512 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4513 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4514 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4515 int font_width = getFontWidth(font_nr);
4517 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4519 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4521 pos->width = strlen(text) * font_width;
4522 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4524 DrawText(sx, sy, text, font_nr);
4527 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4529 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4531 *pos = *mci->pos_input;
4533 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4535 TreeInfo *ti = player_name_current;
4536 int first_entry = ti->cl_first;
4537 int entry_pos = first_entry + ti->cl_cursor;
4538 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4539 int xpos = MENU_SCREEN_START_XPOS;
4540 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4542 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4543 type_name_nr = entry_pos;
4545 strcpy(name, type_name_node->name);
4549 pos->width = MAX_PLAYER_NAME_LEN * 32;
4553 type_name_nr = user.nr;
4555 strcpy(name, setup.player_name);
4558 strcpy(type_name_last, name);
4560 if (strEqual(name, EMPTY_PLAYER_NAME))
4563 *xpos = strlen(name);
4566 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4568 // change name of edited user in global list of user names
4569 setString(&global.user_names[type_name_nr], name);
4571 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4573 TreeInfo *node = type_name_node;
4575 // change name of edited user in local menu tree structure
4576 setString(&node->name, name);
4577 setString(&node->name_sorting, name);
4579 node->color = getPlayerNameColor(name);
4580 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4584 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4587 boolean reset_setup = strEqual(name, "");
4588 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4589 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4592 strcpy(name, type_name_last);
4594 if (strEqual(name, ""))
4595 strcpy(name, EMPTY_PLAYER_NAME);
4597 setTypeNameValues_Name(name, pos);
4599 // if player name not changed, no further action required
4600 if (strEqual(name, type_name_last))
4603 // redraw player name before (possibly) opening request dialogs
4604 drawTypeNameText(name, pos, FALSE);
4606 int last_user_nr = user.nr;
4608 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4610 // save setup of currently active user (may differ from edited user)
4613 // temporarily change active user to edited user
4614 user.nr = type_name_nr;
4617 Request("Use current setup values for the new player?", REQ_ASK))
4619 // use current setup values for new user, but create new player UUID
4620 setup.player_uuid = getStringCopy(getUUID());
4624 // load setup for existing user (or start with defaults for new user)
4629 char *setup_filename = getSetupFilename();
4630 boolean setup_exists = fileExists(setup_filename);
4632 // change name of edited user in setup structure
4633 strcpy(setup.player_name, name);
4635 // save setup of edited user
4638 // change name of edited user on score server
4639 ApiRenamePlayerAsThread();
4641 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4645 if (Request("Reset setup values for this player?", REQ_ASK))
4647 // remove setup config file
4648 unlink(setup_filename);
4650 // set player name to default player name
4653 // update player name used by name typing functions
4654 strcpy(name, setup.player_name);
4656 setTypeNameValues_Name(name, pos);
4659 else if (remove_user && type_name_nr != 0)
4661 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4663 char *user_dir = getUserGameDataDir();
4664 char *user_dir_removed =
4665 getStringCat3WithSeparator(user_dir, "REMOVED",
4666 getCurrentTimestamp(), ".");
4668 if (rename(user_dir, user_dir_removed) != 0)
4669 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4671 checked_free(user_dir_removed);
4674 else if (create_user && type_name_nr != 0 && !setup_exists)
4676 if (Request("Create empty level set for the new player?", REQ_ASK))
4678 char *levelset_subdir = getNewUserLevelSubdir();
4680 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4682 AddUserLevelSetToLevelInfo(levelset_subdir);
4684 LevelDirTree *leveldir_current_last = leveldir_current;
4686 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4689 // set level number of newly created level set to default value
4690 LoadLevelSetup_SeriesInfo();
4692 // set newly created level set as current level set for new user
4693 SaveLevelSetup_LastSeries();
4694 SaveLevelSetup_SeriesInfo();
4696 leveldir_current = leveldir_current_last;
4700 Request("Creating new level set failed!", REQ_CONFIRM);
4705 // restore currently active user
4706 user.nr = last_user_nr;
4708 // restore setup of currently active user
4711 // restore last level set of currently active user
4712 LoadLevelSetup_LastSeries();
4713 LoadLevelSetup_SeriesInfo();
4717 static void HandleTypeNameExt(boolean initialize, Key key)
4719 static struct TextPosInfo pos_name = { 0 };
4720 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4721 static int xpos = 0;
4722 struct TextPosInfo *pos = &pos_name;
4723 char key_char = getValidConfigValueChar(getCharFromKey(key));
4724 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4725 boolean active = TRUE;
4729 getTypeNameValues(name, pos, &xpos);
4731 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4732 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4734 StartTextInput(sx, sy, pos->width, pos->height);
4736 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4738 name[xpos] = key_char;
4743 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4749 else if (key == KSYM_Return || key == KSYM_Escape)
4751 boolean changed = (key == KSYM_Return);
4755 setTypeNameValues(name, pos, changed);
4760 drawTypeNameText(name, pos, active);
4764 SetGameStatus(game_status_last_screen);
4766 if (game_status == GAME_MODE_MAIN)
4767 InitializeMainControls();
4771 static void DrawTypeName(void)
4773 HandleTypeNameExt(TRUE, 0);
4776 void HandleTypeName(Key key)
4778 HandleTypeNameExt(FALSE, key);
4782 // ============================================================================
4783 // tree menu functions
4784 // ============================================================================
4786 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4788 if (game_status != GAME_MODE_SETUP ||
4789 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4792 int max_text_size = 0;
4795 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4796 max_text_size = MAX(max_text_size, strlen(node->name));
4798 int num_entries = numTreeInfoInGroup(ti);
4799 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4800 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4801 int text_width = max_text_size * getFontWidth(font_nr);
4802 int button_width = SC_MENUBUTTON_XSIZE;
4803 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4804 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4805 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4806 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4807 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4808 int align_xoffset = MAX(0, align_xoffset_raw);
4810 return align_xoffset;
4813 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4815 if (game_status != GAME_MODE_SETUP ||
4816 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4819 int num_entries = numTreeInfoInGroup(ti);
4820 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4821 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4822 int font_height = getFontHeight(font_nr);
4823 int text_height = font_height * num_page_entries;
4824 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4825 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4826 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4827 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4828 int align_yoffset = MAX(0, align_yoffset_raw);
4830 return align_yoffset;
4833 static void DrawChooseTree(TreeInfo **ti_ptr)
4835 int fade_mask = REDRAW_FIELD;
4836 boolean restart_music = (game_status != game_status_last_screen &&
4837 game_status_last_screen != GAME_MODE_SCOREINFO);
4840 fade_mask = REDRAW_ALL;
4842 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4844 if (game_status == GAME_MODE_SETUP)
4848 else // GAME_MODE_LEVELS
4850 SetGameStatus(GAME_MODE_MAIN);
4860 FreeScreenGadgets();
4861 CreateScreenGadgets();
4864 FadeMenuSoundsAndMusic();
4868 // needed if different viewport properties defined for this screen
4869 ChangeViewportPropertiesIfNeeded();
4871 if (game_status == GAME_MODE_NAMES)
4872 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4873 else if (game_status == GAME_MODE_LEVELNR)
4874 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4875 else if (game_status == GAME_MODE_LEVELS)
4876 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4877 else if (game_status == GAME_MODE_SCORES)
4878 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4882 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4884 // map gadgets for high score screen
4885 if (game_status == GAME_MODE_SCORES)
4886 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4888 MapScreenTreeGadgets(*ti_ptr);
4890 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4892 DrawMaskedBorder(fade_mask);
4895 PlayMenuSoundsAndMusic();
4900 static int getChooseTreeFont(TreeInfo *node, boolean active)
4902 if (game_status == GAME_MODE_SCORES)
4903 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4905 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4908 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4910 int num_entries = numTreeInfoInGroup(ti);
4911 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4912 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4913 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4914 int first_entry = ti->cl_first;
4915 int entry_pos = first_entry + y;
4916 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4917 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4918 int font_nr = getChooseTreeFont(node, active);
4919 int font_xoffset = getFontDrawOffsetX(font_nr);
4920 int xpos = MENU_SCREEN_START_XPOS;
4921 int ypos = MENU_SCREEN_START_YPOS + y;
4922 int startdx = xpos * 32;
4923 int startdy = ypos * 32;
4924 int startx = amSX + startdx;
4925 int starty = amSY + startdy;
4926 int startx_text = startx + font_xoffset;
4927 int endx_text = amSX + screen_width;
4928 int max_text_size = endx_text - startx_text;
4929 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4930 char buffer[max_buffer_len + 1];
4932 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4934 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4935 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4936 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4937 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4938 int font_size_1 = getFontWidth(font_nr1);
4939 int font_size_3 = getFontWidth(font_nr3);
4940 int font_size_4 = getFontWidth(font_nr4);
4941 int text_size_1 = 4 * font_size_1;
4942 int text_size_4 = 5 * font_size_4;
4943 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4945 int dx3 = text_size_1;
4946 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4947 int num_dots = (dx4 - dx3) / font_size_3;
4948 int startx1 = startx + dx1;
4949 int startx3 = startx + dx3;
4950 int startx4 = startx + dx4;
4951 int pos = node->pos;
4952 char *pos_text = getHallOfFameRankText(pos, 3);
4955 DrawText(startx1, starty, pos_text, font_nr1);
4957 for (i = 0; i < num_dots; i++)
4958 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4960 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4961 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4963 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4967 strncpy(buffer, node->name, max_buffer_len);
4968 buffer[max_buffer_len] = '\0';
4970 DrawText(startx, starty, buffer, font_nr);
4974 static void drawChooseTreeHeadExt(int type, char *title_string)
4976 int yoffset_sets = MENU_TITLE1_YPOS;
4977 int yoffset_setup = 16;
4978 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4979 type == TREE_TYPE_LEVEL_DIR ||
4980 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4982 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4985 static void drawChooseTreeHead(TreeInfo *ti)
4987 drawChooseTreeHeadExt(ti->type, ti->infotext);
4990 static void drawChooseTreeList(TreeInfo *ti)
4992 int first_entry = ti->cl_first;
4993 int num_entries = numTreeInfoInGroup(ti);
4994 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4997 clearMenuListArea();
4999 for (i = 0; i < num_page_entries; i++)
5001 TreeInfo *node, *node_first;
5002 int entry_pos = first_entry + i;
5004 node_first = getTreeInfoFirstGroupEntry(ti);
5005 node = getTreeInfoFromPos(node_first, entry_pos);
5007 drawChooseTreeText(ti, i, FALSE);
5009 if (node->parent_link)
5010 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5011 else if (node->level_group)
5012 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5014 initCursor(i, IMG_MENU_BUTTON);
5016 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
5017 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5019 if (game_status == GAME_MODE_NAMES)
5020 drawChooseTreeEdit(i, FALSE);
5023 redraw_mask |= REDRAW_FIELD;
5026 static void drawChooseTreeInfo(TreeInfo *ti)
5028 int entry_pos = ti->cl_first + ti->cl_cursor;
5029 int last_redraw_mask = redraw_mask;
5030 int ypos = MENU_TITLE2_YPOS;
5031 int font_nr = FONT_TITLE_2;
5034 if (ti->type == TREE_TYPE_LEVEL_NR)
5035 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
5037 if (ti->type == TREE_TYPE_SCORE_ENTRY)
5038 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
5039 scores.last_level_nr);
5041 if (ti->type != TREE_TYPE_LEVEL_DIR)
5044 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
5045 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
5047 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
5049 if (node->parent_link)
5050 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
5051 node->node_parent->name);
5052 else if (node->level_group)
5053 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
5055 else if (ti->type == TREE_TYPE_LEVEL_DIR)
5056 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
5057 node->levels, (node->levels > 1 ? "levels" : "level"),
5060 // let BackToFront() redraw only what is needed
5061 redraw_mask = last_redraw_mask;
5062 for (x = 0; x < SCR_FIELDX; x++)
5063 MarkTileDirty(x, 1);
5066 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
5068 drawChooseTreeCursor(ti->cl_cursor, active);
5069 drawChooseTreeText(ti, ti->cl_cursor, active);
5072 static void drawChooseTreeScreen(TreeInfo *ti)
5074 drawChooseTreeHead(ti);
5075 drawChooseTreeList(ti);
5076 drawChooseTreeInfo(ti);
5077 drawChooseTreeCursorAndText(ti, TRUE);
5079 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
5081 // scroll bar and buttons may just have been added after reloading scores
5082 if (game_status == GAME_MODE_SCORES)
5083 MapScreenTreeGadgets(ti);
5086 static void drawChooseTreeScreen_Scores_NotAvailable(void)
5088 // dirty workaround to use spacing definitions from info screen
5089 info_mode = INFO_MODE_TITLE;
5091 char *text_info = "HighScores of Level %d";
5092 char *text_title = "Score information:";
5093 char *text_error = "No scores for this level.";
5094 char *text_foot = "Press any key or button for main menu";
5095 int font_info = FONT_TITLE_2;
5096 int font_title = FONT_INITIAL_3;
5097 int font_error = FONT_INITIAL_4;
5098 int font_foot = FONT_INITIAL_2;
5099 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
5100 int ystep_title = getMenuTextStep(spacing_title, font_title);
5101 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
5102 int ystart2 = ystart1 + ystep_title;
5103 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
5104 int ystart0 = MENU_TITLE2_YPOS;
5106 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
5107 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
5109 DrawTextSCentered(ystart1, font_title, text_title);
5110 DrawTextSCentered(ystart2, font_error, text_error);
5112 DrawTextSCentered(ybottom, font_foot, text_foot);
5115 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
5117 int score_pos = scores.last_added;
5119 if (game_status_last_screen == GAME_MODE_SCOREINFO)
5120 score_pos = scores.last_entry_nr;
5122 // set current tree entry to last added score entry
5123 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5125 // if that fails, set current tree entry to first entry (back link)
5126 if (*ti_ptr == NULL)
5127 *ti_ptr = score_entries->node_group;
5129 int num_entries = numTreeInfoInGroup(*ti_ptr);
5130 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5131 int pos_score = getPosFromTreeInfo(*ti_ptr);
5132 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5133 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5135 (*ti_ptr)->cl_first = pos_first;
5136 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5141 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5144 TreeInfo *ti = *ti_ptr;
5145 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5146 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5147 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5148 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5149 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5151 int y = (ti != NULL ? ti->cl_cursor : 0);
5152 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5153 int num_entries = numTreeInfoInGroup(ti);
5154 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5155 boolean position_set_by_scrollbar = (dx == 999);
5156 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5157 boolean button_is_valid = (mx >= 0 && my >= 0);
5158 boolean button_screen_clicked = (button_action && button_is_valid);
5160 if (game_status == GAME_MODE_SCORES)
5162 if (server_scores.updated)
5164 // reload scores, using updated server score cache file
5165 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5167 server_scores.updated = FALSE;
5169 DrawHallOfFame_setScoreEntries();
5171 if (score_entries != NULL)
5173 ti = setHallOfFameActiveEntry(ti_ptr);
5175 if (button != MB_MENU_INITIALIZE)
5176 drawChooseTreeScreen(ti);
5180 if (score_entries == NULL)
5182 if (button == MB_MENU_INITIALIZE)
5184 drawChooseTreeScreen_Scores_NotAvailable();
5186 else if (button_screen_clicked)
5188 PlaySound(SND_MENU_ITEM_SELECTING);
5190 SetGameStatus(GAME_MODE_MAIN);
5199 if (button == MB_MENU_INITIALIZE)
5201 int num_entries = numTreeInfoInGroup(ti);
5202 int entry_pos = getPosFromTreeInfo(ti);
5204 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5205 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5207 if (game_status == GAME_MODE_SCORES)
5209 ti = setHallOfFameActiveEntry(ti_ptr);
5211 else if (ti->cl_first == -1)
5213 // only on initialization
5214 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5215 ti->cl_cursor = entry_pos - ti->cl_first;
5218 else if (ti->cl_cursor >= num_page_entries ||
5219 (num_entries > num_page_entries &&
5220 num_entries - ti->cl_first < num_page_entries))
5222 // only after change of list size (by custom graphic configuration)
5223 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5224 ti->cl_cursor = entry_pos - ti->cl_first;
5227 if (position_set_by_scrollbar)
5230 drawChooseTreeScreen(ti);
5234 else if (button == MB_MENU_LEAVE)
5236 if (game_status != GAME_MODE_SCORES)
5239 PlaySound(SND_MENU_ITEM_SELECTING);
5241 if (ti->node_parent)
5243 *ti_ptr = ti->node_parent;
5244 DrawChooseTree(ti_ptr);
5246 else if (game_status == GAME_MODE_SETUP)
5248 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5249 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5250 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5251 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5253 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5254 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5255 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5256 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5257 execSetupGraphics();
5258 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5259 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5260 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5262 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5263 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5264 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5265 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5266 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5267 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5268 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5269 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5276 if (game_status == GAME_MODE_LEVELNR)
5278 int new_level_nr = atoi(level_number_current->identifier);
5280 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5283 SetGameStatus(GAME_MODE_MAIN);
5291 if (mx || my) // mouse input
5293 x = (mx - amSX) / 32;
5294 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5296 if (game_status == GAME_MODE_NAMES)
5297 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5299 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5301 // move cursor instead of scrolling when already at start/end of list
5302 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5304 else if (dy == +1 * SCROLL_LINE &&
5305 ti->cl_first + num_page_entries == num_entries)
5308 // handle scrolling screen one line or page
5309 if (ti->cl_cursor + dy < 0 ||
5310 ti->cl_cursor + dy > num_page_entries - 1)
5312 boolean redraw = FALSE;
5314 if (ABS(dy) == SCROLL_PAGE)
5315 step = num_page_entries - 1;
5317 if (dy < 0 && ti->cl_first > 0)
5319 // scroll page/line up
5321 ti->cl_first -= step;
5322 if (ti->cl_first < 0)
5327 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5329 // scroll page/line down
5331 ti->cl_first += step;
5332 if (ti->cl_first + num_page_entries > num_entries)
5333 ti->cl_first = MAX(0, num_entries - num_page_entries);
5339 drawChooseTreeScreen(ti);
5344 // handle moving cursor one line
5345 y = ti->cl_cursor + dy;
5348 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5350 HandleHallOfFame_SelectLevel(1, dx);
5356 TreeInfo *node_first, *node_cursor;
5357 int entry_pos = ti->cl_first + y;
5359 node_first = getTreeInfoFirstGroupEntry(ti);
5360 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5362 if (node_cursor->node_group)
5366 PlaySound(SND_MENU_ITEM_SELECTING);
5368 node_cursor->cl_first = ti->cl_first;
5369 node_cursor->cl_cursor = ti->cl_cursor;
5370 *ti_ptr = node_cursor->node_group;
5371 DrawChooseTree(ti_ptr);
5376 else if (dx == -1 && ti->node_parent)
5380 PlaySound(SND_MENU_ITEM_SELECTING);
5382 *ti_ptr = ti->node_parent;
5383 DrawChooseTree(ti_ptr);
5388 if (!anyScrollbarGadgetActive() &&
5389 IN_VIS_MENU(x, y) &&
5390 mx < mx_right_border &&
5391 y >= 0 && y < num_page_entries)
5395 if (game_status == GAME_MODE_NAMES)
5397 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5398 drawChooseTreeEdit(y, TRUE);
5401 if (y != ti->cl_cursor)
5403 PlaySound(SND_MENU_ITEM_ACTIVATING);
5405 drawChooseTreeCursorAndText(ti, FALSE);
5409 drawChooseTreeCursorAndText(ti, TRUE);
5411 drawChooseTreeInfo(ti);
5415 if (game_status == GAME_MODE_SETUP)
5417 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5418 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5419 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5420 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5422 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5423 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5424 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5425 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5426 execSetupGraphics();
5427 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5428 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5429 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5431 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5432 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5433 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5434 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5435 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5436 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5437 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5438 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5447 TreeInfo *node_first, *node_cursor;
5448 int entry_pos = ti->cl_first + y;
5450 PlaySound(SND_MENU_ITEM_SELECTING);
5452 node_first = getTreeInfoFirstGroupEntry(ti);
5453 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5455 if (node_cursor->node_group)
5459 node_cursor->cl_first = ti->cl_first;
5460 node_cursor->cl_cursor = ti->cl_cursor;
5461 *ti_ptr = node_cursor->node_group;
5462 DrawChooseTree(ti_ptr);
5464 else if (node_cursor->parent_link)
5466 if (game_status != GAME_MODE_SCORES)
5469 *ti_ptr = node_cursor->node_parent;
5470 DrawChooseTree(ti_ptr);
5474 if (game_status != GAME_MODE_SCORES)
5477 node_cursor->cl_first = ti->cl_first;
5478 node_cursor->cl_cursor = ti->cl_cursor;
5479 *ti_ptr = node_cursor;
5481 if (ti->type == TREE_TYPE_LEVEL_DIR)
5483 LoadLevelSetup_SeriesInfo();
5485 SaveLevelSetup_LastSeries();
5486 SaveLevelSetup_SeriesInfo();
5490 if (game_status == GAME_MODE_SETUP)
5492 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5493 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5494 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5495 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5497 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5498 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5499 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5500 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5501 execSetupGraphics();
5502 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5503 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5504 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5506 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5507 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5508 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5509 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5510 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5511 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5512 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5513 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5520 if (game_status == GAME_MODE_LEVELNR)
5522 int new_level_nr = atoi(level_number_current->identifier);
5524 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5526 else if (game_status == GAME_MODE_LEVELS)
5528 // store level set if chosen from "last played level set" menu
5529 StoreLastPlayedLevels(leveldir_current);
5531 else if (game_status == GAME_MODE_NAMES)
5533 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5535 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5542 // change active user to selected user
5543 user.nr = entry_pos;
5545 // save number of new active user
5548 // load setup of new active user
5551 // load last level set of new active user
5552 LoadLevelSetup_LastSeries();
5553 LoadLevelSetup_SeriesInfo();
5555 // update list of last played level sets
5556 UpdateLastPlayedLevels_TreeInfo();
5560 ToggleFullscreenIfNeeded();
5561 ChangeWindowScalingIfNeeded();
5563 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5564 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5565 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5567 else if (game_status == GAME_MODE_SCORES)
5569 if (game_status_last_screen == GAME_MODE_PLAYING &&
5570 setup.auto_play_next_level && setup.increment_levels &&
5571 scores.last_level_nr < leveldir_current->last_level &&
5574 StartGameActions(network.enabled, setup.autorecord,
5580 SetGameStatus(GAME_MODE_SCOREINFO);
5582 DrawScoreInfo(node_cursor->pos);
5588 SetGameStatus(GAME_MODE_MAIN);
5596 if (game_status == GAME_MODE_SCORES)
5597 PlayMenuSoundIfLoop();
5600 void DrawChoosePlayerName(void)
5604 if (player_name != NULL)
5606 freeTreeInfo(player_name);
5611 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5613 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5614 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5617 ti->node_top = &player_name;
5618 ti->sort_priority = 10000 + value;
5619 ti->color = getPlayerNameColor(global.user_names[i]);
5621 snprintf(identifier, sizeof(identifier), "%d", value);
5622 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5624 setString(&ti->identifier, identifier);
5625 setString(&ti->name, name);
5626 setString(&ti->name_sorting, name);
5628 pushTreeInfo(&player_name, ti);
5631 // sort player entries by player number
5632 sortTreeInfo(&player_name);
5634 // set current player entry to selected player entry
5635 player_name_current =
5636 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5638 // if that fails, set current player name to first available name
5639 if (player_name_current == NULL)
5640 player_name_current = player_name;
5642 DrawChooseTree(&player_name_current);
5645 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5647 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5650 void DrawChooseLevelSet(void)
5652 DrawChooseTree(&leveldir_current);
5655 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5657 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5660 void DrawChooseLevelNr(void)
5664 if (level_number != NULL)
5666 freeTreeInfo(level_number);
5668 level_number = NULL;
5671 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5673 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5674 char identifier[32], name[64];
5677 // temporarily load level info to get level name
5678 LoadLevelInfoOnly(i);
5680 ti->node_top = &level_number;
5681 ti->sort_priority = 10000 + value;
5682 ti->color = (level.no_level_file ? FC_BLUE :
5683 LevelStats_getSolved(i) ? FC_GREEN :
5684 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5686 snprintf(identifier, sizeof(identifier), "%d", value);
5687 snprintf(name, sizeof(name), "%03d: %s", value,
5688 (level.no_level_file ? "(no file)" : level.name));
5690 setString(&ti->identifier, identifier);
5691 setString(&ti->name, name);
5692 setString(&ti->name_sorting, name);
5694 pushTreeInfo(&level_number, ti);
5697 // sort level number values to start with lowest level number
5698 sortTreeInfo(&level_number);
5700 // set current level number to current level number
5701 level_number_current =
5702 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5704 // if that also fails, set current level number to first available level
5705 if (level_number_current == NULL)
5706 level_number_current = level_number;
5708 DrawChooseTree(&level_number_current);
5711 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5713 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5716 static void DrawHallOfFame_setScoreEntries(void)
5718 int max_empty_entries = 10; // at least show "top ten" list, if empty
5719 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5720 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5721 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5724 if (score_entries != NULL)
5726 freeTreeInfo(score_entries);
5728 score_entries = NULL;
5731 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5733 // do not add empty score entries if off-screen
5734 if (scores.entry[i].score == 0 &&
5735 scores.entry[i].time == 0 &&
5736 i >= min_score_entries)
5739 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5740 char identifier[32], name[64];
5743 ti->node_top = &score_entries;
5744 ti->sort_priority = 10000 + value;
5745 ti->color = FC_YELLOW;
5748 snprintf(identifier, sizeof(identifier), "%d", value);
5749 snprintf(name, sizeof(name), "%03d.", value + 1);
5751 setString(&ti->identifier, identifier);
5752 setString(&ti->name, name);
5753 setString(&ti->name_sorting, name);
5755 pushTreeInfo(&score_entries, ti);
5758 // sort score entries to start with highest score entry
5759 sortTreeInfo(&score_entries);
5761 // add top tree node to create back link to main menu
5762 score_entries = addTopTreeInfoNode(score_entries);
5764 // set current score entry to last added or highest score entry
5765 score_entry_current =
5766 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5768 // if that fails, set current score entry to first valid score entry
5769 if (score_entry_current == NULL)
5770 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5772 // ("score_entries" and "score_entry_current" may be NULL here)
5775 void DrawHallOfFame(int level_nr)
5777 scores.last_level_nr = level_nr;
5779 // (this is needed when called from GameEnd() after winning a game)
5780 KeyboardAutoRepeatOn();
5782 // (this is needed when called from GameEnd() after winning a game)
5783 SetDrawDeactivationMask(REDRAW_NONE);
5784 SetDrawBackgroundMask(REDRAW_FIELD);
5786 LoadLocalAndServerScore(level_nr, TRUE);
5788 DrawHallOfFame_setScoreEntries();
5790 if (scores.last_added >= 0)
5791 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5793 FadeSetEnterScreen();
5795 DrawChooseTree(&score_entry_current);
5798 static char *getHallOfFameRankText(int nr, int size)
5800 static char rank_text[10];
5801 boolean forced = (scores.force_last_added && nr == scores.last_added);
5802 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5804 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5809 static char *getHallOfFameTimeText(int nr)
5811 static char score_text[10];
5812 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5813 int mm = (time_seconds / 60) % 60;
5814 int ss = (time_seconds % 60);
5816 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5821 static char *getHallOfFameScoreText(int nr, int size)
5823 if (!level.rate_time_over_score)
5824 return int2str(scores.entry[nr].score, size); // show normal score
5825 else if (level.use_step_counter)
5826 return int2str(scores.entry[nr].time, size); // show number of steps
5828 return getHallOfFameTimeText(nr); // show playing time
5831 static void HandleHallOfFame_SelectLevel(int step, int direction)
5833 int old_level_nr = scores.last_level_nr;
5834 int new_level_nr = old_level_nr + step * direction;
5836 if (new_level_nr < leveldir_current->first_level)
5837 new_level_nr = leveldir_current->first_level;
5838 if (new_level_nr > leveldir_current->last_level)
5839 new_level_nr = leveldir_current->last_level;
5841 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5842 new_level_nr = leveldir_current->handicap_level;
5844 if (new_level_nr != old_level_nr)
5846 PlaySound(SND_MENU_ITEM_SELECTING);
5848 scores.last_level_nr = level_nr = new_level_nr;
5849 scores.last_entry_nr = 0;
5851 LoadLevel(level_nr);
5852 LoadLocalAndServerScore(level_nr, TRUE);
5854 DrawHallOfFame_setScoreEntries();
5856 if (game_status == GAME_MODE_SCORES)
5858 // force remapping optional gadgets (especially scroll bar)
5859 UnmapScreenTreeGadgets();
5861 // redraw complete high score screen, as sub-title has changed
5864 // redraw level selection buttons (which have just been erased)
5865 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5867 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5871 DrawScoreInfo_Content(scores.last_entry_nr);
5874 SaveLevelSetup_SeriesInfo();
5878 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5880 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5883 static void DrawScoreInfo_Content(int entry_nr)
5885 struct ScoreEntry *entry = &scores.entry[entry_nr];
5886 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5887 int font_title = MENU_INFO_FONT_TITLE;
5888 int font_head = MENU_INFO_FONT_HEAD;
5889 int font_text = MENU_INFO_FONT_TEXT;
5890 int font_foot = MENU_INFO_FONT_FOOT;
5891 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5892 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5893 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5894 int xstep = getFontWidth(font_text);
5895 int ystep_title = getMenuTextStep(spacing_title, font_title);
5896 int ystep_para = getMenuTextStep(spacing_para, font_text);
5897 int ystep_line = getMenuTextStep(spacing_line, font_text);
5898 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5899 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5900 int xstart1 = mSX - SX + 2 * xstep;
5901 int xstart2 = mSX - SX + 13 * xstep;
5902 int button_x = SX + xstart1;
5903 int button_y1, button_y2;
5904 int font_width = getFontWidth(font_text);
5905 int font_height = getFontHeight(font_text);
5906 int pad_left = xstart2;
5907 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
5908 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5909 int max_lines_per_text = 5;
5914 // redraw score selection buttons (which have just been erased)
5915 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5917 if (score_entries == NULL)
5919 drawChooseTreeScreen_Scores_NotAvailable();
5924 drawChooseTreeHead(score_entries);
5925 drawChooseTreeInfo(score_entries);
5927 DrawTextSCentered(ystart, font_title, "Score Information:");
5928 ystart += ystep_title;
5930 DrawTextF(xstart1, ystart, font_head, "Level Set");
5931 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5932 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5933 TRUE, FALSE, FALSE);
5934 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5936 DrawTextF(xstart1, ystart, font_head, "Level");
5937 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5938 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5939 TRUE, FALSE, FALSE);
5940 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5942 button_y1 = SY + ystart;
5943 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5945 DrawTextF(xstart1, ystart, font_head, "Rank");
5946 DrawTextF(xstart2, ystart, font_text, pos_text);
5947 ystart += ystep_line;
5949 DrawTextF(xstart1, ystart, font_head, "Player");
5950 DrawTextF(xstart2, ystart, font_text, entry->name);
5951 ystart += ystep_line;
5953 if (level.use_step_counter)
5955 DrawTextF(xstart1, ystart, font_head, "Steps");
5956 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5957 ystart += ystep_line;
5961 DrawTextF(xstart1, ystart, font_head, "Time");
5962 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5963 ystart += ystep_line;
5966 if (!level.rate_time_over_score || entry->score > 0)
5968 DrawTextF(xstart1, ystart, font_head, "Score");
5969 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5970 ystart += ystep_line;
5973 ystart += ystep_line;
5975 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5976 DrawTextF(xstart2, ystart, font_text, entry->tape_date);
5977 ystart += ystep_line;
5979 DrawTextF(xstart1, ystart, font_head, "Platform");
5980 DrawTextF(xstart2, ystart, font_text, entry->platform);
5981 ystart += ystep_line;
5983 DrawTextF(xstart1, ystart, font_head, "Version");
5984 DrawTextF(xstart2, ystart, font_text, entry->version);
5985 ystart += ystep_line;
5987 DrawTextF(xstart1, ystart, font_head, "Country");
5988 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5989 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5990 TRUE, FALSE, FALSE);
5991 ystart += ystep_line;
5993 button_y2 = SY + ystart;
5995 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5997 AdjustScoreInfoButtons(button_x, button_y1, button_y2);
6000 static void DrawScoreInfo(int entry_nr)
6002 scores.last_entry_nr = entry_nr;
6004 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
6008 FadeOut(REDRAW_FIELD);
6010 DrawScoreInfo_Content(entry_nr);
6012 // map gadgets for score info screen
6013 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
6015 FadeIn(REDRAW_FIELD);
6018 static void HandleScoreInfo_SelectScore(int step, int direction)
6020 int old_entry_nr = scores.last_entry_nr;
6021 int new_entry_nr = old_entry_nr + step * direction;
6022 int num_nodes = numTreeInfoInGroup(score_entry_current);
6023 int num_entries = num_nodes - 1; // score nodes only, without back link
6025 if (new_entry_nr < 0)
6027 if (new_entry_nr > num_entries - 1)
6028 new_entry_nr = num_entries - 1;
6030 if (new_entry_nr != old_entry_nr)
6032 scores.last_entry_nr = new_entry_nr;
6034 DrawScoreInfo_Content(new_entry_nr);
6038 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
6040 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
6041 boolean button_is_valid = (mx >= 0 && my >= 0);
6042 boolean button_screen_clicked = (button_action && button_is_valid);
6044 if (server_scores.updated)
6046 // reload scores, using updated server score cache file
6047 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
6049 server_scores.updated = FALSE;
6051 DrawHallOfFame_setScoreEntries();
6053 DrawScoreInfo_Content(scores.last_entry_nr);
6056 if (button_screen_clicked)
6058 PlaySound(SND_MENU_ITEM_SELECTING);
6060 SetGameStatus(GAME_MODE_SCORES);
6062 DrawHallOfFame(level_nr);
6066 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
6070 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
6075 // ============================================================================
6076 // setup screen functions
6077 // ============================================================================
6079 static struct TokenInfo *setup_info;
6080 static int num_setup_info; // number of setup entries shown on screen
6081 static int max_setup_info; // total number of setup entries in list
6083 static char *window_size_text;
6084 static char *scaling_type_text;
6085 static char *rendering_mode_text;
6086 static char *vsync_mode_text;
6087 static char *scroll_delay_text;
6088 static char *snapshot_mode_text;
6089 static char *game_speed_text;
6090 static char *scores_type_text;
6091 static char *network_server_text;
6092 static char *graphics_set_name;
6093 static char *sounds_set_name;
6094 static char *music_set_name;
6095 static char *volume_simple_text;
6096 static char *volume_loops_text;
6097 static char *volume_music_text;
6098 static char *touch_controls_text;
6099 static char *move_distance_text;
6100 static char *drop_distance_text;
6101 static char *transparency_text;
6102 static char *grid_size_text[2][2];
6104 static void execSetupMain(void)
6106 setup_mode = SETUP_MODE_MAIN;
6111 static void execSetupGame_setScoresType(void)
6113 if (scores_types == NULL)
6117 for (i = 0; scores_types_list[i].value != NULL; i++)
6119 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6120 char identifier[32], name[32];
6121 char *value = scores_types_list[i].value;
6122 char *text = scores_types_list[i].text;
6124 ti->node_top = &scores_types;
6125 ti->sort_priority = i;
6127 sprintf(identifier, "%s", value);
6128 sprintf(name, "%s", text);
6130 setString(&ti->identifier, identifier);
6131 setString(&ti->name, name);
6132 setString(&ti->name_sorting, name);
6133 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
6135 pushTreeInfo(&scores_types, ti);
6138 // sort scores type values to start with lowest scores type value
6139 sortTreeInfo(&scores_types);
6141 // set current scores type value to configured scores type value
6142 scores_type_current =
6143 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
6145 // if that fails, set current scores type to reliable default value
6146 if (scores_type_current == NULL)
6147 scores_type_current =
6148 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
6150 // if that also fails, set current scores type to first available value
6151 if (scores_type_current == NULL)
6152 scores_type_current = scores_types;
6155 setup.scores_in_highscore_list = scores_type_current->identifier;
6157 // needed for displaying scores type text instead of identifier
6158 scores_type_text = scores_type_current->name;
6161 static void execSetupGame_setGameSpeeds(boolean update_value)
6163 if (setup.game_speed_extended)
6165 game_speeds_list = game_speeds_list_extended;
6166 game_speeds = game_speeds_extended;
6170 game_speeds_list = game_speeds_list_normal;
6171 game_speeds = game_speeds_normal;
6174 if (game_speeds == NULL)
6178 for (i = 0; game_speeds_list[i].value != -1; i++)
6180 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6181 char identifier[32], name[32];
6182 int value = game_speeds_list[i].value;
6183 char *text = game_speeds_list[i].text;
6185 ti->node_top = &game_speeds;
6186 ti->sort_priority = 10000 - value;
6188 sprintf(identifier, "%d", value);
6189 sprintf(name, "%s", text);
6191 setString(&ti->identifier, identifier);
6192 setString(&ti->name, name);
6193 setString(&ti->name_sorting, name);
6194 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
6196 pushTreeInfo(&game_speeds, ti);
6199 // sort game speed values to start with slowest game speed
6200 sortTreeInfo(&game_speeds);
6202 update_value = TRUE;
6207 // set current game speed to configured game speed value
6208 game_speed_current =
6209 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6211 // if that fails, set current game speed to reliable default value
6212 if (game_speed_current == NULL)
6213 game_speed_current =
6214 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6216 // if that also fails, set current game speed to first available speed
6217 if (game_speed_current == NULL)
6218 game_speed_current = game_speeds;
6220 if (setup.game_speed_extended)
6221 game_speeds_extended = game_speeds;
6223 game_speeds_normal = game_speeds;
6226 setup.game_frame_delay = atoi(game_speed_current->identifier);
6228 // needed for displaying game speed text instead of identifier
6229 game_speed_text = game_speed_current->name;
6232 static void execSetupGame_setScrollDelays(void)
6234 if (scroll_delays == NULL)
6238 for (i = 0; scroll_delays_list[i].value != -1; i++)
6240 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6241 char identifier[32], name[32];
6242 int value = scroll_delays_list[i].value;
6243 char *text = scroll_delays_list[i].text;
6245 ti->node_top = &scroll_delays;
6246 ti->sort_priority = value;
6248 sprintf(identifier, "%d", value);
6249 sprintf(name, "%s", text);
6251 setString(&ti->identifier, identifier);
6252 setString(&ti->name, name);
6253 setString(&ti->name_sorting, name);
6254 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6256 pushTreeInfo(&scroll_delays, ti);
6259 // sort scroll delay values to start with lowest scroll delay value
6260 sortTreeInfo(&scroll_delays);
6262 // set current scroll delay value to configured scroll delay value
6263 scroll_delay_current =
6264 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6266 // if that fails, set current scroll delay to reliable default value
6267 if (scroll_delay_current == NULL)
6268 scroll_delay_current =
6269 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6271 // if that also fails, set current scroll delay to first available value
6272 if (scroll_delay_current == NULL)
6273 scroll_delay_current = scroll_delays;
6276 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6278 // needed for displaying scroll delay text instead of identifier
6279 scroll_delay_text = scroll_delay_current->name;
6282 static void execSetupGame_setSnapshotModes(void)
6284 if (snapshot_modes == NULL)
6288 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6290 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6291 char identifier[32], name[32];
6292 char *value = snapshot_modes_list[i].value;
6293 char *text = snapshot_modes_list[i].text;
6295 ti->node_top = &snapshot_modes;
6296 ti->sort_priority = i;
6298 sprintf(identifier, "%s", value);
6299 sprintf(name, "%s", text);
6301 setString(&ti->identifier, identifier);
6302 setString(&ti->name, name);
6303 setString(&ti->name_sorting, name);
6304 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6306 pushTreeInfo(&snapshot_modes, ti);
6309 // sort snapshot mode values to start with lowest snapshot mode value
6310 sortTreeInfo(&snapshot_modes);
6312 // set current snapshot mode value to configured snapshot mode value
6313 snapshot_mode_current =
6314 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6316 // if that fails, set current snapshot mode to reliable default value
6317 if (snapshot_mode_current == NULL)
6318 snapshot_mode_current =
6319 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6321 // if that also fails, set current snapshot mode to first available value
6322 if (snapshot_mode_current == NULL)
6323 snapshot_mode_current = snapshot_modes;
6326 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6328 // needed for displaying snapshot mode text instead of identifier
6329 snapshot_mode_text = snapshot_mode_current->name;
6332 static void execSetupGame_setNetworkServerText(void)
6334 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6336 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6340 strncpy(network_server_hostname, setup.network_server_hostname,
6341 MAX_SETUP_TEXT_INPUT_LEN);
6342 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6345 // needed for displaying network server text instead of identifier
6346 network_server_text = network_server_hostname;
6349 static void execSetupGame(void)
6351 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6353 execSetupGame_setGameSpeeds(FALSE);
6354 execSetupGame_setScoresType();
6355 execSetupGame_setScrollDelays();
6356 execSetupGame_setSnapshotModes();
6358 execSetupGame_setNetworkServerText();
6360 if (!setup.provide_uploading_tapes)
6361 setHideSetupEntry(execOfferUploadTapes);
6363 setup_mode = SETUP_MODE_GAME;
6367 // check if vsync needs to be disabled for this game speed to work
6368 if (check_vsync_mode)
6369 DisableVsyncIfNeeded();
6372 static void execSetupChooseScoresType(void)
6374 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6379 static void execSetupChooseGameSpeed(void)
6381 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6386 static void execSetupChooseScrollDelay(void)
6388 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6393 static void execSetupChooseSnapshotMode(void)
6395 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6400 static void execSetupEngines(void)
6402 setup_mode = SETUP_MODE_ENGINES;
6407 static void execSetupEditor(void)
6409 setup_mode = SETUP_MODE_EDITOR;
6414 static void execSetupGraphics_setWindowSizes(boolean update_list)
6416 if (window_sizes != NULL && update_list)
6418 freeTreeInfo(window_sizes);
6420 window_sizes = NULL;
6423 if (window_sizes == NULL)
6425 boolean current_window_size_found = FALSE;
6428 for (i = 0; window_sizes_list[i].value != -1; i++)
6430 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6431 char identifier[32], name[32];
6432 int value = window_sizes_list[i].value;
6433 char *text = window_sizes_list[i].text;
6435 ti->node_top = &window_sizes;
6436 ti->sort_priority = value;
6438 sprintf(identifier, "%d", value);
6439 sprintf(name, "%s", text);
6441 setString(&ti->identifier, identifier);
6442 setString(&ti->name, name);
6443 setString(&ti->name_sorting, name);
6444 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6446 pushTreeInfo(&window_sizes, ti);
6448 if (value == setup.window_scaling_percent)
6449 current_window_size_found = TRUE;
6452 if (!current_window_size_found)
6454 // add entry for non-preset window scaling value
6456 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6457 char identifier[32], name[32];
6458 int value = setup.window_scaling_percent;
6460 ti->node_top = &window_sizes;
6461 ti->sort_priority = value;
6463 sprintf(identifier, "%d", value);
6464 sprintf(name, "%d %% (Current)", value);
6466 setString(&ti->identifier, identifier);
6467 setString(&ti->name, name);
6468 setString(&ti->name_sorting, name);
6469 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6471 pushTreeInfo(&window_sizes, ti);
6474 // sort window size values to start with lowest window size value
6475 sortTreeInfo(&window_sizes);
6477 // set current window size value to configured window size value
6478 window_size_current =
6479 getTreeInfoFromIdentifier(window_sizes,
6480 i_to_a(setup.window_scaling_percent));
6482 // if that fails, set current window size to reliable default value
6483 if (window_size_current == NULL)
6484 window_size_current =
6485 getTreeInfoFromIdentifier(window_sizes,
6486 i_to_a(STD_WINDOW_SCALING_PERCENT));
6488 // if that also fails, set current window size to first available value
6489 if (window_size_current == NULL)
6490 window_size_current = window_sizes;
6493 setup.window_scaling_percent = atoi(window_size_current->identifier);
6495 // needed for displaying window size text instead of identifier
6496 window_size_text = window_size_current->name;
6499 static void execSetupGraphics_setScalingTypes(void)
6501 if (scaling_types == NULL)
6505 for (i = 0; scaling_types_list[i].value != NULL; i++)
6507 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6508 char identifier[32], name[32];
6509 char *value = scaling_types_list[i].value;
6510 char *text = scaling_types_list[i].text;
6512 ti->node_top = &scaling_types;
6513 ti->sort_priority = i;
6515 sprintf(identifier, "%s", value);
6516 sprintf(name, "%s", text);
6518 setString(&ti->identifier, identifier);
6519 setString(&ti->name, name);
6520 setString(&ti->name_sorting, name);
6521 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6523 pushTreeInfo(&scaling_types, ti);
6526 // sort scaling type values to start with lowest scaling type value
6527 sortTreeInfo(&scaling_types);
6529 // set current scaling type value to configured scaling type value
6530 scaling_type_current =
6531 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6533 // if that fails, set current scaling type to reliable default value
6534 if (scaling_type_current == NULL)
6535 scaling_type_current =
6536 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6538 // if that also fails, set current scaling type to first available value
6539 if (scaling_type_current == NULL)
6540 scaling_type_current = scaling_types;
6543 setup.window_scaling_quality = scaling_type_current->identifier;
6545 // needed for displaying scaling type text instead of identifier
6546 scaling_type_text = scaling_type_current->name;
6549 static void execSetupGraphics_setRenderingModes(void)
6551 if (rendering_modes == NULL)
6555 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6557 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6558 char identifier[32], name[32];
6559 char *value = rendering_modes_list[i].value;
6560 char *text = rendering_modes_list[i].text;
6562 ti->node_top = &rendering_modes;
6563 ti->sort_priority = i;
6565 sprintf(identifier, "%s", value);
6566 sprintf(name, "%s", text);
6568 setString(&ti->identifier, identifier);
6569 setString(&ti->name, name);
6570 setString(&ti->name_sorting, name);
6571 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6573 pushTreeInfo(&rendering_modes, ti);
6576 // sort rendering mode values to start with lowest rendering mode value
6577 sortTreeInfo(&rendering_modes);
6579 // set current rendering mode value to configured rendering mode value
6580 rendering_mode_current =
6581 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6583 // if that fails, set current rendering mode to reliable default value
6584 if (rendering_mode_current == NULL)
6585 rendering_mode_current =
6586 getTreeInfoFromIdentifier(rendering_modes,
6587 STR_SPECIAL_RENDERING_DEFAULT);
6589 // if that also fails, set current rendering mode to first available one
6590 if (rendering_mode_current == NULL)
6591 rendering_mode_current = rendering_modes;
6594 setup.screen_rendering_mode = rendering_mode_current->identifier;
6596 // needed for displaying rendering mode text instead of identifier
6597 rendering_mode_text = rendering_mode_current->name;
6600 static void execSetupGraphics_setVsyncModes(boolean update_value)
6602 if (vsync_modes == NULL)
6606 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6608 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6609 char identifier[32], name[32];
6610 char *value = vsync_modes_list[i].value;
6611 char *text = vsync_modes_list[i].text;
6613 ti->node_top = &vsync_modes;
6614 ti->sort_priority = i;
6616 sprintf(identifier, "%s", value);
6617 sprintf(name, "%s", text);
6619 setString(&ti->identifier, identifier);
6620 setString(&ti->name, name);
6621 setString(&ti->name_sorting, name);
6622 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6624 pushTreeInfo(&vsync_modes, ti);
6627 // sort vsync mode values to start with lowest vsync mode value
6628 sortTreeInfo(&vsync_modes);
6630 update_value = TRUE;
6635 // set current vsync mode value to configured vsync mode value
6636 vsync_mode_current =
6637 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6639 // if that fails, set current vsync mode to reliable default value
6640 if (vsync_mode_current == NULL)
6641 vsync_mode_current =
6642 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6644 // if that also fails, set current vsync mode to first available one
6645 if (vsync_mode_current == NULL)
6646 vsync_mode_current = vsync_modes;
6649 setup.vsync_mode = vsync_mode_current->identifier;
6651 // needed for displaying vsync mode text instead of identifier
6652 vsync_mode_text = vsync_mode_current->name;
6655 static void execSetupGraphics(void)
6657 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6659 // update "setup.window_scaling_percent" from list selection
6660 // (in this case, window scaling was changed on setup screen)
6661 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6662 execSetupGraphics_setWindowSizes(FALSE);
6664 // update "setup.vsync_mode" from list selection
6665 // (in this case, vsync mode was changed on setup screen)
6666 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6667 execSetupGraphics_setVsyncModes(FALSE);
6669 // update list selection from "setup.window_scaling_percent"
6670 // (window scaling may have changed by resizing the window)
6671 execSetupGraphics_setWindowSizes(TRUE);
6673 // update list selection from "setup.vsync_mode"
6674 // (vsync_mode may have changed by re-creating the renderer)
6675 execSetupGraphics_setVsyncModes(TRUE);
6677 execSetupGraphics_setScalingTypes();
6678 execSetupGraphics_setRenderingModes();
6680 setup_mode = SETUP_MODE_GRAPHICS;
6684 // check if game speed is high enough for 60 Hz vsync to work
6685 if (check_game_speed)
6686 ModifyGameSpeedIfNeeded();
6688 // window scaling may have changed at this point
6689 ChangeWindowScalingIfNeeded();
6691 // window scaling quality may have changed at this point
6692 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6693 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6695 // screen rendering mode may have changed at this point
6696 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6698 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6699 int video_vsync_mode = video.vsync_mode;
6701 // screen vsync mode may have changed at this point
6702 ChangeVsyncModeIfNeeded();
6704 // check if setting vsync mode to selected value failed
6705 if (setup_vsync_mode != video_vsync_mode &&
6706 setup_vsync_mode != video.vsync_mode)
6708 // changing vsync mode to selected value failed -- reset displayed value
6709 execSetupGraphics_setVsyncModes(TRUE);
6711 Request("Setting VSync failed!", REQ_CONFIRM);
6717 static void execSetupChooseWindowSize(void)
6719 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6724 static void execSetupChooseScalingType(void)
6726 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6731 static void execSetupChooseRenderingMode(void)
6733 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6738 static void execSetupChooseVsyncMode(void)
6740 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6745 static void execSetupChooseVolumeSimple(void)
6747 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6752 static void execSetupChooseVolumeLoops(void)
6754 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6759 static void execSetupChooseVolumeMusic(void)
6761 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6766 static void execSetupSound(void)
6768 if (volumes_simple == NULL)
6770 boolean current_volume_simple_found = FALSE;
6773 for (i = 0; volumes_list[i].value != -1; i++)
6775 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6776 char identifier[32], name[32];
6777 int value = volumes_list[i].value;
6778 char *text = volumes_list[i].text;
6780 ti->node_top = &volumes_simple;
6781 ti->sort_priority = value;
6783 sprintf(identifier, "%d", value);
6784 sprintf(name, "%s", text);
6786 setString(&ti->identifier, identifier);
6787 setString(&ti->name, name);
6788 setString(&ti->name_sorting, name);
6789 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6791 pushTreeInfo(&volumes_simple, ti);
6793 if (value == setup.volume_simple)
6794 current_volume_simple_found = TRUE;
6797 if (!current_volume_simple_found)
6799 // add entry for non-preset volume value
6801 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6802 char identifier[32], name[32];
6803 int value = setup.volume_simple;
6805 ti->node_top = &volumes_simple;
6806 ti->sort_priority = value;
6808 sprintf(identifier, "%d", value);
6809 sprintf(name, "%d %% (Current)", value);
6811 setString(&ti->identifier, identifier);
6812 setString(&ti->name, name);
6813 setString(&ti->name_sorting, name);
6814 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6816 pushTreeInfo(&volumes_simple, ti);
6819 // sort volume values to start with lowest volume value
6820 sortTreeInfo(&volumes_simple);
6822 // set current volume value to configured volume value
6823 volume_simple_current =
6824 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6826 // if that fails, set current volume to reliable default value
6827 if (volume_simple_current == NULL)
6828 volume_simple_current =
6829 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6831 // if that also fails, set current volume to first available value
6832 if (volume_simple_current == NULL)
6833 volume_simple_current = volumes_simple;
6836 if (volumes_loops == NULL)
6838 boolean current_volume_loops_found = FALSE;
6841 for (i = 0; volumes_list[i].value != -1; i++)
6843 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6844 char identifier[32], name[32];
6845 int value = volumes_list[i].value;
6846 char *text = volumes_list[i].text;
6848 ti->node_top = &volumes_loops;
6849 ti->sort_priority = value;
6851 sprintf(identifier, "%d", value);
6852 sprintf(name, "%s", text);
6854 setString(&ti->identifier, identifier);
6855 setString(&ti->name, name);
6856 setString(&ti->name_sorting, name);
6857 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6859 pushTreeInfo(&volumes_loops, ti);
6861 if (value == setup.volume_loops)
6862 current_volume_loops_found = TRUE;
6865 if (!current_volume_loops_found)
6867 // add entry for non-preset volume value
6869 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6870 char identifier[32], name[32];
6871 int value = setup.volume_loops;
6873 ti->node_top = &volumes_loops;
6874 ti->sort_priority = value;
6876 sprintf(identifier, "%d", value);
6877 sprintf(name, "%d %% (Current)", value);
6879 setString(&ti->identifier, identifier);
6880 setString(&ti->name, name);
6881 setString(&ti->name_sorting, name);
6882 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6884 pushTreeInfo(&volumes_loops, ti);
6887 // sort volume values to start with lowest volume value
6888 sortTreeInfo(&volumes_loops);
6890 // set current volume value to configured volume value
6891 volume_loops_current =
6892 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6894 // if that fails, set current volume to reliable default value
6895 if (volume_loops_current == NULL)
6896 volume_loops_current =
6897 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6899 // if that also fails, set current volume to first available value
6900 if (volume_loops_current == NULL)
6901 volume_loops_current = volumes_loops;
6904 if (volumes_music == NULL)
6906 boolean current_volume_music_found = FALSE;
6909 for (i = 0; volumes_list[i].value != -1; i++)
6911 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6912 char identifier[32], name[32];
6913 int value = volumes_list[i].value;
6914 char *text = volumes_list[i].text;
6916 ti->node_top = &volumes_music;
6917 ti->sort_priority = value;
6919 sprintf(identifier, "%d", value);
6920 sprintf(name, "%s", text);
6922 setString(&ti->identifier, identifier);
6923 setString(&ti->name, name);
6924 setString(&ti->name_sorting, name);
6925 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6927 pushTreeInfo(&volumes_music, ti);
6929 if (value == setup.volume_music)
6930 current_volume_music_found = TRUE;
6933 if (!current_volume_music_found)
6935 // add entry for non-preset volume value
6937 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6938 char identifier[32], name[32];
6939 int value = setup.volume_music;
6941 ti->node_top = &volumes_music;
6942 ti->sort_priority = value;
6944 sprintf(identifier, "%d", value);
6945 sprintf(name, "%d %% (Current)", value);
6947 setString(&ti->identifier, identifier);
6948 setString(&ti->name, name);
6949 setString(&ti->name_sorting, name);
6950 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6952 pushTreeInfo(&volumes_music, ti);
6955 // sort volume values to start with lowest volume value
6956 sortTreeInfo(&volumes_music);
6958 // set current volume value to configured volume value
6959 volume_music_current =
6960 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6962 // if that fails, set current volume to reliable default value
6963 if (volume_music_current == NULL)
6964 volume_music_current =
6965 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6967 // if that also fails, set current volume to first available value
6968 if (volume_music_current == NULL)
6969 volume_music_current = volumes_music;
6972 setup.volume_simple = atoi(volume_simple_current->identifier);
6973 setup.volume_loops = atoi(volume_loops_current->identifier);
6974 setup.volume_music = atoi(volume_music_current->identifier);
6976 // needed for displaying volume text instead of identifier
6977 volume_simple_text = volume_simple_current->name;
6978 volume_loops_text = volume_loops_current->name;
6979 volume_music_text = volume_music_current->name;
6981 setup_mode = SETUP_MODE_SOUND;
6986 static void execSetupChooseTouchControls(void)
6988 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6993 static void execSetupChooseMoveDistance(void)
6995 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
7000 static void execSetupChooseDropDistance(void)
7002 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
7007 static void execSetupChooseTransparency(void)
7009 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
7014 static void execSetupChooseGridXSize_0(void)
7016 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
7021 static void execSetupChooseGridYSize_0(void)
7023 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
7028 static void execSetupChooseGridXSize_1(void)
7030 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
7035 static void execSetupChooseGridYSize_1(void)
7037 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
7042 static void execSetupConfigureVirtualButtons(void)
7044 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
7046 ConfigureVirtualButtons();
7048 setup_mode = SETUP_MODE_TOUCH;
7053 static void execSetupTouch(void)
7057 if (touch_controls == NULL)
7059 for (i = 0; touch_controls_list[i].value != NULL; i++)
7061 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7062 char identifier[32], name[32];
7063 char *value = touch_controls_list[i].value;
7064 char *text = touch_controls_list[i].text;
7066 ti->node_top = &touch_controls;
7067 ti->sort_priority = i;
7069 sprintf(identifier, "%s", value);
7070 sprintf(name, "%s", text);
7072 setString(&ti->identifier, identifier);
7073 setString(&ti->name, name);
7074 setString(&ti->name_sorting, name);
7075 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
7077 pushTreeInfo(&touch_controls, ti);
7080 // sort touch control values to start with lowest touch control value
7081 sortTreeInfo(&touch_controls);
7083 // set current touch control value to configured touch control value
7084 touch_control_current =
7085 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
7087 // if that fails, set current touch control to reliable default value
7088 if (touch_control_current == NULL)
7089 touch_control_current =
7090 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
7092 // if that also fails, set current touch control to first available value
7093 if (touch_control_current == NULL)
7094 touch_control_current = touch_controls;
7097 if (move_distances == NULL)
7099 for (i = 0; distances_list[i].value != -1; i++)
7101 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7102 char identifier[32], name[32];
7103 int value = distances_list[i].value;
7104 char *text = distances_list[i].text;
7106 ti->node_top = &move_distances;
7107 ti->sort_priority = value;
7109 sprintf(identifier, "%d", value);
7110 sprintf(name, "%s", text);
7112 setString(&ti->identifier, identifier);
7113 setString(&ti->name, name);
7114 setString(&ti->name_sorting, name);
7115 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
7117 pushTreeInfo(&move_distances, ti);
7120 // sort distance values to start with lowest distance value
7121 sortTreeInfo(&move_distances);
7123 // set current distance value to configured distance value
7124 move_distance_current =
7125 getTreeInfoFromIdentifier(move_distances,
7126 i_to_a(setup.touch.move_distance));
7128 // if that fails, set current distance to reliable default value
7129 if (move_distance_current == NULL)
7130 move_distance_current =
7131 getTreeInfoFromIdentifier(move_distances,
7132 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
7134 // if that also fails, set current distance to first available value
7135 if (move_distance_current == NULL)
7136 move_distance_current = move_distances;
7139 if (drop_distances == NULL)
7141 for (i = 0; distances_list[i].value != -1; i++)
7143 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7144 char identifier[32], name[32];
7145 int value = distances_list[i].value;
7146 char *text = distances_list[i].text;
7148 ti->node_top = &drop_distances;
7149 ti->sort_priority = value;
7151 sprintf(identifier, "%d", value);
7152 sprintf(name, "%s", text);
7154 setString(&ti->identifier, identifier);
7155 setString(&ti->name, name);
7156 setString(&ti->name_sorting, name);
7157 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
7159 pushTreeInfo(&drop_distances, ti);
7162 // sort distance values to start with lowest distance value
7163 sortTreeInfo(&drop_distances);
7165 // set current distance value to configured distance value
7166 drop_distance_current =
7167 getTreeInfoFromIdentifier(drop_distances,
7168 i_to_a(setup.touch.drop_distance));
7170 // if that fails, set current distance to reliable default value
7171 if (drop_distance_current == NULL)
7172 drop_distance_current =
7173 getTreeInfoFromIdentifier(drop_distances,
7174 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
7176 // if that also fails, set current distance to first available value
7177 if (drop_distance_current == NULL)
7178 drop_distance_current = drop_distances;
7181 if (transparencies == NULL)
7183 for (i = 0; transparencies_list[i].value != -1; i++)
7185 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7186 char identifier[32], name[32];
7187 int value = transparencies_list[i].value;
7188 char *text = transparencies_list[i].text;
7190 ti->node_top = &transparencies;
7191 ti->sort_priority = value;
7193 sprintf(identifier, "%d", value);
7194 sprintf(name, "%s", text);
7196 setString(&ti->identifier, identifier);
7197 setString(&ti->name, name);
7198 setString(&ti->name_sorting, name);
7199 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
7201 pushTreeInfo(&transparencies, ti);
7204 // sort transparency values to start with lowest transparency value
7205 sortTreeInfo(&transparencies);
7207 // set current transparency value to configured transparency value
7208 transparency_current =
7209 getTreeInfoFromIdentifier(transparencies,
7210 i_to_a(setup.touch.transparency));
7212 // if that fails, set current transparency to reliable default value
7213 if (transparency_current == NULL)
7214 transparency_current =
7215 getTreeInfoFromIdentifier(transparencies,
7216 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7218 // if that also fails, set current transparency to first available value
7219 if (transparency_current == NULL)
7220 transparency_current = transparencies;
7223 for (i = 0; i < 2; i++)
7225 for (j = 0; j < 2; j++)
7227 if (grid_sizes[i][j] == NULL)
7229 for (k = 0; grid_sizes_list[k].value != -1; k++)
7231 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7232 char identifier[32], name[32];
7233 int value = grid_sizes_list[k].value;
7234 char *text = grid_sizes_list[k].text;
7236 ti->node_top = &grid_sizes[i][j];
7237 ti->sort_priority = value;
7239 sprintf(identifier, "%d", value);
7240 sprintf(name, "%s", text);
7242 setString(&ti->identifier, identifier);
7243 setString(&ti->name, name);
7244 setString(&ti->name_sorting, name);
7245 setString(&ti->infotext,
7248 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7249 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7251 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7252 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7254 pushTreeInfo(&grid_sizes[i][j], ti);
7257 // sort grid size values to start with lowest grid size value
7258 sortTreeInfo(&grid_sizes[i][j]);
7260 // set current grid size value to configured grid size value
7261 grid_size_current[i][j] =
7262 getTreeInfoFromIdentifier(grid_sizes[i][j],
7264 setup.touch.grid_xsize[i] :
7265 setup.touch.grid_ysize[i]));
7267 // if that fails, set current grid size to reliable default value
7268 if (grid_size_current[i][j] == NULL)
7269 grid_size_current[i][j] =
7270 getTreeInfoFromIdentifier(grid_sizes[i][j],
7272 DEFAULT_GRID_XSIZE(i) :
7273 DEFAULT_GRID_YSIZE(i)));
7275 // if that also fails, set current grid size to first available value
7276 if (grid_size_current[i][j] == NULL)
7277 grid_size_current[i][j] = grid_sizes[i][j];
7282 setup.touch.control_type = touch_control_current->identifier;
7283 setup.touch.move_distance = atoi(move_distance_current->identifier);
7284 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7285 setup.touch.transparency = atoi(transparency_current->identifier);
7287 for (i = 0; i < 2; i++)
7289 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7290 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7292 if (i == GRID_ACTIVE_NR())
7294 overlay.grid_xsize = setup.touch.grid_xsize[i];
7295 overlay.grid_ysize = setup.touch.grid_ysize[i];
7299 // needed for displaying value text instead of identifier
7300 touch_controls_text = touch_control_current->name;
7301 move_distance_text = move_distance_current->name;
7302 drop_distance_text = drop_distance_current->name;
7303 transparency_text = transparency_current->name;
7305 for (i = 0; i < 2; i++)
7306 for (j = 0; j < 2; j++)
7307 grid_size_text[i][j] = grid_size_current[i][j]->name;
7309 setup_mode = SETUP_MODE_TOUCH;
7314 static void execSetupArtwork(void)
7316 static ArtworkDirTree *gfx_last_valid = NULL;
7317 static ArtworkDirTree *snd_last_valid = NULL;
7318 static ArtworkDirTree *mus_last_valid = NULL;
7320 // current artwork directory may be invalid (level group, parent link)
7321 if (!validLevelSeries(artwork.gfx_current))
7322 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7323 if (!validLevelSeries(artwork.snd_current))
7324 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7325 if (!validLevelSeries(artwork.mus_current))
7326 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7328 // store valid artwork directory information
7329 gfx_last_valid = artwork.gfx_current;
7330 snd_last_valid = artwork.snd_current;
7331 mus_last_valid = artwork.mus_current;
7334 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7335 artwork.gfx_current->subdir,
7336 artwork.gfx_current->fullpath,
7337 artwork.gfx_current->basepath);
7340 setup.graphics_set = artwork.gfx_current->identifier;
7341 setup.sounds_set = artwork.snd_current->identifier;
7342 setup.music_set = artwork.mus_current->identifier;
7344 // needed if last screen (setup choice) changed graphics, sounds or music
7345 ReloadCustomArtwork(0);
7347 // needed for displaying artwork name instead of artwork identifier
7348 graphics_set_name = artwork.gfx_current->name;
7349 sounds_set_name = artwork.snd_current->name;
7350 music_set_name = artwork.mus_current->name;
7352 setup_mode = SETUP_MODE_ARTWORK;
7357 static void execSetupChooseGraphics(void)
7359 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7364 static void execSetupChooseSounds(void)
7366 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7371 static void execSetupChooseMusic(void)
7373 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7378 static void execSetupInput(void)
7380 setup_mode = SETUP_MODE_INPUT;
7385 static void execSetupShortcuts(void)
7387 setup_mode = SETUP_MODE_SHORTCUTS;
7392 static void execSetupShortcuts1(void)
7394 setup_mode = SETUP_MODE_SHORTCUTS_1;
7399 static void execSetupShortcuts2(void)
7401 setup_mode = SETUP_MODE_SHORTCUTS_2;
7406 static void execSetupShortcuts3(void)
7408 setup_mode = SETUP_MODE_SHORTCUTS_3;
7413 static void execSetupShortcuts4(void)
7415 setup_mode = SETUP_MODE_SHORTCUTS_4;
7420 static void execSetupShortcuts5(void)
7422 setup_mode = SETUP_MODE_SHORTCUTS_5;
7427 static void execExitSetup(void)
7429 SetGameStatus(GAME_MODE_MAIN);
7434 static void execSaveAndExitSetup(void)
7440 static void execGadgetNetworkServer(void)
7442 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7443 struct GadgetInfo *gi = screen_gadget[gadget_id];
7445 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7446 network_server_hostname[0] = '\0';
7448 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7452 ClickOnGadget(gi, MB_LEFTBUTTON);
7455 static void execOfferUploadTapes(void)
7460 static void ToggleNetworkModeIfNeeded(void)
7462 int font_title = FONT_TITLE_1;
7463 int font_foot = FC_BLUE;
7464 int ystart = mSY - SY + 16;
7465 int ybottom = mSY - SY + SYSIZE - 20;
7466 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7468 if (setup.network_mode == network.enabled)
7471 network.enabled = setup.network_mode;
7473 FadeOut(REDRAW_ALL);
7477 DrawTextSCentered(ystart, font_title, text);
7481 if (network.enabled)
7482 InitNetworkServer();
7484 DisconnectFromNetworkServer();
7486 DrawTextSCentered(ybottom, font_foot,
7487 "Press any key or button for setup menu");
7489 WaitForEventToContinue();
7494 static void ToggleGameSpeedsListIfNeeded(void)
7496 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7498 if (setup.game_speed_extended == using_game_speeds_extended)
7501 // try to match similar values when changing game speeds list
7502 if (setup.game_speed_extended)
7503 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7504 setup.game_frame_delay == 30 ? 29 :
7505 setup.game_frame_delay);
7507 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7508 setup.game_frame_delay == 16 ? 15 :
7509 setup.game_frame_delay >= 29 ? 30 :
7510 setup.game_frame_delay <= 10 ? 10 :
7511 setup.game_frame_delay);
7513 execSetupGame_setGameSpeeds(TRUE);
7518 static void ToggleUseApiServerIfNeeded(void)
7520 if (runtime.use_api_server == setup.use_api_server)
7523 runtime.use_api_server = setup.use_api_server;
7525 if (runtime.use_api_server)
7526 CheckApiServerTasks();
7529 static void ModifyGameSpeedIfNeeded(void)
7531 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7532 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7536 char *game_speed_text = "Fast";
7537 int game_speed_value = 15;
7539 if (setup.game_speed_extended)
7541 game_speed_text = "60 fps";
7542 game_speed_value = 16;
7545 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7547 // set game speed to existing list value that is fast enough for vsync
7548 setup.game_frame_delay = game_speed_value;
7550 execSetupGame_setGameSpeeds(TRUE);
7552 Request(message, REQ_CONFIRM);
7555 static void DisableVsyncIfNeeded(void)
7557 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7558 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7559 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7562 // disable vsync for the selected game speed to work
7563 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7565 execSetupGraphics_setVsyncModes(TRUE);
7567 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7573 void *related_value;
7574 } hide_related_entry_list[] =
7576 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7577 { &setup.scores_in_highscore_list, &scores_type_text },
7579 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7580 { &setup.game_frame_delay, &game_speed_text },
7582 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7583 { &setup.scroll_delay_value, &scroll_delay_text },
7585 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7586 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7588 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7589 { &setup.window_scaling_percent, &window_size_text },
7591 { &setup.window_scaling_quality, execSetupChooseScalingType },
7592 { &setup.window_scaling_quality, &scaling_type_text },
7594 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7595 { &setup.screen_rendering_mode, &rendering_mode_text },
7597 { &setup.vsync_mode, execSetupChooseVsyncMode },
7598 { &setup.vsync_mode, &vsync_mode_text },
7600 { &setup.graphics_set, execSetupChooseGraphics },
7601 { &setup.graphics_set, &graphics_set_name },
7603 { &setup.sounds_set, execSetupChooseSounds },
7604 { &setup.sounds_set, &sounds_set_name },
7606 { &setup.music_set, execSetupChooseMusic },
7607 { &setup.music_set, &music_set_name },
7609 { &setup.volume_simple, execSetupChooseVolumeSimple },
7610 { &setup.volume_simple, &volume_simple_text },
7612 { &setup.volume_loops, execSetupChooseVolumeLoops },
7613 { &setup.volume_loops, &volume_loops_text },
7615 { &setup.volume_music, execSetupChooseVolumeMusic },
7616 { &setup.volume_music, &volume_music_text },
7618 { &setup.touch.control_type, execSetupChooseTouchControls },
7619 { &setup.touch.control_type, &touch_controls_text },
7621 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7622 { &setup.touch.move_distance, &move_distance_text },
7624 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7625 { &setup.touch.drop_distance, &drop_distance_text },
7627 { &setup.touch.transparency, execSetupChooseTransparency },
7628 { &setup.touch.transparency, &transparency_text },
7630 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7631 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7633 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7634 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7636 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7637 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7639 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7640 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7642 { &setup.internal.menu_game, execSetupGame },
7643 { &setup.internal.menu_engines, execSetupEngines },
7644 { &setup.internal.menu_editor, execSetupEditor },
7645 { &setup.internal.menu_graphics, execSetupGraphics },
7646 { &setup.internal.menu_sound, execSetupSound },
7647 { &setup.internal.menu_artwork, execSetupArtwork },
7648 { &setup.internal.menu_input, execSetupInput },
7649 { &setup.internal.menu_touch, execSetupTouch },
7650 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7651 { &setup.internal.menu_exit, execExitSetup },
7652 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7657 void setHideRelatedSetupEntries(void)
7661 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7662 if (hideSetupEntry(hide_related_entry_list[i].value))
7663 setHideSetupEntry(hide_related_entry_list[i].related_value);
7666 static struct TokenInfo setup_info_main[] =
7668 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7669 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7670 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7671 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7672 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7673 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7674 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7675 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7676 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7677 { TYPE_EMPTY, NULL, "" },
7678 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7679 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7684 static struct TokenInfo setup_info_game[] =
7686 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7687 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7688 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7689 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7690 { TYPE_STRING, &network_server_text, "" },
7691 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7692 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7693 { TYPE_STRING, &scores_type_text, "" },
7694 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7695 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7696 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7697 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7698 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7699 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7700 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7701 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7702 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7703 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7704 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7705 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7706 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7707 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7708 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7709 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7710 { TYPE_STRING, &game_speed_text, "" },
7711 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7713 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7714 { TYPE_STRING, &scroll_delay_text, "" },
7716 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7717 { TYPE_STRING, &snapshot_mode_text, "" },
7718 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7719 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7720 { TYPE_EMPTY, NULL, "" },
7721 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7726 static struct TokenInfo setup_info_engines[] =
7728 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7729 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7730 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7731 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7732 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7733 { TYPE_EMPTY, NULL, "" },
7734 { TYPE_HEADLINE, NULL, "Supaplex" },
7735 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7736 { TYPE_EMPTY, NULL, "" },
7737 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7742 static struct TokenInfo setup_info_editor[] =
7745 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7746 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7747 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7748 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7749 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7750 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7751 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7752 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7753 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7754 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7756 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7757 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7759 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7761 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7762 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7763 { TYPE_EMPTY, NULL, "" },
7765 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7766 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7767 { TYPE_EMPTY, NULL, "" },
7769 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7770 { TYPE_EMPTY, NULL, "" },
7771 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7772 { TYPE_EMPTY, NULL, "" },
7773 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7778 static struct TokenInfo setup_info_graphics[] =
7780 #if !defined(PLATFORM_ANDROID)
7781 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7782 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7783 { TYPE_STRING, &window_size_text, "" },
7784 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7785 { TYPE_STRING, &scaling_type_text, "" },
7786 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7787 { TYPE_STRING, &rendering_mode_text, "" },
7790 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7791 { TYPE_STRING, &scroll_delay_text, "" },
7793 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7794 { TYPE_STRING, &vsync_mode_text, "" },
7795 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7796 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7797 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7798 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7799 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7800 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7801 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7802 { TYPE_EMPTY, NULL, "" },
7803 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7808 static struct TokenInfo setup_info_sound[] =
7810 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7811 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7812 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7813 { TYPE_EMPTY, NULL, "" },
7814 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7815 { TYPE_STRING, &volume_simple_text, "" },
7816 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7817 { TYPE_STRING, &volume_loops_text, "" },
7818 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7819 { TYPE_STRING, &volume_music_text, "" },
7820 { TYPE_EMPTY, NULL, "" },
7821 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7826 static struct TokenInfo setup_info_artwork[] =
7828 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7829 { TYPE_STRING, &graphics_set_name, "" },
7830 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7831 { TYPE_STRING, &sounds_set_name, "" },
7832 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7833 { TYPE_STRING, &music_set_name, "" },
7834 { TYPE_EMPTY, NULL, "" },
7835 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7836 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7837 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7838 { TYPE_EMPTY, NULL, "" },
7839 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7844 static struct TokenInfo setup_info_input[] =
7846 { TYPE_SWITCH, NULL, "Player:" },
7847 { TYPE_SWITCH, NULL, "Device:" },
7848 { TYPE_SWITCH, NULL, "" },
7849 { TYPE_SKIPPABLE, NULL, "" },
7850 { TYPE_EMPTY, NULL, "" },
7851 { TYPE_EMPTY, NULL, "" },
7852 { TYPE_EMPTY, NULL, "" },
7853 { TYPE_EMPTY, NULL, "" },
7854 { TYPE_EMPTY, NULL, "" },
7855 { TYPE_EMPTY, NULL, "" },
7856 { TYPE_EMPTY, NULL, "" },
7857 { TYPE_EMPTY, NULL, "" },
7858 { TYPE_SKIPPABLE, NULL, "" },
7859 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7864 static struct TokenInfo setup_info_touch[] =
7866 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7867 { TYPE_STRING, &touch_controls_text, "" },
7868 { TYPE_EMPTY, NULL, "" },
7869 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7874 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7876 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7877 { TYPE_STRING, &touch_controls_text, "" },
7878 { TYPE_EMPTY, NULL, "" },
7879 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7880 { TYPE_STRING, &grid_size_text[0][0], "" },
7881 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7882 { TYPE_STRING, &grid_size_text[0][1], "" },
7883 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7884 { TYPE_STRING, &transparency_text, "" },
7885 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7886 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7887 { TYPE_EMPTY, NULL, "" },
7888 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7889 { TYPE_EMPTY, NULL, "" },
7890 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7895 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7897 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7898 { TYPE_STRING, &touch_controls_text, "" },
7899 { TYPE_EMPTY, NULL, "" },
7900 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7901 { TYPE_STRING, &grid_size_text[1][0], "" },
7902 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7903 { TYPE_STRING, &grid_size_text[1][1], "" },
7904 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7905 { TYPE_STRING, &transparency_text, "" },
7906 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7907 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7908 { TYPE_EMPTY, NULL, "" },
7909 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7910 { TYPE_EMPTY, NULL, "" },
7911 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7916 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7918 setup_info_touch_virtual_buttons_0,
7919 setup_info_touch_virtual_buttons_1
7922 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7924 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7925 { TYPE_STRING, &touch_controls_text, "" },
7926 { TYPE_EMPTY, NULL, "" },
7927 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7928 { TYPE_STRING, &move_distance_text, "" },
7929 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7930 { TYPE_STRING, &drop_distance_text, "" },
7931 { TYPE_EMPTY, NULL, "" },
7932 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7937 static struct TokenInfo setup_info_shortcuts[] =
7939 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7940 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7941 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7942 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7943 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7944 { TYPE_EMPTY, NULL, "" },
7945 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7950 static struct TokenInfo setup_info_shortcuts_1[] =
7952 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7953 { TYPE_KEY, &setup.shortcut.save_game, "" },
7954 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7955 { TYPE_KEY, &setup.shortcut.load_game, "" },
7956 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7957 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7958 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7959 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7960 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7961 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7962 { TYPE_EMPTY, NULL, "" },
7963 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7964 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7965 { TYPE_EMPTY, NULL, "" },
7966 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7971 static struct TokenInfo setup_info_shortcuts_2[] =
7973 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7974 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7975 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7976 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7977 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7978 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7979 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7980 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7981 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7982 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7983 { TYPE_EMPTY, NULL, "" },
7984 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7989 static struct TokenInfo setup_info_shortcuts_3[] =
7991 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7992 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7993 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7994 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7995 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7996 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7997 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7998 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7999 { TYPE_KEYTEXT, NULL, "Record Tape:", },
8000 { TYPE_KEY, &setup.shortcut.tape_record, "" },
8001 { TYPE_KEYTEXT, NULL, "Play Tape:", },
8002 { TYPE_KEY, &setup.shortcut.tape_play, "" },
8003 { TYPE_EMPTY, NULL, "" },
8004 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8009 static struct TokenInfo setup_info_shortcuts_4[] =
8011 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
8012 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
8013 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
8014 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
8015 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
8016 { TYPE_KEY, &setup.shortcut.sound_music, "" },
8017 { TYPE_EMPTY, NULL, "" },
8018 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8023 static struct TokenInfo setup_info_shortcuts_5[] =
8025 { TYPE_KEYTEXT, NULL, "Snap Left:", },
8026 { TYPE_KEY, &setup.shortcut.snap_left, "" },
8027 { TYPE_KEYTEXT, NULL, "Snap Right:", },
8028 { TYPE_KEY, &setup.shortcut.snap_right, "" },
8029 { TYPE_KEYTEXT, NULL, "Snap Up:", },
8030 { TYPE_KEY, &setup.shortcut.snap_up, "" },
8031 { TYPE_KEYTEXT, NULL, "Snap Down:", },
8032 { TYPE_KEY, &setup.shortcut.snap_down, "" },
8033 { TYPE_EMPTY, NULL, "" },
8034 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8039 static Key getSetupKey(void)
8041 Key key = KSYM_UNDEFINED;
8042 boolean got_key_event = FALSE;
8044 while (!got_key_event)
8048 if (NextValidEvent(&event))
8052 case EVENT_KEYPRESS:
8054 key = GetEventKey((KeyEvent *)&event, TRUE);
8056 // press 'Escape' or 'Enter' to keep the existing key binding
8057 if (key == KSYM_Escape || key == KSYM_Return)
8058 key = KSYM_UNDEFINED; // keep old value
8060 got_key_event = TRUE;
8064 case EVENT_KEYRELEASE:
8065 key_joystick_mapping = 0;
8069 HandleOtherEvents(&event);
8080 static int getSetupValueFont(int type, void *value)
8082 if (type & TYPE_GHOSTED)
8083 return FONT_OPTION_OFF;
8084 else if (type & TYPE_KEY)
8085 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
8086 else if (type & TYPE_STRING)
8087 return FONT_VALUE_2;
8088 else if (type & TYPE_ECS_AGA)
8089 return FONT_VALUE_1;
8090 else if (type & TYPE_BOOLEAN_STYLE)
8091 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
8092 else if (type & TYPE_YES_NO_AUTO)
8093 return (*(int *)value == AUTO ? FONT_OPTION_ON :
8094 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
8095 else if (type & TYPE_PLAYER)
8096 return FONT_VALUE_1;
8098 return FONT_VALUE_1;
8101 static int getSetupValueFontNarrow(int type, int font_nr)
8103 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
8104 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
8105 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
8109 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
8111 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8112 struct TokenInfo *si = &setup_info[si_pos];
8113 boolean font_draw_xoffset_modified = FALSE;
8114 boolean scrollbar_needed = (num_setup_info < max_setup_info);
8115 int font_draw_xoffset_old = -1;
8116 int xoffset = (scrollbar_needed ? -1 : 0);
8117 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
8118 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
8119 int xpos = menu_screen_value_xpos;
8120 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
8121 int startx = mSX + xpos * 32;
8122 int starty = mSY + ypos * 32;
8123 int type = si->type;
8124 void *value = si->value;
8125 char *value_string = getSetupValue(type, value);
8126 int font_nr_default = getSetupValueFont(type, value);
8127 int font_width_default = getFontWidth(font_nr_default);
8128 int font_nr = font_nr_default;
8131 if (value_string == NULL)
8134 if (type & TYPE_KEY)
8136 xpos = MENU_SCREEN_START_XPOS;
8138 if (type & TYPE_QUERY)
8139 value_string = "<press key>";
8141 else if (type & TYPE_STRING)
8143 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
8145 xpos = MENU_SCREEN_START_XPOS;
8147 if (strlen(value_string) > max_value_len)
8148 value_string[max_value_len] = '\0';
8150 else if (type & TYPE_YES_NO_AUTO)
8152 xpos = menu_screen_value_xpos - 1;
8154 else if (type & TYPE_PLAYER)
8156 int displayed_player_nr = *(int *)value + 1;
8158 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
8161 startx = mSX + xpos * 32;
8162 starty = mSY + ypos * 32;
8164 // special check if right-side setup values moved left due to scrollbar
8165 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
8167 int max_menu_text_length = 26; // maximum text length for classic menu
8168 int font_xoffset = getFontDrawOffsetX(font_nr);
8169 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8170 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8171 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8172 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
8174 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
8176 // when using narrow font, left-shifting text "auto" not needed
8177 if (type & TYPE_YES_NO_AUTO)
8181 startx = mSX + xpos * 32;
8183 font_nr = getSetupValueFontNarrow(type, font_nr);
8187 // downward compatibility correction for Juergen Bonhagen's menu settings
8188 if (setup_mode != SETUP_MODE_INPUT)
8190 int max_menu_text_length_big = (menu_screen_value_xpos -
8191 MENU_SCREEN_START_XPOS);
8192 int max_menu_text_length_medium = max_menu_text_length_big * 2;
8193 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
8194 int font1_xoffset = getFontDrawOffsetX(font_nr);
8195 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
8196 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8197 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8198 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8199 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8200 boolean correct_font_draw_xoffset = FALSE;
8202 if (xpos == MENU_SCREEN_START_XPOS &&
8203 startx + font1_xoffset < text_startx + text_font_xoffset)
8204 correct_font_draw_xoffset = TRUE;
8206 if (xpos == menu_screen_value_xpos &&
8207 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8208 correct_font_draw_xoffset = TRUE;
8210 // check if setup value would overlap with setup text when printed
8211 // (this can happen for extreme/wrong values for font draw offset)
8212 if (correct_font_draw_xoffset)
8214 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8215 font_draw_xoffset_modified = TRUE;
8217 if (type & TYPE_KEY)
8218 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8219 else if (!(type & TYPE_STRING))
8220 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8221 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8225 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
8226 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
8228 DrawText(startx, starty, value_string, font_nr);
8230 if (type & TYPE_PLAYER)
8232 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8233 int player_nr = *(int *)value;
8234 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8235 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8236 int startx2 = startx + xoff;
8237 int starty2 = starty + yoff;
8239 if (DrawingOnBackground(startx2, starty2))
8240 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8242 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8243 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8246 if (font_draw_xoffset_modified)
8247 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8250 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8252 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8253 struct TokenInfo *si = &setup_info[si_pos];
8255 if (si->type & TYPE_BOOLEAN_STYLE)
8257 *(boolean *)si->value ^= TRUE;
8259 else if (si->type & TYPE_YES_NO_AUTO)
8263 (*(int *)si->value == AUTO ? TRUE :
8264 *(int *)si->value == TRUE ? FALSE : AUTO) :
8265 (*(int *)si->value == TRUE ? AUTO :
8266 *(int *)si->value == AUTO ? FALSE : TRUE));
8268 else if (si->type & TYPE_KEY)
8272 si->type |= TYPE_QUERY;
8273 drawSetupValue(screen_pos, setup_info_pos_raw);
8274 si->type &= ~TYPE_QUERY;
8276 key = getSetupKey();
8277 if (key != KSYM_UNDEFINED)
8278 *(Key *)si->value = key;
8280 else if (si->type & TYPE_PLAYER)
8282 int player_nr = *(int *)si->value;
8287 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8289 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8292 drawSetupValue(screen_pos, setup_info_pos_raw);
8294 // fullscreen state may have changed at this point
8295 if (si->value == &setup.fullscreen)
8296 ToggleFullscreenIfNeeded();
8298 // network mode may have changed at this point
8299 if (si->value == &setup.network_mode)
8300 ToggleNetworkModeIfNeeded();
8302 // API server mode may have changed at this point
8303 if (si->value == &setup.use_api_server)
8304 ToggleUseApiServerIfNeeded();
8306 // game speed list may have changed at this point
8307 if (si->value == &setup.game_speed_extended)
8308 ToggleGameSpeedsListIfNeeded();
8311 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8313 static struct TokenInfo *setup_info_final = NULL;
8318 // determine maximum list size of target list
8319 while (setup_info_orig[list_size++].type != 0);
8321 // free, allocate and clear memory for target list
8322 checked_free(setup_info_final);
8323 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8325 // copy setup info list without setup entries marked as hidden
8326 for (i = 0; setup_info_orig[i].type != 0; i++)
8328 // skip setup entries configured to be hidden
8329 if (hideSetupEntry(setup_info_orig[i].value))
8332 // skip skippable setup entries if screen is lower than usual
8333 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8334 setup_info_orig[i].type == TYPE_SKIPPABLE)
8337 setup_info_final[list_pos++] = setup_info_orig[i];
8340 return setup_info_final;
8343 static void DrawSetupScreen_Generic(void)
8345 int fade_mask = REDRAW_FIELD;
8346 boolean redraw_all = FALSE;
8347 char *title_string = NULL;
8351 fade_mask = REDRAW_ALL;
8354 FadeMenuSoundsAndMusic();
8356 FreeScreenGadgets();
8357 CreateScreenGadgets();
8359 if (redraw_mask & REDRAW_ALL)
8364 // needed if different viewport properties defined for setup screen
8365 ChangeViewportPropertiesIfNeeded();
8367 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8371 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8373 if (setup_mode == SETUP_MODE_MAIN)
8375 setup_info = setup_info_main;
8376 title_string = STR_SETUP_MAIN;
8378 else if (setup_mode == SETUP_MODE_GAME)
8380 setup_info = setup_info_game;
8381 title_string = STR_SETUP_GAME;
8383 else if (setup_mode == SETUP_MODE_ENGINES)
8385 setup_info = setup_info_engines;
8386 title_string = STR_SETUP_ENGINES;
8388 else if (setup_mode == SETUP_MODE_EDITOR)
8390 setup_info = setup_info_editor;
8391 title_string = STR_SETUP_EDITOR;
8393 else if (setup_mode == SETUP_MODE_GRAPHICS)
8395 setup_info = setup_info_graphics;
8396 title_string = STR_SETUP_GRAPHICS;
8398 else if (setup_mode == SETUP_MODE_SOUND)
8400 setup_info = setup_info_sound;
8401 title_string = STR_SETUP_SOUND;
8403 else if (setup_mode == SETUP_MODE_ARTWORK)
8405 setup_info = setup_info_artwork;
8406 title_string = STR_SETUP_ARTWORK;
8408 else if (setup_mode == SETUP_MODE_TOUCH)
8410 setup_info = setup_info_touch;
8411 title_string = STR_SETUP_TOUCH;
8413 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8414 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8415 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8416 setup_info = setup_info_touch_wipe_gestures;
8418 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8420 setup_info = setup_info_shortcuts;
8421 title_string = STR_SETUP_SHORTCUTS;
8423 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8425 setup_info = setup_info_shortcuts_1;
8426 title_string = STR_SETUP_SHORTCUTS;
8428 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8430 setup_info = setup_info_shortcuts_2;
8431 title_string = STR_SETUP_SHORTCUTS;
8433 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8435 setup_info = setup_info_shortcuts_3;
8436 title_string = STR_SETUP_SHORTCUTS;
8438 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8440 setup_info = setup_info_shortcuts_4;
8441 title_string = STR_SETUP_SHORTCUTS;
8443 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8445 setup_info = setup_info_shortcuts_5;
8446 title_string = STR_SETUP_SHORTCUTS;
8449 // use modified setup info without setup entries marked as hidden
8450 setup_info = getSetupInfoFinal(setup_info);
8452 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8454 // determine maximal number of setup entries that can be displayed on screen
8456 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8459 // determine maximal number of setup entries available for this setup screen
8461 for (i = 0; setup_info[i].type != 0; i++)
8464 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8466 MapScreenGadgets(max_setup_info);
8469 redraw_mask = fade_mask = REDRAW_ALL;
8471 DrawMaskedBorder(fade_mask);
8476 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8478 menu_info = setup_info;
8480 HandleMenuScreen(mx, my, dx, dy, button,
8481 setup_mode, num_setup_info, max_setup_info);
8484 static void DrawSetupScreen_Input(void)
8488 FadeOut(REDRAW_FIELD);
8492 setup_info = getSetupInfoFinal(setup_info_input);
8494 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8496 for (i = 0; setup_info[i].type != 0; i++)
8498 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8499 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8500 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8501 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8502 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8503 initCursor(i, IMG_MENU_BUTTON);
8505 DrawCursorAndText_Setup(i, -1, FALSE);
8508 // create gadgets for setup input menu screen
8509 FreeScreenGadgets();
8510 CreateScreenGadgets();
8512 // map gadgets for setup input menu screen
8513 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8515 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8517 FadeIn(REDRAW_FIELD);
8520 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8522 if (device_name == NULL)
8525 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8528 if (strlen(device_name) > 1)
8530 char c1 = device_name[strlen(device_name) - 1];
8531 char c2 = device_name[strlen(device_name) - 2];
8533 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8534 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8537 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8538 strlen(device_name));
8541 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8544 static struct SetupKeyboardInfo custom_key;
8551 { &custom_key.left, "Axis/Pad Left" },
8552 { &custom_key.right, "Axis/Pad Right" },
8553 { &custom_key.up, "Axis/Pad Up" },
8554 { &custom_key.down, "Axis/Pad Down" },
8555 { &custom_key.snap, "Button 1/A/X" },
8556 { &custom_key.drop, "Button 2/B/Y" }
8558 static char *joystick_name[MAX_PLAYERS] =
8565 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8566 int font_nr_info = FONT_MENU_1;
8567 int font_nr_name = FONT_VALUE_OLD;
8568 int font_nr_on = FONT_VALUE_1;
8569 int font_nr_off = FONT_VALUE_OLD;
8572 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8574 font_nr_info = FONT_MENU_2;
8575 font_nr_on = FONT_VALUE_NARROW;
8576 font_nr_off = FONT_VALUE_OLD_NARROW;
8579 custom_key = setup.input[player_nr].key;
8581 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8582 FONT_INPUT_1_ACTIVE);
8584 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8586 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8587 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8589 if (setup.input[player_nr].use_joystick)
8591 char *device_name = setup.input[player_nr].joy.device_name;
8592 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8593 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8594 char *text = joystick_name[joystick_nr];
8595 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8597 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8598 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8602 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8603 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8606 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8607 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8611 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8612 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8613 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8614 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8616 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8617 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8618 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8619 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8620 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8621 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8623 for (i = 0; i < 6; i++)
8625 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8627 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8629 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8630 (setup.input[player_nr].use_joystick ?
8632 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8636 static int input_player_nr = 0;
8638 static void HandleSetupScreen_Input_Player(int step, int direction)
8640 int old_player_nr = input_player_nr;
8643 new_player_nr = old_player_nr + step * direction;
8644 if (new_player_nr < 0)
8646 if (new_player_nr > MAX_PLAYERS - 1)
8647 new_player_nr = MAX_PLAYERS - 1;
8649 if (new_player_nr != old_player_nr)
8651 input_player_nr = new_player_nr;
8653 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8657 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8659 static int choice = 0;
8662 int pos_start = SETUPINPUT_SCREEN_POS_START;
8663 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8664 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8665 int pos_end = SETUPINPUT_SCREEN_POS_END;
8667 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8671 for (i = 0; setup_info_input[i].type != 0; i++)
8673 // adjust menu structure according to skipped setup entries
8674 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8682 if (button == MB_MENU_INITIALIZE)
8684 // input setup menu may have changed size due to graphics configuration
8685 if (choice >= pos_empty1)
8688 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8690 DrawCursorAndText_Setup(choice, -1, TRUE);
8694 else if (button == MB_MENU_LEAVE)
8696 setup_mode = SETUP_MODE_MAIN;
8703 if (mx || my) // mouse input
8705 x = (mx - mSX) / 32;
8706 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8708 else if (dx || dy) // keyboard input
8710 if (dx && choice == 0)
8711 x = (dx < 0 ? 10 : 12);
8712 else if ((dx && choice == 1) ||
8713 (dx == -1 && choice == pos_end))
8714 button = MB_MENU_CHOICE;
8718 if (y >= pos_empty1 && y <= pos_empty2)
8719 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8722 if (y == 0 && dx != 0 && button)
8724 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8726 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8727 y >= pos_start && y <= pos_end &&
8728 !(y >= pos_empty1 && y <= pos_empty2))
8734 DrawCursorAndText_Setup(choice, -1, FALSE);
8735 DrawCursorAndText_Setup(y, -1, TRUE);
8737 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8746 char *device_name = setup.input[input_player_nr].joy.device_name;
8748 if (!setup.input[input_player_nr].use_joystick)
8750 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8752 setJoystickDeviceToNr(device_name, new_device_nr);
8753 setup.input[input_player_nr].use_joystick = TRUE;
8757 int device_nr = getJoystickNrFromDeviceName(device_name);
8758 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8760 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8761 setup.input[input_player_nr].use_joystick = FALSE;
8763 setJoystickDeviceToNr(device_name, new_device_nr);
8766 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8770 if (setup.input[input_player_nr].use_joystick)
8771 ConfigureJoystick(input_player_nr);
8773 CustomizeKeyboard(input_player_nr);
8775 else if (y == pos_end)
8781 setup_mode = SETUP_MODE_MAIN;
8788 static boolean CustomizeKeyboardMain(int player_nr)
8792 boolean finished = FALSE;
8793 static struct SetupKeyboardInfo custom_key;
8798 } customize_step[] =
8800 { &custom_key.left, "Move Left" },
8801 { &custom_key.right, "Move Right" },
8802 { &custom_key.up, "Move Up" },
8803 { &custom_key.down, "Move Down" },
8804 { &custom_key.snap, "Snap Field" },
8805 { &custom_key.drop, "Drop Element" }
8807 int font_nr_old = FONT_VALUE_OLD;
8808 int font_nr_new = FONT_VALUE_1;
8809 boolean success = FALSE;
8811 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8813 font_nr_old = FONT_VALUE_OLD_NARROW;
8814 font_nr_new = FONT_VALUE_NARROW;
8817 // read existing key bindings from player setup
8818 custom_key = setup.input[player_nr].key;
8821 FadeOut(REDRAW_FIELD);
8825 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8828 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8829 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8830 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8831 "Key:", FONT_INPUT_1_ACTIVE);
8832 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8833 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8835 FadeIn(REDRAW_FIELD);
8841 if (NextValidEvent(&event))
8845 case EVENT_KEYPRESS:
8847 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8849 // press 'Escape' to abort and keep the old key bindings
8850 if (key == KSYM_Escape)
8852 FadeSkipNextFadeIn();
8859 // press 'Enter' to keep the existing key binding
8860 if (key == KSYM_Return)
8861 key = *customize_step[step_nr].key;
8863 // check if key already used
8864 for (i = 0; i < step_nr; i++)
8865 if (*customize_step[i].key == key)
8870 // got new key binding
8871 *customize_step[step_nr].key = key;
8872 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8874 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8875 getKeyNameFromKey(key), font_nr_new);
8878 // un-highlight last query
8879 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8880 customize_step[step_nr - 1].text, FONT_MENU_1);
8881 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8882 "Key:", FONT_MENU_1);
8884 // all keys configured
8893 // query next key binding
8894 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8895 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8896 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8897 "Key:", FONT_INPUT_1_ACTIVE);
8898 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8899 getKeyNameFromKey(*customize_step[step_nr].key),
8904 case EVENT_KEYRELEASE:
8905 key_joystick_mapping = 0;
8909 HandleOtherEvents(&event);
8917 // write new key bindings back to player setup, if successfully finished
8919 setup.input[player_nr].key = custom_key;
8924 void CustomizeKeyboard(int player_nr)
8926 boolean success = CustomizeKeyboardMain(player_nr);
8930 int font_nr = FONT_TITLE_1;
8931 int font_height = getFontHeight(font_nr);
8932 int ypos1 = SYSIZE / 2 - font_height * 2;
8933 int ypos2 = SYSIZE / 2 - font_height * 1;
8934 unsigned int wait_frame_delay = 0;
8935 unsigned int wait_frame_delay_value = 2000;
8937 ResetDelayCounter(&wait_frame_delay);
8941 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8942 DrawTextSCentered(ypos2, font_nr, "configured!");
8944 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8950 DrawSetupScreen_Input();
8953 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8955 #define MARKER_BUTTON 1
8956 #define MARKER_AXIS_X 2
8957 #define MARKER_AXIS_Y 3
8959 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8961 static boolean bitmaps_initialized = FALSE;
8962 boolean screen_initialized = FALSE;
8963 static Bitmap *controller, *button, *axis_x, *axis_y;
8965 boolean success = TRUE;
8966 boolean done = FALSE, next = FALSE;
8968 int alpha = 200, alpha_step = -1;
8969 int alpha_ticks = 0;
8970 char mapping[4096], temp[256];
8971 int font_name = MENU_SETUP_FONT_TITLE;
8972 int font_info = MENU_SETUP_FONT_TEXT;
8973 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8974 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8975 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8976 int ystep_name = getMenuTextStep(spacing_name, font_name);
8977 int ystep_line = getMenuTextStep(spacing_line, font_info);
8978 int ystep_para = getMenuTextStep(spacing_para, font_info);
8986 int axis, button, hat, hat_value;
8989 *step, *prev_step, steps[] =
8991 { 356, 155, MARKER_BUTTON, "a", },
8992 { 396, 122, MARKER_BUTTON, "b", },
8993 { 320, 125, MARKER_BUTTON, "x", },
8994 { 358, 95, MARKER_BUTTON, "y", },
8995 { 162, 125, MARKER_BUTTON, "back", },
8996 { 216, 125, MARKER_BUTTON, "guide", },
8997 { 271, 125, MARKER_BUTTON, "start", },
8998 { 110, 200, MARKER_BUTTON, "dpleft", },
8999 { 146, 228, MARKER_BUTTON, "dpdown", },
9000 { 178, 200, MARKER_BUTTON, "dpright", },
9001 { 146, 172, MARKER_BUTTON, "dpup", },
9002 { 50, 40, MARKER_BUTTON, "leftshoulder", },
9003 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
9004 { 382, 40, MARKER_BUTTON, "rightshoulder", },
9005 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
9006 { 73, 141, MARKER_BUTTON, "leftstick", },
9007 { 282, 210, MARKER_BUTTON, "rightstick", },
9008 { 73, 141, MARKER_AXIS_X, "leftx", },
9009 { 73, 141, MARKER_AXIS_Y, "lefty", },
9010 { 282, 210, MARKER_AXIS_X, "rightx", },
9011 { 282, 210, MARKER_AXIS_Y, "righty", },
9014 unsigned int event_frame_delay = 0;
9015 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
9017 ResetDelayCounter(&event_frame_delay);
9019 if (!bitmaps_initialized)
9021 controller = LoadCustomImage("joystick/controller.png");
9022 button = LoadCustomImage("joystick/button.png");
9023 axis_x = LoadCustomImage("joystick/axis_x.png");
9024 axis_y = LoadCustomImage("joystick/axis_y.png");
9026 bitmaps_initialized = TRUE;
9029 name = getFormattedJoystickName(SDL_JoystickName(joystick));
9032 // print info about the joystick we are watching
9033 Debug("joystick", "watching joystick %d: (%s)",
9034 SDL_JoystickInstanceID(joystick), name);
9035 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
9036 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
9037 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
9040 // initialize mapping with GUID and name
9041 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
9043 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
9044 temp, name, SDL_GetPlatform());
9046 // loop through all steps (buttons and axes), getting joystick events
9047 for (i = 0; i < SDL_arraysize(steps) && !done;)
9049 Bitmap *marker = button; // initialize with reliable default value
9052 strcpy(step->mapping, mapping);
9056 step->hat_value = -1;
9058 marker = (step->marker == MARKER_BUTTON ? button :
9059 step->marker == MARKER_AXIS_X ? axis_x :
9060 step->marker == MARKER_AXIS_Y ? axis_y : marker);
9064 while (!done && !next)
9066 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
9067 alpha_ticks = SDL_GetTicks();
9074 else if (alpha < 128)
9080 int controller_x = SX + (SXSIZE - controller->width) / 2;
9081 int controller_y = SY + ystep_line;
9083 int marker_x = controller_x + step->x;
9084 int marker_y = controller_y + step->y;
9086 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
9087 int ystart2 = ystart1 + ystep_name + ystep_line;
9091 DrawTextSCentered(ystart1, font_name, name);
9093 DrawTextSCentered(ystart2, font_info,
9094 "Press buttons and move axes on");
9095 ystart2 += ystep_line;
9096 DrawTextSCentered(ystart2, font_info,
9097 "your controller when indicated.");
9098 ystart2 += ystep_line;
9099 DrawTextSCentered(ystart2, font_info,
9100 "(Your controller may look different.)");
9101 ystart2 += ystep_para;
9103 #if defined(PLATFORM_ANDROID)
9104 DrawTextSCentered(ystart2, font_info,
9105 "To correct a mistake,");
9106 ystart2 += ystep_line;
9107 DrawTextSCentered(ystart2, font_info,
9108 "press the 'back' button.");
9109 ystart2 += ystep_line;
9110 DrawTextSCentered(ystart2, font_info,
9111 "To skip a button or axis,");
9112 ystart2 += ystep_line;
9113 DrawTextSCentered(ystart2, font_info,
9114 "press the 'menu' button.");
9116 DrawTextSCentered(ystart2, font_info,
9117 "To correct a mistake,");
9118 ystart2 += ystep_line;
9119 DrawTextSCentered(ystart2, font_info,
9120 "press the 'backspace' key.");
9121 ystart2 += ystep_line;
9122 DrawTextSCentered(ystart2, font_info,
9123 "To skip a button or axis,");
9124 ystart2 += ystep_line;
9125 DrawTextSCentered(ystart2, font_info,
9126 "press the 'return' key.");
9127 ystart2 += ystep_line;
9128 DrawTextSCentered(ystart2, font_info,
9129 "To exit, press the 'escape' key.");
9132 BlitBitmapMasked(controller, drawto, 0, 0,
9133 controller->width, controller->height,
9134 controller_x, controller_y);
9136 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
9137 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
9139 BlitBitmapMasked(marker, drawto, 0, 0,
9140 marker->width, marker->height,
9141 marker_x, marker_y);
9143 if (!screen_initialized)
9144 FadeIn(REDRAW_FIELD);
9148 screen_initialized = TRUE;
9150 while (NextValidEvent(&event))
9154 case SDL_JOYAXISMOTION:
9155 if (event.jaxis.value > 20000 ||
9156 event.jaxis.value < -20000)
9158 for (j = 0; j < i; j++)
9159 if (steps[j].axis == event.jaxis.axis)
9164 if (step->marker != MARKER_AXIS_X &&
9165 step->marker != MARKER_AXIS_Y)
9168 step->axis = event.jaxis.axis;
9169 strcat(mapping, step->field);
9170 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
9171 strcat(mapping, temp);
9179 case SDL_JOYHATMOTION:
9180 // ignore centering; we're probably just coming back
9181 // to the center from the previous item we set
9182 if (event.jhat.value == SDL_HAT_CENTERED)
9185 for (j = 0; j < i; j++)
9186 if (steps[j].hat == event.jhat.hat &&
9187 steps[j].hat_value == event.jhat.value)
9192 step->hat = event.jhat.hat;
9193 step->hat_value = event.jhat.value;
9194 strcat(mapping, step->field);
9195 snprintf(temp, sizeof(temp), ":h%u.%u,",
9196 event.jhat.hat, event.jhat.value );
9197 strcat(mapping, temp);
9204 case SDL_JOYBALLMOTION:
9207 case SDL_JOYBUTTONUP:
9208 for (j = 0; j < i; j++)
9209 if (steps[j].button == event.jbutton.button)
9214 step->button = event.jbutton.button;
9215 strcat(mapping, step->field);
9216 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9217 strcat(mapping, temp);
9224 case SDL_FINGERDOWN:
9225 case SDL_MOUSEBUTTONDOWN:
9233 if (event.key.keysym.sym == KSYM_BackSpace ||
9234 event.key.keysym.sym == KSYM_Back)
9246 prev_step = &steps[i - 1];
9247 strcpy(mapping, prev_step->mapping);
9254 if (event.key.keysym.sym == KSYM_space ||
9255 event.key.keysym.sym == KSYM_Return ||
9256 event.key.keysym.sym == KSYM_Menu)
9265 if (event.key.keysym.sym == KSYM_Escape)
9275 program.exit_function(0);
9282 // do not handle events for longer than standard frame delay period
9283 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9292 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9295 // activate mapping for this game
9296 SDL_GameControllerAddMapping(mapping);
9298 // save mapping to personal mappings
9299 SaveSetup_AddGameControllerMapping(mapping);
9302 // wait until the last pending event was removed from event queue
9303 while (NextValidEvent(&event));
9308 static int ConfigureJoystickMain(int player_nr)
9310 char *device_name = setup.input[player_nr].joy.device_name;
9311 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9312 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9313 int success = FALSE;
9316 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9317 return JOYSTICK_NOT_AVAILABLE;
9319 if (!joystick_active || !setup.input[player_nr].use_joystick)
9320 return JOYSTICK_NOT_AVAILABLE;
9323 FadeOut(REDRAW_FIELD);
9325 // close all joystick devices (potentially opened as game controllers)
9326 for (i = 0; i < SDL_NumJoysticks(); i++)
9327 SDLCloseJoystick(i);
9329 // open joystick device as plain joystick to configure as game controller
9330 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9332 // as the joystick was successfully opened before, this should not happen
9333 if (joystick == NULL)
9336 // create new game controller mapping (buttons and axes) for joystick device
9337 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9339 // close joystick (and maybe re-open as configured game controller later)
9340 SDL_JoystickClose(joystick);
9342 // re-open all joystick devices (potentially as game controllers)
9343 for (i = 0; i < SDL_NumJoysticks(); i++)
9346 // clear all joystick input actions for all joystick devices
9347 SDLClearJoystickState();
9349 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9352 void ConfigureJoystick(int player_nr)
9354 boolean state = ConfigureJoystickMain(player_nr);
9356 if (state != JOYSTICK_NOT_CONFIGURED)
9358 boolean success = (state == JOYSTICK_CONFIGURED);
9359 char message1[MAX_OUTPUT_LINESIZE + 1];
9360 char *message2 = (success ? "configured!" : "not available!");
9361 char *device_name = setup.input[player_nr].joy.device_name;
9362 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9363 int font_nr = FONT_TITLE_1;
9364 int font_height = getFontHeight(font_nr);
9365 int ypos1 = SYSIZE / 2 - font_height * 2;
9366 int ypos2 = SYSIZE / 2 - font_height * 1;
9367 unsigned int wait_frame_delay = 0;
9368 unsigned int wait_frame_delay_value = 2000;
9370 ResetDelayCounter(&wait_frame_delay);
9374 sprintf(message1, "Joystick %d", nr);
9376 DrawTextSCentered(ypos1, font_nr, message1);
9377 DrawTextSCentered(ypos2, font_nr, message2);
9379 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9385 DrawSetupScreen_Input();
9388 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9390 if (y < video.screen_height / 3)
9392 // remap touch gadgets to access upper part of the screen
9393 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9394 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9396 else if (y > 2 * video.screen_height / 3)
9398 // remap touch gadgets to access lower part of the screen
9399 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9400 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9404 static boolean ConfigureVirtualButtonsMain(void)
9406 static char *customize_step_text[] =
9415 char grid_button[] =
9417 CHAR_GRID_BUTTON_LEFT,
9418 CHAR_GRID_BUTTON_RIGHT,
9419 CHAR_GRID_BUTTON_UP,
9420 CHAR_GRID_BUTTON_DOWN,
9421 CHAR_GRID_BUTTON_SNAP,
9422 CHAR_GRID_BUTTON_DROP
9431 int font_nr = FONT_INPUT_1_ACTIVE;
9432 int font_height = getFontHeight(font_nr);
9433 int ypos1 = SYSIZE / 2 - font_height * 2;
9434 int ypos2 = SYSIZE / 2 - font_height * 1;
9435 boolean success = FALSE;
9436 boolean finished = FALSE;
9438 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9439 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9440 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9441 boolean set_grid_button = FALSE;
9442 int nr = GRID_ACTIVE_NR();
9445 for (x = 0; x < MAX_GRID_XSIZE; x++)
9446 for (y = 0; y < MAX_GRID_YSIZE; y++)
9447 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9449 overlay.grid_button_highlight = grid_button[step_nr];
9454 FadeOut(REDRAW_FIELD);
9458 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9459 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9460 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9462 FadeIn(REDRAW_FIELD);
9464 SetOverlayShowGrid(TRUE);
9466 // map gadgets for setup touch buttons menu screen
9467 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9473 while (NextValidEvent(&event))
9475 int action = ACTION_NONE;
9477 // ---------- handle events and set the resulting action ----------
9483 UserEvent *user = (UserEvent *)&event;
9484 int id = user->value1;
9486 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9487 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9488 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9489 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9494 case EVENT_KEYPRESS:
9496 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9498 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9499 key == KSYM_BackSpace ||
9500 key == KSYM_Back ? ACTION_BACK :
9501 key == KSYM_Return ||
9503 key == KSYM_space ? ACTION_NEXT :
9508 case EVENT_KEYRELEASE:
9509 key_joystick_mapping = 0;
9512 case EVENT_BUTTONPRESS:
9513 case EVENT_BUTTONRELEASE:
9515 ButtonEvent *button = (ButtonEvent *)&event;
9517 motion_status = FALSE;
9519 if (button->type == EVENT_BUTTONPRESS)
9520 button_status = button->button;
9522 button_status = MB_RELEASED;
9524 if (HandleGadgets(button->x, button->y, button_status))
9526 // do not handle this button event anymore
9530 button->x += video.screen_xoffset;
9531 button->y += video.screen_yoffset;
9533 x = button->x * overlay.grid_xsize / video.screen_width;
9534 y = button->y * overlay.grid_ysize / video.screen_height;
9536 if (button->type == EVENT_BUTTONPRESS)
9539 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9540 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9542 set_grid_button = TRUE;
9545 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9549 case EVENT_MOTIONNOTIFY:
9551 MotionEvent *motion = (MotionEvent *)&event;
9553 motion_status = TRUE;
9555 if (HandleGadgets(motion->x, motion->y, button_status))
9557 // do not handle this button event anymore
9561 motion->x += video.screen_xoffset;
9562 motion->y += video.screen_yoffset;
9564 x = motion->x * overlay.grid_xsize / video.screen_width;
9565 y = motion->y * overlay.grid_ysize / video.screen_height;
9567 set_grid_button = TRUE;
9569 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9573 case SDL_WINDOWEVENT:
9574 HandleWindowEvent((WindowEvent *) &event);
9576 // check if device has been rotated
9577 if (nr != GRID_ACTIVE_NR())
9579 nr = GRID_ACTIVE_NR();
9581 for (x = 0; x < MAX_GRID_XSIZE; x++)
9582 for (y = 0; y < MAX_GRID_YSIZE; y++)
9583 grid_button_old[x][y] = grid_button_tmp[x][y] =
9584 overlay.grid_button[x][y];
9589 case SDL_APP_WILLENTERBACKGROUND:
9590 case SDL_APP_DIDENTERBACKGROUND:
9591 case SDL_APP_WILLENTERFOREGROUND:
9592 case SDL_APP_DIDENTERFOREGROUND:
9593 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9597 HandleOtherEvents(&event);
9601 // ---------- perform action set by handling events ----------
9603 if (action == ACTION_ESCAPE)
9605 // abort and restore the old key bindings
9607 for (x = 0; x < MAX_GRID_XSIZE; x++)
9608 for (y = 0; y < MAX_GRID_YSIZE; y++)
9609 overlay.grid_button[x][y] = grid_button_old[x][y];
9611 FadeSkipNextFadeIn();
9615 else if (action == ACTION_BACK)
9617 // keep the configured key bindings and go to previous page
9623 FadeSkipNextFadeIn();
9628 else if (action == ACTION_NEXT)
9630 // keep the configured key bindings and go to next page
9634 // all virtual buttons configured
9642 if (action != ACTION_NONE && !finished)
9644 for (x = 0; x < MAX_GRID_XSIZE; x++)
9645 for (y = 0; y < MAX_GRID_YSIZE; y++)
9646 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9648 overlay.grid_button_highlight = grid_button[step_nr];
9650 // configure next virtual button
9654 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9655 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9656 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9659 if (set_grid_button)
9661 overlay.grid_button[x][y] =
9662 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9663 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9664 grid_button_tmp[x][y]);
9666 set_grid_button = FALSE;
9673 for (x = 0; x < MAX_GRID_XSIZE; x++)
9674 for (y = 0; y < MAX_GRID_YSIZE; y++)
9675 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9677 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9679 SetOverlayShowGrid(FALSE);
9684 void ConfigureVirtualButtons(void)
9686 boolean success = ConfigureVirtualButtonsMain();
9688 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9689 SCREEN_MASK_TOUCH2);
9693 int font_nr = FONT_TITLE_1;
9694 int font_height = getFontHeight(font_nr);
9695 int ypos1 = SYSIZE / 2 - font_height * 2;
9696 int ypos2 = SYSIZE / 2 - font_height * 1;
9697 unsigned int wait_frame_delay = 0;
9698 unsigned int wait_frame_delay_value = 2000;
9700 ResetDelayCounter(&wait_frame_delay);
9704 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9705 DrawTextSCentered(ypos2, font_nr, "configured!");
9707 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9714 void DrawSetupScreen(void)
9719 if (setup_mode == SETUP_MODE_INPUT)
9720 DrawSetupScreen_Input();
9721 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9722 DrawChooseTree(&scores_type_current);
9723 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9724 DrawChooseTree(&game_speed_current);
9725 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9726 DrawChooseTree(&scroll_delay_current);
9727 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9728 DrawChooseTree(&snapshot_mode_current);
9729 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9730 DrawChooseTree(&window_size_current);
9731 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9732 DrawChooseTree(&scaling_type_current);
9733 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9734 DrawChooseTree(&rendering_mode_current);
9735 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9736 DrawChooseTree(&vsync_mode_current);
9737 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9738 DrawChooseTree(&artwork.gfx_current);
9739 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9740 DrawChooseTree(&artwork.snd_current);
9741 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9742 DrawChooseTree(&artwork.mus_current);
9743 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9744 DrawChooseTree(&volume_simple_current);
9745 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9746 DrawChooseTree(&volume_loops_current);
9747 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9748 DrawChooseTree(&volume_music_current);
9749 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9750 DrawChooseTree(&touch_control_current);
9751 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9752 DrawChooseTree(&move_distance_current);
9753 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9754 DrawChooseTree(&drop_distance_current);
9755 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9756 DrawChooseTree(&transparency_current);
9757 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9758 DrawChooseTree(&grid_size_current[0][0]);
9759 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9760 DrawChooseTree(&grid_size_current[0][1]);
9761 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9762 DrawChooseTree(&grid_size_current[1][0]);
9763 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9764 DrawChooseTree(&grid_size_current[1][1]);
9766 DrawSetupScreen_Generic();
9768 PlayMenuSoundsAndMusic();
9771 void RedrawSetupScreenAfterFullscreenToggle(void)
9773 if (setup_mode == SETUP_MODE_GRAPHICS ||
9774 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9776 // update list selection from "setup.window_scaling_percent"
9777 execSetupGraphics_setWindowSizes(TRUE);
9783 void RedrawSetupScreenAfterScreenRotation(int nr)
9787 if (setup_mode == SETUP_MODE_TOUCH)
9789 // update virtual button settings (depending on screen orientation)
9792 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9794 // save already configured virtual buttons
9795 for (x = 0; x < MAX_GRID_XSIZE; x++)
9796 for (y = 0; y < MAX_GRID_YSIZE; y++)
9797 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9801 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9803 if (setup_mode == SETUP_MODE_INPUT)
9804 HandleSetupScreen_Input(mx, my, dx, dy, button);
9805 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9806 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9807 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9808 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9809 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9810 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9811 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9812 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9813 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9814 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9815 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9816 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9817 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9818 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9819 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9820 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9821 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9822 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9823 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9824 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9825 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9826 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9827 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9828 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9829 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9830 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9831 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9832 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9833 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9834 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9835 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9836 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9837 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9838 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9839 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9840 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9841 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9842 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9843 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9844 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9845 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9846 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9847 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9848 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9850 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9853 void HandleGameActions(void)
9855 if (setup.ask_on_game_over)
9858 if (game.restart_game_message != NULL)
9860 RequestRestartGame(game.restart_game_message);
9865 if (game_status != GAME_MODE_PLAYING)
9868 GameActions(); // main game loop
9870 if (tape.auto_play && !tape.playing)
9871 AutoPlayTapesContinue(); // continue automatically playing next tape
9875 // ---------- new screen button stuff --------------------------------------
9879 int gfx_unpressed, gfx_pressed;
9880 struct MenuPosInfo *pos;
9881 boolean *check_value;
9884 unsigned int event_mask;
9885 boolean is_touch_button;
9887 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9890 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9891 &menu.main.button.prev_level, NULL,
9892 SCREEN_CTRL_ID_PREV_LEVEL,
9894 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9895 FALSE, "previous level"
9898 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9899 &menu.main.button.next_level, NULL,
9900 SCREEN_CTRL_ID_NEXT_LEVEL,
9902 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9906 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9907 &menu.scores.button.prev_level, NULL,
9908 SCREEN_CTRL_ID_PREV_LEVEL2,
9909 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9910 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9911 FALSE, "previous level"
9914 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9915 &menu.scores.button.next_level, NULL,
9916 SCREEN_CTRL_ID_NEXT_LEVEL2,
9917 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9918 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9922 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9923 &menu.scores.button.prev_score, NULL,
9924 SCREEN_CTRL_ID_PREV_SCORE,
9925 SCREEN_MASK_SCORES_INFO,
9926 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9927 FALSE, "previous score"
9930 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9931 &menu.scores.button.next_score, NULL,
9932 SCREEN_CTRL_ID_NEXT_SCORE,
9933 SCREEN_MASK_SCORES_INFO,
9934 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9938 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9939 &menu.main.button.first_level, NULL,
9940 SCREEN_CTRL_ID_FIRST_LEVEL,
9943 FALSE, "first level"
9946 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9947 &menu.main.button.last_level, NULL,
9948 SCREEN_CTRL_ID_LAST_LEVEL,
9954 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9955 &menu.main.button.level_number, NULL,
9956 SCREEN_CTRL_ID_LEVEL_NUMBER,
9959 FALSE, "level number"
9962 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9963 &menu.setup.button.prev_player, NULL,
9964 SCREEN_CTRL_ID_PREV_PLAYER,
9966 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9967 FALSE, "previous player"
9970 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9971 &menu.setup.button.next_player, NULL,
9972 SCREEN_CTRL_ID_NEXT_PLAYER,
9974 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9975 FALSE, "next player"
9978 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9979 &menu.main.button.insert_solution, NULL,
9980 SCREEN_CTRL_ID_INSERT_SOLUTION,
9981 SCREEN_MASK_MAIN_HAS_SOLUTION,
9983 FALSE, "insert solution tape"
9986 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9987 &menu.main.button.play_solution, NULL,
9988 SCREEN_CTRL_ID_PLAY_SOLUTION,
9989 SCREEN_MASK_MAIN_HAS_SOLUTION,
9991 FALSE, "play solution tape"
9994 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9995 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9996 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9998 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9999 FALSE, "switch ECS/AGA chipset"
10002 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
10003 &menu.setup.button.touch_back, NULL,
10004 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
10007 TRUE, "previous page"
10010 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
10011 &menu.setup.button.touch_next, NULL,
10012 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
10018 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
10019 &menu.setup.button.touch_back2, NULL,
10020 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
10021 SCREEN_MASK_TOUCH2,
10023 TRUE, "previous page"
10026 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
10027 &menu.setup.button.touch_next2, NULL,
10028 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
10029 SCREEN_MASK_TOUCH2,
10037 int gfx_unpressed, gfx_pressed;
10041 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
10044 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
10045 -1, -1, // these values are not constant, but can change at runtime
10046 SCREEN_CTRL_ID_SCROLL_UP,
10050 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
10051 -1, -1, // these values are not constant, but can change at runtime
10052 SCREEN_CTRL_ID_SCROLL_DOWN,
10059 int gfx_unpressed, gfx_pressed;
10065 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
10068 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
10069 -1, -1, // these values are not constant, but can change at runtime
10070 -1, -1, // these values are not constant, but can change at runtime
10071 GD_TYPE_SCROLLBAR_VERTICAL,
10072 SCREEN_CTRL_ID_SCROLL_VERTICAL,
10073 "scroll level series vertically"
10085 } textinput_info[NUM_SCREEN_TEXTINPUT] =
10088 IMG_SETUP_INPUT_TEXT,
10089 SCREEN_CTRL_ID_NETWORK_SERVER,
10090 -1, -1, // these values are not constant, but can change at runtime
10091 MAX_SETUP_TEXT_INPUT_LEN,
10092 network_server_hostname,
10093 "Network Server Hostname / IP"
10097 static void CreateScreenMenubuttons(void)
10099 struct GadgetInfo *gi;
10100 unsigned int event_mask;
10103 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10105 struct MenuPosInfo *pos = menubutton_info[i].pos;
10106 int screen_mask = menubutton_info[i].screen_mask;
10107 boolean is_touch_button = menubutton_info[i].is_touch_button;
10108 boolean is_check_button = menubutton_info[i].check_value != NULL;
10109 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
10110 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10111 int gfx_unpressed, gfx_pressed;
10112 int x, y, width, height;
10113 int gd_x1, gd_x2, gd_y1, gd_y2;
10114 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
10115 int id = menubutton_info[i].gadget_id;
10116 int type = GD_TYPE_NORMAL_BUTTON;
10117 boolean checked = FALSE;
10119 event_mask = menubutton_info[i].event_mask;
10121 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
10122 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
10124 width = graphic_info[menubutton_info[i].gfx_pressed].width;
10125 height = graphic_info[menubutton_info[i].gfx_pressed].height;
10127 gfx_unpressed = menubutton_info[i].gfx_unpressed;
10128 gfx_pressed = menubutton_info[i].gfx_pressed;
10129 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10130 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10131 gd_x1 = graphic_info[gfx_unpressed].src_x;
10132 gd_y1 = graphic_info[gfx_unpressed].src_y;
10133 gd_x2 = graphic_info[gfx_pressed].src_x;
10134 gd_y2 = graphic_info[gfx_pressed].src_y;
10140 if (is_touch_button)
10142 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
10143 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
10146 if (is_check_button)
10148 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
10149 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
10150 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
10151 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
10153 type = GD_TYPE_CHECK_BUTTON;
10154 checked = *menubutton_info[i].check_value;
10157 if (is_score_button)
10159 // if x/y set to -1, dynamically place buttons next to title text
10160 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10163 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10164 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10165 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10166 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10169 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
10170 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
10173 gi = CreateGadget(GDI_CUSTOM_ID, id,
10174 GDI_CUSTOM_TYPE_ID, i,
10175 GDI_IMAGE_ID, gfx_unpressed,
10176 GDI_INFO_TEXT, menubutton_info[i].infotext,
10180 GDI_HEIGHT, height,
10182 GDI_STATE, GD_BUTTON_UNPRESSED,
10183 GDI_CHECKED, checked,
10184 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10185 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10186 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
10187 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
10188 GDI_DIRECT_DRAW, FALSE,
10189 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10190 GDI_EVENT_MASK, event_mask,
10191 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10195 Fail("cannot create gadget");
10197 screen_gadget[id] = gi;
10201 static void CreateScreenScrollbuttons(void)
10203 struct GadgetInfo *gi;
10204 unsigned int event_mask;
10207 // these values are not constant, but can change at runtime
10208 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10209 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10210 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10211 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10213 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10215 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10216 int gfx_unpressed, gfx_pressed;
10217 int x, y, width, height;
10218 int gd_x1, gd_x2, gd_y1, gd_y2;
10219 int id = scrollbutton_info[i].gadget_id;
10221 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10223 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10224 y = mSY + scrollbutton_info[i].y;
10225 width = SC_SCROLLBUTTON_XSIZE;
10226 height = SC_SCROLLBUTTON_YSIZE;
10228 // correct scrollbar position if placed outside menu (playfield) area
10229 if (x > SX + SC_SCROLL_UP_XPOS)
10230 x = SX + SC_SCROLL_UP_XPOS;
10232 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10233 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10234 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10236 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10237 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10238 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10239 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10240 gd_x1 = graphic_info[gfx_unpressed].src_x;
10241 gd_y1 = graphic_info[gfx_unpressed].src_y;
10242 gd_x2 = graphic_info[gfx_pressed].src_x;
10243 gd_y2 = graphic_info[gfx_pressed].src_y;
10245 gi = CreateGadget(GDI_CUSTOM_ID, id,
10246 GDI_CUSTOM_TYPE_ID, i,
10247 GDI_IMAGE_ID, gfx_unpressed,
10248 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10252 GDI_HEIGHT, height,
10253 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10254 GDI_STATE, GD_BUTTON_UNPRESSED,
10255 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10256 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10257 GDI_DIRECT_DRAW, FALSE,
10258 GDI_EVENT_MASK, event_mask,
10259 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10263 Fail("cannot create gadget");
10265 screen_gadget[id] = gi;
10269 static void CreateScreenScrollbars(void)
10273 // these values are not constant, but can change at runtime
10274 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10275 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10276 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10277 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10279 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10281 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10282 int gfx_unpressed, gfx_pressed;
10283 int x, y, width, height;
10284 int gd_x1, gd_x2, gd_y1, gd_y2;
10285 struct GadgetInfo *gi;
10286 int items_max, items_visible, item_position;
10287 unsigned int event_mask;
10288 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10289 int id = scrollbar_info[i].gadget_id;
10291 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10293 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10294 y = mSY + scrollbar_info[i].y;
10295 width = scrollbar_info[i].width;
10296 height = scrollbar_info[i].height;
10298 // correct scrollbar position if placed outside menu (playfield) area
10299 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10300 x = SX + SC_SCROLL_VERTICAL_XPOS;
10302 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10303 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10305 items_max = num_page_entries;
10306 items_visible = num_page_entries;
10309 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10310 gfx_pressed = scrollbar_info[i].gfx_pressed;
10311 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10312 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10313 gd_x1 = graphic_info[gfx_unpressed].src_x;
10314 gd_y1 = graphic_info[gfx_unpressed].src_y;
10315 gd_x2 = graphic_info[gfx_pressed].src_x;
10316 gd_y2 = graphic_info[gfx_pressed].src_y;
10318 gi = CreateGadget(GDI_CUSTOM_ID, id,
10319 GDI_CUSTOM_TYPE_ID, i,
10320 GDI_IMAGE_ID, gfx_unpressed,
10321 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10325 GDI_HEIGHT, height,
10326 GDI_TYPE, scrollbar_info[i].type,
10327 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10328 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10329 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10330 GDI_WHEEL_AREA_X, SX,
10331 GDI_WHEEL_AREA_Y, SY,
10332 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10333 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10334 GDI_STATE, GD_BUTTON_UNPRESSED,
10335 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10336 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10337 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10338 GDI_DIRECT_DRAW, FALSE,
10339 GDI_EVENT_MASK, event_mask,
10340 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10344 Fail("cannot create gadget");
10346 screen_gadget[id] = gi;
10350 static void CreateScreenTextInputGadgets(void)
10354 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10356 int graphic = textinput_info[i].graphic;
10357 struct GraphicInfo *gd = &graphic_info[graphic];
10358 int gd_x1 = gd->src_x;
10359 int gd_y1 = gd->src_y;
10360 int gd_x2 = gd->src_x + gd->active_xoffset;
10361 int gd_y2 = gd->src_y + gd->active_yoffset;
10362 struct GadgetInfo *gi;
10363 unsigned int event_mask;
10364 int id = textinput_info[i].gadget_id;
10365 int x = textinput_info[i].x;
10366 int y = textinput_info[i].y;
10368 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10370 gi = CreateGadget(GDI_CUSTOM_ID, id,
10371 GDI_CUSTOM_TYPE_ID, i,
10372 GDI_INFO_TEXT, textinput_info[i].infotext,
10375 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10376 GDI_TEXT_VALUE, textinput_info[i].value,
10377 GDI_TEXT_SIZE, textinput_info[i].size,
10378 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10379 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10380 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10381 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10382 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10383 GDI_DESIGN_WIDTH, gd->width,
10384 GDI_EVENT_MASK, event_mask,
10385 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10386 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10390 Fail("cannot create gadget");
10392 screen_gadget[id] = gi;
10396 void CreateScreenGadgets(void)
10398 CreateScreenMenubuttons();
10400 CreateScreenScrollbuttons();
10401 CreateScreenScrollbars();
10403 CreateScreenTextInputGadgets();
10406 void FreeScreenGadgets(void)
10410 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10411 FreeGadget(screen_gadget[i]);
10414 static void RedrawScreenMenuGadgets(int screen_mask)
10418 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10419 if (screen_mask & menubutton_info[i].screen_mask)
10420 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10423 static void MapScreenMenuGadgets(int screen_mask)
10427 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10428 if (screen_mask & menubutton_info[i].screen_mask)
10429 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10432 static void UnmapScreenMenuGadgets(int screen_mask)
10436 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10438 if (screen_mask & menubutton_info[i].screen_mask)
10440 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10442 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10443 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10444 screen_gadget[menubutton_info[i].gadget_id]->y,
10445 screen_gadget[menubutton_info[i].gadget_id]->width,
10446 screen_gadget[menubutton_info[i].gadget_id]->height);
10451 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10454 MapScreenMenuGadgets(screen_mask);
10456 UnmapScreenMenuGadgets(screen_mask);
10459 static void MapScreenGadgets(int num_entries)
10463 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10466 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10467 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10469 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10470 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10473 static void UnmapScreenGadgets()
10477 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10478 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10480 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10481 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10484 static void MapScreenTreeGadgets(TreeInfo *ti)
10486 MapScreenGadgets(numTreeInfoInGroup(ti));
10489 static void UnmapScreenTreeGadgets(void)
10491 UnmapScreenGadgets();
10494 static void AdjustScoreInfoButtons(int x, int y1, int y2)
10496 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10497 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10498 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10499 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10501 if (pos_1->x == -1 && pos_1->y == -1)
10502 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10504 if (pos_2->x == -1 && pos_2->y == -1)
10505 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10508 static void HandleScreenGadgets(struct GadgetInfo *gi)
10510 int id = gi->custom_id;
10511 int button = gi->event.button;
10512 int step = (button == MB_LEFTBUTTON ? 1 :
10513 button == MB_MIDDLEBUTTON ? 5 :
10514 button == MB_RIGHTBUTTON ? 10 : 1);
10518 case SCREEN_CTRL_ID_PREV_LEVEL:
10519 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10522 case SCREEN_CTRL_ID_NEXT_LEVEL:
10523 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10526 case SCREEN_CTRL_ID_PREV_LEVEL2:
10527 HandleHallOfFame_SelectLevel(step, -1);
10530 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10531 HandleHallOfFame_SelectLevel(step, +1);
10534 case SCREEN_CTRL_ID_PREV_SCORE:
10535 HandleScoreInfo_SelectScore(step, -1);
10538 case SCREEN_CTRL_ID_NEXT_SCORE:
10539 HandleScoreInfo_SelectScore(step, +1);
10542 case SCREEN_CTRL_ID_FIRST_LEVEL:
10543 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10546 case SCREEN_CTRL_ID_LAST_LEVEL:
10547 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10550 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10551 CloseDoor(DOOR_CLOSE_2);
10552 SetGameStatus(GAME_MODE_LEVELNR);
10553 DrawChooseLevelNr();
10556 case SCREEN_CTRL_ID_PREV_PLAYER:
10557 HandleSetupScreen_Input_Player(step, -1);
10560 case SCREEN_CTRL_ID_NEXT_PLAYER:
10561 HandleSetupScreen_Input_Player(step, +1);
10564 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10565 InsertSolutionTape();
10568 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10569 PlaySolutionTape();
10572 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10573 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10577 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10578 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10579 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10580 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10581 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10584 case SCREEN_CTRL_ID_SCROLL_UP:
10585 if (game_status == GAME_MODE_NAMES)
10586 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10587 else if (game_status == GAME_MODE_LEVELS)
10588 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10589 else if (game_status == GAME_MODE_LEVELNR)
10590 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10591 else if (game_status == GAME_MODE_SETUP)
10592 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10593 else if (game_status == GAME_MODE_INFO)
10594 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10595 else if (game_status == GAME_MODE_SCORES)
10596 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10599 case SCREEN_CTRL_ID_SCROLL_DOWN:
10600 if (game_status == GAME_MODE_NAMES)
10601 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10602 else if (game_status == GAME_MODE_LEVELS)
10603 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10604 else if (game_status == GAME_MODE_LEVELNR)
10605 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10606 else if (game_status == GAME_MODE_SETUP)
10607 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10608 else if (game_status == GAME_MODE_INFO)
10609 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10610 else if (game_status == GAME_MODE_SCORES)
10611 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10614 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10615 if (game_status == GAME_MODE_NAMES)
10616 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10617 else if (game_status == GAME_MODE_LEVELS)
10618 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10619 else if (game_status == GAME_MODE_LEVELNR)
10620 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10621 else if (game_status == GAME_MODE_SETUP)
10622 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10623 else if (game_status == GAME_MODE_INFO)
10624 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10625 else if (game_status == GAME_MODE_SCORES)
10626 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10629 case SCREEN_CTRL_ID_NETWORK_SERVER:
10631 if (!strEqual(gi->textinput.value, ""))
10633 setString(&setup.network_server_hostname, gi->textinput.value);
10635 network.server_host = setup.network_server_hostname;
10639 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10641 network.server_host = NULL;
10644 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10645 network.server_host = NULL;
10647 execSetupGame_setNetworkServerText();
10659 void DumpScreenIdentifiers(void)
10663 Print("Active screen elements on current screen:\n");
10665 for (i = 0; main_controls[i].nr != -1; i++)
10667 struct MainControlInfo *mci = &main_controls[i];
10669 if (mci->button_graphic != -1)
10671 char *token = getTokenFromImageID(mci->button_graphic);
10673 Print("- '%s'\n", token);
10680 boolean DoScreenAction(int image_id)
10684 if (game_status != GAME_MODE_MAIN)
10687 for (i = 0; main_controls[i].nr != -1; i++)
10689 struct MainControlInfo *mci = &main_controls[i];
10690 struct MenuPosInfo *pos = mci->pos_button;
10692 if (mci->button_graphic == image_id)
10694 int x = mSX + pos->x;
10695 int y = mSY + pos->y;
10697 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10706 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10708 // get tree info node of newly added level or artwork set
10709 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10710 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10712 if (tree_node_new == NULL) // should not happen
10715 // if request dialog is active, do nothing
10716 if (game.request_active)
10719 if (game_status == GAME_MODE_MAIN &&
10720 tree_type == TREE_TYPE_LEVEL_DIR)
10722 // when adding new level set in main menu, select it as current level set
10724 // change current level set to newly added level set from zip file
10725 leveldir_current = tree_node_new;
10727 // change current level number to first level of newly added level set
10728 level_nr = leveldir_current->first_level;
10730 // redraw screen to reflect changed level set
10733 // save this level set and level number as last selected level set
10734 SaveLevelSetup_LastSeries();
10735 SaveLevelSetup_SeriesInfo();
10737 else if (game_status == GAME_MODE_LEVELS &&
10738 tree_type == TREE_TYPE_LEVEL_DIR)
10740 // when adding new level set in level set menu, set cursor and update screen
10742 leveldir_current = tree_node_new;
10744 DrawChooseTree(&leveldir_current);
10746 else if (game_status == GAME_MODE_SETUP)
10748 // when adding new artwork set in setup menu, set cursor and update screen
10750 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10751 tree_type == TREE_TYPE_GRAPHICS_DIR)
10753 artwork.gfx_current = tree_node_new;
10755 DrawChooseTree(&artwork.gfx_current);
10757 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10758 tree_type == TREE_TYPE_SOUNDS_DIR)
10760 artwork.snd_current = tree_node_new;
10762 DrawChooseTree(&artwork.snd_current);
10764 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10765 tree_type == TREE_TYPE_MUSIC_DIR)
10767 artwork.mus_current = tree_node_new;
10769 DrawChooseTree(&artwork.mus_current);
10774 static int UploadTapes(void)
10776 SetGameStatus(GAME_MODE_LOADING);
10778 FadeSetEnterScreen();
10779 FadeOut(REDRAW_ALL);
10781 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10783 FadeIn(REDRAW_ALL);
10785 DrawInitTextHead("Uploading tapes");
10787 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10788 global.autoplay_leveldir = "ALL";
10789 global.autoplay_all = TRUE;
10791 int num_tapes_uploaded = AutoPlayTapes();
10793 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10794 global.autoplay_leveldir = NULL;
10795 global.autoplay_all = FALSE;
10797 SetGameStatus(GAME_MODE_MAIN);
10801 return num_tapes_uploaded;
10804 static boolean OfferUploadTapes(void)
10806 if (!Request(setup.has_remaining_tapes ?
10807 "Upload missing tapes to the high score server now?" :
10808 "Upload all your tapes to the high score server now?", REQ_ASK))
10811 int num_tapes_uploaded = UploadTapes();
10814 if (num_tapes_uploaded < 0)
10816 num_tapes_uploaded = -num_tapes_uploaded - 1;
10818 if (num_tapes_uploaded == 0)
10819 sprintf(message, "Upload failed! No tapes uploaded!");
10820 else if (num_tapes_uploaded == 1)
10821 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10823 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10824 num_tapes_uploaded);
10826 Request(message, REQ_CONFIRM);
10828 // if uploading tapes failed, add tape upload entry to setup menu
10829 setup.provide_uploading_tapes = TRUE;
10830 setup.has_remaining_tapes = TRUE;
10832 SaveSetup_ServerSetup();
10837 if (num_tapes_uploaded == 0)
10838 sprintf(message, "No tapes uploaded!");
10839 else if (num_tapes_uploaded == 1)
10840 sprintf(message, "1 tape uploaded!");
10842 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10844 Request(message, REQ_CONFIRM);
10846 if (num_tapes_uploaded > 0)
10847 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10849 // after all tapes have been uploaded, remove entry from setup menu
10850 setup.provide_uploading_tapes = FALSE;
10851 setup.has_remaining_tapes = FALSE;
10853 SaveSetup_ServerSetup();
10858 static void CheckUploadTapes(void)
10860 if (!setup.ask_for_uploading_tapes)
10863 // after asking for uploading tapes, do not ask again
10864 setup.ask_for_uploading_tapes = FALSE;
10865 setup.ask_for_remaining_tapes = FALSE;
10867 if (directoryExists(getTapeDir(NULL)))
10869 boolean tapes_uploaded = OfferUploadTapes();
10871 if (!tapes_uploaded)
10873 Request(setup.has_remaining_tapes ?
10874 "You can upload missing tapes from the setup menu later!" :
10875 "You can upload your tapes from the setup menu later!",
10881 // if tapes directory does not exist yet, never offer uploading all tapes
10882 setup.provide_uploading_tapes = FALSE;
10885 SaveSetup_ServerSetup();
10888 static void UpgradePlayerUUID(void)
10890 ApiResetUUIDAsThread(getUUID());
10893 static void CheckUpgradePlayerUUID(void)
10895 if (setup.player_version > 1)
10898 UpgradePlayerUUID();
10901 void CheckApiServerTasks(void)
10903 // check if the player's UUID has to be upgraded
10904 CheckUpgradePlayerUUID();
10906 // check if there are any tapes to be uploaded
10907 CheckUploadTapes();