1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
27 #define DEBUG_JOYSTICKS 0
30 // screens on the info screen
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 // screens on the setup screen
43 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
44 // (should also match corresponding entries in src/conf_gfx.c)
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_ENGINES 2
48 #define SETUP_MODE_EDITOR 3
49 #define SETUP_MODE_GRAPHICS 4
50 #define SETUP_MODE_SOUND 5
51 #define SETUP_MODE_ARTWORK 6
52 #define SETUP_MODE_INPUT 7
53 #define SETUP_MODE_TOUCH 8
54 #define SETUP_MODE_SHORTCUTS 9
55 #define SETUP_MODE_SHORTCUTS_1 10
56 #define SETUP_MODE_SHORTCUTS_2 11
57 #define SETUP_MODE_SHORTCUTS_3 12
58 #define SETUP_MODE_SHORTCUTS_4 13
59 #define SETUP_MODE_SHORTCUTS_5 14
61 // sub-screens on the setup screen (generic)
62 #define SETUP_MODE_CHOOSE_ARTWORK 15
63 #define SETUP_MODE_CHOOSE_OTHER 16
65 // sub-screens on the setup screen (specific)
66 #define SETUP_MODE_CHOOSE_SCORES_TYPE 17
67 #define SETUP_MODE_CHOOSE_GAME_SPEED 18
68 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 19
69 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 20
70 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 21
71 #define SETUP_MODE_CHOOSE_SCALING_TYPE 22
72 #define SETUP_MODE_CHOOSE_RENDERING 23
73 #define SETUP_MODE_CHOOSE_VSYNC 24
74 #define SETUP_MODE_CHOOSE_GRAPHICS 25
75 #define SETUP_MODE_CHOOSE_SOUNDS 26
76 #define SETUP_MODE_CHOOSE_MUSIC 27
77 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 28
78 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 29
79 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 30
80 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 31
81 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 33
83 #define SETUP_MODE_CHOOSE_TRANSPARENCY 34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 36
86 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 37
87 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 38
88 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 39
90 #define MAX_SETUP_MODES 40
92 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
94 // setup screen titles
95 #define STR_SETUP_MAIN "Setup"
96 #define STR_SETUP_GAME "Game & Menu"
97 #define STR_SETUP_ENGINES "Game Engines"
98 #define STR_SETUP_EDITOR "Editor"
99 #define STR_SETUP_GRAPHICS "Graphics"
100 #define STR_SETUP_SOUND "Sound & Music"
101 #define STR_SETUP_ARTWORK "Custom Artwork"
102 #define STR_SETUP_INPUT "Input Devices"
103 #define STR_SETUP_TOUCH "Touch Controls"
104 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
105 #define STR_SETUP_EXIT "Exit"
106 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
108 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
109 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
110 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
111 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
112 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
113 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
114 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
115 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
116 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
117 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
118 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
119 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
120 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
121 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
122 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
125 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
126 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
128 // other screen text constants
129 #define STR_CHOOSE_TREE_EDIT "Edit"
130 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
131 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
133 // for input setup functions
134 #define SETUPINPUT_SCREEN_POS_START 0
135 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
136 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
137 #define SETUPINPUT_SCREEN_POS_END 13
139 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
140 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
142 #define MAX_SETUP_TEXT_INPUT_LEN 28
144 // for various menu stuff
145 #define MENU_SCREEN_START_XPOS 1
146 #define MENU_SCREEN_START_YPOS 2
147 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
148 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
149 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
150 #define MENU_TITLE1_YPOS 8
151 #define MENU_TITLE2_YPOS 46
152 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
153 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
154 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
155 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
156 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
159 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
160 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
161 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
162 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
163 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
164 MENU_INFO_FONT_TITLE))
165 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
166 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
167 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
168 MENU_SCREEN_INFO_YSTART2 - \
170 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
171 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
172 MENU_SCREEN_INFO_YSTEP)
173 #define NUM_INFO_ELEMENTS_FROM_CONF \
174 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
175 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
176 MAX_MENU_ENTRIES_ON_SCREEN)
177 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
178 MAX_INFO_ELEMENTS_ON_SCREEN), \
179 NUM_INFO_ELEMENTS_FROM_CONF)
180 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
181 #define MAX_MENU_TEXT_LENGTH_BIG 13
182 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
184 // screen gadget identifiers
185 #define SCREEN_CTRL_ID_PREV_LEVEL 0
186 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
187 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
188 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
189 #define SCREEN_CTRL_ID_FIRST_LEVEL 4
190 #define SCREEN_CTRL_ID_LAST_LEVEL 5
191 #define SCREEN_CTRL_ID_LEVEL_NUMBER 6
192 #define SCREEN_CTRL_ID_PREV_PLAYER 7
193 #define SCREEN_CTRL_ID_NEXT_PLAYER 8
194 #define SCREEN_CTRL_ID_INSERT_SOLUTION 9
195 #define SCREEN_CTRL_ID_PLAY_SOLUTION 10
196 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 11
197 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 12
198 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 13
199 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 14
200 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 15
201 #define SCREEN_CTRL_ID_SCROLL_UP 16
202 #define SCREEN_CTRL_ID_SCROLL_DOWN 17
203 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 18
204 #define SCREEN_CTRL_ID_NETWORK_SERVER 19
206 #define NUM_SCREEN_GADGETS 20
208 #define NUM_SCREEN_MENUBUTTONS 16
209 #define NUM_SCREEN_SCROLLBUTTONS 2
210 #define NUM_SCREEN_SCROLLBARS 1
211 #define NUM_SCREEN_TEXTINPUT 1
213 #define SCREEN_MASK_MAIN (1 << 0)
214 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
215 #define SCREEN_MASK_INPUT (1 << 2)
216 #define SCREEN_MASK_TOUCH (1 << 3)
217 #define SCREEN_MASK_TOUCH2 (1 << 4)
218 #define SCREEN_MASK_SCORES (1 << 5)
220 // graphic position and size values for buttons and scrollbars
221 #define SC_MENUBUTTON_XSIZE TILEX
222 #define SC_MENUBUTTON_YSIZE TILEY
224 #define SC_SCROLLBUTTON_XSIZE TILEX
225 #define SC_SCROLLBUTTON_YSIZE TILEY
227 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
229 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
230 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
231 SC_SCROLLBUTTON_YSIZE)
233 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
234 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
236 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
237 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
238 SC_SCROLLBUTTON_YSIZE)
240 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
241 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
242 SC_SCROLL_VERTICAL_YSIZE)
244 #define SC_BORDER_SIZE 14
247 // forward declarations of internal functions
248 static void HandleScreenGadgets(struct GadgetInfo *);
249 static void HandleSetupScreen_Generic(int, int, int, int, int);
250 static void HandleSetupScreen_Input(int, int, int, int, int);
251 static void CustomizeKeyboard(int);
252 static void ConfigureJoystick(int);
253 static void ConfigureVirtualButtons(void);
254 static void execSetupGame(void);
255 static void execSetupEngines(void);
256 static void execSetupGraphics(void);
257 static void execSetupSound(void);
258 static void execSetupTouch(void);
259 static void execSetupArtwork(void);
260 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
262 static void DrawChoosePlayerName(void);
263 static void DrawChooseLevelSet(void);
264 static void DrawChooseLevelNr(void);
265 static void DrawInfoScreen(void);
266 static void DrawSetupScreen(void);
267 static void DrawTypeName(void);
269 static void DrawInfoScreen_NotAvailable(char *, char *);
270 static void DrawInfoScreen_HelpAnim(int, int, boolean);
271 static void DrawInfoScreen_HelpText(int, int, int, int);
272 static void HandleInfoScreen_Main(int, int, int, int, int);
273 static void HandleInfoScreen_TitleScreen(int);
274 static void HandleInfoScreen_Elements(int);
275 static void HandleInfoScreen_Music(int);
276 static void HandleInfoScreen_Credits(int);
277 static void HandleInfoScreen_Program(int);
278 static void HandleInfoScreen_Version(int);
280 static void ModifyGameSpeedIfNeeded(void);
281 static void DisableVsyncIfNeeded(void);
283 static void RedrawScreenMenuGadgets(int);
284 static void MapScreenMenuGadgets(int);
285 static void UnmapScreenMenuGadgets(int);
286 static void MapScreenGadgets(int);
287 static void UnmapScreenGadgets(void);
288 static void MapScreenTreeGadgets(TreeInfo *);
289 static void UnmapScreenTreeGadgets(void);
291 static void UpdateScreenMenuGadgets(int, boolean);
293 static boolean OfferUploadTapes(void);
294 static void execOfferUploadTapes(void);
296 static void DrawHallOfFame_setScoreEntries(void);
297 static void HandleHallOfFame_SelectLevel(int, int);
298 static char *getHallOfFameScoreText(int);
300 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
302 static int info_mode = INFO_MODE_MAIN;
303 static int setup_mode = SETUP_MODE_MAIN;
305 static TreeInfo *window_sizes = NULL;
306 static TreeInfo *window_size_current = NULL;
308 static TreeInfo *scaling_types = NULL;
309 static TreeInfo *scaling_type_current = NULL;
311 static TreeInfo *rendering_modes = NULL;
312 static TreeInfo *rendering_mode_current = NULL;
314 static TreeInfo *vsync_modes = NULL;
315 static TreeInfo *vsync_mode_current = NULL;
317 static TreeInfo *scroll_delays = NULL;
318 static TreeInfo *scroll_delay_current = NULL;
320 static TreeInfo *snapshot_modes = NULL;
321 static TreeInfo *snapshot_mode_current = NULL;
323 static TreeInfo *scores_types = NULL;
324 static TreeInfo *scores_type_current = NULL;
326 static TreeInfo *game_speeds_normal = NULL;
327 static TreeInfo *game_speeds_extended = NULL;
328 static TreeInfo *game_speeds = NULL;
329 static TreeInfo *game_speed_current = NULL;
331 static TreeInfo *volumes_simple = NULL;
332 static TreeInfo *volume_simple_current = NULL;
334 static TreeInfo *volumes_loops = NULL;
335 static TreeInfo *volume_loops_current = NULL;
337 static TreeInfo *volumes_music = NULL;
338 static TreeInfo *volume_music_current = NULL;
340 static TreeInfo *touch_controls = NULL;
341 static TreeInfo *touch_control_current = NULL;
343 static TreeInfo *move_distances = NULL;
344 static TreeInfo *move_distance_current = NULL;
346 static TreeInfo *drop_distances = NULL;
347 static TreeInfo *drop_distance_current = NULL;
349 static TreeInfo *transparencies = NULL;
350 static TreeInfo *transparency_current = NULL;
352 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
353 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
355 static TreeInfo *player_name = NULL;
356 static TreeInfo *player_name_current = NULL;
358 static TreeInfo *level_number = NULL;
359 static TreeInfo *level_number_current = NULL;
361 static TreeInfo *score_entries = NULL;
362 static TreeInfo *score_entry_current = NULL;
364 static struct ValueTextInfo window_sizes_list[] =
369 { 100, "100 % (Default)" },
382 static struct StringValueTextInfo scaling_types_list[] =
384 { SCALING_QUALITY_NEAREST, "Off" },
385 { SCALING_QUALITY_LINEAR, "Linear" },
386 { SCALING_QUALITY_BEST, "Anisotropic" },
391 static struct StringValueTextInfo rendering_modes_list[] =
393 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
394 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
396 // this mode may work under certain conditions, but does not work on Windows
397 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
399 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
404 static struct StringValueTextInfo vsync_modes_list[] =
406 { STR_VSYNC_MODE_OFF, "Off" },
407 { STR_VSYNC_MODE_NORMAL, "Normal" },
408 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
413 static struct StringValueTextInfo scores_types_list[] =
415 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
416 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
417 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
422 static struct ValueTextInfo game_speeds_list_normal[] =
433 static struct ValueTextInfo game_speeds_list_extended[] =
435 { 1000, "1 fps (Extremely Slow)" },
440 { 29, "35 fps (Original Supaplex)" },
442 { 20, "50 fps (=== Normal Speed ===)" },
443 { 16, "60 fps (60 Hz VSync Speed)" },
444 { 14, "70 fps (Maximum Supaplex)" },
448 { 1, "1000 fps (Extremely Fast)" },
453 static struct ValueTextInfo *game_speeds_list;
455 static struct ValueTextInfo scroll_delays_list[] =
457 { 0, "0 Tiles (No Scroll Delay)" },
460 { 3, "3 Tiles (Default)" },
465 { 8, "8 Tiles (Maximum Scroll Delay)"},
470 static struct StringValueTextInfo snapshot_modes_list[] =
472 { STR_SNAPSHOT_MODE_OFF, "Off" },
473 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
474 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
475 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
480 static struct ValueTextInfo volumes_list[] =
500 static struct StringValueTextInfo touch_controls_list[] =
502 { TOUCH_CONTROL_OFF, "Off" },
503 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
504 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
505 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
510 static struct ValueTextInfo distances_list[] =
525 static struct ValueTextInfo transparencies_list[] =
527 { 0, "0 % (Opaque)" },
537 { 100, "100 % (Invisible)" },
542 static struct ValueTextInfo grid_sizes_list[] =
578 static int align_xoffset = 0;
579 static int align_yoffset = 0;
581 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
582 (s) <= GAME_MODE_SETUP ? (s) : \
583 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
585 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
586 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
588 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
589 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
590 (i) <= INFO_MODE_LEVELSET ? (i) : \
593 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
594 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
595 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
596 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
597 SETUP_MODE_CHOOSE_ARTWORK : \
598 SETUP_MODE_CHOOSE_OTHER)
600 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
601 menu.draw_xoffset[GAME_MODE_INFO] : \
602 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
603 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
604 menu.draw_yoffset[GAME_MODE_INFO] : \
605 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
606 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
607 menu.extra_spacing[GAME_MODE_INFO] : \
608 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
610 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
611 menu.draw_xoffset[GAME_MODE_SETUP] : \
612 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
613 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
614 menu.draw_yoffset[GAME_MODE_SETUP] : \
615 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
616 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
617 menu.extra_spacing[GAME_MODE_SETUP] : \
618 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
620 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
622 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
624 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
625 DRAW_XOFFSET_INFO(info_mode) : \
626 (s) == GAME_MODE_SETUP ? \
627 DRAW_XOFFSET_SETUP(setup_mode) : \
628 menu.draw_xoffset[DRAW_MODE(s)])
629 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
630 DRAW_YOFFSET_INFO(info_mode) : \
631 (s) == GAME_MODE_SETUP ? \
632 DRAW_YOFFSET_SETUP(setup_mode) : \
633 menu.draw_yoffset[DRAW_MODE(s)])
634 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
635 EXTRA_SPACING_INFO(info_mode) : \
636 (s) == GAME_MODE_SETUP ? \
637 EXTRA_SPACING_SETUP(setup_mode) : \
638 (s) == GAME_MODE_SCORES ? \
639 EXTRA_SPACING_SCORES(info_mode) : \
640 menu.extra_spacing[DRAW_MODE(s)])
642 #define mSX (SX + DRAW_XOFFSET(game_status))
643 #define mSY (SY + DRAW_YOFFSET(game_status))
645 #define amSX (mSX + align_xoffset)
646 #define amSY (mSY + align_yoffset)
648 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
649 menu.list_size[game_status] : \
650 MAX_MENU_ENTRIES_ON_SCREEN)
652 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
653 NUM_MENU_ENTRIES_ON_SCREEN)
656 // title display and control definitions
658 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
659 2 * MAX_NUM_TITLE_MESSAGES)
661 #define NO_DIRECT_LEVEL_SELECT (-1)
664 static int num_title_screens = 0;
666 struct TitleControlInfo
675 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
677 // main menu display and control definitions
679 #define MAIN_CONTROL_NAME 0
680 #define MAIN_CONTROL_LEVELS 1
681 #define MAIN_CONTROL_SCORES 2
682 #define MAIN_CONTROL_EDITOR 3
683 #define MAIN_CONTROL_INFO 4
684 #define MAIN_CONTROL_GAME 5
685 #define MAIN_CONTROL_SETUP 6
686 #define MAIN_CONTROL_QUIT 7
687 #define MAIN_CONTROL_PREV_LEVEL 8
688 #define MAIN_CONTROL_NEXT_LEVEL 9
689 #define MAIN_CONTROL_FIRST_LEVEL 10
690 #define MAIN_CONTROL_LAST_LEVEL 11
691 #define MAIN_CONTROL_LEVEL_NUMBER 12
692 #define MAIN_CONTROL_LEVEL_INFO_1 13
693 #define MAIN_CONTROL_LEVEL_INFO_2 14
694 #define MAIN_CONTROL_LEVEL_NAME 15
695 #define MAIN_CONTROL_LEVEL_AUTHOR 16
696 #define MAIN_CONTROL_LEVEL_YEAR 17
697 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
698 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
699 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
700 #define MAIN_CONTROL_TITLE_1 21
701 #define MAIN_CONTROL_TITLE_2 22
702 #define MAIN_CONTROL_TITLE_3 23
704 static char str_main_text_name[10];
705 static char str_main_text_first_level[10];
706 static char str_main_text_last_level[10];
707 static char str_main_text_level_number[10];
709 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
711 static char *main_text_name = str_main_text_name;
712 static char *main_text_first_level = str_main_text_first_level;
713 static char *main_text_last_level = str_main_text_last_level;
714 static char *main_text_level_number = str_main_text_level_number;
715 static char *main_text_levels = "Levelset";
716 static char *main_text_scores = "Hall Of Fame";
717 static char *main_text_editor = "Level Creator";
718 static char *main_text_info = "Info Screen";
719 static char *main_text_game = "Start Game";
720 static char *main_text_setup = "Setup";
721 static char *main_text_quit = "Quit";
722 static char *main_text_level_name = level.name;
723 static char *main_text_level_author = level.author;
724 static char *main_text_level_year = NULL;
725 static char *main_text_level_imported_from = NULL;
726 static char *main_text_level_imported_by = NULL;
727 static char *main_text_level_tested_by = NULL;
728 static char *main_text_title_1 = NULL;
729 static char *main_text_title_2 = NULL;
730 static char *main_text_title_3 = NULL;
732 extern char debug_xsn_mode[];
734 struct MainControlInfo
738 struct MenuPosInfo *pos_button;
741 struct TextPosInfo *pos_text;
744 struct TextPosInfo *pos_input;
748 static struct MainControlInfo main_controls[] =
752 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
753 &menu.main.text.name, &main_text_name,
754 &menu.main.input.name, &setup.player_name,
758 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
759 &menu.main.text.levels, &main_text_levels,
764 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
765 &menu.main.text.scores, &main_text_scores,
770 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
771 &menu.main.text.editor, &main_text_editor,
776 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
777 &menu.main.text.info, &main_text_info,
782 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
783 &menu.main.text.game, &main_text_game,
788 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
789 &menu.main.text.setup, &main_text_setup,
794 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
795 &menu.main.text.quit, &main_text_quit,
799 MAIN_CONTROL_PREV_LEVEL,
805 MAIN_CONTROL_NEXT_LEVEL,
811 MAIN_CONTROL_FIRST_LEVEL,
813 &menu.main.text.first_level, &main_text_first_level,
817 MAIN_CONTROL_LAST_LEVEL,
819 &menu.main.text.last_level, &main_text_last_level,
823 MAIN_CONTROL_LEVEL_NUMBER,
825 &menu.main.text.level_number, &main_text_level_number,
829 MAIN_CONTROL_LEVEL_INFO_1,
831 &menu.main.text.level_info_1, NULL,
835 MAIN_CONTROL_LEVEL_INFO_2,
837 &menu.main.text.level_info_2, NULL,
841 MAIN_CONTROL_LEVEL_NAME,
843 &menu.main.text.level_name, &main_text_level_name,
847 MAIN_CONTROL_LEVEL_AUTHOR,
849 &menu.main.text.level_author, &main_text_level_author,
853 MAIN_CONTROL_LEVEL_YEAR,
855 &menu.main.text.level_year, &main_text_level_year,
859 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
861 &menu.main.text.level_imported_from, &main_text_level_imported_from,
865 MAIN_CONTROL_LEVEL_IMPORTED_BY,
867 &menu.main.text.level_imported_by, &main_text_level_imported_by,
871 MAIN_CONTROL_LEVEL_TESTED_BY,
873 &menu.main.text.level_tested_by, &main_text_level_tested_by,
877 MAIN_CONTROL_TITLE_1,
879 &menu.main.text.title_1, &main_text_title_1,
883 MAIN_CONTROL_TITLE_2,
885 &menu.main.text.title_2, &main_text_title_2,
889 MAIN_CONTROL_TITLE_3,
891 &menu.main.text.title_3, &main_text_title_3,
904 static int getTitleScreenGraphic(int nr, boolean initial)
906 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
909 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
911 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
915 static int getTitleScreenGameMode(boolean initial)
917 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
921 static int getTitleMessageGameMode(boolean initial)
923 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
926 static int getTitleAnimMode(struct TitleControlInfo *tci)
928 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
930 return base + tci->local_nr;
934 static int getTitleScreenBackground(boolean initial)
936 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
941 static int getTitleMessageBackground(int nr, boolean initial)
943 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
947 static int getTitleBackground(int nr, boolean initial, boolean is_image)
949 int base = (is_image ?
950 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
951 IMG_BACKGROUND_TITLESCREEN_1) :
952 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
953 IMG_BACKGROUND_TITLEMESSAGE_1));
954 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
955 IMG_BACKGROUND_TITLE);
956 int graphic_local = base + nr;
958 if (graphic_info[graphic_local].bitmap != NULL)
959 return graphic_local;
961 if (graphic_info[graphic_global].bitmap != NULL)
962 return graphic_global;
964 return IMG_UNDEFINED;
967 static int getTitleSound(struct TitleControlInfo *tci)
969 boolean is_image = tci->is_image;
970 int initial = tci->initial;
971 int nr = tci->local_nr;
972 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
973 int base = (is_image ?
974 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
975 SND_BACKGROUND_TITLESCREEN_1) :
976 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
977 SND_BACKGROUND_TITLEMESSAGE_1));
978 int sound_global = menu.sound[mode];
979 int sound_local = base + nr;
982 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
983 nr, initial, is_image,
984 sound_global, getSoundListEntry(sound_global)->filename,
985 sound_local, getSoundListEntry(sound_local)->filename);
988 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
991 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
994 return SND_UNDEFINED;
997 static int getTitleMusic(struct TitleControlInfo *tci)
999 boolean is_image = tci->is_image;
1000 int initial = tci->initial;
1001 int nr = tci->local_nr;
1002 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1003 int base = (is_image ?
1004 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1005 MUS_BACKGROUND_TITLESCREEN_1) :
1006 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1007 MUS_BACKGROUND_TITLEMESSAGE_1));
1008 int music_global = menu.music[mode];
1009 int music_local = base + nr;
1012 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1013 nr, initial, is_image,
1014 music_global, getMusicListEntry(music_global)->filename,
1015 music_local, getMusicListEntry(music_local)->filename);
1018 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1021 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1022 return music_global;
1024 return MUS_UNDEFINED;
1027 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1029 boolean is_image = tci->is_image;
1030 boolean initial = tci->initial;
1031 boolean first = tci->first;
1032 int nr = tci->local_nr;
1033 struct TitleMessageInfo tmi;
1034 struct TitleFadingInfo ti;
1036 tmi = (is_image ? (initial ? (first ?
1037 titlescreen_initial_first[nr] :
1038 titlescreen_initial[nr])
1040 titlescreen_first[nr] :
1042 : (initial ? (first ?
1043 titlemessage_initial_first[nr] :
1044 titlemessage_initial[nr])
1046 titlemessage_first[nr] :
1047 titlemessage[nr])));
1049 ti.fade_mode = tmi.fade_mode;
1050 ti.fade_delay = tmi.fade_delay;
1051 ti.post_delay = tmi.post_delay;
1052 ti.auto_delay = tmi.auto_delay;
1053 ti.auto_delay_unit = tmi.auto_delay_unit;
1058 static int compareTitleControlInfo(const void *object1, const void *object2)
1060 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1061 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1064 if (tci1->initial != tci2->initial)
1065 compare_result = (tci1->initial ? -1 : +1);
1066 else if (tci1->sort_priority != tci2->sort_priority)
1067 compare_result = tci1->sort_priority - tci2->sort_priority;
1068 else if (tci1->is_image != tci2->is_image)
1069 compare_result = (tci1->is_image ? -1 : +1);
1071 compare_result = tci1->local_nr - tci2->local_nr;
1073 return compare_result;
1076 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1078 int nr, int sort_priority)
1080 title_controls[num_title_screens].is_image = is_image;
1081 title_controls[num_title_screens].initial = initial;
1082 title_controls[num_title_screens].local_nr = nr;
1083 title_controls[num_title_screens].sort_priority = sort_priority;
1085 title_controls[num_title_screens].first = FALSE; // will be set later
1087 num_title_screens++;
1090 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1094 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1096 int graphic = getTitleScreenGraphic(i, initial);
1097 Bitmap *bitmap = graphic_info[graphic].bitmap;
1098 int sort_priority = graphic_info[graphic].sort_priority;
1101 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1104 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1106 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1107 char *filename = getLevelSetTitleMessageFilename(i, initial);
1108 int sort_priority = tmi->sort_priority;
1110 if (filename != NULL)
1111 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1115 static void InitializeTitleControls(boolean show_title_initial)
1117 num_title_screens = 0;
1119 // 1st step: initialize title screens for game start (only when starting)
1120 if (show_title_initial)
1121 InitializeTitleControls_CheckTitleInfo(TRUE);
1123 // 2nd step: initialize title screens for current level set
1124 InitializeTitleControls_CheckTitleInfo(FALSE);
1126 // sort title screens according to sort_priority and title number
1127 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1128 compareTitleControlInfo);
1130 // mark first title screen
1131 title_controls[0].first = TRUE;
1134 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1136 return (pos != NULL && pos->x != -1 && pos->y != -1);
1139 static boolean visibleTextPos(struct TextPosInfo *pos)
1141 return (pos != NULL && pos->x != -1 && pos->y != -1);
1144 static void InitializeMainControls(void)
1146 boolean local_team_mode = (!network.enabled && setup.team_mode);
1149 // set main control text values to dynamically determined values
1150 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1152 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1153 menu.main.text.first_level.size));
1154 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1155 menu.main.text.last_level.size));
1156 strcpy(main_text_level_number, int2str(level_nr,
1157 menu.main.text.level_number.size));
1159 main_text_level_year = leveldir_current->year;
1160 main_text_level_imported_from = leveldir_current->imported_from;
1161 main_text_level_imported_by = leveldir_current->imported_by;
1162 main_text_level_tested_by = leveldir_current->tested_by;
1164 main_text_title_1 = getConfigProgramTitleString();
1165 main_text_title_2 = getConfigProgramCopyrightString();
1166 main_text_title_3 = getConfigProgramCompanyString();
1168 // set main control screen positions to dynamically determined values
1169 for (i = 0; main_controls[i].nr != -1; i++)
1171 struct MainControlInfo *mci = &main_controls[i];
1173 struct MenuPosInfo *pos_button = mci->pos_button;
1174 struct TextPosInfo *pos_text = mci->pos_text;
1175 struct TextPosInfo *pos_input = mci->pos_input;
1176 char *text = (mci->text ? *mci->text : NULL);
1177 char *input = (mci->input ? *mci->input : NULL);
1178 int button_graphic = mci->button_graphic;
1179 int font_text = (pos_text ? pos_text->font : -1);
1180 int font_input = (pos_input ? pos_input->font : -1);
1182 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1183 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1184 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1185 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1186 int text_chars = (text != NULL ? strlen(text) : 0);
1187 int input_chars = (input != NULL ? strlen(input) : 0);
1190 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1192 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1193 int text_width = font_text_width * text_chars;
1194 int text_height = font_text_height;
1195 int input_width = font_input_width * input_chars;
1196 int input_height = font_input_height;
1198 if (nr == MAIN_CONTROL_NAME)
1200 menu.main.input.name.width = input_width;
1201 menu.main.input.name.height = input_height;
1204 if (pos_button != NULL) // (x/y may be -1/-1 here)
1206 pos_button->width = button_width;
1207 pos_button->height = button_height;
1210 if (pos_text != NULL) // (x/y may be -1/-1 here)
1212 // calculate text size -- needed for text alignment
1213 boolean calculate_text_size = (text != NULL);
1215 if (pos_text->width == -1 || calculate_text_size)
1216 pos_text->width = text_width;
1217 if (pos_text->height == -1 || calculate_text_size)
1218 pos_text->height = text_height;
1220 if (visibleMenuPos(pos_button))
1222 if (pos_text->x == -1)
1223 pos_text->x = pos_button->x + pos_button->width;
1224 if (pos_text->y == -1)
1226 pos_button->y + (pos_button->height - pos_text->height) / 2;
1230 if (pos_input != NULL) // (x/y may be -1/-1 here)
1232 if (visibleTextPos(pos_text))
1234 if (pos_input->x == -1)
1235 pos_input->x = pos_text->x + pos_text->width;
1236 if (pos_input->y == -1)
1237 pos_input->y = pos_text->y;
1240 if (pos_input->width == -1)
1241 pos_input->width = input_width;
1242 if (pos_input->height == -1)
1243 pos_input->height = input_height;
1248 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1249 int graphic, boolean pressed)
1251 struct GraphicInfo *g = &graphic_info[graphic];
1254 int xoffset = (pressed ? g->pressed_xoffset : 0);
1255 int yoffset = (pressed ? g->pressed_yoffset : 0);
1257 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1259 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1260 g->width, g->height, dst_x, dst_y);
1263 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1264 boolean active_input,
1265 boolean pressed_button)
1269 for (i = 0; main_controls[i].nr != -1; i++)
1271 struct MainControlInfo *mci = &main_controls[i];
1273 if (mci->nr == nr || nr == -1)
1275 struct MenuPosInfo *pos_button = mci->pos_button;
1276 struct TextPosInfo *pos_text = mci->pos_text;
1277 struct TextPosInfo *pos_input = mci->pos_input;
1278 char *text = (mci->text ? *mci->text : NULL);
1279 char *input = (mci->input ? *mci->input : NULL);
1280 int button_graphic = mci->button_graphic;
1281 int font_text = (pos_text ? pos_text->font : -1);
1282 int font_input = (pos_input ? pos_input->font : -1);
1286 button_graphic = BUTTON_ACTIVE(button_graphic);
1287 font_text = FONT_ACTIVE(font_text);
1292 font_input = FONT_ACTIVE(font_input);
1295 if (visibleMenuPos(pos_button))
1297 struct MenuPosInfo *pos = pos_button;
1298 int x = mSX + pos->x;
1299 int y = mSY + pos->y;
1301 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1302 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1305 if (visibleTextPos(pos_text) && text != NULL)
1307 struct TextPosInfo *pos = pos_text;
1308 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1309 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1312 // (check why/if this is needed)
1313 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1315 DrawText(x, y, text, font_text);
1318 if (visibleTextPos(pos_input) && input != NULL)
1320 struct TextPosInfo *pos = pos_input;
1321 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1322 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1325 // (check why/if this is needed)
1326 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1328 DrawText(x, y, input, font_input);
1334 static void DrawCursorAndText_Main(int nr, boolean active_text,
1335 boolean pressed_button)
1337 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1341 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1342 boolean pressed_button)
1344 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1348 static struct MainControlInfo *getMainControlInfo(int nr)
1352 for (i = 0; main_controls[i].nr != -1; i++)
1353 if (main_controls[i].nr == nr)
1354 return &main_controls[i];
1359 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1364 int rect_x = ALIGNED_TEXT_XPOS(rect);
1365 int rect_y = ALIGNED_TEXT_YPOS(rect);
1367 return (x >= rect_x && x < rect_x + rect->width &&
1368 y >= rect_y && y < rect_y + rect->height);
1371 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1376 int rect_x = ALIGNED_TEXT_XPOS(rect);
1377 int rect_y = ALIGNED_TEXT_YPOS(rect);
1380 Debug("screens:insideTextPosRect",
1381 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1382 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1383 (x >= rect_x && x < rect_x + rect->width &&
1384 y >= rect_y && y < rect_y + rect->height));
1387 return (x >= rect_x && x < rect_x + rect->width &&
1388 y >= rect_y && y < rect_y + rect->height);
1391 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1393 int rect_width = preview->xsize * preview->tile_size;
1394 int rect_height = preview->ysize * preview->tile_size;
1395 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1396 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1398 return (x >= rect_x && x < rect_x + rect_width &&
1399 y >= rect_y && y < rect_y + rect_height);
1402 static void AdjustScrollbar(int id, int items_max, int items_visible,
1405 struct GadgetInfo *gi = screen_gadget[id];
1407 if (item_position > items_max - items_visible)
1408 item_position = items_max - items_visible;
1410 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1411 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1412 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1415 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1417 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1421 static void clearMenuListArea(void)
1423 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1425 // correct scrollbar position if placed outside menu (playfield) area
1426 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1427 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1429 // clear menu list area, but not title or scrollbar
1430 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1431 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1434 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1436 static int cursor_array[MAX_LEV_FIELDY];
1437 int x = amSX + TILEX * xpos;
1438 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1443 cursor_array[ypos] = graphic;
1445 graphic = cursor_array[ypos];
1449 graphic = BUTTON_ACTIVE(graphic);
1451 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1452 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1455 static void initCursor(int ypos, int graphic)
1457 drawCursorExt(0, ypos, FALSE, graphic);
1460 static void drawCursor(int ypos, boolean active)
1462 drawCursorExt(0, ypos, active, -1);
1465 static void drawCursorXY(int xpos, int ypos, int graphic)
1467 drawCursorExt(xpos, ypos, FALSE, graphic);
1470 static void drawChooseTreeCursor(int ypos, boolean active)
1472 drawCursorExt(0, ypos, active, -1);
1475 static int getChooseTreeEditFont(boolean active)
1477 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1480 static int getChooseTreeEditXPos(int pos)
1482 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1483 int xoffset = (has_scrollbar ? -1 : 0);
1484 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1485 int sx = amSX + xpos * TILEX;
1486 int font_nr = getChooseTreeEditFont(FALSE);
1487 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1489 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1492 static int getChooseTreeEditYPos(int ypos_raw)
1494 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1495 int sy = amSY + ypos * TILEY;
1500 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1502 int sx = getChooseTreeEditXPos(POS_LEFT);
1503 int sy = getChooseTreeEditYPos(ypos_raw);
1504 int font_nr = getChooseTreeEditFont(active);
1506 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1509 static void DrawHeadline(void)
1511 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1512 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1515 static void DrawTitleScreenImage(int nr, boolean initial)
1517 int graphic = getTitleScreenGraphic(nr, initial);
1518 Bitmap *bitmap = graphic_info[graphic].bitmap;
1519 int width = graphic_info[graphic].width;
1520 int height = graphic_info[graphic].height;
1521 int src_x = graphic_info[graphic].src_x;
1522 int src_y = graphic_info[graphic].src_y;
1528 if (width > WIN_XSIZE)
1530 // image width too large for window => center image horizontally
1531 src_x = (width - WIN_XSIZE) / 2;
1535 if (height > WIN_YSIZE)
1537 // image height too large for window => center image vertically
1538 src_y = (height - WIN_YSIZE) / 2;
1542 // always display title screens centered
1543 dst_x = (WIN_XSIZE - width) / 2;
1544 dst_y = (WIN_YSIZE - height) / 2;
1546 SetDrawBackgroundMask(REDRAW_ALL);
1547 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1549 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1551 if (DrawingOnBackground(dst_x, dst_y))
1552 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1554 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1556 redraw_mask = REDRAW_ALL;
1559 static void DrawTitleScreenMessage(int nr, boolean initial)
1561 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1562 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1564 if (filename == NULL)
1567 // force TITLE font on title message screen
1568 SetFontStatus(getTitleMessageGameMode(initial));
1570 // if chars *and* width set to "-1", automatically determine width
1571 if (tmi->chars == -1 && tmi->width == -1)
1572 tmi->width = viewport.window[game_status].width;
1574 // if lines *and* height set to "-1", automatically determine height
1575 if (tmi->lines == -1 && tmi->height == -1)
1576 tmi->height = viewport.window[game_status].height;
1578 // if chars set to "-1", automatically determine by text and font width
1579 if (tmi->chars == -1)
1580 tmi->chars = tmi->width / getFontWidth(tmi->font);
1582 tmi->width = tmi->chars * getFontWidth(tmi->font);
1584 // if lines set to "-1", automatically determine by text and font height
1585 if (tmi->lines == -1)
1586 tmi->lines = tmi->height / getFontHeight(tmi->font);
1588 tmi->height = tmi->lines * getFontHeight(tmi->font);
1590 // if x set to "-1", automatically determine by width and alignment
1592 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1594 // if y set to "-1", automatically determine by height and alignment
1596 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1598 SetDrawBackgroundMask(REDRAW_ALL);
1599 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1601 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1603 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1604 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1605 tmi->autowrap, tmi->centered, tmi->parse_comments);
1610 static void DrawTitleScreen(void)
1612 KeyboardAutoRepeatOff();
1614 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1617 static boolean CheckTitleScreen(boolean levelset_has_changed)
1619 static boolean show_title_initial = TRUE;
1620 boolean show_titlescreen = FALSE;
1622 // needed to be able to skip title screen, if no image or message defined
1623 InitializeTitleControls(show_title_initial);
1625 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1626 show_titlescreen = TRUE;
1628 // show initial title images and messages only once at program start
1629 show_title_initial = FALSE;
1631 return (show_titlescreen && num_title_screens > 0);
1634 void DrawMainMenu(void)
1636 static LevelDirTree *leveldir_last_valid = NULL;
1637 boolean levelset_has_changed = FALSE;
1638 int fade_mask = REDRAW_FIELD;
1640 LimitScreenUpdates(FALSE);
1642 FadeSetLeaveScreen();
1644 // do not fade out here -- function may continue and fade on editor screen
1647 FadeMenuSoundsAndMusic();
1649 ExpireSoundLoops(FALSE);
1651 KeyboardAutoRepeatOn();
1653 audio.sound_deactivated = FALSE;
1657 // needed if last screen was the playing screen, invoked from level editor
1658 if (level_editor_test_game)
1660 CloseDoor(DOOR_CLOSE_ALL);
1662 SetGameStatus(GAME_MODE_EDITOR);
1669 // leveldir_current may be invalid (level group, parent link, node copy)
1670 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1672 if (leveldir_current != leveldir_last_valid)
1674 UpdateLastPlayedLevels_TreeInfo();
1676 levelset_has_changed = TRUE;
1679 // store valid level series information
1680 leveldir_last_valid = leveldir_current;
1682 init_last = init; // switch to new busy animation
1684 // needed if last screen (level choice) changed graphics, sounds or music
1685 ReloadCustomArtwork(0);
1687 if (CheckTitleScreen(levelset_has_changed))
1689 SetGameStatus(GAME_MODE_TITLE);
1696 if (redraw_mask & REDRAW_ALL)
1697 fade_mask = REDRAW_ALL;
1700 fade_mask = REDRAW_ALL;
1704 // needed if different viewport properties defined for menues
1705 ChangeViewportPropertiesIfNeeded();
1707 SetDrawtoField(DRAW_TO_BACKBUFFER);
1709 // level_nr may have been set to value over handicap with level editor
1710 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1711 level_nr = leveldir_current->handicap_level;
1713 LoadLevel(level_nr);
1714 LoadScore(level_nr);
1716 SaveLevelSetup_SeriesInfo();
1718 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1719 SetDrawDeactivationMask(REDRAW_NONE);
1720 SetDrawBackgroundMask(REDRAW_FIELD);
1722 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1725 if (fade_mask == REDRAW_ALL)
1726 RedrawGlobalBorder();
1731 InitializeMainControls();
1733 DrawCursorAndText_Main(-1, FALSE, FALSE);
1734 DrawPreviewLevelInitial();
1735 DrawNetworkPlayers();
1737 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1740 if (TAPE_IS_EMPTY(tape))
1742 DrawCompleteVideoDisplay();
1744 PlayMenuSoundsAndMusic();
1746 // create gadgets for main menu screen
1747 FreeScreenGadgets();
1748 CreateScreenGadgets();
1750 // may be required if audio buttons shown on tape and changed in setup menu
1752 CreateGameButtons();
1754 // map gadgets for main menu screen
1756 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1757 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1759 // copy actual game door content to door double buffer for OpenDoor()
1760 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1761 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1763 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1765 DrawMaskedBorder(fade_mask);
1770 // update screen area with special editor door
1771 redraw_mask |= REDRAW_ALL;
1774 SetMouseCursor(CURSOR_DEFAULT);
1776 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1778 SyncEmscriptenFilesystem();
1780 // needed once after program start or after user change
1781 CheckApiServerTasks();
1784 static void gotoTopLevelDir(void)
1786 // move upwards until inside (but not above) top level directory
1787 while (leveldir_current->node_parent &&
1788 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1790 // write a "path" into level tree for easy navigation to last level
1791 if (leveldir_current->node_parent->node_group->cl_first == -1)
1793 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1794 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1795 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1796 int cl_first, cl_cursor;
1798 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1799 cl_cursor = leveldir_pos - cl_first;
1801 leveldir_current->node_parent->node_group->cl_first = cl_first;
1802 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1805 leveldir_current = leveldir_current->node_parent;
1809 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1811 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1813 return (use_frame_counter ? video.frame_counter : Counter());
1816 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1817 struct TitleFadingInfo *fi)
1819 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1822 static void ResetTitleAutoDelay(unsigned int *counter_var,
1823 struct TitleFadingInfo *fi)
1825 *counter_var = getAutoDelayCounter(fi);
1828 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1830 static unsigned int title_delay = 0;
1831 static int title_screen_nr = 0;
1832 static int last_sound = -1, last_music = -1;
1833 boolean return_to_main_menu = FALSE;
1834 struct TitleControlInfo *tci;
1837 if (button == MB_MENU_INITIALIZE)
1840 title_screen_nr = 0;
1841 tci = &title_controls[title_screen_nr];
1843 SetAnimStatus(getTitleAnimMode(tci));
1845 last_sound = SND_UNDEFINED;
1846 last_music = MUS_UNDEFINED;
1848 if (num_title_screens != 0)
1850 FadeSetEnterScreen();
1852 // use individual title fading instead of global "enter screen" fading
1853 fading = getTitleFading(tci);
1856 if (game_status_last_screen == GAME_MODE_INFO)
1858 if (num_title_screens == 0)
1860 // switch game mode from title screen mode back to info screen mode
1861 SetGameStatus(GAME_MODE_INFO);
1863 // store that last screen was info screen, not main menu screen
1864 game_status_last_screen = GAME_MODE_INFO;
1866 DrawInfoScreen_NotAvailable("Title screen information:",
1867 "No title screen for this level set.");
1872 FadeMenuSoundsAndMusic();
1874 FadeOut(REDRAW_ALL);
1876 // title screens may have different window size
1877 ChangeViewportPropertiesIfNeeded();
1879 // only required to update logic for redrawing global border
1883 DrawTitleScreenImage(tci->local_nr, tci->initial);
1885 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1887 sound = getTitleSound(tci);
1888 music = getTitleMusic(tci);
1890 if (sound != last_sound)
1891 PlayMenuSoundExt(sound);
1892 if (music != last_music)
1893 PlayMenuMusicExt(music);
1898 SetMouseCursor(CURSOR_NONE);
1902 ResetTitleAutoDelay(&title_delay, &fading);
1907 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1908 button = MB_MENU_CHOICE;
1910 if (button == MB_MENU_LEAVE)
1912 return_to_main_menu = TRUE;
1914 else if (button == MB_MENU_CHOICE)
1916 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1918 SetGameStatus(GAME_MODE_INFO);
1920 info_mode = INFO_MODE_MAIN;
1929 if (title_screen_nr < num_title_screens)
1931 tci = &title_controls[title_screen_nr];
1933 SetAnimStatus(getTitleAnimMode(tci));
1935 sound = getTitleSound(tci);
1936 music = getTitleMusic(tci);
1938 if (last_sound != SND_UNDEFINED && sound != last_sound)
1939 FadeSound(last_sound);
1940 if (last_music != MUS_UNDEFINED && music != last_music)
1943 fading = getTitleFading(tci);
1945 FadeOut(REDRAW_ALL);
1948 DrawTitleScreenImage(tci->local_nr, tci->initial);
1950 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1952 sound = getTitleSound(tci);
1953 music = getTitleMusic(tci);
1955 if (sound != last_sound)
1956 PlayMenuSoundExt(sound);
1957 if (music != last_music)
1958 PlayMenuMusicExt(music);
1965 ResetTitleAutoDelay(&title_delay, &fading);
1969 FadeMenuSoundsAndMusic();
1971 return_to_main_menu = TRUE;
1975 if (return_to_main_menu)
1977 SetMouseCursor(CURSOR_DEFAULT);
1979 // force full menu screen redraw after displaying title screens
1980 redraw_mask = REDRAW_ALL;
1982 if (game_status_last_screen == GAME_MODE_INFO)
1984 SetGameStatus(GAME_MODE_INFO);
1986 info_mode = INFO_MODE_MAIN;
1990 else // default: return to main menu
1992 SetGameStatus(GAME_MODE_MAIN);
1999 static void HandleMainMenu_ToggleTeamMode(void)
2001 setup.team_mode = !setup.team_mode;
2003 InitializeMainControls();
2004 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2006 DrawPreviewPlayers();
2009 static void HandleMainMenu_SelectLevel(int step, int direction,
2010 int selected_level_nr)
2012 int old_level_nr = level_nr;
2015 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2016 new_level_nr = selected_level_nr;
2018 new_level_nr = old_level_nr + step * direction;
2020 if (new_level_nr < leveldir_current->first_level)
2021 new_level_nr = leveldir_current->first_level;
2022 if (new_level_nr > leveldir_current->last_level)
2023 new_level_nr = leveldir_current->last_level;
2025 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2027 // skipping levels is only allowed when trying to skip single level
2028 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2029 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2031 leveldir_current->handicap_level++;
2032 SaveLevelSetup_SeriesInfo();
2035 new_level_nr = leveldir_current->handicap_level;
2038 if (new_level_nr != old_level_nr)
2040 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2042 PlaySound(SND_MENU_ITEM_SELECTING);
2044 level_nr = new_level_nr;
2046 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2047 int2str(level_nr, menu.main.text.level_number.size),
2048 mci->pos_text->font);
2050 LoadLevel(level_nr);
2051 DrawPreviewLevelInitial();
2055 DrawCompleteVideoDisplay();
2057 SaveLevelSetup_SeriesInfo();
2059 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2061 // force redraw of playfield area (may be reset at this point)
2062 redraw_mask |= REDRAW_FIELD;
2066 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2068 static int choice = MAIN_CONTROL_GAME;
2069 static boolean button_pressed_last = FALSE;
2070 boolean button_pressed = FALSE;
2072 int i = 0; // needed to prevent compiler warning due to bad code below
2074 if (button == MB_MENU_INITIALIZE)
2076 DrawCursorAndText_Main(choice, TRUE, FALSE);
2081 if (mx || my) // mouse input
2085 for (i = 0; main_controls[i].nr != -1; i++)
2087 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2088 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2089 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2091 pos = main_controls[i].nr;
2097 // check if level preview was clicked
2098 if (insidePreviewRect(&preview, mx - SX, my - SY))
2099 pos = MAIN_CONTROL_GAME;
2101 // handle pressed/unpressed state for active/inactive menu buttons
2102 // (if pos != -1, "i" contains index position corresponding to "pos")
2104 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2105 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2106 button_pressed = TRUE;
2108 if (button_pressed != button_pressed_last)
2110 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2113 PlaySound(SND_MENU_BUTTON_PRESSING);
2115 PlaySound(SND_MENU_BUTTON_RELEASING);
2118 else if (dx || dy) // keyboard input
2120 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2121 choice == MAIN_CONTROL_SETUP))
2122 button = MB_MENU_CHOICE;
2127 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2129 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2131 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2133 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2135 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2137 CloseDoor(DOOR_CLOSE_2);
2139 SetGameStatus(GAME_MODE_LEVELNR);
2141 DrawChooseLevelNr();
2143 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2149 PlaySound(SND_MENU_ITEM_ACTIVATING);
2151 DrawCursorAndText_Main(choice, FALSE, FALSE);
2152 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2158 if (choice == MAIN_CONTROL_NAME)
2160 // special case: cursor left or right pressed -- toggle team mode
2161 HandleMainMenu_ToggleTeamMode();
2163 else if (choice != MAIN_CONTROL_INFO &&
2164 choice != MAIN_CONTROL_SETUP)
2166 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2172 PlaySound(SND_MENU_ITEM_SELECTING);
2174 if (pos == MAIN_CONTROL_NAME)
2177 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2179 // special case: menu text "name/team" clicked -- toggle team mode
2180 HandleMainMenu_ToggleTeamMode();
2184 if (setup.multiple_users)
2186 CloseDoor(DOOR_CLOSE_2);
2188 SetGameStatus(GAME_MODE_NAMES);
2190 DrawChoosePlayerName();
2194 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2200 else if (pos == MAIN_CONTROL_LEVELS)
2204 CloseDoor(DOOR_CLOSE_2);
2206 SetGameStatus(GAME_MODE_LEVELS);
2208 SaveLevelSetup_LastSeries();
2209 SaveLevelSetup_SeriesInfo();
2211 // restore level set if chosen from "last played level set" menu
2212 RestoreLastPlayedLevels(&leveldir_current);
2214 if (setup.internal.choose_from_top_leveldir)
2217 DrawChooseLevelSet();
2220 else if (pos == MAIN_CONTROL_SCORES)
2222 CloseDoor(DOOR_CLOSE_2);
2224 SetGameStatus(GAME_MODE_SCORES);
2226 DrawHallOfFame(level_nr);
2228 else if (pos == MAIN_CONTROL_EDITOR)
2230 if (leveldir_current->readonly &&
2231 setup.editor.show_read_only_warning)
2232 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2234 CloseDoor(DOOR_CLOSE_ALL);
2236 SetGameStatus(GAME_MODE_EDITOR);
2238 FadeSetEnterScreen();
2242 else if (pos == MAIN_CONTROL_INFO)
2244 CloseDoor(DOOR_CLOSE_2);
2246 SetGameStatus(GAME_MODE_INFO);
2248 info_mode = INFO_MODE_MAIN;
2252 else if (pos == MAIN_CONTROL_GAME)
2254 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2256 else if (pos == MAIN_CONTROL_SETUP)
2258 CloseDoor(DOOR_CLOSE_2);
2260 SetGameStatus(GAME_MODE_SETUP);
2262 setup_mode = SETUP_MODE_MAIN;
2266 else if (pos == MAIN_CONTROL_QUIT)
2268 SaveLevelSetup_LastSeries();
2269 SaveLevelSetup_SeriesInfo();
2271 #if defined(PLATFORM_EMSCRIPTEN)
2272 Request("Close the browser window to quit!", REQ_CONFIRM);
2274 if (!setup.ask_on_quit_program ||
2275 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2276 SetGameStatus(GAME_MODE_QUIT);
2282 button_pressed_last = button_pressed;
2286 // ============================================================================
2287 // info screen functions
2288 // ============================================================================
2290 static struct TokenInfo *info_info;
2291 static int num_info_info; // number of info entries shown on screen
2292 static int max_info_info; // total number of info entries in list
2294 static void execInfoTitleScreen(void)
2296 info_mode = INFO_MODE_TITLE;
2301 static void execInfoElements(void)
2303 info_mode = INFO_MODE_ELEMENTS;
2308 static void execInfoMusic(void)
2310 info_mode = INFO_MODE_MUSIC;
2315 static void execInfoCredits(void)
2317 info_mode = INFO_MODE_CREDITS;
2322 static void execInfoProgram(void)
2324 info_mode = INFO_MODE_PROGRAM;
2329 static void execInfoVersion(void)
2331 info_mode = INFO_MODE_VERSION;
2336 static void execInfoLevelSet(void)
2338 info_mode = INFO_MODE_LEVELSET;
2343 static void execExitInfo(void)
2345 SetGameStatus(GAME_MODE_MAIN);
2350 static struct TokenInfo info_info_main[] =
2352 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2353 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2354 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2355 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2356 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2357 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2358 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2359 { TYPE_EMPTY, NULL, "" },
2360 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2365 static int getMenuTextFont(int type)
2367 if (type & (TYPE_SWITCH |
2381 static struct TokenInfo *setup_info;
2382 static struct TokenInfo setup_info_input[];
2384 static struct TokenInfo *menu_info;
2386 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2387 int screen_pos, int menu_info_pos_raw,
2390 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2391 struct TokenInfo *ti = &token_info[pos];
2392 int xpos = MENU_SCREEN_START_XPOS;
2393 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2394 int font_nr = getMenuTextFont(ti->type);
2396 if (setup_mode == SETUP_MODE_INPUT)
2397 font_nr = FONT_MENU_1;
2400 font_nr = FONT_ACTIVE(font_nr);
2402 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2404 if (ti->type & ~TYPE_SKIP_ENTRY)
2405 drawCursor(screen_pos, active);
2408 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2411 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2414 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2417 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2420 static char *window_size_text;
2421 static char *scaling_type_text;
2422 static char *network_server_text;
2424 static void drawSetupValue(int, int);
2426 static void drawMenuInfoList(int first_entry, int num_page_entries,
2427 int max_page_entries)
2431 if (first_entry + num_page_entries > max_page_entries)
2434 clearMenuListArea();
2436 for (i = 0; i < num_page_entries; i++)
2438 int menu_info_pos = first_entry + i;
2439 struct TokenInfo *si = &menu_info[menu_info_pos];
2440 void *value_ptr = si->value;
2442 // set some entries to "unchangeable" according to other variables
2443 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2444 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2445 (value_ptr == &setup.sound_music && !audio.music_available) ||
2446 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2447 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2448 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2449 si->type |= TYPE_GHOSTED;
2451 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2452 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2453 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2454 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2455 else if (si->type & ~TYPE_SKIP_ENTRY)
2456 initCursor(i, IMG_MENU_BUTTON);
2458 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2460 if (si->type & TYPE_STRING)
2464 if (value_ptr == &network_server_text)
2465 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2467 if (gadget_id != -1)
2469 struct GadgetInfo *gi = screen_gadget[gadget_id];
2470 int xpos = MENU_SCREEN_START_XPOS;
2471 int ypos = MENU_SCREEN_START_YPOS + i;
2472 int x = mSX + xpos * 32;
2473 int y = mSY + ypos * 32;
2475 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2479 if (si->type & TYPE_VALUE &&
2480 menu_info == setup_info)
2481 drawSetupValue(i, menu_info_pos);
2485 static void DrawInfoScreen_Main(void)
2487 int fade_mask = REDRAW_FIELD;
2490 if (redraw_mask & REDRAW_ALL)
2491 fade_mask = REDRAW_ALL;
2494 fade_mask = REDRAW_ALL;
2497 FadeMenuSoundsAndMusic();
2499 FreeScreenGadgets();
2500 CreateScreenGadgets();
2502 // (needed after displaying title screens which disable auto repeat)
2503 KeyboardAutoRepeatOn();
2505 FadeSetLeaveScreen();
2509 // needed if different viewport properties defined for info screen
2510 ChangeViewportPropertiesIfNeeded();
2512 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2516 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2518 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2520 info_info = info_info_main;
2522 // determine maximal number of info entries that can be displayed on screen
2524 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2527 // determine maximal number of info entries available for menu of info screen
2529 for (i = 0; info_info[i].type != 0; i++)
2532 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2534 MapScreenGadgets(max_info_info);
2536 PlayMenuSoundsAndMusic();
2538 DrawMaskedBorder(fade_mask);
2543 static void changeSetupValue(int, int, int);
2545 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2546 int mode, int num_page_entries,
2547 int max_page_entries)
2549 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2550 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2551 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2552 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2553 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2554 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2555 int *num_page_entries_last = num_page_entries_all_last[game_status];
2556 int *choice_store = choice_stores[game_status];
2557 int *first_entry_store = first_entry_stores[game_status];
2558 int choice = choice_store[mode]; // starts with 0
2559 int first_entry = first_entry_store[mode]; // starts with 0
2561 int y = choice - first_entry;
2563 boolean position_set_by_scrollbar = (dx == 999);
2564 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2567 if (button == MB_MENU_INITIALIZE)
2569 // check if number of menu page entries has changed (may happen by change
2570 // of custom artwork definition value for 'list_size' for this menu screen)
2571 // (in this case, the last menu position most probably has to be corrected)
2572 if (num_page_entries != num_page_entries_last[mode])
2574 choice_store[mode] = first_entry_store[mode] = 0;
2576 choice = first_entry = 0;
2579 num_page_entries_last[mode] = num_page_entries;
2582 // advance to first valid menu entry
2583 while (choice < num_page_entries &&
2584 menu_info[choice].type & TYPE_SKIP_ENTRY)
2587 if (position_set_by_scrollbar)
2588 first_entry = first_entry_store[mode] = dy;
2590 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2591 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2593 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2595 if (choice < first_entry)
2597 choice = first_entry;
2599 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2602 else if (choice > first_entry + num_page_entries - 1)
2604 choice = first_entry + num_page_entries - 1;
2606 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2610 choice_store[mode] = choice;
2612 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2616 else if (button == MB_MENU_LEAVE)
2618 PlaySound(SND_MENU_ITEM_SELECTING);
2620 for (i = 0; i < max_page_entries; i++)
2622 if (menu_info[i].type & TYPE_LEAVE_MENU)
2624 void (*menu_callback_function)(void) = menu_info[i].value;
2628 menu_callback_function();
2630 break; // absolutely needed because function changes 'menu_info'!
2637 if (mx || my) // mouse input
2639 x = (mx - mSX) / 32;
2640 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2642 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2644 // move cursor instead of scrolling when already at start/end of list
2645 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2647 else if (dy == +1 * SCROLL_LINE &&
2648 first_entry + num_page_entries == max_page_entries)
2651 // handle scrolling screen one line or page
2653 y + dy > num_page_entries - 1)
2655 boolean redraw = FALSE;
2657 if (ABS(dy) == SCROLL_PAGE)
2658 step = num_page_entries - 1;
2660 if (dy < 0 && first_entry > 0)
2662 // scroll page/line up
2664 first_entry -= step;
2665 if (first_entry < 0)
2670 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2672 // scroll page/line down
2674 first_entry += step;
2675 if (first_entry + num_page_entries > max_page_entries)
2676 first_entry = MAX(0, max_page_entries - num_page_entries);
2683 choice += first_entry - first_entry_store[mode];
2685 if (choice < first_entry)
2687 choice = first_entry;
2689 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2692 else if (choice > first_entry + num_page_entries - 1)
2694 choice = first_entry + num_page_entries - 1;
2696 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2699 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2703 if (choice < first_entry ||
2704 choice > first_entry + num_page_entries - 1)
2705 first_entry += SIGN(dy);
2708 first_entry_store[mode] = first_entry;
2709 choice_store[mode] = choice;
2711 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2713 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2715 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2716 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2724 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2726 if (menu_info[choice].type & menu_navigation_type ||
2727 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2728 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2729 menu_info[choice].type & TYPE_PLAYER)
2730 button = MB_MENU_CHOICE;
2735 // jump to next non-empty menu entry (up or down)
2736 while (first_entry + y > 0 &&
2737 first_entry + y < max_page_entries - 1 &&
2738 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2741 if (!IN_VIS_MENU(x, y))
2743 choice += y - y_old;
2745 if (choice < first_entry)
2746 first_entry = choice;
2747 else if (choice > first_entry + num_page_entries - 1)
2748 first_entry = choice - num_page_entries + 1;
2750 if (first_entry >= 0 &&
2751 first_entry + num_page_entries <= max_page_entries)
2753 first_entry_store[mode] = first_entry;
2755 if (choice < first_entry)
2756 choice = first_entry;
2757 else if (choice > first_entry + num_page_entries - 1)
2758 choice = first_entry + num_page_entries - 1;
2760 choice_store[mode] = choice;
2762 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2764 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2766 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2767 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2774 if (!anyScrollbarGadgetActive() &&
2775 IN_VIS_MENU(x, y) &&
2776 mx < mx_right_border &&
2777 y >= 0 && y < num_page_entries)
2781 if (first_entry + y != choice &&
2782 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2784 PlaySound(SND_MENU_ITEM_ACTIVATING);
2786 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2787 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2789 choice = choice_store[mode] = first_entry + y;
2793 PlaySound(SND_MENU_ITEM_SELECTING);
2795 for (i = 0; menu_info[i].type != 0; i++)
2797 if (menu_info[i].type & TYPE_LEAVE_MENU)
2799 void (*menu_callback_function)(void) = menu_info[i].value;
2803 menu_callback_function();
2805 // absolutely needed because function changes 'menu_info'!
2813 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2815 PlaySound(SND_MENU_ITEM_SELECTING);
2817 // when selecting key headline, execute function for key value change
2818 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2819 menu_info[first_entry + y + 1].type & TYPE_KEY)
2822 // when selecting string value, execute function for list selection
2823 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2824 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2827 // when selecting string value, execute function for text input gadget
2828 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2829 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2832 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2834 void (*menu_callback_function)(void) =
2835 menu_info[first_entry + y].value;
2837 FadeSetFromType(menu_info[first_entry + y].type);
2839 menu_callback_function();
2841 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2843 void (*gadget_callback_function)(void) =
2844 menu_info[first_entry + y].value;
2846 gadget_callback_function();
2848 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2849 menu_info == setup_info)
2851 changeSetupValue(y, first_entry + y, dx);
2857 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2859 menu_info = info_info;
2861 HandleMenuScreen(mx, my, dx, dy, button,
2862 info_mode, num_info_info, max_info_info);
2865 static int getMenuFontSpacing(int spacing_height, int font_nr)
2867 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2869 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2873 static int getMenuTextSpacing(int spacing_height, int font_nr)
2875 return (getMenuFontSpacing(spacing_height, font_nr) +
2876 EXTRA_SPACING(game_status));
2879 static int getMenuTextStep(int spacing_height, int font_nr)
2881 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2884 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2886 int font_title = MENU_INFO_FONT_TITLE;
2887 int font_error = FONT_TEXT_2;
2888 int font_foot = MENU_INFO_FONT_FOOT;
2889 int spacing_title = menu.headline1_spacing_info[info_mode];
2890 int ystep_title = getMenuTextStep(spacing_title, font_title);
2891 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2892 int ystart2 = ystart1 + ystep_title;
2893 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2895 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2897 FadeOut(REDRAW_FIELD);
2902 DrawTextSCentered(ystart1, font_title, text_title);
2903 DrawTextSCentered(ystart2, font_error, text_error);
2905 DrawTextSCentered(ybottom, font_foot,
2906 "Press any key or button for info menu");
2908 FadeIn(REDRAW_FIELD);
2911 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2913 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2914 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2915 int font_title = MENU_INFO_FONT_TITLE;
2916 int font_foot = MENU_INFO_FONT_FOOT;
2917 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2918 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2919 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2920 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2921 int ystep = MENU_SCREEN_INFO_YSTEP;
2922 int element, action, direction;
2930 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2931 infoscreen_step[i] = infoscreen_frame[i] = 0;
2936 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2938 DrawTextSCentered(ybottom, font_foot,
2939 "Press any key or button for next page");
2945 while (helpanim_info[j].element != HELPANIM_LIST_END)
2947 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2952 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2961 j += infoscreen_step[i - start];
2963 element = helpanim_info[j].element;
2964 action = helpanim_info[j].action;
2965 direction = helpanim_info[j].direction;
2968 element = EL_UNKNOWN;
2970 if (action != -1 && direction != -1)
2971 graphic = el_act_dir2img(element, action, direction);
2972 else if (action != -1)
2973 graphic = el_act2img(element, action);
2974 else if (direction != -1)
2975 graphic = el_dir2img(element, direction);
2977 graphic = el2img(element);
2979 delay = helpanim_info[j++].delay;
2984 if (infoscreen_frame[i - start] == 0)
2987 infoscreen_frame[i - start] = delay - 1;
2991 sync_frame = delay - infoscreen_frame[i - start];
2992 infoscreen_frame[i - start]--;
2995 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2997 if (!infoscreen_frame[i - start])
2998 infoscreen_step[i - start] = 0;
3002 if (!infoscreen_frame[i - start])
3003 infoscreen_step[i - start]++;
3004 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3010 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3012 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3013 graphic, sync_frame, USE_MASKING);
3016 DrawInfoScreen_HelpText(element, action, direction, i - start);
3021 redraw_mask |= REDRAW_FIELD;
3026 static char *getHelpText(int element, int action, int direction)
3028 char token[MAX_LINE_LEN];
3030 strcpy(token, element_info[element].token_name);
3033 strcat(token, element_action_info[action].suffix);
3035 if (direction != -1)
3036 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3038 return getHashEntry(helptext_info, token);
3041 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3043 int font_nr = FONT_INFO_ELEMENTS;
3044 int font_width = getFontWidth(font_nr);
3045 int font_height = getFontHeight(font_nr);
3046 int yoffset = (TILEX - 2 * font_height) / 2;
3047 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3048 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3049 int ystep = TILEY + 4;
3050 int pad_left = xstart - SX;
3051 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3052 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3053 int max_lines_per_text = 2;
3056 if (action != -1 && direction != -1) // element.action.direction
3057 text = getHelpText(element, action, direction);
3059 if (text == NULL && action != -1) // element.action
3060 text = getHelpText(element, action, -1);
3062 if (text == NULL && direction != -1) // element.direction
3063 text = getHelpText(element, -1, direction);
3065 if (text == NULL) // base element
3066 text = getHelpText(element, -1, -1);
3068 if (text == NULL) // not found
3069 text = "No description available";
3071 if (strlen(text) <= max_chars_per_line) // only one line of text
3072 ystart += getFontHeight(font_nr) / 2;
3074 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3075 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3076 TRUE, FALSE, FALSE);
3079 static void DrawInfoScreen_TitleScreen(void)
3081 SetGameStatus(GAME_MODE_TITLE);
3086 void HandleInfoScreen_TitleScreen(int button)
3088 HandleTitleScreen(0, 0, 0, 0, button);
3091 static void DrawInfoScreen_Elements(void)
3093 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3095 FadeOut(REDRAW_FIELD);
3100 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3102 FadeIn(REDRAW_FIELD);
3105 void HandleInfoScreen_Elements(int button)
3107 static unsigned int info_delay = 0;
3108 static int num_anims;
3109 static int num_pages;
3111 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3114 if (button == MB_MENU_INITIALIZE)
3116 boolean new_element = TRUE;
3120 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3122 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3124 else if (new_element)
3127 new_element = FALSE;
3131 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3135 if (button == MB_MENU_LEAVE)
3137 PlaySound(SND_MENU_ITEM_SELECTING);
3139 info_mode = INFO_MODE_MAIN;
3144 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3146 if (button != MB_MENU_INITIALIZE)
3148 PlaySound(SND_MENU_ITEM_SELECTING);
3153 if (page >= num_pages)
3155 FadeMenuSoundsAndMusic();
3157 info_mode = INFO_MODE_MAIN;
3164 FadeSetNextScreen();
3166 if (button != MB_MENU_INITIALIZE)
3167 FadeOut(REDRAW_FIELD);
3169 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3171 if (button != MB_MENU_INITIALIZE)
3172 FadeIn(REDRAW_FIELD);
3176 if (DelayReached(&info_delay, GameFrameDelay))
3177 if (page < num_pages)
3178 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3180 PlayMenuSoundIfLoop();
3184 static void DrawInfoScreen_Music(void)
3186 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3188 FadeOut(REDRAW_FIELD);
3195 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3197 FadeIn(REDRAW_FIELD);
3200 void HandleInfoScreen_Music(int button)
3202 static struct MusicFileInfo *list = NULL;
3203 int font_title = MENU_INFO_FONT_TITLE;
3204 int font_head = MENU_INFO_FONT_HEAD;
3205 int font_text = MENU_INFO_FONT_TEXT;
3206 int font_foot = MENU_INFO_FONT_FOOT;
3207 int spacing_title = menu.headline1_spacing_info[info_mode];
3208 int spacing_head = menu.headline2_spacing_info[info_mode];
3209 int ystep_title = getMenuTextStep(spacing_title, font_title);
3210 int ystep_head = getMenuTextStep(spacing_head, font_head);
3211 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3212 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3214 if (button == MB_MENU_INITIALIZE)
3216 list = music_file_info;
3220 FadeMenuSoundsAndMusic();
3225 DrawTextSCentered(ystart, font_title,
3226 "No music info for this level set.");
3228 DrawTextSCentered(ybottom, font_foot,
3229 "Press any key or button for info menu");
3235 if (button == MB_MENU_LEAVE)
3237 PlaySound(SND_MENU_ITEM_SELECTING);
3239 FadeMenuSoundsAndMusic();
3241 info_mode = INFO_MODE_MAIN;
3246 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3248 if (button != MB_MENU_INITIALIZE)
3250 PlaySound(SND_MENU_ITEM_SELECTING);
3258 FadeMenuSoundsAndMusic();
3260 info_mode = INFO_MODE_MAIN;
3266 FadeMenuSoundsAndMusic();
3268 if (list != music_file_info)
3269 FadeSetNextScreen();
3271 if (button != MB_MENU_INITIALIZE)
3272 FadeOut(REDRAW_FIELD);
3279 int sound = list->music;
3281 if (IS_LOOP_SOUND(sound))
3282 PlaySoundLoop(sound);
3286 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3290 int music = list->music;
3292 if (IS_LOOP_MUSIC(music))
3293 PlayMusicLoop(music);
3297 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3300 ystart += ystep_title;
3302 if (!strEqual(list->title, UNKNOWN_NAME))
3304 if (!strEqual(list->title_header, UNKNOWN_NAME))
3306 DrawTextSCentered(ystart, font_head, list->title_header);
3307 ystart += ystep_head;
3310 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3311 ystart += ystep_head;
3314 if (!strEqual(list->artist, UNKNOWN_NAME))
3316 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3317 DrawTextSCentered(ystart, font_head, list->artist_header);
3319 DrawTextSCentered(ystart, font_head, "by");
3321 ystart += ystep_head;
3323 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3324 ystart += ystep_head;
3327 if (!strEqual(list->album, UNKNOWN_NAME))
3329 if (!strEqual(list->album_header, UNKNOWN_NAME))
3330 DrawTextSCentered(ystart, font_head, list->album_header);
3332 DrawTextSCentered(ystart, font_head, "from the album");
3334 ystart += ystep_head;
3336 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3337 ystart += ystep_head;
3340 if (!strEqual(list->year, UNKNOWN_NAME))
3342 if (!strEqual(list->year_header, UNKNOWN_NAME))
3343 DrawTextSCentered(ystart, font_head, list->year_header);
3345 DrawTextSCentered(ystart, font_head, "from the year");
3347 ystart += ystep_head;
3349 DrawTextFCentered(ystart, font_text, "%s", list->year);
3350 ystart += ystep_head;
3353 DrawTextSCentered(ybottom, FONT_TEXT_4,
3354 "Press any key or button for next page");
3356 if (button != MB_MENU_INITIALIZE)
3357 FadeIn(REDRAW_FIELD);
3360 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3361 PlaySoundLoop(list->music);
3364 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3366 int font_title = MENU_INFO_FONT_TITLE;
3367 int font_head = MENU_INFO_FONT_HEAD;
3368 int font_text = MENU_INFO_FONT_TEXT;
3369 int font_foot = MENU_INFO_FONT_FOOT;
3370 int spacing_title = menu.headline1_spacing_info[info_mode];
3371 int spacing_head = menu.headline2_spacing_info[info_mode];
3372 int spacing_para = menu.paragraph_spacing_info[info_mode];
3373 int spacing_line = menu.line_spacing_info[info_mode];
3374 int ystep_title = getMenuTextStep(spacing_title, font_title);
3375 int ystep_head = getMenuTextStep(spacing_head, font_head);
3376 int ystep_para = getMenuTextStep(spacing_para, font_text);
3377 int ystep_line = getMenuTextStep(spacing_line, font_text);
3378 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3379 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3384 DrawTextSCentered(ystart, font_title, "Credits:");
3385 ystart += ystep_title;
3389 DrawTextSCentered(ystart, font_head,
3390 "Special thanks to");
3391 ystart += ystep_head;
3392 DrawTextSCentered(ystart, font_text,
3394 ystart += ystep_head;
3395 DrawTextSCentered(ystart, font_head,
3397 ystart += ystep_head;
3398 DrawTextSCentered(ystart, font_text,
3399 "\"Boulder Dash\"");
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_head,
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_text,
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_head,
3409 ystart += ystep_head;
3410 DrawTextSCentered(ystart, font_text,
3411 "First Star Software");
3413 else if (screen_nr == 1)
3415 DrawTextSCentered(ystart, font_head,
3416 "Special thanks to");
3417 ystart += ystep_head;
3418 DrawTextSCentered(ystart, font_text,
3419 "Klaus Heinz & Volker Wertich");
3420 ystart += ystep_head;
3421 DrawTextSCentered(ystart, font_head,
3423 ystart += ystep_head;
3424 DrawTextSCentered(ystart, font_text,
3425 "\"Emerald Mine\"");
3426 ystart += ystep_head;
3427 DrawTextSCentered(ystart, font_head,
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_text,
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_head,
3435 ystart += ystep_head;
3436 DrawTextSCentered(ystart, font_text,
3439 else if (screen_nr == 2)
3441 DrawTextSCentered(ystart, font_head,
3442 "Special thanks to");
3443 ystart += ystep_head;
3444 DrawTextSCentered(ystart, font_text,
3445 "Michael Stopp & Philip Jespersen");
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,
3458 ystart += ystep_head;
3459 DrawTextSCentered(ystart, font_head,
3461 ystart += ystep_head;
3462 DrawTextSCentered(ystart, font_text,
3463 "Digital Integration");
3465 else if (screen_nr == 3)
3467 DrawTextSCentered(ystart, font_head,
3468 "Special thanks to");
3469 ystart += ystep_head;
3470 DrawTextSCentered(ystart, font_text,
3471 "Hiroyuki Imabayashi");
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,
3484 ystart += ystep_head;
3485 DrawTextSCentered(ystart, font_head,
3487 ystart += ystep_head;
3488 DrawTextSCentered(ystart, font_text,
3491 else if (screen_nr == 4)
3493 DrawTextSCentered(ystart, font_head,
3494 "Special thanks to");
3495 ystart += ystep_head;
3496 DrawTextSCentered(ystart, font_text,
3498 ystart += ystep_head;
3499 DrawTextSCentered(ystart, font_head,
3501 ystart += ystep_head;
3502 DrawTextSCentered(ystart, font_text,
3503 "J\xfcrgen Bonhagen");
3504 ystart += ystep_head;
3505 DrawTextSCentered(ystart, font_head,
3506 "for the continuous creation");
3507 ystart += ystep_line;
3508 DrawTextSCentered(ystart, font_head,
3509 "of outstanding level sets");
3511 else if (screen_nr == 5)
3513 DrawTextSCentered(ystart, font_head,
3515 ystart += ystep_head;
3516 DrawTextSCentered(ystart, font_text,
3518 ystart += ystep_head;
3519 DrawTextSCentered(ystart, font_head,
3520 "for ideas and inspiration by");
3521 ystart += ystep_head;
3522 DrawTextSCentered(ystart, font_text,
3524 ystart += ystep_para;
3526 DrawTextSCentered(ystart, font_head,
3528 ystart += ystep_head;
3529 DrawTextSCentered(ystart, font_text,
3531 ystart += ystep_head;
3532 DrawTextSCentered(ystart, font_head,
3533 "for ideas and inspiration by");
3534 ystart += ystep_head;
3535 DrawTextSCentered(ystart, font_text,
3538 else if (screen_nr == 6)
3540 DrawTextSCentered(ystart, font_head,
3542 ystart += ystep_head;
3543 DrawTextSCentered(ystart, font_text,
3545 ystart += ystep_head;
3546 DrawTextSCentered(ystart, font_head,
3547 "for the code base used for the");
3548 ystart += ystep_line;
3549 DrawTextSCentered(ystart, font_head,
3550 "native Emerald Mine engine");
3552 else if (screen_nr == 7)
3554 DrawTextSCentered(ystart, font_head,
3556 ystart += ystep_head;
3557 DrawTextSCentered(ystart, font_text,
3559 ystart += ystep_head;
3560 DrawTextSCentered(ystart, font_head,
3561 "for the initial DOS port");
3562 ystart += ystep_para;
3564 DrawTextSCentered(ystart, font_head,
3566 ystart += ystep_head;
3567 DrawTextSCentered(ystart, font_text,
3569 ystart += ystep_head;
3570 DrawTextSCentered(ystart, font_head,
3571 "for some additional toons");
3573 else if (screen_nr == 8)
3575 DrawTextSCentered(ystart, font_head,
3576 "And not to forget:");
3577 ystart += ystep_head;
3578 DrawTextSCentered(ystart, font_head,
3580 ystart += ystep_head;
3581 DrawTextSCentered(ystart, font_text,
3582 "All those who contributed");
3583 ystart += ystep_line;
3584 DrawTextSCentered(ystart, font_text,
3585 "levels to this game");
3586 ystart += ystep_line;
3587 DrawTextSCentered(ystart, font_text,
3591 DrawTextSCentered(ybottom, font_foot,
3592 "Press any key or button for next page");
3595 static void DrawInfoScreen_Credits(void)
3597 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3599 FadeMenuSoundsAndMusic();
3601 FadeOut(REDRAW_FIELD);
3603 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3605 FadeIn(REDRAW_FIELD);
3608 void HandleInfoScreen_Credits(int button)
3610 static int screen_nr = 0;
3611 int num_screens = 9;
3613 if (button == MB_MENU_INITIALIZE)
3617 // DrawInfoScreen_CreditsScreen(screen_nr);
3620 if (button == MB_MENU_LEAVE)
3622 PlaySound(SND_MENU_ITEM_SELECTING);
3624 info_mode = INFO_MODE_MAIN;
3629 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3631 if (button != MB_MENU_INITIALIZE)
3633 PlaySound(SND_MENU_ITEM_SELECTING);
3638 if (screen_nr >= num_screens)
3640 FadeMenuSoundsAndMusic();
3642 info_mode = INFO_MODE_MAIN;
3649 FadeSetNextScreen();
3651 if (button != MB_MENU_INITIALIZE)
3652 FadeOut(REDRAW_FIELD);
3654 DrawInfoScreen_CreditsScreen(screen_nr);
3656 if (button != MB_MENU_INITIALIZE)
3657 FadeIn(REDRAW_FIELD);
3661 PlayMenuSoundIfLoop();
3665 static void DrawInfoScreen_Program(void)
3667 int font_title = MENU_INFO_FONT_TITLE;
3668 int font_head = MENU_INFO_FONT_HEAD;
3669 int font_text = MENU_INFO_FONT_TEXT;
3670 int font_foot = MENU_INFO_FONT_FOOT;
3671 int spacing_title = menu.headline1_spacing_info[info_mode];
3672 int spacing_head = menu.headline2_spacing_info[info_mode];
3673 int spacing_para = menu.paragraph_spacing_info[info_mode];
3674 int spacing_line = menu.line_spacing_info[info_mode];
3675 int ystep_title = getMenuTextStep(spacing_title, font_title);
3676 int ystep_head = getMenuTextStep(spacing_head, font_head);
3677 int ystep_para = getMenuTextStep(spacing_para, font_text);
3678 int ystep_line = getMenuTextStep(spacing_line, font_text);
3679 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3680 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3682 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3684 FadeOut(REDRAW_FIELD);
3689 DrawTextSCentered(ystart, font_title, "Program Information:");
3690 ystart += ystep_title;
3692 DrawTextSCentered(ystart, font_head,
3693 "This game is Freeware!");
3694 ystart += ystep_head;
3695 DrawTextSCentered(ystart, font_head,
3696 "If you like it, send e-mail to:");
3697 ystart += ystep_head;
3698 DrawTextSCentered(ystart, font_text,
3699 setup.internal.program_email);
3700 ystart += ystep_para;
3702 DrawTextSCentered(ystart, font_head,
3703 "More information and levels:");
3704 ystart += ystep_head;
3705 DrawTextSCentered(ystart, font_text,
3706 setup.internal.program_website);
3707 ystart += ystep_para;
3709 DrawTextSCentered(ystart, font_head,
3710 "If you have created new levels,");
3711 ystart += ystep_line;
3712 DrawTextSCentered(ystart, font_head,
3713 "send them to me to include them!");
3714 ystart += ystep_head;
3715 DrawTextSCentered(ystart, font_head,
3718 DrawTextSCentered(ybottom, font_foot,
3719 "Press any key or button for info menu");
3721 FadeIn(REDRAW_FIELD);
3724 void HandleInfoScreen_Program(int button)
3726 if (button == MB_MENU_LEAVE)
3728 PlaySound(SND_MENU_ITEM_SELECTING);
3730 info_mode = INFO_MODE_MAIN;
3735 else if (button == MB_MENU_CHOICE)
3737 PlaySound(SND_MENU_ITEM_SELECTING);
3739 FadeMenuSoundsAndMusic();
3741 info_mode = INFO_MODE_MAIN;
3746 PlayMenuSoundIfLoop();
3750 static void DrawInfoScreen_Version(void)
3752 int font_title = MENU_INFO_FONT_TITLE;
3753 int font_head = MENU_INFO_FONT_HEAD;
3754 int font_text = MENU_INFO_FONT_TEXT;
3755 int font_foot = MENU_INFO_FONT_FOOT;
3756 int spacing_title = menu.headline1_spacing_info[info_mode];
3757 int spacing_head = menu.headline2_spacing_info[info_mode];
3758 int spacing_para = menu.paragraph_spacing_info[info_mode];
3759 int spacing_line = menu.line_spacing_info[info_mode];
3760 int xstep = getFontWidth(font_text);
3761 int ystep_title = getMenuTextStep(spacing_title, font_title);
3762 int ystep_head = getMenuTextStep(spacing_head, font_head);
3763 int ystep_para = getMenuTextStep(spacing_para, font_text);
3764 int ystep_line = getMenuTextStep(spacing_line, font_text);
3765 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3766 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3767 int xstart1 = mSX - SX + 2 * xstep;
3768 int xstart2 = mSX - SX + 18 * xstep;
3769 int xstart3 = mSX - SX + 28 * xstep;
3770 SDL_version sdl_version_compiled;
3771 const SDL_version *sdl_version_linked;
3772 int driver_name_len = 10;
3773 SDL_version sdl_version_linked_ext;
3774 const char *driver_name = NULL;
3776 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3778 FadeOut(REDRAW_FIELD);
3783 DrawTextSCentered(ystart, font_title, "Version Information:");
3784 ystart += ystep_title;
3786 DrawTextF(xstart1, ystart, font_head, "Name");
3787 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3788 ystart += ystep_line;
3790 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3792 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3793 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3794 ystart += ystep_line;
3796 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3797 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3798 ystart += ystep_line;
3802 DrawTextF(xstart1, ystart, font_head, "Version");
3803 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3804 ystart += ystep_line;
3807 DrawTextF(xstart1, ystart, font_head, "Platform");
3808 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3810 PLATFORM_XX_BIT_STRING);
3811 ystart += ystep_line;
3813 DrawTextF(xstart1, ystart, font_head, "Target");
3814 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3815 ystart += ystep_line;
3817 DrawTextF(xstart1, ystart, font_head, "Source date");
3818 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3819 ystart += ystep_line;
3821 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3822 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3823 ystart += ystep_para;
3825 DrawTextF(xstart1, ystart, font_head, "Library");
3826 DrawTextF(xstart2, ystart, font_head, "compiled");
3827 DrawTextF(xstart3, ystart, font_head, "linked");
3828 ystart += ystep_head;
3830 SDL_VERSION(&sdl_version_compiled);
3831 SDL_GetVersion(&sdl_version_linked_ext);
3832 sdl_version_linked = &sdl_version_linked_ext;
3834 DrawTextF(xstart1, ystart, font_text, "SDL");
3835 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3836 sdl_version_compiled.major,
3837 sdl_version_compiled.minor,
3838 sdl_version_compiled.patch);
3839 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3840 sdl_version_linked->major,
3841 sdl_version_linked->minor,
3842 sdl_version_linked->patch);
3843 ystart += ystep_line;
3845 SDL_IMAGE_VERSION(&sdl_version_compiled);
3846 sdl_version_linked = IMG_Linked_Version();
3848 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3849 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3850 sdl_version_compiled.major,
3851 sdl_version_compiled.minor,
3852 sdl_version_compiled.patch);
3853 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3854 sdl_version_linked->major,
3855 sdl_version_linked->minor,
3856 sdl_version_linked->patch);
3857 ystart += ystep_line;
3859 SDL_MIXER_VERSION(&sdl_version_compiled);
3860 sdl_version_linked = Mix_Linked_Version();
3862 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3863 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3864 sdl_version_compiled.major,
3865 sdl_version_compiled.minor,
3866 sdl_version_compiled.patch);
3867 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3868 sdl_version_linked->major,
3869 sdl_version_linked->minor,
3870 sdl_version_linked->patch);
3871 ystart += ystep_line;
3873 SDL_NET_VERSION(&sdl_version_compiled);
3874 sdl_version_linked = SDLNet_Linked_Version();
3876 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3877 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3878 sdl_version_compiled.major,
3879 sdl_version_compiled.minor,
3880 sdl_version_compiled.patch);
3881 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3882 sdl_version_linked->major,
3883 sdl_version_linked->minor,
3884 sdl_version_linked->patch);
3885 ystart += ystep_para;
3887 DrawTextF(xstart1, ystart, font_head, "Driver");
3888 DrawTextF(xstart2, ystart, font_head, "Requested");
3889 DrawTextF(xstart3, ystart, font_head, "Used");
3890 ystart += ystep_head;
3893 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3895 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3896 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3897 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3898 ystart += ystep_line;
3901 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3903 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3904 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3905 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3906 ystart += ystep_line;
3909 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3911 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3912 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3913 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3915 DrawTextSCentered(ybottom, font_foot,
3916 "Press any key or button for info menu");
3918 FadeIn(REDRAW_FIELD);
3921 void HandleInfoScreen_Version(int button)
3923 if (button == MB_MENU_LEAVE)
3925 PlaySound(SND_MENU_ITEM_SELECTING);
3927 info_mode = INFO_MODE_MAIN;
3932 else if (button == MB_MENU_CHOICE)
3934 PlaySound(SND_MENU_ITEM_SELECTING);
3936 FadeMenuSoundsAndMusic();
3938 info_mode = INFO_MODE_MAIN;
3943 PlayMenuSoundIfLoop();
3947 static void DrawInfoScreen_LevelSet(void)
3949 struct TitleMessageInfo *tmi = &readme;
3950 char *filename = getLevelSetInfoFilename();
3951 char *title = "Level Set Information:";
3952 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3953 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3955 if (filename == NULL)
3957 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3962 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3964 FadeOut(REDRAW_FIELD);
3969 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3971 // if x position set to "-1", automatically determine by playfield width
3973 tmi->x = SXSIZE / 2;
3975 // if y position set to "-1", use static default value
3979 // if width set to "-1", automatically determine by playfield width
3980 if (tmi->width == -1)
3981 tmi->width = SXSIZE - 2 * TILEX;
3983 // if height set to "-1", automatically determine by playfield height
3984 if (tmi->height == -1)
3985 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3987 // if chars set to "-1", automatically determine by text and font width
3988 if (tmi->chars == -1)
3989 tmi->chars = tmi->width / getFontWidth(tmi->font);
3991 tmi->width = tmi->chars * getFontWidth(tmi->font);
3993 // if lines set to "-1", automatically determine by text and font height
3994 if (tmi->lines == -1)
3995 tmi->lines = tmi->height / getFontHeight(tmi->font);
3997 tmi->height = tmi->lines * getFontHeight(tmi->font);
3999 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
4000 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
4001 tmi->autowrap, tmi->centered, tmi->parse_comments);
4003 DrawTextSCentered(ybottom, FONT_TEXT_4,
4004 "Press any key or button for info menu");
4006 FadeIn(REDRAW_FIELD);
4009 static void HandleInfoScreen_LevelSet(int button)
4011 if (button == MB_MENU_LEAVE)
4013 PlaySound(SND_MENU_ITEM_SELECTING);
4015 info_mode = INFO_MODE_MAIN;
4020 else if (button == MB_MENU_CHOICE)
4022 PlaySound(SND_MENU_ITEM_SELECTING);
4024 FadeMenuSoundsAndMusic();
4026 info_mode = INFO_MODE_MAIN;
4031 PlayMenuSoundIfLoop();
4035 static void DrawInfoScreen(void)
4037 if (info_mode == INFO_MODE_TITLE)
4038 DrawInfoScreen_TitleScreen();
4039 else if (info_mode == INFO_MODE_ELEMENTS)
4040 DrawInfoScreen_Elements();
4041 else if (info_mode == INFO_MODE_MUSIC)
4042 DrawInfoScreen_Music();
4043 else if (info_mode == INFO_MODE_CREDITS)
4044 DrawInfoScreen_Credits();
4045 else if (info_mode == INFO_MODE_PROGRAM)
4046 DrawInfoScreen_Program();
4047 else if (info_mode == INFO_MODE_VERSION)
4048 DrawInfoScreen_Version();
4049 else if (info_mode == INFO_MODE_LEVELSET)
4050 DrawInfoScreen_LevelSet();
4052 DrawInfoScreen_Main();
4054 if (info_mode != INFO_MODE_MAIN &&
4055 info_mode != INFO_MODE_TITLE &&
4056 info_mode != INFO_MODE_MUSIC)
4057 PlayMenuSoundsAndMusic();
4060 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4062 if (info_mode == INFO_MODE_TITLE)
4063 HandleInfoScreen_TitleScreen(button);
4064 else if (info_mode == INFO_MODE_ELEMENTS)
4065 HandleInfoScreen_Elements(button);
4066 else if (info_mode == INFO_MODE_MUSIC)
4067 HandleInfoScreen_Music(button);
4068 else if (info_mode == INFO_MODE_CREDITS)
4069 HandleInfoScreen_Credits(button);
4070 else if (info_mode == INFO_MODE_PROGRAM)
4071 HandleInfoScreen_Program(button);
4072 else if (info_mode == INFO_MODE_VERSION)
4073 HandleInfoScreen_Version(button);
4074 else if (info_mode == INFO_MODE_LEVELSET)
4075 HandleInfoScreen_LevelSet(button);
4077 HandleInfoScreen_Main(mx, my, dx, dy, button);
4081 // ============================================================================
4082 // rename player API functions
4083 // ============================================================================
4085 struct ApiRenamePlayerThreadData
4091 static void *CreateThreadData_ApiRenamePlayer(void)
4093 struct ApiRenamePlayerThreadData *data =
4094 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4096 data->player_name = getStringCopy(setup.player_name);
4097 data->player_uuid = getStringCopy(setup.player_uuid);
4102 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4104 struct ApiRenamePlayerThreadData *data = data_raw;
4106 checked_free(data->player_name);
4107 checked_free(data->player_uuid);
4111 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4114 struct ApiRenamePlayerThreadData *data = data_raw;
4115 char *player_name_raw = data->player_name;
4116 char *player_uuid_raw = data->player_uuid;
4118 request->hostname = setup.api_server_hostname;
4119 request->port = API_SERVER_PORT;
4120 request->method = API_SERVER_METHOD;
4121 request->uri = API_SERVER_URI_RENAME;
4123 char *player_name = getEscapedJSON(player_name_raw);
4124 char *player_uuid = getEscapedJSON(player_uuid_raw);
4126 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4129 " \"game_version\": \"%s\",\n"
4130 " \"game_platform\": \"%s\",\n"
4131 " \"name\": \"%s\",\n"
4132 " \"uuid\": \"%s\"\n"
4134 getPasswordJSON(setup.api_server_password),
4135 getProgramRealVersionString(),
4136 getProgramPlatformString(),
4140 checked_free(player_name);
4141 checked_free(player_uuid);
4143 ConvertHttpRequestBodyToServerEncoding(request);
4148 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4151 // nothing to do here
4154 #if defined(PLATFORM_EMSCRIPTEN)
4155 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4156 void *buffer, unsigned int size)
4158 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4160 if (response != NULL)
4162 HandleResponse_ApiRenamePlayer(response, data_raw);
4164 checked_free(response);
4168 Error("server response too large to handle (%d bytes)", size);
4171 FreeThreadData_ApiRenamePlayer(data_raw);
4174 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4175 int code, const char *status)
4177 Error("server failed to handle request: %d %s", code, status);
4179 FreeThreadData_ApiRenamePlayer(data_raw);
4182 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4183 int bytes, int size)
4185 // nothing to do here
4188 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4191 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4193 FreeThreadData_ApiRenamePlayer(data_raw);
4198 emscripten_async_wget2_data(request->uri,
4203 Emscripten_ApiRenamePlayer_Loaded,
4204 Emscripten_ApiRenamePlayer_Failed,
4205 Emscripten_ApiRenamePlayer_Progress);
4210 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4211 struct HttpResponse *response,
4214 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4217 if (!DoHttpRequest(request, response))
4219 Error("HTTP request failed: %s", GetHttpError());
4224 if (!HTTP_SUCCESS(response->status_code))
4226 Error("server failed to handle request: %d %s",
4227 response->status_code,
4228 response->status_text);
4233 HandleResponse_ApiRenamePlayer(response, data_raw);
4236 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4237 struct HttpResponse *response,
4240 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4242 FreeThreadData_ApiRenamePlayer(data_raw);
4246 static int ApiRenamePlayerThread(void *data_raw)
4248 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4249 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4251 program.api_thread_count++;
4253 #if defined(PLATFORM_EMSCRIPTEN)
4254 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4256 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4259 program.api_thread_count--;
4261 checked_free(request);
4262 checked_free(response);
4267 static void ApiRenamePlayerAsThread(void)
4269 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4271 ExecuteAsThread(ApiRenamePlayerThread,
4272 "ApiRenamePlayer", data,
4273 "rename player on server");
4277 // ============================================================================
4278 // reset player UUID API functions
4279 // ============================================================================
4281 struct ApiResetUUIDThreadData
4284 char *player_uuid_old;
4285 char *player_uuid_new;
4288 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4290 struct ApiResetUUIDThreadData *data =
4291 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4293 data->player_name = getStringCopy(setup.player_name);
4294 data->player_uuid_old = getStringCopy(setup.player_uuid);
4295 data->player_uuid_new = getStringCopy(uuid_new);
4300 static void FreeThreadData_ApiResetUUID(void *data_raw)
4302 struct ApiResetUUIDThreadData *data = data_raw;
4304 checked_free(data->player_name);
4305 checked_free(data->player_uuid_old);
4306 checked_free(data->player_uuid_new);
4310 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4313 struct ApiResetUUIDThreadData *data = data_raw;
4314 char *player_name_raw = data->player_name;
4315 char *player_uuid_old_raw = data->player_uuid_old;
4316 char *player_uuid_new_raw = data->player_uuid_new;
4318 request->hostname = setup.api_server_hostname;
4319 request->port = API_SERVER_PORT;
4320 request->method = API_SERVER_METHOD;
4321 request->uri = API_SERVER_URI_RESETUUID;
4323 char *player_name = getEscapedJSON(player_name_raw);
4324 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4325 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4327 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4330 " \"game_version\": \"%s\",\n"
4331 " \"game_platform\": \"%s\",\n"
4332 " \"name\": \"%s\",\n"
4333 " \"uuid_old\": \"%s\",\n"
4334 " \"uuid_new\": \"%s\"\n"
4336 getPasswordJSON(setup.api_server_password),
4337 getProgramRealVersionString(),
4338 getProgramPlatformString(),
4343 checked_free(player_name);
4344 checked_free(player_uuid_old);
4345 checked_free(player_uuid_new);
4347 ConvertHttpRequestBodyToServerEncoding(request);
4352 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4355 struct ApiResetUUIDThreadData *data = data_raw;
4357 // upgrade player UUID in server setup file
4358 setup.player_uuid = getStringCopy(data->player_uuid_new);
4359 setup.player_version = 2;
4361 SaveSetup_ServerSetup();
4364 #if defined(PLATFORM_EMSCRIPTEN)
4365 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4366 void *buffer, unsigned int size)
4368 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4370 if (response != NULL)
4372 HandleResponse_ApiResetUUID(response, data_raw);
4374 checked_free(response);
4378 Error("server response too large to handle (%d bytes)", size);
4381 FreeThreadData_ApiResetUUID(data_raw);
4384 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4385 int code, const char *status)
4387 Error("server failed to handle request: %d %s", code, status);
4389 FreeThreadData_ApiResetUUID(data_raw);
4392 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4393 int bytes, int size)
4395 // nothing to do here
4398 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4401 if (!SetRequest_ApiResetUUID(request, data_raw))
4403 FreeThreadData_ApiResetUUID(data_raw);
4408 emscripten_async_wget2_data(request->uri,
4413 Emscripten_ApiResetUUID_Loaded,
4414 Emscripten_ApiResetUUID_Failed,
4415 Emscripten_ApiResetUUID_Progress);
4420 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4421 struct HttpResponse *response,
4424 if (!SetRequest_ApiResetUUID(request, data_raw))
4427 if (!DoHttpRequest(request, response))
4429 Error("HTTP request failed: %s", GetHttpError());
4434 if (!HTTP_SUCCESS(response->status_code))
4436 Error("server failed to handle request: %d %s",
4437 response->status_code,
4438 response->status_text);
4443 HandleResponse_ApiResetUUID(response, data_raw);
4446 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4447 struct HttpResponse *response,
4450 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4452 FreeThreadData_ApiResetUUID(data_raw);
4456 static int ApiResetUUIDThread(void *data_raw)
4458 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4459 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4461 program.api_thread_count++;
4463 #if defined(PLATFORM_EMSCRIPTEN)
4464 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4466 ApiResetUUID_HttpRequest(request, response, data_raw);
4469 program.api_thread_count--;
4471 checked_free(request);
4472 checked_free(response);
4477 static void ApiResetUUIDAsThread(char *uuid_new)
4479 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4481 ExecuteAsThread(ApiResetUUIDThread,
4482 "ApiResetUUID", data,
4483 "reset UUID on server");
4487 // ============================================================================
4488 // type name functions
4489 // ============================================================================
4491 static TreeInfo *type_name_node = NULL;
4492 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4493 static int type_name_nr = 0;
4495 static int getPlayerNameColor(char *name)
4497 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4500 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4503 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4504 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4505 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4506 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4507 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4508 int font_width = getFontWidth(font_nr);
4510 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4512 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4514 pos->width = strlen(text) * font_width;
4515 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4517 DrawText(sx, sy, text, font_nr);
4520 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4522 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4524 *pos = *mci->pos_input;
4526 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4528 TreeInfo *ti = player_name_current;
4529 int first_entry = ti->cl_first;
4530 int entry_pos = first_entry + ti->cl_cursor;
4531 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4532 int xpos = MENU_SCREEN_START_XPOS;
4533 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4535 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4536 type_name_nr = entry_pos;
4538 strcpy(name, type_name_node->name);
4542 pos->width = MAX_PLAYER_NAME_LEN * 32;
4546 type_name_nr = user.nr;
4548 strcpy(name, setup.player_name);
4551 strcpy(type_name_last, name);
4553 if (strEqual(name, EMPTY_PLAYER_NAME))
4556 *xpos = strlen(name);
4559 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4561 // change name of edited user in global list of user names
4562 setString(&global.user_names[type_name_nr], name);
4564 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4566 TreeInfo *node = type_name_node;
4568 // change name of edited user in local menu tree structure
4569 setString(&node->name, name);
4570 setString(&node->name_sorting, name);
4572 node->color = getPlayerNameColor(name);
4573 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4577 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4580 boolean reset_setup = strEqual(name, "");
4581 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4582 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4585 strcpy(name, type_name_last);
4587 if (strEqual(name, ""))
4588 strcpy(name, EMPTY_PLAYER_NAME);
4590 setTypeNameValues_Name(name, pos);
4592 // if player name not changed, no further action required
4593 if (strEqual(name, type_name_last))
4596 // redraw player name before (possibly) opening request dialogs
4597 drawTypeNameText(name, pos, FALSE);
4599 int last_user_nr = user.nr;
4601 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4603 // save setup of currently active user (may differ from edited user)
4606 // temporarily change active user to edited user
4607 user.nr = type_name_nr;
4610 Request("Use current setup values for the new player?", REQ_ASK))
4612 // use current setup values for new user, but create new player UUID
4613 setup.player_uuid = getStringCopy(getUUID());
4617 // load setup for existing user (or start with defaults for new user)
4622 char *setup_filename = getSetupFilename();
4623 boolean setup_exists = fileExists(setup_filename);
4625 // change name of edited user in setup structure
4626 strcpy(setup.player_name, name);
4628 // save setup of edited user
4631 // change name of edited user on score server
4632 ApiRenamePlayerAsThread();
4634 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4638 if (Request("Reset setup values for this player?", REQ_ASK))
4640 // remove setup config file
4641 unlink(setup_filename);
4643 // set player name to default player name
4646 // update player name used by name typing functions
4647 strcpy(name, setup.player_name);
4649 setTypeNameValues_Name(name, pos);
4652 else if (remove_user && type_name_nr != 0)
4654 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4656 char *user_dir = getUserGameDataDir();
4657 char *user_dir_removed =
4658 getStringCat3WithSeparator(user_dir, "REMOVED",
4659 getCurrentTimestamp(), ".");
4661 if (rename(user_dir, user_dir_removed) != 0)
4662 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4664 checked_free(user_dir_removed);
4667 else if (create_user && type_name_nr != 0 && !setup_exists)
4669 if (Request("Create empty level set for the new player?", REQ_ASK))
4671 char *levelset_subdir = getNewUserLevelSubdir();
4673 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4675 AddUserLevelSetToLevelInfo(levelset_subdir);
4677 LevelDirTree *leveldir_current_last = leveldir_current;
4679 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4682 // set level number of newly created level set to default value
4683 LoadLevelSetup_SeriesInfo();
4685 // set newly created level set as current level set for new user
4686 SaveLevelSetup_LastSeries();
4687 SaveLevelSetup_SeriesInfo();
4689 leveldir_current = leveldir_current_last;
4693 Request("Creating new level set failed!", REQ_CONFIRM);
4698 // restore currently active user
4699 user.nr = last_user_nr;
4701 // restore setup of currently active user
4704 // restore last level set of currently active user
4705 LoadLevelSetup_LastSeries();
4706 LoadLevelSetup_SeriesInfo();
4710 static void HandleTypeNameExt(boolean initialize, Key key)
4712 static struct TextPosInfo pos_name = { 0 };
4713 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4714 static int xpos = 0;
4715 struct TextPosInfo *pos = &pos_name;
4716 char key_char = getValidConfigValueChar(getCharFromKey(key));
4717 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4718 boolean active = TRUE;
4722 getTypeNameValues(name, pos, &xpos);
4724 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4725 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4727 StartTextInput(sx, sy, pos->width, pos->height);
4729 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4731 name[xpos] = key_char;
4736 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4742 else if (key == KSYM_Return || key == KSYM_Escape)
4744 boolean changed = (key == KSYM_Return);
4748 setTypeNameValues(name, pos, changed);
4753 drawTypeNameText(name, pos, active);
4757 SetGameStatus(game_status_last_screen);
4759 if (game_status == GAME_MODE_MAIN)
4760 InitializeMainControls();
4764 static void DrawTypeName(void)
4766 HandleTypeNameExt(TRUE, 0);
4769 void HandleTypeName(Key key)
4771 HandleTypeNameExt(FALSE, key);
4775 // ============================================================================
4776 // tree menu functions
4777 // ============================================================================
4779 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4781 if (game_status != GAME_MODE_SETUP ||
4782 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4785 int max_text_size = 0;
4788 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4789 max_text_size = MAX(max_text_size, strlen(node->name));
4791 int num_entries = numTreeInfoInGroup(ti);
4792 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4793 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4794 int text_width = max_text_size * getFontWidth(font_nr);
4795 int button_width = SC_MENUBUTTON_XSIZE;
4796 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4797 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4798 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4799 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4800 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4801 int align_xoffset = MAX(0, align_xoffset_raw);
4803 return align_xoffset;
4806 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4808 if (game_status != GAME_MODE_SETUP ||
4809 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4812 int num_entries = numTreeInfoInGroup(ti);
4813 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4814 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4815 int font_height = getFontHeight(font_nr);
4816 int text_height = font_height * num_page_entries;
4817 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4818 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4819 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4820 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4821 int align_yoffset = MAX(0, align_yoffset_raw);
4823 return align_yoffset;
4826 static void DrawChooseTree(TreeInfo **ti_ptr)
4828 int fade_mask = REDRAW_FIELD;
4831 fade_mask = REDRAW_ALL;
4833 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4835 if (game_status == GAME_MODE_SETUP)
4839 else // GAME_MODE_LEVELS
4841 SetGameStatus(GAME_MODE_MAIN);
4851 FreeScreenGadgets();
4852 CreateScreenGadgets();
4854 if (game_status != game_status_last_screen)
4855 FadeMenuSoundsAndMusic();
4859 // needed if different viewport properties defined for this screen
4860 ChangeViewportPropertiesIfNeeded();
4862 if (game_status == GAME_MODE_NAMES)
4863 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4864 else if (game_status == GAME_MODE_LEVELNR)
4865 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4866 else if (game_status == GAME_MODE_LEVELS)
4867 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4868 else if (game_status == GAME_MODE_SCORES)
4869 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4873 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4875 // map gadgets for high score screen
4876 if (game_status == GAME_MODE_SCORES)
4877 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4879 MapScreenTreeGadgets(*ti_ptr);
4881 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4883 DrawMaskedBorder(fade_mask);
4885 if (game_status != game_status_last_screen)
4886 PlayMenuSoundsAndMusic();
4891 static int getChooseTreeFont(TreeInfo *node, boolean active)
4893 if (game_status == GAME_MODE_SCORES)
4894 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4896 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4899 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4901 int num_entries = numTreeInfoInGroup(ti);
4902 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4903 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4904 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4905 int first_entry = ti->cl_first;
4906 int entry_pos = first_entry + y;
4907 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4908 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4909 int font_nr = getChooseTreeFont(node, active);
4910 int font_xoffset = getFontDrawOffsetX(font_nr);
4911 int xpos = MENU_SCREEN_START_XPOS;
4912 int ypos = MENU_SCREEN_START_YPOS + y;
4913 int startdx = xpos * 32;
4914 int startdy = ypos * 32;
4915 int startx = amSX + startdx;
4916 int starty = amSY + startdy;
4917 int startx_text = startx + font_xoffset;
4918 int endx_text = amSX + screen_width;
4919 int max_text_size = endx_text - startx_text;
4920 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4921 char buffer[max_buffer_len + 1];
4923 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4925 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4926 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4927 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4928 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4929 int font_size_1 = getFontWidth(font_nr1);
4930 int font_size_3 = getFontWidth(font_nr3);
4931 int font_size_4 = getFontWidth(font_nr4);
4932 int text_size_1 = 3 * font_size_1;
4933 int text_size_4 = 5 * font_size_4;
4934 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4936 int dx2 = text_size_1;
4937 int dx3 = dx2 + font_size_1;
4938 int dx4 = screen_width - startdx - 2 * border - text_size_4;
4939 int num_dots = (dx4 - dx3) / font_size_3;
4940 int startx1 = startx + dx1;
4941 int startx2 = startx + dx2;
4942 int startx3 = startx + dx3;
4943 int startx4 = startx + dx4;
4944 int pos = node->pos;
4945 boolean forced = (scores.force_last_added && pos == scores.last_added);
4946 char *pos_text = (forced ? "???" : int2str(pos + 1, 3));
4947 char *dot_text = ".";
4950 DrawText(startx1, starty, pos_text, font_nr1);
4951 DrawText(startx2, starty, dot_text, font_nr1);
4953 for (i = 0; i < num_dots; i++)
4954 DrawText(startx3 + i * font_size_3, starty, dot_text, font_nr3);
4956 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4957 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4959 DrawText(startx4, starty, getHallOfFameScoreText(pos), font_nr4);
4963 strncpy(buffer, node->name, max_buffer_len);
4964 buffer[max_buffer_len] = '\0';
4966 DrawText(startx, starty, buffer, font_nr);
4970 static void drawChooseTreeHeadExt(int type, char *title_string)
4972 int yoffset_sets = MENU_TITLE1_YPOS;
4973 int yoffset_setup = 16;
4974 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4975 type == TREE_TYPE_LEVEL_DIR ||
4976 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4978 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4981 static void drawChooseTreeHead(TreeInfo *ti)
4983 drawChooseTreeHeadExt(ti->type, ti->infotext);
4986 static void drawChooseTreeList(TreeInfo *ti)
4988 int first_entry = ti->cl_first;
4989 int num_entries = numTreeInfoInGroup(ti);
4990 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4993 clearMenuListArea();
4995 for (i = 0; i < num_page_entries; i++)
4997 TreeInfo *node, *node_first;
4998 int entry_pos = first_entry + i;
5000 node_first = getTreeInfoFirstGroupEntry(ti);
5001 node = getTreeInfoFromPos(node_first, entry_pos);
5003 drawChooseTreeText(ti, i, FALSE);
5005 if (node->parent_link)
5006 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5007 else if (node->level_group)
5008 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5010 initCursor(i, IMG_MENU_BUTTON);
5012 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
5013 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5015 if (game_status == GAME_MODE_NAMES)
5016 drawChooseTreeEdit(i, FALSE);
5019 redraw_mask |= REDRAW_FIELD;
5022 static void drawChooseTreeInfo(TreeInfo *ti)
5024 int entry_pos = ti->cl_first + ti->cl_cursor;
5025 int last_redraw_mask = redraw_mask;
5026 int ypos = MENU_TITLE2_YPOS;
5027 int font_nr = FONT_TITLE_2;
5030 if (ti->type == TREE_TYPE_LEVEL_NR)
5031 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
5033 if (ti->type == TREE_TYPE_SCORE_ENTRY)
5034 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
5035 scores.last_level_nr);
5037 if (ti->type != TREE_TYPE_LEVEL_DIR)
5040 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
5041 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
5043 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
5045 if (node->parent_link)
5046 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
5047 node->node_parent->name);
5048 else if (node->level_group)
5049 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
5051 else if (ti->type == TREE_TYPE_LEVEL_DIR)
5052 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
5053 node->levels, (node->levels > 1 ? "levels" : "level"),
5056 // let BackToFront() redraw only what is needed
5057 redraw_mask = last_redraw_mask;
5058 for (x = 0; x < SCR_FIELDX; x++)
5059 MarkTileDirty(x, 1);
5062 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
5064 drawChooseTreeCursor(ti->cl_cursor, active);
5065 drawChooseTreeText(ti, ti->cl_cursor, active);
5068 static void drawChooseTreeScreen(TreeInfo *ti)
5070 drawChooseTreeHead(ti);
5071 drawChooseTreeList(ti);
5072 drawChooseTreeInfo(ti);
5073 drawChooseTreeCursorAndText(ti, TRUE);
5075 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
5077 // scroll bar and buttons may just have been added after reloading scores
5078 if (game_status == GAME_MODE_SCORES)
5079 MapScreenTreeGadgets(ti);
5082 static void drawChooseTreeScreen_Scores_NotAvailable(void)
5084 // dirty workaround to use spacing definitions from info screen
5085 info_mode = INFO_MODE_TITLE;
5087 char *text_info = "HighScores of Level %d";
5088 char *text_title = "Score information:";
5089 char *text_error = "No scores for this level.";
5090 char *text_foot = "Press any key or button for main menu";
5091 int font_info = FONT_TITLE_2;
5092 int font_title = FONT_INITIAL_3;
5093 int font_error = FONT_INITIAL_4;
5094 int font_foot = FONT_INITIAL_2;
5095 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
5096 int ystep_title = getMenuTextStep(spacing_title, font_title);
5097 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
5098 int ystart2 = ystart1 + ystep_title;
5099 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
5100 int ystart0 = MENU_TITLE2_YPOS;
5102 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
5103 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
5105 DrawTextSCentered(ystart1, font_title, text_title);
5106 DrawTextSCentered(ystart2, font_error, text_error);
5108 DrawTextSCentered(ybottom, font_foot, text_foot);
5111 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
5113 // set current tree entry to last added score entry
5114 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(scores.last_added));
5116 // if that fails, set current tree entry to first entry (back link)
5117 if (*ti_ptr == NULL)
5118 *ti_ptr = score_entries->node_group;
5120 int num_entries = numTreeInfoInGroup(*ti_ptr);
5121 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5122 int pos_score = getPosFromTreeInfo(*ti_ptr);
5123 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5124 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5126 (*ti_ptr)->cl_first = pos_first;
5127 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5132 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5135 TreeInfo *ti = *ti_ptr;
5136 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5137 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5138 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5139 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5140 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5142 int y = (ti != NULL ? ti->cl_cursor : 0);
5143 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5144 int num_entries = numTreeInfoInGroup(ti);
5145 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5146 boolean position_set_by_scrollbar = (dx == 999);
5148 if (game_status == GAME_MODE_SCORES)
5150 if (server_scores.updated)
5152 // reload scores, using updated server score cache file
5153 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5155 server_scores.updated = FALSE;
5157 DrawHallOfFame_setScoreEntries();
5159 if (score_entries != NULL)
5161 ti = setHallOfFameActiveEntry(ti_ptr);
5163 if (button != MB_MENU_INITIALIZE)
5164 drawChooseTreeScreen(ti);
5168 if (score_entries == NULL)
5170 if (button == MB_MENU_INITIALIZE)
5172 drawChooseTreeScreen_Scores_NotAvailable();
5174 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5176 PlaySound(SND_MENU_ITEM_SELECTING);
5178 SetGameStatus(GAME_MODE_MAIN);
5187 if (button == MB_MENU_INITIALIZE)
5189 int num_entries = numTreeInfoInGroup(ti);
5190 int entry_pos = getPosFromTreeInfo(ti);
5192 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5193 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5195 if (game_status == GAME_MODE_SCORES)
5197 ti = setHallOfFameActiveEntry(ti_ptr);
5199 else if (ti->cl_first == -1)
5201 // only on initialization
5202 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5203 ti->cl_cursor = entry_pos - ti->cl_first;
5206 else if (ti->cl_cursor >= num_page_entries ||
5207 (num_entries > num_page_entries &&
5208 num_entries - ti->cl_first < num_page_entries))
5210 // only after change of list size (by custom graphic configuration)
5211 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5212 ti->cl_cursor = entry_pos - ti->cl_first;
5215 if (position_set_by_scrollbar)
5218 drawChooseTreeScreen(ti);
5222 else if (button == MB_MENU_LEAVE)
5224 if (game_status != GAME_MODE_SCORES)
5227 PlaySound(SND_MENU_ITEM_SELECTING);
5229 if (ti->node_parent)
5231 *ti_ptr = ti->node_parent;
5232 DrawChooseTree(ti_ptr);
5234 else if (game_status == GAME_MODE_SETUP)
5236 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5237 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5238 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5239 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5241 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5242 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5243 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5244 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5245 execSetupGraphics();
5246 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5247 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5248 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5250 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5251 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5252 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5253 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5254 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5255 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5256 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5257 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5264 if (game_status == GAME_MODE_LEVELNR)
5266 int new_level_nr = atoi(level_number_current->identifier);
5268 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5271 SetGameStatus(GAME_MODE_MAIN);
5279 if (mx || my) // mouse input
5281 x = (mx - amSX) / 32;
5282 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5284 if (game_status == GAME_MODE_NAMES)
5285 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5287 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5289 // move cursor instead of scrolling when already at start/end of list
5290 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5292 else if (dy == +1 * SCROLL_LINE &&
5293 ti->cl_first + num_page_entries == num_entries)
5296 // handle scrolling screen one line or page
5297 if (ti->cl_cursor + dy < 0 ||
5298 ti->cl_cursor + dy > num_page_entries - 1)
5300 boolean redraw = FALSE;
5302 if (ABS(dy) == SCROLL_PAGE)
5303 step = num_page_entries - 1;
5305 if (dy < 0 && ti->cl_first > 0)
5307 // scroll page/line up
5309 ti->cl_first -= step;
5310 if (ti->cl_first < 0)
5315 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5317 // scroll page/line down
5319 ti->cl_first += step;
5320 if (ti->cl_first + num_page_entries > num_entries)
5321 ti->cl_first = MAX(0, num_entries - num_page_entries);
5327 drawChooseTreeScreen(ti);
5332 // handle moving cursor one line
5333 y = ti->cl_cursor + dy;
5336 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5338 HandleHallOfFame_SelectLevel(1, dx);
5344 TreeInfo *node_first, *node_cursor;
5345 int entry_pos = ti->cl_first + y;
5347 node_first = getTreeInfoFirstGroupEntry(ti);
5348 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5350 if (node_cursor->node_group)
5354 PlaySound(SND_MENU_ITEM_SELECTING);
5356 node_cursor->cl_first = ti->cl_first;
5357 node_cursor->cl_cursor = ti->cl_cursor;
5358 *ti_ptr = node_cursor->node_group;
5359 DrawChooseTree(ti_ptr);
5364 else if (dx == -1 && ti->node_parent)
5368 PlaySound(SND_MENU_ITEM_SELECTING);
5370 *ti_ptr = ti->node_parent;
5371 DrawChooseTree(ti_ptr);
5376 if (!anyScrollbarGadgetActive() &&
5377 IN_VIS_MENU(x, y) &&
5378 mx < mx_right_border &&
5379 y >= 0 && y < num_page_entries)
5383 if (game_status == GAME_MODE_NAMES)
5385 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5386 drawChooseTreeEdit(y, TRUE);
5389 if (y != ti->cl_cursor)
5391 PlaySound(SND_MENU_ITEM_ACTIVATING);
5393 drawChooseTreeCursorAndText(ti, FALSE);
5397 drawChooseTreeCursorAndText(ti, TRUE);
5399 drawChooseTreeInfo(ti);
5403 if (game_status == GAME_MODE_SETUP)
5405 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5406 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5407 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5408 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5410 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5411 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5412 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5413 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5414 execSetupGraphics();
5415 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5416 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5417 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5419 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5420 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5421 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5422 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5423 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5424 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5425 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5426 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5435 TreeInfo *node_first, *node_cursor;
5436 int entry_pos = ti->cl_first + y;
5438 PlaySound(SND_MENU_ITEM_SELECTING);
5440 node_first = getTreeInfoFirstGroupEntry(ti);
5441 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5443 if (node_cursor->node_group)
5447 node_cursor->cl_first = ti->cl_first;
5448 node_cursor->cl_cursor = ti->cl_cursor;
5449 *ti_ptr = node_cursor->node_group;
5450 DrawChooseTree(ti_ptr);
5452 else if (node_cursor->parent_link)
5454 if (game_status != GAME_MODE_SCORES)
5457 *ti_ptr = node_cursor->node_parent;
5458 DrawChooseTree(ti_ptr);
5462 if (game_status != GAME_MODE_SCORES)
5465 node_cursor->cl_first = ti->cl_first;
5466 node_cursor->cl_cursor = ti->cl_cursor;
5467 *ti_ptr = node_cursor;
5469 if (ti->type == TREE_TYPE_LEVEL_DIR)
5471 LoadLevelSetup_SeriesInfo();
5473 SaveLevelSetup_LastSeries();
5474 SaveLevelSetup_SeriesInfo();
5478 if (game_status == GAME_MODE_SETUP)
5480 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5481 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5482 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5483 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5485 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5486 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5487 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5488 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5489 execSetupGraphics();
5490 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5491 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5492 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5494 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5495 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5496 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5497 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5498 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5499 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5500 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5501 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5508 if (game_status == GAME_MODE_LEVELNR)
5510 int new_level_nr = atoi(level_number_current->identifier);
5512 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5514 else if (game_status == GAME_MODE_LEVELS)
5516 // store level set if chosen from "last played level set" menu
5517 StoreLastPlayedLevels(leveldir_current);
5519 else if (game_status == GAME_MODE_NAMES)
5521 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5523 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5530 // change active user to selected user
5531 user.nr = entry_pos;
5533 // save number of new active user
5536 // load setup of new active user
5539 // load last level set of new active user
5540 LoadLevelSetup_LastSeries();
5541 LoadLevelSetup_SeriesInfo();
5543 // update list of last played level sets
5544 UpdateLastPlayedLevels_TreeInfo();
5548 ToggleFullscreenIfNeeded();
5549 ChangeWindowScalingIfNeeded();
5551 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5552 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5553 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5555 else if (game_status == GAME_MODE_SCORES)
5557 if (game_status_last_screen == GAME_MODE_PLAYING &&
5558 setup.auto_play_next_level && setup.increment_levels &&
5559 scores.last_level_nr < leveldir_current->last_level &&
5562 StartGameActions(network.enabled, setup.autorecord,
5568 SetGameStatus(GAME_MODE_MAIN);
5576 if (game_status == GAME_MODE_SCORES)
5577 PlayMenuSoundIfLoop();
5580 void DrawChoosePlayerName(void)
5584 if (player_name != NULL)
5586 freeTreeInfo(player_name);
5591 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5593 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5594 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5597 ti->node_top = &player_name;
5598 ti->sort_priority = 10000 + value;
5599 ti->color = getPlayerNameColor(global.user_names[i]);
5601 snprintf(identifier, sizeof(identifier), "%d", value);
5602 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5604 setString(&ti->identifier, identifier);
5605 setString(&ti->name, name);
5606 setString(&ti->name_sorting, name);
5608 pushTreeInfo(&player_name, ti);
5611 // sort player entries by player number
5612 sortTreeInfo(&player_name);
5614 // set current player entry to selected player entry
5615 player_name_current =
5616 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5618 // if that fails, set current player name to first available name
5619 if (player_name_current == NULL)
5620 player_name_current = player_name;
5622 DrawChooseTree(&player_name_current);
5625 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5627 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5630 void DrawChooseLevelSet(void)
5632 DrawChooseTree(&leveldir_current);
5635 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5637 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5640 void DrawChooseLevelNr(void)
5644 if (level_number != NULL)
5646 freeTreeInfo(level_number);
5648 level_number = NULL;
5651 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5653 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5654 char identifier[32], name[64];
5657 // temporarily load level info to get level name
5658 LoadLevelInfoOnly(i);
5660 ti->node_top = &level_number;
5661 ti->sort_priority = 10000 + value;
5662 ti->color = (level.no_level_file ? FC_BLUE :
5663 LevelStats_getSolved(i) ? FC_GREEN :
5664 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5666 snprintf(identifier, sizeof(identifier), "%d", value);
5667 snprintf(name, sizeof(name), "%03d: %s", value,
5668 (level.no_level_file ? "(no file)" : level.name));
5670 setString(&ti->identifier, identifier);
5671 setString(&ti->name, name);
5672 setString(&ti->name_sorting, name);
5674 pushTreeInfo(&level_number, ti);
5677 // sort level number values to start with lowest level number
5678 sortTreeInfo(&level_number);
5680 // set current level number to current level number
5681 level_number_current =
5682 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5684 // if that also fails, set current level number to first available level
5685 if (level_number_current == NULL)
5686 level_number_current = level_number;
5688 DrawChooseTree(&level_number_current);
5691 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5693 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5696 static void DrawHallOfFame_setScoreEntries(void)
5698 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5701 if (score_entries != NULL)
5703 freeTreeInfo(score_entries);
5705 score_entries = NULL;
5708 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5710 // do not add empty score entries
5711 if (scores.entry[i].score == 0 &&
5712 scores.entry[i].time == 0)
5715 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5716 char identifier[32], name[64];
5719 ti->node_top = &score_entries;
5720 ti->sort_priority = 10000 + value;
5721 ti->color = FC_YELLOW;
5724 snprintf(identifier, sizeof(identifier), "%d", value);
5725 snprintf(name, sizeof(name), "%03d.", value + 1);
5727 setString(&ti->identifier, identifier);
5728 setString(&ti->name, name);
5729 setString(&ti->name_sorting, name);
5731 pushTreeInfo(&score_entries, ti);
5734 // sort score entries to start with highest score entry
5735 sortTreeInfo(&score_entries);
5737 // add top tree node to create back link to main menu
5738 score_entries = addTopTreeInfoNode(score_entries);
5740 // set current score entry to last added or highest score entry
5741 score_entry_current =
5742 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5744 // if that fails, set current score entry to first valid score entry
5745 if (score_entry_current == NULL)
5746 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5748 // ("score_entries" and "score_entry_current" may be NULL here)
5751 void DrawHallOfFame(int level_nr)
5753 scores.last_level_nr = level_nr;
5755 // (this is needed when called from GameEnd() after winning a game)
5756 KeyboardAutoRepeatOn();
5758 // (this is needed when called from GameEnd() after winning a game)
5759 SetDrawDeactivationMask(REDRAW_NONE);
5760 SetDrawBackgroundMask(REDRAW_FIELD);
5762 LoadLocalAndServerScore(level_nr, TRUE);
5764 DrawHallOfFame_setScoreEntries();
5766 if (scores.last_added >= 0)
5767 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5769 FadeSetEnterScreen();
5771 DrawChooseTree(&score_entry_current);
5774 static char *getHallOfFameTimeText(int nr)
5776 static char score_text[10];
5777 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5778 int mm = (time_seconds / 60) % 60;
5779 int ss = (time_seconds % 60);
5781 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5786 static char *getHallOfFameScoreText(int nr)
5788 if (!level.rate_time_over_score)
5789 return int2str(scores.entry[nr].score, 5); // show normal score
5790 else if (level.use_step_counter)
5791 return int2str(scores.entry[nr].time, 5); // show number of steps
5793 return getHallOfFameTimeText(nr); // show playing time
5796 static void HandleHallOfFame_SelectLevel(int step, int direction)
5798 int old_level_nr = level_nr;
5799 int new_level_nr = old_level_nr + step * direction;
5801 if (new_level_nr < leveldir_current->first_level)
5802 new_level_nr = leveldir_current->first_level;
5803 if (new_level_nr > leveldir_current->last_level)
5804 new_level_nr = leveldir_current->last_level;
5806 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5807 new_level_nr = leveldir_current->handicap_level;
5809 if (new_level_nr != old_level_nr)
5811 PlaySound(SND_MENU_ITEM_SELECTING);
5813 scores.last_level_nr = level_nr = new_level_nr;
5815 LoadLocalAndServerScore(level_nr, TRUE);
5817 DrawHallOfFame_setScoreEntries();
5819 // force remapping optional gadgets (especially scroll bar)
5820 UnmapScreenTreeGadgets();
5822 // redraw complete high score screen, as sub-title has changed
5825 // redraw level selection buttons (which have just been erased)
5826 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5828 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5830 SaveLevelSetup_SeriesInfo();
5834 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5836 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5840 // ============================================================================
5841 // setup screen functions
5842 // ============================================================================
5844 static struct TokenInfo *setup_info;
5845 static int num_setup_info; // number of setup entries shown on screen
5846 static int max_setup_info; // total number of setup entries in list
5848 static char *window_size_text;
5849 static char *scaling_type_text;
5850 static char *rendering_mode_text;
5851 static char *vsync_mode_text;
5852 static char *scroll_delay_text;
5853 static char *snapshot_mode_text;
5854 static char *game_speed_text;
5855 static char *scores_type_text;
5856 static char *network_server_text;
5857 static char *graphics_set_name;
5858 static char *sounds_set_name;
5859 static char *music_set_name;
5860 static char *volume_simple_text;
5861 static char *volume_loops_text;
5862 static char *volume_music_text;
5863 static char *touch_controls_text;
5864 static char *move_distance_text;
5865 static char *drop_distance_text;
5866 static char *transparency_text;
5867 static char *grid_size_text[2][2];
5869 static void execSetupMain(void)
5871 setup_mode = SETUP_MODE_MAIN;
5876 static void execSetupGame_setScoresType(void)
5878 if (scores_types == NULL)
5882 for (i = 0; scores_types_list[i].value != NULL; i++)
5884 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5885 char identifier[32], name[32];
5886 char *value = scores_types_list[i].value;
5887 char *text = scores_types_list[i].text;
5889 ti->node_top = &scores_types;
5890 ti->sort_priority = i;
5892 sprintf(identifier, "%s", value);
5893 sprintf(name, "%s", text);
5895 setString(&ti->identifier, identifier);
5896 setString(&ti->name, name);
5897 setString(&ti->name_sorting, name);
5898 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5900 pushTreeInfo(&scores_types, ti);
5903 // sort scores type values to start with lowest scores type value
5904 sortTreeInfo(&scores_types);
5906 // set current scores type value to configured scores type value
5907 scores_type_current =
5908 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5910 // if that fails, set current scores type to reliable default value
5911 if (scores_type_current == NULL)
5912 scores_type_current =
5913 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5915 // if that also fails, set current scores type to first available value
5916 if (scores_type_current == NULL)
5917 scores_type_current = scores_types;
5920 setup.scores_in_highscore_list = scores_type_current->identifier;
5922 // needed for displaying scores type text instead of identifier
5923 scores_type_text = scores_type_current->name;
5926 static void execSetupGame_setGameSpeeds(boolean update_value)
5928 if (setup.game_speed_extended)
5930 game_speeds_list = game_speeds_list_extended;
5931 game_speeds = game_speeds_extended;
5935 game_speeds_list = game_speeds_list_normal;
5936 game_speeds = game_speeds_normal;
5939 if (game_speeds == NULL)
5943 for (i = 0; game_speeds_list[i].value != -1; i++)
5945 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5946 char identifier[32], name[32];
5947 int value = game_speeds_list[i].value;
5948 char *text = game_speeds_list[i].text;
5950 ti->node_top = &game_speeds;
5951 ti->sort_priority = 10000 - value;
5953 sprintf(identifier, "%d", value);
5954 sprintf(name, "%s", text);
5956 setString(&ti->identifier, identifier);
5957 setString(&ti->name, name);
5958 setString(&ti->name_sorting, name);
5959 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5961 pushTreeInfo(&game_speeds, ti);
5964 // sort game speed values to start with slowest game speed
5965 sortTreeInfo(&game_speeds);
5967 update_value = TRUE;
5972 // set current game speed to configured game speed value
5973 game_speed_current =
5974 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5976 // if that fails, set current game speed to reliable default value
5977 if (game_speed_current == NULL)
5978 game_speed_current =
5979 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5981 // if that also fails, set current game speed to first available speed
5982 if (game_speed_current == NULL)
5983 game_speed_current = game_speeds;
5985 if (setup.game_speed_extended)
5986 game_speeds_extended = game_speeds;
5988 game_speeds_normal = game_speeds;
5991 setup.game_frame_delay = atoi(game_speed_current->identifier);
5993 // needed for displaying game speed text instead of identifier
5994 game_speed_text = game_speed_current->name;
5997 static void execSetupGame_setScrollDelays(void)
5999 if (scroll_delays == NULL)
6003 for (i = 0; scroll_delays_list[i].value != -1; i++)
6005 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6006 char identifier[32], name[32];
6007 int value = scroll_delays_list[i].value;
6008 char *text = scroll_delays_list[i].text;
6010 ti->node_top = &scroll_delays;
6011 ti->sort_priority = value;
6013 sprintf(identifier, "%d", value);
6014 sprintf(name, "%s", text);
6016 setString(&ti->identifier, identifier);
6017 setString(&ti->name, name);
6018 setString(&ti->name_sorting, name);
6019 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6021 pushTreeInfo(&scroll_delays, ti);
6024 // sort scroll delay values to start with lowest scroll delay value
6025 sortTreeInfo(&scroll_delays);
6027 // set current scroll delay value to configured scroll delay value
6028 scroll_delay_current =
6029 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6031 // if that fails, set current scroll delay to reliable default value
6032 if (scroll_delay_current == NULL)
6033 scroll_delay_current =
6034 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6036 // if that also fails, set current scroll delay to first available value
6037 if (scroll_delay_current == NULL)
6038 scroll_delay_current = scroll_delays;
6041 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6043 // needed for displaying scroll delay text instead of identifier
6044 scroll_delay_text = scroll_delay_current->name;
6047 static void execSetupGame_setSnapshotModes(void)
6049 if (snapshot_modes == NULL)
6053 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6055 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6056 char identifier[32], name[32];
6057 char *value = snapshot_modes_list[i].value;
6058 char *text = snapshot_modes_list[i].text;
6060 ti->node_top = &snapshot_modes;
6061 ti->sort_priority = i;
6063 sprintf(identifier, "%s", value);
6064 sprintf(name, "%s", text);
6066 setString(&ti->identifier, identifier);
6067 setString(&ti->name, name);
6068 setString(&ti->name_sorting, name);
6069 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6071 pushTreeInfo(&snapshot_modes, ti);
6074 // sort snapshot mode values to start with lowest snapshot mode value
6075 sortTreeInfo(&snapshot_modes);
6077 // set current snapshot mode value to configured snapshot mode value
6078 snapshot_mode_current =
6079 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6081 // if that fails, set current snapshot mode to reliable default value
6082 if (snapshot_mode_current == NULL)
6083 snapshot_mode_current =
6084 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6086 // if that also fails, set current snapshot mode to first available value
6087 if (snapshot_mode_current == NULL)
6088 snapshot_mode_current = snapshot_modes;
6091 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6093 // needed for displaying snapshot mode text instead of identifier
6094 snapshot_mode_text = snapshot_mode_current->name;
6097 static void execSetupGame_setNetworkServerText(void)
6099 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6101 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6105 strncpy(network_server_hostname, setup.network_server_hostname,
6106 MAX_SETUP_TEXT_INPUT_LEN);
6107 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6110 // needed for displaying network server text instead of identifier
6111 network_server_text = network_server_hostname;
6114 static void execSetupGame(void)
6116 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6118 execSetupGame_setGameSpeeds(FALSE);
6119 execSetupGame_setScoresType();
6120 execSetupGame_setScrollDelays();
6121 execSetupGame_setSnapshotModes();
6123 execSetupGame_setNetworkServerText();
6125 if (!setup.provide_uploading_tapes)
6126 setHideSetupEntry(execOfferUploadTapes);
6128 setup_mode = SETUP_MODE_GAME;
6132 // check if vsync needs to be disabled for this game speed to work
6133 if (check_vsync_mode)
6134 DisableVsyncIfNeeded();
6137 static void execSetupChooseScoresType(void)
6139 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6144 static void execSetupChooseGameSpeed(void)
6146 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6151 static void execSetupChooseScrollDelay(void)
6153 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6158 static void execSetupChooseSnapshotMode(void)
6160 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6165 static void execSetupEngines(void)
6167 setup_mode = SETUP_MODE_ENGINES;
6172 static void execSetupEditor(void)
6174 setup_mode = SETUP_MODE_EDITOR;
6179 static void execSetupGraphics_setWindowSizes(boolean update_list)
6181 if (window_sizes != NULL && update_list)
6183 freeTreeInfo(window_sizes);
6185 window_sizes = NULL;
6188 if (window_sizes == NULL)
6190 boolean current_window_size_found = FALSE;
6193 for (i = 0; window_sizes_list[i].value != -1; i++)
6195 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6196 char identifier[32], name[32];
6197 int value = window_sizes_list[i].value;
6198 char *text = window_sizes_list[i].text;
6200 ti->node_top = &window_sizes;
6201 ti->sort_priority = value;
6203 sprintf(identifier, "%d", value);
6204 sprintf(name, "%s", text);
6206 setString(&ti->identifier, identifier);
6207 setString(&ti->name, name);
6208 setString(&ti->name_sorting, name);
6209 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6211 pushTreeInfo(&window_sizes, ti);
6213 if (value == setup.window_scaling_percent)
6214 current_window_size_found = TRUE;
6217 if (!current_window_size_found)
6219 // add entry for non-preset window scaling value
6221 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6222 char identifier[32], name[32];
6223 int value = setup.window_scaling_percent;
6225 ti->node_top = &window_sizes;
6226 ti->sort_priority = value;
6228 sprintf(identifier, "%d", value);
6229 sprintf(name, "%d %% (Current)", value);
6231 setString(&ti->identifier, identifier);
6232 setString(&ti->name, name);
6233 setString(&ti->name_sorting, name);
6234 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6236 pushTreeInfo(&window_sizes, ti);
6239 // sort window size values to start with lowest window size value
6240 sortTreeInfo(&window_sizes);
6242 // set current window size value to configured window size value
6243 window_size_current =
6244 getTreeInfoFromIdentifier(window_sizes,
6245 i_to_a(setup.window_scaling_percent));
6247 // if that fails, set current window size to reliable default value
6248 if (window_size_current == NULL)
6249 window_size_current =
6250 getTreeInfoFromIdentifier(window_sizes,
6251 i_to_a(STD_WINDOW_SCALING_PERCENT));
6253 // if that also fails, set current window size to first available value
6254 if (window_size_current == NULL)
6255 window_size_current = window_sizes;
6258 setup.window_scaling_percent = atoi(window_size_current->identifier);
6260 // needed for displaying window size text instead of identifier
6261 window_size_text = window_size_current->name;
6264 static void execSetupGraphics_setScalingTypes(void)
6266 if (scaling_types == NULL)
6270 for (i = 0; scaling_types_list[i].value != NULL; i++)
6272 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6273 char identifier[32], name[32];
6274 char *value = scaling_types_list[i].value;
6275 char *text = scaling_types_list[i].text;
6277 ti->node_top = &scaling_types;
6278 ti->sort_priority = i;
6280 sprintf(identifier, "%s", value);
6281 sprintf(name, "%s", text);
6283 setString(&ti->identifier, identifier);
6284 setString(&ti->name, name);
6285 setString(&ti->name_sorting, name);
6286 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6288 pushTreeInfo(&scaling_types, ti);
6291 // sort scaling type values to start with lowest scaling type value
6292 sortTreeInfo(&scaling_types);
6294 // set current scaling type value to configured scaling type value
6295 scaling_type_current =
6296 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6298 // if that fails, set current scaling type to reliable default value
6299 if (scaling_type_current == NULL)
6300 scaling_type_current =
6301 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6303 // if that also fails, set current scaling type to first available value
6304 if (scaling_type_current == NULL)
6305 scaling_type_current = scaling_types;
6308 setup.window_scaling_quality = scaling_type_current->identifier;
6310 // needed for displaying scaling type text instead of identifier
6311 scaling_type_text = scaling_type_current->name;
6314 static void execSetupGraphics_setRenderingModes(void)
6316 if (rendering_modes == NULL)
6320 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6322 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6323 char identifier[32], name[32];
6324 char *value = rendering_modes_list[i].value;
6325 char *text = rendering_modes_list[i].text;
6327 ti->node_top = &rendering_modes;
6328 ti->sort_priority = i;
6330 sprintf(identifier, "%s", value);
6331 sprintf(name, "%s", text);
6333 setString(&ti->identifier, identifier);
6334 setString(&ti->name, name);
6335 setString(&ti->name_sorting, name);
6336 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6338 pushTreeInfo(&rendering_modes, ti);
6341 // sort rendering mode values to start with lowest rendering mode value
6342 sortTreeInfo(&rendering_modes);
6344 // set current rendering mode value to configured rendering mode value
6345 rendering_mode_current =
6346 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6348 // if that fails, set current rendering mode to reliable default value
6349 if (rendering_mode_current == NULL)
6350 rendering_mode_current =
6351 getTreeInfoFromIdentifier(rendering_modes,
6352 STR_SPECIAL_RENDERING_DEFAULT);
6354 // if that also fails, set current rendering mode to first available one
6355 if (rendering_mode_current == NULL)
6356 rendering_mode_current = rendering_modes;
6359 setup.screen_rendering_mode = rendering_mode_current->identifier;
6361 // needed for displaying rendering mode text instead of identifier
6362 rendering_mode_text = rendering_mode_current->name;
6365 static void execSetupGraphics_setVsyncModes(boolean update_value)
6367 if (vsync_modes == NULL)
6371 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6373 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6374 char identifier[32], name[32];
6375 char *value = vsync_modes_list[i].value;
6376 char *text = vsync_modes_list[i].text;
6378 ti->node_top = &vsync_modes;
6379 ti->sort_priority = i;
6381 sprintf(identifier, "%s", value);
6382 sprintf(name, "%s", text);
6384 setString(&ti->identifier, identifier);
6385 setString(&ti->name, name);
6386 setString(&ti->name_sorting, name);
6387 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6389 pushTreeInfo(&vsync_modes, ti);
6392 // sort vsync mode values to start with lowest vsync mode value
6393 sortTreeInfo(&vsync_modes);
6395 update_value = TRUE;
6400 // set current vsync mode value to configured vsync mode value
6401 vsync_mode_current =
6402 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6404 // if that fails, set current vsync mode to reliable default value
6405 if (vsync_mode_current == NULL)
6406 vsync_mode_current =
6407 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6409 // if that also fails, set current vsync mode to first available one
6410 if (vsync_mode_current == NULL)
6411 vsync_mode_current = vsync_modes;
6414 setup.vsync_mode = vsync_mode_current->identifier;
6416 // needed for displaying vsync mode text instead of identifier
6417 vsync_mode_text = vsync_mode_current->name;
6420 static void execSetupGraphics(void)
6422 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6424 // update "setup.window_scaling_percent" from list selection
6425 // (in this case, window scaling was changed on setup screen)
6426 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6427 execSetupGraphics_setWindowSizes(FALSE);
6429 // update "setup.vsync_mode" from list selection
6430 // (in this case, vsync mode was changed on setup screen)
6431 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6432 execSetupGraphics_setVsyncModes(FALSE);
6434 // update list selection from "setup.window_scaling_percent"
6435 // (window scaling may have changed by resizing the window)
6436 execSetupGraphics_setWindowSizes(TRUE);
6438 // update list selection from "setup.vsync_mode"
6439 // (vsync_mode may have changed by re-creating the renderer)
6440 execSetupGraphics_setVsyncModes(TRUE);
6442 execSetupGraphics_setScalingTypes();
6443 execSetupGraphics_setRenderingModes();
6445 setup_mode = SETUP_MODE_GRAPHICS;
6449 // check if game speed is high enough for 60 Hz vsync to work
6450 if (check_game_speed)
6451 ModifyGameSpeedIfNeeded();
6453 // window scaling may have changed at this point
6454 ChangeWindowScalingIfNeeded();
6456 // window scaling quality may have changed at this point
6457 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6458 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6460 // screen rendering mode may have changed at this point
6461 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6463 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6464 int video_vsync_mode = video.vsync_mode;
6466 // screen vsync mode may have changed at this point
6467 ChangeVsyncModeIfNeeded();
6469 // check if setting vsync mode to selected value failed
6470 if (setup_vsync_mode != video_vsync_mode &&
6471 setup_vsync_mode != video.vsync_mode)
6473 // changing vsync mode to selected value failed -- reset displayed value
6474 execSetupGraphics_setVsyncModes(TRUE);
6476 Request("Setting VSync failed!", REQ_CONFIRM);
6482 static void execSetupChooseWindowSize(void)
6484 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6489 static void execSetupChooseScalingType(void)
6491 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6496 static void execSetupChooseRenderingMode(void)
6498 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6503 static void execSetupChooseVsyncMode(void)
6505 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6510 static void execSetupChooseVolumeSimple(void)
6512 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6517 static void execSetupChooseVolumeLoops(void)
6519 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6524 static void execSetupChooseVolumeMusic(void)
6526 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6531 static void execSetupSound(void)
6533 if (volumes_simple == NULL)
6535 boolean current_volume_simple_found = FALSE;
6538 for (i = 0; volumes_list[i].value != -1; i++)
6540 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6541 char identifier[32], name[32];
6542 int value = volumes_list[i].value;
6543 char *text = volumes_list[i].text;
6545 ti->node_top = &volumes_simple;
6546 ti->sort_priority = value;
6548 sprintf(identifier, "%d", value);
6549 sprintf(name, "%s", text);
6551 setString(&ti->identifier, identifier);
6552 setString(&ti->name, name);
6553 setString(&ti->name_sorting, name);
6554 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6556 pushTreeInfo(&volumes_simple, ti);
6558 if (value == setup.volume_simple)
6559 current_volume_simple_found = TRUE;
6562 if (!current_volume_simple_found)
6564 // add entry for non-preset volume value
6566 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6567 char identifier[32], name[32];
6568 int value = setup.volume_simple;
6570 ti->node_top = &volumes_simple;
6571 ti->sort_priority = value;
6573 sprintf(identifier, "%d", value);
6574 sprintf(name, "%d %% (Current)", value);
6576 setString(&ti->identifier, identifier);
6577 setString(&ti->name, name);
6578 setString(&ti->name_sorting, name);
6579 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6581 pushTreeInfo(&volumes_simple, ti);
6584 // sort volume values to start with lowest volume value
6585 sortTreeInfo(&volumes_simple);
6587 // set current volume value to configured volume value
6588 volume_simple_current =
6589 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6591 // if that fails, set current volume to reliable default value
6592 if (volume_simple_current == NULL)
6593 volume_simple_current =
6594 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6596 // if that also fails, set current volume to first available value
6597 if (volume_simple_current == NULL)
6598 volume_simple_current = volumes_simple;
6601 if (volumes_loops == NULL)
6603 boolean current_volume_loops_found = FALSE;
6606 for (i = 0; volumes_list[i].value != -1; i++)
6608 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6609 char identifier[32], name[32];
6610 int value = volumes_list[i].value;
6611 char *text = volumes_list[i].text;
6613 ti->node_top = &volumes_loops;
6614 ti->sort_priority = value;
6616 sprintf(identifier, "%d", value);
6617 sprintf(name, "%s", text);
6619 setString(&ti->identifier, identifier);
6620 setString(&ti->name, name);
6621 setString(&ti->name_sorting, name);
6622 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6624 pushTreeInfo(&volumes_loops, ti);
6626 if (value == setup.volume_loops)
6627 current_volume_loops_found = TRUE;
6630 if (!current_volume_loops_found)
6632 // add entry for non-preset volume value
6634 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6635 char identifier[32], name[32];
6636 int value = setup.volume_loops;
6638 ti->node_top = &volumes_loops;
6639 ti->sort_priority = value;
6641 sprintf(identifier, "%d", value);
6642 sprintf(name, "%d %% (Current)", value);
6644 setString(&ti->identifier, identifier);
6645 setString(&ti->name, name);
6646 setString(&ti->name_sorting, name);
6647 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6649 pushTreeInfo(&volumes_loops, ti);
6652 // sort volume values to start with lowest volume value
6653 sortTreeInfo(&volumes_loops);
6655 // set current volume value to configured volume value
6656 volume_loops_current =
6657 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6659 // if that fails, set current volume to reliable default value
6660 if (volume_loops_current == NULL)
6661 volume_loops_current =
6662 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6664 // if that also fails, set current volume to first available value
6665 if (volume_loops_current == NULL)
6666 volume_loops_current = volumes_loops;
6669 if (volumes_music == NULL)
6671 boolean current_volume_music_found = FALSE;
6674 for (i = 0; volumes_list[i].value != -1; i++)
6676 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6677 char identifier[32], name[32];
6678 int value = volumes_list[i].value;
6679 char *text = volumes_list[i].text;
6681 ti->node_top = &volumes_music;
6682 ti->sort_priority = value;
6684 sprintf(identifier, "%d", value);
6685 sprintf(name, "%s", text);
6687 setString(&ti->identifier, identifier);
6688 setString(&ti->name, name);
6689 setString(&ti->name_sorting, name);
6690 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6692 pushTreeInfo(&volumes_music, ti);
6694 if (value == setup.volume_music)
6695 current_volume_music_found = TRUE;
6698 if (!current_volume_music_found)
6700 // add entry for non-preset volume value
6702 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6703 char identifier[32], name[32];
6704 int value = setup.volume_music;
6706 ti->node_top = &volumes_music;
6707 ti->sort_priority = value;
6709 sprintf(identifier, "%d", value);
6710 sprintf(name, "%d %% (Current)", value);
6712 setString(&ti->identifier, identifier);
6713 setString(&ti->name, name);
6714 setString(&ti->name_sorting, name);
6715 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6717 pushTreeInfo(&volumes_music, ti);
6720 // sort volume values to start with lowest volume value
6721 sortTreeInfo(&volumes_music);
6723 // set current volume value to configured volume value
6724 volume_music_current =
6725 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6727 // if that fails, set current volume to reliable default value
6728 if (volume_music_current == NULL)
6729 volume_music_current =
6730 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6732 // if that also fails, set current volume to first available value
6733 if (volume_music_current == NULL)
6734 volume_music_current = volumes_music;
6737 setup.volume_simple = atoi(volume_simple_current->identifier);
6738 setup.volume_loops = atoi(volume_loops_current->identifier);
6739 setup.volume_music = atoi(volume_music_current->identifier);
6741 // needed for displaying volume text instead of identifier
6742 volume_simple_text = volume_simple_current->name;
6743 volume_loops_text = volume_loops_current->name;
6744 volume_music_text = volume_music_current->name;
6746 setup_mode = SETUP_MODE_SOUND;
6751 static void execSetupChooseTouchControls(void)
6753 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6758 static void execSetupChooseMoveDistance(void)
6760 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6765 static void execSetupChooseDropDistance(void)
6767 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6772 static void execSetupChooseTransparency(void)
6774 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6779 static void execSetupChooseGridXSize_0(void)
6781 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6786 static void execSetupChooseGridYSize_0(void)
6788 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6793 static void execSetupChooseGridXSize_1(void)
6795 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6800 static void execSetupChooseGridYSize_1(void)
6802 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6807 static void execSetupConfigureVirtualButtons(void)
6809 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6811 ConfigureVirtualButtons();
6813 setup_mode = SETUP_MODE_TOUCH;
6818 static void execSetupTouch(void)
6822 if (touch_controls == NULL)
6824 for (i = 0; touch_controls_list[i].value != NULL; i++)
6826 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6827 char identifier[32], name[32];
6828 char *value = touch_controls_list[i].value;
6829 char *text = touch_controls_list[i].text;
6831 ti->node_top = &touch_controls;
6832 ti->sort_priority = i;
6834 sprintf(identifier, "%s", value);
6835 sprintf(name, "%s", text);
6837 setString(&ti->identifier, identifier);
6838 setString(&ti->name, name);
6839 setString(&ti->name_sorting, name);
6840 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6842 pushTreeInfo(&touch_controls, ti);
6845 // sort touch control values to start with lowest touch control value
6846 sortTreeInfo(&touch_controls);
6848 // set current touch control value to configured touch control value
6849 touch_control_current =
6850 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6852 // if that fails, set current touch control to reliable default value
6853 if (touch_control_current == NULL)
6854 touch_control_current =
6855 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6857 // if that also fails, set current touch control to first available value
6858 if (touch_control_current == NULL)
6859 touch_control_current = touch_controls;
6862 if (move_distances == NULL)
6864 for (i = 0; distances_list[i].value != -1; i++)
6866 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6867 char identifier[32], name[32];
6868 int value = distances_list[i].value;
6869 char *text = distances_list[i].text;
6871 ti->node_top = &move_distances;
6872 ti->sort_priority = value;
6874 sprintf(identifier, "%d", value);
6875 sprintf(name, "%s", text);
6877 setString(&ti->identifier, identifier);
6878 setString(&ti->name, name);
6879 setString(&ti->name_sorting, name);
6880 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6882 pushTreeInfo(&move_distances, ti);
6885 // sort distance values to start with lowest distance value
6886 sortTreeInfo(&move_distances);
6888 // set current distance value to configured distance value
6889 move_distance_current =
6890 getTreeInfoFromIdentifier(move_distances,
6891 i_to_a(setup.touch.move_distance));
6893 // if that fails, set current distance to reliable default value
6894 if (move_distance_current == NULL)
6895 move_distance_current =
6896 getTreeInfoFromIdentifier(move_distances,
6897 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6899 // if that also fails, set current distance to first available value
6900 if (move_distance_current == NULL)
6901 move_distance_current = move_distances;
6904 if (drop_distances == NULL)
6906 for (i = 0; distances_list[i].value != -1; i++)
6908 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6909 char identifier[32], name[32];
6910 int value = distances_list[i].value;
6911 char *text = distances_list[i].text;
6913 ti->node_top = &drop_distances;
6914 ti->sort_priority = value;
6916 sprintf(identifier, "%d", value);
6917 sprintf(name, "%s", text);
6919 setString(&ti->identifier, identifier);
6920 setString(&ti->name, name);
6921 setString(&ti->name_sorting, name);
6922 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6924 pushTreeInfo(&drop_distances, ti);
6927 // sort distance values to start with lowest distance value
6928 sortTreeInfo(&drop_distances);
6930 // set current distance value to configured distance value
6931 drop_distance_current =
6932 getTreeInfoFromIdentifier(drop_distances,
6933 i_to_a(setup.touch.drop_distance));
6935 // if that fails, set current distance to reliable default value
6936 if (drop_distance_current == NULL)
6937 drop_distance_current =
6938 getTreeInfoFromIdentifier(drop_distances,
6939 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6941 // if that also fails, set current distance to first available value
6942 if (drop_distance_current == NULL)
6943 drop_distance_current = drop_distances;
6946 if (transparencies == NULL)
6948 for (i = 0; transparencies_list[i].value != -1; i++)
6950 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6951 char identifier[32], name[32];
6952 int value = transparencies_list[i].value;
6953 char *text = transparencies_list[i].text;
6955 ti->node_top = &transparencies;
6956 ti->sort_priority = value;
6958 sprintf(identifier, "%d", value);
6959 sprintf(name, "%s", text);
6961 setString(&ti->identifier, identifier);
6962 setString(&ti->name, name);
6963 setString(&ti->name_sorting, name);
6964 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6966 pushTreeInfo(&transparencies, ti);
6969 // sort transparency values to start with lowest transparency value
6970 sortTreeInfo(&transparencies);
6972 // set current transparency value to configured transparency value
6973 transparency_current =
6974 getTreeInfoFromIdentifier(transparencies,
6975 i_to_a(setup.touch.transparency));
6977 // if that fails, set current transparency to reliable default value
6978 if (transparency_current == NULL)
6979 transparency_current =
6980 getTreeInfoFromIdentifier(transparencies,
6981 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6983 // if that also fails, set current transparency to first available value
6984 if (transparency_current == NULL)
6985 transparency_current = transparencies;
6988 for (i = 0; i < 2; i++)
6990 for (j = 0; j < 2; j++)
6992 if (grid_sizes[i][j] == NULL)
6994 for (k = 0; grid_sizes_list[k].value != -1; k++)
6996 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6997 char identifier[32], name[32];
6998 int value = grid_sizes_list[k].value;
6999 char *text = grid_sizes_list[k].text;
7001 ti->node_top = &grid_sizes[i][j];
7002 ti->sort_priority = value;
7004 sprintf(identifier, "%d", value);
7005 sprintf(name, "%s", text);
7007 setString(&ti->identifier, identifier);
7008 setString(&ti->name, name);
7009 setString(&ti->name_sorting, name);
7010 setString(&ti->infotext,
7013 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7014 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7016 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7017 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7019 pushTreeInfo(&grid_sizes[i][j], ti);
7022 // sort grid size values to start with lowest grid size value
7023 sortTreeInfo(&grid_sizes[i][j]);
7025 // set current grid size value to configured grid size value
7026 grid_size_current[i][j] =
7027 getTreeInfoFromIdentifier(grid_sizes[i][j],
7029 setup.touch.grid_xsize[i] :
7030 setup.touch.grid_ysize[i]));
7032 // if that fails, set current grid size to reliable default value
7033 if (grid_size_current[i][j] == NULL)
7034 grid_size_current[i][j] =
7035 getTreeInfoFromIdentifier(grid_sizes[i][j],
7037 DEFAULT_GRID_XSIZE(i) :
7038 DEFAULT_GRID_YSIZE(i)));
7040 // if that also fails, set current grid size to first available value
7041 if (grid_size_current[i][j] == NULL)
7042 grid_size_current[i][j] = grid_sizes[i][j];
7047 setup.touch.control_type = touch_control_current->identifier;
7048 setup.touch.move_distance = atoi(move_distance_current->identifier);
7049 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7050 setup.touch.transparency = atoi(transparency_current->identifier);
7052 for (i = 0; i < 2; i++)
7054 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7055 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7057 if (i == GRID_ACTIVE_NR())
7059 overlay.grid_xsize = setup.touch.grid_xsize[i];
7060 overlay.grid_ysize = setup.touch.grid_ysize[i];
7064 // needed for displaying value text instead of identifier
7065 touch_controls_text = touch_control_current->name;
7066 move_distance_text = move_distance_current->name;
7067 drop_distance_text = drop_distance_current->name;
7068 transparency_text = transparency_current->name;
7070 for (i = 0; i < 2; i++)
7071 for (j = 0; j < 2; j++)
7072 grid_size_text[i][j] = grid_size_current[i][j]->name;
7074 setup_mode = SETUP_MODE_TOUCH;
7079 static void execSetupArtwork(void)
7081 static ArtworkDirTree *gfx_last_valid = NULL;
7082 static ArtworkDirTree *snd_last_valid = NULL;
7083 static ArtworkDirTree *mus_last_valid = NULL;
7085 // current artwork directory may be invalid (level group, parent link)
7086 if (!validLevelSeries(artwork.gfx_current))
7087 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7088 if (!validLevelSeries(artwork.snd_current))
7089 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7090 if (!validLevelSeries(artwork.mus_current))
7091 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7093 // store valid artwork directory information
7094 gfx_last_valid = artwork.gfx_current;
7095 snd_last_valid = artwork.snd_current;
7096 mus_last_valid = artwork.mus_current;
7099 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7100 artwork.gfx_current->subdir,
7101 artwork.gfx_current->fullpath,
7102 artwork.gfx_current->basepath);
7105 setup.graphics_set = artwork.gfx_current->identifier;
7106 setup.sounds_set = artwork.snd_current->identifier;
7107 setup.music_set = artwork.mus_current->identifier;
7109 // needed if last screen (setup choice) changed graphics, sounds or music
7110 ReloadCustomArtwork(0);
7112 // needed for displaying artwork name instead of artwork identifier
7113 graphics_set_name = artwork.gfx_current->name;
7114 sounds_set_name = artwork.snd_current->name;
7115 music_set_name = artwork.mus_current->name;
7117 setup_mode = SETUP_MODE_ARTWORK;
7122 static void execSetupChooseGraphics(void)
7124 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7129 static void execSetupChooseSounds(void)
7131 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7136 static void execSetupChooseMusic(void)
7138 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7143 static void execSetupInput(void)
7145 setup_mode = SETUP_MODE_INPUT;
7150 static void execSetupShortcuts(void)
7152 setup_mode = SETUP_MODE_SHORTCUTS;
7157 static void execSetupShortcuts1(void)
7159 setup_mode = SETUP_MODE_SHORTCUTS_1;
7164 static void execSetupShortcuts2(void)
7166 setup_mode = SETUP_MODE_SHORTCUTS_2;
7171 static void execSetupShortcuts3(void)
7173 setup_mode = SETUP_MODE_SHORTCUTS_3;
7178 static void execSetupShortcuts4(void)
7180 setup_mode = SETUP_MODE_SHORTCUTS_4;
7185 static void execSetupShortcuts5(void)
7187 setup_mode = SETUP_MODE_SHORTCUTS_5;
7192 static void execExitSetup(void)
7194 SetGameStatus(GAME_MODE_MAIN);
7199 static void execSaveAndExitSetup(void)
7205 static void execGadgetNetworkServer(void)
7207 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7208 struct GadgetInfo *gi = screen_gadget[gadget_id];
7210 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7211 network_server_hostname[0] = '\0';
7213 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7217 ClickOnGadget(gi, MB_LEFTBUTTON);
7220 static void execOfferUploadTapes(void)
7225 static void ToggleNetworkModeIfNeeded(void)
7227 int font_title = FONT_TITLE_1;
7228 int font_foot = FC_BLUE;
7229 int ystart = mSY - SY + 16;
7230 int ybottom = mSY - SY + SYSIZE - 20;
7231 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7233 if (setup.network_mode == network.enabled)
7236 network.enabled = setup.network_mode;
7238 FadeOut(REDRAW_ALL);
7242 DrawTextSCentered(ystart, font_title, text);
7246 if (network.enabled)
7247 InitNetworkServer();
7249 DisconnectFromNetworkServer();
7251 DrawTextSCentered(ybottom, font_foot,
7252 "Press any key or button for setup menu");
7254 WaitForEventToContinue();
7259 static void ToggleGameSpeedsListIfNeeded(void)
7261 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7263 if (setup.game_speed_extended == using_game_speeds_extended)
7266 // try to match similar values when changing game speeds list
7267 if (setup.game_speed_extended)
7268 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7269 setup.game_frame_delay == 30 ? 29 :
7270 setup.game_frame_delay);
7272 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7273 setup.game_frame_delay == 16 ? 15 :
7274 setup.game_frame_delay >= 29 ? 30 :
7275 setup.game_frame_delay <= 10 ? 10 :
7276 setup.game_frame_delay);
7278 execSetupGame_setGameSpeeds(TRUE);
7283 static void ToggleUseApiServerIfNeeded(void)
7285 if (runtime.use_api_server == setup.use_api_server)
7288 runtime.use_api_server = setup.use_api_server;
7290 if (runtime.use_api_server)
7291 CheckApiServerTasks();
7294 static void ModifyGameSpeedIfNeeded(void)
7296 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7297 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7301 char *game_speed_text = "Fast";
7302 int game_speed_value = 15;
7304 if (setup.game_speed_extended)
7306 game_speed_text = "60 fps";
7307 game_speed_value = 16;
7310 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7312 // set game speed to existing list value that is fast enough for vsync
7313 setup.game_frame_delay = game_speed_value;
7315 execSetupGame_setGameSpeeds(TRUE);
7317 Request(message, REQ_CONFIRM);
7320 static void DisableVsyncIfNeeded(void)
7322 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7323 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7324 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7327 // disable vsync for the selected game speed to work
7328 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7330 execSetupGraphics_setVsyncModes(TRUE);
7332 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7338 void *related_value;
7339 } hide_related_entry_list[] =
7341 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7342 { &setup.scores_in_highscore_list, &scores_type_text },
7344 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7345 { &setup.game_frame_delay, &game_speed_text },
7347 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7348 { &setup.scroll_delay_value, &scroll_delay_text },
7350 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7351 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7353 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7354 { &setup.window_scaling_percent, &window_size_text },
7356 { &setup.window_scaling_quality, execSetupChooseScalingType },
7357 { &setup.window_scaling_quality, &scaling_type_text },
7359 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7360 { &setup.screen_rendering_mode, &rendering_mode_text },
7362 { &setup.vsync_mode, execSetupChooseVsyncMode },
7363 { &setup.vsync_mode, &vsync_mode_text },
7365 { &setup.graphics_set, execSetupChooseGraphics },
7366 { &setup.graphics_set, &graphics_set_name },
7368 { &setup.sounds_set, execSetupChooseSounds },
7369 { &setup.sounds_set, &sounds_set_name },
7371 { &setup.music_set, execSetupChooseMusic },
7372 { &setup.music_set, &music_set_name },
7374 { &setup.volume_simple, execSetupChooseVolumeSimple },
7375 { &setup.volume_simple, &volume_simple_text },
7377 { &setup.volume_loops, execSetupChooseVolumeLoops },
7378 { &setup.volume_loops, &volume_loops_text },
7380 { &setup.volume_music, execSetupChooseVolumeMusic },
7381 { &setup.volume_music, &volume_music_text },
7383 { &setup.touch.control_type, execSetupChooseTouchControls },
7384 { &setup.touch.control_type, &touch_controls_text },
7386 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7387 { &setup.touch.move_distance, &move_distance_text },
7389 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7390 { &setup.touch.drop_distance, &drop_distance_text },
7392 { &setup.touch.transparency, execSetupChooseTransparency },
7393 { &setup.touch.transparency, &transparency_text },
7395 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7396 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7398 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7399 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7401 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7402 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7404 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7405 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7407 { &setup.internal.menu_game, execSetupGame },
7408 { &setup.internal.menu_engines, execSetupEngines },
7409 { &setup.internal.menu_editor, execSetupEditor },
7410 { &setup.internal.menu_graphics, execSetupGraphics },
7411 { &setup.internal.menu_sound, execSetupSound },
7412 { &setup.internal.menu_artwork, execSetupArtwork },
7413 { &setup.internal.menu_input, execSetupInput },
7414 { &setup.internal.menu_touch, execSetupTouch },
7415 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7416 { &setup.internal.menu_exit, execExitSetup },
7417 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7422 void setHideRelatedSetupEntries(void)
7426 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7427 if (hideSetupEntry(hide_related_entry_list[i].value))
7428 setHideSetupEntry(hide_related_entry_list[i].related_value);
7431 static struct TokenInfo setup_info_main[] =
7433 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7434 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7435 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7436 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7437 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7438 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7439 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7440 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7441 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7442 { TYPE_EMPTY, NULL, "" },
7443 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7444 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7449 static struct TokenInfo setup_info_game[] =
7451 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7452 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7453 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7454 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7455 { TYPE_STRING, &network_server_text, "" },
7456 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7457 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7458 { TYPE_STRING, &scores_type_text, "" },
7459 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7460 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7461 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7462 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7463 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7464 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7465 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7466 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7467 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7468 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7469 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7470 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7471 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7472 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7473 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7474 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7475 { TYPE_STRING, &game_speed_text, "" },
7476 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7478 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7479 { TYPE_STRING, &scroll_delay_text, "" },
7481 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7482 { TYPE_STRING, &snapshot_mode_text, "" },
7483 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7484 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7485 { TYPE_EMPTY, NULL, "" },
7486 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7491 static struct TokenInfo setup_info_engines[] =
7493 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7494 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7495 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7496 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7497 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7498 { TYPE_EMPTY, NULL, "" },
7499 { TYPE_HEADLINE, NULL, "Supaplex" },
7500 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7501 { TYPE_EMPTY, NULL, "" },
7502 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7507 static struct TokenInfo setup_info_editor[] =
7510 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7511 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7512 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7513 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7514 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7515 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7516 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7517 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7518 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7519 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7521 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7522 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7524 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7526 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7527 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7528 { TYPE_EMPTY, NULL, "" },
7530 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7531 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7532 { TYPE_EMPTY, NULL, "" },
7534 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7535 { TYPE_EMPTY, NULL, "" },
7536 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7537 { TYPE_EMPTY, NULL, "" },
7538 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7543 static struct TokenInfo setup_info_graphics[] =
7545 #if !defined(PLATFORM_ANDROID)
7546 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7547 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7548 { TYPE_STRING, &window_size_text, "" },
7549 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7550 { TYPE_STRING, &scaling_type_text, "" },
7551 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7552 { TYPE_STRING, &rendering_mode_text, "" },
7555 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7556 { TYPE_STRING, &scroll_delay_text, "" },
7558 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7559 { TYPE_STRING, &vsync_mode_text, "" },
7560 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7561 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7562 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7563 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7564 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7565 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7566 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7567 { TYPE_EMPTY, NULL, "" },
7568 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7573 static struct TokenInfo setup_info_sound[] =
7575 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7576 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7577 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7578 { TYPE_EMPTY, NULL, "" },
7579 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7580 { TYPE_STRING, &volume_simple_text, "" },
7581 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7582 { TYPE_STRING, &volume_loops_text, "" },
7583 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7584 { TYPE_STRING, &volume_music_text, "" },
7585 { TYPE_EMPTY, NULL, "" },
7586 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7591 static struct TokenInfo setup_info_artwork[] =
7593 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7594 { TYPE_STRING, &graphics_set_name, "" },
7595 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7596 { TYPE_STRING, &sounds_set_name, "" },
7597 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7598 { TYPE_STRING, &music_set_name, "" },
7599 { TYPE_EMPTY, NULL, "" },
7600 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7601 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7602 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7603 { TYPE_EMPTY, NULL, "" },
7604 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7609 static struct TokenInfo setup_info_input[] =
7611 { TYPE_SWITCH, NULL, "Player:" },
7612 { TYPE_SWITCH, NULL, "Device:" },
7613 { TYPE_SWITCH, NULL, "" },
7614 { TYPE_SKIPPABLE, NULL, "" },
7615 { TYPE_EMPTY, NULL, "" },
7616 { TYPE_EMPTY, NULL, "" },
7617 { TYPE_EMPTY, NULL, "" },
7618 { TYPE_EMPTY, NULL, "" },
7619 { TYPE_EMPTY, NULL, "" },
7620 { TYPE_EMPTY, NULL, "" },
7621 { TYPE_EMPTY, NULL, "" },
7622 { TYPE_EMPTY, NULL, "" },
7623 { TYPE_SKIPPABLE, NULL, "" },
7624 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7629 static struct TokenInfo setup_info_touch[] =
7631 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7632 { TYPE_STRING, &touch_controls_text, "" },
7633 { TYPE_EMPTY, NULL, "" },
7634 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7639 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7641 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7642 { TYPE_STRING, &touch_controls_text, "" },
7643 { TYPE_EMPTY, NULL, "" },
7644 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7645 { TYPE_STRING, &grid_size_text[0][0], "" },
7646 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7647 { TYPE_STRING, &grid_size_text[0][1], "" },
7648 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7649 { TYPE_STRING, &transparency_text, "" },
7650 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7651 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7652 { TYPE_EMPTY, NULL, "" },
7653 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7654 { TYPE_EMPTY, NULL, "" },
7655 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7660 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7662 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7663 { TYPE_STRING, &touch_controls_text, "" },
7664 { TYPE_EMPTY, NULL, "" },
7665 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7666 { TYPE_STRING, &grid_size_text[1][0], "" },
7667 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7668 { TYPE_STRING, &grid_size_text[1][1], "" },
7669 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7670 { TYPE_STRING, &transparency_text, "" },
7671 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7672 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7673 { TYPE_EMPTY, NULL, "" },
7674 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7675 { TYPE_EMPTY, NULL, "" },
7676 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7681 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7683 setup_info_touch_virtual_buttons_0,
7684 setup_info_touch_virtual_buttons_1
7687 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7689 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7690 { TYPE_STRING, &touch_controls_text, "" },
7691 { TYPE_EMPTY, NULL, "" },
7692 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7693 { TYPE_STRING, &move_distance_text, "" },
7694 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7695 { TYPE_STRING, &drop_distance_text, "" },
7696 { TYPE_EMPTY, NULL, "" },
7697 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7702 static struct TokenInfo setup_info_shortcuts[] =
7704 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7705 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7706 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7707 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7708 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7709 { TYPE_EMPTY, NULL, "" },
7710 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7715 static struct TokenInfo setup_info_shortcuts_1[] =
7717 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7718 { TYPE_KEY, &setup.shortcut.save_game, "" },
7719 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7720 { TYPE_KEY, &setup.shortcut.load_game, "" },
7721 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7722 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7723 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7724 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7725 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7726 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7727 { TYPE_EMPTY, NULL, "" },
7728 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7729 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7730 { TYPE_EMPTY, NULL, "" },
7731 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7736 static struct TokenInfo setup_info_shortcuts_2[] =
7738 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7739 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7740 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7741 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7742 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7743 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7744 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7745 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7746 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7747 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7748 { TYPE_EMPTY, NULL, "" },
7749 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7754 static struct TokenInfo setup_info_shortcuts_3[] =
7756 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7757 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7758 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7759 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7760 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7761 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7762 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7763 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7764 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7765 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7766 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7767 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7768 { TYPE_EMPTY, NULL, "" },
7769 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7774 static struct TokenInfo setup_info_shortcuts_4[] =
7776 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7777 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7778 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7779 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7780 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7781 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7782 { TYPE_EMPTY, NULL, "" },
7783 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7788 static struct TokenInfo setup_info_shortcuts_5[] =
7790 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7791 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7792 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7793 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7794 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7795 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7796 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7797 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7798 { TYPE_EMPTY, NULL, "" },
7799 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7804 static Key getSetupKey(void)
7806 Key key = KSYM_UNDEFINED;
7807 boolean got_key_event = FALSE;
7809 while (!got_key_event)
7813 if (NextValidEvent(&event))
7817 case EVENT_KEYPRESS:
7819 key = GetEventKey((KeyEvent *)&event, TRUE);
7821 // press 'Escape' or 'Enter' to keep the existing key binding
7822 if (key == KSYM_Escape || key == KSYM_Return)
7823 key = KSYM_UNDEFINED; // keep old value
7825 got_key_event = TRUE;
7829 case EVENT_KEYRELEASE:
7830 key_joystick_mapping = 0;
7834 HandleOtherEvents(&event);
7845 static int getSetupValueFont(int type, void *value)
7847 if (type & TYPE_GHOSTED)
7848 return FONT_OPTION_OFF;
7849 else if (type & TYPE_KEY)
7850 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7851 else if (type & TYPE_STRING)
7852 return FONT_VALUE_2;
7853 else if (type & TYPE_ECS_AGA)
7854 return FONT_VALUE_1;
7855 else if (type & TYPE_BOOLEAN_STYLE)
7856 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7857 else if (type & TYPE_YES_NO_AUTO)
7858 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7859 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7860 else if (type & TYPE_PLAYER)
7861 return FONT_VALUE_1;
7863 return FONT_VALUE_1;
7866 static int getSetupValueFontNarrow(int type, int font_nr)
7868 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7869 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7870 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7874 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7876 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7877 struct TokenInfo *si = &setup_info[si_pos];
7878 boolean font_draw_xoffset_modified = FALSE;
7879 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7880 int font_draw_xoffset_old = -1;
7881 int xoffset = (scrollbar_needed ? -1 : 0);
7882 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7883 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7884 int xpos = menu_screen_value_xpos;
7885 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7886 int startx = mSX + xpos * 32;
7887 int starty = mSY + ypos * 32;
7888 int type = si->type;
7889 void *value = si->value;
7890 char *value_string = getSetupValue(type, value);
7891 int font_nr_default = getSetupValueFont(type, value);
7892 int font_width_default = getFontWidth(font_nr_default);
7893 int font_nr = font_nr_default;
7896 if (value_string == NULL)
7899 if (type & TYPE_KEY)
7901 xpos = MENU_SCREEN_START_XPOS;
7903 if (type & TYPE_QUERY)
7904 value_string = "<press key>";
7906 else if (type & TYPE_STRING)
7908 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7910 xpos = MENU_SCREEN_START_XPOS;
7912 if (strlen(value_string) > max_value_len)
7913 value_string[max_value_len] = '\0';
7915 else if (type & TYPE_YES_NO_AUTO)
7917 xpos = menu_screen_value_xpos - 1;
7919 else if (type & TYPE_PLAYER)
7921 int displayed_player_nr = *(int *)value + 1;
7923 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7926 startx = mSX + xpos * 32;
7927 starty = mSY + ypos * 32;
7929 // special check if right-side setup values moved left due to scrollbar
7930 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7932 int max_menu_text_length = 26; // maximum text length for classic menu
7933 int font_xoffset = getFontDrawOffsetX(font_nr);
7934 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7935 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7936 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7937 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7939 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7941 // when using narrow font, left-shifting text "auto" not needed
7942 if (type & TYPE_YES_NO_AUTO)
7946 startx = mSX + xpos * 32;
7948 font_nr = getSetupValueFontNarrow(type, font_nr);
7952 // downward compatibility correction for Juergen Bonhagen's menu settings
7953 if (setup_mode != SETUP_MODE_INPUT)
7955 int max_menu_text_length_big = (menu_screen_value_xpos -
7956 MENU_SCREEN_START_XPOS);
7957 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7958 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7959 int font1_xoffset = getFontDrawOffsetX(font_nr);
7960 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7961 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7962 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7963 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7964 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7965 boolean correct_font_draw_xoffset = FALSE;
7967 if (xpos == MENU_SCREEN_START_XPOS &&
7968 startx + font1_xoffset < text_startx + text_font_xoffset)
7969 correct_font_draw_xoffset = TRUE;
7971 if (xpos == menu_screen_value_xpos &&
7972 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7973 correct_font_draw_xoffset = TRUE;
7975 // check if setup value would overlap with setup text when printed
7976 // (this can happen for extreme/wrong values for font draw offset)
7977 if (correct_font_draw_xoffset)
7979 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7980 font_draw_xoffset_modified = TRUE;
7982 if (type & TYPE_KEY)
7983 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7984 else if (!(type & TYPE_STRING))
7985 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7986 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7990 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7991 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7993 DrawText(startx, starty, value_string, font_nr);
7995 if (type & TYPE_PLAYER)
7997 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7998 int player_nr = *(int *)value;
7999 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8000 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8001 int startx2 = startx + xoff;
8002 int starty2 = starty + yoff;
8004 if (DrawingOnBackground(startx2, starty2))
8005 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8007 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8008 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8011 if (font_draw_xoffset_modified)
8012 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8015 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8017 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8018 struct TokenInfo *si = &setup_info[si_pos];
8020 if (si->type & TYPE_BOOLEAN_STYLE)
8022 *(boolean *)si->value ^= TRUE;
8024 else if (si->type & TYPE_YES_NO_AUTO)
8028 (*(int *)si->value == AUTO ? TRUE :
8029 *(int *)si->value == TRUE ? FALSE : AUTO) :
8030 (*(int *)si->value == TRUE ? AUTO :
8031 *(int *)si->value == AUTO ? FALSE : TRUE));
8033 else if (si->type & TYPE_KEY)
8037 si->type |= TYPE_QUERY;
8038 drawSetupValue(screen_pos, setup_info_pos_raw);
8039 si->type &= ~TYPE_QUERY;
8041 key = getSetupKey();
8042 if (key != KSYM_UNDEFINED)
8043 *(Key *)si->value = key;
8045 else if (si->type & TYPE_PLAYER)
8047 int player_nr = *(int *)si->value;
8052 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8054 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8057 drawSetupValue(screen_pos, setup_info_pos_raw);
8059 // fullscreen state may have changed at this point
8060 if (si->value == &setup.fullscreen)
8061 ToggleFullscreenIfNeeded();
8063 // network mode may have changed at this point
8064 if (si->value == &setup.network_mode)
8065 ToggleNetworkModeIfNeeded();
8067 // API server mode may have changed at this point
8068 if (si->value == &setup.use_api_server)
8069 ToggleUseApiServerIfNeeded();
8071 // game speed list may have changed at this point
8072 if (si->value == &setup.game_speed_extended)
8073 ToggleGameSpeedsListIfNeeded();
8076 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8078 static struct TokenInfo *setup_info_final = NULL;
8083 // determine maximum list size of target list
8084 while (setup_info_orig[list_size++].type != 0);
8086 // free, allocate and clear memory for target list
8087 checked_free(setup_info_final);
8088 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8090 // copy setup info list without setup entries marked as hidden
8091 for (i = 0; setup_info_orig[i].type != 0; i++)
8093 // skip setup entries configured to be hidden
8094 if (hideSetupEntry(setup_info_orig[i].value))
8097 // skip skippable setup entries if screen is lower than usual
8098 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8099 setup_info_orig[i].type == TYPE_SKIPPABLE)
8102 setup_info_final[list_pos++] = setup_info_orig[i];
8105 return setup_info_final;
8108 static void DrawSetupScreen_Generic(void)
8110 int fade_mask = REDRAW_FIELD;
8111 boolean redraw_all = FALSE;
8112 char *title_string = NULL;
8116 fade_mask = REDRAW_ALL;
8119 FadeMenuSoundsAndMusic();
8121 FreeScreenGadgets();
8122 CreateScreenGadgets();
8124 if (redraw_mask & REDRAW_ALL)
8129 // needed if different viewport properties defined for setup screen
8130 ChangeViewportPropertiesIfNeeded();
8132 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8136 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8138 if (setup_mode == SETUP_MODE_MAIN)
8140 setup_info = setup_info_main;
8141 title_string = STR_SETUP_MAIN;
8143 else if (setup_mode == SETUP_MODE_GAME)
8145 setup_info = setup_info_game;
8146 title_string = STR_SETUP_GAME;
8148 else if (setup_mode == SETUP_MODE_ENGINES)
8150 setup_info = setup_info_engines;
8151 title_string = STR_SETUP_ENGINES;
8153 else if (setup_mode == SETUP_MODE_EDITOR)
8155 setup_info = setup_info_editor;
8156 title_string = STR_SETUP_EDITOR;
8158 else if (setup_mode == SETUP_MODE_GRAPHICS)
8160 setup_info = setup_info_graphics;
8161 title_string = STR_SETUP_GRAPHICS;
8163 else if (setup_mode == SETUP_MODE_SOUND)
8165 setup_info = setup_info_sound;
8166 title_string = STR_SETUP_SOUND;
8168 else if (setup_mode == SETUP_MODE_ARTWORK)
8170 setup_info = setup_info_artwork;
8171 title_string = STR_SETUP_ARTWORK;
8173 else if (setup_mode == SETUP_MODE_TOUCH)
8175 setup_info = setup_info_touch;
8176 title_string = STR_SETUP_TOUCH;
8178 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8179 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8180 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8181 setup_info = setup_info_touch_wipe_gestures;
8183 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8185 setup_info = setup_info_shortcuts;
8186 title_string = STR_SETUP_SHORTCUTS;
8188 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8190 setup_info = setup_info_shortcuts_1;
8191 title_string = STR_SETUP_SHORTCUTS;
8193 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8195 setup_info = setup_info_shortcuts_2;
8196 title_string = STR_SETUP_SHORTCUTS;
8198 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8200 setup_info = setup_info_shortcuts_3;
8201 title_string = STR_SETUP_SHORTCUTS;
8203 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8205 setup_info = setup_info_shortcuts_4;
8206 title_string = STR_SETUP_SHORTCUTS;
8208 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8210 setup_info = setup_info_shortcuts_5;
8211 title_string = STR_SETUP_SHORTCUTS;
8214 // use modified setup info without setup entries marked as hidden
8215 setup_info = getSetupInfoFinal(setup_info);
8217 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8219 // determine maximal number of setup entries that can be displayed on screen
8221 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8224 // determine maximal number of setup entries available for this setup screen
8226 for (i = 0; setup_info[i].type != 0; i++)
8229 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8231 MapScreenGadgets(max_setup_info);
8234 redraw_mask = fade_mask = REDRAW_ALL;
8236 DrawMaskedBorder(fade_mask);
8241 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8243 menu_info = setup_info;
8245 HandleMenuScreen(mx, my, dx, dy, button,
8246 setup_mode, num_setup_info, max_setup_info);
8249 static void DrawSetupScreen_Input(void)
8253 FadeOut(REDRAW_FIELD);
8257 setup_info = getSetupInfoFinal(setup_info_input);
8259 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8261 for (i = 0; setup_info[i].type != 0; i++)
8263 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8264 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8265 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8266 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8267 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8268 initCursor(i, IMG_MENU_BUTTON);
8270 DrawCursorAndText_Setup(i, -1, FALSE);
8273 // create gadgets for setup input menu screen
8274 FreeScreenGadgets();
8275 CreateScreenGadgets();
8277 // map gadgets for setup input menu screen
8278 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8280 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8282 FadeIn(REDRAW_FIELD);
8285 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8287 if (device_name == NULL)
8290 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8293 if (strlen(device_name) > 1)
8295 char c1 = device_name[strlen(device_name) - 1];
8296 char c2 = device_name[strlen(device_name) - 2];
8298 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8299 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8302 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8303 strlen(device_name));
8306 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8309 static struct SetupKeyboardInfo custom_key;
8316 { &custom_key.left, "Axis/Pad Left" },
8317 { &custom_key.right, "Axis/Pad Right" },
8318 { &custom_key.up, "Axis/Pad Up" },
8319 { &custom_key.down, "Axis/Pad Down" },
8320 { &custom_key.snap, "Button 1/A/X" },
8321 { &custom_key.drop, "Button 2/B/Y" }
8323 static char *joystick_name[MAX_PLAYERS] =
8330 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8331 int font_nr_info = FONT_MENU_1;
8332 int font_nr_name = FONT_VALUE_OLD;
8333 int font_nr_on = FONT_VALUE_1;
8334 int font_nr_off = FONT_VALUE_OLD;
8337 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8339 font_nr_info = FONT_MENU_2;
8340 font_nr_on = FONT_VALUE_NARROW;
8341 font_nr_off = FONT_VALUE_OLD_NARROW;
8344 custom_key = setup.input[player_nr].key;
8346 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8347 FONT_INPUT_1_ACTIVE);
8349 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8351 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8352 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8354 if (setup.input[player_nr].use_joystick)
8356 char *device_name = setup.input[player_nr].joy.device_name;
8357 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8358 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8359 char *text = joystick_name[joystick_nr];
8360 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8362 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8363 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8367 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8368 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8371 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8372 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8376 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8377 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8378 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8379 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8381 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8382 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8383 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8384 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8385 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8386 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8388 for (i = 0; i < 6; i++)
8390 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8392 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8394 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8395 (setup.input[player_nr].use_joystick ?
8397 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8401 static int input_player_nr = 0;
8403 static void HandleSetupScreen_Input_Player(int step, int direction)
8405 int old_player_nr = input_player_nr;
8408 new_player_nr = old_player_nr + step * direction;
8409 if (new_player_nr < 0)
8411 if (new_player_nr > MAX_PLAYERS - 1)
8412 new_player_nr = MAX_PLAYERS - 1;
8414 if (new_player_nr != old_player_nr)
8416 input_player_nr = new_player_nr;
8418 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8422 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8424 static int choice = 0;
8427 int pos_start = SETUPINPUT_SCREEN_POS_START;
8428 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8429 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8430 int pos_end = SETUPINPUT_SCREEN_POS_END;
8432 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8436 for (i = 0; setup_info_input[i].type != 0; i++)
8438 // adjust menu structure according to skipped setup entries
8439 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8447 if (button == MB_MENU_INITIALIZE)
8449 // input setup menu may have changed size due to graphics configuration
8450 if (choice >= pos_empty1)
8453 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8455 DrawCursorAndText_Setup(choice, -1, TRUE);
8459 else if (button == MB_MENU_LEAVE)
8461 setup_mode = SETUP_MODE_MAIN;
8468 if (mx || my) // mouse input
8470 x = (mx - mSX) / 32;
8471 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8473 else if (dx || dy) // keyboard input
8475 if (dx && choice == 0)
8476 x = (dx < 0 ? 10 : 12);
8477 else if ((dx && choice == 1) ||
8478 (dx == -1 && choice == pos_end))
8479 button = MB_MENU_CHOICE;
8483 if (y >= pos_empty1 && y <= pos_empty2)
8484 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8487 if (y == 0 && dx != 0 && button)
8489 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8491 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8492 y >= pos_start && y <= pos_end &&
8493 !(y >= pos_empty1 && y <= pos_empty2))
8499 DrawCursorAndText_Setup(choice, -1, FALSE);
8500 DrawCursorAndText_Setup(y, -1, TRUE);
8502 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8511 char *device_name = setup.input[input_player_nr].joy.device_name;
8513 if (!setup.input[input_player_nr].use_joystick)
8515 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8517 setJoystickDeviceToNr(device_name, new_device_nr);
8518 setup.input[input_player_nr].use_joystick = TRUE;
8522 int device_nr = getJoystickNrFromDeviceName(device_name);
8523 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8525 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8526 setup.input[input_player_nr].use_joystick = FALSE;
8528 setJoystickDeviceToNr(device_name, new_device_nr);
8531 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8535 if (setup.input[input_player_nr].use_joystick)
8536 ConfigureJoystick(input_player_nr);
8538 CustomizeKeyboard(input_player_nr);
8540 else if (y == pos_end)
8546 setup_mode = SETUP_MODE_MAIN;
8553 static boolean CustomizeKeyboardMain(int player_nr)
8557 boolean finished = FALSE;
8558 static struct SetupKeyboardInfo custom_key;
8563 } customize_step[] =
8565 { &custom_key.left, "Move Left" },
8566 { &custom_key.right, "Move Right" },
8567 { &custom_key.up, "Move Up" },
8568 { &custom_key.down, "Move Down" },
8569 { &custom_key.snap, "Snap Field" },
8570 { &custom_key.drop, "Drop Element" }
8572 int font_nr_old = FONT_VALUE_OLD;
8573 int font_nr_new = FONT_VALUE_1;
8574 boolean success = FALSE;
8576 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8578 font_nr_old = FONT_VALUE_OLD_NARROW;
8579 font_nr_new = FONT_VALUE_NARROW;
8582 // read existing key bindings from player setup
8583 custom_key = setup.input[player_nr].key;
8586 FadeOut(REDRAW_FIELD);
8590 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8593 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8594 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8595 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8596 "Key:", FONT_INPUT_1_ACTIVE);
8597 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8598 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8600 FadeIn(REDRAW_FIELD);
8606 if (NextValidEvent(&event))
8610 case EVENT_KEYPRESS:
8612 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8614 // press 'Escape' to abort and keep the old key bindings
8615 if (key == KSYM_Escape)
8617 FadeSkipNextFadeIn();
8624 // press 'Enter' to keep the existing key binding
8625 if (key == KSYM_Return)
8626 key = *customize_step[step_nr].key;
8628 // check if key already used
8629 for (i = 0; i < step_nr; i++)
8630 if (*customize_step[i].key == key)
8635 // got new key binding
8636 *customize_step[step_nr].key = key;
8637 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8639 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8640 getKeyNameFromKey(key), font_nr_new);
8643 // un-highlight last query
8644 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8645 customize_step[step_nr - 1].text, FONT_MENU_1);
8646 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8647 "Key:", FONT_MENU_1);
8649 // all keys configured
8658 // query next key binding
8659 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8660 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8661 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8662 "Key:", FONT_INPUT_1_ACTIVE);
8663 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8664 getKeyNameFromKey(*customize_step[step_nr].key),
8669 case EVENT_KEYRELEASE:
8670 key_joystick_mapping = 0;
8674 HandleOtherEvents(&event);
8682 // write new key bindings back to player setup, if successfully finished
8684 setup.input[player_nr].key = custom_key;
8689 void CustomizeKeyboard(int player_nr)
8691 boolean success = CustomizeKeyboardMain(player_nr);
8695 int font_nr = FONT_TITLE_1;
8696 int font_height = getFontHeight(font_nr);
8697 int ypos1 = SYSIZE / 2 - font_height * 2;
8698 int ypos2 = SYSIZE / 2 - font_height * 1;
8699 unsigned int wait_frame_delay = 0;
8700 unsigned int wait_frame_delay_value = 2000;
8702 ResetDelayCounter(&wait_frame_delay);
8706 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8707 DrawTextSCentered(ypos2, font_nr, "configured!");
8709 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8715 DrawSetupScreen_Input();
8718 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8720 #define MARKER_BUTTON 1
8721 #define MARKER_AXIS_X 2
8722 #define MARKER_AXIS_Y 3
8724 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8726 static boolean bitmaps_initialized = FALSE;
8727 boolean screen_initialized = FALSE;
8728 static Bitmap *controller, *button, *axis_x, *axis_y;
8730 boolean success = TRUE;
8731 boolean done = FALSE, next = FALSE;
8733 int alpha = 200, alpha_step = -1;
8734 int alpha_ticks = 0;
8735 char mapping[4096], temp[256];
8736 int font_name = MENU_SETUP_FONT_TITLE;
8737 int font_info = MENU_SETUP_FONT_TEXT;
8738 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8739 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8740 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8741 int ystep_name = getMenuTextStep(spacing_name, font_name);
8742 int ystep_line = getMenuTextStep(spacing_line, font_info);
8743 int ystep_para = getMenuTextStep(spacing_para, font_info);
8751 int axis, button, hat, hat_value;
8754 *step, *prev_step, steps[] =
8756 { 356, 155, MARKER_BUTTON, "a", },
8757 { 396, 122, MARKER_BUTTON, "b", },
8758 { 320, 125, MARKER_BUTTON, "x", },
8759 { 358, 95, MARKER_BUTTON, "y", },
8760 { 162, 125, MARKER_BUTTON, "back", },
8761 { 216, 125, MARKER_BUTTON, "guide", },
8762 { 271, 125, MARKER_BUTTON, "start", },
8763 { 110, 200, MARKER_BUTTON, "dpleft", },
8764 { 146, 228, MARKER_BUTTON, "dpdown", },
8765 { 178, 200, MARKER_BUTTON, "dpright", },
8766 { 146, 172, MARKER_BUTTON, "dpup", },
8767 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8768 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8769 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8770 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8771 { 73, 141, MARKER_BUTTON, "leftstick", },
8772 { 282, 210, MARKER_BUTTON, "rightstick", },
8773 { 73, 141, MARKER_AXIS_X, "leftx", },
8774 { 73, 141, MARKER_AXIS_Y, "lefty", },
8775 { 282, 210, MARKER_AXIS_X, "rightx", },
8776 { 282, 210, MARKER_AXIS_Y, "righty", },
8779 unsigned int event_frame_delay = 0;
8780 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8782 ResetDelayCounter(&event_frame_delay);
8784 if (!bitmaps_initialized)
8786 controller = LoadCustomImage("joystick/controller.png");
8787 button = LoadCustomImage("joystick/button.png");
8788 axis_x = LoadCustomImage("joystick/axis_x.png");
8789 axis_y = LoadCustomImage("joystick/axis_y.png");
8791 bitmaps_initialized = TRUE;
8794 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8797 // print info about the joystick we are watching
8798 Debug("joystick", "watching joystick %d: (%s)",
8799 SDL_JoystickInstanceID(joystick), name);
8800 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8801 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8802 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8805 // initialize mapping with GUID and name
8806 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8808 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8809 temp, name, SDL_GetPlatform());
8811 // loop through all steps (buttons and axes), getting joystick events
8812 for (i = 0; i < SDL_arraysize(steps) && !done;)
8814 Bitmap *marker = button; // initialize with reliable default value
8817 strcpy(step->mapping, mapping);
8821 step->hat_value = -1;
8823 marker = (step->marker == MARKER_BUTTON ? button :
8824 step->marker == MARKER_AXIS_X ? axis_x :
8825 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8829 while (!done && !next)
8831 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8832 alpha_ticks = SDL_GetTicks();
8839 else if (alpha < 128)
8845 int controller_x = SX + (SXSIZE - controller->width) / 2;
8846 int controller_y = SY + ystep_line;
8848 int marker_x = controller_x + step->x;
8849 int marker_y = controller_y + step->y;
8851 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8852 int ystart2 = ystart1 + ystep_name + ystep_line;
8856 DrawTextSCentered(ystart1, font_name, name);
8858 DrawTextSCentered(ystart2, font_info,
8859 "Press buttons and move axes on");
8860 ystart2 += ystep_line;
8861 DrawTextSCentered(ystart2, font_info,
8862 "your controller when indicated.");
8863 ystart2 += ystep_line;
8864 DrawTextSCentered(ystart2, font_info,
8865 "(Your controller may look different.)");
8866 ystart2 += ystep_para;
8868 #if defined(PLATFORM_ANDROID)
8869 DrawTextSCentered(ystart2, font_info,
8870 "To correct a mistake,");
8871 ystart2 += ystep_line;
8872 DrawTextSCentered(ystart2, font_info,
8873 "press the 'back' button.");
8874 ystart2 += ystep_line;
8875 DrawTextSCentered(ystart2, font_info,
8876 "To skip a button or axis,");
8877 ystart2 += ystep_line;
8878 DrawTextSCentered(ystart2, font_info,
8879 "press the 'menu' button.");
8881 DrawTextSCentered(ystart2, font_info,
8882 "To correct a mistake,");
8883 ystart2 += ystep_line;
8884 DrawTextSCentered(ystart2, font_info,
8885 "press the 'backspace' key.");
8886 ystart2 += ystep_line;
8887 DrawTextSCentered(ystart2, font_info,
8888 "To skip a button or axis,");
8889 ystart2 += ystep_line;
8890 DrawTextSCentered(ystart2, font_info,
8891 "press the 'return' key.");
8892 ystart2 += ystep_line;
8893 DrawTextSCentered(ystart2, font_info,
8894 "To exit, press the 'escape' key.");
8897 BlitBitmapMasked(controller, drawto, 0, 0,
8898 controller->width, controller->height,
8899 controller_x, controller_y);
8901 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8902 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8904 BlitBitmapMasked(marker, drawto, 0, 0,
8905 marker->width, marker->height,
8906 marker_x, marker_y);
8908 if (!screen_initialized)
8909 FadeIn(REDRAW_FIELD);
8913 screen_initialized = TRUE;
8915 while (NextValidEvent(&event))
8919 case SDL_JOYAXISMOTION:
8920 if (event.jaxis.value > 20000 ||
8921 event.jaxis.value < -20000)
8923 for (j = 0; j < i; j++)
8924 if (steps[j].axis == event.jaxis.axis)
8929 if (step->marker != MARKER_AXIS_X &&
8930 step->marker != MARKER_AXIS_Y)
8933 step->axis = event.jaxis.axis;
8934 strcat(mapping, step->field);
8935 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8936 strcat(mapping, temp);
8944 case SDL_JOYHATMOTION:
8945 // ignore centering; we're probably just coming back
8946 // to the center from the previous item we set
8947 if (event.jhat.value == SDL_HAT_CENTERED)
8950 for (j = 0; j < i; j++)
8951 if (steps[j].hat == event.jhat.hat &&
8952 steps[j].hat_value == event.jhat.value)
8957 step->hat = event.jhat.hat;
8958 step->hat_value = event.jhat.value;
8959 strcat(mapping, step->field);
8960 snprintf(temp, sizeof(temp), ":h%u.%u,",
8961 event.jhat.hat, event.jhat.value );
8962 strcat(mapping, temp);
8969 case SDL_JOYBALLMOTION:
8972 case SDL_JOYBUTTONUP:
8973 for (j = 0; j < i; j++)
8974 if (steps[j].button == event.jbutton.button)
8979 step->button = event.jbutton.button;
8980 strcat(mapping, step->field);
8981 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8982 strcat(mapping, temp);
8989 case SDL_FINGERDOWN:
8990 case SDL_MOUSEBUTTONDOWN:
8998 if (event.key.keysym.sym == KSYM_BackSpace ||
8999 event.key.keysym.sym == KSYM_Back)
9011 prev_step = &steps[i - 1];
9012 strcpy(mapping, prev_step->mapping);
9019 if (event.key.keysym.sym == KSYM_space ||
9020 event.key.keysym.sym == KSYM_Return ||
9021 event.key.keysym.sym == KSYM_Menu)
9030 if (event.key.keysym.sym == KSYM_Escape)
9040 program.exit_function(0);
9047 // do not handle events for longer than standard frame delay period
9048 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9057 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9060 // activate mapping for this game
9061 SDL_GameControllerAddMapping(mapping);
9063 // save mapping to personal mappings
9064 SaveSetup_AddGameControllerMapping(mapping);
9067 // wait until the last pending event was removed from event queue
9068 while (NextValidEvent(&event));
9073 static int ConfigureJoystickMain(int player_nr)
9075 char *device_name = setup.input[player_nr].joy.device_name;
9076 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9077 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9078 int success = FALSE;
9081 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9082 return JOYSTICK_NOT_AVAILABLE;
9084 if (!joystick_active || !setup.input[player_nr].use_joystick)
9085 return JOYSTICK_NOT_AVAILABLE;
9088 FadeOut(REDRAW_FIELD);
9090 // close all joystick devices (potentially opened as game controllers)
9091 for (i = 0; i < SDL_NumJoysticks(); i++)
9092 SDLCloseJoystick(i);
9094 // open joystick device as plain joystick to configure as game controller
9095 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9097 // as the joystick was successfully opened before, this should not happen
9098 if (joystick == NULL)
9101 // create new game controller mapping (buttons and axes) for joystick device
9102 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9104 // close joystick (and maybe re-open as configured game controller later)
9105 SDL_JoystickClose(joystick);
9107 // re-open all joystick devices (potentially as game controllers)
9108 for (i = 0; i < SDL_NumJoysticks(); i++)
9111 // clear all joystick input actions for all joystick devices
9112 SDLClearJoystickState();
9114 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9117 void ConfigureJoystick(int player_nr)
9119 boolean state = ConfigureJoystickMain(player_nr);
9121 if (state != JOYSTICK_NOT_CONFIGURED)
9123 boolean success = (state == JOYSTICK_CONFIGURED);
9124 char message1[MAX_OUTPUT_LINESIZE + 1];
9125 char *message2 = (success ? "configured!" : "not available!");
9126 char *device_name = setup.input[player_nr].joy.device_name;
9127 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9128 int font_nr = FONT_TITLE_1;
9129 int font_height = getFontHeight(font_nr);
9130 int ypos1 = SYSIZE / 2 - font_height * 2;
9131 int ypos2 = SYSIZE / 2 - font_height * 1;
9132 unsigned int wait_frame_delay = 0;
9133 unsigned int wait_frame_delay_value = 2000;
9135 ResetDelayCounter(&wait_frame_delay);
9139 sprintf(message1, "Joystick %d", nr);
9141 DrawTextSCentered(ypos1, font_nr, message1);
9142 DrawTextSCentered(ypos2, font_nr, message2);
9144 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9150 DrawSetupScreen_Input();
9153 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9155 if (y < video.screen_height / 3)
9157 // remap touch gadgets to access upper part of the screen
9158 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9159 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9161 else if (y > 2 * video.screen_height / 3)
9163 // remap touch gadgets to access lower part of the screen
9164 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9165 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9169 static boolean ConfigureVirtualButtonsMain(void)
9171 static char *customize_step_text[] =
9180 char grid_button[] =
9182 CHAR_GRID_BUTTON_LEFT,
9183 CHAR_GRID_BUTTON_RIGHT,
9184 CHAR_GRID_BUTTON_UP,
9185 CHAR_GRID_BUTTON_DOWN,
9186 CHAR_GRID_BUTTON_SNAP,
9187 CHAR_GRID_BUTTON_DROP
9196 int font_nr = FONT_INPUT_1_ACTIVE;
9197 int font_height = getFontHeight(font_nr);
9198 int ypos1 = SYSIZE / 2 - font_height * 2;
9199 int ypos2 = SYSIZE / 2 - font_height * 1;
9200 boolean success = FALSE;
9201 boolean finished = FALSE;
9203 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9204 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9205 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9206 boolean set_grid_button = FALSE;
9207 int nr = GRID_ACTIVE_NR();
9210 for (x = 0; x < MAX_GRID_XSIZE; x++)
9211 for (y = 0; y < MAX_GRID_YSIZE; y++)
9212 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9214 overlay.grid_button_highlight = grid_button[step_nr];
9219 FadeOut(REDRAW_FIELD);
9223 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9224 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9225 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9227 FadeIn(REDRAW_FIELD);
9229 SetOverlayShowGrid(TRUE);
9231 // map gadgets for setup touch buttons menu screen
9232 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9238 while (NextValidEvent(&event))
9240 int action = ACTION_NONE;
9242 // ---------- handle events and set the resulting action ----------
9248 UserEvent *user = (UserEvent *)&event;
9249 int id = user->value1;
9251 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9252 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9253 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9254 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9259 case EVENT_KEYPRESS:
9261 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9263 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9264 key == KSYM_BackSpace ||
9265 key == KSYM_Back ? ACTION_BACK :
9266 key == KSYM_Return ||
9268 key == KSYM_space ? ACTION_NEXT :
9273 case EVENT_KEYRELEASE:
9274 key_joystick_mapping = 0;
9277 case EVENT_BUTTONPRESS:
9278 case EVENT_BUTTONRELEASE:
9280 ButtonEvent *button = (ButtonEvent *)&event;
9282 motion_status = FALSE;
9284 if (button->type == EVENT_BUTTONPRESS)
9285 button_status = button->button;
9287 button_status = MB_RELEASED;
9289 if (HandleGadgets(button->x, button->y, button_status))
9291 // do not handle this button event anymore
9295 button->x += video.screen_xoffset;
9296 button->y += video.screen_yoffset;
9298 x = button->x * overlay.grid_xsize / video.screen_width;
9299 y = button->y * overlay.grid_ysize / video.screen_height;
9301 if (button->type == EVENT_BUTTONPRESS)
9304 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9305 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9307 set_grid_button = TRUE;
9310 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9314 case EVENT_MOTIONNOTIFY:
9316 MotionEvent *motion = (MotionEvent *)&event;
9318 motion_status = TRUE;
9320 if (HandleGadgets(motion->x, motion->y, button_status))
9322 // do not handle this button event anymore
9326 motion->x += video.screen_xoffset;
9327 motion->y += video.screen_yoffset;
9329 x = motion->x * overlay.grid_xsize / video.screen_width;
9330 y = motion->y * overlay.grid_ysize / video.screen_height;
9332 set_grid_button = TRUE;
9334 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9338 case SDL_WINDOWEVENT:
9339 HandleWindowEvent((WindowEvent *) &event);
9341 // check if device has been rotated
9342 if (nr != GRID_ACTIVE_NR())
9344 nr = GRID_ACTIVE_NR();
9346 for (x = 0; x < MAX_GRID_XSIZE; x++)
9347 for (y = 0; y < MAX_GRID_YSIZE; y++)
9348 grid_button_old[x][y] = grid_button_tmp[x][y] =
9349 overlay.grid_button[x][y];
9354 case SDL_APP_WILLENTERBACKGROUND:
9355 case SDL_APP_DIDENTERBACKGROUND:
9356 case SDL_APP_WILLENTERFOREGROUND:
9357 case SDL_APP_DIDENTERFOREGROUND:
9358 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9362 HandleOtherEvents(&event);
9366 // ---------- perform action set by handling events ----------
9368 if (action == ACTION_ESCAPE)
9370 // abort and restore the old key bindings
9372 for (x = 0; x < MAX_GRID_XSIZE; x++)
9373 for (y = 0; y < MAX_GRID_YSIZE; y++)
9374 overlay.grid_button[x][y] = grid_button_old[x][y];
9376 FadeSkipNextFadeIn();
9380 else if (action == ACTION_BACK)
9382 // keep the configured key bindings and go to previous page
9388 FadeSkipNextFadeIn();
9393 else if (action == ACTION_NEXT)
9395 // keep the configured key bindings and go to next page
9399 // all virtual buttons configured
9407 if (action != ACTION_NONE && !finished)
9409 for (x = 0; x < MAX_GRID_XSIZE; x++)
9410 for (y = 0; y < MAX_GRID_YSIZE; y++)
9411 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9413 overlay.grid_button_highlight = grid_button[step_nr];
9415 // configure next virtual button
9419 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9420 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9421 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9424 if (set_grid_button)
9426 overlay.grid_button[x][y] =
9427 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9428 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9429 grid_button_tmp[x][y]);
9431 set_grid_button = FALSE;
9438 for (x = 0; x < MAX_GRID_XSIZE; x++)
9439 for (y = 0; y < MAX_GRID_YSIZE; y++)
9440 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9442 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9444 SetOverlayShowGrid(FALSE);
9449 void ConfigureVirtualButtons(void)
9451 boolean success = ConfigureVirtualButtonsMain();
9453 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9454 SCREEN_MASK_TOUCH2);
9458 int font_nr = FONT_TITLE_1;
9459 int font_height = getFontHeight(font_nr);
9460 int ypos1 = SYSIZE / 2 - font_height * 2;
9461 int ypos2 = SYSIZE / 2 - font_height * 1;
9462 unsigned int wait_frame_delay = 0;
9463 unsigned int wait_frame_delay_value = 2000;
9465 ResetDelayCounter(&wait_frame_delay);
9469 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9470 DrawTextSCentered(ypos2, font_nr, "configured!");
9472 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9479 void DrawSetupScreen(void)
9484 if (setup_mode == SETUP_MODE_INPUT)
9485 DrawSetupScreen_Input();
9486 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9487 DrawChooseTree(&scores_type_current);
9488 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9489 DrawChooseTree(&game_speed_current);
9490 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9491 DrawChooseTree(&scroll_delay_current);
9492 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9493 DrawChooseTree(&snapshot_mode_current);
9494 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9495 DrawChooseTree(&window_size_current);
9496 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9497 DrawChooseTree(&scaling_type_current);
9498 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9499 DrawChooseTree(&rendering_mode_current);
9500 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9501 DrawChooseTree(&vsync_mode_current);
9502 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9503 DrawChooseTree(&artwork.gfx_current);
9504 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9505 DrawChooseTree(&artwork.snd_current);
9506 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9507 DrawChooseTree(&artwork.mus_current);
9508 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9509 DrawChooseTree(&volume_simple_current);
9510 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9511 DrawChooseTree(&volume_loops_current);
9512 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9513 DrawChooseTree(&volume_music_current);
9514 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9515 DrawChooseTree(&touch_control_current);
9516 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9517 DrawChooseTree(&move_distance_current);
9518 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9519 DrawChooseTree(&drop_distance_current);
9520 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9521 DrawChooseTree(&transparency_current);
9522 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9523 DrawChooseTree(&grid_size_current[0][0]);
9524 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9525 DrawChooseTree(&grid_size_current[0][1]);
9526 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9527 DrawChooseTree(&grid_size_current[1][0]);
9528 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9529 DrawChooseTree(&grid_size_current[1][1]);
9531 DrawSetupScreen_Generic();
9533 PlayMenuSoundsAndMusic();
9536 void RedrawSetupScreenAfterFullscreenToggle(void)
9538 if (setup_mode == SETUP_MODE_GRAPHICS ||
9539 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9541 // update list selection from "setup.window_scaling_percent"
9542 execSetupGraphics_setWindowSizes(TRUE);
9548 void RedrawSetupScreenAfterScreenRotation(int nr)
9552 if (setup_mode == SETUP_MODE_TOUCH)
9554 // update virtual button settings (depending on screen orientation)
9557 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9559 // save already configured virtual buttons
9560 for (x = 0; x < MAX_GRID_XSIZE; x++)
9561 for (y = 0; y < MAX_GRID_YSIZE; y++)
9562 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9566 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9568 if (setup_mode == SETUP_MODE_INPUT)
9569 HandleSetupScreen_Input(mx, my, dx, dy, button);
9570 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9571 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9572 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9573 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9574 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9575 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9576 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9577 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9578 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9579 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9580 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9581 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9582 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9583 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9584 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9585 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9586 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9587 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9588 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9589 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9590 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9591 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9592 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9593 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9594 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9595 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9596 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9597 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9598 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9599 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9600 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9601 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9602 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9603 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9604 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9605 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9606 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9607 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9608 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9609 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9610 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9611 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9612 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9613 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9615 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9618 void HandleGameActions(void)
9620 if (setup.ask_on_game_over)
9623 if (game.restart_game_message != NULL)
9625 RequestRestartGame(game.restart_game_message);
9630 if (game_status != GAME_MODE_PLAYING)
9633 GameActions(); // main game loop
9635 if (tape.auto_play && !tape.playing)
9636 AutoPlayTapesContinue(); // continue automatically playing next tape
9640 // ---------- new screen button stuff --------------------------------------
9644 int gfx_unpressed, gfx_pressed;
9645 struct MenuPosInfo *pos;
9646 boolean *check_value;
9649 unsigned int event_mask;
9650 boolean is_touch_button;
9652 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9655 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9656 &menu.main.button.prev_level, NULL,
9657 SCREEN_CTRL_ID_PREV_LEVEL,
9659 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9660 FALSE, "previous level"
9663 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9664 &menu.main.button.next_level, NULL,
9665 SCREEN_CTRL_ID_NEXT_LEVEL,
9667 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9671 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9672 &menu.scores.button.prev_level, NULL,
9673 SCREEN_CTRL_ID_PREV_LEVEL2,
9675 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9676 FALSE, "previous level"
9679 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9680 &menu.scores.button.next_level, NULL,
9681 SCREEN_CTRL_ID_NEXT_LEVEL2,
9683 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9687 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9688 &menu.main.button.first_level, NULL,
9689 SCREEN_CTRL_ID_FIRST_LEVEL,
9692 FALSE, "first level"
9695 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9696 &menu.main.button.last_level, NULL,
9697 SCREEN_CTRL_ID_LAST_LEVEL,
9703 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9704 &menu.main.button.level_number, NULL,
9705 SCREEN_CTRL_ID_LEVEL_NUMBER,
9708 FALSE, "level number"
9711 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9712 &menu.setup.button.prev_player, NULL,
9713 SCREEN_CTRL_ID_PREV_PLAYER,
9715 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9716 FALSE, "previous player"
9719 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9720 &menu.setup.button.next_player, NULL,
9721 SCREEN_CTRL_ID_NEXT_PLAYER,
9723 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9724 FALSE, "next player"
9727 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9728 &menu.main.button.insert_solution, NULL,
9729 SCREEN_CTRL_ID_INSERT_SOLUTION,
9730 SCREEN_MASK_MAIN_HAS_SOLUTION,
9732 FALSE, "insert solution tape"
9735 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9736 &menu.main.button.play_solution, NULL,
9737 SCREEN_CTRL_ID_PLAY_SOLUTION,
9738 SCREEN_MASK_MAIN_HAS_SOLUTION,
9740 FALSE, "play solution tape"
9743 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9744 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9745 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9747 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9748 FALSE, "switch ECS/AGA chipset"
9751 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9752 &menu.setup.button.touch_back, NULL,
9753 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9756 TRUE, "previous page"
9759 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9760 &menu.setup.button.touch_next, NULL,
9761 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9767 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9768 &menu.setup.button.touch_back2, NULL,
9769 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9772 TRUE, "previous page"
9775 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9776 &menu.setup.button.touch_next2, NULL,
9777 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9786 int gfx_unpressed, gfx_pressed;
9790 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9793 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9794 -1, -1, // these values are not constant, but can change at runtime
9795 SCREEN_CTRL_ID_SCROLL_UP,
9799 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9800 -1, -1, // these values are not constant, but can change at runtime
9801 SCREEN_CTRL_ID_SCROLL_DOWN,
9808 int gfx_unpressed, gfx_pressed;
9814 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9817 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9818 -1, -1, // these values are not constant, but can change at runtime
9819 -1, -1, // these values are not constant, but can change at runtime
9820 GD_TYPE_SCROLLBAR_VERTICAL,
9821 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9822 "scroll level series vertically"
9834 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9837 IMG_SETUP_INPUT_TEXT,
9838 SCREEN_CTRL_ID_NETWORK_SERVER,
9839 -1, -1, // these values are not constant, but can change at runtime
9840 MAX_SETUP_TEXT_INPUT_LEN,
9841 network_server_hostname,
9842 "Network Server Hostname / IP"
9846 static void CreateScreenMenubuttons(void)
9848 struct GadgetInfo *gi;
9849 unsigned int event_mask;
9852 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9854 struct MenuPosInfo *pos = menubutton_info[i].pos;
9855 int screen_mask = menubutton_info[i].screen_mask;
9856 boolean is_touch_button = menubutton_info[i].is_touch_button;
9857 boolean is_check_button = menubutton_info[i].check_value != NULL;
9858 boolean is_score_button = (screen_mask == SCREEN_MASK_SCORES);
9859 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9860 int gfx_unpressed, gfx_pressed;
9861 int x, y, width, height;
9862 int gd_x1, gd_x2, gd_y1, gd_y2;
9863 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9864 int id = menubutton_info[i].gadget_id;
9865 int type = GD_TYPE_NORMAL_BUTTON;
9866 boolean checked = FALSE;
9868 event_mask = menubutton_info[i].event_mask;
9870 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9871 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9873 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9874 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9876 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9877 gfx_pressed = menubutton_info[i].gfx_pressed;
9878 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9879 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9880 gd_x1 = graphic_info[gfx_unpressed].src_x;
9881 gd_y1 = graphic_info[gfx_unpressed].src_y;
9882 gd_x2 = graphic_info[gfx_pressed].src_x;
9883 gd_y2 = graphic_info[gfx_pressed].src_y;
9889 if (is_touch_button)
9891 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9892 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9895 if (is_check_button)
9897 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9898 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9899 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9900 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9902 type = GD_TYPE_CHECK_BUTTON;
9903 checked = *menubutton_info[i].check_value;
9906 if (is_score_button)
9908 // if x/y set to -1, dynamically place buttons next to title text
9909 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9912 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9913 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9914 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9915 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9918 y = mSY + MENU_TITLE1_YPOS;
9921 gi = CreateGadget(GDI_CUSTOM_ID, id,
9922 GDI_CUSTOM_TYPE_ID, i,
9923 GDI_IMAGE_ID, gfx_unpressed,
9924 GDI_INFO_TEXT, menubutton_info[i].infotext,
9930 GDI_STATE, GD_BUTTON_UNPRESSED,
9931 GDI_CHECKED, checked,
9932 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9933 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9934 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9935 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9936 GDI_DIRECT_DRAW, FALSE,
9937 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9938 GDI_EVENT_MASK, event_mask,
9939 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9943 Fail("cannot create gadget");
9945 screen_gadget[id] = gi;
9949 static void CreateScreenScrollbuttons(void)
9951 struct GadgetInfo *gi;
9952 unsigned int event_mask;
9955 // these values are not constant, but can change at runtime
9956 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9957 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9958 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9959 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9961 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9963 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9964 int gfx_unpressed, gfx_pressed;
9965 int x, y, width, height;
9966 int gd_x1, gd_x2, gd_y1, gd_y2;
9967 int id = scrollbutton_info[i].gadget_id;
9969 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9971 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9972 y = mSY + scrollbutton_info[i].y;
9973 width = SC_SCROLLBUTTON_XSIZE;
9974 height = SC_SCROLLBUTTON_YSIZE;
9976 // correct scrollbar position if placed outside menu (playfield) area
9977 if (x > SX + SC_SCROLL_UP_XPOS)
9978 x = SX + SC_SCROLL_UP_XPOS;
9980 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9981 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9982 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9984 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9985 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9986 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9987 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9988 gd_x1 = graphic_info[gfx_unpressed].src_x;
9989 gd_y1 = graphic_info[gfx_unpressed].src_y;
9990 gd_x2 = graphic_info[gfx_pressed].src_x;
9991 gd_y2 = graphic_info[gfx_pressed].src_y;
9993 gi = CreateGadget(GDI_CUSTOM_ID, id,
9994 GDI_CUSTOM_TYPE_ID, i,
9995 GDI_IMAGE_ID, gfx_unpressed,
9996 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10000 GDI_HEIGHT, height,
10001 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10002 GDI_STATE, GD_BUTTON_UNPRESSED,
10003 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10004 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10005 GDI_DIRECT_DRAW, FALSE,
10006 GDI_EVENT_MASK, event_mask,
10007 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10011 Fail("cannot create gadget");
10013 screen_gadget[id] = gi;
10017 static void CreateScreenScrollbars(void)
10021 // these values are not constant, but can change at runtime
10022 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10023 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10024 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10025 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10027 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10029 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10030 int gfx_unpressed, gfx_pressed;
10031 int x, y, width, height;
10032 int gd_x1, gd_x2, gd_y1, gd_y2;
10033 struct GadgetInfo *gi;
10034 int items_max, items_visible, item_position;
10035 unsigned int event_mask;
10036 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10037 int id = scrollbar_info[i].gadget_id;
10039 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10041 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10042 y = mSY + scrollbar_info[i].y;
10043 width = scrollbar_info[i].width;
10044 height = scrollbar_info[i].height;
10046 // correct scrollbar position if placed outside menu (playfield) area
10047 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10048 x = SX + SC_SCROLL_VERTICAL_XPOS;
10050 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10051 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10053 items_max = num_page_entries;
10054 items_visible = num_page_entries;
10057 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10058 gfx_pressed = scrollbar_info[i].gfx_pressed;
10059 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10060 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10061 gd_x1 = graphic_info[gfx_unpressed].src_x;
10062 gd_y1 = graphic_info[gfx_unpressed].src_y;
10063 gd_x2 = graphic_info[gfx_pressed].src_x;
10064 gd_y2 = graphic_info[gfx_pressed].src_y;
10066 gi = CreateGadget(GDI_CUSTOM_ID, id,
10067 GDI_CUSTOM_TYPE_ID, i,
10068 GDI_IMAGE_ID, gfx_unpressed,
10069 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10073 GDI_HEIGHT, height,
10074 GDI_TYPE, scrollbar_info[i].type,
10075 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10076 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10077 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10078 GDI_WHEEL_AREA_X, SX,
10079 GDI_WHEEL_AREA_Y, SY,
10080 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10081 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10082 GDI_STATE, GD_BUTTON_UNPRESSED,
10083 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10084 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10085 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10086 GDI_DIRECT_DRAW, FALSE,
10087 GDI_EVENT_MASK, event_mask,
10088 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10092 Fail("cannot create gadget");
10094 screen_gadget[id] = gi;
10098 static void CreateScreenTextInputGadgets(void)
10102 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10104 int graphic = textinput_info[i].graphic;
10105 struct GraphicInfo *gd = &graphic_info[graphic];
10106 int gd_x1 = gd->src_x;
10107 int gd_y1 = gd->src_y;
10108 int gd_x2 = gd->src_x + gd->active_xoffset;
10109 int gd_y2 = gd->src_y + gd->active_yoffset;
10110 struct GadgetInfo *gi;
10111 unsigned int event_mask;
10112 int id = textinput_info[i].gadget_id;
10113 int x = textinput_info[i].x;
10114 int y = textinput_info[i].y;
10116 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10118 gi = CreateGadget(GDI_CUSTOM_ID, id,
10119 GDI_CUSTOM_TYPE_ID, i,
10120 GDI_INFO_TEXT, textinput_info[i].infotext,
10123 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10124 GDI_TEXT_VALUE, textinput_info[i].value,
10125 GDI_TEXT_SIZE, textinput_info[i].size,
10126 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10127 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10128 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10129 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10130 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10131 GDI_DESIGN_WIDTH, gd->width,
10132 GDI_EVENT_MASK, event_mask,
10133 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10134 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10138 Fail("cannot create gadget");
10140 screen_gadget[id] = gi;
10144 void CreateScreenGadgets(void)
10146 CreateScreenMenubuttons();
10148 CreateScreenScrollbuttons();
10149 CreateScreenScrollbars();
10151 CreateScreenTextInputGadgets();
10154 void FreeScreenGadgets(void)
10158 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10159 FreeGadget(screen_gadget[i]);
10162 static void RedrawScreenMenuGadgets(int screen_mask)
10166 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10167 if (screen_mask & menubutton_info[i].screen_mask)
10168 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10171 static void MapScreenMenuGadgets(int screen_mask)
10175 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10176 if (screen_mask & menubutton_info[i].screen_mask)
10177 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10180 static void UnmapScreenMenuGadgets(int screen_mask)
10184 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10186 if (screen_mask & menubutton_info[i].screen_mask)
10188 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10190 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10191 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10192 screen_gadget[menubutton_info[i].gadget_id]->y,
10193 screen_gadget[menubutton_info[i].gadget_id]->width,
10194 screen_gadget[menubutton_info[i].gadget_id]->height);
10199 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10202 MapScreenMenuGadgets(screen_mask);
10204 UnmapScreenMenuGadgets(screen_mask);
10207 static void MapScreenGadgets(int num_entries)
10211 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10214 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10215 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10217 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10218 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10221 static void UnmapScreenGadgets()
10225 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10226 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10228 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10229 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10232 static void MapScreenTreeGadgets(TreeInfo *ti)
10234 MapScreenGadgets(numTreeInfoInGroup(ti));
10237 static void UnmapScreenTreeGadgets(void)
10239 UnmapScreenGadgets();
10242 static void HandleScreenGadgets(struct GadgetInfo *gi)
10244 int id = gi->custom_id;
10245 int button = gi->event.button;
10246 int step = (button == MB_LEFTBUTTON ? 1 :
10247 button == MB_MIDDLEBUTTON ? 5 :
10248 button == MB_RIGHTBUTTON ? 10 : 1);
10252 case SCREEN_CTRL_ID_PREV_LEVEL:
10253 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10256 case SCREEN_CTRL_ID_NEXT_LEVEL:
10257 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10260 case SCREEN_CTRL_ID_PREV_LEVEL2:
10261 HandleHallOfFame_SelectLevel(step, -1);
10264 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10265 HandleHallOfFame_SelectLevel(step, +1);
10268 case SCREEN_CTRL_ID_FIRST_LEVEL:
10269 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10272 case SCREEN_CTRL_ID_LAST_LEVEL:
10273 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10276 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10277 CloseDoor(DOOR_CLOSE_2);
10278 SetGameStatus(GAME_MODE_LEVELNR);
10279 DrawChooseLevelNr();
10282 case SCREEN_CTRL_ID_PREV_PLAYER:
10283 HandleSetupScreen_Input_Player(step, -1);
10286 case SCREEN_CTRL_ID_NEXT_PLAYER:
10287 HandleSetupScreen_Input_Player(step, +1);
10290 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10291 InsertSolutionTape();
10294 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10295 PlaySolutionTape();
10298 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10299 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10303 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10304 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10305 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10306 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10307 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10310 case SCREEN_CTRL_ID_SCROLL_UP:
10311 if (game_status == GAME_MODE_NAMES)
10312 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10313 else if (game_status == GAME_MODE_LEVELS)
10314 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10315 else if (game_status == GAME_MODE_LEVELNR)
10316 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10317 else if (game_status == GAME_MODE_SETUP)
10318 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10319 else if (game_status == GAME_MODE_INFO)
10320 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10321 else if (game_status == GAME_MODE_SCORES)
10322 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10325 case SCREEN_CTRL_ID_SCROLL_DOWN:
10326 if (game_status == GAME_MODE_NAMES)
10327 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10328 else if (game_status == GAME_MODE_LEVELS)
10329 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10330 else if (game_status == GAME_MODE_LEVELNR)
10331 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10332 else if (game_status == GAME_MODE_SETUP)
10333 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10334 else if (game_status == GAME_MODE_INFO)
10335 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10336 else if (game_status == GAME_MODE_SCORES)
10337 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10340 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10341 if (game_status == GAME_MODE_NAMES)
10342 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10343 else if (game_status == GAME_MODE_LEVELS)
10344 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10345 else if (game_status == GAME_MODE_LEVELNR)
10346 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10347 else if (game_status == GAME_MODE_SETUP)
10348 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10349 else if (game_status == GAME_MODE_INFO)
10350 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10351 else if (game_status == GAME_MODE_SCORES)
10352 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10355 case SCREEN_CTRL_ID_NETWORK_SERVER:
10357 if (!strEqual(gi->textinput.value, ""))
10359 setString(&setup.network_server_hostname, gi->textinput.value);
10361 network.server_host = setup.network_server_hostname;
10365 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10367 network.server_host = NULL;
10370 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10371 network.server_host = NULL;
10373 execSetupGame_setNetworkServerText();
10385 void DumpScreenIdentifiers(void)
10389 Print("Active screen elements on current screen:\n");
10391 for (i = 0; main_controls[i].nr != -1; i++)
10393 struct MainControlInfo *mci = &main_controls[i];
10395 if (mci->button_graphic != -1)
10397 char *token = getTokenFromImageID(mci->button_graphic);
10399 Print("- '%s'\n", token);
10406 boolean DoScreenAction(int image_id)
10410 if (game_status != GAME_MODE_MAIN)
10413 for (i = 0; main_controls[i].nr != -1; i++)
10415 struct MainControlInfo *mci = &main_controls[i];
10416 struct MenuPosInfo *pos = mci->pos_button;
10418 if (mci->button_graphic == image_id)
10420 int x = mSX + pos->x;
10421 int y = mSY + pos->y;
10423 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10432 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10434 // get tree info node of newly added level or artwork set
10435 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10436 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10438 if (tree_node_new == NULL) // should not happen
10441 // if request dialog is active, do nothing
10442 if (game.request_active)
10445 if (game_status == GAME_MODE_MAIN &&
10446 tree_type == TREE_TYPE_LEVEL_DIR)
10448 // when adding new level set in main menu, select it as current level set
10450 // change current level set to newly added level set from zip file
10451 leveldir_current = tree_node_new;
10453 // change current level number to first level of newly added level set
10454 level_nr = leveldir_current->first_level;
10456 // redraw screen to reflect changed level set
10459 // save this level set and level number as last selected level set
10460 SaveLevelSetup_LastSeries();
10461 SaveLevelSetup_SeriesInfo();
10463 else if (game_status == GAME_MODE_LEVELS &&
10464 tree_type == TREE_TYPE_LEVEL_DIR)
10466 // when adding new level set in level set menu, set cursor and update screen
10468 leveldir_current = tree_node_new;
10470 DrawChooseTree(&leveldir_current);
10472 else if (game_status == GAME_MODE_SETUP)
10474 // when adding new artwork set in setup menu, set cursor and update screen
10476 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10477 tree_type == TREE_TYPE_GRAPHICS_DIR)
10479 artwork.gfx_current = tree_node_new;
10481 DrawChooseTree(&artwork.gfx_current);
10483 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10484 tree_type == TREE_TYPE_SOUNDS_DIR)
10486 artwork.snd_current = tree_node_new;
10488 DrawChooseTree(&artwork.snd_current);
10490 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10491 tree_type == TREE_TYPE_MUSIC_DIR)
10493 artwork.mus_current = tree_node_new;
10495 DrawChooseTree(&artwork.mus_current);
10500 static int UploadTapes(void)
10502 SetGameStatus(GAME_MODE_LOADING);
10504 FadeSetEnterScreen();
10505 FadeOut(REDRAW_ALL);
10507 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10509 FadeIn(REDRAW_ALL);
10511 DrawInitTextHead("Uploading tapes");
10513 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10514 global.autoplay_leveldir = "ALL";
10515 global.autoplay_all = TRUE;
10517 int num_tapes_uploaded = AutoPlayTapes();
10519 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10520 global.autoplay_leveldir = NULL;
10521 global.autoplay_all = FALSE;
10523 SetGameStatus(GAME_MODE_MAIN);
10527 return num_tapes_uploaded;
10530 static boolean OfferUploadTapes(void)
10532 if (!Request(setup.has_remaining_tapes ?
10533 "Upload missing tapes to the high score server now?" :
10534 "Upload all your tapes to the high score server now?", REQ_ASK))
10537 int num_tapes_uploaded = UploadTapes();
10540 if (num_tapes_uploaded < 0)
10542 num_tapes_uploaded = -num_tapes_uploaded - 1;
10544 if (num_tapes_uploaded == 0)
10545 sprintf(message, "Upload failed! No tapes uploaded!");
10546 else if (num_tapes_uploaded == 1)
10547 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10549 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10550 num_tapes_uploaded);
10552 Request(message, REQ_CONFIRM);
10554 // if uploading tapes failed, add tape upload entry to setup menu
10555 setup.provide_uploading_tapes = TRUE;
10556 setup.has_remaining_tapes = TRUE;
10558 SaveSetup_ServerSetup();
10563 if (num_tapes_uploaded == 0)
10564 sprintf(message, "No tapes uploaded!");
10565 else if (num_tapes_uploaded == 1)
10566 sprintf(message, "1 tape uploaded!");
10568 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10570 Request(message, REQ_CONFIRM);
10572 if (num_tapes_uploaded > 0)
10573 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10575 // after all tapes have been uploaded, remove entry from setup menu
10576 setup.provide_uploading_tapes = FALSE;
10577 setup.has_remaining_tapes = FALSE;
10579 SaveSetup_ServerSetup();
10584 static void CheckUploadTapes(void)
10586 if (!setup.ask_for_uploading_tapes)
10589 // after asking for uploading tapes, do not ask again
10590 setup.ask_for_uploading_tapes = FALSE;
10591 setup.ask_for_remaining_tapes = FALSE;
10593 if (directoryExists(getTapeDir(NULL)))
10595 boolean tapes_uploaded = OfferUploadTapes();
10597 if (!tapes_uploaded)
10599 Request(setup.has_remaining_tapes ?
10600 "You can upload missing tapes from the setup menu later!" :
10601 "You can upload your tapes from the setup menu later!",
10607 // if tapes directory does not exist yet, never offer uploading all tapes
10608 setup.provide_uploading_tapes = FALSE;
10611 SaveSetup_ServerSetup();
10614 static void UpgradePlayerUUID(void)
10616 ApiResetUUIDAsThread(getUUID());
10619 static void CheckUpgradePlayerUUID(void)
10621 if (setup.player_version > 1)
10624 UpgradePlayerUUID();
10627 void CheckApiServerTasks(void)
10629 // check if the player's UUID has to be upgraded
10630 CheckUpgradePlayerUUID();
10632 // check if there are any tapes to be uploaded
10633 CheckUploadTapes();