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 // for input setup functions
127 #define SETUPINPUT_SCREEN_POS_START 0
128 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
129 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
130 #define SETUPINPUT_SCREEN_POS_END 13
132 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
133 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
135 #define MAX_SETUP_TEXT_INPUT_LEN 28
137 // for various menu stuff
138 #define MENU_SCREEN_START_XPOS 1
139 #define MENU_SCREEN_START_YPOS 2
140 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
141 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
142 #define MENU_TITLE1_YPOS 8
143 #define MENU_TITLE2_YPOS 46
144 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
145 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
146 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
147 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
148 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
149 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
150 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
151 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
152 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
153 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
154 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
155 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
156 MENU_INFO_FONT_TITLE))
157 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
158 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
159 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
160 MENU_SCREEN_INFO_YSTART2 - \
162 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
163 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
164 MENU_SCREEN_INFO_YSTEP)
165 #define NUM_INFO_ELEMENTS_FROM_CONF \
166 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
167 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
168 MAX_MENU_ENTRIES_ON_SCREEN)
169 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
170 MAX_INFO_ELEMENTS_ON_SCREEN), \
171 NUM_INFO_ELEMENTS_FROM_CONF)
172 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
173 #define MAX_MENU_TEXT_LENGTH_BIG 13
174 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
176 // screen gadget identifiers
177 #define SCREEN_CTRL_ID_PREV_LEVEL 0
178 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
179 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
180 #define SCREEN_CTRL_ID_LAST_LEVEL 3
181 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
182 #define SCREEN_CTRL_ID_PREV_PLAYER 5
183 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
184 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
185 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
186 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
187 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
188 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
189 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
190 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
191 #define SCREEN_CTRL_ID_SCROLL_UP 14
192 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
193 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
194 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
196 #define NUM_SCREEN_GADGETS 18
198 #define NUM_SCREEN_MENUBUTTONS 14
199 #define NUM_SCREEN_SCROLLBUTTONS 2
200 #define NUM_SCREEN_SCROLLBARS 1
201 #define NUM_SCREEN_TEXTINPUT 1
203 #define SCREEN_MASK_MAIN (1 << 0)
204 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
205 #define SCREEN_MASK_INPUT (1 << 2)
206 #define SCREEN_MASK_TOUCH (1 << 3)
207 #define SCREEN_MASK_TOUCH2 (1 << 4)
209 // graphic position and size values for buttons and scrollbars
210 #define SC_MENUBUTTON_XSIZE TILEX
211 #define SC_MENUBUTTON_YSIZE TILEY
213 #define SC_SCROLLBUTTON_XSIZE TILEX
214 #define SC_SCROLLBUTTON_YSIZE TILEY
216 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
218 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
219 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
220 SC_SCROLLBUTTON_YSIZE)
222 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
223 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
225 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
226 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
227 SC_SCROLLBUTTON_YSIZE)
229 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
230 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
231 SC_SCROLL_VERTICAL_YSIZE)
233 #define SC_BORDER_SIZE 14
236 // forward declarations of internal functions
237 static void HandleScreenGadgets(struct GadgetInfo *);
238 static void HandleSetupScreen_Generic(int, int, int, int, int);
239 static void HandleSetupScreen_Input(int, int, int, int, int);
240 static void CustomizeKeyboard(int);
241 static void ConfigureJoystick(int);
242 static void ConfigureVirtualButtons(void);
243 static void execSetupGame(void);
244 static void execSetupEngines(void);
245 static void execSetupGraphics(void);
246 static void execSetupSound(void);
247 static void execSetupTouch(void);
248 static void execSetupArtwork(void);
249 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
251 static void DrawChoosePlayerName(void);
252 static void DrawChooseLevelSet(void);
253 static void DrawChooseLevelNr(void);
254 static void DrawInfoScreen(void);
255 static void DrawSetupScreen(void);
256 static void DrawTypeName(void);
258 static void DrawInfoScreen_NotAvailable(char *, char *);
259 static void DrawInfoScreen_HelpAnim(int, int, boolean);
260 static void DrawInfoScreen_HelpText(int, int, int, int);
261 static void HandleInfoScreen_Main(int, int, int, int, int);
262 static void HandleInfoScreen_TitleScreen(int);
263 static void HandleInfoScreen_Elements(int);
264 static void HandleInfoScreen_Music(int);
265 static void HandleInfoScreen_Credits(int);
266 static void HandleInfoScreen_Program(int);
267 static void HandleInfoScreen_Version(int);
269 static void ModifyGameSpeedIfNeeded(void);
270 static void DisableVsyncIfNeeded(void);
272 static void MapScreenMenuGadgets(int);
273 static void UnmapScreenMenuGadgets(int);
274 static void MapScreenGadgets(int);
275 static void MapScreenTreeGadgets(TreeInfo *);
277 static void UpdateScreenMenuGadgets(int, boolean);
279 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
281 static int info_mode = INFO_MODE_MAIN;
282 static int setup_mode = SETUP_MODE_MAIN;
284 static TreeInfo *window_sizes = NULL;
285 static TreeInfo *window_size_current = NULL;
287 static TreeInfo *scaling_types = NULL;
288 static TreeInfo *scaling_type_current = NULL;
290 static TreeInfo *rendering_modes = NULL;
291 static TreeInfo *rendering_mode_current = NULL;
293 static TreeInfo *vsync_modes = NULL;
294 static TreeInfo *vsync_mode_current = NULL;
296 static TreeInfo *scroll_delays = NULL;
297 static TreeInfo *scroll_delay_current = NULL;
299 static TreeInfo *snapshot_modes = NULL;
300 static TreeInfo *snapshot_mode_current = NULL;
302 static TreeInfo *game_speeds_normal = NULL;
303 static TreeInfo *game_speeds_extended = NULL;
304 static TreeInfo *game_speeds = NULL;
305 static TreeInfo *game_speed_current = NULL;
307 static TreeInfo *volumes_simple = NULL;
308 static TreeInfo *volume_simple_current = NULL;
310 static TreeInfo *volumes_loops = NULL;
311 static TreeInfo *volume_loops_current = NULL;
313 static TreeInfo *volumes_music = NULL;
314 static TreeInfo *volume_music_current = NULL;
316 static TreeInfo *touch_controls = NULL;
317 static TreeInfo *touch_control_current = NULL;
319 static TreeInfo *move_distances = NULL;
320 static TreeInfo *move_distance_current = NULL;
322 static TreeInfo *drop_distances = NULL;
323 static TreeInfo *drop_distance_current = NULL;
325 static TreeInfo *transparencies = NULL;
326 static TreeInfo *transparency_current = NULL;
328 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
329 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
331 static TreeInfo *player_name = NULL;
332 static TreeInfo *player_name_current = NULL;
334 static TreeInfo *level_number = NULL;
335 static TreeInfo *level_number_current = NULL;
337 static struct ValueTextInfo window_sizes_list[] =
342 { 100, "100 % (Default)" },
355 static struct StringValueTextInfo scaling_types_list[] =
357 { SCALING_QUALITY_NEAREST, "Off" },
358 { SCALING_QUALITY_LINEAR, "Linear" },
359 { SCALING_QUALITY_BEST, "Anisotropic" },
364 static struct StringValueTextInfo rendering_modes_list[] =
366 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
367 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
369 // this mode may work under certain conditions, but does not work on Windows
370 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
372 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
377 static struct StringValueTextInfo vsync_modes_list[] =
379 { STR_VSYNC_MODE_OFF, "Off" },
380 { STR_VSYNC_MODE_NORMAL, "Normal" },
381 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
386 static struct ValueTextInfo game_speeds_list_normal[] =
397 static struct ValueTextInfo game_speeds_list_extended[] =
399 { 1000, "1 fps (Extremely Slow)" },
404 { 29, "35 fps (Original Supaplex)" },
406 { 20, "50 fps (=== Normal Speed ===)" },
407 { 16, "60 fps (60 Hz VSync Speed)" },
408 { 14, "70 fps (Maximum Supaplex)" },
412 { 1, "1000 fps (Extremely Fast)" },
417 static struct ValueTextInfo *game_speeds_list;
419 static struct ValueTextInfo scroll_delays_list[] =
421 { 0, "0 Tiles (No Scroll Delay)" },
424 { 3, "3 Tiles (Default)" },
429 { 8, "8 Tiles (Maximum Scroll Delay)"},
434 static struct StringValueTextInfo snapshot_modes_list[] =
436 { STR_SNAPSHOT_MODE_OFF, "Off" },
437 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
438 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
439 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
444 static struct ValueTextInfo volumes_list[] =
464 static struct StringValueTextInfo touch_controls_list[] =
466 { TOUCH_CONTROL_OFF, "Off" },
467 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
468 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
469 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
474 static struct ValueTextInfo distances_list[] =
489 static struct ValueTextInfo transparencies_list[] =
491 { 0, "0 % (Opaque)" },
501 { 100, "100 % (Invisible)" },
506 static struct ValueTextInfo grid_sizes_list[] =
542 static int align_xoffset = 0;
543 static int align_yoffset = 0;
545 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
546 (s) <= GAME_MODE_SETUP ? (s) : \
547 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
549 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
550 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
552 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
553 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
554 (i) <= INFO_MODE_LEVELSET ? (i) : \
557 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
558 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
559 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
560 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
561 SETUP_MODE_CHOOSE_ARTWORK : \
562 SETUP_MODE_CHOOSE_OTHER)
564 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
565 menu.draw_xoffset[GAME_MODE_INFO] : \
566 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
567 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
568 menu.draw_yoffset[GAME_MODE_INFO] : \
569 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
570 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
571 menu.extra_spacing[GAME_MODE_INFO] : \
572 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
574 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
575 menu.draw_xoffset[GAME_MODE_SETUP] : \
576 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
577 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
578 menu.draw_yoffset[GAME_MODE_SETUP] : \
579 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
580 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
581 menu.extra_spacing[GAME_MODE_SETUP] : \
582 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
584 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
585 DRAW_XOFFSET_INFO(info_mode) : \
586 (s) == GAME_MODE_SETUP ? \
587 DRAW_XOFFSET_SETUP(setup_mode) : \
588 menu.draw_xoffset[DRAW_MODE(s)])
589 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
590 DRAW_YOFFSET_INFO(info_mode) : \
591 (s) == GAME_MODE_SETUP ? \
592 DRAW_YOFFSET_SETUP(setup_mode) : \
593 menu.draw_yoffset[DRAW_MODE(s)])
594 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
595 EXTRA_SPACING_INFO(info_mode) : \
596 (s) == GAME_MODE_SETUP ? \
597 EXTRA_SPACING_SETUP(setup_mode) : \
598 menu.extra_spacing[DRAW_MODE(s)])
600 #define mSX (SX + DRAW_XOFFSET(game_status))
601 #define mSY (SY + DRAW_YOFFSET(game_status))
603 #define amSX (mSX + align_xoffset)
604 #define amSY (mSY + align_yoffset)
606 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
607 menu.list_size[game_status] : \
608 MAX_MENU_ENTRIES_ON_SCREEN)
610 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
611 NUM_MENU_ENTRIES_ON_SCREEN)
614 // title display and control definitions
616 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
617 2 * MAX_NUM_TITLE_MESSAGES)
619 #define NO_DIRECT_LEVEL_SELECT (-1)
622 static int num_title_screens = 0;
624 struct TitleControlInfo
633 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
635 // main menu display and control definitions
637 #define MAIN_CONTROL_NAME 0
638 #define MAIN_CONTROL_LEVELS 1
639 #define MAIN_CONTROL_SCORES 2
640 #define MAIN_CONTROL_EDITOR 3
641 #define MAIN_CONTROL_INFO 4
642 #define MAIN_CONTROL_GAME 5
643 #define MAIN_CONTROL_SETUP 6
644 #define MAIN_CONTROL_QUIT 7
645 #define MAIN_CONTROL_PREV_LEVEL 8
646 #define MAIN_CONTROL_NEXT_LEVEL 9
647 #define MAIN_CONTROL_FIRST_LEVEL 10
648 #define MAIN_CONTROL_LAST_LEVEL 11
649 #define MAIN_CONTROL_LEVEL_NUMBER 12
650 #define MAIN_CONTROL_LEVEL_INFO_1 13
651 #define MAIN_CONTROL_LEVEL_INFO_2 14
652 #define MAIN_CONTROL_LEVEL_NAME 15
653 #define MAIN_CONTROL_LEVEL_AUTHOR 16
654 #define MAIN_CONTROL_LEVEL_YEAR 17
655 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
656 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
657 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
658 #define MAIN_CONTROL_TITLE_1 21
659 #define MAIN_CONTROL_TITLE_2 22
660 #define MAIN_CONTROL_TITLE_3 23
662 static char str_main_text_name[10];
663 static char str_main_text_first_level[10];
664 static char str_main_text_last_level[10];
665 static char str_main_text_level_number[10];
667 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
669 static char *main_text_name = str_main_text_name;
670 static char *main_text_first_level = str_main_text_first_level;
671 static char *main_text_last_level = str_main_text_last_level;
672 static char *main_text_level_number = str_main_text_level_number;
673 static char *main_text_levels = "Levelset";
674 static char *main_text_scores = "Hall Of Fame";
675 static char *main_text_editor = "Level Creator";
676 static char *main_text_info = "Info Screen";
677 static char *main_text_game = "Start Game";
678 static char *main_text_setup = "Setup";
679 static char *main_text_quit = "Quit";
680 static char *main_text_level_name = level.name;
681 static char *main_text_level_author = level.author;
682 static char *main_text_level_year = NULL;
683 static char *main_text_level_imported_from = NULL;
684 static char *main_text_level_imported_by = NULL;
685 static char *main_text_level_tested_by = NULL;
686 static char *main_text_title_1 = NULL;
687 static char *main_text_title_2 = NULL;
688 static char *main_text_title_3 = NULL;
690 extern char debug_xsn_mode[];
692 struct MainControlInfo
696 struct MenuPosInfo *pos_button;
699 struct TextPosInfo *pos_text;
702 struct TextPosInfo *pos_input;
706 static struct MainControlInfo main_controls[] =
710 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
711 &menu.main.text.name, &main_text_name,
712 &menu.main.input.name, &setup.player_name,
716 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
717 &menu.main.text.levels, &main_text_levels,
722 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
723 &menu.main.text.scores, &main_text_scores,
728 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
729 &menu.main.text.editor, &main_text_editor,
734 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
735 &menu.main.text.info, &main_text_info,
740 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
741 &menu.main.text.game, &main_text_game,
746 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
747 &menu.main.text.setup, &main_text_setup,
752 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
753 &menu.main.text.quit, &main_text_quit,
757 MAIN_CONTROL_PREV_LEVEL,
763 MAIN_CONTROL_NEXT_LEVEL,
769 MAIN_CONTROL_FIRST_LEVEL,
771 &menu.main.text.first_level, &main_text_first_level,
775 MAIN_CONTROL_LAST_LEVEL,
777 &menu.main.text.last_level, &main_text_last_level,
781 MAIN_CONTROL_LEVEL_NUMBER,
783 &menu.main.text.level_number, &main_text_level_number,
787 MAIN_CONTROL_LEVEL_INFO_1,
789 &menu.main.text.level_info_1, NULL,
793 MAIN_CONTROL_LEVEL_INFO_2,
795 &menu.main.text.level_info_2, NULL,
799 MAIN_CONTROL_LEVEL_NAME,
801 &menu.main.text.level_name, &main_text_level_name,
805 MAIN_CONTROL_LEVEL_AUTHOR,
807 &menu.main.text.level_author, &main_text_level_author,
811 MAIN_CONTROL_LEVEL_YEAR,
813 &menu.main.text.level_year, &main_text_level_year,
817 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
819 &menu.main.text.level_imported_from, &main_text_level_imported_from,
823 MAIN_CONTROL_LEVEL_IMPORTED_BY,
825 &menu.main.text.level_imported_by, &main_text_level_imported_by,
829 MAIN_CONTROL_LEVEL_TESTED_BY,
831 &menu.main.text.level_tested_by, &main_text_level_tested_by,
835 MAIN_CONTROL_TITLE_1,
837 &menu.main.text.title_1, &main_text_title_1,
841 MAIN_CONTROL_TITLE_2,
843 &menu.main.text.title_2, &main_text_title_2,
847 MAIN_CONTROL_TITLE_3,
849 &menu.main.text.title_3, &main_text_title_3,
862 static int getTitleScreenGraphic(int nr, boolean initial)
864 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
867 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
869 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
873 static int getTitleScreenGameMode(boolean initial)
875 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
879 static int getTitleMessageGameMode(boolean initial)
881 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
884 static int getTitleAnimMode(struct TitleControlInfo *tci)
886 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
888 return base + tci->local_nr;
892 static int getTitleScreenBackground(boolean initial)
894 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
899 static int getTitleMessageBackground(int nr, boolean initial)
901 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
905 static int getTitleBackground(int nr, boolean initial, boolean is_image)
907 int base = (is_image ?
908 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
909 IMG_BACKGROUND_TITLESCREEN_1) :
910 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
911 IMG_BACKGROUND_TITLEMESSAGE_1));
912 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
913 IMG_BACKGROUND_TITLE);
914 int graphic_local = base + nr;
916 if (graphic_info[graphic_local].bitmap != NULL)
917 return graphic_local;
919 if (graphic_info[graphic_global].bitmap != NULL)
920 return graphic_global;
922 return IMG_UNDEFINED;
925 static int getTitleSound(struct TitleControlInfo *tci)
927 boolean is_image = tci->is_image;
928 int initial = tci->initial;
929 int nr = tci->local_nr;
930 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
931 int base = (is_image ?
932 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
933 SND_BACKGROUND_TITLESCREEN_1) :
934 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
935 SND_BACKGROUND_TITLEMESSAGE_1));
936 int sound_global = menu.sound[mode];
937 int sound_local = base + nr;
940 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
941 nr, initial, is_image,
942 sound_global, getSoundListEntry(sound_global)->filename,
943 sound_local, getSoundListEntry(sound_local)->filename);
946 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
949 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
952 return SND_UNDEFINED;
955 static int getTitleMusic(struct TitleControlInfo *tci)
957 boolean is_image = tci->is_image;
958 int initial = tci->initial;
959 int nr = tci->local_nr;
960 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
961 int base = (is_image ?
962 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
963 MUS_BACKGROUND_TITLESCREEN_1) :
964 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
965 MUS_BACKGROUND_TITLEMESSAGE_1));
966 int music_global = menu.music[mode];
967 int music_local = base + nr;
970 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
971 nr, initial, is_image,
972 music_global, getMusicListEntry(music_global)->filename,
973 music_local, getMusicListEntry(music_local)->filename);
976 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
979 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
982 return MUS_UNDEFINED;
985 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
987 boolean is_image = tci->is_image;
988 boolean initial = tci->initial;
989 boolean first = tci->first;
990 int nr = tci->local_nr;
991 struct TitleMessageInfo tmi;
992 struct TitleFadingInfo ti;
994 tmi = (is_image ? (initial ? (first ?
995 titlescreen_initial_first[nr] :
996 titlescreen_initial[nr])
998 titlescreen_first[nr] :
1000 : (initial ? (first ?
1001 titlemessage_initial_first[nr] :
1002 titlemessage_initial[nr])
1004 titlemessage_first[nr] :
1005 titlemessage[nr])));
1007 ti.fade_mode = tmi.fade_mode;
1008 ti.fade_delay = tmi.fade_delay;
1009 ti.post_delay = tmi.post_delay;
1010 ti.auto_delay = tmi.auto_delay;
1011 ti.auto_delay_unit = tmi.auto_delay_unit;
1016 static int compareTitleControlInfo(const void *object1, const void *object2)
1018 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1019 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1022 if (tci1->initial != tci2->initial)
1023 compare_result = (tci1->initial ? -1 : +1);
1024 else if (tci1->sort_priority != tci2->sort_priority)
1025 compare_result = tci1->sort_priority - tci2->sort_priority;
1026 else if (tci1->is_image != tci2->is_image)
1027 compare_result = (tci1->is_image ? -1 : +1);
1029 compare_result = tci1->local_nr - tci2->local_nr;
1031 return compare_result;
1034 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1036 int nr, int sort_priority)
1038 title_controls[num_title_screens].is_image = is_image;
1039 title_controls[num_title_screens].initial = initial;
1040 title_controls[num_title_screens].local_nr = nr;
1041 title_controls[num_title_screens].sort_priority = sort_priority;
1043 title_controls[num_title_screens].first = FALSE; // will be set later
1045 num_title_screens++;
1048 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1052 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1054 int graphic = getTitleScreenGraphic(i, initial);
1055 Bitmap *bitmap = graphic_info[graphic].bitmap;
1056 int sort_priority = graphic_info[graphic].sort_priority;
1059 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1062 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1064 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1065 char *filename = getLevelSetTitleMessageFilename(i, initial);
1066 int sort_priority = tmi->sort_priority;
1068 if (filename != NULL)
1069 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1073 static void InitializeTitleControls(boolean show_title_initial)
1075 num_title_screens = 0;
1077 // 1st step: initialize title screens for game start (only when starting)
1078 if (show_title_initial)
1079 InitializeTitleControls_CheckTitleInfo(TRUE);
1081 // 2nd step: initialize title screens for current level set
1082 InitializeTitleControls_CheckTitleInfo(FALSE);
1084 // sort title screens according to sort_priority and title number
1085 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1086 compareTitleControlInfo);
1088 // mark first title screen
1089 title_controls[0].first = TRUE;
1092 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1094 return (pos != NULL && pos->x != -1 && pos->y != -1);
1097 static boolean visibleTextPos(struct TextPosInfo *pos)
1099 return (pos != NULL && pos->x != -1 && pos->y != -1);
1102 static void InitializeMainControls(void)
1104 boolean local_team_mode = (!network.enabled && setup.team_mode);
1107 // set main control text values to dynamically determined values
1108 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1110 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1111 menu.main.text.first_level.size));
1112 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1113 menu.main.text.last_level.size));
1114 strcpy(main_text_level_number, int2str(level_nr,
1115 menu.main.text.level_number.size));
1117 main_text_level_year = leveldir_current->year;
1118 main_text_level_imported_from = leveldir_current->imported_from;
1119 main_text_level_imported_by = leveldir_current->imported_by;
1120 main_text_level_tested_by = leveldir_current->tested_by;
1122 main_text_title_1 = getConfigProgramTitleString();
1123 main_text_title_2 = getConfigProgramCopyrightString();
1124 main_text_title_3 = getConfigProgramCompanyString();
1126 // set main control screen positions to dynamically determined values
1127 for (i = 0; main_controls[i].nr != -1; i++)
1129 struct MainControlInfo *mci = &main_controls[i];
1131 struct MenuPosInfo *pos_button = mci->pos_button;
1132 struct TextPosInfo *pos_text = mci->pos_text;
1133 struct TextPosInfo *pos_input = mci->pos_input;
1134 char *text = (mci->text ? *mci->text : NULL);
1135 char *input = (mci->input ? *mci->input : NULL);
1136 int button_graphic = mci->button_graphic;
1137 int font_text = (pos_text ? pos_text->font : -1);
1138 int font_input = (pos_input ? pos_input->font : -1);
1140 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1141 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1142 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1143 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1144 int text_chars = (text != NULL ? strlen(text) : 0);
1145 int input_chars = (input != NULL ? strlen(input) : 0);
1148 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1150 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1151 int text_width = font_text_width * text_chars;
1152 int text_height = font_text_height;
1153 int input_width = font_input_width * input_chars;
1154 int input_height = font_input_height;
1156 if (nr == MAIN_CONTROL_NAME)
1158 menu.main.input.name.width = input_width;
1159 menu.main.input.name.height = input_height;
1162 if (pos_button != NULL) // (x/y may be -1/-1 here)
1164 pos_button->width = button_width;
1165 pos_button->height = button_height;
1168 if (pos_text != NULL) // (x/y may be -1/-1 here)
1170 // calculate text size -- needed for text alignment
1171 boolean calculate_text_size = (text != NULL);
1173 if (pos_text->width == -1 || calculate_text_size)
1174 pos_text->width = text_width;
1175 if (pos_text->height == -1 || calculate_text_size)
1176 pos_text->height = text_height;
1178 if (visibleMenuPos(pos_button))
1180 if (pos_text->x == -1)
1181 pos_text->x = pos_button->x + pos_button->width;
1182 if (pos_text->y == -1)
1184 pos_button->y + (pos_button->height - pos_text->height) / 2;
1188 if (pos_input != NULL) // (x/y may be -1/-1 here)
1190 if (visibleTextPos(pos_text))
1192 if (pos_input->x == -1)
1193 pos_input->x = pos_text->x + pos_text->width;
1194 if (pos_input->y == -1)
1195 pos_input->y = pos_text->y;
1198 if (pos_input->width == -1)
1199 pos_input->width = input_width;
1200 if (pos_input->height == -1)
1201 pos_input->height = input_height;
1206 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1207 int graphic, boolean pressed)
1209 struct GraphicInfo *g = &graphic_info[graphic];
1212 int xoffset = (pressed ? g->pressed_xoffset : 0);
1213 int yoffset = (pressed ? g->pressed_yoffset : 0);
1215 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1217 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1218 g->width, g->height, dst_x, dst_y);
1221 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1222 boolean active_input,
1223 boolean pressed_button)
1227 for (i = 0; main_controls[i].nr != -1; i++)
1229 struct MainControlInfo *mci = &main_controls[i];
1231 if (mci->nr == nr || nr == -1)
1233 struct MenuPosInfo *pos_button = mci->pos_button;
1234 struct TextPosInfo *pos_text = mci->pos_text;
1235 struct TextPosInfo *pos_input = mci->pos_input;
1236 char *text = (mci->text ? *mci->text : NULL);
1237 char *input = (mci->input ? *mci->input : NULL);
1238 int button_graphic = mci->button_graphic;
1239 int font_text = (pos_text ? pos_text->font : -1);
1240 int font_input = (pos_input ? pos_input->font : -1);
1244 button_graphic = BUTTON_ACTIVE(button_graphic);
1245 font_text = FONT_ACTIVE(font_text);
1250 font_input = FONT_ACTIVE(font_input);
1253 if (visibleMenuPos(pos_button))
1255 struct MenuPosInfo *pos = pos_button;
1256 int x = mSX + pos->x;
1257 int y = mSY + pos->y;
1259 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1260 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1263 if (visibleTextPos(pos_text) && text != NULL)
1265 struct TextPosInfo *pos = pos_text;
1266 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1267 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1270 // (check why/if this is needed)
1271 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1273 DrawText(x, y, text, font_text);
1276 if (visibleTextPos(pos_input) && input != NULL)
1278 struct TextPosInfo *pos = pos_input;
1279 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1280 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1283 // (check why/if this is needed)
1284 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1286 DrawText(x, y, input, font_input);
1292 static void DrawCursorAndText_Main(int nr, boolean active_text,
1293 boolean pressed_button)
1295 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1299 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1300 boolean pressed_button)
1302 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1306 static struct MainControlInfo *getMainControlInfo(int nr)
1310 for (i = 0; main_controls[i].nr != -1; i++)
1311 if (main_controls[i].nr == nr)
1312 return &main_controls[i];
1317 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1322 int rect_x = ALIGNED_TEXT_XPOS(rect);
1323 int rect_y = ALIGNED_TEXT_YPOS(rect);
1325 return (x >= rect_x && x < rect_x + rect->width &&
1326 y >= rect_y && y < rect_y + rect->height);
1329 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1334 int rect_x = ALIGNED_TEXT_XPOS(rect);
1335 int rect_y = ALIGNED_TEXT_YPOS(rect);
1338 Debug("screens:insideTextPosRect",
1339 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1340 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1341 (x >= rect_x && x < rect_x + rect->width &&
1342 y >= rect_y && y < rect_y + rect->height));
1345 return (x >= rect_x && x < rect_x + rect->width &&
1346 y >= rect_y && y < rect_y + rect->height);
1349 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1351 int rect_width = preview->xsize * preview->tile_size;
1352 int rect_height = preview->ysize * preview->tile_size;
1353 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1354 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1356 return (x >= rect_x && x < rect_x + rect_width &&
1357 y >= rect_y && y < rect_y + rect_height);
1360 static void AdjustScrollbar(int id, int items_max, int items_visible,
1363 struct GadgetInfo *gi = screen_gadget[id];
1365 if (item_position > items_max - items_visible)
1366 item_position = items_max - items_visible;
1368 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1369 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1370 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1373 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1375 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1379 static void clearMenuListArea(void)
1381 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1383 // correct scrollbar position if placed outside menu (playfield) area
1384 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1385 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1387 // clear menu list area, but not title or scrollbar
1388 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1389 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1392 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1394 static int cursor_array[MAX_LEV_FIELDY];
1395 int x = amSX + TILEX * xpos;
1396 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1401 cursor_array[ypos] = graphic;
1403 graphic = cursor_array[ypos];
1407 graphic = BUTTON_ACTIVE(graphic);
1409 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1410 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1413 static void initCursor(int ypos, int graphic)
1415 drawCursorExt(0, ypos, FALSE, graphic);
1418 static void drawCursor(int ypos, boolean active)
1420 drawCursorExt(0, ypos, active, -1);
1423 static void drawCursorXY(int xpos, int ypos, int graphic)
1425 drawCursorExt(xpos, ypos, FALSE, graphic);
1428 static void drawChooseTreeCursor(int ypos, boolean active)
1430 drawCursorExt(0, ypos, active, -1);
1433 static void DrawHeadline(void)
1435 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1436 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1439 static void DrawTitleScreenImage(int nr, boolean initial)
1441 int graphic = getTitleScreenGraphic(nr, initial);
1442 Bitmap *bitmap = graphic_info[graphic].bitmap;
1443 int width = graphic_info[graphic].width;
1444 int height = graphic_info[graphic].height;
1445 int src_x = graphic_info[graphic].src_x;
1446 int src_y = graphic_info[graphic].src_y;
1452 if (width > WIN_XSIZE)
1454 // image width too large for window => center image horizontally
1455 src_x = (width - WIN_XSIZE) / 2;
1459 if (height > WIN_YSIZE)
1461 // image height too large for window => center image vertically
1462 src_y = (height - WIN_YSIZE) / 2;
1466 // always display title screens centered
1467 dst_x = (WIN_XSIZE - width) / 2;
1468 dst_y = (WIN_YSIZE - height) / 2;
1470 SetDrawBackgroundMask(REDRAW_ALL);
1471 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1473 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1475 if (DrawingOnBackground(dst_x, dst_y))
1476 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1478 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1480 redraw_mask = REDRAW_ALL;
1483 static void DrawTitleScreenMessage(int nr, boolean initial)
1485 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1486 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1488 if (filename == NULL)
1491 // force TITLE font on title message screen
1492 SetFontStatus(getTitleMessageGameMode(initial));
1494 // if chars *and* width set to "-1", automatically determine width
1495 if (tmi->chars == -1 && tmi->width == -1)
1496 tmi->width = viewport.window[game_status].width;
1498 // if lines *and* height set to "-1", automatically determine height
1499 if (tmi->lines == -1 && tmi->height == -1)
1500 tmi->height = viewport.window[game_status].height;
1502 // if chars set to "-1", automatically determine by text and font width
1503 if (tmi->chars == -1)
1504 tmi->chars = tmi->width / getFontWidth(tmi->font);
1506 tmi->width = tmi->chars * getFontWidth(tmi->font);
1508 // if lines set to "-1", automatically determine by text and font height
1509 if (tmi->lines == -1)
1510 tmi->lines = tmi->height / getFontHeight(tmi->font);
1512 tmi->height = tmi->lines * getFontHeight(tmi->font);
1514 // if x set to "-1", automatically determine by width and alignment
1516 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1518 // if y set to "-1", automatically determine by height and alignment
1520 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1522 SetDrawBackgroundMask(REDRAW_ALL);
1523 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1525 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1527 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1528 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1529 tmi->autowrap, tmi->centered, tmi->parse_comments);
1534 static void DrawTitleScreen(void)
1536 KeyboardAutoRepeatOff();
1538 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1541 static boolean CheckTitleScreen(boolean levelset_has_changed)
1543 static boolean show_title_initial = TRUE;
1544 boolean show_titlescreen = FALSE;
1546 // needed to be able to skip title screen, if no image or message defined
1547 InitializeTitleControls(show_title_initial);
1549 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1550 show_titlescreen = TRUE;
1552 // show initial title images and messages only once at program start
1553 show_title_initial = FALSE;
1555 return (show_titlescreen && num_title_screens > 0);
1558 void DrawMainMenu(void)
1560 static LevelDirTree *leveldir_last_valid = NULL;
1561 boolean levelset_has_changed = FALSE;
1562 int fade_mask = REDRAW_FIELD;
1564 LimitScreenUpdates(FALSE);
1566 FadeSetLeaveScreen();
1568 // do not fade out here -- function may continue and fade on editor screen
1571 FadeMenuSoundsAndMusic();
1573 ExpireSoundLoops(FALSE);
1575 KeyboardAutoRepeatOn();
1577 audio.sound_deactivated = FALSE;
1581 // needed if last screen was the playing screen, invoked from level editor
1582 if (level_editor_test_game)
1584 CloseDoor(DOOR_CLOSE_ALL);
1586 SetGameStatus(GAME_MODE_EDITOR);
1593 // leveldir_current may be invalid (level group, parent link)
1594 if (!validLevelSeries(leveldir_current))
1595 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1597 if (leveldir_current != leveldir_last_valid)
1598 levelset_has_changed = TRUE;
1600 // store valid level series information
1601 leveldir_last_valid = leveldir_current;
1603 init_last = init; // switch to new busy animation
1605 // needed if last screen (level choice) changed graphics, sounds or music
1606 ReloadCustomArtwork(0);
1608 if (CheckTitleScreen(levelset_has_changed))
1610 SetGameStatus(GAME_MODE_TITLE);
1617 if (redraw_mask & REDRAW_ALL)
1618 fade_mask = REDRAW_ALL;
1621 fade_mask = REDRAW_ALL;
1625 // needed if different viewport properties defined for menues
1626 ChangeViewportPropertiesIfNeeded();
1628 SetDrawtoField(DRAW_TO_BACKBUFFER);
1630 // level_nr may have been set to value over handicap with level editor
1631 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1632 level_nr = leveldir_current->handicap_level;
1634 LoadLevel(level_nr);
1635 LoadScore(level_nr);
1637 SaveLevelSetup_SeriesInfo();
1639 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1640 SetDrawDeactivationMask(REDRAW_NONE);
1641 SetDrawBackgroundMask(REDRAW_FIELD);
1643 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1646 if (fade_mask == REDRAW_ALL)
1647 RedrawGlobalBorder();
1652 InitializeMainControls();
1654 DrawCursorAndText_Main(-1, FALSE, FALSE);
1655 DrawPreviewLevelInitial();
1656 DrawNetworkPlayers();
1658 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1661 if (TAPE_IS_EMPTY(tape))
1663 DrawCompleteVideoDisplay();
1665 PlayMenuSoundsAndMusic();
1667 // create gadgets for main menu screen
1668 FreeScreenGadgets();
1669 CreateScreenGadgets();
1671 // may be required if audio buttons shown on tape and changed in setup menu
1673 CreateGameButtons();
1675 // map gadgets for main menu screen
1677 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1678 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1680 // copy actual game door content to door double buffer for OpenDoor()
1681 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1682 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1684 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1686 DrawMaskedBorder(fade_mask);
1691 // update screen area with special editor door
1692 redraw_mask |= REDRAW_ALL;
1695 SetMouseCursor(CURSOR_DEFAULT);
1697 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1700 static void gotoTopLevelDir(void)
1702 // move upwards until inside (but not above) top level directory
1703 while (leveldir_current->node_parent &&
1704 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1706 // write a "path" into level tree for easy navigation to last level
1707 if (leveldir_current->node_parent->node_group->cl_first == -1)
1709 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1710 int leveldir_pos = posTreeInfo(leveldir_current);
1711 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1712 int cl_first, cl_cursor;
1714 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1715 cl_cursor = leveldir_pos - cl_first;
1717 leveldir_current->node_parent->node_group->cl_first = cl_first;
1718 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1721 leveldir_current = leveldir_current->node_parent;
1725 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1727 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1729 return (use_frame_counter ? video.frame_counter : Counter());
1732 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1733 struct TitleFadingInfo *fi)
1735 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1738 static void ResetTitleAutoDelay(unsigned int *counter_var,
1739 struct TitleFadingInfo *fi)
1741 *counter_var = getAutoDelayCounter(fi);
1744 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1746 static unsigned int title_delay = 0;
1747 static int title_screen_nr = 0;
1748 static int last_sound = -1, last_music = -1;
1749 boolean return_to_main_menu = FALSE;
1750 struct TitleControlInfo *tci;
1753 if (button == MB_MENU_INITIALIZE)
1756 title_screen_nr = 0;
1757 tci = &title_controls[title_screen_nr];
1759 SetAnimStatus(getTitleAnimMode(tci));
1761 last_sound = SND_UNDEFINED;
1762 last_music = MUS_UNDEFINED;
1764 if (num_title_screens != 0)
1766 FadeSetEnterScreen();
1768 // use individual title fading instead of global "enter screen" fading
1769 fading = getTitleFading(tci);
1772 if (game_status_last_screen == GAME_MODE_INFO)
1774 if (num_title_screens == 0)
1776 // switch game mode from title screen mode back to info screen mode
1777 SetGameStatus(GAME_MODE_INFO);
1779 // store that last screen was info screen, not main menu screen
1780 game_status_last_screen = GAME_MODE_INFO;
1782 DrawInfoScreen_NotAvailable("Title screen information:",
1783 "No title screen for this level set.");
1788 FadeMenuSoundsAndMusic();
1790 FadeOut(REDRAW_ALL);
1792 // title screens may have different window size
1793 ChangeViewportPropertiesIfNeeded();
1795 // only required to update logic for redrawing global border
1799 DrawTitleScreenImage(tci->local_nr, tci->initial);
1801 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1803 sound = getTitleSound(tci);
1804 music = getTitleMusic(tci);
1806 if (sound != last_sound)
1807 PlayMenuSoundExt(sound);
1808 if (music != last_music)
1809 PlayMenuMusicExt(music);
1814 SetMouseCursor(CURSOR_NONE);
1818 ResetTitleAutoDelay(&title_delay, &fading);
1823 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1824 button = MB_MENU_CHOICE;
1826 if (button == MB_MENU_LEAVE)
1828 return_to_main_menu = TRUE;
1830 else if (button == MB_MENU_CHOICE)
1832 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1834 SetGameStatus(GAME_MODE_INFO);
1836 info_mode = INFO_MODE_MAIN;
1845 if (title_screen_nr < num_title_screens)
1847 tci = &title_controls[title_screen_nr];
1849 SetAnimStatus(getTitleAnimMode(tci));
1851 sound = getTitleSound(tci);
1852 music = getTitleMusic(tci);
1854 if (last_sound != SND_UNDEFINED && sound != last_sound)
1855 FadeSound(last_sound);
1856 if (last_music != MUS_UNDEFINED && music != last_music)
1859 fading = getTitleFading(tci);
1861 FadeOut(REDRAW_ALL);
1864 DrawTitleScreenImage(tci->local_nr, tci->initial);
1866 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1868 sound = getTitleSound(tci);
1869 music = getTitleMusic(tci);
1871 if (sound != last_sound)
1872 PlayMenuSoundExt(sound);
1873 if (music != last_music)
1874 PlayMenuMusicExt(music);
1881 ResetTitleAutoDelay(&title_delay, &fading);
1885 FadeMenuSoundsAndMusic();
1887 return_to_main_menu = TRUE;
1891 if (return_to_main_menu)
1893 SetMouseCursor(CURSOR_DEFAULT);
1895 // force full menu screen redraw after displaying title screens
1896 redraw_mask = REDRAW_ALL;
1898 if (game_status_last_screen == GAME_MODE_INFO)
1900 SetGameStatus(GAME_MODE_INFO);
1902 info_mode = INFO_MODE_MAIN;
1906 else // default: return to main menu
1908 SetGameStatus(GAME_MODE_MAIN);
1915 static void HandleMainMenu_SelectLevel(int step, int direction,
1916 int selected_level_nr)
1918 int old_level_nr = level_nr;
1921 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1922 new_level_nr = selected_level_nr;
1924 new_level_nr = old_level_nr + step * direction;
1926 if (new_level_nr < leveldir_current->first_level)
1927 new_level_nr = leveldir_current->first_level;
1928 if (new_level_nr > leveldir_current->last_level)
1929 new_level_nr = leveldir_current->last_level;
1931 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1933 // skipping levels is only allowed when trying to skip single level
1934 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1935 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1937 leveldir_current->handicap_level++;
1938 SaveLevelSetup_SeriesInfo();
1941 new_level_nr = leveldir_current->handicap_level;
1944 if (new_level_nr != old_level_nr)
1946 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1948 PlaySound(SND_MENU_ITEM_SELECTING);
1950 level_nr = new_level_nr;
1952 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1953 int2str(level_nr, menu.main.text.level_number.size),
1954 mci->pos_text->font);
1956 LoadLevel(level_nr);
1957 DrawPreviewLevelInitial();
1961 DrawCompleteVideoDisplay();
1963 SaveLevelSetup_SeriesInfo();
1965 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1967 // force redraw of playfield area (may be reset at this point)
1968 redraw_mask |= REDRAW_FIELD;
1972 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1974 static int choice = MAIN_CONTROL_GAME;
1975 static boolean button_pressed_last = FALSE;
1976 boolean button_pressed = FALSE;
1978 int i = 0; // needed to prevent compiler warning due to bad code below
1980 if (button == MB_MENU_INITIALIZE)
1982 DrawCursorAndText_Main(choice, TRUE, FALSE);
1987 if (mx || my) // mouse input
1991 for (i = 0; main_controls[i].nr != -1; i++)
1993 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1994 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1995 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1997 pos = main_controls[i].nr;
2003 // check if level preview was clicked
2004 if (insidePreviewRect(&preview, mx - SX, my - SY))
2005 pos = MAIN_CONTROL_GAME;
2007 // handle pressed/unpressed state for active/inactive menu buttons
2008 // (if pos != -1, "i" contains index position corresponding to "pos")
2010 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2011 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2012 button_pressed = TRUE;
2014 if (button_pressed != button_pressed_last)
2016 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2019 PlaySound(SND_MENU_BUTTON_PRESSING);
2021 PlaySound(SND_MENU_BUTTON_RELEASING);
2024 else if (dx || dy) // keyboard input
2026 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2027 choice == MAIN_CONTROL_SETUP))
2028 button = MB_MENU_CHOICE;
2033 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2035 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2037 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2039 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2041 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2043 CloseDoor(DOOR_CLOSE_2);
2045 SetGameStatus(GAME_MODE_LEVELNR);
2047 DrawChooseLevelNr();
2049 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2055 PlaySound(SND_MENU_ITEM_ACTIVATING);
2057 DrawCursorAndText_Main(choice, FALSE, FALSE);
2058 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2064 if (choice != MAIN_CONTROL_INFO &&
2065 choice != MAIN_CONTROL_SETUP)
2066 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2071 PlaySound(SND_MENU_ITEM_SELECTING);
2073 if (pos == MAIN_CONTROL_NAME)
2076 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2078 // special case: menu text "name/team" clicked -- toggle team mode
2079 setup.team_mode = !setup.team_mode;
2081 InitializeMainControls();
2082 DrawCursorAndText_Main(choice, TRUE, FALSE);
2084 DrawPreviewPlayers();
2088 if (0 && setup.multiple_users) // (not used yet)
2090 CloseDoor(DOOR_CLOSE_2);
2092 SetGameStatus(GAME_MODE_NAMES);
2094 DrawChoosePlayerName();
2098 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2104 else if (pos == MAIN_CONTROL_LEVELS)
2108 CloseDoor(DOOR_CLOSE_2);
2110 SetGameStatus(GAME_MODE_LEVELS);
2112 SaveLevelSetup_LastSeries();
2113 SaveLevelSetup_SeriesInfo();
2115 if (setup.internal.choose_from_top_leveldir)
2118 DrawChooseLevelSet();
2121 else if (pos == MAIN_CONTROL_SCORES)
2123 CloseDoor(DOOR_CLOSE_2);
2125 SetGameStatus(GAME_MODE_SCORES);
2127 DrawHallOfFame(level_nr, -1);
2129 else if (pos == MAIN_CONTROL_EDITOR)
2131 if (leveldir_current->readonly &&
2132 !strEqual(setup.player_name, "Artsoft"))
2133 Request("This level is read only!", REQ_CONFIRM);
2135 CloseDoor(DOOR_CLOSE_2);
2137 SetGameStatus(GAME_MODE_EDITOR);
2139 FadeSetEnterScreen();
2143 else if (pos == MAIN_CONTROL_INFO)
2145 CloseDoor(DOOR_CLOSE_2);
2147 SetGameStatus(GAME_MODE_INFO);
2149 info_mode = INFO_MODE_MAIN;
2153 else if (pos == MAIN_CONTROL_GAME)
2155 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2157 else if (pos == MAIN_CONTROL_SETUP)
2159 CloseDoor(DOOR_CLOSE_2);
2161 SetGameStatus(GAME_MODE_SETUP);
2163 setup_mode = SETUP_MODE_MAIN;
2167 else if (pos == MAIN_CONTROL_QUIT)
2169 SaveLevelSetup_LastSeries();
2170 SaveLevelSetup_SeriesInfo();
2172 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2173 SetGameStatus(GAME_MODE_QUIT);
2178 button_pressed_last = button_pressed;
2182 // ============================================================================
2183 // info screen functions
2184 // ============================================================================
2186 static struct TokenInfo *info_info;
2187 static int num_info_info; // number of info entries shown on screen
2188 static int max_info_info; // total number of info entries in list
2190 static void execInfoTitleScreen(void)
2192 info_mode = INFO_MODE_TITLE;
2197 static void execInfoElements(void)
2199 info_mode = INFO_MODE_ELEMENTS;
2204 static void execInfoMusic(void)
2206 info_mode = INFO_MODE_MUSIC;
2211 static void execInfoCredits(void)
2213 info_mode = INFO_MODE_CREDITS;
2218 static void execInfoProgram(void)
2220 info_mode = INFO_MODE_PROGRAM;
2225 static void execInfoVersion(void)
2227 info_mode = INFO_MODE_VERSION;
2232 static void execInfoLevelSet(void)
2234 info_mode = INFO_MODE_LEVELSET;
2239 static void execExitInfo(void)
2241 SetGameStatus(GAME_MODE_MAIN);
2246 static struct TokenInfo info_info_main[] =
2248 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2249 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2250 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2251 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2252 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2253 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2254 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2255 { TYPE_EMPTY, NULL, "" },
2256 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2261 static int getMenuTextFont(int type)
2263 if (type & (TYPE_SWITCH |
2277 static struct TokenInfo *setup_info;
2278 static struct TokenInfo setup_info_input[];
2280 static struct TokenInfo *menu_info;
2282 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2283 int screen_pos, int menu_info_pos_raw,
2286 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2287 struct TokenInfo *ti = &token_info[pos];
2288 int xpos = MENU_SCREEN_START_XPOS;
2289 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2290 int font_nr = getMenuTextFont(ti->type);
2292 if (setup_mode == SETUP_MODE_INPUT)
2293 font_nr = FONT_MENU_1;
2296 font_nr = FONT_ACTIVE(font_nr);
2298 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2300 if (ti->type & ~TYPE_SKIP_ENTRY)
2301 drawCursor(screen_pos, active);
2304 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2307 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2310 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2313 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2316 static char *window_size_text;
2317 static char *scaling_type_text;
2318 static char *network_server_text;
2320 static void drawSetupValue(int, int);
2322 static void drawMenuInfoList(int first_entry, int num_page_entries,
2323 int max_page_entries)
2327 if (first_entry + num_page_entries > max_page_entries)
2330 clearMenuListArea();
2332 for (i = 0; i < num_page_entries; i++)
2334 int menu_info_pos = first_entry + i;
2335 struct TokenInfo *si = &menu_info[menu_info_pos];
2336 void *value_ptr = si->value;
2338 // set some entries to "unchangeable" according to other variables
2339 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2340 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2341 (value_ptr == &setup.sound_music && !audio.music_available) ||
2342 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2343 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2344 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2345 si->type |= TYPE_GHOSTED;
2347 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2348 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2349 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2350 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2351 else if (si->type & ~TYPE_SKIP_ENTRY)
2352 initCursor(i, IMG_MENU_BUTTON);
2354 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2356 if (si->type & TYPE_STRING)
2360 if (value_ptr == &network_server_text)
2361 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2363 if (gadget_id != -1)
2365 struct GadgetInfo *gi = screen_gadget[gadget_id];
2366 int xpos = MENU_SCREEN_START_XPOS;
2367 int ypos = MENU_SCREEN_START_YPOS + i;
2368 int x = mSX + xpos * 32;
2369 int y = mSY + ypos * 32;
2371 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2375 if (si->type & TYPE_VALUE &&
2376 menu_info == setup_info)
2377 drawSetupValue(i, menu_info_pos);
2381 static void DrawInfoScreen_Main(void)
2383 int fade_mask = REDRAW_FIELD;
2386 if (redraw_mask & REDRAW_ALL)
2387 fade_mask = REDRAW_ALL;
2390 fade_mask = REDRAW_ALL;
2393 FadeMenuSoundsAndMusic();
2395 FreeScreenGadgets();
2396 CreateScreenGadgets();
2398 // (needed after displaying title screens which disable auto repeat)
2399 KeyboardAutoRepeatOn();
2401 FadeSetLeaveScreen();
2405 // needed if different viewport properties defined for info screen
2406 ChangeViewportPropertiesIfNeeded();
2408 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2412 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2414 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2416 info_info = info_info_main;
2418 // determine maximal number of info entries that can be displayed on screen
2420 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2423 // determine maximal number of info entries available for menu of info screen
2425 for (i = 0; info_info[i].type != 0; i++)
2428 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2430 MapScreenGadgets(max_info_info);
2432 PlayMenuSoundsAndMusic();
2434 DrawMaskedBorder(fade_mask);
2439 static void changeSetupValue(int, int, int);
2441 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2442 int mode, int num_page_entries,
2443 int max_page_entries)
2445 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2446 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2447 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2448 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2449 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2450 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2451 int *num_page_entries_last = num_page_entries_all_last[game_status];
2452 int *choice_store = choice_stores[game_status];
2453 int *first_entry_store = first_entry_stores[game_status];
2454 int choice = choice_store[mode]; // starts with 0
2455 int first_entry = first_entry_store[mode]; // starts with 0
2457 int y = choice - first_entry;
2459 boolean position_set_by_scrollbar = (dx == 999);
2460 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2463 if (button == MB_MENU_INITIALIZE)
2465 // check if number of menu page entries has changed (may happen by change
2466 // of custom artwork definition value for 'list_size' for this menu screen)
2467 // (in this case, the last menu position most probably has to be corrected)
2468 if (num_page_entries != num_page_entries_last[mode])
2470 choice_store[mode] = first_entry_store[mode] = 0;
2472 choice = first_entry = 0;
2475 num_page_entries_last[mode] = num_page_entries;
2478 // advance to first valid menu entry
2479 while (choice < num_page_entries &&
2480 menu_info[choice].type & TYPE_SKIP_ENTRY)
2483 if (position_set_by_scrollbar)
2484 first_entry = first_entry_store[mode] = dy;
2486 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2487 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2489 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2491 if (choice < first_entry)
2493 choice = first_entry;
2495 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2498 else if (choice > first_entry + num_page_entries - 1)
2500 choice = first_entry + num_page_entries - 1;
2502 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2506 choice_store[mode] = choice;
2508 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2512 else if (button == MB_MENU_LEAVE)
2514 PlaySound(SND_MENU_ITEM_SELECTING);
2516 for (i = 0; i < max_page_entries; i++)
2518 if (menu_info[i].type & TYPE_LEAVE_MENU)
2520 void (*menu_callback_function)(void) = menu_info[i].value;
2524 menu_callback_function();
2526 break; // absolutely needed because function changes 'menu_info'!
2533 if (mx || my) // mouse input
2535 x = (mx - mSX) / 32;
2536 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2538 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2540 // move cursor instead of scrolling when already at start/end of list
2541 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2543 else if (dy == +1 * SCROLL_LINE &&
2544 first_entry + num_page_entries == max_page_entries)
2547 // handle scrolling screen one line or page
2549 y + dy > num_page_entries - 1)
2551 boolean redraw = FALSE;
2553 if (ABS(dy) == SCROLL_PAGE)
2554 step = num_page_entries - 1;
2556 if (dy < 0 && first_entry > 0)
2558 // scroll page/line up
2560 first_entry -= step;
2561 if (first_entry < 0)
2566 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2568 // scroll page/line down
2570 first_entry += step;
2571 if (first_entry + num_page_entries > max_page_entries)
2572 first_entry = MAX(0, max_page_entries - num_page_entries);
2579 choice += first_entry - first_entry_store[mode];
2581 if (choice < first_entry)
2583 choice = first_entry;
2585 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2588 else if (choice > first_entry + num_page_entries - 1)
2590 choice = first_entry + num_page_entries - 1;
2592 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2595 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2599 if (choice < first_entry ||
2600 choice > first_entry + num_page_entries - 1)
2601 first_entry += SIGN(dy);
2604 first_entry_store[mode] = first_entry;
2605 choice_store[mode] = choice;
2607 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2609 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2611 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2612 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2620 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2622 if (menu_info[choice].type & menu_navigation_type ||
2623 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2624 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2625 menu_info[choice].type & TYPE_PLAYER)
2626 button = MB_MENU_CHOICE;
2631 // jump to next non-empty menu entry (up or down)
2632 while (first_entry + y > 0 &&
2633 first_entry + y < max_page_entries - 1 &&
2634 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2637 if (!IN_VIS_MENU(x, y))
2639 choice += y - y_old;
2641 if (choice < first_entry)
2642 first_entry = choice;
2643 else if (choice > first_entry + num_page_entries - 1)
2644 first_entry = choice - num_page_entries + 1;
2646 if (first_entry >= 0 &&
2647 first_entry + num_page_entries <= max_page_entries)
2649 first_entry_store[mode] = first_entry;
2651 if (choice < first_entry)
2652 choice = first_entry;
2653 else if (choice > first_entry + num_page_entries - 1)
2654 choice = first_entry + num_page_entries - 1;
2656 choice_store[mode] = choice;
2658 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2660 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2662 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2663 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2670 if (!anyScrollbarGadgetActive() &&
2671 IN_VIS_MENU(x, y) &&
2672 mx < mx_right_border &&
2673 y >= 0 && y < num_page_entries)
2677 if (first_entry + y != choice &&
2678 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2680 PlaySound(SND_MENU_ITEM_ACTIVATING);
2682 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2683 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2685 choice = choice_store[mode] = first_entry + y;
2689 PlaySound(SND_MENU_ITEM_SELECTING);
2691 for (i = 0; menu_info[i].type != 0; i++)
2693 if (menu_info[i].type & TYPE_LEAVE_MENU)
2695 void (*menu_callback_function)(void) = menu_info[i].value;
2699 menu_callback_function();
2701 // absolutely needed because function changes 'menu_info'!
2709 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2711 PlaySound(SND_MENU_ITEM_SELECTING);
2713 // when selecting key headline, execute function for key value change
2714 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2715 menu_info[first_entry + y + 1].type & TYPE_KEY)
2718 // when selecting string value, execute function for list selection
2719 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2720 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2723 // when selecting string value, execute function for text input gadget
2724 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2725 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2728 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2730 void (*menu_callback_function)(void) =
2731 menu_info[first_entry + y].value;
2733 FadeSetFromType(menu_info[first_entry + y].type);
2735 menu_callback_function();
2737 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2739 void (*gadget_callback_function)(void) =
2740 menu_info[first_entry + y].value;
2742 gadget_callback_function();
2744 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2745 menu_info == setup_info)
2747 changeSetupValue(y, first_entry + y, dx);
2753 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2755 menu_info = info_info;
2757 HandleMenuScreen(mx, my, dx, dy, button,
2758 info_mode, num_info_info, max_info_info);
2761 static int getMenuFontSpacing(int spacing_height, int font_nr)
2763 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2765 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2769 static int getMenuTextSpacing(int spacing_height, int font_nr)
2771 return (getMenuFontSpacing(spacing_height, font_nr) +
2772 EXTRA_SPACING(game_status));
2775 static int getMenuTextStep(int spacing_height, int font_nr)
2777 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2780 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2782 int font_title = MENU_INFO_FONT_TITLE;
2783 int font_error = FONT_TEXT_2;
2784 int font_foot = MENU_INFO_FONT_FOOT;
2785 int spacing_title = menu.headline1_spacing_info[info_mode];
2786 int ystep_title = getMenuTextStep(spacing_title, font_title);
2787 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2788 int ystart2 = ystart1 + ystep_title;
2789 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2791 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2793 FadeOut(REDRAW_FIELD);
2798 DrawTextSCentered(ystart1, font_title, text_title);
2799 DrawTextSCentered(ystart2, font_error, text_error);
2801 DrawTextSCentered(ybottom, font_foot,
2802 "Press any key or button for info menu");
2804 FadeIn(REDRAW_FIELD);
2807 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2809 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2810 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2811 int font_title = MENU_INFO_FONT_TITLE;
2812 int font_foot = MENU_INFO_FONT_FOOT;
2813 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2814 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2815 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2816 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2817 int ystep = MENU_SCREEN_INFO_YSTEP;
2818 int element, action, direction;
2826 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2827 infoscreen_step[i] = infoscreen_frame[i] = 0;
2832 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2834 DrawTextSCentered(ybottom, font_foot,
2835 "Press any key or button for next page");
2841 while (helpanim_info[j].element != HELPANIM_LIST_END)
2843 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2848 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2857 j += infoscreen_step[i - start];
2859 element = helpanim_info[j].element;
2860 action = helpanim_info[j].action;
2861 direction = helpanim_info[j].direction;
2864 element = EL_UNKNOWN;
2866 if (action != -1 && direction != -1)
2867 graphic = el_act_dir2img(element, action, direction);
2868 else if (action != -1)
2869 graphic = el_act2img(element, action);
2870 else if (direction != -1)
2871 graphic = el_dir2img(element, direction);
2873 graphic = el2img(element);
2875 delay = helpanim_info[j++].delay;
2880 if (infoscreen_frame[i - start] == 0)
2883 infoscreen_frame[i - start] = delay - 1;
2887 sync_frame = delay - infoscreen_frame[i - start];
2888 infoscreen_frame[i - start]--;
2891 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2893 if (!infoscreen_frame[i - start])
2894 infoscreen_step[i - start] = 0;
2898 if (!infoscreen_frame[i - start])
2899 infoscreen_step[i - start]++;
2900 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2906 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2908 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2909 graphic, sync_frame, USE_MASKING);
2912 DrawInfoScreen_HelpText(element, action, direction, i - start);
2917 redraw_mask |= REDRAW_FIELD;
2922 static char *getHelpText(int element, int action, int direction)
2924 char token[MAX_LINE_LEN];
2926 strcpy(token, element_info[element].token_name);
2929 strcat(token, element_action_info[action].suffix);
2931 if (direction != -1)
2932 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2934 return getHashEntry(helptext_info, token);
2937 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2939 int font_nr = FONT_INFO_ELEMENTS;
2940 int font_width = getFontWidth(font_nr);
2941 int font_height = getFontHeight(font_nr);
2942 int yoffset = (TILEX - 2 * font_height) / 2;
2943 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2944 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2945 int ystep = TILEY + 4;
2946 int pad_left = xstart - SX;
2947 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2948 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2949 int max_lines_per_text = 2;
2952 if (action != -1 && direction != -1) // element.action.direction
2953 text = getHelpText(element, action, direction);
2955 if (text == NULL && action != -1) // element.action
2956 text = getHelpText(element, action, -1);
2958 if (text == NULL && direction != -1) // element.direction
2959 text = getHelpText(element, -1, direction);
2961 if (text == NULL) // base element
2962 text = getHelpText(element, -1, -1);
2964 if (text == NULL) // not found
2965 text = "No description available";
2967 if (strlen(text) <= max_chars_per_line) // only one line of text
2968 ystart += getFontHeight(font_nr) / 2;
2970 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2971 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2972 TRUE, FALSE, FALSE);
2975 static void DrawInfoScreen_TitleScreen(void)
2977 SetGameStatus(GAME_MODE_TITLE);
2982 void HandleInfoScreen_TitleScreen(int button)
2984 HandleTitleScreen(0, 0, 0, 0, button);
2987 static void DrawInfoScreen_Elements(void)
2989 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2991 FadeOut(REDRAW_FIELD);
2996 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2998 FadeIn(REDRAW_FIELD);
3001 void HandleInfoScreen_Elements(int button)
3003 static unsigned int info_delay = 0;
3004 static int num_anims;
3005 static int num_pages;
3007 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3010 if (button == MB_MENU_INITIALIZE)
3012 boolean new_element = TRUE;
3016 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3018 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3020 else if (new_element)
3023 new_element = FALSE;
3027 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3031 if (button == MB_MENU_LEAVE)
3033 PlaySound(SND_MENU_ITEM_SELECTING);
3035 info_mode = INFO_MODE_MAIN;
3040 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3042 if (button != MB_MENU_INITIALIZE)
3044 PlaySound(SND_MENU_ITEM_SELECTING);
3049 if (page >= num_pages)
3051 FadeMenuSoundsAndMusic();
3053 info_mode = INFO_MODE_MAIN;
3060 FadeSetNextScreen();
3062 if (button != MB_MENU_INITIALIZE)
3063 FadeOut(REDRAW_FIELD);
3065 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3067 if (button != MB_MENU_INITIALIZE)
3068 FadeIn(REDRAW_FIELD);
3072 if (DelayReached(&info_delay, GameFrameDelay))
3073 if (page < num_pages)
3074 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3076 PlayMenuSoundIfLoop();
3080 static void DrawInfoScreen_Music(void)
3082 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3084 FadeOut(REDRAW_FIELD);
3091 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3093 FadeIn(REDRAW_FIELD);
3096 void HandleInfoScreen_Music(int button)
3098 static struct MusicFileInfo *list = NULL;
3099 int font_title = MENU_INFO_FONT_TITLE;
3100 int font_head = MENU_INFO_FONT_HEAD;
3101 int font_text = MENU_INFO_FONT_TEXT;
3102 int font_foot = MENU_INFO_FONT_FOOT;
3103 int spacing_title = menu.headline1_spacing_info[info_mode];
3104 int spacing_head = menu.headline2_spacing_info[info_mode];
3105 int ystep_title = getMenuTextStep(spacing_title, font_title);
3106 int ystep_head = getMenuTextStep(spacing_head, font_head);
3107 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3108 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3110 if (button == MB_MENU_INITIALIZE)
3112 list = music_file_info;
3116 FadeMenuSoundsAndMusic();
3121 DrawTextSCentered(ystart, font_title,
3122 "No music info for this level set.");
3124 DrawTextSCentered(ybottom, font_foot,
3125 "Press any key or button for info menu");
3131 if (button == MB_MENU_LEAVE)
3133 PlaySound(SND_MENU_ITEM_SELECTING);
3135 FadeMenuSoundsAndMusic();
3137 info_mode = INFO_MODE_MAIN;
3142 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3144 if (button != MB_MENU_INITIALIZE)
3146 PlaySound(SND_MENU_ITEM_SELECTING);
3154 FadeMenuSoundsAndMusic();
3156 info_mode = INFO_MODE_MAIN;
3162 FadeMenuSoundsAndMusic();
3164 if (list != music_file_info)
3165 FadeSetNextScreen();
3167 if (button != MB_MENU_INITIALIZE)
3168 FadeOut(REDRAW_FIELD);
3175 int sound = list->music;
3177 if (sound_info[sound].loop)
3178 PlaySoundLoop(sound);
3182 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3186 int music = list->music;
3188 if (music_info[music].loop)
3189 PlayMusicLoop(music);
3193 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3196 ystart += ystep_title;
3198 if (!strEqual(list->title, UNKNOWN_NAME))
3200 if (!strEqual(list->title_header, UNKNOWN_NAME))
3202 DrawTextSCentered(ystart, font_head, list->title_header);
3203 ystart += ystep_head;
3206 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3207 ystart += ystep_head;
3210 if (!strEqual(list->artist, UNKNOWN_NAME))
3212 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3213 DrawTextSCentered(ystart, font_head, list->artist_header);
3215 DrawTextSCentered(ystart, font_head, "by");
3217 ystart += ystep_head;
3219 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3220 ystart += ystep_head;
3223 if (!strEqual(list->album, UNKNOWN_NAME))
3225 if (!strEqual(list->album_header, UNKNOWN_NAME))
3226 DrawTextSCentered(ystart, font_head, list->album_header);
3228 DrawTextSCentered(ystart, font_head, "from the album");
3230 ystart += ystep_head;
3232 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3233 ystart += ystep_head;
3236 if (!strEqual(list->year, UNKNOWN_NAME))
3238 if (!strEqual(list->year_header, UNKNOWN_NAME))
3239 DrawTextSCentered(ystart, font_head, list->year_header);
3241 DrawTextSCentered(ystart, font_head, "from the year");
3243 ystart += ystep_head;
3245 DrawTextFCentered(ystart, font_text, "%s", list->year);
3246 ystart += ystep_head;
3249 DrawTextSCentered(ybottom, FONT_TEXT_4,
3250 "Press any key or button for next page");
3252 if (button != MB_MENU_INITIALIZE)
3253 FadeIn(REDRAW_FIELD);
3256 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3257 PlaySoundLoop(list->music);
3260 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3262 int font_title = MENU_INFO_FONT_TITLE;
3263 int font_head = MENU_INFO_FONT_HEAD;
3264 int font_text = MENU_INFO_FONT_TEXT;
3265 int font_foot = MENU_INFO_FONT_FOOT;
3266 int spacing_title = menu.headline1_spacing_info[info_mode];
3267 int spacing_head = menu.headline2_spacing_info[info_mode];
3268 int spacing_para = menu.paragraph_spacing_info[info_mode];
3269 int spacing_line = menu.line_spacing_info[info_mode];
3270 int ystep_title = getMenuTextStep(spacing_title, font_title);
3271 int ystep_head = getMenuTextStep(spacing_head, font_head);
3272 int ystep_para = getMenuTextStep(spacing_para, font_text);
3273 int ystep_line = getMenuTextStep(spacing_line, font_text);
3274 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3275 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3280 DrawTextSCentered(ystart, font_title, "Credits:");
3281 ystart += ystep_title;
3285 DrawTextSCentered(ystart, font_head,
3286 "Special thanks to");
3287 ystart += ystep_head;
3288 DrawTextSCentered(ystart, font_text,
3290 ystart += ystep_head;
3291 DrawTextSCentered(ystart, font_head,
3293 ystart += ystep_head;
3294 DrawTextSCentered(ystart, font_text,
3295 "\"Boulder Dash\"");
3296 ystart += ystep_head;
3297 DrawTextSCentered(ystart, font_head,
3299 ystart += ystep_head;
3300 DrawTextSCentered(ystart, font_text,
3302 ystart += ystep_head;
3303 DrawTextSCentered(ystart, font_head,
3305 ystart += ystep_head;
3306 DrawTextSCentered(ystart, font_text,
3307 "First Star Software");
3309 else if (screen_nr == 1)
3311 DrawTextSCentered(ystart, font_head,
3312 "Special thanks to");
3313 ystart += ystep_head;
3314 DrawTextSCentered(ystart, font_text,
3315 "Klaus Heinz & Volker Wertich");
3316 ystart += ystep_head;
3317 DrawTextSCentered(ystart, font_head,
3319 ystart += ystep_head;
3320 DrawTextSCentered(ystart, font_text,
3321 "\"Emerald Mine\"");
3322 ystart += ystep_head;
3323 DrawTextSCentered(ystart, font_head,
3325 ystart += ystep_head;
3326 DrawTextSCentered(ystart, font_text,
3328 ystart += ystep_head;
3329 DrawTextSCentered(ystart, font_head,
3331 ystart += ystep_head;
3332 DrawTextSCentered(ystart, font_text,
3335 else if (screen_nr == 2)
3337 DrawTextSCentered(ystart, font_head,
3338 "Special thanks to");
3339 ystart += ystep_head;
3340 DrawTextSCentered(ystart, font_text,
3341 "Michael Stopp & Philip Jespersen");
3342 ystart += ystep_head;
3343 DrawTextSCentered(ystart, font_head,
3345 ystart += ystep_head;
3346 DrawTextSCentered(ystart, font_text,
3348 ystart += ystep_head;
3349 DrawTextSCentered(ystart, font_head,
3351 ystart += ystep_head;
3352 DrawTextSCentered(ystart, font_text,
3354 ystart += ystep_head;
3355 DrawTextSCentered(ystart, font_head,
3357 ystart += ystep_head;
3358 DrawTextSCentered(ystart, font_text,
3359 "Digital Integration");
3361 else if (screen_nr == 3)
3363 DrawTextSCentered(ystart, font_head,
3364 "Special thanks to");
3365 ystart += ystep_head;
3366 DrawTextSCentered(ystart, font_text,
3367 "Hiroyuki Imabayashi");
3368 ystart += ystep_head;
3369 DrawTextSCentered(ystart, font_head,
3371 ystart += ystep_head;
3372 DrawTextSCentered(ystart, font_text,
3374 ystart += ystep_head;
3375 DrawTextSCentered(ystart, font_head,
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_text,
3380 ystart += ystep_head;
3381 DrawTextSCentered(ystart, font_head,
3383 ystart += ystep_head;
3384 DrawTextSCentered(ystart, font_text,
3387 else if (screen_nr == 4)
3389 DrawTextSCentered(ystart, font_head,
3390 "Special thanks to");
3391 ystart += ystep_head;
3392 DrawTextSCentered(ystart, font_text,
3394 ystart += ystep_head;
3395 DrawTextSCentered(ystart, font_head,
3397 ystart += ystep_head;
3398 DrawTextSCentered(ystart, font_text,
3399 "J\xfcrgen Bonhagen");
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_head,
3402 "for the continuous creation");
3403 ystart += ystep_line;
3404 DrawTextSCentered(ystart, font_head,
3405 "of outstanding level sets");
3407 else if (screen_nr == 5)
3409 DrawTextSCentered(ystart, font_head,
3411 ystart += ystep_head;
3412 DrawTextSCentered(ystart, font_text,
3414 ystart += ystep_head;
3415 DrawTextSCentered(ystart, font_head,
3416 "for ideas and inspiration by");
3417 ystart += ystep_head;
3418 DrawTextSCentered(ystart, font_text,
3420 ystart += ystep_para;
3422 DrawTextSCentered(ystart, font_head,
3424 ystart += ystep_head;
3425 DrawTextSCentered(ystart, font_text,
3427 ystart += ystep_head;
3428 DrawTextSCentered(ystart, font_head,
3429 "for ideas and inspiration by");
3430 ystart += ystep_head;
3431 DrawTextSCentered(ystart, font_text,
3434 else if (screen_nr == 6)
3436 DrawTextSCentered(ystart, font_head,
3438 ystart += ystep_head;
3439 DrawTextSCentered(ystart, font_text,
3441 ystart += ystep_head;
3442 DrawTextSCentered(ystart, font_head,
3443 "for the code base used for the");
3444 ystart += ystep_line;
3445 DrawTextSCentered(ystart, font_head,
3446 "native Emerald Mine engine");
3448 else if (screen_nr == 7)
3450 DrawTextSCentered(ystart, font_head,
3452 ystart += ystep_head;
3453 DrawTextSCentered(ystart, font_text,
3455 ystart += ystep_head;
3456 DrawTextSCentered(ystart, font_head,
3457 "for the initial DOS port");
3458 ystart += ystep_para;
3460 DrawTextSCentered(ystart, font_head,
3462 ystart += ystep_head;
3463 DrawTextSCentered(ystart, font_text,
3465 ystart += ystep_head;
3466 DrawTextSCentered(ystart, font_head,
3467 "for some additional toons");
3469 else if (screen_nr == 8)
3471 DrawTextSCentered(ystart, font_head,
3472 "And not to forget:");
3473 ystart += ystep_head;
3474 DrawTextSCentered(ystart, font_head,
3476 ystart += ystep_head;
3477 DrawTextSCentered(ystart, font_text,
3478 "All those who contributed");
3479 ystart += ystep_line;
3480 DrawTextSCentered(ystart, font_text,
3481 "levels to this game");
3482 ystart += ystep_line;
3483 DrawTextSCentered(ystart, font_text,
3487 DrawTextSCentered(ybottom, font_foot,
3488 "Press any key or button for next page");
3491 static void DrawInfoScreen_Credits(void)
3493 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3495 FadeMenuSoundsAndMusic();
3497 FadeOut(REDRAW_FIELD);
3499 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3501 FadeIn(REDRAW_FIELD);
3504 void HandleInfoScreen_Credits(int button)
3506 static int screen_nr = 0;
3507 int num_screens = 9;
3509 if (button == MB_MENU_INITIALIZE)
3513 // DrawInfoScreen_CreditsScreen(screen_nr);
3516 if (button == MB_MENU_LEAVE)
3518 PlaySound(SND_MENU_ITEM_SELECTING);
3520 info_mode = INFO_MODE_MAIN;
3525 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3527 if (button != MB_MENU_INITIALIZE)
3529 PlaySound(SND_MENU_ITEM_SELECTING);
3534 if (screen_nr >= num_screens)
3536 FadeMenuSoundsAndMusic();
3538 info_mode = INFO_MODE_MAIN;
3545 FadeSetNextScreen();
3547 if (button != MB_MENU_INITIALIZE)
3548 FadeOut(REDRAW_FIELD);
3550 DrawInfoScreen_CreditsScreen(screen_nr);
3552 if (button != MB_MENU_INITIALIZE)
3553 FadeIn(REDRAW_FIELD);
3557 PlayMenuSoundIfLoop();
3561 static void DrawInfoScreen_Program(void)
3563 int font_title = MENU_INFO_FONT_TITLE;
3564 int font_head = MENU_INFO_FONT_HEAD;
3565 int font_text = MENU_INFO_FONT_TEXT;
3566 int font_foot = MENU_INFO_FONT_FOOT;
3567 int spacing_title = menu.headline1_spacing_info[info_mode];
3568 int spacing_head = menu.headline2_spacing_info[info_mode];
3569 int spacing_para = menu.paragraph_spacing_info[info_mode];
3570 int spacing_line = menu.line_spacing_info[info_mode];
3571 int ystep_title = getMenuTextStep(spacing_title, font_title);
3572 int ystep_head = getMenuTextStep(spacing_head, font_head);
3573 int ystep_para = getMenuTextStep(spacing_para, font_text);
3574 int ystep_line = getMenuTextStep(spacing_line, font_text);
3575 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3576 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3578 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3580 FadeOut(REDRAW_FIELD);
3585 DrawTextSCentered(ystart, font_title, "Program Information:");
3586 ystart += ystep_title;
3588 DrawTextSCentered(ystart, font_head,
3589 "This game is Freeware!");
3590 ystart += ystep_head;
3591 DrawTextSCentered(ystart, font_head,
3592 "If you like it, send e-mail to:");
3593 ystart += ystep_head;
3594 DrawTextSCentered(ystart, font_text,
3595 setup.internal.program_email);
3596 ystart += ystep_para;
3598 DrawTextSCentered(ystart, font_head,
3599 "More information and levels:");
3600 ystart += ystep_head;
3601 DrawTextSCentered(ystart, font_text,
3602 setup.internal.program_website);
3603 ystart += ystep_para;
3605 DrawTextSCentered(ystart, font_head,
3606 "If you have created new levels,");
3607 ystart += ystep_line;
3608 DrawTextSCentered(ystart, font_head,
3609 "send them to me to include them!");
3610 ystart += ystep_head;
3611 DrawTextSCentered(ystart, font_head,
3614 DrawTextSCentered(ybottom, font_foot,
3615 "Press any key or button for info menu");
3617 FadeIn(REDRAW_FIELD);
3620 void HandleInfoScreen_Program(int button)
3622 if (button == MB_MENU_LEAVE)
3624 PlaySound(SND_MENU_ITEM_SELECTING);
3626 info_mode = INFO_MODE_MAIN;
3631 else if (button == MB_MENU_CHOICE)
3633 PlaySound(SND_MENU_ITEM_SELECTING);
3635 FadeMenuSoundsAndMusic();
3637 info_mode = INFO_MODE_MAIN;
3642 PlayMenuSoundIfLoop();
3646 static void DrawInfoScreen_Version(void)
3648 int font_title = MENU_INFO_FONT_TITLE;
3649 int font_head = MENU_INFO_FONT_HEAD;
3650 int font_text = MENU_INFO_FONT_TEXT;
3651 int font_foot = MENU_INFO_FONT_FOOT;
3652 int spacing_title = menu.headline1_spacing_info[info_mode];
3653 int spacing_head = menu.headline2_spacing_info[info_mode];
3654 int spacing_para = menu.paragraph_spacing_info[info_mode];
3655 int spacing_line = menu.line_spacing_info[info_mode];
3656 int xstep = getFontWidth(font_text);
3657 int ystep_title = getMenuTextStep(spacing_title, font_title);
3658 int ystep_head = getMenuTextStep(spacing_head, font_head);
3659 int ystep_para = getMenuTextStep(spacing_para, font_text);
3660 int ystep_line = getMenuTextStep(spacing_line, font_text);
3661 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3662 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3663 int xstart1 = mSX - SX + 2 * xstep;
3664 int xstart2 = mSX - SX + 18 * xstep;
3665 int xstart3 = mSX - SX + 28 * xstep;
3666 SDL_version sdl_version_compiled;
3667 const SDL_version *sdl_version_linked;
3668 int driver_name_len = 10;
3669 SDL_version sdl_version_linked_ext;
3670 const char *driver_name = NULL;
3672 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3674 FadeOut(REDRAW_FIELD);
3679 DrawTextSCentered(ystart, font_title, "Version Information:");
3680 ystart += ystep_title;
3682 DrawTextF(xstart1, ystart, font_head, "Name");
3683 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3684 ystart += ystep_line;
3686 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3688 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3689 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3690 ystart += ystep_line;
3692 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3693 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3694 ystart += ystep_line;
3698 DrawTextF(xstart1, ystart, font_head, "Version");
3699 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3700 ystart += ystep_line;
3703 DrawTextF(xstart1, ystart, font_head, "Platform");
3704 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3706 PLATFORM_XX_BIT_STRING);
3707 ystart += ystep_line;
3709 DrawTextF(xstart1, ystart, font_head, "Target");
3710 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3711 ystart += ystep_line;
3713 DrawTextF(xstart1, ystart, font_head, "Source date");
3714 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3715 ystart += ystep_line;
3717 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3718 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3719 ystart += ystep_para;
3721 DrawTextF(xstart1, ystart, font_head, "Library");
3722 DrawTextF(xstart2, ystart, font_head, "compiled");
3723 DrawTextF(xstart3, ystart, font_head, "linked");
3724 ystart += ystep_head;
3726 SDL_VERSION(&sdl_version_compiled);
3727 SDL_GetVersion(&sdl_version_linked_ext);
3728 sdl_version_linked = &sdl_version_linked_ext;
3730 DrawTextF(xstart1, ystart, font_text, "SDL");
3731 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3732 sdl_version_compiled.major,
3733 sdl_version_compiled.minor,
3734 sdl_version_compiled.patch);
3735 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3736 sdl_version_linked->major,
3737 sdl_version_linked->minor,
3738 sdl_version_linked->patch);
3739 ystart += ystep_line;
3741 SDL_IMAGE_VERSION(&sdl_version_compiled);
3742 sdl_version_linked = IMG_Linked_Version();
3744 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3745 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3746 sdl_version_compiled.major,
3747 sdl_version_compiled.minor,
3748 sdl_version_compiled.patch);
3749 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3750 sdl_version_linked->major,
3751 sdl_version_linked->minor,
3752 sdl_version_linked->patch);
3753 ystart += ystep_line;
3755 SDL_MIXER_VERSION(&sdl_version_compiled);
3756 sdl_version_linked = Mix_Linked_Version();
3758 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3759 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3760 sdl_version_compiled.major,
3761 sdl_version_compiled.minor,
3762 sdl_version_compiled.patch);
3763 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3764 sdl_version_linked->major,
3765 sdl_version_linked->minor,
3766 sdl_version_linked->patch);
3767 ystart += ystep_line;
3769 SDL_NET_VERSION(&sdl_version_compiled);
3770 sdl_version_linked = SDLNet_Linked_Version();
3772 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3773 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3774 sdl_version_compiled.major,
3775 sdl_version_compiled.minor,
3776 sdl_version_compiled.patch);
3777 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3778 sdl_version_linked->major,
3779 sdl_version_linked->minor,
3780 sdl_version_linked->patch);
3781 ystart += ystep_para;
3783 DrawTextF(xstart1, ystart, font_head, "Driver");
3784 DrawTextF(xstart2, ystart, font_head, "Requested");
3785 DrawTextF(xstart3, ystart, font_head, "Used");
3786 ystart += ystep_head;
3789 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3791 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3792 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3793 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3794 ystart += ystep_line;
3797 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3799 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3800 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3801 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3802 ystart += ystep_line;
3805 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3807 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3808 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3809 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3811 DrawTextSCentered(ybottom, font_foot,
3812 "Press any key or button for info menu");
3814 FadeIn(REDRAW_FIELD);
3817 void HandleInfoScreen_Version(int button)
3819 if (button == MB_MENU_LEAVE)
3821 PlaySound(SND_MENU_ITEM_SELECTING);
3823 info_mode = INFO_MODE_MAIN;
3828 else if (button == MB_MENU_CHOICE)
3830 PlaySound(SND_MENU_ITEM_SELECTING);
3832 FadeMenuSoundsAndMusic();
3834 info_mode = INFO_MODE_MAIN;
3839 PlayMenuSoundIfLoop();
3843 static void DrawInfoScreen_LevelSet(void)
3845 struct TitleMessageInfo *tmi = &readme;
3846 char *filename = getLevelSetInfoFilename();
3847 char *title = "Level Set Information:";
3848 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3849 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3851 if (filename == NULL)
3853 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3858 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3860 FadeOut(REDRAW_FIELD);
3865 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3867 // if x position set to "-1", automatically determine by playfield width
3869 tmi->x = SXSIZE / 2;
3871 // if y position set to "-1", use static default value
3875 // if width set to "-1", automatically determine by playfield width
3876 if (tmi->width == -1)
3877 tmi->width = SXSIZE - 2 * TILEX;
3879 // if height set to "-1", automatically determine by playfield height
3880 if (tmi->height == -1)
3881 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3883 // if chars set to "-1", automatically determine by text and font width
3884 if (tmi->chars == -1)
3885 tmi->chars = tmi->width / getFontWidth(tmi->font);
3887 tmi->width = tmi->chars * getFontWidth(tmi->font);
3889 // if lines set to "-1", automatically determine by text and font height
3890 if (tmi->lines == -1)
3891 tmi->lines = tmi->height / getFontHeight(tmi->font);
3893 tmi->height = tmi->lines * getFontHeight(tmi->font);
3895 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3896 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3897 tmi->autowrap, tmi->centered, tmi->parse_comments);
3899 DrawTextSCentered(ybottom, FONT_TEXT_4,
3900 "Press any key or button for info menu");
3902 FadeIn(REDRAW_FIELD);
3905 static void HandleInfoScreen_LevelSet(int button)
3907 if (button == MB_MENU_LEAVE)
3909 PlaySound(SND_MENU_ITEM_SELECTING);
3911 info_mode = INFO_MODE_MAIN;
3916 else if (button == MB_MENU_CHOICE)
3918 PlaySound(SND_MENU_ITEM_SELECTING);
3920 FadeMenuSoundsAndMusic();
3922 info_mode = INFO_MODE_MAIN;
3927 PlayMenuSoundIfLoop();
3931 static void DrawInfoScreen(void)
3933 if (info_mode == INFO_MODE_TITLE)
3934 DrawInfoScreen_TitleScreen();
3935 else if (info_mode == INFO_MODE_ELEMENTS)
3936 DrawInfoScreen_Elements();
3937 else if (info_mode == INFO_MODE_MUSIC)
3938 DrawInfoScreen_Music();
3939 else if (info_mode == INFO_MODE_CREDITS)
3940 DrawInfoScreen_Credits();
3941 else if (info_mode == INFO_MODE_PROGRAM)
3942 DrawInfoScreen_Program();
3943 else if (info_mode == INFO_MODE_VERSION)
3944 DrawInfoScreen_Version();
3945 else if (info_mode == INFO_MODE_LEVELSET)
3946 DrawInfoScreen_LevelSet();
3948 DrawInfoScreen_Main();
3950 if (info_mode != INFO_MODE_MAIN &&
3951 info_mode != INFO_MODE_TITLE &&
3952 info_mode != INFO_MODE_MUSIC)
3953 PlayMenuSoundsAndMusic();
3956 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3958 if (info_mode == INFO_MODE_TITLE)
3959 HandleInfoScreen_TitleScreen(button);
3960 else if (info_mode == INFO_MODE_ELEMENTS)
3961 HandleInfoScreen_Elements(button);
3962 else if (info_mode == INFO_MODE_MUSIC)
3963 HandleInfoScreen_Music(button);
3964 else if (info_mode == INFO_MODE_CREDITS)
3965 HandleInfoScreen_Credits(button);
3966 else if (info_mode == INFO_MODE_PROGRAM)
3967 HandleInfoScreen_Program(button);
3968 else if (info_mode == INFO_MODE_VERSION)
3969 HandleInfoScreen_Version(button);
3970 else if (info_mode == INFO_MODE_LEVELSET)
3971 HandleInfoScreen_LevelSet(button);
3973 HandleInfoScreen_Main(mx, my, dx, dy, button);
3977 // ============================================================================
3978 // type name functions
3979 // ============================================================================
3981 static TreeInfo *type_name_node = NULL;
3982 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
3984 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
3986 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3988 *pos = *mci->pos_input;
3990 if (0 && setup.multiple_users) // (not used yet)
3992 TreeInfo *ti = player_name_current;
3993 int first_entry = ti->cl_first;
3994 int entry_pos = first_entry + ti->cl_cursor;
3995 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
3996 int xpos = MENU_SCREEN_START_XPOS;
3997 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
3999 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4001 strcpy(name, type_name_node->name);
4008 strcpy(name, setup.player_name);
4011 strcpy(type_name_last, name);
4013 if (strEqual(name, EMPTY_PLAYER_NAME))
4016 *xpos = strlen(name);
4019 static void setTypeNameValues(char *name, int *font, boolean success)
4022 strcpy(name, type_name_last);
4024 if (strEqual(name, ""))
4025 strcpy(name, EMPTY_PLAYER_NAME);
4027 if (0 && setup.multiple_users) // (not used yet)
4029 if (type_name_node == NULL) // should not happen
4034 type_name_node->color = FC_RED;
4036 if (strEqual(name, EMPTY_PLAYER_NAME))
4037 type_name_node->color = FC_BLUE;
4040 *font = FONT_TEXT_1 + type_name_node->color;
4046 int last_user_nr = user.nr;
4048 if (0 && setup.multiple_users) // (not used yet)
4050 int edit_user_nr = posTreeInfo(type_name_node);
4052 // change name of edited user in global list of user names
4053 setString(&global.user_names[edit_user_nr], name);
4055 // change name of edited user in local menu tree structure
4056 setString(&type_name_node->name, name);
4057 setString(&type_name_node->name_sorting, name);
4059 // save setup of currently active user (may differ from edited user)
4062 // temporarily change active user to edited user
4063 user.nr = edit_user_nr;
4065 // load setup of edited user
4069 // change name of edited user in setup structure
4070 strcpy(setup.player_name, name);
4072 // save setup of edited user
4075 if (0 && setup.multiple_users) // (not used yet)
4077 // restore currently active user
4078 user.nr = last_user_nr;
4080 // restore setup of currently active user
4085 static void HandleTypeNameExt(boolean initialize, Key key)
4087 static struct TextPosInfo pos_name = { 0 };
4088 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4089 static int xpos = 0;
4092 getTypeNameValues(name, &pos_name, &xpos);
4094 struct TextPosInfo *pos = &pos_name;
4095 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4096 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4097 int font_nr = pos->font;
4098 int font_active_nr = FONT_ACTIVE(font_nr);
4099 int font_width = getFontWidth(font_active_nr);
4100 char key_char = getValidConfigValueChar(getCharFromKey(key));
4101 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4102 boolean is_active = TRUE;
4104 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_active_nr);
4108 StartTextInput(sx, sy, pos->width, pos->height);
4110 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4112 name[xpos] = key_char;
4117 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4123 else if (key == KSYM_Return)
4125 setTypeNameValues(name, &font_nr, TRUE);
4129 else if (key == KSYM_Escape)
4131 setTypeNameValues(name, &font_nr, FALSE);
4138 pos->width = (strlen(name) + 1) * font_width;
4139 sx = mSX + ALIGNED_TEXT_XPOS(pos);
4141 DrawText(sx, sy, name, font_active_nr);
4142 DrawText(sx + xpos * font_width, sy, "_", font_active_nr);
4146 SetGameStatus(game_status_last_screen);
4148 pos->width = strlen(name) * font_width;
4149 sx = mSX + ALIGNED_TEXT_XPOS(pos);
4151 DrawText(sx, sy, name, font_nr);
4157 static void DrawTypeName(void)
4159 HandleTypeNameExt(TRUE, 0);
4162 void HandleTypeName(Key key)
4164 HandleTypeNameExt(FALSE, key);
4168 // ============================================================================
4169 // tree menu functions
4170 // ============================================================================
4172 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4174 if (game_status != GAME_MODE_SETUP ||
4175 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4178 int max_text_size = 0;
4181 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4182 max_text_size = MAX(max_text_size, strlen(node->name));
4184 int num_entries = numTreeInfoInGroup(ti);
4185 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4186 int text_width = max_text_size * getFontWidth(FONT_TEXT_1);
4187 int button_width = SC_MENUBUTTON_XSIZE;
4188 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4189 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4190 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4191 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4192 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4193 int align_xoffset = MAX(0, align_xoffset_raw);
4195 return align_xoffset;
4198 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4200 if (game_status != GAME_MODE_SETUP ||
4201 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4204 int num_entries = numTreeInfoInGroup(ti);
4205 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4206 int font_height = getFontHeight(FONT_TEXT_1);
4207 int text_height = font_height * num_page_entries;
4208 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4209 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4210 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4211 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4212 int align_yoffset = MAX(0, align_yoffset_raw);
4214 return align_yoffset;
4217 static void DrawChooseTree(TreeInfo **ti_ptr)
4219 int fade_mask = REDRAW_FIELD;
4222 fade_mask = REDRAW_ALL;
4224 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4226 SetGameStatus(GAME_MODE_MAIN);
4235 FreeScreenGadgets();
4236 CreateScreenGadgets();
4240 // needed if different viewport properties defined for choosing level (set)
4241 ChangeViewportPropertiesIfNeeded();
4243 if (game_status == GAME_MODE_NAMES)
4244 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4245 else if (game_status == GAME_MODE_LEVELNR)
4246 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4247 else if (game_status == GAME_MODE_LEVELS)
4248 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4252 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4254 MapScreenTreeGadgets(*ti_ptr);
4255 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4257 DrawMaskedBorder(fade_mask);
4262 static void drawChooseTreeList(int first_entry, int num_page_entries,
4265 int num_entries = numTreeInfoInGroup(ti);
4266 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4267 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4268 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4269 int font_nr = FONT_TEXT_1;
4270 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4272 char *title_string = NULL;
4273 int yoffset_sets = MENU_TITLE1_YPOS;
4274 int yoffset_setup = 16;
4275 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4276 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4278 title_string = ti->infotext;
4280 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4282 clearMenuListArea();
4284 for (i = 0; i < num_page_entries; i++)
4286 TreeInfo *node, *node_first;
4287 int entry_pos = first_entry + i;
4288 int xpos = MENU_SCREEN_START_XPOS;
4289 int ypos = MENU_SCREEN_START_YPOS + i;
4290 int startx = amSX + xpos * 32;
4291 int starty = amSY + ypos * 32;
4292 int startx_text = startx + font_xoffset;
4293 int endx_text = amSX + screen_width;
4294 int max_text_size = endx_text - startx_text;
4295 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4296 char buffer[max_buffer_len + 1];
4298 node_first = getTreeInfoFirstGroupEntry(ti);
4299 node = getTreeInfoFromPos(node_first, entry_pos);
4301 strncpy(buffer, node->name, max_buffer_len);
4302 buffer[max_buffer_len] = '\0';
4304 DrawText(startx, starty, buffer, font_nr + node->color);
4306 if (node->parent_link)
4307 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4308 else if (node->level_group)
4309 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4311 initCursor(i, IMG_MENU_BUTTON);
4314 redraw_mask |= REDRAW_FIELD;
4317 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4319 TreeInfo *node, *node_first;
4320 int x, last_redraw_mask = redraw_mask;
4321 int ypos = MENU_TITLE2_YPOS;
4322 int font_nr = FONT_TITLE_2;
4324 if (ti->type == TREE_TYPE_LEVEL_NR)
4325 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4327 if (ti->type != TREE_TYPE_LEVEL_DIR)
4330 node_first = getTreeInfoFirstGroupEntry(ti);
4331 node = getTreeInfoFromPos(node_first, entry_pos);
4333 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4335 if (node->parent_link)
4336 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4337 node->node_parent->name);
4338 else if (node->level_group)
4339 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4341 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4342 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4343 node->levels, (node->levels > 1 ? "levels" : "level"),
4346 // let BackToFront() redraw only what is needed
4347 redraw_mask = last_redraw_mask;
4348 for (x = 0; x < SCR_FIELDX; x++)
4349 MarkTileDirty(x, 1);
4352 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4355 TreeInfo *ti = *ti_ptr;
4356 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4357 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4358 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4360 int y = ti->cl_cursor;
4361 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4362 int num_entries = numTreeInfoInGroup(ti);
4363 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4364 boolean position_set_by_scrollbar = (dx == 999);
4366 if (button == MB_MENU_INITIALIZE)
4368 int num_entries = numTreeInfoInGroup(ti);
4369 int entry_pos = posTreeInfo(ti);
4371 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4372 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4374 if (ti->cl_first == -1)
4376 // only on initialization
4377 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4378 ti->cl_cursor = entry_pos - ti->cl_first;
4380 else if (ti->cl_cursor >= num_page_entries ||
4381 (num_entries > num_page_entries &&
4382 num_entries - ti->cl_first < num_page_entries))
4384 // only after change of list size (by custom graphic configuration)
4385 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4386 ti->cl_cursor = entry_pos - ti->cl_first;
4389 if (position_set_by_scrollbar)
4392 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4395 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4396 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4397 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4401 else if (button == MB_MENU_LEAVE)
4405 PlaySound(SND_MENU_ITEM_SELECTING);
4407 if (ti->node_parent)
4409 *ti_ptr = ti->node_parent;
4410 DrawChooseTree(ti_ptr);
4412 else if (game_status == GAME_MODE_SETUP)
4414 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4415 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4416 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4418 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4419 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4420 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4421 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4422 execSetupGraphics();
4423 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4424 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4425 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4427 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4428 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4429 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4430 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4431 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4432 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4433 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4434 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4441 if (game_status == GAME_MODE_LEVELNR)
4443 int new_level_nr = atoi(level_number_current->identifier);
4445 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4448 SetGameStatus(GAME_MODE_MAIN);
4456 if (mx || my) // mouse input
4458 x = (mx - amSX) / 32;
4459 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4461 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4463 // move cursor instead of scrolling when already at start/end of list
4464 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4466 else if (dy == +1 * SCROLL_LINE &&
4467 ti->cl_first + num_page_entries == num_entries)
4470 // handle scrolling screen one line or page
4471 if (ti->cl_cursor + dy < 0 ||
4472 ti->cl_cursor + dy > num_page_entries - 1)
4474 boolean redraw = FALSE;
4476 if (ABS(dy) == SCROLL_PAGE)
4477 step = num_page_entries - 1;
4479 if (dy < 0 && ti->cl_first > 0)
4481 // scroll page/line up
4483 ti->cl_first -= step;
4484 if (ti->cl_first < 0)
4489 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4491 // scroll page/line down
4493 ti->cl_first += step;
4494 if (ti->cl_first + num_page_entries > num_entries)
4495 ti->cl_first = MAX(0, num_entries - num_page_entries);
4502 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4503 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4504 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4506 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4513 // handle moving cursor one line
4514 y = ti->cl_cursor + dy;
4519 TreeInfo *node_first, *node_cursor;
4520 int entry_pos = ti->cl_first + y;
4522 node_first = getTreeInfoFirstGroupEntry(ti);
4523 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4525 if (node_cursor->node_group)
4529 PlaySound(SND_MENU_ITEM_SELECTING);
4531 node_cursor->cl_first = ti->cl_first;
4532 node_cursor->cl_cursor = ti->cl_cursor;
4533 *ti_ptr = node_cursor->node_group;
4534 DrawChooseTree(ti_ptr);
4539 else if (dx == -1 && ti->node_parent)
4543 PlaySound(SND_MENU_ITEM_SELECTING);
4545 *ti_ptr = ti->node_parent;
4546 DrawChooseTree(ti_ptr);
4551 if (!anyScrollbarGadgetActive() &&
4552 IN_VIS_MENU(x, y) &&
4553 mx < mx_right_border &&
4554 y >= 0 && y < num_page_entries)
4558 if (y != ti->cl_cursor)
4560 PlaySound(SND_MENU_ITEM_ACTIVATING);
4562 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4563 drawChooseTreeCursor(y, TRUE);
4564 drawChooseTreeInfo(ti->cl_first + y, ti);
4570 if (game_status == GAME_MODE_SETUP)
4572 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4573 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4574 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4576 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4577 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4578 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4579 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4580 execSetupGraphics();
4581 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4582 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4583 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4585 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4586 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4587 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4588 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4589 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4590 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4591 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4592 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4601 TreeInfo *node_first, *node_cursor;
4602 int entry_pos = ti->cl_first + y;
4604 PlaySound(SND_MENU_ITEM_SELECTING);
4606 node_first = getTreeInfoFirstGroupEntry(ti);
4607 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4609 if (node_cursor->node_group)
4613 node_cursor->cl_first = ti->cl_first;
4614 node_cursor->cl_cursor = ti->cl_cursor;
4615 *ti_ptr = node_cursor->node_group;
4616 DrawChooseTree(ti_ptr);
4618 else if (node_cursor->parent_link)
4622 *ti_ptr = node_cursor->node_parent;
4623 DrawChooseTree(ti_ptr);
4629 node_cursor->cl_first = ti->cl_first;
4630 node_cursor->cl_cursor = ti->cl_cursor;
4631 *ti_ptr = node_cursor;
4633 if (ti->type == TREE_TYPE_LEVEL_DIR)
4635 LoadLevelSetup_SeriesInfo();
4637 SaveLevelSetup_LastSeries();
4638 SaveLevelSetup_SeriesInfo();
4642 if (game_status == GAME_MODE_SETUP)
4644 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4645 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4646 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4648 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4649 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4650 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4651 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4652 execSetupGraphics();
4653 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4654 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4655 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4657 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4658 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4659 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4660 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4661 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4662 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4663 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4664 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4671 if (game_status == GAME_MODE_LEVELNR)
4673 int new_level_nr = atoi(level_number_current->identifier);
4675 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4678 SetGameStatus(GAME_MODE_MAIN);
4687 void DrawChoosePlayerName(void)
4691 FadeMenuSoundsAndMusic();
4693 if (player_name != NULL)
4695 freeTreeInfo(player_name);
4700 for (i = 0; i < MAX_PLAYER_NAMES; i++)
4702 boolean team_mode = (!network.enabled && setup.team_mode);
4703 int tree_type = (team_mode ? TREE_TYPE_PLAYER_TEAM : TREE_TYPE_PLAYER_NAME);
4704 TreeInfo *ti = newTreeInfo_setDefaults(tree_type);
4705 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
4708 ti->node_top = &player_name;
4709 ti->sort_priority = 10000 + value;
4712 if (strEqual(global.user_names[i], EMPTY_PLAYER_NAME))
4713 ti->color = FC_BLUE;
4715 snprintf(identifier, sizeof(identifier), "%d", value);
4716 snprintf(name, sizeof(name), "%s", global.user_names[i]);
4718 setString(&ti->identifier, identifier);
4719 setString(&ti->name, name);
4720 setString(&ti->name_sorting, name);
4722 pushTreeInfo(&player_name, ti);
4725 // sort player entries by player number
4726 sortTreeInfo(&player_name);
4728 // set current player entry to selected player entry
4729 player_name_current =
4730 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
4732 // if that fails, set current player name to first available name
4733 if (player_name_current == NULL)
4734 player_name_current = player_name;
4736 DrawChooseTree(&player_name_current);
4738 PlayMenuSoundsAndMusic();
4741 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
4743 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
4746 void DrawChooseLevelSet(void)
4748 FadeMenuSoundsAndMusic();
4750 DrawChooseTree(&leveldir_current);
4752 PlayMenuSoundsAndMusic();
4755 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4757 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4760 void DrawChooseLevelNr(void)
4764 FadeMenuSoundsAndMusic();
4766 if (level_number != NULL)
4768 freeTreeInfo(level_number);
4770 level_number = NULL;
4773 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4775 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4776 char identifier[32], name[64];
4779 // temporarily load level info to get level name
4780 LoadLevelInfoOnly(i);
4782 ti->node_top = &level_number;
4783 ti->sort_priority = 10000 + value;
4784 ti->color = (level.no_level_file ? FC_BLUE :
4785 LevelStats_getSolved(i) ? FC_GREEN :
4786 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4788 snprintf(identifier, sizeof(identifier), "%d", value);
4789 snprintf(name, sizeof(name), "%03d: %s", value,
4790 (level.no_level_file ? "(no file)" : level.name));
4792 setString(&ti->identifier, identifier);
4793 setString(&ti->name, name);
4794 setString(&ti->name_sorting, name);
4796 pushTreeInfo(&level_number, ti);
4799 // sort level number values to start with lowest level number
4800 sortTreeInfo(&level_number);
4802 // set current level number to current level number
4803 level_number_current =
4804 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4806 // if that also fails, set current level number to first available level
4807 if (level_number_current == NULL)
4808 level_number_current = level_number;
4810 DrawChooseTree(&level_number_current);
4812 PlayMenuSoundsAndMusic();
4815 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4817 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4820 void DrawHallOfFame(int level_nr, int highlight_position)
4822 int fade_mask = REDRAW_FIELD;
4825 fade_mask = REDRAW_ALL;
4828 FadeMenuSoundsAndMusic();
4830 // (this is needed when called from GameEnd() after winning a game)
4831 KeyboardAutoRepeatOn();
4833 // (this is needed when called from GameEnd() after winning a game)
4834 SetDrawDeactivationMask(REDRAW_NONE);
4835 SetDrawBackgroundMask(REDRAW_FIELD);
4837 if (highlight_position < 0)
4838 LoadScore(level_nr);
4840 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4842 FadeSetEnterScreen();
4846 // needed if different viewport properties defined for scores
4847 ChangeViewportPropertiesIfNeeded();
4849 PlayMenuSoundsAndMusic();
4851 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4853 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4855 DrawMaskedBorder(fade_mask);
4860 static void drawHallOfFameList(int level_nr, int first_entry,
4861 int highlight_position)
4865 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4868 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4869 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4870 "HighScores of Level %d", level_nr);
4872 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4874 int entry = first_entry + i;
4875 boolean active = (entry == highlight_position);
4876 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4877 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4878 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4879 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4880 int dxoff = getFontDrawOffsetX(font_nr1);
4881 int dx1 = 3 * getFontWidth(font_nr1);
4882 int dx2 = dx1 + getFontWidth(font_nr1);
4883 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4884 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4885 int sy = mSY + 64 + i * 32;
4887 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4888 DrawText(mSX + dx1, sy, ".", font_nr1);
4890 for (j = 0; j < num_dots; j++)
4891 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4893 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4894 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4896 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4899 redraw_mask |= REDRAW_FIELD;
4902 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4904 static int level_nr = 0;
4905 static int first_entry = 0;
4906 static int highlight_position = 0;
4907 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4909 if (button == MB_MENU_INITIALIZE)
4913 highlight_position = my;
4915 drawHallOfFameList(level_nr, first_entry, highlight_position);
4920 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
4921 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4925 if (first_entry > 0)
4927 first_entry -= step;
4928 if (first_entry < 0)
4931 drawHallOfFameList(level_nr, first_entry, highlight_position);
4936 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4938 first_entry += step;
4939 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4940 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4942 drawHallOfFameList(level_nr, first_entry, highlight_position);
4945 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4947 PlaySound(SND_MENU_ITEM_SELECTING);
4949 FadeSound(SND_BACKGROUND_SCORES);
4951 if (button == MB_MENU_CHOICE &&
4952 game_status_last_screen == GAME_MODE_PLAYING &&
4953 setup.auto_play_next_level && setup.increment_levels &&
4954 level_nr < leveldir_current->last_level &&
4957 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4961 SetGameStatus(GAME_MODE_MAIN);
4967 if (game_status == GAME_MODE_SCORES)
4968 PlayMenuSoundIfLoop();
4972 // ============================================================================
4973 // setup screen functions
4974 // ============================================================================
4976 static struct TokenInfo *setup_info;
4977 static int num_setup_info; // number of setup entries shown on screen
4978 static int max_setup_info; // total number of setup entries in list
4980 static char *window_size_text;
4981 static char *scaling_type_text;
4982 static char *rendering_mode_text;
4983 static char *vsync_mode_text;
4984 static char *scroll_delay_text;
4985 static char *snapshot_mode_text;
4986 static char *game_speed_text;
4987 static char *network_server_text;
4988 static char *graphics_set_name;
4989 static char *sounds_set_name;
4990 static char *music_set_name;
4991 static char *volume_simple_text;
4992 static char *volume_loops_text;
4993 static char *volume_music_text;
4994 static char *touch_controls_text;
4995 static char *move_distance_text;
4996 static char *drop_distance_text;
4997 static char *transparency_text;
4998 static char *grid_size_text[2][2];
5000 static void execSetupMain(void)
5002 setup_mode = SETUP_MODE_MAIN;
5007 static void execSetupGame_setGameSpeeds(boolean update_value)
5009 if (setup.game_speed_extended)
5011 game_speeds_list = game_speeds_list_extended;
5012 game_speeds = game_speeds_extended;
5016 game_speeds_list = game_speeds_list_normal;
5017 game_speeds = game_speeds_normal;
5020 if (game_speeds == NULL)
5024 for (i = 0; game_speeds_list[i].value != -1; i++)
5026 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5027 char identifier[32], name[32];
5028 int value = game_speeds_list[i].value;
5029 char *text = game_speeds_list[i].text;
5031 ti->node_top = &game_speeds;
5032 ti->sort_priority = 10000 - value;
5034 sprintf(identifier, "%d", value);
5035 sprintf(name, "%s", text);
5037 setString(&ti->identifier, identifier);
5038 setString(&ti->name, name);
5039 setString(&ti->name_sorting, name);
5040 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5042 pushTreeInfo(&game_speeds, ti);
5045 // sort game speed values to start with slowest game speed
5046 sortTreeInfo(&game_speeds);
5048 update_value = TRUE;
5053 // set current game speed to configured game speed value
5054 game_speed_current =
5055 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5057 // if that fails, set current game speed to reliable default value
5058 if (game_speed_current == NULL)
5059 game_speed_current =
5060 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5062 // if that also fails, set current game speed to first available speed
5063 if (game_speed_current == NULL)
5064 game_speed_current = game_speeds;
5066 if (setup.game_speed_extended)
5067 game_speeds_extended = game_speeds;
5069 game_speeds_normal = game_speeds;
5072 setup.game_frame_delay = atoi(game_speed_current->identifier);
5074 // needed for displaying game speed text instead of identifier
5075 game_speed_text = game_speed_current->name;
5078 static void execSetupGame_setScrollDelays(void)
5080 if (scroll_delays == NULL)
5084 for (i = 0; scroll_delays_list[i].value != -1; i++)
5086 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5087 char identifier[32], name[32];
5088 int value = scroll_delays_list[i].value;
5089 char *text = scroll_delays_list[i].text;
5091 ti->node_top = &scroll_delays;
5092 ti->sort_priority = value;
5094 sprintf(identifier, "%d", value);
5095 sprintf(name, "%s", text);
5097 setString(&ti->identifier, identifier);
5098 setString(&ti->name, name);
5099 setString(&ti->name_sorting, name);
5100 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5102 pushTreeInfo(&scroll_delays, ti);
5105 // sort scroll delay values to start with lowest scroll delay value
5106 sortTreeInfo(&scroll_delays);
5108 // set current scroll delay value to configured scroll delay value
5109 scroll_delay_current =
5110 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5112 // if that fails, set current scroll delay to reliable default value
5113 if (scroll_delay_current == NULL)
5114 scroll_delay_current =
5115 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5117 // if that also fails, set current scroll delay to first available value
5118 if (scroll_delay_current == NULL)
5119 scroll_delay_current = scroll_delays;
5122 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5124 // needed for displaying scroll delay text instead of identifier
5125 scroll_delay_text = scroll_delay_current->name;
5128 static void execSetupGame_setSnapshotModes(void)
5130 if (snapshot_modes == NULL)
5134 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5136 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5137 char identifier[32], name[32];
5138 char *value = snapshot_modes_list[i].value;
5139 char *text = snapshot_modes_list[i].text;
5141 ti->node_top = &snapshot_modes;
5142 ti->sort_priority = i;
5144 sprintf(identifier, "%s", value);
5145 sprintf(name, "%s", text);
5147 setString(&ti->identifier, identifier);
5148 setString(&ti->name, name);
5149 setString(&ti->name_sorting, name);
5150 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5152 pushTreeInfo(&snapshot_modes, ti);
5155 // sort snapshot mode values to start with lowest snapshot mode value
5156 sortTreeInfo(&snapshot_modes);
5158 // set current snapshot mode value to configured snapshot mode value
5159 snapshot_mode_current =
5160 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5162 // if that fails, set current snapshot mode to reliable default value
5163 if (snapshot_mode_current == NULL)
5164 snapshot_mode_current =
5165 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5167 // if that also fails, set current snapshot mode to first available value
5168 if (snapshot_mode_current == NULL)
5169 snapshot_mode_current = snapshot_modes;
5172 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5174 // needed for displaying snapshot mode text instead of identifier
5175 snapshot_mode_text = snapshot_mode_current->name;
5178 static void execSetupGame_setNetworkServerText(void)
5180 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5182 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5186 strncpy(network_server_hostname, setup.network_server_hostname,
5187 MAX_SETUP_TEXT_INPUT_LEN);
5188 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5191 // needed for displaying network server text instead of identifier
5192 network_server_text = network_server_hostname;
5195 static void execSetupGame(void)
5197 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5199 execSetupGame_setGameSpeeds(FALSE);
5200 execSetupGame_setScrollDelays();
5201 execSetupGame_setSnapshotModes();
5203 execSetupGame_setNetworkServerText();
5205 setup_mode = SETUP_MODE_GAME;
5209 // check if vsync needs to be disabled for this game speed to work
5210 if (check_vsync_mode)
5211 DisableVsyncIfNeeded();
5214 static void execSetupChooseGameSpeed(void)
5216 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5221 static void execSetupChooseScrollDelay(void)
5223 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5228 static void execSetupChooseSnapshotMode(void)
5230 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5235 static void execSetupEngines(void)
5237 setup_mode = SETUP_MODE_ENGINES;
5242 static void execSetupEditor(void)
5244 setup_mode = SETUP_MODE_EDITOR;
5249 static void execSetupGraphics_setWindowSizes(boolean update_list)
5251 if (window_sizes != NULL && update_list)
5253 freeTreeInfo(window_sizes);
5255 window_sizes = NULL;
5258 if (window_sizes == NULL)
5260 boolean current_window_size_found = FALSE;
5263 for (i = 0; window_sizes_list[i].value != -1; i++)
5265 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5266 char identifier[32], name[32];
5267 int value = window_sizes_list[i].value;
5268 char *text = window_sizes_list[i].text;
5270 ti->node_top = &window_sizes;
5271 ti->sort_priority = value;
5273 sprintf(identifier, "%d", value);
5274 sprintf(name, "%s", text);
5276 setString(&ti->identifier, identifier);
5277 setString(&ti->name, name);
5278 setString(&ti->name_sorting, name);
5279 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5281 pushTreeInfo(&window_sizes, ti);
5283 if (value == setup.window_scaling_percent)
5284 current_window_size_found = TRUE;
5287 if (!current_window_size_found)
5289 // add entry for non-preset window scaling value
5291 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5292 char identifier[32], name[32];
5293 int value = setup.window_scaling_percent;
5295 ti->node_top = &window_sizes;
5296 ti->sort_priority = value;
5298 sprintf(identifier, "%d", value);
5299 sprintf(name, "%d %% (Current)", value);
5301 setString(&ti->identifier, identifier);
5302 setString(&ti->name, name);
5303 setString(&ti->name_sorting, name);
5304 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5306 pushTreeInfo(&window_sizes, ti);
5309 // sort window size values to start with lowest window size value
5310 sortTreeInfo(&window_sizes);
5312 // set current window size value to configured window size value
5313 window_size_current =
5314 getTreeInfoFromIdentifier(window_sizes,
5315 i_to_a(setup.window_scaling_percent));
5317 // if that fails, set current window size to reliable default value
5318 if (window_size_current == NULL)
5319 window_size_current =
5320 getTreeInfoFromIdentifier(window_sizes,
5321 i_to_a(STD_WINDOW_SCALING_PERCENT));
5323 // if that also fails, set current window size to first available value
5324 if (window_size_current == NULL)
5325 window_size_current = window_sizes;
5328 setup.window_scaling_percent = atoi(window_size_current->identifier);
5330 // needed for displaying window size text instead of identifier
5331 window_size_text = window_size_current->name;
5334 static void execSetupGraphics_setScalingTypes(void)
5336 if (scaling_types == NULL)
5340 for (i = 0; scaling_types_list[i].value != NULL; i++)
5342 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5343 char identifier[32], name[32];
5344 char *value = scaling_types_list[i].value;
5345 char *text = scaling_types_list[i].text;
5347 ti->node_top = &scaling_types;
5348 ti->sort_priority = i;
5350 sprintf(identifier, "%s", value);
5351 sprintf(name, "%s", text);
5353 setString(&ti->identifier, identifier);
5354 setString(&ti->name, name);
5355 setString(&ti->name_sorting, name);
5356 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5358 pushTreeInfo(&scaling_types, ti);
5361 // sort scaling type values to start with lowest scaling type value
5362 sortTreeInfo(&scaling_types);
5364 // set current scaling type value to configured scaling type value
5365 scaling_type_current =
5366 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5368 // if that fails, set current scaling type to reliable default value
5369 if (scaling_type_current == NULL)
5370 scaling_type_current =
5371 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5373 // if that also fails, set current scaling type to first available value
5374 if (scaling_type_current == NULL)
5375 scaling_type_current = scaling_types;
5378 setup.window_scaling_quality = scaling_type_current->identifier;
5380 // needed for displaying scaling type text instead of identifier
5381 scaling_type_text = scaling_type_current->name;
5384 static void execSetupGraphics_setRenderingModes(void)
5386 if (rendering_modes == NULL)
5390 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5392 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5393 char identifier[32], name[32];
5394 char *value = rendering_modes_list[i].value;
5395 char *text = rendering_modes_list[i].text;
5397 ti->node_top = &rendering_modes;
5398 ti->sort_priority = i;
5400 sprintf(identifier, "%s", value);
5401 sprintf(name, "%s", text);
5403 setString(&ti->identifier, identifier);
5404 setString(&ti->name, name);
5405 setString(&ti->name_sorting, name);
5406 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5408 pushTreeInfo(&rendering_modes, ti);
5411 // sort rendering mode values to start with lowest rendering mode value
5412 sortTreeInfo(&rendering_modes);
5414 // set current rendering mode value to configured rendering mode value
5415 rendering_mode_current =
5416 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5418 // if that fails, set current rendering mode to reliable default value
5419 if (rendering_mode_current == NULL)
5420 rendering_mode_current =
5421 getTreeInfoFromIdentifier(rendering_modes,
5422 STR_SPECIAL_RENDERING_DEFAULT);
5424 // if that also fails, set current rendering mode to first available one
5425 if (rendering_mode_current == NULL)
5426 rendering_mode_current = rendering_modes;
5429 setup.screen_rendering_mode = rendering_mode_current->identifier;
5431 // needed for displaying rendering mode text instead of identifier
5432 rendering_mode_text = rendering_mode_current->name;
5435 static void execSetupGraphics_setVsyncModes(boolean update_value)
5437 if (vsync_modes == NULL)
5441 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5443 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5444 char identifier[32], name[32];
5445 char *value = vsync_modes_list[i].value;
5446 char *text = vsync_modes_list[i].text;
5448 ti->node_top = &vsync_modes;
5449 ti->sort_priority = i;
5451 sprintf(identifier, "%s", value);
5452 sprintf(name, "%s", text);
5454 setString(&ti->identifier, identifier);
5455 setString(&ti->name, name);
5456 setString(&ti->name_sorting, name);
5457 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5459 pushTreeInfo(&vsync_modes, ti);
5462 // sort vsync mode values to start with lowest vsync mode value
5463 sortTreeInfo(&vsync_modes);
5465 update_value = TRUE;
5470 // set current vsync mode value to configured vsync mode value
5471 vsync_mode_current =
5472 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5474 // if that fails, set current vsync mode to reliable default value
5475 if (vsync_mode_current == NULL)
5476 vsync_mode_current =
5477 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5479 // if that also fails, set current vsync mode to first available one
5480 if (vsync_mode_current == NULL)
5481 vsync_mode_current = vsync_modes;
5484 setup.vsync_mode = vsync_mode_current->identifier;
5486 // needed for displaying vsync mode text instead of identifier
5487 vsync_mode_text = vsync_mode_current->name;
5490 static void execSetupGraphics(void)
5492 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5494 // update "setup.window_scaling_percent" from list selection
5495 // (in this case, window scaling was changed on setup screen)
5496 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5497 execSetupGraphics_setWindowSizes(FALSE);
5499 // update "setup.vsync_mode" from list selection
5500 // (in this case, vsync mode was changed on setup screen)
5501 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5502 execSetupGraphics_setVsyncModes(FALSE);
5504 // update list selection from "setup.window_scaling_percent"
5505 // (window scaling may have changed by resizing the window)
5506 execSetupGraphics_setWindowSizes(TRUE);
5508 // update list selection from "setup.vsync_mode"
5509 // (vsync_mode may have changed by re-creating the renderer)
5510 execSetupGraphics_setVsyncModes(TRUE);
5512 execSetupGraphics_setScalingTypes();
5513 execSetupGraphics_setRenderingModes();
5515 setup_mode = SETUP_MODE_GRAPHICS;
5519 // check if game speed is high enough for 60 Hz vsync to work
5520 if (check_game_speed)
5521 ModifyGameSpeedIfNeeded();
5523 // window scaling may have changed at this point
5524 ChangeWindowScalingIfNeeded();
5526 // window scaling quality may have changed at this point
5527 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5528 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5530 // screen rendering mode may have changed at this point
5531 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5533 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
5534 int video_vsync_mode = video.vsync_mode;
5536 // screen vsync mode may have changed at this point
5537 ChangeVsyncModeIfNeeded();
5539 // check if setting vsync mode to selected value failed
5540 if (setup_vsync_mode != video_vsync_mode &&
5541 setup_vsync_mode != video.vsync_mode)
5543 // changing vsync mode to selected value failed -- reset displayed value
5544 execSetupGraphics_setVsyncModes(TRUE);
5546 Request("Setting VSync failed!", REQ_CONFIRM);
5552 static void execSetupChooseWindowSize(void)
5554 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5559 static void execSetupChooseScalingType(void)
5561 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5566 static void execSetupChooseRenderingMode(void)
5568 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5573 static void execSetupChooseVsyncMode(void)
5575 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5580 static void execSetupChooseVolumeSimple(void)
5582 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5587 static void execSetupChooseVolumeLoops(void)
5589 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5594 static void execSetupChooseVolumeMusic(void)
5596 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5601 static void execSetupSound(void)
5603 if (volumes_simple == NULL)
5605 boolean current_volume_simple_found = FALSE;
5608 for (i = 0; volumes_list[i].value != -1; i++)
5610 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5611 char identifier[32], name[32];
5612 int value = volumes_list[i].value;
5613 char *text = volumes_list[i].text;
5615 ti->node_top = &volumes_simple;
5616 ti->sort_priority = value;
5618 sprintf(identifier, "%d", value);
5619 sprintf(name, "%s", text);
5621 setString(&ti->identifier, identifier);
5622 setString(&ti->name, name);
5623 setString(&ti->name_sorting, name);
5624 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5626 pushTreeInfo(&volumes_simple, ti);
5628 if (value == setup.volume_simple)
5629 current_volume_simple_found = TRUE;
5632 if (!current_volume_simple_found)
5634 // add entry for non-preset volume value
5636 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5637 char identifier[32], name[32];
5638 int value = setup.volume_simple;
5640 ti->node_top = &volumes_simple;
5641 ti->sort_priority = value;
5643 sprintf(identifier, "%d", value);
5644 sprintf(name, "%d %% (Current)", value);
5646 setString(&ti->identifier, identifier);
5647 setString(&ti->name, name);
5648 setString(&ti->name_sorting, name);
5649 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5651 pushTreeInfo(&volumes_simple, ti);
5654 // sort volume values to start with lowest volume value
5655 sortTreeInfo(&volumes_simple);
5657 // set current volume value to configured volume value
5658 volume_simple_current =
5659 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5661 // if that fails, set current volume to reliable default value
5662 if (volume_simple_current == NULL)
5663 volume_simple_current =
5664 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5666 // if that also fails, set current volume to first available value
5667 if (volume_simple_current == NULL)
5668 volume_simple_current = volumes_simple;
5671 if (volumes_loops == NULL)
5673 boolean current_volume_loops_found = FALSE;
5676 for (i = 0; volumes_list[i].value != -1; i++)
5678 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5679 char identifier[32], name[32];
5680 int value = volumes_list[i].value;
5681 char *text = volumes_list[i].text;
5683 ti->node_top = &volumes_loops;
5684 ti->sort_priority = value;
5686 sprintf(identifier, "%d", value);
5687 sprintf(name, "%s", text);
5689 setString(&ti->identifier, identifier);
5690 setString(&ti->name, name);
5691 setString(&ti->name_sorting, name);
5692 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5694 pushTreeInfo(&volumes_loops, ti);
5696 if (value == setup.volume_loops)
5697 current_volume_loops_found = TRUE;
5700 if (!current_volume_loops_found)
5702 // add entry for non-preset volume value
5704 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5705 char identifier[32], name[32];
5706 int value = setup.volume_loops;
5708 ti->node_top = &volumes_loops;
5709 ti->sort_priority = value;
5711 sprintf(identifier, "%d", value);
5712 sprintf(name, "%d %% (Current)", value);
5714 setString(&ti->identifier, identifier);
5715 setString(&ti->name, name);
5716 setString(&ti->name_sorting, name);
5717 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5719 pushTreeInfo(&volumes_loops, ti);
5722 // sort volume values to start with lowest volume value
5723 sortTreeInfo(&volumes_loops);
5725 // set current volume value to configured volume value
5726 volume_loops_current =
5727 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5729 // if that fails, set current volume to reliable default value
5730 if (volume_loops_current == NULL)
5731 volume_loops_current =
5732 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5734 // if that also fails, set current volume to first available value
5735 if (volume_loops_current == NULL)
5736 volume_loops_current = volumes_loops;
5739 if (volumes_music == NULL)
5741 boolean current_volume_music_found = FALSE;
5744 for (i = 0; volumes_list[i].value != -1; i++)
5746 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5747 char identifier[32], name[32];
5748 int value = volumes_list[i].value;
5749 char *text = volumes_list[i].text;
5751 ti->node_top = &volumes_music;
5752 ti->sort_priority = value;
5754 sprintf(identifier, "%d", value);
5755 sprintf(name, "%s", text);
5757 setString(&ti->identifier, identifier);
5758 setString(&ti->name, name);
5759 setString(&ti->name_sorting, name);
5760 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5762 pushTreeInfo(&volumes_music, ti);
5764 if (value == setup.volume_music)
5765 current_volume_music_found = TRUE;
5768 if (!current_volume_music_found)
5770 // add entry for non-preset volume value
5772 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5773 char identifier[32], name[32];
5774 int value = setup.volume_music;
5776 ti->node_top = &volumes_music;
5777 ti->sort_priority = value;
5779 sprintf(identifier, "%d", value);
5780 sprintf(name, "%d %% (Current)", value);
5782 setString(&ti->identifier, identifier);
5783 setString(&ti->name, name);
5784 setString(&ti->name_sorting, name);
5785 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5787 pushTreeInfo(&volumes_music, ti);
5790 // sort volume values to start with lowest volume value
5791 sortTreeInfo(&volumes_music);
5793 // set current volume value to configured volume value
5794 volume_music_current =
5795 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5797 // if that fails, set current volume to reliable default value
5798 if (volume_music_current == NULL)
5799 volume_music_current =
5800 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5802 // if that also fails, set current volume to first available value
5803 if (volume_music_current == NULL)
5804 volume_music_current = volumes_music;
5807 setup.volume_simple = atoi(volume_simple_current->identifier);
5808 setup.volume_loops = atoi(volume_loops_current->identifier);
5809 setup.volume_music = atoi(volume_music_current->identifier);
5811 // needed for displaying volume text instead of identifier
5812 volume_simple_text = volume_simple_current->name;
5813 volume_loops_text = volume_loops_current->name;
5814 volume_music_text = volume_music_current->name;
5816 setup_mode = SETUP_MODE_SOUND;
5821 static void execSetupChooseTouchControls(void)
5823 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5828 static void execSetupChooseMoveDistance(void)
5830 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5835 static void execSetupChooseDropDistance(void)
5837 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5842 static void execSetupChooseTransparency(void)
5844 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5849 static void execSetupChooseGridXSize_0(void)
5851 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5856 static void execSetupChooseGridYSize_0(void)
5858 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5863 static void execSetupChooseGridXSize_1(void)
5865 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5870 static void execSetupChooseGridYSize_1(void)
5872 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5877 static void execSetupConfigureVirtualButtons(void)
5879 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5881 ConfigureVirtualButtons();
5883 setup_mode = SETUP_MODE_TOUCH;
5888 static void execSetupTouch(void)
5892 if (touch_controls == NULL)
5894 for (i = 0; touch_controls_list[i].value != NULL; i++)
5896 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5897 char identifier[32], name[32];
5898 char *value = touch_controls_list[i].value;
5899 char *text = touch_controls_list[i].text;
5901 ti->node_top = &touch_controls;
5902 ti->sort_priority = i;
5904 sprintf(identifier, "%s", value);
5905 sprintf(name, "%s", text);
5907 setString(&ti->identifier, identifier);
5908 setString(&ti->name, name);
5909 setString(&ti->name_sorting, name);
5910 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5912 pushTreeInfo(&touch_controls, ti);
5915 // sort touch control values to start with lowest touch control value
5916 sortTreeInfo(&touch_controls);
5918 // set current touch control value to configured touch control value
5919 touch_control_current =
5920 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5922 // if that fails, set current touch control to reliable default value
5923 if (touch_control_current == NULL)
5924 touch_control_current =
5925 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5927 // if that also fails, set current touch control to first available value
5928 if (touch_control_current == NULL)
5929 touch_control_current = touch_controls;
5932 if (move_distances == NULL)
5934 for (i = 0; distances_list[i].value != -1; i++)
5936 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5937 char identifier[32], name[32];
5938 int value = distances_list[i].value;
5939 char *text = distances_list[i].text;
5941 ti->node_top = &move_distances;
5942 ti->sort_priority = value;
5944 sprintf(identifier, "%d", value);
5945 sprintf(name, "%s", text);
5947 setString(&ti->identifier, identifier);
5948 setString(&ti->name, name);
5949 setString(&ti->name_sorting, name);
5950 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5952 pushTreeInfo(&move_distances, ti);
5955 // sort distance values to start with lowest distance value
5956 sortTreeInfo(&move_distances);
5958 // set current distance value to configured distance value
5959 move_distance_current =
5960 getTreeInfoFromIdentifier(move_distances,
5961 i_to_a(setup.touch.move_distance));
5963 // if that fails, set current distance to reliable default value
5964 if (move_distance_current == NULL)
5965 move_distance_current =
5966 getTreeInfoFromIdentifier(move_distances,
5967 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5969 // if that also fails, set current distance to first available value
5970 if (move_distance_current == NULL)
5971 move_distance_current = move_distances;
5974 if (drop_distances == NULL)
5976 for (i = 0; distances_list[i].value != -1; i++)
5978 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5979 char identifier[32], name[32];
5980 int value = distances_list[i].value;
5981 char *text = distances_list[i].text;
5983 ti->node_top = &drop_distances;
5984 ti->sort_priority = value;
5986 sprintf(identifier, "%d", value);
5987 sprintf(name, "%s", text);
5989 setString(&ti->identifier, identifier);
5990 setString(&ti->name, name);
5991 setString(&ti->name_sorting, name);
5992 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5994 pushTreeInfo(&drop_distances, ti);
5997 // sort distance values to start with lowest distance value
5998 sortTreeInfo(&drop_distances);
6000 // set current distance value to configured distance value
6001 drop_distance_current =
6002 getTreeInfoFromIdentifier(drop_distances,
6003 i_to_a(setup.touch.drop_distance));
6005 // if that fails, set current distance to reliable default value
6006 if (drop_distance_current == NULL)
6007 drop_distance_current =
6008 getTreeInfoFromIdentifier(drop_distances,
6009 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6011 // if that also fails, set current distance to first available value
6012 if (drop_distance_current == NULL)
6013 drop_distance_current = drop_distances;
6016 if (transparencies == NULL)
6018 for (i = 0; transparencies_list[i].value != -1; i++)
6020 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6021 char identifier[32], name[32];
6022 int value = transparencies_list[i].value;
6023 char *text = transparencies_list[i].text;
6025 ti->node_top = &transparencies;
6026 ti->sort_priority = value;
6028 sprintf(identifier, "%d", value);
6029 sprintf(name, "%s", text);
6031 setString(&ti->identifier, identifier);
6032 setString(&ti->name, name);
6033 setString(&ti->name_sorting, name);
6034 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6036 pushTreeInfo(&transparencies, ti);
6039 // sort transparency values to start with lowest transparency value
6040 sortTreeInfo(&transparencies);
6042 // set current transparency value to configured transparency value
6043 transparency_current =
6044 getTreeInfoFromIdentifier(transparencies,
6045 i_to_a(setup.touch.transparency));
6047 // if that fails, set current transparency to reliable default value
6048 if (transparency_current == NULL)
6049 transparency_current =
6050 getTreeInfoFromIdentifier(transparencies,
6051 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6053 // if that also fails, set current transparency to first available value
6054 if (transparency_current == NULL)
6055 transparency_current = transparencies;
6058 for (i = 0; i < 2; i++)
6060 for (j = 0; j < 2; j++)
6062 if (grid_sizes[i][j] == NULL)
6064 for (k = 0; grid_sizes_list[k].value != -1; k++)
6066 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6067 char identifier[32], name[32];
6068 int value = grid_sizes_list[k].value;
6069 char *text = grid_sizes_list[k].text;
6071 ti->node_top = &grid_sizes[i][j];
6072 ti->sort_priority = value;
6074 sprintf(identifier, "%d", value);
6075 sprintf(name, "%s", text);
6077 setString(&ti->identifier, identifier);
6078 setString(&ti->name, name);
6079 setString(&ti->name_sorting, name);
6080 setString(&ti->infotext,
6083 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6084 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6086 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6087 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6089 pushTreeInfo(&grid_sizes[i][j], ti);
6092 // sort grid size values to start with lowest grid size value
6093 sortTreeInfo(&grid_sizes[i][j]);
6095 // set current grid size value to configured grid size value
6096 grid_size_current[i][j] =
6097 getTreeInfoFromIdentifier(grid_sizes[i][j],
6099 setup.touch.grid_xsize[i] :
6100 setup.touch.grid_ysize[i]));
6102 // if that fails, set current grid size to reliable default value
6103 if (grid_size_current[i][j] == NULL)
6104 grid_size_current[i][j] =
6105 getTreeInfoFromIdentifier(grid_sizes[i][j],
6107 DEFAULT_GRID_XSIZE(i) :
6108 DEFAULT_GRID_YSIZE(i)));
6110 // if that also fails, set current grid size to first available value
6111 if (grid_size_current[i][j] == NULL)
6112 grid_size_current[i][j] = grid_sizes[i][j];
6117 setup.touch.control_type = touch_control_current->identifier;
6118 setup.touch.move_distance = atoi(move_distance_current->identifier);
6119 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6120 setup.touch.transparency = atoi(transparency_current->identifier);
6122 for (i = 0; i < 2; i++)
6124 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6125 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6127 if (i == GRID_ACTIVE_NR())
6129 overlay.grid_xsize = setup.touch.grid_xsize[i];
6130 overlay.grid_ysize = setup.touch.grid_ysize[i];
6134 // needed for displaying value text instead of identifier
6135 touch_controls_text = touch_control_current->name;
6136 move_distance_text = move_distance_current->name;
6137 drop_distance_text = drop_distance_current->name;
6138 transparency_text = transparency_current->name;
6140 for (i = 0; i < 2; i++)
6141 for (j = 0; j < 2; j++)
6142 grid_size_text[i][j] = grid_size_current[i][j]->name;
6144 setup_mode = SETUP_MODE_TOUCH;
6149 static void execSetupArtwork(void)
6152 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6153 artwork.gfx_current->subdir,
6154 artwork.gfx_current->fullpath,
6155 artwork.gfx_current->basepath);
6158 setup.graphics_set = artwork.gfx_current->identifier;
6159 setup.sounds_set = artwork.snd_current->identifier;
6160 setup.music_set = artwork.mus_current->identifier;
6162 // needed if last screen (setup choice) changed graphics, sounds or music
6163 ReloadCustomArtwork(0);
6165 // needed for displaying artwork name instead of artwork identifier
6166 graphics_set_name = artwork.gfx_current->name;
6167 sounds_set_name = artwork.snd_current->name;
6168 music_set_name = artwork.mus_current->name;
6170 setup_mode = SETUP_MODE_ARTWORK;
6175 static void execSetupChooseGraphics(void)
6177 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6182 static void execSetupChooseSounds(void)
6184 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6189 static void execSetupChooseMusic(void)
6191 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6196 static void execSetupInput(void)
6198 setup_mode = SETUP_MODE_INPUT;
6203 static void execSetupShortcuts(void)
6205 setup_mode = SETUP_MODE_SHORTCUTS;
6210 static void execSetupShortcuts1(void)
6212 setup_mode = SETUP_MODE_SHORTCUTS_1;
6217 static void execSetupShortcuts2(void)
6219 setup_mode = SETUP_MODE_SHORTCUTS_2;
6224 static void execSetupShortcuts3(void)
6226 setup_mode = SETUP_MODE_SHORTCUTS_3;
6231 static void execSetupShortcuts4(void)
6233 setup_mode = SETUP_MODE_SHORTCUTS_4;
6238 static void execSetupShortcuts5(void)
6240 setup_mode = SETUP_MODE_SHORTCUTS_5;
6245 static void execExitSetup(void)
6247 SetGameStatus(GAME_MODE_MAIN);
6252 static void execSaveAndExitSetup(void)
6258 static void execGadgetNetworkServer(void)
6260 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6261 struct GadgetInfo *gi = screen_gadget[gadget_id];
6263 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6264 network_server_hostname[0] = '\0';
6266 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6270 ClickOnGadget(gi, MB_LEFTBUTTON);
6273 static void ToggleNetworkModeIfNeeded(void)
6275 int font_title = FONT_TITLE_1;
6276 int font_foot = FC_BLUE;
6277 int ystart = mSY - SY + 16;
6278 int ybottom = mSY - SY + SYSIZE - 20;
6279 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6281 if (setup.network_mode == network.enabled)
6284 network.enabled = setup.network_mode;
6286 FadeOut(REDRAW_ALL);
6290 DrawTextSCentered(ystart, font_title, text);
6294 if (network.enabled)
6295 InitNetworkServer();
6297 DisconnectFromNetworkServer();
6299 DrawTextSCentered(ybottom, font_foot,
6300 "Press any key or button for setup menu");
6302 WaitForEventToContinue();
6307 static void ToggleGameSpeedsListIfNeeded(void)
6309 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6311 if (setup.game_speed_extended == using_game_speeds_extended)
6314 // try to match similar values when changing game speeds list
6315 if (setup.game_speed_extended)
6316 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6317 setup.game_frame_delay == 30 ? 29 :
6318 setup.game_frame_delay);
6320 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6321 setup.game_frame_delay == 16 ? 15 :
6322 setup.game_frame_delay >= 29 ? 30 :
6323 setup.game_frame_delay <= 10 ? 10 :
6324 setup.game_frame_delay);
6326 execSetupGame_setGameSpeeds(TRUE);
6331 static void ModifyGameSpeedIfNeeded(void)
6333 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6334 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6338 char *game_speed_text = "Fast";
6339 int game_speed_value = 15;
6341 if (setup.game_speed_extended)
6343 game_speed_text = "60 fps";
6344 game_speed_value = 16;
6347 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6349 // set game speed to existing list value that is fast enough for vsync
6350 setup.game_frame_delay = game_speed_value;
6352 execSetupGame_setGameSpeeds(TRUE);
6354 Request(message, REQ_CONFIRM);
6357 static void DisableVsyncIfNeeded(void)
6359 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6360 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6361 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6364 // disable vsync for the selected game speed to work
6365 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6367 execSetupGraphics_setVsyncModes(TRUE);
6369 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6375 void *related_value;
6376 } hide_related_entry_list[] =
6378 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6379 { &setup.game_frame_delay, &game_speed_text },
6381 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6382 { &setup.scroll_delay_value, &scroll_delay_text },
6384 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6385 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6387 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6388 { &setup.window_scaling_percent, &window_size_text },
6390 { &setup.window_scaling_quality, execSetupChooseScalingType },
6391 { &setup.window_scaling_quality, &scaling_type_text },
6393 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6394 { &setup.screen_rendering_mode, &rendering_mode_text },
6396 { &setup.vsync_mode, execSetupChooseVsyncMode },
6397 { &setup.vsync_mode, &vsync_mode_text },
6399 { &setup.graphics_set, execSetupChooseGraphics },
6400 { &setup.graphics_set, &graphics_set_name },
6402 { &setup.sounds_set, execSetupChooseSounds },
6403 { &setup.sounds_set, &sounds_set_name },
6405 { &setup.music_set, execSetupChooseMusic },
6406 { &setup.music_set, &music_set_name },
6408 { &setup.volume_simple, execSetupChooseVolumeSimple },
6409 { &setup.volume_simple, &volume_simple_text },
6411 { &setup.volume_loops, execSetupChooseVolumeLoops },
6412 { &setup.volume_loops, &volume_loops_text },
6414 { &setup.volume_music, execSetupChooseVolumeMusic },
6415 { &setup.volume_music, &volume_music_text },
6417 { &setup.touch.control_type, execSetupChooseTouchControls },
6418 { &setup.touch.control_type, &touch_controls_text },
6420 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6421 { &setup.touch.move_distance, &move_distance_text },
6423 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6424 { &setup.touch.drop_distance, &drop_distance_text },
6426 { &setup.touch.transparency, execSetupChooseTransparency },
6427 { &setup.touch.transparency, &transparency_text },
6429 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6430 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6432 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6433 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6435 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6436 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6438 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6439 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6441 { &setup.internal.menu_game, execSetupGame },
6442 { &setup.internal.menu_engines, execSetupEngines },
6443 { &setup.internal.menu_editor, execSetupEditor },
6444 { &setup.internal.menu_graphics, execSetupGraphics },
6445 { &setup.internal.menu_sound, execSetupSound },
6446 { &setup.internal.menu_artwork, execSetupArtwork },
6447 { &setup.internal.menu_input, execSetupInput },
6448 { &setup.internal.menu_touch, execSetupTouch },
6449 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6450 { &setup.internal.menu_exit, execExitSetup },
6451 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6456 void setHideRelatedSetupEntries(void)
6460 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6461 if (hideSetupEntry(hide_related_entry_list[i].value))
6462 setHideSetupEntry(hide_related_entry_list[i].related_value);
6465 static struct TokenInfo setup_info_main[] =
6467 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6468 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6469 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6470 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6471 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6472 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6473 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6474 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6475 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6476 { TYPE_EMPTY, NULL, "" },
6477 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6478 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6483 static struct TokenInfo setup_info_game[] =
6485 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6486 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6487 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6488 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6489 { TYPE_STRING, &network_server_text, "" },
6490 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
6491 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6492 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6493 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6494 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6495 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6496 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6497 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
6498 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6499 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6500 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6501 { TYPE_STRING, &game_speed_text, "" },
6502 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6504 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6505 { TYPE_STRING, &scroll_delay_text, "" },
6507 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6508 { TYPE_STRING, &snapshot_mode_text, "" },
6509 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6510 { TYPE_EMPTY, NULL, "" },
6511 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6516 static struct TokenInfo setup_info_engines[] =
6518 { TYPE_HEADLINE, NULL, "Emerald Mine" },
6519 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
6520 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
6521 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
6522 { TYPE_EMPTY, NULL, "" },
6523 { TYPE_HEADLINE, NULL, "Supaplex" },
6524 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
6525 { TYPE_EMPTY, NULL, "" },
6526 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6531 static struct TokenInfo setup_info_editor[] =
6534 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6535 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6536 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6537 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6538 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6539 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6540 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6541 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6542 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6543 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6545 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6546 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6548 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6550 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6551 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6552 { TYPE_EMPTY, NULL, "" },
6554 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6555 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6556 { TYPE_EMPTY, NULL, "" },
6558 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6559 { TYPE_EMPTY, NULL, "" },
6560 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6565 static struct TokenInfo setup_info_graphics[] =
6567 #if !defined(PLATFORM_ANDROID)
6568 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6569 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6570 { TYPE_STRING, &window_size_text, "" },
6571 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6572 { TYPE_STRING, &scaling_type_text, "" },
6573 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6574 { TYPE_STRING, &rendering_mode_text, "" },
6577 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6578 { TYPE_STRING, &scroll_delay_text, "" },
6580 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6581 { TYPE_STRING, &vsync_mode_text, "" },
6582 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6583 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6584 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6585 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6586 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6587 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6588 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
6589 { TYPE_EMPTY, NULL, "" },
6590 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6595 static struct TokenInfo setup_info_sound[] =
6597 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6598 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6599 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6600 { TYPE_EMPTY, NULL, "" },
6601 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6602 { TYPE_STRING, &volume_simple_text, "" },
6603 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6604 { TYPE_STRING, &volume_loops_text, "" },
6605 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6606 { TYPE_STRING, &volume_music_text, "" },
6607 { TYPE_EMPTY, NULL, "" },
6608 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6613 static struct TokenInfo setup_info_artwork[] =
6615 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6616 { TYPE_STRING, &graphics_set_name, "" },
6617 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6618 { TYPE_STRING, &sounds_set_name, "" },
6619 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6620 { TYPE_STRING, &music_set_name, "" },
6621 { TYPE_EMPTY, NULL, "" },
6622 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6623 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6624 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6625 { TYPE_EMPTY, NULL, "" },
6626 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6631 static struct TokenInfo setup_info_input[] =
6633 { TYPE_SWITCH, NULL, "Player:" },
6634 { TYPE_SWITCH, NULL, "Device:" },
6635 { TYPE_SWITCH, NULL, "" },
6636 { TYPE_SKIPPABLE, NULL, "" },
6637 { TYPE_EMPTY, NULL, "" },
6638 { TYPE_EMPTY, NULL, "" },
6639 { TYPE_EMPTY, NULL, "" },
6640 { TYPE_EMPTY, NULL, "" },
6641 { TYPE_EMPTY, NULL, "" },
6642 { TYPE_EMPTY, NULL, "" },
6643 { TYPE_EMPTY, NULL, "" },
6644 { TYPE_EMPTY, NULL, "" },
6645 { TYPE_SKIPPABLE, NULL, "" },
6646 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6651 static struct TokenInfo setup_info_touch[] =
6653 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6654 { TYPE_STRING, &touch_controls_text, "" },
6655 { TYPE_EMPTY, NULL, "" },
6656 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6661 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6663 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6664 { TYPE_STRING, &touch_controls_text, "" },
6665 { TYPE_EMPTY, NULL, "" },
6666 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6667 { TYPE_STRING, &grid_size_text[0][0], "" },
6668 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6669 { TYPE_STRING, &grid_size_text[0][1], "" },
6670 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6671 { TYPE_STRING, &transparency_text, "" },
6672 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6673 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6674 { TYPE_EMPTY, NULL, "" },
6675 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6676 { TYPE_EMPTY, NULL, "" },
6677 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6682 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6684 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6685 { TYPE_STRING, &touch_controls_text, "" },
6686 { TYPE_EMPTY, NULL, "" },
6687 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6688 { TYPE_STRING, &grid_size_text[1][0], "" },
6689 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6690 { TYPE_STRING, &grid_size_text[1][1], "" },
6691 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6692 { TYPE_STRING, &transparency_text, "" },
6693 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6694 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6695 { TYPE_EMPTY, NULL, "" },
6696 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6697 { TYPE_EMPTY, NULL, "" },
6698 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6703 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6705 setup_info_touch_virtual_buttons_0,
6706 setup_info_touch_virtual_buttons_1
6709 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6711 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6712 { TYPE_STRING, &touch_controls_text, "" },
6713 { TYPE_EMPTY, NULL, "" },
6714 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6715 { TYPE_STRING, &move_distance_text, "" },
6716 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6717 { TYPE_STRING, &drop_distance_text, "" },
6718 { TYPE_EMPTY, NULL, "" },
6719 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6724 static struct TokenInfo setup_info_shortcuts[] =
6726 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6727 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6728 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6729 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6730 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6731 { TYPE_EMPTY, NULL, "" },
6732 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6737 static struct TokenInfo setup_info_shortcuts_1[] =
6739 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6740 { TYPE_KEY, &setup.shortcut.save_game, "" },
6741 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6742 { TYPE_KEY, &setup.shortcut.load_game, "" },
6743 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6744 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6745 { TYPE_EMPTY, NULL, "" },
6746 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6747 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6748 { TYPE_EMPTY, NULL, "" },
6749 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6754 static struct TokenInfo setup_info_shortcuts_2[] =
6756 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6757 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6758 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6759 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6760 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6761 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6762 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6763 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6764 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6765 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6766 { TYPE_EMPTY, NULL, "" },
6767 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6772 static struct TokenInfo setup_info_shortcuts_3[] =
6774 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6775 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6776 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6777 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6778 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6779 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6780 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6781 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6782 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6783 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6784 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6785 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6786 { TYPE_EMPTY, NULL, "" },
6787 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6792 static struct TokenInfo setup_info_shortcuts_4[] =
6794 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6795 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6796 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6797 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6798 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6799 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6800 { TYPE_EMPTY, NULL, "" },
6801 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6806 static struct TokenInfo setup_info_shortcuts_5[] =
6808 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6809 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6810 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6811 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6812 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6813 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6814 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6815 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6816 { TYPE_EMPTY, NULL, "" },
6817 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6822 static Key getSetupKey(void)
6824 Key key = KSYM_UNDEFINED;
6825 boolean got_key_event = FALSE;
6827 while (!got_key_event)
6831 if (NextValidEvent(&event))
6835 case EVENT_KEYPRESS:
6837 key = GetEventKey((KeyEvent *)&event, TRUE);
6839 // press 'Escape' or 'Enter' to keep the existing key binding
6840 if (key == KSYM_Escape || key == KSYM_Return)
6841 key = KSYM_UNDEFINED; // keep old value
6843 got_key_event = TRUE;
6847 case EVENT_KEYRELEASE:
6848 key_joystick_mapping = 0;
6852 HandleOtherEvents(&event);
6863 static int getSetupValueFont(int type, void *value)
6865 if (type & TYPE_GHOSTED)
6866 return FONT_OPTION_OFF;
6867 else if (type & TYPE_KEY)
6868 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6869 else if (type & TYPE_STRING)
6870 return FONT_VALUE_2;
6871 else if (type & TYPE_ECS_AGA)
6872 return FONT_VALUE_1;
6873 else if (type & TYPE_BOOLEAN_STYLE)
6874 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6875 else if (type & TYPE_YES_NO_AUTO)
6876 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6877 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6878 else if (type & TYPE_PLAYER)
6879 return FONT_VALUE_1;
6881 return FONT_VALUE_1;
6884 static int getSetupValueFontNarrow(int type, int font_nr)
6886 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6887 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6888 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6892 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6894 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6895 struct TokenInfo *si = &setup_info[si_pos];
6896 boolean font_draw_xoffset_modified = FALSE;
6897 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6898 int font_draw_xoffset_old = -1;
6899 int xoffset = (scrollbar_needed ? -1 : 0);
6900 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6901 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6902 int xpos = menu_screen_value_xpos;
6903 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6904 int startx = mSX + xpos * 32;
6905 int starty = mSY + ypos * 32;
6906 int type = si->type;
6907 void *value = si->value;
6908 char *value_string = getSetupValue(type, value);
6909 int font_nr_default = getSetupValueFont(type, value);
6910 int font_width_default = getFontWidth(font_nr_default);
6911 int font_nr = font_nr_default;
6914 if (value_string == NULL)
6917 if (type & TYPE_KEY)
6919 xpos = MENU_SCREEN_START_XPOS;
6921 if (type & TYPE_QUERY)
6922 value_string = "<press key>";
6924 else if (type & TYPE_STRING)
6926 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
6928 xpos = MENU_SCREEN_START_XPOS;
6930 if (strlen(value_string) > max_value_len)
6931 value_string[max_value_len] = '\0';
6933 else if (type & TYPE_YES_NO_AUTO)
6935 xpos = menu_screen_value_xpos - 1;
6937 else if (type & TYPE_PLAYER)
6939 int displayed_player_nr = *(int *)value + 1;
6941 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6944 startx = mSX + xpos * 32;
6945 starty = mSY + ypos * 32;
6947 // special check if right-side setup values moved left due to scrollbar
6948 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6950 int max_menu_text_length = 26; // maximum text length for classic menu
6951 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6952 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6953 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6954 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6955 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6957 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6959 // when using narrow font, left-shifting text "auto" not needed
6960 if (type & TYPE_YES_NO_AUTO)
6964 startx = mSX + xpos * 32;
6966 font_nr = getSetupValueFontNarrow(type, font_nr);
6970 // downward compatibility correction for Juergen Bonhagen's menu settings
6971 if (setup_mode != SETUP_MODE_INPUT)
6973 int max_menu_text_length_big = (menu_screen_value_xpos -
6974 MENU_SCREEN_START_XPOS);
6975 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6976 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
6977 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6978 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6979 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6980 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6981 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6982 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6983 boolean correct_font_draw_xoffset = FALSE;
6985 if (xpos == MENU_SCREEN_START_XPOS &&
6986 startx + font1_xoffset < text_startx + text_font_xoffset)
6987 correct_font_draw_xoffset = TRUE;
6989 if (xpos == menu_screen_value_xpos &&
6990 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6991 correct_font_draw_xoffset = TRUE;
6993 // check if setup value would overlap with setup text when printed
6994 // (this can happen for extreme/wrong values for font draw offset)
6995 if (correct_font_draw_xoffset)
6997 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6998 font_draw_xoffset_modified = TRUE;
7000 if (type & TYPE_KEY)
7001 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7002 else if (!(type & TYPE_STRING))
7003 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7004 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7008 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7009 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7011 DrawText(startx, starty, value_string, font_nr);
7013 if (type & TYPE_PLAYER)
7015 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7016 int player_nr = *(int *)value;
7017 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7018 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7019 int startx2 = startx + xoff;
7020 int starty2 = starty + yoff;
7022 if (DrawingOnBackground(startx2, starty2))
7023 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7025 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7026 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7029 if (font_draw_xoffset_modified)
7030 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7033 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7035 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7036 struct TokenInfo *si = &setup_info[si_pos];
7038 if (si->type & TYPE_BOOLEAN_STYLE)
7040 *(boolean *)si->value ^= TRUE;
7042 else if (si->type & TYPE_YES_NO_AUTO)
7046 (*(int *)si->value == AUTO ? TRUE :
7047 *(int *)si->value == TRUE ? FALSE : AUTO) :
7048 (*(int *)si->value == TRUE ? AUTO :
7049 *(int *)si->value == AUTO ? FALSE : TRUE));
7051 else if (si->type & TYPE_KEY)
7055 si->type |= TYPE_QUERY;
7056 drawSetupValue(screen_pos, setup_info_pos_raw);
7057 si->type &= ~TYPE_QUERY;
7059 key = getSetupKey();
7060 if (key != KSYM_UNDEFINED)
7061 *(Key *)si->value = key;
7063 else if (si->type & TYPE_PLAYER)
7065 int player_nr = *(int *)si->value;
7070 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7072 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7075 drawSetupValue(screen_pos, setup_info_pos_raw);
7077 // fullscreen state may have changed at this point
7078 if (si->value == &setup.fullscreen)
7079 ToggleFullscreenIfNeeded();
7081 // network mode may have changed at this point
7082 if (si->value == &setup.network_mode)
7083 ToggleNetworkModeIfNeeded();
7085 // game speed list may have changed at this point
7086 if (si->value == &setup.game_speed_extended)
7087 ToggleGameSpeedsListIfNeeded();
7090 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7092 static struct TokenInfo *setup_info_final = NULL;
7097 // determine maximum list size of target list
7098 while (setup_info_orig[list_size++].type != 0);
7100 // free, allocate and clear memory for target list
7101 checked_free(setup_info_final);
7102 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7104 // copy setup info list without setup entries marked as hidden
7105 for (i = 0; setup_info_orig[i].type != 0; i++)
7107 // skip setup entries configured to be hidden
7108 if (hideSetupEntry(setup_info_orig[i].value))
7111 // skip skippable setup entries if screen is lower than usual
7112 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7113 setup_info_orig[i].type == TYPE_SKIPPABLE)
7116 setup_info_final[list_pos++] = setup_info_orig[i];
7119 return setup_info_final;
7122 static void DrawSetupScreen_Generic(void)
7124 int fade_mask = REDRAW_FIELD;
7125 boolean redraw_all = FALSE;
7126 char *title_string = NULL;
7130 fade_mask = REDRAW_ALL;
7133 FadeMenuSoundsAndMusic();
7135 FreeScreenGadgets();
7136 CreateScreenGadgets();
7138 if (redraw_mask & REDRAW_ALL)
7143 // needed if different viewport properties defined for setup screen
7144 ChangeViewportPropertiesIfNeeded();
7146 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7150 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7152 if (setup_mode == SETUP_MODE_MAIN)
7154 setup_info = setup_info_main;
7155 title_string = STR_SETUP_MAIN;
7157 else if (setup_mode == SETUP_MODE_GAME)
7159 setup_info = setup_info_game;
7160 title_string = STR_SETUP_GAME;
7162 else if (setup_mode == SETUP_MODE_ENGINES)
7164 setup_info = setup_info_engines;
7165 title_string = STR_SETUP_ENGINES;
7167 else if (setup_mode == SETUP_MODE_EDITOR)
7169 setup_info = setup_info_editor;
7170 title_string = STR_SETUP_EDITOR;
7172 else if (setup_mode == SETUP_MODE_GRAPHICS)
7174 setup_info = setup_info_graphics;
7175 title_string = STR_SETUP_GRAPHICS;
7177 else if (setup_mode == SETUP_MODE_SOUND)
7179 setup_info = setup_info_sound;
7180 title_string = STR_SETUP_SOUND;
7182 else if (setup_mode == SETUP_MODE_ARTWORK)
7184 setup_info = setup_info_artwork;
7185 title_string = STR_SETUP_ARTWORK;
7187 else if (setup_mode == SETUP_MODE_TOUCH)
7189 setup_info = setup_info_touch;
7190 title_string = STR_SETUP_TOUCH;
7192 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7193 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7194 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7195 setup_info = setup_info_touch_wipe_gestures;
7197 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7199 setup_info = setup_info_shortcuts;
7200 title_string = STR_SETUP_SHORTCUTS;
7202 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7204 setup_info = setup_info_shortcuts_1;
7205 title_string = STR_SETUP_SHORTCUTS;
7207 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7209 setup_info = setup_info_shortcuts_2;
7210 title_string = STR_SETUP_SHORTCUTS;
7212 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7214 setup_info = setup_info_shortcuts_3;
7215 title_string = STR_SETUP_SHORTCUTS;
7217 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7219 setup_info = setup_info_shortcuts_4;
7220 title_string = STR_SETUP_SHORTCUTS;
7222 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7224 setup_info = setup_info_shortcuts_5;
7225 title_string = STR_SETUP_SHORTCUTS;
7228 // use modified setup info without setup entries marked as hidden
7229 setup_info = getSetupInfoFinal(setup_info);
7231 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7233 // determine maximal number of setup entries that can be displayed on screen
7235 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7238 // determine maximal number of setup entries available for this setup screen
7240 for (i = 0; setup_info[i].type != 0; i++)
7243 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7245 MapScreenGadgets(max_setup_info);
7248 redraw_mask = fade_mask = REDRAW_ALL;
7250 DrawMaskedBorder(fade_mask);
7255 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7257 menu_info = setup_info;
7259 HandleMenuScreen(mx, my, dx, dy, button,
7260 setup_mode, num_setup_info, max_setup_info);
7263 static void DrawSetupScreen_Input(void)
7267 FadeOut(REDRAW_FIELD);
7271 setup_info = getSetupInfoFinal(setup_info_input);
7273 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7275 for (i = 0; setup_info[i].type != 0; i++)
7277 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7278 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7279 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7280 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7281 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7282 initCursor(i, IMG_MENU_BUTTON);
7284 DrawCursorAndText_Setup(i, -1, FALSE);
7287 // create gadgets for setup input menu screen
7288 FreeScreenGadgets();
7289 CreateScreenGadgets();
7291 // map gadgets for setup input menu screen
7292 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7294 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7296 FadeIn(REDRAW_FIELD);
7299 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7301 if (device_name == NULL)
7304 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7307 if (strlen(device_name) > 1)
7309 char c1 = device_name[strlen(device_name) - 1];
7310 char c2 = device_name[strlen(device_name) - 2];
7312 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7313 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7316 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7317 strlen(device_name));
7320 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7323 static struct SetupKeyboardInfo custom_key;
7330 { &custom_key.left, "Axis/Pad Left" },
7331 { &custom_key.right, "Axis/Pad Right" },
7332 { &custom_key.up, "Axis/Pad Up" },
7333 { &custom_key.down, "Axis/Pad Down" },
7334 { &custom_key.snap, "Button 1/A/X" },
7335 { &custom_key.drop, "Button 2/B/Y" }
7337 static char *joystick_name[MAX_PLAYERS] =
7344 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7345 int font_nr_info = FONT_MENU_1;
7346 int font_nr_name = FONT_VALUE_OLD;
7347 int font_nr_on = FONT_VALUE_1;
7348 int font_nr_off = FONT_VALUE_OLD;
7351 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7353 font_nr_info = FONT_MENU_2;
7354 font_nr_on = FONT_VALUE_NARROW;
7355 font_nr_off = FONT_VALUE_OLD_NARROW;
7358 custom_key = setup.input[player_nr].key;
7360 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7361 FONT_INPUT_1_ACTIVE);
7363 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7365 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7366 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7368 if (setup.input[player_nr].use_joystick)
7370 char *device_name = setup.input[player_nr].joy.device_name;
7371 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7372 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7373 char *text = joystick_name[joystick_nr];
7374 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7376 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7377 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7381 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7382 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7385 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7386 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7390 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7391 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7392 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7393 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7395 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7396 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7397 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7398 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7399 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7400 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7402 for (i = 0; i < 6; i++)
7404 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7406 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7408 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7409 (setup.input[player_nr].use_joystick ?
7411 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7415 static int input_player_nr = 0;
7417 static void HandleSetupScreen_Input_Player(int step, int direction)
7419 int old_player_nr = input_player_nr;
7422 new_player_nr = old_player_nr + step * direction;
7423 if (new_player_nr < 0)
7425 if (new_player_nr > MAX_PLAYERS - 1)
7426 new_player_nr = MAX_PLAYERS - 1;
7428 if (new_player_nr != old_player_nr)
7430 input_player_nr = new_player_nr;
7432 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7436 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7438 static int choice = 0;
7441 int pos_start = SETUPINPUT_SCREEN_POS_START;
7442 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7443 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7444 int pos_end = SETUPINPUT_SCREEN_POS_END;
7446 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7450 for (i = 0; setup_info_input[i].type != 0; i++)
7452 // adjust menu structure according to skipped setup entries
7453 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7461 if (button == MB_MENU_INITIALIZE)
7463 // input setup menu may have changed size due to graphics configuration
7464 if (choice >= pos_empty1)
7467 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7469 DrawCursorAndText_Setup(choice, -1, TRUE);
7473 else if (button == MB_MENU_LEAVE)
7475 setup_mode = SETUP_MODE_MAIN;
7482 if (mx || my) // mouse input
7484 x = (mx - mSX) / 32;
7485 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7487 else if (dx || dy) // keyboard input
7489 if (dx && choice == 0)
7490 x = (dx < 0 ? 10 : 12);
7491 else if ((dx && choice == 1) ||
7492 (dx == -1 && choice == pos_end))
7493 button = MB_MENU_CHOICE;
7497 if (y >= pos_empty1 && y <= pos_empty2)
7498 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7501 if (y == 0 && dx != 0 && button)
7503 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7505 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7506 y >= pos_start && y <= pos_end &&
7507 !(y >= pos_empty1 && y <= pos_empty2))
7513 DrawCursorAndText_Setup(choice, -1, FALSE);
7514 DrawCursorAndText_Setup(y, -1, TRUE);
7516 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7525 char *device_name = setup.input[input_player_nr].joy.device_name;
7527 if (!setup.input[input_player_nr].use_joystick)
7529 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7531 setJoystickDeviceToNr(device_name, new_device_nr);
7532 setup.input[input_player_nr].use_joystick = TRUE;
7536 int device_nr = getJoystickNrFromDeviceName(device_name);
7537 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7539 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7540 setup.input[input_player_nr].use_joystick = FALSE;
7542 setJoystickDeviceToNr(device_name, new_device_nr);
7545 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7549 if (setup.input[input_player_nr].use_joystick)
7550 ConfigureJoystick(input_player_nr);
7552 CustomizeKeyboard(input_player_nr);
7554 else if (y == pos_end)
7560 setup_mode = SETUP_MODE_MAIN;
7567 static boolean CustomizeKeyboardMain(int player_nr)
7571 boolean finished = FALSE;
7572 static struct SetupKeyboardInfo custom_key;
7577 } customize_step[] =
7579 { &custom_key.left, "Move Left" },
7580 { &custom_key.right, "Move Right" },
7581 { &custom_key.up, "Move Up" },
7582 { &custom_key.down, "Move Down" },
7583 { &custom_key.snap, "Snap Field" },
7584 { &custom_key.drop, "Drop Element" }
7586 int font_nr_old = FONT_VALUE_OLD;
7587 int font_nr_new = FONT_VALUE_1;
7588 boolean success = FALSE;
7590 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7592 font_nr_old = FONT_VALUE_OLD_NARROW;
7593 font_nr_new = FONT_VALUE_NARROW;
7596 // read existing key bindings from player setup
7597 custom_key = setup.input[player_nr].key;
7600 FadeOut(REDRAW_FIELD);
7604 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7607 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7608 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7609 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7610 "Key:", FONT_INPUT_1_ACTIVE);
7611 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7612 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7614 FadeIn(REDRAW_FIELD);
7620 if (NextValidEvent(&event))
7624 case EVENT_KEYPRESS:
7626 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7628 // press 'Escape' to abort and keep the old key bindings
7629 if (key == KSYM_Escape)
7631 FadeSkipNextFadeIn();
7638 // press 'Enter' to keep the existing key binding
7639 if (key == KSYM_Return)
7640 key = *customize_step[step_nr].key;
7642 // check if key already used
7643 for (i = 0; i < step_nr; i++)
7644 if (*customize_step[i].key == key)
7649 // got new key binding
7650 *customize_step[step_nr].key = key;
7651 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7653 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7654 getKeyNameFromKey(key), font_nr_new);
7657 // un-highlight last query
7658 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7659 customize_step[step_nr - 1].text, FONT_MENU_1);
7660 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7661 "Key:", FONT_MENU_1);
7663 // all keys configured
7672 // query next key binding
7673 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7674 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7675 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7676 "Key:", FONT_INPUT_1_ACTIVE);
7677 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7678 getKeyNameFromKey(*customize_step[step_nr].key),
7683 case EVENT_KEYRELEASE:
7684 key_joystick_mapping = 0;
7688 HandleOtherEvents(&event);
7696 // write new key bindings back to player setup, if successfully finished
7698 setup.input[player_nr].key = custom_key;
7703 void CustomizeKeyboard(int player_nr)
7705 boolean success = CustomizeKeyboardMain(player_nr);
7709 int font_nr = FONT_TITLE_1;
7710 int font_height = getFontHeight(font_nr);
7711 int ypos1 = SYSIZE / 2 - font_height * 2;
7712 int ypos2 = SYSIZE / 2 - font_height * 1;
7713 unsigned int wait_frame_delay = 0;
7714 unsigned int wait_frame_delay_value = 2000;
7716 ResetDelayCounter(&wait_frame_delay);
7720 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7721 DrawTextSCentered(ypos2, font_nr, "configured!");
7723 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7729 DrawSetupScreen_Input();
7732 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
7734 #define MARKER_BUTTON 1
7735 #define MARKER_AXIS_X 2
7736 #define MARKER_AXIS_Y 3
7738 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7740 static boolean bitmaps_initialized = FALSE;
7741 boolean screen_initialized = FALSE;
7742 static Bitmap *controller, *button, *axis_x, *axis_y;
7744 boolean success = TRUE;
7745 boolean done = FALSE, next = FALSE;
7747 int alpha = 200, alpha_step = -1;
7748 int alpha_ticks = 0;
7749 char mapping[4096], temp[256];
7750 int font_name = MENU_SETUP_FONT_TITLE;
7751 int font_info = MENU_SETUP_FONT_TEXT;
7752 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7753 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7754 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7755 int ystep_name = getMenuTextStep(spacing_name, font_name);
7756 int ystep_line = getMenuTextStep(spacing_line, font_info);
7757 int ystep_para = getMenuTextStep(spacing_para, font_info);
7765 int axis, button, hat, hat_value;
7768 *step, *prev_step, steps[] =
7770 { 356, 155, MARKER_BUTTON, "a", },
7771 { 396, 122, MARKER_BUTTON, "b", },
7772 { 320, 125, MARKER_BUTTON, "x", },
7773 { 358, 95, MARKER_BUTTON, "y", },
7774 { 162, 125, MARKER_BUTTON, "back", },
7775 { 216, 125, MARKER_BUTTON, "guide", },
7776 { 271, 125, MARKER_BUTTON, "start", },
7777 { 110, 200, MARKER_BUTTON, "dpleft", },
7778 { 146, 228, MARKER_BUTTON, "dpdown", },
7779 { 178, 200, MARKER_BUTTON, "dpright", },
7780 { 146, 172, MARKER_BUTTON, "dpup", },
7781 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7782 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7783 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7784 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7785 { 73, 141, MARKER_BUTTON, "leftstick", },
7786 { 282, 210, MARKER_BUTTON, "rightstick", },
7787 { 73, 141, MARKER_AXIS_X, "leftx", },
7788 { 73, 141, MARKER_AXIS_Y, "lefty", },
7789 { 282, 210, MARKER_AXIS_X, "rightx", },
7790 { 282, 210, MARKER_AXIS_Y, "righty", },
7793 unsigned int event_frame_delay = 0;
7794 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7796 ResetDelayCounter(&event_frame_delay);
7798 if (!bitmaps_initialized)
7800 controller = LoadCustomImage("joystick/controller.png");
7801 button = LoadCustomImage("joystick/button.png");
7802 axis_x = LoadCustomImage("joystick/axis_x.png");
7803 axis_y = LoadCustomImage("joystick/axis_y.png");
7805 bitmaps_initialized = TRUE;
7808 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7811 // print info about the joystick we are watching
7812 Debug("joystick", "watching joystick %d: (%s)",
7813 SDL_JoystickInstanceID(joystick), name);
7814 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
7815 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7816 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7819 // initialize mapping with GUID and name
7820 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7822 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7823 temp, name, SDL_GetPlatform());
7825 // loop through all steps (buttons and axes), getting joystick events
7826 for (i = 0; i < SDL_arraysize(steps) && !done;)
7828 Bitmap *marker = button; // initialize with reliable default value
7831 strcpy(step->mapping, mapping);
7835 step->hat_value = -1;
7837 marker = (step->marker == MARKER_BUTTON ? button :
7838 step->marker == MARKER_AXIS_X ? axis_x :
7839 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7843 while (!done && !next)
7845 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7846 alpha_ticks = SDL_GetTicks();
7853 else if (alpha < 128)
7859 int controller_x = SX + (SXSIZE - controller->width) / 2;
7860 int controller_y = SY + ystep_line;
7862 int marker_x = controller_x + step->x;
7863 int marker_y = controller_y + step->y;
7865 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7866 int ystart2 = ystart1 + ystep_name + ystep_line;
7870 DrawTextSCentered(ystart1, font_name, name);
7872 DrawTextSCentered(ystart2, font_info,
7873 "Press buttons and move axes on");
7874 ystart2 += ystep_line;
7875 DrawTextSCentered(ystart2, font_info,
7876 "your controller when indicated.");
7877 ystart2 += ystep_line;
7878 DrawTextSCentered(ystart2, font_info,
7879 "(Your controller may look different.)");
7880 ystart2 += ystep_para;
7882 #if defined(PLATFORM_ANDROID)
7883 DrawTextSCentered(ystart2, font_info,
7884 "To correct a mistake,");
7885 ystart2 += ystep_line;
7886 DrawTextSCentered(ystart2, font_info,
7887 "press the 'back' button.");
7888 ystart2 += ystep_line;
7889 DrawTextSCentered(ystart2, font_info,
7890 "To skip a button or axis,");
7891 ystart2 += ystep_line;
7892 DrawTextSCentered(ystart2, font_info,
7893 "press the 'menu' button.");
7895 DrawTextSCentered(ystart2, font_info,
7896 "To correct a mistake,");
7897 ystart2 += ystep_line;
7898 DrawTextSCentered(ystart2, font_info,
7899 "press the 'backspace' key.");
7900 ystart2 += ystep_line;
7901 DrawTextSCentered(ystart2, font_info,
7902 "To skip a button or axis,");
7903 ystart2 += ystep_line;
7904 DrawTextSCentered(ystart2, font_info,
7905 "press the 'return' key.");
7906 ystart2 += ystep_line;
7907 DrawTextSCentered(ystart2, font_info,
7908 "To exit, press the 'escape' key.");
7911 BlitBitmapMasked(controller, drawto, 0, 0,
7912 controller->width, controller->height,
7913 controller_x, controller_y);
7915 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7916 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7918 BlitBitmapMasked(marker, drawto, 0, 0,
7919 marker->width, marker->height,
7920 marker_x, marker_y);
7922 if (!screen_initialized)
7923 FadeIn(REDRAW_FIELD);
7927 screen_initialized = TRUE;
7929 while (NextValidEvent(&event))
7933 case SDL_JOYAXISMOTION:
7934 if (event.jaxis.value > 20000 ||
7935 event.jaxis.value < -20000)
7937 for (j = 0; j < i; j++)
7938 if (steps[j].axis == event.jaxis.axis)
7943 if (step->marker != MARKER_AXIS_X &&
7944 step->marker != MARKER_AXIS_Y)
7947 step->axis = event.jaxis.axis;
7948 strcat(mapping, step->field);
7949 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7950 strcat(mapping, temp);
7958 case SDL_JOYHATMOTION:
7959 // ignore centering; we're probably just coming back
7960 // to the center from the previous item we set
7961 if (event.jhat.value == SDL_HAT_CENTERED)
7964 for (j = 0; j < i; j++)
7965 if (steps[j].hat == event.jhat.hat &&
7966 steps[j].hat_value == event.jhat.value)
7971 step->hat = event.jhat.hat;
7972 step->hat_value = event.jhat.value;
7973 strcat(mapping, step->field);
7974 snprintf(temp, sizeof(temp), ":h%u.%u,",
7975 event.jhat.hat, event.jhat.value );
7976 strcat(mapping, temp);
7983 case SDL_JOYBALLMOTION:
7986 case SDL_JOYBUTTONUP:
7987 for (j = 0; j < i; j++)
7988 if (steps[j].button == event.jbutton.button)
7993 step->button = event.jbutton.button;
7994 strcat(mapping, step->field);
7995 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7996 strcat(mapping, temp);
8003 case SDL_FINGERDOWN:
8004 case SDL_MOUSEBUTTONDOWN:
8012 if (event.key.keysym.sym == KSYM_BackSpace ||
8013 event.key.keysym.sym == KSYM_Back)
8025 prev_step = &steps[i - 1];
8026 strcpy(mapping, prev_step->mapping);
8033 if (event.key.keysym.sym == KSYM_space ||
8034 event.key.keysym.sym == KSYM_Return ||
8035 event.key.keysym.sym == KSYM_Menu)
8044 if (event.key.keysym.sym == KSYM_Escape)
8054 program.exit_function(0);
8061 // do not handle events for longer than standard frame delay period
8062 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8071 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8074 // activate mapping for this game
8075 SDL_GameControllerAddMapping(mapping);
8077 // save mapping to personal mappings
8078 SaveSetup_AddGameControllerMapping(mapping);
8081 // wait until the last pending event was removed from event queue
8082 while (NextValidEvent(&event));
8087 static int ConfigureJoystickMain(int player_nr)
8089 char *device_name = setup.input[player_nr].joy.device_name;
8090 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8091 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8092 int success = FALSE;
8095 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8096 return JOYSTICK_NOT_AVAILABLE;
8098 if (!joystick_active || !setup.input[player_nr].use_joystick)
8099 return JOYSTICK_NOT_AVAILABLE;
8102 FadeOut(REDRAW_FIELD);
8104 // close all joystick devices (potentially opened as game controllers)
8105 for (i = 0; i < SDL_NumJoysticks(); i++)
8106 SDLCloseJoystick(i);
8108 // open joystick device as plain joystick to configure as game controller
8109 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8111 // as the joystick was successfully opened before, this should not happen
8112 if (joystick == NULL)
8115 // create new game controller mapping (buttons and axes) for joystick device
8116 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8118 // close joystick (and maybe re-open as configured game controller later)
8119 SDL_JoystickClose(joystick);
8121 // re-open all joystick devices (potentially as game controllers)
8122 for (i = 0; i < SDL_NumJoysticks(); i++)
8125 // clear all joystick input actions for all joystick devices
8126 SDLClearJoystickState();
8128 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8131 void ConfigureJoystick(int player_nr)
8133 boolean state = ConfigureJoystickMain(player_nr);
8135 if (state != JOYSTICK_NOT_CONFIGURED)
8137 boolean success = (state == JOYSTICK_CONFIGURED);
8138 char message1[MAX_OUTPUT_LINESIZE + 1];
8139 char *message2 = (success ? "configured!" : "not available!");
8140 char *device_name = setup.input[player_nr].joy.device_name;
8141 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8142 int font_nr = FONT_TITLE_1;
8143 int font_height = getFontHeight(font_nr);
8144 int ypos1 = SYSIZE / 2 - font_height * 2;
8145 int ypos2 = SYSIZE / 2 - font_height * 1;
8146 unsigned int wait_frame_delay = 0;
8147 unsigned int wait_frame_delay_value = 2000;
8149 ResetDelayCounter(&wait_frame_delay);
8153 sprintf(message1, "Joystick %d", nr);
8155 DrawTextSCentered(ypos1, font_nr, message1);
8156 DrawTextSCentered(ypos2, font_nr, message2);
8158 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8164 DrawSetupScreen_Input();
8167 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8169 if (y < video.screen_height / 3)
8171 // remap touch gadgets to access upper part of the screen
8172 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8173 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8175 else if (y > 2 * video.screen_height / 3)
8177 // remap touch gadgets to access lower part of the screen
8178 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8179 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8183 static boolean ConfigureVirtualButtonsMain(void)
8185 static char *customize_step_text[] =
8194 char grid_button[] =
8196 CHAR_GRID_BUTTON_LEFT,
8197 CHAR_GRID_BUTTON_RIGHT,
8198 CHAR_GRID_BUTTON_UP,
8199 CHAR_GRID_BUTTON_DOWN,
8200 CHAR_GRID_BUTTON_SNAP,
8201 CHAR_GRID_BUTTON_DROP
8210 int font_nr = FONT_INPUT_1_ACTIVE;
8211 int font_height = getFontHeight(font_nr);
8212 int ypos1 = SYSIZE / 2 - font_height * 2;
8213 int ypos2 = SYSIZE / 2 - font_height * 1;
8214 boolean success = FALSE;
8215 boolean finished = FALSE;
8217 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8218 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8219 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8220 boolean set_grid_button = FALSE;
8221 int nr = GRID_ACTIVE_NR();
8224 for (x = 0; x < MAX_GRID_XSIZE; x++)
8225 for (y = 0; y < MAX_GRID_YSIZE; y++)
8226 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8228 overlay.grid_button_highlight = grid_button[step_nr];
8233 FadeOut(REDRAW_FIELD);
8237 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8238 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8239 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8241 FadeIn(REDRAW_FIELD);
8243 SetOverlayShowGrid(TRUE);
8245 // map gadgets for setup touch buttons menu screen
8246 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8252 while (NextValidEvent(&event))
8254 int action = ACTION_NONE;
8256 // ---------- handle events and set the resulting action ----------
8262 UserEvent *user = (UserEvent *)&event;
8263 int id = user->value1;
8265 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8266 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8267 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8268 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8273 case EVENT_KEYPRESS:
8275 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8277 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8278 key == KSYM_BackSpace ||
8279 key == KSYM_Back ? ACTION_BACK :
8280 key == KSYM_Return ||
8282 key == KSYM_space ? ACTION_NEXT :
8287 case EVENT_KEYRELEASE:
8288 key_joystick_mapping = 0;
8291 case EVENT_BUTTONPRESS:
8292 case EVENT_BUTTONRELEASE:
8294 ButtonEvent *button = (ButtonEvent *)&event;
8296 motion_status = FALSE;
8298 if (button->type == EVENT_BUTTONPRESS)
8299 button_status = button->button;
8301 button_status = MB_RELEASED;
8303 if (HandleGadgets(button->x, button->y, button_status))
8305 // do not handle this button event anymore
8309 button->x += video.screen_xoffset;
8310 button->y += video.screen_yoffset;
8312 x = button->x * overlay.grid_xsize / video.screen_width;
8313 y = button->y * overlay.grid_ysize / video.screen_height;
8315 if (button->type == EVENT_BUTTONPRESS)
8318 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8319 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8321 set_grid_button = TRUE;
8324 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8328 case EVENT_MOTIONNOTIFY:
8330 MotionEvent *motion = (MotionEvent *)&event;
8332 motion_status = TRUE;
8334 if (HandleGadgets(motion->x, motion->y, button_status))
8336 // do not handle this button event anymore
8340 motion->x += video.screen_xoffset;
8341 motion->y += video.screen_yoffset;
8343 x = motion->x * overlay.grid_xsize / video.screen_width;
8344 y = motion->y * overlay.grid_ysize / video.screen_height;
8346 set_grid_button = TRUE;
8348 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8352 case SDL_WINDOWEVENT:
8353 HandleWindowEvent((WindowEvent *) &event);
8355 // check if device has been rotated
8356 if (nr != GRID_ACTIVE_NR())
8358 nr = GRID_ACTIVE_NR();
8360 for (x = 0; x < MAX_GRID_XSIZE; x++)
8361 for (y = 0; y < MAX_GRID_YSIZE; y++)
8362 grid_button_old[x][y] = grid_button_tmp[x][y] =
8363 overlay.grid_button[x][y];
8368 case SDL_APP_WILLENTERBACKGROUND:
8369 case SDL_APP_DIDENTERBACKGROUND:
8370 case SDL_APP_WILLENTERFOREGROUND:
8371 case SDL_APP_DIDENTERFOREGROUND:
8372 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8376 HandleOtherEvents(&event);
8380 // ---------- perform action set by handling events ----------
8382 if (action == ACTION_ESCAPE)
8384 // abort and restore the old key bindings
8386 for (x = 0; x < MAX_GRID_XSIZE; x++)
8387 for (y = 0; y < MAX_GRID_YSIZE; y++)
8388 overlay.grid_button[x][y] = grid_button_old[x][y];
8390 FadeSkipNextFadeIn();
8394 else if (action == ACTION_BACK)
8396 // keep the configured key bindings and go to previous page
8402 FadeSkipNextFadeIn();
8407 else if (action == ACTION_NEXT)
8409 // keep the configured key bindings and go to next page
8413 // all virtual buttons configured
8421 if (action != ACTION_NONE && !finished)
8423 for (x = 0; x < MAX_GRID_XSIZE; x++)
8424 for (y = 0; y < MAX_GRID_YSIZE; y++)
8425 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8427 overlay.grid_button_highlight = grid_button[step_nr];
8429 // configure next virtual button
8433 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8434 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8435 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8438 if (set_grid_button)
8440 overlay.grid_button[x][y] =
8441 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8442 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8443 grid_button_tmp[x][y]);
8445 set_grid_button = FALSE;
8452 for (x = 0; x < MAX_GRID_XSIZE; x++)
8453 for (y = 0; y < MAX_GRID_YSIZE; y++)
8454 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8456 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8458 SetOverlayShowGrid(FALSE);
8463 void ConfigureVirtualButtons(void)
8465 boolean success = ConfigureVirtualButtonsMain();
8467 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8468 SCREEN_MASK_TOUCH2);
8472 int font_nr = FONT_TITLE_1;
8473 int font_height = getFontHeight(font_nr);
8474 int ypos1 = SYSIZE / 2 - font_height * 2;
8475 int ypos2 = SYSIZE / 2 - font_height * 1;
8476 unsigned int wait_frame_delay = 0;
8477 unsigned int wait_frame_delay_value = 2000;
8479 ResetDelayCounter(&wait_frame_delay);
8483 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8484 DrawTextSCentered(ypos2, font_nr, "configured!");
8486 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8493 void DrawSetupScreen(void)
8498 if (setup_mode == SETUP_MODE_INPUT)
8499 DrawSetupScreen_Input();
8500 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8501 DrawChooseTree(&game_speed_current);
8502 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8503 DrawChooseTree(&scroll_delay_current);
8504 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8505 DrawChooseTree(&snapshot_mode_current);
8506 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8507 DrawChooseTree(&window_size_current);
8508 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8509 DrawChooseTree(&scaling_type_current);
8510 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8511 DrawChooseTree(&rendering_mode_current);
8512 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8513 DrawChooseTree(&vsync_mode_current);
8514 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8515 DrawChooseTree(&artwork.gfx_current);
8516 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8517 DrawChooseTree(&artwork.snd_current);
8518 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8519 DrawChooseTree(&artwork.mus_current);
8520 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8521 DrawChooseTree(&volume_simple_current);
8522 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8523 DrawChooseTree(&volume_loops_current);
8524 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8525 DrawChooseTree(&volume_music_current);
8526 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8527 DrawChooseTree(&touch_control_current);
8528 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8529 DrawChooseTree(&move_distance_current);
8530 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8531 DrawChooseTree(&drop_distance_current);
8532 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8533 DrawChooseTree(&transparency_current);
8534 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8535 DrawChooseTree(&grid_size_current[0][0]);
8536 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8537 DrawChooseTree(&grid_size_current[0][1]);
8538 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8539 DrawChooseTree(&grid_size_current[1][0]);
8540 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8541 DrawChooseTree(&grid_size_current[1][1]);
8543 DrawSetupScreen_Generic();
8545 PlayMenuSoundsAndMusic();
8548 void RedrawSetupScreenAfterFullscreenToggle(void)
8550 if (setup_mode == SETUP_MODE_GRAPHICS ||
8551 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8553 // update list selection from "setup.window_scaling_percent"
8554 execSetupGraphics_setWindowSizes(TRUE);
8560 void RedrawSetupScreenAfterScreenRotation(int nr)
8564 if (setup_mode == SETUP_MODE_TOUCH)
8566 // update virtual button settings (depending on screen orientation)
8569 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8571 // save already configured virtual buttons
8572 for (x = 0; x < MAX_GRID_XSIZE; x++)
8573 for (y = 0; y < MAX_GRID_YSIZE; y++)
8574 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8578 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8580 if (setup_mode == SETUP_MODE_INPUT)
8581 HandleSetupScreen_Input(mx, my, dx, dy, button);
8582 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8583 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8584 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8585 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8586 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8587 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8588 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8589 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8590 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8591 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8592 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8593 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8594 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8595 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8596 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8597 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8598 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8599 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8600 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8601 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8602 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8603 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8604 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8605 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8606 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8607 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8608 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8609 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8610 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8611 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8612 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8613 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8614 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8615 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8616 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8617 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8618 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8619 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8620 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8621 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8622 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8623 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8625 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8628 void HandleGameActions(void)
8630 if (setup.ask_on_game_over)
8633 if (game.restart_game_message != NULL)
8635 RequestRestartGame(game.restart_game_message);
8640 if (game_status != GAME_MODE_PLAYING)
8643 GameActions(); // main game loop
8645 if (tape.auto_play && !tape.playing)
8646 AutoPlayTapes(); // continue automatically playing next tape
8650 // ---------- new screen button stuff --------------------------------------
8654 int gfx_unpressed, gfx_pressed;
8655 struct MenuPosInfo *pos;
8656 boolean *check_value;
8659 unsigned int event_mask;
8660 boolean is_touch_button;
8662 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8665 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8666 &menu.main.button.prev_level, NULL,
8667 SCREEN_CTRL_ID_PREV_LEVEL,
8669 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8670 FALSE, "previous level"
8673 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8674 &menu.main.button.next_level, NULL,
8675 SCREEN_CTRL_ID_NEXT_LEVEL,
8677 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8681 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
8682 &menu.main.button.first_level, NULL,
8683 SCREEN_CTRL_ID_FIRST_LEVEL,
8686 FALSE, "first level"
8689 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
8690 &menu.main.button.last_level, NULL,
8691 SCREEN_CTRL_ID_LAST_LEVEL,
8697 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
8698 &menu.main.button.level_number, NULL,
8699 SCREEN_CTRL_ID_LEVEL_NUMBER,
8702 FALSE, "level number"
8705 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8706 &menu.setup.button.prev_player, NULL,
8707 SCREEN_CTRL_ID_PREV_PLAYER,
8709 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8710 FALSE, "previous player"
8713 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8714 &menu.setup.button.next_player, NULL,
8715 SCREEN_CTRL_ID_NEXT_PLAYER,
8717 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8718 FALSE, "next player"
8721 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8722 &menu.main.button.insert_solution, NULL,
8723 SCREEN_CTRL_ID_INSERT_SOLUTION,
8724 SCREEN_MASK_MAIN_HAS_SOLUTION,
8726 FALSE, "insert solution tape"
8729 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8730 &menu.main.button.play_solution, NULL,
8731 SCREEN_CTRL_ID_PLAY_SOLUTION,
8732 SCREEN_MASK_MAIN_HAS_SOLUTION,
8734 FALSE, "play solution tape"
8737 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
8738 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
8739 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
8741 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
8742 FALSE, "switch ECS/AGA chipset"
8745 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
8746 &menu.setup.button.touch_back, NULL,
8747 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
8750 TRUE, "previous page"
8753 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
8754 &menu.setup.button.touch_next, NULL,
8755 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
8761 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
8762 &menu.setup.button.touch_back2, NULL,
8763 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
8766 TRUE, "previous page"
8769 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
8770 &menu.setup.button.touch_next2, NULL,
8771 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
8780 int gfx_unpressed, gfx_pressed;
8784 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8787 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8788 -1, -1, // these values are not constant, but can change at runtime
8789 SCREEN_CTRL_ID_SCROLL_UP,
8793 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8794 -1, -1, // these values are not constant, but can change at runtime
8795 SCREEN_CTRL_ID_SCROLL_DOWN,
8802 int gfx_unpressed, gfx_pressed;
8808 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8811 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8812 -1, -1, // these values are not constant, but can change at runtime
8813 -1, -1, // these values are not constant, but can change at runtime
8814 GD_TYPE_SCROLLBAR_VERTICAL,
8815 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8816 "scroll level series vertically"
8828 } textinput_info[NUM_SCREEN_TEXTINPUT] =
8831 IMG_SETUP_INPUT_TEXT,
8832 SCREEN_CTRL_ID_NETWORK_SERVER,
8833 -1, -1, // these values are not constant, but can change at runtime
8834 MAX_SETUP_TEXT_INPUT_LEN,
8835 network_server_hostname,
8836 "Network Server Hostname / IP"
8840 static void CreateScreenMenubuttons(void)
8842 struct GadgetInfo *gi;
8843 unsigned int event_mask;
8846 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8848 struct MenuPosInfo *pos = menubutton_info[i].pos;
8849 boolean is_touch_button = menubutton_info[i].is_touch_button;
8850 boolean is_check_button = menubutton_info[i].check_value != NULL;
8851 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8852 int gfx_unpressed, gfx_pressed;
8853 int x, y, width, height;
8854 int gd_x1, gd_x2, gd_y1, gd_y2;
8855 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
8856 int id = menubutton_info[i].gadget_id;
8857 int type = GD_TYPE_NORMAL_BUTTON;
8858 boolean checked = FALSE;
8860 event_mask = menubutton_info[i].event_mask;
8862 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
8863 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
8865 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8866 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8868 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8869 gfx_pressed = menubutton_info[i].gfx_pressed;
8870 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8871 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8872 gd_x1 = graphic_info[gfx_unpressed].src_x;
8873 gd_y1 = graphic_info[gfx_unpressed].src_y;
8874 gd_x2 = graphic_info[gfx_pressed].src_x;
8875 gd_y2 = graphic_info[gfx_pressed].src_y;
8881 if (is_touch_button)
8883 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
8884 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
8887 if (is_check_button)
8889 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
8890 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
8891 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
8892 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
8894 type = GD_TYPE_CHECK_BUTTON;
8895 checked = *menubutton_info[i].check_value;
8898 gi = CreateGadget(GDI_CUSTOM_ID, id,
8899 GDI_CUSTOM_TYPE_ID, i,
8900 GDI_IMAGE_ID, gfx_unpressed,
8901 GDI_INFO_TEXT, menubutton_info[i].infotext,
8907 GDI_STATE, GD_BUTTON_UNPRESSED,
8908 GDI_CHECKED, checked,
8909 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8910 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8911 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
8912 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
8913 GDI_DIRECT_DRAW, FALSE,
8914 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
8915 GDI_EVENT_MASK, event_mask,
8916 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8920 Fail("cannot create gadget");
8922 screen_gadget[id] = gi;
8926 static void CreateScreenScrollbuttons(void)
8928 struct GadgetInfo *gi;
8929 unsigned int event_mask;
8932 // these values are not constant, but can change at runtime
8933 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8934 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8935 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8936 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8938 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8940 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8941 int gfx_unpressed, gfx_pressed;
8942 int x, y, width, height;
8943 int gd_x1, gd_x2, gd_y1, gd_y2;
8944 int id = scrollbutton_info[i].gadget_id;
8946 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8948 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8949 y = mSY + scrollbutton_info[i].y;
8950 width = SC_SCROLLBUTTON_XSIZE;
8951 height = SC_SCROLLBUTTON_YSIZE;
8953 // correct scrollbar position if placed outside menu (playfield) area
8954 if (x > SX + SC_SCROLL_UP_XPOS)
8955 x = SX + SC_SCROLL_UP_XPOS;
8957 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8958 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8959 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8961 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8962 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8963 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8964 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8965 gd_x1 = graphic_info[gfx_unpressed].src_x;
8966 gd_y1 = graphic_info[gfx_unpressed].src_y;
8967 gd_x2 = graphic_info[gfx_pressed].src_x;
8968 gd_y2 = graphic_info[gfx_pressed].src_y;
8970 gi = CreateGadget(GDI_CUSTOM_ID, id,
8971 GDI_CUSTOM_TYPE_ID, i,
8972 GDI_IMAGE_ID, gfx_unpressed,
8973 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8978 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8979 GDI_STATE, GD_BUTTON_UNPRESSED,
8980 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8981 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8982 GDI_DIRECT_DRAW, FALSE,
8983 GDI_EVENT_MASK, event_mask,
8984 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8988 Fail("cannot create gadget");
8990 screen_gadget[id] = gi;
8994 static void CreateScreenScrollbars(void)
8998 // these values are not constant, but can change at runtime
8999 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9000 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9001 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9002 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9004 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9006 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9007 int gfx_unpressed, gfx_pressed;
9008 int x, y, width, height;
9009 int gd_x1, gd_x2, gd_y1, gd_y2;
9010 struct GadgetInfo *gi;
9011 int items_max, items_visible, item_position;
9012 unsigned int event_mask;
9013 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9014 int id = scrollbar_info[i].gadget_id;
9016 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9018 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9019 y = mSY + scrollbar_info[i].y;
9020 width = scrollbar_info[i].width;
9021 height = scrollbar_info[i].height;
9023 // correct scrollbar position if placed outside menu (playfield) area
9024 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9025 x = SX + SC_SCROLL_VERTICAL_XPOS;
9027 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9028 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9030 items_max = num_page_entries;
9031 items_visible = num_page_entries;
9034 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9035 gfx_pressed = scrollbar_info[i].gfx_pressed;
9036 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9037 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9038 gd_x1 = graphic_info[gfx_unpressed].src_x;
9039 gd_y1 = graphic_info[gfx_unpressed].src_y;
9040 gd_x2 = graphic_info[gfx_pressed].src_x;
9041 gd_y2 = graphic_info[gfx_pressed].src_y;
9043 gi = CreateGadget(GDI_CUSTOM_ID, id,
9044 GDI_CUSTOM_TYPE_ID, i,
9045 GDI_IMAGE_ID, gfx_unpressed,
9046 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9051 GDI_TYPE, scrollbar_info[i].type,
9052 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9053 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9054 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9055 GDI_WHEEL_AREA_X, SX,
9056 GDI_WHEEL_AREA_Y, SY,
9057 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9058 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9059 GDI_STATE, GD_BUTTON_UNPRESSED,
9060 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9061 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9062 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9063 GDI_DIRECT_DRAW, FALSE,
9064 GDI_EVENT_MASK, event_mask,
9065 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9069 Fail("cannot create gadget");
9071 screen_gadget[id] = gi;
9075 static void CreateScreenTextInputGadgets(void)
9079 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9081 int graphic = textinput_info[i].graphic;
9082 struct GraphicInfo *gd = &graphic_info[graphic];
9083 int gd_x1 = gd->src_x;
9084 int gd_y1 = gd->src_y;
9085 int gd_x2 = gd->src_x + gd->active_xoffset;
9086 int gd_y2 = gd->src_y + gd->active_yoffset;
9087 struct GadgetInfo *gi;
9088 unsigned int event_mask;
9089 int id = textinput_info[i].gadget_id;
9090 int x = textinput_info[i].x;
9091 int y = textinput_info[i].y;
9093 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9095 gi = CreateGadget(GDI_CUSTOM_ID, id,
9096 GDI_CUSTOM_TYPE_ID, i,
9097 GDI_INFO_TEXT, textinput_info[i].infotext,
9100 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9101 GDI_TEXT_VALUE, textinput_info[i].value,
9102 GDI_TEXT_SIZE, textinput_info[i].size,
9103 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9104 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9105 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9106 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9107 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9108 GDI_DESIGN_WIDTH, gd->width,
9109 GDI_EVENT_MASK, event_mask,
9110 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9111 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9115 Fail("cannot create gadget");
9117 screen_gadget[id] = gi;
9121 void CreateScreenGadgets(void)
9123 CreateScreenMenubuttons();
9125 CreateScreenScrollbuttons();
9126 CreateScreenScrollbars();
9128 CreateScreenTextInputGadgets();
9131 void FreeScreenGadgets(void)
9135 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9136 FreeGadget(screen_gadget[i]);
9139 static void MapScreenMenuGadgets(int screen_mask)
9143 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9144 if (screen_mask & menubutton_info[i].screen_mask)
9145 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9148 static void UnmapScreenMenuGadgets(int screen_mask)
9152 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9154 if (screen_mask & menubutton_info[i].screen_mask)
9156 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9158 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9159 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9160 screen_gadget[menubutton_info[i].gadget_id]->y,
9161 screen_gadget[menubutton_info[i].gadget_id]->width,
9162 screen_gadget[menubutton_info[i].gadget_id]->height);
9167 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9170 MapScreenMenuGadgets(screen_mask);
9172 UnmapScreenMenuGadgets(screen_mask);
9175 static void MapScreenGadgets(int num_entries)
9179 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9182 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9183 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9185 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9186 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9189 static void MapScreenTreeGadgets(TreeInfo *ti)
9191 MapScreenGadgets(numTreeInfoInGroup(ti));
9194 static void HandleScreenGadgets(struct GadgetInfo *gi)
9196 int id = gi->custom_id;
9197 int button = gi->event.button;
9198 int step = (button == MB_LEFTBUTTON ? 1 :
9199 button == MB_MIDDLEBUTTON ? 5 :
9200 button == MB_RIGHTBUTTON ? 10 : 1);
9204 case SCREEN_CTRL_ID_PREV_LEVEL:
9205 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9208 case SCREEN_CTRL_ID_NEXT_LEVEL:
9209 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9212 case SCREEN_CTRL_ID_FIRST_LEVEL:
9213 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9216 case SCREEN_CTRL_ID_LAST_LEVEL:
9217 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9220 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9221 CloseDoor(DOOR_CLOSE_2);
9222 SetGameStatus(GAME_MODE_LEVELNR);
9223 DrawChooseLevelNr();
9226 case SCREEN_CTRL_ID_PREV_PLAYER:
9227 HandleSetupScreen_Input_Player(step, -1);
9230 case SCREEN_CTRL_ID_NEXT_PLAYER:
9231 HandleSetupScreen_Input_Player(step, +1);
9234 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9235 InsertSolutionTape();
9238 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9242 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9243 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9247 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9248 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9249 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9250 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9251 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9254 case SCREEN_CTRL_ID_SCROLL_UP:
9255 if (game_status == GAME_MODE_NAMES)
9256 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9257 else if (game_status == GAME_MODE_LEVELS)
9258 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9259 else if (game_status == GAME_MODE_LEVELNR)
9260 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9261 else if (game_status == GAME_MODE_SETUP)
9262 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9263 else if (game_status == GAME_MODE_INFO)
9264 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9267 case SCREEN_CTRL_ID_SCROLL_DOWN:
9268 if (game_status == GAME_MODE_NAMES)
9269 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9270 else if (game_status == GAME_MODE_LEVELS)
9271 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9272 else if (game_status == GAME_MODE_LEVELNR)
9273 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9274 else if (game_status == GAME_MODE_SETUP)
9275 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9276 else if (game_status == GAME_MODE_INFO)
9277 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9280 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9281 if (game_status == GAME_MODE_NAMES)
9282 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9283 else if (game_status == GAME_MODE_LEVELS)
9284 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9285 else if (game_status == GAME_MODE_LEVELNR)
9286 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9287 else if (game_status == GAME_MODE_SETUP)
9288 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9289 else if (game_status == GAME_MODE_INFO)
9290 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9293 case SCREEN_CTRL_ID_NETWORK_SERVER:
9295 if (!strEqual(gi->textinput.value, ""))
9297 setString(&setup.network_server_hostname, gi->textinput.value);
9299 network.server_host = setup.network_server_hostname;
9303 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9305 network.server_host = NULL;
9308 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9309 network.server_host = NULL;
9311 execSetupGame_setNetworkServerText();
9323 void DumpScreenIdentifiers(void)
9327 Print("Active screen elements on current screen:\n");
9329 for (i = 0; main_controls[i].nr != -1; i++)
9331 struct MainControlInfo *mci = &main_controls[i];
9333 if (mci->button_graphic != -1)
9335 char *token = getTokenFromImageID(mci->button_graphic);
9337 Print("- '%s'\n", token);
9344 boolean DoScreenAction(int image_id)
9348 if (game_status != GAME_MODE_MAIN)
9351 for (i = 0; main_controls[i].nr != -1; i++)
9353 struct MainControlInfo *mci = &main_controls[i];
9354 struct MenuPosInfo *pos = mci->pos_button;
9356 if (mci->button_graphic == image_id)
9358 int x = mSX + pos->x;
9359 int y = mSY + pos->y;
9361 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9370 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9372 // get tree info node of newly added level or artwork set
9373 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9374 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9376 if (tree_node_new == NULL) // should not happen
9379 // if request dialog is active, do nothing
9380 if (game.request_active)
9383 if (game_status == GAME_MODE_MAIN &&
9384 tree_type == TREE_TYPE_LEVEL_DIR)
9386 // when adding new level set in main menu, select it as current level set
9388 // change current level set to newly added level set from zip file
9389 leveldir_current = tree_node_new;
9391 // change current level number to first level of newly added level set
9392 level_nr = leveldir_current->first_level;
9394 // redraw screen to reflect changed level set
9397 // save this level set and level number as last selected level set
9398 SaveLevelSetup_LastSeries();
9399 SaveLevelSetup_SeriesInfo();
9401 else if (game_status == GAME_MODE_LEVELS &&
9402 tree_type == TREE_TYPE_LEVEL_DIR)
9404 // when adding new level set in level set menu, set cursor and update screen
9406 leveldir_current = tree_node_new;
9408 DrawChooseTree(&leveldir_current);
9410 else if (game_status == GAME_MODE_SETUP)
9412 // when adding new artwork set in setup menu, set cursor and update screen
9414 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9415 tree_type == TREE_TYPE_GRAPHICS_DIR)
9417 artwork.gfx_current = tree_node_new;
9419 DrawChooseTree(&artwork.gfx_current);
9421 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9422 tree_type == TREE_TYPE_SOUNDS_DIR)
9424 artwork.snd_current = tree_node_new;
9426 DrawChooseTree(&artwork.snd_current);
9428 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9429 tree_type == TREE_TYPE_MUSIC_DIR)
9431 artwork.mus_current = tree_node_new;
9433 DrawChooseTree(&artwork.mus_current);