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_FIRST_LEVEL 2
188 #define SCREEN_CTRL_ID_LAST_LEVEL 3
189 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
190 #define SCREEN_CTRL_ID_PREV_PLAYER 5
191 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
192 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
193 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
194 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
195 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
196 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
197 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
198 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
199 #define SCREEN_CTRL_ID_SCROLL_UP 14
200 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
201 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
202 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
204 #define NUM_SCREEN_GADGETS 18
206 #define NUM_SCREEN_MENUBUTTONS 14
207 #define NUM_SCREEN_SCROLLBUTTONS 2
208 #define NUM_SCREEN_SCROLLBARS 1
209 #define NUM_SCREEN_TEXTINPUT 1
211 #define SCREEN_MASK_MAIN (1 << 0)
212 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
213 #define SCREEN_MASK_INPUT (1 << 2)
214 #define SCREEN_MASK_TOUCH (1 << 3)
215 #define SCREEN_MASK_TOUCH2 (1 << 4)
217 // graphic position and size values for buttons and scrollbars
218 #define SC_MENUBUTTON_XSIZE TILEX
219 #define SC_MENUBUTTON_YSIZE TILEY
221 #define SC_SCROLLBUTTON_XSIZE TILEX
222 #define SC_SCROLLBUTTON_YSIZE TILEY
224 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
226 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
227 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
228 SC_SCROLLBUTTON_YSIZE)
230 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
231 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
233 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
234 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
235 SC_SCROLLBUTTON_YSIZE)
237 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
238 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
239 SC_SCROLL_VERTICAL_YSIZE)
241 #define SC_BORDER_SIZE 14
244 // forward declarations of internal functions
245 static void HandleScreenGadgets(struct GadgetInfo *);
246 static void HandleSetupScreen_Generic(int, int, int, int, int);
247 static void HandleSetupScreen_Input(int, int, int, int, int);
248 static void CustomizeKeyboard(int);
249 static void ConfigureJoystick(int);
250 static void ConfigureVirtualButtons(void);
251 static void execSetupGame(void);
252 static void execSetupEngines(void);
253 static void execSetupGraphics(void);
254 static void execSetupSound(void);
255 static void execSetupTouch(void);
256 static void execSetupArtwork(void);
257 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
259 static void DrawChoosePlayerName(void);
260 static void DrawChooseLevelSet(void);
261 static void DrawChooseLevelNr(void);
262 static void DrawInfoScreen(void);
263 static void DrawSetupScreen(void);
264 static void DrawTypeName(void);
266 static void DrawInfoScreen_NotAvailable(char *, char *);
267 static void DrawInfoScreen_HelpAnim(int, int, boolean);
268 static void DrawInfoScreen_HelpText(int, int, int, int);
269 static void HandleInfoScreen_Main(int, int, int, int, int);
270 static void HandleInfoScreen_TitleScreen(int);
271 static void HandleInfoScreen_Elements(int);
272 static void HandleInfoScreen_Music(int);
273 static void HandleInfoScreen_Credits(int);
274 static void HandleInfoScreen_Program(int);
275 static void HandleInfoScreen_Version(int);
277 static void ModifyGameSpeedIfNeeded(void);
278 static void DisableVsyncIfNeeded(void);
280 static void RedrawScreenMenuGadgets(int);
281 static void MapScreenMenuGadgets(int);
282 static void UnmapScreenMenuGadgets(int);
283 static void MapScreenGadgets(int);
284 static void UnmapScreenGadgets(void);
285 static void MapScreenTreeGadgets(TreeInfo *);
286 static void UnmapScreenTreeGadgets(void);
288 static void UpdateScreenMenuGadgets(int, boolean);
290 static boolean OfferUploadTapes(void);
291 static void execOfferUploadTapes(void);
293 static void DrawHallOfFame_setScoreEntries(void);
294 static char *getHallOfFameScoreText(int);
296 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
298 static int info_mode = INFO_MODE_MAIN;
299 static int setup_mode = SETUP_MODE_MAIN;
301 static TreeInfo *window_sizes = NULL;
302 static TreeInfo *window_size_current = NULL;
304 static TreeInfo *scaling_types = NULL;
305 static TreeInfo *scaling_type_current = NULL;
307 static TreeInfo *rendering_modes = NULL;
308 static TreeInfo *rendering_mode_current = NULL;
310 static TreeInfo *vsync_modes = NULL;
311 static TreeInfo *vsync_mode_current = NULL;
313 static TreeInfo *scroll_delays = NULL;
314 static TreeInfo *scroll_delay_current = NULL;
316 static TreeInfo *snapshot_modes = NULL;
317 static TreeInfo *snapshot_mode_current = NULL;
319 static TreeInfo *scores_types = NULL;
320 static TreeInfo *scores_type_current = NULL;
322 static TreeInfo *game_speeds_normal = NULL;
323 static TreeInfo *game_speeds_extended = NULL;
324 static TreeInfo *game_speeds = NULL;
325 static TreeInfo *game_speed_current = NULL;
327 static TreeInfo *volumes_simple = NULL;
328 static TreeInfo *volume_simple_current = NULL;
330 static TreeInfo *volumes_loops = NULL;
331 static TreeInfo *volume_loops_current = NULL;
333 static TreeInfo *volumes_music = NULL;
334 static TreeInfo *volume_music_current = NULL;
336 static TreeInfo *touch_controls = NULL;
337 static TreeInfo *touch_control_current = NULL;
339 static TreeInfo *move_distances = NULL;
340 static TreeInfo *move_distance_current = NULL;
342 static TreeInfo *drop_distances = NULL;
343 static TreeInfo *drop_distance_current = NULL;
345 static TreeInfo *transparencies = NULL;
346 static TreeInfo *transparency_current = NULL;
348 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
349 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
351 static TreeInfo *player_name = NULL;
352 static TreeInfo *player_name_current = NULL;
354 static TreeInfo *level_number = NULL;
355 static TreeInfo *level_number_current = NULL;
357 static TreeInfo *score_entries = NULL;
358 static TreeInfo *score_entry_current = NULL;
360 static struct ValueTextInfo window_sizes_list[] =
365 { 100, "100 % (Default)" },
378 static struct StringValueTextInfo scaling_types_list[] =
380 { SCALING_QUALITY_NEAREST, "Off" },
381 { SCALING_QUALITY_LINEAR, "Linear" },
382 { SCALING_QUALITY_BEST, "Anisotropic" },
387 static struct StringValueTextInfo rendering_modes_list[] =
389 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
390 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
392 // this mode may work under certain conditions, but does not work on Windows
393 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
395 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
400 static struct StringValueTextInfo vsync_modes_list[] =
402 { STR_VSYNC_MODE_OFF, "Off" },
403 { STR_VSYNC_MODE_NORMAL, "Normal" },
404 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
409 static struct StringValueTextInfo scores_types_list[] =
411 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
412 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
413 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
418 static struct ValueTextInfo game_speeds_list_normal[] =
429 static struct ValueTextInfo game_speeds_list_extended[] =
431 { 1000, "1 fps (Extremely Slow)" },
436 { 29, "35 fps (Original Supaplex)" },
438 { 20, "50 fps (=== Normal Speed ===)" },
439 { 16, "60 fps (60 Hz VSync Speed)" },
440 { 14, "70 fps (Maximum Supaplex)" },
444 { 1, "1000 fps (Extremely Fast)" },
449 static struct ValueTextInfo *game_speeds_list;
451 static struct ValueTextInfo scroll_delays_list[] =
453 { 0, "0 Tiles (No Scroll Delay)" },
456 { 3, "3 Tiles (Default)" },
461 { 8, "8 Tiles (Maximum Scroll Delay)"},
466 static struct StringValueTextInfo snapshot_modes_list[] =
468 { STR_SNAPSHOT_MODE_OFF, "Off" },
469 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
470 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
471 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
476 static struct ValueTextInfo volumes_list[] =
496 static struct StringValueTextInfo touch_controls_list[] =
498 { TOUCH_CONTROL_OFF, "Off" },
499 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
500 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
501 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
506 static struct ValueTextInfo distances_list[] =
521 static struct ValueTextInfo transparencies_list[] =
523 { 0, "0 % (Opaque)" },
533 { 100, "100 % (Invisible)" },
538 static struct ValueTextInfo grid_sizes_list[] =
574 static int align_xoffset = 0;
575 static int align_yoffset = 0;
577 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
578 (s) <= GAME_MODE_SETUP ? (s) : \
579 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
581 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
582 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
584 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
585 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
586 (i) <= INFO_MODE_LEVELSET ? (i) : \
589 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
590 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
591 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
592 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
593 SETUP_MODE_CHOOSE_ARTWORK : \
594 SETUP_MODE_CHOOSE_OTHER)
596 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
597 menu.draw_xoffset[GAME_MODE_INFO] : \
598 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
599 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
600 menu.draw_yoffset[GAME_MODE_INFO] : \
601 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
602 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
603 menu.extra_spacing[GAME_MODE_INFO] : \
604 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
606 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
607 menu.draw_xoffset[GAME_MODE_SETUP] : \
608 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
609 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
610 menu.draw_yoffset[GAME_MODE_SETUP] : \
611 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
612 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
613 menu.extra_spacing[GAME_MODE_SETUP] : \
614 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
616 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
618 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
619 DRAW_XOFFSET_INFO(info_mode) : \
620 (s) == GAME_MODE_SETUP ? \
621 DRAW_XOFFSET_SETUP(setup_mode) : \
622 menu.draw_xoffset[DRAW_MODE(s)])
623 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
624 DRAW_YOFFSET_INFO(info_mode) : \
625 (s) == GAME_MODE_SETUP ? \
626 DRAW_YOFFSET_SETUP(setup_mode) : \
627 menu.draw_yoffset[DRAW_MODE(s)])
628 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
629 EXTRA_SPACING_INFO(info_mode) : \
630 (s) == GAME_MODE_SETUP ? \
631 EXTRA_SPACING_SETUP(setup_mode) : \
632 (s) == GAME_MODE_SCORES ? \
633 EXTRA_SPACING_SCORES(info_mode) : \
634 menu.extra_spacing[DRAW_MODE(s)])
636 #define mSX (SX + DRAW_XOFFSET(game_status))
637 #define mSY (SY + DRAW_YOFFSET(game_status))
639 #define amSX (mSX + align_xoffset)
640 #define amSY (mSY + align_yoffset)
642 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
643 menu.list_size[game_status] : \
644 MAX_MENU_ENTRIES_ON_SCREEN)
646 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
647 NUM_MENU_ENTRIES_ON_SCREEN)
650 // title display and control definitions
652 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
653 2 * MAX_NUM_TITLE_MESSAGES)
655 #define NO_DIRECT_LEVEL_SELECT (-1)
658 static int num_title_screens = 0;
660 struct TitleControlInfo
669 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
671 // main menu display and control definitions
673 #define MAIN_CONTROL_NAME 0
674 #define MAIN_CONTROL_LEVELS 1
675 #define MAIN_CONTROL_SCORES 2
676 #define MAIN_CONTROL_EDITOR 3
677 #define MAIN_CONTROL_INFO 4
678 #define MAIN_CONTROL_GAME 5
679 #define MAIN_CONTROL_SETUP 6
680 #define MAIN_CONTROL_QUIT 7
681 #define MAIN_CONTROL_PREV_LEVEL 8
682 #define MAIN_CONTROL_NEXT_LEVEL 9
683 #define MAIN_CONTROL_FIRST_LEVEL 10
684 #define MAIN_CONTROL_LAST_LEVEL 11
685 #define MAIN_CONTROL_LEVEL_NUMBER 12
686 #define MAIN_CONTROL_LEVEL_INFO_1 13
687 #define MAIN_CONTROL_LEVEL_INFO_2 14
688 #define MAIN_CONTROL_LEVEL_NAME 15
689 #define MAIN_CONTROL_LEVEL_AUTHOR 16
690 #define MAIN_CONTROL_LEVEL_YEAR 17
691 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
692 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
693 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
694 #define MAIN_CONTROL_TITLE_1 21
695 #define MAIN_CONTROL_TITLE_2 22
696 #define MAIN_CONTROL_TITLE_3 23
698 static char str_main_text_name[10];
699 static char str_main_text_first_level[10];
700 static char str_main_text_last_level[10];
701 static char str_main_text_level_number[10];
703 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
705 static char *main_text_name = str_main_text_name;
706 static char *main_text_first_level = str_main_text_first_level;
707 static char *main_text_last_level = str_main_text_last_level;
708 static char *main_text_level_number = str_main_text_level_number;
709 static char *main_text_levels = "Levelset";
710 static char *main_text_scores = "Hall Of Fame";
711 static char *main_text_editor = "Level Creator";
712 static char *main_text_info = "Info Screen";
713 static char *main_text_game = "Start Game";
714 static char *main_text_setup = "Setup";
715 static char *main_text_quit = "Quit";
716 static char *main_text_level_name = level.name;
717 static char *main_text_level_author = level.author;
718 static char *main_text_level_year = NULL;
719 static char *main_text_level_imported_from = NULL;
720 static char *main_text_level_imported_by = NULL;
721 static char *main_text_level_tested_by = NULL;
722 static char *main_text_title_1 = NULL;
723 static char *main_text_title_2 = NULL;
724 static char *main_text_title_3 = NULL;
726 extern char debug_xsn_mode[];
728 struct MainControlInfo
732 struct MenuPosInfo *pos_button;
735 struct TextPosInfo *pos_text;
738 struct TextPosInfo *pos_input;
742 static struct MainControlInfo main_controls[] =
746 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
747 &menu.main.text.name, &main_text_name,
748 &menu.main.input.name, &setup.player_name,
752 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
753 &menu.main.text.levels, &main_text_levels,
758 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
759 &menu.main.text.scores, &main_text_scores,
764 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
765 &menu.main.text.editor, &main_text_editor,
770 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
771 &menu.main.text.info, &main_text_info,
776 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
777 &menu.main.text.game, &main_text_game,
782 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
783 &menu.main.text.setup, &main_text_setup,
788 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
789 &menu.main.text.quit, &main_text_quit,
793 MAIN_CONTROL_PREV_LEVEL,
799 MAIN_CONTROL_NEXT_LEVEL,
805 MAIN_CONTROL_FIRST_LEVEL,
807 &menu.main.text.first_level, &main_text_first_level,
811 MAIN_CONTROL_LAST_LEVEL,
813 &menu.main.text.last_level, &main_text_last_level,
817 MAIN_CONTROL_LEVEL_NUMBER,
819 &menu.main.text.level_number, &main_text_level_number,
823 MAIN_CONTROL_LEVEL_INFO_1,
825 &menu.main.text.level_info_1, NULL,
829 MAIN_CONTROL_LEVEL_INFO_2,
831 &menu.main.text.level_info_2, NULL,
835 MAIN_CONTROL_LEVEL_NAME,
837 &menu.main.text.level_name, &main_text_level_name,
841 MAIN_CONTROL_LEVEL_AUTHOR,
843 &menu.main.text.level_author, &main_text_level_author,
847 MAIN_CONTROL_LEVEL_YEAR,
849 &menu.main.text.level_year, &main_text_level_year,
853 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
855 &menu.main.text.level_imported_from, &main_text_level_imported_from,
859 MAIN_CONTROL_LEVEL_IMPORTED_BY,
861 &menu.main.text.level_imported_by, &main_text_level_imported_by,
865 MAIN_CONTROL_LEVEL_TESTED_BY,
867 &menu.main.text.level_tested_by, &main_text_level_tested_by,
871 MAIN_CONTROL_TITLE_1,
873 &menu.main.text.title_1, &main_text_title_1,
877 MAIN_CONTROL_TITLE_2,
879 &menu.main.text.title_2, &main_text_title_2,
883 MAIN_CONTROL_TITLE_3,
885 &menu.main.text.title_3, &main_text_title_3,
898 static int getTitleScreenGraphic(int nr, boolean initial)
900 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
903 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
905 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
909 static int getTitleScreenGameMode(boolean initial)
911 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
915 static int getTitleMessageGameMode(boolean initial)
917 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
920 static int getTitleAnimMode(struct TitleControlInfo *tci)
922 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
924 return base + tci->local_nr;
928 static int getTitleScreenBackground(boolean initial)
930 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
935 static int getTitleMessageBackground(int nr, boolean initial)
937 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
941 static int getTitleBackground(int nr, boolean initial, boolean is_image)
943 int base = (is_image ?
944 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
945 IMG_BACKGROUND_TITLESCREEN_1) :
946 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
947 IMG_BACKGROUND_TITLEMESSAGE_1));
948 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
949 IMG_BACKGROUND_TITLE);
950 int graphic_local = base + nr;
952 if (graphic_info[graphic_local].bitmap != NULL)
953 return graphic_local;
955 if (graphic_info[graphic_global].bitmap != NULL)
956 return graphic_global;
958 return IMG_UNDEFINED;
961 static int getTitleSound(struct TitleControlInfo *tci)
963 boolean is_image = tci->is_image;
964 int initial = tci->initial;
965 int nr = tci->local_nr;
966 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
967 int base = (is_image ?
968 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
969 SND_BACKGROUND_TITLESCREEN_1) :
970 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
971 SND_BACKGROUND_TITLEMESSAGE_1));
972 int sound_global = menu.sound[mode];
973 int sound_local = base + nr;
976 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
977 nr, initial, is_image,
978 sound_global, getSoundListEntry(sound_global)->filename,
979 sound_local, getSoundListEntry(sound_local)->filename);
982 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
985 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
988 return SND_UNDEFINED;
991 static int getTitleMusic(struct TitleControlInfo *tci)
993 boolean is_image = tci->is_image;
994 int initial = tci->initial;
995 int nr = tci->local_nr;
996 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
997 int base = (is_image ?
998 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
999 MUS_BACKGROUND_TITLESCREEN_1) :
1000 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1001 MUS_BACKGROUND_TITLEMESSAGE_1));
1002 int music_global = menu.music[mode];
1003 int music_local = base + nr;
1006 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1007 nr, initial, is_image,
1008 music_global, getMusicListEntry(music_global)->filename,
1009 music_local, getMusicListEntry(music_local)->filename);
1012 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1015 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1016 return music_global;
1018 return MUS_UNDEFINED;
1021 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1023 boolean is_image = tci->is_image;
1024 boolean initial = tci->initial;
1025 boolean first = tci->first;
1026 int nr = tci->local_nr;
1027 struct TitleMessageInfo tmi;
1028 struct TitleFadingInfo ti;
1030 tmi = (is_image ? (initial ? (first ?
1031 titlescreen_initial_first[nr] :
1032 titlescreen_initial[nr])
1034 titlescreen_first[nr] :
1036 : (initial ? (first ?
1037 titlemessage_initial_first[nr] :
1038 titlemessage_initial[nr])
1040 titlemessage_first[nr] :
1041 titlemessage[nr])));
1043 ti.fade_mode = tmi.fade_mode;
1044 ti.fade_delay = tmi.fade_delay;
1045 ti.post_delay = tmi.post_delay;
1046 ti.auto_delay = tmi.auto_delay;
1047 ti.auto_delay_unit = tmi.auto_delay_unit;
1052 static int compareTitleControlInfo(const void *object1, const void *object2)
1054 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1055 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1058 if (tci1->initial != tci2->initial)
1059 compare_result = (tci1->initial ? -1 : +1);
1060 else if (tci1->sort_priority != tci2->sort_priority)
1061 compare_result = tci1->sort_priority - tci2->sort_priority;
1062 else if (tci1->is_image != tci2->is_image)
1063 compare_result = (tci1->is_image ? -1 : +1);
1065 compare_result = tci1->local_nr - tci2->local_nr;
1067 return compare_result;
1070 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1072 int nr, int sort_priority)
1074 title_controls[num_title_screens].is_image = is_image;
1075 title_controls[num_title_screens].initial = initial;
1076 title_controls[num_title_screens].local_nr = nr;
1077 title_controls[num_title_screens].sort_priority = sort_priority;
1079 title_controls[num_title_screens].first = FALSE; // will be set later
1081 num_title_screens++;
1084 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1088 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1090 int graphic = getTitleScreenGraphic(i, initial);
1091 Bitmap *bitmap = graphic_info[graphic].bitmap;
1092 int sort_priority = graphic_info[graphic].sort_priority;
1095 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1098 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1100 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1101 char *filename = getLevelSetTitleMessageFilename(i, initial);
1102 int sort_priority = tmi->sort_priority;
1104 if (filename != NULL)
1105 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1109 static void InitializeTitleControls(boolean show_title_initial)
1111 num_title_screens = 0;
1113 // 1st step: initialize title screens for game start (only when starting)
1114 if (show_title_initial)
1115 InitializeTitleControls_CheckTitleInfo(TRUE);
1117 // 2nd step: initialize title screens for current level set
1118 InitializeTitleControls_CheckTitleInfo(FALSE);
1120 // sort title screens according to sort_priority and title number
1121 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1122 compareTitleControlInfo);
1124 // mark first title screen
1125 title_controls[0].first = TRUE;
1128 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1130 return (pos != NULL && pos->x != -1 && pos->y != -1);
1133 static boolean visibleTextPos(struct TextPosInfo *pos)
1135 return (pos != NULL && pos->x != -1 && pos->y != -1);
1138 static void InitializeMainControls(void)
1140 boolean local_team_mode = (!network.enabled && setup.team_mode);
1143 // set main control text values to dynamically determined values
1144 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1146 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1147 menu.main.text.first_level.size));
1148 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1149 menu.main.text.last_level.size));
1150 strcpy(main_text_level_number, int2str(level_nr,
1151 menu.main.text.level_number.size));
1153 main_text_level_year = leveldir_current->year;
1154 main_text_level_imported_from = leveldir_current->imported_from;
1155 main_text_level_imported_by = leveldir_current->imported_by;
1156 main_text_level_tested_by = leveldir_current->tested_by;
1158 main_text_title_1 = getConfigProgramTitleString();
1159 main_text_title_2 = getConfigProgramCopyrightString();
1160 main_text_title_3 = getConfigProgramCompanyString();
1162 // set main control screen positions to dynamically determined values
1163 for (i = 0; main_controls[i].nr != -1; i++)
1165 struct MainControlInfo *mci = &main_controls[i];
1167 struct MenuPosInfo *pos_button = mci->pos_button;
1168 struct TextPosInfo *pos_text = mci->pos_text;
1169 struct TextPosInfo *pos_input = mci->pos_input;
1170 char *text = (mci->text ? *mci->text : NULL);
1171 char *input = (mci->input ? *mci->input : NULL);
1172 int button_graphic = mci->button_graphic;
1173 int font_text = (pos_text ? pos_text->font : -1);
1174 int font_input = (pos_input ? pos_input->font : -1);
1176 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1177 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1178 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1179 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1180 int text_chars = (text != NULL ? strlen(text) : 0);
1181 int input_chars = (input != NULL ? strlen(input) : 0);
1184 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1186 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1187 int text_width = font_text_width * text_chars;
1188 int text_height = font_text_height;
1189 int input_width = font_input_width * input_chars;
1190 int input_height = font_input_height;
1192 if (nr == MAIN_CONTROL_NAME)
1194 menu.main.input.name.width = input_width;
1195 menu.main.input.name.height = input_height;
1198 if (pos_button != NULL) // (x/y may be -1/-1 here)
1200 pos_button->width = button_width;
1201 pos_button->height = button_height;
1204 if (pos_text != NULL) // (x/y may be -1/-1 here)
1206 // calculate text size -- needed for text alignment
1207 boolean calculate_text_size = (text != NULL);
1209 if (pos_text->width == -1 || calculate_text_size)
1210 pos_text->width = text_width;
1211 if (pos_text->height == -1 || calculate_text_size)
1212 pos_text->height = text_height;
1214 if (visibleMenuPos(pos_button))
1216 if (pos_text->x == -1)
1217 pos_text->x = pos_button->x + pos_button->width;
1218 if (pos_text->y == -1)
1220 pos_button->y + (pos_button->height - pos_text->height) / 2;
1224 if (pos_input != NULL) // (x/y may be -1/-1 here)
1226 if (visibleTextPos(pos_text))
1228 if (pos_input->x == -1)
1229 pos_input->x = pos_text->x + pos_text->width;
1230 if (pos_input->y == -1)
1231 pos_input->y = pos_text->y;
1234 if (pos_input->width == -1)
1235 pos_input->width = input_width;
1236 if (pos_input->height == -1)
1237 pos_input->height = input_height;
1242 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1243 int graphic, boolean pressed)
1245 struct GraphicInfo *g = &graphic_info[graphic];
1248 int xoffset = (pressed ? g->pressed_xoffset : 0);
1249 int yoffset = (pressed ? g->pressed_yoffset : 0);
1251 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1253 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1254 g->width, g->height, dst_x, dst_y);
1257 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1258 boolean active_input,
1259 boolean pressed_button)
1263 for (i = 0; main_controls[i].nr != -1; i++)
1265 struct MainControlInfo *mci = &main_controls[i];
1267 if (mci->nr == nr || nr == -1)
1269 struct MenuPosInfo *pos_button = mci->pos_button;
1270 struct TextPosInfo *pos_text = mci->pos_text;
1271 struct TextPosInfo *pos_input = mci->pos_input;
1272 char *text = (mci->text ? *mci->text : NULL);
1273 char *input = (mci->input ? *mci->input : NULL);
1274 int button_graphic = mci->button_graphic;
1275 int font_text = (pos_text ? pos_text->font : -1);
1276 int font_input = (pos_input ? pos_input->font : -1);
1280 button_graphic = BUTTON_ACTIVE(button_graphic);
1281 font_text = FONT_ACTIVE(font_text);
1286 font_input = FONT_ACTIVE(font_input);
1289 if (visibleMenuPos(pos_button))
1291 struct MenuPosInfo *pos = pos_button;
1292 int x = mSX + pos->x;
1293 int y = mSY + pos->y;
1295 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1296 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1299 if (visibleTextPos(pos_text) && text != NULL)
1301 struct TextPosInfo *pos = pos_text;
1302 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1303 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1306 // (check why/if this is needed)
1307 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1309 DrawText(x, y, text, font_text);
1312 if (visibleTextPos(pos_input) && input != NULL)
1314 struct TextPosInfo *pos = pos_input;
1315 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1316 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1319 // (check why/if this is needed)
1320 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1322 DrawText(x, y, input, font_input);
1328 static void DrawCursorAndText_Main(int nr, boolean active_text,
1329 boolean pressed_button)
1331 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1335 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1336 boolean pressed_button)
1338 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1342 static struct MainControlInfo *getMainControlInfo(int nr)
1346 for (i = 0; main_controls[i].nr != -1; i++)
1347 if (main_controls[i].nr == nr)
1348 return &main_controls[i];
1353 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1358 int rect_x = ALIGNED_TEXT_XPOS(rect);
1359 int rect_y = ALIGNED_TEXT_YPOS(rect);
1361 return (x >= rect_x && x < rect_x + rect->width &&
1362 y >= rect_y && y < rect_y + rect->height);
1365 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1370 int rect_x = ALIGNED_TEXT_XPOS(rect);
1371 int rect_y = ALIGNED_TEXT_YPOS(rect);
1374 Debug("screens:insideTextPosRect",
1375 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1376 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1377 (x >= rect_x && x < rect_x + rect->width &&
1378 y >= rect_y && y < rect_y + rect->height));
1381 return (x >= rect_x && x < rect_x + rect->width &&
1382 y >= rect_y && y < rect_y + rect->height);
1385 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1387 int rect_width = preview->xsize * preview->tile_size;
1388 int rect_height = preview->ysize * preview->tile_size;
1389 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1390 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1392 return (x >= rect_x && x < rect_x + rect_width &&
1393 y >= rect_y && y < rect_y + rect_height);
1396 static void AdjustScrollbar(int id, int items_max, int items_visible,
1399 struct GadgetInfo *gi = screen_gadget[id];
1401 if (item_position > items_max - items_visible)
1402 item_position = items_max - items_visible;
1404 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1405 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1406 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1409 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1411 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1415 static void clearMenuListArea(void)
1417 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1419 // correct scrollbar position if placed outside menu (playfield) area
1420 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1421 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1423 // clear menu list area, but not title or scrollbar
1424 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1425 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1428 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1430 static int cursor_array[MAX_LEV_FIELDY];
1431 int x = amSX + TILEX * xpos;
1432 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1437 cursor_array[ypos] = graphic;
1439 graphic = cursor_array[ypos];
1443 graphic = BUTTON_ACTIVE(graphic);
1445 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1446 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1449 static void initCursor(int ypos, int graphic)
1451 drawCursorExt(0, ypos, FALSE, graphic);
1454 static void drawCursor(int ypos, boolean active)
1456 drawCursorExt(0, ypos, active, -1);
1459 static void drawCursorXY(int xpos, int ypos, int graphic)
1461 drawCursorExt(xpos, ypos, FALSE, graphic);
1464 static void drawChooseTreeCursor(int ypos, boolean active)
1466 drawCursorExt(0, ypos, active, -1);
1469 static int getChooseTreeEditFont(boolean active)
1471 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1474 static int getChooseTreeEditXPos(int pos)
1476 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1477 int xoffset = (has_scrollbar ? -1 : 0);
1478 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1479 int sx = amSX + xpos * TILEX;
1480 int font_nr = getChooseTreeEditFont(FALSE);
1481 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1483 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1486 static int getChooseTreeEditYPos(int ypos_raw)
1488 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1489 int sy = amSY + ypos * TILEY;
1494 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1496 int sx = getChooseTreeEditXPos(POS_LEFT);
1497 int sy = getChooseTreeEditYPos(ypos_raw);
1498 int font_nr = getChooseTreeEditFont(active);
1500 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1503 static void DrawHeadline(void)
1505 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1506 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1509 static void DrawTitleScreenImage(int nr, boolean initial)
1511 int graphic = getTitleScreenGraphic(nr, initial);
1512 Bitmap *bitmap = graphic_info[graphic].bitmap;
1513 int width = graphic_info[graphic].width;
1514 int height = graphic_info[graphic].height;
1515 int src_x = graphic_info[graphic].src_x;
1516 int src_y = graphic_info[graphic].src_y;
1522 if (width > WIN_XSIZE)
1524 // image width too large for window => center image horizontally
1525 src_x = (width - WIN_XSIZE) / 2;
1529 if (height > WIN_YSIZE)
1531 // image height too large for window => center image vertically
1532 src_y = (height - WIN_YSIZE) / 2;
1536 // always display title screens centered
1537 dst_x = (WIN_XSIZE - width) / 2;
1538 dst_y = (WIN_YSIZE - height) / 2;
1540 SetDrawBackgroundMask(REDRAW_ALL);
1541 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1543 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1545 if (DrawingOnBackground(dst_x, dst_y))
1546 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1548 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1550 redraw_mask = REDRAW_ALL;
1553 static void DrawTitleScreenMessage(int nr, boolean initial)
1555 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1556 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1558 if (filename == NULL)
1561 // force TITLE font on title message screen
1562 SetFontStatus(getTitleMessageGameMode(initial));
1564 // if chars *and* width set to "-1", automatically determine width
1565 if (tmi->chars == -1 && tmi->width == -1)
1566 tmi->width = viewport.window[game_status].width;
1568 // if lines *and* height set to "-1", automatically determine height
1569 if (tmi->lines == -1 && tmi->height == -1)
1570 tmi->height = viewport.window[game_status].height;
1572 // if chars set to "-1", automatically determine by text and font width
1573 if (tmi->chars == -1)
1574 tmi->chars = tmi->width / getFontWidth(tmi->font);
1576 tmi->width = tmi->chars * getFontWidth(tmi->font);
1578 // if lines set to "-1", automatically determine by text and font height
1579 if (tmi->lines == -1)
1580 tmi->lines = tmi->height / getFontHeight(tmi->font);
1582 tmi->height = tmi->lines * getFontHeight(tmi->font);
1584 // if x set to "-1", automatically determine by width and alignment
1586 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1588 // if y set to "-1", automatically determine by height and alignment
1590 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1592 SetDrawBackgroundMask(REDRAW_ALL);
1593 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1595 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1597 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1598 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1599 tmi->autowrap, tmi->centered, tmi->parse_comments);
1604 static void DrawTitleScreen(void)
1606 KeyboardAutoRepeatOff();
1608 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1611 static boolean CheckTitleScreen(boolean levelset_has_changed)
1613 static boolean show_title_initial = TRUE;
1614 boolean show_titlescreen = FALSE;
1616 // needed to be able to skip title screen, if no image or message defined
1617 InitializeTitleControls(show_title_initial);
1619 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1620 show_titlescreen = TRUE;
1622 // show initial title images and messages only once at program start
1623 show_title_initial = FALSE;
1625 return (show_titlescreen && num_title_screens > 0);
1628 void DrawMainMenu(void)
1630 static LevelDirTree *leveldir_last_valid = NULL;
1631 boolean levelset_has_changed = FALSE;
1632 int fade_mask = REDRAW_FIELD;
1634 LimitScreenUpdates(FALSE);
1636 FadeSetLeaveScreen();
1638 // do not fade out here -- function may continue and fade on editor screen
1641 FadeMenuSoundsAndMusic();
1643 ExpireSoundLoops(FALSE);
1645 KeyboardAutoRepeatOn();
1647 audio.sound_deactivated = FALSE;
1651 // needed if last screen was the playing screen, invoked from level editor
1652 if (level_editor_test_game)
1654 CloseDoor(DOOR_CLOSE_ALL);
1656 SetGameStatus(GAME_MODE_EDITOR);
1663 // leveldir_current may be invalid (level group, parent link, node copy)
1664 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1666 if (leveldir_current != leveldir_last_valid)
1668 UpdateLastPlayedLevels_TreeInfo();
1670 levelset_has_changed = TRUE;
1673 // store valid level series information
1674 leveldir_last_valid = leveldir_current;
1676 init_last = init; // switch to new busy animation
1678 // needed if last screen (level choice) changed graphics, sounds or music
1679 ReloadCustomArtwork(0);
1681 if (CheckTitleScreen(levelset_has_changed))
1683 SetGameStatus(GAME_MODE_TITLE);
1690 if (redraw_mask & REDRAW_ALL)
1691 fade_mask = REDRAW_ALL;
1694 fade_mask = REDRAW_ALL;
1698 // needed if different viewport properties defined for menues
1699 ChangeViewportPropertiesIfNeeded();
1701 SetDrawtoField(DRAW_TO_BACKBUFFER);
1703 // level_nr may have been set to value over handicap with level editor
1704 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1705 level_nr = leveldir_current->handicap_level;
1707 LoadLevel(level_nr);
1708 LoadScore(level_nr);
1710 SaveLevelSetup_SeriesInfo();
1712 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1713 SetDrawDeactivationMask(REDRAW_NONE);
1714 SetDrawBackgroundMask(REDRAW_FIELD);
1716 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1719 if (fade_mask == REDRAW_ALL)
1720 RedrawGlobalBorder();
1725 InitializeMainControls();
1727 DrawCursorAndText_Main(-1, FALSE, FALSE);
1728 DrawPreviewLevelInitial();
1729 DrawNetworkPlayers();
1731 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1734 if (TAPE_IS_EMPTY(tape))
1736 DrawCompleteVideoDisplay();
1738 PlayMenuSoundsAndMusic();
1740 // create gadgets for main menu screen
1741 FreeScreenGadgets();
1742 CreateScreenGadgets();
1744 // may be required if audio buttons shown on tape and changed in setup menu
1746 CreateGameButtons();
1748 // map gadgets for main menu screen
1750 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1751 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1753 // copy actual game door content to door double buffer for OpenDoor()
1754 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1755 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1757 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1759 DrawMaskedBorder(fade_mask);
1764 // update screen area with special editor door
1765 redraw_mask |= REDRAW_ALL;
1768 SetMouseCursor(CURSOR_DEFAULT);
1770 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1772 SyncEmscriptenFilesystem();
1774 // needed once after program start or after user change
1775 CheckApiServerTasks();
1778 static void gotoTopLevelDir(void)
1780 // move upwards until inside (but not above) top level directory
1781 while (leveldir_current->node_parent &&
1782 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1784 // write a "path" into level tree for easy navigation to last level
1785 if (leveldir_current->node_parent->node_group->cl_first == -1)
1787 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1788 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1789 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1790 int cl_first, cl_cursor;
1792 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1793 cl_cursor = leveldir_pos - cl_first;
1795 leveldir_current->node_parent->node_group->cl_first = cl_first;
1796 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1799 leveldir_current = leveldir_current->node_parent;
1803 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1805 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1807 return (use_frame_counter ? video.frame_counter : Counter());
1810 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1811 struct TitleFadingInfo *fi)
1813 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1816 static void ResetTitleAutoDelay(unsigned int *counter_var,
1817 struct TitleFadingInfo *fi)
1819 *counter_var = getAutoDelayCounter(fi);
1822 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1824 static unsigned int title_delay = 0;
1825 static int title_screen_nr = 0;
1826 static int last_sound = -1, last_music = -1;
1827 boolean return_to_main_menu = FALSE;
1828 struct TitleControlInfo *tci;
1831 if (button == MB_MENU_INITIALIZE)
1834 title_screen_nr = 0;
1835 tci = &title_controls[title_screen_nr];
1837 SetAnimStatus(getTitleAnimMode(tci));
1839 last_sound = SND_UNDEFINED;
1840 last_music = MUS_UNDEFINED;
1842 if (num_title_screens != 0)
1844 FadeSetEnterScreen();
1846 // use individual title fading instead of global "enter screen" fading
1847 fading = getTitleFading(tci);
1850 if (game_status_last_screen == GAME_MODE_INFO)
1852 if (num_title_screens == 0)
1854 // switch game mode from title screen mode back to info screen mode
1855 SetGameStatus(GAME_MODE_INFO);
1857 // store that last screen was info screen, not main menu screen
1858 game_status_last_screen = GAME_MODE_INFO;
1860 DrawInfoScreen_NotAvailable("Title screen information:",
1861 "No title screen for this level set.");
1866 FadeMenuSoundsAndMusic();
1868 FadeOut(REDRAW_ALL);
1870 // title screens may have different window size
1871 ChangeViewportPropertiesIfNeeded();
1873 // only required to update logic for redrawing global border
1877 DrawTitleScreenImage(tci->local_nr, tci->initial);
1879 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1881 sound = getTitleSound(tci);
1882 music = getTitleMusic(tci);
1884 if (sound != last_sound)
1885 PlayMenuSoundExt(sound);
1886 if (music != last_music)
1887 PlayMenuMusicExt(music);
1892 SetMouseCursor(CURSOR_NONE);
1896 ResetTitleAutoDelay(&title_delay, &fading);
1901 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1902 button = MB_MENU_CHOICE;
1904 if (button == MB_MENU_LEAVE)
1906 return_to_main_menu = TRUE;
1908 else if (button == MB_MENU_CHOICE)
1910 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1912 SetGameStatus(GAME_MODE_INFO);
1914 info_mode = INFO_MODE_MAIN;
1923 if (title_screen_nr < num_title_screens)
1925 tci = &title_controls[title_screen_nr];
1927 SetAnimStatus(getTitleAnimMode(tci));
1929 sound = getTitleSound(tci);
1930 music = getTitleMusic(tci);
1932 if (last_sound != SND_UNDEFINED && sound != last_sound)
1933 FadeSound(last_sound);
1934 if (last_music != MUS_UNDEFINED && music != last_music)
1937 fading = getTitleFading(tci);
1939 FadeOut(REDRAW_ALL);
1942 DrawTitleScreenImage(tci->local_nr, tci->initial);
1944 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1946 sound = getTitleSound(tci);
1947 music = getTitleMusic(tci);
1949 if (sound != last_sound)
1950 PlayMenuSoundExt(sound);
1951 if (music != last_music)
1952 PlayMenuMusicExt(music);
1959 ResetTitleAutoDelay(&title_delay, &fading);
1963 FadeMenuSoundsAndMusic();
1965 return_to_main_menu = TRUE;
1969 if (return_to_main_menu)
1971 SetMouseCursor(CURSOR_DEFAULT);
1973 // force full menu screen redraw after displaying title screens
1974 redraw_mask = REDRAW_ALL;
1976 if (game_status_last_screen == GAME_MODE_INFO)
1978 SetGameStatus(GAME_MODE_INFO);
1980 info_mode = INFO_MODE_MAIN;
1984 else // default: return to main menu
1986 SetGameStatus(GAME_MODE_MAIN);
1993 static void HandleMainMenu_ToggleTeamMode(void)
1995 setup.team_mode = !setup.team_mode;
1997 InitializeMainControls();
1998 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2000 DrawPreviewPlayers();
2003 static void HandleMainMenu_SelectLevel(int step, int direction,
2004 int selected_level_nr)
2006 int old_level_nr = level_nr;
2009 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2010 new_level_nr = selected_level_nr;
2012 new_level_nr = old_level_nr + step * direction;
2014 if (new_level_nr < leveldir_current->first_level)
2015 new_level_nr = leveldir_current->first_level;
2016 if (new_level_nr > leveldir_current->last_level)
2017 new_level_nr = leveldir_current->last_level;
2019 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2021 // skipping levels is only allowed when trying to skip single level
2022 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2023 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2025 leveldir_current->handicap_level++;
2026 SaveLevelSetup_SeriesInfo();
2029 new_level_nr = leveldir_current->handicap_level;
2032 if (new_level_nr != old_level_nr)
2034 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2036 PlaySound(SND_MENU_ITEM_SELECTING);
2038 level_nr = new_level_nr;
2040 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2041 int2str(level_nr, menu.main.text.level_number.size),
2042 mci->pos_text->font);
2044 LoadLevel(level_nr);
2045 DrawPreviewLevelInitial();
2049 DrawCompleteVideoDisplay();
2051 SaveLevelSetup_SeriesInfo();
2053 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2055 // force redraw of playfield area (may be reset at this point)
2056 redraw_mask |= REDRAW_FIELD;
2060 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2062 static int choice = MAIN_CONTROL_GAME;
2063 static boolean button_pressed_last = FALSE;
2064 boolean button_pressed = FALSE;
2066 int i = 0; // needed to prevent compiler warning due to bad code below
2068 if (button == MB_MENU_INITIALIZE)
2070 DrawCursorAndText_Main(choice, TRUE, FALSE);
2075 if (mx || my) // mouse input
2079 for (i = 0; main_controls[i].nr != -1; i++)
2081 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2082 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2083 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2085 pos = main_controls[i].nr;
2091 // check if level preview was clicked
2092 if (insidePreviewRect(&preview, mx - SX, my - SY))
2093 pos = MAIN_CONTROL_GAME;
2095 // handle pressed/unpressed state for active/inactive menu buttons
2096 // (if pos != -1, "i" contains index position corresponding to "pos")
2098 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2099 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2100 button_pressed = TRUE;
2102 if (button_pressed != button_pressed_last)
2104 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2107 PlaySound(SND_MENU_BUTTON_PRESSING);
2109 PlaySound(SND_MENU_BUTTON_RELEASING);
2112 else if (dx || dy) // keyboard input
2114 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2115 choice == MAIN_CONTROL_SETUP))
2116 button = MB_MENU_CHOICE;
2121 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2123 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2125 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2127 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2129 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2131 CloseDoor(DOOR_CLOSE_2);
2133 SetGameStatus(GAME_MODE_LEVELNR);
2135 DrawChooseLevelNr();
2137 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2143 PlaySound(SND_MENU_ITEM_ACTIVATING);
2145 DrawCursorAndText_Main(choice, FALSE, FALSE);
2146 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2152 if (choice == MAIN_CONTROL_NAME)
2154 // special case: cursor left or right pressed -- toggle team mode
2155 HandleMainMenu_ToggleTeamMode();
2157 else if (choice != MAIN_CONTROL_INFO &&
2158 choice != MAIN_CONTROL_SETUP)
2160 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2166 PlaySound(SND_MENU_ITEM_SELECTING);
2168 if (pos == MAIN_CONTROL_NAME)
2171 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2173 // special case: menu text "name/team" clicked -- toggle team mode
2174 HandleMainMenu_ToggleTeamMode();
2178 if (setup.multiple_users)
2180 CloseDoor(DOOR_CLOSE_2);
2182 SetGameStatus(GAME_MODE_NAMES);
2184 DrawChoosePlayerName();
2188 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2194 else if (pos == MAIN_CONTROL_LEVELS)
2198 CloseDoor(DOOR_CLOSE_2);
2200 SetGameStatus(GAME_MODE_LEVELS);
2202 SaveLevelSetup_LastSeries();
2203 SaveLevelSetup_SeriesInfo();
2205 // restore level set if chosen from "last played level set" menu
2206 RestoreLastPlayedLevels(&leveldir_current);
2208 if (setup.internal.choose_from_top_leveldir)
2211 DrawChooseLevelSet();
2214 else if (pos == MAIN_CONTROL_SCORES)
2216 CloseDoor(DOOR_CLOSE_2);
2218 SetGameStatus(GAME_MODE_SCORES);
2220 DrawHallOfFame(level_nr);
2222 else if (pos == MAIN_CONTROL_EDITOR)
2224 if (leveldir_current->readonly &&
2225 setup.editor.show_read_only_warning)
2226 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2228 CloseDoor(DOOR_CLOSE_ALL);
2230 SetGameStatus(GAME_MODE_EDITOR);
2232 FadeSetEnterScreen();
2236 else if (pos == MAIN_CONTROL_INFO)
2238 CloseDoor(DOOR_CLOSE_2);
2240 SetGameStatus(GAME_MODE_INFO);
2242 info_mode = INFO_MODE_MAIN;
2246 else if (pos == MAIN_CONTROL_GAME)
2248 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2250 else if (pos == MAIN_CONTROL_SETUP)
2252 CloseDoor(DOOR_CLOSE_2);
2254 SetGameStatus(GAME_MODE_SETUP);
2256 setup_mode = SETUP_MODE_MAIN;
2260 else if (pos == MAIN_CONTROL_QUIT)
2262 SaveLevelSetup_LastSeries();
2263 SaveLevelSetup_SeriesInfo();
2265 #if defined(PLATFORM_EMSCRIPTEN)
2266 Request("Close the browser window to quit!", REQ_CONFIRM);
2268 if (!setup.ask_on_quit_program ||
2269 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2270 SetGameStatus(GAME_MODE_QUIT);
2276 button_pressed_last = button_pressed;
2280 // ============================================================================
2281 // info screen functions
2282 // ============================================================================
2284 static struct TokenInfo *info_info;
2285 static int num_info_info; // number of info entries shown on screen
2286 static int max_info_info; // total number of info entries in list
2288 static void execInfoTitleScreen(void)
2290 info_mode = INFO_MODE_TITLE;
2295 static void execInfoElements(void)
2297 info_mode = INFO_MODE_ELEMENTS;
2302 static void execInfoMusic(void)
2304 info_mode = INFO_MODE_MUSIC;
2309 static void execInfoCredits(void)
2311 info_mode = INFO_MODE_CREDITS;
2316 static void execInfoProgram(void)
2318 info_mode = INFO_MODE_PROGRAM;
2323 static void execInfoVersion(void)
2325 info_mode = INFO_MODE_VERSION;
2330 static void execInfoLevelSet(void)
2332 info_mode = INFO_MODE_LEVELSET;
2337 static void execExitInfo(void)
2339 SetGameStatus(GAME_MODE_MAIN);
2344 static struct TokenInfo info_info_main[] =
2346 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2347 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2348 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2349 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2350 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2351 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2352 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2353 { TYPE_EMPTY, NULL, "" },
2354 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2359 static int getMenuTextFont(int type)
2361 if (type & (TYPE_SWITCH |
2375 static struct TokenInfo *setup_info;
2376 static struct TokenInfo setup_info_input[];
2378 static struct TokenInfo *menu_info;
2380 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2381 int screen_pos, int menu_info_pos_raw,
2384 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2385 struct TokenInfo *ti = &token_info[pos];
2386 int xpos = MENU_SCREEN_START_XPOS;
2387 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2388 int font_nr = getMenuTextFont(ti->type);
2390 if (setup_mode == SETUP_MODE_INPUT)
2391 font_nr = FONT_MENU_1;
2394 font_nr = FONT_ACTIVE(font_nr);
2396 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2398 if (ti->type & ~TYPE_SKIP_ENTRY)
2399 drawCursor(screen_pos, active);
2402 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2405 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2408 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2411 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2414 static char *window_size_text;
2415 static char *scaling_type_text;
2416 static char *network_server_text;
2418 static void drawSetupValue(int, int);
2420 static void drawMenuInfoList(int first_entry, int num_page_entries,
2421 int max_page_entries)
2425 if (first_entry + num_page_entries > max_page_entries)
2428 clearMenuListArea();
2430 for (i = 0; i < num_page_entries; i++)
2432 int menu_info_pos = first_entry + i;
2433 struct TokenInfo *si = &menu_info[menu_info_pos];
2434 void *value_ptr = si->value;
2436 // set some entries to "unchangeable" according to other variables
2437 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2438 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2439 (value_ptr == &setup.sound_music && !audio.music_available) ||
2440 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2441 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2442 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2443 si->type |= TYPE_GHOSTED;
2445 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2446 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2447 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2448 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2449 else if (si->type & ~TYPE_SKIP_ENTRY)
2450 initCursor(i, IMG_MENU_BUTTON);
2452 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2454 if (si->type & TYPE_STRING)
2458 if (value_ptr == &network_server_text)
2459 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2461 if (gadget_id != -1)
2463 struct GadgetInfo *gi = screen_gadget[gadget_id];
2464 int xpos = MENU_SCREEN_START_XPOS;
2465 int ypos = MENU_SCREEN_START_YPOS + i;
2466 int x = mSX + xpos * 32;
2467 int y = mSY + ypos * 32;
2469 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2473 if (si->type & TYPE_VALUE &&
2474 menu_info == setup_info)
2475 drawSetupValue(i, menu_info_pos);
2479 static void DrawInfoScreen_Main(void)
2481 int fade_mask = REDRAW_FIELD;
2484 if (redraw_mask & REDRAW_ALL)
2485 fade_mask = REDRAW_ALL;
2488 fade_mask = REDRAW_ALL;
2491 FadeMenuSoundsAndMusic();
2493 FreeScreenGadgets();
2494 CreateScreenGadgets();
2496 // (needed after displaying title screens which disable auto repeat)
2497 KeyboardAutoRepeatOn();
2499 FadeSetLeaveScreen();
2503 // needed if different viewport properties defined for info screen
2504 ChangeViewportPropertiesIfNeeded();
2506 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2510 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2512 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2514 info_info = info_info_main;
2516 // determine maximal number of info entries that can be displayed on screen
2518 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2521 // determine maximal number of info entries available for menu of info screen
2523 for (i = 0; info_info[i].type != 0; i++)
2526 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2528 MapScreenGadgets(max_info_info);
2530 PlayMenuSoundsAndMusic();
2532 DrawMaskedBorder(fade_mask);
2537 static void changeSetupValue(int, int, int);
2539 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2540 int mode, int num_page_entries,
2541 int max_page_entries)
2543 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2544 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2545 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2546 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2547 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2548 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2549 int *num_page_entries_last = num_page_entries_all_last[game_status];
2550 int *choice_store = choice_stores[game_status];
2551 int *first_entry_store = first_entry_stores[game_status];
2552 int choice = choice_store[mode]; // starts with 0
2553 int first_entry = first_entry_store[mode]; // starts with 0
2555 int y = choice - first_entry;
2557 boolean position_set_by_scrollbar = (dx == 999);
2558 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2561 if (button == MB_MENU_INITIALIZE)
2563 // check if number of menu page entries has changed (may happen by change
2564 // of custom artwork definition value for 'list_size' for this menu screen)
2565 // (in this case, the last menu position most probably has to be corrected)
2566 if (num_page_entries != num_page_entries_last[mode])
2568 choice_store[mode] = first_entry_store[mode] = 0;
2570 choice = first_entry = 0;
2573 num_page_entries_last[mode] = num_page_entries;
2576 // advance to first valid menu entry
2577 while (choice < num_page_entries &&
2578 menu_info[choice].type & TYPE_SKIP_ENTRY)
2581 if (position_set_by_scrollbar)
2582 first_entry = first_entry_store[mode] = dy;
2584 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2585 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2587 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2589 if (choice < first_entry)
2591 choice = first_entry;
2593 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2596 else if (choice > first_entry + num_page_entries - 1)
2598 choice = first_entry + num_page_entries - 1;
2600 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2604 choice_store[mode] = choice;
2606 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2610 else if (button == MB_MENU_LEAVE)
2612 PlaySound(SND_MENU_ITEM_SELECTING);
2614 for (i = 0; i < max_page_entries; i++)
2616 if (menu_info[i].type & TYPE_LEAVE_MENU)
2618 void (*menu_callback_function)(void) = menu_info[i].value;
2622 menu_callback_function();
2624 break; // absolutely needed because function changes 'menu_info'!
2631 if (mx || my) // mouse input
2633 x = (mx - mSX) / 32;
2634 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2636 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2638 // move cursor instead of scrolling when already at start/end of list
2639 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2641 else if (dy == +1 * SCROLL_LINE &&
2642 first_entry + num_page_entries == max_page_entries)
2645 // handle scrolling screen one line or page
2647 y + dy > num_page_entries - 1)
2649 boolean redraw = FALSE;
2651 if (ABS(dy) == SCROLL_PAGE)
2652 step = num_page_entries - 1;
2654 if (dy < 0 && first_entry > 0)
2656 // scroll page/line up
2658 first_entry -= step;
2659 if (first_entry < 0)
2664 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2666 // scroll page/line down
2668 first_entry += step;
2669 if (first_entry + num_page_entries > max_page_entries)
2670 first_entry = MAX(0, max_page_entries - num_page_entries);
2677 choice += first_entry - first_entry_store[mode];
2679 if (choice < first_entry)
2681 choice = first_entry;
2683 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2686 else if (choice > first_entry + num_page_entries - 1)
2688 choice = first_entry + num_page_entries - 1;
2690 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2693 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2697 if (choice < first_entry ||
2698 choice > first_entry + num_page_entries - 1)
2699 first_entry += SIGN(dy);
2702 first_entry_store[mode] = first_entry;
2703 choice_store[mode] = choice;
2705 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2707 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2709 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2710 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2718 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2720 if (menu_info[choice].type & menu_navigation_type ||
2721 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2722 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2723 menu_info[choice].type & TYPE_PLAYER)
2724 button = MB_MENU_CHOICE;
2729 // jump to next non-empty menu entry (up or down)
2730 while (first_entry + y > 0 &&
2731 first_entry + y < max_page_entries - 1 &&
2732 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2735 if (!IN_VIS_MENU(x, y))
2737 choice += y - y_old;
2739 if (choice < first_entry)
2740 first_entry = choice;
2741 else if (choice > first_entry + num_page_entries - 1)
2742 first_entry = choice - num_page_entries + 1;
2744 if (first_entry >= 0 &&
2745 first_entry + num_page_entries <= max_page_entries)
2747 first_entry_store[mode] = first_entry;
2749 if (choice < first_entry)
2750 choice = first_entry;
2751 else if (choice > first_entry + num_page_entries - 1)
2752 choice = first_entry + num_page_entries - 1;
2754 choice_store[mode] = choice;
2756 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2758 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2760 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2761 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2768 if (!anyScrollbarGadgetActive() &&
2769 IN_VIS_MENU(x, y) &&
2770 mx < mx_right_border &&
2771 y >= 0 && y < num_page_entries)
2775 if (first_entry + y != choice &&
2776 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2778 PlaySound(SND_MENU_ITEM_ACTIVATING);
2780 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2781 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2783 choice = choice_store[mode] = first_entry + y;
2787 PlaySound(SND_MENU_ITEM_SELECTING);
2789 for (i = 0; menu_info[i].type != 0; i++)
2791 if (menu_info[i].type & TYPE_LEAVE_MENU)
2793 void (*menu_callback_function)(void) = menu_info[i].value;
2797 menu_callback_function();
2799 // absolutely needed because function changes 'menu_info'!
2807 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2809 PlaySound(SND_MENU_ITEM_SELECTING);
2811 // when selecting key headline, execute function for key value change
2812 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2813 menu_info[first_entry + y + 1].type & TYPE_KEY)
2816 // when selecting string value, execute function for list selection
2817 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2818 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2821 // when selecting string value, execute function for text input gadget
2822 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2823 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2826 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2828 void (*menu_callback_function)(void) =
2829 menu_info[first_entry + y].value;
2831 FadeSetFromType(menu_info[first_entry + y].type);
2833 menu_callback_function();
2835 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2837 void (*gadget_callback_function)(void) =
2838 menu_info[first_entry + y].value;
2840 gadget_callback_function();
2842 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2843 menu_info == setup_info)
2845 changeSetupValue(y, first_entry + y, dx);
2851 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2853 menu_info = info_info;
2855 HandleMenuScreen(mx, my, dx, dy, button,
2856 info_mode, num_info_info, max_info_info);
2859 static int getMenuFontSpacing(int spacing_height, int font_nr)
2861 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2863 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2867 static int getMenuTextSpacing(int spacing_height, int font_nr)
2869 return (getMenuFontSpacing(spacing_height, font_nr) +
2870 EXTRA_SPACING(game_status));
2873 static int getMenuTextStep(int spacing_height, int font_nr)
2875 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2878 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2880 int font_title = MENU_INFO_FONT_TITLE;
2881 int font_error = FONT_TEXT_2;
2882 int font_foot = MENU_INFO_FONT_FOOT;
2883 int spacing_title = menu.headline1_spacing_info[info_mode];
2884 int ystep_title = getMenuTextStep(spacing_title, font_title);
2885 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2886 int ystart2 = ystart1 + ystep_title;
2887 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2889 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2891 FadeOut(REDRAW_FIELD);
2896 DrawTextSCentered(ystart1, font_title, text_title);
2897 DrawTextSCentered(ystart2, font_error, text_error);
2899 DrawTextSCentered(ybottom, font_foot,
2900 "Press any key or button for info menu");
2902 FadeIn(REDRAW_FIELD);
2905 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2907 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2908 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2909 int font_title = MENU_INFO_FONT_TITLE;
2910 int font_foot = MENU_INFO_FONT_FOOT;
2911 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2912 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2913 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2914 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2915 int ystep = MENU_SCREEN_INFO_YSTEP;
2916 int element, action, direction;
2924 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2925 infoscreen_step[i] = infoscreen_frame[i] = 0;
2930 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2932 DrawTextSCentered(ybottom, font_foot,
2933 "Press any key or button for next page");
2939 while (helpanim_info[j].element != HELPANIM_LIST_END)
2941 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2946 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2955 j += infoscreen_step[i - start];
2957 element = helpanim_info[j].element;
2958 action = helpanim_info[j].action;
2959 direction = helpanim_info[j].direction;
2962 element = EL_UNKNOWN;
2964 if (action != -1 && direction != -1)
2965 graphic = el_act_dir2img(element, action, direction);
2966 else if (action != -1)
2967 graphic = el_act2img(element, action);
2968 else if (direction != -1)
2969 graphic = el_dir2img(element, direction);
2971 graphic = el2img(element);
2973 delay = helpanim_info[j++].delay;
2978 if (infoscreen_frame[i - start] == 0)
2981 infoscreen_frame[i - start] = delay - 1;
2985 sync_frame = delay - infoscreen_frame[i - start];
2986 infoscreen_frame[i - start]--;
2989 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2991 if (!infoscreen_frame[i - start])
2992 infoscreen_step[i - start] = 0;
2996 if (!infoscreen_frame[i - start])
2997 infoscreen_step[i - start]++;
2998 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3004 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3006 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3007 graphic, sync_frame, USE_MASKING);
3010 DrawInfoScreen_HelpText(element, action, direction, i - start);
3015 redraw_mask |= REDRAW_FIELD;
3020 static char *getHelpText(int element, int action, int direction)
3022 char token[MAX_LINE_LEN];
3024 strcpy(token, element_info[element].token_name);
3027 strcat(token, element_action_info[action].suffix);
3029 if (direction != -1)
3030 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3032 return getHashEntry(helptext_info, token);
3035 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3037 int font_nr = FONT_INFO_ELEMENTS;
3038 int font_width = getFontWidth(font_nr);
3039 int font_height = getFontHeight(font_nr);
3040 int yoffset = (TILEX - 2 * font_height) / 2;
3041 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3042 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3043 int ystep = TILEY + 4;
3044 int pad_left = xstart - SX;
3045 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3046 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3047 int max_lines_per_text = 2;
3050 if (action != -1 && direction != -1) // element.action.direction
3051 text = getHelpText(element, action, direction);
3053 if (text == NULL && action != -1) // element.action
3054 text = getHelpText(element, action, -1);
3056 if (text == NULL && direction != -1) // element.direction
3057 text = getHelpText(element, -1, direction);
3059 if (text == NULL) // base element
3060 text = getHelpText(element, -1, -1);
3062 if (text == NULL) // not found
3063 text = "No description available";
3065 if (strlen(text) <= max_chars_per_line) // only one line of text
3066 ystart += getFontHeight(font_nr) / 2;
3068 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3069 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3070 TRUE, FALSE, FALSE);
3073 static void DrawInfoScreen_TitleScreen(void)
3075 SetGameStatus(GAME_MODE_TITLE);
3080 void HandleInfoScreen_TitleScreen(int button)
3082 HandleTitleScreen(0, 0, 0, 0, button);
3085 static void DrawInfoScreen_Elements(void)
3087 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3089 FadeOut(REDRAW_FIELD);
3094 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3096 FadeIn(REDRAW_FIELD);
3099 void HandleInfoScreen_Elements(int button)
3101 static unsigned int info_delay = 0;
3102 static int num_anims;
3103 static int num_pages;
3105 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3108 if (button == MB_MENU_INITIALIZE)
3110 boolean new_element = TRUE;
3114 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3116 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3118 else if (new_element)
3121 new_element = FALSE;
3125 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3129 if (button == MB_MENU_LEAVE)
3131 PlaySound(SND_MENU_ITEM_SELECTING);
3133 info_mode = INFO_MODE_MAIN;
3138 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3140 if (button != MB_MENU_INITIALIZE)
3142 PlaySound(SND_MENU_ITEM_SELECTING);
3147 if (page >= num_pages)
3149 FadeMenuSoundsAndMusic();
3151 info_mode = INFO_MODE_MAIN;
3158 FadeSetNextScreen();
3160 if (button != MB_MENU_INITIALIZE)
3161 FadeOut(REDRAW_FIELD);
3163 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3165 if (button != MB_MENU_INITIALIZE)
3166 FadeIn(REDRAW_FIELD);
3170 if (DelayReached(&info_delay, GameFrameDelay))
3171 if (page < num_pages)
3172 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3174 PlayMenuSoundIfLoop();
3178 static void DrawInfoScreen_Music(void)
3180 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3182 FadeOut(REDRAW_FIELD);
3189 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3191 FadeIn(REDRAW_FIELD);
3194 void HandleInfoScreen_Music(int button)
3196 static struct MusicFileInfo *list = NULL;
3197 int font_title = MENU_INFO_FONT_TITLE;
3198 int font_head = MENU_INFO_FONT_HEAD;
3199 int font_text = MENU_INFO_FONT_TEXT;
3200 int font_foot = MENU_INFO_FONT_FOOT;
3201 int spacing_title = menu.headline1_spacing_info[info_mode];
3202 int spacing_head = menu.headline2_spacing_info[info_mode];
3203 int ystep_title = getMenuTextStep(spacing_title, font_title);
3204 int ystep_head = getMenuTextStep(spacing_head, font_head);
3205 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3206 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3208 if (button == MB_MENU_INITIALIZE)
3210 list = music_file_info;
3214 FadeMenuSoundsAndMusic();
3219 DrawTextSCentered(ystart, font_title,
3220 "No music info for this level set.");
3222 DrawTextSCentered(ybottom, font_foot,
3223 "Press any key or button for info menu");
3229 if (button == MB_MENU_LEAVE)
3231 PlaySound(SND_MENU_ITEM_SELECTING);
3233 FadeMenuSoundsAndMusic();
3235 info_mode = INFO_MODE_MAIN;
3240 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3242 if (button != MB_MENU_INITIALIZE)
3244 PlaySound(SND_MENU_ITEM_SELECTING);
3252 FadeMenuSoundsAndMusic();
3254 info_mode = INFO_MODE_MAIN;
3260 FadeMenuSoundsAndMusic();
3262 if (list != music_file_info)
3263 FadeSetNextScreen();
3265 if (button != MB_MENU_INITIALIZE)
3266 FadeOut(REDRAW_FIELD);
3273 int sound = list->music;
3275 if (IS_LOOP_SOUND(sound))
3276 PlaySoundLoop(sound);
3280 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3284 int music = list->music;
3286 if (IS_LOOP_MUSIC(music))
3287 PlayMusicLoop(music);
3291 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3294 ystart += ystep_title;
3296 if (!strEqual(list->title, UNKNOWN_NAME))
3298 if (!strEqual(list->title_header, UNKNOWN_NAME))
3300 DrawTextSCentered(ystart, font_head, list->title_header);
3301 ystart += ystep_head;
3304 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3305 ystart += ystep_head;
3308 if (!strEqual(list->artist, UNKNOWN_NAME))
3310 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3311 DrawTextSCentered(ystart, font_head, list->artist_header);
3313 DrawTextSCentered(ystart, font_head, "by");
3315 ystart += ystep_head;
3317 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3318 ystart += ystep_head;
3321 if (!strEqual(list->album, UNKNOWN_NAME))
3323 if (!strEqual(list->album_header, UNKNOWN_NAME))
3324 DrawTextSCentered(ystart, font_head, list->album_header);
3326 DrawTextSCentered(ystart, font_head, "from the album");
3328 ystart += ystep_head;
3330 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3331 ystart += ystep_head;
3334 if (!strEqual(list->year, UNKNOWN_NAME))
3336 if (!strEqual(list->year_header, UNKNOWN_NAME))
3337 DrawTextSCentered(ystart, font_head, list->year_header);
3339 DrawTextSCentered(ystart, font_head, "from the year");
3341 ystart += ystep_head;
3343 DrawTextFCentered(ystart, font_text, "%s", list->year);
3344 ystart += ystep_head;
3347 DrawTextSCentered(ybottom, FONT_TEXT_4,
3348 "Press any key or button for next page");
3350 if (button != MB_MENU_INITIALIZE)
3351 FadeIn(REDRAW_FIELD);
3354 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3355 PlaySoundLoop(list->music);
3358 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3360 int font_title = MENU_INFO_FONT_TITLE;
3361 int font_head = MENU_INFO_FONT_HEAD;
3362 int font_text = MENU_INFO_FONT_TEXT;
3363 int font_foot = MENU_INFO_FONT_FOOT;
3364 int spacing_title = menu.headline1_spacing_info[info_mode];
3365 int spacing_head = menu.headline2_spacing_info[info_mode];
3366 int spacing_para = menu.paragraph_spacing_info[info_mode];
3367 int spacing_line = menu.line_spacing_info[info_mode];
3368 int ystep_title = getMenuTextStep(spacing_title, font_title);
3369 int ystep_head = getMenuTextStep(spacing_head, font_head);
3370 int ystep_para = getMenuTextStep(spacing_para, font_text);
3371 int ystep_line = getMenuTextStep(spacing_line, font_text);
3372 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3373 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3378 DrawTextSCentered(ystart, font_title, "Credits:");
3379 ystart += ystep_title;
3383 DrawTextSCentered(ystart, font_head,
3384 "Special thanks to");
3385 ystart += ystep_head;
3386 DrawTextSCentered(ystart, font_text,
3388 ystart += ystep_head;
3389 DrawTextSCentered(ystart, font_head,
3391 ystart += ystep_head;
3392 DrawTextSCentered(ystart, font_text,
3393 "\"Boulder Dash\"");
3394 ystart += ystep_head;
3395 DrawTextSCentered(ystart, font_head,
3397 ystart += ystep_head;
3398 DrawTextSCentered(ystart, font_text,
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_head,
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_text,
3405 "First Star Software");
3407 else if (screen_nr == 1)
3409 DrawTextSCentered(ystart, font_head,
3410 "Special thanks to");
3411 ystart += ystep_head;
3412 DrawTextSCentered(ystart, font_text,
3413 "Klaus Heinz & Volker Wertich");
3414 ystart += ystep_head;
3415 DrawTextSCentered(ystart, font_head,
3417 ystart += ystep_head;
3418 DrawTextSCentered(ystart, font_text,
3419 "\"Emerald Mine\"");
3420 ystart += ystep_head;
3421 DrawTextSCentered(ystart, font_head,
3423 ystart += ystep_head;
3424 DrawTextSCentered(ystart, font_text,
3426 ystart += ystep_head;
3427 DrawTextSCentered(ystart, font_head,
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_text,
3433 else if (screen_nr == 2)
3435 DrawTextSCentered(ystart, font_head,
3436 "Special thanks to");
3437 ystart += ystep_head;
3438 DrawTextSCentered(ystart, font_text,
3439 "Michael Stopp & Philip Jespersen");
3440 ystart += ystep_head;
3441 DrawTextSCentered(ystart, font_head,
3443 ystart += ystep_head;
3444 DrawTextSCentered(ystart, font_text,
3446 ystart += ystep_head;
3447 DrawTextSCentered(ystart, font_head,
3449 ystart += ystep_head;
3450 DrawTextSCentered(ystart, font_text,
3452 ystart += ystep_head;
3453 DrawTextSCentered(ystart, font_head,
3455 ystart += ystep_head;
3456 DrawTextSCentered(ystart, font_text,
3457 "Digital Integration");
3459 else if (screen_nr == 3)
3461 DrawTextSCentered(ystart, font_head,
3462 "Special thanks to");
3463 ystart += ystep_head;
3464 DrawTextSCentered(ystart, font_text,
3465 "Hiroyuki Imabayashi");
3466 ystart += ystep_head;
3467 DrawTextSCentered(ystart, font_head,
3469 ystart += ystep_head;
3470 DrawTextSCentered(ystart, font_text,
3472 ystart += ystep_head;
3473 DrawTextSCentered(ystart, font_head,
3475 ystart += ystep_head;
3476 DrawTextSCentered(ystart, font_text,
3478 ystart += ystep_head;
3479 DrawTextSCentered(ystart, font_head,
3481 ystart += ystep_head;
3482 DrawTextSCentered(ystart, font_text,
3485 else if (screen_nr == 4)
3487 DrawTextSCentered(ystart, font_head,
3488 "Special thanks to");
3489 ystart += ystep_head;
3490 DrawTextSCentered(ystart, font_text,
3492 ystart += ystep_head;
3493 DrawTextSCentered(ystart, font_head,
3495 ystart += ystep_head;
3496 DrawTextSCentered(ystart, font_text,
3497 "J\xfcrgen Bonhagen");
3498 ystart += ystep_head;
3499 DrawTextSCentered(ystart, font_head,
3500 "for the continuous creation");
3501 ystart += ystep_line;
3502 DrawTextSCentered(ystart, font_head,
3503 "of outstanding level sets");
3505 else if (screen_nr == 5)
3507 DrawTextSCentered(ystart, font_head,
3509 ystart += ystep_head;
3510 DrawTextSCentered(ystart, font_text,
3512 ystart += ystep_head;
3513 DrawTextSCentered(ystart, font_head,
3514 "for ideas and inspiration by");
3515 ystart += ystep_head;
3516 DrawTextSCentered(ystart, font_text,
3518 ystart += ystep_para;
3520 DrawTextSCentered(ystart, font_head,
3522 ystart += ystep_head;
3523 DrawTextSCentered(ystart, font_text,
3525 ystart += ystep_head;
3526 DrawTextSCentered(ystart, font_head,
3527 "for ideas and inspiration by");
3528 ystart += ystep_head;
3529 DrawTextSCentered(ystart, font_text,
3532 else if (screen_nr == 6)
3534 DrawTextSCentered(ystart, font_head,
3536 ystart += ystep_head;
3537 DrawTextSCentered(ystart, font_text,
3539 ystart += ystep_head;
3540 DrawTextSCentered(ystart, font_head,
3541 "for the code base used for the");
3542 ystart += ystep_line;
3543 DrawTextSCentered(ystart, font_head,
3544 "native Emerald Mine engine");
3546 else if (screen_nr == 7)
3548 DrawTextSCentered(ystart, font_head,
3550 ystart += ystep_head;
3551 DrawTextSCentered(ystart, font_text,
3553 ystart += ystep_head;
3554 DrawTextSCentered(ystart, font_head,
3555 "for the initial DOS port");
3556 ystart += ystep_para;
3558 DrawTextSCentered(ystart, font_head,
3560 ystart += ystep_head;
3561 DrawTextSCentered(ystart, font_text,
3563 ystart += ystep_head;
3564 DrawTextSCentered(ystart, font_head,
3565 "for some additional toons");
3567 else if (screen_nr == 8)
3569 DrawTextSCentered(ystart, font_head,
3570 "And not to forget:");
3571 ystart += ystep_head;
3572 DrawTextSCentered(ystart, font_head,
3574 ystart += ystep_head;
3575 DrawTextSCentered(ystart, font_text,
3576 "All those who contributed");
3577 ystart += ystep_line;
3578 DrawTextSCentered(ystart, font_text,
3579 "levels to this game");
3580 ystart += ystep_line;
3581 DrawTextSCentered(ystart, font_text,
3585 DrawTextSCentered(ybottom, font_foot,
3586 "Press any key or button for next page");
3589 static void DrawInfoScreen_Credits(void)
3591 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3593 FadeMenuSoundsAndMusic();
3595 FadeOut(REDRAW_FIELD);
3597 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3599 FadeIn(REDRAW_FIELD);
3602 void HandleInfoScreen_Credits(int button)
3604 static int screen_nr = 0;
3605 int num_screens = 9;
3607 if (button == MB_MENU_INITIALIZE)
3611 // DrawInfoScreen_CreditsScreen(screen_nr);
3614 if (button == MB_MENU_LEAVE)
3616 PlaySound(SND_MENU_ITEM_SELECTING);
3618 info_mode = INFO_MODE_MAIN;
3623 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3625 if (button != MB_MENU_INITIALIZE)
3627 PlaySound(SND_MENU_ITEM_SELECTING);
3632 if (screen_nr >= num_screens)
3634 FadeMenuSoundsAndMusic();
3636 info_mode = INFO_MODE_MAIN;
3643 FadeSetNextScreen();
3645 if (button != MB_MENU_INITIALIZE)
3646 FadeOut(REDRAW_FIELD);
3648 DrawInfoScreen_CreditsScreen(screen_nr);
3650 if (button != MB_MENU_INITIALIZE)
3651 FadeIn(REDRAW_FIELD);
3655 PlayMenuSoundIfLoop();
3659 static void DrawInfoScreen_Program(void)
3661 int font_title = MENU_INFO_FONT_TITLE;
3662 int font_head = MENU_INFO_FONT_HEAD;
3663 int font_text = MENU_INFO_FONT_TEXT;
3664 int font_foot = MENU_INFO_FONT_FOOT;
3665 int spacing_title = menu.headline1_spacing_info[info_mode];
3666 int spacing_head = menu.headline2_spacing_info[info_mode];
3667 int spacing_para = menu.paragraph_spacing_info[info_mode];
3668 int spacing_line = menu.line_spacing_info[info_mode];
3669 int ystep_title = getMenuTextStep(spacing_title, font_title);
3670 int ystep_head = getMenuTextStep(spacing_head, font_head);
3671 int ystep_para = getMenuTextStep(spacing_para, font_text);
3672 int ystep_line = getMenuTextStep(spacing_line, font_text);
3673 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3674 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3676 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3678 FadeOut(REDRAW_FIELD);
3683 DrawTextSCentered(ystart, font_title, "Program Information:");
3684 ystart += ystep_title;
3686 DrawTextSCentered(ystart, font_head,
3687 "This game is Freeware!");
3688 ystart += ystep_head;
3689 DrawTextSCentered(ystart, font_head,
3690 "If you like it, send e-mail to:");
3691 ystart += ystep_head;
3692 DrawTextSCentered(ystart, font_text,
3693 setup.internal.program_email);
3694 ystart += ystep_para;
3696 DrawTextSCentered(ystart, font_head,
3697 "More information and levels:");
3698 ystart += ystep_head;
3699 DrawTextSCentered(ystart, font_text,
3700 setup.internal.program_website);
3701 ystart += ystep_para;
3703 DrawTextSCentered(ystart, font_head,
3704 "If you have created new levels,");
3705 ystart += ystep_line;
3706 DrawTextSCentered(ystart, font_head,
3707 "send them to me to include them!");
3708 ystart += ystep_head;
3709 DrawTextSCentered(ystart, font_head,
3712 DrawTextSCentered(ybottom, font_foot,
3713 "Press any key or button for info menu");
3715 FadeIn(REDRAW_FIELD);
3718 void HandleInfoScreen_Program(int button)
3720 if (button == MB_MENU_LEAVE)
3722 PlaySound(SND_MENU_ITEM_SELECTING);
3724 info_mode = INFO_MODE_MAIN;
3729 else if (button == MB_MENU_CHOICE)
3731 PlaySound(SND_MENU_ITEM_SELECTING);
3733 FadeMenuSoundsAndMusic();
3735 info_mode = INFO_MODE_MAIN;
3740 PlayMenuSoundIfLoop();
3744 static void DrawInfoScreen_Version(void)
3746 int font_title = MENU_INFO_FONT_TITLE;
3747 int font_head = MENU_INFO_FONT_HEAD;
3748 int font_text = MENU_INFO_FONT_TEXT;
3749 int font_foot = MENU_INFO_FONT_FOOT;
3750 int spacing_title = menu.headline1_spacing_info[info_mode];
3751 int spacing_head = menu.headline2_spacing_info[info_mode];
3752 int spacing_para = menu.paragraph_spacing_info[info_mode];
3753 int spacing_line = menu.line_spacing_info[info_mode];
3754 int xstep = getFontWidth(font_text);
3755 int ystep_title = getMenuTextStep(spacing_title, font_title);
3756 int ystep_head = getMenuTextStep(spacing_head, font_head);
3757 int ystep_para = getMenuTextStep(spacing_para, font_text);
3758 int ystep_line = getMenuTextStep(spacing_line, font_text);
3759 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3760 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3761 int xstart1 = mSX - SX + 2 * xstep;
3762 int xstart2 = mSX - SX + 18 * xstep;
3763 int xstart3 = mSX - SX + 28 * xstep;
3764 SDL_version sdl_version_compiled;
3765 const SDL_version *sdl_version_linked;
3766 int driver_name_len = 10;
3767 SDL_version sdl_version_linked_ext;
3768 const char *driver_name = NULL;
3770 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3772 FadeOut(REDRAW_FIELD);
3777 DrawTextSCentered(ystart, font_title, "Version Information:");
3778 ystart += ystep_title;
3780 DrawTextF(xstart1, ystart, font_head, "Name");
3781 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3782 ystart += ystep_line;
3784 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3786 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3787 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3788 ystart += ystep_line;
3790 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3791 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3792 ystart += ystep_line;
3796 DrawTextF(xstart1, ystart, font_head, "Version");
3797 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3798 ystart += ystep_line;
3801 DrawTextF(xstart1, ystart, font_head, "Platform");
3802 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3804 PLATFORM_XX_BIT_STRING);
3805 ystart += ystep_line;
3807 DrawTextF(xstart1, ystart, font_head, "Target");
3808 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3809 ystart += ystep_line;
3811 DrawTextF(xstart1, ystart, font_head, "Source date");
3812 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3813 ystart += ystep_line;
3815 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3816 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3817 ystart += ystep_para;
3819 DrawTextF(xstart1, ystart, font_head, "Library");
3820 DrawTextF(xstart2, ystart, font_head, "compiled");
3821 DrawTextF(xstart3, ystart, font_head, "linked");
3822 ystart += ystep_head;
3824 SDL_VERSION(&sdl_version_compiled);
3825 SDL_GetVersion(&sdl_version_linked_ext);
3826 sdl_version_linked = &sdl_version_linked_ext;
3828 DrawTextF(xstart1, ystart, font_text, "SDL");
3829 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3830 sdl_version_compiled.major,
3831 sdl_version_compiled.minor,
3832 sdl_version_compiled.patch);
3833 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3834 sdl_version_linked->major,
3835 sdl_version_linked->minor,
3836 sdl_version_linked->patch);
3837 ystart += ystep_line;
3839 SDL_IMAGE_VERSION(&sdl_version_compiled);
3840 sdl_version_linked = IMG_Linked_Version();
3842 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3843 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3844 sdl_version_compiled.major,
3845 sdl_version_compiled.minor,
3846 sdl_version_compiled.patch);
3847 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3848 sdl_version_linked->major,
3849 sdl_version_linked->minor,
3850 sdl_version_linked->patch);
3851 ystart += ystep_line;
3853 SDL_MIXER_VERSION(&sdl_version_compiled);
3854 sdl_version_linked = Mix_Linked_Version();
3856 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3857 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3858 sdl_version_compiled.major,
3859 sdl_version_compiled.minor,
3860 sdl_version_compiled.patch);
3861 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3862 sdl_version_linked->major,
3863 sdl_version_linked->minor,
3864 sdl_version_linked->patch);
3865 ystart += ystep_line;
3867 SDL_NET_VERSION(&sdl_version_compiled);
3868 sdl_version_linked = SDLNet_Linked_Version();
3870 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3871 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3872 sdl_version_compiled.major,
3873 sdl_version_compiled.minor,
3874 sdl_version_compiled.patch);
3875 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3876 sdl_version_linked->major,
3877 sdl_version_linked->minor,
3878 sdl_version_linked->patch);
3879 ystart += ystep_para;
3881 DrawTextF(xstart1, ystart, font_head, "Driver");
3882 DrawTextF(xstart2, ystart, font_head, "Requested");
3883 DrawTextF(xstart3, ystart, font_head, "Used");
3884 ystart += ystep_head;
3887 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3889 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3890 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3891 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3892 ystart += ystep_line;
3895 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3897 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3898 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3899 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3900 ystart += ystep_line;
3903 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3905 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3906 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3907 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3909 DrawTextSCentered(ybottom, font_foot,
3910 "Press any key or button for info menu");
3912 FadeIn(REDRAW_FIELD);
3915 void HandleInfoScreen_Version(int button)
3917 if (button == MB_MENU_LEAVE)
3919 PlaySound(SND_MENU_ITEM_SELECTING);
3921 info_mode = INFO_MODE_MAIN;
3926 else if (button == MB_MENU_CHOICE)
3928 PlaySound(SND_MENU_ITEM_SELECTING);
3930 FadeMenuSoundsAndMusic();
3932 info_mode = INFO_MODE_MAIN;
3937 PlayMenuSoundIfLoop();
3941 static void DrawInfoScreen_LevelSet(void)
3943 struct TitleMessageInfo *tmi = &readme;
3944 char *filename = getLevelSetInfoFilename();
3945 char *title = "Level Set Information:";
3946 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3947 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3949 if (filename == NULL)
3951 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3956 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3958 FadeOut(REDRAW_FIELD);
3963 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3965 // if x position set to "-1", automatically determine by playfield width
3967 tmi->x = SXSIZE / 2;
3969 // if y position set to "-1", use static default value
3973 // if width set to "-1", automatically determine by playfield width
3974 if (tmi->width == -1)
3975 tmi->width = SXSIZE - 2 * TILEX;
3977 // if height set to "-1", automatically determine by playfield height
3978 if (tmi->height == -1)
3979 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3981 // if chars set to "-1", automatically determine by text and font width
3982 if (tmi->chars == -1)
3983 tmi->chars = tmi->width / getFontWidth(tmi->font);
3985 tmi->width = tmi->chars * getFontWidth(tmi->font);
3987 // if lines set to "-1", automatically determine by text and font height
3988 if (tmi->lines == -1)
3989 tmi->lines = tmi->height / getFontHeight(tmi->font);
3991 tmi->height = tmi->lines * getFontHeight(tmi->font);
3993 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3994 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3995 tmi->autowrap, tmi->centered, tmi->parse_comments);
3997 DrawTextSCentered(ybottom, FONT_TEXT_4,
3998 "Press any key or button for info menu");
4000 FadeIn(REDRAW_FIELD);
4003 static void HandleInfoScreen_LevelSet(int button)
4005 if (button == MB_MENU_LEAVE)
4007 PlaySound(SND_MENU_ITEM_SELECTING);
4009 info_mode = INFO_MODE_MAIN;
4014 else if (button == MB_MENU_CHOICE)
4016 PlaySound(SND_MENU_ITEM_SELECTING);
4018 FadeMenuSoundsAndMusic();
4020 info_mode = INFO_MODE_MAIN;
4025 PlayMenuSoundIfLoop();
4029 static void DrawInfoScreen(void)
4031 if (info_mode == INFO_MODE_TITLE)
4032 DrawInfoScreen_TitleScreen();
4033 else if (info_mode == INFO_MODE_ELEMENTS)
4034 DrawInfoScreen_Elements();
4035 else if (info_mode == INFO_MODE_MUSIC)
4036 DrawInfoScreen_Music();
4037 else if (info_mode == INFO_MODE_CREDITS)
4038 DrawInfoScreen_Credits();
4039 else if (info_mode == INFO_MODE_PROGRAM)
4040 DrawInfoScreen_Program();
4041 else if (info_mode == INFO_MODE_VERSION)
4042 DrawInfoScreen_Version();
4043 else if (info_mode == INFO_MODE_LEVELSET)
4044 DrawInfoScreen_LevelSet();
4046 DrawInfoScreen_Main();
4048 if (info_mode != INFO_MODE_MAIN &&
4049 info_mode != INFO_MODE_TITLE &&
4050 info_mode != INFO_MODE_MUSIC)
4051 PlayMenuSoundsAndMusic();
4054 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4056 if (info_mode == INFO_MODE_TITLE)
4057 HandleInfoScreen_TitleScreen(button);
4058 else if (info_mode == INFO_MODE_ELEMENTS)
4059 HandleInfoScreen_Elements(button);
4060 else if (info_mode == INFO_MODE_MUSIC)
4061 HandleInfoScreen_Music(button);
4062 else if (info_mode == INFO_MODE_CREDITS)
4063 HandleInfoScreen_Credits(button);
4064 else if (info_mode == INFO_MODE_PROGRAM)
4065 HandleInfoScreen_Program(button);
4066 else if (info_mode == INFO_MODE_VERSION)
4067 HandleInfoScreen_Version(button);
4068 else if (info_mode == INFO_MODE_LEVELSET)
4069 HandleInfoScreen_LevelSet(button);
4071 HandleInfoScreen_Main(mx, my, dx, dy, button);
4075 // ============================================================================
4076 // rename player API functions
4077 // ============================================================================
4079 struct ApiRenamePlayerThreadData
4085 static void *CreateThreadData_ApiRenamePlayer(void)
4087 struct ApiRenamePlayerThreadData *data =
4088 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4090 data->player_name = getStringCopy(setup.player_name);
4091 data->player_uuid = getStringCopy(setup.player_uuid);
4096 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4098 struct ApiRenamePlayerThreadData *data = data_raw;
4100 checked_free(data->player_name);
4101 checked_free(data->player_uuid);
4105 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4108 struct ApiRenamePlayerThreadData *data = data_raw;
4109 char *player_name_raw = data->player_name;
4110 char *player_uuid_raw = data->player_uuid;
4112 request->hostname = setup.api_server_hostname;
4113 request->port = API_SERVER_PORT;
4114 request->method = API_SERVER_METHOD;
4115 request->uri = API_SERVER_URI_RENAME;
4117 char *player_name = getEscapedJSON(player_name_raw);
4118 char *player_uuid = getEscapedJSON(player_uuid_raw);
4120 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4123 " \"game_version\": \"%s\",\n"
4124 " \"game_platform\": \"%s\",\n"
4125 " \"name\": \"%s\",\n"
4126 " \"uuid\": \"%s\"\n"
4128 getPasswordJSON(setup.api_server_password),
4129 getProgramRealVersionString(),
4130 getProgramPlatformString(),
4134 checked_free(player_name);
4135 checked_free(player_uuid);
4137 ConvertHttpRequestBodyToServerEncoding(request);
4142 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4145 // nothing to do here
4148 #if defined(PLATFORM_EMSCRIPTEN)
4149 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4150 void *buffer, unsigned int size)
4152 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4154 if (response != NULL)
4156 HandleResponse_ApiRenamePlayer(response, data_raw);
4158 checked_free(response);
4162 Error("server response too large to handle (%d bytes)", size);
4165 FreeThreadData_ApiRenamePlayer(data_raw);
4168 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4169 int code, const char *status)
4171 Error("server failed to handle request: %d %s", code, status);
4173 FreeThreadData_ApiRenamePlayer(data_raw);
4176 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4177 int bytes, int size)
4179 // nothing to do here
4182 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4185 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4187 FreeThreadData_ApiRenamePlayer(data_raw);
4192 emscripten_async_wget2_data(request->uri,
4197 Emscripten_ApiRenamePlayer_Loaded,
4198 Emscripten_ApiRenamePlayer_Failed,
4199 Emscripten_ApiRenamePlayer_Progress);
4204 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4205 struct HttpResponse *response,
4208 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4211 if (!DoHttpRequest(request, response))
4213 Error("HTTP request failed: %s", GetHttpError());
4218 if (!HTTP_SUCCESS(response->status_code))
4220 Error("server failed to handle request: %d %s",
4221 response->status_code,
4222 response->status_text);
4227 HandleResponse_ApiRenamePlayer(response, data_raw);
4230 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4231 struct HttpResponse *response,
4234 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4236 FreeThreadData_ApiRenamePlayer(data_raw);
4240 static int ApiRenamePlayerThread(void *data_raw)
4242 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4243 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4245 program.api_thread_count++;
4247 #if defined(PLATFORM_EMSCRIPTEN)
4248 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4250 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4253 program.api_thread_count--;
4255 checked_free(request);
4256 checked_free(response);
4261 static void ApiRenamePlayerAsThread(void)
4263 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4265 ExecuteAsThread(ApiRenamePlayerThread,
4266 "ApiRenamePlayer", data,
4267 "rename player on server");
4271 // ============================================================================
4272 // reset player UUID API functions
4273 // ============================================================================
4275 struct ApiResetUUIDThreadData
4278 char *player_uuid_old;
4279 char *player_uuid_new;
4282 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4284 struct ApiResetUUIDThreadData *data =
4285 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4287 data->player_name = getStringCopy(setup.player_name);
4288 data->player_uuid_old = getStringCopy(setup.player_uuid);
4289 data->player_uuid_new = getStringCopy(uuid_new);
4294 static void FreeThreadData_ApiResetUUID(void *data_raw)
4296 struct ApiResetUUIDThreadData *data = data_raw;
4298 checked_free(data->player_name);
4299 checked_free(data->player_uuid_old);
4300 checked_free(data->player_uuid_new);
4304 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4307 struct ApiResetUUIDThreadData *data = data_raw;
4308 char *player_name_raw = data->player_name;
4309 char *player_uuid_old_raw = data->player_uuid_old;
4310 char *player_uuid_new_raw = data->player_uuid_new;
4312 request->hostname = setup.api_server_hostname;
4313 request->port = API_SERVER_PORT;
4314 request->method = API_SERVER_METHOD;
4315 request->uri = API_SERVER_URI_RESETUUID;
4317 char *player_name = getEscapedJSON(player_name_raw);
4318 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4319 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4321 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4324 " \"game_version\": \"%s\",\n"
4325 " \"game_platform\": \"%s\",\n"
4326 " \"name\": \"%s\",\n"
4327 " \"uuid_old\": \"%s\",\n"
4328 " \"uuid_new\": \"%s\"\n"
4330 getPasswordJSON(setup.api_server_password),
4331 getProgramRealVersionString(),
4332 getProgramPlatformString(),
4337 checked_free(player_name);
4338 checked_free(player_uuid_old);
4339 checked_free(player_uuid_new);
4341 ConvertHttpRequestBodyToServerEncoding(request);
4346 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4349 struct ApiResetUUIDThreadData *data = data_raw;
4351 // upgrade player UUID in server setup file
4352 setup.player_uuid = getStringCopy(data->player_uuid_new);
4353 setup.player_version = 2;
4355 SaveSetup_ServerSetup();
4358 #if defined(PLATFORM_EMSCRIPTEN)
4359 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4360 void *buffer, unsigned int size)
4362 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4364 if (response != NULL)
4366 HandleResponse_ApiResetUUID(response, data_raw);
4368 checked_free(response);
4372 Error("server response too large to handle (%d bytes)", size);
4375 FreeThreadData_ApiResetUUID(data_raw);
4378 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4379 int code, const char *status)
4381 Error("server failed to handle request: %d %s", code, status);
4383 FreeThreadData_ApiResetUUID(data_raw);
4386 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4387 int bytes, int size)
4389 // nothing to do here
4392 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4395 if (!SetRequest_ApiResetUUID(request, data_raw))
4397 FreeThreadData_ApiResetUUID(data_raw);
4402 emscripten_async_wget2_data(request->uri,
4407 Emscripten_ApiResetUUID_Loaded,
4408 Emscripten_ApiResetUUID_Failed,
4409 Emscripten_ApiResetUUID_Progress);
4414 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4415 struct HttpResponse *response,
4418 if (!SetRequest_ApiResetUUID(request, data_raw))
4421 if (!DoHttpRequest(request, response))
4423 Error("HTTP request failed: %s", GetHttpError());
4428 if (!HTTP_SUCCESS(response->status_code))
4430 Error("server failed to handle request: %d %s",
4431 response->status_code,
4432 response->status_text);
4437 HandleResponse_ApiResetUUID(response, data_raw);
4440 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4441 struct HttpResponse *response,
4444 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4446 FreeThreadData_ApiResetUUID(data_raw);
4450 static int ApiResetUUIDThread(void *data_raw)
4452 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4453 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4455 program.api_thread_count++;
4457 #if defined(PLATFORM_EMSCRIPTEN)
4458 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4460 ApiResetUUID_HttpRequest(request, response, data_raw);
4463 program.api_thread_count--;
4465 checked_free(request);
4466 checked_free(response);
4471 static void ApiResetUUIDAsThread(char *uuid_new)
4473 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4475 ExecuteAsThread(ApiResetUUIDThread,
4476 "ApiResetUUID", data,
4477 "reset UUID on server");
4481 // ============================================================================
4482 // type name functions
4483 // ============================================================================
4485 static TreeInfo *type_name_node = NULL;
4486 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4487 static int type_name_nr = 0;
4489 static int getPlayerNameColor(char *name)
4491 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4494 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4497 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4498 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4499 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4500 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4501 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4502 int font_width = getFontWidth(font_nr);
4504 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4506 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4508 pos->width = strlen(text) * font_width;
4509 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4511 DrawText(sx, sy, text, font_nr);
4514 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4516 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4518 *pos = *mci->pos_input;
4520 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4522 TreeInfo *ti = player_name_current;
4523 int first_entry = ti->cl_first;
4524 int entry_pos = first_entry + ti->cl_cursor;
4525 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4526 int xpos = MENU_SCREEN_START_XPOS;
4527 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4529 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4530 type_name_nr = entry_pos;
4532 strcpy(name, type_name_node->name);
4536 pos->width = MAX_PLAYER_NAME_LEN * 32;
4540 type_name_nr = user.nr;
4542 strcpy(name, setup.player_name);
4545 strcpy(type_name_last, name);
4547 if (strEqual(name, EMPTY_PLAYER_NAME))
4550 *xpos = strlen(name);
4553 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4555 // change name of edited user in global list of user names
4556 setString(&global.user_names[type_name_nr], name);
4558 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4560 TreeInfo *node = type_name_node;
4562 // change name of edited user in local menu tree structure
4563 setString(&node->name, name);
4564 setString(&node->name_sorting, name);
4566 node->color = getPlayerNameColor(name);
4567 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4571 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4574 boolean reset_setup = strEqual(name, "");
4575 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4576 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4579 strcpy(name, type_name_last);
4581 if (strEqual(name, ""))
4582 strcpy(name, EMPTY_PLAYER_NAME);
4584 setTypeNameValues_Name(name, pos);
4586 // if player name not changed, no further action required
4587 if (strEqual(name, type_name_last))
4590 // redraw player name before (possibly) opening request dialogs
4591 drawTypeNameText(name, pos, FALSE);
4593 int last_user_nr = user.nr;
4595 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4597 // save setup of currently active user (may differ from edited user)
4600 // temporarily change active user to edited user
4601 user.nr = type_name_nr;
4604 Request("Use current setup values for the new player?", REQ_ASK))
4606 // use current setup values for new user, but create new player UUID
4607 setup.player_uuid = getStringCopy(getUUID());
4611 // load setup for existing user (or start with defaults for new user)
4616 char *setup_filename = getSetupFilename();
4617 boolean setup_exists = fileExists(setup_filename);
4619 // change name of edited user in setup structure
4620 strcpy(setup.player_name, name);
4622 // save setup of edited user
4625 // change name of edited user on score server
4626 ApiRenamePlayerAsThread();
4628 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4632 if (Request("Reset setup values for this player?", REQ_ASK))
4634 // remove setup config file
4635 unlink(setup_filename);
4637 // set player name to default player name
4640 // update player name used by name typing functions
4641 strcpy(name, setup.player_name);
4643 setTypeNameValues_Name(name, pos);
4646 else if (remove_user && type_name_nr != 0)
4648 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4650 char *user_dir = getUserGameDataDir();
4651 char *user_dir_removed =
4652 getStringCat3WithSeparator(user_dir, "REMOVED",
4653 getCurrentTimestamp(), ".");
4655 if (rename(user_dir, user_dir_removed) != 0)
4656 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4658 checked_free(user_dir_removed);
4661 else if (create_user && type_name_nr != 0 && !setup_exists)
4663 if (Request("Create empty level set for the new player?", REQ_ASK))
4665 char *levelset_subdir = getNewUserLevelSubdir();
4667 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4669 AddUserLevelSetToLevelInfo(levelset_subdir);
4671 LevelDirTree *leveldir_current_last = leveldir_current;
4673 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4676 // set level number of newly created level set to default value
4677 LoadLevelSetup_SeriesInfo();
4679 // set newly created level set as current level set for new user
4680 SaveLevelSetup_LastSeries();
4681 SaveLevelSetup_SeriesInfo();
4683 leveldir_current = leveldir_current_last;
4687 Request("Creating new level set failed!", REQ_CONFIRM);
4692 // restore currently active user
4693 user.nr = last_user_nr;
4695 // restore setup of currently active user
4698 // restore last level set of currently active user
4699 LoadLevelSetup_LastSeries();
4700 LoadLevelSetup_SeriesInfo();
4704 static void HandleTypeNameExt(boolean initialize, Key key)
4706 static struct TextPosInfo pos_name = { 0 };
4707 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4708 static int xpos = 0;
4709 struct TextPosInfo *pos = &pos_name;
4710 char key_char = getValidConfigValueChar(getCharFromKey(key));
4711 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4712 boolean active = TRUE;
4716 getTypeNameValues(name, pos, &xpos);
4718 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4719 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4721 StartTextInput(sx, sy, pos->width, pos->height);
4723 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4725 name[xpos] = key_char;
4730 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4736 else if (key == KSYM_Return || key == KSYM_Escape)
4738 boolean changed = (key == KSYM_Return);
4742 setTypeNameValues(name, pos, changed);
4747 drawTypeNameText(name, pos, active);
4751 SetGameStatus(game_status_last_screen);
4753 if (game_status == GAME_MODE_MAIN)
4754 InitializeMainControls();
4758 static void DrawTypeName(void)
4760 HandleTypeNameExt(TRUE, 0);
4763 void HandleTypeName(Key key)
4765 HandleTypeNameExt(FALSE, key);
4769 // ============================================================================
4770 // tree menu functions
4771 // ============================================================================
4773 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4775 if (game_status != GAME_MODE_SETUP ||
4776 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4779 int max_text_size = 0;
4782 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4783 max_text_size = MAX(max_text_size, strlen(node->name));
4785 int num_entries = numTreeInfoInGroup(ti);
4786 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4787 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4788 int text_width = max_text_size * getFontWidth(font_nr);
4789 int button_width = SC_MENUBUTTON_XSIZE;
4790 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4791 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4792 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4793 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4794 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4795 int align_xoffset = MAX(0, align_xoffset_raw);
4797 return align_xoffset;
4800 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4802 if (game_status != GAME_MODE_SETUP ||
4803 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4806 int num_entries = numTreeInfoInGroup(ti);
4807 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4808 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4809 int font_height = getFontHeight(font_nr);
4810 int text_height = font_height * num_page_entries;
4811 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4812 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4813 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4814 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4815 int align_yoffset = MAX(0, align_yoffset_raw);
4817 return align_yoffset;
4820 static void DrawChooseTree(TreeInfo **ti_ptr)
4822 int fade_mask = REDRAW_FIELD;
4825 fade_mask = REDRAW_ALL;
4827 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4829 if (game_status == GAME_MODE_SETUP)
4833 else // GAME_MODE_LEVELS
4835 SetGameStatus(GAME_MODE_MAIN);
4845 FreeScreenGadgets();
4846 CreateScreenGadgets();
4848 if (game_status != game_status_last_screen)
4849 FadeMenuSoundsAndMusic();
4853 // needed if different viewport properties defined for this screen
4854 ChangeViewportPropertiesIfNeeded();
4856 if (game_status == GAME_MODE_NAMES)
4857 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4858 else if (game_status == GAME_MODE_LEVELNR)
4859 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4860 else if (game_status == GAME_MODE_LEVELS)
4861 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4862 else if (game_status == GAME_MODE_SCORES)
4863 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4867 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4869 MapScreenTreeGadgets(*ti_ptr);
4870 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4872 DrawMaskedBorder(fade_mask);
4874 if (game_status != game_status_last_screen)
4875 PlayMenuSoundsAndMusic();
4880 static int getChooseTreeFont(TreeInfo *node, boolean active)
4882 if (game_status == GAME_MODE_SCORES)
4883 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4885 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4888 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4890 int num_entries = numTreeInfoInGroup(ti);
4891 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4892 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4893 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4894 int first_entry = ti->cl_first;
4895 int entry_pos = first_entry + y;
4896 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4897 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4898 int font_nr = getChooseTreeFont(node, active);
4899 int font_xoffset = getFontDrawOffsetX(font_nr);
4900 int xpos = MENU_SCREEN_START_XPOS;
4901 int ypos = MENU_SCREEN_START_YPOS + y;
4902 int startdx = xpos * 32;
4903 int startdy = ypos * 32;
4904 int startx = amSX + startdx;
4905 int starty = amSY + startdy;
4906 int startx_text = startx + font_xoffset;
4907 int endx_text = amSX + screen_width;
4908 int max_text_size = endx_text - startx_text;
4909 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4910 char buffer[max_buffer_len + 1];
4912 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4914 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4915 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4916 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4917 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4918 int font_size_1 = getFontWidth(font_nr1);
4919 int font_size_3 = getFontWidth(font_nr3);
4920 int font_size_4 = getFontWidth(font_nr4);
4921 int text_size_1 = 3 * font_size_1;
4922 int text_size_4 = 5 * font_size_4;
4923 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4925 int dx2 = text_size_1;
4926 int dx3 = dx2 + font_size_1;
4927 int dx4 = screen_width - startdx - 2 * border - text_size_4;
4928 int num_dots = (dx4 - dx3) / font_size_3;
4929 int startx1 = startx + dx1;
4930 int startx2 = startx + dx2;
4931 int startx3 = startx + dx3;
4932 int startx4 = startx + dx4;
4933 int pos = node->pos;
4934 boolean forced = (scores.force_last_added && pos == scores.last_added);
4935 char *pos_text = (forced ? "???" : int2str(pos + 1, 3));
4936 char *dot_text = ".";
4939 DrawText(startx1, starty, pos_text, font_nr1);
4940 DrawText(startx2, starty, dot_text, font_nr1);
4942 for (i = 0; i < num_dots; i++)
4943 DrawText(startx3 + i * font_size_3, starty, dot_text, font_nr3);
4945 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4946 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4948 DrawText(startx4, starty, getHallOfFameScoreText(pos), font_nr4);
4952 strncpy(buffer, node->name, max_buffer_len);
4953 buffer[max_buffer_len] = '\0';
4955 DrawText(startx, starty, buffer, font_nr);
4959 static void drawChooseTreeHeadExt(int type, char *title_string)
4961 int yoffset_sets = MENU_TITLE1_YPOS;
4962 int yoffset_setup = 16;
4963 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4964 type == TREE_TYPE_LEVEL_DIR ||
4965 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4967 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4970 static void drawChooseTreeHead(TreeInfo *ti)
4972 drawChooseTreeHeadExt(ti->type, ti->infotext);
4975 static void drawChooseTreeList(TreeInfo *ti)
4977 int first_entry = ti->cl_first;
4978 int num_entries = numTreeInfoInGroup(ti);
4979 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4982 clearMenuListArea();
4984 for (i = 0; i < num_page_entries; i++)
4986 TreeInfo *node, *node_first;
4987 int entry_pos = first_entry + i;
4989 node_first = getTreeInfoFirstGroupEntry(ti);
4990 node = getTreeInfoFromPos(node_first, entry_pos);
4992 drawChooseTreeText(ti, i, FALSE);
4994 if (node->parent_link)
4995 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4996 else if (node->level_group)
4997 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4999 initCursor(i, IMG_MENU_BUTTON);
5001 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
5002 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5004 if (game_status == GAME_MODE_NAMES)
5005 drawChooseTreeEdit(i, FALSE);
5008 redraw_mask |= REDRAW_FIELD;
5011 static void drawChooseTreeInfo(TreeInfo *ti)
5013 int entry_pos = ti->cl_first + ti->cl_cursor;
5014 int last_redraw_mask = redraw_mask;
5015 int ypos = MENU_TITLE2_YPOS;
5016 int font_nr = FONT_TITLE_2;
5019 if (ti->type == TREE_TYPE_LEVEL_NR)
5020 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
5022 if (ti->type == TREE_TYPE_SCORE_ENTRY)
5023 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
5024 scores.last_level_nr);
5026 if (ti->type != TREE_TYPE_LEVEL_DIR)
5029 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
5030 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
5032 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
5034 if (node->parent_link)
5035 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
5036 node->node_parent->name);
5037 else if (node->level_group)
5038 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
5040 else if (ti->type == TREE_TYPE_LEVEL_DIR)
5041 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
5042 node->levels, (node->levels > 1 ? "levels" : "level"),
5045 // let BackToFront() redraw only what is needed
5046 redraw_mask = last_redraw_mask;
5047 for (x = 0; x < SCR_FIELDX; x++)
5048 MarkTileDirty(x, 1);
5051 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
5053 drawChooseTreeCursor(ti->cl_cursor, active);
5054 drawChooseTreeText(ti, ti->cl_cursor, active);
5057 static void drawChooseTreeScreen(TreeInfo *ti)
5059 drawChooseTreeHead(ti);
5060 drawChooseTreeList(ti);
5061 drawChooseTreeInfo(ti);
5062 drawChooseTreeCursorAndText(ti, TRUE);
5064 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
5066 // scroll bar and buttons may just have been added after reloading scores
5067 if (game_status == GAME_MODE_SCORES)
5068 MapScreenTreeGadgets(ti);
5071 static void drawChooseTreeScreen_Scores_NotAvailable(void)
5073 // dirty workaround to use spacing definitions from info screen
5074 info_mode = INFO_MODE_TITLE;
5076 char *text_info = "HighScores of Level %d";
5077 char *text_title = "Score information:";
5078 char *text_error = "No scores for this level.";
5079 char *text_foot = "Press any key or button for main menu";
5080 int font_info = FONT_TITLE_2;
5081 int font_title = FONT_INITIAL_3;
5082 int font_error = FONT_INITIAL_4;
5083 int font_foot = FONT_INITIAL_2;
5084 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
5085 int ystep_title = getMenuTextStep(spacing_title, font_title);
5086 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
5087 int ystart2 = ystart1 + ystep_title;
5088 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
5089 int ystart0 = MENU_TITLE2_YPOS;
5091 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
5092 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
5094 DrawTextSCentered(ystart1, font_title, text_title);
5095 DrawTextSCentered(ystart2, font_error, text_error);
5097 DrawTextSCentered(ybottom, font_foot, text_foot);
5100 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
5102 // set current tree entry to last added score entry
5103 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(scores.last_added));
5105 // if that fails, set current tree entry to first entry (back link)
5106 if (*ti_ptr == NULL)
5107 *ti_ptr = score_entries->node_group;
5109 int num_entries = numTreeInfoInGroup(*ti_ptr);
5110 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5111 int pos_score = getPosFromTreeInfo(*ti_ptr);
5112 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5113 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5115 (*ti_ptr)->cl_first = pos_first;
5116 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5121 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5124 TreeInfo *ti = *ti_ptr;
5125 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5126 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5127 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5128 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5129 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5131 int y = (ti != NULL ? ti->cl_cursor : 0);
5132 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5133 int num_entries = numTreeInfoInGroup(ti);
5134 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5135 boolean position_set_by_scrollbar = (dx == 999);
5137 if (game_status == GAME_MODE_SCORES)
5139 if (server_scores.updated)
5141 // reload scores, using updated server score cache file
5142 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5144 server_scores.updated = FALSE;
5146 DrawHallOfFame_setScoreEntries();
5148 ti = setHallOfFameActiveEntry(ti_ptr);
5150 if (button != MB_MENU_INITIALIZE)
5151 drawChooseTreeScreen(ti);
5154 if (score_entries == NULL)
5156 if (button == MB_MENU_INITIALIZE)
5158 drawChooseTreeScreen_Scores_NotAvailable();
5160 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5162 PlaySound(SND_MENU_ITEM_SELECTING);
5164 SetGameStatus(GAME_MODE_MAIN);
5173 if (button == MB_MENU_INITIALIZE)
5175 int num_entries = numTreeInfoInGroup(ti);
5176 int entry_pos = getPosFromTreeInfo(ti);
5178 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5179 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5181 if (game_status == GAME_MODE_SCORES)
5183 ti = setHallOfFameActiveEntry(ti_ptr);
5185 else if (ti->cl_first == -1)
5187 // only on initialization
5188 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5189 ti->cl_cursor = entry_pos - ti->cl_first;
5192 else if (ti->cl_cursor >= num_page_entries ||
5193 (num_entries > num_page_entries &&
5194 num_entries - ti->cl_first < num_page_entries))
5196 // only after change of list size (by custom graphic configuration)
5197 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5198 ti->cl_cursor = entry_pos - ti->cl_first;
5201 if (position_set_by_scrollbar)
5204 drawChooseTreeScreen(ti);
5208 else if (button == MB_MENU_LEAVE)
5210 if (game_status != GAME_MODE_SCORES)
5213 PlaySound(SND_MENU_ITEM_SELECTING);
5215 if (ti->node_parent)
5217 *ti_ptr = ti->node_parent;
5218 DrawChooseTree(ti_ptr);
5220 else if (game_status == GAME_MODE_SETUP)
5222 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5223 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5224 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5225 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5227 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5228 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5229 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5230 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5231 execSetupGraphics();
5232 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5233 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5234 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5236 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5237 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5238 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5239 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5240 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5241 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5242 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5243 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5250 if (game_status == GAME_MODE_LEVELNR)
5252 int new_level_nr = atoi(level_number_current->identifier);
5254 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5257 SetGameStatus(GAME_MODE_MAIN);
5265 if (mx || my) // mouse input
5267 x = (mx - amSX) / 32;
5268 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5270 if (game_status == GAME_MODE_NAMES)
5271 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5273 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5275 // move cursor instead of scrolling when already at start/end of list
5276 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5278 else if (dy == +1 * SCROLL_LINE &&
5279 ti->cl_first + num_page_entries == num_entries)
5282 // handle scrolling screen one line or page
5283 if (ti->cl_cursor + dy < 0 ||
5284 ti->cl_cursor + dy > num_page_entries - 1)
5286 boolean redraw = FALSE;
5288 if (ABS(dy) == SCROLL_PAGE)
5289 step = num_page_entries - 1;
5291 if (dy < 0 && ti->cl_first > 0)
5293 // scroll page/line up
5295 ti->cl_first -= step;
5296 if (ti->cl_first < 0)
5301 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5303 // scroll page/line down
5305 ti->cl_first += step;
5306 if (ti->cl_first + num_page_entries > num_entries)
5307 ti->cl_first = MAX(0, num_entries - num_page_entries);
5313 drawChooseTreeScreen(ti);
5318 // handle moving cursor one line
5319 y = ti->cl_cursor + dy;
5324 TreeInfo *node_first, *node_cursor;
5325 int entry_pos = ti->cl_first + y;
5327 node_first = getTreeInfoFirstGroupEntry(ti);
5328 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5330 if (node_cursor->node_group)
5334 PlaySound(SND_MENU_ITEM_SELECTING);
5336 node_cursor->cl_first = ti->cl_first;
5337 node_cursor->cl_cursor = ti->cl_cursor;
5338 *ti_ptr = node_cursor->node_group;
5339 DrawChooseTree(ti_ptr);
5344 else if (dx == -1 && ti->node_parent)
5348 PlaySound(SND_MENU_ITEM_SELECTING);
5350 *ti_ptr = ti->node_parent;
5351 DrawChooseTree(ti_ptr);
5356 if (!anyScrollbarGadgetActive() &&
5357 IN_VIS_MENU(x, y) &&
5358 mx < mx_right_border &&
5359 y >= 0 && y < num_page_entries)
5363 if (game_status == GAME_MODE_NAMES)
5365 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5366 drawChooseTreeEdit(y, TRUE);
5369 if (y != ti->cl_cursor)
5371 PlaySound(SND_MENU_ITEM_ACTIVATING);
5373 drawChooseTreeCursorAndText(ti, FALSE);
5377 drawChooseTreeCursorAndText(ti, TRUE);
5379 drawChooseTreeInfo(ti);
5383 if (game_status == GAME_MODE_SETUP)
5385 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5386 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5387 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5388 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5390 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5391 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5392 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5393 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5394 execSetupGraphics();
5395 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5396 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5397 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5399 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5400 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5401 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5402 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5403 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5404 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5405 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5406 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5415 TreeInfo *node_first, *node_cursor;
5416 int entry_pos = ti->cl_first + y;
5418 PlaySound(SND_MENU_ITEM_SELECTING);
5420 node_first = getTreeInfoFirstGroupEntry(ti);
5421 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5423 if (node_cursor->node_group)
5427 node_cursor->cl_first = ti->cl_first;
5428 node_cursor->cl_cursor = ti->cl_cursor;
5429 *ti_ptr = node_cursor->node_group;
5430 DrawChooseTree(ti_ptr);
5432 else if (node_cursor->parent_link)
5434 if (game_status != GAME_MODE_SCORES)
5437 *ti_ptr = node_cursor->node_parent;
5438 DrawChooseTree(ti_ptr);
5442 if (game_status != GAME_MODE_SCORES)
5445 node_cursor->cl_first = ti->cl_first;
5446 node_cursor->cl_cursor = ti->cl_cursor;
5447 *ti_ptr = node_cursor;
5449 if (ti->type == TREE_TYPE_LEVEL_DIR)
5451 LoadLevelSetup_SeriesInfo();
5453 SaveLevelSetup_LastSeries();
5454 SaveLevelSetup_SeriesInfo();
5458 if (game_status == GAME_MODE_SETUP)
5460 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5461 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5462 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5463 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5465 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5466 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5467 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5468 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5469 execSetupGraphics();
5470 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5471 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5472 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5474 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5475 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5476 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5477 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5478 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5479 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5480 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5481 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5488 if (game_status == GAME_MODE_LEVELNR)
5490 int new_level_nr = atoi(level_number_current->identifier);
5492 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5494 else if (game_status == GAME_MODE_LEVELS)
5496 // store level set if chosen from "last played level set" menu
5497 StoreLastPlayedLevels(leveldir_current);
5499 else if (game_status == GAME_MODE_NAMES)
5501 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5503 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5510 // change active user to selected user
5511 user.nr = entry_pos;
5513 // save number of new active user
5516 // load setup of new active user
5519 // load last level set of new active user
5520 LoadLevelSetup_LastSeries();
5521 LoadLevelSetup_SeriesInfo();
5523 // update list of last played level sets
5524 UpdateLastPlayedLevels_TreeInfo();
5528 ToggleFullscreenIfNeeded();
5529 ChangeWindowScalingIfNeeded();
5531 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5532 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5533 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5535 else if (game_status == GAME_MODE_SCORES)
5537 if (game_status_last_screen == GAME_MODE_PLAYING &&
5538 setup.auto_play_next_level && setup.increment_levels &&
5539 scores.last_level_nr < leveldir_current->last_level &&
5542 StartGameActions(network.enabled, setup.autorecord,
5548 SetGameStatus(GAME_MODE_MAIN);
5556 if (game_status == GAME_MODE_SCORES)
5557 PlayMenuSoundIfLoop();
5560 void DrawChoosePlayerName(void)
5564 if (player_name != NULL)
5566 freeTreeInfo(player_name);
5571 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5573 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5574 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5577 ti->node_top = &player_name;
5578 ti->sort_priority = 10000 + value;
5579 ti->color = getPlayerNameColor(global.user_names[i]);
5581 snprintf(identifier, sizeof(identifier), "%d", value);
5582 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5584 setString(&ti->identifier, identifier);
5585 setString(&ti->name, name);
5586 setString(&ti->name_sorting, name);
5588 pushTreeInfo(&player_name, ti);
5591 // sort player entries by player number
5592 sortTreeInfo(&player_name);
5594 // set current player entry to selected player entry
5595 player_name_current =
5596 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5598 // if that fails, set current player name to first available name
5599 if (player_name_current == NULL)
5600 player_name_current = player_name;
5602 DrawChooseTree(&player_name_current);
5605 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5607 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5610 void DrawChooseLevelSet(void)
5612 DrawChooseTree(&leveldir_current);
5615 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5617 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5620 void DrawChooseLevelNr(void)
5624 if (level_number != NULL)
5626 freeTreeInfo(level_number);
5628 level_number = NULL;
5631 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5633 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5634 char identifier[32], name[64];
5637 // temporarily load level info to get level name
5638 LoadLevelInfoOnly(i);
5640 ti->node_top = &level_number;
5641 ti->sort_priority = 10000 + value;
5642 ti->color = (level.no_level_file ? FC_BLUE :
5643 LevelStats_getSolved(i) ? FC_GREEN :
5644 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5646 snprintf(identifier, sizeof(identifier), "%d", value);
5647 snprintf(name, sizeof(name), "%03d: %s", value,
5648 (level.no_level_file ? "(no file)" : level.name));
5650 setString(&ti->identifier, identifier);
5651 setString(&ti->name, name);
5652 setString(&ti->name_sorting, name);
5654 pushTreeInfo(&level_number, ti);
5657 // sort level number values to start with lowest level number
5658 sortTreeInfo(&level_number);
5660 // set current level number to current level number
5661 level_number_current =
5662 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5664 // if that also fails, set current level number to first available level
5665 if (level_number_current == NULL)
5666 level_number_current = level_number;
5668 DrawChooseTree(&level_number_current);
5671 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5673 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5676 static void DrawHallOfFame_setScoreEntries(void)
5678 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5681 if (score_entries != NULL)
5683 freeTreeInfo(score_entries);
5685 score_entries = NULL;
5688 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5690 // do not add empty score entries
5691 if (scores.entry[i].score == 0 &&
5692 scores.entry[i].time == 0)
5695 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5696 char identifier[32], name[64];
5699 ti->node_top = &score_entries;
5700 ti->sort_priority = 10000 + value;
5701 ti->color = FC_YELLOW;
5704 snprintf(identifier, sizeof(identifier), "%d", value);
5705 snprintf(name, sizeof(name), "%03d.", value + 1);
5707 setString(&ti->identifier, identifier);
5708 setString(&ti->name, name);
5709 setString(&ti->name_sorting, name);
5711 pushTreeInfo(&score_entries, ti);
5714 // sort score entries to start with highest score entry
5715 sortTreeInfo(&score_entries);
5717 // add top tree node to create back link to main menu
5718 score_entries = addTopTreeInfoNode(score_entries);
5720 // set current score entry to last added or highest score entry
5721 score_entry_current =
5722 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5724 // if that fails, set current score entry to first valid score entry
5725 if (score_entry_current == NULL)
5726 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5728 // ("score_entries" and "score_entry_current" may be NULL here)
5731 void DrawHallOfFame(int level_nr)
5733 scores.last_level_nr = level_nr;
5735 // (this is needed when called from GameEnd() after winning a game)
5736 KeyboardAutoRepeatOn();
5738 // (this is needed when called from GameEnd() after winning a game)
5739 SetDrawDeactivationMask(REDRAW_NONE);
5740 SetDrawBackgroundMask(REDRAW_FIELD);
5742 LoadLocalAndServerScore(level_nr, TRUE);
5744 DrawHallOfFame_setScoreEntries();
5746 if (scores.last_added >= 0)
5747 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5749 FadeSetEnterScreen();
5751 DrawChooseTree(&score_entry_current);
5754 static char *getHallOfFameScoreText(int nr)
5756 if (!level.rate_time_over_score)
5757 return int2str(scores.entry[nr].score, 5); // show normal score
5759 if (level.use_step_counter)
5760 return int2str(scores.entry[nr].time, 5); // show number of steps
5762 static char score_text[10];
5763 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5764 int mm = (time_seconds / 60) % 60;
5765 int ss = (time_seconds % 60);
5767 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5772 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5774 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5778 // ============================================================================
5779 // setup screen functions
5780 // ============================================================================
5782 static struct TokenInfo *setup_info;
5783 static int num_setup_info; // number of setup entries shown on screen
5784 static int max_setup_info; // total number of setup entries in list
5786 static char *window_size_text;
5787 static char *scaling_type_text;
5788 static char *rendering_mode_text;
5789 static char *vsync_mode_text;
5790 static char *scroll_delay_text;
5791 static char *snapshot_mode_text;
5792 static char *game_speed_text;
5793 static char *scores_type_text;
5794 static char *network_server_text;
5795 static char *graphics_set_name;
5796 static char *sounds_set_name;
5797 static char *music_set_name;
5798 static char *volume_simple_text;
5799 static char *volume_loops_text;
5800 static char *volume_music_text;
5801 static char *touch_controls_text;
5802 static char *move_distance_text;
5803 static char *drop_distance_text;
5804 static char *transparency_text;
5805 static char *grid_size_text[2][2];
5807 static void execSetupMain(void)
5809 setup_mode = SETUP_MODE_MAIN;
5814 static void execSetupGame_setScoresType(void)
5816 if (scores_types == NULL)
5820 for (i = 0; scores_types_list[i].value != NULL; i++)
5822 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5823 char identifier[32], name[32];
5824 char *value = scores_types_list[i].value;
5825 char *text = scores_types_list[i].text;
5827 ti->node_top = &scores_types;
5828 ti->sort_priority = i;
5830 sprintf(identifier, "%s", value);
5831 sprintf(name, "%s", text);
5833 setString(&ti->identifier, identifier);
5834 setString(&ti->name, name);
5835 setString(&ti->name_sorting, name);
5836 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5838 pushTreeInfo(&scores_types, ti);
5841 // sort scores type values to start with lowest scores type value
5842 sortTreeInfo(&scores_types);
5844 // set current scores type value to configured scores type value
5845 scores_type_current =
5846 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5848 // if that fails, set current scores type to reliable default value
5849 if (scores_type_current == NULL)
5850 scores_type_current =
5851 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5853 // if that also fails, set current scores type to first available value
5854 if (scores_type_current == NULL)
5855 scores_type_current = scores_types;
5858 setup.scores_in_highscore_list = scores_type_current->identifier;
5860 // needed for displaying scores type text instead of identifier
5861 scores_type_text = scores_type_current->name;
5864 static void execSetupGame_setGameSpeeds(boolean update_value)
5866 if (setup.game_speed_extended)
5868 game_speeds_list = game_speeds_list_extended;
5869 game_speeds = game_speeds_extended;
5873 game_speeds_list = game_speeds_list_normal;
5874 game_speeds = game_speeds_normal;
5877 if (game_speeds == NULL)
5881 for (i = 0; game_speeds_list[i].value != -1; i++)
5883 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5884 char identifier[32], name[32];
5885 int value = game_speeds_list[i].value;
5886 char *text = game_speeds_list[i].text;
5888 ti->node_top = &game_speeds;
5889 ti->sort_priority = 10000 - value;
5891 sprintf(identifier, "%d", value);
5892 sprintf(name, "%s", text);
5894 setString(&ti->identifier, identifier);
5895 setString(&ti->name, name);
5896 setString(&ti->name_sorting, name);
5897 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5899 pushTreeInfo(&game_speeds, ti);
5902 // sort game speed values to start with slowest game speed
5903 sortTreeInfo(&game_speeds);
5905 update_value = TRUE;
5910 // set current game speed to configured game speed value
5911 game_speed_current =
5912 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5914 // if that fails, set current game speed to reliable default value
5915 if (game_speed_current == NULL)
5916 game_speed_current =
5917 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5919 // if that also fails, set current game speed to first available speed
5920 if (game_speed_current == NULL)
5921 game_speed_current = game_speeds;
5923 if (setup.game_speed_extended)
5924 game_speeds_extended = game_speeds;
5926 game_speeds_normal = game_speeds;
5929 setup.game_frame_delay = atoi(game_speed_current->identifier);
5931 // needed for displaying game speed text instead of identifier
5932 game_speed_text = game_speed_current->name;
5935 static void execSetupGame_setScrollDelays(void)
5937 if (scroll_delays == NULL)
5941 for (i = 0; scroll_delays_list[i].value != -1; i++)
5943 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5944 char identifier[32], name[32];
5945 int value = scroll_delays_list[i].value;
5946 char *text = scroll_delays_list[i].text;
5948 ti->node_top = &scroll_delays;
5949 ti->sort_priority = 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_SCROLL_DELAY);
5959 pushTreeInfo(&scroll_delays, ti);
5962 // sort scroll delay values to start with lowest scroll delay value
5963 sortTreeInfo(&scroll_delays);
5965 // set current scroll delay value to configured scroll delay value
5966 scroll_delay_current =
5967 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5969 // if that fails, set current scroll delay to reliable default value
5970 if (scroll_delay_current == NULL)
5971 scroll_delay_current =
5972 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5974 // if that also fails, set current scroll delay to first available value
5975 if (scroll_delay_current == NULL)
5976 scroll_delay_current = scroll_delays;
5979 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5981 // needed for displaying scroll delay text instead of identifier
5982 scroll_delay_text = scroll_delay_current->name;
5985 static void execSetupGame_setSnapshotModes(void)
5987 if (snapshot_modes == NULL)
5991 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5993 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5994 char identifier[32], name[32];
5995 char *value = snapshot_modes_list[i].value;
5996 char *text = snapshot_modes_list[i].text;
5998 ti->node_top = &snapshot_modes;
5999 ti->sort_priority = i;
6001 sprintf(identifier, "%s", value);
6002 sprintf(name, "%s", text);
6004 setString(&ti->identifier, identifier);
6005 setString(&ti->name, name);
6006 setString(&ti->name_sorting, name);
6007 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6009 pushTreeInfo(&snapshot_modes, ti);
6012 // sort snapshot mode values to start with lowest snapshot mode value
6013 sortTreeInfo(&snapshot_modes);
6015 // set current snapshot mode value to configured snapshot mode value
6016 snapshot_mode_current =
6017 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6019 // if that fails, set current snapshot mode to reliable default value
6020 if (snapshot_mode_current == NULL)
6021 snapshot_mode_current =
6022 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6024 // if that also fails, set current snapshot mode to first available value
6025 if (snapshot_mode_current == NULL)
6026 snapshot_mode_current = snapshot_modes;
6029 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6031 // needed for displaying snapshot mode text instead of identifier
6032 snapshot_mode_text = snapshot_mode_current->name;
6035 static void execSetupGame_setNetworkServerText(void)
6037 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6039 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6043 strncpy(network_server_hostname, setup.network_server_hostname,
6044 MAX_SETUP_TEXT_INPUT_LEN);
6045 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6048 // needed for displaying network server text instead of identifier
6049 network_server_text = network_server_hostname;
6052 static void execSetupGame(void)
6054 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6056 execSetupGame_setGameSpeeds(FALSE);
6057 execSetupGame_setScoresType();
6058 execSetupGame_setScrollDelays();
6059 execSetupGame_setSnapshotModes();
6061 execSetupGame_setNetworkServerText();
6063 if (!setup.provide_uploading_tapes)
6064 setHideSetupEntry(execOfferUploadTapes);
6066 setup_mode = SETUP_MODE_GAME;
6070 // check if vsync needs to be disabled for this game speed to work
6071 if (check_vsync_mode)
6072 DisableVsyncIfNeeded();
6075 static void execSetupChooseScoresType(void)
6077 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6082 static void execSetupChooseGameSpeed(void)
6084 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6089 static void execSetupChooseScrollDelay(void)
6091 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6096 static void execSetupChooseSnapshotMode(void)
6098 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6103 static void execSetupEngines(void)
6105 setup_mode = SETUP_MODE_ENGINES;
6110 static void execSetupEditor(void)
6112 setup_mode = SETUP_MODE_EDITOR;
6117 static void execSetupGraphics_setWindowSizes(boolean update_list)
6119 if (window_sizes != NULL && update_list)
6121 freeTreeInfo(window_sizes);
6123 window_sizes = NULL;
6126 if (window_sizes == NULL)
6128 boolean current_window_size_found = FALSE;
6131 for (i = 0; window_sizes_list[i].value != -1; i++)
6133 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6134 char identifier[32], name[32];
6135 int value = window_sizes_list[i].value;
6136 char *text = window_sizes_list[i].text;
6138 ti->node_top = &window_sizes;
6139 ti->sort_priority = value;
6141 sprintf(identifier, "%d", value);
6142 sprintf(name, "%s", text);
6144 setString(&ti->identifier, identifier);
6145 setString(&ti->name, name);
6146 setString(&ti->name_sorting, name);
6147 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6149 pushTreeInfo(&window_sizes, ti);
6151 if (value == setup.window_scaling_percent)
6152 current_window_size_found = TRUE;
6155 if (!current_window_size_found)
6157 // add entry for non-preset window scaling value
6159 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6160 char identifier[32], name[32];
6161 int value = setup.window_scaling_percent;
6163 ti->node_top = &window_sizes;
6164 ti->sort_priority = value;
6166 sprintf(identifier, "%d", value);
6167 sprintf(name, "%d %% (Current)", value);
6169 setString(&ti->identifier, identifier);
6170 setString(&ti->name, name);
6171 setString(&ti->name_sorting, name);
6172 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6174 pushTreeInfo(&window_sizes, ti);
6177 // sort window size values to start with lowest window size value
6178 sortTreeInfo(&window_sizes);
6180 // set current window size value to configured window size value
6181 window_size_current =
6182 getTreeInfoFromIdentifier(window_sizes,
6183 i_to_a(setup.window_scaling_percent));
6185 // if that fails, set current window size to reliable default value
6186 if (window_size_current == NULL)
6187 window_size_current =
6188 getTreeInfoFromIdentifier(window_sizes,
6189 i_to_a(STD_WINDOW_SCALING_PERCENT));
6191 // if that also fails, set current window size to first available value
6192 if (window_size_current == NULL)
6193 window_size_current = window_sizes;
6196 setup.window_scaling_percent = atoi(window_size_current->identifier);
6198 // needed for displaying window size text instead of identifier
6199 window_size_text = window_size_current->name;
6202 static void execSetupGraphics_setScalingTypes(void)
6204 if (scaling_types == NULL)
6208 for (i = 0; scaling_types_list[i].value != NULL; i++)
6210 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6211 char identifier[32], name[32];
6212 char *value = scaling_types_list[i].value;
6213 char *text = scaling_types_list[i].text;
6215 ti->node_top = &scaling_types;
6216 ti->sort_priority = i;
6218 sprintf(identifier, "%s", value);
6219 sprintf(name, "%s", text);
6221 setString(&ti->identifier, identifier);
6222 setString(&ti->name, name);
6223 setString(&ti->name_sorting, name);
6224 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6226 pushTreeInfo(&scaling_types, ti);
6229 // sort scaling type values to start with lowest scaling type value
6230 sortTreeInfo(&scaling_types);
6232 // set current scaling type value to configured scaling type value
6233 scaling_type_current =
6234 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6236 // if that fails, set current scaling type to reliable default value
6237 if (scaling_type_current == NULL)
6238 scaling_type_current =
6239 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6241 // if that also fails, set current scaling type to first available value
6242 if (scaling_type_current == NULL)
6243 scaling_type_current = scaling_types;
6246 setup.window_scaling_quality = scaling_type_current->identifier;
6248 // needed for displaying scaling type text instead of identifier
6249 scaling_type_text = scaling_type_current->name;
6252 static void execSetupGraphics_setRenderingModes(void)
6254 if (rendering_modes == NULL)
6258 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6260 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6261 char identifier[32], name[32];
6262 char *value = rendering_modes_list[i].value;
6263 char *text = rendering_modes_list[i].text;
6265 ti->node_top = &rendering_modes;
6266 ti->sort_priority = i;
6268 sprintf(identifier, "%s", value);
6269 sprintf(name, "%s", text);
6271 setString(&ti->identifier, identifier);
6272 setString(&ti->name, name);
6273 setString(&ti->name_sorting, name);
6274 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6276 pushTreeInfo(&rendering_modes, ti);
6279 // sort rendering mode values to start with lowest rendering mode value
6280 sortTreeInfo(&rendering_modes);
6282 // set current rendering mode value to configured rendering mode value
6283 rendering_mode_current =
6284 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6286 // if that fails, set current rendering mode to reliable default value
6287 if (rendering_mode_current == NULL)
6288 rendering_mode_current =
6289 getTreeInfoFromIdentifier(rendering_modes,
6290 STR_SPECIAL_RENDERING_DEFAULT);
6292 // if that also fails, set current rendering mode to first available one
6293 if (rendering_mode_current == NULL)
6294 rendering_mode_current = rendering_modes;
6297 setup.screen_rendering_mode = rendering_mode_current->identifier;
6299 // needed for displaying rendering mode text instead of identifier
6300 rendering_mode_text = rendering_mode_current->name;
6303 static void execSetupGraphics_setVsyncModes(boolean update_value)
6305 if (vsync_modes == NULL)
6309 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6311 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6312 char identifier[32], name[32];
6313 char *value = vsync_modes_list[i].value;
6314 char *text = vsync_modes_list[i].text;
6316 ti->node_top = &vsync_modes;
6317 ti->sort_priority = i;
6319 sprintf(identifier, "%s", value);
6320 sprintf(name, "%s", text);
6322 setString(&ti->identifier, identifier);
6323 setString(&ti->name, name);
6324 setString(&ti->name_sorting, name);
6325 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6327 pushTreeInfo(&vsync_modes, ti);
6330 // sort vsync mode values to start with lowest vsync mode value
6331 sortTreeInfo(&vsync_modes);
6333 update_value = TRUE;
6338 // set current vsync mode value to configured vsync mode value
6339 vsync_mode_current =
6340 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6342 // if that fails, set current vsync mode to reliable default value
6343 if (vsync_mode_current == NULL)
6344 vsync_mode_current =
6345 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6347 // if that also fails, set current vsync mode to first available one
6348 if (vsync_mode_current == NULL)
6349 vsync_mode_current = vsync_modes;
6352 setup.vsync_mode = vsync_mode_current->identifier;
6354 // needed for displaying vsync mode text instead of identifier
6355 vsync_mode_text = vsync_mode_current->name;
6358 static void execSetupGraphics(void)
6360 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6362 // update "setup.window_scaling_percent" from list selection
6363 // (in this case, window scaling was changed on setup screen)
6364 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6365 execSetupGraphics_setWindowSizes(FALSE);
6367 // update "setup.vsync_mode" from list selection
6368 // (in this case, vsync mode was changed on setup screen)
6369 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6370 execSetupGraphics_setVsyncModes(FALSE);
6372 // update list selection from "setup.window_scaling_percent"
6373 // (window scaling may have changed by resizing the window)
6374 execSetupGraphics_setWindowSizes(TRUE);
6376 // update list selection from "setup.vsync_mode"
6377 // (vsync_mode may have changed by re-creating the renderer)
6378 execSetupGraphics_setVsyncModes(TRUE);
6380 execSetupGraphics_setScalingTypes();
6381 execSetupGraphics_setRenderingModes();
6383 setup_mode = SETUP_MODE_GRAPHICS;
6387 // check if game speed is high enough for 60 Hz vsync to work
6388 if (check_game_speed)
6389 ModifyGameSpeedIfNeeded();
6391 // window scaling may have changed at this point
6392 ChangeWindowScalingIfNeeded();
6394 // window scaling quality may have changed at this point
6395 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6396 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6398 // screen rendering mode may have changed at this point
6399 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6401 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6402 int video_vsync_mode = video.vsync_mode;
6404 // screen vsync mode may have changed at this point
6405 ChangeVsyncModeIfNeeded();
6407 // check if setting vsync mode to selected value failed
6408 if (setup_vsync_mode != video_vsync_mode &&
6409 setup_vsync_mode != video.vsync_mode)
6411 // changing vsync mode to selected value failed -- reset displayed value
6412 execSetupGraphics_setVsyncModes(TRUE);
6414 Request("Setting VSync failed!", REQ_CONFIRM);
6420 static void execSetupChooseWindowSize(void)
6422 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6427 static void execSetupChooseScalingType(void)
6429 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6434 static void execSetupChooseRenderingMode(void)
6436 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6441 static void execSetupChooseVsyncMode(void)
6443 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6448 static void execSetupChooseVolumeSimple(void)
6450 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6455 static void execSetupChooseVolumeLoops(void)
6457 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6462 static void execSetupChooseVolumeMusic(void)
6464 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6469 static void execSetupSound(void)
6471 if (volumes_simple == NULL)
6473 boolean current_volume_simple_found = FALSE;
6476 for (i = 0; volumes_list[i].value != -1; i++)
6478 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6479 char identifier[32], name[32];
6480 int value = volumes_list[i].value;
6481 char *text = volumes_list[i].text;
6483 ti->node_top = &volumes_simple;
6484 ti->sort_priority = value;
6486 sprintf(identifier, "%d", value);
6487 sprintf(name, "%s", text);
6489 setString(&ti->identifier, identifier);
6490 setString(&ti->name, name);
6491 setString(&ti->name_sorting, name);
6492 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6494 pushTreeInfo(&volumes_simple, ti);
6496 if (value == setup.volume_simple)
6497 current_volume_simple_found = TRUE;
6500 if (!current_volume_simple_found)
6502 // add entry for non-preset volume value
6504 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6505 char identifier[32], name[32];
6506 int value = setup.volume_simple;
6508 ti->node_top = &volumes_simple;
6509 ti->sort_priority = value;
6511 sprintf(identifier, "%d", value);
6512 sprintf(name, "%d %% (Current)", value);
6514 setString(&ti->identifier, identifier);
6515 setString(&ti->name, name);
6516 setString(&ti->name_sorting, name);
6517 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6519 pushTreeInfo(&volumes_simple, ti);
6522 // sort volume values to start with lowest volume value
6523 sortTreeInfo(&volumes_simple);
6525 // set current volume value to configured volume value
6526 volume_simple_current =
6527 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6529 // if that fails, set current volume to reliable default value
6530 if (volume_simple_current == NULL)
6531 volume_simple_current =
6532 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6534 // if that also fails, set current volume to first available value
6535 if (volume_simple_current == NULL)
6536 volume_simple_current = volumes_simple;
6539 if (volumes_loops == NULL)
6541 boolean current_volume_loops_found = FALSE;
6544 for (i = 0; volumes_list[i].value != -1; i++)
6546 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6547 char identifier[32], name[32];
6548 int value = volumes_list[i].value;
6549 char *text = volumes_list[i].text;
6551 ti->node_top = &volumes_loops;
6552 ti->sort_priority = value;
6554 sprintf(identifier, "%d", value);
6555 sprintf(name, "%s", text);
6557 setString(&ti->identifier, identifier);
6558 setString(&ti->name, name);
6559 setString(&ti->name_sorting, name);
6560 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6562 pushTreeInfo(&volumes_loops, ti);
6564 if (value == setup.volume_loops)
6565 current_volume_loops_found = TRUE;
6568 if (!current_volume_loops_found)
6570 // add entry for non-preset volume value
6572 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6573 char identifier[32], name[32];
6574 int value = setup.volume_loops;
6576 ti->node_top = &volumes_loops;
6577 ti->sort_priority = value;
6579 sprintf(identifier, "%d", value);
6580 sprintf(name, "%d %% (Current)", value);
6582 setString(&ti->identifier, identifier);
6583 setString(&ti->name, name);
6584 setString(&ti->name_sorting, name);
6585 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6587 pushTreeInfo(&volumes_loops, ti);
6590 // sort volume values to start with lowest volume value
6591 sortTreeInfo(&volumes_loops);
6593 // set current volume value to configured volume value
6594 volume_loops_current =
6595 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6597 // if that fails, set current volume to reliable default value
6598 if (volume_loops_current == NULL)
6599 volume_loops_current =
6600 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6602 // if that also fails, set current volume to first available value
6603 if (volume_loops_current == NULL)
6604 volume_loops_current = volumes_loops;
6607 if (volumes_music == NULL)
6609 boolean current_volume_music_found = FALSE;
6612 for (i = 0; volumes_list[i].value != -1; i++)
6614 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6615 char identifier[32], name[32];
6616 int value = volumes_list[i].value;
6617 char *text = volumes_list[i].text;
6619 ti->node_top = &volumes_music;
6620 ti->sort_priority = value;
6622 sprintf(identifier, "%d", value);
6623 sprintf(name, "%s", text);
6625 setString(&ti->identifier, identifier);
6626 setString(&ti->name, name);
6627 setString(&ti->name_sorting, name);
6628 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6630 pushTreeInfo(&volumes_music, ti);
6632 if (value == setup.volume_music)
6633 current_volume_music_found = TRUE;
6636 if (!current_volume_music_found)
6638 // add entry for non-preset volume value
6640 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6641 char identifier[32], name[32];
6642 int value = setup.volume_music;
6644 ti->node_top = &volumes_music;
6645 ti->sort_priority = value;
6647 sprintf(identifier, "%d", value);
6648 sprintf(name, "%d %% (Current)", value);
6650 setString(&ti->identifier, identifier);
6651 setString(&ti->name, name);
6652 setString(&ti->name_sorting, name);
6653 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6655 pushTreeInfo(&volumes_music, ti);
6658 // sort volume values to start with lowest volume value
6659 sortTreeInfo(&volumes_music);
6661 // set current volume value to configured volume value
6662 volume_music_current =
6663 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6665 // if that fails, set current volume to reliable default value
6666 if (volume_music_current == NULL)
6667 volume_music_current =
6668 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6670 // if that also fails, set current volume to first available value
6671 if (volume_music_current == NULL)
6672 volume_music_current = volumes_music;
6675 setup.volume_simple = atoi(volume_simple_current->identifier);
6676 setup.volume_loops = atoi(volume_loops_current->identifier);
6677 setup.volume_music = atoi(volume_music_current->identifier);
6679 // needed for displaying volume text instead of identifier
6680 volume_simple_text = volume_simple_current->name;
6681 volume_loops_text = volume_loops_current->name;
6682 volume_music_text = volume_music_current->name;
6684 setup_mode = SETUP_MODE_SOUND;
6689 static void execSetupChooseTouchControls(void)
6691 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6696 static void execSetupChooseMoveDistance(void)
6698 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6703 static void execSetupChooseDropDistance(void)
6705 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6710 static void execSetupChooseTransparency(void)
6712 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6717 static void execSetupChooseGridXSize_0(void)
6719 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6724 static void execSetupChooseGridYSize_0(void)
6726 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6731 static void execSetupChooseGridXSize_1(void)
6733 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6738 static void execSetupChooseGridYSize_1(void)
6740 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6745 static void execSetupConfigureVirtualButtons(void)
6747 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6749 ConfigureVirtualButtons();
6751 setup_mode = SETUP_MODE_TOUCH;
6756 static void execSetupTouch(void)
6760 if (touch_controls == NULL)
6762 for (i = 0; touch_controls_list[i].value != NULL; i++)
6764 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6765 char identifier[32], name[32];
6766 char *value = touch_controls_list[i].value;
6767 char *text = touch_controls_list[i].text;
6769 ti->node_top = &touch_controls;
6770 ti->sort_priority = i;
6772 sprintf(identifier, "%s", value);
6773 sprintf(name, "%s", text);
6775 setString(&ti->identifier, identifier);
6776 setString(&ti->name, name);
6777 setString(&ti->name_sorting, name);
6778 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6780 pushTreeInfo(&touch_controls, ti);
6783 // sort touch control values to start with lowest touch control value
6784 sortTreeInfo(&touch_controls);
6786 // set current touch control value to configured touch control value
6787 touch_control_current =
6788 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6790 // if that fails, set current touch control to reliable default value
6791 if (touch_control_current == NULL)
6792 touch_control_current =
6793 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6795 // if that also fails, set current touch control to first available value
6796 if (touch_control_current == NULL)
6797 touch_control_current = touch_controls;
6800 if (move_distances == NULL)
6802 for (i = 0; distances_list[i].value != -1; i++)
6804 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6805 char identifier[32], name[32];
6806 int value = distances_list[i].value;
6807 char *text = distances_list[i].text;
6809 ti->node_top = &move_distances;
6810 ti->sort_priority = value;
6812 sprintf(identifier, "%d", value);
6813 sprintf(name, "%s", text);
6815 setString(&ti->identifier, identifier);
6816 setString(&ti->name, name);
6817 setString(&ti->name_sorting, name);
6818 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6820 pushTreeInfo(&move_distances, ti);
6823 // sort distance values to start with lowest distance value
6824 sortTreeInfo(&move_distances);
6826 // set current distance value to configured distance value
6827 move_distance_current =
6828 getTreeInfoFromIdentifier(move_distances,
6829 i_to_a(setup.touch.move_distance));
6831 // if that fails, set current distance to reliable default value
6832 if (move_distance_current == NULL)
6833 move_distance_current =
6834 getTreeInfoFromIdentifier(move_distances,
6835 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6837 // if that also fails, set current distance to first available value
6838 if (move_distance_current == NULL)
6839 move_distance_current = move_distances;
6842 if (drop_distances == NULL)
6844 for (i = 0; distances_list[i].value != -1; i++)
6846 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6847 char identifier[32], name[32];
6848 int value = distances_list[i].value;
6849 char *text = distances_list[i].text;
6851 ti->node_top = &drop_distances;
6852 ti->sort_priority = value;
6854 sprintf(identifier, "%d", value);
6855 sprintf(name, "%s", text);
6857 setString(&ti->identifier, identifier);
6858 setString(&ti->name, name);
6859 setString(&ti->name_sorting, name);
6860 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6862 pushTreeInfo(&drop_distances, ti);
6865 // sort distance values to start with lowest distance value
6866 sortTreeInfo(&drop_distances);
6868 // set current distance value to configured distance value
6869 drop_distance_current =
6870 getTreeInfoFromIdentifier(drop_distances,
6871 i_to_a(setup.touch.drop_distance));
6873 // if that fails, set current distance to reliable default value
6874 if (drop_distance_current == NULL)
6875 drop_distance_current =
6876 getTreeInfoFromIdentifier(drop_distances,
6877 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6879 // if that also fails, set current distance to first available value
6880 if (drop_distance_current == NULL)
6881 drop_distance_current = drop_distances;
6884 if (transparencies == NULL)
6886 for (i = 0; transparencies_list[i].value != -1; i++)
6888 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6889 char identifier[32], name[32];
6890 int value = transparencies_list[i].value;
6891 char *text = transparencies_list[i].text;
6893 ti->node_top = &transparencies;
6894 ti->sort_priority = value;
6896 sprintf(identifier, "%d", value);
6897 sprintf(name, "%s", text);
6899 setString(&ti->identifier, identifier);
6900 setString(&ti->name, name);
6901 setString(&ti->name_sorting, name);
6902 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6904 pushTreeInfo(&transparencies, ti);
6907 // sort transparency values to start with lowest transparency value
6908 sortTreeInfo(&transparencies);
6910 // set current transparency value to configured transparency value
6911 transparency_current =
6912 getTreeInfoFromIdentifier(transparencies,
6913 i_to_a(setup.touch.transparency));
6915 // if that fails, set current transparency to reliable default value
6916 if (transparency_current == NULL)
6917 transparency_current =
6918 getTreeInfoFromIdentifier(transparencies,
6919 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6921 // if that also fails, set current transparency to first available value
6922 if (transparency_current == NULL)
6923 transparency_current = transparencies;
6926 for (i = 0; i < 2; i++)
6928 for (j = 0; j < 2; j++)
6930 if (grid_sizes[i][j] == NULL)
6932 for (k = 0; grid_sizes_list[k].value != -1; k++)
6934 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6935 char identifier[32], name[32];
6936 int value = grid_sizes_list[k].value;
6937 char *text = grid_sizes_list[k].text;
6939 ti->node_top = &grid_sizes[i][j];
6940 ti->sort_priority = value;
6942 sprintf(identifier, "%d", value);
6943 sprintf(name, "%s", text);
6945 setString(&ti->identifier, identifier);
6946 setString(&ti->name, name);
6947 setString(&ti->name_sorting, name);
6948 setString(&ti->infotext,
6951 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6952 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6954 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6955 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6957 pushTreeInfo(&grid_sizes[i][j], ti);
6960 // sort grid size values to start with lowest grid size value
6961 sortTreeInfo(&grid_sizes[i][j]);
6963 // set current grid size value to configured grid size value
6964 grid_size_current[i][j] =
6965 getTreeInfoFromIdentifier(grid_sizes[i][j],
6967 setup.touch.grid_xsize[i] :
6968 setup.touch.grid_ysize[i]));
6970 // if that fails, set current grid size to reliable default value
6971 if (grid_size_current[i][j] == NULL)
6972 grid_size_current[i][j] =
6973 getTreeInfoFromIdentifier(grid_sizes[i][j],
6975 DEFAULT_GRID_XSIZE(i) :
6976 DEFAULT_GRID_YSIZE(i)));
6978 // if that also fails, set current grid size to first available value
6979 if (grid_size_current[i][j] == NULL)
6980 grid_size_current[i][j] = grid_sizes[i][j];
6985 setup.touch.control_type = touch_control_current->identifier;
6986 setup.touch.move_distance = atoi(move_distance_current->identifier);
6987 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6988 setup.touch.transparency = atoi(transparency_current->identifier);
6990 for (i = 0; i < 2; i++)
6992 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6993 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6995 if (i == GRID_ACTIVE_NR())
6997 overlay.grid_xsize = setup.touch.grid_xsize[i];
6998 overlay.grid_ysize = setup.touch.grid_ysize[i];
7002 // needed for displaying value text instead of identifier
7003 touch_controls_text = touch_control_current->name;
7004 move_distance_text = move_distance_current->name;
7005 drop_distance_text = drop_distance_current->name;
7006 transparency_text = transparency_current->name;
7008 for (i = 0; i < 2; i++)
7009 for (j = 0; j < 2; j++)
7010 grid_size_text[i][j] = grid_size_current[i][j]->name;
7012 setup_mode = SETUP_MODE_TOUCH;
7017 static void execSetupArtwork(void)
7019 static ArtworkDirTree *gfx_last_valid = NULL;
7020 static ArtworkDirTree *snd_last_valid = NULL;
7021 static ArtworkDirTree *mus_last_valid = NULL;
7023 // current artwork directory may be invalid (level group, parent link)
7024 if (!validLevelSeries(artwork.gfx_current))
7025 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7026 if (!validLevelSeries(artwork.snd_current))
7027 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7028 if (!validLevelSeries(artwork.mus_current))
7029 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7031 // store valid artwork directory information
7032 gfx_last_valid = artwork.gfx_current;
7033 snd_last_valid = artwork.snd_current;
7034 mus_last_valid = artwork.mus_current;
7037 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7038 artwork.gfx_current->subdir,
7039 artwork.gfx_current->fullpath,
7040 artwork.gfx_current->basepath);
7043 setup.graphics_set = artwork.gfx_current->identifier;
7044 setup.sounds_set = artwork.snd_current->identifier;
7045 setup.music_set = artwork.mus_current->identifier;
7047 // needed if last screen (setup choice) changed graphics, sounds or music
7048 ReloadCustomArtwork(0);
7050 // needed for displaying artwork name instead of artwork identifier
7051 graphics_set_name = artwork.gfx_current->name;
7052 sounds_set_name = artwork.snd_current->name;
7053 music_set_name = artwork.mus_current->name;
7055 setup_mode = SETUP_MODE_ARTWORK;
7060 static void execSetupChooseGraphics(void)
7062 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7067 static void execSetupChooseSounds(void)
7069 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7074 static void execSetupChooseMusic(void)
7076 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7081 static void execSetupInput(void)
7083 setup_mode = SETUP_MODE_INPUT;
7088 static void execSetupShortcuts(void)
7090 setup_mode = SETUP_MODE_SHORTCUTS;
7095 static void execSetupShortcuts1(void)
7097 setup_mode = SETUP_MODE_SHORTCUTS_1;
7102 static void execSetupShortcuts2(void)
7104 setup_mode = SETUP_MODE_SHORTCUTS_2;
7109 static void execSetupShortcuts3(void)
7111 setup_mode = SETUP_MODE_SHORTCUTS_3;
7116 static void execSetupShortcuts4(void)
7118 setup_mode = SETUP_MODE_SHORTCUTS_4;
7123 static void execSetupShortcuts5(void)
7125 setup_mode = SETUP_MODE_SHORTCUTS_5;
7130 static void execExitSetup(void)
7132 SetGameStatus(GAME_MODE_MAIN);
7137 static void execSaveAndExitSetup(void)
7143 static void execGadgetNetworkServer(void)
7145 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7146 struct GadgetInfo *gi = screen_gadget[gadget_id];
7148 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7149 network_server_hostname[0] = '\0';
7151 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7155 ClickOnGadget(gi, MB_LEFTBUTTON);
7158 static void execOfferUploadTapes(void)
7163 static void ToggleNetworkModeIfNeeded(void)
7165 int font_title = FONT_TITLE_1;
7166 int font_foot = FC_BLUE;
7167 int ystart = mSY - SY + 16;
7168 int ybottom = mSY - SY + SYSIZE - 20;
7169 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7171 if (setup.network_mode == network.enabled)
7174 network.enabled = setup.network_mode;
7176 FadeOut(REDRAW_ALL);
7180 DrawTextSCentered(ystart, font_title, text);
7184 if (network.enabled)
7185 InitNetworkServer();
7187 DisconnectFromNetworkServer();
7189 DrawTextSCentered(ybottom, font_foot,
7190 "Press any key or button for setup menu");
7192 WaitForEventToContinue();
7197 static void ToggleGameSpeedsListIfNeeded(void)
7199 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7201 if (setup.game_speed_extended == using_game_speeds_extended)
7204 // try to match similar values when changing game speeds list
7205 if (setup.game_speed_extended)
7206 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7207 setup.game_frame_delay == 30 ? 29 :
7208 setup.game_frame_delay);
7210 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7211 setup.game_frame_delay == 16 ? 15 :
7212 setup.game_frame_delay >= 29 ? 30 :
7213 setup.game_frame_delay <= 10 ? 10 :
7214 setup.game_frame_delay);
7216 execSetupGame_setGameSpeeds(TRUE);
7221 static void ToggleUseApiServerIfNeeded(void)
7223 if (runtime.use_api_server == setup.use_api_server)
7226 runtime.use_api_server = setup.use_api_server;
7228 if (runtime.use_api_server)
7229 CheckApiServerTasks();
7232 static void ModifyGameSpeedIfNeeded(void)
7234 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7235 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7239 char *game_speed_text = "Fast";
7240 int game_speed_value = 15;
7242 if (setup.game_speed_extended)
7244 game_speed_text = "60 fps";
7245 game_speed_value = 16;
7248 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7250 // set game speed to existing list value that is fast enough for vsync
7251 setup.game_frame_delay = game_speed_value;
7253 execSetupGame_setGameSpeeds(TRUE);
7255 Request(message, REQ_CONFIRM);
7258 static void DisableVsyncIfNeeded(void)
7260 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7261 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7262 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7265 // disable vsync for the selected game speed to work
7266 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7268 execSetupGraphics_setVsyncModes(TRUE);
7270 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7276 void *related_value;
7277 } hide_related_entry_list[] =
7279 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7280 { &setup.scores_in_highscore_list, &scores_type_text },
7282 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7283 { &setup.game_frame_delay, &game_speed_text },
7285 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7286 { &setup.scroll_delay_value, &scroll_delay_text },
7288 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7289 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7291 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7292 { &setup.window_scaling_percent, &window_size_text },
7294 { &setup.window_scaling_quality, execSetupChooseScalingType },
7295 { &setup.window_scaling_quality, &scaling_type_text },
7297 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7298 { &setup.screen_rendering_mode, &rendering_mode_text },
7300 { &setup.vsync_mode, execSetupChooseVsyncMode },
7301 { &setup.vsync_mode, &vsync_mode_text },
7303 { &setup.graphics_set, execSetupChooseGraphics },
7304 { &setup.graphics_set, &graphics_set_name },
7306 { &setup.sounds_set, execSetupChooseSounds },
7307 { &setup.sounds_set, &sounds_set_name },
7309 { &setup.music_set, execSetupChooseMusic },
7310 { &setup.music_set, &music_set_name },
7312 { &setup.volume_simple, execSetupChooseVolumeSimple },
7313 { &setup.volume_simple, &volume_simple_text },
7315 { &setup.volume_loops, execSetupChooseVolumeLoops },
7316 { &setup.volume_loops, &volume_loops_text },
7318 { &setup.volume_music, execSetupChooseVolumeMusic },
7319 { &setup.volume_music, &volume_music_text },
7321 { &setup.touch.control_type, execSetupChooseTouchControls },
7322 { &setup.touch.control_type, &touch_controls_text },
7324 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7325 { &setup.touch.move_distance, &move_distance_text },
7327 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7328 { &setup.touch.drop_distance, &drop_distance_text },
7330 { &setup.touch.transparency, execSetupChooseTransparency },
7331 { &setup.touch.transparency, &transparency_text },
7333 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7334 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7336 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7337 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7339 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7340 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7342 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7343 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7345 { &setup.internal.menu_game, execSetupGame },
7346 { &setup.internal.menu_engines, execSetupEngines },
7347 { &setup.internal.menu_editor, execSetupEditor },
7348 { &setup.internal.menu_graphics, execSetupGraphics },
7349 { &setup.internal.menu_sound, execSetupSound },
7350 { &setup.internal.menu_artwork, execSetupArtwork },
7351 { &setup.internal.menu_input, execSetupInput },
7352 { &setup.internal.menu_touch, execSetupTouch },
7353 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7354 { &setup.internal.menu_exit, execExitSetup },
7355 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7360 void setHideRelatedSetupEntries(void)
7364 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7365 if (hideSetupEntry(hide_related_entry_list[i].value))
7366 setHideSetupEntry(hide_related_entry_list[i].related_value);
7369 static struct TokenInfo setup_info_main[] =
7371 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7372 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7373 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7374 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7375 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7376 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7377 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7378 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7379 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7380 { TYPE_EMPTY, NULL, "" },
7381 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7382 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7387 static struct TokenInfo setup_info_game[] =
7389 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7390 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7391 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7392 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7393 { TYPE_STRING, &network_server_text, "" },
7394 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7395 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7396 { TYPE_STRING, &scores_type_text, "" },
7397 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7398 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7399 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7400 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7401 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7402 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7403 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7404 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7405 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7406 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7407 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7408 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7409 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7410 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7411 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7412 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7413 { TYPE_STRING, &game_speed_text, "" },
7414 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7416 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7417 { TYPE_STRING, &scroll_delay_text, "" },
7419 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7420 { TYPE_STRING, &snapshot_mode_text, "" },
7421 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7422 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7423 { TYPE_EMPTY, NULL, "" },
7424 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7429 static struct TokenInfo setup_info_engines[] =
7431 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7432 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7433 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7434 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7435 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7436 { TYPE_EMPTY, NULL, "" },
7437 { TYPE_HEADLINE, NULL, "Supaplex" },
7438 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7439 { TYPE_EMPTY, NULL, "" },
7440 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7445 static struct TokenInfo setup_info_editor[] =
7448 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7449 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7450 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7451 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7452 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7453 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7454 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7455 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7456 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7457 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7459 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7460 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7462 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7464 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7465 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7466 { TYPE_EMPTY, NULL, "" },
7468 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7469 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7470 { TYPE_EMPTY, NULL, "" },
7472 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7473 { TYPE_EMPTY, NULL, "" },
7474 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7475 { TYPE_EMPTY, NULL, "" },
7476 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7481 static struct TokenInfo setup_info_graphics[] =
7483 #if !defined(PLATFORM_ANDROID)
7484 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7485 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7486 { TYPE_STRING, &window_size_text, "" },
7487 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7488 { TYPE_STRING, &scaling_type_text, "" },
7489 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7490 { TYPE_STRING, &rendering_mode_text, "" },
7493 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7494 { TYPE_STRING, &scroll_delay_text, "" },
7496 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7497 { TYPE_STRING, &vsync_mode_text, "" },
7498 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7499 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7500 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7501 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7502 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7503 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7504 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7505 { TYPE_EMPTY, NULL, "" },
7506 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7511 static struct TokenInfo setup_info_sound[] =
7513 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7514 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7515 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7516 { TYPE_EMPTY, NULL, "" },
7517 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7518 { TYPE_STRING, &volume_simple_text, "" },
7519 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7520 { TYPE_STRING, &volume_loops_text, "" },
7521 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7522 { TYPE_STRING, &volume_music_text, "" },
7523 { TYPE_EMPTY, NULL, "" },
7524 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7529 static struct TokenInfo setup_info_artwork[] =
7531 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7532 { TYPE_STRING, &graphics_set_name, "" },
7533 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7534 { TYPE_STRING, &sounds_set_name, "" },
7535 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7536 { TYPE_STRING, &music_set_name, "" },
7537 { TYPE_EMPTY, NULL, "" },
7538 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7539 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7540 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7541 { TYPE_EMPTY, NULL, "" },
7542 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7547 static struct TokenInfo setup_info_input[] =
7549 { TYPE_SWITCH, NULL, "Player:" },
7550 { TYPE_SWITCH, NULL, "Device:" },
7551 { TYPE_SWITCH, NULL, "" },
7552 { TYPE_SKIPPABLE, NULL, "" },
7553 { TYPE_EMPTY, NULL, "" },
7554 { TYPE_EMPTY, NULL, "" },
7555 { TYPE_EMPTY, NULL, "" },
7556 { TYPE_EMPTY, NULL, "" },
7557 { TYPE_EMPTY, NULL, "" },
7558 { TYPE_EMPTY, NULL, "" },
7559 { TYPE_EMPTY, NULL, "" },
7560 { TYPE_EMPTY, NULL, "" },
7561 { TYPE_SKIPPABLE, NULL, "" },
7562 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7567 static struct TokenInfo setup_info_touch[] =
7569 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7570 { TYPE_STRING, &touch_controls_text, "" },
7571 { TYPE_EMPTY, NULL, "" },
7572 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7577 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7579 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7580 { TYPE_STRING, &touch_controls_text, "" },
7581 { TYPE_EMPTY, NULL, "" },
7582 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7583 { TYPE_STRING, &grid_size_text[0][0], "" },
7584 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7585 { TYPE_STRING, &grid_size_text[0][1], "" },
7586 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7587 { TYPE_STRING, &transparency_text, "" },
7588 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7589 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7590 { TYPE_EMPTY, NULL, "" },
7591 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7592 { TYPE_EMPTY, NULL, "" },
7593 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7598 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7600 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7601 { TYPE_STRING, &touch_controls_text, "" },
7602 { TYPE_EMPTY, NULL, "" },
7603 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7604 { TYPE_STRING, &grid_size_text[1][0], "" },
7605 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7606 { TYPE_STRING, &grid_size_text[1][1], "" },
7607 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7608 { TYPE_STRING, &transparency_text, "" },
7609 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7610 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7611 { TYPE_EMPTY, NULL, "" },
7612 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7613 { TYPE_EMPTY, NULL, "" },
7614 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7619 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7621 setup_info_touch_virtual_buttons_0,
7622 setup_info_touch_virtual_buttons_1
7625 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7627 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7628 { TYPE_STRING, &touch_controls_text, "" },
7629 { TYPE_EMPTY, NULL, "" },
7630 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7631 { TYPE_STRING, &move_distance_text, "" },
7632 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7633 { TYPE_STRING, &drop_distance_text, "" },
7634 { TYPE_EMPTY, NULL, "" },
7635 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7640 static struct TokenInfo setup_info_shortcuts[] =
7642 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7643 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7644 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7645 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7646 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7647 { TYPE_EMPTY, NULL, "" },
7648 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7653 static struct TokenInfo setup_info_shortcuts_1[] =
7655 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7656 { TYPE_KEY, &setup.shortcut.save_game, "" },
7657 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7658 { TYPE_KEY, &setup.shortcut.load_game, "" },
7659 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7660 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7661 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7662 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7663 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7664 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7665 { TYPE_EMPTY, NULL, "" },
7666 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7667 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7668 { TYPE_EMPTY, NULL, "" },
7669 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7674 static struct TokenInfo setup_info_shortcuts_2[] =
7676 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7677 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7678 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7679 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7680 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7681 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7682 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7683 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7684 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7685 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7686 { TYPE_EMPTY, NULL, "" },
7687 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7692 static struct TokenInfo setup_info_shortcuts_3[] =
7694 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7695 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7696 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7697 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7698 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7699 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7700 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7701 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7702 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7703 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7704 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7705 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7706 { TYPE_EMPTY, NULL, "" },
7707 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7712 static struct TokenInfo setup_info_shortcuts_4[] =
7714 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7715 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7716 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7717 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7718 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7719 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7720 { TYPE_EMPTY, NULL, "" },
7721 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7726 static struct TokenInfo setup_info_shortcuts_5[] =
7728 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7729 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7730 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7731 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7732 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7733 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7734 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7735 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7736 { TYPE_EMPTY, NULL, "" },
7737 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7742 static Key getSetupKey(void)
7744 Key key = KSYM_UNDEFINED;
7745 boolean got_key_event = FALSE;
7747 while (!got_key_event)
7751 if (NextValidEvent(&event))
7755 case EVENT_KEYPRESS:
7757 key = GetEventKey((KeyEvent *)&event, TRUE);
7759 // press 'Escape' or 'Enter' to keep the existing key binding
7760 if (key == KSYM_Escape || key == KSYM_Return)
7761 key = KSYM_UNDEFINED; // keep old value
7763 got_key_event = TRUE;
7767 case EVENT_KEYRELEASE:
7768 key_joystick_mapping = 0;
7772 HandleOtherEvents(&event);
7783 static int getSetupValueFont(int type, void *value)
7785 if (type & TYPE_GHOSTED)
7786 return FONT_OPTION_OFF;
7787 else if (type & TYPE_KEY)
7788 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7789 else if (type & TYPE_STRING)
7790 return FONT_VALUE_2;
7791 else if (type & TYPE_ECS_AGA)
7792 return FONT_VALUE_1;
7793 else if (type & TYPE_BOOLEAN_STYLE)
7794 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7795 else if (type & TYPE_YES_NO_AUTO)
7796 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7797 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7798 else if (type & TYPE_PLAYER)
7799 return FONT_VALUE_1;
7801 return FONT_VALUE_1;
7804 static int getSetupValueFontNarrow(int type, int font_nr)
7806 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7807 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7808 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7812 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7814 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7815 struct TokenInfo *si = &setup_info[si_pos];
7816 boolean font_draw_xoffset_modified = FALSE;
7817 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7818 int font_draw_xoffset_old = -1;
7819 int xoffset = (scrollbar_needed ? -1 : 0);
7820 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7821 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7822 int xpos = menu_screen_value_xpos;
7823 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7824 int startx = mSX + xpos * 32;
7825 int starty = mSY + ypos * 32;
7826 int type = si->type;
7827 void *value = si->value;
7828 char *value_string = getSetupValue(type, value);
7829 int font_nr_default = getSetupValueFont(type, value);
7830 int font_width_default = getFontWidth(font_nr_default);
7831 int font_nr = font_nr_default;
7834 if (value_string == NULL)
7837 if (type & TYPE_KEY)
7839 xpos = MENU_SCREEN_START_XPOS;
7841 if (type & TYPE_QUERY)
7842 value_string = "<press key>";
7844 else if (type & TYPE_STRING)
7846 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7848 xpos = MENU_SCREEN_START_XPOS;
7850 if (strlen(value_string) > max_value_len)
7851 value_string[max_value_len] = '\0';
7853 else if (type & TYPE_YES_NO_AUTO)
7855 xpos = menu_screen_value_xpos - 1;
7857 else if (type & TYPE_PLAYER)
7859 int displayed_player_nr = *(int *)value + 1;
7861 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7864 startx = mSX + xpos * 32;
7865 starty = mSY + ypos * 32;
7867 // special check if right-side setup values moved left due to scrollbar
7868 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7870 int max_menu_text_length = 26; // maximum text length for classic menu
7871 int font_xoffset = getFontDrawOffsetX(font_nr);
7872 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7873 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7874 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7875 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7877 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7879 // when using narrow font, left-shifting text "auto" not needed
7880 if (type & TYPE_YES_NO_AUTO)
7884 startx = mSX + xpos * 32;
7886 font_nr = getSetupValueFontNarrow(type, font_nr);
7890 // downward compatibility correction for Juergen Bonhagen's menu settings
7891 if (setup_mode != SETUP_MODE_INPUT)
7893 int max_menu_text_length_big = (menu_screen_value_xpos -
7894 MENU_SCREEN_START_XPOS);
7895 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7896 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7897 int font1_xoffset = getFontDrawOffsetX(font_nr);
7898 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7899 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7900 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7901 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7902 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7903 boolean correct_font_draw_xoffset = FALSE;
7905 if (xpos == MENU_SCREEN_START_XPOS &&
7906 startx + font1_xoffset < text_startx + text_font_xoffset)
7907 correct_font_draw_xoffset = TRUE;
7909 if (xpos == menu_screen_value_xpos &&
7910 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7911 correct_font_draw_xoffset = TRUE;
7913 // check if setup value would overlap with setup text when printed
7914 // (this can happen for extreme/wrong values for font draw offset)
7915 if (correct_font_draw_xoffset)
7917 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7918 font_draw_xoffset_modified = TRUE;
7920 if (type & TYPE_KEY)
7921 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7922 else if (!(type & TYPE_STRING))
7923 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7924 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7928 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7929 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7931 DrawText(startx, starty, value_string, font_nr);
7933 if (type & TYPE_PLAYER)
7935 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7936 int player_nr = *(int *)value;
7937 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7938 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7939 int startx2 = startx + xoff;
7940 int starty2 = starty + yoff;
7942 if (DrawingOnBackground(startx2, starty2))
7943 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7945 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7946 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7949 if (font_draw_xoffset_modified)
7950 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7953 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7955 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7956 struct TokenInfo *si = &setup_info[si_pos];
7958 if (si->type & TYPE_BOOLEAN_STYLE)
7960 *(boolean *)si->value ^= TRUE;
7962 else if (si->type & TYPE_YES_NO_AUTO)
7966 (*(int *)si->value == AUTO ? TRUE :
7967 *(int *)si->value == TRUE ? FALSE : AUTO) :
7968 (*(int *)si->value == TRUE ? AUTO :
7969 *(int *)si->value == AUTO ? FALSE : TRUE));
7971 else if (si->type & TYPE_KEY)
7975 si->type |= TYPE_QUERY;
7976 drawSetupValue(screen_pos, setup_info_pos_raw);
7977 si->type &= ~TYPE_QUERY;
7979 key = getSetupKey();
7980 if (key != KSYM_UNDEFINED)
7981 *(Key *)si->value = key;
7983 else if (si->type & TYPE_PLAYER)
7985 int player_nr = *(int *)si->value;
7990 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7992 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7995 drawSetupValue(screen_pos, setup_info_pos_raw);
7997 // fullscreen state may have changed at this point
7998 if (si->value == &setup.fullscreen)
7999 ToggleFullscreenIfNeeded();
8001 // network mode may have changed at this point
8002 if (si->value == &setup.network_mode)
8003 ToggleNetworkModeIfNeeded();
8005 // API server mode may have changed at this point
8006 if (si->value == &setup.use_api_server)
8007 ToggleUseApiServerIfNeeded();
8009 // game speed list may have changed at this point
8010 if (si->value == &setup.game_speed_extended)
8011 ToggleGameSpeedsListIfNeeded();
8014 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8016 static struct TokenInfo *setup_info_final = NULL;
8021 // determine maximum list size of target list
8022 while (setup_info_orig[list_size++].type != 0);
8024 // free, allocate and clear memory for target list
8025 checked_free(setup_info_final);
8026 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8028 // copy setup info list without setup entries marked as hidden
8029 for (i = 0; setup_info_orig[i].type != 0; i++)
8031 // skip setup entries configured to be hidden
8032 if (hideSetupEntry(setup_info_orig[i].value))
8035 // skip skippable setup entries if screen is lower than usual
8036 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8037 setup_info_orig[i].type == TYPE_SKIPPABLE)
8040 setup_info_final[list_pos++] = setup_info_orig[i];
8043 return setup_info_final;
8046 static void DrawSetupScreen_Generic(void)
8048 int fade_mask = REDRAW_FIELD;
8049 boolean redraw_all = FALSE;
8050 char *title_string = NULL;
8054 fade_mask = REDRAW_ALL;
8057 FadeMenuSoundsAndMusic();
8059 FreeScreenGadgets();
8060 CreateScreenGadgets();
8062 if (redraw_mask & REDRAW_ALL)
8067 // needed if different viewport properties defined for setup screen
8068 ChangeViewportPropertiesIfNeeded();
8070 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8074 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8076 if (setup_mode == SETUP_MODE_MAIN)
8078 setup_info = setup_info_main;
8079 title_string = STR_SETUP_MAIN;
8081 else if (setup_mode == SETUP_MODE_GAME)
8083 setup_info = setup_info_game;
8084 title_string = STR_SETUP_GAME;
8086 else if (setup_mode == SETUP_MODE_ENGINES)
8088 setup_info = setup_info_engines;
8089 title_string = STR_SETUP_ENGINES;
8091 else if (setup_mode == SETUP_MODE_EDITOR)
8093 setup_info = setup_info_editor;
8094 title_string = STR_SETUP_EDITOR;
8096 else if (setup_mode == SETUP_MODE_GRAPHICS)
8098 setup_info = setup_info_graphics;
8099 title_string = STR_SETUP_GRAPHICS;
8101 else if (setup_mode == SETUP_MODE_SOUND)
8103 setup_info = setup_info_sound;
8104 title_string = STR_SETUP_SOUND;
8106 else if (setup_mode == SETUP_MODE_ARTWORK)
8108 setup_info = setup_info_artwork;
8109 title_string = STR_SETUP_ARTWORK;
8111 else if (setup_mode == SETUP_MODE_TOUCH)
8113 setup_info = setup_info_touch;
8114 title_string = STR_SETUP_TOUCH;
8116 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8117 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8118 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8119 setup_info = setup_info_touch_wipe_gestures;
8121 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8123 setup_info = setup_info_shortcuts;
8124 title_string = STR_SETUP_SHORTCUTS;
8126 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8128 setup_info = setup_info_shortcuts_1;
8129 title_string = STR_SETUP_SHORTCUTS;
8131 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8133 setup_info = setup_info_shortcuts_2;
8134 title_string = STR_SETUP_SHORTCUTS;
8136 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8138 setup_info = setup_info_shortcuts_3;
8139 title_string = STR_SETUP_SHORTCUTS;
8141 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8143 setup_info = setup_info_shortcuts_4;
8144 title_string = STR_SETUP_SHORTCUTS;
8146 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8148 setup_info = setup_info_shortcuts_5;
8149 title_string = STR_SETUP_SHORTCUTS;
8152 // use modified setup info without setup entries marked as hidden
8153 setup_info = getSetupInfoFinal(setup_info);
8155 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8157 // determine maximal number of setup entries that can be displayed on screen
8159 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8162 // determine maximal number of setup entries available for this setup screen
8164 for (i = 0; setup_info[i].type != 0; i++)
8167 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8169 MapScreenGadgets(max_setup_info);
8172 redraw_mask = fade_mask = REDRAW_ALL;
8174 DrawMaskedBorder(fade_mask);
8179 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8181 menu_info = setup_info;
8183 HandleMenuScreen(mx, my, dx, dy, button,
8184 setup_mode, num_setup_info, max_setup_info);
8187 static void DrawSetupScreen_Input(void)
8191 FadeOut(REDRAW_FIELD);
8195 setup_info = getSetupInfoFinal(setup_info_input);
8197 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8199 for (i = 0; setup_info[i].type != 0; i++)
8201 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8202 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8203 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8204 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8205 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8206 initCursor(i, IMG_MENU_BUTTON);
8208 DrawCursorAndText_Setup(i, -1, FALSE);
8211 // create gadgets for setup input menu screen
8212 FreeScreenGadgets();
8213 CreateScreenGadgets();
8215 // map gadgets for setup input menu screen
8216 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8218 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8220 FadeIn(REDRAW_FIELD);
8223 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8225 if (device_name == NULL)
8228 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8231 if (strlen(device_name) > 1)
8233 char c1 = device_name[strlen(device_name) - 1];
8234 char c2 = device_name[strlen(device_name) - 2];
8236 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8237 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8240 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8241 strlen(device_name));
8244 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8247 static struct SetupKeyboardInfo custom_key;
8254 { &custom_key.left, "Axis/Pad Left" },
8255 { &custom_key.right, "Axis/Pad Right" },
8256 { &custom_key.up, "Axis/Pad Up" },
8257 { &custom_key.down, "Axis/Pad Down" },
8258 { &custom_key.snap, "Button 1/A/X" },
8259 { &custom_key.drop, "Button 2/B/Y" }
8261 static char *joystick_name[MAX_PLAYERS] =
8268 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8269 int font_nr_info = FONT_MENU_1;
8270 int font_nr_name = FONT_VALUE_OLD;
8271 int font_nr_on = FONT_VALUE_1;
8272 int font_nr_off = FONT_VALUE_OLD;
8275 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8277 font_nr_info = FONT_MENU_2;
8278 font_nr_on = FONT_VALUE_NARROW;
8279 font_nr_off = FONT_VALUE_OLD_NARROW;
8282 custom_key = setup.input[player_nr].key;
8284 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8285 FONT_INPUT_1_ACTIVE);
8287 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8289 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8290 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8292 if (setup.input[player_nr].use_joystick)
8294 char *device_name = setup.input[player_nr].joy.device_name;
8295 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8296 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8297 char *text = joystick_name[joystick_nr];
8298 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8300 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8301 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8305 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8306 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8309 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8310 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8314 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8315 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8316 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8317 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8319 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8320 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8321 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8322 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8323 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8324 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8326 for (i = 0; i < 6; i++)
8328 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8330 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8332 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8333 (setup.input[player_nr].use_joystick ?
8335 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8339 static int input_player_nr = 0;
8341 static void HandleSetupScreen_Input_Player(int step, int direction)
8343 int old_player_nr = input_player_nr;
8346 new_player_nr = old_player_nr + step * direction;
8347 if (new_player_nr < 0)
8349 if (new_player_nr > MAX_PLAYERS - 1)
8350 new_player_nr = MAX_PLAYERS - 1;
8352 if (new_player_nr != old_player_nr)
8354 input_player_nr = new_player_nr;
8356 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8360 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8362 static int choice = 0;
8365 int pos_start = SETUPINPUT_SCREEN_POS_START;
8366 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8367 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8368 int pos_end = SETUPINPUT_SCREEN_POS_END;
8370 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8374 for (i = 0; setup_info_input[i].type != 0; i++)
8376 // adjust menu structure according to skipped setup entries
8377 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8385 if (button == MB_MENU_INITIALIZE)
8387 // input setup menu may have changed size due to graphics configuration
8388 if (choice >= pos_empty1)
8391 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8393 DrawCursorAndText_Setup(choice, -1, TRUE);
8397 else if (button == MB_MENU_LEAVE)
8399 setup_mode = SETUP_MODE_MAIN;
8406 if (mx || my) // mouse input
8408 x = (mx - mSX) / 32;
8409 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8411 else if (dx || dy) // keyboard input
8413 if (dx && choice == 0)
8414 x = (dx < 0 ? 10 : 12);
8415 else if ((dx && choice == 1) ||
8416 (dx == -1 && choice == pos_end))
8417 button = MB_MENU_CHOICE;
8421 if (y >= pos_empty1 && y <= pos_empty2)
8422 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8425 if (y == 0 && dx != 0 && button)
8427 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8429 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8430 y >= pos_start && y <= pos_end &&
8431 !(y >= pos_empty1 && y <= pos_empty2))
8437 DrawCursorAndText_Setup(choice, -1, FALSE);
8438 DrawCursorAndText_Setup(y, -1, TRUE);
8440 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8449 char *device_name = setup.input[input_player_nr].joy.device_name;
8451 if (!setup.input[input_player_nr].use_joystick)
8453 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8455 setJoystickDeviceToNr(device_name, new_device_nr);
8456 setup.input[input_player_nr].use_joystick = TRUE;
8460 int device_nr = getJoystickNrFromDeviceName(device_name);
8461 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8463 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8464 setup.input[input_player_nr].use_joystick = FALSE;
8466 setJoystickDeviceToNr(device_name, new_device_nr);
8469 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8473 if (setup.input[input_player_nr].use_joystick)
8474 ConfigureJoystick(input_player_nr);
8476 CustomizeKeyboard(input_player_nr);
8478 else if (y == pos_end)
8484 setup_mode = SETUP_MODE_MAIN;
8491 static boolean CustomizeKeyboardMain(int player_nr)
8495 boolean finished = FALSE;
8496 static struct SetupKeyboardInfo custom_key;
8501 } customize_step[] =
8503 { &custom_key.left, "Move Left" },
8504 { &custom_key.right, "Move Right" },
8505 { &custom_key.up, "Move Up" },
8506 { &custom_key.down, "Move Down" },
8507 { &custom_key.snap, "Snap Field" },
8508 { &custom_key.drop, "Drop Element" }
8510 int font_nr_old = FONT_VALUE_OLD;
8511 int font_nr_new = FONT_VALUE_1;
8512 boolean success = FALSE;
8514 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8516 font_nr_old = FONT_VALUE_OLD_NARROW;
8517 font_nr_new = FONT_VALUE_NARROW;
8520 // read existing key bindings from player setup
8521 custom_key = setup.input[player_nr].key;
8524 FadeOut(REDRAW_FIELD);
8528 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8531 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8532 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8533 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8534 "Key:", FONT_INPUT_1_ACTIVE);
8535 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8536 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8538 FadeIn(REDRAW_FIELD);
8544 if (NextValidEvent(&event))
8548 case EVENT_KEYPRESS:
8550 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8552 // press 'Escape' to abort and keep the old key bindings
8553 if (key == KSYM_Escape)
8555 FadeSkipNextFadeIn();
8562 // press 'Enter' to keep the existing key binding
8563 if (key == KSYM_Return)
8564 key = *customize_step[step_nr].key;
8566 // check if key already used
8567 for (i = 0; i < step_nr; i++)
8568 if (*customize_step[i].key == key)
8573 // got new key binding
8574 *customize_step[step_nr].key = key;
8575 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8577 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8578 getKeyNameFromKey(key), font_nr_new);
8581 // un-highlight last query
8582 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8583 customize_step[step_nr - 1].text, FONT_MENU_1);
8584 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8585 "Key:", FONT_MENU_1);
8587 // all keys configured
8596 // query next key binding
8597 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8598 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8599 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8600 "Key:", FONT_INPUT_1_ACTIVE);
8601 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8602 getKeyNameFromKey(*customize_step[step_nr].key),
8607 case EVENT_KEYRELEASE:
8608 key_joystick_mapping = 0;
8612 HandleOtherEvents(&event);
8620 // write new key bindings back to player setup, if successfully finished
8622 setup.input[player_nr].key = custom_key;
8627 void CustomizeKeyboard(int player_nr)
8629 boolean success = CustomizeKeyboardMain(player_nr);
8633 int font_nr = FONT_TITLE_1;
8634 int font_height = getFontHeight(font_nr);
8635 int ypos1 = SYSIZE / 2 - font_height * 2;
8636 int ypos2 = SYSIZE / 2 - font_height * 1;
8637 unsigned int wait_frame_delay = 0;
8638 unsigned int wait_frame_delay_value = 2000;
8640 ResetDelayCounter(&wait_frame_delay);
8644 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8645 DrawTextSCentered(ypos2, font_nr, "configured!");
8647 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8653 DrawSetupScreen_Input();
8656 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8658 #define MARKER_BUTTON 1
8659 #define MARKER_AXIS_X 2
8660 #define MARKER_AXIS_Y 3
8662 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8664 static boolean bitmaps_initialized = FALSE;
8665 boolean screen_initialized = FALSE;
8666 static Bitmap *controller, *button, *axis_x, *axis_y;
8668 boolean success = TRUE;
8669 boolean done = FALSE, next = FALSE;
8671 int alpha = 200, alpha_step = -1;
8672 int alpha_ticks = 0;
8673 char mapping[4096], temp[256];
8674 int font_name = MENU_SETUP_FONT_TITLE;
8675 int font_info = MENU_SETUP_FONT_TEXT;
8676 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8677 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8678 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8679 int ystep_name = getMenuTextStep(spacing_name, font_name);
8680 int ystep_line = getMenuTextStep(spacing_line, font_info);
8681 int ystep_para = getMenuTextStep(spacing_para, font_info);
8689 int axis, button, hat, hat_value;
8692 *step, *prev_step, steps[] =
8694 { 356, 155, MARKER_BUTTON, "a", },
8695 { 396, 122, MARKER_BUTTON, "b", },
8696 { 320, 125, MARKER_BUTTON, "x", },
8697 { 358, 95, MARKER_BUTTON, "y", },
8698 { 162, 125, MARKER_BUTTON, "back", },
8699 { 216, 125, MARKER_BUTTON, "guide", },
8700 { 271, 125, MARKER_BUTTON, "start", },
8701 { 110, 200, MARKER_BUTTON, "dpleft", },
8702 { 146, 228, MARKER_BUTTON, "dpdown", },
8703 { 178, 200, MARKER_BUTTON, "dpright", },
8704 { 146, 172, MARKER_BUTTON, "dpup", },
8705 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8706 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8707 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8708 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8709 { 73, 141, MARKER_BUTTON, "leftstick", },
8710 { 282, 210, MARKER_BUTTON, "rightstick", },
8711 { 73, 141, MARKER_AXIS_X, "leftx", },
8712 { 73, 141, MARKER_AXIS_Y, "lefty", },
8713 { 282, 210, MARKER_AXIS_X, "rightx", },
8714 { 282, 210, MARKER_AXIS_Y, "righty", },
8717 unsigned int event_frame_delay = 0;
8718 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8720 ResetDelayCounter(&event_frame_delay);
8722 if (!bitmaps_initialized)
8724 controller = LoadCustomImage("joystick/controller.png");
8725 button = LoadCustomImage("joystick/button.png");
8726 axis_x = LoadCustomImage("joystick/axis_x.png");
8727 axis_y = LoadCustomImage("joystick/axis_y.png");
8729 bitmaps_initialized = TRUE;
8732 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8735 // print info about the joystick we are watching
8736 Debug("joystick", "watching joystick %d: (%s)",
8737 SDL_JoystickInstanceID(joystick), name);
8738 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8739 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8740 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8743 // initialize mapping with GUID and name
8744 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8746 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8747 temp, name, SDL_GetPlatform());
8749 // loop through all steps (buttons and axes), getting joystick events
8750 for (i = 0; i < SDL_arraysize(steps) && !done;)
8752 Bitmap *marker = button; // initialize with reliable default value
8755 strcpy(step->mapping, mapping);
8759 step->hat_value = -1;
8761 marker = (step->marker == MARKER_BUTTON ? button :
8762 step->marker == MARKER_AXIS_X ? axis_x :
8763 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8767 while (!done && !next)
8769 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8770 alpha_ticks = SDL_GetTicks();
8777 else if (alpha < 128)
8783 int controller_x = SX + (SXSIZE - controller->width) / 2;
8784 int controller_y = SY + ystep_line;
8786 int marker_x = controller_x + step->x;
8787 int marker_y = controller_y + step->y;
8789 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8790 int ystart2 = ystart1 + ystep_name + ystep_line;
8794 DrawTextSCentered(ystart1, font_name, name);
8796 DrawTextSCentered(ystart2, font_info,
8797 "Press buttons and move axes on");
8798 ystart2 += ystep_line;
8799 DrawTextSCentered(ystart2, font_info,
8800 "your controller when indicated.");
8801 ystart2 += ystep_line;
8802 DrawTextSCentered(ystart2, font_info,
8803 "(Your controller may look different.)");
8804 ystart2 += ystep_para;
8806 #if defined(PLATFORM_ANDROID)
8807 DrawTextSCentered(ystart2, font_info,
8808 "To correct a mistake,");
8809 ystart2 += ystep_line;
8810 DrawTextSCentered(ystart2, font_info,
8811 "press the 'back' button.");
8812 ystart2 += ystep_line;
8813 DrawTextSCentered(ystart2, font_info,
8814 "To skip a button or axis,");
8815 ystart2 += ystep_line;
8816 DrawTextSCentered(ystart2, font_info,
8817 "press the 'menu' button.");
8819 DrawTextSCentered(ystart2, font_info,
8820 "To correct a mistake,");
8821 ystart2 += ystep_line;
8822 DrawTextSCentered(ystart2, font_info,
8823 "press the 'backspace' key.");
8824 ystart2 += ystep_line;
8825 DrawTextSCentered(ystart2, font_info,
8826 "To skip a button or axis,");
8827 ystart2 += ystep_line;
8828 DrawTextSCentered(ystart2, font_info,
8829 "press the 'return' key.");
8830 ystart2 += ystep_line;
8831 DrawTextSCentered(ystart2, font_info,
8832 "To exit, press the 'escape' key.");
8835 BlitBitmapMasked(controller, drawto, 0, 0,
8836 controller->width, controller->height,
8837 controller_x, controller_y);
8839 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8840 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8842 BlitBitmapMasked(marker, drawto, 0, 0,
8843 marker->width, marker->height,
8844 marker_x, marker_y);
8846 if (!screen_initialized)
8847 FadeIn(REDRAW_FIELD);
8851 screen_initialized = TRUE;
8853 while (NextValidEvent(&event))
8857 case SDL_JOYAXISMOTION:
8858 if (event.jaxis.value > 20000 ||
8859 event.jaxis.value < -20000)
8861 for (j = 0; j < i; j++)
8862 if (steps[j].axis == event.jaxis.axis)
8867 if (step->marker != MARKER_AXIS_X &&
8868 step->marker != MARKER_AXIS_Y)
8871 step->axis = event.jaxis.axis;
8872 strcat(mapping, step->field);
8873 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8874 strcat(mapping, temp);
8882 case SDL_JOYHATMOTION:
8883 // ignore centering; we're probably just coming back
8884 // to the center from the previous item we set
8885 if (event.jhat.value == SDL_HAT_CENTERED)
8888 for (j = 0; j < i; j++)
8889 if (steps[j].hat == event.jhat.hat &&
8890 steps[j].hat_value == event.jhat.value)
8895 step->hat = event.jhat.hat;
8896 step->hat_value = event.jhat.value;
8897 strcat(mapping, step->field);
8898 snprintf(temp, sizeof(temp), ":h%u.%u,",
8899 event.jhat.hat, event.jhat.value );
8900 strcat(mapping, temp);
8907 case SDL_JOYBALLMOTION:
8910 case SDL_JOYBUTTONUP:
8911 for (j = 0; j < i; j++)
8912 if (steps[j].button == event.jbutton.button)
8917 step->button = event.jbutton.button;
8918 strcat(mapping, step->field);
8919 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8920 strcat(mapping, temp);
8927 case SDL_FINGERDOWN:
8928 case SDL_MOUSEBUTTONDOWN:
8936 if (event.key.keysym.sym == KSYM_BackSpace ||
8937 event.key.keysym.sym == KSYM_Back)
8949 prev_step = &steps[i - 1];
8950 strcpy(mapping, prev_step->mapping);
8957 if (event.key.keysym.sym == KSYM_space ||
8958 event.key.keysym.sym == KSYM_Return ||
8959 event.key.keysym.sym == KSYM_Menu)
8968 if (event.key.keysym.sym == KSYM_Escape)
8978 program.exit_function(0);
8985 // do not handle events for longer than standard frame delay period
8986 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8995 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8998 // activate mapping for this game
8999 SDL_GameControllerAddMapping(mapping);
9001 // save mapping to personal mappings
9002 SaveSetup_AddGameControllerMapping(mapping);
9005 // wait until the last pending event was removed from event queue
9006 while (NextValidEvent(&event));
9011 static int ConfigureJoystickMain(int player_nr)
9013 char *device_name = setup.input[player_nr].joy.device_name;
9014 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9015 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9016 int success = FALSE;
9019 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9020 return JOYSTICK_NOT_AVAILABLE;
9022 if (!joystick_active || !setup.input[player_nr].use_joystick)
9023 return JOYSTICK_NOT_AVAILABLE;
9026 FadeOut(REDRAW_FIELD);
9028 // close all joystick devices (potentially opened as game controllers)
9029 for (i = 0; i < SDL_NumJoysticks(); i++)
9030 SDLCloseJoystick(i);
9032 // open joystick device as plain joystick to configure as game controller
9033 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9035 // as the joystick was successfully opened before, this should not happen
9036 if (joystick == NULL)
9039 // create new game controller mapping (buttons and axes) for joystick device
9040 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9042 // close joystick (and maybe re-open as configured game controller later)
9043 SDL_JoystickClose(joystick);
9045 // re-open all joystick devices (potentially as game controllers)
9046 for (i = 0; i < SDL_NumJoysticks(); i++)
9049 // clear all joystick input actions for all joystick devices
9050 SDLClearJoystickState();
9052 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9055 void ConfigureJoystick(int player_nr)
9057 boolean state = ConfigureJoystickMain(player_nr);
9059 if (state != JOYSTICK_NOT_CONFIGURED)
9061 boolean success = (state == JOYSTICK_CONFIGURED);
9062 char message1[MAX_OUTPUT_LINESIZE + 1];
9063 char *message2 = (success ? "configured!" : "not available!");
9064 char *device_name = setup.input[player_nr].joy.device_name;
9065 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9066 int font_nr = FONT_TITLE_1;
9067 int font_height = getFontHeight(font_nr);
9068 int ypos1 = SYSIZE / 2 - font_height * 2;
9069 int ypos2 = SYSIZE / 2 - font_height * 1;
9070 unsigned int wait_frame_delay = 0;
9071 unsigned int wait_frame_delay_value = 2000;
9073 ResetDelayCounter(&wait_frame_delay);
9077 sprintf(message1, "Joystick %d", nr);
9079 DrawTextSCentered(ypos1, font_nr, message1);
9080 DrawTextSCentered(ypos2, font_nr, message2);
9082 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9088 DrawSetupScreen_Input();
9091 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9093 if (y < video.screen_height / 3)
9095 // remap touch gadgets to access upper part of the screen
9096 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9097 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9099 else if (y > 2 * video.screen_height / 3)
9101 // remap touch gadgets to access lower part of the screen
9102 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9103 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9107 static boolean ConfigureVirtualButtonsMain(void)
9109 static char *customize_step_text[] =
9118 char grid_button[] =
9120 CHAR_GRID_BUTTON_LEFT,
9121 CHAR_GRID_BUTTON_RIGHT,
9122 CHAR_GRID_BUTTON_UP,
9123 CHAR_GRID_BUTTON_DOWN,
9124 CHAR_GRID_BUTTON_SNAP,
9125 CHAR_GRID_BUTTON_DROP
9134 int font_nr = FONT_INPUT_1_ACTIVE;
9135 int font_height = getFontHeight(font_nr);
9136 int ypos1 = SYSIZE / 2 - font_height * 2;
9137 int ypos2 = SYSIZE / 2 - font_height * 1;
9138 boolean success = FALSE;
9139 boolean finished = FALSE;
9141 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9142 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9143 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9144 boolean set_grid_button = FALSE;
9145 int nr = GRID_ACTIVE_NR();
9148 for (x = 0; x < MAX_GRID_XSIZE; x++)
9149 for (y = 0; y < MAX_GRID_YSIZE; y++)
9150 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9152 overlay.grid_button_highlight = grid_button[step_nr];
9157 FadeOut(REDRAW_FIELD);
9161 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9162 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9163 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9165 FadeIn(REDRAW_FIELD);
9167 SetOverlayShowGrid(TRUE);
9169 // map gadgets for setup touch buttons menu screen
9170 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9176 while (NextValidEvent(&event))
9178 int action = ACTION_NONE;
9180 // ---------- handle events and set the resulting action ----------
9186 UserEvent *user = (UserEvent *)&event;
9187 int id = user->value1;
9189 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9190 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9191 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9192 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9197 case EVENT_KEYPRESS:
9199 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9201 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9202 key == KSYM_BackSpace ||
9203 key == KSYM_Back ? ACTION_BACK :
9204 key == KSYM_Return ||
9206 key == KSYM_space ? ACTION_NEXT :
9211 case EVENT_KEYRELEASE:
9212 key_joystick_mapping = 0;
9215 case EVENT_BUTTONPRESS:
9216 case EVENT_BUTTONRELEASE:
9218 ButtonEvent *button = (ButtonEvent *)&event;
9220 motion_status = FALSE;
9222 if (button->type == EVENT_BUTTONPRESS)
9223 button_status = button->button;
9225 button_status = MB_RELEASED;
9227 if (HandleGadgets(button->x, button->y, button_status))
9229 // do not handle this button event anymore
9233 button->x += video.screen_xoffset;
9234 button->y += video.screen_yoffset;
9236 x = button->x * overlay.grid_xsize / video.screen_width;
9237 y = button->y * overlay.grid_ysize / video.screen_height;
9239 if (button->type == EVENT_BUTTONPRESS)
9242 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9243 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9245 set_grid_button = TRUE;
9248 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9252 case EVENT_MOTIONNOTIFY:
9254 MotionEvent *motion = (MotionEvent *)&event;
9256 motion_status = TRUE;
9258 if (HandleGadgets(motion->x, motion->y, button_status))
9260 // do not handle this button event anymore
9264 motion->x += video.screen_xoffset;
9265 motion->y += video.screen_yoffset;
9267 x = motion->x * overlay.grid_xsize / video.screen_width;
9268 y = motion->y * overlay.grid_ysize / video.screen_height;
9270 set_grid_button = TRUE;
9272 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9276 case SDL_WINDOWEVENT:
9277 HandleWindowEvent((WindowEvent *) &event);
9279 // check if device has been rotated
9280 if (nr != GRID_ACTIVE_NR())
9282 nr = GRID_ACTIVE_NR();
9284 for (x = 0; x < MAX_GRID_XSIZE; x++)
9285 for (y = 0; y < MAX_GRID_YSIZE; y++)
9286 grid_button_old[x][y] = grid_button_tmp[x][y] =
9287 overlay.grid_button[x][y];
9292 case SDL_APP_WILLENTERBACKGROUND:
9293 case SDL_APP_DIDENTERBACKGROUND:
9294 case SDL_APP_WILLENTERFOREGROUND:
9295 case SDL_APP_DIDENTERFOREGROUND:
9296 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9300 HandleOtherEvents(&event);
9304 // ---------- perform action set by handling events ----------
9306 if (action == ACTION_ESCAPE)
9308 // abort and restore the old key bindings
9310 for (x = 0; x < MAX_GRID_XSIZE; x++)
9311 for (y = 0; y < MAX_GRID_YSIZE; y++)
9312 overlay.grid_button[x][y] = grid_button_old[x][y];
9314 FadeSkipNextFadeIn();
9318 else if (action == ACTION_BACK)
9320 // keep the configured key bindings and go to previous page
9326 FadeSkipNextFadeIn();
9331 else if (action == ACTION_NEXT)
9333 // keep the configured key bindings and go to next page
9337 // all virtual buttons configured
9345 if (action != ACTION_NONE && !finished)
9347 for (x = 0; x < MAX_GRID_XSIZE; x++)
9348 for (y = 0; y < MAX_GRID_YSIZE; y++)
9349 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9351 overlay.grid_button_highlight = grid_button[step_nr];
9353 // configure next virtual button
9357 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9358 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9359 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9362 if (set_grid_button)
9364 overlay.grid_button[x][y] =
9365 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9366 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9367 grid_button_tmp[x][y]);
9369 set_grid_button = FALSE;
9376 for (x = 0; x < MAX_GRID_XSIZE; x++)
9377 for (y = 0; y < MAX_GRID_YSIZE; y++)
9378 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9380 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9382 SetOverlayShowGrid(FALSE);
9387 void ConfigureVirtualButtons(void)
9389 boolean success = ConfigureVirtualButtonsMain();
9391 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9392 SCREEN_MASK_TOUCH2);
9396 int font_nr = FONT_TITLE_1;
9397 int font_height = getFontHeight(font_nr);
9398 int ypos1 = SYSIZE / 2 - font_height * 2;
9399 int ypos2 = SYSIZE / 2 - font_height * 1;
9400 unsigned int wait_frame_delay = 0;
9401 unsigned int wait_frame_delay_value = 2000;
9403 ResetDelayCounter(&wait_frame_delay);
9407 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9408 DrawTextSCentered(ypos2, font_nr, "configured!");
9410 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9417 void DrawSetupScreen(void)
9422 if (setup_mode == SETUP_MODE_INPUT)
9423 DrawSetupScreen_Input();
9424 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9425 DrawChooseTree(&scores_type_current);
9426 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9427 DrawChooseTree(&game_speed_current);
9428 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9429 DrawChooseTree(&scroll_delay_current);
9430 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9431 DrawChooseTree(&snapshot_mode_current);
9432 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9433 DrawChooseTree(&window_size_current);
9434 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9435 DrawChooseTree(&scaling_type_current);
9436 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9437 DrawChooseTree(&rendering_mode_current);
9438 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9439 DrawChooseTree(&vsync_mode_current);
9440 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9441 DrawChooseTree(&artwork.gfx_current);
9442 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9443 DrawChooseTree(&artwork.snd_current);
9444 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9445 DrawChooseTree(&artwork.mus_current);
9446 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9447 DrawChooseTree(&volume_simple_current);
9448 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9449 DrawChooseTree(&volume_loops_current);
9450 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9451 DrawChooseTree(&volume_music_current);
9452 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9453 DrawChooseTree(&touch_control_current);
9454 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9455 DrawChooseTree(&move_distance_current);
9456 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9457 DrawChooseTree(&drop_distance_current);
9458 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9459 DrawChooseTree(&transparency_current);
9460 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9461 DrawChooseTree(&grid_size_current[0][0]);
9462 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9463 DrawChooseTree(&grid_size_current[0][1]);
9464 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9465 DrawChooseTree(&grid_size_current[1][0]);
9466 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9467 DrawChooseTree(&grid_size_current[1][1]);
9469 DrawSetupScreen_Generic();
9471 PlayMenuSoundsAndMusic();
9474 void RedrawSetupScreenAfterFullscreenToggle(void)
9476 if (setup_mode == SETUP_MODE_GRAPHICS ||
9477 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9479 // update list selection from "setup.window_scaling_percent"
9480 execSetupGraphics_setWindowSizes(TRUE);
9486 void RedrawSetupScreenAfterScreenRotation(int nr)
9490 if (setup_mode == SETUP_MODE_TOUCH)
9492 // update virtual button settings (depending on screen orientation)
9495 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9497 // save already configured virtual buttons
9498 for (x = 0; x < MAX_GRID_XSIZE; x++)
9499 for (y = 0; y < MAX_GRID_YSIZE; y++)
9500 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9504 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9506 if (setup_mode == SETUP_MODE_INPUT)
9507 HandleSetupScreen_Input(mx, my, dx, dy, button);
9508 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9509 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9510 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9511 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9512 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9513 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9514 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9515 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9516 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9517 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9518 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9519 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9520 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9521 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9522 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9523 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9524 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9525 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9526 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9527 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9528 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9529 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9530 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9531 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9532 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9533 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9534 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9535 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9536 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9537 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9538 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9539 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9540 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9541 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9542 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9543 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9544 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9545 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9546 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9547 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9548 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9549 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9550 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9551 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9553 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9556 void HandleGameActions(void)
9558 if (setup.ask_on_game_over)
9561 if (game.restart_game_message != NULL)
9563 RequestRestartGame(game.restart_game_message);
9568 if (game_status != GAME_MODE_PLAYING)
9571 GameActions(); // main game loop
9573 if (tape.auto_play && !tape.playing)
9574 AutoPlayTapesContinue(); // continue automatically playing next tape
9578 // ---------- new screen button stuff --------------------------------------
9582 int gfx_unpressed, gfx_pressed;
9583 struct MenuPosInfo *pos;
9584 boolean *check_value;
9587 unsigned int event_mask;
9588 boolean is_touch_button;
9590 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9593 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9594 &menu.main.button.prev_level, NULL,
9595 SCREEN_CTRL_ID_PREV_LEVEL,
9597 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9598 FALSE, "previous level"
9601 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9602 &menu.main.button.next_level, NULL,
9603 SCREEN_CTRL_ID_NEXT_LEVEL,
9605 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9609 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9610 &menu.main.button.first_level, NULL,
9611 SCREEN_CTRL_ID_FIRST_LEVEL,
9614 FALSE, "first level"
9617 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9618 &menu.main.button.last_level, NULL,
9619 SCREEN_CTRL_ID_LAST_LEVEL,
9625 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9626 &menu.main.button.level_number, NULL,
9627 SCREEN_CTRL_ID_LEVEL_NUMBER,
9630 FALSE, "level number"
9633 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9634 &menu.setup.button.prev_player, NULL,
9635 SCREEN_CTRL_ID_PREV_PLAYER,
9637 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9638 FALSE, "previous player"
9641 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9642 &menu.setup.button.next_player, NULL,
9643 SCREEN_CTRL_ID_NEXT_PLAYER,
9645 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9646 FALSE, "next player"
9649 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9650 &menu.main.button.insert_solution, NULL,
9651 SCREEN_CTRL_ID_INSERT_SOLUTION,
9652 SCREEN_MASK_MAIN_HAS_SOLUTION,
9654 FALSE, "insert solution tape"
9657 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9658 &menu.main.button.play_solution, NULL,
9659 SCREEN_CTRL_ID_PLAY_SOLUTION,
9660 SCREEN_MASK_MAIN_HAS_SOLUTION,
9662 FALSE, "play solution tape"
9665 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9666 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9667 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9669 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9670 FALSE, "switch ECS/AGA chipset"
9673 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9674 &menu.setup.button.touch_back, NULL,
9675 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9678 TRUE, "previous page"
9681 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9682 &menu.setup.button.touch_next, NULL,
9683 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9689 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9690 &menu.setup.button.touch_back2, NULL,
9691 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9694 TRUE, "previous page"
9697 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9698 &menu.setup.button.touch_next2, NULL,
9699 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9708 int gfx_unpressed, gfx_pressed;
9712 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9715 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9716 -1, -1, // these values are not constant, but can change at runtime
9717 SCREEN_CTRL_ID_SCROLL_UP,
9721 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9722 -1, -1, // these values are not constant, but can change at runtime
9723 SCREEN_CTRL_ID_SCROLL_DOWN,
9730 int gfx_unpressed, gfx_pressed;
9736 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9739 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9740 -1, -1, // these values are not constant, but can change at runtime
9741 -1, -1, // these values are not constant, but can change at runtime
9742 GD_TYPE_SCROLLBAR_VERTICAL,
9743 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9744 "scroll level series vertically"
9756 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9759 IMG_SETUP_INPUT_TEXT,
9760 SCREEN_CTRL_ID_NETWORK_SERVER,
9761 -1, -1, // these values are not constant, but can change at runtime
9762 MAX_SETUP_TEXT_INPUT_LEN,
9763 network_server_hostname,
9764 "Network Server Hostname / IP"
9768 static void CreateScreenMenubuttons(void)
9770 struct GadgetInfo *gi;
9771 unsigned int event_mask;
9774 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9776 struct MenuPosInfo *pos = menubutton_info[i].pos;
9777 boolean is_touch_button = menubutton_info[i].is_touch_button;
9778 boolean is_check_button = menubutton_info[i].check_value != NULL;
9779 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9780 int gfx_unpressed, gfx_pressed;
9781 int x, y, width, height;
9782 int gd_x1, gd_x2, gd_y1, gd_y2;
9783 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9784 int id = menubutton_info[i].gadget_id;
9785 int type = GD_TYPE_NORMAL_BUTTON;
9786 boolean checked = FALSE;
9788 event_mask = menubutton_info[i].event_mask;
9790 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9791 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9793 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9794 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9796 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9797 gfx_pressed = menubutton_info[i].gfx_pressed;
9798 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9799 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9800 gd_x1 = graphic_info[gfx_unpressed].src_x;
9801 gd_y1 = graphic_info[gfx_unpressed].src_y;
9802 gd_x2 = graphic_info[gfx_pressed].src_x;
9803 gd_y2 = graphic_info[gfx_pressed].src_y;
9809 if (is_touch_button)
9811 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9812 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9815 if (is_check_button)
9817 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9818 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9819 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9820 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9822 type = GD_TYPE_CHECK_BUTTON;
9823 checked = *menubutton_info[i].check_value;
9826 gi = CreateGadget(GDI_CUSTOM_ID, id,
9827 GDI_CUSTOM_TYPE_ID, i,
9828 GDI_IMAGE_ID, gfx_unpressed,
9829 GDI_INFO_TEXT, menubutton_info[i].infotext,
9835 GDI_STATE, GD_BUTTON_UNPRESSED,
9836 GDI_CHECKED, checked,
9837 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9838 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9839 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9840 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9841 GDI_DIRECT_DRAW, FALSE,
9842 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9843 GDI_EVENT_MASK, event_mask,
9844 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9848 Fail("cannot create gadget");
9850 screen_gadget[id] = gi;
9854 static void CreateScreenScrollbuttons(void)
9856 struct GadgetInfo *gi;
9857 unsigned int event_mask;
9860 // these values are not constant, but can change at runtime
9861 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9862 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9863 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9864 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9866 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9868 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9869 int gfx_unpressed, gfx_pressed;
9870 int x, y, width, height;
9871 int gd_x1, gd_x2, gd_y1, gd_y2;
9872 int id = scrollbutton_info[i].gadget_id;
9874 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9876 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9877 y = mSY + scrollbutton_info[i].y;
9878 width = SC_SCROLLBUTTON_XSIZE;
9879 height = SC_SCROLLBUTTON_YSIZE;
9881 // correct scrollbar position if placed outside menu (playfield) area
9882 if (x > SX + SC_SCROLL_UP_XPOS)
9883 x = SX + SC_SCROLL_UP_XPOS;
9885 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9886 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9887 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9889 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9890 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9891 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9892 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9893 gd_x1 = graphic_info[gfx_unpressed].src_x;
9894 gd_y1 = graphic_info[gfx_unpressed].src_y;
9895 gd_x2 = graphic_info[gfx_pressed].src_x;
9896 gd_y2 = graphic_info[gfx_pressed].src_y;
9898 gi = CreateGadget(GDI_CUSTOM_ID, id,
9899 GDI_CUSTOM_TYPE_ID, i,
9900 GDI_IMAGE_ID, gfx_unpressed,
9901 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9906 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9907 GDI_STATE, GD_BUTTON_UNPRESSED,
9908 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9909 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9910 GDI_DIRECT_DRAW, FALSE,
9911 GDI_EVENT_MASK, event_mask,
9912 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9916 Fail("cannot create gadget");
9918 screen_gadget[id] = gi;
9922 static void CreateScreenScrollbars(void)
9926 // these values are not constant, but can change at runtime
9927 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9928 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9929 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9930 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9932 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9934 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9935 int gfx_unpressed, gfx_pressed;
9936 int x, y, width, height;
9937 int gd_x1, gd_x2, gd_y1, gd_y2;
9938 struct GadgetInfo *gi;
9939 int items_max, items_visible, item_position;
9940 unsigned int event_mask;
9941 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9942 int id = scrollbar_info[i].gadget_id;
9944 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9946 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9947 y = mSY + scrollbar_info[i].y;
9948 width = scrollbar_info[i].width;
9949 height = scrollbar_info[i].height;
9951 // correct scrollbar position if placed outside menu (playfield) area
9952 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9953 x = SX + SC_SCROLL_VERTICAL_XPOS;
9955 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9956 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9958 items_max = num_page_entries;
9959 items_visible = num_page_entries;
9962 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9963 gfx_pressed = scrollbar_info[i].gfx_pressed;
9964 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9965 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9966 gd_x1 = graphic_info[gfx_unpressed].src_x;
9967 gd_y1 = graphic_info[gfx_unpressed].src_y;
9968 gd_x2 = graphic_info[gfx_pressed].src_x;
9969 gd_y2 = graphic_info[gfx_pressed].src_y;
9971 gi = CreateGadget(GDI_CUSTOM_ID, id,
9972 GDI_CUSTOM_TYPE_ID, i,
9973 GDI_IMAGE_ID, gfx_unpressed,
9974 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9979 GDI_TYPE, scrollbar_info[i].type,
9980 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9981 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9982 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9983 GDI_WHEEL_AREA_X, SX,
9984 GDI_WHEEL_AREA_Y, SY,
9985 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9986 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9987 GDI_STATE, GD_BUTTON_UNPRESSED,
9988 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9989 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9990 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9991 GDI_DIRECT_DRAW, FALSE,
9992 GDI_EVENT_MASK, event_mask,
9993 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9997 Fail("cannot create gadget");
9999 screen_gadget[id] = gi;
10003 static void CreateScreenTextInputGadgets(void)
10007 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10009 int graphic = textinput_info[i].graphic;
10010 struct GraphicInfo *gd = &graphic_info[graphic];
10011 int gd_x1 = gd->src_x;
10012 int gd_y1 = gd->src_y;
10013 int gd_x2 = gd->src_x + gd->active_xoffset;
10014 int gd_y2 = gd->src_y + gd->active_yoffset;
10015 struct GadgetInfo *gi;
10016 unsigned int event_mask;
10017 int id = textinput_info[i].gadget_id;
10018 int x = textinput_info[i].x;
10019 int y = textinput_info[i].y;
10021 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10023 gi = CreateGadget(GDI_CUSTOM_ID, id,
10024 GDI_CUSTOM_TYPE_ID, i,
10025 GDI_INFO_TEXT, textinput_info[i].infotext,
10028 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10029 GDI_TEXT_VALUE, textinput_info[i].value,
10030 GDI_TEXT_SIZE, textinput_info[i].size,
10031 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10032 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10033 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10034 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10035 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10036 GDI_DESIGN_WIDTH, gd->width,
10037 GDI_EVENT_MASK, event_mask,
10038 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10039 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10043 Fail("cannot create gadget");
10045 screen_gadget[id] = gi;
10049 void CreateScreenGadgets(void)
10051 CreateScreenMenubuttons();
10053 CreateScreenScrollbuttons();
10054 CreateScreenScrollbars();
10056 CreateScreenTextInputGadgets();
10059 void FreeScreenGadgets(void)
10063 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10064 FreeGadget(screen_gadget[i]);
10067 static void RedrawScreenMenuGadgets(int screen_mask)
10071 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10072 if (screen_mask & menubutton_info[i].screen_mask)
10073 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10076 static void MapScreenMenuGadgets(int screen_mask)
10080 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10081 if (screen_mask & menubutton_info[i].screen_mask)
10082 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10085 static void UnmapScreenMenuGadgets(int screen_mask)
10089 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10091 if (screen_mask & menubutton_info[i].screen_mask)
10093 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10095 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10096 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10097 screen_gadget[menubutton_info[i].gadget_id]->y,
10098 screen_gadget[menubutton_info[i].gadget_id]->width,
10099 screen_gadget[menubutton_info[i].gadget_id]->height);
10104 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10107 MapScreenMenuGadgets(screen_mask);
10109 UnmapScreenMenuGadgets(screen_mask);
10112 static void MapScreenGadgets(int num_entries)
10116 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10119 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10120 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10122 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10123 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10126 static void UnmapScreenGadgets()
10130 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10131 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10133 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10134 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10137 static void MapScreenTreeGadgets(TreeInfo *ti)
10139 MapScreenGadgets(numTreeInfoInGroup(ti));
10142 static void UnmapScreenTreeGadgets(void)
10144 UnmapScreenGadgets();
10147 static void HandleScreenGadgets(struct GadgetInfo *gi)
10149 int id = gi->custom_id;
10150 int button = gi->event.button;
10151 int step = (button == MB_LEFTBUTTON ? 1 :
10152 button == MB_MIDDLEBUTTON ? 5 :
10153 button == MB_RIGHTBUTTON ? 10 : 1);
10157 case SCREEN_CTRL_ID_PREV_LEVEL:
10158 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10161 case SCREEN_CTRL_ID_NEXT_LEVEL:
10162 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10165 case SCREEN_CTRL_ID_FIRST_LEVEL:
10166 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10169 case SCREEN_CTRL_ID_LAST_LEVEL:
10170 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10173 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10174 CloseDoor(DOOR_CLOSE_2);
10175 SetGameStatus(GAME_MODE_LEVELNR);
10176 DrawChooseLevelNr();
10179 case SCREEN_CTRL_ID_PREV_PLAYER:
10180 HandleSetupScreen_Input_Player(step, -1);
10183 case SCREEN_CTRL_ID_NEXT_PLAYER:
10184 HandleSetupScreen_Input_Player(step, +1);
10187 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10188 InsertSolutionTape();
10191 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10192 PlaySolutionTape();
10195 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10196 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10200 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10201 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10202 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10203 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10204 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10207 case SCREEN_CTRL_ID_SCROLL_UP:
10208 if (game_status == GAME_MODE_NAMES)
10209 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10210 else if (game_status == GAME_MODE_LEVELS)
10211 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10212 else if (game_status == GAME_MODE_LEVELNR)
10213 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10214 else if (game_status == GAME_MODE_SETUP)
10215 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10216 else if (game_status == GAME_MODE_INFO)
10217 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10218 else if (game_status == GAME_MODE_SCORES)
10219 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10222 case SCREEN_CTRL_ID_SCROLL_DOWN:
10223 if (game_status == GAME_MODE_NAMES)
10224 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10225 else if (game_status == GAME_MODE_LEVELS)
10226 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10227 else if (game_status == GAME_MODE_LEVELNR)
10228 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10229 else if (game_status == GAME_MODE_SETUP)
10230 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10231 else if (game_status == GAME_MODE_INFO)
10232 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10233 else if (game_status == GAME_MODE_SCORES)
10234 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10237 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10238 if (game_status == GAME_MODE_NAMES)
10239 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10240 else if (game_status == GAME_MODE_LEVELS)
10241 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10242 else if (game_status == GAME_MODE_LEVELNR)
10243 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10244 else if (game_status == GAME_MODE_SETUP)
10245 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10246 else if (game_status == GAME_MODE_INFO)
10247 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10248 else if (game_status == GAME_MODE_SCORES)
10249 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10252 case SCREEN_CTRL_ID_NETWORK_SERVER:
10254 if (!strEqual(gi->textinput.value, ""))
10256 setString(&setup.network_server_hostname, gi->textinput.value);
10258 network.server_host = setup.network_server_hostname;
10262 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10264 network.server_host = NULL;
10267 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10268 network.server_host = NULL;
10270 execSetupGame_setNetworkServerText();
10282 void DumpScreenIdentifiers(void)
10286 Print("Active screen elements on current screen:\n");
10288 for (i = 0; main_controls[i].nr != -1; i++)
10290 struct MainControlInfo *mci = &main_controls[i];
10292 if (mci->button_graphic != -1)
10294 char *token = getTokenFromImageID(mci->button_graphic);
10296 Print("- '%s'\n", token);
10303 boolean DoScreenAction(int image_id)
10307 if (game_status != GAME_MODE_MAIN)
10310 for (i = 0; main_controls[i].nr != -1; i++)
10312 struct MainControlInfo *mci = &main_controls[i];
10313 struct MenuPosInfo *pos = mci->pos_button;
10315 if (mci->button_graphic == image_id)
10317 int x = mSX + pos->x;
10318 int y = mSY + pos->y;
10320 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10329 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10331 // get tree info node of newly added level or artwork set
10332 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10333 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10335 if (tree_node_new == NULL) // should not happen
10338 // if request dialog is active, do nothing
10339 if (game.request_active)
10342 if (game_status == GAME_MODE_MAIN &&
10343 tree_type == TREE_TYPE_LEVEL_DIR)
10345 // when adding new level set in main menu, select it as current level set
10347 // change current level set to newly added level set from zip file
10348 leveldir_current = tree_node_new;
10350 // change current level number to first level of newly added level set
10351 level_nr = leveldir_current->first_level;
10353 // redraw screen to reflect changed level set
10356 // save this level set and level number as last selected level set
10357 SaveLevelSetup_LastSeries();
10358 SaveLevelSetup_SeriesInfo();
10360 else if (game_status == GAME_MODE_LEVELS &&
10361 tree_type == TREE_TYPE_LEVEL_DIR)
10363 // when adding new level set in level set menu, set cursor and update screen
10365 leveldir_current = tree_node_new;
10367 DrawChooseTree(&leveldir_current);
10369 else if (game_status == GAME_MODE_SETUP)
10371 // when adding new artwork set in setup menu, set cursor and update screen
10373 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10374 tree_type == TREE_TYPE_GRAPHICS_DIR)
10376 artwork.gfx_current = tree_node_new;
10378 DrawChooseTree(&artwork.gfx_current);
10380 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10381 tree_type == TREE_TYPE_SOUNDS_DIR)
10383 artwork.snd_current = tree_node_new;
10385 DrawChooseTree(&artwork.snd_current);
10387 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10388 tree_type == TREE_TYPE_MUSIC_DIR)
10390 artwork.mus_current = tree_node_new;
10392 DrawChooseTree(&artwork.mus_current);
10397 static int UploadTapes(void)
10399 SetGameStatus(GAME_MODE_LOADING);
10401 FadeSetEnterScreen();
10402 FadeOut(REDRAW_ALL);
10404 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10406 FadeIn(REDRAW_ALL);
10408 DrawInitTextHead("Uploading tapes");
10410 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10411 global.autoplay_leveldir = "ALL";
10412 global.autoplay_all = TRUE;
10414 int num_tapes_uploaded = AutoPlayTapes();
10416 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10417 global.autoplay_leveldir = NULL;
10418 global.autoplay_all = FALSE;
10420 SetGameStatus(GAME_MODE_MAIN);
10424 return num_tapes_uploaded;
10427 static boolean OfferUploadTapes(void)
10429 if (!Request(setup.has_remaining_tapes ?
10430 "Upload missing tapes to the high score server now?" :
10431 "Upload all your tapes to the high score server now?", REQ_ASK))
10434 int num_tapes_uploaded = UploadTapes();
10437 if (num_tapes_uploaded < 0)
10439 num_tapes_uploaded = -num_tapes_uploaded - 1;
10441 if (num_tapes_uploaded == 0)
10442 sprintf(message, "Upload failed! No tapes uploaded!");
10443 else if (num_tapes_uploaded == 1)
10444 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10446 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10447 num_tapes_uploaded);
10449 Request(message, REQ_CONFIRM);
10451 // if uploading tapes failed, add tape upload entry to setup menu
10452 setup.provide_uploading_tapes = TRUE;
10453 setup.has_remaining_tapes = TRUE;
10455 SaveSetup_ServerSetup();
10460 if (num_tapes_uploaded == 0)
10461 sprintf(message, "No tapes uploaded!");
10462 else if (num_tapes_uploaded == 1)
10463 sprintf(message, "1 tape uploaded!");
10465 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10467 Request(message, REQ_CONFIRM);
10469 if (num_tapes_uploaded > 0)
10470 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10472 // after all tapes have been uploaded, remove entry from setup menu
10473 setup.provide_uploading_tapes = FALSE;
10474 setup.has_remaining_tapes = FALSE;
10476 SaveSetup_ServerSetup();
10481 static void CheckUploadTapes(void)
10483 if (!setup.ask_for_uploading_tapes)
10486 // after asking for uploading tapes, do not ask again
10487 setup.ask_for_uploading_tapes = FALSE;
10488 setup.ask_for_remaining_tapes = FALSE;
10490 if (directoryExists(getTapeDir(NULL)))
10492 boolean tapes_uploaded = OfferUploadTapes();
10494 if (!tapes_uploaded)
10496 Request(setup.has_remaining_tapes ?
10497 "You can upload missing tapes from the setup menu later!" :
10498 "You can upload your tapes from the setup menu later!",
10504 // if tapes directory does not exist yet, never offer uploading all tapes
10505 setup.provide_uploading_tapes = FALSE;
10508 SaveSetup_ServerSetup();
10511 static void UpgradePlayerUUID(void)
10513 ApiResetUUIDAsThread(getUUID());
10516 static void CheckUpgradePlayerUUID(void)
10518 if (setup.player_version > 1)
10521 UpgradePlayerUUID();
10524 void CheckApiServerTasks(void)
10526 // check if the player's UUID has to be upgraded
10527 CheckUpgradePlayerUUID();
10529 // check if there are any tapes to be uploaded
10530 CheckUploadTapes();