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 DrawScoreInfo(int);
266 static void DrawInfoScreen(void);
267 static void DrawSetupScreen(void);
268 static void DrawTypeName(void);
270 static void DrawInfoScreen_NotAvailable(char *, char *);
271 static void DrawInfoScreen_HelpAnim(int, int, boolean);
272 static void DrawInfoScreen_HelpText(int, int, int, int);
273 static void HandleInfoScreen_Main(int, int, int, int, int);
274 static void HandleInfoScreen_TitleScreen(int);
275 static void HandleInfoScreen_Elements(int);
276 static void HandleInfoScreen_Music(int);
277 static void HandleInfoScreen_Credits(int);
278 static void HandleInfoScreen_Program(int);
279 static void HandleInfoScreen_Version(int);
281 static void ModifyGameSpeedIfNeeded(void);
282 static void DisableVsyncIfNeeded(void);
284 static void RedrawScreenMenuGadgets(int);
285 static void MapScreenMenuGadgets(int);
286 static void UnmapScreenMenuGadgets(int);
287 static void MapScreenGadgets(int);
288 static void UnmapScreenGadgets(void);
289 static void MapScreenTreeGadgets(TreeInfo *);
290 static void UnmapScreenTreeGadgets(void);
292 static void UpdateScreenMenuGadgets(int, boolean);
294 static boolean OfferUploadTapes(void);
295 static void execOfferUploadTapes(void);
297 static void DrawHallOfFame_setScoreEntries(void);
298 static void HandleHallOfFame_SelectLevel(int, int);
299 static char *getHallOfFameScoreText(int);
301 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
303 static int info_mode = INFO_MODE_MAIN;
304 static int setup_mode = SETUP_MODE_MAIN;
306 static TreeInfo *window_sizes = NULL;
307 static TreeInfo *window_size_current = NULL;
309 static TreeInfo *scaling_types = NULL;
310 static TreeInfo *scaling_type_current = NULL;
312 static TreeInfo *rendering_modes = NULL;
313 static TreeInfo *rendering_mode_current = NULL;
315 static TreeInfo *vsync_modes = NULL;
316 static TreeInfo *vsync_mode_current = NULL;
318 static TreeInfo *scroll_delays = NULL;
319 static TreeInfo *scroll_delay_current = NULL;
321 static TreeInfo *snapshot_modes = NULL;
322 static TreeInfo *snapshot_mode_current = NULL;
324 static TreeInfo *scores_types = NULL;
325 static TreeInfo *scores_type_current = NULL;
327 static TreeInfo *game_speeds_normal = NULL;
328 static TreeInfo *game_speeds_extended = NULL;
329 static TreeInfo *game_speeds = NULL;
330 static TreeInfo *game_speed_current = NULL;
332 static TreeInfo *volumes_simple = NULL;
333 static TreeInfo *volume_simple_current = NULL;
335 static TreeInfo *volumes_loops = NULL;
336 static TreeInfo *volume_loops_current = NULL;
338 static TreeInfo *volumes_music = NULL;
339 static TreeInfo *volume_music_current = NULL;
341 static TreeInfo *touch_controls = NULL;
342 static TreeInfo *touch_control_current = NULL;
344 static TreeInfo *move_distances = NULL;
345 static TreeInfo *move_distance_current = NULL;
347 static TreeInfo *drop_distances = NULL;
348 static TreeInfo *drop_distance_current = NULL;
350 static TreeInfo *transparencies = NULL;
351 static TreeInfo *transparency_current = NULL;
353 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
354 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
356 static TreeInfo *player_name = NULL;
357 static TreeInfo *player_name_current = NULL;
359 static TreeInfo *level_number = NULL;
360 static TreeInfo *level_number_current = NULL;
362 static TreeInfo *score_entries = NULL;
363 static TreeInfo *score_entry_current = NULL;
365 static struct ValueTextInfo window_sizes_list[] =
370 { 100, "100 % (Default)" },
383 static struct StringValueTextInfo scaling_types_list[] =
385 { SCALING_QUALITY_NEAREST, "Off" },
386 { SCALING_QUALITY_LINEAR, "Linear" },
387 { SCALING_QUALITY_BEST, "Anisotropic" },
392 static struct StringValueTextInfo rendering_modes_list[] =
394 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
395 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
397 // this mode may work under certain conditions, but does not work on Windows
398 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
400 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
405 static struct StringValueTextInfo vsync_modes_list[] =
407 { STR_VSYNC_MODE_OFF, "Off" },
408 { STR_VSYNC_MODE_NORMAL, "Normal" },
409 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
414 static struct StringValueTextInfo scores_types_list[] =
416 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
417 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
418 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
423 static struct ValueTextInfo game_speeds_list_normal[] =
434 static struct ValueTextInfo game_speeds_list_extended[] =
436 { 1000, "1 fps (Extremely Slow)" },
441 { 29, "35 fps (Original Supaplex)" },
443 { 20, "50 fps (=== Normal Speed ===)" },
444 { 16, "60 fps (60 Hz VSync Speed)" },
445 { 14, "70 fps (Maximum Supaplex)" },
449 { 1, "1000 fps (Extremely Fast)" },
454 static struct ValueTextInfo *game_speeds_list;
456 static struct ValueTextInfo scroll_delays_list[] =
458 { 0, "0 Tiles (No Scroll Delay)" },
461 { 3, "3 Tiles (Default)" },
466 { 8, "8 Tiles (Maximum Scroll Delay)"},
471 static struct StringValueTextInfo snapshot_modes_list[] =
473 { STR_SNAPSHOT_MODE_OFF, "Off" },
474 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
475 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
476 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
481 static struct ValueTextInfo volumes_list[] =
501 static struct StringValueTextInfo touch_controls_list[] =
503 { TOUCH_CONTROL_OFF, "Off" },
504 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
505 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
506 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
511 static struct ValueTextInfo distances_list[] =
526 static struct ValueTextInfo transparencies_list[] =
528 { 0, "0 % (Opaque)" },
538 { 100, "100 % (Invisible)" },
543 static struct ValueTextInfo grid_sizes_list[] =
579 static int align_xoffset = 0;
580 static int align_yoffset = 0;
582 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
583 (s) <= GAME_MODE_SETUP ? (s) : \
584 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
586 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
587 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
589 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
590 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
591 (i) <= INFO_MODE_LEVELSET ? (i) : \
594 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
595 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
596 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
597 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
598 SETUP_MODE_CHOOSE_ARTWORK : \
599 SETUP_MODE_CHOOSE_OTHER)
601 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
602 menu.draw_xoffset[GAME_MODE_INFO] : \
603 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
604 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
605 menu.draw_yoffset[GAME_MODE_INFO] : \
606 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
607 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
608 menu.extra_spacing[GAME_MODE_INFO] : \
609 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
611 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
612 menu.draw_xoffset[GAME_MODE_SETUP] : \
613 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
614 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
615 menu.draw_yoffset[GAME_MODE_SETUP] : \
616 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
617 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
618 menu.extra_spacing[GAME_MODE_SETUP] : \
619 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
621 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
623 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
625 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
626 DRAW_XOFFSET_INFO(info_mode) : \
627 (s) == GAME_MODE_SETUP ? \
628 DRAW_XOFFSET_SETUP(setup_mode) : \
629 menu.draw_xoffset[DRAW_MODE(s)])
630 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
631 DRAW_YOFFSET_INFO(info_mode) : \
632 (s) == GAME_MODE_SETUP ? \
633 DRAW_YOFFSET_SETUP(setup_mode) : \
634 menu.draw_yoffset[DRAW_MODE(s)])
635 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
636 EXTRA_SPACING_INFO(info_mode) : \
637 (s) == GAME_MODE_SETUP ? \
638 EXTRA_SPACING_SETUP(setup_mode) : \
639 (s) == GAME_MODE_SCORES ? \
640 EXTRA_SPACING_SCORES(info_mode) : \
641 menu.extra_spacing[DRAW_MODE(s)])
643 #define mSX (SX + DRAW_XOFFSET(game_status))
644 #define mSY (SY + DRAW_YOFFSET(game_status))
646 #define amSX (mSX + align_xoffset)
647 #define amSY (mSY + align_yoffset)
649 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
650 menu.list_size[game_status] : \
651 MAX_MENU_ENTRIES_ON_SCREEN)
653 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
654 NUM_MENU_ENTRIES_ON_SCREEN)
657 // title display and control definitions
659 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
660 2 * MAX_NUM_TITLE_MESSAGES)
662 #define NO_DIRECT_LEVEL_SELECT (-1)
665 static int num_title_screens = 0;
667 struct TitleControlInfo
676 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
678 // main menu display and control definitions
680 #define MAIN_CONTROL_NAME 0
681 #define MAIN_CONTROL_LEVELS 1
682 #define MAIN_CONTROL_SCORES 2
683 #define MAIN_CONTROL_EDITOR 3
684 #define MAIN_CONTROL_INFO 4
685 #define MAIN_CONTROL_GAME 5
686 #define MAIN_CONTROL_SETUP 6
687 #define MAIN_CONTROL_QUIT 7
688 #define MAIN_CONTROL_PREV_LEVEL 8
689 #define MAIN_CONTROL_NEXT_LEVEL 9
690 #define MAIN_CONTROL_FIRST_LEVEL 10
691 #define MAIN_CONTROL_LAST_LEVEL 11
692 #define MAIN_CONTROL_LEVEL_NUMBER 12
693 #define MAIN_CONTROL_LEVEL_INFO_1 13
694 #define MAIN_CONTROL_LEVEL_INFO_2 14
695 #define MAIN_CONTROL_LEVEL_NAME 15
696 #define MAIN_CONTROL_LEVEL_AUTHOR 16
697 #define MAIN_CONTROL_LEVEL_YEAR 17
698 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
699 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
700 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
701 #define MAIN_CONTROL_TITLE_1 21
702 #define MAIN_CONTROL_TITLE_2 22
703 #define MAIN_CONTROL_TITLE_3 23
705 static char str_main_text_name[10];
706 static char str_main_text_first_level[10];
707 static char str_main_text_last_level[10];
708 static char str_main_text_level_number[10];
710 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
712 static char *main_text_name = str_main_text_name;
713 static char *main_text_first_level = str_main_text_first_level;
714 static char *main_text_last_level = str_main_text_last_level;
715 static char *main_text_level_number = str_main_text_level_number;
716 static char *main_text_levels = "Levelset";
717 static char *main_text_scores = "Hall Of Fame";
718 static char *main_text_editor = "Level Creator";
719 static char *main_text_info = "Info Screen";
720 static char *main_text_game = "Start Game";
721 static char *main_text_setup = "Setup";
722 static char *main_text_quit = "Quit";
723 static char *main_text_level_name = level.name;
724 static char *main_text_level_author = level.author;
725 static char *main_text_level_year = NULL;
726 static char *main_text_level_imported_from = NULL;
727 static char *main_text_level_imported_by = NULL;
728 static char *main_text_level_tested_by = NULL;
729 static char *main_text_title_1 = NULL;
730 static char *main_text_title_2 = NULL;
731 static char *main_text_title_3 = NULL;
733 extern char debug_xsn_mode[];
735 struct MainControlInfo
739 struct MenuPosInfo *pos_button;
742 struct TextPosInfo *pos_text;
745 struct TextPosInfo *pos_input;
749 static struct MainControlInfo main_controls[] =
753 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
754 &menu.main.text.name, &main_text_name,
755 &menu.main.input.name, &setup.player_name,
759 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
760 &menu.main.text.levels, &main_text_levels,
765 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
766 &menu.main.text.scores, &main_text_scores,
771 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
772 &menu.main.text.editor, &main_text_editor,
777 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
778 &menu.main.text.info, &main_text_info,
783 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
784 &menu.main.text.game, &main_text_game,
789 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
790 &menu.main.text.setup, &main_text_setup,
795 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
796 &menu.main.text.quit, &main_text_quit,
800 MAIN_CONTROL_PREV_LEVEL,
806 MAIN_CONTROL_NEXT_LEVEL,
812 MAIN_CONTROL_FIRST_LEVEL,
814 &menu.main.text.first_level, &main_text_first_level,
818 MAIN_CONTROL_LAST_LEVEL,
820 &menu.main.text.last_level, &main_text_last_level,
824 MAIN_CONTROL_LEVEL_NUMBER,
826 &menu.main.text.level_number, &main_text_level_number,
830 MAIN_CONTROL_LEVEL_INFO_1,
832 &menu.main.text.level_info_1, NULL,
836 MAIN_CONTROL_LEVEL_INFO_2,
838 &menu.main.text.level_info_2, NULL,
842 MAIN_CONTROL_LEVEL_NAME,
844 &menu.main.text.level_name, &main_text_level_name,
848 MAIN_CONTROL_LEVEL_AUTHOR,
850 &menu.main.text.level_author, &main_text_level_author,
854 MAIN_CONTROL_LEVEL_YEAR,
856 &menu.main.text.level_year, &main_text_level_year,
860 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
862 &menu.main.text.level_imported_from, &main_text_level_imported_from,
866 MAIN_CONTROL_LEVEL_IMPORTED_BY,
868 &menu.main.text.level_imported_by, &main_text_level_imported_by,
872 MAIN_CONTROL_LEVEL_TESTED_BY,
874 &menu.main.text.level_tested_by, &main_text_level_tested_by,
878 MAIN_CONTROL_TITLE_1,
880 &menu.main.text.title_1, &main_text_title_1,
884 MAIN_CONTROL_TITLE_2,
886 &menu.main.text.title_2, &main_text_title_2,
890 MAIN_CONTROL_TITLE_3,
892 &menu.main.text.title_3, &main_text_title_3,
905 static int getTitleScreenGraphic(int nr, boolean initial)
907 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
910 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
912 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
916 static int getTitleScreenGameMode(boolean initial)
918 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
922 static int getTitleMessageGameMode(boolean initial)
924 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
927 static int getTitleAnimMode(struct TitleControlInfo *tci)
929 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
931 return base + tci->local_nr;
935 static int getTitleScreenBackground(boolean initial)
937 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
942 static int getTitleMessageBackground(int nr, boolean initial)
944 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
948 static int getTitleBackground(int nr, boolean initial, boolean is_image)
950 int base = (is_image ?
951 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
952 IMG_BACKGROUND_TITLESCREEN_1) :
953 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
954 IMG_BACKGROUND_TITLEMESSAGE_1));
955 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
956 IMG_BACKGROUND_TITLE);
957 int graphic_local = base + nr;
959 if (graphic_info[graphic_local].bitmap != NULL)
960 return graphic_local;
962 if (graphic_info[graphic_global].bitmap != NULL)
963 return graphic_global;
965 return IMG_UNDEFINED;
968 static int getTitleSound(struct TitleControlInfo *tci)
970 boolean is_image = tci->is_image;
971 int initial = tci->initial;
972 int nr = tci->local_nr;
973 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
974 int base = (is_image ?
975 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
976 SND_BACKGROUND_TITLESCREEN_1) :
977 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
978 SND_BACKGROUND_TITLEMESSAGE_1));
979 int sound_global = menu.sound[mode];
980 int sound_local = base + nr;
983 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
984 nr, initial, is_image,
985 sound_global, getSoundListEntry(sound_global)->filename,
986 sound_local, getSoundListEntry(sound_local)->filename);
989 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
992 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
995 return SND_UNDEFINED;
998 static int getTitleMusic(struct TitleControlInfo *tci)
1000 boolean is_image = tci->is_image;
1001 int initial = tci->initial;
1002 int nr = tci->local_nr;
1003 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1004 int base = (is_image ?
1005 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1006 MUS_BACKGROUND_TITLESCREEN_1) :
1007 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1008 MUS_BACKGROUND_TITLEMESSAGE_1));
1009 int music_global = menu.music[mode];
1010 int music_local = base + nr;
1013 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1014 nr, initial, is_image,
1015 music_global, getMusicListEntry(music_global)->filename,
1016 music_local, getMusicListEntry(music_local)->filename);
1019 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1022 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1023 return music_global;
1025 return MUS_UNDEFINED;
1028 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1030 boolean is_image = tci->is_image;
1031 boolean initial = tci->initial;
1032 boolean first = tci->first;
1033 int nr = tci->local_nr;
1034 struct TitleMessageInfo tmi;
1035 struct TitleFadingInfo ti;
1037 tmi = (is_image ? (initial ? (first ?
1038 titlescreen_initial_first[nr] :
1039 titlescreen_initial[nr])
1041 titlescreen_first[nr] :
1043 : (initial ? (first ?
1044 titlemessage_initial_first[nr] :
1045 titlemessage_initial[nr])
1047 titlemessage_first[nr] :
1048 titlemessage[nr])));
1050 ti.fade_mode = tmi.fade_mode;
1051 ti.fade_delay = tmi.fade_delay;
1052 ti.post_delay = tmi.post_delay;
1053 ti.auto_delay = tmi.auto_delay;
1054 ti.auto_delay_unit = tmi.auto_delay_unit;
1059 static int compareTitleControlInfo(const void *object1, const void *object2)
1061 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1062 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1065 if (tci1->initial != tci2->initial)
1066 compare_result = (tci1->initial ? -1 : +1);
1067 else if (tci1->sort_priority != tci2->sort_priority)
1068 compare_result = tci1->sort_priority - tci2->sort_priority;
1069 else if (tci1->is_image != tci2->is_image)
1070 compare_result = (tci1->is_image ? -1 : +1);
1072 compare_result = tci1->local_nr - tci2->local_nr;
1074 return compare_result;
1077 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1079 int nr, int sort_priority)
1081 title_controls[num_title_screens].is_image = is_image;
1082 title_controls[num_title_screens].initial = initial;
1083 title_controls[num_title_screens].local_nr = nr;
1084 title_controls[num_title_screens].sort_priority = sort_priority;
1086 title_controls[num_title_screens].first = FALSE; // will be set later
1088 num_title_screens++;
1091 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1095 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1097 int graphic = getTitleScreenGraphic(i, initial);
1098 Bitmap *bitmap = graphic_info[graphic].bitmap;
1099 int sort_priority = graphic_info[graphic].sort_priority;
1102 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1105 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1107 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1108 char *filename = getLevelSetTitleMessageFilename(i, initial);
1109 int sort_priority = tmi->sort_priority;
1111 if (filename != NULL)
1112 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1116 static void InitializeTitleControls(boolean show_title_initial)
1118 num_title_screens = 0;
1120 // 1st step: initialize title screens for game start (only when starting)
1121 if (show_title_initial)
1122 InitializeTitleControls_CheckTitleInfo(TRUE);
1124 // 2nd step: initialize title screens for current level set
1125 InitializeTitleControls_CheckTitleInfo(FALSE);
1127 // sort title screens according to sort_priority and title number
1128 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1129 compareTitleControlInfo);
1131 // mark first title screen
1132 title_controls[0].first = TRUE;
1135 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1137 return (pos != NULL && pos->x != -1 && pos->y != -1);
1140 static boolean visibleTextPos(struct TextPosInfo *pos)
1142 return (pos != NULL && pos->x != -1 && pos->y != -1);
1145 static void InitializeMainControls(void)
1147 boolean local_team_mode = (!network.enabled && setup.team_mode);
1150 // set main control text values to dynamically determined values
1151 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1153 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1154 menu.main.text.first_level.size));
1155 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1156 menu.main.text.last_level.size));
1157 strcpy(main_text_level_number, int2str(level_nr,
1158 menu.main.text.level_number.size));
1160 main_text_level_year = leveldir_current->year;
1161 main_text_level_imported_from = leveldir_current->imported_from;
1162 main_text_level_imported_by = leveldir_current->imported_by;
1163 main_text_level_tested_by = leveldir_current->tested_by;
1165 main_text_title_1 = getConfigProgramTitleString();
1166 main_text_title_2 = getConfigProgramCopyrightString();
1167 main_text_title_3 = getConfigProgramCompanyString();
1169 // set main control screen positions to dynamically determined values
1170 for (i = 0; main_controls[i].nr != -1; i++)
1172 struct MainControlInfo *mci = &main_controls[i];
1174 struct MenuPosInfo *pos_button = mci->pos_button;
1175 struct TextPosInfo *pos_text = mci->pos_text;
1176 struct TextPosInfo *pos_input = mci->pos_input;
1177 char *text = (mci->text ? *mci->text : NULL);
1178 char *input = (mci->input ? *mci->input : NULL);
1179 int button_graphic = mci->button_graphic;
1180 int font_text = (pos_text ? pos_text->font : -1);
1181 int font_input = (pos_input ? pos_input->font : -1);
1183 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1184 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1185 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1186 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1187 int text_chars = (text != NULL ? strlen(text) : 0);
1188 int input_chars = (input != NULL ? strlen(input) : 0);
1191 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1193 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1194 int text_width = font_text_width * text_chars;
1195 int text_height = font_text_height;
1196 int input_width = font_input_width * input_chars;
1197 int input_height = font_input_height;
1199 if (nr == MAIN_CONTROL_NAME)
1201 menu.main.input.name.width = input_width;
1202 menu.main.input.name.height = input_height;
1205 if (pos_button != NULL) // (x/y may be -1/-1 here)
1207 pos_button->width = button_width;
1208 pos_button->height = button_height;
1211 if (pos_text != NULL) // (x/y may be -1/-1 here)
1213 // calculate text size -- needed for text alignment
1214 boolean calculate_text_size = (text != NULL);
1216 if (pos_text->width == -1 || calculate_text_size)
1217 pos_text->width = text_width;
1218 if (pos_text->height == -1 || calculate_text_size)
1219 pos_text->height = text_height;
1221 if (visibleMenuPos(pos_button))
1223 if (pos_text->x == -1)
1224 pos_text->x = pos_button->x + pos_button->width;
1225 if (pos_text->y == -1)
1227 pos_button->y + (pos_button->height - pos_text->height) / 2;
1231 if (pos_input != NULL) // (x/y may be -1/-1 here)
1233 if (visibleTextPos(pos_text))
1235 if (pos_input->x == -1)
1236 pos_input->x = pos_text->x + pos_text->width;
1237 if (pos_input->y == -1)
1238 pos_input->y = pos_text->y;
1241 if (pos_input->width == -1)
1242 pos_input->width = input_width;
1243 if (pos_input->height == -1)
1244 pos_input->height = input_height;
1249 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1250 int graphic, boolean pressed)
1252 struct GraphicInfo *g = &graphic_info[graphic];
1255 int xoffset = (pressed ? g->pressed_xoffset : 0);
1256 int yoffset = (pressed ? g->pressed_yoffset : 0);
1258 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1260 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1261 g->width, g->height, dst_x, dst_y);
1264 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1265 boolean active_input,
1266 boolean pressed_button)
1270 for (i = 0; main_controls[i].nr != -1; i++)
1272 struct MainControlInfo *mci = &main_controls[i];
1274 if (mci->nr == nr || nr == -1)
1276 struct MenuPosInfo *pos_button = mci->pos_button;
1277 struct TextPosInfo *pos_text = mci->pos_text;
1278 struct TextPosInfo *pos_input = mci->pos_input;
1279 char *text = (mci->text ? *mci->text : NULL);
1280 char *input = (mci->input ? *mci->input : NULL);
1281 int button_graphic = mci->button_graphic;
1282 int font_text = (pos_text ? pos_text->font : -1);
1283 int font_input = (pos_input ? pos_input->font : -1);
1287 button_graphic = BUTTON_ACTIVE(button_graphic);
1288 font_text = FONT_ACTIVE(font_text);
1293 font_input = FONT_ACTIVE(font_input);
1296 if (visibleMenuPos(pos_button))
1298 struct MenuPosInfo *pos = pos_button;
1299 int x = mSX + pos->x;
1300 int y = mSY + pos->y;
1302 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1303 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1306 if (visibleTextPos(pos_text) && text != NULL)
1308 struct TextPosInfo *pos = pos_text;
1309 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1310 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1313 // (check why/if this is needed)
1314 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1316 DrawText(x, y, text, font_text);
1319 if (visibleTextPos(pos_input) && input != NULL)
1321 struct TextPosInfo *pos = pos_input;
1322 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1323 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1326 // (check why/if this is needed)
1327 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1329 DrawText(x, y, input, font_input);
1335 static void DrawCursorAndText_Main(int nr, boolean active_text,
1336 boolean pressed_button)
1338 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1342 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1343 boolean pressed_button)
1345 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1349 static struct MainControlInfo *getMainControlInfo(int nr)
1353 for (i = 0; main_controls[i].nr != -1; i++)
1354 if (main_controls[i].nr == nr)
1355 return &main_controls[i];
1360 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1365 int rect_x = ALIGNED_TEXT_XPOS(rect);
1366 int rect_y = ALIGNED_TEXT_YPOS(rect);
1368 return (x >= rect_x && x < rect_x + rect->width &&
1369 y >= rect_y && y < rect_y + rect->height);
1372 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1377 int rect_x = ALIGNED_TEXT_XPOS(rect);
1378 int rect_y = ALIGNED_TEXT_YPOS(rect);
1381 Debug("screens:insideTextPosRect",
1382 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1383 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1384 (x >= rect_x && x < rect_x + rect->width &&
1385 y >= rect_y && y < rect_y + rect->height));
1388 return (x >= rect_x && x < rect_x + rect->width &&
1389 y >= rect_y && y < rect_y + rect->height);
1392 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1394 int rect_width = preview->xsize * preview->tile_size;
1395 int rect_height = preview->ysize * preview->tile_size;
1396 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1397 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1399 return (x >= rect_x && x < rect_x + rect_width &&
1400 y >= rect_y && y < rect_y + rect_height);
1403 static void AdjustScrollbar(int id, int items_max, int items_visible,
1406 struct GadgetInfo *gi = screen_gadget[id];
1408 if (item_position > items_max - items_visible)
1409 item_position = items_max - items_visible;
1411 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1412 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1413 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1416 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1418 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1422 static void clearMenuListArea(void)
1424 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1426 // correct scrollbar position if placed outside menu (playfield) area
1427 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1428 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1430 // clear menu list area, but not title or scrollbar
1431 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1432 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1435 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1437 static int cursor_array[MAX_LEV_FIELDY];
1438 int x = amSX + TILEX * xpos;
1439 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1444 cursor_array[ypos] = graphic;
1446 graphic = cursor_array[ypos];
1450 graphic = BUTTON_ACTIVE(graphic);
1452 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1453 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1456 static void initCursor(int ypos, int graphic)
1458 drawCursorExt(0, ypos, FALSE, graphic);
1461 static void drawCursor(int ypos, boolean active)
1463 drawCursorExt(0, ypos, active, -1);
1466 static void drawCursorXY(int xpos, int ypos, int graphic)
1468 drawCursorExt(xpos, ypos, FALSE, graphic);
1471 static void drawChooseTreeCursor(int ypos, boolean active)
1473 drawCursorExt(0, ypos, active, -1);
1476 static int getChooseTreeEditFont(boolean active)
1478 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1481 static int getChooseTreeEditXPos(int pos)
1483 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1484 int xoffset = (has_scrollbar ? -1 : 0);
1485 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1486 int sx = amSX + xpos * TILEX;
1487 int font_nr = getChooseTreeEditFont(FALSE);
1488 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1490 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1493 static int getChooseTreeEditYPos(int ypos_raw)
1495 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1496 int sy = amSY + ypos * TILEY;
1501 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1503 int sx = getChooseTreeEditXPos(POS_LEFT);
1504 int sy = getChooseTreeEditYPos(ypos_raw);
1505 int font_nr = getChooseTreeEditFont(active);
1507 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1510 static void DrawHeadline(void)
1512 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1513 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1516 static void DrawTitleScreenImage(int nr, boolean initial)
1518 int graphic = getTitleScreenGraphic(nr, initial);
1519 Bitmap *bitmap = graphic_info[graphic].bitmap;
1520 int width = graphic_info[graphic].width;
1521 int height = graphic_info[graphic].height;
1522 int src_x = graphic_info[graphic].src_x;
1523 int src_y = graphic_info[graphic].src_y;
1529 if (width > WIN_XSIZE)
1531 // image width too large for window => center image horizontally
1532 src_x = (width - WIN_XSIZE) / 2;
1536 if (height > WIN_YSIZE)
1538 // image height too large for window => center image vertically
1539 src_y = (height - WIN_YSIZE) / 2;
1543 // always display title screens centered
1544 dst_x = (WIN_XSIZE - width) / 2;
1545 dst_y = (WIN_YSIZE - height) / 2;
1547 SetDrawBackgroundMask(REDRAW_ALL);
1548 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1550 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1552 if (DrawingOnBackground(dst_x, dst_y))
1553 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1555 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1557 redraw_mask = REDRAW_ALL;
1560 static void DrawTitleScreenMessage(int nr, boolean initial)
1562 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1563 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1565 if (filename == NULL)
1568 // force TITLE font on title message screen
1569 SetFontStatus(getTitleMessageGameMode(initial));
1571 // if chars *and* width set to "-1", automatically determine width
1572 if (tmi->chars == -1 && tmi->width == -1)
1573 tmi->width = viewport.window[game_status].width;
1575 // if lines *and* height set to "-1", automatically determine height
1576 if (tmi->lines == -1 && tmi->height == -1)
1577 tmi->height = viewport.window[game_status].height;
1579 // if chars set to "-1", automatically determine by text and font width
1580 if (tmi->chars == -1)
1581 tmi->chars = tmi->width / getFontWidth(tmi->font);
1583 tmi->width = tmi->chars * getFontWidth(tmi->font);
1585 // if lines set to "-1", automatically determine by text and font height
1586 if (tmi->lines == -1)
1587 tmi->lines = tmi->height / getFontHeight(tmi->font);
1589 tmi->height = tmi->lines * getFontHeight(tmi->font);
1591 // if x set to "-1", automatically determine by width and alignment
1593 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1595 // if y set to "-1", automatically determine by height and alignment
1597 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1599 SetDrawBackgroundMask(REDRAW_ALL);
1600 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1602 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1604 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1605 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1606 tmi->autowrap, tmi->centered, tmi->parse_comments);
1611 static void DrawTitleScreen(void)
1613 KeyboardAutoRepeatOff();
1615 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1618 static boolean CheckTitleScreen(boolean levelset_has_changed)
1620 static boolean show_title_initial = TRUE;
1621 boolean show_titlescreen = FALSE;
1623 // needed to be able to skip title screen, if no image or message defined
1624 InitializeTitleControls(show_title_initial);
1626 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1627 show_titlescreen = TRUE;
1629 // show initial title images and messages only once at program start
1630 show_title_initial = FALSE;
1632 return (show_titlescreen && num_title_screens > 0);
1635 void DrawMainMenu(void)
1637 static LevelDirTree *leveldir_last_valid = NULL;
1638 boolean levelset_has_changed = FALSE;
1639 int fade_mask = REDRAW_FIELD;
1641 LimitScreenUpdates(FALSE);
1643 FadeSetLeaveScreen();
1645 // do not fade out here -- function may continue and fade on editor screen
1648 FadeMenuSoundsAndMusic();
1650 ExpireSoundLoops(FALSE);
1652 KeyboardAutoRepeatOn();
1654 audio.sound_deactivated = FALSE;
1658 // needed if last screen was the playing screen, invoked from level editor
1659 if (level_editor_test_game)
1661 CloseDoor(DOOR_CLOSE_ALL);
1663 SetGameStatus(GAME_MODE_EDITOR);
1670 // leveldir_current may be invalid (level group, parent link, node copy)
1671 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1673 if (leveldir_current != leveldir_last_valid)
1675 UpdateLastPlayedLevels_TreeInfo();
1677 levelset_has_changed = TRUE;
1680 // store valid level series information
1681 leveldir_last_valid = leveldir_current;
1683 init_last = init; // switch to new busy animation
1685 // needed if last screen (level choice) changed graphics, sounds or music
1686 ReloadCustomArtwork(0);
1688 if (CheckTitleScreen(levelset_has_changed))
1690 SetGameStatus(GAME_MODE_TITLE);
1697 if (redraw_mask & REDRAW_ALL)
1698 fade_mask = REDRAW_ALL;
1701 fade_mask = REDRAW_ALL;
1705 // needed if different viewport properties defined for menues
1706 ChangeViewportPropertiesIfNeeded();
1708 SetDrawtoField(DRAW_TO_BACKBUFFER);
1710 // level_nr may have been set to value over handicap with level editor
1711 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1712 level_nr = leveldir_current->handicap_level;
1714 LoadLevel(level_nr);
1715 LoadScore(level_nr);
1717 SaveLevelSetup_SeriesInfo();
1719 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1720 SetDrawDeactivationMask(REDRAW_NONE);
1721 SetDrawBackgroundMask(REDRAW_FIELD);
1723 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1726 if (fade_mask == REDRAW_ALL)
1727 RedrawGlobalBorder();
1732 InitializeMainControls();
1734 DrawCursorAndText_Main(-1, FALSE, FALSE);
1735 DrawPreviewLevelInitial();
1736 DrawNetworkPlayers();
1738 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1741 if (TAPE_IS_EMPTY(tape))
1743 DrawCompleteVideoDisplay();
1745 PlayMenuSoundsAndMusic();
1747 // create gadgets for main menu screen
1748 FreeScreenGadgets();
1749 CreateScreenGadgets();
1751 // may be required if audio buttons shown on tape and changed in setup menu
1753 CreateGameButtons();
1755 // map gadgets for main menu screen
1757 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1758 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1760 // copy actual game door content to door double buffer for OpenDoor()
1761 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1762 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1764 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1766 DrawMaskedBorder(fade_mask);
1771 // update screen area with special editor door
1772 redraw_mask |= REDRAW_ALL;
1775 SetMouseCursor(CURSOR_DEFAULT);
1777 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1779 SyncEmscriptenFilesystem();
1781 // needed once after program start or after user change
1782 CheckApiServerTasks();
1785 static void gotoTopLevelDir(void)
1787 // move upwards until inside (but not above) top level directory
1788 while (leveldir_current->node_parent &&
1789 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1791 // write a "path" into level tree for easy navigation to last level
1792 if (leveldir_current->node_parent->node_group->cl_first == -1)
1794 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1795 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1796 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1797 int cl_first, cl_cursor;
1799 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1800 cl_cursor = leveldir_pos - cl_first;
1802 leveldir_current->node_parent->node_group->cl_first = cl_first;
1803 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1806 leveldir_current = leveldir_current->node_parent;
1810 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1812 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1814 return (use_frame_counter ? video.frame_counter : Counter());
1817 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1818 struct TitleFadingInfo *fi)
1820 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1823 static void ResetTitleAutoDelay(unsigned int *counter_var,
1824 struct TitleFadingInfo *fi)
1826 *counter_var = getAutoDelayCounter(fi);
1829 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1831 static unsigned int title_delay = 0;
1832 static int title_screen_nr = 0;
1833 static int last_sound = -1, last_music = -1;
1834 boolean return_to_main_menu = FALSE;
1835 struct TitleControlInfo *tci;
1838 if (button == MB_MENU_INITIALIZE)
1841 title_screen_nr = 0;
1842 tci = &title_controls[title_screen_nr];
1844 SetAnimStatus(getTitleAnimMode(tci));
1846 last_sound = SND_UNDEFINED;
1847 last_music = MUS_UNDEFINED;
1849 if (num_title_screens != 0)
1851 FadeSetEnterScreen();
1853 // use individual title fading instead of global "enter screen" fading
1854 fading = getTitleFading(tci);
1857 if (game_status_last_screen == GAME_MODE_INFO)
1859 if (num_title_screens == 0)
1861 // switch game mode from title screen mode back to info screen mode
1862 SetGameStatus(GAME_MODE_INFO);
1864 // store that last screen was info screen, not main menu screen
1865 game_status_last_screen = GAME_MODE_INFO;
1867 DrawInfoScreen_NotAvailable("Title screen information:",
1868 "No title screen for this level set.");
1873 FadeMenuSoundsAndMusic();
1875 FadeOut(REDRAW_ALL);
1877 // title screens may have different window size
1878 ChangeViewportPropertiesIfNeeded();
1880 // only required to update logic for redrawing global border
1884 DrawTitleScreenImage(tci->local_nr, tci->initial);
1886 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1888 sound = getTitleSound(tci);
1889 music = getTitleMusic(tci);
1891 if (sound != last_sound)
1892 PlayMenuSoundExt(sound);
1893 if (music != last_music)
1894 PlayMenuMusicExt(music);
1899 SetMouseCursor(CURSOR_NONE);
1903 ResetTitleAutoDelay(&title_delay, &fading);
1908 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1909 button = MB_MENU_CHOICE;
1911 if (button == MB_MENU_LEAVE)
1913 return_to_main_menu = TRUE;
1915 else if (button == MB_MENU_CHOICE)
1917 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1919 SetGameStatus(GAME_MODE_INFO);
1921 info_mode = INFO_MODE_MAIN;
1930 if (title_screen_nr < num_title_screens)
1932 tci = &title_controls[title_screen_nr];
1934 SetAnimStatus(getTitleAnimMode(tci));
1936 sound = getTitleSound(tci);
1937 music = getTitleMusic(tci);
1939 if (last_sound != SND_UNDEFINED && sound != last_sound)
1940 FadeSound(last_sound);
1941 if (last_music != MUS_UNDEFINED && music != last_music)
1944 fading = getTitleFading(tci);
1946 FadeOut(REDRAW_ALL);
1949 DrawTitleScreenImage(tci->local_nr, tci->initial);
1951 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1953 sound = getTitleSound(tci);
1954 music = getTitleMusic(tci);
1956 if (sound != last_sound)
1957 PlayMenuSoundExt(sound);
1958 if (music != last_music)
1959 PlayMenuMusicExt(music);
1966 ResetTitleAutoDelay(&title_delay, &fading);
1970 FadeMenuSoundsAndMusic();
1972 return_to_main_menu = TRUE;
1976 if (return_to_main_menu)
1978 SetMouseCursor(CURSOR_DEFAULT);
1980 // force full menu screen redraw after displaying title screens
1981 redraw_mask = REDRAW_ALL;
1983 if (game_status_last_screen == GAME_MODE_INFO)
1985 SetGameStatus(GAME_MODE_INFO);
1987 info_mode = INFO_MODE_MAIN;
1991 else // default: return to main menu
1993 SetGameStatus(GAME_MODE_MAIN);
2000 static void HandleMainMenu_ToggleTeamMode(void)
2002 setup.team_mode = !setup.team_mode;
2004 InitializeMainControls();
2005 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2007 DrawPreviewPlayers();
2010 static void HandleMainMenu_SelectLevel(int step, int direction,
2011 int selected_level_nr)
2013 int old_level_nr = level_nr;
2016 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2017 new_level_nr = selected_level_nr;
2019 new_level_nr = old_level_nr + step * direction;
2021 if (new_level_nr < leveldir_current->first_level)
2022 new_level_nr = leveldir_current->first_level;
2023 if (new_level_nr > leveldir_current->last_level)
2024 new_level_nr = leveldir_current->last_level;
2026 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2028 // skipping levels is only allowed when trying to skip single level
2029 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2030 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2032 leveldir_current->handicap_level++;
2033 SaveLevelSetup_SeriesInfo();
2036 new_level_nr = leveldir_current->handicap_level;
2039 if (new_level_nr != old_level_nr)
2041 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2043 PlaySound(SND_MENU_ITEM_SELECTING);
2045 level_nr = new_level_nr;
2047 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2048 int2str(level_nr, menu.main.text.level_number.size),
2049 mci->pos_text->font);
2051 LoadLevel(level_nr);
2052 DrawPreviewLevelInitial();
2056 DrawCompleteVideoDisplay();
2058 SaveLevelSetup_SeriesInfo();
2060 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2062 // force redraw of playfield area (may be reset at this point)
2063 redraw_mask |= REDRAW_FIELD;
2067 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2069 static int choice = MAIN_CONTROL_GAME;
2070 static boolean button_pressed_last = FALSE;
2071 boolean button_pressed = FALSE;
2073 int i = 0; // needed to prevent compiler warning due to bad code below
2075 if (button == MB_MENU_INITIALIZE)
2077 DrawCursorAndText_Main(choice, TRUE, FALSE);
2082 if (mx || my) // mouse input
2086 for (i = 0; main_controls[i].nr != -1; i++)
2088 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2089 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2090 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2092 pos = main_controls[i].nr;
2098 // check if level preview was clicked
2099 if (insidePreviewRect(&preview, mx - SX, my - SY))
2100 pos = MAIN_CONTROL_GAME;
2102 // handle pressed/unpressed state for active/inactive menu buttons
2103 // (if pos != -1, "i" contains index position corresponding to "pos")
2105 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2106 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2107 button_pressed = TRUE;
2109 if (button_pressed != button_pressed_last)
2111 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2114 PlaySound(SND_MENU_BUTTON_PRESSING);
2116 PlaySound(SND_MENU_BUTTON_RELEASING);
2119 else if (dx || dy) // keyboard input
2121 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2122 choice == MAIN_CONTROL_SETUP))
2123 button = MB_MENU_CHOICE;
2128 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2130 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2132 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2134 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2136 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2138 CloseDoor(DOOR_CLOSE_2);
2140 SetGameStatus(GAME_MODE_LEVELNR);
2142 DrawChooseLevelNr();
2144 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2150 PlaySound(SND_MENU_ITEM_ACTIVATING);
2152 DrawCursorAndText_Main(choice, FALSE, FALSE);
2153 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2159 if (choice == MAIN_CONTROL_NAME)
2161 // special case: cursor left or right pressed -- toggle team mode
2162 HandleMainMenu_ToggleTeamMode();
2164 else if (choice != MAIN_CONTROL_INFO &&
2165 choice != MAIN_CONTROL_SETUP)
2167 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2173 PlaySound(SND_MENU_ITEM_SELECTING);
2175 if (pos == MAIN_CONTROL_NAME)
2178 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2180 // special case: menu text "name/team" clicked -- toggle team mode
2181 HandleMainMenu_ToggleTeamMode();
2185 if (setup.multiple_users)
2187 CloseDoor(DOOR_CLOSE_2);
2189 SetGameStatus(GAME_MODE_NAMES);
2191 DrawChoosePlayerName();
2195 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2201 else if (pos == MAIN_CONTROL_LEVELS)
2205 CloseDoor(DOOR_CLOSE_2);
2207 SetGameStatus(GAME_MODE_LEVELS);
2209 SaveLevelSetup_LastSeries();
2210 SaveLevelSetup_SeriesInfo();
2212 // restore level set if chosen from "last played level set" menu
2213 RestoreLastPlayedLevels(&leveldir_current);
2215 if (setup.internal.choose_from_top_leveldir)
2218 DrawChooseLevelSet();
2221 else if (pos == MAIN_CONTROL_SCORES)
2223 CloseDoor(DOOR_CLOSE_2);
2225 SetGameStatus(GAME_MODE_SCORES);
2227 DrawHallOfFame(level_nr);
2229 else if (pos == MAIN_CONTROL_EDITOR)
2231 if (leveldir_current->readonly &&
2232 setup.editor.show_read_only_warning)
2233 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2235 CloseDoor(DOOR_CLOSE_ALL);
2237 SetGameStatus(GAME_MODE_EDITOR);
2239 FadeSetEnterScreen();
2243 else if (pos == MAIN_CONTROL_INFO)
2245 CloseDoor(DOOR_CLOSE_2);
2247 SetGameStatus(GAME_MODE_INFO);
2249 info_mode = INFO_MODE_MAIN;
2253 else if (pos == MAIN_CONTROL_GAME)
2255 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2257 else if (pos == MAIN_CONTROL_SETUP)
2259 CloseDoor(DOOR_CLOSE_2);
2261 SetGameStatus(GAME_MODE_SETUP);
2263 setup_mode = SETUP_MODE_MAIN;
2267 else if (pos == MAIN_CONTROL_QUIT)
2269 SaveLevelSetup_LastSeries();
2270 SaveLevelSetup_SeriesInfo();
2272 #if defined(PLATFORM_EMSCRIPTEN)
2273 Request("Close the browser window to quit!", REQ_CONFIRM);
2275 if (!setup.ask_on_quit_program ||
2276 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2277 SetGameStatus(GAME_MODE_QUIT);
2283 button_pressed_last = button_pressed;
2287 // ============================================================================
2288 // info screen functions
2289 // ============================================================================
2291 static struct TokenInfo *info_info;
2292 static int num_info_info; // number of info entries shown on screen
2293 static int max_info_info; // total number of info entries in list
2295 static void execInfoTitleScreen(void)
2297 info_mode = INFO_MODE_TITLE;
2302 static void execInfoElements(void)
2304 info_mode = INFO_MODE_ELEMENTS;
2309 static void execInfoMusic(void)
2311 info_mode = INFO_MODE_MUSIC;
2316 static void execInfoCredits(void)
2318 info_mode = INFO_MODE_CREDITS;
2323 static void execInfoProgram(void)
2325 info_mode = INFO_MODE_PROGRAM;
2330 static void execInfoVersion(void)
2332 info_mode = INFO_MODE_VERSION;
2337 static void execInfoLevelSet(void)
2339 info_mode = INFO_MODE_LEVELSET;
2344 static void execExitInfo(void)
2346 SetGameStatus(GAME_MODE_MAIN);
2351 static struct TokenInfo info_info_main[] =
2353 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2354 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2355 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2356 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2357 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2358 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2359 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2360 { TYPE_EMPTY, NULL, "" },
2361 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2366 static int getMenuTextFont(int type)
2368 if (type & (TYPE_SWITCH |
2382 static struct TokenInfo *setup_info;
2383 static struct TokenInfo setup_info_input[];
2385 static struct TokenInfo *menu_info;
2387 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2388 int screen_pos, int menu_info_pos_raw,
2391 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2392 struct TokenInfo *ti = &token_info[pos];
2393 int xpos = MENU_SCREEN_START_XPOS;
2394 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2395 int font_nr = getMenuTextFont(ti->type);
2397 if (setup_mode == SETUP_MODE_INPUT)
2398 font_nr = FONT_MENU_1;
2401 font_nr = FONT_ACTIVE(font_nr);
2403 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2405 if (ti->type & ~TYPE_SKIP_ENTRY)
2406 drawCursor(screen_pos, active);
2409 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2412 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2415 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2418 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2421 static char *window_size_text;
2422 static char *scaling_type_text;
2423 static char *network_server_text;
2425 static void drawSetupValue(int, int);
2427 static void drawMenuInfoList(int first_entry, int num_page_entries,
2428 int max_page_entries)
2432 if (first_entry + num_page_entries > max_page_entries)
2435 clearMenuListArea();
2437 for (i = 0; i < num_page_entries; i++)
2439 int menu_info_pos = first_entry + i;
2440 struct TokenInfo *si = &menu_info[menu_info_pos];
2441 void *value_ptr = si->value;
2443 // set some entries to "unchangeable" according to other variables
2444 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2445 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2446 (value_ptr == &setup.sound_music && !audio.music_available) ||
2447 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2448 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2449 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2450 si->type |= TYPE_GHOSTED;
2452 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2453 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2454 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2455 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2456 else if (si->type & ~TYPE_SKIP_ENTRY)
2457 initCursor(i, IMG_MENU_BUTTON);
2459 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2461 if (si->type & TYPE_STRING)
2465 if (value_ptr == &network_server_text)
2466 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2468 if (gadget_id != -1)
2470 struct GadgetInfo *gi = screen_gadget[gadget_id];
2471 int xpos = MENU_SCREEN_START_XPOS;
2472 int ypos = MENU_SCREEN_START_YPOS + i;
2473 int x = mSX + xpos * 32;
2474 int y = mSY + ypos * 32;
2476 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2480 if (si->type & TYPE_VALUE &&
2481 menu_info == setup_info)
2482 drawSetupValue(i, menu_info_pos);
2486 static void DrawInfoScreen_Main(void)
2488 int fade_mask = REDRAW_FIELD;
2491 if (redraw_mask & REDRAW_ALL)
2492 fade_mask = REDRAW_ALL;
2495 fade_mask = REDRAW_ALL;
2498 FadeMenuSoundsAndMusic();
2500 FreeScreenGadgets();
2501 CreateScreenGadgets();
2503 // (needed after displaying title screens which disable auto repeat)
2504 KeyboardAutoRepeatOn();
2506 FadeSetLeaveScreen();
2510 // needed if different viewport properties defined for info screen
2511 ChangeViewportPropertiesIfNeeded();
2513 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2517 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2519 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2521 info_info = info_info_main;
2523 // determine maximal number of info entries that can be displayed on screen
2525 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2528 // determine maximal number of info entries available for menu of info screen
2530 for (i = 0; info_info[i].type != 0; i++)
2533 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2535 MapScreenGadgets(max_info_info);
2537 PlayMenuSoundsAndMusic();
2539 DrawMaskedBorder(fade_mask);
2544 static void changeSetupValue(int, int, int);
2546 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2547 int mode, int num_page_entries,
2548 int max_page_entries)
2550 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2551 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2552 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2553 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2554 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2555 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2556 int *num_page_entries_last = num_page_entries_all_last[game_status];
2557 int *choice_store = choice_stores[game_status];
2558 int *first_entry_store = first_entry_stores[game_status];
2559 int choice = choice_store[mode]; // starts with 0
2560 int first_entry = first_entry_store[mode]; // starts with 0
2562 int y = choice - first_entry;
2564 boolean position_set_by_scrollbar = (dx == 999);
2565 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2568 if (button == MB_MENU_INITIALIZE)
2570 // check if number of menu page entries has changed (may happen by change
2571 // of custom artwork definition value for 'list_size' for this menu screen)
2572 // (in this case, the last menu position most probably has to be corrected)
2573 if (num_page_entries != num_page_entries_last[mode])
2575 choice_store[mode] = first_entry_store[mode] = 0;
2577 choice = first_entry = 0;
2580 num_page_entries_last[mode] = num_page_entries;
2583 // advance to first valid menu entry
2584 while (choice < num_page_entries &&
2585 menu_info[choice].type & TYPE_SKIP_ENTRY)
2588 if (position_set_by_scrollbar)
2589 first_entry = first_entry_store[mode] = dy;
2591 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2592 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2594 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2596 if (choice < first_entry)
2598 choice = first_entry;
2600 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2603 else if (choice > first_entry + num_page_entries - 1)
2605 choice = first_entry + num_page_entries - 1;
2607 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2611 choice_store[mode] = choice;
2613 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2617 else if (button == MB_MENU_LEAVE)
2619 PlaySound(SND_MENU_ITEM_SELECTING);
2621 for (i = 0; i < max_page_entries; i++)
2623 if (menu_info[i].type & TYPE_LEAVE_MENU)
2625 void (*menu_callback_function)(void) = menu_info[i].value;
2629 menu_callback_function();
2631 break; // absolutely needed because function changes 'menu_info'!
2638 if (mx || my) // mouse input
2640 x = (mx - mSX) / 32;
2641 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2643 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2645 // move cursor instead of scrolling when already at start/end of list
2646 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2648 else if (dy == +1 * SCROLL_LINE &&
2649 first_entry + num_page_entries == max_page_entries)
2652 // handle scrolling screen one line or page
2654 y + dy > num_page_entries - 1)
2656 boolean redraw = FALSE;
2658 if (ABS(dy) == SCROLL_PAGE)
2659 step = num_page_entries - 1;
2661 if (dy < 0 && first_entry > 0)
2663 // scroll page/line up
2665 first_entry -= step;
2666 if (first_entry < 0)
2671 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2673 // scroll page/line down
2675 first_entry += step;
2676 if (first_entry + num_page_entries > max_page_entries)
2677 first_entry = MAX(0, max_page_entries - num_page_entries);
2684 choice += first_entry - first_entry_store[mode];
2686 if (choice < first_entry)
2688 choice = first_entry;
2690 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2693 else if (choice > first_entry + num_page_entries - 1)
2695 choice = first_entry + num_page_entries - 1;
2697 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2700 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2704 if (choice < first_entry ||
2705 choice > first_entry + num_page_entries - 1)
2706 first_entry += SIGN(dy);
2709 first_entry_store[mode] = first_entry;
2710 choice_store[mode] = choice;
2712 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2714 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2716 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2717 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2725 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2727 if (menu_info[choice].type & menu_navigation_type ||
2728 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2729 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2730 menu_info[choice].type & TYPE_PLAYER)
2731 button = MB_MENU_CHOICE;
2736 // jump to next non-empty menu entry (up or down)
2737 while (first_entry + y > 0 &&
2738 first_entry + y < max_page_entries - 1 &&
2739 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2742 if (!IN_VIS_MENU(x, y))
2744 choice += y - y_old;
2746 if (choice < first_entry)
2747 first_entry = choice;
2748 else if (choice > first_entry + num_page_entries - 1)
2749 first_entry = choice - num_page_entries + 1;
2751 if (first_entry >= 0 &&
2752 first_entry + num_page_entries <= max_page_entries)
2754 first_entry_store[mode] = first_entry;
2756 if (choice < first_entry)
2757 choice = first_entry;
2758 else if (choice > first_entry + num_page_entries - 1)
2759 choice = first_entry + num_page_entries - 1;
2761 choice_store[mode] = choice;
2763 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2765 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2767 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2768 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2775 if (!anyScrollbarGadgetActive() &&
2776 IN_VIS_MENU(x, y) &&
2777 mx < mx_right_border &&
2778 y >= 0 && y < num_page_entries)
2782 if (first_entry + y != choice &&
2783 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2785 PlaySound(SND_MENU_ITEM_ACTIVATING);
2787 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2788 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2790 choice = choice_store[mode] = first_entry + y;
2794 PlaySound(SND_MENU_ITEM_SELECTING);
2796 for (i = 0; menu_info[i].type != 0; i++)
2798 if (menu_info[i].type & TYPE_LEAVE_MENU)
2800 void (*menu_callback_function)(void) = menu_info[i].value;
2804 menu_callback_function();
2806 // absolutely needed because function changes 'menu_info'!
2814 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2816 PlaySound(SND_MENU_ITEM_SELECTING);
2818 // when selecting key headline, execute function for key value change
2819 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2820 menu_info[first_entry + y + 1].type & TYPE_KEY)
2823 // when selecting string value, execute function for list selection
2824 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2825 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2828 // when selecting string value, execute function for text input gadget
2829 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2830 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2833 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2835 void (*menu_callback_function)(void) =
2836 menu_info[first_entry + y].value;
2838 FadeSetFromType(menu_info[first_entry + y].type);
2840 menu_callback_function();
2842 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2844 void (*gadget_callback_function)(void) =
2845 menu_info[first_entry + y].value;
2847 gadget_callback_function();
2849 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2850 menu_info == setup_info)
2852 changeSetupValue(y, first_entry + y, dx);
2858 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2860 menu_info = info_info;
2862 HandleMenuScreen(mx, my, dx, dy, button,
2863 info_mode, num_info_info, max_info_info);
2866 static int getMenuFontSpacing(int spacing_height, int font_nr)
2868 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2870 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2874 static int getMenuTextSpacing(int spacing_height, int font_nr)
2876 return (getMenuFontSpacing(spacing_height, font_nr) +
2877 EXTRA_SPACING(game_status));
2880 static int getMenuTextStep(int spacing_height, int font_nr)
2882 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2885 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2887 int font_title = MENU_INFO_FONT_TITLE;
2888 int font_error = FONT_TEXT_2;
2889 int font_foot = MENU_INFO_FONT_FOOT;
2890 int spacing_title = menu.headline1_spacing_info[info_mode];
2891 int ystep_title = getMenuTextStep(spacing_title, font_title);
2892 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2893 int ystart2 = ystart1 + ystep_title;
2894 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2896 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2898 FadeOut(REDRAW_FIELD);
2903 DrawTextSCentered(ystart1, font_title, text_title);
2904 DrawTextSCentered(ystart2, font_error, text_error);
2906 DrawTextSCentered(ybottom, font_foot,
2907 "Press any key or button for info menu");
2909 FadeIn(REDRAW_FIELD);
2912 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2914 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2915 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2916 int font_title = MENU_INFO_FONT_TITLE;
2917 int font_foot = MENU_INFO_FONT_FOOT;
2918 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2919 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2920 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2921 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2922 int ystep = MENU_SCREEN_INFO_YSTEP;
2923 int element, action, direction;
2931 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2932 infoscreen_step[i] = infoscreen_frame[i] = 0;
2937 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2939 DrawTextSCentered(ybottom, font_foot,
2940 "Press any key or button for next page");
2946 while (helpanim_info[j].element != HELPANIM_LIST_END)
2948 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2953 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2962 j += infoscreen_step[i - start];
2964 element = helpanim_info[j].element;
2965 action = helpanim_info[j].action;
2966 direction = helpanim_info[j].direction;
2969 element = EL_UNKNOWN;
2971 if (action != -1 && direction != -1)
2972 graphic = el_act_dir2img(element, action, direction);
2973 else if (action != -1)
2974 graphic = el_act2img(element, action);
2975 else if (direction != -1)
2976 graphic = el_dir2img(element, direction);
2978 graphic = el2img(element);
2980 delay = helpanim_info[j++].delay;
2985 if (infoscreen_frame[i - start] == 0)
2988 infoscreen_frame[i - start] = delay - 1;
2992 sync_frame = delay - infoscreen_frame[i - start];
2993 infoscreen_frame[i - start]--;
2996 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2998 if (!infoscreen_frame[i - start])
2999 infoscreen_step[i - start] = 0;
3003 if (!infoscreen_frame[i - start])
3004 infoscreen_step[i - start]++;
3005 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3011 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3013 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3014 graphic, sync_frame, USE_MASKING);
3017 DrawInfoScreen_HelpText(element, action, direction, i - start);
3022 redraw_mask |= REDRAW_FIELD;
3027 static char *getHelpText(int element, int action, int direction)
3029 char token[MAX_LINE_LEN];
3031 strcpy(token, element_info[element].token_name);
3034 strcat(token, element_action_info[action].suffix);
3036 if (direction != -1)
3037 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3039 return getHashEntry(helptext_info, token);
3042 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3044 int font_nr = FONT_INFO_ELEMENTS;
3045 int font_width = getFontWidth(font_nr);
3046 int font_height = getFontHeight(font_nr);
3047 int yoffset = (TILEX - 2 * font_height) / 2;
3048 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3049 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3050 int ystep = TILEY + 4;
3051 int pad_left = xstart - SX;
3052 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3053 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3054 int max_lines_per_text = 2;
3057 if (action != -1 && direction != -1) // element.action.direction
3058 text = getHelpText(element, action, direction);
3060 if (text == NULL && action != -1) // element.action
3061 text = getHelpText(element, action, -1);
3063 if (text == NULL && direction != -1) // element.direction
3064 text = getHelpText(element, -1, direction);
3066 if (text == NULL) // base element
3067 text = getHelpText(element, -1, -1);
3069 if (text == NULL) // not found
3070 text = "No description available";
3072 if (strlen(text) <= max_chars_per_line) // only one line of text
3073 ystart += getFontHeight(font_nr) / 2;
3075 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3076 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3077 TRUE, FALSE, FALSE);
3080 static void DrawInfoScreen_TitleScreen(void)
3082 SetGameStatus(GAME_MODE_TITLE);
3087 void HandleInfoScreen_TitleScreen(int button)
3089 HandleTitleScreen(0, 0, 0, 0, button);
3092 static void DrawInfoScreen_Elements(void)
3094 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3096 FadeOut(REDRAW_FIELD);
3101 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3103 FadeIn(REDRAW_FIELD);
3106 void HandleInfoScreen_Elements(int button)
3108 static unsigned int info_delay = 0;
3109 static int num_anims;
3110 static int num_pages;
3112 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3115 if (button == MB_MENU_INITIALIZE)
3117 boolean new_element = TRUE;
3121 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3123 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3125 else if (new_element)
3128 new_element = FALSE;
3132 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3136 if (button == MB_MENU_LEAVE)
3138 PlaySound(SND_MENU_ITEM_SELECTING);
3140 info_mode = INFO_MODE_MAIN;
3145 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3147 if (button != MB_MENU_INITIALIZE)
3149 PlaySound(SND_MENU_ITEM_SELECTING);
3154 if (page >= num_pages)
3156 FadeMenuSoundsAndMusic();
3158 info_mode = INFO_MODE_MAIN;
3165 FadeSetNextScreen();
3167 if (button != MB_MENU_INITIALIZE)
3168 FadeOut(REDRAW_FIELD);
3170 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3172 if (button != MB_MENU_INITIALIZE)
3173 FadeIn(REDRAW_FIELD);
3177 if (DelayReached(&info_delay, GameFrameDelay))
3178 if (page < num_pages)
3179 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3181 PlayMenuSoundIfLoop();
3185 static void DrawInfoScreen_Music(void)
3187 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3189 FadeOut(REDRAW_FIELD);
3196 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3198 FadeIn(REDRAW_FIELD);
3201 void HandleInfoScreen_Music(int button)
3203 static struct MusicFileInfo *list = NULL;
3204 int font_title = MENU_INFO_FONT_TITLE;
3205 int font_head = MENU_INFO_FONT_HEAD;
3206 int font_text = MENU_INFO_FONT_TEXT;
3207 int font_foot = MENU_INFO_FONT_FOOT;
3208 int spacing_title = menu.headline1_spacing_info[info_mode];
3209 int spacing_head = menu.headline2_spacing_info[info_mode];
3210 int ystep_title = getMenuTextStep(spacing_title, font_title);
3211 int ystep_head = getMenuTextStep(spacing_head, font_head);
3212 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3213 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3215 if (button == MB_MENU_INITIALIZE)
3217 list = music_file_info;
3221 FadeMenuSoundsAndMusic();
3226 DrawTextSCentered(ystart, font_title,
3227 "No music info for this level set.");
3229 DrawTextSCentered(ybottom, font_foot,
3230 "Press any key or button for info menu");
3236 if (button == MB_MENU_LEAVE)
3238 PlaySound(SND_MENU_ITEM_SELECTING);
3240 FadeMenuSoundsAndMusic();
3242 info_mode = INFO_MODE_MAIN;
3247 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3249 if (button != MB_MENU_INITIALIZE)
3251 PlaySound(SND_MENU_ITEM_SELECTING);
3259 FadeMenuSoundsAndMusic();
3261 info_mode = INFO_MODE_MAIN;
3267 FadeMenuSoundsAndMusic();
3269 if (list != music_file_info)
3270 FadeSetNextScreen();
3272 if (button != MB_MENU_INITIALIZE)
3273 FadeOut(REDRAW_FIELD);
3280 int sound = list->music;
3282 if (IS_LOOP_SOUND(sound))
3283 PlaySoundLoop(sound);
3287 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3291 int music = list->music;
3293 if (IS_LOOP_MUSIC(music))
3294 PlayMusicLoop(music);
3298 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3301 ystart += ystep_title;
3303 if (!strEqual(list->title, UNKNOWN_NAME))
3305 if (!strEqual(list->title_header, UNKNOWN_NAME))
3307 DrawTextSCentered(ystart, font_head, list->title_header);
3308 ystart += ystep_head;
3311 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3312 ystart += ystep_head;
3315 if (!strEqual(list->artist, UNKNOWN_NAME))
3317 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3318 DrawTextSCentered(ystart, font_head, list->artist_header);
3320 DrawTextSCentered(ystart, font_head, "by");
3322 ystart += ystep_head;
3324 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3325 ystart += ystep_head;
3328 if (!strEqual(list->album, UNKNOWN_NAME))
3330 if (!strEqual(list->album_header, UNKNOWN_NAME))
3331 DrawTextSCentered(ystart, font_head, list->album_header);
3333 DrawTextSCentered(ystart, font_head, "from the album");
3335 ystart += ystep_head;
3337 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3338 ystart += ystep_head;
3341 if (!strEqual(list->year, UNKNOWN_NAME))
3343 if (!strEqual(list->year_header, UNKNOWN_NAME))
3344 DrawTextSCentered(ystart, font_head, list->year_header);
3346 DrawTextSCentered(ystart, font_head, "from the year");
3348 ystart += ystep_head;
3350 DrawTextFCentered(ystart, font_text, "%s", list->year);
3351 ystart += ystep_head;
3354 DrawTextSCentered(ybottom, FONT_TEXT_4,
3355 "Press any key or button for next page");
3357 if (button != MB_MENU_INITIALIZE)
3358 FadeIn(REDRAW_FIELD);
3361 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3362 PlaySoundLoop(list->music);
3365 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3367 int font_title = MENU_INFO_FONT_TITLE;
3368 int font_head = MENU_INFO_FONT_HEAD;
3369 int font_text = MENU_INFO_FONT_TEXT;
3370 int font_foot = MENU_INFO_FONT_FOOT;
3371 int spacing_title = menu.headline1_spacing_info[info_mode];
3372 int spacing_head = menu.headline2_spacing_info[info_mode];
3373 int spacing_para = menu.paragraph_spacing_info[info_mode];
3374 int spacing_line = menu.line_spacing_info[info_mode];
3375 int ystep_title = getMenuTextStep(spacing_title, font_title);
3376 int ystep_head = getMenuTextStep(spacing_head, font_head);
3377 int ystep_para = getMenuTextStep(spacing_para, font_text);
3378 int ystep_line = getMenuTextStep(spacing_line, font_text);
3379 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3380 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3385 DrawTextSCentered(ystart, font_title, "Credits:");
3386 ystart += ystep_title;
3390 DrawTextSCentered(ystart, font_head,
3391 "Special thanks to");
3392 ystart += ystep_head;
3393 DrawTextSCentered(ystart, font_text,
3395 ystart += ystep_head;
3396 DrawTextSCentered(ystart, font_head,
3398 ystart += ystep_head;
3399 DrawTextSCentered(ystart, font_text,
3400 "\"Boulder Dash\"");
3401 ystart += ystep_head;
3402 DrawTextSCentered(ystart, font_head,
3404 ystart += ystep_head;
3405 DrawTextSCentered(ystart, font_text,
3407 ystart += ystep_head;
3408 DrawTextSCentered(ystart, font_head,
3410 ystart += ystep_head;
3411 DrawTextSCentered(ystart, font_text,
3412 "First Star Software");
3414 else if (screen_nr == 1)
3416 DrawTextSCentered(ystart, font_head,
3417 "Special thanks to");
3418 ystart += ystep_head;
3419 DrawTextSCentered(ystart, font_text,
3420 "Klaus Heinz & Volker Wertich");
3421 ystart += ystep_head;
3422 DrawTextSCentered(ystart, font_head,
3424 ystart += ystep_head;
3425 DrawTextSCentered(ystart, font_text,
3426 "\"Emerald Mine\"");
3427 ystart += ystep_head;
3428 DrawTextSCentered(ystart, font_head,
3430 ystart += ystep_head;
3431 DrawTextSCentered(ystart, font_text,
3433 ystart += ystep_head;
3434 DrawTextSCentered(ystart, font_head,
3436 ystart += ystep_head;
3437 DrawTextSCentered(ystart, font_text,
3440 else if (screen_nr == 2)
3442 DrawTextSCentered(ystart, font_head,
3443 "Special thanks to");
3444 ystart += ystep_head;
3445 DrawTextSCentered(ystart, font_text,
3446 "Michael Stopp & Philip Jespersen");
3447 ystart += ystep_head;
3448 DrawTextSCentered(ystart, font_head,
3450 ystart += ystep_head;
3451 DrawTextSCentered(ystart, font_text,
3453 ystart += ystep_head;
3454 DrawTextSCentered(ystart, font_head,
3456 ystart += ystep_head;
3457 DrawTextSCentered(ystart, font_text,
3459 ystart += ystep_head;
3460 DrawTextSCentered(ystart, font_head,
3462 ystart += ystep_head;
3463 DrawTextSCentered(ystart, font_text,
3464 "Digital Integration");
3466 else if (screen_nr == 3)
3468 DrawTextSCentered(ystart, font_head,
3469 "Special thanks to");
3470 ystart += ystep_head;
3471 DrawTextSCentered(ystart, font_text,
3472 "Hiroyuki Imabayashi");
3473 ystart += ystep_head;
3474 DrawTextSCentered(ystart, font_head,
3476 ystart += ystep_head;
3477 DrawTextSCentered(ystart, font_text,
3479 ystart += ystep_head;
3480 DrawTextSCentered(ystart, font_head,
3482 ystart += ystep_head;
3483 DrawTextSCentered(ystart, font_text,
3485 ystart += ystep_head;
3486 DrawTextSCentered(ystart, font_head,
3488 ystart += ystep_head;
3489 DrawTextSCentered(ystart, font_text,
3492 else if (screen_nr == 4)
3494 DrawTextSCentered(ystart, font_head,
3495 "Special thanks to");
3496 ystart += ystep_head;
3497 DrawTextSCentered(ystart, font_text,
3499 ystart += ystep_head;
3500 DrawTextSCentered(ystart, font_head,
3502 ystart += ystep_head;
3503 DrawTextSCentered(ystart, font_text,
3504 "J\xfcrgen Bonhagen");
3505 ystart += ystep_head;
3506 DrawTextSCentered(ystart, font_head,
3507 "for the continuous creation");
3508 ystart += ystep_line;
3509 DrawTextSCentered(ystart, font_head,
3510 "of outstanding level sets");
3512 else if (screen_nr == 5)
3514 DrawTextSCentered(ystart, font_head,
3516 ystart += ystep_head;
3517 DrawTextSCentered(ystart, font_text,
3519 ystart += ystep_head;
3520 DrawTextSCentered(ystart, font_head,
3521 "for ideas and inspiration by");
3522 ystart += ystep_head;
3523 DrawTextSCentered(ystart, font_text,
3525 ystart += ystep_para;
3527 DrawTextSCentered(ystart, font_head,
3529 ystart += ystep_head;
3530 DrawTextSCentered(ystart, font_text,
3532 ystart += ystep_head;
3533 DrawTextSCentered(ystart, font_head,
3534 "for ideas and inspiration by");
3535 ystart += ystep_head;
3536 DrawTextSCentered(ystart, font_text,
3539 else if (screen_nr == 6)
3541 DrawTextSCentered(ystart, font_head,
3543 ystart += ystep_head;
3544 DrawTextSCentered(ystart, font_text,
3546 ystart += ystep_head;
3547 DrawTextSCentered(ystart, font_head,
3548 "for the code base used for the");
3549 ystart += ystep_line;
3550 DrawTextSCentered(ystart, font_head,
3551 "native Emerald Mine engine");
3553 else if (screen_nr == 7)
3555 DrawTextSCentered(ystart, font_head,
3557 ystart += ystep_head;
3558 DrawTextSCentered(ystart, font_text,
3560 ystart += ystep_head;
3561 DrawTextSCentered(ystart, font_head,
3562 "for the initial DOS port");
3563 ystart += ystep_para;
3565 DrawTextSCentered(ystart, font_head,
3567 ystart += ystep_head;
3568 DrawTextSCentered(ystart, font_text,
3570 ystart += ystep_head;
3571 DrawTextSCentered(ystart, font_head,
3572 "for some additional toons");
3574 else if (screen_nr == 8)
3576 DrawTextSCentered(ystart, font_head,
3577 "And not to forget:");
3578 ystart += ystep_head;
3579 DrawTextSCentered(ystart, font_head,
3581 ystart += ystep_head;
3582 DrawTextSCentered(ystart, font_text,
3583 "All those who contributed");
3584 ystart += ystep_line;
3585 DrawTextSCentered(ystart, font_text,
3586 "levels to this game");
3587 ystart += ystep_line;
3588 DrawTextSCentered(ystart, font_text,
3592 DrawTextSCentered(ybottom, font_foot,
3593 "Press any key or button for next page");
3596 static void DrawInfoScreen_Credits(void)
3598 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3600 FadeMenuSoundsAndMusic();
3602 FadeOut(REDRAW_FIELD);
3604 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3606 FadeIn(REDRAW_FIELD);
3609 void HandleInfoScreen_Credits(int button)
3611 static int screen_nr = 0;
3612 int num_screens = 9;
3614 if (button == MB_MENU_INITIALIZE)
3618 // DrawInfoScreen_CreditsScreen(screen_nr);
3621 if (button == MB_MENU_LEAVE)
3623 PlaySound(SND_MENU_ITEM_SELECTING);
3625 info_mode = INFO_MODE_MAIN;
3630 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3632 if (button != MB_MENU_INITIALIZE)
3634 PlaySound(SND_MENU_ITEM_SELECTING);
3639 if (screen_nr >= num_screens)
3641 FadeMenuSoundsAndMusic();
3643 info_mode = INFO_MODE_MAIN;
3650 FadeSetNextScreen();
3652 if (button != MB_MENU_INITIALIZE)
3653 FadeOut(REDRAW_FIELD);
3655 DrawInfoScreen_CreditsScreen(screen_nr);
3657 if (button != MB_MENU_INITIALIZE)
3658 FadeIn(REDRAW_FIELD);
3662 PlayMenuSoundIfLoop();
3666 static void DrawInfoScreen_Program(void)
3668 int font_title = MENU_INFO_FONT_TITLE;
3669 int font_head = MENU_INFO_FONT_HEAD;
3670 int font_text = MENU_INFO_FONT_TEXT;
3671 int font_foot = MENU_INFO_FONT_FOOT;
3672 int spacing_title = menu.headline1_spacing_info[info_mode];
3673 int spacing_head = menu.headline2_spacing_info[info_mode];
3674 int spacing_para = menu.paragraph_spacing_info[info_mode];
3675 int spacing_line = menu.line_spacing_info[info_mode];
3676 int ystep_title = getMenuTextStep(spacing_title, font_title);
3677 int ystep_head = getMenuTextStep(spacing_head, font_head);
3678 int ystep_para = getMenuTextStep(spacing_para, font_text);
3679 int ystep_line = getMenuTextStep(spacing_line, font_text);
3680 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3681 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3683 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3685 FadeOut(REDRAW_FIELD);
3690 DrawTextSCentered(ystart, font_title, "Program Information:");
3691 ystart += ystep_title;
3693 DrawTextSCentered(ystart, font_head,
3694 "This game is Freeware!");
3695 ystart += ystep_head;
3696 DrawTextSCentered(ystart, font_head,
3697 "If you like it, send e-mail to:");
3698 ystart += ystep_head;
3699 DrawTextSCentered(ystart, font_text,
3700 setup.internal.program_email);
3701 ystart += ystep_para;
3703 DrawTextSCentered(ystart, font_head,
3704 "More information and levels:");
3705 ystart += ystep_head;
3706 DrawTextSCentered(ystart, font_text,
3707 setup.internal.program_website);
3708 ystart += ystep_para;
3710 DrawTextSCentered(ystart, font_head,
3711 "If you have created new levels,");
3712 ystart += ystep_line;
3713 DrawTextSCentered(ystart, font_head,
3714 "send them to me to include them!");
3715 ystart += ystep_head;
3716 DrawTextSCentered(ystart, font_head,
3719 DrawTextSCentered(ybottom, font_foot,
3720 "Press any key or button for info menu");
3722 FadeIn(REDRAW_FIELD);
3725 void HandleInfoScreen_Program(int button)
3727 if (button == MB_MENU_LEAVE)
3729 PlaySound(SND_MENU_ITEM_SELECTING);
3731 info_mode = INFO_MODE_MAIN;
3736 else if (button == MB_MENU_CHOICE)
3738 PlaySound(SND_MENU_ITEM_SELECTING);
3740 FadeMenuSoundsAndMusic();
3742 info_mode = INFO_MODE_MAIN;
3747 PlayMenuSoundIfLoop();
3751 static void DrawInfoScreen_Version(void)
3753 int font_title = MENU_INFO_FONT_TITLE;
3754 int font_head = MENU_INFO_FONT_HEAD;
3755 int font_text = MENU_INFO_FONT_TEXT;
3756 int font_foot = MENU_INFO_FONT_FOOT;
3757 int spacing_title = menu.headline1_spacing_info[info_mode];
3758 int spacing_head = menu.headline2_spacing_info[info_mode];
3759 int spacing_para = menu.paragraph_spacing_info[info_mode];
3760 int spacing_line = menu.line_spacing_info[info_mode];
3761 int xstep = getFontWidth(font_text);
3762 int ystep_title = getMenuTextStep(spacing_title, font_title);
3763 int ystep_head = getMenuTextStep(spacing_head, font_head);
3764 int ystep_para = getMenuTextStep(spacing_para, font_text);
3765 int ystep_line = getMenuTextStep(spacing_line, font_text);
3766 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3767 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3768 int xstart1 = mSX - SX + 2 * xstep;
3769 int xstart2 = mSX - SX + 18 * xstep;
3770 int xstart3 = mSX - SX + 28 * xstep;
3771 SDL_version sdl_version_compiled;
3772 const SDL_version *sdl_version_linked;
3773 int driver_name_len = 10;
3774 SDL_version sdl_version_linked_ext;
3775 const char *driver_name = NULL;
3777 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3779 FadeOut(REDRAW_FIELD);
3784 DrawTextSCentered(ystart, font_title, "Version Information:");
3785 ystart += ystep_title;
3787 DrawTextF(xstart1, ystart, font_head, "Name");
3788 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3789 ystart += ystep_line;
3791 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3793 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3794 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3795 ystart += ystep_line;
3797 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3798 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3799 ystart += ystep_line;
3803 DrawTextF(xstart1, ystart, font_head, "Version");
3804 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3805 ystart += ystep_line;
3808 DrawTextF(xstart1, ystart, font_head, "Platform");
3809 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3811 PLATFORM_XX_BIT_STRING);
3812 ystart += ystep_line;
3814 DrawTextF(xstart1, ystart, font_head, "Target");
3815 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3816 ystart += ystep_line;
3818 DrawTextF(xstart1, ystart, font_head, "Source date");
3819 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3820 ystart += ystep_line;
3822 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3823 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3824 ystart += ystep_para;
3826 DrawTextF(xstart1, ystart, font_head, "Library");
3827 DrawTextF(xstart2, ystart, font_head, "compiled");
3828 DrawTextF(xstart3, ystart, font_head, "linked");
3829 ystart += ystep_head;
3831 SDL_VERSION(&sdl_version_compiled);
3832 SDL_GetVersion(&sdl_version_linked_ext);
3833 sdl_version_linked = &sdl_version_linked_ext;
3835 DrawTextF(xstart1, ystart, font_text, "SDL");
3836 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3837 sdl_version_compiled.major,
3838 sdl_version_compiled.minor,
3839 sdl_version_compiled.patch);
3840 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3841 sdl_version_linked->major,
3842 sdl_version_linked->minor,
3843 sdl_version_linked->patch);
3844 ystart += ystep_line;
3846 SDL_IMAGE_VERSION(&sdl_version_compiled);
3847 sdl_version_linked = IMG_Linked_Version();
3849 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3850 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3851 sdl_version_compiled.major,
3852 sdl_version_compiled.minor,
3853 sdl_version_compiled.patch);
3854 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3855 sdl_version_linked->major,
3856 sdl_version_linked->minor,
3857 sdl_version_linked->patch);
3858 ystart += ystep_line;
3860 SDL_MIXER_VERSION(&sdl_version_compiled);
3861 sdl_version_linked = Mix_Linked_Version();
3863 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3864 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3865 sdl_version_compiled.major,
3866 sdl_version_compiled.minor,
3867 sdl_version_compiled.patch);
3868 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3869 sdl_version_linked->major,
3870 sdl_version_linked->minor,
3871 sdl_version_linked->patch);
3872 ystart += ystep_line;
3874 SDL_NET_VERSION(&sdl_version_compiled);
3875 sdl_version_linked = SDLNet_Linked_Version();
3877 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3878 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3879 sdl_version_compiled.major,
3880 sdl_version_compiled.minor,
3881 sdl_version_compiled.patch);
3882 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3883 sdl_version_linked->major,
3884 sdl_version_linked->minor,
3885 sdl_version_linked->patch);
3886 ystart += ystep_para;
3888 DrawTextF(xstart1, ystart, font_head, "Driver");
3889 DrawTextF(xstart2, ystart, font_head, "Requested");
3890 DrawTextF(xstart3, ystart, font_head, "Used");
3891 ystart += ystep_head;
3894 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3896 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3897 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3898 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3899 ystart += ystep_line;
3902 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3904 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3905 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3906 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3907 ystart += ystep_line;
3910 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3912 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3913 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3914 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3916 DrawTextSCentered(ybottom, font_foot,
3917 "Press any key or button for info menu");
3919 FadeIn(REDRAW_FIELD);
3922 void HandleInfoScreen_Version(int button)
3924 if (button == MB_MENU_LEAVE)
3926 PlaySound(SND_MENU_ITEM_SELECTING);
3928 info_mode = INFO_MODE_MAIN;
3933 else if (button == MB_MENU_CHOICE)
3935 PlaySound(SND_MENU_ITEM_SELECTING);
3937 FadeMenuSoundsAndMusic();
3939 info_mode = INFO_MODE_MAIN;
3944 PlayMenuSoundIfLoop();
3948 static void DrawInfoScreen_LevelSet(void)
3950 struct TitleMessageInfo *tmi = &readme;
3951 char *filename = getLevelSetInfoFilename();
3952 char *title = "Level Set Information:";
3953 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3954 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3956 if (filename == NULL)
3958 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3963 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3965 FadeOut(REDRAW_FIELD);
3970 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3972 // if x position set to "-1", automatically determine by playfield width
3974 tmi->x = SXSIZE / 2;
3976 // if y position set to "-1", use static default value
3980 // if width set to "-1", automatically determine by playfield width
3981 if (tmi->width == -1)
3982 tmi->width = SXSIZE - 2 * TILEX;
3984 // if height set to "-1", automatically determine by playfield height
3985 if (tmi->height == -1)
3986 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3988 // if chars set to "-1", automatically determine by text and font width
3989 if (tmi->chars == -1)
3990 tmi->chars = tmi->width / getFontWidth(tmi->font);
3992 tmi->width = tmi->chars * getFontWidth(tmi->font);
3994 // if lines set to "-1", automatically determine by text and font height
3995 if (tmi->lines == -1)
3996 tmi->lines = tmi->height / getFontHeight(tmi->font);
3998 tmi->height = tmi->lines * getFontHeight(tmi->font);
4000 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
4001 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
4002 tmi->autowrap, tmi->centered, tmi->parse_comments);
4004 DrawTextSCentered(ybottom, FONT_TEXT_4,
4005 "Press any key or button for info menu");
4007 FadeIn(REDRAW_FIELD);
4010 static void HandleInfoScreen_LevelSet(int button)
4012 if (button == MB_MENU_LEAVE)
4014 PlaySound(SND_MENU_ITEM_SELECTING);
4016 info_mode = INFO_MODE_MAIN;
4021 else if (button == MB_MENU_CHOICE)
4023 PlaySound(SND_MENU_ITEM_SELECTING);
4025 FadeMenuSoundsAndMusic();
4027 info_mode = INFO_MODE_MAIN;
4032 PlayMenuSoundIfLoop();
4036 static void DrawInfoScreen(void)
4038 if (info_mode == INFO_MODE_TITLE)
4039 DrawInfoScreen_TitleScreen();
4040 else if (info_mode == INFO_MODE_ELEMENTS)
4041 DrawInfoScreen_Elements();
4042 else if (info_mode == INFO_MODE_MUSIC)
4043 DrawInfoScreen_Music();
4044 else if (info_mode == INFO_MODE_CREDITS)
4045 DrawInfoScreen_Credits();
4046 else if (info_mode == INFO_MODE_PROGRAM)
4047 DrawInfoScreen_Program();
4048 else if (info_mode == INFO_MODE_VERSION)
4049 DrawInfoScreen_Version();
4050 else if (info_mode == INFO_MODE_LEVELSET)
4051 DrawInfoScreen_LevelSet();
4053 DrawInfoScreen_Main();
4055 if (info_mode != INFO_MODE_MAIN &&
4056 info_mode != INFO_MODE_TITLE &&
4057 info_mode != INFO_MODE_MUSIC)
4058 PlayMenuSoundsAndMusic();
4061 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4063 if (info_mode == INFO_MODE_TITLE)
4064 HandleInfoScreen_TitleScreen(button);
4065 else if (info_mode == INFO_MODE_ELEMENTS)
4066 HandleInfoScreen_Elements(button);
4067 else if (info_mode == INFO_MODE_MUSIC)
4068 HandleInfoScreen_Music(button);
4069 else if (info_mode == INFO_MODE_CREDITS)
4070 HandleInfoScreen_Credits(button);
4071 else if (info_mode == INFO_MODE_PROGRAM)
4072 HandleInfoScreen_Program(button);
4073 else if (info_mode == INFO_MODE_VERSION)
4074 HandleInfoScreen_Version(button);
4075 else if (info_mode == INFO_MODE_LEVELSET)
4076 HandleInfoScreen_LevelSet(button);
4078 HandleInfoScreen_Main(mx, my, dx, dy, button);
4082 // ============================================================================
4083 // rename player API functions
4084 // ============================================================================
4086 struct ApiRenamePlayerThreadData
4092 static void *CreateThreadData_ApiRenamePlayer(void)
4094 struct ApiRenamePlayerThreadData *data =
4095 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4097 data->player_name = getStringCopy(setup.player_name);
4098 data->player_uuid = getStringCopy(setup.player_uuid);
4103 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4105 struct ApiRenamePlayerThreadData *data = data_raw;
4107 checked_free(data->player_name);
4108 checked_free(data->player_uuid);
4112 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4115 struct ApiRenamePlayerThreadData *data = data_raw;
4116 char *player_name_raw = data->player_name;
4117 char *player_uuid_raw = data->player_uuid;
4119 request->hostname = setup.api_server_hostname;
4120 request->port = API_SERVER_PORT;
4121 request->method = API_SERVER_METHOD;
4122 request->uri = API_SERVER_URI_RENAME;
4124 char *player_name = getEscapedJSON(player_name_raw);
4125 char *player_uuid = getEscapedJSON(player_uuid_raw);
4127 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4130 " \"game_version\": \"%s\",\n"
4131 " \"game_platform\": \"%s\",\n"
4132 " \"name\": \"%s\",\n"
4133 " \"uuid\": \"%s\"\n"
4135 getPasswordJSON(setup.api_server_password),
4136 getProgramRealVersionString(),
4137 getProgramPlatformString(),
4141 checked_free(player_name);
4142 checked_free(player_uuid);
4144 ConvertHttpRequestBodyToServerEncoding(request);
4149 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4152 // nothing to do here
4155 #if defined(PLATFORM_EMSCRIPTEN)
4156 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4157 void *buffer, unsigned int size)
4159 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4161 if (response != NULL)
4163 HandleResponse_ApiRenamePlayer(response, data_raw);
4165 checked_free(response);
4169 Error("server response too large to handle (%d bytes)", size);
4172 FreeThreadData_ApiRenamePlayer(data_raw);
4175 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4176 int code, const char *status)
4178 Error("server failed to handle request: %d %s", code, status);
4180 FreeThreadData_ApiRenamePlayer(data_raw);
4183 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4184 int bytes, int size)
4186 // nothing to do here
4189 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4192 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4194 FreeThreadData_ApiRenamePlayer(data_raw);
4199 emscripten_async_wget2_data(request->uri,
4204 Emscripten_ApiRenamePlayer_Loaded,
4205 Emscripten_ApiRenamePlayer_Failed,
4206 Emscripten_ApiRenamePlayer_Progress);
4211 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4212 struct HttpResponse *response,
4215 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4218 if (!DoHttpRequest(request, response))
4220 Error("HTTP request failed: %s", GetHttpError());
4225 if (!HTTP_SUCCESS(response->status_code))
4227 Error("server failed to handle request: %d %s",
4228 response->status_code,
4229 response->status_text);
4234 HandleResponse_ApiRenamePlayer(response, data_raw);
4237 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4238 struct HttpResponse *response,
4241 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4243 FreeThreadData_ApiRenamePlayer(data_raw);
4247 static int ApiRenamePlayerThread(void *data_raw)
4249 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4250 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4252 program.api_thread_count++;
4254 #if defined(PLATFORM_EMSCRIPTEN)
4255 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4257 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4260 program.api_thread_count--;
4262 checked_free(request);
4263 checked_free(response);
4268 static void ApiRenamePlayerAsThread(void)
4270 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4272 ExecuteAsThread(ApiRenamePlayerThread,
4273 "ApiRenamePlayer", data,
4274 "rename player on server");
4278 // ============================================================================
4279 // reset player UUID API functions
4280 // ============================================================================
4282 struct ApiResetUUIDThreadData
4285 char *player_uuid_old;
4286 char *player_uuid_new;
4289 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4291 struct ApiResetUUIDThreadData *data =
4292 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4294 data->player_name = getStringCopy(setup.player_name);
4295 data->player_uuid_old = getStringCopy(setup.player_uuid);
4296 data->player_uuid_new = getStringCopy(uuid_new);
4301 static void FreeThreadData_ApiResetUUID(void *data_raw)
4303 struct ApiResetUUIDThreadData *data = data_raw;
4305 checked_free(data->player_name);
4306 checked_free(data->player_uuid_old);
4307 checked_free(data->player_uuid_new);
4311 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4314 struct ApiResetUUIDThreadData *data = data_raw;
4315 char *player_name_raw = data->player_name;
4316 char *player_uuid_old_raw = data->player_uuid_old;
4317 char *player_uuid_new_raw = data->player_uuid_new;
4319 request->hostname = setup.api_server_hostname;
4320 request->port = API_SERVER_PORT;
4321 request->method = API_SERVER_METHOD;
4322 request->uri = API_SERVER_URI_RESETUUID;
4324 char *player_name = getEscapedJSON(player_name_raw);
4325 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4326 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4328 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4331 " \"game_version\": \"%s\",\n"
4332 " \"game_platform\": \"%s\",\n"
4333 " \"name\": \"%s\",\n"
4334 " \"uuid_old\": \"%s\",\n"
4335 " \"uuid_new\": \"%s\"\n"
4337 getPasswordJSON(setup.api_server_password),
4338 getProgramRealVersionString(),
4339 getProgramPlatformString(),
4344 checked_free(player_name);
4345 checked_free(player_uuid_old);
4346 checked_free(player_uuid_new);
4348 ConvertHttpRequestBodyToServerEncoding(request);
4353 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4356 struct ApiResetUUIDThreadData *data = data_raw;
4358 // upgrade player UUID in server setup file
4359 setup.player_uuid = getStringCopy(data->player_uuid_new);
4360 setup.player_version = 2;
4362 SaveSetup_ServerSetup();
4365 #if defined(PLATFORM_EMSCRIPTEN)
4366 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4367 void *buffer, unsigned int size)
4369 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4371 if (response != NULL)
4373 HandleResponse_ApiResetUUID(response, data_raw);
4375 checked_free(response);
4379 Error("server response too large to handle (%d bytes)", size);
4382 FreeThreadData_ApiResetUUID(data_raw);
4385 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4386 int code, const char *status)
4388 Error("server failed to handle request: %d %s", code, status);
4390 FreeThreadData_ApiResetUUID(data_raw);
4393 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4394 int bytes, int size)
4396 // nothing to do here
4399 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4402 if (!SetRequest_ApiResetUUID(request, data_raw))
4404 FreeThreadData_ApiResetUUID(data_raw);
4409 emscripten_async_wget2_data(request->uri,
4414 Emscripten_ApiResetUUID_Loaded,
4415 Emscripten_ApiResetUUID_Failed,
4416 Emscripten_ApiResetUUID_Progress);
4421 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4422 struct HttpResponse *response,
4425 if (!SetRequest_ApiResetUUID(request, data_raw))
4428 if (!DoHttpRequest(request, response))
4430 Error("HTTP request failed: %s", GetHttpError());
4435 if (!HTTP_SUCCESS(response->status_code))
4437 Error("server failed to handle request: %d %s",
4438 response->status_code,
4439 response->status_text);
4444 HandleResponse_ApiResetUUID(response, data_raw);
4447 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4448 struct HttpResponse *response,
4451 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4453 FreeThreadData_ApiResetUUID(data_raw);
4457 static int ApiResetUUIDThread(void *data_raw)
4459 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4460 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4462 program.api_thread_count++;
4464 #if defined(PLATFORM_EMSCRIPTEN)
4465 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4467 ApiResetUUID_HttpRequest(request, response, data_raw);
4470 program.api_thread_count--;
4472 checked_free(request);
4473 checked_free(response);
4478 static void ApiResetUUIDAsThread(char *uuid_new)
4480 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4482 ExecuteAsThread(ApiResetUUIDThread,
4483 "ApiResetUUID", data,
4484 "reset UUID on server");
4488 // ============================================================================
4489 // type name functions
4490 // ============================================================================
4492 static TreeInfo *type_name_node = NULL;
4493 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4494 static int type_name_nr = 0;
4496 static int getPlayerNameColor(char *name)
4498 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4501 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4504 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4505 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4506 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4507 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4508 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4509 int font_width = getFontWidth(font_nr);
4511 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4513 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4515 pos->width = strlen(text) * font_width;
4516 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4518 DrawText(sx, sy, text, font_nr);
4521 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4523 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4525 *pos = *mci->pos_input;
4527 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4529 TreeInfo *ti = player_name_current;
4530 int first_entry = ti->cl_first;
4531 int entry_pos = first_entry + ti->cl_cursor;
4532 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4533 int xpos = MENU_SCREEN_START_XPOS;
4534 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4536 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4537 type_name_nr = entry_pos;
4539 strcpy(name, type_name_node->name);
4543 pos->width = MAX_PLAYER_NAME_LEN * 32;
4547 type_name_nr = user.nr;
4549 strcpy(name, setup.player_name);
4552 strcpy(type_name_last, name);
4554 if (strEqual(name, EMPTY_PLAYER_NAME))
4557 *xpos = strlen(name);
4560 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4562 // change name of edited user in global list of user names
4563 setString(&global.user_names[type_name_nr], name);
4565 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4567 TreeInfo *node = type_name_node;
4569 // change name of edited user in local menu tree structure
4570 setString(&node->name, name);
4571 setString(&node->name_sorting, name);
4573 node->color = getPlayerNameColor(name);
4574 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4578 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4581 boolean reset_setup = strEqual(name, "");
4582 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4583 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4586 strcpy(name, type_name_last);
4588 if (strEqual(name, ""))
4589 strcpy(name, EMPTY_PLAYER_NAME);
4591 setTypeNameValues_Name(name, pos);
4593 // if player name not changed, no further action required
4594 if (strEqual(name, type_name_last))
4597 // redraw player name before (possibly) opening request dialogs
4598 drawTypeNameText(name, pos, FALSE);
4600 int last_user_nr = user.nr;
4602 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4604 // save setup of currently active user (may differ from edited user)
4607 // temporarily change active user to edited user
4608 user.nr = type_name_nr;
4611 Request("Use current setup values for the new player?", REQ_ASK))
4613 // use current setup values for new user, but create new player UUID
4614 setup.player_uuid = getStringCopy(getUUID());
4618 // load setup for existing user (or start with defaults for new user)
4623 char *setup_filename = getSetupFilename();
4624 boolean setup_exists = fileExists(setup_filename);
4626 // change name of edited user in setup structure
4627 strcpy(setup.player_name, name);
4629 // save setup of edited user
4632 // change name of edited user on score server
4633 ApiRenamePlayerAsThread();
4635 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4639 if (Request("Reset setup values for this player?", REQ_ASK))
4641 // remove setup config file
4642 unlink(setup_filename);
4644 // set player name to default player name
4647 // update player name used by name typing functions
4648 strcpy(name, setup.player_name);
4650 setTypeNameValues_Name(name, pos);
4653 else if (remove_user && type_name_nr != 0)
4655 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4657 char *user_dir = getUserGameDataDir();
4658 char *user_dir_removed =
4659 getStringCat3WithSeparator(user_dir, "REMOVED",
4660 getCurrentTimestamp(), ".");
4662 if (rename(user_dir, user_dir_removed) != 0)
4663 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4665 checked_free(user_dir_removed);
4668 else if (create_user && type_name_nr != 0 && !setup_exists)
4670 if (Request("Create empty level set for the new player?", REQ_ASK))
4672 char *levelset_subdir = getNewUserLevelSubdir();
4674 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4676 AddUserLevelSetToLevelInfo(levelset_subdir);
4678 LevelDirTree *leveldir_current_last = leveldir_current;
4680 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4683 // set level number of newly created level set to default value
4684 LoadLevelSetup_SeriesInfo();
4686 // set newly created level set as current level set for new user
4687 SaveLevelSetup_LastSeries();
4688 SaveLevelSetup_SeriesInfo();
4690 leveldir_current = leveldir_current_last;
4694 Request("Creating new level set failed!", REQ_CONFIRM);
4699 // restore currently active user
4700 user.nr = last_user_nr;
4702 // restore setup of currently active user
4705 // restore last level set of currently active user
4706 LoadLevelSetup_LastSeries();
4707 LoadLevelSetup_SeriesInfo();
4711 static void HandleTypeNameExt(boolean initialize, Key key)
4713 static struct TextPosInfo pos_name = { 0 };
4714 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4715 static int xpos = 0;
4716 struct TextPosInfo *pos = &pos_name;
4717 char key_char = getValidConfigValueChar(getCharFromKey(key));
4718 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4719 boolean active = TRUE;
4723 getTypeNameValues(name, pos, &xpos);
4725 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4726 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4728 StartTextInput(sx, sy, pos->width, pos->height);
4730 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4732 name[xpos] = key_char;
4737 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4743 else if (key == KSYM_Return || key == KSYM_Escape)
4745 boolean changed = (key == KSYM_Return);
4749 setTypeNameValues(name, pos, changed);
4754 drawTypeNameText(name, pos, active);
4758 SetGameStatus(game_status_last_screen);
4760 if (game_status == GAME_MODE_MAIN)
4761 InitializeMainControls();
4765 static void DrawTypeName(void)
4767 HandleTypeNameExt(TRUE, 0);
4770 void HandleTypeName(Key key)
4772 HandleTypeNameExt(FALSE, key);
4776 // ============================================================================
4777 // tree menu functions
4778 // ============================================================================
4780 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4782 if (game_status != GAME_MODE_SETUP ||
4783 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4786 int max_text_size = 0;
4789 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4790 max_text_size = MAX(max_text_size, strlen(node->name));
4792 int num_entries = numTreeInfoInGroup(ti);
4793 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4794 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4795 int text_width = max_text_size * getFontWidth(font_nr);
4796 int button_width = SC_MENUBUTTON_XSIZE;
4797 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4798 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4799 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4800 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4801 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4802 int align_xoffset = MAX(0, align_xoffset_raw);
4804 return align_xoffset;
4807 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4809 if (game_status != GAME_MODE_SETUP ||
4810 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4813 int num_entries = numTreeInfoInGroup(ti);
4814 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4815 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4816 int font_height = getFontHeight(font_nr);
4817 int text_height = font_height * num_page_entries;
4818 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4819 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4820 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4821 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4822 int align_yoffset = MAX(0, align_yoffset_raw);
4824 return align_yoffset;
4827 static void DrawChooseTree(TreeInfo **ti_ptr)
4829 int fade_mask = REDRAW_FIELD;
4832 fade_mask = REDRAW_ALL;
4834 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4836 if (game_status == GAME_MODE_SETUP)
4840 else // GAME_MODE_LEVELS
4842 SetGameStatus(GAME_MODE_MAIN);
4852 FreeScreenGadgets();
4853 CreateScreenGadgets();
4855 if (game_status != game_status_last_screen)
4856 FadeMenuSoundsAndMusic();
4860 // needed if different viewport properties defined for this screen
4861 ChangeViewportPropertiesIfNeeded();
4863 if (game_status == GAME_MODE_NAMES)
4864 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4865 else if (game_status == GAME_MODE_LEVELNR)
4866 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4867 else if (game_status == GAME_MODE_LEVELS)
4868 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4869 else if (game_status == GAME_MODE_SCORES)
4870 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4874 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4876 // map gadgets for high score screen
4877 if (game_status == GAME_MODE_SCORES)
4878 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4880 MapScreenTreeGadgets(*ti_ptr);
4882 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4884 DrawMaskedBorder(fade_mask);
4886 if (game_status != game_status_last_screen)
4887 PlayMenuSoundsAndMusic();
4892 static int getChooseTreeFont(TreeInfo *node, boolean active)
4894 if (game_status == GAME_MODE_SCORES)
4895 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4897 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4900 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4902 int num_entries = numTreeInfoInGroup(ti);
4903 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4904 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4905 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4906 int first_entry = ti->cl_first;
4907 int entry_pos = first_entry + y;
4908 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4909 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4910 int font_nr = getChooseTreeFont(node, active);
4911 int font_xoffset = getFontDrawOffsetX(font_nr);
4912 int xpos = MENU_SCREEN_START_XPOS;
4913 int ypos = MENU_SCREEN_START_YPOS + y;
4914 int startdx = xpos * 32;
4915 int startdy = ypos * 32;
4916 int startx = amSX + startdx;
4917 int starty = amSY + startdy;
4918 int startx_text = startx + font_xoffset;
4919 int endx_text = amSX + screen_width;
4920 int max_text_size = endx_text - startx_text;
4921 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4922 char buffer[max_buffer_len + 1];
4924 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4926 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4927 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4928 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4929 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4930 int font_size_1 = getFontWidth(font_nr1);
4931 int font_size_3 = getFontWidth(font_nr3);
4932 int font_size_4 = getFontWidth(font_nr4);
4933 int text_size_1 = 3 * font_size_1;
4934 int text_size_4 = 5 * font_size_4;
4935 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4937 int dx2 = text_size_1;
4938 int dx3 = dx2 + font_size_1;
4939 int dx4 = screen_width - startdx - 2 * border - text_size_4;
4940 int num_dots = (dx4 - dx3) / font_size_3;
4941 int startx1 = startx + dx1;
4942 int startx2 = startx + dx2;
4943 int startx3 = startx + dx3;
4944 int startx4 = startx + dx4;
4945 int pos = node->pos;
4946 boolean forced = (scores.force_last_added && pos == scores.last_added);
4947 char *pos_text = (forced ? "???" : int2str(pos + 1, 3));
4948 char *dot_text = ".";
4951 DrawText(startx1, starty, pos_text, font_nr1);
4952 DrawText(startx2, starty, dot_text, font_nr1);
4954 for (i = 0; i < num_dots; i++)
4955 DrawText(startx3 + i * font_size_3, starty, dot_text, font_nr3);
4957 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4958 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4960 DrawText(startx4, starty, getHallOfFameScoreText(pos), font_nr4);
4964 strncpy(buffer, node->name, max_buffer_len);
4965 buffer[max_buffer_len] = '\0';
4967 DrawText(startx, starty, buffer, font_nr);
4971 static void drawChooseTreeHeadExt(int type, char *title_string)
4973 int yoffset_sets = MENU_TITLE1_YPOS;
4974 int yoffset_setup = 16;
4975 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4976 type == TREE_TYPE_LEVEL_DIR ||
4977 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4979 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4982 static void drawChooseTreeHead(TreeInfo *ti)
4984 drawChooseTreeHeadExt(ti->type, ti->infotext);
4987 static void drawChooseTreeList(TreeInfo *ti)
4989 int first_entry = ti->cl_first;
4990 int num_entries = numTreeInfoInGroup(ti);
4991 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4994 clearMenuListArea();
4996 for (i = 0; i < num_page_entries; i++)
4998 TreeInfo *node, *node_first;
4999 int entry_pos = first_entry + i;
5001 node_first = getTreeInfoFirstGroupEntry(ti);
5002 node = getTreeInfoFromPos(node_first, entry_pos);
5004 drawChooseTreeText(ti, i, FALSE);
5006 if (node->parent_link)
5007 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5008 else if (node->level_group)
5009 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5011 initCursor(i, IMG_MENU_BUTTON);
5013 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
5014 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5016 if (game_status == GAME_MODE_NAMES)
5017 drawChooseTreeEdit(i, FALSE);
5020 redraw_mask |= REDRAW_FIELD;
5023 static void drawChooseTreeInfo(TreeInfo *ti)
5025 int entry_pos = ti->cl_first + ti->cl_cursor;
5026 int last_redraw_mask = redraw_mask;
5027 int ypos = MENU_TITLE2_YPOS;
5028 int font_nr = FONT_TITLE_2;
5031 if (ti->type == TREE_TYPE_LEVEL_NR)
5032 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
5034 if (ti->type == TREE_TYPE_SCORE_ENTRY)
5035 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
5036 scores.last_level_nr);
5038 if (ti->type != TREE_TYPE_LEVEL_DIR)
5041 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
5042 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
5044 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
5046 if (node->parent_link)
5047 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
5048 node->node_parent->name);
5049 else if (node->level_group)
5050 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
5052 else if (ti->type == TREE_TYPE_LEVEL_DIR)
5053 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
5054 node->levels, (node->levels > 1 ? "levels" : "level"),
5057 // let BackToFront() redraw only what is needed
5058 redraw_mask = last_redraw_mask;
5059 for (x = 0; x < SCR_FIELDX; x++)
5060 MarkTileDirty(x, 1);
5063 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
5065 drawChooseTreeCursor(ti->cl_cursor, active);
5066 drawChooseTreeText(ti, ti->cl_cursor, active);
5069 static void drawChooseTreeScreen(TreeInfo *ti)
5071 drawChooseTreeHead(ti);
5072 drawChooseTreeList(ti);
5073 drawChooseTreeInfo(ti);
5074 drawChooseTreeCursorAndText(ti, TRUE);
5076 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
5078 // scroll bar and buttons may just have been added after reloading scores
5079 if (game_status == GAME_MODE_SCORES)
5080 MapScreenTreeGadgets(ti);
5083 static void drawChooseTreeScreen_Scores_NotAvailable(void)
5085 // dirty workaround to use spacing definitions from info screen
5086 info_mode = INFO_MODE_TITLE;
5088 char *text_info = "HighScores of Level %d";
5089 char *text_title = "Score information:";
5090 char *text_error = "No scores for this level.";
5091 char *text_foot = "Press any key or button for main menu";
5092 int font_info = FONT_TITLE_2;
5093 int font_title = FONT_INITIAL_3;
5094 int font_error = FONT_INITIAL_4;
5095 int font_foot = FONT_INITIAL_2;
5096 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
5097 int ystep_title = getMenuTextStep(spacing_title, font_title);
5098 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
5099 int ystart2 = ystart1 + ystep_title;
5100 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
5101 int ystart0 = MENU_TITLE2_YPOS;
5103 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
5104 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
5106 DrawTextSCentered(ystart1, font_title, text_title);
5107 DrawTextSCentered(ystart2, font_error, text_error);
5109 DrawTextSCentered(ybottom, font_foot, text_foot);
5112 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
5114 // set current tree entry to last added score entry
5115 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(scores.last_added));
5117 // if that fails, set current tree entry to first entry (back link)
5118 if (*ti_ptr == NULL)
5119 *ti_ptr = score_entries->node_group;
5121 int num_entries = numTreeInfoInGroup(*ti_ptr);
5122 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5123 int pos_score = getPosFromTreeInfo(*ti_ptr);
5124 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5125 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5127 (*ti_ptr)->cl_first = pos_first;
5128 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5133 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5136 TreeInfo *ti = *ti_ptr;
5137 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5138 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5139 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5140 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5141 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5143 int y = (ti != NULL ? ti->cl_cursor : 0);
5144 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5145 int num_entries = numTreeInfoInGroup(ti);
5146 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5147 boolean position_set_by_scrollbar = (dx == 999);
5148 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5149 boolean button_is_valid = (mx >= 0 && my >= 0);
5150 boolean button_screen_clicked = (button_action && button_is_valid);
5152 if (game_status == GAME_MODE_SCORES)
5154 if (server_scores.updated)
5156 // reload scores, using updated server score cache file
5157 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5159 server_scores.updated = FALSE;
5161 DrawHallOfFame_setScoreEntries();
5163 if (score_entries != NULL)
5165 ti = setHallOfFameActiveEntry(ti_ptr);
5167 if (button != MB_MENU_INITIALIZE)
5168 drawChooseTreeScreen(ti);
5172 if (score_entries == NULL)
5174 if (button == MB_MENU_INITIALIZE)
5176 drawChooseTreeScreen_Scores_NotAvailable();
5178 else if (button_screen_clicked)
5180 PlaySound(SND_MENU_ITEM_SELECTING);
5182 SetGameStatus(GAME_MODE_MAIN);
5191 if (button == MB_MENU_INITIALIZE)
5193 int num_entries = numTreeInfoInGroup(ti);
5194 int entry_pos = getPosFromTreeInfo(ti);
5196 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5197 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5199 if (game_status == GAME_MODE_SCORES)
5201 ti = setHallOfFameActiveEntry(ti_ptr);
5203 else if (ti->cl_first == -1)
5205 // only on initialization
5206 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5207 ti->cl_cursor = entry_pos - ti->cl_first;
5210 else if (ti->cl_cursor >= num_page_entries ||
5211 (num_entries > num_page_entries &&
5212 num_entries - ti->cl_first < num_page_entries))
5214 // only after change of list size (by custom graphic configuration)
5215 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5216 ti->cl_cursor = entry_pos - ti->cl_first;
5219 if (position_set_by_scrollbar)
5222 drawChooseTreeScreen(ti);
5226 else if (button == MB_MENU_LEAVE)
5228 if (game_status != GAME_MODE_SCORES)
5231 PlaySound(SND_MENU_ITEM_SELECTING);
5233 if (ti->node_parent)
5235 *ti_ptr = ti->node_parent;
5236 DrawChooseTree(ti_ptr);
5238 else if (game_status == GAME_MODE_SETUP)
5240 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5241 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5242 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5243 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5245 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5246 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5247 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5248 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5249 execSetupGraphics();
5250 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5251 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5252 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5254 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5255 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5256 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5257 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5258 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5259 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5260 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5261 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5268 if (game_status == GAME_MODE_LEVELNR)
5270 int new_level_nr = atoi(level_number_current->identifier);
5272 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5275 SetGameStatus(GAME_MODE_MAIN);
5283 if (mx || my) // mouse input
5285 x = (mx - amSX) / 32;
5286 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5288 if (game_status == GAME_MODE_NAMES)
5289 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5291 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5293 // move cursor instead of scrolling when already at start/end of list
5294 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5296 else if (dy == +1 * SCROLL_LINE &&
5297 ti->cl_first + num_page_entries == num_entries)
5300 // handle scrolling screen one line or page
5301 if (ti->cl_cursor + dy < 0 ||
5302 ti->cl_cursor + dy > num_page_entries - 1)
5304 boolean redraw = FALSE;
5306 if (ABS(dy) == SCROLL_PAGE)
5307 step = num_page_entries - 1;
5309 if (dy < 0 && ti->cl_first > 0)
5311 // scroll page/line up
5313 ti->cl_first -= step;
5314 if (ti->cl_first < 0)
5319 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5321 // scroll page/line down
5323 ti->cl_first += step;
5324 if (ti->cl_first + num_page_entries > num_entries)
5325 ti->cl_first = MAX(0, num_entries - num_page_entries);
5331 drawChooseTreeScreen(ti);
5336 // handle moving cursor one line
5337 y = ti->cl_cursor + dy;
5340 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5342 HandleHallOfFame_SelectLevel(1, dx);
5348 TreeInfo *node_first, *node_cursor;
5349 int entry_pos = ti->cl_first + y;
5351 node_first = getTreeInfoFirstGroupEntry(ti);
5352 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5354 if (node_cursor->node_group)
5358 PlaySound(SND_MENU_ITEM_SELECTING);
5360 node_cursor->cl_first = ti->cl_first;
5361 node_cursor->cl_cursor = ti->cl_cursor;
5362 *ti_ptr = node_cursor->node_group;
5363 DrawChooseTree(ti_ptr);
5368 else if (dx == -1 && ti->node_parent)
5372 PlaySound(SND_MENU_ITEM_SELECTING);
5374 *ti_ptr = ti->node_parent;
5375 DrawChooseTree(ti_ptr);
5380 if (!anyScrollbarGadgetActive() &&
5381 IN_VIS_MENU(x, y) &&
5382 mx < mx_right_border &&
5383 y >= 0 && y < num_page_entries)
5387 if (game_status == GAME_MODE_NAMES)
5389 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5390 drawChooseTreeEdit(y, TRUE);
5393 if (y != ti->cl_cursor)
5395 PlaySound(SND_MENU_ITEM_ACTIVATING);
5397 drawChooseTreeCursorAndText(ti, FALSE);
5401 drawChooseTreeCursorAndText(ti, TRUE);
5403 drawChooseTreeInfo(ti);
5407 if (game_status == GAME_MODE_SETUP)
5409 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5410 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5411 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5412 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5414 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5415 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5416 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5417 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5418 execSetupGraphics();
5419 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5420 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5421 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5423 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5424 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5425 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5426 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5427 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5428 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5429 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5430 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5439 TreeInfo *node_first, *node_cursor;
5440 int entry_pos = ti->cl_first + y;
5442 PlaySound(SND_MENU_ITEM_SELECTING);
5444 node_first = getTreeInfoFirstGroupEntry(ti);
5445 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5447 if (node_cursor->node_group)
5451 node_cursor->cl_first = ti->cl_first;
5452 node_cursor->cl_cursor = ti->cl_cursor;
5453 *ti_ptr = node_cursor->node_group;
5454 DrawChooseTree(ti_ptr);
5456 else if (node_cursor->parent_link)
5458 if (game_status != GAME_MODE_SCORES)
5461 *ti_ptr = node_cursor->node_parent;
5462 DrawChooseTree(ti_ptr);
5466 if (game_status != GAME_MODE_SCORES)
5469 node_cursor->cl_first = ti->cl_first;
5470 node_cursor->cl_cursor = ti->cl_cursor;
5471 *ti_ptr = node_cursor;
5473 if (ti->type == TREE_TYPE_LEVEL_DIR)
5475 LoadLevelSetup_SeriesInfo();
5477 SaveLevelSetup_LastSeries();
5478 SaveLevelSetup_SeriesInfo();
5482 if (game_status == GAME_MODE_SETUP)
5484 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5485 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5486 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5487 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5489 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5490 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5491 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5492 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5493 execSetupGraphics();
5494 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5495 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5496 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5498 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5499 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5500 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5501 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5502 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5503 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5504 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5505 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5512 if (game_status == GAME_MODE_LEVELNR)
5514 int new_level_nr = atoi(level_number_current->identifier);
5516 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5518 else if (game_status == GAME_MODE_LEVELS)
5520 // store level set if chosen from "last played level set" menu
5521 StoreLastPlayedLevels(leveldir_current);
5523 else if (game_status == GAME_MODE_NAMES)
5525 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5527 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5534 // change active user to selected user
5535 user.nr = entry_pos;
5537 // save number of new active user
5540 // load setup of new active user
5543 // load last level set of new active user
5544 LoadLevelSetup_LastSeries();
5545 LoadLevelSetup_SeriesInfo();
5547 // update list of last played level sets
5548 UpdateLastPlayedLevels_TreeInfo();
5552 ToggleFullscreenIfNeeded();
5553 ChangeWindowScalingIfNeeded();
5555 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5556 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5557 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5559 else if (game_status == GAME_MODE_SCORES)
5561 if (game_status_last_screen == GAME_MODE_PLAYING &&
5562 setup.auto_play_next_level && setup.increment_levels &&
5563 scores.last_level_nr < leveldir_current->last_level &&
5566 StartGameActions(network.enabled, setup.autorecord,
5572 SetGameStatus(GAME_MODE_SCOREINFO);
5574 DrawScoreInfo(node_cursor->pos);
5580 SetGameStatus(GAME_MODE_MAIN);
5588 if (game_status == GAME_MODE_SCORES)
5589 PlayMenuSoundIfLoop();
5592 void DrawChoosePlayerName(void)
5596 if (player_name != NULL)
5598 freeTreeInfo(player_name);
5603 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5605 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5606 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5609 ti->node_top = &player_name;
5610 ti->sort_priority = 10000 + value;
5611 ti->color = getPlayerNameColor(global.user_names[i]);
5613 snprintf(identifier, sizeof(identifier), "%d", value);
5614 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5616 setString(&ti->identifier, identifier);
5617 setString(&ti->name, name);
5618 setString(&ti->name_sorting, name);
5620 pushTreeInfo(&player_name, ti);
5623 // sort player entries by player number
5624 sortTreeInfo(&player_name);
5626 // set current player entry to selected player entry
5627 player_name_current =
5628 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5630 // if that fails, set current player name to first available name
5631 if (player_name_current == NULL)
5632 player_name_current = player_name;
5634 DrawChooseTree(&player_name_current);
5637 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5639 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5642 void DrawChooseLevelSet(void)
5644 DrawChooseTree(&leveldir_current);
5647 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5649 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5652 void DrawChooseLevelNr(void)
5656 if (level_number != NULL)
5658 freeTreeInfo(level_number);
5660 level_number = NULL;
5663 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5665 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5666 char identifier[32], name[64];
5669 // temporarily load level info to get level name
5670 LoadLevelInfoOnly(i);
5672 ti->node_top = &level_number;
5673 ti->sort_priority = 10000 + value;
5674 ti->color = (level.no_level_file ? FC_BLUE :
5675 LevelStats_getSolved(i) ? FC_GREEN :
5676 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5678 snprintf(identifier, sizeof(identifier), "%d", value);
5679 snprintf(name, sizeof(name), "%03d: %s", value,
5680 (level.no_level_file ? "(no file)" : level.name));
5682 setString(&ti->identifier, identifier);
5683 setString(&ti->name, name);
5684 setString(&ti->name_sorting, name);
5686 pushTreeInfo(&level_number, ti);
5689 // sort level number values to start with lowest level number
5690 sortTreeInfo(&level_number);
5692 // set current level number to current level number
5693 level_number_current =
5694 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5696 // if that also fails, set current level number to first available level
5697 if (level_number_current == NULL)
5698 level_number_current = level_number;
5700 DrawChooseTree(&level_number_current);
5703 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5705 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5708 static void DrawHallOfFame_setScoreEntries(void)
5710 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5713 if (score_entries != NULL)
5715 freeTreeInfo(score_entries);
5717 score_entries = NULL;
5720 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5722 // do not add empty score entries
5723 if (scores.entry[i].score == 0 &&
5724 scores.entry[i].time == 0)
5727 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5728 char identifier[32], name[64];
5731 ti->node_top = &score_entries;
5732 ti->sort_priority = 10000 + value;
5733 ti->color = FC_YELLOW;
5736 snprintf(identifier, sizeof(identifier), "%d", value);
5737 snprintf(name, sizeof(name), "%03d.", value + 1);
5739 setString(&ti->identifier, identifier);
5740 setString(&ti->name, name);
5741 setString(&ti->name_sorting, name);
5743 pushTreeInfo(&score_entries, ti);
5746 // sort score entries to start with highest score entry
5747 sortTreeInfo(&score_entries);
5749 // add top tree node to create back link to main menu
5750 score_entries = addTopTreeInfoNode(score_entries);
5752 // set current score entry to last added or highest score entry
5753 score_entry_current =
5754 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5756 // if that fails, set current score entry to first valid score entry
5757 if (score_entry_current == NULL)
5758 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5760 // ("score_entries" and "score_entry_current" may be NULL here)
5763 void DrawHallOfFame(int level_nr)
5765 scores.last_level_nr = level_nr;
5767 // (this is needed when called from GameEnd() after winning a game)
5768 KeyboardAutoRepeatOn();
5770 // (this is needed when called from GameEnd() after winning a game)
5771 SetDrawDeactivationMask(REDRAW_NONE);
5772 SetDrawBackgroundMask(REDRAW_FIELD);
5774 LoadLocalAndServerScore(level_nr, TRUE);
5776 DrawHallOfFame_setScoreEntries();
5778 if (scores.last_added >= 0)
5779 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5781 FadeSetEnterScreen();
5783 DrawChooseTree(&score_entry_current);
5786 static char *getHallOfFameTimeText(int nr)
5788 static char score_text[10];
5789 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5790 int mm = (time_seconds / 60) % 60;
5791 int ss = (time_seconds % 60);
5793 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5798 static char *getHallOfFameScoreText(int nr)
5800 if (!level.rate_time_over_score)
5801 return int2str(scores.entry[nr].score, 5); // show normal score
5802 else if (level.use_step_counter)
5803 return int2str(scores.entry[nr].time, 5); // show number of steps
5805 return getHallOfFameTimeText(nr); // show playing time
5808 static void HandleHallOfFame_SelectLevel(int step, int direction)
5810 int old_level_nr = scores.last_level_nr;
5811 int new_level_nr = old_level_nr + step * direction;
5813 if (new_level_nr < leveldir_current->first_level)
5814 new_level_nr = leveldir_current->first_level;
5815 if (new_level_nr > leveldir_current->last_level)
5816 new_level_nr = leveldir_current->last_level;
5818 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5819 new_level_nr = leveldir_current->handicap_level;
5821 if (new_level_nr != old_level_nr)
5823 PlaySound(SND_MENU_ITEM_SELECTING);
5825 scores.last_level_nr = level_nr = new_level_nr;
5827 LoadLocalAndServerScore(level_nr, TRUE);
5829 DrawHallOfFame_setScoreEntries();
5831 // force remapping optional gadgets (especially scroll bar)
5832 UnmapScreenTreeGadgets();
5834 // redraw complete high score screen, as sub-title has changed
5837 // redraw level selection buttons (which have just been erased)
5838 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5840 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5842 SaveLevelSetup_SeriesInfo();
5846 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5848 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5851 static void DrawScoreInfo(int entry_nr)
5853 struct ScoreEntry *entry = &scores.entry[entry_nr];
5854 boolean forced = (scores.force_last_added && entry_nr == scores.last_added);
5855 char *pos_text = (forced ? "???" : int2str(entry_nr + 1, 3));
5856 int font_title = MENU_INFO_FONT_TITLE;
5857 int font_head = MENU_INFO_FONT_HEAD;
5858 int font_text = MENU_INFO_FONT_TEXT;
5859 int font_foot = MENU_INFO_FONT_FOOT;
5860 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5861 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5862 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5863 int xstep = getFontWidth(font_text);
5864 int ystep_title = getMenuTextStep(spacing_title, font_title);
5865 int ystep_para = getMenuTextStep(spacing_para, font_text);
5866 int ystep_line = getMenuTextStep(spacing_line, font_text);
5867 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5868 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5869 int xstart1 = mSX - SX + 2 * xstep;
5870 int xstart2 = mSX - SX + 14 * xstep;
5872 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5876 FadeOut(REDRAW_FIELD);
5880 drawChooseTreeHead(score_entries);
5881 drawChooseTreeInfo(score_entries);
5883 DrawTextSCentered(ystart, font_title, "Score Information:");
5884 ystart += ystep_title;
5886 DrawTextF(xstart1, ystart, font_head, "Level Set");
5887 DrawTextF(xstart2, ystart, font_text, leveldir_current->name);
5888 ystart += ystep_line;
5890 DrawTextF(xstart1, ystart, font_head, "Level Name");
5891 DrawTextF(xstart2, ystart, font_text, level.name);
5892 ystart += ystep_para;
5894 DrawTextF(xstart1, ystart, font_head, "Rank");
5895 DrawTextF(xstart2, ystart, font_text, pos_text);
5896 ystart += ystep_line;
5898 DrawTextF(xstart1, ystart, font_head, "Player");
5899 DrawTextF(xstart2, ystart, font_text, entry->name);
5900 ystart += ystep_line;
5902 if (level.use_step_counter)
5904 DrawTextF(xstart1, ystart, font_head, "Steps");
5905 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5906 ystart += ystep_line;
5910 DrawTextF(xstart1, ystart, font_head, "Time");
5911 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5912 ystart += ystep_line;
5915 if (!level.rate_time_over_score || entry->score > 0)
5917 DrawTextF(xstart1, ystart, font_head, "Score");
5918 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5919 ystart += ystep_line;
5922 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5924 FadeIn(REDRAW_FIELD);
5927 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5929 if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5931 PlaySound(SND_MENU_ITEM_SELECTING);
5933 SetGameStatus(GAME_MODE_SCORES);
5935 DrawHallOfFame(level_nr);
5940 // ============================================================================
5941 // setup screen functions
5942 // ============================================================================
5944 static struct TokenInfo *setup_info;
5945 static int num_setup_info; // number of setup entries shown on screen
5946 static int max_setup_info; // total number of setup entries in list
5948 static char *window_size_text;
5949 static char *scaling_type_text;
5950 static char *rendering_mode_text;
5951 static char *vsync_mode_text;
5952 static char *scroll_delay_text;
5953 static char *snapshot_mode_text;
5954 static char *game_speed_text;
5955 static char *scores_type_text;
5956 static char *network_server_text;
5957 static char *graphics_set_name;
5958 static char *sounds_set_name;
5959 static char *music_set_name;
5960 static char *volume_simple_text;
5961 static char *volume_loops_text;
5962 static char *volume_music_text;
5963 static char *touch_controls_text;
5964 static char *move_distance_text;
5965 static char *drop_distance_text;
5966 static char *transparency_text;
5967 static char *grid_size_text[2][2];
5969 static void execSetupMain(void)
5971 setup_mode = SETUP_MODE_MAIN;
5976 static void execSetupGame_setScoresType(void)
5978 if (scores_types == NULL)
5982 for (i = 0; scores_types_list[i].value != NULL; i++)
5984 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5985 char identifier[32], name[32];
5986 char *value = scores_types_list[i].value;
5987 char *text = scores_types_list[i].text;
5989 ti->node_top = &scores_types;
5990 ti->sort_priority = i;
5992 sprintf(identifier, "%s", value);
5993 sprintf(name, "%s", text);
5995 setString(&ti->identifier, identifier);
5996 setString(&ti->name, name);
5997 setString(&ti->name_sorting, name);
5998 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
6000 pushTreeInfo(&scores_types, ti);
6003 // sort scores type values to start with lowest scores type value
6004 sortTreeInfo(&scores_types);
6006 // set current scores type value to configured scores type value
6007 scores_type_current =
6008 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
6010 // if that fails, set current scores type to reliable default value
6011 if (scores_type_current == NULL)
6012 scores_type_current =
6013 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
6015 // if that also fails, set current scores type to first available value
6016 if (scores_type_current == NULL)
6017 scores_type_current = scores_types;
6020 setup.scores_in_highscore_list = scores_type_current->identifier;
6022 // needed for displaying scores type text instead of identifier
6023 scores_type_text = scores_type_current->name;
6026 static void execSetupGame_setGameSpeeds(boolean update_value)
6028 if (setup.game_speed_extended)
6030 game_speeds_list = game_speeds_list_extended;
6031 game_speeds = game_speeds_extended;
6035 game_speeds_list = game_speeds_list_normal;
6036 game_speeds = game_speeds_normal;
6039 if (game_speeds == NULL)
6043 for (i = 0; game_speeds_list[i].value != -1; i++)
6045 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6046 char identifier[32], name[32];
6047 int value = game_speeds_list[i].value;
6048 char *text = game_speeds_list[i].text;
6050 ti->node_top = &game_speeds;
6051 ti->sort_priority = 10000 - value;
6053 sprintf(identifier, "%d", value);
6054 sprintf(name, "%s", text);
6056 setString(&ti->identifier, identifier);
6057 setString(&ti->name, name);
6058 setString(&ti->name_sorting, name);
6059 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
6061 pushTreeInfo(&game_speeds, ti);
6064 // sort game speed values to start with slowest game speed
6065 sortTreeInfo(&game_speeds);
6067 update_value = TRUE;
6072 // set current game speed to configured game speed value
6073 game_speed_current =
6074 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6076 // if that fails, set current game speed to reliable default value
6077 if (game_speed_current == NULL)
6078 game_speed_current =
6079 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6081 // if that also fails, set current game speed to first available speed
6082 if (game_speed_current == NULL)
6083 game_speed_current = game_speeds;
6085 if (setup.game_speed_extended)
6086 game_speeds_extended = game_speeds;
6088 game_speeds_normal = game_speeds;
6091 setup.game_frame_delay = atoi(game_speed_current->identifier);
6093 // needed for displaying game speed text instead of identifier
6094 game_speed_text = game_speed_current->name;
6097 static void execSetupGame_setScrollDelays(void)
6099 if (scroll_delays == NULL)
6103 for (i = 0; scroll_delays_list[i].value != -1; i++)
6105 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6106 char identifier[32], name[32];
6107 int value = scroll_delays_list[i].value;
6108 char *text = scroll_delays_list[i].text;
6110 ti->node_top = &scroll_delays;
6111 ti->sort_priority = value;
6113 sprintf(identifier, "%d", value);
6114 sprintf(name, "%s", text);
6116 setString(&ti->identifier, identifier);
6117 setString(&ti->name, name);
6118 setString(&ti->name_sorting, name);
6119 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6121 pushTreeInfo(&scroll_delays, ti);
6124 // sort scroll delay values to start with lowest scroll delay value
6125 sortTreeInfo(&scroll_delays);
6127 // set current scroll delay value to configured scroll delay value
6128 scroll_delay_current =
6129 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6131 // if that fails, set current scroll delay to reliable default value
6132 if (scroll_delay_current == NULL)
6133 scroll_delay_current =
6134 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6136 // if that also fails, set current scroll delay to first available value
6137 if (scroll_delay_current == NULL)
6138 scroll_delay_current = scroll_delays;
6141 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6143 // needed for displaying scroll delay text instead of identifier
6144 scroll_delay_text = scroll_delay_current->name;
6147 static void execSetupGame_setSnapshotModes(void)
6149 if (snapshot_modes == NULL)
6153 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6155 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6156 char identifier[32], name[32];
6157 char *value = snapshot_modes_list[i].value;
6158 char *text = snapshot_modes_list[i].text;
6160 ti->node_top = &snapshot_modes;
6161 ti->sort_priority = i;
6163 sprintf(identifier, "%s", value);
6164 sprintf(name, "%s", text);
6166 setString(&ti->identifier, identifier);
6167 setString(&ti->name, name);
6168 setString(&ti->name_sorting, name);
6169 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6171 pushTreeInfo(&snapshot_modes, ti);
6174 // sort snapshot mode values to start with lowest snapshot mode value
6175 sortTreeInfo(&snapshot_modes);
6177 // set current snapshot mode value to configured snapshot mode value
6178 snapshot_mode_current =
6179 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6181 // if that fails, set current snapshot mode to reliable default value
6182 if (snapshot_mode_current == NULL)
6183 snapshot_mode_current =
6184 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6186 // if that also fails, set current snapshot mode to first available value
6187 if (snapshot_mode_current == NULL)
6188 snapshot_mode_current = snapshot_modes;
6191 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6193 // needed for displaying snapshot mode text instead of identifier
6194 snapshot_mode_text = snapshot_mode_current->name;
6197 static void execSetupGame_setNetworkServerText(void)
6199 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6201 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6205 strncpy(network_server_hostname, setup.network_server_hostname,
6206 MAX_SETUP_TEXT_INPUT_LEN);
6207 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6210 // needed for displaying network server text instead of identifier
6211 network_server_text = network_server_hostname;
6214 static void execSetupGame(void)
6216 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6218 execSetupGame_setGameSpeeds(FALSE);
6219 execSetupGame_setScoresType();
6220 execSetupGame_setScrollDelays();
6221 execSetupGame_setSnapshotModes();
6223 execSetupGame_setNetworkServerText();
6225 if (!setup.provide_uploading_tapes)
6226 setHideSetupEntry(execOfferUploadTapes);
6228 setup_mode = SETUP_MODE_GAME;
6232 // check if vsync needs to be disabled for this game speed to work
6233 if (check_vsync_mode)
6234 DisableVsyncIfNeeded();
6237 static void execSetupChooseScoresType(void)
6239 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6244 static void execSetupChooseGameSpeed(void)
6246 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6251 static void execSetupChooseScrollDelay(void)
6253 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6258 static void execSetupChooseSnapshotMode(void)
6260 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6265 static void execSetupEngines(void)
6267 setup_mode = SETUP_MODE_ENGINES;
6272 static void execSetupEditor(void)
6274 setup_mode = SETUP_MODE_EDITOR;
6279 static void execSetupGraphics_setWindowSizes(boolean update_list)
6281 if (window_sizes != NULL && update_list)
6283 freeTreeInfo(window_sizes);
6285 window_sizes = NULL;
6288 if (window_sizes == NULL)
6290 boolean current_window_size_found = FALSE;
6293 for (i = 0; window_sizes_list[i].value != -1; i++)
6295 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6296 char identifier[32], name[32];
6297 int value = window_sizes_list[i].value;
6298 char *text = window_sizes_list[i].text;
6300 ti->node_top = &window_sizes;
6301 ti->sort_priority = value;
6303 sprintf(identifier, "%d", value);
6304 sprintf(name, "%s", text);
6306 setString(&ti->identifier, identifier);
6307 setString(&ti->name, name);
6308 setString(&ti->name_sorting, name);
6309 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6311 pushTreeInfo(&window_sizes, ti);
6313 if (value == setup.window_scaling_percent)
6314 current_window_size_found = TRUE;
6317 if (!current_window_size_found)
6319 // add entry for non-preset window scaling value
6321 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6322 char identifier[32], name[32];
6323 int value = setup.window_scaling_percent;
6325 ti->node_top = &window_sizes;
6326 ti->sort_priority = value;
6328 sprintf(identifier, "%d", value);
6329 sprintf(name, "%d %% (Current)", value);
6331 setString(&ti->identifier, identifier);
6332 setString(&ti->name, name);
6333 setString(&ti->name_sorting, name);
6334 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6336 pushTreeInfo(&window_sizes, ti);
6339 // sort window size values to start with lowest window size value
6340 sortTreeInfo(&window_sizes);
6342 // set current window size value to configured window size value
6343 window_size_current =
6344 getTreeInfoFromIdentifier(window_sizes,
6345 i_to_a(setup.window_scaling_percent));
6347 // if that fails, set current window size to reliable default value
6348 if (window_size_current == NULL)
6349 window_size_current =
6350 getTreeInfoFromIdentifier(window_sizes,
6351 i_to_a(STD_WINDOW_SCALING_PERCENT));
6353 // if that also fails, set current window size to first available value
6354 if (window_size_current == NULL)
6355 window_size_current = window_sizes;
6358 setup.window_scaling_percent = atoi(window_size_current->identifier);
6360 // needed for displaying window size text instead of identifier
6361 window_size_text = window_size_current->name;
6364 static void execSetupGraphics_setScalingTypes(void)
6366 if (scaling_types == NULL)
6370 for (i = 0; scaling_types_list[i].value != NULL; i++)
6372 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6373 char identifier[32], name[32];
6374 char *value = scaling_types_list[i].value;
6375 char *text = scaling_types_list[i].text;
6377 ti->node_top = &scaling_types;
6378 ti->sort_priority = i;
6380 sprintf(identifier, "%s", value);
6381 sprintf(name, "%s", text);
6383 setString(&ti->identifier, identifier);
6384 setString(&ti->name, name);
6385 setString(&ti->name_sorting, name);
6386 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6388 pushTreeInfo(&scaling_types, ti);
6391 // sort scaling type values to start with lowest scaling type value
6392 sortTreeInfo(&scaling_types);
6394 // set current scaling type value to configured scaling type value
6395 scaling_type_current =
6396 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6398 // if that fails, set current scaling type to reliable default value
6399 if (scaling_type_current == NULL)
6400 scaling_type_current =
6401 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6403 // if that also fails, set current scaling type to first available value
6404 if (scaling_type_current == NULL)
6405 scaling_type_current = scaling_types;
6408 setup.window_scaling_quality = scaling_type_current->identifier;
6410 // needed for displaying scaling type text instead of identifier
6411 scaling_type_text = scaling_type_current->name;
6414 static void execSetupGraphics_setRenderingModes(void)
6416 if (rendering_modes == NULL)
6420 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6422 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6423 char identifier[32], name[32];
6424 char *value = rendering_modes_list[i].value;
6425 char *text = rendering_modes_list[i].text;
6427 ti->node_top = &rendering_modes;
6428 ti->sort_priority = i;
6430 sprintf(identifier, "%s", value);
6431 sprintf(name, "%s", text);
6433 setString(&ti->identifier, identifier);
6434 setString(&ti->name, name);
6435 setString(&ti->name_sorting, name);
6436 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6438 pushTreeInfo(&rendering_modes, ti);
6441 // sort rendering mode values to start with lowest rendering mode value
6442 sortTreeInfo(&rendering_modes);
6444 // set current rendering mode value to configured rendering mode value
6445 rendering_mode_current =
6446 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6448 // if that fails, set current rendering mode to reliable default value
6449 if (rendering_mode_current == NULL)
6450 rendering_mode_current =
6451 getTreeInfoFromIdentifier(rendering_modes,
6452 STR_SPECIAL_RENDERING_DEFAULT);
6454 // if that also fails, set current rendering mode to first available one
6455 if (rendering_mode_current == NULL)
6456 rendering_mode_current = rendering_modes;
6459 setup.screen_rendering_mode = rendering_mode_current->identifier;
6461 // needed for displaying rendering mode text instead of identifier
6462 rendering_mode_text = rendering_mode_current->name;
6465 static void execSetupGraphics_setVsyncModes(boolean update_value)
6467 if (vsync_modes == NULL)
6471 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6473 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6474 char identifier[32], name[32];
6475 char *value = vsync_modes_list[i].value;
6476 char *text = vsync_modes_list[i].text;
6478 ti->node_top = &vsync_modes;
6479 ti->sort_priority = i;
6481 sprintf(identifier, "%s", value);
6482 sprintf(name, "%s", text);
6484 setString(&ti->identifier, identifier);
6485 setString(&ti->name, name);
6486 setString(&ti->name_sorting, name);
6487 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6489 pushTreeInfo(&vsync_modes, ti);
6492 // sort vsync mode values to start with lowest vsync mode value
6493 sortTreeInfo(&vsync_modes);
6495 update_value = TRUE;
6500 // set current vsync mode value to configured vsync mode value
6501 vsync_mode_current =
6502 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6504 // if that fails, set current vsync mode to reliable default value
6505 if (vsync_mode_current == NULL)
6506 vsync_mode_current =
6507 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6509 // if that also fails, set current vsync mode to first available one
6510 if (vsync_mode_current == NULL)
6511 vsync_mode_current = vsync_modes;
6514 setup.vsync_mode = vsync_mode_current->identifier;
6516 // needed for displaying vsync mode text instead of identifier
6517 vsync_mode_text = vsync_mode_current->name;
6520 static void execSetupGraphics(void)
6522 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6524 // update "setup.window_scaling_percent" from list selection
6525 // (in this case, window scaling was changed on setup screen)
6526 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6527 execSetupGraphics_setWindowSizes(FALSE);
6529 // update "setup.vsync_mode" from list selection
6530 // (in this case, vsync mode was changed on setup screen)
6531 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6532 execSetupGraphics_setVsyncModes(FALSE);
6534 // update list selection from "setup.window_scaling_percent"
6535 // (window scaling may have changed by resizing the window)
6536 execSetupGraphics_setWindowSizes(TRUE);
6538 // update list selection from "setup.vsync_mode"
6539 // (vsync_mode may have changed by re-creating the renderer)
6540 execSetupGraphics_setVsyncModes(TRUE);
6542 execSetupGraphics_setScalingTypes();
6543 execSetupGraphics_setRenderingModes();
6545 setup_mode = SETUP_MODE_GRAPHICS;
6549 // check if game speed is high enough for 60 Hz vsync to work
6550 if (check_game_speed)
6551 ModifyGameSpeedIfNeeded();
6553 // window scaling may have changed at this point
6554 ChangeWindowScalingIfNeeded();
6556 // window scaling quality may have changed at this point
6557 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6558 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6560 // screen rendering mode may have changed at this point
6561 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6563 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6564 int video_vsync_mode = video.vsync_mode;
6566 // screen vsync mode may have changed at this point
6567 ChangeVsyncModeIfNeeded();
6569 // check if setting vsync mode to selected value failed
6570 if (setup_vsync_mode != video_vsync_mode &&
6571 setup_vsync_mode != video.vsync_mode)
6573 // changing vsync mode to selected value failed -- reset displayed value
6574 execSetupGraphics_setVsyncModes(TRUE);
6576 Request("Setting VSync failed!", REQ_CONFIRM);
6582 static void execSetupChooseWindowSize(void)
6584 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6589 static void execSetupChooseScalingType(void)
6591 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6596 static void execSetupChooseRenderingMode(void)
6598 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6603 static void execSetupChooseVsyncMode(void)
6605 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6610 static void execSetupChooseVolumeSimple(void)
6612 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6617 static void execSetupChooseVolumeLoops(void)
6619 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6624 static void execSetupChooseVolumeMusic(void)
6626 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6631 static void execSetupSound(void)
6633 if (volumes_simple == NULL)
6635 boolean current_volume_simple_found = FALSE;
6638 for (i = 0; volumes_list[i].value != -1; i++)
6640 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6641 char identifier[32], name[32];
6642 int value = volumes_list[i].value;
6643 char *text = volumes_list[i].text;
6645 ti->node_top = &volumes_simple;
6646 ti->sort_priority = value;
6648 sprintf(identifier, "%d", value);
6649 sprintf(name, "%s", text);
6651 setString(&ti->identifier, identifier);
6652 setString(&ti->name, name);
6653 setString(&ti->name_sorting, name);
6654 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6656 pushTreeInfo(&volumes_simple, ti);
6658 if (value == setup.volume_simple)
6659 current_volume_simple_found = TRUE;
6662 if (!current_volume_simple_found)
6664 // add entry for non-preset volume value
6666 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6667 char identifier[32], name[32];
6668 int value = setup.volume_simple;
6670 ti->node_top = &volumes_simple;
6671 ti->sort_priority = value;
6673 sprintf(identifier, "%d", value);
6674 sprintf(name, "%d %% (Current)", value);
6676 setString(&ti->identifier, identifier);
6677 setString(&ti->name, name);
6678 setString(&ti->name_sorting, name);
6679 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6681 pushTreeInfo(&volumes_simple, ti);
6684 // sort volume values to start with lowest volume value
6685 sortTreeInfo(&volumes_simple);
6687 // set current volume value to configured volume value
6688 volume_simple_current =
6689 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6691 // if that fails, set current volume to reliable default value
6692 if (volume_simple_current == NULL)
6693 volume_simple_current =
6694 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6696 // if that also fails, set current volume to first available value
6697 if (volume_simple_current == NULL)
6698 volume_simple_current = volumes_simple;
6701 if (volumes_loops == NULL)
6703 boolean current_volume_loops_found = FALSE;
6706 for (i = 0; volumes_list[i].value != -1; i++)
6708 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6709 char identifier[32], name[32];
6710 int value = volumes_list[i].value;
6711 char *text = volumes_list[i].text;
6713 ti->node_top = &volumes_loops;
6714 ti->sort_priority = value;
6716 sprintf(identifier, "%d", value);
6717 sprintf(name, "%s", text);
6719 setString(&ti->identifier, identifier);
6720 setString(&ti->name, name);
6721 setString(&ti->name_sorting, name);
6722 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6724 pushTreeInfo(&volumes_loops, ti);
6726 if (value == setup.volume_loops)
6727 current_volume_loops_found = TRUE;
6730 if (!current_volume_loops_found)
6732 // add entry for non-preset volume value
6734 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6735 char identifier[32], name[32];
6736 int value = setup.volume_loops;
6738 ti->node_top = &volumes_loops;
6739 ti->sort_priority = value;
6741 sprintf(identifier, "%d", value);
6742 sprintf(name, "%d %% (Current)", value);
6744 setString(&ti->identifier, identifier);
6745 setString(&ti->name, name);
6746 setString(&ti->name_sorting, name);
6747 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6749 pushTreeInfo(&volumes_loops, ti);
6752 // sort volume values to start with lowest volume value
6753 sortTreeInfo(&volumes_loops);
6755 // set current volume value to configured volume value
6756 volume_loops_current =
6757 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6759 // if that fails, set current volume to reliable default value
6760 if (volume_loops_current == NULL)
6761 volume_loops_current =
6762 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6764 // if that also fails, set current volume to first available value
6765 if (volume_loops_current == NULL)
6766 volume_loops_current = volumes_loops;
6769 if (volumes_music == NULL)
6771 boolean current_volume_music_found = FALSE;
6774 for (i = 0; volumes_list[i].value != -1; i++)
6776 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6777 char identifier[32], name[32];
6778 int value = volumes_list[i].value;
6779 char *text = volumes_list[i].text;
6781 ti->node_top = &volumes_music;
6782 ti->sort_priority = value;
6784 sprintf(identifier, "%d", value);
6785 sprintf(name, "%s", text);
6787 setString(&ti->identifier, identifier);
6788 setString(&ti->name, name);
6789 setString(&ti->name_sorting, name);
6790 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6792 pushTreeInfo(&volumes_music, ti);
6794 if (value == setup.volume_music)
6795 current_volume_music_found = TRUE;
6798 if (!current_volume_music_found)
6800 // add entry for non-preset volume value
6802 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6803 char identifier[32], name[32];
6804 int value = setup.volume_music;
6806 ti->node_top = &volumes_music;
6807 ti->sort_priority = value;
6809 sprintf(identifier, "%d", value);
6810 sprintf(name, "%d %% (Current)", value);
6812 setString(&ti->identifier, identifier);
6813 setString(&ti->name, name);
6814 setString(&ti->name_sorting, name);
6815 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6817 pushTreeInfo(&volumes_music, ti);
6820 // sort volume values to start with lowest volume value
6821 sortTreeInfo(&volumes_music);
6823 // set current volume value to configured volume value
6824 volume_music_current =
6825 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6827 // if that fails, set current volume to reliable default value
6828 if (volume_music_current == NULL)
6829 volume_music_current =
6830 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6832 // if that also fails, set current volume to first available value
6833 if (volume_music_current == NULL)
6834 volume_music_current = volumes_music;
6837 setup.volume_simple = atoi(volume_simple_current->identifier);
6838 setup.volume_loops = atoi(volume_loops_current->identifier);
6839 setup.volume_music = atoi(volume_music_current->identifier);
6841 // needed for displaying volume text instead of identifier
6842 volume_simple_text = volume_simple_current->name;
6843 volume_loops_text = volume_loops_current->name;
6844 volume_music_text = volume_music_current->name;
6846 setup_mode = SETUP_MODE_SOUND;
6851 static void execSetupChooseTouchControls(void)
6853 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6858 static void execSetupChooseMoveDistance(void)
6860 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6865 static void execSetupChooseDropDistance(void)
6867 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6872 static void execSetupChooseTransparency(void)
6874 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6879 static void execSetupChooseGridXSize_0(void)
6881 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6886 static void execSetupChooseGridYSize_0(void)
6888 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6893 static void execSetupChooseGridXSize_1(void)
6895 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6900 static void execSetupChooseGridYSize_1(void)
6902 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6907 static void execSetupConfigureVirtualButtons(void)
6909 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6911 ConfigureVirtualButtons();
6913 setup_mode = SETUP_MODE_TOUCH;
6918 static void execSetupTouch(void)
6922 if (touch_controls == NULL)
6924 for (i = 0; touch_controls_list[i].value != NULL; i++)
6926 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6927 char identifier[32], name[32];
6928 char *value = touch_controls_list[i].value;
6929 char *text = touch_controls_list[i].text;
6931 ti->node_top = &touch_controls;
6932 ti->sort_priority = i;
6934 sprintf(identifier, "%s", value);
6935 sprintf(name, "%s", text);
6937 setString(&ti->identifier, identifier);
6938 setString(&ti->name, name);
6939 setString(&ti->name_sorting, name);
6940 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6942 pushTreeInfo(&touch_controls, ti);
6945 // sort touch control values to start with lowest touch control value
6946 sortTreeInfo(&touch_controls);
6948 // set current touch control value to configured touch control value
6949 touch_control_current =
6950 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6952 // if that fails, set current touch control to reliable default value
6953 if (touch_control_current == NULL)
6954 touch_control_current =
6955 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6957 // if that also fails, set current touch control to first available value
6958 if (touch_control_current == NULL)
6959 touch_control_current = touch_controls;
6962 if (move_distances == NULL)
6964 for (i = 0; distances_list[i].value != -1; i++)
6966 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6967 char identifier[32], name[32];
6968 int value = distances_list[i].value;
6969 char *text = distances_list[i].text;
6971 ti->node_top = &move_distances;
6972 ti->sort_priority = value;
6974 sprintf(identifier, "%d", value);
6975 sprintf(name, "%s", text);
6977 setString(&ti->identifier, identifier);
6978 setString(&ti->name, name);
6979 setString(&ti->name_sorting, name);
6980 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6982 pushTreeInfo(&move_distances, ti);
6985 // sort distance values to start with lowest distance value
6986 sortTreeInfo(&move_distances);
6988 // set current distance value to configured distance value
6989 move_distance_current =
6990 getTreeInfoFromIdentifier(move_distances,
6991 i_to_a(setup.touch.move_distance));
6993 // if that fails, set current distance to reliable default value
6994 if (move_distance_current == NULL)
6995 move_distance_current =
6996 getTreeInfoFromIdentifier(move_distances,
6997 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6999 // if that also fails, set current distance to first available value
7000 if (move_distance_current == NULL)
7001 move_distance_current = move_distances;
7004 if (drop_distances == NULL)
7006 for (i = 0; distances_list[i].value != -1; i++)
7008 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7009 char identifier[32], name[32];
7010 int value = distances_list[i].value;
7011 char *text = distances_list[i].text;
7013 ti->node_top = &drop_distances;
7014 ti->sort_priority = value;
7016 sprintf(identifier, "%d", value);
7017 sprintf(name, "%s", text);
7019 setString(&ti->identifier, identifier);
7020 setString(&ti->name, name);
7021 setString(&ti->name_sorting, name);
7022 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
7024 pushTreeInfo(&drop_distances, ti);
7027 // sort distance values to start with lowest distance value
7028 sortTreeInfo(&drop_distances);
7030 // set current distance value to configured distance value
7031 drop_distance_current =
7032 getTreeInfoFromIdentifier(drop_distances,
7033 i_to_a(setup.touch.drop_distance));
7035 // if that fails, set current distance to reliable default value
7036 if (drop_distance_current == NULL)
7037 drop_distance_current =
7038 getTreeInfoFromIdentifier(drop_distances,
7039 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
7041 // if that also fails, set current distance to first available value
7042 if (drop_distance_current == NULL)
7043 drop_distance_current = drop_distances;
7046 if (transparencies == NULL)
7048 for (i = 0; transparencies_list[i].value != -1; i++)
7050 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7051 char identifier[32], name[32];
7052 int value = transparencies_list[i].value;
7053 char *text = transparencies_list[i].text;
7055 ti->node_top = &transparencies;
7056 ti->sort_priority = value;
7058 sprintf(identifier, "%d", value);
7059 sprintf(name, "%s", text);
7061 setString(&ti->identifier, identifier);
7062 setString(&ti->name, name);
7063 setString(&ti->name_sorting, name);
7064 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
7066 pushTreeInfo(&transparencies, ti);
7069 // sort transparency values to start with lowest transparency value
7070 sortTreeInfo(&transparencies);
7072 // set current transparency value to configured transparency value
7073 transparency_current =
7074 getTreeInfoFromIdentifier(transparencies,
7075 i_to_a(setup.touch.transparency));
7077 // if that fails, set current transparency to reliable default value
7078 if (transparency_current == NULL)
7079 transparency_current =
7080 getTreeInfoFromIdentifier(transparencies,
7081 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7083 // if that also fails, set current transparency to first available value
7084 if (transparency_current == NULL)
7085 transparency_current = transparencies;
7088 for (i = 0; i < 2; i++)
7090 for (j = 0; j < 2; j++)
7092 if (grid_sizes[i][j] == NULL)
7094 for (k = 0; grid_sizes_list[k].value != -1; k++)
7096 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7097 char identifier[32], name[32];
7098 int value = grid_sizes_list[k].value;
7099 char *text = grid_sizes_list[k].text;
7101 ti->node_top = &grid_sizes[i][j];
7102 ti->sort_priority = value;
7104 sprintf(identifier, "%d", value);
7105 sprintf(name, "%s", text);
7107 setString(&ti->identifier, identifier);
7108 setString(&ti->name, name);
7109 setString(&ti->name_sorting, name);
7110 setString(&ti->infotext,
7113 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7114 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7116 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7117 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7119 pushTreeInfo(&grid_sizes[i][j], ti);
7122 // sort grid size values to start with lowest grid size value
7123 sortTreeInfo(&grid_sizes[i][j]);
7125 // set current grid size value to configured grid size value
7126 grid_size_current[i][j] =
7127 getTreeInfoFromIdentifier(grid_sizes[i][j],
7129 setup.touch.grid_xsize[i] :
7130 setup.touch.grid_ysize[i]));
7132 // if that fails, set current grid size to reliable default value
7133 if (grid_size_current[i][j] == NULL)
7134 grid_size_current[i][j] =
7135 getTreeInfoFromIdentifier(grid_sizes[i][j],
7137 DEFAULT_GRID_XSIZE(i) :
7138 DEFAULT_GRID_YSIZE(i)));
7140 // if that also fails, set current grid size to first available value
7141 if (grid_size_current[i][j] == NULL)
7142 grid_size_current[i][j] = grid_sizes[i][j];
7147 setup.touch.control_type = touch_control_current->identifier;
7148 setup.touch.move_distance = atoi(move_distance_current->identifier);
7149 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7150 setup.touch.transparency = atoi(transparency_current->identifier);
7152 for (i = 0; i < 2; i++)
7154 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7155 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7157 if (i == GRID_ACTIVE_NR())
7159 overlay.grid_xsize = setup.touch.grid_xsize[i];
7160 overlay.grid_ysize = setup.touch.grid_ysize[i];
7164 // needed for displaying value text instead of identifier
7165 touch_controls_text = touch_control_current->name;
7166 move_distance_text = move_distance_current->name;
7167 drop_distance_text = drop_distance_current->name;
7168 transparency_text = transparency_current->name;
7170 for (i = 0; i < 2; i++)
7171 for (j = 0; j < 2; j++)
7172 grid_size_text[i][j] = grid_size_current[i][j]->name;
7174 setup_mode = SETUP_MODE_TOUCH;
7179 static void execSetupArtwork(void)
7181 static ArtworkDirTree *gfx_last_valid = NULL;
7182 static ArtworkDirTree *snd_last_valid = NULL;
7183 static ArtworkDirTree *mus_last_valid = NULL;
7185 // current artwork directory may be invalid (level group, parent link)
7186 if (!validLevelSeries(artwork.gfx_current))
7187 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7188 if (!validLevelSeries(artwork.snd_current))
7189 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7190 if (!validLevelSeries(artwork.mus_current))
7191 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7193 // store valid artwork directory information
7194 gfx_last_valid = artwork.gfx_current;
7195 snd_last_valid = artwork.snd_current;
7196 mus_last_valid = artwork.mus_current;
7199 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7200 artwork.gfx_current->subdir,
7201 artwork.gfx_current->fullpath,
7202 artwork.gfx_current->basepath);
7205 setup.graphics_set = artwork.gfx_current->identifier;
7206 setup.sounds_set = artwork.snd_current->identifier;
7207 setup.music_set = artwork.mus_current->identifier;
7209 // needed if last screen (setup choice) changed graphics, sounds or music
7210 ReloadCustomArtwork(0);
7212 // needed for displaying artwork name instead of artwork identifier
7213 graphics_set_name = artwork.gfx_current->name;
7214 sounds_set_name = artwork.snd_current->name;
7215 music_set_name = artwork.mus_current->name;
7217 setup_mode = SETUP_MODE_ARTWORK;
7222 static void execSetupChooseGraphics(void)
7224 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7229 static void execSetupChooseSounds(void)
7231 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7236 static void execSetupChooseMusic(void)
7238 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7243 static void execSetupInput(void)
7245 setup_mode = SETUP_MODE_INPUT;
7250 static void execSetupShortcuts(void)
7252 setup_mode = SETUP_MODE_SHORTCUTS;
7257 static void execSetupShortcuts1(void)
7259 setup_mode = SETUP_MODE_SHORTCUTS_1;
7264 static void execSetupShortcuts2(void)
7266 setup_mode = SETUP_MODE_SHORTCUTS_2;
7271 static void execSetupShortcuts3(void)
7273 setup_mode = SETUP_MODE_SHORTCUTS_3;
7278 static void execSetupShortcuts4(void)
7280 setup_mode = SETUP_MODE_SHORTCUTS_4;
7285 static void execSetupShortcuts5(void)
7287 setup_mode = SETUP_MODE_SHORTCUTS_5;
7292 static void execExitSetup(void)
7294 SetGameStatus(GAME_MODE_MAIN);
7299 static void execSaveAndExitSetup(void)
7305 static void execGadgetNetworkServer(void)
7307 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7308 struct GadgetInfo *gi = screen_gadget[gadget_id];
7310 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7311 network_server_hostname[0] = '\0';
7313 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7317 ClickOnGadget(gi, MB_LEFTBUTTON);
7320 static void execOfferUploadTapes(void)
7325 static void ToggleNetworkModeIfNeeded(void)
7327 int font_title = FONT_TITLE_1;
7328 int font_foot = FC_BLUE;
7329 int ystart = mSY - SY + 16;
7330 int ybottom = mSY - SY + SYSIZE - 20;
7331 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7333 if (setup.network_mode == network.enabled)
7336 network.enabled = setup.network_mode;
7338 FadeOut(REDRAW_ALL);
7342 DrawTextSCentered(ystart, font_title, text);
7346 if (network.enabled)
7347 InitNetworkServer();
7349 DisconnectFromNetworkServer();
7351 DrawTextSCentered(ybottom, font_foot,
7352 "Press any key or button for setup menu");
7354 WaitForEventToContinue();
7359 static void ToggleGameSpeedsListIfNeeded(void)
7361 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7363 if (setup.game_speed_extended == using_game_speeds_extended)
7366 // try to match similar values when changing game speeds list
7367 if (setup.game_speed_extended)
7368 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7369 setup.game_frame_delay == 30 ? 29 :
7370 setup.game_frame_delay);
7372 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7373 setup.game_frame_delay == 16 ? 15 :
7374 setup.game_frame_delay >= 29 ? 30 :
7375 setup.game_frame_delay <= 10 ? 10 :
7376 setup.game_frame_delay);
7378 execSetupGame_setGameSpeeds(TRUE);
7383 static void ToggleUseApiServerIfNeeded(void)
7385 if (runtime.use_api_server == setup.use_api_server)
7388 runtime.use_api_server = setup.use_api_server;
7390 if (runtime.use_api_server)
7391 CheckApiServerTasks();
7394 static void ModifyGameSpeedIfNeeded(void)
7396 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7397 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7401 char *game_speed_text = "Fast";
7402 int game_speed_value = 15;
7404 if (setup.game_speed_extended)
7406 game_speed_text = "60 fps";
7407 game_speed_value = 16;
7410 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7412 // set game speed to existing list value that is fast enough for vsync
7413 setup.game_frame_delay = game_speed_value;
7415 execSetupGame_setGameSpeeds(TRUE);
7417 Request(message, REQ_CONFIRM);
7420 static void DisableVsyncIfNeeded(void)
7422 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7423 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7424 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7427 // disable vsync for the selected game speed to work
7428 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7430 execSetupGraphics_setVsyncModes(TRUE);
7432 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7438 void *related_value;
7439 } hide_related_entry_list[] =
7441 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7442 { &setup.scores_in_highscore_list, &scores_type_text },
7444 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7445 { &setup.game_frame_delay, &game_speed_text },
7447 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7448 { &setup.scroll_delay_value, &scroll_delay_text },
7450 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7451 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7453 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7454 { &setup.window_scaling_percent, &window_size_text },
7456 { &setup.window_scaling_quality, execSetupChooseScalingType },
7457 { &setup.window_scaling_quality, &scaling_type_text },
7459 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7460 { &setup.screen_rendering_mode, &rendering_mode_text },
7462 { &setup.vsync_mode, execSetupChooseVsyncMode },
7463 { &setup.vsync_mode, &vsync_mode_text },
7465 { &setup.graphics_set, execSetupChooseGraphics },
7466 { &setup.graphics_set, &graphics_set_name },
7468 { &setup.sounds_set, execSetupChooseSounds },
7469 { &setup.sounds_set, &sounds_set_name },
7471 { &setup.music_set, execSetupChooseMusic },
7472 { &setup.music_set, &music_set_name },
7474 { &setup.volume_simple, execSetupChooseVolumeSimple },
7475 { &setup.volume_simple, &volume_simple_text },
7477 { &setup.volume_loops, execSetupChooseVolumeLoops },
7478 { &setup.volume_loops, &volume_loops_text },
7480 { &setup.volume_music, execSetupChooseVolumeMusic },
7481 { &setup.volume_music, &volume_music_text },
7483 { &setup.touch.control_type, execSetupChooseTouchControls },
7484 { &setup.touch.control_type, &touch_controls_text },
7486 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7487 { &setup.touch.move_distance, &move_distance_text },
7489 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7490 { &setup.touch.drop_distance, &drop_distance_text },
7492 { &setup.touch.transparency, execSetupChooseTransparency },
7493 { &setup.touch.transparency, &transparency_text },
7495 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7496 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7498 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7499 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7501 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7502 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7504 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7505 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7507 { &setup.internal.menu_game, execSetupGame },
7508 { &setup.internal.menu_engines, execSetupEngines },
7509 { &setup.internal.menu_editor, execSetupEditor },
7510 { &setup.internal.menu_graphics, execSetupGraphics },
7511 { &setup.internal.menu_sound, execSetupSound },
7512 { &setup.internal.menu_artwork, execSetupArtwork },
7513 { &setup.internal.menu_input, execSetupInput },
7514 { &setup.internal.menu_touch, execSetupTouch },
7515 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7516 { &setup.internal.menu_exit, execExitSetup },
7517 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7522 void setHideRelatedSetupEntries(void)
7526 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7527 if (hideSetupEntry(hide_related_entry_list[i].value))
7528 setHideSetupEntry(hide_related_entry_list[i].related_value);
7531 static struct TokenInfo setup_info_main[] =
7533 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7534 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7535 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7536 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7537 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7538 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7539 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7540 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7541 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7542 { TYPE_EMPTY, NULL, "" },
7543 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7544 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7549 static struct TokenInfo setup_info_game[] =
7551 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7552 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7553 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7554 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7555 { TYPE_STRING, &network_server_text, "" },
7556 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7557 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7558 { TYPE_STRING, &scores_type_text, "" },
7559 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7560 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7561 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7562 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7563 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7564 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7565 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7566 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7567 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7568 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7569 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7570 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7571 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7572 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7573 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7574 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7575 { TYPE_STRING, &game_speed_text, "" },
7576 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7578 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7579 { TYPE_STRING, &scroll_delay_text, "" },
7581 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7582 { TYPE_STRING, &snapshot_mode_text, "" },
7583 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7584 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7585 { TYPE_EMPTY, NULL, "" },
7586 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7591 static struct TokenInfo setup_info_engines[] =
7593 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7594 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7595 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7596 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7597 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7598 { TYPE_EMPTY, NULL, "" },
7599 { TYPE_HEADLINE, NULL, "Supaplex" },
7600 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7601 { TYPE_EMPTY, NULL, "" },
7602 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7607 static struct TokenInfo setup_info_editor[] =
7610 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7611 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7612 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7613 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7614 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7615 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7616 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7617 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7618 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7619 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7621 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7622 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7624 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7626 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7627 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7628 { TYPE_EMPTY, NULL, "" },
7630 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7631 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7632 { TYPE_EMPTY, NULL, "" },
7634 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7635 { TYPE_EMPTY, NULL, "" },
7636 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7637 { TYPE_EMPTY, NULL, "" },
7638 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7643 static struct TokenInfo setup_info_graphics[] =
7645 #if !defined(PLATFORM_ANDROID)
7646 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7647 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7648 { TYPE_STRING, &window_size_text, "" },
7649 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7650 { TYPE_STRING, &scaling_type_text, "" },
7651 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7652 { TYPE_STRING, &rendering_mode_text, "" },
7655 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7656 { TYPE_STRING, &scroll_delay_text, "" },
7658 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7659 { TYPE_STRING, &vsync_mode_text, "" },
7660 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7661 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7662 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7663 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7664 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7665 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7666 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7667 { TYPE_EMPTY, NULL, "" },
7668 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7673 static struct TokenInfo setup_info_sound[] =
7675 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7676 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7677 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7678 { TYPE_EMPTY, NULL, "" },
7679 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7680 { TYPE_STRING, &volume_simple_text, "" },
7681 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7682 { TYPE_STRING, &volume_loops_text, "" },
7683 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7684 { TYPE_STRING, &volume_music_text, "" },
7685 { TYPE_EMPTY, NULL, "" },
7686 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7691 static struct TokenInfo setup_info_artwork[] =
7693 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7694 { TYPE_STRING, &graphics_set_name, "" },
7695 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7696 { TYPE_STRING, &sounds_set_name, "" },
7697 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7698 { TYPE_STRING, &music_set_name, "" },
7699 { TYPE_EMPTY, NULL, "" },
7700 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7701 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7702 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7703 { TYPE_EMPTY, NULL, "" },
7704 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7709 static struct TokenInfo setup_info_input[] =
7711 { TYPE_SWITCH, NULL, "Player:" },
7712 { TYPE_SWITCH, NULL, "Device:" },
7713 { TYPE_SWITCH, NULL, "" },
7714 { TYPE_SKIPPABLE, NULL, "" },
7715 { TYPE_EMPTY, NULL, "" },
7716 { TYPE_EMPTY, NULL, "" },
7717 { TYPE_EMPTY, NULL, "" },
7718 { TYPE_EMPTY, NULL, "" },
7719 { TYPE_EMPTY, NULL, "" },
7720 { TYPE_EMPTY, NULL, "" },
7721 { TYPE_EMPTY, NULL, "" },
7722 { TYPE_EMPTY, NULL, "" },
7723 { TYPE_SKIPPABLE, NULL, "" },
7724 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7729 static struct TokenInfo setup_info_touch[] =
7731 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7732 { TYPE_STRING, &touch_controls_text, "" },
7733 { TYPE_EMPTY, NULL, "" },
7734 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7739 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7741 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7742 { TYPE_STRING, &touch_controls_text, "" },
7743 { TYPE_EMPTY, NULL, "" },
7744 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7745 { TYPE_STRING, &grid_size_text[0][0], "" },
7746 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7747 { TYPE_STRING, &grid_size_text[0][1], "" },
7748 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7749 { TYPE_STRING, &transparency_text, "" },
7750 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7751 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7752 { TYPE_EMPTY, NULL, "" },
7753 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7754 { TYPE_EMPTY, NULL, "" },
7755 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7760 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7762 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7763 { TYPE_STRING, &touch_controls_text, "" },
7764 { TYPE_EMPTY, NULL, "" },
7765 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7766 { TYPE_STRING, &grid_size_text[1][0], "" },
7767 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7768 { TYPE_STRING, &grid_size_text[1][1], "" },
7769 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7770 { TYPE_STRING, &transparency_text, "" },
7771 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7772 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7773 { TYPE_EMPTY, NULL, "" },
7774 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7775 { TYPE_EMPTY, NULL, "" },
7776 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7781 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7783 setup_info_touch_virtual_buttons_0,
7784 setup_info_touch_virtual_buttons_1
7787 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7789 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7790 { TYPE_STRING, &touch_controls_text, "" },
7791 { TYPE_EMPTY, NULL, "" },
7792 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7793 { TYPE_STRING, &move_distance_text, "" },
7794 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7795 { TYPE_STRING, &drop_distance_text, "" },
7796 { TYPE_EMPTY, NULL, "" },
7797 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7802 static struct TokenInfo setup_info_shortcuts[] =
7804 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7805 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7806 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7807 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7808 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7809 { TYPE_EMPTY, NULL, "" },
7810 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7815 static struct TokenInfo setup_info_shortcuts_1[] =
7817 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7818 { TYPE_KEY, &setup.shortcut.save_game, "" },
7819 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7820 { TYPE_KEY, &setup.shortcut.load_game, "" },
7821 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7822 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7823 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7824 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7825 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7826 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7827 { TYPE_EMPTY, NULL, "" },
7828 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7829 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7830 { TYPE_EMPTY, NULL, "" },
7831 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7836 static struct TokenInfo setup_info_shortcuts_2[] =
7838 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7839 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7840 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7841 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7842 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7843 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7844 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7845 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7846 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7847 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7848 { TYPE_EMPTY, NULL, "" },
7849 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7854 static struct TokenInfo setup_info_shortcuts_3[] =
7856 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7857 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7858 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7859 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7860 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7861 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7862 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7863 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7864 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7865 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7866 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7867 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7868 { TYPE_EMPTY, NULL, "" },
7869 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7874 static struct TokenInfo setup_info_shortcuts_4[] =
7876 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7877 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7878 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7879 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7880 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7881 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7882 { TYPE_EMPTY, NULL, "" },
7883 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7888 static struct TokenInfo setup_info_shortcuts_5[] =
7890 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7891 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7892 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7893 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7894 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7895 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7896 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7897 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7898 { TYPE_EMPTY, NULL, "" },
7899 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7904 static Key getSetupKey(void)
7906 Key key = KSYM_UNDEFINED;
7907 boolean got_key_event = FALSE;
7909 while (!got_key_event)
7913 if (NextValidEvent(&event))
7917 case EVENT_KEYPRESS:
7919 key = GetEventKey((KeyEvent *)&event, TRUE);
7921 // press 'Escape' or 'Enter' to keep the existing key binding
7922 if (key == KSYM_Escape || key == KSYM_Return)
7923 key = KSYM_UNDEFINED; // keep old value
7925 got_key_event = TRUE;
7929 case EVENT_KEYRELEASE:
7930 key_joystick_mapping = 0;
7934 HandleOtherEvents(&event);
7945 static int getSetupValueFont(int type, void *value)
7947 if (type & TYPE_GHOSTED)
7948 return FONT_OPTION_OFF;
7949 else if (type & TYPE_KEY)
7950 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7951 else if (type & TYPE_STRING)
7952 return FONT_VALUE_2;
7953 else if (type & TYPE_ECS_AGA)
7954 return FONT_VALUE_1;
7955 else if (type & TYPE_BOOLEAN_STYLE)
7956 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7957 else if (type & TYPE_YES_NO_AUTO)
7958 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7959 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7960 else if (type & TYPE_PLAYER)
7961 return FONT_VALUE_1;
7963 return FONT_VALUE_1;
7966 static int getSetupValueFontNarrow(int type, int font_nr)
7968 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7969 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7970 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7974 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7976 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7977 struct TokenInfo *si = &setup_info[si_pos];
7978 boolean font_draw_xoffset_modified = FALSE;
7979 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7980 int font_draw_xoffset_old = -1;
7981 int xoffset = (scrollbar_needed ? -1 : 0);
7982 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7983 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7984 int xpos = menu_screen_value_xpos;
7985 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7986 int startx = mSX + xpos * 32;
7987 int starty = mSY + ypos * 32;
7988 int type = si->type;
7989 void *value = si->value;
7990 char *value_string = getSetupValue(type, value);
7991 int font_nr_default = getSetupValueFont(type, value);
7992 int font_width_default = getFontWidth(font_nr_default);
7993 int font_nr = font_nr_default;
7996 if (value_string == NULL)
7999 if (type & TYPE_KEY)
8001 xpos = MENU_SCREEN_START_XPOS;
8003 if (type & TYPE_QUERY)
8004 value_string = "<press key>";
8006 else if (type & TYPE_STRING)
8008 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
8010 xpos = MENU_SCREEN_START_XPOS;
8012 if (strlen(value_string) > max_value_len)
8013 value_string[max_value_len] = '\0';
8015 else if (type & TYPE_YES_NO_AUTO)
8017 xpos = menu_screen_value_xpos - 1;
8019 else if (type & TYPE_PLAYER)
8021 int displayed_player_nr = *(int *)value + 1;
8023 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
8026 startx = mSX + xpos * 32;
8027 starty = mSY + ypos * 32;
8029 // special check if right-side setup values moved left due to scrollbar
8030 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
8032 int max_menu_text_length = 26; // maximum text length for classic menu
8033 int font_xoffset = getFontDrawOffsetX(font_nr);
8034 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8035 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8036 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8037 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
8039 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
8041 // when using narrow font, left-shifting text "auto" not needed
8042 if (type & TYPE_YES_NO_AUTO)
8046 startx = mSX + xpos * 32;
8048 font_nr = getSetupValueFontNarrow(type, font_nr);
8052 // downward compatibility correction for Juergen Bonhagen's menu settings
8053 if (setup_mode != SETUP_MODE_INPUT)
8055 int max_menu_text_length_big = (menu_screen_value_xpos -
8056 MENU_SCREEN_START_XPOS);
8057 int max_menu_text_length_medium = max_menu_text_length_big * 2;
8058 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
8059 int font1_xoffset = getFontDrawOffsetX(font_nr);
8060 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
8061 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8062 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8063 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8064 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8065 boolean correct_font_draw_xoffset = FALSE;
8067 if (xpos == MENU_SCREEN_START_XPOS &&
8068 startx + font1_xoffset < text_startx + text_font_xoffset)
8069 correct_font_draw_xoffset = TRUE;
8071 if (xpos == menu_screen_value_xpos &&
8072 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8073 correct_font_draw_xoffset = TRUE;
8075 // check if setup value would overlap with setup text when printed
8076 // (this can happen for extreme/wrong values for font draw offset)
8077 if (correct_font_draw_xoffset)
8079 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8080 font_draw_xoffset_modified = TRUE;
8082 if (type & TYPE_KEY)
8083 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8084 else if (!(type & TYPE_STRING))
8085 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8086 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8090 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
8091 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
8093 DrawText(startx, starty, value_string, font_nr);
8095 if (type & TYPE_PLAYER)
8097 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8098 int player_nr = *(int *)value;
8099 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8100 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8101 int startx2 = startx + xoff;
8102 int starty2 = starty + yoff;
8104 if (DrawingOnBackground(startx2, starty2))
8105 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8107 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8108 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8111 if (font_draw_xoffset_modified)
8112 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8115 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8117 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8118 struct TokenInfo *si = &setup_info[si_pos];
8120 if (si->type & TYPE_BOOLEAN_STYLE)
8122 *(boolean *)si->value ^= TRUE;
8124 else if (si->type & TYPE_YES_NO_AUTO)
8128 (*(int *)si->value == AUTO ? TRUE :
8129 *(int *)si->value == TRUE ? FALSE : AUTO) :
8130 (*(int *)si->value == TRUE ? AUTO :
8131 *(int *)si->value == AUTO ? FALSE : TRUE));
8133 else if (si->type & TYPE_KEY)
8137 si->type |= TYPE_QUERY;
8138 drawSetupValue(screen_pos, setup_info_pos_raw);
8139 si->type &= ~TYPE_QUERY;
8141 key = getSetupKey();
8142 if (key != KSYM_UNDEFINED)
8143 *(Key *)si->value = key;
8145 else if (si->type & TYPE_PLAYER)
8147 int player_nr = *(int *)si->value;
8152 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8154 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8157 drawSetupValue(screen_pos, setup_info_pos_raw);
8159 // fullscreen state may have changed at this point
8160 if (si->value == &setup.fullscreen)
8161 ToggleFullscreenIfNeeded();
8163 // network mode may have changed at this point
8164 if (si->value == &setup.network_mode)
8165 ToggleNetworkModeIfNeeded();
8167 // API server mode may have changed at this point
8168 if (si->value == &setup.use_api_server)
8169 ToggleUseApiServerIfNeeded();
8171 // game speed list may have changed at this point
8172 if (si->value == &setup.game_speed_extended)
8173 ToggleGameSpeedsListIfNeeded();
8176 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8178 static struct TokenInfo *setup_info_final = NULL;
8183 // determine maximum list size of target list
8184 while (setup_info_orig[list_size++].type != 0);
8186 // free, allocate and clear memory for target list
8187 checked_free(setup_info_final);
8188 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8190 // copy setup info list without setup entries marked as hidden
8191 for (i = 0; setup_info_orig[i].type != 0; i++)
8193 // skip setup entries configured to be hidden
8194 if (hideSetupEntry(setup_info_orig[i].value))
8197 // skip skippable setup entries if screen is lower than usual
8198 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8199 setup_info_orig[i].type == TYPE_SKIPPABLE)
8202 setup_info_final[list_pos++] = setup_info_orig[i];
8205 return setup_info_final;
8208 static void DrawSetupScreen_Generic(void)
8210 int fade_mask = REDRAW_FIELD;
8211 boolean redraw_all = FALSE;
8212 char *title_string = NULL;
8216 fade_mask = REDRAW_ALL;
8219 FadeMenuSoundsAndMusic();
8221 FreeScreenGadgets();
8222 CreateScreenGadgets();
8224 if (redraw_mask & REDRAW_ALL)
8229 // needed if different viewport properties defined for setup screen
8230 ChangeViewportPropertiesIfNeeded();
8232 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8236 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8238 if (setup_mode == SETUP_MODE_MAIN)
8240 setup_info = setup_info_main;
8241 title_string = STR_SETUP_MAIN;
8243 else if (setup_mode == SETUP_MODE_GAME)
8245 setup_info = setup_info_game;
8246 title_string = STR_SETUP_GAME;
8248 else if (setup_mode == SETUP_MODE_ENGINES)
8250 setup_info = setup_info_engines;
8251 title_string = STR_SETUP_ENGINES;
8253 else if (setup_mode == SETUP_MODE_EDITOR)
8255 setup_info = setup_info_editor;
8256 title_string = STR_SETUP_EDITOR;
8258 else if (setup_mode == SETUP_MODE_GRAPHICS)
8260 setup_info = setup_info_graphics;
8261 title_string = STR_SETUP_GRAPHICS;
8263 else if (setup_mode == SETUP_MODE_SOUND)
8265 setup_info = setup_info_sound;
8266 title_string = STR_SETUP_SOUND;
8268 else if (setup_mode == SETUP_MODE_ARTWORK)
8270 setup_info = setup_info_artwork;
8271 title_string = STR_SETUP_ARTWORK;
8273 else if (setup_mode == SETUP_MODE_TOUCH)
8275 setup_info = setup_info_touch;
8276 title_string = STR_SETUP_TOUCH;
8278 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8279 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8280 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8281 setup_info = setup_info_touch_wipe_gestures;
8283 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8285 setup_info = setup_info_shortcuts;
8286 title_string = STR_SETUP_SHORTCUTS;
8288 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8290 setup_info = setup_info_shortcuts_1;
8291 title_string = STR_SETUP_SHORTCUTS;
8293 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8295 setup_info = setup_info_shortcuts_2;
8296 title_string = STR_SETUP_SHORTCUTS;
8298 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8300 setup_info = setup_info_shortcuts_3;
8301 title_string = STR_SETUP_SHORTCUTS;
8303 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8305 setup_info = setup_info_shortcuts_4;
8306 title_string = STR_SETUP_SHORTCUTS;
8308 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8310 setup_info = setup_info_shortcuts_5;
8311 title_string = STR_SETUP_SHORTCUTS;
8314 // use modified setup info without setup entries marked as hidden
8315 setup_info = getSetupInfoFinal(setup_info);
8317 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8319 // determine maximal number of setup entries that can be displayed on screen
8321 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8324 // determine maximal number of setup entries available for this setup screen
8326 for (i = 0; setup_info[i].type != 0; i++)
8329 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8331 MapScreenGadgets(max_setup_info);
8334 redraw_mask = fade_mask = REDRAW_ALL;
8336 DrawMaskedBorder(fade_mask);
8341 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8343 menu_info = setup_info;
8345 HandleMenuScreen(mx, my, dx, dy, button,
8346 setup_mode, num_setup_info, max_setup_info);
8349 static void DrawSetupScreen_Input(void)
8353 FadeOut(REDRAW_FIELD);
8357 setup_info = getSetupInfoFinal(setup_info_input);
8359 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8361 for (i = 0; setup_info[i].type != 0; i++)
8363 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8364 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8365 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8366 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8367 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8368 initCursor(i, IMG_MENU_BUTTON);
8370 DrawCursorAndText_Setup(i, -1, FALSE);
8373 // create gadgets for setup input menu screen
8374 FreeScreenGadgets();
8375 CreateScreenGadgets();
8377 // map gadgets for setup input menu screen
8378 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8380 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8382 FadeIn(REDRAW_FIELD);
8385 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8387 if (device_name == NULL)
8390 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8393 if (strlen(device_name) > 1)
8395 char c1 = device_name[strlen(device_name) - 1];
8396 char c2 = device_name[strlen(device_name) - 2];
8398 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8399 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8402 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8403 strlen(device_name));
8406 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8409 static struct SetupKeyboardInfo custom_key;
8416 { &custom_key.left, "Axis/Pad Left" },
8417 { &custom_key.right, "Axis/Pad Right" },
8418 { &custom_key.up, "Axis/Pad Up" },
8419 { &custom_key.down, "Axis/Pad Down" },
8420 { &custom_key.snap, "Button 1/A/X" },
8421 { &custom_key.drop, "Button 2/B/Y" }
8423 static char *joystick_name[MAX_PLAYERS] =
8430 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8431 int font_nr_info = FONT_MENU_1;
8432 int font_nr_name = FONT_VALUE_OLD;
8433 int font_nr_on = FONT_VALUE_1;
8434 int font_nr_off = FONT_VALUE_OLD;
8437 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8439 font_nr_info = FONT_MENU_2;
8440 font_nr_on = FONT_VALUE_NARROW;
8441 font_nr_off = FONT_VALUE_OLD_NARROW;
8444 custom_key = setup.input[player_nr].key;
8446 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8447 FONT_INPUT_1_ACTIVE);
8449 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8451 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8452 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8454 if (setup.input[player_nr].use_joystick)
8456 char *device_name = setup.input[player_nr].joy.device_name;
8457 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8458 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8459 char *text = joystick_name[joystick_nr];
8460 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8462 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8463 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8467 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8468 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8471 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8472 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8476 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8477 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8478 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8479 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8481 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8482 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8483 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8484 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8485 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8486 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8488 for (i = 0; i < 6; i++)
8490 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8492 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8494 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8495 (setup.input[player_nr].use_joystick ?
8497 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8501 static int input_player_nr = 0;
8503 static void HandleSetupScreen_Input_Player(int step, int direction)
8505 int old_player_nr = input_player_nr;
8508 new_player_nr = old_player_nr + step * direction;
8509 if (new_player_nr < 0)
8511 if (new_player_nr > MAX_PLAYERS - 1)
8512 new_player_nr = MAX_PLAYERS - 1;
8514 if (new_player_nr != old_player_nr)
8516 input_player_nr = new_player_nr;
8518 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8522 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8524 static int choice = 0;
8527 int pos_start = SETUPINPUT_SCREEN_POS_START;
8528 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8529 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8530 int pos_end = SETUPINPUT_SCREEN_POS_END;
8532 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8536 for (i = 0; setup_info_input[i].type != 0; i++)
8538 // adjust menu structure according to skipped setup entries
8539 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8547 if (button == MB_MENU_INITIALIZE)
8549 // input setup menu may have changed size due to graphics configuration
8550 if (choice >= pos_empty1)
8553 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8555 DrawCursorAndText_Setup(choice, -1, TRUE);
8559 else if (button == MB_MENU_LEAVE)
8561 setup_mode = SETUP_MODE_MAIN;
8568 if (mx || my) // mouse input
8570 x = (mx - mSX) / 32;
8571 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8573 else if (dx || dy) // keyboard input
8575 if (dx && choice == 0)
8576 x = (dx < 0 ? 10 : 12);
8577 else if ((dx && choice == 1) ||
8578 (dx == -1 && choice == pos_end))
8579 button = MB_MENU_CHOICE;
8583 if (y >= pos_empty1 && y <= pos_empty2)
8584 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8587 if (y == 0 && dx != 0 && button)
8589 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8591 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8592 y >= pos_start && y <= pos_end &&
8593 !(y >= pos_empty1 && y <= pos_empty2))
8599 DrawCursorAndText_Setup(choice, -1, FALSE);
8600 DrawCursorAndText_Setup(y, -1, TRUE);
8602 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8611 char *device_name = setup.input[input_player_nr].joy.device_name;
8613 if (!setup.input[input_player_nr].use_joystick)
8615 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8617 setJoystickDeviceToNr(device_name, new_device_nr);
8618 setup.input[input_player_nr].use_joystick = TRUE;
8622 int device_nr = getJoystickNrFromDeviceName(device_name);
8623 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8625 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8626 setup.input[input_player_nr].use_joystick = FALSE;
8628 setJoystickDeviceToNr(device_name, new_device_nr);
8631 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8635 if (setup.input[input_player_nr].use_joystick)
8636 ConfigureJoystick(input_player_nr);
8638 CustomizeKeyboard(input_player_nr);
8640 else if (y == pos_end)
8646 setup_mode = SETUP_MODE_MAIN;
8653 static boolean CustomizeKeyboardMain(int player_nr)
8657 boolean finished = FALSE;
8658 static struct SetupKeyboardInfo custom_key;
8663 } customize_step[] =
8665 { &custom_key.left, "Move Left" },
8666 { &custom_key.right, "Move Right" },
8667 { &custom_key.up, "Move Up" },
8668 { &custom_key.down, "Move Down" },
8669 { &custom_key.snap, "Snap Field" },
8670 { &custom_key.drop, "Drop Element" }
8672 int font_nr_old = FONT_VALUE_OLD;
8673 int font_nr_new = FONT_VALUE_1;
8674 boolean success = FALSE;
8676 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8678 font_nr_old = FONT_VALUE_OLD_NARROW;
8679 font_nr_new = FONT_VALUE_NARROW;
8682 // read existing key bindings from player setup
8683 custom_key = setup.input[player_nr].key;
8686 FadeOut(REDRAW_FIELD);
8690 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8693 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8694 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8695 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8696 "Key:", FONT_INPUT_1_ACTIVE);
8697 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8698 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8700 FadeIn(REDRAW_FIELD);
8706 if (NextValidEvent(&event))
8710 case EVENT_KEYPRESS:
8712 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8714 // press 'Escape' to abort and keep the old key bindings
8715 if (key == KSYM_Escape)
8717 FadeSkipNextFadeIn();
8724 // press 'Enter' to keep the existing key binding
8725 if (key == KSYM_Return)
8726 key = *customize_step[step_nr].key;
8728 // check if key already used
8729 for (i = 0; i < step_nr; i++)
8730 if (*customize_step[i].key == key)
8735 // got new key binding
8736 *customize_step[step_nr].key = key;
8737 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8739 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8740 getKeyNameFromKey(key), font_nr_new);
8743 // un-highlight last query
8744 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8745 customize_step[step_nr - 1].text, FONT_MENU_1);
8746 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8747 "Key:", FONT_MENU_1);
8749 // all keys configured
8758 // query next key binding
8759 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8760 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8761 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8762 "Key:", FONT_INPUT_1_ACTIVE);
8763 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8764 getKeyNameFromKey(*customize_step[step_nr].key),
8769 case EVENT_KEYRELEASE:
8770 key_joystick_mapping = 0;
8774 HandleOtherEvents(&event);
8782 // write new key bindings back to player setup, if successfully finished
8784 setup.input[player_nr].key = custom_key;
8789 void CustomizeKeyboard(int player_nr)
8791 boolean success = CustomizeKeyboardMain(player_nr);
8795 int font_nr = FONT_TITLE_1;
8796 int font_height = getFontHeight(font_nr);
8797 int ypos1 = SYSIZE / 2 - font_height * 2;
8798 int ypos2 = SYSIZE / 2 - font_height * 1;
8799 unsigned int wait_frame_delay = 0;
8800 unsigned int wait_frame_delay_value = 2000;
8802 ResetDelayCounter(&wait_frame_delay);
8806 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8807 DrawTextSCentered(ypos2, font_nr, "configured!");
8809 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8815 DrawSetupScreen_Input();
8818 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8820 #define MARKER_BUTTON 1
8821 #define MARKER_AXIS_X 2
8822 #define MARKER_AXIS_Y 3
8824 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8826 static boolean bitmaps_initialized = FALSE;
8827 boolean screen_initialized = FALSE;
8828 static Bitmap *controller, *button, *axis_x, *axis_y;
8830 boolean success = TRUE;
8831 boolean done = FALSE, next = FALSE;
8833 int alpha = 200, alpha_step = -1;
8834 int alpha_ticks = 0;
8835 char mapping[4096], temp[256];
8836 int font_name = MENU_SETUP_FONT_TITLE;
8837 int font_info = MENU_SETUP_FONT_TEXT;
8838 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8839 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8840 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8841 int ystep_name = getMenuTextStep(spacing_name, font_name);
8842 int ystep_line = getMenuTextStep(spacing_line, font_info);
8843 int ystep_para = getMenuTextStep(spacing_para, font_info);
8851 int axis, button, hat, hat_value;
8854 *step, *prev_step, steps[] =
8856 { 356, 155, MARKER_BUTTON, "a", },
8857 { 396, 122, MARKER_BUTTON, "b", },
8858 { 320, 125, MARKER_BUTTON, "x", },
8859 { 358, 95, MARKER_BUTTON, "y", },
8860 { 162, 125, MARKER_BUTTON, "back", },
8861 { 216, 125, MARKER_BUTTON, "guide", },
8862 { 271, 125, MARKER_BUTTON, "start", },
8863 { 110, 200, MARKER_BUTTON, "dpleft", },
8864 { 146, 228, MARKER_BUTTON, "dpdown", },
8865 { 178, 200, MARKER_BUTTON, "dpright", },
8866 { 146, 172, MARKER_BUTTON, "dpup", },
8867 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8868 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8869 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8870 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8871 { 73, 141, MARKER_BUTTON, "leftstick", },
8872 { 282, 210, MARKER_BUTTON, "rightstick", },
8873 { 73, 141, MARKER_AXIS_X, "leftx", },
8874 { 73, 141, MARKER_AXIS_Y, "lefty", },
8875 { 282, 210, MARKER_AXIS_X, "rightx", },
8876 { 282, 210, MARKER_AXIS_Y, "righty", },
8879 unsigned int event_frame_delay = 0;
8880 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8882 ResetDelayCounter(&event_frame_delay);
8884 if (!bitmaps_initialized)
8886 controller = LoadCustomImage("joystick/controller.png");
8887 button = LoadCustomImage("joystick/button.png");
8888 axis_x = LoadCustomImage("joystick/axis_x.png");
8889 axis_y = LoadCustomImage("joystick/axis_y.png");
8891 bitmaps_initialized = TRUE;
8894 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8897 // print info about the joystick we are watching
8898 Debug("joystick", "watching joystick %d: (%s)",
8899 SDL_JoystickInstanceID(joystick), name);
8900 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8901 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8902 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8905 // initialize mapping with GUID and name
8906 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8908 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8909 temp, name, SDL_GetPlatform());
8911 // loop through all steps (buttons and axes), getting joystick events
8912 for (i = 0; i < SDL_arraysize(steps) && !done;)
8914 Bitmap *marker = button; // initialize with reliable default value
8917 strcpy(step->mapping, mapping);
8921 step->hat_value = -1;
8923 marker = (step->marker == MARKER_BUTTON ? button :
8924 step->marker == MARKER_AXIS_X ? axis_x :
8925 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8929 while (!done && !next)
8931 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8932 alpha_ticks = SDL_GetTicks();
8939 else if (alpha < 128)
8945 int controller_x = SX + (SXSIZE - controller->width) / 2;
8946 int controller_y = SY + ystep_line;
8948 int marker_x = controller_x + step->x;
8949 int marker_y = controller_y + step->y;
8951 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8952 int ystart2 = ystart1 + ystep_name + ystep_line;
8956 DrawTextSCentered(ystart1, font_name, name);
8958 DrawTextSCentered(ystart2, font_info,
8959 "Press buttons and move axes on");
8960 ystart2 += ystep_line;
8961 DrawTextSCentered(ystart2, font_info,
8962 "your controller when indicated.");
8963 ystart2 += ystep_line;
8964 DrawTextSCentered(ystart2, font_info,
8965 "(Your controller may look different.)");
8966 ystart2 += ystep_para;
8968 #if defined(PLATFORM_ANDROID)
8969 DrawTextSCentered(ystart2, font_info,
8970 "To correct a mistake,");
8971 ystart2 += ystep_line;
8972 DrawTextSCentered(ystart2, font_info,
8973 "press the 'back' button.");
8974 ystart2 += ystep_line;
8975 DrawTextSCentered(ystart2, font_info,
8976 "To skip a button or axis,");
8977 ystart2 += ystep_line;
8978 DrawTextSCentered(ystart2, font_info,
8979 "press the 'menu' button.");
8981 DrawTextSCentered(ystart2, font_info,
8982 "To correct a mistake,");
8983 ystart2 += ystep_line;
8984 DrawTextSCentered(ystart2, font_info,
8985 "press the 'backspace' key.");
8986 ystart2 += ystep_line;
8987 DrawTextSCentered(ystart2, font_info,
8988 "To skip a button or axis,");
8989 ystart2 += ystep_line;
8990 DrawTextSCentered(ystart2, font_info,
8991 "press the 'return' key.");
8992 ystart2 += ystep_line;
8993 DrawTextSCentered(ystart2, font_info,
8994 "To exit, press the 'escape' key.");
8997 BlitBitmapMasked(controller, drawto, 0, 0,
8998 controller->width, controller->height,
8999 controller_x, controller_y);
9001 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
9002 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
9004 BlitBitmapMasked(marker, drawto, 0, 0,
9005 marker->width, marker->height,
9006 marker_x, marker_y);
9008 if (!screen_initialized)
9009 FadeIn(REDRAW_FIELD);
9013 screen_initialized = TRUE;
9015 while (NextValidEvent(&event))
9019 case SDL_JOYAXISMOTION:
9020 if (event.jaxis.value > 20000 ||
9021 event.jaxis.value < -20000)
9023 for (j = 0; j < i; j++)
9024 if (steps[j].axis == event.jaxis.axis)
9029 if (step->marker != MARKER_AXIS_X &&
9030 step->marker != MARKER_AXIS_Y)
9033 step->axis = event.jaxis.axis;
9034 strcat(mapping, step->field);
9035 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
9036 strcat(mapping, temp);
9044 case SDL_JOYHATMOTION:
9045 // ignore centering; we're probably just coming back
9046 // to the center from the previous item we set
9047 if (event.jhat.value == SDL_HAT_CENTERED)
9050 for (j = 0; j < i; j++)
9051 if (steps[j].hat == event.jhat.hat &&
9052 steps[j].hat_value == event.jhat.value)
9057 step->hat = event.jhat.hat;
9058 step->hat_value = event.jhat.value;
9059 strcat(mapping, step->field);
9060 snprintf(temp, sizeof(temp), ":h%u.%u,",
9061 event.jhat.hat, event.jhat.value );
9062 strcat(mapping, temp);
9069 case SDL_JOYBALLMOTION:
9072 case SDL_JOYBUTTONUP:
9073 for (j = 0; j < i; j++)
9074 if (steps[j].button == event.jbutton.button)
9079 step->button = event.jbutton.button;
9080 strcat(mapping, step->field);
9081 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9082 strcat(mapping, temp);
9089 case SDL_FINGERDOWN:
9090 case SDL_MOUSEBUTTONDOWN:
9098 if (event.key.keysym.sym == KSYM_BackSpace ||
9099 event.key.keysym.sym == KSYM_Back)
9111 prev_step = &steps[i - 1];
9112 strcpy(mapping, prev_step->mapping);
9119 if (event.key.keysym.sym == KSYM_space ||
9120 event.key.keysym.sym == KSYM_Return ||
9121 event.key.keysym.sym == KSYM_Menu)
9130 if (event.key.keysym.sym == KSYM_Escape)
9140 program.exit_function(0);
9147 // do not handle events for longer than standard frame delay period
9148 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9157 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9160 // activate mapping for this game
9161 SDL_GameControllerAddMapping(mapping);
9163 // save mapping to personal mappings
9164 SaveSetup_AddGameControllerMapping(mapping);
9167 // wait until the last pending event was removed from event queue
9168 while (NextValidEvent(&event));
9173 static int ConfigureJoystickMain(int player_nr)
9175 char *device_name = setup.input[player_nr].joy.device_name;
9176 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9177 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9178 int success = FALSE;
9181 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9182 return JOYSTICK_NOT_AVAILABLE;
9184 if (!joystick_active || !setup.input[player_nr].use_joystick)
9185 return JOYSTICK_NOT_AVAILABLE;
9188 FadeOut(REDRAW_FIELD);
9190 // close all joystick devices (potentially opened as game controllers)
9191 for (i = 0; i < SDL_NumJoysticks(); i++)
9192 SDLCloseJoystick(i);
9194 // open joystick device as plain joystick to configure as game controller
9195 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9197 // as the joystick was successfully opened before, this should not happen
9198 if (joystick == NULL)
9201 // create new game controller mapping (buttons and axes) for joystick device
9202 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9204 // close joystick (and maybe re-open as configured game controller later)
9205 SDL_JoystickClose(joystick);
9207 // re-open all joystick devices (potentially as game controllers)
9208 for (i = 0; i < SDL_NumJoysticks(); i++)
9211 // clear all joystick input actions for all joystick devices
9212 SDLClearJoystickState();
9214 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9217 void ConfigureJoystick(int player_nr)
9219 boolean state = ConfigureJoystickMain(player_nr);
9221 if (state != JOYSTICK_NOT_CONFIGURED)
9223 boolean success = (state == JOYSTICK_CONFIGURED);
9224 char message1[MAX_OUTPUT_LINESIZE + 1];
9225 char *message2 = (success ? "configured!" : "not available!");
9226 char *device_name = setup.input[player_nr].joy.device_name;
9227 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9228 int font_nr = FONT_TITLE_1;
9229 int font_height = getFontHeight(font_nr);
9230 int ypos1 = SYSIZE / 2 - font_height * 2;
9231 int ypos2 = SYSIZE / 2 - font_height * 1;
9232 unsigned int wait_frame_delay = 0;
9233 unsigned int wait_frame_delay_value = 2000;
9235 ResetDelayCounter(&wait_frame_delay);
9239 sprintf(message1, "Joystick %d", nr);
9241 DrawTextSCentered(ypos1, font_nr, message1);
9242 DrawTextSCentered(ypos2, font_nr, message2);
9244 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9250 DrawSetupScreen_Input();
9253 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9255 if (y < video.screen_height / 3)
9257 // remap touch gadgets to access upper part of the screen
9258 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9259 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9261 else if (y > 2 * video.screen_height / 3)
9263 // remap touch gadgets to access lower part of the screen
9264 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9265 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9269 static boolean ConfigureVirtualButtonsMain(void)
9271 static char *customize_step_text[] =
9280 char grid_button[] =
9282 CHAR_GRID_BUTTON_LEFT,
9283 CHAR_GRID_BUTTON_RIGHT,
9284 CHAR_GRID_BUTTON_UP,
9285 CHAR_GRID_BUTTON_DOWN,
9286 CHAR_GRID_BUTTON_SNAP,
9287 CHAR_GRID_BUTTON_DROP
9296 int font_nr = FONT_INPUT_1_ACTIVE;
9297 int font_height = getFontHeight(font_nr);
9298 int ypos1 = SYSIZE / 2 - font_height * 2;
9299 int ypos2 = SYSIZE / 2 - font_height * 1;
9300 boolean success = FALSE;
9301 boolean finished = FALSE;
9303 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9304 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9305 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9306 boolean set_grid_button = FALSE;
9307 int nr = GRID_ACTIVE_NR();
9310 for (x = 0; x < MAX_GRID_XSIZE; x++)
9311 for (y = 0; y < MAX_GRID_YSIZE; y++)
9312 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9314 overlay.grid_button_highlight = grid_button[step_nr];
9319 FadeOut(REDRAW_FIELD);
9323 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9324 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9325 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9327 FadeIn(REDRAW_FIELD);
9329 SetOverlayShowGrid(TRUE);
9331 // map gadgets for setup touch buttons menu screen
9332 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9338 while (NextValidEvent(&event))
9340 int action = ACTION_NONE;
9342 // ---------- handle events and set the resulting action ----------
9348 UserEvent *user = (UserEvent *)&event;
9349 int id = user->value1;
9351 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9352 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9353 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9354 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9359 case EVENT_KEYPRESS:
9361 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9363 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9364 key == KSYM_BackSpace ||
9365 key == KSYM_Back ? ACTION_BACK :
9366 key == KSYM_Return ||
9368 key == KSYM_space ? ACTION_NEXT :
9373 case EVENT_KEYRELEASE:
9374 key_joystick_mapping = 0;
9377 case EVENT_BUTTONPRESS:
9378 case EVENT_BUTTONRELEASE:
9380 ButtonEvent *button = (ButtonEvent *)&event;
9382 motion_status = FALSE;
9384 if (button->type == EVENT_BUTTONPRESS)
9385 button_status = button->button;
9387 button_status = MB_RELEASED;
9389 if (HandleGadgets(button->x, button->y, button_status))
9391 // do not handle this button event anymore
9395 button->x += video.screen_xoffset;
9396 button->y += video.screen_yoffset;
9398 x = button->x * overlay.grid_xsize / video.screen_width;
9399 y = button->y * overlay.grid_ysize / video.screen_height;
9401 if (button->type == EVENT_BUTTONPRESS)
9404 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9405 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9407 set_grid_button = TRUE;
9410 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9414 case EVENT_MOTIONNOTIFY:
9416 MotionEvent *motion = (MotionEvent *)&event;
9418 motion_status = TRUE;
9420 if (HandleGadgets(motion->x, motion->y, button_status))
9422 // do not handle this button event anymore
9426 motion->x += video.screen_xoffset;
9427 motion->y += video.screen_yoffset;
9429 x = motion->x * overlay.grid_xsize / video.screen_width;
9430 y = motion->y * overlay.grid_ysize / video.screen_height;
9432 set_grid_button = TRUE;
9434 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9438 case SDL_WINDOWEVENT:
9439 HandleWindowEvent((WindowEvent *) &event);
9441 // check if device has been rotated
9442 if (nr != GRID_ACTIVE_NR())
9444 nr = GRID_ACTIVE_NR();
9446 for (x = 0; x < MAX_GRID_XSIZE; x++)
9447 for (y = 0; y < MAX_GRID_YSIZE; y++)
9448 grid_button_old[x][y] = grid_button_tmp[x][y] =
9449 overlay.grid_button[x][y];
9454 case SDL_APP_WILLENTERBACKGROUND:
9455 case SDL_APP_DIDENTERBACKGROUND:
9456 case SDL_APP_WILLENTERFOREGROUND:
9457 case SDL_APP_DIDENTERFOREGROUND:
9458 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9462 HandleOtherEvents(&event);
9466 // ---------- perform action set by handling events ----------
9468 if (action == ACTION_ESCAPE)
9470 // abort and restore the old key bindings
9472 for (x = 0; x < MAX_GRID_XSIZE; x++)
9473 for (y = 0; y < MAX_GRID_YSIZE; y++)
9474 overlay.grid_button[x][y] = grid_button_old[x][y];
9476 FadeSkipNextFadeIn();
9480 else if (action == ACTION_BACK)
9482 // keep the configured key bindings and go to previous page
9488 FadeSkipNextFadeIn();
9493 else if (action == ACTION_NEXT)
9495 // keep the configured key bindings and go to next page
9499 // all virtual buttons configured
9507 if (action != ACTION_NONE && !finished)
9509 for (x = 0; x < MAX_GRID_XSIZE; x++)
9510 for (y = 0; y < MAX_GRID_YSIZE; y++)
9511 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9513 overlay.grid_button_highlight = grid_button[step_nr];
9515 // configure next virtual button
9519 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9520 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9521 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9524 if (set_grid_button)
9526 overlay.grid_button[x][y] =
9527 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9528 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9529 grid_button_tmp[x][y]);
9531 set_grid_button = FALSE;
9538 for (x = 0; x < MAX_GRID_XSIZE; x++)
9539 for (y = 0; y < MAX_GRID_YSIZE; y++)
9540 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9542 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9544 SetOverlayShowGrid(FALSE);
9549 void ConfigureVirtualButtons(void)
9551 boolean success = ConfigureVirtualButtonsMain();
9553 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9554 SCREEN_MASK_TOUCH2);
9558 int font_nr = FONT_TITLE_1;
9559 int font_height = getFontHeight(font_nr);
9560 int ypos1 = SYSIZE / 2 - font_height * 2;
9561 int ypos2 = SYSIZE / 2 - font_height * 1;
9562 unsigned int wait_frame_delay = 0;
9563 unsigned int wait_frame_delay_value = 2000;
9565 ResetDelayCounter(&wait_frame_delay);
9569 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9570 DrawTextSCentered(ypos2, font_nr, "configured!");
9572 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9579 void DrawSetupScreen(void)
9584 if (setup_mode == SETUP_MODE_INPUT)
9585 DrawSetupScreen_Input();
9586 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9587 DrawChooseTree(&scores_type_current);
9588 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9589 DrawChooseTree(&game_speed_current);
9590 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9591 DrawChooseTree(&scroll_delay_current);
9592 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9593 DrawChooseTree(&snapshot_mode_current);
9594 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9595 DrawChooseTree(&window_size_current);
9596 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9597 DrawChooseTree(&scaling_type_current);
9598 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9599 DrawChooseTree(&rendering_mode_current);
9600 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9601 DrawChooseTree(&vsync_mode_current);
9602 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9603 DrawChooseTree(&artwork.gfx_current);
9604 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9605 DrawChooseTree(&artwork.snd_current);
9606 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9607 DrawChooseTree(&artwork.mus_current);
9608 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9609 DrawChooseTree(&volume_simple_current);
9610 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9611 DrawChooseTree(&volume_loops_current);
9612 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9613 DrawChooseTree(&volume_music_current);
9614 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9615 DrawChooseTree(&touch_control_current);
9616 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9617 DrawChooseTree(&move_distance_current);
9618 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9619 DrawChooseTree(&drop_distance_current);
9620 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9621 DrawChooseTree(&transparency_current);
9622 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9623 DrawChooseTree(&grid_size_current[0][0]);
9624 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9625 DrawChooseTree(&grid_size_current[0][1]);
9626 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9627 DrawChooseTree(&grid_size_current[1][0]);
9628 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9629 DrawChooseTree(&grid_size_current[1][1]);
9631 DrawSetupScreen_Generic();
9633 PlayMenuSoundsAndMusic();
9636 void RedrawSetupScreenAfterFullscreenToggle(void)
9638 if (setup_mode == SETUP_MODE_GRAPHICS ||
9639 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9641 // update list selection from "setup.window_scaling_percent"
9642 execSetupGraphics_setWindowSizes(TRUE);
9648 void RedrawSetupScreenAfterScreenRotation(int nr)
9652 if (setup_mode == SETUP_MODE_TOUCH)
9654 // update virtual button settings (depending on screen orientation)
9657 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9659 // save already configured virtual buttons
9660 for (x = 0; x < MAX_GRID_XSIZE; x++)
9661 for (y = 0; y < MAX_GRID_YSIZE; y++)
9662 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9666 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9668 if (setup_mode == SETUP_MODE_INPUT)
9669 HandleSetupScreen_Input(mx, my, dx, dy, button);
9670 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9671 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9672 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9673 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9674 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9675 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9676 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9677 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9678 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9679 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9680 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9681 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9682 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9683 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9684 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9685 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9686 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9687 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9688 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9689 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9690 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9691 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9692 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9693 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9694 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9695 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9696 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9697 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9698 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9699 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9700 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9701 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9702 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9703 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9704 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9705 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9706 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9707 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9708 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9709 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9710 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9711 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9712 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9713 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9715 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9718 void HandleGameActions(void)
9720 if (setup.ask_on_game_over)
9723 if (game.restart_game_message != NULL)
9725 RequestRestartGame(game.restart_game_message);
9730 if (game_status != GAME_MODE_PLAYING)
9733 GameActions(); // main game loop
9735 if (tape.auto_play && !tape.playing)
9736 AutoPlayTapesContinue(); // continue automatically playing next tape
9740 // ---------- new screen button stuff --------------------------------------
9744 int gfx_unpressed, gfx_pressed;
9745 struct MenuPosInfo *pos;
9746 boolean *check_value;
9749 unsigned int event_mask;
9750 boolean is_touch_button;
9752 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9755 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9756 &menu.main.button.prev_level, NULL,
9757 SCREEN_CTRL_ID_PREV_LEVEL,
9759 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9760 FALSE, "previous level"
9763 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9764 &menu.main.button.next_level, NULL,
9765 SCREEN_CTRL_ID_NEXT_LEVEL,
9767 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9771 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9772 &menu.scores.button.prev_level, NULL,
9773 SCREEN_CTRL_ID_PREV_LEVEL2,
9775 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9776 FALSE, "previous level"
9779 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9780 &menu.scores.button.next_level, NULL,
9781 SCREEN_CTRL_ID_NEXT_LEVEL2,
9783 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9787 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9788 &menu.main.button.first_level, NULL,
9789 SCREEN_CTRL_ID_FIRST_LEVEL,
9792 FALSE, "first level"
9795 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9796 &menu.main.button.last_level, NULL,
9797 SCREEN_CTRL_ID_LAST_LEVEL,
9803 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9804 &menu.main.button.level_number, NULL,
9805 SCREEN_CTRL_ID_LEVEL_NUMBER,
9808 FALSE, "level number"
9811 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9812 &menu.setup.button.prev_player, NULL,
9813 SCREEN_CTRL_ID_PREV_PLAYER,
9815 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9816 FALSE, "previous player"
9819 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9820 &menu.setup.button.next_player, NULL,
9821 SCREEN_CTRL_ID_NEXT_PLAYER,
9823 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9824 FALSE, "next player"
9827 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9828 &menu.main.button.insert_solution, NULL,
9829 SCREEN_CTRL_ID_INSERT_SOLUTION,
9830 SCREEN_MASK_MAIN_HAS_SOLUTION,
9832 FALSE, "insert solution tape"
9835 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9836 &menu.main.button.play_solution, NULL,
9837 SCREEN_CTRL_ID_PLAY_SOLUTION,
9838 SCREEN_MASK_MAIN_HAS_SOLUTION,
9840 FALSE, "play solution tape"
9843 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9844 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9845 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9847 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9848 FALSE, "switch ECS/AGA chipset"
9851 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9852 &menu.setup.button.touch_back, NULL,
9853 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9856 TRUE, "previous page"
9859 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9860 &menu.setup.button.touch_next, NULL,
9861 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9867 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9868 &menu.setup.button.touch_back2, NULL,
9869 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9872 TRUE, "previous page"
9875 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9876 &menu.setup.button.touch_next2, NULL,
9877 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9886 int gfx_unpressed, gfx_pressed;
9890 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9893 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9894 -1, -1, // these values are not constant, but can change at runtime
9895 SCREEN_CTRL_ID_SCROLL_UP,
9899 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9900 -1, -1, // these values are not constant, but can change at runtime
9901 SCREEN_CTRL_ID_SCROLL_DOWN,
9908 int gfx_unpressed, gfx_pressed;
9914 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9917 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9918 -1, -1, // these values are not constant, but can change at runtime
9919 -1, -1, // these values are not constant, but can change at runtime
9920 GD_TYPE_SCROLLBAR_VERTICAL,
9921 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9922 "scroll level series vertically"
9934 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9937 IMG_SETUP_INPUT_TEXT,
9938 SCREEN_CTRL_ID_NETWORK_SERVER,
9939 -1, -1, // these values are not constant, but can change at runtime
9940 MAX_SETUP_TEXT_INPUT_LEN,
9941 network_server_hostname,
9942 "Network Server Hostname / IP"
9946 static void CreateScreenMenubuttons(void)
9948 struct GadgetInfo *gi;
9949 unsigned int event_mask;
9952 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9954 struct MenuPosInfo *pos = menubutton_info[i].pos;
9955 int screen_mask = menubutton_info[i].screen_mask;
9956 boolean is_touch_button = menubutton_info[i].is_touch_button;
9957 boolean is_check_button = menubutton_info[i].check_value != NULL;
9958 boolean is_score_button = (screen_mask == SCREEN_MASK_SCORES);
9959 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9960 int gfx_unpressed, gfx_pressed;
9961 int x, y, width, height;
9962 int gd_x1, gd_x2, gd_y1, gd_y2;
9963 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9964 int id = menubutton_info[i].gadget_id;
9965 int type = GD_TYPE_NORMAL_BUTTON;
9966 boolean checked = FALSE;
9968 event_mask = menubutton_info[i].event_mask;
9970 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9971 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9973 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9974 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9976 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9977 gfx_pressed = menubutton_info[i].gfx_pressed;
9978 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9979 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9980 gd_x1 = graphic_info[gfx_unpressed].src_x;
9981 gd_y1 = graphic_info[gfx_unpressed].src_y;
9982 gd_x2 = graphic_info[gfx_pressed].src_x;
9983 gd_y2 = graphic_info[gfx_pressed].src_y;
9989 if (is_touch_button)
9991 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9992 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9995 if (is_check_button)
9997 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9998 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9999 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
10000 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
10002 type = GD_TYPE_CHECK_BUTTON;
10003 checked = *menubutton_info[i].check_value;
10006 if (is_score_button)
10008 // if x/y set to -1, dynamically place buttons next to title text
10009 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10012 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10013 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10014 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10015 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10018 y = mSY + MENU_TITLE1_YPOS;
10021 gi = CreateGadget(GDI_CUSTOM_ID, id,
10022 GDI_CUSTOM_TYPE_ID, i,
10023 GDI_IMAGE_ID, gfx_unpressed,
10024 GDI_INFO_TEXT, menubutton_info[i].infotext,
10028 GDI_HEIGHT, height,
10030 GDI_STATE, GD_BUTTON_UNPRESSED,
10031 GDI_CHECKED, checked,
10032 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10033 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10034 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
10035 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
10036 GDI_DIRECT_DRAW, FALSE,
10037 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10038 GDI_EVENT_MASK, event_mask,
10039 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10043 Fail("cannot create gadget");
10045 screen_gadget[id] = gi;
10049 static void CreateScreenScrollbuttons(void)
10051 struct GadgetInfo *gi;
10052 unsigned int event_mask;
10055 // these values are not constant, but can change at runtime
10056 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10057 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10058 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10059 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10061 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10063 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10064 int gfx_unpressed, gfx_pressed;
10065 int x, y, width, height;
10066 int gd_x1, gd_x2, gd_y1, gd_y2;
10067 int id = scrollbutton_info[i].gadget_id;
10069 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10071 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10072 y = mSY + scrollbutton_info[i].y;
10073 width = SC_SCROLLBUTTON_XSIZE;
10074 height = SC_SCROLLBUTTON_YSIZE;
10076 // correct scrollbar position if placed outside menu (playfield) area
10077 if (x > SX + SC_SCROLL_UP_XPOS)
10078 x = SX + SC_SCROLL_UP_XPOS;
10080 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10081 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10082 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10084 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10085 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10086 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10087 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10088 gd_x1 = graphic_info[gfx_unpressed].src_x;
10089 gd_y1 = graphic_info[gfx_unpressed].src_y;
10090 gd_x2 = graphic_info[gfx_pressed].src_x;
10091 gd_y2 = graphic_info[gfx_pressed].src_y;
10093 gi = CreateGadget(GDI_CUSTOM_ID, id,
10094 GDI_CUSTOM_TYPE_ID, i,
10095 GDI_IMAGE_ID, gfx_unpressed,
10096 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10100 GDI_HEIGHT, height,
10101 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10102 GDI_STATE, GD_BUTTON_UNPRESSED,
10103 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10104 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10105 GDI_DIRECT_DRAW, FALSE,
10106 GDI_EVENT_MASK, event_mask,
10107 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10111 Fail("cannot create gadget");
10113 screen_gadget[id] = gi;
10117 static void CreateScreenScrollbars(void)
10121 // these values are not constant, but can change at runtime
10122 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10123 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10124 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10125 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10127 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10129 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10130 int gfx_unpressed, gfx_pressed;
10131 int x, y, width, height;
10132 int gd_x1, gd_x2, gd_y1, gd_y2;
10133 struct GadgetInfo *gi;
10134 int items_max, items_visible, item_position;
10135 unsigned int event_mask;
10136 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10137 int id = scrollbar_info[i].gadget_id;
10139 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10141 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10142 y = mSY + scrollbar_info[i].y;
10143 width = scrollbar_info[i].width;
10144 height = scrollbar_info[i].height;
10146 // correct scrollbar position if placed outside menu (playfield) area
10147 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10148 x = SX + SC_SCROLL_VERTICAL_XPOS;
10150 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10151 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10153 items_max = num_page_entries;
10154 items_visible = num_page_entries;
10157 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10158 gfx_pressed = scrollbar_info[i].gfx_pressed;
10159 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10160 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10161 gd_x1 = graphic_info[gfx_unpressed].src_x;
10162 gd_y1 = graphic_info[gfx_unpressed].src_y;
10163 gd_x2 = graphic_info[gfx_pressed].src_x;
10164 gd_y2 = graphic_info[gfx_pressed].src_y;
10166 gi = CreateGadget(GDI_CUSTOM_ID, id,
10167 GDI_CUSTOM_TYPE_ID, i,
10168 GDI_IMAGE_ID, gfx_unpressed,
10169 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10173 GDI_HEIGHT, height,
10174 GDI_TYPE, scrollbar_info[i].type,
10175 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10176 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10177 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10178 GDI_WHEEL_AREA_X, SX,
10179 GDI_WHEEL_AREA_Y, SY,
10180 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10181 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10182 GDI_STATE, GD_BUTTON_UNPRESSED,
10183 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10184 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10185 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10186 GDI_DIRECT_DRAW, FALSE,
10187 GDI_EVENT_MASK, event_mask,
10188 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10192 Fail("cannot create gadget");
10194 screen_gadget[id] = gi;
10198 static void CreateScreenTextInputGadgets(void)
10202 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10204 int graphic = textinput_info[i].graphic;
10205 struct GraphicInfo *gd = &graphic_info[graphic];
10206 int gd_x1 = gd->src_x;
10207 int gd_y1 = gd->src_y;
10208 int gd_x2 = gd->src_x + gd->active_xoffset;
10209 int gd_y2 = gd->src_y + gd->active_yoffset;
10210 struct GadgetInfo *gi;
10211 unsigned int event_mask;
10212 int id = textinput_info[i].gadget_id;
10213 int x = textinput_info[i].x;
10214 int y = textinput_info[i].y;
10216 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10218 gi = CreateGadget(GDI_CUSTOM_ID, id,
10219 GDI_CUSTOM_TYPE_ID, i,
10220 GDI_INFO_TEXT, textinput_info[i].infotext,
10223 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10224 GDI_TEXT_VALUE, textinput_info[i].value,
10225 GDI_TEXT_SIZE, textinput_info[i].size,
10226 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10227 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10228 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10229 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10230 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10231 GDI_DESIGN_WIDTH, gd->width,
10232 GDI_EVENT_MASK, event_mask,
10233 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10234 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10238 Fail("cannot create gadget");
10240 screen_gadget[id] = gi;
10244 void CreateScreenGadgets(void)
10246 CreateScreenMenubuttons();
10248 CreateScreenScrollbuttons();
10249 CreateScreenScrollbars();
10251 CreateScreenTextInputGadgets();
10254 void FreeScreenGadgets(void)
10258 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10259 FreeGadget(screen_gadget[i]);
10262 static void RedrawScreenMenuGadgets(int screen_mask)
10266 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10267 if (screen_mask & menubutton_info[i].screen_mask)
10268 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10271 static void MapScreenMenuGadgets(int screen_mask)
10275 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10276 if (screen_mask & menubutton_info[i].screen_mask)
10277 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10280 static void UnmapScreenMenuGadgets(int screen_mask)
10284 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10286 if (screen_mask & menubutton_info[i].screen_mask)
10288 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10290 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10291 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10292 screen_gadget[menubutton_info[i].gadget_id]->y,
10293 screen_gadget[menubutton_info[i].gadget_id]->width,
10294 screen_gadget[menubutton_info[i].gadget_id]->height);
10299 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10302 MapScreenMenuGadgets(screen_mask);
10304 UnmapScreenMenuGadgets(screen_mask);
10307 static void MapScreenGadgets(int num_entries)
10311 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10314 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10315 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10317 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10318 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10321 static void UnmapScreenGadgets()
10325 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10326 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10328 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10329 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10332 static void MapScreenTreeGadgets(TreeInfo *ti)
10334 MapScreenGadgets(numTreeInfoInGroup(ti));
10337 static void UnmapScreenTreeGadgets(void)
10339 UnmapScreenGadgets();
10342 static void HandleScreenGadgets(struct GadgetInfo *gi)
10344 int id = gi->custom_id;
10345 int button = gi->event.button;
10346 int step = (button == MB_LEFTBUTTON ? 1 :
10347 button == MB_MIDDLEBUTTON ? 5 :
10348 button == MB_RIGHTBUTTON ? 10 : 1);
10352 case SCREEN_CTRL_ID_PREV_LEVEL:
10353 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10356 case SCREEN_CTRL_ID_NEXT_LEVEL:
10357 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10360 case SCREEN_CTRL_ID_PREV_LEVEL2:
10361 HandleHallOfFame_SelectLevel(step, -1);
10364 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10365 HandleHallOfFame_SelectLevel(step, +1);
10368 case SCREEN_CTRL_ID_FIRST_LEVEL:
10369 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10372 case SCREEN_CTRL_ID_LAST_LEVEL:
10373 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10376 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10377 CloseDoor(DOOR_CLOSE_2);
10378 SetGameStatus(GAME_MODE_LEVELNR);
10379 DrawChooseLevelNr();
10382 case SCREEN_CTRL_ID_PREV_PLAYER:
10383 HandleSetupScreen_Input_Player(step, -1);
10386 case SCREEN_CTRL_ID_NEXT_PLAYER:
10387 HandleSetupScreen_Input_Player(step, +1);
10390 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10391 InsertSolutionTape();
10394 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10395 PlaySolutionTape();
10398 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10399 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10403 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10404 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10405 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10406 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10407 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10410 case SCREEN_CTRL_ID_SCROLL_UP:
10411 if (game_status == GAME_MODE_NAMES)
10412 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10413 else if (game_status == GAME_MODE_LEVELS)
10414 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10415 else if (game_status == GAME_MODE_LEVELNR)
10416 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10417 else if (game_status == GAME_MODE_SETUP)
10418 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10419 else if (game_status == GAME_MODE_INFO)
10420 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10421 else if (game_status == GAME_MODE_SCORES)
10422 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10425 case SCREEN_CTRL_ID_SCROLL_DOWN:
10426 if (game_status == GAME_MODE_NAMES)
10427 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10428 else if (game_status == GAME_MODE_LEVELS)
10429 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10430 else if (game_status == GAME_MODE_LEVELNR)
10431 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10432 else if (game_status == GAME_MODE_SETUP)
10433 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10434 else if (game_status == GAME_MODE_INFO)
10435 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10436 else if (game_status == GAME_MODE_SCORES)
10437 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10440 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10441 if (game_status == GAME_MODE_NAMES)
10442 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10443 else if (game_status == GAME_MODE_LEVELS)
10444 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10445 else if (game_status == GAME_MODE_LEVELNR)
10446 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10447 else if (game_status == GAME_MODE_SETUP)
10448 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10449 else if (game_status == GAME_MODE_INFO)
10450 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10451 else if (game_status == GAME_MODE_SCORES)
10452 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10455 case SCREEN_CTRL_ID_NETWORK_SERVER:
10457 if (!strEqual(gi->textinput.value, ""))
10459 setString(&setup.network_server_hostname, gi->textinput.value);
10461 network.server_host = setup.network_server_hostname;
10465 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10467 network.server_host = NULL;
10470 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10471 network.server_host = NULL;
10473 execSetupGame_setNetworkServerText();
10485 void DumpScreenIdentifiers(void)
10489 Print("Active screen elements on current screen:\n");
10491 for (i = 0; main_controls[i].nr != -1; i++)
10493 struct MainControlInfo *mci = &main_controls[i];
10495 if (mci->button_graphic != -1)
10497 char *token = getTokenFromImageID(mci->button_graphic);
10499 Print("- '%s'\n", token);
10506 boolean DoScreenAction(int image_id)
10510 if (game_status != GAME_MODE_MAIN)
10513 for (i = 0; main_controls[i].nr != -1; i++)
10515 struct MainControlInfo *mci = &main_controls[i];
10516 struct MenuPosInfo *pos = mci->pos_button;
10518 if (mci->button_graphic == image_id)
10520 int x = mSX + pos->x;
10521 int y = mSY + pos->y;
10523 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10532 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10534 // get tree info node of newly added level or artwork set
10535 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10536 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10538 if (tree_node_new == NULL) // should not happen
10541 // if request dialog is active, do nothing
10542 if (game.request_active)
10545 if (game_status == GAME_MODE_MAIN &&
10546 tree_type == TREE_TYPE_LEVEL_DIR)
10548 // when adding new level set in main menu, select it as current level set
10550 // change current level set to newly added level set from zip file
10551 leveldir_current = tree_node_new;
10553 // change current level number to first level of newly added level set
10554 level_nr = leveldir_current->first_level;
10556 // redraw screen to reflect changed level set
10559 // save this level set and level number as last selected level set
10560 SaveLevelSetup_LastSeries();
10561 SaveLevelSetup_SeriesInfo();
10563 else if (game_status == GAME_MODE_LEVELS &&
10564 tree_type == TREE_TYPE_LEVEL_DIR)
10566 // when adding new level set in level set menu, set cursor and update screen
10568 leveldir_current = tree_node_new;
10570 DrawChooseTree(&leveldir_current);
10572 else if (game_status == GAME_MODE_SETUP)
10574 // when adding new artwork set in setup menu, set cursor and update screen
10576 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10577 tree_type == TREE_TYPE_GRAPHICS_DIR)
10579 artwork.gfx_current = tree_node_new;
10581 DrawChooseTree(&artwork.gfx_current);
10583 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10584 tree_type == TREE_TYPE_SOUNDS_DIR)
10586 artwork.snd_current = tree_node_new;
10588 DrawChooseTree(&artwork.snd_current);
10590 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10591 tree_type == TREE_TYPE_MUSIC_DIR)
10593 artwork.mus_current = tree_node_new;
10595 DrawChooseTree(&artwork.mus_current);
10600 static int UploadTapes(void)
10602 SetGameStatus(GAME_MODE_LOADING);
10604 FadeSetEnterScreen();
10605 FadeOut(REDRAW_ALL);
10607 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10609 FadeIn(REDRAW_ALL);
10611 DrawInitTextHead("Uploading tapes");
10613 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10614 global.autoplay_leveldir = "ALL";
10615 global.autoplay_all = TRUE;
10617 int num_tapes_uploaded = AutoPlayTapes();
10619 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10620 global.autoplay_leveldir = NULL;
10621 global.autoplay_all = FALSE;
10623 SetGameStatus(GAME_MODE_MAIN);
10627 return num_tapes_uploaded;
10630 static boolean OfferUploadTapes(void)
10632 if (!Request(setup.has_remaining_tapes ?
10633 "Upload missing tapes to the high score server now?" :
10634 "Upload all your tapes to the high score server now?", REQ_ASK))
10637 int num_tapes_uploaded = UploadTapes();
10640 if (num_tapes_uploaded < 0)
10642 num_tapes_uploaded = -num_tapes_uploaded - 1;
10644 if (num_tapes_uploaded == 0)
10645 sprintf(message, "Upload failed! No tapes uploaded!");
10646 else if (num_tapes_uploaded == 1)
10647 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10649 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10650 num_tapes_uploaded);
10652 Request(message, REQ_CONFIRM);
10654 // if uploading tapes failed, add tape upload entry to setup menu
10655 setup.provide_uploading_tapes = TRUE;
10656 setup.has_remaining_tapes = TRUE;
10658 SaveSetup_ServerSetup();
10663 if (num_tapes_uploaded == 0)
10664 sprintf(message, "No tapes uploaded!");
10665 else if (num_tapes_uploaded == 1)
10666 sprintf(message, "1 tape uploaded!");
10668 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10670 Request(message, REQ_CONFIRM);
10672 if (num_tapes_uploaded > 0)
10673 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10675 // after all tapes have been uploaded, remove entry from setup menu
10676 setup.provide_uploading_tapes = FALSE;
10677 setup.has_remaining_tapes = FALSE;
10679 SaveSetup_ServerSetup();
10684 static void CheckUploadTapes(void)
10686 if (!setup.ask_for_uploading_tapes)
10689 // after asking for uploading tapes, do not ask again
10690 setup.ask_for_uploading_tapes = FALSE;
10691 setup.ask_for_remaining_tapes = FALSE;
10693 if (directoryExists(getTapeDir(NULL)))
10695 boolean tapes_uploaded = OfferUploadTapes();
10697 if (!tapes_uploaded)
10699 Request(setup.has_remaining_tapes ?
10700 "You can upload missing tapes from the setup menu later!" :
10701 "You can upload your tapes from the setup menu later!",
10707 // if tapes directory does not exist yet, never offer uploading all tapes
10708 setup.provide_uploading_tapes = FALSE;
10711 SaveSetup_ServerSetup();
10714 static void UpgradePlayerUUID(void)
10716 ApiResetUUIDAsThread(getUUID());
10719 static void CheckUpgradePlayerUUID(void)
10721 if (setup.player_version > 1)
10724 UpgradePlayerUUID();
10727 void CheckApiServerTasks(void)
10729 // check if the player's UUID has to be upgraded
10730 CheckUpgradePlayerUUID();
10732 // check if there are any tapes to be uploaded
10733 CheckUploadTapes();