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 struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
287 static int info_mode = INFO_MODE_MAIN;
288 static int setup_mode = SETUP_MODE_MAIN;
290 static TreeInfo *window_sizes = NULL;
291 static TreeInfo *window_size_current = NULL;
293 static TreeInfo *scaling_types = NULL;
294 static TreeInfo *scaling_type_current = NULL;
296 static TreeInfo *rendering_modes = NULL;
297 static TreeInfo *rendering_mode_current = NULL;
299 static TreeInfo *vsync_modes = NULL;
300 static TreeInfo *vsync_mode_current = NULL;
302 static TreeInfo *scroll_delays = NULL;
303 static TreeInfo *scroll_delay_current = NULL;
305 static TreeInfo *snapshot_modes = NULL;
306 static TreeInfo *snapshot_mode_current = NULL;
308 static TreeInfo *game_speeds_normal = NULL;
309 static TreeInfo *game_speeds_extended = NULL;
310 static TreeInfo *game_speeds = NULL;
311 static TreeInfo *game_speed_current = NULL;
313 static TreeInfo *volumes_simple = NULL;
314 static TreeInfo *volume_simple_current = NULL;
316 static TreeInfo *volumes_loops = NULL;
317 static TreeInfo *volume_loops_current = NULL;
319 static TreeInfo *volumes_music = NULL;
320 static TreeInfo *volume_music_current = NULL;
322 static TreeInfo *touch_controls = NULL;
323 static TreeInfo *touch_control_current = NULL;
325 static TreeInfo *move_distances = NULL;
326 static TreeInfo *move_distance_current = NULL;
328 static TreeInfo *drop_distances = NULL;
329 static TreeInfo *drop_distance_current = NULL;
331 static TreeInfo *transparencies = NULL;
332 static TreeInfo *transparency_current = NULL;
334 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
335 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
337 static TreeInfo *player_name = NULL;
338 static TreeInfo *player_name_current = NULL;
340 static TreeInfo *level_number = NULL;
341 static TreeInfo *level_number_current = NULL;
343 static struct ValueTextInfo window_sizes_list[] =
348 { 100, "100 % (Default)" },
361 static struct StringValueTextInfo scaling_types_list[] =
363 { SCALING_QUALITY_NEAREST, "Off" },
364 { SCALING_QUALITY_LINEAR, "Linear" },
365 { SCALING_QUALITY_BEST, "Anisotropic" },
370 static struct StringValueTextInfo rendering_modes_list[] =
372 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
373 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
375 // this mode may work under certain conditions, but does not work on Windows
376 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
378 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
383 static struct StringValueTextInfo vsync_modes_list[] =
385 { STR_VSYNC_MODE_OFF, "Off" },
386 { STR_VSYNC_MODE_NORMAL, "Normal" },
387 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
392 static struct ValueTextInfo game_speeds_list_normal[] =
403 static struct ValueTextInfo game_speeds_list_extended[] =
405 { 1000, "1 fps (Extremely Slow)" },
410 { 29, "35 fps (Original Supaplex)" },
412 { 20, "50 fps (=== Normal Speed ===)" },
413 { 16, "60 fps (60 Hz VSync Speed)" },
414 { 14, "70 fps (Maximum Supaplex)" },
418 { 1, "1000 fps (Extremely Fast)" },
423 static struct ValueTextInfo *game_speeds_list;
425 static struct ValueTextInfo scroll_delays_list[] =
427 { 0, "0 Tiles (No Scroll Delay)" },
430 { 3, "3 Tiles (Default)" },
435 { 8, "8 Tiles (Maximum Scroll Delay)"},
440 static struct StringValueTextInfo snapshot_modes_list[] =
442 { STR_SNAPSHOT_MODE_OFF, "Off" },
443 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
444 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
445 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
450 static struct ValueTextInfo volumes_list[] =
470 static struct StringValueTextInfo touch_controls_list[] =
472 { TOUCH_CONTROL_OFF, "Off" },
473 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
474 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
475 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
480 static struct ValueTextInfo distances_list[] =
495 static struct ValueTextInfo transparencies_list[] =
497 { 0, "0 % (Opaque)" },
507 { 100, "100 % (Invisible)" },
512 static struct ValueTextInfo grid_sizes_list[] =
548 static int align_xoffset = 0;
549 static int align_yoffset = 0;
551 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
552 (s) <= GAME_MODE_SETUP ? (s) : \
553 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
555 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
556 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
558 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
559 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
560 (i) <= INFO_MODE_LEVELSET ? (i) : \
563 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
564 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
565 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
566 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
567 SETUP_MODE_CHOOSE_ARTWORK : \
568 SETUP_MODE_CHOOSE_OTHER)
570 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
571 menu.draw_xoffset[GAME_MODE_INFO] : \
572 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
573 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
574 menu.draw_yoffset[GAME_MODE_INFO] : \
575 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
576 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
577 menu.extra_spacing[GAME_MODE_INFO] : \
578 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
580 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
581 menu.draw_xoffset[GAME_MODE_SETUP] : \
582 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
583 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
584 menu.draw_yoffset[GAME_MODE_SETUP] : \
585 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
586 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
587 menu.extra_spacing[GAME_MODE_SETUP] : \
588 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
590 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
591 DRAW_XOFFSET_INFO(info_mode) : \
592 (s) == GAME_MODE_SETUP ? \
593 DRAW_XOFFSET_SETUP(setup_mode) : \
594 menu.draw_xoffset[DRAW_MODE(s)])
595 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
596 DRAW_YOFFSET_INFO(info_mode) : \
597 (s) == GAME_MODE_SETUP ? \
598 DRAW_YOFFSET_SETUP(setup_mode) : \
599 menu.draw_yoffset[DRAW_MODE(s)])
600 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
601 EXTRA_SPACING_INFO(info_mode) : \
602 (s) == GAME_MODE_SETUP ? \
603 EXTRA_SPACING_SETUP(setup_mode) : \
604 menu.extra_spacing[DRAW_MODE(s)])
606 #define mSX (SX + DRAW_XOFFSET(game_status))
607 #define mSY (SY + DRAW_YOFFSET(game_status))
609 #define amSX (mSX + align_xoffset)
610 #define amSY (mSY + align_yoffset)
612 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
613 menu.list_size[game_status] : \
614 MAX_MENU_ENTRIES_ON_SCREEN)
616 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
617 NUM_MENU_ENTRIES_ON_SCREEN)
620 // title display and control definitions
622 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
623 2 * MAX_NUM_TITLE_MESSAGES)
625 #define NO_DIRECT_LEVEL_SELECT (-1)
628 static int num_title_screens = 0;
630 struct TitleControlInfo
639 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
641 // main menu display and control definitions
643 #define MAIN_CONTROL_NAME 0
644 #define MAIN_CONTROL_LEVELS 1
645 #define MAIN_CONTROL_SCORES 2
646 #define MAIN_CONTROL_EDITOR 3
647 #define MAIN_CONTROL_INFO 4
648 #define MAIN_CONTROL_GAME 5
649 #define MAIN_CONTROL_SETUP 6
650 #define MAIN_CONTROL_QUIT 7
651 #define MAIN_CONTROL_PREV_LEVEL 8
652 #define MAIN_CONTROL_NEXT_LEVEL 9
653 #define MAIN_CONTROL_FIRST_LEVEL 10
654 #define MAIN_CONTROL_LAST_LEVEL 11
655 #define MAIN_CONTROL_LEVEL_NUMBER 12
656 #define MAIN_CONTROL_LEVEL_INFO_1 13
657 #define MAIN_CONTROL_LEVEL_INFO_2 14
658 #define MAIN_CONTROL_LEVEL_NAME 15
659 #define MAIN_CONTROL_LEVEL_AUTHOR 16
660 #define MAIN_CONTROL_LEVEL_YEAR 17
661 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
662 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
663 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
664 #define MAIN_CONTROL_TITLE_1 21
665 #define MAIN_CONTROL_TITLE_2 22
666 #define MAIN_CONTROL_TITLE_3 23
668 static char str_main_text_name[10];
669 static char str_main_text_first_level[10];
670 static char str_main_text_last_level[10];
671 static char str_main_text_level_number[10];
673 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
675 static char *main_text_name = str_main_text_name;
676 static char *main_text_first_level = str_main_text_first_level;
677 static char *main_text_last_level = str_main_text_last_level;
678 static char *main_text_level_number = str_main_text_level_number;
679 static char *main_text_levels = "Levelset";
680 static char *main_text_scores = "Hall Of Fame";
681 static char *main_text_editor = "Level Creator";
682 static char *main_text_info = "Info Screen";
683 static char *main_text_game = "Start Game";
684 static char *main_text_setup = "Setup";
685 static char *main_text_quit = "Quit";
686 static char *main_text_level_name = level.name;
687 static char *main_text_level_author = level.author;
688 static char *main_text_level_year = NULL;
689 static char *main_text_level_imported_from = NULL;
690 static char *main_text_level_imported_by = NULL;
691 static char *main_text_level_tested_by = NULL;
692 static char *main_text_title_1 = NULL;
693 static char *main_text_title_2 = NULL;
694 static char *main_text_title_3 = NULL;
696 extern char debug_xsn_mode[];
698 struct MainControlInfo
702 struct MenuPosInfo *pos_button;
705 struct TextPosInfo *pos_text;
708 struct TextPosInfo *pos_input;
712 static struct MainControlInfo main_controls[] =
716 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
717 &menu.main.text.name, &main_text_name,
718 &menu.main.input.name, &setup.player_name,
722 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
723 &menu.main.text.levels, &main_text_levels,
728 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
729 &menu.main.text.scores, &main_text_scores,
734 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
735 &menu.main.text.editor, &main_text_editor,
740 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
741 &menu.main.text.info, &main_text_info,
746 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
747 &menu.main.text.game, &main_text_game,
752 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
753 &menu.main.text.setup, &main_text_setup,
758 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
759 &menu.main.text.quit, &main_text_quit,
763 MAIN_CONTROL_PREV_LEVEL,
769 MAIN_CONTROL_NEXT_LEVEL,
775 MAIN_CONTROL_FIRST_LEVEL,
777 &menu.main.text.first_level, &main_text_first_level,
781 MAIN_CONTROL_LAST_LEVEL,
783 &menu.main.text.last_level, &main_text_last_level,
787 MAIN_CONTROL_LEVEL_NUMBER,
789 &menu.main.text.level_number, &main_text_level_number,
793 MAIN_CONTROL_LEVEL_INFO_1,
795 &menu.main.text.level_info_1, NULL,
799 MAIN_CONTROL_LEVEL_INFO_2,
801 &menu.main.text.level_info_2, NULL,
805 MAIN_CONTROL_LEVEL_NAME,
807 &menu.main.text.level_name, &main_text_level_name,
811 MAIN_CONTROL_LEVEL_AUTHOR,
813 &menu.main.text.level_author, &main_text_level_author,
817 MAIN_CONTROL_LEVEL_YEAR,
819 &menu.main.text.level_year, &main_text_level_year,
823 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
825 &menu.main.text.level_imported_from, &main_text_level_imported_from,
829 MAIN_CONTROL_LEVEL_IMPORTED_BY,
831 &menu.main.text.level_imported_by, &main_text_level_imported_by,
835 MAIN_CONTROL_LEVEL_TESTED_BY,
837 &menu.main.text.level_tested_by, &main_text_level_tested_by,
841 MAIN_CONTROL_TITLE_1,
843 &menu.main.text.title_1, &main_text_title_1,
847 MAIN_CONTROL_TITLE_2,
849 &menu.main.text.title_2, &main_text_title_2,
853 MAIN_CONTROL_TITLE_3,
855 &menu.main.text.title_3, &main_text_title_3,
868 static int getTitleScreenGraphic(int nr, boolean initial)
870 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
873 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
875 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
879 static int getTitleScreenGameMode(boolean initial)
881 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
885 static int getTitleMessageGameMode(boolean initial)
887 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
890 static int getTitleAnimMode(struct TitleControlInfo *tci)
892 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
894 return base + tci->local_nr;
898 static int getTitleScreenBackground(boolean initial)
900 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
905 static int getTitleMessageBackground(int nr, boolean initial)
907 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
911 static int getTitleBackground(int nr, boolean initial, boolean is_image)
913 int base = (is_image ?
914 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
915 IMG_BACKGROUND_TITLESCREEN_1) :
916 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
917 IMG_BACKGROUND_TITLEMESSAGE_1));
918 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
919 IMG_BACKGROUND_TITLE);
920 int graphic_local = base + nr;
922 if (graphic_info[graphic_local].bitmap != NULL)
923 return graphic_local;
925 if (graphic_info[graphic_global].bitmap != NULL)
926 return graphic_global;
928 return IMG_UNDEFINED;
931 static int getTitleSound(struct TitleControlInfo *tci)
933 boolean is_image = tci->is_image;
934 int initial = tci->initial;
935 int nr = tci->local_nr;
936 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
937 int base = (is_image ?
938 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
939 SND_BACKGROUND_TITLESCREEN_1) :
940 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
941 SND_BACKGROUND_TITLEMESSAGE_1));
942 int sound_global = menu.sound[mode];
943 int sound_local = base + nr;
946 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
947 nr, initial, is_image,
948 sound_global, getSoundListEntry(sound_global)->filename,
949 sound_local, getSoundListEntry(sound_local)->filename);
952 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
955 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
958 return SND_UNDEFINED;
961 static int getTitleMusic(struct TitleControlInfo *tci)
963 boolean is_image = tci->is_image;
964 int initial = tci->initial;
965 int nr = tci->local_nr;
966 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
967 int base = (is_image ?
968 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
969 MUS_BACKGROUND_TITLESCREEN_1) :
970 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
971 MUS_BACKGROUND_TITLEMESSAGE_1));
972 int music_global = menu.music[mode];
973 int music_local = base + nr;
976 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
977 nr, initial, is_image,
978 music_global, getMusicListEntry(music_global)->filename,
979 music_local, getMusicListEntry(music_local)->filename);
982 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
985 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
988 return MUS_UNDEFINED;
991 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
993 boolean is_image = tci->is_image;
994 boolean initial = tci->initial;
995 boolean first = tci->first;
996 int nr = tci->local_nr;
997 struct TitleMessageInfo tmi;
998 struct TitleFadingInfo ti;
1000 tmi = (is_image ? (initial ? (first ?
1001 titlescreen_initial_first[nr] :
1002 titlescreen_initial[nr])
1004 titlescreen_first[nr] :
1006 : (initial ? (first ?
1007 titlemessage_initial_first[nr] :
1008 titlemessage_initial[nr])
1010 titlemessage_first[nr] :
1011 titlemessage[nr])));
1013 ti.fade_mode = tmi.fade_mode;
1014 ti.fade_delay = tmi.fade_delay;
1015 ti.post_delay = tmi.post_delay;
1016 ti.auto_delay = tmi.auto_delay;
1017 ti.auto_delay_unit = tmi.auto_delay_unit;
1022 static int compareTitleControlInfo(const void *object1, const void *object2)
1024 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1025 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1028 if (tci1->initial != tci2->initial)
1029 compare_result = (tci1->initial ? -1 : +1);
1030 else if (tci1->sort_priority != tci2->sort_priority)
1031 compare_result = tci1->sort_priority - tci2->sort_priority;
1032 else if (tci1->is_image != tci2->is_image)
1033 compare_result = (tci1->is_image ? -1 : +1);
1035 compare_result = tci1->local_nr - tci2->local_nr;
1037 return compare_result;
1040 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1042 int nr, int sort_priority)
1044 title_controls[num_title_screens].is_image = is_image;
1045 title_controls[num_title_screens].initial = initial;
1046 title_controls[num_title_screens].local_nr = nr;
1047 title_controls[num_title_screens].sort_priority = sort_priority;
1049 title_controls[num_title_screens].first = FALSE; // will be set later
1051 num_title_screens++;
1054 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1058 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1060 int graphic = getTitleScreenGraphic(i, initial);
1061 Bitmap *bitmap = graphic_info[graphic].bitmap;
1062 int sort_priority = graphic_info[graphic].sort_priority;
1065 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1068 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1070 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1071 char *filename = getLevelSetTitleMessageFilename(i, initial);
1072 int sort_priority = tmi->sort_priority;
1074 if (filename != NULL)
1075 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1079 static void InitializeTitleControls(boolean show_title_initial)
1081 num_title_screens = 0;
1083 // 1st step: initialize title screens for game start (only when starting)
1084 if (show_title_initial)
1085 InitializeTitleControls_CheckTitleInfo(TRUE);
1087 // 2nd step: initialize title screens for current level set
1088 InitializeTitleControls_CheckTitleInfo(FALSE);
1090 // sort title screens according to sort_priority and title number
1091 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1092 compareTitleControlInfo);
1094 // mark first title screen
1095 title_controls[0].first = TRUE;
1098 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1100 return (pos != NULL && pos->x != -1 && pos->y != -1);
1103 static boolean visibleTextPos(struct TextPosInfo *pos)
1105 return (pos != NULL && pos->x != -1 && pos->y != -1);
1108 static void InitializeMainControls(void)
1110 boolean local_team_mode = (!network.enabled && setup.team_mode);
1113 // set main control text values to dynamically determined values
1114 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1116 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1117 menu.main.text.first_level.size));
1118 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1119 menu.main.text.last_level.size));
1120 strcpy(main_text_level_number, int2str(level_nr,
1121 menu.main.text.level_number.size));
1123 main_text_level_year = leveldir_current->year;
1124 main_text_level_imported_from = leveldir_current->imported_from;
1125 main_text_level_imported_by = leveldir_current->imported_by;
1126 main_text_level_tested_by = leveldir_current->tested_by;
1128 main_text_title_1 = getConfigProgramTitleString();
1129 main_text_title_2 = getConfigProgramCopyrightString();
1130 main_text_title_3 = getConfigProgramCompanyString();
1132 // set main control screen positions to dynamically determined values
1133 for (i = 0; main_controls[i].nr != -1; i++)
1135 struct MainControlInfo *mci = &main_controls[i];
1137 struct MenuPosInfo *pos_button = mci->pos_button;
1138 struct TextPosInfo *pos_text = mci->pos_text;
1139 struct TextPosInfo *pos_input = mci->pos_input;
1140 char *text = (mci->text ? *mci->text : NULL);
1141 char *input = (mci->input ? *mci->input : NULL);
1142 int button_graphic = mci->button_graphic;
1143 int font_text = (pos_text ? pos_text->font : -1);
1144 int font_input = (pos_input ? pos_input->font : -1);
1146 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1147 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1148 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1149 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1150 int text_chars = (text != NULL ? strlen(text) : 0);
1151 int input_chars = (input != NULL ? strlen(input) : 0);
1154 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1156 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1157 int text_width = font_text_width * text_chars;
1158 int text_height = font_text_height;
1159 int input_width = font_input_width * input_chars;
1160 int input_height = font_input_height;
1162 if (nr == MAIN_CONTROL_NAME)
1164 menu.main.input.name.width = input_width;
1165 menu.main.input.name.height = input_height;
1168 if (pos_button != NULL) // (x/y may be -1/-1 here)
1170 pos_button->width = button_width;
1171 pos_button->height = button_height;
1174 if (pos_text != NULL) // (x/y may be -1/-1 here)
1176 // calculate text size -- needed for text alignment
1177 boolean calculate_text_size = (text != NULL);
1179 if (pos_text->width == -1 || calculate_text_size)
1180 pos_text->width = text_width;
1181 if (pos_text->height == -1 || calculate_text_size)
1182 pos_text->height = text_height;
1184 if (visibleMenuPos(pos_button))
1186 if (pos_text->x == -1)
1187 pos_text->x = pos_button->x + pos_button->width;
1188 if (pos_text->y == -1)
1190 pos_button->y + (pos_button->height - pos_text->height) / 2;
1194 if (pos_input != NULL) // (x/y may be -1/-1 here)
1196 if (visibleTextPos(pos_text))
1198 if (pos_input->x == -1)
1199 pos_input->x = pos_text->x + pos_text->width;
1200 if (pos_input->y == -1)
1201 pos_input->y = pos_text->y;
1204 if (pos_input->width == -1)
1205 pos_input->width = input_width;
1206 if (pos_input->height == -1)
1207 pos_input->height = input_height;
1212 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1213 int graphic, boolean pressed)
1215 struct GraphicInfo *g = &graphic_info[graphic];
1218 int xoffset = (pressed ? g->pressed_xoffset : 0);
1219 int yoffset = (pressed ? g->pressed_yoffset : 0);
1221 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1223 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1224 g->width, g->height, dst_x, dst_y);
1227 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1228 boolean active_input,
1229 boolean pressed_button)
1233 for (i = 0; main_controls[i].nr != -1; i++)
1235 struct MainControlInfo *mci = &main_controls[i];
1237 if (mci->nr == nr || nr == -1)
1239 struct MenuPosInfo *pos_button = mci->pos_button;
1240 struct TextPosInfo *pos_text = mci->pos_text;
1241 struct TextPosInfo *pos_input = mci->pos_input;
1242 char *text = (mci->text ? *mci->text : NULL);
1243 char *input = (mci->input ? *mci->input : NULL);
1244 int button_graphic = mci->button_graphic;
1245 int font_text = (pos_text ? pos_text->font : -1);
1246 int font_input = (pos_input ? pos_input->font : -1);
1250 button_graphic = BUTTON_ACTIVE(button_graphic);
1251 font_text = FONT_ACTIVE(font_text);
1256 font_input = FONT_ACTIVE(font_input);
1259 if (visibleMenuPos(pos_button))
1261 struct MenuPosInfo *pos = pos_button;
1262 int x = mSX + pos->x;
1263 int y = mSY + pos->y;
1265 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1266 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1269 if (visibleTextPos(pos_text) && text != NULL)
1271 struct TextPosInfo *pos = pos_text;
1272 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1273 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1276 // (check why/if this is needed)
1277 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1279 DrawText(x, y, text, font_text);
1282 if (visibleTextPos(pos_input) && input != NULL)
1284 struct TextPosInfo *pos = pos_input;
1285 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1286 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1289 // (check why/if this is needed)
1290 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1292 DrawText(x, y, input, font_input);
1298 static void DrawCursorAndText_Main(int nr, boolean active_text,
1299 boolean pressed_button)
1301 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1305 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1306 boolean pressed_button)
1308 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1312 static struct MainControlInfo *getMainControlInfo(int nr)
1316 for (i = 0; main_controls[i].nr != -1; i++)
1317 if (main_controls[i].nr == nr)
1318 return &main_controls[i];
1323 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1328 int rect_x = ALIGNED_TEXT_XPOS(rect);
1329 int rect_y = ALIGNED_TEXT_YPOS(rect);
1331 return (x >= rect_x && x < rect_x + rect->width &&
1332 y >= rect_y && y < rect_y + rect->height);
1335 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1340 int rect_x = ALIGNED_TEXT_XPOS(rect);
1341 int rect_y = ALIGNED_TEXT_YPOS(rect);
1344 Debug("screens:insideTextPosRect",
1345 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1346 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1347 (x >= rect_x && x < rect_x + rect->width &&
1348 y >= rect_y && y < rect_y + rect->height));
1351 return (x >= rect_x && x < rect_x + rect->width &&
1352 y >= rect_y && y < rect_y + rect->height);
1355 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1357 int rect_width = preview->xsize * preview->tile_size;
1358 int rect_height = preview->ysize * preview->tile_size;
1359 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1360 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1362 return (x >= rect_x && x < rect_x + rect_width &&
1363 y >= rect_y && y < rect_y + rect_height);
1366 static void AdjustScrollbar(int id, int items_max, int items_visible,
1369 struct GadgetInfo *gi = screen_gadget[id];
1371 if (item_position > items_max - items_visible)
1372 item_position = items_max - items_visible;
1374 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1375 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1376 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1379 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1381 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1385 static void clearMenuListArea(void)
1387 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1389 // correct scrollbar position if placed outside menu (playfield) area
1390 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1391 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1393 // clear menu list area, but not title or scrollbar
1394 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1395 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1398 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1400 static int cursor_array[MAX_LEV_FIELDY];
1401 int x = amSX + TILEX * xpos;
1402 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1407 cursor_array[ypos] = graphic;
1409 graphic = cursor_array[ypos];
1413 graphic = BUTTON_ACTIVE(graphic);
1415 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1416 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1419 static void initCursor(int ypos, int graphic)
1421 drawCursorExt(0, ypos, FALSE, graphic);
1424 static void drawCursor(int ypos, boolean active)
1426 drawCursorExt(0, ypos, active, -1);
1429 static void drawCursorXY(int xpos, int ypos, int graphic)
1431 drawCursorExt(xpos, ypos, FALSE, graphic);
1434 static void drawChooseTreeCursor(int ypos, boolean active)
1436 drawCursorExt(0, ypos, active, -1);
1439 static int getChooseTreeEditFont(boolean active)
1441 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1444 static int getChooseTreeEditXPos(int pos)
1446 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1447 int xoffset = (has_scrollbar ? -1 : 0);
1448 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1449 int sx = amSX + xpos * TILEX;
1450 int font_nr = getChooseTreeEditFont(FALSE);
1451 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1453 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1456 static int getChooseTreeEditYPos(int ypos_raw)
1458 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1459 int sy = amSY + ypos * TILEY;
1464 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1466 int sx = getChooseTreeEditXPos(POS_LEFT);
1467 int sy = getChooseTreeEditYPos(ypos_raw);
1468 int font_nr = getChooseTreeEditFont(active);
1470 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1473 static void DrawHeadline(void)
1475 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1476 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1479 static void DrawTitleScreenImage(int nr, boolean initial)
1481 int graphic = getTitleScreenGraphic(nr, initial);
1482 Bitmap *bitmap = graphic_info[graphic].bitmap;
1483 int width = graphic_info[graphic].width;
1484 int height = graphic_info[graphic].height;
1485 int src_x = graphic_info[graphic].src_x;
1486 int src_y = graphic_info[graphic].src_y;
1492 if (width > WIN_XSIZE)
1494 // image width too large for window => center image horizontally
1495 src_x = (width - WIN_XSIZE) / 2;
1499 if (height > WIN_YSIZE)
1501 // image height too large for window => center image vertically
1502 src_y = (height - WIN_YSIZE) / 2;
1506 // always display title screens centered
1507 dst_x = (WIN_XSIZE - width) / 2;
1508 dst_y = (WIN_YSIZE - height) / 2;
1510 SetDrawBackgroundMask(REDRAW_ALL);
1511 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1513 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1515 if (DrawingOnBackground(dst_x, dst_y))
1516 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1518 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1520 redraw_mask = REDRAW_ALL;
1523 static void DrawTitleScreenMessage(int nr, boolean initial)
1525 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1526 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1528 if (filename == NULL)
1531 // force TITLE font on title message screen
1532 SetFontStatus(getTitleMessageGameMode(initial));
1534 // if chars *and* width set to "-1", automatically determine width
1535 if (tmi->chars == -1 && tmi->width == -1)
1536 tmi->width = viewport.window[game_status].width;
1538 // if lines *and* height set to "-1", automatically determine height
1539 if (tmi->lines == -1 && tmi->height == -1)
1540 tmi->height = viewport.window[game_status].height;
1542 // if chars set to "-1", automatically determine by text and font width
1543 if (tmi->chars == -1)
1544 tmi->chars = tmi->width / getFontWidth(tmi->font);
1546 tmi->width = tmi->chars * getFontWidth(tmi->font);
1548 // if lines set to "-1", automatically determine by text and font height
1549 if (tmi->lines == -1)
1550 tmi->lines = tmi->height / getFontHeight(tmi->font);
1552 tmi->height = tmi->lines * getFontHeight(tmi->font);
1554 // if x set to "-1", automatically determine by width and alignment
1556 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1558 // if y set to "-1", automatically determine by height and alignment
1560 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1562 SetDrawBackgroundMask(REDRAW_ALL);
1563 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1565 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1567 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1568 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1569 tmi->autowrap, tmi->centered, tmi->parse_comments);
1574 static void DrawTitleScreen(void)
1576 KeyboardAutoRepeatOff();
1578 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1581 static boolean CheckTitleScreen(boolean levelset_has_changed)
1583 static boolean show_title_initial = TRUE;
1584 boolean show_titlescreen = FALSE;
1586 // needed to be able to skip title screen, if no image or message defined
1587 InitializeTitleControls(show_title_initial);
1589 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1590 show_titlescreen = TRUE;
1592 // show initial title images and messages only once at program start
1593 show_title_initial = FALSE;
1595 return (show_titlescreen && num_title_screens > 0);
1598 void DrawMainMenu(void)
1600 static LevelDirTree *leveldir_last_valid = NULL;
1601 boolean levelset_has_changed = FALSE;
1602 int fade_mask = REDRAW_FIELD;
1604 LimitScreenUpdates(FALSE);
1606 FadeSetLeaveScreen();
1608 // do not fade out here -- function may continue and fade on editor screen
1611 FadeMenuSoundsAndMusic();
1613 ExpireSoundLoops(FALSE);
1615 KeyboardAutoRepeatOn();
1617 audio.sound_deactivated = FALSE;
1621 // needed if last screen was the playing screen, invoked from level editor
1622 if (level_editor_test_game)
1624 CloseDoor(DOOR_CLOSE_ALL);
1626 SetGameStatus(GAME_MODE_EDITOR);
1633 // leveldir_current may be invalid (level group, parent link, node copy)
1634 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1636 if (leveldir_current != leveldir_last_valid)
1638 UpdateLastPlayedLevels_TreeInfo();
1640 levelset_has_changed = TRUE;
1643 // store valid level series information
1644 leveldir_last_valid = leveldir_current;
1646 init_last = init; // switch to new busy animation
1648 // needed if last screen (level choice) changed graphics, sounds or music
1649 ReloadCustomArtwork(0);
1651 if (CheckTitleScreen(levelset_has_changed))
1653 SetGameStatus(GAME_MODE_TITLE);
1660 if (redraw_mask & REDRAW_ALL)
1661 fade_mask = REDRAW_ALL;
1664 fade_mask = REDRAW_ALL;
1668 // needed if different viewport properties defined for menues
1669 ChangeViewportPropertiesIfNeeded();
1671 SetDrawtoField(DRAW_TO_BACKBUFFER);
1673 // level_nr may have been set to value over handicap with level editor
1674 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1675 level_nr = leveldir_current->handicap_level;
1677 LoadLevel(level_nr);
1678 LoadScore(level_nr);
1680 SaveLevelSetup_SeriesInfo();
1682 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1683 SetDrawDeactivationMask(REDRAW_NONE);
1684 SetDrawBackgroundMask(REDRAW_FIELD);
1686 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1689 if (fade_mask == REDRAW_ALL)
1690 RedrawGlobalBorder();
1695 InitializeMainControls();
1697 DrawCursorAndText_Main(-1, FALSE, FALSE);
1698 DrawPreviewLevelInitial();
1699 DrawNetworkPlayers();
1701 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1704 if (TAPE_IS_EMPTY(tape))
1706 DrawCompleteVideoDisplay();
1708 PlayMenuSoundsAndMusic();
1710 // create gadgets for main menu screen
1711 FreeScreenGadgets();
1712 CreateScreenGadgets();
1714 // may be required if audio buttons shown on tape and changed in setup menu
1716 CreateGameButtons();
1718 // map gadgets for main menu screen
1720 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1721 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1723 // copy actual game door content to door double buffer for OpenDoor()
1724 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1725 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1727 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1729 DrawMaskedBorder(fade_mask);
1734 // update screen area with special editor door
1735 redraw_mask |= REDRAW_ALL;
1738 SetMouseCursor(CURSOR_DEFAULT);
1740 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1742 SyncEmscriptenFilesystem();
1745 static void gotoTopLevelDir(void)
1747 // move upwards until inside (but not above) top level directory
1748 while (leveldir_current->node_parent &&
1749 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1751 // write a "path" into level tree for easy navigation to last level
1752 if (leveldir_current->node_parent->node_group->cl_first == -1)
1754 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1755 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1756 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1757 int cl_first, cl_cursor;
1759 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1760 cl_cursor = leveldir_pos - cl_first;
1762 leveldir_current->node_parent->node_group->cl_first = cl_first;
1763 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1766 leveldir_current = leveldir_current->node_parent;
1770 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1772 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1774 return (use_frame_counter ? video.frame_counter : Counter());
1777 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1778 struct TitleFadingInfo *fi)
1780 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1783 static void ResetTitleAutoDelay(unsigned int *counter_var,
1784 struct TitleFadingInfo *fi)
1786 *counter_var = getAutoDelayCounter(fi);
1789 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1791 static unsigned int title_delay = 0;
1792 static int title_screen_nr = 0;
1793 static int last_sound = -1, last_music = -1;
1794 boolean return_to_main_menu = FALSE;
1795 struct TitleControlInfo *tci;
1798 if (button == MB_MENU_INITIALIZE)
1801 title_screen_nr = 0;
1802 tci = &title_controls[title_screen_nr];
1804 SetAnimStatus(getTitleAnimMode(tci));
1806 last_sound = SND_UNDEFINED;
1807 last_music = MUS_UNDEFINED;
1809 if (num_title_screens != 0)
1811 FadeSetEnterScreen();
1813 // use individual title fading instead of global "enter screen" fading
1814 fading = getTitleFading(tci);
1817 if (game_status_last_screen == GAME_MODE_INFO)
1819 if (num_title_screens == 0)
1821 // switch game mode from title screen mode back to info screen mode
1822 SetGameStatus(GAME_MODE_INFO);
1824 // store that last screen was info screen, not main menu screen
1825 game_status_last_screen = GAME_MODE_INFO;
1827 DrawInfoScreen_NotAvailable("Title screen information:",
1828 "No title screen for this level set.");
1833 FadeMenuSoundsAndMusic();
1835 FadeOut(REDRAW_ALL);
1837 // title screens may have different window size
1838 ChangeViewportPropertiesIfNeeded();
1840 // only required to update logic for redrawing global border
1844 DrawTitleScreenImage(tci->local_nr, tci->initial);
1846 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1848 sound = getTitleSound(tci);
1849 music = getTitleMusic(tci);
1851 if (sound != last_sound)
1852 PlayMenuSoundExt(sound);
1853 if (music != last_music)
1854 PlayMenuMusicExt(music);
1859 SetMouseCursor(CURSOR_NONE);
1863 ResetTitleAutoDelay(&title_delay, &fading);
1868 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1869 button = MB_MENU_CHOICE;
1871 if (button == MB_MENU_LEAVE)
1873 return_to_main_menu = TRUE;
1875 else if (button == MB_MENU_CHOICE)
1877 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1879 SetGameStatus(GAME_MODE_INFO);
1881 info_mode = INFO_MODE_MAIN;
1890 if (title_screen_nr < num_title_screens)
1892 tci = &title_controls[title_screen_nr];
1894 SetAnimStatus(getTitleAnimMode(tci));
1896 sound = getTitleSound(tci);
1897 music = getTitleMusic(tci);
1899 if (last_sound != SND_UNDEFINED && sound != last_sound)
1900 FadeSound(last_sound);
1901 if (last_music != MUS_UNDEFINED && music != last_music)
1904 fading = getTitleFading(tci);
1906 FadeOut(REDRAW_ALL);
1909 DrawTitleScreenImage(tci->local_nr, tci->initial);
1911 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1913 sound = getTitleSound(tci);
1914 music = getTitleMusic(tci);
1916 if (sound != last_sound)
1917 PlayMenuSoundExt(sound);
1918 if (music != last_music)
1919 PlayMenuMusicExt(music);
1926 ResetTitleAutoDelay(&title_delay, &fading);
1930 FadeMenuSoundsAndMusic();
1932 return_to_main_menu = TRUE;
1936 if (return_to_main_menu)
1938 SetMouseCursor(CURSOR_DEFAULT);
1940 // force full menu screen redraw after displaying title screens
1941 redraw_mask = REDRAW_ALL;
1943 if (game_status_last_screen == GAME_MODE_INFO)
1945 SetGameStatus(GAME_MODE_INFO);
1947 info_mode = INFO_MODE_MAIN;
1951 else // default: return to main menu
1953 SetGameStatus(GAME_MODE_MAIN);
1960 static void HandleMainMenu_ToggleTeamMode(void)
1962 setup.team_mode = !setup.team_mode;
1964 InitializeMainControls();
1965 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
1967 DrawPreviewPlayers();
1970 static void HandleMainMenu_SelectLevel(int step, int direction,
1971 int selected_level_nr)
1973 int old_level_nr = level_nr;
1976 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1977 new_level_nr = selected_level_nr;
1979 new_level_nr = old_level_nr + step * direction;
1981 if (new_level_nr < leveldir_current->first_level)
1982 new_level_nr = leveldir_current->first_level;
1983 if (new_level_nr > leveldir_current->last_level)
1984 new_level_nr = leveldir_current->last_level;
1986 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1988 // skipping levels is only allowed when trying to skip single level
1989 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1990 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1992 leveldir_current->handicap_level++;
1993 SaveLevelSetup_SeriesInfo();
1996 new_level_nr = leveldir_current->handicap_level;
1999 if (new_level_nr != old_level_nr)
2001 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2003 PlaySound(SND_MENU_ITEM_SELECTING);
2005 level_nr = new_level_nr;
2007 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2008 int2str(level_nr, menu.main.text.level_number.size),
2009 mci->pos_text->font);
2011 LoadLevel(level_nr);
2012 DrawPreviewLevelInitial();
2016 DrawCompleteVideoDisplay();
2018 SaveLevelSetup_SeriesInfo();
2020 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2022 // force redraw of playfield area (may be reset at this point)
2023 redraw_mask |= REDRAW_FIELD;
2027 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2029 static int choice = MAIN_CONTROL_GAME;
2030 static boolean button_pressed_last = FALSE;
2031 boolean button_pressed = FALSE;
2033 int i = 0; // needed to prevent compiler warning due to bad code below
2035 if (button == MB_MENU_INITIALIZE)
2037 DrawCursorAndText_Main(choice, TRUE, FALSE);
2042 if (mx || my) // mouse input
2046 for (i = 0; main_controls[i].nr != -1; i++)
2048 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2049 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2050 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2052 pos = main_controls[i].nr;
2058 // check if level preview was clicked
2059 if (insidePreviewRect(&preview, mx - SX, my - SY))
2060 pos = MAIN_CONTROL_GAME;
2062 // handle pressed/unpressed state for active/inactive menu buttons
2063 // (if pos != -1, "i" contains index position corresponding to "pos")
2065 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2066 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2067 button_pressed = TRUE;
2069 if (button_pressed != button_pressed_last)
2071 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2074 PlaySound(SND_MENU_BUTTON_PRESSING);
2076 PlaySound(SND_MENU_BUTTON_RELEASING);
2079 else if (dx || dy) // keyboard input
2081 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2082 choice == MAIN_CONTROL_SETUP))
2083 button = MB_MENU_CHOICE;
2088 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2090 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2092 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2094 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2096 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2098 CloseDoor(DOOR_CLOSE_2);
2100 SetGameStatus(GAME_MODE_LEVELNR);
2102 DrawChooseLevelNr();
2104 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2110 PlaySound(SND_MENU_ITEM_ACTIVATING);
2112 DrawCursorAndText_Main(choice, FALSE, FALSE);
2113 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2119 if (choice == MAIN_CONTROL_NAME)
2121 // special case: cursor left or right pressed -- toggle team mode
2122 HandleMainMenu_ToggleTeamMode();
2124 else if (choice != MAIN_CONTROL_INFO &&
2125 choice != MAIN_CONTROL_SETUP)
2127 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2133 PlaySound(SND_MENU_ITEM_SELECTING);
2135 if (pos == MAIN_CONTROL_NAME)
2138 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2140 // special case: menu text "name/team" clicked -- toggle team mode
2141 HandleMainMenu_ToggleTeamMode();
2145 if (setup.multiple_users)
2147 CloseDoor(DOOR_CLOSE_2);
2149 SetGameStatus(GAME_MODE_NAMES);
2151 DrawChoosePlayerName();
2155 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2161 else if (pos == MAIN_CONTROL_LEVELS)
2165 CloseDoor(DOOR_CLOSE_2);
2167 SetGameStatus(GAME_MODE_LEVELS);
2169 SaveLevelSetup_LastSeries();
2170 SaveLevelSetup_SeriesInfo();
2172 // restore level set if chosen from "last played level set" menu
2173 RestoreLastPlayedLevels(&leveldir_current);
2175 if (setup.internal.choose_from_top_leveldir)
2178 DrawChooseLevelSet();
2181 else if (pos == MAIN_CONTROL_SCORES)
2183 CloseDoor(DOOR_CLOSE_2);
2185 SetGameStatus(GAME_MODE_SCORES);
2187 DrawHallOfFame(level_nr);
2189 else if (pos == MAIN_CONTROL_EDITOR)
2191 if (leveldir_current->readonly &&
2192 setup.editor.show_read_only_warning)
2193 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2195 CloseDoor(DOOR_CLOSE_ALL);
2197 SetGameStatus(GAME_MODE_EDITOR);
2199 FadeSetEnterScreen();
2203 else if (pos == MAIN_CONTROL_INFO)
2205 CloseDoor(DOOR_CLOSE_2);
2207 SetGameStatus(GAME_MODE_INFO);
2209 info_mode = INFO_MODE_MAIN;
2213 else if (pos == MAIN_CONTROL_GAME)
2215 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2217 else if (pos == MAIN_CONTROL_SETUP)
2219 CloseDoor(DOOR_CLOSE_2);
2221 SetGameStatus(GAME_MODE_SETUP);
2223 setup_mode = SETUP_MODE_MAIN;
2227 else if (pos == MAIN_CONTROL_QUIT)
2229 SaveLevelSetup_LastSeries();
2230 SaveLevelSetup_SeriesInfo();
2232 if (!setup.ask_on_quit_program ||
2233 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2234 SetGameStatus(GAME_MODE_QUIT);
2239 button_pressed_last = button_pressed;
2243 // ============================================================================
2244 // info screen functions
2245 // ============================================================================
2247 static struct TokenInfo *info_info;
2248 static int num_info_info; // number of info entries shown on screen
2249 static int max_info_info; // total number of info entries in list
2251 static void execInfoTitleScreen(void)
2253 info_mode = INFO_MODE_TITLE;
2258 static void execInfoElements(void)
2260 info_mode = INFO_MODE_ELEMENTS;
2265 static void execInfoMusic(void)
2267 info_mode = INFO_MODE_MUSIC;
2272 static void execInfoCredits(void)
2274 info_mode = INFO_MODE_CREDITS;
2279 static void execInfoProgram(void)
2281 info_mode = INFO_MODE_PROGRAM;
2286 static void execInfoVersion(void)
2288 info_mode = INFO_MODE_VERSION;
2293 static void execInfoLevelSet(void)
2295 info_mode = INFO_MODE_LEVELSET;
2300 static void execExitInfo(void)
2302 SetGameStatus(GAME_MODE_MAIN);
2307 static struct TokenInfo info_info_main[] =
2309 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2310 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2311 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2312 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2313 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2314 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2315 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2316 { TYPE_EMPTY, NULL, "" },
2317 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2322 static int getMenuTextFont(int type)
2324 if (type & (TYPE_SWITCH |
2338 static struct TokenInfo *setup_info;
2339 static struct TokenInfo setup_info_input[];
2341 static struct TokenInfo *menu_info;
2343 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2344 int screen_pos, int menu_info_pos_raw,
2347 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2348 struct TokenInfo *ti = &token_info[pos];
2349 int xpos = MENU_SCREEN_START_XPOS;
2350 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2351 int font_nr = getMenuTextFont(ti->type);
2353 if (setup_mode == SETUP_MODE_INPUT)
2354 font_nr = FONT_MENU_1;
2357 font_nr = FONT_ACTIVE(font_nr);
2359 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2361 if (ti->type & ~TYPE_SKIP_ENTRY)
2362 drawCursor(screen_pos, active);
2365 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2368 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2371 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2374 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2377 static char *window_size_text;
2378 static char *scaling_type_text;
2379 static char *network_server_text;
2381 static void drawSetupValue(int, int);
2383 static void drawMenuInfoList(int first_entry, int num_page_entries,
2384 int max_page_entries)
2388 if (first_entry + num_page_entries > max_page_entries)
2391 clearMenuListArea();
2393 for (i = 0; i < num_page_entries; i++)
2395 int menu_info_pos = first_entry + i;
2396 struct TokenInfo *si = &menu_info[menu_info_pos];
2397 void *value_ptr = si->value;
2399 // set some entries to "unchangeable" according to other variables
2400 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2401 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2402 (value_ptr == &setup.sound_music && !audio.music_available) ||
2403 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2404 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2405 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2406 si->type |= TYPE_GHOSTED;
2408 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2409 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2410 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2411 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2412 else if (si->type & ~TYPE_SKIP_ENTRY)
2413 initCursor(i, IMG_MENU_BUTTON);
2415 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2417 if (si->type & TYPE_STRING)
2421 if (value_ptr == &network_server_text)
2422 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2424 if (gadget_id != -1)
2426 struct GadgetInfo *gi = screen_gadget[gadget_id];
2427 int xpos = MENU_SCREEN_START_XPOS;
2428 int ypos = MENU_SCREEN_START_YPOS + i;
2429 int x = mSX + xpos * 32;
2430 int y = mSY + ypos * 32;
2432 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2436 if (si->type & TYPE_VALUE &&
2437 menu_info == setup_info)
2438 drawSetupValue(i, menu_info_pos);
2442 static void DrawInfoScreen_Main(void)
2444 int fade_mask = REDRAW_FIELD;
2447 if (redraw_mask & REDRAW_ALL)
2448 fade_mask = REDRAW_ALL;
2451 fade_mask = REDRAW_ALL;
2454 FadeMenuSoundsAndMusic();
2456 FreeScreenGadgets();
2457 CreateScreenGadgets();
2459 // (needed after displaying title screens which disable auto repeat)
2460 KeyboardAutoRepeatOn();
2462 FadeSetLeaveScreen();
2466 // needed if different viewport properties defined for info screen
2467 ChangeViewportPropertiesIfNeeded();
2469 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2473 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2475 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2477 info_info = info_info_main;
2479 // determine maximal number of info entries that can be displayed on screen
2481 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2484 // determine maximal number of info entries available for menu of info screen
2486 for (i = 0; info_info[i].type != 0; i++)
2489 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2491 MapScreenGadgets(max_info_info);
2493 PlayMenuSoundsAndMusic();
2495 DrawMaskedBorder(fade_mask);
2500 static void changeSetupValue(int, int, int);
2502 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2503 int mode, int num_page_entries,
2504 int max_page_entries)
2506 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2507 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2508 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2509 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2510 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2511 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2512 int *num_page_entries_last = num_page_entries_all_last[game_status];
2513 int *choice_store = choice_stores[game_status];
2514 int *first_entry_store = first_entry_stores[game_status];
2515 int choice = choice_store[mode]; // starts with 0
2516 int first_entry = first_entry_store[mode]; // starts with 0
2518 int y = choice - first_entry;
2520 boolean position_set_by_scrollbar = (dx == 999);
2521 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2524 if (button == MB_MENU_INITIALIZE)
2526 // check if number of menu page entries has changed (may happen by change
2527 // of custom artwork definition value for 'list_size' for this menu screen)
2528 // (in this case, the last menu position most probably has to be corrected)
2529 if (num_page_entries != num_page_entries_last[mode])
2531 choice_store[mode] = first_entry_store[mode] = 0;
2533 choice = first_entry = 0;
2536 num_page_entries_last[mode] = num_page_entries;
2539 // advance to first valid menu entry
2540 while (choice < num_page_entries &&
2541 menu_info[choice].type & TYPE_SKIP_ENTRY)
2544 if (position_set_by_scrollbar)
2545 first_entry = first_entry_store[mode] = dy;
2547 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2548 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2550 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2552 if (choice < first_entry)
2554 choice = first_entry;
2556 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2559 else if (choice > first_entry + num_page_entries - 1)
2561 choice = first_entry + num_page_entries - 1;
2563 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2567 choice_store[mode] = choice;
2569 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2573 else if (button == MB_MENU_LEAVE)
2575 PlaySound(SND_MENU_ITEM_SELECTING);
2577 for (i = 0; i < max_page_entries; i++)
2579 if (menu_info[i].type & TYPE_LEAVE_MENU)
2581 void (*menu_callback_function)(void) = menu_info[i].value;
2585 menu_callback_function();
2587 break; // absolutely needed because function changes 'menu_info'!
2594 if (mx || my) // mouse input
2596 x = (mx - mSX) / 32;
2597 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2599 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2601 // move cursor instead of scrolling when already at start/end of list
2602 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2604 else if (dy == +1 * SCROLL_LINE &&
2605 first_entry + num_page_entries == max_page_entries)
2608 // handle scrolling screen one line or page
2610 y + dy > num_page_entries - 1)
2612 boolean redraw = FALSE;
2614 if (ABS(dy) == SCROLL_PAGE)
2615 step = num_page_entries - 1;
2617 if (dy < 0 && first_entry > 0)
2619 // scroll page/line up
2621 first_entry -= step;
2622 if (first_entry < 0)
2627 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2629 // scroll page/line down
2631 first_entry += step;
2632 if (first_entry + num_page_entries > max_page_entries)
2633 first_entry = MAX(0, max_page_entries - num_page_entries);
2640 choice += first_entry - first_entry_store[mode];
2642 if (choice < first_entry)
2644 choice = first_entry;
2646 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2649 else if (choice > first_entry + num_page_entries - 1)
2651 choice = first_entry + num_page_entries - 1;
2653 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2656 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2660 if (choice < first_entry ||
2661 choice > first_entry + num_page_entries - 1)
2662 first_entry += SIGN(dy);
2665 first_entry_store[mode] = first_entry;
2666 choice_store[mode] = choice;
2668 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2670 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2672 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2673 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2681 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2683 if (menu_info[choice].type & menu_navigation_type ||
2684 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2685 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2686 menu_info[choice].type & TYPE_PLAYER)
2687 button = MB_MENU_CHOICE;
2692 // jump to next non-empty menu entry (up or down)
2693 while (first_entry + y > 0 &&
2694 first_entry + y < max_page_entries - 1 &&
2695 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2698 if (!IN_VIS_MENU(x, y))
2700 choice += y - y_old;
2702 if (choice < first_entry)
2703 first_entry = choice;
2704 else if (choice > first_entry + num_page_entries - 1)
2705 first_entry = choice - num_page_entries + 1;
2707 if (first_entry >= 0 &&
2708 first_entry + num_page_entries <= max_page_entries)
2710 first_entry_store[mode] = first_entry;
2712 if (choice < first_entry)
2713 choice = first_entry;
2714 else if (choice > first_entry + num_page_entries - 1)
2715 choice = first_entry + num_page_entries - 1;
2717 choice_store[mode] = choice;
2719 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2721 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2723 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2724 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2731 if (!anyScrollbarGadgetActive() &&
2732 IN_VIS_MENU(x, y) &&
2733 mx < mx_right_border &&
2734 y >= 0 && y < num_page_entries)
2738 if (first_entry + y != choice &&
2739 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2741 PlaySound(SND_MENU_ITEM_ACTIVATING);
2743 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2744 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2746 choice = choice_store[mode] = first_entry + y;
2750 PlaySound(SND_MENU_ITEM_SELECTING);
2752 for (i = 0; menu_info[i].type != 0; i++)
2754 if (menu_info[i].type & TYPE_LEAVE_MENU)
2756 void (*menu_callback_function)(void) = menu_info[i].value;
2760 menu_callback_function();
2762 // absolutely needed because function changes 'menu_info'!
2770 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2772 PlaySound(SND_MENU_ITEM_SELECTING);
2774 // when selecting key headline, execute function for key value change
2775 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2776 menu_info[first_entry + y + 1].type & TYPE_KEY)
2779 // when selecting string value, execute function for list selection
2780 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2781 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2784 // when selecting string value, execute function for text input gadget
2785 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2786 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2789 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2791 void (*menu_callback_function)(void) =
2792 menu_info[first_entry + y].value;
2794 FadeSetFromType(menu_info[first_entry + y].type);
2796 menu_callback_function();
2798 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2800 void (*gadget_callback_function)(void) =
2801 menu_info[first_entry + y].value;
2803 gadget_callback_function();
2805 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2806 menu_info == setup_info)
2808 changeSetupValue(y, first_entry + y, dx);
2814 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2816 menu_info = info_info;
2818 HandleMenuScreen(mx, my, dx, dy, button,
2819 info_mode, num_info_info, max_info_info);
2822 static int getMenuFontSpacing(int spacing_height, int font_nr)
2824 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2826 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2830 static int getMenuTextSpacing(int spacing_height, int font_nr)
2832 return (getMenuFontSpacing(spacing_height, font_nr) +
2833 EXTRA_SPACING(game_status));
2836 static int getMenuTextStep(int spacing_height, int font_nr)
2838 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2841 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2843 int font_title = MENU_INFO_FONT_TITLE;
2844 int font_error = FONT_TEXT_2;
2845 int font_foot = MENU_INFO_FONT_FOOT;
2846 int spacing_title = menu.headline1_spacing_info[info_mode];
2847 int ystep_title = getMenuTextStep(spacing_title, font_title);
2848 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2849 int ystart2 = ystart1 + ystep_title;
2850 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2852 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2854 FadeOut(REDRAW_FIELD);
2859 DrawTextSCentered(ystart1, font_title, text_title);
2860 DrawTextSCentered(ystart2, font_error, text_error);
2862 DrawTextSCentered(ybottom, font_foot,
2863 "Press any key or button for info menu");
2865 FadeIn(REDRAW_FIELD);
2868 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2870 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2871 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2872 int font_title = MENU_INFO_FONT_TITLE;
2873 int font_foot = MENU_INFO_FONT_FOOT;
2874 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2875 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2876 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2877 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2878 int ystep = MENU_SCREEN_INFO_YSTEP;
2879 int element, action, direction;
2887 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2888 infoscreen_step[i] = infoscreen_frame[i] = 0;
2893 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2895 DrawTextSCentered(ybottom, font_foot,
2896 "Press any key or button for next page");
2902 while (helpanim_info[j].element != HELPANIM_LIST_END)
2904 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2909 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2918 j += infoscreen_step[i - start];
2920 element = helpanim_info[j].element;
2921 action = helpanim_info[j].action;
2922 direction = helpanim_info[j].direction;
2925 element = EL_UNKNOWN;
2927 if (action != -1 && direction != -1)
2928 graphic = el_act_dir2img(element, action, direction);
2929 else if (action != -1)
2930 graphic = el_act2img(element, action);
2931 else if (direction != -1)
2932 graphic = el_dir2img(element, direction);
2934 graphic = el2img(element);
2936 delay = helpanim_info[j++].delay;
2941 if (infoscreen_frame[i - start] == 0)
2944 infoscreen_frame[i - start] = delay - 1;
2948 sync_frame = delay - infoscreen_frame[i - start];
2949 infoscreen_frame[i - start]--;
2952 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2954 if (!infoscreen_frame[i - start])
2955 infoscreen_step[i - start] = 0;
2959 if (!infoscreen_frame[i - start])
2960 infoscreen_step[i - start]++;
2961 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2967 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2969 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2970 graphic, sync_frame, USE_MASKING);
2973 DrawInfoScreen_HelpText(element, action, direction, i - start);
2978 redraw_mask |= REDRAW_FIELD;
2983 static char *getHelpText(int element, int action, int direction)
2985 char token[MAX_LINE_LEN];
2987 strcpy(token, element_info[element].token_name);
2990 strcat(token, element_action_info[action].suffix);
2992 if (direction != -1)
2993 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2995 return getHashEntry(helptext_info, token);
2998 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3000 int font_nr = FONT_INFO_ELEMENTS;
3001 int font_width = getFontWidth(font_nr);
3002 int font_height = getFontHeight(font_nr);
3003 int yoffset = (TILEX - 2 * font_height) / 2;
3004 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3005 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3006 int ystep = TILEY + 4;
3007 int pad_left = xstart - SX;
3008 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3009 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3010 int max_lines_per_text = 2;
3013 if (action != -1 && direction != -1) // element.action.direction
3014 text = getHelpText(element, action, direction);
3016 if (text == NULL && action != -1) // element.action
3017 text = getHelpText(element, action, -1);
3019 if (text == NULL && direction != -1) // element.direction
3020 text = getHelpText(element, -1, direction);
3022 if (text == NULL) // base element
3023 text = getHelpText(element, -1, -1);
3025 if (text == NULL) // not found
3026 text = "No description available";
3028 if (strlen(text) <= max_chars_per_line) // only one line of text
3029 ystart += getFontHeight(font_nr) / 2;
3031 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3032 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3033 TRUE, FALSE, FALSE);
3036 static void DrawInfoScreen_TitleScreen(void)
3038 SetGameStatus(GAME_MODE_TITLE);
3043 void HandleInfoScreen_TitleScreen(int button)
3045 HandleTitleScreen(0, 0, 0, 0, button);
3048 static void DrawInfoScreen_Elements(void)
3050 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3052 FadeOut(REDRAW_FIELD);
3057 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3059 FadeIn(REDRAW_FIELD);
3062 void HandleInfoScreen_Elements(int button)
3064 static unsigned int info_delay = 0;
3065 static int num_anims;
3066 static int num_pages;
3068 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3071 if (button == MB_MENU_INITIALIZE)
3073 boolean new_element = TRUE;
3077 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3079 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3081 else if (new_element)
3084 new_element = FALSE;
3088 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3092 if (button == MB_MENU_LEAVE)
3094 PlaySound(SND_MENU_ITEM_SELECTING);
3096 info_mode = INFO_MODE_MAIN;
3101 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3103 if (button != MB_MENU_INITIALIZE)
3105 PlaySound(SND_MENU_ITEM_SELECTING);
3110 if (page >= num_pages)
3112 FadeMenuSoundsAndMusic();
3114 info_mode = INFO_MODE_MAIN;
3121 FadeSetNextScreen();
3123 if (button != MB_MENU_INITIALIZE)
3124 FadeOut(REDRAW_FIELD);
3126 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3128 if (button != MB_MENU_INITIALIZE)
3129 FadeIn(REDRAW_FIELD);
3133 if (DelayReached(&info_delay, GameFrameDelay))
3134 if (page < num_pages)
3135 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3137 PlayMenuSoundIfLoop();
3141 static void DrawInfoScreen_Music(void)
3143 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3145 FadeOut(REDRAW_FIELD);
3152 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3154 FadeIn(REDRAW_FIELD);
3157 void HandleInfoScreen_Music(int button)
3159 static struct MusicFileInfo *list = NULL;
3160 int font_title = MENU_INFO_FONT_TITLE;
3161 int font_head = MENU_INFO_FONT_HEAD;
3162 int font_text = MENU_INFO_FONT_TEXT;
3163 int font_foot = MENU_INFO_FONT_FOOT;
3164 int spacing_title = menu.headline1_spacing_info[info_mode];
3165 int spacing_head = menu.headline2_spacing_info[info_mode];
3166 int ystep_title = getMenuTextStep(spacing_title, font_title);
3167 int ystep_head = getMenuTextStep(spacing_head, font_head);
3168 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3169 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3171 if (button == MB_MENU_INITIALIZE)
3173 list = music_file_info;
3177 FadeMenuSoundsAndMusic();
3182 DrawTextSCentered(ystart, font_title,
3183 "No music info for this level set.");
3185 DrawTextSCentered(ybottom, font_foot,
3186 "Press any key or button for info menu");
3192 if (button == MB_MENU_LEAVE)
3194 PlaySound(SND_MENU_ITEM_SELECTING);
3196 FadeMenuSoundsAndMusic();
3198 info_mode = INFO_MODE_MAIN;
3203 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3205 if (button != MB_MENU_INITIALIZE)
3207 PlaySound(SND_MENU_ITEM_SELECTING);
3215 FadeMenuSoundsAndMusic();
3217 info_mode = INFO_MODE_MAIN;
3223 FadeMenuSoundsAndMusic();
3225 if (list != music_file_info)
3226 FadeSetNextScreen();
3228 if (button != MB_MENU_INITIALIZE)
3229 FadeOut(REDRAW_FIELD);
3236 int sound = list->music;
3238 if (sound_info[sound].loop)
3239 PlaySoundLoop(sound);
3243 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3247 int music = list->music;
3249 if (music_info[music].loop)
3250 PlayMusicLoop(music);
3254 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3257 ystart += ystep_title;
3259 if (!strEqual(list->title, UNKNOWN_NAME))
3261 if (!strEqual(list->title_header, UNKNOWN_NAME))
3263 DrawTextSCentered(ystart, font_head, list->title_header);
3264 ystart += ystep_head;
3267 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3268 ystart += ystep_head;
3271 if (!strEqual(list->artist, UNKNOWN_NAME))
3273 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3274 DrawTextSCentered(ystart, font_head, list->artist_header);
3276 DrawTextSCentered(ystart, font_head, "by");
3278 ystart += ystep_head;
3280 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3281 ystart += ystep_head;
3284 if (!strEqual(list->album, UNKNOWN_NAME))
3286 if (!strEqual(list->album_header, UNKNOWN_NAME))
3287 DrawTextSCentered(ystart, font_head, list->album_header);
3289 DrawTextSCentered(ystart, font_head, "from the album");
3291 ystart += ystep_head;
3293 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3294 ystart += ystep_head;
3297 if (!strEqual(list->year, UNKNOWN_NAME))
3299 if (!strEqual(list->year_header, UNKNOWN_NAME))
3300 DrawTextSCentered(ystart, font_head, list->year_header);
3302 DrawTextSCentered(ystart, font_head, "from the year");
3304 ystart += ystep_head;
3306 DrawTextFCentered(ystart, font_text, "%s", list->year);
3307 ystart += ystep_head;
3310 DrawTextSCentered(ybottom, FONT_TEXT_4,
3311 "Press any key or button for next page");
3313 if (button != MB_MENU_INITIALIZE)
3314 FadeIn(REDRAW_FIELD);
3317 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3318 PlaySoundLoop(list->music);
3321 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3323 int font_title = MENU_INFO_FONT_TITLE;
3324 int font_head = MENU_INFO_FONT_HEAD;
3325 int font_text = MENU_INFO_FONT_TEXT;
3326 int font_foot = MENU_INFO_FONT_FOOT;
3327 int spacing_title = menu.headline1_spacing_info[info_mode];
3328 int spacing_head = menu.headline2_spacing_info[info_mode];
3329 int spacing_para = menu.paragraph_spacing_info[info_mode];
3330 int spacing_line = menu.line_spacing_info[info_mode];
3331 int ystep_title = getMenuTextStep(spacing_title, font_title);
3332 int ystep_head = getMenuTextStep(spacing_head, font_head);
3333 int ystep_para = getMenuTextStep(spacing_para, font_text);
3334 int ystep_line = getMenuTextStep(spacing_line, font_text);
3335 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3336 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3341 DrawTextSCentered(ystart, font_title, "Credits:");
3342 ystart += ystep_title;
3346 DrawTextSCentered(ystart, font_head,
3347 "Special thanks to");
3348 ystart += ystep_head;
3349 DrawTextSCentered(ystart, font_text,
3351 ystart += ystep_head;
3352 DrawTextSCentered(ystart, font_head,
3354 ystart += ystep_head;
3355 DrawTextSCentered(ystart, font_text,
3356 "\"Boulder Dash\"");
3357 ystart += ystep_head;
3358 DrawTextSCentered(ystart, font_head,
3360 ystart += ystep_head;
3361 DrawTextSCentered(ystart, font_text,
3363 ystart += ystep_head;
3364 DrawTextSCentered(ystart, font_head,
3366 ystart += ystep_head;
3367 DrawTextSCentered(ystart, font_text,
3368 "First Star Software");
3370 else if (screen_nr == 1)
3372 DrawTextSCentered(ystart, font_head,
3373 "Special thanks to");
3374 ystart += ystep_head;
3375 DrawTextSCentered(ystart, font_text,
3376 "Klaus Heinz & Volker Wertich");
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_head,
3380 ystart += ystep_head;
3381 DrawTextSCentered(ystart, font_text,
3382 "\"Emerald Mine\"");
3383 ystart += ystep_head;
3384 DrawTextSCentered(ystart, font_head,
3386 ystart += ystep_head;
3387 DrawTextSCentered(ystart, font_text,
3389 ystart += ystep_head;
3390 DrawTextSCentered(ystart, font_head,
3392 ystart += ystep_head;
3393 DrawTextSCentered(ystart, font_text,
3396 else if (screen_nr == 2)
3398 DrawTextSCentered(ystart, font_head,
3399 "Special thanks to");
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_text,
3402 "Michael Stopp & Philip Jespersen");
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_head,
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_text,
3409 ystart += ystep_head;
3410 DrawTextSCentered(ystart, font_head,
3412 ystart += ystep_head;
3413 DrawTextSCentered(ystart, font_text,
3415 ystart += ystep_head;
3416 DrawTextSCentered(ystart, font_head,
3418 ystart += ystep_head;
3419 DrawTextSCentered(ystart, font_text,
3420 "Digital Integration");
3422 else if (screen_nr == 3)
3424 DrawTextSCentered(ystart, font_head,
3425 "Special thanks to");
3426 ystart += ystep_head;
3427 DrawTextSCentered(ystart, font_text,
3428 "Hiroyuki Imabayashi");
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_head,
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_text,
3435 ystart += ystep_head;
3436 DrawTextSCentered(ystart, font_head,
3438 ystart += ystep_head;
3439 DrawTextSCentered(ystart, font_text,
3441 ystart += ystep_head;
3442 DrawTextSCentered(ystart, font_head,
3444 ystart += ystep_head;
3445 DrawTextSCentered(ystart, font_text,
3448 else if (screen_nr == 4)
3450 DrawTextSCentered(ystart, font_head,
3451 "Special thanks to");
3452 ystart += ystep_head;
3453 DrawTextSCentered(ystart, font_text,
3455 ystart += ystep_head;
3456 DrawTextSCentered(ystart, font_head,
3458 ystart += ystep_head;
3459 DrawTextSCentered(ystart, font_text,
3460 "J\xfcrgen Bonhagen");
3461 ystart += ystep_head;
3462 DrawTextSCentered(ystart, font_head,
3463 "for the continuous creation");
3464 ystart += ystep_line;
3465 DrawTextSCentered(ystart, font_head,
3466 "of outstanding level sets");
3468 else if (screen_nr == 5)
3470 DrawTextSCentered(ystart, font_head,
3472 ystart += ystep_head;
3473 DrawTextSCentered(ystart, font_text,
3475 ystart += ystep_head;
3476 DrawTextSCentered(ystart, font_head,
3477 "for ideas and inspiration by");
3478 ystart += ystep_head;
3479 DrawTextSCentered(ystart, font_text,
3481 ystart += ystep_para;
3483 DrawTextSCentered(ystart, font_head,
3485 ystart += ystep_head;
3486 DrawTextSCentered(ystart, font_text,
3488 ystart += ystep_head;
3489 DrawTextSCentered(ystart, font_head,
3490 "for ideas and inspiration by");
3491 ystart += ystep_head;
3492 DrawTextSCentered(ystart, font_text,
3495 else if (screen_nr == 6)
3497 DrawTextSCentered(ystart, font_head,
3499 ystart += ystep_head;
3500 DrawTextSCentered(ystart, font_text,
3502 ystart += ystep_head;
3503 DrawTextSCentered(ystart, font_head,
3504 "for the code base used for the");
3505 ystart += ystep_line;
3506 DrawTextSCentered(ystart, font_head,
3507 "native Emerald Mine engine");
3509 else if (screen_nr == 7)
3511 DrawTextSCentered(ystart, font_head,
3513 ystart += ystep_head;
3514 DrawTextSCentered(ystart, font_text,
3516 ystart += ystep_head;
3517 DrawTextSCentered(ystart, font_head,
3518 "for the initial DOS port");
3519 ystart += ystep_para;
3521 DrawTextSCentered(ystart, font_head,
3523 ystart += ystep_head;
3524 DrawTextSCentered(ystart, font_text,
3526 ystart += ystep_head;
3527 DrawTextSCentered(ystart, font_head,
3528 "for some additional toons");
3530 else if (screen_nr == 8)
3532 DrawTextSCentered(ystart, font_head,
3533 "And not to forget:");
3534 ystart += ystep_head;
3535 DrawTextSCentered(ystart, font_head,
3537 ystart += ystep_head;
3538 DrawTextSCentered(ystart, font_text,
3539 "All those who contributed");
3540 ystart += ystep_line;
3541 DrawTextSCentered(ystart, font_text,
3542 "levels to this game");
3543 ystart += ystep_line;
3544 DrawTextSCentered(ystart, font_text,
3548 DrawTextSCentered(ybottom, font_foot,
3549 "Press any key or button for next page");
3552 static void DrawInfoScreen_Credits(void)
3554 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3556 FadeMenuSoundsAndMusic();
3558 FadeOut(REDRAW_FIELD);
3560 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3562 FadeIn(REDRAW_FIELD);
3565 void HandleInfoScreen_Credits(int button)
3567 static int screen_nr = 0;
3568 int num_screens = 9;
3570 if (button == MB_MENU_INITIALIZE)
3574 // DrawInfoScreen_CreditsScreen(screen_nr);
3577 if (button == MB_MENU_LEAVE)
3579 PlaySound(SND_MENU_ITEM_SELECTING);
3581 info_mode = INFO_MODE_MAIN;
3586 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3588 if (button != MB_MENU_INITIALIZE)
3590 PlaySound(SND_MENU_ITEM_SELECTING);
3595 if (screen_nr >= num_screens)
3597 FadeMenuSoundsAndMusic();
3599 info_mode = INFO_MODE_MAIN;
3606 FadeSetNextScreen();
3608 if (button != MB_MENU_INITIALIZE)
3609 FadeOut(REDRAW_FIELD);
3611 DrawInfoScreen_CreditsScreen(screen_nr);
3613 if (button != MB_MENU_INITIALIZE)
3614 FadeIn(REDRAW_FIELD);
3618 PlayMenuSoundIfLoop();
3622 static void DrawInfoScreen_Program(void)
3624 int font_title = MENU_INFO_FONT_TITLE;
3625 int font_head = MENU_INFO_FONT_HEAD;
3626 int font_text = MENU_INFO_FONT_TEXT;
3627 int font_foot = MENU_INFO_FONT_FOOT;
3628 int spacing_title = menu.headline1_spacing_info[info_mode];
3629 int spacing_head = menu.headline2_spacing_info[info_mode];
3630 int spacing_para = menu.paragraph_spacing_info[info_mode];
3631 int spacing_line = menu.line_spacing_info[info_mode];
3632 int ystep_title = getMenuTextStep(spacing_title, font_title);
3633 int ystep_head = getMenuTextStep(spacing_head, font_head);
3634 int ystep_para = getMenuTextStep(spacing_para, font_text);
3635 int ystep_line = getMenuTextStep(spacing_line, font_text);
3636 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3637 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3639 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3641 FadeOut(REDRAW_FIELD);
3646 DrawTextSCentered(ystart, font_title, "Program Information:");
3647 ystart += ystep_title;
3649 DrawTextSCentered(ystart, font_head,
3650 "This game is Freeware!");
3651 ystart += ystep_head;
3652 DrawTextSCentered(ystart, font_head,
3653 "If you like it, send e-mail to:");
3654 ystart += ystep_head;
3655 DrawTextSCentered(ystart, font_text,
3656 setup.internal.program_email);
3657 ystart += ystep_para;
3659 DrawTextSCentered(ystart, font_head,
3660 "More information and levels:");
3661 ystart += ystep_head;
3662 DrawTextSCentered(ystart, font_text,
3663 setup.internal.program_website);
3664 ystart += ystep_para;
3666 DrawTextSCentered(ystart, font_head,
3667 "If you have created new levels,");
3668 ystart += ystep_line;
3669 DrawTextSCentered(ystart, font_head,
3670 "send them to me to include them!");
3671 ystart += ystep_head;
3672 DrawTextSCentered(ystart, font_head,
3675 DrawTextSCentered(ybottom, font_foot,
3676 "Press any key or button for info menu");
3678 FadeIn(REDRAW_FIELD);
3681 void HandleInfoScreen_Program(int button)
3683 if (button == MB_MENU_LEAVE)
3685 PlaySound(SND_MENU_ITEM_SELECTING);
3687 info_mode = INFO_MODE_MAIN;
3692 else if (button == MB_MENU_CHOICE)
3694 PlaySound(SND_MENU_ITEM_SELECTING);
3696 FadeMenuSoundsAndMusic();
3698 info_mode = INFO_MODE_MAIN;
3703 PlayMenuSoundIfLoop();
3707 static void DrawInfoScreen_Version(void)
3709 int font_title = MENU_INFO_FONT_TITLE;
3710 int font_head = MENU_INFO_FONT_HEAD;
3711 int font_text = MENU_INFO_FONT_TEXT;
3712 int font_foot = MENU_INFO_FONT_FOOT;
3713 int spacing_title = menu.headline1_spacing_info[info_mode];
3714 int spacing_head = menu.headline2_spacing_info[info_mode];
3715 int spacing_para = menu.paragraph_spacing_info[info_mode];
3716 int spacing_line = menu.line_spacing_info[info_mode];
3717 int xstep = getFontWidth(font_text);
3718 int ystep_title = getMenuTextStep(spacing_title, font_title);
3719 int ystep_head = getMenuTextStep(spacing_head, font_head);
3720 int ystep_para = getMenuTextStep(spacing_para, font_text);
3721 int ystep_line = getMenuTextStep(spacing_line, font_text);
3722 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3723 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3724 int xstart1 = mSX - SX + 2 * xstep;
3725 int xstart2 = mSX - SX + 18 * xstep;
3726 int xstart3 = mSX - SX + 28 * xstep;
3727 SDL_version sdl_version_compiled;
3728 const SDL_version *sdl_version_linked;
3729 int driver_name_len = 10;
3730 SDL_version sdl_version_linked_ext;
3731 const char *driver_name = NULL;
3733 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3735 FadeOut(REDRAW_FIELD);
3740 DrawTextSCentered(ystart, font_title, "Version Information:");
3741 ystart += ystep_title;
3743 DrawTextF(xstart1, ystart, font_head, "Name");
3744 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3745 ystart += ystep_line;
3747 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3749 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3750 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3751 ystart += ystep_line;
3753 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3754 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3755 ystart += ystep_line;
3759 DrawTextF(xstart1, ystart, font_head, "Version");
3760 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3761 ystart += ystep_line;
3764 DrawTextF(xstart1, ystart, font_head, "Platform");
3765 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3767 PLATFORM_XX_BIT_STRING);
3768 ystart += ystep_line;
3770 DrawTextF(xstart1, ystart, font_head, "Target");
3771 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3772 ystart += ystep_line;
3774 DrawTextF(xstart1, ystart, font_head, "Source date");
3775 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3776 ystart += ystep_line;
3778 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3779 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3780 ystart += ystep_para;
3782 DrawTextF(xstart1, ystart, font_head, "Library");
3783 DrawTextF(xstart2, ystart, font_head, "compiled");
3784 DrawTextF(xstart3, ystart, font_head, "linked");
3785 ystart += ystep_head;
3787 SDL_VERSION(&sdl_version_compiled);
3788 SDL_GetVersion(&sdl_version_linked_ext);
3789 sdl_version_linked = &sdl_version_linked_ext;
3791 DrawTextF(xstart1, ystart, font_text, "SDL");
3792 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3793 sdl_version_compiled.major,
3794 sdl_version_compiled.minor,
3795 sdl_version_compiled.patch);
3796 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3797 sdl_version_linked->major,
3798 sdl_version_linked->minor,
3799 sdl_version_linked->patch);
3800 ystart += ystep_line;
3802 SDL_IMAGE_VERSION(&sdl_version_compiled);
3803 sdl_version_linked = IMG_Linked_Version();
3805 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3806 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3807 sdl_version_compiled.major,
3808 sdl_version_compiled.minor,
3809 sdl_version_compiled.patch);
3810 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3811 sdl_version_linked->major,
3812 sdl_version_linked->minor,
3813 sdl_version_linked->patch);
3814 ystart += ystep_line;
3816 SDL_MIXER_VERSION(&sdl_version_compiled);
3817 sdl_version_linked = Mix_Linked_Version();
3819 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3820 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3821 sdl_version_compiled.major,
3822 sdl_version_compiled.minor,
3823 sdl_version_compiled.patch);
3824 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3825 sdl_version_linked->major,
3826 sdl_version_linked->minor,
3827 sdl_version_linked->patch);
3828 ystart += ystep_line;
3830 SDL_NET_VERSION(&sdl_version_compiled);
3831 sdl_version_linked = SDLNet_Linked_Version();
3833 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3834 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3835 sdl_version_compiled.major,
3836 sdl_version_compiled.minor,
3837 sdl_version_compiled.patch);
3838 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3839 sdl_version_linked->major,
3840 sdl_version_linked->minor,
3841 sdl_version_linked->patch);
3842 ystart += ystep_para;
3844 DrawTextF(xstart1, ystart, font_head, "Driver");
3845 DrawTextF(xstart2, ystart, font_head, "Requested");
3846 DrawTextF(xstart3, ystart, font_head, "Used");
3847 ystart += ystep_head;
3850 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3852 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3853 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3854 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3855 ystart += ystep_line;
3858 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3860 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3861 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3862 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3863 ystart += ystep_line;
3866 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3868 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3869 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3870 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3872 DrawTextSCentered(ybottom, font_foot,
3873 "Press any key or button for info menu");
3875 FadeIn(REDRAW_FIELD);
3878 void HandleInfoScreen_Version(int button)
3880 if (button == MB_MENU_LEAVE)
3882 PlaySound(SND_MENU_ITEM_SELECTING);
3884 info_mode = INFO_MODE_MAIN;
3889 else if (button == MB_MENU_CHOICE)
3891 PlaySound(SND_MENU_ITEM_SELECTING);
3893 FadeMenuSoundsAndMusic();
3895 info_mode = INFO_MODE_MAIN;
3900 PlayMenuSoundIfLoop();
3904 static void DrawInfoScreen_LevelSet(void)
3906 struct TitleMessageInfo *tmi = &readme;
3907 char *filename = getLevelSetInfoFilename();
3908 char *title = "Level Set Information:";
3909 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3910 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3912 if (filename == NULL)
3914 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3919 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3921 FadeOut(REDRAW_FIELD);
3926 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3928 // if x position set to "-1", automatically determine by playfield width
3930 tmi->x = SXSIZE / 2;
3932 // if y position set to "-1", use static default value
3936 // if width set to "-1", automatically determine by playfield width
3937 if (tmi->width == -1)
3938 tmi->width = SXSIZE - 2 * TILEX;
3940 // if height set to "-1", automatically determine by playfield height
3941 if (tmi->height == -1)
3942 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3944 // if chars set to "-1", automatically determine by text and font width
3945 if (tmi->chars == -1)
3946 tmi->chars = tmi->width / getFontWidth(tmi->font);
3948 tmi->width = tmi->chars * getFontWidth(tmi->font);
3950 // if lines set to "-1", automatically determine by text and font height
3951 if (tmi->lines == -1)
3952 tmi->lines = tmi->height / getFontHeight(tmi->font);
3954 tmi->height = tmi->lines * getFontHeight(tmi->font);
3956 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3957 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3958 tmi->autowrap, tmi->centered, tmi->parse_comments);
3960 DrawTextSCentered(ybottom, FONT_TEXT_4,
3961 "Press any key or button for info menu");
3963 FadeIn(REDRAW_FIELD);
3966 static void HandleInfoScreen_LevelSet(int button)
3968 if (button == MB_MENU_LEAVE)
3970 PlaySound(SND_MENU_ITEM_SELECTING);
3972 info_mode = INFO_MODE_MAIN;
3977 else if (button == MB_MENU_CHOICE)
3979 PlaySound(SND_MENU_ITEM_SELECTING);
3981 FadeMenuSoundsAndMusic();
3983 info_mode = INFO_MODE_MAIN;
3988 PlayMenuSoundIfLoop();
3992 static void DrawInfoScreen(void)
3994 if (info_mode == INFO_MODE_TITLE)
3995 DrawInfoScreen_TitleScreen();
3996 else if (info_mode == INFO_MODE_ELEMENTS)
3997 DrawInfoScreen_Elements();
3998 else if (info_mode == INFO_MODE_MUSIC)
3999 DrawInfoScreen_Music();
4000 else if (info_mode == INFO_MODE_CREDITS)
4001 DrawInfoScreen_Credits();
4002 else if (info_mode == INFO_MODE_PROGRAM)
4003 DrawInfoScreen_Program();
4004 else if (info_mode == INFO_MODE_VERSION)
4005 DrawInfoScreen_Version();
4006 else if (info_mode == INFO_MODE_LEVELSET)
4007 DrawInfoScreen_LevelSet();
4009 DrawInfoScreen_Main();
4011 if (info_mode != INFO_MODE_MAIN &&
4012 info_mode != INFO_MODE_TITLE &&
4013 info_mode != INFO_MODE_MUSIC)
4014 PlayMenuSoundsAndMusic();
4017 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4019 if (info_mode == INFO_MODE_TITLE)
4020 HandleInfoScreen_TitleScreen(button);
4021 else if (info_mode == INFO_MODE_ELEMENTS)
4022 HandleInfoScreen_Elements(button);
4023 else if (info_mode == INFO_MODE_MUSIC)
4024 HandleInfoScreen_Music(button);
4025 else if (info_mode == INFO_MODE_CREDITS)
4026 HandleInfoScreen_Credits(button);
4027 else if (info_mode == INFO_MODE_PROGRAM)
4028 HandleInfoScreen_Program(button);
4029 else if (info_mode == INFO_MODE_VERSION)
4030 HandleInfoScreen_Version(button);
4031 else if (info_mode == INFO_MODE_LEVELSET)
4032 HandleInfoScreen_LevelSet(button);
4034 HandleInfoScreen_Main(mx, my, dx, dy, button);
4038 // ============================================================================
4039 // change name functions
4040 // ============================================================================
4042 static void RenamePlayerOnServerExt(struct HttpRequest *request,
4043 struct HttpResponse *response,
4044 char *player_name_raw,
4045 char *player_uuid_raw)
4047 request->hostname = setup.api_server_hostname;
4048 request->port = API_SERVER_PORT;
4049 request->method = API_SERVER_METHOD;
4050 request->uri = API_SERVER_URI_RENAME;
4052 char *player_name = getEscapedJSON(player_name_raw);
4053 char *player_uuid = getEscapedJSON(player_uuid_raw);
4055 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4058 " \"game_version\": \"%s\",\n"
4059 " \"name\": \"%s\",\n"
4060 " \"uuid\": \"%s\"\n"
4062 getPasswordJSON(setup.api_server_password),
4063 getProgramRealVersionString(),
4067 checked_free(player_name);
4068 checked_free(player_uuid);
4070 ConvertHttpRequestBodyToServerEncoding(request);
4072 if (!DoHttpRequest(request, response))
4074 Error("HTTP request failed: %s", GetHttpError());
4079 if (!HTTP_SUCCESS(response->status_code))
4081 Error("server failed to handle request: %d %s",
4082 response->status_code,
4083 response->status_text);
4089 static void RenamePlayerOnServer(char *player_name, char *player_uuid)
4091 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4092 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4094 RenamePlayerOnServerExt(request, response, player_name, player_uuid);
4096 checked_free(request);
4097 checked_free(response);
4100 struct RenamePlayerOnServerThreadData
4106 static int RenamePlayerOnServerThread(void *data_raw)
4108 struct RenamePlayerOnServerThreadData *data = data_raw;
4110 RenamePlayerOnServer(data->player_name, data->player_uuid);
4112 checked_free(data->player_name);
4113 checked_free(data->player_uuid);
4119 static void RenamePlayerOnServerAsThread(void)
4121 struct RenamePlayerOnServerThreadData *data =
4122 checked_malloc(sizeof(struct RenamePlayerOnServerThreadData));
4124 data->player_name = getStringCopy(setup.player_name);
4125 data->player_uuid = getStringCopy(setup.player_uuid);
4127 ExecuteAsThread(RenamePlayerOnServerThread,
4128 "RenamePlayerOnServer", data,
4129 "rename player on server");
4133 // ============================================================================
4134 // type name functions
4135 // ============================================================================
4137 static TreeInfo *type_name_node = NULL;
4138 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4139 static int type_name_nr = 0;
4141 static int getPlayerNameColor(char *name)
4143 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4146 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4149 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4150 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4151 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4152 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4153 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4154 int font_width = getFontWidth(font_nr);
4156 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4158 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4160 pos->width = strlen(text) * font_width;
4161 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4163 DrawText(sx, sy, text, font_nr);
4166 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4168 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4170 *pos = *mci->pos_input;
4172 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4174 TreeInfo *ti = player_name_current;
4175 int first_entry = ti->cl_first;
4176 int entry_pos = first_entry + ti->cl_cursor;
4177 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4178 int xpos = MENU_SCREEN_START_XPOS;
4179 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4181 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4182 type_name_nr = entry_pos;
4184 strcpy(name, type_name_node->name);
4188 pos->width = MAX_PLAYER_NAME_LEN * 32;
4192 type_name_nr = user.nr;
4194 strcpy(name, setup.player_name);
4197 strcpy(type_name_last, name);
4199 if (strEqual(name, EMPTY_PLAYER_NAME))
4202 *xpos = strlen(name);
4205 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4207 // change name of edited user in global list of user names
4208 setString(&global.user_names[type_name_nr], name);
4210 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4212 TreeInfo *node = type_name_node;
4214 // change name of edited user in local menu tree structure
4215 setString(&node->name, name);
4216 setString(&node->name_sorting, name);
4218 node->color = getPlayerNameColor(name);
4219 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4223 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4226 boolean reset_setup = strEqual(name, "");
4227 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4228 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4231 strcpy(name, type_name_last);
4233 if (strEqual(name, ""))
4234 strcpy(name, EMPTY_PLAYER_NAME);
4236 setTypeNameValues_Name(name, pos);
4238 // if player name not changed, no further action required
4239 if (strEqual(name, type_name_last))
4242 // redraw player name before (possibly) opening request dialogs
4243 drawTypeNameText(name, pos, FALSE);
4245 int last_user_nr = user.nr;
4247 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4249 // save setup of currently active user (may differ from edited user)
4252 // temporarily change active user to edited user
4253 user.nr = type_name_nr;
4255 // load setup of edited user (unless creating user with current setup)
4257 !Request("Use current setup values for the new player?", REQ_ASK))
4261 char *setup_filename = getSetupFilename();
4262 boolean setup_exists = fileExists(setup_filename);
4264 // change name of edited user in setup structure
4265 strcpy(setup.player_name, name);
4267 // save setup of edited user
4270 // change name of edited user on score server
4271 RenamePlayerOnServerAsThread();
4273 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4277 if (Request("Reset setup values for this player?", REQ_ASK))
4279 // remove setup config file
4280 unlink(setup_filename);
4282 // set player name to default player name
4285 // update player name used by name typing functions
4286 strcpy(name, setup.player_name);
4288 setTypeNameValues_Name(name, pos);
4291 else if (remove_user && type_name_nr != 0)
4293 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4295 char *user_dir = getUserGameDataDir();
4296 char *user_dir_removed =
4297 getStringCat3WithSeparator(user_dir, "REMOVED",
4298 getCurrentTimestamp(), ".");
4300 if (rename(user_dir, user_dir_removed) != 0)
4301 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4303 checked_free(user_dir_removed);
4306 else if (create_user && type_name_nr != 0 && !setup_exists)
4308 if (Request("Create empty level set for the new player?", REQ_ASK))
4310 char *levelset_subdir = getNewUserLevelSubdir();
4312 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4314 AddUserLevelSetToLevelInfo(levelset_subdir);
4316 LevelDirTree *leveldir_current_last = leveldir_current;
4318 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4321 // set level number of newly created level set to default value
4322 LoadLevelSetup_SeriesInfo();
4324 // set newly created level set as current level set for new user
4325 SaveLevelSetup_LastSeries();
4326 SaveLevelSetup_SeriesInfo();
4328 leveldir_current = leveldir_current_last;
4332 Request("Creating new level set failed!", REQ_CONFIRM);
4337 // restore currently active user
4338 user.nr = last_user_nr;
4340 // restore setup of currently active user
4343 // restore last level set of currently active user
4344 LoadLevelSetup_LastSeries();
4345 LoadLevelSetup_SeriesInfo();
4349 static void HandleTypeNameExt(boolean initialize, Key key)
4351 static struct TextPosInfo pos_name = { 0 };
4352 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4353 static int xpos = 0;
4354 struct TextPosInfo *pos = &pos_name;
4355 char key_char = getValidConfigValueChar(getCharFromKey(key));
4356 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4357 boolean active = TRUE;
4361 getTypeNameValues(name, pos, &xpos);
4363 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4364 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4366 StartTextInput(sx, sy, pos->width, pos->height);
4368 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4370 name[xpos] = key_char;
4375 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4381 else if (key == KSYM_Return || key == KSYM_Escape)
4383 boolean changed = (key == KSYM_Return);
4387 setTypeNameValues(name, pos, changed);
4392 drawTypeNameText(name, pos, active);
4396 SetGameStatus(game_status_last_screen);
4398 if (game_status == GAME_MODE_MAIN)
4399 InitializeMainControls();
4403 static void DrawTypeName(void)
4405 HandleTypeNameExt(TRUE, 0);
4408 void HandleTypeName(Key key)
4410 HandleTypeNameExt(FALSE, key);
4414 // ============================================================================
4415 // tree menu functions
4416 // ============================================================================
4418 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4420 if (game_status != GAME_MODE_SETUP ||
4421 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4424 int max_text_size = 0;
4427 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4428 max_text_size = MAX(max_text_size, strlen(node->name));
4430 int num_entries = numTreeInfoInGroup(ti);
4431 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4432 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4433 int text_width = max_text_size * getFontWidth(font_nr);
4434 int button_width = SC_MENUBUTTON_XSIZE;
4435 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4436 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4437 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4438 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4439 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4440 int align_xoffset = MAX(0, align_xoffset_raw);
4442 return align_xoffset;
4445 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4447 if (game_status != GAME_MODE_SETUP ||
4448 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4451 int num_entries = numTreeInfoInGroup(ti);
4452 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4453 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4454 int font_height = getFontHeight(font_nr);
4455 int text_height = font_height * num_page_entries;
4456 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4457 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4458 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4459 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4460 int align_yoffset = MAX(0, align_yoffset_raw);
4462 return align_yoffset;
4465 static void DrawChooseTree(TreeInfo **ti_ptr)
4467 int fade_mask = REDRAW_FIELD;
4470 fade_mask = REDRAW_ALL;
4472 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4474 if (game_status == GAME_MODE_SETUP)
4478 else // GAME_MODE_LEVELS
4480 SetGameStatus(GAME_MODE_MAIN);
4490 FreeScreenGadgets();
4491 CreateScreenGadgets();
4495 // needed if different viewport properties defined for choosing level (set)
4496 ChangeViewportPropertiesIfNeeded();
4498 if (game_status == GAME_MODE_NAMES)
4499 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4500 else if (game_status == GAME_MODE_LEVELNR)
4501 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4502 else if (game_status == GAME_MODE_LEVELS)
4503 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4507 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4509 MapScreenTreeGadgets(*ti_ptr);
4510 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4512 DrawMaskedBorder(fade_mask);
4517 static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
4519 int num_entries = numTreeInfoInGroup(ti);
4520 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4521 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4522 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4523 int first_entry = ti->cl_first;
4524 int entry_pos = first_entry + y;
4525 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4526 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4527 int font_color = MENU_CHOOSE_TREE_COLOR(node, active);
4528 int font_nr = MENU_CHOOSE_TREE_FONT(font_color);
4529 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4530 int xpos = MENU_SCREEN_START_XPOS;
4531 int ypos = MENU_SCREEN_START_YPOS + y;
4532 int startx = amSX + xpos * 32;
4533 int starty = amSY + ypos * 32;
4534 int startx_text = startx + font_xoffset;
4535 int endx_text = amSX + screen_width;
4536 int max_text_size = endx_text - startx_text;
4537 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4538 char buffer[max_buffer_len + 1];
4540 strncpy(buffer, node->name, max_buffer_len);
4541 buffer[max_buffer_len] = '\0';
4543 DrawText(startx, starty, buffer, font_nr);
4546 static void drawChooseTreeList(int first_entry, int num_page_entries,
4550 char *title_string = NULL;
4551 int yoffset_sets = MENU_TITLE1_YPOS;
4552 int yoffset_setup = 16;
4553 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4554 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4556 title_string = ti->infotext;
4558 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4560 clearMenuListArea();
4562 for (i = 0; i < num_page_entries; i++)
4564 TreeInfo *node, *node_first;
4565 int entry_pos = first_entry + i;
4567 node_first = getTreeInfoFirstGroupEntry(ti);
4568 node = getTreeInfoFromPos(node_first, entry_pos);
4570 drawChooseTreeText(i, FALSE, ti);
4572 if (node->parent_link)
4573 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4574 else if (node->level_group)
4575 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4577 initCursor(i, IMG_MENU_BUTTON);
4579 if (game_status == GAME_MODE_NAMES)
4580 drawChooseTreeEdit(i, FALSE);
4583 redraw_mask |= REDRAW_FIELD;
4586 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4588 TreeInfo *node, *node_first;
4589 int x, last_redraw_mask = redraw_mask;
4590 int ypos = MENU_TITLE2_YPOS;
4591 int font_nr = FONT_TITLE_2;
4593 if (ti->type == TREE_TYPE_LEVEL_NR)
4594 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4596 if (ti->type != TREE_TYPE_LEVEL_DIR)
4599 node_first = getTreeInfoFirstGroupEntry(ti);
4600 node = getTreeInfoFromPos(node_first, entry_pos);
4602 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4604 if (node->parent_link)
4605 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4606 node->node_parent->name);
4607 else if (node->level_group)
4608 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4610 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4611 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4612 node->levels, (node->levels > 1 ? "levels" : "level"),
4615 // let BackToFront() redraw only what is needed
4616 redraw_mask = last_redraw_mask;
4617 for (x = 0; x < SCR_FIELDX; x++)
4618 MarkTileDirty(x, 1);
4621 static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
4623 drawChooseTreeCursor(y, active);
4624 drawChooseTreeText(y, active, ti);
4627 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4630 TreeInfo *ti = *ti_ptr;
4631 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4632 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4633 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4634 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4635 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4637 int y = ti->cl_cursor;
4638 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4639 int num_entries = numTreeInfoInGroup(ti);
4640 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4641 boolean position_set_by_scrollbar = (dx == 999);
4643 if (button == MB_MENU_INITIALIZE)
4645 int num_entries = numTreeInfoInGroup(ti);
4646 int entry_pos = getPosFromTreeInfo(ti);
4648 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4649 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4651 if (ti->cl_first == -1)
4653 // only on initialization
4654 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4655 ti->cl_cursor = entry_pos - ti->cl_first;
4657 else if (ti->cl_cursor >= num_page_entries ||
4658 (num_entries > num_page_entries &&
4659 num_entries - ti->cl_first < num_page_entries))
4661 // only after change of list size (by custom graphic configuration)
4662 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4663 ti->cl_cursor = entry_pos - ti->cl_first;
4666 if (position_set_by_scrollbar)
4669 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4672 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4673 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4674 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4678 else if (button == MB_MENU_LEAVE)
4682 PlaySound(SND_MENU_ITEM_SELECTING);
4684 if (ti->node_parent)
4686 *ti_ptr = ti->node_parent;
4687 DrawChooseTree(ti_ptr);
4689 else if (game_status == GAME_MODE_SETUP)
4691 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4692 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4693 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4695 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4696 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4697 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4698 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4699 execSetupGraphics();
4700 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4701 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4702 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4704 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4705 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4706 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4707 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4708 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4709 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4710 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4711 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4718 if (game_status == GAME_MODE_LEVELNR)
4720 int new_level_nr = atoi(level_number_current->identifier);
4722 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4725 SetGameStatus(GAME_MODE_MAIN);
4733 if (mx || my) // mouse input
4735 x = (mx - amSX) / 32;
4736 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4738 if (game_status == GAME_MODE_NAMES)
4739 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4741 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4743 // move cursor instead of scrolling when already at start/end of list
4744 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4746 else if (dy == +1 * SCROLL_LINE &&
4747 ti->cl_first + num_page_entries == num_entries)
4750 // handle scrolling screen one line or page
4751 if (ti->cl_cursor + dy < 0 ||
4752 ti->cl_cursor + dy > num_page_entries - 1)
4754 boolean redraw = FALSE;
4756 if (ABS(dy) == SCROLL_PAGE)
4757 step = num_page_entries - 1;
4759 if (dy < 0 && ti->cl_first > 0)
4761 // scroll page/line up
4763 ti->cl_first -= step;
4764 if (ti->cl_first < 0)
4769 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4771 // scroll page/line down
4773 ti->cl_first += step;
4774 if (ti->cl_first + num_page_entries > num_entries)
4775 ti->cl_first = MAX(0, num_entries - num_page_entries);
4782 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4783 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4784 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4786 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4793 // handle moving cursor one line
4794 y = ti->cl_cursor + dy;
4799 TreeInfo *node_first, *node_cursor;
4800 int entry_pos = ti->cl_first + y;
4802 node_first = getTreeInfoFirstGroupEntry(ti);
4803 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4805 if (node_cursor->node_group)
4809 PlaySound(SND_MENU_ITEM_SELECTING);
4811 node_cursor->cl_first = ti->cl_first;
4812 node_cursor->cl_cursor = ti->cl_cursor;
4813 *ti_ptr = node_cursor->node_group;
4814 DrawChooseTree(ti_ptr);
4819 else if (dx == -1 && ti->node_parent)
4823 PlaySound(SND_MENU_ITEM_SELECTING);
4825 *ti_ptr = ti->node_parent;
4826 DrawChooseTree(ti_ptr);
4831 if (!anyScrollbarGadgetActive() &&
4832 IN_VIS_MENU(x, y) &&
4833 mx < mx_right_border &&
4834 y >= 0 && y < num_page_entries)
4838 if (game_status == GAME_MODE_NAMES)
4840 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4841 drawChooseTreeEdit(y, TRUE);
4844 if (y != ti->cl_cursor)
4846 PlaySound(SND_MENU_ITEM_ACTIVATING);
4848 drawChooseTreeCursorAndText(ti->cl_cursor, FALSE, ti);
4849 drawChooseTreeCursorAndText(y, TRUE, ti);
4850 drawChooseTreeInfo(ti->cl_first + y, ti);
4856 if (game_status == GAME_MODE_SETUP)
4858 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4859 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4860 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4862 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4863 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4864 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4865 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4866 execSetupGraphics();
4867 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4868 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4869 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4871 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4872 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4873 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4874 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4875 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4876 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4877 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4878 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4887 TreeInfo *node_first, *node_cursor;
4888 int entry_pos = ti->cl_first + y;
4890 PlaySound(SND_MENU_ITEM_SELECTING);
4892 node_first = getTreeInfoFirstGroupEntry(ti);
4893 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4895 if (node_cursor->node_group)
4899 node_cursor->cl_first = ti->cl_first;
4900 node_cursor->cl_cursor = ti->cl_cursor;
4901 *ti_ptr = node_cursor->node_group;
4902 DrawChooseTree(ti_ptr);
4904 else if (node_cursor->parent_link)
4908 *ti_ptr = node_cursor->node_parent;
4909 DrawChooseTree(ti_ptr);
4915 node_cursor->cl_first = ti->cl_first;
4916 node_cursor->cl_cursor = ti->cl_cursor;
4917 *ti_ptr = node_cursor;
4919 if (ti->type == TREE_TYPE_LEVEL_DIR)
4921 LoadLevelSetup_SeriesInfo();
4923 SaveLevelSetup_LastSeries();
4924 SaveLevelSetup_SeriesInfo();
4928 if (game_status == GAME_MODE_SETUP)
4930 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4931 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4932 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4934 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4935 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4936 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4937 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4938 execSetupGraphics();
4939 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4940 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4941 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4943 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4944 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4945 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4946 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4947 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4948 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4949 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4950 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4957 if (game_status == GAME_MODE_LEVELNR)
4959 int new_level_nr = atoi(level_number_current->identifier);
4961 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4963 else if (game_status == GAME_MODE_LEVELS)
4965 // store level set if chosen from "last played level set" menu
4966 StoreLastPlayedLevels(leveldir_current);
4968 else if (game_status == GAME_MODE_NAMES)
4970 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4972 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
4979 // change active user to selected user
4980 user.nr = entry_pos;
4982 // save number of new active user
4985 // load setup of new active user
4988 // load last level set of new active user
4989 LoadLevelSetup_LastSeries();
4990 LoadLevelSetup_SeriesInfo();
4992 // update list of last played level sets
4993 UpdateLastPlayedLevels_TreeInfo();
4997 ToggleFullscreenIfNeeded();
4998 ChangeWindowScalingIfNeeded();
5000 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5001 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5002 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5005 SetGameStatus(GAME_MODE_MAIN);
5014 void DrawChoosePlayerName(void)
5018 FadeMenuSoundsAndMusic();
5020 if (player_name != NULL)
5022 freeTreeInfo(player_name);
5027 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5029 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5030 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5033 ti->node_top = &player_name;
5034 ti->sort_priority = 10000 + value;
5035 ti->color = getPlayerNameColor(global.user_names[i]);
5037 snprintf(identifier, sizeof(identifier), "%d", value);
5038 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5040 setString(&ti->identifier, identifier);
5041 setString(&ti->name, name);
5042 setString(&ti->name_sorting, name);
5044 pushTreeInfo(&player_name, ti);
5047 // sort player entries by player number
5048 sortTreeInfo(&player_name);
5050 // set current player entry to selected player entry
5051 player_name_current =
5052 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5054 // if that fails, set current player name to first available name
5055 if (player_name_current == NULL)
5056 player_name_current = player_name;
5058 DrawChooseTree(&player_name_current);
5060 PlayMenuSoundsAndMusic();
5063 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5065 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5068 void DrawChooseLevelSet(void)
5070 FadeMenuSoundsAndMusic();
5072 DrawChooseTree(&leveldir_current);
5074 PlayMenuSoundsAndMusic();
5077 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5079 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5082 void DrawChooseLevelNr(void)
5086 FadeMenuSoundsAndMusic();
5088 if (level_number != NULL)
5090 freeTreeInfo(level_number);
5092 level_number = NULL;
5095 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5097 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5098 char identifier[32], name[64];
5101 // temporarily load level info to get level name
5102 LoadLevelInfoOnly(i);
5104 ti->node_top = &level_number;
5105 ti->sort_priority = 10000 + value;
5106 ti->color = (level.no_level_file ? FC_BLUE :
5107 LevelStats_getSolved(i) ? FC_GREEN :
5108 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5110 snprintf(identifier, sizeof(identifier), "%d", value);
5111 snprintf(name, sizeof(name), "%03d: %s", value,
5112 (level.no_level_file ? "(no file)" : level.name));
5114 setString(&ti->identifier, identifier);
5115 setString(&ti->name, name);
5116 setString(&ti->name_sorting, name);
5118 pushTreeInfo(&level_number, ti);
5121 // sort level number values to start with lowest level number
5122 sortTreeInfo(&level_number);
5124 // set current level number to current level number
5125 level_number_current =
5126 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5128 // if that also fails, set current level number to first available level
5129 if (level_number_current == NULL)
5130 level_number_current = level_number;
5132 DrawChooseTree(&level_number_current);
5134 PlayMenuSoundsAndMusic();
5137 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5139 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5142 void DrawHallOfFame(int level_nr)
5144 int fade_mask = REDRAW_FIELD;
5147 fade_mask = REDRAW_ALL;
5150 FadeMenuSoundsAndMusic();
5152 // (this is needed when called from GameEnd() after winning a game)
5153 KeyboardAutoRepeatOn();
5155 // (this is needed when called from GameEnd() after winning a game)
5156 SetDrawDeactivationMask(REDRAW_NONE);
5157 SetDrawBackgroundMask(REDRAW_FIELD);
5159 LoadLocalAndServerScore(level_nr, TRUE);
5161 if (scores.last_added >= 0)
5162 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5164 FadeSetEnterScreen();
5168 // needed if different viewport properties defined for scores
5169 ChangeViewportPropertiesIfNeeded();
5171 PlayMenuSoundsAndMusic();
5173 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5175 HandleHallOfFame(level_nr, 0, 0, 0, MB_MENU_INITIALIZE);
5177 DrawMaskedBorder(fade_mask);
5182 static int getHallOfFameFirstEntry(int first_entry, int step)
5185 first_entry = scores.last_added - (NUM_MENU_ENTRIES_ON_SCREEN + 1) / 2 + 1;
5187 first_entry += step;
5189 if (first_entry < 0)
5191 else if (first_entry > MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN)
5192 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
5197 static char *getHallOfFameScoreText(int nr)
5199 if (!level.rate_time_over_score)
5200 return int2str(scores.entry[nr].score, 5); // show normal score
5202 if (level.use_step_counter)
5203 return int2str(scores.entry[nr].time, 5); // show number of steps
5205 static char score_text[10];
5206 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5207 int mm = (time_seconds / 60) % 60;
5208 int ss = (time_seconds % 60);
5210 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5215 static void drawHallOfFameList(int level_nr, int first_entry)
5219 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5222 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
5223 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
5224 "HighScores of Level %d", level_nr);
5226 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5228 int entry = first_entry + i;
5229 boolean active = (entry == scores.last_added);
5230 boolean forced = (scores.force_last_added && active);
5231 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
5232 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
5233 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
5234 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
5235 int dxoff = getFontDrawOffsetX(font_nr1);
5236 int dx1 = 3 * getFontWidth(font_nr1);
5237 int dx2 = dx1 + getFontWidth(font_nr1);
5238 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
5239 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
5240 int sy = mSY + 64 + i * 32;
5241 char *pos_text = (forced ? "???" : int2str(entry + 1, 3));
5243 DrawText(mSX, sy, pos_text, font_nr1);
5244 DrawText(mSX + dx1, sy, ".", font_nr1);
5246 for (j = 0; j < num_dots; j++)
5247 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
5249 if (!strEqual(scores.entry[entry].name, EMPTY_PLAYER_NAME))
5250 DrawText(mSX + dx2, sy, scores.entry[entry].name, font_nr2);
5252 DrawText(mSX + dx3, sy, getHallOfFameScoreText(entry), font_nr4);
5255 redraw_mask |= REDRAW_FIELD;
5258 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5260 static int level_nr = 0;
5261 static int first_entry = 0;
5262 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5264 if (button == MB_MENU_INITIALIZE)
5268 if (server_scores.updated)
5270 // reload scores, using updated server score cache file
5271 LoadLocalAndServerScore(level_nr, FALSE);
5273 server_scores.updated = FALSE;
5276 first_entry = getHallOfFameFirstEntry(0, 0);
5278 drawHallOfFameList(level_nr, first_entry);
5283 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
5284 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
5288 first_entry = getHallOfFameFirstEntry(first_entry, -step);
5290 drawHallOfFameList(level_nr, first_entry);
5294 first_entry = getHallOfFameFirstEntry(first_entry, step);
5296 drawHallOfFameList(level_nr, first_entry);
5298 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5300 PlaySound(SND_MENU_ITEM_SELECTING);
5302 FadeSound(SND_BACKGROUND_SCORES);
5304 if (button == MB_MENU_CHOICE &&
5305 game_status_last_screen == GAME_MODE_PLAYING &&
5306 setup.auto_play_next_level && setup.increment_levels &&
5307 level_nr < leveldir_current->last_level &&
5310 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
5314 SetGameStatus(GAME_MODE_MAIN);
5319 else if (server_scores.updated)
5321 // reload scores, using updated server score cache file
5322 LoadLocalAndServerScore(level_nr, FALSE);
5324 server_scores.updated = FALSE;
5326 first_entry = getHallOfFameFirstEntry(0, 0);
5328 drawHallOfFameList(level_nr, first_entry);
5331 if (game_status == GAME_MODE_SCORES)
5332 PlayMenuSoundIfLoop();
5336 // ============================================================================
5337 // setup screen functions
5338 // ============================================================================
5340 static struct TokenInfo *setup_info;
5341 static int num_setup_info; // number of setup entries shown on screen
5342 static int max_setup_info; // total number of setup entries in list
5344 static char *window_size_text;
5345 static char *scaling_type_text;
5346 static char *rendering_mode_text;
5347 static char *vsync_mode_text;
5348 static char *scroll_delay_text;
5349 static char *snapshot_mode_text;
5350 static char *game_speed_text;
5351 static char *network_server_text;
5352 static char *graphics_set_name;
5353 static char *sounds_set_name;
5354 static char *music_set_name;
5355 static char *volume_simple_text;
5356 static char *volume_loops_text;
5357 static char *volume_music_text;
5358 static char *touch_controls_text;
5359 static char *move_distance_text;
5360 static char *drop_distance_text;
5361 static char *transparency_text;
5362 static char *grid_size_text[2][2];
5364 static void execSetupMain(void)
5366 setup_mode = SETUP_MODE_MAIN;
5371 static void execSetupGame_setGameSpeeds(boolean update_value)
5373 if (setup.game_speed_extended)
5375 game_speeds_list = game_speeds_list_extended;
5376 game_speeds = game_speeds_extended;
5380 game_speeds_list = game_speeds_list_normal;
5381 game_speeds = game_speeds_normal;
5384 if (game_speeds == NULL)
5388 for (i = 0; game_speeds_list[i].value != -1; i++)
5390 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5391 char identifier[32], name[32];
5392 int value = game_speeds_list[i].value;
5393 char *text = game_speeds_list[i].text;
5395 ti->node_top = &game_speeds;
5396 ti->sort_priority = 10000 - value;
5398 sprintf(identifier, "%d", value);
5399 sprintf(name, "%s", text);
5401 setString(&ti->identifier, identifier);
5402 setString(&ti->name, name);
5403 setString(&ti->name_sorting, name);
5404 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5406 pushTreeInfo(&game_speeds, ti);
5409 // sort game speed values to start with slowest game speed
5410 sortTreeInfo(&game_speeds);
5412 update_value = TRUE;
5417 // set current game speed to configured game speed value
5418 game_speed_current =
5419 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5421 // if that fails, set current game speed to reliable default value
5422 if (game_speed_current == NULL)
5423 game_speed_current =
5424 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5426 // if that also fails, set current game speed to first available speed
5427 if (game_speed_current == NULL)
5428 game_speed_current = game_speeds;
5430 if (setup.game_speed_extended)
5431 game_speeds_extended = game_speeds;
5433 game_speeds_normal = game_speeds;
5436 setup.game_frame_delay = atoi(game_speed_current->identifier);
5438 // needed for displaying game speed text instead of identifier
5439 game_speed_text = game_speed_current->name;
5442 static void execSetupGame_setScrollDelays(void)
5444 if (scroll_delays == NULL)
5448 for (i = 0; scroll_delays_list[i].value != -1; i++)
5450 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5451 char identifier[32], name[32];
5452 int value = scroll_delays_list[i].value;
5453 char *text = scroll_delays_list[i].text;
5455 ti->node_top = &scroll_delays;
5456 ti->sort_priority = value;
5458 sprintf(identifier, "%d", value);
5459 sprintf(name, "%s", text);
5461 setString(&ti->identifier, identifier);
5462 setString(&ti->name, name);
5463 setString(&ti->name_sorting, name);
5464 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5466 pushTreeInfo(&scroll_delays, ti);
5469 // sort scroll delay values to start with lowest scroll delay value
5470 sortTreeInfo(&scroll_delays);
5472 // set current scroll delay value to configured scroll delay value
5473 scroll_delay_current =
5474 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5476 // if that fails, set current scroll delay to reliable default value
5477 if (scroll_delay_current == NULL)
5478 scroll_delay_current =
5479 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5481 // if that also fails, set current scroll delay to first available value
5482 if (scroll_delay_current == NULL)
5483 scroll_delay_current = scroll_delays;
5486 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5488 // needed for displaying scroll delay text instead of identifier
5489 scroll_delay_text = scroll_delay_current->name;
5492 static void execSetupGame_setSnapshotModes(void)
5494 if (snapshot_modes == NULL)
5498 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5500 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5501 char identifier[32], name[32];
5502 char *value = snapshot_modes_list[i].value;
5503 char *text = snapshot_modes_list[i].text;
5505 ti->node_top = &snapshot_modes;
5506 ti->sort_priority = i;
5508 sprintf(identifier, "%s", value);
5509 sprintf(name, "%s", text);
5511 setString(&ti->identifier, identifier);
5512 setString(&ti->name, name);
5513 setString(&ti->name_sorting, name);
5514 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5516 pushTreeInfo(&snapshot_modes, ti);
5519 // sort snapshot mode values to start with lowest snapshot mode value
5520 sortTreeInfo(&snapshot_modes);
5522 // set current snapshot mode value to configured snapshot mode value
5523 snapshot_mode_current =
5524 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5526 // if that fails, set current snapshot mode to reliable default value
5527 if (snapshot_mode_current == NULL)
5528 snapshot_mode_current =
5529 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5531 // if that also fails, set current snapshot mode to first available value
5532 if (snapshot_mode_current == NULL)
5533 snapshot_mode_current = snapshot_modes;
5536 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5538 // needed for displaying snapshot mode text instead of identifier
5539 snapshot_mode_text = snapshot_mode_current->name;
5542 static void execSetupGame_setNetworkServerText(void)
5544 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5546 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5550 strncpy(network_server_hostname, setup.network_server_hostname,
5551 MAX_SETUP_TEXT_INPUT_LEN);
5552 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5555 // needed for displaying network server text instead of identifier
5556 network_server_text = network_server_hostname;
5559 static void execSetupGame(void)
5561 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5563 execSetupGame_setGameSpeeds(FALSE);
5564 execSetupGame_setScrollDelays();
5565 execSetupGame_setSnapshotModes();
5567 execSetupGame_setNetworkServerText();
5569 setup_mode = SETUP_MODE_GAME;
5573 // check if vsync needs to be disabled for this game speed to work
5574 if (check_vsync_mode)
5575 DisableVsyncIfNeeded();
5578 static void execSetupChooseGameSpeed(void)
5580 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5585 static void execSetupChooseScrollDelay(void)
5587 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5592 static void execSetupChooseSnapshotMode(void)
5594 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5599 static void execSetupEngines(void)
5601 setup_mode = SETUP_MODE_ENGINES;
5606 static void execSetupEditor(void)
5608 setup_mode = SETUP_MODE_EDITOR;
5613 static void execSetupGraphics_setWindowSizes(boolean update_list)
5615 if (window_sizes != NULL && update_list)
5617 freeTreeInfo(window_sizes);
5619 window_sizes = NULL;
5622 if (window_sizes == NULL)
5624 boolean current_window_size_found = FALSE;
5627 for (i = 0; window_sizes_list[i].value != -1; i++)
5629 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5630 char identifier[32], name[32];
5631 int value = window_sizes_list[i].value;
5632 char *text = window_sizes_list[i].text;
5634 ti->node_top = &window_sizes;
5635 ti->sort_priority = value;
5637 sprintf(identifier, "%d", value);
5638 sprintf(name, "%s", text);
5640 setString(&ti->identifier, identifier);
5641 setString(&ti->name, name);
5642 setString(&ti->name_sorting, name);
5643 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5645 pushTreeInfo(&window_sizes, ti);
5647 if (value == setup.window_scaling_percent)
5648 current_window_size_found = TRUE;
5651 if (!current_window_size_found)
5653 // add entry for non-preset window scaling value
5655 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5656 char identifier[32], name[32];
5657 int value = setup.window_scaling_percent;
5659 ti->node_top = &window_sizes;
5660 ti->sort_priority = value;
5662 sprintf(identifier, "%d", value);
5663 sprintf(name, "%d %% (Current)", value);
5665 setString(&ti->identifier, identifier);
5666 setString(&ti->name, name);
5667 setString(&ti->name_sorting, name);
5668 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5670 pushTreeInfo(&window_sizes, ti);
5673 // sort window size values to start with lowest window size value
5674 sortTreeInfo(&window_sizes);
5676 // set current window size value to configured window size value
5677 window_size_current =
5678 getTreeInfoFromIdentifier(window_sizes,
5679 i_to_a(setup.window_scaling_percent));
5681 // if that fails, set current window size to reliable default value
5682 if (window_size_current == NULL)
5683 window_size_current =
5684 getTreeInfoFromIdentifier(window_sizes,
5685 i_to_a(STD_WINDOW_SCALING_PERCENT));
5687 // if that also fails, set current window size to first available value
5688 if (window_size_current == NULL)
5689 window_size_current = window_sizes;
5692 setup.window_scaling_percent = atoi(window_size_current->identifier);
5694 // needed for displaying window size text instead of identifier
5695 window_size_text = window_size_current->name;
5698 static void execSetupGraphics_setScalingTypes(void)
5700 if (scaling_types == NULL)
5704 for (i = 0; scaling_types_list[i].value != NULL; i++)
5706 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5707 char identifier[32], name[32];
5708 char *value = scaling_types_list[i].value;
5709 char *text = scaling_types_list[i].text;
5711 ti->node_top = &scaling_types;
5712 ti->sort_priority = i;
5714 sprintf(identifier, "%s", value);
5715 sprintf(name, "%s", text);
5717 setString(&ti->identifier, identifier);
5718 setString(&ti->name, name);
5719 setString(&ti->name_sorting, name);
5720 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5722 pushTreeInfo(&scaling_types, ti);
5725 // sort scaling type values to start with lowest scaling type value
5726 sortTreeInfo(&scaling_types);
5728 // set current scaling type value to configured scaling type value
5729 scaling_type_current =
5730 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5732 // if that fails, set current scaling type to reliable default value
5733 if (scaling_type_current == NULL)
5734 scaling_type_current =
5735 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5737 // if that also fails, set current scaling type to first available value
5738 if (scaling_type_current == NULL)
5739 scaling_type_current = scaling_types;
5742 setup.window_scaling_quality = scaling_type_current->identifier;
5744 // needed for displaying scaling type text instead of identifier
5745 scaling_type_text = scaling_type_current->name;
5748 static void execSetupGraphics_setRenderingModes(void)
5750 if (rendering_modes == NULL)
5754 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5756 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5757 char identifier[32], name[32];
5758 char *value = rendering_modes_list[i].value;
5759 char *text = rendering_modes_list[i].text;
5761 ti->node_top = &rendering_modes;
5762 ti->sort_priority = i;
5764 sprintf(identifier, "%s", value);
5765 sprintf(name, "%s", text);
5767 setString(&ti->identifier, identifier);
5768 setString(&ti->name, name);
5769 setString(&ti->name_sorting, name);
5770 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5772 pushTreeInfo(&rendering_modes, ti);
5775 // sort rendering mode values to start with lowest rendering mode value
5776 sortTreeInfo(&rendering_modes);
5778 // set current rendering mode value to configured rendering mode value
5779 rendering_mode_current =
5780 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5782 // if that fails, set current rendering mode to reliable default value
5783 if (rendering_mode_current == NULL)
5784 rendering_mode_current =
5785 getTreeInfoFromIdentifier(rendering_modes,
5786 STR_SPECIAL_RENDERING_DEFAULT);
5788 // if that also fails, set current rendering mode to first available one
5789 if (rendering_mode_current == NULL)
5790 rendering_mode_current = rendering_modes;
5793 setup.screen_rendering_mode = rendering_mode_current->identifier;
5795 // needed for displaying rendering mode text instead of identifier
5796 rendering_mode_text = rendering_mode_current->name;
5799 static void execSetupGraphics_setVsyncModes(boolean update_value)
5801 if (vsync_modes == NULL)
5805 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5807 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5808 char identifier[32], name[32];
5809 char *value = vsync_modes_list[i].value;
5810 char *text = vsync_modes_list[i].text;
5812 ti->node_top = &vsync_modes;
5813 ti->sort_priority = i;
5815 sprintf(identifier, "%s", value);
5816 sprintf(name, "%s", text);
5818 setString(&ti->identifier, identifier);
5819 setString(&ti->name, name);
5820 setString(&ti->name_sorting, name);
5821 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5823 pushTreeInfo(&vsync_modes, ti);
5826 // sort vsync mode values to start with lowest vsync mode value
5827 sortTreeInfo(&vsync_modes);
5829 update_value = TRUE;
5834 // set current vsync mode value to configured vsync mode value
5835 vsync_mode_current =
5836 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5838 // if that fails, set current vsync mode to reliable default value
5839 if (vsync_mode_current == NULL)
5840 vsync_mode_current =
5841 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5843 // if that also fails, set current vsync mode to first available one
5844 if (vsync_mode_current == NULL)
5845 vsync_mode_current = vsync_modes;
5848 setup.vsync_mode = vsync_mode_current->identifier;
5850 // needed for displaying vsync mode text instead of identifier
5851 vsync_mode_text = vsync_mode_current->name;
5854 static void execSetupGraphics(void)
5856 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5858 // update "setup.window_scaling_percent" from list selection
5859 // (in this case, window scaling was changed on setup screen)
5860 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5861 execSetupGraphics_setWindowSizes(FALSE);
5863 // update "setup.vsync_mode" from list selection
5864 // (in this case, vsync mode was changed on setup screen)
5865 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5866 execSetupGraphics_setVsyncModes(FALSE);
5868 // update list selection from "setup.window_scaling_percent"
5869 // (window scaling may have changed by resizing the window)
5870 execSetupGraphics_setWindowSizes(TRUE);
5872 // update list selection from "setup.vsync_mode"
5873 // (vsync_mode may have changed by re-creating the renderer)
5874 execSetupGraphics_setVsyncModes(TRUE);
5876 execSetupGraphics_setScalingTypes();
5877 execSetupGraphics_setRenderingModes();
5879 setup_mode = SETUP_MODE_GRAPHICS;
5883 // check if game speed is high enough for 60 Hz vsync to work
5884 if (check_game_speed)
5885 ModifyGameSpeedIfNeeded();
5887 // window scaling may have changed at this point
5888 ChangeWindowScalingIfNeeded();
5890 // window scaling quality may have changed at this point
5891 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5892 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5894 // screen rendering mode may have changed at this point
5895 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5897 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
5898 int video_vsync_mode = video.vsync_mode;
5900 // screen vsync mode may have changed at this point
5901 ChangeVsyncModeIfNeeded();
5903 // check if setting vsync mode to selected value failed
5904 if (setup_vsync_mode != video_vsync_mode &&
5905 setup_vsync_mode != video.vsync_mode)
5907 // changing vsync mode to selected value failed -- reset displayed value
5908 execSetupGraphics_setVsyncModes(TRUE);
5910 Request("Setting VSync failed!", REQ_CONFIRM);
5916 static void execSetupChooseWindowSize(void)
5918 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5923 static void execSetupChooseScalingType(void)
5925 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5930 static void execSetupChooseRenderingMode(void)
5932 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5937 static void execSetupChooseVsyncMode(void)
5939 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5944 static void execSetupChooseVolumeSimple(void)
5946 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5951 static void execSetupChooseVolumeLoops(void)
5953 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5958 static void execSetupChooseVolumeMusic(void)
5960 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5965 static void execSetupSound(void)
5967 if (volumes_simple == NULL)
5969 boolean current_volume_simple_found = FALSE;
5972 for (i = 0; volumes_list[i].value != -1; i++)
5974 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5975 char identifier[32], name[32];
5976 int value = volumes_list[i].value;
5977 char *text = volumes_list[i].text;
5979 ti->node_top = &volumes_simple;
5980 ti->sort_priority = value;
5982 sprintf(identifier, "%d", value);
5983 sprintf(name, "%s", text);
5985 setString(&ti->identifier, identifier);
5986 setString(&ti->name, name);
5987 setString(&ti->name_sorting, name);
5988 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5990 pushTreeInfo(&volumes_simple, ti);
5992 if (value == setup.volume_simple)
5993 current_volume_simple_found = TRUE;
5996 if (!current_volume_simple_found)
5998 // add entry for non-preset volume value
6000 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6001 char identifier[32], name[32];
6002 int value = setup.volume_simple;
6004 ti->node_top = &volumes_simple;
6005 ti->sort_priority = value;
6007 sprintf(identifier, "%d", value);
6008 sprintf(name, "%d %% (Current)", value);
6010 setString(&ti->identifier, identifier);
6011 setString(&ti->name, name);
6012 setString(&ti->name_sorting, name);
6013 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6015 pushTreeInfo(&volumes_simple, ti);
6018 // sort volume values to start with lowest volume value
6019 sortTreeInfo(&volumes_simple);
6021 // set current volume value to configured volume value
6022 volume_simple_current =
6023 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6025 // if that fails, set current volume to reliable default value
6026 if (volume_simple_current == NULL)
6027 volume_simple_current =
6028 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6030 // if that also fails, set current volume to first available value
6031 if (volume_simple_current == NULL)
6032 volume_simple_current = volumes_simple;
6035 if (volumes_loops == NULL)
6037 boolean current_volume_loops_found = FALSE;
6040 for (i = 0; volumes_list[i].value != -1; i++)
6042 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6043 char identifier[32], name[32];
6044 int value = volumes_list[i].value;
6045 char *text = volumes_list[i].text;
6047 ti->node_top = &volumes_loops;
6048 ti->sort_priority = value;
6050 sprintf(identifier, "%d", value);
6051 sprintf(name, "%s", text);
6053 setString(&ti->identifier, identifier);
6054 setString(&ti->name, name);
6055 setString(&ti->name_sorting, name);
6056 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6058 pushTreeInfo(&volumes_loops, ti);
6060 if (value == setup.volume_loops)
6061 current_volume_loops_found = TRUE;
6064 if (!current_volume_loops_found)
6066 // add entry for non-preset volume value
6068 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6069 char identifier[32], name[32];
6070 int value = setup.volume_loops;
6072 ti->node_top = &volumes_loops;
6073 ti->sort_priority = value;
6075 sprintf(identifier, "%d", value);
6076 sprintf(name, "%d %% (Current)", value);
6078 setString(&ti->identifier, identifier);
6079 setString(&ti->name, name);
6080 setString(&ti->name_sorting, name);
6081 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6083 pushTreeInfo(&volumes_loops, ti);
6086 // sort volume values to start with lowest volume value
6087 sortTreeInfo(&volumes_loops);
6089 // set current volume value to configured volume value
6090 volume_loops_current =
6091 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6093 // if that fails, set current volume to reliable default value
6094 if (volume_loops_current == NULL)
6095 volume_loops_current =
6096 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6098 // if that also fails, set current volume to first available value
6099 if (volume_loops_current == NULL)
6100 volume_loops_current = volumes_loops;
6103 if (volumes_music == NULL)
6105 boolean current_volume_music_found = FALSE;
6108 for (i = 0; volumes_list[i].value != -1; i++)
6110 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6111 char identifier[32], name[32];
6112 int value = volumes_list[i].value;
6113 char *text = volumes_list[i].text;
6115 ti->node_top = &volumes_music;
6116 ti->sort_priority = value;
6118 sprintf(identifier, "%d", value);
6119 sprintf(name, "%s", text);
6121 setString(&ti->identifier, identifier);
6122 setString(&ti->name, name);
6123 setString(&ti->name_sorting, name);
6124 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6126 pushTreeInfo(&volumes_music, ti);
6128 if (value == setup.volume_music)
6129 current_volume_music_found = TRUE;
6132 if (!current_volume_music_found)
6134 // add entry for non-preset volume value
6136 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6137 char identifier[32], name[32];
6138 int value = setup.volume_music;
6140 ti->node_top = &volumes_music;
6141 ti->sort_priority = value;
6143 sprintf(identifier, "%d", value);
6144 sprintf(name, "%d %% (Current)", value);
6146 setString(&ti->identifier, identifier);
6147 setString(&ti->name, name);
6148 setString(&ti->name_sorting, name);
6149 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6151 pushTreeInfo(&volumes_music, ti);
6154 // sort volume values to start with lowest volume value
6155 sortTreeInfo(&volumes_music);
6157 // set current volume value to configured volume value
6158 volume_music_current =
6159 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6161 // if that fails, set current volume to reliable default value
6162 if (volume_music_current == NULL)
6163 volume_music_current =
6164 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6166 // if that also fails, set current volume to first available value
6167 if (volume_music_current == NULL)
6168 volume_music_current = volumes_music;
6171 setup.volume_simple = atoi(volume_simple_current->identifier);
6172 setup.volume_loops = atoi(volume_loops_current->identifier);
6173 setup.volume_music = atoi(volume_music_current->identifier);
6175 // needed for displaying volume text instead of identifier
6176 volume_simple_text = volume_simple_current->name;
6177 volume_loops_text = volume_loops_current->name;
6178 volume_music_text = volume_music_current->name;
6180 setup_mode = SETUP_MODE_SOUND;
6185 static void execSetupChooseTouchControls(void)
6187 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6192 static void execSetupChooseMoveDistance(void)
6194 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6199 static void execSetupChooseDropDistance(void)
6201 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6206 static void execSetupChooseTransparency(void)
6208 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6213 static void execSetupChooseGridXSize_0(void)
6215 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6220 static void execSetupChooseGridYSize_0(void)
6222 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6227 static void execSetupChooseGridXSize_1(void)
6229 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6234 static void execSetupChooseGridYSize_1(void)
6236 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6241 static void execSetupConfigureVirtualButtons(void)
6243 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6245 ConfigureVirtualButtons();
6247 setup_mode = SETUP_MODE_TOUCH;
6252 static void execSetupTouch(void)
6256 if (touch_controls == NULL)
6258 for (i = 0; touch_controls_list[i].value != NULL; i++)
6260 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6261 char identifier[32], name[32];
6262 char *value = touch_controls_list[i].value;
6263 char *text = touch_controls_list[i].text;
6265 ti->node_top = &touch_controls;
6266 ti->sort_priority = i;
6268 sprintf(identifier, "%s", value);
6269 sprintf(name, "%s", text);
6271 setString(&ti->identifier, identifier);
6272 setString(&ti->name, name);
6273 setString(&ti->name_sorting, name);
6274 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6276 pushTreeInfo(&touch_controls, ti);
6279 // sort touch control values to start with lowest touch control value
6280 sortTreeInfo(&touch_controls);
6282 // set current touch control value to configured touch control value
6283 touch_control_current =
6284 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6286 // if that fails, set current touch control to reliable default value
6287 if (touch_control_current == NULL)
6288 touch_control_current =
6289 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6291 // if that also fails, set current touch control to first available value
6292 if (touch_control_current == NULL)
6293 touch_control_current = touch_controls;
6296 if (move_distances == NULL)
6298 for (i = 0; distances_list[i].value != -1; i++)
6300 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6301 char identifier[32], name[32];
6302 int value = distances_list[i].value;
6303 char *text = distances_list[i].text;
6305 ti->node_top = &move_distances;
6306 ti->sort_priority = value;
6308 sprintf(identifier, "%d", value);
6309 sprintf(name, "%s", text);
6311 setString(&ti->identifier, identifier);
6312 setString(&ti->name, name);
6313 setString(&ti->name_sorting, name);
6314 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6316 pushTreeInfo(&move_distances, ti);
6319 // sort distance values to start with lowest distance value
6320 sortTreeInfo(&move_distances);
6322 // set current distance value to configured distance value
6323 move_distance_current =
6324 getTreeInfoFromIdentifier(move_distances,
6325 i_to_a(setup.touch.move_distance));
6327 // if that fails, set current distance to reliable default value
6328 if (move_distance_current == NULL)
6329 move_distance_current =
6330 getTreeInfoFromIdentifier(move_distances,
6331 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6333 // if that also fails, set current distance to first available value
6334 if (move_distance_current == NULL)
6335 move_distance_current = move_distances;
6338 if (drop_distances == NULL)
6340 for (i = 0; distances_list[i].value != -1; i++)
6342 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6343 char identifier[32], name[32];
6344 int value = distances_list[i].value;
6345 char *text = distances_list[i].text;
6347 ti->node_top = &drop_distances;
6348 ti->sort_priority = value;
6350 sprintf(identifier, "%d", value);
6351 sprintf(name, "%s", text);
6353 setString(&ti->identifier, identifier);
6354 setString(&ti->name, name);
6355 setString(&ti->name_sorting, name);
6356 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6358 pushTreeInfo(&drop_distances, ti);
6361 // sort distance values to start with lowest distance value
6362 sortTreeInfo(&drop_distances);
6364 // set current distance value to configured distance value
6365 drop_distance_current =
6366 getTreeInfoFromIdentifier(drop_distances,
6367 i_to_a(setup.touch.drop_distance));
6369 // if that fails, set current distance to reliable default value
6370 if (drop_distance_current == NULL)
6371 drop_distance_current =
6372 getTreeInfoFromIdentifier(drop_distances,
6373 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6375 // if that also fails, set current distance to first available value
6376 if (drop_distance_current == NULL)
6377 drop_distance_current = drop_distances;
6380 if (transparencies == NULL)
6382 for (i = 0; transparencies_list[i].value != -1; i++)
6384 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6385 char identifier[32], name[32];
6386 int value = transparencies_list[i].value;
6387 char *text = transparencies_list[i].text;
6389 ti->node_top = &transparencies;
6390 ti->sort_priority = value;
6392 sprintf(identifier, "%d", value);
6393 sprintf(name, "%s", text);
6395 setString(&ti->identifier, identifier);
6396 setString(&ti->name, name);
6397 setString(&ti->name_sorting, name);
6398 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6400 pushTreeInfo(&transparencies, ti);
6403 // sort transparency values to start with lowest transparency value
6404 sortTreeInfo(&transparencies);
6406 // set current transparency value to configured transparency value
6407 transparency_current =
6408 getTreeInfoFromIdentifier(transparencies,
6409 i_to_a(setup.touch.transparency));
6411 // if that fails, set current transparency to reliable default value
6412 if (transparency_current == NULL)
6413 transparency_current =
6414 getTreeInfoFromIdentifier(transparencies,
6415 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6417 // if that also fails, set current transparency to first available value
6418 if (transparency_current == NULL)
6419 transparency_current = transparencies;
6422 for (i = 0; i < 2; i++)
6424 for (j = 0; j < 2; j++)
6426 if (grid_sizes[i][j] == NULL)
6428 for (k = 0; grid_sizes_list[k].value != -1; k++)
6430 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6431 char identifier[32], name[32];
6432 int value = grid_sizes_list[k].value;
6433 char *text = grid_sizes_list[k].text;
6435 ti->node_top = &grid_sizes[i][j];
6436 ti->sort_priority = value;
6438 sprintf(identifier, "%d", value);
6439 sprintf(name, "%s", text);
6441 setString(&ti->identifier, identifier);
6442 setString(&ti->name, name);
6443 setString(&ti->name_sorting, name);
6444 setString(&ti->infotext,
6447 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6448 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6450 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6451 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6453 pushTreeInfo(&grid_sizes[i][j], ti);
6456 // sort grid size values to start with lowest grid size value
6457 sortTreeInfo(&grid_sizes[i][j]);
6459 // set current grid size value to configured grid size value
6460 grid_size_current[i][j] =
6461 getTreeInfoFromIdentifier(grid_sizes[i][j],
6463 setup.touch.grid_xsize[i] :
6464 setup.touch.grid_ysize[i]));
6466 // if that fails, set current grid size to reliable default value
6467 if (grid_size_current[i][j] == NULL)
6468 grid_size_current[i][j] =
6469 getTreeInfoFromIdentifier(grid_sizes[i][j],
6471 DEFAULT_GRID_XSIZE(i) :
6472 DEFAULT_GRID_YSIZE(i)));
6474 // if that also fails, set current grid size to first available value
6475 if (grid_size_current[i][j] == NULL)
6476 grid_size_current[i][j] = grid_sizes[i][j];
6481 setup.touch.control_type = touch_control_current->identifier;
6482 setup.touch.move_distance = atoi(move_distance_current->identifier);
6483 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6484 setup.touch.transparency = atoi(transparency_current->identifier);
6486 for (i = 0; i < 2; i++)
6488 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6489 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6491 if (i == GRID_ACTIVE_NR())
6493 overlay.grid_xsize = setup.touch.grid_xsize[i];
6494 overlay.grid_ysize = setup.touch.grid_ysize[i];
6498 // needed for displaying value text instead of identifier
6499 touch_controls_text = touch_control_current->name;
6500 move_distance_text = move_distance_current->name;
6501 drop_distance_text = drop_distance_current->name;
6502 transparency_text = transparency_current->name;
6504 for (i = 0; i < 2; i++)
6505 for (j = 0; j < 2; j++)
6506 grid_size_text[i][j] = grid_size_current[i][j]->name;
6508 setup_mode = SETUP_MODE_TOUCH;
6513 static void execSetupArtwork(void)
6515 static ArtworkDirTree *gfx_last_valid = NULL;
6516 static ArtworkDirTree *snd_last_valid = NULL;
6517 static ArtworkDirTree *mus_last_valid = NULL;
6519 // current artwork directory may be invalid (level group, parent link)
6520 if (!validLevelSeries(artwork.gfx_current))
6521 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6522 if (!validLevelSeries(artwork.snd_current))
6523 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6524 if (!validLevelSeries(artwork.mus_current))
6525 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6527 // store valid artwork directory information
6528 gfx_last_valid = artwork.gfx_current;
6529 snd_last_valid = artwork.snd_current;
6530 mus_last_valid = artwork.mus_current;
6533 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6534 artwork.gfx_current->subdir,
6535 artwork.gfx_current->fullpath,
6536 artwork.gfx_current->basepath);
6539 setup.graphics_set = artwork.gfx_current->identifier;
6540 setup.sounds_set = artwork.snd_current->identifier;
6541 setup.music_set = artwork.mus_current->identifier;
6543 // needed if last screen (setup choice) changed graphics, sounds or music
6544 ReloadCustomArtwork(0);
6546 // needed for displaying artwork name instead of artwork identifier
6547 graphics_set_name = artwork.gfx_current->name;
6548 sounds_set_name = artwork.snd_current->name;
6549 music_set_name = artwork.mus_current->name;
6551 setup_mode = SETUP_MODE_ARTWORK;
6556 static void execSetupChooseGraphics(void)
6558 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6563 static void execSetupChooseSounds(void)
6565 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6570 static void execSetupChooseMusic(void)
6572 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6577 static void execSetupInput(void)
6579 setup_mode = SETUP_MODE_INPUT;
6584 static void execSetupShortcuts(void)
6586 setup_mode = SETUP_MODE_SHORTCUTS;
6591 static void execSetupShortcuts1(void)
6593 setup_mode = SETUP_MODE_SHORTCUTS_1;
6598 static void execSetupShortcuts2(void)
6600 setup_mode = SETUP_MODE_SHORTCUTS_2;
6605 static void execSetupShortcuts3(void)
6607 setup_mode = SETUP_MODE_SHORTCUTS_3;
6612 static void execSetupShortcuts4(void)
6614 setup_mode = SETUP_MODE_SHORTCUTS_4;
6619 static void execSetupShortcuts5(void)
6621 setup_mode = SETUP_MODE_SHORTCUTS_5;
6626 static void execExitSetup(void)
6628 SetGameStatus(GAME_MODE_MAIN);
6633 static void execSaveAndExitSetup(void)
6639 static void execGadgetNetworkServer(void)
6641 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6642 struct GadgetInfo *gi = screen_gadget[gadget_id];
6644 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6645 network_server_hostname[0] = '\0';
6647 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6651 ClickOnGadget(gi, MB_LEFTBUTTON);
6654 static void ToggleNetworkModeIfNeeded(void)
6656 int font_title = FONT_TITLE_1;
6657 int font_foot = FC_BLUE;
6658 int ystart = mSY - SY + 16;
6659 int ybottom = mSY - SY + SYSIZE - 20;
6660 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6662 if (setup.network_mode == network.enabled)
6665 network.enabled = setup.network_mode;
6667 FadeOut(REDRAW_ALL);
6671 DrawTextSCentered(ystart, font_title, text);
6675 if (network.enabled)
6676 InitNetworkServer();
6678 DisconnectFromNetworkServer();
6680 DrawTextSCentered(ybottom, font_foot,
6681 "Press any key or button for setup menu");
6683 WaitForEventToContinue();
6688 static void ToggleGameSpeedsListIfNeeded(void)
6690 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6692 if (setup.game_speed_extended == using_game_speeds_extended)
6695 // try to match similar values when changing game speeds list
6696 if (setup.game_speed_extended)
6697 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6698 setup.game_frame_delay == 30 ? 29 :
6699 setup.game_frame_delay);
6701 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6702 setup.game_frame_delay == 16 ? 15 :
6703 setup.game_frame_delay >= 29 ? 30 :
6704 setup.game_frame_delay <= 10 ? 10 :
6705 setup.game_frame_delay);
6707 execSetupGame_setGameSpeeds(TRUE);
6712 static void ModifyGameSpeedIfNeeded(void)
6714 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6715 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6719 char *game_speed_text = "Fast";
6720 int game_speed_value = 15;
6722 if (setup.game_speed_extended)
6724 game_speed_text = "60 fps";
6725 game_speed_value = 16;
6728 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6730 // set game speed to existing list value that is fast enough for vsync
6731 setup.game_frame_delay = game_speed_value;
6733 execSetupGame_setGameSpeeds(TRUE);
6735 Request(message, REQ_CONFIRM);
6738 static void DisableVsyncIfNeeded(void)
6740 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6741 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6742 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6745 // disable vsync for the selected game speed to work
6746 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6748 execSetupGraphics_setVsyncModes(TRUE);
6750 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6756 void *related_value;
6757 } hide_related_entry_list[] =
6759 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6760 { &setup.game_frame_delay, &game_speed_text },
6762 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6763 { &setup.scroll_delay_value, &scroll_delay_text },
6765 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6766 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6768 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6769 { &setup.window_scaling_percent, &window_size_text },
6771 { &setup.window_scaling_quality, execSetupChooseScalingType },
6772 { &setup.window_scaling_quality, &scaling_type_text },
6774 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6775 { &setup.screen_rendering_mode, &rendering_mode_text },
6777 { &setup.vsync_mode, execSetupChooseVsyncMode },
6778 { &setup.vsync_mode, &vsync_mode_text },
6780 { &setup.graphics_set, execSetupChooseGraphics },
6781 { &setup.graphics_set, &graphics_set_name },
6783 { &setup.sounds_set, execSetupChooseSounds },
6784 { &setup.sounds_set, &sounds_set_name },
6786 { &setup.music_set, execSetupChooseMusic },
6787 { &setup.music_set, &music_set_name },
6789 { &setup.volume_simple, execSetupChooseVolumeSimple },
6790 { &setup.volume_simple, &volume_simple_text },
6792 { &setup.volume_loops, execSetupChooseVolumeLoops },
6793 { &setup.volume_loops, &volume_loops_text },
6795 { &setup.volume_music, execSetupChooseVolumeMusic },
6796 { &setup.volume_music, &volume_music_text },
6798 { &setup.touch.control_type, execSetupChooseTouchControls },
6799 { &setup.touch.control_type, &touch_controls_text },
6801 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6802 { &setup.touch.move_distance, &move_distance_text },
6804 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6805 { &setup.touch.drop_distance, &drop_distance_text },
6807 { &setup.touch.transparency, execSetupChooseTransparency },
6808 { &setup.touch.transparency, &transparency_text },
6810 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6811 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6813 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6814 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6816 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6817 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6819 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6820 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6822 { &setup.internal.menu_game, execSetupGame },
6823 { &setup.internal.menu_engines, execSetupEngines },
6824 { &setup.internal.menu_editor, execSetupEditor },
6825 { &setup.internal.menu_graphics, execSetupGraphics },
6826 { &setup.internal.menu_sound, execSetupSound },
6827 { &setup.internal.menu_artwork, execSetupArtwork },
6828 { &setup.internal.menu_input, execSetupInput },
6829 { &setup.internal.menu_touch, execSetupTouch },
6830 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6831 { &setup.internal.menu_exit, execExitSetup },
6832 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6837 void setHideRelatedSetupEntries(void)
6841 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6842 if (hideSetupEntry(hide_related_entry_list[i].value))
6843 setHideSetupEntry(hide_related_entry_list[i].related_value);
6846 static struct TokenInfo setup_info_main[] =
6848 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6849 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6850 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6851 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6852 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6853 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6854 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6855 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6856 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6857 { TYPE_EMPTY, NULL, "" },
6858 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6859 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6864 static struct TokenInfo setup_info_game[] =
6866 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6867 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6868 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6869 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6870 { TYPE_STRING, &network_server_text, "" },
6871 { TYPE_SWITCH, &setup.api_server, "Use Highscore Server:" },
6872 { TYPE_SWITCH, &setup.only_show_local_scores, "Only Show Local Scores:" },
6873 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
6874 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6875 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6876 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6877 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6878 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6879 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6880 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
6881 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
6882 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6883 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
6884 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
6885 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6886 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6887 { TYPE_STRING, &game_speed_text, "" },
6888 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6890 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6891 { TYPE_STRING, &scroll_delay_text, "" },
6893 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6894 { TYPE_STRING, &snapshot_mode_text, "" },
6895 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
6896 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
6897 { TYPE_EMPTY, NULL, "" },
6898 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6903 static struct TokenInfo setup_info_engines[] =
6905 { TYPE_HEADLINE, NULL, "Emerald Mine" },
6906 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
6907 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
6908 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
6909 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
6910 { TYPE_EMPTY, NULL, "" },
6911 { TYPE_HEADLINE, NULL, "Supaplex" },
6912 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
6913 { TYPE_EMPTY, NULL, "" },
6914 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6919 static struct TokenInfo setup_info_editor[] =
6922 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6923 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6924 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6925 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6926 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6927 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6928 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6929 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6930 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6931 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6933 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6934 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6936 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6938 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6939 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6940 { TYPE_EMPTY, NULL, "" },
6942 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6943 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6944 { TYPE_EMPTY, NULL, "" },
6946 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6947 { TYPE_EMPTY, NULL, "" },
6948 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
6949 { TYPE_EMPTY, NULL, "" },
6950 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6955 static struct TokenInfo setup_info_graphics[] =
6957 #if !defined(PLATFORM_ANDROID)
6958 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6959 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6960 { TYPE_STRING, &window_size_text, "" },
6961 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6962 { TYPE_STRING, &scaling_type_text, "" },
6963 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6964 { TYPE_STRING, &rendering_mode_text, "" },
6967 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6968 { TYPE_STRING, &scroll_delay_text, "" },
6970 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6971 { TYPE_STRING, &vsync_mode_text, "" },
6972 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6973 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6974 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6975 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6976 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6977 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6978 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
6979 { TYPE_EMPTY, NULL, "" },
6980 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6985 static struct TokenInfo setup_info_sound[] =
6987 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6988 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6989 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6990 { TYPE_EMPTY, NULL, "" },
6991 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6992 { TYPE_STRING, &volume_simple_text, "" },
6993 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6994 { TYPE_STRING, &volume_loops_text, "" },
6995 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6996 { TYPE_STRING, &volume_music_text, "" },
6997 { TYPE_EMPTY, NULL, "" },
6998 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7003 static struct TokenInfo setup_info_artwork[] =
7005 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7006 { TYPE_STRING, &graphics_set_name, "" },
7007 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7008 { TYPE_STRING, &sounds_set_name, "" },
7009 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7010 { TYPE_STRING, &music_set_name, "" },
7011 { TYPE_EMPTY, NULL, "" },
7012 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7013 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7014 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7015 { TYPE_EMPTY, NULL, "" },
7016 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7021 static struct TokenInfo setup_info_input[] =
7023 { TYPE_SWITCH, NULL, "Player:" },
7024 { TYPE_SWITCH, NULL, "Device:" },
7025 { TYPE_SWITCH, NULL, "" },
7026 { TYPE_SKIPPABLE, NULL, "" },
7027 { TYPE_EMPTY, NULL, "" },
7028 { TYPE_EMPTY, NULL, "" },
7029 { TYPE_EMPTY, NULL, "" },
7030 { TYPE_EMPTY, NULL, "" },
7031 { TYPE_EMPTY, NULL, "" },
7032 { TYPE_EMPTY, NULL, "" },
7033 { TYPE_EMPTY, NULL, "" },
7034 { TYPE_EMPTY, NULL, "" },
7035 { TYPE_SKIPPABLE, NULL, "" },
7036 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7041 static struct TokenInfo setup_info_touch[] =
7043 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7044 { TYPE_STRING, &touch_controls_text, "" },
7045 { TYPE_EMPTY, NULL, "" },
7046 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7051 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7053 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7054 { TYPE_STRING, &touch_controls_text, "" },
7055 { TYPE_EMPTY, NULL, "" },
7056 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7057 { TYPE_STRING, &grid_size_text[0][0], "" },
7058 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7059 { TYPE_STRING, &grid_size_text[0][1], "" },
7060 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7061 { TYPE_STRING, &transparency_text, "" },
7062 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7063 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7064 { TYPE_EMPTY, NULL, "" },
7065 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7066 { TYPE_EMPTY, NULL, "" },
7067 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7072 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7074 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7075 { TYPE_STRING, &touch_controls_text, "" },
7076 { TYPE_EMPTY, NULL, "" },
7077 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7078 { TYPE_STRING, &grid_size_text[1][0], "" },
7079 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7080 { TYPE_STRING, &grid_size_text[1][1], "" },
7081 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7082 { TYPE_STRING, &transparency_text, "" },
7083 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7084 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7085 { TYPE_EMPTY, NULL, "" },
7086 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7087 { TYPE_EMPTY, NULL, "" },
7088 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7093 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7095 setup_info_touch_virtual_buttons_0,
7096 setup_info_touch_virtual_buttons_1
7099 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7101 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7102 { TYPE_STRING, &touch_controls_text, "" },
7103 { TYPE_EMPTY, NULL, "" },
7104 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7105 { TYPE_STRING, &move_distance_text, "" },
7106 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7107 { TYPE_STRING, &drop_distance_text, "" },
7108 { TYPE_EMPTY, NULL, "" },
7109 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7114 static struct TokenInfo setup_info_shortcuts[] =
7116 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7117 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7118 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7119 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7120 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7121 { TYPE_EMPTY, NULL, "" },
7122 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7127 static struct TokenInfo setup_info_shortcuts_1[] =
7129 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7130 { TYPE_KEY, &setup.shortcut.save_game, "" },
7131 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7132 { TYPE_KEY, &setup.shortcut.load_game, "" },
7133 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7134 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7135 { TYPE_EMPTY, NULL, "" },
7136 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7137 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7138 { TYPE_EMPTY, NULL, "" },
7139 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7144 static struct TokenInfo setup_info_shortcuts_2[] =
7146 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7147 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7148 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7149 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7150 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7151 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7152 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7153 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7154 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7155 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7156 { TYPE_EMPTY, NULL, "" },
7157 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7162 static struct TokenInfo setup_info_shortcuts_3[] =
7164 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7165 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7166 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7167 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7168 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7169 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7170 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7171 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7172 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7173 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7174 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7175 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7176 { TYPE_EMPTY, NULL, "" },
7177 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7182 static struct TokenInfo setup_info_shortcuts_4[] =
7184 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7185 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7186 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7187 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7188 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7189 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7190 { TYPE_EMPTY, NULL, "" },
7191 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7196 static struct TokenInfo setup_info_shortcuts_5[] =
7198 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7199 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7200 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7201 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7202 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7203 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7204 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7205 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7206 { TYPE_EMPTY, NULL, "" },
7207 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7212 static Key getSetupKey(void)
7214 Key key = KSYM_UNDEFINED;
7215 boolean got_key_event = FALSE;
7217 while (!got_key_event)
7221 if (NextValidEvent(&event))
7225 case EVENT_KEYPRESS:
7227 key = GetEventKey((KeyEvent *)&event, TRUE);
7229 // press 'Escape' or 'Enter' to keep the existing key binding
7230 if (key == KSYM_Escape || key == KSYM_Return)
7231 key = KSYM_UNDEFINED; // keep old value
7233 got_key_event = TRUE;
7237 case EVENT_KEYRELEASE:
7238 key_joystick_mapping = 0;
7242 HandleOtherEvents(&event);
7253 static int getSetupValueFont(int type, void *value)
7255 if (type & TYPE_GHOSTED)
7256 return FONT_OPTION_OFF;
7257 else if (type & TYPE_KEY)
7258 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7259 else if (type & TYPE_STRING)
7260 return FONT_VALUE_2;
7261 else if (type & TYPE_ECS_AGA)
7262 return FONT_VALUE_1;
7263 else if (type & TYPE_BOOLEAN_STYLE)
7264 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7265 else if (type & TYPE_YES_NO_AUTO)
7266 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7267 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7268 else if (type & TYPE_PLAYER)
7269 return FONT_VALUE_1;
7271 return FONT_VALUE_1;
7274 static int getSetupValueFontNarrow(int type, int font_nr)
7276 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7277 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7278 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7282 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7284 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7285 struct TokenInfo *si = &setup_info[si_pos];
7286 boolean font_draw_xoffset_modified = FALSE;
7287 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7288 int font_draw_xoffset_old = -1;
7289 int xoffset = (scrollbar_needed ? -1 : 0);
7290 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7291 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7292 int xpos = menu_screen_value_xpos;
7293 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7294 int startx = mSX + xpos * 32;
7295 int starty = mSY + ypos * 32;
7296 int type = si->type;
7297 void *value = si->value;
7298 char *value_string = getSetupValue(type, value);
7299 int font_nr_default = getSetupValueFont(type, value);
7300 int font_width_default = getFontWidth(font_nr_default);
7301 int font_nr = font_nr_default;
7304 if (value_string == NULL)
7307 if (type & TYPE_KEY)
7309 xpos = MENU_SCREEN_START_XPOS;
7311 if (type & TYPE_QUERY)
7312 value_string = "<press key>";
7314 else if (type & TYPE_STRING)
7316 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7318 xpos = MENU_SCREEN_START_XPOS;
7320 if (strlen(value_string) > max_value_len)
7321 value_string[max_value_len] = '\0';
7323 else if (type & TYPE_YES_NO_AUTO)
7325 xpos = menu_screen_value_xpos - 1;
7327 else if (type & TYPE_PLAYER)
7329 int displayed_player_nr = *(int *)value + 1;
7331 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7334 startx = mSX + xpos * 32;
7335 starty = mSY + ypos * 32;
7337 // special check if right-side setup values moved left due to scrollbar
7338 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7340 int max_menu_text_length = 26; // maximum text length for classic menu
7341 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7342 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7343 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7344 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7345 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7347 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7349 // when using narrow font, left-shifting text "auto" not needed
7350 if (type & TYPE_YES_NO_AUTO)
7354 startx = mSX + xpos * 32;
7356 font_nr = getSetupValueFontNarrow(type, font_nr);
7360 // downward compatibility correction for Juergen Bonhagen's menu settings
7361 if (setup_mode != SETUP_MODE_INPUT)
7363 int max_menu_text_length_big = (menu_screen_value_xpos -
7364 MENU_SCREEN_START_XPOS);
7365 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7366 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7367 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7368 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
7369 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7370 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7371 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7372 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7373 boolean correct_font_draw_xoffset = FALSE;
7375 if (xpos == MENU_SCREEN_START_XPOS &&
7376 startx + font1_xoffset < text_startx + text_font_xoffset)
7377 correct_font_draw_xoffset = TRUE;
7379 if (xpos == menu_screen_value_xpos &&
7380 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7381 correct_font_draw_xoffset = TRUE;
7383 // check if setup value would overlap with setup text when printed
7384 // (this can happen for extreme/wrong values for font draw offset)
7385 if (correct_font_draw_xoffset)
7387 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
7388 font_draw_xoffset_modified = TRUE;
7390 if (type & TYPE_KEY)
7391 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7392 else if (!(type & TYPE_STRING))
7393 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7394 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7398 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7399 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7401 DrawText(startx, starty, value_string, font_nr);
7403 if (type & TYPE_PLAYER)
7405 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7406 int player_nr = *(int *)value;
7407 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7408 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7409 int startx2 = startx + xoff;
7410 int starty2 = starty + yoff;
7412 if (DrawingOnBackground(startx2, starty2))
7413 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7415 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7416 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7419 if (font_draw_xoffset_modified)
7420 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7423 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7425 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7426 struct TokenInfo *si = &setup_info[si_pos];
7428 if (si->type & TYPE_BOOLEAN_STYLE)
7430 *(boolean *)si->value ^= TRUE;
7432 else if (si->type & TYPE_YES_NO_AUTO)
7436 (*(int *)si->value == AUTO ? TRUE :
7437 *(int *)si->value == TRUE ? FALSE : AUTO) :
7438 (*(int *)si->value == TRUE ? AUTO :
7439 *(int *)si->value == AUTO ? FALSE : TRUE));
7441 else if (si->type & TYPE_KEY)
7445 si->type |= TYPE_QUERY;
7446 drawSetupValue(screen_pos, setup_info_pos_raw);
7447 si->type &= ~TYPE_QUERY;
7449 key = getSetupKey();
7450 if (key != KSYM_UNDEFINED)
7451 *(Key *)si->value = key;
7453 else if (si->type & TYPE_PLAYER)
7455 int player_nr = *(int *)si->value;
7460 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7462 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7465 drawSetupValue(screen_pos, setup_info_pos_raw);
7467 // fullscreen state may have changed at this point
7468 if (si->value == &setup.fullscreen)
7469 ToggleFullscreenIfNeeded();
7471 // network mode may have changed at this point
7472 if (si->value == &setup.network_mode)
7473 ToggleNetworkModeIfNeeded();
7475 // API server mode may have changed at this point
7476 if (si->value == &setup.api_server)
7477 runtime.api_server = setup.api_server;
7479 // game speed list may have changed at this point
7480 if (si->value == &setup.game_speed_extended)
7481 ToggleGameSpeedsListIfNeeded();
7484 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7486 static struct TokenInfo *setup_info_final = NULL;
7491 // determine maximum list size of target list
7492 while (setup_info_orig[list_size++].type != 0);
7494 // free, allocate and clear memory for target list
7495 checked_free(setup_info_final);
7496 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7498 // copy setup info list without setup entries marked as hidden
7499 for (i = 0; setup_info_orig[i].type != 0; i++)
7501 // skip setup entries configured to be hidden
7502 if (hideSetupEntry(setup_info_orig[i].value))
7505 // skip skippable setup entries if screen is lower than usual
7506 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7507 setup_info_orig[i].type == TYPE_SKIPPABLE)
7510 setup_info_final[list_pos++] = setup_info_orig[i];
7513 return setup_info_final;
7516 static void DrawSetupScreen_Generic(void)
7518 int fade_mask = REDRAW_FIELD;
7519 boolean redraw_all = FALSE;
7520 char *title_string = NULL;
7524 fade_mask = REDRAW_ALL;
7527 FadeMenuSoundsAndMusic();
7529 FreeScreenGadgets();
7530 CreateScreenGadgets();
7532 if (redraw_mask & REDRAW_ALL)
7537 // needed if different viewport properties defined for setup screen
7538 ChangeViewportPropertiesIfNeeded();
7540 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7544 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7546 if (setup_mode == SETUP_MODE_MAIN)
7548 setup_info = setup_info_main;
7549 title_string = STR_SETUP_MAIN;
7551 else if (setup_mode == SETUP_MODE_GAME)
7553 setup_info = setup_info_game;
7554 title_string = STR_SETUP_GAME;
7556 else if (setup_mode == SETUP_MODE_ENGINES)
7558 setup_info = setup_info_engines;
7559 title_string = STR_SETUP_ENGINES;
7561 else if (setup_mode == SETUP_MODE_EDITOR)
7563 setup_info = setup_info_editor;
7564 title_string = STR_SETUP_EDITOR;
7566 else if (setup_mode == SETUP_MODE_GRAPHICS)
7568 setup_info = setup_info_graphics;
7569 title_string = STR_SETUP_GRAPHICS;
7571 else if (setup_mode == SETUP_MODE_SOUND)
7573 setup_info = setup_info_sound;
7574 title_string = STR_SETUP_SOUND;
7576 else if (setup_mode == SETUP_MODE_ARTWORK)
7578 setup_info = setup_info_artwork;
7579 title_string = STR_SETUP_ARTWORK;
7581 else if (setup_mode == SETUP_MODE_TOUCH)
7583 setup_info = setup_info_touch;
7584 title_string = STR_SETUP_TOUCH;
7586 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7587 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7588 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7589 setup_info = setup_info_touch_wipe_gestures;
7591 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7593 setup_info = setup_info_shortcuts;
7594 title_string = STR_SETUP_SHORTCUTS;
7596 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7598 setup_info = setup_info_shortcuts_1;
7599 title_string = STR_SETUP_SHORTCUTS;
7601 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7603 setup_info = setup_info_shortcuts_2;
7604 title_string = STR_SETUP_SHORTCUTS;
7606 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7608 setup_info = setup_info_shortcuts_3;
7609 title_string = STR_SETUP_SHORTCUTS;
7611 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7613 setup_info = setup_info_shortcuts_4;
7614 title_string = STR_SETUP_SHORTCUTS;
7616 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7618 setup_info = setup_info_shortcuts_5;
7619 title_string = STR_SETUP_SHORTCUTS;
7622 // use modified setup info without setup entries marked as hidden
7623 setup_info = getSetupInfoFinal(setup_info);
7625 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7627 // determine maximal number of setup entries that can be displayed on screen
7629 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7632 // determine maximal number of setup entries available for this setup screen
7634 for (i = 0; setup_info[i].type != 0; i++)
7637 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7639 MapScreenGadgets(max_setup_info);
7642 redraw_mask = fade_mask = REDRAW_ALL;
7644 DrawMaskedBorder(fade_mask);
7649 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7651 menu_info = setup_info;
7653 HandleMenuScreen(mx, my, dx, dy, button,
7654 setup_mode, num_setup_info, max_setup_info);
7657 static void DrawSetupScreen_Input(void)
7661 FadeOut(REDRAW_FIELD);
7665 setup_info = getSetupInfoFinal(setup_info_input);
7667 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7669 for (i = 0; setup_info[i].type != 0; i++)
7671 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7672 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7673 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7674 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7675 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7676 initCursor(i, IMG_MENU_BUTTON);
7678 DrawCursorAndText_Setup(i, -1, FALSE);
7681 // create gadgets for setup input menu screen
7682 FreeScreenGadgets();
7683 CreateScreenGadgets();
7685 // map gadgets for setup input menu screen
7686 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7688 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7690 FadeIn(REDRAW_FIELD);
7693 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7695 if (device_name == NULL)
7698 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7701 if (strlen(device_name) > 1)
7703 char c1 = device_name[strlen(device_name) - 1];
7704 char c2 = device_name[strlen(device_name) - 2];
7706 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7707 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7710 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7711 strlen(device_name));
7714 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7717 static struct SetupKeyboardInfo custom_key;
7724 { &custom_key.left, "Axis/Pad Left" },
7725 { &custom_key.right, "Axis/Pad Right" },
7726 { &custom_key.up, "Axis/Pad Up" },
7727 { &custom_key.down, "Axis/Pad Down" },
7728 { &custom_key.snap, "Button 1/A/X" },
7729 { &custom_key.drop, "Button 2/B/Y" }
7731 static char *joystick_name[MAX_PLAYERS] =
7738 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7739 int font_nr_info = FONT_MENU_1;
7740 int font_nr_name = FONT_VALUE_OLD;
7741 int font_nr_on = FONT_VALUE_1;
7742 int font_nr_off = FONT_VALUE_OLD;
7745 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7747 font_nr_info = FONT_MENU_2;
7748 font_nr_on = FONT_VALUE_NARROW;
7749 font_nr_off = FONT_VALUE_OLD_NARROW;
7752 custom_key = setup.input[player_nr].key;
7754 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7755 FONT_INPUT_1_ACTIVE);
7757 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7759 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7760 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7762 if (setup.input[player_nr].use_joystick)
7764 char *device_name = setup.input[player_nr].joy.device_name;
7765 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7766 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7767 char *text = joystick_name[joystick_nr];
7768 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7770 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7771 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7775 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7776 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7779 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7780 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7784 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7785 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7786 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7787 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7789 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7790 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7791 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7792 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7793 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7794 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7796 for (i = 0; i < 6; i++)
7798 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7800 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7802 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7803 (setup.input[player_nr].use_joystick ?
7805 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7809 static int input_player_nr = 0;
7811 static void HandleSetupScreen_Input_Player(int step, int direction)
7813 int old_player_nr = input_player_nr;
7816 new_player_nr = old_player_nr + step * direction;
7817 if (new_player_nr < 0)
7819 if (new_player_nr > MAX_PLAYERS - 1)
7820 new_player_nr = MAX_PLAYERS - 1;
7822 if (new_player_nr != old_player_nr)
7824 input_player_nr = new_player_nr;
7826 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7830 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7832 static int choice = 0;
7835 int pos_start = SETUPINPUT_SCREEN_POS_START;
7836 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7837 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7838 int pos_end = SETUPINPUT_SCREEN_POS_END;
7840 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7844 for (i = 0; setup_info_input[i].type != 0; i++)
7846 // adjust menu structure according to skipped setup entries
7847 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7855 if (button == MB_MENU_INITIALIZE)
7857 // input setup menu may have changed size due to graphics configuration
7858 if (choice >= pos_empty1)
7861 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7863 DrawCursorAndText_Setup(choice, -1, TRUE);
7867 else if (button == MB_MENU_LEAVE)
7869 setup_mode = SETUP_MODE_MAIN;
7876 if (mx || my) // mouse input
7878 x = (mx - mSX) / 32;
7879 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7881 else if (dx || dy) // keyboard input
7883 if (dx && choice == 0)
7884 x = (dx < 0 ? 10 : 12);
7885 else if ((dx && choice == 1) ||
7886 (dx == -1 && choice == pos_end))
7887 button = MB_MENU_CHOICE;
7891 if (y >= pos_empty1 && y <= pos_empty2)
7892 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7895 if (y == 0 && dx != 0 && button)
7897 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7899 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7900 y >= pos_start && y <= pos_end &&
7901 !(y >= pos_empty1 && y <= pos_empty2))
7907 DrawCursorAndText_Setup(choice, -1, FALSE);
7908 DrawCursorAndText_Setup(y, -1, TRUE);
7910 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7919 char *device_name = setup.input[input_player_nr].joy.device_name;
7921 if (!setup.input[input_player_nr].use_joystick)
7923 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7925 setJoystickDeviceToNr(device_name, new_device_nr);
7926 setup.input[input_player_nr].use_joystick = TRUE;
7930 int device_nr = getJoystickNrFromDeviceName(device_name);
7931 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7933 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7934 setup.input[input_player_nr].use_joystick = FALSE;
7936 setJoystickDeviceToNr(device_name, new_device_nr);
7939 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7943 if (setup.input[input_player_nr].use_joystick)
7944 ConfigureJoystick(input_player_nr);
7946 CustomizeKeyboard(input_player_nr);
7948 else if (y == pos_end)
7954 setup_mode = SETUP_MODE_MAIN;
7961 static boolean CustomizeKeyboardMain(int player_nr)
7965 boolean finished = FALSE;
7966 static struct SetupKeyboardInfo custom_key;
7971 } customize_step[] =
7973 { &custom_key.left, "Move Left" },
7974 { &custom_key.right, "Move Right" },
7975 { &custom_key.up, "Move Up" },
7976 { &custom_key.down, "Move Down" },
7977 { &custom_key.snap, "Snap Field" },
7978 { &custom_key.drop, "Drop Element" }
7980 int font_nr_old = FONT_VALUE_OLD;
7981 int font_nr_new = FONT_VALUE_1;
7982 boolean success = FALSE;
7984 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7986 font_nr_old = FONT_VALUE_OLD_NARROW;
7987 font_nr_new = FONT_VALUE_NARROW;
7990 // read existing key bindings from player setup
7991 custom_key = setup.input[player_nr].key;
7994 FadeOut(REDRAW_FIELD);
7998 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8001 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8002 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8003 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8004 "Key:", FONT_INPUT_1_ACTIVE);
8005 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8006 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8008 FadeIn(REDRAW_FIELD);
8014 if (NextValidEvent(&event))
8018 case EVENT_KEYPRESS:
8020 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8022 // press 'Escape' to abort and keep the old key bindings
8023 if (key == KSYM_Escape)
8025 FadeSkipNextFadeIn();
8032 // press 'Enter' to keep the existing key binding
8033 if (key == KSYM_Return)
8034 key = *customize_step[step_nr].key;
8036 // check if key already used
8037 for (i = 0; i < step_nr; i++)
8038 if (*customize_step[i].key == key)
8043 // got new key binding
8044 *customize_step[step_nr].key = key;
8045 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8047 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8048 getKeyNameFromKey(key), font_nr_new);
8051 // un-highlight last query
8052 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8053 customize_step[step_nr - 1].text, FONT_MENU_1);
8054 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8055 "Key:", FONT_MENU_1);
8057 // all keys configured
8066 // query next key binding
8067 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8068 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8069 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8070 "Key:", FONT_INPUT_1_ACTIVE);
8071 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8072 getKeyNameFromKey(*customize_step[step_nr].key),
8077 case EVENT_KEYRELEASE:
8078 key_joystick_mapping = 0;
8082 HandleOtherEvents(&event);
8090 // write new key bindings back to player setup, if successfully finished
8092 setup.input[player_nr].key = custom_key;
8097 void CustomizeKeyboard(int player_nr)
8099 boolean success = CustomizeKeyboardMain(player_nr);
8103 int font_nr = FONT_TITLE_1;
8104 int font_height = getFontHeight(font_nr);
8105 int ypos1 = SYSIZE / 2 - font_height * 2;
8106 int ypos2 = SYSIZE / 2 - font_height * 1;
8107 unsigned int wait_frame_delay = 0;
8108 unsigned int wait_frame_delay_value = 2000;
8110 ResetDelayCounter(&wait_frame_delay);
8114 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8115 DrawTextSCentered(ypos2, font_nr, "configured!");
8117 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8123 DrawSetupScreen_Input();
8126 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8128 #define MARKER_BUTTON 1
8129 #define MARKER_AXIS_X 2
8130 #define MARKER_AXIS_Y 3
8132 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8134 static boolean bitmaps_initialized = FALSE;
8135 boolean screen_initialized = FALSE;
8136 static Bitmap *controller, *button, *axis_x, *axis_y;
8138 boolean success = TRUE;
8139 boolean done = FALSE, next = FALSE;
8141 int alpha = 200, alpha_step = -1;
8142 int alpha_ticks = 0;
8143 char mapping[4096], temp[256];
8144 int font_name = MENU_SETUP_FONT_TITLE;
8145 int font_info = MENU_SETUP_FONT_TEXT;
8146 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8147 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8148 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8149 int ystep_name = getMenuTextStep(spacing_name, font_name);
8150 int ystep_line = getMenuTextStep(spacing_line, font_info);
8151 int ystep_para = getMenuTextStep(spacing_para, font_info);
8159 int axis, button, hat, hat_value;
8162 *step, *prev_step, steps[] =
8164 { 356, 155, MARKER_BUTTON, "a", },
8165 { 396, 122, MARKER_BUTTON, "b", },
8166 { 320, 125, MARKER_BUTTON, "x", },
8167 { 358, 95, MARKER_BUTTON, "y", },
8168 { 162, 125, MARKER_BUTTON, "back", },
8169 { 216, 125, MARKER_BUTTON, "guide", },
8170 { 271, 125, MARKER_BUTTON, "start", },
8171 { 110, 200, MARKER_BUTTON, "dpleft", },
8172 { 146, 228, MARKER_BUTTON, "dpdown", },
8173 { 178, 200, MARKER_BUTTON, "dpright", },
8174 { 146, 172, MARKER_BUTTON, "dpup", },
8175 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8176 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8177 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8178 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8179 { 73, 141, MARKER_BUTTON, "leftstick", },
8180 { 282, 210, MARKER_BUTTON, "rightstick", },
8181 { 73, 141, MARKER_AXIS_X, "leftx", },
8182 { 73, 141, MARKER_AXIS_Y, "lefty", },
8183 { 282, 210, MARKER_AXIS_X, "rightx", },
8184 { 282, 210, MARKER_AXIS_Y, "righty", },
8187 unsigned int event_frame_delay = 0;
8188 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8190 ResetDelayCounter(&event_frame_delay);
8192 if (!bitmaps_initialized)
8194 controller = LoadCustomImage("joystick/controller.png");
8195 button = LoadCustomImage("joystick/button.png");
8196 axis_x = LoadCustomImage("joystick/axis_x.png");
8197 axis_y = LoadCustomImage("joystick/axis_y.png");
8199 bitmaps_initialized = TRUE;
8202 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8205 // print info about the joystick we are watching
8206 Debug("joystick", "watching joystick %d: (%s)",
8207 SDL_JoystickInstanceID(joystick), name);
8208 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8209 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8210 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8213 // initialize mapping with GUID and name
8214 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8216 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8217 temp, name, SDL_GetPlatform());
8219 // loop through all steps (buttons and axes), getting joystick events
8220 for (i = 0; i < SDL_arraysize(steps) && !done;)
8222 Bitmap *marker = button; // initialize with reliable default value
8225 strcpy(step->mapping, mapping);
8229 step->hat_value = -1;
8231 marker = (step->marker == MARKER_BUTTON ? button :
8232 step->marker == MARKER_AXIS_X ? axis_x :
8233 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8237 while (!done && !next)
8239 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8240 alpha_ticks = SDL_GetTicks();
8247 else if (alpha < 128)
8253 int controller_x = SX + (SXSIZE - controller->width) / 2;
8254 int controller_y = SY + ystep_line;
8256 int marker_x = controller_x + step->x;
8257 int marker_y = controller_y + step->y;
8259 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8260 int ystart2 = ystart1 + ystep_name + ystep_line;
8264 DrawTextSCentered(ystart1, font_name, name);
8266 DrawTextSCentered(ystart2, font_info,
8267 "Press buttons and move axes on");
8268 ystart2 += ystep_line;
8269 DrawTextSCentered(ystart2, font_info,
8270 "your controller when indicated.");
8271 ystart2 += ystep_line;
8272 DrawTextSCentered(ystart2, font_info,
8273 "(Your controller may look different.)");
8274 ystart2 += ystep_para;
8276 #if defined(PLATFORM_ANDROID)
8277 DrawTextSCentered(ystart2, font_info,
8278 "To correct a mistake,");
8279 ystart2 += ystep_line;
8280 DrawTextSCentered(ystart2, font_info,
8281 "press the 'back' button.");
8282 ystart2 += ystep_line;
8283 DrawTextSCentered(ystart2, font_info,
8284 "To skip a button or axis,");
8285 ystart2 += ystep_line;
8286 DrawTextSCentered(ystart2, font_info,
8287 "press the 'menu' button.");
8289 DrawTextSCentered(ystart2, font_info,
8290 "To correct a mistake,");
8291 ystart2 += ystep_line;
8292 DrawTextSCentered(ystart2, font_info,
8293 "press the 'backspace' key.");
8294 ystart2 += ystep_line;
8295 DrawTextSCentered(ystart2, font_info,
8296 "To skip a button or axis,");
8297 ystart2 += ystep_line;
8298 DrawTextSCentered(ystart2, font_info,
8299 "press the 'return' key.");
8300 ystart2 += ystep_line;
8301 DrawTextSCentered(ystart2, font_info,
8302 "To exit, press the 'escape' key.");
8305 BlitBitmapMasked(controller, drawto, 0, 0,
8306 controller->width, controller->height,
8307 controller_x, controller_y);
8309 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8310 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8312 BlitBitmapMasked(marker, drawto, 0, 0,
8313 marker->width, marker->height,
8314 marker_x, marker_y);
8316 if (!screen_initialized)
8317 FadeIn(REDRAW_FIELD);
8321 screen_initialized = TRUE;
8323 while (NextValidEvent(&event))
8327 case SDL_JOYAXISMOTION:
8328 if (event.jaxis.value > 20000 ||
8329 event.jaxis.value < -20000)
8331 for (j = 0; j < i; j++)
8332 if (steps[j].axis == event.jaxis.axis)
8337 if (step->marker != MARKER_AXIS_X &&
8338 step->marker != MARKER_AXIS_Y)
8341 step->axis = event.jaxis.axis;
8342 strcat(mapping, step->field);
8343 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8344 strcat(mapping, temp);
8352 case SDL_JOYHATMOTION:
8353 // ignore centering; we're probably just coming back
8354 // to the center from the previous item we set
8355 if (event.jhat.value == SDL_HAT_CENTERED)
8358 for (j = 0; j < i; j++)
8359 if (steps[j].hat == event.jhat.hat &&
8360 steps[j].hat_value == event.jhat.value)
8365 step->hat = event.jhat.hat;
8366 step->hat_value = event.jhat.value;
8367 strcat(mapping, step->field);
8368 snprintf(temp, sizeof(temp), ":h%u.%u,",
8369 event.jhat.hat, event.jhat.value );
8370 strcat(mapping, temp);
8377 case SDL_JOYBALLMOTION:
8380 case SDL_JOYBUTTONUP:
8381 for (j = 0; j < i; j++)
8382 if (steps[j].button == event.jbutton.button)
8387 step->button = event.jbutton.button;
8388 strcat(mapping, step->field);
8389 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8390 strcat(mapping, temp);
8397 case SDL_FINGERDOWN:
8398 case SDL_MOUSEBUTTONDOWN:
8406 if (event.key.keysym.sym == KSYM_BackSpace ||
8407 event.key.keysym.sym == KSYM_Back)
8419 prev_step = &steps[i - 1];
8420 strcpy(mapping, prev_step->mapping);
8427 if (event.key.keysym.sym == KSYM_space ||
8428 event.key.keysym.sym == KSYM_Return ||
8429 event.key.keysym.sym == KSYM_Menu)
8438 if (event.key.keysym.sym == KSYM_Escape)
8448 program.exit_function(0);
8455 // do not handle events for longer than standard frame delay period
8456 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8465 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8468 // activate mapping for this game
8469 SDL_GameControllerAddMapping(mapping);
8471 // save mapping to personal mappings
8472 SaveSetup_AddGameControllerMapping(mapping);
8475 // wait until the last pending event was removed from event queue
8476 while (NextValidEvent(&event));
8481 static int ConfigureJoystickMain(int player_nr)
8483 char *device_name = setup.input[player_nr].joy.device_name;
8484 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8485 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8486 int success = FALSE;
8489 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8490 return JOYSTICK_NOT_AVAILABLE;
8492 if (!joystick_active || !setup.input[player_nr].use_joystick)
8493 return JOYSTICK_NOT_AVAILABLE;
8496 FadeOut(REDRAW_FIELD);
8498 // close all joystick devices (potentially opened as game controllers)
8499 for (i = 0; i < SDL_NumJoysticks(); i++)
8500 SDLCloseJoystick(i);
8502 // open joystick device as plain joystick to configure as game controller
8503 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8505 // as the joystick was successfully opened before, this should not happen
8506 if (joystick == NULL)
8509 // create new game controller mapping (buttons and axes) for joystick device
8510 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8512 // close joystick (and maybe re-open as configured game controller later)
8513 SDL_JoystickClose(joystick);
8515 // re-open all joystick devices (potentially as game controllers)
8516 for (i = 0; i < SDL_NumJoysticks(); i++)
8519 // clear all joystick input actions for all joystick devices
8520 SDLClearJoystickState();
8522 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8525 void ConfigureJoystick(int player_nr)
8527 boolean state = ConfigureJoystickMain(player_nr);
8529 if (state != JOYSTICK_NOT_CONFIGURED)
8531 boolean success = (state == JOYSTICK_CONFIGURED);
8532 char message1[MAX_OUTPUT_LINESIZE + 1];
8533 char *message2 = (success ? "configured!" : "not available!");
8534 char *device_name = setup.input[player_nr].joy.device_name;
8535 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8536 int font_nr = FONT_TITLE_1;
8537 int font_height = getFontHeight(font_nr);
8538 int ypos1 = SYSIZE / 2 - font_height * 2;
8539 int ypos2 = SYSIZE / 2 - font_height * 1;
8540 unsigned int wait_frame_delay = 0;
8541 unsigned int wait_frame_delay_value = 2000;
8543 ResetDelayCounter(&wait_frame_delay);
8547 sprintf(message1, "Joystick %d", nr);
8549 DrawTextSCentered(ypos1, font_nr, message1);
8550 DrawTextSCentered(ypos2, font_nr, message2);
8552 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8558 DrawSetupScreen_Input();
8561 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8563 if (y < video.screen_height / 3)
8565 // remap touch gadgets to access upper part of the screen
8566 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8567 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8569 else if (y > 2 * video.screen_height / 3)
8571 // remap touch gadgets to access lower part of the screen
8572 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8573 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8577 static boolean ConfigureVirtualButtonsMain(void)
8579 static char *customize_step_text[] =
8588 char grid_button[] =
8590 CHAR_GRID_BUTTON_LEFT,
8591 CHAR_GRID_BUTTON_RIGHT,
8592 CHAR_GRID_BUTTON_UP,
8593 CHAR_GRID_BUTTON_DOWN,
8594 CHAR_GRID_BUTTON_SNAP,
8595 CHAR_GRID_BUTTON_DROP
8604 int font_nr = FONT_INPUT_1_ACTIVE;
8605 int font_height = getFontHeight(font_nr);
8606 int ypos1 = SYSIZE / 2 - font_height * 2;
8607 int ypos2 = SYSIZE / 2 - font_height * 1;
8608 boolean success = FALSE;
8609 boolean finished = FALSE;
8611 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8612 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8613 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8614 boolean set_grid_button = FALSE;
8615 int nr = GRID_ACTIVE_NR();
8618 for (x = 0; x < MAX_GRID_XSIZE; x++)
8619 for (y = 0; y < MAX_GRID_YSIZE; y++)
8620 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8622 overlay.grid_button_highlight = grid_button[step_nr];
8627 FadeOut(REDRAW_FIELD);
8631 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8632 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8633 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8635 FadeIn(REDRAW_FIELD);
8637 SetOverlayShowGrid(TRUE);
8639 // map gadgets for setup touch buttons menu screen
8640 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8646 while (NextValidEvent(&event))
8648 int action = ACTION_NONE;
8650 // ---------- handle events and set the resulting action ----------
8656 UserEvent *user = (UserEvent *)&event;
8657 int id = user->value1;
8659 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8660 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8661 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8662 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8667 case EVENT_KEYPRESS:
8669 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8671 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8672 key == KSYM_BackSpace ||
8673 key == KSYM_Back ? ACTION_BACK :
8674 key == KSYM_Return ||
8676 key == KSYM_space ? ACTION_NEXT :
8681 case EVENT_KEYRELEASE:
8682 key_joystick_mapping = 0;
8685 case EVENT_BUTTONPRESS:
8686 case EVENT_BUTTONRELEASE:
8688 ButtonEvent *button = (ButtonEvent *)&event;
8690 motion_status = FALSE;
8692 if (button->type == EVENT_BUTTONPRESS)
8693 button_status = button->button;
8695 button_status = MB_RELEASED;
8697 if (HandleGadgets(button->x, button->y, button_status))
8699 // do not handle this button event anymore
8703 button->x += video.screen_xoffset;
8704 button->y += video.screen_yoffset;
8706 x = button->x * overlay.grid_xsize / video.screen_width;
8707 y = button->y * overlay.grid_ysize / video.screen_height;
8709 if (button->type == EVENT_BUTTONPRESS)
8712 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8713 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8715 set_grid_button = TRUE;
8718 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8722 case EVENT_MOTIONNOTIFY:
8724 MotionEvent *motion = (MotionEvent *)&event;
8726 motion_status = TRUE;
8728 if (HandleGadgets(motion->x, motion->y, button_status))
8730 // do not handle this button event anymore
8734 motion->x += video.screen_xoffset;
8735 motion->y += video.screen_yoffset;
8737 x = motion->x * overlay.grid_xsize / video.screen_width;
8738 y = motion->y * overlay.grid_ysize / video.screen_height;
8740 set_grid_button = TRUE;
8742 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8746 case SDL_WINDOWEVENT:
8747 HandleWindowEvent((WindowEvent *) &event);
8749 // check if device has been rotated
8750 if (nr != GRID_ACTIVE_NR())
8752 nr = GRID_ACTIVE_NR();
8754 for (x = 0; x < MAX_GRID_XSIZE; x++)
8755 for (y = 0; y < MAX_GRID_YSIZE; y++)
8756 grid_button_old[x][y] = grid_button_tmp[x][y] =
8757 overlay.grid_button[x][y];
8762 case SDL_APP_WILLENTERBACKGROUND:
8763 case SDL_APP_DIDENTERBACKGROUND:
8764 case SDL_APP_WILLENTERFOREGROUND:
8765 case SDL_APP_DIDENTERFOREGROUND:
8766 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8770 HandleOtherEvents(&event);
8774 // ---------- perform action set by handling events ----------
8776 if (action == ACTION_ESCAPE)
8778 // abort and restore the old key bindings
8780 for (x = 0; x < MAX_GRID_XSIZE; x++)
8781 for (y = 0; y < MAX_GRID_YSIZE; y++)
8782 overlay.grid_button[x][y] = grid_button_old[x][y];
8784 FadeSkipNextFadeIn();
8788 else if (action == ACTION_BACK)
8790 // keep the configured key bindings and go to previous page
8796 FadeSkipNextFadeIn();
8801 else if (action == ACTION_NEXT)
8803 // keep the configured key bindings and go to next page
8807 // all virtual buttons configured
8815 if (action != ACTION_NONE && !finished)
8817 for (x = 0; x < MAX_GRID_XSIZE; x++)
8818 for (y = 0; y < MAX_GRID_YSIZE; y++)
8819 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8821 overlay.grid_button_highlight = grid_button[step_nr];
8823 // configure next virtual button
8827 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8828 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8829 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8832 if (set_grid_button)
8834 overlay.grid_button[x][y] =
8835 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8836 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8837 grid_button_tmp[x][y]);
8839 set_grid_button = FALSE;
8846 for (x = 0; x < MAX_GRID_XSIZE; x++)
8847 for (y = 0; y < MAX_GRID_YSIZE; y++)
8848 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8850 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8852 SetOverlayShowGrid(FALSE);
8857 void ConfigureVirtualButtons(void)
8859 boolean success = ConfigureVirtualButtonsMain();
8861 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8862 SCREEN_MASK_TOUCH2);
8866 int font_nr = FONT_TITLE_1;
8867 int font_height = getFontHeight(font_nr);
8868 int ypos1 = SYSIZE / 2 - font_height * 2;
8869 int ypos2 = SYSIZE / 2 - font_height * 1;
8870 unsigned int wait_frame_delay = 0;
8871 unsigned int wait_frame_delay_value = 2000;
8873 ResetDelayCounter(&wait_frame_delay);
8877 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8878 DrawTextSCentered(ypos2, font_nr, "configured!");
8880 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8887 void DrawSetupScreen(void)
8892 if (setup_mode == SETUP_MODE_INPUT)
8893 DrawSetupScreen_Input();
8894 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8895 DrawChooseTree(&game_speed_current);
8896 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8897 DrawChooseTree(&scroll_delay_current);
8898 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8899 DrawChooseTree(&snapshot_mode_current);
8900 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8901 DrawChooseTree(&window_size_current);
8902 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8903 DrawChooseTree(&scaling_type_current);
8904 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8905 DrawChooseTree(&rendering_mode_current);
8906 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8907 DrawChooseTree(&vsync_mode_current);
8908 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8909 DrawChooseTree(&artwork.gfx_current);
8910 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8911 DrawChooseTree(&artwork.snd_current);
8912 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8913 DrawChooseTree(&artwork.mus_current);
8914 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8915 DrawChooseTree(&volume_simple_current);
8916 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8917 DrawChooseTree(&volume_loops_current);
8918 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8919 DrawChooseTree(&volume_music_current);
8920 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8921 DrawChooseTree(&touch_control_current);
8922 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8923 DrawChooseTree(&move_distance_current);
8924 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8925 DrawChooseTree(&drop_distance_current);
8926 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8927 DrawChooseTree(&transparency_current);
8928 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8929 DrawChooseTree(&grid_size_current[0][0]);
8930 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8931 DrawChooseTree(&grid_size_current[0][1]);
8932 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8933 DrawChooseTree(&grid_size_current[1][0]);
8934 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8935 DrawChooseTree(&grid_size_current[1][1]);
8937 DrawSetupScreen_Generic();
8939 PlayMenuSoundsAndMusic();
8942 void RedrawSetupScreenAfterFullscreenToggle(void)
8944 if (setup_mode == SETUP_MODE_GRAPHICS ||
8945 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8947 // update list selection from "setup.window_scaling_percent"
8948 execSetupGraphics_setWindowSizes(TRUE);
8954 void RedrawSetupScreenAfterScreenRotation(int nr)
8958 if (setup_mode == SETUP_MODE_TOUCH)
8960 // update virtual button settings (depending on screen orientation)
8963 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8965 // save already configured virtual buttons
8966 for (x = 0; x < MAX_GRID_XSIZE; x++)
8967 for (y = 0; y < MAX_GRID_YSIZE; y++)
8968 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8972 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8974 if (setup_mode == SETUP_MODE_INPUT)
8975 HandleSetupScreen_Input(mx, my, dx, dy, button);
8976 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8977 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8978 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8979 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8980 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8981 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8982 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8983 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8984 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8985 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8986 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8987 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8988 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8989 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8990 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8991 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8992 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8993 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8994 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8995 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8996 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8997 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8998 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8999 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9000 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9001 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9002 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9003 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9004 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9005 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9006 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9007 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9008 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9009 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9010 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9011 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9012 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9013 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9014 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9015 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9016 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9017 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9019 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9022 void HandleGameActions(void)
9024 if (setup.ask_on_game_over)
9027 if (game.restart_game_message != NULL)
9029 RequestRestartGame(game.restart_game_message);
9034 if (game_status != GAME_MODE_PLAYING)
9037 GameActions(); // main game loop
9039 if (tape.auto_play && !tape.playing)
9040 AutoPlayTapes(); // continue automatically playing next tape
9044 // ---------- new screen button stuff --------------------------------------
9048 int gfx_unpressed, gfx_pressed;
9049 struct MenuPosInfo *pos;
9050 boolean *check_value;
9053 unsigned int event_mask;
9054 boolean is_touch_button;
9056 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9059 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9060 &menu.main.button.prev_level, NULL,
9061 SCREEN_CTRL_ID_PREV_LEVEL,
9063 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9064 FALSE, "previous level"
9067 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9068 &menu.main.button.next_level, NULL,
9069 SCREEN_CTRL_ID_NEXT_LEVEL,
9071 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9075 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9076 &menu.main.button.first_level, NULL,
9077 SCREEN_CTRL_ID_FIRST_LEVEL,
9080 FALSE, "first level"
9083 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9084 &menu.main.button.last_level, NULL,
9085 SCREEN_CTRL_ID_LAST_LEVEL,
9091 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9092 &menu.main.button.level_number, NULL,
9093 SCREEN_CTRL_ID_LEVEL_NUMBER,
9096 FALSE, "level number"
9099 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9100 &menu.setup.button.prev_player, NULL,
9101 SCREEN_CTRL_ID_PREV_PLAYER,
9103 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9104 FALSE, "previous player"
9107 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9108 &menu.setup.button.next_player, NULL,
9109 SCREEN_CTRL_ID_NEXT_PLAYER,
9111 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9112 FALSE, "next player"
9115 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9116 &menu.main.button.insert_solution, NULL,
9117 SCREEN_CTRL_ID_INSERT_SOLUTION,
9118 SCREEN_MASK_MAIN_HAS_SOLUTION,
9120 FALSE, "insert solution tape"
9123 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9124 &menu.main.button.play_solution, NULL,
9125 SCREEN_CTRL_ID_PLAY_SOLUTION,
9126 SCREEN_MASK_MAIN_HAS_SOLUTION,
9128 FALSE, "play solution tape"
9131 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9132 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9133 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9135 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9136 FALSE, "switch ECS/AGA chipset"
9139 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9140 &menu.setup.button.touch_back, NULL,
9141 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9144 TRUE, "previous page"
9147 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9148 &menu.setup.button.touch_next, NULL,
9149 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9155 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9156 &menu.setup.button.touch_back2, NULL,
9157 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9160 TRUE, "previous page"
9163 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9164 &menu.setup.button.touch_next2, NULL,
9165 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9174 int gfx_unpressed, gfx_pressed;
9178 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9181 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9182 -1, -1, // these values are not constant, but can change at runtime
9183 SCREEN_CTRL_ID_SCROLL_UP,
9187 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9188 -1, -1, // these values are not constant, but can change at runtime
9189 SCREEN_CTRL_ID_SCROLL_DOWN,
9196 int gfx_unpressed, gfx_pressed;
9202 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9205 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9206 -1, -1, // these values are not constant, but can change at runtime
9207 -1, -1, // these values are not constant, but can change at runtime
9208 GD_TYPE_SCROLLBAR_VERTICAL,
9209 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9210 "scroll level series vertically"
9222 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9225 IMG_SETUP_INPUT_TEXT,
9226 SCREEN_CTRL_ID_NETWORK_SERVER,
9227 -1, -1, // these values are not constant, but can change at runtime
9228 MAX_SETUP_TEXT_INPUT_LEN,
9229 network_server_hostname,
9230 "Network Server Hostname / IP"
9234 static void CreateScreenMenubuttons(void)
9236 struct GadgetInfo *gi;
9237 unsigned int event_mask;
9240 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9242 struct MenuPosInfo *pos = menubutton_info[i].pos;
9243 boolean is_touch_button = menubutton_info[i].is_touch_button;
9244 boolean is_check_button = menubutton_info[i].check_value != NULL;
9245 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9246 int gfx_unpressed, gfx_pressed;
9247 int x, y, width, height;
9248 int gd_x1, gd_x2, gd_y1, gd_y2;
9249 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9250 int id = menubutton_info[i].gadget_id;
9251 int type = GD_TYPE_NORMAL_BUTTON;
9252 boolean checked = FALSE;
9254 event_mask = menubutton_info[i].event_mask;
9256 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9257 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9259 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9260 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9262 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9263 gfx_pressed = menubutton_info[i].gfx_pressed;
9264 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9265 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9266 gd_x1 = graphic_info[gfx_unpressed].src_x;
9267 gd_y1 = graphic_info[gfx_unpressed].src_y;
9268 gd_x2 = graphic_info[gfx_pressed].src_x;
9269 gd_y2 = graphic_info[gfx_pressed].src_y;
9275 if (is_touch_button)
9277 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9278 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9281 if (is_check_button)
9283 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9284 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9285 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9286 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9288 type = GD_TYPE_CHECK_BUTTON;
9289 checked = *menubutton_info[i].check_value;
9292 gi = CreateGadget(GDI_CUSTOM_ID, id,
9293 GDI_CUSTOM_TYPE_ID, i,
9294 GDI_IMAGE_ID, gfx_unpressed,
9295 GDI_INFO_TEXT, menubutton_info[i].infotext,
9301 GDI_STATE, GD_BUTTON_UNPRESSED,
9302 GDI_CHECKED, checked,
9303 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9304 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9305 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9306 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9307 GDI_DIRECT_DRAW, FALSE,
9308 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9309 GDI_EVENT_MASK, event_mask,
9310 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9314 Fail("cannot create gadget");
9316 screen_gadget[id] = gi;
9320 static void CreateScreenScrollbuttons(void)
9322 struct GadgetInfo *gi;
9323 unsigned int event_mask;
9326 // these values are not constant, but can change at runtime
9327 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9328 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9329 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9330 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9332 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9334 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9335 int gfx_unpressed, gfx_pressed;
9336 int x, y, width, height;
9337 int gd_x1, gd_x2, gd_y1, gd_y2;
9338 int id = scrollbutton_info[i].gadget_id;
9340 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9342 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9343 y = mSY + scrollbutton_info[i].y;
9344 width = SC_SCROLLBUTTON_XSIZE;
9345 height = SC_SCROLLBUTTON_YSIZE;
9347 // correct scrollbar position if placed outside menu (playfield) area
9348 if (x > SX + SC_SCROLL_UP_XPOS)
9349 x = SX + SC_SCROLL_UP_XPOS;
9351 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9352 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9353 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9355 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9356 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9357 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9358 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9359 gd_x1 = graphic_info[gfx_unpressed].src_x;
9360 gd_y1 = graphic_info[gfx_unpressed].src_y;
9361 gd_x2 = graphic_info[gfx_pressed].src_x;
9362 gd_y2 = graphic_info[gfx_pressed].src_y;
9364 gi = CreateGadget(GDI_CUSTOM_ID, id,
9365 GDI_CUSTOM_TYPE_ID, i,
9366 GDI_IMAGE_ID, gfx_unpressed,
9367 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9372 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9373 GDI_STATE, GD_BUTTON_UNPRESSED,
9374 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9375 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9376 GDI_DIRECT_DRAW, FALSE,
9377 GDI_EVENT_MASK, event_mask,
9378 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9382 Fail("cannot create gadget");
9384 screen_gadget[id] = gi;
9388 static void CreateScreenScrollbars(void)
9392 // these values are not constant, but can change at runtime
9393 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9394 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9395 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9396 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9398 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9400 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9401 int gfx_unpressed, gfx_pressed;
9402 int x, y, width, height;
9403 int gd_x1, gd_x2, gd_y1, gd_y2;
9404 struct GadgetInfo *gi;
9405 int items_max, items_visible, item_position;
9406 unsigned int event_mask;
9407 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9408 int id = scrollbar_info[i].gadget_id;
9410 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9412 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9413 y = mSY + scrollbar_info[i].y;
9414 width = scrollbar_info[i].width;
9415 height = scrollbar_info[i].height;
9417 // correct scrollbar position if placed outside menu (playfield) area
9418 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9419 x = SX + SC_SCROLL_VERTICAL_XPOS;
9421 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9422 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9424 items_max = num_page_entries;
9425 items_visible = num_page_entries;
9428 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9429 gfx_pressed = scrollbar_info[i].gfx_pressed;
9430 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9431 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9432 gd_x1 = graphic_info[gfx_unpressed].src_x;
9433 gd_y1 = graphic_info[gfx_unpressed].src_y;
9434 gd_x2 = graphic_info[gfx_pressed].src_x;
9435 gd_y2 = graphic_info[gfx_pressed].src_y;
9437 gi = CreateGadget(GDI_CUSTOM_ID, id,
9438 GDI_CUSTOM_TYPE_ID, i,
9439 GDI_IMAGE_ID, gfx_unpressed,
9440 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9445 GDI_TYPE, scrollbar_info[i].type,
9446 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9447 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9448 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9449 GDI_WHEEL_AREA_X, SX,
9450 GDI_WHEEL_AREA_Y, SY,
9451 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9452 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9453 GDI_STATE, GD_BUTTON_UNPRESSED,
9454 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9455 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9456 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9457 GDI_DIRECT_DRAW, FALSE,
9458 GDI_EVENT_MASK, event_mask,
9459 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9463 Fail("cannot create gadget");
9465 screen_gadget[id] = gi;
9469 static void CreateScreenTextInputGadgets(void)
9473 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9475 int graphic = textinput_info[i].graphic;
9476 struct GraphicInfo *gd = &graphic_info[graphic];
9477 int gd_x1 = gd->src_x;
9478 int gd_y1 = gd->src_y;
9479 int gd_x2 = gd->src_x + gd->active_xoffset;
9480 int gd_y2 = gd->src_y + gd->active_yoffset;
9481 struct GadgetInfo *gi;
9482 unsigned int event_mask;
9483 int id = textinput_info[i].gadget_id;
9484 int x = textinput_info[i].x;
9485 int y = textinput_info[i].y;
9487 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9489 gi = CreateGadget(GDI_CUSTOM_ID, id,
9490 GDI_CUSTOM_TYPE_ID, i,
9491 GDI_INFO_TEXT, textinput_info[i].infotext,
9494 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9495 GDI_TEXT_VALUE, textinput_info[i].value,
9496 GDI_TEXT_SIZE, textinput_info[i].size,
9497 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9498 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9499 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9500 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9501 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9502 GDI_DESIGN_WIDTH, gd->width,
9503 GDI_EVENT_MASK, event_mask,
9504 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9505 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9509 Fail("cannot create gadget");
9511 screen_gadget[id] = gi;
9515 void CreateScreenGadgets(void)
9517 CreateScreenMenubuttons();
9519 CreateScreenScrollbuttons();
9520 CreateScreenScrollbars();
9522 CreateScreenTextInputGadgets();
9525 void FreeScreenGadgets(void)
9529 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9530 FreeGadget(screen_gadget[i]);
9533 static void MapScreenMenuGadgets(int screen_mask)
9537 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9538 if (screen_mask & menubutton_info[i].screen_mask)
9539 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9542 static void UnmapScreenMenuGadgets(int screen_mask)
9546 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9548 if (screen_mask & menubutton_info[i].screen_mask)
9550 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9552 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9553 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9554 screen_gadget[menubutton_info[i].gadget_id]->y,
9555 screen_gadget[menubutton_info[i].gadget_id]->width,
9556 screen_gadget[menubutton_info[i].gadget_id]->height);
9561 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9564 MapScreenMenuGadgets(screen_mask);
9566 UnmapScreenMenuGadgets(screen_mask);
9569 static void MapScreenGadgets(int num_entries)
9573 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9576 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9577 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9579 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9580 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9583 static void MapScreenTreeGadgets(TreeInfo *ti)
9585 MapScreenGadgets(numTreeInfoInGroup(ti));
9588 static void HandleScreenGadgets(struct GadgetInfo *gi)
9590 int id = gi->custom_id;
9591 int button = gi->event.button;
9592 int step = (button == MB_LEFTBUTTON ? 1 :
9593 button == MB_MIDDLEBUTTON ? 5 :
9594 button == MB_RIGHTBUTTON ? 10 : 1);
9598 case SCREEN_CTRL_ID_PREV_LEVEL:
9599 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9602 case SCREEN_CTRL_ID_NEXT_LEVEL:
9603 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9606 case SCREEN_CTRL_ID_FIRST_LEVEL:
9607 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9610 case SCREEN_CTRL_ID_LAST_LEVEL:
9611 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9614 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9615 CloseDoor(DOOR_CLOSE_2);
9616 SetGameStatus(GAME_MODE_LEVELNR);
9617 DrawChooseLevelNr();
9620 case SCREEN_CTRL_ID_PREV_PLAYER:
9621 HandleSetupScreen_Input_Player(step, -1);
9624 case SCREEN_CTRL_ID_NEXT_PLAYER:
9625 HandleSetupScreen_Input_Player(step, +1);
9628 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9629 InsertSolutionTape();
9632 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9636 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9637 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9641 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9642 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9643 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9644 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9645 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9648 case SCREEN_CTRL_ID_SCROLL_UP:
9649 if (game_status == GAME_MODE_NAMES)
9650 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9651 else if (game_status == GAME_MODE_LEVELS)
9652 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9653 else if (game_status == GAME_MODE_LEVELNR)
9654 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9655 else if (game_status == GAME_MODE_SETUP)
9656 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9657 else if (game_status == GAME_MODE_INFO)
9658 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9661 case SCREEN_CTRL_ID_SCROLL_DOWN:
9662 if (game_status == GAME_MODE_NAMES)
9663 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9664 else if (game_status == GAME_MODE_LEVELS)
9665 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9666 else if (game_status == GAME_MODE_LEVELNR)
9667 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9668 else if (game_status == GAME_MODE_SETUP)
9669 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9670 else if (game_status == GAME_MODE_INFO)
9671 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9674 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9675 if (game_status == GAME_MODE_NAMES)
9676 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9677 else if (game_status == GAME_MODE_LEVELS)
9678 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9679 else if (game_status == GAME_MODE_LEVELNR)
9680 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9681 else if (game_status == GAME_MODE_SETUP)
9682 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9683 else if (game_status == GAME_MODE_INFO)
9684 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9687 case SCREEN_CTRL_ID_NETWORK_SERVER:
9689 if (!strEqual(gi->textinput.value, ""))
9691 setString(&setup.network_server_hostname, gi->textinput.value);
9693 network.server_host = setup.network_server_hostname;
9697 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9699 network.server_host = NULL;
9702 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9703 network.server_host = NULL;
9705 execSetupGame_setNetworkServerText();
9717 void DumpScreenIdentifiers(void)
9721 Print("Active screen elements on current screen:\n");
9723 for (i = 0; main_controls[i].nr != -1; i++)
9725 struct MainControlInfo *mci = &main_controls[i];
9727 if (mci->button_graphic != -1)
9729 char *token = getTokenFromImageID(mci->button_graphic);
9731 Print("- '%s'\n", token);
9738 boolean DoScreenAction(int image_id)
9742 if (game_status != GAME_MODE_MAIN)
9745 for (i = 0; main_controls[i].nr != -1; i++)
9747 struct MainControlInfo *mci = &main_controls[i];
9748 struct MenuPosInfo *pos = mci->pos_button;
9750 if (mci->button_graphic == image_id)
9752 int x = mSX + pos->x;
9753 int y = mSY + pos->y;
9755 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9764 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9766 // get tree info node of newly added level or artwork set
9767 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9768 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9770 if (tree_node_new == NULL) // should not happen
9773 // if request dialog is active, do nothing
9774 if (game.request_active)
9777 if (game_status == GAME_MODE_MAIN &&
9778 tree_type == TREE_TYPE_LEVEL_DIR)
9780 // when adding new level set in main menu, select it as current level set
9782 // change current level set to newly added level set from zip file
9783 leveldir_current = tree_node_new;
9785 // change current level number to first level of newly added level set
9786 level_nr = leveldir_current->first_level;
9788 // redraw screen to reflect changed level set
9791 // save this level set and level number as last selected level set
9792 SaveLevelSetup_LastSeries();
9793 SaveLevelSetup_SeriesInfo();
9795 else if (game_status == GAME_MODE_LEVELS &&
9796 tree_type == TREE_TYPE_LEVEL_DIR)
9798 // when adding new level set in level set menu, set cursor and update screen
9800 leveldir_current = tree_node_new;
9802 DrawChooseTree(&leveldir_current);
9804 else if (game_status == GAME_MODE_SETUP)
9806 // when adding new artwork set in setup menu, set cursor and update screen
9808 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9809 tree_type == TREE_TYPE_GRAPHICS_DIR)
9811 artwork.gfx_current = tree_node_new;
9813 DrawChooseTree(&artwork.gfx_current);
9815 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9816 tree_type == TREE_TYPE_SOUNDS_DIR)
9818 artwork.snd_current = tree_node_new;
9820 DrawChooseTree(&artwork.snd_current);
9822 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9823 tree_type == TREE_TYPE_MUSIC_DIR)
9825 artwork.mus_current = tree_node_new;
9827 DrawChooseTree(&artwork.mus_current);