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_GAME_SPEED 17
67 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 18
68 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 19
69 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 20
70 #define SETUP_MODE_CHOOSE_SCALING_TYPE 21
71 #define SETUP_MODE_CHOOSE_RENDERING 22
72 #define SETUP_MODE_CHOOSE_VSYNC 23
73 #define SETUP_MODE_CHOOSE_GRAPHICS 24
74 #define SETUP_MODE_CHOOSE_SOUNDS 25
75 #define SETUP_MODE_CHOOSE_MUSIC 26
76 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 27
77 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 28
78 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 29
79 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 30
80 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 31
81 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_TRANSPARENCY 33
83 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 34
84 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 36
86 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 37
87 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 38
89 #define MAX_SETUP_MODES 39
91 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
93 // setup screen titles
94 #define STR_SETUP_MAIN "Setup"
95 #define STR_SETUP_GAME "Game & Menu"
96 #define STR_SETUP_ENGINES "Game Engines"
97 #define STR_SETUP_EDITOR "Editor"
98 #define STR_SETUP_GRAPHICS "Graphics"
99 #define STR_SETUP_SOUND "Sound & Music"
100 #define STR_SETUP_ARTWORK "Custom Artwork"
101 #define STR_SETUP_INPUT "Input Devices"
102 #define STR_SETUP_TOUCH "Touch Controls"
103 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
104 #define STR_SETUP_EXIT "Exit"
105 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
107 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
108 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
109 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
110 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
111 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
112 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
113 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
114 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
115 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
116 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
117 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
118 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
119 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
120 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
121 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
122 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
126 // other screen text constants
127 #define STR_CHOOSE_TREE_EDIT "Edit"
128 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
129 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
131 // for input setup functions
132 #define SETUPINPUT_SCREEN_POS_START 0
133 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
134 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
135 #define SETUPINPUT_SCREEN_POS_END 13
137 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
138 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
140 #define MAX_SETUP_TEXT_INPUT_LEN 28
142 // for various menu stuff
143 #define MENU_SCREEN_START_XPOS 1
144 #define MENU_SCREEN_START_YPOS 2
145 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
146 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
147 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
148 #define MENU_TITLE1_YPOS 8
149 #define MENU_TITLE2_YPOS 46
150 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
151 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
152 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
153 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
154 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
155 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
156 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
159 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
160 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
161 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
162 MENU_INFO_FONT_TITLE))
163 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
164 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
165 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
166 MENU_SCREEN_INFO_YSTART2 - \
168 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
169 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
170 MENU_SCREEN_INFO_YSTEP)
171 #define NUM_INFO_ELEMENTS_FROM_CONF \
172 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
173 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
174 MAX_MENU_ENTRIES_ON_SCREEN)
175 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
176 MAX_INFO_ELEMENTS_ON_SCREEN), \
177 NUM_INFO_ELEMENTS_FROM_CONF)
178 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
179 #define MAX_MENU_TEXT_LENGTH_BIG 13
180 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
182 // screen gadget identifiers
183 #define SCREEN_CTRL_ID_PREV_LEVEL 0
184 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
185 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
186 #define SCREEN_CTRL_ID_LAST_LEVEL 3
187 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
188 #define SCREEN_CTRL_ID_PREV_PLAYER 5
189 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
190 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
191 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
192 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
193 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
194 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
195 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
196 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
197 #define SCREEN_CTRL_ID_SCROLL_UP 14
198 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
199 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
200 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
202 #define NUM_SCREEN_GADGETS 18
204 #define NUM_SCREEN_MENUBUTTONS 14
205 #define NUM_SCREEN_SCROLLBUTTONS 2
206 #define NUM_SCREEN_SCROLLBARS 1
207 #define NUM_SCREEN_TEXTINPUT 1
209 #define SCREEN_MASK_MAIN (1 << 0)
210 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
211 #define SCREEN_MASK_INPUT (1 << 2)
212 #define SCREEN_MASK_TOUCH (1 << 3)
213 #define SCREEN_MASK_TOUCH2 (1 << 4)
215 // graphic position and size values for buttons and scrollbars
216 #define SC_MENUBUTTON_XSIZE TILEX
217 #define SC_MENUBUTTON_YSIZE TILEY
219 #define SC_SCROLLBUTTON_XSIZE TILEX
220 #define SC_SCROLLBUTTON_YSIZE TILEY
222 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
224 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
225 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
226 SC_SCROLLBUTTON_YSIZE)
228 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
229 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
231 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
232 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
233 SC_SCROLLBUTTON_YSIZE)
235 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
236 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
237 SC_SCROLL_VERTICAL_YSIZE)
239 #define SC_BORDER_SIZE 14
242 // forward declarations of internal functions
243 static void HandleScreenGadgets(struct GadgetInfo *);
244 static void HandleSetupScreen_Generic(int, int, int, int, int);
245 static void HandleSetupScreen_Input(int, int, int, int, int);
246 static void CustomizeKeyboard(int);
247 static void ConfigureJoystick(int);
248 static void ConfigureVirtualButtons(void);
249 static void execSetupGame(void);
250 static void execSetupEngines(void);
251 static void execSetupGraphics(void);
252 static void execSetupSound(void);
253 static void execSetupTouch(void);
254 static void execSetupArtwork(void);
255 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
257 static void DrawChoosePlayerName(void);
258 static void DrawChooseLevelSet(void);
259 static void DrawChooseLevelNr(void);
260 static void DrawInfoScreen(void);
261 static void DrawSetupScreen(void);
262 static void DrawTypeName(void);
264 static void DrawInfoScreen_NotAvailable(char *, char *);
265 static void DrawInfoScreen_HelpAnim(int, int, boolean);
266 static void DrawInfoScreen_HelpText(int, int, int, int);
267 static void HandleInfoScreen_Main(int, int, int, int, int);
268 static void HandleInfoScreen_TitleScreen(int);
269 static void HandleInfoScreen_Elements(int);
270 static void HandleInfoScreen_Music(int);
271 static void HandleInfoScreen_Credits(int);
272 static void HandleInfoScreen_Program(int);
273 static void HandleInfoScreen_Version(int);
275 static void ModifyGameSpeedIfNeeded(void);
276 static void DisableVsyncIfNeeded(void);
278 static void MapScreenMenuGadgets(int);
279 static void UnmapScreenMenuGadgets(int);
280 static void MapScreenGadgets(int);
281 static void MapScreenTreeGadgets(TreeInfo *);
283 static void UpdateScreenMenuGadgets(int, boolean);
285 static boolean OfferUploadTapes(void);
286 static void execOfferUploadTapes(void);
288 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
290 static int info_mode = INFO_MODE_MAIN;
291 static int setup_mode = SETUP_MODE_MAIN;
293 static TreeInfo *window_sizes = NULL;
294 static TreeInfo *window_size_current = NULL;
296 static TreeInfo *scaling_types = NULL;
297 static TreeInfo *scaling_type_current = NULL;
299 static TreeInfo *rendering_modes = NULL;
300 static TreeInfo *rendering_mode_current = NULL;
302 static TreeInfo *vsync_modes = NULL;
303 static TreeInfo *vsync_mode_current = NULL;
305 static TreeInfo *scroll_delays = NULL;
306 static TreeInfo *scroll_delay_current = NULL;
308 static TreeInfo *snapshot_modes = NULL;
309 static TreeInfo *snapshot_mode_current = NULL;
311 static TreeInfo *game_speeds_normal = NULL;
312 static TreeInfo *game_speeds_extended = NULL;
313 static TreeInfo *game_speeds = NULL;
314 static TreeInfo *game_speed_current = NULL;
316 static TreeInfo *volumes_simple = NULL;
317 static TreeInfo *volume_simple_current = NULL;
319 static TreeInfo *volumes_loops = NULL;
320 static TreeInfo *volume_loops_current = NULL;
322 static TreeInfo *volumes_music = NULL;
323 static TreeInfo *volume_music_current = NULL;
325 static TreeInfo *touch_controls = NULL;
326 static TreeInfo *touch_control_current = NULL;
328 static TreeInfo *move_distances = NULL;
329 static TreeInfo *move_distance_current = NULL;
331 static TreeInfo *drop_distances = NULL;
332 static TreeInfo *drop_distance_current = NULL;
334 static TreeInfo *transparencies = NULL;
335 static TreeInfo *transparency_current = NULL;
337 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
338 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
340 static TreeInfo *player_name = NULL;
341 static TreeInfo *player_name_current = NULL;
343 static TreeInfo *level_number = NULL;
344 static TreeInfo *level_number_current = NULL;
346 static struct ValueTextInfo window_sizes_list[] =
351 { 100, "100 % (Default)" },
364 static struct StringValueTextInfo scaling_types_list[] =
366 { SCALING_QUALITY_NEAREST, "Off" },
367 { SCALING_QUALITY_LINEAR, "Linear" },
368 { SCALING_QUALITY_BEST, "Anisotropic" },
373 static struct StringValueTextInfo rendering_modes_list[] =
375 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
376 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
378 // this mode may work under certain conditions, but does not work on Windows
379 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
381 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
386 static struct StringValueTextInfo vsync_modes_list[] =
388 { STR_VSYNC_MODE_OFF, "Off" },
389 { STR_VSYNC_MODE_NORMAL, "Normal" },
390 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
395 static struct ValueTextInfo game_speeds_list_normal[] =
406 static struct ValueTextInfo game_speeds_list_extended[] =
408 { 1000, "1 fps (Extremely Slow)" },
413 { 29, "35 fps (Original Supaplex)" },
415 { 20, "50 fps (=== Normal Speed ===)" },
416 { 16, "60 fps (60 Hz VSync Speed)" },
417 { 14, "70 fps (Maximum Supaplex)" },
421 { 1, "1000 fps (Extremely Fast)" },
426 static struct ValueTextInfo *game_speeds_list;
428 static struct ValueTextInfo scroll_delays_list[] =
430 { 0, "0 Tiles (No Scroll Delay)" },
433 { 3, "3 Tiles (Default)" },
438 { 8, "8 Tiles (Maximum Scroll Delay)"},
443 static struct StringValueTextInfo snapshot_modes_list[] =
445 { STR_SNAPSHOT_MODE_OFF, "Off" },
446 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
447 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
448 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
453 static struct ValueTextInfo volumes_list[] =
473 static struct StringValueTextInfo touch_controls_list[] =
475 { TOUCH_CONTROL_OFF, "Off" },
476 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
477 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
478 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
483 static struct ValueTextInfo distances_list[] =
498 static struct ValueTextInfo transparencies_list[] =
500 { 0, "0 % (Opaque)" },
510 { 100, "100 % (Invisible)" },
515 static struct ValueTextInfo grid_sizes_list[] =
551 static int align_xoffset = 0;
552 static int align_yoffset = 0;
554 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
555 (s) <= GAME_MODE_SETUP ? (s) : \
556 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
558 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
559 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
561 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
562 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
563 (i) <= INFO_MODE_LEVELSET ? (i) : \
566 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
567 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
568 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
569 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
570 SETUP_MODE_CHOOSE_ARTWORK : \
571 SETUP_MODE_CHOOSE_OTHER)
573 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
574 menu.draw_xoffset[GAME_MODE_INFO] : \
575 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
576 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
577 menu.draw_yoffset[GAME_MODE_INFO] : \
578 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
579 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
580 menu.extra_spacing[GAME_MODE_INFO] : \
581 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
583 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
584 menu.draw_xoffset[GAME_MODE_SETUP] : \
585 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
586 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
587 menu.draw_yoffset[GAME_MODE_SETUP] : \
588 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
589 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
590 menu.extra_spacing[GAME_MODE_SETUP] : \
591 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
593 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
594 DRAW_XOFFSET_INFO(info_mode) : \
595 (s) == GAME_MODE_SETUP ? \
596 DRAW_XOFFSET_SETUP(setup_mode) : \
597 menu.draw_xoffset[DRAW_MODE(s)])
598 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
599 DRAW_YOFFSET_INFO(info_mode) : \
600 (s) == GAME_MODE_SETUP ? \
601 DRAW_YOFFSET_SETUP(setup_mode) : \
602 menu.draw_yoffset[DRAW_MODE(s)])
603 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
604 EXTRA_SPACING_INFO(info_mode) : \
605 (s) == GAME_MODE_SETUP ? \
606 EXTRA_SPACING_SETUP(setup_mode) : \
607 menu.extra_spacing[DRAW_MODE(s)])
609 #define mSX (SX + DRAW_XOFFSET(game_status))
610 #define mSY (SY + DRAW_YOFFSET(game_status))
612 #define amSX (mSX + align_xoffset)
613 #define amSY (mSY + align_yoffset)
615 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
616 menu.list_size[game_status] : \
617 MAX_MENU_ENTRIES_ON_SCREEN)
619 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
620 NUM_MENU_ENTRIES_ON_SCREEN)
623 // title display and control definitions
625 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
626 2 * MAX_NUM_TITLE_MESSAGES)
628 #define NO_DIRECT_LEVEL_SELECT (-1)
631 static int num_title_screens = 0;
633 struct TitleControlInfo
642 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
644 // main menu display and control definitions
646 #define MAIN_CONTROL_NAME 0
647 #define MAIN_CONTROL_LEVELS 1
648 #define MAIN_CONTROL_SCORES 2
649 #define MAIN_CONTROL_EDITOR 3
650 #define MAIN_CONTROL_INFO 4
651 #define MAIN_CONTROL_GAME 5
652 #define MAIN_CONTROL_SETUP 6
653 #define MAIN_CONTROL_QUIT 7
654 #define MAIN_CONTROL_PREV_LEVEL 8
655 #define MAIN_CONTROL_NEXT_LEVEL 9
656 #define MAIN_CONTROL_FIRST_LEVEL 10
657 #define MAIN_CONTROL_LAST_LEVEL 11
658 #define MAIN_CONTROL_LEVEL_NUMBER 12
659 #define MAIN_CONTROL_LEVEL_INFO_1 13
660 #define MAIN_CONTROL_LEVEL_INFO_2 14
661 #define MAIN_CONTROL_LEVEL_NAME 15
662 #define MAIN_CONTROL_LEVEL_AUTHOR 16
663 #define MAIN_CONTROL_LEVEL_YEAR 17
664 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
665 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
666 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
667 #define MAIN_CONTROL_TITLE_1 21
668 #define MAIN_CONTROL_TITLE_2 22
669 #define MAIN_CONTROL_TITLE_3 23
671 static char str_main_text_name[10];
672 static char str_main_text_first_level[10];
673 static char str_main_text_last_level[10];
674 static char str_main_text_level_number[10];
676 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
678 static char *main_text_name = str_main_text_name;
679 static char *main_text_first_level = str_main_text_first_level;
680 static char *main_text_last_level = str_main_text_last_level;
681 static char *main_text_level_number = str_main_text_level_number;
682 static char *main_text_levels = "Levelset";
683 static char *main_text_scores = "Hall Of Fame";
684 static char *main_text_editor = "Level Creator";
685 static char *main_text_info = "Info Screen";
686 static char *main_text_game = "Start Game";
687 static char *main_text_setup = "Setup";
688 static char *main_text_quit = "Quit";
689 static char *main_text_level_name = level.name;
690 static char *main_text_level_author = level.author;
691 static char *main_text_level_year = NULL;
692 static char *main_text_level_imported_from = NULL;
693 static char *main_text_level_imported_by = NULL;
694 static char *main_text_level_tested_by = NULL;
695 static char *main_text_title_1 = NULL;
696 static char *main_text_title_2 = NULL;
697 static char *main_text_title_3 = NULL;
699 extern char debug_xsn_mode[];
701 struct MainControlInfo
705 struct MenuPosInfo *pos_button;
708 struct TextPosInfo *pos_text;
711 struct TextPosInfo *pos_input;
715 static struct MainControlInfo main_controls[] =
719 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
720 &menu.main.text.name, &main_text_name,
721 &menu.main.input.name, &setup.player_name,
725 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
726 &menu.main.text.levels, &main_text_levels,
731 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
732 &menu.main.text.scores, &main_text_scores,
737 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
738 &menu.main.text.editor, &main_text_editor,
743 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
744 &menu.main.text.info, &main_text_info,
749 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
750 &menu.main.text.game, &main_text_game,
755 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
756 &menu.main.text.setup, &main_text_setup,
761 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
762 &menu.main.text.quit, &main_text_quit,
766 MAIN_CONTROL_PREV_LEVEL,
772 MAIN_CONTROL_NEXT_LEVEL,
778 MAIN_CONTROL_FIRST_LEVEL,
780 &menu.main.text.first_level, &main_text_first_level,
784 MAIN_CONTROL_LAST_LEVEL,
786 &menu.main.text.last_level, &main_text_last_level,
790 MAIN_CONTROL_LEVEL_NUMBER,
792 &menu.main.text.level_number, &main_text_level_number,
796 MAIN_CONTROL_LEVEL_INFO_1,
798 &menu.main.text.level_info_1, NULL,
802 MAIN_CONTROL_LEVEL_INFO_2,
804 &menu.main.text.level_info_2, NULL,
808 MAIN_CONTROL_LEVEL_NAME,
810 &menu.main.text.level_name, &main_text_level_name,
814 MAIN_CONTROL_LEVEL_AUTHOR,
816 &menu.main.text.level_author, &main_text_level_author,
820 MAIN_CONTROL_LEVEL_YEAR,
822 &menu.main.text.level_year, &main_text_level_year,
826 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
828 &menu.main.text.level_imported_from, &main_text_level_imported_from,
832 MAIN_CONTROL_LEVEL_IMPORTED_BY,
834 &menu.main.text.level_imported_by, &main_text_level_imported_by,
838 MAIN_CONTROL_LEVEL_TESTED_BY,
840 &menu.main.text.level_tested_by, &main_text_level_tested_by,
844 MAIN_CONTROL_TITLE_1,
846 &menu.main.text.title_1, &main_text_title_1,
850 MAIN_CONTROL_TITLE_2,
852 &menu.main.text.title_2, &main_text_title_2,
856 MAIN_CONTROL_TITLE_3,
858 &menu.main.text.title_3, &main_text_title_3,
871 static int getTitleScreenGraphic(int nr, boolean initial)
873 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
876 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
878 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
882 static int getTitleScreenGameMode(boolean initial)
884 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
888 static int getTitleMessageGameMode(boolean initial)
890 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
893 static int getTitleAnimMode(struct TitleControlInfo *tci)
895 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
897 return base + tci->local_nr;
901 static int getTitleScreenBackground(boolean initial)
903 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
908 static int getTitleMessageBackground(int nr, boolean initial)
910 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
914 static int getTitleBackground(int nr, boolean initial, boolean is_image)
916 int base = (is_image ?
917 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
918 IMG_BACKGROUND_TITLESCREEN_1) :
919 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
920 IMG_BACKGROUND_TITLEMESSAGE_1));
921 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
922 IMG_BACKGROUND_TITLE);
923 int graphic_local = base + nr;
925 if (graphic_info[graphic_local].bitmap != NULL)
926 return graphic_local;
928 if (graphic_info[graphic_global].bitmap != NULL)
929 return graphic_global;
931 return IMG_UNDEFINED;
934 static int getTitleSound(struct TitleControlInfo *tci)
936 boolean is_image = tci->is_image;
937 int initial = tci->initial;
938 int nr = tci->local_nr;
939 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
940 int base = (is_image ?
941 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
942 SND_BACKGROUND_TITLESCREEN_1) :
943 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
944 SND_BACKGROUND_TITLEMESSAGE_1));
945 int sound_global = menu.sound[mode];
946 int sound_local = base + nr;
949 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
950 nr, initial, is_image,
951 sound_global, getSoundListEntry(sound_global)->filename,
952 sound_local, getSoundListEntry(sound_local)->filename);
955 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
958 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
961 return SND_UNDEFINED;
964 static int getTitleMusic(struct TitleControlInfo *tci)
966 boolean is_image = tci->is_image;
967 int initial = tci->initial;
968 int nr = tci->local_nr;
969 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
970 int base = (is_image ?
971 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
972 MUS_BACKGROUND_TITLESCREEN_1) :
973 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
974 MUS_BACKGROUND_TITLEMESSAGE_1));
975 int music_global = menu.music[mode];
976 int music_local = base + nr;
979 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
980 nr, initial, is_image,
981 music_global, getMusicListEntry(music_global)->filename,
982 music_local, getMusicListEntry(music_local)->filename);
985 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
988 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
991 return MUS_UNDEFINED;
994 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
996 boolean is_image = tci->is_image;
997 boolean initial = tci->initial;
998 boolean first = tci->first;
999 int nr = tci->local_nr;
1000 struct TitleMessageInfo tmi;
1001 struct TitleFadingInfo ti;
1003 tmi = (is_image ? (initial ? (first ?
1004 titlescreen_initial_first[nr] :
1005 titlescreen_initial[nr])
1007 titlescreen_first[nr] :
1009 : (initial ? (first ?
1010 titlemessage_initial_first[nr] :
1011 titlemessage_initial[nr])
1013 titlemessage_first[nr] :
1014 titlemessage[nr])));
1016 ti.fade_mode = tmi.fade_mode;
1017 ti.fade_delay = tmi.fade_delay;
1018 ti.post_delay = tmi.post_delay;
1019 ti.auto_delay = tmi.auto_delay;
1020 ti.auto_delay_unit = tmi.auto_delay_unit;
1025 static int compareTitleControlInfo(const void *object1, const void *object2)
1027 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1028 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1031 if (tci1->initial != tci2->initial)
1032 compare_result = (tci1->initial ? -1 : +1);
1033 else if (tci1->sort_priority != tci2->sort_priority)
1034 compare_result = tci1->sort_priority - tci2->sort_priority;
1035 else if (tci1->is_image != tci2->is_image)
1036 compare_result = (tci1->is_image ? -1 : +1);
1038 compare_result = tci1->local_nr - tci2->local_nr;
1040 return compare_result;
1043 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1045 int nr, int sort_priority)
1047 title_controls[num_title_screens].is_image = is_image;
1048 title_controls[num_title_screens].initial = initial;
1049 title_controls[num_title_screens].local_nr = nr;
1050 title_controls[num_title_screens].sort_priority = sort_priority;
1052 title_controls[num_title_screens].first = FALSE; // will be set later
1054 num_title_screens++;
1057 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1061 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1063 int graphic = getTitleScreenGraphic(i, initial);
1064 Bitmap *bitmap = graphic_info[graphic].bitmap;
1065 int sort_priority = graphic_info[graphic].sort_priority;
1068 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1071 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1073 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1074 char *filename = getLevelSetTitleMessageFilename(i, initial);
1075 int sort_priority = tmi->sort_priority;
1077 if (filename != NULL)
1078 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1082 static void InitializeTitleControls(boolean show_title_initial)
1084 num_title_screens = 0;
1086 // 1st step: initialize title screens for game start (only when starting)
1087 if (show_title_initial)
1088 InitializeTitleControls_CheckTitleInfo(TRUE);
1090 // 2nd step: initialize title screens for current level set
1091 InitializeTitleControls_CheckTitleInfo(FALSE);
1093 // sort title screens according to sort_priority and title number
1094 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1095 compareTitleControlInfo);
1097 // mark first title screen
1098 title_controls[0].first = TRUE;
1101 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1103 return (pos != NULL && pos->x != -1 && pos->y != -1);
1106 static boolean visibleTextPos(struct TextPosInfo *pos)
1108 return (pos != NULL && pos->x != -1 && pos->y != -1);
1111 static void InitializeMainControls(void)
1113 boolean local_team_mode = (!network.enabled && setup.team_mode);
1116 // set main control text values to dynamically determined values
1117 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1119 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1120 menu.main.text.first_level.size));
1121 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1122 menu.main.text.last_level.size));
1123 strcpy(main_text_level_number, int2str(level_nr,
1124 menu.main.text.level_number.size));
1126 main_text_level_year = leveldir_current->year;
1127 main_text_level_imported_from = leveldir_current->imported_from;
1128 main_text_level_imported_by = leveldir_current->imported_by;
1129 main_text_level_tested_by = leveldir_current->tested_by;
1131 main_text_title_1 = getConfigProgramTitleString();
1132 main_text_title_2 = getConfigProgramCopyrightString();
1133 main_text_title_3 = getConfigProgramCompanyString();
1135 // set main control screen positions to dynamically determined values
1136 for (i = 0; main_controls[i].nr != -1; i++)
1138 struct MainControlInfo *mci = &main_controls[i];
1140 struct MenuPosInfo *pos_button = mci->pos_button;
1141 struct TextPosInfo *pos_text = mci->pos_text;
1142 struct TextPosInfo *pos_input = mci->pos_input;
1143 char *text = (mci->text ? *mci->text : NULL);
1144 char *input = (mci->input ? *mci->input : NULL);
1145 int button_graphic = mci->button_graphic;
1146 int font_text = (pos_text ? pos_text->font : -1);
1147 int font_input = (pos_input ? pos_input->font : -1);
1149 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1150 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1151 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1152 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1153 int text_chars = (text != NULL ? strlen(text) : 0);
1154 int input_chars = (input != NULL ? strlen(input) : 0);
1157 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1159 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1160 int text_width = font_text_width * text_chars;
1161 int text_height = font_text_height;
1162 int input_width = font_input_width * input_chars;
1163 int input_height = font_input_height;
1165 if (nr == MAIN_CONTROL_NAME)
1167 menu.main.input.name.width = input_width;
1168 menu.main.input.name.height = input_height;
1171 if (pos_button != NULL) // (x/y may be -1/-1 here)
1173 pos_button->width = button_width;
1174 pos_button->height = button_height;
1177 if (pos_text != NULL) // (x/y may be -1/-1 here)
1179 // calculate text size -- needed for text alignment
1180 boolean calculate_text_size = (text != NULL);
1182 if (pos_text->width == -1 || calculate_text_size)
1183 pos_text->width = text_width;
1184 if (pos_text->height == -1 || calculate_text_size)
1185 pos_text->height = text_height;
1187 if (visibleMenuPos(pos_button))
1189 if (pos_text->x == -1)
1190 pos_text->x = pos_button->x + pos_button->width;
1191 if (pos_text->y == -1)
1193 pos_button->y + (pos_button->height - pos_text->height) / 2;
1197 if (pos_input != NULL) // (x/y may be -1/-1 here)
1199 if (visibleTextPos(pos_text))
1201 if (pos_input->x == -1)
1202 pos_input->x = pos_text->x + pos_text->width;
1203 if (pos_input->y == -1)
1204 pos_input->y = pos_text->y;
1207 if (pos_input->width == -1)
1208 pos_input->width = input_width;
1209 if (pos_input->height == -1)
1210 pos_input->height = input_height;
1215 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1216 int graphic, boolean pressed)
1218 struct GraphicInfo *g = &graphic_info[graphic];
1221 int xoffset = (pressed ? g->pressed_xoffset : 0);
1222 int yoffset = (pressed ? g->pressed_yoffset : 0);
1224 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1226 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1227 g->width, g->height, dst_x, dst_y);
1230 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1231 boolean active_input,
1232 boolean pressed_button)
1236 for (i = 0; main_controls[i].nr != -1; i++)
1238 struct MainControlInfo *mci = &main_controls[i];
1240 if (mci->nr == nr || nr == -1)
1242 struct MenuPosInfo *pos_button = mci->pos_button;
1243 struct TextPosInfo *pos_text = mci->pos_text;
1244 struct TextPosInfo *pos_input = mci->pos_input;
1245 char *text = (mci->text ? *mci->text : NULL);
1246 char *input = (mci->input ? *mci->input : NULL);
1247 int button_graphic = mci->button_graphic;
1248 int font_text = (pos_text ? pos_text->font : -1);
1249 int font_input = (pos_input ? pos_input->font : -1);
1253 button_graphic = BUTTON_ACTIVE(button_graphic);
1254 font_text = FONT_ACTIVE(font_text);
1259 font_input = FONT_ACTIVE(font_input);
1262 if (visibleMenuPos(pos_button))
1264 struct MenuPosInfo *pos = pos_button;
1265 int x = mSX + pos->x;
1266 int y = mSY + pos->y;
1268 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1269 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1272 if (visibleTextPos(pos_text) && text != NULL)
1274 struct TextPosInfo *pos = pos_text;
1275 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1276 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1279 // (check why/if this is needed)
1280 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1282 DrawText(x, y, text, font_text);
1285 if (visibleTextPos(pos_input) && input != NULL)
1287 struct TextPosInfo *pos = pos_input;
1288 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1289 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1292 // (check why/if this is needed)
1293 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1295 DrawText(x, y, input, font_input);
1301 static void DrawCursorAndText_Main(int nr, boolean active_text,
1302 boolean pressed_button)
1304 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1308 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1309 boolean pressed_button)
1311 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1315 static struct MainControlInfo *getMainControlInfo(int nr)
1319 for (i = 0; main_controls[i].nr != -1; i++)
1320 if (main_controls[i].nr == nr)
1321 return &main_controls[i];
1326 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1331 int rect_x = ALIGNED_TEXT_XPOS(rect);
1332 int rect_y = ALIGNED_TEXT_YPOS(rect);
1334 return (x >= rect_x && x < rect_x + rect->width &&
1335 y >= rect_y && y < rect_y + rect->height);
1338 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1343 int rect_x = ALIGNED_TEXT_XPOS(rect);
1344 int rect_y = ALIGNED_TEXT_YPOS(rect);
1347 Debug("screens:insideTextPosRect",
1348 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1349 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1350 (x >= rect_x && x < rect_x + rect->width &&
1351 y >= rect_y && y < rect_y + rect->height));
1354 return (x >= rect_x && x < rect_x + rect->width &&
1355 y >= rect_y && y < rect_y + rect->height);
1358 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1360 int rect_width = preview->xsize * preview->tile_size;
1361 int rect_height = preview->ysize * preview->tile_size;
1362 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1363 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1365 return (x >= rect_x && x < rect_x + rect_width &&
1366 y >= rect_y && y < rect_y + rect_height);
1369 static void AdjustScrollbar(int id, int items_max, int items_visible,
1372 struct GadgetInfo *gi = screen_gadget[id];
1374 if (item_position > items_max - items_visible)
1375 item_position = items_max - items_visible;
1377 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1378 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1379 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1382 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1384 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1388 static void clearMenuListArea(void)
1390 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1392 // correct scrollbar position if placed outside menu (playfield) area
1393 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1394 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1396 // clear menu list area, but not title or scrollbar
1397 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1398 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1401 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1403 static int cursor_array[MAX_LEV_FIELDY];
1404 int x = amSX + TILEX * xpos;
1405 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1410 cursor_array[ypos] = graphic;
1412 graphic = cursor_array[ypos];
1416 graphic = BUTTON_ACTIVE(graphic);
1418 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1419 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1422 static void initCursor(int ypos, int graphic)
1424 drawCursorExt(0, ypos, FALSE, graphic);
1427 static void drawCursor(int ypos, boolean active)
1429 drawCursorExt(0, ypos, active, -1);
1432 static void drawCursorXY(int xpos, int ypos, int graphic)
1434 drawCursorExt(xpos, ypos, FALSE, graphic);
1437 static void drawChooseTreeCursor(int ypos, boolean active)
1439 drawCursorExt(0, ypos, active, -1);
1442 static int getChooseTreeEditFont(boolean active)
1444 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1447 static int getChooseTreeEditXPos(int pos)
1449 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1450 int xoffset = (has_scrollbar ? -1 : 0);
1451 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1452 int sx = amSX + xpos * TILEX;
1453 int font_nr = getChooseTreeEditFont(FALSE);
1454 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1456 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1459 static int getChooseTreeEditYPos(int ypos_raw)
1461 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1462 int sy = amSY + ypos * TILEY;
1467 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1469 int sx = getChooseTreeEditXPos(POS_LEFT);
1470 int sy = getChooseTreeEditYPos(ypos_raw);
1471 int font_nr = getChooseTreeEditFont(active);
1473 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1476 static void DrawHeadline(void)
1478 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1479 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1482 static void DrawTitleScreenImage(int nr, boolean initial)
1484 int graphic = getTitleScreenGraphic(nr, initial);
1485 Bitmap *bitmap = graphic_info[graphic].bitmap;
1486 int width = graphic_info[graphic].width;
1487 int height = graphic_info[graphic].height;
1488 int src_x = graphic_info[graphic].src_x;
1489 int src_y = graphic_info[graphic].src_y;
1495 if (width > WIN_XSIZE)
1497 // image width too large for window => center image horizontally
1498 src_x = (width - WIN_XSIZE) / 2;
1502 if (height > WIN_YSIZE)
1504 // image height too large for window => center image vertically
1505 src_y = (height - WIN_YSIZE) / 2;
1509 // always display title screens centered
1510 dst_x = (WIN_XSIZE - width) / 2;
1511 dst_y = (WIN_YSIZE - height) / 2;
1513 SetDrawBackgroundMask(REDRAW_ALL);
1514 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1516 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1518 if (DrawingOnBackground(dst_x, dst_y))
1519 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1521 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1523 redraw_mask = REDRAW_ALL;
1526 static void DrawTitleScreenMessage(int nr, boolean initial)
1528 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1529 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1531 if (filename == NULL)
1534 // force TITLE font on title message screen
1535 SetFontStatus(getTitleMessageGameMode(initial));
1537 // if chars *and* width set to "-1", automatically determine width
1538 if (tmi->chars == -1 && tmi->width == -1)
1539 tmi->width = viewport.window[game_status].width;
1541 // if lines *and* height set to "-1", automatically determine height
1542 if (tmi->lines == -1 && tmi->height == -1)
1543 tmi->height = viewport.window[game_status].height;
1545 // if chars set to "-1", automatically determine by text and font width
1546 if (tmi->chars == -1)
1547 tmi->chars = tmi->width / getFontWidth(tmi->font);
1549 tmi->width = tmi->chars * getFontWidth(tmi->font);
1551 // if lines set to "-1", automatically determine by text and font height
1552 if (tmi->lines == -1)
1553 tmi->lines = tmi->height / getFontHeight(tmi->font);
1555 tmi->height = tmi->lines * getFontHeight(tmi->font);
1557 // if x set to "-1", automatically determine by width and alignment
1559 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1561 // if y set to "-1", automatically determine by height and alignment
1563 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1565 SetDrawBackgroundMask(REDRAW_ALL);
1566 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1568 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1570 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1571 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1572 tmi->autowrap, tmi->centered, tmi->parse_comments);
1577 static void DrawTitleScreen(void)
1579 KeyboardAutoRepeatOff();
1581 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1584 static boolean CheckTitleScreen(boolean levelset_has_changed)
1586 static boolean show_title_initial = TRUE;
1587 boolean show_titlescreen = FALSE;
1589 // needed to be able to skip title screen, if no image or message defined
1590 InitializeTitleControls(show_title_initial);
1592 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1593 show_titlescreen = TRUE;
1595 // show initial title images and messages only once at program start
1596 show_title_initial = FALSE;
1598 return (show_titlescreen && num_title_screens > 0);
1601 void DrawMainMenu(void)
1603 static LevelDirTree *leveldir_last_valid = NULL;
1604 boolean levelset_has_changed = FALSE;
1605 int fade_mask = REDRAW_FIELD;
1607 LimitScreenUpdates(FALSE);
1609 FadeSetLeaveScreen();
1611 // do not fade out here -- function may continue and fade on editor screen
1614 FadeMenuSoundsAndMusic();
1616 ExpireSoundLoops(FALSE);
1618 KeyboardAutoRepeatOn();
1620 audio.sound_deactivated = FALSE;
1624 // needed if last screen was the playing screen, invoked from level editor
1625 if (level_editor_test_game)
1627 CloseDoor(DOOR_CLOSE_ALL);
1629 SetGameStatus(GAME_MODE_EDITOR);
1636 // leveldir_current may be invalid (level group, parent link, node copy)
1637 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1639 if (leveldir_current != leveldir_last_valid)
1641 UpdateLastPlayedLevels_TreeInfo();
1643 levelset_has_changed = TRUE;
1646 // store valid level series information
1647 leveldir_last_valid = leveldir_current;
1649 init_last = init; // switch to new busy animation
1651 // needed if last screen (level choice) changed graphics, sounds or music
1652 ReloadCustomArtwork(0);
1654 if (CheckTitleScreen(levelset_has_changed))
1656 SetGameStatus(GAME_MODE_TITLE);
1663 if (redraw_mask & REDRAW_ALL)
1664 fade_mask = REDRAW_ALL;
1667 fade_mask = REDRAW_ALL;
1671 // needed if different viewport properties defined for menues
1672 ChangeViewportPropertiesIfNeeded();
1674 SetDrawtoField(DRAW_TO_BACKBUFFER);
1676 // level_nr may have been set to value over handicap with level editor
1677 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1678 level_nr = leveldir_current->handicap_level;
1680 LoadLevel(level_nr);
1681 LoadScore(level_nr);
1683 SaveLevelSetup_SeriesInfo();
1685 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1686 SetDrawDeactivationMask(REDRAW_NONE);
1687 SetDrawBackgroundMask(REDRAW_FIELD);
1689 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1692 if (fade_mask == REDRAW_ALL)
1693 RedrawGlobalBorder();
1698 InitializeMainControls();
1700 DrawCursorAndText_Main(-1, FALSE, FALSE);
1701 DrawPreviewLevelInitial();
1702 DrawNetworkPlayers();
1704 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1707 if (TAPE_IS_EMPTY(tape))
1709 DrawCompleteVideoDisplay();
1711 PlayMenuSoundsAndMusic();
1713 // create gadgets for main menu screen
1714 FreeScreenGadgets();
1715 CreateScreenGadgets();
1717 // may be required if audio buttons shown on tape and changed in setup menu
1719 CreateGameButtons();
1721 // map gadgets for main menu screen
1723 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1724 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1726 // copy actual game door content to door double buffer for OpenDoor()
1727 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1728 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1730 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1732 DrawMaskedBorder(fade_mask);
1737 // update screen area with special editor door
1738 redraw_mask |= REDRAW_ALL;
1741 SetMouseCursor(CURSOR_DEFAULT);
1743 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1745 SyncEmscriptenFilesystem();
1748 static void gotoTopLevelDir(void)
1750 // move upwards until inside (but not above) top level directory
1751 while (leveldir_current->node_parent &&
1752 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1754 // write a "path" into level tree for easy navigation to last level
1755 if (leveldir_current->node_parent->node_group->cl_first == -1)
1757 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1758 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1759 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1760 int cl_first, cl_cursor;
1762 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1763 cl_cursor = leveldir_pos - cl_first;
1765 leveldir_current->node_parent->node_group->cl_first = cl_first;
1766 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1769 leveldir_current = leveldir_current->node_parent;
1773 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1775 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1777 return (use_frame_counter ? video.frame_counter : Counter());
1780 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1781 struct TitleFadingInfo *fi)
1783 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1786 static void ResetTitleAutoDelay(unsigned int *counter_var,
1787 struct TitleFadingInfo *fi)
1789 *counter_var = getAutoDelayCounter(fi);
1792 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1794 static unsigned int title_delay = 0;
1795 static int title_screen_nr = 0;
1796 static int last_sound = -1, last_music = -1;
1797 boolean return_to_main_menu = FALSE;
1798 struct TitleControlInfo *tci;
1801 if (button == MB_MENU_INITIALIZE)
1804 title_screen_nr = 0;
1805 tci = &title_controls[title_screen_nr];
1807 SetAnimStatus(getTitleAnimMode(tci));
1809 last_sound = SND_UNDEFINED;
1810 last_music = MUS_UNDEFINED;
1812 if (num_title_screens != 0)
1814 FadeSetEnterScreen();
1816 // use individual title fading instead of global "enter screen" fading
1817 fading = getTitleFading(tci);
1820 if (game_status_last_screen == GAME_MODE_INFO)
1822 if (num_title_screens == 0)
1824 // switch game mode from title screen mode back to info screen mode
1825 SetGameStatus(GAME_MODE_INFO);
1827 // store that last screen was info screen, not main menu screen
1828 game_status_last_screen = GAME_MODE_INFO;
1830 DrawInfoScreen_NotAvailable("Title screen information:",
1831 "No title screen for this level set.");
1836 FadeMenuSoundsAndMusic();
1838 FadeOut(REDRAW_ALL);
1840 // title screens may have different window size
1841 ChangeViewportPropertiesIfNeeded();
1843 // only required to update logic for redrawing global border
1847 DrawTitleScreenImage(tci->local_nr, tci->initial);
1849 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1851 sound = getTitleSound(tci);
1852 music = getTitleMusic(tci);
1854 if (sound != last_sound)
1855 PlayMenuSoundExt(sound);
1856 if (music != last_music)
1857 PlayMenuMusicExt(music);
1862 SetMouseCursor(CURSOR_NONE);
1866 ResetTitleAutoDelay(&title_delay, &fading);
1871 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1872 button = MB_MENU_CHOICE;
1874 if (button == MB_MENU_LEAVE)
1876 return_to_main_menu = TRUE;
1878 else if (button == MB_MENU_CHOICE)
1880 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1882 SetGameStatus(GAME_MODE_INFO);
1884 info_mode = INFO_MODE_MAIN;
1893 if (title_screen_nr < num_title_screens)
1895 tci = &title_controls[title_screen_nr];
1897 SetAnimStatus(getTitleAnimMode(tci));
1899 sound = getTitleSound(tci);
1900 music = getTitleMusic(tci);
1902 if (last_sound != SND_UNDEFINED && sound != last_sound)
1903 FadeSound(last_sound);
1904 if (last_music != MUS_UNDEFINED && music != last_music)
1907 fading = getTitleFading(tci);
1909 FadeOut(REDRAW_ALL);
1912 DrawTitleScreenImage(tci->local_nr, tci->initial);
1914 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1916 sound = getTitleSound(tci);
1917 music = getTitleMusic(tci);
1919 if (sound != last_sound)
1920 PlayMenuSoundExt(sound);
1921 if (music != last_music)
1922 PlayMenuMusicExt(music);
1929 ResetTitleAutoDelay(&title_delay, &fading);
1933 FadeMenuSoundsAndMusic();
1935 return_to_main_menu = TRUE;
1939 if (return_to_main_menu)
1941 SetMouseCursor(CURSOR_DEFAULT);
1943 // force full menu screen redraw after displaying title screens
1944 redraw_mask = REDRAW_ALL;
1946 if (game_status_last_screen == GAME_MODE_INFO)
1948 SetGameStatus(GAME_MODE_INFO);
1950 info_mode = INFO_MODE_MAIN;
1954 else // default: return to main menu
1956 SetGameStatus(GAME_MODE_MAIN);
1963 static void HandleMainMenu_ToggleTeamMode(void)
1965 setup.team_mode = !setup.team_mode;
1967 InitializeMainControls();
1968 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
1970 DrawPreviewPlayers();
1973 static void HandleMainMenu_SelectLevel(int step, int direction,
1974 int selected_level_nr)
1976 int old_level_nr = level_nr;
1979 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1980 new_level_nr = selected_level_nr;
1982 new_level_nr = old_level_nr + step * direction;
1984 if (new_level_nr < leveldir_current->first_level)
1985 new_level_nr = leveldir_current->first_level;
1986 if (new_level_nr > leveldir_current->last_level)
1987 new_level_nr = leveldir_current->last_level;
1989 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1991 // skipping levels is only allowed when trying to skip single level
1992 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1993 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1995 leveldir_current->handicap_level++;
1996 SaveLevelSetup_SeriesInfo();
1999 new_level_nr = leveldir_current->handicap_level;
2002 if (new_level_nr != old_level_nr)
2004 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2006 PlaySound(SND_MENU_ITEM_SELECTING);
2008 level_nr = new_level_nr;
2010 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2011 int2str(level_nr, menu.main.text.level_number.size),
2012 mci->pos_text->font);
2014 LoadLevel(level_nr);
2015 DrawPreviewLevelInitial();
2019 DrawCompleteVideoDisplay();
2021 SaveLevelSetup_SeriesInfo();
2023 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2025 // force redraw of playfield area (may be reset at this point)
2026 redraw_mask |= REDRAW_FIELD;
2030 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2032 static int choice = MAIN_CONTROL_GAME;
2033 static boolean button_pressed_last = FALSE;
2034 boolean button_pressed = FALSE;
2036 int i = 0; // needed to prevent compiler warning due to bad code below
2038 if (button == MB_MENU_INITIALIZE)
2040 DrawCursorAndText_Main(choice, TRUE, FALSE);
2045 if (mx || my) // mouse input
2049 for (i = 0; main_controls[i].nr != -1; i++)
2051 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2052 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2053 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2055 pos = main_controls[i].nr;
2061 // check if level preview was clicked
2062 if (insidePreviewRect(&preview, mx - SX, my - SY))
2063 pos = MAIN_CONTROL_GAME;
2065 // handle pressed/unpressed state for active/inactive menu buttons
2066 // (if pos != -1, "i" contains index position corresponding to "pos")
2068 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2069 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2070 button_pressed = TRUE;
2072 if (button_pressed != button_pressed_last)
2074 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2077 PlaySound(SND_MENU_BUTTON_PRESSING);
2079 PlaySound(SND_MENU_BUTTON_RELEASING);
2082 else if (dx || dy) // keyboard input
2084 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2085 choice == MAIN_CONTROL_SETUP))
2086 button = MB_MENU_CHOICE;
2091 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2093 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2095 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2097 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2099 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2101 CloseDoor(DOOR_CLOSE_2);
2103 SetGameStatus(GAME_MODE_LEVELNR);
2105 DrawChooseLevelNr();
2107 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2113 PlaySound(SND_MENU_ITEM_ACTIVATING);
2115 DrawCursorAndText_Main(choice, FALSE, FALSE);
2116 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2122 if (choice == MAIN_CONTROL_NAME)
2124 // special case: cursor left or right pressed -- toggle team mode
2125 HandleMainMenu_ToggleTeamMode();
2127 else if (choice != MAIN_CONTROL_INFO &&
2128 choice != MAIN_CONTROL_SETUP)
2130 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2136 PlaySound(SND_MENU_ITEM_SELECTING);
2138 if (pos == MAIN_CONTROL_NAME)
2141 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2143 // special case: menu text "name/team" clicked -- toggle team mode
2144 HandleMainMenu_ToggleTeamMode();
2148 if (setup.multiple_users)
2150 CloseDoor(DOOR_CLOSE_2);
2152 SetGameStatus(GAME_MODE_NAMES);
2154 DrawChoosePlayerName();
2158 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2164 else if (pos == MAIN_CONTROL_LEVELS)
2168 CloseDoor(DOOR_CLOSE_2);
2170 SetGameStatus(GAME_MODE_LEVELS);
2172 SaveLevelSetup_LastSeries();
2173 SaveLevelSetup_SeriesInfo();
2175 // restore level set if chosen from "last played level set" menu
2176 RestoreLastPlayedLevels(&leveldir_current);
2178 if (setup.internal.choose_from_top_leveldir)
2181 DrawChooseLevelSet();
2184 else if (pos == MAIN_CONTROL_SCORES)
2186 CloseDoor(DOOR_CLOSE_2);
2188 SetGameStatus(GAME_MODE_SCORES);
2190 DrawHallOfFame(level_nr);
2192 else if (pos == MAIN_CONTROL_EDITOR)
2194 if (leveldir_current->readonly &&
2195 setup.editor.show_read_only_warning)
2196 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2198 CloseDoor(DOOR_CLOSE_ALL);
2200 SetGameStatus(GAME_MODE_EDITOR);
2202 FadeSetEnterScreen();
2206 else if (pos == MAIN_CONTROL_INFO)
2208 CloseDoor(DOOR_CLOSE_2);
2210 SetGameStatus(GAME_MODE_INFO);
2212 info_mode = INFO_MODE_MAIN;
2216 else if (pos == MAIN_CONTROL_GAME)
2218 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2220 else if (pos == MAIN_CONTROL_SETUP)
2222 CloseDoor(DOOR_CLOSE_2);
2224 SetGameStatus(GAME_MODE_SETUP);
2226 setup_mode = SETUP_MODE_MAIN;
2230 else if (pos == MAIN_CONTROL_QUIT)
2232 SaveLevelSetup_LastSeries();
2233 SaveLevelSetup_SeriesInfo();
2235 #if defined(PLATFORM_EMSCRIPTEN)
2236 Request("Close the browser window to quit!", REQ_CONFIRM);
2238 if (!setup.ask_on_quit_program ||
2239 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2240 SetGameStatus(GAME_MODE_QUIT);
2246 button_pressed_last = button_pressed;
2250 // ============================================================================
2251 // info screen functions
2252 // ============================================================================
2254 static struct TokenInfo *info_info;
2255 static int num_info_info; // number of info entries shown on screen
2256 static int max_info_info; // total number of info entries in list
2258 static void execInfoTitleScreen(void)
2260 info_mode = INFO_MODE_TITLE;
2265 static void execInfoElements(void)
2267 info_mode = INFO_MODE_ELEMENTS;
2272 static void execInfoMusic(void)
2274 info_mode = INFO_MODE_MUSIC;
2279 static void execInfoCredits(void)
2281 info_mode = INFO_MODE_CREDITS;
2286 static void execInfoProgram(void)
2288 info_mode = INFO_MODE_PROGRAM;
2293 static void execInfoVersion(void)
2295 info_mode = INFO_MODE_VERSION;
2300 static void execInfoLevelSet(void)
2302 info_mode = INFO_MODE_LEVELSET;
2307 static void execExitInfo(void)
2309 SetGameStatus(GAME_MODE_MAIN);
2314 static struct TokenInfo info_info_main[] =
2316 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2317 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2318 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2319 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2320 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2321 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2322 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2323 { TYPE_EMPTY, NULL, "" },
2324 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2329 static int getMenuTextFont(int type)
2331 if (type & (TYPE_SWITCH |
2345 static struct TokenInfo *setup_info;
2346 static struct TokenInfo setup_info_input[];
2348 static struct TokenInfo *menu_info;
2350 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2351 int screen_pos, int menu_info_pos_raw,
2354 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2355 struct TokenInfo *ti = &token_info[pos];
2356 int xpos = MENU_SCREEN_START_XPOS;
2357 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2358 int font_nr = getMenuTextFont(ti->type);
2360 if (setup_mode == SETUP_MODE_INPUT)
2361 font_nr = FONT_MENU_1;
2364 font_nr = FONT_ACTIVE(font_nr);
2366 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2368 if (ti->type & ~TYPE_SKIP_ENTRY)
2369 drawCursor(screen_pos, active);
2372 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2375 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2378 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2381 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2384 static char *window_size_text;
2385 static char *scaling_type_text;
2386 static char *network_server_text;
2388 static void drawSetupValue(int, int);
2390 static void drawMenuInfoList(int first_entry, int num_page_entries,
2391 int max_page_entries)
2395 if (first_entry + num_page_entries > max_page_entries)
2398 clearMenuListArea();
2400 for (i = 0; i < num_page_entries; i++)
2402 int menu_info_pos = first_entry + i;
2403 struct TokenInfo *si = &menu_info[menu_info_pos];
2404 void *value_ptr = si->value;
2406 // set some entries to "unchangeable" according to other variables
2407 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2408 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2409 (value_ptr == &setup.sound_music && !audio.music_available) ||
2410 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2411 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2412 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2413 si->type |= TYPE_GHOSTED;
2415 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2416 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2417 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2418 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2419 else if (si->type & ~TYPE_SKIP_ENTRY)
2420 initCursor(i, IMG_MENU_BUTTON);
2422 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2424 if (si->type & TYPE_STRING)
2428 if (value_ptr == &network_server_text)
2429 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2431 if (gadget_id != -1)
2433 struct GadgetInfo *gi = screen_gadget[gadget_id];
2434 int xpos = MENU_SCREEN_START_XPOS;
2435 int ypos = MENU_SCREEN_START_YPOS + i;
2436 int x = mSX + xpos * 32;
2437 int y = mSY + ypos * 32;
2439 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2443 if (si->type & TYPE_VALUE &&
2444 menu_info == setup_info)
2445 drawSetupValue(i, menu_info_pos);
2449 static void DrawInfoScreen_Main(void)
2451 int fade_mask = REDRAW_FIELD;
2454 if (redraw_mask & REDRAW_ALL)
2455 fade_mask = REDRAW_ALL;
2458 fade_mask = REDRAW_ALL;
2461 FadeMenuSoundsAndMusic();
2463 FreeScreenGadgets();
2464 CreateScreenGadgets();
2466 // (needed after displaying title screens which disable auto repeat)
2467 KeyboardAutoRepeatOn();
2469 FadeSetLeaveScreen();
2473 // needed if different viewport properties defined for info screen
2474 ChangeViewportPropertiesIfNeeded();
2476 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2480 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2482 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2484 info_info = info_info_main;
2486 // determine maximal number of info entries that can be displayed on screen
2488 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2491 // determine maximal number of info entries available for menu of info screen
2493 for (i = 0; info_info[i].type != 0; i++)
2496 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2498 MapScreenGadgets(max_info_info);
2500 PlayMenuSoundsAndMusic();
2502 DrawMaskedBorder(fade_mask);
2507 static void changeSetupValue(int, int, int);
2509 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2510 int mode, int num_page_entries,
2511 int max_page_entries)
2513 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2514 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2515 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2516 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2517 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2518 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2519 int *num_page_entries_last = num_page_entries_all_last[game_status];
2520 int *choice_store = choice_stores[game_status];
2521 int *first_entry_store = first_entry_stores[game_status];
2522 int choice = choice_store[mode]; // starts with 0
2523 int first_entry = first_entry_store[mode]; // starts with 0
2525 int y = choice - first_entry;
2527 boolean position_set_by_scrollbar = (dx == 999);
2528 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2531 if (button == MB_MENU_INITIALIZE)
2533 // check if number of menu page entries has changed (may happen by change
2534 // of custom artwork definition value for 'list_size' for this menu screen)
2535 // (in this case, the last menu position most probably has to be corrected)
2536 if (num_page_entries != num_page_entries_last[mode])
2538 choice_store[mode] = first_entry_store[mode] = 0;
2540 choice = first_entry = 0;
2543 num_page_entries_last[mode] = num_page_entries;
2546 // advance to first valid menu entry
2547 while (choice < num_page_entries &&
2548 menu_info[choice].type & TYPE_SKIP_ENTRY)
2551 if (position_set_by_scrollbar)
2552 first_entry = first_entry_store[mode] = dy;
2554 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2555 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2557 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2559 if (choice < first_entry)
2561 choice = first_entry;
2563 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2566 else if (choice > first_entry + num_page_entries - 1)
2568 choice = first_entry + num_page_entries - 1;
2570 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2574 choice_store[mode] = choice;
2576 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2580 else if (button == MB_MENU_LEAVE)
2582 PlaySound(SND_MENU_ITEM_SELECTING);
2584 for (i = 0; i < max_page_entries; i++)
2586 if (menu_info[i].type & TYPE_LEAVE_MENU)
2588 void (*menu_callback_function)(void) = menu_info[i].value;
2592 menu_callback_function();
2594 break; // absolutely needed because function changes 'menu_info'!
2601 if (mx || my) // mouse input
2603 x = (mx - mSX) / 32;
2604 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2606 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2608 // move cursor instead of scrolling when already at start/end of list
2609 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2611 else if (dy == +1 * SCROLL_LINE &&
2612 first_entry + num_page_entries == max_page_entries)
2615 // handle scrolling screen one line or page
2617 y + dy > num_page_entries - 1)
2619 boolean redraw = FALSE;
2621 if (ABS(dy) == SCROLL_PAGE)
2622 step = num_page_entries - 1;
2624 if (dy < 0 && first_entry > 0)
2626 // scroll page/line up
2628 first_entry -= step;
2629 if (first_entry < 0)
2634 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2636 // scroll page/line down
2638 first_entry += step;
2639 if (first_entry + num_page_entries > max_page_entries)
2640 first_entry = MAX(0, max_page_entries - num_page_entries);
2647 choice += first_entry - first_entry_store[mode];
2649 if (choice < first_entry)
2651 choice = first_entry;
2653 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2656 else if (choice > first_entry + num_page_entries - 1)
2658 choice = first_entry + num_page_entries - 1;
2660 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2663 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2667 if (choice < first_entry ||
2668 choice > first_entry + num_page_entries - 1)
2669 first_entry += SIGN(dy);
2672 first_entry_store[mode] = first_entry;
2673 choice_store[mode] = choice;
2675 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2677 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2679 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2680 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2688 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2690 if (menu_info[choice].type & menu_navigation_type ||
2691 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2692 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2693 menu_info[choice].type & TYPE_PLAYER)
2694 button = MB_MENU_CHOICE;
2699 // jump to next non-empty menu entry (up or down)
2700 while (first_entry + y > 0 &&
2701 first_entry + y < max_page_entries - 1 &&
2702 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2705 if (!IN_VIS_MENU(x, y))
2707 choice += y - y_old;
2709 if (choice < first_entry)
2710 first_entry = choice;
2711 else if (choice > first_entry + num_page_entries - 1)
2712 first_entry = choice - num_page_entries + 1;
2714 if (first_entry >= 0 &&
2715 first_entry + num_page_entries <= max_page_entries)
2717 first_entry_store[mode] = first_entry;
2719 if (choice < first_entry)
2720 choice = first_entry;
2721 else if (choice > first_entry + num_page_entries - 1)
2722 choice = first_entry + num_page_entries - 1;
2724 choice_store[mode] = choice;
2726 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2728 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2730 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2731 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2738 if (!anyScrollbarGadgetActive() &&
2739 IN_VIS_MENU(x, y) &&
2740 mx < mx_right_border &&
2741 y >= 0 && y < num_page_entries)
2745 if (first_entry + y != choice &&
2746 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2748 PlaySound(SND_MENU_ITEM_ACTIVATING);
2750 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2751 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2753 choice = choice_store[mode] = first_entry + y;
2757 PlaySound(SND_MENU_ITEM_SELECTING);
2759 for (i = 0; menu_info[i].type != 0; i++)
2761 if (menu_info[i].type & TYPE_LEAVE_MENU)
2763 void (*menu_callback_function)(void) = menu_info[i].value;
2767 menu_callback_function();
2769 // absolutely needed because function changes 'menu_info'!
2777 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2779 PlaySound(SND_MENU_ITEM_SELECTING);
2781 // when selecting key headline, execute function for key value change
2782 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2783 menu_info[first_entry + y + 1].type & TYPE_KEY)
2786 // when selecting string value, execute function for list selection
2787 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2788 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2791 // when selecting string value, execute function for text input gadget
2792 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2793 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2796 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2798 void (*menu_callback_function)(void) =
2799 menu_info[first_entry + y].value;
2801 FadeSetFromType(menu_info[first_entry + y].type);
2803 menu_callback_function();
2805 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2807 void (*gadget_callback_function)(void) =
2808 menu_info[first_entry + y].value;
2810 gadget_callback_function();
2812 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2813 menu_info == setup_info)
2815 changeSetupValue(y, first_entry + y, dx);
2821 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2823 menu_info = info_info;
2825 HandleMenuScreen(mx, my, dx, dy, button,
2826 info_mode, num_info_info, max_info_info);
2829 static int getMenuFontSpacing(int spacing_height, int font_nr)
2831 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2833 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2837 static int getMenuTextSpacing(int spacing_height, int font_nr)
2839 return (getMenuFontSpacing(spacing_height, font_nr) +
2840 EXTRA_SPACING(game_status));
2843 static int getMenuTextStep(int spacing_height, int font_nr)
2845 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2848 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2850 int font_title = MENU_INFO_FONT_TITLE;
2851 int font_error = FONT_TEXT_2;
2852 int font_foot = MENU_INFO_FONT_FOOT;
2853 int spacing_title = menu.headline1_spacing_info[info_mode];
2854 int ystep_title = getMenuTextStep(spacing_title, font_title);
2855 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2856 int ystart2 = ystart1 + ystep_title;
2857 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2859 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2861 FadeOut(REDRAW_FIELD);
2866 DrawTextSCentered(ystart1, font_title, text_title);
2867 DrawTextSCentered(ystart2, font_error, text_error);
2869 DrawTextSCentered(ybottom, font_foot,
2870 "Press any key or button for info menu");
2872 FadeIn(REDRAW_FIELD);
2875 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2877 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2878 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2879 int font_title = MENU_INFO_FONT_TITLE;
2880 int font_foot = MENU_INFO_FONT_FOOT;
2881 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2882 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2883 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2884 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2885 int ystep = MENU_SCREEN_INFO_YSTEP;
2886 int element, action, direction;
2894 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2895 infoscreen_step[i] = infoscreen_frame[i] = 0;
2900 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2902 DrawTextSCentered(ybottom, font_foot,
2903 "Press any key or button for next page");
2909 while (helpanim_info[j].element != HELPANIM_LIST_END)
2911 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2916 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2925 j += infoscreen_step[i - start];
2927 element = helpanim_info[j].element;
2928 action = helpanim_info[j].action;
2929 direction = helpanim_info[j].direction;
2932 element = EL_UNKNOWN;
2934 if (action != -1 && direction != -1)
2935 graphic = el_act_dir2img(element, action, direction);
2936 else if (action != -1)
2937 graphic = el_act2img(element, action);
2938 else if (direction != -1)
2939 graphic = el_dir2img(element, direction);
2941 graphic = el2img(element);
2943 delay = helpanim_info[j++].delay;
2948 if (infoscreen_frame[i - start] == 0)
2951 infoscreen_frame[i - start] = delay - 1;
2955 sync_frame = delay - infoscreen_frame[i - start];
2956 infoscreen_frame[i - start]--;
2959 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2961 if (!infoscreen_frame[i - start])
2962 infoscreen_step[i - start] = 0;
2966 if (!infoscreen_frame[i - start])
2967 infoscreen_step[i - start]++;
2968 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2974 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2976 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2977 graphic, sync_frame, USE_MASKING);
2980 DrawInfoScreen_HelpText(element, action, direction, i - start);
2985 redraw_mask |= REDRAW_FIELD;
2990 static char *getHelpText(int element, int action, int direction)
2992 char token[MAX_LINE_LEN];
2994 strcpy(token, element_info[element].token_name);
2997 strcat(token, element_action_info[action].suffix);
2999 if (direction != -1)
3000 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3002 return getHashEntry(helptext_info, token);
3005 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3007 int font_nr = FONT_INFO_ELEMENTS;
3008 int font_width = getFontWidth(font_nr);
3009 int font_height = getFontHeight(font_nr);
3010 int yoffset = (TILEX - 2 * font_height) / 2;
3011 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3012 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3013 int ystep = TILEY + 4;
3014 int pad_left = xstart - SX;
3015 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3016 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3017 int max_lines_per_text = 2;
3020 if (action != -1 && direction != -1) // element.action.direction
3021 text = getHelpText(element, action, direction);
3023 if (text == NULL && action != -1) // element.action
3024 text = getHelpText(element, action, -1);
3026 if (text == NULL && direction != -1) // element.direction
3027 text = getHelpText(element, -1, direction);
3029 if (text == NULL) // base element
3030 text = getHelpText(element, -1, -1);
3032 if (text == NULL) // not found
3033 text = "No description available";
3035 if (strlen(text) <= max_chars_per_line) // only one line of text
3036 ystart += getFontHeight(font_nr) / 2;
3038 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3039 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3040 TRUE, FALSE, FALSE);
3043 static void DrawInfoScreen_TitleScreen(void)
3045 SetGameStatus(GAME_MODE_TITLE);
3050 void HandleInfoScreen_TitleScreen(int button)
3052 HandleTitleScreen(0, 0, 0, 0, button);
3055 static void DrawInfoScreen_Elements(void)
3057 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3059 FadeOut(REDRAW_FIELD);
3064 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3066 FadeIn(REDRAW_FIELD);
3069 void HandleInfoScreen_Elements(int button)
3071 static unsigned int info_delay = 0;
3072 static int num_anims;
3073 static int num_pages;
3075 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3078 if (button == MB_MENU_INITIALIZE)
3080 boolean new_element = TRUE;
3084 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3086 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3088 else if (new_element)
3091 new_element = FALSE;
3095 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3099 if (button == MB_MENU_LEAVE)
3101 PlaySound(SND_MENU_ITEM_SELECTING);
3103 info_mode = INFO_MODE_MAIN;
3108 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3110 if (button != MB_MENU_INITIALIZE)
3112 PlaySound(SND_MENU_ITEM_SELECTING);
3117 if (page >= num_pages)
3119 FadeMenuSoundsAndMusic();
3121 info_mode = INFO_MODE_MAIN;
3128 FadeSetNextScreen();
3130 if (button != MB_MENU_INITIALIZE)
3131 FadeOut(REDRAW_FIELD);
3133 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3135 if (button != MB_MENU_INITIALIZE)
3136 FadeIn(REDRAW_FIELD);
3140 if (DelayReached(&info_delay, GameFrameDelay))
3141 if (page < num_pages)
3142 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3144 PlayMenuSoundIfLoop();
3148 static void DrawInfoScreen_Music(void)
3150 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3152 FadeOut(REDRAW_FIELD);
3159 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3161 FadeIn(REDRAW_FIELD);
3164 void HandleInfoScreen_Music(int button)
3166 static struct MusicFileInfo *list = NULL;
3167 int font_title = MENU_INFO_FONT_TITLE;
3168 int font_head = MENU_INFO_FONT_HEAD;
3169 int font_text = MENU_INFO_FONT_TEXT;
3170 int font_foot = MENU_INFO_FONT_FOOT;
3171 int spacing_title = menu.headline1_spacing_info[info_mode];
3172 int spacing_head = menu.headline2_spacing_info[info_mode];
3173 int ystep_title = getMenuTextStep(spacing_title, font_title);
3174 int ystep_head = getMenuTextStep(spacing_head, font_head);
3175 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3176 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3178 if (button == MB_MENU_INITIALIZE)
3180 list = music_file_info;
3184 FadeMenuSoundsAndMusic();
3189 DrawTextSCentered(ystart, font_title,
3190 "No music info for this level set.");
3192 DrawTextSCentered(ybottom, font_foot,
3193 "Press any key or button for info menu");
3199 if (button == MB_MENU_LEAVE)
3201 PlaySound(SND_MENU_ITEM_SELECTING);
3203 FadeMenuSoundsAndMusic();
3205 info_mode = INFO_MODE_MAIN;
3210 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3212 if (button != MB_MENU_INITIALIZE)
3214 PlaySound(SND_MENU_ITEM_SELECTING);
3222 FadeMenuSoundsAndMusic();
3224 info_mode = INFO_MODE_MAIN;
3230 FadeMenuSoundsAndMusic();
3232 if (list != music_file_info)
3233 FadeSetNextScreen();
3235 if (button != MB_MENU_INITIALIZE)
3236 FadeOut(REDRAW_FIELD);
3243 int sound = list->music;
3245 if (sound_info[sound].loop)
3246 PlaySoundLoop(sound);
3250 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3254 int music = list->music;
3256 if (music_info[music].loop)
3257 PlayMusicLoop(music);
3261 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3264 ystart += ystep_title;
3266 if (!strEqual(list->title, UNKNOWN_NAME))
3268 if (!strEqual(list->title_header, UNKNOWN_NAME))
3270 DrawTextSCentered(ystart, font_head, list->title_header);
3271 ystart += ystep_head;
3274 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3275 ystart += ystep_head;
3278 if (!strEqual(list->artist, UNKNOWN_NAME))
3280 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3281 DrawTextSCentered(ystart, font_head, list->artist_header);
3283 DrawTextSCentered(ystart, font_head, "by");
3285 ystart += ystep_head;
3287 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3288 ystart += ystep_head;
3291 if (!strEqual(list->album, UNKNOWN_NAME))
3293 if (!strEqual(list->album_header, UNKNOWN_NAME))
3294 DrawTextSCentered(ystart, font_head, list->album_header);
3296 DrawTextSCentered(ystart, font_head, "from the album");
3298 ystart += ystep_head;
3300 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3301 ystart += ystep_head;
3304 if (!strEqual(list->year, UNKNOWN_NAME))
3306 if (!strEqual(list->year_header, UNKNOWN_NAME))
3307 DrawTextSCentered(ystart, font_head, list->year_header);
3309 DrawTextSCentered(ystart, font_head, "from the year");
3311 ystart += ystep_head;
3313 DrawTextFCentered(ystart, font_text, "%s", list->year);
3314 ystart += ystep_head;
3317 DrawTextSCentered(ybottom, FONT_TEXT_4,
3318 "Press any key or button for next page");
3320 if (button != MB_MENU_INITIALIZE)
3321 FadeIn(REDRAW_FIELD);
3324 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3325 PlaySoundLoop(list->music);
3328 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3330 int font_title = MENU_INFO_FONT_TITLE;
3331 int font_head = MENU_INFO_FONT_HEAD;
3332 int font_text = MENU_INFO_FONT_TEXT;
3333 int font_foot = MENU_INFO_FONT_FOOT;
3334 int spacing_title = menu.headline1_spacing_info[info_mode];
3335 int spacing_head = menu.headline2_spacing_info[info_mode];
3336 int spacing_para = menu.paragraph_spacing_info[info_mode];
3337 int spacing_line = menu.line_spacing_info[info_mode];
3338 int ystep_title = getMenuTextStep(spacing_title, font_title);
3339 int ystep_head = getMenuTextStep(spacing_head, font_head);
3340 int ystep_para = getMenuTextStep(spacing_para, font_text);
3341 int ystep_line = getMenuTextStep(spacing_line, font_text);
3342 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3343 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3348 DrawTextSCentered(ystart, font_title, "Credits:");
3349 ystart += ystep_title;
3353 DrawTextSCentered(ystart, font_head,
3354 "Special thanks to");
3355 ystart += ystep_head;
3356 DrawTextSCentered(ystart, font_text,
3358 ystart += ystep_head;
3359 DrawTextSCentered(ystart, font_head,
3361 ystart += ystep_head;
3362 DrawTextSCentered(ystart, font_text,
3363 "\"Boulder Dash\"");
3364 ystart += ystep_head;
3365 DrawTextSCentered(ystart, font_head,
3367 ystart += ystep_head;
3368 DrawTextSCentered(ystart, font_text,
3370 ystart += ystep_head;
3371 DrawTextSCentered(ystart, font_head,
3373 ystart += ystep_head;
3374 DrawTextSCentered(ystart, font_text,
3375 "First Star Software");
3377 else if (screen_nr == 1)
3379 DrawTextSCentered(ystart, font_head,
3380 "Special thanks to");
3381 ystart += ystep_head;
3382 DrawTextSCentered(ystart, font_text,
3383 "Klaus Heinz & Volker Wertich");
3384 ystart += ystep_head;
3385 DrawTextSCentered(ystart, font_head,
3387 ystart += ystep_head;
3388 DrawTextSCentered(ystart, font_text,
3389 "\"Emerald Mine\"");
3390 ystart += ystep_head;
3391 DrawTextSCentered(ystart, font_head,
3393 ystart += ystep_head;
3394 DrawTextSCentered(ystart, font_text,
3396 ystart += ystep_head;
3397 DrawTextSCentered(ystart, font_head,
3399 ystart += ystep_head;
3400 DrawTextSCentered(ystart, font_text,
3403 else if (screen_nr == 2)
3405 DrawTextSCentered(ystart, font_head,
3406 "Special thanks to");
3407 ystart += ystep_head;
3408 DrawTextSCentered(ystart, font_text,
3409 "Michael Stopp & Philip Jespersen");
3410 ystart += ystep_head;
3411 DrawTextSCentered(ystart, font_head,
3413 ystart += ystep_head;
3414 DrawTextSCentered(ystart, font_text,
3416 ystart += ystep_head;
3417 DrawTextSCentered(ystart, font_head,
3419 ystart += ystep_head;
3420 DrawTextSCentered(ystart, font_text,
3422 ystart += ystep_head;
3423 DrawTextSCentered(ystart, font_head,
3425 ystart += ystep_head;
3426 DrawTextSCentered(ystart, font_text,
3427 "Digital Integration");
3429 else if (screen_nr == 3)
3431 DrawTextSCentered(ystart, font_head,
3432 "Special thanks to");
3433 ystart += ystep_head;
3434 DrawTextSCentered(ystart, font_text,
3435 "Hiroyuki Imabayashi");
3436 ystart += ystep_head;
3437 DrawTextSCentered(ystart, font_head,
3439 ystart += ystep_head;
3440 DrawTextSCentered(ystart, font_text,
3442 ystart += ystep_head;
3443 DrawTextSCentered(ystart, font_head,
3445 ystart += ystep_head;
3446 DrawTextSCentered(ystart, font_text,
3448 ystart += ystep_head;
3449 DrawTextSCentered(ystart, font_head,
3451 ystart += ystep_head;
3452 DrawTextSCentered(ystart, font_text,
3455 else if (screen_nr == 4)
3457 DrawTextSCentered(ystart, font_head,
3458 "Special thanks to");
3459 ystart += ystep_head;
3460 DrawTextSCentered(ystart, font_text,
3462 ystart += ystep_head;
3463 DrawTextSCentered(ystart, font_head,
3465 ystart += ystep_head;
3466 DrawTextSCentered(ystart, font_text,
3467 "J\xfcrgen Bonhagen");
3468 ystart += ystep_head;
3469 DrawTextSCentered(ystart, font_head,
3470 "for the continuous creation");
3471 ystart += ystep_line;
3472 DrawTextSCentered(ystart, font_head,
3473 "of outstanding level sets");
3475 else if (screen_nr == 5)
3477 DrawTextSCentered(ystart, font_head,
3479 ystart += ystep_head;
3480 DrawTextSCentered(ystart, font_text,
3482 ystart += ystep_head;
3483 DrawTextSCentered(ystart, font_head,
3484 "for ideas and inspiration by");
3485 ystart += ystep_head;
3486 DrawTextSCentered(ystart, font_text,
3488 ystart += ystep_para;
3490 DrawTextSCentered(ystart, font_head,
3492 ystart += ystep_head;
3493 DrawTextSCentered(ystart, font_text,
3495 ystart += ystep_head;
3496 DrawTextSCentered(ystart, font_head,
3497 "for ideas and inspiration by");
3498 ystart += ystep_head;
3499 DrawTextSCentered(ystart, font_text,
3502 else if (screen_nr == 6)
3504 DrawTextSCentered(ystart, font_head,
3506 ystart += ystep_head;
3507 DrawTextSCentered(ystart, font_text,
3509 ystart += ystep_head;
3510 DrawTextSCentered(ystart, font_head,
3511 "for the code base used for the");
3512 ystart += ystep_line;
3513 DrawTextSCentered(ystart, font_head,
3514 "native Emerald Mine engine");
3516 else if (screen_nr == 7)
3518 DrawTextSCentered(ystart, font_head,
3520 ystart += ystep_head;
3521 DrawTextSCentered(ystart, font_text,
3523 ystart += ystep_head;
3524 DrawTextSCentered(ystart, font_head,
3525 "for the initial DOS port");
3526 ystart += ystep_para;
3528 DrawTextSCentered(ystart, font_head,
3530 ystart += ystep_head;
3531 DrawTextSCentered(ystart, font_text,
3533 ystart += ystep_head;
3534 DrawTextSCentered(ystart, font_head,
3535 "for some additional toons");
3537 else if (screen_nr == 8)
3539 DrawTextSCentered(ystart, font_head,
3540 "And not to forget:");
3541 ystart += ystep_head;
3542 DrawTextSCentered(ystart, font_head,
3544 ystart += ystep_head;
3545 DrawTextSCentered(ystart, font_text,
3546 "All those who contributed");
3547 ystart += ystep_line;
3548 DrawTextSCentered(ystart, font_text,
3549 "levels to this game");
3550 ystart += ystep_line;
3551 DrawTextSCentered(ystart, font_text,
3555 DrawTextSCentered(ybottom, font_foot,
3556 "Press any key or button for next page");
3559 static void DrawInfoScreen_Credits(void)
3561 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3563 FadeMenuSoundsAndMusic();
3565 FadeOut(REDRAW_FIELD);
3567 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3569 FadeIn(REDRAW_FIELD);
3572 void HandleInfoScreen_Credits(int button)
3574 static int screen_nr = 0;
3575 int num_screens = 9;
3577 if (button == MB_MENU_INITIALIZE)
3581 // DrawInfoScreen_CreditsScreen(screen_nr);
3584 if (button == MB_MENU_LEAVE)
3586 PlaySound(SND_MENU_ITEM_SELECTING);
3588 info_mode = INFO_MODE_MAIN;
3593 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3595 if (button != MB_MENU_INITIALIZE)
3597 PlaySound(SND_MENU_ITEM_SELECTING);
3602 if (screen_nr >= num_screens)
3604 FadeMenuSoundsAndMusic();
3606 info_mode = INFO_MODE_MAIN;
3613 FadeSetNextScreen();
3615 if (button != MB_MENU_INITIALIZE)
3616 FadeOut(REDRAW_FIELD);
3618 DrawInfoScreen_CreditsScreen(screen_nr);
3620 if (button != MB_MENU_INITIALIZE)
3621 FadeIn(REDRAW_FIELD);
3625 PlayMenuSoundIfLoop();
3629 static void DrawInfoScreen_Program(void)
3631 int font_title = MENU_INFO_FONT_TITLE;
3632 int font_head = MENU_INFO_FONT_HEAD;
3633 int font_text = MENU_INFO_FONT_TEXT;
3634 int font_foot = MENU_INFO_FONT_FOOT;
3635 int spacing_title = menu.headline1_spacing_info[info_mode];
3636 int spacing_head = menu.headline2_spacing_info[info_mode];
3637 int spacing_para = menu.paragraph_spacing_info[info_mode];
3638 int spacing_line = menu.line_spacing_info[info_mode];
3639 int ystep_title = getMenuTextStep(spacing_title, font_title);
3640 int ystep_head = getMenuTextStep(spacing_head, font_head);
3641 int ystep_para = getMenuTextStep(spacing_para, font_text);
3642 int ystep_line = getMenuTextStep(spacing_line, font_text);
3643 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3644 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3646 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3648 FadeOut(REDRAW_FIELD);
3653 DrawTextSCentered(ystart, font_title, "Program Information:");
3654 ystart += ystep_title;
3656 DrawTextSCentered(ystart, font_head,
3657 "This game is Freeware!");
3658 ystart += ystep_head;
3659 DrawTextSCentered(ystart, font_head,
3660 "If you like it, send e-mail to:");
3661 ystart += ystep_head;
3662 DrawTextSCentered(ystart, font_text,
3663 setup.internal.program_email);
3664 ystart += ystep_para;
3666 DrawTextSCentered(ystart, font_head,
3667 "More information and levels:");
3668 ystart += ystep_head;
3669 DrawTextSCentered(ystart, font_text,
3670 setup.internal.program_website);
3671 ystart += ystep_para;
3673 DrawTextSCentered(ystart, font_head,
3674 "If you have created new levels,");
3675 ystart += ystep_line;
3676 DrawTextSCentered(ystart, font_head,
3677 "send them to me to include them!");
3678 ystart += ystep_head;
3679 DrawTextSCentered(ystart, font_head,
3682 DrawTextSCentered(ybottom, font_foot,
3683 "Press any key or button for info menu");
3685 FadeIn(REDRAW_FIELD);
3688 void HandleInfoScreen_Program(int button)
3690 if (button == MB_MENU_LEAVE)
3692 PlaySound(SND_MENU_ITEM_SELECTING);
3694 info_mode = INFO_MODE_MAIN;
3699 else if (button == MB_MENU_CHOICE)
3701 PlaySound(SND_MENU_ITEM_SELECTING);
3703 FadeMenuSoundsAndMusic();
3705 info_mode = INFO_MODE_MAIN;
3710 PlayMenuSoundIfLoop();
3714 static void DrawInfoScreen_Version(void)
3716 int font_title = MENU_INFO_FONT_TITLE;
3717 int font_head = MENU_INFO_FONT_HEAD;
3718 int font_text = MENU_INFO_FONT_TEXT;
3719 int font_foot = MENU_INFO_FONT_FOOT;
3720 int spacing_title = menu.headline1_spacing_info[info_mode];
3721 int spacing_head = menu.headline2_spacing_info[info_mode];
3722 int spacing_para = menu.paragraph_spacing_info[info_mode];
3723 int spacing_line = menu.line_spacing_info[info_mode];
3724 int xstep = getFontWidth(font_text);
3725 int ystep_title = getMenuTextStep(spacing_title, font_title);
3726 int ystep_head = getMenuTextStep(spacing_head, font_head);
3727 int ystep_para = getMenuTextStep(spacing_para, font_text);
3728 int ystep_line = getMenuTextStep(spacing_line, font_text);
3729 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3730 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3731 int xstart1 = mSX - SX + 2 * xstep;
3732 int xstart2 = mSX - SX + 18 * xstep;
3733 int xstart3 = mSX - SX + 28 * xstep;
3734 SDL_version sdl_version_compiled;
3735 const SDL_version *sdl_version_linked;
3736 int driver_name_len = 10;
3737 SDL_version sdl_version_linked_ext;
3738 const char *driver_name = NULL;
3740 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3742 FadeOut(REDRAW_FIELD);
3747 DrawTextSCentered(ystart, font_title, "Version Information:");
3748 ystart += ystep_title;
3750 DrawTextF(xstart1, ystart, font_head, "Name");
3751 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3752 ystart += ystep_line;
3754 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3756 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3757 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3758 ystart += ystep_line;
3760 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3761 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3762 ystart += ystep_line;
3766 DrawTextF(xstart1, ystart, font_head, "Version");
3767 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3768 ystart += ystep_line;
3771 DrawTextF(xstart1, ystart, font_head, "Platform");
3772 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3774 PLATFORM_XX_BIT_STRING);
3775 ystart += ystep_line;
3777 DrawTextF(xstart1, ystart, font_head, "Target");
3778 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3779 ystart += ystep_line;
3781 DrawTextF(xstart1, ystart, font_head, "Source date");
3782 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3783 ystart += ystep_line;
3785 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3786 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3787 ystart += ystep_para;
3789 DrawTextF(xstart1, ystart, font_head, "Library");
3790 DrawTextF(xstart2, ystart, font_head, "compiled");
3791 DrawTextF(xstart3, ystart, font_head, "linked");
3792 ystart += ystep_head;
3794 SDL_VERSION(&sdl_version_compiled);
3795 SDL_GetVersion(&sdl_version_linked_ext);
3796 sdl_version_linked = &sdl_version_linked_ext;
3798 DrawTextF(xstart1, ystart, font_text, "SDL");
3799 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3800 sdl_version_compiled.major,
3801 sdl_version_compiled.minor,
3802 sdl_version_compiled.patch);
3803 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3804 sdl_version_linked->major,
3805 sdl_version_linked->minor,
3806 sdl_version_linked->patch);
3807 ystart += ystep_line;
3809 SDL_IMAGE_VERSION(&sdl_version_compiled);
3810 sdl_version_linked = IMG_Linked_Version();
3812 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3813 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3814 sdl_version_compiled.major,
3815 sdl_version_compiled.minor,
3816 sdl_version_compiled.patch);
3817 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3818 sdl_version_linked->major,
3819 sdl_version_linked->minor,
3820 sdl_version_linked->patch);
3821 ystart += ystep_line;
3823 SDL_MIXER_VERSION(&sdl_version_compiled);
3824 sdl_version_linked = Mix_Linked_Version();
3826 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3827 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3828 sdl_version_compiled.major,
3829 sdl_version_compiled.minor,
3830 sdl_version_compiled.patch);
3831 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3832 sdl_version_linked->major,
3833 sdl_version_linked->minor,
3834 sdl_version_linked->patch);
3835 ystart += ystep_line;
3837 SDL_NET_VERSION(&sdl_version_compiled);
3838 sdl_version_linked = SDLNet_Linked_Version();
3840 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3841 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3842 sdl_version_compiled.major,
3843 sdl_version_compiled.minor,
3844 sdl_version_compiled.patch);
3845 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3846 sdl_version_linked->major,
3847 sdl_version_linked->minor,
3848 sdl_version_linked->patch);
3849 ystart += ystep_para;
3851 DrawTextF(xstart1, ystart, font_head, "Driver");
3852 DrawTextF(xstart2, ystart, font_head, "Requested");
3853 DrawTextF(xstart3, ystart, font_head, "Used");
3854 ystart += ystep_head;
3857 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3859 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3860 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3861 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3862 ystart += ystep_line;
3865 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3867 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3868 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3869 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3870 ystart += ystep_line;
3873 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3875 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3876 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3877 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3879 DrawTextSCentered(ybottom, font_foot,
3880 "Press any key or button for info menu");
3882 FadeIn(REDRAW_FIELD);
3885 void HandleInfoScreen_Version(int button)
3887 if (button == MB_MENU_LEAVE)
3889 PlaySound(SND_MENU_ITEM_SELECTING);
3891 info_mode = INFO_MODE_MAIN;
3896 else if (button == MB_MENU_CHOICE)
3898 PlaySound(SND_MENU_ITEM_SELECTING);
3900 FadeMenuSoundsAndMusic();
3902 info_mode = INFO_MODE_MAIN;
3907 PlayMenuSoundIfLoop();
3911 static void DrawInfoScreen_LevelSet(void)
3913 struct TitleMessageInfo *tmi = &readme;
3914 char *filename = getLevelSetInfoFilename();
3915 char *title = "Level Set Information:";
3916 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3917 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3919 if (filename == NULL)
3921 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3926 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3928 FadeOut(REDRAW_FIELD);
3933 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3935 // if x position set to "-1", automatically determine by playfield width
3937 tmi->x = SXSIZE / 2;
3939 // if y position set to "-1", use static default value
3943 // if width set to "-1", automatically determine by playfield width
3944 if (tmi->width == -1)
3945 tmi->width = SXSIZE - 2 * TILEX;
3947 // if height set to "-1", automatically determine by playfield height
3948 if (tmi->height == -1)
3949 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3951 // if chars set to "-1", automatically determine by text and font width
3952 if (tmi->chars == -1)
3953 tmi->chars = tmi->width / getFontWidth(tmi->font);
3955 tmi->width = tmi->chars * getFontWidth(tmi->font);
3957 // if lines set to "-1", automatically determine by text and font height
3958 if (tmi->lines == -1)
3959 tmi->lines = tmi->height / getFontHeight(tmi->font);
3961 tmi->height = tmi->lines * getFontHeight(tmi->font);
3963 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3964 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3965 tmi->autowrap, tmi->centered, tmi->parse_comments);
3967 DrawTextSCentered(ybottom, FONT_TEXT_4,
3968 "Press any key or button for info menu");
3970 FadeIn(REDRAW_FIELD);
3973 static void HandleInfoScreen_LevelSet(int button)
3975 if (button == MB_MENU_LEAVE)
3977 PlaySound(SND_MENU_ITEM_SELECTING);
3979 info_mode = INFO_MODE_MAIN;
3984 else if (button == MB_MENU_CHOICE)
3986 PlaySound(SND_MENU_ITEM_SELECTING);
3988 FadeMenuSoundsAndMusic();
3990 info_mode = INFO_MODE_MAIN;
3995 PlayMenuSoundIfLoop();
3999 static void DrawInfoScreen(void)
4001 if (info_mode == INFO_MODE_TITLE)
4002 DrawInfoScreen_TitleScreen();
4003 else if (info_mode == INFO_MODE_ELEMENTS)
4004 DrawInfoScreen_Elements();
4005 else if (info_mode == INFO_MODE_MUSIC)
4006 DrawInfoScreen_Music();
4007 else if (info_mode == INFO_MODE_CREDITS)
4008 DrawInfoScreen_Credits();
4009 else if (info_mode == INFO_MODE_PROGRAM)
4010 DrawInfoScreen_Program();
4011 else if (info_mode == INFO_MODE_VERSION)
4012 DrawInfoScreen_Version();
4013 else if (info_mode == INFO_MODE_LEVELSET)
4014 DrawInfoScreen_LevelSet();
4016 DrawInfoScreen_Main();
4018 if (info_mode != INFO_MODE_MAIN &&
4019 info_mode != INFO_MODE_TITLE &&
4020 info_mode != INFO_MODE_MUSIC)
4021 PlayMenuSoundsAndMusic();
4024 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4026 if (info_mode == INFO_MODE_TITLE)
4027 HandleInfoScreen_TitleScreen(button);
4028 else if (info_mode == INFO_MODE_ELEMENTS)
4029 HandleInfoScreen_Elements(button);
4030 else if (info_mode == INFO_MODE_MUSIC)
4031 HandleInfoScreen_Music(button);
4032 else if (info_mode == INFO_MODE_CREDITS)
4033 HandleInfoScreen_Credits(button);
4034 else if (info_mode == INFO_MODE_PROGRAM)
4035 HandleInfoScreen_Program(button);
4036 else if (info_mode == INFO_MODE_VERSION)
4037 HandleInfoScreen_Version(button);
4038 else if (info_mode == INFO_MODE_LEVELSET)
4039 HandleInfoScreen_LevelSet(button);
4041 HandleInfoScreen_Main(mx, my, dx, dy, button);
4045 // ============================================================================
4046 // change name functions
4047 // ============================================================================
4049 struct ApiRenamePlayerThreadData
4055 static void *CreateThreadData_ApiRenamePlayer(void)
4057 struct ApiRenamePlayerThreadData *data =
4058 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4060 data->player_name = getStringCopy(setup.player_name);
4061 data->player_uuid = getStringCopy(setup.player_uuid);
4066 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4068 struct ApiRenamePlayerThreadData *data = data_raw;
4070 checked_free(data->player_name);
4071 checked_free(data->player_uuid);
4075 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4078 struct ApiRenamePlayerThreadData *data = data_raw;
4079 char *player_name_raw = data->player_name;
4080 char *player_uuid_raw = data->player_uuid;
4082 request->hostname = setup.api_server_hostname;
4083 request->port = API_SERVER_PORT;
4084 request->method = API_SERVER_METHOD;
4085 request->uri = API_SERVER_URI_RENAME;
4087 char *player_name = getEscapedJSON(player_name_raw);
4088 char *player_uuid = getEscapedJSON(player_uuid_raw);
4090 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4093 " \"game_version\": \"%s\",\n"
4094 " \"game_platform\": \"%s\",\n"
4095 " \"name\": \"%s\",\n"
4096 " \"uuid\": \"%s\"\n"
4098 getPasswordJSON(setup.api_server_password),
4099 getProgramRealVersionString(),
4100 getProgramPlatformString(),
4104 checked_free(player_name);
4105 checked_free(player_uuid);
4107 ConvertHttpRequestBodyToServerEncoding(request);
4112 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4115 // nothing to do here
4118 #if defined(PLATFORM_EMSCRIPTEN)
4119 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4120 void *buffer, unsigned int size)
4122 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4124 if (response != NULL)
4126 HandleResponse_ApiRenamePlayer(response, data_raw);
4128 checked_free(response);
4132 Error("server response too large to handle (%d bytes)", size);
4135 FreeThreadData_ApiRenamePlayer(data_raw);
4138 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4139 int code, const char *status)
4141 Error("server failed to handle request: %d %s", code, status);
4143 FreeThreadData_ApiRenamePlayer(data_raw);
4146 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4147 int bytes, int size)
4149 // nothing to do here
4152 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4155 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4157 FreeThreadData_ApiRenamePlayer(data_raw);
4162 emscripten_async_wget2_data(request->uri,
4167 Emscripten_ApiRenamePlayer_Loaded,
4168 Emscripten_ApiRenamePlayer_Failed,
4169 Emscripten_ApiRenamePlayer_Progress);
4174 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4175 struct HttpResponse *response,
4178 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4181 if (!DoHttpRequest(request, response))
4183 Error("HTTP request failed: %s", GetHttpError());
4188 if (!HTTP_SUCCESS(response->status_code))
4190 Error("server failed to handle request: %d %s",
4191 response->status_code,
4192 response->status_text);
4197 HandleResponse_ApiRenamePlayer(response, data_raw);
4200 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4201 struct HttpResponse *response,
4204 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4206 FreeThreadData_ApiRenamePlayer(data_raw);
4210 static int ApiRenamePlayerThread(void *data_raw)
4212 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4213 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4215 #if defined(PLATFORM_EMSCRIPTEN)
4216 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4218 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4221 checked_free(request);
4222 checked_free(response);
4227 static void ApiRenamePlayerAsThread(void)
4229 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4231 ExecuteAsThread(ApiRenamePlayerThread,
4232 "ApiRenamePlayer", data,
4233 "rename player on server");
4237 // ============================================================================
4238 // type name functions
4239 // ============================================================================
4241 static TreeInfo *type_name_node = NULL;
4242 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4243 static int type_name_nr = 0;
4245 static int getPlayerNameColor(char *name)
4247 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4250 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4253 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4254 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4255 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4256 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4257 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4258 int font_width = getFontWidth(font_nr);
4260 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4262 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4264 pos->width = strlen(text) * font_width;
4265 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4267 DrawText(sx, sy, text, font_nr);
4270 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4272 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4274 *pos = *mci->pos_input;
4276 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4278 TreeInfo *ti = player_name_current;
4279 int first_entry = ti->cl_first;
4280 int entry_pos = first_entry + ti->cl_cursor;
4281 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4282 int xpos = MENU_SCREEN_START_XPOS;
4283 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4285 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4286 type_name_nr = entry_pos;
4288 strcpy(name, type_name_node->name);
4292 pos->width = MAX_PLAYER_NAME_LEN * 32;
4296 type_name_nr = user.nr;
4298 strcpy(name, setup.player_name);
4301 strcpy(type_name_last, name);
4303 if (strEqual(name, EMPTY_PLAYER_NAME))
4306 *xpos = strlen(name);
4309 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4311 // change name of edited user in global list of user names
4312 setString(&global.user_names[type_name_nr], name);
4314 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4316 TreeInfo *node = type_name_node;
4318 // change name of edited user in local menu tree structure
4319 setString(&node->name, name);
4320 setString(&node->name_sorting, name);
4322 node->color = getPlayerNameColor(name);
4323 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4327 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4330 boolean reset_setup = strEqual(name, "");
4331 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4332 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4335 strcpy(name, type_name_last);
4337 if (strEqual(name, ""))
4338 strcpy(name, EMPTY_PLAYER_NAME);
4340 setTypeNameValues_Name(name, pos);
4342 // if player name not changed, no further action required
4343 if (strEqual(name, type_name_last))
4346 // redraw player name before (possibly) opening request dialogs
4347 drawTypeNameText(name, pos, FALSE);
4349 int last_user_nr = user.nr;
4351 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4353 // save setup of currently active user (may differ from edited user)
4356 // temporarily change active user to edited user
4357 user.nr = type_name_nr;
4359 // load setup of edited user (unless creating user with current setup)
4361 !Request("Use current setup values for the new player?", REQ_ASK))
4364 setup.player_uuid = getStringCopy(getUUID());
4367 char *setup_filename = getSetupFilename();
4368 boolean setup_exists = fileExists(setup_filename);
4370 // change name of edited user in setup structure
4371 strcpy(setup.player_name, name);
4373 // save setup of edited user
4376 // change name of edited user on score server
4377 ApiRenamePlayerAsThread();
4379 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4383 if (Request("Reset setup values for this player?", REQ_ASK))
4385 // remove setup config file
4386 unlink(setup_filename);
4388 // set player name to default player name
4391 // update player name used by name typing functions
4392 strcpy(name, setup.player_name);
4394 setTypeNameValues_Name(name, pos);
4397 else if (remove_user && type_name_nr != 0)
4399 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4401 char *user_dir = getUserGameDataDir();
4402 char *user_dir_removed =
4403 getStringCat3WithSeparator(user_dir, "REMOVED",
4404 getCurrentTimestamp(), ".");
4406 if (rename(user_dir, user_dir_removed) != 0)
4407 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4409 checked_free(user_dir_removed);
4412 else if (create_user && type_name_nr != 0 && !setup_exists)
4414 if (Request("Create empty level set for the new player?", REQ_ASK))
4416 char *levelset_subdir = getNewUserLevelSubdir();
4418 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4420 AddUserLevelSetToLevelInfo(levelset_subdir);
4422 LevelDirTree *leveldir_current_last = leveldir_current;
4424 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4427 // set level number of newly created level set to default value
4428 LoadLevelSetup_SeriesInfo();
4430 // set newly created level set as current level set for new user
4431 SaveLevelSetup_LastSeries();
4432 SaveLevelSetup_SeriesInfo();
4434 leveldir_current = leveldir_current_last;
4438 Request("Creating new level set failed!", REQ_CONFIRM);
4443 // restore currently active user
4444 user.nr = last_user_nr;
4446 // restore setup of currently active user
4449 // restore last level set of currently active user
4450 LoadLevelSetup_LastSeries();
4451 LoadLevelSetup_SeriesInfo();
4455 static void HandleTypeNameExt(boolean initialize, Key key)
4457 static struct TextPosInfo pos_name = { 0 };
4458 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4459 static int xpos = 0;
4460 struct TextPosInfo *pos = &pos_name;
4461 char key_char = getValidConfigValueChar(getCharFromKey(key));
4462 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4463 boolean active = TRUE;
4467 getTypeNameValues(name, pos, &xpos);
4469 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4470 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4472 StartTextInput(sx, sy, pos->width, pos->height);
4474 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4476 name[xpos] = key_char;
4481 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4487 else if (key == KSYM_Return || key == KSYM_Escape)
4489 boolean changed = (key == KSYM_Return);
4493 setTypeNameValues(name, pos, changed);
4498 drawTypeNameText(name, pos, active);
4502 SetGameStatus(game_status_last_screen);
4504 if (game_status == GAME_MODE_MAIN)
4505 InitializeMainControls();
4509 static void DrawTypeName(void)
4511 HandleTypeNameExt(TRUE, 0);
4514 void HandleTypeName(Key key)
4516 HandleTypeNameExt(FALSE, key);
4520 // ============================================================================
4521 // tree menu functions
4522 // ============================================================================
4524 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4526 if (game_status != GAME_MODE_SETUP ||
4527 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4530 int max_text_size = 0;
4533 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4534 max_text_size = MAX(max_text_size, strlen(node->name));
4536 int num_entries = numTreeInfoInGroup(ti);
4537 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4538 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4539 int text_width = max_text_size * getFontWidth(font_nr);
4540 int button_width = SC_MENUBUTTON_XSIZE;
4541 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4542 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4543 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4544 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4545 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4546 int align_xoffset = MAX(0, align_xoffset_raw);
4548 return align_xoffset;
4551 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4553 if (game_status != GAME_MODE_SETUP ||
4554 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4557 int num_entries = numTreeInfoInGroup(ti);
4558 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4559 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4560 int font_height = getFontHeight(font_nr);
4561 int text_height = font_height * num_page_entries;
4562 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4563 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4564 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4565 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4566 int align_yoffset = MAX(0, align_yoffset_raw);
4568 return align_yoffset;
4571 static void DrawChooseTree(TreeInfo **ti_ptr)
4573 int fade_mask = REDRAW_FIELD;
4576 fade_mask = REDRAW_ALL;
4578 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4580 if (game_status == GAME_MODE_SETUP)
4584 else // GAME_MODE_LEVELS
4586 SetGameStatus(GAME_MODE_MAIN);
4596 FreeScreenGadgets();
4597 CreateScreenGadgets();
4601 // needed if different viewport properties defined for choosing level (set)
4602 ChangeViewportPropertiesIfNeeded();
4604 if (game_status == GAME_MODE_NAMES)
4605 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4606 else if (game_status == GAME_MODE_LEVELNR)
4607 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4608 else if (game_status == GAME_MODE_LEVELS)
4609 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4613 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4615 MapScreenTreeGadgets(*ti_ptr);
4616 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4618 DrawMaskedBorder(fade_mask);
4623 static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
4625 int num_entries = numTreeInfoInGroup(ti);
4626 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4627 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4628 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4629 int first_entry = ti->cl_first;
4630 int entry_pos = first_entry + y;
4631 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4632 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4633 int font_color = MENU_CHOOSE_TREE_COLOR(node, active);
4634 int font_nr = MENU_CHOOSE_TREE_FONT(font_color);
4635 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4636 int xpos = MENU_SCREEN_START_XPOS;
4637 int ypos = MENU_SCREEN_START_YPOS + y;
4638 int startx = amSX + xpos * 32;
4639 int starty = amSY + ypos * 32;
4640 int startx_text = startx + font_xoffset;
4641 int endx_text = amSX + screen_width;
4642 int max_text_size = endx_text - startx_text;
4643 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4644 char buffer[max_buffer_len + 1];
4646 strncpy(buffer, node->name, max_buffer_len);
4647 buffer[max_buffer_len] = '\0';
4649 DrawText(startx, starty, buffer, font_nr);
4652 static void drawChooseTreeList(int first_entry, int num_page_entries,
4656 char *title_string = NULL;
4657 int yoffset_sets = MENU_TITLE1_YPOS;
4658 int yoffset_setup = 16;
4659 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4660 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4662 title_string = ti->infotext;
4664 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4666 clearMenuListArea();
4668 for (i = 0; i < num_page_entries; i++)
4670 TreeInfo *node, *node_first;
4671 int entry_pos = first_entry + i;
4673 node_first = getTreeInfoFirstGroupEntry(ti);
4674 node = getTreeInfoFromPos(node_first, entry_pos);
4676 drawChooseTreeText(i, FALSE, ti);
4678 if (node->parent_link)
4679 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4680 else if (node->level_group)
4681 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4683 initCursor(i, IMG_MENU_BUTTON);
4685 if (game_status == GAME_MODE_NAMES)
4686 drawChooseTreeEdit(i, FALSE);
4689 redraw_mask |= REDRAW_FIELD;
4692 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4694 TreeInfo *node, *node_first;
4695 int x, last_redraw_mask = redraw_mask;
4696 int ypos = MENU_TITLE2_YPOS;
4697 int font_nr = FONT_TITLE_2;
4699 if (ti->type == TREE_TYPE_LEVEL_NR)
4700 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4702 if (ti->type != TREE_TYPE_LEVEL_DIR)
4705 node_first = getTreeInfoFirstGroupEntry(ti);
4706 node = getTreeInfoFromPos(node_first, entry_pos);
4708 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4710 if (node->parent_link)
4711 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4712 node->node_parent->name);
4713 else if (node->level_group)
4714 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4716 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4717 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4718 node->levels, (node->levels > 1 ? "levels" : "level"),
4721 // let BackToFront() redraw only what is needed
4722 redraw_mask = last_redraw_mask;
4723 for (x = 0; x < SCR_FIELDX; x++)
4724 MarkTileDirty(x, 1);
4727 static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
4729 drawChooseTreeCursor(y, active);
4730 drawChooseTreeText(y, active, ti);
4733 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4736 TreeInfo *ti = *ti_ptr;
4737 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4738 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4739 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4740 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4741 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4743 int y = ti->cl_cursor;
4744 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4745 int num_entries = numTreeInfoInGroup(ti);
4746 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4747 boolean position_set_by_scrollbar = (dx == 999);
4749 if (button == MB_MENU_INITIALIZE)
4751 int num_entries = numTreeInfoInGroup(ti);
4752 int entry_pos = getPosFromTreeInfo(ti);
4754 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4755 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4757 if (ti->cl_first == -1)
4759 // only on initialization
4760 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4761 ti->cl_cursor = entry_pos - ti->cl_first;
4763 else if (ti->cl_cursor >= num_page_entries ||
4764 (num_entries > num_page_entries &&
4765 num_entries - ti->cl_first < num_page_entries))
4767 // only after change of list size (by custom graphic configuration)
4768 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4769 ti->cl_cursor = entry_pos - ti->cl_first;
4772 if (position_set_by_scrollbar)
4775 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4778 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4779 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4780 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4784 else if (button == MB_MENU_LEAVE)
4788 PlaySound(SND_MENU_ITEM_SELECTING);
4790 if (ti->node_parent)
4792 *ti_ptr = ti->node_parent;
4793 DrawChooseTree(ti_ptr);
4795 else if (game_status == GAME_MODE_SETUP)
4797 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4798 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4799 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4801 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4802 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4803 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4804 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4805 execSetupGraphics();
4806 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4807 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4808 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4810 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4811 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4812 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4813 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4814 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4815 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4816 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4817 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4824 if (game_status == GAME_MODE_LEVELNR)
4826 int new_level_nr = atoi(level_number_current->identifier);
4828 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4831 SetGameStatus(GAME_MODE_MAIN);
4839 if (mx || my) // mouse input
4841 x = (mx - amSX) / 32;
4842 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4844 if (game_status == GAME_MODE_NAMES)
4845 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4847 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4849 // move cursor instead of scrolling when already at start/end of list
4850 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4852 else if (dy == +1 * SCROLL_LINE &&
4853 ti->cl_first + num_page_entries == num_entries)
4856 // handle scrolling screen one line or page
4857 if (ti->cl_cursor + dy < 0 ||
4858 ti->cl_cursor + dy > num_page_entries - 1)
4860 boolean redraw = FALSE;
4862 if (ABS(dy) == SCROLL_PAGE)
4863 step = num_page_entries - 1;
4865 if (dy < 0 && ti->cl_first > 0)
4867 // scroll page/line up
4869 ti->cl_first -= step;
4870 if (ti->cl_first < 0)
4875 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4877 // scroll page/line down
4879 ti->cl_first += step;
4880 if (ti->cl_first + num_page_entries > num_entries)
4881 ti->cl_first = MAX(0, num_entries - num_page_entries);
4888 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4889 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4890 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4892 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4899 // handle moving cursor one line
4900 y = ti->cl_cursor + dy;
4905 TreeInfo *node_first, *node_cursor;
4906 int entry_pos = ti->cl_first + y;
4908 node_first = getTreeInfoFirstGroupEntry(ti);
4909 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4911 if (node_cursor->node_group)
4915 PlaySound(SND_MENU_ITEM_SELECTING);
4917 node_cursor->cl_first = ti->cl_first;
4918 node_cursor->cl_cursor = ti->cl_cursor;
4919 *ti_ptr = node_cursor->node_group;
4920 DrawChooseTree(ti_ptr);
4925 else if (dx == -1 && ti->node_parent)
4929 PlaySound(SND_MENU_ITEM_SELECTING);
4931 *ti_ptr = ti->node_parent;
4932 DrawChooseTree(ti_ptr);
4937 if (!anyScrollbarGadgetActive() &&
4938 IN_VIS_MENU(x, y) &&
4939 mx < mx_right_border &&
4940 y >= 0 && y < num_page_entries)
4944 if (game_status == GAME_MODE_NAMES)
4946 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4947 drawChooseTreeEdit(y, TRUE);
4950 if (y != ti->cl_cursor)
4952 PlaySound(SND_MENU_ITEM_ACTIVATING);
4954 drawChooseTreeCursorAndText(ti->cl_cursor, FALSE, ti);
4955 drawChooseTreeCursorAndText(y, TRUE, ti);
4956 drawChooseTreeInfo(ti->cl_first + y, ti);
4962 if (game_status == GAME_MODE_SETUP)
4964 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4965 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4966 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4968 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4969 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4970 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4971 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4972 execSetupGraphics();
4973 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4974 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4975 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4977 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4978 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4979 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4980 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4981 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4982 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4983 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4984 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4993 TreeInfo *node_first, *node_cursor;
4994 int entry_pos = ti->cl_first + y;
4996 PlaySound(SND_MENU_ITEM_SELECTING);
4998 node_first = getTreeInfoFirstGroupEntry(ti);
4999 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5001 if (node_cursor->node_group)
5005 node_cursor->cl_first = ti->cl_first;
5006 node_cursor->cl_cursor = ti->cl_cursor;
5007 *ti_ptr = node_cursor->node_group;
5008 DrawChooseTree(ti_ptr);
5010 else if (node_cursor->parent_link)
5014 *ti_ptr = node_cursor->node_parent;
5015 DrawChooseTree(ti_ptr);
5021 node_cursor->cl_first = ti->cl_first;
5022 node_cursor->cl_cursor = ti->cl_cursor;
5023 *ti_ptr = node_cursor;
5025 if (ti->type == TREE_TYPE_LEVEL_DIR)
5027 LoadLevelSetup_SeriesInfo();
5029 SaveLevelSetup_LastSeries();
5030 SaveLevelSetup_SeriesInfo();
5034 if (game_status == GAME_MODE_SETUP)
5036 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5037 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5038 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5040 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5041 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5042 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5043 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5044 execSetupGraphics();
5045 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5046 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5047 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5049 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5050 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5051 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5052 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5053 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5054 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5055 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5056 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5063 if (game_status == GAME_MODE_LEVELNR)
5065 int new_level_nr = atoi(level_number_current->identifier);
5067 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5069 else if (game_status == GAME_MODE_LEVELS)
5071 // store level set if chosen from "last played level set" menu
5072 StoreLastPlayedLevels(leveldir_current);
5074 else if (game_status == GAME_MODE_NAMES)
5076 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5078 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5085 // change active user to selected user
5086 user.nr = entry_pos;
5088 // save number of new active user
5091 // load setup of new active user
5094 // load last level set of new active user
5095 LoadLevelSetup_LastSeries();
5096 LoadLevelSetup_SeriesInfo();
5098 // update list of last played level sets
5099 UpdateLastPlayedLevels_TreeInfo();
5103 ToggleFullscreenIfNeeded();
5104 ChangeWindowScalingIfNeeded();
5106 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5107 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5108 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5111 SetGameStatus(GAME_MODE_MAIN);
5120 void DrawChoosePlayerName(void)
5124 FadeMenuSoundsAndMusic();
5126 if (player_name != NULL)
5128 freeTreeInfo(player_name);
5133 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5135 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5136 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5139 ti->node_top = &player_name;
5140 ti->sort_priority = 10000 + value;
5141 ti->color = getPlayerNameColor(global.user_names[i]);
5143 snprintf(identifier, sizeof(identifier), "%d", value);
5144 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5146 setString(&ti->identifier, identifier);
5147 setString(&ti->name, name);
5148 setString(&ti->name_sorting, name);
5150 pushTreeInfo(&player_name, ti);
5153 // sort player entries by player number
5154 sortTreeInfo(&player_name);
5156 // set current player entry to selected player entry
5157 player_name_current =
5158 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5160 // if that fails, set current player name to first available name
5161 if (player_name_current == NULL)
5162 player_name_current = player_name;
5164 DrawChooseTree(&player_name_current);
5166 PlayMenuSoundsAndMusic();
5169 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5171 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5174 void DrawChooseLevelSet(void)
5176 FadeMenuSoundsAndMusic();
5178 DrawChooseTree(&leveldir_current);
5180 PlayMenuSoundsAndMusic();
5183 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5185 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5188 void DrawChooseLevelNr(void)
5192 FadeMenuSoundsAndMusic();
5194 if (level_number != NULL)
5196 freeTreeInfo(level_number);
5198 level_number = NULL;
5201 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5203 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5204 char identifier[32], name[64];
5207 // temporarily load level info to get level name
5208 LoadLevelInfoOnly(i);
5210 ti->node_top = &level_number;
5211 ti->sort_priority = 10000 + value;
5212 ti->color = (level.no_level_file ? FC_BLUE :
5213 LevelStats_getSolved(i) ? FC_GREEN :
5214 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5216 snprintf(identifier, sizeof(identifier), "%d", value);
5217 snprintf(name, sizeof(name), "%03d: %s", value,
5218 (level.no_level_file ? "(no file)" : level.name));
5220 setString(&ti->identifier, identifier);
5221 setString(&ti->name, name);
5222 setString(&ti->name_sorting, name);
5224 pushTreeInfo(&level_number, ti);
5227 // sort level number values to start with lowest level number
5228 sortTreeInfo(&level_number);
5230 // set current level number to current level number
5231 level_number_current =
5232 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5234 // if that also fails, set current level number to first available level
5235 if (level_number_current == NULL)
5236 level_number_current = level_number;
5238 DrawChooseTree(&level_number_current);
5240 PlayMenuSoundsAndMusic();
5243 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5245 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5248 void DrawHallOfFame(int level_nr)
5250 int fade_mask = REDRAW_FIELD;
5253 fade_mask = REDRAW_ALL;
5256 FadeMenuSoundsAndMusic();
5258 // (this is needed when called from GameEnd() after winning a game)
5259 KeyboardAutoRepeatOn();
5261 // (this is needed when called from GameEnd() after winning a game)
5262 SetDrawDeactivationMask(REDRAW_NONE);
5263 SetDrawBackgroundMask(REDRAW_FIELD);
5265 LoadLocalAndServerScore(level_nr, TRUE);
5267 if (scores.last_added >= 0)
5268 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5270 FadeSetEnterScreen();
5274 // needed if different viewport properties defined for scores
5275 ChangeViewportPropertiesIfNeeded();
5277 PlayMenuSoundsAndMusic();
5279 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5281 HandleHallOfFame(level_nr, 0, 0, 0, MB_MENU_INITIALIZE);
5283 DrawMaskedBorder(fade_mask);
5288 static int getHallOfFameFirstEntry(int first_entry, int step)
5291 first_entry = scores.last_added - (NUM_MENU_ENTRIES_ON_SCREEN + 1) / 2 + 1;
5293 first_entry += step;
5295 if (first_entry < 0)
5297 else if (first_entry > MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN)
5298 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
5303 static char *getHallOfFameScoreText(int nr)
5305 if (!level.rate_time_over_score)
5306 return int2str(scores.entry[nr].score, 5); // show normal score
5308 if (level.use_step_counter)
5309 return int2str(scores.entry[nr].time, 5); // show number of steps
5311 static char score_text[10];
5312 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5313 int mm = (time_seconds / 60) % 60;
5314 int ss = (time_seconds % 60);
5316 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5321 static void drawHallOfFameList(int level_nr, int first_entry)
5325 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5328 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
5329 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
5330 "HighScores of Level %d", level_nr);
5332 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5334 int entry = first_entry + i;
5335 boolean active = (entry == scores.last_added);
5336 boolean forced = (scores.force_last_added && active);
5337 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
5338 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
5339 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
5340 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
5341 int dxoff = getFontDrawOffsetX(font_nr1);
5342 int dx1 = 3 * getFontWidth(font_nr1);
5343 int dx2 = dx1 + getFontWidth(font_nr1);
5344 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
5345 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
5346 int sy = mSY + 64 + i * 32;
5347 char *pos_text = (forced ? "???" : int2str(entry + 1, 3));
5349 DrawText(mSX, sy, pos_text, font_nr1);
5350 DrawText(mSX + dx1, sy, ".", font_nr1);
5352 for (j = 0; j < num_dots; j++)
5353 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
5355 if (!strEqual(scores.entry[entry].name, EMPTY_PLAYER_NAME))
5356 DrawText(mSX + dx2, sy, scores.entry[entry].name, font_nr2);
5358 DrawText(mSX + dx3, sy, getHallOfFameScoreText(entry), font_nr4);
5361 redraw_mask |= REDRAW_FIELD;
5364 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5366 static int level_nr = 0;
5367 static int first_entry = 0;
5368 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5370 if (button == MB_MENU_INITIALIZE)
5374 if (server_scores.updated)
5376 // reload scores, using updated server score cache file
5377 LoadLocalAndServerScore(level_nr, FALSE);
5379 server_scores.updated = FALSE;
5382 first_entry = getHallOfFameFirstEntry(0, 0);
5384 drawHallOfFameList(level_nr, first_entry);
5389 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
5390 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
5394 first_entry = getHallOfFameFirstEntry(first_entry, -step);
5396 drawHallOfFameList(level_nr, first_entry);
5400 first_entry = getHallOfFameFirstEntry(first_entry, step);
5402 drawHallOfFameList(level_nr, first_entry);
5404 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5406 PlaySound(SND_MENU_ITEM_SELECTING);
5408 FadeSound(SND_BACKGROUND_SCORES);
5410 if (button == MB_MENU_CHOICE &&
5411 game_status_last_screen == GAME_MODE_PLAYING &&
5412 setup.auto_play_next_level && setup.increment_levels &&
5413 level_nr < leveldir_current->last_level &&
5416 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
5420 SetGameStatus(GAME_MODE_MAIN);
5425 else if (server_scores.updated)
5427 // reload scores, using updated server score cache file
5428 LoadLocalAndServerScore(level_nr, FALSE);
5430 server_scores.updated = FALSE;
5432 first_entry = getHallOfFameFirstEntry(0, 0);
5434 drawHallOfFameList(level_nr, first_entry);
5437 if (game_status == GAME_MODE_SCORES)
5438 PlayMenuSoundIfLoop();
5442 // ============================================================================
5443 // setup screen functions
5444 // ============================================================================
5446 static struct TokenInfo *setup_info;
5447 static int num_setup_info; // number of setup entries shown on screen
5448 static int max_setup_info; // total number of setup entries in list
5450 static char *window_size_text;
5451 static char *scaling_type_text;
5452 static char *rendering_mode_text;
5453 static char *vsync_mode_text;
5454 static char *scroll_delay_text;
5455 static char *snapshot_mode_text;
5456 static char *game_speed_text;
5457 static char *network_server_text;
5458 static char *graphics_set_name;
5459 static char *sounds_set_name;
5460 static char *music_set_name;
5461 static char *volume_simple_text;
5462 static char *volume_loops_text;
5463 static char *volume_music_text;
5464 static char *touch_controls_text;
5465 static char *move_distance_text;
5466 static char *drop_distance_text;
5467 static char *transparency_text;
5468 static char *grid_size_text[2][2];
5470 static void execSetupMain(void)
5472 setup_mode = SETUP_MODE_MAIN;
5477 static void execSetupGame_setGameSpeeds(boolean update_value)
5479 if (setup.game_speed_extended)
5481 game_speeds_list = game_speeds_list_extended;
5482 game_speeds = game_speeds_extended;
5486 game_speeds_list = game_speeds_list_normal;
5487 game_speeds = game_speeds_normal;
5490 if (game_speeds == NULL)
5494 for (i = 0; game_speeds_list[i].value != -1; i++)
5496 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5497 char identifier[32], name[32];
5498 int value = game_speeds_list[i].value;
5499 char *text = game_speeds_list[i].text;
5501 ti->node_top = &game_speeds;
5502 ti->sort_priority = 10000 - value;
5504 sprintf(identifier, "%d", value);
5505 sprintf(name, "%s", text);
5507 setString(&ti->identifier, identifier);
5508 setString(&ti->name, name);
5509 setString(&ti->name_sorting, name);
5510 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5512 pushTreeInfo(&game_speeds, ti);
5515 // sort game speed values to start with slowest game speed
5516 sortTreeInfo(&game_speeds);
5518 update_value = TRUE;
5523 // set current game speed to configured game speed value
5524 game_speed_current =
5525 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5527 // if that fails, set current game speed to reliable default value
5528 if (game_speed_current == NULL)
5529 game_speed_current =
5530 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5532 // if that also fails, set current game speed to first available speed
5533 if (game_speed_current == NULL)
5534 game_speed_current = game_speeds;
5536 if (setup.game_speed_extended)
5537 game_speeds_extended = game_speeds;
5539 game_speeds_normal = game_speeds;
5542 setup.game_frame_delay = atoi(game_speed_current->identifier);
5544 // needed for displaying game speed text instead of identifier
5545 game_speed_text = game_speed_current->name;
5548 static void execSetupGame_setScrollDelays(void)
5550 if (scroll_delays == NULL)
5554 for (i = 0; scroll_delays_list[i].value != -1; i++)
5556 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5557 char identifier[32], name[32];
5558 int value = scroll_delays_list[i].value;
5559 char *text = scroll_delays_list[i].text;
5561 ti->node_top = &scroll_delays;
5562 ti->sort_priority = value;
5564 sprintf(identifier, "%d", value);
5565 sprintf(name, "%s", text);
5567 setString(&ti->identifier, identifier);
5568 setString(&ti->name, name);
5569 setString(&ti->name_sorting, name);
5570 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5572 pushTreeInfo(&scroll_delays, ti);
5575 // sort scroll delay values to start with lowest scroll delay value
5576 sortTreeInfo(&scroll_delays);
5578 // set current scroll delay value to configured scroll delay value
5579 scroll_delay_current =
5580 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5582 // if that fails, set current scroll delay to reliable default value
5583 if (scroll_delay_current == NULL)
5584 scroll_delay_current =
5585 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5587 // if that also fails, set current scroll delay to first available value
5588 if (scroll_delay_current == NULL)
5589 scroll_delay_current = scroll_delays;
5592 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5594 // needed for displaying scroll delay text instead of identifier
5595 scroll_delay_text = scroll_delay_current->name;
5598 static void execSetupGame_setSnapshotModes(void)
5600 if (snapshot_modes == NULL)
5604 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5606 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5607 char identifier[32], name[32];
5608 char *value = snapshot_modes_list[i].value;
5609 char *text = snapshot_modes_list[i].text;
5611 ti->node_top = &snapshot_modes;
5612 ti->sort_priority = i;
5614 sprintf(identifier, "%s", value);
5615 sprintf(name, "%s", text);
5617 setString(&ti->identifier, identifier);
5618 setString(&ti->name, name);
5619 setString(&ti->name_sorting, name);
5620 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5622 pushTreeInfo(&snapshot_modes, ti);
5625 // sort snapshot mode values to start with lowest snapshot mode value
5626 sortTreeInfo(&snapshot_modes);
5628 // set current snapshot mode value to configured snapshot mode value
5629 snapshot_mode_current =
5630 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5632 // if that fails, set current snapshot mode to reliable default value
5633 if (snapshot_mode_current == NULL)
5634 snapshot_mode_current =
5635 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5637 // if that also fails, set current snapshot mode to first available value
5638 if (snapshot_mode_current == NULL)
5639 snapshot_mode_current = snapshot_modes;
5642 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5644 // needed for displaying snapshot mode text instead of identifier
5645 snapshot_mode_text = snapshot_mode_current->name;
5648 static void execSetupGame_setNetworkServerText(void)
5650 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5652 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5656 strncpy(network_server_hostname, setup.network_server_hostname,
5657 MAX_SETUP_TEXT_INPUT_LEN);
5658 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5661 // needed for displaying network server text instead of identifier
5662 network_server_text = network_server_hostname;
5665 static void execSetupGame(void)
5667 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5669 execSetupGame_setGameSpeeds(FALSE);
5670 execSetupGame_setScrollDelays();
5671 execSetupGame_setSnapshotModes();
5673 execSetupGame_setNetworkServerText();
5675 if (!setup.provide_uploading_tapes)
5676 setHideSetupEntry(execOfferUploadTapes);
5678 setup_mode = SETUP_MODE_GAME;
5682 // check if vsync needs to be disabled for this game speed to work
5683 if (check_vsync_mode)
5684 DisableVsyncIfNeeded();
5687 static void execSetupChooseGameSpeed(void)
5689 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5694 static void execSetupChooseScrollDelay(void)
5696 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5701 static void execSetupChooseSnapshotMode(void)
5703 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5708 static void execSetupEngines(void)
5710 setup_mode = SETUP_MODE_ENGINES;
5715 static void execSetupEditor(void)
5717 setup_mode = SETUP_MODE_EDITOR;
5722 static void execSetupGraphics_setWindowSizes(boolean update_list)
5724 if (window_sizes != NULL && update_list)
5726 freeTreeInfo(window_sizes);
5728 window_sizes = NULL;
5731 if (window_sizes == NULL)
5733 boolean current_window_size_found = FALSE;
5736 for (i = 0; window_sizes_list[i].value != -1; i++)
5738 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5739 char identifier[32], name[32];
5740 int value = window_sizes_list[i].value;
5741 char *text = window_sizes_list[i].text;
5743 ti->node_top = &window_sizes;
5744 ti->sort_priority = value;
5746 sprintf(identifier, "%d", value);
5747 sprintf(name, "%s", text);
5749 setString(&ti->identifier, identifier);
5750 setString(&ti->name, name);
5751 setString(&ti->name_sorting, name);
5752 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5754 pushTreeInfo(&window_sizes, ti);
5756 if (value == setup.window_scaling_percent)
5757 current_window_size_found = TRUE;
5760 if (!current_window_size_found)
5762 // add entry for non-preset window scaling value
5764 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5765 char identifier[32], name[32];
5766 int value = setup.window_scaling_percent;
5768 ti->node_top = &window_sizes;
5769 ti->sort_priority = value;
5771 sprintf(identifier, "%d", value);
5772 sprintf(name, "%d %% (Current)", value);
5774 setString(&ti->identifier, identifier);
5775 setString(&ti->name, name);
5776 setString(&ti->name_sorting, name);
5777 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5779 pushTreeInfo(&window_sizes, ti);
5782 // sort window size values to start with lowest window size value
5783 sortTreeInfo(&window_sizes);
5785 // set current window size value to configured window size value
5786 window_size_current =
5787 getTreeInfoFromIdentifier(window_sizes,
5788 i_to_a(setup.window_scaling_percent));
5790 // if that fails, set current window size to reliable default value
5791 if (window_size_current == NULL)
5792 window_size_current =
5793 getTreeInfoFromIdentifier(window_sizes,
5794 i_to_a(STD_WINDOW_SCALING_PERCENT));
5796 // if that also fails, set current window size to first available value
5797 if (window_size_current == NULL)
5798 window_size_current = window_sizes;
5801 setup.window_scaling_percent = atoi(window_size_current->identifier);
5803 // needed for displaying window size text instead of identifier
5804 window_size_text = window_size_current->name;
5807 static void execSetupGraphics_setScalingTypes(void)
5809 if (scaling_types == NULL)
5813 for (i = 0; scaling_types_list[i].value != NULL; i++)
5815 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5816 char identifier[32], name[32];
5817 char *value = scaling_types_list[i].value;
5818 char *text = scaling_types_list[i].text;
5820 ti->node_top = &scaling_types;
5821 ti->sort_priority = i;
5823 sprintf(identifier, "%s", value);
5824 sprintf(name, "%s", text);
5826 setString(&ti->identifier, identifier);
5827 setString(&ti->name, name);
5828 setString(&ti->name_sorting, name);
5829 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5831 pushTreeInfo(&scaling_types, ti);
5834 // sort scaling type values to start with lowest scaling type value
5835 sortTreeInfo(&scaling_types);
5837 // set current scaling type value to configured scaling type value
5838 scaling_type_current =
5839 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5841 // if that fails, set current scaling type to reliable default value
5842 if (scaling_type_current == NULL)
5843 scaling_type_current =
5844 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5846 // if that also fails, set current scaling type to first available value
5847 if (scaling_type_current == NULL)
5848 scaling_type_current = scaling_types;
5851 setup.window_scaling_quality = scaling_type_current->identifier;
5853 // needed for displaying scaling type text instead of identifier
5854 scaling_type_text = scaling_type_current->name;
5857 static void execSetupGraphics_setRenderingModes(void)
5859 if (rendering_modes == NULL)
5863 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5865 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5866 char identifier[32], name[32];
5867 char *value = rendering_modes_list[i].value;
5868 char *text = rendering_modes_list[i].text;
5870 ti->node_top = &rendering_modes;
5871 ti->sort_priority = i;
5873 sprintf(identifier, "%s", value);
5874 sprintf(name, "%s", text);
5876 setString(&ti->identifier, identifier);
5877 setString(&ti->name, name);
5878 setString(&ti->name_sorting, name);
5879 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5881 pushTreeInfo(&rendering_modes, ti);
5884 // sort rendering mode values to start with lowest rendering mode value
5885 sortTreeInfo(&rendering_modes);
5887 // set current rendering mode value to configured rendering mode value
5888 rendering_mode_current =
5889 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5891 // if that fails, set current rendering mode to reliable default value
5892 if (rendering_mode_current == NULL)
5893 rendering_mode_current =
5894 getTreeInfoFromIdentifier(rendering_modes,
5895 STR_SPECIAL_RENDERING_DEFAULT);
5897 // if that also fails, set current rendering mode to first available one
5898 if (rendering_mode_current == NULL)
5899 rendering_mode_current = rendering_modes;
5902 setup.screen_rendering_mode = rendering_mode_current->identifier;
5904 // needed for displaying rendering mode text instead of identifier
5905 rendering_mode_text = rendering_mode_current->name;
5908 static void execSetupGraphics_setVsyncModes(boolean update_value)
5910 if (vsync_modes == NULL)
5914 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5916 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5917 char identifier[32], name[32];
5918 char *value = vsync_modes_list[i].value;
5919 char *text = vsync_modes_list[i].text;
5921 ti->node_top = &vsync_modes;
5922 ti->sort_priority = i;
5924 sprintf(identifier, "%s", value);
5925 sprintf(name, "%s", text);
5927 setString(&ti->identifier, identifier);
5928 setString(&ti->name, name);
5929 setString(&ti->name_sorting, name);
5930 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5932 pushTreeInfo(&vsync_modes, ti);
5935 // sort vsync mode values to start with lowest vsync mode value
5936 sortTreeInfo(&vsync_modes);
5938 update_value = TRUE;
5943 // set current vsync mode value to configured vsync mode value
5944 vsync_mode_current =
5945 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5947 // if that fails, set current vsync mode to reliable default value
5948 if (vsync_mode_current == NULL)
5949 vsync_mode_current =
5950 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5952 // if that also fails, set current vsync mode to first available one
5953 if (vsync_mode_current == NULL)
5954 vsync_mode_current = vsync_modes;
5957 setup.vsync_mode = vsync_mode_current->identifier;
5959 // needed for displaying vsync mode text instead of identifier
5960 vsync_mode_text = vsync_mode_current->name;
5963 static void execSetupGraphics(void)
5965 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5967 // update "setup.window_scaling_percent" from list selection
5968 // (in this case, window scaling was changed on setup screen)
5969 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5970 execSetupGraphics_setWindowSizes(FALSE);
5972 // update "setup.vsync_mode" from list selection
5973 // (in this case, vsync mode was changed on setup screen)
5974 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5975 execSetupGraphics_setVsyncModes(FALSE);
5977 // update list selection from "setup.window_scaling_percent"
5978 // (window scaling may have changed by resizing the window)
5979 execSetupGraphics_setWindowSizes(TRUE);
5981 // update list selection from "setup.vsync_mode"
5982 // (vsync_mode may have changed by re-creating the renderer)
5983 execSetupGraphics_setVsyncModes(TRUE);
5985 execSetupGraphics_setScalingTypes();
5986 execSetupGraphics_setRenderingModes();
5988 setup_mode = SETUP_MODE_GRAPHICS;
5992 // check if game speed is high enough for 60 Hz vsync to work
5993 if (check_game_speed)
5994 ModifyGameSpeedIfNeeded();
5996 // window scaling may have changed at this point
5997 ChangeWindowScalingIfNeeded();
5999 // window scaling quality may have changed at this point
6000 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6001 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6003 // screen rendering mode may have changed at this point
6004 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6006 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6007 int video_vsync_mode = video.vsync_mode;
6009 // screen vsync mode may have changed at this point
6010 ChangeVsyncModeIfNeeded();
6012 // check if setting vsync mode to selected value failed
6013 if (setup_vsync_mode != video_vsync_mode &&
6014 setup_vsync_mode != video.vsync_mode)
6016 // changing vsync mode to selected value failed -- reset displayed value
6017 execSetupGraphics_setVsyncModes(TRUE);
6019 Request("Setting VSync failed!", REQ_CONFIRM);
6025 static void execSetupChooseWindowSize(void)
6027 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6032 static void execSetupChooseScalingType(void)
6034 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6039 static void execSetupChooseRenderingMode(void)
6041 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6046 static void execSetupChooseVsyncMode(void)
6048 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6053 static void execSetupChooseVolumeSimple(void)
6055 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6060 static void execSetupChooseVolumeLoops(void)
6062 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6067 static void execSetupChooseVolumeMusic(void)
6069 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6074 static void execSetupSound(void)
6076 if (volumes_simple == NULL)
6078 boolean current_volume_simple_found = FALSE;
6081 for (i = 0; volumes_list[i].value != -1; i++)
6083 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6084 char identifier[32], name[32];
6085 int value = volumes_list[i].value;
6086 char *text = volumes_list[i].text;
6088 ti->node_top = &volumes_simple;
6089 ti->sort_priority = value;
6091 sprintf(identifier, "%d", value);
6092 sprintf(name, "%s", text);
6094 setString(&ti->identifier, identifier);
6095 setString(&ti->name, name);
6096 setString(&ti->name_sorting, name);
6097 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6099 pushTreeInfo(&volumes_simple, ti);
6101 if (value == setup.volume_simple)
6102 current_volume_simple_found = TRUE;
6105 if (!current_volume_simple_found)
6107 // add entry for non-preset volume value
6109 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6110 char identifier[32], name[32];
6111 int value = setup.volume_simple;
6113 ti->node_top = &volumes_simple;
6114 ti->sort_priority = value;
6116 sprintf(identifier, "%d", value);
6117 sprintf(name, "%d %% (Current)", value);
6119 setString(&ti->identifier, identifier);
6120 setString(&ti->name, name);
6121 setString(&ti->name_sorting, name);
6122 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6124 pushTreeInfo(&volumes_simple, ti);
6127 // sort volume values to start with lowest volume value
6128 sortTreeInfo(&volumes_simple);
6130 // set current volume value to configured volume value
6131 volume_simple_current =
6132 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6134 // if that fails, set current volume to reliable default value
6135 if (volume_simple_current == NULL)
6136 volume_simple_current =
6137 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6139 // if that also fails, set current volume to first available value
6140 if (volume_simple_current == NULL)
6141 volume_simple_current = volumes_simple;
6144 if (volumes_loops == NULL)
6146 boolean current_volume_loops_found = FALSE;
6149 for (i = 0; volumes_list[i].value != -1; i++)
6151 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6152 char identifier[32], name[32];
6153 int value = volumes_list[i].value;
6154 char *text = volumes_list[i].text;
6156 ti->node_top = &volumes_loops;
6157 ti->sort_priority = value;
6159 sprintf(identifier, "%d", value);
6160 sprintf(name, "%s", text);
6162 setString(&ti->identifier, identifier);
6163 setString(&ti->name, name);
6164 setString(&ti->name_sorting, name);
6165 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6167 pushTreeInfo(&volumes_loops, ti);
6169 if (value == setup.volume_loops)
6170 current_volume_loops_found = TRUE;
6173 if (!current_volume_loops_found)
6175 // add entry for non-preset volume value
6177 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6178 char identifier[32], name[32];
6179 int value = setup.volume_loops;
6181 ti->node_top = &volumes_loops;
6182 ti->sort_priority = value;
6184 sprintf(identifier, "%d", value);
6185 sprintf(name, "%d %% (Current)", value);
6187 setString(&ti->identifier, identifier);
6188 setString(&ti->name, name);
6189 setString(&ti->name_sorting, name);
6190 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6192 pushTreeInfo(&volumes_loops, ti);
6195 // sort volume values to start with lowest volume value
6196 sortTreeInfo(&volumes_loops);
6198 // set current volume value to configured volume value
6199 volume_loops_current =
6200 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6202 // if that fails, set current volume to reliable default value
6203 if (volume_loops_current == NULL)
6204 volume_loops_current =
6205 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6207 // if that also fails, set current volume to first available value
6208 if (volume_loops_current == NULL)
6209 volume_loops_current = volumes_loops;
6212 if (volumes_music == NULL)
6214 boolean current_volume_music_found = FALSE;
6217 for (i = 0; volumes_list[i].value != -1; i++)
6219 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6220 char identifier[32], name[32];
6221 int value = volumes_list[i].value;
6222 char *text = volumes_list[i].text;
6224 ti->node_top = &volumes_music;
6225 ti->sort_priority = value;
6227 sprintf(identifier, "%d", value);
6228 sprintf(name, "%s", text);
6230 setString(&ti->identifier, identifier);
6231 setString(&ti->name, name);
6232 setString(&ti->name_sorting, name);
6233 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6235 pushTreeInfo(&volumes_music, ti);
6237 if (value == setup.volume_music)
6238 current_volume_music_found = TRUE;
6241 if (!current_volume_music_found)
6243 // add entry for non-preset volume value
6245 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6246 char identifier[32], name[32];
6247 int value = setup.volume_music;
6249 ti->node_top = &volumes_music;
6250 ti->sort_priority = value;
6252 sprintf(identifier, "%d", value);
6253 sprintf(name, "%d %% (Current)", value);
6255 setString(&ti->identifier, identifier);
6256 setString(&ti->name, name);
6257 setString(&ti->name_sorting, name);
6258 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6260 pushTreeInfo(&volumes_music, ti);
6263 // sort volume values to start with lowest volume value
6264 sortTreeInfo(&volumes_music);
6266 // set current volume value to configured volume value
6267 volume_music_current =
6268 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6270 // if that fails, set current volume to reliable default value
6271 if (volume_music_current == NULL)
6272 volume_music_current =
6273 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6275 // if that also fails, set current volume to first available value
6276 if (volume_music_current == NULL)
6277 volume_music_current = volumes_music;
6280 setup.volume_simple = atoi(volume_simple_current->identifier);
6281 setup.volume_loops = atoi(volume_loops_current->identifier);
6282 setup.volume_music = atoi(volume_music_current->identifier);
6284 // needed for displaying volume text instead of identifier
6285 volume_simple_text = volume_simple_current->name;
6286 volume_loops_text = volume_loops_current->name;
6287 volume_music_text = volume_music_current->name;
6289 setup_mode = SETUP_MODE_SOUND;
6294 static void execSetupChooseTouchControls(void)
6296 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6301 static void execSetupChooseMoveDistance(void)
6303 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6308 static void execSetupChooseDropDistance(void)
6310 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6315 static void execSetupChooseTransparency(void)
6317 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6322 static void execSetupChooseGridXSize_0(void)
6324 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6329 static void execSetupChooseGridYSize_0(void)
6331 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6336 static void execSetupChooseGridXSize_1(void)
6338 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6343 static void execSetupChooseGridYSize_1(void)
6345 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6350 static void execSetupConfigureVirtualButtons(void)
6352 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6354 ConfigureVirtualButtons();
6356 setup_mode = SETUP_MODE_TOUCH;
6361 static void execSetupTouch(void)
6365 if (touch_controls == NULL)
6367 for (i = 0; touch_controls_list[i].value != NULL; i++)
6369 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6370 char identifier[32], name[32];
6371 char *value = touch_controls_list[i].value;
6372 char *text = touch_controls_list[i].text;
6374 ti->node_top = &touch_controls;
6375 ti->sort_priority = i;
6377 sprintf(identifier, "%s", value);
6378 sprintf(name, "%s", text);
6380 setString(&ti->identifier, identifier);
6381 setString(&ti->name, name);
6382 setString(&ti->name_sorting, name);
6383 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6385 pushTreeInfo(&touch_controls, ti);
6388 // sort touch control values to start with lowest touch control value
6389 sortTreeInfo(&touch_controls);
6391 // set current touch control value to configured touch control value
6392 touch_control_current =
6393 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6395 // if that fails, set current touch control to reliable default value
6396 if (touch_control_current == NULL)
6397 touch_control_current =
6398 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6400 // if that also fails, set current touch control to first available value
6401 if (touch_control_current == NULL)
6402 touch_control_current = touch_controls;
6405 if (move_distances == NULL)
6407 for (i = 0; distances_list[i].value != -1; i++)
6409 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6410 char identifier[32], name[32];
6411 int value = distances_list[i].value;
6412 char *text = distances_list[i].text;
6414 ti->node_top = &move_distances;
6415 ti->sort_priority = value;
6417 sprintf(identifier, "%d", value);
6418 sprintf(name, "%s", text);
6420 setString(&ti->identifier, identifier);
6421 setString(&ti->name, name);
6422 setString(&ti->name_sorting, name);
6423 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6425 pushTreeInfo(&move_distances, ti);
6428 // sort distance values to start with lowest distance value
6429 sortTreeInfo(&move_distances);
6431 // set current distance value to configured distance value
6432 move_distance_current =
6433 getTreeInfoFromIdentifier(move_distances,
6434 i_to_a(setup.touch.move_distance));
6436 // if that fails, set current distance to reliable default value
6437 if (move_distance_current == NULL)
6438 move_distance_current =
6439 getTreeInfoFromIdentifier(move_distances,
6440 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6442 // if that also fails, set current distance to first available value
6443 if (move_distance_current == NULL)
6444 move_distance_current = move_distances;
6447 if (drop_distances == NULL)
6449 for (i = 0; distances_list[i].value != -1; i++)
6451 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6452 char identifier[32], name[32];
6453 int value = distances_list[i].value;
6454 char *text = distances_list[i].text;
6456 ti->node_top = &drop_distances;
6457 ti->sort_priority = value;
6459 sprintf(identifier, "%d", value);
6460 sprintf(name, "%s", text);
6462 setString(&ti->identifier, identifier);
6463 setString(&ti->name, name);
6464 setString(&ti->name_sorting, name);
6465 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6467 pushTreeInfo(&drop_distances, ti);
6470 // sort distance values to start with lowest distance value
6471 sortTreeInfo(&drop_distances);
6473 // set current distance value to configured distance value
6474 drop_distance_current =
6475 getTreeInfoFromIdentifier(drop_distances,
6476 i_to_a(setup.touch.drop_distance));
6478 // if that fails, set current distance to reliable default value
6479 if (drop_distance_current == NULL)
6480 drop_distance_current =
6481 getTreeInfoFromIdentifier(drop_distances,
6482 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6484 // if that also fails, set current distance to first available value
6485 if (drop_distance_current == NULL)
6486 drop_distance_current = drop_distances;
6489 if (transparencies == NULL)
6491 for (i = 0; transparencies_list[i].value != -1; i++)
6493 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6494 char identifier[32], name[32];
6495 int value = transparencies_list[i].value;
6496 char *text = transparencies_list[i].text;
6498 ti->node_top = &transparencies;
6499 ti->sort_priority = value;
6501 sprintf(identifier, "%d", value);
6502 sprintf(name, "%s", text);
6504 setString(&ti->identifier, identifier);
6505 setString(&ti->name, name);
6506 setString(&ti->name_sorting, name);
6507 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6509 pushTreeInfo(&transparencies, ti);
6512 // sort transparency values to start with lowest transparency value
6513 sortTreeInfo(&transparencies);
6515 // set current transparency value to configured transparency value
6516 transparency_current =
6517 getTreeInfoFromIdentifier(transparencies,
6518 i_to_a(setup.touch.transparency));
6520 // if that fails, set current transparency to reliable default value
6521 if (transparency_current == NULL)
6522 transparency_current =
6523 getTreeInfoFromIdentifier(transparencies,
6524 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6526 // if that also fails, set current transparency to first available value
6527 if (transparency_current == NULL)
6528 transparency_current = transparencies;
6531 for (i = 0; i < 2; i++)
6533 for (j = 0; j < 2; j++)
6535 if (grid_sizes[i][j] == NULL)
6537 for (k = 0; grid_sizes_list[k].value != -1; k++)
6539 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6540 char identifier[32], name[32];
6541 int value = grid_sizes_list[k].value;
6542 char *text = grid_sizes_list[k].text;
6544 ti->node_top = &grid_sizes[i][j];
6545 ti->sort_priority = value;
6547 sprintf(identifier, "%d", value);
6548 sprintf(name, "%s", text);
6550 setString(&ti->identifier, identifier);
6551 setString(&ti->name, name);
6552 setString(&ti->name_sorting, name);
6553 setString(&ti->infotext,
6556 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6557 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6559 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6560 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6562 pushTreeInfo(&grid_sizes[i][j], ti);
6565 // sort grid size values to start with lowest grid size value
6566 sortTreeInfo(&grid_sizes[i][j]);
6568 // set current grid size value to configured grid size value
6569 grid_size_current[i][j] =
6570 getTreeInfoFromIdentifier(grid_sizes[i][j],
6572 setup.touch.grid_xsize[i] :
6573 setup.touch.grid_ysize[i]));
6575 // if that fails, set current grid size to reliable default value
6576 if (grid_size_current[i][j] == NULL)
6577 grid_size_current[i][j] =
6578 getTreeInfoFromIdentifier(grid_sizes[i][j],
6580 DEFAULT_GRID_XSIZE(i) :
6581 DEFAULT_GRID_YSIZE(i)));
6583 // if that also fails, set current grid size to first available value
6584 if (grid_size_current[i][j] == NULL)
6585 grid_size_current[i][j] = grid_sizes[i][j];
6590 setup.touch.control_type = touch_control_current->identifier;
6591 setup.touch.move_distance = atoi(move_distance_current->identifier);
6592 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6593 setup.touch.transparency = atoi(transparency_current->identifier);
6595 for (i = 0; i < 2; i++)
6597 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6598 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6600 if (i == GRID_ACTIVE_NR())
6602 overlay.grid_xsize = setup.touch.grid_xsize[i];
6603 overlay.grid_ysize = setup.touch.grid_ysize[i];
6607 // needed for displaying value text instead of identifier
6608 touch_controls_text = touch_control_current->name;
6609 move_distance_text = move_distance_current->name;
6610 drop_distance_text = drop_distance_current->name;
6611 transparency_text = transparency_current->name;
6613 for (i = 0; i < 2; i++)
6614 for (j = 0; j < 2; j++)
6615 grid_size_text[i][j] = grid_size_current[i][j]->name;
6617 setup_mode = SETUP_MODE_TOUCH;
6622 static void execSetupArtwork(void)
6624 static ArtworkDirTree *gfx_last_valid = NULL;
6625 static ArtworkDirTree *snd_last_valid = NULL;
6626 static ArtworkDirTree *mus_last_valid = NULL;
6628 // current artwork directory may be invalid (level group, parent link)
6629 if (!validLevelSeries(artwork.gfx_current))
6630 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6631 if (!validLevelSeries(artwork.snd_current))
6632 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6633 if (!validLevelSeries(artwork.mus_current))
6634 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6636 // store valid artwork directory information
6637 gfx_last_valid = artwork.gfx_current;
6638 snd_last_valid = artwork.snd_current;
6639 mus_last_valid = artwork.mus_current;
6642 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6643 artwork.gfx_current->subdir,
6644 artwork.gfx_current->fullpath,
6645 artwork.gfx_current->basepath);
6648 setup.graphics_set = artwork.gfx_current->identifier;
6649 setup.sounds_set = artwork.snd_current->identifier;
6650 setup.music_set = artwork.mus_current->identifier;
6652 // needed if last screen (setup choice) changed graphics, sounds or music
6653 ReloadCustomArtwork(0);
6655 // needed for displaying artwork name instead of artwork identifier
6656 graphics_set_name = artwork.gfx_current->name;
6657 sounds_set_name = artwork.snd_current->name;
6658 music_set_name = artwork.mus_current->name;
6660 setup_mode = SETUP_MODE_ARTWORK;
6665 static void execSetupChooseGraphics(void)
6667 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6672 static void execSetupChooseSounds(void)
6674 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6679 static void execSetupChooseMusic(void)
6681 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6686 static void execSetupInput(void)
6688 setup_mode = SETUP_MODE_INPUT;
6693 static void execSetupShortcuts(void)
6695 setup_mode = SETUP_MODE_SHORTCUTS;
6700 static void execSetupShortcuts1(void)
6702 setup_mode = SETUP_MODE_SHORTCUTS_1;
6707 static void execSetupShortcuts2(void)
6709 setup_mode = SETUP_MODE_SHORTCUTS_2;
6714 static void execSetupShortcuts3(void)
6716 setup_mode = SETUP_MODE_SHORTCUTS_3;
6721 static void execSetupShortcuts4(void)
6723 setup_mode = SETUP_MODE_SHORTCUTS_4;
6728 static void execSetupShortcuts5(void)
6730 setup_mode = SETUP_MODE_SHORTCUTS_5;
6735 static void execExitSetup(void)
6737 SetGameStatus(GAME_MODE_MAIN);
6742 static void execSaveAndExitSetup(void)
6748 static void execGadgetNetworkServer(void)
6750 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6751 struct GadgetInfo *gi = screen_gadget[gadget_id];
6753 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6754 network_server_hostname[0] = '\0';
6756 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6760 ClickOnGadget(gi, MB_LEFTBUTTON);
6763 static void execOfferUploadTapes(void)
6768 static void ToggleNetworkModeIfNeeded(void)
6770 int font_title = FONT_TITLE_1;
6771 int font_foot = FC_BLUE;
6772 int ystart = mSY - SY + 16;
6773 int ybottom = mSY - SY + SYSIZE - 20;
6774 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6776 if (setup.network_mode == network.enabled)
6779 network.enabled = setup.network_mode;
6781 FadeOut(REDRAW_ALL);
6785 DrawTextSCentered(ystart, font_title, text);
6789 if (network.enabled)
6790 InitNetworkServer();
6792 DisconnectFromNetworkServer();
6794 DrawTextSCentered(ybottom, font_foot,
6795 "Press any key or button for setup menu");
6797 WaitForEventToContinue();
6802 static void ToggleGameSpeedsListIfNeeded(void)
6804 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6806 if (setup.game_speed_extended == using_game_speeds_extended)
6809 // try to match similar values when changing game speeds list
6810 if (setup.game_speed_extended)
6811 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6812 setup.game_frame_delay == 30 ? 29 :
6813 setup.game_frame_delay);
6815 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6816 setup.game_frame_delay == 16 ? 15 :
6817 setup.game_frame_delay >= 29 ? 30 :
6818 setup.game_frame_delay <= 10 ? 10 :
6819 setup.game_frame_delay);
6821 execSetupGame_setGameSpeeds(TRUE);
6826 static void ModifyGameSpeedIfNeeded(void)
6828 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6829 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6833 char *game_speed_text = "Fast";
6834 int game_speed_value = 15;
6836 if (setup.game_speed_extended)
6838 game_speed_text = "60 fps";
6839 game_speed_value = 16;
6842 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6844 // set game speed to existing list value that is fast enough for vsync
6845 setup.game_frame_delay = game_speed_value;
6847 execSetupGame_setGameSpeeds(TRUE);
6849 Request(message, REQ_CONFIRM);
6852 static void DisableVsyncIfNeeded(void)
6854 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6855 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6856 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6859 // disable vsync for the selected game speed to work
6860 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6862 execSetupGraphics_setVsyncModes(TRUE);
6864 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6870 void *related_value;
6871 } hide_related_entry_list[] =
6873 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6874 { &setup.game_frame_delay, &game_speed_text },
6876 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6877 { &setup.scroll_delay_value, &scroll_delay_text },
6879 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6880 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6882 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6883 { &setup.window_scaling_percent, &window_size_text },
6885 { &setup.window_scaling_quality, execSetupChooseScalingType },
6886 { &setup.window_scaling_quality, &scaling_type_text },
6888 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6889 { &setup.screen_rendering_mode, &rendering_mode_text },
6891 { &setup.vsync_mode, execSetupChooseVsyncMode },
6892 { &setup.vsync_mode, &vsync_mode_text },
6894 { &setup.graphics_set, execSetupChooseGraphics },
6895 { &setup.graphics_set, &graphics_set_name },
6897 { &setup.sounds_set, execSetupChooseSounds },
6898 { &setup.sounds_set, &sounds_set_name },
6900 { &setup.music_set, execSetupChooseMusic },
6901 { &setup.music_set, &music_set_name },
6903 { &setup.volume_simple, execSetupChooseVolumeSimple },
6904 { &setup.volume_simple, &volume_simple_text },
6906 { &setup.volume_loops, execSetupChooseVolumeLoops },
6907 { &setup.volume_loops, &volume_loops_text },
6909 { &setup.volume_music, execSetupChooseVolumeMusic },
6910 { &setup.volume_music, &volume_music_text },
6912 { &setup.touch.control_type, execSetupChooseTouchControls },
6913 { &setup.touch.control_type, &touch_controls_text },
6915 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6916 { &setup.touch.move_distance, &move_distance_text },
6918 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6919 { &setup.touch.drop_distance, &drop_distance_text },
6921 { &setup.touch.transparency, execSetupChooseTransparency },
6922 { &setup.touch.transparency, &transparency_text },
6924 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6925 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6927 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6928 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6930 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6931 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6933 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6934 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6936 { &setup.internal.menu_game, execSetupGame },
6937 { &setup.internal.menu_engines, execSetupEngines },
6938 { &setup.internal.menu_editor, execSetupEditor },
6939 { &setup.internal.menu_graphics, execSetupGraphics },
6940 { &setup.internal.menu_sound, execSetupSound },
6941 { &setup.internal.menu_artwork, execSetupArtwork },
6942 { &setup.internal.menu_input, execSetupInput },
6943 { &setup.internal.menu_touch, execSetupTouch },
6944 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6945 { &setup.internal.menu_exit, execExitSetup },
6946 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6951 void setHideRelatedSetupEntries(void)
6955 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6956 if (hideSetupEntry(hide_related_entry_list[i].value))
6957 setHideSetupEntry(hide_related_entry_list[i].related_value);
6960 static struct TokenInfo setup_info_main[] =
6962 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6963 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6964 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6965 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6966 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6967 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6968 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6969 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6970 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6971 { TYPE_EMPTY, NULL, "" },
6972 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6973 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6978 static struct TokenInfo setup_info_game[] =
6980 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6981 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6982 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6983 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6984 { TYPE_STRING, &network_server_text, "" },
6985 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
6986 { TYPE_SWITCH, &setup.only_show_local_scores, "Only Show Local Scores:" },
6987 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload All Tapes to Server" },
6988 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
6989 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6990 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6991 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6992 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6993 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6994 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6995 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
6996 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
6997 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6998 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
6999 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7000 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7001 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7002 { TYPE_STRING, &game_speed_text, "" },
7003 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7005 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7006 { TYPE_STRING, &scroll_delay_text, "" },
7008 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7009 { TYPE_STRING, &snapshot_mode_text, "" },
7010 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7011 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7012 { TYPE_EMPTY, NULL, "" },
7013 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7018 static struct TokenInfo setup_info_engines[] =
7020 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7021 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7022 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7023 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7024 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7025 { TYPE_EMPTY, NULL, "" },
7026 { TYPE_HEADLINE, NULL, "Supaplex" },
7027 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7028 { TYPE_EMPTY, NULL, "" },
7029 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7034 static struct TokenInfo setup_info_editor[] =
7037 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7038 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7039 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7040 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7041 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7042 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7043 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7044 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7045 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7046 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7048 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7049 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7051 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7053 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7054 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7055 { TYPE_EMPTY, NULL, "" },
7057 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7058 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7059 { TYPE_EMPTY, NULL, "" },
7061 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7062 { TYPE_EMPTY, NULL, "" },
7063 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7064 { TYPE_EMPTY, NULL, "" },
7065 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7070 static struct TokenInfo setup_info_graphics[] =
7072 #if !defined(PLATFORM_ANDROID)
7073 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7074 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7075 { TYPE_STRING, &window_size_text, "" },
7076 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7077 { TYPE_STRING, &scaling_type_text, "" },
7078 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7079 { TYPE_STRING, &rendering_mode_text, "" },
7082 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7083 { TYPE_STRING, &scroll_delay_text, "" },
7085 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7086 { TYPE_STRING, &vsync_mode_text, "" },
7087 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7088 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7089 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7090 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7091 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7092 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7093 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7094 { TYPE_EMPTY, NULL, "" },
7095 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7100 static struct TokenInfo setup_info_sound[] =
7102 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7103 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7104 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7105 { TYPE_EMPTY, NULL, "" },
7106 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7107 { TYPE_STRING, &volume_simple_text, "" },
7108 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7109 { TYPE_STRING, &volume_loops_text, "" },
7110 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7111 { TYPE_STRING, &volume_music_text, "" },
7112 { TYPE_EMPTY, NULL, "" },
7113 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7118 static struct TokenInfo setup_info_artwork[] =
7120 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7121 { TYPE_STRING, &graphics_set_name, "" },
7122 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7123 { TYPE_STRING, &sounds_set_name, "" },
7124 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7125 { TYPE_STRING, &music_set_name, "" },
7126 { TYPE_EMPTY, NULL, "" },
7127 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7128 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7129 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7130 { TYPE_EMPTY, NULL, "" },
7131 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7136 static struct TokenInfo setup_info_input[] =
7138 { TYPE_SWITCH, NULL, "Player:" },
7139 { TYPE_SWITCH, NULL, "Device:" },
7140 { TYPE_SWITCH, NULL, "" },
7141 { TYPE_SKIPPABLE, NULL, "" },
7142 { TYPE_EMPTY, NULL, "" },
7143 { TYPE_EMPTY, NULL, "" },
7144 { TYPE_EMPTY, NULL, "" },
7145 { TYPE_EMPTY, NULL, "" },
7146 { TYPE_EMPTY, NULL, "" },
7147 { TYPE_EMPTY, NULL, "" },
7148 { TYPE_EMPTY, NULL, "" },
7149 { TYPE_EMPTY, NULL, "" },
7150 { TYPE_SKIPPABLE, NULL, "" },
7151 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7156 static struct TokenInfo setup_info_touch[] =
7158 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7159 { TYPE_STRING, &touch_controls_text, "" },
7160 { TYPE_EMPTY, NULL, "" },
7161 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7166 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7168 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7169 { TYPE_STRING, &touch_controls_text, "" },
7170 { TYPE_EMPTY, NULL, "" },
7171 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7172 { TYPE_STRING, &grid_size_text[0][0], "" },
7173 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7174 { TYPE_STRING, &grid_size_text[0][1], "" },
7175 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7176 { TYPE_STRING, &transparency_text, "" },
7177 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7178 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7179 { TYPE_EMPTY, NULL, "" },
7180 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7181 { TYPE_EMPTY, NULL, "" },
7182 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7187 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7189 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7190 { TYPE_STRING, &touch_controls_text, "" },
7191 { TYPE_EMPTY, NULL, "" },
7192 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7193 { TYPE_STRING, &grid_size_text[1][0], "" },
7194 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7195 { TYPE_STRING, &grid_size_text[1][1], "" },
7196 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7197 { TYPE_STRING, &transparency_text, "" },
7198 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7199 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7200 { TYPE_EMPTY, NULL, "" },
7201 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7202 { TYPE_EMPTY, NULL, "" },
7203 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7208 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7210 setup_info_touch_virtual_buttons_0,
7211 setup_info_touch_virtual_buttons_1
7214 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7216 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7217 { TYPE_STRING, &touch_controls_text, "" },
7218 { TYPE_EMPTY, NULL, "" },
7219 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7220 { TYPE_STRING, &move_distance_text, "" },
7221 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7222 { TYPE_STRING, &drop_distance_text, "" },
7223 { TYPE_EMPTY, NULL, "" },
7224 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7229 static struct TokenInfo setup_info_shortcuts[] =
7231 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7232 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7233 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7234 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7235 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7236 { TYPE_EMPTY, NULL, "" },
7237 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7242 static struct TokenInfo setup_info_shortcuts_1[] =
7244 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7245 { TYPE_KEY, &setup.shortcut.save_game, "" },
7246 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7247 { TYPE_KEY, &setup.shortcut.load_game, "" },
7248 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7249 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7250 { TYPE_EMPTY, NULL, "" },
7251 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7252 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7253 { TYPE_EMPTY, NULL, "" },
7254 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7259 static struct TokenInfo setup_info_shortcuts_2[] =
7261 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7262 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7263 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7264 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7265 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7266 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7267 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7268 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7269 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7270 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7271 { TYPE_EMPTY, NULL, "" },
7272 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7277 static struct TokenInfo setup_info_shortcuts_3[] =
7279 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7280 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7281 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7282 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7283 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7284 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7285 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7286 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7287 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7288 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7289 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7290 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7291 { TYPE_EMPTY, NULL, "" },
7292 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7297 static struct TokenInfo setup_info_shortcuts_4[] =
7299 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7300 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7301 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7302 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7303 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7304 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7305 { TYPE_EMPTY, NULL, "" },
7306 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7311 static struct TokenInfo setup_info_shortcuts_5[] =
7313 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7314 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7315 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7316 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7317 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7318 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7319 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7320 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7321 { TYPE_EMPTY, NULL, "" },
7322 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7327 static Key getSetupKey(void)
7329 Key key = KSYM_UNDEFINED;
7330 boolean got_key_event = FALSE;
7332 while (!got_key_event)
7336 if (NextValidEvent(&event))
7340 case EVENT_KEYPRESS:
7342 key = GetEventKey((KeyEvent *)&event, TRUE);
7344 // press 'Escape' or 'Enter' to keep the existing key binding
7345 if (key == KSYM_Escape || key == KSYM_Return)
7346 key = KSYM_UNDEFINED; // keep old value
7348 got_key_event = TRUE;
7352 case EVENT_KEYRELEASE:
7353 key_joystick_mapping = 0;
7357 HandleOtherEvents(&event);
7368 static int getSetupValueFont(int type, void *value)
7370 if (type & TYPE_GHOSTED)
7371 return FONT_OPTION_OFF;
7372 else if (type & TYPE_KEY)
7373 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7374 else if (type & TYPE_STRING)
7375 return FONT_VALUE_2;
7376 else if (type & TYPE_ECS_AGA)
7377 return FONT_VALUE_1;
7378 else if (type & TYPE_BOOLEAN_STYLE)
7379 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7380 else if (type & TYPE_YES_NO_AUTO)
7381 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7382 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7383 else if (type & TYPE_PLAYER)
7384 return FONT_VALUE_1;
7386 return FONT_VALUE_1;
7389 static int getSetupValueFontNarrow(int type, int font_nr)
7391 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7392 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7393 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7397 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7399 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7400 struct TokenInfo *si = &setup_info[si_pos];
7401 boolean font_draw_xoffset_modified = FALSE;
7402 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7403 int font_draw_xoffset_old = -1;
7404 int xoffset = (scrollbar_needed ? -1 : 0);
7405 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7406 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7407 int xpos = menu_screen_value_xpos;
7408 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7409 int startx = mSX + xpos * 32;
7410 int starty = mSY + ypos * 32;
7411 int type = si->type;
7412 void *value = si->value;
7413 char *value_string = getSetupValue(type, value);
7414 int font_nr_default = getSetupValueFont(type, value);
7415 int font_width_default = getFontWidth(font_nr_default);
7416 int font_nr = font_nr_default;
7419 if (value_string == NULL)
7422 if (type & TYPE_KEY)
7424 xpos = MENU_SCREEN_START_XPOS;
7426 if (type & TYPE_QUERY)
7427 value_string = "<press key>";
7429 else if (type & TYPE_STRING)
7431 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7433 xpos = MENU_SCREEN_START_XPOS;
7435 if (strlen(value_string) > max_value_len)
7436 value_string[max_value_len] = '\0';
7438 else if (type & TYPE_YES_NO_AUTO)
7440 xpos = menu_screen_value_xpos - 1;
7442 else if (type & TYPE_PLAYER)
7444 int displayed_player_nr = *(int *)value + 1;
7446 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7449 startx = mSX + xpos * 32;
7450 starty = mSY + ypos * 32;
7452 // special check if right-side setup values moved left due to scrollbar
7453 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7455 int max_menu_text_length = 26; // maximum text length for classic menu
7456 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7457 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7458 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7459 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7460 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7462 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7464 // when using narrow font, left-shifting text "auto" not needed
7465 if (type & TYPE_YES_NO_AUTO)
7469 startx = mSX + xpos * 32;
7471 font_nr = getSetupValueFontNarrow(type, font_nr);
7475 // downward compatibility correction for Juergen Bonhagen's menu settings
7476 if (setup_mode != SETUP_MODE_INPUT)
7478 int max_menu_text_length_big = (menu_screen_value_xpos -
7479 MENU_SCREEN_START_XPOS);
7480 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7481 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7482 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7483 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
7484 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7485 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7486 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7487 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7488 boolean correct_font_draw_xoffset = FALSE;
7490 if (xpos == MENU_SCREEN_START_XPOS &&
7491 startx + font1_xoffset < text_startx + text_font_xoffset)
7492 correct_font_draw_xoffset = TRUE;
7494 if (xpos == menu_screen_value_xpos &&
7495 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7496 correct_font_draw_xoffset = TRUE;
7498 // check if setup value would overlap with setup text when printed
7499 // (this can happen for extreme/wrong values for font draw offset)
7500 if (correct_font_draw_xoffset)
7502 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
7503 font_draw_xoffset_modified = TRUE;
7505 if (type & TYPE_KEY)
7506 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7507 else if (!(type & TYPE_STRING))
7508 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7509 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7513 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7514 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7516 DrawText(startx, starty, value_string, font_nr);
7518 if (type & TYPE_PLAYER)
7520 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7521 int player_nr = *(int *)value;
7522 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7523 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7524 int startx2 = startx + xoff;
7525 int starty2 = starty + yoff;
7527 if (DrawingOnBackground(startx2, starty2))
7528 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7530 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7531 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7534 if (font_draw_xoffset_modified)
7535 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7538 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7540 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7541 struct TokenInfo *si = &setup_info[si_pos];
7543 if (si->type & TYPE_BOOLEAN_STYLE)
7545 *(boolean *)si->value ^= TRUE;
7547 else if (si->type & TYPE_YES_NO_AUTO)
7551 (*(int *)si->value == AUTO ? TRUE :
7552 *(int *)si->value == TRUE ? FALSE : AUTO) :
7553 (*(int *)si->value == TRUE ? AUTO :
7554 *(int *)si->value == AUTO ? FALSE : TRUE));
7556 else if (si->type & TYPE_KEY)
7560 si->type |= TYPE_QUERY;
7561 drawSetupValue(screen_pos, setup_info_pos_raw);
7562 si->type &= ~TYPE_QUERY;
7564 key = getSetupKey();
7565 if (key != KSYM_UNDEFINED)
7566 *(Key *)si->value = key;
7568 else if (si->type & TYPE_PLAYER)
7570 int player_nr = *(int *)si->value;
7575 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7577 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7580 drawSetupValue(screen_pos, setup_info_pos_raw);
7582 // fullscreen state may have changed at this point
7583 if (si->value == &setup.fullscreen)
7584 ToggleFullscreenIfNeeded();
7586 // network mode may have changed at this point
7587 if (si->value == &setup.network_mode)
7588 ToggleNetworkModeIfNeeded();
7590 // API server mode may have changed at this point
7591 if (si->value == &setup.use_api_server)
7592 runtime.use_api_server = setup.use_api_server;
7594 // game speed list may have changed at this point
7595 if (si->value == &setup.game_speed_extended)
7596 ToggleGameSpeedsListIfNeeded();
7599 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7601 static struct TokenInfo *setup_info_final = NULL;
7606 // determine maximum list size of target list
7607 while (setup_info_orig[list_size++].type != 0);
7609 // free, allocate and clear memory for target list
7610 checked_free(setup_info_final);
7611 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7613 // copy setup info list without setup entries marked as hidden
7614 for (i = 0; setup_info_orig[i].type != 0; i++)
7616 // skip setup entries configured to be hidden
7617 if (hideSetupEntry(setup_info_orig[i].value))
7620 // skip skippable setup entries if screen is lower than usual
7621 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7622 setup_info_orig[i].type == TYPE_SKIPPABLE)
7625 setup_info_final[list_pos++] = setup_info_orig[i];
7628 return setup_info_final;
7631 static void DrawSetupScreen_Generic(void)
7633 int fade_mask = REDRAW_FIELD;
7634 boolean redraw_all = FALSE;
7635 char *title_string = NULL;
7639 fade_mask = REDRAW_ALL;
7642 FadeMenuSoundsAndMusic();
7644 FreeScreenGadgets();
7645 CreateScreenGadgets();
7647 if (redraw_mask & REDRAW_ALL)
7652 // needed if different viewport properties defined for setup screen
7653 ChangeViewportPropertiesIfNeeded();
7655 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7659 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7661 if (setup_mode == SETUP_MODE_MAIN)
7663 setup_info = setup_info_main;
7664 title_string = STR_SETUP_MAIN;
7666 else if (setup_mode == SETUP_MODE_GAME)
7668 setup_info = setup_info_game;
7669 title_string = STR_SETUP_GAME;
7671 else if (setup_mode == SETUP_MODE_ENGINES)
7673 setup_info = setup_info_engines;
7674 title_string = STR_SETUP_ENGINES;
7676 else if (setup_mode == SETUP_MODE_EDITOR)
7678 setup_info = setup_info_editor;
7679 title_string = STR_SETUP_EDITOR;
7681 else if (setup_mode == SETUP_MODE_GRAPHICS)
7683 setup_info = setup_info_graphics;
7684 title_string = STR_SETUP_GRAPHICS;
7686 else if (setup_mode == SETUP_MODE_SOUND)
7688 setup_info = setup_info_sound;
7689 title_string = STR_SETUP_SOUND;
7691 else if (setup_mode == SETUP_MODE_ARTWORK)
7693 setup_info = setup_info_artwork;
7694 title_string = STR_SETUP_ARTWORK;
7696 else if (setup_mode == SETUP_MODE_TOUCH)
7698 setup_info = setup_info_touch;
7699 title_string = STR_SETUP_TOUCH;
7701 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7702 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7703 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7704 setup_info = setup_info_touch_wipe_gestures;
7706 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7708 setup_info = setup_info_shortcuts;
7709 title_string = STR_SETUP_SHORTCUTS;
7711 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7713 setup_info = setup_info_shortcuts_1;
7714 title_string = STR_SETUP_SHORTCUTS;
7716 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7718 setup_info = setup_info_shortcuts_2;
7719 title_string = STR_SETUP_SHORTCUTS;
7721 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7723 setup_info = setup_info_shortcuts_3;
7724 title_string = STR_SETUP_SHORTCUTS;
7726 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7728 setup_info = setup_info_shortcuts_4;
7729 title_string = STR_SETUP_SHORTCUTS;
7731 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7733 setup_info = setup_info_shortcuts_5;
7734 title_string = STR_SETUP_SHORTCUTS;
7737 // use modified setup info without setup entries marked as hidden
7738 setup_info = getSetupInfoFinal(setup_info);
7740 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7742 // determine maximal number of setup entries that can be displayed on screen
7744 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7747 // determine maximal number of setup entries available for this setup screen
7749 for (i = 0; setup_info[i].type != 0; i++)
7752 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7754 MapScreenGadgets(max_setup_info);
7757 redraw_mask = fade_mask = REDRAW_ALL;
7759 DrawMaskedBorder(fade_mask);
7764 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7766 menu_info = setup_info;
7768 HandleMenuScreen(mx, my, dx, dy, button,
7769 setup_mode, num_setup_info, max_setup_info);
7772 static void DrawSetupScreen_Input(void)
7776 FadeOut(REDRAW_FIELD);
7780 setup_info = getSetupInfoFinal(setup_info_input);
7782 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7784 for (i = 0; setup_info[i].type != 0; i++)
7786 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7787 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7788 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7789 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7790 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7791 initCursor(i, IMG_MENU_BUTTON);
7793 DrawCursorAndText_Setup(i, -1, FALSE);
7796 // create gadgets for setup input menu screen
7797 FreeScreenGadgets();
7798 CreateScreenGadgets();
7800 // map gadgets for setup input menu screen
7801 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7803 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7805 FadeIn(REDRAW_FIELD);
7808 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7810 if (device_name == NULL)
7813 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7816 if (strlen(device_name) > 1)
7818 char c1 = device_name[strlen(device_name) - 1];
7819 char c2 = device_name[strlen(device_name) - 2];
7821 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7822 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7825 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7826 strlen(device_name));
7829 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7832 static struct SetupKeyboardInfo custom_key;
7839 { &custom_key.left, "Axis/Pad Left" },
7840 { &custom_key.right, "Axis/Pad Right" },
7841 { &custom_key.up, "Axis/Pad Up" },
7842 { &custom_key.down, "Axis/Pad Down" },
7843 { &custom_key.snap, "Button 1/A/X" },
7844 { &custom_key.drop, "Button 2/B/Y" }
7846 static char *joystick_name[MAX_PLAYERS] =
7853 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7854 int font_nr_info = FONT_MENU_1;
7855 int font_nr_name = FONT_VALUE_OLD;
7856 int font_nr_on = FONT_VALUE_1;
7857 int font_nr_off = FONT_VALUE_OLD;
7860 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7862 font_nr_info = FONT_MENU_2;
7863 font_nr_on = FONT_VALUE_NARROW;
7864 font_nr_off = FONT_VALUE_OLD_NARROW;
7867 custom_key = setup.input[player_nr].key;
7869 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7870 FONT_INPUT_1_ACTIVE);
7872 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7874 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7875 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7877 if (setup.input[player_nr].use_joystick)
7879 char *device_name = setup.input[player_nr].joy.device_name;
7880 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7881 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7882 char *text = joystick_name[joystick_nr];
7883 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7885 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7886 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7890 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7891 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7894 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7895 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7899 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7900 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7901 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7902 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7904 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7905 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7906 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7907 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7908 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7909 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7911 for (i = 0; i < 6; i++)
7913 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7915 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7917 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7918 (setup.input[player_nr].use_joystick ?
7920 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7924 static int input_player_nr = 0;
7926 static void HandleSetupScreen_Input_Player(int step, int direction)
7928 int old_player_nr = input_player_nr;
7931 new_player_nr = old_player_nr + step * direction;
7932 if (new_player_nr < 0)
7934 if (new_player_nr > MAX_PLAYERS - 1)
7935 new_player_nr = MAX_PLAYERS - 1;
7937 if (new_player_nr != old_player_nr)
7939 input_player_nr = new_player_nr;
7941 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7945 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7947 static int choice = 0;
7950 int pos_start = SETUPINPUT_SCREEN_POS_START;
7951 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7952 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7953 int pos_end = SETUPINPUT_SCREEN_POS_END;
7955 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7959 for (i = 0; setup_info_input[i].type != 0; i++)
7961 // adjust menu structure according to skipped setup entries
7962 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7970 if (button == MB_MENU_INITIALIZE)
7972 // input setup menu may have changed size due to graphics configuration
7973 if (choice >= pos_empty1)
7976 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7978 DrawCursorAndText_Setup(choice, -1, TRUE);
7982 else if (button == MB_MENU_LEAVE)
7984 setup_mode = SETUP_MODE_MAIN;
7991 if (mx || my) // mouse input
7993 x = (mx - mSX) / 32;
7994 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7996 else if (dx || dy) // keyboard input
7998 if (dx && choice == 0)
7999 x = (dx < 0 ? 10 : 12);
8000 else if ((dx && choice == 1) ||
8001 (dx == -1 && choice == pos_end))
8002 button = MB_MENU_CHOICE;
8006 if (y >= pos_empty1 && y <= pos_empty2)
8007 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8010 if (y == 0 && dx != 0 && button)
8012 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8014 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8015 y >= pos_start && y <= pos_end &&
8016 !(y >= pos_empty1 && y <= pos_empty2))
8022 DrawCursorAndText_Setup(choice, -1, FALSE);
8023 DrawCursorAndText_Setup(y, -1, TRUE);
8025 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8034 char *device_name = setup.input[input_player_nr].joy.device_name;
8036 if (!setup.input[input_player_nr].use_joystick)
8038 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8040 setJoystickDeviceToNr(device_name, new_device_nr);
8041 setup.input[input_player_nr].use_joystick = TRUE;
8045 int device_nr = getJoystickNrFromDeviceName(device_name);
8046 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8048 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8049 setup.input[input_player_nr].use_joystick = FALSE;
8051 setJoystickDeviceToNr(device_name, new_device_nr);
8054 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8058 if (setup.input[input_player_nr].use_joystick)
8059 ConfigureJoystick(input_player_nr);
8061 CustomizeKeyboard(input_player_nr);
8063 else if (y == pos_end)
8069 setup_mode = SETUP_MODE_MAIN;
8076 static boolean CustomizeKeyboardMain(int player_nr)
8080 boolean finished = FALSE;
8081 static struct SetupKeyboardInfo custom_key;
8086 } customize_step[] =
8088 { &custom_key.left, "Move Left" },
8089 { &custom_key.right, "Move Right" },
8090 { &custom_key.up, "Move Up" },
8091 { &custom_key.down, "Move Down" },
8092 { &custom_key.snap, "Snap Field" },
8093 { &custom_key.drop, "Drop Element" }
8095 int font_nr_old = FONT_VALUE_OLD;
8096 int font_nr_new = FONT_VALUE_1;
8097 boolean success = FALSE;
8099 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8101 font_nr_old = FONT_VALUE_OLD_NARROW;
8102 font_nr_new = FONT_VALUE_NARROW;
8105 // read existing key bindings from player setup
8106 custom_key = setup.input[player_nr].key;
8109 FadeOut(REDRAW_FIELD);
8113 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8116 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8117 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8118 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8119 "Key:", FONT_INPUT_1_ACTIVE);
8120 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8121 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8123 FadeIn(REDRAW_FIELD);
8129 if (NextValidEvent(&event))
8133 case EVENT_KEYPRESS:
8135 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8137 // press 'Escape' to abort and keep the old key bindings
8138 if (key == KSYM_Escape)
8140 FadeSkipNextFadeIn();
8147 // press 'Enter' to keep the existing key binding
8148 if (key == KSYM_Return)
8149 key = *customize_step[step_nr].key;
8151 // check if key already used
8152 for (i = 0; i < step_nr; i++)
8153 if (*customize_step[i].key == key)
8158 // got new key binding
8159 *customize_step[step_nr].key = key;
8160 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8162 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8163 getKeyNameFromKey(key), font_nr_new);
8166 // un-highlight last query
8167 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8168 customize_step[step_nr - 1].text, FONT_MENU_1);
8169 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8170 "Key:", FONT_MENU_1);
8172 // all keys configured
8181 // query next key binding
8182 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8183 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8184 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8185 "Key:", FONT_INPUT_1_ACTIVE);
8186 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8187 getKeyNameFromKey(*customize_step[step_nr].key),
8192 case EVENT_KEYRELEASE:
8193 key_joystick_mapping = 0;
8197 HandleOtherEvents(&event);
8205 // write new key bindings back to player setup, if successfully finished
8207 setup.input[player_nr].key = custom_key;
8212 void CustomizeKeyboard(int player_nr)
8214 boolean success = CustomizeKeyboardMain(player_nr);
8218 int font_nr = FONT_TITLE_1;
8219 int font_height = getFontHeight(font_nr);
8220 int ypos1 = SYSIZE / 2 - font_height * 2;
8221 int ypos2 = SYSIZE / 2 - font_height * 1;
8222 unsigned int wait_frame_delay = 0;
8223 unsigned int wait_frame_delay_value = 2000;
8225 ResetDelayCounter(&wait_frame_delay);
8229 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8230 DrawTextSCentered(ypos2, font_nr, "configured!");
8232 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8238 DrawSetupScreen_Input();
8241 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8243 #define MARKER_BUTTON 1
8244 #define MARKER_AXIS_X 2
8245 #define MARKER_AXIS_Y 3
8247 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8249 static boolean bitmaps_initialized = FALSE;
8250 boolean screen_initialized = FALSE;
8251 static Bitmap *controller, *button, *axis_x, *axis_y;
8253 boolean success = TRUE;
8254 boolean done = FALSE, next = FALSE;
8256 int alpha = 200, alpha_step = -1;
8257 int alpha_ticks = 0;
8258 char mapping[4096], temp[256];
8259 int font_name = MENU_SETUP_FONT_TITLE;
8260 int font_info = MENU_SETUP_FONT_TEXT;
8261 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8262 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8263 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8264 int ystep_name = getMenuTextStep(spacing_name, font_name);
8265 int ystep_line = getMenuTextStep(spacing_line, font_info);
8266 int ystep_para = getMenuTextStep(spacing_para, font_info);
8274 int axis, button, hat, hat_value;
8277 *step, *prev_step, steps[] =
8279 { 356, 155, MARKER_BUTTON, "a", },
8280 { 396, 122, MARKER_BUTTON, "b", },
8281 { 320, 125, MARKER_BUTTON, "x", },
8282 { 358, 95, MARKER_BUTTON, "y", },
8283 { 162, 125, MARKER_BUTTON, "back", },
8284 { 216, 125, MARKER_BUTTON, "guide", },
8285 { 271, 125, MARKER_BUTTON, "start", },
8286 { 110, 200, MARKER_BUTTON, "dpleft", },
8287 { 146, 228, MARKER_BUTTON, "dpdown", },
8288 { 178, 200, MARKER_BUTTON, "dpright", },
8289 { 146, 172, MARKER_BUTTON, "dpup", },
8290 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8291 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8292 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8293 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8294 { 73, 141, MARKER_BUTTON, "leftstick", },
8295 { 282, 210, MARKER_BUTTON, "rightstick", },
8296 { 73, 141, MARKER_AXIS_X, "leftx", },
8297 { 73, 141, MARKER_AXIS_Y, "lefty", },
8298 { 282, 210, MARKER_AXIS_X, "rightx", },
8299 { 282, 210, MARKER_AXIS_Y, "righty", },
8302 unsigned int event_frame_delay = 0;
8303 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8305 ResetDelayCounter(&event_frame_delay);
8307 if (!bitmaps_initialized)
8309 controller = LoadCustomImage("joystick/controller.png");
8310 button = LoadCustomImage("joystick/button.png");
8311 axis_x = LoadCustomImage("joystick/axis_x.png");
8312 axis_y = LoadCustomImage("joystick/axis_y.png");
8314 bitmaps_initialized = TRUE;
8317 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8320 // print info about the joystick we are watching
8321 Debug("joystick", "watching joystick %d: (%s)",
8322 SDL_JoystickInstanceID(joystick), name);
8323 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8324 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8325 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8328 // initialize mapping with GUID and name
8329 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8331 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8332 temp, name, SDL_GetPlatform());
8334 // loop through all steps (buttons and axes), getting joystick events
8335 for (i = 0; i < SDL_arraysize(steps) && !done;)
8337 Bitmap *marker = button; // initialize with reliable default value
8340 strcpy(step->mapping, mapping);
8344 step->hat_value = -1;
8346 marker = (step->marker == MARKER_BUTTON ? button :
8347 step->marker == MARKER_AXIS_X ? axis_x :
8348 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8352 while (!done && !next)
8354 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8355 alpha_ticks = SDL_GetTicks();
8362 else if (alpha < 128)
8368 int controller_x = SX + (SXSIZE - controller->width) / 2;
8369 int controller_y = SY + ystep_line;
8371 int marker_x = controller_x + step->x;
8372 int marker_y = controller_y + step->y;
8374 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8375 int ystart2 = ystart1 + ystep_name + ystep_line;
8379 DrawTextSCentered(ystart1, font_name, name);
8381 DrawTextSCentered(ystart2, font_info,
8382 "Press buttons and move axes on");
8383 ystart2 += ystep_line;
8384 DrawTextSCentered(ystart2, font_info,
8385 "your controller when indicated.");
8386 ystart2 += ystep_line;
8387 DrawTextSCentered(ystart2, font_info,
8388 "(Your controller may look different.)");
8389 ystart2 += ystep_para;
8391 #if defined(PLATFORM_ANDROID)
8392 DrawTextSCentered(ystart2, font_info,
8393 "To correct a mistake,");
8394 ystart2 += ystep_line;
8395 DrawTextSCentered(ystart2, font_info,
8396 "press the 'back' button.");
8397 ystart2 += ystep_line;
8398 DrawTextSCentered(ystart2, font_info,
8399 "To skip a button or axis,");
8400 ystart2 += ystep_line;
8401 DrawTextSCentered(ystart2, font_info,
8402 "press the 'menu' button.");
8404 DrawTextSCentered(ystart2, font_info,
8405 "To correct a mistake,");
8406 ystart2 += ystep_line;
8407 DrawTextSCentered(ystart2, font_info,
8408 "press the 'backspace' key.");
8409 ystart2 += ystep_line;
8410 DrawTextSCentered(ystart2, font_info,
8411 "To skip a button or axis,");
8412 ystart2 += ystep_line;
8413 DrawTextSCentered(ystart2, font_info,
8414 "press the 'return' key.");
8415 ystart2 += ystep_line;
8416 DrawTextSCentered(ystart2, font_info,
8417 "To exit, press the 'escape' key.");
8420 BlitBitmapMasked(controller, drawto, 0, 0,
8421 controller->width, controller->height,
8422 controller_x, controller_y);
8424 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8425 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8427 BlitBitmapMasked(marker, drawto, 0, 0,
8428 marker->width, marker->height,
8429 marker_x, marker_y);
8431 if (!screen_initialized)
8432 FadeIn(REDRAW_FIELD);
8436 screen_initialized = TRUE;
8438 while (NextValidEvent(&event))
8442 case SDL_JOYAXISMOTION:
8443 if (event.jaxis.value > 20000 ||
8444 event.jaxis.value < -20000)
8446 for (j = 0; j < i; j++)
8447 if (steps[j].axis == event.jaxis.axis)
8452 if (step->marker != MARKER_AXIS_X &&
8453 step->marker != MARKER_AXIS_Y)
8456 step->axis = event.jaxis.axis;
8457 strcat(mapping, step->field);
8458 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8459 strcat(mapping, temp);
8467 case SDL_JOYHATMOTION:
8468 // ignore centering; we're probably just coming back
8469 // to the center from the previous item we set
8470 if (event.jhat.value == SDL_HAT_CENTERED)
8473 for (j = 0; j < i; j++)
8474 if (steps[j].hat == event.jhat.hat &&
8475 steps[j].hat_value == event.jhat.value)
8480 step->hat = event.jhat.hat;
8481 step->hat_value = event.jhat.value;
8482 strcat(mapping, step->field);
8483 snprintf(temp, sizeof(temp), ":h%u.%u,",
8484 event.jhat.hat, event.jhat.value );
8485 strcat(mapping, temp);
8492 case SDL_JOYBALLMOTION:
8495 case SDL_JOYBUTTONUP:
8496 for (j = 0; j < i; j++)
8497 if (steps[j].button == event.jbutton.button)
8502 step->button = event.jbutton.button;
8503 strcat(mapping, step->field);
8504 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8505 strcat(mapping, temp);
8512 case SDL_FINGERDOWN:
8513 case SDL_MOUSEBUTTONDOWN:
8521 if (event.key.keysym.sym == KSYM_BackSpace ||
8522 event.key.keysym.sym == KSYM_Back)
8534 prev_step = &steps[i - 1];
8535 strcpy(mapping, prev_step->mapping);
8542 if (event.key.keysym.sym == KSYM_space ||
8543 event.key.keysym.sym == KSYM_Return ||
8544 event.key.keysym.sym == KSYM_Menu)
8553 if (event.key.keysym.sym == KSYM_Escape)
8563 program.exit_function(0);
8570 // do not handle events for longer than standard frame delay period
8571 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8580 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8583 // activate mapping for this game
8584 SDL_GameControllerAddMapping(mapping);
8586 // save mapping to personal mappings
8587 SaveSetup_AddGameControllerMapping(mapping);
8590 // wait until the last pending event was removed from event queue
8591 while (NextValidEvent(&event));
8596 static int ConfigureJoystickMain(int player_nr)
8598 char *device_name = setup.input[player_nr].joy.device_name;
8599 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8600 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8601 int success = FALSE;
8604 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8605 return JOYSTICK_NOT_AVAILABLE;
8607 if (!joystick_active || !setup.input[player_nr].use_joystick)
8608 return JOYSTICK_NOT_AVAILABLE;
8611 FadeOut(REDRAW_FIELD);
8613 // close all joystick devices (potentially opened as game controllers)
8614 for (i = 0; i < SDL_NumJoysticks(); i++)
8615 SDLCloseJoystick(i);
8617 // open joystick device as plain joystick to configure as game controller
8618 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8620 // as the joystick was successfully opened before, this should not happen
8621 if (joystick == NULL)
8624 // create new game controller mapping (buttons and axes) for joystick device
8625 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8627 // close joystick (and maybe re-open as configured game controller later)
8628 SDL_JoystickClose(joystick);
8630 // re-open all joystick devices (potentially as game controllers)
8631 for (i = 0; i < SDL_NumJoysticks(); i++)
8634 // clear all joystick input actions for all joystick devices
8635 SDLClearJoystickState();
8637 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8640 void ConfigureJoystick(int player_nr)
8642 boolean state = ConfigureJoystickMain(player_nr);
8644 if (state != JOYSTICK_NOT_CONFIGURED)
8646 boolean success = (state == JOYSTICK_CONFIGURED);
8647 char message1[MAX_OUTPUT_LINESIZE + 1];
8648 char *message2 = (success ? "configured!" : "not available!");
8649 char *device_name = setup.input[player_nr].joy.device_name;
8650 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8651 int font_nr = FONT_TITLE_1;
8652 int font_height = getFontHeight(font_nr);
8653 int ypos1 = SYSIZE / 2 - font_height * 2;
8654 int ypos2 = SYSIZE / 2 - font_height * 1;
8655 unsigned int wait_frame_delay = 0;
8656 unsigned int wait_frame_delay_value = 2000;
8658 ResetDelayCounter(&wait_frame_delay);
8662 sprintf(message1, "Joystick %d", nr);
8664 DrawTextSCentered(ypos1, font_nr, message1);
8665 DrawTextSCentered(ypos2, font_nr, message2);
8667 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8673 DrawSetupScreen_Input();
8676 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8678 if (y < video.screen_height / 3)
8680 // remap touch gadgets to access upper part of the screen
8681 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8682 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8684 else if (y > 2 * video.screen_height / 3)
8686 // remap touch gadgets to access lower part of the screen
8687 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8688 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8692 static boolean ConfigureVirtualButtonsMain(void)
8694 static char *customize_step_text[] =
8703 char grid_button[] =
8705 CHAR_GRID_BUTTON_LEFT,
8706 CHAR_GRID_BUTTON_RIGHT,
8707 CHAR_GRID_BUTTON_UP,
8708 CHAR_GRID_BUTTON_DOWN,
8709 CHAR_GRID_BUTTON_SNAP,
8710 CHAR_GRID_BUTTON_DROP
8719 int font_nr = FONT_INPUT_1_ACTIVE;
8720 int font_height = getFontHeight(font_nr);
8721 int ypos1 = SYSIZE / 2 - font_height * 2;
8722 int ypos2 = SYSIZE / 2 - font_height * 1;
8723 boolean success = FALSE;
8724 boolean finished = FALSE;
8726 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8727 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8728 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8729 boolean set_grid_button = FALSE;
8730 int nr = GRID_ACTIVE_NR();
8733 for (x = 0; x < MAX_GRID_XSIZE; x++)
8734 for (y = 0; y < MAX_GRID_YSIZE; y++)
8735 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8737 overlay.grid_button_highlight = grid_button[step_nr];
8742 FadeOut(REDRAW_FIELD);
8746 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8747 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8748 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8750 FadeIn(REDRAW_FIELD);
8752 SetOverlayShowGrid(TRUE);
8754 // map gadgets for setup touch buttons menu screen
8755 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8761 while (NextValidEvent(&event))
8763 int action = ACTION_NONE;
8765 // ---------- handle events and set the resulting action ----------
8771 UserEvent *user = (UserEvent *)&event;
8772 int id = user->value1;
8774 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8775 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8776 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8777 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8782 case EVENT_KEYPRESS:
8784 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8786 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8787 key == KSYM_BackSpace ||
8788 key == KSYM_Back ? ACTION_BACK :
8789 key == KSYM_Return ||
8791 key == KSYM_space ? ACTION_NEXT :
8796 case EVENT_KEYRELEASE:
8797 key_joystick_mapping = 0;
8800 case EVENT_BUTTONPRESS:
8801 case EVENT_BUTTONRELEASE:
8803 ButtonEvent *button = (ButtonEvent *)&event;
8805 motion_status = FALSE;
8807 if (button->type == EVENT_BUTTONPRESS)
8808 button_status = button->button;
8810 button_status = MB_RELEASED;
8812 if (HandleGadgets(button->x, button->y, button_status))
8814 // do not handle this button event anymore
8818 button->x += video.screen_xoffset;
8819 button->y += video.screen_yoffset;
8821 x = button->x * overlay.grid_xsize / video.screen_width;
8822 y = button->y * overlay.grid_ysize / video.screen_height;
8824 if (button->type == EVENT_BUTTONPRESS)
8827 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8828 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8830 set_grid_button = TRUE;
8833 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8837 case EVENT_MOTIONNOTIFY:
8839 MotionEvent *motion = (MotionEvent *)&event;
8841 motion_status = TRUE;
8843 if (HandleGadgets(motion->x, motion->y, button_status))
8845 // do not handle this button event anymore
8849 motion->x += video.screen_xoffset;
8850 motion->y += video.screen_yoffset;
8852 x = motion->x * overlay.grid_xsize / video.screen_width;
8853 y = motion->y * overlay.grid_ysize / video.screen_height;
8855 set_grid_button = TRUE;
8857 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8861 case SDL_WINDOWEVENT:
8862 HandleWindowEvent((WindowEvent *) &event);
8864 // check if device has been rotated
8865 if (nr != GRID_ACTIVE_NR())
8867 nr = GRID_ACTIVE_NR();
8869 for (x = 0; x < MAX_GRID_XSIZE; x++)
8870 for (y = 0; y < MAX_GRID_YSIZE; y++)
8871 grid_button_old[x][y] = grid_button_tmp[x][y] =
8872 overlay.grid_button[x][y];
8877 case SDL_APP_WILLENTERBACKGROUND:
8878 case SDL_APP_DIDENTERBACKGROUND:
8879 case SDL_APP_WILLENTERFOREGROUND:
8880 case SDL_APP_DIDENTERFOREGROUND:
8881 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8885 HandleOtherEvents(&event);
8889 // ---------- perform action set by handling events ----------
8891 if (action == ACTION_ESCAPE)
8893 // abort and restore the old key bindings
8895 for (x = 0; x < MAX_GRID_XSIZE; x++)
8896 for (y = 0; y < MAX_GRID_YSIZE; y++)
8897 overlay.grid_button[x][y] = grid_button_old[x][y];
8899 FadeSkipNextFadeIn();
8903 else if (action == ACTION_BACK)
8905 // keep the configured key bindings and go to previous page
8911 FadeSkipNextFadeIn();
8916 else if (action == ACTION_NEXT)
8918 // keep the configured key bindings and go to next page
8922 // all virtual buttons configured
8930 if (action != ACTION_NONE && !finished)
8932 for (x = 0; x < MAX_GRID_XSIZE; x++)
8933 for (y = 0; y < MAX_GRID_YSIZE; y++)
8934 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8936 overlay.grid_button_highlight = grid_button[step_nr];
8938 // configure next virtual button
8942 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8943 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8944 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8947 if (set_grid_button)
8949 overlay.grid_button[x][y] =
8950 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8951 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8952 grid_button_tmp[x][y]);
8954 set_grid_button = FALSE;
8961 for (x = 0; x < MAX_GRID_XSIZE; x++)
8962 for (y = 0; y < MAX_GRID_YSIZE; y++)
8963 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8965 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8967 SetOverlayShowGrid(FALSE);
8972 void ConfigureVirtualButtons(void)
8974 boolean success = ConfigureVirtualButtonsMain();
8976 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8977 SCREEN_MASK_TOUCH2);
8981 int font_nr = FONT_TITLE_1;
8982 int font_height = getFontHeight(font_nr);
8983 int ypos1 = SYSIZE / 2 - font_height * 2;
8984 int ypos2 = SYSIZE / 2 - font_height * 1;
8985 unsigned int wait_frame_delay = 0;
8986 unsigned int wait_frame_delay_value = 2000;
8988 ResetDelayCounter(&wait_frame_delay);
8992 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8993 DrawTextSCentered(ypos2, font_nr, "configured!");
8995 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9002 void DrawSetupScreen(void)
9007 if (setup_mode == SETUP_MODE_INPUT)
9008 DrawSetupScreen_Input();
9009 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9010 DrawChooseTree(&game_speed_current);
9011 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9012 DrawChooseTree(&scroll_delay_current);
9013 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9014 DrawChooseTree(&snapshot_mode_current);
9015 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9016 DrawChooseTree(&window_size_current);
9017 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9018 DrawChooseTree(&scaling_type_current);
9019 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9020 DrawChooseTree(&rendering_mode_current);
9021 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9022 DrawChooseTree(&vsync_mode_current);
9023 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9024 DrawChooseTree(&artwork.gfx_current);
9025 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9026 DrawChooseTree(&artwork.snd_current);
9027 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9028 DrawChooseTree(&artwork.mus_current);
9029 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9030 DrawChooseTree(&volume_simple_current);
9031 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9032 DrawChooseTree(&volume_loops_current);
9033 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9034 DrawChooseTree(&volume_music_current);
9035 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9036 DrawChooseTree(&touch_control_current);
9037 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9038 DrawChooseTree(&move_distance_current);
9039 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9040 DrawChooseTree(&drop_distance_current);
9041 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9042 DrawChooseTree(&transparency_current);
9043 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9044 DrawChooseTree(&grid_size_current[0][0]);
9045 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9046 DrawChooseTree(&grid_size_current[0][1]);
9047 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9048 DrawChooseTree(&grid_size_current[1][0]);
9049 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9050 DrawChooseTree(&grid_size_current[1][1]);
9052 DrawSetupScreen_Generic();
9054 PlayMenuSoundsAndMusic();
9057 void RedrawSetupScreenAfterFullscreenToggle(void)
9059 if (setup_mode == SETUP_MODE_GRAPHICS ||
9060 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9062 // update list selection from "setup.window_scaling_percent"
9063 execSetupGraphics_setWindowSizes(TRUE);
9069 void RedrawSetupScreenAfterScreenRotation(int nr)
9073 if (setup_mode == SETUP_MODE_TOUCH)
9075 // update virtual button settings (depending on screen orientation)
9078 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9080 // save already configured virtual buttons
9081 for (x = 0; x < MAX_GRID_XSIZE; x++)
9082 for (y = 0; y < MAX_GRID_YSIZE; y++)
9083 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9087 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9089 if (setup_mode == SETUP_MODE_INPUT)
9090 HandleSetupScreen_Input(mx, my, dx, dy, button);
9091 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9092 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9093 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9094 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9095 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9096 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9097 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9098 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9099 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9100 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9101 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9102 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9103 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9104 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9105 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9106 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9107 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9108 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9109 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9110 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9111 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9112 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9113 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9114 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9115 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9116 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9117 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9118 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9119 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9120 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9121 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9122 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9123 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9124 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9125 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9126 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9127 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9128 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9129 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9130 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9131 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9132 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9134 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9137 void HandleGameActions(void)
9139 if (setup.ask_on_game_over)
9142 if (game.restart_game_message != NULL)
9144 RequestRestartGame(game.restart_game_message);
9149 if (game_status != GAME_MODE_PLAYING)
9152 GameActions(); // main game loop
9154 if (tape.auto_play && !tape.playing)
9155 AutoPlayTapesContinue(); // continue automatically playing next tape
9159 // ---------- new screen button stuff --------------------------------------
9163 int gfx_unpressed, gfx_pressed;
9164 struct MenuPosInfo *pos;
9165 boolean *check_value;
9168 unsigned int event_mask;
9169 boolean is_touch_button;
9171 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9174 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9175 &menu.main.button.prev_level, NULL,
9176 SCREEN_CTRL_ID_PREV_LEVEL,
9178 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9179 FALSE, "previous level"
9182 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9183 &menu.main.button.next_level, NULL,
9184 SCREEN_CTRL_ID_NEXT_LEVEL,
9186 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9190 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9191 &menu.main.button.first_level, NULL,
9192 SCREEN_CTRL_ID_FIRST_LEVEL,
9195 FALSE, "first level"
9198 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9199 &menu.main.button.last_level, NULL,
9200 SCREEN_CTRL_ID_LAST_LEVEL,
9206 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9207 &menu.main.button.level_number, NULL,
9208 SCREEN_CTRL_ID_LEVEL_NUMBER,
9211 FALSE, "level number"
9214 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9215 &menu.setup.button.prev_player, NULL,
9216 SCREEN_CTRL_ID_PREV_PLAYER,
9218 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9219 FALSE, "previous player"
9222 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9223 &menu.setup.button.next_player, NULL,
9224 SCREEN_CTRL_ID_NEXT_PLAYER,
9226 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9227 FALSE, "next player"
9230 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9231 &menu.main.button.insert_solution, NULL,
9232 SCREEN_CTRL_ID_INSERT_SOLUTION,
9233 SCREEN_MASK_MAIN_HAS_SOLUTION,
9235 FALSE, "insert solution tape"
9238 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9239 &menu.main.button.play_solution, NULL,
9240 SCREEN_CTRL_ID_PLAY_SOLUTION,
9241 SCREEN_MASK_MAIN_HAS_SOLUTION,
9243 FALSE, "play solution tape"
9246 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9247 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9248 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9250 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9251 FALSE, "switch ECS/AGA chipset"
9254 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9255 &menu.setup.button.touch_back, NULL,
9256 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9259 TRUE, "previous page"
9262 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9263 &menu.setup.button.touch_next, NULL,
9264 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9270 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9271 &menu.setup.button.touch_back2, NULL,
9272 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9275 TRUE, "previous page"
9278 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9279 &menu.setup.button.touch_next2, NULL,
9280 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9289 int gfx_unpressed, gfx_pressed;
9293 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9296 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9297 -1, -1, // these values are not constant, but can change at runtime
9298 SCREEN_CTRL_ID_SCROLL_UP,
9302 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9303 -1, -1, // these values are not constant, but can change at runtime
9304 SCREEN_CTRL_ID_SCROLL_DOWN,
9311 int gfx_unpressed, gfx_pressed;
9317 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9320 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9321 -1, -1, // these values are not constant, but can change at runtime
9322 -1, -1, // these values are not constant, but can change at runtime
9323 GD_TYPE_SCROLLBAR_VERTICAL,
9324 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9325 "scroll level series vertically"
9337 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9340 IMG_SETUP_INPUT_TEXT,
9341 SCREEN_CTRL_ID_NETWORK_SERVER,
9342 -1, -1, // these values are not constant, but can change at runtime
9343 MAX_SETUP_TEXT_INPUT_LEN,
9344 network_server_hostname,
9345 "Network Server Hostname / IP"
9349 static void CreateScreenMenubuttons(void)
9351 struct GadgetInfo *gi;
9352 unsigned int event_mask;
9355 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9357 struct MenuPosInfo *pos = menubutton_info[i].pos;
9358 boolean is_touch_button = menubutton_info[i].is_touch_button;
9359 boolean is_check_button = menubutton_info[i].check_value != NULL;
9360 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9361 int gfx_unpressed, gfx_pressed;
9362 int x, y, width, height;
9363 int gd_x1, gd_x2, gd_y1, gd_y2;
9364 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9365 int id = menubutton_info[i].gadget_id;
9366 int type = GD_TYPE_NORMAL_BUTTON;
9367 boolean checked = FALSE;
9369 event_mask = menubutton_info[i].event_mask;
9371 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9372 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9374 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9375 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9377 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9378 gfx_pressed = menubutton_info[i].gfx_pressed;
9379 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9380 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9381 gd_x1 = graphic_info[gfx_unpressed].src_x;
9382 gd_y1 = graphic_info[gfx_unpressed].src_y;
9383 gd_x2 = graphic_info[gfx_pressed].src_x;
9384 gd_y2 = graphic_info[gfx_pressed].src_y;
9390 if (is_touch_button)
9392 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9393 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9396 if (is_check_button)
9398 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9399 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9400 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9401 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9403 type = GD_TYPE_CHECK_BUTTON;
9404 checked = *menubutton_info[i].check_value;
9407 gi = CreateGadget(GDI_CUSTOM_ID, id,
9408 GDI_CUSTOM_TYPE_ID, i,
9409 GDI_IMAGE_ID, gfx_unpressed,
9410 GDI_INFO_TEXT, menubutton_info[i].infotext,
9416 GDI_STATE, GD_BUTTON_UNPRESSED,
9417 GDI_CHECKED, checked,
9418 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9419 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9420 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9421 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9422 GDI_DIRECT_DRAW, FALSE,
9423 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9424 GDI_EVENT_MASK, event_mask,
9425 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9429 Fail("cannot create gadget");
9431 screen_gadget[id] = gi;
9435 static void CreateScreenScrollbuttons(void)
9437 struct GadgetInfo *gi;
9438 unsigned int event_mask;
9441 // these values are not constant, but can change at runtime
9442 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9443 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9444 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9445 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9447 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9449 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9450 int gfx_unpressed, gfx_pressed;
9451 int x, y, width, height;
9452 int gd_x1, gd_x2, gd_y1, gd_y2;
9453 int id = scrollbutton_info[i].gadget_id;
9455 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9457 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9458 y = mSY + scrollbutton_info[i].y;
9459 width = SC_SCROLLBUTTON_XSIZE;
9460 height = SC_SCROLLBUTTON_YSIZE;
9462 // correct scrollbar position if placed outside menu (playfield) area
9463 if (x > SX + SC_SCROLL_UP_XPOS)
9464 x = SX + SC_SCROLL_UP_XPOS;
9466 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9467 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9468 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9470 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9471 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9472 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9473 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9474 gd_x1 = graphic_info[gfx_unpressed].src_x;
9475 gd_y1 = graphic_info[gfx_unpressed].src_y;
9476 gd_x2 = graphic_info[gfx_pressed].src_x;
9477 gd_y2 = graphic_info[gfx_pressed].src_y;
9479 gi = CreateGadget(GDI_CUSTOM_ID, id,
9480 GDI_CUSTOM_TYPE_ID, i,
9481 GDI_IMAGE_ID, gfx_unpressed,
9482 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9487 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9488 GDI_STATE, GD_BUTTON_UNPRESSED,
9489 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9490 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9491 GDI_DIRECT_DRAW, FALSE,
9492 GDI_EVENT_MASK, event_mask,
9493 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9497 Fail("cannot create gadget");
9499 screen_gadget[id] = gi;
9503 static void CreateScreenScrollbars(void)
9507 // these values are not constant, but can change at runtime
9508 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9509 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9510 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9511 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9513 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9515 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9516 int gfx_unpressed, gfx_pressed;
9517 int x, y, width, height;
9518 int gd_x1, gd_x2, gd_y1, gd_y2;
9519 struct GadgetInfo *gi;
9520 int items_max, items_visible, item_position;
9521 unsigned int event_mask;
9522 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9523 int id = scrollbar_info[i].gadget_id;
9525 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9527 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9528 y = mSY + scrollbar_info[i].y;
9529 width = scrollbar_info[i].width;
9530 height = scrollbar_info[i].height;
9532 // correct scrollbar position if placed outside menu (playfield) area
9533 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9534 x = SX + SC_SCROLL_VERTICAL_XPOS;
9536 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9537 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9539 items_max = num_page_entries;
9540 items_visible = num_page_entries;
9543 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9544 gfx_pressed = scrollbar_info[i].gfx_pressed;
9545 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9546 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9547 gd_x1 = graphic_info[gfx_unpressed].src_x;
9548 gd_y1 = graphic_info[gfx_unpressed].src_y;
9549 gd_x2 = graphic_info[gfx_pressed].src_x;
9550 gd_y2 = graphic_info[gfx_pressed].src_y;
9552 gi = CreateGadget(GDI_CUSTOM_ID, id,
9553 GDI_CUSTOM_TYPE_ID, i,
9554 GDI_IMAGE_ID, gfx_unpressed,
9555 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9560 GDI_TYPE, scrollbar_info[i].type,
9561 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9562 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9563 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9564 GDI_WHEEL_AREA_X, SX,
9565 GDI_WHEEL_AREA_Y, SY,
9566 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9567 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9568 GDI_STATE, GD_BUTTON_UNPRESSED,
9569 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9570 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9571 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9572 GDI_DIRECT_DRAW, FALSE,
9573 GDI_EVENT_MASK, event_mask,
9574 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9578 Fail("cannot create gadget");
9580 screen_gadget[id] = gi;
9584 static void CreateScreenTextInputGadgets(void)
9588 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9590 int graphic = textinput_info[i].graphic;
9591 struct GraphicInfo *gd = &graphic_info[graphic];
9592 int gd_x1 = gd->src_x;
9593 int gd_y1 = gd->src_y;
9594 int gd_x2 = gd->src_x + gd->active_xoffset;
9595 int gd_y2 = gd->src_y + gd->active_yoffset;
9596 struct GadgetInfo *gi;
9597 unsigned int event_mask;
9598 int id = textinput_info[i].gadget_id;
9599 int x = textinput_info[i].x;
9600 int y = textinput_info[i].y;
9602 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9604 gi = CreateGadget(GDI_CUSTOM_ID, id,
9605 GDI_CUSTOM_TYPE_ID, i,
9606 GDI_INFO_TEXT, textinput_info[i].infotext,
9609 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9610 GDI_TEXT_VALUE, textinput_info[i].value,
9611 GDI_TEXT_SIZE, textinput_info[i].size,
9612 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9613 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9614 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9615 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9616 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9617 GDI_DESIGN_WIDTH, gd->width,
9618 GDI_EVENT_MASK, event_mask,
9619 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9620 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9624 Fail("cannot create gadget");
9626 screen_gadget[id] = gi;
9630 void CreateScreenGadgets(void)
9632 CreateScreenMenubuttons();
9634 CreateScreenScrollbuttons();
9635 CreateScreenScrollbars();
9637 CreateScreenTextInputGadgets();
9640 void FreeScreenGadgets(void)
9644 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9645 FreeGadget(screen_gadget[i]);
9648 static void MapScreenMenuGadgets(int screen_mask)
9652 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9653 if (screen_mask & menubutton_info[i].screen_mask)
9654 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9657 static void UnmapScreenMenuGadgets(int screen_mask)
9661 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9663 if (screen_mask & menubutton_info[i].screen_mask)
9665 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9667 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9668 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9669 screen_gadget[menubutton_info[i].gadget_id]->y,
9670 screen_gadget[menubutton_info[i].gadget_id]->width,
9671 screen_gadget[menubutton_info[i].gadget_id]->height);
9676 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9679 MapScreenMenuGadgets(screen_mask);
9681 UnmapScreenMenuGadgets(screen_mask);
9684 static void MapScreenGadgets(int num_entries)
9688 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9691 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9692 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9694 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9695 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9698 static void MapScreenTreeGadgets(TreeInfo *ti)
9700 MapScreenGadgets(numTreeInfoInGroup(ti));
9703 static void HandleScreenGadgets(struct GadgetInfo *gi)
9705 int id = gi->custom_id;
9706 int button = gi->event.button;
9707 int step = (button == MB_LEFTBUTTON ? 1 :
9708 button == MB_MIDDLEBUTTON ? 5 :
9709 button == MB_RIGHTBUTTON ? 10 : 1);
9713 case SCREEN_CTRL_ID_PREV_LEVEL:
9714 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9717 case SCREEN_CTRL_ID_NEXT_LEVEL:
9718 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9721 case SCREEN_CTRL_ID_FIRST_LEVEL:
9722 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9725 case SCREEN_CTRL_ID_LAST_LEVEL:
9726 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9729 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9730 CloseDoor(DOOR_CLOSE_2);
9731 SetGameStatus(GAME_MODE_LEVELNR);
9732 DrawChooseLevelNr();
9735 case SCREEN_CTRL_ID_PREV_PLAYER:
9736 HandleSetupScreen_Input_Player(step, -1);
9739 case SCREEN_CTRL_ID_NEXT_PLAYER:
9740 HandleSetupScreen_Input_Player(step, +1);
9743 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9744 InsertSolutionTape();
9747 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9751 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9752 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9756 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9757 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9758 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9759 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9760 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9763 case SCREEN_CTRL_ID_SCROLL_UP:
9764 if (game_status == GAME_MODE_NAMES)
9765 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9766 else if (game_status == GAME_MODE_LEVELS)
9767 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9768 else if (game_status == GAME_MODE_LEVELNR)
9769 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9770 else if (game_status == GAME_MODE_SETUP)
9771 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9772 else if (game_status == GAME_MODE_INFO)
9773 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9776 case SCREEN_CTRL_ID_SCROLL_DOWN:
9777 if (game_status == GAME_MODE_NAMES)
9778 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9779 else if (game_status == GAME_MODE_LEVELS)
9780 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9781 else if (game_status == GAME_MODE_LEVELNR)
9782 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9783 else if (game_status == GAME_MODE_SETUP)
9784 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9785 else if (game_status == GAME_MODE_INFO)
9786 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9789 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9790 if (game_status == GAME_MODE_NAMES)
9791 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9792 else if (game_status == GAME_MODE_LEVELS)
9793 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9794 else if (game_status == GAME_MODE_LEVELNR)
9795 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9796 else if (game_status == GAME_MODE_SETUP)
9797 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9798 else if (game_status == GAME_MODE_INFO)
9799 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9802 case SCREEN_CTRL_ID_NETWORK_SERVER:
9804 if (!strEqual(gi->textinput.value, ""))
9806 setString(&setup.network_server_hostname, gi->textinput.value);
9808 network.server_host = setup.network_server_hostname;
9812 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9814 network.server_host = NULL;
9817 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9818 network.server_host = NULL;
9820 execSetupGame_setNetworkServerText();
9832 void DumpScreenIdentifiers(void)
9836 Print("Active screen elements on current screen:\n");
9838 for (i = 0; main_controls[i].nr != -1; i++)
9840 struct MainControlInfo *mci = &main_controls[i];
9842 if (mci->button_graphic != -1)
9844 char *token = getTokenFromImageID(mci->button_graphic);
9846 Print("- '%s'\n", token);
9853 boolean DoScreenAction(int image_id)
9857 if (game_status != GAME_MODE_MAIN)
9860 for (i = 0; main_controls[i].nr != -1; i++)
9862 struct MainControlInfo *mci = &main_controls[i];
9863 struct MenuPosInfo *pos = mci->pos_button;
9865 if (mci->button_graphic == image_id)
9867 int x = mSX + pos->x;
9868 int y = mSY + pos->y;
9870 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9879 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9881 // get tree info node of newly added level or artwork set
9882 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9883 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9885 if (tree_node_new == NULL) // should not happen
9888 // if request dialog is active, do nothing
9889 if (game.request_active)
9892 if (game_status == GAME_MODE_MAIN &&
9893 tree_type == TREE_TYPE_LEVEL_DIR)
9895 // when adding new level set in main menu, select it as current level set
9897 // change current level set to newly added level set from zip file
9898 leveldir_current = tree_node_new;
9900 // change current level number to first level of newly added level set
9901 level_nr = leveldir_current->first_level;
9903 // redraw screen to reflect changed level set
9906 // save this level set and level number as last selected level set
9907 SaveLevelSetup_LastSeries();
9908 SaveLevelSetup_SeriesInfo();
9910 else if (game_status == GAME_MODE_LEVELS &&
9911 tree_type == TREE_TYPE_LEVEL_DIR)
9913 // when adding new level set in level set menu, set cursor and update screen
9915 leveldir_current = tree_node_new;
9917 DrawChooseTree(&leveldir_current);
9919 else if (game_status == GAME_MODE_SETUP)
9921 // when adding new artwork set in setup menu, set cursor and update screen
9923 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9924 tree_type == TREE_TYPE_GRAPHICS_DIR)
9926 artwork.gfx_current = tree_node_new;
9928 DrawChooseTree(&artwork.gfx_current);
9930 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9931 tree_type == TREE_TYPE_SOUNDS_DIR)
9933 artwork.snd_current = tree_node_new;
9935 DrawChooseTree(&artwork.snd_current);
9937 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9938 tree_type == TREE_TYPE_MUSIC_DIR)
9940 artwork.mus_current = tree_node_new;
9942 DrawChooseTree(&artwork.mus_current);
9947 static int UploadTapes(void)
9949 SetGameStatus(GAME_MODE_LOADING);
9951 FadeSetEnterScreen();
9952 FadeOut(REDRAW_ALL);
9954 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
9958 DrawInitTextHead("Uploading tapes");
9960 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
9961 global.autoplay_leveldir = "ALL";
9962 global.autoplay_all = TRUE;
9964 int num_tapes_uploaded = AutoPlayTapes();
9966 global.autoplay_mode = AUTOPLAY_MODE_NONE;
9967 global.autoplay_leveldir = NULL;
9968 global.autoplay_all = FALSE;
9970 SetGameStatus(GAME_MODE_MAIN);
9974 return num_tapes_uploaded;
9977 static boolean OfferUploadTapes(void)
9979 if (!Request("Upload all your tapes to the high score server now?", REQ_ASK))
9982 int num_tapes_uploaded = UploadTapes();
9985 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
9987 Request(message, REQ_CONFIRM);
9989 // after all tapes have been uploaded, remove entry from setup menu
9990 setup.provide_uploading_tapes = FALSE;
9994 return (num_tapes_uploaded > 0);
9997 void CheckUploadTapes(void)
9999 if (!setup.ask_for_uploading_tapes)
10002 if (directoryExists(getTapeDir(NULL)))
10004 boolean tapes_uploaded = OfferUploadTapes();
10006 if (!tapes_uploaded)
10007 Request("You can upload your tapes from the setup menu later!",
10012 // if tapes directory does not exist yet, never offer uploading all tapes
10013 setup.provide_uploading_tapes = FALSE;
10016 // after asking for uploading all tapes once, do not ask again
10017 setup.ask_for_uploading_tapes = FALSE;