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))
130 // for input setup functions
131 #define SETUPINPUT_SCREEN_POS_START 0
132 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
133 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
134 #define SETUPINPUT_SCREEN_POS_END 13
136 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
137 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
139 #define MAX_SETUP_TEXT_INPUT_LEN 28
141 // for various menu stuff
142 #define MENU_SCREEN_START_XPOS 1
143 #define MENU_SCREEN_START_YPOS 2
144 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
145 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
146 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
147 #define MENU_TITLE1_YPOS 8
148 #define MENU_TITLE2_YPOS 46
149 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
150 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
151 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
152 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
153 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
154 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
155 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
156 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
159 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
160 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
161 MENU_INFO_FONT_TITLE))
162 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
163 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
164 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
165 MENU_SCREEN_INFO_YSTART2 - \
167 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
168 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
169 MENU_SCREEN_INFO_YSTEP)
170 #define NUM_INFO_ELEMENTS_FROM_CONF \
171 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
172 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
173 MAX_MENU_ENTRIES_ON_SCREEN)
174 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
175 MAX_INFO_ELEMENTS_ON_SCREEN), \
176 NUM_INFO_ELEMENTS_FROM_CONF)
177 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
178 #define MAX_MENU_TEXT_LENGTH_BIG 13
179 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
181 // screen gadget identifiers
182 #define SCREEN_CTRL_ID_PREV_LEVEL 0
183 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
184 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
185 #define SCREEN_CTRL_ID_LAST_LEVEL 3
186 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
187 #define SCREEN_CTRL_ID_PREV_PLAYER 5
188 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
189 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
190 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
191 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
192 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
193 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
194 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
195 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
196 #define SCREEN_CTRL_ID_SCROLL_UP 14
197 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
198 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
199 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
201 #define NUM_SCREEN_GADGETS 18
203 #define NUM_SCREEN_MENUBUTTONS 14
204 #define NUM_SCREEN_SCROLLBUTTONS 2
205 #define NUM_SCREEN_SCROLLBARS 1
206 #define NUM_SCREEN_TEXTINPUT 1
208 #define SCREEN_MASK_MAIN (1 << 0)
209 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
210 #define SCREEN_MASK_INPUT (1 << 2)
211 #define SCREEN_MASK_TOUCH (1 << 3)
212 #define SCREEN_MASK_TOUCH2 (1 << 4)
214 // graphic position and size values for buttons and scrollbars
215 #define SC_MENUBUTTON_XSIZE TILEX
216 #define SC_MENUBUTTON_YSIZE TILEY
218 #define SC_SCROLLBUTTON_XSIZE TILEX
219 #define SC_SCROLLBUTTON_YSIZE TILEY
221 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
223 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
224 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
225 SC_SCROLLBUTTON_YSIZE)
227 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
228 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
230 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
231 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
232 SC_SCROLLBUTTON_YSIZE)
234 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
235 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
236 SC_SCROLL_VERTICAL_YSIZE)
238 #define SC_BORDER_SIZE 14
241 // forward declarations of internal functions
242 static void HandleScreenGadgets(struct GadgetInfo *);
243 static void HandleSetupScreen_Generic(int, int, int, int, int);
244 static void HandleSetupScreen_Input(int, int, int, int, int);
245 static void CustomizeKeyboard(int);
246 static void ConfigureJoystick(int);
247 static void ConfigureVirtualButtons(void);
248 static void execSetupGame(void);
249 static void execSetupEngines(void);
250 static void execSetupGraphics(void);
251 static void execSetupSound(void);
252 static void execSetupTouch(void);
253 static void execSetupArtwork(void);
254 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
256 static void DrawChoosePlayerName(void);
257 static void DrawChooseLevelSet(void);
258 static void DrawChooseLevelNr(void);
259 static void DrawInfoScreen(void);
260 static void DrawSetupScreen(void);
261 static void DrawTypeName(void);
263 static void DrawInfoScreen_NotAvailable(char *, char *);
264 static void DrawInfoScreen_HelpAnim(int, int, boolean);
265 static void DrawInfoScreen_HelpText(int, int, int, int);
266 static void HandleInfoScreen_Main(int, int, int, int, int);
267 static void HandleInfoScreen_TitleScreen(int);
268 static void HandleInfoScreen_Elements(int);
269 static void HandleInfoScreen_Music(int);
270 static void HandleInfoScreen_Credits(int);
271 static void HandleInfoScreen_Program(int);
272 static void HandleInfoScreen_Version(int);
274 static void ModifyGameSpeedIfNeeded(void);
275 static void DisableVsyncIfNeeded(void);
277 static void MapScreenMenuGadgets(int);
278 static void UnmapScreenMenuGadgets(int);
279 static void MapScreenGadgets(int);
280 static void MapScreenTreeGadgets(TreeInfo *);
282 static void UpdateScreenMenuGadgets(int, boolean);
284 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
286 static int info_mode = INFO_MODE_MAIN;
287 static int setup_mode = SETUP_MODE_MAIN;
289 static TreeInfo *window_sizes = NULL;
290 static TreeInfo *window_size_current = NULL;
292 static TreeInfo *scaling_types = NULL;
293 static TreeInfo *scaling_type_current = NULL;
295 static TreeInfo *rendering_modes = NULL;
296 static TreeInfo *rendering_mode_current = NULL;
298 static TreeInfo *vsync_modes = NULL;
299 static TreeInfo *vsync_mode_current = NULL;
301 static TreeInfo *scroll_delays = NULL;
302 static TreeInfo *scroll_delay_current = NULL;
304 static TreeInfo *snapshot_modes = NULL;
305 static TreeInfo *snapshot_mode_current = NULL;
307 static TreeInfo *game_speeds_normal = NULL;
308 static TreeInfo *game_speeds_extended = NULL;
309 static TreeInfo *game_speeds = NULL;
310 static TreeInfo *game_speed_current = NULL;
312 static TreeInfo *volumes_simple = NULL;
313 static TreeInfo *volume_simple_current = NULL;
315 static TreeInfo *volumes_loops = NULL;
316 static TreeInfo *volume_loops_current = NULL;
318 static TreeInfo *volumes_music = NULL;
319 static TreeInfo *volume_music_current = NULL;
321 static TreeInfo *touch_controls = NULL;
322 static TreeInfo *touch_control_current = NULL;
324 static TreeInfo *move_distances = NULL;
325 static TreeInfo *move_distance_current = NULL;
327 static TreeInfo *drop_distances = NULL;
328 static TreeInfo *drop_distance_current = NULL;
330 static TreeInfo *transparencies = NULL;
331 static TreeInfo *transparency_current = NULL;
333 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
334 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
336 static TreeInfo *player_name = NULL;
337 static TreeInfo *player_name_current = NULL;
339 static TreeInfo *level_number = NULL;
340 static TreeInfo *level_number_current = NULL;
342 static struct ValueTextInfo window_sizes_list[] =
347 { 100, "100 % (Default)" },
360 static struct StringValueTextInfo scaling_types_list[] =
362 { SCALING_QUALITY_NEAREST, "Off" },
363 { SCALING_QUALITY_LINEAR, "Linear" },
364 { SCALING_QUALITY_BEST, "Anisotropic" },
369 static struct StringValueTextInfo rendering_modes_list[] =
371 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
372 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
374 // this mode may work under certain conditions, but does not work on Windows
375 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
377 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
382 static struct StringValueTextInfo vsync_modes_list[] =
384 { STR_VSYNC_MODE_OFF, "Off" },
385 { STR_VSYNC_MODE_NORMAL, "Normal" },
386 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
391 static struct ValueTextInfo game_speeds_list_normal[] =
402 static struct ValueTextInfo game_speeds_list_extended[] =
404 { 1000, "1 fps (Extremely Slow)" },
409 { 29, "35 fps (Original Supaplex)" },
411 { 20, "50 fps (=== Normal Speed ===)" },
412 { 16, "60 fps (60 Hz VSync Speed)" },
413 { 14, "70 fps (Maximum Supaplex)" },
417 { 1, "1000 fps (Extremely Fast)" },
422 static struct ValueTextInfo *game_speeds_list;
424 static struct ValueTextInfo scroll_delays_list[] =
426 { 0, "0 Tiles (No Scroll Delay)" },
429 { 3, "3 Tiles (Default)" },
434 { 8, "8 Tiles (Maximum Scroll Delay)"},
439 static struct StringValueTextInfo snapshot_modes_list[] =
441 { STR_SNAPSHOT_MODE_OFF, "Off" },
442 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
443 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
444 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
449 static struct ValueTextInfo volumes_list[] =
469 static struct StringValueTextInfo touch_controls_list[] =
471 { TOUCH_CONTROL_OFF, "Off" },
472 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
473 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
474 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
479 static struct ValueTextInfo distances_list[] =
494 static struct ValueTextInfo transparencies_list[] =
496 { 0, "0 % (Opaque)" },
506 { 100, "100 % (Invisible)" },
511 static struct ValueTextInfo grid_sizes_list[] =
547 static int align_xoffset = 0;
548 static int align_yoffset = 0;
550 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
551 (s) <= GAME_MODE_SETUP ? (s) : \
552 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
554 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
555 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
557 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
558 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
559 (i) <= INFO_MODE_LEVELSET ? (i) : \
562 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
563 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
564 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
565 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
566 SETUP_MODE_CHOOSE_ARTWORK : \
567 SETUP_MODE_CHOOSE_OTHER)
569 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
570 menu.draw_xoffset[GAME_MODE_INFO] : \
571 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
572 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
573 menu.draw_yoffset[GAME_MODE_INFO] : \
574 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
575 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
576 menu.extra_spacing[GAME_MODE_INFO] : \
577 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
579 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
580 menu.draw_xoffset[GAME_MODE_SETUP] : \
581 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
582 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
583 menu.draw_yoffset[GAME_MODE_SETUP] : \
584 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
585 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
586 menu.extra_spacing[GAME_MODE_SETUP] : \
587 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
589 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
590 DRAW_XOFFSET_INFO(info_mode) : \
591 (s) == GAME_MODE_SETUP ? \
592 DRAW_XOFFSET_SETUP(setup_mode) : \
593 menu.draw_xoffset[DRAW_MODE(s)])
594 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
595 DRAW_YOFFSET_INFO(info_mode) : \
596 (s) == GAME_MODE_SETUP ? \
597 DRAW_YOFFSET_SETUP(setup_mode) : \
598 menu.draw_yoffset[DRAW_MODE(s)])
599 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
600 EXTRA_SPACING_INFO(info_mode) : \
601 (s) == GAME_MODE_SETUP ? \
602 EXTRA_SPACING_SETUP(setup_mode) : \
603 menu.extra_spacing[DRAW_MODE(s)])
605 #define mSX (SX + DRAW_XOFFSET(game_status))
606 #define mSY (SY + DRAW_YOFFSET(game_status))
608 #define amSX (mSX + align_xoffset)
609 #define amSY (mSY + align_yoffset)
611 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
612 menu.list_size[game_status] : \
613 MAX_MENU_ENTRIES_ON_SCREEN)
615 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
616 NUM_MENU_ENTRIES_ON_SCREEN)
619 // title display and control definitions
621 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
622 2 * MAX_NUM_TITLE_MESSAGES)
624 #define NO_DIRECT_LEVEL_SELECT (-1)
627 static int num_title_screens = 0;
629 struct TitleControlInfo
638 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
640 // main menu display and control definitions
642 #define MAIN_CONTROL_NAME 0
643 #define MAIN_CONTROL_LEVELS 1
644 #define MAIN_CONTROL_SCORES 2
645 #define MAIN_CONTROL_EDITOR 3
646 #define MAIN_CONTROL_INFO 4
647 #define MAIN_CONTROL_GAME 5
648 #define MAIN_CONTROL_SETUP 6
649 #define MAIN_CONTROL_QUIT 7
650 #define MAIN_CONTROL_PREV_LEVEL 8
651 #define MAIN_CONTROL_NEXT_LEVEL 9
652 #define MAIN_CONTROL_FIRST_LEVEL 10
653 #define MAIN_CONTROL_LAST_LEVEL 11
654 #define MAIN_CONTROL_LEVEL_NUMBER 12
655 #define MAIN_CONTROL_LEVEL_INFO_1 13
656 #define MAIN_CONTROL_LEVEL_INFO_2 14
657 #define MAIN_CONTROL_LEVEL_NAME 15
658 #define MAIN_CONTROL_LEVEL_AUTHOR 16
659 #define MAIN_CONTROL_LEVEL_YEAR 17
660 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
661 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
662 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
663 #define MAIN_CONTROL_TITLE_1 21
664 #define MAIN_CONTROL_TITLE_2 22
665 #define MAIN_CONTROL_TITLE_3 23
667 static char str_main_text_name[10];
668 static char str_main_text_first_level[10];
669 static char str_main_text_last_level[10];
670 static char str_main_text_level_number[10];
672 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
674 static char *main_text_name = str_main_text_name;
675 static char *main_text_first_level = str_main_text_first_level;
676 static char *main_text_last_level = str_main_text_last_level;
677 static char *main_text_level_number = str_main_text_level_number;
678 static char *main_text_levels = "Levelset";
679 static char *main_text_scores = "Hall Of Fame";
680 static char *main_text_editor = "Level Creator";
681 static char *main_text_info = "Info Screen";
682 static char *main_text_game = "Start Game";
683 static char *main_text_setup = "Setup";
684 static char *main_text_quit = "Quit";
685 static char *main_text_level_name = level.name;
686 static char *main_text_level_author = level.author;
687 static char *main_text_level_year = NULL;
688 static char *main_text_level_imported_from = NULL;
689 static char *main_text_level_imported_by = NULL;
690 static char *main_text_level_tested_by = NULL;
691 static char *main_text_title_1 = NULL;
692 static char *main_text_title_2 = NULL;
693 static char *main_text_title_3 = NULL;
695 extern char debug_xsn_mode[];
697 struct MainControlInfo
701 struct MenuPosInfo *pos_button;
704 struct TextPosInfo *pos_text;
707 struct TextPosInfo *pos_input;
711 static struct MainControlInfo main_controls[] =
715 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
716 &menu.main.text.name, &main_text_name,
717 &menu.main.input.name, &setup.player_name,
721 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
722 &menu.main.text.levels, &main_text_levels,
727 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
728 &menu.main.text.scores, &main_text_scores,
733 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
734 &menu.main.text.editor, &main_text_editor,
739 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
740 &menu.main.text.info, &main_text_info,
745 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
746 &menu.main.text.game, &main_text_game,
751 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
752 &menu.main.text.setup, &main_text_setup,
757 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
758 &menu.main.text.quit, &main_text_quit,
762 MAIN_CONTROL_PREV_LEVEL,
768 MAIN_CONTROL_NEXT_LEVEL,
774 MAIN_CONTROL_FIRST_LEVEL,
776 &menu.main.text.first_level, &main_text_first_level,
780 MAIN_CONTROL_LAST_LEVEL,
782 &menu.main.text.last_level, &main_text_last_level,
786 MAIN_CONTROL_LEVEL_NUMBER,
788 &menu.main.text.level_number, &main_text_level_number,
792 MAIN_CONTROL_LEVEL_INFO_1,
794 &menu.main.text.level_info_1, NULL,
798 MAIN_CONTROL_LEVEL_INFO_2,
800 &menu.main.text.level_info_2, NULL,
804 MAIN_CONTROL_LEVEL_NAME,
806 &menu.main.text.level_name, &main_text_level_name,
810 MAIN_CONTROL_LEVEL_AUTHOR,
812 &menu.main.text.level_author, &main_text_level_author,
816 MAIN_CONTROL_LEVEL_YEAR,
818 &menu.main.text.level_year, &main_text_level_year,
822 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
824 &menu.main.text.level_imported_from, &main_text_level_imported_from,
828 MAIN_CONTROL_LEVEL_IMPORTED_BY,
830 &menu.main.text.level_imported_by, &main_text_level_imported_by,
834 MAIN_CONTROL_LEVEL_TESTED_BY,
836 &menu.main.text.level_tested_by, &main_text_level_tested_by,
840 MAIN_CONTROL_TITLE_1,
842 &menu.main.text.title_1, &main_text_title_1,
846 MAIN_CONTROL_TITLE_2,
848 &menu.main.text.title_2, &main_text_title_2,
852 MAIN_CONTROL_TITLE_3,
854 &menu.main.text.title_3, &main_text_title_3,
867 static int getTitleScreenGraphic(int nr, boolean initial)
869 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
872 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
874 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
878 static int getTitleScreenGameMode(boolean initial)
880 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
884 static int getTitleMessageGameMode(boolean initial)
886 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
889 static int getTitleAnimMode(struct TitleControlInfo *tci)
891 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
893 return base + tci->local_nr;
897 static int getTitleScreenBackground(boolean initial)
899 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
904 static int getTitleMessageBackground(int nr, boolean initial)
906 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
910 static int getTitleBackground(int nr, boolean initial, boolean is_image)
912 int base = (is_image ?
913 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
914 IMG_BACKGROUND_TITLESCREEN_1) :
915 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
916 IMG_BACKGROUND_TITLEMESSAGE_1));
917 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
918 IMG_BACKGROUND_TITLE);
919 int graphic_local = base + nr;
921 if (graphic_info[graphic_local].bitmap != NULL)
922 return graphic_local;
924 if (graphic_info[graphic_global].bitmap != NULL)
925 return graphic_global;
927 return IMG_UNDEFINED;
930 static int getTitleSound(struct TitleControlInfo *tci)
932 boolean is_image = tci->is_image;
933 int initial = tci->initial;
934 int nr = tci->local_nr;
935 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
936 int base = (is_image ?
937 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
938 SND_BACKGROUND_TITLESCREEN_1) :
939 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
940 SND_BACKGROUND_TITLEMESSAGE_1));
941 int sound_global = menu.sound[mode];
942 int sound_local = base + nr;
945 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
946 nr, initial, is_image,
947 sound_global, getSoundListEntry(sound_global)->filename,
948 sound_local, getSoundListEntry(sound_local)->filename);
951 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
954 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
957 return SND_UNDEFINED;
960 static int getTitleMusic(struct TitleControlInfo *tci)
962 boolean is_image = tci->is_image;
963 int initial = tci->initial;
964 int nr = tci->local_nr;
965 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
966 int base = (is_image ?
967 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
968 MUS_BACKGROUND_TITLESCREEN_1) :
969 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
970 MUS_BACKGROUND_TITLEMESSAGE_1));
971 int music_global = menu.music[mode];
972 int music_local = base + nr;
975 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
976 nr, initial, is_image,
977 music_global, getMusicListEntry(music_global)->filename,
978 music_local, getMusicListEntry(music_local)->filename);
981 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
984 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
987 return MUS_UNDEFINED;
990 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
992 boolean is_image = tci->is_image;
993 boolean initial = tci->initial;
994 boolean first = tci->first;
995 int nr = tci->local_nr;
996 struct TitleMessageInfo tmi;
997 struct TitleFadingInfo ti;
999 tmi = (is_image ? (initial ? (first ?
1000 titlescreen_initial_first[nr] :
1001 titlescreen_initial[nr])
1003 titlescreen_first[nr] :
1005 : (initial ? (first ?
1006 titlemessage_initial_first[nr] :
1007 titlemessage_initial[nr])
1009 titlemessage_first[nr] :
1010 titlemessage[nr])));
1012 ti.fade_mode = tmi.fade_mode;
1013 ti.fade_delay = tmi.fade_delay;
1014 ti.post_delay = tmi.post_delay;
1015 ti.auto_delay = tmi.auto_delay;
1016 ti.auto_delay_unit = tmi.auto_delay_unit;
1021 static int compareTitleControlInfo(const void *object1, const void *object2)
1023 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1024 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1027 if (tci1->initial != tci2->initial)
1028 compare_result = (tci1->initial ? -1 : +1);
1029 else if (tci1->sort_priority != tci2->sort_priority)
1030 compare_result = tci1->sort_priority - tci2->sort_priority;
1031 else if (tci1->is_image != tci2->is_image)
1032 compare_result = (tci1->is_image ? -1 : +1);
1034 compare_result = tci1->local_nr - tci2->local_nr;
1036 return compare_result;
1039 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1041 int nr, int sort_priority)
1043 title_controls[num_title_screens].is_image = is_image;
1044 title_controls[num_title_screens].initial = initial;
1045 title_controls[num_title_screens].local_nr = nr;
1046 title_controls[num_title_screens].sort_priority = sort_priority;
1048 title_controls[num_title_screens].first = FALSE; // will be set later
1050 num_title_screens++;
1053 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1057 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1059 int graphic = getTitleScreenGraphic(i, initial);
1060 Bitmap *bitmap = graphic_info[graphic].bitmap;
1061 int sort_priority = graphic_info[graphic].sort_priority;
1064 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1067 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1069 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1070 char *filename = getLevelSetTitleMessageFilename(i, initial);
1071 int sort_priority = tmi->sort_priority;
1073 if (filename != NULL)
1074 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1078 static void InitializeTitleControls(boolean show_title_initial)
1080 num_title_screens = 0;
1082 // 1st step: initialize title screens for game start (only when starting)
1083 if (show_title_initial)
1084 InitializeTitleControls_CheckTitleInfo(TRUE);
1086 // 2nd step: initialize title screens for current level set
1087 InitializeTitleControls_CheckTitleInfo(FALSE);
1089 // sort title screens according to sort_priority and title number
1090 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1091 compareTitleControlInfo);
1093 // mark first title screen
1094 title_controls[0].first = TRUE;
1097 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1099 return (pos != NULL && pos->x != -1 && pos->y != -1);
1102 static boolean visibleTextPos(struct TextPosInfo *pos)
1104 return (pos != NULL && pos->x != -1 && pos->y != -1);
1107 static void InitializeMainControls(void)
1109 boolean local_team_mode = (!network.enabled && setup.team_mode);
1112 // set main control text values to dynamically determined values
1113 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1115 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1116 menu.main.text.first_level.size));
1117 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1118 menu.main.text.last_level.size));
1119 strcpy(main_text_level_number, int2str(level_nr,
1120 menu.main.text.level_number.size));
1122 main_text_level_year = leveldir_current->year;
1123 main_text_level_imported_from = leveldir_current->imported_from;
1124 main_text_level_imported_by = leveldir_current->imported_by;
1125 main_text_level_tested_by = leveldir_current->tested_by;
1127 main_text_title_1 = getConfigProgramTitleString();
1128 main_text_title_2 = getConfigProgramCopyrightString();
1129 main_text_title_3 = getConfigProgramCompanyString();
1131 // set main control screen positions to dynamically determined values
1132 for (i = 0; main_controls[i].nr != -1; i++)
1134 struct MainControlInfo *mci = &main_controls[i];
1136 struct MenuPosInfo *pos_button = mci->pos_button;
1137 struct TextPosInfo *pos_text = mci->pos_text;
1138 struct TextPosInfo *pos_input = mci->pos_input;
1139 char *text = (mci->text ? *mci->text : NULL);
1140 char *input = (mci->input ? *mci->input : NULL);
1141 int button_graphic = mci->button_graphic;
1142 int font_text = (pos_text ? pos_text->font : -1);
1143 int font_input = (pos_input ? pos_input->font : -1);
1145 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1146 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1147 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1148 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1149 int text_chars = (text != NULL ? strlen(text) : 0);
1150 int input_chars = (input != NULL ? strlen(input) : 0);
1153 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1155 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1156 int text_width = font_text_width * text_chars;
1157 int text_height = font_text_height;
1158 int input_width = font_input_width * input_chars;
1159 int input_height = font_input_height;
1161 if (nr == MAIN_CONTROL_NAME)
1163 menu.main.input.name.width = input_width;
1164 menu.main.input.name.height = input_height;
1167 if (pos_button != NULL) // (x/y may be -1/-1 here)
1169 pos_button->width = button_width;
1170 pos_button->height = button_height;
1173 if (pos_text != NULL) // (x/y may be -1/-1 here)
1175 // calculate text size -- needed for text alignment
1176 boolean calculate_text_size = (text != NULL);
1178 if (pos_text->width == -1 || calculate_text_size)
1179 pos_text->width = text_width;
1180 if (pos_text->height == -1 || calculate_text_size)
1181 pos_text->height = text_height;
1183 if (visibleMenuPos(pos_button))
1185 if (pos_text->x == -1)
1186 pos_text->x = pos_button->x + pos_button->width;
1187 if (pos_text->y == -1)
1189 pos_button->y + (pos_button->height - pos_text->height) / 2;
1193 if (pos_input != NULL) // (x/y may be -1/-1 here)
1195 if (visibleTextPos(pos_text))
1197 if (pos_input->x == -1)
1198 pos_input->x = pos_text->x + pos_text->width;
1199 if (pos_input->y == -1)
1200 pos_input->y = pos_text->y;
1203 if (pos_input->width == -1)
1204 pos_input->width = input_width;
1205 if (pos_input->height == -1)
1206 pos_input->height = input_height;
1211 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1212 int graphic, boolean pressed)
1214 struct GraphicInfo *g = &graphic_info[graphic];
1217 int xoffset = (pressed ? g->pressed_xoffset : 0);
1218 int yoffset = (pressed ? g->pressed_yoffset : 0);
1220 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1222 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1223 g->width, g->height, dst_x, dst_y);
1226 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1227 boolean active_input,
1228 boolean pressed_button)
1232 for (i = 0; main_controls[i].nr != -1; i++)
1234 struct MainControlInfo *mci = &main_controls[i];
1236 if (mci->nr == nr || nr == -1)
1238 struct MenuPosInfo *pos_button = mci->pos_button;
1239 struct TextPosInfo *pos_text = mci->pos_text;
1240 struct TextPosInfo *pos_input = mci->pos_input;
1241 char *text = (mci->text ? *mci->text : NULL);
1242 char *input = (mci->input ? *mci->input : NULL);
1243 int button_graphic = mci->button_graphic;
1244 int font_text = (pos_text ? pos_text->font : -1);
1245 int font_input = (pos_input ? pos_input->font : -1);
1249 button_graphic = BUTTON_ACTIVE(button_graphic);
1250 font_text = FONT_ACTIVE(font_text);
1255 font_input = FONT_ACTIVE(font_input);
1258 if (visibleMenuPos(pos_button))
1260 struct MenuPosInfo *pos = pos_button;
1261 int x = mSX + pos->x;
1262 int y = mSY + pos->y;
1264 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1265 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1268 if (visibleTextPos(pos_text) && text != NULL)
1270 struct TextPosInfo *pos = pos_text;
1271 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1272 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1275 // (check why/if this is needed)
1276 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1278 DrawText(x, y, text, font_text);
1281 if (visibleTextPos(pos_input) && input != NULL)
1283 struct TextPosInfo *pos = pos_input;
1284 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1285 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1288 // (check why/if this is needed)
1289 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1291 DrawText(x, y, input, font_input);
1297 static void DrawCursorAndText_Main(int nr, boolean active_text,
1298 boolean pressed_button)
1300 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1304 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1305 boolean pressed_button)
1307 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1311 static struct MainControlInfo *getMainControlInfo(int nr)
1315 for (i = 0; main_controls[i].nr != -1; i++)
1316 if (main_controls[i].nr == nr)
1317 return &main_controls[i];
1322 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1327 int rect_x = ALIGNED_TEXT_XPOS(rect);
1328 int rect_y = ALIGNED_TEXT_YPOS(rect);
1330 return (x >= rect_x && x < rect_x + rect->width &&
1331 y >= rect_y && y < rect_y + rect->height);
1334 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1339 int rect_x = ALIGNED_TEXT_XPOS(rect);
1340 int rect_y = ALIGNED_TEXT_YPOS(rect);
1343 Debug("screens:insideTextPosRect",
1344 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1345 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1346 (x >= rect_x && x < rect_x + rect->width &&
1347 y >= rect_y && y < rect_y + rect->height));
1350 return (x >= rect_x && x < rect_x + rect->width &&
1351 y >= rect_y && y < rect_y + rect->height);
1354 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1356 int rect_width = preview->xsize * preview->tile_size;
1357 int rect_height = preview->ysize * preview->tile_size;
1358 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1359 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1361 return (x >= rect_x && x < rect_x + rect_width &&
1362 y >= rect_y && y < rect_y + rect_height);
1365 static void AdjustScrollbar(int id, int items_max, int items_visible,
1368 struct GadgetInfo *gi = screen_gadget[id];
1370 if (item_position > items_max - items_visible)
1371 item_position = items_max - items_visible;
1373 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1374 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1375 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1378 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1380 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1384 static void clearMenuListArea(void)
1386 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1388 // correct scrollbar position if placed outside menu (playfield) area
1389 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1390 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1392 // clear menu list area, but not title or scrollbar
1393 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1394 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1397 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1399 static int cursor_array[MAX_LEV_FIELDY];
1400 int x = amSX + TILEX * xpos;
1401 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1406 cursor_array[ypos] = graphic;
1408 graphic = cursor_array[ypos];
1412 graphic = BUTTON_ACTIVE(graphic);
1414 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1415 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1418 static void initCursor(int ypos, int graphic)
1420 drawCursorExt(0, ypos, FALSE, graphic);
1423 static void drawCursor(int ypos, boolean active)
1425 drawCursorExt(0, ypos, active, -1);
1428 static void drawCursorXY(int xpos, int ypos, int graphic)
1430 drawCursorExt(xpos, ypos, FALSE, graphic);
1433 static void drawChooseTreeCursor(int ypos, boolean active)
1435 drawCursorExt(0, ypos, active, -1);
1438 static int getChooseTreeEditFont(boolean active)
1440 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1443 static int getChooseTreeEditXPos(int pos)
1445 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1446 int xoffset = (has_scrollbar ? -1 : 0);
1447 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1448 int sx = amSX + xpos * TILEX;
1449 int font_nr = getChooseTreeEditFont(FALSE);
1450 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1452 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1455 static int getChooseTreeEditYPos(int ypos_raw)
1457 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1458 int sy = amSY + ypos * TILEY;
1463 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1465 int sx = getChooseTreeEditXPos(POS_LEFT);
1466 int sy = getChooseTreeEditYPos(ypos_raw);
1467 int font_nr = getChooseTreeEditFont(active);
1469 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1472 static void DrawHeadline(void)
1474 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1475 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1478 static void DrawTitleScreenImage(int nr, boolean initial)
1480 int graphic = getTitleScreenGraphic(nr, initial);
1481 Bitmap *bitmap = graphic_info[graphic].bitmap;
1482 int width = graphic_info[graphic].width;
1483 int height = graphic_info[graphic].height;
1484 int src_x = graphic_info[graphic].src_x;
1485 int src_y = graphic_info[graphic].src_y;
1491 if (width > WIN_XSIZE)
1493 // image width too large for window => center image horizontally
1494 src_x = (width - WIN_XSIZE) / 2;
1498 if (height > WIN_YSIZE)
1500 // image height too large for window => center image vertically
1501 src_y = (height - WIN_YSIZE) / 2;
1505 // always display title screens centered
1506 dst_x = (WIN_XSIZE - width) / 2;
1507 dst_y = (WIN_YSIZE - height) / 2;
1509 SetDrawBackgroundMask(REDRAW_ALL);
1510 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1512 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1514 if (DrawingOnBackground(dst_x, dst_y))
1515 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1517 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1519 redraw_mask = REDRAW_ALL;
1522 static void DrawTitleScreenMessage(int nr, boolean initial)
1524 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1525 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1527 if (filename == NULL)
1530 // force TITLE font on title message screen
1531 SetFontStatus(getTitleMessageGameMode(initial));
1533 // if chars *and* width set to "-1", automatically determine width
1534 if (tmi->chars == -1 && tmi->width == -1)
1535 tmi->width = viewport.window[game_status].width;
1537 // if lines *and* height set to "-1", automatically determine height
1538 if (tmi->lines == -1 && tmi->height == -1)
1539 tmi->height = viewport.window[game_status].height;
1541 // if chars set to "-1", automatically determine by text and font width
1542 if (tmi->chars == -1)
1543 tmi->chars = tmi->width / getFontWidth(tmi->font);
1545 tmi->width = tmi->chars * getFontWidth(tmi->font);
1547 // if lines set to "-1", automatically determine by text and font height
1548 if (tmi->lines == -1)
1549 tmi->lines = tmi->height / getFontHeight(tmi->font);
1551 tmi->height = tmi->lines * getFontHeight(tmi->font);
1553 // if x set to "-1", automatically determine by width and alignment
1555 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1557 // if y set to "-1", automatically determine by height and alignment
1559 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1561 SetDrawBackgroundMask(REDRAW_ALL);
1562 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1564 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1566 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1567 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1568 tmi->autowrap, tmi->centered, tmi->parse_comments);
1573 static void DrawTitleScreen(void)
1575 KeyboardAutoRepeatOff();
1577 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1580 static boolean CheckTitleScreen(boolean levelset_has_changed)
1582 static boolean show_title_initial = TRUE;
1583 boolean show_titlescreen = FALSE;
1585 // needed to be able to skip title screen, if no image or message defined
1586 InitializeTitleControls(show_title_initial);
1588 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1589 show_titlescreen = TRUE;
1591 // show initial title images and messages only once at program start
1592 show_title_initial = FALSE;
1594 return (show_titlescreen && num_title_screens > 0);
1597 void DrawMainMenu(void)
1599 static LevelDirTree *leveldir_last_valid = NULL;
1600 boolean levelset_has_changed = FALSE;
1601 int fade_mask = REDRAW_FIELD;
1603 LimitScreenUpdates(FALSE);
1605 FadeSetLeaveScreen();
1607 // do not fade out here -- function may continue and fade on editor screen
1610 FadeMenuSoundsAndMusic();
1612 ExpireSoundLoops(FALSE);
1614 KeyboardAutoRepeatOn();
1616 audio.sound_deactivated = FALSE;
1620 // needed if last screen was the playing screen, invoked from level editor
1621 if (level_editor_test_game)
1623 CloseDoor(DOOR_CLOSE_ALL);
1625 SetGameStatus(GAME_MODE_EDITOR);
1632 // leveldir_current may be invalid (level group, parent link)
1633 if (!validLevelSeries(leveldir_current))
1634 leveldir_current = getFirstValidTreeInfoEntry(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);
1743 static void gotoTopLevelDir(void)
1745 // move upwards until inside (but not above) top level directory
1746 while (leveldir_current->node_parent &&
1747 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1749 // write a "path" into level tree for easy navigation to last level
1750 if (leveldir_current->node_parent->node_group->cl_first == -1)
1752 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1753 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1754 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1755 int cl_first, cl_cursor;
1757 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1758 cl_cursor = leveldir_pos - cl_first;
1760 leveldir_current->node_parent->node_group->cl_first = cl_first;
1761 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1764 leveldir_current = leveldir_current->node_parent;
1768 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1770 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1772 return (use_frame_counter ? video.frame_counter : Counter());
1775 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1776 struct TitleFadingInfo *fi)
1778 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1781 static void ResetTitleAutoDelay(unsigned int *counter_var,
1782 struct TitleFadingInfo *fi)
1784 *counter_var = getAutoDelayCounter(fi);
1787 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1789 static unsigned int title_delay = 0;
1790 static int title_screen_nr = 0;
1791 static int last_sound = -1, last_music = -1;
1792 boolean return_to_main_menu = FALSE;
1793 struct TitleControlInfo *tci;
1796 if (button == MB_MENU_INITIALIZE)
1799 title_screen_nr = 0;
1800 tci = &title_controls[title_screen_nr];
1802 SetAnimStatus(getTitleAnimMode(tci));
1804 last_sound = SND_UNDEFINED;
1805 last_music = MUS_UNDEFINED;
1807 if (num_title_screens != 0)
1809 FadeSetEnterScreen();
1811 // use individual title fading instead of global "enter screen" fading
1812 fading = getTitleFading(tci);
1815 if (game_status_last_screen == GAME_MODE_INFO)
1817 if (num_title_screens == 0)
1819 // switch game mode from title screen mode back to info screen mode
1820 SetGameStatus(GAME_MODE_INFO);
1822 // store that last screen was info screen, not main menu screen
1823 game_status_last_screen = GAME_MODE_INFO;
1825 DrawInfoScreen_NotAvailable("Title screen information:",
1826 "No title screen for this level set.");
1831 FadeMenuSoundsAndMusic();
1833 FadeOut(REDRAW_ALL);
1835 // title screens may have different window size
1836 ChangeViewportPropertiesIfNeeded();
1838 // only required to update logic for redrawing global border
1842 DrawTitleScreenImage(tci->local_nr, tci->initial);
1844 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1846 sound = getTitleSound(tci);
1847 music = getTitleMusic(tci);
1849 if (sound != last_sound)
1850 PlayMenuSoundExt(sound);
1851 if (music != last_music)
1852 PlayMenuMusicExt(music);
1857 SetMouseCursor(CURSOR_NONE);
1861 ResetTitleAutoDelay(&title_delay, &fading);
1866 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1867 button = MB_MENU_CHOICE;
1869 if (button == MB_MENU_LEAVE)
1871 return_to_main_menu = TRUE;
1873 else if (button == MB_MENU_CHOICE)
1875 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1877 SetGameStatus(GAME_MODE_INFO);
1879 info_mode = INFO_MODE_MAIN;
1888 if (title_screen_nr < num_title_screens)
1890 tci = &title_controls[title_screen_nr];
1892 SetAnimStatus(getTitleAnimMode(tci));
1894 sound = getTitleSound(tci);
1895 music = getTitleMusic(tci);
1897 if (last_sound != SND_UNDEFINED && sound != last_sound)
1898 FadeSound(last_sound);
1899 if (last_music != MUS_UNDEFINED && music != last_music)
1902 fading = getTitleFading(tci);
1904 FadeOut(REDRAW_ALL);
1907 DrawTitleScreenImage(tci->local_nr, tci->initial);
1909 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1911 sound = getTitleSound(tci);
1912 music = getTitleMusic(tci);
1914 if (sound != last_sound)
1915 PlayMenuSoundExt(sound);
1916 if (music != last_music)
1917 PlayMenuMusicExt(music);
1924 ResetTitleAutoDelay(&title_delay, &fading);
1928 FadeMenuSoundsAndMusic();
1930 return_to_main_menu = TRUE;
1934 if (return_to_main_menu)
1936 SetMouseCursor(CURSOR_DEFAULT);
1938 // force full menu screen redraw after displaying title screens
1939 redraw_mask = REDRAW_ALL;
1941 if (game_status_last_screen == GAME_MODE_INFO)
1943 SetGameStatus(GAME_MODE_INFO);
1945 info_mode = INFO_MODE_MAIN;
1949 else // default: return to main menu
1951 SetGameStatus(GAME_MODE_MAIN);
1958 static void HandleMainMenu_SelectLevel(int step, int direction,
1959 int selected_level_nr)
1961 int old_level_nr = level_nr;
1964 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1965 new_level_nr = selected_level_nr;
1967 new_level_nr = old_level_nr + step * direction;
1969 if (new_level_nr < leveldir_current->first_level)
1970 new_level_nr = leveldir_current->first_level;
1971 if (new_level_nr > leveldir_current->last_level)
1972 new_level_nr = leveldir_current->last_level;
1974 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1976 // skipping levels is only allowed when trying to skip single level
1977 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1978 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1980 leveldir_current->handicap_level++;
1981 SaveLevelSetup_SeriesInfo();
1984 new_level_nr = leveldir_current->handicap_level;
1987 if (new_level_nr != old_level_nr)
1989 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1991 PlaySound(SND_MENU_ITEM_SELECTING);
1993 level_nr = new_level_nr;
1995 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1996 int2str(level_nr, menu.main.text.level_number.size),
1997 mci->pos_text->font);
1999 LoadLevel(level_nr);
2000 DrawPreviewLevelInitial();
2004 DrawCompleteVideoDisplay();
2006 SaveLevelSetup_SeriesInfo();
2008 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2010 // force redraw of playfield area (may be reset at this point)
2011 redraw_mask |= REDRAW_FIELD;
2015 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2017 static int choice = MAIN_CONTROL_GAME;
2018 static boolean button_pressed_last = FALSE;
2019 boolean button_pressed = FALSE;
2021 int i = 0; // needed to prevent compiler warning due to bad code below
2023 if (button == MB_MENU_INITIALIZE)
2025 DrawCursorAndText_Main(choice, TRUE, FALSE);
2030 if (mx || my) // mouse input
2034 for (i = 0; main_controls[i].nr != -1; i++)
2036 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2037 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2038 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2040 pos = main_controls[i].nr;
2046 // check if level preview was clicked
2047 if (insidePreviewRect(&preview, mx - SX, my - SY))
2048 pos = MAIN_CONTROL_GAME;
2050 // handle pressed/unpressed state for active/inactive menu buttons
2051 // (if pos != -1, "i" contains index position corresponding to "pos")
2053 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2054 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2055 button_pressed = TRUE;
2057 if (button_pressed != button_pressed_last)
2059 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2062 PlaySound(SND_MENU_BUTTON_PRESSING);
2064 PlaySound(SND_MENU_BUTTON_RELEASING);
2067 else if (dx || dy) // keyboard input
2069 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2070 choice == MAIN_CONTROL_SETUP))
2071 button = MB_MENU_CHOICE;
2076 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2078 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2080 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2082 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2084 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2086 CloseDoor(DOOR_CLOSE_2);
2088 SetGameStatus(GAME_MODE_LEVELNR);
2090 DrawChooseLevelNr();
2092 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2098 PlaySound(SND_MENU_ITEM_ACTIVATING);
2100 DrawCursorAndText_Main(choice, FALSE, FALSE);
2101 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2107 if (choice != MAIN_CONTROL_INFO &&
2108 choice != MAIN_CONTROL_SETUP)
2109 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2114 PlaySound(SND_MENU_ITEM_SELECTING);
2116 if (pos == MAIN_CONTROL_NAME)
2119 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2121 // special case: menu text "name/team" clicked -- toggle team mode
2122 setup.team_mode = !setup.team_mode;
2124 InitializeMainControls();
2125 DrawCursorAndText_Main(choice, TRUE, FALSE);
2127 DrawPreviewPlayers();
2131 if (setup.multiple_users)
2133 CloseDoor(DOOR_CLOSE_2);
2135 SetGameStatus(GAME_MODE_NAMES);
2137 DrawChoosePlayerName();
2141 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2147 else if (pos == MAIN_CONTROL_LEVELS)
2151 CloseDoor(DOOR_CLOSE_2);
2153 SetGameStatus(GAME_MODE_LEVELS);
2155 SaveLevelSetup_LastSeries();
2156 SaveLevelSetup_SeriesInfo();
2158 if (setup.internal.choose_from_top_leveldir)
2161 DrawChooseLevelSet();
2164 else if (pos == MAIN_CONTROL_SCORES)
2166 CloseDoor(DOOR_CLOSE_2);
2168 SetGameStatus(GAME_MODE_SCORES);
2170 DrawHallOfFame(level_nr, -1);
2172 else if (pos == MAIN_CONTROL_EDITOR)
2174 if (leveldir_current->readonly &&
2175 setup.editor.show_read_only_warning)
2176 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2178 CloseDoor(DOOR_CLOSE_ALL);
2180 SetGameStatus(GAME_MODE_EDITOR);
2182 FadeSetEnterScreen();
2186 else if (pos == MAIN_CONTROL_INFO)
2188 CloseDoor(DOOR_CLOSE_2);
2190 SetGameStatus(GAME_MODE_INFO);
2192 info_mode = INFO_MODE_MAIN;
2196 else if (pos == MAIN_CONTROL_GAME)
2198 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2200 else if (pos == MAIN_CONTROL_SETUP)
2202 CloseDoor(DOOR_CLOSE_2);
2204 SetGameStatus(GAME_MODE_SETUP);
2206 setup_mode = SETUP_MODE_MAIN;
2210 else if (pos == MAIN_CONTROL_QUIT)
2212 SaveLevelSetup_LastSeries();
2213 SaveLevelSetup_SeriesInfo();
2215 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2216 SetGameStatus(GAME_MODE_QUIT);
2221 button_pressed_last = button_pressed;
2225 // ============================================================================
2226 // info screen functions
2227 // ============================================================================
2229 static struct TokenInfo *info_info;
2230 static int num_info_info; // number of info entries shown on screen
2231 static int max_info_info; // total number of info entries in list
2233 static void execInfoTitleScreen(void)
2235 info_mode = INFO_MODE_TITLE;
2240 static void execInfoElements(void)
2242 info_mode = INFO_MODE_ELEMENTS;
2247 static void execInfoMusic(void)
2249 info_mode = INFO_MODE_MUSIC;
2254 static void execInfoCredits(void)
2256 info_mode = INFO_MODE_CREDITS;
2261 static void execInfoProgram(void)
2263 info_mode = INFO_MODE_PROGRAM;
2268 static void execInfoVersion(void)
2270 info_mode = INFO_MODE_VERSION;
2275 static void execInfoLevelSet(void)
2277 info_mode = INFO_MODE_LEVELSET;
2282 static void execExitInfo(void)
2284 SetGameStatus(GAME_MODE_MAIN);
2289 static struct TokenInfo info_info_main[] =
2291 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2292 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2293 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2294 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2295 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2296 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2297 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2298 { TYPE_EMPTY, NULL, "" },
2299 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2304 static int getMenuTextFont(int type)
2306 if (type & (TYPE_SWITCH |
2320 static struct TokenInfo *setup_info;
2321 static struct TokenInfo setup_info_input[];
2323 static struct TokenInfo *menu_info;
2325 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2326 int screen_pos, int menu_info_pos_raw,
2329 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2330 struct TokenInfo *ti = &token_info[pos];
2331 int xpos = MENU_SCREEN_START_XPOS;
2332 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2333 int font_nr = getMenuTextFont(ti->type);
2335 if (setup_mode == SETUP_MODE_INPUT)
2336 font_nr = FONT_MENU_1;
2339 font_nr = FONT_ACTIVE(font_nr);
2341 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2343 if (ti->type & ~TYPE_SKIP_ENTRY)
2344 drawCursor(screen_pos, active);
2347 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2350 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2353 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2356 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2359 static char *window_size_text;
2360 static char *scaling_type_text;
2361 static char *network_server_text;
2363 static void drawSetupValue(int, int);
2365 static void drawMenuInfoList(int first_entry, int num_page_entries,
2366 int max_page_entries)
2370 if (first_entry + num_page_entries > max_page_entries)
2373 clearMenuListArea();
2375 for (i = 0; i < num_page_entries; i++)
2377 int menu_info_pos = first_entry + i;
2378 struct TokenInfo *si = &menu_info[menu_info_pos];
2379 void *value_ptr = si->value;
2381 // set some entries to "unchangeable" according to other variables
2382 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2383 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2384 (value_ptr == &setup.sound_music && !audio.music_available) ||
2385 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2386 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2387 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2388 si->type |= TYPE_GHOSTED;
2390 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2391 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2392 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2393 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2394 else if (si->type & ~TYPE_SKIP_ENTRY)
2395 initCursor(i, IMG_MENU_BUTTON);
2397 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2399 if (si->type & TYPE_STRING)
2403 if (value_ptr == &network_server_text)
2404 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2406 if (gadget_id != -1)
2408 struct GadgetInfo *gi = screen_gadget[gadget_id];
2409 int xpos = MENU_SCREEN_START_XPOS;
2410 int ypos = MENU_SCREEN_START_YPOS + i;
2411 int x = mSX + xpos * 32;
2412 int y = mSY + ypos * 32;
2414 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2418 if (si->type & TYPE_VALUE &&
2419 menu_info == setup_info)
2420 drawSetupValue(i, menu_info_pos);
2424 static void DrawInfoScreen_Main(void)
2426 int fade_mask = REDRAW_FIELD;
2429 if (redraw_mask & REDRAW_ALL)
2430 fade_mask = REDRAW_ALL;
2433 fade_mask = REDRAW_ALL;
2436 FadeMenuSoundsAndMusic();
2438 FreeScreenGadgets();
2439 CreateScreenGadgets();
2441 // (needed after displaying title screens which disable auto repeat)
2442 KeyboardAutoRepeatOn();
2444 FadeSetLeaveScreen();
2448 // needed if different viewport properties defined for info screen
2449 ChangeViewportPropertiesIfNeeded();
2451 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2455 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2457 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2459 info_info = info_info_main;
2461 // determine maximal number of info entries that can be displayed on screen
2463 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2466 // determine maximal number of info entries available for menu of info screen
2468 for (i = 0; info_info[i].type != 0; i++)
2471 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2473 MapScreenGadgets(max_info_info);
2475 PlayMenuSoundsAndMusic();
2477 DrawMaskedBorder(fade_mask);
2482 static void changeSetupValue(int, int, int);
2484 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2485 int mode, int num_page_entries,
2486 int max_page_entries)
2488 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2489 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2490 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2491 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2492 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2493 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2494 int *num_page_entries_last = num_page_entries_all_last[game_status];
2495 int *choice_store = choice_stores[game_status];
2496 int *first_entry_store = first_entry_stores[game_status];
2497 int choice = choice_store[mode]; // starts with 0
2498 int first_entry = first_entry_store[mode]; // starts with 0
2500 int y = choice - first_entry;
2502 boolean position_set_by_scrollbar = (dx == 999);
2503 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2506 if (button == MB_MENU_INITIALIZE)
2508 // check if number of menu page entries has changed (may happen by change
2509 // of custom artwork definition value for 'list_size' for this menu screen)
2510 // (in this case, the last menu position most probably has to be corrected)
2511 if (num_page_entries != num_page_entries_last[mode])
2513 choice_store[mode] = first_entry_store[mode] = 0;
2515 choice = first_entry = 0;
2518 num_page_entries_last[mode] = num_page_entries;
2521 // advance to first valid menu entry
2522 while (choice < num_page_entries &&
2523 menu_info[choice].type & TYPE_SKIP_ENTRY)
2526 if (position_set_by_scrollbar)
2527 first_entry = first_entry_store[mode] = dy;
2529 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2530 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2532 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2534 if (choice < first_entry)
2536 choice = first_entry;
2538 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2541 else if (choice > first_entry + num_page_entries - 1)
2543 choice = first_entry + num_page_entries - 1;
2545 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2549 choice_store[mode] = choice;
2551 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2555 else if (button == MB_MENU_LEAVE)
2557 PlaySound(SND_MENU_ITEM_SELECTING);
2559 for (i = 0; i < max_page_entries; i++)
2561 if (menu_info[i].type & TYPE_LEAVE_MENU)
2563 void (*menu_callback_function)(void) = menu_info[i].value;
2567 menu_callback_function();
2569 break; // absolutely needed because function changes 'menu_info'!
2576 if (mx || my) // mouse input
2578 x = (mx - mSX) / 32;
2579 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2581 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2583 // move cursor instead of scrolling when already at start/end of list
2584 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2586 else if (dy == +1 * SCROLL_LINE &&
2587 first_entry + num_page_entries == max_page_entries)
2590 // handle scrolling screen one line or page
2592 y + dy > num_page_entries - 1)
2594 boolean redraw = FALSE;
2596 if (ABS(dy) == SCROLL_PAGE)
2597 step = num_page_entries - 1;
2599 if (dy < 0 && first_entry > 0)
2601 // scroll page/line up
2603 first_entry -= step;
2604 if (first_entry < 0)
2609 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2611 // scroll page/line down
2613 first_entry += step;
2614 if (first_entry + num_page_entries > max_page_entries)
2615 first_entry = MAX(0, max_page_entries - num_page_entries);
2622 choice += first_entry - first_entry_store[mode];
2624 if (choice < first_entry)
2626 choice = first_entry;
2628 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2631 else if (choice > first_entry + num_page_entries - 1)
2633 choice = first_entry + num_page_entries - 1;
2635 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2638 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2642 if (choice < first_entry ||
2643 choice > first_entry + num_page_entries - 1)
2644 first_entry += SIGN(dy);
2647 first_entry_store[mode] = first_entry;
2648 choice_store[mode] = choice;
2650 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2652 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2654 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2655 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2663 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2665 if (menu_info[choice].type & menu_navigation_type ||
2666 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2667 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2668 menu_info[choice].type & TYPE_PLAYER)
2669 button = MB_MENU_CHOICE;
2674 // jump to next non-empty menu entry (up or down)
2675 while (first_entry + y > 0 &&
2676 first_entry + y < max_page_entries - 1 &&
2677 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2680 if (!IN_VIS_MENU(x, y))
2682 choice += y - y_old;
2684 if (choice < first_entry)
2685 first_entry = choice;
2686 else if (choice > first_entry + num_page_entries - 1)
2687 first_entry = choice - num_page_entries + 1;
2689 if (first_entry >= 0 &&
2690 first_entry + num_page_entries <= max_page_entries)
2692 first_entry_store[mode] = first_entry;
2694 if (choice < first_entry)
2695 choice = first_entry;
2696 else if (choice > first_entry + num_page_entries - 1)
2697 choice = first_entry + num_page_entries - 1;
2699 choice_store[mode] = choice;
2701 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2703 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2705 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2706 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2713 if (!anyScrollbarGadgetActive() &&
2714 IN_VIS_MENU(x, y) &&
2715 mx < mx_right_border &&
2716 y >= 0 && y < num_page_entries)
2720 if (first_entry + y != choice &&
2721 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2723 PlaySound(SND_MENU_ITEM_ACTIVATING);
2725 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2726 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2728 choice = choice_store[mode] = first_entry + y;
2732 PlaySound(SND_MENU_ITEM_SELECTING);
2734 for (i = 0; menu_info[i].type != 0; i++)
2736 if (menu_info[i].type & TYPE_LEAVE_MENU)
2738 void (*menu_callback_function)(void) = menu_info[i].value;
2742 menu_callback_function();
2744 // absolutely needed because function changes 'menu_info'!
2752 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2754 PlaySound(SND_MENU_ITEM_SELECTING);
2756 // when selecting key headline, execute function for key value change
2757 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2758 menu_info[first_entry + y + 1].type & TYPE_KEY)
2761 // when selecting string value, execute function for list selection
2762 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2763 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2766 // when selecting string value, execute function for text input gadget
2767 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2768 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2771 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2773 void (*menu_callback_function)(void) =
2774 menu_info[first_entry + y].value;
2776 FadeSetFromType(menu_info[first_entry + y].type);
2778 menu_callback_function();
2780 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2782 void (*gadget_callback_function)(void) =
2783 menu_info[first_entry + y].value;
2785 gadget_callback_function();
2787 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2788 menu_info == setup_info)
2790 changeSetupValue(y, first_entry + y, dx);
2796 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2798 menu_info = info_info;
2800 HandleMenuScreen(mx, my, dx, dy, button,
2801 info_mode, num_info_info, max_info_info);
2804 static int getMenuFontSpacing(int spacing_height, int font_nr)
2806 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2808 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2812 static int getMenuTextSpacing(int spacing_height, int font_nr)
2814 return (getMenuFontSpacing(spacing_height, font_nr) +
2815 EXTRA_SPACING(game_status));
2818 static int getMenuTextStep(int spacing_height, int font_nr)
2820 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2823 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2825 int font_title = MENU_INFO_FONT_TITLE;
2826 int font_error = FONT_TEXT_2;
2827 int font_foot = MENU_INFO_FONT_FOOT;
2828 int spacing_title = menu.headline1_spacing_info[info_mode];
2829 int ystep_title = getMenuTextStep(spacing_title, font_title);
2830 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2831 int ystart2 = ystart1 + ystep_title;
2832 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2834 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2836 FadeOut(REDRAW_FIELD);
2841 DrawTextSCentered(ystart1, font_title, text_title);
2842 DrawTextSCentered(ystart2, font_error, text_error);
2844 DrawTextSCentered(ybottom, font_foot,
2845 "Press any key or button for info menu");
2847 FadeIn(REDRAW_FIELD);
2850 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2852 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2853 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2854 int font_title = MENU_INFO_FONT_TITLE;
2855 int font_foot = MENU_INFO_FONT_FOOT;
2856 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2857 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2858 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2859 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2860 int ystep = MENU_SCREEN_INFO_YSTEP;
2861 int element, action, direction;
2869 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2870 infoscreen_step[i] = infoscreen_frame[i] = 0;
2875 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2877 DrawTextSCentered(ybottom, font_foot,
2878 "Press any key or button for next page");
2884 while (helpanim_info[j].element != HELPANIM_LIST_END)
2886 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2891 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2900 j += infoscreen_step[i - start];
2902 element = helpanim_info[j].element;
2903 action = helpanim_info[j].action;
2904 direction = helpanim_info[j].direction;
2907 element = EL_UNKNOWN;
2909 if (action != -1 && direction != -1)
2910 graphic = el_act_dir2img(element, action, direction);
2911 else if (action != -1)
2912 graphic = el_act2img(element, action);
2913 else if (direction != -1)
2914 graphic = el_dir2img(element, direction);
2916 graphic = el2img(element);
2918 delay = helpanim_info[j++].delay;
2923 if (infoscreen_frame[i - start] == 0)
2926 infoscreen_frame[i - start] = delay - 1;
2930 sync_frame = delay - infoscreen_frame[i - start];
2931 infoscreen_frame[i - start]--;
2934 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2936 if (!infoscreen_frame[i - start])
2937 infoscreen_step[i - start] = 0;
2941 if (!infoscreen_frame[i - start])
2942 infoscreen_step[i - start]++;
2943 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2949 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2951 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2952 graphic, sync_frame, USE_MASKING);
2955 DrawInfoScreen_HelpText(element, action, direction, i - start);
2960 redraw_mask |= REDRAW_FIELD;
2965 static char *getHelpText(int element, int action, int direction)
2967 char token[MAX_LINE_LEN];
2969 strcpy(token, element_info[element].token_name);
2972 strcat(token, element_action_info[action].suffix);
2974 if (direction != -1)
2975 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2977 return getHashEntry(helptext_info, token);
2980 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2982 int font_nr = FONT_INFO_ELEMENTS;
2983 int font_width = getFontWidth(font_nr);
2984 int font_height = getFontHeight(font_nr);
2985 int yoffset = (TILEX - 2 * font_height) / 2;
2986 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2987 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2988 int ystep = TILEY + 4;
2989 int pad_left = xstart - SX;
2990 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2991 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2992 int max_lines_per_text = 2;
2995 if (action != -1 && direction != -1) // element.action.direction
2996 text = getHelpText(element, action, direction);
2998 if (text == NULL && action != -1) // element.action
2999 text = getHelpText(element, action, -1);
3001 if (text == NULL && direction != -1) // element.direction
3002 text = getHelpText(element, -1, direction);
3004 if (text == NULL) // base element
3005 text = getHelpText(element, -1, -1);
3007 if (text == NULL) // not found
3008 text = "No description available";
3010 if (strlen(text) <= max_chars_per_line) // only one line of text
3011 ystart += getFontHeight(font_nr) / 2;
3013 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3014 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3015 TRUE, FALSE, FALSE);
3018 static void DrawInfoScreen_TitleScreen(void)
3020 SetGameStatus(GAME_MODE_TITLE);
3025 void HandleInfoScreen_TitleScreen(int button)
3027 HandleTitleScreen(0, 0, 0, 0, button);
3030 static void DrawInfoScreen_Elements(void)
3032 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3034 FadeOut(REDRAW_FIELD);
3039 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3041 FadeIn(REDRAW_FIELD);
3044 void HandleInfoScreen_Elements(int button)
3046 static unsigned int info_delay = 0;
3047 static int num_anims;
3048 static int num_pages;
3050 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3053 if (button == MB_MENU_INITIALIZE)
3055 boolean new_element = TRUE;
3059 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3061 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3063 else if (new_element)
3066 new_element = FALSE;
3070 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3074 if (button == MB_MENU_LEAVE)
3076 PlaySound(SND_MENU_ITEM_SELECTING);
3078 info_mode = INFO_MODE_MAIN;
3083 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3085 if (button != MB_MENU_INITIALIZE)
3087 PlaySound(SND_MENU_ITEM_SELECTING);
3092 if (page >= num_pages)
3094 FadeMenuSoundsAndMusic();
3096 info_mode = INFO_MODE_MAIN;
3103 FadeSetNextScreen();
3105 if (button != MB_MENU_INITIALIZE)
3106 FadeOut(REDRAW_FIELD);
3108 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3110 if (button != MB_MENU_INITIALIZE)
3111 FadeIn(REDRAW_FIELD);
3115 if (DelayReached(&info_delay, GameFrameDelay))
3116 if (page < num_pages)
3117 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3119 PlayMenuSoundIfLoop();
3123 static void DrawInfoScreen_Music(void)
3125 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3127 FadeOut(REDRAW_FIELD);
3134 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3136 FadeIn(REDRAW_FIELD);
3139 void HandleInfoScreen_Music(int button)
3141 static struct MusicFileInfo *list = NULL;
3142 int font_title = MENU_INFO_FONT_TITLE;
3143 int font_head = MENU_INFO_FONT_HEAD;
3144 int font_text = MENU_INFO_FONT_TEXT;
3145 int font_foot = MENU_INFO_FONT_FOOT;
3146 int spacing_title = menu.headline1_spacing_info[info_mode];
3147 int spacing_head = menu.headline2_spacing_info[info_mode];
3148 int ystep_title = getMenuTextStep(spacing_title, font_title);
3149 int ystep_head = getMenuTextStep(spacing_head, font_head);
3150 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3151 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3153 if (button == MB_MENU_INITIALIZE)
3155 list = music_file_info;
3159 FadeMenuSoundsAndMusic();
3164 DrawTextSCentered(ystart, font_title,
3165 "No music info for this level set.");
3167 DrawTextSCentered(ybottom, font_foot,
3168 "Press any key or button for info menu");
3174 if (button == MB_MENU_LEAVE)
3176 PlaySound(SND_MENU_ITEM_SELECTING);
3178 FadeMenuSoundsAndMusic();
3180 info_mode = INFO_MODE_MAIN;
3185 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3187 if (button != MB_MENU_INITIALIZE)
3189 PlaySound(SND_MENU_ITEM_SELECTING);
3197 FadeMenuSoundsAndMusic();
3199 info_mode = INFO_MODE_MAIN;
3205 FadeMenuSoundsAndMusic();
3207 if (list != music_file_info)
3208 FadeSetNextScreen();
3210 if (button != MB_MENU_INITIALIZE)
3211 FadeOut(REDRAW_FIELD);
3218 int sound = list->music;
3220 if (sound_info[sound].loop)
3221 PlaySoundLoop(sound);
3225 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3229 int music = list->music;
3231 if (music_info[music].loop)
3232 PlayMusicLoop(music);
3236 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3239 ystart += ystep_title;
3241 if (!strEqual(list->title, UNKNOWN_NAME))
3243 if (!strEqual(list->title_header, UNKNOWN_NAME))
3245 DrawTextSCentered(ystart, font_head, list->title_header);
3246 ystart += ystep_head;
3249 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3250 ystart += ystep_head;
3253 if (!strEqual(list->artist, UNKNOWN_NAME))
3255 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3256 DrawTextSCentered(ystart, font_head, list->artist_header);
3258 DrawTextSCentered(ystart, font_head, "by");
3260 ystart += ystep_head;
3262 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3263 ystart += ystep_head;
3266 if (!strEqual(list->album, UNKNOWN_NAME))
3268 if (!strEqual(list->album_header, UNKNOWN_NAME))
3269 DrawTextSCentered(ystart, font_head, list->album_header);
3271 DrawTextSCentered(ystart, font_head, "from the album");
3273 ystart += ystep_head;
3275 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3276 ystart += ystep_head;
3279 if (!strEqual(list->year, UNKNOWN_NAME))
3281 if (!strEqual(list->year_header, UNKNOWN_NAME))
3282 DrawTextSCentered(ystart, font_head, list->year_header);
3284 DrawTextSCentered(ystart, font_head, "from the year");
3286 ystart += ystep_head;
3288 DrawTextFCentered(ystart, font_text, "%s", list->year);
3289 ystart += ystep_head;
3292 DrawTextSCentered(ybottom, FONT_TEXT_4,
3293 "Press any key or button for next page");
3295 if (button != MB_MENU_INITIALIZE)
3296 FadeIn(REDRAW_FIELD);
3299 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3300 PlaySoundLoop(list->music);
3303 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3305 int font_title = MENU_INFO_FONT_TITLE;
3306 int font_head = MENU_INFO_FONT_HEAD;
3307 int font_text = MENU_INFO_FONT_TEXT;
3308 int font_foot = MENU_INFO_FONT_FOOT;
3309 int spacing_title = menu.headline1_spacing_info[info_mode];
3310 int spacing_head = menu.headline2_spacing_info[info_mode];
3311 int spacing_para = menu.paragraph_spacing_info[info_mode];
3312 int spacing_line = menu.line_spacing_info[info_mode];
3313 int ystep_title = getMenuTextStep(spacing_title, font_title);
3314 int ystep_head = getMenuTextStep(spacing_head, font_head);
3315 int ystep_para = getMenuTextStep(spacing_para, font_text);
3316 int ystep_line = getMenuTextStep(spacing_line, font_text);
3317 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3318 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3323 DrawTextSCentered(ystart, font_title, "Credits:");
3324 ystart += ystep_title;
3328 DrawTextSCentered(ystart, font_head,
3329 "Special thanks to");
3330 ystart += ystep_head;
3331 DrawTextSCentered(ystart, font_text,
3333 ystart += ystep_head;
3334 DrawTextSCentered(ystart, font_head,
3336 ystart += ystep_head;
3337 DrawTextSCentered(ystart, font_text,
3338 "\"Boulder Dash\"");
3339 ystart += ystep_head;
3340 DrawTextSCentered(ystart, font_head,
3342 ystart += ystep_head;
3343 DrawTextSCentered(ystart, font_text,
3345 ystart += ystep_head;
3346 DrawTextSCentered(ystart, font_head,
3348 ystart += ystep_head;
3349 DrawTextSCentered(ystart, font_text,
3350 "First Star Software");
3352 else if (screen_nr == 1)
3354 DrawTextSCentered(ystart, font_head,
3355 "Special thanks to");
3356 ystart += ystep_head;
3357 DrawTextSCentered(ystart, font_text,
3358 "Klaus Heinz & Volker Wertich");
3359 ystart += ystep_head;
3360 DrawTextSCentered(ystart, font_head,
3362 ystart += ystep_head;
3363 DrawTextSCentered(ystart, font_text,
3364 "\"Emerald Mine\"");
3365 ystart += ystep_head;
3366 DrawTextSCentered(ystart, font_head,
3368 ystart += ystep_head;
3369 DrawTextSCentered(ystart, font_text,
3371 ystart += ystep_head;
3372 DrawTextSCentered(ystart, font_head,
3374 ystart += ystep_head;
3375 DrawTextSCentered(ystart, font_text,
3378 else if (screen_nr == 2)
3380 DrawTextSCentered(ystart, font_head,
3381 "Special thanks to");
3382 ystart += ystep_head;
3383 DrawTextSCentered(ystart, font_text,
3384 "Michael Stopp & Philip Jespersen");
3385 ystart += ystep_head;
3386 DrawTextSCentered(ystart, font_head,
3388 ystart += ystep_head;
3389 DrawTextSCentered(ystart, font_text,
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,
3402 "Digital Integration");
3404 else if (screen_nr == 3)
3406 DrawTextSCentered(ystart, font_head,
3407 "Special thanks to");
3408 ystart += ystep_head;
3409 DrawTextSCentered(ystart, font_text,
3410 "Hiroyuki Imabayashi");
3411 ystart += ystep_head;
3412 DrawTextSCentered(ystart, font_head,
3414 ystart += ystep_head;
3415 DrawTextSCentered(ystart, font_text,
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,
3430 else if (screen_nr == 4)
3432 DrawTextSCentered(ystart, font_head,
3433 "Special thanks to");
3434 ystart += ystep_head;
3435 DrawTextSCentered(ystart, font_text,
3437 ystart += ystep_head;
3438 DrawTextSCentered(ystart, font_head,
3440 ystart += ystep_head;
3441 DrawTextSCentered(ystart, font_text,
3442 "J\xfcrgen Bonhagen");
3443 ystart += ystep_head;
3444 DrawTextSCentered(ystart, font_head,
3445 "for the continuous creation");
3446 ystart += ystep_line;
3447 DrawTextSCentered(ystart, font_head,
3448 "of outstanding level sets");
3450 else if (screen_nr == 5)
3452 DrawTextSCentered(ystart, font_head,
3454 ystart += ystep_head;
3455 DrawTextSCentered(ystart, font_text,
3457 ystart += ystep_head;
3458 DrawTextSCentered(ystart, font_head,
3459 "for ideas and inspiration by");
3460 ystart += ystep_head;
3461 DrawTextSCentered(ystart, font_text,
3463 ystart += ystep_para;
3465 DrawTextSCentered(ystart, font_head,
3467 ystart += ystep_head;
3468 DrawTextSCentered(ystart, font_text,
3470 ystart += ystep_head;
3471 DrawTextSCentered(ystart, font_head,
3472 "for ideas and inspiration by");
3473 ystart += ystep_head;
3474 DrawTextSCentered(ystart, font_text,
3477 else if (screen_nr == 6)
3479 DrawTextSCentered(ystart, font_head,
3481 ystart += ystep_head;
3482 DrawTextSCentered(ystart, font_text,
3484 ystart += ystep_head;
3485 DrawTextSCentered(ystart, font_head,
3486 "for the code base used for the");
3487 ystart += ystep_line;
3488 DrawTextSCentered(ystart, font_head,
3489 "native Emerald Mine engine");
3491 else if (screen_nr == 7)
3493 DrawTextSCentered(ystart, font_head,
3495 ystart += ystep_head;
3496 DrawTextSCentered(ystart, font_text,
3498 ystart += ystep_head;
3499 DrawTextSCentered(ystart, font_head,
3500 "for the initial DOS port");
3501 ystart += ystep_para;
3503 DrawTextSCentered(ystart, font_head,
3505 ystart += ystep_head;
3506 DrawTextSCentered(ystart, font_text,
3508 ystart += ystep_head;
3509 DrawTextSCentered(ystart, font_head,
3510 "for some additional toons");
3512 else if (screen_nr == 8)
3514 DrawTextSCentered(ystart, font_head,
3515 "And not to forget:");
3516 ystart += ystep_head;
3517 DrawTextSCentered(ystart, font_head,
3519 ystart += ystep_head;
3520 DrawTextSCentered(ystart, font_text,
3521 "All those who contributed");
3522 ystart += ystep_line;
3523 DrawTextSCentered(ystart, font_text,
3524 "levels to this game");
3525 ystart += ystep_line;
3526 DrawTextSCentered(ystart, font_text,
3530 DrawTextSCentered(ybottom, font_foot,
3531 "Press any key or button for next page");
3534 static void DrawInfoScreen_Credits(void)
3536 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3538 FadeMenuSoundsAndMusic();
3540 FadeOut(REDRAW_FIELD);
3542 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3544 FadeIn(REDRAW_FIELD);
3547 void HandleInfoScreen_Credits(int button)
3549 static int screen_nr = 0;
3550 int num_screens = 9;
3552 if (button == MB_MENU_INITIALIZE)
3556 // DrawInfoScreen_CreditsScreen(screen_nr);
3559 if (button == MB_MENU_LEAVE)
3561 PlaySound(SND_MENU_ITEM_SELECTING);
3563 info_mode = INFO_MODE_MAIN;
3568 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3570 if (button != MB_MENU_INITIALIZE)
3572 PlaySound(SND_MENU_ITEM_SELECTING);
3577 if (screen_nr >= num_screens)
3579 FadeMenuSoundsAndMusic();
3581 info_mode = INFO_MODE_MAIN;
3588 FadeSetNextScreen();
3590 if (button != MB_MENU_INITIALIZE)
3591 FadeOut(REDRAW_FIELD);
3593 DrawInfoScreen_CreditsScreen(screen_nr);
3595 if (button != MB_MENU_INITIALIZE)
3596 FadeIn(REDRAW_FIELD);
3600 PlayMenuSoundIfLoop();
3604 static void DrawInfoScreen_Program(void)
3606 int font_title = MENU_INFO_FONT_TITLE;
3607 int font_head = MENU_INFO_FONT_HEAD;
3608 int font_text = MENU_INFO_FONT_TEXT;
3609 int font_foot = MENU_INFO_FONT_FOOT;
3610 int spacing_title = menu.headline1_spacing_info[info_mode];
3611 int spacing_head = menu.headline2_spacing_info[info_mode];
3612 int spacing_para = menu.paragraph_spacing_info[info_mode];
3613 int spacing_line = menu.line_spacing_info[info_mode];
3614 int ystep_title = getMenuTextStep(spacing_title, font_title);
3615 int ystep_head = getMenuTextStep(spacing_head, font_head);
3616 int ystep_para = getMenuTextStep(spacing_para, font_text);
3617 int ystep_line = getMenuTextStep(spacing_line, font_text);
3618 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3619 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3621 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3623 FadeOut(REDRAW_FIELD);
3628 DrawTextSCentered(ystart, font_title, "Program Information:");
3629 ystart += ystep_title;
3631 DrawTextSCentered(ystart, font_head,
3632 "This game is Freeware!");
3633 ystart += ystep_head;
3634 DrawTextSCentered(ystart, font_head,
3635 "If you like it, send e-mail to:");
3636 ystart += ystep_head;
3637 DrawTextSCentered(ystart, font_text,
3638 setup.internal.program_email);
3639 ystart += ystep_para;
3641 DrawTextSCentered(ystart, font_head,
3642 "More information and levels:");
3643 ystart += ystep_head;
3644 DrawTextSCentered(ystart, font_text,
3645 setup.internal.program_website);
3646 ystart += ystep_para;
3648 DrawTextSCentered(ystart, font_head,
3649 "If you have created new levels,");
3650 ystart += ystep_line;
3651 DrawTextSCentered(ystart, font_head,
3652 "send them to me to include them!");
3653 ystart += ystep_head;
3654 DrawTextSCentered(ystart, font_head,
3657 DrawTextSCentered(ybottom, font_foot,
3658 "Press any key or button for info menu");
3660 FadeIn(REDRAW_FIELD);
3663 void HandleInfoScreen_Program(int button)
3665 if (button == MB_MENU_LEAVE)
3667 PlaySound(SND_MENU_ITEM_SELECTING);
3669 info_mode = INFO_MODE_MAIN;
3674 else if (button == MB_MENU_CHOICE)
3676 PlaySound(SND_MENU_ITEM_SELECTING);
3678 FadeMenuSoundsAndMusic();
3680 info_mode = INFO_MODE_MAIN;
3685 PlayMenuSoundIfLoop();
3689 static void DrawInfoScreen_Version(void)
3691 int font_title = MENU_INFO_FONT_TITLE;
3692 int font_head = MENU_INFO_FONT_HEAD;
3693 int font_text = MENU_INFO_FONT_TEXT;
3694 int font_foot = MENU_INFO_FONT_FOOT;
3695 int spacing_title = menu.headline1_spacing_info[info_mode];
3696 int spacing_head = menu.headline2_spacing_info[info_mode];
3697 int spacing_para = menu.paragraph_spacing_info[info_mode];
3698 int spacing_line = menu.line_spacing_info[info_mode];
3699 int xstep = getFontWidth(font_text);
3700 int ystep_title = getMenuTextStep(spacing_title, font_title);
3701 int ystep_head = getMenuTextStep(spacing_head, font_head);
3702 int ystep_para = getMenuTextStep(spacing_para, font_text);
3703 int ystep_line = getMenuTextStep(spacing_line, font_text);
3704 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3705 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3706 int xstart1 = mSX - SX + 2 * xstep;
3707 int xstart2 = mSX - SX + 18 * xstep;
3708 int xstart3 = mSX - SX + 28 * xstep;
3709 SDL_version sdl_version_compiled;
3710 const SDL_version *sdl_version_linked;
3711 int driver_name_len = 10;
3712 SDL_version sdl_version_linked_ext;
3713 const char *driver_name = NULL;
3715 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3717 FadeOut(REDRAW_FIELD);
3722 DrawTextSCentered(ystart, font_title, "Version Information:");
3723 ystart += ystep_title;
3725 DrawTextF(xstart1, ystart, font_head, "Name");
3726 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3727 ystart += ystep_line;
3729 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3731 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3732 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3733 ystart += ystep_line;
3735 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3736 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3737 ystart += ystep_line;
3741 DrawTextF(xstart1, ystart, font_head, "Version");
3742 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3743 ystart += ystep_line;
3746 DrawTextF(xstart1, ystart, font_head, "Platform");
3747 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3749 PLATFORM_XX_BIT_STRING);
3750 ystart += ystep_line;
3752 DrawTextF(xstart1, ystart, font_head, "Target");
3753 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3754 ystart += ystep_line;
3756 DrawTextF(xstart1, ystart, font_head, "Source date");
3757 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3758 ystart += ystep_line;
3760 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3761 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3762 ystart += ystep_para;
3764 DrawTextF(xstart1, ystart, font_head, "Library");
3765 DrawTextF(xstart2, ystart, font_head, "compiled");
3766 DrawTextF(xstart3, ystart, font_head, "linked");
3767 ystart += ystep_head;
3769 SDL_VERSION(&sdl_version_compiled);
3770 SDL_GetVersion(&sdl_version_linked_ext);
3771 sdl_version_linked = &sdl_version_linked_ext;
3773 DrawTextF(xstart1, ystart, font_text, "SDL");
3774 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3775 sdl_version_compiled.major,
3776 sdl_version_compiled.minor,
3777 sdl_version_compiled.patch);
3778 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3779 sdl_version_linked->major,
3780 sdl_version_linked->minor,
3781 sdl_version_linked->patch);
3782 ystart += ystep_line;
3784 SDL_IMAGE_VERSION(&sdl_version_compiled);
3785 sdl_version_linked = IMG_Linked_Version();
3787 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3788 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3789 sdl_version_compiled.major,
3790 sdl_version_compiled.minor,
3791 sdl_version_compiled.patch);
3792 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3793 sdl_version_linked->major,
3794 sdl_version_linked->minor,
3795 sdl_version_linked->patch);
3796 ystart += ystep_line;
3798 SDL_MIXER_VERSION(&sdl_version_compiled);
3799 sdl_version_linked = Mix_Linked_Version();
3801 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3802 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3803 sdl_version_compiled.major,
3804 sdl_version_compiled.minor,
3805 sdl_version_compiled.patch);
3806 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3807 sdl_version_linked->major,
3808 sdl_version_linked->minor,
3809 sdl_version_linked->patch);
3810 ystart += ystep_line;
3812 SDL_NET_VERSION(&sdl_version_compiled);
3813 sdl_version_linked = SDLNet_Linked_Version();
3815 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3816 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3817 sdl_version_compiled.major,
3818 sdl_version_compiled.minor,
3819 sdl_version_compiled.patch);
3820 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3821 sdl_version_linked->major,
3822 sdl_version_linked->minor,
3823 sdl_version_linked->patch);
3824 ystart += ystep_para;
3826 DrawTextF(xstart1, ystart, font_head, "Driver");
3827 DrawTextF(xstart2, ystart, font_head, "Requested");
3828 DrawTextF(xstart3, ystart, font_head, "Used");
3829 ystart += ystep_head;
3832 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3834 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3835 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3836 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3837 ystart += ystep_line;
3840 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3842 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3843 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3844 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3845 ystart += ystep_line;
3848 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3850 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3851 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3852 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3854 DrawTextSCentered(ybottom, font_foot,
3855 "Press any key or button for info menu");
3857 FadeIn(REDRAW_FIELD);
3860 void HandleInfoScreen_Version(int button)
3862 if (button == MB_MENU_LEAVE)
3864 PlaySound(SND_MENU_ITEM_SELECTING);
3866 info_mode = INFO_MODE_MAIN;
3871 else if (button == MB_MENU_CHOICE)
3873 PlaySound(SND_MENU_ITEM_SELECTING);
3875 FadeMenuSoundsAndMusic();
3877 info_mode = INFO_MODE_MAIN;
3882 PlayMenuSoundIfLoop();
3886 static void DrawInfoScreen_LevelSet(void)
3888 struct TitleMessageInfo *tmi = &readme;
3889 char *filename = getLevelSetInfoFilename();
3890 char *title = "Level Set Information:";
3891 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3892 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3894 if (filename == NULL)
3896 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3901 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3903 FadeOut(REDRAW_FIELD);
3908 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3910 // if x position set to "-1", automatically determine by playfield width
3912 tmi->x = SXSIZE / 2;
3914 // if y position set to "-1", use static default value
3918 // if width set to "-1", automatically determine by playfield width
3919 if (tmi->width == -1)
3920 tmi->width = SXSIZE - 2 * TILEX;
3922 // if height set to "-1", automatically determine by playfield height
3923 if (tmi->height == -1)
3924 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3926 // if chars set to "-1", automatically determine by text and font width
3927 if (tmi->chars == -1)
3928 tmi->chars = tmi->width / getFontWidth(tmi->font);
3930 tmi->width = tmi->chars * getFontWidth(tmi->font);
3932 // if lines set to "-1", automatically determine by text and font height
3933 if (tmi->lines == -1)
3934 tmi->lines = tmi->height / getFontHeight(tmi->font);
3936 tmi->height = tmi->lines * getFontHeight(tmi->font);
3938 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3939 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3940 tmi->autowrap, tmi->centered, tmi->parse_comments);
3942 DrawTextSCentered(ybottom, FONT_TEXT_4,
3943 "Press any key or button for info menu");
3945 FadeIn(REDRAW_FIELD);
3948 static void HandleInfoScreen_LevelSet(int button)
3950 if (button == MB_MENU_LEAVE)
3952 PlaySound(SND_MENU_ITEM_SELECTING);
3954 info_mode = INFO_MODE_MAIN;
3959 else if (button == MB_MENU_CHOICE)
3961 PlaySound(SND_MENU_ITEM_SELECTING);
3963 FadeMenuSoundsAndMusic();
3965 info_mode = INFO_MODE_MAIN;
3970 PlayMenuSoundIfLoop();
3974 static void DrawInfoScreen(void)
3976 if (info_mode == INFO_MODE_TITLE)
3977 DrawInfoScreen_TitleScreen();
3978 else if (info_mode == INFO_MODE_ELEMENTS)
3979 DrawInfoScreen_Elements();
3980 else if (info_mode == INFO_MODE_MUSIC)
3981 DrawInfoScreen_Music();
3982 else if (info_mode == INFO_MODE_CREDITS)
3983 DrawInfoScreen_Credits();
3984 else if (info_mode == INFO_MODE_PROGRAM)
3985 DrawInfoScreen_Program();
3986 else if (info_mode == INFO_MODE_VERSION)
3987 DrawInfoScreen_Version();
3988 else if (info_mode == INFO_MODE_LEVELSET)
3989 DrawInfoScreen_LevelSet();
3991 DrawInfoScreen_Main();
3993 if (info_mode != INFO_MODE_MAIN &&
3994 info_mode != INFO_MODE_TITLE &&
3995 info_mode != INFO_MODE_MUSIC)
3996 PlayMenuSoundsAndMusic();
3999 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4001 if (info_mode == INFO_MODE_TITLE)
4002 HandleInfoScreen_TitleScreen(button);
4003 else if (info_mode == INFO_MODE_ELEMENTS)
4004 HandleInfoScreen_Elements(button);
4005 else if (info_mode == INFO_MODE_MUSIC)
4006 HandleInfoScreen_Music(button);
4007 else if (info_mode == INFO_MODE_CREDITS)
4008 HandleInfoScreen_Credits(button);
4009 else if (info_mode == INFO_MODE_PROGRAM)
4010 HandleInfoScreen_Program(button);
4011 else if (info_mode == INFO_MODE_VERSION)
4012 HandleInfoScreen_Version(button);
4013 else if (info_mode == INFO_MODE_LEVELSET)
4014 HandleInfoScreen_LevelSet(button);
4016 HandleInfoScreen_Main(mx, my, dx, dy, button);
4020 // ============================================================================
4021 // type name functions
4022 // ============================================================================
4024 static TreeInfo *type_name_node = NULL;
4025 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4026 static int type_name_nr = 0;
4028 static int getPlayerNameColor(char *name)
4030 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4033 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4036 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4037 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4038 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4039 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4040 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4041 int font_width = getFontWidth(font_nr);
4043 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4045 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4047 pos->width = strlen(text) * font_width;
4048 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4050 DrawText(sx, sy, text, font_nr);
4053 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4055 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4057 *pos = *mci->pos_input;
4059 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4061 TreeInfo *ti = player_name_current;
4062 int first_entry = ti->cl_first;
4063 int entry_pos = first_entry + ti->cl_cursor;
4064 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4065 int xpos = MENU_SCREEN_START_XPOS;
4066 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4068 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4069 type_name_nr = entry_pos;
4071 strcpy(name, type_name_node->name);
4075 pos->width = MAX_PLAYER_NAME_LEN * 32;
4079 type_name_nr = user.nr;
4081 strcpy(name, setup.player_name);
4084 strcpy(type_name_last, name);
4086 if (strEqual(name, EMPTY_PLAYER_NAME))
4089 *xpos = strlen(name);
4092 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4094 // change name of edited user in global list of user names
4095 setString(&global.user_names[type_name_nr], name);
4097 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4099 TreeInfo *node = type_name_node;
4101 // change name of edited user in local menu tree structure
4102 setString(&node->name, name);
4103 setString(&node->name_sorting, name);
4105 node->color = getPlayerNameColor(name);
4106 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4110 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4113 boolean reset_setup = strEqual(name, "");
4114 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4115 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4118 strcpy(name, type_name_last);
4120 if (strEqual(name, ""))
4121 strcpy(name, EMPTY_PLAYER_NAME);
4123 setTypeNameValues_Name(name, pos);
4125 // if player name not changed, no further action required
4126 if (strEqual(name, type_name_last))
4129 // redraw player name before (possibly) opening request dialogs
4130 drawTypeNameText(name, pos, FALSE);
4132 int last_user_nr = user.nr;
4134 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4136 // save setup of currently active user (may differ from edited user)
4139 // temporarily change active user to edited user
4140 user.nr = type_name_nr;
4142 // load setup of edited user (unless creating user with current setup)
4144 !Request("Use current setup values for the new player?", REQ_ASK))
4148 char *setup_filename = getSetupFilename();
4149 boolean setup_exists = fileExists(setup_filename);
4151 // change name of edited user in setup structure
4152 strcpy(setup.player_name, name);
4154 // save setup of edited user
4157 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4161 if (Request("Reset setup values for this player?", REQ_ASK))
4163 // remove setup config file
4164 unlink(setup_filename);
4166 // set player name to default player name
4169 // update player name used by name typing functions
4170 strcpy(name, setup.player_name);
4172 setTypeNameValues_Name(name, pos);
4175 else if (remove_user && type_name_nr != 0)
4177 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4179 char *user_dir = getUserGameDataDir();
4180 char *user_dir_removed =
4181 getStringCat3WithSeparator(user_dir, "REMOVED",
4182 getCurrentTimestamp(), ".");
4184 if (rename(user_dir, user_dir_removed) != 0)
4185 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4187 checked_free(user_dir_removed);
4190 else if (create_user && type_name_nr != 0 && !setup_exists)
4192 if (Request("Create empty level set for the new player?", REQ_ASK))
4194 char *levelset_subdir = getNewUserLevelSubdir();
4196 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4198 AddUserLevelSetToLevelInfo(levelset_subdir);
4200 LevelDirTree *leveldir_current_last = leveldir_current;
4202 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4205 // set level number of newly created level set to default value
4206 LoadLevelSetup_SeriesInfo();
4208 // set newly created level set as current level set for new user
4209 SaveLevelSetup_LastSeries();
4210 SaveLevelSetup_SeriesInfo();
4212 leveldir_current = leveldir_current_last;
4216 Request("Creating new level set failed!", REQ_CONFIRM);
4221 // restore currently active user
4222 user.nr = last_user_nr;
4224 // restore setup of currently active user
4227 // restore last level set of currently active user
4228 LoadLevelSetup_LastSeries();
4229 LoadLevelSetup_SeriesInfo();
4233 static void HandleTypeNameExt(boolean initialize, Key key)
4235 static struct TextPosInfo pos_name = { 0 };
4236 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4237 static int xpos = 0;
4238 struct TextPosInfo *pos = &pos_name;
4239 char key_char = getValidConfigValueChar(getCharFromKey(key));
4240 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4241 boolean active = TRUE;
4245 getTypeNameValues(name, pos, &xpos);
4247 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4248 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4250 StartTextInput(sx, sy, pos->width, pos->height);
4252 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4254 name[xpos] = key_char;
4259 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4265 else if (key == KSYM_Return || key == KSYM_Escape)
4267 boolean changed = (key == KSYM_Return);
4271 setTypeNameValues(name, pos, changed);
4276 drawTypeNameText(name, pos, active);
4280 SetGameStatus(game_status_last_screen);
4282 if (game_status == GAME_MODE_MAIN)
4283 InitializeMainControls();
4287 static void DrawTypeName(void)
4289 HandleTypeNameExt(TRUE, 0);
4292 void HandleTypeName(Key key)
4294 HandleTypeNameExt(FALSE, key);
4298 // ============================================================================
4299 // tree menu functions
4300 // ============================================================================
4302 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4304 if (game_status != GAME_MODE_SETUP ||
4305 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4308 int max_text_size = 0;
4311 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4312 max_text_size = MAX(max_text_size, strlen(node->name));
4314 int num_entries = numTreeInfoInGroup(ti);
4315 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4316 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4317 int text_width = max_text_size * getFontWidth(font_nr);
4318 int button_width = SC_MENUBUTTON_XSIZE;
4319 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4320 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4321 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4322 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4323 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4324 int align_xoffset = MAX(0, align_xoffset_raw);
4326 return align_xoffset;
4329 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4331 if (game_status != GAME_MODE_SETUP ||
4332 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4335 int num_entries = numTreeInfoInGroup(ti);
4336 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4337 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4338 int font_height = getFontHeight(font_nr);
4339 int text_height = font_height * num_page_entries;
4340 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4341 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4342 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4343 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4344 int align_yoffset = MAX(0, align_yoffset_raw);
4346 return align_yoffset;
4349 static void DrawChooseTree(TreeInfo **ti_ptr)
4351 int fade_mask = REDRAW_FIELD;
4354 fade_mask = REDRAW_ALL;
4356 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4358 SetGameStatus(GAME_MODE_MAIN);
4367 FreeScreenGadgets();
4368 CreateScreenGadgets();
4372 // needed if different viewport properties defined for choosing level (set)
4373 ChangeViewportPropertiesIfNeeded();
4375 if (game_status == GAME_MODE_NAMES)
4376 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4377 else if (game_status == GAME_MODE_LEVELNR)
4378 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4379 else if (game_status == GAME_MODE_LEVELS)
4380 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4384 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4386 MapScreenTreeGadgets(*ti_ptr);
4387 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4389 DrawMaskedBorder(fade_mask);
4394 static void drawChooseTreeList(int first_entry, int num_page_entries,
4397 int num_entries = numTreeInfoInGroup(ti);
4398 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4399 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4400 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4402 char *title_string = NULL;
4403 int yoffset_sets = MENU_TITLE1_YPOS;
4404 int yoffset_setup = 16;
4405 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4406 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4408 title_string = ti->infotext;
4410 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4412 clearMenuListArea();
4414 for (i = 0; i < num_page_entries; i++)
4416 TreeInfo *node, *node_first;
4417 int entry_pos = first_entry + i;
4419 node_first = getTreeInfoFirstGroupEntry(ti);
4420 node = getTreeInfoFromPos(node_first, entry_pos);
4422 int font_nr = MENU_CHOOSE_TREE_FONT(node->color);
4423 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4424 int xpos = MENU_SCREEN_START_XPOS;
4425 int ypos = MENU_SCREEN_START_YPOS + i;
4426 int startx = amSX + xpos * 32;
4427 int starty = amSY + ypos * 32;
4428 int startx_text = startx + font_xoffset;
4429 int endx_text = amSX + screen_width;
4430 int max_text_size = endx_text - startx_text;
4431 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4432 char buffer[max_buffer_len + 1];
4434 strncpy(buffer, node->name, max_buffer_len);
4435 buffer[max_buffer_len] = '\0';
4437 DrawText(startx, starty, buffer, font_nr);
4439 if (node->parent_link)
4440 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4441 else if (node->level_group)
4442 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4444 initCursor(i, IMG_MENU_BUTTON);
4446 if (game_status == GAME_MODE_NAMES)
4447 drawChooseTreeEdit(i, FALSE);
4450 redraw_mask |= REDRAW_FIELD;
4453 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4455 TreeInfo *node, *node_first;
4456 int x, last_redraw_mask = redraw_mask;
4457 int ypos = MENU_TITLE2_YPOS;
4458 int font_nr = FONT_TITLE_2;
4460 if (ti->type == TREE_TYPE_LEVEL_NR)
4461 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4463 if (ti->type != TREE_TYPE_LEVEL_DIR)
4466 node_first = getTreeInfoFirstGroupEntry(ti);
4467 node = getTreeInfoFromPos(node_first, entry_pos);
4469 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4471 if (node->parent_link)
4472 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4473 node->node_parent->name);
4474 else if (node->level_group)
4475 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4477 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4478 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4479 node->levels, (node->levels > 1 ? "levels" : "level"),
4482 // let BackToFront() redraw only what is needed
4483 redraw_mask = last_redraw_mask;
4484 for (x = 0; x < SCR_FIELDX; x++)
4485 MarkTileDirty(x, 1);
4488 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4491 TreeInfo *ti = *ti_ptr;
4492 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4493 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4494 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4495 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4496 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4498 int y = ti->cl_cursor;
4499 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4500 int num_entries = numTreeInfoInGroup(ti);
4501 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4502 boolean position_set_by_scrollbar = (dx == 999);
4504 if (button == MB_MENU_INITIALIZE)
4506 int num_entries = numTreeInfoInGroup(ti);
4507 int entry_pos = getPosFromTreeInfo(ti);
4509 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4510 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4512 if (ti->cl_first == -1)
4514 // only on initialization
4515 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4516 ti->cl_cursor = entry_pos - ti->cl_first;
4518 else if (ti->cl_cursor >= num_page_entries ||
4519 (num_entries > num_page_entries &&
4520 num_entries - ti->cl_first < num_page_entries))
4522 // only after change of list size (by custom graphic configuration)
4523 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4524 ti->cl_cursor = entry_pos - ti->cl_first;
4527 if (position_set_by_scrollbar)
4530 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4533 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4534 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4535 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4539 else if (button == MB_MENU_LEAVE)
4543 PlaySound(SND_MENU_ITEM_SELECTING);
4545 if (ti->node_parent)
4547 *ti_ptr = ti->node_parent;
4548 DrawChooseTree(ti_ptr);
4550 else if (game_status == GAME_MODE_SETUP)
4552 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4553 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4554 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4556 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4557 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4558 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4559 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4560 execSetupGraphics();
4561 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4562 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4563 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4565 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4566 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4567 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4568 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4569 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4570 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4571 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4572 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4579 if (game_status == GAME_MODE_LEVELNR)
4581 int new_level_nr = atoi(level_number_current->identifier);
4583 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4586 SetGameStatus(GAME_MODE_MAIN);
4594 if (mx || my) // mouse input
4596 x = (mx - amSX) / 32;
4597 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4599 if (game_status == GAME_MODE_NAMES)
4600 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4602 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4604 // move cursor instead of scrolling when already at start/end of list
4605 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4607 else if (dy == +1 * SCROLL_LINE &&
4608 ti->cl_first + num_page_entries == num_entries)
4611 // handle scrolling screen one line or page
4612 if (ti->cl_cursor + dy < 0 ||
4613 ti->cl_cursor + dy > num_page_entries - 1)
4615 boolean redraw = FALSE;
4617 if (ABS(dy) == SCROLL_PAGE)
4618 step = num_page_entries - 1;
4620 if (dy < 0 && ti->cl_first > 0)
4622 // scroll page/line up
4624 ti->cl_first -= step;
4625 if (ti->cl_first < 0)
4630 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4632 // scroll page/line down
4634 ti->cl_first += step;
4635 if (ti->cl_first + num_page_entries > num_entries)
4636 ti->cl_first = MAX(0, num_entries - num_page_entries);
4643 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4644 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4645 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4647 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4654 // handle moving cursor one line
4655 y = ti->cl_cursor + dy;
4660 TreeInfo *node_first, *node_cursor;
4661 int entry_pos = ti->cl_first + y;
4663 node_first = getTreeInfoFirstGroupEntry(ti);
4664 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4666 if (node_cursor->node_group)
4670 PlaySound(SND_MENU_ITEM_SELECTING);
4672 node_cursor->cl_first = ti->cl_first;
4673 node_cursor->cl_cursor = ti->cl_cursor;
4674 *ti_ptr = node_cursor->node_group;
4675 DrawChooseTree(ti_ptr);
4680 else if (dx == -1 && ti->node_parent)
4684 PlaySound(SND_MENU_ITEM_SELECTING);
4686 *ti_ptr = ti->node_parent;
4687 DrawChooseTree(ti_ptr);
4692 if (!anyScrollbarGadgetActive() &&
4693 IN_VIS_MENU(x, y) &&
4694 mx < mx_right_border &&
4695 y >= 0 && y < num_page_entries)
4699 if (game_status == GAME_MODE_NAMES)
4701 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4702 drawChooseTreeEdit(y, TRUE);
4705 if (y != ti->cl_cursor)
4707 PlaySound(SND_MENU_ITEM_ACTIVATING);
4709 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4710 drawChooseTreeCursor(y, TRUE);
4711 drawChooseTreeInfo(ti->cl_first + y, ti);
4717 if (game_status == GAME_MODE_SETUP)
4719 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4720 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4721 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4723 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4724 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4725 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4726 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4727 execSetupGraphics();
4728 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4729 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4730 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4732 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4733 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4734 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4735 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4736 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4737 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4738 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4739 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4748 TreeInfo *node_first, *node_cursor;
4749 int entry_pos = ti->cl_first + y;
4751 PlaySound(SND_MENU_ITEM_SELECTING);
4753 node_first = getTreeInfoFirstGroupEntry(ti);
4754 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4756 if (node_cursor->node_group)
4760 node_cursor->cl_first = ti->cl_first;
4761 node_cursor->cl_cursor = ti->cl_cursor;
4762 *ti_ptr = node_cursor->node_group;
4763 DrawChooseTree(ti_ptr);
4765 else if (node_cursor->parent_link)
4769 *ti_ptr = node_cursor->node_parent;
4770 DrawChooseTree(ti_ptr);
4776 node_cursor->cl_first = ti->cl_first;
4777 node_cursor->cl_cursor = ti->cl_cursor;
4778 *ti_ptr = node_cursor;
4780 if (ti->type == TREE_TYPE_LEVEL_DIR)
4782 LoadLevelSetup_SeriesInfo();
4784 SaveLevelSetup_LastSeries();
4785 SaveLevelSetup_SeriesInfo();
4789 if (game_status == GAME_MODE_SETUP)
4791 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4792 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4793 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4795 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4796 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4797 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4798 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4799 execSetupGraphics();
4800 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4801 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4802 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4804 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4805 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4806 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4807 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4808 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4809 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4810 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4811 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4818 if (game_status == GAME_MODE_LEVELNR)
4820 int new_level_nr = atoi(level_number_current->identifier);
4822 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4824 else if (game_status == GAME_MODE_NAMES)
4826 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4828 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
4835 // change active user to selected user
4836 user.nr = entry_pos;
4838 // save number of new active user
4841 // load setup of new active user
4844 // load last level set of new active user
4845 LoadLevelSetup_LastSeries();
4846 LoadLevelSetup_SeriesInfo();
4850 ToggleFullscreenIfNeeded();
4851 ChangeWindowScalingIfNeeded();
4853 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
4854 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
4855 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
4858 SetGameStatus(GAME_MODE_MAIN);
4867 void DrawChoosePlayerName(void)
4871 FadeMenuSoundsAndMusic();
4873 if (player_name != NULL)
4875 freeTreeInfo(player_name);
4880 for (i = 0; i < MAX_PLAYER_NAMES; i++)
4882 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
4883 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
4886 ti->node_top = &player_name;
4887 ti->sort_priority = 10000 + value;
4888 ti->color = getPlayerNameColor(global.user_names[i]);
4890 snprintf(identifier, sizeof(identifier), "%d", value);
4891 snprintf(name, sizeof(name), "%s", global.user_names[i]);
4893 setString(&ti->identifier, identifier);
4894 setString(&ti->name, name);
4895 setString(&ti->name_sorting, name);
4897 pushTreeInfo(&player_name, ti);
4900 // sort player entries by player number
4901 sortTreeInfo(&player_name);
4903 // set current player entry to selected player entry
4904 player_name_current =
4905 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
4907 // if that fails, set current player name to first available name
4908 if (player_name_current == NULL)
4909 player_name_current = player_name;
4911 DrawChooseTree(&player_name_current);
4913 PlayMenuSoundsAndMusic();
4916 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
4918 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
4921 void DrawChooseLevelSet(void)
4923 FadeMenuSoundsAndMusic();
4925 DrawChooseTree(&leveldir_current);
4927 PlayMenuSoundsAndMusic();
4930 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4932 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4935 void DrawChooseLevelNr(void)
4939 FadeMenuSoundsAndMusic();
4941 if (level_number != NULL)
4943 freeTreeInfo(level_number);
4945 level_number = NULL;
4948 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4950 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4951 char identifier[32], name[64];
4954 // temporarily load level info to get level name
4955 LoadLevelInfoOnly(i);
4957 ti->node_top = &level_number;
4958 ti->sort_priority = 10000 + value;
4959 ti->color = (level.no_level_file ? FC_BLUE :
4960 LevelStats_getSolved(i) ? FC_GREEN :
4961 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4963 snprintf(identifier, sizeof(identifier), "%d", value);
4964 snprintf(name, sizeof(name), "%03d: %s", value,
4965 (level.no_level_file ? "(no file)" : level.name));
4967 setString(&ti->identifier, identifier);
4968 setString(&ti->name, name);
4969 setString(&ti->name_sorting, name);
4971 pushTreeInfo(&level_number, ti);
4974 // sort level number values to start with lowest level number
4975 sortTreeInfo(&level_number);
4977 // set current level number to current level number
4978 level_number_current =
4979 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4981 // if that also fails, set current level number to first available level
4982 if (level_number_current == NULL)
4983 level_number_current = level_number;
4985 DrawChooseTree(&level_number_current);
4987 PlayMenuSoundsAndMusic();
4990 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4992 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4995 void DrawHallOfFame(int level_nr, int highlight_position)
4997 int fade_mask = REDRAW_FIELD;
5000 fade_mask = REDRAW_ALL;
5003 FadeMenuSoundsAndMusic();
5005 // (this is needed when called from GameEnd() after winning a game)
5006 KeyboardAutoRepeatOn();
5008 // (this is needed when called from GameEnd() after winning a game)
5009 SetDrawDeactivationMask(REDRAW_NONE);
5010 SetDrawBackgroundMask(REDRAW_FIELD);
5012 if (highlight_position < 0)
5013 LoadScore(level_nr);
5015 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5017 FadeSetEnterScreen();
5021 // needed if different viewport properties defined for scores
5022 ChangeViewportPropertiesIfNeeded();
5024 PlayMenuSoundsAndMusic();
5026 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5028 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
5030 DrawMaskedBorder(fade_mask);
5035 static void drawHallOfFameList(int level_nr, int first_entry,
5036 int highlight_position)
5040 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5043 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
5044 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
5045 "HighScores of Level %d", level_nr);
5047 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5049 int entry = first_entry + i;
5050 boolean active = (entry == highlight_position);
5051 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
5052 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
5053 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
5054 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
5055 int dxoff = getFontDrawOffsetX(font_nr1);
5056 int dx1 = 3 * getFontWidth(font_nr1);
5057 int dx2 = dx1 + getFontWidth(font_nr1);
5058 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
5059 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
5060 int sy = mSY + 64 + i * 32;
5062 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
5063 DrawText(mSX + dx1, sy, ".", font_nr1);
5065 for (j = 0; j < num_dots; j++)
5066 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
5068 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
5069 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
5071 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
5074 redraw_mask |= REDRAW_FIELD;
5077 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5079 static int level_nr = 0;
5080 static int first_entry = 0;
5081 static int highlight_position = 0;
5082 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5084 if (button == MB_MENU_INITIALIZE)
5087 highlight_position = my;
5089 first_entry = highlight_position - (NUM_MENU_ENTRIES_ON_SCREEN + 1) / 2 + 1;
5091 if (first_entry < 0)
5093 else if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
5094 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
5096 drawHallOfFameList(level_nr, first_entry, highlight_position);
5101 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
5102 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
5106 if (first_entry > 0)
5108 first_entry -= step;
5109 if (first_entry < 0)
5112 drawHallOfFameList(level_nr, first_entry, highlight_position);
5117 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
5119 first_entry += step;
5120 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
5121 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
5123 drawHallOfFameList(level_nr, first_entry, highlight_position);
5126 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5128 PlaySound(SND_MENU_ITEM_SELECTING);
5130 FadeSound(SND_BACKGROUND_SCORES);
5132 if (button == MB_MENU_CHOICE &&
5133 game_status_last_screen == GAME_MODE_PLAYING &&
5134 setup.auto_play_next_level && setup.increment_levels &&
5135 level_nr < leveldir_current->last_level &&
5138 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
5142 SetGameStatus(GAME_MODE_MAIN);
5148 if (game_status == GAME_MODE_SCORES)
5149 PlayMenuSoundIfLoop();
5153 // ============================================================================
5154 // setup screen functions
5155 // ============================================================================
5157 static struct TokenInfo *setup_info;
5158 static int num_setup_info; // number of setup entries shown on screen
5159 static int max_setup_info; // total number of setup entries in list
5161 static char *window_size_text;
5162 static char *scaling_type_text;
5163 static char *rendering_mode_text;
5164 static char *vsync_mode_text;
5165 static char *scroll_delay_text;
5166 static char *snapshot_mode_text;
5167 static char *game_speed_text;
5168 static char *network_server_text;
5169 static char *graphics_set_name;
5170 static char *sounds_set_name;
5171 static char *music_set_name;
5172 static char *volume_simple_text;
5173 static char *volume_loops_text;
5174 static char *volume_music_text;
5175 static char *touch_controls_text;
5176 static char *move_distance_text;
5177 static char *drop_distance_text;
5178 static char *transparency_text;
5179 static char *grid_size_text[2][2];
5181 static void execSetupMain(void)
5183 setup_mode = SETUP_MODE_MAIN;
5188 static void execSetupGame_setGameSpeeds(boolean update_value)
5190 if (setup.game_speed_extended)
5192 game_speeds_list = game_speeds_list_extended;
5193 game_speeds = game_speeds_extended;
5197 game_speeds_list = game_speeds_list_normal;
5198 game_speeds = game_speeds_normal;
5201 if (game_speeds == NULL)
5205 for (i = 0; game_speeds_list[i].value != -1; i++)
5207 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5208 char identifier[32], name[32];
5209 int value = game_speeds_list[i].value;
5210 char *text = game_speeds_list[i].text;
5212 ti->node_top = &game_speeds;
5213 ti->sort_priority = 10000 - value;
5215 sprintf(identifier, "%d", value);
5216 sprintf(name, "%s", text);
5218 setString(&ti->identifier, identifier);
5219 setString(&ti->name, name);
5220 setString(&ti->name_sorting, name);
5221 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5223 pushTreeInfo(&game_speeds, ti);
5226 // sort game speed values to start with slowest game speed
5227 sortTreeInfo(&game_speeds);
5229 update_value = TRUE;
5234 // set current game speed to configured game speed value
5235 game_speed_current =
5236 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5238 // if that fails, set current game speed to reliable default value
5239 if (game_speed_current == NULL)
5240 game_speed_current =
5241 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5243 // if that also fails, set current game speed to first available speed
5244 if (game_speed_current == NULL)
5245 game_speed_current = game_speeds;
5247 if (setup.game_speed_extended)
5248 game_speeds_extended = game_speeds;
5250 game_speeds_normal = game_speeds;
5253 setup.game_frame_delay = atoi(game_speed_current->identifier);
5255 // needed for displaying game speed text instead of identifier
5256 game_speed_text = game_speed_current->name;
5259 static void execSetupGame_setScrollDelays(void)
5261 if (scroll_delays == NULL)
5265 for (i = 0; scroll_delays_list[i].value != -1; i++)
5267 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5268 char identifier[32], name[32];
5269 int value = scroll_delays_list[i].value;
5270 char *text = scroll_delays_list[i].text;
5272 ti->node_top = &scroll_delays;
5273 ti->sort_priority = value;
5275 sprintf(identifier, "%d", value);
5276 sprintf(name, "%s", text);
5278 setString(&ti->identifier, identifier);
5279 setString(&ti->name, name);
5280 setString(&ti->name_sorting, name);
5281 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5283 pushTreeInfo(&scroll_delays, ti);
5286 // sort scroll delay values to start with lowest scroll delay value
5287 sortTreeInfo(&scroll_delays);
5289 // set current scroll delay value to configured scroll delay value
5290 scroll_delay_current =
5291 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5293 // if that fails, set current scroll delay to reliable default value
5294 if (scroll_delay_current == NULL)
5295 scroll_delay_current =
5296 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5298 // if that also fails, set current scroll delay to first available value
5299 if (scroll_delay_current == NULL)
5300 scroll_delay_current = scroll_delays;
5303 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5305 // needed for displaying scroll delay text instead of identifier
5306 scroll_delay_text = scroll_delay_current->name;
5309 static void execSetupGame_setSnapshotModes(void)
5311 if (snapshot_modes == NULL)
5315 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5317 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5318 char identifier[32], name[32];
5319 char *value = snapshot_modes_list[i].value;
5320 char *text = snapshot_modes_list[i].text;
5322 ti->node_top = &snapshot_modes;
5323 ti->sort_priority = i;
5325 sprintf(identifier, "%s", value);
5326 sprintf(name, "%s", text);
5328 setString(&ti->identifier, identifier);
5329 setString(&ti->name, name);
5330 setString(&ti->name_sorting, name);
5331 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5333 pushTreeInfo(&snapshot_modes, ti);
5336 // sort snapshot mode values to start with lowest snapshot mode value
5337 sortTreeInfo(&snapshot_modes);
5339 // set current snapshot mode value to configured snapshot mode value
5340 snapshot_mode_current =
5341 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5343 // if that fails, set current snapshot mode to reliable default value
5344 if (snapshot_mode_current == NULL)
5345 snapshot_mode_current =
5346 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5348 // if that also fails, set current snapshot mode to first available value
5349 if (snapshot_mode_current == NULL)
5350 snapshot_mode_current = snapshot_modes;
5353 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5355 // needed for displaying snapshot mode text instead of identifier
5356 snapshot_mode_text = snapshot_mode_current->name;
5359 static void execSetupGame_setNetworkServerText(void)
5361 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5363 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5367 strncpy(network_server_hostname, setup.network_server_hostname,
5368 MAX_SETUP_TEXT_INPUT_LEN);
5369 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5372 // needed for displaying network server text instead of identifier
5373 network_server_text = network_server_hostname;
5376 static void execSetupGame(void)
5378 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5380 execSetupGame_setGameSpeeds(FALSE);
5381 execSetupGame_setScrollDelays();
5382 execSetupGame_setSnapshotModes();
5384 execSetupGame_setNetworkServerText();
5386 setup_mode = SETUP_MODE_GAME;
5390 // check if vsync needs to be disabled for this game speed to work
5391 if (check_vsync_mode)
5392 DisableVsyncIfNeeded();
5395 static void execSetupChooseGameSpeed(void)
5397 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5402 static void execSetupChooseScrollDelay(void)
5404 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5409 static void execSetupChooseSnapshotMode(void)
5411 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5416 static void execSetupEngines(void)
5418 setup_mode = SETUP_MODE_ENGINES;
5423 static void execSetupEditor(void)
5425 setup_mode = SETUP_MODE_EDITOR;
5430 static void execSetupGraphics_setWindowSizes(boolean update_list)
5432 if (window_sizes != NULL && update_list)
5434 freeTreeInfo(window_sizes);
5436 window_sizes = NULL;
5439 if (window_sizes == NULL)
5441 boolean current_window_size_found = FALSE;
5444 for (i = 0; window_sizes_list[i].value != -1; i++)
5446 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5447 char identifier[32], name[32];
5448 int value = window_sizes_list[i].value;
5449 char *text = window_sizes_list[i].text;
5451 ti->node_top = &window_sizes;
5452 ti->sort_priority = value;
5454 sprintf(identifier, "%d", value);
5455 sprintf(name, "%s", text);
5457 setString(&ti->identifier, identifier);
5458 setString(&ti->name, name);
5459 setString(&ti->name_sorting, name);
5460 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5462 pushTreeInfo(&window_sizes, ti);
5464 if (value == setup.window_scaling_percent)
5465 current_window_size_found = TRUE;
5468 if (!current_window_size_found)
5470 // add entry for non-preset window scaling value
5472 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5473 char identifier[32], name[32];
5474 int value = setup.window_scaling_percent;
5476 ti->node_top = &window_sizes;
5477 ti->sort_priority = value;
5479 sprintf(identifier, "%d", value);
5480 sprintf(name, "%d %% (Current)", value);
5482 setString(&ti->identifier, identifier);
5483 setString(&ti->name, name);
5484 setString(&ti->name_sorting, name);
5485 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5487 pushTreeInfo(&window_sizes, ti);
5490 // sort window size values to start with lowest window size value
5491 sortTreeInfo(&window_sizes);
5493 // set current window size value to configured window size value
5494 window_size_current =
5495 getTreeInfoFromIdentifier(window_sizes,
5496 i_to_a(setup.window_scaling_percent));
5498 // if that fails, set current window size to reliable default value
5499 if (window_size_current == NULL)
5500 window_size_current =
5501 getTreeInfoFromIdentifier(window_sizes,
5502 i_to_a(STD_WINDOW_SCALING_PERCENT));
5504 // if that also fails, set current window size to first available value
5505 if (window_size_current == NULL)
5506 window_size_current = window_sizes;
5509 setup.window_scaling_percent = atoi(window_size_current->identifier);
5511 // needed for displaying window size text instead of identifier
5512 window_size_text = window_size_current->name;
5515 static void execSetupGraphics_setScalingTypes(void)
5517 if (scaling_types == NULL)
5521 for (i = 0; scaling_types_list[i].value != NULL; i++)
5523 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5524 char identifier[32], name[32];
5525 char *value = scaling_types_list[i].value;
5526 char *text = scaling_types_list[i].text;
5528 ti->node_top = &scaling_types;
5529 ti->sort_priority = i;
5531 sprintf(identifier, "%s", value);
5532 sprintf(name, "%s", text);
5534 setString(&ti->identifier, identifier);
5535 setString(&ti->name, name);
5536 setString(&ti->name_sorting, name);
5537 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5539 pushTreeInfo(&scaling_types, ti);
5542 // sort scaling type values to start with lowest scaling type value
5543 sortTreeInfo(&scaling_types);
5545 // set current scaling type value to configured scaling type value
5546 scaling_type_current =
5547 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5549 // if that fails, set current scaling type to reliable default value
5550 if (scaling_type_current == NULL)
5551 scaling_type_current =
5552 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5554 // if that also fails, set current scaling type to first available value
5555 if (scaling_type_current == NULL)
5556 scaling_type_current = scaling_types;
5559 setup.window_scaling_quality = scaling_type_current->identifier;
5561 // needed for displaying scaling type text instead of identifier
5562 scaling_type_text = scaling_type_current->name;
5565 static void execSetupGraphics_setRenderingModes(void)
5567 if (rendering_modes == NULL)
5571 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5573 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5574 char identifier[32], name[32];
5575 char *value = rendering_modes_list[i].value;
5576 char *text = rendering_modes_list[i].text;
5578 ti->node_top = &rendering_modes;
5579 ti->sort_priority = i;
5581 sprintf(identifier, "%s", value);
5582 sprintf(name, "%s", text);
5584 setString(&ti->identifier, identifier);
5585 setString(&ti->name, name);
5586 setString(&ti->name_sorting, name);
5587 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5589 pushTreeInfo(&rendering_modes, ti);
5592 // sort rendering mode values to start with lowest rendering mode value
5593 sortTreeInfo(&rendering_modes);
5595 // set current rendering mode value to configured rendering mode value
5596 rendering_mode_current =
5597 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5599 // if that fails, set current rendering mode to reliable default value
5600 if (rendering_mode_current == NULL)
5601 rendering_mode_current =
5602 getTreeInfoFromIdentifier(rendering_modes,
5603 STR_SPECIAL_RENDERING_DEFAULT);
5605 // if that also fails, set current rendering mode to first available one
5606 if (rendering_mode_current == NULL)
5607 rendering_mode_current = rendering_modes;
5610 setup.screen_rendering_mode = rendering_mode_current->identifier;
5612 // needed for displaying rendering mode text instead of identifier
5613 rendering_mode_text = rendering_mode_current->name;
5616 static void execSetupGraphics_setVsyncModes(boolean update_value)
5618 if (vsync_modes == NULL)
5622 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5624 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5625 char identifier[32], name[32];
5626 char *value = vsync_modes_list[i].value;
5627 char *text = vsync_modes_list[i].text;
5629 ti->node_top = &vsync_modes;
5630 ti->sort_priority = i;
5632 sprintf(identifier, "%s", value);
5633 sprintf(name, "%s", text);
5635 setString(&ti->identifier, identifier);
5636 setString(&ti->name, name);
5637 setString(&ti->name_sorting, name);
5638 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5640 pushTreeInfo(&vsync_modes, ti);
5643 // sort vsync mode values to start with lowest vsync mode value
5644 sortTreeInfo(&vsync_modes);
5646 update_value = TRUE;
5651 // set current vsync mode value to configured vsync mode value
5652 vsync_mode_current =
5653 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5655 // if that fails, set current vsync mode to reliable default value
5656 if (vsync_mode_current == NULL)
5657 vsync_mode_current =
5658 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5660 // if that also fails, set current vsync mode to first available one
5661 if (vsync_mode_current == NULL)
5662 vsync_mode_current = vsync_modes;
5665 setup.vsync_mode = vsync_mode_current->identifier;
5667 // needed for displaying vsync mode text instead of identifier
5668 vsync_mode_text = vsync_mode_current->name;
5671 static void execSetupGraphics(void)
5673 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5675 // update "setup.window_scaling_percent" from list selection
5676 // (in this case, window scaling was changed on setup screen)
5677 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5678 execSetupGraphics_setWindowSizes(FALSE);
5680 // update "setup.vsync_mode" from list selection
5681 // (in this case, vsync mode was changed on setup screen)
5682 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5683 execSetupGraphics_setVsyncModes(FALSE);
5685 // update list selection from "setup.window_scaling_percent"
5686 // (window scaling may have changed by resizing the window)
5687 execSetupGraphics_setWindowSizes(TRUE);
5689 // update list selection from "setup.vsync_mode"
5690 // (vsync_mode may have changed by re-creating the renderer)
5691 execSetupGraphics_setVsyncModes(TRUE);
5693 execSetupGraphics_setScalingTypes();
5694 execSetupGraphics_setRenderingModes();
5696 setup_mode = SETUP_MODE_GRAPHICS;
5700 // check if game speed is high enough for 60 Hz vsync to work
5701 if (check_game_speed)
5702 ModifyGameSpeedIfNeeded();
5704 // window scaling may have changed at this point
5705 ChangeWindowScalingIfNeeded();
5707 // window scaling quality may have changed at this point
5708 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5709 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5711 // screen rendering mode may have changed at this point
5712 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5714 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
5715 int video_vsync_mode = video.vsync_mode;
5717 // screen vsync mode may have changed at this point
5718 ChangeVsyncModeIfNeeded();
5720 // check if setting vsync mode to selected value failed
5721 if (setup_vsync_mode != video_vsync_mode &&
5722 setup_vsync_mode != video.vsync_mode)
5724 // changing vsync mode to selected value failed -- reset displayed value
5725 execSetupGraphics_setVsyncModes(TRUE);
5727 Request("Setting VSync failed!", REQ_CONFIRM);
5733 static void execSetupChooseWindowSize(void)
5735 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5740 static void execSetupChooseScalingType(void)
5742 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5747 static void execSetupChooseRenderingMode(void)
5749 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5754 static void execSetupChooseVsyncMode(void)
5756 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5761 static void execSetupChooseVolumeSimple(void)
5763 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5768 static void execSetupChooseVolumeLoops(void)
5770 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5775 static void execSetupChooseVolumeMusic(void)
5777 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5782 static void execSetupSound(void)
5784 if (volumes_simple == NULL)
5786 boolean current_volume_simple_found = FALSE;
5789 for (i = 0; volumes_list[i].value != -1; i++)
5791 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5792 char identifier[32], name[32];
5793 int value = volumes_list[i].value;
5794 char *text = volumes_list[i].text;
5796 ti->node_top = &volumes_simple;
5797 ti->sort_priority = value;
5799 sprintf(identifier, "%d", value);
5800 sprintf(name, "%s", text);
5802 setString(&ti->identifier, identifier);
5803 setString(&ti->name, name);
5804 setString(&ti->name_sorting, name);
5805 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5807 pushTreeInfo(&volumes_simple, ti);
5809 if (value == setup.volume_simple)
5810 current_volume_simple_found = TRUE;
5813 if (!current_volume_simple_found)
5815 // add entry for non-preset volume value
5817 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5818 char identifier[32], name[32];
5819 int value = setup.volume_simple;
5821 ti->node_top = &volumes_simple;
5822 ti->sort_priority = value;
5824 sprintf(identifier, "%d", value);
5825 sprintf(name, "%d %% (Current)", value);
5827 setString(&ti->identifier, identifier);
5828 setString(&ti->name, name);
5829 setString(&ti->name_sorting, name);
5830 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5832 pushTreeInfo(&volumes_simple, ti);
5835 // sort volume values to start with lowest volume value
5836 sortTreeInfo(&volumes_simple);
5838 // set current volume value to configured volume value
5839 volume_simple_current =
5840 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5842 // if that fails, set current volume to reliable default value
5843 if (volume_simple_current == NULL)
5844 volume_simple_current =
5845 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5847 // if that also fails, set current volume to first available value
5848 if (volume_simple_current == NULL)
5849 volume_simple_current = volumes_simple;
5852 if (volumes_loops == NULL)
5854 boolean current_volume_loops_found = FALSE;
5857 for (i = 0; volumes_list[i].value != -1; i++)
5859 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5860 char identifier[32], name[32];
5861 int value = volumes_list[i].value;
5862 char *text = volumes_list[i].text;
5864 ti->node_top = &volumes_loops;
5865 ti->sort_priority = value;
5867 sprintf(identifier, "%d", value);
5868 sprintf(name, "%s", text);
5870 setString(&ti->identifier, identifier);
5871 setString(&ti->name, name);
5872 setString(&ti->name_sorting, name);
5873 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5875 pushTreeInfo(&volumes_loops, ti);
5877 if (value == setup.volume_loops)
5878 current_volume_loops_found = TRUE;
5881 if (!current_volume_loops_found)
5883 // add entry for non-preset volume value
5885 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5886 char identifier[32], name[32];
5887 int value = setup.volume_loops;
5889 ti->node_top = &volumes_loops;
5890 ti->sort_priority = value;
5892 sprintf(identifier, "%d", value);
5893 sprintf(name, "%d %% (Current)", value);
5895 setString(&ti->identifier, identifier);
5896 setString(&ti->name, name);
5897 setString(&ti->name_sorting, name);
5898 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5900 pushTreeInfo(&volumes_loops, ti);
5903 // sort volume values to start with lowest volume value
5904 sortTreeInfo(&volumes_loops);
5906 // set current volume value to configured volume value
5907 volume_loops_current =
5908 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5910 // if that fails, set current volume to reliable default value
5911 if (volume_loops_current == NULL)
5912 volume_loops_current =
5913 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5915 // if that also fails, set current volume to first available value
5916 if (volume_loops_current == NULL)
5917 volume_loops_current = volumes_loops;
5920 if (volumes_music == NULL)
5922 boolean current_volume_music_found = FALSE;
5925 for (i = 0; volumes_list[i].value != -1; i++)
5927 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5928 char identifier[32], name[32];
5929 int value = volumes_list[i].value;
5930 char *text = volumes_list[i].text;
5932 ti->node_top = &volumes_music;
5933 ti->sort_priority = value;
5935 sprintf(identifier, "%d", value);
5936 sprintf(name, "%s", text);
5938 setString(&ti->identifier, identifier);
5939 setString(&ti->name, name);
5940 setString(&ti->name_sorting, name);
5941 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5943 pushTreeInfo(&volumes_music, ti);
5945 if (value == setup.volume_music)
5946 current_volume_music_found = TRUE;
5949 if (!current_volume_music_found)
5951 // add entry for non-preset volume value
5953 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5954 char identifier[32], name[32];
5955 int value = setup.volume_music;
5957 ti->node_top = &volumes_music;
5958 ti->sort_priority = value;
5960 sprintf(identifier, "%d", value);
5961 sprintf(name, "%d %% (Current)", value);
5963 setString(&ti->identifier, identifier);
5964 setString(&ti->name, name);
5965 setString(&ti->name_sorting, name);
5966 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5968 pushTreeInfo(&volumes_music, ti);
5971 // sort volume values to start with lowest volume value
5972 sortTreeInfo(&volumes_music);
5974 // set current volume value to configured volume value
5975 volume_music_current =
5976 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5978 // if that fails, set current volume to reliable default value
5979 if (volume_music_current == NULL)
5980 volume_music_current =
5981 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5983 // if that also fails, set current volume to first available value
5984 if (volume_music_current == NULL)
5985 volume_music_current = volumes_music;
5988 setup.volume_simple = atoi(volume_simple_current->identifier);
5989 setup.volume_loops = atoi(volume_loops_current->identifier);
5990 setup.volume_music = atoi(volume_music_current->identifier);
5992 // needed for displaying volume text instead of identifier
5993 volume_simple_text = volume_simple_current->name;
5994 volume_loops_text = volume_loops_current->name;
5995 volume_music_text = volume_music_current->name;
5997 setup_mode = SETUP_MODE_SOUND;
6002 static void execSetupChooseTouchControls(void)
6004 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6009 static void execSetupChooseMoveDistance(void)
6011 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6016 static void execSetupChooseDropDistance(void)
6018 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6023 static void execSetupChooseTransparency(void)
6025 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6030 static void execSetupChooseGridXSize_0(void)
6032 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6037 static void execSetupChooseGridYSize_0(void)
6039 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6044 static void execSetupChooseGridXSize_1(void)
6046 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6051 static void execSetupChooseGridYSize_1(void)
6053 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6058 static void execSetupConfigureVirtualButtons(void)
6060 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6062 ConfigureVirtualButtons();
6064 setup_mode = SETUP_MODE_TOUCH;
6069 static void execSetupTouch(void)
6073 if (touch_controls == NULL)
6075 for (i = 0; touch_controls_list[i].value != NULL; i++)
6077 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6078 char identifier[32], name[32];
6079 char *value = touch_controls_list[i].value;
6080 char *text = touch_controls_list[i].text;
6082 ti->node_top = &touch_controls;
6083 ti->sort_priority = i;
6085 sprintf(identifier, "%s", value);
6086 sprintf(name, "%s", text);
6088 setString(&ti->identifier, identifier);
6089 setString(&ti->name, name);
6090 setString(&ti->name_sorting, name);
6091 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6093 pushTreeInfo(&touch_controls, ti);
6096 // sort touch control values to start with lowest touch control value
6097 sortTreeInfo(&touch_controls);
6099 // set current touch control value to configured touch control value
6100 touch_control_current =
6101 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6103 // if that fails, set current touch control to reliable default value
6104 if (touch_control_current == NULL)
6105 touch_control_current =
6106 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6108 // if that also fails, set current touch control to first available value
6109 if (touch_control_current == NULL)
6110 touch_control_current = touch_controls;
6113 if (move_distances == NULL)
6115 for (i = 0; distances_list[i].value != -1; i++)
6117 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6118 char identifier[32], name[32];
6119 int value = distances_list[i].value;
6120 char *text = distances_list[i].text;
6122 ti->node_top = &move_distances;
6123 ti->sort_priority = value;
6125 sprintf(identifier, "%d", value);
6126 sprintf(name, "%s", text);
6128 setString(&ti->identifier, identifier);
6129 setString(&ti->name, name);
6130 setString(&ti->name_sorting, name);
6131 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6133 pushTreeInfo(&move_distances, ti);
6136 // sort distance values to start with lowest distance value
6137 sortTreeInfo(&move_distances);
6139 // set current distance value to configured distance value
6140 move_distance_current =
6141 getTreeInfoFromIdentifier(move_distances,
6142 i_to_a(setup.touch.move_distance));
6144 // if that fails, set current distance to reliable default value
6145 if (move_distance_current == NULL)
6146 move_distance_current =
6147 getTreeInfoFromIdentifier(move_distances,
6148 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6150 // if that also fails, set current distance to first available value
6151 if (move_distance_current == NULL)
6152 move_distance_current = move_distances;
6155 if (drop_distances == NULL)
6157 for (i = 0; distances_list[i].value != -1; i++)
6159 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6160 char identifier[32], name[32];
6161 int value = distances_list[i].value;
6162 char *text = distances_list[i].text;
6164 ti->node_top = &drop_distances;
6165 ti->sort_priority = value;
6167 sprintf(identifier, "%d", value);
6168 sprintf(name, "%s", text);
6170 setString(&ti->identifier, identifier);
6171 setString(&ti->name, name);
6172 setString(&ti->name_sorting, name);
6173 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6175 pushTreeInfo(&drop_distances, ti);
6178 // sort distance values to start with lowest distance value
6179 sortTreeInfo(&drop_distances);
6181 // set current distance value to configured distance value
6182 drop_distance_current =
6183 getTreeInfoFromIdentifier(drop_distances,
6184 i_to_a(setup.touch.drop_distance));
6186 // if that fails, set current distance to reliable default value
6187 if (drop_distance_current == NULL)
6188 drop_distance_current =
6189 getTreeInfoFromIdentifier(drop_distances,
6190 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6192 // if that also fails, set current distance to first available value
6193 if (drop_distance_current == NULL)
6194 drop_distance_current = drop_distances;
6197 if (transparencies == NULL)
6199 for (i = 0; transparencies_list[i].value != -1; i++)
6201 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6202 char identifier[32], name[32];
6203 int value = transparencies_list[i].value;
6204 char *text = transparencies_list[i].text;
6206 ti->node_top = &transparencies;
6207 ti->sort_priority = value;
6209 sprintf(identifier, "%d", value);
6210 sprintf(name, "%s", text);
6212 setString(&ti->identifier, identifier);
6213 setString(&ti->name, name);
6214 setString(&ti->name_sorting, name);
6215 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6217 pushTreeInfo(&transparencies, ti);
6220 // sort transparency values to start with lowest transparency value
6221 sortTreeInfo(&transparencies);
6223 // set current transparency value to configured transparency value
6224 transparency_current =
6225 getTreeInfoFromIdentifier(transparencies,
6226 i_to_a(setup.touch.transparency));
6228 // if that fails, set current transparency to reliable default value
6229 if (transparency_current == NULL)
6230 transparency_current =
6231 getTreeInfoFromIdentifier(transparencies,
6232 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6234 // if that also fails, set current transparency to first available value
6235 if (transparency_current == NULL)
6236 transparency_current = transparencies;
6239 for (i = 0; i < 2; i++)
6241 for (j = 0; j < 2; j++)
6243 if (grid_sizes[i][j] == NULL)
6245 for (k = 0; grid_sizes_list[k].value != -1; k++)
6247 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6248 char identifier[32], name[32];
6249 int value = grid_sizes_list[k].value;
6250 char *text = grid_sizes_list[k].text;
6252 ti->node_top = &grid_sizes[i][j];
6253 ti->sort_priority = value;
6255 sprintf(identifier, "%d", value);
6256 sprintf(name, "%s", text);
6258 setString(&ti->identifier, identifier);
6259 setString(&ti->name, name);
6260 setString(&ti->name_sorting, name);
6261 setString(&ti->infotext,
6264 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6265 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6267 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6268 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6270 pushTreeInfo(&grid_sizes[i][j], ti);
6273 // sort grid size values to start with lowest grid size value
6274 sortTreeInfo(&grid_sizes[i][j]);
6276 // set current grid size value to configured grid size value
6277 grid_size_current[i][j] =
6278 getTreeInfoFromIdentifier(grid_sizes[i][j],
6280 setup.touch.grid_xsize[i] :
6281 setup.touch.grid_ysize[i]));
6283 // if that fails, set current grid size to reliable default value
6284 if (grid_size_current[i][j] == NULL)
6285 grid_size_current[i][j] =
6286 getTreeInfoFromIdentifier(grid_sizes[i][j],
6288 DEFAULT_GRID_XSIZE(i) :
6289 DEFAULT_GRID_YSIZE(i)));
6291 // if that also fails, set current grid size to first available value
6292 if (grid_size_current[i][j] == NULL)
6293 grid_size_current[i][j] = grid_sizes[i][j];
6298 setup.touch.control_type = touch_control_current->identifier;
6299 setup.touch.move_distance = atoi(move_distance_current->identifier);
6300 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6301 setup.touch.transparency = atoi(transparency_current->identifier);
6303 for (i = 0; i < 2; i++)
6305 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6306 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6308 if (i == GRID_ACTIVE_NR())
6310 overlay.grid_xsize = setup.touch.grid_xsize[i];
6311 overlay.grid_ysize = setup.touch.grid_ysize[i];
6315 // needed for displaying value text instead of identifier
6316 touch_controls_text = touch_control_current->name;
6317 move_distance_text = move_distance_current->name;
6318 drop_distance_text = drop_distance_current->name;
6319 transparency_text = transparency_current->name;
6321 for (i = 0; i < 2; i++)
6322 for (j = 0; j < 2; j++)
6323 grid_size_text[i][j] = grid_size_current[i][j]->name;
6325 setup_mode = SETUP_MODE_TOUCH;
6330 static void execSetupArtwork(void)
6332 static ArtworkDirTree *gfx_last_valid = NULL;
6333 static ArtworkDirTree *snd_last_valid = NULL;
6334 static ArtworkDirTree *mus_last_valid = NULL;
6336 // current artwork directory may be invalid (level group, parent link)
6337 if (!validLevelSeries(artwork.gfx_current))
6338 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6339 if (!validLevelSeries(artwork.snd_current))
6340 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6341 if (!validLevelSeries(artwork.mus_current))
6342 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6344 // store valid artwork directory information
6345 gfx_last_valid = artwork.gfx_current;
6346 snd_last_valid = artwork.snd_current;
6347 mus_last_valid = artwork.mus_current;
6350 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6351 artwork.gfx_current->subdir,
6352 artwork.gfx_current->fullpath,
6353 artwork.gfx_current->basepath);
6356 setup.graphics_set = artwork.gfx_current->identifier;
6357 setup.sounds_set = artwork.snd_current->identifier;
6358 setup.music_set = artwork.mus_current->identifier;
6360 // needed if last screen (setup choice) changed graphics, sounds or music
6361 ReloadCustomArtwork(0);
6363 // needed for displaying artwork name instead of artwork identifier
6364 graphics_set_name = artwork.gfx_current->name;
6365 sounds_set_name = artwork.snd_current->name;
6366 music_set_name = artwork.mus_current->name;
6368 setup_mode = SETUP_MODE_ARTWORK;
6373 static void execSetupChooseGraphics(void)
6375 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6380 static void execSetupChooseSounds(void)
6382 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6387 static void execSetupChooseMusic(void)
6389 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6394 static void execSetupInput(void)
6396 setup_mode = SETUP_MODE_INPUT;
6401 static void execSetupShortcuts(void)
6403 setup_mode = SETUP_MODE_SHORTCUTS;
6408 static void execSetupShortcuts1(void)
6410 setup_mode = SETUP_MODE_SHORTCUTS_1;
6415 static void execSetupShortcuts2(void)
6417 setup_mode = SETUP_MODE_SHORTCUTS_2;
6422 static void execSetupShortcuts3(void)
6424 setup_mode = SETUP_MODE_SHORTCUTS_3;
6429 static void execSetupShortcuts4(void)
6431 setup_mode = SETUP_MODE_SHORTCUTS_4;
6436 static void execSetupShortcuts5(void)
6438 setup_mode = SETUP_MODE_SHORTCUTS_5;
6443 static void execExitSetup(void)
6445 SetGameStatus(GAME_MODE_MAIN);
6450 static void execSaveAndExitSetup(void)
6456 static void execGadgetNetworkServer(void)
6458 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6459 struct GadgetInfo *gi = screen_gadget[gadget_id];
6461 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6462 network_server_hostname[0] = '\0';
6464 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6468 ClickOnGadget(gi, MB_LEFTBUTTON);
6471 static void ToggleNetworkModeIfNeeded(void)
6473 int font_title = FONT_TITLE_1;
6474 int font_foot = FC_BLUE;
6475 int ystart = mSY - SY + 16;
6476 int ybottom = mSY - SY + SYSIZE - 20;
6477 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6479 if (setup.network_mode == network.enabled)
6482 network.enabled = setup.network_mode;
6484 FadeOut(REDRAW_ALL);
6488 DrawTextSCentered(ystart, font_title, text);
6492 if (network.enabled)
6493 InitNetworkServer();
6495 DisconnectFromNetworkServer();
6497 DrawTextSCentered(ybottom, font_foot,
6498 "Press any key or button for setup menu");
6500 WaitForEventToContinue();
6505 static void ToggleGameSpeedsListIfNeeded(void)
6507 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6509 if (setup.game_speed_extended == using_game_speeds_extended)
6512 // try to match similar values when changing game speeds list
6513 if (setup.game_speed_extended)
6514 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6515 setup.game_frame_delay == 30 ? 29 :
6516 setup.game_frame_delay);
6518 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6519 setup.game_frame_delay == 16 ? 15 :
6520 setup.game_frame_delay >= 29 ? 30 :
6521 setup.game_frame_delay <= 10 ? 10 :
6522 setup.game_frame_delay);
6524 execSetupGame_setGameSpeeds(TRUE);
6529 static void ModifyGameSpeedIfNeeded(void)
6531 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6532 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6536 char *game_speed_text = "Fast";
6537 int game_speed_value = 15;
6539 if (setup.game_speed_extended)
6541 game_speed_text = "60 fps";
6542 game_speed_value = 16;
6545 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6547 // set game speed to existing list value that is fast enough for vsync
6548 setup.game_frame_delay = game_speed_value;
6550 execSetupGame_setGameSpeeds(TRUE);
6552 Request(message, REQ_CONFIRM);
6555 static void DisableVsyncIfNeeded(void)
6557 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6558 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6559 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6562 // disable vsync for the selected game speed to work
6563 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6565 execSetupGraphics_setVsyncModes(TRUE);
6567 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6573 void *related_value;
6574 } hide_related_entry_list[] =
6576 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6577 { &setup.game_frame_delay, &game_speed_text },
6579 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6580 { &setup.scroll_delay_value, &scroll_delay_text },
6582 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6583 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6585 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6586 { &setup.window_scaling_percent, &window_size_text },
6588 { &setup.window_scaling_quality, execSetupChooseScalingType },
6589 { &setup.window_scaling_quality, &scaling_type_text },
6591 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6592 { &setup.screen_rendering_mode, &rendering_mode_text },
6594 { &setup.vsync_mode, execSetupChooseVsyncMode },
6595 { &setup.vsync_mode, &vsync_mode_text },
6597 { &setup.graphics_set, execSetupChooseGraphics },
6598 { &setup.graphics_set, &graphics_set_name },
6600 { &setup.sounds_set, execSetupChooseSounds },
6601 { &setup.sounds_set, &sounds_set_name },
6603 { &setup.music_set, execSetupChooseMusic },
6604 { &setup.music_set, &music_set_name },
6606 { &setup.volume_simple, execSetupChooseVolumeSimple },
6607 { &setup.volume_simple, &volume_simple_text },
6609 { &setup.volume_loops, execSetupChooseVolumeLoops },
6610 { &setup.volume_loops, &volume_loops_text },
6612 { &setup.volume_music, execSetupChooseVolumeMusic },
6613 { &setup.volume_music, &volume_music_text },
6615 { &setup.touch.control_type, execSetupChooseTouchControls },
6616 { &setup.touch.control_type, &touch_controls_text },
6618 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6619 { &setup.touch.move_distance, &move_distance_text },
6621 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6622 { &setup.touch.drop_distance, &drop_distance_text },
6624 { &setup.touch.transparency, execSetupChooseTransparency },
6625 { &setup.touch.transparency, &transparency_text },
6627 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6628 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6630 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6631 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6633 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6634 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6636 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6637 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6639 { &setup.internal.menu_game, execSetupGame },
6640 { &setup.internal.menu_engines, execSetupEngines },
6641 { &setup.internal.menu_editor, execSetupEditor },
6642 { &setup.internal.menu_graphics, execSetupGraphics },
6643 { &setup.internal.menu_sound, execSetupSound },
6644 { &setup.internal.menu_artwork, execSetupArtwork },
6645 { &setup.internal.menu_input, execSetupInput },
6646 { &setup.internal.menu_touch, execSetupTouch },
6647 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6648 { &setup.internal.menu_exit, execExitSetup },
6649 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6654 void setHideRelatedSetupEntries(void)
6658 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6659 if (hideSetupEntry(hide_related_entry_list[i].value))
6660 setHideSetupEntry(hide_related_entry_list[i].related_value);
6663 static struct TokenInfo setup_info_main[] =
6665 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6666 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6667 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6668 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6669 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6670 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6671 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6672 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6673 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6674 { TYPE_EMPTY, NULL, "" },
6675 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6676 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6681 static struct TokenInfo setup_info_game[] =
6683 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6684 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6685 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6686 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6687 { TYPE_STRING, &network_server_text, "" },
6688 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
6689 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6690 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6691 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6692 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6693 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6694 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6695 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
6696 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
6697 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6698 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6699 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6700 { TYPE_STRING, &game_speed_text, "" },
6701 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6703 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6704 { TYPE_STRING, &scroll_delay_text, "" },
6706 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6707 { TYPE_STRING, &snapshot_mode_text, "" },
6708 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6709 { TYPE_EMPTY, NULL, "" },
6710 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6715 static struct TokenInfo setup_info_engines[] =
6717 { TYPE_HEADLINE, NULL, "Emerald Mine" },
6718 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
6719 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
6720 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
6721 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
6722 { TYPE_EMPTY, NULL, "" },
6723 { TYPE_HEADLINE, NULL, "Supaplex" },
6724 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
6725 { TYPE_EMPTY, NULL, "" },
6726 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6731 static struct TokenInfo setup_info_editor[] =
6734 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6735 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6736 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6737 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6738 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6739 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6740 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6741 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6742 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6743 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6745 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6746 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6748 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6750 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6751 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6752 { TYPE_EMPTY, NULL, "" },
6754 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6755 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6756 { TYPE_EMPTY, NULL, "" },
6758 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6759 { TYPE_EMPTY, NULL, "" },
6760 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
6761 { TYPE_EMPTY, NULL, "" },
6762 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6767 static struct TokenInfo setup_info_graphics[] =
6769 #if !defined(PLATFORM_ANDROID)
6770 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6771 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6772 { TYPE_STRING, &window_size_text, "" },
6773 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6774 { TYPE_STRING, &scaling_type_text, "" },
6775 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6776 { TYPE_STRING, &rendering_mode_text, "" },
6779 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6780 { TYPE_STRING, &scroll_delay_text, "" },
6782 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6783 { TYPE_STRING, &vsync_mode_text, "" },
6784 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6785 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6786 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6787 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6788 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6789 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6790 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
6791 { TYPE_EMPTY, NULL, "" },
6792 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6797 static struct TokenInfo setup_info_sound[] =
6799 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6800 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6801 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6802 { TYPE_EMPTY, NULL, "" },
6803 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6804 { TYPE_STRING, &volume_simple_text, "" },
6805 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6806 { TYPE_STRING, &volume_loops_text, "" },
6807 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6808 { TYPE_STRING, &volume_music_text, "" },
6809 { TYPE_EMPTY, NULL, "" },
6810 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6815 static struct TokenInfo setup_info_artwork[] =
6817 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6818 { TYPE_STRING, &graphics_set_name, "" },
6819 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6820 { TYPE_STRING, &sounds_set_name, "" },
6821 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6822 { TYPE_STRING, &music_set_name, "" },
6823 { TYPE_EMPTY, NULL, "" },
6824 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6825 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6826 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6827 { TYPE_EMPTY, NULL, "" },
6828 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6833 static struct TokenInfo setup_info_input[] =
6835 { TYPE_SWITCH, NULL, "Player:" },
6836 { TYPE_SWITCH, NULL, "Device:" },
6837 { TYPE_SWITCH, NULL, "" },
6838 { TYPE_SKIPPABLE, NULL, "" },
6839 { TYPE_EMPTY, NULL, "" },
6840 { TYPE_EMPTY, NULL, "" },
6841 { TYPE_EMPTY, NULL, "" },
6842 { TYPE_EMPTY, NULL, "" },
6843 { TYPE_EMPTY, NULL, "" },
6844 { TYPE_EMPTY, NULL, "" },
6845 { TYPE_EMPTY, NULL, "" },
6846 { TYPE_EMPTY, NULL, "" },
6847 { TYPE_SKIPPABLE, NULL, "" },
6848 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6853 static struct TokenInfo setup_info_touch[] =
6855 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6856 { TYPE_STRING, &touch_controls_text, "" },
6857 { TYPE_EMPTY, NULL, "" },
6858 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6863 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6865 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6866 { TYPE_STRING, &touch_controls_text, "" },
6867 { TYPE_EMPTY, NULL, "" },
6868 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6869 { TYPE_STRING, &grid_size_text[0][0], "" },
6870 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6871 { TYPE_STRING, &grid_size_text[0][1], "" },
6872 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6873 { TYPE_STRING, &transparency_text, "" },
6874 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6875 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6876 { TYPE_EMPTY, NULL, "" },
6877 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6878 { TYPE_EMPTY, NULL, "" },
6879 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6884 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6886 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6887 { TYPE_STRING, &touch_controls_text, "" },
6888 { TYPE_EMPTY, NULL, "" },
6889 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6890 { TYPE_STRING, &grid_size_text[1][0], "" },
6891 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6892 { TYPE_STRING, &grid_size_text[1][1], "" },
6893 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6894 { TYPE_STRING, &transparency_text, "" },
6895 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6896 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6897 { TYPE_EMPTY, NULL, "" },
6898 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6899 { TYPE_EMPTY, NULL, "" },
6900 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6905 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6907 setup_info_touch_virtual_buttons_0,
6908 setup_info_touch_virtual_buttons_1
6911 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6913 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6914 { TYPE_STRING, &touch_controls_text, "" },
6915 { TYPE_EMPTY, NULL, "" },
6916 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6917 { TYPE_STRING, &move_distance_text, "" },
6918 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6919 { TYPE_STRING, &drop_distance_text, "" },
6920 { TYPE_EMPTY, NULL, "" },
6921 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6926 static struct TokenInfo setup_info_shortcuts[] =
6928 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6929 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6930 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6931 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6932 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6933 { TYPE_EMPTY, NULL, "" },
6934 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6939 static struct TokenInfo setup_info_shortcuts_1[] =
6941 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6942 { TYPE_KEY, &setup.shortcut.save_game, "" },
6943 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6944 { TYPE_KEY, &setup.shortcut.load_game, "" },
6945 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6946 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6947 { TYPE_EMPTY, NULL, "" },
6948 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6949 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6950 { TYPE_EMPTY, NULL, "" },
6951 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6956 static struct TokenInfo setup_info_shortcuts_2[] =
6958 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6959 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6960 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6961 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6962 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6963 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6964 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6965 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6966 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6967 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6968 { TYPE_EMPTY, NULL, "" },
6969 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6974 static struct TokenInfo setup_info_shortcuts_3[] =
6976 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6977 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6978 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6979 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6980 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6981 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6982 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6983 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6984 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6985 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6986 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6987 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6988 { TYPE_EMPTY, NULL, "" },
6989 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6994 static struct TokenInfo setup_info_shortcuts_4[] =
6996 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6997 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6998 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6999 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7000 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7001 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7002 { TYPE_EMPTY, NULL, "" },
7003 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7008 static struct TokenInfo setup_info_shortcuts_5[] =
7010 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7011 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7012 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7013 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7014 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7015 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7016 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7017 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7018 { TYPE_EMPTY, NULL, "" },
7019 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7024 static Key getSetupKey(void)
7026 Key key = KSYM_UNDEFINED;
7027 boolean got_key_event = FALSE;
7029 while (!got_key_event)
7033 if (NextValidEvent(&event))
7037 case EVENT_KEYPRESS:
7039 key = GetEventKey((KeyEvent *)&event, TRUE);
7041 // press 'Escape' or 'Enter' to keep the existing key binding
7042 if (key == KSYM_Escape || key == KSYM_Return)
7043 key = KSYM_UNDEFINED; // keep old value
7045 got_key_event = TRUE;
7049 case EVENT_KEYRELEASE:
7050 key_joystick_mapping = 0;
7054 HandleOtherEvents(&event);
7065 static int getSetupValueFont(int type, void *value)
7067 if (type & TYPE_GHOSTED)
7068 return FONT_OPTION_OFF;
7069 else if (type & TYPE_KEY)
7070 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7071 else if (type & TYPE_STRING)
7072 return FONT_VALUE_2;
7073 else if (type & TYPE_ECS_AGA)
7074 return FONT_VALUE_1;
7075 else if (type & TYPE_BOOLEAN_STYLE)
7076 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7077 else if (type & TYPE_YES_NO_AUTO)
7078 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7079 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7080 else if (type & TYPE_PLAYER)
7081 return FONT_VALUE_1;
7083 return FONT_VALUE_1;
7086 static int getSetupValueFontNarrow(int type, int font_nr)
7088 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7089 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7090 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7094 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7096 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7097 struct TokenInfo *si = &setup_info[si_pos];
7098 boolean font_draw_xoffset_modified = FALSE;
7099 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7100 int font_draw_xoffset_old = -1;
7101 int xoffset = (scrollbar_needed ? -1 : 0);
7102 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7103 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7104 int xpos = menu_screen_value_xpos;
7105 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7106 int startx = mSX + xpos * 32;
7107 int starty = mSY + ypos * 32;
7108 int type = si->type;
7109 void *value = si->value;
7110 char *value_string = getSetupValue(type, value);
7111 int font_nr_default = getSetupValueFont(type, value);
7112 int font_width_default = getFontWidth(font_nr_default);
7113 int font_nr = font_nr_default;
7116 if (value_string == NULL)
7119 if (type & TYPE_KEY)
7121 xpos = MENU_SCREEN_START_XPOS;
7123 if (type & TYPE_QUERY)
7124 value_string = "<press key>";
7126 else if (type & TYPE_STRING)
7128 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7130 xpos = MENU_SCREEN_START_XPOS;
7132 if (strlen(value_string) > max_value_len)
7133 value_string[max_value_len] = '\0';
7135 else if (type & TYPE_YES_NO_AUTO)
7137 xpos = menu_screen_value_xpos - 1;
7139 else if (type & TYPE_PLAYER)
7141 int displayed_player_nr = *(int *)value + 1;
7143 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7146 startx = mSX + xpos * 32;
7147 starty = mSY + ypos * 32;
7149 // special check if right-side setup values moved left due to scrollbar
7150 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7152 int max_menu_text_length = 26; // maximum text length for classic menu
7153 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7154 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7155 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7156 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7157 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7159 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7161 // when using narrow font, left-shifting text "auto" not needed
7162 if (type & TYPE_YES_NO_AUTO)
7166 startx = mSX + xpos * 32;
7168 font_nr = getSetupValueFontNarrow(type, font_nr);
7172 // downward compatibility correction for Juergen Bonhagen's menu settings
7173 if (setup_mode != SETUP_MODE_INPUT)
7175 int max_menu_text_length_big = (menu_screen_value_xpos -
7176 MENU_SCREEN_START_XPOS);
7177 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7178 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7179 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7180 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
7181 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7182 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7183 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7184 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7185 boolean correct_font_draw_xoffset = FALSE;
7187 if (xpos == MENU_SCREEN_START_XPOS &&
7188 startx + font1_xoffset < text_startx + text_font_xoffset)
7189 correct_font_draw_xoffset = TRUE;
7191 if (xpos == menu_screen_value_xpos &&
7192 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7193 correct_font_draw_xoffset = TRUE;
7195 // check if setup value would overlap with setup text when printed
7196 // (this can happen for extreme/wrong values for font draw offset)
7197 if (correct_font_draw_xoffset)
7199 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
7200 font_draw_xoffset_modified = TRUE;
7202 if (type & TYPE_KEY)
7203 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7204 else if (!(type & TYPE_STRING))
7205 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7206 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7210 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7211 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7213 DrawText(startx, starty, value_string, font_nr);
7215 if (type & TYPE_PLAYER)
7217 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7218 int player_nr = *(int *)value;
7219 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7220 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7221 int startx2 = startx + xoff;
7222 int starty2 = starty + yoff;
7224 if (DrawingOnBackground(startx2, starty2))
7225 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7227 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7228 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7231 if (font_draw_xoffset_modified)
7232 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7235 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7237 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7238 struct TokenInfo *si = &setup_info[si_pos];
7240 if (si->type & TYPE_BOOLEAN_STYLE)
7242 *(boolean *)si->value ^= TRUE;
7244 else if (si->type & TYPE_YES_NO_AUTO)
7248 (*(int *)si->value == AUTO ? TRUE :
7249 *(int *)si->value == TRUE ? FALSE : AUTO) :
7250 (*(int *)si->value == TRUE ? AUTO :
7251 *(int *)si->value == AUTO ? FALSE : TRUE));
7253 else if (si->type & TYPE_KEY)
7257 si->type |= TYPE_QUERY;
7258 drawSetupValue(screen_pos, setup_info_pos_raw);
7259 si->type &= ~TYPE_QUERY;
7261 key = getSetupKey();
7262 if (key != KSYM_UNDEFINED)
7263 *(Key *)si->value = key;
7265 else if (si->type & TYPE_PLAYER)
7267 int player_nr = *(int *)si->value;
7272 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7274 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7277 drawSetupValue(screen_pos, setup_info_pos_raw);
7279 // fullscreen state may have changed at this point
7280 if (si->value == &setup.fullscreen)
7281 ToggleFullscreenIfNeeded();
7283 // network mode may have changed at this point
7284 if (si->value == &setup.network_mode)
7285 ToggleNetworkModeIfNeeded();
7287 // game speed list may have changed at this point
7288 if (si->value == &setup.game_speed_extended)
7289 ToggleGameSpeedsListIfNeeded();
7292 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7294 static struct TokenInfo *setup_info_final = NULL;
7299 // determine maximum list size of target list
7300 while (setup_info_orig[list_size++].type != 0);
7302 // free, allocate and clear memory for target list
7303 checked_free(setup_info_final);
7304 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7306 // copy setup info list without setup entries marked as hidden
7307 for (i = 0; setup_info_orig[i].type != 0; i++)
7309 // skip setup entries configured to be hidden
7310 if (hideSetupEntry(setup_info_orig[i].value))
7313 // skip skippable setup entries if screen is lower than usual
7314 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7315 setup_info_orig[i].type == TYPE_SKIPPABLE)
7318 setup_info_final[list_pos++] = setup_info_orig[i];
7321 return setup_info_final;
7324 static void DrawSetupScreen_Generic(void)
7326 int fade_mask = REDRAW_FIELD;
7327 boolean redraw_all = FALSE;
7328 char *title_string = NULL;
7332 fade_mask = REDRAW_ALL;
7335 FadeMenuSoundsAndMusic();
7337 FreeScreenGadgets();
7338 CreateScreenGadgets();
7340 if (redraw_mask & REDRAW_ALL)
7345 // needed if different viewport properties defined for setup screen
7346 ChangeViewportPropertiesIfNeeded();
7348 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7352 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7354 if (setup_mode == SETUP_MODE_MAIN)
7356 setup_info = setup_info_main;
7357 title_string = STR_SETUP_MAIN;
7359 else if (setup_mode == SETUP_MODE_GAME)
7361 setup_info = setup_info_game;
7362 title_string = STR_SETUP_GAME;
7364 else if (setup_mode == SETUP_MODE_ENGINES)
7366 setup_info = setup_info_engines;
7367 title_string = STR_SETUP_ENGINES;
7369 else if (setup_mode == SETUP_MODE_EDITOR)
7371 setup_info = setup_info_editor;
7372 title_string = STR_SETUP_EDITOR;
7374 else if (setup_mode == SETUP_MODE_GRAPHICS)
7376 setup_info = setup_info_graphics;
7377 title_string = STR_SETUP_GRAPHICS;
7379 else if (setup_mode == SETUP_MODE_SOUND)
7381 setup_info = setup_info_sound;
7382 title_string = STR_SETUP_SOUND;
7384 else if (setup_mode == SETUP_MODE_ARTWORK)
7386 setup_info = setup_info_artwork;
7387 title_string = STR_SETUP_ARTWORK;
7389 else if (setup_mode == SETUP_MODE_TOUCH)
7391 setup_info = setup_info_touch;
7392 title_string = STR_SETUP_TOUCH;
7394 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7395 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7396 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7397 setup_info = setup_info_touch_wipe_gestures;
7399 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7401 setup_info = setup_info_shortcuts;
7402 title_string = STR_SETUP_SHORTCUTS;
7404 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7406 setup_info = setup_info_shortcuts_1;
7407 title_string = STR_SETUP_SHORTCUTS;
7409 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7411 setup_info = setup_info_shortcuts_2;
7412 title_string = STR_SETUP_SHORTCUTS;
7414 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7416 setup_info = setup_info_shortcuts_3;
7417 title_string = STR_SETUP_SHORTCUTS;
7419 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7421 setup_info = setup_info_shortcuts_4;
7422 title_string = STR_SETUP_SHORTCUTS;
7424 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7426 setup_info = setup_info_shortcuts_5;
7427 title_string = STR_SETUP_SHORTCUTS;
7430 // use modified setup info without setup entries marked as hidden
7431 setup_info = getSetupInfoFinal(setup_info);
7433 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7435 // determine maximal number of setup entries that can be displayed on screen
7437 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7440 // determine maximal number of setup entries available for this setup screen
7442 for (i = 0; setup_info[i].type != 0; i++)
7445 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7447 MapScreenGadgets(max_setup_info);
7450 redraw_mask = fade_mask = REDRAW_ALL;
7452 DrawMaskedBorder(fade_mask);
7457 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7459 menu_info = setup_info;
7461 HandleMenuScreen(mx, my, dx, dy, button,
7462 setup_mode, num_setup_info, max_setup_info);
7465 static void DrawSetupScreen_Input(void)
7469 FadeOut(REDRAW_FIELD);
7473 setup_info = getSetupInfoFinal(setup_info_input);
7475 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7477 for (i = 0; setup_info[i].type != 0; i++)
7479 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7480 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7481 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7482 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7483 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7484 initCursor(i, IMG_MENU_BUTTON);
7486 DrawCursorAndText_Setup(i, -1, FALSE);
7489 // create gadgets for setup input menu screen
7490 FreeScreenGadgets();
7491 CreateScreenGadgets();
7493 // map gadgets for setup input menu screen
7494 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7496 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7498 FadeIn(REDRAW_FIELD);
7501 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7503 if (device_name == NULL)
7506 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7509 if (strlen(device_name) > 1)
7511 char c1 = device_name[strlen(device_name) - 1];
7512 char c2 = device_name[strlen(device_name) - 2];
7514 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7515 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7518 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7519 strlen(device_name));
7522 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7525 static struct SetupKeyboardInfo custom_key;
7532 { &custom_key.left, "Axis/Pad Left" },
7533 { &custom_key.right, "Axis/Pad Right" },
7534 { &custom_key.up, "Axis/Pad Up" },
7535 { &custom_key.down, "Axis/Pad Down" },
7536 { &custom_key.snap, "Button 1/A/X" },
7537 { &custom_key.drop, "Button 2/B/Y" }
7539 static char *joystick_name[MAX_PLAYERS] =
7546 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7547 int font_nr_info = FONT_MENU_1;
7548 int font_nr_name = FONT_VALUE_OLD;
7549 int font_nr_on = FONT_VALUE_1;
7550 int font_nr_off = FONT_VALUE_OLD;
7553 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7555 font_nr_info = FONT_MENU_2;
7556 font_nr_on = FONT_VALUE_NARROW;
7557 font_nr_off = FONT_VALUE_OLD_NARROW;
7560 custom_key = setup.input[player_nr].key;
7562 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7563 FONT_INPUT_1_ACTIVE);
7565 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7567 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7568 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7570 if (setup.input[player_nr].use_joystick)
7572 char *device_name = setup.input[player_nr].joy.device_name;
7573 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7574 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7575 char *text = joystick_name[joystick_nr];
7576 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7578 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7579 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7583 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7584 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7587 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7588 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7592 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7593 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7594 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7595 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7597 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7598 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7599 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7600 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7601 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7602 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7604 for (i = 0; i < 6; i++)
7606 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7608 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7610 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7611 (setup.input[player_nr].use_joystick ?
7613 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7617 static int input_player_nr = 0;
7619 static void HandleSetupScreen_Input_Player(int step, int direction)
7621 int old_player_nr = input_player_nr;
7624 new_player_nr = old_player_nr + step * direction;
7625 if (new_player_nr < 0)
7627 if (new_player_nr > MAX_PLAYERS - 1)
7628 new_player_nr = MAX_PLAYERS - 1;
7630 if (new_player_nr != old_player_nr)
7632 input_player_nr = new_player_nr;
7634 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7638 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7640 static int choice = 0;
7643 int pos_start = SETUPINPUT_SCREEN_POS_START;
7644 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7645 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7646 int pos_end = SETUPINPUT_SCREEN_POS_END;
7648 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7652 for (i = 0; setup_info_input[i].type != 0; i++)
7654 // adjust menu structure according to skipped setup entries
7655 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7663 if (button == MB_MENU_INITIALIZE)
7665 // input setup menu may have changed size due to graphics configuration
7666 if (choice >= pos_empty1)
7669 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7671 DrawCursorAndText_Setup(choice, -1, TRUE);
7675 else if (button == MB_MENU_LEAVE)
7677 setup_mode = SETUP_MODE_MAIN;
7684 if (mx || my) // mouse input
7686 x = (mx - mSX) / 32;
7687 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7689 else if (dx || dy) // keyboard input
7691 if (dx && choice == 0)
7692 x = (dx < 0 ? 10 : 12);
7693 else if ((dx && choice == 1) ||
7694 (dx == -1 && choice == pos_end))
7695 button = MB_MENU_CHOICE;
7699 if (y >= pos_empty1 && y <= pos_empty2)
7700 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7703 if (y == 0 && dx != 0 && button)
7705 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7707 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7708 y >= pos_start && y <= pos_end &&
7709 !(y >= pos_empty1 && y <= pos_empty2))
7715 DrawCursorAndText_Setup(choice, -1, FALSE);
7716 DrawCursorAndText_Setup(y, -1, TRUE);
7718 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7727 char *device_name = setup.input[input_player_nr].joy.device_name;
7729 if (!setup.input[input_player_nr].use_joystick)
7731 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7733 setJoystickDeviceToNr(device_name, new_device_nr);
7734 setup.input[input_player_nr].use_joystick = TRUE;
7738 int device_nr = getJoystickNrFromDeviceName(device_name);
7739 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7741 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7742 setup.input[input_player_nr].use_joystick = FALSE;
7744 setJoystickDeviceToNr(device_name, new_device_nr);
7747 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7751 if (setup.input[input_player_nr].use_joystick)
7752 ConfigureJoystick(input_player_nr);
7754 CustomizeKeyboard(input_player_nr);
7756 else if (y == pos_end)
7762 setup_mode = SETUP_MODE_MAIN;
7769 static boolean CustomizeKeyboardMain(int player_nr)
7773 boolean finished = FALSE;
7774 static struct SetupKeyboardInfo custom_key;
7779 } customize_step[] =
7781 { &custom_key.left, "Move Left" },
7782 { &custom_key.right, "Move Right" },
7783 { &custom_key.up, "Move Up" },
7784 { &custom_key.down, "Move Down" },
7785 { &custom_key.snap, "Snap Field" },
7786 { &custom_key.drop, "Drop Element" }
7788 int font_nr_old = FONT_VALUE_OLD;
7789 int font_nr_new = FONT_VALUE_1;
7790 boolean success = FALSE;
7792 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7794 font_nr_old = FONT_VALUE_OLD_NARROW;
7795 font_nr_new = FONT_VALUE_NARROW;
7798 // read existing key bindings from player setup
7799 custom_key = setup.input[player_nr].key;
7802 FadeOut(REDRAW_FIELD);
7806 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7809 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7810 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7811 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7812 "Key:", FONT_INPUT_1_ACTIVE);
7813 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7814 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7816 FadeIn(REDRAW_FIELD);
7822 if (NextValidEvent(&event))
7826 case EVENT_KEYPRESS:
7828 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7830 // press 'Escape' to abort and keep the old key bindings
7831 if (key == KSYM_Escape)
7833 FadeSkipNextFadeIn();
7840 // press 'Enter' to keep the existing key binding
7841 if (key == KSYM_Return)
7842 key = *customize_step[step_nr].key;
7844 // check if key already used
7845 for (i = 0; i < step_nr; i++)
7846 if (*customize_step[i].key == key)
7851 // got new key binding
7852 *customize_step[step_nr].key = key;
7853 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7855 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7856 getKeyNameFromKey(key), font_nr_new);
7859 // un-highlight last query
7860 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7861 customize_step[step_nr - 1].text, FONT_MENU_1);
7862 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7863 "Key:", FONT_MENU_1);
7865 // all keys configured
7874 // query next key binding
7875 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7876 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7877 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7878 "Key:", FONT_INPUT_1_ACTIVE);
7879 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7880 getKeyNameFromKey(*customize_step[step_nr].key),
7885 case EVENT_KEYRELEASE:
7886 key_joystick_mapping = 0;
7890 HandleOtherEvents(&event);
7898 // write new key bindings back to player setup, if successfully finished
7900 setup.input[player_nr].key = custom_key;
7905 void CustomizeKeyboard(int player_nr)
7907 boolean success = CustomizeKeyboardMain(player_nr);
7911 int font_nr = FONT_TITLE_1;
7912 int font_height = getFontHeight(font_nr);
7913 int ypos1 = SYSIZE / 2 - font_height * 2;
7914 int ypos2 = SYSIZE / 2 - font_height * 1;
7915 unsigned int wait_frame_delay = 0;
7916 unsigned int wait_frame_delay_value = 2000;
7918 ResetDelayCounter(&wait_frame_delay);
7922 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7923 DrawTextSCentered(ypos2, font_nr, "configured!");
7925 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7931 DrawSetupScreen_Input();
7934 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
7936 #define MARKER_BUTTON 1
7937 #define MARKER_AXIS_X 2
7938 #define MARKER_AXIS_Y 3
7940 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7942 static boolean bitmaps_initialized = FALSE;
7943 boolean screen_initialized = FALSE;
7944 static Bitmap *controller, *button, *axis_x, *axis_y;
7946 boolean success = TRUE;
7947 boolean done = FALSE, next = FALSE;
7949 int alpha = 200, alpha_step = -1;
7950 int alpha_ticks = 0;
7951 char mapping[4096], temp[256];
7952 int font_name = MENU_SETUP_FONT_TITLE;
7953 int font_info = MENU_SETUP_FONT_TEXT;
7954 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7955 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7956 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7957 int ystep_name = getMenuTextStep(spacing_name, font_name);
7958 int ystep_line = getMenuTextStep(spacing_line, font_info);
7959 int ystep_para = getMenuTextStep(spacing_para, font_info);
7967 int axis, button, hat, hat_value;
7970 *step, *prev_step, steps[] =
7972 { 356, 155, MARKER_BUTTON, "a", },
7973 { 396, 122, MARKER_BUTTON, "b", },
7974 { 320, 125, MARKER_BUTTON, "x", },
7975 { 358, 95, MARKER_BUTTON, "y", },
7976 { 162, 125, MARKER_BUTTON, "back", },
7977 { 216, 125, MARKER_BUTTON, "guide", },
7978 { 271, 125, MARKER_BUTTON, "start", },
7979 { 110, 200, MARKER_BUTTON, "dpleft", },
7980 { 146, 228, MARKER_BUTTON, "dpdown", },
7981 { 178, 200, MARKER_BUTTON, "dpright", },
7982 { 146, 172, MARKER_BUTTON, "dpup", },
7983 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7984 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7985 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7986 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7987 { 73, 141, MARKER_BUTTON, "leftstick", },
7988 { 282, 210, MARKER_BUTTON, "rightstick", },
7989 { 73, 141, MARKER_AXIS_X, "leftx", },
7990 { 73, 141, MARKER_AXIS_Y, "lefty", },
7991 { 282, 210, MARKER_AXIS_X, "rightx", },
7992 { 282, 210, MARKER_AXIS_Y, "righty", },
7995 unsigned int event_frame_delay = 0;
7996 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7998 ResetDelayCounter(&event_frame_delay);
8000 if (!bitmaps_initialized)
8002 controller = LoadCustomImage("joystick/controller.png");
8003 button = LoadCustomImage("joystick/button.png");
8004 axis_x = LoadCustomImage("joystick/axis_x.png");
8005 axis_y = LoadCustomImage("joystick/axis_y.png");
8007 bitmaps_initialized = TRUE;
8010 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8013 // print info about the joystick we are watching
8014 Debug("joystick", "watching joystick %d: (%s)",
8015 SDL_JoystickInstanceID(joystick), name);
8016 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8017 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8018 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8021 // initialize mapping with GUID and name
8022 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8024 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8025 temp, name, SDL_GetPlatform());
8027 // loop through all steps (buttons and axes), getting joystick events
8028 for (i = 0; i < SDL_arraysize(steps) && !done;)
8030 Bitmap *marker = button; // initialize with reliable default value
8033 strcpy(step->mapping, mapping);
8037 step->hat_value = -1;
8039 marker = (step->marker == MARKER_BUTTON ? button :
8040 step->marker == MARKER_AXIS_X ? axis_x :
8041 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8045 while (!done && !next)
8047 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8048 alpha_ticks = SDL_GetTicks();
8055 else if (alpha < 128)
8061 int controller_x = SX + (SXSIZE - controller->width) / 2;
8062 int controller_y = SY + ystep_line;
8064 int marker_x = controller_x + step->x;
8065 int marker_y = controller_y + step->y;
8067 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8068 int ystart2 = ystart1 + ystep_name + ystep_line;
8072 DrawTextSCentered(ystart1, font_name, name);
8074 DrawTextSCentered(ystart2, font_info,
8075 "Press buttons and move axes on");
8076 ystart2 += ystep_line;
8077 DrawTextSCentered(ystart2, font_info,
8078 "your controller when indicated.");
8079 ystart2 += ystep_line;
8080 DrawTextSCentered(ystart2, font_info,
8081 "(Your controller may look different.)");
8082 ystart2 += ystep_para;
8084 #if defined(PLATFORM_ANDROID)
8085 DrawTextSCentered(ystart2, font_info,
8086 "To correct a mistake,");
8087 ystart2 += ystep_line;
8088 DrawTextSCentered(ystart2, font_info,
8089 "press the 'back' button.");
8090 ystart2 += ystep_line;
8091 DrawTextSCentered(ystart2, font_info,
8092 "To skip a button or axis,");
8093 ystart2 += ystep_line;
8094 DrawTextSCentered(ystart2, font_info,
8095 "press the 'menu' button.");
8097 DrawTextSCentered(ystart2, font_info,
8098 "To correct a mistake,");
8099 ystart2 += ystep_line;
8100 DrawTextSCentered(ystart2, font_info,
8101 "press the 'backspace' key.");
8102 ystart2 += ystep_line;
8103 DrawTextSCentered(ystart2, font_info,
8104 "To skip a button or axis,");
8105 ystart2 += ystep_line;
8106 DrawTextSCentered(ystart2, font_info,
8107 "press the 'return' key.");
8108 ystart2 += ystep_line;
8109 DrawTextSCentered(ystart2, font_info,
8110 "To exit, press the 'escape' key.");
8113 BlitBitmapMasked(controller, drawto, 0, 0,
8114 controller->width, controller->height,
8115 controller_x, controller_y);
8117 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8118 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8120 BlitBitmapMasked(marker, drawto, 0, 0,
8121 marker->width, marker->height,
8122 marker_x, marker_y);
8124 if (!screen_initialized)
8125 FadeIn(REDRAW_FIELD);
8129 screen_initialized = TRUE;
8131 while (NextValidEvent(&event))
8135 case SDL_JOYAXISMOTION:
8136 if (event.jaxis.value > 20000 ||
8137 event.jaxis.value < -20000)
8139 for (j = 0; j < i; j++)
8140 if (steps[j].axis == event.jaxis.axis)
8145 if (step->marker != MARKER_AXIS_X &&
8146 step->marker != MARKER_AXIS_Y)
8149 step->axis = event.jaxis.axis;
8150 strcat(mapping, step->field);
8151 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8152 strcat(mapping, temp);
8160 case SDL_JOYHATMOTION:
8161 // ignore centering; we're probably just coming back
8162 // to the center from the previous item we set
8163 if (event.jhat.value == SDL_HAT_CENTERED)
8166 for (j = 0; j < i; j++)
8167 if (steps[j].hat == event.jhat.hat &&
8168 steps[j].hat_value == event.jhat.value)
8173 step->hat = event.jhat.hat;
8174 step->hat_value = event.jhat.value;
8175 strcat(mapping, step->field);
8176 snprintf(temp, sizeof(temp), ":h%u.%u,",
8177 event.jhat.hat, event.jhat.value );
8178 strcat(mapping, temp);
8185 case SDL_JOYBALLMOTION:
8188 case SDL_JOYBUTTONUP:
8189 for (j = 0; j < i; j++)
8190 if (steps[j].button == event.jbutton.button)
8195 step->button = event.jbutton.button;
8196 strcat(mapping, step->field);
8197 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8198 strcat(mapping, temp);
8205 case SDL_FINGERDOWN:
8206 case SDL_MOUSEBUTTONDOWN:
8214 if (event.key.keysym.sym == KSYM_BackSpace ||
8215 event.key.keysym.sym == KSYM_Back)
8227 prev_step = &steps[i - 1];
8228 strcpy(mapping, prev_step->mapping);
8235 if (event.key.keysym.sym == KSYM_space ||
8236 event.key.keysym.sym == KSYM_Return ||
8237 event.key.keysym.sym == KSYM_Menu)
8246 if (event.key.keysym.sym == KSYM_Escape)
8256 program.exit_function(0);
8263 // do not handle events for longer than standard frame delay period
8264 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8273 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8276 // activate mapping for this game
8277 SDL_GameControllerAddMapping(mapping);
8279 // save mapping to personal mappings
8280 SaveSetup_AddGameControllerMapping(mapping);
8283 // wait until the last pending event was removed from event queue
8284 while (NextValidEvent(&event));
8289 static int ConfigureJoystickMain(int player_nr)
8291 char *device_name = setup.input[player_nr].joy.device_name;
8292 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8293 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8294 int success = FALSE;
8297 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8298 return JOYSTICK_NOT_AVAILABLE;
8300 if (!joystick_active || !setup.input[player_nr].use_joystick)
8301 return JOYSTICK_NOT_AVAILABLE;
8304 FadeOut(REDRAW_FIELD);
8306 // close all joystick devices (potentially opened as game controllers)
8307 for (i = 0; i < SDL_NumJoysticks(); i++)
8308 SDLCloseJoystick(i);
8310 // open joystick device as plain joystick to configure as game controller
8311 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8313 // as the joystick was successfully opened before, this should not happen
8314 if (joystick == NULL)
8317 // create new game controller mapping (buttons and axes) for joystick device
8318 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8320 // close joystick (and maybe re-open as configured game controller later)
8321 SDL_JoystickClose(joystick);
8323 // re-open all joystick devices (potentially as game controllers)
8324 for (i = 0; i < SDL_NumJoysticks(); i++)
8327 // clear all joystick input actions for all joystick devices
8328 SDLClearJoystickState();
8330 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8333 void ConfigureJoystick(int player_nr)
8335 boolean state = ConfigureJoystickMain(player_nr);
8337 if (state != JOYSTICK_NOT_CONFIGURED)
8339 boolean success = (state == JOYSTICK_CONFIGURED);
8340 char message1[MAX_OUTPUT_LINESIZE + 1];
8341 char *message2 = (success ? "configured!" : "not available!");
8342 char *device_name = setup.input[player_nr].joy.device_name;
8343 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8344 int font_nr = FONT_TITLE_1;
8345 int font_height = getFontHeight(font_nr);
8346 int ypos1 = SYSIZE / 2 - font_height * 2;
8347 int ypos2 = SYSIZE / 2 - font_height * 1;
8348 unsigned int wait_frame_delay = 0;
8349 unsigned int wait_frame_delay_value = 2000;
8351 ResetDelayCounter(&wait_frame_delay);
8355 sprintf(message1, "Joystick %d", nr);
8357 DrawTextSCentered(ypos1, font_nr, message1);
8358 DrawTextSCentered(ypos2, font_nr, message2);
8360 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8366 DrawSetupScreen_Input();
8369 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8371 if (y < video.screen_height / 3)
8373 // remap touch gadgets to access upper part of the screen
8374 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8375 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8377 else if (y > 2 * video.screen_height / 3)
8379 // remap touch gadgets to access lower part of the screen
8380 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8381 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8385 static boolean ConfigureVirtualButtonsMain(void)
8387 static char *customize_step_text[] =
8396 char grid_button[] =
8398 CHAR_GRID_BUTTON_LEFT,
8399 CHAR_GRID_BUTTON_RIGHT,
8400 CHAR_GRID_BUTTON_UP,
8401 CHAR_GRID_BUTTON_DOWN,
8402 CHAR_GRID_BUTTON_SNAP,
8403 CHAR_GRID_BUTTON_DROP
8412 int font_nr = FONT_INPUT_1_ACTIVE;
8413 int font_height = getFontHeight(font_nr);
8414 int ypos1 = SYSIZE / 2 - font_height * 2;
8415 int ypos2 = SYSIZE / 2 - font_height * 1;
8416 boolean success = FALSE;
8417 boolean finished = FALSE;
8419 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8420 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8421 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8422 boolean set_grid_button = FALSE;
8423 int nr = GRID_ACTIVE_NR();
8426 for (x = 0; x < MAX_GRID_XSIZE; x++)
8427 for (y = 0; y < MAX_GRID_YSIZE; y++)
8428 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8430 overlay.grid_button_highlight = grid_button[step_nr];
8435 FadeOut(REDRAW_FIELD);
8439 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8440 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8441 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8443 FadeIn(REDRAW_FIELD);
8445 SetOverlayShowGrid(TRUE);
8447 // map gadgets for setup touch buttons menu screen
8448 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8454 while (NextValidEvent(&event))
8456 int action = ACTION_NONE;
8458 // ---------- handle events and set the resulting action ----------
8464 UserEvent *user = (UserEvent *)&event;
8465 int id = user->value1;
8467 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8468 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8469 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8470 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8475 case EVENT_KEYPRESS:
8477 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8479 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8480 key == KSYM_BackSpace ||
8481 key == KSYM_Back ? ACTION_BACK :
8482 key == KSYM_Return ||
8484 key == KSYM_space ? ACTION_NEXT :
8489 case EVENT_KEYRELEASE:
8490 key_joystick_mapping = 0;
8493 case EVENT_BUTTONPRESS:
8494 case EVENT_BUTTONRELEASE:
8496 ButtonEvent *button = (ButtonEvent *)&event;
8498 motion_status = FALSE;
8500 if (button->type == EVENT_BUTTONPRESS)
8501 button_status = button->button;
8503 button_status = MB_RELEASED;
8505 if (HandleGadgets(button->x, button->y, button_status))
8507 // do not handle this button event anymore
8511 button->x += video.screen_xoffset;
8512 button->y += video.screen_yoffset;
8514 x = button->x * overlay.grid_xsize / video.screen_width;
8515 y = button->y * overlay.grid_ysize / video.screen_height;
8517 if (button->type == EVENT_BUTTONPRESS)
8520 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8521 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8523 set_grid_button = TRUE;
8526 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8530 case EVENT_MOTIONNOTIFY:
8532 MotionEvent *motion = (MotionEvent *)&event;
8534 motion_status = TRUE;
8536 if (HandleGadgets(motion->x, motion->y, button_status))
8538 // do not handle this button event anymore
8542 motion->x += video.screen_xoffset;
8543 motion->y += video.screen_yoffset;
8545 x = motion->x * overlay.grid_xsize / video.screen_width;
8546 y = motion->y * overlay.grid_ysize / video.screen_height;
8548 set_grid_button = TRUE;
8550 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8554 case SDL_WINDOWEVENT:
8555 HandleWindowEvent((WindowEvent *) &event);
8557 // check if device has been rotated
8558 if (nr != GRID_ACTIVE_NR())
8560 nr = GRID_ACTIVE_NR();
8562 for (x = 0; x < MAX_GRID_XSIZE; x++)
8563 for (y = 0; y < MAX_GRID_YSIZE; y++)
8564 grid_button_old[x][y] = grid_button_tmp[x][y] =
8565 overlay.grid_button[x][y];
8570 case SDL_APP_WILLENTERBACKGROUND:
8571 case SDL_APP_DIDENTERBACKGROUND:
8572 case SDL_APP_WILLENTERFOREGROUND:
8573 case SDL_APP_DIDENTERFOREGROUND:
8574 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8578 HandleOtherEvents(&event);
8582 // ---------- perform action set by handling events ----------
8584 if (action == ACTION_ESCAPE)
8586 // abort and restore the old key bindings
8588 for (x = 0; x < MAX_GRID_XSIZE; x++)
8589 for (y = 0; y < MAX_GRID_YSIZE; y++)
8590 overlay.grid_button[x][y] = grid_button_old[x][y];
8592 FadeSkipNextFadeIn();
8596 else if (action == ACTION_BACK)
8598 // keep the configured key bindings and go to previous page
8604 FadeSkipNextFadeIn();
8609 else if (action == ACTION_NEXT)
8611 // keep the configured key bindings and go to next page
8615 // all virtual buttons configured
8623 if (action != ACTION_NONE && !finished)
8625 for (x = 0; x < MAX_GRID_XSIZE; x++)
8626 for (y = 0; y < MAX_GRID_YSIZE; y++)
8627 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8629 overlay.grid_button_highlight = grid_button[step_nr];
8631 // configure next virtual button
8635 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8636 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8637 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8640 if (set_grid_button)
8642 overlay.grid_button[x][y] =
8643 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8644 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8645 grid_button_tmp[x][y]);
8647 set_grid_button = FALSE;
8654 for (x = 0; x < MAX_GRID_XSIZE; x++)
8655 for (y = 0; y < MAX_GRID_YSIZE; y++)
8656 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8658 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8660 SetOverlayShowGrid(FALSE);
8665 void ConfigureVirtualButtons(void)
8667 boolean success = ConfigureVirtualButtonsMain();
8669 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8670 SCREEN_MASK_TOUCH2);
8674 int font_nr = FONT_TITLE_1;
8675 int font_height = getFontHeight(font_nr);
8676 int ypos1 = SYSIZE / 2 - font_height * 2;
8677 int ypos2 = SYSIZE / 2 - font_height * 1;
8678 unsigned int wait_frame_delay = 0;
8679 unsigned int wait_frame_delay_value = 2000;
8681 ResetDelayCounter(&wait_frame_delay);
8685 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8686 DrawTextSCentered(ypos2, font_nr, "configured!");
8688 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8695 void DrawSetupScreen(void)
8700 if (setup_mode == SETUP_MODE_INPUT)
8701 DrawSetupScreen_Input();
8702 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8703 DrawChooseTree(&game_speed_current);
8704 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8705 DrawChooseTree(&scroll_delay_current);
8706 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8707 DrawChooseTree(&snapshot_mode_current);
8708 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8709 DrawChooseTree(&window_size_current);
8710 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8711 DrawChooseTree(&scaling_type_current);
8712 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8713 DrawChooseTree(&rendering_mode_current);
8714 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8715 DrawChooseTree(&vsync_mode_current);
8716 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8717 DrawChooseTree(&artwork.gfx_current);
8718 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8719 DrawChooseTree(&artwork.snd_current);
8720 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8721 DrawChooseTree(&artwork.mus_current);
8722 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8723 DrawChooseTree(&volume_simple_current);
8724 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8725 DrawChooseTree(&volume_loops_current);
8726 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8727 DrawChooseTree(&volume_music_current);
8728 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8729 DrawChooseTree(&touch_control_current);
8730 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8731 DrawChooseTree(&move_distance_current);
8732 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8733 DrawChooseTree(&drop_distance_current);
8734 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8735 DrawChooseTree(&transparency_current);
8736 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8737 DrawChooseTree(&grid_size_current[0][0]);
8738 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8739 DrawChooseTree(&grid_size_current[0][1]);
8740 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8741 DrawChooseTree(&grid_size_current[1][0]);
8742 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8743 DrawChooseTree(&grid_size_current[1][1]);
8745 DrawSetupScreen_Generic();
8747 PlayMenuSoundsAndMusic();
8750 void RedrawSetupScreenAfterFullscreenToggle(void)
8752 if (setup_mode == SETUP_MODE_GRAPHICS ||
8753 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8755 // update list selection from "setup.window_scaling_percent"
8756 execSetupGraphics_setWindowSizes(TRUE);
8762 void RedrawSetupScreenAfterScreenRotation(int nr)
8766 if (setup_mode == SETUP_MODE_TOUCH)
8768 // update virtual button settings (depending on screen orientation)
8771 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8773 // save already configured virtual buttons
8774 for (x = 0; x < MAX_GRID_XSIZE; x++)
8775 for (y = 0; y < MAX_GRID_YSIZE; y++)
8776 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8780 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8782 if (setup_mode == SETUP_MODE_INPUT)
8783 HandleSetupScreen_Input(mx, my, dx, dy, button);
8784 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8785 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8786 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8787 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8788 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8789 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8790 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8791 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8792 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8793 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8794 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8795 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8796 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8797 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8798 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8799 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8800 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8801 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8802 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8803 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8804 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8805 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8806 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8807 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8808 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8809 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8810 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8811 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8812 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8813 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8814 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8815 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8816 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8817 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8818 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8819 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8820 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8821 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8822 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8823 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8824 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8825 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8827 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8830 void HandleGameActions(void)
8832 if (setup.ask_on_game_over)
8835 if (game.restart_game_message != NULL)
8837 RequestRestartGame(game.restart_game_message);
8842 if (game_status != GAME_MODE_PLAYING)
8845 GameActions(); // main game loop
8847 if (tape.auto_play && !tape.playing)
8848 AutoPlayTapes(); // continue automatically playing next tape
8852 // ---------- new screen button stuff --------------------------------------
8856 int gfx_unpressed, gfx_pressed;
8857 struct MenuPosInfo *pos;
8858 boolean *check_value;
8861 unsigned int event_mask;
8862 boolean is_touch_button;
8864 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8867 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8868 &menu.main.button.prev_level, NULL,
8869 SCREEN_CTRL_ID_PREV_LEVEL,
8871 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8872 FALSE, "previous level"
8875 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8876 &menu.main.button.next_level, NULL,
8877 SCREEN_CTRL_ID_NEXT_LEVEL,
8879 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8883 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
8884 &menu.main.button.first_level, NULL,
8885 SCREEN_CTRL_ID_FIRST_LEVEL,
8888 FALSE, "first level"
8891 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
8892 &menu.main.button.last_level, NULL,
8893 SCREEN_CTRL_ID_LAST_LEVEL,
8899 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
8900 &menu.main.button.level_number, NULL,
8901 SCREEN_CTRL_ID_LEVEL_NUMBER,
8904 FALSE, "level number"
8907 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8908 &menu.setup.button.prev_player, NULL,
8909 SCREEN_CTRL_ID_PREV_PLAYER,
8911 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8912 FALSE, "previous player"
8915 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8916 &menu.setup.button.next_player, NULL,
8917 SCREEN_CTRL_ID_NEXT_PLAYER,
8919 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8920 FALSE, "next player"
8923 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8924 &menu.main.button.insert_solution, NULL,
8925 SCREEN_CTRL_ID_INSERT_SOLUTION,
8926 SCREEN_MASK_MAIN_HAS_SOLUTION,
8928 FALSE, "insert solution tape"
8931 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8932 &menu.main.button.play_solution, NULL,
8933 SCREEN_CTRL_ID_PLAY_SOLUTION,
8934 SCREEN_MASK_MAIN_HAS_SOLUTION,
8936 FALSE, "play solution tape"
8939 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
8940 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
8941 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
8943 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
8944 FALSE, "switch ECS/AGA chipset"
8947 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
8948 &menu.setup.button.touch_back, NULL,
8949 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
8952 TRUE, "previous page"
8955 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
8956 &menu.setup.button.touch_next, NULL,
8957 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
8963 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
8964 &menu.setup.button.touch_back2, NULL,
8965 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
8968 TRUE, "previous page"
8971 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
8972 &menu.setup.button.touch_next2, NULL,
8973 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
8982 int gfx_unpressed, gfx_pressed;
8986 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8989 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8990 -1, -1, // these values are not constant, but can change at runtime
8991 SCREEN_CTRL_ID_SCROLL_UP,
8995 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8996 -1, -1, // these values are not constant, but can change at runtime
8997 SCREEN_CTRL_ID_SCROLL_DOWN,
9004 int gfx_unpressed, gfx_pressed;
9010 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9013 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9014 -1, -1, // these values are not constant, but can change at runtime
9015 -1, -1, // these values are not constant, but can change at runtime
9016 GD_TYPE_SCROLLBAR_VERTICAL,
9017 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9018 "scroll level series vertically"
9030 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9033 IMG_SETUP_INPUT_TEXT,
9034 SCREEN_CTRL_ID_NETWORK_SERVER,
9035 -1, -1, // these values are not constant, but can change at runtime
9036 MAX_SETUP_TEXT_INPUT_LEN,
9037 network_server_hostname,
9038 "Network Server Hostname / IP"
9042 static void CreateScreenMenubuttons(void)
9044 struct GadgetInfo *gi;
9045 unsigned int event_mask;
9048 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9050 struct MenuPosInfo *pos = menubutton_info[i].pos;
9051 boolean is_touch_button = menubutton_info[i].is_touch_button;
9052 boolean is_check_button = menubutton_info[i].check_value != NULL;
9053 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9054 int gfx_unpressed, gfx_pressed;
9055 int x, y, width, height;
9056 int gd_x1, gd_x2, gd_y1, gd_y2;
9057 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9058 int id = menubutton_info[i].gadget_id;
9059 int type = GD_TYPE_NORMAL_BUTTON;
9060 boolean checked = FALSE;
9062 event_mask = menubutton_info[i].event_mask;
9064 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9065 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9067 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9068 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9070 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9071 gfx_pressed = menubutton_info[i].gfx_pressed;
9072 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9073 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9074 gd_x1 = graphic_info[gfx_unpressed].src_x;
9075 gd_y1 = graphic_info[gfx_unpressed].src_y;
9076 gd_x2 = graphic_info[gfx_pressed].src_x;
9077 gd_y2 = graphic_info[gfx_pressed].src_y;
9083 if (is_touch_button)
9085 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9086 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9089 if (is_check_button)
9091 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9092 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9093 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9094 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9096 type = GD_TYPE_CHECK_BUTTON;
9097 checked = *menubutton_info[i].check_value;
9100 gi = CreateGadget(GDI_CUSTOM_ID, id,
9101 GDI_CUSTOM_TYPE_ID, i,
9102 GDI_IMAGE_ID, gfx_unpressed,
9103 GDI_INFO_TEXT, menubutton_info[i].infotext,
9109 GDI_STATE, GD_BUTTON_UNPRESSED,
9110 GDI_CHECKED, checked,
9111 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9112 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9113 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9114 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9115 GDI_DIRECT_DRAW, FALSE,
9116 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9117 GDI_EVENT_MASK, event_mask,
9118 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9122 Fail("cannot create gadget");
9124 screen_gadget[id] = gi;
9128 static void CreateScreenScrollbuttons(void)
9130 struct GadgetInfo *gi;
9131 unsigned int event_mask;
9134 // these values are not constant, but can change at runtime
9135 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9136 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9137 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9138 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9140 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9142 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9143 int gfx_unpressed, gfx_pressed;
9144 int x, y, width, height;
9145 int gd_x1, gd_x2, gd_y1, gd_y2;
9146 int id = scrollbutton_info[i].gadget_id;
9148 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9150 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9151 y = mSY + scrollbutton_info[i].y;
9152 width = SC_SCROLLBUTTON_XSIZE;
9153 height = SC_SCROLLBUTTON_YSIZE;
9155 // correct scrollbar position if placed outside menu (playfield) area
9156 if (x > SX + SC_SCROLL_UP_XPOS)
9157 x = SX + SC_SCROLL_UP_XPOS;
9159 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9160 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9161 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9163 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9164 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9165 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9166 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9167 gd_x1 = graphic_info[gfx_unpressed].src_x;
9168 gd_y1 = graphic_info[gfx_unpressed].src_y;
9169 gd_x2 = graphic_info[gfx_pressed].src_x;
9170 gd_y2 = graphic_info[gfx_pressed].src_y;
9172 gi = CreateGadget(GDI_CUSTOM_ID, id,
9173 GDI_CUSTOM_TYPE_ID, i,
9174 GDI_IMAGE_ID, gfx_unpressed,
9175 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9180 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9181 GDI_STATE, GD_BUTTON_UNPRESSED,
9182 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9183 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9184 GDI_DIRECT_DRAW, FALSE,
9185 GDI_EVENT_MASK, event_mask,
9186 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9190 Fail("cannot create gadget");
9192 screen_gadget[id] = gi;
9196 static void CreateScreenScrollbars(void)
9200 // these values are not constant, but can change at runtime
9201 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9202 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9203 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9204 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9206 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9208 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9209 int gfx_unpressed, gfx_pressed;
9210 int x, y, width, height;
9211 int gd_x1, gd_x2, gd_y1, gd_y2;
9212 struct GadgetInfo *gi;
9213 int items_max, items_visible, item_position;
9214 unsigned int event_mask;
9215 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9216 int id = scrollbar_info[i].gadget_id;
9218 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9220 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9221 y = mSY + scrollbar_info[i].y;
9222 width = scrollbar_info[i].width;
9223 height = scrollbar_info[i].height;
9225 // correct scrollbar position if placed outside menu (playfield) area
9226 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9227 x = SX + SC_SCROLL_VERTICAL_XPOS;
9229 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9230 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9232 items_max = num_page_entries;
9233 items_visible = num_page_entries;
9236 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9237 gfx_pressed = scrollbar_info[i].gfx_pressed;
9238 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9239 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9240 gd_x1 = graphic_info[gfx_unpressed].src_x;
9241 gd_y1 = graphic_info[gfx_unpressed].src_y;
9242 gd_x2 = graphic_info[gfx_pressed].src_x;
9243 gd_y2 = graphic_info[gfx_pressed].src_y;
9245 gi = CreateGadget(GDI_CUSTOM_ID, id,
9246 GDI_CUSTOM_TYPE_ID, i,
9247 GDI_IMAGE_ID, gfx_unpressed,
9248 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9253 GDI_TYPE, scrollbar_info[i].type,
9254 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9255 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9256 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9257 GDI_WHEEL_AREA_X, SX,
9258 GDI_WHEEL_AREA_Y, SY,
9259 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9260 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9261 GDI_STATE, GD_BUTTON_UNPRESSED,
9262 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9263 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9264 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9265 GDI_DIRECT_DRAW, FALSE,
9266 GDI_EVENT_MASK, event_mask,
9267 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9271 Fail("cannot create gadget");
9273 screen_gadget[id] = gi;
9277 static void CreateScreenTextInputGadgets(void)
9281 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9283 int graphic = textinput_info[i].graphic;
9284 struct GraphicInfo *gd = &graphic_info[graphic];
9285 int gd_x1 = gd->src_x;
9286 int gd_y1 = gd->src_y;
9287 int gd_x2 = gd->src_x + gd->active_xoffset;
9288 int gd_y2 = gd->src_y + gd->active_yoffset;
9289 struct GadgetInfo *gi;
9290 unsigned int event_mask;
9291 int id = textinput_info[i].gadget_id;
9292 int x = textinput_info[i].x;
9293 int y = textinput_info[i].y;
9295 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9297 gi = CreateGadget(GDI_CUSTOM_ID, id,
9298 GDI_CUSTOM_TYPE_ID, i,
9299 GDI_INFO_TEXT, textinput_info[i].infotext,
9302 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9303 GDI_TEXT_VALUE, textinput_info[i].value,
9304 GDI_TEXT_SIZE, textinput_info[i].size,
9305 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9306 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9307 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9308 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9309 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9310 GDI_DESIGN_WIDTH, gd->width,
9311 GDI_EVENT_MASK, event_mask,
9312 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9313 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9317 Fail("cannot create gadget");
9319 screen_gadget[id] = gi;
9323 void CreateScreenGadgets(void)
9325 CreateScreenMenubuttons();
9327 CreateScreenScrollbuttons();
9328 CreateScreenScrollbars();
9330 CreateScreenTextInputGadgets();
9333 void FreeScreenGadgets(void)
9337 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9338 FreeGadget(screen_gadget[i]);
9341 static void MapScreenMenuGadgets(int screen_mask)
9345 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9346 if (screen_mask & menubutton_info[i].screen_mask)
9347 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9350 static void UnmapScreenMenuGadgets(int screen_mask)
9354 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9356 if (screen_mask & menubutton_info[i].screen_mask)
9358 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9360 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9361 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9362 screen_gadget[menubutton_info[i].gadget_id]->y,
9363 screen_gadget[menubutton_info[i].gadget_id]->width,
9364 screen_gadget[menubutton_info[i].gadget_id]->height);
9369 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9372 MapScreenMenuGadgets(screen_mask);
9374 UnmapScreenMenuGadgets(screen_mask);
9377 static void MapScreenGadgets(int num_entries)
9381 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9384 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9385 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9387 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9388 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9391 static void MapScreenTreeGadgets(TreeInfo *ti)
9393 MapScreenGadgets(numTreeInfoInGroup(ti));
9396 static void HandleScreenGadgets(struct GadgetInfo *gi)
9398 int id = gi->custom_id;
9399 int button = gi->event.button;
9400 int step = (button == MB_LEFTBUTTON ? 1 :
9401 button == MB_MIDDLEBUTTON ? 5 :
9402 button == MB_RIGHTBUTTON ? 10 : 1);
9406 case SCREEN_CTRL_ID_PREV_LEVEL:
9407 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9410 case SCREEN_CTRL_ID_NEXT_LEVEL:
9411 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9414 case SCREEN_CTRL_ID_FIRST_LEVEL:
9415 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9418 case SCREEN_CTRL_ID_LAST_LEVEL:
9419 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9422 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9423 CloseDoor(DOOR_CLOSE_2);
9424 SetGameStatus(GAME_MODE_LEVELNR);
9425 DrawChooseLevelNr();
9428 case SCREEN_CTRL_ID_PREV_PLAYER:
9429 HandleSetupScreen_Input_Player(step, -1);
9432 case SCREEN_CTRL_ID_NEXT_PLAYER:
9433 HandleSetupScreen_Input_Player(step, +1);
9436 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9437 InsertSolutionTape();
9440 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9444 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9445 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9449 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9450 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9451 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9452 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9453 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9456 case SCREEN_CTRL_ID_SCROLL_UP:
9457 if (game_status == GAME_MODE_NAMES)
9458 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9459 else if (game_status == GAME_MODE_LEVELS)
9460 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9461 else if (game_status == GAME_MODE_LEVELNR)
9462 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9463 else if (game_status == GAME_MODE_SETUP)
9464 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9465 else if (game_status == GAME_MODE_INFO)
9466 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9469 case SCREEN_CTRL_ID_SCROLL_DOWN:
9470 if (game_status == GAME_MODE_NAMES)
9471 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9472 else if (game_status == GAME_MODE_LEVELS)
9473 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9474 else if (game_status == GAME_MODE_LEVELNR)
9475 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9476 else if (game_status == GAME_MODE_SETUP)
9477 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9478 else if (game_status == GAME_MODE_INFO)
9479 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9482 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9483 if (game_status == GAME_MODE_NAMES)
9484 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9485 else if (game_status == GAME_MODE_LEVELS)
9486 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9487 else if (game_status == GAME_MODE_LEVELNR)
9488 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9489 else if (game_status == GAME_MODE_SETUP)
9490 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9491 else if (game_status == GAME_MODE_INFO)
9492 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9495 case SCREEN_CTRL_ID_NETWORK_SERVER:
9497 if (!strEqual(gi->textinput.value, ""))
9499 setString(&setup.network_server_hostname, gi->textinput.value);
9501 network.server_host = setup.network_server_hostname;
9505 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9507 network.server_host = NULL;
9510 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9511 network.server_host = NULL;
9513 execSetupGame_setNetworkServerText();
9525 void DumpScreenIdentifiers(void)
9529 Print("Active screen elements on current screen:\n");
9531 for (i = 0; main_controls[i].nr != -1; i++)
9533 struct MainControlInfo *mci = &main_controls[i];
9535 if (mci->button_graphic != -1)
9537 char *token = getTokenFromImageID(mci->button_graphic);
9539 Print("- '%s'\n", token);
9546 boolean DoScreenAction(int image_id)
9550 if (game_status != GAME_MODE_MAIN)
9553 for (i = 0; main_controls[i].nr != -1; i++)
9555 struct MainControlInfo *mci = &main_controls[i];
9556 struct MenuPosInfo *pos = mci->pos_button;
9558 if (mci->button_graphic == image_id)
9560 int x = mSX + pos->x;
9561 int y = mSY + pos->y;
9563 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9572 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9574 // get tree info node of newly added level or artwork set
9575 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9576 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9578 if (tree_node_new == NULL) // should not happen
9581 // if request dialog is active, do nothing
9582 if (game.request_active)
9585 if (game_status == GAME_MODE_MAIN &&
9586 tree_type == TREE_TYPE_LEVEL_DIR)
9588 // when adding new level set in main menu, select it as current level set
9590 // change current level set to newly added level set from zip file
9591 leveldir_current = tree_node_new;
9593 // change current level number to first level of newly added level set
9594 level_nr = leveldir_current->first_level;
9596 // redraw screen to reflect changed level set
9599 // save this level set and level number as last selected level set
9600 SaveLevelSetup_LastSeries();
9601 SaveLevelSetup_SeriesInfo();
9603 else if (game_status == GAME_MODE_LEVELS &&
9604 tree_type == TREE_TYPE_LEVEL_DIR)
9606 // when adding new level set in level set menu, set cursor and update screen
9608 leveldir_current = tree_node_new;
9610 DrawChooseTree(&leveldir_current);
9612 else if (game_status == GAME_MODE_SETUP)
9614 // when adding new artwork set in setup menu, set cursor and update screen
9616 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9617 tree_type == TREE_TYPE_GRAPHICS_DIR)
9619 artwork.gfx_current = tree_node_new;
9621 DrawChooseTree(&artwork.gfx_current);
9623 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9624 tree_type == TREE_TYPE_SOUNDS_DIR)
9626 artwork.snd_current = tree_node_new;
9628 DrawChooseTree(&artwork.snd_current);
9630 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9631 tree_type == TREE_TYPE_MUSIC_DIR)
9633 artwork.mus_current = tree_node_new;
9635 DrawChooseTree(&artwork.mus_current);