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_FIRST_LEVEL 4
190 #define SCREEN_CTRL_ID_LAST_LEVEL 5
191 #define SCREEN_CTRL_ID_LEVEL_NUMBER 6
192 #define SCREEN_CTRL_ID_PREV_PLAYER 7
193 #define SCREEN_CTRL_ID_NEXT_PLAYER 8
194 #define SCREEN_CTRL_ID_INSERT_SOLUTION 9
195 #define SCREEN_CTRL_ID_PLAY_SOLUTION 10
196 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 11
197 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 12
198 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 13
199 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 14
200 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 15
201 #define SCREEN_CTRL_ID_SCROLL_UP 16
202 #define SCREEN_CTRL_ID_SCROLL_DOWN 17
203 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 18
204 #define SCREEN_CTRL_ID_NETWORK_SERVER 19
206 #define NUM_SCREEN_GADGETS 20
208 #define NUM_SCREEN_MENUBUTTONS 16
209 #define NUM_SCREEN_SCROLLBUTTONS 2
210 #define NUM_SCREEN_SCROLLBARS 1
211 #define NUM_SCREEN_TEXTINPUT 1
213 #define SCREEN_MASK_MAIN (1 << 0)
214 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
215 #define SCREEN_MASK_INPUT (1 << 2)
216 #define SCREEN_MASK_TOUCH (1 << 3)
217 #define SCREEN_MASK_TOUCH2 (1 << 4)
218 #define SCREEN_MASK_SCORES (1 << 5)
220 // graphic position and size values for buttons and scrollbars
221 #define SC_MENUBUTTON_XSIZE TILEX
222 #define SC_MENUBUTTON_YSIZE TILEY
224 #define SC_SCROLLBUTTON_XSIZE TILEX
225 #define SC_SCROLLBUTTON_YSIZE TILEY
227 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
229 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
230 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
231 SC_SCROLLBUTTON_YSIZE)
233 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
234 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
236 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
237 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
238 SC_SCROLLBUTTON_YSIZE)
240 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
241 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
242 SC_SCROLL_VERTICAL_YSIZE)
244 #define SC_BORDER_SIZE 14
247 // forward declarations of internal functions
248 static void HandleScreenGadgets(struct GadgetInfo *);
249 static void HandleSetupScreen_Generic(int, int, int, int, int);
250 static void HandleSetupScreen_Input(int, int, int, int, int);
251 static void CustomizeKeyboard(int);
252 static void ConfigureJoystick(int);
253 static void ConfigureVirtualButtons(void);
254 static void execSetupGame(void);
255 static void execSetupEngines(void);
256 static void execSetupGraphics(void);
257 static void execSetupSound(void);
258 static void execSetupTouch(void);
259 static void execSetupArtwork(void);
260 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
262 static void DrawChoosePlayerName(void);
263 static void DrawChooseLevelSet(void);
264 static void DrawChooseLevelNr(void);
265 static void DrawInfoScreen(void);
266 static void DrawSetupScreen(void);
267 static void DrawTypeName(void);
269 static void DrawInfoScreen_NotAvailable(char *, char *);
270 static void DrawInfoScreen_HelpAnim(int, int, boolean);
271 static void DrawInfoScreen_HelpText(int, int, int, int);
272 static void HandleInfoScreen_Main(int, int, int, int, int);
273 static void HandleInfoScreen_TitleScreen(int);
274 static void HandleInfoScreen_Elements(int);
275 static void HandleInfoScreen_Music(int);
276 static void HandleInfoScreen_Credits(int);
277 static void HandleInfoScreen_Program(int);
278 static void HandleInfoScreen_Version(int);
280 static void ModifyGameSpeedIfNeeded(void);
281 static void DisableVsyncIfNeeded(void);
283 static void RedrawScreenMenuGadgets(int);
284 static void MapScreenMenuGadgets(int);
285 static void UnmapScreenMenuGadgets(int);
286 static void MapScreenGadgets(int);
287 static void UnmapScreenGadgets(void);
288 static void MapScreenTreeGadgets(TreeInfo *);
289 static void UnmapScreenTreeGadgets(void);
291 static void UpdateScreenMenuGadgets(int, boolean);
293 static boolean OfferUploadTapes(void);
294 static void execOfferUploadTapes(void);
296 static void DrawHallOfFame_setScoreEntries(void);
297 static void HandleHallOfFame_SelectLevel(int, int);
298 static char *getHallOfFameScoreText(int);
300 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
302 static int info_mode = INFO_MODE_MAIN;
303 static int setup_mode = SETUP_MODE_MAIN;
305 static TreeInfo *window_sizes = NULL;
306 static TreeInfo *window_size_current = NULL;
308 static TreeInfo *scaling_types = NULL;
309 static TreeInfo *scaling_type_current = NULL;
311 static TreeInfo *rendering_modes = NULL;
312 static TreeInfo *rendering_mode_current = NULL;
314 static TreeInfo *vsync_modes = NULL;
315 static TreeInfo *vsync_mode_current = NULL;
317 static TreeInfo *scroll_delays = NULL;
318 static TreeInfo *scroll_delay_current = NULL;
320 static TreeInfo *snapshot_modes = NULL;
321 static TreeInfo *snapshot_mode_current = NULL;
323 static TreeInfo *scores_types = NULL;
324 static TreeInfo *scores_type_current = NULL;
326 static TreeInfo *game_speeds_normal = NULL;
327 static TreeInfo *game_speeds_extended = NULL;
328 static TreeInfo *game_speeds = NULL;
329 static TreeInfo *game_speed_current = NULL;
331 static TreeInfo *volumes_simple = NULL;
332 static TreeInfo *volume_simple_current = NULL;
334 static TreeInfo *volumes_loops = NULL;
335 static TreeInfo *volume_loops_current = NULL;
337 static TreeInfo *volumes_music = NULL;
338 static TreeInfo *volume_music_current = NULL;
340 static TreeInfo *touch_controls = NULL;
341 static TreeInfo *touch_control_current = NULL;
343 static TreeInfo *move_distances = NULL;
344 static TreeInfo *move_distance_current = NULL;
346 static TreeInfo *drop_distances = NULL;
347 static TreeInfo *drop_distance_current = NULL;
349 static TreeInfo *transparencies = NULL;
350 static TreeInfo *transparency_current = NULL;
352 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
353 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
355 static TreeInfo *player_name = NULL;
356 static TreeInfo *player_name_current = NULL;
358 static TreeInfo *level_number = NULL;
359 static TreeInfo *level_number_current = NULL;
361 static TreeInfo *score_entries = NULL;
362 static TreeInfo *score_entry_current = NULL;
364 static struct ValueTextInfo window_sizes_list[] =
369 { 100, "100 % (Default)" },
382 static struct StringValueTextInfo scaling_types_list[] =
384 { SCALING_QUALITY_NEAREST, "Off" },
385 { SCALING_QUALITY_LINEAR, "Linear" },
386 { SCALING_QUALITY_BEST, "Anisotropic" },
391 static struct StringValueTextInfo rendering_modes_list[] =
393 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
394 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
396 // this mode may work under certain conditions, but does not work on Windows
397 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
399 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
404 static struct StringValueTextInfo vsync_modes_list[] =
406 { STR_VSYNC_MODE_OFF, "Off" },
407 { STR_VSYNC_MODE_NORMAL, "Normal" },
408 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
413 static struct StringValueTextInfo scores_types_list[] =
415 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
416 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
417 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
422 static struct ValueTextInfo game_speeds_list_normal[] =
433 static struct ValueTextInfo game_speeds_list_extended[] =
435 { 1000, "1 fps (Extremely Slow)" },
440 { 29, "35 fps (Original Supaplex)" },
442 { 20, "50 fps (=== Normal Speed ===)" },
443 { 16, "60 fps (60 Hz VSync Speed)" },
444 { 14, "70 fps (Maximum Supaplex)" },
448 { 1, "1000 fps (Extremely Fast)" },
453 static struct ValueTextInfo *game_speeds_list;
455 static struct ValueTextInfo scroll_delays_list[] =
457 { 0, "0 Tiles (No Scroll Delay)" },
460 { 3, "3 Tiles (Default)" },
465 { 8, "8 Tiles (Maximum Scroll Delay)"},
470 static struct StringValueTextInfo snapshot_modes_list[] =
472 { STR_SNAPSHOT_MODE_OFF, "Off" },
473 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
474 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
475 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
480 static struct ValueTextInfo volumes_list[] =
500 static struct StringValueTextInfo touch_controls_list[] =
502 { TOUCH_CONTROL_OFF, "Off" },
503 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
504 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
505 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
510 static struct ValueTextInfo distances_list[] =
525 static struct ValueTextInfo transparencies_list[] =
527 { 0, "0 % (Opaque)" },
537 { 100, "100 % (Invisible)" },
542 static struct ValueTextInfo grid_sizes_list[] =
578 static int align_xoffset = 0;
579 static int align_yoffset = 0;
581 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
582 (s) <= GAME_MODE_SETUP ? (s) : \
583 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
585 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
586 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
588 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
589 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
590 (i) <= INFO_MODE_LEVELSET ? (i) : \
593 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
594 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
595 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
596 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
597 SETUP_MODE_CHOOSE_ARTWORK : \
598 SETUP_MODE_CHOOSE_OTHER)
600 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
601 menu.draw_xoffset[GAME_MODE_INFO] : \
602 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
603 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
604 menu.draw_yoffset[GAME_MODE_INFO] : \
605 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
606 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
607 menu.extra_spacing[GAME_MODE_INFO] : \
608 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
610 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
611 menu.draw_xoffset[GAME_MODE_SETUP] : \
612 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
613 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
614 menu.draw_yoffset[GAME_MODE_SETUP] : \
615 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
616 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
617 menu.extra_spacing[GAME_MODE_SETUP] : \
618 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
620 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
622 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
623 DRAW_XOFFSET_INFO(info_mode) : \
624 (s) == GAME_MODE_SETUP ? \
625 DRAW_XOFFSET_SETUP(setup_mode) : \
626 menu.draw_xoffset[DRAW_MODE(s)])
627 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
628 DRAW_YOFFSET_INFO(info_mode) : \
629 (s) == GAME_MODE_SETUP ? \
630 DRAW_YOFFSET_SETUP(setup_mode) : \
631 menu.draw_yoffset[DRAW_MODE(s)])
632 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
633 EXTRA_SPACING_INFO(info_mode) : \
634 (s) == GAME_MODE_SETUP ? \
635 EXTRA_SPACING_SETUP(setup_mode) : \
636 (s) == GAME_MODE_SCORES ? \
637 EXTRA_SPACING_SCORES(info_mode) : \
638 menu.extra_spacing[DRAW_MODE(s)])
640 #define mSX (SX + DRAW_XOFFSET(game_status))
641 #define mSY (SY + DRAW_YOFFSET(game_status))
643 #define amSX (mSX + align_xoffset)
644 #define amSY (mSY + align_yoffset)
646 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
647 menu.list_size[game_status] : \
648 MAX_MENU_ENTRIES_ON_SCREEN)
650 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
651 NUM_MENU_ENTRIES_ON_SCREEN)
654 // title display and control definitions
656 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
657 2 * MAX_NUM_TITLE_MESSAGES)
659 #define NO_DIRECT_LEVEL_SELECT (-1)
662 static int num_title_screens = 0;
664 struct TitleControlInfo
673 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
675 // main menu display and control definitions
677 #define MAIN_CONTROL_NAME 0
678 #define MAIN_CONTROL_LEVELS 1
679 #define MAIN_CONTROL_SCORES 2
680 #define MAIN_CONTROL_EDITOR 3
681 #define MAIN_CONTROL_INFO 4
682 #define MAIN_CONTROL_GAME 5
683 #define MAIN_CONTROL_SETUP 6
684 #define MAIN_CONTROL_QUIT 7
685 #define MAIN_CONTROL_PREV_LEVEL 8
686 #define MAIN_CONTROL_NEXT_LEVEL 9
687 #define MAIN_CONTROL_FIRST_LEVEL 10
688 #define MAIN_CONTROL_LAST_LEVEL 11
689 #define MAIN_CONTROL_LEVEL_NUMBER 12
690 #define MAIN_CONTROL_LEVEL_INFO_1 13
691 #define MAIN_CONTROL_LEVEL_INFO_2 14
692 #define MAIN_CONTROL_LEVEL_NAME 15
693 #define MAIN_CONTROL_LEVEL_AUTHOR 16
694 #define MAIN_CONTROL_LEVEL_YEAR 17
695 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
696 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
697 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
698 #define MAIN_CONTROL_TITLE_1 21
699 #define MAIN_CONTROL_TITLE_2 22
700 #define MAIN_CONTROL_TITLE_3 23
702 static char str_main_text_name[10];
703 static char str_main_text_first_level[10];
704 static char str_main_text_last_level[10];
705 static char str_main_text_level_number[10];
707 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
709 static char *main_text_name = str_main_text_name;
710 static char *main_text_first_level = str_main_text_first_level;
711 static char *main_text_last_level = str_main_text_last_level;
712 static char *main_text_level_number = str_main_text_level_number;
713 static char *main_text_levels = "Levelset";
714 static char *main_text_scores = "Hall Of Fame";
715 static char *main_text_editor = "Level Creator";
716 static char *main_text_info = "Info Screen";
717 static char *main_text_game = "Start Game";
718 static char *main_text_setup = "Setup";
719 static char *main_text_quit = "Quit";
720 static char *main_text_level_name = level.name;
721 static char *main_text_level_author = level.author;
722 static char *main_text_level_year = NULL;
723 static char *main_text_level_imported_from = NULL;
724 static char *main_text_level_imported_by = NULL;
725 static char *main_text_level_tested_by = NULL;
726 static char *main_text_title_1 = NULL;
727 static char *main_text_title_2 = NULL;
728 static char *main_text_title_3 = NULL;
730 extern char debug_xsn_mode[];
732 struct MainControlInfo
736 struct MenuPosInfo *pos_button;
739 struct TextPosInfo *pos_text;
742 struct TextPosInfo *pos_input;
746 static struct MainControlInfo main_controls[] =
750 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
751 &menu.main.text.name, &main_text_name,
752 &menu.main.input.name, &setup.player_name,
756 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
757 &menu.main.text.levels, &main_text_levels,
762 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
763 &menu.main.text.scores, &main_text_scores,
768 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
769 &menu.main.text.editor, &main_text_editor,
774 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
775 &menu.main.text.info, &main_text_info,
780 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
781 &menu.main.text.game, &main_text_game,
786 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
787 &menu.main.text.setup, &main_text_setup,
792 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
793 &menu.main.text.quit, &main_text_quit,
797 MAIN_CONTROL_PREV_LEVEL,
803 MAIN_CONTROL_NEXT_LEVEL,
809 MAIN_CONTROL_FIRST_LEVEL,
811 &menu.main.text.first_level, &main_text_first_level,
815 MAIN_CONTROL_LAST_LEVEL,
817 &menu.main.text.last_level, &main_text_last_level,
821 MAIN_CONTROL_LEVEL_NUMBER,
823 &menu.main.text.level_number, &main_text_level_number,
827 MAIN_CONTROL_LEVEL_INFO_1,
829 &menu.main.text.level_info_1, NULL,
833 MAIN_CONTROL_LEVEL_INFO_2,
835 &menu.main.text.level_info_2, NULL,
839 MAIN_CONTROL_LEVEL_NAME,
841 &menu.main.text.level_name, &main_text_level_name,
845 MAIN_CONTROL_LEVEL_AUTHOR,
847 &menu.main.text.level_author, &main_text_level_author,
851 MAIN_CONTROL_LEVEL_YEAR,
853 &menu.main.text.level_year, &main_text_level_year,
857 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
859 &menu.main.text.level_imported_from, &main_text_level_imported_from,
863 MAIN_CONTROL_LEVEL_IMPORTED_BY,
865 &menu.main.text.level_imported_by, &main_text_level_imported_by,
869 MAIN_CONTROL_LEVEL_TESTED_BY,
871 &menu.main.text.level_tested_by, &main_text_level_tested_by,
875 MAIN_CONTROL_TITLE_1,
877 &menu.main.text.title_1, &main_text_title_1,
881 MAIN_CONTROL_TITLE_2,
883 &menu.main.text.title_2, &main_text_title_2,
887 MAIN_CONTROL_TITLE_3,
889 &menu.main.text.title_3, &main_text_title_3,
902 static int getTitleScreenGraphic(int nr, boolean initial)
904 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
907 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
909 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
913 static int getTitleScreenGameMode(boolean initial)
915 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
919 static int getTitleMessageGameMode(boolean initial)
921 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
924 static int getTitleAnimMode(struct TitleControlInfo *tci)
926 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
928 return base + tci->local_nr;
932 static int getTitleScreenBackground(boolean initial)
934 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
939 static int getTitleMessageBackground(int nr, boolean initial)
941 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
945 static int getTitleBackground(int nr, boolean initial, boolean is_image)
947 int base = (is_image ?
948 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
949 IMG_BACKGROUND_TITLESCREEN_1) :
950 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
951 IMG_BACKGROUND_TITLEMESSAGE_1));
952 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
953 IMG_BACKGROUND_TITLE);
954 int graphic_local = base + nr;
956 if (graphic_info[graphic_local].bitmap != NULL)
957 return graphic_local;
959 if (graphic_info[graphic_global].bitmap != NULL)
960 return graphic_global;
962 return IMG_UNDEFINED;
965 static int getTitleSound(struct TitleControlInfo *tci)
967 boolean is_image = tci->is_image;
968 int initial = tci->initial;
969 int nr = tci->local_nr;
970 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
971 int base = (is_image ?
972 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
973 SND_BACKGROUND_TITLESCREEN_1) :
974 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
975 SND_BACKGROUND_TITLEMESSAGE_1));
976 int sound_global = menu.sound[mode];
977 int sound_local = base + nr;
980 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
981 nr, initial, is_image,
982 sound_global, getSoundListEntry(sound_global)->filename,
983 sound_local, getSoundListEntry(sound_local)->filename);
986 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
989 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
992 return SND_UNDEFINED;
995 static int getTitleMusic(struct TitleControlInfo *tci)
997 boolean is_image = tci->is_image;
998 int initial = tci->initial;
999 int nr = tci->local_nr;
1000 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1001 int base = (is_image ?
1002 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1003 MUS_BACKGROUND_TITLESCREEN_1) :
1004 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1005 MUS_BACKGROUND_TITLEMESSAGE_1));
1006 int music_global = menu.music[mode];
1007 int music_local = base + nr;
1010 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1011 nr, initial, is_image,
1012 music_global, getMusicListEntry(music_global)->filename,
1013 music_local, getMusicListEntry(music_local)->filename);
1016 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1019 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1020 return music_global;
1022 return MUS_UNDEFINED;
1025 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1027 boolean is_image = tci->is_image;
1028 boolean initial = tci->initial;
1029 boolean first = tci->first;
1030 int nr = tci->local_nr;
1031 struct TitleMessageInfo tmi;
1032 struct TitleFadingInfo ti;
1034 tmi = (is_image ? (initial ? (first ?
1035 titlescreen_initial_first[nr] :
1036 titlescreen_initial[nr])
1038 titlescreen_first[nr] :
1040 : (initial ? (first ?
1041 titlemessage_initial_first[nr] :
1042 titlemessage_initial[nr])
1044 titlemessage_first[nr] :
1045 titlemessage[nr])));
1047 ti.fade_mode = tmi.fade_mode;
1048 ti.fade_delay = tmi.fade_delay;
1049 ti.post_delay = tmi.post_delay;
1050 ti.auto_delay = tmi.auto_delay;
1051 ti.auto_delay_unit = tmi.auto_delay_unit;
1056 static int compareTitleControlInfo(const void *object1, const void *object2)
1058 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1059 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1062 if (tci1->initial != tci2->initial)
1063 compare_result = (tci1->initial ? -1 : +1);
1064 else if (tci1->sort_priority != tci2->sort_priority)
1065 compare_result = tci1->sort_priority - tci2->sort_priority;
1066 else if (tci1->is_image != tci2->is_image)
1067 compare_result = (tci1->is_image ? -1 : +1);
1069 compare_result = tci1->local_nr - tci2->local_nr;
1071 return compare_result;
1074 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1076 int nr, int sort_priority)
1078 title_controls[num_title_screens].is_image = is_image;
1079 title_controls[num_title_screens].initial = initial;
1080 title_controls[num_title_screens].local_nr = nr;
1081 title_controls[num_title_screens].sort_priority = sort_priority;
1083 title_controls[num_title_screens].first = FALSE; // will be set later
1085 num_title_screens++;
1088 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1092 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1094 int graphic = getTitleScreenGraphic(i, initial);
1095 Bitmap *bitmap = graphic_info[graphic].bitmap;
1096 int sort_priority = graphic_info[graphic].sort_priority;
1099 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1102 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1104 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1105 char *filename = getLevelSetTitleMessageFilename(i, initial);
1106 int sort_priority = tmi->sort_priority;
1108 if (filename != NULL)
1109 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1113 static void InitializeTitleControls(boolean show_title_initial)
1115 num_title_screens = 0;
1117 // 1st step: initialize title screens for game start (only when starting)
1118 if (show_title_initial)
1119 InitializeTitleControls_CheckTitleInfo(TRUE);
1121 // 2nd step: initialize title screens for current level set
1122 InitializeTitleControls_CheckTitleInfo(FALSE);
1124 // sort title screens according to sort_priority and title number
1125 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1126 compareTitleControlInfo);
1128 // mark first title screen
1129 title_controls[0].first = TRUE;
1132 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1134 return (pos != NULL && pos->x != -1 && pos->y != -1);
1137 static boolean visibleTextPos(struct TextPosInfo *pos)
1139 return (pos != NULL && pos->x != -1 && pos->y != -1);
1142 static void InitializeMainControls(void)
1144 boolean local_team_mode = (!network.enabled && setup.team_mode);
1147 // set main control text values to dynamically determined values
1148 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1150 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1151 menu.main.text.first_level.size));
1152 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1153 menu.main.text.last_level.size));
1154 strcpy(main_text_level_number, int2str(level_nr,
1155 menu.main.text.level_number.size));
1157 main_text_level_year = leveldir_current->year;
1158 main_text_level_imported_from = leveldir_current->imported_from;
1159 main_text_level_imported_by = leveldir_current->imported_by;
1160 main_text_level_tested_by = leveldir_current->tested_by;
1162 main_text_title_1 = getConfigProgramTitleString();
1163 main_text_title_2 = getConfigProgramCopyrightString();
1164 main_text_title_3 = getConfigProgramCompanyString();
1166 // set main control screen positions to dynamically determined values
1167 for (i = 0; main_controls[i].nr != -1; i++)
1169 struct MainControlInfo *mci = &main_controls[i];
1171 struct MenuPosInfo *pos_button = mci->pos_button;
1172 struct TextPosInfo *pos_text = mci->pos_text;
1173 struct TextPosInfo *pos_input = mci->pos_input;
1174 char *text = (mci->text ? *mci->text : NULL);
1175 char *input = (mci->input ? *mci->input : NULL);
1176 int button_graphic = mci->button_graphic;
1177 int font_text = (pos_text ? pos_text->font : -1);
1178 int font_input = (pos_input ? pos_input->font : -1);
1180 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1181 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1182 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1183 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1184 int text_chars = (text != NULL ? strlen(text) : 0);
1185 int input_chars = (input != NULL ? strlen(input) : 0);
1188 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1190 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1191 int text_width = font_text_width * text_chars;
1192 int text_height = font_text_height;
1193 int input_width = font_input_width * input_chars;
1194 int input_height = font_input_height;
1196 if (nr == MAIN_CONTROL_NAME)
1198 menu.main.input.name.width = input_width;
1199 menu.main.input.name.height = input_height;
1202 if (pos_button != NULL) // (x/y may be -1/-1 here)
1204 pos_button->width = button_width;
1205 pos_button->height = button_height;
1208 if (pos_text != NULL) // (x/y may be -1/-1 here)
1210 // calculate text size -- needed for text alignment
1211 boolean calculate_text_size = (text != NULL);
1213 if (pos_text->width == -1 || calculate_text_size)
1214 pos_text->width = text_width;
1215 if (pos_text->height == -1 || calculate_text_size)
1216 pos_text->height = text_height;
1218 if (visibleMenuPos(pos_button))
1220 if (pos_text->x == -1)
1221 pos_text->x = pos_button->x + pos_button->width;
1222 if (pos_text->y == -1)
1224 pos_button->y + (pos_button->height - pos_text->height) / 2;
1228 if (pos_input != NULL) // (x/y may be -1/-1 here)
1230 if (visibleTextPos(pos_text))
1232 if (pos_input->x == -1)
1233 pos_input->x = pos_text->x + pos_text->width;
1234 if (pos_input->y == -1)
1235 pos_input->y = pos_text->y;
1238 if (pos_input->width == -1)
1239 pos_input->width = input_width;
1240 if (pos_input->height == -1)
1241 pos_input->height = input_height;
1246 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1247 int graphic, boolean pressed)
1249 struct GraphicInfo *g = &graphic_info[graphic];
1252 int xoffset = (pressed ? g->pressed_xoffset : 0);
1253 int yoffset = (pressed ? g->pressed_yoffset : 0);
1255 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1257 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1258 g->width, g->height, dst_x, dst_y);
1261 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1262 boolean active_input,
1263 boolean pressed_button)
1267 for (i = 0; main_controls[i].nr != -1; i++)
1269 struct MainControlInfo *mci = &main_controls[i];
1271 if (mci->nr == nr || nr == -1)
1273 struct MenuPosInfo *pos_button = mci->pos_button;
1274 struct TextPosInfo *pos_text = mci->pos_text;
1275 struct TextPosInfo *pos_input = mci->pos_input;
1276 char *text = (mci->text ? *mci->text : NULL);
1277 char *input = (mci->input ? *mci->input : NULL);
1278 int button_graphic = mci->button_graphic;
1279 int font_text = (pos_text ? pos_text->font : -1);
1280 int font_input = (pos_input ? pos_input->font : -1);
1284 button_graphic = BUTTON_ACTIVE(button_graphic);
1285 font_text = FONT_ACTIVE(font_text);
1290 font_input = FONT_ACTIVE(font_input);
1293 if (visibleMenuPos(pos_button))
1295 struct MenuPosInfo *pos = pos_button;
1296 int x = mSX + pos->x;
1297 int y = mSY + pos->y;
1299 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1300 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1303 if (visibleTextPos(pos_text) && text != NULL)
1305 struct TextPosInfo *pos = pos_text;
1306 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1307 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1310 // (check why/if this is needed)
1311 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1313 DrawText(x, y, text, font_text);
1316 if (visibleTextPos(pos_input) && input != NULL)
1318 struct TextPosInfo *pos = pos_input;
1319 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1320 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1323 // (check why/if this is needed)
1324 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1326 DrawText(x, y, input, font_input);
1332 static void DrawCursorAndText_Main(int nr, boolean active_text,
1333 boolean pressed_button)
1335 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1339 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1340 boolean pressed_button)
1342 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1346 static struct MainControlInfo *getMainControlInfo(int nr)
1350 for (i = 0; main_controls[i].nr != -1; i++)
1351 if (main_controls[i].nr == nr)
1352 return &main_controls[i];
1357 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1362 int rect_x = ALIGNED_TEXT_XPOS(rect);
1363 int rect_y = ALIGNED_TEXT_YPOS(rect);
1365 return (x >= rect_x && x < rect_x + rect->width &&
1366 y >= rect_y && y < rect_y + rect->height);
1369 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1374 int rect_x = ALIGNED_TEXT_XPOS(rect);
1375 int rect_y = ALIGNED_TEXT_YPOS(rect);
1378 Debug("screens:insideTextPosRect",
1379 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1380 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1381 (x >= rect_x && x < rect_x + rect->width &&
1382 y >= rect_y && y < rect_y + rect->height));
1385 return (x >= rect_x && x < rect_x + rect->width &&
1386 y >= rect_y && y < rect_y + rect->height);
1389 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1391 int rect_width = preview->xsize * preview->tile_size;
1392 int rect_height = preview->ysize * preview->tile_size;
1393 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1394 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1396 return (x >= rect_x && x < rect_x + rect_width &&
1397 y >= rect_y && y < rect_y + rect_height);
1400 static void AdjustScrollbar(int id, int items_max, int items_visible,
1403 struct GadgetInfo *gi = screen_gadget[id];
1405 if (item_position > items_max - items_visible)
1406 item_position = items_max - items_visible;
1408 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1409 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1410 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1413 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1415 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1419 static void clearMenuListArea(void)
1421 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1423 // correct scrollbar position if placed outside menu (playfield) area
1424 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1425 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1427 // clear menu list area, but not title or scrollbar
1428 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1429 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1432 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1434 static int cursor_array[MAX_LEV_FIELDY];
1435 int x = amSX + TILEX * xpos;
1436 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1441 cursor_array[ypos] = graphic;
1443 graphic = cursor_array[ypos];
1447 graphic = BUTTON_ACTIVE(graphic);
1449 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1450 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1453 static void initCursor(int ypos, int graphic)
1455 drawCursorExt(0, ypos, FALSE, graphic);
1458 static void drawCursor(int ypos, boolean active)
1460 drawCursorExt(0, ypos, active, -1);
1463 static void drawCursorXY(int xpos, int ypos, int graphic)
1465 drawCursorExt(xpos, ypos, FALSE, graphic);
1468 static void drawChooseTreeCursor(int ypos, boolean active)
1470 drawCursorExt(0, ypos, active, -1);
1473 static int getChooseTreeEditFont(boolean active)
1475 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1478 static int getChooseTreeEditXPos(int pos)
1480 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1481 int xoffset = (has_scrollbar ? -1 : 0);
1482 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1483 int sx = amSX + xpos * TILEX;
1484 int font_nr = getChooseTreeEditFont(FALSE);
1485 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1487 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1490 static int getChooseTreeEditYPos(int ypos_raw)
1492 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1493 int sy = amSY + ypos * TILEY;
1498 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1500 int sx = getChooseTreeEditXPos(POS_LEFT);
1501 int sy = getChooseTreeEditYPos(ypos_raw);
1502 int font_nr = getChooseTreeEditFont(active);
1504 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1507 static void DrawHeadline(void)
1509 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1510 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1513 static void DrawTitleScreenImage(int nr, boolean initial)
1515 int graphic = getTitleScreenGraphic(nr, initial);
1516 Bitmap *bitmap = graphic_info[graphic].bitmap;
1517 int width = graphic_info[graphic].width;
1518 int height = graphic_info[graphic].height;
1519 int src_x = graphic_info[graphic].src_x;
1520 int src_y = graphic_info[graphic].src_y;
1526 if (width > WIN_XSIZE)
1528 // image width too large for window => center image horizontally
1529 src_x = (width - WIN_XSIZE) / 2;
1533 if (height > WIN_YSIZE)
1535 // image height too large for window => center image vertically
1536 src_y = (height - WIN_YSIZE) / 2;
1540 // always display title screens centered
1541 dst_x = (WIN_XSIZE - width) / 2;
1542 dst_y = (WIN_YSIZE - height) / 2;
1544 SetDrawBackgroundMask(REDRAW_ALL);
1545 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1547 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1549 if (DrawingOnBackground(dst_x, dst_y))
1550 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1552 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1554 redraw_mask = REDRAW_ALL;
1557 static void DrawTitleScreenMessage(int nr, boolean initial)
1559 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1560 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1562 if (filename == NULL)
1565 // force TITLE font on title message screen
1566 SetFontStatus(getTitleMessageGameMode(initial));
1568 // if chars *and* width set to "-1", automatically determine width
1569 if (tmi->chars == -1 && tmi->width == -1)
1570 tmi->width = viewport.window[game_status].width;
1572 // if lines *and* height set to "-1", automatically determine height
1573 if (tmi->lines == -1 && tmi->height == -1)
1574 tmi->height = viewport.window[game_status].height;
1576 // if chars set to "-1", automatically determine by text and font width
1577 if (tmi->chars == -1)
1578 tmi->chars = tmi->width / getFontWidth(tmi->font);
1580 tmi->width = tmi->chars * getFontWidth(tmi->font);
1582 // if lines set to "-1", automatically determine by text and font height
1583 if (tmi->lines == -1)
1584 tmi->lines = tmi->height / getFontHeight(tmi->font);
1586 tmi->height = tmi->lines * getFontHeight(tmi->font);
1588 // if x set to "-1", automatically determine by width and alignment
1590 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1592 // if y set to "-1", automatically determine by height and alignment
1594 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1596 SetDrawBackgroundMask(REDRAW_ALL);
1597 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1599 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1601 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1602 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1603 tmi->autowrap, tmi->centered, tmi->parse_comments);
1608 static void DrawTitleScreen(void)
1610 KeyboardAutoRepeatOff();
1612 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1615 static boolean CheckTitleScreen(boolean levelset_has_changed)
1617 static boolean show_title_initial = TRUE;
1618 boolean show_titlescreen = FALSE;
1620 // needed to be able to skip title screen, if no image or message defined
1621 InitializeTitleControls(show_title_initial);
1623 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1624 show_titlescreen = TRUE;
1626 // show initial title images and messages only once at program start
1627 show_title_initial = FALSE;
1629 return (show_titlescreen && num_title_screens > 0);
1632 void DrawMainMenu(void)
1634 static LevelDirTree *leveldir_last_valid = NULL;
1635 boolean levelset_has_changed = FALSE;
1636 int fade_mask = REDRAW_FIELD;
1638 LimitScreenUpdates(FALSE);
1640 FadeSetLeaveScreen();
1642 // do not fade out here -- function may continue and fade on editor screen
1645 FadeMenuSoundsAndMusic();
1647 ExpireSoundLoops(FALSE);
1649 KeyboardAutoRepeatOn();
1651 audio.sound_deactivated = FALSE;
1655 // needed if last screen was the playing screen, invoked from level editor
1656 if (level_editor_test_game)
1658 CloseDoor(DOOR_CLOSE_ALL);
1660 SetGameStatus(GAME_MODE_EDITOR);
1667 // leveldir_current may be invalid (level group, parent link, node copy)
1668 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1670 if (leveldir_current != leveldir_last_valid)
1672 UpdateLastPlayedLevels_TreeInfo();
1674 levelset_has_changed = TRUE;
1677 // store valid level series information
1678 leveldir_last_valid = leveldir_current;
1680 init_last = init; // switch to new busy animation
1682 // needed if last screen (level choice) changed graphics, sounds or music
1683 ReloadCustomArtwork(0);
1685 if (CheckTitleScreen(levelset_has_changed))
1687 SetGameStatus(GAME_MODE_TITLE);
1694 if (redraw_mask & REDRAW_ALL)
1695 fade_mask = REDRAW_ALL;
1698 fade_mask = REDRAW_ALL;
1702 // needed if different viewport properties defined for menues
1703 ChangeViewportPropertiesIfNeeded();
1705 SetDrawtoField(DRAW_TO_BACKBUFFER);
1707 // level_nr may have been set to value over handicap with level editor
1708 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1709 level_nr = leveldir_current->handicap_level;
1711 LoadLevel(level_nr);
1712 LoadScore(level_nr);
1714 SaveLevelSetup_SeriesInfo();
1716 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1717 SetDrawDeactivationMask(REDRAW_NONE);
1718 SetDrawBackgroundMask(REDRAW_FIELD);
1720 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1723 if (fade_mask == REDRAW_ALL)
1724 RedrawGlobalBorder();
1729 InitializeMainControls();
1731 DrawCursorAndText_Main(-1, FALSE, FALSE);
1732 DrawPreviewLevelInitial();
1733 DrawNetworkPlayers();
1735 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1738 if (TAPE_IS_EMPTY(tape))
1740 DrawCompleteVideoDisplay();
1742 PlayMenuSoundsAndMusic();
1744 // create gadgets for main menu screen
1745 FreeScreenGadgets();
1746 CreateScreenGadgets();
1748 // may be required if audio buttons shown on tape and changed in setup menu
1750 CreateGameButtons();
1752 // map gadgets for main menu screen
1754 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1755 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1757 // copy actual game door content to door double buffer for OpenDoor()
1758 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1759 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1761 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1763 DrawMaskedBorder(fade_mask);
1768 // update screen area with special editor door
1769 redraw_mask |= REDRAW_ALL;
1772 SetMouseCursor(CURSOR_DEFAULT);
1774 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1776 SyncEmscriptenFilesystem();
1778 // needed once after program start or after user change
1779 CheckApiServerTasks();
1782 static void gotoTopLevelDir(void)
1784 // move upwards until inside (but not above) top level directory
1785 while (leveldir_current->node_parent &&
1786 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1788 // write a "path" into level tree for easy navigation to last level
1789 if (leveldir_current->node_parent->node_group->cl_first == -1)
1791 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1792 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1793 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1794 int cl_first, cl_cursor;
1796 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1797 cl_cursor = leveldir_pos - cl_first;
1799 leveldir_current->node_parent->node_group->cl_first = cl_first;
1800 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1803 leveldir_current = leveldir_current->node_parent;
1807 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1809 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1811 return (use_frame_counter ? video.frame_counter : Counter());
1814 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1815 struct TitleFadingInfo *fi)
1817 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1820 static void ResetTitleAutoDelay(unsigned int *counter_var,
1821 struct TitleFadingInfo *fi)
1823 *counter_var = getAutoDelayCounter(fi);
1826 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1828 static unsigned int title_delay = 0;
1829 static int title_screen_nr = 0;
1830 static int last_sound = -1, last_music = -1;
1831 boolean return_to_main_menu = FALSE;
1832 struct TitleControlInfo *tci;
1835 if (button == MB_MENU_INITIALIZE)
1838 title_screen_nr = 0;
1839 tci = &title_controls[title_screen_nr];
1841 SetAnimStatus(getTitleAnimMode(tci));
1843 last_sound = SND_UNDEFINED;
1844 last_music = MUS_UNDEFINED;
1846 if (num_title_screens != 0)
1848 FadeSetEnterScreen();
1850 // use individual title fading instead of global "enter screen" fading
1851 fading = getTitleFading(tci);
1854 if (game_status_last_screen == GAME_MODE_INFO)
1856 if (num_title_screens == 0)
1858 // switch game mode from title screen mode back to info screen mode
1859 SetGameStatus(GAME_MODE_INFO);
1861 // store that last screen was info screen, not main menu screen
1862 game_status_last_screen = GAME_MODE_INFO;
1864 DrawInfoScreen_NotAvailable("Title screen information:",
1865 "No title screen for this level set.");
1870 FadeMenuSoundsAndMusic();
1872 FadeOut(REDRAW_ALL);
1874 // title screens may have different window size
1875 ChangeViewportPropertiesIfNeeded();
1877 // only required to update logic for redrawing global border
1881 DrawTitleScreenImage(tci->local_nr, tci->initial);
1883 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1885 sound = getTitleSound(tci);
1886 music = getTitleMusic(tci);
1888 if (sound != last_sound)
1889 PlayMenuSoundExt(sound);
1890 if (music != last_music)
1891 PlayMenuMusicExt(music);
1896 SetMouseCursor(CURSOR_NONE);
1900 ResetTitleAutoDelay(&title_delay, &fading);
1905 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1906 button = MB_MENU_CHOICE;
1908 if (button == MB_MENU_LEAVE)
1910 return_to_main_menu = TRUE;
1912 else if (button == MB_MENU_CHOICE)
1914 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1916 SetGameStatus(GAME_MODE_INFO);
1918 info_mode = INFO_MODE_MAIN;
1927 if (title_screen_nr < num_title_screens)
1929 tci = &title_controls[title_screen_nr];
1931 SetAnimStatus(getTitleAnimMode(tci));
1933 sound = getTitleSound(tci);
1934 music = getTitleMusic(tci);
1936 if (last_sound != SND_UNDEFINED && sound != last_sound)
1937 FadeSound(last_sound);
1938 if (last_music != MUS_UNDEFINED && music != last_music)
1941 fading = getTitleFading(tci);
1943 FadeOut(REDRAW_ALL);
1946 DrawTitleScreenImage(tci->local_nr, tci->initial);
1948 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1950 sound = getTitleSound(tci);
1951 music = getTitleMusic(tci);
1953 if (sound != last_sound)
1954 PlayMenuSoundExt(sound);
1955 if (music != last_music)
1956 PlayMenuMusicExt(music);
1963 ResetTitleAutoDelay(&title_delay, &fading);
1967 FadeMenuSoundsAndMusic();
1969 return_to_main_menu = TRUE;
1973 if (return_to_main_menu)
1975 SetMouseCursor(CURSOR_DEFAULT);
1977 // force full menu screen redraw after displaying title screens
1978 redraw_mask = REDRAW_ALL;
1980 if (game_status_last_screen == GAME_MODE_INFO)
1982 SetGameStatus(GAME_MODE_INFO);
1984 info_mode = INFO_MODE_MAIN;
1988 else // default: return to main menu
1990 SetGameStatus(GAME_MODE_MAIN);
1997 static void HandleMainMenu_ToggleTeamMode(void)
1999 setup.team_mode = !setup.team_mode;
2001 InitializeMainControls();
2002 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2004 DrawPreviewPlayers();
2007 static void HandleMainMenu_SelectLevel(int step, int direction,
2008 int selected_level_nr)
2010 int old_level_nr = level_nr;
2013 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2014 new_level_nr = selected_level_nr;
2016 new_level_nr = old_level_nr + step * direction;
2018 if (new_level_nr < leveldir_current->first_level)
2019 new_level_nr = leveldir_current->first_level;
2020 if (new_level_nr > leveldir_current->last_level)
2021 new_level_nr = leveldir_current->last_level;
2023 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2025 // skipping levels is only allowed when trying to skip single level
2026 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2027 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2029 leveldir_current->handicap_level++;
2030 SaveLevelSetup_SeriesInfo();
2033 new_level_nr = leveldir_current->handicap_level;
2036 if (new_level_nr != old_level_nr)
2038 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2040 PlaySound(SND_MENU_ITEM_SELECTING);
2042 level_nr = new_level_nr;
2044 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2045 int2str(level_nr, menu.main.text.level_number.size),
2046 mci->pos_text->font);
2048 LoadLevel(level_nr);
2049 DrawPreviewLevelInitial();
2053 DrawCompleteVideoDisplay();
2055 SaveLevelSetup_SeriesInfo();
2057 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2059 // force redraw of playfield area (may be reset at this point)
2060 redraw_mask |= REDRAW_FIELD;
2064 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2066 static int choice = MAIN_CONTROL_GAME;
2067 static boolean button_pressed_last = FALSE;
2068 boolean button_pressed = FALSE;
2070 int i = 0; // needed to prevent compiler warning due to bad code below
2072 if (button == MB_MENU_INITIALIZE)
2074 DrawCursorAndText_Main(choice, TRUE, FALSE);
2079 if (mx || my) // mouse input
2083 for (i = 0; main_controls[i].nr != -1; i++)
2085 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2086 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2087 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2089 pos = main_controls[i].nr;
2095 // check if level preview was clicked
2096 if (insidePreviewRect(&preview, mx - SX, my - SY))
2097 pos = MAIN_CONTROL_GAME;
2099 // handle pressed/unpressed state for active/inactive menu buttons
2100 // (if pos != -1, "i" contains index position corresponding to "pos")
2102 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2103 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2104 button_pressed = TRUE;
2106 if (button_pressed != button_pressed_last)
2108 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2111 PlaySound(SND_MENU_BUTTON_PRESSING);
2113 PlaySound(SND_MENU_BUTTON_RELEASING);
2116 else if (dx || dy) // keyboard input
2118 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2119 choice == MAIN_CONTROL_SETUP))
2120 button = MB_MENU_CHOICE;
2125 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2127 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2129 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2131 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2133 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2135 CloseDoor(DOOR_CLOSE_2);
2137 SetGameStatus(GAME_MODE_LEVELNR);
2139 DrawChooseLevelNr();
2141 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2147 PlaySound(SND_MENU_ITEM_ACTIVATING);
2149 DrawCursorAndText_Main(choice, FALSE, FALSE);
2150 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2156 if (choice == MAIN_CONTROL_NAME)
2158 // special case: cursor left or right pressed -- toggle team mode
2159 HandleMainMenu_ToggleTeamMode();
2161 else if (choice != MAIN_CONTROL_INFO &&
2162 choice != MAIN_CONTROL_SETUP)
2164 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2170 PlaySound(SND_MENU_ITEM_SELECTING);
2172 if (pos == MAIN_CONTROL_NAME)
2175 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2177 // special case: menu text "name/team" clicked -- toggle team mode
2178 HandleMainMenu_ToggleTeamMode();
2182 if (setup.multiple_users)
2184 CloseDoor(DOOR_CLOSE_2);
2186 SetGameStatus(GAME_MODE_NAMES);
2188 DrawChoosePlayerName();
2192 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2198 else if (pos == MAIN_CONTROL_LEVELS)
2202 CloseDoor(DOOR_CLOSE_2);
2204 SetGameStatus(GAME_MODE_LEVELS);
2206 SaveLevelSetup_LastSeries();
2207 SaveLevelSetup_SeriesInfo();
2209 // restore level set if chosen from "last played level set" menu
2210 RestoreLastPlayedLevels(&leveldir_current);
2212 if (setup.internal.choose_from_top_leveldir)
2215 DrawChooseLevelSet();
2218 else if (pos == MAIN_CONTROL_SCORES)
2220 CloseDoor(DOOR_CLOSE_2);
2222 SetGameStatus(GAME_MODE_SCORES);
2224 DrawHallOfFame(level_nr);
2226 else if (pos == MAIN_CONTROL_EDITOR)
2228 if (leveldir_current->readonly &&
2229 setup.editor.show_read_only_warning)
2230 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2232 CloseDoor(DOOR_CLOSE_ALL);
2234 SetGameStatus(GAME_MODE_EDITOR);
2236 FadeSetEnterScreen();
2240 else if (pos == MAIN_CONTROL_INFO)
2242 CloseDoor(DOOR_CLOSE_2);
2244 SetGameStatus(GAME_MODE_INFO);
2246 info_mode = INFO_MODE_MAIN;
2250 else if (pos == MAIN_CONTROL_GAME)
2252 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2254 else if (pos == MAIN_CONTROL_SETUP)
2256 CloseDoor(DOOR_CLOSE_2);
2258 SetGameStatus(GAME_MODE_SETUP);
2260 setup_mode = SETUP_MODE_MAIN;
2264 else if (pos == MAIN_CONTROL_QUIT)
2266 SaveLevelSetup_LastSeries();
2267 SaveLevelSetup_SeriesInfo();
2269 #if defined(PLATFORM_EMSCRIPTEN)
2270 Request("Close the browser window to quit!", REQ_CONFIRM);
2272 if (!setup.ask_on_quit_program ||
2273 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2274 SetGameStatus(GAME_MODE_QUIT);
2280 button_pressed_last = button_pressed;
2284 // ============================================================================
2285 // info screen functions
2286 // ============================================================================
2288 static struct TokenInfo *info_info;
2289 static int num_info_info; // number of info entries shown on screen
2290 static int max_info_info; // total number of info entries in list
2292 static void execInfoTitleScreen(void)
2294 info_mode = INFO_MODE_TITLE;
2299 static void execInfoElements(void)
2301 info_mode = INFO_MODE_ELEMENTS;
2306 static void execInfoMusic(void)
2308 info_mode = INFO_MODE_MUSIC;
2313 static void execInfoCredits(void)
2315 info_mode = INFO_MODE_CREDITS;
2320 static void execInfoProgram(void)
2322 info_mode = INFO_MODE_PROGRAM;
2327 static void execInfoVersion(void)
2329 info_mode = INFO_MODE_VERSION;
2334 static void execInfoLevelSet(void)
2336 info_mode = INFO_MODE_LEVELSET;
2341 static void execExitInfo(void)
2343 SetGameStatus(GAME_MODE_MAIN);
2348 static struct TokenInfo info_info_main[] =
2350 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2351 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2352 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2353 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2354 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2355 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2356 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2357 { TYPE_EMPTY, NULL, "" },
2358 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2363 static int getMenuTextFont(int type)
2365 if (type & (TYPE_SWITCH |
2379 static struct TokenInfo *setup_info;
2380 static struct TokenInfo setup_info_input[];
2382 static struct TokenInfo *menu_info;
2384 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2385 int screen_pos, int menu_info_pos_raw,
2388 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2389 struct TokenInfo *ti = &token_info[pos];
2390 int xpos = MENU_SCREEN_START_XPOS;
2391 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2392 int font_nr = getMenuTextFont(ti->type);
2394 if (setup_mode == SETUP_MODE_INPUT)
2395 font_nr = FONT_MENU_1;
2398 font_nr = FONT_ACTIVE(font_nr);
2400 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2402 if (ti->type & ~TYPE_SKIP_ENTRY)
2403 drawCursor(screen_pos, active);
2406 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2409 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2412 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2415 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2418 static char *window_size_text;
2419 static char *scaling_type_text;
2420 static char *network_server_text;
2422 static void drawSetupValue(int, int);
2424 static void drawMenuInfoList(int first_entry, int num_page_entries,
2425 int max_page_entries)
2429 if (first_entry + num_page_entries > max_page_entries)
2432 clearMenuListArea();
2434 for (i = 0; i < num_page_entries; i++)
2436 int menu_info_pos = first_entry + i;
2437 struct TokenInfo *si = &menu_info[menu_info_pos];
2438 void *value_ptr = si->value;
2440 // set some entries to "unchangeable" according to other variables
2441 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2442 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2443 (value_ptr == &setup.sound_music && !audio.music_available) ||
2444 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2445 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2446 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2447 si->type |= TYPE_GHOSTED;
2449 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2450 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2451 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2452 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2453 else if (si->type & ~TYPE_SKIP_ENTRY)
2454 initCursor(i, IMG_MENU_BUTTON);
2456 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2458 if (si->type & TYPE_STRING)
2462 if (value_ptr == &network_server_text)
2463 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2465 if (gadget_id != -1)
2467 struct GadgetInfo *gi = screen_gadget[gadget_id];
2468 int xpos = MENU_SCREEN_START_XPOS;
2469 int ypos = MENU_SCREEN_START_YPOS + i;
2470 int x = mSX + xpos * 32;
2471 int y = mSY + ypos * 32;
2473 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2477 if (si->type & TYPE_VALUE &&
2478 menu_info == setup_info)
2479 drawSetupValue(i, menu_info_pos);
2483 static void DrawInfoScreen_Main(void)
2485 int fade_mask = REDRAW_FIELD;
2488 if (redraw_mask & REDRAW_ALL)
2489 fade_mask = REDRAW_ALL;
2492 fade_mask = REDRAW_ALL;
2495 FadeMenuSoundsAndMusic();
2497 FreeScreenGadgets();
2498 CreateScreenGadgets();
2500 // (needed after displaying title screens which disable auto repeat)
2501 KeyboardAutoRepeatOn();
2503 FadeSetLeaveScreen();
2507 // needed if different viewport properties defined for info screen
2508 ChangeViewportPropertiesIfNeeded();
2510 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2514 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2516 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2518 info_info = info_info_main;
2520 // determine maximal number of info entries that can be displayed on screen
2522 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2525 // determine maximal number of info entries available for menu of info screen
2527 for (i = 0; info_info[i].type != 0; i++)
2530 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2532 MapScreenGadgets(max_info_info);
2534 PlayMenuSoundsAndMusic();
2536 DrawMaskedBorder(fade_mask);
2541 static void changeSetupValue(int, int, int);
2543 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2544 int mode, int num_page_entries,
2545 int max_page_entries)
2547 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2548 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2549 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2550 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2551 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2552 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2553 int *num_page_entries_last = num_page_entries_all_last[game_status];
2554 int *choice_store = choice_stores[game_status];
2555 int *first_entry_store = first_entry_stores[game_status];
2556 int choice = choice_store[mode]; // starts with 0
2557 int first_entry = first_entry_store[mode]; // starts with 0
2559 int y = choice - first_entry;
2561 boolean position_set_by_scrollbar = (dx == 999);
2562 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2565 if (button == MB_MENU_INITIALIZE)
2567 // check if number of menu page entries has changed (may happen by change
2568 // of custom artwork definition value for 'list_size' for this menu screen)
2569 // (in this case, the last menu position most probably has to be corrected)
2570 if (num_page_entries != num_page_entries_last[mode])
2572 choice_store[mode] = first_entry_store[mode] = 0;
2574 choice = first_entry = 0;
2577 num_page_entries_last[mode] = num_page_entries;
2580 // advance to first valid menu entry
2581 while (choice < num_page_entries &&
2582 menu_info[choice].type & TYPE_SKIP_ENTRY)
2585 if (position_set_by_scrollbar)
2586 first_entry = first_entry_store[mode] = dy;
2588 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2589 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2591 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2593 if (choice < first_entry)
2595 choice = first_entry;
2597 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2600 else if (choice > first_entry + num_page_entries - 1)
2602 choice = first_entry + num_page_entries - 1;
2604 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2608 choice_store[mode] = choice;
2610 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2614 else if (button == MB_MENU_LEAVE)
2616 PlaySound(SND_MENU_ITEM_SELECTING);
2618 for (i = 0; i < max_page_entries; i++)
2620 if (menu_info[i].type & TYPE_LEAVE_MENU)
2622 void (*menu_callback_function)(void) = menu_info[i].value;
2626 menu_callback_function();
2628 break; // absolutely needed because function changes 'menu_info'!
2635 if (mx || my) // mouse input
2637 x = (mx - mSX) / 32;
2638 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2640 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2642 // move cursor instead of scrolling when already at start/end of list
2643 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2645 else if (dy == +1 * SCROLL_LINE &&
2646 first_entry + num_page_entries == max_page_entries)
2649 // handle scrolling screen one line or page
2651 y + dy > num_page_entries - 1)
2653 boolean redraw = FALSE;
2655 if (ABS(dy) == SCROLL_PAGE)
2656 step = num_page_entries - 1;
2658 if (dy < 0 && first_entry > 0)
2660 // scroll page/line up
2662 first_entry -= step;
2663 if (first_entry < 0)
2668 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2670 // scroll page/line down
2672 first_entry += step;
2673 if (first_entry + num_page_entries > max_page_entries)
2674 first_entry = MAX(0, max_page_entries - num_page_entries);
2681 choice += first_entry - first_entry_store[mode];
2683 if (choice < first_entry)
2685 choice = first_entry;
2687 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2690 else if (choice > first_entry + num_page_entries - 1)
2692 choice = first_entry + num_page_entries - 1;
2694 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2697 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2701 if (choice < first_entry ||
2702 choice > first_entry + num_page_entries - 1)
2703 first_entry += SIGN(dy);
2706 first_entry_store[mode] = first_entry;
2707 choice_store[mode] = choice;
2709 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2711 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2713 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2714 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2722 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2724 if (menu_info[choice].type & menu_navigation_type ||
2725 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2726 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2727 menu_info[choice].type & TYPE_PLAYER)
2728 button = MB_MENU_CHOICE;
2733 // jump to next non-empty menu entry (up or down)
2734 while (first_entry + y > 0 &&
2735 first_entry + y < max_page_entries - 1 &&
2736 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2739 if (!IN_VIS_MENU(x, y))
2741 choice += y - y_old;
2743 if (choice < first_entry)
2744 first_entry = choice;
2745 else if (choice > first_entry + num_page_entries - 1)
2746 first_entry = choice - num_page_entries + 1;
2748 if (first_entry >= 0 &&
2749 first_entry + num_page_entries <= max_page_entries)
2751 first_entry_store[mode] = first_entry;
2753 if (choice < first_entry)
2754 choice = first_entry;
2755 else if (choice > first_entry + num_page_entries - 1)
2756 choice = first_entry + num_page_entries - 1;
2758 choice_store[mode] = choice;
2760 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2762 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2764 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2765 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2772 if (!anyScrollbarGadgetActive() &&
2773 IN_VIS_MENU(x, y) &&
2774 mx < mx_right_border &&
2775 y >= 0 && y < num_page_entries)
2779 if (first_entry + y != choice &&
2780 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2782 PlaySound(SND_MENU_ITEM_ACTIVATING);
2784 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2785 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2787 choice = choice_store[mode] = first_entry + y;
2791 PlaySound(SND_MENU_ITEM_SELECTING);
2793 for (i = 0; menu_info[i].type != 0; i++)
2795 if (menu_info[i].type & TYPE_LEAVE_MENU)
2797 void (*menu_callback_function)(void) = menu_info[i].value;
2801 menu_callback_function();
2803 // absolutely needed because function changes 'menu_info'!
2811 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2813 PlaySound(SND_MENU_ITEM_SELECTING);
2815 // when selecting key headline, execute function for key value change
2816 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2817 menu_info[first_entry + y + 1].type & TYPE_KEY)
2820 // when selecting string value, execute function for list selection
2821 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2822 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2825 // when selecting string value, execute function for text input gadget
2826 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2827 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2830 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2832 void (*menu_callback_function)(void) =
2833 menu_info[first_entry + y].value;
2835 FadeSetFromType(menu_info[first_entry + y].type);
2837 menu_callback_function();
2839 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2841 void (*gadget_callback_function)(void) =
2842 menu_info[first_entry + y].value;
2844 gadget_callback_function();
2846 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2847 menu_info == setup_info)
2849 changeSetupValue(y, first_entry + y, dx);
2855 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2857 menu_info = info_info;
2859 HandleMenuScreen(mx, my, dx, dy, button,
2860 info_mode, num_info_info, max_info_info);
2863 static int getMenuFontSpacing(int spacing_height, int font_nr)
2865 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2867 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2871 static int getMenuTextSpacing(int spacing_height, int font_nr)
2873 return (getMenuFontSpacing(spacing_height, font_nr) +
2874 EXTRA_SPACING(game_status));
2877 static int getMenuTextStep(int spacing_height, int font_nr)
2879 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2882 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2884 int font_title = MENU_INFO_FONT_TITLE;
2885 int font_error = FONT_TEXT_2;
2886 int font_foot = MENU_INFO_FONT_FOOT;
2887 int spacing_title = menu.headline1_spacing_info[info_mode];
2888 int ystep_title = getMenuTextStep(spacing_title, font_title);
2889 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2890 int ystart2 = ystart1 + ystep_title;
2891 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2893 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2895 FadeOut(REDRAW_FIELD);
2900 DrawTextSCentered(ystart1, font_title, text_title);
2901 DrawTextSCentered(ystart2, font_error, text_error);
2903 DrawTextSCentered(ybottom, font_foot,
2904 "Press any key or button for info menu");
2906 FadeIn(REDRAW_FIELD);
2909 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2911 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2912 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2913 int font_title = MENU_INFO_FONT_TITLE;
2914 int font_foot = MENU_INFO_FONT_FOOT;
2915 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2916 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2917 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2918 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2919 int ystep = MENU_SCREEN_INFO_YSTEP;
2920 int element, action, direction;
2928 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2929 infoscreen_step[i] = infoscreen_frame[i] = 0;
2934 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2936 DrawTextSCentered(ybottom, font_foot,
2937 "Press any key or button for next page");
2943 while (helpanim_info[j].element != HELPANIM_LIST_END)
2945 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2950 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2959 j += infoscreen_step[i - start];
2961 element = helpanim_info[j].element;
2962 action = helpanim_info[j].action;
2963 direction = helpanim_info[j].direction;
2966 element = EL_UNKNOWN;
2968 if (action != -1 && direction != -1)
2969 graphic = el_act_dir2img(element, action, direction);
2970 else if (action != -1)
2971 graphic = el_act2img(element, action);
2972 else if (direction != -1)
2973 graphic = el_dir2img(element, direction);
2975 graphic = el2img(element);
2977 delay = helpanim_info[j++].delay;
2982 if (infoscreen_frame[i - start] == 0)
2985 infoscreen_frame[i - start] = delay - 1;
2989 sync_frame = delay - infoscreen_frame[i - start];
2990 infoscreen_frame[i - start]--;
2993 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2995 if (!infoscreen_frame[i - start])
2996 infoscreen_step[i - start] = 0;
3000 if (!infoscreen_frame[i - start])
3001 infoscreen_step[i - start]++;
3002 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3008 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3010 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3011 graphic, sync_frame, USE_MASKING);
3014 DrawInfoScreen_HelpText(element, action, direction, i - start);
3019 redraw_mask |= REDRAW_FIELD;
3024 static char *getHelpText(int element, int action, int direction)
3026 char token[MAX_LINE_LEN];
3028 strcpy(token, element_info[element].token_name);
3031 strcat(token, element_action_info[action].suffix);
3033 if (direction != -1)
3034 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3036 return getHashEntry(helptext_info, token);
3039 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3041 int font_nr = FONT_INFO_ELEMENTS;
3042 int font_width = getFontWidth(font_nr);
3043 int font_height = getFontHeight(font_nr);
3044 int yoffset = (TILEX - 2 * font_height) / 2;
3045 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3046 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3047 int ystep = TILEY + 4;
3048 int pad_left = xstart - SX;
3049 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3050 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3051 int max_lines_per_text = 2;
3054 if (action != -1 && direction != -1) // element.action.direction
3055 text = getHelpText(element, action, direction);
3057 if (text == NULL && action != -1) // element.action
3058 text = getHelpText(element, action, -1);
3060 if (text == NULL && direction != -1) // element.direction
3061 text = getHelpText(element, -1, direction);
3063 if (text == NULL) // base element
3064 text = getHelpText(element, -1, -1);
3066 if (text == NULL) // not found
3067 text = "No description available";
3069 if (strlen(text) <= max_chars_per_line) // only one line of text
3070 ystart += getFontHeight(font_nr) / 2;
3072 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3073 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3074 TRUE, FALSE, FALSE);
3077 static void DrawInfoScreen_TitleScreen(void)
3079 SetGameStatus(GAME_MODE_TITLE);
3084 void HandleInfoScreen_TitleScreen(int button)
3086 HandleTitleScreen(0, 0, 0, 0, button);
3089 static void DrawInfoScreen_Elements(void)
3091 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3093 FadeOut(REDRAW_FIELD);
3098 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3100 FadeIn(REDRAW_FIELD);
3103 void HandleInfoScreen_Elements(int button)
3105 static unsigned int info_delay = 0;
3106 static int num_anims;
3107 static int num_pages;
3109 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3112 if (button == MB_MENU_INITIALIZE)
3114 boolean new_element = TRUE;
3118 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3120 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3122 else if (new_element)
3125 new_element = FALSE;
3129 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3133 if (button == MB_MENU_LEAVE)
3135 PlaySound(SND_MENU_ITEM_SELECTING);
3137 info_mode = INFO_MODE_MAIN;
3142 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3144 if (button != MB_MENU_INITIALIZE)
3146 PlaySound(SND_MENU_ITEM_SELECTING);
3151 if (page >= num_pages)
3153 FadeMenuSoundsAndMusic();
3155 info_mode = INFO_MODE_MAIN;
3162 FadeSetNextScreen();
3164 if (button != MB_MENU_INITIALIZE)
3165 FadeOut(REDRAW_FIELD);
3167 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3169 if (button != MB_MENU_INITIALIZE)
3170 FadeIn(REDRAW_FIELD);
3174 if (DelayReached(&info_delay, GameFrameDelay))
3175 if (page < num_pages)
3176 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3178 PlayMenuSoundIfLoop();
3182 static void DrawInfoScreen_Music(void)
3184 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3186 FadeOut(REDRAW_FIELD);
3193 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3195 FadeIn(REDRAW_FIELD);
3198 void HandleInfoScreen_Music(int button)
3200 static struct MusicFileInfo *list = NULL;
3201 int font_title = MENU_INFO_FONT_TITLE;
3202 int font_head = MENU_INFO_FONT_HEAD;
3203 int font_text = MENU_INFO_FONT_TEXT;
3204 int font_foot = MENU_INFO_FONT_FOOT;
3205 int spacing_title = menu.headline1_spacing_info[info_mode];
3206 int spacing_head = menu.headline2_spacing_info[info_mode];
3207 int ystep_title = getMenuTextStep(spacing_title, font_title);
3208 int ystep_head = getMenuTextStep(spacing_head, font_head);
3209 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3210 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3212 if (button == MB_MENU_INITIALIZE)
3214 list = music_file_info;
3218 FadeMenuSoundsAndMusic();
3223 DrawTextSCentered(ystart, font_title,
3224 "No music info for this level set.");
3226 DrawTextSCentered(ybottom, font_foot,
3227 "Press any key or button for info menu");
3233 if (button == MB_MENU_LEAVE)
3235 PlaySound(SND_MENU_ITEM_SELECTING);
3237 FadeMenuSoundsAndMusic();
3239 info_mode = INFO_MODE_MAIN;
3244 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3246 if (button != MB_MENU_INITIALIZE)
3248 PlaySound(SND_MENU_ITEM_SELECTING);
3256 FadeMenuSoundsAndMusic();
3258 info_mode = INFO_MODE_MAIN;
3264 FadeMenuSoundsAndMusic();
3266 if (list != music_file_info)
3267 FadeSetNextScreen();
3269 if (button != MB_MENU_INITIALIZE)
3270 FadeOut(REDRAW_FIELD);
3277 int sound = list->music;
3279 if (IS_LOOP_SOUND(sound))
3280 PlaySoundLoop(sound);
3284 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3288 int music = list->music;
3290 if (IS_LOOP_MUSIC(music))
3291 PlayMusicLoop(music);
3295 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3298 ystart += ystep_title;
3300 if (!strEqual(list->title, UNKNOWN_NAME))
3302 if (!strEqual(list->title_header, UNKNOWN_NAME))
3304 DrawTextSCentered(ystart, font_head, list->title_header);
3305 ystart += ystep_head;
3308 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3309 ystart += ystep_head;
3312 if (!strEqual(list->artist, UNKNOWN_NAME))
3314 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3315 DrawTextSCentered(ystart, font_head, list->artist_header);
3317 DrawTextSCentered(ystart, font_head, "by");
3319 ystart += ystep_head;
3321 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3322 ystart += ystep_head;
3325 if (!strEqual(list->album, UNKNOWN_NAME))
3327 if (!strEqual(list->album_header, UNKNOWN_NAME))
3328 DrawTextSCentered(ystart, font_head, list->album_header);
3330 DrawTextSCentered(ystart, font_head, "from the album");
3332 ystart += ystep_head;
3334 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3335 ystart += ystep_head;
3338 if (!strEqual(list->year, UNKNOWN_NAME))
3340 if (!strEqual(list->year_header, UNKNOWN_NAME))
3341 DrawTextSCentered(ystart, font_head, list->year_header);
3343 DrawTextSCentered(ystart, font_head, "from the year");
3345 ystart += ystep_head;
3347 DrawTextFCentered(ystart, font_text, "%s", list->year);
3348 ystart += ystep_head;
3351 DrawTextSCentered(ybottom, FONT_TEXT_4,
3352 "Press any key or button for next page");
3354 if (button != MB_MENU_INITIALIZE)
3355 FadeIn(REDRAW_FIELD);
3358 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3359 PlaySoundLoop(list->music);
3362 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3364 int font_title = MENU_INFO_FONT_TITLE;
3365 int font_head = MENU_INFO_FONT_HEAD;
3366 int font_text = MENU_INFO_FONT_TEXT;
3367 int font_foot = MENU_INFO_FONT_FOOT;
3368 int spacing_title = menu.headline1_spacing_info[info_mode];
3369 int spacing_head = menu.headline2_spacing_info[info_mode];
3370 int spacing_para = menu.paragraph_spacing_info[info_mode];
3371 int spacing_line = menu.line_spacing_info[info_mode];
3372 int ystep_title = getMenuTextStep(spacing_title, font_title);
3373 int ystep_head = getMenuTextStep(spacing_head, font_head);
3374 int ystep_para = getMenuTextStep(spacing_para, font_text);
3375 int ystep_line = getMenuTextStep(spacing_line, font_text);
3376 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3377 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3382 DrawTextSCentered(ystart, font_title, "Credits:");
3383 ystart += ystep_title;
3387 DrawTextSCentered(ystart, font_head,
3388 "Special thanks to");
3389 ystart += ystep_head;
3390 DrawTextSCentered(ystart, font_text,
3392 ystart += ystep_head;
3393 DrawTextSCentered(ystart, font_head,
3395 ystart += ystep_head;
3396 DrawTextSCentered(ystart, font_text,
3397 "\"Boulder Dash\"");
3398 ystart += ystep_head;
3399 DrawTextSCentered(ystart, font_head,
3401 ystart += ystep_head;
3402 DrawTextSCentered(ystart, font_text,
3404 ystart += ystep_head;
3405 DrawTextSCentered(ystart, font_head,
3407 ystart += ystep_head;
3408 DrawTextSCentered(ystart, font_text,
3409 "First Star Software");
3411 else if (screen_nr == 1)
3413 DrawTextSCentered(ystart, font_head,
3414 "Special thanks to");
3415 ystart += ystep_head;
3416 DrawTextSCentered(ystart, font_text,
3417 "Klaus Heinz & Volker Wertich");
3418 ystart += ystep_head;
3419 DrawTextSCentered(ystart, font_head,
3421 ystart += ystep_head;
3422 DrawTextSCentered(ystart, font_text,
3423 "\"Emerald Mine\"");
3424 ystart += ystep_head;
3425 DrawTextSCentered(ystart, font_head,
3427 ystart += ystep_head;
3428 DrawTextSCentered(ystart, font_text,
3430 ystart += ystep_head;
3431 DrawTextSCentered(ystart, font_head,
3433 ystart += ystep_head;
3434 DrawTextSCentered(ystart, font_text,
3437 else if (screen_nr == 2)
3439 DrawTextSCentered(ystart, font_head,
3440 "Special thanks to");
3441 ystart += ystep_head;
3442 DrawTextSCentered(ystart, font_text,
3443 "Michael Stopp & Philip Jespersen");
3444 ystart += ystep_head;
3445 DrawTextSCentered(ystart, font_head,
3447 ystart += ystep_head;
3448 DrawTextSCentered(ystart, font_text,
3450 ystart += ystep_head;
3451 DrawTextSCentered(ystart, font_head,
3453 ystart += ystep_head;
3454 DrawTextSCentered(ystart, font_text,
3456 ystart += ystep_head;
3457 DrawTextSCentered(ystart, font_head,
3459 ystart += ystep_head;
3460 DrawTextSCentered(ystart, font_text,
3461 "Digital Integration");
3463 else if (screen_nr == 3)
3465 DrawTextSCentered(ystart, font_head,
3466 "Special thanks to");
3467 ystart += ystep_head;
3468 DrawTextSCentered(ystart, font_text,
3469 "Hiroyuki Imabayashi");
3470 ystart += ystep_head;
3471 DrawTextSCentered(ystart, font_head,
3473 ystart += ystep_head;
3474 DrawTextSCentered(ystart, font_text,
3476 ystart += ystep_head;
3477 DrawTextSCentered(ystart, font_head,
3479 ystart += ystep_head;
3480 DrawTextSCentered(ystart, font_text,
3482 ystart += ystep_head;
3483 DrawTextSCentered(ystart, font_head,
3485 ystart += ystep_head;
3486 DrawTextSCentered(ystart, font_text,
3489 else if (screen_nr == 4)
3491 DrawTextSCentered(ystart, font_head,
3492 "Special thanks to");
3493 ystart += ystep_head;
3494 DrawTextSCentered(ystart, font_text,
3496 ystart += ystep_head;
3497 DrawTextSCentered(ystart, font_head,
3499 ystart += ystep_head;
3500 DrawTextSCentered(ystart, font_text,
3501 "J\xfcrgen Bonhagen");
3502 ystart += ystep_head;
3503 DrawTextSCentered(ystart, font_head,
3504 "for the continuous creation");
3505 ystart += ystep_line;
3506 DrawTextSCentered(ystart, font_head,
3507 "of outstanding level sets");
3509 else if (screen_nr == 5)
3511 DrawTextSCentered(ystart, font_head,
3513 ystart += ystep_head;
3514 DrawTextSCentered(ystart, font_text,
3516 ystart += ystep_head;
3517 DrawTextSCentered(ystart, font_head,
3518 "for ideas and inspiration by");
3519 ystart += ystep_head;
3520 DrawTextSCentered(ystart, font_text,
3522 ystart += ystep_para;
3524 DrawTextSCentered(ystart, font_head,
3526 ystart += ystep_head;
3527 DrawTextSCentered(ystart, font_text,
3529 ystart += ystep_head;
3530 DrawTextSCentered(ystart, font_head,
3531 "for ideas and inspiration by");
3532 ystart += ystep_head;
3533 DrawTextSCentered(ystart, font_text,
3536 else if (screen_nr == 6)
3538 DrawTextSCentered(ystart, font_head,
3540 ystart += ystep_head;
3541 DrawTextSCentered(ystart, font_text,
3543 ystart += ystep_head;
3544 DrawTextSCentered(ystart, font_head,
3545 "for the code base used for the");
3546 ystart += ystep_line;
3547 DrawTextSCentered(ystart, font_head,
3548 "native Emerald Mine engine");
3550 else if (screen_nr == 7)
3552 DrawTextSCentered(ystart, font_head,
3554 ystart += ystep_head;
3555 DrawTextSCentered(ystart, font_text,
3557 ystart += ystep_head;
3558 DrawTextSCentered(ystart, font_head,
3559 "for the initial DOS port");
3560 ystart += ystep_para;
3562 DrawTextSCentered(ystart, font_head,
3564 ystart += ystep_head;
3565 DrawTextSCentered(ystart, font_text,
3567 ystart += ystep_head;
3568 DrawTextSCentered(ystart, font_head,
3569 "for some additional toons");
3571 else if (screen_nr == 8)
3573 DrawTextSCentered(ystart, font_head,
3574 "And not to forget:");
3575 ystart += ystep_head;
3576 DrawTextSCentered(ystart, font_head,
3578 ystart += ystep_head;
3579 DrawTextSCentered(ystart, font_text,
3580 "All those who contributed");
3581 ystart += ystep_line;
3582 DrawTextSCentered(ystart, font_text,
3583 "levels to this game");
3584 ystart += ystep_line;
3585 DrawTextSCentered(ystart, font_text,
3589 DrawTextSCentered(ybottom, font_foot,
3590 "Press any key or button for next page");
3593 static void DrawInfoScreen_Credits(void)
3595 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3597 FadeMenuSoundsAndMusic();
3599 FadeOut(REDRAW_FIELD);
3601 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3603 FadeIn(REDRAW_FIELD);
3606 void HandleInfoScreen_Credits(int button)
3608 static int screen_nr = 0;
3609 int num_screens = 9;
3611 if (button == MB_MENU_INITIALIZE)
3615 // DrawInfoScreen_CreditsScreen(screen_nr);
3618 if (button == MB_MENU_LEAVE)
3620 PlaySound(SND_MENU_ITEM_SELECTING);
3622 info_mode = INFO_MODE_MAIN;
3627 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3629 if (button != MB_MENU_INITIALIZE)
3631 PlaySound(SND_MENU_ITEM_SELECTING);
3636 if (screen_nr >= num_screens)
3638 FadeMenuSoundsAndMusic();
3640 info_mode = INFO_MODE_MAIN;
3647 FadeSetNextScreen();
3649 if (button != MB_MENU_INITIALIZE)
3650 FadeOut(REDRAW_FIELD);
3652 DrawInfoScreen_CreditsScreen(screen_nr);
3654 if (button != MB_MENU_INITIALIZE)
3655 FadeIn(REDRAW_FIELD);
3659 PlayMenuSoundIfLoop();
3663 static void DrawInfoScreen_Program(void)
3665 int font_title = MENU_INFO_FONT_TITLE;
3666 int font_head = MENU_INFO_FONT_HEAD;
3667 int font_text = MENU_INFO_FONT_TEXT;
3668 int font_foot = MENU_INFO_FONT_FOOT;
3669 int spacing_title = menu.headline1_spacing_info[info_mode];
3670 int spacing_head = menu.headline2_spacing_info[info_mode];
3671 int spacing_para = menu.paragraph_spacing_info[info_mode];
3672 int spacing_line = menu.line_spacing_info[info_mode];
3673 int ystep_title = getMenuTextStep(spacing_title, font_title);
3674 int ystep_head = getMenuTextStep(spacing_head, font_head);
3675 int ystep_para = getMenuTextStep(spacing_para, font_text);
3676 int ystep_line = getMenuTextStep(spacing_line, font_text);
3677 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3678 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3680 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3682 FadeOut(REDRAW_FIELD);
3687 DrawTextSCentered(ystart, font_title, "Program Information:");
3688 ystart += ystep_title;
3690 DrawTextSCentered(ystart, font_head,
3691 "This game is Freeware!");
3692 ystart += ystep_head;
3693 DrawTextSCentered(ystart, font_head,
3694 "If you like it, send e-mail to:");
3695 ystart += ystep_head;
3696 DrawTextSCentered(ystart, font_text,
3697 setup.internal.program_email);
3698 ystart += ystep_para;
3700 DrawTextSCentered(ystart, font_head,
3701 "More information and levels:");
3702 ystart += ystep_head;
3703 DrawTextSCentered(ystart, font_text,
3704 setup.internal.program_website);
3705 ystart += ystep_para;
3707 DrawTextSCentered(ystart, font_head,
3708 "If you have created new levels,");
3709 ystart += ystep_line;
3710 DrawTextSCentered(ystart, font_head,
3711 "send them to me to include them!");
3712 ystart += ystep_head;
3713 DrawTextSCentered(ystart, font_head,
3716 DrawTextSCentered(ybottom, font_foot,
3717 "Press any key or button for info menu");
3719 FadeIn(REDRAW_FIELD);
3722 void HandleInfoScreen_Program(int button)
3724 if (button == MB_MENU_LEAVE)
3726 PlaySound(SND_MENU_ITEM_SELECTING);
3728 info_mode = INFO_MODE_MAIN;
3733 else if (button == MB_MENU_CHOICE)
3735 PlaySound(SND_MENU_ITEM_SELECTING);
3737 FadeMenuSoundsAndMusic();
3739 info_mode = INFO_MODE_MAIN;
3744 PlayMenuSoundIfLoop();
3748 static void DrawInfoScreen_Version(void)
3750 int font_title = MENU_INFO_FONT_TITLE;
3751 int font_head = MENU_INFO_FONT_HEAD;
3752 int font_text = MENU_INFO_FONT_TEXT;
3753 int font_foot = MENU_INFO_FONT_FOOT;
3754 int spacing_title = menu.headline1_spacing_info[info_mode];
3755 int spacing_head = menu.headline2_spacing_info[info_mode];
3756 int spacing_para = menu.paragraph_spacing_info[info_mode];
3757 int spacing_line = menu.line_spacing_info[info_mode];
3758 int xstep = getFontWidth(font_text);
3759 int ystep_title = getMenuTextStep(spacing_title, font_title);
3760 int ystep_head = getMenuTextStep(spacing_head, font_head);
3761 int ystep_para = getMenuTextStep(spacing_para, font_text);
3762 int ystep_line = getMenuTextStep(spacing_line, font_text);
3763 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3764 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3765 int xstart1 = mSX - SX + 2 * xstep;
3766 int xstart2 = mSX - SX + 18 * xstep;
3767 int xstart3 = mSX - SX + 28 * xstep;
3768 SDL_version sdl_version_compiled;
3769 const SDL_version *sdl_version_linked;
3770 int driver_name_len = 10;
3771 SDL_version sdl_version_linked_ext;
3772 const char *driver_name = NULL;
3774 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3776 FadeOut(REDRAW_FIELD);
3781 DrawTextSCentered(ystart, font_title, "Version Information:");
3782 ystart += ystep_title;
3784 DrawTextF(xstart1, ystart, font_head, "Name");
3785 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3786 ystart += ystep_line;
3788 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3790 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3791 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3792 ystart += ystep_line;
3794 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3795 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3796 ystart += ystep_line;
3800 DrawTextF(xstart1, ystart, font_head, "Version");
3801 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3802 ystart += ystep_line;
3805 DrawTextF(xstart1, ystart, font_head, "Platform");
3806 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3808 PLATFORM_XX_BIT_STRING);
3809 ystart += ystep_line;
3811 DrawTextF(xstart1, ystart, font_head, "Target");
3812 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3813 ystart += ystep_line;
3815 DrawTextF(xstart1, ystart, font_head, "Source date");
3816 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3817 ystart += ystep_line;
3819 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3820 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3821 ystart += ystep_para;
3823 DrawTextF(xstart1, ystart, font_head, "Library");
3824 DrawTextF(xstart2, ystart, font_head, "compiled");
3825 DrawTextF(xstart3, ystart, font_head, "linked");
3826 ystart += ystep_head;
3828 SDL_VERSION(&sdl_version_compiled);
3829 SDL_GetVersion(&sdl_version_linked_ext);
3830 sdl_version_linked = &sdl_version_linked_ext;
3832 DrawTextF(xstart1, ystart, font_text, "SDL");
3833 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3834 sdl_version_compiled.major,
3835 sdl_version_compiled.minor,
3836 sdl_version_compiled.patch);
3837 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3838 sdl_version_linked->major,
3839 sdl_version_linked->minor,
3840 sdl_version_linked->patch);
3841 ystart += ystep_line;
3843 SDL_IMAGE_VERSION(&sdl_version_compiled);
3844 sdl_version_linked = IMG_Linked_Version();
3846 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3847 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3848 sdl_version_compiled.major,
3849 sdl_version_compiled.minor,
3850 sdl_version_compiled.patch);
3851 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3852 sdl_version_linked->major,
3853 sdl_version_linked->minor,
3854 sdl_version_linked->patch);
3855 ystart += ystep_line;
3857 SDL_MIXER_VERSION(&sdl_version_compiled);
3858 sdl_version_linked = Mix_Linked_Version();
3860 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3861 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3862 sdl_version_compiled.major,
3863 sdl_version_compiled.minor,
3864 sdl_version_compiled.patch);
3865 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3866 sdl_version_linked->major,
3867 sdl_version_linked->minor,
3868 sdl_version_linked->patch);
3869 ystart += ystep_line;
3871 SDL_NET_VERSION(&sdl_version_compiled);
3872 sdl_version_linked = SDLNet_Linked_Version();
3874 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3875 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3876 sdl_version_compiled.major,
3877 sdl_version_compiled.minor,
3878 sdl_version_compiled.patch);
3879 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3880 sdl_version_linked->major,
3881 sdl_version_linked->minor,
3882 sdl_version_linked->patch);
3883 ystart += ystep_para;
3885 DrawTextF(xstart1, ystart, font_head, "Driver");
3886 DrawTextF(xstart2, ystart, font_head, "Requested");
3887 DrawTextF(xstart3, ystart, font_head, "Used");
3888 ystart += ystep_head;
3891 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3893 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3894 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3895 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3896 ystart += ystep_line;
3899 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3901 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3902 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3903 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3904 ystart += ystep_line;
3907 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3909 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3910 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3911 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3913 DrawTextSCentered(ybottom, font_foot,
3914 "Press any key or button for info menu");
3916 FadeIn(REDRAW_FIELD);
3919 void HandleInfoScreen_Version(int button)
3921 if (button == MB_MENU_LEAVE)
3923 PlaySound(SND_MENU_ITEM_SELECTING);
3925 info_mode = INFO_MODE_MAIN;
3930 else if (button == MB_MENU_CHOICE)
3932 PlaySound(SND_MENU_ITEM_SELECTING);
3934 FadeMenuSoundsAndMusic();
3936 info_mode = INFO_MODE_MAIN;
3941 PlayMenuSoundIfLoop();
3945 static void DrawInfoScreen_LevelSet(void)
3947 struct TitleMessageInfo *tmi = &readme;
3948 char *filename = getLevelSetInfoFilename();
3949 char *title = "Level Set Information:";
3950 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3951 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3953 if (filename == NULL)
3955 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3960 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3962 FadeOut(REDRAW_FIELD);
3967 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3969 // if x position set to "-1", automatically determine by playfield width
3971 tmi->x = SXSIZE / 2;
3973 // if y position set to "-1", use static default value
3977 // if width set to "-1", automatically determine by playfield width
3978 if (tmi->width == -1)
3979 tmi->width = SXSIZE - 2 * TILEX;
3981 // if height set to "-1", automatically determine by playfield height
3982 if (tmi->height == -1)
3983 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3985 // if chars set to "-1", automatically determine by text and font width
3986 if (tmi->chars == -1)
3987 tmi->chars = tmi->width / getFontWidth(tmi->font);
3989 tmi->width = tmi->chars * getFontWidth(tmi->font);
3991 // if lines set to "-1", automatically determine by text and font height
3992 if (tmi->lines == -1)
3993 tmi->lines = tmi->height / getFontHeight(tmi->font);
3995 tmi->height = tmi->lines * getFontHeight(tmi->font);
3997 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3998 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3999 tmi->autowrap, tmi->centered, tmi->parse_comments);
4001 DrawTextSCentered(ybottom, FONT_TEXT_4,
4002 "Press any key or button for info menu");
4004 FadeIn(REDRAW_FIELD);
4007 static void HandleInfoScreen_LevelSet(int button)
4009 if (button == MB_MENU_LEAVE)
4011 PlaySound(SND_MENU_ITEM_SELECTING);
4013 info_mode = INFO_MODE_MAIN;
4018 else if (button == MB_MENU_CHOICE)
4020 PlaySound(SND_MENU_ITEM_SELECTING);
4022 FadeMenuSoundsAndMusic();
4024 info_mode = INFO_MODE_MAIN;
4029 PlayMenuSoundIfLoop();
4033 static void DrawInfoScreen(void)
4035 if (info_mode == INFO_MODE_TITLE)
4036 DrawInfoScreen_TitleScreen();
4037 else if (info_mode == INFO_MODE_ELEMENTS)
4038 DrawInfoScreen_Elements();
4039 else if (info_mode == INFO_MODE_MUSIC)
4040 DrawInfoScreen_Music();
4041 else if (info_mode == INFO_MODE_CREDITS)
4042 DrawInfoScreen_Credits();
4043 else if (info_mode == INFO_MODE_PROGRAM)
4044 DrawInfoScreen_Program();
4045 else if (info_mode == INFO_MODE_VERSION)
4046 DrawInfoScreen_Version();
4047 else if (info_mode == INFO_MODE_LEVELSET)
4048 DrawInfoScreen_LevelSet();
4050 DrawInfoScreen_Main();
4052 if (info_mode != INFO_MODE_MAIN &&
4053 info_mode != INFO_MODE_TITLE &&
4054 info_mode != INFO_MODE_MUSIC)
4055 PlayMenuSoundsAndMusic();
4058 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4060 if (info_mode == INFO_MODE_TITLE)
4061 HandleInfoScreen_TitleScreen(button);
4062 else if (info_mode == INFO_MODE_ELEMENTS)
4063 HandleInfoScreen_Elements(button);
4064 else if (info_mode == INFO_MODE_MUSIC)
4065 HandleInfoScreen_Music(button);
4066 else if (info_mode == INFO_MODE_CREDITS)
4067 HandleInfoScreen_Credits(button);
4068 else if (info_mode == INFO_MODE_PROGRAM)
4069 HandleInfoScreen_Program(button);
4070 else if (info_mode == INFO_MODE_VERSION)
4071 HandleInfoScreen_Version(button);
4072 else if (info_mode == INFO_MODE_LEVELSET)
4073 HandleInfoScreen_LevelSet(button);
4075 HandleInfoScreen_Main(mx, my, dx, dy, button);
4079 // ============================================================================
4080 // rename player API functions
4081 // ============================================================================
4083 struct ApiRenamePlayerThreadData
4089 static void *CreateThreadData_ApiRenamePlayer(void)
4091 struct ApiRenamePlayerThreadData *data =
4092 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4094 data->player_name = getStringCopy(setup.player_name);
4095 data->player_uuid = getStringCopy(setup.player_uuid);
4100 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4102 struct ApiRenamePlayerThreadData *data = data_raw;
4104 checked_free(data->player_name);
4105 checked_free(data->player_uuid);
4109 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4112 struct ApiRenamePlayerThreadData *data = data_raw;
4113 char *player_name_raw = data->player_name;
4114 char *player_uuid_raw = data->player_uuid;
4116 request->hostname = setup.api_server_hostname;
4117 request->port = API_SERVER_PORT;
4118 request->method = API_SERVER_METHOD;
4119 request->uri = API_SERVER_URI_RENAME;
4121 char *player_name = getEscapedJSON(player_name_raw);
4122 char *player_uuid = getEscapedJSON(player_uuid_raw);
4124 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4127 " \"game_version\": \"%s\",\n"
4128 " \"game_platform\": \"%s\",\n"
4129 " \"name\": \"%s\",\n"
4130 " \"uuid\": \"%s\"\n"
4132 getPasswordJSON(setup.api_server_password),
4133 getProgramRealVersionString(),
4134 getProgramPlatformString(),
4138 checked_free(player_name);
4139 checked_free(player_uuid);
4141 ConvertHttpRequestBodyToServerEncoding(request);
4146 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4149 // nothing to do here
4152 #if defined(PLATFORM_EMSCRIPTEN)
4153 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4154 void *buffer, unsigned int size)
4156 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4158 if (response != NULL)
4160 HandleResponse_ApiRenamePlayer(response, data_raw);
4162 checked_free(response);
4166 Error("server response too large to handle (%d bytes)", size);
4169 FreeThreadData_ApiRenamePlayer(data_raw);
4172 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4173 int code, const char *status)
4175 Error("server failed to handle request: %d %s", code, status);
4177 FreeThreadData_ApiRenamePlayer(data_raw);
4180 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4181 int bytes, int size)
4183 // nothing to do here
4186 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4189 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4191 FreeThreadData_ApiRenamePlayer(data_raw);
4196 emscripten_async_wget2_data(request->uri,
4201 Emscripten_ApiRenamePlayer_Loaded,
4202 Emscripten_ApiRenamePlayer_Failed,
4203 Emscripten_ApiRenamePlayer_Progress);
4208 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4209 struct HttpResponse *response,
4212 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4215 if (!DoHttpRequest(request, response))
4217 Error("HTTP request failed: %s", GetHttpError());
4222 if (!HTTP_SUCCESS(response->status_code))
4224 Error("server failed to handle request: %d %s",
4225 response->status_code,
4226 response->status_text);
4231 HandleResponse_ApiRenamePlayer(response, data_raw);
4234 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4235 struct HttpResponse *response,
4238 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4240 FreeThreadData_ApiRenamePlayer(data_raw);
4244 static int ApiRenamePlayerThread(void *data_raw)
4246 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4247 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4249 program.api_thread_count++;
4251 #if defined(PLATFORM_EMSCRIPTEN)
4252 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4254 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4257 program.api_thread_count--;
4259 checked_free(request);
4260 checked_free(response);
4265 static void ApiRenamePlayerAsThread(void)
4267 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4269 ExecuteAsThread(ApiRenamePlayerThread,
4270 "ApiRenamePlayer", data,
4271 "rename player on server");
4275 // ============================================================================
4276 // reset player UUID API functions
4277 // ============================================================================
4279 struct ApiResetUUIDThreadData
4282 char *player_uuid_old;
4283 char *player_uuid_new;
4286 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4288 struct ApiResetUUIDThreadData *data =
4289 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4291 data->player_name = getStringCopy(setup.player_name);
4292 data->player_uuid_old = getStringCopy(setup.player_uuid);
4293 data->player_uuid_new = getStringCopy(uuid_new);
4298 static void FreeThreadData_ApiResetUUID(void *data_raw)
4300 struct ApiResetUUIDThreadData *data = data_raw;
4302 checked_free(data->player_name);
4303 checked_free(data->player_uuid_old);
4304 checked_free(data->player_uuid_new);
4308 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4311 struct ApiResetUUIDThreadData *data = data_raw;
4312 char *player_name_raw = data->player_name;
4313 char *player_uuid_old_raw = data->player_uuid_old;
4314 char *player_uuid_new_raw = data->player_uuid_new;
4316 request->hostname = setup.api_server_hostname;
4317 request->port = API_SERVER_PORT;
4318 request->method = API_SERVER_METHOD;
4319 request->uri = API_SERVER_URI_RESETUUID;
4321 char *player_name = getEscapedJSON(player_name_raw);
4322 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4323 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4325 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4328 " \"game_version\": \"%s\",\n"
4329 " \"game_platform\": \"%s\",\n"
4330 " \"name\": \"%s\",\n"
4331 " \"uuid_old\": \"%s\",\n"
4332 " \"uuid_new\": \"%s\"\n"
4334 getPasswordJSON(setup.api_server_password),
4335 getProgramRealVersionString(),
4336 getProgramPlatformString(),
4341 checked_free(player_name);
4342 checked_free(player_uuid_old);
4343 checked_free(player_uuid_new);
4345 ConvertHttpRequestBodyToServerEncoding(request);
4350 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4353 struct ApiResetUUIDThreadData *data = data_raw;
4355 // upgrade player UUID in server setup file
4356 setup.player_uuid = getStringCopy(data->player_uuid_new);
4357 setup.player_version = 2;
4359 SaveSetup_ServerSetup();
4362 #if defined(PLATFORM_EMSCRIPTEN)
4363 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4364 void *buffer, unsigned int size)
4366 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4368 if (response != NULL)
4370 HandleResponse_ApiResetUUID(response, data_raw);
4372 checked_free(response);
4376 Error("server response too large to handle (%d bytes)", size);
4379 FreeThreadData_ApiResetUUID(data_raw);
4382 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4383 int code, const char *status)
4385 Error("server failed to handle request: %d %s", code, status);
4387 FreeThreadData_ApiResetUUID(data_raw);
4390 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4391 int bytes, int size)
4393 // nothing to do here
4396 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4399 if (!SetRequest_ApiResetUUID(request, data_raw))
4401 FreeThreadData_ApiResetUUID(data_raw);
4406 emscripten_async_wget2_data(request->uri,
4411 Emscripten_ApiResetUUID_Loaded,
4412 Emscripten_ApiResetUUID_Failed,
4413 Emscripten_ApiResetUUID_Progress);
4418 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4419 struct HttpResponse *response,
4422 if (!SetRequest_ApiResetUUID(request, data_raw))
4425 if (!DoHttpRequest(request, response))
4427 Error("HTTP request failed: %s", GetHttpError());
4432 if (!HTTP_SUCCESS(response->status_code))
4434 Error("server failed to handle request: %d %s",
4435 response->status_code,
4436 response->status_text);
4441 HandleResponse_ApiResetUUID(response, data_raw);
4444 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4445 struct HttpResponse *response,
4448 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4450 FreeThreadData_ApiResetUUID(data_raw);
4454 static int ApiResetUUIDThread(void *data_raw)
4456 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4457 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4459 program.api_thread_count++;
4461 #if defined(PLATFORM_EMSCRIPTEN)
4462 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4464 ApiResetUUID_HttpRequest(request, response, data_raw);
4467 program.api_thread_count--;
4469 checked_free(request);
4470 checked_free(response);
4475 static void ApiResetUUIDAsThread(char *uuid_new)
4477 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4479 ExecuteAsThread(ApiResetUUIDThread,
4480 "ApiResetUUID", data,
4481 "reset UUID on server");
4485 // ============================================================================
4486 // type name functions
4487 // ============================================================================
4489 static TreeInfo *type_name_node = NULL;
4490 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4491 static int type_name_nr = 0;
4493 static int getPlayerNameColor(char *name)
4495 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4498 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4501 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4502 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4503 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4504 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4505 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4506 int font_width = getFontWidth(font_nr);
4508 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4510 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4512 pos->width = strlen(text) * font_width;
4513 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4515 DrawText(sx, sy, text, font_nr);
4518 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4520 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4522 *pos = *mci->pos_input;
4524 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4526 TreeInfo *ti = player_name_current;
4527 int first_entry = ti->cl_first;
4528 int entry_pos = first_entry + ti->cl_cursor;
4529 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4530 int xpos = MENU_SCREEN_START_XPOS;
4531 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4533 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4534 type_name_nr = entry_pos;
4536 strcpy(name, type_name_node->name);
4540 pos->width = MAX_PLAYER_NAME_LEN * 32;
4544 type_name_nr = user.nr;
4546 strcpy(name, setup.player_name);
4549 strcpy(type_name_last, name);
4551 if (strEqual(name, EMPTY_PLAYER_NAME))
4554 *xpos = strlen(name);
4557 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4559 // change name of edited user in global list of user names
4560 setString(&global.user_names[type_name_nr], name);
4562 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4564 TreeInfo *node = type_name_node;
4566 // change name of edited user in local menu tree structure
4567 setString(&node->name, name);
4568 setString(&node->name_sorting, name);
4570 node->color = getPlayerNameColor(name);
4571 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4575 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4578 boolean reset_setup = strEqual(name, "");
4579 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4580 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4583 strcpy(name, type_name_last);
4585 if (strEqual(name, ""))
4586 strcpy(name, EMPTY_PLAYER_NAME);
4588 setTypeNameValues_Name(name, pos);
4590 // if player name not changed, no further action required
4591 if (strEqual(name, type_name_last))
4594 // redraw player name before (possibly) opening request dialogs
4595 drawTypeNameText(name, pos, FALSE);
4597 int last_user_nr = user.nr;
4599 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4601 // save setup of currently active user (may differ from edited user)
4604 // temporarily change active user to edited user
4605 user.nr = type_name_nr;
4608 Request("Use current setup values for the new player?", REQ_ASK))
4610 // use current setup values for new user, but create new player UUID
4611 setup.player_uuid = getStringCopy(getUUID());
4615 // load setup for existing user (or start with defaults for new user)
4620 char *setup_filename = getSetupFilename();
4621 boolean setup_exists = fileExists(setup_filename);
4623 // change name of edited user in setup structure
4624 strcpy(setup.player_name, name);
4626 // save setup of edited user
4629 // change name of edited user on score server
4630 ApiRenamePlayerAsThread();
4632 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4636 if (Request("Reset setup values for this player?", REQ_ASK))
4638 // remove setup config file
4639 unlink(setup_filename);
4641 // set player name to default player name
4644 // update player name used by name typing functions
4645 strcpy(name, setup.player_name);
4647 setTypeNameValues_Name(name, pos);
4650 else if (remove_user && type_name_nr != 0)
4652 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4654 char *user_dir = getUserGameDataDir();
4655 char *user_dir_removed =
4656 getStringCat3WithSeparator(user_dir, "REMOVED",
4657 getCurrentTimestamp(), ".");
4659 if (rename(user_dir, user_dir_removed) != 0)
4660 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4662 checked_free(user_dir_removed);
4665 else if (create_user && type_name_nr != 0 && !setup_exists)
4667 if (Request("Create empty level set for the new player?", REQ_ASK))
4669 char *levelset_subdir = getNewUserLevelSubdir();
4671 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4673 AddUserLevelSetToLevelInfo(levelset_subdir);
4675 LevelDirTree *leveldir_current_last = leveldir_current;
4677 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4680 // set level number of newly created level set to default value
4681 LoadLevelSetup_SeriesInfo();
4683 // set newly created level set as current level set for new user
4684 SaveLevelSetup_LastSeries();
4685 SaveLevelSetup_SeriesInfo();
4687 leveldir_current = leveldir_current_last;
4691 Request("Creating new level set failed!", REQ_CONFIRM);
4696 // restore currently active user
4697 user.nr = last_user_nr;
4699 // restore setup of currently active user
4702 // restore last level set of currently active user
4703 LoadLevelSetup_LastSeries();
4704 LoadLevelSetup_SeriesInfo();
4708 static void HandleTypeNameExt(boolean initialize, Key key)
4710 static struct TextPosInfo pos_name = { 0 };
4711 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4712 static int xpos = 0;
4713 struct TextPosInfo *pos = &pos_name;
4714 char key_char = getValidConfigValueChar(getCharFromKey(key));
4715 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4716 boolean active = TRUE;
4720 getTypeNameValues(name, pos, &xpos);
4722 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4723 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4725 StartTextInput(sx, sy, pos->width, pos->height);
4727 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4729 name[xpos] = key_char;
4734 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4740 else if (key == KSYM_Return || key == KSYM_Escape)
4742 boolean changed = (key == KSYM_Return);
4746 setTypeNameValues(name, pos, changed);
4751 drawTypeNameText(name, pos, active);
4755 SetGameStatus(game_status_last_screen);
4757 if (game_status == GAME_MODE_MAIN)
4758 InitializeMainControls();
4762 static void DrawTypeName(void)
4764 HandleTypeNameExt(TRUE, 0);
4767 void HandleTypeName(Key key)
4769 HandleTypeNameExt(FALSE, key);
4773 // ============================================================================
4774 // tree menu functions
4775 // ============================================================================
4777 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4779 if (game_status != GAME_MODE_SETUP ||
4780 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4783 int max_text_size = 0;
4786 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4787 max_text_size = MAX(max_text_size, strlen(node->name));
4789 int num_entries = numTreeInfoInGroup(ti);
4790 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4791 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4792 int text_width = max_text_size * getFontWidth(font_nr);
4793 int button_width = SC_MENUBUTTON_XSIZE;
4794 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4795 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4796 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4797 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4798 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4799 int align_xoffset = MAX(0, align_xoffset_raw);
4801 return align_xoffset;
4804 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4806 if (game_status != GAME_MODE_SETUP ||
4807 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4810 int num_entries = numTreeInfoInGroup(ti);
4811 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4812 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4813 int font_height = getFontHeight(font_nr);
4814 int text_height = font_height * num_page_entries;
4815 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4816 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4817 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4818 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4819 int align_yoffset = MAX(0, align_yoffset_raw);
4821 return align_yoffset;
4824 static void DrawChooseTree(TreeInfo **ti_ptr)
4826 int fade_mask = REDRAW_FIELD;
4829 fade_mask = REDRAW_ALL;
4831 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4833 if (game_status == GAME_MODE_SETUP)
4837 else // GAME_MODE_LEVELS
4839 SetGameStatus(GAME_MODE_MAIN);
4849 FreeScreenGadgets();
4850 CreateScreenGadgets();
4852 if (game_status != game_status_last_screen)
4853 FadeMenuSoundsAndMusic();
4857 // needed if different viewport properties defined for this screen
4858 ChangeViewportPropertiesIfNeeded();
4860 if (game_status == GAME_MODE_NAMES)
4861 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4862 else if (game_status == GAME_MODE_LEVELNR)
4863 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4864 else if (game_status == GAME_MODE_LEVELS)
4865 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4866 else if (game_status == GAME_MODE_SCORES)
4867 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4871 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4873 // map gadgets for high score screen
4874 if (game_status == GAME_MODE_SCORES)
4875 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4877 MapScreenTreeGadgets(*ti_ptr);
4879 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4881 DrawMaskedBorder(fade_mask);
4883 if (game_status != game_status_last_screen)
4884 PlayMenuSoundsAndMusic();
4889 static int getChooseTreeFont(TreeInfo *node, boolean active)
4891 if (game_status == GAME_MODE_SCORES)
4892 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4894 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4897 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4899 int num_entries = numTreeInfoInGroup(ti);
4900 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4901 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4902 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4903 int first_entry = ti->cl_first;
4904 int entry_pos = first_entry + y;
4905 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4906 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4907 int font_nr = getChooseTreeFont(node, active);
4908 int font_xoffset = getFontDrawOffsetX(font_nr);
4909 int xpos = MENU_SCREEN_START_XPOS;
4910 int ypos = MENU_SCREEN_START_YPOS + y;
4911 int startdx = xpos * 32;
4912 int startdy = ypos * 32;
4913 int startx = amSX + startdx;
4914 int starty = amSY + startdy;
4915 int startx_text = startx + font_xoffset;
4916 int endx_text = amSX + screen_width;
4917 int max_text_size = endx_text - startx_text;
4918 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4919 char buffer[max_buffer_len + 1];
4921 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4923 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4924 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4925 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4926 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4927 int font_size_1 = getFontWidth(font_nr1);
4928 int font_size_3 = getFontWidth(font_nr3);
4929 int font_size_4 = getFontWidth(font_nr4);
4930 int text_size_1 = 3 * font_size_1;
4931 int text_size_4 = 5 * font_size_4;
4932 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4934 int dx2 = text_size_1;
4935 int dx3 = dx2 + font_size_1;
4936 int dx4 = screen_width - startdx - 2 * border - text_size_4;
4937 int num_dots = (dx4 - dx3) / font_size_3;
4938 int startx1 = startx + dx1;
4939 int startx2 = startx + dx2;
4940 int startx3 = startx + dx3;
4941 int startx4 = startx + dx4;
4942 int pos = node->pos;
4943 boolean forced = (scores.force_last_added && pos == scores.last_added);
4944 char *pos_text = (forced ? "???" : int2str(pos + 1, 3));
4945 char *dot_text = ".";
4948 DrawText(startx1, starty, pos_text, font_nr1);
4949 DrawText(startx2, starty, dot_text, font_nr1);
4951 for (i = 0; i < num_dots; i++)
4952 DrawText(startx3 + i * font_size_3, starty, dot_text, font_nr3);
4954 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4955 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4957 DrawText(startx4, starty, getHallOfFameScoreText(pos), font_nr4);
4961 strncpy(buffer, node->name, max_buffer_len);
4962 buffer[max_buffer_len] = '\0';
4964 DrawText(startx, starty, buffer, font_nr);
4968 static void drawChooseTreeHeadExt(int type, char *title_string)
4970 int yoffset_sets = MENU_TITLE1_YPOS;
4971 int yoffset_setup = 16;
4972 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4973 type == TREE_TYPE_LEVEL_DIR ||
4974 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4976 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4979 static void drawChooseTreeHead(TreeInfo *ti)
4981 drawChooseTreeHeadExt(ti->type, ti->infotext);
4984 static void drawChooseTreeList(TreeInfo *ti)
4986 int first_entry = ti->cl_first;
4987 int num_entries = numTreeInfoInGroup(ti);
4988 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4991 clearMenuListArea();
4993 for (i = 0; i < num_page_entries; i++)
4995 TreeInfo *node, *node_first;
4996 int entry_pos = first_entry + i;
4998 node_first = getTreeInfoFirstGroupEntry(ti);
4999 node = getTreeInfoFromPos(node_first, entry_pos);
5001 drawChooseTreeText(ti, i, FALSE);
5003 if (node->parent_link)
5004 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5005 else if (node->level_group)
5006 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5008 initCursor(i, IMG_MENU_BUTTON);
5010 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
5011 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5013 if (game_status == GAME_MODE_NAMES)
5014 drawChooseTreeEdit(i, FALSE);
5017 redraw_mask |= REDRAW_FIELD;
5020 static void drawChooseTreeInfo(TreeInfo *ti)
5022 int entry_pos = ti->cl_first + ti->cl_cursor;
5023 int last_redraw_mask = redraw_mask;
5024 int ypos = MENU_TITLE2_YPOS;
5025 int font_nr = FONT_TITLE_2;
5028 if (ti->type == TREE_TYPE_LEVEL_NR)
5029 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
5031 if (ti->type == TREE_TYPE_SCORE_ENTRY)
5032 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
5033 scores.last_level_nr);
5035 if (ti->type != TREE_TYPE_LEVEL_DIR)
5038 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
5039 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
5041 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
5043 if (node->parent_link)
5044 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
5045 node->node_parent->name);
5046 else if (node->level_group)
5047 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
5049 else if (ti->type == TREE_TYPE_LEVEL_DIR)
5050 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
5051 node->levels, (node->levels > 1 ? "levels" : "level"),
5054 // let BackToFront() redraw only what is needed
5055 redraw_mask = last_redraw_mask;
5056 for (x = 0; x < SCR_FIELDX; x++)
5057 MarkTileDirty(x, 1);
5060 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
5062 drawChooseTreeCursor(ti->cl_cursor, active);
5063 drawChooseTreeText(ti, ti->cl_cursor, active);
5066 static void drawChooseTreeScreen(TreeInfo *ti)
5068 drawChooseTreeHead(ti);
5069 drawChooseTreeList(ti);
5070 drawChooseTreeInfo(ti);
5071 drawChooseTreeCursorAndText(ti, TRUE);
5073 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
5075 // scroll bar and buttons may just have been added after reloading scores
5076 if (game_status == GAME_MODE_SCORES)
5077 MapScreenTreeGadgets(ti);
5080 static void drawChooseTreeScreen_Scores_NotAvailable(void)
5082 // dirty workaround to use spacing definitions from info screen
5083 info_mode = INFO_MODE_TITLE;
5085 char *text_info = "HighScores of Level %d";
5086 char *text_title = "Score information:";
5087 char *text_error = "No scores for this level.";
5088 char *text_foot = "Press any key or button for main menu";
5089 int font_info = FONT_TITLE_2;
5090 int font_title = FONT_INITIAL_3;
5091 int font_error = FONT_INITIAL_4;
5092 int font_foot = FONT_INITIAL_2;
5093 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
5094 int ystep_title = getMenuTextStep(spacing_title, font_title);
5095 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
5096 int ystart2 = ystart1 + ystep_title;
5097 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
5098 int ystart0 = MENU_TITLE2_YPOS;
5100 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
5101 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
5103 DrawTextSCentered(ystart1, font_title, text_title);
5104 DrawTextSCentered(ystart2, font_error, text_error);
5106 DrawTextSCentered(ybottom, font_foot, text_foot);
5109 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
5111 // set current tree entry to last added score entry
5112 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(scores.last_added));
5114 // if that fails, set current tree entry to first entry (back link)
5115 if (*ti_ptr == NULL)
5116 *ti_ptr = score_entries->node_group;
5118 int num_entries = numTreeInfoInGroup(*ti_ptr);
5119 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5120 int pos_score = getPosFromTreeInfo(*ti_ptr);
5121 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5122 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5124 (*ti_ptr)->cl_first = pos_first;
5125 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5130 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5133 TreeInfo *ti = *ti_ptr;
5134 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5135 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5136 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5137 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5138 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5140 int y = (ti != NULL ? ti->cl_cursor : 0);
5141 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5142 int num_entries = numTreeInfoInGroup(ti);
5143 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5144 boolean position_set_by_scrollbar = (dx == 999);
5146 if (game_status == GAME_MODE_SCORES)
5148 if (server_scores.updated)
5150 // reload scores, using updated server score cache file
5151 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5153 server_scores.updated = FALSE;
5155 DrawHallOfFame_setScoreEntries();
5157 if (score_entries != NULL)
5159 ti = setHallOfFameActiveEntry(ti_ptr);
5161 if (button != MB_MENU_INITIALIZE)
5162 drawChooseTreeScreen(ti);
5166 if (score_entries == NULL)
5168 if (button == MB_MENU_INITIALIZE)
5170 drawChooseTreeScreen_Scores_NotAvailable();
5172 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5174 PlaySound(SND_MENU_ITEM_SELECTING);
5176 SetGameStatus(GAME_MODE_MAIN);
5185 if (button == MB_MENU_INITIALIZE)
5187 int num_entries = numTreeInfoInGroup(ti);
5188 int entry_pos = getPosFromTreeInfo(ti);
5190 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5191 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5193 if (game_status == GAME_MODE_SCORES)
5195 ti = setHallOfFameActiveEntry(ti_ptr);
5197 else if (ti->cl_first == -1)
5199 // only on initialization
5200 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5201 ti->cl_cursor = entry_pos - ti->cl_first;
5204 else if (ti->cl_cursor >= num_page_entries ||
5205 (num_entries > num_page_entries &&
5206 num_entries - ti->cl_first < num_page_entries))
5208 // only after change of list size (by custom graphic configuration)
5209 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5210 ti->cl_cursor = entry_pos - ti->cl_first;
5213 if (position_set_by_scrollbar)
5216 drawChooseTreeScreen(ti);
5220 else if (button == MB_MENU_LEAVE)
5222 if (game_status != GAME_MODE_SCORES)
5225 PlaySound(SND_MENU_ITEM_SELECTING);
5227 if (ti->node_parent)
5229 *ti_ptr = ti->node_parent;
5230 DrawChooseTree(ti_ptr);
5232 else if (game_status == GAME_MODE_SETUP)
5234 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5235 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5236 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5237 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5239 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5240 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5241 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5242 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5243 execSetupGraphics();
5244 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5245 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5246 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5248 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5249 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5250 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5251 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5252 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5253 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5254 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5255 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5262 if (game_status == GAME_MODE_LEVELNR)
5264 int new_level_nr = atoi(level_number_current->identifier);
5266 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5269 SetGameStatus(GAME_MODE_MAIN);
5277 if (mx || my) // mouse input
5279 x = (mx - amSX) / 32;
5280 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5282 if (game_status == GAME_MODE_NAMES)
5283 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5285 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5287 // move cursor instead of scrolling when already at start/end of list
5288 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5290 else if (dy == +1 * SCROLL_LINE &&
5291 ti->cl_first + num_page_entries == num_entries)
5294 // handle scrolling screen one line or page
5295 if (ti->cl_cursor + dy < 0 ||
5296 ti->cl_cursor + dy > num_page_entries - 1)
5298 boolean redraw = FALSE;
5300 if (ABS(dy) == SCROLL_PAGE)
5301 step = num_page_entries - 1;
5303 if (dy < 0 && ti->cl_first > 0)
5305 // scroll page/line up
5307 ti->cl_first -= step;
5308 if (ti->cl_first < 0)
5313 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5315 // scroll page/line down
5317 ti->cl_first += step;
5318 if (ti->cl_first + num_page_entries > num_entries)
5319 ti->cl_first = MAX(0, num_entries - num_page_entries);
5325 drawChooseTreeScreen(ti);
5330 // handle moving cursor one line
5331 y = ti->cl_cursor + dy;
5334 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5336 HandleHallOfFame_SelectLevel(1, dx);
5342 TreeInfo *node_first, *node_cursor;
5343 int entry_pos = ti->cl_first + y;
5345 node_first = getTreeInfoFirstGroupEntry(ti);
5346 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5348 if (node_cursor->node_group)
5352 PlaySound(SND_MENU_ITEM_SELECTING);
5354 node_cursor->cl_first = ti->cl_first;
5355 node_cursor->cl_cursor = ti->cl_cursor;
5356 *ti_ptr = node_cursor->node_group;
5357 DrawChooseTree(ti_ptr);
5362 else if (dx == -1 && ti->node_parent)
5366 PlaySound(SND_MENU_ITEM_SELECTING);
5368 *ti_ptr = ti->node_parent;
5369 DrawChooseTree(ti_ptr);
5374 if (!anyScrollbarGadgetActive() &&
5375 IN_VIS_MENU(x, y) &&
5376 mx < mx_right_border &&
5377 y >= 0 && y < num_page_entries)
5381 if (game_status == GAME_MODE_NAMES)
5383 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5384 drawChooseTreeEdit(y, TRUE);
5387 if (y != ti->cl_cursor)
5389 PlaySound(SND_MENU_ITEM_ACTIVATING);
5391 drawChooseTreeCursorAndText(ti, FALSE);
5395 drawChooseTreeCursorAndText(ti, TRUE);
5397 drawChooseTreeInfo(ti);
5401 if (game_status == GAME_MODE_SETUP)
5403 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5404 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5405 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5406 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5408 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5409 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5410 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5411 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5412 execSetupGraphics();
5413 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5414 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5415 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5417 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5418 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5419 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5420 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5421 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5422 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5423 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5424 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5433 TreeInfo *node_first, *node_cursor;
5434 int entry_pos = ti->cl_first + y;
5436 PlaySound(SND_MENU_ITEM_SELECTING);
5438 node_first = getTreeInfoFirstGroupEntry(ti);
5439 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5441 if (node_cursor->node_group)
5445 node_cursor->cl_first = ti->cl_first;
5446 node_cursor->cl_cursor = ti->cl_cursor;
5447 *ti_ptr = node_cursor->node_group;
5448 DrawChooseTree(ti_ptr);
5450 else if (node_cursor->parent_link)
5452 if (game_status != GAME_MODE_SCORES)
5455 *ti_ptr = node_cursor->node_parent;
5456 DrawChooseTree(ti_ptr);
5460 if (game_status != GAME_MODE_SCORES)
5463 node_cursor->cl_first = ti->cl_first;
5464 node_cursor->cl_cursor = ti->cl_cursor;
5465 *ti_ptr = node_cursor;
5467 if (ti->type == TREE_TYPE_LEVEL_DIR)
5469 LoadLevelSetup_SeriesInfo();
5471 SaveLevelSetup_LastSeries();
5472 SaveLevelSetup_SeriesInfo();
5476 if (game_status == GAME_MODE_SETUP)
5478 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5479 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5480 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5481 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5483 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5484 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5485 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5486 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5487 execSetupGraphics();
5488 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5489 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5490 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5492 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5493 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5494 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5495 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5496 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5497 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5498 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5499 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5506 if (game_status == GAME_MODE_LEVELNR)
5508 int new_level_nr = atoi(level_number_current->identifier);
5510 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5512 else if (game_status == GAME_MODE_LEVELS)
5514 // store level set if chosen from "last played level set" menu
5515 StoreLastPlayedLevels(leveldir_current);
5517 else if (game_status == GAME_MODE_NAMES)
5519 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5521 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5528 // change active user to selected user
5529 user.nr = entry_pos;
5531 // save number of new active user
5534 // load setup of new active user
5537 // load last level set of new active user
5538 LoadLevelSetup_LastSeries();
5539 LoadLevelSetup_SeriesInfo();
5541 // update list of last played level sets
5542 UpdateLastPlayedLevels_TreeInfo();
5546 ToggleFullscreenIfNeeded();
5547 ChangeWindowScalingIfNeeded();
5549 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5550 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5551 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5553 else if (game_status == GAME_MODE_SCORES)
5555 if (game_status_last_screen == GAME_MODE_PLAYING &&
5556 setup.auto_play_next_level && setup.increment_levels &&
5557 scores.last_level_nr < leveldir_current->last_level &&
5560 StartGameActions(network.enabled, setup.autorecord,
5566 SetGameStatus(GAME_MODE_MAIN);
5574 if (game_status == GAME_MODE_SCORES)
5575 PlayMenuSoundIfLoop();
5578 void DrawChoosePlayerName(void)
5582 if (player_name != NULL)
5584 freeTreeInfo(player_name);
5589 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5591 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5592 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5595 ti->node_top = &player_name;
5596 ti->sort_priority = 10000 + value;
5597 ti->color = getPlayerNameColor(global.user_names[i]);
5599 snprintf(identifier, sizeof(identifier), "%d", value);
5600 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5602 setString(&ti->identifier, identifier);
5603 setString(&ti->name, name);
5604 setString(&ti->name_sorting, name);
5606 pushTreeInfo(&player_name, ti);
5609 // sort player entries by player number
5610 sortTreeInfo(&player_name);
5612 // set current player entry to selected player entry
5613 player_name_current =
5614 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5616 // if that fails, set current player name to first available name
5617 if (player_name_current == NULL)
5618 player_name_current = player_name;
5620 DrawChooseTree(&player_name_current);
5623 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5625 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5628 void DrawChooseLevelSet(void)
5630 DrawChooseTree(&leveldir_current);
5633 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5635 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5638 void DrawChooseLevelNr(void)
5642 if (level_number != NULL)
5644 freeTreeInfo(level_number);
5646 level_number = NULL;
5649 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5651 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5652 char identifier[32], name[64];
5655 // temporarily load level info to get level name
5656 LoadLevelInfoOnly(i);
5658 ti->node_top = &level_number;
5659 ti->sort_priority = 10000 + value;
5660 ti->color = (level.no_level_file ? FC_BLUE :
5661 LevelStats_getSolved(i) ? FC_GREEN :
5662 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5664 snprintf(identifier, sizeof(identifier), "%d", value);
5665 snprintf(name, sizeof(name), "%03d: %s", value,
5666 (level.no_level_file ? "(no file)" : level.name));
5668 setString(&ti->identifier, identifier);
5669 setString(&ti->name, name);
5670 setString(&ti->name_sorting, name);
5672 pushTreeInfo(&level_number, ti);
5675 // sort level number values to start with lowest level number
5676 sortTreeInfo(&level_number);
5678 // set current level number to current level number
5679 level_number_current =
5680 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5682 // if that also fails, set current level number to first available level
5683 if (level_number_current == NULL)
5684 level_number_current = level_number;
5686 DrawChooseTree(&level_number_current);
5689 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5691 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5694 static void DrawHallOfFame_setScoreEntries(void)
5696 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5699 if (score_entries != NULL)
5701 freeTreeInfo(score_entries);
5703 score_entries = NULL;
5706 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5708 // do not add empty score entries
5709 if (scores.entry[i].score == 0 &&
5710 scores.entry[i].time == 0)
5713 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5714 char identifier[32], name[64];
5717 ti->node_top = &score_entries;
5718 ti->sort_priority = 10000 + value;
5719 ti->color = FC_YELLOW;
5722 snprintf(identifier, sizeof(identifier), "%d", value);
5723 snprintf(name, sizeof(name), "%03d.", value + 1);
5725 setString(&ti->identifier, identifier);
5726 setString(&ti->name, name);
5727 setString(&ti->name_sorting, name);
5729 pushTreeInfo(&score_entries, ti);
5732 // sort score entries to start with highest score entry
5733 sortTreeInfo(&score_entries);
5735 // add top tree node to create back link to main menu
5736 score_entries = addTopTreeInfoNode(score_entries);
5738 // set current score entry to last added or highest score entry
5739 score_entry_current =
5740 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5742 // if that fails, set current score entry to first valid score entry
5743 if (score_entry_current == NULL)
5744 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5746 // ("score_entries" and "score_entry_current" may be NULL here)
5749 void DrawHallOfFame(int level_nr)
5751 scores.last_level_nr = level_nr;
5753 // (this is needed when called from GameEnd() after winning a game)
5754 KeyboardAutoRepeatOn();
5756 // (this is needed when called from GameEnd() after winning a game)
5757 SetDrawDeactivationMask(REDRAW_NONE);
5758 SetDrawBackgroundMask(REDRAW_FIELD);
5760 LoadLocalAndServerScore(level_nr, TRUE);
5762 DrawHallOfFame_setScoreEntries();
5764 if (scores.last_added >= 0)
5765 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5767 FadeSetEnterScreen();
5769 DrawChooseTree(&score_entry_current);
5772 static char *getHallOfFameTimeText(int nr)
5774 static char score_text[10];
5775 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5776 int mm = (time_seconds / 60) % 60;
5777 int ss = (time_seconds % 60);
5779 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5784 static char *getHallOfFameScoreText(int nr)
5786 if (!level.rate_time_over_score)
5787 return int2str(scores.entry[nr].score, 5); // show normal score
5788 else if (level.use_step_counter)
5789 return int2str(scores.entry[nr].time, 5); // show number of steps
5791 return getHallOfFameTimeText(nr); // show playing time
5794 static void HandleHallOfFame_SelectLevel(int step, int direction)
5796 int old_level_nr = level_nr;
5797 int new_level_nr = old_level_nr + step * direction;
5799 if (new_level_nr < leveldir_current->first_level)
5800 new_level_nr = leveldir_current->first_level;
5801 if (new_level_nr > leveldir_current->last_level)
5802 new_level_nr = leveldir_current->last_level;
5804 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5805 new_level_nr = leveldir_current->handicap_level;
5807 if (new_level_nr != old_level_nr)
5809 PlaySound(SND_MENU_ITEM_SELECTING);
5811 scores.last_level_nr = level_nr = new_level_nr;
5813 LoadLocalAndServerScore(level_nr, TRUE);
5815 DrawHallOfFame_setScoreEntries();
5817 // force remapping optional gadgets (especially scroll bar)
5818 UnmapScreenTreeGadgets();
5820 // redraw complete high score screen, as sub-title has changed
5823 // redraw level selection buttons (which have just been erased)
5824 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5826 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5828 SaveLevelSetup_SeriesInfo();
5832 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5834 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5838 // ============================================================================
5839 // setup screen functions
5840 // ============================================================================
5842 static struct TokenInfo *setup_info;
5843 static int num_setup_info; // number of setup entries shown on screen
5844 static int max_setup_info; // total number of setup entries in list
5846 static char *window_size_text;
5847 static char *scaling_type_text;
5848 static char *rendering_mode_text;
5849 static char *vsync_mode_text;
5850 static char *scroll_delay_text;
5851 static char *snapshot_mode_text;
5852 static char *game_speed_text;
5853 static char *scores_type_text;
5854 static char *network_server_text;
5855 static char *graphics_set_name;
5856 static char *sounds_set_name;
5857 static char *music_set_name;
5858 static char *volume_simple_text;
5859 static char *volume_loops_text;
5860 static char *volume_music_text;
5861 static char *touch_controls_text;
5862 static char *move_distance_text;
5863 static char *drop_distance_text;
5864 static char *transparency_text;
5865 static char *grid_size_text[2][2];
5867 static void execSetupMain(void)
5869 setup_mode = SETUP_MODE_MAIN;
5874 static void execSetupGame_setScoresType(void)
5876 if (scores_types == NULL)
5880 for (i = 0; scores_types_list[i].value != NULL; i++)
5882 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5883 char identifier[32], name[32];
5884 char *value = scores_types_list[i].value;
5885 char *text = scores_types_list[i].text;
5887 ti->node_top = &scores_types;
5888 ti->sort_priority = i;
5890 sprintf(identifier, "%s", value);
5891 sprintf(name, "%s", text);
5893 setString(&ti->identifier, identifier);
5894 setString(&ti->name, name);
5895 setString(&ti->name_sorting, name);
5896 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5898 pushTreeInfo(&scores_types, ti);
5901 // sort scores type values to start with lowest scores type value
5902 sortTreeInfo(&scores_types);
5904 // set current scores type value to configured scores type value
5905 scores_type_current =
5906 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5908 // if that fails, set current scores type to reliable default value
5909 if (scores_type_current == NULL)
5910 scores_type_current =
5911 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5913 // if that also fails, set current scores type to first available value
5914 if (scores_type_current == NULL)
5915 scores_type_current = scores_types;
5918 setup.scores_in_highscore_list = scores_type_current->identifier;
5920 // needed for displaying scores type text instead of identifier
5921 scores_type_text = scores_type_current->name;
5924 static void execSetupGame_setGameSpeeds(boolean update_value)
5926 if (setup.game_speed_extended)
5928 game_speeds_list = game_speeds_list_extended;
5929 game_speeds = game_speeds_extended;
5933 game_speeds_list = game_speeds_list_normal;
5934 game_speeds = game_speeds_normal;
5937 if (game_speeds == NULL)
5941 for (i = 0; game_speeds_list[i].value != -1; i++)
5943 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5944 char identifier[32], name[32];
5945 int value = game_speeds_list[i].value;
5946 char *text = game_speeds_list[i].text;
5948 ti->node_top = &game_speeds;
5949 ti->sort_priority = 10000 - value;
5951 sprintf(identifier, "%d", value);
5952 sprintf(name, "%s", text);
5954 setString(&ti->identifier, identifier);
5955 setString(&ti->name, name);
5956 setString(&ti->name_sorting, name);
5957 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5959 pushTreeInfo(&game_speeds, ti);
5962 // sort game speed values to start with slowest game speed
5963 sortTreeInfo(&game_speeds);
5965 update_value = TRUE;
5970 // set current game speed to configured game speed value
5971 game_speed_current =
5972 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5974 // if that fails, set current game speed to reliable default value
5975 if (game_speed_current == NULL)
5976 game_speed_current =
5977 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5979 // if that also fails, set current game speed to first available speed
5980 if (game_speed_current == NULL)
5981 game_speed_current = game_speeds;
5983 if (setup.game_speed_extended)
5984 game_speeds_extended = game_speeds;
5986 game_speeds_normal = game_speeds;
5989 setup.game_frame_delay = atoi(game_speed_current->identifier);
5991 // needed for displaying game speed text instead of identifier
5992 game_speed_text = game_speed_current->name;
5995 static void execSetupGame_setScrollDelays(void)
5997 if (scroll_delays == NULL)
6001 for (i = 0; scroll_delays_list[i].value != -1; i++)
6003 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6004 char identifier[32], name[32];
6005 int value = scroll_delays_list[i].value;
6006 char *text = scroll_delays_list[i].text;
6008 ti->node_top = &scroll_delays;
6009 ti->sort_priority = value;
6011 sprintf(identifier, "%d", value);
6012 sprintf(name, "%s", text);
6014 setString(&ti->identifier, identifier);
6015 setString(&ti->name, name);
6016 setString(&ti->name_sorting, name);
6017 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6019 pushTreeInfo(&scroll_delays, ti);
6022 // sort scroll delay values to start with lowest scroll delay value
6023 sortTreeInfo(&scroll_delays);
6025 // set current scroll delay value to configured scroll delay value
6026 scroll_delay_current =
6027 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6029 // if that fails, set current scroll delay to reliable default value
6030 if (scroll_delay_current == NULL)
6031 scroll_delay_current =
6032 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6034 // if that also fails, set current scroll delay to first available value
6035 if (scroll_delay_current == NULL)
6036 scroll_delay_current = scroll_delays;
6039 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6041 // needed for displaying scroll delay text instead of identifier
6042 scroll_delay_text = scroll_delay_current->name;
6045 static void execSetupGame_setSnapshotModes(void)
6047 if (snapshot_modes == NULL)
6051 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6053 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6054 char identifier[32], name[32];
6055 char *value = snapshot_modes_list[i].value;
6056 char *text = snapshot_modes_list[i].text;
6058 ti->node_top = &snapshot_modes;
6059 ti->sort_priority = i;
6061 sprintf(identifier, "%s", value);
6062 sprintf(name, "%s", text);
6064 setString(&ti->identifier, identifier);
6065 setString(&ti->name, name);
6066 setString(&ti->name_sorting, name);
6067 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6069 pushTreeInfo(&snapshot_modes, ti);
6072 // sort snapshot mode values to start with lowest snapshot mode value
6073 sortTreeInfo(&snapshot_modes);
6075 // set current snapshot mode value to configured snapshot mode value
6076 snapshot_mode_current =
6077 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6079 // if that fails, set current snapshot mode to reliable default value
6080 if (snapshot_mode_current == NULL)
6081 snapshot_mode_current =
6082 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6084 // if that also fails, set current snapshot mode to first available value
6085 if (snapshot_mode_current == NULL)
6086 snapshot_mode_current = snapshot_modes;
6089 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6091 // needed for displaying snapshot mode text instead of identifier
6092 snapshot_mode_text = snapshot_mode_current->name;
6095 static void execSetupGame_setNetworkServerText(void)
6097 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6099 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6103 strncpy(network_server_hostname, setup.network_server_hostname,
6104 MAX_SETUP_TEXT_INPUT_LEN);
6105 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6108 // needed for displaying network server text instead of identifier
6109 network_server_text = network_server_hostname;
6112 static void execSetupGame(void)
6114 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6116 execSetupGame_setGameSpeeds(FALSE);
6117 execSetupGame_setScoresType();
6118 execSetupGame_setScrollDelays();
6119 execSetupGame_setSnapshotModes();
6121 execSetupGame_setNetworkServerText();
6123 if (!setup.provide_uploading_tapes)
6124 setHideSetupEntry(execOfferUploadTapes);
6126 setup_mode = SETUP_MODE_GAME;
6130 // check if vsync needs to be disabled for this game speed to work
6131 if (check_vsync_mode)
6132 DisableVsyncIfNeeded();
6135 static void execSetupChooseScoresType(void)
6137 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6142 static void execSetupChooseGameSpeed(void)
6144 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6149 static void execSetupChooseScrollDelay(void)
6151 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6156 static void execSetupChooseSnapshotMode(void)
6158 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6163 static void execSetupEngines(void)
6165 setup_mode = SETUP_MODE_ENGINES;
6170 static void execSetupEditor(void)
6172 setup_mode = SETUP_MODE_EDITOR;
6177 static void execSetupGraphics_setWindowSizes(boolean update_list)
6179 if (window_sizes != NULL && update_list)
6181 freeTreeInfo(window_sizes);
6183 window_sizes = NULL;
6186 if (window_sizes == NULL)
6188 boolean current_window_size_found = FALSE;
6191 for (i = 0; window_sizes_list[i].value != -1; i++)
6193 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6194 char identifier[32], name[32];
6195 int value = window_sizes_list[i].value;
6196 char *text = window_sizes_list[i].text;
6198 ti->node_top = &window_sizes;
6199 ti->sort_priority = value;
6201 sprintf(identifier, "%d", value);
6202 sprintf(name, "%s", text);
6204 setString(&ti->identifier, identifier);
6205 setString(&ti->name, name);
6206 setString(&ti->name_sorting, name);
6207 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6209 pushTreeInfo(&window_sizes, ti);
6211 if (value == setup.window_scaling_percent)
6212 current_window_size_found = TRUE;
6215 if (!current_window_size_found)
6217 // add entry for non-preset window scaling value
6219 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6220 char identifier[32], name[32];
6221 int value = setup.window_scaling_percent;
6223 ti->node_top = &window_sizes;
6224 ti->sort_priority = value;
6226 sprintf(identifier, "%d", value);
6227 sprintf(name, "%d %% (Current)", value);
6229 setString(&ti->identifier, identifier);
6230 setString(&ti->name, name);
6231 setString(&ti->name_sorting, name);
6232 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6234 pushTreeInfo(&window_sizes, ti);
6237 // sort window size values to start with lowest window size value
6238 sortTreeInfo(&window_sizes);
6240 // set current window size value to configured window size value
6241 window_size_current =
6242 getTreeInfoFromIdentifier(window_sizes,
6243 i_to_a(setup.window_scaling_percent));
6245 // if that fails, set current window size to reliable default value
6246 if (window_size_current == NULL)
6247 window_size_current =
6248 getTreeInfoFromIdentifier(window_sizes,
6249 i_to_a(STD_WINDOW_SCALING_PERCENT));
6251 // if that also fails, set current window size to first available value
6252 if (window_size_current == NULL)
6253 window_size_current = window_sizes;
6256 setup.window_scaling_percent = atoi(window_size_current->identifier);
6258 // needed for displaying window size text instead of identifier
6259 window_size_text = window_size_current->name;
6262 static void execSetupGraphics_setScalingTypes(void)
6264 if (scaling_types == NULL)
6268 for (i = 0; scaling_types_list[i].value != NULL; i++)
6270 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6271 char identifier[32], name[32];
6272 char *value = scaling_types_list[i].value;
6273 char *text = scaling_types_list[i].text;
6275 ti->node_top = &scaling_types;
6276 ti->sort_priority = i;
6278 sprintf(identifier, "%s", value);
6279 sprintf(name, "%s", text);
6281 setString(&ti->identifier, identifier);
6282 setString(&ti->name, name);
6283 setString(&ti->name_sorting, name);
6284 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6286 pushTreeInfo(&scaling_types, ti);
6289 // sort scaling type values to start with lowest scaling type value
6290 sortTreeInfo(&scaling_types);
6292 // set current scaling type value to configured scaling type value
6293 scaling_type_current =
6294 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6296 // if that fails, set current scaling type to reliable default value
6297 if (scaling_type_current == NULL)
6298 scaling_type_current =
6299 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6301 // if that also fails, set current scaling type to first available value
6302 if (scaling_type_current == NULL)
6303 scaling_type_current = scaling_types;
6306 setup.window_scaling_quality = scaling_type_current->identifier;
6308 // needed for displaying scaling type text instead of identifier
6309 scaling_type_text = scaling_type_current->name;
6312 static void execSetupGraphics_setRenderingModes(void)
6314 if (rendering_modes == NULL)
6318 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6320 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6321 char identifier[32], name[32];
6322 char *value = rendering_modes_list[i].value;
6323 char *text = rendering_modes_list[i].text;
6325 ti->node_top = &rendering_modes;
6326 ti->sort_priority = i;
6328 sprintf(identifier, "%s", value);
6329 sprintf(name, "%s", text);
6331 setString(&ti->identifier, identifier);
6332 setString(&ti->name, name);
6333 setString(&ti->name_sorting, name);
6334 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6336 pushTreeInfo(&rendering_modes, ti);
6339 // sort rendering mode values to start with lowest rendering mode value
6340 sortTreeInfo(&rendering_modes);
6342 // set current rendering mode value to configured rendering mode value
6343 rendering_mode_current =
6344 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6346 // if that fails, set current rendering mode to reliable default value
6347 if (rendering_mode_current == NULL)
6348 rendering_mode_current =
6349 getTreeInfoFromIdentifier(rendering_modes,
6350 STR_SPECIAL_RENDERING_DEFAULT);
6352 // if that also fails, set current rendering mode to first available one
6353 if (rendering_mode_current == NULL)
6354 rendering_mode_current = rendering_modes;
6357 setup.screen_rendering_mode = rendering_mode_current->identifier;
6359 // needed for displaying rendering mode text instead of identifier
6360 rendering_mode_text = rendering_mode_current->name;
6363 static void execSetupGraphics_setVsyncModes(boolean update_value)
6365 if (vsync_modes == NULL)
6369 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6371 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6372 char identifier[32], name[32];
6373 char *value = vsync_modes_list[i].value;
6374 char *text = vsync_modes_list[i].text;
6376 ti->node_top = &vsync_modes;
6377 ti->sort_priority = i;
6379 sprintf(identifier, "%s", value);
6380 sprintf(name, "%s", text);
6382 setString(&ti->identifier, identifier);
6383 setString(&ti->name, name);
6384 setString(&ti->name_sorting, name);
6385 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6387 pushTreeInfo(&vsync_modes, ti);
6390 // sort vsync mode values to start with lowest vsync mode value
6391 sortTreeInfo(&vsync_modes);
6393 update_value = TRUE;
6398 // set current vsync mode value to configured vsync mode value
6399 vsync_mode_current =
6400 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6402 // if that fails, set current vsync mode to reliable default value
6403 if (vsync_mode_current == NULL)
6404 vsync_mode_current =
6405 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6407 // if that also fails, set current vsync mode to first available one
6408 if (vsync_mode_current == NULL)
6409 vsync_mode_current = vsync_modes;
6412 setup.vsync_mode = vsync_mode_current->identifier;
6414 // needed for displaying vsync mode text instead of identifier
6415 vsync_mode_text = vsync_mode_current->name;
6418 static void execSetupGraphics(void)
6420 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6422 // update "setup.window_scaling_percent" from list selection
6423 // (in this case, window scaling was changed on setup screen)
6424 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6425 execSetupGraphics_setWindowSizes(FALSE);
6427 // update "setup.vsync_mode" from list selection
6428 // (in this case, vsync mode was changed on setup screen)
6429 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6430 execSetupGraphics_setVsyncModes(FALSE);
6432 // update list selection from "setup.window_scaling_percent"
6433 // (window scaling may have changed by resizing the window)
6434 execSetupGraphics_setWindowSizes(TRUE);
6436 // update list selection from "setup.vsync_mode"
6437 // (vsync_mode may have changed by re-creating the renderer)
6438 execSetupGraphics_setVsyncModes(TRUE);
6440 execSetupGraphics_setScalingTypes();
6441 execSetupGraphics_setRenderingModes();
6443 setup_mode = SETUP_MODE_GRAPHICS;
6447 // check if game speed is high enough for 60 Hz vsync to work
6448 if (check_game_speed)
6449 ModifyGameSpeedIfNeeded();
6451 // window scaling may have changed at this point
6452 ChangeWindowScalingIfNeeded();
6454 // window scaling quality may have changed at this point
6455 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6456 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6458 // screen rendering mode may have changed at this point
6459 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6461 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6462 int video_vsync_mode = video.vsync_mode;
6464 // screen vsync mode may have changed at this point
6465 ChangeVsyncModeIfNeeded();
6467 // check if setting vsync mode to selected value failed
6468 if (setup_vsync_mode != video_vsync_mode &&
6469 setup_vsync_mode != video.vsync_mode)
6471 // changing vsync mode to selected value failed -- reset displayed value
6472 execSetupGraphics_setVsyncModes(TRUE);
6474 Request("Setting VSync failed!", REQ_CONFIRM);
6480 static void execSetupChooseWindowSize(void)
6482 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6487 static void execSetupChooseScalingType(void)
6489 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6494 static void execSetupChooseRenderingMode(void)
6496 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6501 static void execSetupChooseVsyncMode(void)
6503 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6508 static void execSetupChooseVolumeSimple(void)
6510 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6515 static void execSetupChooseVolumeLoops(void)
6517 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6522 static void execSetupChooseVolumeMusic(void)
6524 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6529 static void execSetupSound(void)
6531 if (volumes_simple == NULL)
6533 boolean current_volume_simple_found = FALSE;
6536 for (i = 0; volumes_list[i].value != -1; i++)
6538 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6539 char identifier[32], name[32];
6540 int value = volumes_list[i].value;
6541 char *text = volumes_list[i].text;
6543 ti->node_top = &volumes_simple;
6544 ti->sort_priority = value;
6546 sprintf(identifier, "%d", value);
6547 sprintf(name, "%s", text);
6549 setString(&ti->identifier, identifier);
6550 setString(&ti->name, name);
6551 setString(&ti->name_sorting, name);
6552 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6554 pushTreeInfo(&volumes_simple, ti);
6556 if (value == setup.volume_simple)
6557 current_volume_simple_found = TRUE;
6560 if (!current_volume_simple_found)
6562 // add entry for non-preset volume value
6564 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6565 char identifier[32], name[32];
6566 int value = setup.volume_simple;
6568 ti->node_top = &volumes_simple;
6569 ti->sort_priority = value;
6571 sprintf(identifier, "%d", value);
6572 sprintf(name, "%d %% (Current)", value);
6574 setString(&ti->identifier, identifier);
6575 setString(&ti->name, name);
6576 setString(&ti->name_sorting, name);
6577 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6579 pushTreeInfo(&volumes_simple, ti);
6582 // sort volume values to start with lowest volume value
6583 sortTreeInfo(&volumes_simple);
6585 // set current volume value to configured volume value
6586 volume_simple_current =
6587 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6589 // if that fails, set current volume to reliable default value
6590 if (volume_simple_current == NULL)
6591 volume_simple_current =
6592 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6594 // if that also fails, set current volume to first available value
6595 if (volume_simple_current == NULL)
6596 volume_simple_current = volumes_simple;
6599 if (volumes_loops == NULL)
6601 boolean current_volume_loops_found = FALSE;
6604 for (i = 0; volumes_list[i].value != -1; i++)
6606 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6607 char identifier[32], name[32];
6608 int value = volumes_list[i].value;
6609 char *text = volumes_list[i].text;
6611 ti->node_top = &volumes_loops;
6612 ti->sort_priority = value;
6614 sprintf(identifier, "%d", value);
6615 sprintf(name, "%s", text);
6617 setString(&ti->identifier, identifier);
6618 setString(&ti->name, name);
6619 setString(&ti->name_sorting, name);
6620 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6622 pushTreeInfo(&volumes_loops, ti);
6624 if (value == setup.volume_loops)
6625 current_volume_loops_found = TRUE;
6628 if (!current_volume_loops_found)
6630 // add entry for non-preset volume value
6632 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6633 char identifier[32], name[32];
6634 int value = setup.volume_loops;
6636 ti->node_top = &volumes_loops;
6637 ti->sort_priority = value;
6639 sprintf(identifier, "%d", value);
6640 sprintf(name, "%d %% (Current)", value);
6642 setString(&ti->identifier, identifier);
6643 setString(&ti->name, name);
6644 setString(&ti->name_sorting, name);
6645 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6647 pushTreeInfo(&volumes_loops, ti);
6650 // sort volume values to start with lowest volume value
6651 sortTreeInfo(&volumes_loops);
6653 // set current volume value to configured volume value
6654 volume_loops_current =
6655 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6657 // if that fails, set current volume to reliable default value
6658 if (volume_loops_current == NULL)
6659 volume_loops_current =
6660 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6662 // if that also fails, set current volume to first available value
6663 if (volume_loops_current == NULL)
6664 volume_loops_current = volumes_loops;
6667 if (volumes_music == NULL)
6669 boolean current_volume_music_found = FALSE;
6672 for (i = 0; volumes_list[i].value != -1; i++)
6674 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6675 char identifier[32], name[32];
6676 int value = volumes_list[i].value;
6677 char *text = volumes_list[i].text;
6679 ti->node_top = &volumes_music;
6680 ti->sort_priority = value;
6682 sprintf(identifier, "%d", value);
6683 sprintf(name, "%s", text);
6685 setString(&ti->identifier, identifier);
6686 setString(&ti->name, name);
6687 setString(&ti->name_sorting, name);
6688 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6690 pushTreeInfo(&volumes_music, ti);
6692 if (value == setup.volume_music)
6693 current_volume_music_found = TRUE;
6696 if (!current_volume_music_found)
6698 // add entry for non-preset volume value
6700 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6701 char identifier[32], name[32];
6702 int value = setup.volume_music;
6704 ti->node_top = &volumes_music;
6705 ti->sort_priority = value;
6707 sprintf(identifier, "%d", value);
6708 sprintf(name, "%d %% (Current)", value);
6710 setString(&ti->identifier, identifier);
6711 setString(&ti->name, name);
6712 setString(&ti->name_sorting, name);
6713 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6715 pushTreeInfo(&volumes_music, ti);
6718 // sort volume values to start with lowest volume value
6719 sortTreeInfo(&volumes_music);
6721 // set current volume value to configured volume value
6722 volume_music_current =
6723 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6725 // if that fails, set current volume to reliable default value
6726 if (volume_music_current == NULL)
6727 volume_music_current =
6728 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6730 // if that also fails, set current volume to first available value
6731 if (volume_music_current == NULL)
6732 volume_music_current = volumes_music;
6735 setup.volume_simple = atoi(volume_simple_current->identifier);
6736 setup.volume_loops = atoi(volume_loops_current->identifier);
6737 setup.volume_music = atoi(volume_music_current->identifier);
6739 // needed for displaying volume text instead of identifier
6740 volume_simple_text = volume_simple_current->name;
6741 volume_loops_text = volume_loops_current->name;
6742 volume_music_text = volume_music_current->name;
6744 setup_mode = SETUP_MODE_SOUND;
6749 static void execSetupChooseTouchControls(void)
6751 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6756 static void execSetupChooseMoveDistance(void)
6758 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6763 static void execSetupChooseDropDistance(void)
6765 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6770 static void execSetupChooseTransparency(void)
6772 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6777 static void execSetupChooseGridXSize_0(void)
6779 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6784 static void execSetupChooseGridYSize_0(void)
6786 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6791 static void execSetupChooseGridXSize_1(void)
6793 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6798 static void execSetupChooseGridYSize_1(void)
6800 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6805 static void execSetupConfigureVirtualButtons(void)
6807 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6809 ConfigureVirtualButtons();
6811 setup_mode = SETUP_MODE_TOUCH;
6816 static void execSetupTouch(void)
6820 if (touch_controls == NULL)
6822 for (i = 0; touch_controls_list[i].value != NULL; i++)
6824 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6825 char identifier[32], name[32];
6826 char *value = touch_controls_list[i].value;
6827 char *text = touch_controls_list[i].text;
6829 ti->node_top = &touch_controls;
6830 ti->sort_priority = i;
6832 sprintf(identifier, "%s", value);
6833 sprintf(name, "%s", text);
6835 setString(&ti->identifier, identifier);
6836 setString(&ti->name, name);
6837 setString(&ti->name_sorting, name);
6838 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6840 pushTreeInfo(&touch_controls, ti);
6843 // sort touch control values to start with lowest touch control value
6844 sortTreeInfo(&touch_controls);
6846 // set current touch control value to configured touch control value
6847 touch_control_current =
6848 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6850 // if that fails, set current touch control to reliable default value
6851 if (touch_control_current == NULL)
6852 touch_control_current =
6853 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6855 // if that also fails, set current touch control to first available value
6856 if (touch_control_current == NULL)
6857 touch_control_current = touch_controls;
6860 if (move_distances == NULL)
6862 for (i = 0; distances_list[i].value != -1; i++)
6864 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6865 char identifier[32], name[32];
6866 int value = distances_list[i].value;
6867 char *text = distances_list[i].text;
6869 ti->node_top = &move_distances;
6870 ti->sort_priority = value;
6872 sprintf(identifier, "%d", value);
6873 sprintf(name, "%s", text);
6875 setString(&ti->identifier, identifier);
6876 setString(&ti->name, name);
6877 setString(&ti->name_sorting, name);
6878 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6880 pushTreeInfo(&move_distances, ti);
6883 // sort distance values to start with lowest distance value
6884 sortTreeInfo(&move_distances);
6886 // set current distance value to configured distance value
6887 move_distance_current =
6888 getTreeInfoFromIdentifier(move_distances,
6889 i_to_a(setup.touch.move_distance));
6891 // if that fails, set current distance to reliable default value
6892 if (move_distance_current == NULL)
6893 move_distance_current =
6894 getTreeInfoFromIdentifier(move_distances,
6895 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6897 // if that also fails, set current distance to first available value
6898 if (move_distance_current == NULL)
6899 move_distance_current = move_distances;
6902 if (drop_distances == NULL)
6904 for (i = 0; distances_list[i].value != -1; i++)
6906 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6907 char identifier[32], name[32];
6908 int value = distances_list[i].value;
6909 char *text = distances_list[i].text;
6911 ti->node_top = &drop_distances;
6912 ti->sort_priority = value;
6914 sprintf(identifier, "%d", value);
6915 sprintf(name, "%s", text);
6917 setString(&ti->identifier, identifier);
6918 setString(&ti->name, name);
6919 setString(&ti->name_sorting, name);
6920 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6922 pushTreeInfo(&drop_distances, ti);
6925 // sort distance values to start with lowest distance value
6926 sortTreeInfo(&drop_distances);
6928 // set current distance value to configured distance value
6929 drop_distance_current =
6930 getTreeInfoFromIdentifier(drop_distances,
6931 i_to_a(setup.touch.drop_distance));
6933 // if that fails, set current distance to reliable default value
6934 if (drop_distance_current == NULL)
6935 drop_distance_current =
6936 getTreeInfoFromIdentifier(drop_distances,
6937 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6939 // if that also fails, set current distance to first available value
6940 if (drop_distance_current == NULL)
6941 drop_distance_current = drop_distances;
6944 if (transparencies == NULL)
6946 for (i = 0; transparencies_list[i].value != -1; i++)
6948 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6949 char identifier[32], name[32];
6950 int value = transparencies_list[i].value;
6951 char *text = transparencies_list[i].text;
6953 ti->node_top = &transparencies;
6954 ti->sort_priority = value;
6956 sprintf(identifier, "%d", value);
6957 sprintf(name, "%s", text);
6959 setString(&ti->identifier, identifier);
6960 setString(&ti->name, name);
6961 setString(&ti->name_sorting, name);
6962 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6964 pushTreeInfo(&transparencies, ti);
6967 // sort transparency values to start with lowest transparency value
6968 sortTreeInfo(&transparencies);
6970 // set current transparency value to configured transparency value
6971 transparency_current =
6972 getTreeInfoFromIdentifier(transparencies,
6973 i_to_a(setup.touch.transparency));
6975 // if that fails, set current transparency to reliable default value
6976 if (transparency_current == NULL)
6977 transparency_current =
6978 getTreeInfoFromIdentifier(transparencies,
6979 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6981 // if that also fails, set current transparency to first available value
6982 if (transparency_current == NULL)
6983 transparency_current = transparencies;
6986 for (i = 0; i < 2; i++)
6988 for (j = 0; j < 2; j++)
6990 if (grid_sizes[i][j] == NULL)
6992 for (k = 0; grid_sizes_list[k].value != -1; k++)
6994 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6995 char identifier[32], name[32];
6996 int value = grid_sizes_list[k].value;
6997 char *text = grid_sizes_list[k].text;
6999 ti->node_top = &grid_sizes[i][j];
7000 ti->sort_priority = value;
7002 sprintf(identifier, "%d", value);
7003 sprintf(name, "%s", text);
7005 setString(&ti->identifier, identifier);
7006 setString(&ti->name, name);
7007 setString(&ti->name_sorting, name);
7008 setString(&ti->infotext,
7011 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7012 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7014 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7015 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7017 pushTreeInfo(&grid_sizes[i][j], ti);
7020 // sort grid size values to start with lowest grid size value
7021 sortTreeInfo(&grid_sizes[i][j]);
7023 // set current grid size value to configured grid size value
7024 grid_size_current[i][j] =
7025 getTreeInfoFromIdentifier(grid_sizes[i][j],
7027 setup.touch.grid_xsize[i] :
7028 setup.touch.grid_ysize[i]));
7030 // if that fails, set current grid size to reliable default value
7031 if (grid_size_current[i][j] == NULL)
7032 grid_size_current[i][j] =
7033 getTreeInfoFromIdentifier(grid_sizes[i][j],
7035 DEFAULT_GRID_XSIZE(i) :
7036 DEFAULT_GRID_YSIZE(i)));
7038 // if that also fails, set current grid size to first available value
7039 if (grid_size_current[i][j] == NULL)
7040 grid_size_current[i][j] = grid_sizes[i][j];
7045 setup.touch.control_type = touch_control_current->identifier;
7046 setup.touch.move_distance = atoi(move_distance_current->identifier);
7047 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7048 setup.touch.transparency = atoi(transparency_current->identifier);
7050 for (i = 0; i < 2; i++)
7052 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7053 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7055 if (i == GRID_ACTIVE_NR())
7057 overlay.grid_xsize = setup.touch.grid_xsize[i];
7058 overlay.grid_ysize = setup.touch.grid_ysize[i];
7062 // needed for displaying value text instead of identifier
7063 touch_controls_text = touch_control_current->name;
7064 move_distance_text = move_distance_current->name;
7065 drop_distance_text = drop_distance_current->name;
7066 transparency_text = transparency_current->name;
7068 for (i = 0; i < 2; i++)
7069 for (j = 0; j < 2; j++)
7070 grid_size_text[i][j] = grid_size_current[i][j]->name;
7072 setup_mode = SETUP_MODE_TOUCH;
7077 static void execSetupArtwork(void)
7079 static ArtworkDirTree *gfx_last_valid = NULL;
7080 static ArtworkDirTree *snd_last_valid = NULL;
7081 static ArtworkDirTree *mus_last_valid = NULL;
7083 // current artwork directory may be invalid (level group, parent link)
7084 if (!validLevelSeries(artwork.gfx_current))
7085 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7086 if (!validLevelSeries(artwork.snd_current))
7087 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7088 if (!validLevelSeries(artwork.mus_current))
7089 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7091 // store valid artwork directory information
7092 gfx_last_valid = artwork.gfx_current;
7093 snd_last_valid = artwork.snd_current;
7094 mus_last_valid = artwork.mus_current;
7097 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7098 artwork.gfx_current->subdir,
7099 artwork.gfx_current->fullpath,
7100 artwork.gfx_current->basepath);
7103 setup.graphics_set = artwork.gfx_current->identifier;
7104 setup.sounds_set = artwork.snd_current->identifier;
7105 setup.music_set = artwork.mus_current->identifier;
7107 // needed if last screen (setup choice) changed graphics, sounds or music
7108 ReloadCustomArtwork(0);
7110 // needed for displaying artwork name instead of artwork identifier
7111 graphics_set_name = artwork.gfx_current->name;
7112 sounds_set_name = artwork.snd_current->name;
7113 music_set_name = artwork.mus_current->name;
7115 setup_mode = SETUP_MODE_ARTWORK;
7120 static void execSetupChooseGraphics(void)
7122 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7127 static void execSetupChooseSounds(void)
7129 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7134 static void execSetupChooseMusic(void)
7136 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7141 static void execSetupInput(void)
7143 setup_mode = SETUP_MODE_INPUT;
7148 static void execSetupShortcuts(void)
7150 setup_mode = SETUP_MODE_SHORTCUTS;
7155 static void execSetupShortcuts1(void)
7157 setup_mode = SETUP_MODE_SHORTCUTS_1;
7162 static void execSetupShortcuts2(void)
7164 setup_mode = SETUP_MODE_SHORTCUTS_2;
7169 static void execSetupShortcuts3(void)
7171 setup_mode = SETUP_MODE_SHORTCUTS_3;
7176 static void execSetupShortcuts4(void)
7178 setup_mode = SETUP_MODE_SHORTCUTS_4;
7183 static void execSetupShortcuts5(void)
7185 setup_mode = SETUP_MODE_SHORTCUTS_5;
7190 static void execExitSetup(void)
7192 SetGameStatus(GAME_MODE_MAIN);
7197 static void execSaveAndExitSetup(void)
7203 static void execGadgetNetworkServer(void)
7205 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7206 struct GadgetInfo *gi = screen_gadget[gadget_id];
7208 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7209 network_server_hostname[0] = '\0';
7211 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7215 ClickOnGadget(gi, MB_LEFTBUTTON);
7218 static void execOfferUploadTapes(void)
7223 static void ToggleNetworkModeIfNeeded(void)
7225 int font_title = FONT_TITLE_1;
7226 int font_foot = FC_BLUE;
7227 int ystart = mSY - SY + 16;
7228 int ybottom = mSY - SY + SYSIZE - 20;
7229 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7231 if (setup.network_mode == network.enabled)
7234 network.enabled = setup.network_mode;
7236 FadeOut(REDRAW_ALL);
7240 DrawTextSCentered(ystart, font_title, text);
7244 if (network.enabled)
7245 InitNetworkServer();
7247 DisconnectFromNetworkServer();
7249 DrawTextSCentered(ybottom, font_foot,
7250 "Press any key or button for setup menu");
7252 WaitForEventToContinue();
7257 static void ToggleGameSpeedsListIfNeeded(void)
7259 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7261 if (setup.game_speed_extended == using_game_speeds_extended)
7264 // try to match similar values when changing game speeds list
7265 if (setup.game_speed_extended)
7266 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7267 setup.game_frame_delay == 30 ? 29 :
7268 setup.game_frame_delay);
7270 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7271 setup.game_frame_delay == 16 ? 15 :
7272 setup.game_frame_delay >= 29 ? 30 :
7273 setup.game_frame_delay <= 10 ? 10 :
7274 setup.game_frame_delay);
7276 execSetupGame_setGameSpeeds(TRUE);
7281 static void ToggleUseApiServerIfNeeded(void)
7283 if (runtime.use_api_server == setup.use_api_server)
7286 runtime.use_api_server = setup.use_api_server;
7288 if (runtime.use_api_server)
7289 CheckApiServerTasks();
7292 static void ModifyGameSpeedIfNeeded(void)
7294 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7295 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7299 char *game_speed_text = "Fast";
7300 int game_speed_value = 15;
7302 if (setup.game_speed_extended)
7304 game_speed_text = "60 fps";
7305 game_speed_value = 16;
7308 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7310 // set game speed to existing list value that is fast enough for vsync
7311 setup.game_frame_delay = game_speed_value;
7313 execSetupGame_setGameSpeeds(TRUE);
7315 Request(message, REQ_CONFIRM);
7318 static void DisableVsyncIfNeeded(void)
7320 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7321 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7322 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7325 // disable vsync for the selected game speed to work
7326 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7328 execSetupGraphics_setVsyncModes(TRUE);
7330 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7336 void *related_value;
7337 } hide_related_entry_list[] =
7339 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7340 { &setup.scores_in_highscore_list, &scores_type_text },
7342 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7343 { &setup.game_frame_delay, &game_speed_text },
7345 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7346 { &setup.scroll_delay_value, &scroll_delay_text },
7348 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7349 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7351 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7352 { &setup.window_scaling_percent, &window_size_text },
7354 { &setup.window_scaling_quality, execSetupChooseScalingType },
7355 { &setup.window_scaling_quality, &scaling_type_text },
7357 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7358 { &setup.screen_rendering_mode, &rendering_mode_text },
7360 { &setup.vsync_mode, execSetupChooseVsyncMode },
7361 { &setup.vsync_mode, &vsync_mode_text },
7363 { &setup.graphics_set, execSetupChooseGraphics },
7364 { &setup.graphics_set, &graphics_set_name },
7366 { &setup.sounds_set, execSetupChooseSounds },
7367 { &setup.sounds_set, &sounds_set_name },
7369 { &setup.music_set, execSetupChooseMusic },
7370 { &setup.music_set, &music_set_name },
7372 { &setup.volume_simple, execSetupChooseVolumeSimple },
7373 { &setup.volume_simple, &volume_simple_text },
7375 { &setup.volume_loops, execSetupChooseVolumeLoops },
7376 { &setup.volume_loops, &volume_loops_text },
7378 { &setup.volume_music, execSetupChooseVolumeMusic },
7379 { &setup.volume_music, &volume_music_text },
7381 { &setup.touch.control_type, execSetupChooseTouchControls },
7382 { &setup.touch.control_type, &touch_controls_text },
7384 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7385 { &setup.touch.move_distance, &move_distance_text },
7387 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7388 { &setup.touch.drop_distance, &drop_distance_text },
7390 { &setup.touch.transparency, execSetupChooseTransparency },
7391 { &setup.touch.transparency, &transparency_text },
7393 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7394 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7396 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7397 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7399 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7400 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7402 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7403 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7405 { &setup.internal.menu_game, execSetupGame },
7406 { &setup.internal.menu_engines, execSetupEngines },
7407 { &setup.internal.menu_editor, execSetupEditor },
7408 { &setup.internal.menu_graphics, execSetupGraphics },
7409 { &setup.internal.menu_sound, execSetupSound },
7410 { &setup.internal.menu_artwork, execSetupArtwork },
7411 { &setup.internal.menu_input, execSetupInput },
7412 { &setup.internal.menu_touch, execSetupTouch },
7413 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7414 { &setup.internal.menu_exit, execExitSetup },
7415 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7420 void setHideRelatedSetupEntries(void)
7424 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7425 if (hideSetupEntry(hide_related_entry_list[i].value))
7426 setHideSetupEntry(hide_related_entry_list[i].related_value);
7429 static struct TokenInfo setup_info_main[] =
7431 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7432 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7433 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7434 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7435 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7436 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7437 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7438 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7439 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7440 { TYPE_EMPTY, NULL, "" },
7441 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7442 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7447 static struct TokenInfo setup_info_game[] =
7449 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7450 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7451 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7452 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7453 { TYPE_STRING, &network_server_text, "" },
7454 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7455 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7456 { TYPE_STRING, &scores_type_text, "" },
7457 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7458 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7459 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7460 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7461 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7462 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7463 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7464 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7465 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7466 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7467 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7468 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7469 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7470 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7471 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7472 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7473 { TYPE_STRING, &game_speed_text, "" },
7474 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7476 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7477 { TYPE_STRING, &scroll_delay_text, "" },
7479 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7480 { TYPE_STRING, &snapshot_mode_text, "" },
7481 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7482 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7483 { TYPE_EMPTY, NULL, "" },
7484 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7489 static struct TokenInfo setup_info_engines[] =
7491 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7492 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7493 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7494 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7495 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7496 { TYPE_EMPTY, NULL, "" },
7497 { TYPE_HEADLINE, NULL, "Supaplex" },
7498 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7499 { TYPE_EMPTY, NULL, "" },
7500 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7505 static struct TokenInfo setup_info_editor[] =
7508 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7509 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7510 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7511 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7512 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7513 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7514 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7515 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7516 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7517 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7519 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7520 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7522 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7524 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7525 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7526 { TYPE_EMPTY, NULL, "" },
7528 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7529 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7530 { TYPE_EMPTY, NULL, "" },
7532 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7533 { TYPE_EMPTY, NULL, "" },
7534 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7535 { TYPE_EMPTY, NULL, "" },
7536 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7541 static struct TokenInfo setup_info_graphics[] =
7543 #if !defined(PLATFORM_ANDROID)
7544 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7545 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7546 { TYPE_STRING, &window_size_text, "" },
7547 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7548 { TYPE_STRING, &scaling_type_text, "" },
7549 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7550 { TYPE_STRING, &rendering_mode_text, "" },
7553 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7554 { TYPE_STRING, &scroll_delay_text, "" },
7556 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7557 { TYPE_STRING, &vsync_mode_text, "" },
7558 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7559 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7560 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7561 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7562 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7563 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7564 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7565 { TYPE_EMPTY, NULL, "" },
7566 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7571 static struct TokenInfo setup_info_sound[] =
7573 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7574 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7575 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7576 { TYPE_EMPTY, NULL, "" },
7577 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7578 { TYPE_STRING, &volume_simple_text, "" },
7579 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7580 { TYPE_STRING, &volume_loops_text, "" },
7581 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7582 { TYPE_STRING, &volume_music_text, "" },
7583 { TYPE_EMPTY, NULL, "" },
7584 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7589 static struct TokenInfo setup_info_artwork[] =
7591 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7592 { TYPE_STRING, &graphics_set_name, "" },
7593 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7594 { TYPE_STRING, &sounds_set_name, "" },
7595 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7596 { TYPE_STRING, &music_set_name, "" },
7597 { TYPE_EMPTY, NULL, "" },
7598 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7599 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7600 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7601 { TYPE_EMPTY, NULL, "" },
7602 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7607 static struct TokenInfo setup_info_input[] =
7609 { TYPE_SWITCH, NULL, "Player:" },
7610 { TYPE_SWITCH, NULL, "Device:" },
7611 { TYPE_SWITCH, NULL, "" },
7612 { TYPE_SKIPPABLE, NULL, "" },
7613 { TYPE_EMPTY, NULL, "" },
7614 { TYPE_EMPTY, NULL, "" },
7615 { TYPE_EMPTY, NULL, "" },
7616 { TYPE_EMPTY, NULL, "" },
7617 { TYPE_EMPTY, NULL, "" },
7618 { TYPE_EMPTY, NULL, "" },
7619 { TYPE_EMPTY, NULL, "" },
7620 { TYPE_EMPTY, NULL, "" },
7621 { TYPE_SKIPPABLE, NULL, "" },
7622 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7627 static struct TokenInfo setup_info_touch[] =
7629 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7630 { TYPE_STRING, &touch_controls_text, "" },
7631 { TYPE_EMPTY, NULL, "" },
7632 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7637 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7639 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7640 { TYPE_STRING, &touch_controls_text, "" },
7641 { TYPE_EMPTY, NULL, "" },
7642 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7643 { TYPE_STRING, &grid_size_text[0][0], "" },
7644 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7645 { TYPE_STRING, &grid_size_text[0][1], "" },
7646 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7647 { TYPE_STRING, &transparency_text, "" },
7648 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7649 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7650 { TYPE_EMPTY, NULL, "" },
7651 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7652 { TYPE_EMPTY, NULL, "" },
7653 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7658 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7660 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7661 { TYPE_STRING, &touch_controls_text, "" },
7662 { TYPE_EMPTY, NULL, "" },
7663 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7664 { TYPE_STRING, &grid_size_text[1][0], "" },
7665 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7666 { TYPE_STRING, &grid_size_text[1][1], "" },
7667 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7668 { TYPE_STRING, &transparency_text, "" },
7669 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7670 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7671 { TYPE_EMPTY, NULL, "" },
7672 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7673 { TYPE_EMPTY, NULL, "" },
7674 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7679 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7681 setup_info_touch_virtual_buttons_0,
7682 setup_info_touch_virtual_buttons_1
7685 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7687 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7688 { TYPE_STRING, &touch_controls_text, "" },
7689 { TYPE_EMPTY, NULL, "" },
7690 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7691 { TYPE_STRING, &move_distance_text, "" },
7692 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7693 { TYPE_STRING, &drop_distance_text, "" },
7694 { TYPE_EMPTY, NULL, "" },
7695 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7700 static struct TokenInfo setup_info_shortcuts[] =
7702 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7703 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7704 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7705 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7706 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7707 { TYPE_EMPTY, NULL, "" },
7708 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7713 static struct TokenInfo setup_info_shortcuts_1[] =
7715 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7716 { TYPE_KEY, &setup.shortcut.save_game, "" },
7717 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7718 { TYPE_KEY, &setup.shortcut.load_game, "" },
7719 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7720 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7721 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7722 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7723 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7724 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7725 { TYPE_EMPTY, NULL, "" },
7726 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7727 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7728 { TYPE_EMPTY, NULL, "" },
7729 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7734 static struct TokenInfo setup_info_shortcuts_2[] =
7736 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7737 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7738 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7739 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7740 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7741 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7742 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7743 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7744 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7745 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7746 { TYPE_EMPTY, NULL, "" },
7747 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7752 static struct TokenInfo setup_info_shortcuts_3[] =
7754 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7755 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7756 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7757 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7758 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7759 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7760 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7761 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7762 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7763 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7764 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7765 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7766 { TYPE_EMPTY, NULL, "" },
7767 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7772 static struct TokenInfo setup_info_shortcuts_4[] =
7774 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7775 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7776 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7777 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7778 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7779 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7780 { TYPE_EMPTY, NULL, "" },
7781 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7786 static struct TokenInfo setup_info_shortcuts_5[] =
7788 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7789 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7790 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7791 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7792 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7793 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7794 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7795 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7796 { TYPE_EMPTY, NULL, "" },
7797 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7802 static Key getSetupKey(void)
7804 Key key = KSYM_UNDEFINED;
7805 boolean got_key_event = FALSE;
7807 while (!got_key_event)
7811 if (NextValidEvent(&event))
7815 case EVENT_KEYPRESS:
7817 key = GetEventKey((KeyEvent *)&event, TRUE);
7819 // press 'Escape' or 'Enter' to keep the existing key binding
7820 if (key == KSYM_Escape || key == KSYM_Return)
7821 key = KSYM_UNDEFINED; // keep old value
7823 got_key_event = TRUE;
7827 case EVENT_KEYRELEASE:
7828 key_joystick_mapping = 0;
7832 HandleOtherEvents(&event);
7843 static int getSetupValueFont(int type, void *value)
7845 if (type & TYPE_GHOSTED)
7846 return FONT_OPTION_OFF;
7847 else if (type & TYPE_KEY)
7848 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7849 else if (type & TYPE_STRING)
7850 return FONT_VALUE_2;
7851 else if (type & TYPE_ECS_AGA)
7852 return FONT_VALUE_1;
7853 else if (type & TYPE_BOOLEAN_STYLE)
7854 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7855 else if (type & TYPE_YES_NO_AUTO)
7856 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7857 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7858 else if (type & TYPE_PLAYER)
7859 return FONT_VALUE_1;
7861 return FONT_VALUE_1;
7864 static int getSetupValueFontNarrow(int type, int font_nr)
7866 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7867 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7868 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7872 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7874 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7875 struct TokenInfo *si = &setup_info[si_pos];
7876 boolean font_draw_xoffset_modified = FALSE;
7877 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7878 int font_draw_xoffset_old = -1;
7879 int xoffset = (scrollbar_needed ? -1 : 0);
7880 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7881 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7882 int xpos = menu_screen_value_xpos;
7883 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7884 int startx = mSX + xpos * 32;
7885 int starty = mSY + ypos * 32;
7886 int type = si->type;
7887 void *value = si->value;
7888 char *value_string = getSetupValue(type, value);
7889 int font_nr_default = getSetupValueFont(type, value);
7890 int font_width_default = getFontWidth(font_nr_default);
7891 int font_nr = font_nr_default;
7894 if (value_string == NULL)
7897 if (type & TYPE_KEY)
7899 xpos = MENU_SCREEN_START_XPOS;
7901 if (type & TYPE_QUERY)
7902 value_string = "<press key>";
7904 else if (type & TYPE_STRING)
7906 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7908 xpos = MENU_SCREEN_START_XPOS;
7910 if (strlen(value_string) > max_value_len)
7911 value_string[max_value_len] = '\0';
7913 else if (type & TYPE_YES_NO_AUTO)
7915 xpos = menu_screen_value_xpos - 1;
7917 else if (type & TYPE_PLAYER)
7919 int displayed_player_nr = *(int *)value + 1;
7921 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7924 startx = mSX + xpos * 32;
7925 starty = mSY + ypos * 32;
7927 // special check if right-side setup values moved left due to scrollbar
7928 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7930 int max_menu_text_length = 26; // maximum text length for classic menu
7931 int font_xoffset = getFontDrawOffsetX(font_nr);
7932 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7933 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7934 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7935 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7937 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7939 // when using narrow font, left-shifting text "auto" not needed
7940 if (type & TYPE_YES_NO_AUTO)
7944 startx = mSX + xpos * 32;
7946 font_nr = getSetupValueFontNarrow(type, font_nr);
7950 // downward compatibility correction for Juergen Bonhagen's menu settings
7951 if (setup_mode != SETUP_MODE_INPUT)
7953 int max_menu_text_length_big = (menu_screen_value_xpos -
7954 MENU_SCREEN_START_XPOS);
7955 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7956 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7957 int font1_xoffset = getFontDrawOffsetX(font_nr);
7958 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7959 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7960 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7961 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7962 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7963 boolean correct_font_draw_xoffset = FALSE;
7965 if (xpos == MENU_SCREEN_START_XPOS &&
7966 startx + font1_xoffset < text_startx + text_font_xoffset)
7967 correct_font_draw_xoffset = TRUE;
7969 if (xpos == menu_screen_value_xpos &&
7970 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7971 correct_font_draw_xoffset = TRUE;
7973 // check if setup value would overlap with setup text when printed
7974 // (this can happen for extreme/wrong values for font draw offset)
7975 if (correct_font_draw_xoffset)
7977 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7978 font_draw_xoffset_modified = TRUE;
7980 if (type & TYPE_KEY)
7981 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7982 else if (!(type & TYPE_STRING))
7983 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7984 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7988 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7989 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7991 DrawText(startx, starty, value_string, font_nr);
7993 if (type & TYPE_PLAYER)
7995 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7996 int player_nr = *(int *)value;
7997 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7998 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7999 int startx2 = startx + xoff;
8000 int starty2 = starty + yoff;
8002 if (DrawingOnBackground(startx2, starty2))
8003 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8005 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8006 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8009 if (font_draw_xoffset_modified)
8010 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8013 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8015 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8016 struct TokenInfo *si = &setup_info[si_pos];
8018 if (si->type & TYPE_BOOLEAN_STYLE)
8020 *(boolean *)si->value ^= TRUE;
8022 else if (si->type & TYPE_YES_NO_AUTO)
8026 (*(int *)si->value == AUTO ? TRUE :
8027 *(int *)si->value == TRUE ? FALSE : AUTO) :
8028 (*(int *)si->value == TRUE ? AUTO :
8029 *(int *)si->value == AUTO ? FALSE : TRUE));
8031 else if (si->type & TYPE_KEY)
8035 si->type |= TYPE_QUERY;
8036 drawSetupValue(screen_pos, setup_info_pos_raw);
8037 si->type &= ~TYPE_QUERY;
8039 key = getSetupKey();
8040 if (key != KSYM_UNDEFINED)
8041 *(Key *)si->value = key;
8043 else if (si->type & TYPE_PLAYER)
8045 int player_nr = *(int *)si->value;
8050 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8052 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8055 drawSetupValue(screen_pos, setup_info_pos_raw);
8057 // fullscreen state may have changed at this point
8058 if (si->value == &setup.fullscreen)
8059 ToggleFullscreenIfNeeded();
8061 // network mode may have changed at this point
8062 if (si->value == &setup.network_mode)
8063 ToggleNetworkModeIfNeeded();
8065 // API server mode may have changed at this point
8066 if (si->value == &setup.use_api_server)
8067 ToggleUseApiServerIfNeeded();
8069 // game speed list may have changed at this point
8070 if (si->value == &setup.game_speed_extended)
8071 ToggleGameSpeedsListIfNeeded();
8074 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8076 static struct TokenInfo *setup_info_final = NULL;
8081 // determine maximum list size of target list
8082 while (setup_info_orig[list_size++].type != 0);
8084 // free, allocate and clear memory for target list
8085 checked_free(setup_info_final);
8086 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8088 // copy setup info list without setup entries marked as hidden
8089 for (i = 0; setup_info_orig[i].type != 0; i++)
8091 // skip setup entries configured to be hidden
8092 if (hideSetupEntry(setup_info_orig[i].value))
8095 // skip skippable setup entries if screen is lower than usual
8096 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8097 setup_info_orig[i].type == TYPE_SKIPPABLE)
8100 setup_info_final[list_pos++] = setup_info_orig[i];
8103 return setup_info_final;
8106 static void DrawSetupScreen_Generic(void)
8108 int fade_mask = REDRAW_FIELD;
8109 boolean redraw_all = FALSE;
8110 char *title_string = NULL;
8114 fade_mask = REDRAW_ALL;
8117 FadeMenuSoundsAndMusic();
8119 FreeScreenGadgets();
8120 CreateScreenGadgets();
8122 if (redraw_mask & REDRAW_ALL)
8127 // needed if different viewport properties defined for setup screen
8128 ChangeViewportPropertiesIfNeeded();
8130 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8134 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8136 if (setup_mode == SETUP_MODE_MAIN)
8138 setup_info = setup_info_main;
8139 title_string = STR_SETUP_MAIN;
8141 else if (setup_mode == SETUP_MODE_GAME)
8143 setup_info = setup_info_game;
8144 title_string = STR_SETUP_GAME;
8146 else if (setup_mode == SETUP_MODE_ENGINES)
8148 setup_info = setup_info_engines;
8149 title_string = STR_SETUP_ENGINES;
8151 else if (setup_mode == SETUP_MODE_EDITOR)
8153 setup_info = setup_info_editor;
8154 title_string = STR_SETUP_EDITOR;
8156 else if (setup_mode == SETUP_MODE_GRAPHICS)
8158 setup_info = setup_info_graphics;
8159 title_string = STR_SETUP_GRAPHICS;
8161 else if (setup_mode == SETUP_MODE_SOUND)
8163 setup_info = setup_info_sound;
8164 title_string = STR_SETUP_SOUND;
8166 else if (setup_mode == SETUP_MODE_ARTWORK)
8168 setup_info = setup_info_artwork;
8169 title_string = STR_SETUP_ARTWORK;
8171 else if (setup_mode == SETUP_MODE_TOUCH)
8173 setup_info = setup_info_touch;
8174 title_string = STR_SETUP_TOUCH;
8176 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8177 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8178 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8179 setup_info = setup_info_touch_wipe_gestures;
8181 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8183 setup_info = setup_info_shortcuts;
8184 title_string = STR_SETUP_SHORTCUTS;
8186 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8188 setup_info = setup_info_shortcuts_1;
8189 title_string = STR_SETUP_SHORTCUTS;
8191 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8193 setup_info = setup_info_shortcuts_2;
8194 title_string = STR_SETUP_SHORTCUTS;
8196 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8198 setup_info = setup_info_shortcuts_3;
8199 title_string = STR_SETUP_SHORTCUTS;
8201 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8203 setup_info = setup_info_shortcuts_4;
8204 title_string = STR_SETUP_SHORTCUTS;
8206 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8208 setup_info = setup_info_shortcuts_5;
8209 title_string = STR_SETUP_SHORTCUTS;
8212 // use modified setup info without setup entries marked as hidden
8213 setup_info = getSetupInfoFinal(setup_info);
8215 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8217 // determine maximal number of setup entries that can be displayed on screen
8219 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8222 // determine maximal number of setup entries available for this setup screen
8224 for (i = 0; setup_info[i].type != 0; i++)
8227 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8229 MapScreenGadgets(max_setup_info);
8232 redraw_mask = fade_mask = REDRAW_ALL;
8234 DrawMaskedBorder(fade_mask);
8239 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8241 menu_info = setup_info;
8243 HandleMenuScreen(mx, my, dx, dy, button,
8244 setup_mode, num_setup_info, max_setup_info);
8247 static void DrawSetupScreen_Input(void)
8251 FadeOut(REDRAW_FIELD);
8255 setup_info = getSetupInfoFinal(setup_info_input);
8257 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8259 for (i = 0; setup_info[i].type != 0; i++)
8261 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8262 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8263 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8264 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8265 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8266 initCursor(i, IMG_MENU_BUTTON);
8268 DrawCursorAndText_Setup(i, -1, FALSE);
8271 // create gadgets for setup input menu screen
8272 FreeScreenGadgets();
8273 CreateScreenGadgets();
8275 // map gadgets for setup input menu screen
8276 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8278 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8280 FadeIn(REDRAW_FIELD);
8283 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8285 if (device_name == NULL)
8288 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8291 if (strlen(device_name) > 1)
8293 char c1 = device_name[strlen(device_name) - 1];
8294 char c2 = device_name[strlen(device_name) - 2];
8296 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8297 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8300 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8301 strlen(device_name));
8304 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8307 static struct SetupKeyboardInfo custom_key;
8314 { &custom_key.left, "Axis/Pad Left" },
8315 { &custom_key.right, "Axis/Pad Right" },
8316 { &custom_key.up, "Axis/Pad Up" },
8317 { &custom_key.down, "Axis/Pad Down" },
8318 { &custom_key.snap, "Button 1/A/X" },
8319 { &custom_key.drop, "Button 2/B/Y" }
8321 static char *joystick_name[MAX_PLAYERS] =
8328 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8329 int font_nr_info = FONT_MENU_1;
8330 int font_nr_name = FONT_VALUE_OLD;
8331 int font_nr_on = FONT_VALUE_1;
8332 int font_nr_off = FONT_VALUE_OLD;
8335 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8337 font_nr_info = FONT_MENU_2;
8338 font_nr_on = FONT_VALUE_NARROW;
8339 font_nr_off = FONT_VALUE_OLD_NARROW;
8342 custom_key = setup.input[player_nr].key;
8344 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8345 FONT_INPUT_1_ACTIVE);
8347 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8349 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8350 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8352 if (setup.input[player_nr].use_joystick)
8354 char *device_name = setup.input[player_nr].joy.device_name;
8355 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8356 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8357 char *text = joystick_name[joystick_nr];
8358 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8360 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8361 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8365 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8366 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8369 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8370 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8374 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8375 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8376 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8377 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8379 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8380 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8381 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8382 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8383 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8384 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8386 for (i = 0; i < 6; i++)
8388 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8390 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8392 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8393 (setup.input[player_nr].use_joystick ?
8395 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8399 static int input_player_nr = 0;
8401 static void HandleSetupScreen_Input_Player(int step, int direction)
8403 int old_player_nr = input_player_nr;
8406 new_player_nr = old_player_nr + step * direction;
8407 if (new_player_nr < 0)
8409 if (new_player_nr > MAX_PLAYERS - 1)
8410 new_player_nr = MAX_PLAYERS - 1;
8412 if (new_player_nr != old_player_nr)
8414 input_player_nr = new_player_nr;
8416 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8420 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8422 static int choice = 0;
8425 int pos_start = SETUPINPUT_SCREEN_POS_START;
8426 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8427 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8428 int pos_end = SETUPINPUT_SCREEN_POS_END;
8430 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8434 for (i = 0; setup_info_input[i].type != 0; i++)
8436 // adjust menu structure according to skipped setup entries
8437 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8445 if (button == MB_MENU_INITIALIZE)
8447 // input setup menu may have changed size due to graphics configuration
8448 if (choice >= pos_empty1)
8451 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8453 DrawCursorAndText_Setup(choice, -1, TRUE);
8457 else if (button == MB_MENU_LEAVE)
8459 setup_mode = SETUP_MODE_MAIN;
8466 if (mx || my) // mouse input
8468 x = (mx - mSX) / 32;
8469 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8471 else if (dx || dy) // keyboard input
8473 if (dx && choice == 0)
8474 x = (dx < 0 ? 10 : 12);
8475 else if ((dx && choice == 1) ||
8476 (dx == -1 && choice == pos_end))
8477 button = MB_MENU_CHOICE;
8481 if (y >= pos_empty1 && y <= pos_empty2)
8482 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8485 if (y == 0 && dx != 0 && button)
8487 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8489 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8490 y >= pos_start && y <= pos_end &&
8491 !(y >= pos_empty1 && y <= pos_empty2))
8497 DrawCursorAndText_Setup(choice, -1, FALSE);
8498 DrawCursorAndText_Setup(y, -1, TRUE);
8500 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8509 char *device_name = setup.input[input_player_nr].joy.device_name;
8511 if (!setup.input[input_player_nr].use_joystick)
8513 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8515 setJoystickDeviceToNr(device_name, new_device_nr);
8516 setup.input[input_player_nr].use_joystick = TRUE;
8520 int device_nr = getJoystickNrFromDeviceName(device_name);
8521 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8523 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8524 setup.input[input_player_nr].use_joystick = FALSE;
8526 setJoystickDeviceToNr(device_name, new_device_nr);
8529 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8533 if (setup.input[input_player_nr].use_joystick)
8534 ConfigureJoystick(input_player_nr);
8536 CustomizeKeyboard(input_player_nr);
8538 else if (y == pos_end)
8544 setup_mode = SETUP_MODE_MAIN;
8551 static boolean CustomizeKeyboardMain(int player_nr)
8555 boolean finished = FALSE;
8556 static struct SetupKeyboardInfo custom_key;
8561 } customize_step[] =
8563 { &custom_key.left, "Move Left" },
8564 { &custom_key.right, "Move Right" },
8565 { &custom_key.up, "Move Up" },
8566 { &custom_key.down, "Move Down" },
8567 { &custom_key.snap, "Snap Field" },
8568 { &custom_key.drop, "Drop Element" }
8570 int font_nr_old = FONT_VALUE_OLD;
8571 int font_nr_new = FONT_VALUE_1;
8572 boolean success = FALSE;
8574 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8576 font_nr_old = FONT_VALUE_OLD_NARROW;
8577 font_nr_new = FONT_VALUE_NARROW;
8580 // read existing key bindings from player setup
8581 custom_key = setup.input[player_nr].key;
8584 FadeOut(REDRAW_FIELD);
8588 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8591 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8592 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8593 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8594 "Key:", FONT_INPUT_1_ACTIVE);
8595 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8596 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8598 FadeIn(REDRAW_FIELD);
8604 if (NextValidEvent(&event))
8608 case EVENT_KEYPRESS:
8610 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8612 // press 'Escape' to abort and keep the old key bindings
8613 if (key == KSYM_Escape)
8615 FadeSkipNextFadeIn();
8622 // press 'Enter' to keep the existing key binding
8623 if (key == KSYM_Return)
8624 key = *customize_step[step_nr].key;
8626 // check if key already used
8627 for (i = 0; i < step_nr; i++)
8628 if (*customize_step[i].key == key)
8633 // got new key binding
8634 *customize_step[step_nr].key = key;
8635 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8637 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8638 getKeyNameFromKey(key), font_nr_new);
8641 // un-highlight last query
8642 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8643 customize_step[step_nr - 1].text, FONT_MENU_1);
8644 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8645 "Key:", FONT_MENU_1);
8647 // all keys configured
8656 // query next key binding
8657 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8658 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8659 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8660 "Key:", FONT_INPUT_1_ACTIVE);
8661 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8662 getKeyNameFromKey(*customize_step[step_nr].key),
8667 case EVENT_KEYRELEASE:
8668 key_joystick_mapping = 0;
8672 HandleOtherEvents(&event);
8680 // write new key bindings back to player setup, if successfully finished
8682 setup.input[player_nr].key = custom_key;
8687 void CustomizeKeyboard(int player_nr)
8689 boolean success = CustomizeKeyboardMain(player_nr);
8693 int font_nr = FONT_TITLE_1;
8694 int font_height = getFontHeight(font_nr);
8695 int ypos1 = SYSIZE / 2 - font_height * 2;
8696 int ypos2 = SYSIZE / 2 - font_height * 1;
8697 unsigned int wait_frame_delay = 0;
8698 unsigned int wait_frame_delay_value = 2000;
8700 ResetDelayCounter(&wait_frame_delay);
8704 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8705 DrawTextSCentered(ypos2, font_nr, "configured!");
8707 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8713 DrawSetupScreen_Input();
8716 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8718 #define MARKER_BUTTON 1
8719 #define MARKER_AXIS_X 2
8720 #define MARKER_AXIS_Y 3
8722 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8724 static boolean bitmaps_initialized = FALSE;
8725 boolean screen_initialized = FALSE;
8726 static Bitmap *controller, *button, *axis_x, *axis_y;
8728 boolean success = TRUE;
8729 boolean done = FALSE, next = FALSE;
8731 int alpha = 200, alpha_step = -1;
8732 int alpha_ticks = 0;
8733 char mapping[4096], temp[256];
8734 int font_name = MENU_SETUP_FONT_TITLE;
8735 int font_info = MENU_SETUP_FONT_TEXT;
8736 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8737 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8738 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8739 int ystep_name = getMenuTextStep(spacing_name, font_name);
8740 int ystep_line = getMenuTextStep(spacing_line, font_info);
8741 int ystep_para = getMenuTextStep(spacing_para, font_info);
8749 int axis, button, hat, hat_value;
8752 *step, *prev_step, steps[] =
8754 { 356, 155, MARKER_BUTTON, "a", },
8755 { 396, 122, MARKER_BUTTON, "b", },
8756 { 320, 125, MARKER_BUTTON, "x", },
8757 { 358, 95, MARKER_BUTTON, "y", },
8758 { 162, 125, MARKER_BUTTON, "back", },
8759 { 216, 125, MARKER_BUTTON, "guide", },
8760 { 271, 125, MARKER_BUTTON, "start", },
8761 { 110, 200, MARKER_BUTTON, "dpleft", },
8762 { 146, 228, MARKER_BUTTON, "dpdown", },
8763 { 178, 200, MARKER_BUTTON, "dpright", },
8764 { 146, 172, MARKER_BUTTON, "dpup", },
8765 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8766 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8767 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8768 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8769 { 73, 141, MARKER_BUTTON, "leftstick", },
8770 { 282, 210, MARKER_BUTTON, "rightstick", },
8771 { 73, 141, MARKER_AXIS_X, "leftx", },
8772 { 73, 141, MARKER_AXIS_Y, "lefty", },
8773 { 282, 210, MARKER_AXIS_X, "rightx", },
8774 { 282, 210, MARKER_AXIS_Y, "righty", },
8777 unsigned int event_frame_delay = 0;
8778 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8780 ResetDelayCounter(&event_frame_delay);
8782 if (!bitmaps_initialized)
8784 controller = LoadCustomImage("joystick/controller.png");
8785 button = LoadCustomImage("joystick/button.png");
8786 axis_x = LoadCustomImage("joystick/axis_x.png");
8787 axis_y = LoadCustomImage("joystick/axis_y.png");
8789 bitmaps_initialized = TRUE;
8792 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8795 // print info about the joystick we are watching
8796 Debug("joystick", "watching joystick %d: (%s)",
8797 SDL_JoystickInstanceID(joystick), name);
8798 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8799 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8800 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8803 // initialize mapping with GUID and name
8804 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8806 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8807 temp, name, SDL_GetPlatform());
8809 // loop through all steps (buttons and axes), getting joystick events
8810 for (i = 0; i < SDL_arraysize(steps) && !done;)
8812 Bitmap *marker = button; // initialize with reliable default value
8815 strcpy(step->mapping, mapping);
8819 step->hat_value = -1;
8821 marker = (step->marker == MARKER_BUTTON ? button :
8822 step->marker == MARKER_AXIS_X ? axis_x :
8823 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8827 while (!done && !next)
8829 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8830 alpha_ticks = SDL_GetTicks();
8837 else if (alpha < 128)
8843 int controller_x = SX + (SXSIZE - controller->width) / 2;
8844 int controller_y = SY + ystep_line;
8846 int marker_x = controller_x + step->x;
8847 int marker_y = controller_y + step->y;
8849 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8850 int ystart2 = ystart1 + ystep_name + ystep_line;
8854 DrawTextSCentered(ystart1, font_name, name);
8856 DrawTextSCentered(ystart2, font_info,
8857 "Press buttons and move axes on");
8858 ystart2 += ystep_line;
8859 DrawTextSCentered(ystart2, font_info,
8860 "your controller when indicated.");
8861 ystart2 += ystep_line;
8862 DrawTextSCentered(ystart2, font_info,
8863 "(Your controller may look different.)");
8864 ystart2 += ystep_para;
8866 #if defined(PLATFORM_ANDROID)
8867 DrawTextSCentered(ystart2, font_info,
8868 "To correct a mistake,");
8869 ystart2 += ystep_line;
8870 DrawTextSCentered(ystart2, font_info,
8871 "press the 'back' button.");
8872 ystart2 += ystep_line;
8873 DrawTextSCentered(ystart2, font_info,
8874 "To skip a button or axis,");
8875 ystart2 += ystep_line;
8876 DrawTextSCentered(ystart2, font_info,
8877 "press the 'menu' button.");
8879 DrawTextSCentered(ystart2, font_info,
8880 "To correct a mistake,");
8881 ystart2 += ystep_line;
8882 DrawTextSCentered(ystart2, font_info,
8883 "press the 'backspace' key.");
8884 ystart2 += ystep_line;
8885 DrawTextSCentered(ystart2, font_info,
8886 "To skip a button or axis,");
8887 ystart2 += ystep_line;
8888 DrawTextSCentered(ystart2, font_info,
8889 "press the 'return' key.");
8890 ystart2 += ystep_line;
8891 DrawTextSCentered(ystart2, font_info,
8892 "To exit, press the 'escape' key.");
8895 BlitBitmapMasked(controller, drawto, 0, 0,
8896 controller->width, controller->height,
8897 controller_x, controller_y);
8899 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8900 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8902 BlitBitmapMasked(marker, drawto, 0, 0,
8903 marker->width, marker->height,
8904 marker_x, marker_y);
8906 if (!screen_initialized)
8907 FadeIn(REDRAW_FIELD);
8911 screen_initialized = TRUE;
8913 while (NextValidEvent(&event))
8917 case SDL_JOYAXISMOTION:
8918 if (event.jaxis.value > 20000 ||
8919 event.jaxis.value < -20000)
8921 for (j = 0; j < i; j++)
8922 if (steps[j].axis == event.jaxis.axis)
8927 if (step->marker != MARKER_AXIS_X &&
8928 step->marker != MARKER_AXIS_Y)
8931 step->axis = event.jaxis.axis;
8932 strcat(mapping, step->field);
8933 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8934 strcat(mapping, temp);
8942 case SDL_JOYHATMOTION:
8943 // ignore centering; we're probably just coming back
8944 // to the center from the previous item we set
8945 if (event.jhat.value == SDL_HAT_CENTERED)
8948 for (j = 0; j < i; j++)
8949 if (steps[j].hat == event.jhat.hat &&
8950 steps[j].hat_value == event.jhat.value)
8955 step->hat = event.jhat.hat;
8956 step->hat_value = event.jhat.value;
8957 strcat(mapping, step->field);
8958 snprintf(temp, sizeof(temp), ":h%u.%u,",
8959 event.jhat.hat, event.jhat.value );
8960 strcat(mapping, temp);
8967 case SDL_JOYBALLMOTION:
8970 case SDL_JOYBUTTONUP:
8971 for (j = 0; j < i; j++)
8972 if (steps[j].button == event.jbutton.button)
8977 step->button = event.jbutton.button;
8978 strcat(mapping, step->field);
8979 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8980 strcat(mapping, temp);
8987 case SDL_FINGERDOWN:
8988 case SDL_MOUSEBUTTONDOWN:
8996 if (event.key.keysym.sym == KSYM_BackSpace ||
8997 event.key.keysym.sym == KSYM_Back)
9009 prev_step = &steps[i - 1];
9010 strcpy(mapping, prev_step->mapping);
9017 if (event.key.keysym.sym == KSYM_space ||
9018 event.key.keysym.sym == KSYM_Return ||
9019 event.key.keysym.sym == KSYM_Menu)
9028 if (event.key.keysym.sym == KSYM_Escape)
9038 program.exit_function(0);
9045 // do not handle events for longer than standard frame delay period
9046 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9055 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9058 // activate mapping for this game
9059 SDL_GameControllerAddMapping(mapping);
9061 // save mapping to personal mappings
9062 SaveSetup_AddGameControllerMapping(mapping);
9065 // wait until the last pending event was removed from event queue
9066 while (NextValidEvent(&event));
9071 static int ConfigureJoystickMain(int player_nr)
9073 char *device_name = setup.input[player_nr].joy.device_name;
9074 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9075 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9076 int success = FALSE;
9079 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9080 return JOYSTICK_NOT_AVAILABLE;
9082 if (!joystick_active || !setup.input[player_nr].use_joystick)
9083 return JOYSTICK_NOT_AVAILABLE;
9086 FadeOut(REDRAW_FIELD);
9088 // close all joystick devices (potentially opened as game controllers)
9089 for (i = 0; i < SDL_NumJoysticks(); i++)
9090 SDLCloseJoystick(i);
9092 // open joystick device as plain joystick to configure as game controller
9093 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9095 // as the joystick was successfully opened before, this should not happen
9096 if (joystick == NULL)
9099 // create new game controller mapping (buttons and axes) for joystick device
9100 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9102 // close joystick (and maybe re-open as configured game controller later)
9103 SDL_JoystickClose(joystick);
9105 // re-open all joystick devices (potentially as game controllers)
9106 for (i = 0; i < SDL_NumJoysticks(); i++)
9109 // clear all joystick input actions for all joystick devices
9110 SDLClearJoystickState();
9112 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9115 void ConfigureJoystick(int player_nr)
9117 boolean state = ConfigureJoystickMain(player_nr);
9119 if (state != JOYSTICK_NOT_CONFIGURED)
9121 boolean success = (state == JOYSTICK_CONFIGURED);
9122 char message1[MAX_OUTPUT_LINESIZE + 1];
9123 char *message2 = (success ? "configured!" : "not available!");
9124 char *device_name = setup.input[player_nr].joy.device_name;
9125 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9126 int font_nr = FONT_TITLE_1;
9127 int font_height = getFontHeight(font_nr);
9128 int ypos1 = SYSIZE / 2 - font_height * 2;
9129 int ypos2 = SYSIZE / 2 - font_height * 1;
9130 unsigned int wait_frame_delay = 0;
9131 unsigned int wait_frame_delay_value = 2000;
9133 ResetDelayCounter(&wait_frame_delay);
9137 sprintf(message1, "Joystick %d", nr);
9139 DrawTextSCentered(ypos1, font_nr, message1);
9140 DrawTextSCentered(ypos2, font_nr, message2);
9142 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9148 DrawSetupScreen_Input();
9151 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9153 if (y < video.screen_height / 3)
9155 // remap touch gadgets to access upper part of the screen
9156 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9157 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9159 else if (y > 2 * video.screen_height / 3)
9161 // remap touch gadgets to access lower part of the screen
9162 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9163 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9167 static boolean ConfigureVirtualButtonsMain(void)
9169 static char *customize_step_text[] =
9178 char grid_button[] =
9180 CHAR_GRID_BUTTON_LEFT,
9181 CHAR_GRID_BUTTON_RIGHT,
9182 CHAR_GRID_BUTTON_UP,
9183 CHAR_GRID_BUTTON_DOWN,
9184 CHAR_GRID_BUTTON_SNAP,
9185 CHAR_GRID_BUTTON_DROP
9194 int font_nr = FONT_INPUT_1_ACTIVE;
9195 int font_height = getFontHeight(font_nr);
9196 int ypos1 = SYSIZE / 2 - font_height * 2;
9197 int ypos2 = SYSIZE / 2 - font_height * 1;
9198 boolean success = FALSE;
9199 boolean finished = FALSE;
9201 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9202 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9203 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9204 boolean set_grid_button = FALSE;
9205 int nr = GRID_ACTIVE_NR();
9208 for (x = 0; x < MAX_GRID_XSIZE; x++)
9209 for (y = 0; y < MAX_GRID_YSIZE; y++)
9210 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9212 overlay.grid_button_highlight = grid_button[step_nr];
9217 FadeOut(REDRAW_FIELD);
9221 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9222 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9223 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9225 FadeIn(REDRAW_FIELD);
9227 SetOverlayShowGrid(TRUE);
9229 // map gadgets for setup touch buttons menu screen
9230 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9236 while (NextValidEvent(&event))
9238 int action = ACTION_NONE;
9240 // ---------- handle events and set the resulting action ----------
9246 UserEvent *user = (UserEvent *)&event;
9247 int id = user->value1;
9249 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9250 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9251 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9252 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9257 case EVENT_KEYPRESS:
9259 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9261 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9262 key == KSYM_BackSpace ||
9263 key == KSYM_Back ? ACTION_BACK :
9264 key == KSYM_Return ||
9266 key == KSYM_space ? ACTION_NEXT :
9271 case EVENT_KEYRELEASE:
9272 key_joystick_mapping = 0;
9275 case EVENT_BUTTONPRESS:
9276 case EVENT_BUTTONRELEASE:
9278 ButtonEvent *button = (ButtonEvent *)&event;
9280 motion_status = FALSE;
9282 if (button->type == EVENT_BUTTONPRESS)
9283 button_status = button->button;
9285 button_status = MB_RELEASED;
9287 if (HandleGadgets(button->x, button->y, button_status))
9289 // do not handle this button event anymore
9293 button->x += video.screen_xoffset;
9294 button->y += video.screen_yoffset;
9296 x = button->x * overlay.grid_xsize / video.screen_width;
9297 y = button->y * overlay.grid_ysize / video.screen_height;
9299 if (button->type == EVENT_BUTTONPRESS)
9302 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9303 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9305 set_grid_button = TRUE;
9308 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9312 case EVENT_MOTIONNOTIFY:
9314 MotionEvent *motion = (MotionEvent *)&event;
9316 motion_status = TRUE;
9318 if (HandleGadgets(motion->x, motion->y, button_status))
9320 // do not handle this button event anymore
9324 motion->x += video.screen_xoffset;
9325 motion->y += video.screen_yoffset;
9327 x = motion->x * overlay.grid_xsize / video.screen_width;
9328 y = motion->y * overlay.grid_ysize / video.screen_height;
9330 set_grid_button = TRUE;
9332 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9336 case SDL_WINDOWEVENT:
9337 HandleWindowEvent((WindowEvent *) &event);
9339 // check if device has been rotated
9340 if (nr != GRID_ACTIVE_NR())
9342 nr = GRID_ACTIVE_NR();
9344 for (x = 0; x < MAX_GRID_XSIZE; x++)
9345 for (y = 0; y < MAX_GRID_YSIZE; y++)
9346 grid_button_old[x][y] = grid_button_tmp[x][y] =
9347 overlay.grid_button[x][y];
9352 case SDL_APP_WILLENTERBACKGROUND:
9353 case SDL_APP_DIDENTERBACKGROUND:
9354 case SDL_APP_WILLENTERFOREGROUND:
9355 case SDL_APP_DIDENTERFOREGROUND:
9356 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9360 HandleOtherEvents(&event);
9364 // ---------- perform action set by handling events ----------
9366 if (action == ACTION_ESCAPE)
9368 // abort and restore the old key bindings
9370 for (x = 0; x < MAX_GRID_XSIZE; x++)
9371 for (y = 0; y < MAX_GRID_YSIZE; y++)
9372 overlay.grid_button[x][y] = grid_button_old[x][y];
9374 FadeSkipNextFadeIn();
9378 else if (action == ACTION_BACK)
9380 // keep the configured key bindings and go to previous page
9386 FadeSkipNextFadeIn();
9391 else if (action == ACTION_NEXT)
9393 // keep the configured key bindings and go to next page
9397 // all virtual buttons configured
9405 if (action != ACTION_NONE && !finished)
9407 for (x = 0; x < MAX_GRID_XSIZE; x++)
9408 for (y = 0; y < MAX_GRID_YSIZE; y++)
9409 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9411 overlay.grid_button_highlight = grid_button[step_nr];
9413 // configure next virtual button
9417 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9418 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9419 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9422 if (set_grid_button)
9424 overlay.grid_button[x][y] =
9425 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9426 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9427 grid_button_tmp[x][y]);
9429 set_grid_button = FALSE;
9436 for (x = 0; x < MAX_GRID_XSIZE; x++)
9437 for (y = 0; y < MAX_GRID_YSIZE; y++)
9438 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9440 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9442 SetOverlayShowGrid(FALSE);
9447 void ConfigureVirtualButtons(void)
9449 boolean success = ConfigureVirtualButtonsMain();
9451 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9452 SCREEN_MASK_TOUCH2);
9456 int font_nr = FONT_TITLE_1;
9457 int font_height = getFontHeight(font_nr);
9458 int ypos1 = SYSIZE / 2 - font_height * 2;
9459 int ypos2 = SYSIZE / 2 - font_height * 1;
9460 unsigned int wait_frame_delay = 0;
9461 unsigned int wait_frame_delay_value = 2000;
9463 ResetDelayCounter(&wait_frame_delay);
9467 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9468 DrawTextSCentered(ypos2, font_nr, "configured!");
9470 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9477 void DrawSetupScreen(void)
9482 if (setup_mode == SETUP_MODE_INPUT)
9483 DrawSetupScreen_Input();
9484 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9485 DrawChooseTree(&scores_type_current);
9486 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9487 DrawChooseTree(&game_speed_current);
9488 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9489 DrawChooseTree(&scroll_delay_current);
9490 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9491 DrawChooseTree(&snapshot_mode_current);
9492 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9493 DrawChooseTree(&window_size_current);
9494 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9495 DrawChooseTree(&scaling_type_current);
9496 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9497 DrawChooseTree(&rendering_mode_current);
9498 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9499 DrawChooseTree(&vsync_mode_current);
9500 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9501 DrawChooseTree(&artwork.gfx_current);
9502 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9503 DrawChooseTree(&artwork.snd_current);
9504 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9505 DrawChooseTree(&artwork.mus_current);
9506 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9507 DrawChooseTree(&volume_simple_current);
9508 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9509 DrawChooseTree(&volume_loops_current);
9510 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9511 DrawChooseTree(&volume_music_current);
9512 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9513 DrawChooseTree(&touch_control_current);
9514 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9515 DrawChooseTree(&move_distance_current);
9516 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9517 DrawChooseTree(&drop_distance_current);
9518 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9519 DrawChooseTree(&transparency_current);
9520 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9521 DrawChooseTree(&grid_size_current[0][0]);
9522 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9523 DrawChooseTree(&grid_size_current[0][1]);
9524 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9525 DrawChooseTree(&grid_size_current[1][0]);
9526 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9527 DrawChooseTree(&grid_size_current[1][1]);
9529 DrawSetupScreen_Generic();
9531 PlayMenuSoundsAndMusic();
9534 void RedrawSetupScreenAfterFullscreenToggle(void)
9536 if (setup_mode == SETUP_MODE_GRAPHICS ||
9537 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9539 // update list selection from "setup.window_scaling_percent"
9540 execSetupGraphics_setWindowSizes(TRUE);
9546 void RedrawSetupScreenAfterScreenRotation(int nr)
9550 if (setup_mode == SETUP_MODE_TOUCH)
9552 // update virtual button settings (depending on screen orientation)
9555 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9557 // save already configured virtual buttons
9558 for (x = 0; x < MAX_GRID_XSIZE; x++)
9559 for (y = 0; y < MAX_GRID_YSIZE; y++)
9560 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9564 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9566 if (setup_mode == SETUP_MODE_INPUT)
9567 HandleSetupScreen_Input(mx, my, dx, dy, button);
9568 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9569 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9570 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9571 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9572 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9573 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9574 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9575 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9576 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9577 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9578 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9579 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9580 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9581 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9582 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9583 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9584 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9585 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9586 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9587 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9588 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9589 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9590 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9591 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9592 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9593 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9594 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9595 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9596 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9597 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9598 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9599 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9600 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9601 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9602 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9603 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9604 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9605 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9606 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9607 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9608 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9609 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9610 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9611 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9613 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9616 void HandleGameActions(void)
9618 if (setup.ask_on_game_over)
9621 if (game.restart_game_message != NULL)
9623 RequestRestartGame(game.restart_game_message);
9628 if (game_status != GAME_MODE_PLAYING)
9631 GameActions(); // main game loop
9633 if (tape.auto_play && !tape.playing)
9634 AutoPlayTapesContinue(); // continue automatically playing next tape
9638 // ---------- new screen button stuff --------------------------------------
9642 int gfx_unpressed, gfx_pressed;
9643 struct MenuPosInfo *pos;
9644 boolean *check_value;
9647 unsigned int event_mask;
9648 boolean is_touch_button;
9650 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9653 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9654 &menu.main.button.prev_level, NULL,
9655 SCREEN_CTRL_ID_PREV_LEVEL,
9657 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9658 FALSE, "previous level"
9661 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9662 &menu.main.button.next_level, NULL,
9663 SCREEN_CTRL_ID_NEXT_LEVEL,
9665 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9669 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9670 &menu.scores.button.prev_level, NULL,
9671 SCREEN_CTRL_ID_PREV_LEVEL2,
9673 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9674 FALSE, "previous level"
9677 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9678 &menu.scores.button.next_level, NULL,
9679 SCREEN_CTRL_ID_NEXT_LEVEL2,
9681 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9685 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9686 &menu.main.button.first_level, NULL,
9687 SCREEN_CTRL_ID_FIRST_LEVEL,
9690 FALSE, "first level"
9693 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9694 &menu.main.button.last_level, NULL,
9695 SCREEN_CTRL_ID_LAST_LEVEL,
9701 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9702 &menu.main.button.level_number, NULL,
9703 SCREEN_CTRL_ID_LEVEL_NUMBER,
9706 FALSE, "level number"
9709 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9710 &menu.setup.button.prev_player, NULL,
9711 SCREEN_CTRL_ID_PREV_PLAYER,
9713 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9714 FALSE, "previous player"
9717 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9718 &menu.setup.button.next_player, NULL,
9719 SCREEN_CTRL_ID_NEXT_PLAYER,
9721 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9722 FALSE, "next player"
9725 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9726 &menu.main.button.insert_solution, NULL,
9727 SCREEN_CTRL_ID_INSERT_SOLUTION,
9728 SCREEN_MASK_MAIN_HAS_SOLUTION,
9730 FALSE, "insert solution tape"
9733 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9734 &menu.main.button.play_solution, NULL,
9735 SCREEN_CTRL_ID_PLAY_SOLUTION,
9736 SCREEN_MASK_MAIN_HAS_SOLUTION,
9738 FALSE, "play solution tape"
9741 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9742 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9743 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9745 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9746 FALSE, "switch ECS/AGA chipset"
9749 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9750 &menu.setup.button.touch_back, NULL,
9751 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9754 TRUE, "previous page"
9757 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9758 &menu.setup.button.touch_next, NULL,
9759 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9765 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9766 &menu.setup.button.touch_back2, NULL,
9767 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9770 TRUE, "previous page"
9773 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9774 &menu.setup.button.touch_next2, NULL,
9775 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9784 int gfx_unpressed, gfx_pressed;
9788 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9791 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9792 -1, -1, // these values are not constant, but can change at runtime
9793 SCREEN_CTRL_ID_SCROLL_UP,
9797 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9798 -1, -1, // these values are not constant, but can change at runtime
9799 SCREEN_CTRL_ID_SCROLL_DOWN,
9806 int gfx_unpressed, gfx_pressed;
9812 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9815 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9816 -1, -1, // these values are not constant, but can change at runtime
9817 -1, -1, // these values are not constant, but can change at runtime
9818 GD_TYPE_SCROLLBAR_VERTICAL,
9819 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9820 "scroll level series vertically"
9832 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9835 IMG_SETUP_INPUT_TEXT,
9836 SCREEN_CTRL_ID_NETWORK_SERVER,
9837 -1, -1, // these values are not constant, but can change at runtime
9838 MAX_SETUP_TEXT_INPUT_LEN,
9839 network_server_hostname,
9840 "Network Server Hostname / IP"
9844 static void CreateScreenMenubuttons(void)
9846 struct GadgetInfo *gi;
9847 unsigned int event_mask;
9850 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9852 struct MenuPosInfo *pos = menubutton_info[i].pos;
9853 int screen_mask = menubutton_info[i].screen_mask;
9854 boolean is_touch_button = menubutton_info[i].is_touch_button;
9855 boolean is_check_button = menubutton_info[i].check_value != NULL;
9856 boolean is_score_button = (screen_mask == SCREEN_MASK_SCORES);
9857 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9858 int gfx_unpressed, gfx_pressed;
9859 int x, y, width, height;
9860 int gd_x1, gd_x2, gd_y1, gd_y2;
9861 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9862 int id = menubutton_info[i].gadget_id;
9863 int type = GD_TYPE_NORMAL_BUTTON;
9864 boolean checked = FALSE;
9866 event_mask = menubutton_info[i].event_mask;
9868 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9869 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9871 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9872 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9874 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9875 gfx_pressed = menubutton_info[i].gfx_pressed;
9876 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9877 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9878 gd_x1 = graphic_info[gfx_unpressed].src_x;
9879 gd_y1 = graphic_info[gfx_unpressed].src_y;
9880 gd_x2 = graphic_info[gfx_pressed].src_x;
9881 gd_y2 = graphic_info[gfx_pressed].src_y;
9887 if (is_touch_button)
9889 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9890 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9893 if (is_check_button)
9895 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9896 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9897 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9898 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9900 type = GD_TYPE_CHECK_BUTTON;
9901 checked = *menubutton_info[i].check_value;
9904 if (is_score_button)
9906 // if x/y set to -1, dynamically place buttons next to title text
9907 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9910 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9911 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9912 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9913 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9916 y = mSY + MENU_TITLE1_YPOS;
9919 gi = CreateGadget(GDI_CUSTOM_ID, id,
9920 GDI_CUSTOM_TYPE_ID, i,
9921 GDI_IMAGE_ID, gfx_unpressed,
9922 GDI_INFO_TEXT, menubutton_info[i].infotext,
9928 GDI_STATE, GD_BUTTON_UNPRESSED,
9929 GDI_CHECKED, checked,
9930 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9931 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9932 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9933 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9934 GDI_DIRECT_DRAW, FALSE,
9935 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9936 GDI_EVENT_MASK, event_mask,
9937 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9941 Fail("cannot create gadget");
9943 screen_gadget[id] = gi;
9947 static void CreateScreenScrollbuttons(void)
9949 struct GadgetInfo *gi;
9950 unsigned int event_mask;
9953 // these values are not constant, but can change at runtime
9954 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9955 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9956 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9957 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9959 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9961 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9962 int gfx_unpressed, gfx_pressed;
9963 int x, y, width, height;
9964 int gd_x1, gd_x2, gd_y1, gd_y2;
9965 int id = scrollbutton_info[i].gadget_id;
9967 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9969 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9970 y = mSY + scrollbutton_info[i].y;
9971 width = SC_SCROLLBUTTON_XSIZE;
9972 height = SC_SCROLLBUTTON_YSIZE;
9974 // correct scrollbar position if placed outside menu (playfield) area
9975 if (x > SX + SC_SCROLL_UP_XPOS)
9976 x = SX + SC_SCROLL_UP_XPOS;
9978 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9979 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9980 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9982 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9983 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9984 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9985 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9986 gd_x1 = graphic_info[gfx_unpressed].src_x;
9987 gd_y1 = graphic_info[gfx_unpressed].src_y;
9988 gd_x2 = graphic_info[gfx_pressed].src_x;
9989 gd_y2 = graphic_info[gfx_pressed].src_y;
9991 gi = CreateGadget(GDI_CUSTOM_ID, id,
9992 GDI_CUSTOM_TYPE_ID, i,
9993 GDI_IMAGE_ID, gfx_unpressed,
9994 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9999 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10000 GDI_STATE, GD_BUTTON_UNPRESSED,
10001 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10002 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10003 GDI_DIRECT_DRAW, FALSE,
10004 GDI_EVENT_MASK, event_mask,
10005 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10009 Fail("cannot create gadget");
10011 screen_gadget[id] = gi;
10015 static void CreateScreenScrollbars(void)
10019 // these values are not constant, but can change at runtime
10020 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10021 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10022 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10023 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10025 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10027 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10028 int gfx_unpressed, gfx_pressed;
10029 int x, y, width, height;
10030 int gd_x1, gd_x2, gd_y1, gd_y2;
10031 struct GadgetInfo *gi;
10032 int items_max, items_visible, item_position;
10033 unsigned int event_mask;
10034 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10035 int id = scrollbar_info[i].gadget_id;
10037 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10039 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10040 y = mSY + scrollbar_info[i].y;
10041 width = scrollbar_info[i].width;
10042 height = scrollbar_info[i].height;
10044 // correct scrollbar position if placed outside menu (playfield) area
10045 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10046 x = SX + SC_SCROLL_VERTICAL_XPOS;
10048 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10049 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10051 items_max = num_page_entries;
10052 items_visible = num_page_entries;
10055 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10056 gfx_pressed = scrollbar_info[i].gfx_pressed;
10057 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10058 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10059 gd_x1 = graphic_info[gfx_unpressed].src_x;
10060 gd_y1 = graphic_info[gfx_unpressed].src_y;
10061 gd_x2 = graphic_info[gfx_pressed].src_x;
10062 gd_y2 = graphic_info[gfx_pressed].src_y;
10064 gi = CreateGadget(GDI_CUSTOM_ID, id,
10065 GDI_CUSTOM_TYPE_ID, i,
10066 GDI_IMAGE_ID, gfx_unpressed,
10067 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10071 GDI_HEIGHT, height,
10072 GDI_TYPE, scrollbar_info[i].type,
10073 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10074 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10075 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10076 GDI_WHEEL_AREA_X, SX,
10077 GDI_WHEEL_AREA_Y, SY,
10078 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10079 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10080 GDI_STATE, GD_BUTTON_UNPRESSED,
10081 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10082 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10083 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10084 GDI_DIRECT_DRAW, FALSE,
10085 GDI_EVENT_MASK, event_mask,
10086 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10090 Fail("cannot create gadget");
10092 screen_gadget[id] = gi;
10096 static void CreateScreenTextInputGadgets(void)
10100 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10102 int graphic = textinput_info[i].graphic;
10103 struct GraphicInfo *gd = &graphic_info[graphic];
10104 int gd_x1 = gd->src_x;
10105 int gd_y1 = gd->src_y;
10106 int gd_x2 = gd->src_x + gd->active_xoffset;
10107 int gd_y2 = gd->src_y + gd->active_yoffset;
10108 struct GadgetInfo *gi;
10109 unsigned int event_mask;
10110 int id = textinput_info[i].gadget_id;
10111 int x = textinput_info[i].x;
10112 int y = textinput_info[i].y;
10114 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10116 gi = CreateGadget(GDI_CUSTOM_ID, id,
10117 GDI_CUSTOM_TYPE_ID, i,
10118 GDI_INFO_TEXT, textinput_info[i].infotext,
10121 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10122 GDI_TEXT_VALUE, textinput_info[i].value,
10123 GDI_TEXT_SIZE, textinput_info[i].size,
10124 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10125 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10126 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10127 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10128 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10129 GDI_DESIGN_WIDTH, gd->width,
10130 GDI_EVENT_MASK, event_mask,
10131 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10132 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10136 Fail("cannot create gadget");
10138 screen_gadget[id] = gi;
10142 void CreateScreenGadgets(void)
10144 CreateScreenMenubuttons();
10146 CreateScreenScrollbuttons();
10147 CreateScreenScrollbars();
10149 CreateScreenTextInputGadgets();
10152 void FreeScreenGadgets(void)
10156 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10157 FreeGadget(screen_gadget[i]);
10160 static void RedrawScreenMenuGadgets(int screen_mask)
10164 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10165 if (screen_mask & menubutton_info[i].screen_mask)
10166 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10169 static void MapScreenMenuGadgets(int screen_mask)
10173 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10174 if (screen_mask & menubutton_info[i].screen_mask)
10175 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10178 static void UnmapScreenMenuGadgets(int screen_mask)
10182 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10184 if (screen_mask & menubutton_info[i].screen_mask)
10186 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10188 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10189 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10190 screen_gadget[menubutton_info[i].gadget_id]->y,
10191 screen_gadget[menubutton_info[i].gadget_id]->width,
10192 screen_gadget[menubutton_info[i].gadget_id]->height);
10197 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10200 MapScreenMenuGadgets(screen_mask);
10202 UnmapScreenMenuGadgets(screen_mask);
10205 static void MapScreenGadgets(int num_entries)
10209 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10212 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10213 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10215 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10216 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10219 static void UnmapScreenGadgets()
10223 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10224 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10226 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10227 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10230 static void MapScreenTreeGadgets(TreeInfo *ti)
10232 MapScreenGadgets(numTreeInfoInGroup(ti));
10235 static void UnmapScreenTreeGadgets(void)
10237 UnmapScreenGadgets();
10240 static void HandleScreenGadgets(struct GadgetInfo *gi)
10242 int id = gi->custom_id;
10243 int button = gi->event.button;
10244 int step = (button == MB_LEFTBUTTON ? 1 :
10245 button == MB_MIDDLEBUTTON ? 5 :
10246 button == MB_RIGHTBUTTON ? 10 : 1);
10250 case SCREEN_CTRL_ID_PREV_LEVEL:
10251 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10254 case SCREEN_CTRL_ID_NEXT_LEVEL:
10255 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10258 case SCREEN_CTRL_ID_PREV_LEVEL2:
10259 HandleHallOfFame_SelectLevel(step, -1);
10262 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10263 HandleHallOfFame_SelectLevel(step, +1);
10266 case SCREEN_CTRL_ID_FIRST_LEVEL:
10267 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10270 case SCREEN_CTRL_ID_LAST_LEVEL:
10271 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10274 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10275 CloseDoor(DOOR_CLOSE_2);
10276 SetGameStatus(GAME_MODE_LEVELNR);
10277 DrawChooseLevelNr();
10280 case SCREEN_CTRL_ID_PREV_PLAYER:
10281 HandleSetupScreen_Input_Player(step, -1);
10284 case SCREEN_CTRL_ID_NEXT_PLAYER:
10285 HandleSetupScreen_Input_Player(step, +1);
10288 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10289 InsertSolutionTape();
10292 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10293 PlaySolutionTape();
10296 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10297 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10301 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10302 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10303 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10304 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10305 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10308 case SCREEN_CTRL_ID_SCROLL_UP:
10309 if (game_status == GAME_MODE_NAMES)
10310 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10311 else if (game_status == GAME_MODE_LEVELS)
10312 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10313 else if (game_status == GAME_MODE_LEVELNR)
10314 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10315 else if (game_status == GAME_MODE_SETUP)
10316 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10317 else if (game_status == GAME_MODE_INFO)
10318 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10319 else if (game_status == GAME_MODE_SCORES)
10320 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10323 case SCREEN_CTRL_ID_SCROLL_DOWN:
10324 if (game_status == GAME_MODE_NAMES)
10325 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10326 else if (game_status == GAME_MODE_LEVELS)
10327 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10328 else if (game_status == GAME_MODE_LEVELNR)
10329 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10330 else if (game_status == GAME_MODE_SETUP)
10331 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10332 else if (game_status == GAME_MODE_INFO)
10333 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10334 else if (game_status == GAME_MODE_SCORES)
10335 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10338 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10339 if (game_status == GAME_MODE_NAMES)
10340 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10341 else if (game_status == GAME_MODE_LEVELS)
10342 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10343 else if (game_status == GAME_MODE_LEVELNR)
10344 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10345 else if (game_status == GAME_MODE_SETUP)
10346 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10347 else if (game_status == GAME_MODE_INFO)
10348 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10349 else if (game_status == GAME_MODE_SCORES)
10350 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10353 case SCREEN_CTRL_ID_NETWORK_SERVER:
10355 if (!strEqual(gi->textinput.value, ""))
10357 setString(&setup.network_server_hostname, gi->textinput.value);
10359 network.server_host = setup.network_server_hostname;
10363 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10365 network.server_host = NULL;
10368 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10369 network.server_host = NULL;
10371 execSetupGame_setNetworkServerText();
10383 void DumpScreenIdentifiers(void)
10387 Print("Active screen elements on current screen:\n");
10389 for (i = 0; main_controls[i].nr != -1; i++)
10391 struct MainControlInfo *mci = &main_controls[i];
10393 if (mci->button_graphic != -1)
10395 char *token = getTokenFromImageID(mci->button_graphic);
10397 Print("- '%s'\n", token);
10404 boolean DoScreenAction(int image_id)
10408 if (game_status != GAME_MODE_MAIN)
10411 for (i = 0; main_controls[i].nr != -1; i++)
10413 struct MainControlInfo *mci = &main_controls[i];
10414 struct MenuPosInfo *pos = mci->pos_button;
10416 if (mci->button_graphic == image_id)
10418 int x = mSX + pos->x;
10419 int y = mSY + pos->y;
10421 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10430 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10432 // get tree info node of newly added level or artwork set
10433 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10434 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10436 if (tree_node_new == NULL) // should not happen
10439 // if request dialog is active, do nothing
10440 if (game.request_active)
10443 if (game_status == GAME_MODE_MAIN &&
10444 tree_type == TREE_TYPE_LEVEL_DIR)
10446 // when adding new level set in main menu, select it as current level set
10448 // change current level set to newly added level set from zip file
10449 leveldir_current = tree_node_new;
10451 // change current level number to first level of newly added level set
10452 level_nr = leveldir_current->first_level;
10454 // redraw screen to reflect changed level set
10457 // save this level set and level number as last selected level set
10458 SaveLevelSetup_LastSeries();
10459 SaveLevelSetup_SeriesInfo();
10461 else if (game_status == GAME_MODE_LEVELS &&
10462 tree_type == TREE_TYPE_LEVEL_DIR)
10464 // when adding new level set in level set menu, set cursor and update screen
10466 leveldir_current = tree_node_new;
10468 DrawChooseTree(&leveldir_current);
10470 else if (game_status == GAME_MODE_SETUP)
10472 // when adding new artwork set in setup menu, set cursor and update screen
10474 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10475 tree_type == TREE_TYPE_GRAPHICS_DIR)
10477 artwork.gfx_current = tree_node_new;
10479 DrawChooseTree(&artwork.gfx_current);
10481 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10482 tree_type == TREE_TYPE_SOUNDS_DIR)
10484 artwork.snd_current = tree_node_new;
10486 DrawChooseTree(&artwork.snd_current);
10488 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10489 tree_type == TREE_TYPE_MUSIC_DIR)
10491 artwork.mus_current = tree_node_new;
10493 DrawChooseTree(&artwork.mus_current);
10498 static int UploadTapes(void)
10500 SetGameStatus(GAME_MODE_LOADING);
10502 FadeSetEnterScreen();
10503 FadeOut(REDRAW_ALL);
10505 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10507 FadeIn(REDRAW_ALL);
10509 DrawInitTextHead("Uploading tapes");
10511 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10512 global.autoplay_leveldir = "ALL";
10513 global.autoplay_all = TRUE;
10515 int num_tapes_uploaded = AutoPlayTapes();
10517 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10518 global.autoplay_leveldir = NULL;
10519 global.autoplay_all = FALSE;
10521 SetGameStatus(GAME_MODE_MAIN);
10525 return num_tapes_uploaded;
10528 static boolean OfferUploadTapes(void)
10530 if (!Request(setup.has_remaining_tapes ?
10531 "Upload missing tapes to the high score server now?" :
10532 "Upload all your tapes to the high score server now?", REQ_ASK))
10535 int num_tapes_uploaded = UploadTapes();
10538 if (num_tapes_uploaded < 0)
10540 num_tapes_uploaded = -num_tapes_uploaded - 1;
10542 if (num_tapes_uploaded == 0)
10543 sprintf(message, "Upload failed! No tapes uploaded!");
10544 else if (num_tapes_uploaded == 1)
10545 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10547 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10548 num_tapes_uploaded);
10550 Request(message, REQ_CONFIRM);
10552 // if uploading tapes failed, add tape upload entry to setup menu
10553 setup.provide_uploading_tapes = TRUE;
10554 setup.has_remaining_tapes = TRUE;
10556 SaveSetup_ServerSetup();
10561 if (num_tapes_uploaded == 0)
10562 sprintf(message, "No tapes uploaded!");
10563 else if (num_tapes_uploaded == 1)
10564 sprintf(message, "1 tape uploaded!");
10566 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10568 Request(message, REQ_CONFIRM);
10570 if (num_tapes_uploaded > 0)
10571 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10573 // after all tapes have been uploaded, remove entry from setup menu
10574 setup.provide_uploading_tapes = FALSE;
10575 setup.has_remaining_tapes = FALSE;
10577 SaveSetup_ServerSetup();
10582 static void CheckUploadTapes(void)
10584 if (!setup.ask_for_uploading_tapes)
10587 // after asking for uploading tapes, do not ask again
10588 setup.ask_for_uploading_tapes = FALSE;
10589 setup.ask_for_remaining_tapes = FALSE;
10591 if (directoryExists(getTapeDir(NULL)))
10593 boolean tapes_uploaded = OfferUploadTapes();
10595 if (!tapes_uploaded)
10597 Request(setup.has_remaining_tapes ?
10598 "You can upload missing tapes from the setup menu later!" :
10599 "You can upload your tapes from the setup menu later!",
10605 // if tapes directory does not exist yet, never offer uploading all tapes
10606 setup.provide_uploading_tapes = FALSE;
10609 SaveSetup_ServerSetup();
10612 static void UpgradePlayerUUID(void)
10614 ApiResetUUIDAsThread(getUUID());
10617 static void CheckUpgradePlayerUUID(void)
10619 if (setup.player_version > 1)
10622 UpgradePlayerUUID();
10625 void CheckApiServerTasks(void)
10627 // check if the player's UUID has to be upgraded
10628 CheckUpgradePlayerUUID();
10630 // check if there are any tapes to be uploaded
10631 CheckUploadTapes();