1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
27 #define DEBUG_JOYSTICKS 0
30 // screens on the info screen
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 // screens on the setup screen
43 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
44 // (should also match corresponding entries in src/conf_gfx.c)
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_ENGINES 2
48 #define SETUP_MODE_EDITOR 3
49 #define SETUP_MODE_GRAPHICS 4
50 #define SETUP_MODE_SOUND 5
51 #define SETUP_MODE_ARTWORK 6
52 #define SETUP_MODE_INPUT 7
53 #define SETUP_MODE_TOUCH 8
54 #define SETUP_MODE_SHORTCUTS 9
55 #define SETUP_MODE_SHORTCUTS_1 10
56 #define SETUP_MODE_SHORTCUTS_2 11
57 #define SETUP_MODE_SHORTCUTS_3 12
58 #define SETUP_MODE_SHORTCUTS_4 13
59 #define SETUP_MODE_SHORTCUTS_5 14
61 // sub-screens on the setup screen (generic)
62 #define SETUP_MODE_CHOOSE_ARTWORK 15
63 #define SETUP_MODE_CHOOSE_OTHER 16
65 // sub-screens on the setup screen (specific)
66 #define SETUP_MODE_CHOOSE_GAME_SPEED 17
67 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 18
68 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 19
69 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 20
70 #define SETUP_MODE_CHOOSE_SCALING_TYPE 21
71 #define SETUP_MODE_CHOOSE_RENDERING 22
72 #define SETUP_MODE_CHOOSE_VSYNC 23
73 #define SETUP_MODE_CHOOSE_GRAPHICS 24
74 #define SETUP_MODE_CHOOSE_SOUNDS 25
75 #define SETUP_MODE_CHOOSE_MUSIC 26
76 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 27
77 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 28
78 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 29
79 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 30
80 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 31
81 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_TRANSPARENCY 33
83 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 34
84 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 36
86 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 37
87 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 38
89 #define MAX_SETUP_MODES 39
91 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
93 // setup screen titles
94 #define STR_SETUP_MAIN "Setup"
95 #define STR_SETUP_GAME "Game & Menu"
96 #define STR_SETUP_ENGINES "Game Engines"
97 #define STR_SETUP_EDITOR "Editor"
98 #define STR_SETUP_GRAPHICS "Graphics"
99 #define STR_SETUP_SOUND "Sound & Music"
100 #define STR_SETUP_ARTWORK "Custom Artwork"
101 #define STR_SETUP_INPUT "Input Devices"
102 #define STR_SETUP_TOUCH "Touch Controls"
103 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
104 #define STR_SETUP_EXIT "Exit"
105 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
107 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
108 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
109 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
110 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
111 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
112 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
113 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
114 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
115 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
116 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
117 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
118 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
119 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
120 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
121 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
122 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
126 // other screen text constants
127 #define STR_CHOOSE_TREE_EDIT "Edit"
128 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
129 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
131 // for input setup functions
132 #define SETUPINPUT_SCREEN_POS_START 0
133 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
134 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
135 #define SETUPINPUT_SCREEN_POS_END 13
137 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
138 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
140 #define MAX_SETUP_TEXT_INPUT_LEN 28
142 // for various menu stuff
143 #define MENU_SCREEN_START_XPOS 1
144 #define MENU_SCREEN_START_YPOS 2
145 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
146 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
147 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
148 #define MENU_TITLE1_YPOS 8
149 #define MENU_TITLE2_YPOS 46
150 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
151 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
152 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
153 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
154 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
155 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
156 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
159 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
160 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
161 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
162 MENU_INFO_FONT_TITLE))
163 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
164 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
165 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
166 MENU_SCREEN_INFO_YSTART2 - \
168 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
169 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
170 MENU_SCREEN_INFO_YSTEP)
171 #define NUM_INFO_ELEMENTS_FROM_CONF \
172 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
173 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
174 MAX_MENU_ENTRIES_ON_SCREEN)
175 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
176 MAX_INFO_ELEMENTS_ON_SCREEN), \
177 NUM_INFO_ELEMENTS_FROM_CONF)
178 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
179 #define MAX_MENU_TEXT_LENGTH_BIG 13
180 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
182 // screen gadget identifiers
183 #define SCREEN_CTRL_ID_PREV_LEVEL 0
184 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
185 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
186 #define SCREEN_CTRL_ID_LAST_LEVEL 3
187 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
188 #define SCREEN_CTRL_ID_PREV_PLAYER 5
189 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
190 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
191 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
192 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
193 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
194 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
195 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
196 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
197 #define SCREEN_CTRL_ID_SCROLL_UP 14
198 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
199 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
200 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
202 #define NUM_SCREEN_GADGETS 18
204 #define NUM_SCREEN_MENUBUTTONS 14
205 #define NUM_SCREEN_SCROLLBUTTONS 2
206 #define NUM_SCREEN_SCROLLBARS 1
207 #define NUM_SCREEN_TEXTINPUT 1
209 #define SCREEN_MASK_MAIN (1 << 0)
210 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
211 #define SCREEN_MASK_INPUT (1 << 2)
212 #define SCREEN_MASK_TOUCH (1 << 3)
213 #define SCREEN_MASK_TOUCH2 (1 << 4)
215 // graphic position and size values for buttons and scrollbars
216 #define SC_MENUBUTTON_XSIZE TILEX
217 #define SC_MENUBUTTON_YSIZE TILEY
219 #define SC_SCROLLBUTTON_XSIZE TILEX
220 #define SC_SCROLLBUTTON_YSIZE TILEY
222 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
224 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
225 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
226 SC_SCROLLBUTTON_YSIZE)
228 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
229 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
231 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
232 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
233 SC_SCROLLBUTTON_YSIZE)
235 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
236 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
237 SC_SCROLL_VERTICAL_YSIZE)
239 #define SC_BORDER_SIZE 14
242 // forward declarations of internal functions
243 static void HandleScreenGadgets(struct GadgetInfo *);
244 static void HandleSetupScreen_Generic(int, int, int, int, int);
245 static void HandleSetupScreen_Input(int, int, int, int, int);
246 static void CustomizeKeyboard(int);
247 static void ConfigureJoystick(int);
248 static void ConfigureVirtualButtons(void);
249 static void execSetupGame(void);
250 static void execSetupEngines(void);
251 static void execSetupGraphics(void);
252 static void execSetupSound(void);
253 static void execSetupTouch(void);
254 static void execSetupArtwork(void);
255 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
257 static void DrawChoosePlayerName(void);
258 static void DrawChooseLevelSet(void);
259 static void DrawChooseLevelNr(void);
260 static void DrawInfoScreen(void);
261 static void DrawSetupScreen(void);
262 static void DrawTypeName(void);
264 static void DrawInfoScreen_NotAvailable(char *, char *);
265 static void DrawInfoScreen_HelpAnim(int, int, boolean);
266 static void DrawInfoScreen_HelpText(int, int, int, int);
267 static void HandleInfoScreen_Main(int, int, int, int, int);
268 static void HandleInfoScreen_TitleScreen(int);
269 static void HandleInfoScreen_Elements(int);
270 static void HandleInfoScreen_Music(int);
271 static void HandleInfoScreen_Credits(int);
272 static void HandleInfoScreen_Program(int);
273 static void HandleInfoScreen_Version(int);
275 static void ModifyGameSpeedIfNeeded(void);
276 static void DisableVsyncIfNeeded(void);
278 static void MapScreenMenuGadgets(int);
279 static void UnmapScreenMenuGadgets(int);
280 static void MapScreenGadgets(int);
281 static void MapScreenTreeGadgets(TreeInfo *);
283 static void UpdateScreenMenuGadgets(int, boolean);
285 static boolean OfferUploadTapes(void);
286 static void execOfferUploadTapes(void);
288 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
290 static int info_mode = INFO_MODE_MAIN;
291 static int setup_mode = SETUP_MODE_MAIN;
293 static TreeInfo *window_sizes = NULL;
294 static TreeInfo *window_size_current = NULL;
296 static TreeInfo *scaling_types = NULL;
297 static TreeInfo *scaling_type_current = NULL;
299 static TreeInfo *rendering_modes = NULL;
300 static TreeInfo *rendering_mode_current = NULL;
302 static TreeInfo *vsync_modes = NULL;
303 static TreeInfo *vsync_mode_current = NULL;
305 static TreeInfo *scroll_delays = NULL;
306 static TreeInfo *scroll_delay_current = NULL;
308 static TreeInfo *snapshot_modes = NULL;
309 static TreeInfo *snapshot_mode_current = NULL;
311 static TreeInfo *game_speeds_normal = NULL;
312 static TreeInfo *game_speeds_extended = NULL;
313 static TreeInfo *game_speeds = NULL;
314 static TreeInfo *game_speed_current = NULL;
316 static TreeInfo *volumes_simple = NULL;
317 static TreeInfo *volume_simple_current = NULL;
319 static TreeInfo *volumes_loops = NULL;
320 static TreeInfo *volume_loops_current = NULL;
322 static TreeInfo *volumes_music = NULL;
323 static TreeInfo *volume_music_current = NULL;
325 static TreeInfo *touch_controls = NULL;
326 static TreeInfo *touch_control_current = NULL;
328 static TreeInfo *move_distances = NULL;
329 static TreeInfo *move_distance_current = NULL;
331 static TreeInfo *drop_distances = NULL;
332 static TreeInfo *drop_distance_current = NULL;
334 static TreeInfo *transparencies = NULL;
335 static TreeInfo *transparency_current = NULL;
337 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
338 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
340 static TreeInfo *player_name = NULL;
341 static TreeInfo *player_name_current = NULL;
343 static TreeInfo *level_number = NULL;
344 static TreeInfo *level_number_current = NULL;
346 static struct ValueTextInfo window_sizes_list[] =
351 { 100, "100 % (Default)" },
364 static struct StringValueTextInfo scaling_types_list[] =
366 { SCALING_QUALITY_NEAREST, "Off" },
367 { SCALING_QUALITY_LINEAR, "Linear" },
368 { SCALING_QUALITY_BEST, "Anisotropic" },
373 static struct StringValueTextInfo rendering_modes_list[] =
375 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
376 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
378 // this mode may work under certain conditions, but does not work on Windows
379 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
381 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
386 static struct StringValueTextInfo vsync_modes_list[] =
388 { STR_VSYNC_MODE_OFF, "Off" },
389 { STR_VSYNC_MODE_NORMAL, "Normal" },
390 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
395 static struct ValueTextInfo game_speeds_list_normal[] =
406 static struct ValueTextInfo game_speeds_list_extended[] =
408 { 1000, "1 fps (Extremely Slow)" },
413 { 29, "35 fps (Original Supaplex)" },
415 { 20, "50 fps (=== Normal Speed ===)" },
416 { 16, "60 fps (60 Hz VSync Speed)" },
417 { 14, "70 fps (Maximum Supaplex)" },
421 { 1, "1000 fps (Extremely Fast)" },
426 static struct ValueTextInfo *game_speeds_list;
428 static struct ValueTextInfo scroll_delays_list[] =
430 { 0, "0 Tiles (No Scroll Delay)" },
433 { 3, "3 Tiles (Default)" },
438 { 8, "8 Tiles (Maximum Scroll Delay)"},
443 static struct StringValueTextInfo snapshot_modes_list[] =
445 { STR_SNAPSHOT_MODE_OFF, "Off" },
446 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
447 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
448 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
453 static struct ValueTextInfo volumes_list[] =
473 static struct StringValueTextInfo touch_controls_list[] =
475 { TOUCH_CONTROL_OFF, "Off" },
476 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
477 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
478 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
483 static struct ValueTextInfo distances_list[] =
498 static struct ValueTextInfo transparencies_list[] =
500 { 0, "0 % (Opaque)" },
510 { 100, "100 % (Invisible)" },
515 static struct ValueTextInfo grid_sizes_list[] =
551 static int align_xoffset = 0;
552 static int align_yoffset = 0;
554 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
555 (s) <= GAME_MODE_SETUP ? (s) : \
556 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
558 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
559 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
561 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
562 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
563 (i) <= INFO_MODE_LEVELSET ? (i) : \
566 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
567 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
568 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
569 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
570 SETUP_MODE_CHOOSE_ARTWORK : \
571 SETUP_MODE_CHOOSE_OTHER)
573 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
574 menu.draw_xoffset[GAME_MODE_INFO] : \
575 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
576 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
577 menu.draw_yoffset[GAME_MODE_INFO] : \
578 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
579 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
580 menu.extra_spacing[GAME_MODE_INFO] : \
581 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
583 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
584 menu.draw_xoffset[GAME_MODE_SETUP] : \
585 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
586 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
587 menu.draw_yoffset[GAME_MODE_SETUP] : \
588 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
589 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
590 menu.extra_spacing[GAME_MODE_SETUP] : \
591 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
593 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
594 DRAW_XOFFSET_INFO(info_mode) : \
595 (s) == GAME_MODE_SETUP ? \
596 DRAW_XOFFSET_SETUP(setup_mode) : \
597 menu.draw_xoffset[DRAW_MODE(s)])
598 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
599 DRAW_YOFFSET_INFO(info_mode) : \
600 (s) == GAME_MODE_SETUP ? \
601 DRAW_YOFFSET_SETUP(setup_mode) : \
602 menu.draw_yoffset[DRAW_MODE(s)])
603 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
604 EXTRA_SPACING_INFO(info_mode) : \
605 (s) == GAME_MODE_SETUP ? \
606 EXTRA_SPACING_SETUP(setup_mode) : \
607 menu.extra_spacing[DRAW_MODE(s)])
609 #define mSX (SX + DRAW_XOFFSET(game_status))
610 #define mSY (SY + DRAW_YOFFSET(game_status))
612 #define amSX (mSX + align_xoffset)
613 #define amSY (mSY + align_yoffset)
615 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
616 menu.list_size[game_status] : \
617 MAX_MENU_ENTRIES_ON_SCREEN)
619 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
620 NUM_MENU_ENTRIES_ON_SCREEN)
623 // title display and control definitions
625 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
626 2 * MAX_NUM_TITLE_MESSAGES)
628 #define NO_DIRECT_LEVEL_SELECT (-1)
631 static int num_title_screens = 0;
633 struct TitleControlInfo
642 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
644 // main menu display and control definitions
646 #define MAIN_CONTROL_NAME 0
647 #define MAIN_CONTROL_LEVELS 1
648 #define MAIN_CONTROL_SCORES 2
649 #define MAIN_CONTROL_EDITOR 3
650 #define MAIN_CONTROL_INFO 4
651 #define MAIN_CONTROL_GAME 5
652 #define MAIN_CONTROL_SETUP 6
653 #define MAIN_CONTROL_QUIT 7
654 #define MAIN_CONTROL_PREV_LEVEL 8
655 #define MAIN_CONTROL_NEXT_LEVEL 9
656 #define MAIN_CONTROL_FIRST_LEVEL 10
657 #define MAIN_CONTROL_LAST_LEVEL 11
658 #define MAIN_CONTROL_LEVEL_NUMBER 12
659 #define MAIN_CONTROL_LEVEL_INFO_1 13
660 #define MAIN_CONTROL_LEVEL_INFO_2 14
661 #define MAIN_CONTROL_LEVEL_NAME 15
662 #define MAIN_CONTROL_LEVEL_AUTHOR 16
663 #define MAIN_CONTROL_LEVEL_YEAR 17
664 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
665 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
666 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
667 #define MAIN_CONTROL_TITLE_1 21
668 #define MAIN_CONTROL_TITLE_2 22
669 #define MAIN_CONTROL_TITLE_3 23
671 static char str_main_text_name[10];
672 static char str_main_text_first_level[10];
673 static char str_main_text_last_level[10];
674 static char str_main_text_level_number[10];
676 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
678 static char *main_text_name = str_main_text_name;
679 static char *main_text_first_level = str_main_text_first_level;
680 static char *main_text_last_level = str_main_text_last_level;
681 static char *main_text_level_number = str_main_text_level_number;
682 static char *main_text_levels = "Levelset";
683 static char *main_text_scores = "Hall Of Fame";
684 static char *main_text_editor = "Level Creator";
685 static char *main_text_info = "Info Screen";
686 static char *main_text_game = "Start Game";
687 static char *main_text_setup = "Setup";
688 static char *main_text_quit = "Quit";
689 static char *main_text_level_name = level.name;
690 static char *main_text_level_author = level.author;
691 static char *main_text_level_year = NULL;
692 static char *main_text_level_imported_from = NULL;
693 static char *main_text_level_imported_by = NULL;
694 static char *main_text_level_tested_by = NULL;
695 static char *main_text_title_1 = NULL;
696 static char *main_text_title_2 = NULL;
697 static char *main_text_title_3 = NULL;
699 extern char debug_xsn_mode[];
701 struct MainControlInfo
705 struct MenuPosInfo *pos_button;
708 struct TextPosInfo *pos_text;
711 struct TextPosInfo *pos_input;
715 static struct MainControlInfo main_controls[] =
719 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
720 &menu.main.text.name, &main_text_name,
721 &menu.main.input.name, &setup.player_name,
725 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
726 &menu.main.text.levels, &main_text_levels,
731 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
732 &menu.main.text.scores, &main_text_scores,
737 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
738 &menu.main.text.editor, &main_text_editor,
743 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
744 &menu.main.text.info, &main_text_info,
749 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
750 &menu.main.text.game, &main_text_game,
755 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
756 &menu.main.text.setup, &main_text_setup,
761 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
762 &menu.main.text.quit, &main_text_quit,
766 MAIN_CONTROL_PREV_LEVEL,
772 MAIN_CONTROL_NEXT_LEVEL,
778 MAIN_CONTROL_FIRST_LEVEL,
780 &menu.main.text.first_level, &main_text_first_level,
784 MAIN_CONTROL_LAST_LEVEL,
786 &menu.main.text.last_level, &main_text_last_level,
790 MAIN_CONTROL_LEVEL_NUMBER,
792 &menu.main.text.level_number, &main_text_level_number,
796 MAIN_CONTROL_LEVEL_INFO_1,
798 &menu.main.text.level_info_1, NULL,
802 MAIN_CONTROL_LEVEL_INFO_2,
804 &menu.main.text.level_info_2, NULL,
808 MAIN_CONTROL_LEVEL_NAME,
810 &menu.main.text.level_name, &main_text_level_name,
814 MAIN_CONTROL_LEVEL_AUTHOR,
816 &menu.main.text.level_author, &main_text_level_author,
820 MAIN_CONTROL_LEVEL_YEAR,
822 &menu.main.text.level_year, &main_text_level_year,
826 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
828 &menu.main.text.level_imported_from, &main_text_level_imported_from,
832 MAIN_CONTROL_LEVEL_IMPORTED_BY,
834 &menu.main.text.level_imported_by, &main_text_level_imported_by,
838 MAIN_CONTROL_LEVEL_TESTED_BY,
840 &menu.main.text.level_tested_by, &main_text_level_tested_by,
844 MAIN_CONTROL_TITLE_1,
846 &menu.main.text.title_1, &main_text_title_1,
850 MAIN_CONTROL_TITLE_2,
852 &menu.main.text.title_2, &main_text_title_2,
856 MAIN_CONTROL_TITLE_3,
858 &menu.main.text.title_3, &main_text_title_3,
871 static int getTitleScreenGraphic(int nr, boolean initial)
873 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
876 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
878 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
882 static int getTitleScreenGameMode(boolean initial)
884 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
888 static int getTitleMessageGameMode(boolean initial)
890 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
893 static int getTitleAnimMode(struct TitleControlInfo *tci)
895 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
897 return base + tci->local_nr;
901 static int getTitleScreenBackground(boolean initial)
903 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
908 static int getTitleMessageBackground(int nr, boolean initial)
910 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
914 static int getTitleBackground(int nr, boolean initial, boolean is_image)
916 int base = (is_image ?
917 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
918 IMG_BACKGROUND_TITLESCREEN_1) :
919 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
920 IMG_BACKGROUND_TITLEMESSAGE_1));
921 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
922 IMG_BACKGROUND_TITLE);
923 int graphic_local = base + nr;
925 if (graphic_info[graphic_local].bitmap != NULL)
926 return graphic_local;
928 if (graphic_info[graphic_global].bitmap != NULL)
929 return graphic_global;
931 return IMG_UNDEFINED;
934 static int getTitleSound(struct TitleControlInfo *tci)
936 boolean is_image = tci->is_image;
937 int initial = tci->initial;
938 int nr = tci->local_nr;
939 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
940 int base = (is_image ?
941 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
942 SND_BACKGROUND_TITLESCREEN_1) :
943 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
944 SND_BACKGROUND_TITLEMESSAGE_1));
945 int sound_global = menu.sound[mode];
946 int sound_local = base + nr;
949 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
950 nr, initial, is_image,
951 sound_global, getSoundListEntry(sound_global)->filename,
952 sound_local, getSoundListEntry(sound_local)->filename);
955 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
958 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
961 return SND_UNDEFINED;
964 static int getTitleMusic(struct TitleControlInfo *tci)
966 boolean is_image = tci->is_image;
967 int initial = tci->initial;
968 int nr = tci->local_nr;
969 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
970 int base = (is_image ?
971 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
972 MUS_BACKGROUND_TITLESCREEN_1) :
973 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
974 MUS_BACKGROUND_TITLEMESSAGE_1));
975 int music_global = menu.music[mode];
976 int music_local = base + nr;
979 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
980 nr, initial, is_image,
981 music_global, getMusicListEntry(music_global)->filename,
982 music_local, getMusicListEntry(music_local)->filename);
985 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
988 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
991 return MUS_UNDEFINED;
994 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
996 boolean is_image = tci->is_image;
997 boolean initial = tci->initial;
998 boolean first = tci->first;
999 int nr = tci->local_nr;
1000 struct TitleMessageInfo tmi;
1001 struct TitleFadingInfo ti;
1003 tmi = (is_image ? (initial ? (first ?
1004 titlescreen_initial_first[nr] :
1005 titlescreen_initial[nr])
1007 titlescreen_first[nr] :
1009 : (initial ? (first ?
1010 titlemessage_initial_first[nr] :
1011 titlemessage_initial[nr])
1013 titlemessage_first[nr] :
1014 titlemessage[nr])));
1016 ti.fade_mode = tmi.fade_mode;
1017 ti.fade_delay = tmi.fade_delay;
1018 ti.post_delay = tmi.post_delay;
1019 ti.auto_delay = tmi.auto_delay;
1020 ti.auto_delay_unit = tmi.auto_delay_unit;
1025 static int compareTitleControlInfo(const void *object1, const void *object2)
1027 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1028 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1031 if (tci1->initial != tci2->initial)
1032 compare_result = (tci1->initial ? -1 : +1);
1033 else if (tci1->sort_priority != tci2->sort_priority)
1034 compare_result = tci1->sort_priority - tci2->sort_priority;
1035 else if (tci1->is_image != tci2->is_image)
1036 compare_result = (tci1->is_image ? -1 : +1);
1038 compare_result = tci1->local_nr - tci2->local_nr;
1040 return compare_result;
1043 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1045 int nr, int sort_priority)
1047 title_controls[num_title_screens].is_image = is_image;
1048 title_controls[num_title_screens].initial = initial;
1049 title_controls[num_title_screens].local_nr = nr;
1050 title_controls[num_title_screens].sort_priority = sort_priority;
1052 title_controls[num_title_screens].first = FALSE; // will be set later
1054 num_title_screens++;
1057 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1061 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1063 int graphic = getTitleScreenGraphic(i, initial);
1064 Bitmap *bitmap = graphic_info[graphic].bitmap;
1065 int sort_priority = graphic_info[graphic].sort_priority;
1068 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1071 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1073 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1074 char *filename = getLevelSetTitleMessageFilename(i, initial);
1075 int sort_priority = tmi->sort_priority;
1077 if (filename != NULL)
1078 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1082 static void InitializeTitleControls(boolean show_title_initial)
1084 num_title_screens = 0;
1086 // 1st step: initialize title screens for game start (only when starting)
1087 if (show_title_initial)
1088 InitializeTitleControls_CheckTitleInfo(TRUE);
1090 // 2nd step: initialize title screens for current level set
1091 InitializeTitleControls_CheckTitleInfo(FALSE);
1093 // sort title screens according to sort_priority and title number
1094 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1095 compareTitleControlInfo);
1097 // mark first title screen
1098 title_controls[0].first = TRUE;
1101 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1103 return (pos != NULL && pos->x != -1 && pos->y != -1);
1106 static boolean visibleTextPos(struct TextPosInfo *pos)
1108 return (pos != NULL && pos->x != -1 && pos->y != -1);
1111 static void InitializeMainControls(void)
1113 boolean local_team_mode = (!network.enabled && setup.team_mode);
1116 // set main control text values to dynamically determined values
1117 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1119 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1120 menu.main.text.first_level.size));
1121 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1122 menu.main.text.last_level.size));
1123 strcpy(main_text_level_number, int2str(level_nr,
1124 menu.main.text.level_number.size));
1126 main_text_level_year = leveldir_current->year;
1127 main_text_level_imported_from = leveldir_current->imported_from;
1128 main_text_level_imported_by = leveldir_current->imported_by;
1129 main_text_level_tested_by = leveldir_current->tested_by;
1131 main_text_title_1 = getConfigProgramTitleString();
1132 main_text_title_2 = getConfigProgramCopyrightString();
1133 main_text_title_3 = getConfigProgramCompanyString();
1135 // set main control screen positions to dynamically determined values
1136 for (i = 0; main_controls[i].nr != -1; i++)
1138 struct MainControlInfo *mci = &main_controls[i];
1140 struct MenuPosInfo *pos_button = mci->pos_button;
1141 struct TextPosInfo *pos_text = mci->pos_text;
1142 struct TextPosInfo *pos_input = mci->pos_input;
1143 char *text = (mci->text ? *mci->text : NULL);
1144 char *input = (mci->input ? *mci->input : NULL);
1145 int button_graphic = mci->button_graphic;
1146 int font_text = (pos_text ? pos_text->font : -1);
1147 int font_input = (pos_input ? pos_input->font : -1);
1149 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1150 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1151 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1152 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1153 int text_chars = (text != NULL ? strlen(text) : 0);
1154 int input_chars = (input != NULL ? strlen(input) : 0);
1157 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1159 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1160 int text_width = font_text_width * text_chars;
1161 int text_height = font_text_height;
1162 int input_width = font_input_width * input_chars;
1163 int input_height = font_input_height;
1165 if (nr == MAIN_CONTROL_NAME)
1167 menu.main.input.name.width = input_width;
1168 menu.main.input.name.height = input_height;
1171 if (pos_button != NULL) // (x/y may be -1/-1 here)
1173 pos_button->width = button_width;
1174 pos_button->height = button_height;
1177 if (pos_text != NULL) // (x/y may be -1/-1 here)
1179 // calculate text size -- needed for text alignment
1180 boolean calculate_text_size = (text != NULL);
1182 if (pos_text->width == -1 || calculate_text_size)
1183 pos_text->width = text_width;
1184 if (pos_text->height == -1 || calculate_text_size)
1185 pos_text->height = text_height;
1187 if (visibleMenuPos(pos_button))
1189 if (pos_text->x == -1)
1190 pos_text->x = pos_button->x + pos_button->width;
1191 if (pos_text->y == -1)
1193 pos_button->y + (pos_button->height - pos_text->height) / 2;
1197 if (pos_input != NULL) // (x/y may be -1/-1 here)
1199 if (visibleTextPos(pos_text))
1201 if (pos_input->x == -1)
1202 pos_input->x = pos_text->x + pos_text->width;
1203 if (pos_input->y == -1)
1204 pos_input->y = pos_text->y;
1207 if (pos_input->width == -1)
1208 pos_input->width = input_width;
1209 if (pos_input->height == -1)
1210 pos_input->height = input_height;
1215 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1216 int graphic, boolean pressed)
1218 struct GraphicInfo *g = &graphic_info[graphic];
1221 int xoffset = (pressed ? g->pressed_xoffset : 0);
1222 int yoffset = (pressed ? g->pressed_yoffset : 0);
1224 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1226 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1227 g->width, g->height, dst_x, dst_y);
1230 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1231 boolean active_input,
1232 boolean pressed_button)
1236 for (i = 0; main_controls[i].nr != -1; i++)
1238 struct MainControlInfo *mci = &main_controls[i];
1240 if (mci->nr == nr || nr == -1)
1242 struct MenuPosInfo *pos_button = mci->pos_button;
1243 struct TextPosInfo *pos_text = mci->pos_text;
1244 struct TextPosInfo *pos_input = mci->pos_input;
1245 char *text = (mci->text ? *mci->text : NULL);
1246 char *input = (mci->input ? *mci->input : NULL);
1247 int button_graphic = mci->button_graphic;
1248 int font_text = (pos_text ? pos_text->font : -1);
1249 int font_input = (pos_input ? pos_input->font : -1);
1253 button_graphic = BUTTON_ACTIVE(button_graphic);
1254 font_text = FONT_ACTIVE(font_text);
1259 font_input = FONT_ACTIVE(font_input);
1262 if (visibleMenuPos(pos_button))
1264 struct MenuPosInfo *pos = pos_button;
1265 int x = mSX + pos->x;
1266 int y = mSY + pos->y;
1268 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1269 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1272 if (visibleTextPos(pos_text) && text != NULL)
1274 struct TextPosInfo *pos = pos_text;
1275 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1276 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1279 // (check why/if this is needed)
1280 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1282 DrawText(x, y, text, font_text);
1285 if (visibleTextPos(pos_input) && input != NULL)
1287 struct TextPosInfo *pos = pos_input;
1288 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1289 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1292 // (check why/if this is needed)
1293 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1295 DrawText(x, y, input, font_input);
1301 static void DrawCursorAndText_Main(int nr, boolean active_text,
1302 boolean pressed_button)
1304 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1308 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1309 boolean pressed_button)
1311 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1315 static struct MainControlInfo *getMainControlInfo(int nr)
1319 for (i = 0; main_controls[i].nr != -1; i++)
1320 if (main_controls[i].nr == nr)
1321 return &main_controls[i];
1326 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1331 int rect_x = ALIGNED_TEXT_XPOS(rect);
1332 int rect_y = ALIGNED_TEXT_YPOS(rect);
1334 return (x >= rect_x && x < rect_x + rect->width &&
1335 y >= rect_y && y < rect_y + rect->height);
1338 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1343 int rect_x = ALIGNED_TEXT_XPOS(rect);
1344 int rect_y = ALIGNED_TEXT_YPOS(rect);
1347 Debug("screens:insideTextPosRect",
1348 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1349 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1350 (x >= rect_x && x < rect_x + rect->width &&
1351 y >= rect_y && y < rect_y + rect->height));
1354 return (x >= rect_x && x < rect_x + rect->width &&
1355 y >= rect_y && y < rect_y + rect->height);
1358 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1360 int rect_width = preview->xsize * preview->tile_size;
1361 int rect_height = preview->ysize * preview->tile_size;
1362 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1363 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1365 return (x >= rect_x && x < rect_x + rect_width &&
1366 y >= rect_y && y < rect_y + rect_height);
1369 static void AdjustScrollbar(int id, int items_max, int items_visible,
1372 struct GadgetInfo *gi = screen_gadget[id];
1374 if (item_position > items_max - items_visible)
1375 item_position = items_max - items_visible;
1377 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1378 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1379 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1382 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1384 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1388 static void clearMenuListArea(void)
1390 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1392 // correct scrollbar position if placed outside menu (playfield) area
1393 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1394 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1396 // clear menu list area, but not title or scrollbar
1397 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1398 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1401 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1403 static int cursor_array[MAX_LEV_FIELDY];
1404 int x = amSX + TILEX * xpos;
1405 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1410 cursor_array[ypos] = graphic;
1412 graphic = cursor_array[ypos];
1416 graphic = BUTTON_ACTIVE(graphic);
1418 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1419 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1422 static void initCursor(int ypos, int graphic)
1424 drawCursorExt(0, ypos, FALSE, graphic);
1427 static void drawCursor(int ypos, boolean active)
1429 drawCursorExt(0, ypos, active, -1);
1432 static void drawCursorXY(int xpos, int ypos, int graphic)
1434 drawCursorExt(xpos, ypos, FALSE, graphic);
1437 static void drawChooseTreeCursor(int ypos, boolean active)
1439 drawCursorExt(0, ypos, active, -1);
1442 static int getChooseTreeEditFont(boolean active)
1444 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1447 static int getChooseTreeEditXPos(int pos)
1449 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1450 int xoffset = (has_scrollbar ? -1 : 0);
1451 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1452 int sx = amSX + xpos * TILEX;
1453 int font_nr = getChooseTreeEditFont(FALSE);
1454 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1456 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1459 static int getChooseTreeEditYPos(int ypos_raw)
1461 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1462 int sy = amSY + ypos * TILEY;
1467 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1469 int sx = getChooseTreeEditXPos(POS_LEFT);
1470 int sy = getChooseTreeEditYPos(ypos_raw);
1471 int font_nr = getChooseTreeEditFont(active);
1473 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1476 static void DrawHeadline(void)
1478 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1479 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1482 static void DrawTitleScreenImage(int nr, boolean initial)
1484 int graphic = getTitleScreenGraphic(nr, initial);
1485 Bitmap *bitmap = graphic_info[graphic].bitmap;
1486 int width = graphic_info[graphic].width;
1487 int height = graphic_info[graphic].height;
1488 int src_x = graphic_info[graphic].src_x;
1489 int src_y = graphic_info[graphic].src_y;
1495 if (width > WIN_XSIZE)
1497 // image width too large for window => center image horizontally
1498 src_x = (width - WIN_XSIZE) / 2;
1502 if (height > WIN_YSIZE)
1504 // image height too large for window => center image vertically
1505 src_y = (height - WIN_YSIZE) / 2;
1509 // always display title screens centered
1510 dst_x = (WIN_XSIZE - width) / 2;
1511 dst_y = (WIN_YSIZE - height) / 2;
1513 SetDrawBackgroundMask(REDRAW_ALL);
1514 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1516 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1518 if (DrawingOnBackground(dst_x, dst_y))
1519 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1521 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1523 redraw_mask = REDRAW_ALL;
1526 static void DrawTitleScreenMessage(int nr, boolean initial)
1528 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1529 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1531 if (filename == NULL)
1534 // force TITLE font on title message screen
1535 SetFontStatus(getTitleMessageGameMode(initial));
1537 // if chars *and* width set to "-1", automatically determine width
1538 if (tmi->chars == -1 && tmi->width == -1)
1539 tmi->width = viewport.window[game_status].width;
1541 // if lines *and* height set to "-1", automatically determine height
1542 if (tmi->lines == -1 && tmi->height == -1)
1543 tmi->height = viewport.window[game_status].height;
1545 // if chars set to "-1", automatically determine by text and font width
1546 if (tmi->chars == -1)
1547 tmi->chars = tmi->width / getFontWidth(tmi->font);
1549 tmi->width = tmi->chars * getFontWidth(tmi->font);
1551 // if lines set to "-1", automatically determine by text and font height
1552 if (tmi->lines == -1)
1553 tmi->lines = tmi->height / getFontHeight(tmi->font);
1555 tmi->height = tmi->lines * getFontHeight(tmi->font);
1557 // if x set to "-1", automatically determine by width and alignment
1559 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1561 // if y set to "-1", automatically determine by height and alignment
1563 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1565 SetDrawBackgroundMask(REDRAW_ALL);
1566 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1568 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1570 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1571 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1572 tmi->autowrap, tmi->centered, tmi->parse_comments);
1577 static void DrawTitleScreen(void)
1579 KeyboardAutoRepeatOff();
1581 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1584 static boolean CheckTitleScreen(boolean levelset_has_changed)
1586 static boolean show_title_initial = TRUE;
1587 boolean show_titlescreen = FALSE;
1589 // needed to be able to skip title screen, if no image or message defined
1590 InitializeTitleControls(show_title_initial);
1592 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1593 show_titlescreen = TRUE;
1595 // show initial title images and messages only once at program start
1596 show_title_initial = FALSE;
1598 return (show_titlescreen && num_title_screens > 0);
1601 void DrawMainMenu(void)
1603 static LevelDirTree *leveldir_last_valid = NULL;
1604 boolean levelset_has_changed = FALSE;
1605 int fade_mask = REDRAW_FIELD;
1607 LimitScreenUpdates(FALSE);
1609 FadeSetLeaveScreen();
1611 // do not fade out here -- function may continue and fade on editor screen
1614 FadeMenuSoundsAndMusic();
1616 ExpireSoundLoops(FALSE);
1618 KeyboardAutoRepeatOn();
1620 audio.sound_deactivated = FALSE;
1624 // needed if last screen was the playing screen, invoked from level editor
1625 if (level_editor_test_game)
1627 CloseDoor(DOOR_CLOSE_ALL);
1629 SetGameStatus(GAME_MODE_EDITOR);
1636 // leveldir_current may be invalid (level group, parent link, node copy)
1637 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1639 if (leveldir_current != leveldir_last_valid)
1641 UpdateLastPlayedLevels_TreeInfo();
1643 levelset_has_changed = TRUE;
1646 // store valid level series information
1647 leveldir_last_valid = leveldir_current;
1649 init_last = init; // switch to new busy animation
1651 // needed if last screen (level choice) changed graphics, sounds or music
1652 ReloadCustomArtwork(0);
1654 if (CheckTitleScreen(levelset_has_changed))
1656 SetGameStatus(GAME_MODE_TITLE);
1663 if (redraw_mask & REDRAW_ALL)
1664 fade_mask = REDRAW_ALL;
1667 fade_mask = REDRAW_ALL;
1671 // needed if different viewport properties defined for menues
1672 ChangeViewportPropertiesIfNeeded();
1674 SetDrawtoField(DRAW_TO_BACKBUFFER);
1676 // level_nr may have been set to value over handicap with level editor
1677 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1678 level_nr = leveldir_current->handicap_level;
1680 LoadLevel(level_nr);
1681 LoadScore(level_nr);
1683 SaveLevelSetup_SeriesInfo();
1685 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1686 SetDrawDeactivationMask(REDRAW_NONE);
1687 SetDrawBackgroundMask(REDRAW_FIELD);
1689 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1692 if (fade_mask == REDRAW_ALL)
1693 RedrawGlobalBorder();
1698 InitializeMainControls();
1700 DrawCursorAndText_Main(-1, FALSE, FALSE);
1701 DrawPreviewLevelInitial();
1702 DrawNetworkPlayers();
1704 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1707 if (TAPE_IS_EMPTY(tape))
1709 DrawCompleteVideoDisplay();
1711 PlayMenuSoundsAndMusic();
1713 // create gadgets for main menu screen
1714 FreeScreenGadgets();
1715 CreateScreenGadgets();
1717 // may be required if audio buttons shown on tape and changed in setup menu
1719 CreateGameButtons();
1721 // map gadgets for main menu screen
1723 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1724 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1726 // copy actual game door content to door double buffer for OpenDoor()
1727 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1728 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1730 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1732 DrawMaskedBorder(fade_mask);
1737 // update screen area with special editor door
1738 redraw_mask |= REDRAW_ALL;
1741 SetMouseCursor(CURSOR_DEFAULT);
1743 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1745 SyncEmscriptenFilesystem();
1748 static void gotoTopLevelDir(void)
1750 // move upwards until inside (but not above) top level directory
1751 while (leveldir_current->node_parent &&
1752 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1754 // write a "path" into level tree for easy navigation to last level
1755 if (leveldir_current->node_parent->node_group->cl_first == -1)
1757 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1758 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1759 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1760 int cl_first, cl_cursor;
1762 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1763 cl_cursor = leveldir_pos - cl_first;
1765 leveldir_current->node_parent->node_group->cl_first = cl_first;
1766 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1769 leveldir_current = leveldir_current->node_parent;
1773 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1775 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1777 return (use_frame_counter ? video.frame_counter : Counter());
1780 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1781 struct TitleFadingInfo *fi)
1783 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1786 static void ResetTitleAutoDelay(unsigned int *counter_var,
1787 struct TitleFadingInfo *fi)
1789 *counter_var = getAutoDelayCounter(fi);
1792 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1794 static unsigned int title_delay = 0;
1795 static int title_screen_nr = 0;
1796 static int last_sound = -1, last_music = -1;
1797 boolean return_to_main_menu = FALSE;
1798 struct TitleControlInfo *tci;
1801 if (button == MB_MENU_INITIALIZE)
1804 title_screen_nr = 0;
1805 tci = &title_controls[title_screen_nr];
1807 SetAnimStatus(getTitleAnimMode(tci));
1809 last_sound = SND_UNDEFINED;
1810 last_music = MUS_UNDEFINED;
1812 if (num_title_screens != 0)
1814 FadeSetEnterScreen();
1816 // use individual title fading instead of global "enter screen" fading
1817 fading = getTitleFading(tci);
1820 if (game_status_last_screen == GAME_MODE_INFO)
1822 if (num_title_screens == 0)
1824 // switch game mode from title screen mode back to info screen mode
1825 SetGameStatus(GAME_MODE_INFO);
1827 // store that last screen was info screen, not main menu screen
1828 game_status_last_screen = GAME_MODE_INFO;
1830 DrawInfoScreen_NotAvailable("Title screen information:",
1831 "No title screen for this level set.");
1836 FadeMenuSoundsAndMusic();
1838 FadeOut(REDRAW_ALL);
1840 // title screens may have different window size
1841 ChangeViewportPropertiesIfNeeded();
1843 // only required to update logic for redrawing global border
1847 DrawTitleScreenImage(tci->local_nr, tci->initial);
1849 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1851 sound = getTitleSound(tci);
1852 music = getTitleMusic(tci);
1854 if (sound != last_sound)
1855 PlayMenuSoundExt(sound);
1856 if (music != last_music)
1857 PlayMenuMusicExt(music);
1862 SetMouseCursor(CURSOR_NONE);
1866 ResetTitleAutoDelay(&title_delay, &fading);
1871 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1872 button = MB_MENU_CHOICE;
1874 if (button == MB_MENU_LEAVE)
1876 return_to_main_menu = TRUE;
1878 else if (button == MB_MENU_CHOICE)
1880 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1882 SetGameStatus(GAME_MODE_INFO);
1884 info_mode = INFO_MODE_MAIN;
1893 if (title_screen_nr < num_title_screens)
1895 tci = &title_controls[title_screen_nr];
1897 SetAnimStatus(getTitleAnimMode(tci));
1899 sound = getTitleSound(tci);
1900 music = getTitleMusic(tci);
1902 if (last_sound != SND_UNDEFINED && sound != last_sound)
1903 FadeSound(last_sound);
1904 if (last_music != MUS_UNDEFINED && music != last_music)
1907 fading = getTitleFading(tci);
1909 FadeOut(REDRAW_ALL);
1912 DrawTitleScreenImage(tci->local_nr, tci->initial);
1914 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1916 sound = getTitleSound(tci);
1917 music = getTitleMusic(tci);
1919 if (sound != last_sound)
1920 PlayMenuSoundExt(sound);
1921 if (music != last_music)
1922 PlayMenuMusicExt(music);
1929 ResetTitleAutoDelay(&title_delay, &fading);
1933 FadeMenuSoundsAndMusic();
1935 return_to_main_menu = TRUE;
1939 if (return_to_main_menu)
1941 SetMouseCursor(CURSOR_DEFAULT);
1943 // force full menu screen redraw after displaying title screens
1944 redraw_mask = REDRAW_ALL;
1946 if (game_status_last_screen == GAME_MODE_INFO)
1948 SetGameStatus(GAME_MODE_INFO);
1950 info_mode = INFO_MODE_MAIN;
1954 else // default: return to main menu
1956 SetGameStatus(GAME_MODE_MAIN);
1963 static void HandleMainMenu_ToggleTeamMode(void)
1965 setup.team_mode = !setup.team_mode;
1967 InitializeMainControls();
1968 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
1970 DrawPreviewPlayers();
1973 static void HandleMainMenu_SelectLevel(int step, int direction,
1974 int selected_level_nr)
1976 int old_level_nr = level_nr;
1979 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1980 new_level_nr = selected_level_nr;
1982 new_level_nr = old_level_nr + step * direction;
1984 if (new_level_nr < leveldir_current->first_level)
1985 new_level_nr = leveldir_current->first_level;
1986 if (new_level_nr > leveldir_current->last_level)
1987 new_level_nr = leveldir_current->last_level;
1989 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1991 // skipping levels is only allowed when trying to skip single level
1992 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1993 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1995 leveldir_current->handicap_level++;
1996 SaveLevelSetup_SeriesInfo();
1999 new_level_nr = leveldir_current->handicap_level;
2002 if (new_level_nr != old_level_nr)
2004 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2006 PlaySound(SND_MENU_ITEM_SELECTING);
2008 level_nr = new_level_nr;
2010 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2011 int2str(level_nr, menu.main.text.level_number.size),
2012 mci->pos_text->font);
2014 LoadLevel(level_nr);
2015 DrawPreviewLevelInitial();
2019 DrawCompleteVideoDisplay();
2021 SaveLevelSetup_SeriesInfo();
2023 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2025 // force redraw of playfield area (may be reset at this point)
2026 redraw_mask |= REDRAW_FIELD;
2030 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2032 static int choice = MAIN_CONTROL_GAME;
2033 static boolean button_pressed_last = FALSE;
2034 boolean button_pressed = FALSE;
2036 int i = 0; // needed to prevent compiler warning due to bad code below
2038 if (button == MB_MENU_INITIALIZE)
2040 DrawCursorAndText_Main(choice, TRUE, FALSE);
2045 if (mx || my) // mouse input
2049 for (i = 0; main_controls[i].nr != -1; i++)
2051 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2052 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2053 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2055 pos = main_controls[i].nr;
2061 // check if level preview was clicked
2062 if (insidePreviewRect(&preview, mx - SX, my - SY))
2063 pos = MAIN_CONTROL_GAME;
2065 // handle pressed/unpressed state for active/inactive menu buttons
2066 // (if pos != -1, "i" contains index position corresponding to "pos")
2068 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2069 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2070 button_pressed = TRUE;
2072 if (button_pressed != button_pressed_last)
2074 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2077 PlaySound(SND_MENU_BUTTON_PRESSING);
2079 PlaySound(SND_MENU_BUTTON_RELEASING);
2082 else if (dx || dy) // keyboard input
2084 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2085 choice == MAIN_CONTROL_SETUP))
2086 button = MB_MENU_CHOICE;
2091 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2093 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2095 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2097 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2099 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2101 CloseDoor(DOOR_CLOSE_2);
2103 SetGameStatus(GAME_MODE_LEVELNR);
2105 DrawChooseLevelNr();
2107 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2113 PlaySound(SND_MENU_ITEM_ACTIVATING);
2115 DrawCursorAndText_Main(choice, FALSE, FALSE);
2116 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2122 if (choice == MAIN_CONTROL_NAME)
2124 // special case: cursor left or right pressed -- toggle team mode
2125 HandleMainMenu_ToggleTeamMode();
2127 else if (choice != MAIN_CONTROL_INFO &&
2128 choice != MAIN_CONTROL_SETUP)
2130 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2136 PlaySound(SND_MENU_ITEM_SELECTING);
2138 if (pos == MAIN_CONTROL_NAME)
2141 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2143 // special case: menu text "name/team" clicked -- toggle team mode
2144 HandleMainMenu_ToggleTeamMode();
2148 if (setup.multiple_users)
2150 CloseDoor(DOOR_CLOSE_2);
2152 SetGameStatus(GAME_MODE_NAMES);
2154 DrawChoosePlayerName();
2158 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2164 else if (pos == MAIN_CONTROL_LEVELS)
2168 CloseDoor(DOOR_CLOSE_2);
2170 SetGameStatus(GAME_MODE_LEVELS);
2172 SaveLevelSetup_LastSeries();
2173 SaveLevelSetup_SeriesInfo();
2175 // restore level set if chosen from "last played level set" menu
2176 RestoreLastPlayedLevels(&leveldir_current);
2178 if (setup.internal.choose_from_top_leveldir)
2181 DrawChooseLevelSet();
2184 else if (pos == MAIN_CONTROL_SCORES)
2186 CloseDoor(DOOR_CLOSE_2);
2188 SetGameStatus(GAME_MODE_SCORES);
2190 DrawHallOfFame(level_nr);
2192 else if (pos == MAIN_CONTROL_EDITOR)
2194 if (leveldir_current->readonly &&
2195 setup.editor.show_read_only_warning)
2196 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2198 CloseDoor(DOOR_CLOSE_ALL);
2200 SetGameStatus(GAME_MODE_EDITOR);
2202 FadeSetEnterScreen();
2206 else if (pos == MAIN_CONTROL_INFO)
2208 CloseDoor(DOOR_CLOSE_2);
2210 SetGameStatus(GAME_MODE_INFO);
2212 info_mode = INFO_MODE_MAIN;
2216 else if (pos == MAIN_CONTROL_GAME)
2218 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2220 else if (pos == MAIN_CONTROL_SETUP)
2222 CloseDoor(DOOR_CLOSE_2);
2224 SetGameStatus(GAME_MODE_SETUP);
2226 setup_mode = SETUP_MODE_MAIN;
2230 else if (pos == MAIN_CONTROL_QUIT)
2232 SaveLevelSetup_LastSeries();
2233 SaveLevelSetup_SeriesInfo();
2235 if (!setup.ask_on_quit_program ||
2236 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2237 SetGameStatus(GAME_MODE_QUIT);
2242 button_pressed_last = button_pressed;
2246 // ============================================================================
2247 // info screen functions
2248 // ============================================================================
2250 static struct TokenInfo *info_info;
2251 static int num_info_info; // number of info entries shown on screen
2252 static int max_info_info; // total number of info entries in list
2254 static void execInfoTitleScreen(void)
2256 info_mode = INFO_MODE_TITLE;
2261 static void execInfoElements(void)
2263 info_mode = INFO_MODE_ELEMENTS;
2268 static void execInfoMusic(void)
2270 info_mode = INFO_MODE_MUSIC;
2275 static void execInfoCredits(void)
2277 info_mode = INFO_MODE_CREDITS;
2282 static void execInfoProgram(void)
2284 info_mode = INFO_MODE_PROGRAM;
2289 static void execInfoVersion(void)
2291 info_mode = INFO_MODE_VERSION;
2296 static void execInfoLevelSet(void)
2298 info_mode = INFO_MODE_LEVELSET;
2303 static void execExitInfo(void)
2305 SetGameStatus(GAME_MODE_MAIN);
2310 static struct TokenInfo info_info_main[] =
2312 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2313 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2314 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2315 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2316 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2317 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2318 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2319 { TYPE_EMPTY, NULL, "" },
2320 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2325 static int getMenuTextFont(int type)
2327 if (type & (TYPE_SWITCH |
2341 static struct TokenInfo *setup_info;
2342 static struct TokenInfo setup_info_input[];
2344 static struct TokenInfo *menu_info;
2346 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2347 int screen_pos, int menu_info_pos_raw,
2350 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2351 struct TokenInfo *ti = &token_info[pos];
2352 int xpos = MENU_SCREEN_START_XPOS;
2353 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2354 int font_nr = getMenuTextFont(ti->type);
2356 if (setup_mode == SETUP_MODE_INPUT)
2357 font_nr = FONT_MENU_1;
2360 font_nr = FONT_ACTIVE(font_nr);
2362 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2364 if (ti->type & ~TYPE_SKIP_ENTRY)
2365 drawCursor(screen_pos, active);
2368 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2371 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2374 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2377 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2380 static char *window_size_text;
2381 static char *scaling_type_text;
2382 static char *network_server_text;
2384 static void drawSetupValue(int, int);
2386 static void drawMenuInfoList(int first_entry, int num_page_entries,
2387 int max_page_entries)
2391 if (first_entry + num_page_entries > max_page_entries)
2394 clearMenuListArea();
2396 for (i = 0; i < num_page_entries; i++)
2398 int menu_info_pos = first_entry + i;
2399 struct TokenInfo *si = &menu_info[menu_info_pos];
2400 void *value_ptr = si->value;
2402 // set some entries to "unchangeable" according to other variables
2403 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2404 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2405 (value_ptr == &setup.sound_music && !audio.music_available) ||
2406 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2407 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2408 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2409 si->type |= TYPE_GHOSTED;
2411 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2412 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2413 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2414 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2415 else if (si->type & ~TYPE_SKIP_ENTRY)
2416 initCursor(i, IMG_MENU_BUTTON);
2418 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2420 if (si->type & TYPE_STRING)
2424 if (value_ptr == &network_server_text)
2425 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2427 if (gadget_id != -1)
2429 struct GadgetInfo *gi = screen_gadget[gadget_id];
2430 int xpos = MENU_SCREEN_START_XPOS;
2431 int ypos = MENU_SCREEN_START_YPOS + i;
2432 int x = mSX + xpos * 32;
2433 int y = mSY + ypos * 32;
2435 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2439 if (si->type & TYPE_VALUE &&
2440 menu_info == setup_info)
2441 drawSetupValue(i, menu_info_pos);
2445 static void DrawInfoScreen_Main(void)
2447 int fade_mask = REDRAW_FIELD;
2450 if (redraw_mask & REDRAW_ALL)
2451 fade_mask = REDRAW_ALL;
2454 fade_mask = REDRAW_ALL;
2457 FadeMenuSoundsAndMusic();
2459 FreeScreenGadgets();
2460 CreateScreenGadgets();
2462 // (needed after displaying title screens which disable auto repeat)
2463 KeyboardAutoRepeatOn();
2465 FadeSetLeaveScreen();
2469 // needed if different viewport properties defined for info screen
2470 ChangeViewportPropertiesIfNeeded();
2472 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2476 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2478 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2480 info_info = info_info_main;
2482 // determine maximal number of info entries that can be displayed on screen
2484 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2487 // determine maximal number of info entries available for menu of info screen
2489 for (i = 0; info_info[i].type != 0; i++)
2492 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2494 MapScreenGadgets(max_info_info);
2496 PlayMenuSoundsAndMusic();
2498 DrawMaskedBorder(fade_mask);
2503 static void changeSetupValue(int, int, int);
2505 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2506 int mode, int num_page_entries,
2507 int max_page_entries)
2509 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2510 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2511 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2512 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2513 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2514 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2515 int *num_page_entries_last = num_page_entries_all_last[game_status];
2516 int *choice_store = choice_stores[game_status];
2517 int *first_entry_store = first_entry_stores[game_status];
2518 int choice = choice_store[mode]; // starts with 0
2519 int first_entry = first_entry_store[mode]; // starts with 0
2521 int y = choice - first_entry;
2523 boolean position_set_by_scrollbar = (dx == 999);
2524 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2527 if (button == MB_MENU_INITIALIZE)
2529 // check if number of menu page entries has changed (may happen by change
2530 // of custom artwork definition value for 'list_size' for this menu screen)
2531 // (in this case, the last menu position most probably has to be corrected)
2532 if (num_page_entries != num_page_entries_last[mode])
2534 choice_store[mode] = first_entry_store[mode] = 0;
2536 choice = first_entry = 0;
2539 num_page_entries_last[mode] = num_page_entries;
2542 // advance to first valid menu entry
2543 while (choice < num_page_entries &&
2544 menu_info[choice].type & TYPE_SKIP_ENTRY)
2547 if (position_set_by_scrollbar)
2548 first_entry = first_entry_store[mode] = dy;
2550 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2551 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2553 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2555 if (choice < first_entry)
2557 choice = first_entry;
2559 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2562 else if (choice > first_entry + num_page_entries - 1)
2564 choice = first_entry + num_page_entries - 1;
2566 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2570 choice_store[mode] = choice;
2572 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2576 else if (button == MB_MENU_LEAVE)
2578 PlaySound(SND_MENU_ITEM_SELECTING);
2580 for (i = 0; i < max_page_entries; i++)
2582 if (menu_info[i].type & TYPE_LEAVE_MENU)
2584 void (*menu_callback_function)(void) = menu_info[i].value;
2588 menu_callback_function();
2590 break; // absolutely needed because function changes 'menu_info'!
2597 if (mx || my) // mouse input
2599 x = (mx - mSX) / 32;
2600 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2602 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2604 // move cursor instead of scrolling when already at start/end of list
2605 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2607 else if (dy == +1 * SCROLL_LINE &&
2608 first_entry + num_page_entries == max_page_entries)
2611 // handle scrolling screen one line or page
2613 y + dy > num_page_entries - 1)
2615 boolean redraw = FALSE;
2617 if (ABS(dy) == SCROLL_PAGE)
2618 step = num_page_entries - 1;
2620 if (dy < 0 && first_entry > 0)
2622 // scroll page/line up
2624 first_entry -= step;
2625 if (first_entry < 0)
2630 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2632 // scroll page/line down
2634 first_entry += step;
2635 if (first_entry + num_page_entries > max_page_entries)
2636 first_entry = MAX(0, max_page_entries - num_page_entries);
2643 choice += first_entry - first_entry_store[mode];
2645 if (choice < first_entry)
2647 choice = first_entry;
2649 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2652 else if (choice > first_entry + num_page_entries - 1)
2654 choice = first_entry + num_page_entries - 1;
2656 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2659 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2663 if (choice < first_entry ||
2664 choice > first_entry + num_page_entries - 1)
2665 first_entry += SIGN(dy);
2668 first_entry_store[mode] = first_entry;
2669 choice_store[mode] = choice;
2671 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2673 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2675 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2676 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2684 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2686 if (menu_info[choice].type & menu_navigation_type ||
2687 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2688 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2689 menu_info[choice].type & TYPE_PLAYER)
2690 button = MB_MENU_CHOICE;
2695 // jump to next non-empty menu entry (up or down)
2696 while (first_entry + y > 0 &&
2697 first_entry + y < max_page_entries - 1 &&
2698 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2701 if (!IN_VIS_MENU(x, y))
2703 choice += y - y_old;
2705 if (choice < first_entry)
2706 first_entry = choice;
2707 else if (choice > first_entry + num_page_entries - 1)
2708 first_entry = choice - num_page_entries + 1;
2710 if (first_entry >= 0 &&
2711 first_entry + num_page_entries <= max_page_entries)
2713 first_entry_store[mode] = first_entry;
2715 if (choice < first_entry)
2716 choice = first_entry;
2717 else if (choice > first_entry + num_page_entries - 1)
2718 choice = first_entry + num_page_entries - 1;
2720 choice_store[mode] = choice;
2722 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2724 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2726 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2727 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2734 if (!anyScrollbarGadgetActive() &&
2735 IN_VIS_MENU(x, y) &&
2736 mx < mx_right_border &&
2737 y >= 0 && y < num_page_entries)
2741 if (first_entry + y != choice &&
2742 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2744 PlaySound(SND_MENU_ITEM_ACTIVATING);
2746 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2747 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2749 choice = choice_store[mode] = first_entry + y;
2753 PlaySound(SND_MENU_ITEM_SELECTING);
2755 for (i = 0; menu_info[i].type != 0; i++)
2757 if (menu_info[i].type & TYPE_LEAVE_MENU)
2759 void (*menu_callback_function)(void) = menu_info[i].value;
2763 menu_callback_function();
2765 // absolutely needed because function changes 'menu_info'!
2773 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2775 PlaySound(SND_MENU_ITEM_SELECTING);
2777 // when selecting key headline, execute function for key value change
2778 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2779 menu_info[first_entry + y + 1].type & TYPE_KEY)
2782 // when selecting string value, execute function for list selection
2783 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2784 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2787 // when selecting string value, execute function for text input gadget
2788 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2789 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2792 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2794 void (*menu_callback_function)(void) =
2795 menu_info[first_entry + y].value;
2797 FadeSetFromType(menu_info[first_entry + y].type);
2799 menu_callback_function();
2801 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2803 void (*gadget_callback_function)(void) =
2804 menu_info[first_entry + y].value;
2806 gadget_callback_function();
2808 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2809 menu_info == setup_info)
2811 changeSetupValue(y, first_entry + y, dx);
2817 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2819 menu_info = info_info;
2821 HandleMenuScreen(mx, my, dx, dy, button,
2822 info_mode, num_info_info, max_info_info);
2825 static int getMenuFontSpacing(int spacing_height, int font_nr)
2827 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2829 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2833 static int getMenuTextSpacing(int spacing_height, int font_nr)
2835 return (getMenuFontSpacing(spacing_height, font_nr) +
2836 EXTRA_SPACING(game_status));
2839 static int getMenuTextStep(int spacing_height, int font_nr)
2841 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2844 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2846 int font_title = MENU_INFO_FONT_TITLE;
2847 int font_error = FONT_TEXT_2;
2848 int font_foot = MENU_INFO_FONT_FOOT;
2849 int spacing_title = menu.headline1_spacing_info[info_mode];
2850 int ystep_title = getMenuTextStep(spacing_title, font_title);
2851 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2852 int ystart2 = ystart1 + ystep_title;
2853 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2855 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2857 FadeOut(REDRAW_FIELD);
2862 DrawTextSCentered(ystart1, font_title, text_title);
2863 DrawTextSCentered(ystart2, font_error, text_error);
2865 DrawTextSCentered(ybottom, font_foot,
2866 "Press any key or button for info menu");
2868 FadeIn(REDRAW_FIELD);
2871 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2873 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2874 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2875 int font_title = MENU_INFO_FONT_TITLE;
2876 int font_foot = MENU_INFO_FONT_FOOT;
2877 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2878 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2879 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2880 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2881 int ystep = MENU_SCREEN_INFO_YSTEP;
2882 int element, action, direction;
2890 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2891 infoscreen_step[i] = infoscreen_frame[i] = 0;
2896 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2898 DrawTextSCentered(ybottom, font_foot,
2899 "Press any key or button for next page");
2905 while (helpanim_info[j].element != HELPANIM_LIST_END)
2907 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2912 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2921 j += infoscreen_step[i - start];
2923 element = helpanim_info[j].element;
2924 action = helpanim_info[j].action;
2925 direction = helpanim_info[j].direction;
2928 element = EL_UNKNOWN;
2930 if (action != -1 && direction != -1)
2931 graphic = el_act_dir2img(element, action, direction);
2932 else if (action != -1)
2933 graphic = el_act2img(element, action);
2934 else if (direction != -1)
2935 graphic = el_dir2img(element, direction);
2937 graphic = el2img(element);
2939 delay = helpanim_info[j++].delay;
2944 if (infoscreen_frame[i - start] == 0)
2947 infoscreen_frame[i - start] = delay - 1;
2951 sync_frame = delay - infoscreen_frame[i - start];
2952 infoscreen_frame[i - start]--;
2955 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2957 if (!infoscreen_frame[i - start])
2958 infoscreen_step[i - start] = 0;
2962 if (!infoscreen_frame[i - start])
2963 infoscreen_step[i - start]++;
2964 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2970 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2972 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2973 graphic, sync_frame, USE_MASKING);
2976 DrawInfoScreen_HelpText(element, action, direction, i - start);
2981 redraw_mask |= REDRAW_FIELD;
2986 static char *getHelpText(int element, int action, int direction)
2988 char token[MAX_LINE_LEN];
2990 strcpy(token, element_info[element].token_name);
2993 strcat(token, element_action_info[action].suffix);
2995 if (direction != -1)
2996 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2998 return getHashEntry(helptext_info, token);
3001 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3003 int font_nr = FONT_INFO_ELEMENTS;
3004 int font_width = getFontWidth(font_nr);
3005 int font_height = getFontHeight(font_nr);
3006 int yoffset = (TILEX - 2 * font_height) / 2;
3007 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3008 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3009 int ystep = TILEY + 4;
3010 int pad_left = xstart - SX;
3011 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3012 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3013 int max_lines_per_text = 2;
3016 if (action != -1 && direction != -1) // element.action.direction
3017 text = getHelpText(element, action, direction);
3019 if (text == NULL && action != -1) // element.action
3020 text = getHelpText(element, action, -1);
3022 if (text == NULL && direction != -1) // element.direction
3023 text = getHelpText(element, -1, direction);
3025 if (text == NULL) // base element
3026 text = getHelpText(element, -1, -1);
3028 if (text == NULL) // not found
3029 text = "No description available";
3031 if (strlen(text) <= max_chars_per_line) // only one line of text
3032 ystart += getFontHeight(font_nr) / 2;
3034 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3035 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3036 TRUE, FALSE, FALSE);
3039 static void DrawInfoScreen_TitleScreen(void)
3041 SetGameStatus(GAME_MODE_TITLE);
3046 void HandleInfoScreen_TitleScreen(int button)
3048 HandleTitleScreen(0, 0, 0, 0, button);
3051 static void DrawInfoScreen_Elements(void)
3053 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3055 FadeOut(REDRAW_FIELD);
3060 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3062 FadeIn(REDRAW_FIELD);
3065 void HandleInfoScreen_Elements(int button)
3067 static unsigned int info_delay = 0;
3068 static int num_anims;
3069 static int num_pages;
3071 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3074 if (button == MB_MENU_INITIALIZE)
3076 boolean new_element = TRUE;
3080 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3082 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3084 else if (new_element)
3087 new_element = FALSE;
3091 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3095 if (button == MB_MENU_LEAVE)
3097 PlaySound(SND_MENU_ITEM_SELECTING);
3099 info_mode = INFO_MODE_MAIN;
3104 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3106 if (button != MB_MENU_INITIALIZE)
3108 PlaySound(SND_MENU_ITEM_SELECTING);
3113 if (page >= num_pages)
3115 FadeMenuSoundsAndMusic();
3117 info_mode = INFO_MODE_MAIN;
3124 FadeSetNextScreen();
3126 if (button != MB_MENU_INITIALIZE)
3127 FadeOut(REDRAW_FIELD);
3129 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3131 if (button != MB_MENU_INITIALIZE)
3132 FadeIn(REDRAW_FIELD);
3136 if (DelayReached(&info_delay, GameFrameDelay))
3137 if (page < num_pages)
3138 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3140 PlayMenuSoundIfLoop();
3144 static void DrawInfoScreen_Music(void)
3146 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3148 FadeOut(REDRAW_FIELD);
3155 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3157 FadeIn(REDRAW_FIELD);
3160 void HandleInfoScreen_Music(int button)
3162 static struct MusicFileInfo *list = NULL;
3163 int font_title = MENU_INFO_FONT_TITLE;
3164 int font_head = MENU_INFO_FONT_HEAD;
3165 int font_text = MENU_INFO_FONT_TEXT;
3166 int font_foot = MENU_INFO_FONT_FOOT;
3167 int spacing_title = menu.headline1_spacing_info[info_mode];
3168 int spacing_head = menu.headline2_spacing_info[info_mode];
3169 int ystep_title = getMenuTextStep(spacing_title, font_title);
3170 int ystep_head = getMenuTextStep(spacing_head, font_head);
3171 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3172 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3174 if (button == MB_MENU_INITIALIZE)
3176 list = music_file_info;
3180 FadeMenuSoundsAndMusic();
3185 DrawTextSCentered(ystart, font_title,
3186 "No music info for this level set.");
3188 DrawTextSCentered(ybottom, font_foot,
3189 "Press any key or button for info menu");
3195 if (button == MB_MENU_LEAVE)
3197 PlaySound(SND_MENU_ITEM_SELECTING);
3199 FadeMenuSoundsAndMusic();
3201 info_mode = INFO_MODE_MAIN;
3206 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3208 if (button != MB_MENU_INITIALIZE)
3210 PlaySound(SND_MENU_ITEM_SELECTING);
3218 FadeMenuSoundsAndMusic();
3220 info_mode = INFO_MODE_MAIN;
3226 FadeMenuSoundsAndMusic();
3228 if (list != music_file_info)
3229 FadeSetNextScreen();
3231 if (button != MB_MENU_INITIALIZE)
3232 FadeOut(REDRAW_FIELD);
3239 int sound = list->music;
3241 if (sound_info[sound].loop)
3242 PlaySoundLoop(sound);
3246 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3250 int music = list->music;
3252 if (music_info[music].loop)
3253 PlayMusicLoop(music);
3257 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3260 ystart += ystep_title;
3262 if (!strEqual(list->title, UNKNOWN_NAME))
3264 if (!strEqual(list->title_header, UNKNOWN_NAME))
3266 DrawTextSCentered(ystart, font_head, list->title_header);
3267 ystart += ystep_head;
3270 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3271 ystart += ystep_head;
3274 if (!strEqual(list->artist, UNKNOWN_NAME))
3276 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3277 DrawTextSCentered(ystart, font_head, list->artist_header);
3279 DrawTextSCentered(ystart, font_head, "by");
3281 ystart += ystep_head;
3283 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3284 ystart += ystep_head;
3287 if (!strEqual(list->album, UNKNOWN_NAME))
3289 if (!strEqual(list->album_header, UNKNOWN_NAME))
3290 DrawTextSCentered(ystart, font_head, list->album_header);
3292 DrawTextSCentered(ystart, font_head, "from the album");
3294 ystart += ystep_head;
3296 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3297 ystart += ystep_head;
3300 if (!strEqual(list->year, UNKNOWN_NAME))
3302 if (!strEqual(list->year_header, UNKNOWN_NAME))
3303 DrawTextSCentered(ystart, font_head, list->year_header);
3305 DrawTextSCentered(ystart, font_head, "from the year");
3307 ystart += ystep_head;
3309 DrawTextFCentered(ystart, font_text, "%s", list->year);
3310 ystart += ystep_head;
3313 DrawTextSCentered(ybottom, FONT_TEXT_4,
3314 "Press any key or button for next page");
3316 if (button != MB_MENU_INITIALIZE)
3317 FadeIn(REDRAW_FIELD);
3320 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3321 PlaySoundLoop(list->music);
3324 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3326 int font_title = MENU_INFO_FONT_TITLE;
3327 int font_head = MENU_INFO_FONT_HEAD;
3328 int font_text = MENU_INFO_FONT_TEXT;
3329 int font_foot = MENU_INFO_FONT_FOOT;
3330 int spacing_title = menu.headline1_spacing_info[info_mode];
3331 int spacing_head = menu.headline2_spacing_info[info_mode];
3332 int spacing_para = menu.paragraph_spacing_info[info_mode];
3333 int spacing_line = menu.line_spacing_info[info_mode];
3334 int ystep_title = getMenuTextStep(spacing_title, font_title);
3335 int ystep_head = getMenuTextStep(spacing_head, font_head);
3336 int ystep_para = getMenuTextStep(spacing_para, font_text);
3337 int ystep_line = getMenuTextStep(spacing_line, font_text);
3338 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3339 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3344 DrawTextSCentered(ystart, font_title, "Credits:");
3345 ystart += ystep_title;
3349 DrawTextSCentered(ystart, font_head,
3350 "Special thanks to");
3351 ystart += ystep_head;
3352 DrawTextSCentered(ystart, font_text,
3354 ystart += ystep_head;
3355 DrawTextSCentered(ystart, font_head,
3357 ystart += ystep_head;
3358 DrawTextSCentered(ystart, font_text,
3359 "\"Boulder Dash\"");
3360 ystart += ystep_head;
3361 DrawTextSCentered(ystart, font_head,
3363 ystart += ystep_head;
3364 DrawTextSCentered(ystart, font_text,
3366 ystart += ystep_head;
3367 DrawTextSCentered(ystart, font_head,
3369 ystart += ystep_head;
3370 DrawTextSCentered(ystart, font_text,
3371 "First Star Software");
3373 else if (screen_nr == 1)
3375 DrawTextSCentered(ystart, font_head,
3376 "Special thanks to");
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_text,
3379 "Klaus Heinz & Volker Wertich");
3380 ystart += ystep_head;
3381 DrawTextSCentered(ystart, font_head,
3383 ystart += ystep_head;
3384 DrawTextSCentered(ystart, font_text,
3385 "\"Emerald Mine\"");
3386 ystart += ystep_head;
3387 DrawTextSCentered(ystart, font_head,
3389 ystart += ystep_head;
3390 DrawTextSCentered(ystart, font_text,
3392 ystart += ystep_head;
3393 DrawTextSCentered(ystart, font_head,
3395 ystart += ystep_head;
3396 DrawTextSCentered(ystart, font_text,
3399 else if (screen_nr == 2)
3401 DrawTextSCentered(ystart, font_head,
3402 "Special thanks to");
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_text,
3405 "Michael Stopp & Philip Jespersen");
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_head,
3409 ystart += ystep_head;
3410 DrawTextSCentered(ystart, font_text,
3412 ystart += ystep_head;
3413 DrawTextSCentered(ystart, font_head,
3415 ystart += ystep_head;
3416 DrawTextSCentered(ystart, font_text,
3418 ystart += ystep_head;
3419 DrawTextSCentered(ystart, font_head,
3421 ystart += ystep_head;
3422 DrawTextSCentered(ystart, font_text,
3423 "Digital Integration");
3425 else if (screen_nr == 3)
3427 DrawTextSCentered(ystart, font_head,
3428 "Special thanks to");
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_text,
3431 "Hiroyuki Imabayashi");
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_head,
3435 ystart += ystep_head;
3436 DrawTextSCentered(ystart, font_text,
3438 ystart += ystep_head;
3439 DrawTextSCentered(ystart, font_head,
3441 ystart += ystep_head;
3442 DrawTextSCentered(ystart, font_text,
3444 ystart += ystep_head;
3445 DrawTextSCentered(ystart, font_head,
3447 ystart += ystep_head;
3448 DrawTextSCentered(ystart, font_text,
3451 else if (screen_nr == 4)
3453 DrawTextSCentered(ystart, font_head,
3454 "Special thanks to");
3455 ystart += ystep_head;
3456 DrawTextSCentered(ystart, font_text,
3458 ystart += ystep_head;
3459 DrawTextSCentered(ystart, font_head,
3461 ystart += ystep_head;
3462 DrawTextSCentered(ystart, font_text,
3463 "J\xfcrgen Bonhagen");
3464 ystart += ystep_head;
3465 DrawTextSCentered(ystart, font_head,
3466 "for the continuous creation");
3467 ystart += ystep_line;
3468 DrawTextSCentered(ystart, font_head,
3469 "of outstanding level sets");
3471 else if (screen_nr == 5)
3473 DrawTextSCentered(ystart, font_head,
3475 ystart += ystep_head;
3476 DrawTextSCentered(ystart, font_text,
3478 ystart += ystep_head;
3479 DrawTextSCentered(ystart, font_head,
3480 "for ideas and inspiration by");
3481 ystart += ystep_head;
3482 DrawTextSCentered(ystart, font_text,
3484 ystart += ystep_para;
3486 DrawTextSCentered(ystart, font_head,
3488 ystart += ystep_head;
3489 DrawTextSCentered(ystart, font_text,
3491 ystart += ystep_head;
3492 DrawTextSCentered(ystart, font_head,
3493 "for ideas and inspiration by");
3494 ystart += ystep_head;
3495 DrawTextSCentered(ystart, font_text,
3498 else if (screen_nr == 6)
3500 DrawTextSCentered(ystart, font_head,
3502 ystart += ystep_head;
3503 DrawTextSCentered(ystart, font_text,
3505 ystart += ystep_head;
3506 DrawTextSCentered(ystart, font_head,
3507 "for the code base used for the");
3508 ystart += ystep_line;
3509 DrawTextSCentered(ystart, font_head,
3510 "native Emerald Mine engine");
3512 else if (screen_nr == 7)
3514 DrawTextSCentered(ystart, font_head,
3516 ystart += ystep_head;
3517 DrawTextSCentered(ystart, font_text,
3519 ystart += ystep_head;
3520 DrawTextSCentered(ystart, font_head,
3521 "for the initial DOS port");
3522 ystart += ystep_para;
3524 DrawTextSCentered(ystart, font_head,
3526 ystart += ystep_head;
3527 DrawTextSCentered(ystart, font_text,
3529 ystart += ystep_head;
3530 DrawTextSCentered(ystart, font_head,
3531 "for some additional toons");
3533 else if (screen_nr == 8)
3535 DrawTextSCentered(ystart, font_head,
3536 "And not to forget:");
3537 ystart += ystep_head;
3538 DrawTextSCentered(ystart, font_head,
3540 ystart += ystep_head;
3541 DrawTextSCentered(ystart, font_text,
3542 "All those who contributed");
3543 ystart += ystep_line;
3544 DrawTextSCentered(ystart, font_text,
3545 "levels to this game");
3546 ystart += ystep_line;
3547 DrawTextSCentered(ystart, font_text,
3551 DrawTextSCentered(ybottom, font_foot,
3552 "Press any key or button for next page");
3555 static void DrawInfoScreen_Credits(void)
3557 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3559 FadeMenuSoundsAndMusic();
3561 FadeOut(REDRAW_FIELD);
3563 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3565 FadeIn(REDRAW_FIELD);
3568 void HandleInfoScreen_Credits(int button)
3570 static int screen_nr = 0;
3571 int num_screens = 9;
3573 if (button == MB_MENU_INITIALIZE)
3577 // DrawInfoScreen_CreditsScreen(screen_nr);
3580 if (button == MB_MENU_LEAVE)
3582 PlaySound(SND_MENU_ITEM_SELECTING);
3584 info_mode = INFO_MODE_MAIN;
3589 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3591 if (button != MB_MENU_INITIALIZE)
3593 PlaySound(SND_MENU_ITEM_SELECTING);
3598 if (screen_nr >= num_screens)
3600 FadeMenuSoundsAndMusic();
3602 info_mode = INFO_MODE_MAIN;
3609 FadeSetNextScreen();
3611 if (button != MB_MENU_INITIALIZE)
3612 FadeOut(REDRAW_FIELD);
3614 DrawInfoScreen_CreditsScreen(screen_nr);
3616 if (button != MB_MENU_INITIALIZE)
3617 FadeIn(REDRAW_FIELD);
3621 PlayMenuSoundIfLoop();
3625 static void DrawInfoScreen_Program(void)
3627 int font_title = MENU_INFO_FONT_TITLE;
3628 int font_head = MENU_INFO_FONT_HEAD;
3629 int font_text = MENU_INFO_FONT_TEXT;
3630 int font_foot = MENU_INFO_FONT_FOOT;
3631 int spacing_title = menu.headline1_spacing_info[info_mode];
3632 int spacing_head = menu.headline2_spacing_info[info_mode];
3633 int spacing_para = menu.paragraph_spacing_info[info_mode];
3634 int spacing_line = menu.line_spacing_info[info_mode];
3635 int ystep_title = getMenuTextStep(spacing_title, font_title);
3636 int ystep_head = getMenuTextStep(spacing_head, font_head);
3637 int ystep_para = getMenuTextStep(spacing_para, font_text);
3638 int ystep_line = getMenuTextStep(spacing_line, font_text);
3639 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3640 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3642 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3644 FadeOut(REDRAW_FIELD);
3649 DrawTextSCentered(ystart, font_title, "Program Information:");
3650 ystart += ystep_title;
3652 DrawTextSCentered(ystart, font_head,
3653 "This game is Freeware!");
3654 ystart += ystep_head;
3655 DrawTextSCentered(ystart, font_head,
3656 "If you like it, send e-mail to:");
3657 ystart += ystep_head;
3658 DrawTextSCentered(ystart, font_text,
3659 setup.internal.program_email);
3660 ystart += ystep_para;
3662 DrawTextSCentered(ystart, font_head,
3663 "More information and levels:");
3664 ystart += ystep_head;
3665 DrawTextSCentered(ystart, font_text,
3666 setup.internal.program_website);
3667 ystart += ystep_para;
3669 DrawTextSCentered(ystart, font_head,
3670 "If you have created new levels,");
3671 ystart += ystep_line;
3672 DrawTextSCentered(ystart, font_head,
3673 "send them to me to include them!");
3674 ystart += ystep_head;
3675 DrawTextSCentered(ystart, font_head,
3678 DrawTextSCentered(ybottom, font_foot,
3679 "Press any key or button for info menu");
3681 FadeIn(REDRAW_FIELD);
3684 void HandleInfoScreen_Program(int button)
3686 if (button == MB_MENU_LEAVE)
3688 PlaySound(SND_MENU_ITEM_SELECTING);
3690 info_mode = INFO_MODE_MAIN;
3695 else if (button == MB_MENU_CHOICE)
3697 PlaySound(SND_MENU_ITEM_SELECTING);
3699 FadeMenuSoundsAndMusic();
3701 info_mode = INFO_MODE_MAIN;
3706 PlayMenuSoundIfLoop();
3710 static void DrawInfoScreen_Version(void)
3712 int font_title = MENU_INFO_FONT_TITLE;
3713 int font_head = MENU_INFO_FONT_HEAD;
3714 int font_text = MENU_INFO_FONT_TEXT;
3715 int font_foot = MENU_INFO_FONT_FOOT;
3716 int spacing_title = menu.headline1_spacing_info[info_mode];
3717 int spacing_head = menu.headline2_spacing_info[info_mode];
3718 int spacing_para = menu.paragraph_spacing_info[info_mode];
3719 int spacing_line = menu.line_spacing_info[info_mode];
3720 int xstep = getFontWidth(font_text);
3721 int ystep_title = getMenuTextStep(spacing_title, font_title);
3722 int ystep_head = getMenuTextStep(spacing_head, font_head);
3723 int ystep_para = getMenuTextStep(spacing_para, font_text);
3724 int ystep_line = getMenuTextStep(spacing_line, font_text);
3725 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3726 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3727 int xstart1 = mSX - SX + 2 * xstep;
3728 int xstart2 = mSX - SX + 18 * xstep;
3729 int xstart3 = mSX - SX + 28 * xstep;
3730 SDL_version sdl_version_compiled;
3731 const SDL_version *sdl_version_linked;
3732 int driver_name_len = 10;
3733 SDL_version sdl_version_linked_ext;
3734 const char *driver_name = NULL;
3736 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3738 FadeOut(REDRAW_FIELD);
3743 DrawTextSCentered(ystart, font_title, "Version Information:");
3744 ystart += ystep_title;
3746 DrawTextF(xstart1, ystart, font_head, "Name");
3747 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3748 ystart += ystep_line;
3750 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3752 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3753 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3754 ystart += ystep_line;
3756 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3757 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3758 ystart += ystep_line;
3762 DrawTextF(xstart1, ystart, font_head, "Version");
3763 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3764 ystart += ystep_line;
3767 DrawTextF(xstart1, ystart, font_head, "Platform");
3768 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3770 PLATFORM_XX_BIT_STRING);
3771 ystart += ystep_line;
3773 DrawTextF(xstart1, ystart, font_head, "Target");
3774 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3775 ystart += ystep_line;
3777 DrawTextF(xstart1, ystart, font_head, "Source date");
3778 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3779 ystart += ystep_line;
3781 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3782 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3783 ystart += ystep_para;
3785 DrawTextF(xstart1, ystart, font_head, "Library");
3786 DrawTextF(xstart2, ystart, font_head, "compiled");
3787 DrawTextF(xstart3, ystart, font_head, "linked");
3788 ystart += ystep_head;
3790 SDL_VERSION(&sdl_version_compiled);
3791 SDL_GetVersion(&sdl_version_linked_ext);
3792 sdl_version_linked = &sdl_version_linked_ext;
3794 DrawTextF(xstart1, ystart, font_text, "SDL");
3795 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3796 sdl_version_compiled.major,
3797 sdl_version_compiled.minor,
3798 sdl_version_compiled.patch);
3799 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3800 sdl_version_linked->major,
3801 sdl_version_linked->minor,
3802 sdl_version_linked->patch);
3803 ystart += ystep_line;
3805 SDL_IMAGE_VERSION(&sdl_version_compiled);
3806 sdl_version_linked = IMG_Linked_Version();
3808 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3809 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3810 sdl_version_compiled.major,
3811 sdl_version_compiled.minor,
3812 sdl_version_compiled.patch);
3813 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3814 sdl_version_linked->major,
3815 sdl_version_linked->minor,
3816 sdl_version_linked->patch);
3817 ystart += ystep_line;
3819 SDL_MIXER_VERSION(&sdl_version_compiled);
3820 sdl_version_linked = Mix_Linked_Version();
3822 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3823 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3824 sdl_version_compiled.major,
3825 sdl_version_compiled.minor,
3826 sdl_version_compiled.patch);
3827 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3828 sdl_version_linked->major,
3829 sdl_version_linked->minor,
3830 sdl_version_linked->patch);
3831 ystart += ystep_line;
3833 SDL_NET_VERSION(&sdl_version_compiled);
3834 sdl_version_linked = SDLNet_Linked_Version();
3836 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3837 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3838 sdl_version_compiled.major,
3839 sdl_version_compiled.minor,
3840 sdl_version_compiled.patch);
3841 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3842 sdl_version_linked->major,
3843 sdl_version_linked->minor,
3844 sdl_version_linked->patch);
3845 ystart += ystep_para;
3847 DrawTextF(xstart1, ystart, font_head, "Driver");
3848 DrawTextF(xstart2, ystart, font_head, "Requested");
3849 DrawTextF(xstart3, ystart, font_head, "Used");
3850 ystart += ystep_head;
3853 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3855 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3856 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3857 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3858 ystart += ystep_line;
3861 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3863 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3864 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3865 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3866 ystart += ystep_line;
3869 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3871 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3872 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3873 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3875 DrawTextSCentered(ybottom, font_foot,
3876 "Press any key or button for info menu");
3878 FadeIn(REDRAW_FIELD);
3881 void HandleInfoScreen_Version(int button)
3883 if (button == MB_MENU_LEAVE)
3885 PlaySound(SND_MENU_ITEM_SELECTING);
3887 info_mode = INFO_MODE_MAIN;
3892 else if (button == MB_MENU_CHOICE)
3894 PlaySound(SND_MENU_ITEM_SELECTING);
3896 FadeMenuSoundsAndMusic();
3898 info_mode = INFO_MODE_MAIN;
3903 PlayMenuSoundIfLoop();
3907 static void DrawInfoScreen_LevelSet(void)
3909 struct TitleMessageInfo *tmi = &readme;
3910 char *filename = getLevelSetInfoFilename();
3911 char *title = "Level Set Information:";
3912 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3913 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3915 if (filename == NULL)
3917 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3922 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3924 FadeOut(REDRAW_FIELD);
3929 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3931 // if x position set to "-1", automatically determine by playfield width
3933 tmi->x = SXSIZE / 2;
3935 // if y position set to "-1", use static default value
3939 // if width set to "-1", automatically determine by playfield width
3940 if (tmi->width == -1)
3941 tmi->width = SXSIZE - 2 * TILEX;
3943 // if height set to "-1", automatically determine by playfield height
3944 if (tmi->height == -1)
3945 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3947 // if chars set to "-1", automatically determine by text and font width
3948 if (tmi->chars == -1)
3949 tmi->chars = tmi->width / getFontWidth(tmi->font);
3951 tmi->width = tmi->chars * getFontWidth(tmi->font);
3953 // if lines set to "-1", automatically determine by text and font height
3954 if (tmi->lines == -1)
3955 tmi->lines = tmi->height / getFontHeight(tmi->font);
3957 tmi->height = tmi->lines * getFontHeight(tmi->font);
3959 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3960 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3961 tmi->autowrap, tmi->centered, tmi->parse_comments);
3963 DrawTextSCentered(ybottom, FONT_TEXT_4,
3964 "Press any key or button for info menu");
3966 FadeIn(REDRAW_FIELD);
3969 static void HandleInfoScreen_LevelSet(int button)
3971 if (button == MB_MENU_LEAVE)
3973 PlaySound(SND_MENU_ITEM_SELECTING);
3975 info_mode = INFO_MODE_MAIN;
3980 else if (button == MB_MENU_CHOICE)
3982 PlaySound(SND_MENU_ITEM_SELECTING);
3984 FadeMenuSoundsAndMusic();
3986 info_mode = INFO_MODE_MAIN;
3991 PlayMenuSoundIfLoop();
3995 static void DrawInfoScreen(void)
3997 if (info_mode == INFO_MODE_TITLE)
3998 DrawInfoScreen_TitleScreen();
3999 else if (info_mode == INFO_MODE_ELEMENTS)
4000 DrawInfoScreen_Elements();
4001 else if (info_mode == INFO_MODE_MUSIC)
4002 DrawInfoScreen_Music();
4003 else if (info_mode == INFO_MODE_CREDITS)
4004 DrawInfoScreen_Credits();
4005 else if (info_mode == INFO_MODE_PROGRAM)
4006 DrawInfoScreen_Program();
4007 else if (info_mode == INFO_MODE_VERSION)
4008 DrawInfoScreen_Version();
4009 else if (info_mode == INFO_MODE_LEVELSET)
4010 DrawInfoScreen_LevelSet();
4012 DrawInfoScreen_Main();
4014 if (info_mode != INFO_MODE_MAIN &&
4015 info_mode != INFO_MODE_TITLE &&
4016 info_mode != INFO_MODE_MUSIC)
4017 PlayMenuSoundsAndMusic();
4020 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4022 if (info_mode == INFO_MODE_TITLE)
4023 HandleInfoScreen_TitleScreen(button);
4024 else if (info_mode == INFO_MODE_ELEMENTS)
4025 HandleInfoScreen_Elements(button);
4026 else if (info_mode == INFO_MODE_MUSIC)
4027 HandleInfoScreen_Music(button);
4028 else if (info_mode == INFO_MODE_CREDITS)
4029 HandleInfoScreen_Credits(button);
4030 else if (info_mode == INFO_MODE_PROGRAM)
4031 HandleInfoScreen_Program(button);
4032 else if (info_mode == INFO_MODE_VERSION)
4033 HandleInfoScreen_Version(button);
4034 else if (info_mode == INFO_MODE_LEVELSET)
4035 HandleInfoScreen_LevelSet(button);
4037 HandleInfoScreen_Main(mx, my, dx, dy, button);
4041 // ============================================================================
4042 // change name functions
4043 // ============================================================================
4045 struct ApiRenamePlayerThreadData
4051 static void *CreateThreadData_ApiRenamePlayer(void)
4053 struct ApiRenamePlayerThreadData *data =
4054 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4056 data->player_name = getStringCopy(setup.player_name);
4057 data->player_uuid = getStringCopy(setup.player_uuid);
4062 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4064 struct ApiRenamePlayerThreadData *data = data_raw;
4066 checked_free(data->player_name);
4067 checked_free(data->player_uuid);
4071 static void ApiRenamePlayerExt(struct HttpRequest *request,
4072 struct HttpResponse *response,
4075 struct ApiRenamePlayerThreadData *data = data_raw;
4076 char *player_name_raw = data->player_name;
4077 char *player_uuid_raw = data->player_uuid;
4079 request->hostname = setup.api_server_hostname;
4080 request->port = API_SERVER_PORT;
4081 request->method = API_SERVER_METHOD;
4082 request->uri = API_SERVER_URI_RENAME;
4084 char *player_name = getEscapedJSON(player_name_raw);
4085 char *player_uuid = getEscapedJSON(player_uuid_raw);
4087 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4090 " \"game_version\": \"%s\",\n"
4091 " \"game_platform\": \"%s\",\n"
4092 " \"name\": \"%s\",\n"
4093 " \"uuid\": \"%s\"\n"
4095 getPasswordJSON(setup.api_server_password),
4096 getProgramRealVersionString(),
4097 getProgramPlatformString(),
4101 checked_free(player_name);
4102 checked_free(player_uuid);
4104 ConvertHttpRequestBodyToServerEncoding(request);
4106 if (!DoHttpRequest(request, response))
4108 Error("HTTP request failed: %s", GetHttpError());
4113 if (!HTTP_SUCCESS(response->status_code))
4115 Error("server failed to handle request: %d %s",
4116 response->status_code,
4117 response->status_text);
4123 static void ApiRenamePlayer(void *data_raw)
4125 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4126 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4128 ApiRenamePlayerExt(request, response, data_raw);
4130 checked_free(request);
4131 checked_free(response);
4134 static int ApiRenamePlayerThread(void *data_raw)
4136 ApiRenamePlayer(data_raw);
4138 FreeThreadData_ApiRenamePlayer(data_raw);
4143 static void ApiRenamePlayerAsThread(void)
4145 struct ApiRenamePlayerThreadData *data =
4146 CreateThreadData_ApiRenamePlayer();
4148 ExecuteAsThread(ApiRenamePlayerThread,
4149 "ApiRenamePlayer", data,
4150 "rename player on server");
4154 // ============================================================================
4155 // type name functions
4156 // ============================================================================
4158 static TreeInfo *type_name_node = NULL;
4159 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4160 static int type_name_nr = 0;
4162 static int getPlayerNameColor(char *name)
4164 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4167 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4170 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4171 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4172 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4173 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4174 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4175 int font_width = getFontWidth(font_nr);
4177 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4179 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4181 pos->width = strlen(text) * font_width;
4182 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4184 DrawText(sx, sy, text, font_nr);
4187 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4189 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4191 *pos = *mci->pos_input;
4193 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4195 TreeInfo *ti = player_name_current;
4196 int first_entry = ti->cl_first;
4197 int entry_pos = first_entry + ti->cl_cursor;
4198 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4199 int xpos = MENU_SCREEN_START_XPOS;
4200 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4202 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4203 type_name_nr = entry_pos;
4205 strcpy(name, type_name_node->name);
4209 pos->width = MAX_PLAYER_NAME_LEN * 32;
4213 type_name_nr = user.nr;
4215 strcpy(name, setup.player_name);
4218 strcpy(type_name_last, name);
4220 if (strEqual(name, EMPTY_PLAYER_NAME))
4223 *xpos = strlen(name);
4226 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4228 // change name of edited user in global list of user names
4229 setString(&global.user_names[type_name_nr], name);
4231 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4233 TreeInfo *node = type_name_node;
4235 // change name of edited user in local menu tree structure
4236 setString(&node->name, name);
4237 setString(&node->name_sorting, name);
4239 node->color = getPlayerNameColor(name);
4240 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4244 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4247 boolean reset_setup = strEqual(name, "");
4248 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4249 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4252 strcpy(name, type_name_last);
4254 if (strEqual(name, ""))
4255 strcpy(name, EMPTY_PLAYER_NAME);
4257 setTypeNameValues_Name(name, pos);
4259 // if player name not changed, no further action required
4260 if (strEqual(name, type_name_last))
4263 // redraw player name before (possibly) opening request dialogs
4264 drawTypeNameText(name, pos, FALSE);
4266 int last_user_nr = user.nr;
4268 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4270 // save setup of currently active user (may differ from edited user)
4273 // temporarily change active user to edited user
4274 user.nr = type_name_nr;
4276 // load setup of edited user (unless creating user with current setup)
4278 !Request("Use current setup values for the new player?", REQ_ASK))
4282 char *setup_filename = getSetupFilename();
4283 boolean setup_exists = fileExists(setup_filename);
4285 // change name of edited user in setup structure
4286 strcpy(setup.player_name, name);
4288 // save setup of edited user
4291 // change name of edited user on score server
4292 ApiRenamePlayerAsThread();
4294 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4298 if (Request("Reset setup values for this player?", REQ_ASK))
4300 // remove setup config file
4301 unlink(setup_filename);
4303 // set player name to default player name
4306 // update player name used by name typing functions
4307 strcpy(name, setup.player_name);
4309 setTypeNameValues_Name(name, pos);
4312 else if (remove_user && type_name_nr != 0)
4314 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4316 char *user_dir = getUserGameDataDir();
4317 char *user_dir_removed =
4318 getStringCat3WithSeparator(user_dir, "REMOVED",
4319 getCurrentTimestamp(), ".");
4321 if (rename(user_dir, user_dir_removed) != 0)
4322 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4324 checked_free(user_dir_removed);
4327 else if (create_user && type_name_nr != 0 && !setup_exists)
4329 if (Request("Create empty level set for the new player?", REQ_ASK))
4331 char *levelset_subdir = getNewUserLevelSubdir();
4333 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4335 AddUserLevelSetToLevelInfo(levelset_subdir);
4337 LevelDirTree *leveldir_current_last = leveldir_current;
4339 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4342 // set level number of newly created level set to default value
4343 LoadLevelSetup_SeriesInfo();
4345 // set newly created level set as current level set for new user
4346 SaveLevelSetup_LastSeries();
4347 SaveLevelSetup_SeriesInfo();
4349 leveldir_current = leveldir_current_last;
4353 Request("Creating new level set failed!", REQ_CONFIRM);
4358 // restore currently active user
4359 user.nr = last_user_nr;
4361 // restore setup of currently active user
4364 // restore last level set of currently active user
4365 LoadLevelSetup_LastSeries();
4366 LoadLevelSetup_SeriesInfo();
4370 static void HandleTypeNameExt(boolean initialize, Key key)
4372 static struct TextPosInfo pos_name = { 0 };
4373 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4374 static int xpos = 0;
4375 struct TextPosInfo *pos = &pos_name;
4376 char key_char = getValidConfigValueChar(getCharFromKey(key));
4377 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4378 boolean active = TRUE;
4382 getTypeNameValues(name, pos, &xpos);
4384 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4385 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4387 StartTextInput(sx, sy, pos->width, pos->height);
4389 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4391 name[xpos] = key_char;
4396 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4402 else if (key == KSYM_Return || key == KSYM_Escape)
4404 boolean changed = (key == KSYM_Return);
4408 setTypeNameValues(name, pos, changed);
4413 drawTypeNameText(name, pos, active);
4417 SetGameStatus(game_status_last_screen);
4419 if (game_status == GAME_MODE_MAIN)
4420 InitializeMainControls();
4424 static void DrawTypeName(void)
4426 HandleTypeNameExt(TRUE, 0);
4429 void HandleTypeName(Key key)
4431 HandleTypeNameExt(FALSE, key);
4435 // ============================================================================
4436 // tree menu functions
4437 // ============================================================================
4439 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4441 if (game_status != GAME_MODE_SETUP ||
4442 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4445 int max_text_size = 0;
4448 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4449 max_text_size = MAX(max_text_size, strlen(node->name));
4451 int num_entries = numTreeInfoInGroup(ti);
4452 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4453 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4454 int text_width = max_text_size * getFontWidth(font_nr);
4455 int button_width = SC_MENUBUTTON_XSIZE;
4456 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4457 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4458 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4459 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4460 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4461 int align_xoffset = MAX(0, align_xoffset_raw);
4463 return align_xoffset;
4466 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4468 if (game_status != GAME_MODE_SETUP ||
4469 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4472 int num_entries = numTreeInfoInGroup(ti);
4473 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4474 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4475 int font_height = getFontHeight(font_nr);
4476 int text_height = font_height * num_page_entries;
4477 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4478 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4479 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4480 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4481 int align_yoffset = MAX(0, align_yoffset_raw);
4483 return align_yoffset;
4486 static void DrawChooseTree(TreeInfo **ti_ptr)
4488 int fade_mask = REDRAW_FIELD;
4491 fade_mask = REDRAW_ALL;
4493 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4495 if (game_status == GAME_MODE_SETUP)
4499 else // GAME_MODE_LEVELS
4501 SetGameStatus(GAME_MODE_MAIN);
4511 FreeScreenGadgets();
4512 CreateScreenGadgets();
4516 // needed if different viewport properties defined for choosing level (set)
4517 ChangeViewportPropertiesIfNeeded();
4519 if (game_status == GAME_MODE_NAMES)
4520 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4521 else if (game_status == GAME_MODE_LEVELNR)
4522 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4523 else if (game_status == GAME_MODE_LEVELS)
4524 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4528 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4530 MapScreenTreeGadgets(*ti_ptr);
4531 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4533 DrawMaskedBorder(fade_mask);
4538 static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
4540 int num_entries = numTreeInfoInGroup(ti);
4541 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4542 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4543 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4544 int first_entry = ti->cl_first;
4545 int entry_pos = first_entry + y;
4546 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4547 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4548 int font_color = MENU_CHOOSE_TREE_COLOR(node, active);
4549 int font_nr = MENU_CHOOSE_TREE_FONT(font_color);
4550 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4551 int xpos = MENU_SCREEN_START_XPOS;
4552 int ypos = MENU_SCREEN_START_YPOS + y;
4553 int startx = amSX + xpos * 32;
4554 int starty = amSY + ypos * 32;
4555 int startx_text = startx + font_xoffset;
4556 int endx_text = amSX + screen_width;
4557 int max_text_size = endx_text - startx_text;
4558 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4559 char buffer[max_buffer_len + 1];
4561 strncpy(buffer, node->name, max_buffer_len);
4562 buffer[max_buffer_len] = '\0';
4564 DrawText(startx, starty, buffer, font_nr);
4567 static void drawChooseTreeList(int first_entry, int num_page_entries,
4571 char *title_string = NULL;
4572 int yoffset_sets = MENU_TITLE1_YPOS;
4573 int yoffset_setup = 16;
4574 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4575 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4577 title_string = ti->infotext;
4579 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4581 clearMenuListArea();
4583 for (i = 0; i < num_page_entries; i++)
4585 TreeInfo *node, *node_first;
4586 int entry_pos = first_entry + i;
4588 node_first = getTreeInfoFirstGroupEntry(ti);
4589 node = getTreeInfoFromPos(node_first, entry_pos);
4591 drawChooseTreeText(i, FALSE, ti);
4593 if (node->parent_link)
4594 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4595 else if (node->level_group)
4596 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4598 initCursor(i, IMG_MENU_BUTTON);
4600 if (game_status == GAME_MODE_NAMES)
4601 drawChooseTreeEdit(i, FALSE);
4604 redraw_mask |= REDRAW_FIELD;
4607 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4609 TreeInfo *node, *node_first;
4610 int x, last_redraw_mask = redraw_mask;
4611 int ypos = MENU_TITLE2_YPOS;
4612 int font_nr = FONT_TITLE_2;
4614 if (ti->type == TREE_TYPE_LEVEL_NR)
4615 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4617 if (ti->type != TREE_TYPE_LEVEL_DIR)
4620 node_first = getTreeInfoFirstGroupEntry(ti);
4621 node = getTreeInfoFromPos(node_first, entry_pos);
4623 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4625 if (node->parent_link)
4626 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4627 node->node_parent->name);
4628 else if (node->level_group)
4629 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4631 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4632 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4633 node->levels, (node->levels > 1 ? "levels" : "level"),
4636 // let BackToFront() redraw only what is needed
4637 redraw_mask = last_redraw_mask;
4638 for (x = 0; x < SCR_FIELDX; x++)
4639 MarkTileDirty(x, 1);
4642 static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
4644 drawChooseTreeCursor(y, active);
4645 drawChooseTreeText(y, active, ti);
4648 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4651 TreeInfo *ti = *ti_ptr;
4652 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4653 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4654 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4655 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4656 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4658 int y = ti->cl_cursor;
4659 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4660 int num_entries = numTreeInfoInGroup(ti);
4661 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4662 boolean position_set_by_scrollbar = (dx == 999);
4664 if (button == MB_MENU_INITIALIZE)
4666 int num_entries = numTreeInfoInGroup(ti);
4667 int entry_pos = getPosFromTreeInfo(ti);
4669 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4670 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4672 if (ti->cl_first == -1)
4674 // only on initialization
4675 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4676 ti->cl_cursor = entry_pos - ti->cl_first;
4678 else if (ti->cl_cursor >= num_page_entries ||
4679 (num_entries > num_page_entries &&
4680 num_entries - ti->cl_first < num_page_entries))
4682 // only after change of list size (by custom graphic configuration)
4683 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4684 ti->cl_cursor = entry_pos - ti->cl_first;
4687 if (position_set_by_scrollbar)
4690 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4693 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4694 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4695 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4699 else if (button == MB_MENU_LEAVE)
4703 PlaySound(SND_MENU_ITEM_SELECTING);
4705 if (ti->node_parent)
4707 *ti_ptr = ti->node_parent;
4708 DrawChooseTree(ti_ptr);
4710 else if (game_status == GAME_MODE_SETUP)
4712 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4713 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4714 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4716 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4717 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4718 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4719 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4720 execSetupGraphics();
4721 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4722 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4723 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4725 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4726 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4727 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4728 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4729 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4730 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4731 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4732 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4739 if (game_status == GAME_MODE_LEVELNR)
4741 int new_level_nr = atoi(level_number_current->identifier);
4743 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4746 SetGameStatus(GAME_MODE_MAIN);
4754 if (mx || my) // mouse input
4756 x = (mx - amSX) / 32;
4757 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4759 if (game_status == GAME_MODE_NAMES)
4760 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4762 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4764 // move cursor instead of scrolling when already at start/end of list
4765 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4767 else if (dy == +1 * SCROLL_LINE &&
4768 ti->cl_first + num_page_entries == num_entries)
4771 // handle scrolling screen one line or page
4772 if (ti->cl_cursor + dy < 0 ||
4773 ti->cl_cursor + dy > num_page_entries - 1)
4775 boolean redraw = FALSE;
4777 if (ABS(dy) == SCROLL_PAGE)
4778 step = num_page_entries - 1;
4780 if (dy < 0 && ti->cl_first > 0)
4782 // scroll page/line up
4784 ti->cl_first -= step;
4785 if (ti->cl_first < 0)
4790 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4792 // scroll page/line down
4794 ti->cl_first += step;
4795 if (ti->cl_first + num_page_entries > num_entries)
4796 ti->cl_first = MAX(0, num_entries - num_page_entries);
4803 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4804 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4805 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4807 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4814 // handle moving cursor one line
4815 y = ti->cl_cursor + dy;
4820 TreeInfo *node_first, *node_cursor;
4821 int entry_pos = ti->cl_first + y;
4823 node_first = getTreeInfoFirstGroupEntry(ti);
4824 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4826 if (node_cursor->node_group)
4830 PlaySound(SND_MENU_ITEM_SELECTING);
4832 node_cursor->cl_first = ti->cl_first;
4833 node_cursor->cl_cursor = ti->cl_cursor;
4834 *ti_ptr = node_cursor->node_group;
4835 DrawChooseTree(ti_ptr);
4840 else if (dx == -1 && ti->node_parent)
4844 PlaySound(SND_MENU_ITEM_SELECTING);
4846 *ti_ptr = ti->node_parent;
4847 DrawChooseTree(ti_ptr);
4852 if (!anyScrollbarGadgetActive() &&
4853 IN_VIS_MENU(x, y) &&
4854 mx < mx_right_border &&
4855 y >= 0 && y < num_page_entries)
4859 if (game_status == GAME_MODE_NAMES)
4861 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4862 drawChooseTreeEdit(y, TRUE);
4865 if (y != ti->cl_cursor)
4867 PlaySound(SND_MENU_ITEM_ACTIVATING);
4869 drawChooseTreeCursorAndText(ti->cl_cursor, FALSE, ti);
4870 drawChooseTreeCursorAndText(y, TRUE, ti);
4871 drawChooseTreeInfo(ti->cl_first + y, ti);
4877 if (game_status == GAME_MODE_SETUP)
4879 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4880 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4881 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4883 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4884 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4885 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4886 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4887 execSetupGraphics();
4888 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4889 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4890 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4892 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4893 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4894 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4895 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4896 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4897 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4898 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4899 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4908 TreeInfo *node_first, *node_cursor;
4909 int entry_pos = ti->cl_first + y;
4911 PlaySound(SND_MENU_ITEM_SELECTING);
4913 node_first = getTreeInfoFirstGroupEntry(ti);
4914 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4916 if (node_cursor->node_group)
4920 node_cursor->cl_first = ti->cl_first;
4921 node_cursor->cl_cursor = ti->cl_cursor;
4922 *ti_ptr = node_cursor->node_group;
4923 DrawChooseTree(ti_ptr);
4925 else if (node_cursor->parent_link)
4929 *ti_ptr = node_cursor->node_parent;
4930 DrawChooseTree(ti_ptr);
4936 node_cursor->cl_first = ti->cl_first;
4937 node_cursor->cl_cursor = ti->cl_cursor;
4938 *ti_ptr = node_cursor;
4940 if (ti->type == TREE_TYPE_LEVEL_DIR)
4942 LoadLevelSetup_SeriesInfo();
4944 SaveLevelSetup_LastSeries();
4945 SaveLevelSetup_SeriesInfo();
4949 if (game_status == GAME_MODE_SETUP)
4951 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4952 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4953 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4955 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4956 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4957 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4958 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4959 execSetupGraphics();
4960 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4961 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4962 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4964 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4965 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4966 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4967 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4968 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4969 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4970 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4971 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4978 if (game_status == GAME_MODE_LEVELNR)
4980 int new_level_nr = atoi(level_number_current->identifier);
4982 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4984 else if (game_status == GAME_MODE_LEVELS)
4986 // store level set if chosen from "last played level set" menu
4987 StoreLastPlayedLevels(leveldir_current);
4989 else if (game_status == GAME_MODE_NAMES)
4991 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4993 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5000 // change active user to selected user
5001 user.nr = entry_pos;
5003 // save number of new active user
5006 // load setup of new active user
5009 // load last level set of new active user
5010 LoadLevelSetup_LastSeries();
5011 LoadLevelSetup_SeriesInfo();
5013 // update list of last played level sets
5014 UpdateLastPlayedLevels_TreeInfo();
5018 ToggleFullscreenIfNeeded();
5019 ChangeWindowScalingIfNeeded();
5021 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5022 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5023 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5026 SetGameStatus(GAME_MODE_MAIN);
5035 void DrawChoosePlayerName(void)
5039 FadeMenuSoundsAndMusic();
5041 if (player_name != NULL)
5043 freeTreeInfo(player_name);
5048 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5050 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5051 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5054 ti->node_top = &player_name;
5055 ti->sort_priority = 10000 + value;
5056 ti->color = getPlayerNameColor(global.user_names[i]);
5058 snprintf(identifier, sizeof(identifier), "%d", value);
5059 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5061 setString(&ti->identifier, identifier);
5062 setString(&ti->name, name);
5063 setString(&ti->name_sorting, name);
5065 pushTreeInfo(&player_name, ti);
5068 // sort player entries by player number
5069 sortTreeInfo(&player_name);
5071 // set current player entry to selected player entry
5072 player_name_current =
5073 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5075 // if that fails, set current player name to first available name
5076 if (player_name_current == NULL)
5077 player_name_current = player_name;
5079 DrawChooseTree(&player_name_current);
5081 PlayMenuSoundsAndMusic();
5084 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5086 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5089 void DrawChooseLevelSet(void)
5091 FadeMenuSoundsAndMusic();
5093 DrawChooseTree(&leveldir_current);
5095 PlayMenuSoundsAndMusic();
5098 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5100 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5103 void DrawChooseLevelNr(void)
5107 FadeMenuSoundsAndMusic();
5109 if (level_number != NULL)
5111 freeTreeInfo(level_number);
5113 level_number = NULL;
5116 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5118 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5119 char identifier[32], name[64];
5122 // temporarily load level info to get level name
5123 LoadLevelInfoOnly(i);
5125 ti->node_top = &level_number;
5126 ti->sort_priority = 10000 + value;
5127 ti->color = (level.no_level_file ? FC_BLUE :
5128 LevelStats_getSolved(i) ? FC_GREEN :
5129 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5131 snprintf(identifier, sizeof(identifier), "%d", value);
5132 snprintf(name, sizeof(name), "%03d: %s", value,
5133 (level.no_level_file ? "(no file)" : level.name));
5135 setString(&ti->identifier, identifier);
5136 setString(&ti->name, name);
5137 setString(&ti->name_sorting, name);
5139 pushTreeInfo(&level_number, ti);
5142 // sort level number values to start with lowest level number
5143 sortTreeInfo(&level_number);
5145 // set current level number to current level number
5146 level_number_current =
5147 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5149 // if that also fails, set current level number to first available level
5150 if (level_number_current == NULL)
5151 level_number_current = level_number;
5153 DrawChooseTree(&level_number_current);
5155 PlayMenuSoundsAndMusic();
5158 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5160 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5163 void DrawHallOfFame(int level_nr)
5165 int fade_mask = REDRAW_FIELD;
5168 fade_mask = REDRAW_ALL;
5171 FadeMenuSoundsAndMusic();
5173 // (this is needed when called from GameEnd() after winning a game)
5174 KeyboardAutoRepeatOn();
5176 // (this is needed when called from GameEnd() after winning a game)
5177 SetDrawDeactivationMask(REDRAW_NONE);
5178 SetDrawBackgroundMask(REDRAW_FIELD);
5180 LoadLocalAndServerScore(level_nr, TRUE);
5182 if (scores.last_added >= 0)
5183 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5185 FadeSetEnterScreen();
5189 // needed if different viewport properties defined for scores
5190 ChangeViewportPropertiesIfNeeded();
5192 PlayMenuSoundsAndMusic();
5194 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5196 HandleHallOfFame(level_nr, 0, 0, 0, MB_MENU_INITIALIZE);
5198 DrawMaskedBorder(fade_mask);
5203 static int getHallOfFameFirstEntry(int first_entry, int step)
5206 first_entry = scores.last_added - (NUM_MENU_ENTRIES_ON_SCREEN + 1) / 2 + 1;
5208 first_entry += step;
5210 if (first_entry < 0)
5212 else if (first_entry > MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN)
5213 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
5218 static char *getHallOfFameScoreText(int nr)
5220 if (!level.rate_time_over_score)
5221 return int2str(scores.entry[nr].score, 5); // show normal score
5223 if (level.use_step_counter)
5224 return int2str(scores.entry[nr].time, 5); // show number of steps
5226 static char score_text[10];
5227 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5228 int mm = (time_seconds / 60) % 60;
5229 int ss = (time_seconds % 60);
5231 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5236 static void drawHallOfFameList(int level_nr, int first_entry)
5240 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5243 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
5244 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
5245 "HighScores of Level %d", level_nr);
5247 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5249 int entry = first_entry + i;
5250 boolean active = (entry == scores.last_added);
5251 boolean forced = (scores.force_last_added && active);
5252 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
5253 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
5254 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
5255 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
5256 int dxoff = getFontDrawOffsetX(font_nr1);
5257 int dx1 = 3 * getFontWidth(font_nr1);
5258 int dx2 = dx1 + getFontWidth(font_nr1);
5259 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
5260 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
5261 int sy = mSY + 64 + i * 32;
5262 char *pos_text = (forced ? "???" : int2str(entry + 1, 3));
5264 DrawText(mSX, sy, pos_text, font_nr1);
5265 DrawText(mSX + dx1, sy, ".", font_nr1);
5267 for (j = 0; j < num_dots; j++)
5268 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
5270 if (!strEqual(scores.entry[entry].name, EMPTY_PLAYER_NAME))
5271 DrawText(mSX + dx2, sy, scores.entry[entry].name, font_nr2);
5273 DrawText(mSX + dx3, sy, getHallOfFameScoreText(entry), font_nr4);
5276 redraw_mask |= REDRAW_FIELD;
5279 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5281 static int level_nr = 0;
5282 static int first_entry = 0;
5283 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5285 if (button == MB_MENU_INITIALIZE)
5289 if (server_scores.updated)
5291 // reload scores, using updated server score cache file
5292 LoadLocalAndServerScore(level_nr, FALSE);
5294 server_scores.updated = FALSE;
5297 first_entry = getHallOfFameFirstEntry(0, 0);
5299 drawHallOfFameList(level_nr, first_entry);
5304 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
5305 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
5309 first_entry = getHallOfFameFirstEntry(first_entry, -step);
5311 drawHallOfFameList(level_nr, first_entry);
5315 first_entry = getHallOfFameFirstEntry(first_entry, step);
5317 drawHallOfFameList(level_nr, first_entry);
5319 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5321 PlaySound(SND_MENU_ITEM_SELECTING);
5323 FadeSound(SND_BACKGROUND_SCORES);
5325 if (button == MB_MENU_CHOICE &&
5326 game_status_last_screen == GAME_MODE_PLAYING &&
5327 setup.auto_play_next_level && setup.increment_levels &&
5328 level_nr < leveldir_current->last_level &&
5331 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
5335 SetGameStatus(GAME_MODE_MAIN);
5340 else if (server_scores.updated)
5342 // reload scores, using updated server score cache file
5343 LoadLocalAndServerScore(level_nr, FALSE);
5345 server_scores.updated = FALSE;
5347 first_entry = getHallOfFameFirstEntry(0, 0);
5349 drawHallOfFameList(level_nr, first_entry);
5352 if (game_status == GAME_MODE_SCORES)
5353 PlayMenuSoundIfLoop();
5357 // ============================================================================
5358 // setup screen functions
5359 // ============================================================================
5361 static struct TokenInfo *setup_info;
5362 static int num_setup_info; // number of setup entries shown on screen
5363 static int max_setup_info; // total number of setup entries in list
5365 static char *window_size_text;
5366 static char *scaling_type_text;
5367 static char *rendering_mode_text;
5368 static char *vsync_mode_text;
5369 static char *scroll_delay_text;
5370 static char *snapshot_mode_text;
5371 static char *game_speed_text;
5372 static char *network_server_text;
5373 static char *graphics_set_name;
5374 static char *sounds_set_name;
5375 static char *music_set_name;
5376 static char *volume_simple_text;
5377 static char *volume_loops_text;
5378 static char *volume_music_text;
5379 static char *touch_controls_text;
5380 static char *move_distance_text;
5381 static char *drop_distance_text;
5382 static char *transparency_text;
5383 static char *grid_size_text[2][2];
5385 static void execSetupMain(void)
5387 setup_mode = SETUP_MODE_MAIN;
5392 static void execSetupGame_setGameSpeeds(boolean update_value)
5394 if (setup.game_speed_extended)
5396 game_speeds_list = game_speeds_list_extended;
5397 game_speeds = game_speeds_extended;
5401 game_speeds_list = game_speeds_list_normal;
5402 game_speeds = game_speeds_normal;
5405 if (game_speeds == NULL)
5409 for (i = 0; game_speeds_list[i].value != -1; i++)
5411 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5412 char identifier[32], name[32];
5413 int value = game_speeds_list[i].value;
5414 char *text = game_speeds_list[i].text;
5416 ti->node_top = &game_speeds;
5417 ti->sort_priority = 10000 - value;
5419 sprintf(identifier, "%d", value);
5420 sprintf(name, "%s", text);
5422 setString(&ti->identifier, identifier);
5423 setString(&ti->name, name);
5424 setString(&ti->name_sorting, name);
5425 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5427 pushTreeInfo(&game_speeds, ti);
5430 // sort game speed values to start with slowest game speed
5431 sortTreeInfo(&game_speeds);
5433 update_value = TRUE;
5438 // set current game speed to configured game speed value
5439 game_speed_current =
5440 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5442 // if that fails, set current game speed to reliable default value
5443 if (game_speed_current == NULL)
5444 game_speed_current =
5445 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5447 // if that also fails, set current game speed to first available speed
5448 if (game_speed_current == NULL)
5449 game_speed_current = game_speeds;
5451 if (setup.game_speed_extended)
5452 game_speeds_extended = game_speeds;
5454 game_speeds_normal = game_speeds;
5457 setup.game_frame_delay = atoi(game_speed_current->identifier);
5459 // needed for displaying game speed text instead of identifier
5460 game_speed_text = game_speed_current->name;
5463 static void execSetupGame_setScrollDelays(void)
5465 if (scroll_delays == NULL)
5469 for (i = 0; scroll_delays_list[i].value != -1; i++)
5471 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5472 char identifier[32], name[32];
5473 int value = scroll_delays_list[i].value;
5474 char *text = scroll_delays_list[i].text;
5476 ti->node_top = &scroll_delays;
5477 ti->sort_priority = value;
5479 sprintf(identifier, "%d", value);
5480 sprintf(name, "%s", text);
5482 setString(&ti->identifier, identifier);
5483 setString(&ti->name, name);
5484 setString(&ti->name_sorting, name);
5485 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5487 pushTreeInfo(&scroll_delays, ti);
5490 // sort scroll delay values to start with lowest scroll delay value
5491 sortTreeInfo(&scroll_delays);
5493 // set current scroll delay value to configured scroll delay value
5494 scroll_delay_current =
5495 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5497 // if that fails, set current scroll delay to reliable default value
5498 if (scroll_delay_current == NULL)
5499 scroll_delay_current =
5500 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5502 // if that also fails, set current scroll delay to first available value
5503 if (scroll_delay_current == NULL)
5504 scroll_delay_current = scroll_delays;
5507 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5509 // needed for displaying scroll delay text instead of identifier
5510 scroll_delay_text = scroll_delay_current->name;
5513 static void execSetupGame_setSnapshotModes(void)
5515 if (snapshot_modes == NULL)
5519 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5521 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5522 char identifier[32], name[32];
5523 char *value = snapshot_modes_list[i].value;
5524 char *text = snapshot_modes_list[i].text;
5526 ti->node_top = &snapshot_modes;
5527 ti->sort_priority = i;
5529 sprintf(identifier, "%s", value);
5530 sprintf(name, "%s", text);
5532 setString(&ti->identifier, identifier);
5533 setString(&ti->name, name);
5534 setString(&ti->name_sorting, name);
5535 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5537 pushTreeInfo(&snapshot_modes, ti);
5540 // sort snapshot mode values to start with lowest snapshot mode value
5541 sortTreeInfo(&snapshot_modes);
5543 // set current snapshot mode value to configured snapshot mode value
5544 snapshot_mode_current =
5545 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5547 // if that fails, set current snapshot mode to reliable default value
5548 if (snapshot_mode_current == NULL)
5549 snapshot_mode_current =
5550 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5552 // if that also fails, set current snapshot mode to first available value
5553 if (snapshot_mode_current == NULL)
5554 snapshot_mode_current = snapshot_modes;
5557 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5559 // needed for displaying snapshot mode text instead of identifier
5560 snapshot_mode_text = snapshot_mode_current->name;
5563 static void execSetupGame_setNetworkServerText(void)
5565 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5567 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5571 strncpy(network_server_hostname, setup.network_server_hostname,
5572 MAX_SETUP_TEXT_INPUT_LEN);
5573 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5576 // needed for displaying network server text instead of identifier
5577 network_server_text = network_server_hostname;
5580 static void execSetupGame(void)
5582 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5584 execSetupGame_setGameSpeeds(FALSE);
5585 execSetupGame_setScrollDelays();
5586 execSetupGame_setSnapshotModes();
5588 execSetupGame_setNetworkServerText();
5590 if (!setup.provide_uploading_tapes)
5591 setHideSetupEntry(execOfferUploadTapes);
5593 setup_mode = SETUP_MODE_GAME;
5597 // check if vsync needs to be disabled for this game speed to work
5598 if (check_vsync_mode)
5599 DisableVsyncIfNeeded();
5602 static void execSetupChooseGameSpeed(void)
5604 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5609 static void execSetupChooseScrollDelay(void)
5611 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5616 static void execSetupChooseSnapshotMode(void)
5618 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5623 static void execSetupEngines(void)
5625 setup_mode = SETUP_MODE_ENGINES;
5630 static void execSetupEditor(void)
5632 setup_mode = SETUP_MODE_EDITOR;
5637 static void execSetupGraphics_setWindowSizes(boolean update_list)
5639 if (window_sizes != NULL && update_list)
5641 freeTreeInfo(window_sizes);
5643 window_sizes = NULL;
5646 if (window_sizes == NULL)
5648 boolean current_window_size_found = FALSE;
5651 for (i = 0; window_sizes_list[i].value != -1; i++)
5653 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5654 char identifier[32], name[32];
5655 int value = window_sizes_list[i].value;
5656 char *text = window_sizes_list[i].text;
5658 ti->node_top = &window_sizes;
5659 ti->sort_priority = value;
5661 sprintf(identifier, "%d", value);
5662 sprintf(name, "%s", text);
5664 setString(&ti->identifier, identifier);
5665 setString(&ti->name, name);
5666 setString(&ti->name_sorting, name);
5667 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5669 pushTreeInfo(&window_sizes, ti);
5671 if (value == setup.window_scaling_percent)
5672 current_window_size_found = TRUE;
5675 if (!current_window_size_found)
5677 // add entry for non-preset window scaling value
5679 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5680 char identifier[32], name[32];
5681 int value = setup.window_scaling_percent;
5683 ti->node_top = &window_sizes;
5684 ti->sort_priority = value;
5686 sprintf(identifier, "%d", value);
5687 sprintf(name, "%d %% (Current)", value);
5689 setString(&ti->identifier, identifier);
5690 setString(&ti->name, name);
5691 setString(&ti->name_sorting, name);
5692 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5694 pushTreeInfo(&window_sizes, ti);
5697 // sort window size values to start with lowest window size value
5698 sortTreeInfo(&window_sizes);
5700 // set current window size value to configured window size value
5701 window_size_current =
5702 getTreeInfoFromIdentifier(window_sizes,
5703 i_to_a(setup.window_scaling_percent));
5705 // if that fails, set current window size to reliable default value
5706 if (window_size_current == NULL)
5707 window_size_current =
5708 getTreeInfoFromIdentifier(window_sizes,
5709 i_to_a(STD_WINDOW_SCALING_PERCENT));
5711 // if that also fails, set current window size to first available value
5712 if (window_size_current == NULL)
5713 window_size_current = window_sizes;
5716 setup.window_scaling_percent = atoi(window_size_current->identifier);
5718 // needed for displaying window size text instead of identifier
5719 window_size_text = window_size_current->name;
5722 static void execSetupGraphics_setScalingTypes(void)
5724 if (scaling_types == NULL)
5728 for (i = 0; scaling_types_list[i].value != NULL; i++)
5730 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5731 char identifier[32], name[32];
5732 char *value = scaling_types_list[i].value;
5733 char *text = scaling_types_list[i].text;
5735 ti->node_top = &scaling_types;
5736 ti->sort_priority = i;
5738 sprintf(identifier, "%s", value);
5739 sprintf(name, "%s", text);
5741 setString(&ti->identifier, identifier);
5742 setString(&ti->name, name);
5743 setString(&ti->name_sorting, name);
5744 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5746 pushTreeInfo(&scaling_types, ti);
5749 // sort scaling type values to start with lowest scaling type value
5750 sortTreeInfo(&scaling_types);
5752 // set current scaling type value to configured scaling type value
5753 scaling_type_current =
5754 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5756 // if that fails, set current scaling type to reliable default value
5757 if (scaling_type_current == NULL)
5758 scaling_type_current =
5759 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5761 // if that also fails, set current scaling type to first available value
5762 if (scaling_type_current == NULL)
5763 scaling_type_current = scaling_types;
5766 setup.window_scaling_quality = scaling_type_current->identifier;
5768 // needed for displaying scaling type text instead of identifier
5769 scaling_type_text = scaling_type_current->name;
5772 static void execSetupGraphics_setRenderingModes(void)
5774 if (rendering_modes == NULL)
5778 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5780 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5781 char identifier[32], name[32];
5782 char *value = rendering_modes_list[i].value;
5783 char *text = rendering_modes_list[i].text;
5785 ti->node_top = &rendering_modes;
5786 ti->sort_priority = i;
5788 sprintf(identifier, "%s", value);
5789 sprintf(name, "%s", text);
5791 setString(&ti->identifier, identifier);
5792 setString(&ti->name, name);
5793 setString(&ti->name_sorting, name);
5794 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5796 pushTreeInfo(&rendering_modes, ti);
5799 // sort rendering mode values to start with lowest rendering mode value
5800 sortTreeInfo(&rendering_modes);
5802 // set current rendering mode value to configured rendering mode value
5803 rendering_mode_current =
5804 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5806 // if that fails, set current rendering mode to reliable default value
5807 if (rendering_mode_current == NULL)
5808 rendering_mode_current =
5809 getTreeInfoFromIdentifier(rendering_modes,
5810 STR_SPECIAL_RENDERING_DEFAULT);
5812 // if that also fails, set current rendering mode to first available one
5813 if (rendering_mode_current == NULL)
5814 rendering_mode_current = rendering_modes;
5817 setup.screen_rendering_mode = rendering_mode_current->identifier;
5819 // needed for displaying rendering mode text instead of identifier
5820 rendering_mode_text = rendering_mode_current->name;
5823 static void execSetupGraphics_setVsyncModes(boolean update_value)
5825 if (vsync_modes == NULL)
5829 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5831 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5832 char identifier[32], name[32];
5833 char *value = vsync_modes_list[i].value;
5834 char *text = vsync_modes_list[i].text;
5836 ti->node_top = &vsync_modes;
5837 ti->sort_priority = i;
5839 sprintf(identifier, "%s", value);
5840 sprintf(name, "%s", text);
5842 setString(&ti->identifier, identifier);
5843 setString(&ti->name, name);
5844 setString(&ti->name_sorting, name);
5845 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5847 pushTreeInfo(&vsync_modes, ti);
5850 // sort vsync mode values to start with lowest vsync mode value
5851 sortTreeInfo(&vsync_modes);
5853 update_value = TRUE;
5858 // set current vsync mode value to configured vsync mode value
5859 vsync_mode_current =
5860 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5862 // if that fails, set current vsync mode to reliable default value
5863 if (vsync_mode_current == NULL)
5864 vsync_mode_current =
5865 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5867 // if that also fails, set current vsync mode to first available one
5868 if (vsync_mode_current == NULL)
5869 vsync_mode_current = vsync_modes;
5872 setup.vsync_mode = vsync_mode_current->identifier;
5874 // needed for displaying vsync mode text instead of identifier
5875 vsync_mode_text = vsync_mode_current->name;
5878 static void execSetupGraphics(void)
5880 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5882 // update "setup.window_scaling_percent" from list selection
5883 // (in this case, window scaling was changed on setup screen)
5884 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5885 execSetupGraphics_setWindowSizes(FALSE);
5887 // update "setup.vsync_mode" from list selection
5888 // (in this case, vsync mode was changed on setup screen)
5889 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5890 execSetupGraphics_setVsyncModes(FALSE);
5892 // update list selection from "setup.window_scaling_percent"
5893 // (window scaling may have changed by resizing the window)
5894 execSetupGraphics_setWindowSizes(TRUE);
5896 // update list selection from "setup.vsync_mode"
5897 // (vsync_mode may have changed by re-creating the renderer)
5898 execSetupGraphics_setVsyncModes(TRUE);
5900 execSetupGraphics_setScalingTypes();
5901 execSetupGraphics_setRenderingModes();
5903 setup_mode = SETUP_MODE_GRAPHICS;
5907 // check if game speed is high enough for 60 Hz vsync to work
5908 if (check_game_speed)
5909 ModifyGameSpeedIfNeeded();
5911 // window scaling may have changed at this point
5912 ChangeWindowScalingIfNeeded();
5914 // window scaling quality may have changed at this point
5915 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5916 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5918 // screen rendering mode may have changed at this point
5919 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5921 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
5922 int video_vsync_mode = video.vsync_mode;
5924 // screen vsync mode may have changed at this point
5925 ChangeVsyncModeIfNeeded();
5927 // check if setting vsync mode to selected value failed
5928 if (setup_vsync_mode != video_vsync_mode &&
5929 setup_vsync_mode != video.vsync_mode)
5931 // changing vsync mode to selected value failed -- reset displayed value
5932 execSetupGraphics_setVsyncModes(TRUE);
5934 Request("Setting VSync failed!", REQ_CONFIRM);
5940 static void execSetupChooseWindowSize(void)
5942 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5947 static void execSetupChooseScalingType(void)
5949 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5954 static void execSetupChooseRenderingMode(void)
5956 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5961 static void execSetupChooseVsyncMode(void)
5963 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5968 static void execSetupChooseVolumeSimple(void)
5970 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5975 static void execSetupChooseVolumeLoops(void)
5977 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5982 static void execSetupChooseVolumeMusic(void)
5984 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5989 static void execSetupSound(void)
5991 if (volumes_simple == NULL)
5993 boolean current_volume_simple_found = FALSE;
5996 for (i = 0; volumes_list[i].value != -1; i++)
5998 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5999 char identifier[32], name[32];
6000 int value = volumes_list[i].value;
6001 char *text = volumes_list[i].text;
6003 ti->node_top = &volumes_simple;
6004 ti->sort_priority = value;
6006 sprintf(identifier, "%d", value);
6007 sprintf(name, "%s", text);
6009 setString(&ti->identifier, identifier);
6010 setString(&ti->name, name);
6011 setString(&ti->name_sorting, name);
6012 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6014 pushTreeInfo(&volumes_simple, ti);
6016 if (value == setup.volume_simple)
6017 current_volume_simple_found = TRUE;
6020 if (!current_volume_simple_found)
6022 // add entry for non-preset volume value
6024 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6025 char identifier[32], name[32];
6026 int value = setup.volume_simple;
6028 ti->node_top = &volumes_simple;
6029 ti->sort_priority = value;
6031 sprintf(identifier, "%d", value);
6032 sprintf(name, "%d %% (Current)", value);
6034 setString(&ti->identifier, identifier);
6035 setString(&ti->name, name);
6036 setString(&ti->name_sorting, name);
6037 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6039 pushTreeInfo(&volumes_simple, ti);
6042 // sort volume values to start with lowest volume value
6043 sortTreeInfo(&volumes_simple);
6045 // set current volume value to configured volume value
6046 volume_simple_current =
6047 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6049 // if that fails, set current volume to reliable default value
6050 if (volume_simple_current == NULL)
6051 volume_simple_current =
6052 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6054 // if that also fails, set current volume to first available value
6055 if (volume_simple_current == NULL)
6056 volume_simple_current = volumes_simple;
6059 if (volumes_loops == NULL)
6061 boolean current_volume_loops_found = FALSE;
6064 for (i = 0; volumes_list[i].value != -1; i++)
6066 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6067 char identifier[32], name[32];
6068 int value = volumes_list[i].value;
6069 char *text = volumes_list[i].text;
6071 ti->node_top = &volumes_loops;
6072 ti->sort_priority = value;
6074 sprintf(identifier, "%d", value);
6075 sprintf(name, "%s", text);
6077 setString(&ti->identifier, identifier);
6078 setString(&ti->name, name);
6079 setString(&ti->name_sorting, name);
6080 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6082 pushTreeInfo(&volumes_loops, ti);
6084 if (value == setup.volume_loops)
6085 current_volume_loops_found = TRUE;
6088 if (!current_volume_loops_found)
6090 // add entry for non-preset volume value
6092 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6093 char identifier[32], name[32];
6094 int value = setup.volume_loops;
6096 ti->node_top = &volumes_loops;
6097 ti->sort_priority = value;
6099 sprintf(identifier, "%d", value);
6100 sprintf(name, "%d %% (Current)", value);
6102 setString(&ti->identifier, identifier);
6103 setString(&ti->name, name);
6104 setString(&ti->name_sorting, name);
6105 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6107 pushTreeInfo(&volumes_loops, ti);
6110 // sort volume values to start with lowest volume value
6111 sortTreeInfo(&volumes_loops);
6113 // set current volume value to configured volume value
6114 volume_loops_current =
6115 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6117 // if that fails, set current volume to reliable default value
6118 if (volume_loops_current == NULL)
6119 volume_loops_current =
6120 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6122 // if that also fails, set current volume to first available value
6123 if (volume_loops_current == NULL)
6124 volume_loops_current = volumes_loops;
6127 if (volumes_music == NULL)
6129 boolean current_volume_music_found = FALSE;
6132 for (i = 0; volumes_list[i].value != -1; i++)
6134 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6135 char identifier[32], name[32];
6136 int value = volumes_list[i].value;
6137 char *text = volumes_list[i].text;
6139 ti->node_top = &volumes_music;
6140 ti->sort_priority = value;
6142 sprintf(identifier, "%d", value);
6143 sprintf(name, "%s", text);
6145 setString(&ti->identifier, identifier);
6146 setString(&ti->name, name);
6147 setString(&ti->name_sorting, name);
6148 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6150 pushTreeInfo(&volumes_music, ti);
6152 if (value == setup.volume_music)
6153 current_volume_music_found = TRUE;
6156 if (!current_volume_music_found)
6158 // add entry for non-preset volume value
6160 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6161 char identifier[32], name[32];
6162 int value = setup.volume_music;
6164 ti->node_top = &volumes_music;
6165 ti->sort_priority = value;
6167 sprintf(identifier, "%d", value);
6168 sprintf(name, "%d %% (Current)", value);
6170 setString(&ti->identifier, identifier);
6171 setString(&ti->name, name);
6172 setString(&ti->name_sorting, name);
6173 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6175 pushTreeInfo(&volumes_music, ti);
6178 // sort volume values to start with lowest volume value
6179 sortTreeInfo(&volumes_music);
6181 // set current volume value to configured volume value
6182 volume_music_current =
6183 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6185 // if that fails, set current volume to reliable default value
6186 if (volume_music_current == NULL)
6187 volume_music_current =
6188 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6190 // if that also fails, set current volume to first available value
6191 if (volume_music_current == NULL)
6192 volume_music_current = volumes_music;
6195 setup.volume_simple = atoi(volume_simple_current->identifier);
6196 setup.volume_loops = atoi(volume_loops_current->identifier);
6197 setup.volume_music = atoi(volume_music_current->identifier);
6199 // needed for displaying volume text instead of identifier
6200 volume_simple_text = volume_simple_current->name;
6201 volume_loops_text = volume_loops_current->name;
6202 volume_music_text = volume_music_current->name;
6204 setup_mode = SETUP_MODE_SOUND;
6209 static void execSetupChooseTouchControls(void)
6211 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6216 static void execSetupChooseMoveDistance(void)
6218 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6223 static void execSetupChooseDropDistance(void)
6225 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6230 static void execSetupChooseTransparency(void)
6232 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6237 static void execSetupChooseGridXSize_0(void)
6239 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6244 static void execSetupChooseGridYSize_0(void)
6246 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6251 static void execSetupChooseGridXSize_1(void)
6253 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6258 static void execSetupChooseGridYSize_1(void)
6260 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6265 static void execSetupConfigureVirtualButtons(void)
6267 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6269 ConfigureVirtualButtons();
6271 setup_mode = SETUP_MODE_TOUCH;
6276 static void execSetupTouch(void)
6280 if (touch_controls == NULL)
6282 for (i = 0; touch_controls_list[i].value != NULL; i++)
6284 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6285 char identifier[32], name[32];
6286 char *value = touch_controls_list[i].value;
6287 char *text = touch_controls_list[i].text;
6289 ti->node_top = &touch_controls;
6290 ti->sort_priority = i;
6292 sprintf(identifier, "%s", value);
6293 sprintf(name, "%s", text);
6295 setString(&ti->identifier, identifier);
6296 setString(&ti->name, name);
6297 setString(&ti->name_sorting, name);
6298 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6300 pushTreeInfo(&touch_controls, ti);
6303 // sort touch control values to start with lowest touch control value
6304 sortTreeInfo(&touch_controls);
6306 // set current touch control value to configured touch control value
6307 touch_control_current =
6308 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6310 // if that fails, set current touch control to reliable default value
6311 if (touch_control_current == NULL)
6312 touch_control_current =
6313 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6315 // if that also fails, set current touch control to first available value
6316 if (touch_control_current == NULL)
6317 touch_control_current = touch_controls;
6320 if (move_distances == NULL)
6322 for (i = 0; distances_list[i].value != -1; i++)
6324 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6325 char identifier[32], name[32];
6326 int value = distances_list[i].value;
6327 char *text = distances_list[i].text;
6329 ti->node_top = &move_distances;
6330 ti->sort_priority = value;
6332 sprintf(identifier, "%d", value);
6333 sprintf(name, "%s", text);
6335 setString(&ti->identifier, identifier);
6336 setString(&ti->name, name);
6337 setString(&ti->name_sorting, name);
6338 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6340 pushTreeInfo(&move_distances, ti);
6343 // sort distance values to start with lowest distance value
6344 sortTreeInfo(&move_distances);
6346 // set current distance value to configured distance value
6347 move_distance_current =
6348 getTreeInfoFromIdentifier(move_distances,
6349 i_to_a(setup.touch.move_distance));
6351 // if that fails, set current distance to reliable default value
6352 if (move_distance_current == NULL)
6353 move_distance_current =
6354 getTreeInfoFromIdentifier(move_distances,
6355 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6357 // if that also fails, set current distance to first available value
6358 if (move_distance_current == NULL)
6359 move_distance_current = move_distances;
6362 if (drop_distances == NULL)
6364 for (i = 0; distances_list[i].value != -1; i++)
6366 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6367 char identifier[32], name[32];
6368 int value = distances_list[i].value;
6369 char *text = distances_list[i].text;
6371 ti->node_top = &drop_distances;
6372 ti->sort_priority = value;
6374 sprintf(identifier, "%d", value);
6375 sprintf(name, "%s", text);
6377 setString(&ti->identifier, identifier);
6378 setString(&ti->name, name);
6379 setString(&ti->name_sorting, name);
6380 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6382 pushTreeInfo(&drop_distances, ti);
6385 // sort distance values to start with lowest distance value
6386 sortTreeInfo(&drop_distances);
6388 // set current distance value to configured distance value
6389 drop_distance_current =
6390 getTreeInfoFromIdentifier(drop_distances,
6391 i_to_a(setup.touch.drop_distance));
6393 // if that fails, set current distance to reliable default value
6394 if (drop_distance_current == NULL)
6395 drop_distance_current =
6396 getTreeInfoFromIdentifier(drop_distances,
6397 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6399 // if that also fails, set current distance to first available value
6400 if (drop_distance_current == NULL)
6401 drop_distance_current = drop_distances;
6404 if (transparencies == NULL)
6406 for (i = 0; transparencies_list[i].value != -1; i++)
6408 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6409 char identifier[32], name[32];
6410 int value = transparencies_list[i].value;
6411 char *text = transparencies_list[i].text;
6413 ti->node_top = &transparencies;
6414 ti->sort_priority = value;
6416 sprintf(identifier, "%d", value);
6417 sprintf(name, "%s", text);
6419 setString(&ti->identifier, identifier);
6420 setString(&ti->name, name);
6421 setString(&ti->name_sorting, name);
6422 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6424 pushTreeInfo(&transparencies, ti);
6427 // sort transparency values to start with lowest transparency value
6428 sortTreeInfo(&transparencies);
6430 // set current transparency value to configured transparency value
6431 transparency_current =
6432 getTreeInfoFromIdentifier(transparencies,
6433 i_to_a(setup.touch.transparency));
6435 // if that fails, set current transparency to reliable default value
6436 if (transparency_current == NULL)
6437 transparency_current =
6438 getTreeInfoFromIdentifier(transparencies,
6439 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6441 // if that also fails, set current transparency to first available value
6442 if (transparency_current == NULL)
6443 transparency_current = transparencies;
6446 for (i = 0; i < 2; i++)
6448 for (j = 0; j < 2; j++)
6450 if (grid_sizes[i][j] == NULL)
6452 for (k = 0; grid_sizes_list[k].value != -1; k++)
6454 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6455 char identifier[32], name[32];
6456 int value = grid_sizes_list[k].value;
6457 char *text = grid_sizes_list[k].text;
6459 ti->node_top = &grid_sizes[i][j];
6460 ti->sort_priority = value;
6462 sprintf(identifier, "%d", value);
6463 sprintf(name, "%s", text);
6465 setString(&ti->identifier, identifier);
6466 setString(&ti->name, name);
6467 setString(&ti->name_sorting, name);
6468 setString(&ti->infotext,
6471 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6472 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6474 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6475 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6477 pushTreeInfo(&grid_sizes[i][j], ti);
6480 // sort grid size values to start with lowest grid size value
6481 sortTreeInfo(&grid_sizes[i][j]);
6483 // set current grid size value to configured grid size value
6484 grid_size_current[i][j] =
6485 getTreeInfoFromIdentifier(grid_sizes[i][j],
6487 setup.touch.grid_xsize[i] :
6488 setup.touch.grid_ysize[i]));
6490 // if that fails, set current grid size to reliable default value
6491 if (grid_size_current[i][j] == NULL)
6492 grid_size_current[i][j] =
6493 getTreeInfoFromIdentifier(grid_sizes[i][j],
6495 DEFAULT_GRID_XSIZE(i) :
6496 DEFAULT_GRID_YSIZE(i)));
6498 // if that also fails, set current grid size to first available value
6499 if (grid_size_current[i][j] == NULL)
6500 grid_size_current[i][j] = grid_sizes[i][j];
6505 setup.touch.control_type = touch_control_current->identifier;
6506 setup.touch.move_distance = atoi(move_distance_current->identifier);
6507 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6508 setup.touch.transparency = atoi(transparency_current->identifier);
6510 for (i = 0; i < 2; i++)
6512 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6513 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6515 if (i == GRID_ACTIVE_NR())
6517 overlay.grid_xsize = setup.touch.grid_xsize[i];
6518 overlay.grid_ysize = setup.touch.grid_ysize[i];
6522 // needed for displaying value text instead of identifier
6523 touch_controls_text = touch_control_current->name;
6524 move_distance_text = move_distance_current->name;
6525 drop_distance_text = drop_distance_current->name;
6526 transparency_text = transparency_current->name;
6528 for (i = 0; i < 2; i++)
6529 for (j = 0; j < 2; j++)
6530 grid_size_text[i][j] = grid_size_current[i][j]->name;
6532 setup_mode = SETUP_MODE_TOUCH;
6537 static void execSetupArtwork(void)
6539 static ArtworkDirTree *gfx_last_valid = NULL;
6540 static ArtworkDirTree *snd_last_valid = NULL;
6541 static ArtworkDirTree *mus_last_valid = NULL;
6543 // current artwork directory may be invalid (level group, parent link)
6544 if (!validLevelSeries(artwork.gfx_current))
6545 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6546 if (!validLevelSeries(artwork.snd_current))
6547 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6548 if (!validLevelSeries(artwork.mus_current))
6549 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6551 // store valid artwork directory information
6552 gfx_last_valid = artwork.gfx_current;
6553 snd_last_valid = artwork.snd_current;
6554 mus_last_valid = artwork.mus_current;
6557 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6558 artwork.gfx_current->subdir,
6559 artwork.gfx_current->fullpath,
6560 artwork.gfx_current->basepath);
6563 setup.graphics_set = artwork.gfx_current->identifier;
6564 setup.sounds_set = artwork.snd_current->identifier;
6565 setup.music_set = artwork.mus_current->identifier;
6567 // needed if last screen (setup choice) changed graphics, sounds or music
6568 ReloadCustomArtwork(0);
6570 // needed for displaying artwork name instead of artwork identifier
6571 graphics_set_name = artwork.gfx_current->name;
6572 sounds_set_name = artwork.snd_current->name;
6573 music_set_name = artwork.mus_current->name;
6575 setup_mode = SETUP_MODE_ARTWORK;
6580 static void execSetupChooseGraphics(void)
6582 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6587 static void execSetupChooseSounds(void)
6589 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6594 static void execSetupChooseMusic(void)
6596 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6601 static void execSetupInput(void)
6603 setup_mode = SETUP_MODE_INPUT;
6608 static void execSetupShortcuts(void)
6610 setup_mode = SETUP_MODE_SHORTCUTS;
6615 static void execSetupShortcuts1(void)
6617 setup_mode = SETUP_MODE_SHORTCUTS_1;
6622 static void execSetupShortcuts2(void)
6624 setup_mode = SETUP_MODE_SHORTCUTS_2;
6629 static void execSetupShortcuts3(void)
6631 setup_mode = SETUP_MODE_SHORTCUTS_3;
6636 static void execSetupShortcuts4(void)
6638 setup_mode = SETUP_MODE_SHORTCUTS_4;
6643 static void execSetupShortcuts5(void)
6645 setup_mode = SETUP_MODE_SHORTCUTS_5;
6650 static void execExitSetup(void)
6652 SetGameStatus(GAME_MODE_MAIN);
6657 static void execSaveAndExitSetup(void)
6663 static void execGadgetNetworkServer(void)
6665 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6666 struct GadgetInfo *gi = screen_gadget[gadget_id];
6668 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6669 network_server_hostname[0] = '\0';
6671 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6675 ClickOnGadget(gi, MB_LEFTBUTTON);
6678 static void execOfferUploadTapes(void)
6683 static void ToggleNetworkModeIfNeeded(void)
6685 int font_title = FONT_TITLE_1;
6686 int font_foot = FC_BLUE;
6687 int ystart = mSY - SY + 16;
6688 int ybottom = mSY - SY + SYSIZE - 20;
6689 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6691 if (setup.network_mode == network.enabled)
6694 network.enabled = setup.network_mode;
6696 FadeOut(REDRAW_ALL);
6700 DrawTextSCentered(ystart, font_title, text);
6704 if (network.enabled)
6705 InitNetworkServer();
6707 DisconnectFromNetworkServer();
6709 DrawTextSCentered(ybottom, font_foot,
6710 "Press any key or button for setup menu");
6712 WaitForEventToContinue();
6717 static void ToggleGameSpeedsListIfNeeded(void)
6719 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6721 if (setup.game_speed_extended == using_game_speeds_extended)
6724 // try to match similar values when changing game speeds list
6725 if (setup.game_speed_extended)
6726 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6727 setup.game_frame_delay == 30 ? 29 :
6728 setup.game_frame_delay);
6730 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6731 setup.game_frame_delay == 16 ? 15 :
6732 setup.game_frame_delay >= 29 ? 30 :
6733 setup.game_frame_delay <= 10 ? 10 :
6734 setup.game_frame_delay);
6736 execSetupGame_setGameSpeeds(TRUE);
6741 static void ModifyGameSpeedIfNeeded(void)
6743 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6744 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6748 char *game_speed_text = "Fast";
6749 int game_speed_value = 15;
6751 if (setup.game_speed_extended)
6753 game_speed_text = "60 fps";
6754 game_speed_value = 16;
6757 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6759 // set game speed to existing list value that is fast enough for vsync
6760 setup.game_frame_delay = game_speed_value;
6762 execSetupGame_setGameSpeeds(TRUE);
6764 Request(message, REQ_CONFIRM);
6767 static void DisableVsyncIfNeeded(void)
6769 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6770 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6771 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6774 // disable vsync for the selected game speed to work
6775 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6777 execSetupGraphics_setVsyncModes(TRUE);
6779 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6785 void *related_value;
6786 } hide_related_entry_list[] =
6788 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6789 { &setup.game_frame_delay, &game_speed_text },
6791 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6792 { &setup.scroll_delay_value, &scroll_delay_text },
6794 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6795 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6797 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6798 { &setup.window_scaling_percent, &window_size_text },
6800 { &setup.window_scaling_quality, execSetupChooseScalingType },
6801 { &setup.window_scaling_quality, &scaling_type_text },
6803 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6804 { &setup.screen_rendering_mode, &rendering_mode_text },
6806 { &setup.vsync_mode, execSetupChooseVsyncMode },
6807 { &setup.vsync_mode, &vsync_mode_text },
6809 { &setup.graphics_set, execSetupChooseGraphics },
6810 { &setup.graphics_set, &graphics_set_name },
6812 { &setup.sounds_set, execSetupChooseSounds },
6813 { &setup.sounds_set, &sounds_set_name },
6815 { &setup.music_set, execSetupChooseMusic },
6816 { &setup.music_set, &music_set_name },
6818 { &setup.volume_simple, execSetupChooseVolumeSimple },
6819 { &setup.volume_simple, &volume_simple_text },
6821 { &setup.volume_loops, execSetupChooseVolumeLoops },
6822 { &setup.volume_loops, &volume_loops_text },
6824 { &setup.volume_music, execSetupChooseVolumeMusic },
6825 { &setup.volume_music, &volume_music_text },
6827 { &setup.touch.control_type, execSetupChooseTouchControls },
6828 { &setup.touch.control_type, &touch_controls_text },
6830 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6831 { &setup.touch.move_distance, &move_distance_text },
6833 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6834 { &setup.touch.drop_distance, &drop_distance_text },
6836 { &setup.touch.transparency, execSetupChooseTransparency },
6837 { &setup.touch.transparency, &transparency_text },
6839 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6840 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6842 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6843 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6845 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6846 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6848 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6849 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6851 { &setup.internal.menu_game, execSetupGame },
6852 { &setup.internal.menu_engines, execSetupEngines },
6853 { &setup.internal.menu_editor, execSetupEditor },
6854 { &setup.internal.menu_graphics, execSetupGraphics },
6855 { &setup.internal.menu_sound, execSetupSound },
6856 { &setup.internal.menu_artwork, execSetupArtwork },
6857 { &setup.internal.menu_input, execSetupInput },
6858 { &setup.internal.menu_touch, execSetupTouch },
6859 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6860 { &setup.internal.menu_exit, execExitSetup },
6861 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6866 void setHideRelatedSetupEntries(void)
6870 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6871 if (hideSetupEntry(hide_related_entry_list[i].value))
6872 setHideSetupEntry(hide_related_entry_list[i].related_value);
6875 static struct TokenInfo setup_info_main[] =
6877 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6878 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6879 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6880 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6881 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6882 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6883 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6884 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6885 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6886 { TYPE_EMPTY, NULL, "" },
6887 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6888 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6893 static struct TokenInfo setup_info_game[] =
6895 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6896 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6897 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6898 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6899 { TYPE_STRING, &network_server_text, "" },
6900 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
6901 { TYPE_SWITCH, &setup.only_show_local_scores, "Only Show Local Scores:" },
6902 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload All Tapes to Server" },
6903 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
6904 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6905 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6906 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6907 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6908 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6909 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6910 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
6911 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
6912 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6913 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
6914 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
6915 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6916 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6917 { TYPE_STRING, &game_speed_text, "" },
6918 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6920 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6921 { TYPE_STRING, &scroll_delay_text, "" },
6923 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6924 { TYPE_STRING, &snapshot_mode_text, "" },
6925 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
6926 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
6927 { TYPE_EMPTY, NULL, "" },
6928 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6933 static struct TokenInfo setup_info_engines[] =
6935 { TYPE_HEADLINE, NULL, "Emerald Mine" },
6936 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
6937 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
6938 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
6939 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
6940 { TYPE_EMPTY, NULL, "" },
6941 { TYPE_HEADLINE, NULL, "Supaplex" },
6942 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
6943 { TYPE_EMPTY, NULL, "" },
6944 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6949 static struct TokenInfo setup_info_editor[] =
6952 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6953 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6954 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6955 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6956 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6957 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6958 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6959 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6960 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6961 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6963 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6964 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6966 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6968 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6969 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6970 { TYPE_EMPTY, NULL, "" },
6972 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6973 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6974 { TYPE_EMPTY, NULL, "" },
6976 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6977 { TYPE_EMPTY, NULL, "" },
6978 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
6979 { TYPE_EMPTY, NULL, "" },
6980 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6985 static struct TokenInfo setup_info_graphics[] =
6987 #if !defined(PLATFORM_ANDROID)
6988 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6989 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6990 { TYPE_STRING, &window_size_text, "" },
6991 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6992 { TYPE_STRING, &scaling_type_text, "" },
6993 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6994 { TYPE_STRING, &rendering_mode_text, "" },
6997 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6998 { TYPE_STRING, &scroll_delay_text, "" },
7000 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7001 { TYPE_STRING, &vsync_mode_text, "" },
7002 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7003 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7004 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7005 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7006 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7007 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7008 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7009 { TYPE_EMPTY, NULL, "" },
7010 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7015 static struct TokenInfo setup_info_sound[] =
7017 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7018 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7019 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7020 { TYPE_EMPTY, NULL, "" },
7021 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7022 { TYPE_STRING, &volume_simple_text, "" },
7023 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7024 { TYPE_STRING, &volume_loops_text, "" },
7025 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7026 { TYPE_STRING, &volume_music_text, "" },
7027 { TYPE_EMPTY, NULL, "" },
7028 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7033 static struct TokenInfo setup_info_artwork[] =
7035 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7036 { TYPE_STRING, &graphics_set_name, "" },
7037 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7038 { TYPE_STRING, &sounds_set_name, "" },
7039 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7040 { TYPE_STRING, &music_set_name, "" },
7041 { TYPE_EMPTY, NULL, "" },
7042 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7043 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7044 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7045 { TYPE_EMPTY, NULL, "" },
7046 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7051 static struct TokenInfo setup_info_input[] =
7053 { TYPE_SWITCH, NULL, "Player:" },
7054 { TYPE_SWITCH, NULL, "Device:" },
7055 { TYPE_SWITCH, NULL, "" },
7056 { TYPE_SKIPPABLE, NULL, "" },
7057 { TYPE_EMPTY, NULL, "" },
7058 { TYPE_EMPTY, NULL, "" },
7059 { TYPE_EMPTY, NULL, "" },
7060 { TYPE_EMPTY, NULL, "" },
7061 { TYPE_EMPTY, NULL, "" },
7062 { TYPE_EMPTY, NULL, "" },
7063 { TYPE_EMPTY, NULL, "" },
7064 { TYPE_EMPTY, NULL, "" },
7065 { TYPE_SKIPPABLE, NULL, "" },
7066 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7071 static struct TokenInfo setup_info_touch[] =
7073 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7074 { TYPE_STRING, &touch_controls_text, "" },
7075 { TYPE_EMPTY, NULL, "" },
7076 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7081 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7083 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7084 { TYPE_STRING, &touch_controls_text, "" },
7085 { TYPE_EMPTY, NULL, "" },
7086 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7087 { TYPE_STRING, &grid_size_text[0][0], "" },
7088 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7089 { TYPE_STRING, &grid_size_text[0][1], "" },
7090 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7091 { TYPE_STRING, &transparency_text, "" },
7092 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7093 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7094 { TYPE_EMPTY, NULL, "" },
7095 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7096 { TYPE_EMPTY, NULL, "" },
7097 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7102 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7104 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7105 { TYPE_STRING, &touch_controls_text, "" },
7106 { TYPE_EMPTY, NULL, "" },
7107 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7108 { TYPE_STRING, &grid_size_text[1][0], "" },
7109 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7110 { TYPE_STRING, &grid_size_text[1][1], "" },
7111 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7112 { TYPE_STRING, &transparency_text, "" },
7113 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7114 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7115 { TYPE_EMPTY, NULL, "" },
7116 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7117 { TYPE_EMPTY, NULL, "" },
7118 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7123 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7125 setup_info_touch_virtual_buttons_0,
7126 setup_info_touch_virtual_buttons_1
7129 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7131 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7132 { TYPE_STRING, &touch_controls_text, "" },
7133 { TYPE_EMPTY, NULL, "" },
7134 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7135 { TYPE_STRING, &move_distance_text, "" },
7136 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7137 { TYPE_STRING, &drop_distance_text, "" },
7138 { TYPE_EMPTY, NULL, "" },
7139 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7144 static struct TokenInfo setup_info_shortcuts[] =
7146 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7147 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7148 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7149 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7150 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7151 { TYPE_EMPTY, NULL, "" },
7152 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7157 static struct TokenInfo setup_info_shortcuts_1[] =
7159 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7160 { TYPE_KEY, &setup.shortcut.save_game, "" },
7161 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7162 { TYPE_KEY, &setup.shortcut.load_game, "" },
7163 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7164 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7165 { TYPE_EMPTY, NULL, "" },
7166 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7167 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7168 { TYPE_EMPTY, NULL, "" },
7169 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7174 static struct TokenInfo setup_info_shortcuts_2[] =
7176 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7177 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7178 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7179 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7180 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7181 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7182 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7183 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7184 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7185 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7186 { TYPE_EMPTY, NULL, "" },
7187 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7192 static struct TokenInfo setup_info_shortcuts_3[] =
7194 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7195 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7196 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7197 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7198 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7199 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7200 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7201 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7202 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7203 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7204 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7205 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7206 { TYPE_EMPTY, NULL, "" },
7207 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7212 static struct TokenInfo setup_info_shortcuts_4[] =
7214 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7215 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7216 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7217 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7218 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7219 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7220 { TYPE_EMPTY, NULL, "" },
7221 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7226 static struct TokenInfo setup_info_shortcuts_5[] =
7228 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7229 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7230 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7231 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7232 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7233 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7234 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7235 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7236 { TYPE_EMPTY, NULL, "" },
7237 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7242 static Key getSetupKey(void)
7244 Key key = KSYM_UNDEFINED;
7245 boolean got_key_event = FALSE;
7247 while (!got_key_event)
7251 if (NextValidEvent(&event))
7255 case EVENT_KEYPRESS:
7257 key = GetEventKey((KeyEvent *)&event, TRUE);
7259 // press 'Escape' or 'Enter' to keep the existing key binding
7260 if (key == KSYM_Escape || key == KSYM_Return)
7261 key = KSYM_UNDEFINED; // keep old value
7263 got_key_event = TRUE;
7267 case EVENT_KEYRELEASE:
7268 key_joystick_mapping = 0;
7272 HandleOtherEvents(&event);
7283 static int getSetupValueFont(int type, void *value)
7285 if (type & TYPE_GHOSTED)
7286 return FONT_OPTION_OFF;
7287 else if (type & TYPE_KEY)
7288 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7289 else if (type & TYPE_STRING)
7290 return FONT_VALUE_2;
7291 else if (type & TYPE_ECS_AGA)
7292 return FONT_VALUE_1;
7293 else if (type & TYPE_BOOLEAN_STYLE)
7294 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7295 else if (type & TYPE_YES_NO_AUTO)
7296 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7297 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7298 else if (type & TYPE_PLAYER)
7299 return FONT_VALUE_1;
7301 return FONT_VALUE_1;
7304 static int getSetupValueFontNarrow(int type, int font_nr)
7306 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7307 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7308 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7312 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7314 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7315 struct TokenInfo *si = &setup_info[si_pos];
7316 boolean font_draw_xoffset_modified = FALSE;
7317 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7318 int font_draw_xoffset_old = -1;
7319 int xoffset = (scrollbar_needed ? -1 : 0);
7320 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7321 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7322 int xpos = menu_screen_value_xpos;
7323 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7324 int startx = mSX + xpos * 32;
7325 int starty = mSY + ypos * 32;
7326 int type = si->type;
7327 void *value = si->value;
7328 char *value_string = getSetupValue(type, value);
7329 int font_nr_default = getSetupValueFont(type, value);
7330 int font_width_default = getFontWidth(font_nr_default);
7331 int font_nr = font_nr_default;
7334 if (value_string == NULL)
7337 if (type & TYPE_KEY)
7339 xpos = MENU_SCREEN_START_XPOS;
7341 if (type & TYPE_QUERY)
7342 value_string = "<press key>";
7344 else if (type & TYPE_STRING)
7346 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7348 xpos = MENU_SCREEN_START_XPOS;
7350 if (strlen(value_string) > max_value_len)
7351 value_string[max_value_len] = '\0';
7353 else if (type & TYPE_YES_NO_AUTO)
7355 xpos = menu_screen_value_xpos - 1;
7357 else if (type & TYPE_PLAYER)
7359 int displayed_player_nr = *(int *)value + 1;
7361 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7364 startx = mSX + xpos * 32;
7365 starty = mSY + ypos * 32;
7367 // special check if right-side setup values moved left due to scrollbar
7368 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7370 int max_menu_text_length = 26; // maximum text length for classic menu
7371 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7372 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7373 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7374 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7375 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7377 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7379 // when using narrow font, left-shifting text "auto" not needed
7380 if (type & TYPE_YES_NO_AUTO)
7384 startx = mSX + xpos * 32;
7386 font_nr = getSetupValueFontNarrow(type, font_nr);
7390 // downward compatibility correction for Juergen Bonhagen's menu settings
7391 if (setup_mode != SETUP_MODE_INPUT)
7393 int max_menu_text_length_big = (menu_screen_value_xpos -
7394 MENU_SCREEN_START_XPOS);
7395 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7396 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7397 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7398 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
7399 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7400 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7401 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7402 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7403 boolean correct_font_draw_xoffset = FALSE;
7405 if (xpos == MENU_SCREEN_START_XPOS &&
7406 startx + font1_xoffset < text_startx + text_font_xoffset)
7407 correct_font_draw_xoffset = TRUE;
7409 if (xpos == menu_screen_value_xpos &&
7410 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7411 correct_font_draw_xoffset = TRUE;
7413 // check if setup value would overlap with setup text when printed
7414 // (this can happen for extreme/wrong values for font draw offset)
7415 if (correct_font_draw_xoffset)
7417 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
7418 font_draw_xoffset_modified = TRUE;
7420 if (type & TYPE_KEY)
7421 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7422 else if (!(type & TYPE_STRING))
7423 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7424 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7428 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7429 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7431 DrawText(startx, starty, value_string, font_nr);
7433 if (type & TYPE_PLAYER)
7435 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7436 int player_nr = *(int *)value;
7437 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7438 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7439 int startx2 = startx + xoff;
7440 int starty2 = starty + yoff;
7442 if (DrawingOnBackground(startx2, starty2))
7443 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7445 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7446 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7449 if (font_draw_xoffset_modified)
7450 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7453 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7455 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7456 struct TokenInfo *si = &setup_info[si_pos];
7458 if (si->type & TYPE_BOOLEAN_STYLE)
7460 *(boolean *)si->value ^= TRUE;
7462 else if (si->type & TYPE_YES_NO_AUTO)
7466 (*(int *)si->value == AUTO ? TRUE :
7467 *(int *)si->value == TRUE ? FALSE : AUTO) :
7468 (*(int *)si->value == TRUE ? AUTO :
7469 *(int *)si->value == AUTO ? FALSE : TRUE));
7471 else if (si->type & TYPE_KEY)
7475 si->type |= TYPE_QUERY;
7476 drawSetupValue(screen_pos, setup_info_pos_raw);
7477 si->type &= ~TYPE_QUERY;
7479 key = getSetupKey();
7480 if (key != KSYM_UNDEFINED)
7481 *(Key *)si->value = key;
7483 else if (si->type & TYPE_PLAYER)
7485 int player_nr = *(int *)si->value;
7490 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7492 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7495 drawSetupValue(screen_pos, setup_info_pos_raw);
7497 // fullscreen state may have changed at this point
7498 if (si->value == &setup.fullscreen)
7499 ToggleFullscreenIfNeeded();
7501 // network mode may have changed at this point
7502 if (si->value == &setup.network_mode)
7503 ToggleNetworkModeIfNeeded();
7505 // API server mode may have changed at this point
7506 if (si->value == &setup.use_api_server)
7507 runtime.use_api_server = setup.use_api_server;
7509 // game speed list may have changed at this point
7510 if (si->value == &setup.game_speed_extended)
7511 ToggleGameSpeedsListIfNeeded();
7514 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7516 static struct TokenInfo *setup_info_final = NULL;
7521 // determine maximum list size of target list
7522 while (setup_info_orig[list_size++].type != 0);
7524 // free, allocate and clear memory for target list
7525 checked_free(setup_info_final);
7526 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7528 // copy setup info list without setup entries marked as hidden
7529 for (i = 0; setup_info_orig[i].type != 0; i++)
7531 // skip setup entries configured to be hidden
7532 if (hideSetupEntry(setup_info_orig[i].value))
7535 // skip skippable setup entries if screen is lower than usual
7536 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7537 setup_info_orig[i].type == TYPE_SKIPPABLE)
7540 setup_info_final[list_pos++] = setup_info_orig[i];
7543 return setup_info_final;
7546 static void DrawSetupScreen_Generic(void)
7548 int fade_mask = REDRAW_FIELD;
7549 boolean redraw_all = FALSE;
7550 char *title_string = NULL;
7554 fade_mask = REDRAW_ALL;
7557 FadeMenuSoundsAndMusic();
7559 FreeScreenGadgets();
7560 CreateScreenGadgets();
7562 if (redraw_mask & REDRAW_ALL)
7567 // needed if different viewport properties defined for setup screen
7568 ChangeViewportPropertiesIfNeeded();
7570 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7574 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7576 if (setup_mode == SETUP_MODE_MAIN)
7578 setup_info = setup_info_main;
7579 title_string = STR_SETUP_MAIN;
7581 else if (setup_mode == SETUP_MODE_GAME)
7583 setup_info = setup_info_game;
7584 title_string = STR_SETUP_GAME;
7586 else if (setup_mode == SETUP_MODE_ENGINES)
7588 setup_info = setup_info_engines;
7589 title_string = STR_SETUP_ENGINES;
7591 else if (setup_mode == SETUP_MODE_EDITOR)
7593 setup_info = setup_info_editor;
7594 title_string = STR_SETUP_EDITOR;
7596 else if (setup_mode == SETUP_MODE_GRAPHICS)
7598 setup_info = setup_info_graphics;
7599 title_string = STR_SETUP_GRAPHICS;
7601 else if (setup_mode == SETUP_MODE_SOUND)
7603 setup_info = setup_info_sound;
7604 title_string = STR_SETUP_SOUND;
7606 else if (setup_mode == SETUP_MODE_ARTWORK)
7608 setup_info = setup_info_artwork;
7609 title_string = STR_SETUP_ARTWORK;
7611 else if (setup_mode == SETUP_MODE_TOUCH)
7613 setup_info = setup_info_touch;
7614 title_string = STR_SETUP_TOUCH;
7616 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7617 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7618 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7619 setup_info = setup_info_touch_wipe_gestures;
7621 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7623 setup_info = setup_info_shortcuts;
7624 title_string = STR_SETUP_SHORTCUTS;
7626 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7628 setup_info = setup_info_shortcuts_1;
7629 title_string = STR_SETUP_SHORTCUTS;
7631 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7633 setup_info = setup_info_shortcuts_2;
7634 title_string = STR_SETUP_SHORTCUTS;
7636 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7638 setup_info = setup_info_shortcuts_3;
7639 title_string = STR_SETUP_SHORTCUTS;
7641 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7643 setup_info = setup_info_shortcuts_4;
7644 title_string = STR_SETUP_SHORTCUTS;
7646 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7648 setup_info = setup_info_shortcuts_5;
7649 title_string = STR_SETUP_SHORTCUTS;
7652 // use modified setup info without setup entries marked as hidden
7653 setup_info = getSetupInfoFinal(setup_info);
7655 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7657 // determine maximal number of setup entries that can be displayed on screen
7659 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7662 // determine maximal number of setup entries available for this setup screen
7664 for (i = 0; setup_info[i].type != 0; i++)
7667 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7669 MapScreenGadgets(max_setup_info);
7672 redraw_mask = fade_mask = REDRAW_ALL;
7674 DrawMaskedBorder(fade_mask);
7679 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7681 menu_info = setup_info;
7683 HandleMenuScreen(mx, my, dx, dy, button,
7684 setup_mode, num_setup_info, max_setup_info);
7687 static void DrawSetupScreen_Input(void)
7691 FadeOut(REDRAW_FIELD);
7695 setup_info = getSetupInfoFinal(setup_info_input);
7697 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7699 for (i = 0; setup_info[i].type != 0; i++)
7701 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7702 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7703 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7704 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7705 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7706 initCursor(i, IMG_MENU_BUTTON);
7708 DrawCursorAndText_Setup(i, -1, FALSE);
7711 // create gadgets for setup input menu screen
7712 FreeScreenGadgets();
7713 CreateScreenGadgets();
7715 // map gadgets for setup input menu screen
7716 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7718 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7720 FadeIn(REDRAW_FIELD);
7723 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7725 if (device_name == NULL)
7728 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7731 if (strlen(device_name) > 1)
7733 char c1 = device_name[strlen(device_name) - 1];
7734 char c2 = device_name[strlen(device_name) - 2];
7736 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7737 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7740 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7741 strlen(device_name));
7744 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7747 static struct SetupKeyboardInfo custom_key;
7754 { &custom_key.left, "Axis/Pad Left" },
7755 { &custom_key.right, "Axis/Pad Right" },
7756 { &custom_key.up, "Axis/Pad Up" },
7757 { &custom_key.down, "Axis/Pad Down" },
7758 { &custom_key.snap, "Button 1/A/X" },
7759 { &custom_key.drop, "Button 2/B/Y" }
7761 static char *joystick_name[MAX_PLAYERS] =
7768 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7769 int font_nr_info = FONT_MENU_1;
7770 int font_nr_name = FONT_VALUE_OLD;
7771 int font_nr_on = FONT_VALUE_1;
7772 int font_nr_off = FONT_VALUE_OLD;
7775 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7777 font_nr_info = FONT_MENU_2;
7778 font_nr_on = FONT_VALUE_NARROW;
7779 font_nr_off = FONT_VALUE_OLD_NARROW;
7782 custom_key = setup.input[player_nr].key;
7784 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7785 FONT_INPUT_1_ACTIVE);
7787 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7789 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7790 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7792 if (setup.input[player_nr].use_joystick)
7794 char *device_name = setup.input[player_nr].joy.device_name;
7795 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7796 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7797 char *text = joystick_name[joystick_nr];
7798 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7800 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7801 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7805 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7806 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7809 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7810 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7814 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7815 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7816 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7817 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7819 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7820 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7821 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7822 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7823 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7824 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7826 for (i = 0; i < 6; i++)
7828 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7830 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7832 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7833 (setup.input[player_nr].use_joystick ?
7835 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7839 static int input_player_nr = 0;
7841 static void HandleSetupScreen_Input_Player(int step, int direction)
7843 int old_player_nr = input_player_nr;
7846 new_player_nr = old_player_nr + step * direction;
7847 if (new_player_nr < 0)
7849 if (new_player_nr > MAX_PLAYERS - 1)
7850 new_player_nr = MAX_PLAYERS - 1;
7852 if (new_player_nr != old_player_nr)
7854 input_player_nr = new_player_nr;
7856 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7860 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7862 static int choice = 0;
7865 int pos_start = SETUPINPUT_SCREEN_POS_START;
7866 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7867 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7868 int pos_end = SETUPINPUT_SCREEN_POS_END;
7870 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7874 for (i = 0; setup_info_input[i].type != 0; i++)
7876 // adjust menu structure according to skipped setup entries
7877 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7885 if (button == MB_MENU_INITIALIZE)
7887 // input setup menu may have changed size due to graphics configuration
7888 if (choice >= pos_empty1)
7891 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7893 DrawCursorAndText_Setup(choice, -1, TRUE);
7897 else if (button == MB_MENU_LEAVE)
7899 setup_mode = SETUP_MODE_MAIN;
7906 if (mx || my) // mouse input
7908 x = (mx - mSX) / 32;
7909 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7911 else if (dx || dy) // keyboard input
7913 if (dx && choice == 0)
7914 x = (dx < 0 ? 10 : 12);
7915 else if ((dx && choice == 1) ||
7916 (dx == -1 && choice == pos_end))
7917 button = MB_MENU_CHOICE;
7921 if (y >= pos_empty1 && y <= pos_empty2)
7922 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7925 if (y == 0 && dx != 0 && button)
7927 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7929 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7930 y >= pos_start && y <= pos_end &&
7931 !(y >= pos_empty1 && y <= pos_empty2))
7937 DrawCursorAndText_Setup(choice, -1, FALSE);
7938 DrawCursorAndText_Setup(y, -1, TRUE);
7940 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7949 char *device_name = setup.input[input_player_nr].joy.device_name;
7951 if (!setup.input[input_player_nr].use_joystick)
7953 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7955 setJoystickDeviceToNr(device_name, new_device_nr);
7956 setup.input[input_player_nr].use_joystick = TRUE;
7960 int device_nr = getJoystickNrFromDeviceName(device_name);
7961 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7963 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7964 setup.input[input_player_nr].use_joystick = FALSE;
7966 setJoystickDeviceToNr(device_name, new_device_nr);
7969 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7973 if (setup.input[input_player_nr].use_joystick)
7974 ConfigureJoystick(input_player_nr);
7976 CustomizeKeyboard(input_player_nr);
7978 else if (y == pos_end)
7984 setup_mode = SETUP_MODE_MAIN;
7991 static boolean CustomizeKeyboardMain(int player_nr)
7995 boolean finished = FALSE;
7996 static struct SetupKeyboardInfo custom_key;
8001 } customize_step[] =
8003 { &custom_key.left, "Move Left" },
8004 { &custom_key.right, "Move Right" },
8005 { &custom_key.up, "Move Up" },
8006 { &custom_key.down, "Move Down" },
8007 { &custom_key.snap, "Snap Field" },
8008 { &custom_key.drop, "Drop Element" }
8010 int font_nr_old = FONT_VALUE_OLD;
8011 int font_nr_new = FONT_VALUE_1;
8012 boolean success = FALSE;
8014 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8016 font_nr_old = FONT_VALUE_OLD_NARROW;
8017 font_nr_new = FONT_VALUE_NARROW;
8020 // read existing key bindings from player setup
8021 custom_key = setup.input[player_nr].key;
8024 FadeOut(REDRAW_FIELD);
8028 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8031 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8032 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8033 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8034 "Key:", FONT_INPUT_1_ACTIVE);
8035 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8036 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8038 FadeIn(REDRAW_FIELD);
8044 if (NextValidEvent(&event))
8048 case EVENT_KEYPRESS:
8050 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8052 // press 'Escape' to abort and keep the old key bindings
8053 if (key == KSYM_Escape)
8055 FadeSkipNextFadeIn();
8062 // press 'Enter' to keep the existing key binding
8063 if (key == KSYM_Return)
8064 key = *customize_step[step_nr].key;
8066 // check if key already used
8067 for (i = 0; i < step_nr; i++)
8068 if (*customize_step[i].key == key)
8073 // got new key binding
8074 *customize_step[step_nr].key = key;
8075 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8077 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8078 getKeyNameFromKey(key), font_nr_new);
8081 // un-highlight last query
8082 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8083 customize_step[step_nr - 1].text, FONT_MENU_1);
8084 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8085 "Key:", FONT_MENU_1);
8087 // all keys configured
8096 // query next key binding
8097 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8098 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8099 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8100 "Key:", FONT_INPUT_1_ACTIVE);
8101 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8102 getKeyNameFromKey(*customize_step[step_nr].key),
8107 case EVENT_KEYRELEASE:
8108 key_joystick_mapping = 0;
8112 HandleOtherEvents(&event);
8120 // write new key bindings back to player setup, if successfully finished
8122 setup.input[player_nr].key = custom_key;
8127 void CustomizeKeyboard(int player_nr)
8129 boolean success = CustomizeKeyboardMain(player_nr);
8133 int font_nr = FONT_TITLE_1;
8134 int font_height = getFontHeight(font_nr);
8135 int ypos1 = SYSIZE / 2 - font_height * 2;
8136 int ypos2 = SYSIZE / 2 - font_height * 1;
8137 unsigned int wait_frame_delay = 0;
8138 unsigned int wait_frame_delay_value = 2000;
8140 ResetDelayCounter(&wait_frame_delay);
8144 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8145 DrawTextSCentered(ypos2, font_nr, "configured!");
8147 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8153 DrawSetupScreen_Input();
8156 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8158 #define MARKER_BUTTON 1
8159 #define MARKER_AXIS_X 2
8160 #define MARKER_AXIS_Y 3
8162 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8164 static boolean bitmaps_initialized = FALSE;
8165 boolean screen_initialized = FALSE;
8166 static Bitmap *controller, *button, *axis_x, *axis_y;
8168 boolean success = TRUE;
8169 boolean done = FALSE, next = FALSE;
8171 int alpha = 200, alpha_step = -1;
8172 int alpha_ticks = 0;
8173 char mapping[4096], temp[256];
8174 int font_name = MENU_SETUP_FONT_TITLE;
8175 int font_info = MENU_SETUP_FONT_TEXT;
8176 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8177 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8178 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8179 int ystep_name = getMenuTextStep(spacing_name, font_name);
8180 int ystep_line = getMenuTextStep(spacing_line, font_info);
8181 int ystep_para = getMenuTextStep(spacing_para, font_info);
8189 int axis, button, hat, hat_value;
8192 *step, *prev_step, steps[] =
8194 { 356, 155, MARKER_BUTTON, "a", },
8195 { 396, 122, MARKER_BUTTON, "b", },
8196 { 320, 125, MARKER_BUTTON, "x", },
8197 { 358, 95, MARKER_BUTTON, "y", },
8198 { 162, 125, MARKER_BUTTON, "back", },
8199 { 216, 125, MARKER_BUTTON, "guide", },
8200 { 271, 125, MARKER_BUTTON, "start", },
8201 { 110, 200, MARKER_BUTTON, "dpleft", },
8202 { 146, 228, MARKER_BUTTON, "dpdown", },
8203 { 178, 200, MARKER_BUTTON, "dpright", },
8204 { 146, 172, MARKER_BUTTON, "dpup", },
8205 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8206 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8207 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8208 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8209 { 73, 141, MARKER_BUTTON, "leftstick", },
8210 { 282, 210, MARKER_BUTTON, "rightstick", },
8211 { 73, 141, MARKER_AXIS_X, "leftx", },
8212 { 73, 141, MARKER_AXIS_Y, "lefty", },
8213 { 282, 210, MARKER_AXIS_X, "rightx", },
8214 { 282, 210, MARKER_AXIS_Y, "righty", },
8217 unsigned int event_frame_delay = 0;
8218 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8220 ResetDelayCounter(&event_frame_delay);
8222 if (!bitmaps_initialized)
8224 controller = LoadCustomImage("joystick/controller.png");
8225 button = LoadCustomImage("joystick/button.png");
8226 axis_x = LoadCustomImage("joystick/axis_x.png");
8227 axis_y = LoadCustomImage("joystick/axis_y.png");
8229 bitmaps_initialized = TRUE;
8232 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8235 // print info about the joystick we are watching
8236 Debug("joystick", "watching joystick %d: (%s)",
8237 SDL_JoystickInstanceID(joystick), name);
8238 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8239 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8240 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8243 // initialize mapping with GUID and name
8244 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8246 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8247 temp, name, SDL_GetPlatform());
8249 // loop through all steps (buttons and axes), getting joystick events
8250 for (i = 0; i < SDL_arraysize(steps) && !done;)
8252 Bitmap *marker = button; // initialize with reliable default value
8255 strcpy(step->mapping, mapping);
8259 step->hat_value = -1;
8261 marker = (step->marker == MARKER_BUTTON ? button :
8262 step->marker == MARKER_AXIS_X ? axis_x :
8263 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8267 while (!done && !next)
8269 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8270 alpha_ticks = SDL_GetTicks();
8277 else if (alpha < 128)
8283 int controller_x = SX + (SXSIZE - controller->width) / 2;
8284 int controller_y = SY + ystep_line;
8286 int marker_x = controller_x + step->x;
8287 int marker_y = controller_y + step->y;
8289 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8290 int ystart2 = ystart1 + ystep_name + ystep_line;
8294 DrawTextSCentered(ystart1, font_name, name);
8296 DrawTextSCentered(ystart2, font_info,
8297 "Press buttons and move axes on");
8298 ystart2 += ystep_line;
8299 DrawTextSCentered(ystart2, font_info,
8300 "your controller when indicated.");
8301 ystart2 += ystep_line;
8302 DrawTextSCentered(ystart2, font_info,
8303 "(Your controller may look different.)");
8304 ystart2 += ystep_para;
8306 #if defined(PLATFORM_ANDROID)
8307 DrawTextSCentered(ystart2, font_info,
8308 "To correct a mistake,");
8309 ystart2 += ystep_line;
8310 DrawTextSCentered(ystart2, font_info,
8311 "press the 'back' button.");
8312 ystart2 += ystep_line;
8313 DrawTextSCentered(ystart2, font_info,
8314 "To skip a button or axis,");
8315 ystart2 += ystep_line;
8316 DrawTextSCentered(ystart2, font_info,
8317 "press the 'menu' button.");
8319 DrawTextSCentered(ystart2, font_info,
8320 "To correct a mistake,");
8321 ystart2 += ystep_line;
8322 DrawTextSCentered(ystart2, font_info,
8323 "press the 'backspace' key.");
8324 ystart2 += ystep_line;
8325 DrawTextSCentered(ystart2, font_info,
8326 "To skip a button or axis,");
8327 ystart2 += ystep_line;
8328 DrawTextSCentered(ystart2, font_info,
8329 "press the 'return' key.");
8330 ystart2 += ystep_line;
8331 DrawTextSCentered(ystart2, font_info,
8332 "To exit, press the 'escape' key.");
8335 BlitBitmapMasked(controller, drawto, 0, 0,
8336 controller->width, controller->height,
8337 controller_x, controller_y);
8339 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8340 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8342 BlitBitmapMasked(marker, drawto, 0, 0,
8343 marker->width, marker->height,
8344 marker_x, marker_y);
8346 if (!screen_initialized)
8347 FadeIn(REDRAW_FIELD);
8351 screen_initialized = TRUE;
8353 while (NextValidEvent(&event))
8357 case SDL_JOYAXISMOTION:
8358 if (event.jaxis.value > 20000 ||
8359 event.jaxis.value < -20000)
8361 for (j = 0; j < i; j++)
8362 if (steps[j].axis == event.jaxis.axis)
8367 if (step->marker != MARKER_AXIS_X &&
8368 step->marker != MARKER_AXIS_Y)
8371 step->axis = event.jaxis.axis;
8372 strcat(mapping, step->field);
8373 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8374 strcat(mapping, temp);
8382 case SDL_JOYHATMOTION:
8383 // ignore centering; we're probably just coming back
8384 // to the center from the previous item we set
8385 if (event.jhat.value == SDL_HAT_CENTERED)
8388 for (j = 0; j < i; j++)
8389 if (steps[j].hat == event.jhat.hat &&
8390 steps[j].hat_value == event.jhat.value)
8395 step->hat = event.jhat.hat;
8396 step->hat_value = event.jhat.value;
8397 strcat(mapping, step->field);
8398 snprintf(temp, sizeof(temp), ":h%u.%u,",
8399 event.jhat.hat, event.jhat.value );
8400 strcat(mapping, temp);
8407 case SDL_JOYBALLMOTION:
8410 case SDL_JOYBUTTONUP:
8411 for (j = 0; j < i; j++)
8412 if (steps[j].button == event.jbutton.button)
8417 step->button = event.jbutton.button;
8418 strcat(mapping, step->field);
8419 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8420 strcat(mapping, temp);
8427 case SDL_FINGERDOWN:
8428 case SDL_MOUSEBUTTONDOWN:
8436 if (event.key.keysym.sym == KSYM_BackSpace ||
8437 event.key.keysym.sym == KSYM_Back)
8449 prev_step = &steps[i - 1];
8450 strcpy(mapping, prev_step->mapping);
8457 if (event.key.keysym.sym == KSYM_space ||
8458 event.key.keysym.sym == KSYM_Return ||
8459 event.key.keysym.sym == KSYM_Menu)
8468 if (event.key.keysym.sym == KSYM_Escape)
8478 program.exit_function(0);
8485 // do not handle events for longer than standard frame delay period
8486 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8495 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8498 // activate mapping for this game
8499 SDL_GameControllerAddMapping(mapping);
8501 // save mapping to personal mappings
8502 SaveSetup_AddGameControllerMapping(mapping);
8505 // wait until the last pending event was removed from event queue
8506 while (NextValidEvent(&event));
8511 static int ConfigureJoystickMain(int player_nr)
8513 char *device_name = setup.input[player_nr].joy.device_name;
8514 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8515 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8516 int success = FALSE;
8519 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8520 return JOYSTICK_NOT_AVAILABLE;
8522 if (!joystick_active || !setup.input[player_nr].use_joystick)
8523 return JOYSTICK_NOT_AVAILABLE;
8526 FadeOut(REDRAW_FIELD);
8528 // close all joystick devices (potentially opened as game controllers)
8529 for (i = 0; i < SDL_NumJoysticks(); i++)
8530 SDLCloseJoystick(i);
8532 // open joystick device as plain joystick to configure as game controller
8533 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8535 // as the joystick was successfully opened before, this should not happen
8536 if (joystick == NULL)
8539 // create new game controller mapping (buttons and axes) for joystick device
8540 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8542 // close joystick (and maybe re-open as configured game controller later)
8543 SDL_JoystickClose(joystick);
8545 // re-open all joystick devices (potentially as game controllers)
8546 for (i = 0; i < SDL_NumJoysticks(); i++)
8549 // clear all joystick input actions for all joystick devices
8550 SDLClearJoystickState();
8552 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8555 void ConfigureJoystick(int player_nr)
8557 boolean state = ConfigureJoystickMain(player_nr);
8559 if (state != JOYSTICK_NOT_CONFIGURED)
8561 boolean success = (state == JOYSTICK_CONFIGURED);
8562 char message1[MAX_OUTPUT_LINESIZE + 1];
8563 char *message2 = (success ? "configured!" : "not available!");
8564 char *device_name = setup.input[player_nr].joy.device_name;
8565 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8566 int font_nr = FONT_TITLE_1;
8567 int font_height = getFontHeight(font_nr);
8568 int ypos1 = SYSIZE / 2 - font_height * 2;
8569 int ypos2 = SYSIZE / 2 - font_height * 1;
8570 unsigned int wait_frame_delay = 0;
8571 unsigned int wait_frame_delay_value = 2000;
8573 ResetDelayCounter(&wait_frame_delay);
8577 sprintf(message1, "Joystick %d", nr);
8579 DrawTextSCentered(ypos1, font_nr, message1);
8580 DrawTextSCentered(ypos2, font_nr, message2);
8582 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8588 DrawSetupScreen_Input();
8591 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8593 if (y < video.screen_height / 3)
8595 // remap touch gadgets to access upper part of the screen
8596 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8597 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8599 else if (y > 2 * video.screen_height / 3)
8601 // remap touch gadgets to access lower part of the screen
8602 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8603 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8607 static boolean ConfigureVirtualButtonsMain(void)
8609 static char *customize_step_text[] =
8618 char grid_button[] =
8620 CHAR_GRID_BUTTON_LEFT,
8621 CHAR_GRID_BUTTON_RIGHT,
8622 CHAR_GRID_BUTTON_UP,
8623 CHAR_GRID_BUTTON_DOWN,
8624 CHAR_GRID_BUTTON_SNAP,
8625 CHAR_GRID_BUTTON_DROP
8634 int font_nr = FONT_INPUT_1_ACTIVE;
8635 int font_height = getFontHeight(font_nr);
8636 int ypos1 = SYSIZE / 2 - font_height * 2;
8637 int ypos2 = SYSIZE / 2 - font_height * 1;
8638 boolean success = FALSE;
8639 boolean finished = FALSE;
8641 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8642 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8643 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8644 boolean set_grid_button = FALSE;
8645 int nr = GRID_ACTIVE_NR();
8648 for (x = 0; x < MAX_GRID_XSIZE; x++)
8649 for (y = 0; y < MAX_GRID_YSIZE; y++)
8650 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8652 overlay.grid_button_highlight = grid_button[step_nr];
8657 FadeOut(REDRAW_FIELD);
8661 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8662 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8663 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8665 FadeIn(REDRAW_FIELD);
8667 SetOverlayShowGrid(TRUE);
8669 // map gadgets for setup touch buttons menu screen
8670 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8676 while (NextValidEvent(&event))
8678 int action = ACTION_NONE;
8680 // ---------- handle events and set the resulting action ----------
8686 UserEvent *user = (UserEvent *)&event;
8687 int id = user->value1;
8689 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8690 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8691 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8692 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8697 case EVENT_KEYPRESS:
8699 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8701 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8702 key == KSYM_BackSpace ||
8703 key == KSYM_Back ? ACTION_BACK :
8704 key == KSYM_Return ||
8706 key == KSYM_space ? ACTION_NEXT :
8711 case EVENT_KEYRELEASE:
8712 key_joystick_mapping = 0;
8715 case EVENT_BUTTONPRESS:
8716 case EVENT_BUTTONRELEASE:
8718 ButtonEvent *button = (ButtonEvent *)&event;
8720 motion_status = FALSE;
8722 if (button->type == EVENT_BUTTONPRESS)
8723 button_status = button->button;
8725 button_status = MB_RELEASED;
8727 if (HandleGadgets(button->x, button->y, button_status))
8729 // do not handle this button event anymore
8733 button->x += video.screen_xoffset;
8734 button->y += video.screen_yoffset;
8736 x = button->x * overlay.grid_xsize / video.screen_width;
8737 y = button->y * overlay.grid_ysize / video.screen_height;
8739 if (button->type == EVENT_BUTTONPRESS)
8742 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8743 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8745 set_grid_button = TRUE;
8748 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8752 case EVENT_MOTIONNOTIFY:
8754 MotionEvent *motion = (MotionEvent *)&event;
8756 motion_status = TRUE;
8758 if (HandleGadgets(motion->x, motion->y, button_status))
8760 // do not handle this button event anymore
8764 motion->x += video.screen_xoffset;
8765 motion->y += video.screen_yoffset;
8767 x = motion->x * overlay.grid_xsize / video.screen_width;
8768 y = motion->y * overlay.grid_ysize / video.screen_height;
8770 set_grid_button = TRUE;
8772 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8776 case SDL_WINDOWEVENT:
8777 HandleWindowEvent((WindowEvent *) &event);
8779 // check if device has been rotated
8780 if (nr != GRID_ACTIVE_NR())
8782 nr = GRID_ACTIVE_NR();
8784 for (x = 0; x < MAX_GRID_XSIZE; x++)
8785 for (y = 0; y < MAX_GRID_YSIZE; y++)
8786 grid_button_old[x][y] = grid_button_tmp[x][y] =
8787 overlay.grid_button[x][y];
8792 case SDL_APP_WILLENTERBACKGROUND:
8793 case SDL_APP_DIDENTERBACKGROUND:
8794 case SDL_APP_WILLENTERFOREGROUND:
8795 case SDL_APP_DIDENTERFOREGROUND:
8796 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8800 HandleOtherEvents(&event);
8804 // ---------- perform action set by handling events ----------
8806 if (action == ACTION_ESCAPE)
8808 // abort and restore the old key bindings
8810 for (x = 0; x < MAX_GRID_XSIZE; x++)
8811 for (y = 0; y < MAX_GRID_YSIZE; y++)
8812 overlay.grid_button[x][y] = grid_button_old[x][y];
8814 FadeSkipNextFadeIn();
8818 else if (action == ACTION_BACK)
8820 // keep the configured key bindings and go to previous page
8826 FadeSkipNextFadeIn();
8831 else if (action == ACTION_NEXT)
8833 // keep the configured key bindings and go to next page
8837 // all virtual buttons configured
8845 if (action != ACTION_NONE && !finished)
8847 for (x = 0; x < MAX_GRID_XSIZE; x++)
8848 for (y = 0; y < MAX_GRID_YSIZE; y++)
8849 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8851 overlay.grid_button_highlight = grid_button[step_nr];
8853 // configure next virtual button
8857 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8858 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8859 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8862 if (set_grid_button)
8864 overlay.grid_button[x][y] =
8865 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8866 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8867 grid_button_tmp[x][y]);
8869 set_grid_button = FALSE;
8876 for (x = 0; x < MAX_GRID_XSIZE; x++)
8877 for (y = 0; y < MAX_GRID_YSIZE; y++)
8878 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8880 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8882 SetOverlayShowGrid(FALSE);
8887 void ConfigureVirtualButtons(void)
8889 boolean success = ConfigureVirtualButtonsMain();
8891 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8892 SCREEN_MASK_TOUCH2);
8896 int font_nr = FONT_TITLE_1;
8897 int font_height = getFontHeight(font_nr);
8898 int ypos1 = SYSIZE / 2 - font_height * 2;
8899 int ypos2 = SYSIZE / 2 - font_height * 1;
8900 unsigned int wait_frame_delay = 0;
8901 unsigned int wait_frame_delay_value = 2000;
8903 ResetDelayCounter(&wait_frame_delay);
8907 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8908 DrawTextSCentered(ypos2, font_nr, "configured!");
8910 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8917 void DrawSetupScreen(void)
8922 if (setup_mode == SETUP_MODE_INPUT)
8923 DrawSetupScreen_Input();
8924 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8925 DrawChooseTree(&game_speed_current);
8926 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8927 DrawChooseTree(&scroll_delay_current);
8928 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8929 DrawChooseTree(&snapshot_mode_current);
8930 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8931 DrawChooseTree(&window_size_current);
8932 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8933 DrawChooseTree(&scaling_type_current);
8934 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8935 DrawChooseTree(&rendering_mode_current);
8936 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8937 DrawChooseTree(&vsync_mode_current);
8938 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8939 DrawChooseTree(&artwork.gfx_current);
8940 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8941 DrawChooseTree(&artwork.snd_current);
8942 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8943 DrawChooseTree(&artwork.mus_current);
8944 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8945 DrawChooseTree(&volume_simple_current);
8946 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8947 DrawChooseTree(&volume_loops_current);
8948 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8949 DrawChooseTree(&volume_music_current);
8950 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8951 DrawChooseTree(&touch_control_current);
8952 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8953 DrawChooseTree(&move_distance_current);
8954 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8955 DrawChooseTree(&drop_distance_current);
8956 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8957 DrawChooseTree(&transparency_current);
8958 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8959 DrawChooseTree(&grid_size_current[0][0]);
8960 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8961 DrawChooseTree(&grid_size_current[0][1]);
8962 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8963 DrawChooseTree(&grid_size_current[1][0]);
8964 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8965 DrawChooseTree(&grid_size_current[1][1]);
8967 DrawSetupScreen_Generic();
8969 PlayMenuSoundsAndMusic();
8972 void RedrawSetupScreenAfterFullscreenToggle(void)
8974 if (setup_mode == SETUP_MODE_GRAPHICS ||
8975 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8977 // update list selection from "setup.window_scaling_percent"
8978 execSetupGraphics_setWindowSizes(TRUE);
8984 void RedrawSetupScreenAfterScreenRotation(int nr)
8988 if (setup_mode == SETUP_MODE_TOUCH)
8990 // update virtual button settings (depending on screen orientation)
8993 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8995 // save already configured virtual buttons
8996 for (x = 0; x < MAX_GRID_XSIZE; x++)
8997 for (y = 0; y < MAX_GRID_YSIZE; y++)
8998 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9002 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9004 if (setup_mode == SETUP_MODE_INPUT)
9005 HandleSetupScreen_Input(mx, my, dx, dy, button);
9006 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9007 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9008 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9009 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9010 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9011 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9012 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9013 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9014 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9015 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9016 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9017 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9018 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9019 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9020 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9021 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9022 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9023 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9024 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9025 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9026 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9027 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9028 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9029 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9030 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9031 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9032 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9033 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9034 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9035 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9036 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9037 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9038 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9039 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9040 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9041 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9042 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9043 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9044 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9045 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9046 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9047 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9049 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9052 void HandleGameActions(void)
9054 if (setup.ask_on_game_over)
9057 if (game.restart_game_message != NULL)
9059 RequestRestartGame(game.restart_game_message);
9064 if (game_status != GAME_MODE_PLAYING)
9067 GameActions(); // main game loop
9069 if (tape.auto_play && !tape.playing)
9070 AutoPlayTapesContinue(); // continue automatically playing next tape
9074 // ---------- new screen button stuff --------------------------------------
9078 int gfx_unpressed, gfx_pressed;
9079 struct MenuPosInfo *pos;
9080 boolean *check_value;
9083 unsigned int event_mask;
9084 boolean is_touch_button;
9086 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9089 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9090 &menu.main.button.prev_level, NULL,
9091 SCREEN_CTRL_ID_PREV_LEVEL,
9093 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9094 FALSE, "previous level"
9097 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9098 &menu.main.button.next_level, NULL,
9099 SCREEN_CTRL_ID_NEXT_LEVEL,
9101 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9105 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9106 &menu.main.button.first_level, NULL,
9107 SCREEN_CTRL_ID_FIRST_LEVEL,
9110 FALSE, "first level"
9113 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9114 &menu.main.button.last_level, NULL,
9115 SCREEN_CTRL_ID_LAST_LEVEL,
9121 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9122 &menu.main.button.level_number, NULL,
9123 SCREEN_CTRL_ID_LEVEL_NUMBER,
9126 FALSE, "level number"
9129 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9130 &menu.setup.button.prev_player, NULL,
9131 SCREEN_CTRL_ID_PREV_PLAYER,
9133 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9134 FALSE, "previous player"
9137 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9138 &menu.setup.button.next_player, NULL,
9139 SCREEN_CTRL_ID_NEXT_PLAYER,
9141 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9142 FALSE, "next player"
9145 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9146 &menu.main.button.insert_solution, NULL,
9147 SCREEN_CTRL_ID_INSERT_SOLUTION,
9148 SCREEN_MASK_MAIN_HAS_SOLUTION,
9150 FALSE, "insert solution tape"
9153 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9154 &menu.main.button.play_solution, NULL,
9155 SCREEN_CTRL_ID_PLAY_SOLUTION,
9156 SCREEN_MASK_MAIN_HAS_SOLUTION,
9158 FALSE, "play solution tape"
9161 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9162 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9163 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9165 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9166 FALSE, "switch ECS/AGA chipset"
9169 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9170 &menu.setup.button.touch_back, NULL,
9171 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9174 TRUE, "previous page"
9177 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9178 &menu.setup.button.touch_next, NULL,
9179 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9185 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9186 &menu.setup.button.touch_back2, NULL,
9187 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9190 TRUE, "previous page"
9193 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9194 &menu.setup.button.touch_next2, NULL,
9195 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9204 int gfx_unpressed, gfx_pressed;
9208 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9211 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9212 -1, -1, // these values are not constant, but can change at runtime
9213 SCREEN_CTRL_ID_SCROLL_UP,
9217 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9218 -1, -1, // these values are not constant, but can change at runtime
9219 SCREEN_CTRL_ID_SCROLL_DOWN,
9226 int gfx_unpressed, gfx_pressed;
9232 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9235 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9236 -1, -1, // these values are not constant, but can change at runtime
9237 -1, -1, // these values are not constant, but can change at runtime
9238 GD_TYPE_SCROLLBAR_VERTICAL,
9239 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9240 "scroll level series vertically"
9252 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9255 IMG_SETUP_INPUT_TEXT,
9256 SCREEN_CTRL_ID_NETWORK_SERVER,
9257 -1, -1, // these values are not constant, but can change at runtime
9258 MAX_SETUP_TEXT_INPUT_LEN,
9259 network_server_hostname,
9260 "Network Server Hostname / IP"
9264 static void CreateScreenMenubuttons(void)
9266 struct GadgetInfo *gi;
9267 unsigned int event_mask;
9270 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9272 struct MenuPosInfo *pos = menubutton_info[i].pos;
9273 boolean is_touch_button = menubutton_info[i].is_touch_button;
9274 boolean is_check_button = menubutton_info[i].check_value != NULL;
9275 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9276 int gfx_unpressed, gfx_pressed;
9277 int x, y, width, height;
9278 int gd_x1, gd_x2, gd_y1, gd_y2;
9279 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9280 int id = menubutton_info[i].gadget_id;
9281 int type = GD_TYPE_NORMAL_BUTTON;
9282 boolean checked = FALSE;
9284 event_mask = menubutton_info[i].event_mask;
9286 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9287 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9289 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9290 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9292 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9293 gfx_pressed = menubutton_info[i].gfx_pressed;
9294 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9295 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9296 gd_x1 = graphic_info[gfx_unpressed].src_x;
9297 gd_y1 = graphic_info[gfx_unpressed].src_y;
9298 gd_x2 = graphic_info[gfx_pressed].src_x;
9299 gd_y2 = graphic_info[gfx_pressed].src_y;
9305 if (is_touch_button)
9307 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9308 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9311 if (is_check_button)
9313 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9314 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9315 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9316 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9318 type = GD_TYPE_CHECK_BUTTON;
9319 checked = *menubutton_info[i].check_value;
9322 gi = CreateGadget(GDI_CUSTOM_ID, id,
9323 GDI_CUSTOM_TYPE_ID, i,
9324 GDI_IMAGE_ID, gfx_unpressed,
9325 GDI_INFO_TEXT, menubutton_info[i].infotext,
9331 GDI_STATE, GD_BUTTON_UNPRESSED,
9332 GDI_CHECKED, checked,
9333 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9334 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9335 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9336 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9337 GDI_DIRECT_DRAW, FALSE,
9338 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9339 GDI_EVENT_MASK, event_mask,
9340 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9344 Fail("cannot create gadget");
9346 screen_gadget[id] = gi;
9350 static void CreateScreenScrollbuttons(void)
9352 struct GadgetInfo *gi;
9353 unsigned int event_mask;
9356 // these values are not constant, but can change at runtime
9357 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9358 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9359 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9360 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9362 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9364 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9365 int gfx_unpressed, gfx_pressed;
9366 int x, y, width, height;
9367 int gd_x1, gd_x2, gd_y1, gd_y2;
9368 int id = scrollbutton_info[i].gadget_id;
9370 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9372 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9373 y = mSY + scrollbutton_info[i].y;
9374 width = SC_SCROLLBUTTON_XSIZE;
9375 height = SC_SCROLLBUTTON_YSIZE;
9377 // correct scrollbar position if placed outside menu (playfield) area
9378 if (x > SX + SC_SCROLL_UP_XPOS)
9379 x = SX + SC_SCROLL_UP_XPOS;
9381 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9382 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9383 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9385 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9386 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9387 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9388 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9389 gd_x1 = graphic_info[gfx_unpressed].src_x;
9390 gd_y1 = graphic_info[gfx_unpressed].src_y;
9391 gd_x2 = graphic_info[gfx_pressed].src_x;
9392 gd_y2 = graphic_info[gfx_pressed].src_y;
9394 gi = CreateGadget(GDI_CUSTOM_ID, id,
9395 GDI_CUSTOM_TYPE_ID, i,
9396 GDI_IMAGE_ID, gfx_unpressed,
9397 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9402 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9403 GDI_STATE, GD_BUTTON_UNPRESSED,
9404 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9405 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9406 GDI_DIRECT_DRAW, FALSE,
9407 GDI_EVENT_MASK, event_mask,
9408 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9412 Fail("cannot create gadget");
9414 screen_gadget[id] = gi;
9418 static void CreateScreenScrollbars(void)
9422 // these values are not constant, but can change at runtime
9423 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9424 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9425 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9426 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9428 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9430 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9431 int gfx_unpressed, gfx_pressed;
9432 int x, y, width, height;
9433 int gd_x1, gd_x2, gd_y1, gd_y2;
9434 struct GadgetInfo *gi;
9435 int items_max, items_visible, item_position;
9436 unsigned int event_mask;
9437 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9438 int id = scrollbar_info[i].gadget_id;
9440 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9442 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9443 y = mSY + scrollbar_info[i].y;
9444 width = scrollbar_info[i].width;
9445 height = scrollbar_info[i].height;
9447 // correct scrollbar position if placed outside menu (playfield) area
9448 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9449 x = SX + SC_SCROLL_VERTICAL_XPOS;
9451 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9452 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9454 items_max = num_page_entries;
9455 items_visible = num_page_entries;
9458 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9459 gfx_pressed = scrollbar_info[i].gfx_pressed;
9460 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9461 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9462 gd_x1 = graphic_info[gfx_unpressed].src_x;
9463 gd_y1 = graphic_info[gfx_unpressed].src_y;
9464 gd_x2 = graphic_info[gfx_pressed].src_x;
9465 gd_y2 = graphic_info[gfx_pressed].src_y;
9467 gi = CreateGadget(GDI_CUSTOM_ID, id,
9468 GDI_CUSTOM_TYPE_ID, i,
9469 GDI_IMAGE_ID, gfx_unpressed,
9470 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9475 GDI_TYPE, scrollbar_info[i].type,
9476 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9477 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9478 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9479 GDI_WHEEL_AREA_X, SX,
9480 GDI_WHEEL_AREA_Y, SY,
9481 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9482 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9483 GDI_STATE, GD_BUTTON_UNPRESSED,
9484 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9485 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9486 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9487 GDI_DIRECT_DRAW, FALSE,
9488 GDI_EVENT_MASK, event_mask,
9489 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9493 Fail("cannot create gadget");
9495 screen_gadget[id] = gi;
9499 static void CreateScreenTextInputGadgets(void)
9503 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9505 int graphic = textinput_info[i].graphic;
9506 struct GraphicInfo *gd = &graphic_info[graphic];
9507 int gd_x1 = gd->src_x;
9508 int gd_y1 = gd->src_y;
9509 int gd_x2 = gd->src_x + gd->active_xoffset;
9510 int gd_y2 = gd->src_y + gd->active_yoffset;
9511 struct GadgetInfo *gi;
9512 unsigned int event_mask;
9513 int id = textinput_info[i].gadget_id;
9514 int x = textinput_info[i].x;
9515 int y = textinput_info[i].y;
9517 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9519 gi = CreateGadget(GDI_CUSTOM_ID, id,
9520 GDI_CUSTOM_TYPE_ID, i,
9521 GDI_INFO_TEXT, textinput_info[i].infotext,
9524 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9525 GDI_TEXT_VALUE, textinput_info[i].value,
9526 GDI_TEXT_SIZE, textinput_info[i].size,
9527 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9528 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9529 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9530 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9531 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9532 GDI_DESIGN_WIDTH, gd->width,
9533 GDI_EVENT_MASK, event_mask,
9534 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9535 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9539 Fail("cannot create gadget");
9541 screen_gadget[id] = gi;
9545 void CreateScreenGadgets(void)
9547 CreateScreenMenubuttons();
9549 CreateScreenScrollbuttons();
9550 CreateScreenScrollbars();
9552 CreateScreenTextInputGadgets();
9555 void FreeScreenGadgets(void)
9559 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9560 FreeGadget(screen_gadget[i]);
9563 static void MapScreenMenuGadgets(int screen_mask)
9567 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9568 if (screen_mask & menubutton_info[i].screen_mask)
9569 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9572 static void UnmapScreenMenuGadgets(int screen_mask)
9576 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9578 if (screen_mask & menubutton_info[i].screen_mask)
9580 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9582 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9583 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9584 screen_gadget[menubutton_info[i].gadget_id]->y,
9585 screen_gadget[menubutton_info[i].gadget_id]->width,
9586 screen_gadget[menubutton_info[i].gadget_id]->height);
9591 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9594 MapScreenMenuGadgets(screen_mask);
9596 UnmapScreenMenuGadgets(screen_mask);
9599 static void MapScreenGadgets(int num_entries)
9603 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9606 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9607 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9609 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9610 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9613 static void MapScreenTreeGadgets(TreeInfo *ti)
9615 MapScreenGadgets(numTreeInfoInGroup(ti));
9618 static void HandleScreenGadgets(struct GadgetInfo *gi)
9620 int id = gi->custom_id;
9621 int button = gi->event.button;
9622 int step = (button == MB_LEFTBUTTON ? 1 :
9623 button == MB_MIDDLEBUTTON ? 5 :
9624 button == MB_RIGHTBUTTON ? 10 : 1);
9628 case SCREEN_CTRL_ID_PREV_LEVEL:
9629 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9632 case SCREEN_CTRL_ID_NEXT_LEVEL:
9633 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9636 case SCREEN_CTRL_ID_FIRST_LEVEL:
9637 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9640 case SCREEN_CTRL_ID_LAST_LEVEL:
9641 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9644 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9645 CloseDoor(DOOR_CLOSE_2);
9646 SetGameStatus(GAME_MODE_LEVELNR);
9647 DrawChooseLevelNr();
9650 case SCREEN_CTRL_ID_PREV_PLAYER:
9651 HandleSetupScreen_Input_Player(step, -1);
9654 case SCREEN_CTRL_ID_NEXT_PLAYER:
9655 HandleSetupScreen_Input_Player(step, +1);
9658 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9659 InsertSolutionTape();
9662 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9666 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9667 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9671 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9672 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9673 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9674 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9675 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9678 case SCREEN_CTRL_ID_SCROLL_UP:
9679 if (game_status == GAME_MODE_NAMES)
9680 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9681 else if (game_status == GAME_MODE_LEVELS)
9682 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9683 else if (game_status == GAME_MODE_LEVELNR)
9684 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9685 else if (game_status == GAME_MODE_SETUP)
9686 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9687 else if (game_status == GAME_MODE_INFO)
9688 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9691 case SCREEN_CTRL_ID_SCROLL_DOWN:
9692 if (game_status == GAME_MODE_NAMES)
9693 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9694 else if (game_status == GAME_MODE_LEVELS)
9695 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9696 else if (game_status == GAME_MODE_LEVELNR)
9697 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9698 else if (game_status == GAME_MODE_SETUP)
9699 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9700 else if (game_status == GAME_MODE_INFO)
9701 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9704 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9705 if (game_status == GAME_MODE_NAMES)
9706 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9707 else if (game_status == GAME_MODE_LEVELS)
9708 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9709 else if (game_status == GAME_MODE_LEVELNR)
9710 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9711 else if (game_status == GAME_MODE_SETUP)
9712 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9713 else if (game_status == GAME_MODE_INFO)
9714 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9717 case SCREEN_CTRL_ID_NETWORK_SERVER:
9719 if (!strEqual(gi->textinput.value, ""))
9721 setString(&setup.network_server_hostname, gi->textinput.value);
9723 network.server_host = setup.network_server_hostname;
9727 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9729 network.server_host = NULL;
9732 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9733 network.server_host = NULL;
9735 execSetupGame_setNetworkServerText();
9747 void DumpScreenIdentifiers(void)
9751 Print("Active screen elements on current screen:\n");
9753 for (i = 0; main_controls[i].nr != -1; i++)
9755 struct MainControlInfo *mci = &main_controls[i];
9757 if (mci->button_graphic != -1)
9759 char *token = getTokenFromImageID(mci->button_graphic);
9761 Print("- '%s'\n", token);
9768 boolean DoScreenAction(int image_id)
9772 if (game_status != GAME_MODE_MAIN)
9775 for (i = 0; main_controls[i].nr != -1; i++)
9777 struct MainControlInfo *mci = &main_controls[i];
9778 struct MenuPosInfo *pos = mci->pos_button;
9780 if (mci->button_graphic == image_id)
9782 int x = mSX + pos->x;
9783 int y = mSY + pos->y;
9785 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9794 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9796 // get tree info node of newly added level or artwork set
9797 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9798 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9800 if (tree_node_new == NULL) // should not happen
9803 // if request dialog is active, do nothing
9804 if (game.request_active)
9807 if (game_status == GAME_MODE_MAIN &&
9808 tree_type == TREE_TYPE_LEVEL_DIR)
9810 // when adding new level set in main menu, select it as current level set
9812 // change current level set to newly added level set from zip file
9813 leveldir_current = tree_node_new;
9815 // change current level number to first level of newly added level set
9816 level_nr = leveldir_current->first_level;
9818 // redraw screen to reflect changed level set
9821 // save this level set and level number as last selected level set
9822 SaveLevelSetup_LastSeries();
9823 SaveLevelSetup_SeriesInfo();
9825 else if (game_status == GAME_MODE_LEVELS &&
9826 tree_type == TREE_TYPE_LEVEL_DIR)
9828 // when adding new level set in level set menu, set cursor and update screen
9830 leveldir_current = tree_node_new;
9832 DrawChooseTree(&leveldir_current);
9834 else if (game_status == GAME_MODE_SETUP)
9836 // when adding new artwork set in setup menu, set cursor and update screen
9838 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9839 tree_type == TREE_TYPE_GRAPHICS_DIR)
9841 artwork.gfx_current = tree_node_new;
9843 DrawChooseTree(&artwork.gfx_current);
9845 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9846 tree_type == TREE_TYPE_SOUNDS_DIR)
9848 artwork.snd_current = tree_node_new;
9850 DrawChooseTree(&artwork.snd_current);
9852 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9853 tree_type == TREE_TYPE_MUSIC_DIR)
9855 artwork.mus_current = tree_node_new;
9857 DrawChooseTree(&artwork.mus_current);
9862 static int UploadTapes(void)
9864 SetGameStatus(GAME_MODE_LOADING);
9866 FadeSetEnterScreen();
9867 FadeOut(REDRAW_ALL);
9869 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
9873 DrawInitTextHead("Uploading tapes");
9875 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
9876 global.autoplay_leveldir = "ALL";
9877 global.autoplay_all = TRUE;
9879 int num_tapes_uploaded = AutoPlayTapes();
9881 global.autoplay_mode = AUTOPLAY_MODE_NONE;
9882 global.autoplay_leveldir = NULL;
9883 global.autoplay_all = FALSE;
9885 SetGameStatus(GAME_MODE_MAIN);
9889 return num_tapes_uploaded;
9892 static boolean OfferUploadTapes(void)
9894 if (!Request("Upload all your tapes to the high score server now?", REQ_ASK))
9897 int num_tapes_uploaded = UploadTapes();
9900 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
9902 Request(message, REQ_CONFIRM);
9904 // after all tapes have been uploaded, remove entry from setup menu
9905 setup.provide_uploading_tapes = FALSE;
9909 return (num_tapes_uploaded > 0);
9912 void CheckUploadTapes(void)
9914 if (!setup.ask_for_uploading_tapes)
9917 if (directoryExists(getTapeDir(NULL)))
9919 boolean tapes_uploaded = OfferUploadTapes();
9921 if (!tapes_uploaded)
9922 Request("You can upload your tapes from the setup menu later!",
9927 // if tapes directory does not exist yet, never offer uploading all tapes
9928 setup.provide_uploading_tapes = FALSE;
9931 // after asking for uploading all tapes once, do not ask again
9932 setup.ask_for_uploading_tapes = FALSE;