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_TOUCH_PREV_PAGE 9
185 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 10
186 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 11
187 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 12
188 #define SCREEN_CTRL_ID_SCROLL_UP 13
189 #define SCREEN_CTRL_ID_SCROLL_DOWN 14
190 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 15
191 #define SCREEN_CTRL_ID_NETWORK_SERVER 16
193 #define NUM_SCREEN_GADGETS 17
195 #define NUM_SCREEN_MENUBUTTONS 13
196 #define NUM_SCREEN_SCROLLBUTTONS 2
197 #define NUM_SCREEN_SCROLLBARS 1
198 #define NUM_SCREEN_TEXTINPUT 1
200 #define SCREEN_MASK_MAIN (1 << 0)
201 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
202 #define SCREEN_MASK_INPUT (1 << 2)
203 #define SCREEN_MASK_TOUCH (1 << 3)
204 #define SCREEN_MASK_TOUCH2 (1 << 4)
206 // graphic position and size values for buttons and scrollbars
207 #define SC_MENUBUTTON_XSIZE TILEX
208 #define SC_MENUBUTTON_YSIZE TILEY
210 #define SC_SCROLLBUTTON_XSIZE TILEX
211 #define SC_SCROLLBUTTON_YSIZE TILEY
213 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
215 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
216 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
217 SC_SCROLLBUTTON_YSIZE)
219 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
220 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
222 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
223 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
224 SC_SCROLLBUTTON_YSIZE)
226 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
227 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
228 SC_SCROLL_VERTICAL_YSIZE)
230 #define SC_BORDER_SIZE 14
233 // forward declarations of internal functions
234 static void HandleScreenGadgets(struct GadgetInfo *);
235 static void HandleSetupScreen_Generic(int, int, int, int, int);
236 static void HandleSetupScreen_Input(int, int, int, int, int);
237 static void CustomizeKeyboard(int);
238 static void ConfigureJoystick(int);
239 static void ConfigureVirtualButtons(void);
240 static void execSetupGame(void);
241 static void execSetupGraphics(void);
242 static void execSetupSound(void);
243 static void execSetupTouch(void);
244 static void execSetupArtwork(void);
245 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
247 static void DrawChooseLevelSet(void);
248 static void DrawChooseLevelNr(void);
249 static void DrawInfoScreen(void);
250 static void DrawSetupScreen(void);
252 static void DrawInfoScreen_NotAvailable(char *, char *);
253 static void DrawInfoScreen_HelpAnim(int, int, boolean);
254 static void DrawInfoScreen_HelpText(int, int, int, int);
255 static void HandleInfoScreen_Main(int, int, int, int, int);
256 static void HandleInfoScreen_TitleScreen(int);
257 static void HandleInfoScreen_Elements(int);
258 static void HandleInfoScreen_Music(int);
259 static void HandleInfoScreen_Credits(int);
260 static void HandleInfoScreen_Program(int);
261 static void HandleInfoScreen_Version(int);
263 static void ModifyGameSpeedIfNeeded(void);
264 static void DisableVsyncIfNeeded(void);
266 static void MapScreenMenuGadgets(int);
267 static void UnmapScreenMenuGadgets(int);
268 static void MapScreenGadgets(int);
269 static void MapScreenTreeGadgets(TreeInfo *);
271 static void UpdateScreenMenuGadgets(int, boolean);
273 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
275 static int info_mode = INFO_MODE_MAIN;
276 static int setup_mode = SETUP_MODE_MAIN;
278 static TreeInfo *window_sizes = NULL;
279 static TreeInfo *window_size_current = NULL;
281 static TreeInfo *scaling_types = NULL;
282 static TreeInfo *scaling_type_current = NULL;
284 static TreeInfo *rendering_modes = NULL;
285 static TreeInfo *rendering_mode_current = NULL;
287 static TreeInfo *vsync_modes = NULL;
288 static TreeInfo *vsync_mode_current = NULL;
290 static TreeInfo *scroll_delays = NULL;
291 static TreeInfo *scroll_delay_current = NULL;
293 static TreeInfo *snapshot_modes = NULL;
294 static TreeInfo *snapshot_mode_current = NULL;
296 static TreeInfo *game_speeds_normal = NULL;
297 static TreeInfo *game_speeds_extended = NULL;
298 static TreeInfo *game_speeds = NULL;
299 static TreeInfo *game_speed_current = NULL;
301 static TreeInfo *volumes_simple = NULL;
302 static TreeInfo *volume_simple_current = NULL;
304 static TreeInfo *volumes_loops = NULL;
305 static TreeInfo *volume_loops_current = NULL;
307 static TreeInfo *volumes_music = NULL;
308 static TreeInfo *volume_music_current = NULL;
310 static TreeInfo *touch_controls = NULL;
311 static TreeInfo *touch_control_current = NULL;
313 static TreeInfo *move_distances = NULL;
314 static TreeInfo *move_distance_current = NULL;
316 static TreeInfo *drop_distances = NULL;
317 static TreeInfo *drop_distance_current = NULL;
319 static TreeInfo *transparencies = NULL;
320 static TreeInfo *transparency_current = NULL;
322 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
323 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
325 static TreeInfo *level_number = NULL;
326 static TreeInfo *level_number_current = NULL;
328 static struct ValueTextInfo window_sizes_list[] =
333 { 100, "100 % (Default)" },
346 static struct StringValueTextInfo scaling_types_list[] =
348 { SCALING_QUALITY_NEAREST, "Off" },
349 { SCALING_QUALITY_LINEAR, "Linear" },
350 { SCALING_QUALITY_BEST, "Anisotropic" },
355 static struct StringValueTextInfo rendering_modes_list[] =
357 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
358 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
360 // this mode may work under certain conditions, but does not work on Windows
361 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
363 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
368 static struct StringValueTextInfo vsync_modes_list[] =
370 { STR_VSYNC_MODE_OFF, "Off" },
371 { STR_VSYNC_MODE_NORMAL, "Normal" },
372 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
377 static struct ValueTextInfo game_speeds_list_normal[] =
388 static struct ValueTextInfo game_speeds_list_extended[] =
390 { 1000, "1 fps (Extremely Slow)" },
395 { 29, "35 fps (Original Supaplex)" },
397 { 20, "50 fps (=== Normal Speed ===)" },
398 { 16, "60 fps (60 Hz VSync Speed)" },
399 { 14, "70 fps (Maximum Supaplex)" },
403 { 1, "1000 fps (Extremely Fast)" },
408 static struct ValueTextInfo *game_speeds_list;
410 static struct ValueTextInfo scroll_delays_list[] =
412 { 0, "0 Tiles (No Scroll Delay)" },
415 { 3, "3 Tiles (Default)" },
420 { 8, "8 Tiles (Maximum Scroll Delay)"},
425 static struct StringValueTextInfo snapshot_modes_list[] =
427 { STR_SNAPSHOT_MODE_OFF, "Off" },
428 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
429 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
430 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
435 static struct ValueTextInfo volumes_list[] =
455 static struct StringValueTextInfo touch_controls_list[] =
457 { TOUCH_CONTROL_OFF, "Off" },
458 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
459 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
460 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
465 static struct ValueTextInfo distances_list[] =
480 static struct ValueTextInfo transparencies_list[] =
482 { 0, "0 % (Opaque)" },
492 { 100, "100 % (Invisible)" },
497 static struct ValueTextInfo grid_sizes_list[] =
533 static int align_xoffset = 0;
534 static int align_yoffset = 0;
536 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
537 (s) <= GAME_MODE_SETUP ? (s) : \
538 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
539 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
541 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
542 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
543 (i) <= INFO_MODE_LEVELSET ? (i) : \
546 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
547 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
548 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
549 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
550 SETUP_MODE_CHOOSE_ARTWORK : \
551 SETUP_MODE_CHOOSE_OTHER)
553 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
554 menu.draw_xoffset[GAME_MODE_INFO] : \
555 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
556 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
557 menu.draw_yoffset[GAME_MODE_INFO] : \
558 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
559 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
560 menu.extra_spacing[GAME_MODE_INFO] : \
561 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
563 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
564 menu.draw_xoffset[GAME_MODE_SETUP] : \
565 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
566 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
567 menu.draw_yoffset[GAME_MODE_SETUP] : \
568 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
569 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
570 menu.extra_spacing[GAME_MODE_SETUP] : \
571 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
573 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
574 DRAW_XOFFSET_INFO(info_mode) : \
575 (s) == GAME_MODE_SETUP ? \
576 DRAW_XOFFSET_SETUP(setup_mode) : \
577 menu.draw_xoffset[DRAW_MODE(s)])
578 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
579 DRAW_YOFFSET_INFO(info_mode) : \
580 (s) == GAME_MODE_SETUP ? \
581 DRAW_YOFFSET_SETUP(setup_mode) : \
582 menu.draw_yoffset[DRAW_MODE(s)])
583 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
584 EXTRA_SPACING_INFO(info_mode) : \
585 (s) == GAME_MODE_SETUP ? \
586 EXTRA_SPACING_SETUP(setup_mode) : \
587 menu.extra_spacing[DRAW_MODE(s)])
589 #define mSX (SX + DRAW_XOFFSET(game_status))
590 #define mSY (SY + DRAW_YOFFSET(game_status))
592 #define amSX (mSX + align_xoffset)
593 #define amSY (mSY + align_yoffset)
595 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
596 menu.list_size[game_status] : \
597 MAX_MENU_ENTRIES_ON_SCREEN)
599 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
600 NUM_MENU_ENTRIES_ON_SCREEN)
603 // title display and control definitions
605 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
606 2 * MAX_NUM_TITLE_MESSAGES)
608 #define NO_DIRECT_LEVEL_SELECT (-1)
611 static int num_title_screens = 0;
613 struct TitleControlInfo
622 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
624 // main menu display and control definitions
626 #define MAIN_CONTROL_NAME 0
627 #define MAIN_CONTROL_LEVELS 1
628 #define MAIN_CONTROL_SCORES 2
629 #define MAIN_CONTROL_EDITOR 3
630 #define MAIN_CONTROL_INFO 4
631 #define MAIN_CONTROL_GAME 5
632 #define MAIN_CONTROL_SETUP 6
633 #define MAIN_CONTROL_QUIT 7
634 #define MAIN_CONTROL_PREV_LEVEL 8
635 #define MAIN_CONTROL_NEXT_LEVEL 9
636 #define MAIN_CONTROL_FIRST_LEVEL 10
637 #define MAIN_CONTROL_LAST_LEVEL 11
638 #define MAIN_CONTROL_LEVEL_NUMBER 12
639 #define MAIN_CONTROL_LEVEL_INFO_1 13
640 #define MAIN_CONTROL_LEVEL_INFO_2 14
641 #define MAIN_CONTROL_LEVEL_NAME 15
642 #define MAIN_CONTROL_LEVEL_AUTHOR 16
643 #define MAIN_CONTROL_LEVEL_YEAR 17
644 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
645 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
646 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
647 #define MAIN_CONTROL_TITLE_1 21
648 #define MAIN_CONTROL_TITLE_2 22
649 #define MAIN_CONTROL_TITLE_3 23
651 static char str_main_text_name[10];
652 static char str_main_text_first_level[10];
653 static char str_main_text_last_level[10];
654 static char str_main_text_level_number[10];
656 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
658 static char *main_text_name = str_main_text_name;
659 static char *main_text_first_level = str_main_text_first_level;
660 static char *main_text_last_level = str_main_text_last_level;
661 static char *main_text_level_number = str_main_text_level_number;
662 static char *main_text_levels = "Levelset";
663 static char *main_text_scores = "Hall Of Fame";
664 static char *main_text_editor = "Level Creator";
665 static char *main_text_info = "Info Screen";
666 static char *main_text_game = "Start Game";
667 static char *main_text_setup = "Setup";
668 static char *main_text_quit = "Quit";
669 static char *main_text_level_name = level.name;
670 static char *main_text_level_author = level.author;
671 static char *main_text_level_year = NULL;
672 static char *main_text_level_imported_from = NULL;
673 static char *main_text_level_imported_by = NULL;
674 static char *main_text_level_tested_by = NULL;
675 static char *main_text_title_1 = NULL;
676 static char *main_text_title_2 = NULL;
677 static char *main_text_title_3 = NULL;
679 struct MainControlInfo
683 struct MenuPosInfo *pos_button;
686 struct TextPosInfo *pos_text;
689 struct TextPosInfo *pos_input;
693 static struct MainControlInfo main_controls[] =
697 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
698 &menu.main.text.name, &main_text_name,
699 &menu.main.input.name, &setup.player_name,
703 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
704 &menu.main.text.levels, &main_text_levels,
709 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
710 &menu.main.text.scores, &main_text_scores,
715 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
716 &menu.main.text.editor, &main_text_editor,
721 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
722 &menu.main.text.info, &main_text_info,
727 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
728 &menu.main.text.game, &main_text_game,
733 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
734 &menu.main.text.setup, &main_text_setup,
739 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
740 &menu.main.text.quit, &main_text_quit,
744 MAIN_CONTROL_PREV_LEVEL,
750 MAIN_CONTROL_NEXT_LEVEL,
756 MAIN_CONTROL_FIRST_LEVEL,
758 &menu.main.text.first_level, &main_text_first_level,
762 MAIN_CONTROL_LAST_LEVEL,
764 &menu.main.text.last_level, &main_text_last_level,
768 MAIN_CONTROL_LEVEL_NUMBER,
770 &menu.main.text.level_number, &main_text_level_number,
774 MAIN_CONTROL_LEVEL_INFO_1,
776 &menu.main.text.level_info_1, NULL,
780 MAIN_CONTROL_LEVEL_INFO_2,
782 &menu.main.text.level_info_2, NULL,
786 MAIN_CONTROL_LEVEL_NAME,
788 &menu.main.text.level_name, &main_text_level_name,
792 MAIN_CONTROL_LEVEL_AUTHOR,
794 &menu.main.text.level_author, &main_text_level_author,
798 MAIN_CONTROL_LEVEL_YEAR,
800 &menu.main.text.level_year, &main_text_level_year,
804 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
806 &menu.main.text.level_imported_from, &main_text_level_imported_from,
810 MAIN_CONTROL_LEVEL_IMPORTED_BY,
812 &menu.main.text.level_imported_by, &main_text_level_imported_by,
816 MAIN_CONTROL_LEVEL_TESTED_BY,
818 &menu.main.text.level_tested_by, &main_text_level_tested_by,
822 MAIN_CONTROL_TITLE_1,
824 &menu.main.text.title_1, &main_text_title_1,
828 MAIN_CONTROL_TITLE_2,
830 &menu.main.text.title_2, &main_text_title_2,
834 MAIN_CONTROL_TITLE_3,
836 &menu.main.text.title_3, &main_text_title_3,
849 static int getTitleScreenGraphic(int nr, boolean initial)
851 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
854 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
856 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
860 static int getTitleScreenGameMode(boolean initial)
862 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
866 static int getTitleMessageGameMode(boolean initial)
868 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
871 static int getTitleAnimMode(struct TitleControlInfo *tci)
873 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
875 return base + tci->local_nr;
879 static int getTitleScreenBackground(boolean initial)
881 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
886 static int getTitleMessageBackground(int nr, boolean initial)
888 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
892 static int getTitleBackground(int nr, boolean initial, boolean is_image)
894 int base = (is_image ?
895 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
896 IMG_BACKGROUND_TITLESCREEN_1) :
897 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
898 IMG_BACKGROUND_TITLEMESSAGE_1));
899 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
900 IMG_BACKGROUND_TITLE);
901 int graphic_local = base + nr;
903 if (graphic_info[graphic_local].bitmap != NULL)
904 return graphic_local;
906 if (graphic_info[graphic_global].bitmap != NULL)
907 return graphic_global;
909 return IMG_UNDEFINED;
912 static int getTitleSound(struct TitleControlInfo *tci)
914 boolean is_image = tci->is_image;
915 int initial = tci->initial;
916 int nr = tci->local_nr;
917 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
918 int base = (is_image ?
919 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
920 SND_BACKGROUND_TITLESCREEN_1) :
921 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
922 SND_BACKGROUND_TITLEMESSAGE_1));
923 int sound_global = menu.sound[mode];
924 int sound_local = base + nr;
927 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
928 nr, initial, is_image,
929 sound_global, getSoundListEntry(sound_global)->filename,
930 sound_local, getSoundListEntry(sound_local)->filename);
933 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
936 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
939 return SND_UNDEFINED;
942 static int getTitleMusic(struct TitleControlInfo *tci)
944 boolean is_image = tci->is_image;
945 int initial = tci->initial;
946 int nr = tci->local_nr;
947 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
948 int base = (is_image ?
949 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
950 MUS_BACKGROUND_TITLESCREEN_1) :
951 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
952 MUS_BACKGROUND_TITLEMESSAGE_1));
953 int music_global = menu.music[mode];
954 int music_local = base + nr;
957 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
958 nr, initial, is_image,
959 music_global, getMusicListEntry(music_global)->filename,
960 music_local, getMusicListEntry(music_local)->filename);
963 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
966 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
969 return MUS_UNDEFINED;
972 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
974 boolean is_image = tci->is_image;
975 boolean initial = tci->initial;
976 boolean first = tci->first;
977 int nr = tci->local_nr;
978 struct TitleMessageInfo tmi;
979 struct TitleFadingInfo ti;
981 tmi = (is_image ? (initial ? (first ?
982 titlescreen_initial_first[nr] :
983 titlescreen_initial[nr])
985 titlescreen_first[nr] :
987 : (initial ? (first ?
988 titlemessage_initial_first[nr] :
989 titlemessage_initial[nr])
991 titlemessage_first[nr] :
994 ti.fade_mode = tmi.fade_mode;
995 ti.fade_delay = tmi.fade_delay;
996 ti.post_delay = tmi.post_delay;
997 ti.auto_delay = tmi.auto_delay;
998 ti.auto_delay_unit = tmi.auto_delay_unit;
1003 static int compareTitleControlInfo(const void *object1, const void *object2)
1005 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1006 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1009 if (tci1->initial != tci2->initial)
1010 compare_result = (tci1->initial ? -1 : +1);
1011 else if (tci1->sort_priority != tci2->sort_priority)
1012 compare_result = tci1->sort_priority - tci2->sort_priority;
1013 else if (tci1->is_image != tci2->is_image)
1014 compare_result = (tci1->is_image ? -1 : +1);
1016 compare_result = tci1->local_nr - tci2->local_nr;
1018 return compare_result;
1021 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1023 int nr, int sort_priority)
1025 title_controls[num_title_screens].is_image = is_image;
1026 title_controls[num_title_screens].initial = initial;
1027 title_controls[num_title_screens].local_nr = nr;
1028 title_controls[num_title_screens].sort_priority = sort_priority;
1030 title_controls[num_title_screens].first = FALSE; // will be set later
1032 num_title_screens++;
1035 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1039 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1041 int graphic = getTitleScreenGraphic(i, initial);
1042 Bitmap *bitmap = graphic_info[graphic].bitmap;
1043 int sort_priority = graphic_info[graphic].sort_priority;
1046 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1049 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1051 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1052 char *filename = getLevelSetTitleMessageFilename(i, initial);
1053 int sort_priority = tmi->sort_priority;
1055 if (filename != NULL)
1056 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1060 static void InitializeTitleControls(boolean show_title_initial)
1062 num_title_screens = 0;
1064 // 1st step: initialize title screens for game start (only when starting)
1065 if (show_title_initial)
1066 InitializeTitleControls_CheckTitleInfo(TRUE);
1068 // 2nd step: initialize title screens for current level set
1069 InitializeTitleControls_CheckTitleInfo(FALSE);
1071 // sort title screens according to sort_priority and title number
1072 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1073 compareTitleControlInfo);
1075 // mark first title screen
1076 title_controls[0].first = TRUE;
1079 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1081 return (pos != NULL && pos->x != -1 && pos->y != -1);
1084 static boolean visibleTextPos(struct TextPosInfo *pos)
1086 return (pos != NULL && pos->x != -1 && pos->y != -1);
1089 static void InitializeMainControls(void)
1091 boolean local_team_mode = (!network.enabled && setup.team_mode);
1094 // set main control text values to dynamically determined values
1095 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1097 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1098 menu.main.text.first_level.size));
1099 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1100 menu.main.text.last_level.size));
1101 strcpy(main_text_level_number, int2str(level_nr,
1102 menu.main.text.level_number.size));
1104 main_text_level_year = leveldir_current->year;
1105 main_text_level_imported_from = leveldir_current->imported_from;
1106 main_text_level_imported_by = leveldir_current->imported_by;
1107 main_text_level_tested_by = leveldir_current->tested_by;
1109 main_text_title_1 = getConfigProgramTitleString();
1110 main_text_title_2 = getConfigProgramCopyrightString();
1111 main_text_title_3 = getConfigProgramCompanyString();
1113 // set main control screen positions to dynamically determined values
1114 for (i = 0; main_controls[i].nr != -1; i++)
1116 struct MainControlInfo *mci = &main_controls[i];
1118 struct MenuPosInfo *pos_button = mci->pos_button;
1119 struct TextPosInfo *pos_text = mci->pos_text;
1120 struct TextPosInfo *pos_input = mci->pos_input;
1121 char *text = (mci->text ? *mci->text : NULL);
1122 char *input = (mci->input ? *mci->input : NULL);
1123 int button_graphic = mci->button_graphic;
1124 int font_text = (pos_text ? pos_text->font : -1);
1125 int font_input = (pos_input ? pos_input->font : -1);
1127 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1128 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1129 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1130 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1131 int text_chars = (text != NULL ? strlen(text) : 0);
1132 int input_chars = (input != NULL ? strlen(input) : 0);
1135 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1137 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1138 int text_width = font_text_width * text_chars;
1139 int text_height = font_text_height;
1140 int input_width = font_input_width * input_chars;
1141 int input_height = font_input_height;
1143 if (nr == MAIN_CONTROL_NAME)
1145 menu.main.input.name.width = input_width;
1146 menu.main.input.name.height = input_height;
1149 if (pos_button != NULL) // (x/y may be -1/-1 here)
1151 pos_button->width = button_width;
1152 pos_button->height = button_height;
1155 if (pos_text != NULL) // (x/y may be -1/-1 here)
1157 // calculate text size -- needed for text alignment
1158 boolean calculate_text_size = (text != NULL);
1160 if (pos_text->width == -1 || calculate_text_size)
1161 pos_text->width = text_width;
1162 if (pos_text->height == -1 || calculate_text_size)
1163 pos_text->height = text_height;
1165 if (visibleMenuPos(pos_button))
1167 if (pos_text->x == -1)
1168 pos_text->x = pos_button->x + pos_button->width;
1169 if (pos_text->y == -1)
1171 pos_button->y + (pos_button->height - pos_text->height) / 2;
1175 if (pos_input != NULL) // (x/y may be -1/-1 here)
1177 if (visibleTextPos(pos_text))
1179 if (pos_input->x == -1)
1180 pos_input->x = pos_text->x + pos_text->width;
1181 if (pos_input->y == -1)
1182 pos_input->y = pos_text->y;
1185 if (pos_input->width == -1)
1186 pos_input->width = input_width;
1187 if (pos_input->height == -1)
1188 pos_input->height = input_height;
1193 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1194 int graphic, boolean pressed)
1196 struct GraphicInfo *g = &graphic_info[graphic];
1199 int xoffset = (pressed ? g->pressed_xoffset : 0);
1200 int yoffset = (pressed ? g->pressed_yoffset : 0);
1202 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1204 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1205 g->width, g->height, dst_x, dst_y);
1208 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1209 boolean active_input,
1210 boolean pressed_button)
1214 for (i = 0; main_controls[i].nr != -1; i++)
1216 struct MainControlInfo *mci = &main_controls[i];
1218 if (mci->nr == nr || nr == -1)
1220 struct MenuPosInfo *pos_button = mci->pos_button;
1221 struct TextPosInfo *pos_text = mci->pos_text;
1222 struct TextPosInfo *pos_input = mci->pos_input;
1223 char *text = (mci->text ? *mci->text : NULL);
1224 char *input = (mci->input ? *mci->input : NULL);
1225 int button_graphic = mci->button_graphic;
1226 int font_text = (pos_text ? pos_text->font : -1);
1227 int font_input = (pos_input ? pos_input->font : -1);
1231 button_graphic = BUTTON_ACTIVE(button_graphic);
1232 font_text = FONT_ACTIVE(font_text);
1237 font_input = FONT_ACTIVE(font_input);
1240 if (visibleMenuPos(pos_button))
1242 struct MenuPosInfo *pos = pos_button;
1243 int x = mSX + pos->x;
1244 int y = mSY + pos->y;
1246 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1247 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1250 if (visibleTextPos(pos_text) && text != NULL)
1252 struct TextPosInfo *pos = pos_text;
1253 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1254 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1257 // (check why/if this is needed)
1258 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1260 DrawText(x, y, text, font_text);
1263 if (visibleTextPos(pos_input) && input != NULL)
1265 struct TextPosInfo *pos = pos_input;
1266 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1267 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1270 // (check why/if this is needed)
1271 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1273 DrawText(x, y, input, font_input);
1279 static void DrawCursorAndText_Main(int nr, boolean active_text,
1280 boolean pressed_button)
1282 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1286 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1287 boolean pressed_button)
1289 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1293 static struct MainControlInfo *getMainControlInfo(int nr)
1297 for (i = 0; main_controls[i].nr != -1; i++)
1298 if (main_controls[i].nr == nr)
1299 return &main_controls[i];
1304 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1309 int rect_x = ALIGNED_TEXT_XPOS(rect);
1310 int rect_y = ALIGNED_TEXT_YPOS(rect);
1312 return (x >= rect_x && x < rect_x + rect->width &&
1313 y >= rect_y && y < rect_y + rect->height);
1316 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1321 int rect_x = ALIGNED_TEXT_XPOS(rect);
1322 int rect_y = ALIGNED_TEXT_YPOS(rect);
1325 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1326 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1327 (x >= rect_x && x < rect_x + rect->width &&
1328 y >= rect_y && y < rect_y + rect->height));
1331 return (x >= rect_x && x < rect_x + rect->width &&
1332 y >= rect_y && y < rect_y + rect->height);
1335 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1337 int rect_width = preview->xsize * preview->tile_size;
1338 int rect_height = preview->ysize * preview->tile_size;
1339 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1340 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1342 return (x >= rect_x && x < rect_x + rect_width &&
1343 y >= rect_y && y < rect_y + rect_height);
1346 static void AdjustScrollbar(int id, int items_max, int items_visible,
1349 struct GadgetInfo *gi = screen_gadget[id];
1351 if (item_position > items_max - items_visible)
1352 item_position = items_max - items_visible;
1354 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1355 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1356 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1359 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1361 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1365 static void clearMenuListArea(void)
1367 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1369 // correct scrollbar position if placed outside menu (playfield) area
1370 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1371 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1373 // clear menu list area, but not title or scrollbar
1374 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1375 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1378 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1380 static int cursor_array[MAX_LEV_FIELDY];
1381 int x = amSX + TILEX * xpos;
1382 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1387 cursor_array[ypos] = graphic;
1389 graphic = cursor_array[ypos];
1393 graphic = BUTTON_ACTIVE(graphic);
1395 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1396 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1399 static void initCursor(int ypos, int graphic)
1401 drawCursorExt(0, ypos, FALSE, graphic);
1404 static void drawCursor(int ypos, boolean active)
1406 drawCursorExt(0, ypos, active, -1);
1409 static void drawCursorXY(int xpos, int ypos, int graphic)
1411 drawCursorExt(xpos, ypos, FALSE, graphic);
1414 static void drawChooseTreeCursor(int ypos, boolean active)
1416 drawCursorExt(0, ypos, active, -1);
1419 static void DrawHeadline(void)
1421 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1422 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1425 static void DrawTitleScreenImage(int nr, boolean initial)
1427 int graphic = getTitleScreenGraphic(nr, initial);
1428 Bitmap *bitmap = graphic_info[graphic].bitmap;
1429 int width = graphic_info[graphic].width;
1430 int height = graphic_info[graphic].height;
1431 int src_x = graphic_info[graphic].src_x;
1432 int src_y = graphic_info[graphic].src_y;
1438 if (width > WIN_XSIZE)
1440 // image width too large for window => center image horizontally
1441 src_x = (width - WIN_XSIZE) / 2;
1445 if (height > WIN_YSIZE)
1447 // image height too large for window => center image vertically
1448 src_y = (height - WIN_YSIZE) / 2;
1452 // always display title screens centered
1453 dst_x = (WIN_XSIZE - width) / 2;
1454 dst_y = (WIN_YSIZE - height) / 2;
1456 SetDrawBackgroundMask(REDRAW_ALL);
1457 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1459 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1461 if (DrawingOnBackground(dst_x, dst_y))
1462 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1464 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1466 redraw_mask = REDRAW_ALL;
1469 static void DrawTitleScreenMessage(int nr, boolean initial)
1471 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1472 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1474 if (filename == NULL)
1477 // force TITLE font on title message screen
1478 SetFontStatus(getTitleMessageGameMode(initial));
1480 // if chars *and* width set to "-1", automatically determine width
1481 if (tmi->chars == -1 && tmi->width == -1)
1482 tmi->width = viewport.window[game_status].width;
1484 // if lines *and* height set to "-1", automatically determine height
1485 if (tmi->lines == -1 && tmi->height == -1)
1486 tmi->height = viewport.window[game_status].height;
1488 // if chars set to "-1", automatically determine by text and font width
1489 if (tmi->chars == -1)
1490 tmi->chars = tmi->width / getFontWidth(tmi->font);
1492 tmi->width = tmi->chars * getFontWidth(tmi->font);
1494 // if lines set to "-1", automatically determine by text and font height
1495 if (tmi->lines == -1)
1496 tmi->lines = tmi->height / getFontHeight(tmi->font);
1498 tmi->height = tmi->lines * getFontHeight(tmi->font);
1500 // if x set to "-1", automatically determine by width and alignment
1502 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1504 // if y set to "-1", automatically determine by height and alignment
1506 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1508 SetDrawBackgroundMask(REDRAW_ALL);
1509 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1511 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1513 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1514 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1515 tmi->autowrap, tmi->centered, tmi->parse_comments);
1520 static void DrawTitleScreen(void)
1522 KeyboardAutoRepeatOff();
1524 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1527 static boolean CheckTitleScreen(boolean levelset_has_changed)
1529 static boolean show_title_initial = TRUE;
1530 boolean show_titlescreen = FALSE;
1532 // needed to be able to skip title screen, if no image or message defined
1533 InitializeTitleControls(show_title_initial);
1535 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1536 show_titlescreen = TRUE;
1538 // show initial title images and messages only once at program start
1539 show_title_initial = FALSE;
1541 return (show_titlescreen && num_title_screens > 0);
1544 void DrawMainMenu(void)
1546 static LevelDirTree *leveldir_last_valid = NULL;
1547 boolean levelset_has_changed = FALSE;
1548 int fade_mask = REDRAW_FIELD;
1550 LimitScreenUpdates(FALSE);
1552 FadeSetLeaveScreen();
1554 // do not fade out here -- function may continue and fade on editor screen
1557 FadeMenuSoundsAndMusic();
1559 ExpireSoundLoops(FALSE);
1561 KeyboardAutoRepeatOn();
1563 audio.sound_deactivated = FALSE;
1567 // needed if last screen was the playing screen, invoked from level editor
1568 if (level_editor_test_game)
1570 CloseDoor(DOOR_CLOSE_ALL);
1572 SetGameStatus(GAME_MODE_EDITOR);
1579 // needed if last screen was the setup screen and fullscreen state changed
1580 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1581 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1583 // leveldir_current may be invalid (level group, parent link)
1584 if (!validLevelSeries(leveldir_current))
1585 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1587 if (leveldir_current != leveldir_last_valid)
1588 levelset_has_changed = TRUE;
1590 // store valid level series information
1591 leveldir_last_valid = leveldir_current;
1593 init_last = init; // switch to new busy animation
1595 // needed if last screen (level choice) changed graphics, sounds or music
1596 ReloadCustomArtwork(0);
1598 if (CheckTitleScreen(levelset_has_changed))
1600 SetGameStatus(GAME_MODE_TITLE);
1607 if (redraw_mask & REDRAW_ALL)
1608 fade_mask = REDRAW_ALL;
1611 fade_mask = REDRAW_ALL;
1615 // needed if different viewport properties defined for menues
1616 ChangeViewportPropertiesIfNeeded();
1618 SetDrawtoField(DRAW_TO_BACKBUFFER);
1620 // level_nr may have been set to value over handicap with level editor
1621 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1622 level_nr = leveldir_current->handicap_level;
1624 LoadLevel(level_nr);
1625 LoadScore(level_nr);
1627 SaveLevelSetup_SeriesInfo();
1629 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1630 SetDrawDeactivationMask(REDRAW_NONE);
1631 SetDrawBackgroundMask(REDRAW_FIELD);
1633 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1636 if (fade_mask == REDRAW_ALL)
1637 RedrawGlobalBorder();
1642 InitializeMainControls();
1644 DrawCursorAndText_Main(-1, FALSE, FALSE);
1645 DrawPreviewLevelInitial();
1646 DrawNetworkPlayers();
1648 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1651 if (TAPE_IS_EMPTY(tape))
1653 DrawCompleteVideoDisplay();
1655 PlayMenuSoundsAndMusic();
1657 // create gadgets for main menu screen
1658 FreeScreenGadgets();
1659 CreateScreenGadgets();
1661 // may be required if audio buttons shown on tape and changed in setup menu
1663 CreateGameButtons();
1665 // map gadgets for main menu screen
1667 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1668 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1670 // copy actual game door content to door double buffer for OpenDoor()
1671 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1672 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1674 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1676 DrawMaskedBorder(fade_mask);
1681 // update screen area with special editor door
1682 redraw_mask |= REDRAW_ALL;
1685 SetMouseCursor(CURSOR_DEFAULT);
1687 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1690 static void gotoTopLevelDir(void)
1692 // move upwards until inside (but not above) top level directory
1693 while (leveldir_current->node_parent &&
1694 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1696 // write a "path" into level tree for easy navigation to last level
1697 if (leveldir_current->node_parent->node_group->cl_first == -1)
1699 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1700 int leveldir_pos = posTreeInfo(leveldir_current);
1701 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1702 int cl_first, cl_cursor;
1704 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1705 cl_cursor = leveldir_pos - cl_first;
1707 leveldir_current->node_parent->node_group->cl_first = cl_first;
1708 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1711 leveldir_current = leveldir_current->node_parent;
1715 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1717 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1719 return (use_frame_counter ? video.frame_counter : Counter());
1722 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1723 struct TitleFadingInfo *fi)
1725 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1728 static void ResetTitleAutoDelay(unsigned int *counter_var,
1729 struct TitleFadingInfo *fi)
1731 *counter_var = getAutoDelayCounter(fi);
1734 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1736 static unsigned int title_delay = 0;
1737 static int title_screen_nr = 0;
1738 static int last_sound = -1, last_music = -1;
1739 boolean return_to_main_menu = FALSE;
1740 struct TitleControlInfo *tci;
1743 if (button == MB_MENU_INITIALIZE)
1746 title_screen_nr = 0;
1747 tci = &title_controls[title_screen_nr];
1749 SetAnimStatus(getTitleAnimMode(tci));
1751 last_sound = SND_UNDEFINED;
1752 last_music = MUS_UNDEFINED;
1754 if (num_title_screens != 0)
1756 FadeSetEnterScreen();
1758 // use individual title fading instead of global "enter screen" fading
1759 fading = getTitleFading(tci);
1762 if (game_status_last_screen == GAME_MODE_INFO)
1764 if (num_title_screens == 0)
1766 // switch game mode from title screen mode back to info screen mode
1767 SetGameStatus(GAME_MODE_INFO);
1769 // store that last screen was info screen, not main menu screen
1770 game_status_last_screen = GAME_MODE_INFO;
1772 DrawInfoScreen_NotAvailable("Title screen information:",
1773 "No title screen for this level set.");
1778 FadeMenuSoundsAndMusic();
1780 FadeOut(REDRAW_ALL);
1782 // title screens may have different window size
1783 ChangeViewportPropertiesIfNeeded();
1785 // only required to update logic for redrawing global border
1789 DrawTitleScreenImage(tci->local_nr, tci->initial);
1791 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1793 sound = getTitleSound(tci);
1794 music = getTitleMusic(tci);
1796 if (sound != last_sound)
1797 PlayMenuSoundExt(sound);
1798 if (music != last_music)
1799 PlayMenuMusicExt(music);
1804 SetMouseCursor(CURSOR_NONE);
1808 ResetTitleAutoDelay(&title_delay, &fading);
1813 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1814 button = MB_MENU_CHOICE;
1816 if (button == MB_MENU_LEAVE)
1818 return_to_main_menu = TRUE;
1820 else if (button == MB_MENU_CHOICE)
1822 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1824 SetGameStatus(GAME_MODE_INFO);
1826 info_mode = INFO_MODE_MAIN;
1835 if (title_screen_nr < num_title_screens)
1837 tci = &title_controls[title_screen_nr];
1839 SetAnimStatus(getTitleAnimMode(tci));
1841 sound = getTitleSound(tci);
1842 music = getTitleMusic(tci);
1844 if (last_sound != SND_UNDEFINED && sound != last_sound)
1845 FadeSound(last_sound);
1846 if (last_music != MUS_UNDEFINED && music != last_music)
1849 fading = getTitleFading(tci);
1851 FadeOut(REDRAW_ALL);
1854 DrawTitleScreenImage(tci->local_nr, tci->initial);
1856 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1858 sound = getTitleSound(tci);
1859 music = getTitleMusic(tci);
1861 if (sound != last_sound)
1862 PlayMenuSoundExt(sound);
1863 if (music != last_music)
1864 PlayMenuMusicExt(music);
1871 ResetTitleAutoDelay(&title_delay, &fading);
1875 FadeMenuSoundsAndMusic();
1877 return_to_main_menu = TRUE;
1881 if (return_to_main_menu)
1883 SetMouseCursor(CURSOR_DEFAULT);
1885 // force full menu screen redraw after displaying title screens
1886 redraw_mask = REDRAW_ALL;
1888 if (game_status_last_screen == GAME_MODE_INFO)
1890 SetGameStatus(GAME_MODE_INFO);
1892 info_mode = INFO_MODE_MAIN;
1896 else // default: return to main menu
1898 SetGameStatus(GAME_MODE_MAIN);
1905 static void HandleMainMenu_SelectLevel(int step, int direction,
1906 int selected_level_nr)
1908 int old_level_nr = level_nr;
1911 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1912 new_level_nr = selected_level_nr;
1914 new_level_nr = old_level_nr + step * direction;
1916 if (new_level_nr < leveldir_current->first_level)
1917 new_level_nr = leveldir_current->first_level;
1918 if (new_level_nr > leveldir_current->last_level)
1919 new_level_nr = leveldir_current->last_level;
1921 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1923 // skipping levels is only allowed when trying to skip single level
1924 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1925 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1927 leveldir_current->handicap_level++;
1928 SaveLevelSetup_SeriesInfo();
1931 new_level_nr = leveldir_current->handicap_level;
1934 if (new_level_nr != old_level_nr)
1936 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1938 PlaySound(SND_MENU_ITEM_SELECTING);
1940 level_nr = new_level_nr;
1942 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1943 int2str(level_nr, menu.main.text.level_number.size),
1944 mci->pos_text->font);
1946 LoadLevel(level_nr);
1947 DrawPreviewLevelInitial();
1951 DrawCompleteVideoDisplay();
1953 SaveLevelSetup_SeriesInfo();
1955 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1957 // force redraw of playfield area (may be reset at this point)
1958 redraw_mask |= REDRAW_FIELD;
1962 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1964 static int choice = MAIN_CONTROL_GAME;
1965 static boolean button_pressed_last = FALSE;
1966 boolean button_pressed = FALSE;
1968 int i = 0; // needed to prevent compiler warning due to bad code below
1970 if (button == MB_MENU_INITIALIZE)
1972 DrawCursorAndText_Main(choice, TRUE, FALSE);
1977 if (mx || my) // mouse input
1981 for (i = 0; main_controls[i].nr != -1; i++)
1983 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1984 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1985 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1987 pos = main_controls[i].nr;
1993 // check if level preview was clicked
1994 if (insidePreviewRect(&preview, mx - SX, my - SY))
1995 pos = MAIN_CONTROL_GAME;
1997 // handle pressed/unpressed state for active/inactive menu buttons
1998 // (if pos != -1, "i" contains index position corresponding to "pos")
2000 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2001 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2002 button_pressed = TRUE;
2004 if (button_pressed != button_pressed_last)
2006 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2009 PlaySound(SND_MENU_BUTTON_PRESSING);
2011 PlaySound(SND_MENU_BUTTON_RELEASING);
2014 else if (dx || dy) // keyboard input
2016 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2017 choice == MAIN_CONTROL_SETUP))
2018 button = MB_MENU_CHOICE;
2023 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2025 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2027 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2029 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2031 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2033 CloseDoor(DOOR_CLOSE_2);
2035 SetGameStatus(GAME_MODE_LEVELNR);
2037 DrawChooseLevelNr();
2039 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2045 PlaySound(SND_MENU_ITEM_ACTIVATING);
2047 DrawCursorAndText_Main(choice, FALSE, FALSE);
2048 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2054 if (choice != MAIN_CONTROL_INFO &&
2055 choice != MAIN_CONTROL_SETUP)
2056 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2061 PlaySound(SND_MENU_ITEM_SELECTING);
2063 if (pos == MAIN_CONTROL_NAME)
2066 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2068 // special case: menu text "name/team" clicked -- toggle team mode
2069 setup.team_mode = !setup.team_mode;
2071 InitializeMainControls();
2072 DrawCursorAndText_Main(choice, TRUE, FALSE);
2074 DrawPreviewPlayers();
2078 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2080 HandleTypeName(strlen(setup.player_name), 0);
2083 else if (pos == MAIN_CONTROL_LEVELS)
2087 CloseDoor(DOOR_CLOSE_2);
2089 SetGameStatus(GAME_MODE_LEVELS);
2091 SaveLevelSetup_LastSeries();
2092 SaveLevelSetup_SeriesInfo();
2094 if (setup.internal.choose_from_top_leveldir)
2097 DrawChooseLevelSet();
2100 else if (pos == MAIN_CONTROL_SCORES)
2102 CloseDoor(DOOR_CLOSE_2);
2104 SetGameStatus(GAME_MODE_SCORES);
2106 DrawHallOfFame(level_nr, -1);
2108 else if (pos == MAIN_CONTROL_EDITOR)
2110 if (leveldir_current->readonly &&
2111 !strEqual(setup.player_name, "Artsoft"))
2112 Request("This level is read only!", REQ_CONFIRM);
2114 CloseDoor(DOOR_CLOSE_2);
2116 SetGameStatus(GAME_MODE_EDITOR);
2118 FadeSetEnterScreen();
2122 else if (pos == MAIN_CONTROL_INFO)
2124 CloseDoor(DOOR_CLOSE_2);
2126 SetGameStatus(GAME_MODE_INFO);
2128 info_mode = INFO_MODE_MAIN;
2132 else if (pos == MAIN_CONTROL_GAME)
2134 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2136 else if (pos == MAIN_CONTROL_SETUP)
2138 CloseDoor(DOOR_CLOSE_2);
2140 SetGameStatus(GAME_MODE_SETUP);
2142 setup_mode = SETUP_MODE_MAIN;
2146 else if (pos == MAIN_CONTROL_QUIT)
2148 SaveLevelSetup_LastSeries();
2149 SaveLevelSetup_SeriesInfo();
2151 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2152 SetGameStatus(GAME_MODE_QUIT);
2157 button_pressed_last = button_pressed;
2161 // ============================================================================
2162 // info screen functions
2163 // ============================================================================
2165 static struct TokenInfo *info_info;
2166 static int num_info_info; // number of info entries shown on screen
2167 static int max_info_info; // total number of info entries in list
2169 static void execInfoTitleScreen(void)
2171 info_mode = INFO_MODE_TITLE;
2176 static void execInfoElements(void)
2178 info_mode = INFO_MODE_ELEMENTS;
2183 static void execInfoMusic(void)
2185 info_mode = INFO_MODE_MUSIC;
2190 static void execInfoCredits(void)
2192 info_mode = INFO_MODE_CREDITS;
2197 static void execInfoProgram(void)
2199 info_mode = INFO_MODE_PROGRAM;
2204 static void execInfoVersion(void)
2206 info_mode = INFO_MODE_VERSION;
2211 static void execInfoLevelSet(void)
2213 info_mode = INFO_MODE_LEVELSET;
2218 static void execExitInfo(void)
2220 SetGameStatus(GAME_MODE_MAIN);
2225 static struct TokenInfo info_info_main[] =
2227 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2228 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2229 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2230 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2231 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2232 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2233 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2234 { TYPE_EMPTY, NULL, "" },
2235 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2240 static int getMenuTextFont(int type)
2242 if (type & (TYPE_SWITCH |
2256 static struct TokenInfo *setup_info;
2257 static struct TokenInfo setup_info_input[];
2259 static struct TokenInfo *menu_info;
2261 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2262 int screen_pos, int menu_info_pos_raw,
2265 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2266 struct TokenInfo *ti = &token_info[pos];
2267 int xpos = MENU_SCREEN_START_XPOS;
2268 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2269 int font_nr = getMenuTextFont(ti->type);
2271 if (setup_mode == SETUP_MODE_INPUT)
2272 font_nr = FONT_MENU_1;
2275 font_nr = FONT_ACTIVE(font_nr);
2277 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2279 if (ti->type & ~TYPE_SKIP_ENTRY)
2280 drawCursor(screen_pos, active);
2283 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2286 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2289 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2292 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2295 static char *window_size_text;
2296 static char *scaling_type_text;
2297 static char *network_server_text;
2299 static void drawSetupValue(int, int);
2301 static void drawMenuInfoList(int first_entry, int num_page_entries,
2302 int max_page_entries)
2306 if (first_entry + num_page_entries > max_page_entries)
2309 clearMenuListArea();
2311 for (i = 0; i < num_page_entries; i++)
2313 int menu_info_pos = first_entry + i;
2314 struct TokenInfo *si = &menu_info[menu_info_pos];
2315 void *value_ptr = si->value;
2317 // set some entries to "unchangeable" according to other variables
2318 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2319 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2320 (value_ptr == &setup.sound_music && !audio.music_available) ||
2321 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2322 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2323 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2324 si->type |= TYPE_GHOSTED;
2326 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2327 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2328 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2329 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2330 else if (si->type & ~TYPE_SKIP_ENTRY)
2331 initCursor(i, IMG_MENU_BUTTON);
2333 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2335 if (si->type & TYPE_STRING)
2339 if (value_ptr == &network_server_text)
2340 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2342 if (gadget_id != -1)
2344 struct GadgetInfo *gi = screen_gadget[gadget_id];
2345 int xpos = MENU_SCREEN_START_XPOS;
2346 int ypos = MENU_SCREEN_START_YPOS + i;
2347 int x = mSX + xpos * 32;
2348 int y = mSY + ypos * 32;
2350 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2354 if (si->type & TYPE_VALUE &&
2355 menu_info == setup_info)
2356 drawSetupValue(i, menu_info_pos);
2360 static void DrawInfoScreen_Main(void)
2362 int fade_mask = REDRAW_FIELD;
2365 if (redraw_mask & REDRAW_ALL)
2366 fade_mask = REDRAW_ALL;
2369 fade_mask = REDRAW_ALL;
2372 FadeMenuSoundsAndMusic();
2374 FreeScreenGadgets();
2375 CreateScreenGadgets();
2377 // (needed after displaying title screens which disable auto repeat)
2378 KeyboardAutoRepeatOn();
2380 FadeSetLeaveScreen();
2384 // needed if different viewport properties defined for info screen
2385 ChangeViewportPropertiesIfNeeded();
2387 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2391 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2393 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2395 info_info = info_info_main;
2397 // determine maximal number of info entries that can be displayed on screen
2399 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2402 // determine maximal number of info entries available for menu of info screen
2404 for (i = 0; info_info[i].type != 0; i++)
2407 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2409 MapScreenGadgets(max_info_info);
2411 PlayMenuSoundsAndMusic();
2413 DrawMaskedBorder(fade_mask);
2418 static void changeSetupValue(int, int, int);
2420 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2421 int mode, int num_page_entries,
2422 int max_page_entries)
2424 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2425 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2426 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2427 int *num_page_entries_last = num_page_entries_all_last[game_status];
2428 int *choice_store = choice_stores[game_status];
2429 int *first_entry_store = first_entry_stores[game_status];
2430 int choice = choice_store[mode]; // starts with 0
2431 int first_entry = first_entry_store[mode]; // starts with 0
2433 int y = choice - first_entry;
2435 boolean position_set_by_scrollbar = (dx == 999);
2436 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2439 if (button == MB_MENU_INITIALIZE)
2441 // check if number of menu page entries has changed (may happen by change
2442 // of custom artwork definition value for 'list_size' for this menu screen)
2443 // (in this case, the last menu position most probably has to be corrected)
2444 if (num_page_entries != num_page_entries_last[mode])
2446 choice_store[mode] = first_entry_store[mode] = 0;
2448 choice = first_entry = 0;
2451 num_page_entries_last[mode] = num_page_entries;
2454 // advance to first valid menu entry
2455 while (choice < num_page_entries &&
2456 menu_info[choice].type & TYPE_SKIP_ENTRY)
2459 if (position_set_by_scrollbar)
2460 first_entry = first_entry_store[mode] = dy;
2462 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2463 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2465 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2467 if (choice < first_entry)
2469 choice = first_entry;
2471 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2474 else if (choice > first_entry + num_page_entries - 1)
2476 choice = first_entry + num_page_entries - 1;
2478 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2482 choice_store[mode] = choice;
2484 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2488 else if (button == MB_MENU_LEAVE)
2490 PlaySound(SND_MENU_ITEM_SELECTING);
2492 for (i = 0; i < max_page_entries; i++)
2494 if (menu_info[i].type & TYPE_LEAVE_MENU)
2496 void (*menu_callback_function)(void) = menu_info[i].value;
2500 menu_callback_function();
2502 break; // absolutely needed because function changes 'menu_info'!
2509 if (mx || my) // mouse input
2511 x = (mx - mSX) / 32;
2512 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2514 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2516 // move cursor instead of scrolling when already at start/end of list
2517 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2519 else if (dy == +1 * SCROLL_LINE &&
2520 first_entry + num_page_entries == max_page_entries)
2523 // handle scrolling screen one line or page
2525 y + dy > num_page_entries - 1)
2527 boolean redraw = FALSE;
2529 if (ABS(dy) == SCROLL_PAGE)
2530 step = num_page_entries - 1;
2532 if (dy < 0 && first_entry > 0)
2534 // scroll page/line up
2536 first_entry -= step;
2537 if (first_entry < 0)
2542 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2544 // scroll page/line down
2546 first_entry += step;
2547 if (first_entry + num_page_entries > max_page_entries)
2548 first_entry = MAX(0, max_page_entries - num_page_entries);
2555 choice += first_entry - first_entry_store[mode];
2557 if (choice < first_entry)
2559 choice = first_entry;
2561 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2564 else if (choice > first_entry + num_page_entries - 1)
2566 choice = first_entry + num_page_entries - 1;
2568 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2571 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2575 if (choice < first_entry ||
2576 choice > first_entry + num_page_entries - 1)
2577 first_entry += SIGN(dy);
2580 first_entry_store[mode] = first_entry;
2581 choice_store[mode] = choice;
2583 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2585 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2587 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2588 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2596 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2598 if (menu_info[choice].type & menu_navigation_type ||
2599 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2600 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2601 menu_info[choice].type & TYPE_PLAYER)
2602 button = MB_MENU_CHOICE;
2607 // jump to next non-empty menu entry (up or down)
2608 while (first_entry + y > 0 &&
2609 first_entry + y < max_page_entries - 1 &&
2610 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2613 if (!IN_VIS_MENU(x, y))
2615 choice += y - y_old;
2617 if (choice < first_entry)
2618 first_entry = choice;
2619 else if (choice > first_entry + num_page_entries - 1)
2620 first_entry = choice - num_page_entries + 1;
2622 if (first_entry >= 0 &&
2623 first_entry + num_page_entries <= max_page_entries)
2625 first_entry_store[mode] = first_entry;
2627 if (choice < first_entry)
2628 choice = first_entry;
2629 else if (choice > first_entry + num_page_entries - 1)
2630 choice = first_entry + num_page_entries - 1;
2632 choice_store[mode] = choice;
2634 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2636 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2638 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2639 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2646 if (!anyScrollbarGadgetActive() &&
2647 IN_VIS_MENU(x, y) &&
2648 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2649 y >= 0 && y < num_page_entries)
2653 if (first_entry + y != choice &&
2654 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2656 PlaySound(SND_MENU_ITEM_ACTIVATING);
2658 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2659 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2661 choice = choice_store[mode] = first_entry + y;
2665 PlaySound(SND_MENU_ITEM_SELECTING);
2667 for (i = 0; menu_info[i].type != 0; i++)
2669 if (menu_info[i].type & TYPE_LEAVE_MENU)
2671 void (*menu_callback_function)(void) = menu_info[i].value;
2675 menu_callback_function();
2677 // absolutely needed because function changes 'menu_info'!
2685 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2687 PlaySound(SND_MENU_ITEM_SELECTING);
2689 // when selecting key headline, execute function for key value change
2690 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2691 menu_info[first_entry + y + 1].type & TYPE_KEY)
2694 // when selecting string value, execute function for list selection
2695 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2696 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2699 // when selecting string value, execute function for text input gadget
2700 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2701 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2704 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2706 void (*menu_callback_function)(void) =
2707 menu_info[first_entry + y].value;
2709 FadeSetFromType(menu_info[first_entry + y].type);
2711 menu_callback_function();
2713 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2715 void (*gadget_callback_function)(void) =
2716 menu_info[first_entry + y].value;
2718 gadget_callback_function();
2720 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2721 menu_info == setup_info)
2723 changeSetupValue(y, first_entry + y, dx);
2729 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2731 menu_info = info_info;
2733 HandleMenuScreen(mx, my, dx, dy, button,
2734 info_mode, num_info_info, max_info_info);
2737 static int getMenuFontSpacing(int spacing_height, int font_nr)
2739 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2741 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2745 static int getMenuTextSpacing(int spacing_height, int font_nr)
2747 return (getMenuFontSpacing(spacing_height, font_nr) +
2748 EXTRA_SPACING(game_status));
2751 static int getMenuTextStep(int spacing_height, int font_nr)
2753 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2756 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2758 int font_title = MENU_INFO_FONT_TITLE;
2759 int font_error = FONT_TEXT_2;
2760 int font_foot = MENU_INFO_FONT_FOOT;
2761 int spacing_title = menu.headline1_spacing_info[info_mode];
2762 int ystep_title = getMenuTextStep(spacing_title, font_title);
2763 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2764 int ystart2 = ystart1 + ystep_title;
2765 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2767 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2769 FadeOut(REDRAW_FIELD);
2774 DrawTextSCentered(ystart1, font_title, text_title);
2775 DrawTextSCentered(ystart2, font_error, text_error);
2777 DrawTextSCentered(ybottom, font_foot,
2778 "Press any key or button for info menu");
2780 FadeIn(REDRAW_FIELD);
2783 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2785 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2786 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2787 int font_title = MENU_INFO_FONT_TITLE;
2788 int font_foot = MENU_INFO_FONT_FOOT;
2789 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2790 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2791 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2792 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2793 int ystep = MENU_SCREEN_INFO_YSTEP;
2794 int element, action, direction;
2802 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2803 infoscreen_step[i] = infoscreen_frame[i] = 0;
2808 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2810 DrawTextSCentered(ybottom, font_foot,
2811 "Press any key or button for next page");
2817 while (helpanim_info[j].element != HELPANIM_LIST_END)
2819 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2824 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2833 j += infoscreen_step[i - start];
2835 element = helpanim_info[j].element;
2836 action = helpanim_info[j].action;
2837 direction = helpanim_info[j].direction;
2840 element = EL_UNKNOWN;
2842 if (action != -1 && direction != -1)
2843 graphic = el_act_dir2img(element, action, direction);
2844 else if (action != -1)
2845 graphic = el_act2img(element, action);
2846 else if (direction != -1)
2847 graphic = el_dir2img(element, direction);
2849 graphic = el2img(element);
2851 delay = helpanim_info[j++].delay;
2856 if (infoscreen_frame[i - start] == 0)
2859 infoscreen_frame[i - start] = delay - 1;
2863 sync_frame = delay - infoscreen_frame[i - start];
2864 infoscreen_frame[i - start]--;
2867 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2869 if (!infoscreen_frame[i - start])
2870 infoscreen_step[i - start] = 0;
2874 if (!infoscreen_frame[i - start])
2875 infoscreen_step[i - start]++;
2876 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2882 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2884 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2885 graphic, sync_frame, USE_MASKING);
2888 DrawInfoScreen_HelpText(element, action, direction, i - start);
2893 redraw_mask |= REDRAW_FIELD;
2898 static char *getHelpText(int element, int action, int direction)
2900 char token[MAX_LINE_LEN];
2902 strcpy(token, element_info[element].token_name);
2905 strcat(token, element_action_info[action].suffix);
2907 if (direction != -1)
2908 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2910 return getHashEntry(helptext_info, token);
2913 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2915 int font_nr = FONT_INFO_ELEMENTS;
2916 int font_width = getFontWidth(font_nr);
2917 int font_height = getFontHeight(font_nr);
2918 int yoffset = (TILEX - 2 * font_height) / 2;
2919 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2920 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2921 int ystep = TILEY + 4;
2922 int pad_left = xstart - SX;
2923 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2924 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2925 int max_lines_per_text = 2;
2928 if (action != -1 && direction != -1) // element.action.direction
2929 text = getHelpText(element, action, direction);
2931 if (text == NULL && action != -1) // element.action
2932 text = getHelpText(element, action, -1);
2934 if (text == NULL && direction != -1) // element.direction
2935 text = getHelpText(element, -1, direction);
2937 if (text == NULL) // base element
2938 text = getHelpText(element, -1, -1);
2940 if (text == NULL) // not found
2941 text = "No description available";
2943 if (strlen(text) <= max_chars_per_line) // only one line of text
2944 ystart += getFontHeight(font_nr) / 2;
2946 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2947 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2948 TRUE, FALSE, FALSE);
2951 static void DrawInfoScreen_TitleScreen(void)
2953 SetGameStatus(GAME_MODE_TITLE);
2958 void HandleInfoScreen_TitleScreen(int button)
2960 HandleTitleScreen(0, 0, 0, 0, button);
2963 static void DrawInfoScreen_Elements(void)
2965 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2967 FadeOut(REDRAW_FIELD);
2972 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2974 FadeIn(REDRAW_FIELD);
2977 void HandleInfoScreen_Elements(int button)
2979 static unsigned int info_delay = 0;
2980 static int num_anims;
2981 static int num_pages;
2983 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2986 if (button == MB_MENU_INITIALIZE)
2988 boolean new_element = TRUE;
2992 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2994 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2996 else if (new_element)
2999 new_element = FALSE;
3003 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3007 if (button == MB_MENU_LEAVE)
3009 PlaySound(SND_MENU_ITEM_SELECTING);
3011 info_mode = INFO_MODE_MAIN;
3016 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3018 if (button != MB_MENU_INITIALIZE)
3020 PlaySound(SND_MENU_ITEM_SELECTING);
3025 if (page >= num_pages)
3027 FadeMenuSoundsAndMusic();
3029 info_mode = INFO_MODE_MAIN;
3036 FadeSetNextScreen();
3038 if (button != MB_MENU_INITIALIZE)
3039 FadeOut(REDRAW_FIELD);
3041 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3043 if (button != MB_MENU_INITIALIZE)
3044 FadeIn(REDRAW_FIELD);
3048 if (DelayReached(&info_delay, GameFrameDelay))
3049 if (page < num_pages)
3050 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3052 PlayMenuSoundIfLoop();
3056 static void DrawInfoScreen_Music(void)
3058 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3060 FadeOut(REDRAW_FIELD);
3067 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3069 FadeIn(REDRAW_FIELD);
3072 void HandleInfoScreen_Music(int button)
3074 static struct MusicFileInfo *list = NULL;
3075 int font_title = MENU_INFO_FONT_TITLE;
3076 int font_head = MENU_INFO_FONT_HEAD;
3077 int font_text = MENU_INFO_FONT_TEXT;
3078 int font_foot = MENU_INFO_FONT_FOOT;
3079 int spacing_title = menu.headline1_spacing_info[info_mode];
3080 int spacing_head = menu.headline2_spacing_info[info_mode];
3081 int ystep_title = getMenuTextStep(spacing_title, font_title);
3082 int ystep_head = getMenuTextStep(spacing_head, font_head);
3083 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3084 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3086 if (button == MB_MENU_INITIALIZE)
3088 list = music_file_info;
3092 FadeMenuSoundsAndMusic();
3097 DrawTextSCentered(ystart, font_title,
3098 "No music info for this level set.");
3100 DrawTextSCentered(ybottom, font_foot,
3101 "Press any key or button for info menu");
3107 if (button == MB_MENU_LEAVE)
3109 PlaySound(SND_MENU_ITEM_SELECTING);
3111 FadeMenuSoundsAndMusic();
3113 info_mode = INFO_MODE_MAIN;
3118 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3120 if (button != MB_MENU_INITIALIZE)
3122 PlaySound(SND_MENU_ITEM_SELECTING);
3130 FadeMenuSoundsAndMusic();
3132 info_mode = INFO_MODE_MAIN;
3138 FadeMenuSoundsAndMusic();
3140 if (list != music_file_info)
3141 FadeSetNextScreen();
3143 if (button != MB_MENU_INITIALIZE)
3144 FadeOut(REDRAW_FIELD);
3151 int sound = list->music;
3153 if (sound_info[sound].loop)
3154 PlaySoundLoop(sound);
3158 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3162 int music = list->music;
3164 if (music_info[music].loop)
3165 PlayMusicLoop(music);
3169 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3172 ystart += ystep_title;
3174 if (!strEqual(list->title, UNKNOWN_NAME))
3176 if (!strEqual(list->title_header, UNKNOWN_NAME))
3178 DrawTextSCentered(ystart, font_head, list->title_header);
3179 ystart += ystep_head;
3182 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3183 ystart += ystep_head;
3186 if (!strEqual(list->artist, UNKNOWN_NAME))
3188 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3189 DrawTextSCentered(ystart, font_head, list->artist_header);
3191 DrawTextSCentered(ystart, font_head, "by");
3193 ystart += ystep_head;
3195 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3196 ystart += ystep_head;
3199 if (!strEqual(list->album, UNKNOWN_NAME))
3201 if (!strEqual(list->album_header, UNKNOWN_NAME))
3202 DrawTextSCentered(ystart, font_head, list->album_header);
3204 DrawTextSCentered(ystart, font_head, "from the album");
3206 ystart += ystep_head;
3208 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3209 ystart += ystep_head;
3212 if (!strEqual(list->year, UNKNOWN_NAME))
3214 if (!strEqual(list->year_header, UNKNOWN_NAME))
3215 DrawTextSCentered(ystart, font_head, list->year_header);
3217 DrawTextSCentered(ystart, font_head, "from the year");
3219 ystart += ystep_head;
3221 DrawTextFCentered(ystart, font_text, "%s", list->year);
3222 ystart += ystep_head;
3225 DrawTextSCentered(ybottom, FONT_TEXT_4,
3226 "Press any key or button for next page");
3228 if (button != MB_MENU_INITIALIZE)
3229 FadeIn(REDRAW_FIELD);
3232 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3233 PlaySoundLoop(list->music);
3236 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3238 int font_title = MENU_INFO_FONT_TITLE;
3239 int font_head = MENU_INFO_FONT_HEAD;
3240 int font_text = MENU_INFO_FONT_TEXT;
3241 int font_foot = MENU_INFO_FONT_FOOT;
3242 int spacing_title = menu.headline1_spacing_info[info_mode];
3243 int spacing_head = menu.headline2_spacing_info[info_mode];
3244 int spacing_para = menu.paragraph_spacing_info[info_mode];
3245 int spacing_line = menu.line_spacing_info[info_mode];
3246 int ystep_title = getMenuTextStep(spacing_title, font_title);
3247 int ystep_head = getMenuTextStep(spacing_head, font_head);
3248 int ystep_para = getMenuTextStep(spacing_para, font_text);
3249 int ystep_line = getMenuTextStep(spacing_line, font_text);
3250 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3251 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3256 DrawTextSCentered(ystart, font_title, "Credits:");
3257 ystart += ystep_title;
3261 DrawTextSCentered(ystart, font_head,
3262 "Special thanks to");
3263 ystart += ystep_head;
3264 DrawTextSCentered(ystart, font_text,
3266 ystart += ystep_head;
3267 DrawTextSCentered(ystart, font_head,
3269 ystart += ystep_head;
3270 DrawTextSCentered(ystart, font_text,
3271 "\"Boulder Dash\"");
3272 ystart += ystep_head;
3273 DrawTextSCentered(ystart, font_head,
3275 ystart += ystep_head;
3276 DrawTextSCentered(ystart, font_text,
3278 ystart += ystep_head;
3279 DrawTextSCentered(ystart, font_head,
3281 ystart += ystep_head;
3282 DrawTextSCentered(ystart, font_text,
3283 "First Star Software");
3285 else if (screen_nr == 1)
3287 DrawTextSCentered(ystart, font_head,
3288 "Special thanks to");
3289 ystart += ystep_head;
3290 DrawTextSCentered(ystart, font_text,
3291 "Klaus Heinz & Volker Wertich");
3292 ystart += ystep_head;
3293 DrawTextSCentered(ystart, font_head,
3295 ystart += ystep_head;
3296 DrawTextSCentered(ystart, font_text,
3297 "\"Emerald Mine\"");
3298 ystart += ystep_head;
3299 DrawTextSCentered(ystart, font_head,
3301 ystart += ystep_head;
3302 DrawTextSCentered(ystart, font_text,
3304 ystart += ystep_head;
3305 DrawTextSCentered(ystart, font_head,
3307 ystart += ystep_head;
3308 DrawTextSCentered(ystart, font_text,
3311 else if (screen_nr == 2)
3313 DrawTextSCentered(ystart, font_head,
3314 "Special thanks to");
3315 ystart += ystep_head;
3316 DrawTextSCentered(ystart, font_text,
3317 "Michael Stopp & Philip Jespersen");
3318 ystart += ystep_head;
3319 DrawTextSCentered(ystart, font_head,
3321 ystart += ystep_head;
3322 DrawTextSCentered(ystart, font_text,
3324 ystart += ystep_head;
3325 DrawTextSCentered(ystart, font_head,
3327 ystart += ystep_head;
3328 DrawTextSCentered(ystart, font_text,
3330 ystart += ystep_head;
3331 DrawTextSCentered(ystart, font_head,
3333 ystart += ystep_head;
3334 DrawTextSCentered(ystart, font_text,
3335 "Digital Integration");
3337 else if (screen_nr == 3)
3339 DrawTextSCentered(ystart, font_head,
3340 "Special thanks to");
3341 ystart += ystep_head;
3342 DrawTextSCentered(ystart, font_text,
3343 "Hiroyuki Imabayashi");
3344 ystart += ystep_head;
3345 DrawTextSCentered(ystart, font_head,
3347 ystart += ystep_head;
3348 DrawTextSCentered(ystart, font_text,
3350 ystart += ystep_head;
3351 DrawTextSCentered(ystart, font_head,
3353 ystart += ystep_head;
3354 DrawTextSCentered(ystart, font_text,
3356 ystart += ystep_head;
3357 DrawTextSCentered(ystart, font_head,
3359 ystart += ystep_head;
3360 DrawTextSCentered(ystart, font_text,
3363 else if (screen_nr == 4)
3365 DrawTextSCentered(ystart, font_head,
3366 "Special thanks to");
3367 ystart += ystep_head;
3368 DrawTextSCentered(ystart, font_text,
3370 ystart += ystep_head;
3371 DrawTextSCentered(ystart, font_head,
3373 ystart += ystep_head;
3374 DrawTextSCentered(ystart, font_text,
3375 "J\xfcrgen Bonhagen");
3376 ystart += ystep_head;
3377 DrawTextSCentered(ystart, font_head,
3378 "for the continuous creation");
3379 ystart += ystep_line;
3380 DrawTextSCentered(ystart, font_head,
3381 "of outstanding level sets");
3383 else if (screen_nr == 5)
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 ideas and inspiration by");
3393 ystart += ystep_head;
3394 DrawTextSCentered(ystart, font_text,
3396 ystart += ystep_para;
3398 DrawTextSCentered(ystart, font_head,
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_text,
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_head,
3405 "for ideas and inspiration by");
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_text,
3410 else if (screen_nr == 6)
3412 DrawTextSCentered(ystart, font_head,
3414 ystart += ystep_head;
3415 DrawTextSCentered(ystart, font_text,
3417 ystart += ystep_head;
3418 DrawTextSCentered(ystart, font_head,
3419 "for the code base used for the");
3420 ystart += ystep_line;
3421 DrawTextSCentered(ystart, font_head,
3422 "native Emerald Mine engine");
3424 else if (screen_nr == 7)
3426 DrawTextSCentered(ystart, font_head,
3428 ystart += ystep_head;
3429 DrawTextSCentered(ystart, font_text,
3431 ystart += ystep_head;
3432 DrawTextSCentered(ystart, font_head,
3433 "for the initial DOS port");
3434 ystart += ystep_para;
3436 DrawTextSCentered(ystart, font_head,
3438 ystart += ystep_head;
3439 DrawTextSCentered(ystart, font_text,
3441 ystart += ystep_head;
3442 DrawTextSCentered(ystart, font_head,
3443 "for some additional toons");
3445 else if (screen_nr == 8)
3447 DrawTextSCentered(ystart, font_head,
3448 "And not to forget:");
3449 ystart += ystep_head;
3450 DrawTextSCentered(ystart, font_head,
3452 ystart += ystep_head;
3453 DrawTextSCentered(ystart, font_text,
3454 "All those who contributed");
3455 ystart += ystep_line;
3456 DrawTextSCentered(ystart, font_text,
3457 "levels to this game");
3458 ystart += ystep_line;
3459 DrawTextSCentered(ystart, font_text,
3463 DrawTextSCentered(ybottom, font_foot,
3464 "Press any key or button for next page");
3467 static void DrawInfoScreen_Credits(void)
3469 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3471 FadeMenuSoundsAndMusic();
3473 FadeOut(REDRAW_FIELD);
3475 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3477 FadeIn(REDRAW_FIELD);
3480 void HandleInfoScreen_Credits(int button)
3482 static int screen_nr = 0;
3483 int num_screens = 9;
3485 if (button == MB_MENU_INITIALIZE)
3489 // DrawInfoScreen_CreditsScreen(screen_nr);
3492 if (button == MB_MENU_LEAVE)
3494 PlaySound(SND_MENU_ITEM_SELECTING);
3496 info_mode = INFO_MODE_MAIN;
3501 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3503 if (button != MB_MENU_INITIALIZE)
3505 PlaySound(SND_MENU_ITEM_SELECTING);
3510 if (screen_nr >= num_screens)
3512 FadeMenuSoundsAndMusic();
3514 info_mode = INFO_MODE_MAIN;
3521 FadeSetNextScreen();
3523 if (button != MB_MENU_INITIALIZE)
3524 FadeOut(REDRAW_FIELD);
3526 DrawInfoScreen_CreditsScreen(screen_nr);
3528 if (button != MB_MENU_INITIALIZE)
3529 FadeIn(REDRAW_FIELD);
3533 PlayMenuSoundIfLoop();
3537 static void DrawInfoScreen_Program(void)
3539 int font_title = MENU_INFO_FONT_TITLE;
3540 int font_head = MENU_INFO_FONT_HEAD;
3541 int font_text = MENU_INFO_FONT_TEXT;
3542 int font_foot = MENU_INFO_FONT_FOOT;
3543 int spacing_title = menu.headline1_spacing_info[info_mode];
3544 int spacing_head = menu.headline2_spacing_info[info_mode];
3545 int spacing_para = menu.paragraph_spacing_info[info_mode];
3546 int spacing_line = menu.line_spacing_info[info_mode];
3547 int ystep_title = getMenuTextStep(spacing_title, font_title);
3548 int ystep_head = getMenuTextStep(spacing_head, font_head);
3549 int ystep_para = getMenuTextStep(spacing_para, font_text);
3550 int ystep_line = getMenuTextStep(spacing_line, font_text);
3551 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3552 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3554 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3556 FadeOut(REDRAW_FIELD);
3561 DrawTextSCentered(ystart, font_title, "Program Information:");
3562 ystart += ystep_title;
3564 DrawTextSCentered(ystart, font_head,
3565 "This game is Freeware!");
3566 ystart += ystep_head;
3567 DrawTextSCentered(ystart, font_head,
3568 "If you like it, send e-mail to:");
3569 ystart += ystep_head;
3570 DrawTextSCentered(ystart, font_text,
3571 setup.internal.program_email);
3572 ystart += ystep_para;
3574 DrawTextSCentered(ystart, font_head,
3575 "More information and levels:");
3576 ystart += ystep_head;
3577 DrawTextSCentered(ystart, font_text,
3578 setup.internal.program_website);
3579 ystart += ystep_para;
3581 DrawTextSCentered(ystart, font_head,
3582 "If you have created new levels,");
3583 ystart += ystep_line;
3584 DrawTextSCentered(ystart, font_head,
3585 "send them to me to include them!");
3586 ystart += ystep_head;
3587 DrawTextSCentered(ystart, font_head,
3590 DrawTextSCentered(ybottom, font_foot,
3591 "Press any key or button for info menu");
3593 FadeIn(REDRAW_FIELD);
3596 void HandleInfoScreen_Program(int button)
3598 if (button == MB_MENU_LEAVE)
3600 PlaySound(SND_MENU_ITEM_SELECTING);
3602 info_mode = INFO_MODE_MAIN;
3607 else if (button == MB_MENU_CHOICE)
3609 PlaySound(SND_MENU_ITEM_SELECTING);
3611 FadeMenuSoundsAndMusic();
3613 info_mode = INFO_MODE_MAIN;
3618 PlayMenuSoundIfLoop();
3622 static void DrawInfoScreen_Version(void)
3624 int font_title = MENU_INFO_FONT_TITLE;
3625 int font_head = MENU_INFO_FONT_HEAD;
3626 int font_text = MENU_INFO_FONT_TEXT;
3627 int font_foot = MENU_INFO_FONT_FOOT;
3628 int spacing_title = menu.headline1_spacing_info[info_mode];
3629 int spacing_head = menu.headline2_spacing_info[info_mode];
3630 int spacing_para = menu.paragraph_spacing_info[info_mode];
3631 int spacing_line = menu.line_spacing_info[info_mode];
3632 int xstep = getFontWidth(font_text);
3633 int ystep_title = getMenuTextStep(spacing_title, font_title);
3634 int ystep_head = getMenuTextStep(spacing_head, font_head);
3635 int ystep_para = getMenuTextStep(spacing_para, font_text);
3636 int ystep_line = getMenuTextStep(spacing_line, font_text);
3637 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3638 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3639 int xstart1 = mSX - SX + 2 * xstep;
3640 int xstart2 = mSX - SX + 18 * xstep;
3641 int xstart3 = mSX - SX + 28 * xstep;
3642 SDL_version sdl_version_compiled;
3643 const SDL_version *sdl_version_linked;
3644 int driver_name_len = 10;
3645 SDL_version sdl_version_linked_ext;
3646 const char *driver_name = NULL;
3648 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3650 FadeOut(REDRAW_FIELD);
3655 DrawTextSCentered(ystart, font_title, "Version Information:");
3656 ystart += ystep_title;
3658 DrawTextF(xstart1, ystart, font_head, "Name");
3659 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3660 ystart += ystep_line;
3662 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3664 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3665 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3666 ystart += ystep_line;
3668 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3669 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3670 ystart += ystep_line;
3674 DrawTextF(xstart1, ystart, font_head, "Version");
3675 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3676 ystart += ystep_line;
3679 DrawTextF(xstart1, ystart, font_head, "Platform");
3680 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3681 ystart += ystep_line;
3683 DrawTextF(xstart1, ystart, font_head, "Target");
3684 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3685 ystart += ystep_line;
3687 DrawTextF(xstart1, ystart, font_head, "Source date");
3688 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3689 ystart += ystep_para;
3691 DrawTextF(xstart1, ystart, font_head, "Library");
3692 DrawTextF(xstart2, ystart, font_head, "compiled");
3693 DrawTextF(xstart3, ystart, font_head, "linked");
3694 ystart += ystep_head;
3696 SDL_VERSION(&sdl_version_compiled);
3697 SDL_GetVersion(&sdl_version_linked_ext);
3698 sdl_version_linked = &sdl_version_linked_ext;
3700 DrawTextF(xstart1, ystart, font_text, "SDL");
3701 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3702 sdl_version_compiled.major,
3703 sdl_version_compiled.minor,
3704 sdl_version_compiled.patch);
3705 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3706 sdl_version_linked->major,
3707 sdl_version_linked->minor,
3708 sdl_version_linked->patch);
3709 ystart += ystep_line;
3711 SDL_IMAGE_VERSION(&sdl_version_compiled);
3712 sdl_version_linked = IMG_Linked_Version();
3714 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3715 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3716 sdl_version_compiled.major,
3717 sdl_version_compiled.minor,
3718 sdl_version_compiled.patch);
3719 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3720 sdl_version_linked->major,
3721 sdl_version_linked->minor,
3722 sdl_version_linked->patch);
3723 ystart += ystep_line;
3725 SDL_MIXER_VERSION(&sdl_version_compiled);
3726 sdl_version_linked = Mix_Linked_Version();
3728 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3729 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3730 sdl_version_compiled.major,
3731 sdl_version_compiled.minor,
3732 sdl_version_compiled.patch);
3733 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3734 sdl_version_linked->major,
3735 sdl_version_linked->minor,
3736 sdl_version_linked->patch);
3737 ystart += ystep_line;
3739 SDL_NET_VERSION(&sdl_version_compiled);
3740 sdl_version_linked = SDLNet_Linked_Version();
3742 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3743 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3744 sdl_version_compiled.major,
3745 sdl_version_compiled.minor,
3746 sdl_version_compiled.patch);
3747 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3748 sdl_version_linked->major,
3749 sdl_version_linked->minor,
3750 sdl_version_linked->patch);
3751 ystart += ystep_para;
3753 DrawTextF(xstart1, ystart, font_head, "Driver");
3754 DrawTextF(xstart2, ystart, font_head, "Requested");
3755 DrawTextF(xstart3, ystart, font_head, "Used");
3756 ystart += ystep_head;
3758 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3760 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3761 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3762 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3763 ystart += ystep_line;
3765 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3767 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3768 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3769 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3771 DrawTextSCentered(ybottom, font_foot,
3772 "Press any key or button for info menu");
3774 FadeIn(REDRAW_FIELD);
3777 void HandleInfoScreen_Version(int button)
3779 if (button == MB_MENU_LEAVE)
3781 PlaySound(SND_MENU_ITEM_SELECTING);
3783 info_mode = INFO_MODE_MAIN;
3788 else if (button == MB_MENU_CHOICE)
3790 PlaySound(SND_MENU_ITEM_SELECTING);
3792 FadeMenuSoundsAndMusic();
3794 info_mode = INFO_MODE_MAIN;
3799 PlayMenuSoundIfLoop();
3803 static void DrawInfoScreen_LevelSet(void)
3805 struct TitleMessageInfo *tmi = &readme;
3806 char *filename = getLevelSetInfoFilename();
3807 char *title = "Level Set Information:";
3808 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3809 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3811 if (filename == NULL)
3813 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3818 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3820 FadeOut(REDRAW_FIELD);
3825 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3827 // if x position set to "-1", automatically determine by playfield width
3829 tmi->x = SXSIZE / 2;
3831 // if y position set to "-1", use static default value
3835 // if width set to "-1", automatically determine by playfield width
3836 if (tmi->width == -1)
3837 tmi->width = SXSIZE - 2 * TILEX;
3839 // if height set to "-1", automatically determine by playfield height
3840 if (tmi->height == -1)
3841 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3843 // if chars set to "-1", automatically determine by text and font width
3844 if (tmi->chars == -1)
3845 tmi->chars = tmi->width / getFontWidth(tmi->font);
3847 tmi->width = tmi->chars * getFontWidth(tmi->font);
3849 // if lines set to "-1", automatically determine by text and font height
3850 if (tmi->lines == -1)
3851 tmi->lines = tmi->height / getFontHeight(tmi->font);
3853 tmi->height = tmi->lines * getFontHeight(tmi->font);
3855 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3856 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3857 tmi->autowrap, tmi->centered, tmi->parse_comments);
3859 DrawTextSCentered(ybottom, FONT_TEXT_4,
3860 "Press any key or button for info menu");
3862 FadeIn(REDRAW_FIELD);
3865 static void HandleInfoScreen_LevelSet(int button)
3867 if (button == MB_MENU_LEAVE)
3869 PlaySound(SND_MENU_ITEM_SELECTING);
3871 info_mode = INFO_MODE_MAIN;
3876 else if (button == MB_MENU_CHOICE)
3878 PlaySound(SND_MENU_ITEM_SELECTING);
3880 FadeMenuSoundsAndMusic();
3882 info_mode = INFO_MODE_MAIN;
3887 PlayMenuSoundIfLoop();
3891 static void DrawInfoScreen(void)
3893 if (info_mode == INFO_MODE_TITLE)
3894 DrawInfoScreen_TitleScreen();
3895 else if (info_mode == INFO_MODE_ELEMENTS)
3896 DrawInfoScreen_Elements();
3897 else if (info_mode == INFO_MODE_MUSIC)
3898 DrawInfoScreen_Music();
3899 else if (info_mode == INFO_MODE_CREDITS)
3900 DrawInfoScreen_Credits();
3901 else if (info_mode == INFO_MODE_PROGRAM)
3902 DrawInfoScreen_Program();
3903 else if (info_mode == INFO_MODE_VERSION)
3904 DrawInfoScreen_Version();
3905 else if (info_mode == INFO_MODE_LEVELSET)
3906 DrawInfoScreen_LevelSet();
3908 DrawInfoScreen_Main();
3910 if (info_mode != INFO_MODE_MAIN &&
3911 info_mode != INFO_MODE_TITLE &&
3912 info_mode != INFO_MODE_MUSIC)
3913 PlayMenuSoundsAndMusic();
3916 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3918 if (info_mode == INFO_MODE_TITLE)
3919 HandleInfoScreen_TitleScreen(button);
3920 else if (info_mode == INFO_MODE_ELEMENTS)
3921 HandleInfoScreen_Elements(button);
3922 else if (info_mode == INFO_MODE_MUSIC)
3923 HandleInfoScreen_Music(button);
3924 else if (info_mode == INFO_MODE_CREDITS)
3925 HandleInfoScreen_Credits(button);
3926 else if (info_mode == INFO_MODE_PROGRAM)
3927 HandleInfoScreen_Program(button);
3928 else if (info_mode == INFO_MODE_VERSION)
3929 HandleInfoScreen_Version(button);
3930 else if (info_mode == INFO_MODE_LEVELSET)
3931 HandleInfoScreen_LevelSet(button);
3933 HandleInfoScreen_Main(mx, my, dx, dy, button);
3937 // ============================================================================
3938 // type name functions
3939 // ============================================================================
3941 void HandleTypeName(int newxpos, Key key)
3943 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3944 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3945 struct TextPosInfo *pos = mci->pos_input;
3946 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3947 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3948 static int xpos = 0;
3949 int font_nr = pos->font;
3950 int font_active_nr = FONT_ACTIVE(font_nr);
3951 int font_width = getFontWidth(font_active_nr);
3952 char key_char = getValidConfigValueChar(getCharFromKey(key));
3953 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3954 boolean is_active = TRUE;
3956 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3960 strcpy(last_player_name, setup.player_name);
3964 StartTextInput(startx, starty, pos->width, pos->height);
3966 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3968 setup.player_name[xpos] = key_char;
3969 setup.player_name[xpos + 1] = 0;
3973 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3977 setup.player_name[xpos] = 0;
3979 else if (key == KSYM_Return && xpos > 0)
3985 SetGameStatus(GAME_MODE_MAIN);
3987 else if (key == KSYM_Escape)
3989 strcpy(setup.player_name, last_player_name);
3993 SetGameStatus(GAME_MODE_MAIN);
3998 pos->width = (strlen(setup.player_name) + 1) * font_width;
3999 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4001 DrawText(startx, starty, setup.player_name, font_active_nr);
4002 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
4006 pos->width = strlen(setup.player_name) * font_width;
4007 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4009 DrawText(startx, starty, setup.player_name, font_nr);
4016 // ============================================================================
4017 // tree menu functions
4018 // ============================================================================
4020 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4022 if (game_status != GAME_MODE_SETUP ||
4023 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4026 int max_text_size = 0;
4029 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4030 max_text_size = MAX(max_text_size, strlen(node->name));
4032 int num_entries = numTreeInfoInGroup(ti);
4033 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4034 int text_width = max_text_size * getFontWidth(FONT_TEXT_1);
4035 int button_width = SC_MENUBUTTON_XSIZE;
4036 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4037 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4038 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4039 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4040 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4041 int align_xoffset = MAX(0, align_xoffset_raw);
4043 return align_xoffset;
4046 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4048 if (game_status != GAME_MODE_SETUP ||
4049 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4052 int num_entries = numTreeInfoInGroup(ti);
4053 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4054 int font_height = getFontHeight(FONT_TEXT_1);
4055 int text_height = font_height * num_page_entries;
4056 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4057 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4058 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4059 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4060 int align_yoffset = MAX(0, align_yoffset_raw);
4062 return align_yoffset;
4065 static void DrawChooseTree(TreeInfo **ti_ptr)
4067 int fade_mask = REDRAW_FIELD;
4070 fade_mask = REDRAW_ALL;
4072 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4074 SetGameStatus(GAME_MODE_MAIN);
4083 FreeScreenGadgets();
4084 CreateScreenGadgets();
4088 // needed if different viewport properties defined for choosing level (set)
4089 ChangeViewportPropertiesIfNeeded();
4091 if (game_status == GAME_MODE_LEVELNR)
4092 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4093 else if (game_status == GAME_MODE_LEVELS)
4094 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4098 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4100 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4101 MapScreenTreeGadgets(*ti_ptr);
4103 DrawMaskedBorder(fade_mask);
4108 static void drawChooseTreeList(int first_entry, int num_page_entries,
4111 int num_entries = numTreeInfoInGroup(ti);
4112 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4113 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4114 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4115 int font_nr = FONT_TEXT_1;
4116 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4118 char *title_string = NULL;
4119 int yoffset_sets = MENU_TITLE1_YPOS;
4120 int yoffset_setup = 16;
4121 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4122 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4124 title_string = ti->infotext;
4126 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4128 clearMenuListArea();
4130 for (i = 0; i < num_page_entries; i++)
4132 TreeInfo *node, *node_first;
4133 int entry_pos = first_entry + i;
4134 int xpos = MENU_SCREEN_START_XPOS;
4135 int ypos = MENU_SCREEN_START_YPOS + i;
4136 int startx = amSX + xpos * 32;
4137 int starty = amSY + ypos * 32;
4138 int startx_text = startx + font_xoffset;
4139 int endx_text = amSX + screen_width;
4140 int max_text_size = endx_text - startx_text;
4141 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4142 char buffer[max_buffer_len + 1];
4144 node_first = getTreeInfoFirstGroupEntry(ti);
4145 node = getTreeInfoFromPos(node_first, entry_pos);
4147 strncpy(buffer, node->name, max_buffer_len);
4148 buffer[max_buffer_len] = '\0';
4150 DrawText(startx, starty, buffer, font_nr + node->color);
4152 if (node->parent_link)
4153 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4154 else if (node->level_group)
4155 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4157 initCursor(i, IMG_MENU_BUTTON);
4160 redraw_mask |= REDRAW_FIELD;
4163 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4165 TreeInfo *node, *node_first;
4166 int x, last_redraw_mask = redraw_mask;
4167 int ypos = MENU_TITLE2_YPOS;
4168 int font_nr = FONT_TITLE_2;
4170 if (ti->type == TREE_TYPE_LEVEL_NR)
4171 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4173 if (ti->type != TREE_TYPE_LEVEL_DIR)
4176 node_first = getTreeInfoFirstGroupEntry(ti);
4177 node = getTreeInfoFromPos(node_first, entry_pos);
4179 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4181 if (node->parent_link)
4182 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4183 node->node_parent->name);
4184 else if (node->level_group)
4185 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4187 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4188 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4189 node->levels, (node->levels > 1 ? "levels" : "level"),
4192 // let BackToFront() redraw only what is needed
4193 redraw_mask = last_redraw_mask;
4194 for (x = 0; x < SCR_FIELDX; x++)
4195 MarkTileDirty(x, 1);
4198 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4201 TreeInfo *ti = *ti_ptr;
4203 int y = ti->cl_cursor;
4204 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4205 int num_entries = numTreeInfoInGroup(ti);
4206 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4207 boolean position_set_by_scrollbar = (dx == 999);
4209 if (button == MB_MENU_INITIALIZE)
4211 int num_entries = numTreeInfoInGroup(ti);
4212 int entry_pos = posTreeInfo(ti);
4214 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4215 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4217 if (ti->cl_first == -1)
4219 // only on initialization
4220 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4221 ti->cl_cursor = entry_pos - ti->cl_first;
4223 else if (ti->cl_cursor >= num_page_entries ||
4224 (num_entries > num_page_entries &&
4225 num_entries - ti->cl_first < num_page_entries))
4227 // only after change of list size (by custom graphic configuration)
4228 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4229 ti->cl_cursor = entry_pos - ti->cl_first;
4232 if (position_set_by_scrollbar)
4235 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4238 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4239 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4240 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4244 else if (button == MB_MENU_LEAVE)
4248 PlaySound(SND_MENU_ITEM_SELECTING);
4250 if (ti->node_parent)
4252 *ti_ptr = ti->node_parent;
4253 DrawChooseTree(ti_ptr);
4255 else if (game_status == GAME_MODE_SETUP)
4257 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4258 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4259 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4261 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4262 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4263 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4264 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4265 execSetupGraphics();
4266 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4267 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4268 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4270 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4271 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4272 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4273 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4274 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4275 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4276 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4277 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4284 if (game_status == GAME_MODE_LEVELNR)
4286 int new_level_nr = atoi(level_number_current->identifier);
4288 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4291 SetGameStatus(GAME_MODE_MAIN);
4299 if (mx || my) // mouse input
4301 x = (mx - amSX) / 32;
4302 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4304 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4306 // move cursor instead of scrolling when already at start/end of list
4307 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4309 else if (dy == +1 * SCROLL_LINE &&
4310 ti->cl_first + num_page_entries == num_entries)
4313 // handle scrolling screen one line or page
4314 if (ti->cl_cursor + dy < 0 ||
4315 ti->cl_cursor + dy > num_page_entries - 1)
4317 boolean redraw = FALSE;
4319 if (ABS(dy) == SCROLL_PAGE)
4320 step = num_page_entries - 1;
4322 if (dy < 0 && ti->cl_first > 0)
4324 // scroll page/line up
4326 ti->cl_first -= step;
4327 if (ti->cl_first < 0)
4332 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4334 // scroll page/line down
4336 ti->cl_first += step;
4337 if (ti->cl_first + num_page_entries > num_entries)
4338 ti->cl_first = MAX(0, num_entries - num_page_entries);
4345 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4346 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4347 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4349 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4356 // handle moving cursor one line
4357 y = ti->cl_cursor + dy;
4362 TreeInfo *node_first, *node_cursor;
4363 int entry_pos = ti->cl_first + y;
4365 node_first = getTreeInfoFirstGroupEntry(ti);
4366 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4368 if (node_cursor->node_group)
4372 PlaySound(SND_MENU_ITEM_SELECTING);
4374 node_cursor->cl_first = ti->cl_first;
4375 node_cursor->cl_cursor = ti->cl_cursor;
4376 *ti_ptr = node_cursor->node_group;
4377 DrawChooseTree(ti_ptr);
4382 else if (dx == -1 && ti->node_parent)
4386 PlaySound(SND_MENU_ITEM_SELECTING);
4388 *ti_ptr = ti->node_parent;
4389 DrawChooseTree(ti_ptr);
4394 if (!anyScrollbarGadgetActive() &&
4395 IN_VIS_MENU(x, y) &&
4396 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4397 y >= 0 && y < num_page_entries)
4401 if (y != ti->cl_cursor)
4403 PlaySound(SND_MENU_ITEM_ACTIVATING);
4405 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4406 drawChooseTreeCursor(y, TRUE);
4407 drawChooseTreeInfo(ti->cl_first + y, ti);
4413 if (game_status == GAME_MODE_SETUP)
4415 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4416 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4417 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4419 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4420 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4421 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4422 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4423 execSetupGraphics();
4424 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4425 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4426 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4428 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4429 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4430 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4431 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4432 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4433 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4434 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4435 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4444 TreeInfo *node_first, *node_cursor;
4445 int entry_pos = ti->cl_first + y;
4447 PlaySound(SND_MENU_ITEM_SELECTING);
4449 node_first = getTreeInfoFirstGroupEntry(ti);
4450 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4452 if (node_cursor->node_group)
4456 node_cursor->cl_first = ti->cl_first;
4457 node_cursor->cl_cursor = ti->cl_cursor;
4458 *ti_ptr = node_cursor->node_group;
4459 DrawChooseTree(ti_ptr);
4461 else if (node_cursor->parent_link)
4465 *ti_ptr = node_cursor->node_parent;
4466 DrawChooseTree(ti_ptr);
4472 node_cursor->cl_first = ti->cl_first;
4473 node_cursor->cl_cursor = ti->cl_cursor;
4474 *ti_ptr = node_cursor;
4476 if (ti->type == TREE_TYPE_LEVEL_DIR)
4478 LoadLevelSetup_SeriesInfo();
4480 SaveLevelSetup_LastSeries();
4481 SaveLevelSetup_SeriesInfo();
4485 if (game_status == GAME_MODE_SETUP)
4487 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4488 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4489 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4491 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4492 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4493 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4494 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4495 execSetupGraphics();
4496 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4497 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4498 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4500 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4501 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4502 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4503 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4504 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4505 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4506 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4507 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4514 if (game_status == GAME_MODE_LEVELNR)
4516 int new_level_nr = atoi(level_number_current->identifier);
4518 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4521 SetGameStatus(GAME_MODE_MAIN);
4530 void DrawChooseLevelSet(void)
4532 FadeMenuSoundsAndMusic();
4534 DrawChooseTree(&leveldir_current);
4536 PlayMenuSoundsAndMusic();
4539 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4541 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4544 void DrawChooseLevelNr(void)
4548 FadeMenuSoundsAndMusic();
4550 if (level_number != NULL)
4552 freeTreeInfo(level_number);
4554 level_number = NULL;
4557 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4559 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4560 char identifier[32], name[64];
4563 // temporarily load level info to get level name
4564 LoadLevelInfoOnly(i);
4566 ti->node_top = &level_number;
4567 ti->sort_priority = 10000 + value;
4568 ti->color = (level.no_level_file ? FC_BLUE :
4569 LevelStats_getSolved(i) ? FC_GREEN :
4570 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4572 snprintf(identifier, sizeof(identifier), "%d", value);
4573 snprintf(name, sizeof(name), "%03d: %s", value,
4574 (level.no_level_file ? "(no file)" : level.name));
4576 setString(&ti->identifier, identifier);
4577 setString(&ti->name, name);
4578 setString(&ti->name_sorting, name);
4580 pushTreeInfo(&level_number, ti);
4583 // sort level number values to start with lowest level number
4584 sortTreeInfo(&level_number);
4586 // set current level number to current level number
4587 level_number_current =
4588 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4590 // if that also fails, set current level number to first available level
4591 if (level_number_current == NULL)
4592 level_number_current = level_number;
4594 DrawChooseTree(&level_number_current);
4596 PlayMenuSoundsAndMusic();
4599 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4601 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4604 void DrawHallOfFame(int level_nr, int highlight_position)
4606 int fade_mask = REDRAW_FIELD;
4609 fade_mask = REDRAW_ALL;
4612 FadeMenuSoundsAndMusic();
4614 // (this is needed when called from GameEnd() after winning a game)
4615 KeyboardAutoRepeatOn();
4617 // (this is needed when called from GameEnd() after winning a game)
4618 SetDrawDeactivationMask(REDRAW_NONE);
4619 SetDrawBackgroundMask(REDRAW_FIELD);
4621 if (highlight_position < 0)
4622 LoadScore(level_nr);
4624 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4626 FadeSetEnterScreen();
4630 // needed if different viewport properties defined for scores
4631 ChangeViewportPropertiesIfNeeded();
4633 PlayMenuSoundsAndMusic();
4635 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4637 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4639 DrawMaskedBorder(fade_mask);
4644 static void drawHallOfFameList(int level_nr, int first_entry,
4645 int highlight_position)
4649 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4652 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4653 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4654 "HighScores of Level %d", level_nr);
4656 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4658 int entry = first_entry + i;
4659 boolean active = (entry == highlight_position);
4660 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4661 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4662 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4663 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4664 int dxoff = getFontDrawOffsetX(font_nr1);
4665 int dx1 = 3 * getFontWidth(font_nr1);
4666 int dx2 = dx1 + getFontWidth(font_nr1);
4667 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4668 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4669 int sy = mSY + 64 + i * 32;
4671 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4672 DrawText(mSX + dx1, sy, ".", font_nr1);
4674 for (j = 0; j < num_dots; j++)
4675 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4677 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4678 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4680 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4683 redraw_mask |= REDRAW_FIELD;
4686 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4688 static int level_nr = 0;
4689 static int first_entry = 0;
4690 static int highlight_position = 0;
4691 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4693 if (button == MB_MENU_INITIALIZE)
4697 highlight_position = my;
4699 drawHallOfFameList(level_nr, first_entry, highlight_position);
4704 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
4705 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4709 if (first_entry > 0)
4711 first_entry -= step;
4712 if (first_entry < 0)
4715 drawHallOfFameList(level_nr, first_entry, highlight_position);
4720 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4722 first_entry += step;
4723 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4724 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4726 drawHallOfFameList(level_nr, first_entry, highlight_position);
4729 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4731 PlaySound(SND_MENU_ITEM_SELECTING);
4733 FadeSound(SND_BACKGROUND_SCORES);
4735 if (button == MB_MENU_CHOICE &&
4736 game_status_last_screen == GAME_MODE_PLAYING &&
4737 setup.auto_play_next_level && setup.increment_levels &&
4738 level_nr < leveldir_current->last_level &&
4741 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4745 SetGameStatus(GAME_MODE_MAIN);
4751 if (game_status == GAME_MODE_SCORES)
4752 PlayMenuSoundIfLoop();
4756 // ============================================================================
4757 // setup screen functions
4758 // ============================================================================
4760 static struct TokenInfo *setup_info;
4761 static int num_setup_info; // number of setup entries shown on screen
4762 static int max_setup_info; // total number of setup entries in list
4764 static char *window_size_text;
4765 static char *scaling_type_text;
4766 static char *rendering_mode_text;
4767 static char *vsync_mode_text;
4768 static char *scroll_delay_text;
4769 static char *snapshot_mode_text;
4770 static char *game_speed_text;
4771 static char *network_server_text;
4772 static char *graphics_set_name;
4773 static char *sounds_set_name;
4774 static char *music_set_name;
4775 static char *volume_simple_text;
4776 static char *volume_loops_text;
4777 static char *volume_music_text;
4778 static char *touch_controls_text;
4779 static char *move_distance_text;
4780 static char *drop_distance_text;
4781 static char *transparency_text;
4782 static char *grid_size_text[2][2];
4784 static void execSetupMain(void)
4786 setup_mode = SETUP_MODE_MAIN;
4791 static void execSetupGame_setGameSpeeds(boolean update_value)
4793 if (setup.game_speed_extended)
4795 game_speeds_list = game_speeds_list_extended;
4796 game_speeds = game_speeds_extended;
4800 game_speeds_list = game_speeds_list_normal;
4801 game_speeds = game_speeds_normal;
4804 if (game_speeds == NULL)
4808 for (i = 0; game_speeds_list[i].value != -1; i++)
4810 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4811 char identifier[32], name[32];
4812 int value = game_speeds_list[i].value;
4813 char *text = game_speeds_list[i].text;
4815 ti->node_top = &game_speeds;
4816 ti->sort_priority = 10000 - value;
4818 sprintf(identifier, "%d", value);
4819 sprintf(name, "%s", text);
4821 setString(&ti->identifier, identifier);
4822 setString(&ti->name, name);
4823 setString(&ti->name_sorting, name);
4824 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4826 pushTreeInfo(&game_speeds, ti);
4829 // sort game speed values to start with slowest game speed
4830 sortTreeInfo(&game_speeds);
4832 update_value = TRUE;
4837 // set current game speed to configured game speed value
4838 game_speed_current =
4839 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4841 // if that fails, set current game speed to reliable default value
4842 if (game_speed_current == NULL)
4843 game_speed_current =
4844 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4846 // if that also fails, set current game speed to first available speed
4847 if (game_speed_current == NULL)
4848 game_speed_current = game_speeds;
4850 if (setup.game_speed_extended)
4851 game_speeds_extended = game_speeds;
4853 game_speeds_normal = game_speeds;
4856 setup.game_frame_delay = atoi(game_speed_current->identifier);
4858 // needed for displaying game speed text instead of identifier
4859 game_speed_text = game_speed_current->name;
4862 static void execSetupGame_setScrollDelays(void)
4864 if (scroll_delays == NULL)
4868 for (i = 0; scroll_delays_list[i].value != -1; i++)
4870 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4871 char identifier[32], name[32];
4872 int value = scroll_delays_list[i].value;
4873 char *text = scroll_delays_list[i].text;
4875 ti->node_top = &scroll_delays;
4876 ti->sort_priority = value;
4878 sprintf(identifier, "%d", value);
4879 sprintf(name, "%s", text);
4881 setString(&ti->identifier, identifier);
4882 setString(&ti->name, name);
4883 setString(&ti->name_sorting, name);
4884 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4886 pushTreeInfo(&scroll_delays, ti);
4889 // sort scroll delay values to start with lowest scroll delay value
4890 sortTreeInfo(&scroll_delays);
4892 // set current scroll delay value to configured scroll delay value
4893 scroll_delay_current =
4894 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4896 // if that fails, set current scroll delay to reliable default value
4897 if (scroll_delay_current == NULL)
4898 scroll_delay_current =
4899 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4901 // if that also fails, set current scroll delay to first available value
4902 if (scroll_delay_current == NULL)
4903 scroll_delay_current = scroll_delays;
4906 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4908 // needed for displaying scroll delay text instead of identifier
4909 scroll_delay_text = scroll_delay_current->name;
4912 static void execSetupGame_setSnapshotModes(void)
4914 if (snapshot_modes == NULL)
4918 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4920 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4921 char identifier[32], name[32];
4922 char *value = snapshot_modes_list[i].value;
4923 char *text = snapshot_modes_list[i].text;
4925 ti->node_top = &snapshot_modes;
4926 ti->sort_priority = i;
4928 sprintf(identifier, "%s", value);
4929 sprintf(name, "%s", text);
4931 setString(&ti->identifier, identifier);
4932 setString(&ti->name, name);
4933 setString(&ti->name_sorting, name);
4934 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4936 pushTreeInfo(&snapshot_modes, ti);
4939 // sort snapshot mode values to start with lowest snapshot mode value
4940 sortTreeInfo(&snapshot_modes);
4942 // set current snapshot mode value to configured snapshot mode value
4943 snapshot_mode_current =
4944 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4946 // if that fails, set current snapshot mode to reliable default value
4947 if (snapshot_mode_current == NULL)
4948 snapshot_mode_current =
4949 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4951 // if that also fails, set current snapshot mode to first available value
4952 if (snapshot_mode_current == NULL)
4953 snapshot_mode_current = snapshot_modes;
4956 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4958 // needed for displaying snapshot mode text instead of identifier
4959 snapshot_mode_text = snapshot_mode_current->name;
4962 static void execSetupGame_setNetworkServerText(void)
4964 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
4966 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
4970 strncpy(network_server_hostname, setup.network_server_hostname,
4971 MAX_SETUP_TEXT_INPUT_LEN);
4972 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
4975 // needed for displaying network server text instead of identifier
4976 network_server_text = network_server_hostname;
4979 static void execSetupGame(void)
4981 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
4983 execSetupGame_setGameSpeeds(FALSE);
4984 execSetupGame_setScrollDelays();
4985 execSetupGame_setSnapshotModes();
4987 execSetupGame_setNetworkServerText();
4989 setup_mode = SETUP_MODE_GAME;
4993 // check if vsync needs to be disabled for this game speed to work
4994 if (check_vsync_mode)
4995 DisableVsyncIfNeeded();
4998 static void execSetupChooseGameSpeed(void)
5000 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5005 static void execSetupChooseScrollDelay(void)
5007 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5012 static void execSetupChooseSnapshotMode(void)
5014 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5019 static void execSetupEditor(void)
5021 setup_mode = SETUP_MODE_EDITOR;
5026 static void execSetupGraphics_setWindowSizes(boolean update_list)
5028 if (window_sizes != NULL && update_list)
5030 freeTreeInfo(window_sizes);
5032 window_sizes = NULL;
5035 if (window_sizes == NULL)
5037 boolean current_window_size_found = FALSE;
5040 for (i = 0; window_sizes_list[i].value != -1; i++)
5042 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5043 char identifier[32], name[32];
5044 int value = window_sizes_list[i].value;
5045 char *text = window_sizes_list[i].text;
5047 ti->node_top = &window_sizes;
5048 ti->sort_priority = value;
5050 sprintf(identifier, "%d", value);
5051 sprintf(name, "%s", text);
5053 setString(&ti->identifier, identifier);
5054 setString(&ti->name, name);
5055 setString(&ti->name_sorting, name);
5056 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5058 pushTreeInfo(&window_sizes, ti);
5060 if (value == setup.window_scaling_percent)
5061 current_window_size_found = TRUE;
5064 if (!current_window_size_found)
5066 // add entry for non-preset window scaling value
5068 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5069 char identifier[32], name[32];
5070 int value = setup.window_scaling_percent;
5072 ti->node_top = &window_sizes;
5073 ti->sort_priority = value;
5075 sprintf(identifier, "%d", value);
5076 sprintf(name, "%d %% (Current)", value);
5078 setString(&ti->identifier, identifier);
5079 setString(&ti->name, name);
5080 setString(&ti->name_sorting, name);
5081 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5083 pushTreeInfo(&window_sizes, ti);
5086 // sort window size values to start with lowest window size value
5087 sortTreeInfo(&window_sizes);
5089 // set current window size value to configured window size value
5090 window_size_current =
5091 getTreeInfoFromIdentifier(window_sizes,
5092 i_to_a(setup.window_scaling_percent));
5094 // if that fails, set current window size to reliable default value
5095 if (window_size_current == NULL)
5096 window_size_current =
5097 getTreeInfoFromIdentifier(window_sizes,
5098 i_to_a(STD_WINDOW_SCALING_PERCENT));
5100 // if that also fails, set current window size to first available value
5101 if (window_size_current == NULL)
5102 window_size_current = window_sizes;
5105 setup.window_scaling_percent = atoi(window_size_current->identifier);
5107 // needed for displaying window size text instead of identifier
5108 window_size_text = window_size_current->name;
5111 static void execSetupGraphics_setScalingTypes(void)
5113 if (scaling_types == NULL)
5117 for (i = 0; scaling_types_list[i].value != NULL; i++)
5119 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5120 char identifier[32], name[32];
5121 char *value = scaling_types_list[i].value;
5122 char *text = scaling_types_list[i].text;
5124 ti->node_top = &scaling_types;
5125 ti->sort_priority = i;
5127 sprintf(identifier, "%s", value);
5128 sprintf(name, "%s", text);
5130 setString(&ti->identifier, identifier);
5131 setString(&ti->name, name);
5132 setString(&ti->name_sorting, name);
5133 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5135 pushTreeInfo(&scaling_types, ti);
5138 // sort scaling type values to start with lowest scaling type value
5139 sortTreeInfo(&scaling_types);
5141 // set current scaling type value to configured scaling type value
5142 scaling_type_current =
5143 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5145 // if that fails, set current scaling type to reliable default value
5146 if (scaling_type_current == NULL)
5147 scaling_type_current =
5148 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5150 // if that also fails, set current scaling type to first available value
5151 if (scaling_type_current == NULL)
5152 scaling_type_current = scaling_types;
5155 setup.window_scaling_quality = scaling_type_current->identifier;
5157 // needed for displaying scaling type text instead of identifier
5158 scaling_type_text = scaling_type_current->name;
5161 static void execSetupGraphics_setRenderingModes(void)
5163 if (rendering_modes == NULL)
5167 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5169 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5170 char identifier[32], name[32];
5171 char *value = rendering_modes_list[i].value;
5172 char *text = rendering_modes_list[i].text;
5174 ti->node_top = &rendering_modes;
5175 ti->sort_priority = i;
5177 sprintf(identifier, "%s", value);
5178 sprintf(name, "%s", text);
5180 setString(&ti->identifier, identifier);
5181 setString(&ti->name, name);
5182 setString(&ti->name_sorting, name);
5183 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5185 pushTreeInfo(&rendering_modes, ti);
5188 // sort rendering mode values to start with lowest rendering mode value
5189 sortTreeInfo(&rendering_modes);
5191 // set current rendering mode value to configured rendering mode value
5192 rendering_mode_current =
5193 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5195 // if that fails, set current rendering mode to reliable default value
5196 if (rendering_mode_current == NULL)
5197 rendering_mode_current =
5198 getTreeInfoFromIdentifier(rendering_modes,
5199 STR_SPECIAL_RENDERING_DEFAULT);
5201 // if that also fails, set current rendering mode to first available one
5202 if (rendering_mode_current == NULL)
5203 rendering_mode_current = rendering_modes;
5206 setup.screen_rendering_mode = rendering_mode_current->identifier;
5208 // needed for displaying rendering mode text instead of identifier
5209 rendering_mode_text = rendering_mode_current->name;
5212 static void execSetupGraphics_setVsyncModes(boolean update_value)
5214 if (vsync_modes == NULL)
5218 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5220 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5221 char identifier[32], name[32];
5222 char *value = vsync_modes_list[i].value;
5223 char *text = vsync_modes_list[i].text;
5225 ti->node_top = &vsync_modes;
5226 ti->sort_priority = i;
5228 sprintf(identifier, "%s", value);
5229 sprintf(name, "%s", text);
5231 setString(&ti->identifier, identifier);
5232 setString(&ti->name, name);
5233 setString(&ti->name_sorting, name);
5234 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5236 pushTreeInfo(&vsync_modes, ti);
5239 // sort vsync mode values to start with lowest vsync mode value
5240 sortTreeInfo(&vsync_modes);
5242 update_value = TRUE;
5247 // set current vsync mode value to configured vsync mode value
5248 vsync_mode_current =
5249 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5251 // if that fails, set current vsync mode to reliable default value
5252 if (vsync_mode_current == NULL)
5253 vsync_mode_current =
5254 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5256 // if that also fails, set current vsync mode to first available one
5257 if (vsync_mode_current == NULL)
5258 vsync_mode_current = vsync_modes;
5261 setup.vsync_mode = vsync_mode_current->identifier;
5263 // needed for displaying vsync mode text instead of identifier
5264 vsync_mode_text = vsync_mode_current->name;
5267 static void execSetupGraphics(void)
5269 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5271 // update "setup.window_scaling_percent" from list selection
5272 // (in this case, window scaling was changed on setup screen)
5273 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5274 execSetupGraphics_setWindowSizes(FALSE);
5276 // update list selection from "setup.window_scaling_percent"
5277 // (window scaling may have changed by resizing the window)
5278 execSetupGraphics_setWindowSizes(TRUE);
5280 execSetupGraphics_setScalingTypes();
5281 execSetupGraphics_setRenderingModes();
5282 execSetupGraphics_setVsyncModes(FALSE);
5284 setup_mode = SETUP_MODE_GRAPHICS;
5288 // check if game speed is high enough for 60 Hz vsync to work
5289 if (check_game_speed)
5290 ModifyGameSpeedIfNeeded();
5292 // window scaling may have changed at this point
5293 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5295 // window scaling quality may have changed at this point
5296 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5297 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5299 // screen rendering mode may have changed at this point
5300 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5302 // screen vsync mode may have changed at this point
5303 SDLSetScreenVsyncMode(setup.vsync_mode);
5306 static void execSetupChooseWindowSize(void)
5308 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5313 static void execSetupChooseScalingType(void)
5315 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5320 static void execSetupChooseRenderingMode(void)
5322 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5327 static void execSetupChooseVsyncMode(void)
5329 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5334 static void execSetupChooseVolumeSimple(void)
5336 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5341 static void execSetupChooseVolumeLoops(void)
5343 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5348 static void execSetupChooseVolumeMusic(void)
5350 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5355 static void execSetupSound(void)
5357 if (volumes_simple == NULL)
5359 boolean current_volume_simple_found = FALSE;
5362 for (i = 0; volumes_list[i].value != -1; i++)
5364 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5365 char identifier[32], name[32];
5366 int value = volumes_list[i].value;
5367 char *text = volumes_list[i].text;
5369 ti->node_top = &volumes_simple;
5370 ti->sort_priority = value;
5372 sprintf(identifier, "%d", value);
5373 sprintf(name, "%s", text);
5375 setString(&ti->identifier, identifier);
5376 setString(&ti->name, name);
5377 setString(&ti->name_sorting, name);
5378 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5380 pushTreeInfo(&volumes_simple, ti);
5382 if (value == setup.volume_simple)
5383 current_volume_simple_found = TRUE;
5386 if (!current_volume_simple_found)
5388 // add entry for non-preset volume value
5390 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5391 char identifier[32], name[32];
5392 int value = setup.volume_simple;
5394 ti->node_top = &volumes_simple;
5395 ti->sort_priority = value;
5397 sprintf(identifier, "%d", value);
5398 sprintf(name, "%d %% (Current)", value);
5400 setString(&ti->identifier, identifier);
5401 setString(&ti->name, name);
5402 setString(&ti->name_sorting, name);
5403 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5405 pushTreeInfo(&volumes_simple, ti);
5408 // sort volume values to start with lowest volume value
5409 sortTreeInfo(&volumes_simple);
5411 // set current volume value to configured volume value
5412 volume_simple_current =
5413 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5415 // if that fails, set current volume to reliable default value
5416 if (volume_simple_current == NULL)
5417 volume_simple_current =
5418 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5420 // if that also fails, set current volume to first available value
5421 if (volume_simple_current == NULL)
5422 volume_simple_current = volumes_simple;
5425 if (volumes_loops == NULL)
5427 boolean current_volume_loops_found = FALSE;
5430 for (i = 0; volumes_list[i].value != -1; i++)
5432 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5433 char identifier[32], name[32];
5434 int value = volumes_list[i].value;
5435 char *text = volumes_list[i].text;
5437 ti->node_top = &volumes_loops;
5438 ti->sort_priority = value;
5440 sprintf(identifier, "%d", value);
5441 sprintf(name, "%s", text);
5443 setString(&ti->identifier, identifier);
5444 setString(&ti->name, name);
5445 setString(&ti->name_sorting, name);
5446 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5448 pushTreeInfo(&volumes_loops, ti);
5450 if (value == setup.volume_loops)
5451 current_volume_loops_found = TRUE;
5454 if (!current_volume_loops_found)
5456 // add entry for non-preset volume value
5458 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5459 char identifier[32], name[32];
5460 int value = setup.volume_loops;
5462 ti->node_top = &volumes_loops;
5463 ti->sort_priority = value;
5465 sprintf(identifier, "%d", value);
5466 sprintf(name, "%d %% (Current)", value);
5468 setString(&ti->identifier, identifier);
5469 setString(&ti->name, name);
5470 setString(&ti->name_sorting, name);
5471 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5473 pushTreeInfo(&volumes_loops, ti);
5476 // sort volume values to start with lowest volume value
5477 sortTreeInfo(&volumes_loops);
5479 // set current volume value to configured volume value
5480 volume_loops_current =
5481 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5483 // if that fails, set current volume to reliable default value
5484 if (volume_loops_current == NULL)
5485 volume_loops_current =
5486 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5488 // if that also fails, set current volume to first available value
5489 if (volume_loops_current == NULL)
5490 volume_loops_current = volumes_loops;
5493 if (volumes_music == NULL)
5495 boolean current_volume_music_found = FALSE;
5498 for (i = 0; volumes_list[i].value != -1; i++)
5500 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5501 char identifier[32], name[32];
5502 int value = volumes_list[i].value;
5503 char *text = volumes_list[i].text;
5505 ti->node_top = &volumes_music;
5506 ti->sort_priority = value;
5508 sprintf(identifier, "%d", value);
5509 sprintf(name, "%s", text);
5511 setString(&ti->identifier, identifier);
5512 setString(&ti->name, name);
5513 setString(&ti->name_sorting, name);
5514 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5516 pushTreeInfo(&volumes_music, ti);
5518 if (value == setup.volume_music)
5519 current_volume_music_found = TRUE;
5522 if (!current_volume_music_found)
5524 // add entry for non-preset volume value
5526 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5527 char identifier[32], name[32];
5528 int value = setup.volume_music;
5530 ti->node_top = &volumes_music;
5531 ti->sort_priority = value;
5533 sprintf(identifier, "%d", value);
5534 sprintf(name, "%d %% (Current)", value);
5536 setString(&ti->identifier, identifier);
5537 setString(&ti->name, name);
5538 setString(&ti->name_sorting, name);
5539 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5541 pushTreeInfo(&volumes_music, ti);
5544 // sort volume values to start with lowest volume value
5545 sortTreeInfo(&volumes_music);
5547 // set current volume value to configured volume value
5548 volume_music_current =
5549 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5551 // if that fails, set current volume to reliable default value
5552 if (volume_music_current == NULL)
5553 volume_music_current =
5554 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5556 // if that also fails, set current volume to first available value
5557 if (volume_music_current == NULL)
5558 volume_music_current = volumes_music;
5561 setup.volume_simple = atoi(volume_simple_current->identifier);
5562 setup.volume_loops = atoi(volume_loops_current->identifier);
5563 setup.volume_music = atoi(volume_music_current->identifier);
5565 // needed for displaying volume text instead of identifier
5566 volume_simple_text = volume_simple_current->name;
5567 volume_loops_text = volume_loops_current->name;
5568 volume_music_text = volume_music_current->name;
5570 setup_mode = SETUP_MODE_SOUND;
5575 static void execSetupChooseTouchControls(void)
5577 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5582 static void execSetupChooseMoveDistance(void)
5584 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5589 static void execSetupChooseDropDistance(void)
5591 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5596 static void execSetupChooseTransparency(void)
5598 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5603 static void execSetupChooseGridXSize_0(void)
5605 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5610 static void execSetupChooseGridYSize_0(void)
5612 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5617 static void execSetupChooseGridXSize_1(void)
5619 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5624 static void execSetupChooseGridYSize_1(void)
5626 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5631 static void execSetupConfigureVirtualButtons(void)
5633 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5635 ConfigureVirtualButtons();
5637 setup_mode = SETUP_MODE_TOUCH;
5642 static void execSetupTouch(void)
5646 if (touch_controls == NULL)
5648 for (i = 0; touch_controls_list[i].value != NULL; i++)
5650 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5651 char identifier[32], name[32];
5652 char *value = touch_controls_list[i].value;
5653 char *text = touch_controls_list[i].text;
5655 ti->node_top = &touch_controls;
5656 ti->sort_priority = i;
5658 sprintf(identifier, "%s", value);
5659 sprintf(name, "%s", text);
5661 setString(&ti->identifier, identifier);
5662 setString(&ti->name, name);
5663 setString(&ti->name_sorting, name);
5664 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5666 pushTreeInfo(&touch_controls, ti);
5669 // sort touch control values to start with lowest touch control value
5670 sortTreeInfo(&touch_controls);
5672 // set current touch control value to configured touch control value
5673 touch_control_current =
5674 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5676 // if that fails, set current touch control to reliable default value
5677 if (touch_control_current == NULL)
5678 touch_control_current =
5679 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5681 // if that also fails, set current touch control to first available value
5682 if (touch_control_current == NULL)
5683 touch_control_current = touch_controls;
5686 if (move_distances == NULL)
5688 for (i = 0; distances_list[i].value != -1; i++)
5690 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5691 char identifier[32], name[32];
5692 int value = distances_list[i].value;
5693 char *text = distances_list[i].text;
5695 ti->node_top = &move_distances;
5696 ti->sort_priority = value;
5698 sprintf(identifier, "%d", value);
5699 sprintf(name, "%s", text);
5701 setString(&ti->identifier, identifier);
5702 setString(&ti->name, name);
5703 setString(&ti->name_sorting, name);
5704 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5706 pushTreeInfo(&move_distances, ti);
5709 // sort distance values to start with lowest distance value
5710 sortTreeInfo(&move_distances);
5712 // set current distance value to configured distance value
5713 move_distance_current =
5714 getTreeInfoFromIdentifier(move_distances,
5715 i_to_a(setup.touch.move_distance));
5717 // if that fails, set current distance to reliable default value
5718 if (move_distance_current == NULL)
5719 move_distance_current =
5720 getTreeInfoFromIdentifier(move_distances,
5721 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5723 // if that also fails, set current distance to first available value
5724 if (move_distance_current == NULL)
5725 move_distance_current = move_distances;
5728 if (drop_distances == NULL)
5730 for (i = 0; distances_list[i].value != -1; i++)
5732 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5733 char identifier[32], name[32];
5734 int value = distances_list[i].value;
5735 char *text = distances_list[i].text;
5737 ti->node_top = &drop_distances;
5738 ti->sort_priority = value;
5740 sprintf(identifier, "%d", value);
5741 sprintf(name, "%s", text);
5743 setString(&ti->identifier, identifier);
5744 setString(&ti->name, name);
5745 setString(&ti->name_sorting, name);
5746 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5748 pushTreeInfo(&drop_distances, ti);
5751 // sort distance values to start with lowest distance value
5752 sortTreeInfo(&drop_distances);
5754 // set current distance value to configured distance value
5755 drop_distance_current =
5756 getTreeInfoFromIdentifier(drop_distances,
5757 i_to_a(setup.touch.drop_distance));
5759 // if that fails, set current distance to reliable default value
5760 if (drop_distance_current == NULL)
5761 drop_distance_current =
5762 getTreeInfoFromIdentifier(drop_distances,
5763 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5765 // if that also fails, set current distance to first available value
5766 if (drop_distance_current == NULL)
5767 drop_distance_current = drop_distances;
5770 if (transparencies == NULL)
5772 for (i = 0; transparencies_list[i].value != -1; i++)
5774 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5775 char identifier[32], name[32];
5776 int value = transparencies_list[i].value;
5777 char *text = transparencies_list[i].text;
5779 ti->node_top = &transparencies;
5780 ti->sort_priority = value;
5782 sprintf(identifier, "%d", value);
5783 sprintf(name, "%s", text);
5785 setString(&ti->identifier, identifier);
5786 setString(&ti->name, name);
5787 setString(&ti->name_sorting, name);
5788 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5790 pushTreeInfo(&transparencies, ti);
5793 // sort transparency values to start with lowest transparency value
5794 sortTreeInfo(&transparencies);
5796 // set current transparency value to configured transparency value
5797 transparency_current =
5798 getTreeInfoFromIdentifier(transparencies,
5799 i_to_a(setup.touch.transparency));
5801 // if that fails, set current transparency to reliable default value
5802 if (transparency_current == NULL)
5803 transparency_current =
5804 getTreeInfoFromIdentifier(transparencies,
5805 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5807 // if that also fails, set current transparency to first available value
5808 if (transparency_current == NULL)
5809 transparency_current = transparencies;
5812 for (i = 0; i < 2; i++)
5814 for (j = 0; j < 2; j++)
5816 if (grid_sizes[i][j] == NULL)
5818 for (k = 0; grid_sizes_list[k].value != -1; k++)
5820 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5821 char identifier[32], name[32];
5822 int value = grid_sizes_list[k].value;
5823 char *text = grid_sizes_list[k].text;
5825 ti->node_top = &grid_sizes[i][j];
5826 ti->sort_priority = value;
5828 sprintf(identifier, "%d", value);
5829 sprintf(name, "%s", text);
5831 setString(&ti->identifier, identifier);
5832 setString(&ti->name, name);
5833 setString(&ti->name_sorting, name);
5834 setString(&ti->infotext,
5837 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5838 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5840 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5841 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5843 pushTreeInfo(&grid_sizes[i][j], ti);
5846 // sort grid size values to start with lowest grid size value
5847 sortTreeInfo(&grid_sizes[i][j]);
5849 // set current grid size value to configured grid size value
5850 grid_size_current[i][j] =
5851 getTreeInfoFromIdentifier(grid_sizes[i][j],
5853 setup.touch.grid_xsize[i] :
5854 setup.touch.grid_ysize[i]));
5856 // if that fails, set current grid size to reliable default value
5857 if (grid_size_current[i][j] == NULL)
5858 grid_size_current[i][j] =
5859 getTreeInfoFromIdentifier(grid_sizes[i][j],
5861 DEFAULT_GRID_XSIZE(i) :
5862 DEFAULT_GRID_YSIZE(i)));
5864 // if that also fails, set current grid size to first available value
5865 if (grid_size_current[i][j] == NULL)
5866 grid_size_current[i][j] = grid_sizes[i][j];
5871 setup.touch.control_type = touch_control_current->identifier;
5872 setup.touch.move_distance = atoi(move_distance_current->identifier);
5873 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5874 setup.touch.transparency = atoi(transparency_current->identifier);
5876 for (i = 0; i < 2; i++)
5878 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5879 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5881 if (i == GRID_ACTIVE_NR())
5883 overlay.grid_xsize = setup.touch.grid_xsize[i];
5884 overlay.grid_ysize = setup.touch.grid_ysize[i];
5888 // needed for displaying value text instead of identifier
5889 touch_controls_text = touch_control_current->name;
5890 move_distance_text = move_distance_current->name;
5891 drop_distance_text = drop_distance_current->name;
5892 transparency_text = transparency_current->name;
5894 for (i = 0; i < 2; i++)
5895 for (j = 0; j < 2; j++)
5896 grid_size_text[i][j] = grid_size_current[i][j]->name;
5898 setup_mode = SETUP_MODE_TOUCH;
5903 static void execSetupArtwork(void)
5906 printf("::: '%s', '%s', '%s'\n",
5907 artwork.gfx_current->subdir,
5908 artwork.gfx_current->fullpath,
5909 artwork.gfx_current->basepath);
5912 setup.graphics_set = artwork.gfx_current->identifier;
5913 setup.sounds_set = artwork.snd_current->identifier;
5914 setup.music_set = artwork.mus_current->identifier;
5916 // needed if last screen (setup choice) changed graphics, sounds or music
5917 ReloadCustomArtwork(0);
5919 // needed for displaying artwork name instead of artwork identifier
5920 graphics_set_name = artwork.gfx_current->name;
5921 sounds_set_name = artwork.snd_current->name;
5922 music_set_name = artwork.mus_current->name;
5924 setup_mode = SETUP_MODE_ARTWORK;
5929 static void execSetupChooseGraphics(void)
5931 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5936 static void execSetupChooseSounds(void)
5938 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5943 static void execSetupChooseMusic(void)
5945 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5950 static void execSetupInput(void)
5952 setup_mode = SETUP_MODE_INPUT;
5957 static void execSetupShortcuts(void)
5959 setup_mode = SETUP_MODE_SHORTCUTS;
5964 static void execSetupShortcuts1(void)
5966 setup_mode = SETUP_MODE_SHORTCUTS_1;
5971 static void execSetupShortcuts2(void)
5973 setup_mode = SETUP_MODE_SHORTCUTS_2;
5978 static void execSetupShortcuts3(void)
5980 setup_mode = SETUP_MODE_SHORTCUTS_3;
5985 static void execSetupShortcuts4(void)
5987 setup_mode = SETUP_MODE_SHORTCUTS_4;
5992 static void execSetupShortcuts5(void)
5994 setup_mode = SETUP_MODE_SHORTCUTS_5;
5999 static void execExitSetup(void)
6001 SetGameStatus(GAME_MODE_MAIN);
6006 static void execSaveAndExitSetup(void)
6012 static void execGadgetNetworkServer(void)
6014 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6015 struct GadgetInfo *gi = screen_gadget[gadget_id];
6017 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6018 network_server_hostname[0] = '\0';
6020 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6024 ClickOnGadget(gi, MB_LEFTBUTTON);
6027 static void ToggleNetworkModeIfNeeded(void)
6029 int font_title = FONT_TITLE_1;
6030 int font_foot = FC_BLUE;
6031 int ystart = mSY - SY + 16;
6032 int ybottom = mSY - SY + SYSIZE - 20;
6033 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6035 if (setup.network_mode == network.enabled)
6038 network.enabled = setup.network_mode;
6040 FadeOut(REDRAW_ALL);
6044 DrawTextSCentered(ystart, font_title, text);
6048 if (network.enabled)
6049 InitNetworkServer();
6051 DisconnectFromNetworkServer();
6053 DrawTextSCentered(ybottom, font_foot,
6054 "Press any key or button for setup menu");
6056 WaitForEventToContinue();
6061 static void ToggleGameSpeedsListIfNeeded(void)
6063 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6065 if (setup.game_speed_extended == using_game_speeds_extended)
6068 // try to match similar values when changing game speeds list
6069 if (setup.game_speed_extended)
6070 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6071 setup.game_frame_delay == 30 ? 29 :
6072 setup.game_frame_delay);
6074 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6075 setup.game_frame_delay == 16 ? 15 :
6076 setup.game_frame_delay >= 29 ? 30 :
6077 setup.game_frame_delay <= 10 ? 10 :
6078 setup.game_frame_delay);
6080 execSetupGame_setGameSpeeds(TRUE);
6085 static void ModifyGameSpeedIfNeeded(void)
6087 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6088 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6092 char *game_speed_text = "Fast";
6093 int game_speed_value = 15;
6095 if (setup.game_speed_extended)
6097 game_speed_text = "60 fps";
6098 game_speed_value = 16;
6101 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6103 // set game speed to existing list value that is fast enough for vsync
6104 setup.game_frame_delay = game_speed_value;
6106 execSetupGame_setGameSpeeds(TRUE);
6108 Request(message, REQ_CONFIRM);
6111 static void DisableVsyncIfNeeded(void)
6113 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6114 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6115 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6118 // disable vsync for the selected game speed to work
6119 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6121 execSetupGraphics_setVsyncModes(TRUE);
6123 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6129 void *related_value;
6130 } hide_related_entry_list[] =
6132 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6133 { &setup.game_frame_delay, &game_speed_text },
6135 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6136 { &setup.scroll_delay_value, &scroll_delay_text },
6138 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6139 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6141 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6142 { &setup.window_scaling_percent, &window_size_text },
6144 { &setup.window_scaling_quality, execSetupChooseScalingType },
6145 { &setup.window_scaling_quality, &scaling_type_text },
6147 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6148 { &setup.screen_rendering_mode, &rendering_mode_text },
6150 { &setup.vsync_mode, execSetupChooseVsyncMode },
6151 { &setup.vsync_mode, &vsync_mode_text },
6153 { &setup.graphics_set, execSetupChooseGraphics },
6154 { &setup.graphics_set, &graphics_set_name },
6156 { &setup.sounds_set, execSetupChooseSounds },
6157 { &setup.sounds_set, &sounds_set_name },
6159 { &setup.music_set, execSetupChooseMusic },
6160 { &setup.music_set, &music_set_name },
6162 { &setup.volume_simple, execSetupChooseVolumeSimple },
6163 { &setup.volume_simple, &volume_simple_text },
6165 { &setup.volume_loops, execSetupChooseVolumeLoops },
6166 { &setup.volume_loops, &volume_loops_text },
6168 { &setup.volume_music, execSetupChooseVolumeMusic },
6169 { &setup.volume_music, &volume_music_text },
6171 { &setup.touch.control_type, execSetupChooseTouchControls },
6172 { &setup.touch.control_type, &touch_controls_text },
6174 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6175 { &setup.touch.move_distance, &move_distance_text },
6177 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6178 { &setup.touch.drop_distance, &drop_distance_text },
6180 { &setup.touch.transparency, execSetupChooseTransparency },
6181 { &setup.touch.transparency, &transparency_text },
6183 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6184 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6186 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6187 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6189 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6190 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6192 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6193 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6195 { &setup.internal.menu_game, execSetupGame },
6196 { &setup.internal.menu_editor, execSetupEditor },
6197 { &setup.internal.menu_graphics, execSetupGraphics },
6198 { &setup.internal.menu_sound, execSetupSound },
6199 { &setup.internal.menu_artwork, execSetupArtwork },
6200 { &setup.internal.menu_input, execSetupInput },
6201 { &setup.internal.menu_touch, execSetupTouch },
6202 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6203 { &setup.internal.menu_exit, execExitSetup },
6204 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6209 void setHideRelatedSetupEntries(void)
6213 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6214 if (hideSetupEntry(hide_related_entry_list[i].value))
6215 setHideSetupEntry(hide_related_entry_list[i].related_value);
6218 static struct TokenInfo setup_info_main[] =
6220 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6221 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6222 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6223 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6224 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6225 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6226 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6227 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6228 { TYPE_EMPTY, NULL, "" },
6229 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6230 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6235 static struct TokenInfo setup_info_game[] =
6237 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6238 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6239 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6240 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6241 { TYPE_STRING, &network_server_text, "" },
6242 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6243 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6244 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6245 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6246 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6247 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6248 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
6249 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6250 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6251 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6252 { TYPE_STRING, &game_speed_text, "" },
6253 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6255 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6256 { TYPE_STRING, &scroll_delay_text, "" },
6258 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6259 { TYPE_STRING, &snapshot_mode_text, "" },
6260 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6261 { TYPE_EMPTY, NULL, "" },
6262 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6267 static struct TokenInfo setup_info_editor[] =
6270 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6271 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6272 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6273 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6274 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6275 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6276 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6277 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6278 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6279 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6281 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6282 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6284 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6286 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6287 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6288 { TYPE_EMPTY, NULL, "" },
6290 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6291 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6292 { TYPE_EMPTY, NULL, "" },
6294 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6295 { TYPE_EMPTY, NULL, "" },
6296 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6301 static struct TokenInfo setup_info_graphics[] =
6303 #if !defined(PLATFORM_ANDROID)
6304 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6305 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6306 { TYPE_STRING, &window_size_text, "" },
6307 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6308 { TYPE_STRING, &scaling_type_text, "" },
6309 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6310 { TYPE_STRING, &rendering_mode_text, "" },
6313 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6314 { TYPE_STRING, &scroll_delay_text, "" },
6316 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6317 { TYPE_STRING, &vsync_mode_text, "" },
6318 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6319 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6320 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6321 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6322 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6323 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
6324 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
6325 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6326 { TYPE_EMPTY, NULL, "" },
6327 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6332 static struct TokenInfo setup_info_sound[] =
6334 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6335 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6336 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6337 { TYPE_EMPTY, NULL, "" },
6338 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6339 { TYPE_STRING, &volume_simple_text, "" },
6340 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6341 { TYPE_STRING, &volume_loops_text, "" },
6342 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6343 { TYPE_STRING, &volume_music_text, "" },
6344 { TYPE_EMPTY, NULL, "" },
6345 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6350 static struct TokenInfo setup_info_artwork[] =
6352 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6353 { TYPE_STRING, &graphics_set_name, "" },
6354 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6355 { TYPE_STRING, &sounds_set_name, "" },
6356 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6357 { TYPE_STRING, &music_set_name, "" },
6358 { TYPE_EMPTY, NULL, "" },
6359 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6360 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6361 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6362 { TYPE_EMPTY, NULL, "" },
6363 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6368 static struct TokenInfo setup_info_input[] =
6370 { TYPE_SWITCH, NULL, "Player:" },
6371 { TYPE_SWITCH, NULL, "Device:" },
6372 { TYPE_SWITCH, NULL, "" },
6373 { TYPE_SKIPPABLE, NULL, "" },
6374 { TYPE_EMPTY, NULL, "" },
6375 { TYPE_EMPTY, NULL, "" },
6376 { TYPE_EMPTY, NULL, "" },
6377 { TYPE_EMPTY, NULL, "" },
6378 { TYPE_EMPTY, NULL, "" },
6379 { TYPE_EMPTY, NULL, "" },
6380 { TYPE_EMPTY, NULL, "" },
6381 { TYPE_EMPTY, NULL, "" },
6382 { TYPE_SKIPPABLE, NULL, "" },
6383 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6388 static struct TokenInfo setup_info_touch[] =
6390 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6391 { TYPE_STRING, &touch_controls_text, "" },
6392 { TYPE_EMPTY, NULL, "" },
6393 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6398 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6400 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6401 { TYPE_STRING, &touch_controls_text, "" },
6402 { TYPE_EMPTY, NULL, "" },
6403 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6404 { TYPE_STRING, &grid_size_text[0][0], "" },
6405 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6406 { TYPE_STRING, &grid_size_text[0][1], "" },
6407 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6408 { TYPE_STRING, &transparency_text, "" },
6409 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6410 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6411 { TYPE_EMPTY, NULL, "" },
6412 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6413 { TYPE_EMPTY, NULL, "" },
6414 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6419 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6421 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6422 { TYPE_STRING, &touch_controls_text, "" },
6423 { TYPE_EMPTY, NULL, "" },
6424 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6425 { TYPE_STRING, &grid_size_text[1][0], "" },
6426 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6427 { TYPE_STRING, &grid_size_text[1][1], "" },
6428 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6429 { TYPE_STRING, &transparency_text, "" },
6430 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6431 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6432 { TYPE_EMPTY, NULL, "" },
6433 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6434 { TYPE_EMPTY, NULL, "" },
6435 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6440 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6442 setup_info_touch_virtual_buttons_0,
6443 setup_info_touch_virtual_buttons_1
6446 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6448 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6449 { TYPE_STRING, &touch_controls_text, "" },
6450 { TYPE_EMPTY, NULL, "" },
6451 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6452 { TYPE_STRING, &move_distance_text, "" },
6453 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6454 { TYPE_STRING, &drop_distance_text, "" },
6455 { TYPE_EMPTY, NULL, "" },
6456 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6461 static struct TokenInfo setup_info_shortcuts[] =
6463 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6464 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6465 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6466 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6467 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6468 { TYPE_EMPTY, NULL, "" },
6469 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6474 static struct TokenInfo setup_info_shortcuts_1[] =
6476 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6477 { TYPE_KEY, &setup.shortcut.save_game, "" },
6478 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6479 { TYPE_KEY, &setup.shortcut.load_game, "" },
6480 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6481 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6482 { TYPE_EMPTY, NULL, "" },
6483 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6484 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6485 { TYPE_EMPTY, NULL, "" },
6486 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6491 static struct TokenInfo setup_info_shortcuts_2[] =
6493 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6494 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6495 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6496 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6497 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6498 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6499 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6500 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6501 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6502 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6503 { TYPE_EMPTY, NULL, "" },
6504 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6509 static struct TokenInfo setup_info_shortcuts_3[] =
6511 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6512 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6513 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6514 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6515 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6516 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6517 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6518 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6519 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6520 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6521 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6522 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6523 { TYPE_EMPTY, NULL, "" },
6524 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6529 static struct TokenInfo setup_info_shortcuts_4[] =
6531 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6532 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6533 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6534 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6535 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6536 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6537 { TYPE_EMPTY, NULL, "" },
6538 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6543 static struct TokenInfo setup_info_shortcuts_5[] =
6545 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6546 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6547 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6548 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6549 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6550 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6551 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6552 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6553 { TYPE_EMPTY, NULL, "" },
6554 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6559 static Key getSetupKey(void)
6561 Key key = KSYM_UNDEFINED;
6562 boolean got_key_event = FALSE;
6564 while (!got_key_event)
6568 if (NextValidEvent(&event))
6572 case EVENT_KEYPRESS:
6574 key = GetEventKey((KeyEvent *)&event, TRUE);
6576 // press 'Escape' or 'Enter' to keep the existing key binding
6577 if (key == KSYM_Escape || key == KSYM_Return)
6578 key = KSYM_UNDEFINED; // keep old value
6580 got_key_event = TRUE;
6584 case EVENT_KEYRELEASE:
6585 key_joystick_mapping = 0;
6589 HandleOtherEvents(&event);
6600 static int getSetupValueFont(int type, void *value)
6602 if (type & TYPE_GHOSTED)
6603 return FONT_OPTION_OFF;
6604 else if (type & TYPE_KEY)
6605 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6606 else if (type & TYPE_STRING)
6607 return FONT_VALUE_2;
6608 else if (type & TYPE_ECS_AGA)
6609 return FONT_VALUE_1;
6610 else if (type & TYPE_BOOLEAN_STYLE)
6611 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6612 else if (type & TYPE_YES_NO_AUTO)
6613 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6614 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6615 else if (type & TYPE_PLAYER)
6616 return FONT_VALUE_1;
6618 return FONT_VALUE_1;
6621 static int getSetupValueFontNarrow(int type, int font_nr)
6623 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6624 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6625 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6629 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6631 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6632 struct TokenInfo *si = &setup_info[si_pos];
6633 boolean font_draw_xoffset_modified = FALSE;
6634 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6635 int font_draw_xoffset_old = -1;
6636 int xoffset = (scrollbar_needed ? -1 : 0);
6637 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6638 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6639 int xpos = menu_screen_value_xpos;
6640 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6641 int startx = mSX + xpos * 32;
6642 int starty = mSY + ypos * 32;
6643 int type = si->type;
6644 void *value = si->value;
6645 char *value_string = getSetupValue(type, value);
6646 int font_nr_default = getSetupValueFont(type, value);
6647 int font_width_default = getFontWidth(font_nr_default);
6648 int font_nr = font_nr_default;
6651 if (value_string == NULL)
6654 if (type & TYPE_KEY)
6656 xpos = MENU_SCREEN_START_XPOS;
6658 if (type & TYPE_QUERY)
6659 value_string = "<press key>";
6661 else if (type & TYPE_STRING)
6663 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
6665 xpos = MENU_SCREEN_START_XPOS;
6667 if (strlen(value_string) > max_value_len)
6668 value_string[max_value_len] = '\0';
6670 else if (type & TYPE_YES_NO_AUTO)
6672 xpos = menu_screen_value_xpos - 1;
6674 else if (type & TYPE_PLAYER)
6676 int displayed_player_nr = *(int *)value + 1;
6678 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6681 startx = mSX + xpos * 32;
6682 starty = mSY + ypos * 32;
6684 // special check if right-side setup values moved left due to scrollbar
6685 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6687 int max_menu_text_length = 26; // maximum text length for classic menu
6688 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6689 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6690 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6691 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6692 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6694 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6697 startx = mSX + xpos * 32;
6699 font_nr = getSetupValueFontNarrow(type, font_nr);
6703 // downward compatibility correction for Juergen Bonhagen's menu settings
6704 if (setup_mode != SETUP_MODE_INPUT)
6706 int max_menu_text_length_big = (menu_screen_value_xpos -
6707 MENU_SCREEN_START_XPOS);
6708 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6709 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
6710 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6711 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6712 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6713 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6714 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6715 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6716 boolean correct_font_draw_xoffset = FALSE;
6718 if (xpos == MENU_SCREEN_START_XPOS &&
6719 startx + font1_xoffset < text_startx + text_font_xoffset)
6720 correct_font_draw_xoffset = TRUE;
6722 if (xpos == menu_screen_value_xpos &&
6723 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6724 correct_font_draw_xoffset = TRUE;
6726 // check if setup value would overlap with setup text when printed
6727 // (this can happen for extreme/wrong values for font draw offset)
6728 if (correct_font_draw_xoffset)
6730 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6731 font_draw_xoffset_modified = TRUE;
6733 if (type & TYPE_KEY)
6734 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6735 else if (!(type & TYPE_STRING))
6736 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6737 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6741 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6742 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6744 DrawText(startx, starty, value_string, font_nr);
6746 if (type & TYPE_PLAYER)
6748 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
6749 int player_nr = *(int *)value;
6750 int xoff = font->draw_xoffset + getFontWidth(font_nr);
6751 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
6752 int startx2 = startx + xoff;
6753 int starty2 = starty + yoff;
6755 if (DrawingOnBackground(startx2, starty2))
6756 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
6758 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
6759 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6762 if (font_draw_xoffset_modified)
6763 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6766 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6768 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6769 struct TokenInfo *si = &setup_info[si_pos];
6771 if (si->type & TYPE_BOOLEAN_STYLE)
6773 *(boolean *)si->value ^= TRUE;
6775 else if (si->type & TYPE_YES_NO_AUTO)
6779 (*(int *)si->value == AUTO ? TRUE :
6780 *(int *)si->value == TRUE ? FALSE : AUTO) :
6781 (*(int *)si->value == TRUE ? AUTO :
6782 *(int *)si->value == AUTO ? FALSE : TRUE));
6784 else if (si->type & TYPE_KEY)
6788 si->type |= TYPE_QUERY;
6789 drawSetupValue(screen_pos, setup_info_pos_raw);
6790 si->type &= ~TYPE_QUERY;
6792 key = getSetupKey();
6793 if (key != KSYM_UNDEFINED)
6794 *(Key *)si->value = key;
6796 else if (si->type & TYPE_PLAYER)
6798 int player_nr = *(int *)si->value;
6803 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6805 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6808 drawSetupValue(screen_pos, setup_info_pos_raw);
6810 // fullscreen state may have changed at this point
6811 if (si->value == &setup.fullscreen)
6812 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6814 // network mode may have changed at this point
6815 if (si->value == &setup.network_mode)
6816 ToggleNetworkModeIfNeeded();
6818 // game speed list may have changed at this point
6819 if (si->value == &setup.game_speed_extended)
6820 ToggleGameSpeedsListIfNeeded();
6823 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6825 static struct TokenInfo *setup_info_final = NULL;
6830 // determine maximum list size of target list
6831 while (setup_info_orig[list_size++].type != 0);
6833 // free, allocate and clear memory for target list
6834 checked_free(setup_info_final);
6835 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6837 // copy setup info list without setup entries marked as hidden
6838 for (i = 0; setup_info_orig[i].type != 0; i++)
6840 // skip setup entries configured to be hidden
6841 if (hideSetupEntry(setup_info_orig[i].value))
6844 // skip skippable setup entries if screen is lower than usual
6845 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6846 setup_info_orig[i].type == TYPE_SKIPPABLE)
6849 setup_info_final[list_pos++] = setup_info_orig[i];
6852 return setup_info_final;
6855 static void DrawSetupScreen_Generic(void)
6857 int fade_mask = REDRAW_FIELD;
6858 boolean redraw_all = FALSE;
6859 char *title_string = NULL;
6863 fade_mask = REDRAW_ALL;
6866 FadeMenuSoundsAndMusic();
6868 FreeScreenGadgets();
6869 CreateScreenGadgets();
6871 if (redraw_mask & REDRAW_ALL)
6876 // needed if different viewport properties defined for setup screen
6877 ChangeViewportPropertiesIfNeeded();
6879 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6883 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6885 if (setup_mode == SETUP_MODE_MAIN)
6887 setup_info = setup_info_main;
6888 title_string = STR_SETUP_MAIN;
6890 else if (setup_mode == SETUP_MODE_GAME)
6892 setup_info = setup_info_game;
6893 title_string = STR_SETUP_GAME;
6895 else if (setup_mode == SETUP_MODE_EDITOR)
6897 setup_info = setup_info_editor;
6898 title_string = STR_SETUP_EDITOR;
6900 else if (setup_mode == SETUP_MODE_GRAPHICS)
6902 setup_info = setup_info_graphics;
6903 title_string = STR_SETUP_GRAPHICS;
6905 else if (setup_mode == SETUP_MODE_SOUND)
6907 setup_info = setup_info_sound;
6908 title_string = STR_SETUP_SOUND;
6910 else if (setup_mode == SETUP_MODE_ARTWORK)
6912 setup_info = setup_info_artwork;
6913 title_string = STR_SETUP_ARTWORK;
6915 else if (setup_mode == SETUP_MODE_TOUCH)
6917 setup_info = setup_info_touch;
6918 title_string = STR_SETUP_TOUCH;
6920 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6921 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6922 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6923 setup_info = setup_info_touch_wipe_gestures;
6925 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6927 setup_info = setup_info_shortcuts;
6928 title_string = STR_SETUP_SHORTCUTS;
6930 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6932 setup_info = setup_info_shortcuts_1;
6933 title_string = STR_SETUP_SHORTCUTS;
6935 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6937 setup_info = setup_info_shortcuts_2;
6938 title_string = STR_SETUP_SHORTCUTS;
6940 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6942 setup_info = setup_info_shortcuts_3;
6943 title_string = STR_SETUP_SHORTCUTS;
6945 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6947 setup_info = setup_info_shortcuts_4;
6948 title_string = STR_SETUP_SHORTCUTS;
6950 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6952 setup_info = setup_info_shortcuts_5;
6953 title_string = STR_SETUP_SHORTCUTS;
6956 // use modified setup info without setup entries marked as hidden
6957 setup_info = getSetupInfoFinal(setup_info);
6959 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6961 // determine maximal number of setup entries that can be displayed on screen
6963 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6966 // determine maximal number of setup entries available for this setup screen
6968 for (i = 0; setup_info[i].type != 0; i++)
6971 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6973 MapScreenGadgets(max_setup_info);
6976 redraw_mask = fade_mask = REDRAW_ALL;
6978 DrawMaskedBorder(fade_mask);
6983 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6985 menu_info = setup_info;
6987 HandleMenuScreen(mx, my, dx, dy, button,
6988 setup_mode, num_setup_info, max_setup_info);
6991 static void DrawSetupScreen_Input(void)
6995 FadeOut(REDRAW_FIELD);
6999 setup_info = getSetupInfoFinal(setup_info_input);
7001 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7003 for (i = 0; setup_info[i].type != 0; i++)
7005 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7006 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7007 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7008 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7009 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7010 initCursor(i, IMG_MENU_BUTTON);
7012 DrawCursorAndText_Setup(i, -1, FALSE);
7015 // create gadgets for setup input menu screen
7016 FreeScreenGadgets();
7017 CreateScreenGadgets();
7019 // map gadgets for setup input menu screen
7020 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7022 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7024 FadeIn(REDRAW_FIELD);
7027 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7029 if (device_name == NULL)
7032 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7035 if (strlen(device_name) > 1)
7037 char c1 = device_name[strlen(device_name) - 1];
7038 char c2 = device_name[strlen(device_name) - 2];
7040 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7041 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7044 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7045 strlen(device_name));
7048 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7051 static struct SetupKeyboardInfo custom_key;
7058 { &custom_key.left, "Axis/Pad Left" },
7059 { &custom_key.right, "Axis/Pad Right" },
7060 { &custom_key.up, "Axis/Pad Up" },
7061 { &custom_key.down, "Axis/Pad Down" },
7062 { &custom_key.snap, "Button 1/A/X" },
7063 { &custom_key.drop, "Button 2/B/Y" }
7065 static char *joystick_name[MAX_PLAYERS] =
7072 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7073 int font_nr_info = FONT_MENU_1;
7074 int font_nr_name = FONT_VALUE_OLD;
7075 int font_nr_on = FONT_VALUE_1;
7076 int font_nr_off = FONT_VALUE_OLD;
7079 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7081 font_nr_info = FONT_MENU_2;
7082 font_nr_on = FONT_VALUE_NARROW;
7083 font_nr_off = FONT_VALUE_OLD_NARROW;
7086 custom_key = setup.input[player_nr].key;
7088 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7089 FONT_INPUT_1_ACTIVE);
7091 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7093 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7094 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7096 if (setup.input[player_nr].use_joystick)
7098 char *device_name = setup.input[player_nr].joy.device_name;
7099 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7100 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7101 char *text = joystick_name[joystick_nr];
7102 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7104 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7105 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7109 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7110 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7113 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7114 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7118 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7119 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7120 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7121 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7123 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7124 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7125 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7126 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7127 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7128 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7130 for (i = 0; i < 6; i++)
7132 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7134 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7136 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7137 (setup.input[player_nr].use_joystick ?
7139 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7143 static int input_player_nr = 0;
7145 static void HandleSetupScreen_Input_Player(int step, int direction)
7147 int old_player_nr = input_player_nr;
7150 new_player_nr = old_player_nr + step * direction;
7151 if (new_player_nr < 0)
7153 if (new_player_nr > MAX_PLAYERS - 1)
7154 new_player_nr = MAX_PLAYERS - 1;
7156 if (new_player_nr != old_player_nr)
7158 input_player_nr = new_player_nr;
7160 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7164 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7166 static int choice = 0;
7169 int pos_start = SETUPINPUT_SCREEN_POS_START;
7170 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7171 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7172 int pos_end = SETUPINPUT_SCREEN_POS_END;
7174 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7178 for (i = 0; setup_info_input[i].type != 0; i++)
7180 // adjust menu structure according to skipped setup entries
7181 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7189 if (button == MB_MENU_INITIALIZE)
7191 // input setup menu may have changed size due to graphics configuration
7192 if (choice >= pos_empty1)
7195 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7197 DrawCursorAndText_Setup(choice, -1, TRUE);
7201 else if (button == MB_MENU_LEAVE)
7203 setup_mode = SETUP_MODE_MAIN;
7210 if (mx || my) // mouse input
7212 x = (mx - mSX) / 32;
7213 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7215 else if (dx || dy) // keyboard input
7217 if (dx && choice == 0)
7218 x = (dx < 0 ? 10 : 12);
7219 else if ((dx && choice == 1) ||
7220 (dx == -1 && choice == pos_end))
7221 button = MB_MENU_CHOICE;
7225 if (y >= pos_empty1 && y <= pos_empty2)
7226 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7229 if (y == 0 && dx != 0 && button)
7231 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7233 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7234 y >= pos_start && y <= pos_end &&
7235 !(y >= pos_empty1 && y <= pos_empty2))
7241 DrawCursorAndText_Setup(choice, -1, FALSE);
7242 DrawCursorAndText_Setup(y, -1, TRUE);
7244 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7253 char *device_name = setup.input[input_player_nr].joy.device_name;
7255 if (!setup.input[input_player_nr].use_joystick)
7257 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7259 setJoystickDeviceToNr(device_name, new_device_nr);
7260 setup.input[input_player_nr].use_joystick = TRUE;
7264 int device_nr = getJoystickNrFromDeviceName(device_name);
7265 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7267 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7268 setup.input[input_player_nr].use_joystick = FALSE;
7270 setJoystickDeviceToNr(device_name, new_device_nr);
7273 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7277 if (setup.input[input_player_nr].use_joystick)
7278 ConfigureJoystick(input_player_nr);
7280 CustomizeKeyboard(input_player_nr);
7282 else if (y == pos_end)
7288 setup_mode = SETUP_MODE_MAIN;
7295 static boolean CustomizeKeyboardMain(int player_nr)
7299 boolean finished = FALSE;
7300 static struct SetupKeyboardInfo custom_key;
7305 } customize_step[] =
7307 { &custom_key.left, "Move Left" },
7308 { &custom_key.right, "Move Right" },
7309 { &custom_key.up, "Move Up" },
7310 { &custom_key.down, "Move Down" },
7311 { &custom_key.snap, "Snap Field" },
7312 { &custom_key.drop, "Drop Element" }
7314 int font_nr_old = FONT_VALUE_OLD;
7315 int font_nr_new = FONT_VALUE_1;
7316 boolean success = FALSE;
7318 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7320 font_nr_old = FONT_VALUE_OLD_NARROW;
7321 font_nr_new = FONT_VALUE_NARROW;
7324 // read existing key bindings from player setup
7325 custom_key = setup.input[player_nr].key;
7328 FadeOut(REDRAW_FIELD);
7332 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7335 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7336 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7337 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7338 "Key:", FONT_INPUT_1_ACTIVE);
7339 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7340 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7342 FadeIn(REDRAW_FIELD);
7348 if (NextValidEvent(&event))
7352 case EVENT_KEYPRESS:
7354 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7356 // press 'Escape' to abort and keep the old key bindings
7357 if (key == KSYM_Escape)
7359 FadeSkipNextFadeIn();
7366 // press 'Enter' to keep the existing key binding
7367 if (key == KSYM_Return)
7368 key = *customize_step[step_nr].key;
7370 // check if key already used
7371 for (i = 0; i < step_nr; i++)
7372 if (*customize_step[i].key == key)
7377 // got new key binding
7378 *customize_step[step_nr].key = key;
7379 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7381 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7382 getKeyNameFromKey(key), font_nr_new);
7385 // un-highlight last query
7386 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7387 customize_step[step_nr - 1].text, FONT_MENU_1);
7388 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7389 "Key:", FONT_MENU_1);
7391 // all keys configured
7400 // query next key binding
7401 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7402 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7403 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7404 "Key:", FONT_INPUT_1_ACTIVE);
7405 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7406 getKeyNameFromKey(*customize_step[step_nr].key),
7411 case EVENT_KEYRELEASE:
7412 key_joystick_mapping = 0;
7416 HandleOtherEvents(&event);
7424 // write new key bindings back to player setup, if successfully finished
7426 setup.input[player_nr].key = custom_key;
7431 void CustomizeKeyboard(int player_nr)
7433 boolean success = CustomizeKeyboardMain(player_nr);
7437 int font_nr = FONT_TITLE_1;
7438 int font_height = getFontHeight(font_nr);
7439 int ypos1 = SYSIZE / 2 - font_height * 2;
7440 int ypos2 = SYSIZE / 2 - font_height * 1;
7441 unsigned int wait_frame_delay = 0;
7442 unsigned int wait_frame_delay_value = 2000;
7444 ResetDelayCounter(&wait_frame_delay);
7448 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7449 DrawTextSCentered(ypos2, font_nr, "configured!");
7451 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7457 DrawSetupScreen_Input();
7460 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
7462 #define MARKER_BUTTON 1
7463 #define MARKER_AXIS_X 2
7464 #define MARKER_AXIS_Y 3
7466 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7468 static boolean bitmaps_initialized = FALSE;
7469 boolean screen_initialized = FALSE;
7470 static Bitmap *controller, *button, *axis_x, *axis_y;
7472 boolean success = TRUE;
7473 boolean done = FALSE, next = FALSE;
7475 int alpha = 200, alpha_step = -1;
7476 int alpha_ticks = 0;
7477 char mapping[4096], temp[4096];
7478 int font_name = MENU_SETUP_FONT_TITLE;
7479 int font_info = MENU_SETUP_FONT_TEXT;
7480 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7481 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7482 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7483 int ystep_name = getMenuTextStep(spacing_name, font_name);
7484 int ystep_line = getMenuTextStep(spacing_line, font_info);
7485 int ystep_para = getMenuTextStep(spacing_para, font_info);
7493 int axis, button, hat, hat_value;
7496 *step, *prev_step, steps[] =
7498 { 356, 155, MARKER_BUTTON, "a", },
7499 { 396, 122, MARKER_BUTTON, "b", },
7500 { 320, 125, MARKER_BUTTON, "x", },
7501 { 358, 95, MARKER_BUTTON, "y", },
7502 { 162, 125, MARKER_BUTTON, "back", },
7503 { 216, 125, MARKER_BUTTON, "guide", },
7504 { 271, 125, MARKER_BUTTON, "start", },
7505 { 110, 200, MARKER_BUTTON, "dpleft", },
7506 { 146, 228, MARKER_BUTTON, "dpdown", },
7507 { 178, 200, MARKER_BUTTON, "dpright", },
7508 { 146, 172, MARKER_BUTTON, "dpup", },
7509 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7510 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7511 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7512 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7513 { 73, 141, MARKER_BUTTON, "leftstick", },
7514 { 282, 210, MARKER_BUTTON, "rightstick", },
7515 { 73, 141, MARKER_AXIS_X, "leftx", },
7516 { 73, 141, MARKER_AXIS_Y, "lefty", },
7517 { 282, 210, MARKER_AXIS_X, "rightx", },
7518 { 282, 210, MARKER_AXIS_Y, "righty", },
7521 unsigned int event_frame_delay = 0;
7522 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7524 ResetDelayCounter(&event_frame_delay);
7526 if (!bitmaps_initialized)
7528 controller = LoadCustomImage("joystick/controller.png");
7529 button = LoadCustomImage("joystick/button.png");
7530 axis_x = LoadCustomImage("joystick/axis_x.png");
7531 axis_y = LoadCustomImage("joystick/axis_y.png");
7533 bitmaps_initialized = TRUE;
7536 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7539 // print info about the joystick we are watching
7540 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7541 SDL_JoystickInstanceID(joystick), name);
7542 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7543 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7544 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7547 // initialize mapping with GUID and name
7548 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7550 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7551 temp, name, SDL_GetPlatform());
7553 // loop through all steps (buttons and axes), getting joystick events
7554 for (i = 0; i < SDL_arraysize(steps) && !done;)
7556 Bitmap *marker = button; // initialize with reliable default value
7559 strcpy(step->mapping, mapping);
7563 step->hat_value = -1;
7565 marker = (step->marker == MARKER_BUTTON ? button :
7566 step->marker == MARKER_AXIS_X ? axis_x :
7567 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7571 while (!done && !next)
7573 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7574 alpha_ticks = SDL_GetTicks();
7581 else if (alpha < 128)
7587 int controller_x = SX + (SXSIZE - controller->width) / 2;
7588 int controller_y = SY + ystep_line;
7590 int marker_x = controller_x + step->x;
7591 int marker_y = controller_y + step->y;
7593 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7594 int ystart2 = ystart1 + ystep_name + ystep_line;
7598 DrawTextSCentered(ystart1, font_name, name);
7600 DrawTextSCentered(ystart2, font_info,
7601 "Press buttons and move axes on");
7602 ystart2 += ystep_line;
7603 DrawTextSCentered(ystart2, font_info,
7604 "your controller when indicated.");
7605 ystart2 += ystep_line;
7606 DrawTextSCentered(ystart2, font_info,
7607 "(Your controller may look different.)");
7608 ystart2 += ystep_para;
7610 #if defined(PLATFORM_ANDROID)
7611 DrawTextSCentered(ystart2, font_info,
7612 "To correct a mistake,");
7613 ystart2 += ystep_line;
7614 DrawTextSCentered(ystart2, font_info,
7615 "press the 'back' button.");
7616 ystart2 += ystep_line;
7617 DrawTextSCentered(ystart2, font_info,
7618 "To skip a button or axis,");
7619 ystart2 += ystep_line;
7620 DrawTextSCentered(ystart2, font_info,
7621 "press the 'menu' button.");
7623 DrawTextSCentered(ystart2, font_info,
7624 "To correct a mistake,");
7625 ystart2 += ystep_line;
7626 DrawTextSCentered(ystart2, font_info,
7627 "press the 'backspace' key.");
7628 ystart2 += ystep_line;
7629 DrawTextSCentered(ystart2, font_info,
7630 "To skip a button or axis,");
7631 ystart2 += ystep_line;
7632 DrawTextSCentered(ystart2, font_info,
7633 "press the 'return' key.");
7634 ystart2 += ystep_line;
7635 DrawTextSCentered(ystart2, font_info,
7636 "To exit, press the 'escape' key.");
7639 BlitBitmapMasked(controller, drawto, 0, 0,
7640 controller->width, controller->height,
7641 controller_x, controller_y);
7643 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7644 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7646 BlitBitmapMasked(marker, drawto, 0, 0,
7647 marker->width, marker->height,
7648 marker_x, marker_y);
7650 if (!screen_initialized)
7651 FadeIn(REDRAW_FIELD);
7655 screen_initialized = TRUE;
7657 while (NextValidEvent(&event))
7661 case SDL_JOYAXISMOTION:
7662 if (event.jaxis.value > 20000 ||
7663 event.jaxis.value < -20000)
7665 for (j = 0; j < i; j++)
7666 if (steps[j].axis == event.jaxis.axis)
7671 if (step->marker != MARKER_AXIS_X &&
7672 step->marker != MARKER_AXIS_Y)
7675 step->axis = event.jaxis.axis;
7676 strcat(mapping, step->field);
7677 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7678 strcat(mapping, temp);
7686 case SDL_JOYHATMOTION:
7687 // ignore centering; we're probably just coming back
7688 // to the center from the previous item we set
7689 if (event.jhat.value == SDL_HAT_CENTERED)
7692 for (j = 0; j < i; j++)
7693 if (steps[j].hat == event.jhat.hat &&
7694 steps[j].hat_value == event.jhat.value)
7699 step->hat = event.jhat.hat;
7700 step->hat_value = event.jhat.value;
7701 strcat(mapping, step->field);
7702 snprintf(temp, sizeof(temp), ":h%u.%u,",
7703 event.jhat.hat, event.jhat.value );
7704 strcat(mapping, temp);
7711 case SDL_JOYBALLMOTION:
7714 case SDL_JOYBUTTONUP:
7715 for (j = 0; j < i; j++)
7716 if (steps[j].button == event.jbutton.button)
7721 step->button = event.jbutton.button;
7722 strcat(mapping, step->field);
7723 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7724 strcat(mapping, temp);
7731 case SDL_FINGERDOWN:
7732 case SDL_MOUSEBUTTONDOWN:
7740 if (event.key.keysym.sym == KSYM_BackSpace ||
7741 event.key.keysym.sym == KSYM_Back)
7753 prev_step = &steps[i - 1];
7754 strcpy(mapping, prev_step->mapping);
7761 if (event.key.keysym.sym == KSYM_space ||
7762 event.key.keysym.sym == KSYM_Return ||
7763 event.key.keysym.sym == KSYM_Menu)
7772 if (event.key.keysym.sym == KSYM_Escape)
7782 program.exit_function(0);
7789 // do not handle events for longer than standard frame delay period
7790 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7799 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7802 // activate mapping for this game
7803 SDL_GameControllerAddMapping(mapping);
7805 // save mapping to personal mappings
7806 SaveSetup_AddGameControllerMapping(mapping);
7809 // wait until the last pending event was removed from event queue
7810 while (NextValidEvent(&event));
7815 static int ConfigureJoystickMain(int player_nr)
7817 char *device_name = setup.input[player_nr].joy.device_name;
7818 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7819 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7820 int success = FALSE;
7823 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7824 return JOYSTICK_NOT_AVAILABLE;
7826 if (!joystick_active || !setup.input[player_nr].use_joystick)
7827 return JOYSTICK_NOT_AVAILABLE;
7830 FadeOut(REDRAW_FIELD);
7832 // close all joystick devices (potentially opened as game controllers)
7833 for (i = 0; i < SDL_NumJoysticks(); i++)
7834 SDLCloseJoystick(i);
7836 // open joystick device as plain joystick to configure as game controller
7837 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7839 // as the joystick was successfully opened before, this should not happen
7840 if (joystick == NULL)
7843 // create new game controller mapping (buttons and axes) for joystick device
7844 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7846 // close joystick (and maybe re-open as configured game controller later)
7847 SDL_JoystickClose(joystick);
7849 // re-open all joystick devices (potentially as game controllers)
7850 for (i = 0; i < SDL_NumJoysticks(); i++)
7853 // clear all joystick input actions for all joystick devices
7854 SDLClearJoystickState();
7856 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7859 void ConfigureJoystick(int player_nr)
7861 boolean state = ConfigureJoystickMain(player_nr);
7863 if (state != JOYSTICK_NOT_CONFIGURED)
7865 boolean success = (state == JOYSTICK_CONFIGURED);
7866 char message1[MAX_OUTPUT_LINESIZE + 1];
7867 char *message2 = (success ? "configured!" : "not available!");
7868 char *device_name = setup.input[player_nr].joy.device_name;
7869 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7870 int font_nr = FONT_TITLE_1;
7871 int font_height = getFontHeight(font_nr);
7872 int ypos1 = SYSIZE / 2 - font_height * 2;
7873 int ypos2 = SYSIZE / 2 - font_height * 1;
7874 unsigned int wait_frame_delay = 0;
7875 unsigned int wait_frame_delay_value = 2000;
7877 ResetDelayCounter(&wait_frame_delay);
7881 sprintf(message1, "Joystick %d", nr);
7883 DrawTextSCentered(ypos1, font_nr, message1);
7884 DrawTextSCentered(ypos2, font_nr, message2);
7886 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7892 DrawSetupScreen_Input();
7895 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
7897 if (y < video.screen_height / 3)
7899 // remap touch gadgets to access upper part of the screen
7900 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7901 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
7903 else if (y > 2 * video.screen_height / 3)
7905 // remap touch gadgets to access lower part of the screen
7906 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7907 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
7911 static boolean ConfigureVirtualButtonsMain(void)
7913 static char *customize_step_text[] =
7922 char grid_button[] =
7924 CHAR_GRID_BUTTON_LEFT,
7925 CHAR_GRID_BUTTON_RIGHT,
7926 CHAR_GRID_BUTTON_UP,
7927 CHAR_GRID_BUTTON_DOWN,
7928 CHAR_GRID_BUTTON_SNAP,
7929 CHAR_GRID_BUTTON_DROP
7938 int font_nr = FONT_INPUT_1_ACTIVE;
7939 int font_height = getFontHeight(font_nr);
7940 int ypos1 = SYSIZE / 2 - font_height * 2;
7941 int ypos2 = SYSIZE / 2 - font_height * 1;
7942 boolean success = FALSE;
7943 boolean finished = FALSE;
7945 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7946 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7947 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7948 boolean set_grid_button = FALSE;
7949 int nr = GRID_ACTIVE_NR();
7952 for (x = 0; x < MAX_GRID_XSIZE; x++)
7953 for (y = 0; y < MAX_GRID_YSIZE; y++)
7954 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7956 overlay.grid_button_highlight = grid_button[step_nr];
7959 FadeOut(REDRAW_FIELD);
7963 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7964 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7965 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7967 FadeIn(REDRAW_FIELD);
7969 SetOverlayShowGrid(TRUE);
7971 // map gadgets for setup touch buttons menu screen
7972 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7978 while (NextValidEvent(&event))
7980 int action = ACTION_NONE;
7982 // ---------- handle events and set the resulting action ----------
7988 UserEvent *user = (UserEvent *)&event;
7989 int id = user->value1;
7991 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
7992 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
7993 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
7994 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
7999 case EVENT_KEYPRESS:
8001 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8003 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8004 key == KSYM_BackSpace ||
8005 key == KSYM_Back ? ACTION_BACK :
8006 key == KSYM_Return ||
8008 key == KSYM_space ? ACTION_NEXT :
8013 case EVENT_KEYRELEASE:
8014 key_joystick_mapping = 0;
8017 case EVENT_BUTTONPRESS:
8018 case EVENT_BUTTONRELEASE:
8020 ButtonEvent *button = (ButtonEvent *)&event;
8022 motion_status = FALSE;
8024 if (button->type == EVENT_BUTTONPRESS)
8025 button_status = button->button;
8027 button_status = MB_RELEASED;
8029 if (HandleGadgets(button->x, button->y, button_status))
8031 // do not handle this button event anymore
8035 button->x += video.screen_xoffset;
8036 button->y += video.screen_yoffset;
8038 x = button->x * overlay.grid_xsize / video.screen_width;
8039 y = button->y * overlay.grid_ysize / video.screen_height;
8041 if (button->type == EVENT_BUTTONPRESS)
8044 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8045 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8047 set_grid_button = TRUE;
8050 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8054 case EVENT_MOTIONNOTIFY:
8056 MotionEvent *motion = (MotionEvent *)&event;
8058 motion_status = TRUE;
8060 if (HandleGadgets(motion->x, motion->y, button_status))
8062 // do not handle this button event anymore
8066 motion->x += video.screen_xoffset;
8067 motion->y += video.screen_yoffset;
8069 x = motion->x * overlay.grid_xsize / video.screen_width;
8070 y = motion->y * overlay.grid_ysize / video.screen_height;
8072 set_grid_button = TRUE;
8074 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8078 case SDL_WINDOWEVENT:
8079 HandleWindowEvent((WindowEvent *) &event);
8081 // check if device has been rotated
8082 if (nr != GRID_ACTIVE_NR())
8084 nr = GRID_ACTIVE_NR();
8086 for (x = 0; x < MAX_GRID_XSIZE; x++)
8087 for (y = 0; y < MAX_GRID_YSIZE; y++)
8088 grid_button_old[x][y] = grid_button_tmp[x][y] =
8089 overlay.grid_button[x][y];
8094 case SDL_APP_WILLENTERBACKGROUND:
8095 case SDL_APP_DIDENTERBACKGROUND:
8096 case SDL_APP_WILLENTERFOREGROUND:
8097 case SDL_APP_DIDENTERFOREGROUND:
8098 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8102 HandleOtherEvents(&event);
8106 // ---------- perform action set by handling events ----------
8108 if (action == ACTION_ESCAPE)
8110 // abort and restore the old key bindings
8112 for (x = 0; x < MAX_GRID_XSIZE; x++)
8113 for (y = 0; y < MAX_GRID_YSIZE; y++)
8114 overlay.grid_button[x][y] = grid_button_old[x][y];
8116 FadeSkipNextFadeIn();
8120 else if (action == ACTION_BACK)
8122 // keep the configured key bindings and go to previous page
8128 FadeSkipNextFadeIn();
8133 else if (action == ACTION_NEXT)
8135 // keep the configured key bindings and go to next page
8139 // all virtual buttons configured
8147 if (action != ACTION_NONE && !finished)
8149 for (x = 0; x < MAX_GRID_XSIZE; x++)
8150 for (y = 0; y < MAX_GRID_YSIZE; y++)
8151 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8153 overlay.grid_button_highlight = grid_button[step_nr];
8155 // configure next virtual button
8159 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8160 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8161 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8164 if (set_grid_button)
8166 overlay.grid_button[x][y] =
8167 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8168 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8169 grid_button_tmp[x][y]);
8171 set_grid_button = FALSE;
8178 for (x = 0; x < MAX_GRID_XSIZE; x++)
8179 for (y = 0; y < MAX_GRID_YSIZE; y++)
8180 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8182 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8184 SetOverlayShowGrid(FALSE);
8189 void ConfigureVirtualButtons(void)
8191 boolean success = ConfigureVirtualButtonsMain();
8193 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8194 SCREEN_MASK_TOUCH2);
8198 int font_nr = FONT_TITLE_1;
8199 int font_height = getFontHeight(font_nr);
8200 int ypos1 = SYSIZE / 2 - font_height * 2;
8201 int ypos2 = SYSIZE / 2 - font_height * 1;
8202 unsigned int wait_frame_delay = 0;
8203 unsigned int wait_frame_delay_value = 2000;
8205 ResetDelayCounter(&wait_frame_delay);
8209 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8210 DrawTextSCentered(ypos2, font_nr, "configured!");
8212 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8219 void DrawSetupScreen(void)
8224 if (setup_mode == SETUP_MODE_INPUT)
8225 DrawSetupScreen_Input();
8226 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8227 DrawChooseTree(&game_speed_current);
8228 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8229 DrawChooseTree(&scroll_delay_current);
8230 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8231 DrawChooseTree(&snapshot_mode_current);
8232 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8233 DrawChooseTree(&window_size_current);
8234 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8235 DrawChooseTree(&scaling_type_current);
8236 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8237 DrawChooseTree(&rendering_mode_current);
8238 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8239 DrawChooseTree(&vsync_mode_current);
8240 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8241 DrawChooseTree(&artwork.gfx_current);
8242 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8243 DrawChooseTree(&artwork.snd_current);
8244 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8245 DrawChooseTree(&artwork.mus_current);
8246 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8247 DrawChooseTree(&volume_simple_current);
8248 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8249 DrawChooseTree(&volume_loops_current);
8250 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8251 DrawChooseTree(&volume_music_current);
8252 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8253 DrawChooseTree(&touch_control_current);
8254 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8255 DrawChooseTree(&move_distance_current);
8256 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8257 DrawChooseTree(&drop_distance_current);
8258 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8259 DrawChooseTree(&transparency_current);
8260 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8261 DrawChooseTree(&grid_size_current[0][0]);
8262 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8263 DrawChooseTree(&grid_size_current[0][1]);
8264 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8265 DrawChooseTree(&grid_size_current[1][0]);
8266 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8267 DrawChooseTree(&grid_size_current[1][1]);
8269 DrawSetupScreen_Generic();
8271 PlayMenuSoundsAndMusic();
8274 void RedrawSetupScreenAfterFullscreenToggle(void)
8276 if (setup_mode == SETUP_MODE_GRAPHICS ||
8277 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8279 // update list selection from "setup.window_scaling_percent"
8280 execSetupGraphics_setWindowSizes(TRUE);
8286 void RedrawSetupScreenAfterScreenRotation(int nr)
8290 if (setup_mode == SETUP_MODE_TOUCH)
8292 // update virtual button settings (depending on screen orientation)
8295 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8297 // save already configured virtual buttons
8298 for (x = 0; x < MAX_GRID_XSIZE; x++)
8299 for (y = 0; y < MAX_GRID_YSIZE; y++)
8300 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8304 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8306 if (setup_mode == SETUP_MODE_INPUT)
8307 HandleSetupScreen_Input(mx, my, dx, dy, button);
8308 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8309 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8310 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8311 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8312 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8313 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8314 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8315 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8316 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8317 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8318 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8319 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8320 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8321 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8322 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8323 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8324 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8325 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8326 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8327 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8328 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8329 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8330 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8331 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8332 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8333 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8334 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8335 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8336 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8337 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8338 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8339 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8340 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8341 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8342 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8343 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8344 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8345 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8346 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8347 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8348 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8349 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8351 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8354 void HandleGameActions(void)
8356 if (setup.ask_on_game_over)
8359 if (game.restart_game_message != NULL)
8361 RequestRestartGame(game.restart_game_message);
8366 if (game_status != GAME_MODE_PLAYING)
8369 GameActions(); // main game loop
8371 if (tape.auto_play && !tape.playing)
8372 AutoPlayTape(); // continue automatically playing next tape
8376 // ---------- new screen button stuff --------------------------------------
8380 int gfx_unpressed, gfx_pressed;
8381 struct MenuPosInfo *pos;
8384 unsigned int event_mask;
8385 boolean is_touch_button;
8387 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8390 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8391 &menu.main.button.prev_level,
8392 SCREEN_CTRL_ID_PREV_LEVEL,
8394 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8395 FALSE, "previous level"
8398 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8399 &menu.main.button.next_level,
8400 SCREEN_CTRL_ID_NEXT_LEVEL,
8402 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8406 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
8407 &menu.main.button.first_level,
8408 SCREEN_CTRL_ID_FIRST_LEVEL,
8411 FALSE, "first level"
8414 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
8415 &menu.main.button.last_level,
8416 SCREEN_CTRL_ID_LAST_LEVEL,
8422 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
8423 &menu.main.button.level_number,
8424 SCREEN_CTRL_ID_LEVEL_NUMBER,
8427 FALSE, "level number"
8430 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8431 &menu.setup.button.prev_player,
8432 SCREEN_CTRL_ID_PREV_PLAYER,
8434 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8435 FALSE, "previous player"
8438 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8439 &menu.setup.button.next_player,
8440 SCREEN_CTRL_ID_NEXT_PLAYER,
8442 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8443 FALSE, "next player"
8446 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8447 &menu.main.button.insert_solution,
8448 SCREEN_CTRL_ID_INSERT_SOLUTION,
8449 SCREEN_MASK_MAIN_HAS_SOLUTION,
8451 FALSE, "insert solution tape"
8454 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8455 &menu.main.button.play_solution,
8456 SCREEN_CTRL_ID_PLAY_SOLUTION,
8457 SCREEN_MASK_MAIN_HAS_SOLUTION,
8459 FALSE, "play solution tape"
8462 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
8463 &menu.setup.button.touch_back,
8464 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
8467 TRUE, "previous page"
8470 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
8471 &menu.setup.button.touch_next,
8472 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
8478 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
8479 &menu.setup.button.touch_back2,
8480 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
8483 TRUE, "previous page"
8486 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
8487 &menu.setup.button.touch_next2,
8488 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
8497 int gfx_unpressed, gfx_pressed;
8501 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8504 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8505 -1, -1, // these values are not constant, but can change at runtime
8506 SCREEN_CTRL_ID_SCROLL_UP,
8510 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8511 -1, -1, // these values are not constant, but can change at runtime
8512 SCREEN_CTRL_ID_SCROLL_DOWN,
8519 int gfx_unpressed, gfx_pressed;
8525 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8528 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8529 -1, -1, // these values are not constant, but can change at runtime
8530 -1, -1, // these values are not constant, but can change at runtime
8531 GD_TYPE_SCROLLBAR_VERTICAL,
8532 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8533 "scroll level series vertically"
8545 } textinput_info[NUM_SCREEN_TEXTINPUT] =
8548 IMG_SETUP_INPUT_TEXT,
8549 SCREEN_CTRL_ID_NETWORK_SERVER,
8550 -1, -1, // these values are not constant, but can change at runtime
8551 MAX_SETUP_TEXT_INPUT_LEN,
8552 network_server_hostname,
8553 "Network Server Hostname / IP"
8557 static void CreateScreenMenubuttons(void)
8559 struct GadgetInfo *gi;
8560 unsigned int event_mask;
8563 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8565 struct MenuPosInfo *pos = menubutton_info[i].pos;
8566 boolean is_touch_button = menubutton_info[i].is_touch_button;
8567 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8568 int gfx_unpressed, gfx_pressed;
8569 int x, y, width, height;
8570 int gd_x1, gd_x2, gd_y1, gd_y2;
8571 int id = menubutton_info[i].gadget_id;
8573 event_mask = menubutton_info[i].event_mask;
8575 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
8576 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
8578 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8579 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8581 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8582 gfx_pressed = menubutton_info[i].gfx_pressed;
8583 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8584 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8585 gd_x1 = graphic_info[gfx_unpressed].src_x;
8586 gd_y1 = graphic_info[gfx_unpressed].src_y;
8587 gd_x2 = graphic_info[gfx_pressed].src_x;
8588 gd_y2 = graphic_info[gfx_pressed].src_y;
8590 if (is_touch_button)
8592 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
8593 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
8596 gi = CreateGadget(GDI_CUSTOM_ID, id,
8597 GDI_CUSTOM_TYPE_ID, i,
8598 GDI_IMAGE_ID, gfx_unpressed,
8599 GDI_INFO_TEXT, menubutton_info[i].infotext,
8604 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8605 GDI_STATE, GD_BUTTON_UNPRESSED,
8606 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8607 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8608 GDI_DIRECT_DRAW, FALSE,
8609 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
8610 GDI_EVENT_MASK, event_mask,
8611 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8615 Error(ERR_EXIT, "cannot create gadget");
8617 screen_gadget[id] = gi;
8621 static void CreateScreenScrollbuttons(void)
8623 struct GadgetInfo *gi;
8624 unsigned int event_mask;
8627 // these values are not constant, but can change at runtime
8628 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8629 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8630 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8631 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8633 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8635 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8636 int gfx_unpressed, gfx_pressed;
8637 int x, y, width, height;
8638 int gd_x1, gd_x2, gd_y1, gd_y2;
8639 int id = scrollbutton_info[i].gadget_id;
8641 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8643 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8644 y = mSY + scrollbutton_info[i].y;
8645 width = SC_SCROLLBUTTON_XSIZE;
8646 height = SC_SCROLLBUTTON_YSIZE;
8648 // correct scrollbar position if placed outside menu (playfield) area
8649 if (x > SX + SC_SCROLL_UP_XPOS)
8650 x = SX + SC_SCROLL_UP_XPOS;
8652 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8653 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8654 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8656 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8657 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8658 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8659 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8660 gd_x1 = graphic_info[gfx_unpressed].src_x;
8661 gd_y1 = graphic_info[gfx_unpressed].src_y;
8662 gd_x2 = graphic_info[gfx_pressed].src_x;
8663 gd_y2 = graphic_info[gfx_pressed].src_y;
8665 gi = CreateGadget(GDI_CUSTOM_ID, id,
8666 GDI_CUSTOM_TYPE_ID, i,
8667 GDI_IMAGE_ID, gfx_unpressed,
8668 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8673 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8674 GDI_STATE, GD_BUTTON_UNPRESSED,
8675 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8676 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8677 GDI_DIRECT_DRAW, FALSE,
8678 GDI_EVENT_MASK, event_mask,
8679 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8683 Error(ERR_EXIT, "cannot create gadget");
8685 screen_gadget[id] = gi;
8689 static void CreateScreenScrollbars(void)
8693 // these values are not constant, but can change at runtime
8694 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8695 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8696 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8697 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8699 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8701 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8702 int gfx_unpressed, gfx_pressed;
8703 int x, y, width, height;
8704 int gd_x1, gd_x2, gd_y1, gd_y2;
8705 struct GadgetInfo *gi;
8706 int items_max, items_visible, item_position;
8707 unsigned int event_mask;
8708 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8709 int id = scrollbar_info[i].gadget_id;
8711 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8713 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8714 y = mSY + scrollbar_info[i].y;
8715 width = scrollbar_info[i].width;
8716 height = scrollbar_info[i].height;
8718 // correct scrollbar position if placed outside menu (playfield) area
8719 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8720 x = SX + SC_SCROLL_VERTICAL_XPOS;
8722 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8723 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8725 items_max = num_page_entries;
8726 items_visible = num_page_entries;
8729 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8730 gfx_pressed = scrollbar_info[i].gfx_pressed;
8731 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8732 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8733 gd_x1 = graphic_info[gfx_unpressed].src_x;
8734 gd_y1 = graphic_info[gfx_unpressed].src_y;
8735 gd_x2 = graphic_info[gfx_pressed].src_x;
8736 gd_y2 = graphic_info[gfx_pressed].src_y;
8738 gi = CreateGadget(GDI_CUSTOM_ID, id,
8739 GDI_CUSTOM_TYPE_ID, i,
8740 GDI_IMAGE_ID, gfx_unpressed,
8741 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8746 GDI_TYPE, scrollbar_info[i].type,
8747 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8748 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8749 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8750 GDI_WHEEL_AREA_X, SX,
8751 GDI_WHEEL_AREA_Y, SY,
8752 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8753 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8754 GDI_STATE, GD_BUTTON_UNPRESSED,
8755 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8756 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8757 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8758 GDI_DIRECT_DRAW, FALSE,
8759 GDI_EVENT_MASK, event_mask,
8760 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8764 Error(ERR_EXIT, "cannot create gadget");
8766 screen_gadget[id] = gi;
8770 static void CreateScreenTextInputGadgets(void)
8774 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
8776 int graphic = textinput_info[i].graphic;
8777 struct GraphicInfo *gd = &graphic_info[graphic];
8778 int gd_x1 = gd->src_x;
8779 int gd_y1 = gd->src_y;
8780 int gd_x2 = gd->src_x + gd->active_xoffset;
8781 int gd_y2 = gd->src_y + gd->active_yoffset;
8782 struct GadgetInfo *gi;
8783 unsigned int event_mask;
8784 int id = textinput_info[i].gadget_id;
8785 int x = textinput_info[i].x;
8786 int y = textinput_info[i].y;
8788 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
8790 gi = CreateGadget(GDI_CUSTOM_ID, id,
8791 GDI_CUSTOM_TYPE_ID, i,
8792 GDI_INFO_TEXT, textinput_info[i].infotext,
8795 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
8796 GDI_TEXT_VALUE, textinput_info[i].value,
8797 GDI_TEXT_SIZE, textinput_info[i].size,
8798 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
8799 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
8800 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8801 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8802 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8803 GDI_DESIGN_WIDTH, gd->width,
8804 GDI_EVENT_MASK, event_mask,
8805 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8806 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
8810 Error(ERR_EXIT, "cannot create gadget");
8812 screen_gadget[id] = gi;
8816 void CreateScreenGadgets(void)
8818 CreateScreenMenubuttons();
8820 CreateScreenScrollbuttons();
8821 CreateScreenScrollbars();
8823 CreateScreenTextInputGadgets();
8826 void FreeScreenGadgets(void)
8830 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8831 FreeGadget(screen_gadget[i]);
8834 static void MapScreenMenuGadgets(int screen_mask)
8838 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8839 if (screen_mask & menubutton_info[i].screen_mask)
8840 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8843 static void UnmapScreenMenuGadgets(int screen_mask)
8847 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8849 if (screen_mask & menubutton_info[i].screen_mask)
8851 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8853 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8854 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8855 screen_gadget[menubutton_info[i].gadget_id]->y,
8856 screen_gadget[menubutton_info[i].gadget_id]->width,
8857 screen_gadget[menubutton_info[i].gadget_id]->height);
8862 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8865 MapScreenMenuGadgets(screen_mask);
8867 UnmapScreenMenuGadgets(screen_mask);
8870 static void MapScreenGadgets(int num_entries)
8874 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8877 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8878 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8880 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8881 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8884 static void MapScreenTreeGadgets(TreeInfo *ti)
8886 MapScreenGadgets(numTreeInfoInGroup(ti));
8889 static void HandleScreenGadgets(struct GadgetInfo *gi)
8891 int id = gi->custom_id;
8892 int button = gi->event.button;
8893 int step = (button == MB_LEFTBUTTON ? 1 :
8894 button == MB_MIDDLEBUTTON ? 5 :
8895 button == MB_RIGHTBUTTON ? 10 : 1);
8899 case SCREEN_CTRL_ID_PREV_LEVEL:
8900 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8903 case SCREEN_CTRL_ID_NEXT_LEVEL:
8904 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8907 case SCREEN_CTRL_ID_FIRST_LEVEL:
8908 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
8911 case SCREEN_CTRL_ID_LAST_LEVEL:
8912 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
8915 case SCREEN_CTRL_ID_LEVEL_NUMBER:
8916 CloseDoor(DOOR_CLOSE_2);
8917 SetGameStatus(GAME_MODE_LEVELNR);
8918 DrawChooseLevelNr();
8921 case SCREEN_CTRL_ID_PREV_PLAYER:
8922 HandleSetupScreen_Input_Player(step, -1);
8925 case SCREEN_CTRL_ID_NEXT_PLAYER:
8926 HandleSetupScreen_Input_Player(step, +1);
8929 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8930 InsertSolutionTape();
8933 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8937 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
8938 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
8939 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
8940 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
8941 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
8944 case SCREEN_CTRL_ID_SCROLL_UP:
8945 if (game_status == GAME_MODE_LEVELS)
8946 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8947 else if (game_status == GAME_MODE_LEVELNR)
8948 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8949 else if (game_status == GAME_MODE_SETUP)
8950 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8951 else if (game_status == GAME_MODE_INFO)
8952 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8955 case SCREEN_CTRL_ID_SCROLL_DOWN:
8956 if (game_status == GAME_MODE_LEVELS)
8957 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8958 else if (game_status == GAME_MODE_LEVELNR)
8959 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8960 else if (game_status == GAME_MODE_SETUP)
8961 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8962 else if (game_status == GAME_MODE_INFO)
8963 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8966 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8967 if (game_status == GAME_MODE_LEVELS)
8968 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8969 else if (game_status == GAME_MODE_LEVELNR)
8970 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8971 else if (game_status == GAME_MODE_SETUP)
8972 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8973 else if (game_status == GAME_MODE_INFO)
8974 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8977 case SCREEN_CTRL_ID_NETWORK_SERVER:
8979 if (!strEqual(gi->textinput.value, ""))
8981 setString(&setup.network_server_hostname, gi->textinput.value);
8983 network.server_host = setup.network_server_hostname;
8987 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
8989 network.server_host = NULL;
8992 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
8993 network.server_host = NULL;
8995 execSetupGame_setNetworkServerText();
9007 void DumpScreenIdentifiers(void)
9011 Print("Active screen elements on current screen:\n");
9013 for (i = 0; main_controls[i].nr != -1; i++)
9015 struct MainControlInfo *mci = &main_controls[i];
9017 if (mci->button_graphic != -1)
9019 char *token = getTokenFromImageID(mci->button_graphic);
9021 Print("- '%s'\n", token);
9028 boolean DoScreenAction(int image_id)
9032 if (game_status != GAME_MODE_MAIN)
9035 for (i = 0; main_controls[i].nr != -1; i++)
9037 struct MainControlInfo *mci = &main_controls[i];
9038 struct MenuPosInfo *pos = mci->pos_button;
9040 if (mci->button_graphic == image_id)
9042 int x = mSX + pos->x;
9043 int y = mSY + pos->y;
9045 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9054 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9056 // get tree info node of newly added level or artwork set
9057 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9058 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9060 if (tree_node_new == NULL) // should not happen
9063 // if request dialog is active, do nothing
9064 if (game.request_active)
9067 if (game_status == GAME_MODE_MAIN &&
9068 tree_type == TREE_TYPE_LEVEL_DIR)
9070 // when adding new level set in main menu, select it as current level set
9072 // change current level set to newly added level set from zip file
9073 leveldir_current = tree_node_new;
9075 // change current level number to first level of newly added level set
9076 level_nr = leveldir_current->first_level;
9078 // redraw screen to reflect changed level set
9081 // save this level set and level number as last selected level set
9082 SaveLevelSetup_LastSeries();
9083 SaveLevelSetup_SeriesInfo();
9085 else if (game_status == GAME_MODE_LEVELS &&
9086 tree_type == TREE_TYPE_LEVEL_DIR)
9088 // when adding new level set in level set menu, set cursor and update screen
9090 leveldir_current = tree_node_new;
9092 DrawChooseTree(&leveldir_current);
9094 else if (game_status == GAME_MODE_SETUP)
9096 // when adding new artwork set in setup menu, set cursor and update screen
9098 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9099 tree_type == TREE_TYPE_GRAPHICS_DIR)
9101 artwork.gfx_current = tree_node_new;
9103 DrawChooseTree(&artwork.gfx_current);
9105 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9106 tree_type == TREE_TYPE_SOUNDS_DIR)
9108 artwork.snd_current = tree_node_new;
9110 DrawChooseTree(&artwork.snd_current);
9112 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9113 tree_type == TREE_TYPE_MUSIC_DIR)
9115 artwork.mus_current = tree_node_new;
9117 DrawChooseTree(&artwork.mus_current);