1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
27 #define DEBUG_JOYSTICKS 0
30 // screens on the info screen
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 // screens on the setup screen
43 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
44 // (should also match corresponding entries in src/conf_gfx.c)
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_ENGINES 2
48 #define SETUP_MODE_EDITOR 3
49 #define SETUP_MODE_GRAPHICS 4
50 #define SETUP_MODE_SOUND 5
51 #define SETUP_MODE_ARTWORK 6
52 #define SETUP_MODE_INPUT 7
53 #define SETUP_MODE_TOUCH 8
54 #define SETUP_MODE_SHORTCUTS 9
55 #define SETUP_MODE_SHORTCUTS_1 10
56 #define SETUP_MODE_SHORTCUTS_2 11
57 #define SETUP_MODE_SHORTCUTS_3 12
58 #define SETUP_MODE_SHORTCUTS_4 13
59 #define SETUP_MODE_SHORTCUTS_5 14
61 // sub-screens on the setup screen (generic)
62 #define SETUP_MODE_CHOOSE_ARTWORK 15
63 #define SETUP_MODE_CHOOSE_OTHER 16
65 // sub-screens on the setup screen (specific)
66 #define SETUP_MODE_CHOOSE_SCORES_TYPE 17
67 #define SETUP_MODE_CHOOSE_GAME_SPEED 18
68 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 19
69 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 20
70 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 21
71 #define SETUP_MODE_CHOOSE_SCALING_TYPE 22
72 #define SETUP_MODE_CHOOSE_RENDERING 23
73 #define SETUP_MODE_CHOOSE_VSYNC 24
74 #define SETUP_MODE_CHOOSE_GRAPHICS 25
75 #define SETUP_MODE_CHOOSE_SOUNDS 26
76 #define SETUP_MODE_CHOOSE_MUSIC 27
77 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 28
78 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 29
79 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 30
80 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 31
81 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 33
83 #define SETUP_MODE_CHOOSE_TRANSPARENCY 34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 36
86 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 37
87 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 38
88 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 39
90 #define MAX_SETUP_MODES 40
92 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
94 // setup screen titles
95 #define STR_SETUP_MAIN "Setup"
96 #define STR_SETUP_GAME "Game & Menu"
97 #define STR_SETUP_ENGINES "Game Engines"
98 #define STR_SETUP_EDITOR "Editor"
99 #define STR_SETUP_GRAPHICS "Graphics"
100 #define STR_SETUP_SOUND "Sound & Music"
101 #define STR_SETUP_ARTWORK "Custom Artwork"
102 #define STR_SETUP_INPUT "Input Devices"
103 #define STR_SETUP_TOUCH "Touch Controls"
104 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
105 #define STR_SETUP_EXIT "Exit"
106 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
108 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
109 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
110 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
111 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
112 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
113 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
114 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
115 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
116 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
117 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
118 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
119 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
120 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
121 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
122 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
125 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
126 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
128 // other screen text constants
129 #define STR_CHOOSE_TREE_EDIT "Edit"
130 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
131 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
133 // for input setup functions
134 #define SETUPINPUT_SCREEN_POS_START 0
135 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
136 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
137 #define SETUPINPUT_SCREEN_POS_END 13
139 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
140 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
142 #define MAX_SETUP_TEXT_INPUT_LEN 28
144 // for various menu stuff
145 #define MENU_SCREEN_START_XPOS 1
146 #define MENU_SCREEN_START_YPOS 2
147 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
148 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
149 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
150 #define MENU_TITLE1_YPOS 8
151 #define MENU_TITLE2_YPOS 46
152 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
153 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
154 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
155 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
156 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
159 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
160 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
161 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
162 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
163 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
164 MENU_INFO_FONT_TITLE))
165 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
166 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
167 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
168 MENU_SCREEN_INFO_YSTART2 - \
170 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
171 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
172 MENU_SCREEN_INFO_YSTEP)
173 #define NUM_INFO_ELEMENTS_FROM_CONF \
174 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
175 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
176 MAX_MENU_ENTRIES_ON_SCREEN)
177 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
178 MAX_INFO_ELEMENTS_ON_SCREEN), \
179 NUM_INFO_ELEMENTS_FROM_CONF)
180 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
181 #define MAX_MENU_TEXT_LENGTH_BIG 13
182 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
184 // screen gadget identifiers
185 #define SCREEN_CTRL_ID_PREV_LEVEL 0
186 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
187 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
188 #define SCREEN_CTRL_ID_LAST_LEVEL 3
189 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
190 #define SCREEN_CTRL_ID_PREV_PLAYER 5
191 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
192 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
193 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
194 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
195 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
196 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
197 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
198 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
199 #define SCREEN_CTRL_ID_SCROLL_UP 14
200 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
201 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
202 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
204 #define NUM_SCREEN_GADGETS 18
206 #define NUM_SCREEN_MENUBUTTONS 14
207 #define NUM_SCREEN_SCROLLBUTTONS 2
208 #define NUM_SCREEN_SCROLLBARS 1
209 #define NUM_SCREEN_TEXTINPUT 1
211 #define SCREEN_MASK_MAIN (1 << 0)
212 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
213 #define SCREEN_MASK_INPUT (1 << 2)
214 #define SCREEN_MASK_TOUCH (1 << 3)
215 #define SCREEN_MASK_TOUCH2 (1 << 4)
217 // graphic position and size values for buttons and scrollbars
218 #define SC_MENUBUTTON_XSIZE TILEX
219 #define SC_MENUBUTTON_YSIZE TILEY
221 #define SC_SCROLLBUTTON_XSIZE TILEX
222 #define SC_SCROLLBUTTON_YSIZE TILEY
224 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
226 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
227 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
228 SC_SCROLLBUTTON_YSIZE)
230 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
231 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
233 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
234 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
235 SC_SCROLLBUTTON_YSIZE)
237 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
238 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
239 SC_SCROLL_VERTICAL_YSIZE)
241 #define SC_BORDER_SIZE 14
244 // forward declarations of internal functions
245 static void HandleScreenGadgets(struct GadgetInfo *);
246 static void HandleSetupScreen_Generic(int, int, int, int, int);
247 static void HandleSetupScreen_Input(int, int, int, int, int);
248 static void CustomizeKeyboard(int);
249 static void ConfigureJoystick(int);
250 static void ConfigureVirtualButtons(void);
251 static void execSetupGame(void);
252 static void execSetupEngines(void);
253 static void execSetupGraphics(void);
254 static void execSetupSound(void);
255 static void execSetupTouch(void);
256 static void execSetupArtwork(void);
257 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
259 static void DrawChoosePlayerName(void);
260 static void DrawChooseLevelSet(void);
261 static void DrawChooseLevelNr(void);
262 static void DrawInfoScreen(void);
263 static void DrawSetupScreen(void);
264 static void DrawTypeName(void);
266 static void DrawInfoScreen_NotAvailable(char *, char *);
267 static void DrawInfoScreen_HelpAnim(int, int, boolean);
268 static void DrawInfoScreen_HelpText(int, int, int, int);
269 static void HandleInfoScreen_Main(int, int, int, int, int);
270 static void HandleInfoScreen_TitleScreen(int);
271 static void HandleInfoScreen_Elements(int);
272 static void HandleInfoScreen_Music(int);
273 static void HandleInfoScreen_Credits(int);
274 static void HandleInfoScreen_Program(int);
275 static void HandleInfoScreen_Version(int);
277 static void ModifyGameSpeedIfNeeded(void);
278 static void DisableVsyncIfNeeded(void);
280 static void MapScreenMenuGadgets(int);
281 static void UnmapScreenMenuGadgets(int);
282 static void MapScreenGadgets(int);
283 static void MapScreenTreeGadgets(TreeInfo *);
285 static void UpdateScreenMenuGadgets(int, boolean);
287 static boolean OfferUploadTapes(void);
288 static void execOfferUploadTapes(void);
290 static char *getHallOfFameScoreText(int);
292 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
294 static int info_mode = INFO_MODE_MAIN;
295 static int setup_mode = SETUP_MODE_MAIN;
297 static TreeInfo *window_sizes = NULL;
298 static TreeInfo *window_size_current = NULL;
300 static TreeInfo *scaling_types = NULL;
301 static TreeInfo *scaling_type_current = NULL;
303 static TreeInfo *rendering_modes = NULL;
304 static TreeInfo *rendering_mode_current = NULL;
306 static TreeInfo *vsync_modes = NULL;
307 static TreeInfo *vsync_mode_current = NULL;
309 static TreeInfo *scroll_delays = NULL;
310 static TreeInfo *scroll_delay_current = NULL;
312 static TreeInfo *snapshot_modes = NULL;
313 static TreeInfo *snapshot_mode_current = NULL;
315 static TreeInfo *scores_types = NULL;
316 static TreeInfo *scores_type_current = NULL;
318 static TreeInfo *game_speeds_normal = NULL;
319 static TreeInfo *game_speeds_extended = NULL;
320 static TreeInfo *game_speeds = NULL;
321 static TreeInfo *game_speed_current = NULL;
323 static TreeInfo *volumes_simple = NULL;
324 static TreeInfo *volume_simple_current = NULL;
326 static TreeInfo *volumes_loops = NULL;
327 static TreeInfo *volume_loops_current = NULL;
329 static TreeInfo *volumes_music = NULL;
330 static TreeInfo *volume_music_current = NULL;
332 static TreeInfo *touch_controls = NULL;
333 static TreeInfo *touch_control_current = NULL;
335 static TreeInfo *move_distances = NULL;
336 static TreeInfo *move_distance_current = NULL;
338 static TreeInfo *drop_distances = NULL;
339 static TreeInfo *drop_distance_current = NULL;
341 static TreeInfo *transparencies = NULL;
342 static TreeInfo *transparency_current = NULL;
344 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
345 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
347 static TreeInfo *player_name = NULL;
348 static TreeInfo *player_name_current = NULL;
350 static TreeInfo *level_number = NULL;
351 static TreeInfo *level_number_current = NULL;
353 static TreeInfo *score_entries = NULL;
354 static TreeInfo *score_entry_current = NULL;
356 static struct ValueTextInfo window_sizes_list[] =
361 { 100, "100 % (Default)" },
374 static struct StringValueTextInfo scaling_types_list[] =
376 { SCALING_QUALITY_NEAREST, "Off" },
377 { SCALING_QUALITY_LINEAR, "Linear" },
378 { SCALING_QUALITY_BEST, "Anisotropic" },
383 static struct StringValueTextInfo rendering_modes_list[] =
385 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
386 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
388 // this mode may work under certain conditions, but does not work on Windows
389 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
391 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
396 static struct StringValueTextInfo vsync_modes_list[] =
398 { STR_VSYNC_MODE_OFF, "Off" },
399 { STR_VSYNC_MODE_NORMAL, "Normal" },
400 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
405 static struct StringValueTextInfo scores_types_list[] =
407 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
408 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
409 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
414 static struct ValueTextInfo game_speeds_list_normal[] =
425 static struct ValueTextInfo game_speeds_list_extended[] =
427 { 1000, "1 fps (Extremely Slow)" },
432 { 29, "35 fps (Original Supaplex)" },
434 { 20, "50 fps (=== Normal Speed ===)" },
435 { 16, "60 fps (60 Hz VSync Speed)" },
436 { 14, "70 fps (Maximum Supaplex)" },
440 { 1, "1000 fps (Extremely Fast)" },
445 static struct ValueTextInfo *game_speeds_list;
447 static struct ValueTextInfo scroll_delays_list[] =
449 { 0, "0 Tiles (No Scroll Delay)" },
452 { 3, "3 Tiles (Default)" },
457 { 8, "8 Tiles (Maximum Scroll Delay)"},
462 static struct StringValueTextInfo snapshot_modes_list[] =
464 { STR_SNAPSHOT_MODE_OFF, "Off" },
465 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
466 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
467 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
472 static struct ValueTextInfo volumes_list[] =
492 static struct StringValueTextInfo touch_controls_list[] =
494 { TOUCH_CONTROL_OFF, "Off" },
495 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
496 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
497 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
502 static struct ValueTextInfo distances_list[] =
517 static struct ValueTextInfo transparencies_list[] =
519 { 0, "0 % (Opaque)" },
529 { 100, "100 % (Invisible)" },
534 static struct ValueTextInfo grid_sizes_list[] =
570 static int align_xoffset = 0;
571 static int align_yoffset = 0;
573 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
574 (s) <= GAME_MODE_SETUP ? (s) : \
575 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
577 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
578 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
580 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
581 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
582 (i) <= INFO_MODE_LEVELSET ? (i) : \
585 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
586 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
587 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
588 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
589 SETUP_MODE_CHOOSE_ARTWORK : \
590 SETUP_MODE_CHOOSE_OTHER)
592 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
593 menu.draw_xoffset[GAME_MODE_INFO] : \
594 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
595 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
596 menu.draw_yoffset[GAME_MODE_INFO] : \
597 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
598 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
599 menu.extra_spacing[GAME_MODE_INFO] : \
600 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
602 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
603 menu.draw_xoffset[GAME_MODE_SETUP] : \
604 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
605 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
606 menu.draw_yoffset[GAME_MODE_SETUP] : \
607 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
608 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
609 menu.extra_spacing[GAME_MODE_SETUP] : \
610 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
612 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
613 DRAW_XOFFSET_INFO(info_mode) : \
614 (s) == GAME_MODE_SETUP ? \
615 DRAW_XOFFSET_SETUP(setup_mode) : \
616 menu.draw_xoffset[DRAW_MODE(s)])
617 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
618 DRAW_YOFFSET_INFO(info_mode) : \
619 (s) == GAME_MODE_SETUP ? \
620 DRAW_YOFFSET_SETUP(setup_mode) : \
621 menu.draw_yoffset[DRAW_MODE(s)])
622 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
623 EXTRA_SPACING_INFO(info_mode) : \
624 (s) == GAME_MODE_SETUP ? \
625 EXTRA_SPACING_SETUP(setup_mode) : \
626 menu.extra_spacing[DRAW_MODE(s)])
628 #define mSX (SX + DRAW_XOFFSET(game_status))
629 #define mSY (SY + DRAW_YOFFSET(game_status))
631 #define amSX (mSX + align_xoffset)
632 #define amSY (mSY + align_yoffset)
634 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
635 menu.list_size[game_status] : \
636 MAX_MENU_ENTRIES_ON_SCREEN)
638 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
639 NUM_MENU_ENTRIES_ON_SCREEN)
642 // title display and control definitions
644 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
645 2 * MAX_NUM_TITLE_MESSAGES)
647 #define NO_DIRECT_LEVEL_SELECT (-1)
650 static int num_title_screens = 0;
652 struct TitleControlInfo
661 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
663 // main menu display and control definitions
665 #define MAIN_CONTROL_NAME 0
666 #define MAIN_CONTROL_LEVELS 1
667 #define MAIN_CONTROL_SCORES 2
668 #define MAIN_CONTROL_EDITOR 3
669 #define MAIN_CONTROL_INFO 4
670 #define MAIN_CONTROL_GAME 5
671 #define MAIN_CONTROL_SETUP 6
672 #define MAIN_CONTROL_QUIT 7
673 #define MAIN_CONTROL_PREV_LEVEL 8
674 #define MAIN_CONTROL_NEXT_LEVEL 9
675 #define MAIN_CONTROL_FIRST_LEVEL 10
676 #define MAIN_CONTROL_LAST_LEVEL 11
677 #define MAIN_CONTROL_LEVEL_NUMBER 12
678 #define MAIN_CONTROL_LEVEL_INFO_1 13
679 #define MAIN_CONTROL_LEVEL_INFO_2 14
680 #define MAIN_CONTROL_LEVEL_NAME 15
681 #define MAIN_CONTROL_LEVEL_AUTHOR 16
682 #define MAIN_CONTROL_LEVEL_YEAR 17
683 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
684 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
685 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
686 #define MAIN_CONTROL_TITLE_1 21
687 #define MAIN_CONTROL_TITLE_2 22
688 #define MAIN_CONTROL_TITLE_3 23
690 static char str_main_text_name[10];
691 static char str_main_text_first_level[10];
692 static char str_main_text_last_level[10];
693 static char str_main_text_level_number[10];
695 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
697 static char *main_text_name = str_main_text_name;
698 static char *main_text_first_level = str_main_text_first_level;
699 static char *main_text_last_level = str_main_text_last_level;
700 static char *main_text_level_number = str_main_text_level_number;
701 static char *main_text_levels = "Levelset";
702 static char *main_text_scores = "Hall Of Fame";
703 static char *main_text_editor = "Level Creator";
704 static char *main_text_info = "Info Screen";
705 static char *main_text_game = "Start Game";
706 static char *main_text_setup = "Setup";
707 static char *main_text_quit = "Quit";
708 static char *main_text_level_name = level.name;
709 static char *main_text_level_author = level.author;
710 static char *main_text_level_year = NULL;
711 static char *main_text_level_imported_from = NULL;
712 static char *main_text_level_imported_by = NULL;
713 static char *main_text_level_tested_by = NULL;
714 static char *main_text_title_1 = NULL;
715 static char *main_text_title_2 = NULL;
716 static char *main_text_title_3 = NULL;
718 extern char debug_xsn_mode[];
720 struct MainControlInfo
724 struct MenuPosInfo *pos_button;
727 struct TextPosInfo *pos_text;
730 struct TextPosInfo *pos_input;
734 static struct MainControlInfo main_controls[] =
738 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
739 &menu.main.text.name, &main_text_name,
740 &menu.main.input.name, &setup.player_name,
744 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
745 &menu.main.text.levels, &main_text_levels,
750 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
751 &menu.main.text.scores, &main_text_scores,
756 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
757 &menu.main.text.editor, &main_text_editor,
762 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
763 &menu.main.text.info, &main_text_info,
768 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
769 &menu.main.text.game, &main_text_game,
774 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
775 &menu.main.text.setup, &main_text_setup,
780 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
781 &menu.main.text.quit, &main_text_quit,
785 MAIN_CONTROL_PREV_LEVEL,
791 MAIN_CONTROL_NEXT_LEVEL,
797 MAIN_CONTROL_FIRST_LEVEL,
799 &menu.main.text.first_level, &main_text_first_level,
803 MAIN_CONTROL_LAST_LEVEL,
805 &menu.main.text.last_level, &main_text_last_level,
809 MAIN_CONTROL_LEVEL_NUMBER,
811 &menu.main.text.level_number, &main_text_level_number,
815 MAIN_CONTROL_LEVEL_INFO_1,
817 &menu.main.text.level_info_1, NULL,
821 MAIN_CONTROL_LEVEL_INFO_2,
823 &menu.main.text.level_info_2, NULL,
827 MAIN_CONTROL_LEVEL_NAME,
829 &menu.main.text.level_name, &main_text_level_name,
833 MAIN_CONTROL_LEVEL_AUTHOR,
835 &menu.main.text.level_author, &main_text_level_author,
839 MAIN_CONTROL_LEVEL_YEAR,
841 &menu.main.text.level_year, &main_text_level_year,
845 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
847 &menu.main.text.level_imported_from, &main_text_level_imported_from,
851 MAIN_CONTROL_LEVEL_IMPORTED_BY,
853 &menu.main.text.level_imported_by, &main_text_level_imported_by,
857 MAIN_CONTROL_LEVEL_TESTED_BY,
859 &menu.main.text.level_tested_by, &main_text_level_tested_by,
863 MAIN_CONTROL_TITLE_1,
865 &menu.main.text.title_1, &main_text_title_1,
869 MAIN_CONTROL_TITLE_2,
871 &menu.main.text.title_2, &main_text_title_2,
875 MAIN_CONTROL_TITLE_3,
877 &menu.main.text.title_3, &main_text_title_3,
890 static int getTitleScreenGraphic(int nr, boolean initial)
892 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
895 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
897 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
901 static int getTitleScreenGameMode(boolean initial)
903 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
907 static int getTitleMessageGameMode(boolean initial)
909 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
912 static int getTitleAnimMode(struct TitleControlInfo *tci)
914 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
916 return base + tci->local_nr;
920 static int getTitleScreenBackground(boolean initial)
922 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
927 static int getTitleMessageBackground(int nr, boolean initial)
929 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
933 static int getTitleBackground(int nr, boolean initial, boolean is_image)
935 int base = (is_image ?
936 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
937 IMG_BACKGROUND_TITLESCREEN_1) :
938 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
939 IMG_BACKGROUND_TITLEMESSAGE_1));
940 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
941 IMG_BACKGROUND_TITLE);
942 int graphic_local = base + nr;
944 if (graphic_info[graphic_local].bitmap != NULL)
945 return graphic_local;
947 if (graphic_info[graphic_global].bitmap != NULL)
948 return graphic_global;
950 return IMG_UNDEFINED;
953 static int getTitleSound(struct TitleControlInfo *tci)
955 boolean is_image = tci->is_image;
956 int initial = tci->initial;
957 int nr = tci->local_nr;
958 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
959 int base = (is_image ?
960 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
961 SND_BACKGROUND_TITLESCREEN_1) :
962 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
963 SND_BACKGROUND_TITLEMESSAGE_1));
964 int sound_global = menu.sound[mode];
965 int sound_local = base + nr;
968 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
969 nr, initial, is_image,
970 sound_global, getSoundListEntry(sound_global)->filename,
971 sound_local, getSoundListEntry(sound_local)->filename);
974 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
977 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
980 return SND_UNDEFINED;
983 static int getTitleMusic(struct TitleControlInfo *tci)
985 boolean is_image = tci->is_image;
986 int initial = tci->initial;
987 int nr = tci->local_nr;
988 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
989 int base = (is_image ?
990 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
991 MUS_BACKGROUND_TITLESCREEN_1) :
992 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
993 MUS_BACKGROUND_TITLEMESSAGE_1));
994 int music_global = menu.music[mode];
995 int music_local = base + nr;
998 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
999 nr, initial, is_image,
1000 music_global, getMusicListEntry(music_global)->filename,
1001 music_local, getMusicListEntry(music_local)->filename);
1004 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1007 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1008 return music_global;
1010 return MUS_UNDEFINED;
1013 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1015 boolean is_image = tci->is_image;
1016 boolean initial = tci->initial;
1017 boolean first = tci->first;
1018 int nr = tci->local_nr;
1019 struct TitleMessageInfo tmi;
1020 struct TitleFadingInfo ti;
1022 tmi = (is_image ? (initial ? (first ?
1023 titlescreen_initial_first[nr] :
1024 titlescreen_initial[nr])
1026 titlescreen_first[nr] :
1028 : (initial ? (first ?
1029 titlemessage_initial_first[nr] :
1030 titlemessage_initial[nr])
1032 titlemessage_first[nr] :
1033 titlemessage[nr])));
1035 ti.fade_mode = tmi.fade_mode;
1036 ti.fade_delay = tmi.fade_delay;
1037 ti.post_delay = tmi.post_delay;
1038 ti.auto_delay = tmi.auto_delay;
1039 ti.auto_delay_unit = tmi.auto_delay_unit;
1044 static int compareTitleControlInfo(const void *object1, const void *object2)
1046 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1047 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1050 if (tci1->initial != tci2->initial)
1051 compare_result = (tci1->initial ? -1 : +1);
1052 else if (tci1->sort_priority != tci2->sort_priority)
1053 compare_result = tci1->sort_priority - tci2->sort_priority;
1054 else if (tci1->is_image != tci2->is_image)
1055 compare_result = (tci1->is_image ? -1 : +1);
1057 compare_result = tci1->local_nr - tci2->local_nr;
1059 return compare_result;
1062 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1064 int nr, int sort_priority)
1066 title_controls[num_title_screens].is_image = is_image;
1067 title_controls[num_title_screens].initial = initial;
1068 title_controls[num_title_screens].local_nr = nr;
1069 title_controls[num_title_screens].sort_priority = sort_priority;
1071 title_controls[num_title_screens].first = FALSE; // will be set later
1073 num_title_screens++;
1076 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1080 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1082 int graphic = getTitleScreenGraphic(i, initial);
1083 Bitmap *bitmap = graphic_info[graphic].bitmap;
1084 int sort_priority = graphic_info[graphic].sort_priority;
1087 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1090 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1092 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1093 char *filename = getLevelSetTitleMessageFilename(i, initial);
1094 int sort_priority = tmi->sort_priority;
1096 if (filename != NULL)
1097 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1101 static void InitializeTitleControls(boolean show_title_initial)
1103 num_title_screens = 0;
1105 // 1st step: initialize title screens for game start (only when starting)
1106 if (show_title_initial)
1107 InitializeTitleControls_CheckTitleInfo(TRUE);
1109 // 2nd step: initialize title screens for current level set
1110 InitializeTitleControls_CheckTitleInfo(FALSE);
1112 // sort title screens according to sort_priority and title number
1113 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1114 compareTitleControlInfo);
1116 // mark first title screen
1117 title_controls[0].first = TRUE;
1120 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1122 return (pos != NULL && pos->x != -1 && pos->y != -1);
1125 static boolean visibleTextPos(struct TextPosInfo *pos)
1127 return (pos != NULL && pos->x != -1 && pos->y != -1);
1130 static void InitializeMainControls(void)
1132 boolean local_team_mode = (!network.enabled && setup.team_mode);
1135 // set main control text values to dynamically determined values
1136 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1138 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1139 menu.main.text.first_level.size));
1140 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1141 menu.main.text.last_level.size));
1142 strcpy(main_text_level_number, int2str(level_nr,
1143 menu.main.text.level_number.size));
1145 main_text_level_year = leveldir_current->year;
1146 main_text_level_imported_from = leveldir_current->imported_from;
1147 main_text_level_imported_by = leveldir_current->imported_by;
1148 main_text_level_tested_by = leveldir_current->tested_by;
1150 main_text_title_1 = getConfigProgramTitleString();
1151 main_text_title_2 = getConfigProgramCopyrightString();
1152 main_text_title_3 = getConfigProgramCompanyString();
1154 // set main control screen positions to dynamically determined values
1155 for (i = 0; main_controls[i].nr != -1; i++)
1157 struct MainControlInfo *mci = &main_controls[i];
1159 struct MenuPosInfo *pos_button = mci->pos_button;
1160 struct TextPosInfo *pos_text = mci->pos_text;
1161 struct TextPosInfo *pos_input = mci->pos_input;
1162 char *text = (mci->text ? *mci->text : NULL);
1163 char *input = (mci->input ? *mci->input : NULL);
1164 int button_graphic = mci->button_graphic;
1165 int font_text = (pos_text ? pos_text->font : -1);
1166 int font_input = (pos_input ? pos_input->font : -1);
1168 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1169 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1170 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1171 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1172 int text_chars = (text != NULL ? strlen(text) : 0);
1173 int input_chars = (input != NULL ? strlen(input) : 0);
1176 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1178 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1179 int text_width = font_text_width * text_chars;
1180 int text_height = font_text_height;
1181 int input_width = font_input_width * input_chars;
1182 int input_height = font_input_height;
1184 if (nr == MAIN_CONTROL_NAME)
1186 menu.main.input.name.width = input_width;
1187 menu.main.input.name.height = input_height;
1190 if (pos_button != NULL) // (x/y may be -1/-1 here)
1192 pos_button->width = button_width;
1193 pos_button->height = button_height;
1196 if (pos_text != NULL) // (x/y may be -1/-1 here)
1198 // calculate text size -- needed for text alignment
1199 boolean calculate_text_size = (text != NULL);
1201 if (pos_text->width == -1 || calculate_text_size)
1202 pos_text->width = text_width;
1203 if (pos_text->height == -1 || calculate_text_size)
1204 pos_text->height = text_height;
1206 if (visibleMenuPos(pos_button))
1208 if (pos_text->x == -1)
1209 pos_text->x = pos_button->x + pos_button->width;
1210 if (pos_text->y == -1)
1212 pos_button->y + (pos_button->height - pos_text->height) / 2;
1216 if (pos_input != NULL) // (x/y may be -1/-1 here)
1218 if (visibleTextPos(pos_text))
1220 if (pos_input->x == -1)
1221 pos_input->x = pos_text->x + pos_text->width;
1222 if (pos_input->y == -1)
1223 pos_input->y = pos_text->y;
1226 if (pos_input->width == -1)
1227 pos_input->width = input_width;
1228 if (pos_input->height == -1)
1229 pos_input->height = input_height;
1234 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1235 int graphic, boolean pressed)
1237 struct GraphicInfo *g = &graphic_info[graphic];
1240 int xoffset = (pressed ? g->pressed_xoffset : 0);
1241 int yoffset = (pressed ? g->pressed_yoffset : 0);
1243 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1245 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1246 g->width, g->height, dst_x, dst_y);
1249 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1250 boolean active_input,
1251 boolean pressed_button)
1255 for (i = 0; main_controls[i].nr != -1; i++)
1257 struct MainControlInfo *mci = &main_controls[i];
1259 if (mci->nr == nr || nr == -1)
1261 struct MenuPosInfo *pos_button = mci->pos_button;
1262 struct TextPosInfo *pos_text = mci->pos_text;
1263 struct TextPosInfo *pos_input = mci->pos_input;
1264 char *text = (mci->text ? *mci->text : NULL);
1265 char *input = (mci->input ? *mci->input : NULL);
1266 int button_graphic = mci->button_graphic;
1267 int font_text = (pos_text ? pos_text->font : -1);
1268 int font_input = (pos_input ? pos_input->font : -1);
1272 button_graphic = BUTTON_ACTIVE(button_graphic);
1273 font_text = FONT_ACTIVE(font_text);
1278 font_input = FONT_ACTIVE(font_input);
1281 if (visibleMenuPos(pos_button))
1283 struct MenuPosInfo *pos = pos_button;
1284 int x = mSX + pos->x;
1285 int y = mSY + pos->y;
1287 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1288 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1291 if (visibleTextPos(pos_text) && text != NULL)
1293 struct TextPosInfo *pos = pos_text;
1294 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1295 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1298 // (check why/if this is needed)
1299 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1301 DrawText(x, y, text, font_text);
1304 if (visibleTextPos(pos_input) && input != NULL)
1306 struct TextPosInfo *pos = pos_input;
1307 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1308 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1311 // (check why/if this is needed)
1312 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1314 DrawText(x, y, input, font_input);
1320 static void DrawCursorAndText_Main(int nr, boolean active_text,
1321 boolean pressed_button)
1323 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1327 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1328 boolean pressed_button)
1330 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1334 static struct MainControlInfo *getMainControlInfo(int nr)
1338 for (i = 0; main_controls[i].nr != -1; i++)
1339 if (main_controls[i].nr == nr)
1340 return &main_controls[i];
1345 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1350 int rect_x = ALIGNED_TEXT_XPOS(rect);
1351 int rect_y = ALIGNED_TEXT_YPOS(rect);
1353 return (x >= rect_x && x < rect_x + rect->width &&
1354 y >= rect_y && y < rect_y + rect->height);
1357 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1362 int rect_x = ALIGNED_TEXT_XPOS(rect);
1363 int rect_y = ALIGNED_TEXT_YPOS(rect);
1366 Debug("screens:insideTextPosRect",
1367 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1368 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1369 (x >= rect_x && x < rect_x + rect->width &&
1370 y >= rect_y && y < rect_y + rect->height));
1373 return (x >= rect_x && x < rect_x + rect->width &&
1374 y >= rect_y && y < rect_y + rect->height);
1377 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1379 int rect_width = preview->xsize * preview->tile_size;
1380 int rect_height = preview->ysize * preview->tile_size;
1381 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1382 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1384 return (x >= rect_x && x < rect_x + rect_width &&
1385 y >= rect_y && y < rect_y + rect_height);
1388 static void AdjustScrollbar(int id, int items_max, int items_visible,
1391 struct GadgetInfo *gi = screen_gadget[id];
1393 if (item_position > items_max - items_visible)
1394 item_position = items_max - items_visible;
1396 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1397 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1398 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1401 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1403 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1407 static void clearMenuListArea(void)
1409 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1411 // correct scrollbar position if placed outside menu (playfield) area
1412 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1413 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1415 // clear menu list area, but not title or scrollbar
1416 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1417 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1420 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1422 static int cursor_array[MAX_LEV_FIELDY];
1423 int x = amSX + TILEX * xpos;
1424 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1429 cursor_array[ypos] = graphic;
1431 graphic = cursor_array[ypos];
1435 graphic = BUTTON_ACTIVE(graphic);
1437 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1438 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1441 static void initCursor(int ypos, int graphic)
1443 drawCursorExt(0, ypos, FALSE, graphic);
1446 static void drawCursor(int ypos, boolean active)
1448 drawCursorExt(0, ypos, active, -1);
1451 static void drawCursorXY(int xpos, int ypos, int graphic)
1453 drawCursorExt(xpos, ypos, FALSE, graphic);
1456 static void drawChooseTreeCursor(int ypos, boolean active)
1458 drawCursorExt(0, ypos, active, -1);
1461 static int getChooseTreeEditFont(boolean active)
1463 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1466 static int getChooseTreeEditXPos(int pos)
1468 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1469 int xoffset = (has_scrollbar ? -1 : 0);
1470 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1471 int sx = amSX + xpos * TILEX;
1472 int font_nr = getChooseTreeEditFont(FALSE);
1473 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1475 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1478 static int getChooseTreeEditYPos(int ypos_raw)
1480 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1481 int sy = amSY + ypos * TILEY;
1486 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1488 int sx = getChooseTreeEditXPos(POS_LEFT);
1489 int sy = getChooseTreeEditYPos(ypos_raw);
1490 int font_nr = getChooseTreeEditFont(active);
1492 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1495 static void DrawHeadline(void)
1497 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1498 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1501 static void DrawTitleScreenImage(int nr, boolean initial)
1503 int graphic = getTitleScreenGraphic(nr, initial);
1504 Bitmap *bitmap = graphic_info[graphic].bitmap;
1505 int width = graphic_info[graphic].width;
1506 int height = graphic_info[graphic].height;
1507 int src_x = graphic_info[graphic].src_x;
1508 int src_y = graphic_info[graphic].src_y;
1514 if (width > WIN_XSIZE)
1516 // image width too large for window => center image horizontally
1517 src_x = (width - WIN_XSIZE) / 2;
1521 if (height > WIN_YSIZE)
1523 // image height too large for window => center image vertically
1524 src_y = (height - WIN_YSIZE) / 2;
1528 // always display title screens centered
1529 dst_x = (WIN_XSIZE - width) / 2;
1530 dst_y = (WIN_YSIZE - height) / 2;
1532 SetDrawBackgroundMask(REDRAW_ALL);
1533 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1535 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1537 if (DrawingOnBackground(dst_x, dst_y))
1538 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1540 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1542 redraw_mask = REDRAW_ALL;
1545 static void DrawTitleScreenMessage(int nr, boolean initial)
1547 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1548 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1550 if (filename == NULL)
1553 // force TITLE font on title message screen
1554 SetFontStatus(getTitleMessageGameMode(initial));
1556 // if chars *and* width set to "-1", automatically determine width
1557 if (tmi->chars == -1 && tmi->width == -1)
1558 tmi->width = viewport.window[game_status].width;
1560 // if lines *and* height set to "-1", automatically determine height
1561 if (tmi->lines == -1 && tmi->height == -1)
1562 tmi->height = viewport.window[game_status].height;
1564 // if chars set to "-1", automatically determine by text and font width
1565 if (tmi->chars == -1)
1566 tmi->chars = tmi->width / getFontWidth(tmi->font);
1568 tmi->width = tmi->chars * getFontWidth(tmi->font);
1570 // if lines set to "-1", automatically determine by text and font height
1571 if (tmi->lines == -1)
1572 tmi->lines = tmi->height / getFontHeight(tmi->font);
1574 tmi->height = tmi->lines * getFontHeight(tmi->font);
1576 // if x set to "-1", automatically determine by width and alignment
1578 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1580 // if y set to "-1", automatically determine by height and alignment
1582 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1584 SetDrawBackgroundMask(REDRAW_ALL);
1585 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1587 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1589 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1590 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1591 tmi->autowrap, tmi->centered, tmi->parse_comments);
1596 static void DrawTitleScreen(void)
1598 KeyboardAutoRepeatOff();
1600 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1603 static boolean CheckTitleScreen(boolean levelset_has_changed)
1605 static boolean show_title_initial = TRUE;
1606 boolean show_titlescreen = FALSE;
1608 // needed to be able to skip title screen, if no image or message defined
1609 InitializeTitleControls(show_title_initial);
1611 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1612 show_titlescreen = TRUE;
1614 // show initial title images and messages only once at program start
1615 show_title_initial = FALSE;
1617 return (show_titlescreen && num_title_screens > 0);
1620 void DrawMainMenu(void)
1622 static LevelDirTree *leveldir_last_valid = NULL;
1623 boolean levelset_has_changed = FALSE;
1624 int fade_mask = REDRAW_FIELD;
1626 LimitScreenUpdates(FALSE);
1628 FadeSetLeaveScreen();
1630 // do not fade out here -- function may continue and fade on editor screen
1633 FadeMenuSoundsAndMusic();
1635 ExpireSoundLoops(FALSE);
1637 KeyboardAutoRepeatOn();
1639 audio.sound_deactivated = FALSE;
1643 // needed if last screen was the playing screen, invoked from level editor
1644 if (level_editor_test_game)
1646 CloseDoor(DOOR_CLOSE_ALL);
1648 SetGameStatus(GAME_MODE_EDITOR);
1655 // leveldir_current may be invalid (level group, parent link, node copy)
1656 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1658 if (leveldir_current != leveldir_last_valid)
1660 UpdateLastPlayedLevels_TreeInfo();
1662 levelset_has_changed = TRUE;
1665 // store valid level series information
1666 leveldir_last_valid = leveldir_current;
1668 init_last = init; // switch to new busy animation
1670 // needed if last screen (level choice) changed graphics, sounds or music
1671 ReloadCustomArtwork(0);
1673 if (CheckTitleScreen(levelset_has_changed))
1675 SetGameStatus(GAME_MODE_TITLE);
1682 if (redraw_mask & REDRAW_ALL)
1683 fade_mask = REDRAW_ALL;
1686 fade_mask = REDRAW_ALL;
1690 // needed if different viewport properties defined for menues
1691 ChangeViewportPropertiesIfNeeded();
1693 SetDrawtoField(DRAW_TO_BACKBUFFER);
1695 // level_nr may have been set to value over handicap with level editor
1696 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1697 level_nr = leveldir_current->handicap_level;
1699 LoadLevel(level_nr);
1700 LoadScore(level_nr);
1702 SaveLevelSetup_SeriesInfo();
1704 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1705 SetDrawDeactivationMask(REDRAW_NONE);
1706 SetDrawBackgroundMask(REDRAW_FIELD);
1708 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1711 if (fade_mask == REDRAW_ALL)
1712 RedrawGlobalBorder();
1717 InitializeMainControls();
1719 DrawCursorAndText_Main(-1, FALSE, FALSE);
1720 DrawPreviewLevelInitial();
1721 DrawNetworkPlayers();
1723 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1726 if (TAPE_IS_EMPTY(tape))
1728 DrawCompleteVideoDisplay();
1730 PlayMenuSoundsAndMusic();
1732 // create gadgets for main menu screen
1733 FreeScreenGadgets();
1734 CreateScreenGadgets();
1736 // may be required if audio buttons shown on tape and changed in setup menu
1738 CreateGameButtons();
1740 // map gadgets for main menu screen
1742 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1743 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1745 // copy actual game door content to door double buffer for OpenDoor()
1746 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1747 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1749 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1751 DrawMaskedBorder(fade_mask);
1756 // update screen area with special editor door
1757 redraw_mask |= REDRAW_ALL;
1760 SetMouseCursor(CURSOR_DEFAULT);
1762 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1764 SyncEmscriptenFilesystem();
1766 // needed once after program start or after user change
1767 CheckApiServerTasks();
1770 static void gotoTopLevelDir(void)
1772 // move upwards until inside (but not above) top level directory
1773 while (leveldir_current->node_parent &&
1774 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1776 // write a "path" into level tree for easy navigation to last level
1777 if (leveldir_current->node_parent->node_group->cl_first == -1)
1779 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1780 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1781 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1782 int cl_first, cl_cursor;
1784 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1785 cl_cursor = leveldir_pos - cl_first;
1787 leveldir_current->node_parent->node_group->cl_first = cl_first;
1788 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1791 leveldir_current = leveldir_current->node_parent;
1795 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1797 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1799 return (use_frame_counter ? video.frame_counter : Counter());
1802 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1803 struct TitleFadingInfo *fi)
1805 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1808 static void ResetTitleAutoDelay(unsigned int *counter_var,
1809 struct TitleFadingInfo *fi)
1811 *counter_var = getAutoDelayCounter(fi);
1814 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1816 static unsigned int title_delay = 0;
1817 static int title_screen_nr = 0;
1818 static int last_sound = -1, last_music = -1;
1819 boolean return_to_main_menu = FALSE;
1820 struct TitleControlInfo *tci;
1823 if (button == MB_MENU_INITIALIZE)
1826 title_screen_nr = 0;
1827 tci = &title_controls[title_screen_nr];
1829 SetAnimStatus(getTitleAnimMode(tci));
1831 last_sound = SND_UNDEFINED;
1832 last_music = MUS_UNDEFINED;
1834 if (num_title_screens != 0)
1836 FadeSetEnterScreen();
1838 // use individual title fading instead of global "enter screen" fading
1839 fading = getTitleFading(tci);
1842 if (game_status_last_screen == GAME_MODE_INFO)
1844 if (num_title_screens == 0)
1846 // switch game mode from title screen mode back to info screen mode
1847 SetGameStatus(GAME_MODE_INFO);
1849 // store that last screen was info screen, not main menu screen
1850 game_status_last_screen = GAME_MODE_INFO;
1852 DrawInfoScreen_NotAvailable("Title screen information:",
1853 "No title screen for this level set.");
1858 FadeMenuSoundsAndMusic();
1860 FadeOut(REDRAW_ALL);
1862 // title screens may have different window size
1863 ChangeViewportPropertiesIfNeeded();
1865 // only required to update logic for redrawing global border
1869 DrawTitleScreenImage(tci->local_nr, tci->initial);
1871 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1873 sound = getTitleSound(tci);
1874 music = getTitleMusic(tci);
1876 if (sound != last_sound)
1877 PlayMenuSoundExt(sound);
1878 if (music != last_music)
1879 PlayMenuMusicExt(music);
1884 SetMouseCursor(CURSOR_NONE);
1888 ResetTitleAutoDelay(&title_delay, &fading);
1893 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1894 button = MB_MENU_CHOICE;
1896 if (button == MB_MENU_LEAVE)
1898 return_to_main_menu = TRUE;
1900 else if (button == MB_MENU_CHOICE)
1902 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1904 SetGameStatus(GAME_MODE_INFO);
1906 info_mode = INFO_MODE_MAIN;
1915 if (title_screen_nr < num_title_screens)
1917 tci = &title_controls[title_screen_nr];
1919 SetAnimStatus(getTitleAnimMode(tci));
1921 sound = getTitleSound(tci);
1922 music = getTitleMusic(tci);
1924 if (last_sound != SND_UNDEFINED && sound != last_sound)
1925 FadeSound(last_sound);
1926 if (last_music != MUS_UNDEFINED && music != last_music)
1929 fading = getTitleFading(tci);
1931 FadeOut(REDRAW_ALL);
1934 DrawTitleScreenImage(tci->local_nr, tci->initial);
1936 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1938 sound = getTitleSound(tci);
1939 music = getTitleMusic(tci);
1941 if (sound != last_sound)
1942 PlayMenuSoundExt(sound);
1943 if (music != last_music)
1944 PlayMenuMusicExt(music);
1951 ResetTitleAutoDelay(&title_delay, &fading);
1955 FadeMenuSoundsAndMusic();
1957 return_to_main_menu = TRUE;
1961 if (return_to_main_menu)
1963 SetMouseCursor(CURSOR_DEFAULT);
1965 // force full menu screen redraw after displaying title screens
1966 redraw_mask = REDRAW_ALL;
1968 if (game_status_last_screen == GAME_MODE_INFO)
1970 SetGameStatus(GAME_MODE_INFO);
1972 info_mode = INFO_MODE_MAIN;
1976 else // default: return to main menu
1978 SetGameStatus(GAME_MODE_MAIN);
1985 static void HandleMainMenu_ToggleTeamMode(void)
1987 setup.team_mode = !setup.team_mode;
1989 InitializeMainControls();
1990 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
1992 DrawPreviewPlayers();
1995 static void HandleMainMenu_SelectLevel(int step, int direction,
1996 int selected_level_nr)
1998 int old_level_nr = level_nr;
2001 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2002 new_level_nr = selected_level_nr;
2004 new_level_nr = old_level_nr + step * direction;
2006 if (new_level_nr < leveldir_current->first_level)
2007 new_level_nr = leveldir_current->first_level;
2008 if (new_level_nr > leveldir_current->last_level)
2009 new_level_nr = leveldir_current->last_level;
2011 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2013 // skipping levels is only allowed when trying to skip single level
2014 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2015 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2017 leveldir_current->handicap_level++;
2018 SaveLevelSetup_SeriesInfo();
2021 new_level_nr = leveldir_current->handicap_level;
2024 if (new_level_nr != old_level_nr)
2026 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2028 PlaySound(SND_MENU_ITEM_SELECTING);
2030 level_nr = new_level_nr;
2032 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2033 int2str(level_nr, menu.main.text.level_number.size),
2034 mci->pos_text->font);
2036 LoadLevel(level_nr);
2037 DrawPreviewLevelInitial();
2041 DrawCompleteVideoDisplay();
2043 SaveLevelSetup_SeriesInfo();
2045 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2047 // force redraw of playfield area (may be reset at this point)
2048 redraw_mask |= REDRAW_FIELD;
2052 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2054 static int choice = MAIN_CONTROL_GAME;
2055 static boolean button_pressed_last = FALSE;
2056 boolean button_pressed = FALSE;
2058 int i = 0; // needed to prevent compiler warning due to bad code below
2060 if (button == MB_MENU_INITIALIZE)
2062 DrawCursorAndText_Main(choice, TRUE, FALSE);
2067 if (mx || my) // mouse input
2071 for (i = 0; main_controls[i].nr != -1; i++)
2073 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2074 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2075 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2077 pos = main_controls[i].nr;
2083 // check if level preview was clicked
2084 if (insidePreviewRect(&preview, mx - SX, my - SY))
2085 pos = MAIN_CONTROL_GAME;
2087 // handle pressed/unpressed state for active/inactive menu buttons
2088 // (if pos != -1, "i" contains index position corresponding to "pos")
2090 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2091 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2092 button_pressed = TRUE;
2094 if (button_pressed != button_pressed_last)
2096 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2099 PlaySound(SND_MENU_BUTTON_PRESSING);
2101 PlaySound(SND_MENU_BUTTON_RELEASING);
2104 else if (dx || dy) // keyboard input
2106 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2107 choice == MAIN_CONTROL_SETUP))
2108 button = MB_MENU_CHOICE;
2113 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2115 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2117 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2119 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2121 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2123 CloseDoor(DOOR_CLOSE_2);
2125 SetGameStatus(GAME_MODE_LEVELNR);
2127 DrawChooseLevelNr();
2129 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2135 PlaySound(SND_MENU_ITEM_ACTIVATING);
2137 DrawCursorAndText_Main(choice, FALSE, FALSE);
2138 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2144 if (choice == MAIN_CONTROL_NAME)
2146 // special case: cursor left or right pressed -- toggle team mode
2147 HandleMainMenu_ToggleTeamMode();
2149 else if (choice != MAIN_CONTROL_INFO &&
2150 choice != MAIN_CONTROL_SETUP)
2152 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2158 PlaySound(SND_MENU_ITEM_SELECTING);
2160 if (pos == MAIN_CONTROL_NAME)
2163 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2165 // special case: menu text "name/team" clicked -- toggle team mode
2166 HandleMainMenu_ToggleTeamMode();
2170 if (setup.multiple_users)
2172 CloseDoor(DOOR_CLOSE_2);
2174 SetGameStatus(GAME_MODE_NAMES);
2176 DrawChoosePlayerName();
2180 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2186 else if (pos == MAIN_CONTROL_LEVELS)
2190 CloseDoor(DOOR_CLOSE_2);
2192 SetGameStatus(GAME_MODE_LEVELS);
2194 SaveLevelSetup_LastSeries();
2195 SaveLevelSetup_SeriesInfo();
2197 // restore level set if chosen from "last played level set" menu
2198 RestoreLastPlayedLevels(&leveldir_current);
2200 if (setup.internal.choose_from_top_leveldir)
2203 DrawChooseLevelSet();
2206 else if (pos == MAIN_CONTROL_SCORES)
2208 CloseDoor(DOOR_CLOSE_2);
2210 SetGameStatus(GAME_MODE_SCORES);
2212 DrawHallOfFame(level_nr);
2214 else if (pos == MAIN_CONTROL_EDITOR)
2216 if (leveldir_current->readonly &&
2217 setup.editor.show_read_only_warning)
2218 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2220 CloseDoor(DOOR_CLOSE_ALL);
2222 SetGameStatus(GAME_MODE_EDITOR);
2224 FadeSetEnterScreen();
2228 else if (pos == MAIN_CONTROL_INFO)
2230 CloseDoor(DOOR_CLOSE_2);
2232 SetGameStatus(GAME_MODE_INFO);
2234 info_mode = INFO_MODE_MAIN;
2238 else if (pos == MAIN_CONTROL_GAME)
2240 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2242 else if (pos == MAIN_CONTROL_SETUP)
2244 CloseDoor(DOOR_CLOSE_2);
2246 SetGameStatus(GAME_MODE_SETUP);
2248 setup_mode = SETUP_MODE_MAIN;
2252 else if (pos == MAIN_CONTROL_QUIT)
2254 SaveLevelSetup_LastSeries();
2255 SaveLevelSetup_SeriesInfo();
2257 #if defined(PLATFORM_EMSCRIPTEN)
2258 Request("Close the browser window to quit!", REQ_CONFIRM);
2260 if (!setup.ask_on_quit_program ||
2261 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2262 SetGameStatus(GAME_MODE_QUIT);
2268 button_pressed_last = button_pressed;
2272 // ============================================================================
2273 // info screen functions
2274 // ============================================================================
2276 static struct TokenInfo *info_info;
2277 static int num_info_info; // number of info entries shown on screen
2278 static int max_info_info; // total number of info entries in list
2280 static void execInfoTitleScreen(void)
2282 info_mode = INFO_MODE_TITLE;
2287 static void execInfoElements(void)
2289 info_mode = INFO_MODE_ELEMENTS;
2294 static void execInfoMusic(void)
2296 info_mode = INFO_MODE_MUSIC;
2301 static void execInfoCredits(void)
2303 info_mode = INFO_MODE_CREDITS;
2308 static void execInfoProgram(void)
2310 info_mode = INFO_MODE_PROGRAM;
2315 static void execInfoVersion(void)
2317 info_mode = INFO_MODE_VERSION;
2322 static void execInfoLevelSet(void)
2324 info_mode = INFO_MODE_LEVELSET;
2329 static void execExitInfo(void)
2331 SetGameStatus(GAME_MODE_MAIN);
2336 static struct TokenInfo info_info_main[] =
2338 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2339 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2340 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2341 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2342 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2343 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2344 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2345 { TYPE_EMPTY, NULL, "" },
2346 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2351 static int getMenuTextFont(int type)
2353 if (type & (TYPE_SWITCH |
2367 static struct TokenInfo *setup_info;
2368 static struct TokenInfo setup_info_input[];
2370 static struct TokenInfo *menu_info;
2372 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2373 int screen_pos, int menu_info_pos_raw,
2376 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2377 struct TokenInfo *ti = &token_info[pos];
2378 int xpos = MENU_SCREEN_START_XPOS;
2379 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2380 int font_nr = getMenuTextFont(ti->type);
2382 if (setup_mode == SETUP_MODE_INPUT)
2383 font_nr = FONT_MENU_1;
2386 font_nr = FONT_ACTIVE(font_nr);
2388 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2390 if (ti->type & ~TYPE_SKIP_ENTRY)
2391 drawCursor(screen_pos, active);
2394 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2397 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2400 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2403 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2406 static char *window_size_text;
2407 static char *scaling_type_text;
2408 static char *network_server_text;
2410 static void drawSetupValue(int, int);
2412 static void drawMenuInfoList(int first_entry, int num_page_entries,
2413 int max_page_entries)
2417 if (first_entry + num_page_entries > max_page_entries)
2420 clearMenuListArea();
2422 for (i = 0; i < num_page_entries; i++)
2424 int menu_info_pos = first_entry + i;
2425 struct TokenInfo *si = &menu_info[menu_info_pos];
2426 void *value_ptr = si->value;
2428 // set some entries to "unchangeable" according to other variables
2429 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2430 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2431 (value_ptr == &setup.sound_music && !audio.music_available) ||
2432 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2433 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2434 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2435 si->type |= TYPE_GHOSTED;
2437 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2438 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2439 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2440 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2441 else if (si->type & ~TYPE_SKIP_ENTRY)
2442 initCursor(i, IMG_MENU_BUTTON);
2444 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2446 if (si->type & TYPE_STRING)
2450 if (value_ptr == &network_server_text)
2451 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2453 if (gadget_id != -1)
2455 struct GadgetInfo *gi = screen_gadget[gadget_id];
2456 int xpos = MENU_SCREEN_START_XPOS;
2457 int ypos = MENU_SCREEN_START_YPOS + i;
2458 int x = mSX + xpos * 32;
2459 int y = mSY + ypos * 32;
2461 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2465 if (si->type & TYPE_VALUE &&
2466 menu_info == setup_info)
2467 drawSetupValue(i, menu_info_pos);
2471 static void DrawInfoScreen_Main(void)
2473 int fade_mask = REDRAW_FIELD;
2476 if (redraw_mask & REDRAW_ALL)
2477 fade_mask = REDRAW_ALL;
2480 fade_mask = REDRAW_ALL;
2483 FadeMenuSoundsAndMusic();
2485 FreeScreenGadgets();
2486 CreateScreenGadgets();
2488 // (needed after displaying title screens which disable auto repeat)
2489 KeyboardAutoRepeatOn();
2491 FadeSetLeaveScreen();
2495 // needed if different viewport properties defined for info screen
2496 ChangeViewportPropertiesIfNeeded();
2498 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2502 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2504 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2506 info_info = info_info_main;
2508 // determine maximal number of info entries that can be displayed on screen
2510 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2513 // determine maximal number of info entries available for menu of info screen
2515 for (i = 0; info_info[i].type != 0; i++)
2518 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2520 MapScreenGadgets(max_info_info);
2522 PlayMenuSoundsAndMusic();
2524 DrawMaskedBorder(fade_mask);
2529 static void changeSetupValue(int, int, int);
2531 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2532 int mode, int num_page_entries,
2533 int max_page_entries)
2535 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2536 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2537 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2538 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2539 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2540 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2541 int *num_page_entries_last = num_page_entries_all_last[game_status];
2542 int *choice_store = choice_stores[game_status];
2543 int *first_entry_store = first_entry_stores[game_status];
2544 int choice = choice_store[mode]; // starts with 0
2545 int first_entry = first_entry_store[mode]; // starts with 0
2547 int y = choice - first_entry;
2549 boolean position_set_by_scrollbar = (dx == 999);
2550 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2553 if (button == MB_MENU_INITIALIZE)
2555 // check if number of menu page entries has changed (may happen by change
2556 // of custom artwork definition value for 'list_size' for this menu screen)
2557 // (in this case, the last menu position most probably has to be corrected)
2558 if (num_page_entries != num_page_entries_last[mode])
2560 choice_store[mode] = first_entry_store[mode] = 0;
2562 choice = first_entry = 0;
2565 num_page_entries_last[mode] = num_page_entries;
2568 // advance to first valid menu entry
2569 while (choice < num_page_entries &&
2570 menu_info[choice].type & TYPE_SKIP_ENTRY)
2573 if (position_set_by_scrollbar)
2574 first_entry = first_entry_store[mode] = dy;
2576 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2577 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2579 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2581 if (choice < first_entry)
2583 choice = first_entry;
2585 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2588 else if (choice > first_entry + num_page_entries - 1)
2590 choice = first_entry + num_page_entries - 1;
2592 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2596 choice_store[mode] = choice;
2598 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2602 else if (button == MB_MENU_LEAVE)
2604 PlaySound(SND_MENU_ITEM_SELECTING);
2606 for (i = 0; i < max_page_entries; i++)
2608 if (menu_info[i].type & TYPE_LEAVE_MENU)
2610 void (*menu_callback_function)(void) = menu_info[i].value;
2614 menu_callback_function();
2616 break; // absolutely needed because function changes 'menu_info'!
2623 if (mx || my) // mouse input
2625 x = (mx - mSX) / 32;
2626 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2628 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2630 // move cursor instead of scrolling when already at start/end of list
2631 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2633 else if (dy == +1 * SCROLL_LINE &&
2634 first_entry + num_page_entries == max_page_entries)
2637 // handle scrolling screen one line or page
2639 y + dy > num_page_entries - 1)
2641 boolean redraw = FALSE;
2643 if (ABS(dy) == SCROLL_PAGE)
2644 step = num_page_entries - 1;
2646 if (dy < 0 && first_entry > 0)
2648 // scroll page/line up
2650 first_entry -= step;
2651 if (first_entry < 0)
2656 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2658 // scroll page/line down
2660 first_entry += step;
2661 if (first_entry + num_page_entries > max_page_entries)
2662 first_entry = MAX(0, max_page_entries - num_page_entries);
2669 choice += first_entry - first_entry_store[mode];
2671 if (choice < first_entry)
2673 choice = first_entry;
2675 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2678 else if (choice > first_entry + num_page_entries - 1)
2680 choice = first_entry + num_page_entries - 1;
2682 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2685 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2689 if (choice < first_entry ||
2690 choice > first_entry + num_page_entries - 1)
2691 first_entry += SIGN(dy);
2694 first_entry_store[mode] = first_entry;
2695 choice_store[mode] = choice;
2697 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2699 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2701 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2702 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2710 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2712 if (menu_info[choice].type & menu_navigation_type ||
2713 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2714 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2715 menu_info[choice].type & TYPE_PLAYER)
2716 button = MB_MENU_CHOICE;
2721 // jump to next non-empty menu entry (up or down)
2722 while (first_entry + y > 0 &&
2723 first_entry + y < max_page_entries - 1 &&
2724 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2727 if (!IN_VIS_MENU(x, y))
2729 choice += y - y_old;
2731 if (choice < first_entry)
2732 first_entry = choice;
2733 else if (choice > first_entry + num_page_entries - 1)
2734 first_entry = choice - num_page_entries + 1;
2736 if (first_entry >= 0 &&
2737 first_entry + num_page_entries <= max_page_entries)
2739 first_entry_store[mode] = first_entry;
2741 if (choice < first_entry)
2742 choice = first_entry;
2743 else if (choice > first_entry + num_page_entries - 1)
2744 choice = first_entry + num_page_entries - 1;
2746 choice_store[mode] = choice;
2748 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2750 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2752 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2753 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2760 if (!anyScrollbarGadgetActive() &&
2761 IN_VIS_MENU(x, y) &&
2762 mx < mx_right_border &&
2763 y >= 0 && y < num_page_entries)
2767 if (first_entry + y != choice &&
2768 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2770 PlaySound(SND_MENU_ITEM_ACTIVATING);
2772 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2773 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2775 choice = choice_store[mode] = first_entry + y;
2779 PlaySound(SND_MENU_ITEM_SELECTING);
2781 for (i = 0; menu_info[i].type != 0; i++)
2783 if (menu_info[i].type & TYPE_LEAVE_MENU)
2785 void (*menu_callback_function)(void) = menu_info[i].value;
2789 menu_callback_function();
2791 // absolutely needed because function changes 'menu_info'!
2799 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2801 PlaySound(SND_MENU_ITEM_SELECTING);
2803 // when selecting key headline, execute function for key value change
2804 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2805 menu_info[first_entry + y + 1].type & TYPE_KEY)
2808 // when selecting string value, execute function for list selection
2809 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2810 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2813 // when selecting string value, execute function for text input gadget
2814 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2815 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2818 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2820 void (*menu_callback_function)(void) =
2821 menu_info[first_entry + y].value;
2823 FadeSetFromType(menu_info[first_entry + y].type);
2825 menu_callback_function();
2827 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2829 void (*gadget_callback_function)(void) =
2830 menu_info[first_entry + y].value;
2832 gadget_callback_function();
2834 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2835 menu_info == setup_info)
2837 changeSetupValue(y, first_entry + y, dx);
2843 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2845 menu_info = info_info;
2847 HandleMenuScreen(mx, my, dx, dy, button,
2848 info_mode, num_info_info, max_info_info);
2851 static int getMenuFontSpacing(int spacing_height, int font_nr)
2853 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2855 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2859 static int getMenuTextSpacing(int spacing_height, int font_nr)
2861 return (getMenuFontSpacing(spacing_height, font_nr) +
2862 EXTRA_SPACING(game_status));
2865 static int getMenuTextStep(int spacing_height, int font_nr)
2867 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2870 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2872 int font_title = MENU_INFO_FONT_TITLE;
2873 int font_error = FONT_TEXT_2;
2874 int font_foot = MENU_INFO_FONT_FOOT;
2875 int spacing_title = menu.headline1_spacing_info[info_mode];
2876 int ystep_title = getMenuTextStep(spacing_title, font_title);
2877 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2878 int ystart2 = ystart1 + ystep_title;
2879 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2881 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2883 FadeOut(REDRAW_FIELD);
2888 DrawTextSCentered(ystart1, font_title, text_title);
2889 DrawTextSCentered(ystart2, font_error, text_error);
2891 DrawTextSCentered(ybottom, font_foot,
2892 "Press any key or button for info menu");
2894 FadeIn(REDRAW_FIELD);
2897 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2899 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2900 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2901 int font_title = MENU_INFO_FONT_TITLE;
2902 int font_foot = MENU_INFO_FONT_FOOT;
2903 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2904 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2905 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2906 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2907 int ystep = MENU_SCREEN_INFO_YSTEP;
2908 int element, action, direction;
2916 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2917 infoscreen_step[i] = infoscreen_frame[i] = 0;
2922 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2924 DrawTextSCentered(ybottom, font_foot,
2925 "Press any key or button for next page");
2931 while (helpanim_info[j].element != HELPANIM_LIST_END)
2933 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2938 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2947 j += infoscreen_step[i - start];
2949 element = helpanim_info[j].element;
2950 action = helpanim_info[j].action;
2951 direction = helpanim_info[j].direction;
2954 element = EL_UNKNOWN;
2956 if (action != -1 && direction != -1)
2957 graphic = el_act_dir2img(element, action, direction);
2958 else if (action != -1)
2959 graphic = el_act2img(element, action);
2960 else if (direction != -1)
2961 graphic = el_dir2img(element, direction);
2963 graphic = el2img(element);
2965 delay = helpanim_info[j++].delay;
2970 if (infoscreen_frame[i - start] == 0)
2973 infoscreen_frame[i - start] = delay - 1;
2977 sync_frame = delay - infoscreen_frame[i - start];
2978 infoscreen_frame[i - start]--;
2981 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2983 if (!infoscreen_frame[i - start])
2984 infoscreen_step[i - start] = 0;
2988 if (!infoscreen_frame[i - start])
2989 infoscreen_step[i - start]++;
2990 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2996 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2998 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2999 graphic, sync_frame, USE_MASKING);
3002 DrawInfoScreen_HelpText(element, action, direction, i - start);
3007 redraw_mask |= REDRAW_FIELD;
3012 static char *getHelpText(int element, int action, int direction)
3014 char token[MAX_LINE_LEN];
3016 strcpy(token, element_info[element].token_name);
3019 strcat(token, element_action_info[action].suffix);
3021 if (direction != -1)
3022 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3024 return getHashEntry(helptext_info, token);
3027 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3029 int font_nr = FONT_INFO_ELEMENTS;
3030 int font_width = getFontWidth(font_nr);
3031 int font_height = getFontHeight(font_nr);
3032 int yoffset = (TILEX - 2 * font_height) / 2;
3033 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3034 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3035 int ystep = TILEY + 4;
3036 int pad_left = xstart - SX;
3037 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3038 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3039 int max_lines_per_text = 2;
3042 if (action != -1 && direction != -1) // element.action.direction
3043 text = getHelpText(element, action, direction);
3045 if (text == NULL && action != -1) // element.action
3046 text = getHelpText(element, action, -1);
3048 if (text == NULL && direction != -1) // element.direction
3049 text = getHelpText(element, -1, direction);
3051 if (text == NULL) // base element
3052 text = getHelpText(element, -1, -1);
3054 if (text == NULL) // not found
3055 text = "No description available";
3057 if (strlen(text) <= max_chars_per_line) // only one line of text
3058 ystart += getFontHeight(font_nr) / 2;
3060 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3061 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3062 TRUE, FALSE, FALSE);
3065 static void DrawInfoScreen_TitleScreen(void)
3067 SetGameStatus(GAME_MODE_TITLE);
3072 void HandleInfoScreen_TitleScreen(int button)
3074 HandleTitleScreen(0, 0, 0, 0, button);
3077 static void DrawInfoScreen_Elements(void)
3079 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3081 FadeOut(REDRAW_FIELD);
3086 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3088 FadeIn(REDRAW_FIELD);
3091 void HandleInfoScreen_Elements(int button)
3093 static unsigned int info_delay = 0;
3094 static int num_anims;
3095 static int num_pages;
3097 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3100 if (button == MB_MENU_INITIALIZE)
3102 boolean new_element = TRUE;
3106 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3108 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3110 else if (new_element)
3113 new_element = FALSE;
3117 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3121 if (button == MB_MENU_LEAVE)
3123 PlaySound(SND_MENU_ITEM_SELECTING);
3125 info_mode = INFO_MODE_MAIN;
3130 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3132 if (button != MB_MENU_INITIALIZE)
3134 PlaySound(SND_MENU_ITEM_SELECTING);
3139 if (page >= num_pages)
3141 FadeMenuSoundsAndMusic();
3143 info_mode = INFO_MODE_MAIN;
3150 FadeSetNextScreen();
3152 if (button != MB_MENU_INITIALIZE)
3153 FadeOut(REDRAW_FIELD);
3155 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3157 if (button != MB_MENU_INITIALIZE)
3158 FadeIn(REDRAW_FIELD);
3162 if (DelayReached(&info_delay, GameFrameDelay))
3163 if (page < num_pages)
3164 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3166 PlayMenuSoundIfLoop();
3170 static void DrawInfoScreen_Music(void)
3172 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3174 FadeOut(REDRAW_FIELD);
3181 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3183 FadeIn(REDRAW_FIELD);
3186 void HandleInfoScreen_Music(int button)
3188 static struct MusicFileInfo *list = NULL;
3189 int font_title = MENU_INFO_FONT_TITLE;
3190 int font_head = MENU_INFO_FONT_HEAD;
3191 int font_text = MENU_INFO_FONT_TEXT;
3192 int font_foot = MENU_INFO_FONT_FOOT;
3193 int spacing_title = menu.headline1_spacing_info[info_mode];
3194 int spacing_head = menu.headline2_spacing_info[info_mode];
3195 int ystep_title = getMenuTextStep(spacing_title, font_title);
3196 int ystep_head = getMenuTextStep(spacing_head, font_head);
3197 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3198 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3200 if (button == MB_MENU_INITIALIZE)
3202 list = music_file_info;
3206 FadeMenuSoundsAndMusic();
3211 DrawTextSCentered(ystart, font_title,
3212 "No music info for this level set.");
3214 DrawTextSCentered(ybottom, font_foot,
3215 "Press any key or button for info menu");
3221 if (button == MB_MENU_LEAVE)
3223 PlaySound(SND_MENU_ITEM_SELECTING);
3225 FadeMenuSoundsAndMusic();
3227 info_mode = INFO_MODE_MAIN;
3232 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3234 if (button != MB_MENU_INITIALIZE)
3236 PlaySound(SND_MENU_ITEM_SELECTING);
3244 FadeMenuSoundsAndMusic();
3246 info_mode = INFO_MODE_MAIN;
3252 FadeMenuSoundsAndMusic();
3254 if (list != music_file_info)
3255 FadeSetNextScreen();
3257 if (button != MB_MENU_INITIALIZE)
3258 FadeOut(REDRAW_FIELD);
3265 int sound = list->music;
3267 if (IS_LOOP_SOUND(sound))
3268 PlaySoundLoop(sound);
3272 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3276 int music = list->music;
3278 if (IS_LOOP_MUSIC(music))
3279 PlayMusicLoop(music);
3283 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3286 ystart += ystep_title;
3288 if (!strEqual(list->title, UNKNOWN_NAME))
3290 if (!strEqual(list->title_header, UNKNOWN_NAME))
3292 DrawTextSCentered(ystart, font_head, list->title_header);
3293 ystart += ystep_head;
3296 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3297 ystart += ystep_head;
3300 if (!strEqual(list->artist, UNKNOWN_NAME))
3302 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3303 DrawTextSCentered(ystart, font_head, list->artist_header);
3305 DrawTextSCentered(ystart, font_head, "by");
3307 ystart += ystep_head;
3309 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3310 ystart += ystep_head;
3313 if (!strEqual(list->album, UNKNOWN_NAME))
3315 if (!strEqual(list->album_header, UNKNOWN_NAME))
3316 DrawTextSCentered(ystart, font_head, list->album_header);
3318 DrawTextSCentered(ystart, font_head, "from the album");
3320 ystart += ystep_head;
3322 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3323 ystart += ystep_head;
3326 if (!strEqual(list->year, UNKNOWN_NAME))
3328 if (!strEqual(list->year_header, UNKNOWN_NAME))
3329 DrawTextSCentered(ystart, font_head, list->year_header);
3331 DrawTextSCentered(ystart, font_head, "from the year");
3333 ystart += ystep_head;
3335 DrawTextFCentered(ystart, font_text, "%s", list->year);
3336 ystart += ystep_head;
3339 DrawTextSCentered(ybottom, FONT_TEXT_4,
3340 "Press any key or button for next page");
3342 if (button != MB_MENU_INITIALIZE)
3343 FadeIn(REDRAW_FIELD);
3346 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3347 PlaySoundLoop(list->music);
3350 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3352 int font_title = MENU_INFO_FONT_TITLE;
3353 int font_head = MENU_INFO_FONT_HEAD;
3354 int font_text = MENU_INFO_FONT_TEXT;
3355 int font_foot = MENU_INFO_FONT_FOOT;
3356 int spacing_title = menu.headline1_spacing_info[info_mode];
3357 int spacing_head = menu.headline2_spacing_info[info_mode];
3358 int spacing_para = menu.paragraph_spacing_info[info_mode];
3359 int spacing_line = menu.line_spacing_info[info_mode];
3360 int ystep_title = getMenuTextStep(spacing_title, font_title);
3361 int ystep_head = getMenuTextStep(spacing_head, font_head);
3362 int ystep_para = getMenuTextStep(spacing_para, font_text);
3363 int ystep_line = getMenuTextStep(spacing_line, font_text);
3364 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3365 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3370 DrawTextSCentered(ystart, font_title, "Credits:");
3371 ystart += ystep_title;
3375 DrawTextSCentered(ystart, font_head,
3376 "Special thanks to");
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_text,
3380 ystart += ystep_head;
3381 DrawTextSCentered(ystart, font_head,
3383 ystart += ystep_head;
3384 DrawTextSCentered(ystart, font_text,
3385 "\"Boulder Dash\"");
3386 ystart += ystep_head;
3387 DrawTextSCentered(ystart, font_head,
3389 ystart += ystep_head;
3390 DrawTextSCentered(ystart, font_text,
3392 ystart += ystep_head;
3393 DrawTextSCentered(ystart, font_head,
3395 ystart += ystep_head;
3396 DrawTextSCentered(ystart, font_text,
3397 "First Star Software");
3399 else if (screen_nr == 1)
3401 DrawTextSCentered(ystart, font_head,
3402 "Special thanks to");
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_text,
3405 "Klaus Heinz & Volker Wertich");
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_head,
3409 ystart += ystep_head;
3410 DrawTextSCentered(ystart, font_text,
3411 "\"Emerald Mine\"");
3412 ystart += ystep_head;
3413 DrawTextSCentered(ystart, font_head,
3415 ystart += ystep_head;
3416 DrawTextSCentered(ystart, font_text,
3418 ystart += ystep_head;
3419 DrawTextSCentered(ystart, font_head,
3421 ystart += ystep_head;
3422 DrawTextSCentered(ystart, font_text,
3425 else if (screen_nr == 2)
3427 DrawTextSCentered(ystart, font_head,
3428 "Special thanks to");
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_text,
3431 "Michael Stopp & Philip Jespersen");
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_head,
3435 ystart += ystep_head;
3436 DrawTextSCentered(ystart, font_text,
3438 ystart += ystep_head;
3439 DrawTextSCentered(ystart, font_head,
3441 ystart += ystep_head;
3442 DrawTextSCentered(ystart, font_text,
3444 ystart += ystep_head;
3445 DrawTextSCentered(ystart, font_head,
3447 ystart += ystep_head;
3448 DrawTextSCentered(ystart, font_text,
3449 "Digital Integration");
3451 else if (screen_nr == 3)
3453 DrawTextSCentered(ystart, font_head,
3454 "Special thanks to");
3455 ystart += ystep_head;
3456 DrawTextSCentered(ystart, font_text,
3457 "Hiroyuki Imabayashi");
3458 ystart += ystep_head;
3459 DrawTextSCentered(ystart, font_head,
3461 ystart += ystep_head;
3462 DrawTextSCentered(ystart, font_text,
3464 ystart += ystep_head;
3465 DrawTextSCentered(ystart, font_head,
3467 ystart += ystep_head;
3468 DrawTextSCentered(ystart, font_text,
3470 ystart += ystep_head;
3471 DrawTextSCentered(ystart, font_head,
3473 ystart += ystep_head;
3474 DrawTextSCentered(ystart, font_text,
3477 else if (screen_nr == 4)
3479 DrawTextSCentered(ystart, font_head,
3480 "Special thanks to");
3481 ystart += ystep_head;
3482 DrawTextSCentered(ystart, font_text,
3484 ystart += ystep_head;
3485 DrawTextSCentered(ystart, font_head,
3487 ystart += ystep_head;
3488 DrawTextSCentered(ystart, font_text,
3489 "J\xfcrgen Bonhagen");
3490 ystart += ystep_head;
3491 DrawTextSCentered(ystart, font_head,
3492 "for the continuous creation");
3493 ystart += ystep_line;
3494 DrawTextSCentered(ystart, font_head,
3495 "of outstanding level sets");
3497 else if (screen_nr == 5)
3499 DrawTextSCentered(ystart, font_head,
3501 ystart += ystep_head;
3502 DrawTextSCentered(ystart, font_text,
3504 ystart += ystep_head;
3505 DrawTextSCentered(ystart, font_head,
3506 "for ideas and inspiration by");
3507 ystart += ystep_head;
3508 DrawTextSCentered(ystart, font_text,
3510 ystart += ystep_para;
3512 DrawTextSCentered(ystart, font_head,
3514 ystart += ystep_head;
3515 DrawTextSCentered(ystart, font_text,
3517 ystart += ystep_head;
3518 DrawTextSCentered(ystart, font_head,
3519 "for ideas and inspiration by");
3520 ystart += ystep_head;
3521 DrawTextSCentered(ystart, font_text,
3524 else if (screen_nr == 6)
3526 DrawTextSCentered(ystart, font_head,
3528 ystart += ystep_head;
3529 DrawTextSCentered(ystart, font_text,
3531 ystart += ystep_head;
3532 DrawTextSCentered(ystart, font_head,
3533 "for the code base used for the");
3534 ystart += ystep_line;
3535 DrawTextSCentered(ystart, font_head,
3536 "native Emerald Mine engine");
3538 else if (screen_nr == 7)
3540 DrawTextSCentered(ystart, font_head,
3542 ystart += ystep_head;
3543 DrawTextSCentered(ystart, font_text,
3545 ystart += ystep_head;
3546 DrawTextSCentered(ystart, font_head,
3547 "for the initial DOS port");
3548 ystart += ystep_para;
3550 DrawTextSCentered(ystart, font_head,
3552 ystart += ystep_head;
3553 DrawTextSCentered(ystart, font_text,
3555 ystart += ystep_head;
3556 DrawTextSCentered(ystart, font_head,
3557 "for some additional toons");
3559 else if (screen_nr == 8)
3561 DrawTextSCentered(ystart, font_head,
3562 "And not to forget:");
3563 ystart += ystep_head;
3564 DrawTextSCentered(ystart, font_head,
3566 ystart += ystep_head;
3567 DrawTextSCentered(ystart, font_text,
3568 "All those who contributed");
3569 ystart += ystep_line;
3570 DrawTextSCentered(ystart, font_text,
3571 "levels to this game");
3572 ystart += ystep_line;
3573 DrawTextSCentered(ystart, font_text,
3577 DrawTextSCentered(ybottom, font_foot,
3578 "Press any key or button for next page");
3581 static void DrawInfoScreen_Credits(void)
3583 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3585 FadeMenuSoundsAndMusic();
3587 FadeOut(REDRAW_FIELD);
3589 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3591 FadeIn(REDRAW_FIELD);
3594 void HandleInfoScreen_Credits(int button)
3596 static int screen_nr = 0;
3597 int num_screens = 9;
3599 if (button == MB_MENU_INITIALIZE)
3603 // DrawInfoScreen_CreditsScreen(screen_nr);
3606 if (button == MB_MENU_LEAVE)
3608 PlaySound(SND_MENU_ITEM_SELECTING);
3610 info_mode = INFO_MODE_MAIN;
3615 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3617 if (button != MB_MENU_INITIALIZE)
3619 PlaySound(SND_MENU_ITEM_SELECTING);
3624 if (screen_nr >= num_screens)
3626 FadeMenuSoundsAndMusic();
3628 info_mode = INFO_MODE_MAIN;
3635 FadeSetNextScreen();
3637 if (button != MB_MENU_INITIALIZE)
3638 FadeOut(REDRAW_FIELD);
3640 DrawInfoScreen_CreditsScreen(screen_nr);
3642 if (button != MB_MENU_INITIALIZE)
3643 FadeIn(REDRAW_FIELD);
3647 PlayMenuSoundIfLoop();
3651 static void DrawInfoScreen_Program(void)
3653 int font_title = MENU_INFO_FONT_TITLE;
3654 int font_head = MENU_INFO_FONT_HEAD;
3655 int font_text = MENU_INFO_FONT_TEXT;
3656 int font_foot = MENU_INFO_FONT_FOOT;
3657 int spacing_title = menu.headline1_spacing_info[info_mode];
3658 int spacing_head = menu.headline2_spacing_info[info_mode];
3659 int spacing_para = menu.paragraph_spacing_info[info_mode];
3660 int spacing_line = menu.line_spacing_info[info_mode];
3661 int ystep_title = getMenuTextStep(spacing_title, font_title);
3662 int ystep_head = getMenuTextStep(spacing_head, font_head);
3663 int ystep_para = getMenuTextStep(spacing_para, font_text);
3664 int ystep_line = getMenuTextStep(spacing_line, font_text);
3665 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3666 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3668 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3670 FadeOut(REDRAW_FIELD);
3675 DrawTextSCentered(ystart, font_title, "Program Information:");
3676 ystart += ystep_title;
3678 DrawTextSCentered(ystart, font_head,
3679 "This game is Freeware!");
3680 ystart += ystep_head;
3681 DrawTextSCentered(ystart, font_head,
3682 "If you like it, send e-mail to:");
3683 ystart += ystep_head;
3684 DrawTextSCentered(ystart, font_text,
3685 setup.internal.program_email);
3686 ystart += ystep_para;
3688 DrawTextSCentered(ystart, font_head,
3689 "More information and levels:");
3690 ystart += ystep_head;
3691 DrawTextSCentered(ystart, font_text,
3692 setup.internal.program_website);
3693 ystart += ystep_para;
3695 DrawTextSCentered(ystart, font_head,
3696 "If you have created new levels,");
3697 ystart += ystep_line;
3698 DrawTextSCentered(ystart, font_head,
3699 "send them to me to include them!");
3700 ystart += ystep_head;
3701 DrawTextSCentered(ystart, font_head,
3704 DrawTextSCentered(ybottom, font_foot,
3705 "Press any key or button for info menu");
3707 FadeIn(REDRAW_FIELD);
3710 void HandleInfoScreen_Program(int button)
3712 if (button == MB_MENU_LEAVE)
3714 PlaySound(SND_MENU_ITEM_SELECTING);
3716 info_mode = INFO_MODE_MAIN;
3721 else if (button == MB_MENU_CHOICE)
3723 PlaySound(SND_MENU_ITEM_SELECTING);
3725 FadeMenuSoundsAndMusic();
3727 info_mode = INFO_MODE_MAIN;
3732 PlayMenuSoundIfLoop();
3736 static void DrawInfoScreen_Version(void)
3738 int font_title = MENU_INFO_FONT_TITLE;
3739 int font_head = MENU_INFO_FONT_HEAD;
3740 int font_text = MENU_INFO_FONT_TEXT;
3741 int font_foot = MENU_INFO_FONT_FOOT;
3742 int spacing_title = menu.headline1_spacing_info[info_mode];
3743 int spacing_head = menu.headline2_spacing_info[info_mode];
3744 int spacing_para = menu.paragraph_spacing_info[info_mode];
3745 int spacing_line = menu.line_spacing_info[info_mode];
3746 int xstep = getFontWidth(font_text);
3747 int ystep_title = getMenuTextStep(spacing_title, font_title);
3748 int ystep_head = getMenuTextStep(spacing_head, font_head);
3749 int ystep_para = getMenuTextStep(spacing_para, font_text);
3750 int ystep_line = getMenuTextStep(spacing_line, font_text);
3751 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3752 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3753 int xstart1 = mSX - SX + 2 * xstep;
3754 int xstart2 = mSX - SX + 18 * xstep;
3755 int xstart3 = mSX - SX + 28 * xstep;
3756 SDL_version sdl_version_compiled;
3757 const SDL_version *sdl_version_linked;
3758 int driver_name_len = 10;
3759 SDL_version sdl_version_linked_ext;
3760 const char *driver_name = NULL;
3762 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3764 FadeOut(REDRAW_FIELD);
3769 DrawTextSCentered(ystart, font_title, "Version Information:");
3770 ystart += ystep_title;
3772 DrawTextF(xstart1, ystart, font_head, "Name");
3773 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3774 ystart += ystep_line;
3776 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3778 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3779 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3780 ystart += ystep_line;
3782 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3783 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3784 ystart += ystep_line;
3788 DrawTextF(xstart1, ystart, font_head, "Version");
3789 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3790 ystart += ystep_line;
3793 DrawTextF(xstart1, ystart, font_head, "Platform");
3794 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3796 PLATFORM_XX_BIT_STRING);
3797 ystart += ystep_line;
3799 DrawTextF(xstart1, ystart, font_head, "Target");
3800 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3801 ystart += ystep_line;
3803 DrawTextF(xstart1, ystart, font_head, "Source date");
3804 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3805 ystart += ystep_line;
3807 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3808 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3809 ystart += ystep_para;
3811 DrawTextF(xstart1, ystart, font_head, "Library");
3812 DrawTextF(xstart2, ystart, font_head, "compiled");
3813 DrawTextF(xstart3, ystart, font_head, "linked");
3814 ystart += ystep_head;
3816 SDL_VERSION(&sdl_version_compiled);
3817 SDL_GetVersion(&sdl_version_linked_ext);
3818 sdl_version_linked = &sdl_version_linked_ext;
3820 DrawTextF(xstart1, ystart, font_text, "SDL");
3821 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3822 sdl_version_compiled.major,
3823 sdl_version_compiled.minor,
3824 sdl_version_compiled.patch);
3825 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3826 sdl_version_linked->major,
3827 sdl_version_linked->minor,
3828 sdl_version_linked->patch);
3829 ystart += ystep_line;
3831 SDL_IMAGE_VERSION(&sdl_version_compiled);
3832 sdl_version_linked = IMG_Linked_Version();
3834 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3835 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3836 sdl_version_compiled.major,
3837 sdl_version_compiled.minor,
3838 sdl_version_compiled.patch);
3839 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3840 sdl_version_linked->major,
3841 sdl_version_linked->minor,
3842 sdl_version_linked->patch);
3843 ystart += ystep_line;
3845 SDL_MIXER_VERSION(&sdl_version_compiled);
3846 sdl_version_linked = Mix_Linked_Version();
3848 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3849 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3850 sdl_version_compiled.major,
3851 sdl_version_compiled.minor,
3852 sdl_version_compiled.patch);
3853 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3854 sdl_version_linked->major,
3855 sdl_version_linked->minor,
3856 sdl_version_linked->patch);
3857 ystart += ystep_line;
3859 SDL_NET_VERSION(&sdl_version_compiled);
3860 sdl_version_linked = SDLNet_Linked_Version();
3862 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3863 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3864 sdl_version_compiled.major,
3865 sdl_version_compiled.minor,
3866 sdl_version_compiled.patch);
3867 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3868 sdl_version_linked->major,
3869 sdl_version_linked->minor,
3870 sdl_version_linked->patch);
3871 ystart += ystep_para;
3873 DrawTextF(xstart1, ystart, font_head, "Driver");
3874 DrawTextF(xstart2, ystart, font_head, "Requested");
3875 DrawTextF(xstart3, ystart, font_head, "Used");
3876 ystart += ystep_head;
3879 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3881 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3882 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3883 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3884 ystart += ystep_line;
3887 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3889 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3890 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3891 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3892 ystart += ystep_line;
3895 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3897 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3898 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3899 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3901 DrawTextSCentered(ybottom, font_foot,
3902 "Press any key or button for info menu");
3904 FadeIn(REDRAW_FIELD);
3907 void HandleInfoScreen_Version(int button)
3909 if (button == MB_MENU_LEAVE)
3911 PlaySound(SND_MENU_ITEM_SELECTING);
3913 info_mode = INFO_MODE_MAIN;
3918 else if (button == MB_MENU_CHOICE)
3920 PlaySound(SND_MENU_ITEM_SELECTING);
3922 FadeMenuSoundsAndMusic();
3924 info_mode = INFO_MODE_MAIN;
3929 PlayMenuSoundIfLoop();
3933 static void DrawInfoScreen_LevelSet(void)
3935 struct TitleMessageInfo *tmi = &readme;
3936 char *filename = getLevelSetInfoFilename();
3937 char *title = "Level Set Information:";
3938 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3939 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3941 if (filename == NULL)
3943 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3948 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3950 FadeOut(REDRAW_FIELD);
3955 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3957 // if x position set to "-1", automatically determine by playfield width
3959 tmi->x = SXSIZE / 2;
3961 // if y position set to "-1", use static default value
3965 // if width set to "-1", automatically determine by playfield width
3966 if (tmi->width == -1)
3967 tmi->width = SXSIZE - 2 * TILEX;
3969 // if height set to "-1", automatically determine by playfield height
3970 if (tmi->height == -1)
3971 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3973 // if chars set to "-1", automatically determine by text and font width
3974 if (tmi->chars == -1)
3975 tmi->chars = tmi->width / getFontWidth(tmi->font);
3977 tmi->width = tmi->chars * getFontWidth(tmi->font);
3979 // if lines set to "-1", automatically determine by text and font height
3980 if (tmi->lines == -1)
3981 tmi->lines = tmi->height / getFontHeight(tmi->font);
3983 tmi->height = tmi->lines * getFontHeight(tmi->font);
3985 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3986 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3987 tmi->autowrap, tmi->centered, tmi->parse_comments);
3989 DrawTextSCentered(ybottom, FONT_TEXT_4,
3990 "Press any key or button for info menu");
3992 FadeIn(REDRAW_FIELD);
3995 static void HandleInfoScreen_LevelSet(int button)
3997 if (button == MB_MENU_LEAVE)
3999 PlaySound(SND_MENU_ITEM_SELECTING);
4001 info_mode = INFO_MODE_MAIN;
4006 else if (button == MB_MENU_CHOICE)
4008 PlaySound(SND_MENU_ITEM_SELECTING);
4010 FadeMenuSoundsAndMusic();
4012 info_mode = INFO_MODE_MAIN;
4017 PlayMenuSoundIfLoop();
4021 static void DrawInfoScreen(void)
4023 if (info_mode == INFO_MODE_TITLE)
4024 DrawInfoScreen_TitleScreen();
4025 else if (info_mode == INFO_MODE_ELEMENTS)
4026 DrawInfoScreen_Elements();
4027 else if (info_mode == INFO_MODE_MUSIC)
4028 DrawInfoScreen_Music();
4029 else if (info_mode == INFO_MODE_CREDITS)
4030 DrawInfoScreen_Credits();
4031 else if (info_mode == INFO_MODE_PROGRAM)
4032 DrawInfoScreen_Program();
4033 else if (info_mode == INFO_MODE_VERSION)
4034 DrawInfoScreen_Version();
4035 else if (info_mode == INFO_MODE_LEVELSET)
4036 DrawInfoScreen_LevelSet();
4038 DrawInfoScreen_Main();
4040 if (info_mode != INFO_MODE_MAIN &&
4041 info_mode != INFO_MODE_TITLE &&
4042 info_mode != INFO_MODE_MUSIC)
4043 PlayMenuSoundsAndMusic();
4046 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4048 if (info_mode == INFO_MODE_TITLE)
4049 HandleInfoScreen_TitleScreen(button);
4050 else if (info_mode == INFO_MODE_ELEMENTS)
4051 HandleInfoScreen_Elements(button);
4052 else if (info_mode == INFO_MODE_MUSIC)
4053 HandleInfoScreen_Music(button);
4054 else if (info_mode == INFO_MODE_CREDITS)
4055 HandleInfoScreen_Credits(button);
4056 else if (info_mode == INFO_MODE_PROGRAM)
4057 HandleInfoScreen_Program(button);
4058 else if (info_mode == INFO_MODE_VERSION)
4059 HandleInfoScreen_Version(button);
4060 else if (info_mode == INFO_MODE_LEVELSET)
4061 HandleInfoScreen_LevelSet(button);
4063 HandleInfoScreen_Main(mx, my, dx, dy, button);
4067 // ============================================================================
4068 // rename player API functions
4069 // ============================================================================
4071 struct ApiRenamePlayerThreadData
4077 static void *CreateThreadData_ApiRenamePlayer(void)
4079 struct ApiRenamePlayerThreadData *data =
4080 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4082 data->player_name = getStringCopy(setup.player_name);
4083 data->player_uuid = getStringCopy(setup.player_uuid);
4088 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4090 struct ApiRenamePlayerThreadData *data = data_raw;
4092 checked_free(data->player_name);
4093 checked_free(data->player_uuid);
4097 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4100 struct ApiRenamePlayerThreadData *data = data_raw;
4101 char *player_name_raw = data->player_name;
4102 char *player_uuid_raw = data->player_uuid;
4104 request->hostname = setup.api_server_hostname;
4105 request->port = API_SERVER_PORT;
4106 request->method = API_SERVER_METHOD;
4107 request->uri = API_SERVER_URI_RENAME;
4109 char *player_name = getEscapedJSON(player_name_raw);
4110 char *player_uuid = getEscapedJSON(player_uuid_raw);
4112 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4115 " \"game_version\": \"%s\",\n"
4116 " \"game_platform\": \"%s\",\n"
4117 " \"name\": \"%s\",\n"
4118 " \"uuid\": \"%s\"\n"
4120 getPasswordJSON(setup.api_server_password),
4121 getProgramRealVersionString(),
4122 getProgramPlatformString(),
4126 checked_free(player_name);
4127 checked_free(player_uuid);
4129 ConvertHttpRequestBodyToServerEncoding(request);
4134 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4137 // nothing to do here
4140 #if defined(PLATFORM_EMSCRIPTEN)
4141 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4142 void *buffer, unsigned int size)
4144 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4146 if (response != NULL)
4148 HandleResponse_ApiRenamePlayer(response, data_raw);
4150 checked_free(response);
4154 Error("server response too large to handle (%d bytes)", size);
4157 FreeThreadData_ApiRenamePlayer(data_raw);
4160 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4161 int code, const char *status)
4163 Error("server failed to handle request: %d %s", code, status);
4165 FreeThreadData_ApiRenamePlayer(data_raw);
4168 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4169 int bytes, int size)
4171 // nothing to do here
4174 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4177 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4179 FreeThreadData_ApiRenamePlayer(data_raw);
4184 emscripten_async_wget2_data(request->uri,
4189 Emscripten_ApiRenamePlayer_Loaded,
4190 Emscripten_ApiRenamePlayer_Failed,
4191 Emscripten_ApiRenamePlayer_Progress);
4196 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4197 struct HttpResponse *response,
4200 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4203 if (!DoHttpRequest(request, response))
4205 Error("HTTP request failed: %s", GetHttpError());
4210 if (!HTTP_SUCCESS(response->status_code))
4212 Error("server failed to handle request: %d %s",
4213 response->status_code,
4214 response->status_text);
4219 HandleResponse_ApiRenamePlayer(response, data_raw);
4222 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4223 struct HttpResponse *response,
4226 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4228 FreeThreadData_ApiRenamePlayer(data_raw);
4232 static int ApiRenamePlayerThread(void *data_raw)
4234 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4235 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4237 program.api_thread_count++;
4239 #if defined(PLATFORM_EMSCRIPTEN)
4240 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4242 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4245 program.api_thread_count--;
4247 checked_free(request);
4248 checked_free(response);
4253 static void ApiRenamePlayerAsThread(void)
4255 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4257 ExecuteAsThread(ApiRenamePlayerThread,
4258 "ApiRenamePlayer", data,
4259 "rename player on server");
4263 // ============================================================================
4264 // reset player UUID API functions
4265 // ============================================================================
4267 struct ApiResetUUIDThreadData
4270 char *player_uuid_old;
4271 char *player_uuid_new;
4274 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4276 struct ApiResetUUIDThreadData *data =
4277 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4279 data->player_name = getStringCopy(setup.player_name);
4280 data->player_uuid_old = getStringCopy(setup.player_uuid);
4281 data->player_uuid_new = getStringCopy(uuid_new);
4286 static void FreeThreadData_ApiResetUUID(void *data_raw)
4288 struct ApiResetUUIDThreadData *data = data_raw;
4290 checked_free(data->player_name);
4291 checked_free(data->player_uuid_old);
4292 checked_free(data->player_uuid_new);
4296 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4299 struct ApiResetUUIDThreadData *data = data_raw;
4300 char *player_name_raw = data->player_name;
4301 char *player_uuid_old_raw = data->player_uuid_old;
4302 char *player_uuid_new_raw = data->player_uuid_new;
4304 request->hostname = setup.api_server_hostname;
4305 request->port = API_SERVER_PORT;
4306 request->method = API_SERVER_METHOD;
4307 request->uri = API_SERVER_URI_RESETUUID;
4309 char *player_name = getEscapedJSON(player_name_raw);
4310 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4311 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4313 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4316 " \"game_version\": \"%s\",\n"
4317 " \"game_platform\": \"%s\",\n"
4318 " \"name\": \"%s\",\n"
4319 " \"uuid_old\": \"%s\",\n"
4320 " \"uuid_new\": \"%s\"\n"
4322 getPasswordJSON(setup.api_server_password),
4323 getProgramRealVersionString(),
4324 getProgramPlatformString(),
4329 checked_free(player_name);
4330 checked_free(player_uuid_old);
4331 checked_free(player_uuid_new);
4333 ConvertHttpRequestBodyToServerEncoding(request);
4338 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4341 struct ApiResetUUIDThreadData *data = data_raw;
4343 // upgrade player UUID in server setup file
4344 setup.player_uuid = getStringCopy(data->player_uuid_new);
4345 setup.player_version = 2;
4347 SaveSetup_ServerSetup();
4350 #if defined(PLATFORM_EMSCRIPTEN)
4351 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4352 void *buffer, unsigned int size)
4354 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4356 if (response != NULL)
4358 HandleResponse_ApiResetUUID(response, data_raw);
4360 checked_free(response);
4364 Error("server response too large to handle (%d bytes)", size);
4367 FreeThreadData_ApiResetUUID(data_raw);
4370 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4371 int code, const char *status)
4373 Error("server failed to handle request: %d %s", code, status);
4375 FreeThreadData_ApiResetUUID(data_raw);
4378 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4379 int bytes, int size)
4381 // nothing to do here
4384 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4387 if (!SetRequest_ApiResetUUID(request, data_raw))
4389 FreeThreadData_ApiResetUUID(data_raw);
4394 emscripten_async_wget2_data(request->uri,
4399 Emscripten_ApiResetUUID_Loaded,
4400 Emscripten_ApiResetUUID_Failed,
4401 Emscripten_ApiResetUUID_Progress);
4406 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4407 struct HttpResponse *response,
4410 if (!SetRequest_ApiResetUUID(request, data_raw))
4413 if (!DoHttpRequest(request, response))
4415 Error("HTTP request failed: %s", GetHttpError());
4420 if (!HTTP_SUCCESS(response->status_code))
4422 Error("server failed to handle request: %d %s",
4423 response->status_code,
4424 response->status_text);
4429 HandleResponse_ApiResetUUID(response, data_raw);
4432 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4433 struct HttpResponse *response,
4436 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4438 FreeThreadData_ApiResetUUID(data_raw);
4442 static int ApiResetUUIDThread(void *data_raw)
4444 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4445 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4447 program.api_thread_count++;
4449 #if defined(PLATFORM_EMSCRIPTEN)
4450 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4452 ApiResetUUID_HttpRequest(request, response, data_raw);
4455 program.api_thread_count--;
4457 checked_free(request);
4458 checked_free(response);
4463 static void ApiResetUUIDAsThread(char *uuid_new)
4465 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4467 ExecuteAsThread(ApiResetUUIDThread,
4468 "ApiResetUUID", data,
4469 "reset UUID on server");
4473 // ============================================================================
4474 // type name functions
4475 // ============================================================================
4477 static TreeInfo *type_name_node = NULL;
4478 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4479 static int type_name_nr = 0;
4481 static int getPlayerNameColor(char *name)
4483 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4486 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4489 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4490 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4491 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4492 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4493 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4494 int font_width = getFontWidth(font_nr);
4496 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4498 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4500 pos->width = strlen(text) * font_width;
4501 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4503 DrawText(sx, sy, text, font_nr);
4506 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4508 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4510 *pos = *mci->pos_input;
4512 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4514 TreeInfo *ti = player_name_current;
4515 int first_entry = ti->cl_first;
4516 int entry_pos = first_entry + ti->cl_cursor;
4517 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4518 int xpos = MENU_SCREEN_START_XPOS;
4519 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4521 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4522 type_name_nr = entry_pos;
4524 strcpy(name, type_name_node->name);
4528 pos->width = MAX_PLAYER_NAME_LEN * 32;
4532 type_name_nr = user.nr;
4534 strcpy(name, setup.player_name);
4537 strcpy(type_name_last, name);
4539 if (strEqual(name, EMPTY_PLAYER_NAME))
4542 *xpos = strlen(name);
4545 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4547 // change name of edited user in global list of user names
4548 setString(&global.user_names[type_name_nr], name);
4550 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4552 TreeInfo *node = type_name_node;
4554 // change name of edited user in local menu tree structure
4555 setString(&node->name, name);
4556 setString(&node->name_sorting, name);
4558 node->color = getPlayerNameColor(name);
4559 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4563 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4566 boolean reset_setup = strEqual(name, "");
4567 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4568 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4571 strcpy(name, type_name_last);
4573 if (strEqual(name, ""))
4574 strcpy(name, EMPTY_PLAYER_NAME);
4576 setTypeNameValues_Name(name, pos);
4578 // if player name not changed, no further action required
4579 if (strEqual(name, type_name_last))
4582 // redraw player name before (possibly) opening request dialogs
4583 drawTypeNameText(name, pos, FALSE);
4585 int last_user_nr = user.nr;
4587 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4589 // save setup of currently active user (may differ from edited user)
4592 // temporarily change active user to edited user
4593 user.nr = type_name_nr;
4596 Request("Use current setup values for the new player?", REQ_ASK))
4598 // use current setup values for new user, but create new player UUID
4599 setup.player_uuid = getStringCopy(getUUID());
4603 // load setup for existing user (or start with defaults for new user)
4608 char *setup_filename = getSetupFilename();
4609 boolean setup_exists = fileExists(setup_filename);
4611 // change name of edited user in setup structure
4612 strcpy(setup.player_name, name);
4614 // save setup of edited user
4617 // change name of edited user on score server
4618 ApiRenamePlayerAsThread();
4620 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4624 if (Request("Reset setup values for this player?", REQ_ASK))
4626 // remove setup config file
4627 unlink(setup_filename);
4629 // set player name to default player name
4632 // update player name used by name typing functions
4633 strcpy(name, setup.player_name);
4635 setTypeNameValues_Name(name, pos);
4638 else if (remove_user && type_name_nr != 0)
4640 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4642 char *user_dir = getUserGameDataDir();
4643 char *user_dir_removed =
4644 getStringCat3WithSeparator(user_dir, "REMOVED",
4645 getCurrentTimestamp(), ".");
4647 if (rename(user_dir, user_dir_removed) != 0)
4648 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4650 checked_free(user_dir_removed);
4653 else if (create_user && type_name_nr != 0 && !setup_exists)
4655 if (Request("Create empty level set for the new player?", REQ_ASK))
4657 char *levelset_subdir = getNewUserLevelSubdir();
4659 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4661 AddUserLevelSetToLevelInfo(levelset_subdir);
4663 LevelDirTree *leveldir_current_last = leveldir_current;
4665 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4668 // set level number of newly created level set to default value
4669 LoadLevelSetup_SeriesInfo();
4671 // set newly created level set as current level set for new user
4672 SaveLevelSetup_LastSeries();
4673 SaveLevelSetup_SeriesInfo();
4675 leveldir_current = leveldir_current_last;
4679 Request("Creating new level set failed!", REQ_CONFIRM);
4684 // restore currently active user
4685 user.nr = last_user_nr;
4687 // restore setup of currently active user
4690 // restore last level set of currently active user
4691 LoadLevelSetup_LastSeries();
4692 LoadLevelSetup_SeriesInfo();
4696 static void HandleTypeNameExt(boolean initialize, Key key)
4698 static struct TextPosInfo pos_name = { 0 };
4699 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4700 static int xpos = 0;
4701 struct TextPosInfo *pos = &pos_name;
4702 char key_char = getValidConfigValueChar(getCharFromKey(key));
4703 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4704 boolean active = TRUE;
4708 getTypeNameValues(name, pos, &xpos);
4710 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4711 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4713 StartTextInput(sx, sy, pos->width, pos->height);
4715 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4717 name[xpos] = key_char;
4722 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4728 else if (key == KSYM_Return || key == KSYM_Escape)
4730 boolean changed = (key == KSYM_Return);
4734 setTypeNameValues(name, pos, changed);
4739 drawTypeNameText(name, pos, active);
4743 SetGameStatus(game_status_last_screen);
4745 if (game_status == GAME_MODE_MAIN)
4746 InitializeMainControls();
4750 static void DrawTypeName(void)
4752 HandleTypeNameExt(TRUE, 0);
4755 void HandleTypeName(Key key)
4757 HandleTypeNameExt(FALSE, key);
4761 // ============================================================================
4762 // tree menu functions
4763 // ============================================================================
4765 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4767 if (game_status != GAME_MODE_SETUP ||
4768 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4771 int max_text_size = 0;
4774 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4775 max_text_size = MAX(max_text_size, strlen(node->name));
4777 int num_entries = numTreeInfoInGroup(ti);
4778 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4779 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4780 int text_width = max_text_size * getFontWidth(font_nr);
4781 int button_width = SC_MENUBUTTON_XSIZE;
4782 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4783 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4784 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4785 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4786 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4787 int align_xoffset = MAX(0, align_xoffset_raw);
4789 return align_xoffset;
4792 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4794 if (game_status != GAME_MODE_SETUP ||
4795 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4798 int num_entries = numTreeInfoInGroup(ti);
4799 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4800 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4801 int font_height = getFontHeight(font_nr);
4802 int text_height = font_height * num_page_entries;
4803 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4804 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4805 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4806 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4807 int align_yoffset = MAX(0, align_yoffset_raw);
4809 return align_yoffset;
4812 static void DrawChooseTree(TreeInfo **ti_ptr)
4814 int fade_mask = REDRAW_FIELD;
4817 fade_mask = REDRAW_ALL;
4819 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4821 if (game_status == GAME_MODE_SETUP)
4825 else // GAME_MODE_LEVELS
4827 SetGameStatus(GAME_MODE_MAIN);
4837 FreeScreenGadgets();
4838 CreateScreenGadgets();
4840 if (game_status != game_status_last_screen)
4841 FadeMenuSoundsAndMusic();
4845 // needed if different viewport properties defined for this screen
4846 ChangeViewportPropertiesIfNeeded();
4848 if (game_status == GAME_MODE_NAMES)
4849 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4850 else if (game_status == GAME_MODE_LEVELNR)
4851 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4852 else if (game_status == GAME_MODE_LEVELS)
4853 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4854 else if (game_status == GAME_MODE_SCORES)
4855 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4859 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4861 MapScreenTreeGadgets(*ti_ptr);
4862 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4864 DrawMaskedBorder(fade_mask);
4866 if (game_status != game_status_last_screen)
4867 PlayMenuSoundsAndMusic();
4872 static int getChooseTreeFont(TreeInfo *node, boolean active)
4874 if (game_status == GAME_MODE_SCORES)
4875 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4877 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4880 static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
4882 int num_entries = numTreeInfoInGroup(ti);
4883 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4884 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4885 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4886 int first_entry = ti->cl_first;
4887 int entry_pos = first_entry + y;
4888 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4889 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4890 int font_nr = getChooseTreeFont(node, active);
4891 int font_xoffset = getFontDrawOffsetX(font_nr);
4892 int xpos = MENU_SCREEN_START_XPOS;
4893 int ypos = MENU_SCREEN_START_YPOS + y;
4894 int startdx = xpos * 32;
4895 int startdy = ypos * 32;
4896 int startx = amSX + startdx;
4897 int starty = amSY + startdy;
4898 int startx_text = startx + font_xoffset;
4899 int endx_text = amSX + screen_width;
4900 int max_text_size = endx_text - startx_text;
4901 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4902 char buffer[max_buffer_len + 1];
4904 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4906 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4907 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4908 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4909 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4910 int font_size_1 = getFontWidth(font_nr1);
4911 int font_size_3 = getFontWidth(font_nr3);
4912 int font_size_4 = getFontWidth(font_nr4);
4913 int text_size_1 = 3 * font_size_1;
4914 int text_size_4 = 5 * font_size_4;
4915 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4917 int dx2 = text_size_1;
4918 int dx3 = dx2 + font_size_1;
4919 int dx4 = screen_width - startdx - 2 * border - text_size_4;
4920 int num_dots = (dx4 - dx3) / font_size_3;
4921 int startx1 = startx + dx1;
4922 int startx2 = startx + dx2;
4923 int startx3 = startx + dx3;
4924 int startx4 = startx + dx4;
4925 int pos = node->pos;
4926 boolean forced = (scores.force_last_added && pos == scores.last_added);
4927 char *pos_text = (forced ? "???" : int2str(pos + 1, 3));
4928 char *dot_text = ".";
4931 DrawText(startx1, starty, pos_text, font_nr1);
4932 DrawText(startx2, starty, dot_text, font_nr1);
4934 for (i = 0; i < num_dots; i++)
4935 DrawText(startx3 + i * font_size_3, starty, dot_text, font_nr3);
4937 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4938 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4940 DrawText(startx4, starty, getHallOfFameScoreText(pos), font_nr4);
4944 strncpy(buffer, node->name, max_buffer_len);
4945 buffer[max_buffer_len] = '\0';
4947 DrawText(startx, starty, buffer, font_nr);
4951 static void drawChooseTreeList(int first_entry, int num_page_entries,
4955 char *title_string = NULL;
4956 int yoffset_sets = MENU_TITLE1_YPOS;
4957 int yoffset_setup = 16;
4958 int yoffset = (ti->type == TREE_TYPE_SCORE_ENTRY ||
4959 ti->type == TREE_TYPE_LEVEL_DIR ||
4960 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4962 title_string = ti->infotext;
4964 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4966 clearMenuListArea();
4968 for (i = 0; i < num_page_entries; i++)
4970 TreeInfo *node, *node_first;
4971 int entry_pos = first_entry + i;
4973 node_first = getTreeInfoFirstGroupEntry(ti);
4974 node = getTreeInfoFromPos(node_first, entry_pos);
4976 drawChooseTreeText(i, FALSE, ti);
4978 if (node->parent_link)
4979 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4980 else if (node->level_group)
4981 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4983 initCursor(i, IMG_MENU_BUTTON);
4985 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4986 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4988 if (game_status == GAME_MODE_NAMES)
4989 drawChooseTreeEdit(i, FALSE);
4992 redraw_mask |= REDRAW_FIELD;
4995 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4997 TreeInfo *node, *node_first;
4998 int x, last_redraw_mask = redraw_mask;
4999 int ypos = MENU_TITLE2_YPOS;
5000 int font_nr = FONT_TITLE_2;
5002 if (ti->type == TREE_TYPE_LEVEL_NR)
5003 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
5005 if (ti->type == TREE_TYPE_SCORE_ENTRY)
5006 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
5007 scores.last_level_nr);
5009 if (ti->type != TREE_TYPE_LEVEL_DIR)
5012 node_first = getTreeInfoFirstGroupEntry(ti);
5013 node = getTreeInfoFromPos(node_first, entry_pos);
5015 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
5017 if (node->parent_link)
5018 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
5019 node->node_parent->name);
5020 else if (node->level_group)
5021 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
5023 else if (ti->type == TREE_TYPE_LEVEL_DIR)
5024 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
5025 node->levels, (node->levels > 1 ? "levels" : "level"),
5028 // let BackToFront() redraw only what is needed
5029 redraw_mask = last_redraw_mask;
5030 for (x = 0; x < SCR_FIELDX; x++)
5031 MarkTileDirty(x, 1);
5034 static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
5036 drawChooseTreeCursor(y, active);
5037 drawChooseTreeText(y, active, ti);
5040 static void drawChooseTreeScreen(TreeInfo *ti)
5042 int num_entries = numTreeInfoInGroup(ti);
5043 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5045 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
5046 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
5047 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
5049 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, ti->cl_first, ti);
5052 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
5054 // set current tree entry to last added score entry
5055 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(scores.last_added));
5057 // if that fails, set current tree entry to first entry (back link)
5058 if (*ti_ptr == NULL)
5059 *ti_ptr = score_entries->node_group;
5061 int num_entries = numTreeInfoInGroup(*ti_ptr);
5062 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5063 int pos_score = getPosFromTreeInfo(*ti_ptr);
5064 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5065 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5067 (*ti_ptr)->cl_first = pos_first;
5068 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5073 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5076 TreeInfo *ti = *ti_ptr;
5077 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5078 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5079 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5080 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5081 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5083 int y = ti->cl_cursor;
5084 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5085 int num_entries = numTreeInfoInGroup(ti);
5086 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5087 boolean position_set_by_scrollbar = (dx == 999);
5089 if (button == MB_MENU_INITIALIZE)
5091 int num_entries = numTreeInfoInGroup(ti);
5092 int entry_pos = getPosFromTreeInfo(ti);
5094 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5095 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5097 if (game_status == GAME_MODE_SCORES)
5099 if (server_scores.updated)
5101 // reload scores, using updated server score cache file
5102 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5104 server_scores.updated = FALSE;
5107 ti = setHallOfFameActiveEntry(ti_ptr);
5109 else if (ti->cl_first == -1)
5111 // only on initialization
5112 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5113 ti->cl_cursor = entry_pos - ti->cl_first;
5116 else if (ti->cl_cursor >= num_page_entries ||
5117 (num_entries > num_page_entries &&
5118 num_entries - ti->cl_first < num_page_entries))
5120 // only after change of list size (by custom graphic configuration)
5121 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5122 ti->cl_cursor = entry_pos - ti->cl_first;
5125 if (position_set_by_scrollbar)
5128 drawChooseTreeScreen(ti);
5132 else if (button == MB_MENU_LEAVE)
5134 if (game_status != GAME_MODE_SCORES)
5137 PlaySound(SND_MENU_ITEM_SELECTING);
5139 if (ti->node_parent)
5141 *ti_ptr = ti->node_parent;
5142 DrawChooseTree(ti_ptr);
5144 else if (game_status == GAME_MODE_SETUP)
5146 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5147 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5148 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5149 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5151 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5152 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5153 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5154 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5155 execSetupGraphics();
5156 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5157 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5158 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5160 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5161 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5162 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5163 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5164 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5165 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5166 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5167 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5174 if (game_status == GAME_MODE_LEVELNR)
5176 int new_level_nr = atoi(level_number_current->identifier);
5178 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5181 SetGameStatus(GAME_MODE_MAIN);
5189 if (mx || my) // mouse input
5191 x = (mx - amSX) / 32;
5192 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5194 if (game_status == GAME_MODE_NAMES)
5195 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5197 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5199 // move cursor instead of scrolling when already at start/end of list
5200 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5202 else if (dy == +1 * SCROLL_LINE &&
5203 ti->cl_first + num_page_entries == num_entries)
5206 // handle scrolling screen one line or page
5207 if (ti->cl_cursor + dy < 0 ||
5208 ti->cl_cursor + dy > num_page_entries - 1)
5210 boolean redraw = FALSE;
5212 if (ABS(dy) == SCROLL_PAGE)
5213 step = num_page_entries - 1;
5215 if (dy < 0 && ti->cl_first > 0)
5217 // scroll page/line up
5219 ti->cl_first -= step;
5220 if (ti->cl_first < 0)
5225 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5227 // scroll page/line down
5229 ti->cl_first += step;
5230 if (ti->cl_first + num_page_entries > num_entries)
5231 ti->cl_first = MAX(0, num_entries - num_page_entries);
5237 drawChooseTreeScreen(ti);
5242 // handle moving cursor one line
5243 y = ti->cl_cursor + dy;
5248 TreeInfo *node_first, *node_cursor;
5249 int entry_pos = ti->cl_first + y;
5251 node_first = getTreeInfoFirstGroupEntry(ti);
5252 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5254 if (node_cursor->node_group)
5258 PlaySound(SND_MENU_ITEM_SELECTING);
5260 node_cursor->cl_first = ti->cl_first;
5261 node_cursor->cl_cursor = ti->cl_cursor;
5262 *ti_ptr = node_cursor->node_group;
5263 DrawChooseTree(ti_ptr);
5268 else if (dx == -1 && ti->node_parent)
5272 PlaySound(SND_MENU_ITEM_SELECTING);
5274 *ti_ptr = ti->node_parent;
5275 DrawChooseTree(ti_ptr);
5280 if (!anyScrollbarGadgetActive() &&
5281 IN_VIS_MENU(x, y) &&
5282 mx < mx_right_border &&
5283 y >= 0 && y < num_page_entries)
5287 if (game_status == GAME_MODE_NAMES)
5289 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5290 drawChooseTreeEdit(y, TRUE);
5293 if (y != ti->cl_cursor)
5295 PlaySound(SND_MENU_ITEM_ACTIVATING);
5297 drawChooseTreeCursorAndText(ti->cl_cursor, FALSE, ti);
5298 drawChooseTreeCursorAndText(y, TRUE, ti);
5299 drawChooseTreeInfo(ti->cl_first + y, ti);
5305 if (game_status == GAME_MODE_SETUP)
5307 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5308 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5309 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5310 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5312 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5313 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5314 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5315 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5316 execSetupGraphics();
5317 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5318 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5319 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5321 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5322 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5323 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5324 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5325 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5326 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5327 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5328 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5337 TreeInfo *node_first, *node_cursor;
5338 int entry_pos = ti->cl_first + y;
5340 PlaySound(SND_MENU_ITEM_SELECTING);
5342 node_first = getTreeInfoFirstGroupEntry(ti);
5343 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5345 if (node_cursor->node_group)
5349 node_cursor->cl_first = ti->cl_first;
5350 node_cursor->cl_cursor = ti->cl_cursor;
5351 *ti_ptr = node_cursor->node_group;
5352 DrawChooseTree(ti_ptr);
5354 else if (node_cursor->parent_link)
5356 if (game_status != GAME_MODE_SCORES)
5359 *ti_ptr = node_cursor->node_parent;
5360 DrawChooseTree(ti_ptr);
5364 if (game_status != GAME_MODE_SCORES)
5367 node_cursor->cl_first = ti->cl_first;
5368 node_cursor->cl_cursor = ti->cl_cursor;
5369 *ti_ptr = node_cursor;
5371 if (ti->type == TREE_TYPE_LEVEL_DIR)
5373 LoadLevelSetup_SeriesInfo();
5375 SaveLevelSetup_LastSeries();
5376 SaveLevelSetup_SeriesInfo();
5380 if (game_status == GAME_MODE_SETUP)
5382 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5383 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5384 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5385 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5387 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5388 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5389 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5390 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5391 execSetupGraphics();
5392 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5393 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5394 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5396 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5397 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5398 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5399 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5400 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5401 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5402 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5403 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5410 if (game_status == GAME_MODE_LEVELNR)
5412 int new_level_nr = atoi(level_number_current->identifier);
5414 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5416 else if (game_status == GAME_MODE_LEVELS)
5418 // store level set if chosen from "last played level set" menu
5419 StoreLastPlayedLevels(leveldir_current);
5421 else if (game_status == GAME_MODE_NAMES)
5423 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5425 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5432 // change active user to selected user
5433 user.nr = entry_pos;
5435 // save number of new active user
5438 // load setup of new active user
5441 // load last level set of new active user
5442 LoadLevelSetup_LastSeries();
5443 LoadLevelSetup_SeriesInfo();
5445 // update list of last played level sets
5446 UpdateLastPlayedLevels_TreeInfo();
5450 ToggleFullscreenIfNeeded();
5451 ChangeWindowScalingIfNeeded();
5453 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5454 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5455 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5457 else if (game_status == GAME_MODE_SCORES)
5459 if (game_status_last_screen == GAME_MODE_PLAYING &&
5460 setup.auto_play_next_level && setup.increment_levels &&
5461 scores.last_level_nr < leveldir_current->last_level &&
5464 StartGameActions(network.enabled, setup.autorecord,
5470 SetGameStatus(GAME_MODE_MAIN);
5478 if (game_status == GAME_MODE_SCORES && server_scores.updated)
5480 // reload scores, using updated server score cache file
5481 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5483 server_scores.updated = FALSE;
5485 ti = setHallOfFameActiveEntry(ti_ptr);
5487 drawChooseTreeScreen(ti);
5490 if (game_status == GAME_MODE_SCORES)
5491 PlayMenuSoundIfLoop();
5494 void DrawChoosePlayerName(void)
5498 if (player_name != NULL)
5500 freeTreeInfo(player_name);
5505 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5507 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5508 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5511 ti->node_top = &player_name;
5512 ti->sort_priority = 10000 + value;
5513 ti->color = getPlayerNameColor(global.user_names[i]);
5515 snprintf(identifier, sizeof(identifier), "%d", value);
5516 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5518 setString(&ti->identifier, identifier);
5519 setString(&ti->name, name);
5520 setString(&ti->name_sorting, name);
5522 pushTreeInfo(&player_name, ti);
5525 // sort player entries by player number
5526 sortTreeInfo(&player_name);
5528 // set current player entry to selected player entry
5529 player_name_current =
5530 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5532 // if that fails, set current player name to first available name
5533 if (player_name_current == NULL)
5534 player_name_current = player_name;
5536 DrawChooseTree(&player_name_current);
5539 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5541 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5544 void DrawChooseLevelSet(void)
5546 DrawChooseTree(&leveldir_current);
5549 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5551 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5554 void DrawChooseLevelNr(void)
5558 if (level_number != NULL)
5560 freeTreeInfo(level_number);
5562 level_number = NULL;
5565 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5567 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5568 char identifier[32], name[64];
5571 // temporarily load level info to get level name
5572 LoadLevelInfoOnly(i);
5574 ti->node_top = &level_number;
5575 ti->sort_priority = 10000 + value;
5576 ti->color = (level.no_level_file ? FC_BLUE :
5577 LevelStats_getSolved(i) ? FC_GREEN :
5578 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5580 snprintf(identifier, sizeof(identifier), "%d", value);
5581 snprintf(name, sizeof(name), "%03d: %s", value,
5582 (level.no_level_file ? "(no file)" : level.name));
5584 setString(&ti->identifier, identifier);
5585 setString(&ti->name, name);
5586 setString(&ti->name_sorting, name);
5588 pushTreeInfo(&level_number, ti);
5591 // sort level number values to start with lowest level number
5592 sortTreeInfo(&level_number);
5594 // set current level number to current level number
5595 level_number_current =
5596 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5598 // if that also fails, set current level number to first available level
5599 if (level_number_current == NULL)
5600 level_number_current = level_number;
5602 DrawChooseTree(&level_number_current);
5605 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5607 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5610 static void DrawHallOfFame_setScoreEntries(void)
5612 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5615 if (score_entries != NULL)
5617 freeTreeInfo(score_entries);
5619 score_entries = NULL;
5622 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5624 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5625 char identifier[32], name[64];
5628 ti->node_top = &score_entries;
5629 ti->sort_priority = 10000 + value;
5630 ti->color = FC_YELLOW;
5633 snprintf(identifier, sizeof(identifier), "%d", value);
5634 snprintf(name, sizeof(name), "%03d.", value + 1);
5636 setString(&ti->identifier, identifier);
5637 setString(&ti->name, name);
5638 setString(&ti->name_sorting, name);
5640 pushTreeInfo(&score_entries, ti);
5643 // sort score entries to start with highest score entry
5644 sortTreeInfo(&score_entries);
5646 // add top tree node to create back link to main menu
5647 score_entries = addTopTreeInfoNode(score_entries);
5649 // set current score entry to last added or highest score entry
5650 score_entry_current =
5651 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5653 // if that fails, set current score entry to first valid score entry
5654 if (score_entry_current == NULL)
5655 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5658 void DrawHallOfFame(int level_nr)
5660 scores.last_level_nr = level_nr;
5662 // (this is needed when called from GameEnd() after winning a game)
5663 KeyboardAutoRepeatOn();
5665 // (this is needed when called from GameEnd() after winning a game)
5666 SetDrawDeactivationMask(REDRAW_NONE);
5667 SetDrawBackgroundMask(REDRAW_FIELD);
5669 LoadLocalAndServerScore(level_nr, TRUE);
5671 DrawHallOfFame_setScoreEntries();
5673 if (scores.last_added >= 0)
5674 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5676 FadeSetEnterScreen();
5678 DrawChooseTree(&score_entry_current);
5681 static char *getHallOfFameScoreText(int nr)
5683 if (!level.rate_time_over_score)
5684 return int2str(scores.entry[nr].score, 5); // show normal score
5686 if (level.use_step_counter)
5687 return int2str(scores.entry[nr].time, 5); // show number of steps
5689 static char score_text[10];
5690 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5691 int mm = (time_seconds / 60) % 60;
5692 int ss = (time_seconds % 60);
5694 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5699 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5701 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5705 // ============================================================================
5706 // setup screen functions
5707 // ============================================================================
5709 static struct TokenInfo *setup_info;
5710 static int num_setup_info; // number of setup entries shown on screen
5711 static int max_setup_info; // total number of setup entries in list
5713 static char *window_size_text;
5714 static char *scaling_type_text;
5715 static char *rendering_mode_text;
5716 static char *vsync_mode_text;
5717 static char *scroll_delay_text;
5718 static char *snapshot_mode_text;
5719 static char *game_speed_text;
5720 static char *scores_type_text;
5721 static char *network_server_text;
5722 static char *graphics_set_name;
5723 static char *sounds_set_name;
5724 static char *music_set_name;
5725 static char *volume_simple_text;
5726 static char *volume_loops_text;
5727 static char *volume_music_text;
5728 static char *touch_controls_text;
5729 static char *move_distance_text;
5730 static char *drop_distance_text;
5731 static char *transparency_text;
5732 static char *grid_size_text[2][2];
5734 static void execSetupMain(void)
5736 setup_mode = SETUP_MODE_MAIN;
5741 static void execSetupGame_setScoresType(void)
5743 if (scores_types == NULL)
5747 for (i = 0; scores_types_list[i].value != NULL; i++)
5749 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5750 char identifier[32], name[32];
5751 char *value = scores_types_list[i].value;
5752 char *text = scores_types_list[i].text;
5754 ti->node_top = &scores_types;
5755 ti->sort_priority = i;
5757 sprintf(identifier, "%s", value);
5758 sprintf(name, "%s", text);
5760 setString(&ti->identifier, identifier);
5761 setString(&ti->name, name);
5762 setString(&ti->name_sorting, name);
5763 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5765 pushTreeInfo(&scores_types, ti);
5768 // sort scores type values to start with lowest scores type value
5769 sortTreeInfo(&scores_types);
5771 // set current scores type value to configured scores type value
5772 scores_type_current =
5773 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5775 // if that fails, set current scores type to reliable default value
5776 if (scores_type_current == NULL)
5777 scores_type_current =
5778 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5780 // if that also fails, set current scores type to first available value
5781 if (scores_type_current == NULL)
5782 scores_type_current = scores_types;
5785 setup.scores_in_highscore_list = scores_type_current->identifier;
5787 // needed for displaying scores type text instead of identifier
5788 scores_type_text = scores_type_current->name;
5791 static void execSetupGame_setGameSpeeds(boolean update_value)
5793 if (setup.game_speed_extended)
5795 game_speeds_list = game_speeds_list_extended;
5796 game_speeds = game_speeds_extended;
5800 game_speeds_list = game_speeds_list_normal;
5801 game_speeds = game_speeds_normal;
5804 if (game_speeds == NULL)
5808 for (i = 0; game_speeds_list[i].value != -1; i++)
5810 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5811 char identifier[32], name[32];
5812 int value = game_speeds_list[i].value;
5813 char *text = game_speeds_list[i].text;
5815 ti->node_top = &game_speeds;
5816 ti->sort_priority = 10000 - value;
5818 sprintf(identifier, "%d", value);
5819 sprintf(name, "%s", text);
5821 setString(&ti->identifier, identifier);
5822 setString(&ti->name, name);
5823 setString(&ti->name_sorting, name);
5824 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5826 pushTreeInfo(&game_speeds, ti);
5829 // sort game speed values to start with slowest game speed
5830 sortTreeInfo(&game_speeds);
5832 update_value = TRUE;
5837 // set current game speed to configured game speed value
5838 game_speed_current =
5839 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5841 // if that fails, set current game speed to reliable default value
5842 if (game_speed_current == NULL)
5843 game_speed_current =
5844 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5846 // if that also fails, set current game speed to first available speed
5847 if (game_speed_current == NULL)
5848 game_speed_current = game_speeds;
5850 if (setup.game_speed_extended)
5851 game_speeds_extended = game_speeds;
5853 game_speeds_normal = game_speeds;
5856 setup.game_frame_delay = atoi(game_speed_current->identifier);
5858 // needed for displaying game speed text instead of identifier
5859 game_speed_text = game_speed_current->name;
5862 static void execSetupGame_setScrollDelays(void)
5864 if (scroll_delays == NULL)
5868 for (i = 0; scroll_delays_list[i].value != -1; i++)
5870 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5871 char identifier[32], name[32];
5872 int value = scroll_delays_list[i].value;
5873 char *text = scroll_delays_list[i].text;
5875 ti->node_top = &scroll_delays;
5876 ti->sort_priority = value;
5878 sprintf(identifier, "%d", value);
5879 sprintf(name, "%s", text);
5881 setString(&ti->identifier, identifier);
5882 setString(&ti->name, name);
5883 setString(&ti->name_sorting, name);
5884 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5886 pushTreeInfo(&scroll_delays, ti);
5889 // sort scroll delay values to start with lowest scroll delay value
5890 sortTreeInfo(&scroll_delays);
5892 // set current scroll delay value to configured scroll delay value
5893 scroll_delay_current =
5894 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5896 // if that fails, set current scroll delay to reliable default value
5897 if (scroll_delay_current == NULL)
5898 scroll_delay_current =
5899 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5901 // if that also fails, set current scroll delay to first available value
5902 if (scroll_delay_current == NULL)
5903 scroll_delay_current = scroll_delays;
5906 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5908 // needed for displaying scroll delay text instead of identifier
5909 scroll_delay_text = scroll_delay_current->name;
5912 static void execSetupGame_setSnapshotModes(void)
5914 if (snapshot_modes == NULL)
5918 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5920 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5921 char identifier[32], name[32];
5922 char *value = snapshot_modes_list[i].value;
5923 char *text = snapshot_modes_list[i].text;
5925 ti->node_top = &snapshot_modes;
5926 ti->sort_priority = i;
5928 sprintf(identifier, "%s", value);
5929 sprintf(name, "%s", text);
5931 setString(&ti->identifier, identifier);
5932 setString(&ti->name, name);
5933 setString(&ti->name_sorting, name);
5934 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5936 pushTreeInfo(&snapshot_modes, ti);
5939 // sort snapshot mode values to start with lowest snapshot mode value
5940 sortTreeInfo(&snapshot_modes);
5942 // set current snapshot mode value to configured snapshot mode value
5943 snapshot_mode_current =
5944 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5946 // if that fails, set current snapshot mode to reliable default value
5947 if (snapshot_mode_current == NULL)
5948 snapshot_mode_current =
5949 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5951 // if that also fails, set current snapshot mode to first available value
5952 if (snapshot_mode_current == NULL)
5953 snapshot_mode_current = snapshot_modes;
5956 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5958 // needed for displaying snapshot mode text instead of identifier
5959 snapshot_mode_text = snapshot_mode_current->name;
5962 static void execSetupGame_setNetworkServerText(void)
5964 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5966 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5970 strncpy(network_server_hostname, setup.network_server_hostname,
5971 MAX_SETUP_TEXT_INPUT_LEN);
5972 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5975 // needed for displaying network server text instead of identifier
5976 network_server_text = network_server_hostname;
5979 static void execSetupGame(void)
5981 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5983 execSetupGame_setGameSpeeds(FALSE);
5984 execSetupGame_setScoresType();
5985 execSetupGame_setScrollDelays();
5986 execSetupGame_setSnapshotModes();
5988 execSetupGame_setNetworkServerText();
5990 if (!setup.provide_uploading_tapes)
5991 setHideSetupEntry(execOfferUploadTapes);
5993 setup_mode = SETUP_MODE_GAME;
5997 // check if vsync needs to be disabled for this game speed to work
5998 if (check_vsync_mode)
5999 DisableVsyncIfNeeded();
6002 static void execSetupChooseScoresType(void)
6004 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6009 static void execSetupChooseGameSpeed(void)
6011 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6016 static void execSetupChooseScrollDelay(void)
6018 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6023 static void execSetupChooseSnapshotMode(void)
6025 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6030 static void execSetupEngines(void)
6032 setup_mode = SETUP_MODE_ENGINES;
6037 static void execSetupEditor(void)
6039 setup_mode = SETUP_MODE_EDITOR;
6044 static void execSetupGraphics_setWindowSizes(boolean update_list)
6046 if (window_sizes != NULL && update_list)
6048 freeTreeInfo(window_sizes);
6050 window_sizes = NULL;
6053 if (window_sizes == NULL)
6055 boolean current_window_size_found = FALSE;
6058 for (i = 0; window_sizes_list[i].value != -1; i++)
6060 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6061 char identifier[32], name[32];
6062 int value = window_sizes_list[i].value;
6063 char *text = window_sizes_list[i].text;
6065 ti->node_top = &window_sizes;
6066 ti->sort_priority = value;
6068 sprintf(identifier, "%d", value);
6069 sprintf(name, "%s", text);
6071 setString(&ti->identifier, identifier);
6072 setString(&ti->name, name);
6073 setString(&ti->name_sorting, name);
6074 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6076 pushTreeInfo(&window_sizes, ti);
6078 if (value == setup.window_scaling_percent)
6079 current_window_size_found = TRUE;
6082 if (!current_window_size_found)
6084 // add entry for non-preset window scaling value
6086 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6087 char identifier[32], name[32];
6088 int value = setup.window_scaling_percent;
6090 ti->node_top = &window_sizes;
6091 ti->sort_priority = value;
6093 sprintf(identifier, "%d", value);
6094 sprintf(name, "%d %% (Current)", value);
6096 setString(&ti->identifier, identifier);
6097 setString(&ti->name, name);
6098 setString(&ti->name_sorting, name);
6099 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6101 pushTreeInfo(&window_sizes, ti);
6104 // sort window size values to start with lowest window size value
6105 sortTreeInfo(&window_sizes);
6107 // set current window size value to configured window size value
6108 window_size_current =
6109 getTreeInfoFromIdentifier(window_sizes,
6110 i_to_a(setup.window_scaling_percent));
6112 // if that fails, set current window size to reliable default value
6113 if (window_size_current == NULL)
6114 window_size_current =
6115 getTreeInfoFromIdentifier(window_sizes,
6116 i_to_a(STD_WINDOW_SCALING_PERCENT));
6118 // if that also fails, set current window size to first available value
6119 if (window_size_current == NULL)
6120 window_size_current = window_sizes;
6123 setup.window_scaling_percent = atoi(window_size_current->identifier);
6125 // needed for displaying window size text instead of identifier
6126 window_size_text = window_size_current->name;
6129 static void execSetupGraphics_setScalingTypes(void)
6131 if (scaling_types == NULL)
6135 for (i = 0; scaling_types_list[i].value != NULL; i++)
6137 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6138 char identifier[32], name[32];
6139 char *value = scaling_types_list[i].value;
6140 char *text = scaling_types_list[i].text;
6142 ti->node_top = &scaling_types;
6143 ti->sort_priority = i;
6145 sprintf(identifier, "%s", value);
6146 sprintf(name, "%s", text);
6148 setString(&ti->identifier, identifier);
6149 setString(&ti->name, name);
6150 setString(&ti->name_sorting, name);
6151 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6153 pushTreeInfo(&scaling_types, ti);
6156 // sort scaling type values to start with lowest scaling type value
6157 sortTreeInfo(&scaling_types);
6159 // set current scaling type value to configured scaling type value
6160 scaling_type_current =
6161 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6163 // if that fails, set current scaling type to reliable default value
6164 if (scaling_type_current == NULL)
6165 scaling_type_current =
6166 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6168 // if that also fails, set current scaling type to first available value
6169 if (scaling_type_current == NULL)
6170 scaling_type_current = scaling_types;
6173 setup.window_scaling_quality = scaling_type_current->identifier;
6175 // needed for displaying scaling type text instead of identifier
6176 scaling_type_text = scaling_type_current->name;
6179 static void execSetupGraphics_setRenderingModes(void)
6181 if (rendering_modes == NULL)
6185 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6187 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6188 char identifier[32], name[32];
6189 char *value = rendering_modes_list[i].value;
6190 char *text = rendering_modes_list[i].text;
6192 ti->node_top = &rendering_modes;
6193 ti->sort_priority = i;
6195 sprintf(identifier, "%s", value);
6196 sprintf(name, "%s", text);
6198 setString(&ti->identifier, identifier);
6199 setString(&ti->name, name);
6200 setString(&ti->name_sorting, name);
6201 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6203 pushTreeInfo(&rendering_modes, ti);
6206 // sort rendering mode values to start with lowest rendering mode value
6207 sortTreeInfo(&rendering_modes);
6209 // set current rendering mode value to configured rendering mode value
6210 rendering_mode_current =
6211 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6213 // if that fails, set current rendering mode to reliable default value
6214 if (rendering_mode_current == NULL)
6215 rendering_mode_current =
6216 getTreeInfoFromIdentifier(rendering_modes,
6217 STR_SPECIAL_RENDERING_DEFAULT);
6219 // if that also fails, set current rendering mode to first available one
6220 if (rendering_mode_current == NULL)
6221 rendering_mode_current = rendering_modes;
6224 setup.screen_rendering_mode = rendering_mode_current->identifier;
6226 // needed for displaying rendering mode text instead of identifier
6227 rendering_mode_text = rendering_mode_current->name;
6230 static void execSetupGraphics_setVsyncModes(boolean update_value)
6232 if (vsync_modes == NULL)
6236 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6238 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6239 char identifier[32], name[32];
6240 char *value = vsync_modes_list[i].value;
6241 char *text = vsync_modes_list[i].text;
6243 ti->node_top = &vsync_modes;
6244 ti->sort_priority = i;
6246 sprintf(identifier, "%s", value);
6247 sprintf(name, "%s", text);
6249 setString(&ti->identifier, identifier);
6250 setString(&ti->name, name);
6251 setString(&ti->name_sorting, name);
6252 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6254 pushTreeInfo(&vsync_modes, ti);
6257 // sort vsync mode values to start with lowest vsync mode value
6258 sortTreeInfo(&vsync_modes);
6260 update_value = TRUE;
6265 // set current vsync mode value to configured vsync mode value
6266 vsync_mode_current =
6267 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6269 // if that fails, set current vsync mode to reliable default value
6270 if (vsync_mode_current == NULL)
6271 vsync_mode_current =
6272 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6274 // if that also fails, set current vsync mode to first available one
6275 if (vsync_mode_current == NULL)
6276 vsync_mode_current = vsync_modes;
6279 setup.vsync_mode = vsync_mode_current->identifier;
6281 // needed for displaying vsync mode text instead of identifier
6282 vsync_mode_text = vsync_mode_current->name;
6285 static void execSetupGraphics(void)
6287 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6289 // update "setup.window_scaling_percent" from list selection
6290 // (in this case, window scaling was changed on setup screen)
6291 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6292 execSetupGraphics_setWindowSizes(FALSE);
6294 // update "setup.vsync_mode" from list selection
6295 // (in this case, vsync mode was changed on setup screen)
6296 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6297 execSetupGraphics_setVsyncModes(FALSE);
6299 // update list selection from "setup.window_scaling_percent"
6300 // (window scaling may have changed by resizing the window)
6301 execSetupGraphics_setWindowSizes(TRUE);
6303 // update list selection from "setup.vsync_mode"
6304 // (vsync_mode may have changed by re-creating the renderer)
6305 execSetupGraphics_setVsyncModes(TRUE);
6307 execSetupGraphics_setScalingTypes();
6308 execSetupGraphics_setRenderingModes();
6310 setup_mode = SETUP_MODE_GRAPHICS;
6314 // check if game speed is high enough for 60 Hz vsync to work
6315 if (check_game_speed)
6316 ModifyGameSpeedIfNeeded();
6318 // window scaling may have changed at this point
6319 ChangeWindowScalingIfNeeded();
6321 // window scaling quality may have changed at this point
6322 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6323 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6325 // screen rendering mode may have changed at this point
6326 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6328 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6329 int video_vsync_mode = video.vsync_mode;
6331 // screen vsync mode may have changed at this point
6332 ChangeVsyncModeIfNeeded();
6334 // check if setting vsync mode to selected value failed
6335 if (setup_vsync_mode != video_vsync_mode &&
6336 setup_vsync_mode != video.vsync_mode)
6338 // changing vsync mode to selected value failed -- reset displayed value
6339 execSetupGraphics_setVsyncModes(TRUE);
6341 Request("Setting VSync failed!", REQ_CONFIRM);
6347 static void execSetupChooseWindowSize(void)
6349 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6354 static void execSetupChooseScalingType(void)
6356 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6361 static void execSetupChooseRenderingMode(void)
6363 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6368 static void execSetupChooseVsyncMode(void)
6370 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6375 static void execSetupChooseVolumeSimple(void)
6377 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6382 static void execSetupChooseVolumeLoops(void)
6384 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6389 static void execSetupChooseVolumeMusic(void)
6391 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6396 static void execSetupSound(void)
6398 if (volumes_simple == NULL)
6400 boolean current_volume_simple_found = FALSE;
6403 for (i = 0; volumes_list[i].value != -1; i++)
6405 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6406 char identifier[32], name[32];
6407 int value = volumes_list[i].value;
6408 char *text = volumes_list[i].text;
6410 ti->node_top = &volumes_simple;
6411 ti->sort_priority = value;
6413 sprintf(identifier, "%d", value);
6414 sprintf(name, "%s", text);
6416 setString(&ti->identifier, identifier);
6417 setString(&ti->name, name);
6418 setString(&ti->name_sorting, name);
6419 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6421 pushTreeInfo(&volumes_simple, ti);
6423 if (value == setup.volume_simple)
6424 current_volume_simple_found = TRUE;
6427 if (!current_volume_simple_found)
6429 // add entry for non-preset volume value
6431 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6432 char identifier[32], name[32];
6433 int value = setup.volume_simple;
6435 ti->node_top = &volumes_simple;
6436 ti->sort_priority = value;
6438 sprintf(identifier, "%d", value);
6439 sprintf(name, "%d %% (Current)", value);
6441 setString(&ti->identifier, identifier);
6442 setString(&ti->name, name);
6443 setString(&ti->name_sorting, name);
6444 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6446 pushTreeInfo(&volumes_simple, ti);
6449 // sort volume values to start with lowest volume value
6450 sortTreeInfo(&volumes_simple);
6452 // set current volume value to configured volume value
6453 volume_simple_current =
6454 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6456 // if that fails, set current volume to reliable default value
6457 if (volume_simple_current == NULL)
6458 volume_simple_current =
6459 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6461 // if that also fails, set current volume to first available value
6462 if (volume_simple_current == NULL)
6463 volume_simple_current = volumes_simple;
6466 if (volumes_loops == NULL)
6468 boolean current_volume_loops_found = FALSE;
6471 for (i = 0; volumes_list[i].value != -1; i++)
6473 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6474 char identifier[32], name[32];
6475 int value = volumes_list[i].value;
6476 char *text = volumes_list[i].text;
6478 ti->node_top = &volumes_loops;
6479 ti->sort_priority = value;
6481 sprintf(identifier, "%d", 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_VOLUME_LOOPS);
6489 pushTreeInfo(&volumes_loops, ti);
6491 if (value == setup.volume_loops)
6492 current_volume_loops_found = TRUE;
6495 if (!current_volume_loops_found)
6497 // add entry for non-preset volume value
6499 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6500 char identifier[32], name[32];
6501 int value = setup.volume_loops;
6503 ti->node_top = &volumes_loops;
6504 ti->sort_priority = value;
6506 sprintf(identifier, "%d", value);
6507 sprintf(name, "%d %% (Current)", value);
6509 setString(&ti->identifier, identifier);
6510 setString(&ti->name, name);
6511 setString(&ti->name_sorting, name);
6512 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6514 pushTreeInfo(&volumes_loops, ti);
6517 // sort volume values to start with lowest volume value
6518 sortTreeInfo(&volumes_loops);
6520 // set current volume value to configured volume value
6521 volume_loops_current =
6522 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6524 // if that fails, set current volume to reliable default value
6525 if (volume_loops_current == NULL)
6526 volume_loops_current =
6527 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6529 // if that also fails, set current volume to first available value
6530 if (volume_loops_current == NULL)
6531 volume_loops_current = volumes_loops;
6534 if (volumes_music == NULL)
6536 boolean current_volume_music_found = FALSE;
6539 for (i = 0; volumes_list[i].value != -1; i++)
6541 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6542 char identifier[32], name[32];
6543 int value = volumes_list[i].value;
6544 char *text = volumes_list[i].text;
6546 ti->node_top = &volumes_music;
6547 ti->sort_priority = value;
6549 sprintf(identifier, "%d", value);
6550 sprintf(name, "%s", text);
6552 setString(&ti->identifier, identifier);
6553 setString(&ti->name, name);
6554 setString(&ti->name_sorting, name);
6555 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6557 pushTreeInfo(&volumes_music, ti);
6559 if (value == setup.volume_music)
6560 current_volume_music_found = TRUE;
6563 if (!current_volume_music_found)
6565 // add entry for non-preset volume value
6567 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6568 char identifier[32], name[32];
6569 int value = setup.volume_music;
6571 ti->node_top = &volumes_music;
6572 ti->sort_priority = value;
6574 sprintf(identifier, "%d", value);
6575 sprintf(name, "%d %% (Current)", value);
6577 setString(&ti->identifier, identifier);
6578 setString(&ti->name, name);
6579 setString(&ti->name_sorting, name);
6580 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6582 pushTreeInfo(&volumes_music, ti);
6585 // sort volume values to start with lowest volume value
6586 sortTreeInfo(&volumes_music);
6588 // set current volume value to configured volume value
6589 volume_music_current =
6590 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6592 // if that fails, set current volume to reliable default value
6593 if (volume_music_current == NULL)
6594 volume_music_current =
6595 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6597 // if that also fails, set current volume to first available value
6598 if (volume_music_current == NULL)
6599 volume_music_current = volumes_music;
6602 setup.volume_simple = atoi(volume_simple_current->identifier);
6603 setup.volume_loops = atoi(volume_loops_current->identifier);
6604 setup.volume_music = atoi(volume_music_current->identifier);
6606 // needed for displaying volume text instead of identifier
6607 volume_simple_text = volume_simple_current->name;
6608 volume_loops_text = volume_loops_current->name;
6609 volume_music_text = volume_music_current->name;
6611 setup_mode = SETUP_MODE_SOUND;
6616 static void execSetupChooseTouchControls(void)
6618 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6623 static void execSetupChooseMoveDistance(void)
6625 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6630 static void execSetupChooseDropDistance(void)
6632 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6637 static void execSetupChooseTransparency(void)
6639 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6644 static void execSetupChooseGridXSize_0(void)
6646 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6651 static void execSetupChooseGridYSize_0(void)
6653 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6658 static void execSetupChooseGridXSize_1(void)
6660 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6665 static void execSetupChooseGridYSize_1(void)
6667 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6672 static void execSetupConfigureVirtualButtons(void)
6674 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6676 ConfigureVirtualButtons();
6678 setup_mode = SETUP_MODE_TOUCH;
6683 static void execSetupTouch(void)
6687 if (touch_controls == NULL)
6689 for (i = 0; touch_controls_list[i].value != NULL; i++)
6691 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6692 char identifier[32], name[32];
6693 char *value = touch_controls_list[i].value;
6694 char *text = touch_controls_list[i].text;
6696 ti->node_top = &touch_controls;
6697 ti->sort_priority = i;
6699 sprintf(identifier, "%s", value);
6700 sprintf(name, "%s", text);
6702 setString(&ti->identifier, identifier);
6703 setString(&ti->name, name);
6704 setString(&ti->name_sorting, name);
6705 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6707 pushTreeInfo(&touch_controls, ti);
6710 // sort touch control values to start with lowest touch control value
6711 sortTreeInfo(&touch_controls);
6713 // set current touch control value to configured touch control value
6714 touch_control_current =
6715 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6717 // if that fails, set current touch control to reliable default value
6718 if (touch_control_current == NULL)
6719 touch_control_current =
6720 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6722 // if that also fails, set current touch control to first available value
6723 if (touch_control_current == NULL)
6724 touch_control_current = touch_controls;
6727 if (move_distances == NULL)
6729 for (i = 0; distances_list[i].value != -1; i++)
6731 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6732 char identifier[32], name[32];
6733 int value = distances_list[i].value;
6734 char *text = distances_list[i].text;
6736 ti->node_top = &move_distances;
6737 ti->sort_priority = value;
6739 sprintf(identifier, "%d", value);
6740 sprintf(name, "%s", text);
6742 setString(&ti->identifier, identifier);
6743 setString(&ti->name, name);
6744 setString(&ti->name_sorting, name);
6745 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6747 pushTreeInfo(&move_distances, ti);
6750 // sort distance values to start with lowest distance value
6751 sortTreeInfo(&move_distances);
6753 // set current distance value to configured distance value
6754 move_distance_current =
6755 getTreeInfoFromIdentifier(move_distances,
6756 i_to_a(setup.touch.move_distance));
6758 // if that fails, set current distance to reliable default value
6759 if (move_distance_current == NULL)
6760 move_distance_current =
6761 getTreeInfoFromIdentifier(move_distances,
6762 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6764 // if that also fails, set current distance to first available value
6765 if (move_distance_current == NULL)
6766 move_distance_current = move_distances;
6769 if (drop_distances == NULL)
6771 for (i = 0; distances_list[i].value != -1; i++)
6773 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6774 char identifier[32], name[32];
6775 int value = distances_list[i].value;
6776 char *text = distances_list[i].text;
6778 ti->node_top = &drop_distances;
6779 ti->sort_priority = value;
6781 sprintf(identifier, "%d", value);
6782 sprintf(name, "%s", text);
6784 setString(&ti->identifier, identifier);
6785 setString(&ti->name, name);
6786 setString(&ti->name_sorting, name);
6787 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6789 pushTreeInfo(&drop_distances, ti);
6792 // sort distance values to start with lowest distance value
6793 sortTreeInfo(&drop_distances);
6795 // set current distance value to configured distance value
6796 drop_distance_current =
6797 getTreeInfoFromIdentifier(drop_distances,
6798 i_to_a(setup.touch.drop_distance));
6800 // if that fails, set current distance to reliable default value
6801 if (drop_distance_current == NULL)
6802 drop_distance_current =
6803 getTreeInfoFromIdentifier(drop_distances,
6804 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6806 // if that also fails, set current distance to first available value
6807 if (drop_distance_current == NULL)
6808 drop_distance_current = drop_distances;
6811 if (transparencies == NULL)
6813 for (i = 0; transparencies_list[i].value != -1; i++)
6815 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6816 char identifier[32], name[32];
6817 int value = transparencies_list[i].value;
6818 char *text = transparencies_list[i].text;
6820 ti->node_top = &transparencies;
6821 ti->sort_priority = value;
6823 sprintf(identifier, "%d", value);
6824 sprintf(name, "%s", text);
6826 setString(&ti->identifier, identifier);
6827 setString(&ti->name, name);
6828 setString(&ti->name_sorting, name);
6829 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6831 pushTreeInfo(&transparencies, ti);
6834 // sort transparency values to start with lowest transparency value
6835 sortTreeInfo(&transparencies);
6837 // set current transparency value to configured transparency value
6838 transparency_current =
6839 getTreeInfoFromIdentifier(transparencies,
6840 i_to_a(setup.touch.transparency));
6842 // if that fails, set current transparency to reliable default value
6843 if (transparency_current == NULL)
6844 transparency_current =
6845 getTreeInfoFromIdentifier(transparencies,
6846 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6848 // if that also fails, set current transparency to first available value
6849 if (transparency_current == NULL)
6850 transparency_current = transparencies;
6853 for (i = 0; i < 2; i++)
6855 for (j = 0; j < 2; j++)
6857 if (grid_sizes[i][j] == NULL)
6859 for (k = 0; grid_sizes_list[k].value != -1; k++)
6861 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6862 char identifier[32], name[32];
6863 int value = grid_sizes_list[k].value;
6864 char *text = grid_sizes_list[k].text;
6866 ti->node_top = &grid_sizes[i][j];
6867 ti->sort_priority = value;
6869 sprintf(identifier, "%d", value);
6870 sprintf(name, "%s", text);
6872 setString(&ti->identifier, identifier);
6873 setString(&ti->name, name);
6874 setString(&ti->name_sorting, name);
6875 setString(&ti->infotext,
6878 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6879 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6881 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6882 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6884 pushTreeInfo(&grid_sizes[i][j], ti);
6887 // sort grid size values to start with lowest grid size value
6888 sortTreeInfo(&grid_sizes[i][j]);
6890 // set current grid size value to configured grid size value
6891 grid_size_current[i][j] =
6892 getTreeInfoFromIdentifier(grid_sizes[i][j],
6894 setup.touch.grid_xsize[i] :
6895 setup.touch.grid_ysize[i]));
6897 // if that fails, set current grid size to reliable default value
6898 if (grid_size_current[i][j] == NULL)
6899 grid_size_current[i][j] =
6900 getTreeInfoFromIdentifier(grid_sizes[i][j],
6902 DEFAULT_GRID_XSIZE(i) :
6903 DEFAULT_GRID_YSIZE(i)));
6905 // if that also fails, set current grid size to first available value
6906 if (grid_size_current[i][j] == NULL)
6907 grid_size_current[i][j] = grid_sizes[i][j];
6912 setup.touch.control_type = touch_control_current->identifier;
6913 setup.touch.move_distance = atoi(move_distance_current->identifier);
6914 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6915 setup.touch.transparency = atoi(transparency_current->identifier);
6917 for (i = 0; i < 2; i++)
6919 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6920 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6922 if (i == GRID_ACTIVE_NR())
6924 overlay.grid_xsize = setup.touch.grid_xsize[i];
6925 overlay.grid_ysize = setup.touch.grid_ysize[i];
6929 // needed for displaying value text instead of identifier
6930 touch_controls_text = touch_control_current->name;
6931 move_distance_text = move_distance_current->name;
6932 drop_distance_text = drop_distance_current->name;
6933 transparency_text = transparency_current->name;
6935 for (i = 0; i < 2; i++)
6936 for (j = 0; j < 2; j++)
6937 grid_size_text[i][j] = grid_size_current[i][j]->name;
6939 setup_mode = SETUP_MODE_TOUCH;
6944 static void execSetupArtwork(void)
6946 static ArtworkDirTree *gfx_last_valid = NULL;
6947 static ArtworkDirTree *snd_last_valid = NULL;
6948 static ArtworkDirTree *mus_last_valid = NULL;
6950 // current artwork directory may be invalid (level group, parent link)
6951 if (!validLevelSeries(artwork.gfx_current))
6952 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6953 if (!validLevelSeries(artwork.snd_current))
6954 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6955 if (!validLevelSeries(artwork.mus_current))
6956 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6958 // store valid artwork directory information
6959 gfx_last_valid = artwork.gfx_current;
6960 snd_last_valid = artwork.snd_current;
6961 mus_last_valid = artwork.mus_current;
6964 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6965 artwork.gfx_current->subdir,
6966 artwork.gfx_current->fullpath,
6967 artwork.gfx_current->basepath);
6970 setup.graphics_set = artwork.gfx_current->identifier;
6971 setup.sounds_set = artwork.snd_current->identifier;
6972 setup.music_set = artwork.mus_current->identifier;
6974 // needed if last screen (setup choice) changed graphics, sounds or music
6975 ReloadCustomArtwork(0);
6977 // needed for displaying artwork name instead of artwork identifier
6978 graphics_set_name = artwork.gfx_current->name;
6979 sounds_set_name = artwork.snd_current->name;
6980 music_set_name = artwork.mus_current->name;
6982 setup_mode = SETUP_MODE_ARTWORK;
6987 static void execSetupChooseGraphics(void)
6989 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6994 static void execSetupChooseSounds(void)
6996 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7001 static void execSetupChooseMusic(void)
7003 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7008 static void execSetupInput(void)
7010 setup_mode = SETUP_MODE_INPUT;
7015 static void execSetupShortcuts(void)
7017 setup_mode = SETUP_MODE_SHORTCUTS;
7022 static void execSetupShortcuts1(void)
7024 setup_mode = SETUP_MODE_SHORTCUTS_1;
7029 static void execSetupShortcuts2(void)
7031 setup_mode = SETUP_MODE_SHORTCUTS_2;
7036 static void execSetupShortcuts3(void)
7038 setup_mode = SETUP_MODE_SHORTCUTS_3;
7043 static void execSetupShortcuts4(void)
7045 setup_mode = SETUP_MODE_SHORTCUTS_4;
7050 static void execSetupShortcuts5(void)
7052 setup_mode = SETUP_MODE_SHORTCUTS_5;
7057 static void execExitSetup(void)
7059 SetGameStatus(GAME_MODE_MAIN);
7064 static void execSaveAndExitSetup(void)
7070 static void execGadgetNetworkServer(void)
7072 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7073 struct GadgetInfo *gi = screen_gadget[gadget_id];
7075 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7076 network_server_hostname[0] = '\0';
7078 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7082 ClickOnGadget(gi, MB_LEFTBUTTON);
7085 static void execOfferUploadTapes(void)
7090 static void ToggleNetworkModeIfNeeded(void)
7092 int font_title = FONT_TITLE_1;
7093 int font_foot = FC_BLUE;
7094 int ystart = mSY - SY + 16;
7095 int ybottom = mSY - SY + SYSIZE - 20;
7096 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7098 if (setup.network_mode == network.enabled)
7101 network.enabled = setup.network_mode;
7103 FadeOut(REDRAW_ALL);
7107 DrawTextSCentered(ystart, font_title, text);
7111 if (network.enabled)
7112 InitNetworkServer();
7114 DisconnectFromNetworkServer();
7116 DrawTextSCentered(ybottom, font_foot,
7117 "Press any key or button for setup menu");
7119 WaitForEventToContinue();
7124 static void ToggleGameSpeedsListIfNeeded(void)
7126 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7128 if (setup.game_speed_extended == using_game_speeds_extended)
7131 // try to match similar values when changing game speeds list
7132 if (setup.game_speed_extended)
7133 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7134 setup.game_frame_delay == 30 ? 29 :
7135 setup.game_frame_delay);
7137 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7138 setup.game_frame_delay == 16 ? 15 :
7139 setup.game_frame_delay >= 29 ? 30 :
7140 setup.game_frame_delay <= 10 ? 10 :
7141 setup.game_frame_delay);
7143 execSetupGame_setGameSpeeds(TRUE);
7148 static void ToggleUseApiServerIfNeeded(void)
7150 if (runtime.use_api_server == setup.use_api_server)
7153 runtime.use_api_server = setup.use_api_server;
7155 if (runtime.use_api_server)
7156 CheckApiServerTasks();
7159 static void ModifyGameSpeedIfNeeded(void)
7161 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7162 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7166 char *game_speed_text = "Fast";
7167 int game_speed_value = 15;
7169 if (setup.game_speed_extended)
7171 game_speed_text = "60 fps";
7172 game_speed_value = 16;
7175 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7177 // set game speed to existing list value that is fast enough for vsync
7178 setup.game_frame_delay = game_speed_value;
7180 execSetupGame_setGameSpeeds(TRUE);
7182 Request(message, REQ_CONFIRM);
7185 static void DisableVsyncIfNeeded(void)
7187 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7188 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7189 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7192 // disable vsync for the selected game speed to work
7193 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7195 execSetupGraphics_setVsyncModes(TRUE);
7197 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7203 void *related_value;
7204 } hide_related_entry_list[] =
7206 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7207 { &setup.scores_in_highscore_list, &scores_type_text },
7209 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7210 { &setup.game_frame_delay, &game_speed_text },
7212 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7213 { &setup.scroll_delay_value, &scroll_delay_text },
7215 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7216 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7218 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7219 { &setup.window_scaling_percent, &window_size_text },
7221 { &setup.window_scaling_quality, execSetupChooseScalingType },
7222 { &setup.window_scaling_quality, &scaling_type_text },
7224 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7225 { &setup.screen_rendering_mode, &rendering_mode_text },
7227 { &setup.vsync_mode, execSetupChooseVsyncMode },
7228 { &setup.vsync_mode, &vsync_mode_text },
7230 { &setup.graphics_set, execSetupChooseGraphics },
7231 { &setup.graphics_set, &graphics_set_name },
7233 { &setup.sounds_set, execSetupChooseSounds },
7234 { &setup.sounds_set, &sounds_set_name },
7236 { &setup.music_set, execSetupChooseMusic },
7237 { &setup.music_set, &music_set_name },
7239 { &setup.volume_simple, execSetupChooseVolumeSimple },
7240 { &setup.volume_simple, &volume_simple_text },
7242 { &setup.volume_loops, execSetupChooseVolumeLoops },
7243 { &setup.volume_loops, &volume_loops_text },
7245 { &setup.volume_music, execSetupChooseVolumeMusic },
7246 { &setup.volume_music, &volume_music_text },
7248 { &setup.touch.control_type, execSetupChooseTouchControls },
7249 { &setup.touch.control_type, &touch_controls_text },
7251 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7252 { &setup.touch.move_distance, &move_distance_text },
7254 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7255 { &setup.touch.drop_distance, &drop_distance_text },
7257 { &setup.touch.transparency, execSetupChooseTransparency },
7258 { &setup.touch.transparency, &transparency_text },
7260 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7261 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7263 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7264 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7266 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7267 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7269 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7270 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7272 { &setup.internal.menu_game, execSetupGame },
7273 { &setup.internal.menu_engines, execSetupEngines },
7274 { &setup.internal.menu_editor, execSetupEditor },
7275 { &setup.internal.menu_graphics, execSetupGraphics },
7276 { &setup.internal.menu_sound, execSetupSound },
7277 { &setup.internal.menu_artwork, execSetupArtwork },
7278 { &setup.internal.menu_input, execSetupInput },
7279 { &setup.internal.menu_touch, execSetupTouch },
7280 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7281 { &setup.internal.menu_exit, execExitSetup },
7282 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7287 void setHideRelatedSetupEntries(void)
7291 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7292 if (hideSetupEntry(hide_related_entry_list[i].value))
7293 setHideSetupEntry(hide_related_entry_list[i].related_value);
7296 static struct TokenInfo setup_info_main[] =
7298 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7299 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7300 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7301 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7302 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7303 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7304 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7305 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7306 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7307 { TYPE_EMPTY, NULL, "" },
7308 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7309 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7314 static struct TokenInfo setup_info_game[] =
7316 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7317 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7318 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7319 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7320 { TYPE_STRING, &network_server_text, "" },
7321 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7322 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7323 { TYPE_STRING, &scores_type_text, "" },
7324 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7325 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7326 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7327 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7328 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7329 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7330 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7331 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7332 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7333 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7334 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7335 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7336 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7337 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7338 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7339 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7340 { TYPE_STRING, &game_speed_text, "" },
7341 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7343 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7344 { TYPE_STRING, &scroll_delay_text, "" },
7346 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7347 { TYPE_STRING, &snapshot_mode_text, "" },
7348 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7349 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7350 { TYPE_EMPTY, NULL, "" },
7351 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7356 static struct TokenInfo setup_info_engines[] =
7358 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7359 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7360 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7361 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7362 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7363 { TYPE_EMPTY, NULL, "" },
7364 { TYPE_HEADLINE, NULL, "Supaplex" },
7365 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7366 { TYPE_EMPTY, NULL, "" },
7367 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7372 static struct TokenInfo setup_info_editor[] =
7375 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7376 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7377 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7378 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7379 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7380 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7381 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7382 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7383 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7384 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7386 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7387 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7389 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7391 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7392 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7393 { TYPE_EMPTY, NULL, "" },
7395 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7396 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7397 { TYPE_EMPTY, NULL, "" },
7399 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7400 { TYPE_EMPTY, NULL, "" },
7401 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7402 { TYPE_EMPTY, NULL, "" },
7403 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7408 static struct TokenInfo setup_info_graphics[] =
7410 #if !defined(PLATFORM_ANDROID)
7411 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7412 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7413 { TYPE_STRING, &window_size_text, "" },
7414 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7415 { TYPE_STRING, &scaling_type_text, "" },
7416 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7417 { TYPE_STRING, &rendering_mode_text, "" },
7420 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7421 { TYPE_STRING, &scroll_delay_text, "" },
7423 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7424 { TYPE_STRING, &vsync_mode_text, "" },
7425 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7426 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7427 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7428 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7429 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7430 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7431 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7432 { TYPE_EMPTY, NULL, "" },
7433 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7438 static struct TokenInfo setup_info_sound[] =
7440 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7441 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7442 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7443 { TYPE_EMPTY, NULL, "" },
7444 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7445 { TYPE_STRING, &volume_simple_text, "" },
7446 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7447 { TYPE_STRING, &volume_loops_text, "" },
7448 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7449 { TYPE_STRING, &volume_music_text, "" },
7450 { TYPE_EMPTY, NULL, "" },
7451 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7456 static struct TokenInfo setup_info_artwork[] =
7458 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7459 { TYPE_STRING, &graphics_set_name, "" },
7460 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7461 { TYPE_STRING, &sounds_set_name, "" },
7462 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7463 { TYPE_STRING, &music_set_name, "" },
7464 { TYPE_EMPTY, NULL, "" },
7465 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7466 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7467 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7468 { TYPE_EMPTY, NULL, "" },
7469 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7474 static struct TokenInfo setup_info_input[] =
7476 { TYPE_SWITCH, NULL, "Player:" },
7477 { TYPE_SWITCH, NULL, "Device:" },
7478 { TYPE_SWITCH, NULL, "" },
7479 { TYPE_SKIPPABLE, NULL, "" },
7480 { TYPE_EMPTY, NULL, "" },
7481 { TYPE_EMPTY, NULL, "" },
7482 { TYPE_EMPTY, NULL, "" },
7483 { TYPE_EMPTY, NULL, "" },
7484 { TYPE_EMPTY, NULL, "" },
7485 { TYPE_EMPTY, NULL, "" },
7486 { TYPE_EMPTY, NULL, "" },
7487 { TYPE_EMPTY, NULL, "" },
7488 { TYPE_SKIPPABLE, NULL, "" },
7489 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7494 static struct TokenInfo setup_info_touch[] =
7496 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7497 { TYPE_STRING, &touch_controls_text, "" },
7498 { TYPE_EMPTY, NULL, "" },
7499 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7504 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7506 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7507 { TYPE_STRING, &touch_controls_text, "" },
7508 { TYPE_EMPTY, NULL, "" },
7509 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7510 { TYPE_STRING, &grid_size_text[0][0], "" },
7511 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7512 { TYPE_STRING, &grid_size_text[0][1], "" },
7513 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7514 { TYPE_STRING, &transparency_text, "" },
7515 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7516 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7517 { TYPE_EMPTY, NULL, "" },
7518 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7519 { TYPE_EMPTY, NULL, "" },
7520 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7525 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7527 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7528 { TYPE_STRING, &touch_controls_text, "" },
7529 { TYPE_EMPTY, NULL, "" },
7530 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7531 { TYPE_STRING, &grid_size_text[1][0], "" },
7532 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7533 { TYPE_STRING, &grid_size_text[1][1], "" },
7534 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7535 { TYPE_STRING, &transparency_text, "" },
7536 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7537 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7538 { TYPE_EMPTY, NULL, "" },
7539 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7540 { TYPE_EMPTY, NULL, "" },
7541 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7546 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7548 setup_info_touch_virtual_buttons_0,
7549 setup_info_touch_virtual_buttons_1
7552 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7554 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7555 { TYPE_STRING, &touch_controls_text, "" },
7556 { TYPE_EMPTY, NULL, "" },
7557 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7558 { TYPE_STRING, &move_distance_text, "" },
7559 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7560 { TYPE_STRING, &drop_distance_text, "" },
7561 { TYPE_EMPTY, NULL, "" },
7562 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7567 static struct TokenInfo setup_info_shortcuts[] =
7569 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7570 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7571 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7572 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7573 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7574 { TYPE_EMPTY, NULL, "" },
7575 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7580 static struct TokenInfo setup_info_shortcuts_1[] =
7582 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7583 { TYPE_KEY, &setup.shortcut.save_game, "" },
7584 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7585 { TYPE_KEY, &setup.shortcut.load_game, "" },
7586 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7587 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7588 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7589 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7590 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7591 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7592 { TYPE_EMPTY, NULL, "" },
7593 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7594 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7595 { TYPE_EMPTY, NULL, "" },
7596 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7601 static struct TokenInfo setup_info_shortcuts_2[] =
7603 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7604 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7605 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7606 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7607 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7608 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7609 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7610 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7611 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7612 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7613 { TYPE_EMPTY, NULL, "" },
7614 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7619 static struct TokenInfo setup_info_shortcuts_3[] =
7621 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7622 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7623 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7624 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7625 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7626 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7627 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7628 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7629 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7630 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7631 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7632 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7633 { TYPE_EMPTY, NULL, "" },
7634 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7639 static struct TokenInfo setup_info_shortcuts_4[] =
7641 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7642 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7643 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7644 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7645 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7646 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7647 { TYPE_EMPTY, NULL, "" },
7648 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7653 static struct TokenInfo setup_info_shortcuts_5[] =
7655 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7656 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7657 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7658 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7659 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7660 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7661 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7662 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7663 { TYPE_EMPTY, NULL, "" },
7664 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7669 static Key getSetupKey(void)
7671 Key key = KSYM_UNDEFINED;
7672 boolean got_key_event = FALSE;
7674 while (!got_key_event)
7678 if (NextValidEvent(&event))
7682 case EVENT_KEYPRESS:
7684 key = GetEventKey((KeyEvent *)&event, TRUE);
7686 // press 'Escape' or 'Enter' to keep the existing key binding
7687 if (key == KSYM_Escape || key == KSYM_Return)
7688 key = KSYM_UNDEFINED; // keep old value
7690 got_key_event = TRUE;
7694 case EVENT_KEYRELEASE:
7695 key_joystick_mapping = 0;
7699 HandleOtherEvents(&event);
7710 static int getSetupValueFont(int type, void *value)
7712 if (type & TYPE_GHOSTED)
7713 return FONT_OPTION_OFF;
7714 else if (type & TYPE_KEY)
7715 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7716 else if (type & TYPE_STRING)
7717 return FONT_VALUE_2;
7718 else if (type & TYPE_ECS_AGA)
7719 return FONT_VALUE_1;
7720 else if (type & TYPE_BOOLEAN_STYLE)
7721 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7722 else if (type & TYPE_YES_NO_AUTO)
7723 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7724 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7725 else if (type & TYPE_PLAYER)
7726 return FONT_VALUE_1;
7728 return FONT_VALUE_1;
7731 static int getSetupValueFontNarrow(int type, int font_nr)
7733 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7734 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7735 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7739 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7741 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7742 struct TokenInfo *si = &setup_info[si_pos];
7743 boolean font_draw_xoffset_modified = FALSE;
7744 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7745 int font_draw_xoffset_old = -1;
7746 int xoffset = (scrollbar_needed ? -1 : 0);
7747 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7748 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7749 int xpos = menu_screen_value_xpos;
7750 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7751 int startx = mSX + xpos * 32;
7752 int starty = mSY + ypos * 32;
7753 int type = si->type;
7754 void *value = si->value;
7755 char *value_string = getSetupValue(type, value);
7756 int font_nr_default = getSetupValueFont(type, value);
7757 int font_width_default = getFontWidth(font_nr_default);
7758 int font_nr = font_nr_default;
7761 if (value_string == NULL)
7764 if (type & TYPE_KEY)
7766 xpos = MENU_SCREEN_START_XPOS;
7768 if (type & TYPE_QUERY)
7769 value_string = "<press key>";
7771 else if (type & TYPE_STRING)
7773 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7775 xpos = MENU_SCREEN_START_XPOS;
7777 if (strlen(value_string) > max_value_len)
7778 value_string[max_value_len] = '\0';
7780 else if (type & TYPE_YES_NO_AUTO)
7782 xpos = menu_screen_value_xpos - 1;
7784 else if (type & TYPE_PLAYER)
7786 int displayed_player_nr = *(int *)value + 1;
7788 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7791 startx = mSX + xpos * 32;
7792 starty = mSY + ypos * 32;
7794 // special check if right-side setup values moved left due to scrollbar
7795 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7797 int max_menu_text_length = 26; // maximum text length for classic menu
7798 int font_xoffset = getFontDrawOffsetX(font_nr);
7799 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7800 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7801 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7802 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7804 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7806 // when using narrow font, left-shifting text "auto" not needed
7807 if (type & TYPE_YES_NO_AUTO)
7811 startx = mSX + xpos * 32;
7813 font_nr = getSetupValueFontNarrow(type, font_nr);
7817 // downward compatibility correction for Juergen Bonhagen's menu settings
7818 if (setup_mode != SETUP_MODE_INPUT)
7820 int max_menu_text_length_big = (menu_screen_value_xpos -
7821 MENU_SCREEN_START_XPOS);
7822 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7823 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7824 int font1_xoffset = getFontDrawOffsetX(font_nr);
7825 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7826 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7827 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7828 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7829 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7830 boolean correct_font_draw_xoffset = FALSE;
7832 if (xpos == MENU_SCREEN_START_XPOS &&
7833 startx + font1_xoffset < text_startx + text_font_xoffset)
7834 correct_font_draw_xoffset = TRUE;
7836 if (xpos == menu_screen_value_xpos &&
7837 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7838 correct_font_draw_xoffset = TRUE;
7840 // check if setup value would overlap with setup text when printed
7841 // (this can happen for extreme/wrong values for font draw offset)
7842 if (correct_font_draw_xoffset)
7844 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7845 font_draw_xoffset_modified = TRUE;
7847 if (type & TYPE_KEY)
7848 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7849 else if (!(type & TYPE_STRING))
7850 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7851 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7855 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7856 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7858 DrawText(startx, starty, value_string, font_nr);
7860 if (type & TYPE_PLAYER)
7862 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7863 int player_nr = *(int *)value;
7864 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7865 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7866 int startx2 = startx + xoff;
7867 int starty2 = starty + yoff;
7869 if (DrawingOnBackground(startx2, starty2))
7870 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7872 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7873 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7876 if (font_draw_xoffset_modified)
7877 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7880 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7882 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7883 struct TokenInfo *si = &setup_info[si_pos];
7885 if (si->type & TYPE_BOOLEAN_STYLE)
7887 *(boolean *)si->value ^= TRUE;
7889 else if (si->type & TYPE_YES_NO_AUTO)
7893 (*(int *)si->value == AUTO ? TRUE :
7894 *(int *)si->value == TRUE ? FALSE : AUTO) :
7895 (*(int *)si->value == TRUE ? AUTO :
7896 *(int *)si->value == AUTO ? FALSE : TRUE));
7898 else if (si->type & TYPE_KEY)
7902 si->type |= TYPE_QUERY;
7903 drawSetupValue(screen_pos, setup_info_pos_raw);
7904 si->type &= ~TYPE_QUERY;
7906 key = getSetupKey();
7907 if (key != KSYM_UNDEFINED)
7908 *(Key *)si->value = key;
7910 else if (si->type & TYPE_PLAYER)
7912 int player_nr = *(int *)si->value;
7917 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7919 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7922 drawSetupValue(screen_pos, setup_info_pos_raw);
7924 // fullscreen state may have changed at this point
7925 if (si->value == &setup.fullscreen)
7926 ToggleFullscreenIfNeeded();
7928 // network mode may have changed at this point
7929 if (si->value == &setup.network_mode)
7930 ToggleNetworkModeIfNeeded();
7932 // API server mode may have changed at this point
7933 if (si->value == &setup.use_api_server)
7934 ToggleUseApiServerIfNeeded();
7936 // game speed list may have changed at this point
7937 if (si->value == &setup.game_speed_extended)
7938 ToggleGameSpeedsListIfNeeded();
7941 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7943 static struct TokenInfo *setup_info_final = NULL;
7948 // determine maximum list size of target list
7949 while (setup_info_orig[list_size++].type != 0);
7951 // free, allocate and clear memory for target list
7952 checked_free(setup_info_final);
7953 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7955 // copy setup info list without setup entries marked as hidden
7956 for (i = 0; setup_info_orig[i].type != 0; i++)
7958 // skip setup entries configured to be hidden
7959 if (hideSetupEntry(setup_info_orig[i].value))
7962 // skip skippable setup entries if screen is lower than usual
7963 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7964 setup_info_orig[i].type == TYPE_SKIPPABLE)
7967 setup_info_final[list_pos++] = setup_info_orig[i];
7970 return setup_info_final;
7973 static void DrawSetupScreen_Generic(void)
7975 int fade_mask = REDRAW_FIELD;
7976 boolean redraw_all = FALSE;
7977 char *title_string = NULL;
7981 fade_mask = REDRAW_ALL;
7984 FadeMenuSoundsAndMusic();
7986 FreeScreenGadgets();
7987 CreateScreenGadgets();
7989 if (redraw_mask & REDRAW_ALL)
7994 // needed if different viewport properties defined for setup screen
7995 ChangeViewportPropertiesIfNeeded();
7997 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8001 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8003 if (setup_mode == SETUP_MODE_MAIN)
8005 setup_info = setup_info_main;
8006 title_string = STR_SETUP_MAIN;
8008 else if (setup_mode == SETUP_MODE_GAME)
8010 setup_info = setup_info_game;
8011 title_string = STR_SETUP_GAME;
8013 else if (setup_mode == SETUP_MODE_ENGINES)
8015 setup_info = setup_info_engines;
8016 title_string = STR_SETUP_ENGINES;
8018 else if (setup_mode == SETUP_MODE_EDITOR)
8020 setup_info = setup_info_editor;
8021 title_string = STR_SETUP_EDITOR;
8023 else if (setup_mode == SETUP_MODE_GRAPHICS)
8025 setup_info = setup_info_graphics;
8026 title_string = STR_SETUP_GRAPHICS;
8028 else if (setup_mode == SETUP_MODE_SOUND)
8030 setup_info = setup_info_sound;
8031 title_string = STR_SETUP_SOUND;
8033 else if (setup_mode == SETUP_MODE_ARTWORK)
8035 setup_info = setup_info_artwork;
8036 title_string = STR_SETUP_ARTWORK;
8038 else if (setup_mode == SETUP_MODE_TOUCH)
8040 setup_info = setup_info_touch;
8041 title_string = STR_SETUP_TOUCH;
8043 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8044 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8045 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8046 setup_info = setup_info_touch_wipe_gestures;
8048 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8050 setup_info = setup_info_shortcuts;
8051 title_string = STR_SETUP_SHORTCUTS;
8053 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8055 setup_info = setup_info_shortcuts_1;
8056 title_string = STR_SETUP_SHORTCUTS;
8058 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8060 setup_info = setup_info_shortcuts_2;
8061 title_string = STR_SETUP_SHORTCUTS;
8063 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8065 setup_info = setup_info_shortcuts_3;
8066 title_string = STR_SETUP_SHORTCUTS;
8068 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8070 setup_info = setup_info_shortcuts_4;
8071 title_string = STR_SETUP_SHORTCUTS;
8073 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8075 setup_info = setup_info_shortcuts_5;
8076 title_string = STR_SETUP_SHORTCUTS;
8079 // use modified setup info without setup entries marked as hidden
8080 setup_info = getSetupInfoFinal(setup_info);
8082 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8084 // determine maximal number of setup entries that can be displayed on screen
8086 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8089 // determine maximal number of setup entries available for this setup screen
8091 for (i = 0; setup_info[i].type != 0; i++)
8094 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8096 MapScreenGadgets(max_setup_info);
8099 redraw_mask = fade_mask = REDRAW_ALL;
8101 DrawMaskedBorder(fade_mask);
8106 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8108 menu_info = setup_info;
8110 HandleMenuScreen(mx, my, dx, dy, button,
8111 setup_mode, num_setup_info, max_setup_info);
8114 static void DrawSetupScreen_Input(void)
8118 FadeOut(REDRAW_FIELD);
8122 setup_info = getSetupInfoFinal(setup_info_input);
8124 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8126 for (i = 0; setup_info[i].type != 0; i++)
8128 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8129 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8130 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8131 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8132 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8133 initCursor(i, IMG_MENU_BUTTON);
8135 DrawCursorAndText_Setup(i, -1, FALSE);
8138 // create gadgets for setup input menu screen
8139 FreeScreenGadgets();
8140 CreateScreenGadgets();
8142 // map gadgets for setup input menu screen
8143 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8145 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8147 FadeIn(REDRAW_FIELD);
8150 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8152 if (device_name == NULL)
8155 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8158 if (strlen(device_name) > 1)
8160 char c1 = device_name[strlen(device_name) - 1];
8161 char c2 = device_name[strlen(device_name) - 2];
8163 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8164 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8167 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8168 strlen(device_name));
8171 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8174 static struct SetupKeyboardInfo custom_key;
8181 { &custom_key.left, "Axis/Pad Left" },
8182 { &custom_key.right, "Axis/Pad Right" },
8183 { &custom_key.up, "Axis/Pad Up" },
8184 { &custom_key.down, "Axis/Pad Down" },
8185 { &custom_key.snap, "Button 1/A/X" },
8186 { &custom_key.drop, "Button 2/B/Y" }
8188 static char *joystick_name[MAX_PLAYERS] =
8195 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8196 int font_nr_info = FONT_MENU_1;
8197 int font_nr_name = FONT_VALUE_OLD;
8198 int font_nr_on = FONT_VALUE_1;
8199 int font_nr_off = FONT_VALUE_OLD;
8202 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8204 font_nr_info = FONT_MENU_2;
8205 font_nr_on = FONT_VALUE_NARROW;
8206 font_nr_off = FONT_VALUE_OLD_NARROW;
8209 custom_key = setup.input[player_nr].key;
8211 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8212 FONT_INPUT_1_ACTIVE);
8214 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8216 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8217 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8219 if (setup.input[player_nr].use_joystick)
8221 char *device_name = setup.input[player_nr].joy.device_name;
8222 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8223 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8224 char *text = joystick_name[joystick_nr];
8225 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8227 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8228 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8232 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8233 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8236 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8237 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8241 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8242 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8243 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8244 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8246 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8247 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8248 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8249 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8250 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8251 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8253 for (i = 0; i < 6; i++)
8255 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8257 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8259 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8260 (setup.input[player_nr].use_joystick ?
8262 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8266 static int input_player_nr = 0;
8268 static void HandleSetupScreen_Input_Player(int step, int direction)
8270 int old_player_nr = input_player_nr;
8273 new_player_nr = old_player_nr + step * direction;
8274 if (new_player_nr < 0)
8276 if (new_player_nr > MAX_PLAYERS - 1)
8277 new_player_nr = MAX_PLAYERS - 1;
8279 if (new_player_nr != old_player_nr)
8281 input_player_nr = new_player_nr;
8283 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8287 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8289 static int choice = 0;
8292 int pos_start = SETUPINPUT_SCREEN_POS_START;
8293 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8294 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8295 int pos_end = SETUPINPUT_SCREEN_POS_END;
8297 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8301 for (i = 0; setup_info_input[i].type != 0; i++)
8303 // adjust menu structure according to skipped setup entries
8304 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8312 if (button == MB_MENU_INITIALIZE)
8314 // input setup menu may have changed size due to graphics configuration
8315 if (choice >= pos_empty1)
8318 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8320 DrawCursorAndText_Setup(choice, -1, TRUE);
8324 else if (button == MB_MENU_LEAVE)
8326 setup_mode = SETUP_MODE_MAIN;
8333 if (mx || my) // mouse input
8335 x = (mx - mSX) / 32;
8336 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8338 else if (dx || dy) // keyboard input
8340 if (dx && choice == 0)
8341 x = (dx < 0 ? 10 : 12);
8342 else if ((dx && choice == 1) ||
8343 (dx == -1 && choice == pos_end))
8344 button = MB_MENU_CHOICE;
8348 if (y >= pos_empty1 && y <= pos_empty2)
8349 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8352 if (y == 0 && dx != 0 && button)
8354 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8356 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8357 y >= pos_start && y <= pos_end &&
8358 !(y >= pos_empty1 && y <= pos_empty2))
8364 DrawCursorAndText_Setup(choice, -1, FALSE);
8365 DrawCursorAndText_Setup(y, -1, TRUE);
8367 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8376 char *device_name = setup.input[input_player_nr].joy.device_name;
8378 if (!setup.input[input_player_nr].use_joystick)
8380 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8382 setJoystickDeviceToNr(device_name, new_device_nr);
8383 setup.input[input_player_nr].use_joystick = TRUE;
8387 int device_nr = getJoystickNrFromDeviceName(device_name);
8388 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8390 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8391 setup.input[input_player_nr].use_joystick = FALSE;
8393 setJoystickDeviceToNr(device_name, new_device_nr);
8396 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8400 if (setup.input[input_player_nr].use_joystick)
8401 ConfigureJoystick(input_player_nr);
8403 CustomizeKeyboard(input_player_nr);
8405 else if (y == pos_end)
8411 setup_mode = SETUP_MODE_MAIN;
8418 static boolean CustomizeKeyboardMain(int player_nr)
8422 boolean finished = FALSE;
8423 static struct SetupKeyboardInfo custom_key;
8428 } customize_step[] =
8430 { &custom_key.left, "Move Left" },
8431 { &custom_key.right, "Move Right" },
8432 { &custom_key.up, "Move Up" },
8433 { &custom_key.down, "Move Down" },
8434 { &custom_key.snap, "Snap Field" },
8435 { &custom_key.drop, "Drop Element" }
8437 int font_nr_old = FONT_VALUE_OLD;
8438 int font_nr_new = FONT_VALUE_1;
8439 boolean success = FALSE;
8441 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8443 font_nr_old = FONT_VALUE_OLD_NARROW;
8444 font_nr_new = FONT_VALUE_NARROW;
8447 // read existing key bindings from player setup
8448 custom_key = setup.input[player_nr].key;
8451 FadeOut(REDRAW_FIELD);
8455 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8458 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8459 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8460 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8461 "Key:", FONT_INPUT_1_ACTIVE);
8462 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8463 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8465 FadeIn(REDRAW_FIELD);
8471 if (NextValidEvent(&event))
8475 case EVENT_KEYPRESS:
8477 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8479 // press 'Escape' to abort and keep the old key bindings
8480 if (key == KSYM_Escape)
8482 FadeSkipNextFadeIn();
8489 // press 'Enter' to keep the existing key binding
8490 if (key == KSYM_Return)
8491 key = *customize_step[step_nr].key;
8493 // check if key already used
8494 for (i = 0; i < step_nr; i++)
8495 if (*customize_step[i].key == key)
8500 // got new key binding
8501 *customize_step[step_nr].key = key;
8502 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8504 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8505 getKeyNameFromKey(key), font_nr_new);
8508 // un-highlight last query
8509 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8510 customize_step[step_nr - 1].text, FONT_MENU_1);
8511 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8512 "Key:", FONT_MENU_1);
8514 // all keys configured
8523 // query next key binding
8524 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8525 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8526 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8527 "Key:", FONT_INPUT_1_ACTIVE);
8528 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8529 getKeyNameFromKey(*customize_step[step_nr].key),
8534 case EVENT_KEYRELEASE:
8535 key_joystick_mapping = 0;
8539 HandleOtherEvents(&event);
8547 // write new key bindings back to player setup, if successfully finished
8549 setup.input[player_nr].key = custom_key;
8554 void CustomizeKeyboard(int player_nr)
8556 boolean success = CustomizeKeyboardMain(player_nr);
8560 int font_nr = FONT_TITLE_1;
8561 int font_height = getFontHeight(font_nr);
8562 int ypos1 = SYSIZE / 2 - font_height * 2;
8563 int ypos2 = SYSIZE / 2 - font_height * 1;
8564 unsigned int wait_frame_delay = 0;
8565 unsigned int wait_frame_delay_value = 2000;
8567 ResetDelayCounter(&wait_frame_delay);
8571 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8572 DrawTextSCentered(ypos2, font_nr, "configured!");
8574 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8580 DrawSetupScreen_Input();
8583 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8585 #define MARKER_BUTTON 1
8586 #define MARKER_AXIS_X 2
8587 #define MARKER_AXIS_Y 3
8589 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8591 static boolean bitmaps_initialized = FALSE;
8592 boolean screen_initialized = FALSE;
8593 static Bitmap *controller, *button, *axis_x, *axis_y;
8595 boolean success = TRUE;
8596 boolean done = FALSE, next = FALSE;
8598 int alpha = 200, alpha_step = -1;
8599 int alpha_ticks = 0;
8600 char mapping[4096], temp[256];
8601 int font_name = MENU_SETUP_FONT_TITLE;
8602 int font_info = MENU_SETUP_FONT_TEXT;
8603 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8604 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8605 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8606 int ystep_name = getMenuTextStep(spacing_name, font_name);
8607 int ystep_line = getMenuTextStep(spacing_line, font_info);
8608 int ystep_para = getMenuTextStep(spacing_para, font_info);
8616 int axis, button, hat, hat_value;
8619 *step, *prev_step, steps[] =
8621 { 356, 155, MARKER_BUTTON, "a", },
8622 { 396, 122, MARKER_BUTTON, "b", },
8623 { 320, 125, MARKER_BUTTON, "x", },
8624 { 358, 95, MARKER_BUTTON, "y", },
8625 { 162, 125, MARKER_BUTTON, "back", },
8626 { 216, 125, MARKER_BUTTON, "guide", },
8627 { 271, 125, MARKER_BUTTON, "start", },
8628 { 110, 200, MARKER_BUTTON, "dpleft", },
8629 { 146, 228, MARKER_BUTTON, "dpdown", },
8630 { 178, 200, MARKER_BUTTON, "dpright", },
8631 { 146, 172, MARKER_BUTTON, "dpup", },
8632 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8633 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8634 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8635 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8636 { 73, 141, MARKER_BUTTON, "leftstick", },
8637 { 282, 210, MARKER_BUTTON, "rightstick", },
8638 { 73, 141, MARKER_AXIS_X, "leftx", },
8639 { 73, 141, MARKER_AXIS_Y, "lefty", },
8640 { 282, 210, MARKER_AXIS_X, "rightx", },
8641 { 282, 210, MARKER_AXIS_Y, "righty", },
8644 unsigned int event_frame_delay = 0;
8645 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8647 ResetDelayCounter(&event_frame_delay);
8649 if (!bitmaps_initialized)
8651 controller = LoadCustomImage("joystick/controller.png");
8652 button = LoadCustomImage("joystick/button.png");
8653 axis_x = LoadCustomImage("joystick/axis_x.png");
8654 axis_y = LoadCustomImage("joystick/axis_y.png");
8656 bitmaps_initialized = TRUE;
8659 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8662 // print info about the joystick we are watching
8663 Debug("joystick", "watching joystick %d: (%s)",
8664 SDL_JoystickInstanceID(joystick), name);
8665 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8666 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8667 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8670 // initialize mapping with GUID and name
8671 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8673 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8674 temp, name, SDL_GetPlatform());
8676 // loop through all steps (buttons and axes), getting joystick events
8677 for (i = 0; i < SDL_arraysize(steps) && !done;)
8679 Bitmap *marker = button; // initialize with reliable default value
8682 strcpy(step->mapping, mapping);
8686 step->hat_value = -1;
8688 marker = (step->marker == MARKER_BUTTON ? button :
8689 step->marker == MARKER_AXIS_X ? axis_x :
8690 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8694 while (!done && !next)
8696 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8697 alpha_ticks = SDL_GetTicks();
8704 else if (alpha < 128)
8710 int controller_x = SX + (SXSIZE - controller->width) / 2;
8711 int controller_y = SY + ystep_line;
8713 int marker_x = controller_x + step->x;
8714 int marker_y = controller_y + step->y;
8716 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8717 int ystart2 = ystart1 + ystep_name + ystep_line;
8721 DrawTextSCentered(ystart1, font_name, name);
8723 DrawTextSCentered(ystart2, font_info,
8724 "Press buttons and move axes on");
8725 ystart2 += ystep_line;
8726 DrawTextSCentered(ystart2, font_info,
8727 "your controller when indicated.");
8728 ystart2 += ystep_line;
8729 DrawTextSCentered(ystart2, font_info,
8730 "(Your controller may look different.)");
8731 ystart2 += ystep_para;
8733 #if defined(PLATFORM_ANDROID)
8734 DrawTextSCentered(ystart2, font_info,
8735 "To correct a mistake,");
8736 ystart2 += ystep_line;
8737 DrawTextSCentered(ystart2, font_info,
8738 "press the 'back' button.");
8739 ystart2 += ystep_line;
8740 DrawTextSCentered(ystart2, font_info,
8741 "To skip a button or axis,");
8742 ystart2 += ystep_line;
8743 DrawTextSCentered(ystart2, font_info,
8744 "press the 'menu' button.");
8746 DrawTextSCentered(ystart2, font_info,
8747 "To correct a mistake,");
8748 ystart2 += ystep_line;
8749 DrawTextSCentered(ystart2, font_info,
8750 "press the 'backspace' key.");
8751 ystart2 += ystep_line;
8752 DrawTextSCentered(ystart2, font_info,
8753 "To skip a button or axis,");
8754 ystart2 += ystep_line;
8755 DrawTextSCentered(ystart2, font_info,
8756 "press the 'return' key.");
8757 ystart2 += ystep_line;
8758 DrawTextSCentered(ystart2, font_info,
8759 "To exit, press the 'escape' key.");
8762 BlitBitmapMasked(controller, drawto, 0, 0,
8763 controller->width, controller->height,
8764 controller_x, controller_y);
8766 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8767 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8769 BlitBitmapMasked(marker, drawto, 0, 0,
8770 marker->width, marker->height,
8771 marker_x, marker_y);
8773 if (!screen_initialized)
8774 FadeIn(REDRAW_FIELD);
8778 screen_initialized = TRUE;
8780 while (NextValidEvent(&event))
8784 case SDL_JOYAXISMOTION:
8785 if (event.jaxis.value > 20000 ||
8786 event.jaxis.value < -20000)
8788 for (j = 0; j < i; j++)
8789 if (steps[j].axis == event.jaxis.axis)
8794 if (step->marker != MARKER_AXIS_X &&
8795 step->marker != MARKER_AXIS_Y)
8798 step->axis = event.jaxis.axis;
8799 strcat(mapping, step->field);
8800 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8801 strcat(mapping, temp);
8809 case SDL_JOYHATMOTION:
8810 // ignore centering; we're probably just coming back
8811 // to the center from the previous item we set
8812 if (event.jhat.value == SDL_HAT_CENTERED)
8815 for (j = 0; j < i; j++)
8816 if (steps[j].hat == event.jhat.hat &&
8817 steps[j].hat_value == event.jhat.value)
8822 step->hat = event.jhat.hat;
8823 step->hat_value = event.jhat.value;
8824 strcat(mapping, step->field);
8825 snprintf(temp, sizeof(temp), ":h%u.%u,",
8826 event.jhat.hat, event.jhat.value );
8827 strcat(mapping, temp);
8834 case SDL_JOYBALLMOTION:
8837 case SDL_JOYBUTTONUP:
8838 for (j = 0; j < i; j++)
8839 if (steps[j].button == event.jbutton.button)
8844 step->button = event.jbutton.button;
8845 strcat(mapping, step->field);
8846 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8847 strcat(mapping, temp);
8854 case SDL_FINGERDOWN:
8855 case SDL_MOUSEBUTTONDOWN:
8863 if (event.key.keysym.sym == KSYM_BackSpace ||
8864 event.key.keysym.sym == KSYM_Back)
8876 prev_step = &steps[i - 1];
8877 strcpy(mapping, prev_step->mapping);
8884 if (event.key.keysym.sym == KSYM_space ||
8885 event.key.keysym.sym == KSYM_Return ||
8886 event.key.keysym.sym == KSYM_Menu)
8895 if (event.key.keysym.sym == KSYM_Escape)
8905 program.exit_function(0);
8912 // do not handle events for longer than standard frame delay period
8913 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8922 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8925 // activate mapping for this game
8926 SDL_GameControllerAddMapping(mapping);
8928 // save mapping to personal mappings
8929 SaveSetup_AddGameControllerMapping(mapping);
8932 // wait until the last pending event was removed from event queue
8933 while (NextValidEvent(&event));
8938 static int ConfigureJoystickMain(int player_nr)
8940 char *device_name = setup.input[player_nr].joy.device_name;
8941 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8942 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8943 int success = FALSE;
8946 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8947 return JOYSTICK_NOT_AVAILABLE;
8949 if (!joystick_active || !setup.input[player_nr].use_joystick)
8950 return JOYSTICK_NOT_AVAILABLE;
8953 FadeOut(REDRAW_FIELD);
8955 // close all joystick devices (potentially opened as game controllers)
8956 for (i = 0; i < SDL_NumJoysticks(); i++)
8957 SDLCloseJoystick(i);
8959 // open joystick device as plain joystick to configure as game controller
8960 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8962 // as the joystick was successfully opened before, this should not happen
8963 if (joystick == NULL)
8966 // create new game controller mapping (buttons and axes) for joystick device
8967 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8969 // close joystick (and maybe re-open as configured game controller later)
8970 SDL_JoystickClose(joystick);
8972 // re-open all joystick devices (potentially as game controllers)
8973 for (i = 0; i < SDL_NumJoysticks(); i++)
8976 // clear all joystick input actions for all joystick devices
8977 SDLClearJoystickState();
8979 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8982 void ConfigureJoystick(int player_nr)
8984 boolean state = ConfigureJoystickMain(player_nr);
8986 if (state != JOYSTICK_NOT_CONFIGURED)
8988 boolean success = (state == JOYSTICK_CONFIGURED);
8989 char message1[MAX_OUTPUT_LINESIZE + 1];
8990 char *message2 = (success ? "configured!" : "not available!");
8991 char *device_name = setup.input[player_nr].joy.device_name;
8992 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8993 int font_nr = FONT_TITLE_1;
8994 int font_height = getFontHeight(font_nr);
8995 int ypos1 = SYSIZE / 2 - font_height * 2;
8996 int ypos2 = SYSIZE / 2 - font_height * 1;
8997 unsigned int wait_frame_delay = 0;
8998 unsigned int wait_frame_delay_value = 2000;
9000 ResetDelayCounter(&wait_frame_delay);
9004 sprintf(message1, "Joystick %d", nr);
9006 DrawTextSCentered(ypos1, font_nr, message1);
9007 DrawTextSCentered(ypos2, font_nr, message2);
9009 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9015 DrawSetupScreen_Input();
9018 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9020 if (y < video.screen_height / 3)
9022 // remap touch gadgets to access upper part of the screen
9023 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9024 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9026 else if (y > 2 * video.screen_height / 3)
9028 // remap touch gadgets to access lower part of the screen
9029 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9030 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9034 static boolean ConfigureVirtualButtonsMain(void)
9036 static char *customize_step_text[] =
9045 char grid_button[] =
9047 CHAR_GRID_BUTTON_LEFT,
9048 CHAR_GRID_BUTTON_RIGHT,
9049 CHAR_GRID_BUTTON_UP,
9050 CHAR_GRID_BUTTON_DOWN,
9051 CHAR_GRID_BUTTON_SNAP,
9052 CHAR_GRID_BUTTON_DROP
9061 int font_nr = FONT_INPUT_1_ACTIVE;
9062 int font_height = getFontHeight(font_nr);
9063 int ypos1 = SYSIZE / 2 - font_height * 2;
9064 int ypos2 = SYSIZE / 2 - font_height * 1;
9065 boolean success = FALSE;
9066 boolean finished = FALSE;
9068 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9069 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9070 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9071 boolean set_grid_button = FALSE;
9072 int nr = GRID_ACTIVE_NR();
9075 for (x = 0; x < MAX_GRID_XSIZE; x++)
9076 for (y = 0; y < MAX_GRID_YSIZE; y++)
9077 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9079 overlay.grid_button_highlight = grid_button[step_nr];
9084 FadeOut(REDRAW_FIELD);
9088 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9089 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9090 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9092 FadeIn(REDRAW_FIELD);
9094 SetOverlayShowGrid(TRUE);
9096 // map gadgets for setup touch buttons menu screen
9097 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9103 while (NextValidEvent(&event))
9105 int action = ACTION_NONE;
9107 // ---------- handle events and set the resulting action ----------
9113 UserEvent *user = (UserEvent *)&event;
9114 int id = user->value1;
9116 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9117 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9118 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9119 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9124 case EVENT_KEYPRESS:
9126 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9128 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9129 key == KSYM_BackSpace ||
9130 key == KSYM_Back ? ACTION_BACK :
9131 key == KSYM_Return ||
9133 key == KSYM_space ? ACTION_NEXT :
9138 case EVENT_KEYRELEASE:
9139 key_joystick_mapping = 0;
9142 case EVENT_BUTTONPRESS:
9143 case EVENT_BUTTONRELEASE:
9145 ButtonEvent *button = (ButtonEvent *)&event;
9147 motion_status = FALSE;
9149 if (button->type == EVENT_BUTTONPRESS)
9150 button_status = button->button;
9152 button_status = MB_RELEASED;
9154 if (HandleGadgets(button->x, button->y, button_status))
9156 // do not handle this button event anymore
9160 button->x += video.screen_xoffset;
9161 button->y += video.screen_yoffset;
9163 x = button->x * overlay.grid_xsize / video.screen_width;
9164 y = button->y * overlay.grid_ysize / video.screen_height;
9166 if (button->type == EVENT_BUTTONPRESS)
9169 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9170 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9172 set_grid_button = TRUE;
9175 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9179 case EVENT_MOTIONNOTIFY:
9181 MotionEvent *motion = (MotionEvent *)&event;
9183 motion_status = TRUE;
9185 if (HandleGadgets(motion->x, motion->y, button_status))
9187 // do not handle this button event anymore
9191 motion->x += video.screen_xoffset;
9192 motion->y += video.screen_yoffset;
9194 x = motion->x * overlay.grid_xsize / video.screen_width;
9195 y = motion->y * overlay.grid_ysize / video.screen_height;
9197 set_grid_button = TRUE;
9199 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9203 case SDL_WINDOWEVENT:
9204 HandleWindowEvent((WindowEvent *) &event);
9206 // check if device has been rotated
9207 if (nr != GRID_ACTIVE_NR())
9209 nr = GRID_ACTIVE_NR();
9211 for (x = 0; x < MAX_GRID_XSIZE; x++)
9212 for (y = 0; y < MAX_GRID_YSIZE; y++)
9213 grid_button_old[x][y] = grid_button_tmp[x][y] =
9214 overlay.grid_button[x][y];
9219 case SDL_APP_WILLENTERBACKGROUND:
9220 case SDL_APP_DIDENTERBACKGROUND:
9221 case SDL_APP_WILLENTERFOREGROUND:
9222 case SDL_APP_DIDENTERFOREGROUND:
9223 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9227 HandleOtherEvents(&event);
9231 // ---------- perform action set by handling events ----------
9233 if (action == ACTION_ESCAPE)
9235 // abort and restore the old key bindings
9237 for (x = 0; x < MAX_GRID_XSIZE; x++)
9238 for (y = 0; y < MAX_GRID_YSIZE; y++)
9239 overlay.grid_button[x][y] = grid_button_old[x][y];
9241 FadeSkipNextFadeIn();
9245 else if (action == ACTION_BACK)
9247 // keep the configured key bindings and go to previous page
9253 FadeSkipNextFadeIn();
9258 else if (action == ACTION_NEXT)
9260 // keep the configured key bindings and go to next page
9264 // all virtual buttons configured
9272 if (action != ACTION_NONE && !finished)
9274 for (x = 0; x < MAX_GRID_XSIZE; x++)
9275 for (y = 0; y < MAX_GRID_YSIZE; y++)
9276 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9278 overlay.grid_button_highlight = grid_button[step_nr];
9280 // configure next virtual button
9284 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9285 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9286 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9289 if (set_grid_button)
9291 overlay.grid_button[x][y] =
9292 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9293 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9294 grid_button_tmp[x][y]);
9296 set_grid_button = FALSE;
9303 for (x = 0; x < MAX_GRID_XSIZE; x++)
9304 for (y = 0; y < MAX_GRID_YSIZE; y++)
9305 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9307 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9309 SetOverlayShowGrid(FALSE);
9314 void ConfigureVirtualButtons(void)
9316 boolean success = ConfigureVirtualButtonsMain();
9318 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9319 SCREEN_MASK_TOUCH2);
9323 int font_nr = FONT_TITLE_1;
9324 int font_height = getFontHeight(font_nr);
9325 int ypos1 = SYSIZE / 2 - font_height * 2;
9326 int ypos2 = SYSIZE / 2 - font_height * 1;
9327 unsigned int wait_frame_delay = 0;
9328 unsigned int wait_frame_delay_value = 2000;
9330 ResetDelayCounter(&wait_frame_delay);
9334 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9335 DrawTextSCentered(ypos2, font_nr, "configured!");
9337 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9344 void DrawSetupScreen(void)
9349 if (setup_mode == SETUP_MODE_INPUT)
9350 DrawSetupScreen_Input();
9351 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9352 DrawChooseTree(&scores_type_current);
9353 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9354 DrawChooseTree(&game_speed_current);
9355 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9356 DrawChooseTree(&scroll_delay_current);
9357 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9358 DrawChooseTree(&snapshot_mode_current);
9359 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9360 DrawChooseTree(&window_size_current);
9361 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9362 DrawChooseTree(&scaling_type_current);
9363 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9364 DrawChooseTree(&rendering_mode_current);
9365 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9366 DrawChooseTree(&vsync_mode_current);
9367 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9368 DrawChooseTree(&artwork.gfx_current);
9369 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9370 DrawChooseTree(&artwork.snd_current);
9371 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9372 DrawChooseTree(&artwork.mus_current);
9373 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9374 DrawChooseTree(&volume_simple_current);
9375 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9376 DrawChooseTree(&volume_loops_current);
9377 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9378 DrawChooseTree(&volume_music_current);
9379 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9380 DrawChooseTree(&touch_control_current);
9381 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9382 DrawChooseTree(&move_distance_current);
9383 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9384 DrawChooseTree(&drop_distance_current);
9385 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9386 DrawChooseTree(&transparency_current);
9387 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9388 DrawChooseTree(&grid_size_current[0][0]);
9389 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9390 DrawChooseTree(&grid_size_current[0][1]);
9391 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9392 DrawChooseTree(&grid_size_current[1][0]);
9393 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9394 DrawChooseTree(&grid_size_current[1][1]);
9396 DrawSetupScreen_Generic();
9398 PlayMenuSoundsAndMusic();
9401 void RedrawSetupScreenAfterFullscreenToggle(void)
9403 if (setup_mode == SETUP_MODE_GRAPHICS ||
9404 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9406 // update list selection from "setup.window_scaling_percent"
9407 execSetupGraphics_setWindowSizes(TRUE);
9413 void RedrawSetupScreenAfterScreenRotation(int nr)
9417 if (setup_mode == SETUP_MODE_TOUCH)
9419 // update virtual button settings (depending on screen orientation)
9422 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9424 // save already configured virtual buttons
9425 for (x = 0; x < MAX_GRID_XSIZE; x++)
9426 for (y = 0; y < MAX_GRID_YSIZE; y++)
9427 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9431 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9433 if (setup_mode == SETUP_MODE_INPUT)
9434 HandleSetupScreen_Input(mx, my, dx, dy, button);
9435 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9436 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9437 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9438 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9439 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9440 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9441 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9442 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9443 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9444 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9445 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9446 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9447 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9448 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9449 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9450 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9451 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9452 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9453 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9454 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9455 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9456 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9457 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9458 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9459 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9460 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9461 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9462 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9463 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9464 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9465 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9466 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9467 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9468 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9469 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9470 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9471 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9472 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9473 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9474 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9475 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9476 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9477 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9478 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9480 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9483 void HandleGameActions(void)
9485 if (setup.ask_on_game_over)
9488 if (game.restart_game_message != NULL)
9490 RequestRestartGame(game.restart_game_message);
9495 if (game_status != GAME_MODE_PLAYING)
9498 GameActions(); // main game loop
9500 if (tape.auto_play && !tape.playing)
9501 AutoPlayTapesContinue(); // continue automatically playing next tape
9505 // ---------- new screen button stuff --------------------------------------
9509 int gfx_unpressed, gfx_pressed;
9510 struct MenuPosInfo *pos;
9511 boolean *check_value;
9514 unsigned int event_mask;
9515 boolean is_touch_button;
9517 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9520 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9521 &menu.main.button.prev_level, NULL,
9522 SCREEN_CTRL_ID_PREV_LEVEL,
9524 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9525 FALSE, "previous level"
9528 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9529 &menu.main.button.next_level, NULL,
9530 SCREEN_CTRL_ID_NEXT_LEVEL,
9532 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9536 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9537 &menu.main.button.first_level, NULL,
9538 SCREEN_CTRL_ID_FIRST_LEVEL,
9541 FALSE, "first level"
9544 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9545 &menu.main.button.last_level, NULL,
9546 SCREEN_CTRL_ID_LAST_LEVEL,
9552 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9553 &menu.main.button.level_number, NULL,
9554 SCREEN_CTRL_ID_LEVEL_NUMBER,
9557 FALSE, "level number"
9560 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9561 &menu.setup.button.prev_player, NULL,
9562 SCREEN_CTRL_ID_PREV_PLAYER,
9564 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9565 FALSE, "previous player"
9568 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9569 &menu.setup.button.next_player, NULL,
9570 SCREEN_CTRL_ID_NEXT_PLAYER,
9572 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9573 FALSE, "next player"
9576 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9577 &menu.main.button.insert_solution, NULL,
9578 SCREEN_CTRL_ID_INSERT_SOLUTION,
9579 SCREEN_MASK_MAIN_HAS_SOLUTION,
9581 FALSE, "insert solution tape"
9584 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9585 &menu.main.button.play_solution, NULL,
9586 SCREEN_CTRL_ID_PLAY_SOLUTION,
9587 SCREEN_MASK_MAIN_HAS_SOLUTION,
9589 FALSE, "play solution tape"
9592 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9593 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9594 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9596 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9597 FALSE, "switch ECS/AGA chipset"
9600 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9601 &menu.setup.button.touch_back, NULL,
9602 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9605 TRUE, "previous page"
9608 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9609 &menu.setup.button.touch_next, NULL,
9610 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9616 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9617 &menu.setup.button.touch_back2, NULL,
9618 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9621 TRUE, "previous page"
9624 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9625 &menu.setup.button.touch_next2, NULL,
9626 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9635 int gfx_unpressed, gfx_pressed;
9639 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9642 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9643 -1, -1, // these values are not constant, but can change at runtime
9644 SCREEN_CTRL_ID_SCROLL_UP,
9648 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9649 -1, -1, // these values are not constant, but can change at runtime
9650 SCREEN_CTRL_ID_SCROLL_DOWN,
9657 int gfx_unpressed, gfx_pressed;
9663 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9666 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9667 -1, -1, // these values are not constant, but can change at runtime
9668 -1, -1, // these values are not constant, but can change at runtime
9669 GD_TYPE_SCROLLBAR_VERTICAL,
9670 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9671 "scroll level series vertically"
9683 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9686 IMG_SETUP_INPUT_TEXT,
9687 SCREEN_CTRL_ID_NETWORK_SERVER,
9688 -1, -1, // these values are not constant, but can change at runtime
9689 MAX_SETUP_TEXT_INPUT_LEN,
9690 network_server_hostname,
9691 "Network Server Hostname / IP"
9695 static void CreateScreenMenubuttons(void)
9697 struct GadgetInfo *gi;
9698 unsigned int event_mask;
9701 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9703 struct MenuPosInfo *pos = menubutton_info[i].pos;
9704 boolean is_touch_button = menubutton_info[i].is_touch_button;
9705 boolean is_check_button = menubutton_info[i].check_value != NULL;
9706 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9707 int gfx_unpressed, gfx_pressed;
9708 int x, y, width, height;
9709 int gd_x1, gd_x2, gd_y1, gd_y2;
9710 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9711 int id = menubutton_info[i].gadget_id;
9712 int type = GD_TYPE_NORMAL_BUTTON;
9713 boolean checked = FALSE;
9715 event_mask = menubutton_info[i].event_mask;
9717 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9718 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9720 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9721 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9723 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9724 gfx_pressed = menubutton_info[i].gfx_pressed;
9725 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9726 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9727 gd_x1 = graphic_info[gfx_unpressed].src_x;
9728 gd_y1 = graphic_info[gfx_unpressed].src_y;
9729 gd_x2 = graphic_info[gfx_pressed].src_x;
9730 gd_y2 = graphic_info[gfx_pressed].src_y;
9736 if (is_touch_button)
9738 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9739 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9742 if (is_check_button)
9744 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9745 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9746 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9747 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9749 type = GD_TYPE_CHECK_BUTTON;
9750 checked = *menubutton_info[i].check_value;
9753 gi = CreateGadget(GDI_CUSTOM_ID, id,
9754 GDI_CUSTOM_TYPE_ID, i,
9755 GDI_IMAGE_ID, gfx_unpressed,
9756 GDI_INFO_TEXT, menubutton_info[i].infotext,
9762 GDI_STATE, GD_BUTTON_UNPRESSED,
9763 GDI_CHECKED, checked,
9764 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9765 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9766 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9767 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9768 GDI_DIRECT_DRAW, FALSE,
9769 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9770 GDI_EVENT_MASK, event_mask,
9771 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9775 Fail("cannot create gadget");
9777 screen_gadget[id] = gi;
9781 static void CreateScreenScrollbuttons(void)
9783 struct GadgetInfo *gi;
9784 unsigned int event_mask;
9787 // these values are not constant, but can change at runtime
9788 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9789 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9790 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9791 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9793 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9795 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9796 int gfx_unpressed, gfx_pressed;
9797 int x, y, width, height;
9798 int gd_x1, gd_x2, gd_y1, gd_y2;
9799 int id = scrollbutton_info[i].gadget_id;
9801 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9803 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9804 y = mSY + scrollbutton_info[i].y;
9805 width = SC_SCROLLBUTTON_XSIZE;
9806 height = SC_SCROLLBUTTON_YSIZE;
9808 // correct scrollbar position if placed outside menu (playfield) area
9809 if (x > SX + SC_SCROLL_UP_XPOS)
9810 x = SX + SC_SCROLL_UP_XPOS;
9812 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9813 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9814 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9816 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9817 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9818 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9819 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9820 gd_x1 = graphic_info[gfx_unpressed].src_x;
9821 gd_y1 = graphic_info[gfx_unpressed].src_y;
9822 gd_x2 = graphic_info[gfx_pressed].src_x;
9823 gd_y2 = graphic_info[gfx_pressed].src_y;
9825 gi = CreateGadget(GDI_CUSTOM_ID, id,
9826 GDI_CUSTOM_TYPE_ID, i,
9827 GDI_IMAGE_ID, gfx_unpressed,
9828 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9833 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9834 GDI_STATE, GD_BUTTON_UNPRESSED,
9835 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9836 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9837 GDI_DIRECT_DRAW, FALSE,
9838 GDI_EVENT_MASK, event_mask,
9839 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9843 Fail("cannot create gadget");
9845 screen_gadget[id] = gi;
9849 static void CreateScreenScrollbars(void)
9853 // these values are not constant, but can change at runtime
9854 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9855 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9856 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9857 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9859 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9861 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9862 int gfx_unpressed, gfx_pressed;
9863 int x, y, width, height;
9864 int gd_x1, gd_x2, gd_y1, gd_y2;
9865 struct GadgetInfo *gi;
9866 int items_max, items_visible, item_position;
9867 unsigned int event_mask;
9868 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9869 int id = scrollbar_info[i].gadget_id;
9871 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9873 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9874 y = mSY + scrollbar_info[i].y;
9875 width = scrollbar_info[i].width;
9876 height = scrollbar_info[i].height;
9878 // correct scrollbar position if placed outside menu (playfield) area
9879 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9880 x = SX + SC_SCROLL_VERTICAL_XPOS;
9882 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9883 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9885 items_max = num_page_entries;
9886 items_visible = num_page_entries;
9889 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9890 gfx_pressed = scrollbar_info[i].gfx_pressed;
9891 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9892 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9893 gd_x1 = graphic_info[gfx_unpressed].src_x;
9894 gd_y1 = graphic_info[gfx_unpressed].src_y;
9895 gd_x2 = graphic_info[gfx_pressed].src_x;
9896 gd_y2 = graphic_info[gfx_pressed].src_y;
9898 gi = CreateGadget(GDI_CUSTOM_ID, id,
9899 GDI_CUSTOM_TYPE_ID, i,
9900 GDI_IMAGE_ID, gfx_unpressed,
9901 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9906 GDI_TYPE, scrollbar_info[i].type,
9907 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9908 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9909 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9910 GDI_WHEEL_AREA_X, SX,
9911 GDI_WHEEL_AREA_Y, SY,
9912 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9913 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9914 GDI_STATE, GD_BUTTON_UNPRESSED,
9915 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9916 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9917 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9918 GDI_DIRECT_DRAW, FALSE,
9919 GDI_EVENT_MASK, event_mask,
9920 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9924 Fail("cannot create gadget");
9926 screen_gadget[id] = gi;
9930 static void CreateScreenTextInputGadgets(void)
9934 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9936 int graphic = textinput_info[i].graphic;
9937 struct GraphicInfo *gd = &graphic_info[graphic];
9938 int gd_x1 = gd->src_x;
9939 int gd_y1 = gd->src_y;
9940 int gd_x2 = gd->src_x + gd->active_xoffset;
9941 int gd_y2 = gd->src_y + gd->active_yoffset;
9942 struct GadgetInfo *gi;
9943 unsigned int event_mask;
9944 int id = textinput_info[i].gadget_id;
9945 int x = textinput_info[i].x;
9946 int y = textinput_info[i].y;
9948 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9950 gi = CreateGadget(GDI_CUSTOM_ID, id,
9951 GDI_CUSTOM_TYPE_ID, i,
9952 GDI_INFO_TEXT, textinput_info[i].infotext,
9955 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9956 GDI_TEXT_VALUE, textinput_info[i].value,
9957 GDI_TEXT_SIZE, textinput_info[i].size,
9958 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9959 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9960 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9961 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9962 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9963 GDI_DESIGN_WIDTH, gd->width,
9964 GDI_EVENT_MASK, event_mask,
9965 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9966 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9970 Fail("cannot create gadget");
9972 screen_gadget[id] = gi;
9976 void CreateScreenGadgets(void)
9978 CreateScreenMenubuttons();
9980 CreateScreenScrollbuttons();
9981 CreateScreenScrollbars();
9983 CreateScreenTextInputGadgets();
9986 void FreeScreenGadgets(void)
9990 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9991 FreeGadget(screen_gadget[i]);
9994 static void MapScreenMenuGadgets(int screen_mask)
9998 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9999 if (screen_mask & menubutton_info[i].screen_mask)
10000 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10003 static void UnmapScreenMenuGadgets(int screen_mask)
10007 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10009 if (screen_mask & menubutton_info[i].screen_mask)
10011 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10013 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10014 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10015 screen_gadget[menubutton_info[i].gadget_id]->y,
10016 screen_gadget[menubutton_info[i].gadget_id]->width,
10017 screen_gadget[menubutton_info[i].gadget_id]->height);
10022 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10025 MapScreenMenuGadgets(screen_mask);
10027 UnmapScreenMenuGadgets(screen_mask);
10030 static void MapScreenGadgets(int num_entries)
10034 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10037 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10038 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10040 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10041 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10044 static void MapScreenTreeGadgets(TreeInfo *ti)
10046 MapScreenGadgets(numTreeInfoInGroup(ti));
10049 static void HandleScreenGadgets(struct GadgetInfo *gi)
10051 int id = gi->custom_id;
10052 int button = gi->event.button;
10053 int step = (button == MB_LEFTBUTTON ? 1 :
10054 button == MB_MIDDLEBUTTON ? 5 :
10055 button == MB_RIGHTBUTTON ? 10 : 1);
10059 case SCREEN_CTRL_ID_PREV_LEVEL:
10060 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10063 case SCREEN_CTRL_ID_NEXT_LEVEL:
10064 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10067 case SCREEN_CTRL_ID_FIRST_LEVEL:
10068 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10071 case SCREEN_CTRL_ID_LAST_LEVEL:
10072 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10075 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10076 CloseDoor(DOOR_CLOSE_2);
10077 SetGameStatus(GAME_MODE_LEVELNR);
10078 DrawChooseLevelNr();
10081 case SCREEN_CTRL_ID_PREV_PLAYER:
10082 HandleSetupScreen_Input_Player(step, -1);
10085 case SCREEN_CTRL_ID_NEXT_PLAYER:
10086 HandleSetupScreen_Input_Player(step, +1);
10089 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10090 InsertSolutionTape();
10093 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10094 PlaySolutionTape();
10097 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10098 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10102 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10103 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10104 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10105 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10106 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10109 case SCREEN_CTRL_ID_SCROLL_UP:
10110 if (game_status == GAME_MODE_NAMES)
10111 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10112 else if (game_status == GAME_MODE_LEVELS)
10113 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10114 else if (game_status == GAME_MODE_LEVELNR)
10115 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10116 else if (game_status == GAME_MODE_SETUP)
10117 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10118 else if (game_status == GAME_MODE_INFO)
10119 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10120 else if (game_status == GAME_MODE_SCORES)
10121 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10124 case SCREEN_CTRL_ID_SCROLL_DOWN:
10125 if (game_status == GAME_MODE_NAMES)
10126 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10127 else if (game_status == GAME_MODE_LEVELS)
10128 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10129 else if (game_status == GAME_MODE_LEVELNR)
10130 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10131 else if (game_status == GAME_MODE_SETUP)
10132 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10133 else if (game_status == GAME_MODE_INFO)
10134 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10135 else if (game_status == GAME_MODE_SCORES)
10136 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10139 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10140 if (game_status == GAME_MODE_NAMES)
10141 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10142 else if (game_status == GAME_MODE_LEVELS)
10143 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10144 else if (game_status == GAME_MODE_LEVELNR)
10145 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10146 else if (game_status == GAME_MODE_SETUP)
10147 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10148 else if (game_status == GAME_MODE_INFO)
10149 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10150 else if (game_status == GAME_MODE_SCORES)
10151 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10154 case SCREEN_CTRL_ID_NETWORK_SERVER:
10156 if (!strEqual(gi->textinput.value, ""))
10158 setString(&setup.network_server_hostname, gi->textinput.value);
10160 network.server_host = setup.network_server_hostname;
10164 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10166 network.server_host = NULL;
10169 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10170 network.server_host = NULL;
10172 execSetupGame_setNetworkServerText();
10184 void DumpScreenIdentifiers(void)
10188 Print("Active screen elements on current screen:\n");
10190 for (i = 0; main_controls[i].nr != -1; i++)
10192 struct MainControlInfo *mci = &main_controls[i];
10194 if (mci->button_graphic != -1)
10196 char *token = getTokenFromImageID(mci->button_graphic);
10198 Print("- '%s'\n", token);
10205 boolean DoScreenAction(int image_id)
10209 if (game_status != GAME_MODE_MAIN)
10212 for (i = 0; main_controls[i].nr != -1; i++)
10214 struct MainControlInfo *mci = &main_controls[i];
10215 struct MenuPosInfo *pos = mci->pos_button;
10217 if (mci->button_graphic == image_id)
10219 int x = mSX + pos->x;
10220 int y = mSY + pos->y;
10222 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10231 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10233 // get tree info node of newly added level or artwork set
10234 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10235 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10237 if (tree_node_new == NULL) // should not happen
10240 // if request dialog is active, do nothing
10241 if (game.request_active)
10244 if (game_status == GAME_MODE_MAIN &&
10245 tree_type == TREE_TYPE_LEVEL_DIR)
10247 // when adding new level set in main menu, select it as current level set
10249 // change current level set to newly added level set from zip file
10250 leveldir_current = tree_node_new;
10252 // change current level number to first level of newly added level set
10253 level_nr = leveldir_current->first_level;
10255 // redraw screen to reflect changed level set
10258 // save this level set and level number as last selected level set
10259 SaveLevelSetup_LastSeries();
10260 SaveLevelSetup_SeriesInfo();
10262 else if (game_status == GAME_MODE_LEVELS &&
10263 tree_type == TREE_TYPE_LEVEL_DIR)
10265 // when adding new level set in level set menu, set cursor and update screen
10267 leveldir_current = tree_node_new;
10269 DrawChooseTree(&leveldir_current);
10271 else if (game_status == GAME_MODE_SETUP)
10273 // when adding new artwork set in setup menu, set cursor and update screen
10275 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10276 tree_type == TREE_TYPE_GRAPHICS_DIR)
10278 artwork.gfx_current = tree_node_new;
10280 DrawChooseTree(&artwork.gfx_current);
10282 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10283 tree_type == TREE_TYPE_SOUNDS_DIR)
10285 artwork.snd_current = tree_node_new;
10287 DrawChooseTree(&artwork.snd_current);
10289 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10290 tree_type == TREE_TYPE_MUSIC_DIR)
10292 artwork.mus_current = tree_node_new;
10294 DrawChooseTree(&artwork.mus_current);
10299 static int UploadTapes(void)
10301 SetGameStatus(GAME_MODE_LOADING);
10303 FadeSetEnterScreen();
10304 FadeOut(REDRAW_ALL);
10306 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10308 FadeIn(REDRAW_ALL);
10310 DrawInitTextHead("Uploading tapes");
10312 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10313 global.autoplay_leveldir = "ALL";
10314 global.autoplay_all = TRUE;
10316 int num_tapes_uploaded = AutoPlayTapes();
10318 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10319 global.autoplay_leveldir = NULL;
10320 global.autoplay_all = FALSE;
10322 SetGameStatus(GAME_MODE_MAIN);
10326 return num_tapes_uploaded;
10329 static boolean OfferUploadTapes(void)
10331 if (!Request(setup.has_remaining_tapes ?
10332 "Upload missing tapes to the high score server now?" :
10333 "Upload all your tapes to the high score server now?", REQ_ASK))
10336 int num_tapes_uploaded = UploadTapes();
10339 if (num_tapes_uploaded < 0)
10341 num_tapes_uploaded = -num_tapes_uploaded - 1;
10343 if (num_tapes_uploaded == 0)
10344 sprintf(message, "Upload failed! No tapes uploaded!");
10345 else if (num_tapes_uploaded == 1)
10346 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10348 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10349 num_tapes_uploaded);
10351 Request(message, REQ_CONFIRM);
10353 // if uploading tapes failed, add tape upload entry to setup menu
10354 setup.provide_uploading_tapes = TRUE;
10355 setup.has_remaining_tapes = TRUE;
10357 SaveSetup_ServerSetup();
10362 if (num_tapes_uploaded == 0)
10363 sprintf(message, "No tapes uploaded!");
10364 else if (num_tapes_uploaded == 1)
10365 sprintf(message, "1 tape uploaded!");
10367 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10369 Request(message, REQ_CONFIRM);
10371 if (num_tapes_uploaded > 0)
10372 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10374 // after all tapes have been uploaded, remove entry from setup menu
10375 setup.provide_uploading_tapes = FALSE;
10376 setup.has_remaining_tapes = FALSE;
10378 SaveSetup_ServerSetup();
10383 static void CheckUploadTapes(void)
10385 if (!setup.ask_for_uploading_tapes)
10388 // after asking for uploading tapes, do not ask again
10389 setup.ask_for_uploading_tapes = FALSE;
10390 setup.ask_for_remaining_tapes = FALSE;
10392 if (directoryExists(getTapeDir(NULL)))
10394 boolean tapes_uploaded = OfferUploadTapes();
10396 if (!tapes_uploaded)
10398 Request(setup.has_remaining_tapes ?
10399 "You can upload missing tapes from the setup menu later!" :
10400 "You can upload your tapes from the setup menu later!",
10406 // if tapes directory does not exist yet, never offer uploading all tapes
10407 setup.provide_uploading_tapes = FALSE;
10410 SaveSetup_ServerSetup();
10413 static void UpgradePlayerUUID(void)
10415 ApiResetUUIDAsThread(getUUID());
10418 static void CheckUpgradePlayerUUID(void)
10420 if (setup.player_version > 1)
10423 UpgradePlayerUUID();
10426 void CheckApiServerTasks(void)
10428 // check if the player's UUID has to be upgraded
10429 CheckUpgradePlayerUUID();
10431 // check if there are any tapes to be uploaded
10432 CheckUploadTapes();