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_SelectLevel(int step, int direction,
1961 int selected_level_nr)
1963 int old_level_nr = level_nr;
1966 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1967 new_level_nr = selected_level_nr;
1969 new_level_nr = old_level_nr + step * direction;
1971 if (new_level_nr < leveldir_current->first_level)
1972 new_level_nr = leveldir_current->first_level;
1973 if (new_level_nr > leveldir_current->last_level)
1974 new_level_nr = leveldir_current->last_level;
1976 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1978 // skipping levels is only allowed when trying to skip single level
1979 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1980 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1982 leveldir_current->handicap_level++;
1983 SaveLevelSetup_SeriesInfo();
1986 new_level_nr = leveldir_current->handicap_level;
1989 if (new_level_nr != old_level_nr)
1991 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1993 PlaySound(SND_MENU_ITEM_SELECTING);
1995 level_nr = new_level_nr;
1997 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1998 int2str(level_nr, menu.main.text.level_number.size),
1999 mci->pos_text->font);
2001 LoadLevel(level_nr);
2002 DrawPreviewLevelInitial();
2006 DrawCompleteVideoDisplay();
2008 SaveLevelSetup_SeriesInfo();
2010 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2012 // force redraw of playfield area (may be reset at this point)
2013 redraw_mask |= REDRAW_FIELD;
2017 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2019 static int choice = MAIN_CONTROL_GAME;
2020 static boolean button_pressed_last = FALSE;
2021 boolean button_pressed = FALSE;
2023 int i = 0; // needed to prevent compiler warning due to bad code below
2025 if (button == MB_MENU_INITIALIZE)
2027 DrawCursorAndText_Main(choice, TRUE, FALSE);
2032 if (mx || my) // mouse input
2036 for (i = 0; main_controls[i].nr != -1; i++)
2038 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2039 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2040 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2042 pos = main_controls[i].nr;
2048 // check if level preview was clicked
2049 if (insidePreviewRect(&preview, mx - SX, my - SY))
2050 pos = MAIN_CONTROL_GAME;
2052 // handle pressed/unpressed state for active/inactive menu buttons
2053 // (if pos != -1, "i" contains index position corresponding to "pos")
2055 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2056 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2057 button_pressed = TRUE;
2059 if (button_pressed != button_pressed_last)
2061 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2064 PlaySound(SND_MENU_BUTTON_PRESSING);
2066 PlaySound(SND_MENU_BUTTON_RELEASING);
2069 else if (dx || dy) // keyboard input
2071 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2072 choice == MAIN_CONTROL_SETUP))
2073 button = MB_MENU_CHOICE;
2078 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2080 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2082 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2084 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2086 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2088 CloseDoor(DOOR_CLOSE_2);
2090 SetGameStatus(GAME_MODE_LEVELNR);
2092 DrawChooseLevelNr();
2094 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2100 PlaySound(SND_MENU_ITEM_ACTIVATING);
2102 DrawCursorAndText_Main(choice, FALSE, FALSE);
2103 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2109 if (choice != MAIN_CONTROL_INFO &&
2110 choice != MAIN_CONTROL_SETUP)
2111 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2116 PlaySound(SND_MENU_ITEM_SELECTING);
2118 if (pos == MAIN_CONTROL_NAME)
2121 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2123 // special case: menu text "name/team" clicked -- toggle team mode
2124 setup.team_mode = !setup.team_mode;
2126 InitializeMainControls();
2127 DrawCursorAndText_Main(choice, TRUE, FALSE);
2129 DrawPreviewPlayers();
2133 if (setup.multiple_users)
2135 CloseDoor(DOOR_CLOSE_2);
2137 SetGameStatus(GAME_MODE_NAMES);
2139 DrawChoosePlayerName();
2143 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2149 else if (pos == MAIN_CONTROL_LEVELS)
2153 CloseDoor(DOOR_CLOSE_2);
2155 SetGameStatus(GAME_MODE_LEVELS);
2157 SaveLevelSetup_LastSeries();
2158 SaveLevelSetup_SeriesInfo();
2160 // restore level set if chosen from "last played level set" menu
2161 RestoreLastPlayedLevels(&leveldir_current);
2163 if (setup.internal.choose_from_top_leveldir)
2166 DrawChooseLevelSet();
2169 else if (pos == MAIN_CONTROL_SCORES)
2171 CloseDoor(DOOR_CLOSE_2);
2173 SetGameStatus(GAME_MODE_SCORES);
2175 DrawHallOfFame(level_nr);
2177 else if (pos == MAIN_CONTROL_EDITOR)
2179 if (leveldir_current->readonly &&
2180 setup.editor.show_read_only_warning)
2181 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2183 CloseDoor(DOOR_CLOSE_ALL);
2185 SetGameStatus(GAME_MODE_EDITOR);
2187 FadeSetEnterScreen();
2191 else if (pos == MAIN_CONTROL_INFO)
2193 CloseDoor(DOOR_CLOSE_2);
2195 SetGameStatus(GAME_MODE_INFO);
2197 info_mode = INFO_MODE_MAIN;
2201 else if (pos == MAIN_CONTROL_GAME)
2203 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2205 else if (pos == MAIN_CONTROL_SETUP)
2207 CloseDoor(DOOR_CLOSE_2);
2209 SetGameStatus(GAME_MODE_SETUP);
2211 setup_mode = SETUP_MODE_MAIN;
2215 else if (pos == MAIN_CONTROL_QUIT)
2217 SaveLevelSetup_LastSeries();
2218 SaveLevelSetup_SeriesInfo();
2220 if (!setup.ask_on_quit_program ||
2221 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2222 SetGameStatus(GAME_MODE_QUIT);
2227 button_pressed_last = button_pressed;
2231 // ============================================================================
2232 // info screen functions
2233 // ============================================================================
2235 static struct TokenInfo *info_info;
2236 static int num_info_info; // number of info entries shown on screen
2237 static int max_info_info; // total number of info entries in list
2239 static void execInfoTitleScreen(void)
2241 info_mode = INFO_MODE_TITLE;
2246 static void execInfoElements(void)
2248 info_mode = INFO_MODE_ELEMENTS;
2253 static void execInfoMusic(void)
2255 info_mode = INFO_MODE_MUSIC;
2260 static void execInfoCredits(void)
2262 info_mode = INFO_MODE_CREDITS;
2267 static void execInfoProgram(void)
2269 info_mode = INFO_MODE_PROGRAM;
2274 static void execInfoVersion(void)
2276 info_mode = INFO_MODE_VERSION;
2281 static void execInfoLevelSet(void)
2283 info_mode = INFO_MODE_LEVELSET;
2288 static void execExitInfo(void)
2290 SetGameStatus(GAME_MODE_MAIN);
2295 static struct TokenInfo info_info_main[] =
2297 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2298 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2299 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2300 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2301 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2302 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2303 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2304 { TYPE_EMPTY, NULL, "" },
2305 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2310 static int getMenuTextFont(int type)
2312 if (type & (TYPE_SWITCH |
2326 static struct TokenInfo *setup_info;
2327 static struct TokenInfo setup_info_input[];
2329 static struct TokenInfo *menu_info;
2331 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2332 int screen_pos, int menu_info_pos_raw,
2335 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2336 struct TokenInfo *ti = &token_info[pos];
2337 int xpos = MENU_SCREEN_START_XPOS;
2338 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2339 int font_nr = getMenuTextFont(ti->type);
2341 if (setup_mode == SETUP_MODE_INPUT)
2342 font_nr = FONT_MENU_1;
2345 font_nr = FONT_ACTIVE(font_nr);
2347 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2349 if (ti->type & ~TYPE_SKIP_ENTRY)
2350 drawCursor(screen_pos, active);
2353 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2356 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2359 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2362 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2365 static char *window_size_text;
2366 static char *scaling_type_text;
2367 static char *network_server_text;
2369 static void drawSetupValue(int, int);
2371 static void drawMenuInfoList(int first_entry, int num_page_entries,
2372 int max_page_entries)
2376 if (first_entry + num_page_entries > max_page_entries)
2379 clearMenuListArea();
2381 for (i = 0; i < num_page_entries; i++)
2383 int menu_info_pos = first_entry + i;
2384 struct TokenInfo *si = &menu_info[menu_info_pos];
2385 void *value_ptr = si->value;
2387 // set some entries to "unchangeable" according to other variables
2388 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2389 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2390 (value_ptr == &setup.sound_music && !audio.music_available) ||
2391 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2392 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2393 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2394 si->type |= TYPE_GHOSTED;
2396 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2397 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2398 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2399 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2400 else if (si->type & ~TYPE_SKIP_ENTRY)
2401 initCursor(i, IMG_MENU_BUTTON);
2403 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2405 if (si->type & TYPE_STRING)
2409 if (value_ptr == &network_server_text)
2410 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2412 if (gadget_id != -1)
2414 struct GadgetInfo *gi = screen_gadget[gadget_id];
2415 int xpos = MENU_SCREEN_START_XPOS;
2416 int ypos = MENU_SCREEN_START_YPOS + i;
2417 int x = mSX + xpos * 32;
2418 int y = mSY + ypos * 32;
2420 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2424 if (si->type & TYPE_VALUE &&
2425 menu_info == setup_info)
2426 drawSetupValue(i, menu_info_pos);
2430 static void DrawInfoScreen_Main(void)
2432 int fade_mask = REDRAW_FIELD;
2435 if (redraw_mask & REDRAW_ALL)
2436 fade_mask = REDRAW_ALL;
2439 fade_mask = REDRAW_ALL;
2442 FadeMenuSoundsAndMusic();
2444 FreeScreenGadgets();
2445 CreateScreenGadgets();
2447 // (needed after displaying title screens which disable auto repeat)
2448 KeyboardAutoRepeatOn();
2450 FadeSetLeaveScreen();
2454 // needed if different viewport properties defined for info screen
2455 ChangeViewportPropertiesIfNeeded();
2457 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2461 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2463 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2465 info_info = info_info_main;
2467 // determine maximal number of info entries that can be displayed on screen
2469 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2472 // determine maximal number of info entries available for menu of info screen
2474 for (i = 0; info_info[i].type != 0; i++)
2477 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2479 MapScreenGadgets(max_info_info);
2481 PlayMenuSoundsAndMusic();
2483 DrawMaskedBorder(fade_mask);
2488 static void changeSetupValue(int, int, int);
2490 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2491 int mode, int num_page_entries,
2492 int max_page_entries)
2494 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2495 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2496 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2497 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2498 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2499 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2500 int *num_page_entries_last = num_page_entries_all_last[game_status];
2501 int *choice_store = choice_stores[game_status];
2502 int *first_entry_store = first_entry_stores[game_status];
2503 int choice = choice_store[mode]; // starts with 0
2504 int first_entry = first_entry_store[mode]; // starts with 0
2506 int y = choice - first_entry;
2508 boolean position_set_by_scrollbar = (dx == 999);
2509 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2512 if (button == MB_MENU_INITIALIZE)
2514 // check if number of menu page entries has changed (may happen by change
2515 // of custom artwork definition value for 'list_size' for this menu screen)
2516 // (in this case, the last menu position most probably has to be corrected)
2517 if (num_page_entries != num_page_entries_last[mode])
2519 choice_store[mode] = first_entry_store[mode] = 0;
2521 choice = first_entry = 0;
2524 num_page_entries_last[mode] = num_page_entries;
2527 // advance to first valid menu entry
2528 while (choice < num_page_entries &&
2529 menu_info[choice].type & TYPE_SKIP_ENTRY)
2532 if (position_set_by_scrollbar)
2533 first_entry = first_entry_store[mode] = dy;
2535 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2536 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2538 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2540 if (choice < first_entry)
2542 choice = first_entry;
2544 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2547 else if (choice > first_entry + num_page_entries - 1)
2549 choice = first_entry + num_page_entries - 1;
2551 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2555 choice_store[mode] = choice;
2557 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2561 else if (button == MB_MENU_LEAVE)
2563 PlaySound(SND_MENU_ITEM_SELECTING);
2565 for (i = 0; i < max_page_entries; i++)
2567 if (menu_info[i].type & TYPE_LEAVE_MENU)
2569 void (*menu_callback_function)(void) = menu_info[i].value;
2573 menu_callback_function();
2575 break; // absolutely needed because function changes 'menu_info'!
2582 if (mx || my) // mouse input
2584 x = (mx - mSX) / 32;
2585 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2587 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2589 // move cursor instead of scrolling when already at start/end of list
2590 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2592 else if (dy == +1 * SCROLL_LINE &&
2593 first_entry + num_page_entries == max_page_entries)
2596 // handle scrolling screen one line or page
2598 y + dy > num_page_entries - 1)
2600 boolean redraw = FALSE;
2602 if (ABS(dy) == SCROLL_PAGE)
2603 step = num_page_entries - 1;
2605 if (dy < 0 && first_entry > 0)
2607 // scroll page/line up
2609 first_entry -= step;
2610 if (first_entry < 0)
2615 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2617 // scroll page/line down
2619 first_entry += step;
2620 if (first_entry + num_page_entries > max_page_entries)
2621 first_entry = MAX(0, max_page_entries - num_page_entries);
2628 choice += first_entry - first_entry_store[mode];
2630 if (choice < first_entry)
2632 choice = first_entry;
2634 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2637 else if (choice > first_entry + num_page_entries - 1)
2639 choice = first_entry + num_page_entries - 1;
2641 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2644 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2648 if (choice < first_entry ||
2649 choice > first_entry + num_page_entries - 1)
2650 first_entry += SIGN(dy);
2653 first_entry_store[mode] = first_entry;
2654 choice_store[mode] = choice;
2656 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2658 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2660 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2661 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2669 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2671 if (menu_info[choice].type & menu_navigation_type ||
2672 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2673 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2674 menu_info[choice].type & TYPE_PLAYER)
2675 button = MB_MENU_CHOICE;
2680 // jump to next non-empty menu entry (up or down)
2681 while (first_entry + y > 0 &&
2682 first_entry + y < max_page_entries - 1 &&
2683 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2686 if (!IN_VIS_MENU(x, y))
2688 choice += y - y_old;
2690 if (choice < first_entry)
2691 first_entry = choice;
2692 else if (choice > first_entry + num_page_entries - 1)
2693 first_entry = choice - num_page_entries + 1;
2695 if (first_entry >= 0 &&
2696 first_entry + num_page_entries <= max_page_entries)
2698 first_entry_store[mode] = first_entry;
2700 if (choice < first_entry)
2701 choice = first_entry;
2702 else if (choice > first_entry + num_page_entries - 1)
2703 choice = first_entry + num_page_entries - 1;
2705 choice_store[mode] = choice;
2707 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2709 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2711 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2712 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2719 if (!anyScrollbarGadgetActive() &&
2720 IN_VIS_MENU(x, y) &&
2721 mx < mx_right_border &&
2722 y >= 0 && y < num_page_entries)
2726 if (first_entry + y != choice &&
2727 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2729 PlaySound(SND_MENU_ITEM_ACTIVATING);
2731 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2732 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2734 choice = choice_store[mode] = first_entry + y;
2738 PlaySound(SND_MENU_ITEM_SELECTING);
2740 for (i = 0; menu_info[i].type != 0; i++)
2742 if (menu_info[i].type & TYPE_LEAVE_MENU)
2744 void (*menu_callback_function)(void) = menu_info[i].value;
2748 menu_callback_function();
2750 // absolutely needed because function changes 'menu_info'!
2758 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2760 PlaySound(SND_MENU_ITEM_SELECTING);
2762 // when selecting key headline, execute function for key value change
2763 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2764 menu_info[first_entry + y + 1].type & TYPE_KEY)
2767 // when selecting string value, execute function for list selection
2768 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2769 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2772 // when selecting string value, execute function for text input gadget
2773 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2774 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2777 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2779 void (*menu_callback_function)(void) =
2780 menu_info[first_entry + y].value;
2782 FadeSetFromType(menu_info[first_entry + y].type);
2784 menu_callback_function();
2786 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2788 void (*gadget_callback_function)(void) =
2789 menu_info[first_entry + y].value;
2791 gadget_callback_function();
2793 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2794 menu_info == setup_info)
2796 changeSetupValue(y, first_entry + y, dx);
2802 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2804 menu_info = info_info;
2806 HandleMenuScreen(mx, my, dx, dy, button,
2807 info_mode, num_info_info, max_info_info);
2810 static int getMenuFontSpacing(int spacing_height, int font_nr)
2812 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2814 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2818 static int getMenuTextSpacing(int spacing_height, int font_nr)
2820 return (getMenuFontSpacing(spacing_height, font_nr) +
2821 EXTRA_SPACING(game_status));
2824 static int getMenuTextStep(int spacing_height, int font_nr)
2826 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2829 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2831 int font_title = MENU_INFO_FONT_TITLE;
2832 int font_error = FONT_TEXT_2;
2833 int font_foot = MENU_INFO_FONT_FOOT;
2834 int spacing_title = menu.headline1_spacing_info[info_mode];
2835 int ystep_title = getMenuTextStep(spacing_title, font_title);
2836 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2837 int ystart2 = ystart1 + ystep_title;
2838 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2840 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2842 FadeOut(REDRAW_FIELD);
2847 DrawTextSCentered(ystart1, font_title, text_title);
2848 DrawTextSCentered(ystart2, font_error, text_error);
2850 DrawTextSCentered(ybottom, font_foot,
2851 "Press any key or button for info menu");
2853 FadeIn(REDRAW_FIELD);
2856 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2858 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2859 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2860 int font_title = MENU_INFO_FONT_TITLE;
2861 int font_foot = MENU_INFO_FONT_FOOT;
2862 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2863 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2864 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2865 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2866 int ystep = MENU_SCREEN_INFO_YSTEP;
2867 int element, action, direction;
2875 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2876 infoscreen_step[i] = infoscreen_frame[i] = 0;
2881 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2883 DrawTextSCentered(ybottom, font_foot,
2884 "Press any key or button for next page");
2890 while (helpanim_info[j].element != HELPANIM_LIST_END)
2892 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2897 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2906 j += infoscreen_step[i - start];
2908 element = helpanim_info[j].element;
2909 action = helpanim_info[j].action;
2910 direction = helpanim_info[j].direction;
2913 element = EL_UNKNOWN;
2915 if (action != -1 && direction != -1)
2916 graphic = el_act_dir2img(element, action, direction);
2917 else if (action != -1)
2918 graphic = el_act2img(element, action);
2919 else if (direction != -1)
2920 graphic = el_dir2img(element, direction);
2922 graphic = el2img(element);
2924 delay = helpanim_info[j++].delay;
2929 if (infoscreen_frame[i - start] == 0)
2932 infoscreen_frame[i - start] = delay - 1;
2936 sync_frame = delay - infoscreen_frame[i - start];
2937 infoscreen_frame[i - start]--;
2940 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2942 if (!infoscreen_frame[i - start])
2943 infoscreen_step[i - start] = 0;
2947 if (!infoscreen_frame[i - start])
2948 infoscreen_step[i - start]++;
2949 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2955 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2957 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2958 graphic, sync_frame, USE_MASKING);
2961 DrawInfoScreen_HelpText(element, action, direction, i - start);
2966 redraw_mask |= REDRAW_FIELD;
2971 static char *getHelpText(int element, int action, int direction)
2973 char token[MAX_LINE_LEN];
2975 strcpy(token, element_info[element].token_name);
2978 strcat(token, element_action_info[action].suffix);
2980 if (direction != -1)
2981 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2983 return getHashEntry(helptext_info, token);
2986 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2988 int font_nr = FONT_INFO_ELEMENTS;
2989 int font_width = getFontWidth(font_nr);
2990 int font_height = getFontHeight(font_nr);
2991 int yoffset = (TILEX - 2 * font_height) / 2;
2992 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2993 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2994 int ystep = TILEY + 4;
2995 int pad_left = xstart - SX;
2996 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2997 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2998 int max_lines_per_text = 2;
3001 if (action != -1 && direction != -1) // element.action.direction
3002 text = getHelpText(element, action, direction);
3004 if (text == NULL && action != -1) // element.action
3005 text = getHelpText(element, action, -1);
3007 if (text == NULL && direction != -1) // element.direction
3008 text = getHelpText(element, -1, direction);
3010 if (text == NULL) // base element
3011 text = getHelpText(element, -1, -1);
3013 if (text == NULL) // not found
3014 text = "No description available";
3016 if (strlen(text) <= max_chars_per_line) // only one line of text
3017 ystart += getFontHeight(font_nr) / 2;
3019 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3020 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3021 TRUE, FALSE, FALSE);
3024 static void DrawInfoScreen_TitleScreen(void)
3026 SetGameStatus(GAME_MODE_TITLE);
3031 void HandleInfoScreen_TitleScreen(int button)
3033 HandleTitleScreen(0, 0, 0, 0, button);
3036 static void DrawInfoScreen_Elements(void)
3038 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3040 FadeOut(REDRAW_FIELD);
3045 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3047 FadeIn(REDRAW_FIELD);
3050 void HandleInfoScreen_Elements(int button)
3052 static unsigned int info_delay = 0;
3053 static int num_anims;
3054 static int num_pages;
3056 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3059 if (button == MB_MENU_INITIALIZE)
3061 boolean new_element = TRUE;
3065 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3067 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3069 else if (new_element)
3072 new_element = FALSE;
3076 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3080 if (button == MB_MENU_LEAVE)
3082 PlaySound(SND_MENU_ITEM_SELECTING);
3084 info_mode = INFO_MODE_MAIN;
3089 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3091 if (button != MB_MENU_INITIALIZE)
3093 PlaySound(SND_MENU_ITEM_SELECTING);
3098 if (page >= num_pages)
3100 FadeMenuSoundsAndMusic();
3102 info_mode = INFO_MODE_MAIN;
3109 FadeSetNextScreen();
3111 if (button != MB_MENU_INITIALIZE)
3112 FadeOut(REDRAW_FIELD);
3114 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3116 if (button != MB_MENU_INITIALIZE)
3117 FadeIn(REDRAW_FIELD);
3121 if (DelayReached(&info_delay, GameFrameDelay))
3122 if (page < num_pages)
3123 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3125 PlayMenuSoundIfLoop();
3129 static void DrawInfoScreen_Music(void)
3131 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3133 FadeOut(REDRAW_FIELD);
3140 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3142 FadeIn(REDRAW_FIELD);
3145 void HandleInfoScreen_Music(int button)
3147 static struct MusicFileInfo *list = NULL;
3148 int font_title = MENU_INFO_FONT_TITLE;
3149 int font_head = MENU_INFO_FONT_HEAD;
3150 int font_text = MENU_INFO_FONT_TEXT;
3151 int font_foot = MENU_INFO_FONT_FOOT;
3152 int spacing_title = menu.headline1_spacing_info[info_mode];
3153 int spacing_head = menu.headline2_spacing_info[info_mode];
3154 int ystep_title = getMenuTextStep(spacing_title, font_title);
3155 int ystep_head = getMenuTextStep(spacing_head, font_head);
3156 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3157 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3159 if (button == MB_MENU_INITIALIZE)
3161 list = music_file_info;
3165 FadeMenuSoundsAndMusic();
3170 DrawTextSCentered(ystart, font_title,
3171 "No music info for this level set.");
3173 DrawTextSCentered(ybottom, font_foot,
3174 "Press any key or button for info menu");
3180 if (button == MB_MENU_LEAVE)
3182 PlaySound(SND_MENU_ITEM_SELECTING);
3184 FadeMenuSoundsAndMusic();
3186 info_mode = INFO_MODE_MAIN;
3191 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3193 if (button != MB_MENU_INITIALIZE)
3195 PlaySound(SND_MENU_ITEM_SELECTING);
3203 FadeMenuSoundsAndMusic();
3205 info_mode = INFO_MODE_MAIN;
3211 FadeMenuSoundsAndMusic();
3213 if (list != music_file_info)
3214 FadeSetNextScreen();
3216 if (button != MB_MENU_INITIALIZE)
3217 FadeOut(REDRAW_FIELD);
3224 int sound = list->music;
3226 if (sound_info[sound].loop)
3227 PlaySoundLoop(sound);
3231 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3235 int music = list->music;
3237 if (music_info[music].loop)
3238 PlayMusicLoop(music);
3242 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3245 ystart += ystep_title;
3247 if (!strEqual(list->title, UNKNOWN_NAME))
3249 if (!strEqual(list->title_header, UNKNOWN_NAME))
3251 DrawTextSCentered(ystart, font_head, list->title_header);
3252 ystart += ystep_head;
3255 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3256 ystart += ystep_head;
3259 if (!strEqual(list->artist, UNKNOWN_NAME))
3261 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3262 DrawTextSCentered(ystart, font_head, list->artist_header);
3264 DrawTextSCentered(ystart, font_head, "by");
3266 ystart += ystep_head;
3268 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3269 ystart += ystep_head;
3272 if (!strEqual(list->album, UNKNOWN_NAME))
3274 if (!strEqual(list->album_header, UNKNOWN_NAME))
3275 DrawTextSCentered(ystart, font_head, list->album_header);
3277 DrawTextSCentered(ystart, font_head, "from the album");
3279 ystart += ystep_head;
3281 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3282 ystart += ystep_head;
3285 if (!strEqual(list->year, UNKNOWN_NAME))
3287 if (!strEqual(list->year_header, UNKNOWN_NAME))
3288 DrawTextSCentered(ystart, font_head, list->year_header);
3290 DrawTextSCentered(ystart, font_head, "from the year");
3292 ystart += ystep_head;
3294 DrawTextFCentered(ystart, font_text, "%s", list->year);
3295 ystart += ystep_head;
3298 DrawTextSCentered(ybottom, FONT_TEXT_4,
3299 "Press any key or button for next page");
3301 if (button != MB_MENU_INITIALIZE)
3302 FadeIn(REDRAW_FIELD);
3305 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3306 PlaySoundLoop(list->music);
3309 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3311 int font_title = MENU_INFO_FONT_TITLE;
3312 int font_head = MENU_INFO_FONT_HEAD;
3313 int font_text = MENU_INFO_FONT_TEXT;
3314 int font_foot = MENU_INFO_FONT_FOOT;
3315 int spacing_title = menu.headline1_spacing_info[info_mode];
3316 int spacing_head = menu.headline2_spacing_info[info_mode];
3317 int spacing_para = menu.paragraph_spacing_info[info_mode];
3318 int spacing_line = menu.line_spacing_info[info_mode];
3319 int ystep_title = getMenuTextStep(spacing_title, font_title);
3320 int ystep_head = getMenuTextStep(spacing_head, font_head);
3321 int ystep_para = getMenuTextStep(spacing_para, font_text);
3322 int ystep_line = getMenuTextStep(spacing_line, font_text);
3323 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3324 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3329 DrawTextSCentered(ystart, font_title, "Credits:");
3330 ystart += ystep_title;
3334 DrawTextSCentered(ystart, font_head,
3335 "Special thanks to");
3336 ystart += ystep_head;
3337 DrawTextSCentered(ystart, font_text,
3339 ystart += ystep_head;
3340 DrawTextSCentered(ystart, font_head,
3342 ystart += ystep_head;
3343 DrawTextSCentered(ystart, font_text,
3344 "\"Boulder Dash\"");
3345 ystart += ystep_head;
3346 DrawTextSCentered(ystart, font_head,
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 "First Star Software");
3358 else if (screen_nr == 1)
3360 DrawTextSCentered(ystart, font_head,
3361 "Special thanks to");
3362 ystart += ystep_head;
3363 DrawTextSCentered(ystart, font_text,
3364 "Klaus Heinz & Volker Wertich");
3365 ystart += ystep_head;
3366 DrawTextSCentered(ystart, font_head,
3368 ystart += ystep_head;
3369 DrawTextSCentered(ystart, font_text,
3370 "\"Emerald Mine\"");
3371 ystart += ystep_head;
3372 DrawTextSCentered(ystart, font_head,
3374 ystart += ystep_head;
3375 DrawTextSCentered(ystart, font_text,
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_head,
3380 ystart += ystep_head;
3381 DrawTextSCentered(ystart, font_text,
3384 else if (screen_nr == 2)
3386 DrawTextSCentered(ystart, font_head,
3387 "Special thanks to");
3388 ystart += ystep_head;
3389 DrawTextSCentered(ystart, font_text,
3390 "Michael Stopp & Philip Jespersen");
3391 ystart += ystep_head;
3392 DrawTextSCentered(ystart, font_head,
3394 ystart += ystep_head;
3395 DrawTextSCentered(ystart, font_text,
3397 ystart += ystep_head;
3398 DrawTextSCentered(ystart, font_head,
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_text,
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_head,
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_text,
3408 "Digital Integration");
3410 else if (screen_nr == 3)
3412 DrawTextSCentered(ystart, font_head,
3413 "Special thanks to");
3414 ystart += ystep_head;
3415 DrawTextSCentered(ystart, font_text,
3416 "Hiroyuki Imabayashi");
3417 ystart += ystep_head;
3418 DrawTextSCentered(ystart, font_head,
3420 ystart += ystep_head;
3421 DrawTextSCentered(ystart, font_text,
3423 ystart += ystep_head;
3424 DrawTextSCentered(ystart, font_head,
3426 ystart += ystep_head;
3427 DrawTextSCentered(ystart, font_text,
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_head,
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_text,
3436 else if (screen_nr == 4)
3438 DrawTextSCentered(ystart, font_head,
3439 "Special thanks to");
3440 ystart += ystep_head;
3441 DrawTextSCentered(ystart, font_text,
3443 ystart += ystep_head;
3444 DrawTextSCentered(ystart, font_head,
3446 ystart += ystep_head;
3447 DrawTextSCentered(ystart, font_text,
3448 "J\xfcrgen Bonhagen");
3449 ystart += ystep_head;
3450 DrawTextSCentered(ystart, font_head,
3451 "for the continuous creation");
3452 ystart += ystep_line;
3453 DrawTextSCentered(ystart, font_head,
3454 "of outstanding level sets");
3456 else if (screen_nr == 5)
3458 DrawTextSCentered(ystart, font_head,
3460 ystart += ystep_head;
3461 DrawTextSCentered(ystart, font_text,
3463 ystart += ystep_head;
3464 DrawTextSCentered(ystart, font_head,
3465 "for ideas and inspiration by");
3466 ystart += ystep_head;
3467 DrawTextSCentered(ystart, font_text,
3469 ystart += ystep_para;
3471 DrawTextSCentered(ystart, font_head,
3473 ystart += ystep_head;
3474 DrawTextSCentered(ystart, font_text,
3476 ystart += ystep_head;
3477 DrawTextSCentered(ystart, font_head,
3478 "for ideas and inspiration by");
3479 ystart += ystep_head;
3480 DrawTextSCentered(ystart, font_text,
3483 else if (screen_nr == 6)
3485 DrawTextSCentered(ystart, font_head,
3487 ystart += ystep_head;
3488 DrawTextSCentered(ystart, font_text,
3490 ystart += ystep_head;
3491 DrawTextSCentered(ystart, font_head,
3492 "for the code base used for the");
3493 ystart += ystep_line;
3494 DrawTextSCentered(ystart, font_head,
3495 "native Emerald Mine engine");
3497 else if (screen_nr == 7)
3499 DrawTextSCentered(ystart, font_head,
3501 ystart += ystep_head;
3502 DrawTextSCentered(ystart, font_text,
3504 ystart += ystep_head;
3505 DrawTextSCentered(ystart, font_head,
3506 "for the initial DOS port");
3507 ystart += ystep_para;
3509 DrawTextSCentered(ystart, font_head,
3511 ystart += ystep_head;
3512 DrawTextSCentered(ystart, font_text,
3514 ystart += ystep_head;
3515 DrawTextSCentered(ystart, font_head,
3516 "for some additional toons");
3518 else if (screen_nr == 8)
3520 DrawTextSCentered(ystart, font_head,
3521 "And not to forget:");
3522 ystart += ystep_head;
3523 DrawTextSCentered(ystart, font_head,
3525 ystart += ystep_head;
3526 DrawTextSCentered(ystart, font_text,
3527 "All those who contributed");
3528 ystart += ystep_line;
3529 DrawTextSCentered(ystart, font_text,
3530 "levels to this game");
3531 ystart += ystep_line;
3532 DrawTextSCentered(ystart, font_text,
3536 DrawTextSCentered(ybottom, font_foot,
3537 "Press any key or button for next page");
3540 static void DrawInfoScreen_Credits(void)
3542 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3544 FadeMenuSoundsAndMusic();
3546 FadeOut(REDRAW_FIELD);
3548 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3550 FadeIn(REDRAW_FIELD);
3553 void HandleInfoScreen_Credits(int button)
3555 static int screen_nr = 0;
3556 int num_screens = 9;
3558 if (button == MB_MENU_INITIALIZE)
3562 // DrawInfoScreen_CreditsScreen(screen_nr);
3565 if (button == MB_MENU_LEAVE)
3567 PlaySound(SND_MENU_ITEM_SELECTING);
3569 info_mode = INFO_MODE_MAIN;
3574 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3576 if (button != MB_MENU_INITIALIZE)
3578 PlaySound(SND_MENU_ITEM_SELECTING);
3583 if (screen_nr >= num_screens)
3585 FadeMenuSoundsAndMusic();
3587 info_mode = INFO_MODE_MAIN;
3594 FadeSetNextScreen();
3596 if (button != MB_MENU_INITIALIZE)
3597 FadeOut(REDRAW_FIELD);
3599 DrawInfoScreen_CreditsScreen(screen_nr);
3601 if (button != MB_MENU_INITIALIZE)
3602 FadeIn(REDRAW_FIELD);
3606 PlayMenuSoundIfLoop();
3610 static void DrawInfoScreen_Program(void)
3612 int font_title = MENU_INFO_FONT_TITLE;
3613 int font_head = MENU_INFO_FONT_HEAD;
3614 int font_text = MENU_INFO_FONT_TEXT;
3615 int font_foot = MENU_INFO_FONT_FOOT;
3616 int spacing_title = menu.headline1_spacing_info[info_mode];
3617 int spacing_head = menu.headline2_spacing_info[info_mode];
3618 int spacing_para = menu.paragraph_spacing_info[info_mode];
3619 int spacing_line = menu.line_spacing_info[info_mode];
3620 int ystep_title = getMenuTextStep(spacing_title, font_title);
3621 int ystep_head = getMenuTextStep(spacing_head, font_head);
3622 int ystep_para = getMenuTextStep(spacing_para, font_text);
3623 int ystep_line = getMenuTextStep(spacing_line, font_text);
3624 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3625 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3627 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3629 FadeOut(REDRAW_FIELD);
3634 DrawTextSCentered(ystart, font_title, "Program Information:");
3635 ystart += ystep_title;
3637 DrawTextSCentered(ystart, font_head,
3638 "This game is Freeware!");
3639 ystart += ystep_head;
3640 DrawTextSCentered(ystart, font_head,
3641 "If you like it, send e-mail to:");
3642 ystart += ystep_head;
3643 DrawTextSCentered(ystart, font_text,
3644 setup.internal.program_email);
3645 ystart += ystep_para;
3647 DrawTextSCentered(ystart, font_head,
3648 "More information and levels:");
3649 ystart += ystep_head;
3650 DrawTextSCentered(ystart, font_text,
3651 setup.internal.program_website);
3652 ystart += ystep_para;
3654 DrawTextSCentered(ystart, font_head,
3655 "If you have created new levels,");
3656 ystart += ystep_line;
3657 DrawTextSCentered(ystart, font_head,
3658 "send them to me to include them!");
3659 ystart += ystep_head;
3660 DrawTextSCentered(ystart, font_head,
3663 DrawTextSCentered(ybottom, font_foot,
3664 "Press any key or button for info menu");
3666 FadeIn(REDRAW_FIELD);
3669 void HandleInfoScreen_Program(int button)
3671 if (button == MB_MENU_LEAVE)
3673 PlaySound(SND_MENU_ITEM_SELECTING);
3675 info_mode = INFO_MODE_MAIN;
3680 else if (button == MB_MENU_CHOICE)
3682 PlaySound(SND_MENU_ITEM_SELECTING);
3684 FadeMenuSoundsAndMusic();
3686 info_mode = INFO_MODE_MAIN;
3691 PlayMenuSoundIfLoop();
3695 static void DrawInfoScreen_Version(void)
3697 int font_title = MENU_INFO_FONT_TITLE;
3698 int font_head = MENU_INFO_FONT_HEAD;
3699 int font_text = MENU_INFO_FONT_TEXT;
3700 int font_foot = MENU_INFO_FONT_FOOT;
3701 int spacing_title = menu.headline1_spacing_info[info_mode];
3702 int spacing_head = menu.headline2_spacing_info[info_mode];
3703 int spacing_para = menu.paragraph_spacing_info[info_mode];
3704 int spacing_line = menu.line_spacing_info[info_mode];
3705 int xstep = getFontWidth(font_text);
3706 int ystep_title = getMenuTextStep(spacing_title, font_title);
3707 int ystep_head = getMenuTextStep(spacing_head, font_head);
3708 int ystep_para = getMenuTextStep(spacing_para, font_text);
3709 int ystep_line = getMenuTextStep(spacing_line, font_text);
3710 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3711 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3712 int xstart1 = mSX - SX + 2 * xstep;
3713 int xstart2 = mSX - SX + 18 * xstep;
3714 int xstart3 = mSX - SX + 28 * xstep;
3715 SDL_version sdl_version_compiled;
3716 const SDL_version *sdl_version_linked;
3717 int driver_name_len = 10;
3718 SDL_version sdl_version_linked_ext;
3719 const char *driver_name = NULL;
3721 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3723 FadeOut(REDRAW_FIELD);
3728 DrawTextSCentered(ystart, font_title, "Version Information:");
3729 ystart += ystep_title;
3731 DrawTextF(xstart1, ystart, font_head, "Name");
3732 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3733 ystart += ystep_line;
3735 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3737 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3738 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3739 ystart += ystep_line;
3741 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3742 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3743 ystart += ystep_line;
3747 DrawTextF(xstart1, ystart, font_head, "Version");
3748 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3749 ystart += ystep_line;
3752 DrawTextF(xstart1, ystart, font_head, "Platform");
3753 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3755 PLATFORM_XX_BIT_STRING);
3756 ystart += ystep_line;
3758 DrawTextF(xstart1, ystart, font_head, "Target");
3759 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3760 ystart += ystep_line;
3762 DrawTextF(xstart1, ystart, font_head, "Source date");
3763 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3764 ystart += ystep_line;
3766 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3767 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3768 ystart += ystep_para;
3770 DrawTextF(xstart1, ystart, font_head, "Library");
3771 DrawTextF(xstart2, ystart, font_head, "compiled");
3772 DrawTextF(xstart3, ystart, font_head, "linked");
3773 ystart += ystep_head;
3775 SDL_VERSION(&sdl_version_compiled);
3776 SDL_GetVersion(&sdl_version_linked_ext);
3777 sdl_version_linked = &sdl_version_linked_ext;
3779 DrawTextF(xstart1, ystart, font_text, "SDL");
3780 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3781 sdl_version_compiled.major,
3782 sdl_version_compiled.minor,
3783 sdl_version_compiled.patch);
3784 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3785 sdl_version_linked->major,
3786 sdl_version_linked->minor,
3787 sdl_version_linked->patch);
3788 ystart += ystep_line;
3790 SDL_IMAGE_VERSION(&sdl_version_compiled);
3791 sdl_version_linked = IMG_Linked_Version();
3793 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3794 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3795 sdl_version_compiled.major,
3796 sdl_version_compiled.minor,
3797 sdl_version_compiled.patch);
3798 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3799 sdl_version_linked->major,
3800 sdl_version_linked->minor,
3801 sdl_version_linked->patch);
3802 ystart += ystep_line;
3804 SDL_MIXER_VERSION(&sdl_version_compiled);
3805 sdl_version_linked = Mix_Linked_Version();
3807 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3808 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3809 sdl_version_compiled.major,
3810 sdl_version_compiled.minor,
3811 sdl_version_compiled.patch);
3812 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3813 sdl_version_linked->major,
3814 sdl_version_linked->minor,
3815 sdl_version_linked->patch);
3816 ystart += ystep_line;
3818 SDL_NET_VERSION(&sdl_version_compiled);
3819 sdl_version_linked = SDLNet_Linked_Version();
3821 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3822 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3823 sdl_version_compiled.major,
3824 sdl_version_compiled.minor,
3825 sdl_version_compiled.patch);
3826 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3827 sdl_version_linked->major,
3828 sdl_version_linked->minor,
3829 sdl_version_linked->patch);
3830 ystart += ystep_para;
3832 DrawTextF(xstart1, ystart, font_head, "Driver");
3833 DrawTextF(xstart2, ystart, font_head, "Requested");
3834 DrawTextF(xstart3, ystart, font_head, "Used");
3835 ystart += ystep_head;
3838 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3840 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3841 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3842 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3843 ystart += ystep_line;
3846 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3848 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3849 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3850 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3851 ystart += ystep_line;
3854 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3856 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3857 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3858 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3860 DrawTextSCentered(ybottom, font_foot,
3861 "Press any key or button for info menu");
3863 FadeIn(REDRAW_FIELD);
3866 void HandleInfoScreen_Version(int button)
3868 if (button == MB_MENU_LEAVE)
3870 PlaySound(SND_MENU_ITEM_SELECTING);
3872 info_mode = INFO_MODE_MAIN;
3877 else if (button == MB_MENU_CHOICE)
3879 PlaySound(SND_MENU_ITEM_SELECTING);
3881 FadeMenuSoundsAndMusic();
3883 info_mode = INFO_MODE_MAIN;
3888 PlayMenuSoundIfLoop();
3892 static void DrawInfoScreen_LevelSet(void)
3894 struct TitleMessageInfo *tmi = &readme;
3895 char *filename = getLevelSetInfoFilename();
3896 char *title = "Level Set Information:";
3897 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3898 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3900 if (filename == NULL)
3902 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3907 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3909 FadeOut(REDRAW_FIELD);
3914 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3916 // if x position set to "-1", automatically determine by playfield width
3918 tmi->x = SXSIZE / 2;
3920 // if y position set to "-1", use static default value
3924 // if width set to "-1", automatically determine by playfield width
3925 if (tmi->width == -1)
3926 tmi->width = SXSIZE - 2 * TILEX;
3928 // if height set to "-1", automatically determine by playfield height
3929 if (tmi->height == -1)
3930 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3932 // if chars set to "-1", automatically determine by text and font width
3933 if (tmi->chars == -1)
3934 tmi->chars = tmi->width / getFontWidth(tmi->font);
3936 tmi->width = tmi->chars * getFontWidth(tmi->font);
3938 // if lines set to "-1", automatically determine by text and font height
3939 if (tmi->lines == -1)
3940 tmi->lines = tmi->height / getFontHeight(tmi->font);
3942 tmi->height = tmi->lines * getFontHeight(tmi->font);
3944 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3945 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3946 tmi->autowrap, tmi->centered, tmi->parse_comments);
3948 DrawTextSCentered(ybottom, FONT_TEXT_4,
3949 "Press any key or button for info menu");
3951 FadeIn(REDRAW_FIELD);
3954 static void HandleInfoScreen_LevelSet(int button)
3956 if (button == MB_MENU_LEAVE)
3958 PlaySound(SND_MENU_ITEM_SELECTING);
3960 info_mode = INFO_MODE_MAIN;
3965 else if (button == MB_MENU_CHOICE)
3967 PlaySound(SND_MENU_ITEM_SELECTING);
3969 FadeMenuSoundsAndMusic();
3971 info_mode = INFO_MODE_MAIN;
3976 PlayMenuSoundIfLoop();
3980 static void DrawInfoScreen(void)
3982 if (info_mode == INFO_MODE_TITLE)
3983 DrawInfoScreen_TitleScreen();
3984 else if (info_mode == INFO_MODE_ELEMENTS)
3985 DrawInfoScreen_Elements();
3986 else if (info_mode == INFO_MODE_MUSIC)
3987 DrawInfoScreen_Music();
3988 else if (info_mode == INFO_MODE_CREDITS)
3989 DrawInfoScreen_Credits();
3990 else if (info_mode == INFO_MODE_PROGRAM)
3991 DrawInfoScreen_Program();
3992 else if (info_mode == INFO_MODE_VERSION)
3993 DrawInfoScreen_Version();
3994 else if (info_mode == INFO_MODE_LEVELSET)
3995 DrawInfoScreen_LevelSet();
3997 DrawInfoScreen_Main();
3999 if (info_mode != INFO_MODE_MAIN &&
4000 info_mode != INFO_MODE_TITLE &&
4001 info_mode != INFO_MODE_MUSIC)
4002 PlayMenuSoundsAndMusic();
4005 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4007 if (info_mode == INFO_MODE_TITLE)
4008 HandleInfoScreen_TitleScreen(button);
4009 else if (info_mode == INFO_MODE_ELEMENTS)
4010 HandleInfoScreen_Elements(button);
4011 else if (info_mode == INFO_MODE_MUSIC)
4012 HandleInfoScreen_Music(button);
4013 else if (info_mode == INFO_MODE_CREDITS)
4014 HandleInfoScreen_Credits(button);
4015 else if (info_mode == INFO_MODE_PROGRAM)
4016 HandleInfoScreen_Program(button);
4017 else if (info_mode == INFO_MODE_VERSION)
4018 HandleInfoScreen_Version(button);
4019 else if (info_mode == INFO_MODE_LEVELSET)
4020 HandleInfoScreen_LevelSet(button);
4022 HandleInfoScreen_Main(mx, my, dx, dy, button);
4026 // ============================================================================
4027 // type name functions
4028 // ============================================================================
4030 static TreeInfo *type_name_node = NULL;
4031 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4032 static int type_name_nr = 0;
4034 static int getPlayerNameColor(char *name)
4036 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4039 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4042 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4043 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4044 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4045 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4046 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4047 int font_width = getFontWidth(font_nr);
4049 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4051 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4053 pos->width = strlen(text) * font_width;
4054 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4056 DrawText(sx, sy, text, font_nr);
4059 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4061 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4063 *pos = *mci->pos_input;
4065 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4067 TreeInfo *ti = player_name_current;
4068 int first_entry = ti->cl_first;
4069 int entry_pos = first_entry + ti->cl_cursor;
4070 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4071 int xpos = MENU_SCREEN_START_XPOS;
4072 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4074 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4075 type_name_nr = entry_pos;
4077 strcpy(name, type_name_node->name);
4081 pos->width = MAX_PLAYER_NAME_LEN * 32;
4085 type_name_nr = user.nr;
4087 strcpy(name, setup.player_name);
4090 strcpy(type_name_last, name);
4092 if (strEqual(name, EMPTY_PLAYER_NAME))
4095 *xpos = strlen(name);
4098 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4100 // change name of edited user in global list of user names
4101 setString(&global.user_names[type_name_nr], name);
4103 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4105 TreeInfo *node = type_name_node;
4107 // change name of edited user in local menu tree structure
4108 setString(&node->name, name);
4109 setString(&node->name_sorting, name);
4111 node->color = getPlayerNameColor(name);
4112 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4116 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4119 boolean reset_setup = strEqual(name, "");
4120 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4121 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4124 strcpy(name, type_name_last);
4126 if (strEqual(name, ""))
4127 strcpy(name, EMPTY_PLAYER_NAME);
4129 setTypeNameValues_Name(name, pos);
4131 // if player name not changed, no further action required
4132 if (strEqual(name, type_name_last))
4135 // redraw player name before (possibly) opening request dialogs
4136 drawTypeNameText(name, pos, FALSE);
4138 int last_user_nr = user.nr;
4140 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4142 // save setup of currently active user (may differ from edited user)
4145 // temporarily change active user to edited user
4146 user.nr = type_name_nr;
4148 // load setup of edited user (unless creating user with current setup)
4150 !Request("Use current setup values for the new player?", REQ_ASK))
4154 char *setup_filename = getSetupFilename();
4155 boolean setup_exists = fileExists(setup_filename);
4157 // change name of edited user in setup structure
4158 strcpy(setup.player_name, name);
4160 // save setup of edited user
4163 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4167 if (Request("Reset setup values for this player?", REQ_ASK))
4169 // remove setup config file
4170 unlink(setup_filename);
4172 // set player name to default player name
4175 // update player name used by name typing functions
4176 strcpy(name, setup.player_name);
4178 setTypeNameValues_Name(name, pos);
4181 else if (remove_user && type_name_nr != 0)
4183 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4185 char *user_dir = getUserGameDataDir();
4186 char *user_dir_removed =
4187 getStringCat3WithSeparator(user_dir, "REMOVED",
4188 getCurrentTimestamp(), ".");
4190 if (rename(user_dir, user_dir_removed) != 0)
4191 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4193 checked_free(user_dir_removed);
4196 else if (create_user && type_name_nr != 0 && !setup_exists)
4198 if (Request("Create empty level set for the new player?", REQ_ASK))
4200 char *levelset_subdir = getNewUserLevelSubdir();
4202 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4204 AddUserLevelSetToLevelInfo(levelset_subdir);
4206 LevelDirTree *leveldir_current_last = leveldir_current;
4208 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4211 // set level number of newly created level set to default value
4212 LoadLevelSetup_SeriesInfo();
4214 // set newly created level set as current level set for new user
4215 SaveLevelSetup_LastSeries();
4216 SaveLevelSetup_SeriesInfo();
4218 leveldir_current = leveldir_current_last;
4222 Request("Creating new level set failed!", REQ_CONFIRM);
4227 // restore currently active user
4228 user.nr = last_user_nr;
4230 // restore setup of currently active user
4233 // restore last level set of currently active user
4234 LoadLevelSetup_LastSeries();
4235 LoadLevelSetup_SeriesInfo();
4239 static void HandleTypeNameExt(boolean initialize, Key key)
4241 static struct TextPosInfo pos_name = { 0 };
4242 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4243 static int xpos = 0;
4244 struct TextPosInfo *pos = &pos_name;
4245 char key_char = getValidConfigValueChar(getCharFromKey(key));
4246 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4247 boolean active = TRUE;
4251 getTypeNameValues(name, pos, &xpos);
4253 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4254 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4256 StartTextInput(sx, sy, pos->width, pos->height);
4258 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4260 name[xpos] = key_char;
4265 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4271 else if (key == KSYM_Return || key == KSYM_Escape)
4273 boolean changed = (key == KSYM_Return);
4277 setTypeNameValues(name, pos, changed);
4282 drawTypeNameText(name, pos, active);
4286 SetGameStatus(game_status_last_screen);
4288 if (game_status == GAME_MODE_MAIN)
4289 InitializeMainControls();
4293 static void DrawTypeName(void)
4295 HandleTypeNameExt(TRUE, 0);
4298 void HandleTypeName(Key key)
4300 HandleTypeNameExt(FALSE, key);
4304 // ============================================================================
4305 // tree menu functions
4306 // ============================================================================
4308 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4310 if (game_status != GAME_MODE_SETUP ||
4311 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4314 int max_text_size = 0;
4317 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4318 max_text_size = MAX(max_text_size, strlen(node->name));
4320 int num_entries = numTreeInfoInGroup(ti);
4321 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4322 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4323 int text_width = max_text_size * getFontWidth(font_nr);
4324 int button_width = SC_MENUBUTTON_XSIZE;
4325 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4326 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4327 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4328 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4329 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4330 int align_xoffset = MAX(0, align_xoffset_raw);
4332 return align_xoffset;
4335 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4337 if (game_status != GAME_MODE_SETUP ||
4338 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4341 int num_entries = numTreeInfoInGroup(ti);
4342 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4343 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4344 int font_height = getFontHeight(font_nr);
4345 int text_height = font_height * num_page_entries;
4346 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4347 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4348 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4349 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4350 int align_yoffset = MAX(0, align_yoffset_raw);
4352 return align_yoffset;
4355 static void DrawChooseTree(TreeInfo **ti_ptr)
4357 int fade_mask = REDRAW_FIELD;
4360 fade_mask = REDRAW_ALL;
4362 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4364 if (game_status == GAME_MODE_SETUP)
4368 else // GAME_MODE_LEVELS
4370 SetGameStatus(GAME_MODE_MAIN);
4380 FreeScreenGadgets();
4381 CreateScreenGadgets();
4385 // needed if different viewport properties defined for choosing level (set)
4386 ChangeViewportPropertiesIfNeeded();
4388 if (game_status == GAME_MODE_NAMES)
4389 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4390 else if (game_status == GAME_MODE_LEVELNR)
4391 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4392 else if (game_status == GAME_MODE_LEVELS)
4393 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4397 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4399 MapScreenTreeGadgets(*ti_ptr);
4400 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4402 DrawMaskedBorder(fade_mask);
4407 static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
4409 int num_entries = numTreeInfoInGroup(ti);
4410 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4411 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4412 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4413 int first_entry = ti->cl_first;
4414 int entry_pos = first_entry + y;
4415 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4416 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4417 int font_color = MENU_CHOOSE_TREE_COLOR(node, active);
4418 int font_nr = MENU_CHOOSE_TREE_FONT(font_color);
4419 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4420 int xpos = MENU_SCREEN_START_XPOS;
4421 int ypos = MENU_SCREEN_START_YPOS + y;
4422 int startx = amSX + xpos * 32;
4423 int starty = amSY + ypos * 32;
4424 int startx_text = startx + font_xoffset;
4425 int endx_text = amSX + screen_width;
4426 int max_text_size = endx_text - startx_text;
4427 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4428 char buffer[max_buffer_len + 1];
4430 strncpy(buffer, node->name, max_buffer_len);
4431 buffer[max_buffer_len] = '\0';
4433 DrawText(startx, starty, buffer, font_nr);
4436 static void drawChooseTreeList(int first_entry, int num_page_entries,
4440 char *title_string = NULL;
4441 int yoffset_sets = MENU_TITLE1_YPOS;
4442 int yoffset_setup = 16;
4443 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4444 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4446 title_string = ti->infotext;
4448 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4450 clearMenuListArea();
4452 for (i = 0; i < num_page_entries; i++)
4454 TreeInfo *node, *node_first;
4455 int entry_pos = first_entry + i;
4457 node_first = getTreeInfoFirstGroupEntry(ti);
4458 node = getTreeInfoFromPos(node_first, entry_pos);
4460 drawChooseTreeText(i, FALSE, ti);
4462 if (node->parent_link)
4463 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4464 else if (node->level_group)
4465 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4467 initCursor(i, IMG_MENU_BUTTON);
4469 if (game_status == GAME_MODE_NAMES)
4470 drawChooseTreeEdit(i, FALSE);
4473 redraw_mask |= REDRAW_FIELD;
4476 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4478 TreeInfo *node, *node_first;
4479 int x, last_redraw_mask = redraw_mask;
4480 int ypos = MENU_TITLE2_YPOS;
4481 int font_nr = FONT_TITLE_2;
4483 if (ti->type == TREE_TYPE_LEVEL_NR)
4484 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4486 if (ti->type != TREE_TYPE_LEVEL_DIR)
4489 node_first = getTreeInfoFirstGroupEntry(ti);
4490 node = getTreeInfoFromPos(node_first, entry_pos);
4492 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4494 if (node->parent_link)
4495 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4496 node->node_parent->name);
4497 else if (node->level_group)
4498 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4500 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4501 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4502 node->levels, (node->levels > 1 ? "levels" : "level"),
4505 // let BackToFront() redraw only what is needed
4506 redraw_mask = last_redraw_mask;
4507 for (x = 0; x < SCR_FIELDX; x++)
4508 MarkTileDirty(x, 1);
4511 static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
4513 drawChooseTreeCursor(y, active);
4514 drawChooseTreeText(y, active, ti);
4517 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4520 TreeInfo *ti = *ti_ptr;
4521 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4522 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4523 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4524 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4525 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4527 int y = ti->cl_cursor;
4528 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4529 int num_entries = numTreeInfoInGroup(ti);
4530 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4531 boolean position_set_by_scrollbar = (dx == 999);
4533 if (button == MB_MENU_INITIALIZE)
4535 int num_entries = numTreeInfoInGroup(ti);
4536 int entry_pos = getPosFromTreeInfo(ti);
4538 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4539 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4541 if (ti->cl_first == -1)
4543 // only on initialization
4544 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4545 ti->cl_cursor = entry_pos - ti->cl_first;
4547 else if (ti->cl_cursor >= num_page_entries ||
4548 (num_entries > num_page_entries &&
4549 num_entries - ti->cl_first < num_page_entries))
4551 // only after change of list size (by custom graphic configuration)
4552 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4553 ti->cl_cursor = entry_pos - ti->cl_first;
4556 if (position_set_by_scrollbar)
4559 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4562 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4563 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4564 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4568 else if (button == MB_MENU_LEAVE)
4572 PlaySound(SND_MENU_ITEM_SELECTING);
4574 if (ti->node_parent)
4576 *ti_ptr = ti->node_parent;
4577 DrawChooseTree(ti_ptr);
4579 else if (game_status == GAME_MODE_SETUP)
4581 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4582 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4583 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4585 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4586 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4587 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4588 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4589 execSetupGraphics();
4590 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4591 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4592 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4594 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4595 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4596 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4597 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4598 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4599 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4600 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4601 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4608 if (game_status == GAME_MODE_LEVELNR)
4610 int new_level_nr = atoi(level_number_current->identifier);
4612 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4615 SetGameStatus(GAME_MODE_MAIN);
4623 if (mx || my) // mouse input
4625 x = (mx - amSX) / 32;
4626 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4628 if (game_status == GAME_MODE_NAMES)
4629 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4631 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4633 // move cursor instead of scrolling when already at start/end of list
4634 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4636 else if (dy == +1 * SCROLL_LINE &&
4637 ti->cl_first + num_page_entries == num_entries)
4640 // handle scrolling screen one line or page
4641 if (ti->cl_cursor + dy < 0 ||
4642 ti->cl_cursor + dy > num_page_entries - 1)
4644 boolean redraw = FALSE;
4646 if (ABS(dy) == SCROLL_PAGE)
4647 step = num_page_entries - 1;
4649 if (dy < 0 && ti->cl_first > 0)
4651 // scroll page/line up
4653 ti->cl_first -= step;
4654 if (ti->cl_first < 0)
4659 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4661 // scroll page/line down
4663 ti->cl_first += step;
4664 if (ti->cl_first + num_page_entries > num_entries)
4665 ti->cl_first = MAX(0, num_entries - num_page_entries);
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);
4676 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4683 // handle moving cursor one line
4684 y = ti->cl_cursor + dy;
4689 TreeInfo *node_first, *node_cursor;
4690 int entry_pos = ti->cl_first + y;
4692 node_first = getTreeInfoFirstGroupEntry(ti);
4693 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4695 if (node_cursor->node_group)
4699 PlaySound(SND_MENU_ITEM_SELECTING);
4701 node_cursor->cl_first = ti->cl_first;
4702 node_cursor->cl_cursor = ti->cl_cursor;
4703 *ti_ptr = node_cursor->node_group;
4704 DrawChooseTree(ti_ptr);
4709 else if (dx == -1 && ti->node_parent)
4713 PlaySound(SND_MENU_ITEM_SELECTING);
4715 *ti_ptr = ti->node_parent;
4716 DrawChooseTree(ti_ptr);
4721 if (!anyScrollbarGadgetActive() &&
4722 IN_VIS_MENU(x, y) &&
4723 mx < mx_right_border &&
4724 y >= 0 && y < num_page_entries)
4728 if (game_status == GAME_MODE_NAMES)
4730 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4731 drawChooseTreeEdit(y, TRUE);
4734 if (y != ti->cl_cursor)
4736 PlaySound(SND_MENU_ITEM_ACTIVATING);
4738 drawChooseTreeCursorAndText(ti->cl_cursor, FALSE, ti);
4739 drawChooseTreeCursorAndText(y, TRUE, ti);
4740 drawChooseTreeInfo(ti->cl_first + y, ti);
4746 if (game_status == GAME_MODE_SETUP)
4748 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4749 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4750 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4752 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4753 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4754 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4755 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4756 execSetupGraphics();
4757 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4758 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4759 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4761 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4762 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4763 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4764 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4765 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4766 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4767 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4768 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4777 TreeInfo *node_first, *node_cursor;
4778 int entry_pos = ti->cl_first + y;
4780 PlaySound(SND_MENU_ITEM_SELECTING);
4782 node_first = getTreeInfoFirstGroupEntry(ti);
4783 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4785 if (node_cursor->node_group)
4789 node_cursor->cl_first = ti->cl_first;
4790 node_cursor->cl_cursor = ti->cl_cursor;
4791 *ti_ptr = node_cursor->node_group;
4792 DrawChooseTree(ti_ptr);
4794 else if (node_cursor->parent_link)
4798 *ti_ptr = node_cursor->node_parent;
4799 DrawChooseTree(ti_ptr);
4805 node_cursor->cl_first = ti->cl_first;
4806 node_cursor->cl_cursor = ti->cl_cursor;
4807 *ti_ptr = node_cursor;
4809 if (ti->type == TREE_TYPE_LEVEL_DIR)
4811 LoadLevelSetup_SeriesInfo();
4813 SaveLevelSetup_LastSeries();
4814 SaveLevelSetup_SeriesInfo();
4818 if (game_status == GAME_MODE_SETUP)
4820 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4821 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4822 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4824 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4825 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4826 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4827 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4828 execSetupGraphics();
4829 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4830 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4831 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4833 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4834 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4835 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4836 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4837 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4838 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4839 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4840 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4847 if (game_status == GAME_MODE_LEVELNR)
4849 int new_level_nr = atoi(level_number_current->identifier);
4851 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4853 else if (game_status == GAME_MODE_LEVELS)
4855 // store level set if chosen from "last played level set" menu
4856 StoreLastPlayedLevels(leveldir_current);
4858 else if (game_status == GAME_MODE_NAMES)
4860 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4862 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
4869 // change active user to selected user
4870 user.nr = entry_pos;
4872 // save number of new active user
4875 // load setup of new active user
4878 // load last level set of new active user
4879 LoadLevelSetup_LastSeries();
4880 LoadLevelSetup_SeriesInfo();
4882 // update list of last played level sets
4883 UpdateLastPlayedLevels_TreeInfo();
4887 ToggleFullscreenIfNeeded();
4888 ChangeWindowScalingIfNeeded();
4890 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
4891 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
4892 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
4895 SetGameStatus(GAME_MODE_MAIN);
4904 void DrawChoosePlayerName(void)
4908 FadeMenuSoundsAndMusic();
4910 if (player_name != NULL)
4912 freeTreeInfo(player_name);
4917 for (i = 0; i < MAX_PLAYER_NAMES; i++)
4919 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
4920 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
4923 ti->node_top = &player_name;
4924 ti->sort_priority = 10000 + value;
4925 ti->color = getPlayerNameColor(global.user_names[i]);
4927 snprintf(identifier, sizeof(identifier), "%d", value);
4928 snprintf(name, sizeof(name), "%s", global.user_names[i]);
4930 setString(&ti->identifier, identifier);
4931 setString(&ti->name, name);
4932 setString(&ti->name_sorting, name);
4934 pushTreeInfo(&player_name, ti);
4937 // sort player entries by player number
4938 sortTreeInfo(&player_name);
4940 // set current player entry to selected player entry
4941 player_name_current =
4942 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
4944 // if that fails, set current player name to first available name
4945 if (player_name_current == NULL)
4946 player_name_current = player_name;
4948 DrawChooseTree(&player_name_current);
4950 PlayMenuSoundsAndMusic();
4953 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
4955 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
4958 void DrawChooseLevelSet(void)
4960 FadeMenuSoundsAndMusic();
4962 DrawChooseTree(&leveldir_current);
4964 PlayMenuSoundsAndMusic();
4967 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4969 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4972 void DrawChooseLevelNr(void)
4976 FadeMenuSoundsAndMusic();
4978 if (level_number != NULL)
4980 freeTreeInfo(level_number);
4982 level_number = NULL;
4985 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4987 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4988 char identifier[32], name[64];
4991 // temporarily load level info to get level name
4992 LoadLevelInfoOnly(i);
4994 ti->node_top = &level_number;
4995 ti->sort_priority = 10000 + value;
4996 ti->color = (level.no_level_file ? FC_BLUE :
4997 LevelStats_getSolved(i) ? FC_GREEN :
4998 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5000 snprintf(identifier, sizeof(identifier), "%d", value);
5001 snprintf(name, sizeof(name), "%03d: %s", value,
5002 (level.no_level_file ? "(no file)" : level.name));
5004 setString(&ti->identifier, identifier);
5005 setString(&ti->name, name);
5006 setString(&ti->name_sorting, name);
5008 pushTreeInfo(&level_number, ti);
5011 // sort level number values to start with lowest level number
5012 sortTreeInfo(&level_number);
5014 // set current level number to current level number
5015 level_number_current =
5016 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5018 // if that also fails, set current level number to first available level
5019 if (level_number_current == NULL)
5020 level_number_current = level_number;
5022 DrawChooseTree(&level_number_current);
5024 PlayMenuSoundsAndMusic();
5027 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5029 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5032 void DrawHallOfFame(int level_nr)
5034 int fade_mask = REDRAW_FIELD;
5037 fade_mask = REDRAW_ALL;
5040 FadeMenuSoundsAndMusic();
5042 // (this is needed when called from GameEnd() after winning a game)
5043 KeyboardAutoRepeatOn();
5045 // (this is needed when called from GameEnd() after winning a game)
5046 SetDrawDeactivationMask(REDRAW_NONE);
5047 SetDrawBackgroundMask(REDRAW_FIELD);
5049 LoadLocalAndServerScore(level_nr);
5051 if (scores.last_added >= 0)
5052 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5054 FadeSetEnterScreen();
5058 // needed if different viewport properties defined for scores
5059 ChangeViewportPropertiesIfNeeded();
5061 PlayMenuSoundsAndMusic();
5063 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5065 HandleHallOfFame(level_nr, 0, 0, 0, MB_MENU_INITIALIZE);
5067 DrawMaskedBorder(fade_mask);
5072 static int getHallOfFameFirstEntry(int first_entry, int step)
5075 first_entry = scores.last_added - (NUM_MENU_ENTRIES_ON_SCREEN + 1) / 2 + 1;
5077 first_entry += step;
5079 if (first_entry < 0)
5081 else if (first_entry > MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN)
5082 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
5087 static char *getHallOfFameScoreText(int nr)
5089 if (!level.rate_time_over_score)
5090 return int2str(scores.entry[nr].score, 5); // show normal score
5092 if (level.use_step_counter)
5093 return int2str(scores.entry[nr].time, 5); // show number of steps
5095 static char score_text[10];
5096 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5097 int mm = (time_seconds / 60) % 60;
5098 int ss = (time_seconds % 60);
5100 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5105 static void drawHallOfFameList(int level_nr, int first_entry)
5109 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5112 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
5113 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
5114 "HighScores of Level %d", level_nr);
5116 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5118 int entry = first_entry + i;
5119 boolean active = (entry == scores.last_added);
5120 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
5121 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
5122 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
5123 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
5124 int dxoff = getFontDrawOffsetX(font_nr1);
5125 int dx1 = 3 * getFontWidth(font_nr1);
5126 int dx2 = dx1 + getFontWidth(font_nr1);
5127 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
5128 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
5129 int sy = mSY + 64 + i * 32;
5131 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
5132 DrawText(mSX + dx1, sy, ".", font_nr1);
5134 for (j = 0; j < num_dots; j++)
5135 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
5137 if (!strEqual(scores.entry[entry].name, EMPTY_PLAYER_NAME))
5138 DrawText(mSX + dx2, sy, scores.entry[entry].name, font_nr2);
5140 DrawText(mSX + dx3, sy, getHallOfFameScoreText(entry), font_nr4);
5143 redraw_mask |= REDRAW_FIELD;
5146 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5148 static int level_nr = 0;
5149 static int first_entry = 0;
5150 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5152 if (button == MB_MENU_INITIALIZE)
5156 first_entry = getHallOfFameFirstEntry(0, 0);
5158 drawHallOfFameList(level_nr, first_entry);
5163 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
5164 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
5168 first_entry = getHallOfFameFirstEntry(first_entry, -step);
5170 drawHallOfFameList(level_nr, first_entry);
5174 first_entry = getHallOfFameFirstEntry(first_entry, step);
5176 drawHallOfFameList(level_nr, first_entry);
5178 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5180 PlaySound(SND_MENU_ITEM_SELECTING);
5182 FadeSound(SND_BACKGROUND_SCORES);
5184 if (button == MB_MENU_CHOICE &&
5185 game_status_last_screen == GAME_MODE_PLAYING &&
5186 setup.auto_play_next_level && setup.increment_levels &&
5187 level_nr < leveldir_current->last_level &&
5190 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
5194 SetGameStatus(GAME_MODE_MAIN);
5200 if (game_status == GAME_MODE_SCORES)
5201 PlayMenuSoundIfLoop();
5205 // ============================================================================
5206 // setup screen functions
5207 // ============================================================================
5209 static struct TokenInfo *setup_info;
5210 static int num_setup_info; // number of setup entries shown on screen
5211 static int max_setup_info; // total number of setup entries in list
5213 static char *window_size_text;
5214 static char *scaling_type_text;
5215 static char *rendering_mode_text;
5216 static char *vsync_mode_text;
5217 static char *scroll_delay_text;
5218 static char *snapshot_mode_text;
5219 static char *game_speed_text;
5220 static char *network_server_text;
5221 static char *graphics_set_name;
5222 static char *sounds_set_name;
5223 static char *music_set_name;
5224 static char *volume_simple_text;
5225 static char *volume_loops_text;
5226 static char *volume_music_text;
5227 static char *touch_controls_text;
5228 static char *move_distance_text;
5229 static char *drop_distance_text;
5230 static char *transparency_text;
5231 static char *grid_size_text[2][2];
5233 static void execSetupMain(void)
5235 setup_mode = SETUP_MODE_MAIN;
5240 static void execSetupGame_setGameSpeeds(boolean update_value)
5242 if (setup.game_speed_extended)
5244 game_speeds_list = game_speeds_list_extended;
5245 game_speeds = game_speeds_extended;
5249 game_speeds_list = game_speeds_list_normal;
5250 game_speeds = game_speeds_normal;
5253 if (game_speeds == NULL)
5257 for (i = 0; game_speeds_list[i].value != -1; i++)
5259 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5260 char identifier[32], name[32];
5261 int value = game_speeds_list[i].value;
5262 char *text = game_speeds_list[i].text;
5264 ti->node_top = &game_speeds;
5265 ti->sort_priority = 10000 - value;
5267 sprintf(identifier, "%d", value);
5268 sprintf(name, "%s", text);
5270 setString(&ti->identifier, identifier);
5271 setString(&ti->name, name);
5272 setString(&ti->name_sorting, name);
5273 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5275 pushTreeInfo(&game_speeds, ti);
5278 // sort game speed values to start with slowest game speed
5279 sortTreeInfo(&game_speeds);
5281 update_value = TRUE;
5286 // set current game speed to configured game speed value
5287 game_speed_current =
5288 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5290 // if that fails, set current game speed to reliable default value
5291 if (game_speed_current == NULL)
5292 game_speed_current =
5293 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5295 // if that also fails, set current game speed to first available speed
5296 if (game_speed_current == NULL)
5297 game_speed_current = game_speeds;
5299 if (setup.game_speed_extended)
5300 game_speeds_extended = game_speeds;
5302 game_speeds_normal = game_speeds;
5305 setup.game_frame_delay = atoi(game_speed_current->identifier);
5307 // needed for displaying game speed text instead of identifier
5308 game_speed_text = game_speed_current->name;
5311 static void execSetupGame_setScrollDelays(void)
5313 if (scroll_delays == NULL)
5317 for (i = 0; scroll_delays_list[i].value != -1; i++)
5319 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5320 char identifier[32], name[32];
5321 int value = scroll_delays_list[i].value;
5322 char *text = scroll_delays_list[i].text;
5324 ti->node_top = &scroll_delays;
5325 ti->sort_priority = value;
5327 sprintf(identifier, "%d", value);
5328 sprintf(name, "%s", text);
5330 setString(&ti->identifier, identifier);
5331 setString(&ti->name, name);
5332 setString(&ti->name_sorting, name);
5333 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5335 pushTreeInfo(&scroll_delays, ti);
5338 // sort scroll delay values to start with lowest scroll delay value
5339 sortTreeInfo(&scroll_delays);
5341 // set current scroll delay value to configured scroll delay value
5342 scroll_delay_current =
5343 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5345 // if that fails, set current scroll delay to reliable default value
5346 if (scroll_delay_current == NULL)
5347 scroll_delay_current =
5348 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5350 // if that also fails, set current scroll delay to first available value
5351 if (scroll_delay_current == NULL)
5352 scroll_delay_current = scroll_delays;
5355 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5357 // needed for displaying scroll delay text instead of identifier
5358 scroll_delay_text = scroll_delay_current->name;
5361 static void execSetupGame_setSnapshotModes(void)
5363 if (snapshot_modes == NULL)
5367 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5369 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5370 char identifier[32], name[32];
5371 char *value = snapshot_modes_list[i].value;
5372 char *text = snapshot_modes_list[i].text;
5374 ti->node_top = &snapshot_modes;
5375 ti->sort_priority = i;
5377 sprintf(identifier, "%s", value);
5378 sprintf(name, "%s", text);
5380 setString(&ti->identifier, identifier);
5381 setString(&ti->name, name);
5382 setString(&ti->name_sorting, name);
5383 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5385 pushTreeInfo(&snapshot_modes, ti);
5388 // sort snapshot mode values to start with lowest snapshot mode value
5389 sortTreeInfo(&snapshot_modes);
5391 // set current snapshot mode value to configured snapshot mode value
5392 snapshot_mode_current =
5393 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5395 // if that fails, set current snapshot mode to reliable default value
5396 if (snapshot_mode_current == NULL)
5397 snapshot_mode_current =
5398 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5400 // if that also fails, set current snapshot mode to first available value
5401 if (snapshot_mode_current == NULL)
5402 snapshot_mode_current = snapshot_modes;
5405 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5407 // needed for displaying snapshot mode text instead of identifier
5408 snapshot_mode_text = snapshot_mode_current->name;
5411 static void execSetupGame_setNetworkServerText(void)
5413 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5415 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5419 strncpy(network_server_hostname, setup.network_server_hostname,
5420 MAX_SETUP_TEXT_INPUT_LEN);
5421 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5424 // needed for displaying network server text instead of identifier
5425 network_server_text = network_server_hostname;
5428 static void execSetupGame(void)
5430 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5432 execSetupGame_setGameSpeeds(FALSE);
5433 execSetupGame_setScrollDelays();
5434 execSetupGame_setSnapshotModes();
5436 execSetupGame_setNetworkServerText();
5438 setup_mode = SETUP_MODE_GAME;
5442 // check if vsync needs to be disabled for this game speed to work
5443 if (check_vsync_mode)
5444 DisableVsyncIfNeeded();
5447 static void execSetupChooseGameSpeed(void)
5449 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5454 static void execSetupChooseScrollDelay(void)
5456 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5461 static void execSetupChooseSnapshotMode(void)
5463 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5468 static void execSetupEngines(void)
5470 setup_mode = SETUP_MODE_ENGINES;
5475 static void execSetupEditor(void)
5477 setup_mode = SETUP_MODE_EDITOR;
5482 static void execSetupGraphics_setWindowSizes(boolean update_list)
5484 if (window_sizes != NULL && update_list)
5486 freeTreeInfo(window_sizes);
5488 window_sizes = NULL;
5491 if (window_sizes == NULL)
5493 boolean current_window_size_found = FALSE;
5496 for (i = 0; window_sizes_list[i].value != -1; i++)
5498 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5499 char identifier[32], name[32];
5500 int value = window_sizes_list[i].value;
5501 char *text = window_sizes_list[i].text;
5503 ti->node_top = &window_sizes;
5504 ti->sort_priority = value;
5506 sprintf(identifier, "%d", value);
5507 sprintf(name, "%s", text);
5509 setString(&ti->identifier, identifier);
5510 setString(&ti->name, name);
5511 setString(&ti->name_sorting, name);
5512 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5514 pushTreeInfo(&window_sizes, ti);
5516 if (value == setup.window_scaling_percent)
5517 current_window_size_found = TRUE;
5520 if (!current_window_size_found)
5522 // add entry for non-preset window scaling value
5524 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5525 char identifier[32], name[32];
5526 int value = setup.window_scaling_percent;
5528 ti->node_top = &window_sizes;
5529 ti->sort_priority = value;
5531 sprintf(identifier, "%d", value);
5532 sprintf(name, "%d %% (Current)", value);
5534 setString(&ti->identifier, identifier);
5535 setString(&ti->name, name);
5536 setString(&ti->name_sorting, name);
5537 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5539 pushTreeInfo(&window_sizes, ti);
5542 // sort window size values to start with lowest window size value
5543 sortTreeInfo(&window_sizes);
5545 // set current window size value to configured window size value
5546 window_size_current =
5547 getTreeInfoFromIdentifier(window_sizes,
5548 i_to_a(setup.window_scaling_percent));
5550 // if that fails, set current window size to reliable default value
5551 if (window_size_current == NULL)
5552 window_size_current =
5553 getTreeInfoFromIdentifier(window_sizes,
5554 i_to_a(STD_WINDOW_SCALING_PERCENT));
5556 // if that also fails, set current window size to first available value
5557 if (window_size_current == NULL)
5558 window_size_current = window_sizes;
5561 setup.window_scaling_percent = atoi(window_size_current->identifier);
5563 // needed for displaying window size text instead of identifier
5564 window_size_text = window_size_current->name;
5567 static void execSetupGraphics_setScalingTypes(void)
5569 if (scaling_types == NULL)
5573 for (i = 0; scaling_types_list[i].value != NULL; i++)
5575 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5576 char identifier[32], name[32];
5577 char *value = scaling_types_list[i].value;
5578 char *text = scaling_types_list[i].text;
5580 ti->node_top = &scaling_types;
5581 ti->sort_priority = i;
5583 sprintf(identifier, "%s", value);
5584 sprintf(name, "%s", text);
5586 setString(&ti->identifier, identifier);
5587 setString(&ti->name, name);
5588 setString(&ti->name_sorting, name);
5589 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5591 pushTreeInfo(&scaling_types, ti);
5594 // sort scaling type values to start with lowest scaling type value
5595 sortTreeInfo(&scaling_types);
5597 // set current scaling type value to configured scaling type value
5598 scaling_type_current =
5599 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5601 // if that fails, set current scaling type to reliable default value
5602 if (scaling_type_current == NULL)
5603 scaling_type_current =
5604 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5606 // if that also fails, set current scaling type to first available value
5607 if (scaling_type_current == NULL)
5608 scaling_type_current = scaling_types;
5611 setup.window_scaling_quality = scaling_type_current->identifier;
5613 // needed for displaying scaling type text instead of identifier
5614 scaling_type_text = scaling_type_current->name;
5617 static void execSetupGraphics_setRenderingModes(void)
5619 if (rendering_modes == NULL)
5623 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5625 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5626 char identifier[32], name[32];
5627 char *value = rendering_modes_list[i].value;
5628 char *text = rendering_modes_list[i].text;
5630 ti->node_top = &rendering_modes;
5631 ti->sort_priority = i;
5633 sprintf(identifier, "%s", value);
5634 sprintf(name, "%s", text);
5636 setString(&ti->identifier, identifier);
5637 setString(&ti->name, name);
5638 setString(&ti->name_sorting, name);
5639 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5641 pushTreeInfo(&rendering_modes, ti);
5644 // sort rendering mode values to start with lowest rendering mode value
5645 sortTreeInfo(&rendering_modes);
5647 // set current rendering mode value to configured rendering mode value
5648 rendering_mode_current =
5649 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5651 // if that fails, set current rendering mode to reliable default value
5652 if (rendering_mode_current == NULL)
5653 rendering_mode_current =
5654 getTreeInfoFromIdentifier(rendering_modes,
5655 STR_SPECIAL_RENDERING_DEFAULT);
5657 // if that also fails, set current rendering mode to first available one
5658 if (rendering_mode_current == NULL)
5659 rendering_mode_current = rendering_modes;
5662 setup.screen_rendering_mode = rendering_mode_current->identifier;
5664 // needed for displaying rendering mode text instead of identifier
5665 rendering_mode_text = rendering_mode_current->name;
5668 static void execSetupGraphics_setVsyncModes(boolean update_value)
5670 if (vsync_modes == NULL)
5674 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5676 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5677 char identifier[32], name[32];
5678 char *value = vsync_modes_list[i].value;
5679 char *text = vsync_modes_list[i].text;
5681 ti->node_top = &vsync_modes;
5682 ti->sort_priority = i;
5684 sprintf(identifier, "%s", value);
5685 sprintf(name, "%s", text);
5687 setString(&ti->identifier, identifier);
5688 setString(&ti->name, name);
5689 setString(&ti->name_sorting, name);
5690 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5692 pushTreeInfo(&vsync_modes, ti);
5695 // sort vsync mode values to start with lowest vsync mode value
5696 sortTreeInfo(&vsync_modes);
5698 update_value = TRUE;
5703 // set current vsync mode value to configured vsync mode value
5704 vsync_mode_current =
5705 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5707 // if that fails, set current vsync mode to reliable default value
5708 if (vsync_mode_current == NULL)
5709 vsync_mode_current =
5710 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5712 // if that also fails, set current vsync mode to first available one
5713 if (vsync_mode_current == NULL)
5714 vsync_mode_current = vsync_modes;
5717 setup.vsync_mode = vsync_mode_current->identifier;
5719 // needed for displaying vsync mode text instead of identifier
5720 vsync_mode_text = vsync_mode_current->name;
5723 static void execSetupGraphics(void)
5725 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5727 // update "setup.window_scaling_percent" from list selection
5728 // (in this case, window scaling was changed on setup screen)
5729 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5730 execSetupGraphics_setWindowSizes(FALSE);
5732 // update "setup.vsync_mode" from list selection
5733 // (in this case, vsync mode was changed on setup screen)
5734 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5735 execSetupGraphics_setVsyncModes(FALSE);
5737 // update list selection from "setup.window_scaling_percent"
5738 // (window scaling may have changed by resizing the window)
5739 execSetupGraphics_setWindowSizes(TRUE);
5741 // update list selection from "setup.vsync_mode"
5742 // (vsync_mode may have changed by re-creating the renderer)
5743 execSetupGraphics_setVsyncModes(TRUE);
5745 execSetupGraphics_setScalingTypes();
5746 execSetupGraphics_setRenderingModes();
5748 setup_mode = SETUP_MODE_GRAPHICS;
5752 // check if game speed is high enough for 60 Hz vsync to work
5753 if (check_game_speed)
5754 ModifyGameSpeedIfNeeded();
5756 // window scaling may have changed at this point
5757 ChangeWindowScalingIfNeeded();
5759 // window scaling quality may have changed at this point
5760 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5761 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5763 // screen rendering mode may have changed at this point
5764 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5766 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
5767 int video_vsync_mode = video.vsync_mode;
5769 // screen vsync mode may have changed at this point
5770 ChangeVsyncModeIfNeeded();
5772 // check if setting vsync mode to selected value failed
5773 if (setup_vsync_mode != video_vsync_mode &&
5774 setup_vsync_mode != video.vsync_mode)
5776 // changing vsync mode to selected value failed -- reset displayed value
5777 execSetupGraphics_setVsyncModes(TRUE);
5779 Request("Setting VSync failed!", REQ_CONFIRM);
5785 static void execSetupChooseWindowSize(void)
5787 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5792 static void execSetupChooseScalingType(void)
5794 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5799 static void execSetupChooseRenderingMode(void)
5801 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5806 static void execSetupChooseVsyncMode(void)
5808 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5813 static void execSetupChooseVolumeSimple(void)
5815 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5820 static void execSetupChooseVolumeLoops(void)
5822 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5827 static void execSetupChooseVolumeMusic(void)
5829 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5834 static void execSetupSound(void)
5836 if (volumes_simple == NULL)
5838 boolean current_volume_simple_found = FALSE;
5841 for (i = 0; volumes_list[i].value != -1; i++)
5843 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5844 char identifier[32], name[32];
5845 int value = volumes_list[i].value;
5846 char *text = volumes_list[i].text;
5848 ti->node_top = &volumes_simple;
5849 ti->sort_priority = value;
5851 sprintf(identifier, "%d", value);
5852 sprintf(name, "%s", text);
5854 setString(&ti->identifier, identifier);
5855 setString(&ti->name, name);
5856 setString(&ti->name_sorting, name);
5857 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5859 pushTreeInfo(&volumes_simple, ti);
5861 if (value == setup.volume_simple)
5862 current_volume_simple_found = TRUE;
5865 if (!current_volume_simple_found)
5867 // add entry for non-preset volume value
5869 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5870 char identifier[32], name[32];
5871 int value = setup.volume_simple;
5873 ti->node_top = &volumes_simple;
5874 ti->sort_priority = value;
5876 sprintf(identifier, "%d", value);
5877 sprintf(name, "%d %% (Current)", value);
5879 setString(&ti->identifier, identifier);
5880 setString(&ti->name, name);
5881 setString(&ti->name_sorting, name);
5882 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5884 pushTreeInfo(&volumes_simple, ti);
5887 // sort volume values to start with lowest volume value
5888 sortTreeInfo(&volumes_simple);
5890 // set current volume value to configured volume value
5891 volume_simple_current =
5892 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5894 // if that fails, set current volume to reliable default value
5895 if (volume_simple_current == NULL)
5896 volume_simple_current =
5897 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5899 // if that also fails, set current volume to first available value
5900 if (volume_simple_current == NULL)
5901 volume_simple_current = volumes_simple;
5904 if (volumes_loops == NULL)
5906 boolean current_volume_loops_found = FALSE;
5909 for (i = 0; volumes_list[i].value != -1; i++)
5911 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5912 char identifier[32], name[32];
5913 int value = volumes_list[i].value;
5914 char *text = volumes_list[i].text;
5916 ti->node_top = &volumes_loops;
5917 ti->sort_priority = value;
5919 sprintf(identifier, "%d", value);
5920 sprintf(name, "%s", text);
5922 setString(&ti->identifier, identifier);
5923 setString(&ti->name, name);
5924 setString(&ti->name_sorting, name);
5925 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5927 pushTreeInfo(&volumes_loops, ti);
5929 if (value == setup.volume_loops)
5930 current_volume_loops_found = TRUE;
5933 if (!current_volume_loops_found)
5935 // add entry for non-preset volume value
5937 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5938 char identifier[32], name[32];
5939 int value = setup.volume_loops;
5941 ti->node_top = &volumes_loops;
5942 ti->sort_priority = value;
5944 sprintf(identifier, "%d", value);
5945 sprintf(name, "%d %% (Current)", value);
5947 setString(&ti->identifier, identifier);
5948 setString(&ti->name, name);
5949 setString(&ti->name_sorting, name);
5950 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5952 pushTreeInfo(&volumes_loops, ti);
5955 // sort volume values to start with lowest volume value
5956 sortTreeInfo(&volumes_loops);
5958 // set current volume value to configured volume value
5959 volume_loops_current =
5960 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5962 // if that fails, set current volume to reliable default value
5963 if (volume_loops_current == NULL)
5964 volume_loops_current =
5965 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5967 // if that also fails, set current volume to first available value
5968 if (volume_loops_current == NULL)
5969 volume_loops_current = volumes_loops;
5972 if (volumes_music == NULL)
5974 boolean current_volume_music_found = FALSE;
5977 for (i = 0; volumes_list[i].value != -1; i++)
5979 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5980 char identifier[32], name[32];
5981 int value = volumes_list[i].value;
5982 char *text = volumes_list[i].text;
5984 ti->node_top = &volumes_music;
5985 ti->sort_priority = value;
5987 sprintf(identifier, "%d", value);
5988 sprintf(name, "%s", text);
5990 setString(&ti->identifier, identifier);
5991 setString(&ti->name, name);
5992 setString(&ti->name_sorting, name);
5993 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5995 pushTreeInfo(&volumes_music, ti);
5997 if (value == setup.volume_music)
5998 current_volume_music_found = TRUE;
6001 if (!current_volume_music_found)
6003 // add entry for non-preset volume value
6005 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6006 char identifier[32], name[32];
6007 int value = setup.volume_music;
6009 ti->node_top = &volumes_music;
6010 ti->sort_priority = value;
6012 sprintf(identifier, "%d", value);
6013 sprintf(name, "%d %% (Current)", value);
6015 setString(&ti->identifier, identifier);
6016 setString(&ti->name, name);
6017 setString(&ti->name_sorting, name);
6018 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6020 pushTreeInfo(&volumes_music, ti);
6023 // sort volume values to start with lowest volume value
6024 sortTreeInfo(&volumes_music);
6026 // set current volume value to configured volume value
6027 volume_music_current =
6028 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6030 // if that fails, set current volume to reliable default value
6031 if (volume_music_current == NULL)
6032 volume_music_current =
6033 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6035 // if that also fails, set current volume to first available value
6036 if (volume_music_current == NULL)
6037 volume_music_current = volumes_music;
6040 setup.volume_simple = atoi(volume_simple_current->identifier);
6041 setup.volume_loops = atoi(volume_loops_current->identifier);
6042 setup.volume_music = atoi(volume_music_current->identifier);
6044 // needed for displaying volume text instead of identifier
6045 volume_simple_text = volume_simple_current->name;
6046 volume_loops_text = volume_loops_current->name;
6047 volume_music_text = volume_music_current->name;
6049 setup_mode = SETUP_MODE_SOUND;
6054 static void execSetupChooseTouchControls(void)
6056 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6061 static void execSetupChooseMoveDistance(void)
6063 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6068 static void execSetupChooseDropDistance(void)
6070 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6075 static void execSetupChooseTransparency(void)
6077 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6082 static void execSetupChooseGridXSize_0(void)
6084 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6089 static void execSetupChooseGridYSize_0(void)
6091 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6096 static void execSetupChooseGridXSize_1(void)
6098 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6103 static void execSetupChooseGridYSize_1(void)
6105 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6110 static void execSetupConfigureVirtualButtons(void)
6112 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6114 ConfigureVirtualButtons();
6116 setup_mode = SETUP_MODE_TOUCH;
6121 static void execSetupTouch(void)
6125 if (touch_controls == NULL)
6127 for (i = 0; touch_controls_list[i].value != NULL; i++)
6129 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6130 char identifier[32], name[32];
6131 char *value = touch_controls_list[i].value;
6132 char *text = touch_controls_list[i].text;
6134 ti->node_top = &touch_controls;
6135 ti->sort_priority = i;
6137 sprintf(identifier, "%s", value);
6138 sprintf(name, "%s", text);
6140 setString(&ti->identifier, identifier);
6141 setString(&ti->name, name);
6142 setString(&ti->name_sorting, name);
6143 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6145 pushTreeInfo(&touch_controls, ti);
6148 // sort touch control values to start with lowest touch control value
6149 sortTreeInfo(&touch_controls);
6151 // set current touch control value to configured touch control value
6152 touch_control_current =
6153 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6155 // if that fails, set current touch control to reliable default value
6156 if (touch_control_current == NULL)
6157 touch_control_current =
6158 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6160 // if that also fails, set current touch control to first available value
6161 if (touch_control_current == NULL)
6162 touch_control_current = touch_controls;
6165 if (move_distances == NULL)
6167 for (i = 0; distances_list[i].value != -1; i++)
6169 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6170 char identifier[32], name[32];
6171 int value = distances_list[i].value;
6172 char *text = distances_list[i].text;
6174 ti->node_top = &move_distances;
6175 ti->sort_priority = value;
6177 sprintf(identifier, "%d", value);
6178 sprintf(name, "%s", text);
6180 setString(&ti->identifier, identifier);
6181 setString(&ti->name, name);
6182 setString(&ti->name_sorting, name);
6183 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6185 pushTreeInfo(&move_distances, ti);
6188 // sort distance values to start with lowest distance value
6189 sortTreeInfo(&move_distances);
6191 // set current distance value to configured distance value
6192 move_distance_current =
6193 getTreeInfoFromIdentifier(move_distances,
6194 i_to_a(setup.touch.move_distance));
6196 // if that fails, set current distance to reliable default value
6197 if (move_distance_current == NULL)
6198 move_distance_current =
6199 getTreeInfoFromIdentifier(move_distances,
6200 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6202 // if that also fails, set current distance to first available value
6203 if (move_distance_current == NULL)
6204 move_distance_current = move_distances;
6207 if (drop_distances == NULL)
6209 for (i = 0; distances_list[i].value != -1; i++)
6211 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6212 char identifier[32], name[32];
6213 int value = distances_list[i].value;
6214 char *text = distances_list[i].text;
6216 ti->node_top = &drop_distances;
6217 ti->sort_priority = value;
6219 sprintf(identifier, "%d", value);
6220 sprintf(name, "%s", text);
6222 setString(&ti->identifier, identifier);
6223 setString(&ti->name, name);
6224 setString(&ti->name_sorting, name);
6225 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6227 pushTreeInfo(&drop_distances, ti);
6230 // sort distance values to start with lowest distance value
6231 sortTreeInfo(&drop_distances);
6233 // set current distance value to configured distance value
6234 drop_distance_current =
6235 getTreeInfoFromIdentifier(drop_distances,
6236 i_to_a(setup.touch.drop_distance));
6238 // if that fails, set current distance to reliable default value
6239 if (drop_distance_current == NULL)
6240 drop_distance_current =
6241 getTreeInfoFromIdentifier(drop_distances,
6242 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6244 // if that also fails, set current distance to first available value
6245 if (drop_distance_current == NULL)
6246 drop_distance_current = drop_distances;
6249 if (transparencies == NULL)
6251 for (i = 0; transparencies_list[i].value != -1; i++)
6253 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6254 char identifier[32], name[32];
6255 int value = transparencies_list[i].value;
6256 char *text = transparencies_list[i].text;
6258 ti->node_top = &transparencies;
6259 ti->sort_priority = value;
6261 sprintf(identifier, "%d", value);
6262 sprintf(name, "%s", text);
6264 setString(&ti->identifier, identifier);
6265 setString(&ti->name, name);
6266 setString(&ti->name_sorting, name);
6267 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6269 pushTreeInfo(&transparencies, ti);
6272 // sort transparency values to start with lowest transparency value
6273 sortTreeInfo(&transparencies);
6275 // set current transparency value to configured transparency value
6276 transparency_current =
6277 getTreeInfoFromIdentifier(transparencies,
6278 i_to_a(setup.touch.transparency));
6280 // if that fails, set current transparency to reliable default value
6281 if (transparency_current == NULL)
6282 transparency_current =
6283 getTreeInfoFromIdentifier(transparencies,
6284 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6286 // if that also fails, set current transparency to first available value
6287 if (transparency_current == NULL)
6288 transparency_current = transparencies;
6291 for (i = 0; i < 2; i++)
6293 for (j = 0; j < 2; j++)
6295 if (grid_sizes[i][j] == NULL)
6297 for (k = 0; grid_sizes_list[k].value != -1; k++)
6299 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6300 char identifier[32], name[32];
6301 int value = grid_sizes_list[k].value;
6302 char *text = grid_sizes_list[k].text;
6304 ti->node_top = &grid_sizes[i][j];
6305 ti->sort_priority = value;
6307 sprintf(identifier, "%d", value);
6308 sprintf(name, "%s", text);
6310 setString(&ti->identifier, identifier);
6311 setString(&ti->name, name);
6312 setString(&ti->name_sorting, name);
6313 setString(&ti->infotext,
6316 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6317 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6319 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6320 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6322 pushTreeInfo(&grid_sizes[i][j], ti);
6325 // sort grid size values to start with lowest grid size value
6326 sortTreeInfo(&grid_sizes[i][j]);
6328 // set current grid size value to configured grid size value
6329 grid_size_current[i][j] =
6330 getTreeInfoFromIdentifier(grid_sizes[i][j],
6332 setup.touch.grid_xsize[i] :
6333 setup.touch.grid_ysize[i]));
6335 // if that fails, set current grid size to reliable default value
6336 if (grid_size_current[i][j] == NULL)
6337 grid_size_current[i][j] =
6338 getTreeInfoFromIdentifier(grid_sizes[i][j],
6340 DEFAULT_GRID_XSIZE(i) :
6341 DEFAULT_GRID_YSIZE(i)));
6343 // if that also fails, set current grid size to first available value
6344 if (grid_size_current[i][j] == NULL)
6345 grid_size_current[i][j] = grid_sizes[i][j];
6350 setup.touch.control_type = touch_control_current->identifier;
6351 setup.touch.move_distance = atoi(move_distance_current->identifier);
6352 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6353 setup.touch.transparency = atoi(transparency_current->identifier);
6355 for (i = 0; i < 2; i++)
6357 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6358 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6360 if (i == GRID_ACTIVE_NR())
6362 overlay.grid_xsize = setup.touch.grid_xsize[i];
6363 overlay.grid_ysize = setup.touch.grid_ysize[i];
6367 // needed for displaying value text instead of identifier
6368 touch_controls_text = touch_control_current->name;
6369 move_distance_text = move_distance_current->name;
6370 drop_distance_text = drop_distance_current->name;
6371 transparency_text = transparency_current->name;
6373 for (i = 0; i < 2; i++)
6374 for (j = 0; j < 2; j++)
6375 grid_size_text[i][j] = grid_size_current[i][j]->name;
6377 setup_mode = SETUP_MODE_TOUCH;
6382 static void execSetupArtwork(void)
6384 static ArtworkDirTree *gfx_last_valid = NULL;
6385 static ArtworkDirTree *snd_last_valid = NULL;
6386 static ArtworkDirTree *mus_last_valid = NULL;
6388 // current artwork directory may be invalid (level group, parent link)
6389 if (!validLevelSeries(artwork.gfx_current))
6390 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6391 if (!validLevelSeries(artwork.snd_current))
6392 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6393 if (!validLevelSeries(artwork.mus_current))
6394 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6396 // store valid artwork directory information
6397 gfx_last_valid = artwork.gfx_current;
6398 snd_last_valid = artwork.snd_current;
6399 mus_last_valid = artwork.mus_current;
6402 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6403 artwork.gfx_current->subdir,
6404 artwork.gfx_current->fullpath,
6405 artwork.gfx_current->basepath);
6408 setup.graphics_set = artwork.gfx_current->identifier;
6409 setup.sounds_set = artwork.snd_current->identifier;
6410 setup.music_set = artwork.mus_current->identifier;
6412 // needed if last screen (setup choice) changed graphics, sounds or music
6413 ReloadCustomArtwork(0);
6415 // needed for displaying artwork name instead of artwork identifier
6416 graphics_set_name = artwork.gfx_current->name;
6417 sounds_set_name = artwork.snd_current->name;
6418 music_set_name = artwork.mus_current->name;
6420 setup_mode = SETUP_MODE_ARTWORK;
6425 static void execSetupChooseGraphics(void)
6427 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6432 static void execSetupChooseSounds(void)
6434 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6439 static void execSetupChooseMusic(void)
6441 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6446 static void execSetupInput(void)
6448 setup_mode = SETUP_MODE_INPUT;
6453 static void execSetupShortcuts(void)
6455 setup_mode = SETUP_MODE_SHORTCUTS;
6460 static void execSetupShortcuts1(void)
6462 setup_mode = SETUP_MODE_SHORTCUTS_1;
6467 static void execSetupShortcuts2(void)
6469 setup_mode = SETUP_MODE_SHORTCUTS_2;
6474 static void execSetupShortcuts3(void)
6476 setup_mode = SETUP_MODE_SHORTCUTS_3;
6481 static void execSetupShortcuts4(void)
6483 setup_mode = SETUP_MODE_SHORTCUTS_4;
6488 static void execSetupShortcuts5(void)
6490 setup_mode = SETUP_MODE_SHORTCUTS_5;
6495 static void execExitSetup(void)
6497 SetGameStatus(GAME_MODE_MAIN);
6502 static void execSaveAndExitSetup(void)
6508 static void execGadgetNetworkServer(void)
6510 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6511 struct GadgetInfo *gi = screen_gadget[gadget_id];
6513 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6514 network_server_hostname[0] = '\0';
6516 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6520 ClickOnGadget(gi, MB_LEFTBUTTON);
6523 static void ToggleNetworkModeIfNeeded(void)
6525 int font_title = FONT_TITLE_1;
6526 int font_foot = FC_BLUE;
6527 int ystart = mSY - SY + 16;
6528 int ybottom = mSY - SY + SYSIZE - 20;
6529 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6531 if (setup.network_mode == network.enabled)
6534 network.enabled = setup.network_mode;
6536 FadeOut(REDRAW_ALL);
6540 DrawTextSCentered(ystart, font_title, text);
6544 if (network.enabled)
6545 InitNetworkServer();
6547 DisconnectFromNetworkServer();
6549 DrawTextSCentered(ybottom, font_foot,
6550 "Press any key or button for setup menu");
6552 WaitForEventToContinue();
6557 static void ToggleGameSpeedsListIfNeeded(void)
6559 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6561 if (setup.game_speed_extended == using_game_speeds_extended)
6564 // try to match similar values when changing game speeds list
6565 if (setup.game_speed_extended)
6566 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6567 setup.game_frame_delay == 30 ? 29 :
6568 setup.game_frame_delay);
6570 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6571 setup.game_frame_delay == 16 ? 15 :
6572 setup.game_frame_delay >= 29 ? 30 :
6573 setup.game_frame_delay <= 10 ? 10 :
6574 setup.game_frame_delay);
6576 execSetupGame_setGameSpeeds(TRUE);
6581 static void ModifyGameSpeedIfNeeded(void)
6583 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6584 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6588 char *game_speed_text = "Fast";
6589 int game_speed_value = 15;
6591 if (setup.game_speed_extended)
6593 game_speed_text = "60 fps";
6594 game_speed_value = 16;
6597 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6599 // set game speed to existing list value that is fast enough for vsync
6600 setup.game_frame_delay = game_speed_value;
6602 execSetupGame_setGameSpeeds(TRUE);
6604 Request(message, REQ_CONFIRM);
6607 static void DisableVsyncIfNeeded(void)
6609 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6610 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6611 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6614 // disable vsync for the selected game speed to work
6615 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6617 execSetupGraphics_setVsyncModes(TRUE);
6619 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6625 void *related_value;
6626 } hide_related_entry_list[] =
6628 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6629 { &setup.game_frame_delay, &game_speed_text },
6631 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6632 { &setup.scroll_delay_value, &scroll_delay_text },
6634 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6635 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6637 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6638 { &setup.window_scaling_percent, &window_size_text },
6640 { &setup.window_scaling_quality, execSetupChooseScalingType },
6641 { &setup.window_scaling_quality, &scaling_type_text },
6643 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6644 { &setup.screen_rendering_mode, &rendering_mode_text },
6646 { &setup.vsync_mode, execSetupChooseVsyncMode },
6647 { &setup.vsync_mode, &vsync_mode_text },
6649 { &setup.graphics_set, execSetupChooseGraphics },
6650 { &setup.graphics_set, &graphics_set_name },
6652 { &setup.sounds_set, execSetupChooseSounds },
6653 { &setup.sounds_set, &sounds_set_name },
6655 { &setup.music_set, execSetupChooseMusic },
6656 { &setup.music_set, &music_set_name },
6658 { &setup.volume_simple, execSetupChooseVolumeSimple },
6659 { &setup.volume_simple, &volume_simple_text },
6661 { &setup.volume_loops, execSetupChooseVolumeLoops },
6662 { &setup.volume_loops, &volume_loops_text },
6664 { &setup.volume_music, execSetupChooseVolumeMusic },
6665 { &setup.volume_music, &volume_music_text },
6667 { &setup.touch.control_type, execSetupChooseTouchControls },
6668 { &setup.touch.control_type, &touch_controls_text },
6670 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6671 { &setup.touch.move_distance, &move_distance_text },
6673 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6674 { &setup.touch.drop_distance, &drop_distance_text },
6676 { &setup.touch.transparency, execSetupChooseTransparency },
6677 { &setup.touch.transparency, &transparency_text },
6679 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6680 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6682 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6683 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6685 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6686 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6688 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6689 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6691 { &setup.internal.menu_game, execSetupGame },
6692 { &setup.internal.menu_engines, execSetupEngines },
6693 { &setup.internal.menu_editor, execSetupEditor },
6694 { &setup.internal.menu_graphics, execSetupGraphics },
6695 { &setup.internal.menu_sound, execSetupSound },
6696 { &setup.internal.menu_artwork, execSetupArtwork },
6697 { &setup.internal.menu_input, execSetupInput },
6698 { &setup.internal.menu_touch, execSetupTouch },
6699 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6700 { &setup.internal.menu_exit, execExitSetup },
6701 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6706 void setHideRelatedSetupEntries(void)
6710 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6711 if (hideSetupEntry(hide_related_entry_list[i].value))
6712 setHideSetupEntry(hide_related_entry_list[i].related_value);
6715 static struct TokenInfo setup_info_main[] =
6717 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6718 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6719 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6720 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6721 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6722 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6723 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6724 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6725 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6726 { TYPE_EMPTY, NULL, "" },
6727 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6728 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6733 static struct TokenInfo setup_info_game[] =
6735 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6736 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6737 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6738 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6739 { TYPE_STRING, &network_server_text, "" },
6740 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
6741 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6742 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6743 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6744 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6745 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6746 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6747 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
6748 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
6749 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6750 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
6751 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
6752 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6753 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6754 { TYPE_STRING, &game_speed_text, "" },
6755 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6757 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6758 { TYPE_STRING, &scroll_delay_text, "" },
6760 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6761 { TYPE_STRING, &snapshot_mode_text, "" },
6762 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6763 { TYPE_EMPTY, NULL, "" },
6764 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6769 static struct TokenInfo setup_info_engines[] =
6771 { TYPE_HEADLINE, NULL, "Emerald Mine" },
6772 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
6773 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
6774 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
6775 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
6776 { TYPE_EMPTY, NULL, "" },
6777 { TYPE_HEADLINE, NULL, "Supaplex" },
6778 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
6779 { TYPE_EMPTY, NULL, "" },
6780 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6785 static struct TokenInfo setup_info_editor[] =
6788 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6789 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6790 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6791 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6792 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6793 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6794 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6795 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6796 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6797 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6799 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6800 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6802 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6804 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6805 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6806 { TYPE_EMPTY, NULL, "" },
6808 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6809 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6810 { TYPE_EMPTY, NULL, "" },
6812 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6813 { TYPE_EMPTY, NULL, "" },
6814 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
6815 { TYPE_EMPTY, NULL, "" },
6816 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6821 static struct TokenInfo setup_info_graphics[] =
6823 #if !defined(PLATFORM_ANDROID)
6824 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6825 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6826 { TYPE_STRING, &window_size_text, "" },
6827 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6828 { TYPE_STRING, &scaling_type_text, "" },
6829 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6830 { TYPE_STRING, &rendering_mode_text, "" },
6833 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6834 { TYPE_STRING, &scroll_delay_text, "" },
6836 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6837 { TYPE_STRING, &vsync_mode_text, "" },
6838 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6839 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6840 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6841 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6842 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6843 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6844 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
6845 { TYPE_EMPTY, NULL, "" },
6846 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6851 static struct TokenInfo setup_info_sound[] =
6853 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6854 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6855 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6856 { TYPE_EMPTY, NULL, "" },
6857 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6858 { TYPE_STRING, &volume_simple_text, "" },
6859 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6860 { TYPE_STRING, &volume_loops_text, "" },
6861 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6862 { TYPE_STRING, &volume_music_text, "" },
6863 { TYPE_EMPTY, NULL, "" },
6864 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6869 static struct TokenInfo setup_info_artwork[] =
6871 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6872 { TYPE_STRING, &graphics_set_name, "" },
6873 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6874 { TYPE_STRING, &sounds_set_name, "" },
6875 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6876 { TYPE_STRING, &music_set_name, "" },
6877 { TYPE_EMPTY, NULL, "" },
6878 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6879 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6880 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6881 { TYPE_EMPTY, NULL, "" },
6882 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6887 static struct TokenInfo setup_info_input[] =
6889 { TYPE_SWITCH, NULL, "Player:" },
6890 { TYPE_SWITCH, NULL, "Device:" },
6891 { TYPE_SWITCH, NULL, "" },
6892 { TYPE_SKIPPABLE, NULL, "" },
6893 { TYPE_EMPTY, NULL, "" },
6894 { TYPE_EMPTY, NULL, "" },
6895 { TYPE_EMPTY, NULL, "" },
6896 { TYPE_EMPTY, NULL, "" },
6897 { TYPE_EMPTY, NULL, "" },
6898 { TYPE_EMPTY, NULL, "" },
6899 { TYPE_EMPTY, NULL, "" },
6900 { TYPE_EMPTY, NULL, "" },
6901 { TYPE_SKIPPABLE, NULL, "" },
6902 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6907 static struct TokenInfo setup_info_touch[] =
6909 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6910 { TYPE_STRING, &touch_controls_text, "" },
6911 { TYPE_EMPTY, NULL, "" },
6912 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6917 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6919 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6920 { TYPE_STRING, &touch_controls_text, "" },
6921 { TYPE_EMPTY, NULL, "" },
6922 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6923 { TYPE_STRING, &grid_size_text[0][0], "" },
6924 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6925 { TYPE_STRING, &grid_size_text[0][1], "" },
6926 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6927 { TYPE_STRING, &transparency_text, "" },
6928 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6929 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6930 { TYPE_EMPTY, NULL, "" },
6931 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6932 { TYPE_EMPTY, NULL, "" },
6933 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6938 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6940 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6941 { TYPE_STRING, &touch_controls_text, "" },
6942 { TYPE_EMPTY, NULL, "" },
6943 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6944 { TYPE_STRING, &grid_size_text[1][0], "" },
6945 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6946 { TYPE_STRING, &grid_size_text[1][1], "" },
6947 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6948 { TYPE_STRING, &transparency_text, "" },
6949 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6950 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6951 { TYPE_EMPTY, NULL, "" },
6952 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6953 { TYPE_EMPTY, NULL, "" },
6954 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6959 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6961 setup_info_touch_virtual_buttons_0,
6962 setup_info_touch_virtual_buttons_1
6965 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6967 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6968 { TYPE_STRING, &touch_controls_text, "" },
6969 { TYPE_EMPTY, NULL, "" },
6970 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6971 { TYPE_STRING, &move_distance_text, "" },
6972 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6973 { TYPE_STRING, &drop_distance_text, "" },
6974 { TYPE_EMPTY, NULL, "" },
6975 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6980 static struct TokenInfo setup_info_shortcuts[] =
6982 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6983 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6984 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6985 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6986 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6987 { TYPE_EMPTY, NULL, "" },
6988 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6993 static struct TokenInfo setup_info_shortcuts_1[] =
6995 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6996 { TYPE_KEY, &setup.shortcut.save_game, "" },
6997 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6998 { TYPE_KEY, &setup.shortcut.load_game, "" },
6999 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7000 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7001 { TYPE_EMPTY, NULL, "" },
7002 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7003 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7004 { TYPE_EMPTY, NULL, "" },
7005 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7010 static struct TokenInfo setup_info_shortcuts_2[] =
7012 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7013 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7014 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7015 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7016 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7017 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7018 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7019 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7020 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7021 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7022 { TYPE_EMPTY, NULL, "" },
7023 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7028 static struct TokenInfo setup_info_shortcuts_3[] =
7030 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7031 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7032 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7033 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7034 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7035 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7036 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7037 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7038 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7039 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7040 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7041 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7042 { TYPE_EMPTY, NULL, "" },
7043 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7048 static struct TokenInfo setup_info_shortcuts_4[] =
7050 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7051 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7052 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7053 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7054 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7055 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7056 { TYPE_EMPTY, NULL, "" },
7057 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7062 static struct TokenInfo setup_info_shortcuts_5[] =
7064 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7065 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7066 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7067 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7068 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7069 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7070 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7071 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7072 { TYPE_EMPTY, NULL, "" },
7073 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7078 static Key getSetupKey(void)
7080 Key key = KSYM_UNDEFINED;
7081 boolean got_key_event = FALSE;
7083 while (!got_key_event)
7087 if (NextValidEvent(&event))
7091 case EVENT_KEYPRESS:
7093 key = GetEventKey((KeyEvent *)&event, TRUE);
7095 // press 'Escape' or 'Enter' to keep the existing key binding
7096 if (key == KSYM_Escape || key == KSYM_Return)
7097 key = KSYM_UNDEFINED; // keep old value
7099 got_key_event = TRUE;
7103 case EVENT_KEYRELEASE:
7104 key_joystick_mapping = 0;
7108 HandleOtherEvents(&event);
7119 static int getSetupValueFont(int type, void *value)
7121 if (type & TYPE_GHOSTED)
7122 return FONT_OPTION_OFF;
7123 else if (type & TYPE_KEY)
7124 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7125 else if (type & TYPE_STRING)
7126 return FONT_VALUE_2;
7127 else if (type & TYPE_ECS_AGA)
7128 return FONT_VALUE_1;
7129 else if (type & TYPE_BOOLEAN_STYLE)
7130 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7131 else if (type & TYPE_YES_NO_AUTO)
7132 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7133 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7134 else if (type & TYPE_PLAYER)
7135 return FONT_VALUE_1;
7137 return FONT_VALUE_1;
7140 static int getSetupValueFontNarrow(int type, int font_nr)
7142 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7143 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7144 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7148 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7150 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7151 struct TokenInfo *si = &setup_info[si_pos];
7152 boolean font_draw_xoffset_modified = FALSE;
7153 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7154 int font_draw_xoffset_old = -1;
7155 int xoffset = (scrollbar_needed ? -1 : 0);
7156 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7157 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7158 int xpos = menu_screen_value_xpos;
7159 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7160 int startx = mSX + xpos * 32;
7161 int starty = mSY + ypos * 32;
7162 int type = si->type;
7163 void *value = si->value;
7164 char *value_string = getSetupValue(type, value);
7165 int font_nr_default = getSetupValueFont(type, value);
7166 int font_width_default = getFontWidth(font_nr_default);
7167 int font_nr = font_nr_default;
7170 if (value_string == NULL)
7173 if (type & TYPE_KEY)
7175 xpos = MENU_SCREEN_START_XPOS;
7177 if (type & TYPE_QUERY)
7178 value_string = "<press key>";
7180 else if (type & TYPE_STRING)
7182 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7184 xpos = MENU_SCREEN_START_XPOS;
7186 if (strlen(value_string) > max_value_len)
7187 value_string[max_value_len] = '\0';
7189 else if (type & TYPE_YES_NO_AUTO)
7191 xpos = menu_screen_value_xpos - 1;
7193 else if (type & TYPE_PLAYER)
7195 int displayed_player_nr = *(int *)value + 1;
7197 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7200 startx = mSX + xpos * 32;
7201 starty = mSY + ypos * 32;
7203 // special check if right-side setup values moved left due to scrollbar
7204 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7206 int max_menu_text_length = 26; // maximum text length for classic menu
7207 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7208 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7209 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7210 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7211 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7213 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7215 // when using narrow font, left-shifting text "auto" not needed
7216 if (type & TYPE_YES_NO_AUTO)
7220 startx = mSX + xpos * 32;
7222 font_nr = getSetupValueFontNarrow(type, font_nr);
7226 // downward compatibility correction for Juergen Bonhagen's menu settings
7227 if (setup_mode != SETUP_MODE_INPUT)
7229 int max_menu_text_length_big = (menu_screen_value_xpos -
7230 MENU_SCREEN_START_XPOS);
7231 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7232 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7233 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7234 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
7235 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7236 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7237 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7238 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7239 boolean correct_font_draw_xoffset = FALSE;
7241 if (xpos == MENU_SCREEN_START_XPOS &&
7242 startx + font1_xoffset < text_startx + text_font_xoffset)
7243 correct_font_draw_xoffset = TRUE;
7245 if (xpos == menu_screen_value_xpos &&
7246 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7247 correct_font_draw_xoffset = TRUE;
7249 // check if setup value would overlap with setup text when printed
7250 // (this can happen for extreme/wrong values for font draw offset)
7251 if (correct_font_draw_xoffset)
7253 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
7254 font_draw_xoffset_modified = TRUE;
7256 if (type & TYPE_KEY)
7257 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7258 else if (!(type & TYPE_STRING))
7259 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7260 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7264 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7265 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7267 DrawText(startx, starty, value_string, font_nr);
7269 if (type & TYPE_PLAYER)
7271 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7272 int player_nr = *(int *)value;
7273 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7274 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7275 int startx2 = startx + xoff;
7276 int starty2 = starty + yoff;
7278 if (DrawingOnBackground(startx2, starty2))
7279 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7281 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7282 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7285 if (font_draw_xoffset_modified)
7286 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7289 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7291 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7292 struct TokenInfo *si = &setup_info[si_pos];
7294 if (si->type & TYPE_BOOLEAN_STYLE)
7296 *(boolean *)si->value ^= TRUE;
7298 else if (si->type & TYPE_YES_NO_AUTO)
7302 (*(int *)si->value == AUTO ? TRUE :
7303 *(int *)si->value == TRUE ? FALSE : AUTO) :
7304 (*(int *)si->value == TRUE ? AUTO :
7305 *(int *)si->value == AUTO ? FALSE : TRUE));
7307 else if (si->type & TYPE_KEY)
7311 si->type |= TYPE_QUERY;
7312 drawSetupValue(screen_pos, setup_info_pos_raw);
7313 si->type &= ~TYPE_QUERY;
7315 key = getSetupKey();
7316 if (key != KSYM_UNDEFINED)
7317 *(Key *)si->value = key;
7319 else if (si->type & TYPE_PLAYER)
7321 int player_nr = *(int *)si->value;
7326 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7328 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7331 drawSetupValue(screen_pos, setup_info_pos_raw);
7333 // fullscreen state may have changed at this point
7334 if (si->value == &setup.fullscreen)
7335 ToggleFullscreenIfNeeded();
7337 // network mode may have changed at this point
7338 if (si->value == &setup.network_mode)
7339 ToggleNetworkModeIfNeeded();
7341 // game speed list may have changed at this point
7342 if (si->value == &setup.game_speed_extended)
7343 ToggleGameSpeedsListIfNeeded();
7346 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7348 static struct TokenInfo *setup_info_final = NULL;
7353 // determine maximum list size of target list
7354 while (setup_info_orig[list_size++].type != 0);
7356 // free, allocate and clear memory for target list
7357 checked_free(setup_info_final);
7358 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7360 // copy setup info list without setup entries marked as hidden
7361 for (i = 0; setup_info_orig[i].type != 0; i++)
7363 // skip setup entries configured to be hidden
7364 if (hideSetupEntry(setup_info_orig[i].value))
7367 // skip skippable setup entries if screen is lower than usual
7368 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7369 setup_info_orig[i].type == TYPE_SKIPPABLE)
7372 setup_info_final[list_pos++] = setup_info_orig[i];
7375 return setup_info_final;
7378 static void DrawSetupScreen_Generic(void)
7380 int fade_mask = REDRAW_FIELD;
7381 boolean redraw_all = FALSE;
7382 char *title_string = NULL;
7386 fade_mask = REDRAW_ALL;
7389 FadeMenuSoundsAndMusic();
7391 FreeScreenGadgets();
7392 CreateScreenGadgets();
7394 if (redraw_mask & REDRAW_ALL)
7399 // needed if different viewport properties defined for setup screen
7400 ChangeViewportPropertiesIfNeeded();
7402 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7406 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7408 if (setup_mode == SETUP_MODE_MAIN)
7410 setup_info = setup_info_main;
7411 title_string = STR_SETUP_MAIN;
7413 else if (setup_mode == SETUP_MODE_GAME)
7415 setup_info = setup_info_game;
7416 title_string = STR_SETUP_GAME;
7418 else if (setup_mode == SETUP_MODE_ENGINES)
7420 setup_info = setup_info_engines;
7421 title_string = STR_SETUP_ENGINES;
7423 else if (setup_mode == SETUP_MODE_EDITOR)
7425 setup_info = setup_info_editor;
7426 title_string = STR_SETUP_EDITOR;
7428 else if (setup_mode == SETUP_MODE_GRAPHICS)
7430 setup_info = setup_info_graphics;
7431 title_string = STR_SETUP_GRAPHICS;
7433 else if (setup_mode == SETUP_MODE_SOUND)
7435 setup_info = setup_info_sound;
7436 title_string = STR_SETUP_SOUND;
7438 else if (setup_mode == SETUP_MODE_ARTWORK)
7440 setup_info = setup_info_artwork;
7441 title_string = STR_SETUP_ARTWORK;
7443 else if (setup_mode == SETUP_MODE_TOUCH)
7445 setup_info = setup_info_touch;
7446 title_string = STR_SETUP_TOUCH;
7448 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7449 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7450 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7451 setup_info = setup_info_touch_wipe_gestures;
7453 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7455 setup_info = setup_info_shortcuts;
7456 title_string = STR_SETUP_SHORTCUTS;
7458 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7460 setup_info = setup_info_shortcuts_1;
7461 title_string = STR_SETUP_SHORTCUTS;
7463 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7465 setup_info = setup_info_shortcuts_2;
7466 title_string = STR_SETUP_SHORTCUTS;
7468 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7470 setup_info = setup_info_shortcuts_3;
7471 title_string = STR_SETUP_SHORTCUTS;
7473 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7475 setup_info = setup_info_shortcuts_4;
7476 title_string = STR_SETUP_SHORTCUTS;
7478 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7480 setup_info = setup_info_shortcuts_5;
7481 title_string = STR_SETUP_SHORTCUTS;
7484 // use modified setup info without setup entries marked as hidden
7485 setup_info = getSetupInfoFinal(setup_info);
7487 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7489 // determine maximal number of setup entries that can be displayed on screen
7491 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7494 // determine maximal number of setup entries available for this setup screen
7496 for (i = 0; setup_info[i].type != 0; i++)
7499 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7501 MapScreenGadgets(max_setup_info);
7504 redraw_mask = fade_mask = REDRAW_ALL;
7506 DrawMaskedBorder(fade_mask);
7511 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7513 menu_info = setup_info;
7515 HandleMenuScreen(mx, my, dx, dy, button,
7516 setup_mode, num_setup_info, max_setup_info);
7519 static void DrawSetupScreen_Input(void)
7523 FadeOut(REDRAW_FIELD);
7527 setup_info = getSetupInfoFinal(setup_info_input);
7529 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7531 for (i = 0; setup_info[i].type != 0; i++)
7533 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7534 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7535 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7536 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7537 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7538 initCursor(i, IMG_MENU_BUTTON);
7540 DrawCursorAndText_Setup(i, -1, FALSE);
7543 // create gadgets for setup input menu screen
7544 FreeScreenGadgets();
7545 CreateScreenGadgets();
7547 // map gadgets for setup input menu screen
7548 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7550 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7552 FadeIn(REDRAW_FIELD);
7555 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7557 if (device_name == NULL)
7560 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7563 if (strlen(device_name) > 1)
7565 char c1 = device_name[strlen(device_name) - 1];
7566 char c2 = device_name[strlen(device_name) - 2];
7568 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7569 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7572 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7573 strlen(device_name));
7576 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7579 static struct SetupKeyboardInfo custom_key;
7586 { &custom_key.left, "Axis/Pad Left" },
7587 { &custom_key.right, "Axis/Pad Right" },
7588 { &custom_key.up, "Axis/Pad Up" },
7589 { &custom_key.down, "Axis/Pad Down" },
7590 { &custom_key.snap, "Button 1/A/X" },
7591 { &custom_key.drop, "Button 2/B/Y" }
7593 static char *joystick_name[MAX_PLAYERS] =
7600 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7601 int font_nr_info = FONT_MENU_1;
7602 int font_nr_name = FONT_VALUE_OLD;
7603 int font_nr_on = FONT_VALUE_1;
7604 int font_nr_off = FONT_VALUE_OLD;
7607 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7609 font_nr_info = FONT_MENU_2;
7610 font_nr_on = FONT_VALUE_NARROW;
7611 font_nr_off = FONT_VALUE_OLD_NARROW;
7614 custom_key = setup.input[player_nr].key;
7616 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7617 FONT_INPUT_1_ACTIVE);
7619 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7621 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7622 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7624 if (setup.input[player_nr].use_joystick)
7626 char *device_name = setup.input[player_nr].joy.device_name;
7627 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7628 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7629 char *text = joystick_name[joystick_nr];
7630 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7632 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7633 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7637 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7638 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7641 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7642 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7646 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7647 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7648 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7649 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7651 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7652 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7653 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7654 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7655 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7656 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7658 for (i = 0; i < 6; i++)
7660 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7662 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7664 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7665 (setup.input[player_nr].use_joystick ?
7667 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7671 static int input_player_nr = 0;
7673 static void HandleSetupScreen_Input_Player(int step, int direction)
7675 int old_player_nr = input_player_nr;
7678 new_player_nr = old_player_nr + step * direction;
7679 if (new_player_nr < 0)
7681 if (new_player_nr > MAX_PLAYERS - 1)
7682 new_player_nr = MAX_PLAYERS - 1;
7684 if (new_player_nr != old_player_nr)
7686 input_player_nr = new_player_nr;
7688 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7692 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7694 static int choice = 0;
7697 int pos_start = SETUPINPUT_SCREEN_POS_START;
7698 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7699 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7700 int pos_end = SETUPINPUT_SCREEN_POS_END;
7702 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7706 for (i = 0; setup_info_input[i].type != 0; i++)
7708 // adjust menu structure according to skipped setup entries
7709 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7717 if (button == MB_MENU_INITIALIZE)
7719 // input setup menu may have changed size due to graphics configuration
7720 if (choice >= pos_empty1)
7723 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7725 DrawCursorAndText_Setup(choice, -1, TRUE);
7729 else if (button == MB_MENU_LEAVE)
7731 setup_mode = SETUP_MODE_MAIN;
7738 if (mx || my) // mouse input
7740 x = (mx - mSX) / 32;
7741 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7743 else if (dx || dy) // keyboard input
7745 if (dx && choice == 0)
7746 x = (dx < 0 ? 10 : 12);
7747 else if ((dx && choice == 1) ||
7748 (dx == -1 && choice == pos_end))
7749 button = MB_MENU_CHOICE;
7753 if (y >= pos_empty1 && y <= pos_empty2)
7754 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7757 if (y == 0 && dx != 0 && button)
7759 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7761 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7762 y >= pos_start && y <= pos_end &&
7763 !(y >= pos_empty1 && y <= pos_empty2))
7769 DrawCursorAndText_Setup(choice, -1, FALSE);
7770 DrawCursorAndText_Setup(y, -1, TRUE);
7772 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7781 char *device_name = setup.input[input_player_nr].joy.device_name;
7783 if (!setup.input[input_player_nr].use_joystick)
7785 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7787 setJoystickDeviceToNr(device_name, new_device_nr);
7788 setup.input[input_player_nr].use_joystick = TRUE;
7792 int device_nr = getJoystickNrFromDeviceName(device_name);
7793 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7795 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7796 setup.input[input_player_nr].use_joystick = FALSE;
7798 setJoystickDeviceToNr(device_name, new_device_nr);
7801 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7805 if (setup.input[input_player_nr].use_joystick)
7806 ConfigureJoystick(input_player_nr);
7808 CustomizeKeyboard(input_player_nr);
7810 else if (y == pos_end)
7816 setup_mode = SETUP_MODE_MAIN;
7823 static boolean CustomizeKeyboardMain(int player_nr)
7827 boolean finished = FALSE;
7828 static struct SetupKeyboardInfo custom_key;
7833 } customize_step[] =
7835 { &custom_key.left, "Move Left" },
7836 { &custom_key.right, "Move Right" },
7837 { &custom_key.up, "Move Up" },
7838 { &custom_key.down, "Move Down" },
7839 { &custom_key.snap, "Snap Field" },
7840 { &custom_key.drop, "Drop Element" }
7842 int font_nr_old = FONT_VALUE_OLD;
7843 int font_nr_new = FONT_VALUE_1;
7844 boolean success = FALSE;
7846 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7848 font_nr_old = FONT_VALUE_OLD_NARROW;
7849 font_nr_new = FONT_VALUE_NARROW;
7852 // read existing key bindings from player setup
7853 custom_key = setup.input[player_nr].key;
7856 FadeOut(REDRAW_FIELD);
7860 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7863 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7864 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7865 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7866 "Key:", FONT_INPUT_1_ACTIVE);
7867 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7868 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7870 FadeIn(REDRAW_FIELD);
7876 if (NextValidEvent(&event))
7880 case EVENT_KEYPRESS:
7882 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7884 // press 'Escape' to abort and keep the old key bindings
7885 if (key == KSYM_Escape)
7887 FadeSkipNextFadeIn();
7894 // press 'Enter' to keep the existing key binding
7895 if (key == KSYM_Return)
7896 key = *customize_step[step_nr].key;
7898 // check if key already used
7899 for (i = 0; i < step_nr; i++)
7900 if (*customize_step[i].key == key)
7905 // got new key binding
7906 *customize_step[step_nr].key = key;
7907 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7909 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7910 getKeyNameFromKey(key), font_nr_new);
7913 // un-highlight last query
7914 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7915 customize_step[step_nr - 1].text, FONT_MENU_1);
7916 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7917 "Key:", FONT_MENU_1);
7919 // all keys configured
7928 // query next key binding
7929 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7930 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7931 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7932 "Key:", FONT_INPUT_1_ACTIVE);
7933 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7934 getKeyNameFromKey(*customize_step[step_nr].key),
7939 case EVENT_KEYRELEASE:
7940 key_joystick_mapping = 0;
7944 HandleOtherEvents(&event);
7952 // write new key bindings back to player setup, if successfully finished
7954 setup.input[player_nr].key = custom_key;
7959 void CustomizeKeyboard(int player_nr)
7961 boolean success = CustomizeKeyboardMain(player_nr);
7965 int font_nr = FONT_TITLE_1;
7966 int font_height = getFontHeight(font_nr);
7967 int ypos1 = SYSIZE / 2 - font_height * 2;
7968 int ypos2 = SYSIZE / 2 - font_height * 1;
7969 unsigned int wait_frame_delay = 0;
7970 unsigned int wait_frame_delay_value = 2000;
7972 ResetDelayCounter(&wait_frame_delay);
7976 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7977 DrawTextSCentered(ypos2, font_nr, "configured!");
7979 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7985 DrawSetupScreen_Input();
7988 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
7990 #define MARKER_BUTTON 1
7991 #define MARKER_AXIS_X 2
7992 #define MARKER_AXIS_Y 3
7994 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7996 static boolean bitmaps_initialized = FALSE;
7997 boolean screen_initialized = FALSE;
7998 static Bitmap *controller, *button, *axis_x, *axis_y;
8000 boolean success = TRUE;
8001 boolean done = FALSE, next = FALSE;
8003 int alpha = 200, alpha_step = -1;
8004 int alpha_ticks = 0;
8005 char mapping[4096], temp[256];
8006 int font_name = MENU_SETUP_FONT_TITLE;
8007 int font_info = MENU_SETUP_FONT_TEXT;
8008 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8009 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8010 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8011 int ystep_name = getMenuTextStep(spacing_name, font_name);
8012 int ystep_line = getMenuTextStep(spacing_line, font_info);
8013 int ystep_para = getMenuTextStep(spacing_para, font_info);
8021 int axis, button, hat, hat_value;
8024 *step, *prev_step, steps[] =
8026 { 356, 155, MARKER_BUTTON, "a", },
8027 { 396, 122, MARKER_BUTTON, "b", },
8028 { 320, 125, MARKER_BUTTON, "x", },
8029 { 358, 95, MARKER_BUTTON, "y", },
8030 { 162, 125, MARKER_BUTTON, "back", },
8031 { 216, 125, MARKER_BUTTON, "guide", },
8032 { 271, 125, MARKER_BUTTON, "start", },
8033 { 110, 200, MARKER_BUTTON, "dpleft", },
8034 { 146, 228, MARKER_BUTTON, "dpdown", },
8035 { 178, 200, MARKER_BUTTON, "dpright", },
8036 { 146, 172, MARKER_BUTTON, "dpup", },
8037 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8038 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8039 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8040 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8041 { 73, 141, MARKER_BUTTON, "leftstick", },
8042 { 282, 210, MARKER_BUTTON, "rightstick", },
8043 { 73, 141, MARKER_AXIS_X, "leftx", },
8044 { 73, 141, MARKER_AXIS_Y, "lefty", },
8045 { 282, 210, MARKER_AXIS_X, "rightx", },
8046 { 282, 210, MARKER_AXIS_Y, "righty", },
8049 unsigned int event_frame_delay = 0;
8050 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8052 ResetDelayCounter(&event_frame_delay);
8054 if (!bitmaps_initialized)
8056 controller = LoadCustomImage("joystick/controller.png");
8057 button = LoadCustomImage("joystick/button.png");
8058 axis_x = LoadCustomImage("joystick/axis_x.png");
8059 axis_y = LoadCustomImage("joystick/axis_y.png");
8061 bitmaps_initialized = TRUE;
8064 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8067 // print info about the joystick we are watching
8068 Debug("joystick", "watching joystick %d: (%s)",
8069 SDL_JoystickInstanceID(joystick), name);
8070 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8071 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8072 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8075 // initialize mapping with GUID and name
8076 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8078 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8079 temp, name, SDL_GetPlatform());
8081 // loop through all steps (buttons and axes), getting joystick events
8082 for (i = 0; i < SDL_arraysize(steps) && !done;)
8084 Bitmap *marker = button; // initialize with reliable default value
8087 strcpy(step->mapping, mapping);
8091 step->hat_value = -1;
8093 marker = (step->marker == MARKER_BUTTON ? button :
8094 step->marker == MARKER_AXIS_X ? axis_x :
8095 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8099 while (!done && !next)
8101 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8102 alpha_ticks = SDL_GetTicks();
8109 else if (alpha < 128)
8115 int controller_x = SX + (SXSIZE - controller->width) / 2;
8116 int controller_y = SY + ystep_line;
8118 int marker_x = controller_x + step->x;
8119 int marker_y = controller_y + step->y;
8121 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8122 int ystart2 = ystart1 + ystep_name + ystep_line;
8126 DrawTextSCentered(ystart1, font_name, name);
8128 DrawTextSCentered(ystart2, font_info,
8129 "Press buttons and move axes on");
8130 ystart2 += ystep_line;
8131 DrawTextSCentered(ystart2, font_info,
8132 "your controller when indicated.");
8133 ystart2 += ystep_line;
8134 DrawTextSCentered(ystart2, font_info,
8135 "(Your controller may look different.)");
8136 ystart2 += ystep_para;
8138 #if defined(PLATFORM_ANDROID)
8139 DrawTextSCentered(ystart2, font_info,
8140 "To correct a mistake,");
8141 ystart2 += ystep_line;
8142 DrawTextSCentered(ystart2, font_info,
8143 "press the 'back' button.");
8144 ystart2 += ystep_line;
8145 DrawTextSCentered(ystart2, font_info,
8146 "To skip a button or axis,");
8147 ystart2 += ystep_line;
8148 DrawTextSCentered(ystart2, font_info,
8149 "press the 'menu' button.");
8151 DrawTextSCentered(ystart2, font_info,
8152 "To correct a mistake,");
8153 ystart2 += ystep_line;
8154 DrawTextSCentered(ystart2, font_info,
8155 "press the 'backspace' key.");
8156 ystart2 += ystep_line;
8157 DrawTextSCentered(ystart2, font_info,
8158 "To skip a button or axis,");
8159 ystart2 += ystep_line;
8160 DrawTextSCentered(ystart2, font_info,
8161 "press the 'return' key.");
8162 ystart2 += ystep_line;
8163 DrawTextSCentered(ystart2, font_info,
8164 "To exit, press the 'escape' key.");
8167 BlitBitmapMasked(controller, drawto, 0, 0,
8168 controller->width, controller->height,
8169 controller_x, controller_y);
8171 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8172 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8174 BlitBitmapMasked(marker, drawto, 0, 0,
8175 marker->width, marker->height,
8176 marker_x, marker_y);
8178 if (!screen_initialized)
8179 FadeIn(REDRAW_FIELD);
8183 screen_initialized = TRUE;
8185 while (NextValidEvent(&event))
8189 case SDL_JOYAXISMOTION:
8190 if (event.jaxis.value > 20000 ||
8191 event.jaxis.value < -20000)
8193 for (j = 0; j < i; j++)
8194 if (steps[j].axis == event.jaxis.axis)
8199 if (step->marker != MARKER_AXIS_X &&
8200 step->marker != MARKER_AXIS_Y)
8203 step->axis = event.jaxis.axis;
8204 strcat(mapping, step->field);
8205 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8206 strcat(mapping, temp);
8214 case SDL_JOYHATMOTION:
8215 // ignore centering; we're probably just coming back
8216 // to the center from the previous item we set
8217 if (event.jhat.value == SDL_HAT_CENTERED)
8220 for (j = 0; j < i; j++)
8221 if (steps[j].hat == event.jhat.hat &&
8222 steps[j].hat_value == event.jhat.value)
8227 step->hat = event.jhat.hat;
8228 step->hat_value = event.jhat.value;
8229 strcat(mapping, step->field);
8230 snprintf(temp, sizeof(temp), ":h%u.%u,",
8231 event.jhat.hat, event.jhat.value );
8232 strcat(mapping, temp);
8239 case SDL_JOYBALLMOTION:
8242 case SDL_JOYBUTTONUP:
8243 for (j = 0; j < i; j++)
8244 if (steps[j].button == event.jbutton.button)
8249 step->button = event.jbutton.button;
8250 strcat(mapping, step->field);
8251 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8252 strcat(mapping, temp);
8259 case SDL_FINGERDOWN:
8260 case SDL_MOUSEBUTTONDOWN:
8268 if (event.key.keysym.sym == KSYM_BackSpace ||
8269 event.key.keysym.sym == KSYM_Back)
8281 prev_step = &steps[i - 1];
8282 strcpy(mapping, prev_step->mapping);
8289 if (event.key.keysym.sym == KSYM_space ||
8290 event.key.keysym.sym == KSYM_Return ||
8291 event.key.keysym.sym == KSYM_Menu)
8300 if (event.key.keysym.sym == KSYM_Escape)
8310 program.exit_function(0);
8317 // do not handle events for longer than standard frame delay period
8318 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8327 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8330 // activate mapping for this game
8331 SDL_GameControllerAddMapping(mapping);
8333 // save mapping to personal mappings
8334 SaveSetup_AddGameControllerMapping(mapping);
8337 // wait until the last pending event was removed from event queue
8338 while (NextValidEvent(&event));
8343 static int ConfigureJoystickMain(int player_nr)
8345 char *device_name = setup.input[player_nr].joy.device_name;
8346 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8347 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8348 int success = FALSE;
8351 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8352 return JOYSTICK_NOT_AVAILABLE;
8354 if (!joystick_active || !setup.input[player_nr].use_joystick)
8355 return JOYSTICK_NOT_AVAILABLE;
8358 FadeOut(REDRAW_FIELD);
8360 // close all joystick devices (potentially opened as game controllers)
8361 for (i = 0; i < SDL_NumJoysticks(); i++)
8362 SDLCloseJoystick(i);
8364 // open joystick device as plain joystick to configure as game controller
8365 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8367 // as the joystick was successfully opened before, this should not happen
8368 if (joystick == NULL)
8371 // create new game controller mapping (buttons and axes) for joystick device
8372 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8374 // close joystick (and maybe re-open as configured game controller later)
8375 SDL_JoystickClose(joystick);
8377 // re-open all joystick devices (potentially as game controllers)
8378 for (i = 0; i < SDL_NumJoysticks(); i++)
8381 // clear all joystick input actions for all joystick devices
8382 SDLClearJoystickState();
8384 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8387 void ConfigureJoystick(int player_nr)
8389 boolean state = ConfigureJoystickMain(player_nr);
8391 if (state != JOYSTICK_NOT_CONFIGURED)
8393 boolean success = (state == JOYSTICK_CONFIGURED);
8394 char message1[MAX_OUTPUT_LINESIZE + 1];
8395 char *message2 = (success ? "configured!" : "not available!");
8396 char *device_name = setup.input[player_nr].joy.device_name;
8397 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8398 int font_nr = FONT_TITLE_1;
8399 int font_height = getFontHeight(font_nr);
8400 int ypos1 = SYSIZE / 2 - font_height * 2;
8401 int ypos2 = SYSIZE / 2 - font_height * 1;
8402 unsigned int wait_frame_delay = 0;
8403 unsigned int wait_frame_delay_value = 2000;
8405 ResetDelayCounter(&wait_frame_delay);
8409 sprintf(message1, "Joystick %d", nr);
8411 DrawTextSCentered(ypos1, font_nr, message1);
8412 DrawTextSCentered(ypos2, font_nr, message2);
8414 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8420 DrawSetupScreen_Input();
8423 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8425 if (y < video.screen_height / 3)
8427 // remap touch gadgets to access upper part of the screen
8428 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8429 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8431 else if (y > 2 * video.screen_height / 3)
8433 // remap touch gadgets to access lower part of the screen
8434 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8435 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8439 static boolean ConfigureVirtualButtonsMain(void)
8441 static char *customize_step_text[] =
8450 char grid_button[] =
8452 CHAR_GRID_BUTTON_LEFT,
8453 CHAR_GRID_BUTTON_RIGHT,
8454 CHAR_GRID_BUTTON_UP,
8455 CHAR_GRID_BUTTON_DOWN,
8456 CHAR_GRID_BUTTON_SNAP,
8457 CHAR_GRID_BUTTON_DROP
8466 int font_nr = FONT_INPUT_1_ACTIVE;
8467 int font_height = getFontHeight(font_nr);
8468 int ypos1 = SYSIZE / 2 - font_height * 2;
8469 int ypos2 = SYSIZE / 2 - font_height * 1;
8470 boolean success = FALSE;
8471 boolean finished = FALSE;
8473 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8474 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8475 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8476 boolean set_grid_button = FALSE;
8477 int nr = GRID_ACTIVE_NR();
8480 for (x = 0; x < MAX_GRID_XSIZE; x++)
8481 for (y = 0; y < MAX_GRID_YSIZE; y++)
8482 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8484 overlay.grid_button_highlight = grid_button[step_nr];
8489 FadeOut(REDRAW_FIELD);
8493 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8494 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8495 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8497 FadeIn(REDRAW_FIELD);
8499 SetOverlayShowGrid(TRUE);
8501 // map gadgets for setup touch buttons menu screen
8502 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8508 while (NextValidEvent(&event))
8510 int action = ACTION_NONE;
8512 // ---------- handle events and set the resulting action ----------
8518 UserEvent *user = (UserEvent *)&event;
8519 int id = user->value1;
8521 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8522 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8523 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8524 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8529 case EVENT_KEYPRESS:
8531 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8533 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8534 key == KSYM_BackSpace ||
8535 key == KSYM_Back ? ACTION_BACK :
8536 key == KSYM_Return ||
8538 key == KSYM_space ? ACTION_NEXT :
8543 case EVENT_KEYRELEASE:
8544 key_joystick_mapping = 0;
8547 case EVENT_BUTTONPRESS:
8548 case EVENT_BUTTONRELEASE:
8550 ButtonEvent *button = (ButtonEvent *)&event;
8552 motion_status = FALSE;
8554 if (button->type == EVENT_BUTTONPRESS)
8555 button_status = button->button;
8557 button_status = MB_RELEASED;
8559 if (HandleGadgets(button->x, button->y, button_status))
8561 // do not handle this button event anymore
8565 button->x += video.screen_xoffset;
8566 button->y += video.screen_yoffset;
8568 x = button->x * overlay.grid_xsize / video.screen_width;
8569 y = button->y * overlay.grid_ysize / video.screen_height;
8571 if (button->type == EVENT_BUTTONPRESS)
8574 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8575 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8577 set_grid_button = TRUE;
8580 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8584 case EVENT_MOTIONNOTIFY:
8586 MotionEvent *motion = (MotionEvent *)&event;
8588 motion_status = TRUE;
8590 if (HandleGadgets(motion->x, motion->y, button_status))
8592 // do not handle this button event anymore
8596 motion->x += video.screen_xoffset;
8597 motion->y += video.screen_yoffset;
8599 x = motion->x * overlay.grid_xsize / video.screen_width;
8600 y = motion->y * overlay.grid_ysize / video.screen_height;
8602 set_grid_button = TRUE;
8604 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8608 case SDL_WINDOWEVENT:
8609 HandleWindowEvent((WindowEvent *) &event);
8611 // check if device has been rotated
8612 if (nr != GRID_ACTIVE_NR())
8614 nr = GRID_ACTIVE_NR();
8616 for (x = 0; x < MAX_GRID_XSIZE; x++)
8617 for (y = 0; y < MAX_GRID_YSIZE; y++)
8618 grid_button_old[x][y] = grid_button_tmp[x][y] =
8619 overlay.grid_button[x][y];
8624 case SDL_APP_WILLENTERBACKGROUND:
8625 case SDL_APP_DIDENTERBACKGROUND:
8626 case SDL_APP_WILLENTERFOREGROUND:
8627 case SDL_APP_DIDENTERFOREGROUND:
8628 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8632 HandleOtherEvents(&event);
8636 // ---------- perform action set by handling events ----------
8638 if (action == ACTION_ESCAPE)
8640 // abort and restore the old key bindings
8642 for (x = 0; x < MAX_GRID_XSIZE; x++)
8643 for (y = 0; y < MAX_GRID_YSIZE; y++)
8644 overlay.grid_button[x][y] = grid_button_old[x][y];
8646 FadeSkipNextFadeIn();
8650 else if (action == ACTION_BACK)
8652 // keep the configured key bindings and go to previous page
8658 FadeSkipNextFadeIn();
8663 else if (action == ACTION_NEXT)
8665 // keep the configured key bindings and go to next page
8669 // all virtual buttons configured
8677 if (action != ACTION_NONE && !finished)
8679 for (x = 0; x < MAX_GRID_XSIZE; x++)
8680 for (y = 0; y < MAX_GRID_YSIZE; y++)
8681 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8683 overlay.grid_button_highlight = grid_button[step_nr];
8685 // configure next virtual button
8689 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8690 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8691 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8694 if (set_grid_button)
8696 overlay.grid_button[x][y] =
8697 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8698 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8699 grid_button_tmp[x][y]);
8701 set_grid_button = FALSE;
8708 for (x = 0; x < MAX_GRID_XSIZE; x++)
8709 for (y = 0; y < MAX_GRID_YSIZE; y++)
8710 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8712 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8714 SetOverlayShowGrid(FALSE);
8719 void ConfigureVirtualButtons(void)
8721 boolean success = ConfigureVirtualButtonsMain();
8723 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8724 SCREEN_MASK_TOUCH2);
8728 int font_nr = FONT_TITLE_1;
8729 int font_height = getFontHeight(font_nr);
8730 int ypos1 = SYSIZE / 2 - font_height * 2;
8731 int ypos2 = SYSIZE / 2 - font_height * 1;
8732 unsigned int wait_frame_delay = 0;
8733 unsigned int wait_frame_delay_value = 2000;
8735 ResetDelayCounter(&wait_frame_delay);
8739 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8740 DrawTextSCentered(ypos2, font_nr, "configured!");
8742 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8749 void DrawSetupScreen(void)
8754 if (setup_mode == SETUP_MODE_INPUT)
8755 DrawSetupScreen_Input();
8756 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8757 DrawChooseTree(&game_speed_current);
8758 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8759 DrawChooseTree(&scroll_delay_current);
8760 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8761 DrawChooseTree(&snapshot_mode_current);
8762 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8763 DrawChooseTree(&window_size_current);
8764 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8765 DrawChooseTree(&scaling_type_current);
8766 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8767 DrawChooseTree(&rendering_mode_current);
8768 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8769 DrawChooseTree(&vsync_mode_current);
8770 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8771 DrawChooseTree(&artwork.gfx_current);
8772 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8773 DrawChooseTree(&artwork.snd_current);
8774 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8775 DrawChooseTree(&artwork.mus_current);
8776 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8777 DrawChooseTree(&volume_simple_current);
8778 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8779 DrawChooseTree(&volume_loops_current);
8780 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8781 DrawChooseTree(&volume_music_current);
8782 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8783 DrawChooseTree(&touch_control_current);
8784 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8785 DrawChooseTree(&move_distance_current);
8786 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8787 DrawChooseTree(&drop_distance_current);
8788 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8789 DrawChooseTree(&transparency_current);
8790 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8791 DrawChooseTree(&grid_size_current[0][0]);
8792 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8793 DrawChooseTree(&grid_size_current[0][1]);
8794 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8795 DrawChooseTree(&grid_size_current[1][0]);
8796 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8797 DrawChooseTree(&grid_size_current[1][1]);
8799 DrawSetupScreen_Generic();
8801 PlayMenuSoundsAndMusic();
8804 void RedrawSetupScreenAfterFullscreenToggle(void)
8806 if (setup_mode == SETUP_MODE_GRAPHICS ||
8807 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8809 // update list selection from "setup.window_scaling_percent"
8810 execSetupGraphics_setWindowSizes(TRUE);
8816 void RedrawSetupScreenAfterScreenRotation(int nr)
8820 if (setup_mode == SETUP_MODE_TOUCH)
8822 // update virtual button settings (depending on screen orientation)
8825 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8827 // save already configured virtual buttons
8828 for (x = 0; x < MAX_GRID_XSIZE; x++)
8829 for (y = 0; y < MAX_GRID_YSIZE; y++)
8830 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8834 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8836 if (setup_mode == SETUP_MODE_INPUT)
8837 HandleSetupScreen_Input(mx, my, dx, dy, button);
8838 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8839 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8840 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8841 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8842 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8843 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8844 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8845 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8846 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8847 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8848 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8849 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8850 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8851 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8852 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8853 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8854 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8855 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8856 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8857 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8858 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8859 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8860 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8861 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8862 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8863 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8864 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8865 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8866 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8867 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8868 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8869 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8870 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8871 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8872 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8873 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8874 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8875 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8876 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8877 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8878 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8879 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8881 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8884 void HandleGameActions(void)
8886 if (setup.ask_on_game_over)
8889 if (game.restart_game_message != NULL)
8891 RequestRestartGame(game.restart_game_message);
8896 if (game_status != GAME_MODE_PLAYING)
8899 GameActions(); // main game loop
8901 if (tape.auto_play && !tape.playing)
8902 AutoPlayTapes(); // continue automatically playing next tape
8906 // ---------- new screen button stuff --------------------------------------
8910 int gfx_unpressed, gfx_pressed;
8911 struct MenuPosInfo *pos;
8912 boolean *check_value;
8915 unsigned int event_mask;
8916 boolean is_touch_button;
8918 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8921 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8922 &menu.main.button.prev_level, NULL,
8923 SCREEN_CTRL_ID_PREV_LEVEL,
8925 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8926 FALSE, "previous level"
8929 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8930 &menu.main.button.next_level, NULL,
8931 SCREEN_CTRL_ID_NEXT_LEVEL,
8933 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8937 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
8938 &menu.main.button.first_level, NULL,
8939 SCREEN_CTRL_ID_FIRST_LEVEL,
8942 FALSE, "first level"
8945 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
8946 &menu.main.button.last_level, NULL,
8947 SCREEN_CTRL_ID_LAST_LEVEL,
8953 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
8954 &menu.main.button.level_number, NULL,
8955 SCREEN_CTRL_ID_LEVEL_NUMBER,
8958 FALSE, "level number"
8961 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8962 &menu.setup.button.prev_player, NULL,
8963 SCREEN_CTRL_ID_PREV_PLAYER,
8965 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8966 FALSE, "previous player"
8969 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8970 &menu.setup.button.next_player, NULL,
8971 SCREEN_CTRL_ID_NEXT_PLAYER,
8973 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8974 FALSE, "next player"
8977 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8978 &menu.main.button.insert_solution, NULL,
8979 SCREEN_CTRL_ID_INSERT_SOLUTION,
8980 SCREEN_MASK_MAIN_HAS_SOLUTION,
8982 FALSE, "insert solution tape"
8985 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8986 &menu.main.button.play_solution, NULL,
8987 SCREEN_CTRL_ID_PLAY_SOLUTION,
8988 SCREEN_MASK_MAIN_HAS_SOLUTION,
8990 FALSE, "play solution tape"
8993 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
8994 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
8995 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
8997 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
8998 FALSE, "switch ECS/AGA chipset"
9001 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9002 &menu.setup.button.touch_back, NULL,
9003 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9006 TRUE, "previous page"
9009 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9010 &menu.setup.button.touch_next, NULL,
9011 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9017 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9018 &menu.setup.button.touch_back2, NULL,
9019 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9022 TRUE, "previous page"
9025 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9026 &menu.setup.button.touch_next2, NULL,
9027 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9036 int gfx_unpressed, gfx_pressed;
9040 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9043 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9044 -1, -1, // these values are not constant, but can change at runtime
9045 SCREEN_CTRL_ID_SCROLL_UP,
9049 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9050 -1, -1, // these values are not constant, but can change at runtime
9051 SCREEN_CTRL_ID_SCROLL_DOWN,
9058 int gfx_unpressed, gfx_pressed;
9064 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9067 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9068 -1, -1, // these values are not constant, but can change at runtime
9069 -1, -1, // these values are not constant, but can change at runtime
9070 GD_TYPE_SCROLLBAR_VERTICAL,
9071 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9072 "scroll level series vertically"
9084 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9087 IMG_SETUP_INPUT_TEXT,
9088 SCREEN_CTRL_ID_NETWORK_SERVER,
9089 -1, -1, // these values are not constant, but can change at runtime
9090 MAX_SETUP_TEXT_INPUT_LEN,
9091 network_server_hostname,
9092 "Network Server Hostname / IP"
9096 static void CreateScreenMenubuttons(void)
9098 struct GadgetInfo *gi;
9099 unsigned int event_mask;
9102 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9104 struct MenuPosInfo *pos = menubutton_info[i].pos;
9105 boolean is_touch_button = menubutton_info[i].is_touch_button;
9106 boolean is_check_button = menubutton_info[i].check_value != NULL;
9107 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9108 int gfx_unpressed, gfx_pressed;
9109 int x, y, width, height;
9110 int gd_x1, gd_x2, gd_y1, gd_y2;
9111 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9112 int id = menubutton_info[i].gadget_id;
9113 int type = GD_TYPE_NORMAL_BUTTON;
9114 boolean checked = FALSE;
9116 event_mask = menubutton_info[i].event_mask;
9118 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9119 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9121 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9122 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9124 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9125 gfx_pressed = menubutton_info[i].gfx_pressed;
9126 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9127 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9128 gd_x1 = graphic_info[gfx_unpressed].src_x;
9129 gd_y1 = graphic_info[gfx_unpressed].src_y;
9130 gd_x2 = graphic_info[gfx_pressed].src_x;
9131 gd_y2 = graphic_info[gfx_pressed].src_y;
9137 if (is_touch_button)
9139 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9140 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9143 if (is_check_button)
9145 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9146 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9147 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9148 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9150 type = GD_TYPE_CHECK_BUTTON;
9151 checked = *menubutton_info[i].check_value;
9154 gi = CreateGadget(GDI_CUSTOM_ID, id,
9155 GDI_CUSTOM_TYPE_ID, i,
9156 GDI_IMAGE_ID, gfx_unpressed,
9157 GDI_INFO_TEXT, menubutton_info[i].infotext,
9163 GDI_STATE, GD_BUTTON_UNPRESSED,
9164 GDI_CHECKED, checked,
9165 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9166 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9167 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9168 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9169 GDI_DIRECT_DRAW, FALSE,
9170 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9171 GDI_EVENT_MASK, event_mask,
9172 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9176 Fail("cannot create gadget");
9178 screen_gadget[id] = gi;
9182 static void CreateScreenScrollbuttons(void)
9184 struct GadgetInfo *gi;
9185 unsigned int event_mask;
9188 // these values are not constant, but can change at runtime
9189 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9190 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9191 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9192 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9194 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9196 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9197 int gfx_unpressed, gfx_pressed;
9198 int x, y, width, height;
9199 int gd_x1, gd_x2, gd_y1, gd_y2;
9200 int id = scrollbutton_info[i].gadget_id;
9202 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9204 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9205 y = mSY + scrollbutton_info[i].y;
9206 width = SC_SCROLLBUTTON_XSIZE;
9207 height = SC_SCROLLBUTTON_YSIZE;
9209 // correct scrollbar position if placed outside menu (playfield) area
9210 if (x > SX + SC_SCROLL_UP_XPOS)
9211 x = SX + SC_SCROLL_UP_XPOS;
9213 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9214 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9215 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9217 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9218 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9219 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9220 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9221 gd_x1 = graphic_info[gfx_unpressed].src_x;
9222 gd_y1 = graphic_info[gfx_unpressed].src_y;
9223 gd_x2 = graphic_info[gfx_pressed].src_x;
9224 gd_y2 = graphic_info[gfx_pressed].src_y;
9226 gi = CreateGadget(GDI_CUSTOM_ID, id,
9227 GDI_CUSTOM_TYPE_ID, i,
9228 GDI_IMAGE_ID, gfx_unpressed,
9229 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9234 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9235 GDI_STATE, GD_BUTTON_UNPRESSED,
9236 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9237 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9238 GDI_DIRECT_DRAW, FALSE,
9239 GDI_EVENT_MASK, event_mask,
9240 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9244 Fail("cannot create gadget");
9246 screen_gadget[id] = gi;
9250 static void CreateScreenScrollbars(void)
9254 // these values are not constant, but can change at runtime
9255 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9256 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9257 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9258 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9260 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9262 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9263 int gfx_unpressed, gfx_pressed;
9264 int x, y, width, height;
9265 int gd_x1, gd_x2, gd_y1, gd_y2;
9266 struct GadgetInfo *gi;
9267 int items_max, items_visible, item_position;
9268 unsigned int event_mask;
9269 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9270 int id = scrollbar_info[i].gadget_id;
9272 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9274 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9275 y = mSY + scrollbar_info[i].y;
9276 width = scrollbar_info[i].width;
9277 height = scrollbar_info[i].height;
9279 // correct scrollbar position if placed outside menu (playfield) area
9280 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9281 x = SX + SC_SCROLL_VERTICAL_XPOS;
9283 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9284 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9286 items_max = num_page_entries;
9287 items_visible = num_page_entries;
9290 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9291 gfx_pressed = scrollbar_info[i].gfx_pressed;
9292 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9293 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9294 gd_x1 = graphic_info[gfx_unpressed].src_x;
9295 gd_y1 = graphic_info[gfx_unpressed].src_y;
9296 gd_x2 = graphic_info[gfx_pressed].src_x;
9297 gd_y2 = graphic_info[gfx_pressed].src_y;
9299 gi = CreateGadget(GDI_CUSTOM_ID, id,
9300 GDI_CUSTOM_TYPE_ID, i,
9301 GDI_IMAGE_ID, gfx_unpressed,
9302 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9307 GDI_TYPE, scrollbar_info[i].type,
9308 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9309 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9310 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9311 GDI_WHEEL_AREA_X, SX,
9312 GDI_WHEEL_AREA_Y, SY,
9313 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9314 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9315 GDI_STATE, GD_BUTTON_UNPRESSED,
9316 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9317 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9318 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9319 GDI_DIRECT_DRAW, FALSE,
9320 GDI_EVENT_MASK, event_mask,
9321 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9325 Fail("cannot create gadget");
9327 screen_gadget[id] = gi;
9331 static void CreateScreenTextInputGadgets(void)
9335 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9337 int graphic = textinput_info[i].graphic;
9338 struct GraphicInfo *gd = &graphic_info[graphic];
9339 int gd_x1 = gd->src_x;
9340 int gd_y1 = gd->src_y;
9341 int gd_x2 = gd->src_x + gd->active_xoffset;
9342 int gd_y2 = gd->src_y + gd->active_yoffset;
9343 struct GadgetInfo *gi;
9344 unsigned int event_mask;
9345 int id = textinput_info[i].gadget_id;
9346 int x = textinput_info[i].x;
9347 int y = textinput_info[i].y;
9349 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9351 gi = CreateGadget(GDI_CUSTOM_ID, id,
9352 GDI_CUSTOM_TYPE_ID, i,
9353 GDI_INFO_TEXT, textinput_info[i].infotext,
9356 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9357 GDI_TEXT_VALUE, textinput_info[i].value,
9358 GDI_TEXT_SIZE, textinput_info[i].size,
9359 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9360 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9361 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9362 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9363 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9364 GDI_DESIGN_WIDTH, gd->width,
9365 GDI_EVENT_MASK, event_mask,
9366 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9367 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9371 Fail("cannot create gadget");
9373 screen_gadget[id] = gi;
9377 void CreateScreenGadgets(void)
9379 CreateScreenMenubuttons();
9381 CreateScreenScrollbuttons();
9382 CreateScreenScrollbars();
9384 CreateScreenTextInputGadgets();
9387 void FreeScreenGadgets(void)
9391 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9392 FreeGadget(screen_gadget[i]);
9395 static void MapScreenMenuGadgets(int screen_mask)
9399 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9400 if (screen_mask & menubutton_info[i].screen_mask)
9401 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9404 static void UnmapScreenMenuGadgets(int screen_mask)
9408 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9410 if (screen_mask & menubutton_info[i].screen_mask)
9412 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9414 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9415 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9416 screen_gadget[menubutton_info[i].gadget_id]->y,
9417 screen_gadget[menubutton_info[i].gadget_id]->width,
9418 screen_gadget[menubutton_info[i].gadget_id]->height);
9423 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9426 MapScreenMenuGadgets(screen_mask);
9428 UnmapScreenMenuGadgets(screen_mask);
9431 static void MapScreenGadgets(int num_entries)
9435 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9438 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9439 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9441 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9442 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9445 static void MapScreenTreeGadgets(TreeInfo *ti)
9447 MapScreenGadgets(numTreeInfoInGroup(ti));
9450 static void HandleScreenGadgets(struct GadgetInfo *gi)
9452 int id = gi->custom_id;
9453 int button = gi->event.button;
9454 int step = (button == MB_LEFTBUTTON ? 1 :
9455 button == MB_MIDDLEBUTTON ? 5 :
9456 button == MB_RIGHTBUTTON ? 10 : 1);
9460 case SCREEN_CTRL_ID_PREV_LEVEL:
9461 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9464 case SCREEN_CTRL_ID_NEXT_LEVEL:
9465 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9468 case SCREEN_CTRL_ID_FIRST_LEVEL:
9469 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9472 case SCREEN_CTRL_ID_LAST_LEVEL:
9473 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9476 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9477 CloseDoor(DOOR_CLOSE_2);
9478 SetGameStatus(GAME_MODE_LEVELNR);
9479 DrawChooseLevelNr();
9482 case SCREEN_CTRL_ID_PREV_PLAYER:
9483 HandleSetupScreen_Input_Player(step, -1);
9486 case SCREEN_CTRL_ID_NEXT_PLAYER:
9487 HandleSetupScreen_Input_Player(step, +1);
9490 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9491 InsertSolutionTape();
9494 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9498 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9499 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9503 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9504 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9505 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9506 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9507 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9510 case SCREEN_CTRL_ID_SCROLL_UP:
9511 if (game_status == GAME_MODE_NAMES)
9512 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9513 else if (game_status == GAME_MODE_LEVELS)
9514 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9515 else if (game_status == GAME_MODE_LEVELNR)
9516 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9517 else if (game_status == GAME_MODE_SETUP)
9518 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9519 else if (game_status == GAME_MODE_INFO)
9520 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9523 case SCREEN_CTRL_ID_SCROLL_DOWN:
9524 if (game_status == GAME_MODE_NAMES)
9525 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9526 else if (game_status == GAME_MODE_LEVELS)
9527 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9528 else if (game_status == GAME_MODE_LEVELNR)
9529 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9530 else if (game_status == GAME_MODE_SETUP)
9531 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9532 else if (game_status == GAME_MODE_INFO)
9533 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9536 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9537 if (game_status == GAME_MODE_NAMES)
9538 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9539 else if (game_status == GAME_MODE_LEVELS)
9540 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9541 else if (game_status == GAME_MODE_LEVELNR)
9542 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9543 else if (game_status == GAME_MODE_SETUP)
9544 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9545 else if (game_status == GAME_MODE_INFO)
9546 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9549 case SCREEN_CTRL_ID_NETWORK_SERVER:
9551 if (!strEqual(gi->textinput.value, ""))
9553 setString(&setup.network_server_hostname, gi->textinput.value);
9555 network.server_host = setup.network_server_hostname;
9559 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9561 network.server_host = NULL;
9564 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9565 network.server_host = NULL;
9567 execSetupGame_setNetworkServerText();
9579 void DumpScreenIdentifiers(void)
9583 Print("Active screen elements on current screen:\n");
9585 for (i = 0; main_controls[i].nr != -1; i++)
9587 struct MainControlInfo *mci = &main_controls[i];
9589 if (mci->button_graphic != -1)
9591 char *token = getTokenFromImageID(mci->button_graphic);
9593 Print("- '%s'\n", token);
9600 boolean DoScreenAction(int image_id)
9604 if (game_status != GAME_MODE_MAIN)
9607 for (i = 0; main_controls[i].nr != -1; i++)
9609 struct MainControlInfo *mci = &main_controls[i];
9610 struct MenuPosInfo *pos = mci->pos_button;
9612 if (mci->button_graphic == image_id)
9614 int x = mSX + pos->x;
9615 int y = mSY + pos->y;
9617 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9626 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9628 // get tree info node of newly added level or artwork set
9629 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9630 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9632 if (tree_node_new == NULL) // should not happen
9635 // if request dialog is active, do nothing
9636 if (game.request_active)
9639 if (game_status == GAME_MODE_MAIN &&
9640 tree_type == TREE_TYPE_LEVEL_DIR)
9642 // when adding new level set in main menu, select it as current level set
9644 // change current level set to newly added level set from zip file
9645 leveldir_current = tree_node_new;
9647 // change current level number to first level of newly added level set
9648 level_nr = leveldir_current->first_level;
9650 // redraw screen to reflect changed level set
9653 // save this level set and level number as last selected level set
9654 SaveLevelSetup_LastSeries();
9655 SaveLevelSetup_SeriesInfo();
9657 else if (game_status == GAME_MODE_LEVELS &&
9658 tree_type == TREE_TYPE_LEVEL_DIR)
9660 // when adding new level set in level set menu, set cursor and update screen
9662 leveldir_current = tree_node_new;
9664 DrawChooseTree(&leveldir_current);
9666 else if (game_status == GAME_MODE_SETUP)
9668 // when adding new artwork set in setup menu, set cursor and update screen
9670 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9671 tree_type == TREE_TYPE_GRAPHICS_DIR)
9673 artwork.gfx_current = tree_node_new;
9675 DrawChooseTree(&artwork.gfx_current);
9677 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9678 tree_type == TREE_TYPE_SOUNDS_DIR)
9680 artwork.snd_current = tree_node_new;
9682 DrawChooseTree(&artwork.snd_current);
9684 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9685 tree_type == TREE_TYPE_MUSIC_DIR)
9687 artwork.mus_current = tree_node_new;
9689 DrawChooseTree(&artwork.mus_current);