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_SCROLL_UP 9
185 #define SCREEN_CTRL_ID_SCROLL_DOWN 10
186 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 11
187 #define SCREEN_CTRL_ID_NETWORK_SERVER 12
189 #define NUM_SCREEN_GADGETS 13
191 #define NUM_SCREEN_MENUBUTTONS 9
192 #define NUM_SCREEN_SCROLLBUTTONS 2
193 #define NUM_SCREEN_SCROLLBARS 1
194 #define NUM_SCREEN_TEXTINPUT 1
196 #define SCREEN_MASK_MAIN (1 << 0)
197 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
198 #define SCREEN_MASK_INPUT (1 << 2)
200 // graphic position and size values for buttons and scrollbars
201 #define SC_MENUBUTTON_XSIZE TILEX
202 #define SC_MENUBUTTON_YSIZE TILEY
204 #define SC_SCROLLBUTTON_XSIZE TILEX
205 #define SC_SCROLLBUTTON_YSIZE TILEY
207 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
209 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
210 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
211 SC_SCROLLBUTTON_YSIZE)
213 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
214 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
216 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
217 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
218 SC_SCROLLBUTTON_YSIZE)
220 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
221 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
222 SC_SCROLL_VERTICAL_YSIZE)
224 #define SC_BORDER_SIZE 14
227 // forward declarations of internal functions
228 static void HandleScreenGadgets(struct GadgetInfo *);
229 static void HandleSetupScreen_Generic(int, int, int, int, int);
230 static void HandleSetupScreen_Input(int, int, int, int, int);
231 static void CustomizeKeyboard(int);
232 static void ConfigureJoystick(int);
233 static void ConfigureVirtualButtons(void);
234 static void execSetupGame(void);
235 static void execSetupGraphics(void);
236 static void execSetupSound(void);
237 static void execSetupTouch(void);
238 static void execSetupArtwork(void);
239 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
241 static void DrawChooseLevelSet(void);
242 static void DrawChooseLevelNr(void);
243 static void DrawInfoScreen(void);
244 static void DrawSetupScreen(void);
246 static void DrawInfoScreen_NotAvailable(char *, char *);
247 static void DrawInfoScreen_HelpAnim(int, int, boolean);
248 static void DrawInfoScreen_HelpText(int, int, int, int);
249 static void HandleInfoScreen_Main(int, int, int, int, int);
250 static void HandleInfoScreen_TitleScreen(int);
251 static void HandleInfoScreen_Elements(int);
252 static void HandleInfoScreen_Music(int);
253 static void HandleInfoScreen_Credits(int);
254 static void HandleInfoScreen_Program(int);
255 static void HandleInfoScreen_Version(int);
257 static void ModifyGameSpeedIfNeeded(void);
258 static void DisableVsyncIfNeeded(void);
260 static void MapScreenMenuGadgets(int);
261 static void MapScreenGadgets(int);
262 static void MapScreenTreeGadgets(TreeInfo *);
264 static void UpdateScreenMenuGadgets(int, boolean);
266 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
268 static int info_mode = INFO_MODE_MAIN;
269 static int setup_mode = SETUP_MODE_MAIN;
271 static TreeInfo *window_sizes = NULL;
272 static TreeInfo *window_size_current = NULL;
274 static TreeInfo *scaling_types = NULL;
275 static TreeInfo *scaling_type_current = NULL;
277 static TreeInfo *rendering_modes = NULL;
278 static TreeInfo *rendering_mode_current = NULL;
280 static TreeInfo *vsync_modes = NULL;
281 static TreeInfo *vsync_mode_current = NULL;
283 static TreeInfo *scroll_delays = NULL;
284 static TreeInfo *scroll_delay_current = NULL;
286 static TreeInfo *snapshot_modes = NULL;
287 static TreeInfo *snapshot_mode_current = NULL;
289 static TreeInfo *game_speeds_normal = NULL;
290 static TreeInfo *game_speeds_extended = NULL;
291 static TreeInfo *game_speeds = NULL;
292 static TreeInfo *game_speed_current = NULL;
294 static TreeInfo *volumes_simple = NULL;
295 static TreeInfo *volume_simple_current = NULL;
297 static TreeInfo *volumes_loops = NULL;
298 static TreeInfo *volume_loops_current = NULL;
300 static TreeInfo *volumes_music = NULL;
301 static TreeInfo *volume_music_current = NULL;
303 static TreeInfo *touch_controls = NULL;
304 static TreeInfo *touch_control_current = NULL;
306 static TreeInfo *move_distances = NULL;
307 static TreeInfo *move_distance_current = NULL;
309 static TreeInfo *drop_distances = NULL;
310 static TreeInfo *drop_distance_current = NULL;
312 static TreeInfo *transparencies = NULL;
313 static TreeInfo *transparency_current = NULL;
315 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
316 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
318 static TreeInfo *level_number = NULL;
319 static TreeInfo *level_number_current = NULL;
321 static struct ValueTextInfo window_sizes_list[] =
326 { 100, "100 % (Default)" },
339 static struct StringValueTextInfo scaling_types_list[] =
341 { SCALING_QUALITY_NEAREST, "Off" },
342 { SCALING_QUALITY_LINEAR, "Linear" },
343 { SCALING_QUALITY_BEST, "Anisotropic" },
348 static struct StringValueTextInfo rendering_modes_list[] =
350 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
351 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
353 // this mode may work under certain conditions, but does not work on Windows
354 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
356 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
361 static struct StringValueTextInfo vsync_modes_list[] =
363 { STR_VSYNC_MODE_OFF, "Off" },
364 { STR_VSYNC_MODE_NORMAL, "Normal" },
365 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
370 static struct ValueTextInfo game_speeds_list_normal[] =
381 static struct ValueTextInfo game_speeds_list_extended[] =
383 { 1000, "1 fps (Extremely Slow)" },
388 { 29, "35 fps (Original Supaplex)" },
390 { 20, "50 fps (=== Normal Speed ===)" },
391 { 16, "60 fps (60 Hz VSync Speed)" },
392 { 14, "70 fps (Maximum Supaplex)" },
396 { 1, "1000 fps (Extremely Fast)" },
401 static struct ValueTextInfo *game_speeds_list;
403 static struct ValueTextInfo scroll_delays_list[] =
405 { 0, "0 Tiles (No Scroll Delay)" },
408 { 3, "3 Tiles (Default)" },
413 { 8, "8 Tiles (Maximum Scroll Delay)"},
418 static struct StringValueTextInfo snapshot_modes_list[] =
420 { STR_SNAPSHOT_MODE_OFF, "Off" },
421 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
422 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
423 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
428 static struct ValueTextInfo volumes_list[] =
448 static struct StringValueTextInfo touch_controls_list[] =
450 { TOUCH_CONTROL_OFF, "Off" },
451 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
452 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
453 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
458 static struct ValueTextInfo distances_list[] =
473 static struct ValueTextInfo transparencies_list[] =
475 { 0, "0 % (Opaque)" },
485 { 100, "100 % (Invisible)" },
490 static struct ValueTextInfo grid_sizes_list[] =
526 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
527 (s) <= GAME_MODE_SETUP ? (s) : \
528 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
529 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
531 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
532 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
533 (i) <= INFO_MODE_LEVELSET ? (i) : \
536 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
537 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
538 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
539 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
540 SETUP_MODE_CHOOSE_ARTWORK : \
541 SETUP_MODE_CHOOSE_OTHER)
543 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
544 menu.draw_xoffset[GAME_MODE_INFO] : \
545 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
546 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
547 menu.draw_yoffset[GAME_MODE_INFO] : \
548 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
549 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
550 menu.extra_spacing[GAME_MODE_INFO] : \
551 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
553 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
554 menu.draw_xoffset[GAME_MODE_SETUP] : \
555 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
556 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
557 menu.draw_yoffset[GAME_MODE_SETUP] : \
558 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
559 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
560 menu.extra_spacing[GAME_MODE_SETUP] : \
561 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
563 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
564 DRAW_XOFFSET_INFO(info_mode) : \
565 (s) == GAME_MODE_SETUP ? \
566 DRAW_XOFFSET_SETUP(setup_mode) : \
567 menu.draw_xoffset[DRAW_MODE(s)])
568 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
569 DRAW_YOFFSET_INFO(info_mode) : \
570 (s) == GAME_MODE_SETUP ? \
571 DRAW_YOFFSET_SETUP(setup_mode) : \
572 menu.draw_yoffset[DRAW_MODE(s)])
573 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
574 EXTRA_SPACING_INFO(info_mode) : \
575 (s) == GAME_MODE_SETUP ? \
576 EXTRA_SPACING_SETUP(setup_mode) : \
577 menu.extra_spacing[DRAW_MODE(s)])
579 #define mSX (SX + DRAW_XOFFSET(game_status))
580 #define mSY (SY + DRAW_YOFFSET(game_status))
582 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
583 menu.list_size[game_status] : \
584 MAX_MENU_ENTRIES_ON_SCREEN)
586 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
587 NUM_MENU_ENTRIES_ON_SCREEN)
590 // title display and control definitions
592 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
593 2 * MAX_NUM_TITLE_MESSAGES)
595 #define NO_DIRECT_LEVEL_SELECT (-1)
598 static int num_title_screens = 0;
600 struct TitleControlInfo
609 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
611 // main menu display and control definitions
613 #define MAIN_CONTROL_NAME 0
614 #define MAIN_CONTROL_LEVELS 1
615 #define MAIN_CONTROL_SCORES 2
616 #define MAIN_CONTROL_EDITOR 3
617 #define MAIN_CONTROL_INFO 4
618 #define MAIN_CONTROL_GAME 5
619 #define MAIN_CONTROL_SETUP 6
620 #define MAIN_CONTROL_QUIT 7
621 #define MAIN_CONTROL_PREV_LEVEL 8
622 #define MAIN_CONTROL_NEXT_LEVEL 9
623 #define MAIN_CONTROL_FIRST_LEVEL 10
624 #define MAIN_CONTROL_LAST_LEVEL 11
625 #define MAIN_CONTROL_LEVEL_NUMBER 12
626 #define MAIN_CONTROL_LEVEL_INFO_1 13
627 #define MAIN_CONTROL_LEVEL_INFO_2 14
628 #define MAIN_CONTROL_LEVEL_NAME 15
629 #define MAIN_CONTROL_LEVEL_AUTHOR 16
630 #define MAIN_CONTROL_LEVEL_YEAR 17
631 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
632 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
633 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
634 #define MAIN_CONTROL_TITLE_1 21
635 #define MAIN_CONTROL_TITLE_2 22
636 #define MAIN_CONTROL_TITLE_3 23
638 static char str_main_text_name[10];
639 static char str_main_text_first_level[10];
640 static char str_main_text_last_level[10];
641 static char str_main_text_level_number[10];
643 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
645 static char *main_text_name = str_main_text_name;
646 static char *main_text_first_level = str_main_text_first_level;
647 static char *main_text_last_level = str_main_text_last_level;
648 static char *main_text_level_number = str_main_text_level_number;
649 static char *main_text_levels = "Levelset";
650 static char *main_text_scores = "Hall Of Fame";
651 static char *main_text_editor = "Level Creator";
652 static char *main_text_info = "Info Screen";
653 static char *main_text_game = "Start Game";
654 static char *main_text_setup = "Setup";
655 static char *main_text_quit = "Quit";
656 static char *main_text_level_name = level.name;
657 static char *main_text_level_author = level.author;
658 static char *main_text_level_year = NULL;
659 static char *main_text_level_imported_from = NULL;
660 static char *main_text_level_imported_by = NULL;
661 static char *main_text_level_tested_by = NULL;
662 static char *main_text_title_1 = NULL;
663 static char *main_text_title_2 = NULL;
664 static char *main_text_title_3 = NULL;
666 struct MainControlInfo
670 struct MenuPosInfo *pos_button;
673 struct TextPosInfo *pos_text;
676 struct TextPosInfo *pos_input;
680 static struct MainControlInfo main_controls[] =
684 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
685 &menu.main.text.name, &main_text_name,
686 &menu.main.input.name, &setup.player_name,
690 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
691 &menu.main.text.levels, &main_text_levels,
696 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
697 &menu.main.text.scores, &main_text_scores,
702 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
703 &menu.main.text.editor, &main_text_editor,
708 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
709 &menu.main.text.info, &main_text_info,
714 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
715 &menu.main.text.game, &main_text_game,
720 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
721 &menu.main.text.setup, &main_text_setup,
726 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
727 &menu.main.text.quit, &main_text_quit,
731 MAIN_CONTROL_PREV_LEVEL,
737 MAIN_CONTROL_NEXT_LEVEL,
743 MAIN_CONTROL_FIRST_LEVEL,
745 &menu.main.text.first_level, &main_text_first_level,
749 MAIN_CONTROL_LAST_LEVEL,
751 &menu.main.text.last_level, &main_text_last_level,
755 MAIN_CONTROL_LEVEL_NUMBER,
757 &menu.main.text.level_number, &main_text_level_number,
761 MAIN_CONTROL_LEVEL_INFO_1,
763 &menu.main.text.level_info_1, NULL,
767 MAIN_CONTROL_LEVEL_INFO_2,
769 &menu.main.text.level_info_2, NULL,
773 MAIN_CONTROL_LEVEL_NAME,
775 &menu.main.text.level_name, &main_text_level_name,
779 MAIN_CONTROL_LEVEL_AUTHOR,
781 &menu.main.text.level_author, &main_text_level_author,
785 MAIN_CONTROL_LEVEL_YEAR,
787 &menu.main.text.level_year, &main_text_level_year,
791 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
793 &menu.main.text.level_imported_from, &main_text_level_imported_from,
797 MAIN_CONTROL_LEVEL_IMPORTED_BY,
799 &menu.main.text.level_imported_by, &main_text_level_imported_by,
803 MAIN_CONTROL_LEVEL_TESTED_BY,
805 &menu.main.text.level_tested_by, &main_text_level_tested_by,
809 MAIN_CONTROL_TITLE_1,
811 &menu.main.text.title_1, &main_text_title_1,
815 MAIN_CONTROL_TITLE_2,
817 &menu.main.text.title_2, &main_text_title_2,
821 MAIN_CONTROL_TITLE_3,
823 &menu.main.text.title_3, &main_text_title_3,
836 static int getTitleScreenGraphic(int nr, boolean initial)
838 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
841 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
843 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
847 static int getTitleScreenGameMode(boolean initial)
849 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
853 static int getTitleMessageGameMode(boolean initial)
855 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
858 static int getTitleAnimMode(struct TitleControlInfo *tci)
860 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
862 return base + tci->local_nr;
866 static int getTitleScreenBackground(boolean initial)
868 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
873 static int getTitleMessageBackground(int nr, boolean initial)
875 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
879 static int getTitleBackground(int nr, boolean initial, boolean is_image)
881 int base = (is_image ?
882 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
883 IMG_BACKGROUND_TITLESCREEN_1) :
884 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
885 IMG_BACKGROUND_TITLEMESSAGE_1));
886 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
887 IMG_BACKGROUND_TITLE);
888 int graphic_local = base + nr;
890 if (graphic_info[graphic_local].bitmap != NULL)
891 return graphic_local;
893 if (graphic_info[graphic_global].bitmap != NULL)
894 return graphic_global;
896 return IMG_UNDEFINED;
899 static int getTitleSound(struct TitleControlInfo *tci)
901 boolean is_image = tci->is_image;
902 int initial = tci->initial;
903 int nr = tci->local_nr;
904 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
905 int base = (is_image ?
906 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
907 SND_BACKGROUND_TITLESCREEN_1) :
908 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
909 SND_BACKGROUND_TITLEMESSAGE_1));
910 int sound_global = menu.sound[mode];
911 int sound_local = base + nr;
914 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
915 nr, initial, is_image,
916 sound_global, getSoundListEntry(sound_global)->filename,
917 sound_local, getSoundListEntry(sound_local)->filename);
920 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
923 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
926 return SND_UNDEFINED;
929 static int getTitleMusic(struct TitleControlInfo *tci)
931 boolean is_image = tci->is_image;
932 int initial = tci->initial;
933 int nr = tci->local_nr;
934 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
935 int base = (is_image ?
936 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
937 MUS_BACKGROUND_TITLESCREEN_1) :
938 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
939 MUS_BACKGROUND_TITLEMESSAGE_1));
940 int music_global = menu.music[mode];
941 int music_local = base + nr;
944 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
945 nr, initial, is_image,
946 music_global, getMusicListEntry(music_global)->filename,
947 music_local, getMusicListEntry(music_local)->filename);
950 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
953 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
956 return MUS_UNDEFINED;
959 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
961 boolean is_image = tci->is_image;
962 boolean initial = tci->initial;
963 boolean first = tci->first;
964 int nr = tci->local_nr;
965 struct TitleMessageInfo tmi;
966 struct TitleFadingInfo ti;
968 tmi = (is_image ? (initial ? (first ?
969 titlescreen_initial_first[nr] :
970 titlescreen_initial[nr])
972 titlescreen_first[nr] :
974 : (initial ? (first ?
975 titlemessage_initial_first[nr] :
976 titlemessage_initial[nr])
978 titlemessage_first[nr] :
981 ti.fade_mode = tmi.fade_mode;
982 ti.fade_delay = tmi.fade_delay;
983 ti.post_delay = tmi.post_delay;
984 ti.auto_delay = tmi.auto_delay;
989 static int compareTitleControlInfo(const void *object1, const void *object2)
991 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
992 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
995 if (tci1->initial != tci2->initial)
996 compare_result = (tci1->initial ? -1 : +1);
997 else if (tci1->sort_priority != tci2->sort_priority)
998 compare_result = tci1->sort_priority - tci2->sort_priority;
999 else if (tci1->is_image != tci2->is_image)
1000 compare_result = (tci1->is_image ? -1 : +1);
1002 compare_result = tci1->local_nr - tci2->local_nr;
1004 return compare_result;
1007 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1009 int nr, int sort_priority)
1011 title_controls[num_title_screens].is_image = is_image;
1012 title_controls[num_title_screens].initial = initial;
1013 title_controls[num_title_screens].local_nr = nr;
1014 title_controls[num_title_screens].sort_priority = sort_priority;
1016 title_controls[num_title_screens].first = FALSE; // will be set later
1018 num_title_screens++;
1021 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1025 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1027 int graphic = getTitleScreenGraphic(i, initial);
1028 Bitmap *bitmap = graphic_info[graphic].bitmap;
1029 int sort_priority = graphic_info[graphic].sort_priority;
1032 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1035 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1037 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1038 char *filename = getLevelSetTitleMessageFilename(i, initial);
1039 int sort_priority = tmi->sort_priority;
1041 if (filename != NULL)
1042 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1046 static void InitializeTitleControls(boolean show_title_initial)
1048 num_title_screens = 0;
1050 // 1st step: initialize title screens for game start (only when starting)
1051 if (show_title_initial)
1052 InitializeTitleControls_CheckTitleInfo(TRUE);
1054 // 2nd step: initialize title screens for current level set
1055 InitializeTitleControls_CheckTitleInfo(FALSE);
1057 // sort title screens according to sort_priority and title number
1058 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1059 compareTitleControlInfo);
1061 // mark first title screen
1062 title_controls[0].first = TRUE;
1065 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1067 return (pos != NULL && pos->x != -1 && pos->y != -1);
1070 static boolean visibleTextPos(struct TextPosInfo *pos)
1072 return (pos != NULL && pos->x != -1 && pos->y != -1);
1075 static void InitializeMainControls(void)
1077 boolean local_team_mode = (!network.enabled && setup.team_mode);
1080 // set main control text values to dynamically determined values
1081 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1083 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1084 menu.main.text.first_level.size));
1085 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1086 menu.main.text.last_level.size));
1087 strcpy(main_text_level_number, int2str(level_nr,
1088 menu.main.text.level_number.size));
1090 main_text_level_year = leveldir_current->year;
1091 main_text_level_imported_from = leveldir_current->imported_from;
1092 main_text_level_imported_by = leveldir_current->imported_by;
1093 main_text_level_tested_by = leveldir_current->tested_by;
1095 main_text_title_1 = getConfigProgramTitleString();
1096 main_text_title_2 = getConfigProgramCopyrightString();
1097 main_text_title_3 = getConfigProgramCompanyString();
1099 // set main control screen positions to dynamically determined values
1100 for (i = 0; main_controls[i].nr != -1; i++)
1102 struct MainControlInfo *mci = &main_controls[i];
1104 struct MenuPosInfo *pos_button = mci->pos_button;
1105 struct TextPosInfo *pos_text = mci->pos_text;
1106 struct TextPosInfo *pos_input = mci->pos_input;
1107 char *text = (mci->text ? *mci->text : NULL);
1108 char *input = (mci->input ? *mci->input : NULL);
1109 int button_graphic = mci->button_graphic;
1110 int font_text = (pos_text ? pos_text->font : -1);
1111 int font_input = (pos_input ? pos_input->font : -1);
1113 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1114 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1115 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1116 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1117 int text_chars = (text != NULL ? strlen(text) : 0);
1118 int input_chars = (input != NULL ? strlen(input) : 0);
1121 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1123 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1124 int text_width = font_text_width * text_chars;
1125 int text_height = font_text_height;
1126 int input_width = font_input_width * input_chars;
1127 int input_height = font_input_height;
1129 if (nr == MAIN_CONTROL_NAME)
1131 menu.main.input.name.width = input_width;
1132 menu.main.input.name.height = input_height;
1135 if (pos_button != NULL) // (x/y may be -1/-1 here)
1137 pos_button->width = button_width;
1138 pos_button->height = button_height;
1141 if (pos_text != NULL) // (x/y may be -1/-1 here)
1143 // calculate text size -- needed for text alignment
1144 boolean calculate_text_size = (text != NULL);
1146 if (pos_text->width == -1 || calculate_text_size)
1147 pos_text->width = text_width;
1148 if (pos_text->height == -1 || calculate_text_size)
1149 pos_text->height = text_height;
1151 if (visibleMenuPos(pos_button))
1153 if (pos_text->x == -1)
1154 pos_text->x = pos_button->x + pos_button->width;
1155 if (pos_text->y == -1)
1157 pos_button->y + (pos_button->height - pos_text->height) / 2;
1161 if (pos_input != NULL) // (x/y may be -1/-1 here)
1163 if (visibleTextPos(pos_text))
1165 if (pos_input->x == -1)
1166 pos_input->x = pos_text->x + pos_text->width;
1167 if (pos_input->y == -1)
1168 pos_input->y = pos_text->y;
1171 if (pos_input->width == -1)
1172 pos_input->width = input_width;
1173 if (pos_input->height == -1)
1174 pos_input->height = input_height;
1179 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1180 int graphic, boolean pressed)
1182 struct GraphicInfo *g = &graphic_info[graphic];
1185 int xoffset = (pressed ? g->pressed_xoffset : 0);
1186 int yoffset = (pressed ? g->pressed_yoffset : 0);
1188 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1190 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1191 g->width, g->height, dst_x, dst_y);
1194 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1195 boolean active_input,
1196 boolean pressed_button)
1200 for (i = 0; main_controls[i].nr != -1; i++)
1202 struct MainControlInfo *mci = &main_controls[i];
1204 if (mci->nr == nr || nr == -1)
1206 struct MenuPosInfo *pos_button = mci->pos_button;
1207 struct TextPosInfo *pos_text = mci->pos_text;
1208 struct TextPosInfo *pos_input = mci->pos_input;
1209 char *text = (mci->text ? *mci->text : NULL);
1210 char *input = (mci->input ? *mci->input : NULL);
1211 int button_graphic = mci->button_graphic;
1212 int font_text = (pos_text ? pos_text->font : -1);
1213 int font_input = (pos_input ? pos_input->font : -1);
1217 button_graphic = BUTTON_ACTIVE(button_graphic);
1218 font_text = FONT_ACTIVE(font_text);
1223 font_input = FONT_ACTIVE(font_input);
1226 if (visibleMenuPos(pos_button))
1228 struct MenuPosInfo *pos = pos_button;
1229 int x = mSX + pos->x;
1230 int y = mSY + pos->y;
1232 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1233 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1236 if (visibleTextPos(pos_text) && text != NULL)
1238 struct TextPosInfo *pos = pos_text;
1239 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1240 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1243 // (check why/if this is needed)
1244 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1246 DrawText(x, y, text, font_text);
1249 if (visibleTextPos(pos_input) && input != NULL)
1251 struct TextPosInfo *pos = pos_input;
1252 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1253 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1256 // (check why/if this is needed)
1257 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1259 DrawText(x, y, input, font_input);
1265 static void DrawCursorAndText_Main(int nr, boolean active_text,
1266 boolean pressed_button)
1268 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1272 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1273 boolean pressed_button)
1275 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1279 static struct MainControlInfo *getMainControlInfo(int nr)
1283 for (i = 0; main_controls[i].nr != -1; i++)
1284 if (main_controls[i].nr == nr)
1285 return &main_controls[i];
1290 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1295 int rect_x = ALIGNED_TEXT_XPOS(rect);
1296 int rect_y = ALIGNED_TEXT_YPOS(rect);
1298 return (x >= rect_x && x < rect_x + rect->width &&
1299 y >= rect_y && y < rect_y + rect->height);
1302 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1307 int rect_x = ALIGNED_TEXT_XPOS(rect);
1308 int rect_y = ALIGNED_TEXT_YPOS(rect);
1311 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1312 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1313 (x >= rect_x && x < rect_x + rect->width &&
1314 y >= rect_y && y < rect_y + rect->height));
1317 return (x >= rect_x && x < rect_x + rect->width &&
1318 y >= rect_y && y < rect_y + rect->height);
1321 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1323 int rect_width = preview->xsize * preview->tile_size;
1324 int rect_height = preview->ysize * preview->tile_size;
1325 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1326 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1328 return (x >= rect_x && x < rect_x + rect_width &&
1329 y >= rect_y && y < rect_y + rect_height);
1332 static void AdjustScrollbar(int id, int items_max, int items_visible,
1335 struct GadgetInfo *gi = screen_gadget[id];
1337 if (item_position > items_max - items_visible)
1338 item_position = items_max - items_visible;
1340 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1341 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1342 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1345 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1347 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1351 static void clearMenuListArea(void)
1353 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1355 // correct scrollbar position if placed outside menu (playfield) area
1356 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1357 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1359 // clear menu list area, but not title or scrollbar
1360 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1361 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1364 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1366 static int cursor_array[MAX_LEV_FIELDY];
1367 int x = mSX + TILEX * xpos;
1368 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1373 cursor_array[ypos] = graphic;
1375 graphic = cursor_array[ypos];
1379 graphic = BUTTON_ACTIVE(graphic);
1381 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1382 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1385 static void initCursor(int ypos, int graphic)
1387 drawCursorExt(0, ypos, FALSE, graphic);
1390 static void drawCursor(int ypos, boolean active)
1392 drawCursorExt(0, ypos, active, -1);
1395 static void drawCursorXY(int xpos, int ypos, int graphic)
1397 drawCursorExt(xpos, ypos, FALSE, graphic);
1400 static void drawChooseTreeCursor(int ypos, boolean active)
1402 drawCursorExt(0, ypos, active, -1);
1405 static void DrawHeadline(void)
1407 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1408 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1411 static void DrawTitleScreenImage(int nr, boolean initial)
1413 int graphic = getTitleScreenGraphic(nr, initial);
1414 Bitmap *bitmap = graphic_info[graphic].bitmap;
1415 int width = graphic_info[graphic].width;
1416 int height = graphic_info[graphic].height;
1417 int src_x = graphic_info[graphic].src_x;
1418 int src_y = graphic_info[graphic].src_y;
1424 if (width > WIN_XSIZE)
1426 // image width too large for window => center image horizontally
1427 src_x = (width - WIN_XSIZE) / 2;
1431 if (height > WIN_YSIZE)
1433 // image height too large for window => center image vertically
1434 src_y = (height - WIN_YSIZE) / 2;
1438 // always display title screens centered
1439 dst_x = (WIN_XSIZE - width) / 2;
1440 dst_y = (WIN_YSIZE - height) / 2;
1442 SetDrawBackgroundMask(REDRAW_ALL);
1443 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1445 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1447 if (DrawingOnBackground(dst_x, dst_y))
1448 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1450 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1452 redraw_mask = REDRAW_ALL;
1455 static void DrawTitleScreenMessage(int nr, boolean initial)
1457 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1458 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1460 if (filename == NULL)
1463 // force TITLE font on title message screen
1464 SetFontStatus(getTitleMessageGameMode(initial));
1466 // if chars *and* width set to "-1", automatically determine width
1467 if (tmi->chars == -1 && tmi->width == -1)
1468 tmi->width = viewport.window[game_status].width;
1470 // if lines *and* height set to "-1", automatically determine height
1471 if (tmi->lines == -1 && tmi->height == -1)
1472 tmi->height = viewport.window[game_status].height;
1474 // if chars set to "-1", automatically determine by text and font width
1475 if (tmi->chars == -1)
1476 tmi->chars = tmi->width / getFontWidth(tmi->font);
1478 tmi->width = tmi->chars * getFontWidth(tmi->font);
1480 // if lines set to "-1", automatically determine by text and font height
1481 if (tmi->lines == -1)
1482 tmi->lines = tmi->height / getFontHeight(tmi->font);
1484 tmi->height = tmi->lines * getFontHeight(tmi->font);
1486 // if x set to "-1", automatically determine by width and alignment
1488 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1490 // if y set to "-1", automatically determine by height and alignment
1492 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1494 SetDrawBackgroundMask(REDRAW_ALL);
1495 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1497 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1499 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1500 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1501 tmi->autowrap, tmi->centered, tmi->parse_comments);
1506 static void DrawTitleScreen(void)
1508 KeyboardAutoRepeatOff();
1510 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1513 static boolean CheckTitleScreen(boolean levelset_has_changed)
1515 static boolean show_title_initial = TRUE;
1516 boolean show_titlescreen = FALSE;
1518 // needed to be able to skip title screen, if no image or message defined
1519 InitializeTitleControls(show_title_initial);
1521 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1522 show_titlescreen = TRUE;
1524 // show initial title images and messages only once at program start
1525 show_title_initial = FALSE;
1527 return (show_titlescreen && num_title_screens > 0);
1530 void DrawMainMenu(void)
1532 static LevelDirTree *leveldir_last_valid = NULL;
1533 boolean levelset_has_changed = FALSE;
1534 int fade_mask = REDRAW_FIELD;
1536 LimitScreenUpdates(FALSE);
1538 FadeSetLeaveScreen();
1540 // do not fade out here -- function may continue and fade on editor screen
1543 FadeMenuSoundsAndMusic();
1545 ExpireSoundLoops(FALSE);
1547 KeyboardAutoRepeatOn();
1549 audio.sound_deactivated = FALSE;
1553 // needed if last screen was the playing screen, invoked from level editor
1554 if (level_editor_test_game)
1556 CloseDoor(DOOR_CLOSE_ALL);
1558 SetGameStatus(GAME_MODE_EDITOR);
1565 // needed if last screen was the setup screen and fullscreen state changed
1566 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1567 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1569 // leveldir_current may be invalid (level group, parent link)
1570 if (!validLevelSeries(leveldir_current))
1571 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1573 if (leveldir_current != leveldir_last_valid)
1574 levelset_has_changed = TRUE;
1576 // store valid level series information
1577 leveldir_last_valid = leveldir_current;
1579 init_last = init; // switch to new busy animation
1581 // needed if last screen (level choice) changed graphics, sounds or music
1582 ReloadCustomArtwork(0);
1584 if (CheckTitleScreen(levelset_has_changed))
1586 SetGameStatus(GAME_MODE_TITLE);
1593 if (redraw_mask & REDRAW_ALL)
1594 fade_mask = REDRAW_ALL;
1597 fade_mask = REDRAW_ALL;
1601 // needed if different viewport properties defined for menues
1602 ChangeViewportPropertiesIfNeeded();
1604 SetDrawtoField(DRAW_TO_BACKBUFFER);
1606 // level_nr may have been set to value over handicap with level editor
1607 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1608 level_nr = leveldir_current->handicap_level;
1610 LoadLevel(level_nr);
1611 LoadScore(level_nr);
1613 SaveLevelSetup_SeriesInfo();
1615 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1616 SetDrawDeactivationMask(REDRAW_NONE);
1617 SetDrawBackgroundMask(REDRAW_FIELD);
1619 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1622 if (fade_mask == REDRAW_ALL)
1623 RedrawGlobalBorder();
1628 InitializeMainControls();
1630 DrawCursorAndText_Main(-1, FALSE, FALSE);
1631 DrawPreviewLevelInitial();
1632 DrawNetworkPlayers();
1634 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1637 if (TAPE_IS_EMPTY(tape))
1639 DrawCompleteVideoDisplay();
1641 PlayMenuSoundsAndMusic();
1643 // create gadgets for main menu screen
1644 FreeScreenGadgets();
1645 CreateScreenGadgets();
1647 // may be required if audio buttons shown on tape and changed in setup menu
1649 CreateGameButtons();
1651 // map gadgets for main menu screen
1653 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1654 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1656 // copy actual game door content to door double buffer for OpenDoor()
1657 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1658 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1660 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1662 DrawMaskedBorder(fade_mask);
1667 // update screen area with special editor door
1668 redraw_mask |= REDRAW_ALL;
1671 SetMouseCursor(CURSOR_DEFAULT);
1673 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1676 static void gotoTopLevelDir(void)
1678 // move upwards until inside (but not above) top level directory
1679 while (leveldir_current->node_parent &&
1680 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1682 // write a "path" into level tree for easy navigation to last level
1683 if (leveldir_current->node_parent->node_group->cl_first == -1)
1685 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1686 int leveldir_pos = posTreeInfo(leveldir_current);
1687 int num_page_entries;
1688 int cl_first, cl_cursor;
1690 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1691 num_page_entries = num_leveldirs;
1693 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1695 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1696 cl_cursor = leveldir_pos - cl_first;
1698 leveldir_current->node_parent->node_group->cl_first = cl_first;
1699 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1702 leveldir_current = leveldir_current->node_parent;
1706 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1708 static unsigned int title_delay = 0;
1709 static int title_screen_nr = 0;
1710 static int last_sound = -1, last_music = -1;
1711 boolean return_to_main_menu = FALSE;
1712 struct TitleControlInfo *tci;
1715 if (button == MB_MENU_INITIALIZE)
1718 title_screen_nr = 0;
1719 tci = &title_controls[title_screen_nr];
1721 SetAnimStatus(getTitleAnimMode(tci));
1723 last_sound = SND_UNDEFINED;
1724 last_music = MUS_UNDEFINED;
1726 if (num_title_screens != 0)
1728 FadeSetEnterScreen();
1730 // use individual title fading instead of global "enter screen" fading
1731 fading = getTitleFading(tci);
1734 if (game_status_last_screen == GAME_MODE_INFO)
1736 if (num_title_screens == 0)
1738 // switch game mode from title screen mode back to info screen mode
1739 SetGameStatus(GAME_MODE_INFO);
1741 // store that last screen was info screen, not main menu screen
1742 game_status_last_screen = GAME_MODE_INFO;
1744 DrawInfoScreen_NotAvailable("Title screen information:",
1745 "No title screen for this level set.");
1749 FadeMenuSoundsAndMusic();
1752 FadeOut(REDRAW_ALL);
1754 // title screens may have different window size
1755 ChangeViewportPropertiesIfNeeded();
1757 // only required to update logic for redrawing global border
1761 DrawTitleScreenImage(tci->local_nr, tci->initial);
1763 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1765 sound = getTitleSound(tci);
1766 music = getTitleMusic(tci);
1768 if (sound != last_sound)
1769 PlayMenuSoundExt(sound);
1770 if (music != last_music)
1771 PlayMenuMusicExt(music);
1776 SetMouseCursor(CURSOR_NONE);
1780 DelayReached(&title_delay, 0); // reset delay counter
1785 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1786 button = MB_MENU_CHOICE;
1788 if (button == MB_MENU_LEAVE)
1790 return_to_main_menu = TRUE;
1792 else if (button == MB_MENU_CHOICE)
1794 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1796 SetGameStatus(GAME_MODE_INFO);
1798 info_mode = INFO_MODE_MAIN;
1807 if (title_screen_nr < num_title_screens)
1809 tci = &title_controls[title_screen_nr];
1811 SetAnimStatus(getTitleAnimMode(tci));
1813 sound = getTitleSound(tci);
1814 music = getTitleMusic(tci);
1816 if (last_sound != SND_UNDEFINED && sound != last_sound)
1817 FadeSound(last_sound);
1818 if (last_music != MUS_UNDEFINED && music != last_music)
1821 fading = getTitleFading(tci);
1823 FadeOut(REDRAW_ALL);
1826 DrawTitleScreenImage(tci->local_nr, tci->initial);
1828 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1830 sound = getTitleSound(tci);
1831 music = getTitleMusic(tci);
1833 if (sound != last_sound)
1834 PlayMenuSoundExt(sound);
1835 if (music != last_music)
1836 PlayMenuMusicExt(music);
1843 DelayReached(&title_delay, 0); // reset delay counter
1847 FadeMenuSoundsAndMusic();
1849 return_to_main_menu = TRUE;
1853 if (return_to_main_menu)
1855 SetMouseCursor(CURSOR_DEFAULT);
1857 // force full menu screen redraw after displaying title screens
1858 redraw_mask = REDRAW_ALL;
1860 if (game_status_last_screen == GAME_MODE_INFO)
1862 SetGameStatus(GAME_MODE_INFO);
1864 info_mode = INFO_MODE_MAIN;
1868 else // default: return to main menu
1870 SetGameStatus(GAME_MODE_MAIN);
1877 static void HandleMainMenu_SelectLevel(int step, int direction,
1878 int selected_level_nr)
1880 int old_level_nr = level_nr;
1883 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1884 new_level_nr = selected_level_nr;
1886 new_level_nr = old_level_nr + step * direction;
1888 if (new_level_nr < leveldir_current->first_level)
1889 new_level_nr = leveldir_current->first_level;
1890 if (new_level_nr > leveldir_current->last_level)
1891 new_level_nr = leveldir_current->last_level;
1893 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1895 // skipping levels is only allowed when trying to skip single level
1896 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1897 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1899 leveldir_current->handicap_level++;
1900 SaveLevelSetup_SeriesInfo();
1903 new_level_nr = leveldir_current->handicap_level;
1906 if (new_level_nr != old_level_nr)
1908 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1910 PlaySound(SND_MENU_ITEM_SELECTING);
1912 level_nr = new_level_nr;
1914 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1915 int2str(level_nr, menu.main.text.level_number.size),
1916 mci->pos_text->font);
1918 LoadLevel(level_nr);
1919 DrawPreviewLevelInitial();
1923 DrawCompleteVideoDisplay();
1925 SaveLevelSetup_SeriesInfo();
1927 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1929 // needed because DrawPreviewLevelInitial() takes some time
1935 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1937 static int choice = MAIN_CONTROL_GAME;
1938 static boolean button_pressed_last = FALSE;
1939 boolean button_pressed = FALSE;
1943 if (button == MB_MENU_INITIALIZE)
1945 DrawCursorAndText_Main(choice, TRUE, FALSE);
1950 if (mx || my) // mouse input
1954 for (i = 0; main_controls[i].nr != -1; i++)
1956 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1957 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1958 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1960 pos = main_controls[i].nr;
1966 // check if level preview was clicked
1967 if (insidePreviewRect(&preview, mx - SX, my - SY))
1968 pos = MAIN_CONTROL_GAME;
1970 // handle pressed/unpressed state for active/inactive menu buttons
1971 // (if pos != -1, "i" contains index position corresponding to "pos")
1973 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1974 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1975 button_pressed = TRUE;
1977 if (button_pressed != button_pressed_last)
1979 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1982 PlaySound(SND_MENU_BUTTON_PRESSING);
1984 PlaySound(SND_MENU_BUTTON_RELEASING);
1987 else if (dx || dy) // keyboard input
1989 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1990 choice == MAIN_CONTROL_SETUP))
1991 button = MB_MENU_CHOICE;
1996 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1998 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2000 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2002 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2004 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2006 CloseDoor(DOOR_CLOSE_2);
2008 SetGameStatus(GAME_MODE_LEVELNR);
2010 DrawChooseLevelNr();
2012 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2018 PlaySound(SND_MENU_ITEM_ACTIVATING);
2020 DrawCursorAndText_Main(choice, FALSE, FALSE);
2021 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2027 if (choice != MAIN_CONTROL_INFO &&
2028 choice != MAIN_CONTROL_SETUP)
2029 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2034 PlaySound(SND_MENU_ITEM_SELECTING);
2036 if (pos == MAIN_CONTROL_NAME)
2038 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2040 HandleTypeName(strlen(setup.player_name), 0);
2042 else if (pos == MAIN_CONTROL_LEVELS)
2046 CloseDoor(DOOR_CLOSE_2);
2048 SetGameStatus(GAME_MODE_LEVELS);
2050 SaveLevelSetup_LastSeries();
2051 SaveLevelSetup_SeriesInfo();
2053 if (setup.internal.choose_from_top_leveldir)
2056 DrawChooseLevelSet();
2059 else if (pos == MAIN_CONTROL_SCORES)
2061 CloseDoor(DOOR_CLOSE_2);
2063 SetGameStatus(GAME_MODE_SCORES);
2065 DrawHallOfFame(level_nr, -1);
2067 else if (pos == MAIN_CONTROL_EDITOR)
2069 if (leveldir_current->readonly &&
2070 !strEqual(setup.player_name, "Artsoft"))
2071 Request("This level is read only!", REQ_CONFIRM);
2073 CloseDoor(DOOR_CLOSE_2);
2075 SetGameStatus(GAME_MODE_EDITOR);
2077 FadeSetEnterScreen();
2081 else if (pos == MAIN_CONTROL_INFO)
2083 CloseDoor(DOOR_CLOSE_2);
2085 SetGameStatus(GAME_MODE_INFO);
2087 info_mode = INFO_MODE_MAIN;
2091 else if (pos == MAIN_CONTROL_GAME)
2093 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2095 else if (pos == MAIN_CONTROL_SETUP)
2097 CloseDoor(DOOR_CLOSE_2);
2099 SetGameStatus(GAME_MODE_SETUP);
2101 setup_mode = SETUP_MODE_MAIN;
2105 else if (pos == MAIN_CONTROL_QUIT)
2107 SaveLevelSetup_LastSeries();
2108 SaveLevelSetup_SeriesInfo();
2110 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2111 SetGameStatus(GAME_MODE_QUIT);
2116 button_pressed_last = button_pressed;
2120 // ============================================================================
2121 // info screen functions
2122 // ============================================================================
2124 static struct TokenInfo *info_info;
2125 static int num_info_info; // number of info entries shown on screen
2126 static int max_info_info; // total number of info entries in list
2128 static void execInfoTitleScreen(void)
2130 info_mode = INFO_MODE_TITLE;
2135 static void execInfoElements(void)
2137 info_mode = INFO_MODE_ELEMENTS;
2142 static void execInfoMusic(void)
2144 info_mode = INFO_MODE_MUSIC;
2149 static void execInfoCredits(void)
2151 info_mode = INFO_MODE_CREDITS;
2156 static void execInfoProgram(void)
2158 info_mode = INFO_MODE_PROGRAM;
2163 static void execInfoVersion(void)
2165 info_mode = INFO_MODE_VERSION;
2170 static void execInfoLevelSet(void)
2172 info_mode = INFO_MODE_LEVELSET;
2177 static void execExitInfo(void)
2179 SetGameStatus(GAME_MODE_MAIN);
2184 static struct TokenInfo info_info_main[] =
2186 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2187 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2188 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2189 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2190 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2191 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2192 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2193 { TYPE_EMPTY, NULL, "" },
2194 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2199 static int getMenuTextFont(int type)
2201 if (type & (TYPE_SWITCH |
2215 static struct TokenInfo *setup_info;
2216 static struct TokenInfo setup_info_input[];
2218 static struct TokenInfo *menu_info;
2220 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2221 int screen_pos, int menu_info_pos_raw,
2224 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2225 struct TokenInfo *ti = &token_info[pos];
2226 int xpos = MENU_SCREEN_START_XPOS;
2227 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2228 int font_nr = getMenuTextFont(ti->type);
2230 if (setup_mode == SETUP_MODE_INPUT)
2231 font_nr = FONT_MENU_1;
2234 font_nr = FONT_ACTIVE(font_nr);
2236 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2238 if (ti->type & ~TYPE_SKIP_ENTRY)
2239 drawCursor(screen_pos, active);
2242 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2245 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2248 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2251 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2254 static char *window_size_text;
2255 static char *scaling_type_text;
2256 static char *network_server_text;
2258 static void drawSetupValue(int, int);
2260 static void drawMenuInfoList(int first_entry, int num_page_entries,
2261 int max_page_entries)
2265 if (first_entry + num_page_entries > max_page_entries)
2268 clearMenuListArea();
2270 for (i = 0; i < num_page_entries; i++)
2272 int menu_info_pos = first_entry + i;
2273 struct TokenInfo *si = &menu_info[menu_info_pos];
2274 void *value_ptr = si->value;
2276 // set some entries to "unchangeable" according to other variables
2277 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2278 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2279 (value_ptr == &setup.sound_music && !audio.music_available) ||
2280 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2281 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2282 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2283 si->type |= TYPE_GHOSTED;
2285 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2286 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2287 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2288 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2289 else if (si->type & ~TYPE_SKIP_ENTRY)
2290 initCursor(i, IMG_MENU_BUTTON);
2292 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2294 if (si->type & TYPE_STRING)
2298 if (value_ptr == &network_server_text)
2299 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2301 if (gadget_id != -1)
2303 struct GadgetInfo *gi = screen_gadget[gadget_id];
2304 int xpos = MENU_SCREEN_START_XPOS;
2305 int ypos = MENU_SCREEN_START_YPOS + i;
2306 int x = mSX + xpos * 32;
2307 int y = mSY + ypos * 32;
2309 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2313 if (si->type & TYPE_VALUE &&
2314 menu_info == setup_info)
2315 drawSetupValue(i, menu_info_pos);
2319 static void DrawInfoScreen_Main(void)
2321 int fade_mask = REDRAW_FIELD;
2324 if (redraw_mask & REDRAW_ALL)
2325 fade_mask = REDRAW_ALL;
2328 fade_mask = REDRAW_ALL;
2331 FadeMenuSoundsAndMusic();
2333 FreeScreenGadgets();
2334 CreateScreenGadgets();
2336 // (needed after displaying title screens which disable auto repeat)
2337 KeyboardAutoRepeatOn();
2339 FadeSetLeaveScreen();
2343 // needed if different viewport properties defined for info screen
2344 ChangeViewportPropertiesIfNeeded();
2346 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2350 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2352 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2354 info_info = info_info_main;
2356 // determine maximal number of info entries that can be displayed on screen
2358 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2361 // determine maximal number of info entries available for menu of info screen
2363 for (i = 0; info_info[i].type != 0; i++)
2366 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2368 MapScreenGadgets(max_info_info);
2370 PlayMenuSoundsAndMusic();
2372 DrawMaskedBorder(fade_mask);
2377 static void changeSetupValue(int, int, int);
2379 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2380 int mode, int num_page_entries,
2381 int max_page_entries)
2383 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2384 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2385 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2386 int *num_page_entries_last = num_page_entries_all_last[game_status];
2387 int *choice_store = choice_stores[game_status];
2388 int *first_entry_store = first_entry_stores[game_status];
2389 int choice = choice_store[mode]; // starts with 0
2390 int first_entry = first_entry_store[mode]; // starts with 0
2392 int y = choice - first_entry;
2394 boolean position_set_by_scrollbar = (dx == 999);
2395 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2398 if (button == MB_MENU_INITIALIZE)
2400 // check if number of menu page entries has changed (may happen by change
2401 // of custom artwork definition value for 'list_size' for this menu screen)
2402 // (in this case, the last menu position most probably has to be corrected)
2403 if (num_page_entries != num_page_entries_last[mode])
2405 choice_store[mode] = first_entry_store[mode] = 0;
2407 choice = first_entry = 0;
2410 num_page_entries_last[mode] = num_page_entries;
2413 // advance to first valid menu entry
2414 while (choice < num_page_entries &&
2415 menu_info[choice].type & TYPE_SKIP_ENTRY)
2418 if (position_set_by_scrollbar)
2419 first_entry = first_entry_store[mode] = dy;
2421 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2422 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2424 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2426 if (choice < first_entry)
2428 choice = first_entry;
2430 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2433 else if (choice > first_entry + num_page_entries - 1)
2435 choice = first_entry + num_page_entries - 1;
2437 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2441 choice_store[mode] = choice;
2443 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2447 else if (button == MB_MENU_LEAVE)
2449 PlaySound(SND_MENU_ITEM_SELECTING);
2451 for (i = 0; i < max_page_entries; i++)
2453 if (menu_info[i].type & TYPE_LEAVE_MENU)
2455 void (*menu_callback_function)(void) = menu_info[i].value;
2459 menu_callback_function();
2461 break; // absolutely needed because function changes 'menu_info'!
2468 if (mx || my) // mouse input
2470 x = (mx - mSX) / 32;
2471 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2473 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2475 // move cursor instead of scrolling when already at start/end of list
2476 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2478 else if (dy == +1 * SCROLL_LINE &&
2479 first_entry + num_page_entries == max_page_entries)
2482 // handle scrolling screen one line or page
2484 y + dy > num_page_entries - 1)
2486 boolean redraw = FALSE;
2488 if (ABS(dy) == SCROLL_PAGE)
2489 step = num_page_entries - 1;
2491 if (dy < 0 && first_entry > 0)
2493 // scroll page/line up
2495 first_entry -= step;
2496 if (first_entry < 0)
2501 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2503 // scroll page/line down
2505 first_entry += step;
2506 if (first_entry + num_page_entries > max_page_entries)
2507 first_entry = MAX(0, max_page_entries - num_page_entries);
2514 choice += first_entry - first_entry_store[mode];
2516 if (choice < first_entry)
2518 choice = first_entry;
2520 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2523 else if (choice > first_entry + num_page_entries - 1)
2525 choice = first_entry + num_page_entries - 1;
2527 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2530 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2534 if (choice < first_entry ||
2535 choice > first_entry + num_page_entries - 1)
2536 first_entry += SIGN(dy);
2539 first_entry_store[mode] = first_entry;
2540 choice_store[mode] = choice;
2542 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2544 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2546 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2547 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2555 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2557 if (menu_info[choice].type & menu_navigation_type ||
2558 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2559 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2560 menu_info[choice].type & TYPE_PLAYER)
2561 button = MB_MENU_CHOICE;
2566 // jump to next non-empty menu entry (up or down)
2567 while (first_entry + y > 0 &&
2568 first_entry + y < max_page_entries - 1 &&
2569 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2572 if (!IN_VIS_MENU(x, y))
2574 choice += y - y_old;
2576 if (choice < first_entry)
2577 first_entry = choice;
2578 else if (choice > first_entry + num_page_entries - 1)
2579 first_entry = choice - num_page_entries + 1;
2581 if (first_entry >= 0 &&
2582 first_entry + num_page_entries <= max_page_entries)
2584 first_entry_store[mode] = first_entry;
2586 if (choice < first_entry)
2587 choice = first_entry;
2588 else if (choice > first_entry + num_page_entries - 1)
2589 choice = first_entry + num_page_entries - 1;
2591 choice_store[mode] = choice;
2593 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2595 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2597 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2598 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2605 if (!anyScrollbarGadgetActive() &&
2606 IN_VIS_MENU(x, y) &&
2607 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2608 y >= 0 && y < num_page_entries)
2612 if (first_entry + y != choice &&
2613 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2615 PlaySound(SND_MENU_ITEM_ACTIVATING);
2617 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2618 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2620 choice = choice_store[mode] = first_entry + y;
2624 PlaySound(SND_MENU_ITEM_SELECTING);
2626 for (i = 0; menu_info[i].type != 0; i++)
2628 if (menu_info[i].type & TYPE_LEAVE_MENU)
2630 void (*menu_callback_function)(void) = menu_info[i].value;
2634 menu_callback_function();
2636 // absolutely needed because function changes 'menu_info'!
2644 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2646 PlaySound(SND_MENU_ITEM_SELECTING);
2648 // when selecting key headline, execute function for key value change
2649 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2650 menu_info[first_entry + y + 1].type & TYPE_KEY)
2653 // when selecting string value, execute function for list selection
2654 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2655 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2658 // when selecting string value, execute function for text input gadget
2659 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2660 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2663 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2665 void (*menu_callback_function)(void) =
2666 menu_info[first_entry + y].value;
2668 FadeSetFromType(menu_info[first_entry + y].type);
2670 menu_callback_function();
2672 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2674 void (*gadget_callback_function)(void) =
2675 menu_info[first_entry + y].value;
2677 gadget_callback_function();
2679 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2680 menu_info == setup_info)
2682 changeSetupValue(y, first_entry + y, dx);
2688 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2690 menu_info = info_info;
2692 HandleMenuScreen(mx, my, dx, dy, button,
2693 info_mode, num_info_info, max_info_info);
2696 static int getMenuFontSpacing(int spacing_height, int font_nr)
2698 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2700 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2704 static int getMenuTextSpacing(int spacing_height, int font_nr)
2706 return (getMenuFontSpacing(spacing_height, font_nr) +
2707 EXTRA_SPACING(game_status));
2710 static int getMenuTextStep(int spacing_height, int font_nr)
2712 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2715 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2717 int font_title = MENU_INFO_FONT_TITLE;
2718 int font_error = FONT_TEXT_2;
2719 int font_foot = MENU_INFO_FONT_FOOT;
2720 int spacing_title = menu.headline1_spacing_info[info_mode];
2721 int ystep_title = getMenuTextStep(spacing_title, font_title);
2722 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2723 int ystart2 = ystart1 + ystep_title;
2724 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2726 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2728 FadeOut(REDRAW_FIELD);
2733 DrawTextSCentered(ystart1, font_title, text_title);
2734 DrawTextSCentered(ystart2, font_error, text_error);
2736 DrawTextSCentered(ybottom, font_foot,
2737 "Press any key or button for info menu");
2739 FadeIn(REDRAW_FIELD);
2742 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2744 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2745 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2746 int font_title = MENU_INFO_FONT_TITLE;
2747 int font_foot = MENU_INFO_FONT_FOOT;
2748 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2749 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2750 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2751 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2752 int ystep = MENU_SCREEN_INFO_YSTEP;
2753 int element, action, direction;
2761 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2762 infoscreen_step[i] = infoscreen_frame[i] = 0;
2767 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2769 DrawTextSCentered(ybottom, font_foot,
2770 "Press any key or button for next page");
2776 while (helpanim_info[j].element != HELPANIM_LIST_END)
2778 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2783 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2792 j += infoscreen_step[i - start];
2794 element = helpanim_info[j].element;
2795 action = helpanim_info[j].action;
2796 direction = helpanim_info[j].direction;
2799 element = EL_UNKNOWN;
2801 if (action != -1 && direction != -1)
2802 graphic = el_act_dir2img(element, action, direction);
2803 else if (action != -1)
2804 graphic = el_act2img(element, action);
2805 else if (direction != -1)
2806 graphic = el_dir2img(element, direction);
2808 graphic = el2img(element);
2810 delay = helpanim_info[j++].delay;
2815 if (infoscreen_frame[i - start] == 0)
2818 infoscreen_frame[i - start] = delay - 1;
2822 sync_frame = delay - infoscreen_frame[i - start];
2823 infoscreen_frame[i - start]--;
2826 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2828 if (!infoscreen_frame[i - start])
2829 infoscreen_step[i - start] = 0;
2833 if (!infoscreen_frame[i - start])
2834 infoscreen_step[i - start]++;
2835 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2841 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2843 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2844 graphic, sync_frame, USE_MASKING);
2847 DrawInfoScreen_HelpText(element, action, direction, i - start);
2852 redraw_mask |= REDRAW_FIELD;
2857 static char *getHelpText(int element, int action, int direction)
2859 char token[MAX_LINE_LEN];
2861 strcpy(token, element_info[element].token_name);
2864 strcat(token, element_action_info[action].suffix);
2866 if (direction != -1)
2867 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2869 return getHashEntry(helptext_info, token);
2872 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2874 int font_nr = FONT_INFO_ELEMENTS;
2875 int font_width = getFontWidth(font_nr);
2876 int font_height = getFontHeight(font_nr);
2877 int yoffset = (TILEX - 2 * font_height) / 2;
2878 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2879 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2880 int ystep = TILEY + 4;
2881 int pad_left = xstart - SX;
2882 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2883 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2884 int max_lines_per_text = 2;
2887 if (action != -1 && direction != -1) // element.action.direction
2888 text = getHelpText(element, action, direction);
2890 if (text == NULL && action != -1) // element.action
2891 text = getHelpText(element, action, -1);
2893 if (text == NULL && direction != -1) // element.direction
2894 text = getHelpText(element, -1, direction);
2896 if (text == NULL) // base element
2897 text = getHelpText(element, -1, -1);
2899 if (text == NULL) // not found
2900 text = "No description available";
2902 if (strlen(text) <= max_chars_per_line) // only one line of text
2903 ystart += getFontHeight(font_nr) / 2;
2905 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2906 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2907 TRUE, FALSE, FALSE);
2910 static void DrawInfoScreen_TitleScreen(void)
2912 SetGameStatus(GAME_MODE_TITLE);
2917 void HandleInfoScreen_TitleScreen(int button)
2919 HandleTitleScreen(0, 0, 0, 0, button);
2922 static void DrawInfoScreen_Elements(void)
2924 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2926 FadeOut(REDRAW_FIELD);
2931 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2933 FadeIn(REDRAW_FIELD);
2936 void HandleInfoScreen_Elements(int button)
2938 static unsigned int info_delay = 0;
2939 static int num_anims;
2940 static int num_pages;
2942 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2945 if (button == MB_MENU_INITIALIZE)
2947 boolean new_element = TRUE;
2951 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2953 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2955 else if (new_element)
2958 new_element = FALSE;
2962 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2966 if (button == MB_MENU_LEAVE)
2968 PlaySound(SND_MENU_ITEM_SELECTING);
2970 info_mode = INFO_MODE_MAIN;
2975 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2977 if (button != MB_MENU_INITIALIZE)
2979 PlaySound(SND_MENU_ITEM_SELECTING);
2984 if (page >= num_pages)
2986 FadeMenuSoundsAndMusic();
2988 info_mode = INFO_MODE_MAIN;
2995 FadeSetNextScreen();
2997 if (button != MB_MENU_INITIALIZE)
2998 FadeOut(REDRAW_FIELD);
3000 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3002 if (button != MB_MENU_INITIALIZE)
3003 FadeIn(REDRAW_FIELD);
3007 if (DelayReached(&info_delay, GameFrameDelay))
3008 if (page < num_pages)
3009 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3011 PlayMenuSoundIfLoop();
3015 static void DrawInfoScreen_Music(void)
3017 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3019 FadeOut(REDRAW_FIELD);
3026 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3028 FadeIn(REDRAW_FIELD);
3031 void HandleInfoScreen_Music(int button)
3033 static struct MusicFileInfo *list = NULL;
3034 int font_title = MENU_INFO_FONT_TITLE;
3035 int font_head = MENU_INFO_FONT_HEAD;
3036 int font_text = MENU_INFO_FONT_TEXT;
3037 int font_foot = MENU_INFO_FONT_FOOT;
3038 int spacing_title = menu.headline1_spacing_info[info_mode];
3039 int spacing_head = menu.headline2_spacing_info[info_mode];
3040 int ystep_title = getMenuTextStep(spacing_title, font_title);
3041 int ystep_head = getMenuTextStep(spacing_head, font_head);
3042 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3043 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3045 if (button == MB_MENU_INITIALIZE)
3047 list = music_file_info;
3051 FadeMenuSoundsAndMusic();
3056 DrawTextSCentered(ystart, font_title,
3057 "No music info for this level set.");
3059 DrawTextSCentered(ybottom, font_foot,
3060 "Press any key or button for info menu");
3066 if (button == MB_MENU_LEAVE)
3068 PlaySound(SND_MENU_ITEM_SELECTING);
3070 FadeMenuSoundsAndMusic();
3072 info_mode = INFO_MODE_MAIN;
3077 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3079 if (button != MB_MENU_INITIALIZE)
3081 PlaySound(SND_MENU_ITEM_SELECTING);
3089 FadeMenuSoundsAndMusic();
3091 info_mode = INFO_MODE_MAIN;
3097 FadeMenuSoundsAndMusic();
3099 if (list != music_file_info)
3100 FadeSetNextScreen();
3102 if (button != MB_MENU_INITIALIZE)
3103 FadeOut(REDRAW_FIELD);
3110 int sound = list->music;
3112 if (sound_info[sound].loop)
3113 PlaySoundLoop(sound);
3117 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3121 int music = list->music;
3123 if (music_info[music].loop)
3124 PlayMusicLoop(music);
3128 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3131 ystart += ystep_title;
3133 if (!strEqual(list->title, UNKNOWN_NAME))
3135 if (!strEqual(list->title_header, UNKNOWN_NAME))
3137 DrawTextSCentered(ystart, font_head, list->title_header);
3138 ystart += ystep_head;
3141 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3142 ystart += ystep_head;
3145 if (!strEqual(list->artist, UNKNOWN_NAME))
3147 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3148 DrawTextSCentered(ystart, font_head, list->artist_header);
3150 DrawTextSCentered(ystart, font_head, "by");
3152 ystart += ystep_head;
3154 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3155 ystart += ystep_head;
3158 if (!strEqual(list->album, UNKNOWN_NAME))
3160 if (!strEqual(list->album_header, UNKNOWN_NAME))
3161 DrawTextSCentered(ystart, font_head, list->album_header);
3163 DrawTextSCentered(ystart, font_head, "from the album");
3165 ystart += ystep_head;
3167 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3168 ystart += ystep_head;
3171 if (!strEqual(list->year, UNKNOWN_NAME))
3173 if (!strEqual(list->year_header, UNKNOWN_NAME))
3174 DrawTextSCentered(ystart, font_head, list->year_header);
3176 DrawTextSCentered(ystart, font_head, "from the year");
3178 ystart += ystep_head;
3180 DrawTextFCentered(ystart, font_text, "%s", list->year);
3181 ystart += ystep_head;
3184 DrawTextSCentered(ybottom, FONT_TEXT_4,
3185 "Press any key or button for next page");
3187 if (button != MB_MENU_INITIALIZE)
3188 FadeIn(REDRAW_FIELD);
3191 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3192 PlaySoundLoop(list->music);
3195 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3197 int font_title = MENU_INFO_FONT_TITLE;
3198 int font_head = MENU_INFO_FONT_HEAD;
3199 int font_text = MENU_INFO_FONT_TEXT;
3200 int font_foot = MENU_INFO_FONT_FOOT;
3201 int spacing_title = menu.headline1_spacing_info[info_mode];
3202 int spacing_head = menu.headline2_spacing_info[info_mode];
3203 int spacing_para = menu.paragraph_spacing_info[info_mode];
3204 int spacing_line = menu.line_spacing_info[info_mode];
3205 int ystep_title = getMenuTextStep(spacing_title, font_title);
3206 int ystep_head = getMenuTextStep(spacing_head, font_head);
3207 int ystep_para = getMenuTextStep(spacing_para, font_text);
3208 int ystep_line = getMenuTextStep(spacing_line, font_text);
3209 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3210 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3215 DrawTextSCentered(ystart, font_title, "Credits:");
3216 ystart += ystep_title;
3220 DrawTextSCentered(ystart, font_head,
3221 "Special thanks to");
3222 ystart += ystep_head;
3223 DrawTextSCentered(ystart, font_text,
3225 ystart += ystep_head;
3226 DrawTextSCentered(ystart, font_head,
3228 ystart += ystep_head;
3229 DrawTextSCentered(ystart, font_text,
3230 "\"Boulder Dash\"");
3231 ystart += ystep_head;
3232 DrawTextSCentered(ystart, font_head,
3234 ystart += ystep_head;
3235 DrawTextSCentered(ystart, font_text,
3237 ystart += ystep_head;
3238 DrawTextSCentered(ystart, font_head,
3240 ystart += ystep_head;
3241 DrawTextSCentered(ystart, font_text,
3242 "First Star Software");
3244 else if (screen_nr == 1)
3246 DrawTextSCentered(ystart, font_head,
3247 "Special thanks to");
3248 ystart += ystep_head;
3249 DrawTextSCentered(ystart, font_text,
3250 "Klaus Heinz & Volker Wertich");
3251 ystart += ystep_head;
3252 DrawTextSCentered(ystart, font_head,
3254 ystart += ystep_head;
3255 DrawTextSCentered(ystart, font_text,
3256 "\"Emerald Mine\"");
3257 ystart += ystep_head;
3258 DrawTextSCentered(ystart, font_head,
3260 ystart += ystep_head;
3261 DrawTextSCentered(ystart, font_text,
3263 ystart += ystep_head;
3264 DrawTextSCentered(ystart, font_head,
3266 ystart += ystep_head;
3267 DrawTextSCentered(ystart, font_text,
3270 else if (screen_nr == 2)
3272 DrawTextSCentered(ystart, font_head,
3273 "Special thanks to");
3274 ystart += ystep_head;
3275 DrawTextSCentered(ystart, font_text,
3276 "Michael Stopp & Philip Jespersen");
3277 ystart += ystep_head;
3278 DrawTextSCentered(ystart, font_head,
3280 ystart += ystep_head;
3281 DrawTextSCentered(ystart, font_text,
3283 ystart += ystep_head;
3284 DrawTextSCentered(ystart, font_head,
3286 ystart += ystep_head;
3287 DrawTextSCentered(ystart, font_text,
3289 ystart += ystep_head;
3290 DrawTextSCentered(ystart, font_head,
3292 ystart += ystep_head;
3293 DrawTextSCentered(ystart, font_text,
3294 "Digital Integration");
3296 else if (screen_nr == 3)
3298 DrawTextSCentered(ystart, font_head,
3299 "Special thanks to");
3300 ystart += ystep_head;
3301 DrawTextSCentered(ystart, font_text,
3302 "Hiroyuki Imabayashi");
3303 ystart += ystep_head;
3304 DrawTextSCentered(ystart, font_head,
3306 ystart += ystep_head;
3307 DrawTextSCentered(ystart, font_text,
3309 ystart += ystep_head;
3310 DrawTextSCentered(ystart, font_head,
3312 ystart += ystep_head;
3313 DrawTextSCentered(ystart, font_text,
3315 ystart += ystep_head;
3316 DrawTextSCentered(ystart, font_head,
3318 ystart += ystep_head;
3319 DrawTextSCentered(ystart, font_text,
3322 else if (screen_nr == 4)
3324 DrawTextSCentered(ystart, font_head,
3325 "Special thanks to");
3326 ystart += ystep_head;
3327 DrawTextSCentered(ystart, font_text,
3329 ystart += ystep_head;
3330 DrawTextSCentered(ystart, font_head,
3332 ystart += ystep_head;
3333 DrawTextSCentered(ystart, font_text,
3334 "J\xfcrgen Bonhagen");
3335 ystart += ystep_head;
3336 DrawTextSCentered(ystart, font_head,
3337 "for the continuous creation");
3338 ystart += ystep_line;
3339 DrawTextSCentered(ystart, font_head,
3340 "of outstanding level sets");
3342 else if (screen_nr == 5)
3344 DrawTextSCentered(ystart, font_head,
3346 ystart += ystep_head;
3347 DrawTextSCentered(ystart, font_text,
3349 ystart += ystep_head;
3350 DrawTextSCentered(ystart, font_head,
3351 "for ideas and inspiration by");
3352 ystart += ystep_head;
3353 DrawTextSCentered(ystart, font_text,
3355 ystart += ystep_para;
3357 DrawTextSCentered(ystart, font_head,
3359 ystart += ystep_head;
3360 DrawTextSCentered(ystart, font_text,
3362 ystart += ystep_head;
3363 DrawTextSCentered(ystart, font_head,
3364 "for ideas and inspiration by");
3365 ystart += ystep_head;
3366 DrawTextSCentered(ystart, font_text,
3369 else if (screen_nr == 6)
3371 DrawTextSCentered(ystart, font_head,
3373 ystart += ystep_head;
3374 DrawTextSCentered(ystart, font_text,
3376 ystart += ystep_head;
3377 DrawTextSCentered(ystart, font_head,
3378 "for the code base used for the");
3379 ystart += ystep_line;
3380 DrawTextSCentered(ystart, font_head,
3381 "native Emerald Mine engine");
3383 else if (screen_nr == 7)
3385 DrawTextSCentered(ystart, font_head,
3387 ystart += ystep_head;
3388 DrawTextSCentered(ystart, font_text,
3390 ystart += ystep_head;
3391 DrawTextSCentered(ystart, font_head,
3392 "for the initial DOS port");
3393 ystart += ystep_para;
3395 DrawTextSCentered(ystart, font_head,
3397 ystart += ystep_head;
3398 DrawTextSCentered(ystart, font_text,
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_head,
3402 "for some additional toons");
3404 else if (screen_nr == 8)
3406 DrawTextSCentered(ystart, font_head,
3407 "And not to forget:");
3408 ystart += ystep_head;
3409 DrawTextSCentered(ystart, font_head,
3411 ystart += ystep_head;
3412 DrawTextSCentered(ystart, font_text,
3413 "All those who contributed");
3414 ystart += ystep_line;
3415 DrawTextSCentered(ystart, font_text,
3416 "levels to this game");
3417 ystart += ystep_line;
3418 DrawTextSCentered(ystart, font_text,
3422 DrawTextSCentered(ybottom, font_foot,
3423 "Press any key or button for next page");
3426 static void DrawInfoScreen_Credits(void)
3428 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3430 FadeMenuSoundsAndMusic();
3432 FadeOut(REDRAW_FIELD);
3434 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3436 FadeIn(REDRAW_FIELD);
3439 void HandleInfoScreen_Credits(int button)
3441 static int screen_nr = 0;
3442 int num_screens = 9;
3444 if (button == MB_MENU_INITIALIZE)
3448 // DrawInfoScreen_CreditsScreen(screen_nr);
3451 if (button == MB_MENU_LEAVE)
3453 PlaySound(SND_MENU_ITEM_SELECTING);
3455 info_mode = INFO_MODE_MAIN;
3460 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3462 if (button != MB_MENU_INITIALIZE)
3464 PlaySound(SND_MENU_ITEM_SELECTING);
3469 if (screen_nr >= num_screens)
3471 FadeMenuSoundsAndMusic();
3473 info_mode = INFO_MODE_MAIN;
3480 FadeSetNextScreen();
3482 if (button != MB_MENU_INITIALIZE)
3483 FadeOut(REDRAW_FIELD);
3485 DrawInfoScreen_CreditsScreen(screen_nr);
3487 if (button != MB_MENU_INITIALIZE)
3488 FadeIn(REDRAW_FIELD);
3492 PlayMenuSoundIfLoop();
3496 static void DrawInfoScreen_Program(void)
3498 int font_title = MENU_INFO_FONT_TITLE;
3499 int font_head = MENU_INFO_FONT_HEAD;
3500 int font_text = MENU_INFO_FONT_TEXT;
3501 int font_foot = MENU_INFO_FONT_FOOT;
3502 int spacing_title = menu.headline1_spacing_info[info_mode];
3503 int spacing_head = menu.headline2_spacing_info[info_mode];
3504 int spacing_para = menu.paragraph_spacing_info[info_mode];
3505 int spacing_line = menu.line_spacing_info[info_mode];
3506 int ystep_title = getMenuTextStep(spacing_title, font_title);
3507 int ystep_head = getMenuTextStep(spacing_head, font_head);
3508 int ystep_para = getMenuTextStep(spacing_para, font_text);
3509 int ystep_line = getMenuTextStep(spacing_line, font_text);
3510 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3511 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3513 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3515 FadeOut(REDRAW_FIELD);
3520 DrawTextSCentered(ystart, font_title, "Program Information:");
3521 ystart += ystep_title;
3523 DrawTextSCentered(ystart, font_head,
3524 "This game is Freeware!");
3525 ystart += ystep_head;
3526 DrawTextSCentered(ystart, font_head,
3527 "If you like it, send e-mail to:");
3528 ystart += ystep_head;
3529 DrawTextSCentered(ystart, font_text,
3530 setup.internal.program_email);
3531 ystart += ystep_para;
3533 DrawTextSCentered(ystart, font_head,
3534 "More information and levels:");
3535 ystart += ystep_head;
3536 DrawTextSCentered(ystart, font_text,
3537 setup.internal.program_website);
3538 ystart += ystep_para;
3540 DrawTextSCentered(ystart, font_head,
3541 "If you have created new levels,");
3542 ystart += ystep_line;
3543 DrawTextSCentered(ystart, font_head,
3544 "send them to me to include them!");
3545 ystart += ystep_head;
3546 DrawTextSCentered(ystart, font_head,
3549 DrawTextSCentered(ybottom, font_foot,
3550 "Press any key or button for info menu");
3552 FadeIn(REDRAW_FIELD);
3555 void HandleInfoScreen_Program(int button)
3557 if (button == MB_MENU_LEAVE)
3559 PlaySound(SND_MENU_ITEM_SELECTING);
3561 info_mode = INFO_MODE_MAIN;
3566 else if (button == MB_MENU_CHOICE)
3568 PlaySound(SND_MENU_ITEM_SELECTING);
3570 FadeMenuSoundsAndMusic();
3572 info_mode = INFO_MODE_MAIN;
3577 PlayMenuSoundIfLoop();
3581 static void DrawInfoScreen_Version(void)
3583 int font_title = MENU_INFO_FONT_TITLE;
3584 int font_head = MENU_INFO_FONT_HEAD;
3585 int font_text = MENU_INFO_FONT_TEXT;
3586 int font_foot = MENU_INFO_FONT_FOOT;
3587 int spacing_title = menu.headline1_spacing_info[info_mode];
3588 int spacing_head = menu.headline2_spacing_info[info_mode];
3589 int spacing_para = menu.paragraph_spacing_info[info_mode];
3590 int spacing_line = menu.line_spacing_info[info_mode];
3591 int xstep = getFontWidth(font_text);
3592 int ystep_title = getMenuTextStep(spacing_title, font_title);
3593 int ystep_head = getMenuTextStep(spacing_head, font_head);
3594 int ystep_para = getMenuTextStep(spacing_para, font_text);
3595 int ystep_line = getMenuTextStep(spacing_line, font_text);
3596 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3597 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3598 int xstart1 = mSX - SX + 2 * xstep;
3599 int xstart2 = mSX - SX + 18 * xstep;
3600 int xstart3 = mSX - SX + 28 * xstep;
3601 SDL_version sdl_version_compiled;
3602 const SDL_version *sdl_version_linked;
3603 int driver_name_len = 10;
3604 SDL_version sdl_version_linked_ext;
3605 const char *driver_name = NULL;
3607 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3609 FadeOut(REDRAW_FIELD);
3614 DrawTextSCentered(ystart, font_title, "Version Information:");
3615 ystart += ystep_title;
3617 DrawTextF(xstart1, ystart, font_head, "Name");
3618 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3619 ystart += ystep_line;
3621 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3623 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3624 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3625 ystart += ystep_line;
3627 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3628 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3629 ystart += ystep_line;
3633 DrawTextF(xstart1, ystart, font_head, "Version");
3634 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3635 ystart += ystep_line;
3638 DrawTextF(xstart1, ystart, font_head, "Platform");
3639 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3640 ystart += ystep_line;
3642 DrawTextF(xstart1, ystart, font_head, "Target");
3643 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3644 ystart += ystep_line;
3646 DrawTextF(xstart1, ystart, font_head, "Source date");
3647 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3648 ystart += ystep_para;
3650 DrawTextF(xstart1, ystart, font_head, "Library");
3651 DrawTextF(xstart2, ystart, font_head, "compiled");
3652 DrawTextF(xstart3, ystart, font_head, "linked");
3653 ystart += ystep_head;
3655 SDL_VERSION(&sdl_version_compiled);
3656 SDL_GetVersion(&sdl_version_linked_ext);
3657 sdl_version_linked = &sdl_version_linked_ext;
3659 DrawTextF(xstart1, ystart, font_text, "SDL");
3660 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3661 sdl_version_compiled.major,
3662 sdl_version_compiled.minor,
3663 sdl_version_compiled.patch);
3664 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3665 sdl_version_linked->major,
3666 sdl_version_linked->minor,
3667 sdl_version_linked->patch);
3668 ystart += ystep_line;
3670 SDL_IMAGE_VERSION(&sdl_version_compiled);
3671 sdl_version_linked = IMG_Linked_Version();
3673 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3674 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3675 sdl_version_compiled.major,
3676 sdl_version_compiled.minor,
3677 sdl_version_compiled.patch);
3678 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3679 sdl_version_linked->major,
3680 sdl_version_linked->minor,
3681 sdl_version_linked->patch);
3682 ystart += ystep_line;
3684 SDL_MIXER_VERSION(&sdl_version_compiled);
3685 sdl_version_linked = Mix_Linked_Version();
3687 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3688 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3689 sdl_version_compiled.major,
3690 sdl_version_compiled.minor,
3691 sdl_version_compiled.patch);
3692 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3693 sdl_version_linked->major,
3694 sdl_version_linked->minor,
3695 sdl_version_linked->patch);
3696 ystart += ystep_line;
3698 SDL_NET_VERSION(&sdl_version_compiled);
3699 sdl_version_linked = SDLNet_Linked_Version();
3701 DrawTextF(xstart1, ystart, font_text, "SDL_net");
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_para;
3712 DrawTextF(xstart1, ystart, font_head, "Driver");
3713 DrawTextF(xstart2, ystart, font_head, "Requested");
3714 DrawTextF(xstart3, ystart, font_head, "Used");
3715 ystart += ystep_head;
3717 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3719 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3720 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3721 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3722 ystart += ystep_line;
3724 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3726 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3727 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3728 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3730 DrawTextSCentered(ybottom, font_foot,
3731 "Press any key or button for info menu");
3733 FadeIn(REDRAW_FIELD);
3736 void HandleInfoScreen_Version(int button)
3738 if (button == MB_MENU_LEAVE)
3740 PlaySound(SND_MENU_ITEM_SELECTING);
3742 info_mode = INFO_MODE_MAIN;
3747 else if (button == MB_MENU_CHOICE)
3749 PlaySound(SND_MENU_ITEM_SELECTING);
3751 FadeMenuSoundsAndMusic();
3753 info_mode = INFO_MODE_MAIN;
3758 PlayMenuSoundIfLoop();
3762 static void DrawInfoScreen_LevelSet(void)
3764 struct TitleMessageInfo *tmi = &readme;
3765 char *filename = getLevelSetInfoFilename();
3766 char *title = "Level Set Information:";
3767 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3768 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3770 if (filename == NULL)
3772 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3777 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3779 FadeOut(REDRAW_FIELD);
3784 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3786 // if x position set to "-1", automatically determine by playfield width
3788 tmi->x = SXSIZE / 2;
3790 // if y position set to "-1", use static default value
3794 // if width set to "-1", automatically determine by playfield width
3795 if (tmi->width == -1)
3796 tmi->width = SXSIZE - 2 * TILEX;
3798 // if height set to "-1", automatically determine by playfield height
3799 if (tmi->height == -1)
3800 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3802 // if chars set to "-1", automatically determine by text and font width
3803 if (tmi->chars == -1)
3804 tmi->chars = tmi->width / getFontWidth(tmi->font);
3806 tmi->width = tmi->chars * getFontWidth(tmi->font);
3808 // if lines set to "-1", automatically determine by text and font height
3809 if (tmi->lines == -1)
3810 tmi->lines = tmi->height / getFontHeight(tmi->font);
3812 tmi->height = tmi->lines * getFontHeight(tmi->font);
3814 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3815 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3816 tmi->autowrap, tmi->centered, tmi->parse_comments);
3818 DrawTextSCentered(ybottom, FONT_TEXT_4,
3819 "Press any key or button for info menu");
3821 FadeIn(REDRAW_FIELD);
3824 static void HandleInfoScreen_LevelSet(int button)
3826 if (button == MB_MENU_LEAVE)
3828 PlaySound(SND_MENU_ITEM_SELECTING);
3830 info_mode = INFO_MODE_MAIN;
3835 else if (button == MB_MENU_CHOICE)
3837 PlaySound(SND_MENU_ITEM_SELECTING);
3839 FadeMenuSoundsAndMusic();
3841 info_mode = INFO_MODE_MAIN;
3846 PlayMenuSoundIfLoop();
3850 static void DrawInfoScreen(void)
3852 if (info_mode == INFO_MODE_TITLE)
3853 DrawInfoScreen_TitleScreen();
3854 else if (info_mode == INFO_MODE_ELEMENTS)
3855 DrawInfoScreen_Elements();
3856 else if (info_mode == INFO_MODE_MUSIC)
3857 DrawInfoScreen_Music();
3858 else if (info_mode == INFO_MODE_CREDITS)
3859 DrawInfoScreen_Credits();
3860 else if (info_mode == INFO_MODE_PROGRAM)
3861 DrawInfoScreen_Program();
3862 else if (info_mode == INFO_MODE_VERSION)
3863 DrawInfoScreen_Version();
3864 else if (info_mode == INFO_MODE_LEVELSET)
3865 DrawInfoScreen_LevelSet();
3867 DrawInfoScreen_Main();
3869 if (info_mode != INFO_MODE_MAIN &&
3870 info_mode != INFO_MODE_TITLE &&
3871 info_mode != INFO_MODE_MUSIC)
3872 PlayMenuSoundsAndMusic();
3875 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3877 if (info_mode == INFO_MODE_TITLE)
3878 HandleInfoScreen_TitleScreen(button);
3879 else if (info_mode == INFO_MODE_ELEMENTS)
3880 HandleInfoScreen_Elements(button);
3881 else if (info_mode == INFO_MODE_MUSIC)
3882 HandleInfoScreen_Music(button);
3883 else if (info_mode == INFO_MODE_CREDITS)
3884 HandleInfoScreen_Credits(button);
3885 else if (info_mode == INFO_MODE_PROGRAM)
3886 HandleInfoScreen_Program(button);
3887 else if (info_mode == INFO_MODE_VERSION)
3888 HandleInfoScreen_Version(button);
3889 else if (info_mode == INFO_MODE_LEVELSET)
3890 HandleInfoScreen_LevelSet(button);
3892 HandleInfoScreen_Main(mx, my, dx, dy, button);
3896 // ============================================================================
3897 // type name functions
3898 // ============================================================================
3900 void HandleTypeName(int newxpos, Key key)
3902 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3903 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3904 struct TextPosInfo *pos = mci->pos_input;
3905 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3906 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3907 static int xpos = 0;
3908 int font_nr = pos->font;
3909 int font_active_nr = FONT_ACTIVE(font_nr);
3910 int font_width = getFontWidth(font_active_nr);
3911 char key_char = getValidConfigValueChar(getCharFromKey(key));
3912 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3913 boolean is_active = TRUE;
3915 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3919 strcpy(last_player_name, setup.player_name);
3923 StartTextInput(startx, starty, pos->width, pos->height);
3925 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3927 setup.player_name[xpos] = key_char;
3928 setup.player_name[xpos + 1] = 0;
3932 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3936 setup.player_name[xpos] = 0;
3938 else if (key == KSYM_Return && xpos > 0)
3944 SetGameStatus(GAME_MODE_MAIN);
3946 else if (key == KSYM_Escape)
3948 strcpy(setup.player_name, last_player_name);
3952 SetGameStatus(GAME_MODE_MAIN);
3957 pos->width = (strlen(setup.player_name) + 1) * font_width;
3958 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3960 DrawText(startx, starty, setup.player_name, font_active_nr);
3961 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3965 pos->width = strlen(setup.player_name) * font_width;
3966 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3968 DrawText(startx, starty, setup.player_name, font_nr);
3975 // ============================================================================
3976 // tree menu functions
3977 // ============================================================================
3979 static void DrawChooseTree(TreeInfo **ti_ptr)
3981 int fade_mask = REDRAW_FIELD;
3984 fade_mask = REDRAW_ALL;
3986 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3988 SetGameStatus(GAME_MODE_MAIN);
3997 FreeScreenGadgets();
3998 CreateScreenGadgets();
4002 // needed if different viewport properties defined for choosing level (set)
4003 ChangeViewportPropertiesIfNeeded();
4005 if (game_status == GAME_MODE_LEVELNR)
4006 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4007 else if (game_status == GAME_MODE_LEVELS)
4008 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4012 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4014 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4015 MapScreenTreeGadgets(*ti_ptr);
4017 DrawMaskedBorder(fade_mask);
4022 static void drawChooseTreeList(int first_entry, int num_page_entries,
4026 char *title_string = NULL;
4027 int yoffset_sets = MENU_TITLE1_YPOS;
4028 int yoffset_setup = 16;
4029 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4030 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4032 title_string = ti->infotext;
4034 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4036 clearMenuListArea();
4038 for (i = 0; i < num_page_entries; i++)
4040 TreeInfo *node, *node_first;
4041 int entry_pos = first_entry + i;
4042 int xpos = MENU_SCREEN_START_XPOS;
4043 int ypos = MENU_SCREEN_START_YPOS + i;
4044 int startx = mSX + xpos * 32;
4045 int starty = mSY + ypos * 32;
4046 int font_nr = FONT_TEXT_1;
4047 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4048 int startx_text = startx + font_xoffset;
4049 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4050 int text_size = startx_scrollbar - startx_text;
4051 int max_buffer_len = text_size / getFontWidth(font_nr);
4052 char buffer[max_buffer_len + 1];
4054 node_first = getTreeInfoFirstGroupEntry(ti);
4055 node = getTreeInfoFromPos(node_first, entry_pos);
4057 strncpy(buffer, node->name, max_buffer_len);
4058 buffer[max_buffer_len] = '\0';
4060 DrawText(startx, starty, buffer, font_nr + node->color);
4062 if (node->parent_link)
4063 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4064 else if (node->level_group)
4065 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4067 initCursor(i, IMG_MENU_BUTTON);
4070 redraw_mask |= REDRAW_FIELD;
4073 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4075 TreeInfo *node, *node_first;
4076 int x, last_redraw_mask = redraw_mask;
4077 int ypos = MENU_TITLE2_YPOS;
4078 int font_nr = FONT_TITLE_2;
4080 if (ti->type == TREE_TYPE_LEVEL_NR)
4081 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4083 if (ti->type != TREE_TYPE_LEVEL_DIR)
4086 node_first = getTreeInfoFirstGroupEntry(ti);
4087 node = getTreeInfoFromPos(node_first, entry_pos);
4089 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4091 if (node->parent_link)
4092 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4093 node->node_parent->name);
4094 else if (node->level_group)
4095 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4097 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4098 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4099 node->levels, (node->levels > 1 ? "levels" : "level"),
4102 // let BackToFront() redraw only what is needed
4103 redraw_mask = last_redraw_mask;
4104 for (x = 0; x < SCR_FIELDX; x++)
4105 MarkTileDirty(x, 1);
4108 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4111 TreeInfo *ti = *ti_ptr;
4113 int y = ti->cl_cursor;
4114 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4115 int num_entries = numTreeInfoInGroup(ti);
4116 int num_page_entries;
4117 boolean position_set_by_scrollbar = (dx == 999);
4119 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4120 num_page_entries = num_entries;
4122 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4124 if (button == MB_MENU_INITIALIZE)
4126 int num_entries = numTreeInfoInGroup(ti);
4127 int entry_pos = posTreeInfo(ti);
4129 if (ti->cl_first == -1)
4131 // only on initialization
4132 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4133 ti->cl_cursor = entry_pos - ti->cl_first;
4135 else if (ti->cl_cursor >= num_page_entries ||
4136 (num_entries > num_page_entries &&
4137 num_entries - ti->cl_first < num_page_entries))
4139 // only after change of list size (by custom graphic configuration)
4140 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4141 ti->cl_cursor = entry_pos - ti->cl_first;
4144 if (position_set_by_scrollbar)
4147 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4150 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4151 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4152 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4156 else if (button == MB_MENU_LEAVE)
4160 PlaySound(SND_MENU_ITEM_SELECTING);
4162 if (ti->node_parent)
4164 *ti_ptr = ti->node_parent;
4165 DrawChooseTree(ti_ptr);
4167 else if (game_status == GAME_MODE_SETUP)
4169 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4170 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4171 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4173 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4174 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4175 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4176 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4177 execSetupGraphics();
4178 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4179 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4180 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4182 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4183 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4184 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4185 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4186 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4187 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4188 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4189 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4196 if (game_status == GAME_MODE_LEVELNR)
4198 int new_level_nr = atoi(level_number_current->identifier);
4200 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4203 SetGameStatus(GAME_MODE_MAIN);
4211 if (mx || my) // mouse input
4213 x = (mx - mSX) / 32;
4214 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4216 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4218 // move cursor instead of scrolling when already at start/end of list
4219 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4221 else if (dy == +1 * SCROLL_LINE &&
4222 ti->cl_first + num_page_entries == num_entries)
4225 // handle scrolling screen one line or page
4226 if (ti->cl_cursor + dy < 0 ||
4227 ti->cl_cursor + dy > num_page_entries - 1)
4229 boolean redraw = FALSE;
4231 if (ABS(dy) == SCROLL_PAGE)
4232 step = num_page_entries - 1;
4234 if (dy < 0 && ti->cl_first > 0)
4236 // scroll page/line up
4238 ti->cl_first -= step;
4239 if (ti->cl_first < 0)
4244 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4246 // scroll page/line down
4248 ti->cl_first += step;
4249 if (ti->cl_first + num_page_entries > num_entries)
4250 ti->cl_first = MAX(0, num_entries - num_page_entries);
4257 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4258 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4259 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4261 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4268 // handle moving cursor one line
4269 y = ti->cl_cursor + dy;
4274 TreeInfo *node_first, *node_cursor;
4275 int entry_pos = ti->cl_first + y;
4277 node_first = getTreeInfoFirstGroupEntry(ti);
4278 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4280 if (node_cursor->node_group)
4284 PlaySound(SND_MENU_ITEM_SELECTING);
4286 node_cursor->cl_first = ti->cl_first;
4287 node_cursor->cl_cursor = ti->cl_cursor;
4288 *ti_ptr = node_cursor->node_group;
4289 DrawChooseTree(ti_ptr);
4294 else if (dx == -1 && ti->node_parent)
4298 PlaySound(SND_MENU_ITEM_SELECTING);
4300 *ti_ptr = ti->node_parent;
4301 DrawChooseTree(ti_ptr);
4306 if (!anyScrollbarGadgetActive() &&
4307 IN_VIS_MENU(x, y) &&
4308 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4309 y >= 0 && y < num_page_entries)
4313 if (y != ti->cl_cursor)
4315 PlaySound(SND_MENU_ITEM_ACTIVATING);
4317 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4318 drawChooseTreeCursor(y, TRUE);
4319 drawChooseTreeInfo(ti->cl_first + y, ti);
4325 if (game_status == GAME_MODE_SETUP)
4327 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4328 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4329 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4331 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4332 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4333 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4334 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4335 execSetupGraphics();
4336 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4337 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4338 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4340 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4341 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4342 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4343 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4344 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4345 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4346 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4347 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4356 TreeInfo *node_first, *node_cursor;
4357 int entry_pos = ti->cl_first + y;
4359 PlaySound(SND_MENU_ITEM_SELECTING);
4361 node_first = getTreeInfoFirstGroupEntry(ti);
4362 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4364 if (node_cursor->node_group)
4368 node_cursor->cl_first = ti->cl_first;
4369 node_cursor->cl_cursor = ti->cl_cursor;
4370 *ti_ptr = node_cursor->node_group;
4371 DrawChooseTree(ti_ptr);
4373 else if (node_cursor->parent_link)
4377 *ti_ptr = node_cursor->node_parent;
4378 DrawChooseTree(ti_ptr);
4384 node_cursor->cl_first = ti->cl_first;
4385 node_cursor->cl_cursor = ti->cl_cursor;
4386 *ti_ptr = node_cursor;
4388 if (ti->type == TREE_TYPE_LEVEL_DIR)
4390 LoadLevelSetup_SeriesInfo();
4392 SaveLevelSetup_LastSeries();
4393 SaveLevelSetup_SeriesInfo();
4397 if (game_status == GAME_MODE_SETUP)
4399 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4400 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4401 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4403 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4404 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4405 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4406 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4407 execSetupGraphics();
4408 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4409 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4410 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4412 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4413 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4414 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4415 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4416 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4417 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4418 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4419 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4426 if (game_status == GAME_MODE_LEVELNR)
4428 int new_level_nr = atoi(level_number_current->identifier);
4430 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4433 SetGameStatus(GAME_MODE_MAIN);
4442 void DrawChooseLevelSet(void)
4444 FadeMenuSoundsAndMusic();
4446 DrawChooseTree(&leveldir_current);
4448 PlayMenuSoundsAndMusic();
4451 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4453 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4456 void DrawChooseLevelNr(void)
4460 FadeMenuSoundsAndMusic();
4462 if (level_number != NULL)
4464 freeTreeInfo(level_number);
4466 level_number = NULL;
4469 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4471 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4472 char identifier[32], name[32];
4475 // temporarily load level info to get level name
4476 LoadLevelInfoOnly(i);
4478 ti->node_top = &level_number;
4479 ti->sort_priority = 10000 + value;
4480 ti->color = (level.no_level_file ? FC_BLUE :
4481 LevelStats_getSolved(i) ? FC_GREEN :
4482 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4484 snprintf(identifier, sizeof(identifier), "%d", value);
4485 snprintf(name, sizeof(name), "%03d: %s", value,
4486 (level.no_level_file ? "(no file)" : level.name));
4488 setString(&ti->identifier, identifier);
4489 setString(&ti->name, name);
4490 setString(&ti->name_sorting, name);
4492 pushTreeInfo(&level_number, ti);
4495 // sort level number values to start with lowest level number
4496 sortTreeInfo(&level_number);
4498 // set current level number to current level number
4499 level_number_current =
4500 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4502 // if that also fails, set current level number to first available level
4503 if (level_number_current == NULL)
4504 level_number_current = level_number;
4506 DrawChooseTree(&level_number_current);
4508 PlayMenuSoundsAndMusic();
4511 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4513 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4516 void DrawHallOfFame(int level_nr, int highlight_position)
4518 int fade_mask = REDRAW_FIELD;
4521 fade_mask = REDRAW_ALL;
4524 FadeMenuSoundsAndMusic();
4526 // (this is needed when called from GameEnd() after winning a game)
4527 KeyboardAutoRepeatOn();
4529 // (this is needed when called from GameEnd() after winning a game)
4530 SetDrawDeactivationMask(REDRAW_NONE);
4531 SetDrawBackgroundMask(REDRAW_FIELD);
4533 if (highlight_position < 0)
4534 LoadScore(level_nr);
4536 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4538 FadeSetEnterScreen();
4542 // needed if different viewport properties defined for scores
4543 ChangeViewportPropertiesIfNeeded();
4545 PlayMenuSoundsAndMusic();
4547 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4549 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4551 DrawMaskedBorder(fade_mask);
4556 static void drawHallOfFameList(int level_nr, int first_entry,
4557 int highlight_position)
4561 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4564 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4565 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4566 "HighScores of Level %d", level_nr);
4568 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4570 int entry = first_entry + i;
4571 boolean active = (entry == highlight_position);
4572 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4573 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4574 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4575 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4576 int dxoff = getFontDrawOffsetX(font_nr1);
4577 int dx1 = 3 * getFontWidth(font_nr1);
4578 int dx2 = dx1 + getFontWidth(font_nr1);
4579 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4580 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4581 int sy = mSY + 64 + i * 32;
4583 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4584 DrawText(mSX + dx1, sy, ".", font_nr1);
4586 for (j = 0; j < num_dots; j++)
4587 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4589 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4590 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4592 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4595 redraw_mask |= REDRAW_FIELD;
4598 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4600 static int level_nr = 0;
4601 static int first_entry = 0;
4602 static int highlight_position = 0;
4603 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4605 if (button == MB_MENU_INITIALIZE)
4609 highlight_position = my;
4611 drawHallOfFameList(level_nr, first_entry, highlight_position);
4616 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
4617 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4621 if (first_entry > 0)
4623 first_entry -= step;
4624 if (first_entry < 0)
4627 drawHallOfFameList(level_nr, first_entry, highlight_position);
4632 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4634 first_entry += step;
4635 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4636 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4638 drawHallOfFameList(level_nr, first_entry, highlight_position);
4641 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4643 PlaySound(SND_MENU_ITEM_SELECTING);
4645 FadeSound(SND_BACKGROUND_SCORES);
4647 if (game_status_last_screen == GAME_MODE_PLAYING &&
4648 setup.auto_play_next_level && setup.increment_levels &&
4649 level_nr < leveldir_current->last_level &&
4652 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4656 SetGameStatus(GAME_MODE_MAIN);
4662 if (game_status == GAME_MODE_SCORES)
4663 PlayMenuSoundIfLoop();
4667 // ============================================================================
4668 // setup screen functions
4669 // ============================================================================
4671 static struct TokenInfo *setup_info;
4672 static int num_setup_info; // number of setup entries shown on screen
4673 static int max_setup_info; // total number of setup entries in list
4675 static char *window_size_text;
4676 static char *scaling_type_text;
4677 static char *rendering_mode_text;
4678 static char *vsync_mode_text;
4679 static char *scroll_delay_text;
4680 static char *snapshot_mode_text;
4681 static char *game_speed_text;
4682 static char *network_server_text;
4683 static char *graphics_set_name;
4684 static char *sounds_set_name;
4685 static char *music_set_name;
4686 static char *volume_simple_text;
4687 static char *volume_loops_text;
4688 static char *volume_music_text;
4689 static char *touch_controls_text;
4690 static char *move_distance_text;
4691 static char *drop_distance_text;
4692 static char *transparency_text;
4693 static char *grid_size_text[2][2];
4695 static void execSetupMain(void)
4697 setup_mode = SETUP_MODE_MAIN;
4702 static void execSetupGame_setGameSpeeds(boolean update_value)
4704 if (setup.game_speed_extended)
4706 game_speeds_list = game_speeds_list_extended;
4707 game_speeds = game_speeds_extended;
4711 game_speeds_list = game_speeds_list_normal;
4712 game_speeds = game_speeds_normal;
4715 if (game_speeds == NULL)
4719 for (i = 0; game_speeds_list[i].value != -1; i++)
4721 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4722 char identifier[32], name[32];
4723 int value = game_speeds_list[i].value;
4724 char *text = game_speeds_list[i].text;
4726 ti->node_top = &game_speeds;
4727 ti->sort_priority = 10000 - value;
4729 sprintf(identifier, "%d", value);
4730 sprintf(name, "%s", text);
4732 setString(&ti->identifier, identifier);
4733 setString(&ti->name, name);
4734 setString(&ti->name_sorting, name);
4735 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4737 pushTreeInfo(&game_speeds, ti);
4740 // sort game speed values to start with slowest game speed
4741 sortTreeInfo(&game_speeds);
4743 update_value = TRUE;
4748 // set current game speed to configured game speed value
4749 game_speed_current =
4750 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4752 // if that fails, set current game speed to reliable default value
4753 if (game_speed_current == NULL)
4754 game_speed_current =
4755 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4757 // if that also fails, set current game speed to first available speed
4758 if (game_speed_current == NULL)
4759 game_speed_current = game_speeds;
4761 if (setup.game_speed_extended)
4762 game_speeds_extended = game_speeds;
4764 game_speeds_normal = game_speeds;
4767 setup.game_frame_delay = atoi(game_speed_current->identifier);
4769 // needed for displaying game speed text instead of identifier
4770 game_speed_text = game_speed_current->name;
4773 static void execSetupGame_setScrollDelays(void)
4775 if (scroll_delays == NULL)
4779 for (i = 0; scroll_delays_list[i].value != -1; i++)
4781 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4782 char identifier[32], name[32];
4783 int value = scroll_delays_list[i].value;
4784 char *text = scroll_delays_list[i].text;
4786 ti->node_top = &scroll_delays;
4787 ti->sort_priority = value;
4789 sprintf(identifier, "%d", value);
4790 sprintf(name, "%s", text);
4792 setString(&ti->identifier, identifier);
4793 setString(&ti->name, name);
4794 setString(&ti->name_sorting, name);
4795 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4797 pushTreeInfo(&scroll_delays, ti);
4800 // sort scroll delay values to start with lowest scroll delay value
4801 sortTreeInfo(&scroll_delays);
4803 // set current scroll delay value to configured scroll delay value
4804 scroll_delay_current =
4805 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4807 // if that fails, set current scroll delay to reliable default value
4808 if (scroll_delay_current == NULL)
4809 scroll_delay_current =
4810 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4812 // if that also fails, set current scroll delay to first available value
4813 if (scroll_delay_current == NULL)
4814 scroll_delay_current = scroll_delays;
4817 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4819 // needed for displaying scroll delay text instead of identifier
4820 scroll_delay_text = scroll_delay_current->name;
4823 static void execSetupGame_setSnapshotModes(void)
4825 if (snapshot_modes == NULL)
4829 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4831 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4832 char identifier[32], name[32];
4833 char *value = snapshot_modes_list[i].value;
4834 char *text = snapshot_modes_list[i].text;
4836 ti->node_top = &snapshot_modes;
4837 ti->sort_priority = i;
4839 sprintf(identifier, "%s", value);
4840 sprintf(name, "%s", text);
4842 setString(&ti->identifier, identifier);
4843 setString(&ti->name, name);
4844 setString(&ti->name_sorting, name);
4845 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4847 pushTreeInfo(&snapshot_modes, ti);
4850 // sort snapshot mode values to start with lowest snapshot mode value
4851 sortTreeInfo(&snapshot_modes);
4853 // set current snapshot mode value to configured snapshot mode value
4854 snapshot_mode_current =
4855 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4857 // if that fails, set current snapshot mode to reliable default value
4858 if (snapshot_mode_current == NULL)
4859 snapshot_mode_current =
4860 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4862 // if that also fails, set current snapshot mode to first available value
4863 if (snapshot_mode_current == NULL)
4864 snapshot_mode_current = snapshot_modes;
4867 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4869 // needed for displaying snapshot mode text instead of identifier
4870 snapshot_mode_text = snapshot_mode_current->name;
4873 static void execSetupGame_setNetworkServerText(void)
4875 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
4877 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
4881 strncpy(network_server_hostname, setup.network_server_hostname,
4882 MAX_SETUP_TEXT_INPUT_LEN);
4883 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
4886 // needed for displaying network server text instead of identifier
4887 network_server_text = network_server_hostname;
4890 static void execSetupGame(void)
4892 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
4894 execSetupGame_setGameSpeeds(FALSE);
4895 execSetupGame_setScrollDelays();
4896 execSetupGame_setSnapshotModes();
4898 execSetupGame_setNetworkServerText();
4900 setup_mode = SETUP_MODE_GAME;
4904 // check if vsync needs to be disabled for this game speed to work
4905 if (check_vsync_mode)
4906 DisableVsyncIfNeeded();
4909 static void execSetupChooseGameSpeed(void)
4911 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4916 static void execSetupChooseScrollDelay(void)
4918 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4923 static void execSetupChooseSnapshotMode(void)
4925 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4930 static void execSetupEditor(void)
4932 setup_mode = SETUP_MODE_EDITOR;
4937 static void execSetupGraphics_setWindowSizes(boolean update_list)
4939 if (window_sizes != NULL && update_list)
4941 freeTreeInfo(window_sizes);
4943 window_sizes = NULL;
4946 if (window_sizes == NULL)
4948 boolean current_window_size_found = FALSE;
4951 for (i = 0; window_sizes_list[i].value != -1; i++)
4953 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4954 char identifier[32], name[32];
4955 int value = window_sizes_list[i].value;
4956 char *text = window_sizes_list[i].text;
4958 ti->node_top = &window_sizes;
4959 ti->sort_priority = value;
4961 sprintf(identifier, "%d", value);
4962 sprintf(name, "%s", text);
4964 setString(&ti->identifier, identifier);
4965 setString(&ti->name, name);
4966 setString(&ti->name_sorting, name);
4967 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4969 pushTreeInfo(&window_sizes, ti);
4971 if (value == setup.window_scaling_percent)
4972 current_window_size_found = TRUE;
4975 if (!current_window_size_found)
4977 // add entry for non-preset window scaling value
4979 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4980 char identifier[32], name[32];
4981 int value = setup.window_scaling_percent;
4983 ti->node_top = &window_sizes;
4984 ti->sort_priority = value;
4986 sprintf(identifier, "%d", value);
4987 sprintf(name, "%d %% (Current)", value);
4989 setString(&ti->identifier, identifier);
4990 setString(&ti->name, name);
4991 setString(&ti->name_sorting, name);
4992 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4994 pushTreeInfo(&window_sizes, ti);
4997 // sort window size values to start with lowest window size value
4998 sortTreeInfo(&window_sizes);
5000 // set current window size value to configured window size value
5001 window_size_current =
5002 getTreeInfoFromIdentifier(window_sizes,
5003 i_to_a(setup.window_scaling_percent));
5005 // if that fails, set current window size to reliable default value
5006 if (window_size_current == NULL)
5007 window_size_current =
5008 getTreeInfoFromIdentifier(window_sizes,
5009 i_to_a(STD_WINDOW_SCALING_PERCENT));
5011 // if that also fails, set current window size to first available value
5012 if (window_size_current == NULL)
5013 window_size_current = window_sizes;
5016 setup.window_scaling_percent = atoi(window_size_current->identifier);
5018 // needed for displaying window size text instead of identifier
5019 window_size_text = window_size_current->name;
5022 static void execSetupGraphics_setScalingTypes(void)
5024 if (scaling_types == NULL)
5028 for (i = 0; scaling_types_list[i].value != NULL; i++)
5030 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5031 char identifier[32], name[32];
5032 char *value = scaling_types_list[i].value;
5033 char *text = scaling_types_list[i].text;
5035 ti->node_top = &scaling_types;
5036 ti->sort_priority = i;
5038 sprintf(identifier, "%s", value);
5039 sprintf(name, "%s", text);
5041 setString(&ti->identifier, identifier);
5042 setString(&ti->name, name);
5043 setString(&ti->name_sorting, name);
5044 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5046 pushTreeInfo(&scaling_types, ti);
5049 // sort scaling type values to start with lowest scaling type value
5050 sortTreeInfo(&scaling_types);
5052 // set current scaling type value to configured scaling type value
5053 scaling_type_current =
5054 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5056 // if that fails, set current scaling type to reliable default value
5057 if (scaling_type_current == NULL)
5058 scaling_type_current =
5059 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5061 // if that also fails, set current scaling type to first available value
5062 if (scaling_type_current == NULL)
5063 scaling_type_current = scaling_types;
5066 setup.window_scaling_quality = scaling_type_current->identifier;
5068 // needed for displaying scaling type text instead of identifier
5069 scaling_type_text = scaling_type_current->name;
5072 static void execSetupGraphics_setRenderingModes(void)
5074 if (rendering_modes == NULL)
5078 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5080 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5081 char identifier[32], name[32];
5082 char *value = rendering_modes_list[i].value;
5083 char *text = rendering_modes_list[i].text;
5085 ti->node_top = &rendering_modes;
5086 ti->sort_priority = i;
5088 sprintf(identifier, "%s", value);
5089 sprintf(name, "%s", text);
5091 setString(&ti->identifier, identifier);
5092 setString(&ti->name, name);
5093 setString(&ti->name_sorting, name);
5094 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5096 pushTreeInfo(&rendering_modes, ti);
5099 // sort rendering mode values to start with lowest rendering mode value
5100 sortTreeInfo(&rendering_modes);
5102 // set current rendering mode value to configured rendering mode value
5103 rendering_mode_current =
5104 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5106 // if that fails, set current rendering mode to reliable default value
5107 if (rendering_mode_current == NULL)
5108 rendering_mode_current =
5109 getTreeInfoFromIdentifier(rendering_modes,
5110 STR_SPECIAL_RENDERING_DEFAULT);
5112 // if that also fails, set current rendering mode to first available one
5113 if (rendering_mode_current == NULL)
5114 rendering_mode_current = rendering_modes;
5117 setup.screen_rendering_mode = rendering_mode_current->identifier;
5119 // needed for displaying rendering mode text instead of identifier
5120 rendering_mode_text = rendering_mode_current->name;
5123 static void execSetupGraphics_setVsyncModes(boolean update_value)
5125 if (vsync_modes == NULL)
5129 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5131 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5132 char identifier[32], name[32];
5133 char *value = vsync_modes_list[i].value;
5134 char *text = vsync_modes_list[i].text;
5136 ti->node_top = &vsync_modes;
5137 ti->sort_priority = i;
5139 sprintf(identifier, "%s", value);
5140 sprintf(name, "%s", text);
5142 setString(&ti->identifier, identifier);
5143 setString(&ti->name, name);
5144 setString(&ti->name_sorting, name);
5145 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5147 pushTreeInfo(&vsync_modes, ti);
5150 // sort vsync mode values to start with lowest vsync mode value
5151 sortTreeInfo(&vsync_modes);
5153 update_value = TRUE;
5158 // set current vsync mode value to configured vsync mode value
5159 vsync_mode_current =
5160 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5162 // if that fails, set current vsync mode to reliable default value
5163 if (vsync_mode_current == NULL)
5164 vsync_mode_current =
5165 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5167 // if that also fails, set current vsync mode to first available one
5168 if (vsync_mode_current == NULL)
5169 vsync_mode_current = vsync_modes;
5172 setup.vsync_mode = vsync_mode_current->identifier;
5174 // needed for displaying vsync mode text instead of identifier
5175 vsync_mode_text = vsync_mode_current->name;
5178 static void execSetupGraphics(void)
5180 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5182 // update "setup.window_scaling_percent" from list selection
5183 // (in this case, window scaling was changed on setup screen)
5184 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5185 execSetupGraphics_setWindowSizes(FALSE);
5187 // update list selection from "setup.window_scaling_percent"
5188 // (window scaling may have changed by resizing the window)
5189 execSetupGraphics_setWindowSizes(TRUE);
5191 execSetupGraphics_setScalingTypes();
5192 execSetupGraphics_setRenderingModes();
5193 execSetupGraphics_setVsyncModes(FALSE);
5195 setup_mode = SETUP_MODE_GRAPHICS;
5199 // check if game speed is high enough for 60 Hz vsync to work
5200 if (check_game_speed)
5201 ModifyGameSpeedIfNeeded();
5203 // window scaling may have changed at this point
5204 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5206 // window scaling quality may have changed at this point
5207 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5208 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5210 // screen rendering mode may have changed at this point
5211 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5213 // screen vsync mode may have changed at this point
5214 SDLSetScreenVsyncMode(setup.vsync_mode);
5217 static void execSetupChooseWindowSize(void)
5219 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5224 static void execSetupChooseScalingType(void)
5226 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5231 static void execSetupChooseRenderingMode(void)
5233 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5238 static void execSetupChooseVsyncMode(void)
5240 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5245 static void execSetupChooseVolumeSimple(void)
5247 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5252 static void execSetupChooseVolumeLoops(void)
5254 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5259 static void execSetupChooseVolumeMusic(void)
5261 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5266 static void execSetupSound(void)
5268 if (volumes_simple == NULL)
5270 boolean current_volume_simple_found = FALSE;
5273 for (i = 0; volumes_list[i].value != -1; i++)
5275 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5276 char identifier[32], name[32];
5277 int value = volumes_list[i].value;
5278 char *text = volumes_list[i].text;
5280 ti->node_top = &volumes_simple;
5281 ti->sort_priority = value;
5283 sprintf(identifier, "%d", value);
5284 sprintf(name, "%s", text);
5286 setString(&ti->identifier, identifier);
5287 setString(&ti->name, name);
5288 setString(&ti->name_sorting, name);
5289 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5291 pushTreeInfo(&volumes_simple, ti);
5293 if (value == setup.volume_simple)
5294 current_volume_simple_found = TRUE;
5297 if (!current_volume_simple_found)
5299 // add entry for non-preset volume value
5301 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5302 char identifier[32], name[32];
5303 int value = setup.volume_simple;
5305 ti->node_top = &volumes_simple;
5306 ti->sort_priority = value;
5308 sprintf(identifier, "%d", value);
5309 sprintf(name, "%d %% (Current)", value);
5311 setString(&ti->identifier, identifier);
5312 setString(&ti->name, name);
5313 setString(&ti->name_sorting, name);
5314 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5316 pushTreeInfo(&volumes_simple, ti);
5319 // sort volume values to start with lowest volume value
5320 sortTreeInfo(&volumes_simple);
5322 // set current volume value to configured volume value
5323 volume_simple_current =
5324 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5326 // if that fails, set current volume to reliable default value
5327 if (volume_simple_current == NULL)
5328 volume_simple_current =
5329 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5331 // if that also fails, set current volume to first available value
5332 if (volume_simple_current == NULL)
5333 volume_simple_current = volumes_simple;
5336 if (volumes_loops == NULL)
5338 boolean current_volume_loops_found = FALSE;
5341 for (i = 0; volumes_list[i].value != -1; i++)
5343 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5344 char identifier[32], name[32];
5345 int value = volumes_list[i].value;
5346 char *text = volumes_list[i].text;
5348 ti->node_top = &volumes_loops;
5349 ti->sort_priority = value;
5351 sprintf(identifier, "%d", value);
5352 sprintf(name, "%s", text);
5354 setString(&ti->identifier, identifier);
5355 setString(&ti->name, name);
5356 setString(&ti->name_sorting, name);
5357 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5359 pushTreeInfo(&volumes_loops, ti);
5361 if (value == setup.volume_loops)
5362 current_volume_loops_found = TRUE;
5365 if (!current_volume_loops_found)
5367 // add entry for non-preset volume value
5369 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5370 char identifier[32], name[32];
5371 int value = setup.volume_loops;
5373 ti->node_top = &volumes_loops;
5374 ti->sort_priority = value;
5376 sprintf(identifier, "%d", value);
5377 sprintf(name, "%d %% (Current)", value);
5379 setString(&ti->identifier, identifier);
5380 setString(&ti->name, name);
5381 setString(&ti->name_sorting, name);
5382 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5384 pushTreeInfo(&volumes_loops, ti);
5387 // sort volume values to start with lowest volume value
5388 sortTreeInfo(&volumes_loops);
5390 // set current volume value to configured volume value
5391 volume_loops_current =
5392 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5394 // if that fails, set current volume to reliable default value
5395 if (volume_loops_current == NULL)
5396 volume_loops_current =
5397 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5399 // if that also fails, set current volume to first available value
5400 if (volume_loops_current == NULL)
5401 volume_loops_current = volumes_loops;
5404 if (volumes_music == NULL)
5406 boolean current_volume_music_found = FALSE;
5409 for (i = 0; volumes_list[i].value != -1; i++)
5411 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5412 char identifier[32], name[32];
5413 int value = volumes_list[i].value;
5414 char *text = volumes_list[i].text;
5416 ti->node_top = &volumes_music;
5417 ti->sort_priority = value;
5419 sprintf(identifier, "%d", value);
5420 sprintf(name, "%s", text);
5422 setString(&ti->identifier, identifier);
5423 setString(&ti->name, name);
5424 setString(&ti->name_sorting, name);
5425 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5427 pushTreeInfo(&volumes_music, ti);
5429 if (value == setup.volume_music)
5430 current_volume_music_found = TRUE;
5433 if (!current_volume_music_found)
5435 // add entry for non-preset volume value
5437 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5438 char identifier[32], name[32];
5439 int value = setup.volume_music;
5441 ti->node_top = &volumes_music;
5442 ti->sort_priority = value;
5444 sprintf(identifier, "%d", value);
5445 sprintf(name, "%d %% (Current)", value);
5447 setString(&ti->identifier, identifier);
5448 setString(&ti->name, name);
5449 setString(&ti->name_sorting, name);
5450 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5452 pushTreeInfo(&volumes_music, ti);
5455 // sort volume values to start with lowest volume value
5456 sortTreeInfo(&volumes_music);
5458 // set current volume value to configured volume value
5459 volume_music_current =
5460 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5462 // if that fails, set current volume to reliable default value
5463 if (volume_music_current == NULL)
5464 volume_music_current =
5465 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5467 // if that also fails, set current volume to first available value
5468 if (volume_music_current == NULL)
5469 volume_music_current = volumes_music;
5472 setup.volume_simple = atoi(volume_simple_current->identifier);
5473 setup.volume_loops = atoi(volume_loops_current->identifier);
5474 setup.volume_music = atoi(volume_music_current->identifier);
5476 // needed for displaying volume text instead of identifier
5477 volume_simple_text = volume_simple_current->name;
5478 volume_loops_text = volume_loops_current->name;
5479 volume_music_text = volume_music_current->name;
5481 setup_mode = SETUP_MODE_SOUND;
5486 static void execSetupChooseTouchControls(void)
5488 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5493 static void execSetupChooseMoveDistance(void)
5495 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5500 static void execSetupChooseDropDistance(void)
5502 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5507 static void execSetupChooseTransparency(void)
5509 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5514 static void execSetupChooseGridXSize_0(void)
5516 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5521 static void execSetupChooseGridYSize_0(void)
5523 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5528 static void execSetupChooseGridXSize_1(void)
5530 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5535 static void execSetupChooseGridYSize_1(void)
5537 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5542 static void execSetupConfigureVirtualButtons(void)
5544 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5546 ConfigureVirtualButtons();
5548 setup_mode = SETUP_MODE_TOUCH;
5553 static void execSetupTouch(void)
5557 if (touch_controls == NULL)
5559 for (i = 0; touch_controls_list[i].value != NULL; i++)
5561 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5562 char identifier[32], name[32];
5563 char *value = touch_controls_list[i].value;
5564 char *text = touch_controls_list[i].text;
5566 ti->node_top = &touch_controls;
5567 ti->sort_priority = i;
5569 sprintf(identifier, "%s", value);
5570 sprintf(name, "%s", text);
5572 setString(&ti->identifier, identifier);
5573 setString(&ti->name, name);
5574 setString(&ti->name_sorting, name);
5575 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5577 pushTreeInfo(&touch_controls, ti);
5580 // sort touch control values to start with lowest touch control value
5581 sortTreeInfo(&touch_controls);
5583 // set current touch control value to configured touch control value
5584 touch_control_current =
5585 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5587 // if that fails, set current touch control to reliable default value
5588 if (touch_control_current == NULL)
5589 touch_control_current =
5590 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5592 // if that also fails, set current touch control to first available value
5593 if (touch_control_current == NULL)
5594 touch_control_current = touch_controls;
5597 if (move_distances == NULL)
5599 for (i = 0; distances_list[i].value != -1; i++)
5601 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5602 char identifier[32], name[32];
5603 int value = distances_list[i].value;
5604 char *text = distances_list[i].text;
5606 ti->node_top = &move_distances;
5607 ti->sort_priority = value;
5609 sprintf(identifier, "%d", value);
5610 sprintf(name, "%s", text);
5612 setString(&ti->identifier, identifier);
5613 setString(&ti->name, name);
5614 setString(&ti->name_sorting, name);
5615 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5617 pushTreeInfo(&move_distances, ti);
5620 // sort distance values to start with lowest distance value
5621 sortTreeInfo(&move_distances);
5623 // set current distance value to configured distance value
5624 move_distance_current =
5625 getTreeInfoFromIdentifier(move_distances,
5626 i_to_a(setup.touch.move_distance));
5628 // if that fails, set current distance to reliable default value
5629 if (move_distance_current == NULL)
5630 move_distance_current =
5631 getTreeInfoFromIdentifier(move_distances,
5632 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5634 // if that also fails, set current distance to first available value
5635 if (move_distance_current == NULL)
5636 move_distance_current = move_distances;
5639 if (drop_distances == NULL)
5641 for (i = 0; distances_list[i].value != -1; i++)
5643 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5644 char identifier[32], name[32];
5645 int value = distances_list[i].value;
5646 char *text = distances_list[i].text;
5648 ti->node_top = &drop_distances;
5649 ti->sort_priority = value;
5651 sprintf(identifier, "%d", value);
5652 sprintf(name, "%s", text);
5654 setString(&ti->identifier, identifier);
5655 setString(&ti->name, name);
5656 setString(&ti->name_sorting, name);
5657 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5659 pushTreeInfo(&drop_distances, ti);
5662 // sort distance values to start with lowest distance value
5663 sortTreeInfo(&drop_distances);
5665 // set current distance value to configured distance value
5666 drop_distance_current =
5667 getTreeInfoFromIdentifier(drop_distances,
5668 i_to_a(setup.touch.drop_distance));
5670 // if that fails, set current distance to reliable default value
5671 if (drop_distance_current == NULL)
5672 drop_distance_current =
5673 getTreeInfoFromIdentifier(drop_distances,
5674 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5676 // if that also fails, set current distance to first available value
5677 if (drop_distance_current == NULL)
5678 drop_distance_current = drop_distances;
5681 if (transparencies == NULL)
5683 for (i = 0; transparencies_list[i].value != -1; i++)
5685 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5686 char identifier[32], name[32];
5687 int value = transparencies_list[i].value;
5688 char *text = transparencies_list[i].text;
5690 ti->node_top = &transparencies;
5691 ti->sort_priority = value;
5693 sprintf(identifier, "%d", value);
5694 sprintf(name, "%s", text);
5696 setString(&ti->identifier, identifier);
5697 setString(&ti->name, name);
5698 setString(&ti->name_sorting, name);
5699 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5701 pushTreeInfo(&transparencies, ti);
5704 // sort transparency values to start with lowest transparency value
5705 sortTreeInfo(&transparencies);
5707 // set current transparency value to configured transparency value
5708 transparency_current =
5709 getTreeInfoFromIdentifier(transparencies,
5710 i_to_a(setup.touch.transparency));
5712 // if that fails, set current transparency to reliable default value
5713 if (transparency_current == NULL)
5714 transparency_current =
5715 getTreeInfoFromIdentifier(transparencies,
5716 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5718 // if that also fails, set current transparency to first available value
5719 if (transparency_current == NULL)
5720 transparency_current = transparencies;
5723 for (i = 0; i < 2; i++)
5725 for (j = 0; j < 2; j++)
5727 if (grid_sizes[i][j] == NULL)
5729 for (k = 0; grid_sizes_list[k].value != -1; k++)
5731 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5732 char identifier[32], name[32];
5733 int value = grid_sizes_list[k].value;
5734 char *text = grid_sizes_list[k].text;
5736 ti->node_top = &grid_sizes[i][j];
5737 ti->sort_priority = value;
5739 sprintf(identifier, "%d", value);
5740 sprintf(name, "%s", text);
5742 setString(&ti->identifier, identifier);
5743 setString(&ti->name, name);
5744 setString(&ti->name_sorting, name);
5745 setString(&ti->infotext,
5748 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5749 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5751 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5752 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5754 pushTreeInfo(&grid_sizes[i][j], ti);
5757 // sort grid size values to start with lowest grid size value
5758 sortTreeInfo(&grid_sizes[i][j]);
5760 // set current grid size value to configured grid size value
5761 grid_size_current[i][j] =
5762 getTreeInfoFromIdentifier(grid_sizes[i][j],
5764 setup.touch.grid_xsize[i] :
5765 setup.touch.grid_ysize[i]));
5767 // if that fails, set current grid size to reliable default value
5768 if (grid_size_current[i][j] == NULL)
5769 grid_size_current[i][j] =
5770 getTreeInfoFromIdentifier(grid_sizes[i][j],
5772 DEFAULT_GRID_XSIZE(i) :
5773 DEFAULT_GRID_YSIZE(i)));
5775 // if that also fails, set current grid size to first available value
5776 if (grid_size_current[i][j] == NULL)
5777 grid_size_current[i][j] = grid_sizes[i][j];
5782 setup.touch.control_type = touch_control_current->identifier;
5783 setup.touch.move_distance = atoi(move_distance_current->identifier);
5784 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5785 setup.touch.transparency = atoi(transparency_current->identifier);
5787 for (i = 0; i < 2; i++)
5789 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5790 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5792 if (i == GRID_ACTIVE_NR())
5794 overlay.grid_xsize = setup.touch.grid_xsize[i];
5795 overlay.grid_ysize = setup.touch.grid_ysize[i];
5799 // needed for displaying value text instead of identifier
5800 touch_controls_text = touch_control_current->name;
5801 move_distance_text = move_distance_current->name;
5802 drop_distance_text = drop_distance_current->name;
5803 transparency_text = transparency_current->name;
5805 for (i = 0; i < 2; i++)
5806 for (j = 0; j < 2; j++)
5807 grid_size_text[i][j] = grid_size_current[i][j]->name;
5809 setup_mode = SETUP_MODE_TOUCH;
5814 static void execSetupArtwork(void)
5817 printf("::: '%s', '%s', '%s'\n",
5818 artwork.gfx_current->subdir,
5819 artwork.gfx_current->fullpath,
5820 artwork.gfx_current->basepath);
5823 setup.graphics_set = artwork.gfx_current->identifier;
5824 setup.sounds_set = artwork.snd_current->identifier;
5825 setup.music_set = artwork.mus_current->identifier;
5827 // needed if last screen (setup choice) changed graphics, sounds or music
5828 ReloadCustomArtwork(0);
5830 // needed for displaying artwork name instead of artwork identifier
5831 graphics_set_name = artwork.gfx_current->name;
5832 sounds_set_name = artwork.snd_current->name;
5833 music_set_name = artwork.mus_current->name;
5835 setup_mode = SETUP_MODE_ARTWORK;
5840 static void execSetupChooseGraphics(void)
5842 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5847 static void execSetupChooseSounds(void)
5849 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5854 static void execSetupChooseMusic(void)
5856 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5861 static void execSetupInput(void)
5863 setup_mode = SETUP_MODE_INPUT;
5868 static void execSetupShortcuts(void)
5870 setup_mode = SETUP_MODE_SHORTCUTS;
5875 static void execSetupShortcuts1(void)
5877 setup_mode = SETUP_MODE_SHORTCUTS_1;
5882 static void execSetupShortcuts2(void)
5884 setup_mode = SETUP_MODE_SHORTCUTS_2;
5889 static void execSetupShortcuts3(void)
5891 setup_mode = SETUP_MODE_SHORTCUTS_3;
5896 static void execSetupShortcuts4(void)
5898 setup_mode = SETUP_MODE_SHORTCUTS_4;
5903 static void execSetupShortcuts5(void)
5905 setup_mode = SETUP_MODE_SHORTCUTS_5;
5910 static void execExitSetup(void)
5912 SetGameStatus(GAME_MODE_MAIN);
5917 static void execSaveAndExitSetup(void)
5923 static void execGadgetNetworkServer(void)
5925 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
5926 struct GadgetInfo *gi = screen_gadget[gadget_id];
5928 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5929 network_server_hostname[0] = '\0';
5931 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
5935 ClickOnGadget(gi, MB_LEFTBUTTON);
5938 static void ToggleNetworkModeIfNeeded(void)
5940 int font_title = FONT_TITLE_1;
5941 int font_foot = FC_BLUE;
5942 int ystart = mSY - SY + 16;
5943 int ybottom = mSY - SY + SYSIZE - 20;
5944 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
5946 if (setup.network_mode == network.enabled)
5949 network.enabled = setup.network_mode;
5951 FadeOut(REDRAW_ALL);
5955 DrawTextSCentered(ystart, font_title, text);
5959 if (network.enabled)
5960 InitNetworkServer();
5962 DisconnectFromNetworkServer();
5964 DrawTextSCentered(ybottom, font_foot,
5965 "Press any key or button for setup menu");
5967 WaitForEventToContinue();
5972 static void ToggleGameSpeedsListIfNeeded(void)
5974 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
5976 if (setup.game_speed_extended == using_game_speeds_extended)
5979 // try to match similar values when changing game speeds list
5980 if (setup.game_speed_extended)
5981 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
5982 setup.game_frame_delay == 30 ? 29 :
5983 setup.game_frame_delay);
5985 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
5986 setup.game_frame_delay == 16 ? 15 :
5987 setup.game_frame_delay >= 29 ? 30 :
5988 setup.game_frame_delay <= 10 ? 10 :
5989 setup.game_frame_delay);
5991 execSetupGame_setGameSpeeds(TRUE);
5996 static void ModifyGameSpeedIfNeeded(void)
5998 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
5999 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6003 char *game_speed_text = "Fast";
6004 int game_speed_value = 15;
6006 if (setup.game_speed_extended)
6008 game_speed_text = "60 fps";
6009 game_speed_value = 16;
6012 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6014 // set game speed to existing list value that is fast enough for vsync
6015 setup.game_frame_delay = game_speed_value;
6017 execSetupGame_setGameSpeeds(TRUE);
6019 Request(message, REQ_CONFIRM);
6022 static void DisableVsyncIfNeeded(void)
6024 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6025 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6026 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6029 // disable vsync for the selected game speed to work
6030 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6032 execSetupGraphics_setVsyncModes(TRUE);
6034 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6040 void *related_value;
6041 } hide_related_entry_list[] =
6043 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6044 { &setup.game_frame_delay, &game_speed_text },
6046 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6047 { &setup.scroll_delay_value, &scroll_delay_text },
6049 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6050 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6052 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6053 { &setup.window_scaling_percent, &window_size_text },
6055 { &setup.window_scaling_quality, execSetupChooseScalingType },
6056 { &setup.window_scaling_quality, &scaling_type_text },
6058 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6059 { &setup.screen_rendering_mode, &rendering_mode_text },
6061 { &setup.vsync_mode, execSetupChooseVsyncMode },
6062 { &setup.vsync_mode, &vsync_mode_text },
6064 { &setup.graphics_set, execSetupChooseGraphics },
6065 { &setup.graphics_set, &graphics_set_name },
6067 { &setup.sounds_set, execSetupChooseSounds },
6068 { &setup.sounds_set, &sounds_set_name },
6070 { &setup.music_set, execSetupChooseMusic },
6071 { &setup.music_set, &music_set_name },
6073 { &setup.volume_simple, execSetupChooseVolumeSimple },
6074 { &setup.volume_simple, &volume_simple_text },
6076 { &setup.volume_loops, execSetupChooseVolumeLoops },
6077 { &setup.volume_loops, &volume_loops_text },
6079 { &setup.volume_music, execSetupChooseVolumeMusic },
6080 { &setup.volume_music, &volume_music_text },
6082 { &setup.touch.control_type, execSetupChooseTouchControls },
6083 { &setup.touch.control_type, &touch_controls_text },
6085 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6086 { &setup.touch.move_distance, &move_distance_text },
6088 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6089 { &setup.touch.drop_distance, &drop_distance_text },
6091 { &setup.touch.transparency, execSetupChooseTransparency },
6092 { &setup.touch.transparency, &transparency_text },
6094 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6095 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6097 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6098 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6100 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6101 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6103 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6104 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6109 void setHideRelatedSetupEntries(void)
6113 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6114 if (hideSetupEntry(hide_related_entry_list[i].value))
6115 setHideSetupEntry(hide_related_entry_list[i].related_value);
6118 static struct TokenInfo setup_info_main[] =
6120 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6121 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6122 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6123 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6124 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6125 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6126 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6127 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6128 { TYPE_EMPTY, NULL, "" },
6129 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6130 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6135 static struct TokenInfo setup_info_game[] =
6137 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6138 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6139 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6140 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6141 { TYPE_STRING, &network_server_text, "" },
6142 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6143 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6144 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6145 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6146 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6147 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6148 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
6149 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6150 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6151 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6152 { TYPE_STRING, &game_speed_text, "" },
6153 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6155 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6156 { TYPE_STRING, &scroll_delay_text, "" },
6158 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6159 { TYPE_STRING, &snapshot_mode_text, "" },
6160 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6161 { TYPE_EMPTY, NULL, "" },
6162 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6167 static struct TokenInfo setup_info_editor[] =
6170 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6171 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6172 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6173 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6174 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6175 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6176 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6177 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6178 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6179 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6181 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6182 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6184 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6186 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6187 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6188 { TYPE_EMPTY, NULL, "" },
6190 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6191 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6192 { TYPE_EMPTY, NULL, "" },
6194 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6195 { TYPE_EMPTY, NULL, "" },
6196 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6201 static struct TokenInfo setup_info_graphics[] =
6203 #if !defined(PLATFORM_ANDROID)
6204 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6205 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6206 { TYPE_STRING, &window_size_text, "" },
6207 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6208 { TYPE_STRING, &scaling_type_text, "" },
6209 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6210 { TYPE_STRING, &rendering_mode_text, "" },
6213 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6214 { TYPE_STRING, &scroll_delay_text, "" },
6216 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6217 { TYPE_STRING, &vsync_mode_text, "" },
6218 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6219 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6220 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6221 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6222 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6223 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
6224 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
6225 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6226 { TYPE_EMPTY, NULL, "" },
6227 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6232 static struct TokenInfo setup_info_sound[] =
6234 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6235 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6236 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6237 { TYPE_EMPTY, NULL, "" },
6238 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6239 { TYPE_STRING, &volume_simple_text, "" },
6240 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6241 { TYPE_STRING, &volume_loops_text, "" },
6242 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6243 { TYPE_STRING, &volume_music_text, "" },
6244 { TYPE_EMPTY, NULL, "" },
6245 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6250 static struct TokenInfo setup_info_artwork[] =
6252 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6253 { TYPE_STRING, &graphics_set_name, "" },
6254 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6255 { TYPE_STRING, &sounds_set_name, "" },
6256 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6257 { TYPE_STRING, &music_set_name, "" },
6258 { TYPE_EMPTY, NULL, "" },
6259 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6260 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6261 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6262 { TYPE_EMPTY, NULL, "" },
6263 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6268 static struct TokenInfo setup_info_input[] =
6270 { TYPE_SWITCH, NULL, "Player:" },
6271 { TYPE_SWITCH, NULL, "Device:" },
6272 { TYPE_SWITCH, NULL, "" },
6273 { TYPE_SKIPPABLE, NULL, "" },
6274 { TYPE_EMPTY, NULL, "" },
6275 { TYPE_EMPTY, NULL, "" },
6276 { TYPE_EMPTY, NULL, "" },
6277 { TYPE_EMPTY, NULL, "" },
6278 { TYPE_EMPTY, NULL, "" },
6279 { TYPE_EMPTY, NULL, "" },
6280 { TYPE_EMPTY, NULL, "" },
6281 { TYPE_EMPTY, NULL, "" },
6282 { TYPE_SKIPPABLE, NULL, "" },
6283 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6288 static struct TokenInfo setup_info_touch[] =
6290 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6291 { TYPE_STRING, &touch_controls_text, "" },
6292 { TYPE_EMPTY, NULL, "" },
6293 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6298 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6300 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6301 { TYPE_STRING, &touch_controls_text, "" },
6302 { TYPE_EMPTY, NULL, "" },
6303 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6304 { TYPE_STRING, &grid_size_text[0][0], "" },
6305 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6306 { TYPE_STRING, &grid_size_text[0][1], "" },
6307 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6308 { TYPE_STRING, &transparency_text, "" },
6309 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6310 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6311 { TYPE_EMPTY, NULL, "" },
6312 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6313 { TYPE_EMPTY, NULL, "" },
6314 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6319 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6321 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6322 { TYPE_STRING, &touch_controls_text, "" },
6323 { TYPE_EMPTY, NULL, "" },
6324 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6325 { TYPE_STRING, &grid_size_text[1][0], "" },
6326 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6327 { TYPE_STRING, &grid_size_text[1][1], "" },
6328 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6329 { TYPE_STRING, &transparency_text, "" },
6330 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6331 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6332 { TYPE_EMPTY, NULL, "" },
6333 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6334 { TYPE_EMPTY, NULL, "" },
6335 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6340 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6342 setup_info_touch_virtual_buttons_0,
6343 setup_info_touch_virtual_buttons_1
6346 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6348 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6349 { TYPE_STRING, &touch_controls_text, "" },
6350 { TYPE_EMPTY, NULL, "" },
6351 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6352 { TYPE_STRING, &move_distance_text, "" },
6353 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6354 { TYPE_STRING, &drop_distance_text, "" },
6355 { TYPE_EMPTY, NULL, "" },
6356 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6361 static struct TokenInfo setup_info_shortcuts[] =
6363 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6364 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6365 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6366 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6367 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6368 { TYPE_EMPTY, NULL, "" },
6369 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6374 static struct TokenInfo setup_info_shortcuts_1[] =
6376 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6377 { TYPE_KEY, &setup.shortcut.save_game, "" },
6378 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6379 { TYPE_KEY, &setup.shortcut.load_game, "" },
6380 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6381 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6382 { TYPE_EMPTY, NULL, "" },
6383 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6384 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6385 { TYPE_EMPTY, NULL, "" },
6386 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6391 static struct TokenInfo setup_info_shortcuts_2[] =
6393 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6394 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6395 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6396 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6397 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6398 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6399 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6400 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6401 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6402 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6403 { TYPE_EMPTY, NULL, "" },
6404 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6409 static struct TokenInfo setup_info_shortcuts_3[] =
6411 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6412 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6413 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6414 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6415 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6416 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6417 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6418 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6419 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6420 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6421 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6422 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6423 { TYPE_EMPTY, NULL, "" },
6424 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6429 static struct TokenInfo setup_info_shortcuts_4[] =
6431 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6432 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6433 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6434 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6435 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6436 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6437 { TYPE_EMPTY, NULL, "" },
6438 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6443 static struct TokenInfo setup_info_shortcuts_5[] =
6445 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6446 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6447 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6448 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6449 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6450 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6451 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6452 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6453 { TYPE_EMPTY, NULL, "" },
6454 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6459 static Key getSetupKey(void)
6461 Key key = KSYM_UNDEFINED;
6462 boolean got_key_event = FALSE;
6464 while (!got_key_event)
6468 if (NextValidEvent(&event))
6472 case EVENT_KEYPRESS:
6474 key = GetEventKey((KeyEvent *)&event, TRUE);
6476 // press 'Escape' or 'Enter' to keep the existing key binding
6477 if (key == KSYM_Escape || key == KSYM_Return)
6478 key = KSYM_UNDEFINED; // keep old value
6480 got_key_event = TRUE;
6484 case EVENT_KEYRELEASE:
6485 key_joystick_mapping = 0;
6489 HandleOtherEvents(&event);
6500 static int getSetupValueFont(int type, void *value)
6502 if (type & TYPE_GHOSTED)
6503 return FONT_OPTION_OFF;
6504 else if (type & TYPE_KEY)
6505 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6506 else if (type & TYPE_STRING)
6507 return FONT_VALUE_2;
6508 else if (type & TYPE_ECS_AGA)
6509 return FONT_VALUE_1;
6510 else if (type & TYPE_BOOLEAN_STYLE)
6511 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6512 else if (type & TYPE_YES_NO_AUTO)
6513 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6514 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6515 else if (type & TYPE_PLAYER)
6516 return FONT_VALUE_1;
6518 return FONT_VALUE_1;
6521 static int getSetupValueFontNarrow(int type, int font_nr)
6523 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6524 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6525 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6529 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6531 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6532 struct TokenInfo *si = &setup_info[si_pos];
6533 boolean font_draw_xoffset_modified = FALSE;
6534 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6535 int font_draw_xoffset_old = -1;
6536 int xoffset = (scrollbar_needed ? -1 : 0);
6537 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6538 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6539 int xpos = menu_screen_value_xpos;
6540 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6541 int startx = mSX + xpos * 32;
6542 int starty = mSY + ypos * 32;
6543 int type = si->type;
6544 void *value = si->value;
6545 char *value_string = getSetupValue(type, value);
6546 int font_nr_default = getSetupValueFont(type, value);
6547 int font_width_default = getFontWidth(font_nr_default);
6548 int font_nr = font_nr_default;
6551 if (value_string == NULL)
6554 if (type & TYPE_KEY)
6556 xpos = MENU_SCREEN_START_XPOS;
6558 if (type & TYPE_QUERY)
6559 value_string = "<press key>";
6561 else if (type & TYPE_STRING)
6563 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
6565 xpos = MENU_SCREEN_START_XPOS;
6567 if (strlen(value_string) > max_value_len)
6568 value_string[max_value_len] = '\0';
6570 else if (type & TYPE_YES_NO_AUTO)
6572 xpos = menu_screen_value_xpos - 1;
6574 else if (type & TYPE_PLAYER)
6576 int displayed_player_nr = *(int *)value + 1;
6578 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6581 startx = mSX + xpos * 32;
6582 starty = mSY + ypos * 32;
6584 // special check if right-side setup values moved left due to scrollbar
6585 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6587 int max_menu_text_length = 26; // maximum text length for classic menu
6588 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6589 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6590 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6591 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6592 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6594 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6597 startx = mSX + xpos * 32;
6599 font_nr = getSetupValueFontNarrow(type, font_nr);
6603 // downward compatibility correction for Juergen Bonhagen's menu settings
6604 if (setup_mode != SETUP_MODE_INPUT)
6606 int max_menu_text_length_big = (menu_screen_value_xpos -
6607 MENU_SCREEN_START_XPOS);
6608 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6609 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
6610 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6611 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6612 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6613 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6614 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6615 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6616 boolean correct_font_draw_xoffset = FALSE;
6618 if (xpos == MENU_SCREEN_START_XPOS &&
6619 startx + font1_xoffset < text_startx + text_font_xoffset)
6620 correct_font_draw_xoffset = TRUE;
6622 if (xpos == menu_screen_value_xpos &&
6623 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6624 correct_font_draw_xoffset = TRUE;
6626 // check if setup value would overlap with setup text when printed
6627 // (this can happen for extreme/wrong values for font draw offset)
6628 if (correct_font_draw_xoffset)
6630 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6631 font_draw_xoffset_modified = TRUE;
6633 if (type & TYPE_KEY)
6634 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6635 else if (!(type & TYPE_STRING))
6636 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6637 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6641 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6642 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6644 DrawText(startx, starty, value_string, font_nr);
6646 if (type & TYPE_PLAYER)
6648 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
6649 int player_nr = *(int *)value;
6650 int xoff = font->draw_xoffset + getFontWidth(font_nr);
6651 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
6652 int startx2 = startx + xoff;
6653 int starty2 = starty + yoff;
6655 if (DrawingOnBackground(startx2, starty2))
6656 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
6658 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
6659 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6662 if (font_draw_xoffset_modified)
6663 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6666 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6668 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6669 struct TokenInfo *si = &setup_info[si_pos];
6671 if (si->type & TYPE_BOOLEAN_STYLE)
6673 *(boolean *)si->value ^= TRUE;
6675 else if (si->type & TYPE_YES_NO_AUTO)
6679 (*(int *)si->value == AUTO ? TRUE :
6680 *(int *)si->value == TRUE ? FALSE : AUTO) :
6681 (*(int *)si->value == TRUE ? AUTO :
6682 *(int *)si->value == AUTO ? FALSE : TRUE));
6684 else if (si->type & TYPE_KEY)
6688 si->type |= TYPE_QUERY;
6689 drawSetupValue(screen_pos, setup_info_pos_raw);
6690 si->type &= ~TYPE_QUERY;
6692 key = getSetupKey();
6693 if (key != KSYM_UNDEFINED)
6694 *(Key *)si->value = key;
6696 else if (si->type & TYPE_PLAYER)
6698 int player_nr = *(int *)si->value;
6703 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6705 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6708 drawSetupValue(screen_pos, setup_info_pos_raw);
6710 // fullscreen state may have changed at this point
6711 if (si->value == &setup.fullscreen)
6712 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6714 // network mode may have changed at this point
6715 if (si->value == &setup.network_mode)
6716 ToggleNetworkModeIfNeeded();
6718 // game speed list may have changed at this point
6719 if (si->value == &setup.game_speed_extended)
6720 ToggleGameSpeedsListIfNeeded();
6723 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6725 static struct TokenInfo *setup_info_final = NULL;
6730 // determine maximum list size of target list
6731 while (setup_info_orig[list_size++].type != 0);
6733 // free, allocate and clear memory for target list
6734 checked_free(setup_info_final);
6735 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6737 // copy setup info list without setup entries marked as hidden
6738 for (i = 0; setup_info_orig[i].type != 0; i++)
6740 // skip setup entries configured to be hidden
6741 if (hideSetupEntry(setup_info_orig[i].value))
6744 // skip skippable setup entries if screen is lower than usual
6745 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6746 setup_info_orig[i].type == TYPE_SKIPPABLE)
6749 setup_info_final[list_pos++] = setup_info_orig[i];
6752 return setup_info_final;
6755 static void DrawSetupScreen_Generic(void)
6757 int fade_mask = REDRAW_FIELD;
6758 boolean redraw_all = FALSE;
6759 char *title_string = NULL;
6763 fade_mask = REDRAW_ALL;
6766 FadeMenuSoundsAndMusic();
6768 FreeScreenGadgets();
6769 CreateScreenGadgets();
6771 if (redraw_mask & REDRAW_ALL)
6776 // needed if different viewport properties defined for setup screen
6777 ChangeViewportPropertiesIfNeeded();
6779 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6783 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6785 if (setup_mode == SETUP_MODE_MAIN)
6787 setup_info = setup_info_main;
6788 title_string = STR_SETUP_MAIN;
6790 else if (setup_mode == SETUP_MODE_GAME)
6792 setup_info = setup_info_game;
6793 title_string = STR_SETUP_GAME;
6795 else if (setup_mode == SETUP_MODE_EDITOR)
6797 setup_info = setup_info_editor;
6798 title_string = STR_SETUP_EDITOR;
6800 else if (setup_mode == SETUP_MODE_GRAPHICS)
6802 setup_info = setup_info_graphics;
6803 title_string = STR_SETUP_GRAPHICS;
6805 else if (setup_mode == SETUP_MODE_SOUND)
6807 setup_info = setup_info_sound;
6808 title_string = STR_SETUP_SOUND;
6810 else if (setup_mode == SETUP_MODE_ARTWORK)
6812 setup_info = setup_info_artwork;
6813 title_string = STR_SETUP_ARTWORK;
6815 else if (setup_mode == SETUP_MODE_TOUCH)
6817 setup_info = setup_info_touch;
6818 title_string = STR_SETUP_TOUCH;
6820 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6821 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6822 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6823 setup_info = setup_info_touch_wipe_gestures;
6825 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6827 setup_info = setup_info_shortcuts;
6828 title_string = STR_SETUP_SHORTCUTS;
6830 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6832 setup_info = setup_info_shortcuts_1;
6833 title_string = STR_SETUP_SHORTCUTS;
6835 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6837 setup_info = setup_info_shortcuts_2;
6838 title_string = STR_SETUP_SHORTCUTS;
6840 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6842 setup_info = setup_info_shortcuts_3;
6843 title_string = STR_SETUP_SHORTCUTS;
6845 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6847 setup_info = setup_info_shortcuts_4;
6848 title_string = STR_SETUP_SHORTCUTS;
6850 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6852 setup_info = setup_info_shortcuts_5;
6853 title_string = STR_SETUP_SHORTCUTS;
6856 // use modified setup info without setup entries marked as hidden
6857 setup_info = getSetupInfoFinal(setup_info);
6859 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6861 // determine maximal number of setup entries that can be displayed on screen
6863 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6866 // determine maximal number of setup entries available for this setup screen
6868 for (i = 0; setup_info[i].type != 0; i++)
6871 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6873 MapScreenGadgets(max_setup_info);
6876 redraw_mask = fade_mask = REDRAW_ALL;
6878 DrawMaskedBorder(fade_mask);
6883 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6885 menu_info = setup_info;
6887 HandleMenuScreen(mx, my, dx, dy, button,
6888 setup_mode, num_setup_info, max_setup_info);
6891 static void DrawSetupScreen_Input(void)
6895 FadeOut(REDRAW_FIELD);
6899 setup_info = getSetupInfoFinal(setup_info_input);
6901 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6903 for (i = 0; setup_info[i].type != 0; i++)
6905 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6906 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6907 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6908 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6909 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6910 initCursor(i, IMG_MENU_BUTTON);
6912 DrawCursorAndText_Setup(i, -1, FALSE);
6915 // create gadgets for setup input menu screen
6916 FreeScreenGadgets();
6917 CreateScreenGadgets();
6919 // map gadgets for setup input menu screen
6920 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6922 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6924 FadeIn(REDRAW_FIELD);
6927 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6929 if (device_name == NULL)
6932 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6935 if (strlen(device_name) > 1)
6937 char c1 = device_name[strlen(device_name) - 1];
6938 char c2 = device_name[strlen(device_name) - 2];
6940 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6941 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6944 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6945 strlen(device_name));
6948 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6951 static struct SetupKeyboardInfo custom_key;
6958 { &custom_key.left, "Axis/Pad Left" },
6959 { &custom_key.right, "Axis/Pad Right" },
6960 { &custom_key.up, "Axis/Pad Up" },
6961 { &custom_key.down, "Axis/Pad Down" },
6962 { &custom_key.snap, "Button 1/A/X" },
6963 { &custom_key.drop, "Button 2/B/Y" }
6965 static char *joystick_name[MAX_PLAYERS] =
6972 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6973 int font_nr_info = FONT_MENU_1;
6974 int font_nr_name = FONT_VALUE_OLD;
6975 int font_nr_on = FONT_VALUE_1;
6976 int font_nr_off = FONT_VALUE_OLD;
6979 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6981 font_nr_info = FONT_MENU_2;
6982 font_nr_on = FONT_VALUE_NARROW;
6983 font_nr_off = FONT_VALUE_OLD_NARROW;
6986 custom_key = setup.input[player_nr].key;
6988 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6989 FONT_INPUT_1_ACTIVE);
6991 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6993 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6994 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6996 if (setup.input[player_nr].use_joystick)
6998 char *device_name = setup.input[player_nr].joy.device_name;
6999 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7000 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7001 char *text = joystick_name[joystick_nr];
7002 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7004 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7005 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7009 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7010 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7013 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7014 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7018 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7019 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7020 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7021 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7023 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7024 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7025 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7026 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7027 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7028 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7030 for (i = 0; i < 6; i++)
7032 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7034 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7036 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7037 (setup.input[player_nr].use_joystick ?
7039 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7043 static int input_player_nr = 0;
7045 static void HandleSetupScreen_Input_Player(int step, int direction)
7047 int old_player_nr = input_player_nr;
7050 new_player_nr = old_player_nr + step * direction;
7051 if (new_player_nr < 0)
7053 if (new_player_nr > MAX_PLAYERS - 1)
7054 new_player_nr = MAX_PLAYERS - 1;
7056 if (new_player_nr != old_player_nr)
7058 input_player_nr = new_player_nr;
7060 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7064 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7066 static int choice = 0;
7069 int pos_start = SETUPINPUT_SCREEN_POS_START;
7070 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7071 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7072 int pos_end = SETUPINPUT_SCREEN_POS_END;
7074 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7078 for (i = 0; setup_info_input[i].type != 0; i++)
7080 // adjust menu structure according to skipped setup entries
7081 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7089 if (button == MB_MENU_INITIALIZE)
7091 // input setup menu may have changed size due to graphics configuration
7092 if (choice >= pos_empty1)
7095 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7097 DrawCursorAndText_Setup(choice, -1, TRUE);
7101 else if (button == MB_MENU_LEAVE)
7103 setup_mode = SETUP_MODE_MAIN;
7110 if (mx || my) // mouse input
7112 x = (mx - mSX) / 32;
7113 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7115 else if (dx || dy) // keyboard input
7117 if (dx && choice == 0)
7118 x = (dx < 0 ? 10 : 12);
7119 else if ((dx && choice == 1) ||
7120 (dx == -1 && choice == pos_end))
7121 button = MB_MENU_CHOICE;
7125 if (y >= pos_empty1 && y <= pos_empty2)
7126 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7129 if (y == 0 && dx != 0 && button)
7131 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7133 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7134 y >= pos_start && y <= pos_end &&
7135 !(y >= pos_empty1 && y <= pos_empty2))
7141 DrawCursorAndText_Setup(choice, -1, FALSE);
7142 DrawCursorAndText_Setup(y, -1, TRUE);
7144 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7153 char *device_name = setup.input[input_player_nr].joy.device_name;
7155 if (!setup.input[input_player_nr].use_joystick)
7157 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7159 setJoystickDeviceToNr(device_name, new_device_nr);
7160 setup.input[input_player_nr].use_joystick = TRUE;
7164 int device_nr = getJoystickNrFromDeviceName(device_name);
7165 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7167 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7168 setup.input[input_player_nr].use_joystick = FALSE;
7170 setJoystickDeviceToNr(device_name, new_device_nr);
7173 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7177 if (setup.input[input_player_nr].use_joystick)
7178 ConfigureJoystick(input_player_nr);
7180 CustomizeKeyboard(input_player_nr);
7182 else if (y == pos_end)
7188 setup_mode = SETUP_MODE_MAIN;
7195 static boolean CustomizeKeyboardMain(int player_nr)
7199 boolean finished = FALSE;
7200 static struct SetupKeyboardInfo custom_key;
7205 } customize_step[] =
7207 { &custom_key.left, "Move Left" },
7208 { &custom_key.right, "Move Right" },
7209 { &custom_key.up, "Move Up" },
7210 { &custom_key.down, "Move Down" },
7211 { &custom_key.snap, "Snap Field" },
7212 { &custom_key.drop, "Drop Element" }
7214 int font_nr_old = FONT_VALUE_OLD;
7215 int font_nr_new = FONT_VALUE_1;
7216 boolean success = FALSE;
7218 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7220 font_nr_old = FONT_VALUE_OLD_NARROW;
7221 font_nr_new = FONT_VALUE_NARROW;
7224 // read existing key bindings from player setup
7225 custom_key = setup.input[player_nr].key;
7228 FadeOut(REDRAW_FIELD);
7232 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7235 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7236 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7237 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7238 "Key:", FONT_INPUT_1_ACTIVE);
7239 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7240 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7242 FadeIn(REDRAW_FIELD);
7248 if (NextValidEvent(&event))
7252 case EVENT_KEYPRESS:
7254 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7256 // press 'Escape' to abort and keep the old key bindings
7257 if (key == KSYM_Escape)
7259 FadeSkipNextFadeIn();
7266 // press 'Enter' to keep the existing key binding
7267 if (key == KSYM_Return)
7268 key = *customize_step[step_nr].key;
7270 // check if key already used
7271 for (i = 0; i < step_nr; i++)
7272 if (*customize_step[i].key == key)
7277 // got new key binding
7278 *customize_step[step_nr].key = key;
7279 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7281 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7282 getKeyNameFromKey(key), font_nr_new);
7285 // un-highlight last query
7286 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7287 customize_step[step_nr - 1].text, FONT_MENU_1);
7288 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7289 "Key:", FONT_MENU_1);
7291 // all keys configured
7300 // query next key binding
7301 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7302 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7303 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7304 "Key:", FONT_INPUT_1_ACTIVE);
7305 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7306 getKeyNameFromKey(*customize_step[step_nr].key),
7311 case EVENT_KEYRELEASE:
7312 key_joystick_mapping = 0;
7316 HandleOtherEvents(&event);
7324 // write new key bindings back to player setup, if successfully finished
7326 setup.input[player_nr].key = custom_key;
7331 void CustomizeKeyboard(int player_nr)
7333 boolean success = CustomizeKeyboardMain(player_nr);
7337 int font_nr = FONT_TITLE_1;
7338 int font_height = getFontHeight(font_nr);
7339 int ypos1 = SYSIZE / 2 - font_height * 2;
7340 int ypos2 = SYSIZE / 2 - font_height * 1;
7341 unsigned int wait_frame_delay = 0;
7342 unsigned int wait_frame_delay_value = 2000;
7344 ResetDelayCounter(&wait_frame_delay);
7348 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7349 DrawTextSCentered(ypos2, font_nr, "configured!");
7351 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7357 DrawSetupScreen_Input();
7360 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
7362 #define MARKER_BUTTON 1
7363 #define MARKER_AXIS_X 2
7364 #define MARKER_AXIS_Y 3
7366 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7368 static boolean bitmaps_initialized = FALSE;
7369 boolean screen_initialized = FALSE;
7370 static Bitmap *controller, *button, *axis_x, *axis_y;
7372 boolean success = TRUE;
7373 boolean done = FALSE, next = FALSE;
7375 int alpha = 200, alpha_step = -1;
7376 int alpha_ticks = 0;
7377 char mapping[4096], temp[4096];
7378 int font_name = MENU_SETUP_FONT_TITLE;
7379 int font_info = MENU_SETUP_FONT_TEXT;
7380 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7381 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7382 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7383 int ystep_name = getMenuTextStep(spacing_name, font_name);
7384 int ystep_line = getMenuTextStep(spacing_line, font_info);
7385 int ystep_para = getMenuTextStep(spacing_para, font_info);
7393 int axis, button, hat, hat_value;
7396 *step, *prev_step, steps[] =
7398 { 356, 155, MARKER_BUTTON, "a", },
7399 { 396, 122, MARKER_BUTTON, "b", },
7400 { 320, 125, MARKER_BUTTON, "x", },
7401 { 358, 95, MARKER_BUTTON, "y", },
7402 { 162, 125, MARKER_BUTTON, "back", },
7403 { 216, 125, MARKER_BUTTON, "guide", },
7404 { 271, 125, MARKER_BUTTON, "start", },
7405 { 110, 200, MARKER_BUTTON, "dpleft", },
7406 { 146, 228, MARKER_BUTTON, "dpdown", },
7407 { 178, 200, MARKER_BUTTON, "dpright", },
7408 { 146, 172, MARKER_BUTTON, "dpup", },
7409 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7410 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7411 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7412 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7413 { 73, 141, MARKER_BUTTON, "leftstick", },
7414 { 282, 210, MARKER_BUTTON, "rightstick", },
7415 { 73, 141, MARKER_AXIS_X, "leftx", },
7416 { 73, 141, MARKER_AXIS_Y, "lefty", },
7417 { 282, 210, MARKER_AXIS_X, "rightx", },
7418 { 282, 210, MARKER_AXIS_Y, "righty", },
7421 unsigned int event_frame_delay = 0;
7422 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7424 ResetDelayCounter(&event_frame_delay);
7426 if (!bitmaps_initialized)
7428 controller = LoadCustomImage("joystick/controller.png");
7429 button = LoadCustomImage("joystick/button.png");
7430 axis_x = LoadCustomImage("joystick/axis_x.png");
7431 axis_y = LoadCustomImage("joystick/axis_y.png");
7433 bitmaps_initialized = TRUE;
7436 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7439 // print info about the joystick we are watching
7440 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7441 SDL_JoystickInstanceID(joystick), name);
7442 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7443 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7444 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7447 // initialize mapping with GUID and name
7448 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7450 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7451 temp, name, SDL_GetPlatform());
7453 // loop through all steps (buttons and axes), getting joystick events
7454 for (i = 0; i < SDL_arraysize(steps) && !done;)
7456 Bitmap *marker = button; // initialize with reliable default value
7459 strcpy(step->mapping, mapping);
7463 step->hat_value = -1;
7465 marker = (step->marker == MARKER_BUTTON ? button :
7466 step->marker == MARKER_AXIS_X ? axis_x :
7467 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7471 while (!done && !next)
7473 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7474 alpha_ticks = SDL_GetTicks();
7481 else if (alpha < 128)
7487 int controller_x = SX + (SXSIZE - controller->width) / 2;
7488 int controller_y = SY + ystep_line;
7490 int marker_x = controller_x + step->x;
7491 int marker_y = controller_y + step->y;
7493 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7494 int ystart2 = ystart1 + ystep_name + ystep_line;
7498 DrawTextSCentered(ystart1, font_name, name);
7500 DrawTextSCentered(ystart2, font_info,
7501 "Press buttons and move axes on");
7502 ystart2 += ystep_line;
7503 DrawTextSCentered(ystart2, font_info,
7504 "your controller when indicated.");
7505 ystart2 += ystep_line;
7506 DrawTextSCentered(ystart2, font_info,
7507 "(Your controller may look different.)");
7508 ystart2 += ystep_para;
7510 #if defined(PLATFORM_ANDROID)
7511 DrawTextSCentered(ystart2, font_info,
7512 "To correct a mistake,");
7513 ystart2 += ystep_line;
7514 DrawTextSCentered(ystart2, font_info,
7515 "press the 'back' button.");
7516 ystart2 += ystep_line;
7517 DrawTextSCentered(ystart2, font_info,
7518 "To skip a button or axis,");
7519 ystart2 += ystep_line;
7520 DrawTextSCentered(ystart2, font_info,
7521 "press the 'menu' button.");
7523 DrawTextSCentered(ystart2, font_info,
7524 "To correct a mistake,");
7525 ystart2 += ystep_line;
7526 DrawTextSCentered(ystart2, font_info,
7527 "press the 'backspace' key.");
7528 ystart2 += ystep_line;
7529 DrawTextSCentered(ystart2, font_info,
7530 "To skip a button or axis,");
7531 ystart2 += ystep_line;
7532 DrawTextSCentered(ystart2, font_info,
7533 "press the 'return' key.");
7534 ystart2 += ystep_line;
7535 DrawTextSCentered(ystart2, font_info,
7536 "To exit, press the 'escape' key.");
7539 BlitBitmapMasked(controller, drawto, 0, 0,
7540 controller->width, controller->height,
7541 controller_x, controller_y);
7543 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7544 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7546 BlitBitmapMasked(marker, drawto, 0, 0,
7547 marker->width, marker->height,
7548 marker_x, marker_y);
7550 if (!screen_initialized)
7551 FadeIn(REDRAW_FIELD);
7555 screen_initialized = TRUE;
7557 while (NextValidEvent(&event))
7561 case SDL_JOYAXISMOTION:
7562 if (event.jaxis.value > 20000 ||
7563 event.jaxis.value < -20000)
7565 for (j = 0; j < i; j++)
7566 if (steps[j].axis == event.jaxis.axis)
7571 if (step->marker != MARKER_AXIS_X &&
7572 step->marker != MARKER_AXIS_Y)
7575 step->axis = event.jaxis.axis;
7576 strcat(mapping, step->field);
7577 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7578 strcat(mapping, temp);
7586 case SDL_JOYHATMOTION:
7587 // ignore centering; we're probably just coming back
7588 // to the center from the previous item we set
7589 if (event.jhat.value == SDL_HAT_CENTERED)
7592 for (j = 0; j < i; j++)
7593 if (steps[j].hat == event.jhat.hat &&
7594 steps[j].hat_value == event.jhat.value)
7599 step->hat = event.jhat.hat;
7600 step->hat_value = event.jhat.value;
7601 strcat(mapping, step->field);
7602 snprintf(temp, sizeof(temp), ":h%u.%u,",
7603 event.jhat.hat, event.jhat.value );
7604 strcat(mapping, temp);
7611 case SDL_JOYBALLMOTION:
7614 case SDL_JOYBUTTONUP:
7615 for (j = 0; j < i; j++)
7616 if (steps[j].button == event.jbutton.button)
7621 step->button = event.jbutton.button;
7622 strcat(mapping, step->field);
7623 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7624 strcat(mapping, temp);
7631 case SDL_FINGERDOWN:
7632 case SDL_MOUSEBUTTONDOWN:
7640 if (event.key.keysym.sym == KSYM_BackSpace ||
7641 event.key.keysym.sym == KSYM_Back)
7653 prev_step = &steps[i - 1];
7654 strcpy(mapping, prev_step->mapping);
7661 if (event.key.keysym.sym == KSYM_space ||
7662 event.key.keysym.sym == KSYM_Return ||
7663 event.key.keysym.sym == KSYM_Menu)
7672 if (event.key.keysym.sym == KSYM_Escape)
7682 program.exit_function(0);
7689 // do not handle events for longer than standard frame delay period
7690 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7699 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7702 // activate mapping for this game
7703 SDL_GameControllerAddMapping(mapping);
7705 // save mapping to personal mappings
7706 SaveSetup_AddGameControllerMapping(mapping);
7709 // wait until the last pending event was removed from event queue
7710 while (NextValidEvent(&event));
7715 static int ConfigureJoystickMain(int player_nr)
7717 char *device_name = setup.input[player_nr].joy.device_name;
7718 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7719 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7720 int success = FALSE;
7723 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7724 return JOYSTICK_NOT_AVAILABLE;
7726 if (!joystick_active || !setup.input[player_nr].use_joystick)
7727 return JOYSTICK_NOT_AVAILABLE;
7730 FadeOut(REDRAW_FIELD);
7732 // close all joystick devices (potentially opened as game controllers)
7733 for (i = 0; i < SDL_NumJoysticks(); i++)
7734 SDLCloseJoystick(i);
7736 // open joystick device as plain joystick to configure as game controller
7737 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7739 // as the joystick was successfully opened before, this should not happen
7740 if (joystick == NULL)
7743 // create new game controller mapping (buttons and axes) for joystick device
7744 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7746 // close joystick (and maybe re-open as configured game controller later)
7747 SDL_JoystickClose(joystick);
7749 // re-open all joystick devices (potentially as game controllers)
7750 for (i = 0; i < SDL_NumJoysticks(); i++)
7753 // clear all joystick input actions for all joystick devices
7754 SDLClearJoystickState();
7756 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7759 void ConfigureJoystick(int player_nr)
7761 boolean state = ConfigureJoystickMain(player_nr);
7763 if (state != JOYSTICK_NOT_CONFIGURED)
7765 boolean success = (state == JOYSTICK_CONFIGURED);
7766 char message1[MAX_OUTPUT_LINESIZE + 1];
7767 char *message2 = (success ? "configured!" : "not available!");
7768 char *device_name = setup.input[player_nr].joy.device_name;
7769 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7770 int font_nr = FONT_TITLE_1;
7771 int font_height = getFontHeight(font_nr);
7772 int ypos1 = SYSIZE / 2 - font_height * 2;
7773 int ypos2 = SYSIZE / 2 - font_height * 1;
7774 unsigned int wait_frame_delay = 0;
7775 unsigned int wait_frame_delay_value = 2000;
7777 ResetDelayCounter(&wait_frame_delay);
7781 sprintf(message1, "Joystick %d", nr);
7783 DrawTextSCentered(ypos1, font_nr, message1);
7784 DrawTextSCentered(ypos2, font_nr, message2);
7786 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7792 DrawSetupScreen_Input();
7795 static boolean ConfigureVirtualButtonsMain(void)
7797 static char *customize_step_text[] =
7806 char grid_button[] =
7808 CHAR_GRID_BUTTON_LEFT,
7809 CHAR_GRID_BUTTON_RIGHT,
7810 CHAR_GRID_BUTTON_UP,
7811 CHAR_GRID_BUTTON_DOWN,
7812 CHAR_GRID_BUTTON_SNAP,
7813 CHAR_GRID_BUTTON_DROP
7815 int font_nr = FONT_INPUT_1_ACTIVE;
7816 int font_height = getFontHeight(font_nr);
7817 int ypos1 = SYSIZE / 2 - font_height * 2;
7818 int ypos2 = SYSIZE / 2 - font_height * 1;
7819 boolean success = FALSE;
7820 boolean finished = FALSE;
7822 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7823 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7824 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7825 boolean set_grid_button = FALSE;
7826 int nr = GRID_ACTIVE_NR();
7829 for (x = 0; x < MAX_GRID_XSIZE; x++)
7830 for (y = 0; y < MAX_GRID_YSIZE; y++)
7831 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7833 overlay.grid_button_highlight = grid_button[step_nr];
7836 FadeOut(REDRAW_FIELD);
7840 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7841 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7842 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7844 FadeIn(REDRAW_FIELD);
7846 SetOverlayShowGrid(TRUE);
7852 while (NextValidEvent(&event))
7856 case EVENT_KEYPRESS:
7858 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7860 // press 'Escape' to abort and keep the old key bindings
7861 if (key == KSYM_Escape)
7863 for (x = 0; x < MAX_GRID_XSIZE; x++)
7864 for (y = 0; y < MAX_GRID_YSIZE; y++)
7865 overlay.grid_button[x][y] = grid_button_old[x][y];
7867 FadeSkipNextFadeIn();
7874 // press 'Enter' to keep the existing key binding
7875 if (key == KSYM_Return ||
7881 else if (key == KSYM_BackSpace ||
7886 FadeSkipNextFadeIn();
7900 // all virtual buttons configured
7909 for (x = 0; x < MAX_GRID_XSIZE; x++)
7910 for (y = 0; y < MAX_GRID_YSIZE; y++)
7911 grid_button_tmp[x][y] = overlay.grid_button[x][y];
7913 overlay.grid_button_highlight = grid_button[step_nr];
7915 // query next virtual button
7919 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7920 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7921 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7925 case EVENT_KEYRELEASE:
7926 key_joystick_mapping = 0;
7929 case EVENT_BUTTONPRESS:
7930 case EVENT_BUTTONRELEASE:
7932 ButtonEvent *button = (ButtonEvent *)&event;
7934 button->x += video.screen_xoffset;
7935 button->y += video.screen_yoffset;
7937 x = button->x * overlay.grid_xsize / video.screen_width;
7938 y = button->y * overlay.grid_ysize / video.screen_height;
7940 if (button->type == EVENT_BUTTONPRESS)
7942 button_status = button->button;
7945 (overlay.grid_button[x][y] != grid_button[step_nr] ?
7946 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
7948 set_grid_button = TRUE;
7952 button_status = MB_RELEASED;
7957 case EVENT_MOTIONNOTIFY:
7959 MotionEvent *motion = (MotionEvent *)&event;
7961 motion->x += video.screen_xoffset;
7962 motion->y += video.screen_yoffset;
7964 x = motion->x * overlay.grid_xsize / video.screen_width;
7965 y = motion->y * overlay.grid_ysize / video.screen_height;
7967 set_grid_button = TRUE;
7971 case SDL_WINDOWEVENT:
7972 HandleWindowEvent((WindowEvent *) &event);
7974 // check if device has been rotated
7975 if (nr != GRID_ACTIVE_NR())
7977 nr = GRID_ACTIVE_NR();
7979 for (x = 0; x < MAX_GRID_XSIZE; x++)
7980 for (y = 0; y < MAX_GRID_YSIZE; y++)
7981 grid_button_old[x][y] = grid_button_tmp[x][y] =
7982 overlay.grid_button[x][y];
7987 case SDL_APP_WILLENTERBACKGROUND:
7988 case SDL_APP_DIDENTERBACKGROUND:
7989 case SDL_APP_WILLENTERFOREGROUND:
7990 case SDL_APP_DIDENTERFOREGROUND:
7991 HandlePauseResumeEvent((PauseResumeEvent *) &event);
7995 HandleOtherEvents(&event);
7999 if (set_grid_button)
8001 overlay.grid_button[x][y] =
8002 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8003 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8004 grid_button_tmp[x][y]);
8006 set_grid_button = FALSE;
8013 for (x = 0; x < MAX_GRID_XSIZE; x++)
8014 for (y = 0; y < MAX_GRID_YSIZE; y++)
8015 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8017 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8019 SetOverlayShowGrid(FALSE);
8024 void ConfigureVirtualButtons(void)
8026 boolean success = ConfigureVirtualButtonsMain();
8030 int font_nr = FONT_TITLE_1;
8031 int font_height = getFontHeight(font_nr);
8032 int ypos1 = SYSIZE / 2 - font_height * 2;
8033 int ypos2 = SYSIZE / 2 - font_height * 1;
8034 unsigned int wait_frame_delay = 0;
8035 unsigned int wait_frame_delay_value = 2000;
8037 ResetDelayCounter(&wait_frame_delay);
8041 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8042 DrawTextSCentered(ypos2, font_nr, "configured!");
8044 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8051 void DrawSetupScreen(void)
8053 if (setup_mode == SETUP_MODE_INPUT)
8054 DrawSetupScreen_Input();
8055 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8056 DrawChooseTree(&game_speed_current);
8057 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8058 DrawChooseTree(&scroll_delay_current);
8059 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8060 DrawChooseTree(&snapshot_mode_current);
8061 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8062 DrawChooseTree(&window_size_current);
8063 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8064 DrawChooseTree(&scaling_type_current);
8065 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8066 DrawChooseTree(&rendering_mode_current);
8067 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8068 DrawChooseTree(&vsync_mode_current);
8069 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8070 DrawChooseTree(&artwork.gfx_current);
8071 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8072 DrawChooseTree(&artwork.snd_current);
8073 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8074 DrawChooseTree(&artwork.mus_current);
8075 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8076 DrawChooseTree(&volume_simple_current);
8077 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8078 DrawChooseTree(&volume_loops_current);
8079 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8080 DrawChooseTree(&volume_music_current);
8081 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8082 DrawChooseTree(&touch_control_current);
8083 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8084 DrawChooseTree(&move_distance_current);
8085 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8086 DrawChooseTree(&drop_distance_current);
8087 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8088 DrawChooseTree(&transparency_current);
8089 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8090 DrawChooseTree(&grid_size_current[0][0]);
8091 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8092 DrawChooseTree(&grid_size_current[0][1]);
8093 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8094 DrawChooseTree(&grid_size_current[1][0]);
8095 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8096 DrawChooseTree(&grid_size_current[1][1]);
8098 DrawSetupScreen_Generic();
8100 PlayMenuSoundsAndMusic();
8103 void RedrawSetupScreenAfterFullscreenToggle(void)
8105 if (setup_mode == SETUP_MODE_GRAPHICS ||
8106 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8108 // update list selection from "setup.window_scaling_percent"
8109 execSetupGraphics_setWindowSizes(TRUE);
8115 void RedrawSetupScreenAfterScreenRotation(int nr)
8119 if (setup_mode == SETUP_MODE_TOUCH)
8121 // update virtual button settings (depending on screen orientation)
8124 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8126 // save already configured virtual buttons
8127 for (x = 0; x < MAX_GRID_XSIZE; x++)
8128 for (y = 0; y < MAX_GRID_YSIZE; y++)
8129 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8133 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8135 if (setup_mode == SETUP_MODE_INPUT)
8136 HandleSetupScreen_Input(mx, my, dx, dy, button);
8137 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8138 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8139 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8140 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8141 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8142 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8143 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8144 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8145 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8146 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8147 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8148 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8149 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8150 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8151 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8152 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8153 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8154 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8155 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8156 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8157 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8158 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8159 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8160 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8161 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8162 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8163 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8164 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8165 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8166 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8167 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8168 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8169 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8170 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8171 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8172 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8173 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8174 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8175 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8176 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8177 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8178 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8180 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8183 void HandleGameActions(void)
8185 if (setup.ask_on_game_over)
8188 if (game.restart_game_message != NULL)
8190 RequestRestartGame(game.restart_game_message);
8195 if (game_status != GAME_MODE_PLAYING)
8198 GameActions(); // main game loop
8200 if (tape.auto_play && !tape.playing)
8201 AutoPlayTape(); // continue automatically playing next tape
8205 // ---------- new screen button stuff --------------------------------------
8207 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
8211 case SCREEN_CTRL_ID_PREV_LEVEL:
8212 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
8213 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
8216 case SCREEN_CTRL_ID_NEXT_LEVEL:
8217 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
8218 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
8221 case SCREEN_CTRL_ID_FIRST_LEVEL:
8222 *x = mSX + GDI_ACTIVE_POS(menu.main.button.first_level.x);
8223 *y = mSY + GDI_ACTIVE_POS(menu.main.button.first_level.y);
8226 case SCREEN_CTRL_ID_LAST_LEVEL:
8227 *x = mSX + GDI_ACTIVE_POS(menu.main.button.last_level.x);
8228 *y = mSY + GDI_ACTIVE_POS(menu.main.button.last_level.y);
8231 case SCREEN_CTRL_ID_LEVEL_NUMBER:
8232 *x = mSX + GDI_ACTIVE_POS(menu.main.button.level_number.x);
8233 *y = mSY + GDI_ACTIVE_POS(menu.main.button.level_number.y);
8236 case SCREEN_CTRL_ID_PREV_PLAYER:
8237 *x = mSX + TILEX * 10;
8238 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
8241 case SCREEN_CTRL_ID_NEXT_PLAYER:
8242 *x = mSX + TILEX * 12;
8243 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
8246 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8247 *x = mSX + GDI_ACTIVE_POS(menu.main.button.insert_solution.x);
8248 *y = mSY + GDI_ACTIVE_POS(menu.main.button.insert_solution.y);
8251 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8252 *x = mSX + GDI_ACTIVE_POS(menu.main.button.play_solution.x);
8253 *y = mSY + GDI_ACTIVE_POS(menu.main.button.play_solution.y);
8257 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
8263 int gfx_unpressed, gfx_pressed;
8264 void (*get_gadget_position)(int *, int *, int);
8267 unsigned int event_mask;
8269 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8272 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8273 getScreenMenuButtonPos,
8274 SCREEN_CTRL_ID_PREV_LEVEL,
8276 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8280 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8281 getScreenMenuButtonPos,
8282 SCREEN_CTRL_ID_NEXT_LEVEL,
8284 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8288 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
8289 getScreenMenuButtonPos,
8290 SCREEN_CTRL_ID_FIRST_LEVEL,
8296 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
8297 getScreenMenuButtonPos,
8298 SCREEN_CTRL_ID_LAST_LEVEL,
8304 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
8305 getScreenMenuButtonPos,
8306 SCREEN_CTRL_ID_LEVEL_NUMBER,
8312 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8313 getScreenMenuButtonPos,
8314 SCREEN_CTRL_ID_PREV_PLAYER,
8316 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8320 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8321 getScreenMenuButtonPos,
8322 SCREEN_CTRL_ID_NEXT_PLAYER,
8324 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8328 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8329 getScreenMenuButtonPos,
8330 SCREEN_CTRL_ID_INSERT_SOLUTION,
8331 SCREEN_MASK_MAIN_HAS_SOLUTION,
8333 "insert solution tape"
8336 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8337 getScreenMenuButtonPos,
8338 SCREEN_CTRL_ID_PLAY_SOLUTION,
8339 SCREEN_MASK_MAIN_HAS_SOLUTION,
8341 "play solution tape"
8347 int gfx_unpressed, gfx_pressed;
8351 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8354 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8355 -1, -1, // these values are not constant, but can change at runtime
8356 SCREEN_CTRL_ID_SCROLL_UP,
8360 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8361 -1, -1, // these values are not constant, but can change at runtime
8362 SCREEN_CTRL_ID_SCROLL_DOWN,
8369 int gfx_unpressed, gfx_pressed;
8375 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8378 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8379 -1, -1, // these values are not constant, but can change at runtime
8380 -1, -1, // these values are not constant, but can change at runtime
8381 GD_TYPE_SCROLLBAR_VERTICAL,
8382 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8383 "scroll level series vertically"
8395 } textinput_info[NUM_SCREEN_TEXTINPUT] =
8398 IMG_SETUP_INPUT_TEXT,
8399 SCREEN_CTRL_ID_NETWORK_SERVER,
8400 -1, -1, // these values are not constant, but can change at runtime
8401 MAX_SETUP_TEXT_INPUT_LEN,
8402 network_server_hostname,
8403 "Network Server Hostname / IP"
8407 static void CreateScreenMenubuttons(void)
8409 struct GadgetInfo *gi;
8410 unsigned int event_mask;
8413 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8415 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8416 int gfx_unpressed, gfx_pressed;
8417 int x, y, width, height;
8418 int gd_x1, gd_x2, gd_y1, gd_y2;
8419 int id = menubutton_info[i].gadget_id;
8421 event_mask = menubutton_info[i].event_mask;
8423 menubutton_info[i].get_gadget_position(&x, &y, id);
8425 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8427 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8428 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8432 width = SC_MENUBUTTON_XSIZE;
8433 height = SC_MENUBUTTON_YSIZE;
8436 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8437 gfx_pressed = menubutton_info[i].gfx_pressed;
8438 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8439 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8440 gd_x1 = graphic_info[gfx_unpressed].src_x;
8441 gd_y1 = graphic_info[gfx_unpressed].src_y;
8442 gd_x2 = graphic_info[gfx_pressed].src_x;
8443 gd_y2 = graphic_info[gfx_pressed].src_y;
8445 gi = CreateGadget(GDI_CUSTOM_ID, id,
8446 GDI_CUSTOM_TYPE_ID, i,
8447 GDI_IMAGE_ID, gfx_unpressed,
8448 GDI_INFO_TEXT, menubutton_info[i].infotext,
8453 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8454 GDI_STATE, GD_BUTTON_UNPRESSED,
8455 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8456 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8457 GDI_DIRECT_DRAW, FALSE,
8458 GDI_EVENT_MASK, event_mask,
8459 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8463 Error(ERR_EXIT, "cannot create gadget");
8465 screen_gadget[id] = gi;
8469 static void CreateScreenScrollbuttons(void)
8471 struct GadgetInfo *gi;
8472 unsigned int event_mask;
8475 // these values are not constant, but can change at runtime
8476 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8477 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8478 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8479 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8481 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8483 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8484 int gfx_unpressed, gfx_pressed;
8485 int x, y, width, height;
8486 int gd_x1, gd_x2, gd_y1, gd_y2;
8487 int id = scrollbutton_info[i].gadget_id;
8489 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8491 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8492 y = mSY + scrollbutton_info[i].y;
8493 width = SC_SCROLLBUTTON_XSIZE;
8494 height = SC_SCROLLBUTTON_YSIZE;
8496 // correct scrollbar position if placed outside menu (playfield) area
8497 if (x > SX + SC_SCROLL_UP_XPOS)
8498 x = SX + SC_SCROLL_UP_XPOS;
8500 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8501 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8502 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8504 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8505 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8506 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8507 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8508 gd_x1 = graphic_info[gfx_unpressed].src_x;
8509 gd_y1 = graphic_info[gfx_unpressed].src_y;
8510 gd_x2 = graphic_info[gfx_pressed].src_x;
8511 gd_y2 = graphic_info[gfx_pressed].src_y;
8513 gi = CreateGadget(GDI_CUSTOM_ID, id,
8514 GDI_CUSTOM_TYPE_ID, i,
8515 GDI_IMAGE_ID, gfx_unpressed,
8516 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8521 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8522 GDI_STATE, GD_BUTTON_UNPRESSED,
8523 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8524 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8525 GDI_DIRECT_DRAW, FALSE,
8526 GDI_EVENT_MASK, event_mask,
8527 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8531 Error(ERR_EXIT, "cannot create gadget");
8533 screen_gadget[id] = gi;
8537 static void CreateScreenScrollbars(void)
8541 // these values are not constant, but can change at runtime
8542 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8543 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8544 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8545 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8547 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8549 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8550 int gfx_unpressed, gfx_pressed;
8551 int x, y, width, height;
8552 int gd_x1, gd_x2, gd_y1, gd_y2;
8553 struct GadgetInfo *gi;
8554 int items_max, items_visible, item_position;
8555 unsigned int event_mask;
8556 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8557 int id = scrollbar_info[i].gadget_id;
8559 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8561 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8562 y = mSY + scrollbar_info[i].y;
8563 width = scrollbar_info[i].width;
8564 height = scrollbar_info[i].height;
8566 // correct scrollbar position if placed outside menu (playfield) area
8567 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8568 x = SX + SC_SCROLL_VERTICAL_XPOS;
8570 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8571 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8573 items_max = num_page_entries;
8574 items_visible = num_page_entries;
8577 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8578 gfx_pressed = scrollbar_info[i].gfx_pressed;
8579 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8580 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8581 gd_x1 = graphic_info[gfx_unpressed].src_x;
8582 gd_y1 = graphic_info[gfx_unpressed].src_y;
8583 gd_x2 = graphic_info[gfx_pressed].src_x;
8584 gd_y2 = graphic_info[gfx_pressed].src_y;
8586 gi = CreateGadget(GDI_CUSTOM_ID, id,
8587 GDI_CUSTOM_TYPE_ID, i,
8588 GDI_IMAGE_ID, gfx_unpressed,
8589 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8594 GDI_TYPE, scrollbar_info[i].type,
8595 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8596 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8597 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8598 GDI_WHEEL_AREA_X, SX,
8599 GDI_WHEEL_AREA_Y, SY,
8600 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8601 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8602 GDI_STATE, GD_BUTTON_UNPRESSED,
8603 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8604 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8605 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8606 GDI_DIRECT_DRAW, FALSE,
8607 GDI_EVENT_MASK, event_mask,
8608 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8612 Error(ERR_EXIT, "cannot create gadget");
8614 screen_gadget[id] = gi;
8618 static void CreateScreenTextInputGadgets(void)
8622 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
8624 int graphic = textinput_info[i].graphic;
8625 struct GraphicInfo *gd = &graphic_info[graphic];
8626 int gd_x1 = gd->src_x;
8627 int gd_y1 = gd->src_y;
8628 int gd_x2 = gd->src_x + gd->active_xoffset;
8629 int gd_y2 = gd->src_y + gd->active_yoffset;
8630 struct GadgetInfo *gi;
8631 unsigned int event_mask;
8632 int id = textinput_info[i].gadget_id;
8633 int x = textinput_info[i].x;
8634 int y = textinput_info[i].y;
8636 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
8638 gi = CreateGadget(GDI_CUSTOM_ID, id,
8639 GDI_CUSTOM_TYPE_ID, i,
8640 GDI_INFO_TEXT, textinput_info[i].infotext,
8643 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
8644 GDI_TEXT_VALUE, textinput_info[i].value,
8645 GDI_TEXT_SIZE, textinput_info[i].size,
8646 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
8647 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
8648 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8649 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8650 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8651 GDI_DESIGN_WIDTH, gd->width,
8652 GDI_EVENT_MASK, event_mask,
8653 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8654 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
8658 Error(ERR_EXIT, "cannot create gadget");
8660 screen_gadget[id] = gi;
8664 void CreateScreenGadgets(void)
8666 CreateScreenMenubuttons();
8668 CreateScreenScrollbuttons();
8669 CreateScreenScrollbars();
8671 CreateScreenTextInputGadgets();
8674 void FreeScreenGadgets(void)
8678 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8679 FreeGadget(screen_gadget[i]);
8682 void MapScreenMenuGadgets(int screen_mask)
8686 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8687 if (screen_mask & menubutton_info[i].screen_mask)
8688 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8691 static void UnmapScreenMenuGadgets(int screen_mask)
8695 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8697 if (screen_mask & menubutton_info[i].screen_mask)
8699 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8701 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8702 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8703 screen_gadget[menubutton_info[i].gadget_id]->y,
8704 screen_gadget[menubutton_info[i].gadget_id]->width,
8705 screen_gadget[menubutton_info[i].gadget_id]->height);
8710 void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8713 MapScreenMenuGadgets(screen_mask);
8715 UnmapScreenMenuGadgets(screen_mask);
8718 void MapScreenGadgets(int num_entries)
8722 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8725 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8726 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8728 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8729 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8732 void MapScreenTreeGadgets(TreeInfo *ti)
8734 MapScreenGadgets(numTreeInfoInGroup(ti));
8737 static void HandleScreenGadgets(struct GadgetInfo *gi)
8739 int id = gi->custom_id;
8740 int button = gi->event.button;
8741 int step = (button == MB_LEFTBUTTON ? 1 :
8742 button == MB_MIDDLEBUTTON ? 5 :
8743 button == MB_RIGHTBUTTON ? 10 : 1);
8747 case SCREEN_CTRL_ID_PREV_LEVEL:
8748 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8751 case SCREEN_CTRL_ID_NEXT_LEVEL:
8752 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8755 case SCREEN_CTRL_ID_FIRST_LEVEL:
8756 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
8759 case SCREEN_CTRL_ID_LAST_LEVEL:
8760 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
8763 case SCREEN_CTRL_ID_LEVEL_NUMBER:
8764 CloseDoor(DOOR_CLOSE_2);
8765 SetGameStatus(GAME_MODE_LEVELNR);
8766 DrawChooseLevelNr();
8769 case SCREEN_CTRL_ID_PREV_PLAYER:
8770 HandleSetupScreen_Input_Player(step, -1);
8773 case SCREEN_CTRL_ID_NEXT_PLAYER:
8774 HandleSetupScreen_Input_Player(step, +1);
8777 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8778 InsertSolutionTape();
8781 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8785 case SCREEN_CTRL_ID_SCROLL_UP:
8786 if (game_status == GAME_MODE_LEVELS)
8787 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8788 else if (game_status == GAME_MODE_LEVELNR)
8789 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8790 else if (game_status == GAME_MODE_SETUP)
8791 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8792 else if (game_status == GAME_MODE_INFO)
8793 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8796 case SCREEN_CTRL_ID_SCROLL_DOWN:
8797 if (game_status == GAME_MODE_LEVELS)
8798 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8799 else if (game_status == GAME_MODE_LEVELNR)
8800 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8801 else if (game_status == GAME_MODE_SETUP)
8802 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8803 else if (game_status == GAME_MODE_INFO)
8804 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8807 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8808 if (game_status == GAME_MODE_LEVELS)
8809 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8810 else if (game_status == GAME_MODE_LEVELNR)
8811 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8812 else if (game_status == GAME_MODE_SETUP)
8813 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8814 else if (game_status == GAME_MODE_INFO)
8815 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8818 case SCREEN_CTRL_ID_NETWORK_SERVER:
8820 if (!strEqual(gi->textinput.value, ""))
8822 setString(&setup.network_server_hostname, gi->textinput.value);
8824 network.server_host = setup.network_server_hostname;
8828 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
8830 network.server_host = NULL;
8833 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
8834 network.server_host = NULL;
8836 execSetupGame_setNetworkServerText();
8848 void DumpScreenIdentifiers(void)
8852 Print("Active screen elements on current screen:\n");
8854 for (i = 0; main_controls[i].nr != -1; i++)
8856 struct MainControlInfo *mci = &main_controls[i];
8858 if (mci->button_graphic != -1)
8860 char *token = getTokenFromImageID(mci->button_graphic);
8862 Print("- '%s'\n", token);
8869 boolean DoScreenAction(int image_id)
8873 if (game_status != GAME_MODE_MAIN)
8876 for (i = 0; main_controls[i].nr != -1; i++)
8878 struct MainControlInfo *mci = &main_controls[i];
8879 struct MenuPosInfo *pos = mci->pos_button;
8881 if (mci->button_graphic == image_id)
8883 int x = mSX + pos->x;
8884 int y = mSY + pos->y;
8886 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);