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 init_last = init; // switch to new busy animation
1693 // needed if last screen (level choice) changed graphics, sounds or music
1694 ReloadCustomArtwork(0);
1696 if (CheckTitleScreen(levelset_has_changed))
1698 SetGameStatus(GAME_MODE_TITLE);
1705 if (redraw_mask & REDRAW_ALL)
1706 fade_mask = REDRAW_ALL;
1709 fade_mask = REDRAW_ALL;
1713 // needed if different viewport properties defined for menues
1714 ChangeViewportPropertiesIfNeeded();
1716 SetDrawtoField(DRAW_TO_BACKBUFFER);
1718 // level_nr may have been set to value over handicap with level editor
1719 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1720 level_nr = leveldir_current->handicap_level;
1722 LoadLevel(level_nr);
1723 LoadScore(level_nr);
1725 SaveLevelSetup_SeriesInfo();
1727 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1728 SetDrawDeactivationMask(REDRAW_NONE);
1729 SetDrawBackgroundMask(REDRAW_FIELD);
1731 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1734 if (fade_mask == REDRAW_ALL)
1735 RedrawGlobalBorder();
1740 InitializeMainControls();
1742 DrawCursorAndText_Main(-1, FALSE, FALSE);
1743 DrawPreviewLevelInitial();
1744 DrawNetworkPlayers();
1746 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1749 if (TAPE_IS_EMPTY(tape))
1751 DrawCompleteVideoDisplay();
1753 PlayMenuSoundsAndMusic();
1755 // create gadgets for main menu screen
1756 FreeScreenGadgets();
1757 CreateScreenGadgets();
1759 // may be required if audio buttons shown on tape and changed in setup menu
1761 CreateGameButtons();
1763 // map gadgets for main menu screen
1765 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1766 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1768 // copy actual game door content to door double buffer for OpenDoor()
1769 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1770 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1772 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1774 DrawMaskedBorder(fade_mask);
1779 // update screen area with special editor door
1780 redraw_mask |= REDRAW_ALL;
1783 SetMouseCursor(CURSOR_DEFAULT);
1785 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1787 SyncEmscriptenFilesystem();
1789 // needed once after program start or after user change
1790 CheckApiServerTasks();
1793 static void gotoTopLevelDir(void)
1795 // move upwards until inside (but not above) top level directory
1796 while (leveldir_current->node_parent &&
1797 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1799 // write a "path" into level tree for easy navigation to last level
1800 if (leveldir_current->node_parent->node_group->cl_first == -1)
1802 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1803 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1804 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1805 int cl_first, cl_cursor;
1807 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1808 cl_cursor = leveldir_pos - cl_first;
1810 leveldir_current->node_parent->node_group->cl_first = cl_first;
1811 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1814 leveldir_current = leveldir_current->node_parent;
1818 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1820 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1822 return (use_frame_counter ? video.frame_counter : Counter());
1825 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1826 struct TitleFadingInfo *fi)
1828 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1831 static void ResetTitleAutoDelay(unsigned int *counter_var,
1832 struct TitleFadingInfo *fi)
1834 *counter_var = getAutoDelayCounter(fi);
1837 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1839 static unsigned int title_delay = 0;
1840 static int title_screen_nr = 0;
1841 static int last_sound = -1, last_music = -1;
1842 boolean return_to_main_menu = FALSE;
1843 struct TitleControlInfo *tci;
1846 if (button == MB_MENU_INITIALIZE)
1849 title_screen_nr = 0;
1850 tci = &title_controls[title_screen_nr];
1852 SetAnimStatus(getTitleAnimMode(tci));
1854 last_sound = SND_UNDEFINED;
1855 last_music = MUS_UNDEFINED;
1857 if (num_title_screens != 0)
1859 FadeSetEnterScreen();
1861 // use individual title fading instead of global "enter screen" fading
1862 fading = getTitleFading(tci);
1865 if (game_status_last_screen == GAME_MODE_INFO)
1867 if (num_title_screens == 0)
1869 // switch game mode from title screen mode back to info screen mode
1870 SetGameStatus(GAME_MODE_INFO);
1872 // store that last screen was info screen, not main menu screen
1873 game_status_last_screen = GAME_MODE_INFO;
1875 DrawInfoScreen_NotAvailable("Title screen information:",
1876 "No title screen for this level set.");
1881 FadeMenuSoundsAndMusic();
1883 FadeOut(REDRAW_ALL);
1885 // title screens may have different window size
1886 ChangeViewportPropertiesIfNeeded();
1888 // only required to update logic for redrawing global border
1892 DrawTitleScreenImage(tci->local_nr, tci->initial);
1894 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1896 sound = getTitleSound(tci);
1897 music = getTitleMusic(tci);
1899 if (sound != last_sound)
1900 PlayMenuSoundExt(sound);
1901 if (music != last_music)
1902 PlayMenuMusicExt(music);
1907 SetMouseCursor(CURSOR_NONE);
1911 ResetTitleAutoDelay(&title_delay, &fading);
1916 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1917 button = MB_MENU_CHOICE;
1919 if (button == MB_MENU_LEAVE)
1921 return_to_main_menu = TRUE;
1923 else if (button == MB_MENU_CHOICE)
1925 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1927 SetGameStatus(GAME_MODE_INFO);
1929 info_mode = INFO_MODE_MAIN;
1938 if (title_screen_nr < num_title_screens)
1940 tci = &title_controls[title_screen_nr];
1942 SetAnimStatus(getTitleAnimMode(tci));
1944 sound = getTitleSound(tci);
1945 music = getTitleMusic(tci);
1947 if (last_sound != SND_UNDEFINED && sound != last_sound)
1948 FadeSound(last_sound);
1949 if (last_music != MUS_UNDEFINED && music != last_music)
1952 fading = getTitleFading(tci);
1954 FadeOut(REDRAW_ALL);
1957 DrawTitleScreenImage(tci->local_nr, tci->initial);
1959 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1961 sound = getTitleSound(tci);
1962 music = getTitleMusic(tci);
1964 if (sound != last_sound)
1965 PlayMenuSoundExt(sound);
1966 if (music != last_music)
1967 PlayMenuMusicExt(music);
1974 ResetTitleAutoDelay(&title_delay, &fading);
1978 FadeMenuSoundsAndMusic();
1980 return_to_main_menu = TRUE;
1984 if (return_to_main_menu)
1986 SetMouseCursor(CURSOR_DEFAULT);
1988 // force full menu screen redraw after displaying title screens
1989 redraw_mask = REDRAW_ALL;
1991 if (game_status_last_screen == GAME_MODE_INFO)
1993 SetGameStatus(GAME_MODE_INFO);
1995 info_mode = INFO_MODE_MAIN;
1999 else // default: return to main menu
2001 SetGameStatus(GAME_MODE_MAIN);
2008 static void HandleMainMenu_ToggleTeamMode(void)
2010 setup.team_mode = !setup.team_mode;
2012 InitializeMainControls();
2013 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2015 DrawPreviewPlayers();
2018 static void HandleMainMenu_SelectLevel(int step, int direction,
2019 int selected_level_nr)
2021 int old_level_nr = level_nr;
2024 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2025 new_level_nr = selected_level_nr;
2027 new_level_nr = old_level_nr + step * direction;
2029 if (new_level_nr < leveldir_current->first_level)
2030 new_level_nr = leveldir_current->first_level;
2031 if (new_level_nr > leveldir_current->last_level)
2032 new_level_nr = leveldir_current->last_level;
2034 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2036 // skipping levels is only allowed when trying to skip single level
2037 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2038 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2040 leveldir_current->handicap_level++;
2041 SaveLevelSetup_SeriesInfo();
2044 new_level_nr = leveldir_current->handicap_level;
2047 if (new_level_nr != old_level_nr)
2049 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2051 PlaySound(SND_MENU_ITEM_SELECTING);
2053 level_nr = new_level_nr;
2055 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2056 int2str(level_nr, menu.main.text.level_number.size),
2057 mci->pos_text->font);
2059 LoadLevel(level_nr);
2060 DrawPreviewLevelInitial();
2064 DrawCompleteVideoDisplay();
2066 SaveLevelSetup_SeriesInfo();
2068 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2070 // force redraw of playfield area (may be reset at this point)
2071 redraw_mask |= REDRAW_FIELD;
2075 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2077 static int choice = MAIN_CONTROL_GAME;
2078 static boolean button_pressed_last = FALSE;
2079 boolean button_pressed = FALSE;
2081 int i = 0; // needed to prevent compiler warning due to bad code below
2083 if (button == MB_MENU_INITIALIZE)
2085 DrawCursorAndText_Main(choice, TRUE, FALSE);
2090 if (mx || my) // mouse input
2094 for (i = 0; main_controls[i].nr != -1; i++)
2096 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2097 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2098 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2100 pos = main_controls[i].nr;
2106 // check if level preview was clicked
2107 if (insidePreviewRect(&preview, mx - SX, my - SY))
2108 pos = MAIN_CONTROL_GAME;
2110 // handle pressed/unpressed state for active/inactive menu buttons
2111 // (if pos != -1, "i" contains index position corresponding to "pos")
2113 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2114 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2115 button_pressed = TRUE;
2117 if (button_pressed != button_pressed_last)
2119 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2122 PlaySound(SND_MENU_BUTTON_PRESSING);
2124 PlaySound(SND_MENU_BUTTON_RELEASING);
2127 else if (dx || dy) // keyboard input
2129 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2130 choice == MAIN_CONTROL_SETUP))
2131 button = MB_MENU_CHOICE;
2136 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2138 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2140 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2142 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2144 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2146 CloseDoor(DOOR_CLOSE_2);
2148 SetGameStatus(GAME_MODE_LEVELNR);
2150 DrawChooseLevelNr();
2152 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2158 PlaySound(SND_MENU_ITEM_ACTIVATING);
2160 DrawCursorAndText_Main(choice, FALSE, FALSE);
2161 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2167 if (choice == MAIN_CONTROL_NAME)
2169 // special case: cursor left or right pressed -- toggle team mode
2170 HandleMainMenu_ToggleTeamMode();
2172 else if (choice != MAIN_CONTROL_INFO &&
2173 choice != MAIN_CONTROL_SETUP)
2175 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2181 PlaySound(SND_MENU_ITEM_SELECTING);
2183 if (pos == MAIN_CONTROL_NAME)
2186 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2188 // special case: menu text "name/team" clicked -- toggle team mode
2189 HandleMainMenu_ToggleTeamMode();
2193 if (setup.multiple_users)
2195 CloseDoor(DOOR_CLOSE_2);
2197 SetGameStatus(GAME_MODE_NAMES);
2199 DrawChoosePlayerName();
2203 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2209 else if (pos == MAIN_CONTROL_LEVELS)
2213 CloseDoor(DOOR_CLOSE_2);
2215 SetGameStatus(GAME_MODE_LEVELS);
2217 SaveLevelSetup_LastSeries();
2218 SaveLevelSetup_SeriesInfo();
2220 // restore level set if chosen from "last played level set" menu
2221 RestoreLastPlayedLevels(&leveldir_current);
2223 if (setup.internal.choose_from_top_leveldir)
2226 DrawChooseLevelSet();
2229 else if (pos == MAIN_CONTROL_SCORES)
2231 CloseDoor(DOOR_CLOSE_2);
2233 SetGameStatus(GAME_MODE_SCORES);
2235 DrawHallOfFame(level_nr);
2237 else if (pos == MAIN_CONTROL_EDITOR)
2239 if (leveldir_current->readonly &&
2240 setup.editor.show_read_only_warning)
2241 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2243 CloseDoor(DOOR_CLOSE_ALL);
2245 SetGameStatus(GAME_MODE_EDITOR);
2247 FadeSetEnterScreen();
2251 else if (pos == MAIN_CONTROL_INFO)
2253 CloseDoor(DOOR_CLOSE_2);
2255 SetGameStatus(GAME_MODE_INFO);
2257 info_mode = INFO_MODE_MAIN;
2261 else if (pos == MAIN_CONTROL_GAME)
2263 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2265 else if (pos == MAIN_CONTROL_SETUP)
2267 CloseDoor(DOOR_CLOSE_2);
2269 SetGameStatus(GAME_MODE_SETUP);
2271 setup_mode = SETUP_MODE_MAIN;
2275 else if (pos == MAIN_CONTROL_QUIT)
2277 SaveLevelSetup_LastSeries();
2278 SaveLevelSetup_SeriesInfo();
2280 #if defined(PLATFORM_EMSCRIPTEN)
2281 Request("Close the browser window to quit!", REQ_CONFIRM);
2283 if (!setup.ask_on_quit_program ||
2284 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2285 SetGameStatus(GAME_MODE_QUIT);
2291 button_pressed_last = button_pressed;
2295 // ============================================================================
2296 // info screen functions
2297 // ============================================================================
2299 static struct TokenInfo *info_info;
2300 static int num_info_info; // number of info entries shown on screen
2301 static int max_info_info; // total number of info entries in list
2303 static void execInfoTitleScreen(void)
2305 info_mode = INFO_MODE_TITLE;
2310 static void execInfoElements(void)
2312 info_mode = INFO_MODE_ELEMENTS;
2317 static void execInfoMusic(void)
2319 info_mode = INFO_MODE_MUSIC;
2324 static void execInfoCredits(void)
2326 info_mode = INFO_MODE_CREDITS;
2331 static void execInfoProgram(void)
2333 info_mode = INFO_MODE_PROGRAM;
2338 static void execInfoVersion(void)
2340 info_mode = INFO_MODE_VERSION;
2345 static void execInfoLevelSet(void)
2347 info_mode = INFO_MODE_LEVELSET;
2352 static void execExitInfo(void)
2354 SetGameStatus(GAME_MODE_MAIN);
2359 static struct TokenInfo info_info_main[] =
2361 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2362 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2363 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2364 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2365 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2366 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2367 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2368 { TYPE_EMPTY, NULL, "" },
2369 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2374 static int getMenuTextFont(int type)
2376 if (type & (TYPE_SWITCH |
2390 static struct TokenInfo *setup_info;
2391 static struct TokenInfo setup_info_input[];
2393 static struct TokenInfo *menu_info;
2395 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2396 int screen_pos, int menu_info_pos_raw,
2399 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2400 struct TokenInfo *ti = &token_info[pos];
2401 int xpos = MENU_SCREEN_START_XPOS;
2402 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2403 int font_nr = getMenuTextFont(ti->type);
2405 if (setup_mode == SETUP_MODE_INPUT)
2406 font_nr = FONT_MENU_1;
2409 font_nr = FONT_ACTIVE(font_nr);
2411 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2413 if (ti->type & ~TYPE_SKIP_ENTRY)
2414 drawCursor(screen_pos, active);
2417 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2420 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2423 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2426 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2429 static char *window_size_text;
2430 static char *scaling_type_text;
2431 static char *network_server_text;
2433 static void drawSetupValue(int, int);
2435 static void drawMenuInfoList(int first_entry, int num_page_entries,
2436 int max_page_entries)
2440 if (first_entry + num_page_entries > max_page_entries)
2443 clearMenuListArea();
2445 for (i = 0; i < num_page_entries; i++)
2447 int menu_info_pos = first_entry + i;
2448 struct TokenInfo *si = &menu_info[menu_info_pos];
2449 void *value_ptr = si->value;
2451 // set some entries to "unchangeable" according to other variables
2452 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2453 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2454 (value_ptr == &setup.sound_music && !audio.music_available) ||
2455 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2456 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2457 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2458 si->type |= TYPE_GHOSTED;
2460 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2461 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2462 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2463 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2464 else if (si->type & ~TYPE_SKIP_ENTRY)
2465 initCursor(i, IMG_MENU_BUTTON);
2467 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2469 if (si->type & TYPE_STRING)
2473 if (value_ptr == &network_server_text)
2474 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2476 if (gadget_id != -1)
2478 struct GadgetInfo *gi = screen_gadget[gadget_id];
2479 int xpos = MENU_SCREEN_START_XPOS;
2480 int ypos = MENU_SCREEN_START_YPOS + i;
2481 int x = mSX + xpos * 32;
2482 int y = mSY + ypos * 32;
2484 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2488 if (si->type & TYPE_VALUE &&
2489 menu_info == setup_info)
2490 drawSetupValue(i, menu_info_pos);
2494 static void DrawInfoScreen_Main(void)
2496 int fade_mask = REDRAW_FIELD;
2499 if (redraw_mask & REDRAW_ALL)
2500 fade_mask = REDRAW_ALL;
2503 fade_mask = REDRAW_ALL;
2506 FadeMenuSoundsAndMusic();
2508 FreeScreenGadgets();
2509 CreateScreenGadgets();
2511 // (needed after displaying title screens which disable auto repeat)
2512 KeyboardAutoRepeatOn();
2514 FadeSetLeaveScreen();
2518 // needed if different viewport properties defined for info screen
2519 ChangeViewportPropertiesIfNeeded();
2521 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2525 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2527 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2529 info_info = info_info_main;
2531 // determine maximal number of info entries that can be displayed on screen
2533 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2536 // determine maximal number of info entries available for menu of info screen
2538 for (i = 0; info_info[i].type != 0; i++)
2541 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2543 MapScreenGadgets(max_info_info);
2545 PlayMenuSoundsAndMusic();
2547 DrawMaskedBorder(fade_mask);
2552 static void changeSetupValue(int, int, int);
2554 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2555 int mode, int num_page_entries,
2556 int max_page_entries)
2558 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2559 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2560 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2561 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2562 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2563 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2564 int *num_page_entries_last = num_page_entries_all_last[game_status];
2565 int *choice_store = choice_stores[game_status];
2566 int *first_entry_store = first_entry_stores[game_status];
2567 int choice = choice_store[mode]; // starts with 0
2568 int first_entry = first_entry_store[mode]; // starts with 0
2570 int y = choice - first_entry;
2572 boolean position_set_by_scrollbar = (dx == 999);
2573 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2576 if (button == MB_MENU_INITIALIZE)
2578 // check if number of menu page entries has changed (may happen by change
2579 // of custom artwork definition value for 'list_size' for this menu screen)
2580 // (in this case, the last menu position most probably has to be corrected)
2581 if (num_page_entries != num_page_entries_last[mode])
2583 choice_store[mode] = first_entry_store[mode] = 0;
2585 choice = first_entry = 0;
2588 num_page_entries_last[mode] = num_page_entries;
2591 // advance to first valid menu entry
2592 while (choice < num_page_entries &&
2593 menu_info[choice].type & TYPE_SKIP_ENTRY)
2596 if (position_set_by_scrollbar)
2597 first_entry = first_entry_store[mode] = dy;
2599 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2600 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2602 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2604 if (choice < first_entry)
2606 choice = first_entry;
2608 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2611 else if (choice > first_entry + num_page_entries - 1)
2613 choice = first_entry + num_page_entries - 1;
2615 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2619 choice_store[mode] = choice;
2621 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2625 else if (button == MB_MENU_LEAVE)
2627 PlaySound(SND_MENU_ITEM_SELECTING);
2629 for (i = 0; i < max_page_entries; i++)
2631 if (menu_info[i].type & TYPE_LEAVE_MENU)
2633 void (*menu_callback_function)(void) = menu_info[i].value;
2637 menu_callback_function();
2639 break; // absolutely needed because function changes 'menu_info'!
2646 if (mx || my) // mouse input
2648 x = (mx - mSX) / 32;
2649 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2651 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2653 // move cursor instead of scrolling when already at start/end of list
2654 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2656 else if (dy == +1 * SCROLL_LINE &&
2657 first_entry + num_page_entries == max_page_entries)
2660 // handle scrolling screen one line or page
2662 y + dy > num_page_entries - 1)
2664 boolean redraw = FALSE;
2666 if (ABS(dy) == SCROLL_PAGE)
2667 step = num_page_entries - 1;
2669 if (dy < 0 && first_entry > 0)
2671 // scroll page/line up
2673 first_entry -= step;
2674 if (first_entry < 0)
2679 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2681 // scroll page/line down
2683 first_entry += step;
2684 if (first_entry + num_page_entries > max_page_entries)
2685 first_entry = MAX(0, max_page_entries - num_page_entries);
2692 choice += first_entry - first_entry_store[mode];
2694 if (choice < first_entry)
2696 choice = first_entry;
2698 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2701 else if (choice > first_entry + num_page_entries - 1)
2703 choice = first_entry + num_page_entries - 1;
2705 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2708 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2712 if (choice < first_entry ||
2713 choice > first_entry + num_page_entries - 1)
2714 first_entry += SIGN(dy);
2717 first_entry_store[mode] = first_entry;
2718 choice_store[mode] = choice;
2720 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2722 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2724 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2725 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2733 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2735 if (menu_info[choice].type & menu_navigation_type ||
2736 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2737 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2738 menu_info[choice].type & TYPE_PLAYER)
2739 button = MB_MENU_CHOICE;
2744 // jump to next non-empty menu entry (up or down)
2745 while (first_entry + y > 0 &&
2746 first_entry + y < max_page_entries - 1 &&
2747 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2750 if (!IN_VIS_MENU(x, y))
2752 choice += y - y_old;
2754 if (choice < first_entry)
2755 first_entry = choice;
2756 else if (choice > first_entry + num_page_entries - 1)
2757 first_entry = choice - num_page_entries + 1;
2759 if (first_entry >= 0 &&
2760 first_entry + num_page_entries <= max_page_entries)
2762 first_entry_store[mode] = first_entry;
2764 if (choice < first_entry)
2765 choice = first_entry;
2766 else if (choice > first_entry + num_page_entries - 1)
2767 choice = first_entry + num_page_entries - 1;
2769 choice_store[mode] = choice;
2771 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2773 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2775 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2776 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2783 if (!anyScrollbarGadgetActive() &&
2784 IN_VIS_MENU(x, y) &&
2785 mx < mx_right_border &&
2786 y >= 0 && y < num_page_entries)
2790 if (first_entry + y != choice &&
2791 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2793 PlaySound(SND_MENU_ITEM_ACTIVATING);
2795 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2796 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2798 choice = choice_store[mode] = first_entry + y;
2802 PlaySound(SND_MENU_ITEM_SELECTING);
2804 for (i = 0; menu_info[i].type != 0; i++)
2806 if (menu_info[i].type & TYPE_LEAVE_MENU)
2808 void (*menu_callback_function)(void) = menu_info[i].value;
2812 menu_callback_function();
2814 // absolutely needed because function changes 'menu_info'!
2822 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2824 PlaySound(SND_MENU_ITEM_SELECTING);
2826 // when selecting key headline, execute function for key value change
2827 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2828 menu_info[first_entry + y + 1].type & TYPE_KEY)
2831 // when selecting string value, execute function for list selection
2832 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2833 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2836 // when selecting string value, execute function for text input gadget
2837 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2838 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2841 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2843 void (*menu_callback_function)(void) =
2844 menu_info[first_entry + y].value;
2846 FadeSetFromType(menu_info[first_entry + y].type);
2848 menu_callback_function();
2850 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2852 void (*gadget_callback_function)(void) =
2853 menu_info[first_entry + y].value;
2855 gadget_callback_function();
2857 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2858 menu_info == setup_info)
2860 changeSetupValue(y, first_entry + y, dx);
2866 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2868 menu_info = info_info;
2870 HandleMenuScreen(mx, my, dx, dy, button,
2871 info_mode, num_info_info, max_info_info);
2874 static int getMenuFontSpacing(int spacing_height, int font_nr)
2876 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2878 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2882 static int getMenuTextSpacing(int spacing_height, int font_nr)
2884 return (getMenuFontSpacing(spacing_height, font_nr) +
2885 EXTRA_SPACING(game_status));
2888 static int getMenuTextStep(int spacing_height, int font_nr)
2890 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2893 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2895 int font_title = MENU_INFO_FONT_TITLE;
2896 int font_error = FONT_TEXT_2;
2897 int font_foot = MENU_INFO_FONT_FOOT;
2898 int spacing_title = menu.headline1_spacing_info[info_mode];
2899 int ystep_title = getMenuTextStep(spacing_title, font_title);
2900 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2901 int ystart2 = ystart1 + ystep_title;
2902 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2904 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2906 FadeOut(REDRAW_FIELD);
2911 DrawTextSCentered(ystart1, font_title, text_title);
2912 DrawTextSCentered(ystart2, font_error, text_error);
2914 DrawTextSCentered(ybottom, font_foot,
2915 "Press any key or button for info menu");
2917 FadeIn(REDRAW_FIELD);
2920 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2922 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2923 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2924 int font_title = MENU_INFO_FONT_TITLE;
2925 int font_foot = MENU_INFO_FONT_FOOT;
2926 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2927 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2928 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2929 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2930 int ystep = MENU_SCREEN_INFO_YSTEP;
2931 int element, action, direction;
2939 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2940 infoscreen_step[i] = infoscreen_frame[i] = 0;
2945 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2947 DrawTextSCentered(ybottom, font_foot,
2948 "Press any key or button for next page");
2954 while (helpanim_info[j].element != HELPANIM_LIST_END)
2956 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2961 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2970 j += infoscreen_step[i - start];
2972 element = helpanim_info[j].element;
2973 action = helpanim_info[j].action;
2974 direction = helpanim_info[j].direction;
2977 element = EL_UNKNOWN;
2979 if (action != -1 && direction != -1)
2980 graphic = el_act_dir2img(element, action, direction);
2981 else if (action != -1)
2982 graphic = el_act2img(element, action);
2983 else if (direction != -1)
2984 graphic = el_dir2img(element, direction);
2986 graphic = el2img(element);
2988 delay = helpanim_info[j++].delay;
2993 if (infoscreen_frame[i - start] == 0)
2996 infoscreen_frame[i - start] = delay - 1;
3000 sync_frame = delay - infoscreen_frame[i - start];
3001 infoscreen_frame[i - start]--;
3004 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3006 if (!infoscreen_frame[i - start])
3007 infoscreen_step[i - start] = 0;
3011 if (!infoscreen_frame[i - start])
3012 infoscreen_step[i - start]++;
3013 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3019 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3021 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3022 graphic, sync_frame, USE_MASKING);
3025 DrawInfoScreen_HelpText(element, action, direction, i - start);
3030 redraw_mask |= REDRAW_FIELD;
3035 static char *getHelpText(int element, int action, int direction)
3037 char token[MAX_LINE_LEN];
3039 strcpy(token, element_info[element].token_name);
3042 strcat(token, element_action_info[action].suffix);
3044 if (direction != -1)
3045 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3047 return getHashEntry(helptext_info, token);
3050 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3052 int font_nr = FONT_INFO_ELEMENTS;
3053 int font_width = getFontWidth(font_nr);
3054 int font_height = getFontHeight(font_nr);
3055 int yoffset = (TILEX - 2 * font_height) / 2;
3056 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3057 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3058 int ystep = TILEY + 4;
3059 int pad_left = xstart - SX;
3060 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3061 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3062 int max_lines_per_text = 2;
3065 if (action != -1 && direction != -1) // element.action.direction
3066 text = getHelpText(element, action, direction);
3068 if (text == NULL && action != -1) // element.action
3069 text = getHelpText(element, action, -1);
3071 if (text == NULL && direction != -1) // element.direction
3072 text = getHelpText(element, -1, direction);
3074 if (text == NULL) // base element
3075 text = getHelpText(element, -1, -1);
3077 if (text == NULL) // not found
3078 text = "No description available";
3080 if (strlen(text) <= max_chars_per_line) // only one line of text
3081 ystart += getFontHeight(font_nr) / 2;
3083 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3084 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3085 TRUE, FALSE, FALSE);
3088 static void DrawInfoScreen_TitleScreen(void)
3090 SetGameStatus(GAME_MODE_TITLE);
3095 void HandleInfoScreen_TitleScreen(int button)
3097 HandleTitleScreen(0, 0, 0, 0, button);
3100 static void DrawInfoScreen_Elements(void)
3102 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3104 FadeOut(REDRAW_FIELD);
3109 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3111 FadeIn(REDRAW_FIELD);
3114 void HandleInfoScreen_Elements(int button)
3116 static unsigned int info_delay = 0;
3117 static int num_anims;
3118 static int num_pages;
3120 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3123 if (button == MB_MENU_INITIALIZE)
3125 boolean new_element = TRUE;
3129 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3131 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3133 else if (new_element)
3136 new_element = FALSE;
3140 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3144 if (button == MB_MENU_LEAVE)
3146 PlaySound(SND_MENU_ITEM_SELECTING);
3148 info_mode = INFO_MODE_MAIN;
3153 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3155 if (button != MB_MENU_INITIALIZE)
3157 PlaySound(SND_MENU_ITEM_SELECTING);
3162 if (page >= num_pages)
3164 FadeMenuSoundsAndMusic();
3166 info_mode = INFO_MODE_MAIN;
3173 FadeSetNextScreen();
3175 if (button != MB_MENU_INITIALIZE)
3176 FadeOut(REDRAW_FIELD);
3178 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3180 if (button != MB_MENU_INITIALIZE)
3181 FadeIn(REDRAW_FIELD);
3185 if (DelayReached(&info_delay, GameFrameDelay))
3186 if (page < num_pages)
3187 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3189 PlayMenuSoundIfLoop();
3193 static void DrawInfoScreen_Music(void)
3195 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3197 FadeOut(REDRAW_FIELD);
3204 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3206 FadeIn(REDRAW_FIELD);
3209 void HandleInfoScreen_Music(int button)
3211 static struct MusicFileInfo *list = NULL;
3212 int font_title = MENU_INFO_FONT_TITLE;
3213 int font_head = MENU_INFO_FONT_HEAD;
3214 int font_text = MENU_INFO_FONT_TEXT;
3215 int font_foot = MENU_INFO_FONT_FOOT;
3216 int spacing_title = menu.headline1_spacing_info[info_mode];
3217 int spacing_head = menu.headline2_spacing_info[info_mode];
3218 int ystep_title = getMenuTextStep(spacing_title, font_title);
3219 int ystep_head = getMenuTextStep(spacing_head, font_head);
3220 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3221 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3223 if (button == MB_MENU_INITIALIZE)
3225 list = music_file_info;
3229 FadeMenuSoundsAndMusic();
3234 DrawTextSCentered(ystart, font_title,
3235 "No music info for this level set.");
3237 DrawTextSCentered(ybottom, font_foot,
3238 "Press any key or button for info menu");
3244 if (button == MB_MENU_LEAVE)
3246 PlaySound(SND_MENU_ITEM_SELECTING);
3248 FadeMenuSoundsAndMusic();
3250 info_mode = INFO_MODE_MAIN;
3255 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3257 if (button != MB_MENU_INITIALIZE)
3259 PlaySound(SND_MENU_ITEM_SELECTING);
3267 FadeMenuSoundsAndMusic();
3269 info_mode = INFO_MODE_MAIN;
3275 FadeMenuSoundsAndMusic();
3277 if (list != music_file_info)
3278 FadeSetNextScreen();
3280 if (button != MB_MENU_INITIALIZE)
3281 FadeOut(REDRAW_FIELD);
3288 int sound = list->music;
3290 if (IS_LOOP_SOUND(sound))
3291 PlaySoundLoop(sound);
3295 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3299 int music = list->music;
3301 if (IS_LOOP_MUSIC(music))
3302 PlayMusicLoop(music);
3306 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3309 ystart += ystep_title;
3311 if (!strEqual(list->title, UNKNOWN_NAME))
3313 if (!strEqual(list->title_header, UNKNOWN_NAME))
3315 DrawTextSCentered(ystart, font_head, list->title_header);
3316 ystart += ystep_head;
3319 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3320 ystart += ystep_head;
3323 if (!strEqual(list->artist, UNKNOWN_NAME))
3325 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3326 DrawTextSCentered(ystart, font_head, list->artist_header);
3328 DrawTextSCentered(ystart, font_head, "by");
3330 ystart += ystep_head;
3332 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3333 ystart += ystep_head;
3336 if (!strEqual(list->album, UNKNOWN_NAME))
3338 if (!strEqual(list->album_header, UNKNOWN_NAME))
3339 DrawTextSCentered(ystart, font_head, list->album_header);
3341 DrawTextSCentered(ystart, font_head, "from the album");
3343 ystart += ystep_head;
3345 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3346 ystart += ystep_head;
3349 if (!strEqual(list->year, UNKNOWN_NAME))
3351 if (!strEqual(list->year_header, UNKNOWN_NAME))
3352 DrawTextSCentered(ystart, font_head, list->year_header);
3354 DrawTextSCentered(ystart, font_head, "from the year");
3356 ystart += ystep_head;
3358 DrawTextFCentered(ystart, font_text, "%s", list->year);
3359 ystart += ystep_head;
3362 DrawTextSCentered(ybottom, FONT_TEXT_4,
3363 "Press any key or button for next page");
3365 if (button != MB_MENU_INITIALIZE)
3366 FadeIn(REDRAW_FIELD);
3369 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3370 PlaySoundLoop(list->music);
3373 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3375 int font_title = MENU_INFO_FONT_TITLE;
3376 int font_head = MENU_INFO_FONT_HEAD;
3377 int font_text = MENU_INFO_FONT_TEXT;
3378 int font_foot = MENU_INFO_FONT_FOOT;
3379 int spacing_title = menu.headline1_spacing_info[info_mode];
3380 int spacing_head = menu.headline2_spacing_info[info_mode];
3381 int spacing_para = menu.paragraph_spacing_info[info_mode];
3382 int spacing_line = menu.line_spacing_info[info_mode];
3383 int ystep_title = getMenuTextStep(spacing_title, font_title);
3384 int ystep_head = getMenuTextStep(spacing_head, font_head);
3385 int ystep_para = getMenuTextStep(spacing_para, font_text);
3386 int ystep_line = getMenuTextStep(spacing_line, font_text);
3387 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3388 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3393 DrawTextSCentered(ystart, font_title, "Credits:");
3394 ystart += ystep_title;
3398 DrawTextSCentered(ystart, font_head,
3399 "Special thanks to");
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_text,
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_head,
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_text,
3408 "\"Boulder Dash\"");
3409 ystart += ystep_head;
3410 DrawTextSCentered(ystart, font_head,
3412 ystart += ystep_head;
3413 DrawTextSCentered(ystart, font_text,
3415 ystart += ystep_head;
3416 DrawTextSCentered(ystart, font_head,
3418 ystart += ystep_head;
3419 DrawTextSCentered(ystart, font_text,
3420 "First Star Software");
3422 else if (screen_nr == 1)
3424 DrawTextSCentered(ystart, font_head,
3425 "Special thanks to");
3426 ystart += ystep_head;
3427 DrawTextSCentered(ystart, font_text,
3428 "Klaus Heinz & Volker Wertich");
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_head,
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_text,
3434 "\"Emerald Mine\"");
3435 ystart += ystep_head;
3436 DrawTextSCentered(ystart, font_head,
3438 ystart += ystep_head;
3439 DrawTextSCentered(ystart, font_text,
3441 ystart += ystep_head;
3442 DrawTextSCentered(ystart, font_head,
3444 ystart += ystep_head;
3445 DrawTextSCentered(ystart, font_text,
3448 else if (screen_nr == 2)
3450 DrawTextSCentered(ystart, font_head,
3451 "Special thanks to");
3452 ystart += ystep_head;
3453 DrawTextSCentered(ystart, font_text,
3454 "Michael Stopp & Philip Jespersen");
3455 ystart += ystep_head;
3456 DrawTextSCentered(ystart, font_head,
3458 ystart += ystep_head;
3459 DrawTextSCentered(ystart, font_text,
3461 ystart += ystep_head;
3462 DrawTextSCentered(ystart, font_head,
3464 ystart += ystep_head;
3465 DrawTextSCentered(ystart, font_text,
3467 ystart += ystep_head;
3468 DrawTextSCentered(ystart, font_head,
3470 ystart += ystep_head;
3471 DrawTextSCentered(ystart, font_text,
3472 "Digital Integration");
3474 else if (screen_nr == 3)
3476 DrawTextSCentered(ystart, font_head,
3477 "Special thanks to");
3478 ystart += ystep_head;
3479 DrawTextSCentered(ystart, font_text,
3480 "Hiroyuki Imabayashi");
3481 ystart += ystep_head;
3482 DrawTextSCentered(ystart, font_head,
3484 ystart += ystep_head;
3485 DrawTextSCentered(ystart, font_text,
3487 ystart += ystep_head;
3488 DrawTextSCentered(ystart, font_head,
3490 ystart += ystep_head;
3491 DrawTextSCentered(ystart, font_text,
3493 ystart += ystep_head;
3494 DrawTextSCentered(ystart, font_head,
3496 ystart += ystep_head;
3497 DrawTextSCentered(ystart, font_text,
3500 else if (screen_nr == 4)
3502 DrawTextSCentered(ystart, font_head,
3503 "Special thanks to");
3504 ystart += ystep_head;
3505 DrawTextSCentered(ystart, font_text,
3507 ystart += ystep_head;
3508 DrawTextSCentered(ystart, font_head,
3510 ystart += ystep_head;
3511 DrawTextSCentered(ystart, font_text,
3512 "J\xfcrgen Bonhagen");
3513 ystart += ystep_head;
3514 DrawTextSCentered(ystart, font_head,
3515 "for the continuous creation");
3516 ystart += ystep_line;
3517 DrawTextSCentered(ystart, font_head,
3518 "of outstanding level sets");
3520 else if (screen_nr == 5)
3522 DrawTextSCentered(ystart, font_head,
3524 ystart += ystep_head;
3525 DrawTextSCentered(ystart, font_text,
3527 ystart += ystep_head;
3528 DrawTextSCentered(ystart, font_head,
3529 "for ideas and inspiration by");
3530 ystart += ystep_head;
3531 DrawTextSCentered(ystart, font_text,
3533 ystart += ystep_para;
3535 DrawTextSCentered(ystart, font_head,
3537 ystart += ystep_head;
3538 DrawTextSCentered(ystart, font_text,
3540 ystart += ystep_head;
3541 DrawTextSCentered(ystart, font_head,
3542 "for ideas and inspiration by");
3543 ystart += ystep_head;
3544 DrawTextSCentered(ystart, font_text,
3547 else if (screen_nr == 6)
3549 DrawTextSCentered(ystart, font_head,
3551 ystart += ystep_head;
3552 DrawTextSCentered(ystart, font_text,
3554 ystart += ystep_head;
3555 DrawTextSCentered(ystart, font_head,
3556 "for the code base used for the");
3557 ystart += ystep_line;
3558 DrawTextSCentered(ystart, font_head,
3559 "native Emerald Mine engine");
3561 else if (screen_nr == 7)
3563 DrawTextSCentered(ystart, font_head,
3565 ystart += ystep_head;
3566 DrawTextSCentered(ystart, font_text,
3568 ystart += ystep_head;
3569 DrawTextSCentered(ystart, font_head,
3570 "for the initial DOS port");
3571 ystart += ystep_para;
3573 DrawTextSCentered(ystart, font_head,
3575 ystart += ystep_head;
3576 DrawTextSCentered(ystart, font_text,
3578 ystart += ystep_head;
3579 DrawTextSCentered(ystart, font_head,
3580 "for some additional toons");
3582 else if (screen_nr == 8)
3584 DrawTextSCentered(ystart, font_head,
3585 "And not to forget:");
3586 ystart += ystep_head;
3587 DrawTextSCentered(ystart, font_head,
3589 ystart += ystep_head;
3590 DrawTextSCentered(ystart, font_text,
3591 "All those who contributed");
3592 ystart += ystep_line;
3593 DrawTextSCentered(ystart, font_text,
3594 "levels to this game");
3595 ystart += ystep_line;
3596 DrawTextSCentered(ystart, font_text,
3600 DrawTextSCentered(ybottom, font_foot,
3601 "Press any key or button for next page");
3604 static void DrawInfoScreen_Credits(void)
3606 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3608 FadeMenuSoundsAndMusic();
3610 FadeOut(REDRAW_FIELD);
3612 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3614 FadeIn(REDRAW_FIELD);
3617 void HandleInfoScreen_Credits(int button)
3619 static int screen_nr = 0;
3620 int num_screens = 9;
3622 if (button == MB_MENU_INITIALIZE)
3626 // DrawInfoScreen_CreditsScreen(screen_nr);
3629 if (button == MB_MENU_LEAVE)
3631 PlaySound(SND_MENU_ITEM_SELECTING);
3633 info_mode = INFO_MODE_MAIN;
3638 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3640 if (button != MB_MENU_INITIALIZE)
3642 PlaySound(SND_MENU_ITEM_SELECTING);
3647 if (screen_nr >= num_screens)
3649 FadeMenuSoundsAndMusic();
3651 info_mode = INFO_MODE_MAIN;
3658 FadeSetNextScreen();
3660 if (button != MB_MENU_INITIALIZE)
3661 FadeOut(REDRAW_FIELD);
3663 DrawInfoScreen_CreditsScreen(screen_nr);
3665 if (button != MB_MENU_INITIALIZE)
3666 FadeIn(REDRAW_FIELD);
3670 PlayMenuSoundIfLoop();
3674 static void DrawInfoScreen_Program(void)
3676 int font_title = MENU_INFO_FONT_TITLE;
3677 int font_head = MENU_INFO_FONT_HEAD;
3678 int font_text = MENU_INFO_FONT_TEXT;
3679 int font_foot = MENU_INFO_FONT_FOOT;
3680 int spacing_title = menu.headline1_spacing_info[info_mode];
3681 int spacing_head = menu.headline2_spacing_info[info_mode];
3682 int spacing_para = menu.paragraph_spacing_info[info_mode];
3683 int spacing_line = menu.line_spacing_info[info_mode];
3684 int ystep_title = getMenuTextStep(spacing_title, font_title);
3685 int ystep_head = getMenuTextStep(spacing_head, font_head);
3686 int ystep_para = getMenuTextStep(spacing_para, font_text);
3687 int ystep_line = getMenuTextStep(spacing_line, font_text);
3688 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3689 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3691 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3693 FadeOut(REDRAW_FIELD);
3698 DrawTextSCentered(ystart, font_title, "Program Information:");
3699 ystart += ystep_title;
3701 DrawTextSCentered(ystart, font_head,
3702 "This game is Freeware!");
3703 ystart += ystep_head;
3704 DrawTextSCentered(ystart, font_head,
3705 "If you like it, send e-mail to:");
3706 ystart += ystep_head;
3707 DrawTextSCentered(ystart, font_text,
3708 setup.internal.program_email);
3709 ystart += ystep_para;
3711 DrawTextSCentered(ystart, font_head,
3712 "More information and levels:");
3713 ystart += ystep_head;
3714 DrawTextSCentered(ystart, font_text,
3715 setup.internal.program_website);
3716 ystart += ystep_para;
3718 DrawTextSCentered(ystart, font_head,
3719 "If you have created new levels,");
3720 ystart += ystep_line;
3721 DrawTextSCentered(ystart, font_head,
3722 "send them to me to include them!");
3723 ystart += ystep_head;
3724 DrawTextSCentered(ystart, font_head,
3727 DrawTextSCentered(ybottom, font_foot,
3728 "Press any key or button for info menu");
3730 FadeIn(REDRAW_FIELD);
3733 void HandleInfoScreen_Program(int button)
3735 if (button == MB_MENU_LEAVE)
3737 PlaySound(SND_MENU_ITEM_SELECTING);
3739 info_mode = INFO_MODE_MAIN;
3744 else if (button == MB_MENU_CHOICE)
3746 PlaySound(SND_MENU_ITEM_SELECTING);
3748 FadeMenuSoundsAndMusic();
3750 info_mode = INFO_MODE_MAIN;
3755 PlayMenuSoundIfLoop();
3759 static void DrawInfoScreen_Version(void)
3761 int font_title = MENU_INFO_FONT_TITLE;
3762 int font_head = MENU_INFO_FONT_HEAD;
3763 int font_text = MENU_INFO_FONT_TEXT;
3764 int font_foot = MENU_INFO_FONT_FOOT;
3765 int spacing_title = menu.headline1_spacing_info[info_mode];
3766 int spacing_head = menu.headline2_spacing_info[info_mode];
3767 int spacing_para = menu.paragraph_spacing_info[info_mode];
3768 int spacing_line = menu.line_spacing_info[info_mode];
3769 int xstep = getFontWidth(font_text);
3770 int ystep_title = getMenuTextStep(spacing_title, font_title);
3771 int ystep_head = getMenuTextStep(spacing_head, font_head);
3772 int ystep_para = getMenuTextStep(spacing_para, font_text);
3773 int ystep_line = getMenuTextStep(spacing_line, font_text);
3774 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3775 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3776 int xstart1 = mSX - SX + 2 * xstep;
3777 int xstart2 = mSX - SX + 18 * xstep;
3778 int xstart3 = mSX - SX + 28 * xstep;
3779 SDL_version sdl_version_compiled;
3780 const SDL_version *sdl_version_linked;
3781 int driver_name_len = 10;
3782 SDL_version sdl_version_linked_ext;
3783 const char *driver_name = NULL;
3785 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3787 FadeOut(REDRAW_FIELD);
3792 DrawTextSCentered(ystart, font_title, "Version Information:");
3793 ystart += ystep_title;
3795 DrawTextF(xstart1, ystart, font_head, "Name");
3796 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3797 ystart += ystep_line;
3799 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3801 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3802 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3803 ystart += ystep_line;
3805 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3806 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3807 ystart += ystep_line;
3811 DrawTextF(xstart1, ystart, font_head, "Version");
3812 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3813 ystart += ystep_line;
3816 DrawTextF(xstart1, ystart, font_head, "Platform");
3817 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3819 PLATFORM_XX_BIT_STRING);
3820 ystart += ystep_line;
3822 DrawTextF(xstart1, ystart, font_head, "Target");
3823 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3824 ystart += ystep_line;
3826 DrawTextF(xstart1, ystart, font_head, "Source date");
3827 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3828 ystart += ystep_line;
3830 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3831 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3832 ystart += ystep_para;
3834 DrawTextF(xstart1, ystart, font_head, "Library");
3835 DrawTextF(xstart2, ystart, font_head, "compiled");
3836 DrawTextF(xstart3, ystart, font_head, "linked");
3837 ystart += ystep_head;
3839 SDL_VERSION(&sdl_version_compiled);
3840 SDL_GetVersion(&sdl_version_linked_ext);
3841 sdl_version_linked = &sdl_version_linked_ext;
3843 DrawTextF(xstart1, ystart, font_text, "SDL");
3844 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3845 sdl_version_compiled.major,
3846 sdl_version_compiled.minor,
3847 sdl_version_compiled.patch);
3848 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3849 sdl_version_linked->major,
3850 sdl_version_linked->minor,
3851 sdl_version_linked->patch);
3852 ystart += ystep_line;
3854 SDL_IMAGE_VERSION(&sdl_version_compiled);
3855 sdl_version_linked = IMG_Linked_Version();
3857 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3858 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3859 sdl_version_compiled.major,
3860 sdl_version_compiled.minor,
3861 sdl_version_compiled.patch);
3862 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3863 sdl_version_linked->major,
3864 sdl_version_linked->minor,
3865 sdl_version_linked->patch);
3866 ystart += ystep_line;
3868 SDL_MIXER_VERSION(&sdl_version_compiled);
3869 sdl_version_linked = Mix_Linked_Version();
3871 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3872 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3873 sdl_version_compiled.major,
3874 sdl_version_compiled.minor,
3875 sdl_version_compiled.patch);
3876 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3877 sdl_version_linked->major,
3878 sdl_version_linked->minor,
3879 sdl_version_linked->patch);
3880 ystart += ystep_line;
3882 SDL_NET_VERSION(&sdl_version_compiled);
3883 sdl_version_linked = SDLNet_Linked_Version();
3885 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3886 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3887 sdl_version_compiled.major,
3888 sdl_version_compiled.minor,
3889 sdl_version_compiled.patch);
3890 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3891 sdl_version_linked->major,
3892 sdl_version_linked->minor,
3893 sdl_version_linked->patch);
3894 ystart += ystep_para;
3896 DrawTextF(xstart1, ystart, font_head, "Driver");
3897 DrawTextF(xstart2, ystart, font_head, "Requested");
3898 DrawTextF(xstart3, ystart, font_head, "Used");
3899 ystart += ystep_head;
3902 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3904 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3905 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3906 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3907 ystart += ystep_line;
3910 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3912 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3913 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3914 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3915 ystart += ystep_line;
3918 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3920 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3921 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3922 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3924 DrawTextSCentered(ybottom, font_foot,
3925 "Press any key or button for info menu");
3927 FadeIn(REDRAW_FIELD);
3930 void HandleInfoScreen_Version(int button)
3932 if (button == MB_MENU_LEAVE)
3934 PlaySound(SND_MENU_ITEM_SELECTING);
3936 info_mode = INFO_MODE_MAIN;
3941 else if (button == MB_MENU_CHOICE)
3943 PlaySound(SND_MENU_ITEM_SELECTING);
3945 FadeMenuSoundsAndMusic();
3947 info_mode = INFO_MODE_MAIN;
3952 PlayMenuSoundIfLoop();
3956 static void DrawInfoScreen_LevelSet(void)
3958 struct TitleMessageInfo *tmi = &readme;
3959 char *filename = getLevelSetInfoFilename();
3960 char *title = "Level Set Information:";
3961 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3962 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3964 if (filename == NULL)
3966 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3971 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3973 FadeOut(REDRAW_FIELD);
3978 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3980 // if x position set to "-1", automatically determine by playfield width
3982 tmi->x = SXSIZE / 2;
3984 // if y position set to "-1", use static default value
3988 // if width set to "-1", automatically determine by playfield width
3989 if (tmi->width == -1)
3990 tmi->width = SXSIZE - 2 * TILEX;
3992 // if height set to "-1", automatically determine by playfield height
3993 if (tmi->height == -1)
3994 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3996 // if chars set to "-1", automatically determine by text and font width
3997 if (tmi->chars == -1)
3998 tmi->chars = tmi->width / getFontWidth(tmi->font);
4000 tmi->width = tmi->chars * getFontWidth(tmi->font);
4002 // if lines set to "-1", automatically determine by text and font height
4003 if (tmi->lines == -1)
4004 tmi->lines = tmi->height / getFontHeight(tmi->font);
4006 tmi->height = tmi->lines * getFontHeight(tmi->font);
4008 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
4009 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
4010 tmi->autowrap, tmi->centered, tmi->parse_comments);
4012 DrawTextSCentered(ybottom, FONT_TEXT_4,
4013 "Press any key or button for info menu");
4015 FadeIn(REDRAW_FIELD);
4018 static void HandleInfoScreen_LevelSet(int button)
4020 if (button == MB_MENU_LEAVE)
4022 PlaySound(SND_MENU_ITEM_SELECTING);
4024 info_mode = INFO_MODE_MAIN;
4029 else if (button == MB_MENU_CHOICE)
4031 PlaySound(SND_MENU_ITEM_SELECTING);
4033 FadeMenuSoundsAndMusic();
4035 info_mode = INFO_MODE_MAIN;
4040 PlayMenuSoundIfLoop();
4044 static void DrawInfoScreen(void)
4046 if (info_mode == INFO_MODE_TITLE)
4047 DrawInfoScreen_TitleScreen();
4048 else if (info_mode == INFO_MODE_ELEMENTS)
4049 DrawInfoScreen_Elements();
4050 else if (info_mode == INFO_MODE_MUSIC)
4051 DrawInfoScreen_Music();
4052 else if (info_mode == INFO_MODE_CREDITS)
4053 DrawInfoScreen_Credits();
4054 else if (info_mode == INFO_MODE_PROGRAM)
4055 DrawInfoScreen_Program();
4056 else if (info_mode == INFO_MODE_VERSION)
4057 DrawInfoScreen_Version();
4058 else if (info_mode == INFO_MODE_LEVELSET)
4059 DrawInfoScreen_LevelSet();
4061 DrawInfoScreen_Main();
4063 if (info_mode != INFO_MODE_MAIN &&
4064 info_mode != INFO_MODE_TITLE &&
4065 info_mode != INFO_MODE_MUSIC)
4066 PlayMenuSoundsAndMusic();
4069 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4071 if (info_mode == INFO_MODE_TITLE)
4072 HandleInfoScreen_TitleScreen(button);
4073 else if (info_mode == INFO_MODE_ELEMENTS)
4074 HandleInfoScreen_Elements(button);
4075 else if (info_mode == INFO_MODE_MUSIC)
4076 HandleInfoScreen_Music(button);
4077 else if (info_mode == INFO_MODE_CREDITS)
4078 HandleInfoScreen_Credits(button);
4079 else if (info_mode == INFO_MODE_PROGRAM)
4080 HandleInfoScreen_Program(button);
4081 else if (info_mode == INFO_MODE_VERSION)
4082 HandleInfoScreen_Version(button);
4083 else if (info_mode == INFO_MODE_LEVELSET)
4084 HandleInfoScreen_LevelSet(button);
4086 HandleInfoScreen_Main(mx, my, dx, dy, button);
4090 // ============================================================================
4091 // rename player API functions
4092 // ============================================================================
4094 struct ApiRenamePlayerThreadData
4100 static void *CreateThreadData_ApiRenamePlayer(void)
4102 struct ApiRenamePlayerThreadData *data =
4103 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4105 data->player_name = getStringCopy(setup.player_name);
4106 data->player_uuid = getStringCopy(setup.player_uuid);
4111 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4113 struct ApiRenamePlayerThreadData *data = data_raw;
4115 checked_free(data->player_name);
4116 checked_free(data->player_uuid);
4120 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4123 struct ApiRenamePlayerThreadData *data = data_raw;
4124 char *player_name_raw = data->player_name;
4125 char *player_uuid_raw = data->player_uuid;
4127 request->hostname = setup.api_server_hostname;
4128 request->port = API_SERVER_PORT;
4129 request->method = API_SERVER_METHOD;
4130 request->uri = API_SERVER_URI_RENAME;
4132 char *player_name = getEscapedJSON(player_name_raw);
4133 char *player_uuid = getEscapedJSON(player_uuid_raw);
4135 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4138 " \"game_version\": \"%s\",\n"
4139 " \"game_platform\": \"%s\",\n"
4140 " \"name\": \"%s\",\n"
4141 " \"uuid\": \"%s\"\n"
4143 getPasswordJSON(setup.api_server_password),
4144 getProgramRealVersionString(),
4145 getProgramPlatformString(),
4149 checked_free(player_name);
4150 checked_free(player_uuid);
4152 ConvertHttpRequestBodyToServerEncoding(request);
4157 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4160 // nothing to do here
4163 #if defined(PLATFORM_EMSCRIPTEN)
4164 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4165 void *buffer, unsigned int size)
4167 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4169 if (response != NULL)
4171 HandleResponse_ApiRenamePlayer(response, data_raw);
4173 checked_free(response);
4177 Error("server response too large to handle (%d bytes)", size);
4180 FreeThreadData_ApiRenamePlayer(data_raw);
4183 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4184 int code, const char *status)
4186 Error("server failed to handle request: %d %s", code, status);
4188 FreeThreadData_ApiRenamePlayer(data_raw);
4191 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4192 int bytes, int size)
4194 // nothing to do here
4197 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4200 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4202 FreeThreadData_ApiRenamePlayer(data_raw);
4207 emscripten_async_wget2_data(request->uri,
4212 Emscripten_ApiRenamePlayer_Loaded,
4213 Emscripten_ApiRenamePlayer_Failed,
4214 Emscripten_ApiRenamePlayer_Progress);
4219 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4220 struct HttpResponse *response,
4223 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4226 if (!DoHttpRequest(request, response))
4228 Error("HTTP request failed: %s", GetHttpError());
4233 if (!HTTP_SUCCESS(response->status_code))
4235 Error("server failed to handle request: %d %s",
4236 response->status_code,
4237 response->status_text);
4242 HandleResponse_ApiRenamePlayer(response, data_raw);
4245 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4246 struct HttpResponse *response,
4249 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4251 FreeThreadData_ApiRenamePlayer(data_raw);
4255 static int ApiRenamePlayerThread(void *data_raw)
4257 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4258 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4260 program.api_thread_count++;
4262 #if defined(PLATFORM_EMSCRIPTEN)
4263 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4265 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4268 program.api_thread_count--;
4270 checked_free(request);
4271 checked_free(response);
4276 static void ApiRenamePlayerAsThread(void)
4278 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4280 ExecuteAsThread(ApiRenamePlayerThread,
4281 "ApiRenamePlayer", data,
4282 "rename player on server");
4286 // ============================================================================
4287 // reset player UUID API functions
4288 // ============================================================================
4290 struct ApiResetUUIDThreadData
4293 char *player_uuid_old;
4294 char *player_uuid_new;
4297 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4299 struct ApiResetUUIDThreadData *data =
4300 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4302 data->player_name = getStringCopy(setup.player_name);
4303 data->player_uuid_old = getStringCopy(setup.player_uuid);
4304 data->player_uuid_new = getStringCopy(uuid_new);
4309 static void FreeThreadData_ApiResetUUID(void *data_raw)
4311 struct ApiResetUUIDThreadData *data = data_raw;
4313 checked_free(data->player_name);
4314 checked_free(data->player_uuid_old);
4315 checked_free(data->player_uuid_new);
4319 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4322 struct ApiResetUUIDThreadData *data = data_raw;
4323 char *player_name_raw = data->player_name;
4324 char *player_uuid_old_raw = data->player_uuid_old;
4325 char *player_uuid_new_raw = data->player_uuid_new;
4327 request->hostname = setup.api_server_hostname;
4328 request->port = API_SERVER_PORT;
4329 request->method = API_SERVER_METHOD;
4330 request->uri = API_SERVER_URI_RESETUUID;
4332 char *player_name = getEscapedJSON(player_name_raw);
4333 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4334 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4336 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4339 " \"game_version\": \"%s\",\n"
4340 " \"game_platform\": \"%s\",\n"
4341 " \"name\": \"%s\",\n"
4342 " \"uuid_old\": \"%s\",\n"
4343 " \"uuid_new\": \"%s\"\n"
4345 getPasswordJSON(setup.api_server_password),
4346 getProgramRealVersionString(),
4347 getProgramPlatformString(),
4352 checked_free(player_name);
4353 checked_free(player_uuid_old);
4354 checked_free(player_uuid_new);
4356 ConvertHttpRequestBodyToServerEncoding(request);
4361 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4364 struct ApiResetUUIDThreadData *data = data_raw;
4366 // upgrade player UUID in server setup file
4367 setup.player_uuid = getStringCopy(data->player_uuid_new);
4368 setup.player_version = 2;
4370 SaveSetup_ServerSetup();
4373 #if defined(PLATFORM_EMSCRIPTEN)
4374 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4375 void *buffer, unsigned int size)
4377 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4379 if (response != NULL)
4381 HandleResponse_ApiResetUUID(response, data_raw);
4383 checked_free(response);
4387 Error("server response too large to handle (%d bytes)", size);
4390 FreeThreadData_ApiResetUUID(data_raw);
4393 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4394 int code, const char *status)
4396 Error("server failed to handle request: %d %s", code, status);
4398 FreeThreadData_ApiResetUUID(data_raw);
4401 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4402 int bytes, int size)
4404 // nothing to do here
4407 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4410 if (!SetRequest_ApiResetUUID(request, data_raw))
4412 FreeThreadData_ApiResetUUID(data_raw);
4417 emscripten_async_wget2_data(request->uri,
4422 Emscripten_ApiResetUUID_Loaded,
4423 Emscripten_ApiResetUUID_Failed,
4424 Emscripten_ApiResetUUID_Progress);
4429 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4430 struct HttpResponse *response,
4433 if (!SetRequest_ApiResetUUID(request, data_raw))
4436 if (!DoHttpRequest(request, response))
4438 Error("HTTP request failed: %s", GetHttpError());
4443 if (!HTTP_SUCCESS(response->status_code))
4445 Error("server failed to handle request: %d %s",
4446 response->status_code,
4447 response->status_text);
4452 HandleResponse_ApiResetUUID(response, data_raw);
4455 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4456 struct HttpResponse *response,
4459 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4461 FreeThreadData_ApiResetUUID(data_raw);
4465 static int ApiResetUUIDThread(void *data_raw)
4467 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4468 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4470 program.api_thread_count++;
4472 #if defined(PLATFORM_EMSCRIPTEN)
4473 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4475 ApiResetUUID_HttpRequest(request, response, data_raw);
4478 program.api_thread_count--;
4480 checked_free(request);
4481 checked_free(response);
4486 static void ApiResetUUIDAsThread(char *uuid_new)
4488 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4490 ExecuteAsThread(ApiResetUUIDThread,
4491 "ApiResetUUID", data,
4492 "reset UUID on server");
4496 // ============================================================================
4497 // type name functions
4498 // ============================================================================
4500 static TreeInfo *type_name_node = NULL;
4501 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4502 static int type_name_nr = 0;
4504 static int getPlayerNameColor(char *name)
4506 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4509 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4512 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4513 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4514 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4515 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4516 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4517 int font_width = getFontWidth(font_nr);
4519 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4521 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4523 pos->width = strlen(text) * font_width;
4524 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4526 DrawText(sx, sy, text, font_nr);
4529 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4531 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4533 *pos = *mci->pos_input;
4535 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4537 TreeInfo *ti = player_name_current;
4538 int first_entry = ti->cl_first;
4539 int entry_pos = first_entry + ti->cl_cursor;
4540 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4541 int xpos = MENU_SCREEN_START_XPOS;
4542 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4544 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4545 type_name_nr = entry_pos;
4547 strcpy(name, type_name_node->name);
4551 pos->width = MAX_PLAYER_NAME_LEN * 32;
4555 type_name_nr = user.nr;
4557 strcpy(name, setup.player_name);
4560 strcpy(type_name_last, name);
4562 if (strEqual(name, EMPTY_PLAYER_NAME))
4565 *xpos = strlen(name);
4568 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4570 // change name of edited user in global list of user names
4571 setString(&global.user_names[type_name_nr], name);
4573 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4575 TreeInfo *node = type_name_node;
4577 // change name of edited user in local menu tree structure
4578 setString(&node->name, name);
4579 setString(&node->name_sorting, name);
4581 node->color = getPlayerNameColor(name);
4582 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4586 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4589 boolean reset_setup = strEqual(name, "");
4590 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4591 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4594 strcpy(name, type_name_last);
4596 if (strEqual(name, ""))
4597 strcpy(name, EMPTY_PLAYER_NAME);
4599 setTypeNameValues_Name(name, pos);
4601 // if player name not changed, no further action required
4602 if (strEqual(name, type_name_last))
4605 // redraw player name before (possibly) opening request dialogs
4606 drawTypeNameText(name, pos, FALSE);
4608 int last_user_nr = user.nr;
4610 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4612 // save setup of currently active user (may differ from edited user)
4615 // temporarily change active user to edited user
4616 user.nr = type_name_nr;
4619 Request("Use current setup values for the new player?", REQ_ASK))
4621 // use current setup values for new user, but create new player UUID
4622 setup.player_uuid = getStringCopy(getUUID());
4626 // load setup for existing user (or start with defaults for new user)
4631 char *setup_filename = getSetupFilename();
4632 boolean setup_exists = fileExists(setup_filename);
4634 // change name of edited user in setup structure
4635 strcpy(setup.player_name, name);
4637 // save setup of edited user
4640 // change name of edited user on score server
4641 ApiRenamePlayerAsThread();
4643 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4647 if (Request("Reset setup values for this player?", REQ_ASK))
4649 // remove setup config file
4650 unlink(setup_filename);
4652 // set player name to default player name
4655 // update player name used by name typing functions
4656 strcpy(name, setup.player_name);
4658 setTypeNameValues_Name(name, pos);
4661 else if (remove_user && type_name_nr != 0)
4663 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4665 char *user_dir = getUserGameDataDir();
4666 char *user_dir_removed =
4667 getStringCat3WithSeparator(user_dir, "REMOVED",
4668 getCurrentTimestamp(), ".");
4670 if (rename(user_dir, user_dir_removed) != 0)
4671 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4673 checked_free(user_dir_removed);
4676 else if (create_user && type_name_nr != 0 && !setup_exists)
4678 if (Request("Create empty level set for the new player?", REQ_ASK))
4680 char *levelset_subdir = getNewUserLevelSubdir();
4682 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4684 AddUserLevelSetToLevelInfo(levelset_subdir);
4686 LevelDirTree *leveldir_current_last = leveldir_current;
4688 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4691 // set level number of newly created level set to default value
4692 LoadLevelSetup_SeriesInfo();
4694 // set newly created level set as current level set for new user
4695 SaveLevelSetup_LastSeries();
4696 SaveLevelSetup_SeriesInfo();
4698 leveldir_current = leveldir_current_last;
4702 Request("Creating new level set failed!", REQ_CONFIRM);
4707 // restore currently active user
4708 user.nr = last_user_nr;
4710 // restore setup of currently active user
4713 // restore last level set of currently active user
4714 LoadLevelSetup_LastSeries();
4715 LoadLevelSetup_SeriesInfo();
4719 static void HandleTypeNameExt(boolean initialize, Key key)
4721 static struct TextPosInfo pos_name = { 0 };
4722 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4723 static int xpos = 0;
4724 struct TextPosInfo *pos = &pos_name;
4725 char key_char = getValidConfigValueChar(getCharFromKey(key));
4726 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4727 boolean active = TRUE;
4731 getTypeNameValues(name, pos, &xpos);
4733 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4734 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4736 StartTextInput(sx, sy, pos->width, pos->height);
4738 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4740 name[xpos] = key_char;
4745 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4751 else if (key == KSYM_Return || key == KSYM_Escape)
4753 boolean changed = (key == KSYM_Return);
4757 setTypeNameValues(name, pos, changed);
4762 drawTypeNameText(name, pos, active);
4766 SetGameStatus(game_status_last_screen);
4768 if (game_status == GAME_MODE_MAIN)
4769 InitializeMainControls();
4773 static void DrawTypeName(void)
4775 HandleTypeNameExt(TRUE, 0);
4778 void HandleTypeName(Key key)
4780 HandleTypeNameExt(FALSE, key);
4784 // ============================================================================
4785 // tree menu functions
4786 // ============================================================================
4788 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4790 if (game_status != GAME_MODE_SETUP ||
4791 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4794 int max_text_size = 0;
4797 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4798 max_text_size = MAX(max_text_size, strlen(node->name));
4800 int num_entries = numTreeInfoInGroup(ti);
4801 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4802 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4803 int text_width = max_text_size * getFontWidth(font_nr);
4804 int button_width = SC_MENUBUTTON_XSIZE;
4805 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4806 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4807 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4808 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4809 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4810 int align_xoffset = MAX(0, align_xoffset_raw);
4812 return align_xoffset;
4815 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4817 if (game_status != GAME_MODE_SETUP ||
4818 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4821 int num_entries = numTreeInfoInGroup(ti);
4822 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4823 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4824 int font_height = getFontHeight(font_nr);
4825 int text_height = font_height * num_page_entries;
4826 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4827 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4828 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4829 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4830 int align_yoffset = MAX(0, align_yoffset_raw);
4832 return align_yoffset;
4835 static void DrawChooseTree(TreeInfo **ti_ptr)
4837 int fade_mask = REDRAW_FIELD;
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();
4863 if (game_status != game_status_last_screen)
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);
4894 if (game_status != game_status_last_screen)
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 = screen_width - 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 score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5721 if (score_entries != NULL)
5723 freeTreeInfo(score_entries);
5725 score_entries = NULL;
5728 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5730 // do not add empty score entries
5731 if (scores.entry[i].score == 0 &&
5732 scores.entry[i].time == 0)
5735 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5736 char identifier[32], name[64];
5739 ti->node_top = &score_entries;
5740 ti->sort_priority = 10000 + value;
5741 ti->color = FC_YELLOW;
5744 snprintf(identifier, sizeof(identifier), "%d", value);
5745 snprintf(name, sizeof(name), "%03d.", value + 1);
5747 setString(&ti->identifier, identifier);
5748 setString(&ti->name, name);
5749 setString(&ti->name_sorting, name);
5751 pushTreeInfo(&score_entries, ti);
5754 // sort score entries to start with highest score entry
5755 sortTreeInfo(&score_entries);
5757 // add top tree node to create back link to main menu
5758 score_entries = addTopTreeInfoNode(score_entries);
5760 // set current score entry to last added or highest score entry
5761 score_entry_current =
5762 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5764 // if that fails, set current score entry to first valid score entry
5765 if (score_entry_current == NULL)
5766 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5768 // ("score_entries" and "score_entry_current" may be NULL here)
5771 void DrawHallOfFame(int level_nr)
5773 scores.last_level_nr = level_nr;
5775 // (this is needed when called from GameEnd() after winning a game)
5776 KeyboardAutoRepeatOn();
5778 // (this is needed when called from GameEnd() after winning a game)
5779 SetDrawDeactivationMask(REDRAW_NONE);
5780 SetDrawBackgroundMask(REDRAW_FIELD);
5782 LoadLocalAndServerScore(level_nr, TRUE);
5784 DrawHallOfFame_setScoreEntries();
5786 if (scores.last_added >= 0)
5787 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5789 FadeSetEnterScreen();
5791 DrawChooseTree(&score_entry_current);
5794 static char *getHallOfFameRankText(int nr, int size)
5796 static char rank_text[10];
5797 boolean forced = (scores.force_last_added && nr == scores.last_added);
5798 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5800 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5805 static char *getHallOfFameTimeText(int nr)
5807 static char score_text[10];
5808 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5809 int mm = (time_seconds / 60) % 60;
5810 int ss = (time_seconds % 60);
5812 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5817 static char *getHallOfFameScoreText(int nr, int size)
5819 if (!level.rate_time_over_score)
5820 return int2str(scores.entry[nr].score, size); // show normal score
5821 else if (level.use_step_counter)
5822 return int2str(scores.entry[nr].time, size); // show number of steps
5824 return getHallOfFameTimeText(nr); // show playing time
5827 static void HandleHallOfFame_SelectLevel(int step, int direction)
5829 int old_level_nr = scores.last_level_nr;
5830 int new_level_nr = old_level_nr + step * direction;
5832 if (new_level_nr < leveldir_current->first_level)
5833 new_level_nr = leveldir_current->first_level;
5834 if (new_level_nr > leveldir_current->last_level)
5835 new_level_nr = leveldir_current->last_level;
5837 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5838 new_level_nr = leveldir_current->handicap_level;
5840 if (new_level_nr != old_level_nr)
5842 PlaySound(SND_MENU_ITEM_SELECTING);
5844 scores.last_level_nr = level_nr = new_level_nr;
5846 LoadLevel(level_nr);
5847 LoadLocalAndServerScore(level_nr, TRUE);
5849 DrawHallOfFame_setScoreEntries();
5851 if (game_status == GAME_MODE_SCORES)
5853 // force remapping optional gadgets (especially scroll bar)
5854 UnmapScreenTreeGadgets();
5856 // redraw complete high score screen, as sub-title has changed
5859 // redraw level selection buttons (which have just been erased)
5860 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5862 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5866 scores.last_entry_nr = 0;
5868 DrawScoreInfo_Content(scores.last_entry_nr);
5871 SaveLevelSetup_SeriesInfo();
5875 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5877 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5880 static void DrawScoreInfo_Content(int entry_nr)
5882 struct ScoreEntry *entry = &scores.entry[entry_nr];
5883 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5884 int font_title = MENU_INFO_FONT_TITLE;
5885 int font_head = MENU_INFO_FONT_HEAD;
5886 int font_text = MENU_INFO_FONT_TEXT;
5887 int font_foot = MENU_INFO_FONT_FOOT;
5888 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5889 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5890 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5891 int xstep = getFontWidth(font_text);
5892 int ystep_title = getMenuTextStep(spacing_title, font_title);
5893 int ystep_para = getMenuTextStep(spacing_para, font_text);
5894 int ystep_line = getMenuTextStep(spacing_line, font_text);
5895 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5896 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5897 int xstart1 = mSX - SX + 2 * xstep;
5898 int xstart2 = mSX - SX + 13 * xstep;
5899 int button_x = SX + xstart1;
5900 int button_y1, button_y2;
5901 int font_width = getFontWidth(font_text);
5902 int font_height = getFontHeight(font_text);
5903 int pad_left = xstart2;
5904 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
5905 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5906 int max_lines_per_text = 5;
5911 // redraw score selection buttons (which have just been erased)
5912 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5914 if (score_entries == NULL)
5916 drawChooseTreeScreen_Scores_NotAvailable();
5921 drawChooseTreeHead(score_entries);
5922 drawChooseTreeInfo(score_entries);
5924 DrawTextSCentered(ystart, font_title, "Score Information:");
5925 ystart += ystep_title;
5927 DrawTextF(xstart1, ystart, font_head, "Level Set");
5928 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5929 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5930 TRUE, FALSE, FALSE);
5931 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5933 DrawTextF(xstart1, ystart, font_head, "Level");
5934 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5935 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5936 TRUE, FALSE, FALSE);
5937 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5939 button_y1 = SY + ystart;
5940 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5942 DrawTextF(xstart1, ystart, font_head, "Rank");
5943 DrawTextF(xstart2, ystart, font_text, pos_text);
5944 ystart += ystep_line;
5946 DrawTextF(xstart1, ystart, font_head, "Player");
5947 DrawTextF(xstart2, ystart, font_text, entry->name);
5948 ystart += ystep_line;
5950 if (level.use_step_counter)
5952 DrawTextF(xstart1, ystart, font_head, "Steps");
5953 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5954 ystart += ystep_line;
5958 DrawTextF(xstart1, ystart, font_head, "Time");
5959 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5960 ystart += ystep_line;
5963 if (!level.rate_time_over_score || entry->score > 0)
5965 DrawTextF(xstart1, ystart, font_head, "Score");
5966 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5967 ystart += ystep_line;
5970 ystart += ystep_line;
5972 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5973 DrawTextF(xstart2, ystart, font_text, entry->tape_date);
5974 ystart += ystep_line;
5976 DrawTextF(xstart1, ystart, font_head, "Platform");
5977 DrawTextF(xstart2, ystart, font_text, entry->platform);
5978 ystart += ystep_line;
5980 DrawTextF(xstart1, ystart, font_head, "Version");
5981 DrawTextF(xstart2, ystart, font_text, entry->version);
5982 ystart += ystep_line;
5984 DrawTextF(xstart1, ystart, font_head, "Country");
5985 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5986 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5987 TRUE, FALSE, FALSE);
5988 ystart += ystep_line;
5990 button_y2 = SY + ystart;
5992 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5994 AdjustScoreInfoButtons(button_x, button_y1, button_y2);
5997 static void DrawScoreInfo(int entry_nr)
5999 scores.last_entry_nr = entry_nr;
6001 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
6005 FadeOut(REDRAW_FIELD);
6007 DrawScoreInfo_Content(entry_nr);
6009 // map gadgets for score info screen
6010 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
6012 FadeIn(REDRAW_FIELD);
6015 static void HandleScoreInfo_SelectScore(int step, int direction)
6017 int old_entry_nr = scores.last_entry_nr;
6018 int new_entry_nr = old_entry_nr + step * direction;
6019 int num_nodes = numTreeInfoInGroup(score_entry_current);
6020 int num_entries = num_nodes - 1; // score nodes only, without back link
6022 if (new_entry_nr < 0)
6024 if (new_entry_nr > num_entries - 1)
6025 new_entry_nr = num_entries - 1;
6027 if (new_entry_nr != old_entry_nr)
6029 scores.last_entry_nr = new_entry_nr;
6031 DrawScoreInfo_Content(new_entry_nr);
6035 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
6037 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
6038 boolean button_is_valid = (mx >= 0 && my >= 0);
6039 boolean button_screen_clicked = (button_action && button_is_valid);
6041 if (server_scores.updated)
6043 // reload scores, using updated server score cache file
6044 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
6046 server_scores.updated = FALSE;
6048 DrawHallOfFame_setScoreEntries();
6050 DrawScoreInfo_Content(scores.last_entry_nr);
6053 if (button_screen_clicked)
6055 PlaySound(SND_MENU_ITEM_SELECTING);
6057 SetGameStatus(GAME_MODE_SCORES);
6059 DrawHallOfFame(level_nr);
6063 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
6067 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
6072 // ============================================================================
6073 // setup screen functions
6074 // ============================================================================
6076 static struct TokenInfo *setup_info;
6077 static int num_setup_info; // number of setup entries shown on screen
6078 static int max_setup_info; // total number of setup entries in list
6080 static char *window_size_text;
6081 static char *scaling_type_text;
6082 static char *rendering_mode_text;
6083 static char *vsync_mode_text;
6084 static char *scroll_delay_text;
6085 static char *snapshot_mode_text;
6086 static char *game_speed_text;
6087 static char *scores_type_text;
6088 static char *network_server_text;
6089 static char *graphics_set_name;
6090 static char *sounds_set_name;
6091 static char *music_set_name;
6092 static char *volume_simple_text;
6093 static char *volume_loops_text;
6094 static char *volume_music_text;
6095 static char *touch_controls_text;
6096 static char *move_distance_text;
6097 static char *drop_distance_text;
6098 static char *transparency_text;
6099 static char *grid_size_text[2][2];
6101 static void execSetupMain(void)
6103 setup_mode = SETUP_MODE_MAIN;
6108 static void execSetupGame_setScoresType(void)
6110 if (scores_types == NULL)
6114 for (i = 0; scores_types_list[i].value != NULL; i++)
6116 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6117 char identifier[32], name[32];
6118 char *value = scores_types_list[i].value;
6119 char *text = scores_types_list[i].text;
6121 ti->node_top = &scores_types;
6122 ti->sort_priority = i;
6124 sprintf(identifier, "%s", value);
6125 sprintf(name, "%s", text);
6127 setString(&ti->identifier, identifier);
6128 setString(&ti->name, name);
6129 setString(&ti->name_sorting, name);
6130 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
6132 pushTreeInfo(&scores_types, ti);
6135 // sort scores type values to start with lowest scores type value
6136 sortTreeInfo(&scores_types);
6138 // set current scores type value to configured scores type value
6139 scores_type_current =
6140 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
6142 // if that fails, set current scores type to reliable default value
6143 if (scores_type_current == NULL)
6144 scores_type_current =
6145 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
6147 // if that also fails, set current scores type to first available value
6148 if (scores_type_current == NULL)
6149 scores_type_current = scores_types;
6152 setup.scores_in_highscore_list = scores_type_current->identifier;
6154 // needed for displaying scores type text instead of identifier
6155 scores_type_text = scores_type_current->name;
6158 static void execSetupGame_setGameSpeeds(boolean update_value)
6160 if (setup.game_speed_extended)
6162 game_speeds_list = game_speeds_list_extended;
6163 game_speeds = game_speeds_extended;
6167 game_speeds_list = game_speeds_list_normal;
6168 game_speeds = game_speeds_normal;
6171 if (game_speeds == NULL)
6175 for (i = 0; game_speeds_list[i].value != -1; i++)
6177 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6178 char identifier[32], name[32];
6179 int value = game_speeds_list[i].value;
6180 char *text = game_speeds_list[i].text;
6182 ti->node_top = &game_speeds;
6183 ti->sort_priority = 10000 - value;
6185 sprintf(identifier, "%d", value);
6186 sprintf(name, "%s", text);
6188 setString(&ti->identifier, identifier);
6189 setString(&ti->name, name);
6190 setString(&ti->name_sorting, name);
6191 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
6193 pushTreeInfo(&game_speeds, ti);
6196 // sort game speed values to start with slowest game speed
6197 sortTreeInfo(&game_speeds);
6199 update_value = TRUE;
6204 // set current game speed to configured game speed value
6205 game_speed_current =
6206 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6208 // if that fails, set current game speed to reliable default value
6209 if (game_speed_current == NULL)
6210 game_speed_current =
6211 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6213 // if that also fails, set current game speed to first available speed
6214 if (game_speed_current == NULL)
6215 game_speed_current = game_speeds;
6217 if (setup.game_speed_extended)
6218 game_speeds_extended = game_speeds;
6220 game_speeds_normal = game_speeds;
6223 setup.game_frame_delay = atoi(game_speed_current->identifier);
6225 // needed for displaying game speed text instead of identifier
6226 game_speed_text = game_speed_current->name;
6229 static void execSetupGame_setScrollDelays(void)
6231 if (scroll_delays == NULL)
6235 for (i = 0; scroll_delays_list[i].value != -1; i++)
6237 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6238 char identifier[32], name[32];
6239 int value = scroll_delays_list[i].value;
6240 char *text = scroll_delays_list[i].text;
6242 ti->node_top = &scroll_delays;
6243 ti->sort_priority = value;
6245 sprintf(identifier, "%d", value);
6246 sprintf(name, "%s", text);
6248 setString(&ti->identifier, identifier);
6249 setString(&ti->name, name);
6250 setString(&ti->name_sorting, name);
6251 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6253 pushTreeInfo(&scroll_delays, ti);
6256 // sort scroll delay values to start with lowest scroll delay value
6257 sortTreeInfo(&scroll_delays);
6259 // set current scroll delay value to configured scroll delay value
6260 scroll_delay_current =
6261 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6263 // if that fails, set current scroll delay to reliable default value
6264 if (scroll_delay_current == NULL)
6265 scroll_delay_current =
6266 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6268 // if that also fails, set current scroll delay to first available value
6269 if (scroll_delay_current == NULL)
6270 scroll_delay_current = scroll_delays;
6273 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6275 // needed for displaying scroll delay text instead of identifier
6276 scroll_delay_text = scroll_delay_current->name;
6279 static void execSetupGame_setSnapshotModes(void)
6281 if (snapshot_modes == NULL)
6285 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6287 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6288 char identifier[32], name[32];
6289 char *value = snapshot_modes_list[i].value;
6290 char *text = snapshot_modes_list[i].text;
6292 ti->node_top = &snapshot_modes;
6293 ti->sort_priority = i;
6295 sprintf(identifier, "%s", value);
6296 sprintf(name, "%s", text);
6298 setString(&ti->identifier, identifier);
6299 setString(&ti->name, name);
6300 setString(&ti->name_sorting, name);
6301 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6303 pushTreeInfo(&snapshot_modes, ti);
6306 // sort snapshot mode values to start with lowest snapshot mode value
6307 sortTreeInfo(&snapshot_modes);
6309 // set current snapshot mode value to configured snapshot mode value
6310 snapshot_mode_current =
6311 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6313 // if that fails, set current snapshot mode to reliable default value
6314 if (snapshot_mode_current == NULL)
6315 snapshot_mode_current =
6316 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6318 // if that also fails, set current snapshot mode to first available value
6319 if (snapshot_mode_current == NULL)
6320 snapshot_mode_current = snapshot_modes;
6323 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6325 // needed for displaying snapshot mode text instead of identifier
6326 snapshot_mode_text = snapshot_mode_current->name;
6329 static void execSetupGame_setNetworkServerText(void)
6331 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6333 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6337 strncpy(network_server_hostname, setup.network_server_hostname,
6338 MAX_SETUP_TEXT_INPUT_LEN);
6339 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6342 // needed for displaying network server text instead of identifier
6343 network_server_text = network_server_hostname;
6346 static void execSetupGame(void)
6348 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6350 execSetupGame_setGameSpeeds(FALSE);
6351 execSetupGame_setScoresType();
6352 execSetupGame_setScrollDelays();
6353 execSetupGame_setSnapshotModes();
6355 execSetupGame_setNetworkServerText();
6357 if (!setup.provide_uploading_tapes)
6358 setHideSetupEntry(execOfferUploadTapes);
6360 setup_mode = SETUP_MODE_GAME;
6364 // check if vsync needs to be disabled for this game speed to work
6365 if (check_vsync_mode)
6366 DisableVsyncIfNeeded();
6369 static void execSetupChooseScoresType(void)
6371 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6376 static void execSetupChooseGameSpeed(void)
6378 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6383 static void execSetupChooseScrollDelay(void)
6385 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6390 static void execSetupChooseSnapshotMode(void)
6392 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6397 static void execSetupEngines(void)
6399 setup_mode = SETUP_MODE_ENGINES;
6404 static void execSetupEditor(void)
6406 setup_mode = SETUP_MODE_EDITOR;
6411 static void execSetupGraphics_setWindowSizes(boolean update_list)
6413 if (window_sizes != NULL && update_list)
6415 freeTreeInfo(window_sizes);
6417 window_sizes = NULL;
6420 if (window_sizes == NULL)
6422 boolean current_window_size_found = FALSE;
6425 for (i = 0; window_sizes_list[i].value != -1; i++)
6427 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6428 char identifier[32], name[32];
6429 int value = window_sizes_list[i].value;
6430 char *text = window_sizes_list[i].text;
6432 ti->node_top = &window_sizes;
6433 ti->sort_priority = value;
6435 sprintf(identifier, "%d", value);
6436 sprintf(name, "%s", text);
6438 setString(&ti->identifier, identifier);
6439 setString(&ti->name, name);
6440 setString(&ti->name_sorting, name);
6441 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6443 pushTreeInfo(&window_sizes, ti);
6445 if (value == setup.window_scaling_percent)
6446 current_window_size_found = TRUE;
6449 if (!current_window_size_found)
6451 // add entry for non-preset window scaling value
6453 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6454 char identifier[32], name[32];
6455 int value = setup.window_scaling_percent;
6457 ti->node_top = &window_sizes;
6458 ti->sort_priority = value;
6460 sprintf(identifier, "%d", value);
6461 sprintf(name, "%d %% (Current)", value);
6463 setString(&ti->identifier, identifier);
6464 setString(&ti->name, name);
6465 setString(&ti->name_sorting, name);
6466 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6468 pushTreeInfo(&window_sizes, ti);
6471 // sort window size values to start with lowest window size value
6472 sortTreeInfo(&window_sizes);
6474 // set current window size value to configured window size value
6475 window_size_current =
6476 getTreeInfoFromIdentifier(window_sizes,
6477 i_to_a(setup.window_scaling_percent));
6479 // if that fails, set current window size to reliable default value
6480 if (window_size_current == NULL)
6481 window_size_current =
6482 getTreeInfoFromIdentifier(window_sizes,
6483 i_to_a(STD_WINDOW_SCALING_PERCENT));
6485 // if that also fails, set current window size to first available value
6486 if (window_size_current == NULL)
6487 window_size_current = window_sizes;
6490 setup.window_scaling_percent = atoi(window_size_current->identifier);
6492 // needed for displaying window size text instead of identifier
6493 window_size_text = window_size_current->name;
6496 static void execSetupGraphics_setScalingTypes(void)
6498 if (scaling_types == NULL)
6502 for (i = 0; scaling_types_list[i].value != NULL; i++)
6504 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6505 char identifier[32], name[32];
6506 char *value = scaling_types_list[i].value;
6507 char *text = scaling_types_list[i].text;
6509 ti->node_top = &scaling_types;
6510 ti->sort_priority = i;
6512 sprintf(identifier, "%s", value);
6513 sprintf(name, "%s", text);
6515 setString(&ti->identifier, identifier);
6516 setString(&ti->name, name);
6517 setString(&ti->name_sorting, name);
6518 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6520 pushTreeInfo(&scaling_types, ti);
6523 // sort scaling type values to start with lowest scaling type value
6524 sortTreeInfo(&scaling_types);
6526 // set current scaling type value to configured scaling type value
6527 scaling_type_current =
6528 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6530 // if that fails, set current scaling type to reliable default value
6531 if (scaling_type_current == NULL)
6532 scaling_type_current =
6533 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6535 // if that also fails, set current scaling type to first available value
6536 if (scaling_type_current == NULL)
6537 scaling_type_current = scaling_types;
6540 setup.window_scaling_quality = scaling_type_current->identifier;
6542 // needed for displaying scaling type text instead of identifier
6543 scaling_type_text = scaling_type_current->name;
6546 static void execSetupGraphics_setRenderingModes(void)
6548 if (rendering_modes == NULL)
6552 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6554 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6555 char identifier[32], name[32];
6556 char *value = rendering_modes_list[i].value;
6557 char *text = rendering_modes_list[i].text;
6559 ti->node_top = &rendering_modes;
6560 ti->sort_priority = i;
6562 sprintf(identifier, "%s", value);
6563 sprintf(name, "%s", text);
6565 setString(&ti->identifier, identifier);
6566 setString(&ti->name, name);
6567 setString(&ti->name_sorting, name);
6568 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6570 pushTreeInfo(&rendering_modes, ti);
6573 // sort rendering mode values to start with lowest rendering mode value
6574 sortTreeInfo(&rendering_modes);
6576 // set current rendering mode value to configured rendering mode value
6577 rendering_mode_current =
6578 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6580 // if that fails, set current rendering mode to reliable default value
6581 if (rendering_mode_current == NULL)
6582 rendering_mode_current =
6583 getTreeInfoFromIdentifier(rendering_modes,
6584 STR_SPECIAL_RENDERING_DEFAULT);
6586 // if that also fails, set current rendering mode to first available one
6587 if (rendering_mode_current == NULL)
6588 rendering_mode_current = rendering_modes;
6591 setup.screen_rendering_mode = rendering_mode_current->identifier;
6593 // needed for displaying rendering mode text instead of identifier
6594 rendering_mode_text = rendering_mode_current->name;
6597 static void execSetupGraphics_setVsyncModes(boolean update_value)
6599 if (vsync_modes == NULL)
6603 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6605 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6606 char identifier[32], name[32];
6607 char *value = vsync_modes_list[i].value;
6608 char *text = vsync_modes_list[i].text;
6610 ti->node_top = &vsync_modes;
6611 ti->sort_priority = i;
6613 sprintf(identifier, "%s", value);
6614 sprintf(name, "%s", text);
6616 setString(&ti->identifier, identifier);
6617 setString(&ti->name, name);
6618 setString(&ti->name_sorting, name);
6619 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6621 pushTreeInfo(&vsync_modes, ti);
6624 // sort vsync mode values to start with lowest vsync mode value
6625 sortTreeInfo(&vsync_modes);
6627 update_value = TRUE;
6632 // set current vsync mode value to configured vsync mode value
6633 vsync_mode_current =
6634 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6636 // if that fails, set current vsync mode to reliable default value
6637 if (vsync_mode_current == NULL)
6638 vsync_mode_current =
6639 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6641 // if that also fails, set current vsync mode to first available one
6642 if (vsync_mode_current == NULL)
6643 vsync_mode_current = vsync_modes;
6646 setup.vsync_mode = vsync_mode_current->identifier;
6648 // needed for displaying vsync mode text instead of identifier
6649 vsync_mode_text = vsync_mode_current->name;
6652 static void execSetupGraphics(void)
6654 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6656 // update "setup.window_scaling_percent" from list selection
6657 // (in this case, window scaling was changed on setup screen)
6658 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6659 execSetupGraphics_setWindowSizes(FALSE);
6661 // update "setup.vsync_mode" from list selection
6662 // (in this case, vsync mode was changed on setup screen)
6663 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6664 execSetupGraphics_setVsyncModes(FALSE);
6666 // update list selection from "setup.window_scaling_percent"
6667 // (window scaling may have changed by resizing the window)
6668 execSetupGraphics_setWindowSizes(TRUE);
6670 // update list selection from "setup.vsync_mode"
6671 // (vsync_mode may have changed by re-creating the renderer)
6672 execSetupGraphics_setVsyncModes(TRUE);
6674 execSetupGraphics_setScalingTypes();
6675 execSetupGraphics_setRenderingModes();
6677 setup_mode = SETUP_MODE_GRAPHICS;
6681 // check if game speed is high enough for 60 Hz vsync to work
6682 if (check_game_speed)
6683 ModifyGameSpeedIfNeeded();
6685 // window scaling may have changed at this point
6686 ChangeWindowScalingIfNeeded();
6688 // window scaling quality may have changed at this point
6689 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6690 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6692 // screen rendering mode may have changed at this point
6693 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6695 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6696 int video_vsync_mode = video.vsync_mode;
6698 // screen vsync mode may have changed at this point
6699 ChangeVsyncModeIfNeeded();
6701 // check if setting vsync mode to selected value failed
6702 if (setup_vsync_mode != video_vsync_mode &&
6703 setup_vsync_mode != video.vsync_mode)
6705 // changing vsync mode to selected value failed -- reset displayed value
6706 execSetupGraphics_setVsyncModes(TRUE);
6708 Request("Setting VSync failed!", REQ_CONFIRM);
6714 static void execSetupChooseWindowSize(void)
6716 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6721 static void execSetupChooseScalingType(void)
6723 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6728 static void execSetupChooseRenderingMode(void)
6730 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6735 static void execSetupChooseVsyncMode(void)
6737 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6742 static void execSetupChooseVolumeSimple(void)
6744 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6749 static void execSetupChooseVolumeLoops(void)
6751 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6756 static void execSetupChooseVolumeMusic(void)
6758 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6763 static void execSetupSound(void)
6765 if (volumes_simple == NULL)
6767 boolean current_volume_simple_found = FALSE;
6770 for (i = 0; volumes_list[i].value != -1; i++)
6772 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6773 char identifier[32], name[32];
6774 int value = volumes_list[i].value;
6775 char *text = volumes_list[i].text;
6777 ti->node_top = &volumes_simple;
6778 ti->sort_priority = value;
6780 sprintf(identifier, "%d", value);
6781 sprintf(name, "%s", text);
6783 setString(&ti->identifier, identifier);
6784 setString(&ti->name, name);
6785 setString(&ti->name_sorting, name);
6786 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6788 pushTreeInfo(&volumes_simple, ti);
6790 if (value == setup.volume_simple)
6791 current_volume_simple_found = TRUE;
6794 if (!current_volume_simple_found)
6796 // add entry for non-preset volume value
6798 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6799 char identifier[32], name[32];
6800 int value = setup.volume_simple;
6802 ti->node_top = &volumes_simple;
6803 ti->sort_priority = value;
6805 sprintf(identifier, "%d", value);
6806 sprintf(name, "%d %% (Current)", value);
6808 setString(&ti->identifier, identifier);
6809 setString(&ti->name, name);
6810 setString(&ti->name_sorting, name);
6811 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6813 pushTreeInfo(&volumes_simple, ti);
6816 // sort volume values to start with lowest volume value
6817 sortTreeInfo(&volumes_simple);
6819 // set current volume value to configured volume value
6820 volume_simple_current =
6821 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6823 // if that fails, set current volume to reliable default value
6824 if (volume_simple_current == NULL)
6825 volume_simple_current =
6826 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6828 // if that also fails, set current volume to first available value
6829 if (volume_simple_current == NULL)
6830 volume_simple_current = volumes_simple;
6833 if (volumes_loops == NULL)
6835 boolean current_volume_loops_found = FALSE;
6838 for (i = 0; volumes_list[i].value != -1; i++)
6840 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6841 char identifier[32], name[32];
6842 int value = volumes_list[i].value;
6843 char *text = volumes_list[i].text;
6845 ti->node_top = &volumes_loops;
6846 ti->sort_priority = value;
6848 sprintf(identifier, "%d", value);
6849 sprintf(name, "%s", text);
6851 setString(&ti->identifier, identifier);
6852 setString(&ti->name, name);
6853 setString(&ti->name_sorting, name);
6854 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6856 pushTreeInfo(&volumes_loops, ti);
6858 if (value == setup.volume_loops)
6859 current_volume_loops_found = TRUE;
6862 if (!current_volume_loops_found)
6864 // add entry for non-preset volume value
6866 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6867 char identifier[32], name[32];
6868 int value = setup.volume_loops;
6870 ti->node_top = &volumes_loops;
6871 ti->sort_priority = value;
6873 sprintf(identifier, "%d", value);
6874 sprintf(name, "%d %% (Current)", value);
6876 setString(&ti->identifier, identifier);
6877 setString(&ti->name, name);
6878 setString(&ti->name_sorting, name);
6879 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6881 pushTreeInfo(&volumes_loops, ti);
6884 // sort volume values to start with lowest volume value
6885 sortTreeInfo(&volumes_loops);
6887 // set current volume value to configured volume value
6888 volume_loops_current =
6889 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6891 // if that fails, set current volume to reliable default value
6892 if (volume_loops_current == NULL)
6893 volume_loops_current =
6894 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6896 // if that also fails, set current volume to first available value
6897 if (volume_loops_current == NULL)
6898 volume_loops_current = volumes_loops;
6901 if (volumes_music == NULL)
6903 boolean current_volume_music_found = FALSE;
6906 for (i = 0; volumes_list[i].value != -1; i++)
6908 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6909 char identifier[32], name[32];
6910 int value = volumes_list[i].value;
6911 char *text = volumes_list[i].text;
6913 ti->node_top = &volumes_music;
6914 ti->sort_priority = value;
6916 sprintf(identifier, "%d", value);
6917 sprintf(name, "%s", text);
6919 setString(&ti->identifier, identifier);
6920 setString(&ti->name, name);
6921 setString(&ti->name_sorting, name);
6922 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6924 pushTreeInfo(&volumes_music, ti);
6926 if (value == setup.volume_music)
6927 current_volume_music_found = TRUE;
6930 if (!current_volume_music_found)
6932 // add entry for non-preset volume value
6934 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6935 char identifier[32], name[32];
6936 int value = setup.volume_music;
6938 ti->node_top = &volumes_music;
6939 ti->sort_priority = value;
6941 sprintf(identifier, "%d", value);
6942 sprintf(name, "%d %% (Current)", value);
6944 setString(&ti->identifier, identifier);
6945 setString(&ti->name, name);
6946 setString(&ti->name_sorting, name);
6947 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6949 pushTreeInfo(&volumes_music, ti);
6952 // sort volume values to start with lowest volume value
6953 sortTreeInfo(&volumes_music);
6955 // set current volume value to configured volume value
6956 volume_music_current =
6957 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6959 // if that fails, set current volume to reliable default value
6960 if (volume_music_current == NULL)
6961 volume_music_current =
6962 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6964 // if that also fails, set current volume to first available value
6965 if (volume_music_current == NULL)
6966 volume_music_current = volumes_music;
6969 setup.volume_simple = atoi(volume_simple_current->identifier);
6970 setup.volume_loops = atoi(volume_loops_current->identifier);
6971 setup.volume_music = atoi(volume_music_current->identifier);
6973 // needed for displaying volume text instead of identifier
6974 volume_simple_text = volume_simple_current->name;
6975 volume_loops_text = volume_loops_current->name;
6976 volume_music_text = volume_music_current->name;
6978 setup_mode = SETUP_MODE_SOUND;
6983 static void execSetupChooseTouchControls(void)
6985 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6990 static void execSetupChooseMoveDistance(void)
6992 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6997 static void execSetupChooseDropDistance(void)
6999 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
7004 static void execSetupChooseTransparency(void)
7006 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
7011 static void execSetupChooseGridXSize_0(void)
7013 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
7018 static void execSetupChooseGridYSize_0(void)
7020 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
7025 static void execSetupChooseGridXSize_1(void)
7027 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
7032 static void execSetupChooseGridYSize_1(void)
7034 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
7039 static void execSetupConfigureVirtualButtons(void)
7041 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
7043 ConfigureVirtualButtons();
7045 setup_mode = SETUP_MODE_TOUCH;
7050 static void execSetupTouch(void)
7054 if (touch_controls == NULL)
7056 for (i = 0; touch_controls_list[i].value != NULL; i++)
7058 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7059 char identifier[32], name[32];
7060 char *value = touch_controls_list[i].value;
7061 char *text = touch_controls_list[i].text;
7063 ti->node_top = &touch_controls;
7064 ti->sort_priority = i;
7066 sprintf(identifier, "%s", value);
7067 sprintf(name, "%s", text);
7069 setString(&ti->identifier, identifier);
7070 setString(&ti->name, name);
7071 setString(&ti->name_sorting, name);
7072 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
7074 pushTreeInfo(&touch_controls, ti);
7077 // sort touch control values to start with lowest touch control value
7078 sortTreeInfo(&touch_controls);
7080 // set current touch control value to configured touch control value
7081 touch_control_current =
7082 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
7084 // if that fails, set current touch control to reliable default value
7085 if (touch_control_current == NULL)
7086 touch_control_current =
7087 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
7089 // if that also fails, set current touch control to first available value
7090 if (touch_control_current == NULL)
7091 touch_control_current = touch_controls;
7094 if (move_distances == NULL)
7096 for (i = 0; distances_list[i].value != -1; i++)
7098 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7099 char identifier[32], name[32];
7100 int value = distances_list[i].value;
7101 char *text = distances_list[i].text;
7103 ti->node_top = &move_distances;
7104 ti->sort_priority = value;
7106 sprintf(identifier, "%d", value);
7107 sprintf(name, "%s", text);
7109 setString(&ti->identifier, identifier);
7110 setString(&ti->name, name);
7111 setString(&ti->name_sorting, name);
7112 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
7114 pushTreeInfo(&move_distances, ti);
7117 // sort distance values to start with lowest distance value
7118 sortTreeInfo(&move_distances);
7120 // set current distance value to configured distance value
7121 move_distance_current =
7122 getTreeInfoFromIdentifier(move_distances,
7123 i_to_a(setup.touch.move_distance));
7125 // if that fails, set current distance to reliable default value
7126 if (move_distance_current == NULL)
7127 move_distance_current =
7128 getTreeInfoFromIdentifier(move_distances,
7129 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
7131 // if that also fails, set current distance to first available value
7132 if (move_distance_current == NULL)
7133 move_distance_current = move_distances;
7136 if (drop_distances == NULL)
7138 for (i = 0; distances_list[i].value != -1; i++)
7140 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7141 char identifier[32], name[32];
7142 int value = distances_list[i].value;
7143 char *text = distances_list[i].text;
7145 ti->node_top = &drop_distances;
7146 ti->sort_priority = value;
7148 sprintf(identifier, "%d", value);
7149 sprintf(name, "%s", text);
7151 setString(&ti->identifier, identifier);
7152 setString(&ti->name, name);
7153 setString(&ti->name_sorting, name);
7154 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
7156 pushTreeInfo(&drop_distances, ti);
7159 // sort distance values to start with lowest distance value
7160 sortTreeInfo(&drop_distances);
7162 // set current distance value to configured distance value
7163 drop_distance_current =
7164 getTreeInfoFromIdentifier(drop_distances,
7165 i_to_a(setup.touch.drop_distance));
7167 // if that fails, set current distance to reliable default value
7168 if (drop_distance_current == NULL)
7169 drop_distance_current =
7170 getTreeInfoFromIdentifier(drop_distances,
7171 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
7173 // if that also fails, set current distance to first available value
7174 if (drop_distance_current == NULL)
7175 drop_distance_current = drop_distances;
7178 if (transparencies == NULL)
7180 for (i = 0; transparencies_list[i].value != -1; i++)
7182 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7183 char identifier[32], name[32];
7184 int value = transparencies_list[i].value;
7185 char *text = transparencies_list[i].text;
7187 ti->node_top = &transparencies;
7188 ti->sort_priority = value;
7190 sprintf(identifier, "%d", value);
7191 sprintf(name, "%s", text);
7193 setString(&ti->identifier, identifier);
7194 setString(&ti->name, name);
7195 setString(&ti->name_sorting, name);
7196 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
7198 pushTreeInfo(&transparencies, ti);
7201 // sort transparency values to start with lowest transparency value
7202 sortTreeInfo(&transparencies);
7204 // set current transparency value to configured transparency value
7205 transparency_current =
7206 getTreeInfoFromIdentifier(transparencies,
7207 i_to_a(setup.touch.transparency));
7209 // if that fails, set current transparency to reliable default value
7210 if (transparency_current == NULL)
7211 transparency_current =
7212 getTreeInfoFromIdentifier(transparencies,
7213 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7215 // if that also fails, set current transparency to first available value
7216 if (transparency_current == NULL)
7217 transparency_current = transparencies;
7220 for (i = 0; i < 2; i++)
7222 for (j = 0; j < 2; j++)
7224 if (grid_sizes[i][j] == NULL)
7226 for (k = 0; grid_sizes_list[k].value != -1; k++)
7228 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7229 char identifier[32], name[32];
7230 int value = grid_sizes_list[k].value;
7231 char *text = grid_sizes_list[k].text;
7233 ti->node_top = &grid_sizes[i][j];
7234 ti->sort_priority = value;
7236 sprintf(identifier, "%d", value);
7237 sprintf(name, "%s", text);
7239 setString(&ti->identifier, identifier);
7240 setString(&ti->name, name);
7241 setString(&ti->name_sorting, name);
7242 setString(&ti->infotext,
7245 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7246 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7248 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7249 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7251 pushTreeInfo(&grid_sizes[i][j], ti);
7254 // sort grid size values to start with lowest grid size value
7255 sortTreeInfo(&grid_sizes[i][j]);
7257 // set current grid size value to configured grid size value
7258 grid_size_current[i][j] =
7259 getTreeInfoFromIdentifier(grid_sizes[i][j],
7261 setup.touch.grid_xsize[i] :
7262 setup.touch.grid_ysize[i]));
7264 // if that fails, set current grid size to reliable default value
7265 if (grid_size_current[i][j] == NULL)
7266 grid_size_current[i][j] =
7267 getTreeInfoFromIdentifier(grid_sizes[i][j],
7269 DEFAULT_GRID_XSIZE(i) :
7270 DEFAULT_GRID_YSIZE(i)));
7272 // if that also fails, set current grid size to first available value
7273 if (grid_size_current[i][j] == NULL)
7274 grid_size_current[i][j] = grid_sizes[i][j];
7279 setup.touch.control_type = touch_control_current->identifier;
7280 setup.touch.move_distance = atoi(move_distance_current->identifier);
7281 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7282 setup.touch.transparency = atoi(transparency_current->identifier);
7284 for (i = 0; i < 2; i++)
7286 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7287 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7289 if (i == GRID_ACTIVE_NR())
7291 overlay.grid_xsize = setup.touch.grid_xsize[i];
7292 overlay.grid_ysize = setup.touch.grid_ysize[i];
7296 // needed for displaying value text instead of identifier
7297 touch_controls_text = touch_control_current->name;
7298 move_distance_text = move_distance_current->name;
7299 drop_distance_text = drop_distance_current->name;
7300 transparency_text = transparency_current->name;
7302 for (i = 0; i < 2; i++)
7303 for (j = 0; j < 2; j++)
7304 grid_size_text[i][j] = grid_size_current[i][j]->name;
7306 setup_mode = SETUP_MODE_TOUCH;
7311 static void execSetupArtwork(void)
7313 static ArtworkDirTree *gfx_last_valid = NULL;
7314 static ArtworkDirTree *snd_last_valid = NULL;
7315 static ArtworkDirTree *mus_last_valid = NULL;
7317 // current artwork directory may be invalid (level group, parent link)
7318 if (!validLevelSeries(artwork.gfx_current))
7319 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7320 if (!validLevelSeries(artwork.snd_current))
7321 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7322 if (!validLevelSeries(artwork.mus_current))
7323 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7325 // store valid artwork directory information
7326 gfx_last_valid = artwork.gfx_current;
7327 snd_last_valid = artwork.snd_current;
7328 mus_last_valid = artwork.mus_current;
7331 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7332 artwork.gfx_current->subdir,
7333 artwork.gfx_current->fullpath,
7334 artwork.gfx_current->basepath);
7337 setup.graphics_set = artwork.gfx_current->identifier;
7338 setup.sounds_set = artwork.snd_current->identifier;
7339 setup.music_set = artwork.mus_current->identifier;
7341 // needed if last screen (setup choice) changed graphics, sounds or music
7342 ReloadCustomArtwork(0);
7344 // needed for displaying artwork name instead of artwork identifier
7345 graphics_set_name = artwork.gfx_current->name;
7346 sounds_set_name = artwork.snd_current->name;
7347 music_set_name = artwork.mus_current->name;
7349 setup_mode = SETUP_MODE_ARTWORK;
7354 static void execSetupChooseGraphics(void)
7356 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7361 static void execSetupChooseSounds(void)
7363 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7368 static void execSetupChooseMusic(void)
7370 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7375 static void execSetupInput(void)
7377 setup_mode = SETUP_MODE_INPUT;
7382 static void execSetupShortcuts(void)
7384 setup_mode = SETUP_MODE_SHORTCUTS;
7389 static void execSetupShortcuts1(void)
7391 setup_mode = SETUP_MODE_SHORTCUTS_1;
7396 static void execSetupShortcuts2(void)
7398 setup_mode = SETUP_MODE_SHORTCUTS_2;
7403 static void execSetupShortcuts3(void)
7405 setup_mode = SETUP_MODE_SHORTCUTS_3;
7410 static void execSetupShortcuts4(void)
7412 setup_mode = SETUP_MODE_SHORTCUTS_4;
7417 static void execSetupShortcuts5(void)
7419 setup_mode = SETUP_MODE_SHORTCUTS_5;
7424 static void execExitSetup(void)
7426 SetGameStatus(GAME_MODE_MAIN);
7431 static void execSaveAndExitSetup(void)
7437 static void execGadgetNetworkServer(void)
7439 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7440 struct GadgetInfo *gi = screen_gadget[gadget_id];
7442 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7443 network_server_hostname[0] = '\0';
7445 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7449 ClickOnGadget(gi, MB_LEFTBUTTON);
7452 static void execOfferUploadTapes(void)
7457 static void ToggleNetworkModeIfNeeded(void)
7459 int font_title = FONT_TITLE_1;
7460 int font_foot = FC_BLUE;
7461 int ystart = mSY - SY + 16;
7462 int ybottom = mSY - SY + SYSIZE - 20;
7463 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7465 if (setup.network_mode == network.enabled)
7468 network.enabled = setup.network_mode;
7470 FadeOut(REDRAW_ALL);
7474 DrawTextSCentered(ystart, font_title, text);
7478 if (network.enabled)
7479 InitNetworkServer();
7481 DisconnectFromNetworkServer();
7483 DrawTextSCentered(ybottom, font_foot,
7484 "Press any key or button for setup menu");
7486 WaitForEventToContinue();
7491 static void ToggleGameSpeedsListIfNeeded(void)
7493 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7495 if (setup.game_speed_extended == using_game_speeds_extended)
7498 // try to match similar values when changing game speeds list
7499 if (setup.game_speed_extended)
7500 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7501 setup.game_frame_delay == 30 ? 29 :
7502 setup.game_frame_delay);
7504 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7505 setup.game_frame_delay == 16 ? 15 :
7506 setup.game_frame_delay >= 29 ? 30 :
7507 setup.game_frame_delay <= 10 ? 10 :
7508 setup.game_frame_delay);
7510 execSetupGame_setGameSpeeds(TRUE);
7515 static void ToggleUseApiServerIfNeeded(void)
7517 if (runtime.use_api_server == setup.use_api_server)
7520 runtime.use_api_server = setup.use_api_server;
7522 if (runtime.use_api_server)
7523 CheckApiServerTasks();
7526 static void ModifyGameSpeedIfNeeded(void)
7528 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7529 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7533 char *game_speed_text = "Fast";
7534 int game_speed_value = 15;
7536 if (setup.game_speed_extended)
7538 game_speed_text = "60 fps";
7539 game_speed_value = 16;
7542 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7544 // set game speed to existing list value that is fast enough for vsync
7545 setup.game_frame_delay = game_speed_value;
7547 execSetupGame_setGameSpeeds(TRUE);
7549 Request(message, REQ_CONFIRM);
7552 static void DisableVsyncIfNeeded(void)
7554 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7555 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7556 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7559 // disable vsync for the selected game speed to work
7560 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7562 execSetupGraphics_setVsyncModes(TRUE);
7564 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7570 void *related_value;
7571 } hide_related_entry_list[] =
7573 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7574 { &setup.scores_in_highscore_list, &scores_type_text },
7576 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7577 { &setup.game_frame_delay, &game_speed_text },
7579 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7580 { &setup.scroll_delay_value, &scroll_delay_text },
7582 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7583 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7585 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7586 { &setup.window_scaling_percent, &window_size_text },
7588 { &setup.window_scaling_quality, execSetupChooseScalingType },
7589 { &setup.window_scaling_quality, &scaling_type_text },
7591 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7592 { &setup.screen_rendering_mode, &rendering_mode_text },
7594 { &setup.vsync_mode, execSetupChooseVsyncMode },
7595 { &setup.vsync_mode, &vsync_mode_text },
7597 { &setup.graphics_set, execSetupChooseGraphics },
7598 { &setup.graphics_set, &graphics_set_name },
7600 { &setup.sounds_set, execSetupChooseSounds },
7601 { &setup.sounds_set, &sounds_set_name },
7603 { &setup.music_set, execSetupChooseMusic },
7604 { &setup.music_set, &music_set_name },
7606 { &setup.volume_simple, execSetupChooseVolumeSimple },
7607 { &setup.volume_simple, &volume_simple_text },
7609 { &setup.volume_loops, execSetupChooseVolumeLoops },
7610 { &setup.volume_loops, &volume_loops_text },
7612 { &setup.volume_music, execSetupChooseVolumeMusic },
7613 { &setup.volume_music, &volume_music_text },
7615 { &setup.touch.control_type, execSetupChooseTouchControls },
7616 { &setup.touch.control_type, &touch_controls_text },
7618 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7619 { &setup.touch.move_distance, &move_distance_text },
7621 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7622 { &setup.touch.drop_distance, &drop_distance_text },
7624 { &setup.touch.transparency, execSetupChooseTransparency },
7625 { &setup.touch.transparency, &transparency_text },
7627 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7628 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7630 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7631 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7633 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7634 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7636 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7637 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7639 { &setup.internal.menu_game, execSetupGame },
7640 { &setup.internal.menu_engines, execSetupEngines },
7641 { &setup.internal.menu_editor, execSetupEditor },
7642 { &setup.internal.menu_graphics, execSetupGraphics },
7643 { &setup.internal.menu_sound, execSetupSound },
7644 { &setup.internal.menu_artwork, execSetupArtwork },
7645 { &setup.internal.menu_input, execSetupInput },
7646 { &setup.internal.menu_touch, execSetupTouch },
7647 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7648 { &setup.internal.menu_exit, execExitSetup },
7649 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7654 void setHideRelatedSetupEntries(void)
7658 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7659 if (hideSetupEntry(hide_related_entry_list[i].value))
7660 setHideSetupEntry(hide_related_entry_list[i].related_value);
7663 static struct TokenInfo setup_info_main[] =
7665 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7666 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7667 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7668 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7669 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7670 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7671 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7672 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7673 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7674 { TYPE_EMPTY, NULL, "" },
7675 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7676 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7681 static struct TokenInfo setup_info_game[] =
7683 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7684 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7685 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7686 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7687 { TYPE_STRING, &network_server_text, "" },
7688 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7689 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7690 { TYPE_STRING, &scores_type_text, "" },
7691 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7692 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7693 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7694 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7695 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7696 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7697 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7698 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7699 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7700 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7701 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7702 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7703 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7704 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7705 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7706 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7707 { TYPE_STRING, &game_speed_text, "" },
7708 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7710 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7711 { TYPE_STRING, &scroll_delay_text, "" },
7713 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7714 { TYPE_STRING, &snapshot_mode_text, "" },
7715 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7716 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7717 { TYPE_EMPTY, NULL, "" },
7718 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7723 static struct TokenInfo setup_info_engines[] =
7725 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7726 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7727 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7728 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7729 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7730 { TYPE_EMPTY, NULL, "" },
7731 { TYPE_HEADLINE, NULL, "Supaplex" },
7732 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7733 { TYPE_EMPTY, NULL, "" },
7734 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7739 static struct TokenInfo setup_info_editor[] =
7742 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7743 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7744 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7745 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7746 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7747 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7748 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7749 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7750 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7751 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7753 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7754 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7756 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7758 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7759 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7760 { TYPE_EMPTY, NULL, "" },
7762 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7763 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7764 { TYPE_EMPTY, NULL, "" },
7766 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7767 { TYPE_EMPTY, NULL, "" },
7768 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7769 { TYPE_EMPTY, NULL, "" },
7770 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7775 static struct TokenInfo setup_info_graphics[] =
7777 #if !defined(PLATFORM_ANDROID)
7778 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7779 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7780 { TYPE_STRING, &window_size_text, "" },
7781 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7782 { TYPE_STRING, &scaling_type_text, "" },
7783 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7784 { TYPE_STRING, &rendering_mode_text, "" },
7787 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7788 { TYPE_STRING, &scroll_delay_text, "" },
7790 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7791 { TYPE_STRING, &vsync_mode_text, "" },
7792 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7793 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7794 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7795 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7796 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7797 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7798 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7799 { TYPE_EMPTY, NULL, "" },
7800 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7805 static struct TokenInfo setup_info_sound[] =
7807 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7808 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7809 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7810 { TYPE_EMPTY, NULL, "" },
7811 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7812 { TYPE_STRING, &volume_simple_text, "" },
7813 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7814 { TYPE_STRING, &volume_loops_text, "" },
7815 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7816 { TYPE_STRING, &volume_music_text, "" },
7817 { TYPE_EMPTY, NULL, "" },
7818 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7823 static struct TokenInfo setup_info_artwork[] =
7825 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7826 { TYPE_STRING, &graphics_set_name, "" },
7827 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7828 { TYPE_STRING, &sounds_set_name, "" },
7829 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7830 { TYPE_STRING, &music_set_name, "" },
7831 { TYPE_EMPTY, NULL, "" },
7832 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7833 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7834 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7835 { TYPE_EMPTY, NULL, "" },
7836 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7841 static struct TokenInfo setup_info_input[] =
7843 { TYPE_SWITCH, NULL, "Player:" },
7844 { TYPE_SWITCH, NULL, "Device:" },
7845 { TYPE_SWITCH, NULL, "" },
7846 { TYPE_SKIPPABLE, NULL, "" },
7847 { TYPE_EMPTY, NULL, "" },
7848 { TYPE_EMPTY, NULL, "" },
7849 { TYPE_EMPTY, NULL, "" },
7850 { TYPE_EMPTY, NULL, "" },
7851 { TYPE_EMPTY, NULL, "" },
7852 { TYPE_EMPTY, NULL, "" },
7853 { TYPE_EMPTY, NULL, "" },
7854 { TYPE_EMPTY, NULL, "" },
7855 { TYPE_SKIPPABLE, NULL, "" },
7856 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7861 static struct TokenInfo setup_info_touch[] =
7863 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7864 { TYPE_STRING, &touch_controls_text, "" },
7865 { TYPE_EMPTY, NULL, "" },
7866 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7871 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7873 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7874 { TYPE_STRING, &touch_controls_text, "" },
7875 { TYPE_EMPTY, NULL, "" },
7876 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7877 { TYPE_STRING, &grid_size_text[0][0], "" },
7878 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7879 { TYPE_STRING, &grid_size_text[0][1], "" },
7880 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7881 { TYPE_STRING, &transparency_text, "" },
7882 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7883 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7884 { TYPE_EMPTY, NULL, "" },
7885 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7886 { TYPE_EMPTY, NULL, "" },
7887 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7892 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7894 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7895 { TYPE_STRING, &touch_controls_text, "" },
7896 { TYPE_EMPTY, NULL, "" },
7897 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7898 { TYPE_STRING, &grid_size_text[1][0], "" },
7899 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7900 { TYPE_STRING, &grid_size_text[1][1], "" },
7901 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7902 { TYPE_STRING, &transparency_text, "" },
7903 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7904 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7905 { TYPE_EMPTY, NULL, "" },
7906 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7907 { TYPE_EMPTY, NULL, "" },
7908 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7913 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7915 setup_info_touch_virtual_buttons_0,
7916 setup_info_touch_virtual_buttons_1
7919 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7921 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7922 { TYPE_STRING, &touch_controls_text, "" },
7923 { TYPE_EMPTY, NULL, "" },
7924 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7925 { TYPE_STRING, &move_distance_text, "" },
7926 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7927 { TYPE_STRING, &drop_distance_text, "" },
7928 { TYPE_EMPTY, NULL, "" },
7929 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7934 static struct TokenInfo setup_info_shortcuts[] =
7936 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7937 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7938 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7939 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7940 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7941 { TYPE_EMPTY, NULL, "" },
7942 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7947 static struct TokenInfo setup_info_shortcuts_1[] =
7949 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7950 { TYPE_KEY, &setup.shortcut.save_game, "" },
7951 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7952 { TYPE_KEY, &setup.shortcut.load_game, "" },
7953 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7954 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7955 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7956 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7957 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7958 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7959 { TYPE_EMPTY, NULL, "" },
7960 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7961 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7962 { TYPE_EMPTY, NULL, "" },
7963 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7968 static struct TokenInfo setup_info_shortcuts_2[] =
7970 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7971 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7972 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7973 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7974 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7975 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7976 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7977 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7978 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7979 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7980 { TYPE_EMPTY, NULL, "" },
7981 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7986 static struct TokenInfo setup_info_shortcuts_3[] =
7988 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7989 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7990 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7991 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7992 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7993 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7994 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7995 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7996 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7997 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7998 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7999 { TYPE_KEY, &setup.shortcut.tape_play, "" },
8000 { TYPE_EMPTY, NULL, "" },
8001 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8006 static struct TokenInfo setup_info_shortcuts_4[] =
8008 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
8009 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
8010 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
8011 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
8012 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
8013 { TYPE_KEY, &setup.shortcut.sound_music, "" },
8014 { TYPE_EMPTY, NULL, "" },
8015 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8020 static struct TokenInfo setup_info_shortcuts_5[] =
8022 { TYPE_KEYTEXT, NULL, "Snap Left:", },
8023 { TYPE_KEY, &setup.shortcut.snap_left, "" },
8024 { TYPE_KEYTEXT, NULL, "Snap Right:", },
8025 { TYPE_KEY, &setup.shortcut.snap_right, "" },
8026 { TYPE_KEYTEXT, NULL, "Snap Up:", },
8027 { TYPE_KEY, &setup.shortcut.snap_up, "" },
8028 { TYPE_KEYTEXT, NULL, "Snap Down:", },
8029 { TYPE_KEY, &setup.shortcut.snap_down, "" },
8030 { TYPE_EMPTY, NULL, "" },
8031 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
8036 static Key getSetupKey(void)
8038 Key key = KSYM_UNDEFINED;
8039 boolean got_key_event = FALSE;
8041 while (!got_key_event)
8045 if (NextValidEvent(&event))
8049 case EVENT_KEYPRESS:
8051 key = GetEventKey((KeyEvent *)&event, TRUE);
8053 // press 'Escape' or 'Enter' to keep the existing key binding
8054 if (key == KSYM_Escape || key == KSYM_Return)
8055 key = KSYM_UNDEFINED; // keep old value
8057 got_key_event = TRUE;
8061 case EVENT_KEYRELEASE:
8062 key_joystick_mapping = 0;
8066 HandleOtherEvents(&event);
8077 static int getSetupValueFont(int type, void *value)
8079 if (type & TYPE_GHOSTED)
8080 return FONT_OPTION_OFF;
8081 else if (type & TYPE_KEY)
8082 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
8083 else if (type & TYPE_STRING)
8084 return FONT_VALUE_2;
8085 else if (type & TYPE_ECS_AGA)
8086 return FONT_VALUE_1;
8087 else if (type & TYPE_BOOLEAN_STYLE)
8088 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
8089 else if (type & TYPE_YES_NO_AUTO)
8090 return (*(int *)value == AUTO ? FONT_OPTION_ON :
8091 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
8092 else if (type & TYPE_PLAYER)
8093 return FONT_VALUE_1;
8095 return FONT_VALUE_1;
8098 static int getSetupValueFontNarrow(int type, int font_nr)
8100 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
8101 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
8102 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
8106 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
8108 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8109 struct TokenInfo *si = &setup_info[si_pos];
8110 boolean font_draw_xoffset_modified = FALSE;
8111 boolean scrollbar_needed = (num_setup_info < max_setup_info);
8112 int font_draw_xoffset_old = -1;
8113 int xoffset = (scrollbar_needed ? -1 : 0);
8114 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
8115 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
8116 int xpos = menu_screen_value_xpos;
8117 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
8118 int startx = mSX + xpos * 32;
8119 int starty = mSY + ypos * 32;
8120 int type = si->type;
8121 void *value = si->value;
8122 char *value_string = getSetupValue(type, value);
8123 int font_nr_default = getSetupValueFont(type, value);
8124 int font_width_default = getFontWidth(font_nr_default);
8125 int font_nr = font_nr_default;
8128 if (value_string == NULL)
8131 if (type & TYPE_KEY)
8133 xpos = MENU_SCREEN_START_XPOS;
8135 if (type & TYPE_QUERY)
8136 value_string = "<press key>";
8138 else if (type & TYPE_STRING)
8140 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
8142 xpos = MENU_SCREEN_START_XPOS;
8144 if (strlen(value_string) > max_value_len)
8145 value_string[max_value_len] = '\0';
8147 else if (type & TYPE_YES_NO_AUTO)
8149 xpos = menu_screen_value_xpos - 1;
8151 else if (type & TYPE_PLAYER)
8153 int displayed_player_nr = *(int *)value + 1;
8155 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
8158 startx = mSX + xpos * 32;
8159 starty = mSY + ypos * 32;
8161 // special check if right-side setup values moved left due to scrollbar
8162 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
8164 int max_menu_text_length = 26; // maximum text length for classic menu
8165 int font_xoffset = getFontDrawOffsetX(font_nr);
8166 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8167 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8168 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8169 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
8171 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
8173 // when using narrow font, left-shifting text "auto" not needed
8174 if (type & TYPE_YES_NO_AUTO)
8178 startx = mSX + xpos * 32;
8180 font_nr = getSetupValueFontNarrow(type, font_nr);
8184 // downward compatibility correction for Juergen Bonhagen's menu settings
8185 if (setup_mode != SETUP_MODE_INPUT)
8187 int max_menu_text_length_big = (menu_screen_value_xpos -
8188 MENU_SCREEN_START_XPOS);
8189 int max_menu_text_length_medium = max_menu_text_length_big * 2;
8190 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
8191 int font1_xoffset = getFontDrawOffsetX(font_nr);
8192 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
8193 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8194 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8195 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8196 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8197 boolean correct_font_draw_xoffset = FALSE;
8199 if (xpos == MENU_SCREEN_START_XPOS &&
8200 startx + font1_xoffset < text_startx + text_font_xoffset)
8201 correct_font_draw_xoffset = TRUE;
8203 if (xpos == menu_screen_value_xpos &&
8204 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8205 correct_font_draw_xoffset = TRUE;
8207 // check if setup value would overlap with setup text when printed
8208 // (this can happen for extreme/wrong values for font draw offset)
8209 if (correct_font_draw_xoffset)
8211 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8212 font_draw_xoffset_modified = TRUE;
8214 if (type & TYPE_KEY)
8215 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8216 else if (!(type & TYPE_STRING))
8217 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8218 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8222 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
8223 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
8225 DrawText(startx, starty, value_string, font_nr);
8227 if (type & TYPE_PLAYER)
8229 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8230 int player_nr = *(int *)value;
8231 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8232 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8233 int startx2 = startx + xoff;
8234 int starty2 = starty + yoff;
8236 if (DrawingOnBackground(startx2, starty2))
8237 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8239 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8240 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8243 if (font_draw_xoffset_modified)
8244 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8247 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8249 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8250 struct TokenInfo *si = &setup_info[si_pos];
8252 if (si->type & TYPE_BOOLEAN_STYLE)
8254 *(boolean *)si->value ^= TRUE;
8256 else if (si->type & TYPE_YES_NO_AUTO)
8260 (*(int *)si->value == AUTO ? TRUE :
8261 *(int *)si->value == TRUE ? FALSE : AUTO) :
8262 (*(int *)si->value == TRUE ? AUTO :
8263 *(int *)si->value == AUTO ? FALSE : TRUE));
8265 else if (si->type & TYPE_KEY)
8269 si->type |= TYPE_QUERY;
8270 drawSetupValue(screen_pos, setup_info_pos_raw);
8271 si->type &= ~TYPE_QUERY;
8273 key = getSetupKey();
8274 if (key != KSYM_UNDEFINED)
8275 *(Key *)si->value = key;
8277 else if (si->type & TYPE_PLAYER)
8279 int player_nr = *(int *)si->value;
8284 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8286 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8289 drawSetupValue(screen_pos, setup_info_pos_raw);
8291 // fullscreen state may have changed at this point
8292 if (si->value == &setup.fullscreen)
8293 ToggleFullscreenIfNeeded();
8295 // network mode may have changed at this point
8296 if (si->value == &setup.network_mode)
8297 ToggleNetworkModeIfNeeded();
8299 // API server mode may have changed at this point
8300 if (si->value == &setup.use_api_server)
8301 ToggleUseApiServerIfNeeded();
8303 // game speed list may have changed at this point
8304 if (si->value == &setup.game_speed_extended)
8305 ToggleGameSpeedsListIfNeeded();
8308 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8310 static struct TokenInfo *setup_info_final = NULL;
8315 // determine maximum list size of target list
8316 while (setup_info_orig[list_size++].type != 0);
8318 // free, allocate and clear memory for target list
8319 checked_free(setup_info_final);
8320 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8322 // copy setup info list without setup entries marked as hidden
8323 for (i = 0; setup_info_orig[i].type != 0; i++)
8325 // skip setup entries configured to be hidden
8326 if (hideSetupEntry(setup_info_orig[i].value))
8329 // skip skippable setup entries if screen is lower than usual
8330 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8331 setup_info_orig[i].type == TYPE_SKIPPABLE)
8334 setup_info_final[list_pos++] = setup_info_orig[i];
8337 return setup_info_final;
8340 static void DrawSetupScreen_Generic(void)
8342 int fade_mask = REDRAW_FIELD;
8343 boolean redraw_all = FALSE;
8344 char *title_string = NULL;
8348 fade_mask = REDRAW_ALL;
8351 FadeMenuSoundsAndMusic();
8353 FreeScreenGadgets();
8354 CreateScreenGadgets();
8356 if (redraw_mask & REDRAW_ALL)
8361 // needed if different viewport properties defined for setup screen
8362 ChangeViewportPropertiesIfNeeded();
8364 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8368 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8370 if (setup_mode == SETUP_MODE_MAIN)
8372 setup_info = setup_info_main;
8373 title_string = STR_SETUP_MAIN;
8375 else if (setup_mode == SETUP_MODE_GAME)
8377 setup_info = setup_info_game;
8378 title_string = STR_SETUP_GAME;
8380 else if (setup_mode == SETUP_MODE_ENGINES)
8382 setup_info = setup_info_engines;
8383 title_string = STR_SETUP_ENGINES;
8385 else if (setup_mode == SETUP_MODE_EDITOR)
8387 setup_info = setup_info_editor;
8388 title_string = STR_SETUP_EDITOR;
8390 else if (setup_mode == SETUP_MODE_GRAPHICS)
8392 setup_info = setup_info_graphics;
8393 title_string = STR_SETUP_GRAPHICS;
8395 else if (setup_mode == SETUP_MODE_SOUND)
8397 setup_info = setup_info_sound;
8398 title_string = STR_SETUP_SOUND;
8400 else if (setup_mode == SETUP_MODE_ARTWORK)
8402 setup_info = setup_info_artwork;
8403 title_string = STR_SETUP_ARTWORK;
8405 else if (setup_mode == SETUP_MODE_TOUCH)
8407 setup_info = setup_info_touch;
8408 title_string = STR_SETUP_TOUCH;
8410 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8411 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8412 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8413 setup_info = setup_info_touch_wipe_gestures;
8415 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8417 setup_info = setup_info_shortcuts;
8418 title_string = STR_SETUP_SHORTCUTS;
8420 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8422 setup_info = setup_info_shortcuts_1;
8423 title_string = STR_SETUP_SHORTCUTS;
8425 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8427 setup_info = setup_info_shortcuts_2;
8428 title_string = STR_SETUP_SHORTCUTS;
8430 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8432 setup_info = setup_info_shortcuts_3;
8433 title_string = STR_SETUP_SHORTCUTS;
8435 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8437 setup_info = setup_info_shortcuts_4;
8438 title_string = STR_SETUP_SHORTCUTS;
8440 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8442 setup_info = setup_info_shortcuts_5;
8443 title_string = STR_SETUP_SHORTCUTS;
8446 // use modified setup info without setup entries marked as hidden
8447 setup_info = getSetupInfoFinal(setup_info);
8449 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8451 // determine maximal number of setup entries that can be displayed on screen
8453 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8456 // determine maximal number of setup entries available for this setup screen
8458 for (i = 0; setup_info[i].type != 0; i++)
8461 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8463 MapScreenGadgets(max_setup_info);
8466 redraw_mask = fade_mask = REDRAW_ALL;
8468 DrawMaskedBorder(fade_mask);
8473 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8475 menu_info = setup_info;
8477 HandleMenuScreen(mx, my, dx, dy, button,
8478 setup_mode, num_setup_info, max_setup_info);
8481 static void DrawSetupScreen_Input(void)
8485 FadeOut(REDRAW_FIELD);
8489 setup_info = getSetupInfoFinal(setup_info_input);
8491 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8493 for (i = 0; setup_info[i].type != 0; i++)
8495 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8496 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8497 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8498 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8499 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8500 initCursor(i, IMG_MENU_BUTTON);
8502 DrawCursorAndText_Setup(i, -1, FALSE);
8505 // create gadgets for setup input menu screen
8506 FreeScreenGadgets();
8507 CreateScreenGadgets();
8509 // map gadgets for setup input menu screen
8510 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8512 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8514 FadeIn(REDRAW_FIELD);
8517 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8519 if (device_name == NULL)
8522 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8525 if (strlen(device_name) > 1)
8527 char c1 = device_name[strlen(device_name) - 1];
8528 char c2 = device_name[strlen(device_name) - 2];
8530 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8531 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8534 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8535 strlen(device_name));
8538 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8541 static struct SetupKeyboardInfo custom_key;
8548 { &custom_key.left, "Axis/Pad Left" },
8549 { &custom_key.right, "Axis/Pad Right" },
8550 { &custom_key.up, "Axis/Pad Up" },
8551 { &custom_key.down, "Axis/Pad Down" },
8552 { &custom_key.snap, "Button 1/A/X" },
8553 { &custom_key.drop, "Button 2/B/Y" }
8555 static char *joystick_name[MAX_PLAYERS] =
8562 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8563 int font_nr_info = FONT_MENU_1;
8564 int font_nr_name = FONT_VALUE_OLD;
8565 int font_nr_on = FONT_VALUE_1;
8566 int font_nr_off = FONT_VALUE_OLD;
8569 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8571 font_nr_info = FONT_MENU_2;
8572 font_nr_on = FONT_VALUE_NARROW;
8573 font_nr_off = FONT_VALUE_OLD_NARROW;
8576 custom_key = setup.input[player_nr].key;
8578 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8579 FONT_INPUT_1_ACTIVE);
8581 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8583 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8584 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8586 if (setup.input[player_nr].use_joystick)
8588 char *device_name = setup.input[player_nr].joy.device_name;
8589 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8590 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8591 char *text = joystick_name[joystick_nr];
8592 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8594 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8595 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8599 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8600 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8603 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8604 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8608 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8609 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8610 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8611 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8613 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8614 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8615 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8616 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8617 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8618 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8620 for (i = 0; i < 6; i++)
8622 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8624 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8626 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8627 (setup.input[player_nr].use_joystick ?
8629 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8633 static int input_player_nr = 0;
8635 static void HandleSetupScreen_Input_Player(int step, int direction)
8637 int old_player_nr = input_player_nr;
8640 new_player_nr = old_player_nr + step * direction;
8641 if (new_player_nr < 0)
8643 if (new_player_nr > MAX_PLAYERS - 1)
8644 new_player_nr = MAX_PLAYERS - 1;
8646 if (new_player_nr != old_player_nr)
8648 input_player_nr = new_player_nr;
8650 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8654 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8656 static int choice = 0;
8659 int pos_start = SETUPINPUT_SCREEN_POS_START;
8660 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8661 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8662 int pos_end = SETUPINPUT_SCREEN_POS_END;
8664 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8668 for (i = 0; setup_info_input[i].type != 0; i++)
8670 // adjust menu structure according to skipped setup entries
8671 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8679 if (button == MB_MENU_INITIALIZE)
8681 // input setup menu may have changed size due to graphics configuration
8682 if (choice >= pos_empty1)
8685 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8687 DrawCursorAndText_Setup(choice, -1, TRUE);
8691 else if (button == MB_MENU_LEAVE)
8693 setup_mode = SETUP_MODE_MAIN;
8700 if (mx || my) // mouse input
8702 x = (mx - mSX) / 32;
8703 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8705 else if (dx || dy) // keyboard input
8707 if (dx && choice == 0)
8708 x = (dx < 0 ? 10 : 12);
8709 else if ((dx && choice == 1) ||
8710 (dx == -1 && choice == pos_end))
8711 button = MB_MENU_CHOICE;
8715 if (y >= pos_empty1 && y <= pos_empty2)
8716 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8719 if (y == 0 && dx != 0 && button)
8721 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8723 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8724 y >= pos_start && y <= pos_end &&
8725 !(y >= pos_empty1 && y <= pos_empty2))
8731 DrawCursorAndText_Setup(choice, -1, FALSE);
8732 DrawCursorAndText_Setup(y, -1, TRUE);
8734 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8743 char *device_name = setup.input[input_player_nr].joy.device_name;
8745 if (!setup.input[input_player_nr].use_joystick)
8747 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8749 setJoystickDeviceToNr(device_name, new_device_nr);
8750 setup.input[input_player_nr].use_joystick = TRUE;
8754 int device_nr = getJoystickNrFromDeviceName(device_name);
8755 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8757 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8758 setup.input[input_player_nr].use_joystick = FALSE;
8760 setJoystickDeviceToNr(device_name, new_device_nr);
8763 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8767 if (setup.input[input_player_nr].use_joystick)
8768 ConfigureJoystick(input_player_nr);
8770 CustomizeKeyboard(input_player_nr);
8772 else if (y == pos_end)
8778 setup_mode = SETUP_MODE_MAIN;
8785 static boolean CustomizeKeyboardMain(int player_nr)
8789 boolean finished = FALSE;
8790 static struct SetupKeyboardInfo custom_key;
8795 } customize_step[] =
8797 { &custom_key.left, "Move Left" },
8798 { &custom_key.right, "Move Right" },
8799 { &custom_key.up, "Move Up" },
8800 { &custom_key.down, "Move Down" },
8801 { &custom_key.snap, "Snap Field" },
8802 { &custom_key.drop, "Drop Element" }
8804 int font_nr_old = FONT_VALUE_OLD;
8805 int font_nr_new = FONT_VALUE_1;
8806 boolean success = FALSE;
8808 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8810 font_nr_old = FONT_VALUE_OLD_NARROW;
8811 font_nr_new = FONT_VALUE_NARROW;
8814 // read existing key bindings from player setup
8815 custom_key = setup.input[player_nr].key;
8818 FadeOut(REDRAW_FIELD);
8822 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8825 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8826 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8827 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8828 "Key:", FONT_INPUT_1_ACTIVE);
8829 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8830 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8832 FadeIn(REDRAW_FIELD);
8838 if (NextValidEvent(&event))
8842 case EVENT_KEYPRESS:
8844 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8846 // press 'Escape' to abort and keep the old key bindings
8847 if (key == KSYM_Escape)
8849 FadeSkipNextFadeIn();
8856 // press 'Enter' to keep the existing key binding
8857 if (key == KSYM_Return)
8858 key = *customize_step[step_nr].key;
8860 // check if key already used
8861 for (i = 0; i < step_nr; i++)
8862 if (*customize_step[i].key == key)
8867 // got new key binding
8868 *customize_step[step_nr].key = key;
8869 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8871 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8872 getKeyNameFromKey(key), font_nr_new);
8875 // un-highlight last query
8876 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8877 customize_step[step_nr - 1].text, FONT_MENU_1);
8878 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8879 "Key:", FONT_MENU_1);
8881 // all keys configured
8890 // query next key binding
8891 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8892 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8893 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8894 "Key:", FONT_INPUT_1_ACTIVE);
8895 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8896 getKeyNameFromKey(*customize_step[step_nr].key),
8901 case EVENT_KEYRELEASE:
8902 key_joystick_mapping = 0;
8906 HandleOtherEvents(&event);
8914 // write new key bindings back to player setup, if successfully finished
8916 setup.input[player_nr].key = custom_key;
8921 void CustomizeKeyboard(int player_nr)
8923 boolean success = CustomizeKeyboardMain(player_nr);
8927 int font_nr = FONT_TITLE_1;
8928 int font_height = getFontHeight(font_nr);
8929 int ypos1 = SYSIZE / 2 - font_height * 2;
8930 int ypos2 = SYSIZE / 2 - font_height * 1;
8931 unsigned int wait_frame_delay = 0;
8932 unsigned int wait_frame_delay_value = 2000;
8934 ResetDelayCounter(&wait_frame_delay);
8938 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8939 DrawTextSCentered(ypos2, font_nr, "configured!");
8941 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8947 DrawSetupScreen_Input();
8950 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8952 #define MARKER_BUTTON 1
8953 #define MARKER_AXIS_X 2
8954 #define MARKER_AXIS_Y 3
8956 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8958 static boolean bitmaps_initialized = FALSE;
8959 boolean screen_initialized = FALSE;
8960 static Bitmap *controller, *button, *axis_x, *axis_y;
8962 boolean success = TRUE;
8963 boolean done = FALSE, next = FALSE;
8965 int alpha = 200, alpha_step = -1;
8966 int alpha_ticks = 0;
8967 char mapping[4096], temp[256];
8968 int font_name = MENU_SETUP_FONT_TITLE;
8969 int font_info = MENU_SETUP_FONT_TEXT;
8970 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8971 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8972 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8973 int ystep_name = getMenuTextStep(spacing_name, font_name);
8974 int ystep_line = getMenuTextStep(spacing_line, font_info);
8975 int ystep_para = getMenuTextStep(spacing_para, font_info);
8983 int axis, button, hat, hat_value;
8986 *step, *prev_step, steps[] =
8988 { 356, 155, MARKER_BUTTON, "a", },
8989 { 396, 122, MARKER_BUTTON, "b", },
8990 { 320, 125, MARKER_BUTTON, "x", },
8991 { 358, 95, MARKER_BUTTON, "y", },
8992 { 162, 125, MARKER_BUTTON, "back", },
8993 { 216, 125, MARKER_BUTTON, "guide", },
8994 { 271, 125, MARKER_BUTTON, "start", },
8995 { 110, 200, MARKER_BUTTON, "dpleft", },
8996 { 146, 228, MARKER_BUTTON, "dpdown", },
8997 { 178, 200, MARKER_BUTTON, "dpright", },
8998 { 146, 172, MARKER_BUTTON, "dpup", },
8999 { 50, 40, MARKER_BUTTON, "leftshoulder", },
9000 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
9001 { 382, 40, MARKER_BUTTON, "rightshoulder", },
9002 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
9003 { 73, 141, MARKER_BUTTON, "leftstick", },
9004 { 282, 210, MARKER_BUTTON, "rightstick", },
9005 { 73, 141, MARKER_AXIS_X, "leftx", },
9006 { 73, 141, MARKER_AXIS_Y, "lefty", },
9007 { 282, 210, MARKER_AXIS_X, "rightx", },
9008 { 282, 210, MARKER_AXIS_Y, "righty", },
9011 unsigned int event_frame_delay = 0;
9012 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
9014 ResetDelayCounter(&event_frame_delay);
9016 if (!bitmaps_initialized)
9018 controller = LoadCustomImage("joystick/controller.png");
9019 button = LoadCustomImage("joystick/button.png");
9020 axis_x = LoadCustomImage("joystick/axis_x.png");
9021 axis_y = LoadCustomImage("joystick/axis_y.png");
9023 bitmaps_initialized = TRUE;
9026 name = getFormattedJoystickName(SDL_JoystickName(joystick));
9029 // print info about the joystick we are watching
9030 Debug("joystick", "watching joystick %d: (%s)",
9031 SDL_JoystickInstanceID(joystick), name);
9032 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
9033 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
9034 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
9037 // initialize mapping with GUID and name
9038 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
9040 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
9041 temp, name, SDL_GetPlatform());
9043 // loop through all steps (buttons and axes), getting joystick events
9044 for (i = 0; i < SDL_arraysize(steps) && !done;)
9046 Bitmap *marker = button; // initialize with reliable default value
9049 strcpy(step->mapping, mapping);
9053 step->hat_value = -1;
9055 marker = (step->marker == MARKER_BUTTON ? button :
9056 step->marker == MARKER_AXIS_X ? axis_x :
9057 step->marker == MARKER_AXIS_Y ? axis_y : marker);
9061 while (!done && !next)
9063 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
9064 alpha_ticks = SDL_GetTicks();
9071 else if (alpha < 128)
9077 int controller_x = SX + (SXSIZE - controller->width) / 2;
9078 int controller_y = SY + ystep_line;
9080 int marker_x = controller_x + step->x;
9081 int marker_y = controller_y + step->y;
9083 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
9084 int ystart2 = ystart1 + ystep_name + ystep_line;
9088 DrawTextSCentered(ystart1, font_name, name);
9090 DrawTextSCentered(ystart2, font_info,
9091 "Press buttons and move axes on");
9092 ystart2 += ystep_line;
9093 DrawTextSCentered(ystart2, font_info,
9094 "your controller when indicated.");
9095 ystart2 += ystep_line;
9096 DrawTextSCentered(ystart2, font_info,
9097 "(Your controller may look different.)");
9098 ystart2 += ystep_para;
9100 #if defined(PLATFORM_ANDROID)
9101 DrawTextSCentered(ystart2, font_info,
9102 "To correct a mistake,");
9103 ystart2 += ystep_line;
9104 DrawTextSCentered(ystart2, font_info,
9105 "press the 'back' button.");
9106 ystart2 += ystep_line;
9107 DrawTextSCentered(ystart2, font_info,
9108 "To skip a button or axis,");
9109 ystart2 += ystep_line;
9110 DrawTextSCentered(ystart2, font_info,
9111 "press the 'menu' button.");
9113 DrawTextSCentered(ystart2, font_info,
9114 "To correct a mistake,");
9115 ystart2 += ystep_line;
9116 DrawTextSCentered(ystart2, font_info,
9117 "press the 'backspace' key.");
9118 ystart2 += ystep_line;
9119 DrawTextSCentered(ystart2, font_info,
9120 "To skip a button or axis,");
9121 ystart2 += ystep_line;
9122 DrawTextSCentered(ystart2, font_info,
9123 "press the 'return' key.");
9124 ystart2 += ystep_line;
9125 DrawTextSCentered(ystart2, font_info,
9126 "To exit, press the 'escape' key.");
9129 BlitBitmapMasked(controller, drawto, 0, 0,
9130 controller->width, controller->height,
9131 controller_x, controller_y);
9133 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
9134 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
9136 BlitBitmapMasked(marker, drawto, 0, 0,
9137 marker->width, marker->height,
9138 marker_x, marker_y);
9140 if (!screen_initialized)
9141 FadeIn(REDRAW_FIELD);
9145 screen_initialized = TRUE;
9147 while (NextValidEvent(&event))
9151 case SDL_JOYAXISMOTION:
9152 if (event.jaxis.value > 20000 ||
9153 event.jaxis.value < -20000)
9155 for (j = 0; j < i; j++)
9156 if (steps[j].axis == event.jaxis.axis)
9161 if (step->marker != MARKER_AXIS_X &&
9162 step->marker != MARKER_AXIS_Y)
9165 step->axis = event.jaxis.axis;
9166 strcat(mapping, step->field);
9167 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
9168 strcat(mapping, temp);
9176 case SDL_JOYHATMOTION:
9177 // ignore centering; we're probably just coming back
9178 // to the center from the previous item we set
9179 if (event.jhat.value == SDL_HAT_CENTERED)
9182 for (j = 0; j < i; j++)
9183 if (steps[j].hat == event.jhat.hat &&
9184 steps[j].hat_value == event.jhat.value)
9189 step->hat = event.jhat.hat;
9190 step->hat_value = event.jhat.value;
9191 strcat(mapping, step->field);
9192 snprintf(temp, sizeof(temp), ":h%u.%u,",
9193 event.jhat.hat, event.jhat.value );
9194 strcat(mapping, temp);
9201 case SDL_JOYBALLMOTION:
9204 case SDL_JOYBUTTONUP:
9205 for (j = 0; j < i; j++)
9206 if (steps[j].button == event.jbutton.button)
9211 step->button = event.jbutton.button;
9212 strcat(mapping, step->field);
9213 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9214 strcat(mapping, temp);
9221 case SDL_FINGERDOWN:
9222 case SDL_MOUSEBUTTONDOWN:
9230 if (event.key.keysym.sym == KSYM_BackSpace ||
9231 event.key.keysym.sym == KSYM_Back)
9243 prev_step = &steps[i - 1];
9244 strcpy(mapping, prev_step->mapping);
9251 if (event.key.keysym.sym == KSYM_space ||
9252 event.key.keysym.sym == KSYM_Return ||
9253 event.key.keysym.sym == KSYM_Menu)
9262 if (event.key.keysym.sym == KSYM_Escape)
9272 program.exit_function(0);
9279 // do not handle events for longer than standard frame delay period
9280 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9289 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9292 // activate mapping for this game
9293 SDL_GameControllerAddMapping(mapping);
9295 // save mapping to personal mappings
9296 SaveSetup_AddGameControllerMapping(mapping);
9299 // wait until the last pending event was removed from event queue
9300 while (NextValidEvent(&event));
9305 static int ConfigureJoystickMain(int player_nr)
9307 char *device_name = setup.input[player_nr].joy.device_name;
9308 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9309 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9310 int success = FALSE;
9313 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9314 return JOYSTICK_NOT_AVAILABLE;
9316 if (!joystick_active || !setup.input[player_nr].use_joystick)
9317 return JOYSTICK_NOT_AVAILABLE;
9320 FadeOut(REDRAW_FIELD);
9322 // close all joystick devices (potentially opened as game controllers)
9323 for (i = 0; i < SDL_NumJoysticks(); i++)
9324 SDLCloseJoystick(i);
9326 // open joystick device as plain joystick to configure as game controller
9327 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9329 // as the joystick was successfully opened before, this should not happen
9330 if (joystick == NULL)
9333 // create new game controller mapping (buttons and axes) for joystick device
9334 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9336 // close joystick (and maybe re-open as configured game controller later)
9337 SDL_JoystickClose(joystick);
9339 // re-open all joystick devices (potentially as game controllers)
9340 for (i = 0; i < SDL_NumJoysticks(); i++)
9343 // clear all joystick input actions for all joystick devices
9344 SDLClearJoystickState();
9346 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9349 void ConfigureJoystick(int player_nr)
9351 boolean state = ConfigureJoystickMain(player_nr);
9353 if (state != JOYSTICK_NOT_CONFIGURED)
9355 boolean success = (state == JOYSTICK_CONFIGURED);
9356 char message1[MAX_OUTPUT_LINESIZE + 1];
9357 char *message2 = (success ? "configured!" : "not available!");
9358 char *device_name = setup.input[player_nr].joy.device_name;
9359 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9360 int font_nr = FONT_TITLE_1;
9361 int font_height = getFontHeight(font_nr);
9362 int ypos1 = SYSIZE / 2 - font_height * 2;
9363 int ypos2 = SYSIZE / 2 - font_height * 1;
9364 unsigned int wait_frame_delay = 0;
9365 unsigned int wait_frame_delay_value = 2000;
9367 ResetDelayCounter(&wait_frame_delay);
9371 sprintf(message1, "Joystick %d", nr);
9373 DrawTextSCentered(ypos1, font_nr, message1);
9374 DrawTextSCentered(ypos2, font_nr, message2);
9376 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9382 DrawSetupScreen_Input();
9385 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9387 if (y < video.screen_height / 3)
9389 // remap touch gadgets to access upper part of the screen
9390 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9391 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9393 else if (y > 2 * video.screen_height / 3)
9395 // remap touch gadgets to access lower part of the screen
9396 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9397 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9401 static boolean ConfigureVirtualButtonsMain(void)
9403 static char *customize_step_text[] =
9412 char grid_button[] =
9414 CHAR_GRID_BUTTON_LEFT,
9415 CHAR_GRID_BUTTON_RIGHT,
9416 CHAR_GRID_BUTTON_UP,
9417 CHAR_GRID_BUTTON_DOWN,
9418 CHAR_GRID_BUTTON_SNAP,
9419 CHAR_GRID_BUTTON_DROP
9428 int font_nr = FONT_INPUT_1_ACTIVE;
9429 int font_height = getFontHeight(font_nr);
9430 int ypos1 = SYSIZE / 2 - font_height * 2;
9431 int ypos2 = SYSIZE / 2 - font_height * 1;
9432 boolean success = FALSE;
9433 boolean finished = FALSE;
9435 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9436 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9437 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9438 boolean set_grid_button = FALSE;
9439 int nr = GRID_ACTIVE_NR();
9442 for (x = 0; x < MAX_GRID_XSIZE; x++)
9443 for (y = 0; y < MAX_GRID_YSIZE; y++)
9444 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9446 overlay.grid_button_highlight = grid_button[step_nr];
9451 FadeOut(REDRAW_FIELD);
9455 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9456 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9457 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9459 FadeIn(REDRAW_FIELD);
9461 SetOverlayShowGrid(TRUE);
9463 // map gadgets for setup touch buttons menu screen
9464 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9470 while (NextValidEvent(&event))
9472 int action = ACTION_NONE;
9474 // ---------- handle events and set the resulting action ----------
9480 UserEvent *user = (UserEvent *)&event;
9481 int id = user->value1;
9483 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9484 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9485 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9486 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9491 case EVENT_KEYPRESS:
9493 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9495 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9496 key == KSYM_BackSpace ||
9497 key == KSYM_Back ? ACTION_BACK :
9498 key == KSYM_Return ||
9500 key == KSYM_space ? ACTION_NEXT :
9505 case EVENT_KEYRELEASE:
9506 key_joystick_mapping = 0;
9509 case EVENT_BUTTONPRESS:
9510 case EVENT_BUTTONRELEASE:
9512 ButtonEvent *button = (ButtonEvent *)&event;
9514 motion_status = FALSE;
9516 if (button->type == EVENT_BUTTONPRESS)
9517 button_status = button->button;
9519 button_status = MB_RELEASED;
9521 if (HandleGadgets(button->x, button->y, button_status))
9523 // do not handle this button event anymore
9527 button->x += video.screen_xoffset;
9528 button->y += video.screen_yoffset;
9530 x = button->x * overlay.grid_xsize / video.screen_width;
9531 y = button->y * overlay.grid_ysize / video.screen_height;
9533 if (button->type == EVENT_BUTTONPRESS)
9536 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9537 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9539 set_grid_button = TRUE;
9542 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9546 case EVENT_MOTIONNOTIFY:
9548 MotionEvent *motion = (MotionEvent *)&event;
9550 motion_status = TRUE;
9552 if (HandleGadgets(motion->x, motion->y, button_status))
9554 // do not handle this button event anymore
9558 motion->x += video.screen_xoffset;
9559 motion->y += video.screen_yoffset;
9561 x = motion->x * overlay.grid_xsize / video.screen_width;
9562 y = motion->y * overlay.grid_ysize / video.screen_height;
9564 set_grid_button = TRUE;
9566 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9570 case SDL_WINDOWEVENT:
9571 HandleWindowEvent((WindowEvent *) &event);
9573 // check if device has been rotated
9574 if (nr != GRID_ACTIVE_NR())
9576 nr = GRID_ACTIVE_NR();
9578 for (x = 0; x < MAX_GRID_XSIZE; x++)
9579 for (y = 0; y < MAX_GRID_YSIZE; y++)
9580 grid_button_old[x][y] = grid_button_tmp[x][y] =
9581 overlay.grid_button[x][y];
9586 case SDL_APP_WILLENTERBACKGROUND:
9587 case SDL_APP_DIDENTERBACKGROUND:
9588 case SDL_APP_WILLENTERFOREGROUND:
9589 case SDL_APP_DIDENTERFOREGROUND:
9590 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9594 HandleOtherEvents(&event);
9598 // ---------- perform action set by handling events ----------
9600 if (action == ACTION_ESCAPE)
9602 // abort and restore the old key bindings
9604 for (x = 0; x < MAX_GRID_XSIZE; x++)
9605 for (y = 0; y < MAX_GRID_YSIZE; y++)
9606 overlay.grid_button[x][y] = grid_button_old[x][y];
9608 FadeSkipNextFadeIn();
9612 else if (action == ACTION_BACK)
9614 // keep the configured key bindings and go to previous page
9620 FadeSkipNextFadeIn();
9625 else if (action == ACTION_NEXT)
9627 // keep the configured key bindings and go to next page
9631 // all virtual buttons configured
9639 if (action != ACTION_NONE && !finished)
9641 for (x = 0; x < MAX_GRID_XSIZE; x++)
9642 for (y = 0; y < MAX_GRID_YSIZE; y++)
9643 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9645 overlay.grid_button_highlight = grid_button[step_nr];
9647 // configure next virtual button
9651 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9652 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9653 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9656 if (set_grid_button)
9658 overlay.grid_button[x][y] =
9659 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9660 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9661 grid_button_tmp[x][y]);
9663 set_grid_button = FALSE;
9670 for (x = 0; x < MAX_GRID_XSIZE; x++)
9671 for (y = 0; y < MAX_GRID_YSIZE; y++)
9672 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9674 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9676 SetOverlayShowGrid(FALSE);
9681 void ConfigureVirtualButtons(void)
9683 boolean success = ConfigureVirtualButtonsMain();
9685 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9686 SCREEN_MASK_TOUCH2);
9690 int font_nr = FONT_TITLE_1;
9691 int font_height = getFontHeight(font_nr);
9692 int ypos1 = SYSIZE / 2 - font_height * 2;
9693 int ypos2 = SYSIZE / 2 - font_height * 1;
9694 unsigned int wait_frame_delay = 0;
9695 unsigned int wait_frame_delay_value = 2000;
9697 ResetDelayCounter(&wait_frame_delay);
9701 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9702 DrawTextSCentered(ypos2, font_nr, "configured!");
9704 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9711 void DrawSetupScreen(void)
9716 if (setup_mode == SETUP_MODE_INPUT)
9717 DrawSetupScreen_Input();
9718 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9719 DrawChooseTree(&scores_type_current);
9720 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9721 DrawChooseTree(&game_speed_current);
9722 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9723 DrawChooseTree(&scroll_delay_current);
9724 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9725 DrawChooseTree(&snapshot_mode_current);
9726 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9727 DrawChooseTree(&window_size_current);
9728 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9729 DrawChooseTree(&scaling_type_current);
9730 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9731 DrawChooseTree(&rendering_mode_current);
9732 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9733 DrawChooseTree(&vsync_mode_current);
9734 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9735 DrawChooseTree(&artwork.gfx_current);
9736 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9737 DrawChooseTree(&artwork.snd_current);
9738 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9739 DrawChooseTree(&artwork.mus_current);
9740 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9741 DrawChooseTree(&volume_simple_current);
9742 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9743 DrawChooseTree(&volume_loops_current);
9744 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9745 DrawChooseTree(&volume_music_current);
9746 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9747 DrawChooseTree(&touch_control_current);
9748 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9749 DrawChooseTree(&move_distance_current);
9750 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9751 DrawChooseTree(&drop_distance_current);
9752 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9753 DrawChooseTree(&transparency_current);
9754 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9755 DrawChooseTree(&grid_size_current[0][0]);
9756 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9757 DrawChooseTree(&grid_size_current[0][1]);
9758 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9759 DrawChooseTree(&grid_size_current[1][0]);
9760 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9761 DrawChooseTree(&grid_size_current[1][1]);
9763 DrawSetupScreen_Generic();
9765 PlayMenuSoundsAndMusic();
9768 void RedrawSetupScreenAfterFullscreenToggle(void)
9770 if (setup_mode == SETUP_MODE_GRAPHICS ||
9771 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9773 // update list selection from "setup.window_scaling_percent"
9774 execSetupGraphics_setWindowSizes(TRUE);
9780 void RedrawSetupScreenAfterScreenRotation(int nr)
9784 if (setup_mode == SETUP_MODE_TOUCH)
9786 // update virtual button settings (depending on screen orientation)
9789 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9791 // save already configured virtual buttons
9792 for (x = 0; x < MAX_GRID_XSIZE; x++)
9793 for (y = 0; y < MAX_GRID_YSIZE; y++)
9794 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9798 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9800 if (setup_mode == SETUP_MODE_INPUT)
9801 HandleSetupScreen_Input(mx, my, dx, dy, button);
9802 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9803 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9804 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9805 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9806 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9807 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9808 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9809 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9810 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9811 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9812 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9813 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9814 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9815 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9816 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9817 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9818 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9819 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9820 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9821 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9822 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9823 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9824 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9825 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9826 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9827 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9828 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9829 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9830 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9831 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9832 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9833 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9834 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9835 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9836 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9837 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9838 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9839 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9840 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9841 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9842 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9843 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9844 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9845 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9847 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9850 void HandleGameActions(void)
9852 if (setup.ask_on_game_over)
9855 if (game.restart_game_message != NULL)
9857 RequestRestartGame(game.restart_game_message);
9862 if (game_status != GAME_MODE_PLAYING)
9865 GameActions(); // main game loop
9867 if (tape.auto_play && !tape.playing)
9868 AutoPlayTapesContinue(); // continue automatically playing next tape
9872 // ---------- new screen button stuff --------------------------------------
9876 int gfx_unpressed, gfx_pressed;
9877 struct MenuPosInfo *pos;
9878 boolean *check_value;
9881 unsigned int event_mask;
9882 boolean is_touch_button;
9884 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9887 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9888 &menu.main.button.prev_level, NULL,
9889 SCREEN_CTRL_ID_PREV_LEVEL,
9891 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9892 FALSE, "previous level"
9895 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9896 &menu.main.button.next_level, NULL,
9897 SCREEN_CTRL_ID_NEXT_LEVEL,
9899 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9903 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9904 &menu.scores.button.prev_level, NULL,
9905 SCREEN_CTRL_ID_PREV_LEVEL2,
9906 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9907 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9908 FALSE, "previous level"
9911 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9912 &menu.scores.button.next_level, NULL,
9913 SCREEN_CTRL_ID_NEXT_LEVEL2,
9914 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9915 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9919 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9920 &menu.scores.button.prev_score, NULL,
9921 SCREEN_CTRL_ID_PREV_SCORE,
9922 SCREEN_MASK_SCORES_INFO,
9923 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9924 FALSE, "previous score"
9927 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9928 &menu.scores.button.next_score, NULL,
9929 SCREEN_CTRL_ID_NEXT_SCORE,
9930 SCREEN_MASK_SCORES_INFO,
9931 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9935 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9936 &menu.main.button.first_level, NULL,
9937 SCREEN_CTRL_ID_FIRST_LEVEL,
9940 FALSE, "first level"
9943 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9944 &menu.main.button.last_level, NULL,
9945 SCREEN_CTRL_ID_LAST_LEVEL,
9951 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9952 &menu.main.button.level_number, NULL,
9953 SCREEN_CTRL_ID_LEVEL_NUMBER,
9956 FALSE, "level number"
9959 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9960 &menu.setup.button.prev_player, NULL,
9961 SCREEN_CTRL_ID_PREV_PLAYER,
9963 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9964 FALSE, "previous player"
9967 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9968 &menu.setup.button.next_player, NULL,
9969 SCREEN_CTRL_ID_NEXT_PLAYER,
9971 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9972 FALSE, "next player"
9975 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9976 &menu.main.button.insert_solution, NULL,
9977 SCREEN_CTRL_ID_INSERT_SOLUTION,
9978 SCREEN_MASK_MAIN_HAS_SOLUTION,
9980 FALSE, "insert solution tape"
9983 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9984 &menu.main.button.play_solution, NULL,
9985 SCREEN_CTRL_ID_PLAY_SOLUTION,
9986 SCREEN_MASK_MAIN_HAS_SOLUTION,
9988 FALSE, "play solution tape"
9991 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9992 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9993 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9995 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9996 FALSE, "switch ECS/AGA chipset"
9999 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
10000 &menu.setup.button.touch_back, NULL,
10001 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
10004 TRUE, "previous page"
10007 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
10008 &menu.setup.button.touch_next, NULL,
10009 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
10015 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
10016 &menu.setup.button.touch_back2, NULL,
10017 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
10018 SCREEN_MASK_TOUCH2,
10020 TRUE, "previous page"
10023 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
10024 &menu.setup.button.touch_next2, NULL,
10025 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
10026 SCREEN_MASK_TOUCH2,
10034 int gfx_unpressed, gfx_pressed;
10038 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
10041 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
10042 -1, -1, // these values are not constant, but can change at runtime
10043 SCREEN_CTRL_ID_SCROLL_UP,
10047 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
10048 -1, -1, // these values are not constant, but can change at runtime
10049 SCREEN_CTRL_ID_SCROLL_DOWN,
10056 int gfx_unpressed, gfx_pressed;
10062 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
10065 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
10066 -1, -1, // these values are not constant, but can change at runtime
10067 -1, -1, // these values are not constant, but can change at runtime
10068 GD_TYPE_SCROLLBAR_VERTICAL,
10069 SCREEN_CTRL_ID_SCROLL_VERTICAL,
10070 "scroll level series vertically"
10082 } textinput_info[NUM_SCREEN_TEXTINPUT] =
10085 IMG_SETUP_INPUT_TEXT,
10086 SCREEN_CTRL_ID_NETWORK_SERVER,
10087 -1, -1, // these values are not constant, but can change at runtime
10088 MAX_SETUP_TEXT_INPUT_LEN,
10089 network_server_hostname,
10090 "Network Server Hostname / IP"
10094 static void CreateScreenMenubuttons(void)
10096 struct GadgetInfo *gi;
10097 unsigned int event_mask;
10100 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10102 struct MenuPosInfo *pos = menubutton_info[i].pos;
10103 int screen_mask = menubutton_info[i].screen_mask;
10104 boolean is_touch_button = menubutton_info[i].is_touch_button;
10105 boolean is_check_button = menubutton_info[i].check_value != NULL;
10106 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
10107 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10108 int gfx_unpressed, gfx_pressed;
10109 int x, y, width, height;
10110 int gd_x1, gd_x2, gd_y1, gd_y2;
10111 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
10112 int id = menubutton_info[i].gadget_id;
10113 int type = GD_TYPE_NORMAL_BUTTON;
10114 boolean checked = FALSE;
10116 event_mask = menubutton_info[i].event_mask;
10118 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
10119 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
10121 width = graphic_info[menubutton_info[i].gfx_pressed].width;
10122 height = graphic_info[menubutton_info[i].gfx_pressed].height;
10124 gfx_unpressed = menubutton_info[i].gfx_unpressed;
10125 gfx_pressed = menubutton_info[i].gfx_pressed;
10126 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10127 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10128 gd_x1 = graphic_info[gfx_unpressed].src_x;
10129 gd_y1 = graphic_info[gfx_unpressed].src_y;
10130 gd_x2 = graphic_info[gfx_pressed].src_x;
10131 gd_y2 = graphic_info[gfx_pressed].src_y;
10137 if (is_touch_button)
10139 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
10140 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
10143 if (is_check_button)
10145 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
10146 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
10147 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
10148 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
10150 type = GD_TYPE_CHECK_BUTTON;
10151 checked = *menubutton_info[i].check_value;
10154 if (is_score_button)
10156 // if x/y set to -1, dynamically place buttons next to title text
10157 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10160 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10161 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10162 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10163 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10166 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
10167 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
10170 gi = CreateGadget(GDI_CUSTOM_ID, id,
10171 GDI_CUSTOM_TYPE_ID, i,
10172 GDI_IMAGE_ID, gfx_unpressed,
10173 GDI_INFO_TEXT, menubutton_info[i].infotext,
10177 GDI_HEIGHT, height,
10179 GDI_STATE, GD_BUTTON_UNPRESSED,
10180 GDI_CHECKED, checked,
10181 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10182 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10183 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
10184 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
10185 GDI_DIRECT_DRAW, FALSE,
10186 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10187 GDI_EVENT_MASK, event_mask,
10188 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10192 Fail("cannot create gadget");
10194 screen_gadget[id] = gi;
10198 static void CreateScreenScrollbuttons(void)
10200 struct GadgetInfo *gi;
10201 unsigned int event_mask;
10204 // these values are not constant, but can change at runtime
10205 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10206 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10207 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10208 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10210 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10212 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10213 int gfx_unpressed, gfx_pressed;
10214 int x, y, width, height;
10215 int gd_x1, gd_x2, gd_y1, gd_y2;
10216 int id = scrollbutton_info[i].gadget_id;
10218 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10220 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10221 y = mSY + scrollbutton_info[i].y;
10222 width = SC_SCROLLBUTTON_XSIZE;
10223 height = SC_SCROLLBUTTON_YSIZE;
10225 // correct scrollbar position if placed outside menu (playfield) area
10226 if (x > SX + SC_SCROLL_UP_XPOS)
10227 x = SX + SC_SCROLL_UP_XPOS;
10229 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10230 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10231 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10233 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10234 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10235 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10236 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10237 gd_x1 = graphic_info[gfx_unpressed].src_x;
10238 gd_y1 = graphic_info[gfx_unpressed].src_y;
10239 gd_x2 = graphic_info[gfx_pressed].src_x;
10240 gd_y2 = graphic_info[gfx_pressed].src_y;
10242 gi = CreateGadget(GDI_CUSTOM_ID, id,
10243 GDI_CUSTOM_TYPE_ID, i,
10244 GDI_IMAGE_ID, gfx_unpressed,
10245 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10249 GDI_HEIGHT, height,
10250 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10251 GDI_STATE, GD_BUTTON_UNPRESSED,
10252 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10253 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10254 GDI_DIRECT_DRAW, FALSE,
10255 GDI_EVENT_MASK, event_mask,
10256 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10260 Fail("cannot create gadget");
10262 screen_gadget[id] = gi;
10266 static void CreateScreenScrollbars(void)
10270 // these values are not constant, but can change at runtime
10271 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10272 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10273 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10274 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10276 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10278 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10279 int gfx_unpressed, gfx_pressed;
10280 int x, y, width, height;
10281 int gd_x1, gd_x2, gd_y1, gd_y2;
10282 struct GadgetInfo *gi;
10283 int items_max, items_visible, item_position;
10284 unsigned int event_mask;
10285 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10286 int id = scrollbar_info[i].gadget_id;
10288 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10290 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10291 y = mSY + scrollbar_info[i].y;
10292 width = scrollbar_info[i].width;
10293 height = scrollbar_info[i].height;
10295 // correct scrollbar position if placed outside menu (playfield) area
10296 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10297 x = SX + SC_SCROLL_VERTICAL_XPOS;
10299 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10300 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10302 items_max = num_page_entries;
10303 items_visible = num_page_entries;
10306 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10307 gfx_pressed = scrollbar_info[i].gfx_pressed;
10308 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10309 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10310 gd_x1 = graphic_info[gfx_unpressed].src_x;
10311 gd_y1 = graphic_info[gfx_unpressed].src_y;
10312 gd_x2 = graphic_info[gfx_pressed].src_x;
10313 gd_y2 = graphic_info[gfx_pressed].src_y;
10315 gi = CreateGadget(GDI_CUSTOM_ID, id,
10316 GDI_CUSTOM_TYPE_ID, i,
10317 GDI_IMAGE_ID, gfx_unpressed,
10318 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10322 GDI_HEIGHT, height,
10323 GDI_TYPE, scrollbar_info[i].type,
10324 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10325 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10326 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10327 GDI_WHEEL_AREA_X, SX,
10328 GDI_WHEEL_AREA_Y, SY,
10329 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10330 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10331 GDI_STATE, GD_BUTTON_UNPRESSED,
10332 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10333 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10334 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10335 GDI_DIRECT_DRAW, FALSE,
10336 GDI_EVENT_MASK, event_mask,
10337 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10341 Fail("cannot create gadget");
10343 screen_gadget[id] = gi;
10347 static void CreateScreenTextInputGadgets(void)
10351 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10353 int graphic = textinput_info[i].graphic;
10354 struct GraphicInfo *gd = &graphic_info[graphic];
10355 int gd_x1 = gd->src_x;
10356 int gd_y1 = gd->src_y;
10357 int gd_x2 = gd->src_x + gd->active_xoffset;
10358 int gd_y2 = gd->src_y + gd->active_yoffset;
10359 struct GadgetInfo *gi;
10360 unsigned int event_mask;
10361 int id = textinput_info[i].gadget_id;
10362 int x = textinput_info[i].x;
10363 int y = textinput_info[i].y;
10365 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10367 gi = CreateGadget(GDI_CUSTOM_ID, id,
10368 GDI_CUSTOM_TYPE_ID, i,
10369 GDI_INFO_TEXT, textinput_info[i].infotext,
10372 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10373 GDI_TEXT_VALUE, textinput_info[i].value,
10374 GDI_TEXT_SIZE, textinput_info[i].size,
10375 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10376 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10377 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10378 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10379 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10380 GDI_DESIGN_WIDTH, gd->width,
10381 GDI_EVENT_MASK, event_mask,
10382 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10383 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10387 Fail("cannot create gadget");
10389 screen_gadget[id] = gi;
10393 void CreateScreenGadgets(void)
10395 CreateScreenMenubuttons();
10397 CreateScreenScrollbuttons();
10398 CreateScreenScrollbars();
10400 CreateScreenTextInputGadgets();
10403 void FreeScreenGadgets(void)
10407 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10408 FreeGadget(screen_gadget[i]);
10411 static void RedrawScreenMenuGadgets(int screen_mask)
10415 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10416 if (screen_mask & menubutton_info[i].screen_mask)
10417 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10420 static void MapScreenMenuGadgets(int screen_mask)
10424 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10425 if (screen_mask & menubutton_info[i].screen_mask)
10426 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10429 static void UnmapScreenMenuGadgets(int screen_mask)
10433 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10435 if (screen_mask & menubutton_info[i].screen_mask)
10437 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10439 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10440 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10441 screen_gadget[menubutton_info[i].gadget_id]->y,
10442 screen_gadget[menubutton_info[i].gadget_id]->width,
10443 screen_gadget[menubutton_info[i].gadget_id]->height);
10448 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10451 MapScreenMenuGadgets(screen_mask);
10453 UnmapScreenMenuGadgets(screen_mask);
10456 static void MapScreenGadgets(int num_entries)
10460 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10463 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10464 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10466 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10467 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10470 static void UnmapScreenGadgets()
10474 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10475 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10477 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10478 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10481 static void MapScreenTreeGadgets(TreeInfo *ti)
10483 MapScreenGadgets(numTreeInfoInGroup(ti));
10486 static void UnmapScreenTreeGadgets(void)
10488 UnmapScreenGadgets();
10491 static void AdjustScoreInfoButtons(int x, int y1, int y2)
10493 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10494 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10495 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10496 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10498 if (pos_1->x == -1 && pos_1->y == -1)
10499 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10501 if (pos_2->x == -1 && pos_2->y == -1)
10502 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10505 static void HandleScreenGadgets(struct GadgetInfo *gi)
10507 int id = gi->custom_id;
10508 int button = gi->event.button;
10509 int step = (button == MB_LEFTBUTTON ? 1 :
10510 button == MB_MIDDLEBUTTON ? 5 :
10511 button == MB_RIGHTBUTTON ? 10 : 1);
10515 case SCREEN_CTRL_ID_PREV_LEVEL:
10516 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10519 case SCREEN_CTRL_ID_NEXT_LEVEL:
10520 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10523 case SCREEN_CTRL_ID_PREV_LEVEL2:
10524 HandleHallOfFame_SelectLevel(step, -1);
10527 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10528 HandleHallOfFame_SelectLevel(step, +1);
10531 case SCREEN_CTRL_ID_PREV_SCORE:
10532 HandleScoreInfo_SelectScore(step, -1);
10535 case SCREEN_CTRL_ID_NEXT_SCORE:
10536 HandleScoreInfo_SelectScore(step, +1);
10539 case SCREEN_CTRL_ID_FIRST_LEVEL:
10540 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10543 case SCREEN_CTRL_ID_LAST_LEVEL:
10544 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10547 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10548 CloseDoor(DOOR_CLOSE_2);
10549 SetGameStatus(GAME_MODE_LEVELNR);
10550 DrawChooseLevelNr();
10553 case SCREEN_CTRL_ID_PREV_PLAYER:
10554 HandleSetupScreen_Input_Player(step, -1);
10557 case SCREEN_CTRL_ID_NEXT_PLAYER:
10558 HandleSetupScreen_Input_Player(step, +1);
10561 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10562 InsertSolutionTape();
10565 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10566 PlaySolutionTape();
10569 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10570 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10574 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10575 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10576 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10577 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10578 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10581 case SCREEN_CTRL_ID_SCROLL_UP:
10582 if (game_status == GAME_MODE_NAMES)
10583 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10584 else if (game_status == GAME_MODE_LEVELS)
10585 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10586 else if (game_status == GAME_MODE_LEVELNR)
10587 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10588 else if (game_status == GAME_MODE_SETUP)
10589 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10590 else if (game_status == GAME_MODE_INFO)
10591 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10592 else if (game_status == GAME_MODE_SCORES)
10593 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10596 case SCREEN_CTRL_ID_SCROLL_DOWN:
10597 if (game_status == GAME_MODE_NAMES)
10598 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10599 else if (game_status == GAME_MODE_LEVELS)
10600 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10601 else if (game_status == GAME_MODE_LEVELNR)
10602 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10603 else if (game_status == GAME_MODE_SETUP)
10604 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10605 else if (game_status == GAME_MODE_INFO)
10606 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10607 else if (game_status == GAME_MODE_SCORES)
10608 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10611 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10612 if (game_status == GAME_MODE_NAMES)
10613 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10614 else if (game_status == GAME_MODE_LEVELS)
10615 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10616 else if (game_status == GAME_MODE_LEVELNR)
10617 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10618 else if (game_status == GAME_MODE_SETUP)
10619 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10620 else if (game_status == GAME_MODE_INFO)
10621 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10622 else if (game_status == GAME_MODE_SCORES)
10623 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10626 case SCREEN_CTRL_ID_NETWORK_SERVER:
10628 if (!strEqual(gi->textinput.value, ""))
10630 setString(&setup.network_server_hostname, gi->textinput.value);
10632 network.server_host = setup.network_server_hostname;
10636 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10638 network.server_host = NULL;
10641 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10642 network.server_host = NULL;
10644 execSetupGame_setNetworkServerText();
10656 void DumpScreenIdentifiers(void)
10660 Print("Active screen elements on current screen:\n");
10662 for (i = 0; main_controls[i].nr != -1; i++)
10664 struct MainControlInfo *mci = &main_controls[i];
10666 if (mci->button_graphic != -1)
10668 char *token = getTokenFromImageID(mci->button_graphic);
10670 Print("- '%s'\n", token);
10677 boolean DoScreenAction(int image_id)
10681 if (game_status != GAME_MODE_MAIN)
10684 for (i = 0; main_controls[i].nr != -1; i++)
10686 struct MainControlInfo *mci = &main_controls[i];
10687 struct MenuPosInfo *pos = mci->pos_button;
10689 if (mci->button_graphic == image_id)
10691 int x = mSX + pos->x;
10692 int y = mSY + pos->y;
10694 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10703 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10705 // get tree info node of newly added level or artwork set
10706 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10707 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10709 if (tree_node_new == NULL) // should not happen
10712 // if request dialog is active, do nothing
10713 if (game.request_active)
10716 if (game_status == GAME_MODE_MAIN &&
10717 tree_type == TREE_TYPE_LEVEL_DIR)
10719 // when adding new level set in main menu, select it as current level set
10721 // change current level set to newly added level set from zip file
10722 leveldir_current = tree_node_new;
10724 // change current level number to first level of newly added level set
10725 level_nr = leveldir_current->first_level;
10727 // redraw screen to reflect changed level set
10730 // save this level set and level number as last selected level set
10731 SaveLevelSetup_LastSeries();
10732 SaveLevelSetup_SeriesInfo();
10734 else if (game_status == GAME_MODE_LEVELS &&
10735 tree_type == TREE_TYPE_LEVEL_DIR)
10737 // when adding new level set in level set menu, set cursor and update screen
10739 leveldir_current = tree_node_new;
10741 DrawChooseTree(&leveldir_current);
10743 else if (game_status == GAME_MODE_SETUP)
10745 // when adding new artwork set in setup menu, set cursor and update screen
10747 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10748 tree_type == TREE_TYPE_GRAPHICS_DIR)
10750 artwork.gfx_current = tree_node_new;
10752 DrawChooseTree(&artwork.gfx_current);
10754 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10755 tree_type == TREE_TYPE_SOUNDS_DIR)
10757 artwork.snd_current = tree_node_new;
10759 DrawChooseTree(&artwork.snd_current);
10761 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10762 tree_type == TREE_TYPE_MUSIC_DIR)
10764 artwork.mus_current = tree_node_new;
10766 DrawChooseTree(&artwork.mus_current);
10771 static int UploadTapes(void)
10773 SetGameStatus(GAME_MODE_LOADING);
10775 FadeSetEnterScreen();
10776 FadeOut(REDRAW_ALL);
10778 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10780 FadeIn(REDRAW_ALL);
10782 DrawInitTextHead("Uploading tapes");
10784 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10785 global.autoplay_leveldir = "ALL";
10786 global.autoplay_all = TRUE;
10788 int num_tapes_uploaded = AutoPlayTapes();
10790 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10791 global.autoplay_leveldir = NULL;
10792 global.autoplay_all = FALSE;
10794 SetGameStatus(GAME_MODE_MAIN);
10798 return num_tapes_uploaded;
10801 static boolean OfferUploadTapes(void)
10803 if (!Request(setup.has_remaining_tapes ?
10804 "Upload missing tapes to the high score server now?" :
10805 "Upload all your tapes to the high score server now?", REQ_ASK))
10808 int num_tapes_uploaded = UploadTapes();
10811 if (num_tapes_uploaded < 0)
10813 num_tapes_uploaded = -num_tapes_uploaded - 1;
10815 if (num_tapes_uploaded == 0)
10816 sprintf(message, "Upload failed! No tapes uploaded!");
10817 else if (num_tapes_uploaded == 1)
10818 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10820 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10821 num_tapes_uploaded);
10823 Request(message, REQ_CONFIRM);
10825 // if uploading tapes failed, add tape upload entry to setup menu
10826 setup.provide_uploading_tapes = TRUE;
10827 setup.has_remaining_tapes = TRUE;
10829 SaveSetup_ServerSetup();
10834 if (num_tapes_uploaded == 0)
10835 sprintf(message, "No tapes uploaded!");
10836 else if (num_tapes_uploaded == 1)
10837 sprintf(message, "1 tape uploaded!");
10839 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10841 Request(message, REQ_CONFIRM);
10843 if (num_tapes_uploaded > 0)
10844 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10846 // after all tapes have been uploaded, remove entry from setup menu
10847 setup.provide_uploading_tapes = FALSE;
10848 setup.has_remaining_tapes = FALSE;
10850 SaveSetup_ServerSetup();
10855 static void CheckUploadTapes(void)
10857 if (!setup.ask_for_uploading_tapes)
10860 // after asking for uploading tapes, do not ask again
10861 setup.ask_for_uploading_tapes = FALSE;
10862 setup.ask_for_remaining_tapes = FALSE;
10864 if (directoryExists(getTapeDir(NULL)))
10866 boolean tapes_uploaded = OfferUploadTapes();
10868 if (!tapes_uploaded)
10870 Request(setup.has_remaining_tapes ?
10871 "You can upload missing tapes from the setup menu later!" :
10872 "You can upload your tapes from the setup menu later!",
10878 // if tapes directory does not exist yet, never offer uploading all tapes
10879 setup.provide_uploading_tapes = FALSE;
10882 SaveSetup_ServerSetup();
10885 static void UpgradePlayerUUID(void)
10887 ApiResetUUIDAsThread(getUUID());
10890 static void CheckUpgradePlayerUUID(void)
10892 if (setup.player_version > 1)
10895 UpgradePlayerUUID();
10898 void CheckApiServerTasks(void)
10900 // check if the player's UUID has to be upgraded
10901 CheckUpgradePlayerUUID();
10903 // check if there are any tapes to be uploaded
10904 CheckUploadTapes();