1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://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_EDITOR 2
48 #define SETUP_MODE_GRAPHICS 3
49 #define SETUP_MODE_SOUND 4
50 #define SETUP_MODE_ARTWORK 5
51 #define SETUP_MODE_INPUT 6
52 #define SETUP_MODE_TOUCH 7
53 #define SETUP_MODE_SHORTCUTS 8
54 #define SETUP_MODE_SHORTCUTS_1 9
55 #define SETUP_MODE_SHORTCUTS_2 10
56 #define SETUP_MODE_SHORTCUTS_3 11
57 #define SETUP_MODE_SHORTCUTS_4 12
58 #define SETUP_MODE_SHORTCUTS_5 13
60 // sub-screens on the setup screen (generic)
61 #define SETUP_MODE_CHOOSE_ARTWORK 14
62 #define SETUP_MODE_CHOOSE_OTHER 15
64 // sub-screens on the setup screen (specific)
65 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
66 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
67 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
68 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
69 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
70 #define SETUP_MODE_CHOOSE_RENDERING 21
71 #define SETUP_MODE_CHOOSE_VSYNC 22
72 #define SETUP_MODE_CHOOSE_GRAPHICS 23
73 #define SETUP_MODE_CHOOSE_SOUNDS 24
74 #define SETUP_MODE_CHOOSE_MUSIC 25
75 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 26
76 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 27
77 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 28
78 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 29
79 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 30
80 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 31
81 #define SETUP_MODE_CHOOSE_TRANSPARENCY 32
82 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 33
83 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 36
86 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 37
88 #define MAX_SETUP_MODES 38
90 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
92 // setup screen titles
93 #define STR_SETUP_MAIN "Setup"
94 #define STR_SETUP_GAME "Game & Menu"
95 #define STR_SETUP_EDITOR "Editor"
96 #define STR_SETUP_GRAPHICS "Graphics"
97 #define STR_SETUP_SOUND "Sound & Music"
98 #define STR_SETUP_ARTWORK "Custom Artwork"
99 #define STR_SETUP_INPUT "Input Devices"
100 #define STR_SETUP_TOUCH "Touch Controls"
101 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
102 #define STR_SETUP_EXIT "Exit"
103 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
105 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
106 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
107 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
108 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
109 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
110 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
111 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
112 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
113 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
114 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
115 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
116 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
117 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
118 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
119 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
120 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
121 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
122 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
124 // for input setup functions
125 #define SETUPINPUT_SCREEN_POS_START 0
126 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
127 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
128 #define SETUPINPUT_SCREEN_POS_END 13
130 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
131 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
133 #define MAX_SETUP_TEXT_INPUT_LEN 28
135 // for various menu stuff
136 #define MENU_SCREEN_START_XPOS 1
137 #define MENU_SCREEN_START_YPOS 2
138 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
139 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
140 #define MENU_TITLE1_YPOS 8
141 #define MENU_TITLE2_YPOS 46
142 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
143 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
144 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
145 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
146 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
147 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
148 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
149 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
150 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
151 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
152 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
153 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
154 MENU_INFO_FONT_TITLE))
155 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
156 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
157 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
158 MENU_SCREEN_INFO_YSTART2 - \
160 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
161 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
162 MENU_SCREEN_INFO_YSTEP)
163 #define NUM_INFO_ELEMENTS_FROM_CONF \
164 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
165 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
166 MAX_MENU_ENTRIES_ON_SCREEN)
167 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
168 MAX_INFO_ELEMENTS_ON_SCREEN), \
169 NUM_INFO_ELEMENTS_FROM_CONF)
170 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
171 #define MAX_MENU_TEXT_LENGTH_BIG 13
172 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
174 // screen gadget identifiers
175 #define SCREEN_CTRL_ID_PREV_LEVEL 0
176 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
177 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
178 #define SCREEN_CTRL_ID_LAST_LEVEL 3
179 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
180 #define SCREEN_CTRL_ID_PREV_PLAYER 5
181 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
182 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
183 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
184 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
185 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
186 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
187 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
188 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
189 #define SCREEN_CTRL_ID_SCROLL_UP 14
190 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
191 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
192 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
194 #define NUM_SCREEN_GADGETS 18
196 #define NUM_SCREEN_MENUBUTTONS 14
197 #define NUM_SCREEN_SCROLLBUTTONS 2
198 #define NUM_SCREEN_SCROLLBARS 1
199 #define NUM_SCREEN_TEXTINPUT 1
201 #define SCREEN_MASK_MAIN (1 << 0)
202 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
203 #define SCREEN_MASK_INPUT (1 << 2)
204 #define SCREEN_MASK_TOUCH (1 << 3)
205 #define SCREEN_MASK_TOUCH2 (1 << 4)
207 // graphic position and size values for buttons and scrollbars
208 #define SC_MENUBUTTON_XSIZE TILEX
209 #define SC_MENUBUTTON_YSIZE TILEY
211 #define SC_SCROLLBUTTON_XSIZE TILEX
212 #define SC_SCROLLBUTTON_YSIZE TILEY
214 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
216 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
217 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
218 SC_SCROLLBUTTON_YSIZE)
220 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
221 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
223 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
224 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
225 SC_SCROLLBUTTON_YSIZE)
227 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
228 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
229 SC_SCROLL_VERTICAL_YSIZE)
231 #define SC_BORDER_SIZE 14
234 // forward declarations of internal functions
235 static void HandleScreenGadgets(struct GadgetInfo *);
236 static void HandleSetupScreen_Generic(int, int, int, int, int);
237 static void HandleSetupScreen_Input(int, int, int, int, int);
238 static void CustomizeKeyboard(int);
239 static void ConfigureJoystick(int);
240 static void ConfigureVirtualButtons(void);
241 static void execSetupGame(void);
242 static void execSetupGraphics(void);
243 static void execSetupSound(void);
244 static void execSetupTouch(void);
245 static void execSetupArtwork(void);
246 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
248 static void DrawChooseLevelSet(void);
249 static void DrawChooseLevelNr(void);
250 static void DrawInfoScreen(void);
251 static void DrawSetupScreen(void);
253 static void DrawInfoScreen_NotAvailable(char *, char *);
254 static void DrawInfoScreen_HelpAnim(int, int, boolean);
255 static void DrawInfoScreen_HelpText(int, int, int, int);
256 static void HandleInfoScreen_Main(int, int, int, int, int);
257 static void HandleInfoScreen_TitleScreen(int);
258 static void HandleInfoScreen_Elements(int);
259 static void HandleInfoScreen_Music(int);
260 static void HandleInfoScreen_Credits(int);
261 static void HandleInfoScreen_Program(int);
262 static void HandleInfoScreen_Version(int);
264 static void ModifyGameSpeedIfNeeded(void);
265 static void DisableVsyncIfNeeded(void);
267 static void MapScreenMenuGadgets(int);
268 static void UnmapScreenMenuGadgets(int);
269 static void MapScreenGadgets(int);
270 static void MapScreenTreeGadgets(TreeInfo *);
272 static void UpdateScreenMenuGadgets(int, boolean);
274 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
276 static int info_mode = INFO_MODE_MAIN;
277 static int setup_mode = SETUP_MODE_MAIN;
279 static TreeInfo *window_sizes = NULL;
280 static TreeInfo *window_size_current = NULL;
282 static TreeInfo *scaling_types = NULL;
283 static TreeInfo *scaling_type_current = NULL;
285 static TreeInfo *rendering_modes = NULL;
286 static TreeInfo *rendering_mode_current = NULL;
288 static TreeInfo *vsync_modes = NULL;
289 static TreeInfo *vsync_mode_current = NULL;
291 static TreeInfo *scroll_delays = NULL;
292 static TreeInfo *scroll_delay_current = NULL;
294 static TreeInfo *snapshot_modes = NULL;
295 static TreeInfo *snapshot_mode_current = NULL;
297 static TreeInfo *game_speeds_normal = NULL;
298 static TreeInfo *game_speeds_extended = NULL;
299 static TreeInfo *game_speeds = NULL;
300 static TreeInfo *game_speed_current = NULL;
302 static TreeInfo *volumes_simple = NULL;
303 static TreeInfo *volume_simple_current = NULL;
305 static TreeInfo *volumes_loops = NULL;
306 static TreeInfo *volume_loops_current = NULL;
308 static TreeInfo *volumes_music = NULL;
309 static TreeInfo *volume_music_current = NULL;
311 static TreeInfo *touch_controls = NULL;
312 static TreeInfo *touch_control_current = NULL;
314 static TreeInfo *move_distances = NULL;
315 static TreeInfo *move_distance_current = NULL;
317 static TreeInfo *drop_distances = NULL;
318 static TreeInfo *drop_distance_current = NULL;
320 static TreeInfo *transparencies = NULL;
321 static TreeInfo *transparency_current = NULL;
323 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
324 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
326 static TreeInfo *level_number = NULL;
327 static TreeInfo *level_number_current = NULL;
329 static struct ValueTextInfo window_sizes_list[] =
334 { 100, "100 % (Default)" },
347 static struct StringValueTextInfo scaling_types_list[] =
349 { SCALING_QUALITY_NEAREST, "Off" },
350 { SCALING_QUALITY_LINEAR, "Linear" },
351 { SCALING_QUALITY_BEST, "Anisotropic" },
356 static struct StringValueTextInfo rendering_modes_list[] =
358 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
359 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
361 // this mode may work under certain conditions, but does not work on Windows
362 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
364 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
369 static struct StringValueTextInfo vsync_modes_list[] =
371 { STR_VSYNC_MODE_OFF, "Off" },
372 { STR_VSYNC_MODE_NORMAL, "Normal" },
373 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
378 static struct ValueTextInfo game_speeds_list_normal[] =
389 static struct ValueTextInfo game_speeds_list_extended[] =
391 { 1000, "1 fps (Extremely Slow)" },
396 { 29, "35 fps (Original Supaplex)" },
398 { 20, "50 fps (=== Normal Speed ===)" },
399 { 16, "60 fps (60 Hz VSync Speed)" },
400 { 14, "70 fps (Maximum Supaplex)" },
404 { 1, "1000 fps (Extremely Fast)" },
409 static struct ValueTextInfo *game_speeds_list;
411 static struct ValueTextInfo scroll_delays_list[] =
413 { 0, "0 Tiles (No Scroll Delay)" },
416 { 3, "3 Tiles (Default)" },
421 { 8, "8 Tiles (Maximum Scroll Delay)"},
426 static struct StringValueTextInfo snapshot_modes_list[] =
428 { STR_SNAPSHOT_MODE_OFF, "Off" },
429 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
430 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
431 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
436 static struct ValueTextInfo volumes_list[] =
456 static struct StringValueTextInfo touch_controls_list[] =
458 { TOUCH_CONTROL_OFF, "Off" },
459 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
460 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
461 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
466 static struct ValueTextInfo distances_list[] =
481 static struct ValueTextInfo transparencies_list[] =
483 { 0, "0 % (Opaque)" },
493 { 100, "100 % (Invisible)" },
498 static struct ValueTextInfo grid_sizes_list[] =
534 static int align_xoffset = 0;
535 static int align_yoffset = 0;
537 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
538 (s) <= GAME_MODE_SETUP ? (s) : \
539 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
540 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
542 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
543 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
544 (i) <= INFO_MODE_LEVELSET ? (i) : \
547 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
548 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
549 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
550 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
551 SETUP_MODE_CHOOSE_ARTWORK : \
552 SETUP_MODE_CHOOSE_OTHER)
554 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
555 menu.draw_xoffset[GAME_MODE_INFO] : \
556 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
557 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
558 menu.draw_yoffset[GAME_MODE_INFO] : \
559 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
560 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
561 menu.extra_spacing[GAME_MODE_INFO] : \
562 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
564 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
565 menu.draw_xoffset[GAME_MODE_SETUP] : \
566 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
567 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
568 menu.draw_yoffset[GAME_MODE_SETUP] : \
569 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
570 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
571 menu.extra_spacing[GAME_MODE_SETUP] : \
572 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
574 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
575 DRAW_XOFFSET_INFO(info_mode) : \
576 (s) == GAME_MODE_SETUP ? \
577 DRAW_XOFFSET_SETUP(setup_mode) : \
578 menu.draw_xoffset[DRAW_MODE(s)])
579 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
580 DRAW_YOFFSET_INFO(info_mode) : \
581 (s) == GAME_MODE_SETUP ? \
582 DRAW_YOFFSET_SETUP(setup_mode) : \
583 menu.draw_yoffset[DRAW_MODE(s)])
584 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
585 EXTRA_SPACING_INFO(info_mode) : \
586 (s) == GAME_MODE_SETUP ? \
587 EXTRA_SPACING_SETUP(setup_mode) : \
588 menu.extra_spacing[DRAW_MODE(s)])
590 #define mSX (SX + DRAW_XOFFSET(game_status))
591 #define mSY (SY + DRAW_YOFFSET(game_status))
593 #define amSX (mSX + align_xoffset)
594 #define amSY (mSY + align_yoffset)
596 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
597 menu.list_size[game_status] : \
598 MAX_MENU_ENTRIES_ON_SCREEN)
600 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
601 NUM_MENU_ENTRIES_ON_SCREEN)
604 // title display and control definitions
606 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
607 2 * MAX_NUM_TITLE_MESSAGES)
609 #define NO_DIRECT_LEVEL_SELECT (-1)
612 static int num_title_screens = 0;
614 struct TitleControlInfo
623 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
625 // main menu display and control definitions
627 #define MAIN_CONTROL_NAME 0
628 #define MAIN_CONTROL_LEVELS 1
629 #define MAIN_CONTROL_SCORES 2
630 #define MAIN_CONTROL_EDITOR 3
631 #define MAIN_CONTROL_INFO 4
632 #define MAIN_CONTROL_GAME 5
633 #define MAIN_CONTROL_SETUP 6
634 #define MAIN_CONTROL_QUIT 7
635 #define MAIN_CONTROL_PREV_LEVEL 8
636 #define MAIN_CONTROL_NEXT_LEVEL 9
637 #define MAIN_CONTROL_FIRST_LEVEL 10
638 #define MAIN_CONTROL_LAST_LEVEL 11
639 #define MAIN_CONTROL_LEVEL_NUMBER 12
640 #define MAIN_CONTROL_LEVEL_INFO_1 13
641 #define MAIN_CONTROL_LEVEL_INFO_2 14
642 #define MAIN_CONTROL_LEVEL_NAME 15
643 #define MAIN_CONTROL_LEVEL_AUTHOR 16
644 #define MAIN_CONTROL_LEVEL_YEAR 17
645 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
646 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
647 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
648 #define MAIN_CONTROL_TITLE_1 21
649 #define MAIN_CONTROL_TITLE_2 22
650 #define MAIN_CONTROL_TITLE_3 23
652 static char str_main_text_name[10];
653 static char str_main_text_first_level[10];
654 static char str_main_text_last_level[10];
655 static char str_main_text_level_number[10];
657 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
659 static char *main_text_name = str_main_text_name;
660 static char *main_text_first_level = str_main_text_first_level;
661 static char *main_text_last_level = str_main_text_last_level;
662 static char *main_text_level_number = str_main_text_level_number;
663 static char *main_text_levels = "Levelset";
664 static char *main_text_scores = "Hall Of Fame";
665 static char *main_text_editor = "Level Creator";
666 static char *main_text_info = "Info Screen";
667 static char *main_text_game = "Start Game";
668 static char *main_text_setup = "Setup";
669 static char *main_text_quit = "Quit";
670 static char *main_text_level_name = level.name;
671 static char *main_text_level_author = level.author;
672 static char *main_text_level_year = NULL;
673 static char *main_text_level_imported_from = NULL;
674 static char *main_text_level_imported_by = NULL;
675 static char *main_text_level_tested_by = NULL;
676 static char *main_text_title_1 = NULL;
677 static char *main_text_title_2 = NULL;
678 static char *main_text_title_3 = NULL;
680 struct MainControlInfo
684 struct MenuPosInfo *pos_button;
687 struct TextPosInfo *pos_text;
690 struct TextPosInfo *pos_input;
694 static struct MainControlInfo main_controls[] =
698 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
699 &menu.main.text.name, &main_text_name,
700 &menu.main.input.name, &setup.player_name,
704 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
705 &menu.main.text.levels, &main_text_levels,
710 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
711 &menu.main.text.scores, &main_text_scores,
716 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
717 &menu.main.text.editor, &main_text_editor,
722 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
723 &menu.main.text.info, &main_text_info,
728 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
729 &menu.main.text.game, &main_text_game,
734 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
735 &menu.main.text.setup, &main_text_setup,
740 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
741 &menu.main.text.quit, &main_text_quit,
745 MAIN_CONTROL_PREV_LEVEL,
751 MAIN_CONTROL_NEXT_LEVEL,
757 MAIN_CONTROL_FIRST_LEVEL,
759 &menu.main.text.first_level, &main_text_first_level,
763 MAIN_CONTROL_LAST_LEVEL,
765 &menu.main.text.last_level, &main_text_last_level,
769 MAIN_CONTROL_LEVEL_NUMBER,
771 &menu.main.text.level_number, &main_text_level_number,
775 MAIN_CONTROL_LEVEL_INFO_1,
777 &menu.main.text.level_info_1, NULL,
781 MAIN_CONTROL_LEVEL_INFO_2,
783 &menu.main.text.level_info_2, NULL,
787 MAIN_CONTROL_LEVEL_NAME,
789 &menu.main.text.level_name, &main_text_level_name,
793 MAIN_CONTROL_LEVEL_AUTHOR,
795 &menu.main.text.level_author, &main_text_level_author,
799 MAIN_CONTROL_LEVEL_YEAR,
801 &menu.main.text.level_year, &main_text_level_year,
805 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
807 &menu.main.text.level_imported_from, &main_text_level_imported_from,
811 MAIN_CONTROL_LEVEL_IMPORTED_BY,
813 &menu.main.text.level_imported_by, &main_text_level_imported_by,
817 MAIN_CONTROL_LEVEL_TESTED_BY,
819 &menu.main.text.level_tested_by, &main_text_level_tested_by,
823 MAIN_CONTROL_TITLE_1,
825 &menu.main.text.title_1, &main_text_title_1,
829 MAIN_CONTROL_TITLE_2,
831 &menu.main.text.title_2, &main_text_title_2,
835 MAIN_CONTROL_TITLE_3,
837 &menu.main.text.title_3, &main_text_title_3,
850 static int getTitleScreenGraphic(int nr, boolean initial)
852 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
855 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
857 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
861 static int getTitleScreenGameMode(boolean initial)
863 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
867 static int getTitleMessageGameMode(boolean initial)
869 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
872 static int getTitleAnimMode(struct TitleControlInfo *tci)
874 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
876 return base + tci->local_nr;
880 static int getTitleScreenBackground(boolean initial)
882 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
887 static int getTitleMessageBackground(int nr, boolean initial)
889 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
893 static int getTitleBackground(int nr, boolean initial, boolean is_image)
895 int base = (is_image ?
896 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
897 IMG_BACKGROUND_TITLESCREEN_1) :
898 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
899 IMG_BACKGROUND_TITLEMESSAGE_1));
900 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
901 IMG_BACKGROUND_TITLE);
902 int graphic_local = base + nr;
904 if (graphic_info[graphic_local].bitmap != NULL)
905 return graphic_local;
907 if (graphic_info[graphic_global].bitmap != NULL)
908 return graphic_global;
910 return IMG_UNDEFINED;
913 static int getTitleSound(struct TitleControlInfo *tci)
915 boolean is_image = tci->is_image;
916 int initial = tci->initial;
917 int nr = tci->local_nr;
918 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
919 int base = (is_image ?
920 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
921 SND_BACKGROUND_TITLESCREEN_1) :
922 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
923 SND_BACKGROUND_TITLEMESSAGE_1));
924 int sound_global = menu.sound[mode];
925 int sound_local = base + nr;
928 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
929 nr, initial, is_image,
930 sound_global, getSoundListEntry(sound_global)->filename,
931 sound_local, getSoundListEntry(sound_local)->filename);
934 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
937 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
940 return SND_UNDEFINED;
943 static int getTitleMusic(struct TitleControlInfo *tci)
945 boolean is_image = tci->is_image;
946 int initial = tci->initial;
947 int nr = tci->local_nr;
948 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
949 int base = (is_image ?
950 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
951 MUS_BACKGROUND_TITLESCREEN_1) :
952 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
953 MUS_BACKGROUND_TITLEMESSAGE_1));
954 int music_global = menu.music[mode];
955 int music_local = base + nr;
958 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
959 nr, initial, is_image,
960 music_global, getMusicListEntry(music_global)->filename,
961 music_local, getMusicListEntry(music_local)->filename);
964 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
967 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
970 return MUS_UNDEFINED;
973 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
975 boolean is_image = tci->is_image;
976 boolean initial = tci->initial;
977 boolean first = tci->first;
978 int nr = tci->local_nr;
979 struct TitleMessageInfo tmi;
980 struct TitleFadingInfo ti;
982 tmi = (is_image ? (initial ? (first ?
983 titlescreen_initial_first[nr] :
984 titlescreen_initial[nr])
986 titlescreen_first[nr] :
988 : (initial ? (first ?
989 titlemessage_initial_first[nr] :
990 titlemessage_initial[nr])
992 titlemessage_first[nr] :
995 ti.fade_mode = tmi.fade_mode;
996 ti.fade_delay = tmi.fade_delay;
997 ti.post_delay = tmi.post_delay;
998 ti.auto_delay = tmi.auto_delay;
999 ti.auto_delay_unit = tmi.auto_delay_unit;
1004 static int compareTitleControlInfo(const void *object1, const void *object2)
1006 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1007 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1010 if (tci1->initial != tci2->initial)
1011 compare_result = (tci1->initial ? -1 : +1);
1012 else if (tci1->sort_priority != tci2->sort_priority)
1013 compare_result = tci1->sort_priority - tci2->sort_priority;
1014 else if (tci1->is_image != tci2->is_image)
1015 compare_result = (tci1->is_image ? -1 : +1);
1017 compare_result = tci1->local_nr - tci2->local_nr;
1019 return compare_result;
1022 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1024 int nr, int sort_priority)
1026 title_controls[num_title_screens].is_image = is_image;
1027 title_controls[num_title_screens].initial = initial;
1028 title_controls[num_title_screens].local_nr = nr;
1029 title_controls[num_title_screens].sort_priority = sort_priority;
1031 title_controls[num_title_screens].first = FALSE; // will be set later
1033 num_title_screens++;
1036 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1040 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1042 int graphic = getTitleScreenGraphic(i, initial);
1043 Bitmap *bitmap = graphic_info[graphic].bitmap;
1044 int sort_priority = graphic_info[graphic].sort_priority;
1047 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1050 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1052 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1053 char *filename = getLevelSetTitleMessageFilename(i, initial);
1054 int sort_priority = tmi->sort_priority;
1056 if (filename != NULL)
1057 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1061 static void InitializeTitleControls(boolean show_title_initial)
1063 num_title_screens = 0;
1065 // 1st step: initialize title screens for game start (only when starting)
1066 if (show_title_initial)
1067 InitializeTitleControls_CheckTitleInfo(TRUE);
1069 // 2nd step: initialize title screens for current level set
1070 InitializeTitleControls_CheckTitleInfo(FALSE);
1072 // sort title screens according to sort_priority and title number
1073 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1074 compareTitleControlInfo);
1076 // mark first title screen
1077 title_controls[0].first = TRUE;
1080 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1082 return (pos != NULL && pos->x != -1 && pos->y != -1);
1085 static boolean visibleTextPos(struct TextPosInfo *pos)
1087 return (pos != NULL && pos->x != -1 && pos->y != -1);
1090 static void InitializeMainControls(void)
1092 boolean local_team_mode = (!network.enabled && setup.team_mode);
1095 // set main control text values to dynamically determined values
1096 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1098 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1099 menu.main.text.first_level.size));
1100 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1101 menu.main.text.last_level.size));
1102 strcpy(main_text_level_number, int2str(level_nr,
1103 menu.main.text.level_number.size));
1105 main_text_level_year = leveldir_current->year;
1106 main_text_level_imported_from = leveldir_current->imported_from;
1107 main_text_level_imported_by = leveldir_current->imported_by;
1108 main_text_level_tested_by = leveldir_current->tested_by;
1110 main_text_title_1 = getConfigProgramTitleString();
1111 main_text_title_2 = getConfigProgramCopyrightString();
1112 main_text_title_3 = getConfigProgramCompanyString();
1114 // set main control screen positions to dynamically determined values
1115 for (i = 0; main_controls[i].nr != -1; i++)
1117 struct MainControlInfo *mci = &main_controls[i];
1119 struct MenuPosInfo *pos_button = mci->pos_button;
1120 struct TextPosInfo *pos_text = mci->pos_text;
1121 struct TextPosInfo *pos_input = mci->pos_input;
1122 char *text = (mci->text ? *mci->text : NULL);
1123 char *input = (mci->input ? *mci->input : NULL);
1124 int button_graphic = mci->button_graphic;
1125 int font_text = (pos_text ? pos_text->font : -1);
1126 int font_input = (pos_input ? pos_input->font : -1);
1128 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1129 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1130 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1131 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1132 int text_chars = (text != NULL ? strlen(text) : 0);
1133 int input_chars = (input != NULL ? strlen(input) : 0);
1136 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1138 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1139 int text_width = font_text_width * text_chars;
1140 int text_height = font_text_height;
1141 int input_width = font_input_width * input_chars;
1142 int input_height = font_input_height;
1144 if (nr == MAIN_CONTROL_NAME)
1146 menu.main.input.name.width = input_width;
1147 menu.main.input.name.height = input_height;
1150 if (pos_button != NULL) // (x/y may be -1/-1 here)
1152 pos_button->width = button_width;
1153 pos_button->height = button_height;
1156 if (pos_text != NULL) // (x/y may be -1/-1 here)
1158 // calculate text size -- needed for text alignment
1159 boolean calculate_text_size = (text != NULL);
1161 if (pos_text->width == -1 || calculate_text_size)
1162 pos_text->width = text_width;
1163 if (pos_text->height == -1 || calculate_text_size)
1164 pos_text->height = text_height;
1166 if (visibleMenuPos(pos_button))
1168 if (pos_text->x == -1)
1169 pos_text->x = pos_button->x + pos_button->width;
1170 if (pos_text->y == -1)
1172 pos_button->y + (pos_button->height - pos_text->height) / 2;
1176 if (pos_input != NULL) // (x/y may be -1/-1 here)
1178 if (visibleTextPos(pos_text))
1180 if (pos_input->x == -1)
1181 pos_input->x = pos_text->x + pos_text->width;
1182 if (pos_input->y == -1)
1183 pos_input->y = pos_text->y;
1186 if (pos_input->width == -1)
1187 pos_input->width = input_width;
1188 if (pos_input->height == -1)
1189 pos_input->height = input_height;
1194 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1195 int graphic, boolean pressed)
1197 struct GraphicInfo *g = &graphic_info[graphic];
1200 int xoffset = (pressed ? g->pressed_xoffset : 0);
1201 int yoffset = (pressed ? g->pressed_yoffset : 0);
1203 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1205 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1206 g->width, g->height, dst_x, dst_y);
1209 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1210 boolean active_input,
1211 boolean pressed_button)
1215 for (i = 0; main_controls[i].nr != -1; i++)
1217 struct MainControlInfo *mci = &main_controls[i];
1219 if (mci->nr == nr || nr == -1)
1221 struct MenuPosInfo *pos_button = mci->pos_button;
1222 struct TextPosInfo *pos_text = mci->pos_text;
1223 struct TextPosInfo *pos_input = mci->pos_input;
1224 char *text = (mci->text ? *mci->text : NULL);
1225 char *input = (mci->input ? *mci->input : NULL);
1226 int button_graphic = mci->button_graphic;
1227 int font_text = (pos_text ? pos_text->font : -1);
1228 int font_input = (pos_input ? pos_input->font : -1);
1232 button_graphic = BUTTON_ACTIVE(button_graphic);
1233 font_text = FONT_ACTIVE(font_text);
1238 font_input = FONT_ACTIVE(font_input);
1241 if (visibleMenuPos(pos_button))
1243 struct MenuPosInfo *pos = pos_button;
1244 int x = mSX + pos->x;
1245 int y = mSY + pos->y;
1247 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1248 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1251 if (visibleTextPos(pos_text) && text != NULL)
1253 struct TextPosInfo *pos = pos_text;
1254 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1255 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1258 // (check why/if this is needed)
1259 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1261 DrawText(x, y, text, font_text);
1264 if (visibleTextPos(pos_input) && input != NULL)
1266 struct TextPosInfo *pos = pos_input;
1267 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1268 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1271 // (check why/if this is needed)
1272 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1274 DrawText(x, y, input, font_input);
1280 static void DrawCursorAndText_Main(int nr, boolean active_text,
1281 boolean pressed_button)
1283 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1287 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1288 boolean pressed_button)
1290 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1294 static struct MainControlInfo *getMainControlInfo(int nr)
1298 for (i = 0; main_controls[i].nr != -1; i++)
1299 if (main_controls[i].nr == nr)
1300 return &main_controls[i];
1305 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1310 int rect_x = ALIGNED_TEXT_XPOS(rect);
1311 int rect_y = ALIGNED_TEXT_YPOS(rect);
1313 return (x >= rect_x && x < rect_x + rect->width &&
1314 y >= rect_y && y < rect_y + rect->height);
1317 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1322 int rect_x = ALIGNED_TEXT_XPOS(rect);
1323 int rect_y = ALIGNED_TEXT_YPOS(rect);
1326 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1327 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1328 (x >= rect_x && x < rect_x + rect->width &&
1329 y >= rect_y && y < rect_y + rect->height));
1332 return (x >= rect_x && x < rect_x + rect->width &&
1333 y >= rect_y && y < rect_y + rect->height);
1336 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1338 int rect_width = preview->xsize * preview->tile_size;
1339 int rect_height = preview->ysize * preview->tile_size;
1340 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1341 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1343 return (x >= rect_x && x < rect_x + rect_width &&
1344 y >= rect_y && y < rect_y + rect_height);
1347 static void AdjustScrollbar(int id, int items_max, int items_visible,
1350 struct GadgetInfo *gi = screen_gadget[id];
1352 if (item_position > items_max - items_visible)
1353 item_position = items_max - items_visible;
1355 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1356 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1357 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1360 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1362 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1366 static void clearMenuListArea(void)
1368 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1370 // correct scrollbar position if placed outside menu (playfield) area
1371 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1372 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1374 // clear menu list area, but not title or scrollbar
1375 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1376 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1379 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1381 static int cursor_array[MAX_LEV_FIELDY];
1382 int x = amSX + TILEX * xpos;
1383 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1388 cursor_array[ypos] = graphic;
1390 graphic = cursor_array[ypos];
1394 graphic = BUTTON_ACTIVE(graphic);
1396 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1397 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1400 static void initCursor(int ypos, int graphic)
1402 drawCursorExt(0, ypos, FALSE, graphic);
1405 static void drawCursor(int ypos, boolean active)
1407 drawCursorExt(0, ypos, active, -1);
1410 static void drawCursorXY(int xpos, int ypos, int graphic)
1412 drawCursorExt(xpos, ypos, FALSE, graphic);
1415 static void drawChooseTreeCursor(int ypos, boolean active)
1417 drawCursorExt(0, ypos, active, -1);
1420 static void DrawHeadline(void)
1422 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1423 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1426 static void DrawTitleScreenImage(int nr, boolean initial)
1428 int graphic = getTitleScreenGraphic(nr, initial);
1429 Bitmap *bitmap = graphic_info[graphic].bitmap;
1430 int width = graphic_info[graphic].width;
1431 int height = graphic_info[graphic].height;
1432 int src_x = graphic_info[graphic].src_x;
1433 int src_y = graphic_info[graphic].src_y;
1439 if (width > WIN_XSIZE)
1441 // image width too large for window => center image horizontally
1442 src_x = (width - WIN_XSIZE) / 2;
1446 if (height > WIN_YSIZE)
1448 // image height too large for window => center image vertically
1449 src_y = (height - WIN_YSIZE) / 2;
1453 // always display title screens centered
1454 dst_x = (WIN_XSIZE - width) / 2;
1455 dst_y = (WIN_YSIZE - height) / 2;
1457 SetDrawBackgroundMask(REDRAW_ALL);
1458 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1460 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1462 if (DrawingOnBackground(dst_x, dst_y))
1463 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1465 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1467 redraw_mask = REDRAW_ALL;
1470 static void DrawTitleScreenMessage(int nr, boolean initial)
1472 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1473 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1475 if (filename == NULL)
1478 // force TITLE font on title message screen
1479 SetFontStatus(getTitleMessageGameMode(initial));
1481 // if chars *and* width set to "-1", automatically determine width
1482 if (tmi->chars == -1 && tmi->width == -1)
1483 tmi->width = viewport.window[game_status].width;
1485 // if lines *and* height set to "-1", automatically determine height
1486 if (tmi->lines == -1 && tmi->height == -1)
1487 tmi->height = viewport.window[game_status].height;
1489 // if chars set to "-1", automatically determine by text and font width
1490 if (tmi->chars == -1)
1491 tmi->chars = tmi->width / getFontWidth(tmi->font);
1493 tmi->width = tmi->chars * getFontWidth(tmi->font);
1495 // if lines set to "-1", automatically determine by text and font height
1496 if (tmi->lines == -1)
1497 tmi->lines = tmi->height / getFontHeight(tmi->font);
1499 tmi->height = tmi->lines * getFontHeight(tmi->font);
1501 // if x set to "-1", automatically determine by width and alignment
1503 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1505 // if y set to "-1", automatically determine by height and alignment
1507 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1509 SetDrawBackgroundMask(REDRAW_ALL);
1510 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1512 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1514 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1515 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1516 tmi->autowrap, tmi->centered, tmi->parse_comments);
1521 static void DrawTitleScreen(void)
1523 KeyboardAutoRepeatOff();
1525 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1528 static boolean CheckTitleScreen(boolean levelset_has_changed)
1530 static boolean show_title_initial = TRUE;
1531 boolean show_titlescreen = FALSE;
1533 // needed to be able to skip title screen, if no image or message defined
1534 InitializeTitleControls(show_title_initial);
1536 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1537 show_titlescreen = TRUE;
1539 // show initial title images and messages only once at program start
1540 show_title_initial = FALSE;
1542 return (show_titlescreen && num_title_screens > 0);
1545 void DrawMainMenu(void)
1547 static LevelDirTree *leveldir_last_valid = NULL;
1548 boolean levelset_has_changed = FALSE;
1549 int fade_mask = REDRAW_FIELD;
1551 LimitScreenUpdates(FALSE);
1553 FadeSetLeaveScreen();
1555 // do not fade out here -- function may continue and fade on editor screen
1558 FadeMenuSoundsAndMusic();
1560 ExpireSoundLoops(FALSE);
1562 KeyboardAutoRepeatOn();
1564 audio.sound_deactivated = FALSE;
1568 // needed if last screen was the playing screen, invoked from level editor
1569 if (level_editor_test_game)
1571 CloseDoor(DOOR_CLOSE_ALL);
1573 SetGameStatus(GAME_MODE_EDITOR);
1580 // needed if last screen was the setup screen and fullscreen state changed
1581 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1582 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1584 // leveldir_current may be invalid (level group, parent link)
1585 if (!validLevelSeries(leveldir_current))
1586 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1588 if (leveldir_current != leveldir_last_valid)
1589 levelset_has_changed = TRUE;
1591 // store valid level series information
1592 leveldir_last_valid = leveldir_current;
1594 init_last = init; // switch to new busy animation
1596 // needed if last screen (level choice) changed graphics, sounds or music
1597 ReloadCustomArtwork(0);
1599 if (CheckTitleScreen(levelset_has_changed))
1601 SetGameStatus(GAME_MODE_TITLE);
1608 if (redraw_mask & REDRAW_ALL)
1609 fade_mask = REDRAW_ALL;
1612 fade_mask = REDRAW_ALL;
1616 // needed if different viewport properties defined for menues
1617 ChangeViewportPropertiesIfNeeded();
1619 SetDrawtoField(DRAW_TO_BACKBUFFER);
1621 // level_nr may have been set to value over handicap with level editor
1622 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1623 level_nr = leveldir_current->handicap_level;
1625 LoadLevel(level_nr);
1626 LoadScore(level_nr);
1628 SaveLevelSetup_SeriesInfo();
1630 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1631 SetDrawDeactivationMask(REDRAW_NONE);
1632 SetDrawBackgroundMask(REDRAW_FIELD);
1634 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1637 if (fade_mask == REDRAW_ALL)
1638 RedrawGlobalBorder();
1643 InitializeMainControls();
1645 DrawCursorAndText_Main(-1, FALSE, FALSE);
1646 DrawPreviewLevelInitial();
1647 DrawNetworkPlayers();
1649 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1652 if (TAPE_IS_EMPTY(tape))
1654 DrawCompleteVideoDisplay();
1656 PlayMenuSoundsAndMusic();
1658 // create gadgets for main menu screen
1659 FreeScreenGadgets();
1660 CreateScreenGadgets();
1662 // may be required if audio buttons shown on tape and changed in setup menu
1664 CreateGameButtons();
1666 // map gadgets for main menu screen
1668 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1669 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1671 // copy actual game door content to door double buffer for OpenDoor()
1672 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1673 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1675 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1677 DrawMaskedBorder(fade_mask);
1682 // update screen area with special editor door
1683 redraw_mask |= REDRAW_ALL;
1686 SetMouseCursor(CURSOR_DEFAULT);
1688 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1691 static void gotoTopLevelDir(void)
1693 // move upwards until inside (but not above) top level directory
1694 while (leveldir_current->node_parent &&
1695 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1697 // write a "path" into level tree for easy navigation to last level
1698 if (leveldir_current->node_parent->node_group->cl_first == -1)
1700 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1701 int leveldir_pos = posTreeInfo(leveldir_current);
1702 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1703 int cl_first, cl_cursor;
1705 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1706 cl_cursor = leveldir_pos - cl_first;
1708 leveldir_current->node_parent->node_group->cl_first = cl_first;
1709 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1712 leveldir_current = leveldir_current->node_parent;
1716 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1718 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1720 return (use_frame_counter ? video.frame_counter : Counter());
1723 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1724 struct TitleFadingInfo *fi)
1726 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1729 static void ResetTitleAutoDelay(unsigned int *counter_var,
1730 struct TitleFadingInfo *fi)
1732 *counter_var = getAutoDelayCounter(fi);
1735 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1737 static unsigned int title_delay = 0;
1738 static int title_screen_nr = 0;
1739 static int last_sound = -1, last_music = -1;
1740 boolean return_to_main_menu = FALSE;
1741 struct TitleControlInfo *tci;
1744 if (button == MB_MENU_INITIALIZE)
1747 title_screen_nr = 0;
1748 tci = &title_controls[title_screen_nr];
1750 SetAnimStatus(getTitleAnimMode(tci));
1752 last_sound = SND_UNDEFINED;
1753 last_music = MUS_UNDEFINED;
1755 if (num_title_screens != 0)
1757 FadeSetEnterScreen();
1759 // use individual title fading instead of global "enter screen" fading
1760 fading = getTitleFading(tci);
1763 if (game_status_last_screen == GAME_MODE_INFO)
1765 if (num_title_screens == 0)
1767 // switch game mode from title screen mode back to info screen mode
1768 SetGameStatus(GAME_MODE_INFO);
1770 // store that last screen was info screen, not main menu screen
1771 game_status_last_screen = GAME_MODE_INFO;
1773 DrawInfoScreen_NotAvailable("Title screen information:",
1774 "No title screen for this level set.");
1779 FadeMenuSoundsAndMusic();
1781 FadeOut(REDRAW_ALL);
1783 // title screens may have different window size
1784 ChangeViewportPropertiesIfNeeded();
1786 // only required to update logic for redrawing global border
1790 DrawTitleScreenImage(tci->local_nr, tci->initial);
1792 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1794 sound = getTitleSound(tci);
1795 music = getTitleMusic(tci);
1797 if (sound != last_sound)
1798 PlayMenuSoundExt(sound);
1799 if (music != last_music)
1800 PlayMenuMusicExt(music);
1805 SetMouseCursor(CURSOR_NONE);
1809 ResetTitleAutoDelay(&title_delay, &fading);
1814 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1815 button = MB_MENU_CHOICE;
1817 if (button == MB_MENU_LEAVE)
1819 return_to_main_menu = TRUE;
1821 else if (button == MB_MENU_CHOICE)
1823 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1825 SetGameStatus(GAME_MODE_INFO);
1827 info_mode = INFO_MODE_MAIN;
1836 if (title_screen_nr < num_title_screens)
1838 tci = &title_controls[title_screen_nr];
1840 SetAnimStatus(getTitleAnimMode(tci));
1842 sound = getTitleSound(tci);
1843 music = getTitleMusic(tci);
1845 if (last_sound != SND_UNDEFINED && sound != last_sound)
1846 FadeSound(last_sound);
1847 if (last_music != MUS_UNDEFINED && music != last_music)
1850 fading = getTitleFading(tci);
1852 FadeOut(REDRAW_ALL);
1855 DrawTitleScreenImage(tci->local_nr, tci->initial);
1857 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1859 sound = getTitleSound(tci);
1860 music = getTitleMusic(tci);
1862 if (sound != last_sound)
1863 PlayMenuSoundExt(sound);
1864 if (music != last_music)
1865 PlayMenuMusicExt(music);
1872 ResetTitleAutoDelay(&title_delay, &fading);
1876 FadeMenuSoundsAndMusic();
1878 return_to_main_menu = TRUE;
1882 if (return_to_main_menu)
1884 SetMouseCursor(CURSOR_DEFAULT);
1886 // force full menu screen redraw after displaying title screens
1887 redraw_mask = REDRAW_ALL;
1889 if (game_status_last_screen == GAME_MODE_INFO)
1891 SetGameStatus(GAME_MODE_INFO);
1893 info_mode = INFO_MODE_MAIN;
1897 else // default: return to main menu
1899 SetGameStatus(GAME_MODE_MAIN);
1906 static void HandleMainMenu_SelectLevel(int step, int direction,
1907 int selected_level_nr)
1909 int old_level_nr = level_nr;
1912 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1913 new_level_nr = selected_level_nr;
1915 new_level_nr = old_level_nr + step * direction;
1917 if (new_level_nr < leveldir_current->first_level)
1918 new_level_nr = leveldir_current->first_level;
1919 if (new_level_nr > leveldir_current->last_level)
1920 new_level_nr = leveldir_current->last_level;
1922 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1924 // skipping levels is only allowed when trying to skip single level
1925 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1926 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1928 leveldir_current->handicap_level++;
1929 SaveLevelSetup_SeriesInfo();
1932 new_level_nr = leveldir_current->handicap_level;
1935 if (new_level_nr != old_level_nr)
1937 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1939 PlaySound(SND_MENU_ITEM_SELECTING);
1941 level_nr = new_level_nr;
1943 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1944 int2str(level_nr, menu.main.text.level_number.size),
1945 mci->pos_text->font);
1947 LoadLevel(level_nr);
1948 DrawPreviewLevelInitial();
1952 DrawCompleteVideoDisplay();
1954 SaveLevelSetup_SeriesInfo();
1956 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1958 // force redraw of playfield area (may be reset at this point)
1959 redraw_mask |= REDRAW_FIELD;
1963 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1965 static int choice = MAIN_CONTROL_GAME;
1966 static boolean button_pressed_last = FALSE;
1967 boolean button_pressed = FALSE;
1969 int i = 0; // needed to prevent compiler warning due to bad code below
1971 if (button == MB_MENU_INITIALIZE)
1973 DrawCursorAndText_Main(choice, TRUE, FALSE);
1978 if (mx || my) // mouse input
1982 for (i = 0; main_controls[i].nr != -1; i++)
1984 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1985 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1986 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1988 pos = main_controls[i].nr;
1994 // check if level preview was clicked
1995 if (insidePreviewRect(&preview, mx - SX, my - SY))
1996 pos = MAIN_CONTROL_GAME;
1998 // handle pressed/unpressed state for active/inactive menu buttons
1999 // (if pos != -1, "i" contains index position corresponding to "pos")
2001 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2002 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2003 button_pressed = TRUE;
2005 if (button_pressed != button_pressed_last)
2007 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2010 PlaySound(SND_MENU_BUTTON_PRESSING);
2012 PlaySound(SND_MENU_BUTTON_RELEASING);
2015 else if (dx || dy) // keyboard input
2017 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2018 choice == MAIN_CONTROL_SETUP))
2019 button = MB_MENU_CHOICE;
2024 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2026 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2028 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2030 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2032 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2034 CloseDoor(DOOR_CLOSE_2);
2036 SetGameStatus(GAME_MODE_LEVELNR);
2038 DrawChooseLevelNr();
2040 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2046 PlaySound(SND_MENU_ITEM_ACTIVATING);
2048 DrawCursorAndText_Main(choice, FALSE, FALSE);
2049 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2055 if (choice != MAIN_CONTROL_INFO &&
2056 choice != MAIN_CONTROL_SETUP)
2057 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2062 PlaySound(SND_MENU_ITEM_SELECTING);
2064 if (pos == MAIN_CONTROL_NAME)
2067 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2069 // special case: menu text "name/team" clicked -- toggle team mode
2070 setup.team_mode = !setup.team_mode;
2072 InitializeMainControls();
2073 DrawCursorAndText_Main(choice, TRUE, FALSE);
2075 DrawPreviewPlayers();
2079 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2081 HandleTypeName(strlen(setup.player_name), 0);
2084 else if (pos == MAIN_CONTROL_LEVELS)
2088 CloseDoor(DOOR_CLOSE_2);
2090 SetGameStatus(GAME_MODE_LEVELS);
2092 SaveLevelSetup_LastSeries();
2093 SaveLevelSetup_SeriesInfo();
2095 if (setup.internal.choose_from_top_leveldir)
2098 DrawChooseLevelSet();
2101 else if (pos == MAIN_CONTROL_SCORES)
2103 CloseDoor(DOOR_CLOSE_2);
2105 SetGameStatus(GAME_MODE_SCORES);
2107 DrawHallOfFame(level_nr, -1);
2109 else if (pos == MAIN_CONTROL_EDITOR)
2111 if (leveldir_current->readonly &&
2112 !strEqual(setup.player_name, "Artsoft"))
2113 Request("This level is read only!", REQ_CONFIRM);
2115 CloseDoor(DOOR_CLOSE_2);
2117 SetGameStatus(GAME_MODE_EDITOR);
2119 FadeSetEnterScreen();
2123 else if (pos == MAIN_CONTROL_INFO)
2125 CloseDoor(DOOR_CLOSE_2);
2127 SetGameStatus(GAME_MODE_INFO);
2129 info_mode = INFO_MODE_MAIN;
2133 else if (pos == MAIN_CONTROL_GAME)
2135 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2137 else if (pos == MAIN_CONTROL_SETUP)
2139 CloseDoor(DOOR_CLOSE_2);
2141 SetGameStatus(GAME_MODE_SETUP);
2143 setup_mode = SETUP_MODE_MAIN;
2147 else if (pos == MAIN_CONTROL_QUIT)
2149 SaveLevelSetup_LastSeries();
2150 SaveLevelSetup_SeriesInfo();
2152 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2153 SetGameStatus(GAME_MODE_QUIT);
2158 button_pressed_last = button_pressed;
2162 // ============================================================================
2163 // info screen functions
2164 // ============================================================================
2166 static struct TokenInfo *info_info;
2167 static int num_info_info; // number of info entries shown on screen
2168 static int max_info_info; // total number of info entries in list
2170 static void execInfoTitleScreen(void)
2172 info_mode = INFO_MODE_TITLE;
2177 static void execInfoElements(void)
2179 info_mode = INFO_MODE_ELEMENTS;
2184 static void execInfoMusic(void)
2186 info_mode = INFO_MODE_MUSIC;
2191 static void execInfoCredits(void)
2193 info_mode = INFO_MODE_CREDITS;
2198 static void execInfoProgram(void)
2200 info_mode = INFO_MODE_PROGRAM;
2205 static void execInfoVersion(void)
2207 info_mode = INFO_MODE_VERSION;
2212 static void execInfoLevelSet(void)
2214 info_mode = INFO_MODE_LEVELSET;
2219 static void execExitInfo(void)
2221 SetGameStatus(GAME_MODE_MAIN);
2226 static struct TokenInfo info_info_main[] =
2228 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2229 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2230 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2231 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2232 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2233 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2234 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2235 { TYPE_EMPTY, NULL, "" },
2236 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2241 static int getMenuTextFont(int type)
2243 if (type & (TYPE_SWITCH |
2257 static struct TokenInfo *setup_info;
2258 static struct TokenInfo setup_info_input[];
2260 static struct TokenInfo *menu_info;
2262 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2263 int screen_pos, int menu_info_pos_raw,
2266 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2267 struct TokenInfo *ti = &token_info[pos];
2268 int xpos = MENU_SCREEN_START_XPOS;
2269 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2270 int font_nr = getMenuTextFont(ti->type);
2272 if (setup_mode == SETUP_MODE_INPUT)
2273 font_nr = FONT_MENU_1;
2276 font_nr = FONT_ACTIVE(font_nr);
2278 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2280 if (ti->type & ~TYPE_SKIP_ENTRY)
2281 drawCursor(screen_pos, active);
2284 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2287 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2290 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2293 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2296 static char *window_size_text;
2297 static char *scaling_type_text;
2298 static char *network_server_text;
2300 static void drawSetupValue(int, int);
2302 static void drawMenuInfoList(int first_entry, int num_page_entries,
2303 int max_page_entries)
2307 if (first_entry + num_page_entries > max_page_entries)
2310 clearMenuListArea();
2312 for (i = 0; i < num_page_entries; i++)
2314 int menu_info_pos = first_entry + i;
2315 struct TokenInfo *si = &menu_info[menu_info_pos];
2316 void *value_ptr = si->value;
2318 // set some entries to "unchangeable" according to other variables
2319 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2320 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2321 (value_ptr == &setup.sound_music && !audio.music_available) ||
2322 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2323 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2324 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2325 si->type |= TYPE_GHOSTED;
2327 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2328 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2329 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2330 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2331 else if (si->type & ~TYPE_SKIP_ENTRY)
2332 initCursor(i, IMG_MENU_BUTTON);
2334 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2336 if (si->type & TYPE_STRING)
2340 if (value_ptr == &network_server_text)
2341 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2343 if (gadget_id != -1)
2345 struct GadgetInfo *gi = screen_gadget[gadget_id];
2346 int xpos = MENU_SCREEN_START_XPOS;
2347 int ypos = MENU_SCREEN_START_YPOS + i;
2348 int x = mSX + xpos * 32;
2349 int y = mSY + ypos * 32;
2351 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2355 if (si->type & TYPE_VALUE &&
2356 menu_info == setup_info)
2357 drawSetupValue(i, menu_info_pos);
2361 static void DrawInfoScreen_Main(void)
2363 int fade_mask = REDRAW_FIELD;
2366 if (redraw_mask & REDRAW_ALL)
2367 fade_mask = REDRAW_ALL;
2370 fade_mask = REDRAW_ALL;
2373 FadeMenuSoundsAndMusic();
2375 FreeScreenGadgets();
2376 CreateScreenGadgets();
2378 // (needed after displaying title screens which disable auto repeat)
2379 KeyboardAutoRepeatOn();
2381 FadeSetLeaveScreen();
2385 // needed if different viewport properties defined for info screen
2386 ChangeViewportPropertiesIfNeeded();
2388 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2392 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2394 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2396 info_info = info_info_main;
2398 // determine maximal number of info entries that can be displayed on screen
2400 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2403 // determine maximal number of info entries available for menu of info screen
2405 for (i = 0; info_info[i].type != 0; i++)
2408 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2410 MapScreenGadgets(max_info_info);
2412 PlayMenuSoundsAndMusic();
2414 DrawMaskedBorder(fade_mask);
2419 static void changeSetupValue(int, int, int);
2421 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2422 int mode, int num_page_entries,
2423 int max_page_entries)
2425 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2426 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2427 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2428 int *num_page_entries_last = num_page_entries_all_last[game_status];
2429 int *choice_store = choice_stores[game_status];
2430 int *first_entry_store = first_entry_stores[game_status];
2431 int choice = choice_store[mode]; // starts with 0
2432 int first_entry = first_entry_store[mode]; // starts with 0
2434 int y = choice - first_entry;
2436 boolean position_set_by_scrollbar = (dx == 999);
2437 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2440 if (button == MB_MENU_INITIALIZE)
2442 // check if number of menu page entries has changed (may happen by change
2443 // of custom artwork definition value for 'list_size' for this menu screen)
2444 // (in this case, the last menu position most probably has to be corrected)
2445 if (num_page_entries != num_page_entries_last[mode])
2447 choice_store[mode] = first_entry_store[mode] = 0;
2449 choice = first_entry = 0;
2452 num_page_entries_last[mode] = num_page_entries;
2455 // advance to first valid menu entry
2456 while (choice < num_page_entries &&
2457 menu_info[choice].type & TYPE_SKIP_ENTRY)
2460 if (position_set_by_scrollbar)
2461 first_entry = first_entry_store[mode] = dy;
2463 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2464 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2466 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2468 if (choice < first_entry)
2470 choice = first_entry;
2472 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2475 else if (choice > first_entry + num_page_entries - 1)
2477 choice = first_entry + num_page_entries - 1;
2479 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2483 choice_store[mode] = choice;
2485 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2489 else if (button == MB_MENU_LEAVE)
2491 PlaySound(SND_MENU_ITEM_SELECTING);
2493 for (i = 0; i < max_page_entries; i++)
2495 if (menu_info[i].type & TYPE_LEAVE_MENU)
2497 void (*menu_callback_function)(void) = menu_info[i].value;
2501 menu_callback_function();
2503 break; // absolutely needed because function changes 'menu_info'!
2510 if (mx || my) // mouse input
2512 x = (mx - mSX) / 32;
2513 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2515 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2517 // move cursor instead of scrolling when already at start/end of list
2518 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2520 else if (dy == +1 * SCROLL_LINE &&
2521 first_entry + num_page_entries == max_page_entries)
2524 // handle scrolling screen one line or page
2526 y + dy > num_page_entries - 1)
2528 boolean redraw = FALSE;
2530 if (ABS(dy) == SCROLL_PAGE)
2531 step = num_page_entries - 1;
2533 if (dy < 0 && first_entry > 0)
2535 // scroll page/line up
2537 first_entry -= step;
2538 if (first_entry < 0)
2543 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2545 // scroll page/line down
2547 first_entry += step;
2548 if (first_entry + num_page_entries > max_page_entries)
2549 first_entry = MAX(0, max_page_entries - num_page_entries);
2556 choice += first_entry - first_entry_store[mode];
2558 if (choice < first_entry)
2560 choice = first_entry;
2562 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2565 else if (choice > first_entry + num_page_entries - 1)
2567 choice = first_entry + num_page_entries - 1;
2569 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2572 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2576 if (choice < first_entry ||
2577 choice > first_entry + num_page_entries - 1)
2578 first_entry += SIGN(dy);
2581 first_entry_store[mode] = first_entry;
2582 choice_store[mode] = choice;
2584 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2586 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2588 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2589 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2597 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2599 if (menu_info[choice].type & menu_navigation_type ||
2600 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2601 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2602 menu_info[choice].type & TYPE_PLAYER)
2603 button = MB_MENU_CHOICE;
2608 // jump to next non-empty menu entry (up or down)
2609 while (first_entry + y > 0 &&
2610 first_entry + y < max_page_entries - 1 &&
2611 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2614 if (!IN_VIS_MENU(x, y))
2616 choice += y - y_old;
2618 if (choice < first_entry)
2619 first_entry = choice;
2620 else if (choice > first_entry + num_page_entries - 1)
2621 first_entry = choice - num_page_entries + 1;
2623 if (first_entry >= 0 &&
2624 first_entry + num_page_entries <= max_page_entries)
2626 first_entry_store[mode] = first_entry;
2628 if (choice < first_entry)
2629 choice = first_entry;
2630 else if (choice > first_entry + num_page_entries - 1)
2631 choice = first_entry + num_page_entries - 1;
2633 choice_store[mode] = choice;
2635 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2637 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2639 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2640 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2647 if (!anyScrollbarGadgetActive() &&
2648 IN_VIS_MENU(x, y) &&
2649 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2650 y >= 0 && y < num_page_entries)
2654 if (first_entry + y != choice &&
2655 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2657 PlaySound(SND_MENU_ITEM_ACTIVATING);
2659 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2660 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2662 choice = choice_store[mode] = first_entry + y;
2666 PlaySound(SND_MENU_ITEM_SELECTING);
2668 for (i = 0; menu_info[i].type != 0; i++)
2670 if (menu_info[i].type & TYPE_LEAVE_MENU)
2672 void (*menu_callback_function)(void) = menu_info[i].value;
2676 menu_callback_function();
2678 // absolutely needed because function changes 'menu_info'!
2686 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2688 PlaySound(SND_MENU_ITEM_SELECTING);
2690 // when selecting key headline, execute function for key value change
2691 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2692 menu_info[first_entry + y + 1].type & TYPE_KEY)
2695 // when selecting string value, execute function for list selection
2696 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2697 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2700 // when selecting string value, execute function for text input gadget
2701 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2702 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2705 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2707 void (*menu_callback_function)(void) =
2708 menu_info[first_entry + y].value;
2710 FadeSetFromType(menu_info[first_entry + y].type);
2712 menu_callback_function();
2714 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2716 void (*gadget_callback_function)(void) =
2717 menu_info[first_entry + y].value;
2719 gadget_callback_function();
2721 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2722 menu_info == setup_info)
2724 changeSetupValue(y, first_entry + y, dx);
2730 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2732 menu_info = info_info;
2734 HandleMenuScreen(mx, my, dx, dy, button,
2735 info_mode, num_info_info, max_info_info);
2738 static int getMenuFontSpacing(int spacing_height, int font_nr)
2740 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2742 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2746 static int getMenuTextSpacing(int spacing_height, int font_nr)
2748 return (getMenuFontSpacing(spacing_height, font_nr) +
2749 EXTRA_SPACING(game_status));
2752 static int getMenuTextStep(int spacing_height, int font_nr)
2754 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2757 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2759 int font_title = MENU_INFO_FONT_TITLE;
2760 int font_error = FONT_TEXT_2;
2761 int font_foot = MENU_INFO_FONT_FOOT;
2762 int spacing_title = menu.headline1_spacing_info[info_mode];
2763 int ystep_title = getMenuTextStep(spacing_title, font_title);
2764 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2765 int ystart2 = ystart1 + ystep_title;
2766 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2768 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2770 FadeOut(REDRAW_FIELD);
2775 DrawTextSCentered(ystart1, font_title, text_title);
2776 DrawTextSCentered(ystart2, font_error, text_error);
2778 DrawTextSCentered(ybottom, font_foot,
2779 "Press any key or button for info menu");
2781 FadeIn(REDRAW_FIELD);
2784 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2786 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2787 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2788 int font_title = MENU_INFO_FONT_TITLE;
2789 int font_foot = MENU_INFO_FONT_FOOT;
2790 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2791 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2792 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2793 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2794 int ystep = MENU_SCREEN_INFO_YSTEP;
2795 int element, action, direction;
2803 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2804 infoscreen_step[i] = infoscreen_frame[i] = 0;
2809 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2811 DrawTextSCentered(ybottom, font_foot,
2812 "Press any key or button for next page");
2818 while (helpanim_info[j].element != HELPANIM_LIST_END)
2820 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2825 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2834 j += infoscreen_step[i - start];
2836 element = helpanim_info[j].element;
2837 action = helpanim_info[j].action;
2838 direction = helpanim_info[j].direction;
2841 element = EL_UNKNOWN;
2843 if (action != -1 && direction != -1)
2844 graphic = el_act_dir2img(element, action, direction);
2845 else if (action != -1)
2846 graphic = el_act2img(element, action);
2847 else if (direction != -1)
2848 graphic = el_dir2img(element, direction);
2850 graphic = el2img(element);
2852 delay = helpanim_info[j++].delay;
2857 if (infoscreen_frame[i - start] == 0)
2860 infoscreen_frame[i - start] = delay - 1;
2864 sync_frame = delay - infoscreen_frame[i - start];
2865 infoscreen_frame[i - start]--;
2868 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2870 if (!infoscreen_frame[i - start])
2871 infoscreen_step[i - start] = 0;
2875 if (!infoscreen_frame[i - start])
2876 infoscreen_step[i - start]++;
2877 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2883 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2885 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2886 graphic, sync_frame, USE_MASKING);
2889 DrawInfoScreen_HelpText(element, action, direction, i - start);
2894 redraw_mask |= REDRAW_FIELD;
2899 static char *getHelpText(int element, int action, int direction)
2901 char token[MAX_LINE_LEN];
2903 strcpy(token, element_info[element].token_name);
2906 strcat(token, element_action_info[action].suffix);
2908 if (direction != -1)
2909 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2911 return getHashEntry(helptext_info, token);
2914 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2916 int font_nr = FONT_INFO_ELEMENTS;
2917 int font_width = getFontWidth(font_nr);
2918 int font_height = getFontHeight(font_nr);
2919 int yoffset = (TILEX - 2 * font_height) / 2;
2920 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2921 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2922 int ystep = TILEY + 4;
2923 int pad_left = xstart - SX;
2924 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2925 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2926 int max_lines_per_text = 2;
2929 if (action != -1 && direction != -1) // element.action.direction
2930 text = getHelpText(element, action, direction);
2932 if (text == NULL && action != -1) // element.action
2933 text = getHelpText(element, action, -1);
2935 if (text == NULL && direction != -1) // element.direction
2936 text = getHelpText(element, -1, direction);
2938 if (text == NULL) // base element
2939 text = getHelpText(element, -1, -1);
2941 if (text == NULL) // not found
2942 text = "No description available";
2944 if (strlen(text) <= max_chars_per_line) // only one line of text
2945 ystart += getFontHeight(font_nr) / 2;
2947 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2948 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2949 TRUE, FALSE, FALSE);
2952 static void DrawInfoScreen_TitleScreen(void)
2954 SetGameStatus(GAME_MODE_TITLE);
2959 void HandleInfoScreen_TitleScreen(int button)
2961 HandleTitleScreen(0, 0, 0, 0, button);
2964 static void DrawInfoScreen_Elements(void)
2966 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2968 FadeOut(REDRAW_FIELD);
2973 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2975 FadeIn(REDRAW_FIELD);
2978 void HandleInfoScreen_Elements(int button)
2980 static unsigned int info_delay = 0;
2981 static int num_anims;
2982 static int num_pages;
2984 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2987 if (button == MB_MENU_INITIALIZE)
2989 boolean new_element = TRUE;
2993 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2995 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2997 else if (new_element)
3000 new_element = FALSE;
3004 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3008 if (button == MB_MENU_LEAVE)
3010 PlaySound(SND_MENU_ITEM_SELECTING);
3012 info_mode = INFO_MODE_MAIN;
3017 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3019 if (button != MB_MENU_INITIALIZE)
3021 PlaySound(SND_MENU_ITEM_SELECTING);
3026 if (page >= num_pages)
3028 FadeMenuSoundsAndMusic();
3030 info_mode = INFO_MODE_MAIN;
3037 FadeSetNextScreen();
3039 if (button != MB_MENU_INITIALIZE)
3040 FadeOut(REDRAW_FIELD);
3042 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3044 if (button != MB_MENU_INITIALIZE)
3045 FadeIn(REDRAW_FIELD);
3049 if (DelayReached(&info_delay, GameFrameDelay))
3050 if (page < num_pages)
3051 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3053 PlayMenuSoundIfLoop();
3057 static void DrawInfoScreen_Music(void)
3059 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3061 FadeOut(REDRAW_FIELD);
3068 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3070 FadeIn(REDRAW_FIELD);
3073 void HandleInfoScreen_Music(int button)
3075 static struct MusicFileInfo *list = NULL;
3076 int font_title = MENU_INFO_FONT_TITLE;
3077 int font_head = MENU_INFO_FONT_HEAD;
3078 int font_text = MENU_INFO_FONT_TEXT;
3079 int font_foot = MENU_INFO_FONT_FOOT;
3080 int spacing_title = menu.headline1_spacing_info[info_mode];
3081 int spacing_head = menu.headline2_spacing_info[info_mode];
3082 int ystep_title = getMenuTextStep(spacing_title, font_title);
3083 int ystep_head = getMenuTextStep(spacing_head, font_head);
3084 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3085 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3087 if (button == MB_MENU_INITIALIZE)
3089 list = music_file_info;
3093 FadeMenuSoundsAndMusic();
3098 DrawTextSCentered(ystart, font_title,
3099 "No music info for this level set.");
3101 DrawTextSCentered(ybottom, font_foot,
3102 "Press any key or button for info menu");
3108 if (button == MB_MENU_LEAVE)
3110 PlaySound(SND_MENU_ITEM_SELECTING);
3112 FadeMenuSoundsAndMusic();
3114 info_mode = INFO_MODE_MAIN;
3119 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3121 if (button != MB_MENU_INITIALIZE)
3123 PlaySound(SND_MENU_ITEM_SELECTING);
3131 FadeMenuSoundsAndMusic();
3133 info_mode = INFO_MODE_MAIN;
3139 FadeMenuSoundsAndMusic();
3141 if (list != music_file_info)
3142 FadeSetNextScreen();
3144 if (button != MB_MENU_INITIALIZE)
3145 FadeOut(REDRAW_FIELD);
3152 int sound = list->music;
3154 if (sound_info[sound].loop)
3155 PlaySoundLoop(sound);
3159 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3163 int music = list->music;
3165 if (music_info[music].loop)
3166 PlayMusicLoop(music);
3170 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3173 ystart += ystep_title;
3175 if (!strEqual(list->title, UNKNOWN_NAME))
3177 if (!strEqual(list->title_header, UNKNOWN_NAME))
3179 DrawTextSCentered(ystart, font_head, list->title_header);
3180 ystart += ystep_head;
3183 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3184 ystart += ystep_head;
3187 if (!strEqual(list->artist, UNKNOWN_NAME))
3189 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3190 DrawTextSCentered(ystart, font_head, list->artist_header);
3192 DrawTextSCentered(ystart, font_head, "by");
3194 ystart += ystep_head;
3196 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3197 ystart += ystep_head;
3200 if (!strEqual(list->album, UNKNOWN_NAME))
3202 if (!strEqual(list->album_header, UNKNOWN_NAME))
3203 DrawTextSCentered(ystart, font_head, list->album_header);
3205 DrawTextSCentered(ystart, font_head, "from the album");
3207 ystart += ystep_head;
3209 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3210 ystart += ystep_head;
3213 if (!strEqual(list->year, UNKNOWN_NAME))
3215 if (!strEqual(list->year_header, UNKNOWN_NAME))
3216 DrawTextSCentered(ystart, font_head, list->year_header);
3218 DrawTextSCentered(ystart, font_head, "from the year");
3220 ystart += ystep_head;
3222 DrawTextFCentered(ystart, font_text, "%s", list->year);
3223 ystart += ystep_head;
3226 DrawTextSCentered(ybottom, FONT_TEXT_4,
3227 "Press any key or button for next page");
3229 if (button != MB_MENU_INITIALIZE)
3230 FadeIn(REDRAW_FIELD);
3233 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3234 PlaySoundLoop(list->music);
3237 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3239 int font_title = MENU_INFO_FONT_TITLE;
3240 int font_head = MENU_INFO_FONT_HEAD;
3241 int font_text = MENU_INFO_FONT_TEXT;
3242 int font_foot = MENU_INFO_FONT_FOOT;
3243 int spacing_title = menu.headline1_spacing_info[info_mode];
3244 int spacing_head = menu.headline2_spacing_info[info_mode];
3245 int spacing_para = menu.paragraph_spacing_info[info_mode];
3246 int spacing_line = menu.line_spacing_info[info_mode];
3247 int ystep_title = getMenuTextStep(spacing_title, font_title);
3248 int ystep_head = getMenuTextStep(spacing_head, font_head);
3249 int ystep_para = getMenuTextStep(spacing_para, font_text);
3250 int ystep_line = getMenuTextStep(spacing_line, font_text);
3251 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3252 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3257 DrawTextSCentered(ystart, font_title, "Credits:");
3258 ystart += ystep_title;
3262 DrawTextSCentered(ystart, font_head,
3263 "Special thanks to");
3264 ystart += ystep_head;
3265 DrawTextSCentered(ystart, font_text,
3267 ystart += ystep_head;
3268 DrawTextSCentered(ystart, font_head,
3270 ystart += ystep_head;
3271 DrawTextSCentered(ystart, font_text,
3272 "\"Boulder Dash\"");
3273 ystart += ystep_head;
3274 DrawTextSCentered(ystart, font_head,
3276 ystart += ystep_head;
3277 DrawTextSCentered(ystart, font_text,
3279 ystart += ystep_head;
3280 DrawTextSCentered(ystart, font_head,
3282 ystart += ystep_head;
3283 DrawTextSCentered(ystart, font_text,
3284 "First Star Software");
3286 else if (screen_nr == 1)
3288 DrawTextSCentered(ystart, font_head,
3289 "Special thanks to");
3290 ystart += ystep_head;
3291 DrawTextSCentered(ystart, font_text,
3292 "Klaus Heinz & Volker Wertich");
3293 ystart += ystep_head;
3294 DrawTextSCentered(ystart, font_head,
3296 ystart += ystep_head;
3297 DrawTextSCentered(ystart, font_text,
3298 "\"Emerald Mine\"");
3299 ystart += ystep_head;
3300 DrawTextSCentered(ystart, font_head,
3302 ystart += ystep_head;
3303 DrawTextSCentered(ystart, font_text,
3305 ystart += ystep_head;
3306 DrawTextSCentered(ystart, font_head,
3308 ystart += ystep_head;
3309 DrawTextSCentered(ystart, font_text,
3312 else if (screen_nr == 2)
3314 DrawTextSCentered(ystart, font_head,
3315 "Special thanks to");
3316 ystart += ystep_head;
3317 DrawTextSCentered(ystart, font_text,
3318 "Michael Stopp & Philip Jespersen");
3319 ystart += ystep_head;
3320 DrawTextSCentered(ystart, font_head,
3322 ystart += ystep_head;
3323 DrawTextSCentered(ystart, font_text,
3325 ystart += ystep_head;
3326 DrawTextSCentered(ystart, font_head,
3328 ystart += ystep_head;
3329 DrawTextSCentered(ystart, font_text,
3331 ystart += ystep_head;
3332 DrawTextSCentered(ystart, font_head,
3334 ystart += ystep_head;
3335 DrawTextSCentered(ystart, font_text,
3336 "Digital Integration");
3338 else if (screen_nr == 3)
3340 DrawTextSCentered(ystart, font_head,
3341 "Special thanks to");
3342 ystart += ystep_head;
3343 DrawTextSCentered(ystart, font_text,
3344 "Hiroyuki Imabayashi");
3345 ystart += ystep_head;
3346 DrawTextSCentered(ystart, font_head,
3348 ystart += ystep_head;
3349 DrawTextSCentered(ystart, font_text,
3351 ystart += ystep_head;
3352 DrawTextSCentered(ystart, font_head,
3354 ystart += ystep_head;
3355 DrawTextSCentered(ystart, font_text,
3357 ystart += ystep_head;
3358 DrawTextSCentered(ystart, font_head,
3360 ystart += ystep_head;
3361 DrawTextSCentered(ystart, font_text,
3364 else if (screen_nr == 4)
3366 DrawTextSCentered(ystart, font_head,
3367 "Special thanks to");
3368 ystart += ystep_head;
3369 DrawTextSCentered(ystart, font_text,
3371 ystart += ystep_head;
3372 DrawTextSCentered(ystart, font_head,
3374 ystart += ystep_head;
3375 DrawTextSCentered(ystart, font_text,
3376 "J\xfcrgen Bonhagen");
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_head,
3379 "for the continuous creation");
3380 ystart += ystep_line;
3381 DrawTextSCentered(ystart, font_head,
3382 "of outstanding level sets");
3384 else if (screen_nr == 5)
3386 DrawTextSCentered(ystart, font_head,
3388 ystart += ystep_head;
3389 DrawTextSCentered(ystart, font_text,
3391 ystart += ystep_head;
3392 DrawTextSCentered(ystart, font_head,
3393 "for ideas and inspiration by");
3394 ystart += ystep_head;
3395 DrawTextSCentered(ystart, font_text,
3397 ystart += ystep_para;
3399 DrawTextSCentered(ystart, font_head,
3401 ystart += ystep_head;
3402 DrawTextSCentered(ystart, font_text,
3404 ystart += ystep_head;
3405 DrawTextSCentered(ystart, font_head,
3406 "for ideas and inspiration by");
3407 ystart += ystep_head;
3408 DrawTextSCentered(ystart, font_text,
3411 else if (screen_nr == 6)
3413 DrawTextSCentered(ystart, font_head,
3415 ystart += ystep_head;
3416 DrawTextSCentered(ystart, font_text,
3418 ystart += ystep_head;
3419 DrawTextSCentered(ystart, font_head,
3420 "for the code base used for the");
3421 ystart += ystep_line;
3422 DrawTextSCentered(ystart, font_head,
3423 "native Emerald Mine engine");
3425 else if (screen_nr == 7)
3427 DrawTextSCentered(ystart, font_head,
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_text,
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_head,
3434 "for the initial DOS port");
3435 ystart += ystep_para;
3437 DrawTextSCentered(ystart, font_head,
3439 ystart += ystep_head;
3440 DrawTextSCentered(ystart, font_text,
3442 ystart += ystep_head;
3443 DrawTextSCentered(ystart, font_head,
3444 "for some additional toons");
3446 else if (screen_nr == 8)
3448 DrawTextSCentered(ystart, font_head,
3449 "And not to forget:");
3450 ystart += ystep_head;
3451 DrawTextSCentered(ystart, font_head,
3453 ystart += ystep_head;
3454 DrawTextSCentered(ystart, font_text,
3455 "All those who contributed");
3456 ystart += ystep_line;
3457 DrawTextSCentered(ystart, font_text,
3458 "levels to this game");
3459 ystart += ystep_line;
3460 DrawTextSCentered(ystart, font_text,
3464 DrawTextSCentered(ybottom, font_foot,
3465 "Press any key or button for next page");
3468 static void DrawInfoScreen_Credits(void)
3470 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3472 FadeMenuSoundsAndMusic();
3474 FadeOut(REDRAW_FIELD);
3476 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3478 FadeIn(REDRAW_FIELD);
3481 void HandleInfoScreen_Credits(int button)
3483 static int screen_nr = 0;
3484 int num_screens = 9;
3486 if (button == MB_MENU_INITIALIZE)
3490 // DrawInfoScreen_CreditsScreen(screen_nr);
3493 if (button == MB_MENU_LEAVE)
3495 PlaySound(SND_MENU_ITEM_SELECTING);
3497 info_mode = INFO_MODE_MAIN;
3502 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3504 if (button != MB_MENU_INITIALIZE)
3506 PlaySound(SND_MENU_ITEM_SELECTING);
3511 if (screen_nr >= num_screens)
3513 FadeMenuSoundsAndMusic();
3515 info_mode = INFO_MODE_MAIN;
3522 FadeSetNextScreen();
3524 if (button != MB_MENU_INITIALIZE)
3525 FadeOut(REDRAW_FIELD);
3527 DrawInfoScreen_CreditsScreen(screen_nr);
3529 if (button != MB_MENU_INITIALIZE)
3530 FadeIn(REDRAW_FIELD);
3534 PlayMenuSoundIfLoop();
3538 static void DrawInfoScreen_Program(void)
3540 int font_title = MENU_INFO_FONT_TITLE;
3541 int font_head = MENU_INFO_FONT_HEAD;
3542 int font_text = MENU_INFO_FONT_TEXT;
3543 int font_foot = MENU_INFO_FONT_FOOT;
3544 int spacing_title = menu.headline1_spacing_info[info_mode];
3545 int spacing_head = menu.headline2_spacing_info[info_mode];
3546 int spacing_para = menu.paragraph_spacing_info[info_mode];
3547 int spacing_line = menu.line_spacing_info[info_mode];
3548 int ystep_title = getMenuTextStep(spacing_title, font_title);
3549 int ystep_head = getMenuTextStep(spacing_head, font_head);
3550 int ystep_para = getMenuTextStep(spacing_para, font_text);
3551 int ystep_line = getMenuTextStep(spacing_line, font_text);
3552 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3553 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3555 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3557 FadeOut(REDRAW_FIELD);
3562 DrawTextSCentered(ystart, font_title, "Program Information:");
3563 ystart += ystep_title;
3565 DrawTextSCentered(ystart, font_head,
3566 "This game is Freeware!");
3567 ystart += ystep_head;
3568 DrawTextSCentered(ystart, font_head,
3569 "If you like it, send e-mail to:");
3570 ystart += ystep_head;
3571 DrawTextSCentered(ystart, font_text,
3572 setup.internal.program_email);
3573 ystart += ystep_para;
3575 DrawTextSCentered(ystart, font_head,
3576 "More information and levels:");
3577 ystart += ystep_head;
3578 DrawTextSCentered(ystart, font_text,
3579 setup.internal.program_website);
3580 ystart += ystep_para;
3582 DrawTextSCentered(ystart, font_head,
3583 "If you have created new levels,");
3584 ystart += ystep_line;
3585 DrawTextSCentered(ystart, font_head,
3586 "send them to me to include them!");
3587 ystart += ystep_head;
3588 DrawTextSCentered(ystart, font_head,
3591 DrawTextSCentered(ybottom, font_foot,
3592 "Press any key or button for info menu");
3594 FadeIn(REDRAW_FIELD);
3597 void HandleInfoScreen_Program(int button)
3599 if (button == MB_MENU_LEAVE)
3601 PlaySound(SND_MENU_ITEM_SELECTING);
3603 info_mode = INFO_MODE_MAIN;
3608 else if (button == MB_MENU_CHOICE)
3610 PlaySound(SND_MENU_ITEM_SELECTING);
3612 FadeMenuSoundsAndMusic();
3614 info_mode = INFO_MODE_MAIN;
3619 PlayMenuSoundIfLoop();
3623 static void DrawInfoScreen_Version(void)
3625 int font_title = MENU_INFO_FONT_TITLE;
3626 int font_head = MENU_INFO_FONT_HEAD;
3627 int font_text = MENU_INFO_FONT_TEXT;
3628 int font_foot = MENU_INFO_FONT_FOOT;
3629 int spacing_title = menu.headline1_spacing_info[info_mode];
3630 int spacing_head = menu.headline2_spacing_info[info_mode];
3631 int spacing_para = menu.paragraph_spacing_info[info_mode];
3632 int spacing_line = menu.line_spacing_info[info_mode];
3633 int xstep = getFontWidth(font_text);
3634 int ystep_title = getMenuTextStep(spacing_title, font_title);
3635 int ystep_head = getMenuTextStep(spacing_head, font_head);
3636 int ystep_para = getMenuTextStep(spacing_para, font_text);
3637 int ystep_line = getMenuTextStep(spacing_line, font_text);
3638 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3639 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3640 int xstart1 = mSX - SX + 2 * xstep;
3641 int xstart2 = mSX - SX + 18 * xstep;
3642 int xstart3 = mSX - SX + 28 * xstep;
3643 SDL_version sdl_version_compiled;
3644 const SDL_version *sdl_version_linked;
3645 int driver_name_len = 10;
3646 SDL_version sdl_version_linked_ext;
3647 const char *driver_name = NULL;
3649 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3651 FadeOut(REDRAW_FIELD);
3656 DrawTextSCentered(ystart, font_title, "Version Information:");
3657 ystart += ystep_title;
3659 DrawTextF(xstart1, ystart, font_head, "Name");
3660 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3661 ystart += ystep_line;
3663 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3665 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3666 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3667 ystart += ystep_line;
3669 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3670 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3671 ystart += ystep_line;
3675 DrawTextF(xstart1, ystart, font_head, "Version");
3676 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3677 ystart += ystep_line;
3680 DrawTextF(xstart1, ystart, font_head, "Platform");
3681 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3682 ystart += ystep_line;
3684 DrawTextF(xstart1, ystart, font_head, "Target");
3685 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3686 ystart += ystep_line;
3688 DrawTextF(xstart1, ystart, font_head, "Source date");
3689 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3690 ystart += ystep_para;
3692 DrawTextF(xstart1, ystart, font_head, "Library");
3693 DrawTextF(xstart2, ystart, font_head, "compiled");
3694 DrawTextF(xstart3, ystart, font_head, "linked");
3695 ystart += ystep_head;
3697 SDL_VERSION(&sdl_version_compiled);
3698 SDL_GetVersion(&sdl_version_linked_ext);
3699 sdl_version_linked = &sdl_version_linked_ext;
3701 DrawTextF(xstart1, ystart, font_text, "SDL");
3702 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3703 sdl_version_compiled.major,
3704 sdl_version_compiled.minor,
3705 sdl_version_compiled.patch);
3706 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3707 sdl_version_linked->major,
3708 sdl_version_linked->minor,
3709 sdl_version_linked->patch);
3710 ystart += ystep_line;
3712 SDL_IMAGE_VERSION(&sdl_version_compiled);
3713 sdl_version_linked = IMG_Linked_Version();
3715 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3716 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3717 sdl_version_compiled.major,
3718 sdl_version_compiled.minor,
3719 sdl_version_compiled.patch);
3720 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3721 sdl_version_linked->major,
3722 sdl_version_linked->minor,
3723 sdl_version_linked->patch);
3724 ystart += ystep_line;
3726 SDL_MIXER_VERSION(&sdl_version_compiled);
3727 sdl_version_linked = Mix_Linked_Version();
3729 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3730 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3731 sdl_version_compiled.major,
3732 sdl_version_compiled.minor,
3733 sdl_version_compiled.patch);
3734 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3735 sdl_version_linked->major,
3736 sdl_version_linked->minor,
3737 sdl_version_linked->patch);
3738 ystart += ystep_line;
3740 SDL_NET_VERSION(&sdl_version_compiled);
3741 sdl_version_linked = SDLNet_Linked_Version();
3743 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3744 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3745 sdl_version_compiled.major,
3746 sdl_version_compiled.minor,
3747 sdl_version_compiled.patch);
3748 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3749 sdl_version_linked->major,
3750 sdl_version_linked->minor,
3751 sdl_version_linked->patch);
3752 ystart += ystep_para;
3754 DrawTextF(xstart1, ystart, font_head, "Driver");
3755 DrawTextF(xstart2, ystart, font_head, "Requested");
3756 DrawTextF(xstart3, ystart, font_head, "Used");
3757 ystart += ystep_head;
3759 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3761 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3762 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3763 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3764 ystart += ystep_line;
3766 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3768 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3769 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3770 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3772 DrawTextSCentered(ybottom, font_foot,
3773 "Press any key or button for info menu");
3775 FadeIn(REDRAW_FIELD);
3778 void HandleInfoScreen_Version(int button)
3780 if (button == MB_MENU_LEAVE)
3782 PlaySound(SND_MENU_ITEM_SELECTING);
3784 info_mode = INFO_MODE_MAIN;
3789 else if (button == MB_MENU_CHOICE)
3791 PlaySound(SND_MENU_ITEM_SELECTING);
3793 FadeMenuSoundsAndMusic();
3795 info_mode = INFO_MODE_MAIN;
3800 PlayMenuSoundIfLoop();
3804 static void DrawInfoScreen_LevelSet(void)
3806 struct TitleMessageInfo *tmi = &readme;
3807 char *filename = getLevelSetInfoFilename();
3808 char *title = "Level Set Information:";
3809 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3810 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3812 if (filename == NULL)
3814 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3819 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3821 FadeOut(REDRAW_FIELD);
3826 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3828 // if x position set to "-1", automatically determine by playfield width
3830 tmi->x = SXSIZE / 2;
3832 // if y position set to "-1", use static default value
3836 // if width set to "-1", automatically determine by playfield width
3837 if (tmi->width == -1)
3838 tmi->width = SXSIZE - 2 * TILEX;
3840 // if height set to "-1", automatically determine by playfield height
3841 if (tmi->height == -1)
3842 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3844 // if chars set to "-1", automatically determine by text and font width
3845 if (tmi->chars == -1)
3846 tmi->chars = tmi->width / getFontWidth(tmi->font);
3848 tmi->width = tmi->chars * getFontWidth(tmi->font);
3850 // if lines set to "-1", automatically determine by text and font height
3851 if (tmi->lines == -1)
3852 tmi->lines = tmi->height / getFontHeight(tmi->font);
3854 tmi->height = tmi->lines * getFontHeight(tmi->font);
3856 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3857 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3858 tmi->autowrap, tmi->centered, tmi->parse_comments);
3860 DrawTextSCentered(ybottom, FONT_TEXT_4,
3861 "Press any key or button for info menu");
3863 FadeIn(REDRAW_FIELD);
3866 static void HandleInfoScreen_LevelSet(int button)
3868 if (button == MB_MENU_LEAVE)
3870 PlaySound(SND_MENU_ITEM_SELECTING);
3872 info_mode = INFO_MODE_MAIN;
3877 else if (button == MB_MENU_CHOICE)
3879 PlaySound(SND_MENU_ITEM_SELECTING);
3881 FadeMenuSoundsAndMusic();
3883 info_mode = INFO_MODE_MAIN;
3888 PlayMenuSoundIfLoop();
3892 static void DrawInfoScreen(void)
3894 if (info_mode == INFO_MODE_TITLE)
3895 DrawInfoScreen_TitleScreen();
3896 else if (info_mode == INFO_MODE_ELEMENTS)
3897 DrawInfoScreen_Elements();
3898 else if (info_mode == INFO_MODE_MUSIC)
3899 DrawInfoScreen_Music();
3900 else if (info_mode == INFO_MODE_CREDITS)
3901 DrawInfoScreen_Credits();
3902 else if (info_mode == INFO_MODE_PROGRAM)
3903 DrawInfoScreen_Program();
3904 else if (info_mode == INFO_MODE_VERSION)
3905 DrawInfoScreen_Version();
3906 else if (info_mode == INFO_MODE_LEVELSET)
3907 DrawInfoScreen_LevelSet();
3909 DrawInfoScreen_Main();
3911 if (info_mode != INFO_MODE_MAIN &&
3912 info_mode != INFO_MODE_TITLE &&
3913 info_mode != INFO_MODE_MUSIC)
3914 PlayMenuSoundsAndMusic();
3917 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3919 if (info_mode == INFO_MODE_TITLE)
3920 HandleInfoScreen_TitleScreen(button);
3921 else if (info_mode == INFO_MODE_ELEMENTS)
3922 HandleInfoScreen_Elements(button);
3923 else if (info_mode == INFO_MODE_MUSIC)
3924 HandleInfoScreen_Music(button);
3925 else if (info_mode == INFO_MODE_CREDITS)
3926 HandleInfoScreen_Credits(button);
3927 else if (info_mode == INFO_MODE_PROGRAM)
3928 HandleInfoScreen_Program(button);
3929 else if (info_mode == INFO_MODE_VERSION)
3930 HandleInfoScreen_Version(button);
3931 else if (info_mode == INFO_MODE_LEVELSET)
3932 HandleInfoScreen_LevelSet(button);
3934 HandleInfoScreen_Main(mx, my, dx, dy, button);
3938 // ============================================================================
3939 // type name functions
3940 // ============================================================================
3942 void HandleTypeName(int newxpos, Key key)
3944 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3945 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3946 struct TextPosInfo *pos = mci->pos_input;
3947 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3948 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3949 static int xpos = 0;
3950 int font_nr = pos->font;
3951 int font_active_nr = FONT_ACTIVE(font_nr);
3952 int font_width = getFontWidth(font_active_nr);
3953 char key_char = getValidConfigValueChar(getCharFromKey(key));
3954 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3955 boolean is_active = TRUE;
3957 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3961 strcpy(last_player_name, setup.player_name);
3965 StartTextInput(startx, starty, pos->width, pos->height);
3967 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3969 setup.player_name[xpos] = key_char;
3970 setup.player_name[xpos + 1] = 0;
3974 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3978 setup.player_name[xpos] = 0;
3980 else if (key == KSYM_Return && xpos > 0)
3986 SetGameStatus(GAME_MODE_MAIN);
3988 else if (key == KSYM_Escape)
3990 strcpy(setup.player_name, last_player_name);
3994 SetGameStatus(GAME_MODE_MAIN);
3999 pos->width = (strlen(setup.player_name) + 1) * font_width;
4000 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4002 DrawText(startx, starty, setup.player_name, font_active_nr);
4003 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
4007 pos->width = strlen(setup.player_name) * font_width;
4008 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4010 DrawText(startx, starty, setup.player_name, font_nr);
4017 // ============================================================================
4018 // tree menu functions
4019 // ============================================================================
4021 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4023 if (game_status != GAME_MODE_SETUP ||
4024 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4027 int max_text_size = 0;
4030 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4031 max_text_size = MAX(max_text_size, strlen(node->name));
4033 int num_entries = numTreeInfoInGroup(ti);
4034 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4035 int text_width = max_text_size * getFontWidth(FONT_TEXT_1);
4036 int button_width = SC_MENUBUTTON_XSIZE;
4037 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4038 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4039 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4040 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4041 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4042 int align_xoffset = MAX(0, align_xoffset_raw);
4044 return align_xoffset;
4047 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4049 if (game_status != GAME_MODE_SETUP ||
4050 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4053 int num_entries = numTreeInfoInGroup(ti);
4054 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4055 int font_height = getFontHeight(FONT_TEXT_1);
4056 int text_height = font_height * num_page_entries;
4057 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4058 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4059 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4060 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4061 int align_yoffset = MAX(0, align_yoffset_raw);
4063 return align_yoffset;
4066 static void DrawChooseTree(TreeInfo **ti_ptr)
4068 int fade_mask = REDRAW_FIELD;
4071 fade_mask = REDRAW_ALL;
4073 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4075 SetGameStatus(GAME_MODE_MAIN);
4084 FreeScreenGadgets();
4085 CreateScreenGadgets();
4089 // needed if different viewport properties defined for choosing level (set)
4090 ChangeViewportPropertiesIfNeeded();
4092 if (game_status == GAME_MODE_LEVELNR)
4093 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4094 else if (game_status == GAME_MODE_LEVELS)
4095 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4099 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4101 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4102 MapScreenTreeGadgets(*ti_ptr);
4104 DrawMaskedBorder(fade_mask);
4109 static void drawChooseTreeList(int first_entry, int num_page_entries,
4112 int num_entries = numTreeInfoInGroup(ti);
4113 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4114 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4115 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4116 int font_nr = FONT_TEXT_1;
4117 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4119 char *title_string = NULL;
4120 int yoffset_sets = MENU_TITLE1_YPOS;
4121 int yoffset_setup = 16;
4122 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4123 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4125 title_string = ti->infotext;
4127 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4129 clearMenuListArea();
4131 for (i = 0; i < num_page_entries; i++)
4133 TreeInfo *node, *node_first;
4134 int entry_pos = first_entry + i;
4135 int xpos = MENU_SCREEN_START_XPOS;
4136 int ypos = MENU_SCREEN_START_YPOS + i;
4137 int startx = amSX + xpos * 32;
4138 int starty = amSY + ypos * 32;
4139 int startx_text = startx + font_xoffset;
4140 int endx_text = amSX + screen_width;
4141 int max_text_size = endx_text - startx_text;
4142 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4143 char buffer[max_buffer_len + 1];
4145 node_first = getTreeInfoFirstGroupEntry(ti);
4146 node = getTreeInfoFromPos(node_first, entry_pos);
4148 strncpy(buffer, node->name, max_buffer_len);
4149 buffer[max_buffer_len] = '\0';
4151 DrawText(startx, starty, buffer, font_nr + node->color);
4153 if (node->parent_link)
4154 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4155 else if (node->level_group)
4156 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4158 initCursor(i, IMG_MENU_BUTTON);
4161 redraw_mask |= REDRAW_FIELD;
4164 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4166 TreeInfo *node, *node_first;
4167 int x, last_redraw_mask = redraw_mask;
4168 int ypos = MENU_TITLE2_YPOS;
4169 int font_nr = FONT_TITLE_2;
4171 if (ti->type == TREE_TYPE_LEVEL_NR)
4172 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4174 if (ti->type != TREE_TYPE_LEVEL_DIR)
4177 node_first = getTreeInfoFirstGroupEntry(ti);
4178 node = getTreeInfoFromPos(node_first, entry_pos);
4180 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4182 if (node->parent_link)
4183 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4184 node->node_parent->name);
4185 else if (node->level_group)
4186 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4188 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4189 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4190 node->levels, (node->levels > 1 ? "levels" : "level"),
4193 // let BackToFront() redraw only what is needed
4194 redraw_mask = last_redraw_mask;
4195 for (x = 0; x < SCR_FIELDX; x++)
4196 MarkTileDirty(x, 1);
4199 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4202 TreeInfo *ti = *ti_ptr;
4204 int y = ti->cl_cursor;
4205 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4206 int num_entries = numTreeInfoInGroup(ti);
4207 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4208 boolean position_set_by_scrollbar = (dx == 999);
4210 if (button == MB_MENU_INITIALIZE)
4212 int num_entries = numTreeInfoInGroup(ti);
4213 int entry_pos = posTreeInfo(ti);
4215 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4216 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4218 if (ti->cl_first == -1)
4220 // only on initialization
4221 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4222 ti->cl_cursor = entry_pos - ti->cl_first;
4224 else if (ti->cl_cursor >= num_page_entries ||
4225 (num_entries > num_page_entries &&
4226 num_entries - ti->cl_first < num_page_entries))
4228 // only after change of list size (by custom graphic configuration)
4229 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4230 ti->cl_cursor = entry_pos - ti->cl_first;
4233 if (position_set_by_scrollbar)
4236 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4239 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4240 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4241 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4245 else if (button == MB_MENU_LEAVE)
4249 PlaySound(SND_MENU_ITEM_SELECTING);
4251 if (ti->node_parent)
4253 *ti_ptr = ti->node_parent;
4254 DrawChooseTree(ti_ptr);
4256 else if (game_status == GAME_MODE_SETUP)
4258 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4259 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4260 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4262 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4263 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4264 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4265 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4266 execSetupGraphics();
4267 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4268 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4269 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4271 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4272 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4273 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4274 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4275 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4276 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4277 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4278 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4285 if (game_status == GAME_MODE_LEVELNR)
4287 int new_level_nr = atoi(level_number_current->identifier);
4289 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4292 SetGameStatus(GAME_MODE_MAIN);
4300 if (mx || my) // mouse input
4302 x = (mx - amSX) / 32;
4303 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4305 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4307 // move cursor instead of scrolling when already at start/end of list
4308 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4310 else if (dy == +1 * SCROLL_LINE &&
4311 ti->cl_first + num_page_entries == num_entries)
4314 // handle scrolling screen one line or page
4315 if (ti->cl_cursor + dy < 0 ||
4316 ti->cl_cursor + dy > num_page_entries - 1)
4318 boolean redraw = FALSE;
4320 if (ABS(dy) == SCROLL_PAGE)
4321 step = num_page_entries - 1;
4323 if (dy < 0 && ti->cl_first > 0)
4325 // scroll page/line up
4327 ti->cl_first -= step;
4328 if (ti->cl_first < 0)
4333 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4335 // scroll page/line down
4337 ti->cl_first += step;
4338 if (ti->cl_first + num_page_entries > num_entries)
4339 ti->cl_first = MAX(0, num_entries - num_page_entries);
4346 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4347 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4348 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4350 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4357 // handle moving cursor one line
4358 y = ti->cl_cursor + dy;
4363 TreeInfo *node_first, *node_cursor;
4364 int entry_pos = ti->cl_first + y;
4366 node_first = getTreeInfoFirstGroupEntry(ti);
4367 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4369 if (node_cursor->node_group)
4373 PlaySound(SND_MENU_ITEM_SELECTING);
4375 node_cursor->cl_first = ti->cl_first;
4376 node_cursor->cl_cursor = ti->cl_cursor;
4377 *ti_ptr = node_cursor->node_group;
4378 DrawChooseTree(ti_ptr);
4383 else if (dx == -1 && ti->node_parent)
4387 PlaySound(SND_MENU_ITEM_SELECTING);
4389 *ti_ptr = ti->node_parent;
4390 DrawChooseTree(ti_ptr);
4395 if (!anyScrollbarGadgetActive() &&
4396 IN_VIS_MENU(x, y) &&
4397 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4398 y >= 0 && y < num_page_entries)
4402 if (y != ti->cl_cursor)
4404 PlaySound(SND_MENU_ITEM_ACTIVATING);
4406 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4407 drawChooseTreeCursor(y, TRUE);
4408 drawChooseTreeInfo(ti->cl_first + y, ti);
4414 if (game_status == GAME_MODE_SETUP)
4416 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4417 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4418 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4420 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4421 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4422 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4423 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4424 execSetupGraphics();
4425 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4426 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4427 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4429 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4430 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4431 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4432 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4433 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4434 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4435 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4436 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4445 TreeInfo *node_first, *node_cursor;
4446 int entry_pos = ti->cl_first + y;
4448 PlaySound(SND_MENU_ITEM_SELECTING);
4450 node_first = getTreeInfoFirstGroupEntry(ti);
4451 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4453 if (node_cursor->node_group)
4457 node_cursor->cl_first = ti->cl_first;
4458 node_cursor->cl_cursor = ti->cl_cursor;
4459 *ti_ptr = node_cursor->node_group;
4460 DrawChooseTree(ti_ptr);
4462 else if (node_cursor->parent_link)
4466 *ti_ptr = node_cursor->node_parent;
4467 DrawChooseTree(ti_ptr);
4473 node_cursor->cl_first = ti->cl_first;
4474 node_cursor->cl_cursor = ti->cl_cursor;
4475 *ti_ptr = node_cursor;
4477 if (ti->type == TREE_TYPE_LEVEL_DIR)
4479 LoadLevelSetup_SeriesInfo();
4481 SaveLevelSetup_LastSeries();
4482 SaveLevelSetup_SeriesInfo();
4486 if (game_status == GAME_MODE_SETUP)
4488 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4489 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4490 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4492 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4493 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4494 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4495 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4496 execSetupGraphics();
4497 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4498 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4499 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4501 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4502 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4503 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4504 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4505 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4506 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4507 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4508 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4515 if (game_status == GAME_MODE_LEVELNR)
4517 int new_level_nr = atoi(level_number_current->identifier);
4519 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4522 SetGameStatus(GAME_MODE_MAIN);
4531 void DrawChooseLevelSet(void)
4533 FadeMenuSoundsAndMusic();
4535 DrawChooseTree(&leveldir_current);
4537 PlayMenuSoundsAndMusic();
4540 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4542 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4545 void DrawChooseLevelNr(void)
4549 FadeMenuSoundsAndMusic();
4551 if (level_number != NULL)
4553 freeTreeInfo(level_number);
4555 level_number = NULL;
4558 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4560 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4561 char identifier[32], name[64];
4564 // temporarily load level info to get level name
4565 LoadLevelInfoOnly(i);
4567 ti->node_top = &level_number;
4568 ti->sort_priority = 10000 + value;
4569 ti->color = (level.no_level_file ? FC_BLUE :
4570 LevelStats_getSolved(i) ? FC_GREEN :
4571 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4573 snprintf(identifier, sizeof(identifier), "%d", value);
4574 snprintf(name, sizeof(name), "%03d: %s", value,
4575 (level.no_level_file ? "(no file)" : level.name));
4577 setString(&ti->identifier, identifier);
4578 setString(&ti->name, name);
4579 setString(&ti->name_sorting, name);
4581 pushTreeInfo(&level_number, ti);
4584 // sort level number values to start with lowest level number
4585 sortTreeInfo(&level_number);
4587 // set current level number to current level number
4588 level_number_current =
4589 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4591 // if that also fails, set current level number to first available level
4592 if (level_number_current == NULL)
4593 level_number_current = level_number;
4595 DrawChooseTree(&level_number_current);
4597 PlayMenuSoundsAndMusic();
4600 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4602 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4605 void DrawHallOfFame(int level_nr, int highlight_position)
4607 int fade_mask = REDRAW_FIELD;
4610 fade_mask = REDRAW_ALL;
4613 FadeMenuSoundsAndMusic();
4615 // (this is needed when called from GameEnd() after winning a game)
4616 KeyboardAutoRepeatOn();
4618 // (this is needed when called from GameEnd() after winning a game)
4619 SetDrawDeactivationMask(REDRAW_NONE);
4620 SetDrawBackgroundMask(REDRAW_FIELD);
4622 if (highlight_position < 0)
4623 LoadScore(level_nr);
4625 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4627 FadeSetEnterScreen();
4631 // needed if different viewport properties defined for scores
4632 ChangeViewportPropertiesIfNeeded();
4634 PlayMenuSoundsAndMusic();
4636 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4638 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4640 DrawMaskedBorder(fade_mask);
4645 static void drawHallOfFameList(int level_nr, int first_entry,
4646 int highlight_position)
4650 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4653 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4654 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4655 "HighScores of Level %d", level_nr);
4657 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4659 int entry = first_entry + i;
4660 boolean active = (entry == highlight_position);
4661 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4662 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4663 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4664 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4665 int dxoff = getFontDrawOffsetX(font_nr1);
4666 int dx1 = 3 * getFontWidth(font_nr1);
4667 int dx2 = dx1 + getFontWidth(font_nr1);
4668 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4669 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4670 int sy = mSY + 64 + i * 32;
4672 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4673 DrawText(mSX + dx1, sy, ".", font_nr1);
4675 for (j = 0; j < num_dots; j++)
4676 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4678 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4679 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4681 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4684 redraw_mask |= REDRAW_FIELD;
4687 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4689 static int level_nr = 0;
4690 static int first_entry = 0;
4691 static int highlight_position = 0;
4692 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4694 if (button == MB_MENU_INITIALIZE)
4698 highlight_position = my;
4700 drawHallOfFameList(level_nr, first_entry, highlight_position);
4705 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
4706 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4710 if (first_entry > 0)
4712 first_entry -= step;
4713 if (first_entry < 0)
4716 drawHallOfFameList(level_nr, first_entry, highlight_position);
4721 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4723 first_entry += step;
4724 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4725 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4727 drawHallOfFameList(level_nr, first_entry, highlight_position);
4730 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4732 PlaySound(SND_MENU_ITEM_SELECTING);
4734 FadeSound(SND_BACKGROUND_SCORES);
4736 if (button == MB_MENU_CHOICE &&
4737 game_status_last_screen == GAME_MODE_PLAYING &&
4738 setup.auto_play_next_level && setup.increment_levels &&
4739 level_nr < leveldir_current->last_level &&
4742 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4746 SetGameStatus(GAME_MODE_MAIN);
4752 if (game_status == GAME_MODE_SCORES)
4753 PlayMenuSoundIfLoop();
4757 // ============================================================================
4758 // setup screen functions
4759 // ============================================================================
4761 static struct TokenInfo *setup_info;
4762 static int num_setup_info; // number of setup entries shown on screen
4763 static int max_setup_info; // total number of setup entries in list
4765 static char *window_size_text;
4766 static char *scaling_type_text;
4767 static char *rendering_mode_text;
4768 static char *vsync_mode_text;
4769 static char *scroll_delay_text;
4770 static char *snapshot_mode_text;
4771 static char *game_speed_text;
4772 static char *network_server_text;
4773 static char *graphics_set_name;
4774 static char *sounds_set_name;
4775 static char *music_set_name;
4776 static char *volume_simple_text;
4777 static char *volume_loops_text;
4778 static char *volume_music_text;
4779 static char *touch_controls_text;
4780 static char *move_distance_text;
4781 static char *drop_distance_text;
4782 static char *transparency_text;
4783 static char *grid_size_text[2][2];
4785 static void execSetupMain(void)
4787 setup_mode = SETUP_MODE_MAIN;
4792 static void execSetupGame_setGameSpeeds(boolean update_value)
4794 if (setup.game_speed_extended)
4796 game_speeds_list = game_speeds_list_extended;
4797 game_speeds = game_speeds_extended;
4801 game_speeds_list = game_speeds_list_normal;
4802 game_speeds = game_speeds_normal;
4805 if (game_speeds == NULL)
4809 for (i = 0; game_speeds_list[i].value != -1; i++)
4811 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4812 char identifier[32], name[32];
4813 int value = game_speeds_list[i].value;
4814 char *text = game_speeds_list[i].text;
4816 ti->node_top = &game_speeds;
4817 ti->sort_priority = 10000 - value;
4819 sprintf(identifier, "%d", value);
4820 sprintf(name, "%s", text);
4822 setString(&ti->identifier, identifier);
4823 setString(&ti->name, name);
4824 setString(&ti->name_sorting, name);
4825 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4827 pushTreeInfo(&game_speeds, ti);
4830 // sort game speed values to start with slowest game speed
4831 sortTreeInfo(&game_speeds);
4833 update_value = TRUE;
4838 // set current game speed to configured game speed value
4839 game_speed_current =
4840 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4842 // if that fails, set current game speed to reliable default value
4843 if (game_speed_current == NULL)
4844 game_speed_current =
4845 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4847 // if that also fails, set current game speed to first available speed
4848 if (game_speed_current == NULL)
4849 game_speed_current = game_speeds;
4851 if (setup.game_speed_extended)
4852 game_speeds_extended = game_speeds;
4854 game_speeds_normal = game_speeds;
4857 setup.game_frame_delay = atoi(game_speed_current->identifier);
4859 // needed for displaying game speed text instead of identifier
4860 game_speed_text = game_speed_current->name;
4863 static void execSetupGame_setScrollDelays(void)
4865 if (scroll_delays == NULL)
4869 for (i = 0; scroll_delays_list[i].value != -1; i++)
4871 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4872 char identifier[32], name[32];
4873 int value = scroll_delays_list[i].value;
4874 char *text = scroll_delays_list[i].text;
4876 ti->node_top = &scroll_delays;
4877 ti->sort_priority = value;
4879 sprintf(identifier, "%d", value);
4880 sprintf(name, "%s", text);
4882 setString(&ti->identifier, identifier);
4883 setString(&ti->name, name);
4884 setString(&ti->name_sorting, name);
4885 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4887 pushTreeInfo(&scroll_delays, ti);
4890 // sort scroll delay values to start with lowest scroll delay value
4891 sortTreeInfo(&scroll_delays);
4893 // set current scroll delay value to configured scroll delay value
4894 scroll_delay_current =
4895 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4897 // if that fails, set current scroll delay to reliable default value
4898 if (scroll_delay_current == NULL)
4899 scroll_delay_current =
4900 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4902 // if that also fails, set current scroll delay to first available value
4903 if (scroll_delay_current == NULL)
4904 scroll_delay_current = scroll_delays;
4907 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4909 // needed for displaying scroll delay text instead of identifier
4910 scroll_delay_text = scroll_delay_current->name;
4913 static void execSetupGame_setSnapshotModes(void)
4915 if (snapshot_modes == NULL)
4919 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4921 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4922 char identifier[32], name[32];
4923 char *value = snapshot_modes_list[i].value;
4924 char *text = snapshot_modes_list[i].text;
4926 ti->node_top = &snapshot_modes;
4927 ti->sort_priority = i;
4929 sprintf(identifier, "%s", value);
4930 sprintf(name, "%s", text);
4932 setString(&ti->identifier, identifier);
4933 setString(&ti->name, name);
4934 setString(&ti->name_sorting, name);
4935 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4937 pushTreeInfo(&snapshot_modes, ti);
4940 // sort snapshot mode values to start with lowest snapshot mode value
4941 sortTreeInfo(&snapshot_modes);
4943 // set current snapshot mode value to configured snapshot mode value
4944 snapshot_mode_current =
4945 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4947 // if that fails, set current snapshot mode to reliable default value
4948 if (snapshot_mode_current == NULL)
4949 snapshot_mode_current =
4950 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4952 // if that also fails, set current snapshot mode to first available value
4953 if (snapshot_mode_current == NULL)
4954 snapshot_mode_current = snapshot_modes;
4957 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4959 // needed for displaying snapshot mode text instead of identifier
4960 snapshot_mode_text = snapshot_mode_current->name;
4963 static void execSetupGame_setNetworkServerText(void)
4965 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
4967 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
4971 strncpy(network_server_hostname, setup.network_server_hostname,
4972 MAX_SETUP_TEXT_INPUT_LEN);
4973 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
4976 // needed for displaying network server text instead of identifier
4977 network_server_text = network_server_hostname;
4980 static void execSetupGame(void)
4982 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
4984 execSetupGame_setGameSpeeds(FALSE);
4985 execSetupGame_setScrollDelays();
4986 execSetupGame_setSnapshotModes();
4988 execSetupGame_setNetworkServerText();
4990 setup_mode = SETUP_MODE_GAME;
4994 // check if vsync needs to be disabled for this game speed to work
4995 if (check_vsync_mode)
4996 DisableVsyncIfNeeded();
4999 static void execSetupChooseGameSpeed(void)
5001 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5006 static void execSetupChooseScrollDelay(void)
5008 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5013 static void execSetupChooseSnapshotMode(void)
5015 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5020 static void execSetupEditor(void)
5022 setup_mode = SETUP_MODE_EDITOR;
5027 static void execSetupGraphics_setWindowSizes(boolean update_list)
5029 if (window_sizes != NULL && update_list)
5031 freeTreeInfo(window_sizes);
5033 window_sizes = NULL;
5036 if (window_sizes == NULL)
5038 boolean current_window_size_found = FALSE;
5041 for (i = 0; window_sizes_list[i].value != -1; i++)
5043 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5044 char identifier[32], name[32];
5045 int value = window_sizes_list[i].value;
5046 char *text = window_sizes_list[i].text;
5048 ti->node_top = &window_sizes;
5049 ti->sort_priority = value;
5051 sprintf(identifier, "%d", value);
5052 sprintf(name, "%s", text);
5054 setString(&ti->identifier, identifier);
5055 setString(&ti->name, name);
5056 setString(&ti->name_sorting, name);
5057 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5059 pushTreeInfo(&window_sizes, ti);
5061 if (value == setup.window_scaling_percent)
5062 current_window_size_found = TRUE;
5065 if (!current_window_size_found)
5067 // add entry for non-preset window scaling value
5069 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5070 char identifier[32], name[32];
5071 int value = setup.window_scaling_percent;
5073 ti->node_top = &window_sizes;
5074 ti->sort_priority = value;
5076 sprintf(identifier, "%d", value);
5077 sprintf(name, "%d %% (Current)", value);
5079 setString(&ti->identifier, identifier);
5080 setString(&ti->name, name);
5081 setString(&ti->name_sorting, name);
5082 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5084 pushTreeInfo(&window_sizes, ti);
5087 // sort window size values to start with lowest window size value
5088 sortTreeInfo(&window_sizes);
5090 // set current window size value to configured window size value
5091 window_size_current =
5092 getTreeInfoFromIdentifier(window_sizes,
5093 i_to_a(setup.window_scaling_percent));
5095 // if that fails, set current window size to reliable default value
5096 if (window_size_current == NULL)
5097 window_size_current =
5098 getTreeInfoFromIdentifier(window_sizes,
5099 i_to_a(STD_WINDOW_SCALING_PERCENT));
5101 // if that also fails, set current window size to first available value
5102 if (window_size_current == NULL)
5103 window_size_current = window_sizes;
5106 setup.window_scaling_percent = atoi(window_size_current->identifier);
5108 // needed for displaying window size text instead of identifier
5109 window_size_text = window_size_current->name;
5112 static void execSetupGraphics_setScalingTypes(void)
5114 if (scaling_types == NULL)
5118 for (i = 0; scaling_types_list[i].value != NULL; i++)
5120 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5121 char identifier[32], name[32];
5122 char *value = scaling_types_list[i].value;
5123 char *text = scaling_types_list[i].text;
5125 ti->node_top = &scaling_types;
5126 ti->sort_priority = i;
5128 sprintf(identifier, "%s", value);
5129 sprintf(name, "%s", text);
5131 setString(&ti->identifier, identifier);
5132 setString(&ti->name, name);
5133 setString(&ti->name_sorting, name);
5134 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5136 pushTreeInfo(&scaling_types, ti);
5139 // sort scaling type values to start with lowest scaling type value
5140 sortTreeInfo(&scaling_types);
5142 // set current scaling type value to configured scaling type value
5143 scaling_type_current =
5144 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5146 // if that fails, set current scaling type to reliable default value
5147 if (scaling_type_current == NULL)
5148 scaling_type_current =
5149 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5151 // if that also fails, set current scaling type to first available value
5152 if (scaling_type_current == NULL)
5153 scaling_type_current = scaling_types;
5156 setup.window_scaling_quality = scaling_type_current->identifier;
5158 // needed for displaying scaling type text instead of identifier
5159 scaling_type_text = scaling_type_current->name;
5162 static void execSetupGraphics_setRenderingModes(void)
5164 if (rendering_modes == NULL)
5168 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5170 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5171 char identifier[32], name[32];
5172 char *value = rendering_modes_list[i].value;
5173 char *text = rendering_modes_list[i].text;
5175 ti->node_top = &rendering_modes;
5176 ti->sort_priority = i;
5178 sprintf(identifier, "%s", value);
5179 sprintf(name, "%s", text);
5181 setString(&ti->identifier, identifier);
5182 setString(&ti->name, name);
5183 setString(&ti->name_sorting, name);
5184 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5186 pushTreeInfo(&rendering_modes, ti);
5189 // sort rendering mode values to start with lowest rendering mode value
5190 sortTreeInfo(&rendering_modes);
5192 // set current rendering mode value to configured rendering mode value
5193 rendering_mode_current =
5194 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5196 // if that fails, set current rendering mode to reliable default value
5197 if (rendering_mode_current == NULL)
5198 rendering_mode_current =
5199 getTreeInfoFromIdentifier(rendering_modes,
5200 STR_SPECIAL_RENDERING_DEFAULT);
5202 // if that also fails, set current rendering mode to first available one
5203 if (rendering_mode_current == NULL)
5204 rendering_mode_current = rendering_modes;
5207 setup.screen_rendering_mode = rendering_mode_current->identifier;
5209 // needed for displaying rendering mode text instead of identifier
5210 rendering_mode_text = rendering_mode_current->name;
5213 static void execSetupGraphics_setVsyncModes(boolean update_value)
5215 if (vsync_modes == NULL)
5219 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5221 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5222 char identifier[32], name[32];
5223 char *value = vsync_modes_list[i].value;
5224 char *text = vsync_modes_list[i].text;
5226 ti->node_top = &vsync_modes;
5227 ti->sort_priority = i;
5229 sprintf(identifier, "%s", value);
5230 sprintf(name, "%s", text);
5232 setString(&ti->identifier, identifier);
5233 setString(&ti->name, name);
5234 setString(&ti->name_sorting, name);
5235 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5237 pushTreeInfo(&vsync_modes, ti);
5240 // sort vsync mode values to start with lowest vsync mode value
5241 sortTreeInfo(&vsync_modes);
5243 update_value = TRUE;
5248 // set current vsync mode value to configured vsync mode value
5249 vsync_mode_current =
5250 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5252 // if that fails, set current vsync mode to reliable default value
5253 if (vsync_mode_current == NULL)
5254 vsync_mode_current =
5255 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5257 // if that also fails, set current vsync mode to first available one
5258 if (vsync_mode_current == NULL)
5259 vsync_mode_current = vsync_modes;
5262 setup.vsync_mode = vsync_mode_current->identifier;
5264 // needed for displaying vsync mode text instead of identifier
5265 vsync_mode_text = vsync_mode_current->name;
5268 static void execSetupGraphics(void)
5270 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5272 // update "setup.window_scaling_percent" from list selection
5273 // (in this case, window scaling was changed on setup screen)
5274 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5275 execSetupGraphics_setWindowSizes(FALSE);
5277 // update list selection from "setup.window_scaling_percent"
5278 // (window scaling may have changed by resizing the window)
5279 execSetupGraphics_setWindowSizes(TRUE);
5281 execSetupGraphics_setScalingTypes();
5282 execSetupGraphics_setRenderingModes();
5283 execSetupGraphics_setVsyncModes(FALSE);
5285 setup_mode = SETUP_MODE_GRAPHICS;
5289 // check if game speed is high enough for 60 Hz vsync to work
5290 if (check_game_speed)
5291 ModifyGameSpeedIfNeeded();
5293 // window scaling may have changed at this point
5294 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5296 // window scaling quality may have changed at this point
5297 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5298 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5300 // screen rendering mode may have changed at this point
5301 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5303 // screen vsync mode may have changed at this point
5304 SDLSetScreenVsyncMode(setup.vsync_mode);
5307 static void execSetupChooseWindowSize(void)
5309 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5314 static void execSetupChooseScalingType(void)
5316 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5321 static void execSetupChooseRenderingMode(void)
5323 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5328 static void execSetupChooseVsyncMode(void)
5330 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5335 static void execSetupChooseVolumeSimple(void)
5337 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5342 static void execSetupChooseVolumeLoops(void)
5344 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5349 static void execSetupChooseVolumeMusic(void)
5351 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5356 static void execSetupSound(void)
5358 if (volumes_simple == NULL)
5360 boolean current_volume_simple_found = FALSE;
5363 for (i = 0; volumes_list[i].value != -1; i++)
5365 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5366 char identifier[32], name[32];
5367 int value = volumes_list[i].value;
5368 char *text = volumes_list[i].text;
5370 ti->node_top = &volumes_simple;
5371 ti->sort_priority = value;
5373 sprintf(identifier, "%d", value);
5374 sprintf(name, "%s", text);
5376 setString(&ti->identifier, identifier);
5377 setString(&ti->name, name);
5378 setString(&ti->name_sorting, name);
5379 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5381 pushTreeInfo(&volumes_simple, ti);
5383 if (value == setup.volume_simple)
5384 current_volume_simple_found = TRUE;
5387 if (!current_volume_simple_found)
5389 // add entry for non-preset volume value
5391 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5392 char identifier[32], name[32];
5393 int value = setup.volume_simple;
5395 ti->node_top = &volumes_simple;
5396 ti->sort_priority = value;
5398 sprintf(identifier, "%d", value);
5399 sprintf(name, "%d %% (Current)", value);
5401 setString(&ti->identifier, identifier);
5402 setString(&ti->name, name);
5403 setString(&ti->name_sorting, name);
5404 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5406 pushTreeInfo(&volumes_simple, ti);
5409 // sort volume values to start with lowest volume value
5410 sortTreeInfo(&volumes_simple);
5412 // set current volume value to configured volume value
5413 volume_simple_current =
5414 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5416 // if that fails, set current volume to reliable default value
5417 if (volume_simple_current == NULL)
5418 volume_simple_current =
5419 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5421 // if that also fails, set current volume to first available value
5422 if (volume_simple_current == NULL)
5423 volume_simple_current = volumes_simple;
5426 if (volumes_loops == NULL)
5428 boolean current_volume_loops_found = FALSE;
5431 for (i = 0; volumes_list[i].value != -1; i++)
5433 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5434 char identifier[32], name[32];
5435 int value = volumes_list[i].value;
5436 char *text = volumes_list[i].text;
5438 ti->node_top = &volumes_loops;
5439 ti->sort_priority = value;
5441 sprintf(identifier, "%d", value);
5442 sprintf(name, "%s", text);
5444 setString(&ti->identifier, identifier);
5445 setString(&ti->name, name);
5446 setString(&ti->name_sorting, name);
5447 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5449 pushTreeInfo(&volumes_loops, ti);
5451 if (value == setup.volume_loops)
5452 current_volume_loops_found = TRUE;
5455 if (!current_volume_loops_found)
5457 // add entry for non-preset volume value
5459 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5460 char identifier[32], name[32];
5461 int value = setup.volume_loops;
5463 ti->node_top = &volumes_loops;
5464 ti->sort_priority = value;
5466 sprintf(identifier, "%d", value);
5467 sprintf(name, "%d %% (Current)", value);
5469 setString(&ti->identifier, identifier);
5470 setString(&ti->name, name);
5471 setString(&ti->name_sorting, name);
5472 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5474 pushTreeInfo(&volumes_loops, ti);
5477 // sort volume values to start with lowest volume value
5478 sortTreeInfo(&volumes_loops);
5480 // set current volume value to configured volume value
5481 volume_loops_current =
5482 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5484 // if that fails, set current volume to reliable default value
5485 if (volume_loops_current == NULL)
5486 volume_loops_current =
5487 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5489 // if that also fails, set current volume to first available value
5490 if (volume_loops_current == NULL)
5491 volume_loops_current = volumes_loops;
5494 if (volumes_music == NULL)
5496 boolean current_volume_music_found = FALSE;
5499 for (i = 0; volumes_list[i].value != -1; i++)
5501 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5502 char identifier[32], name[32];
5503 int value = volumes_list[i].value;
5504 char *text = volumes_list[i].text;
5506 ti->node_top = &volumes_music;
5507 ti->sort_priority = value;
5509 sprintf(identifier, "%d", value);
5510 sprintf(name, "%s", text);
5512 setString(&ti->identifier, identifier);
5513 setString(&ti->name, name);
5514 setString(&ti->name_sorting, name);
5515 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5517 pushTreeInfo(&volumes_music, ti);
5519 if (value == setup.volume_music)
5520 current_volume_music_found = TRUE;
5523 if (!current_volume_music_found)
5525 // add entry for non-preset volume value
5527 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5528 char identifier[32], name[32];
5529 int value = setup.volume_music;
5531 ti->node_top = &volumes_music;
5532 ti->sort_priority = value;
5534 sprintf(identifier, "%d", value);
5535 sprintf(name, "%d %% (Current)", value);
5537 setString(&ti->identifier, identifier);
5538 setString(&ti->name, name);
5539 setString(&ti->name_sorting, name);
5540 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5542 pushTreeInfo(&volumes_music, ti);
5545 // sort volume values to start with lowest volume value
5546 sortTreeInfo(&volumes_music);
5548 // set current volume value to configured volume value
5549 volume_music_current =
5550 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5552 // if that fails, set current volume to reliable default value
5553 if (volume_music_current == NULL)
5554 volume_music_current =
5555 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5557 // if that also fails, set current volume to first available value
5558 if (volume_music_current == NULL)
5559 volume_music_current = volumes_music;
5562 setup.volume_simple = atoi(volume_simple_current->identifier);
5563 setup.volume_loops = atoi(volume_loops_current->identifier);
5564 setup.volume_music = atoi(volume_music_current->identifier);
5566 // needed for displaying volume text instead of identifier
5567 volume_simple_text = volume_simple_current->name;
5568 volume_loops_text = volume_loops_current->name;
5569 volume_music_text = volume_music_current->name;
5571 setup_mode = SETUP_MODE_SOUND;
5576 static void execSetupChooseTouchControls(void)
5578 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5583 static void execSetupChooseMoveDistance(void)
5585 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5590 static void execSetupChooseDropDistance(void)
5592 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5597 static void execSetupChooseTransparency(void)
5599 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5604 static void execSetupChooseGridXSize_0(void)
5606 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5611 static void execSetupChooseGridYSize_0(void)
5613 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5618 static void execSetupChooseGridXSize_1(void)
5620 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5625 static void execSetupChooseGridYSize_1(void)
5627 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5632 static void execSetupConfigureVirtualButtons(void)
5634 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5636 ConfigureVirtualButtons();
5638 setup_mode = SETUP_MODE_TOUCH;
5643 static void execSetupTouch(void)
5647 if (touch_controls == NULL)
5649 for (i = 0; touch_controls_list[i].value != NULL; i++)
5651 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5652 char identifier[32], name[32];
5653 char *value = touch_controls_list[i].value;
5654 char *text = touch_controls_list[i].text;
5656 ti->node_top = &touch_controls;
5657 ti->sort_priority = i;
5659 sprintf(identifier, "%s", value);
5660 sprintf(name, "%s", text);
5662 setString(&ti->identifier, identifier);
5663 setString(&ti->name, name);
5664 setString(&ti->name_sorting, name);
5665 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5667 pushTreeInfo(&touch_controls, ti);
5670 // sort touch control values to start with lowest touch control value
5671 sortTreeInfo(&touch_controls);
5673 // set current touch control value to configured touch control value
5674 touch_control_current =
5675 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5677 // if that fails, set current touch control to reliable default value
5678 if (touch_control_current == NULL)
5679 touch_control_current =
5680 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5682 // if that also fails, set current touch control to first available value
5683 if (touch_control_current == NULL)
5684 touch_control_current = touch_controls;
5687 if (move_distances == NULL)
5689 for (i = 0; distances_list[i].value != -1; i++)
5691 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5692 char identifier[32], name[32];
5693 int value = distances_list[i].value;
5694 char *text = distances_list[i].text;
5696 ti->node_top = &move_distances;
5697 ti->sort_priority = value;
5699 sprintf(identifier, "%d", value);
5700 sprintf(name, "%s", text);
5702 setString(&ti->identifier, identifier);
5703 setString(&ti->name, name);
5704 setString(&ti->name_sorting, name);
5705 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5707 pushTreeInfo(&move_distances, ti);
5710 // sort distance values to start with lowest distance value
5711 sortTreeInfo(&move_distances);
5713 // set current distance value to configured distance value
5714 move_distance_current =
5715 getTreeInfoFromIdentifier(move_distances,
5716 i_to_a(setup.touch.move_distance));
5718 // if that fails, set current distance to reliable default value
5719 if (move_distance_current == NULL)
5720 move_distance_current =
5721 getTreeInfoFromIdentifier(move_distances,
5722 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5724 // if that also fails, set current distance to first available value
5725 if (move_distance_current == NULL)
5726 move_distance_current = move_distances;
5729 if (drop_distances == NULL)
5731 for (i = 0; distances_list[i].value != -1; i++)
5733 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5734 char identifier[32], name[32];
5735 int value = distances_list[i].value;
5736 char *text = distances_list[i].text;
5738 ti->node_top = &drop_distances;
5739 ti->sort_priority = value;
5741 sprintf(identifier, "%d", value);
5742 sprintf(name, "%s", text);
5744 setString(&ti->identifier, identifier);
5745 setString(&ti->name, name);
5746 setString(&ti->name_sorting, name);
5747 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5749 pushTreeInfo(&drop_distances, ti);
5752 // sort distance values to start with lowest distance value
5753 sortTreeInfo(&drop_distances);
5755 // set current distance value to configured distance value
5756 drop_distance_current =
5757 getTreeInfoFromIdentifier(drop_distances,
5758 i_to_a(setup.touch.drop_distance));
5760 // if that fails, set current distance to reliable default value
5761 if (drop_distance_current == NULL)
5762 drop_distance_current =
5763 getTreeInfoFromIdentifier(drop_distances,
5764 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5766 // if that also fails, set current distance to first available value
5767 if (drop_distance_current == NULL)
5768 drop_distance_current = drop_distances;
5771 if (transparencies == NULL)
5773 for (i = 0; transparencies_list[i].value != -1; i++)
5775 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5776 char identifier[32], name[32];
5777 int value = transparencies_list[i].value;
5778 char *text = transparencies_list[i].text;
5780 ti->node_top = &transparencies;
5781 ti->sort_priority = value;
5783 sprintf(identifier, "%d", value);
5784 sprintf(name, "%s", text);
5786 setString(&ti->identifier, identifier);
5787 setString(&ti->name, name);
5788 setString(&ti->name_sorting, name);
5789 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5791 pushTreeInfo(&transparencies, ti);
5794 // sort transparency values to start with lowest transparency value
5795 sortTreeInfo(&transparencies);
5797 // set current transparency value to configured transparency value
5798 transparency_current =
5799 getTreeInfoFromIdentifier(transparencies,
5800 i_to_a(setup.touch.transparency));
5802 // if that fails, set current transparency to reliable default value
5803 if (transparency_current == NULL)
5804 transparency_current =
5805 getTreeInfoFromIdentifier(transparencies,
5806 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5808 // if that also fails, set current transparency to first available value
5809 if (transparency_current == NULL)
5810 transparency_current = transparencies;
5813 for (i = 0; i < 2; i++)
5815 for (j = 0; j < 2; j++)
5817 if (grid_sizes[i][j] == NULL)
5819 for (k = 0; grid_sizes_list[k].value != -1; k++)
5821 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5822 char identifier[32], name[32];
5823 int value = grid_sizes_list[k].value;
5824 char *text = grid_sizes_list[k].text;
5826 ti->node_top = &grid_sizes[i][j];
5827 ti->sort_priority = value;
5829 sprintf(identifier, "%d", value);
5830 sprintf(name, "%s", text);
5832 setString(&ti->identifier, identifier);
5833 setString(&ti->name, name);
5834 setString(&ti->name_sorting, name);
5835 setString(&ti->infotext,
5838 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5839 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5841 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5842 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5844 pushTreeInfo(&grid_sizes[i][j], ti);
5847 // sort grid size values to start with lowest grid size value
5848 sortTreeInfo(&grid_sizes[i][j]);
5850 // set current grid size value to configured grid size value
5851 grid_size_current[i][j] =
5852 getTreeInfoFromIdentifier(grid_sizes[i][j],
5854 setup.touch.grid_xsize[i] :
5855 setup.touch.grid_ysize[i]));
5857 // if that fails, set current grid size to reliable default value
5858 if (grid_size_current[i][j] == NULL)
5859 grid_size_current[i][j] =
5860 getTreeInfoFromIdentifier(grid_sizes[i][j],
5862 DEFAULT_GRID_XSIZE(i) :
5863 DEFAULT_GRID_YSIZE(i)));
5865 // if that also fails, set current grid size to first available value
5866 if (grid_size_current[i][j] == NULL)
5867 grid_size_current[i][j] = grid_sizes[i][j];
5872 setup.touch.control_type = touch_control_current->identifier;
5873 setup.touch.move_distance = atoi(move_distance_current->identifier);
5874 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5875 setup.touch.transparency = atoi(transparency_current->identifier);
5877 for (i = 0; i < 2; i++)
5879 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5880 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5882 if (i == GRID_ACTIVE_NR())
5884 overlay.grid_xsize = setup.touch.grid_xsize[i];
5885 overlay.grid_ysize = setup.touch.grid_ysize[i];
5889 // needed for displaying value text instead of identifier
5890 touch_controls_text = touch_control_current->name;
5891 move_distance_text = move_distance_current->name;
5892 drop_distance_text = drop_distance_current->name;
5893 transparency_text = transparency_current->name;
5895 for (i = 0; i < 2; i++)
5896 for (j = 0; j < 2; j++)
5897 grid_size_text[i][j] = grid_size_current[i][j]->name;
5899 setup_mode = SETUP_MODE_TOUCH;
5904 static void execSetupArtwork(void)
5907 printf("::: '%s', '%s', '%s'\n",
5908 artwork.gfx_current->subdir,
5909 artwork.gfx_current->fullpath,
5910 artwork.gfx_current->basepath);
5913 setup.graphics_set = artwork.gfx_current->identifier;
5914 setup.sounds_set = artwork.snd_current->identifier;
5915 setup.music_set = artwork.mus_current->identifier;
5917 // needed if last screen (setup choice) changed graphics, sounds or music
5918 ReloadCustomArtwork(0);
5920 // needed for displaying artwork name instead of artwork identifier
5921 graphics_set_name = artwork.gfx_current->name;
5922 sounds_set_name = artwork.snd_current->name;
5923 music_set_name = artwork.mus_current->name;
5925 setup_mode = SETUP_MODE_ARTWORK;
5930 static void execSetupChooseGraphics(void)
5932 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5937 static void execSetupChooseSounds(void)
5939 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5944 static void execSetupChooseMusic(void)
5946 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5951 static void execSetupInput(void)
5953 setup_mode = SETUP_MODE_INPUT;
5958 static void execSetupShortcuts(void)
5960 setup_mode = SETUP_MODE_SHORTCUTS;
5965 static void execSetupShortcuts1(void)
5967 setup_mode = SETUP_MODE_SHORTCUTS_1;
5972 static void execSetupShortcuts2(void)
5974 setup_mode = SETUP_MODE_SHORTCUTS_2;
5979 static void execSetupShortcuts3(void)
5981 setup_mode = SETUP_MODE_SHORTCUTS_3;
5986 static void execSetupShortcuts4(void)
5988 setup_mode = SETUP_MODE_SHORTCUTS_4;
5993 static void execSetupShortcuts5(void)
5995 setup_mode = SETUP_MODE_SHORTCUTS_5;
6000 static void execExitSetup(void)
6002 SetGameStatus(GAME_MODE_MAIN);
6007 static void execSaveAndExitSetup(void)
6013 static void execGadgetNetworkServer(void)
6015 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6016 struct GadgetInfo *gi = screen_gadget[gadget_id];
6018 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6019 network_server_hostname[0] = '\0';
6021 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6025 ClickOnGadget(gi, MB_LEFTBUTTON);
6028 static void ToggleNetworkModeIfNeeded(void)
6030 int font_title = FONT_TITLE_1;
6031 int font_foot = FC_BLUE;
6032 int ystart = mSY - SY + 16;
6033 int ybottom = mSY - SY + SYSIZE - 20;
6034 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6036 if (setup.network_mode == network.enabled)
6039 network.enabled = setup.network_mode;
6041 FadeOut(REDRAW_ALL);
6045 DrawTextSCentered(ystart, font_title, text);
6049 if (network.enabled)
6050 InitNetworkServer();
6052 DisconnectFromNetworkServer();
6054 DrawTextSCentered(ybottom, font_foot,
6055 "Press any key or button for setup menu");
6057 WaitForEventToContinue();
6062 static void ToggleGameSpeedsListIfNeeded(void)
6064 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6066 if (setup.game_speed_extended == using_game_speeds_extended)
6069 // try to match similar values when changing game speeds list
6070 if (setup.game_speed_extended)
6071 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6072 setup.game_frame_delay == 30 ? 29 :
6073 setup.game_frame_delay);
6075 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6076 setup.game_frame_delay == 16 ? 15 :
6077 setup.game_frame_delay >= 29 ? 30 :
6078 setup.game_frame_delay <= 10 ? 10 :
6079 setup.game_frame_delay);
6081 execSetupGame_setGameSpeeds(TRUE);
6086 static void ModifyGameSpeedIfNeeded(void)
6088 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6089 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6093 char *game_speed_text = "Fast";
6094 int game_speed_value = 15;
6096 if (setup.game_speed_extended)
6098 game_speed_text = "60 fps";
6099 game_speed_value = 16;
6102 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6104 // set game speed to existing list value that is fast enough for vsync
6105 setup.game_frame_delay = game_speed_value;
6107 execSetupGame_setGameSpeeds(TRUE);
6109 Request(message, REQ_CONFIRM);
6112 static void DisableVsyncIfNeeded(void)
6114 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6115 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6116 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6119 // disable vsync for the selected game speed to work
6120 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6122 execSetupGraphics_setVsyncModes(TRUE);
6124 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6130 void *related_value;
6131 } hide_related_entry_list[] =
6133 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6134 { &setup.game_frame_delay, &game_speed_text },
6136 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6137 { &setup.scroll_delay_value, &scroll_delay_text },
6139 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6140 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6142 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6143 { &setup.window_scaling_percent, &window_size_text },
6145 { &setup.window_scaling_quality, execSetupChooseScalingType },
6146 { &setup.window_scaling_quality, &scaling_type_text },
6148 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6149 { &setup.screen_rendering_mode, &rendering_mode_text },
6151 { &setup.vsync_mode, execSetupChooseVsyncMode },
6152 { &setup.vsync_mode, &vsync_mode_text },
6154 { &setup.graphics_set, execSetupChooseGraphics },
6155 { &setup.graphics_set, &graphics_set_name },
6157 { &setup.sounds_set, execSetupChooseSounds },
6158 { &setup.sounds_set, &sounds_set_name },
6160 { &setup.music_set, execSetupChooseMusic },
6161 { &setup.music_set, &music_set_name },
6163 { &setup.volume_simple, execSetupChooseVolumeSimple },
6164 { &setup.volume_simple, &volume_simple_text },
6166 { &setup.volume_loops, execSetupChooseVolumeLoops },
6167 { &setup.volume_loops, &volume_loops_text },
6169 { &setup.volume_music, execSetupChooseVolumeMusic },
6170 { &setup.volume_music, &volume_music_text },
6172 { &setup.touch.control_type, execSetupChooseTouchControls },
6173 { &setup.touch.control_type, &touch_controls_text },
6175 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6176 { &setup.touch.move_distance, &move_distance_text },
6178 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6179 { &setup.touch.drop_distance, &drop_distance_text },
6181 { &setup.touch.transparency, execSetupChooseTransparency },
6182 { &setup.touch.transparency, &transparency_text },
6184 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6185 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6187 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6188 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6190 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6191 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6193 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6194 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6196 { &setup.internal.menu_game, execSetupGame },
6197 { &setup.internal.menu_editor, execSetupEditor },
6198 { &setup.internal.menu_graphics, execSetupGraphics },
6199 { &setup.internal.menu_sound, execSetupSound },
6200 { &setup.internal.menu_artwork, execSetupArtwork },
6201 { &setup.internal.menu_input, execSetupInput },
6202 { &setup.internal.menu_touch, execSetupTouch },
6203 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6204 { &setup.internal.menu_exit, execExitSetup },
6205 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6210 void setHideRelatedSetupEntries(void)
6214 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6215 if (hideSetupEntry(hide_related_entry_list[i].value))
6216 setHideSetupEntry(hide_related_entry_list[i].related_value);
6219 static struct TokenInfo setup_info_main[] =
6221 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6222 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6223 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6224 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6225 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6226 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6227 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6228 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6229 { TYPE_EMPTY, NULL, "" },
6230 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6231 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6236 static struct TokenInfo setup_info_game[] =
6238 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6239 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6240 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6241 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6242 { TYPE_STRING, &network_server_text, "" },
6243 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6244 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6245 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6246 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6247 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6248 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6249 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
6250 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6251 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6252 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6253 { TYPE_STRING, &game_speed_text, "" },
6254 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6256 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6257 { TYPE_STRING, &scroll_delay_text, "" },
6259 { TYPE_SWITCH, &setup.forced_scroll_delay,"Scroll Delay in EM engine:" },
6260 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6261 { TYPE_STRING, &snapshot_mode_text, "" },
6262 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6263 { TYPE_EMPTY, NULL, "" },
6264 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6269 static struct TokenInfo setup_info_editor[] =
6272 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6273 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6274 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6275 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6276 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6277 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6278 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6279 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6280 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6281 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6283 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6284 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6286 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6288 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6289 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6290 { TYPE_EMPTY, NULL, "" },
6292 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6293 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6294 { TYPE_EMPTY, NULL, "" },
6296 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6297 { TYPE_EMPTY, NULL, "" },
6298 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6303 static struct TokenInfo setup_info_graphics[] =
6305 #if !defined(PLATFORM_ANDROID)
6306 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6307 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6308 { TYPE_STRING, &window_size_text, "" },
6309 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6310 { TYPE_STRING, &scaling_type_text, "" },
6311 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6312 { TYPE_STRING, &rendering_mode_text, "" },
6315 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6316 { TYPE_STRING, &scroll_delay_text, "" },
6318 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6319 { TYPE_STRING, &vsync_mode_text, "" },
6320 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6321 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6322 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6323 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6324 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6325 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
6326 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
6327 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6328 { TYPE_EMPTY, NULL, "" },
6329 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6334 static struct TokenInfo setup_info_sound[] =
6336 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6337 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6338 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6339 { TYPE_EMPTY, NULL, "" },
6340 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6341 { TYPE_STRING, &volume_simple_text, "" },
6342 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6343 { TYPE_STRING, &volume_loops_text, "" },
6344 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6345 { TYPE_STRING, &volume_music_text, "" },
6346 { TYPE_EMPTY, NULL, "" },
6347 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6352 static struct TokenInfo setup_info_artwork[] =
6354 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6355 { TYPE_STRING, &graphics_set_name, "" },
6356 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6357 { TYPE_STRING, &sounds_set_name, "" },
6358 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6359 { TYPE_STRING, &music_set_name, "" },
6360 { TYPE_EMPTY, NULL, "" },
6361 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6362 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6363 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6364 { TYPE_EMPTY, NULL, "" },
6365 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6370 static struct TokenInfo setup_info_input[] =
6372 { TYPE_SWITCH, NULL, "Player:" },
6373 { TYPE_SWITCH, NULL, "Device:" },
6374 { TYPE_SWITCH, NULL, "" },
6375 { TYPE_SKIPPABLE, NULL, "" },
6376 { TYPE_EMPTY, NULL, "" },
6377 { TYPE_EMPTY, NULL, "" },
6378 { TYPE_EMPTY, NULL, "" },
6379 { TYPE_EMPTY, NULL, "" },
6380 { TYPE_EMPTY, NULL, "" },
6381 { TYPE_EMPTY, NULL, "" },
6382 { TYPE_EMPTY, NULL, "" },
6383 { TYPE_EMPTY, NULL, "" },
6384 { TYPE_SKIPPABLE, NULL, "" },
6385 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6390 static struct TokenInfo setup_info_touch[] =
6392 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6393 { TYPE_STRING, &touch_controls_text, "" },
6394 { TYPE_EMPTY, NULL, "" },
6395 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6400 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6402 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6403 { TYPE_STRING, &touch_controls_text, "" },
6404 { TYPE_EMPTY, NULL, "" },
6405 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6406 { TYPE_STRING, &grid_size_text[0][0], "" },
6407 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6408 { TYPE_STRING, &grid_size_text[0][1], "" },
6409 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6410 { TYPE_STRING, &transparency_text, "" },
6411 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6412 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6413 { TYPE_EMPTY, NULL, "" },
6414 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6415 { TYPE_EMPTY, NULL, "" },
6416 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6421 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6423 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6424 { TYPE_STRING, &touch_controls_text, "" },
6425 { TYPE_EMPTY, NULL, "" },
6426 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6427 { TYPE_STRING, &grid_size_text[1][0], "" },
6428 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6429 { TYPE_STRING, &grid_size_text[1][1], "" },
6430 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6431 { TYPE_STRING, &transparency_text, "" },
6432 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6433 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6434 { TYPE_EMPTY, NULL, "" },
6435 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6436 { TYPE_EMPTY, NULL, "" },
6437 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6442 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6444 setup_info_touch_virtual_buttons_0,
6445 setup_info_touch_virtual_buttons_1
6448 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6450 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6451 { TYPE_STRING, &touch_controls_text, "" },
6452 { TYPE_EMPTY, NULL, "" },
6453 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6454 { TYPE_STRING, &move_distance_text, "" },
6455 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6456 { TYPE_STRING, &drop_distance_text, "" },
6457 { TYPE_EMPTY, NULL, "" },
6458 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6463 static struct TokenInfo setup_info_shortcuts[] =
6465 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6466 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6467 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6468 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6469 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6470 { TYPE_EMPTY, NULL, "" },
6471 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6476 static struct TokenInfo setup_info_shortcuts_1[] =
6478 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6479 { TYPE_KEY, &setup.shortcut.save_game, "" },
6480 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6481 { TYPE_KEY, &setup.shortcut.load_game, "" },
6482 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6483 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6484 { TYPE_EMPTY, NULL, "" },
6485 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6486 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6487 { TYPE_EMPTY, NULL, "" },
6488 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6493 static struct TokenInfo setup_info_shortcuts_2[] =
6495 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6496 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6497 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6498 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6499 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6500 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6501 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6502 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6503 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6504 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6505 { TYPE_EMPTY, NULL, "" },
6506 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6511 static struct TokenInfo setup_info_shortcuts_3[] =
6513 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6514 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6515 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6516 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6517 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6518 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6519 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6520 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6521 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6522 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6523 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6524 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6525 { TYPE_EMPTY, NULL, "" },
6526 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6531 static struct TokenInfo setup_info_shortcuts_4[] =
6533 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6534 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6535 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6536 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6537 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6538 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6539 { TYPE_EMPTY, NULL, "" },
6540 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6545 static struct TokenInfo setup_info_shortcuts_5[] =
6547 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6548 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6549 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6550 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6551 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6552 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6553 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6554 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6555 { TYPE_EMPTY, NULL, "" },
6556 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6561 static Key getSetupKey(void)
6563 Key key = KSYM_UNDEFINED;
6564 boolean got_key_event = FALSE;
6566 while (!got_key_event)
6570 if (NextValidEvent(&event))
6574 case EVENT_KEYPRESS:
6576 key = GetEventKey((KeyEvent *)&event, TRUE);
6578 // press 'Escape' or 'Enter' to keep the existing key binding
6579 if (key == KSYM_Escape || key == KSYM_Return)
6580 key = KSYM_UNDEFINED; // keep old value
6582 got_key_event = TRUE;
6586 case EVENT_KEYRELEASE:
6587 key_joystick_mapping = 0;
6591 HandleOtherEvents(&event);
6602 static int getSetupValueFont(int type, void *value)
6604 if (type & TYPE_GHOSTED)
6605 return FONT_OPTION_OFF;
6606 else if (type & TYPE_KEY)
6607 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6608 else if (type & TYPE_STRING)
6609 return FONT_VALUE_2;
6610 else if (type & TYPE_ECS_AGA)
6611 return FONT_VALUE_1;
6612 else if (type & TYPE_BOOLEAN_STYLE)
6613 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6614 else if (type & TYPE_YES_NO_AUTO)
6615 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6616 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6617 else if (type & TYPE_PLAYER)
6618 return FONT_VALUE_1;
6620 return FONT_VALUE_1;
6623 static int getSetupValueFontNarrow(int type, int font_nr)
6625 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6626 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6627 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6631 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6633 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6634 struct TokenInfo *si = &setup_info[si_pos];
6635 boolean font_draw_xoffset_modified = FALSE;
6636 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6637 int font_draw_xoffset_old = -1;
6638 int xoffset = (scrollbar_needed ? -1 : 0);
6639 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6640 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6641 int xpos = menu_screen_value_xpos;
6642 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6643 int startx = mSX + xpos * 32;
6644 int starty = mSY + ypos * 32;
6645 int type = si->type;
6646 void *value = si->value;
6647 char *value_string = getSetupValue(type, value);
6648 int font_nr_default = getSetupValueFont(type, value);
6649 int font_width_default = getFontWidth(font_nr_default);
6650 int font_nr = font_nr_default;
6653 if (value_string == NULL)
6656 if (type & TYPE_KEY)
6658 xpos = MENU_SCREEN_START_XPOS;
6660 if (type & TYPE_QUERY)
6661 value_string = "<press key>";
6663 else if (type & TYPE_STRING)
6665 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
6667 xpos = MENU_SCREEN_START_XPOS;
6669 if (strlen(value_string) > max_value_len)
6670 value_string[max_value_len] = '\0';
6672 else if (type & TYPE_YES_NO_AUTO)
6674 xpos = menu_screen_value_xpos - 1;
6676 else if (type & TYPE_PLAYER)
6678 int displayed_player_nr = *(int *)value + 1;
6680 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6683 startx = mSX + xpos * 32;
6684 starty = mSY + ypos * 32;
6686 // special check if right-side setup values moved left due to scrollbar
6687 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6689 int max_menu_text_length = 26; // maximum text length for classic menu
6690 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6691 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6692 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6693 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6694 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6696 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6699 startx = mSX + xpos * 32;
6701 font_nr = getSetupValueFontNarrow(type, font_nr);
6705 // downward compatibility correction for Juergen Bonhagen's menu settings
6706 if (setup_mode != SETUP_MODE_INPUT)
6708 int max_menu_text_length_big = (menu_screen_value_xpos -
6709 MENU_SCREEN_START_XPOS);
6710 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6711 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
6712 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6713 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6714 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6715 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6716 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6717 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6718 boolean correct_font_draw_xoffset = FALSE;
6720 if (xpos == MENU_SCREEN_START_XPOS &&
6721 startx + font1_xoffset < text_startx + text_font_xoffset)
6722 correct_font_draw_xoffset = TRUE;
6724 if (xpos == menu_screen_value_xpos &&
6725 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6726 correct_font_draw_xoffset = TRUE;
6728 // check if setup value would overlap with setup text when printed
6729 // (this can happen for extreme/wrong values for font draw offset)
6730 if (correct_font_draw_xoffset)
6732 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6733 font_draw_xoffset_modified = TRUE;
6735 if (type & TYPE_KEY)
6736 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6737 else if (!(type & TYPE_STRING))
6738 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6739 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6743 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6744 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6746 DrawText(startx, starty, value_string, font_nr);
6748 if (type & TYPE_PLAYER)
6750 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
6751 int player_nr = *(int *)value;
6752 int xoff = font->draw_xoffset + getFontWidth(font_nr);
6753 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
6754 int startx2 = startx + xoff;
6755 int starty2 = starty + yoff;
6757 if (DrawingOnBackground(startx2, starty2))
6758 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
6760 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
6761 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6764 if (font_draw_xoffset_modified)
6765 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6768 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6770 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6771 struct TokenInfo *si = &setup_info[si_pos];
6773 if (si->type & TYPE_BOOLEAN_STYLE)
6775 *(boolean *)si->value ^= TRUE;
6777 else if (si->type & TYPE_YES_NO_AUTO)
6781 (*(int *)si->value == AUTO ? TRUE :
6782 *(int *)si->value == TRUE ? FALSE : AUTO) :
6783 (*(int *)si->value == TRUE ? AUTO :
6784 *(int *)si->value == AUTO ? FALSE : TRUE));
6786 else if (si->type & TYPE_KEY)
6790 si->type |= TYPE_QUERY;
6791 drawSetupValue(screen_pos, setup_info_pos_raw);
6792 si->type &= ~TYPE_QUERY;
6794 key = getSetupKey();
6795 if (key != KSYM_UNDEFINED)
6796 *(Key *)si->value = key;
6798 else if (si->type & TYPE_PLAYER)
6800 int player_nr = *(int *)si->value;
6805 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6807 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6810 drawSetupValue(screen_pos, setup_info_pos_raw);
6812 // fullscreen state may have changed at this point
6813 if (si->value == &setup.fullscreen)
6814 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6816 // network mode may have changed at this point
6817 if (si->value == &setup.network_mode)
6818 ToggleNetworkModeIfNeeded();
6820 // game speed list may have changed at this point
6821 if (si->value == &setup.game_speed_extended)
6822 ToggleGameSpeedsListIfNeeded();
6825 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6827 static struct TokenInfo *setup_info_final = NULL;
6832 // determine maximum list size of target list
6833 while (setup_info_orig[list_size++].type != 0);
6835 // free, allocate and clear memory for target list
6836 checked_free(setup_info_final);
6837 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6839 // copy setup info list without setup entries marked as hidden
6840 for (i = 0; setup_info_orig[i].type != 0; i++)
6842 // skip setup entries configured to be hidden
6843 if (hideSetupEntry(setup_info_orig[i].value))
6846 // skip skippable setup entries if screen is lower than usual
6847 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6848 setup_info_orig[i].type == TYPE_SKIPPABLE)
6851 setup_info_final[list_pos++] = setup_info_orig[i];
6854 return setup_info_final;
6857 static void DrawSetupScreen_Generic(void)
6859 int fade_mask = REDRAW_FIELD;
6860 boolean redraw_all = FALSE;
6861 char *title_string = NULL;
6865 fade_mask = REDRAW_ALL;
6868 FadeMenuSoundsAndMusic();
6870 FreeScreenGadgets();
6871 CreateScreenGadgets();
6873 if (redraw_mask & REDRAW_ALL)
6878 // needed if different viewport properties defined for setup screen
6879 ChangeViewportPropertiesIfNeeded();
6881 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6885 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6887 if (setup_mode == SETUP_MODE_MAIN)
6889 setup_info = setup_info_main;
6890 title_string = STR_SETUP_MAIN;
6892 else if (setup_mode == SETUP_MODE_GAME)
6894 setup_info = setup_info_game;
6895 title_string = STR_SETUP_GAME;
6897 else if (setup_mode == SETUP_MODE_EDITOR)
6899 setup_info = setup_info_editor;
6900 title_string = STR_SETUP_EDITOR;
6902 else if (setup_mode == SETUP_MODE_GRAPHICS)
6904 setup_info = setup_info_graphics;
6905 title_string = STR_SETUP_GRAPHICS;
6907 else if (setup_mode == SETUP_MODE_SOUND)
6909 setup_info = setup_info_sound;
6910 title_string = STR_SETUP_SOUND;
6912 else if (setup_mode == SETUP_MODE_ARTWORK)
6914 setup_info = setup_info_artwork;
6915 title_string = STR_SETUP_ARTWORK;
6917 else if (setup_mode == SETUP_MODE_TOUCH)
6919 setup_info = setup_info_touch;
6920 title_string = STR_SETUP_TOUCH;
6922 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6923 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6924 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6925 setup_info = setup_info_touch_wipe_gestures;
6927 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6929 setup_info = setup_info_shortcuts;
6930 title_string = STR_SETUP_SHORTCUTS;
6932 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6934 setup_info = setup_info_shortcuts_1;
6935 title_string = STR_SETUP_SHORTCUTS;
6937 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6939 setup_info = setup_info_shortcuts_2;
6940 title_string = STR_SETUP_SHORTCUTS;
6942 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6944 setup_info = setup_info_shortcuts_3;
6945 title_string = STR_SETUP_SHORTCUTS;
6947 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6949 setup_info = setup_info_shortcuts_4;
6950 title_string = STR_SETUP_SHORTCUTS;
6952 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6954 setup_info = setup_info_shortcuts_5;
6955 title_string = STR_SETUP_SHORTCUTS;
6958 // use modified setup info without setup entries marked as hidden
6959 setup_info = getSetupInfoFinal(setup_info);
6961 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6963 // determine maximal number of setup entries that can be displayed on screen
6965 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6968 // determine maximal number of setup entries available for this setup screen
6970 for (i = 0; setup_info[i].type != 0; i++)
6973 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6975 MapScreenGadgets(max_setup_info);
6978 redraw_mask = fade_mask = REDRAW_ALL;
6980 DrawMaskedBorder(fade_mask);
6985 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6987 menu_info = setup_info;
6989 HandleMenuScreen(mx, my, dx, dy, button,
6990 setup_mode, num_setup_info, max_setup_info);
6993 static void DrawSetupScreen_Input(void)
6997 FadeOut(REDRAW_FIELD);
7001 setup_info = getSetupInfoFinal(setup_info_input);
7003 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7005 for (i = 0; setup_info[i].type != 0; i++)
7007 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7008 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7009 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7010 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7011 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7012 initCursor(i, IMG_MENU_BUTTON);
7014 DrawCursorAndText_Setup(i, -1, FALSE);
7017 // create gadgets for setup input menu screen
7018 FreeScreenGadgets();
7019 CreateScreenGadgets();
7021 // map gadgets for setup input menu screen
7022 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7024 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7026 FadeIn(REDRAW_FIELD);
7029 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7031 if (device_name == NULL)
7034 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7037 if (strlen(device_name) > 1)
7039 char c1 = device_name[strlen(device_name) - 1];
7040 char c2 = device_name[strlen(device_name) - 2];
7042 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7043 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7046 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7047 strlen(device_name));
7050 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7053 static struct SetupKeyboardInfo custom_key;
7060 { &custom_key.left, "Axis/Pad Left" },
7061 { &custom_key.right, "Axis/Pad Right" },
7062 { &custom_key.up, "Axis/Pad Up" },
7063 { &custom_key.down, "Axis/Pad Down" },
7064 { &custom_key.snap, "Button 1/A/X" },
7065 { &custom_key.drop, "Button 2/B/Y" }
7067 static char *joystick_name[MAX_PLAYERS] =
7074 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7075 int font_nr_info = FONT_MENU_1;
7076 int font_nr_name = FONT_VALUE_OLD;
7077 int font_nr_on = FONT_VALUE_1;
7078 int font_nr_off = FONT_VALUE_OLD;
7081 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7083 font_nr_info = FONT_MENU_2;
7084 font_nr_on = FONT_VALUE_NARROW;
7085 font_nr_off = FONT_VALUE_OLD_NARROW;
7088 custom_key = setup.input[player_nr].key;
7090 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7091 FONT_INPUT_1_ACTIVE);
7093 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7095 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7096 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7098 if (setup.input[player_nr].use_joystick)
7100 char *device_name = setup.input[player_nr].joy.device_name;
7101 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7102 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7103 char *text = joystick_name[joystick_nr];
7104 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7106 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7107 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7111 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7112 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7115 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7116 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7120 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7121 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7122 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7123 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7125 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7126 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7127 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7128 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7129 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7130 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7132 for (i = 0; i < 6; i++)
7134 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7136 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7138 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7139 (setup.input[player_nr].use_joystick ?
7141 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7145 static int input_player_nr = 0;
7147 static void HandleSetupScreen_Input_Player(int step, int direction)
7149 int old_player_nr = input_player_nr;
7152 new_player_nr = old_player_nr + step * direction;
7153 if (new_player_nr < 0)
7155 if (new_player_nr > MAX_PLAYERS - 1)
7156 new_player_nr = MAX_PLAYERS - 1;
7158 if (new_player_nr != old_player_nr)
7160 input_player_nr = new_player_nr;
7162 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7166 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7168 static int choice = 0;
7171 int pos_start = SETUPINPUT_SCREEN_POS_START;
7172 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7173 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7174 int pos_end = SETUPINPUT_SCREEN_POS_END;
7176 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7180 for (i = 0; setup_info_input[i].type != 0; i++)
7182 // adjust menu structure according to skipped setup entries
7183 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7191 if (button == MB_MENU_INITIALIZE)
7193 // input setup menu may have changed size due to graphics configuration
7194 if (choice >= pos_empty1)
7197 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7199 DrawCursorAndText_Setup(choice, -1, TRUE);
7203 else if (button == MB_MENU_LEAVE)
7205 setup_mode = SETUP_MODE_MAIN;
7212 if (mx || my) // mouse input
7214 x = (mx - mSX) / 32;
7215 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7217 else if (dx || dy) // keyboard input
7219 if (dx && choice == 0)
7220 x = (dx < 0 ? 10 : 12);
7221 else if ((dx && choice == 1) ||
7222 (dx == -1 && choice == pos_end))
7223 button = MB_MENU_CHOICE;
7227 if (y >= pos_empty1 && y <= pos_empty2)
7228 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7231 if (y == 0 && dx != 0 && button)
7233 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7235 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7236 y >= pos_start && y <= pos_end &&
7237 !(y >= pos_empty1 && y <= pos_empty2))
7243 DrawCursorAndText_Setup(choice, -1, FALSE);
7244 DrawCursorAndText_Setup(y, -1, TRUE);
7246 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7255 char *device_name = setup.input[input_player_nr].joy.device_name;
7257 if (!setup.input[input_player_nr].use_joystick)
7259 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7261 setJoystickDeviceToNr(device_name, new_device_nr);
7262 setup.input[input_player_nr].use_joystick = TRUE;
7266 int device_nr = getJoystickNrFromDeviceName(device_name);
7267 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7269 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7270 setup.input[input_player_nr].use_joystick = FALSE;
7272 setJoystickDeviceToNr(device_name, new_device_nr);
7275 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7279 if (setup.input[input_player_nr].use_joystick)
7280 ConfigureJoystick(input_player_nr);
7282 CustomizeKeyboard(input_player_nr);
7284 else if (y == pos_end)
7290 setup_mode = SETUP_MODE_MAIN;
7297 static boolean CustomizeKeyboardMain(int player_nr)
7301 boolean finished = FALSE;
7302 static struct SetupKeyboardInfo custom_key;
7307 } customize_step[] =
7309 { &custom_key.left, "Move Left" },
7310 { &custom_key.right, "Move Right" },
7311 { &custom_key.up, "Move Up" },
7312 { &custom_key.down, "Move Down" },
7313 { &custom_key.snap, "Snap Field" },
7314 { &custom_key.drop, "Drop Element" }
7316 int font_nr_old = FONT_VALUE_OLD;
7317 int font_nr_new = FONT_VALUE_1;
7318 boolean success = FALSE;
7320 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7322 font_nr_old = FONT_VALUE_OLD_NARROW;
7323 font_nr_new = FONT_VALUE_NARROW;
7326 // read existing key bindings from player setup
7327 custom_key = setup.input[player_nr].key;
7330 FadeOut(REDRAW_FIELD);
7334 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7337 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7338 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7339 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7340 "Key:", FONT_INPUT_1_ACTIVE);
7341 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7342 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7344 FadeIn(REDRAW_FIELD);
7350 if (NextValidEvent(&event))
7354 case EVENT_KEYPRESS:
7356 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7358 // press 'Escape' to abort and keep the old key bindings
7359 if (key == KSYM_Escape)
7361 FadeSkipNextFadeIn();
7368 // press 'Enter' to keep the existing key binding
7369 if (key == KSYM_Return)
7370 key = *customize_step[step_nr].key;
7372 // check if key already used
7373 for (i = 0; i < step_nr; i++)
7374 if (*customize_step[i].key == key)
7379 // got new key binding
7380 *customize_step[step_nr].key = key;
7381 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7383 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7384 getKeyNameFromKey(key), font_nr_new);
7387 // un-highlight last query
7388 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7389 customize_step[step_nr - 1].text, FONT_MENU_1);
7390 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7391 "Key:", FONT_MENU_1);
7393 // all keys configured
7402 // query next key binding
7403 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7404 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7405 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7406 "Key:", FONT_INPUT_1_ACTIVE);
7407 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7408 getKeyNameFromKey(*customize_step[step_nr].key),
7413 case EVENT_KEYRELEASE:
7414 key_joystick_mapping = 0;
7418 HandleOtherEvents(&event);
7426 // write new key bindings back to player setup, if successfully finished
7428 setup.input[player_nr].key = custom_key;
7433 void CustomizeKeyboard(int player_nr)
7435 boolean success = CustomizeKeyboardMain(player_nr);
7439 int font_nr = FONT_TITLE_1;
7440 int font_height = getFontHeight(font_nr);
7441 int ypos1 = SYSIZE / 2 - font_height * 2;
7442 int ypos2 = SYSIZE / 2 - font_height * 1;
7443 unsigned int wait_frame_delay = 0;
7444 unsigned int wait_frame_delay_value = 2000;
7446 ResetDelayCounter(&wait_frame_delay);
7450 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7451 DrawTextSCentered(ypos2, font_nr, "configured!");
7453 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7459 DrawSetupScreen_Input();
7462 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
7464 #define MARKER_BUTTON 1
7465 #define MARKER_AXIS_X 2
7466 #define MARKER_AXIS_Y 3
7468 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7470 static boolean bitmaps_initialized = FALSE;
7471 boolean screen_initialized = FALSE;
7472 static Bitmap *controller, *button, *axis_x, *axis_y;
7474 boolean success = TRUE;
7475 boolean done = FALSE, next = FALSE;
7477 int alpha = 200, alpha_step = -1;
7478 int alpha_ticks = 0;
7479 char mapping[4096], temp[4096];
7480 int font_name = MENU_SETUP_FONT_TITLE;
7481 int font_info = MENU_SETUP_FONT_TEXT;
7482 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7483 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7484 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7485 int ystep_name = getMenuTextStep(spacing_name, font_name);
7486 int ystep_line = getMenuTextStep(spacing_line, font_info);
7487 int ystep_para = getMenuTextStep(spacing_para, font_info);
7495 int axis, button, hat, hat_value;
7498 *step, *prev_step, steps[] =
7500 { 356, 155, MARKER_BUTTON, "a", },
7501 { 396, 122, MARKER_BUTTON, "b", },
7502 { 320, 125, MARKER_BUTTON, "x", },
7503 { 358, 95, MARKER_BUTTON, "y", },
7504 { 162, 125, MARKER_BUTTON, "back", },
7505 { 216, 125, MARKER_BUTTON, "guide", },
7506 { 271, 125, MARKER_BUTTON, "start", },
7507 { 110, 200, MARKER_BUTTON, "dpleft", },
7508 { 146, 228, MARKER_BUTTON, "dpdown", },
7509 { 178, 200, MARKER_BUTTON, "dpright", },
7510 { 146, 172, MARKER_BUTTON, "dpup", },
7511 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7512 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7513 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7514 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7515 { 73, 141, MARKER_BUTTON, "leftstick", },
7516 { 282, 210, MARKER_BUTTON, "rightstick", },
7517 { 73, 141, MARKER_AXIS_X, "leftx", },
7518 { 73, 141, MARKER_AXIS_Y, "lefty", },
7519 { 282, 210, MARKER_AXIS_X, "rightx", },
7520 { 282, 210, MARKER_AXIS_Y, "righty", },
7523 unsigned int event_frame_delay = 0;
7524 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7526 ResetDelayCounter(&event_frame_delay);
7528 if (!bitmaps_initialized)
7530 controller = LoadCustomImage("joystick/controller.png");
7531 button = LoadCustomImage("joystick/button.png");
7532 axis_x = LoadCustomImage("joystick/axis_x.png");
7533 axis_y = LoadCustomImage("joystick/axis_y.png");
7535 bitmaps_initialized = TRUE;
7538 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7541 // print info about the joystick we are watching
7542 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7543 SDL_JoystickInstanceID(joystick), name);
7544 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7545 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7546 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7549 // initialize mapping with GUID and name
7550 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7552 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7553 temp, name, SDL_GetPlatform());
7555 // loop through all steps (buttons and axes), getting joystick events
7556 for (i = 0; i < SDL_arraysize(steps) && !done;)
7558 Bitmap *marker = button; // initialize with reliable default value
7561 strcpy(step->mapping, mapping);
7565 step->hat_value = -1;
7567 marker = (step->marker == MARKER_BUTTON ? button :
7568 step->marker == MARKER_AXIS_X ? axis_x :
7569 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7573 while (!done && !next)
7575 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7576 alpha_ticks = SDL_GetTicks();
7583 else if (alpha < 128)
7589 int controller_x = SX + (SXSIZE - controller->width) / 2;
7590 int controller_y = SY + ystep_line;
7592 int marker_x = controller_x + step->x;
7593 int marker_y = controller_y + step->y;
7595 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7596 int ystart2 = ystart1 + ystep_name + ystep_line;
7600 DrawTextSCentered(ystart1, font_name, name);
7602 DrawTextSCentered(ystart2, font_info,
7603 "Press buttons and move axes on");
7604 ystart2 += ystep_line;
7605 DrawTextSCentered(ystart2, font_info,
7606 "your controller when indicated.");
7607 ystart2 += ystep_line;
7608 DrawTextSCentered(ystart2, font_info,
7609 "(Your controller may look different.)");
7610 ystart2 += ystep_para;
7612 #if defined(PLATFORM_ANDROID)
7613 DrawTextSCentered(ystart2, font_info,
7614 "To correct a mistake,");
7615 ystart2 += ystep_line;
7616 DrawTextSCentered(ystart2, font_info,
7617 "press the 'back' button.");
7618 ystart2 += ystep_line;
7619 DrawTextSCentered(ystart2, font_info,
7620 "To skip a button or axis,");
7621 ystart2 += ystep_line;
7622 DrawTextSCentered(ystart2, font_info,
7623 "press the 'menu' button.");
7625 DrawTextSCentered(ystart2, font_info,
7626 "To correct a mistake,");
7627 ystart2 += ystep_line;
7628 DrawTextSCentered(ystart2, font_info,
7629 "press the 'backspace' key.");
7630 ystart2 += ystep_line;
7631 DrawTextSCentered(ystart2, font_info,
7632 "To skip a button or axis,");
7633 ystart2 += ystep_line;
7634 DrawTextSCentered(ystart2, font_info,
7635 "press the 'return' key.");
7636 ystart2 += ystep_line;
7637 DrawTextSCentered(ystart2, font_info,
7638 "To exit, press the 'escape' key.");
7641 BlitBitmapMasked(controller, drawto, 0, 0,
7642 controller->width, controller->height,
7643 controller_x, controller_y);
7645 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7646 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7648 BlitBitmapMasked(marker, drawto, 0, 0,
7649 marker->width, marker->height,
7650 marker_x, marker_y);
7652 if (!screen_initialized)
7653 FadeIn(REDRAW_FIELD);
7657 screen_initialized = TRUE;
7659 while (NextValidEvent(&event))
7663 case SDL_JOYAXISMOTION:
7664 if (event.jaxis.value > 20000 ||
7665 event.jaxis.value < -20000)
7667 for (j = 0; j < i; j++)
7668 if (steps[j].axis == event.jaxis.axis)
7673 if (step->marker != MARKER_AXIS_X &&
7674 step->marker != MARKER_AXIS_Y)
7677 step->axis = event.jaxis.axis;
7678 strcat(mapping, step->field);
7679 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7680 strcat(mapping, temp);
7688 case SDL_JOYHATMOTION:
7689 // ignore centering; we're probably just coming back
7690 // to the center from the previous item we set
7691 if (event.jhat.value == SDL_HAT_CENTERED)
7694 for (j = 0; j < i; j++)
7695 if (steps[j].hat == event.jhat.hat &&
7696 steps[j].hat_value == event.jhat.value)
7701 step->hat = event.jhat.hat;
7702 step->hat_value = event.jhat.value;
7703 strcat(mapping, step->field);
7704 snprintf(temp, sizeof(temp), ":h%u.%u,",
7705 event.jhat.hat, event.jhat.value );
7706 strcat(mapping, temp);
7713 case SDL_JOYBALLMOTION:
7716 case SDL_JOYBUTTONUP:
7717 for (j = 0; j < i; j++)
7718 if (steps[j].button == event.jbutton.button)
7723 step->button = event.jbutton.button;
7724 strcat(mapping, step->field);
7725 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7726 strcat(mapping, temp);
7733 case SDL_FINGERDOWN:
7734 case SDL_MOUSEBUTTONDOWN:
7742 if (event.key.keysym.sym == KSYM_BackSpace ||
7743 event.key.keysym.sym == KSYM_Back)
7755 prev_step = &steps[i - 1];
7756 strcpy(mapping, prev_step->mapping);
7763 if (event.key.keysym.sym == KSYM_space ||
7764 event.key.keysym.sym == KSYM_Return ||
7765 event.key.keysym.sym == KSYM_Menu)
7774 if (event.key.keysym.sym == KSYM_Escape)
7784 program.exit_function(0);
7791 // do not handle events for longer than standard frame delay period
7792 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7801 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7804 // activate mapping for this game
7805 SDL_GameControllerAddMapping(mapping);
7807 // save mapping to personal mappings
7808 SaveSetup_AddGameControllerMapping(mapping);
7811 // wait until the last pending event was removed from event queue
7812 while (NextValidEvent(&event));
7817 static int ConfigureJoystickMain(int player_nr)
7819 char *device_name = setup.input[player_nr].joy.device_name;
7820 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7821 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7822 int success = FALSE;
7825 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7826 return JOYSTICK_NOT_AVAILABLE;
7828 if (!joystick_active || !setup.input[player_nr].use_joystick)
7829 return JOYSTICK_NOT_AVAILABLE;
7832 FadeOut(REDRAW_FIELD);
7834 // close all joystick devices (potentially opened as game controllers)
7835 for (i = 0; i < SDL_NumJoysticks(); i++)
7836 SDLCloseJoystick(i);
7838 // open joystick device as plain joystick to configure as game controller
7839 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7841 // as the joystick was successfully opened before, this should not happen
7842 if (joystick == NULL)
7845 // create new game controller mapping (buttons and axes) for joystick device
7846 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7848 // close joystick (and maybe re-open as configured game controller later)
7849 SDL_JoystickClose(joystick);
7851 // re-open all joystick devices (potentially as game controllers)
7852 for (i = 0; i < SDL_NumJoysticks(); i++)
7855 // clear all joystick input actions for all joystick devices
7856 SDLClearJoystickState();
7858 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7861 void ConfigureJoystick(int player_nr)
7863 boolean state = ConfigureJoystickMain(player_nr);
7865 if (state != JOYSTICK_NOT_CONFIGURED)
7867 boolean success = (state == JOYSTICK_CONFIGURED);
7868 char message1[MAX_OUTPUT_LINESIZE + 1];
7869 char *message2 = (success ? "configured!" : "not available!");
7870 char *device_name = setup.input[player_nr].joy.device_name;
7871 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7872 int font_nr = FONT_TITLE_1;
7873 int font_height = getFontHeight(font_nr);
7874 int ypos1 = SYSIZE / 2 - font_height * 2;
7875 int ypos2 = SYSIZE / 2 - font_height * 1;
7876 unsigned int wait_frame_delay = 0;
7877 unsigned int wait_frame_delay_value = 2000;
7879 ResetDelayCounter(&wait_frame_delay);
7883 sprintf(message1, "Joystick %d", nr);
7885 DrawTextSCentered(ypos1, font_nr, message1);
7886 DrawTextSCentered(ypos2, font_nr, message2);
7888 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7894 DrawSetupScreen_Input();
7897 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
7899 if (y < video.screen_height / 3)
7901 // remap touch gadgets to access upper part of the screen
7902 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7903 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
7905 else if (y > 2 * video.screen_height / 3)
7907 // remap touch gadgets to access lower part of the screen
7908 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7909 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
7913 static boolean ConfigureVirtualButtonsMain(void)
7915 static char *customize_step_text[] =
7924 char grid_button[] =
7926 CHAR_GRID_BUTTON_LEFT,
7927 CHAR_GRID_BUTTON_RIGHT,
7928 CHAR_GRID_BUTTON_UP,
7929 CHAR_GRID_BUTTON_DOWN,
7930 CHAR_GRID_BUTTON_SNAP,
7931 CHAR_GRID_BUTTON_DROP
7940 int font_nr = FONT_INPUT_1_ACTIVE;
7941 int font_height = getFontHeight(font_nr);
7942 int ypos1 = SYSIZE / 2 - font_height * 2;
7943 int ypos2 = SYSIZE / 2 - font_height * 1;
7944 boolean success = FALSE;
7945 boolean finished = FALSE;
7947 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7948 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7949 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7950 boolean set_grid_button = FALSE;
7951 int nr = GRID_ACTIVE_NR();
7954 for (x = 0; x < MAX_GRID_XSIZE; x++)
7955 for (y = 0; y < MAX_GRID_YSIZE; y++)
7956 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7958 overlay.grid_button_highlight = grid_button[step_nr];
7961 FadeOut(REDRAW_FIELD);
7965 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7966 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7967 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7969 FadeIn(REDRAW_FIELD);
7971 SetOverlayShowGrid(TRUE);
7973 // map gadgets for setup touch buttons menu screen
7974 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7980 while (NextValidEvent(&event))
7982 int action = ACTION_NONE;
7984 // ---------- handle events and set the resulting action ----------
7990 UserEvent *user = (UserEvent *)&event;
7991 int id = user->value1;
7993 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
7994 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
7995 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
7996 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8001 case EVENT_KEYPRESS:
8003 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8005 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8006 key == KSYM_BackSpace ||
8007 key == KSYM_Back ? ACTION_BACK :
8008 key == KSYM_Return ||
8010 key == KSYM_space ? ACTION_NEXT :
8015 case EVENT_KEYRELEASE:
8016 key_joystick_mapping = 0;
8019 case EVENT_BUTTONPRESS:
8020 case EVENT_BUTTONRELEASE:
8022 ButtonEvent *button = (ButtonEvent *)&event;
8024 motion_status = FALSE;
8026 if (button->type == EVENT_BUTTONPRESS)
8027 button_status = button->button;
8029 button_status = MB_RELEASED;
8031 if (HandleGadgets(button->x, button->y, button_status))
8033 // do not handle this button event anymore
8037 button->x += video.screen_xoffset;
8038 button->y += video.screen_yoffset;
8040 x = button->x * overlay.grid_xsize / video.screen_width;
8041 y = button->y * overlay.grid_ysize / video.screen_height;
8043 if (button->type == EVENT_BUTTONPRESS)
8046 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8047 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8049 set_grid_button = TRUE;
8052 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8056 case EVENT_MOTIONNOTIFY:
8058 MotionEvent *motion = (MotionEvent *)&event;
8060 motion_status = TRUE;
8062 if (HandleGadgets(motion->x, motion->y, button_status))
8064 // do not handle this button event anymore
8068 motion->x += video.screen_xoffset;
8069 motion->y += video.screen_yoffset;
8071 x = motion->x * overlay.grid_xsize / video.screen_width;
8072 y = motion->y * overlay.grid_ysize / video.screen_height;
8074 set_grid_button = TRUE;
8076 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8080 case SDL_WINDOWEVENT:
8081 HandleWindowEvent((WindowEvent *) &event);
8083 // check if device has been rotated
8084 if (nr != GRID_ACTIVE_NR())
8086 nr = GRID_ACTIVE_NR();
8088 for (x = 0; x < MAX_GRID_XSIZE; x++)
8089 for (y = 0; y < MAX_GRID_YSIZE; y++)
8090 grid_button_old[x][y] = grid_button_tmp[x][y] =
8091 overlay.grid_button[x][y];
8096 case SDL_APP_WILLENTERBACKGROUND:
8097 case SDL_APP_DIDENTERBACKGROUND:
8098 case SDL_APP_WILLENTERFOREGROUND:
8099 case SDL_APP_DIDENTERFOREGROUND:
8100 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8104 HandleOtherEvents(&event);
8108 // ---------- perform action set by handling events ----------
8110 if (action == ACTION_ESCAPE)
8112 // abort and restore the old key bindings
8114 for (x = 0; x < MAX_GRID_XSIZE; x++)
8115 for (y = 0; y < MAX_GRID_YSIZE; y++)
8116 overlay.grid_button[x][y] = grid_button_old[x][y];
8118 FadeSkipNextFadeIn();
8122 else if (action == ACTION_BACK)
8124 // keep the configured key bindings and go to previous page
8130 FadeSkipNextFadeIn();
8135 else if (action == ACTION_NEXT)
8137 // keep the configured key bindings and go to next page
8141 // all virtual buttons configured
8149 if (action != ACTION_NONE && !finished)
8151 for (x = 0; x < MAX_GRID_XSIZE; x++)
8152 for (y = 0; y < MAX_GRID_YSIZE; y++)
8153 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8155 overlay.grid_button_highlight = grid_button[step_nr];
8157 // configure next virtual button
8161 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8162 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8163 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8166 if (set_grid_button)
8168 overlay.grid_button[x][y] =
8169 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8170 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8171 grid_button_tmp[x][y]);
8173 set_grid_button = FALSE;
8180 for (x = 0; x < MAX_GRID_XSIZE; x++)
8181 for (y = 0; y < MAX_GRID_YSIZE; y++)
8182 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8184 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8186 SetOverlayShowGrid(FALSE);
8191 void ConfigureVirtualButtons(void)
8193 boolean success = ConfigureVirtualButtonsMain();
8195 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8196 SCREEN_MASK_TOUCH2);
8200 int font_nr = FONT_TITLE_1;
8201 int font_height = getFontHeight(font_nr);
8202 int ypos1 = SYSIZE / 2 - font_height * 2;
8203 int ypos2 = SYSIZE / 2 - font_height * 1;
8204 unsigned int wait_frame_delay = 0;
8205 unsigned int wait_frame_delay_value = 2000;
8207 ResetDelayCounter(&wait_frame_delay);
8211 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8212 DrawTextSCentered(ypos2, font_nr, "configured!");
8214 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8221 void DrawSetupScreen(void)
8226 if (setup_mode == SETUP_MODE_INPUT)
8227 DrawSetupScreen_Input();
8228 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8229 DrawChooseTree(&game_speed_current);
8230 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8231 DrawChooseTree(&scroll_delay_current);
8232 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8233 DrawChooseTree(&snapshot_mode_current);
8234 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8235 DrawChooseTree(&window_size_current);
8236 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8237 DrawChooseTree(&scaling_type_current);
8238 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8239 DrawChooseTree(&rendering_mode_current);
8240 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8241 DrawChooseTree(&vsync_mode_current);
8242 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8243 DrawChooseTree(&artwork.gfx_current);
8244 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8245 DrawChooseTree(&artwork.snd_current);
8246 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8247 DrawChooseTree(&artwork.mus_current);
8248 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8249 DrawChooseTree(&volume_simple_current);
8250 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8251 DrawChooseTree(&volume_loops_current);
8252 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8253 DrawChooseTree(&volume_music_current);
8254 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8255 DrawChooseTree(&touch_control_current);
8256 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8257 DrawChooseTree(&move_distance_current);
8258 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8259 DrawChooseTree(&drop_distance_current);
8260 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8261 DrawChooseTree(&transparency_current);
8262 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8263 DrawChooseTree(&grid_size_current[0][0]);
8264 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8265 DrawChooseTree(&grid_size_current[0][1]);
8266 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8267 DrawChooseTree(&grid_size_current[1][0]);
8268 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8269 DrawChooseTree(&grid_size_current[1][1]);
8271 DrawSetupScreen_Generic();
8273 PlayMenuSoundsAndMusic();
8276 void RedrawSetupScreenAfterFullscreenToggle(void)
8278 if (setup_mode == SETUP_MODE_GRAPHICS ||
8279 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8281 // update list selection from "setup.window_scaling_percent"
8282 execSetupGraphics_setWindowSizes(TRUE);
8288 void RedrawSetupScreenAfterScreenRotation(int nr)
8292 if (setup_mode == SETUP_MODE_TOUCH)
8294 // update virtual button settings (depending on screen orientation)
8297 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8299 // save already configured virtual buttons
8300 for (x = 0; x < MAX_GRID_XSIZE; x++)
8301 for (y = 0; y < MAX_GRID_YSIZE; y++)
8302 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8306 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8308 if (setup_mode == SETUP_MODE_INPUT)
8309 HandleSetupScreen_Input(mx, my, dx, dy, button);
8310 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8311 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8312 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8313 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8314 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8315 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8316 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8317 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8318 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8319 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8320 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8321 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8322 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8323 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8324 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8325 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8326 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8327 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8328 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8329 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8330 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8331 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8332 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8333 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8334 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8335 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8336 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8337 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8338 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8339 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8340 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8341 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8342 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8343 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8344 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8345 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8346 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8347 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8348 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8349 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8350 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8351 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8353 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8356 void HandleGameActions(void)
8358 if (setup.ask_on_game_over)
8361 if (game.restart_game_message != NULL)
8363 RequestRestartGame(game.restart_game_message);
8368 if (game_status != GAME_MODE_PLAYING)
8371 GameActions(); // main game loop
8373 if (tape.auto_play && !tape.playing)
8374 AutoPlayTape(); // continue automatically playing next tape
8378 // ---------- new screen button stuff --------------------------------------
8382 int gfx_unpressed, gfx_pressed;
8383 struct MenuPosInfo *pos;
8384 boolean *check_value;
8387 unsigned int event_mask;
8388 boolean is_touch_button;
8390 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8393 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8394 &menu.main.button.prev_level, NULL,
8395 SCREEN_CTRL_ID_PREV_LEVEL,
8397 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8398 FALSE, "previous level"
8401 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8402 &menu.main.button.next_level, NULL,
8403 SCREEN_CTRL_ID_NEXT_LEVEL,
8405 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8409 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
8410 &menu.main.button.first_level, NULL,
8411 SCREEN_CTRL_ID_FIRST_LEVEL,
8414 FALSE, "first level"
8417 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
8418 &menu.main.button.last_level, NULL,
8419 SCREEN_CTRL_ID_LAST_LEVEL,
8425 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
8426 &menu.main.button.level_number, NULL,
8427 SCREEN_CTRL_ID_LEVEL_NUMBER,
8430 FALSE, "level number"
8433 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8434 &menu.setup.button.prev_player, NULL,
8435 SCREEN_CTRL_ID_PREV_PLAYER,
8437 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8438 FALSE, "previous player"
8441 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8442 &menu.setup.button.next_player, NULL,
8443 SCREEN_CTRL_ID_NEXT_PLAYER,
8445 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8446 FALSE, "next player"
8449 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8450 &menu.main.button.insert_solution, NULL,
8451 SCREEN_CTRL_ID_INSERT_SOLUTION,
8452 SCREEN_MASK_MAIN_HAS_SOLUTION,
8454 FALSE, "insert solution tape"
8457 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8458 &menu.main.button.play_solution, NULL,
8459 SCREEN_CTRL_ID_PLAY_SOLUTION,
8460 SCREEN_MASK_MAIN_HAS_SOLUTION,
8462 FALSE, "play solution tape"
8465 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
8466 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
8467 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
8469 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
8470 FALSE, "switch ECS/AGA chipset"
8473 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
8474 &menu.setup.button.touch_back, NULL,
8475 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
8478 TRUE, "previous page"
8481 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
8482 &menu.setup.button.touch_next, NULL,
8483 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
8489 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
8490 &menu.setup.button.touch_back2, NULL,
8491 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
8494 TRUE, "previous page"
8497 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
8498 &menu.setup.button.touch_next2, NULL,
8499 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
8508 int gfx_unpressed, gfx_pressed;
8512 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8515 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8516 -1, -1, // these values are not constant, but can change at runtime
8517 SCREEN_CTRL_ID_SCROLL_UP,
8521 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8522 -1, -1, // these values are not constant, but can change at runtime
8523 SCREEN_CTRL_ID_SCROLL_DOWN,
8530 int gfx_unpressed, gfx_pressed;
8536 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8539 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8540 -1, -1, // these values are not constant, but can change at runtime
8541 -1, -1, // these values are not constant, but can change at runtime
8542 GD_TYPE_SCROLLBAR_VERTICAL,
8543 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8544 "scroll level series vertically"
8556 } textinput_info[NUM_SCREEN_TEXTINPUT] =
8559 IMG_SETUP_INPUT_TEXT,
8560 SCREEN_CTRL_ID_NETWORK_SERVER,
8561 -1, -1, // these values are not constant, but can change at runtime
8562 MAX_SETUP_TEXT_INPUT_LEN,
8563 network_server_hostname,
8564 "Network Server Hostname / IP"
8568 static void CreateScreenMenubuttons(void)
8570 struct GadgetInfo *gi;
8571 unsigned int event_mask;
8574 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8576 struct MenuPosInfo *pos = menubutton_info[i].pos;
8577 boolean is_touch_button = menubutton_info[i].is_touch_button;
8578 boolean is_check_button = menubutton_info[i].check_value != NULL;
8579 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8580 int gfx_unpressed, gfx_pressed;
8581 int x, y, width, height;
8582 int gd_x1, gd_x2, gd_y1, gd_y2;
8583 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
8584 int id = menubutton_info[i].gadget_id;
8585 int type = GD_TYPE_NORMAL_BUTTON;
8586 boolean checked = FALSE;
8588 event_mask = menubutton_info[i].event_mask;
8590 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
8591 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
8593 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8594 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8596 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8597 gfx_pressed = menubutton_info[i].gfx_pressed;
8598 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8599 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8600 gd_x1 = graphic_info[gfx_unpressed].src_x;
8601 gd_y1 = graphic_info[gfx_unpressed].src_y;
8602 gd_x2 = graphic_info[gfx_pressed].src_x;
8603 gd_y2 = graphic_info[gfx_pressed].src_y;
8609 if (is_touch_button)
8611 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
8612 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
8615 if (is_check_button)
8617 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
8618 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
8619 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
8620 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
8622 type = GD_TYPE_CHECK_BUTTON;
8623 checked = *menubutton_info[i].check_value;
8626 gi = CreateGadget(GDI_CUSTOM_ID, id,
8627 GDI_CUSTOM_TYPE_ID, i,
8628 GDI_IMAGE_ID, gfx_unpressed,
8629 GDI_INFO_TEXT, menubutton_info[i].infotext,
8635 GDI_STATE, GD_BUTTON_UNPRESSED,
8636 GDI_CHECKED, checked,
8637 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8638 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8639 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
8640 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
8641 GDI_DIRECT_DRAW, FALSE,
8642 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
8643 GDI_EVENT_MASK, event_mask,
8644 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8648 Error(ERR_EXIT, "cannot create gadget");
8650 screen_gadget[id] = gi;
8654 static void CreateScreenScrollbuttons(void)
8656 struct GadgetInfo *gi;
8657 unsigned int event_mask;
8660 // these values are not constant, but can change at runtime
8661 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8662 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8663 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8664 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8666 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8668 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8669 int gfx_unpressed, gfx_pressed;
8670 int x, y, width, height;
8671 int gd_x1, gd_x2, gd_y1, gd_y2;
8672 int id = scrollbutton_info[i].gadget_id;
8674 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8676 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8677 y = mSY + scrollbutton_info[i].y;
8678 width = SC_SCROLLBUTTON_XSIZE;
8679 height = SC_SCROLLBUTTON_YSIZE;
8681 // correct scrollbar position if placed outside menu (playfield) area
8682 if (x > SX + SC_SCROLL_UP_XPOS)
8683 x = SX + SC_SCROLL_UP_XPOS;
8685 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8686 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8687 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8689 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8690 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8691 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8692 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8693 gd_x1 = graphic_info[gfx_unpressed].src_x;
8694 gd_y1 = graphic_info[gfx_unpressed].src_y;
8695 gd_x2 = graphic_info[gfx_pressed].src_x;
8696 gd_y2 = graphic_info[gfx_pressed].src_y;
8698 gi = CreateGadget(GDI_CUSTOM_ID, id,
8699 GDI_CUSTOM_TYPE_ID, i,
8700 GDI_IMAGE_ID, gfx_unpressed,
8701 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8706 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8707 GDI_STATE, GD_BUTTON_UNPRESSED,
8708 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8709 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8710 GDI_DIRECT_DRAW, FALSE,
8711 GDI_EVENT_MASK, event_mask,
8712 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8716 Error(ERR_EXIT, "cannot create gadget");
8718 screen_gadget[id] = gi;
8722 static void CreateScreenScrollbars(void)
8726 // these values are not constant, but can change at runtime
8727 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8728 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8729 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8730 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8732 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8734 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8735 int gfx_unpressed, gfx_pressed;
8736 int x, y, width, height;
8737 int gd_x1, gd_x2, gd_y1, gd_y2;
8738 struct GadgetInfo *gi;
8739 int items_max, items_visible, item_position;
8740 unsigned int event_mask;
8741 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8742 int id = scrollbar_info[i].gadget_id;
8744 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8746 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8747 y = mSY + scrollbar_info[i].y;
8748 width = scrollbar_info[i].width;
8749 height = scrollbar_info[i].height;
8751 // correct scrollbar position if placed outside menu (playfield) area
8752 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8753 x = SX + SC_SCROLL_VERTICAL_XPOS;
8755 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8756 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8758 items_max = num_page_entries;
8759 items_visible = num_page_entries;
8762 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8763 gfx_pressed = scrollbar_info[i].gfx_pressed;
8764 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8765 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8766 gd_x1 = graphic_info[gfx_unpressed].src_x;
8767 gd_y1 = graphic_info[gfx_unpressed].src_y;
8768 gd_x2 = graphic_info[gfx_pressed].src_x;
8769 gd_y2 = graphic_info[gfx_pressed].src_y;
8771 gi = CreateGadget(GDI_CUSTOM_ID, id,
8772 GDI_CUSTOM_TYPE_ID, i,
8773 GDI_IMAGE_ID, gfx_unpressed,
8774 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8779 GDI_TYPE, scrollbar_info[i].type,
8780 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8781 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8782 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8783 GDI_WHEEL_AREA_X, SX,
8784 GDI_WHEEL_AREA_Y, SY,
8785 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8786 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8787 GDI_STATE, GD_BUTTON_UNPRESSED,
8788 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8789 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8790 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8791 GDI_DIRECT_DRAW, FALSE,
8792 GDI_EVENT_MASK, event_mask,
8793 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8797 Error(ERR_EXIT, "cannot create gadget");
8799 screen_gadget[id] = gi;
8803 static void CreateScreenTextInputGadgets(void)
8807 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
8809 int graphic = textinput_info[i].graphic;
8810 struct GraphicInfo *gd = &graphic_info[graphic];
8811 int gd_x1 = gd->src_x;
8812 int gd_y1 = gd->src_y;
8813 int gd_x2 = gd->src_x + gd->active_xoffset;
8814 int gd_y2 = gd->src_y + gd->active_yoffset;
8815 struct GadgetInfo *gi;
8816 unsigned int event_mask;
8817 int id = textinput_info[i].gadget_id;
8818 int x = textinput_info[i].x;
8819 int y = textinput_info[i].y;
8821 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
8823 gi = CreateGadget(GDI_CUSTOM_ID, id,
8824 GDI_CUSTOM_TYPE_ID, i,
8825 GDI_INFO_TEXT, textinput_info[i].infotext,
8828 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
8829 GDI_TEXT_VALUE, textinput_info[i].value,
8830 GDI_TEXT_SIZE, textinput_info[i].size,
8831 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
8832 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
8833 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8834 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8835 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8836 GDI_DESIGN_WIDTH, gd->width,
8837 GDI_EVENT_MASK, event_mask,
8838 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8839 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
8843 Error(ERR_EXIT, "cannot create gadget");
8845 screen_gadget[id] = gi;
8849 void CreateScreenGadgets(void)
8851 CreateScreenMenubuttons();
8853 CreateScreenScrollbuttons();
8854 CreateScreenScrollbars();
8856 CreateScreenTextInputGadgets();
8859 void FreeScreenGadgets(void)
8863 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8864 FreeGadget(screen_gadget[i]);
8867 static void MapScreenMenuGadgets(int screen_mask)
8871 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8872 if (screen_mask & menubutton_info[i].screen_mask)
8873 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8876 static void UnmapScreenMenuGadgets(int screen_mask)
8880 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8882 if (screen_mask & menubutton_info[i].screen_mask)
8884 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8886 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8887 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8888 screen_gadget[menubutton_info[i].gadget_id]->y,
8889 screen_gadget[menubutton_info[i].gadget_id]->width,
8890 screen_gadget[menubutton_info[i].gadget_id]->height);
8895 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8898 MapScreenMenuGadgets(screen_mask);
8900 UnmapScreenMenuGadgets(screen_mask);
8903 static void MapScreenGadgets(int num_entries)
8907 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8910 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8911 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8913 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8914 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8917 static void MapScreenTreeGadgets(TreeInfo *ti)
8919 MapScreenGadgets(numTreeInfoInGroup(ti));
8922 static void HandleScreenGadgets(struct GadgetInfo *gi)
8924 int id = gi->custom_id;
8925 int button = gi->event.button;
8926 int step = (button == MB_LEFTBUTTON ? 1 :
8927 button == MB_MIDDLEBUTTON ? 5 :
8928 button == MB_RIGHTBUTTON ? 10 : 1);
8932 case SCREEN_CTRL_ID_PREV_LEVEL:
8933 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8936 case SCREEN_CTRL_ID_NEXT_LEVEL:
8937 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8940 case SCREEN_CTRL_ID_FIRST_LEVEL:
8941 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
8944 case SCREEN_CTRL_ID_LAST_LEVEL:
8945 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
8948 case SCREEN_CTRL_ID_LEVEL_NUMBER:
8949 CloseDoor(DOOR_CLOSE_2);
8950 SetGameStatus(GAME_MODE_LEVELNR);
8951 DrawChooseLevelNr();
8954 case SCREEN_CTRL_ID_PREV_PLAYER:
8955 HandleSetupScreen_Input_Player(step, -1);
8958 case SCREEN_CTRL_ID_NEXT_PLAYER:
8959 HandleSetupScreen_Input_Player(step, +1);
8962 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8963 InsertSolutionTape();
8966 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8970 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
8971 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
8975 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
8976 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
8977 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
8978 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
8979 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
8982 case SCREEN_CTRL_ID_SCROLL_UP:
8983 if (game_status == GAME_MODE_LEVELS)
8984 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8985 else if (game_status == GAME_MODE_LEVELNR)
8986 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8987 else if (game_status == GAME_MODE_SETUP)
8988 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8989 else if (game_status == GAME_MODE_INFO)
8990 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8993 case SCREEN_CTRL_ID_SCROLL_DOWN:
8994 if (game_status == GAME_MODE_LEVELS)
8995 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8996 else if (game_status == GAME_MODE_LEVELNR)
8997 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8998 else if (game_status == GAME_MODE_SETUP)
8999 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9000 else if (game_status == GAME_MODE_INFO)
9001 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9004 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9005 if (game_status == GAME_MODE_LEVELS)
9006 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9007 else if (game_status == GAME_MODE_LEVELNR)
9008 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9009 else if (game_status == GAME_MODE_SETUP)
9010 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9011 else if (game_status == GAME_MODE_INFO)
9012 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9015 case SCREEN_CTRL_ID_NETWORK_SERVER:
9017 if (!strEqual(gi->textinput.value, ""))
9019 setString(&setup.network_server_hostname, gi->textinput.value);
9021 network.server_host = setup.network_server_hostname;
9025 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9027 network.server_host = NULL;
9030 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9031 network.server_host = NULL;
9033 execSetupGame_setNetworkServerText();
9045 void DumpScreenIdentifiers(void)
9049 Print("Active screen elements on current screen:\n");
9051 for (i = 0; main_controls[i].nr != -1; i++)
9053 struct MainControlInfo *mci = &main_controls[i];
9055 if (mci->button_graphic != -1)
9057 char *token = getTokenFromImageID(mci->button_graphic);
9059 Print("- '%s'\n", token);
9066 boolean DoScreenAction(int image_id)
9070 if (game_status != GAME_MODE_MAIN)
9073 for (i = 0; main_controls[i].nr != -1; i++)
9075 struct MainControlInfo *mci = &main_controls[i];
9076 struct MenuPosInfo *pos = mci->pos_button;
9078 if (mci->button_graphic == image_id)
9080 int x = mSX + pos->x;
9081 int y = mSY + pos->y;
9083 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9092 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9094 // get tree info node of newly added level or artwork set
9095 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9096 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9098 if (tree_node_new == NULL) // should not happen
9101 // if request dialog is active, do nothing
9102 if (game.request_active)
9105 if (game_status == GAME_MODE_MAIN &&
9106 tree_type == TREE_TYPE_LEVEL_DIR)
9108 // when adding new level set in main menu, select it as current level set
9110 // change current level set to newly added level set from zip file
9111 leveldir_current = tree_node_new;
9113 // change current level number to first level of newly added level set
9114 level_nr = leveldir_current->first_level;
9116 // redraw screen to reflect changed level set
9119 // save this level set and level number as last selected level set
9120 SaveLevelSetup_LastSeries();
9121 SaveLevelSetup_SeriesInfo();
9123 else if (game_status == GAME_MODE_LEVELS &&
9124 tree_type == TREE_TYPE_LEVEL_DIR)
9126 // when adding new level set in level set menu, set cursor and update screen
9128 leveldir_current = tree_node_new;
9130 DrawChooseTree(&leveldir_current);
9132 else if (game_status == GAME_MODE_SETUP)
9134 // when adding new artwork set in setup menu, set cursor and update screen
9136 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9137 tree_type == TREE_TYPE_GRAPHICS_DIR)
9139 artwork.gfx_current = tree_node_new;
9141 DrawChooseTree(&artwork.gfx_current);
9143 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9144 tree_type == TREE_TYPE_SOUNDS_DIR)
9146 artwork.snd_current = tree_node_new;
9148 DrawChooseTree(&artwork.snd_current);
9150 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9151 tree_type == TREE_TYPE_MUSIC_DIR)
9153 artwork.mus_current = tree_node_new;
9155 DrawChooseTree(&artwork.mus_current);