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_SCORES_TYPE 17
67 #define SETUP_MODE_CHOOSE_GAME_SPEED 18
68 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 19
69 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 20
70 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 21
71 #define SETUP_MODE_CHOOSE_SCALING_TYPE 22
72 #define SETUP_MODE_CHOOSE_RENDERING 23
73 #define SETUP_MODE_CHOOSE_VSYNC 24
74 #define SETUP_MODE_CHOOSE_GRAPHICS 25
75 #define SETUP_MODE_CHOOSE_SOUNDS 26
76 #define SETUP_MODE_CHOOSE_MUSIC 27
77 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 28
78 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 29
79 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 30
80 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 31
81 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 33
83 #define SETUP_MODE_CHOOSE_TRANSPARENCY 34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 36
86 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 37
87 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 38
88 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 39
90 #define MAX_SETUP_MODES 40
92 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
94 // setup screen titles
95 #define STR_SETUP_MAIN "Setup"
96 #define STR_SETUP_GAME "Game & Menu"
97 #define STR_SETUP_ENGINES "Game Engines"
98 #define STR_SETUP_EDITOR "Editor"
99 #define STR_SETUP_GRAPHICS "Graphics"
100 #define STR_SETUP_SOUND "Sound & Music"
101 #define STR_SETUP_ARTWORK "Custom Artwork"
102 #define STR_SETUP_INPUT "Input Devices"
103 #define STR_SETUP_TOUCH "Touch Controls"
104 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
105 #define STR_SETUP_EXIT "Exit"
106 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
108 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
109 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
110 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
111 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
112 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
113 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
114 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
115 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
116 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
117 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
118 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
119 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
120 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
121 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
122 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
125 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
126 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
128 // other screen text constants
129 #define STR_CHOOSE_TREE_EDIT "Edit"
130 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
131 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
133 // for input setup functions
134 #define SETUPINPUT_SCREEN_POS_START 0
135 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
136 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
137 #define SETUPINPUT_SCREEN_POS_END 13
139 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
140 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
142 #define MAX_SETUP_TEXT_INPUT_LEN 28
144 // for various menu stuff
145 #define MENU_SCREEN_START_XPOS 1
146 #define MENU_SCREEN_START_YPOS 2
147 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
148 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
149 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
150 #define MENU_TITLE1_YPOS 8
151 #define MENU_TITLE2_YPOS 46
152 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
153 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
154 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
155 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
156 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
159 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
160 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
161 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
162 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
163 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
164 MENU_INFO_FONT_TITLE))
165 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
166 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
167 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
168 MENU_SCREEN_INFO_YSTART2 - \
170 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
171 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
172 MENU_SCREEN_INFO_YSTEP)
173 #define NUM_INFO_ELEMENTS_FROM_CONF \
174 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
175 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
176 MAX_MENU_ENTRIES_ON_SCREEN)
177 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
178 MAX_INFO_ELEMENTS_ON_SCREEN), \
179 NUM_INFO_ELEMENTS_FROM_CONF)
180 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
181 #define MAX_MENU_TEXT_LENGTH_BIG 13
182 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
184 // screen gadget identifiers
185 #define SCREEN_CTRL_ID_PREV_LEVEL 0
186 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
187 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
188 #define SCREEN_CTRL_ID_LAST_LEVEL 3
189 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
190 #define SCREEN_CTRL_ID_PREV_PLAYER 5
191 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
192 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
193 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
194 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
195 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
196 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
197 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
198 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
199 #define SCREEN_CTRL_ID_SCROLL_UP 14
200 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
201 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
202 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
204 #define NUM_SCREEN_GADGETS 18
206 #define NUM_SCREEN_MENUBUTTONS 14
207 #define NUM_SCREEN_SCROLLBUTTONS 2
208 #define NUM_SCREEN_SCROLLBARS 1
209 #define NUM_SCREEN_TEXTINPUT 1
211 #define SCREEN_MASK_MAIN (1 << 0)
212 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
213 #define SCREEN_MASK_INPUT (1 << 2)
214 #define SCREEN_MASK_TOUCH (1 << 3)
215 #define SCREEN_MASK_TOUCH2 (1 << 4)
217 // graphic position and size values for buttons and scrollbars
218 #define SC_MENUBUTTON_XSIZE TILEX
219 #define SC_MENUBUTTON_YSIZE TILEY
221 #define SC_SCROLLBUTTON_XSIZE TILEX
222 #define SC_SCROLLBUTTON_YSIZE TILEY
224 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
226 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
227 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
228 SC_SCROLLBUTTON_YSIZE)
230 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
231 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
233 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
234 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
235 SC_SCROLLBUTTON_YSIZE)
237 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
238 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
239 SC_SCROLL_VERTICAL_YSIZE)
241 #define SC_BORDER_SIZE 14
244 // forward declarations of internal functions
245 static void HandleScreenGadgets(struct GadgetInfo *);
246 static void HandleSetupScreen_Generic(int, int, int, int, int);
247 static void HandleSetupScreen_Input(int, int, int, int, int);
248 static void CustomizeKeyboard(int);
249 static void ConfigureJoystick(int);
250 static void ConfigureVirtualButtons(void);
251 static void execSetupGame(void);
252 static void execSetupEngines(void);
253 static void execSetupGraphics(void);
254 static void execSetupSound(void);
255 static void execSetupTouch(void);
256 static void execSetupArtwork(void);
257 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
259 static void DrawChoosePlayerName(void);
260 static void DrawChooseLevelSet(void);
261 static void DrawChooseLevelNr(void);
262 static void DrawInfoScreen(void);
263 static void DrawSetupScreen(void);
264 static void DrawTypeName(void);
266 static void DrawInfoScreen_NotAvailable(char *, char *);
267 static void DrawInfoScreen_HelpAnim(int, int, boolean);
268 static void DrawInfoScreen_HelpText(int, int, int, int);
269 static void HandleInfoScreen_Main(int, int, int, int, int);
270 static void HandleInfoScreen_TitleScreen(int);
271 static void HandleInfoScreen_Elements(int);
272 static void HandleInfoScreen_Music(int);
273 static void HandleInfoScreen_Credits(int);
274 static void HandleInfoScreen_Program(int);
275 static void HandleInfoScreen_Version(int);
277 static void ModifyGameSpeedIfNeeded(void);
278 static void DisableVsyncIfNeeded(void);
280 static void MapScreenMenuGadgets(int);
281 static void UnmapScreenMenuGadgets(int);
282 static void MapScreenGadgets(int);
283 static void MapScreenTreeGadgets(TreeInfo *);
285 static void UpdateScreenMenuGadgets(int, boolean);
287 static boolean OfferUploadTapes(void);
288 static void execOfferUploadTapes(void);
290 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
292 static int info_mode = INFO_MODE_MAIN;
293 static int setup_mode = SETUP_MODE_MAIN;
295 static TreeInfo *window_sizes = NULL;
296 static TreeInfo *window_size_current = NULL;
298 static TreeInfo *scaling_types = NULL;
299 static TreeInfo *scaling_type_current = NULL;
301 static TreeInfo *rendering_modes = NULL;
302 static TreeInfo *rendering_mode_current = NULL;
304 static TreeInfo *vsync_modes = NULL;
305 static TreeInfo *vsync_mode_current = NULL;
307 static TreeInfo *scroll_delays = NULL;
308 static TreeInfo *scroll_delay_current = NULL;
310 static TreeInfo *snapshot_modes = NULL;
311 static TreeInfo *snapshot_mode_current = NULL;
313 static TreeInfo *scores_types = NULL;
314 static TreeInfo *scores_type_current = NULL;
316 static TreeInfo *game_speeds_normal = NULL;
317 static TreeInfo *game_speeds_extended = NULL;
318 static TreeInfo *game_speeds = NULL;
319 static TreeInfo *game_speed_current = NULL;
321 static TreeInfo *volumes_simple = NULL;
322 static TreeInfo *volume_simple_current = NULL;
324 static TreeInfo *volumes_loops = NULL;
325 static TreeInfo *volume_loops_current = NULL;
327 static TreeInfo *volumes_music = NULL;
328 static TreeInfo *volume_music_current = NULL;
330 static TreeInfo *touch_controls = NULL;
331 static TreeInfo *touch_control_current = NULL;
333 static TreeInfo *move_distances = NULL;
334 static TreeInfo *move_distance_current = NULL;
336 static TreeInfo *drop_distances = NULL;
337 static TreeInfo *drop_distance_current = NULL;
339 static TreeInfo *transparencies = NULL;
340 static TreeInfo *transparency_current = NULL;
342 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
343 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
345 static TreeInfo *player_name = NULL;
346 static TreeInfo *player_name_current = NULL;
348 static TreeInfo *level_number = NULL;
349 static TreeInfo *level_number_current = NULL;
351 static struct ValueTextInfo window_sizes_list[] =
356 { 100, "100 % (Default)" },
369 static struct StringValueTextInfo scaling_types_list[] =
371 { SCALING_QUALITY_NEAREST, "Off" },
372 { SCALING_QUALITY_LINEAR, "Linear" },
373 { SCALING_QUALITY_BEST, "Anisotropic" },
378 static struct StringValueTextInfo rendering_modes_list[] =
380 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
381 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
383 // this mode may work under certain conditions, but does not work on Windows
384 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
386 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
391 static struct StringValueTextInfo vsync_modes_list[] =
393 { STR_VSYNC_MODE_OFF, "Off" },
394 { STR_VSYNC_MODE_NORMAL, "Normal" },
395 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
400 static struct StringValueTextInfo scores_types_list[] =
402 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
403 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
404 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
409 static struct ValueTextInfo game_speeds_list_normal[] =
420 static struct ValueTextInfo game_speeds_list_extended[] =
422 { 1000, "1 fps (Extremely Slow)" },
427 { 29, "35 fps (Original Supaplex)" },
429 { 20, "50 fps (=== Normal Speed ===)" },
430 { 16, "60 fps (60 Hz VSync Speed)" },
431 { 14, "70 fps (Maximum Supaplex)" },
435 { 1, "1000 fps (Extremely Fast)" },
440 static struct ValueTextInfo *game_speeds_list;
442 static struct ValueTextInfo scroll_delays_list[] =
444 { 0, "0 Tiles (No Scroll Delay)" },
447 { 3, "3 Tiles (Default)" },
452 { 8, "8 Tiles (Maximum Scroll Delay)"},
457 static struct StringValueTextInfo snapshot_modes_list[] =
459 { STR_SNAPSHOT_MODE_OFF, "Off" },
460 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
461 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
462 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
467 static struct ValueTextInfo volumes_list[] =
487 static struct StringValueTextInfo touch_controls_list[] =
489 { TOUCH_CONTROL_OFF, "Off" },
490 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
491 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
492 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
497 static struct ValueTextInfo distances_list[] =
512 static struct ValueTextInfo transparencies_list[] =
514 { 0, "0 % (Opaque)" },
524 { 100, "100 % (Invisible)" },
529 static struct ValueTextInfo grid_sizes_list[] =
565 static int align_xoffset = 0;
566 static int align_yoffset = 0;
568 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
569 (s) <= GAME_MODE_SETUP ? (s) : \
570 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
572 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
573 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
575 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
576 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
577 (i) <= INFO_MODE_LEVELSET ? (i) : \
580 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
581 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
582 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
583 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
584 SETUP_MODE_CHOOSE_ARTWORK : \
585 SETUP_MODE_CHOOSE_OTHER)
587 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
588 menu.draw_xoffset[GAME_MODE_INFO] : \
589 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
590 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
591 menu.draw_yoffset[GAME_MODE_INFO] : \
592 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
593 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
594 menu.extra_spacing[GAME_MODE_INFO] : \
595 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
597 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
598 menu.draw_xoffset[GAME_MODE_SETUP] : \
599 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
600 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
601 menu.draw_yoffset[GAME_MODE_SETUP] : \
602 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
603 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
604 menu.extra_spacing[GAME_MODE_SETUP] : \
605 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
607 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
608 DRAW_XOFFSET_INFO(info_mode) : \
609 (s) == GAME_MODE_SETUP ? \
610 DRAW_XOFFSET_SETUP(setup_mode) : \
611 menu.draw_xoffset[DRAW_MODE(s)])
612 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
613 DRAW_YOFFSET_INFO(info_mode) : \
614 (s) == GAME_MODE_SETUP ? \
615 DRAW_YOFFSET_SETUP(setup_mode) : \
616 menu.draw_yoffset[DRAW_MODE(s)])
617 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
618 EXTRA_SPACING_INFO(info_mode) : \
619 (s) == GAME_MODE_SETUP ? \
620 EXTRA_SPACING_SETUP(setup_mode) : \
621 menu.extra_spacing[DRAW_MODE(s)])
623 #define mSX (SX + DRAW_XOFFSET(game_status))
624 #define mSY (SY + DRAW_YOFFSET(game_status))
626 #define amSX (mSX + align_xoffset)
627 #define amSY (mSY + align_yoffset)
629 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
630 menu.list_size[game_status] : \
631 MAX_MENU_ENTRIES_ON_SCREEN)
633 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
634 NUM_MENU_ENTRIES_ON_SCREEN)
637 // title display and control definitions
639 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
640 2 * MAX_NUM_TITLE_MESSAGES)
642 #define NO_DIRECT_LEVEL_SELECT (-1)
645 static int num_title_screens = 0;
647 struct TitleControlInfo
656 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
658 // main menu display and control definitions
660 #define MAIN_CONTROL_NAME 0
661 #define MAIN_CONTROL_LEVELS 1
662 #define MAIN_CONTROL_SCORES 2
663 #define MAIN_CONTROL_EDITOR 3
664 #define MAIN_CONTROL_INFO 4
665 #define MAIN_CONTROL_GAME 5
666 #define MAIN_CONTROL_SETUP 6
667 #define MAIN_CONTROL_QUIT 7
668 #define MAIN_CONTROL_PREV_LEVEL 8
669 #define MAIN_CONTROL_NEXT_LEVEL 9
670 #define MAIN_CONTROL_FIRST_LEVEL 10
671 #define MAIN_CONTROL_LAST_LEVEL 11
672 #define MAIN_CONTROL_LEVEL_NUMBER 12
673 #define MAIN_CONTROL_LEVEL_INFO_1 13
674 #define MAIN_CONTROL_LEVEL_INFO_2 14
675 #define MAIN_CONTROL_LEVEL_NAME 15
676 #define MAIN_CONTROL_LEVEL_AUTHOR 16
677 #define MAIN_CONTROL_LEVEL_YEAR 17
678 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
679 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
680 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
681 #define MAIN_CONTROL_TITLE_1 21
682 #define MAIN_CONTROL_TITLE_2 22
683 #define MAIN_CONTROL_TITLE_3 23
685 static char str_main_text_name[10];
686 static char str_main_text_first_level[10];
687 static char str_main_text_last_level[10];
688 static char str_main_text_level_number[10];
690 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
692 static char *main_text_name = str_main_text_name;
693 static char *main_text_first_level = str_main_text_first_level;
694 static char *main_text_last_level = str_main_text_last_level;
695 static char *main_text_level_number = str_main_text_level_number;
696 static char *main_text_levels = "Levelset";
697 static char *main_text_scores = "Hall Of Fame";
698 static char *main_text_editor = "Level Creator";
699 static char *main_text_info = "Info Screen";
700 static char *main_text_game = "Start Game";
701 static char *main_text_setup = "Setup";
702 static char *main_text_quit = "Quit";
703 static char *main_text_level_name = level.name;
704 static char *main_text_level_author = level.author;
705 static char *main_text_level_year = NULL;
706 static char *main_text_level_imported_from = NULL;
707 static char *main_text_level_imported_by = NULL;
708 static char *main_text_level_tested_by = NULL;
709 static char *main_text_title_1 = NULL;
710 static char *main_text_title_2 = NULL;
711 static char *main_text_title_3 = NULL;
713 extern char debug_xsn_mode[];
715 struct MainControlInfo
719 struct MenuPosInfo *pos_button;
722 struct TextPosInfo *pos_text;
725 struct TextPosInfo *pos_input;
729 static struct MainControlInfo main_controls[] =
733 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
734 &menu.main.text.name, &main_text_name,
735 &menu.main.input.name, &setup.player_name,
739 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
740 &menu.main.text.levels, &main_text_levels,
745 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
746 &menu.main.text.scores, &main_text_scores,
751 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
752 &menu.main.text.editor, &main_text_editor,
757 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
758 &menu.main.text.info, &main_text_info,
763 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
764 &menu.main.text.game, &main_text_game,
769 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
770 &menu.main.text.setup, &main_text_setup,
775 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
776 &menu.main.text.quit, &main_text_quit,
780 MAIN_CONTROL_PREV_LEVEL,
786 MAIN_CONTROL_NEXT_LEVEL,
792 MAIN_CONTROL_FIRST_LEVEL,
794 &menu.main.text.first_level, &main_text_first_level,
798 MAIN_CONTROL_LAST_LEVEL,
800 &menu.main.text.last_level, &main_text_last_level,
804 MAIN_CONTROL_LEVEL_NUMBER,
806 &menu.main.text.level_number, &main_text_level_number,
810 MAIN_CONTROL_LEVEL_INFO_1,
812 &menu.main.text.level_info_1, NULL,
816 MAIN_CONTROL_LEVEL_INFO_2,
818 &menu.main.text.level_info_2, NULL,
822 MAIN_CONTROL_LEVEL_NAME,
824 &menu.main.text.level_name, &main_text_level_name,
828 MAIN_CONTROL_LEVEL_AUTHOR,
830 &menu.main.text.level_author, &main_text_level_author,
834 MAIN_CONTROL_LEVEL_YEAR,
836 &menu.main.text.level_year, &main_text_level_year,
840 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
842 &menu.main.text.level_imported_from, &main_text_level_imported_from,
846 MAIN_CONTROL_LEVEL_IMPORTED_BY,
848 &menu.main.text.level_imported_by, &main_text_level_imported_by,
852 MAIN_CONTROL_LEVEL_TESTED_BY,
854 &menu.main.text.level_tested_by, &main_text_level_tested_by,
858 MAIN_CONTROL_TITLE_1,
860 &menu.main.text.title_1, &main_text_title_1,
864 MAIN_CONTROL_TITLE_2,
866 &menu.main.text.title_2, &main_text_title_2,
870 MAIN_CONTROL_TITLE_3,
872 &menu.main.text.title_3, &main_text_title_3,
885 static int getTitleScreenGraphic(int nr, boolean initial)
887 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
890 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
892 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
896 static int getTitleScreenGameMode(boolean initial)
898 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
902 static int getTitleMessageGameMode(boolean initial)
904 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
907 static int getTitleAnimMode(struct TitleControlInfo *tci)
909 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
911 return base + tci->local_nr;
915 static int getTitleScreenBackground(boolean initial)
917 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
922 static int getTitleMessageBackground(int nr, boolean initial)
924 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
928 static int getTitleBackground(int nr, boolean initial, boolean is_image)
930 int base = (is_image ?
931 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
932 IMG_BACKGROUND_TITLESCREEN_1) :
933 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
934 IMG_BACKGROUND_TITLEMESSAGE_1));
935 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
936 IMG_BACKGROUND_TITLE);
937 int graphic_local = base + nr;
939 if (graphic_info[graphic_local].bitmap != NULL)
940 return graphic_local;
942 if (graphic_info[graphic_global].bitmap != NULL)
943 return graphic_global;
945 return IMG_UNDEFINED;
948 static int getTitleSound(struct TitleControlInfo *tci)
950 boolean is_image = tci->is_image;
951 int initial = tci->initial;
952 int nr = tci->local_nr;
953 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
954 int base = (is_image ?
955 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
956 SND_BACKGROUND_TITLESCREEN_1) :
957 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
958 SND_BACKGROUND_TITLEMESSAGE_1));
959 int sound_global = menu.sound[mode];
960 int sound_local = base + nr;
963 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
964 nr, initial, is_image,
965 sound_global, getSoundListEntry(sound_global)->filename,
966 sound_local, getSoundListEntry(sound_local)->filename);
969 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
972 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
975 return SND_UNDEFINED;
978 static int getTitleMusic(struct TitleControlInfo *tci)
980 boolean is_image = tci->is_image;
981 int initial = tci->initial;
982 int nr = tci->local_nr;
983 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
984 int base = (is_image ?
985 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
986 MUS_BACKGROUND_TITLESCREEN_1) :
987 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
988 MUS_BACKGROUND_TITLEMESSAGE_1));
989 int music_global = menu.music[mode];
990 int music_local = base + nr;
993 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
994 nr, initial, is_image,
995 music_global, getMusicListEntry(music_global)->filename,
996 music_local, getMusicListEntry(music_local)->filename);
999 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1002 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1003 return music_global;
1005 return MUS_UNDEFINED;
1008 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1010 boolean is_image = tci->is_image;
1011 boolean initial = tci->initial;
1012 boolean first = tci->first;
1013 int nr = tci->local_nr;
1014 struct TitleMessageInfo tmi;
1015 struct TitleFadingInfo ti;
1017 tmi = (is_image ? (initial ? (first ?
1018 titlescreen_initial_first[nr] :
1019 titlescreen_initial[nr])
1021 titlescreen_first[nr] :
1023 : (initial ? (first ?
1024 titlemessage_initial_first[nr] :
1025 titlemessage_initial[nr])
1027 titlemessage_first[nr] :
1028 titlemessage[nr])));
1030 ti.fade_mode = tmi.fade_mode;
1031 ti.fade_delay = tmi.fade_delay;
1032 ti.post_delay = tmi.post_delay;
1033 ti.auto_delay = tmi.auto_delay;
1034 ti.auto_delay_unit = tmi.auto_delay_unit;
1039 static int compareTitleControlInfo(const void *object1, const void *object2)
1041 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1042 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1045 if (tci1->initial != tci2->initial)
1046 compare_result = (tci1->initial ? -1 : +1);
1047 else if (tci1->sort_priority != tci2->sort_priority)
1048 compare_result = tci1->sort_priority - tci2->sort_priority;
1049 else if (tci1->is_image != tci2->is_image)
1050 compare_result = (tci1->is_image ? -1 : +1);
1052 compare_result = tci1->local_nr - tci2->local_nr;
1054 return compare_result;
1057 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1059 int nr, int sort_priority)
1061 title_controls[num_title_screens].is_image = is_image;
1062 title_controls[num_title_screens].initial = initial;
1063 title_controls[num_title_screens].local_nr = nr;
1064 title_controls[num_title_screens].sort_priority = sort_priority;
1066 title_controls[num_title_screens].first = FALSE; // will be set later
1068 num_title_screens++;
1071 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1075 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1077 int graphic = getTitleScreenGraphic(i, initial);
1078 Bitmap *bitmap = graphic_info[graphic].bitmap;
1079 int sort_priority = graphic_info[graphic].sort_priority;
1082 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1085 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1087 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1088 char *filename = getLevelSetTitleMessageFilename(i, initial);
1089 int sort_priority = tmi->sort_priority;
1091 if (filename != NULL)
1092 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1096 static void InitializeTitleControls(boolean show_title_initial)
1098 num_title_screens = 0;
1100 // 1st step: initialize title screens for game start (only when starting)
1101 if (show_title_initial)
1102 InitializeTitleControls_CheckTitleInfo(TRUE);
1104 // 2nd step: initialize title screens for current level set
1105 InitializeTitleControls_CheckTitleInfo(FALSE);
1107 // sort title screens according to sort_priority and title number
1108 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1109 compareTitleControlInfo);
1111 // mark first title screen
1112 title_controls[0].first = TRUE;
1115 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1117 return (pos != NULL && pos->x != -1 && pos->y != -1);
1120 static boolean visibleTextPos(struct TextPosInfo *pos)
1122 return (pos != NULL && pos->x != -1 && pos->y != -1);
1125 static void InitializeMainControls(void)
1127 boolean local_team_mode = (!network.enabled && setup.team_mode);
1130 // set main control text values to dynamically determined values
1131 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1133 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1134 menu.main.text.first_level.size));
1135 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1136 menu.main.text.last_level.size));
1137 strcpy(main_text_level_number, int2str(level_nr,
1138 menu.main.text.level_number.size));
1140 main_text_level_year = leveldir_current->year;
1141 main_text_level_imported_from = leveldir_current->imported_from;
1142 main_text_level_imported_by = leveldir_current->imported_by;
1143 main_text_level_tested_by = leveldir_current->tested_by;
1145 main_text_title_1 = getConfigProgramTitleString();
1146 main_text_title_2 = getConfigProgramCopyrightString();
1147 main_text_title_3 = getConfigProgramCompanyString();
1149 // set main control screen positions to dynamically determined values
1150 for (i = 0; main_controls[i].nr != -1; i++)
1152 struct MainControlInfo *mci = &main_controls[i];
1154 struct MenuPosInfo *pos_button = mci->pos_button;
1155 struct TextPosInfo *pos_text = mci->pos_text;
1156 struct TextPosInfo *pos_input = mci->pos_input;
1157 char *text = (mci->text ? *mci->text : NULL);
1158 char *input = (mci->input ? *mci->input : NULL);
1159 int button_graphic = mci->button_graphic;
1160 int font_text = (pos_text ? pos_text->font : -1);
1161 int font_input = (pos_input ? pos_input->font : -1);
1163 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1164 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1165 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1166 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1167 int text_chars = (text != NULL ? strlen(text) : 0);
1168 int input_chars = (input != NULL ? strlen(input) : 0);
1171 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1173 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1174 int text_width = font_text_width * text_chars;
1175 int text_height = font_text_height;
1176 int input_width = font_input_width * input_chars;
1177 int input_height = font_input_height;
1179 if (nr == MAIN_CONTROL_NAME)
1181 menu.main.input.name.width = input_width;
1182 menu.main.input.name.height = input_height;
1185 if (pos_button != NULL) // (x/y may be -1/-1 here)
1187 pos_button->width = button_width;
1188 pos_button->height = button_height;
1191 if (pos_text != NULL) // (x/y may be -1/-1 here)
1193 // calculate text size -- needed for text alignment
1194 boolean calculate_text_size = (text != NULL);
1196 if (pos_text->width == -1 || calculate_text_size)
1197 pos_text->width = text_width;
1198 if (pos_text->height == -1 || calculate_text_size)
1199 pos_text->height = text_height;
1201 if (visibleMenuPos(pos_button))
1203 if (pos_text->x == -1)
1204 pos_text->x = pos_button->x + pos_button->width;
1205 if (pos_text->y == -1)
1207 pos_button->y + (pos_button->height - pos_text->height) / 2;
1211 if (pos_input != NULL) // (x/y may be -1/-1 here)
1213 if (visibleTextPos(pos_text))
1215 if (pos_input->x == -1)
1216 pos_input->x = pos_text->x + pos_text->width;
1217 if (pos_input->y == -1)
1218 pos_input->y = pos_text->y;
1221 if (pos_input->width == -1)
1222 pos_input->width = input_width;
1223 if (pos_input->height == -1)
1224 pos_input->height = input_height;
1229 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1230 int graphic, boolean pressed)
1232 struct GraphicInfo *g = &graphic_info[graphic];
1235 int xoffset = (pressed ? g->pressed_xoffset : 0);
1236 int yoffset = (pressed ? g->pressed_yoffset : 0);
1238 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1240 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1241 g->width, g->height, dst_x, dst_y);
1244 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1245 boolean active_input,
1246 boolean pressed_button)
1250 for (i = 0; main_controls[i].nr != -1; i++)
1252 struct MainControlInfo *mci = &main_controls[i];
1254 if (mci->nr == nr || nr == -1)
1256 struct MenuPosInfo *pos_button = mci->pos_button;
1257 struct TextPosInfo *pos_text = mci->pos_text;
1258 struct TextPosInfo *pos_input = mci->pos_input;
1259 char *text = (mci->text ? *mci->text : NULL);
1260 char *input = (mci->input ? *mci->input : NULL);
1261 int button_graphic = mci->button_graphic;
1262 int font_text = (pos_text ? pos_text->font : -1);
1263 int font_input = (pos_input ? pos_input->font : -1);
1267 button_graphic = BUTTON_ACTIVE(button_graphic);
1268 font_text = FONT_ACTIVE(font_text);
1273 font_input = FONT_ACTIVE(font_input);
1276 if (visibleMenuPos(pos_button))
1278 struct MenuPosInfo *pos = pos_button;
1279 int x = mSX + pos->x;
1280 int y = mSY + pos->y;
1282 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1283 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1286 if (visibleTextPos(pos_text) && text != NULL)
1288 struct TextPosInfo *pos = pos_text;
1289 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1290 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1293 // (check why/if this is needed)
1294 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1296 DrawText(x, y, text, font_text);
1299 if (visibleTextPos(pos_input) && input != NULL)
1301 struct TextPosInfo *pos = pos_input;
1302 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1303 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1306 // (check why/if this is needed)
1307 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1309 DrawText(x, y, input, font_input);
1315 static void DrawCursorAndText_Main(int nr, boolean active_text,
1316 boolean pressed_button)
1318 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1322 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1323 boolean pressed_button)
1325 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1329 static struct MainControlInfo *getMainControlInfo(int nr)
1333 for (i = 0; main_controls[i].nr != -1; i++)
1334 if (main_controls[i].nr == nr)
1335 return &main_controls[i];
1340 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1345 int rect_x = ALIGNED_TEXT_XPOS(rect);
1346 int rect_y = ALIGNED_TEXT_YPOS(rect);
1348 return (x >= rect_x && x < rect_x + rect->width &&
1349 y >= rect_y && y < rect_y + rect->height);
1352 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1357 int rect_x = ALIGNED_TEXT_XPOS(rect);
1358 int rect_y = ALIGNED_TEXT_YPOS(rect);
1361 Debug("screens:insideTextPosRect",
1362 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1363 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1364 (x >= rect_x && x < rect_x + rect->width &&
1365 y >= rect_y && y < rect_y + rect->height));
1368 return (x >= rect_x && x < rect_x + rect->width &&
1369 y >= rect_y && y < rect_y + rect->height);
1372 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1374 int rect_width = preview->xsize * preview->tile_size;
1375 int rect_height = preview->ysize * preview->tile_size;
1376 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1377 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1379 return (x >= rect_x && x < rect_x + rect_width &&
1380 y >= rect_y && y < rect_y + rect_height);
1383 static void AdjustScrollbar(int id, int items_max, int items_visible,
1386 struct GadgetInfo *gi = screen_gadget[id];
1388 if (item_position > items_max - items_visible)
1389 item_position = items_max - items_visible;
1391 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1392 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1393 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1396 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1398 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1402 static void clearMenuListArea(void)
1404 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1406 // correct scrollbar position if placed outside menu (playfield) area
1407 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1408 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1410 // clear menu list area, but not title or scrollbar
1411 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1412 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1415 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1417 static int cursor_array[MAX_LEV_FIELDY];
1418 int x = amSX + TILEX * xpos;
1419 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1424 cursor_array[ypos] = graphic;
1426 graphic = cursor_array[ypos];
1430 graphic = BUTTON_ACTIVE(graphic);
1432 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1433 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1436 static void initCursor(int ypos, int graphic)
1438 drawCursorExt(0, ypos, FALSE, graphic);
1441 static void drawCursor(int ypos, boolean active)
1443 drawCursorExt(0, ypos, active, -1);
1446 static void drawCursorXY(int xpos, int ypos, int graphic)
1448 drawCursorExt(xpos, ypos, FALSE, graphic);
1451 static void drawChooseTreeCursor(int ypos, boolean active)
1453 drawCursorExt(0, ypos, active, -1);
1456 static int getChooseTreeEditFont(boolean active)
1458 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1461 static int getChooseTreeEditXPos(int pos)
1463 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1464 int xoffset = (has_scrollbar ? -1 : 0);
1465 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1466 int sx = amSX + xpos * TILEX;
1467 int font_nr = getChooseTreeEditFont(FALSE);
1468 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1470 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1473 static int getChooseTreeEditYPos(int ypos_raw)
1475 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1476 int sy = amSY + ypos * TILEY;
1481 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1483 int sx = getChooseTreeEditXPos(POS_LEFT);
1484 int sy = getChooseTreeEditYPos(ypos_raw);
1485 int font_nr = getChooseTreeEditFont(active);
1487 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1490 static void DrawHeadline(void)
1492 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1493 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1496 static void DrawTitleScreenImage(int nr, boolean initial)
1498 int graphic = getTitleScreenGraphic(nr, initial);
1499 Bitmap *bitmap = graphic_info[graphic].bitmap;
1500 int width = graphic_info[graphic].width;
1501 int height = graphic_info[graphic].height;
1502 int src_x = graphic_info[graphic].src_x;
1503 int src_y = graphic_info[graphic].src_y;
1509 if (width > WIN_XSIZE)
1511 // image width too large for window => center image horizontally
1512 src_x = (width - WIN_XSIZE) / 2;
1516 if (height > WIN_YSIZE)
1518 // image height too large for window => center image vertically
1519 src_y = (height - WIN_YSIZE) / 2;
1523 // always display title screens centered
1524 dst_x = (WIN_XSIZE - width) / 2;
1525 dst_y = (WIN_YSIZE - height) / 2;
1527 SetDrawBackgroundMask(REDRAW_ALL);
1528 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1530 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1532 if (DrawingOnBackground(dst_x, dst_y))
1533 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1535 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1537 redraw_mask = REDRAW_ALL;
1540 static void DrawTitleScreenMessage(int nr, boolean initial)
1542 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1543 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1545 if (filename == NULL)
1548 // force TITLE font on title message screen
1549 SetFontStatus(getTitleMessageGameMode(initial));
1551 // if chars *and* width set to "-1", automatically determine width
1552 if (tmi->chars == -1 && tmi->width == -1)
1553 tmi->width = viewport.window[game_status].width;
1555 // if lines *and* height set to "-1", automatically determine height
1556 if (tmi->lines == -1 && tmi->height == -1)
1557 tmi->height = viewport.window[game_status].height;
1559 // if chars set to "-1", automatically determine by text and font width
1560 if (tmi->chars == -1)
1561 tmi->chars = tmi->width / getFontWidth(tmi->font);
1563 tmi->width = tmi->chars * getFontWidth(tmi->font);
1565 // if lines set to "-1", automatically determine by text and font height
1566 if (tmi->lines == -1)
1567 tmi->lines = tmi->height / getFontHeight(tmi->font);
1569 tmi->height = tmi->lines * getFontHeight(tmi->font);
1571 // if x set to "-1", automatically determine by width and alignment
1573 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1575 // if y set to "-1", automatically determine by height and alignment
1577 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1579 SetDrawBackgroundMask(REDRAW_ALL);
1580 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1582 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1584 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1585 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1586 tmi->autowrap, tmi->centered, tmi->parse_comments);
1591 static void DrawTitleScreen(void)
1593 KeyboardAutoRepeatOff();
1595 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1598 static boolean CheckTitleScreen(boolean levelset_has_changed)
1600 static boolean show_title_initial = TRUE;
1601 boolean show_titlescreen = FALSE;
1603 // needed to be able to skip title screen, if no image or message defined
1604 InitializeTitleControls(show_title_initial);
1606 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1607 show_titlescreen = TRUE;
1609 // show initial title images and messages only once at program start
1610 show_title_initial = FALSE;
1612 return (show_titlescreen && num_title_screens > 0);
1615 void DrawMainMenu(void)
1617 static LevelDirTree *leveldir_last_valid = NULL;
1618 boolean levelset_has_changed = FALSE;
1619 int fade_mask = REDRAW_FIELD;
1621 LimitScreenUpdates(FALSE);
1623 FadeSetLeaveScreen();
1625 // do not fade out here -- function may continue and fade on editor screen
1628 FadeMenuSoundsAndMusic();
1630 ExpireSoundLoops(FALSE);
1632 KeyboardAutoRepeatOn();
1634 audio.sound_deactivated = FALSE;
1638 // needed if last screen was the playing screen, invoked from level editor
1639 if (level_editor_test_game)
1641 CloseDoor(DOOR_CLOSE_ALL);
1643 SetGameStatus(GAME_MODE_EDITOR);
1650 // leveldir_current may be invalid (level group, parent link, node copy)
1651 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1653 if (leveldir_current != leveldir_last_valid)
1655 UpdateLastPlayedLevels_TreeInfo();
1657 levelset_has_changed = TRUE;
1660 // store valid level series information
1661 leveldir_last_valid = leveldir_current;
1663 init_last = init; // switch to new busy animation
1665 // needed if last screen (level choice) changed graphics, sounds or music
1666 ReloadCustomArtwork(0);
1668 if (CheckTitleScreen(levelset_has_changed))
1670 SetGameStatus(GAME_MODE_TITLE);
1677 if (redraw_mask & REDRAW_ALL)
1678 fade_mask = REDRAW_ALL;
1681 fade_mask = REDRAW_ALL;
1685 // needed if different viewport properties defined for menues
1686 ChangeViewportPropertiesIfNeeded();
1688 SetDrawtoField(DRAW_TO_BACKBUFFER);
1690 // level_nr may have been set to value over handicap with level editor
1691 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1692 level_nr = leveldir_current->handicap_level;
1694 LoadLevel(level_nr);
1695 LoadScore(level_nr);
1697 SaveLevelSetup_SeriesInfo();
1699 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1700 SetDrawDeactivationMask(REDRAW_NONE);
1701 SetDrawBackgroundMask(REDRAW_FIELD);
1703 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1706 if (fade_mask == REDRAW_ALL)
1707 RedrawGlobalBorder();
1712 InitializeMainControls();
1714 DrawCursorAndText_Main(-1, FALSE, FALSE);
1715 DrawPreviewLevelInitial();
1716 DrawNetworkPlayers();
1718 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1721 if (TAPE_IS_EMPTY(tape))
1723 DrawCompleteVideoDisplay();
1725 PlayMenuSoundsAndMusic();
1727 // create gadgets for main menu screen
1728 FreeScreenGadgets();
1729 CreateScreenGadgets();
1731 // may be required if audio buttons shown on tape and changed in setup menu
1733 CreateGameButtons();
1735 // map gadgets for main menu screen
1737 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1738 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1740 // copy actual game door content to door double buffer for OpenDoor()
1741 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1742 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1744 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1746 DrawMaskedBorder(fade_mask);
1751 // update screen area with special editor door
1752 redraw_mask |= REDRAW_ALL;
1755 SetMouseCursor(CURSOR_DEFAULT);
1757 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1759 SyncEmscriptenFilesystem();
1761 // needed once to upload tapes (after program start or after user change)
1765 static void gotoTopLevelDir(void)
1767 // move upwards until inside (but not above) top level directory
1768 while (leveldir_current->node_parent &&
1769 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1771 // write a "path" into level tree for easy navigation to last level
1772 if (leveldir_current->node_parent->node_group->cl_first == -1)
1774 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1775 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1776 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1777 int cl_first, cl_cursor;
1779 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1780 cl_cursor = leveldir_pos - cl_first;
1782 leveldir_current->node_parent->node_group->cl_first = cl_first;
1783 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1786 leveldir_current = leveldir_current->node_parent;
1790 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1792 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1794 return (use_frame_counter ? video.frame_counter : Counter());
1797 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1798 struct TitleFadingInfo *fi)
1800 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1803 static void ResetTitleAutoDelay(unsigned int *counter_var,
1804 struct TitleFadingInfo *fi)
1806 *counter_var = getAutoDelayCounter(fi);
1809 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1811 static unsigned int title_delay = 0;
1812 static int title_screen_nr = 0;
1813 static int last_sound = -1, last_music = -1;
1814 boolean return_to_main_menu = FALSE;
1815 struct TitleControlInfo *tci;
1818 if (button == MB_MENU_INITIALIZE)
1821 title_screen_nr = 0;
1822 tci = &title_controls[title_screen_nr];
1824 SetAnimStatus(getTitleAnimMode(tci));
1826 last_sound = SND_UNDEFINED;
1827 last_music = MUS_UNDEFINED;
1829 if (num_title_screens != 0)
1831 FadeSetEnterScreen();
1833 // use individual title fading instead of global "enter screen" fading
1834 fading = getTitleFading(tci);
1837 if (game_status_last_screen == GAME_MODE_INFO)
1839 if (num_title_screens == 0)
1841 // switch game mode from title screen mode back to info screen mode
1842 SetGameStatus(GAME_MODE_INFO);
1844 // store that last screen was info screen, not main menu screen
1845 game_status_last_screen = GAME_MODE_INFO;
1847 DrawInfoScreen_NotAvailable("Title screen information:",
1848 "No title screen for this level set.");
1853 FadeMenuSoundsAndMusic();
1855 FadeOut(REDRAW_ALL);
1857 // title screens may have different window size
1858 ChangeViewportPropertiesIfNeeded();
1860 // only required to update logic for redrawing global border
1864 DrawTitleScreenImage(tci->local_nr, tci->initial);
1866 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1868 sound = getTitleSound(tci);
1869 music = getTitleMusic(tci);
1871 if (sound != last_sound)
1872 PlayMenuSoundExt(sound);
1873 if (music != last_music)
1874 PlayMenuMusicExt(music);
1879 SetMouseCursor(CURSOR_NONE);
1883 ResetTitleAutoDelay(&title_delay, &fading);
1888 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1889 button = MB_MENU_CHOICE;
1891 if (button == MB_MENU_LEAVE)
1893 return_to_main_menu = TRUE;
1895 else if (button == MB_MENU_CHOICE)
1897 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1899 SetGameStatus(GAME_MODE_INFO);
1901 info_mode = INFO_MODE_MAIN;
1910 if (title_screen_nr < num_title_screens)
1912 tci = &title_controls[title_screen_nr];
1914 SetAnimStatus(getTitleAnimMode(tci));
1916 sound = getTitleSound(tci);
1917 music = getTitleMusic(tci);
1919 if (last_sound != SND_UNDEFINED && sound != last_sound)
1920 FadeSound(last_sound);
1921 if (last_music != MUS_UNDEFINED && music != last_music)
1924 fading = getTitleFading(tci);
1926 FadeOut(REDRAW_ALL);
1929 DrawTitleScreenImage(tci->local_nr, tci->initial);
1931 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1933 sound = getTitleSound(tci);
1934 music = getTitleMusic(tci);
1936 if (sound != last_sound)
1937 PlayMenuSoundExt(sound);
1938 if (music != last_music)
1939 PlayMenuMusicExt(music);
1946 ResetTitleAutoDelay(&title_delay, &fading);
1950 FadeMenuSoundsAndMusic();
1952 return_to_main_menu = TRUE;
1956 if (return_to_main_menu)
1958 SetMouseCursor(CURSOR_DEFAULT);
1960 // force full menu screen redraw after displaying title screens
1961 redraw_mask = REDRAW_ALL;
1963 if (game_status_last_screen == GAME_MODE_INFO)
1965 SetGameStatus(GAME_MODE_INFO);
1967 info_mode = INFO_MODE_MAIN;
1971 else // default: return to main menu
1973 SetGameStatus(GAME_MODE_MAIN);
1980 static void HandleMainMenu_ToggleTeamMode(void)
1982 setup.team_mode = !setup.team_mode;
1984 InitializeMainControls();
1985 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
1987 DrawPreviewPlayers();
1990 static void HandleMainMenu_SelectLevel(int step, int direction,
1991 int selected_level_nr)
1993 int old_level_nr = level_nr;
1996 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1997 new_level_nr = selected_level_nr;
1999 new_level_nr = old_level_nr + step * direction;
2001 if (new_level_nr < leveldir_current->first_level)
2002 new_level_nr = leveldir_current->first_level;
2003 if (new_level_nr > leveldir_current->last_level)
2004 new_level_nr = leveldir_current->last_level;
2006 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2008 // skipping levels is only allowed when trying to skip single level
2009 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2010 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2012 leveldir_current->handicap_level++;
2013 SaveLevelSetup_SeriesInfo();
2016 new_level_nr = leveldir_current->handicap_level;
2019 if (new_level_nr != old_level_nr)
2021 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2023 PlaySound(SND_MENU_ITEM_SELECTING);
2025 level_nr = new_level_nr;
2027 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2028 int2str(level_nr, menu.main.text.level_number.size),
2029 mci->pos_text->font);
2031 LoadLevel(level_nr);
2032 DrawPreviewLevelInitial();
2036 DrawCompleteVideoDisplay();
2038 SaveLevelSetup_SeriesInfo();
2040 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2042 // force redraw of playfield area (may be reset at this point)
2043 redraw_mask |= REDRAW_FIELD;
2047 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2049 static int choice = MAIN_CONTROL_GAME;
2050 static boolean button_pressed_last = FALSE;
2051 boolean button_pressed = FALSE;
2053 int i = 0; // needed to prevent compiler warning due to bad code below
2055 if (button == MB_MENU_INITIALIZE)
2057 DrawCursorAndText_Main(choice, TRUE, FALSE);
2062 if (mx || my) // mouse input
2066 for (i = 0; main_controls[i].nr != -1; i++)
2068 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2069 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2070 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2072 pos = main_controls[i].nr;
2078 // check if level preview was clicked
2079 if (insidePreviewRect(&preview, mx - SX, my - SY))
2080 pos = MAIN_CONTROL_GAME;
2082 // handle pressed/unpressed state for active/inactive menu buttons
2083 // (if pos != -1, "i" contains index position corresponding to "pos")
2085 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2086 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2087 button_pressed = TRUE;
2089 if (button_pressed != button_pressed_last)
2091 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2094 PlaySound(SND_MENU_BUTTON_PRESSING);
2096 PlaySound(SND_MENU_BUTTON_RELEASING);
2099 else if (dx || dy) // keyboard input
2101 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2102 choice == MAIN_CONTROL_SETUP))
2103 button = MB_MENU_CHOICE;
2108 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2110 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2112 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2114 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2116 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2118 CloseDoor(DOOR_CLOSE_2);
2120 SetGameStatus(GAME_MODE_LEVELNR);
2122 DrawChooseLevelNr();
2124 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2130 PlaySound(SND_MENU_ITEM_ACTIVATING);
2132 DrawCursorAndText_Main(choice, FALSE, FALSE);
2133 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2139 if (choice == MAIN_CONTROL_NAME)
2141 // special case: cursor left or right pressed -- toggle team mode
2142 HandleMainMenu_ToggleTeamMode();
2144 else if (choice != MAIN_CONTROL_INFO &&
2145 choice != MAIN_CONTROL_SETUP)
2147 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2153 PlaySound(SND_MENU_ITEM_SELECTING);
2155 if (pos == MAIN_CONTROL_NAME)
2158 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2160 // special case: menu text "name/team" clicked -- toggle team mode
2161 HandleMainMenu_ToggleTeamMode();
2165 if (setup.multiple_users)
2167 CloseDoor(DOOR_CLOSE_2);
2169 SetGameStatus(GAME_MODE_NAMES);
2171 DrawChoosePlayerName();
2175 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2181 else if (pos == MAIN_CONTROL_LEVELS)
2185 CloseDoor(DOOR_CLOSE_2);
2187 SetGameStatus(GAME_MODE_LEVELS);
2189 SaveLevelSetup_LastSeries();
2190 SaveLevelSetup_SeriesInfo();
2192 // restore level set if chosen from "last played level set" menu
2193 RestoreLastPlayedLevels(&leveldir_current);
2195 if (setup.internal.choose_from_top_leveldir)
2198 DrawChooseLevelSet();
2201 else if (pos == MAIN_CONTROL_SCORES)
2203 CloseDoor(DOOR_CLOSE_2);
2205 SetGameStatus(GAME_MODE_SCORES);
2207 DrawHallOfFame(level_nr);
2209 else if (pos == MAIN_CONTROL_EDITOR)
2211 if (leveldir_current->readonly &&
2212 setup.editor.show_read_only_warning)
2213 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2215 CloseDoor(DOOR_CLOSE_ALL);
2217 SetGameStatus(GAME_MODE_EDITOR);
2219 FadeSetEnterScreen();
2223 else if (pos == MAIN_CONTROL_INFO)
2225 CloseDoor(DOOR_CLOSE_2);
2227 SetGameStatus(GAME_MODE_INFO);
2229 info_mode = INFO_MODE_MAIN;
2233 else if (pos == MAIN_CONTROL_GAME)
2235 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2237 else if (pos == MAIN_CONTROL_SETUP)
2239 CloseDoor(DOOR_CLOSE_2);
2241 SetGameStatus(GAME_MODE_SETUP);
2243 setup_mode = SETUP_MODE_MAIN;
2247 else if (pos == MAIN_CONTROL_QUIT)
2249 SaveLevelSetup_LastSeries();
2250 SaveLevelSetup_SeriesInfo();
2252 #if defined(PLATFORM_EMSCRIPTEN)
2253 Request("Close the browser window to quit!", REQ_CONFIRM);
2255 if (!setup.ask_on_quit_program ||
2256 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2257 SetGameStatus(GAME_MODE_QUIT);
2263 button_pressed_last = button_pressed;
2267 // ============================================================================
2268 // info screen functions
2269 // ============================================================================
2271 static struct TokenInfo *info_info;
2272 static int num_info_info; // number of info entries shown on screen
2273 static int max_info_info; // total number of info entries in list
2275 static void execInfoTitleScreen(void)
2277 info_mode = INFO_MODE_TITLE;
2282 static void execInfoElements(void)
2284 info_mode = INFO_MODE_ELEMENTS;
2289 static void execInfoMusic(void)
2291 info_mode = INFO_MODE_MUSIC;
2296 static void execInfoCredits(void)
2298 info_mode = INFO_MODE_CREDITS;
2303 static void execInfoProgram(void)
2305 info_mode = INFO_MODE_PROGRAM;
2310 static void execInfoVersion(void)
2312 info_mode = INFO_MODE_VERSION;
2317 static void execInfoLevelSet(void)
2319 info_mode = INFO_MODE_LEVELSET;
2324 static void execExitInfo(void)
2326 SetGameStatus(GAME_MODE_MAIN);
2331 static struct TokenInfo info_info_main[] =
2333 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2334 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2335 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2336 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2337 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2338 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2339 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2340 { TYPE_EMPTY, NULL, "" },
2341 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2346 static int getMenuTextFont(int type)
2348 if (type & (TYPE_SWITCH |
2362 static struct TokenInfo *setup_info;
2363 static struct TokenInfo setup_info_input[];
2365 static struct TokenInfo *menu_info;
2367 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2368 int screen_pos, int menu_info_pos_raw,
2371 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2372 struct TokenInfo *ti = &token_info[pos];
2373 int xpos = MENU_SCREEN_START_XPOS;
2374 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2375 int font_nr = getMenuTextFont(ti->type);
2377 if (setup_mode == SETUP_MODE_INPUT)
2378 font_nr = FONT_MENU_1;
2381 font_nr = FONT_ACTIVE(font_nr);
2383 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2385 if (ti->type & ~TYPE_SKIP_ENTRY)
2386 drawCursor(screen_pos, active);
2389 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2392 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2395 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2398 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2401 static char *window_size_text;
2402 static char *scaling_type_text;
2403 static char *network_server_text;
2405 static void drawSetupValue(int, int);
2407 static void drawMenuInfoList(int first_entry, int num_page_entries,
2408 int max_page_entries)
2412 if (first_entry + num_page_entries > max_page_entries)
2415 clearMenuListArea();
2417 for (i = 0; i < num_page_entries; i++)
2419 int menu_info_pos = first_entry + i;
2420 struct TokenInfo *si = &menu_info[menu_info_pos];
2421 void *value_ptr = si->value;
2423 // set some entries to "unchangeable" according to other variables
2424 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2425 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2426 (value_ptr == &setup.sound_music && !audio.music_available) ||
2427 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2428 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2429 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2430 si->type |= TYPE_GHOSTED;
2432 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2433 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2434 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2435 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2436 else if (si->type & ~TYPE_SKIP_ENTRY)
2437 initCursor(i, IMG_MENU_BUTTON);
2439 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2441 if (si->type & TYPE_STRING)
2445 if (value_ptr == &network_server_text)
2446 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2448 if (gadget_id != -1)
2450 struct GadgetInfo *gi = screen_gadget[gadget_id];
2451 int xpos = MENU_SCREEN_START_XPOS;
2452 int ypos = MENU_SCREEN_START_YPOS + i;
2453 int x = mSX + xpos * 32;
2454 int y = mSY + ypos * 32;
2456 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2460 if (si->type & TYPE_VALUE &&
2461 menu_info == setup_info)
2462 drawSetupValue(i, menu_info_pos);
2466 static void DrawInfoScreen_Main(void)
2468 int fade_mask = REDRAW_FIELD;
2471 if (redraw_mask & REDRAW_ALL)
2472 fade_mask = REDRAW_ALL;
2475 fade_mask = REDRAW_ALL;
2478 FadeMenuSoundsAndMusic();
2480 FreeScreenGadgets();
2481 CreateScreenGadgets();
2483 // (needed after displaying title screens which disable auto repeat)
2484 KeyboardAutoRepeatOn();
2486 FadeSetLeaveScreen();
2490 // needed if different viewport properties defined for info screen
2491 ChangeViewportPropertiesIfNeeded();
2493 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2497 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2499 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2501 info_info = info_info_main;
2503 // determine maximal number of info entries that can be displayed on screen
2505 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2508 // determine maximal number of info entries available for menu of info screen
2510 for (i = 0; info_info[i].type != 0; i++)
2513 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2515 MapScreenGadgets(max_info_info);
2517 PlayMenuSoundsAndMusic();
2519 DrawMaskedBorder(fade_mask);
2524 static void changeSetupValue(int, int, int);
2526 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2527 int mode, int num_page_entries,
2528 int max_page_entries)
2530 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2531 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2532 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2533 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2534 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2535 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2536 int *num_page_entries_last = num_page_entries_all_last[game_status];
2537 int *choice_store = choice_stores[game_status];
2538 int *first_entry_store = first_entry_stores[game_status];
2539 int choice = choice_store[mode]; // starts with 0
2540 int first_entry = first_entry_store[mode]; // starts with 0
2542 int y = choice - first_entry;
2544 boolean position_set_by_scrollbar = (dx == 999);
2545 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2548 if (button == MB_MENU_INITIALIZE)
2550 // check if number of menu page entries has changed (may happen by change
2551 // of custom artwork definition value for 'list_size' for this menu screen)
2552 // (in this case, the last menu position most probably has to be corrected)
2553 if (num_page_entries != num_page_entries_last[mode])
2555 choice_store[mode] = first_entry_store[mode] = 0;
2557 choice = first_entry = 0;
2560 num_page_entries_last[mode] = num_page_entries;
2563 // advance to first valid menu entry
2564 while (choice < num_page_entries &&
2565 menu_info[choice].type & TYPE_SKIP_ENTRY)
2568 if (position_set_by_scrollbar)
2569 first_entry = first_entry_store[mode] = dy;
2571 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2572 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2574 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2576 if (choice < first_entry)
2578 choice = first_entry;
2580 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2583 else if (choice > first_entry + num_page_entries - 1)
2585 choice = first_entry + num_page_entries - 1;
2587 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2591 choice_store[mode] = choice;
2593 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2597 else if (button == MB_MENU_LEAVE)
2599 PlaySound(SND_MENU_ITEM_SELECTING);
2601 for (i = 0; i < max_page_entries; i++)
2603 if (menu_info[i].type & TYPE_LEAVE_MENU)
2605 void (*menu_callback_function)(void) = menu_info[i].value;
2609 menu_callback_function();
2611 break; // absolutely needed because function changes 'menu_info'!
2618 if (mx || my) // mouse input
2620 x = (mx - mSX) / 32;
2621 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2623 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2625 // move cursor instead of scrolling when already at start/end of list
2626 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2628 else if (dy == +1 * SCROLL_LINE &&
2629 first_entry + num_page_entries == max_page_entries)
2632 // handle scrolling screen one line or page
2634 y + dy > num_page_entries - 1)
2636 boolean redraw = FALSE;
2638 if (ABS(dy) == SCROLL_PAGE)
2639 step = num_page_entries - 1;
2641 if (dy < 0 && first_entry > 0)
2643 // scroll page/line up
2645 first_entry -= step;
2646 if (first_entry < 0)
2651 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2653 // scroll page/line down
2655 first_entry += step;
2656 if (first_entry + num_page_entries > max_page_entries)
2657 first_entry = MAX(0, max_page_entries - num_page_entries);
2664 choice += first_entry - first_entry_store[mode];
2666 if (choice < first_entry)
2668 choice = first_entry;
2670 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2673 else if (choice > first_entry + num_page_entries - 1)
2675 choice = first_entry + num_page_entries - 1;
2677 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2680 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2684 if (choice < first_entry ||
2685 choice > first_entry + num_page_entries - 1)
2686 first_entry += SIGN(dy);
2689 first_entry_store[mode] = first_entry;
2690 choice_store[mode] = choice;
2692 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2694 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2696 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2697 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2705 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2707 if (menu_info[choice].type & menu_navigation_type ||
2708 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2709 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2710 menu_info[choice].type & TYPE_PLAYER)
2711 button = MB_MENU_CHOICE;
2716 // jump to next non-empty menu entry (up or down)
2717 while (first_entry + y > 0 &&
2718 first_entry + y < max_page_entries - 1 &&
2719 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2722 if (!IN_VIS_MENU(x, y))
2724 choice += y - y_old;
2726 if (choice < first_entry)
2727 first_entry = choice;
2728 else if (choice > first_entry + num_page_entries - 1)
2729 first_entry = choice - num_page_entries + 1;
2731 if (first_entry >= 0 &&
2732 first_entry + num_page_entries <= max_page_entries)
2734 first_entry_store[mode] = first_entry;
2736 if (choice < first_entry)
2737 choice = first_entry;
2738 else if (choice > first_entry + num_page_entries - 1)
2739 choice = first_entry + num_page_entries - 1;
2741 choice_store[mode] = choice;
2743 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2745 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2747 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2748 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2755 if (!anyScrollbarGadgetActive() &&
2756 IN_VIS_MENU(x, y) &&
2757 mx < mx_right_border &&
2758 y >= 0 && y < num_page_entries)
2762 if (first_entry + y != choice &&
2763 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2765 PlaySound(SND_MENU_ITEM_ACTIVATING);
2767 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2768 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2770 choice = choice_store[mode] = first_entry + y;
2774 PlaySound(SND_MENU_ITEM_SELECTING);
2776 for (i = 0; menu_info[i].type != 0; i++)
2778 if (menu_info[i].type & TYPE_LEAVE_MENU)
2780 void (*menu_callback_function)(void) = menu_info[i].value;
2784 menu_callback_function();
2786 // absolutely needed because function changes 'menu_info'!
2794 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2796 PlaySound(SND_MENU_ITEM_SELECTING);
2798 // when selecting key headline, execute function for key value change
2799 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2800 menu_info[first_entry + y + 1].type & TYPE_KEY)
2803 // when selecting string value, execute function for list selection
2804 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2805 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2808 // when selecting string value, execute function for text input gadget
2809 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2810 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2813 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2815 void (*menu_callback_function)(void) =
2816 menu_info[first_entry + y].value;
2818 FadeSetFromType(menu_info[first_entry + y].type);
2820 menu_callback_function();
2822 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2824 void (*gadget_callback_function)(void) =
2825 menu_info[first_entry + y].value;
2827 gadget_callback_function();
2829 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2830 menu_info == setup_info)
2832 changeSetupValue(y, first_entry + y, dx);
2838 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2840 menu_info = info_info;
2842 HandleMenuScreen(mx, my, dx, dy, button,
2843 info_mode, num_info_info, max_info_info);
2846 static int getMenuFontSpacing(int spacing_height, int font_nr)
2848 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2850 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2854 static int getMenuTextSpacing(int spacing_height, int font_nr)
2856 return (getMenuFontSpacing(spacing_height, font_nr) +
2857 EXTRA_SPACING(game_status));
2860 static int getMenuTextStep(int spacing_height, int font_nr)
2862 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2865 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2867 int font_title = MENU_INFO_FONT_TITLE;
2868 int font_error = FONT_TEXT_2;
2869 int font_foot = MENU_INFO_FONT_FOOT;
2870 int spacing_title = menu.headline1_spacing_info[info_mode];
2871 int ystep_title = getMenuTextStep(spacing_title, font_title);
2872 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2873 int ystart2 = ystart1 + ystep_title;
2874 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2876 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2878 FadeOut(REDRAW_FIELD);
2883 DrawTextSCentered(ystart1, font_title, text_title);
2884 DrawTextSCentered(ystart2, font_error, text_error);
2886 DrawTextSCentered(ybottom, font_foot,
2887 "Press any key or button for info menu");
2889 FadeIn(REDRAW_FIELD);
2892 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2894 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2895 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2896 int font_title = MENU_INFO_FONT_TITLE;
2897 int font_foot = MENU_INFO_FONT_FOOT;
2898 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2899 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2900 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2901 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2902 int ystep = MENU_SCREEN_INFO_YSTEP;
2903 int element, action, direction;
2911 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2912 infoscreen_step[i] = infoscreen_frame[i] = 0;
2917 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2919 DrawTextSCentered(ybottom, font_foot,
2920 "Press any key or button for next page");
2926 while (helpanim_info[j].element != HELPANIM_LIST_END)
2928 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2933 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2942 j += infoscreen_step[i - start];
2944 element = helpanim_info[j].element;
2945 action = helpanim_info[j].action;
2946 direction = helpanim_info[j].direction;
2949 element = EL_UNKNOWN;
2951 if (action != -1 && direction != -1)
2952 graphic = el_act_dir2img(element, action, direction);
2953 else if (action != -1)
2954 graphic = el_act2img(element, action);
2955 else if (direction != -1)
2956 graphic = el_dir2img(element, direction);
2958 graphic = el2img(element);
2960 delay = helpanim_info[j++].delay;
2965 if (infoscreen_frame[i - start] == 0)
2968 infoscreen_frame[i - start] = delay - 1;
2972 sync_frame = delay - infoscreen_frame[i - start];
2973 infoscreen_frame[i - start]--;
2976 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2978 if (!infoscreen_frame[i - start])
2979 infoscreen_step[i - start] = 0;
2983 if (!infoscreen_frame[i - start])
2984 infoscreen_step[i - start]++;
2985 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2991 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2993 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2994 graphic, sync_frame, USE_MASKING);
2997 DrawInfoScreen_HelpText(element, action, direction, i - start);
3002 redraw_mask |= REDRAW_FIELD;
3007 static char *getHelpText(int element, int action, int direction)
3009 char token[MAX_LINE_LEN];
3011 strcpy(token, element_info[element].token_name);
3014 strcat(token, element_action_info[action].suffix);
3016 if (direction != -1)
3017 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3019 return getHashEntry(helptext_info, token);
3022 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3024 int font_nr = FONT_INFO_ELEMENTS;
3025 int font_width = getFontWidth(font_nr);
3026 int font_height = getFontHeight(font_nr);
3027 int yoffset = (TILEX - 2 * font_height) / 2;
3028 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3029 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3030 int ystep = TILEY + 4;
3031 int pad_left = xstart - SX;
3032 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3033 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3034 int max_lines_per_text = 2;
3037 if (action != -1 && direction != -1) // element.action.direction
3038 text = getHelpText(element, action, direction);
3040 if (text == NULL && action != -1) // element.action
3041 text = getHelpText(element, action, -1);
3043 if (text == NULL && direction != -1) // element.direction
3044 text = getHelpText(element, -1, direction);
3046 if (text == NULL) // base element
3047 text = getHelpText(element, -1, -1);
3049 if (text == NULL) // not found
3050 text = "No description available";
3052 if (strlen(text) <= max_chars_per_line) // only one line of text
3053 ystart += getFontHeight(font_nr) / 2;
3055 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3056 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3057 TRUE, FALSE, FALSE);
3060 static void DrawInfoScreen_TitleScreen(void)
3062 SetGameStatus(GAME_MODE_TITLE);
3067 void HandleInfoScreen_TitleScreen(int button)
3069 HandleTitleScreen(0, 0, 0, 0, button);
3072 static void DrawInfoScreen_Elements(void)
3074 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3076 FadeOut(REDRAW_FIELD);
3081 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3083 FadeIn(REDRAW_FIELD);
3086 void HandleInfoScreen_Elements(int button)
3088 static unsigned int info_delay = 0;
3089 static int num_anims;
3090 static int num_pages;
3092 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3095 if (button == MB_MENU_INITIALIZE)
3097 boolean new_element = TRUE;
3101 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3103 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3105 else if (new_element)
3108 new_element = FALSE;
3112 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3116 if (button == MB_MENU_LEAVE)
3118 PlaySound(SND_MENU_ITEM_SELECTING);
3120 info_mode = INFO_MODE_MAIN;
3125 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3127 if (button != MB_MENU_INITIALIZE)
3129 PlaySound(SND_MENU_ITEM_SELECTING);
3134 if (page >= num_pages)
3136 FadeMenuSoundsAndMusic();
3138 info_mode = INFO_MODE_MAIN;
3145 FadeSetNextScreen();
3147 if (button != MB_MENU_INITIALIZE)
3148 FadeOut(REDRAW_FIELD);
3150 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3152 if (button != MB_MENU_INITIALIZE)
3153 FadeIn(REDRAW_FIELD);
3157 if (DelayReached(&info_delay, GameFrameDelay))
3158 if (page < num_pages)
3159 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3161 PlayMenuSoundIfLoop();
3165 static void DrawInfoScreen_Music(void)
3167 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3169 FadeOut(REDRAW_FIELD);
3176 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3178 FadeIn(REDRAW_FIELD);
3181 void HandleInfoScreen_Music(int button)
3183 static struct MusicFileInfo *list = NULL;
3184 int font_title = MENU_INFO_FONT_TITLE;
3185 int font_head = MENU_INFO_FONT_HEAD;
3186 int font_text = MENU_INFO_FONT_TEXT;
3187 int font_foot = MENU_INFO_FONT_FOOT;
3188 int spacing_title = menu.headline1_spacing_info[info_mode];
3189 int spacing_head = menu.headline2_spacing_info[info_mode];
3190 int ystep_title = getMenuTextStep(spacing_title, font_title);
3191 int ystep_head = getMenuTextStep(spacing_head, font_head);
3192 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3193 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3195 if (button == MB_MENU_INITIALIZE)
3197 list = music_file_info;
3201 FadeMenuSoundsAndMusic();
3206 DrawTextSCentered(ystart, font_title,
3207 "No music info for this level set.");
3209 DrawTextSCentered(ybottom, font_foot,
3210 "Press any key or button for info menu");
3216 if (button == MB_MENU_LEAVE)
3218 PlaySound(SND_MENU_ITEM_SELECTING);
3220 FadeMenuSoundsAndMusic();
3222 info_mode = INFO_MODE_MAIN;
3227 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3229 if (button != MB_MENU_INITIALIZE)
3231 PlaySound(SND_MENU_ITEM_SELECTING);
3239 FadeMenuSoundsAndMusic();
3241 info_mode = INFO_MODE_MAIN;
3247 FadeMenuSoundsAndMusic();
3249 if (list != music_file_info)
3250 FadeSetNextScreen();
3252 if (button != MB_MENU_INITIALIZE)
3253 FadeOut(REDRAW_FIELD);
3260 int sound = list->music;
3262 if (sound_info[sound].loop)
3263 PlaySoundLoop(sound);
3267 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3271 int music = list->music;
3273 if (music_info[music].loop)
3274 PlayMusicLoop(music);
3278 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3281 ystart += ystep_title;
3283 if (!strEqual(list->title, UNKNOWN_NAME))
3285 if (!strEqual(list->title_header, UNKNOWN_NAME))
3287 DrawTextSCentered(ystart, font_head, list->title_header);
3288 ystart += ystep_head;
3291 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3292 ystart += ystep_head;
3295 if (!strEqual(list->artist, UNKNOWN_NAME))
3297 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3298 DrawTextSCentered(ystart, font_head, list->artist_header);
3300 DrawTextSCentered(ystart, font_head, "by");
3302 ystart += ystep_head;
3304 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3305 ystart += ystep_head;
3308 if (!strEqual(list->album, UNKNOWN_NAME))
3310 if (!strEqual(list->album_header, UNKNOWN_NAME))
3311 DrawTextSCentered(ystart, font_head, list->album_header);
3313 DrawTextSCentered(ystart, font_head, "from the album");
3315 ystart += ystep_head;
3317 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3318 ystart += ystep_head;
3321 if (!strEqual(list->year, UNKNOWN_NAME))
3323 if (!strEqual(list->year_header, UNKNOWN_NAME))
3324 DrawTextSCentered(ystart, font_head, list->year_header);
3326 DrawTextSCentered(ystart, font_head, "from the year");
3328 ystart += ystep_head;
3330 DrawTextFCentered(ystart, font_text, "%s", list->year);
3331 ystart += ystep_head;
3334 DrawTextSCentered(ybottom, FONT_TEXT_4,
3335 "Press any key or button for next page");
3337 if (button != MB_MENU_INITIALIZE)
3338 FadeIn(REDRAW_FIELD);
3341 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3342 PlaySoundLoop(list->music);
3345 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3347 int font_title = MENU_INFO_FONT_TITLE;
3348 int font_head = MENU_INFO_FONT_HEAD;
3349 int font_text = MENU_INFO_FONT_TEXT;
3350 int font_foot = MENU_INFO_FONT_FOOT;
3351 int spacing_title = menu.headline1_spacing_info[info_mode];
3352 int spacing_head = menu.headline2_spacing_info[info_mode];
3353 int spacing_para = menu.paragraph_spacing_info[info_mode];
3354 int spacing_line = menu.line_spacing_info[info_mode];
3355 int ystep_title = getMenuTextStep(spacing_title, font_title);
3356 int ystep_head = getMenuTextStep(spacing_head, font_head);
3357 int ystep_para = getMenuTextStep(spacing_para, font_text);
3358 int ystep_line = getMenuTextStep(spacing_line, font_text);
3359 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3360 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3365 DrawTextSCentered(ystart, font_title, "Credits:");
3366 ystart += ystep_title;
3370 DrawTextSCentered(ystart, font_head,
3371 "Special thanks to");
3372 ystart += ystep_head;
3373 DrawTextSCentered(ystart, font_text,
3375 ystart += ystep_head;
3376 DrawTextSCentered(ystart, font_head,
3378 ystart += ystep_head;
3379 DrawTextSCentered(ystart, font_text,
3380 "\"Boulder Dash\"");
3381 ystart += ystep_head;
3382 DrawTextSCentered(ystart, font_head,
3384 ystart += ystep_head;
3385 DrawTextSCentered(ystart, font_text,
3387 ystart += ystep_head;
3388 DrawTextSCentered(ystart, font_head,
3390 ystart += ystep_head;
3391 DrawTextSCentered(ystart, font_text,
3392 "First Star Software");
3394 else if (screen_nr == 1)
3396 DrawTextSCentered(ystart, font_head,
3397 "Special thanks to");
3398 ystart += ystep_head;
3399 DrawTextSCentered(ystart, font_text,
3400 "Klaus Heinz & Volker Wertich");
3401 ystart += ystep_head;
3402 DrawTextSCentered(ystart, font_head,
3404 ystart += ystep_head;
3405 DrawTextSCentered(ystart, font_text,
3406 "\"Emerald Mine\"");
3407 ystart += ystep_head;
3408 DrawTextSCentered(ystart, font_head,
3410 ystart += ystep_head;
3411 DrawTextSCentered(ystart, font_text,
3413 ystart += ystep_head;
3414 DrawTextSCentered(ystart, font_head,
3416 ystart += ystep_head;
3417 DrawTextSCentered(ystart, font_text,
3420 else if (screen_nr == 2)
3422 DrawTextSCentered(ystart, font_head,
3423 "Special thanks to");
3424 ystart += ystep_head;
3425 DrawTextSCentered(ystart, font_text,
3426 "Michael Stopp & Philip Jespersen");
3427 ystart += ystep_head;
3428 DrawTextSCentered(ystart, font_head,
3430 ystart += ystep_head;
3431 DrawTextSCentered(ystart, font_text,
3433 ystart += ystep_head;
3434 DrawTextSCentered(ystart, font_head,
3436 ystart += ystep_head;
3437 DrawTextSCentered(ystart, font_text,
3439 ystart += ystep_head;
3440 DrawTextSCentered(ystart, font_head,
3442 ystart += ystep_head;
3443 DrawTextSCentered(ystart, font_text,
3444 "Digital Integration");
3446 else if (screen_nr == 3)
3448 DrawTextSCentered(ystart, font_head,
3449 "Special thanks to");
3450 ystart += ystep_head;
3451 DrawTextSCentered(ystart, font_text,
3452 "Hiroyuki Imabayashi");
3453 ystart += ystep_head;
3454 DrawTextSCentered(ystart, font_head,
3456 ystart += ystep_head;
3457 DrawTextSCentered(ystart, font_text,
3459 ystart += ystep_head;
3460 DrawTextSCentered(ystart, font_head,
3462 ystart += ystep_head;
3463 DrawTextSCentered(ystart, font_text,
3465 ystart += ystep_head;
3466 DrawTextSCentered(ystart, font_head,
3468 ystart += ystep_head;
3469 DrawTextSCentered(ystart, font_text,
3472 else if (screen_nr == 4)
3474 DrawTextSCentered(ystart, font_head,
3475 "Special thanks to");
3476 ystart += ystep_head;
3477 DrawTextSCentered(ystart, font_text,
3479 ystart += ystep_head;
3480 DrawTextSCentered(ystart, font_head,
3482 ystart += ystep_head;
3483 DrawTextSCentered(ystart, font_text,
3484 "J\xfcrgen Bonhagen");
3485 ystart += ystep_head;
3486 DrawTextSCentered(ystart, font_head,
3487 "for the continuous creation");
3488 ystart += ystep_line;
3489 DrawTextSCentered(ystart, font_head,
3490 "of outstanding level sets");
3492 else if (screen_nr == 5)
3494 DrawTextSCentered(ystart, font_head,
3496 ystart += ystep_head;
3497 DrawTextSCentered(ystart, font_text,
3499 ystart += ystep_head;
3500 DrawTextSCentered(ystart, font_head,
3501 "for ideas and inspiration by");
3502 ystart += ystep_head;
3503 DrawTextSCentered(ystart, font_text,
3505 ystart += ystep_para;
3507 DrawTextSCentered(ystart, font_head,
3509 ystart += ystep_head;
3510 DrawTextSCentered(ystart, font_text,
3512 ystart += ystep_head;
3513 DrawTextSCentered(ystart, font_head,
3514 "for ideas and inspiration by");
3515 ystart += ystep_head;
3516 DrawTextSCentered(ystart, font_text,
3519 else if (screen_nr == 6)
3521 DrawTextSCentered(ystart, font_head,
3523 ystart += ystep_head;
3524 DrawTextSCentered(ystart, font_text,
3526 ystart += ystep_head;
3527 DrawTextSCentered(ystart, font_head,
3528 "for the code base used for the");
3529 ystart += ystep_line;
3530 DrawTextSCentered(ystart, font_head,
3531 "native Emerald Mine engine");
3533 else if (screen_nr == 7)
3535 DrawTextSCentered(ystart, font_head,
3537 ystart += ystep_head;
3538 DrawTextSCentered(ystart, font_text,
3540 ystart += ystep_head;
3541 DrawTextSCentered(ystart, font_head,
3542 "for the initial DOS port");
3543 ystart += ystep_para;
3545 DrawTextSCentered(ystart, font_head,
3547 ystart += ystep_head;
3548 DrawTextSCentered(ystart, font_text,
3550 ystart += ystep_head;
3551 DrawTextSCentered(ystart, font_head,
3552 "for some additional toons");
3554 else if (screen_nr == 8)
3556 DrawTextSCentered(ystart, font_head,
3557 "And not to forget:");
3558 ystart += ystep_head;
3559 DrawTextSCentered(ystart, font_head,
3561 ystart += ystep_head;
3562 DrawTextSCentered(ystart, font_text,
3563 "All those who contributed");
3564 ystart += ystep_line;
3565 DrawTextSCentered(ystart, font_text,
3566 "levels to this game");
3567 ystart += ystep_line;
3568 DrawTextSCentered(ystart, font_text,
3572 DrawTextSCentered(ybottom, font_foot,
3573 "Press any key or button for next page");
3576 static void DrawInfoScreen_Credits(void)
3578 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3580 FadeMenuSoundsAndMusic();
3582 FadeOut(REDRAW_FIELD);
3584 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3586 FadeIn(REDRAW_FIELD);
3589 void HandleInfoScreen_Credits(int button)
3591 static int screen_nr = 0;
3592 int num_screens = 9;
3594 if (button == MB_MENU_INITIALIZE)
3598 // DrawInfoScreen_CreditsScreen(screen_nr);
3601 if (button == MB_MENU_LEAVE)
3603 PlaySound(SND_MENU_ITEM_SELECTING);
3605 info_mode = INFO_MODE_MAIN;
3610 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3612 if (button != MB_MENU_INITIALIZE)
3614 PlaySound(SND_MENU_ITEM_SELECTING);
3619 if (screen_nr >= num_screens)
3621 FadeMenuSoundsAndMusic();
3623 info_mode = INFO_MODE_MAIN;
3630 FadeSetNextScreen();
3632 if (button != MB_MENU_INITIALIZE)
3633 FadeOut(REDRAW_FIELD);
3635 DrawInfoScreen_CreditsScreen(screen_nr);
3637 if (button != MB_MENU_INITIALIZE)
3638 FadeIn(REDRAW_FIELD);
3642 PlayMenuSoundIfLoop();
3646 static void DrawInfoScreen_Program(void)
3648 int font_title = MENU_INFO_FONT_TITLE;
3649 int font_head = MENU_INFO_FONT_HEAD;
3650 int font_text = MENU_INFO_FONT_TEXT;
3651 int font_foot = MENU_INFO_FONT_FOOT;
3652 int spacing_title = menu.headline1_spacing_info[info_mode];
3653 int spacing_head = menu.headline2_spacing_info[info_mode];
3654 int spacing_para = menu.paragraph_spacing_info[info_mode];
3655 int spacing_line = menu.line_spacing_info[info_mode];
3656 int ystep_title = getMenuTextStep(spacing_title, font_title);
3657 int ystep_head = getMenuTextStep(spacing_head, font_head);
3658 int ystep_para = getMenuTextStep(spacing_para, font_text);
3659 int ystep_line = getMenuTextStep(spacing_line, font_text);
3660 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3661 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3663 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3665 FadeOut(REDRAW_FIELD);
3670 DrawTextSCentered(ystart, font_title, "Program Information:");
3671 ystart += ystep_title;
3673 DrawTextSCentered(ystart, font_head,
3674 "This game is Freeware!");
3675 ystart += ystep_head;
3676 DrawTextSCentered(ystart, font_head,
3677 "If you like it, send e-mail to:");
3678 ystart += ystep_head;
3679 DrawTextSCentered(ystart, font_text,
3680 setup.internal.program_email);
3681 ystart += ystep_para;
3683 DrawTextSCentered(ystart, font_head,
3684 "More information and levels:");
3685 ystart += ystep_head;
3686 DrawTextSCentered(ystart, font_text,
3687 setup.internal.program_website);
3688 ystart += ystep_para;
3690 DrawTextSCentered(ystart, font_head,
3691 "If you have created new levels,");
3692 ystart += ystep_line;
3693 DrawTextSCentered(ystart, font_head,
3694 "send them to me to include them!");
3695 ystart += ystep_head;
3696 DrawTextSCentered(ystart, font_head,
3699 DrawTextSCentered(ybottom, font_foot,
3700 "Press any key or button for info menu");
3702 FadeIn(REDRAW_FIELD);
3705 void HandleInfoScreen_Program(int button)
3707 if (button == MB_MENU_LEAVE)
3709 PlaySound(SND_MENU_ITEM_SELECTING);
3711 info_mode = INFO_MODE_MAIN;
3716 else if (button == MB_MENU_CHOICE)
3718 PlaySound(SND_MENU_ITEM_SELECTING);
3720 FadeMenuSoundsAndMusic();
3722 info_mode = INFO_MODE_MAIN;
3727 PlayMenuSoundIfLoop();
3731 static void DrawInfoScreen_Version(void)
3733 int font_title = MENU_INFO_FONT_TITLE;
3734 int font_head = MENU_INFO_FONT_HEAD;
3735 int font_text = MENU_INFO_FONT_TEXT;
3736 int font_foot = MENU_INFO_FONT_FOOT;
3737 int spacing_title = menu.headline1_spacing_info[info_mode];
3738 int spacing_head = menu.headline2_spacing_info[info_mode];
3739 int spacing_para = menu.paragraph_spacing_info[info_mode];
3740 int spacing_line = menu.line_spacing_info[info_mode];
3741 int xstep = getFontWidth(font_text);
3742 int ystep_title = getMenuTextStep(spacing_title, font_title);
3743 int ystep_head = getMenuTextStep(spacing_head, font_head);
3744 int ystep_para = getMenuTextStep(spacing_para, font_text);
3745 int ystep_line = getMenuTextStep(spacing_line, font_text);
3746 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3747 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3748 int xstart1 = mSX - SX + 2 * xstep;
3749 int xstart2 = mSX - SX + 18 * xstep;
3750 int xstart3 = mSX - SX + 28 * xstep;
3751 SDL_version sdl_version_compiled;
3752 const SDL_version *sdl_version_linked;
3753 int driver_name_len = 10;
3754 SDL_version sdl_version_linked_ext;
3755 const char *driver_name = NULL;
3757 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3759 FadeOut(REDRAW_FIELD);
3764 DrawTextSCentered(ystart, font_title, "Version Information:");
3765 ystart += ystep_title;
3767 DrawTextF(xstart1, ystart, font_head, "Name");
3768 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3769 ystart += ystep_line;
3771 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3773 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3774 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3775 ystart += ystep_line;
3777 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3778 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3779 ystart += ystep_line;
3783 DrawTextF(xstart1, ystart, font_head, "Version");
3784 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3785 ystart += ystep_line;
3788 DrawTextF(xstart1, ystart, font_head, "Platform");
3789 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3791 PLATFORM_XX_BIT_STRING);
3792 ystart += ystep_line;
3794 DrawTextF(xstart1, ystart, font_head, "Target");
3795 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3796 ystart += ystep_line;
3798 DrawTextF(xstart1, ystart, font_head, "Source date");
3799 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3800 ystart += ystep_line;
3802 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3803 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3804 ystart += ystep_para;
3806 DrawTextF(xstart1, ystart, font_head, "Library");
3807 DrawTextF(xstart2, ystart, font_head, "compiled");
3808 DrawTextF(xstart3, ystart, font_head, "linked");
3809 ystart += ystep_head;
3811 SDL_VERSION(&sdl_version_compiled);
3812 SDL_GetVersion(&sdl_version_linked_ext);
3813 sdl_version_linked = &sdl_version_linked_ext;
3815 DrawTextF(xstart1, ystart, font_text, "SDL");
3816 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3817 sdl_version_compiled.major,
3818 sdl_version_compiled.minor,
3819 sdl_version_compiled.patch);
3820 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3821 sdl_version_linked->major,
3822 sdl_version_linked->minor,
3823 sdl_version_linked->patch);
3824 ystart += ystep_line;
3826 SDL_IMAGE_VERSION(&sdl_version_compiled);
3827 sdl_version_linked = IMG_Linked_Version();
3829 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3830 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3831 sdl_version_compiled.major,
3832 sdl_version_compiled.minor,
3833 sdl_version_compiled.patch);
3834 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3835 sdl_version_linked->major,
3836 sdl_version_linked->minor,
3837 sdl_version_linked->patch);
3838 ystart += ystep_line;
3840 SDL_MIXER_VERSION(&sdl_version_compiled);
3841 sdl_version_linked = Mix_Linked_Version();
3843 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3844 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3845 sdl_version_compiled.major,
3846 sdl_version_compiled.minor,
3847 sdl_version_compiled.patch);
3848 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3849 sdl_version_linked->major,
3850 sdl_version_linked->minor,
3851 sdl_version_linked->patch);
3852 ystart += ystep_line;
3854 SDL_NET_VERSION(&sdl_version_compiled);
3855 sdl_version_linked = SDLNet_Linked_Version();
3857 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3858 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3859 sdl_version_compiled.major,
3860 sdl_version_compiled.minor,
3861 sdl_version_compiled.patch);
3862 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3863 sdl_version_linked->major,
3864 sdl_version_linked->minor,
3865 sdl_version_linked->patch);
3866 ystart += ystep_para;
3868 DrawTextF(xstart1, ystart, font_head, "Driver");
3869 DrawTextF(xstart2, ystart, font_head, "Requested");
3870 DrawTextF(xstart3, ystart, font_head, "Used");
3871 ystart += ystep_head;
3874 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3876 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3877 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3878 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3879 ystart += ystep_line;
3882 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3884 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3885 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3886 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3887 ystart += ystep_line;
3890 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3892 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3893 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3894 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3896 DrawTextSCentered(ybottom, font_foot,
3897 "Press any key or button for info menu");
3899 FadeIn(REDRAW_FIELD);
3902 void HandleInfoScreen_Version(int button)
3904 if (button == MB_MENU_LEAVE)
3906 PlaySound(SND_MENU_ITEM_SELECTING);
3908 info_mode = INFO_MODE_MAIN;
3913 else if (button == MB_MENU_CHOICE)
3915 PlaySound(SND_MENU_ITEM_SELECTING);
3917 FadeMenuSoundsAndMusic();
3919 info_mode = INFO_MODE_MAIN;
3924 PlayMenuSoundIfLoop();
3928 static void DrawInfoScreen_LevelSet(void)
3930 struct TitleMessageInfo *tmi = &readme;
3931 char *filename = getLevelSetInfoFilename();
3932 char *title = "Level Set Information:";
3933 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3934 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3936 if (filename == NULL)
3938 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3943 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3945 FadeOut(REDRAW_FIELD);
3950 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3952 // if x position set to "-1", automatically determine by playfield width
3954 tmi->x = SXSIZE / 2;
3956 // if y position set to "-1", use static default value
3960 // if width set to "-1", automatically determine by playfield width
3961 if (tmi->width == -1)
3962 tmi->width = SXSIZE - 2 * TILEX;
3964 // if height set to "-1", automatically determine by playfield height
3965 if (tmi->height == -1)
3966 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3968 // if chars set to "-1", automatically determine by text and font width
3969 if (tmi->chars == -1)
3970 tmi->chars = tmi->width / getFontWidth(tmi->font);
3972 tmi->width = tmi->chars * getFontWidth(tmi->font);
3974 // if lines set to "-1", automatically determine by text and font height
3975 if (tmi->lines == -1)
3976 tmi->lines = tmi->height / getFontHeight(tmi->font);
3978 tmi->height = tmi->lines * getFontHeight(tmi->font);
3980 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3981 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3982 tmi->autowrap, tmi->centered, tmi->parse_comments);
3984 DrawTextSCentered(ybottom, FONT_TEXT_4,
3985 "Press any key or button for info menu");
3987 FadeIn(REDRAW_FIELD);
3990 static void HandleInfoScreen_LevelSet(int button)
3992 if (button == MB_MENU_LEAVE)
3994 PlaySound(SND_MENU_ITEM_SELECTING);
3996 info_mode = INFO_MODE_MAIN;
4001 else if (button == MB_MENU_CHOICE)
4003 PlaySound(SND_MENU_ITEM_SELECTING);
4005 FadeMenuSoundsAndMusic();
4007 info_mode = INFO_MODE_MAIN;
4012 PlayMenuSoundIfLoop();
4016 static void DrawInfoScreen(void)
4018 if (info_mode == INFO_MODE_TITLE)
4019 DrawInfoScreen_TitleScreen();
4020 else if (info_mode == INFO_MODE_ELEMENTS)
4021 DrawInfoScreen_Elements();
4022 else if (info_mode == INFO_MODE_MUSIC)
4023 DrawInfoScreen_Music();
4024 else if (info_mode == INFO_MODE_CREDITS)
4025 DrawInfoScreen_Credits();
4026 else if (info_mode == INFO_MODE_PROGRAM)
4027 DrawInfoScreen_Program();
4028 else if (info_mode == INFO_MODE_VERSION)
4029 DrawInfoScreen_Version();
4030 else if (info_mode == INFO_MODE_LEVELSET)
4031 DrawInfoScreen_LevelSet();
4033 DrawInfoScreen_Main();
4035 if (info_mode != INFO_MODE_MAIN &&
4036 info_mode != INFO_MODE_TITLE &&
4037 info_mode != INFO_MODE_MUSIC)
4038 PlayMenuSoundsAndMusic();
4041 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4043 if (info_mode == INFO_MODE_TITLE)
4044 HandleInfoScreen_TitleScreen(button);
4045 else if (info_mode == INFO_MODE_ELEMENTS)
4046 HandleInfoScreen_Elements(button);
4047 else if (info_mode == INFO_MODE_MUSIC)
4048 HandleInfoScreen_Music(button);
4049 else if (info_mode == INFO_MODE_CREDITS)
4050 HandleInfoScreen_Credits(button);
4051 else if (info_mode == INFO_MODE_PROGRAM)
4052 HandleInfoScreen_Program(button);
4053 else if (info_mode == INFO_MODE_VERSION)
4054 HandleInfoScreen_Version(button);
4055 else if (info_mode == INFO_MODE_LEVELSET)
4056 HandleInfoScreen_LevelSet(button);
4058 HandleInfoScreen_Main(mx, my, dx, dy, button);
4062 // ============================================================================
4063 // change name functions
4064 // ============================================================================
4066 struct ApiRenamePlayerThreadData
4072 static void *CreateThreadData_ApiRenamePlayer(void)
4074 struct ApiRenamePlayerThreadData *data =
4075 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4077 data->player_name = getStringCopy(setup.player_name);
4078 data->player_uuid = getStringCopy(setup.player_uuid);
4083 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4085 struct ApiRenamePlayerThreadData *data = data_raw;
4087 checked_free(data->player_name);
4088 checked_free(data->player_uuid);
4092 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4095 struct ApiRenamePlayerThreadData *data = data_raw;
4096 char *player_name_raw = data->player_name;
4097 char *player_uuid_raw = data->player_uuid;
4099 request->hostname = setup.api_server_hostname;
4100 request->port = API_SERVER_PORT;
4101 request->method = API_SERVER_METHOD;
4102 request->uri = API_SERVER_URI_RENAME;
4104 char *player_name = getEscapedJSON(player_name_raw);
4105 char *player_uuid = getEscapedJSON(player_uuid_raw);
4107 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4110 " \"game_version\": \"%s\",\n"
4111 " \"game_platform\": \"%s\",\n"
4112 " \"name\": \"%s\",\n"
4113 " \"uuid\": \"%s\"\n"
4115 getPasswordJSON(setup.api_server_password),
4116 getProgramRealVersionString(),
4117 getProgramPlatformString(),
4121 checked_free(player_name);
4122 checked_free(player_uuid);
4124 ConvertHttpRequestBodyToServerEncoding(request);
4129 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4132 // nothing to do here
4135 #if defined(PLATFORM_EMSCRIPTEN)
4136 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4137 void *buffer, unsigned int size)
4139 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4141 if (response != NULL)
4143 HandleResponse_ApiRenamePlayer(response, data_raw);
4145 checked_free(response);
4149 Error("server response too large to handle (%d bytes)", size);
4152 FreeThreadData_ApiRenamePlayer(data_raw);
4155 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4156 int code, const char *status)
4158 Error("server failed to handle request: %d %s", code, status);
4160 FreeThreadData_ApiRenamePlayer(data_raw);
4163 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4164 int bytes, int size)
4166 // nothing to do here
4169 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4172 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4174 FreeThreadData_ApiRenamePlayer(data_raw);
4179 emscripten_async_wget2_data(request->uri,
4184 Emscripten_ApiRenamePlayer_Loaded,
4185 Emscripten_ApiRenamePlayer_Failed,
4186 Emscripten_ApiRenamePlayer_Progress);
4191 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4192 struct HttpResponse *response,
4195 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4198 if (!DoHttpRequest(request, response))
4200 Error("HTTP request failed: %s", GetHttpError());
4205 if (!HTTP_SUCCESS(response->status_code))
4207 Error("server failed to handle request: %d %s",
4208 response->status_code,
4209 response->status_text);
4214 HandleResponse_ApiRenamePlayer(response, data_raw);
4217 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4218 struct HttpResponse *response,
4221 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4223 FreeThreadData_ApiRenamePlayer(data_raw);
4227 static int ApiRenamePlayerThread(void *data_raw)
4229 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4230 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4232 program.api_thread_count++;
4234 #if defined(PLATFORM_EMSCRIPTEN)
4235 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4237 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4240 program.api_thread_count--;
4242 checked_free(request);
4243 checked_free(response);
4248 static void ApiRenamePlayerAsThread(void)
4250 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4252 ExecuteAsThread(ApiRenamePlayerThread,
4253 "ApiRenamePlayer", data,
4254 "rename player on server");
4258 // ============================================================================
4259 // type name functions
4260 // ============================================================================
4262 static TreeInfo *type_name_node = NULL;
4263 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4264 static int type_name_nr = 0;
4266 static int getPlayerNameColor(char *name)
4268 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4271 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4274 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4275 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4276 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4277 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4278 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4279 int font_width = getFontWidth(font_nr);
4281 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4283 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4285 pos->width = strlen(text) * font_width;
4286 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4288 DrawText(sx, sy, text, font_nr);
4291 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4293 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4295 *pos = *mci->pos_input;
4297 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4299 TreeInfo *ti = player_name_current;
4300 int first_entry = ti->cl_first;
4301 int entry_pos = first_entry + ti->cl_cursor;
4302 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4303 int xpos = MENU_SCREEN_START_XPOS;
4304 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4306 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4307 type_name_nr = entry_pos;
4309 strcpy(name, type_name_node->name);
4313 pos->width = MAX_PLAYER_NAME_LEN * 32;
4317 type_name_nr = user.nr;
4319 strcpy(name, setup.player_name);
4322 strcpy(type_name_last, name);
4324 if (strEqual(name, EMPTY_PLAYER_NAME))
4327 *xpos = strlen(name);
4330 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4332 // change name of edited user in global list of user names
4333 setString(&global.user_names[type_name_nr], name);
4335 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4337 TreeInfo *node = type_name_node;
4339 // change name of edited user in local menu tree structure
4340 setString(&node->name, name);
4341 setString(&node->name_sorting, name);
4343 node->color = getPlayerNameColor(name);
4344 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4348 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4351 boolean reset_setup = strEqual(name, "");
4352 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4353 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4356 strcpy(name, type_name_last);
4358 if (strEqual(name, ""))
4359 strcpy(name, EMPTY_PLAYER_NAME);
4361 setTypeNameValues_Name(name, pos);
4363 // if player name not changed, no further action required
4364 if (strEqual(name, type_name_last))
4367 // redraw player name before (possibly) opening request dialogs
4368 drawTypeNameText(name, pos, FALSE);
4370 int last_user_nr = user.nr;
4372 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4374 // save setup of currently active user (may differ from edited user)
4377 // temporarily change active user to edited user
4378 user.nr = type_name_nr;
4381 Request("Use current setup values for the new player?", REQ_ASK))
4383 // use current setup values for new user, but create new player UUID
4384 setup.player_uuid = getStringCopy(getUUID());
4388 // load setup for existing user (or start with defaults for new user)
4393 char *setup_filename = getSetupFilename();
4394 boolean setup_exists = fileExists(setup_filename);
4396 // change name of edited user in setup structure
4397 strcpy(setup.player_name, name);
4399 // save setup of edited user
4402 // change name of edited user on score server
4403 ApiRenamePlayerAsThread();
4405 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4409 if (Request("Reset setup values for this player?", REQ_ASK))
4411 // remove setup config file
4412 unlink(setup_filename);
4414 // set player name to default player name
4417 // update player name used by name typing functions
4418 strcpy(name, setup.player_name);
4420 setTypeNameValues_Name(name, pos);
4423 else if (remove_user && type_name_nr != 0)
4425 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4427 char *user_dir = getUserGameDataDir();
4428 char *user_dir_removed =
4429 getStringCat3WithSeparator(user_dir, "REMOVED",
4430 getCurrentTimestamp(), ".");
4432 if (rename(user_dir, user_dir_removed) != 0)
4433 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4435 checked_free(user_dir_removed);
4438 else if (create_user && type_name_nr != 0 && !setup_exists)
4440 if (Request("Create empty level set for the new player?", REQ_ASK))
4442 char *levelset_subdir = getNewUserLevelSubdir();
4444 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4446 AddUserLevelSetToLevelInfo(levelset_subdir);
4448 LevelDirTree *leveldir_current_last = leveldir_current;
4450 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4453 // set level number of newly created level set to default value
4454 LoadLevelSetup_SeriesInfo();
4456 // set newly created level set as current level set for new user
4457 SaveLevelSetup_LastSeries();
4458 SaveLevelSetup_SeriesInfo();
4460 leveldir_current = leveldir_current_last;
4464 Request("Creating new level set failed!", REQ_CONFIRM);
4469 // restore currently active user
4470 user.nr = last_user_nr;
4472 // restore setup of currently active user
4475 // restore last level set of currently active user
4476 LoadLevelSetup_LastSeries();
4477 LoadLevelSetup_SeriesInfo();
4481 static void HandleTypeNameExt(boolean initialize, Key key)
4483 static struct TextPosInfo pos_name = { 0 };
4484 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4485 static int xpos = 0;
4486 struct TextPosInfo *pos = &pos_name;
4487 char key_char = getValidConfigValueChar(getCharFromKey(key));
4488 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4489 boolean active = TRUE;
4493 getTypeNameValues(name, pos, &xpos);
4495 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4496 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4498 StartTextInput(sx, sy, pos->width, pos->height);
4500 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4502 name[xpos] = key_char;
4507 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4513 else if (key == KSYM_Return || key == KSYM_Escape)
4515 boolean changed = (key == KSYM_Return);
4519 setTypeNameValues(name, pos, changed);
4524 drawTypeNameText(name, pos, active);
4528 SetGameStatus(game_status_last_screen);
4530 if (game_status == GAME_MODE_MAIN)
4531 InitializeMainControls();
4535 static void DrawTypeName(void)
4537 HandleTypeNameExt(TRUE, 0);
4540 void HandleTypeName(Key key)
4542 HandleTypeNameExt(FALSE, key);
4546 // ============================================================================
4547 // tree menu functions
4548 // ============================================================================
4550 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4552 if (game_status != GAME_MODE_SETUP ||
4553 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4556 int max_text_size = 0;
4559 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4560 max_text_size = MAX(max_text_size, strlen(node->name));
4562 int num_entries = numTreeInfoInGroup(ti);
4563 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4564 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4565 int text_width = max_text_size * getFontWidth(font_nr);
4566 int button_width = SC_MENUBUTTON_XSIZE;
4567 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4568 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4569 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4570 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4571 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4572 int align_xoffset = MAX(0, align_xoffset_raw);
4574 return align_xoffset;
4577 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4579 if (game_status != GAME_MODE_SETUP ||
4580 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4583 int num_entries = numTreeInfoInGroup(ti);
4584 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4585 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4586 int font_height = getFontHeight(font_nr);
4587 int text_height = font_height * num_page_entries;
4588 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4589 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4590 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4591 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4592 int align_yoffset = MAX(0, align_yoffset_raw);
4594 return align_yoffset;
4597 static void DrawChooseTree(TreeInfo **ti_ptr)
4599 int fade_mask = REDRAW_FIELD;
4602 fade_mask = REDRAW_ALL;
4604 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4606 if (game_status == GAME_MODE_SETUP)
4610 else // GAME_MODE_LEVELS
4612 SetGameStatus(GAME_MODE_MAIN);
4622 FreeScreenGadgets();
4623 CreateScreenGadgets();
4627 // needed if different viewport properties defined for choosing level (set)
4628 ChangeViewportPropertiesIfNeeded();
4630 if (game_status == GAME_MODE_NAMES)
4631 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4632 else if (game_status == GAME_MODE_LEVELNR)
4633 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4634 else if (game_status == GAME_MODE_LEVELS)
4635 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4639 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4641 MapScreenTreeGadgets(*ti_ptr);
4642 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4644 DrawMaskedBorder(fade_mask);
4649 static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
4651 int num_entries = numTreeInfoInGroup(ti);
4652 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4653 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4654 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4655 int first_entry = ti->cl_first;
4656 int entry_pos = first_entry + y;
4657 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4658 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4659 int font_color = MENU_CHOOSE_TREE_COLOR(node, active);
4660 int font_nr = MENU_CHOOSE_TREE_FONT(font_color);
4661 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4662 int xpos = MENU_SCREEN_START_XPOS;
4663 int ypos = MENU_SCREEN_START_YPOS + y;
4664 int startx = amSX + xpos * 32;
4665 int starty = amSY + ypos * 32;
4666 int startx_text = startx + font_xoffset;
4667 int endx_text = amSX + screen_width;
4668 int max_text_size = endx_text - startx_text;
4669 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4670 char buffer[max_buffer_len + 1];
4672 strncpy(buffer, node->name, max_buffer_len);
4673 buffer[max_buffer_len] = '\0';
4675 DrawText(startx, starty, buffer, font_nr);
4678 static void drawChooseTreeList(int first_entry, int num_page_entries,
4682 char *title_string = NULL;
4683 int yoffset_sets = MENU_TITLE1_YPOS;
4684 int yoffset_setup = 16;
4685 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4686 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4688 title_string = ti->infotext;
4690 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4692 clearMenuListArea();
4694 for (i = 0; i < num_page_entries; i++)
4696 TreeInfo *node, *node_first;
4697 int entry_pos = first_entry + i;
4699 node_first = getTreeInfoFirstGroupEntry(ti);
4700 node = getTreeInfoFromPos(node_first, entry_pos);
4702 drawChooseTreeText(i, FALSE, ti);
4704 if (node->parent_link)
4705 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4706 else if (node->level_group)
4707 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4709 initCursor(i, IMG_MENU_BUTTON);
4711 if (game_status == GAME_MODE_NAMES)
4712 drawChooseTreeEdit(i, FALSE);
4715 redraw_mask |= REDRAW_FIELD;
4718 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4720 TreeInfo *node, *node_first;
4721 int x, last_redraw_mask = redraw_mask;
4722 int ypos = MENU_TITLE2_YPOS;
4723 int font_nr = FONT_TITLE_2;
4725 if (ti->type == TREE_TYPE_LEVEL_NR)
4726 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4728 if (ti->type != TREE_TYPE_LEVEL_DIR)
4731 node_first = getTreeInfoFirstGroupEntry(ti);
4732 node = getTreeInfoFromPos(node_first, entry_pos);
4734 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4736 if (node->parent_link)
4737 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4738 node->node_parent->name);
4739 else if (node->level_group)
4740 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4742 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4743 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4744 node->levels, (node->levels > 1 ? "levels" : "level"),
4747 // let BackToFront() redraw only what is needed
4748 redraw_mask = last_redraw_mask;
4749 for (x = 0; x < SCR_FIELDX; x++)
4750 MarkTileDirty(x, 1);
4753 static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
4755 drawChooseTreeCursor(y, active);
4756 drawChooseTreeText(y, active, ti);
4759 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4762 TreeInfo *ti = *ti_ptr;
4763 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4764 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4765 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4766 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4767 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4769 int y = ti->cl_cursor;
4770 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4771 int num_entries = numTreeInfoInGroup(ti);
4772 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4773 boolean position_set_by_scrollbar = (dx == 999);
4775 if (button == MB_MENU_INITIALIZE)
4777 int num_entries = numTreeInfoInGroup(ti);
4778 int entry_pos = getPosFromTreeInfo(ti);
4780 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4781 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4783 if (ti->cl_first == -1)
4785 // only on initialization
4786 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4787 ti->cl_cursor = entry_pos - ti->cl_first;
4789 else if (ti->cl_cursor >= num_page_entries ||
4790 (num_entries > num_page_entries &&
4791 num_entries - ti->cl_first < num_page_entries))
4793 // only after change of list size (by custom graphic configuration)
4794 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4795 ti->cl_cursor = entry_pos - ti->cl_first;
4798 if (position_set_by_scrollbar)
4801 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4804 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4805 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4806 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4810 else if (button == MB_MENU_LEAVE)
4814 PlaySound(SND_MENU_ITEM_SELECTING);
4816 if (ti->node_parent)
4818 *ti_ptr = ti->node_parent;
4819 DrawChooseTree(ti_ptr);
4821 else if (game_status == GAME_MODE_SETUP)
4823 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4824 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4825 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4826 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4828 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4829 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4830 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4831 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4832 execSetupGraphics();
4833 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4834 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4835 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4837 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4838 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4839 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4840 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4841 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4842 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4843 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4844 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4851 if (game_status == GAME_MODE_LEVELNR)
4853 int new_level_nr = atoi(level_number_current->identifier);
4855 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4858 SetGameStatus(GAME_MODE_MAIN);
4866 if (mx || my) // mouse input
4868 x = (mx - amSX) / 32;
4869 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4871 if (game_status == GAME_MODE_NAMES)
4872 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4874 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4876 // move cursor instead of scrolling when already at start/end of list
4877 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4879 else if (dy == +1 * SCROLL_LINE &&
4880 ti->cl_first + num_page_entries == num_entries)
4883 // handle scrolling screen one line or page
4884 if (ti->cl_cursor + dy < 0 ||
4885 ti->cl_cursor + dy > num_page_entries - 1)
4887 boolean redraw = FALSE;
4889 if (ABS(dy) == SCROLL_PAGE)
4890 step = num_page_entries - 1;
4892 if (dy < 0 && ti->cl_first > 0)
4894 // scroll page/line up
4896 ti->cl_first -= step;
4897 if (ti->cl_first < 0)
4902 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4904 // scroll page/line down
4906 ti->cl_first += step;
4907 if (ti->cl_first + num_page_entries > num_entries)
4908 ti->cl_first = MAX(0, num_entries - num_page_entries);
4915 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4916 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4917 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4919 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4926 // handle moving cursor one line
4927 y = ti->cl_cursor + dy;
4932 TreeInfo *node_first, *node_cursor;
4933 int entry_pos = ti->cl_first + y;
4935 node_first = getTreeInfoFirstGroupEntry(ti);
4936 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4938 if (node_cursor->node_group)
4942 PlaySound(SND_MENU_ITEM_SELECTING);
4944 node_cursor->cl_first = ti->cl_first;
4945 node_cursor->cl_cursor = ti->cl_cursor;
4946 *ti_ptr = node_cursor->node_group;
4947 DrawChooseTree(ti_ptr);
4952 else if (dx == -1 && ti->node_parent)
4956 PlaySound(SND_MENU_ITEM_SELECTING);
4958 *ti_ptr = ti->node_parent;
4959 DrawChooseTree(ti_ptr);
4964 if (!anyScrollbarGadgetActive() &&
4965 IN_VIS_MENU(x, y) &&
4966 mx < mx_right_border &&
4967 y >= 0 && y < num_page_entries)
4971 if (game_status == GAME_MODE_NAMES)
4973 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4974 drawChooseTreeEdit(y, TRUE);
4977 if (y != ti->cl_cursor)
4979 PlaySound(SND_MENU_ITEM_ACTIVATING);
4981 drawChooseTreeCursorAndText(ti->cl_cursor, FALSE, ti);
4982 drawChooseTreeCursorAndText(y, TRUE, ti);
4983 drawChooseTreeInfo(ti->cl_first + y, ti);
4989 if (game_status == GAME_MODE_SETUP)
4991 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4992 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4993 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4994 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4996 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4997 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4998 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4999 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5000 execSetupGraphics();
5001 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5002 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5003 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5005 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5006 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5007 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5008 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5009 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5010 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5011 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5012 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5021 TreeInfo *node_first, *node_cursor;
5022 int entry_pos = ti->cl_first + y;
5024 PlaySound(SND_MENU_ITEM_SELECTING);
5026 node_first = getTreeInfoFirstGroupEntry(ti);
5027 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5029 if (node_cursor->node_group)
5033 node_cursor->cl_first = ti->cl_first;
5034 node_cursor->cl_cursor = ti->cl_cursor;
5035 *ti_ptr = node_cursor->node_group;
5036 DrawChooseTree(ti_ptr);
5038 else if (node_cursor->parent_link)
5042 *ti_ptr = node_cursor->node_parent;
5043 DrawChooseTree(ti_ptr);
5049 node_cursor->cl_first = ti->cl_first;
5050 node_cursor->cl_cursor = ti->cl_cursor;
5051 *ti_ptr = node_cursor;
5053 if (ti->type == TREE_TYPE_LEVEL_DIR)
5055 LoadLevelSetup_SeriesInfo();
5057 SaveLevelSetup_LastSeries();
5058 SaveLevelSetup_SeriesInfo();
5062 if (game_status == GAME_MODE_SETUP)
5064 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5065 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5066 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5067 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5069 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5070 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5071 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5072 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5073 execSetupGraphics();
5074 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5075 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5076 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5078 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5079 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5080 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5081 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5082 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5083 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5084 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5085 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5092 if (game_status == GAME_MODE_LEVELNR)
5094 int new_level_nr = atoi(level_number_current->identifier);
5096 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5098 else if (game_status == GAME_MODE_LEVELS)
5100 // store level set if chosen from "last played level set" menu
5101 StoreLastPlayedLevels(leveldir_current);
5103 else if (game_status == GAME_MODE_NAMES)
5105 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5107 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5114 // change active user to selected user
5115 user.nr = entry_pos;
5117 // save number of new active user
5120 // load setup of new active user
5123 // load last level set of new active user
5124 LoadLevelSetup_LastSeries();
5125 LoadLevelSetup_SeriesInfo();
5127 // update list of last played level sets
5128 UpdateLastPlayedLevels_TreeInfo();
5132 ToggleFullscreenIfNeeded();
5133 ChangeWindowScalingIfNeeded();
5135 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5136 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5137 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5140 SetGameStatus(GAME_MODE_MAIN);
5149 void DrawChoosePlayerName(void)
5153 FadeMenuSoundsAndMusic();
5155 if (player_name != NULL)
5157 freeTreeInfo(player_name);
5162 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5164 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5165 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5168 ti->node_top = &player_name;
5169 ti->sort_priority = 10000 + value;
5170 ti->color = getPlayerNameColor(global.user_names[i]);
5172 snprintf(identifier, sizeof(identifier), "%d", value);
5173 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5175 setString(&ti->identifier, identifier);
5176 setString(&ti->name, name);
5177 setString(&ti->name_sorting, name);
5179 pushTreeInfo(&player_name, ti);
5182 // sort player entries by player number
5183 sortTreeInfo(&player_name);
5185 // set current player entry to selected player entry
5186 player_name_current =
5187 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5189 // if that fails, set current player name to first available name
5190 if (player_name_current == NULL)
5191 player_name_current = player_name;
5193 DrawChooseTree(&player_name_current);
5195 PlayMenuSoundsAndMusic();
5198 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5200 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5203 void DrawChooseLevelSet(void)
5205 FadeMenuSoundsAndMusic();
5207 DrawChooseTree(&leveldir_current);
5209 PlayMenuSoundsAndMusic();
5212 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5214 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5217 void DrawChooseLevelNr(void)
5221 FadeMenuSoundsAndMusic();
5223 if (level_number != NULL)
5225 freeTreeInfo(level_number);
5227 level_number = NULL;
5230 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5232 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5233 char identifier[32], name[64];
5236 // temporarily load level info to get level name
5237 LoadLevelInfoOnly(i);
5239 ti->node_top = &level_number;
5240 ti->sort_priority = 10000 + value;
5241 ti->color = (level.no_level_file ? FC_BLUE :
5242 LevelStats_getSolved(i) ? FC_GREEN :
5243 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5245 snprintf(identifier, sizeof(identifier), "%d", value);
5246 snprintf(name, sizeof(name), "%03d: %s", value,
5247 (level.no_level_file ? "(no file)" : level.name));
5249 setString(&ti->identifier, identifier);
5250 setString(&ti->name, name);
5251 setString(&ti->name_sorting, name);
5253 pushTreeInfo(&level_number, ti);
5256 // sort level number values to start with lowest level number
5257 sortTreeInfo(&level_number);
5259 // set current level number to current level number
5260 level_number_current =
5261 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5263 // if that also fails, set current level number to first available level
5264 if (level_number_current == NULL)
5265 level_number_current = level_number;
5267 DrawChooseTree(&level_number_current);
5269 PlayMenuSoundsAndMusic();
5272 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5274 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5277 void DrawHallOfFame(int level_nr)
5279 int fade_mask = REDRAW_FIELD;
5282 fade_mask = REDRAW_ALL;
5285 FadeMenuSoundsAndMusic();
5287 // (this is needed when called from GameEnd() after winning a game)
5288 KeyboardAutoRepeatOn();
5290 // (this is needed when called from GameEnd() after winning a game)
5291 SetDrawDeactivationMask(REDRAW_NONE);
5292 SetDrawBackgroundMask(REDRAW_FIELD);
5294 LoadLocalAndServerScore(level_nr, TRUE);
5296 if (scores.last_added >= 0)
5297 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5299 FadeSetEnterScreen();
5303 // needed if different viewport properties defined for scores
5304 ChangeViewportPropertiesIfNeeded();
5306 PlayMenuSoundsAndMusic();
5308 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5310 HandleHallOfFame(level_nr, 0, 0, 0, MB_MENU_INITIALIZE);
5312 DrawMaskedBorder(fade_mask);
5317 static int getHallOfFameFirstEntry(int first_entry, int step)
5320 first_entry = scores.last_added - (NUM_MENU_ENTRIES_ON_SCREEN + 1) / 2 + 1;
5322 first_entry += step;
5324 if (first_entry < 0)
5326 else if (first_entry > MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN)
5327 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
5332 static char *getHallOfFameScoreText(int nr)
5334 if (!level.rate_time_over_score)
5335 return int2str(scores.entry[nr].score, 5); // show normal score
5337 if (level.use_step_counter)
5338 return int2str(scores.entry[nr].time, 5); // show number of steps
5340 static char score_text[10];
5341 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5342 int mm = (time_seconds / 60) % 60;
5343 int ss = (time_seconds % 60);
5345 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5350 static void drawHallOfFameList(int level_nr, int first_entry)
5354 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5357 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
5358 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
5359 "HighScores of Level %d", level_nr);
5361 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5363 int entry = first_entry + i;
5364 boolean active = (entry == scores.last_added);
5365 boolean forced = (scores.force_last_added && active);
5366 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
5367 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
5368 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
5369 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
5370 int dxoff = getFontDrawOffsetX(font_nr1);
5371 int dx1 = 3 * getFontWidth(font_nr1);
5372 int dx2 = dx1 + getFontWidth(font_nr1);
5373 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
5374 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
5375 int sy = mSY + 64 + i * 32;
5376 char *pos_text = (forced ? "???" : int2str(entry + 1, 3));
5378 DrawText(mSX, sy, pos_text, font_nr1);
5379 DrawText(mSX + dx1, sy, ".", font_nr1);
5381 for (j = 0; j < num_dots; j++)
5382 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
5384 if (!strEqual(scores.entry[entry].name, EMPTY_PLAYER_NAME))
5385 DrawText(mSX + dx2, sy, scores.entry[entry].name, font_nr2);
5387 DrawText(mSX + dx3, sy, getHallOfFameScoreText(entry), font_nr4);
5390 redraw_mask |= REDRAW_FIELD;
5393 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5395 static int level_nr = 0;
5396 static int first_entry = 0;
5397 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5399 if (button == MB_MENU_INITIALIZE)
5403 if (server_scores.updated)
5405 // reload scores, using updated server score cache file
5406 LoadLocalAndServerScore(level_nr, FALSE);
5408 server_scores.updated = FALSE;
5411 first_entry = getHallOfFameFirstEntry(0, 0);
5413 drawHallOfFameList(level_nr, first_entry);
5418 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
5419 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
5423 first_entry = getHallOfFameFirstEntry(first_entry, -step);
5425 drawHallOfFameList(level_nr, first_entry);
5429 first_entry = getHallOfFameFirstEntry(first_entry, step);
5431 drawHallOfFameList(level_nr, first_entry);
5433 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5435 PlaySound(SND_MENU_ITEM_SELECTING);
5437 FadeSound(SND_BACKGROUND_SCORES);
5439 if (button == MB_MENU_CHOICE &&
5440 game_status_last_screen == GAME_MODE_PLAYING &&
5441 setup.auto_play_next_level && setup.increment_levels &&
5442 level_nr < leveldir_current->last_level &&
5445 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
5449 SetGameStatus(GAME_MODE_MAIN);
5454 else if (server_scores.updated)
5456 // reload scores, using updated server score cache file
5457 LoadLocalAndServerScore(level_nr, FALSE);
5459 server_scores.updated = FALSE;
5461 first_entry = getHallOfFameFirstEntry(0, 0);
5463 drawHallOfFameList(level_nr, first_entry);
5466 if (game_status == GAME_MODE_SCORES)
5467 PlayMenuSoundIfLoop();
5471 // ============================================================================
5472 // setup screen functions
5473 // ============================================================================
5475 static struct TokenInfo *setup_info;
5476 static int num_setup_info; // number of setup entries shown on screen
5477 static int max_setup_info; // total number of setup entries in list
5479 static char *window_size_text;
5480 static char *scaling_type_text;
5481 static char *rendering_mode_text;
5482 static char *vsync_mode_text;
5483 static char *scroll_delay_text;
5484 static char *snapshot_mode_text;
5485 static char *game_speed_text;
5486 static char *scores_type_text;
5487 static char *network_server_text;
5488 static char *graphics_set_name;
5489 static char *sounds_set_name;
5490 static char *music_set_name;
5491 static char *volume_simple_text;
5492 static char *volume_loops_text;
5493 static char *volume_music_text;
5494 static char *touch_controls_text;
5495 static char *move_distance_text;
5496 static char *drop_distance_text;
5497 static char *transparency_text;
5498 static char *grid_size_text[2][2];
5500 static void execSetupMain(void)
5502 setup_mode = SETUP_MODE_MAIN;
5507 static void execSetupGame_setScoresType(void)
5509 if (scores_types == NULL)
5513 for (i = 0; scores_types_list[i].value != NULL; i++)
5515 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5516 char identifier[32], name[32];
5517 char *value = scores_types_list[i].value;
5518 char *text = scores_types_list[i].text;
5520 ti->node_top = &scores_types;
5521 ti->sort_priority = i;
5523 sprintf(identifier, "%s", value);
5524 sprintf(name, "%s", text);
5526 setString(&ti->identifier, identifier);
5527 setString(&ti->name, name);
5528 setString(&ti->name_sorting, name);
5529 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5531 pushTreeInfo(&scores_types, ti);
5534 // sort scores type values to start with lowest scores type value
5535 sortTreeInfo(&scores_types);
5537 // set current scores type value to configured scores type value
5538 scores_type_current =
5539 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5541 // if that fails, set current scores type to reliable default value
5542 if (scores_type_current == NULL)
5543 scores_type_current =
5544 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5546 // if that also fails, set current scores type to first available value
5547 if (scores_type_current == NULL)
5548 scores_type_current = scores_types;
5551 setup.scores_in_highscore_list = scores_type_current->identifier;
5553 // needed for displaying scores type text instead of identifier
5554 scores_type_text = scores_type_current->name;
5557 static void execSetupGame_setGameSpeeds(boolean update_value)
5559 if (setup.game_speed_extended)
5561 game_speeds_list = game_speeds_list_extended;
5562 game_speeds = game_speeds_extended;
5566 game_speeds_list = game_speeds_list_normal;
5567 game_speeds = game_speeds_normal;
5570 if (game_speeds == NULL)
5574 for (i = 0; game_speeds_list[i].value != -1; i++)
5576 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5577 char identifier[32], name[32];
5578 int value = game_speeds_list[i].value;
5579 char *text = game_speeds_list[i].text;
5581 ti->node_top = &game_speeds;
5582 ti->sort_priority = 10000 - value;
5584 sprintf(identifier, "%d", value);
5585 sprintf(name, "%s", text);
5587 setString(&ti->identifier, identifier);
5588 setString(&ti->name, name);
5589 setString(&ti->name_sorting, name);
5590 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5592 pushTreeInfo(&game_speeds, ti);
5595 // sort game speed values to start with slowest game speed
5596 sortTreeInfo(&game_speeds);
5598 update_value = TRUE;
5603 // set current game speed to configured game speed value
5604 game_speed_current =
5605 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5607 // if that fails, set current game speed to reliable default value
5608 if (game_speed_current == NULL)
5609 game_speed_current =
5610 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5612 // if that also fails, set current game speed to first available speed
5613 if (game_speed_current == NULL)
5614 game_speed_current = game_speeds;
5616 if (setup.game_speed_extended)
5617 game_speeds_extended = game_speeds;
5619 game_speeds_normal = game_speeds;
5622 setup.game_frame_delay = atoi(game_speed_current->identifier);
5624 // needed for displaying game speed text instead of identifier
5625 game_speed_text = game_speed_current->name;
5628 static void execSetupGame_setScrollDelays(void)
5630 if (scroll_delays == NULL)
5634 for (i = 0; scroll_delays_list[i].value != -1; i++)
5636 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5637 char identifier[32], name[32];
5638 int value = scroll_delays_list[i].value;
5639 char *text = scroll_delays_list[i].text;
5641 ti->node_top = &scroll_delays;
5642 ti->sort_priority = value;
5644 sprintf(identifier, "%d", value);
5645 sprintf(name, "%s", text);
5647 setString(&ti->identifier, identifier);
5648 setString(&ti->name, name);
5649 setString(&ti->name_sorting, name);
5650 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5652 pushTreeInfo(&scroll_delays, ti);
5655 // sort scroll delay values to start with lowest scroll delay value
5656 sortTreeInfo(&scroll_delays);
5658 // set current scroll delay value to configured scroll delay value
5659 scroll_delay_current =
5660 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5662 // if that fails, set current scroll delay to reliable default value
5663 if (scroll_delay_current == NULL)
5664 scroll_delay_current =
5665 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5667 // if that also fails, set current scroll delay to first available value
5668 if (scroll_delay_current == NULL)
5669 scroll_delay_current = scroll_delays;
5672 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5674 // needed for displaying scroll delay text instead of identifier
5675 scroll_delay_text = scroll_delay_current->name;
5678 static void execSetupGame_setSnapshotModes(void)
5680 if (snapshot_modes == NULL)
5684 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5686 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5687 char identifier[32], name[32];
5688 char *value = snapshot_modes_list[i].value;
5689 char *text = snapshot_modes_list[i].text;
5691 ti->node_top = &snapshot_modes;
5692 ti->sort_priority = i;
5694 sprintf(identifier, "%s", value);
5695 sprintf(name, "%s", text);
5697 setString(&ti->identifier, identifier);
5698 setString(&ti->name, name);
5699 setString(&ti->name_sorting, name);
5700 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5702 pushTreeInfo(&snapshot_modes, ti);
5705 // sort snapshot mode values to start with lowest snapshot mode value
5706 sortTreeInfo(&snapshot_modes);
5708 // set current snapshot mode value to configured snapshot mode value
5709 snapshot_mode_current =
5710 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5712 // if that fails, set current snapshot mode to reliable default value
5713 if (snapshot_mode_current == NULL)
5714 snapshot_mode_current =
5715 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5717 // if that also fails, set current snapshot mode to first available value
5718 if (snapshot_mode_current == NULL)
5719 snapshot_mode_current = snapshot_modes;
5722 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5724 // needed for displaying snapshot mode text instead of identifier
5725 snapshot_mode_text = snapshot_mode_current->name;
5728 static void execSetupGame_setNetworkServerText(void)
5730 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5732 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5736 strncpy(network_server_hostname, setup.network_server_hostname,
5737 MAX_SETUP_TEXT_INPUT_LEN);
5738 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5741 // needed for displaying network server text instead of identifier
5742 network_server_text = network_server_hostname;
5745 static void execSetupGame(void)
5747 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5749 execSetupGame_setGameSpeeds(FALSE);
5750 execSetupGame_setScoresType();
5751 execSetupGame_setScrollDelays();
5752 execSetupGame_setSnapshotModes();
5754 execSetupGame_setNetworkServerText();
5756 if (!setup.provide_uploading_tapes)
5757 setHideSetupEntry(execOfferUploadTapes);
5759 setup_mode = SETUP_MODE_GAME;
5763 // check if vsync needs to be disabled for this game speed to work
5764 if (check_vsync_mode)
5765 DisableVsyncIfNeeded();
5768 static void execSetupChooseScoresType(void)
5770 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
5775 static void execSetupChooseGameSpeed(void)
5777 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5782 static void execSetupChooseScrollDelay(void)
5784 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5789 static void execSetupChooseSnapshotMode(void)
5791 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5796 static void execSetupEngines(void)
5798 setup_mode = SETUP_MODE_ENGINES;
5803 static void execSetupEditor(void)
5805 setup_mode = SETUP_MODE_EDITOR;
5810 static void execSetupGraphics_setWindowSizes(boolean update_list)
5812 if (window_sizes != NULL && update_list)
5814 freeTreeInfo(window_sizes);
5816 window_sizes = NULL;
5819 if (window_sizes == NULL)
5821 boolean current_window_size_found = FALSE;
5824 for (i = 0; window_sizes_list[i].value != -1; i++)
5826 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5827 char identifier[32], name[32];
5828 int value = window_sizes_list[i].value;
5829 char *text = window_sizes_list[i].text;
5831 ti->node_top = &window_sizes;
5832 ti->sort_priority = value;
5834 sprintf(identifier, "%d", value);
5835 sprintf(name, "%s", text);
5837 setString(&ti->identifier, identifier);
5838 setString(&ti->name, name);
5839 setString(&ti->name_sorting, name);
5840 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5842 pushTreeInfo(&window_sizes, ti);
5844 if (value == setup.window_scaling_percent)
5845 current_window_size_found = TRUE;
5848 if (!current_window_size_found)
5850 // add entry for non-preset window scaling value
5852 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5853 char identifier[32], name[32];
5854 int value = setup.window_scaling_percent;
5856 ti->node_top = &window_sizes;
5857 ti->sort_priority = value;
5859 sprintf(identifier, "%d", value);
5860 sprintf(name, "%d %% (Current)", value);
5862 setString(&ti->identifier, identifier);
5863 setString(&ti->name, name);
5864 setString(&ti->name_sorting, name);
5865 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5867 pushTreeInfo(&window_sizes, ti);
5870 // sort window size values to start with lowest window size value
5871 sortTreeInfo(&window_sizes);
5873 // set current window size value to configured window size value
5874 window_size_current =
5875 getTreeInfoFromIdentifier(window_sizes,
5876 i_to_a(setup.window_scaling_percent));
5878 // if that fails, set current window size to reliable default value
5879 if (window_size_current == NULL)
5880 window_size_current =
5881 getTreeInfoFromIdentifier(window_sizes,
5882 i_to_a(STD_WINDOW_SCALING_PERCENT));
5884 // if that also fails, set current window size to first available value
5885 if (window_size_current == NULL)
5886 window_size_current = window_sizes;
5889 setup.window_scaling_percent = atoi(window_size_current->identifier);
5891 // needed for displaying window size text instead of identifier
5892 window_size_text = window_size_current->name;
5895 static void execSetupGraphics_setScalingTypes(void)
5897 if (scaling_types == NULL)
5901 for (i = 0; scaling_types_list[i].value != NULL; i++)
5903 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5904 char identifier[32], name[32];
5905 char *value = scaling_types_list[i].value;
5906 char *text = scaling_types_list[i].text;
5908 ti->node_top = &scaling_types;
5909 ti->sort_priority = i;
5911 sprintf(identifier, "%s", value);
5912 sprintf(name, "%s", text);
5914 setString(&ti->identifier, identifier);
5915 setString(&ti->name, name);
5916 setString(&ti->name_sorting, name);
5917 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5919 pushTreeInfo(&scaling_types, ti);
5922 // sort scaling type values to start with lowest scaling type value
5923 sortTreeInfo(&scaling_types);
5925 // set current scaling type value to configured scaling type value
5926 scaling_type_current =
5927 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5929 // if that fails, set current scaling type to reliable default value
5930 if (scaling_type_current == NULL)
5931 scaling_type_current =
5932 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5934 // if that also fails, set current scaling type to first available value
5935 if (scaling_type_current == NULL)
5936 scaling_type_current = scaling_types;
5939 setup.window_scaling_quality = scaling_type_current->identifier;
5941 // needed for displaying scaling type text instead of identifier
5942 scaling_type_text = scaling_type_current->name;
5945 static void execSetupGraphics_setRenderingModes(void)
5947 if (rendering_modes == NULL)
5951 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5953 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5954 char identifier[32], name[32];
5955 char *value = rendering_modes_list[i].value;
5956 char *text = rendering_modes_list[i].text;
5958 ti->node_top = &rendering_modes;
5959 ti->sort_priority = i;
5961 sprintf(identifier, "%s", value);
5962 sprintf(name, "%s", text);
5964 setString(&ti->identifier, identifier);
5965 setString(&ti->name, name);
5966 setString(&ti->name_sorting, name);
5967 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5969 pushTreeInfo(&rendering_modes, ti);
5972 // sort rendering mode values to start with lowest rendering mode value
5973 sortTreeInfo(&rendering_modes);
5975 // set current rendering mode value to configured rendering mode value
5976 rendering_mode_current =
5977 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5979 // if that fails, set current rendering mode to reliable default value
5980 if (rendering_mode_current == NULL)
5981 rendering_mode_current =
5982 getTreeInfoFromIdentifier(rendering_modes,
5983 STR_SPECIAL_RENDERING_DEFAULT);
5985 // if that also fails, set current rendering mode to first available one
5986 if (rendering_mode_current == NULL)
5987 rendering_mode_current = rendering_modes;
5990 setup.screen_rendering_mode = rendering_mode_current->identifier;
5992 // needed for displaying rendering mode text instead of identifier
5993 rendering_mode_text = rendering_mode_current->name;
5996 static void execSetupGraphics_setVsyncModes(boolean update_value)
5998 if (vsync_modes == NULL)
6002 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6004 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6005 char identifier[32], name[32];
6006 char *value = vsync_modes_list[i].value;
6007 char *text = vsync_modes_list[i].text;
6009 ti->node_top = &vsync_modes;
6010 ti->sort_priority = i;
6012 sprintf(identifier, "%s", value);
6013 sprintf(name, "%s", text);
6015 setString(&ti->identifier, identifier);
6016 setString(&ti->name, name);
6017 setString(&ti->name_sorting, name);
6018 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6020 pushTreeInfo(&vsync_modes, ti);
6023 // sort vsync mode values to start with lowest vsync mode value
6024 sortTreeInfo(&vsync_modes);
6026 update_value = TRUE;
6031 // set current vsync mode value to configured vsync mode value
6032 vsync_mode_current =
6033 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6035 // if that fails, set current vsync mode to reliable default value
6036 if (vsync_mode_current == NULL)
6037 vsync_mode_current =
6038 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6040 // if that also fails, set current vsync mode to first available one
6041 if (vsync_mode_current == NULL)
6042 vsync_mode_current = vsync_modes;
6045 setup.vsync_mode = vsync_mode_current->identifier;
6047 // needed for displaying vsync mode text instead of identifier
6048 vsync_mode_text = vsync_mode_current->name;
6051 static void execSetupGraphics(void)
6053 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6055 // update "setup.window_scaling_percent" from list selection
6056 // (in this case, window scaling was changed on setup screen)
6057 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6058 execSetupGraphics_setWindowSizes(FALSE);
6060 // update "setup.vsync_mode" from list selection
6061 // (in this case, vsync mode was changed on setup screen)
6062 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6063 execSetupGraphics_setVsyncModes(FALSE);
6065 // update list selection from "setup.window_scaling_percent"
6066 // (window scaling may have changed by resizing the window)
6067 execSetupGraphics_setWindowSizes(TRUE);
6069 // update list selection from "setup.vsync_mode"
6070 // (vsync_mode may have changed by re-creating the renderer)
6071 execSetupGraphics_setVsyncModes(TRUE);
6073 execSetupGraphics_setScalingTypes();
6074 execSetupGraphics_setRenderingModes();
6076 setup_mode = SETUP_MODE_GRAPHICS;
6080 // check if game speed is high enough for 60 Hz vsync to work
6081 if (check_game_speed)
6082 ModifyGameSpeedIfNeeded();
6084 // window scaling may have changed at this point
6085 ChangeWindowScalingIfNeeded();
6087 // window scaling quality may have changed at this point
6088 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6089 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6091 // screen rendering mode may have changed at this point
6092 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6094 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6095 int video_vsync_mode = video.vsync_mode;
6097 // screen vsync mode may have changed at this point
6098 ChangeVsyncModeIfNeeded();
6100 // check if setting vsync mode to selected value failed
6101 if (setup_vsync_mode != video_vsync_mode &&
6102 setup_vsync_mode != video.vsync_mode)
6104 // changing vsync mode to selected value failed -- reset displayed value
6105 execSetupGraphics_setVsyncModes(TRUE);
6107 Request("Setting VSync failed!", REQ_CONFIRM);
6113 static void execSetupChooseWindowSize(void)
6115 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6120 static void execSetupChooseScalingType(void)
6122 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6127 static void execSetupChooseRenderingMode(void)
6129 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6134 static void execSetupChooseVsyncMode(void)
6136 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6141 static void execSetupChooseVolumeSimple(void)
6143 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6148 static void execSetupChooseVolumeLoops(void)
6150 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6155 static void execSetupChooseVolumeMusic(void)
6157 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6162 static void execSetupSound(void)
6164 if (volumes_simple == NULL)
6166 boolean current_volume_simple_found = FALSE;
6169 for (i = 0; volumes_list[i].value != -1; i++)
6171 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6172 char identifier[32], name[32];
6173 int value = volumes_list[i].value;
6174 char *text = volumes_list[i].text;
6176 ti->node_top = &volumes_simple;
6177 ti->sort_priority = value;
6179 sprintf(identifier, "%d", value);
6180 sprintf(name, "%s", text);
6182 setString(&ti->identifier, identifier);
6183 setString(&ti->name, name);
6184 setString(&ti->name_sorting, name);
6185 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6187 pushTreeInfo(&volumes_simple, ti);
6189 if (value == setup.volume_simple)
6190 current_volume_simple_found = TRUE;
6193 if (!current_volume_simple_found)
6195 // add entry for non-preset volume value
6197 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6198 char identifier[32], name[32];
6199 int value = setup.volume_simple;
6201 ti->node_top = &volumes_simple;
6202 ti->sort_priority = value;
6204 sprintf(identifier, "%d", value);
6205 sprintf(name, "%d %% (Current)", value);
6207 setString(&ti->identifier, identifier);
6208 setString(&ti->name, name);
6209 setString(&ti->name_sorting, name);
6210 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6212 pushTreeInfo(&volumes_simple, ti);
6215 // sort volume values to start with lowest volume value
6216 sortTreeInfo(&volumes_simple);
6218 // set current volume value to configured volume value
6219 volume_simple_current =
6220 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6222 // if that fails, set current volume to reliable default value
6223 if (volume_simple_current == NULL)
6224 volume_simple_current =
6225 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6227 // if that also fails, set current volume to first available value
6228 if (volume_simple_current == NULL)
6229 volume_simple_current = volumes_simple;
6232 if (volumes_loops == NULL)
6234 boolean current_volume_loops_found = FALSE;
6237 for (i = 0; volumes_list[i].value != -1; i++)
6239 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6240 char identifier[32], name[32];
6241 int value = volumes_list[i].value;
6242 char *text = volumes_list[i].text;
6244 ti->node_top = &volumes_loops;
6245 ti->sort_priority = value;
6247 sprintf(identifier, "%d", value);
6248 sprintf(name, "%s", text);
6250 setString(&ti->identifier, identifier);
6251 setString(&ti->name, name);
6252 setString(&ti->name_sorting, name);
6253 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6255 pushTreeInfo(&volumes_loops, ti);
6257 if (value == setup.volume_loops)
6258 current_volume_loops_found = TRUE;
6261 if (!current_volume_loops_found)
6263 // add entry for non-preset volume value
6265 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6266 char identifier[32], name[32];
6267 int value = setup.volume_loops;
6269 ti->node_top = &volumes_loops;
6270 ti->sort_priority = value;
6272 sprintf(identifier, "%d", value);
6273 sprintf(name, "%d %% (Current)", value);
6275 setString(&ti->identifier, identifier);
6276 setString(&ti->name, name);
6277 setString(&ti->name_sorting, name);
6278 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6280 pushTreeInfo(&volumes_loops, ti);
6283 // sort volume values to start with lowest volume value
6284 sortTreeInfo(&volumes_loops);
6286 // set current volume value to configured volume value
6287 volume_loops_current =
6288 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6290 // if that fails, set current volume to reliable default value
6291 if (volume_loops_current == NULL)
6292 volume_loops_current =
6293 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6295 // if that also fails, set current volume to first available value
6296 if (volume_loops_current == NULL)
6297 volume_loops_current = volumes_loops;
6300 if (volumes_music == NULL)
6302 boolean current_volume_music_found = FALSE;
6305 for (i = 0; volumes_list[i].value != -1; i++)
6307 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6308 char identifier[32], name[32];
6309 int value = volumes_list[i].value;
6310 char *text = volumes_list[i].text;
6312 ti->node_top = &volumes_music;
6313 ti->sort_priority = value;
6315 sprintf(identifier, "%d", value);
6316 sprintf(name, "%s", text);
6318 setString(&ti->identifier, identifier);
6319 setString(&ti->name, name);
6320 setString(&ti->name_sorting, name);
6321 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6323 pushTreeInfo(&volumes_music, ti);
6325 if (value == setup.volume_music)
6326 current_volume_music_found = TRUE;
6329 if (!current_volume_music_found)
6331 // add entry for non-preset volume value
6333 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6334 char identifier[32], name[32];
6335 int value = setup.volume_music;
6337 ti->node_top = &volumes_music;
6338 ti->sort_priority = value;
6340 sprintf(identifier, "%d", value);
6341 sprintf(name, "%d %% (Current)", value);
6343 setString(&ti->identifier, identifier);
6344 setString(&ti->name, name);
6345 setString(&ti->name_sorting, name);
6346 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6348 pushTreeInfo(&volumes_music, ti);
6351 // sort volume values to start with lowest volume value
6352 sortTreeInfo(&volumes_music);
6354 // set current volume value to configured volume value
6355 volume_music_current =
6356 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6358 // if that fails, set current volume to reliable default value
6359 if (volume_music_current == NULL)
6360 volume_music_current =
6361 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6363 // if that also fails, set current volume to first available value
6364 if (volume_music_current == NULL)
6365 volume_music_current = volumes_music;
6368 setup.volume_simple = atoi(volume_simple_current->identifier);
6369 setup.volume_loops = atoi(volume_loops_current->identifier);
6370 setup.volume_music = atoi(volume_music_current->identifier);
6372 // needed for displaying volume text instead of identifier
6373 volume_simple_text = volume_simple_current->name;
6374 volume_loops_text = volume_loops_current->name;
6375 volume_music_text = volume_music_current->name;
6377 setup_mode = SETUP_MODE_SOUND;
6382 static void execSetupChooseTouchControls(void)
6384 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6389 static void execSetupChooseMoveDistance(void)
6391 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6396 static void execSetupChooseDropDistance(void)
6398 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6403 static void execSetupChooseTransparency(void)
6405 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6410 static void execSetupChooseGridXSize_0(void)
6412 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6417 static void execSetupChooseGridYSize_0(void)
6419 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6424 static void execSetupChooseGridXSize_1(void)
6426 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6431 static void execSetupChooseGridYSize_1(void)
6433 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6438 static void execSetupConfigureVirtualButtons(void)
6440 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6442 ConfigureVirtualButtons();
6444 setup_mode = SETUP_MODE_TOUCH;
6449 static void execSetupTouch(void)
6453 if (touch_controls == NULL)
6455 for (i = 0; touch_controls_list[i].value != NULL; i++)
6457 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6458 char identifier[32], name[32];
6459 char *value = touch_controls_list[i].value;
6460 char *text = touch_controls_list[i].text;
6462 ti->node_top = &touch_controls;
6463 ti->sort_priority = i;
6465 sprintf(identifier, "%s", value);
6466 sprintf(name, "%s", text);
6468 setString(&ti->identifier, identifier);
6469 setString(&ti->name, name);
6470 setString(&ti->name_sorting, name);
6471 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6473 pushTreeInfo(&touch_controls, ti);
6476 // sort touch control values to start with lowest touch control value
6477 sortTreeInfo(&touch_controls);
6479 // set current touch control value to configured touch control value
6480 touch_control_current =
6481 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6483 // if that fails, set current touch control to reliable default value
6484 if (touch_control_current == NULL)
6485 touch_control_current =
6486 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6488 // if that also fails, set current touch control to first available value
6489 if (touch_control_current == NULL)
6490 touch_control_current = touch_controls;
6493 if (move_distances == NULL)
6495 for (i = 0; distances_list[i].value != -1; i++)
6497 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6498 char identifier[32], name[32];
6499 int value = distances_list[i].value;
6500 char *text = distances_list[i].text;
6502 ti->node_top = &move_distances;
6503 ti->sort_priority = value;
6505 sprintf(identifier, "%d", value);
6506 sprintf(name, "%s", text);
6508 setString(&ti->identifier, identifier);
6509 setString(&ti->name, name);
6510 setString(&ti->name_sorting, name);
6511 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6513 pushTreeInfo(&move_distances, ti);
6516 // sort distance values to start with lowest distance value
6517 sortTreeInfo(&move_distances);
6519 // set current distance value to configured distance value
6520 move_distance_current =
6521 getTreeInfoFromIdentifier(move_distances,
6522 i_to_a(setup.touch.move_distance));
6524 // if that fails, set current distance to reliable default value
6525 if (move_distance_current == NULL)
6526 move_distance_current =
6527 getTreeInfoFromIdentifier(move_distances,
6528 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6530 // if that also fails, set current distance to first available value
6531 if (move_distance_current == NULL)
6532 move_distance_current = move_distances;
6535 if (drop_distances == NULL)
6537 for (i = 0; distances_list[i].value != -1; i++)
6539 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6540 char identifier[32], name[32];
6541 int value = distances_list[i].value;
6542 char *text = distances_list[i].text;
6544 ti->node_top = &drop_distances;
6545 ti->sort_priority = value;
6547 sprintf(identifier, "%d", value);
6548 sprintf(name, "%s", text);
6550 setString(&ti->identifier, identifier);
6551 setString(&ti->name, name);
6552 setString(&ti->name_sorting, name);
6553 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6555 pushTreeInfo(&drop_distances, ti);
6558 // sort distance values to start with lowest distance value
6559 sortTreeInfo(&drop_distances);
6561 // set current distance value to configured distance value
6562 drop_distance_current =
6563 getTreeInfoFromIdentifier(drop_distances,
6564 i_to_a(setup.touch.drop_distance));
6566 // if that fails, set current distance to reliable default value
6567 if (drop_distance_current == NULL)
6568 drop_distance_current =
6569 getTreeInfoFromIdentifier(drop_distances,
6570 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6572 // if that also fails, set current distance to first available value
6573 if (drop_distance_current == NULL)
6574 drop_distance_current = drop_distances;
6577 if (transparencies == NULL)
6579 for (i = 0; transparencies_list[i].value != -1; i++)
6581 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6582 char identifier[32], name[32];
6583 int value = transparencies_list[i].value;
6584 char *text = transparencies_list[i].text;
6586 ti->node_top = &transparencies;
6587 ti->sort_priority = value;
6589 sprintf(identifier, "%d", value);
6590 sprintf(name, "%s", text);
6592 setString(&ti->identifier, identifier);
6593 setString(&ti->name, name);
6594 setString(&ti->name_sorting, name);
6595 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6597 pushTreeInfo(&transparencies, ti);
6600 // sort transparency values to start with lowest transparency value
6601 sortTreeInfo(&transparencies);
6603 // set current transparency value to configured transparency value
6604 transparency_current =
6605 getTreeInfoFromIdentifier(transparencies,
6606 i_to_a(setup.touch.transparency));
6608 // if that fails, set current transparency to reliable default value
6609 if (transparency_current == NULL)
6610 transparency_current =
6611 getTreeInfoFromIdentifier(transparencies,
6612 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6614 // if that also fails, set current transparency to first available value
6615 if (transparency_current == NULL)
6616 transparency_current = transparencies;
6619 for (i = 0; i < 2; i++)
6621 for (j = 0; j < 2; j++)
6623 if (grid_sizes[i][j] == NULL)
6625 for (k = 0; grid_sizes_list[k].value != -1; k++)
6627 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6628 char identifier[32], name[32];
6629 int value = grid_sizes_list[k].value;
6630 char *text = grid_sizes_list[k].text;
6632 ti->node_top = &grid_sizes[i][j];
6633 ti->sort_priority = value;
6635 sprintf(identifier, "%d", value);
6636 sprintf(name, "%s", text);
6638 setString(&ti->identifier, identifier);
6639 setString(&ti->name, name);
6640 setString(&ti->name_sorting, name);
6641 setString(&ti->infotext,
6644 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6645 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6647 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6648 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6650 pushTreeInfo(&grid_sizes[i][j], ti);
6653 // sort grid size values to start with lowest grid size value
6654 sortTreeInfo(&grid_sizes[i][j]);
6656 // set current grid size value to configured grid size value
6657 grid_size_current[i][j] =
6658 getTreeInfoFromIdentifier(grid_sizes[i][j],
6660 setup.touch.grid_xsize[i] :
6661 setup.touch.grid_ysize[i]));
6663 // if that fails, set current grid size to reliable default value
6664 if (grid_size_current[i][j] == NULL)
6665 grid_size_current[i][j] =
6666 getTreeInfoFromIdentifier(grid_sizes[i][j],
6668 DEFAULT_GRID_XSIZE(i) :
6669 DEFAULT_GRID_YSIZE(i)));
6671 // if that also fails, set current grid size to first available value
6672 if (grid_size_current[i][j] == NULL)
6673 grid_size_current[i][j] = grid_sizes[i][j];
6678 setup.touch.control_type = touch_control_current->identifier;
6679 setup.touch.move_distance = atoi(move_distance_current->identifier);
6680 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6681 setup.touch.transparency = atoi(transparency_current->identifier);
6683 for (i = 0; i < 2; i++)
6685 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6686 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6688 if (i == GRID_ACTIVE_NR())
6690 overlay.grid_xsize = setup.touch.grid_xsize[i];
6691 overlay.grid_ysize = setup.touch.grid_ysize[i];
6695 // needed for displaying value text instead of identifier
6696 touch_controls_text = touch_control_current->name;
6697 move_distance_text = move_distance_current->name;
6698 drop_distance_text = drop_distance_current->name;
6699 transparency_text = transparency_current->name;
6701 for (i = 0; i < 2; i++)
6702 for (j = 0; j < 2; j++)
6703 grid_size_text[i][j] = grid_size_current[i][j]->name;
6705 setup_mode = SETUP_MODE_TOUCH;
6710 static void execSetupArtwork(void)
6712 static ArtworkDirTree *gfx_last_valid = NULL;
6713 static ArtworkDirTree *snd_last_valid = NULL;
6714 static ArtworkDirTree *mus_last_valid = NULL;
6716 // current artwork directory may be invalid (level group, parent link)
6717 if (!validLevelSeries(artwork.gfx_current))
6718 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6719 if (!validLevelSeries(artwork.snd_current))
6720 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6721 if (!validLevelSeries(artwork.mus_current))
6722 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6724 // store valid artwork directory information
6725 gfx_last_valid = artwork.gfx_current;
6726 snd_last_valid = artwork.snd_current;
6727 mus_last_valid = artwork.mus_current;
6730 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6731 artwork.gfx_current->subdir,
6732 artwork.gfx_current->fullpath,
6733 artwork.gfx_current->basepath);
6736 setup.graphics_set = artwork.gfx_current->identifier;
6737 setup.sounds_set = artwork.snd_current->identifier;
6738 setup.music_set = artwork.mus_current->identifier;
6740 // needed if last screen (setup choice) changed graphics, sounds or music
6741 ReloadCustomArtwork(0);
6743 // needed for displaying artwork name instead of artwork identifier
6744 graphics_set_name = artwork.gfx_current->name;
6745 sounds_set_name = artwork.snd_current->name;
6746 music_set_name = artwork.mus_current->name;
6748 setup_mode = SETUP_MODE_ARTWORK;
6753 static void execSetupChooseGraphics(void)
6755 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6760 static void execSetupChooseSounds(void)
6762 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6767 static void execSetupChooseMusic(void)
6769 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6774 static void execSetupInput(void)
6776 setup_mode = SETUP_MODE_INPUT;
6781 static void execSetupShortcuts(void)
6783 setup_mode = SETUP_MODE_SHORTCUTS;
6788 static void execSetupShortcuts1(void)
6790 setup_mode = SETUP_MODE_SHORTCUTS_1;
6795 static void execSetupShortcuts2(void)
6797 setup_mode = SETUP_MODE_SHORTCUTS_2;
6802 static void execSetupShortcuts3(void)
6804 setup_mode = SETUP_MODE_SHORTCUTS_3;
6809 static void execSetupShortcuts4(void)
6811 setup_mode = SETUP_MODE_SHORTCUTS_4;
6816 static void execSetupShortcuts5(void)
6818 setup_mode = SETUP_MODE_SHORTCUTS_5;
6823 static void execExitSetup(void)
6825 SetGameStatus(GAME_MODE_MAIN);
6830 static void execSaveAndExitSetup(void)
6836 static void execGadgetNetworkServer(void)
6838 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6839 struct GadgetInfo *gi = screen_gadget[gadget_id];
6841 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6842 network_server_hostname[0] = '\0';
6844 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6848 ClickOnGadget(gi, MB_LEFTBUTTON);
6851 static void execOfferUploadTapes(void)
6856 static void ToggleNetworkModeIfNeeded(void)
6858 int font_title = FONT_TITLE_1;
6859 int font_foot = FC_BLUE;
6860 int ystart = mSY - SY + 16;
6861 int ybottom = mSY - SY + SYSIZE - 20;
6862 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6864 if (setup.network_mode == network.enabled)
6867 network.enabled = setup.network_mode;
6869 FadeOut(REDRAW_ALL);
6873 DrawTextSCentered(ystart, font_title, text);
6877 if (network.enabled)
6878 InitNetworkServer();
6880 DisconnectFromNetworkServer();
6882 DrawTextSCentered(ybottom, font_foot,
6883 "Press any key or button for setup menu");
6885 WaitForEventToContinue();
6890 static void ToggleGameSpeedsListIfNeeded(void)
6892 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6894 if (setup.game_speed_extended == using_game_speeds_extended)
6897 // try to match similar values when changing game speeds list
6898 if (setup.game_speed_extended)
6899 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6900 setup.game_frame_delay == 30 ? 29 :
6901 setup.game_frame_delay);
6903 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6904 setup.game_frame_delay == 16 ? 15 :
6905 setup.game_frame_delay >= 29 ? 30 :
6906 setup.game_frame_delay <= 10 ? 10 :
6907 setup.game_frame_delay);
6909 execSetupGame_setGameSpeeds(TRUE);
6914 static void ModifyGameSpeedIfNeeded(void)
6916 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6917 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6921 char *game_speed_text = "Fast";
6922 int game_speed_value = 15;
6924 if (setup.game_speed_extended)
6926 game_speed_text = "60 fps";
6927 game_speed_value = 16;
6930 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6932 // set game speed to existing list value that is fast enough for vsync
6933 setup.game_frame_delay = game_speed_value;
6935 execSetupGame_setGameSpeeds(TRUE);
6937 Request(message, REQ_CONFIRM);
6940 static void DisableVsyncIfNeeded(void)
6942 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6943 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6944 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6947 // disable vsync for the selected game speed to work
6948 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6950 execSetupGraphics_setVsyncModes(TRUE);
6952 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6958 void *related_value;
6959 } hide_related_entry_list[] =
6961 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
6962 { &setup.scores_in_highscore_list, &scores_type_text },
6964 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6965 { &setup.game_frame_delay, &game_speed_text },
6967 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6968 { &setup.scroll_delay_value, &scroll_delay_text },
6970 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6971 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6973 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6974 { &setup.window_scaling_percent, &window_size_text },
6976 { &setup.window_scaling_quality, execSetupChooseScalingType },
6977 { &setup.window_scaling_quality, &scaling_type_text },
6979 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6980 { &setup.screen_rendering_mode, &rendering_mode_text },
6982 { &setup.vsync_mode, execSetupChooseVsyncMode },
6983 { &setup.vsync_mode, &vsync_mode_text },
6985 { &setup.graphics_set, execSetupChooseGraphics },
6986 { &setup.graphics_set, &graphics_set_name },
6988 { &setup.sounds_set, execSetupChooseSounds },
6989 { &setup.sounds_set, &sounds_set_name },
6991 { &setup.music_set, execSetupChooseMusic },
6992 { &setup.music_set, &music_set_name },
6994 { &setup.volume_simple, execSetupChooseVolumeSimple },
6995 { &setup.volume_simple, &volume_simple_text },
6997 { &setup.volume_loops, execSetupChooseVolumeLoops },
6998 { &setup.volume_loops, &volume_loops_text },
7000 { &setup.volume_music, execSetupChooseVolumeMusic },
7001 { &setup.volume_music, &volume_music_text },
7003 { &setup.touch.control_type, execSetupChooseTouchControls },
7004 { &setup.touch.control_type, &touch_controls_text },
7006 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7007 { &setup.touch.move_distance, &move_distance_text },
7009 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7010 { &setup.touch.drop_distance, &drop_distance_text },
7012 { &setup.touch.transparency, execSetupChooseTransparency },
7013 { &setup.touch.transparency, &transparency_text },
7015 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7016 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7018 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7019 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7021 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7022 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7024 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7025 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7027 { &setup.internal.menu_game, execSetupGame },
7028 { &setup.internal.menu_engines, execSetupEngines },
7029 { &setup.internal.menu_editor, execSetupEditor },
7030 { &setup.internal.menu_graphics, execSetupGraphics },
7031 { &setup.internal.menu_sound, execSetupSound },
7032 { &setup.internal.menu_artwork, execSetupArtwork },
7033 { &setup.internal.menu_input, execSetupInput },
7034 { &setup.internal.menu_touch, execSetupTouch },
7035 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7036 { &setup.internal.menu_exit, execExitSetup },
7037 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7042 void setHideRelatedSetupEntries(void)
7046 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7047 if (hideSetupEntry(hide_related_entry_list[i].value))
7048 setHideSetupEntry(hide_related_entry_list[i].related_value);
7051 static struct TokenInfo setup_info_main[] =
7053 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7054 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7055 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7056 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7057 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7058 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7059 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7060 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7061 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7062 { TYPE_EMPTY, NULL, "" },
7063 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7064 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7069 static struct TokenInfo setup_info_game[] =
7071 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7072 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7073 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7074 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7075 { TYPE_STRING, &network_server_text, "" },
7076 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7077 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7078 { TYPE_STRING, &scores_type_text, "" },
7079 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload All Tapes to Server" },
7080 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7081 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7082 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7083 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7084 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7085 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7086 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7087 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7088 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7089 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7090 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7091 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7092 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7093 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7094 { TYPE_STRING, &game_speed_text, "" },
7095 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7097 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7098 { TYPE_STRING, &scroll_delay_text, "" },
7100 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7101 { TYPE_STRING, &snapshot_mode_text, "" },
7102 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7103 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7104 { TYPE_EMPTY, NULL, "" },
7105 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7110 static struct TokenInfo setup_info_engines[] =
7112 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7113 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7114 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7115 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7116 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7117 { TYPE_EMPTY, NULL, "" },
7118 { TYPE_HEADLINE, NULL, "Supaplex" },
7119 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7120 { TYPE_EMPTY, NULL, "" },
7121 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7126 static struct TokenInfo setup_info_editor[] =
7129 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7130 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7131 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7132 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7133 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7134 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7135 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7136 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7137 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7138 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7140 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7141 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7143 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7145 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7146 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7147 { TYPE_EMPTY, NULL, "" },
7149 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7150 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7151 { TYPE_EMPTY, NULL, "" },
7153 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7154 { TYPE_EMPTY, NULL, "" },
7155 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7156 { TYPE_EMPTY, NULL, "" },
7157 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7162 static struct TokenInfo setup_info_graphics[] =
7164 #if !defined(PLATFORM_ANDROID)
7165 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7166 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7167 { TYPE_STRING, &window_size_text, "" },
7168 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7169 { TYPE_STRING, &scaling_type_text, "" },
7170 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7171 { TYPE_STRING, &rendering_mode_text, "" },
7174 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7175 { TYPE_STRING, &scroll_delay_text, "" },
7177 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7178 { TYPE_STRING, &vsync_mode_text, "" },
7179 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7180 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7181 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7182 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7183 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7184 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7185 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7186 { TYPE_EMPTY, NULL, "" },
7187 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7192 static struct TokenInfo setup_info_sound[] =
7194 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7195 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7196 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7197 { TYPE_EMPTY, NULL, "" },
7198 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7199 { TYPE_STRING, &volume_simple_text, "" },
7200 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7201 { TYPE_STRING, &volume_loops_text, "" },
7202 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7203 { TYPE_STRING, &volume_music_text, "" },
7204 { TYPE_EMPTY, NULL, "" },
7205 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7210 static struct TokenInfo setup_info_artwork[] =
7212 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7213 { TYPE_STRING, &graphics_set_name, "" },
7214 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7215 { TYPE_STRING, &sounds_set_name, "" },
7216 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7217 { TYPE_STRING, &music_set_name, "" },
7218 { TYPE_EMPTY, NULL, "" },
7219 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7220 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7221 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7222 { TYPE_EMPTY, NULL, "" },
7223 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7228 static struct TokenInfo setup_info_input[] =
7230 { TYPE_SWITCH, NULL, "Player:" },
7231 { TYPE_SWITCH, NULL, "Device:" },
7232 { TYPE_SWITCH, NULL, "" },
7233 { TYPE_SKIPPABLE, NULL, "" },
7234 { TYPE_EMPTY, NULL, "" },
7235 { TYPE_EMPTY, NULL, "" },
7236 { TYPE_EMPTY, NULL, "" },
7237 { TYPE_EMPTY, NULL, "" },
7238 { TYPE_EMPTY, NULL, "" },
7239 { TYPE_EMPTY, NULL, "" },
7240 { TYPE_EMPTY, NULL, "" },
7241 { TYPE_EMPTY, NULL, "" },
7242 { TYPE_SKIPPABLE, NULL, "" },
7243 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7248 static struct TokenInfo setup_info_touch[] =
7250 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7251 { TYPE_STRING, &touch_controls_text, "" },
7252 { TYPE_EMPTY, NULL, "" },
7253 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7258 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7260 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7261 { TYPE_STRING, &touch_controls_text, "" },
7262 { TYPE_EMPTY, NULL, "" },
7263 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7264 { TYPE_STRING, &grid_size_text[0][0], "" },
7265 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7266 { TYPE_STRING, &grid_size_text[0][1], "" },
7267 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7268 { TYPE_STRING, &transparency_text, "" },
7269 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7270 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7271 { TYPE_EMPTY, NULL, "" },
7272 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7273 { TYPE_EMPTY, NULL, "" },
7274 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7279 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7281 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7282 { TYPE_STRING, &touch_controls_text, "" },
7283 { TYPE_EMPTY, NULL, "" },
7284 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7285 { TYPE_STRING, &grid_size_text[1][0], "" },
7286 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7287 { TYPE_STRING, &grid_size_text[1][1], "" },
7288 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7289 { TYPE_STRING, &transparency_text, "" },
7290 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7291 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7292 { TYPE_EMPTY, NULL, "" },
7293 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7294 { TYPE_EMPTY, NULL, "" },
7295 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7300 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7302 setup_info_touch_virtual_buttons_0,
7303 setup_info_touch_virtual_buttons_1
7306 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7308 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7309 { TYPE_STRING, &touch_controls_text, "" },
7310 { TYPE_EMPTY, NULL, "" },
7311 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7312 { TYPE_STRING, &move_distance_text, "" },
7313 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7314 { TYPE_STRING, &drop_distance_text, "" },
7315 { TYPE_EMPTY, NULL, "" },
7316 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7321 static struct TokenInfo setup_info_shortcuts[] =
7323 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7324 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7325 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7326 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7327 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7328 { TYPE_EMPTY, NULL, "" },
7329 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7334 static struct TokenInfo setup_info_shortcuts_1[] =
7336 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7337 { TYPE_KEY, &setup.shortcut.save_game, "" },
7338 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7339 { TYPE_KEY, &setup.shortcut.load_game, "" },
7340 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7341 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7342 { TYPE_EMPTY, NULL, "" },
7343 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7344 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7345 { TYPE_EMPTY, NULL, "" },
7346 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7351 static struct TokenInfo setup_info_shortcuts_2[] =
7353 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7354 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7355 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7356 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7357 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7358 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7359 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7360 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7361 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7362 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7363 { TYPE_EMPTY, NULL, "" },
7364 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7369 static struct TokenInfo setup_info_shortcuts_3[] =
7371 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7372 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7373 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7374 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7375 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7376 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7377 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7378 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7379 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7380 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7381 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7382 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7383 { TYPE_EMPTY, NULL, "" },
7384 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7389 static struct TokenInfo setup_info_shortcuts_4[] =
7391 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7392 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7393 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7394 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7395 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7396 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7397 { TYPE_EMPTY, NULL, "" },
7398 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7403 static struct TokenInfo setup_info_shortcuts_5[] =
7405 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7406 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7407 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7408 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7409 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7410 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7411 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7412 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7413 { TYPE_EMPTY, NULL, "" },
7414 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7419 static Key getSetupKey(void)
7421 Key key = KSYM_UNDEFINED;
7422 boolean got_key_event = FALSE;
7424 while (!got_key_event)
7428 if (NextValidEvent(&event))
7432 case EVENT_KEYPRESS:
7434 key = GetEventKey((KeyEvent *)&event, TRUE);
7436 // press 'Escape' or 'Enter' to keep the existing key binding
7437 if (key == KSYM_Escape || key == KSYM_Return)
7438 key = KSYM_UNDEFINED; // keep old value
7440 got_key_event = TRUE;
7444 case EVENT_KEYRELEASE:
7445 key_joystick_mapping = 0;
7449 HandleOtherEvents(&event);
7460 static int getSetupValueFont(int type, void *value)
7462 if (type & TYPE_GHOSTED)
7463 return FONT_OPTION_OFF;
7464 else if (type & TYPE_KEY)
7465 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7466 else if (type & TYPE_STRING)
7467 return FONT_VALUE_2;
7468 else if (type & TYPE_ECS_AGA)
7469 return FONT_VALUE_1;
7470 else if (type & TYPE_BOOLEAN_STYLE)
7471 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7472 else if (type & TYPE_YES_NO_AUTO)
7473 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7474 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7475 else if (type & TYPE_PLAYER)
7476 return FONT_VALUE_1;
7478 return FONT_VALUE_1;
7481 static int getSetupValueFontNarrow(int type, int font_nr)
7483 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7484 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7485 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7489 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7491 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7492 struct TokenInfo *si = &setup_info[si_pos];
7493 boolean font_draw_xoffset_modified = FALSE;
7494 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7495 int font_draw_xoffset_old = -1;
7496 int xoffset = (scrollbar_needed ? -1 : 0);
7497 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7498 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7499 int xpos = menu_screen_value_xpos;
7500 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7501 int startx = mSX + xpos * 32;
7502 int starty = mSY + ypos * 32;
7503 int type = si->type;
7504 void *value = si->value;
7505 char *value_string = getSetupValue(type, value);
7506 int font_nr_default = getSetupValueFont(type, value);
7507 int font_width_default = getFontWidth(font_nr_default);
7508 int font_nr = font_nr_default;
7511 if (value_string == NULL)
7514 if (type & TYPE_KEY)
7516 xpos = MENU_SCREEN_START_XPOS;
7518 if (type & TYPE_QUERY)
7519 value_string = "<press key>";
7521 else if (type & TYPE_STRING)
7523 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7525 xpos = MENU_SCREEN_START_XPOS;
7527 if (strlen(value_string) > max_value_len)
7528 value_string[max_value_len] = '\0';
7530 else if (type & TYPE_YES_NO_AUTO)
7532 xpos = menu_screen_value_xpos - 1;
7534 else if (type & TYPE_PLAYER)
7536 int displayed_player_nr = *(int *)value + 1;
7538 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7541 startx = mSX + xpos * 32;
7542 starty = mSY + ypos * 32;
7544 // special check if right-side setup values moved left due to scrollbar
7545 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7547 int max_menu_text_length = 26; // maximum text length for classic menu
7548 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7549 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7550 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7551 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7552 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7554 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7556 // when using narrow font, left-shifting text "auto" not needed
7557 if (type & TYPE_YES_NO_AUTO)
7561 startx = mSX + xpos * 32;
7563 font_nr = getSetupValueFontNarrow(type, font_nr);
7567 // downward compatibility correction for Juergen Bonhagen's menu settings
7568 if (setup_mode != SETUP_MODE_INPUT)
7570 int max_menu_text_length_big = (menu_screen_value_xpos -
7571 MENU_SCREEN_START_XPOS);
7572 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7573 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7574 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7575 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
7576 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7577 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7578 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7579 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7580 boolean correct_font_draw_xoffset = FALSE;
7582 if (xpos == MENU_SCREEN_START_XPOS &&
7583 startx + font1_xoffset < text_startx + text_font_xoffset)
7584 correct_font_draw_xoffset = TRUE;
7586 if (xpos == menu_screen_value_xpos &&
7587 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7588 correct_font_draw_xoffset = TRUE;
7590 // check if setup value would overlap with setup text when printed
7591 // (this can happen for extreme/wrong values for font draw offset)
7592 if (correct_font_draw_xoffset)
7594 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
7595 font_draw_xoffset_modified = TRUE;
7597 if (type & TYPE_KEY)
7598 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7599 else if (!(type & TYPE_STRING))
7600 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7601 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7605 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7606 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7608 DrawText(startx, starty, value_string, font_nr);
7610 if (type & TYPE_PLAYER)
7612 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7613 int player_nr = *(int *)value;
7614 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7615 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7616 int startx2 = startx + xoff;
7617 int starty2 = starty + yoff;
7619 if (DrawingOnBackground(startx2, starty2))
7620 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7622 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7623 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7626 if (font_draw_xoffset_modified)
7627 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7630 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7632 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7633 struct TokenInfo *si = &setup_info[si_pos];
7635 if (si->type & TYPE_BOOLEAN_STYLE)
7637 *(boolean *)si->value ^= TRUE;
7639 else if (si->type & TYPE_YES_NO_AUTO)
7643 (*(int *)si->value == AUTO ? TRUE :
7644 *(int *)si->value == TRUE ? FALSE : AUTO) :
7645 (*(int *)si->value == TRUE ? AUTO :
7646 *(int *)si->value == AUTO ? FALSE : TRUE));
7648 else if (si->type & TYPE_KEY)
7652 si->type |= TYPE_QUERY;
7653 drawSetupValue(screen_pos, setup_info_pos_raw);
7654 si->type &= ~TYPE_QUERY;
7656 key = getSetupKey();
7657 if (key != KSYM_UNDEFINED)
7658 *(Key *)si->value = key;
7660 else if (si->type & TYPE_PLAYER)
7662 int player_nr = *(int *)si->value;
7667 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7669 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7672 drawSetupValue(screen_pos, setup_info_pos_raw);
7674 // fullscreen state may have changed at this point
7675 if (si->value == &setup.fullscreen)
7676 ToggleFullscreenIfNeeded();
7678 // network mode may have changed at this point
7679 if (si->value == &setup.network_mode)
7680 ToggleNetworkModeIfNeeded();
7682 // API server mode may have changed at this point
7683 if (si->value == &setup.use_api_server)
7684 runtime.use_api_server = setup.use_api_server;
7686 // game speed list may have changed at this point
7687 if (si->value == &setup.game_speed_extended)
7688 ToggleGameSpeedsListIfNeeded();
7691 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7693 static struct TokenInfo *setup_info_final = NULL;
7698 // determine maximum list size of target list
7699 while (setup_info_orig[list_size++].type != 0);
7701 // free, allocate and clear memory for target list
7702 checked_free(setup_info_final);
7703 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7705 // copy setup info list without setup entries marked as hidden
7706 for (i = 0; setup_info_orig[i].type != 0; i++)
7708 // skip setup entries configured to be hidden
7709 if (hideSetupEntry(setup_info_orig[i].value))
7712 // skip skippable setup entries if screen is lower than usual
7713 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7714 setup_info_orig[i].type == TYPE_SKIPPABLE)
7717 setup_info_final[list_pos++] = setup_info_orig[i];
7720 return setup_info_final;
7723 static void DrawSetupScreen_Generic(void)
7725 int fade_mask = REDRAW_FIELD;
7726 boolean redraw_all = FALSE;
7727 char *title_string = NULL;
7731 fade_mask = REDRAW_ALL;
7734 FadeMenuSoundsAndMusic();
7736 FreeScreenGadgets();
7737 CreateScreenGadgets();
7739 if (redraw_mask & REDRAW_ALL)
7744 // needed if different viewport properties defined for setup screen
7745 ChangeViewportPropertiesIfNeeded();
7747 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7751 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7753 if (setup_mode == SETUP_MODE_MAIN)
7755 setup_info = setup_info_main;
7756 title_string = STR_SETUP_MAIN;
7758 else if (setup_mode == SETUP_MODE_GAME)
7760 setup_info = setup_info_game;
7761 title_string = STR_SETUP_GAME;
7763 else if (setup_mode == SETUP_MODE_ENGINES)
7765 setup_info = setup_info_engines;
7766 title_string = STR_SETUP_ENGINES;
7768 else if (setup_mode == SETUP_MODE_EDITOR)
7770 setup_info = setup_info_editor;
7771 title_string = STR_SETUP_EDITOR;
7773 else if (setup_mode == SETUP_MODE_GRAPHICS)
7775 setup_info = setup_info_graphics;
7776 title_string = STR_SETUP_GRAPHICS;
7778 else if (setup_mode == SETUP_MODE_SOUND)
7780 setup_info = setup_info_sound;
7781 title_string = STR_SETUP_SOUND;
7783 else if (setup_mode == SETUP_MODE_ARTWORK)
7785 setup_info = setup_info_artwork;
7786 title_string = STR_SETUP_ARTWORK;
7788 else if (setup_mode == SETUP_MODE_TOUCH)
7790 setup_info = setup_info_touch;
7791 title_string = STR_SETUP_TOUCH;
7793 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7794 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7795 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7796 setup_info = setup_info_touch_wipe_gestures;
7798 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7800 setup_info = setup_info_shortcuts;
7801 title_string = STR_SETUP_SHORTCUTS;
7803 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7805 setup_info = setup_info_shortcuts_1;
7806 title_string = STR_SETUP_SHORTCUTS;
7808 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7810 setup_info = setup_info_shortcuts_2;
7811 title_string = STR_SETUP_SHORTCUTS;
7813 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7815 setup_info = setup_info_shortcuts_3;
7816 title_string = STR_SETUP_SHORTCUTS;
7818 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7820 setup_info = setup_info_shortcuts_4;
7821 title_string = STR_SETUP_SHORTCUTS;
7823 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7825 setup_info = setup_info_shortcuts_5;
7826 title_string = STR_SETUP_SHORTCUTS;
7829 // use modified setup info without setup entries marked as hidden
7830 setup_info = getSetupInfoFinal(setup_info);
7832 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7834 // determine maximal number of setup entries that can be displayed on screen
7836 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7839 // determine maximal number of setup entries available for this setup screen
7841 for (i = 0; setup_info[i].type != 0; i++)
7844 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7846 MapScreenGadgets(max_setup_info);
7849 redraw_mask = fade_mask = REDRAW_ALL;
7851 DrawMaskedBorder(fade_mask);
7856 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7858 menu_info = setup_info;
7860 HandleMenuScreen(mx, my, dx, dy, button,
7861 setup_mode, num_setup_info, max_setup_info);
7864 static void DrawSetupScreen_Input(void)
7868 FadeOut(REDRAW_FIELD);
7872 setup_info = getSetupInfoFinal(setup_info_input);
7874 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7876 for (i = 0; setup_info[i].type != 0; i++)
7878 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7879 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7880 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7881 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7882 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7883 initCursor(i, IMG_MENU_BUTTON);
7885 DrawCursorAndText_Setup(i, -1, FALSE);
7888 // create gadgets for setup input menu screen
7889 FreeScreenGadgets();
7890 CreateScreenGadgets();
7892 // map gadgets for setup input menu screen
7893 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7895 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7897 FadeIn(REDRAW_FIELD);
7900 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7902 if (device_name == NULL)
7905 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7908 if (strlen(device_name) > 1)
7910 char c1 = device_name[strlen(device_name) - 1];
7911 char c2 = device_name[strlen(device_name) - 2];
7913 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7914 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7917 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7918 strlen(device_name));
7921 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7924 static struct SetupKeyboardInfo custom_key;
7931 { &custom_key.left, "Axis/Pad Left" },
7932 { &custom_key.right, "Axis/Pad Right" },
7933 { &custom_key.up, "Axis/Pad Up" },
7934 { &custom_key.down, "Axis/Pad Down" },
7935 { &custom_key.snap, "Button 1/A/X" },
7936 { &custom_key.drop, "Button 2/B/Y" }
7938 static char *joystick_name[MAX_PLAYERS] =
7945 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7946 int font_nr_info = FONT_MENU_1;
7947 int font_nr_name = FONT_VALUE_OLD;
7948 int font_nr_on = FONT_VALUE_1;
7949 int font_nr_off = FONT_VALUE_OLD;
7952 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7954 font_nr_info = FONT_MENU_2;
7955 font_nr_on = FONT_VALUE_NARROW;
7956 font_nr_off = FONT_VALUE_OLD_NARROW;
7959 custom_key = setup.input[player_nr].key;
7961 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7962 FONT_INPUT_1_ACTIVE);
7964 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7966 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7967 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7969 if (setup.input[player_nr].use_joystick)
7971 char *device_name = setup.input[player_nr].joy.device_name;
7972 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7973 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7974 char *text = joystick_name[joystick_nr];
7975 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7977 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7978 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7982 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7983 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7986 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7987 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7991 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7992 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7993 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7994 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7996 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7997 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7998 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7999 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8000 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8001 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8003 for (i = 0; i < 6; i++)
8005 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8007 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8009 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8010 (setup.input[player_nr].use_joystick ?
8012 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8016 static int input_player_nr = 0;
8018 static void HandleSetupScreen_Input_Player(int step, int direction)
8020 int old_player_nr = input_player_nr;
8023 new_player_nr = old_player_nr + step * direction;
8024 if (new_player_nr < 0)
8026 if (new_player_nr > MAX_PLAYERS - 1)
8027 new_player_nr = MAX_PLAYERS - 1;
8029 if (new_player_nr != old_player_nr)
8031 input_player_nr = new_player_nr;
8033 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8037 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8039 static int choice = 0;
8042 int pos_start = SETUPINPUT_SCREEN_POS_START;
8043 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8044 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8045 int pos_end = SETUPINPUT_SCREEN_POS_END;
8047 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8051 for (i = 0; setup_info_input[i].type != 0; i++)
8053 // adjust menu structure according to skipped setup entries
8054 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8062 if (button == MB_MENU_INITIALIZE)
8064 // input setup menu may have changed size due to graphics configuration
8065 if (choice >= pos_empty1)
8068 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8070 DrawCursorAndText_Setup(choice, -1, TRUE);
8074 else if (button == MB_MENU_LEAVE)
8076 setup_mode = SETUP_MODE_MAIN;
8083 if (mx || my) // mouse input
8085 x = (mx - mSX) / 32;
8086 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8088 else if (dx || dy) // keyboard input
8090 if (dx && choice == 0)
8091 x = (dx < 0 ? 10 : 12);
8092 else if ((dx && choice == 1) ||
8093 (dx == -1 && choice == pos_end))
8094 button = MB_MENU_CHOICE;
8098 if (y >= pos_empty1 && y <= pos_empty2)
8099 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8102 if (y == 0 && dx != 0 && button)
8104 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8106 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8107 y >= pos_start && y <= pos_end &&
8108 !(y >= pos_empty1 && y <= pos_empty2))
8114 DrawCursorAndText_Setup(choice, -1, FALSE);
8115 DrawCursorAndText_Setup(y, -1, TRUE);
8117 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8126 char *device_name = setup.input[input_player_nr].joy.device_name;
8128 if (!setup.input[input_player_nr].use_joystick)
8130 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8132 setJoystickDeviceToNr(device_name, new_device_nr);
8133 setup.input[input_player_nr].use_joystick = TRUE;
8137 int device_nr = getJoystickNrFromDeviceName(device_name);
8138 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8140 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8141 setup.input[input_player_nr].use_joystick = FALSE;
8143 setJoystickDeviceToNr(device_name, new_device_nr);
8146 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8150 if (setup.input[input_player_nr].use_joystick)
8151 ConfigureJoystick(input_player_nr);
8153 CustomizeKeyboard(input_player_nr);
8155 else if (y == pos_end)
8161 setup_mode = SETUP_MODE_MAIN;
8168 static boolean CustomizeKeyboardMain(int player_nr)
8172 boolean finished = FALSE;
8173 static struct SetupKeyboardInfo custom_key;
8178 } customize_step[] =
8180 { &custom_key.left, "Move Left" },
8181 { &custom_key.right, "Move Right" },
8182 { &custom_key.up, "Move Up" },
8183 { &custom_key.down, "Move Down" },
8184 { &custom_key.snap, "Snap Field" },
8185 { &custom_key.drop, "Drop Element" }
8187 int font_nr_old = FONT_VALUE_OLD;
8188 int font_nr_new = FONT_VALUE_1;
8189 boolean success = FALSE;
8191 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8193 font_nr_old = FONT_VALUE_OLD_NARROW;
8194 font_nr_new = FONT_VALUE_NARROW;
8197 // read existing key bindings from player setup
8198 custom_key = setup.input[player_nr].key;
8201 FadeOut(REDRAW_FIELD);
8205 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8208 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8209 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8210 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8211 "Key:", FONT_INPUT_1_ACTIVE);
8212 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8213 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8215 FadeIn(REDRAW_FIELD);
8221 if (NextValidEvent(&event))
8225 case EVENT_KEYPRESS:
8227 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8229 // press 'Escape' to abort and keep the old key bindings
8230 if (key == KSYM_Escape)
8232 FadeSkipNextFadeIn();
8239 // press 'Enter' to keep the existing key binding
8240 if (key == KSYM_Return)
8241 key = *customize_step[step_nr].key;
8243 // check if key already used
8244 for (i = 0; i < step_nr; i++)
8245 if (*customize_step[i].key == key)
8250 // got new key binding
8251 *customize_step[step_nr].key = key;
8252 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8254 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8255 getKeyNameFromKey(key), font_nr_new);
8258 // un-highlight last query
8259 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8260 customize_step[step_nr - 1].text, FONT_MENU_1);
8261 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8262 "Key:", FONT_MENU_1);
8264 // all keys configured
8273 // query next key binding
8274 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8275 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8276 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8277 "Key:", FONT_INPUT_1_ACTIVE);
8278 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8279 getKeyNameFromKey(*customize_step[step_nr].key),
8284 case EVENT_KEYRELEASE:
8285 key_joystick_mapping = 0;
8289 HandleOtherEvents(&event);
8297 // write new key bindings back to player setup, if successfully finished
8299 setup.input[player_nr].key = custom_key;
8304 void CustomizeKeyboard(int player_nr)
8306 boolean success = CustomizeKeyboardMain(player_nr);
8310 int font_nr = FONT_TITLE_1;
8311 int font_height = getFontHeight(font_nr);
8312 int ypos1 = SYSIZE / 2 - font_height * 2;
8313 int ypos2 = SYSIZE / 2 - font_height * 1;
8314 unsigned int wait_frame_delay = 0;
8315 unsigned int wait_frame_delay_value = 2000;
8317 ResetDelayCounter(&wait_frame_delay);
8321 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8322 DrawTextSCentered(ypos2, font_nr, "configured!");
8324 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8330 DrawSetupScreen_Input();
8333 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8335 #define MARKER_BUTTON 1
8336 #define MARKER_AXIS_X 2
8337 #define MARKER_AXIS_Y 3
8339 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8341 static boolean bitmaps_initialized = FALSE;
8342 boolean screen_initialized = FALSE;
8343 static Bitmap *controller, *button, *axis_x, *axis_y;
8345 boolean success = TRUE;
8346 boolean done = FALSE, next = FALSE;
8348 int alpha = 200, alpha_step = -1;
8349 int alpha_ticks = 0;
8350 char mapping[4096], temp[256];
8351 int font_name = MENU_SETUP_FONT_TITLE;
8352 int font_info = MENU_SETUP_FONT_TEXT;
8353 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8354 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8355 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8356 int ystep_name = getMenuTextStep(spacing_name, font_name);
8357 int ystep_line = getMenuTextStep(spacing_line, font_info);
8358 int ystep_para = getMenuTextStep(spacing_para, font_info);
8366 int axis, button, hat, hat_value;
8369 *step, *prev_step, steps[] =
8371 { 356, 155, MARKER_BUTTON, "a", },
8372 { 396, 122, MARKER_BUTTON, "b", },
8373 { 320, 125, MARKER_BUTTON, "x", },
8374 { 358, 95, MARKER_BUTTON, "y", },
8375 { 162, 125, MARKER_BUTTON, "back", },
8376 { 216, 125, MARKER_BUTTON, "guide", },
8377 { 271, 125, MARKER_BUTTON, "start", },
8378 { 110, 200, MARKER_BUTTON, "dpleft", },
8379 { 146, 228, MARKER_BUTTON, "dpdown", },
8380 { 178, 200, MARKER_BUTTON, "dpright", },
8381 { 146, 172, MARKER_BUTTON, "dpup", },
8382 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8383 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8384 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8385 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8386 { 73, 141, MARKER_BUTTON, "leftstick", },
8387 { 282, 210, MARKER_BUTTON, "rightstick", },
8388 { 73, 141, MARKER_AXIS_X, "leftx", },
8389 { 73, 141, MARKER_AXIS_Y, "lefty", },
8390 { 282, 210, MARKER_AXIS_X, "rightx", },
8391 { 282, 210, MARKER_AXIS_Y, "righty", },
8394 unsigned int event_frame_delay = 0;
8395 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8397 ResetDelayCounter(&event_frame_delay);
8399 if (!bitmaps_initialized)
8401 controller = LoadCustomImage("joystick/controller.png");
8402 button = LoadCustomImage("joystick/button.png");
8403 axis_x = LoadCustomImage("joystick/axis_x.png");
8404 axis_y = LoadCustomImage("joystick/axis_y.png");
8406 bitmaps_initialized = TRUE;
8409 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8412 // print info about the joystick we are watching
8413 Debug("joystick", "watching joystick %d: (%s)",
8414 SDL_JoystickInstanceID(joystick), name);
8415 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8416 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8417 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8420 // initialize mapping with GUID and name
8421 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8423 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8424 temp, name, SDL_GetPlatform());
8426 // loop through all steps (buttons and axes), getting joystick events
8427 for (i = 0; i < SDL_arraysize(steps) && !done;)
8429 Bitmap *marker = button; // initialize with reliable default value
8432 strcpy(step->mapping, mapping);
8436 step->hat_value = -1;
8438 marker = (step->marker == MARKER_BUTTON ? button :
8439 step->marker == MARKER_AXIS_X ? axis_x :
8440 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8444 while (!done && !next)
8446 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8447 alpha_ticks = SDL_GetTicks();
8454 else if (alpha < 128)
8460 int controller_x = SX + (SXSIZE - controller->width) / 2;
8461 int controller_y = SY + ystep_line;
8463 int marker_x = controller_x + step->x;
8464 int marker_y = controller_y + step->y;
8466 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8467 int ystart2 = ystart1 + ystep_name + ystep_line;
8471 DrawTextSCentered(ystart1, font_name, name);
8473 DrawTextSCentered(ystart2, font_info,
8474 "Press buttons and move axes on");
8475 ystart2 += ystep_line;
8476 DrawTextSCentered(ystart2, font_info,
8477 "your controller when indicated.");
8478 ystart2 += ystep_line;
8479 DrawTextSCentered(ystart2, font_info,
8480 "(Your controller may look different.)");
8481 ystart2 += ystep_para;
8483 #if defined(PLATFORM_ANDROID)
8484 DrawTextSCentered(ystart2, font_info,
8485 "To correct a mistake,");
8486 ystart2 += ystep_line;
8487 DrawTextSCentered(ystart2, font_info,
8488 "press the 'back' button.");
8489 ystart2 += ystep_line;
8490 DrawTextSCentered(ystart2, font_info,
8491 "To skip a button or axis,");
8492 ystart2 += ystep_line;
8493 DrawTextSCentered(ystart2, font_info,
8494 "press the 'menu' button.");
8496 DrawTextSCentered(ystart2, font_info,
8497 "To correct a mistake,");
8498 ystart2 += ystep_line;
8499 DrawTextSCentered(ystart2, font_info,
8500 "press the 'backspace' key.");
8501 ystart2 += ystep_line;
8502 DrawTextSCentered(ystart2, font_info,
8503 "To skip a button or axis,");
8504 ystart2 += ystep_line;
8505 DrawTextSCentered(ystart2, font_info,
8506 "press the 'return' key.");
8507 ystart2 += ystep_line;
8508 DrawTextSCentered(ystart2, font_info,
8509 "To exit, press the 'escape' key.");
8512 BlitBitmapMasked(controller, drawto, 0, 0,
8513 controller->width, controller->height,
8514 controller_x, controller_y);
8516 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8517 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8519 BlitBitmapMasked(marker, drawto, 0, 0,
8520 marker->width, marker->height,
8521 marker_x, marker_y);
8523 if (!screen_initialized)
8524 FadeIn(REDRAW_FIELD);
8528 screen_initialized = TRUE;
8530 while (NextValidEvent(&event))
8534 case SDL_JOYAXISMOTION:
8535 if (event.jaxis.value > 20000 ||
8536 event.jaxis.value < -20000)
8538 for (j = 0; j < i; j++)
8539 if (steps[j].axis == event.jaxis.axis)
8544 if (step->marker != MARKER_AXIS_X &&
8545 step->marker != MARKER_AXIS_Y)
8548 step->axis = event.jaxis.axis;
8549 strcat(mapping, step->field);
8550 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8551 strcat(mapping, temp);
8559 case SDL_JOYHATMOTION:
8560 // ignore centering; we're probably just coming back
8561 // to the center from the previous item we set
8562 if (event.jhat.value == SDL_HAT_CENTERED)
8565 for (j = 0; j < i; j++)
8566 if (steps[j].hat == event.jhat.hat &&
8567 steps[j].hat_value == event.jhat.value)
8572 step->hat = event.jhat.hat;
8573 step->hat_value = event.jhat.value;
8574 strcat(mapping, step->field);
8575 snprintf(temp, sizeof(temp), ":h%u.%u,",
8576 event.jhat.hat, event.jhat.value );
8577 strcat(mapping, temp);
8584 case SDL_JOYBALLMOTION:
8587 case SDL_JOYBUTTONUP:
8588 for (j = 0; j < i; j++)
8589 if (steps[j].button == event.jbutton.button)
8594 step->button = event.jbutton.button;
8595 strcat(mapping, step->field);
8596 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8597 strcat(mapping, temp);
8604 case SDL_FINGERDOWN:
8605 case SDL_MOUSEBUTTONDOWN:
8613 if (event.key.keysym.sym == KSYM_BackSpace ||
8614 event.key.keysym.sym == KSYM_Back)
8626 prev_step = &steps[i - 1];
8627 strcpy(mapping, prev_step->mapping);
8634 if (event.key.keysym.sym == KSYM_space ||
8635 event.key.keysym.sym == KSYM_Return ||
8636 event.key.keysym.sym == KSYM_Menu)
8645 if (event.key.keysym.sym == KSYM_Escape)
8655 program.exit_function(0);
8662 // do not handle events for longer than standard frame delay period
8663 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8672 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8675 // activate mapping for this game
8676 SDL_GameControllerAddMapping(mapping);
8678 // save mapping to personal mappings
8679 SaveSetup_AddGameControllerMapping(mapping);
8682 // wait until the last pending event was removed from event queue
8683 while (NextValidEvent(&event));
8688 static int ConfigureJoystickMain(int player_nr)
8690 char *device_name = setup.input[player_nr].joy.device_name;
8691 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8692 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8693 int success = FALSE;
8696 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8697 return JOYSTICK_NOT_AVAILABLE;
8699 if (!joystick_active || !setup.input[player_nr].use_joystick)
8700 return JOYSTICK_NOT_AVAILABLE;
8703 FadeOut(REDRAW_FIELD);
8705 // close all joystick devices (potentially opened as game controllers)
8706 for (i = 0; i < SDL_NumJoysticks(); i++)
8707 SDLCloseJoystick(i);
8709 // open joystick device as plain joystick to configure as game controller
8710 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8712 // as the joystick was successfully opened before, this should not happen
8713 if (joystick == NULL)
8716 // create new game controller mapping (buttons and axes) for joystick device
8717 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8719 // close joystick (and maybe re-open as configured game controller later)
8720 SDL_JoystickClose(joystick);
8722 // re-open all joystick devices (potentially as game controllers)
8723 for (i = 0; i < SDL_NumJoysticks(); i++)
8726 // clear all joystick input actions for all joystick devices
8727 SDLClearJoystickState();
8729 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8732 void ConfigureJoystick(int player_nr)
8734 boolean state = ConfigureJoystickMain(player_nr);
8736 if (state != JOYSTICK_NOT_CONFIGURED)
8738 boolean success = (state == JOYSTICK_CONFIGURED);
8739 char message1[MAX_OUTPUT_LINESIZE + 1];
8740 char *message2 = (success ? "configured!" : "not available!");
8741 char *device_name = setup.input[player_nr].joy.device_name;
8742 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8743 int font_nr = FONT_TITLE_1;
8744 int font_height = getFontHeight(font_nr);
8745 int ypos1 = SYSIZE / 2 - font_height * 2;
8746 int ypos2 = SYSIZE / 2 - font_height * 1;
8747 unsigned int wait_frame_delay = 0;
8748 unsigned int wait_frame_delay_value = 2000;
8750 ResetDelayCounter(&wait_frame_delay);
8754 sprintf(message1, "Joystick %d", nr);
8756 DrawTextSCentered(ypos1, font_nr, message1);
8757 DrawTextSCentered(ypos2, font_nr, message2);
8759 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8765 DrawSetupScreen_Input();
8768 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8770 if (y < video.screen_height / 3)
8772 // remap touch gadgets to access upper part of the screen
8773 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8774 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8776 else if (y > 2 * video.screen_height / 3)
8778 // remap touch gadgets to access lower part of the screen
8779 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8780 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8784 static boolean ConfigureVirtualButtonsMain(void)
8786 static char *customize_step_text[] =
8795 char grid_button[] =
8797 CHAR_GRID_BUTTON_LEFT,
8798 CHAR_GRID_BUTTON_RIGHT,
8799 CHAR_GRID_BUTTON_UP,
8800 CHAR_GRID_BUTTON_DOWN,
8801 CHAR_GRID_BUTTON_SNAP,
8802 CHAR_GRID_BUTTON_DROP
8811 int font_nr = FONT_INPUT_1_ACTIVE;
8812 int font_height = getFontHeight(font_nr);
8813 int ypos1 = SYSIZE / 2 - font_height * 2;
8814 int ypos2 = SYSIZE / 2 - font_height * 1;
8815 boolean success = FALSE;
8816 boolean finished = FALSE;
8818 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8819 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8820 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8821 boolean set_grid_button = FALSE;
8822 int nr = GRID_ACTIVE_NR();
8825 for (x = 0; x < MAX_GRID_XSIZE; x++)
8826 for (y = 0; y < MAX_GRID_YSIZE; y++)
8827 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8829 overlay.grid_button_highlight = grid_button[step_nr];
8834 FadeOut(REDRAW_FIELD);
8838 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8839 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8840 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8842 FadeIn(REDRAW_FIELD);
8844 SetOverlayShowGrid(TRUE);
8846 // map gadgets for setup touch buttons menu screen
8847 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8853 while (NextValidEvent(&event))
8855 int action = ACTION_NONE;
8857 // ---------- handle events and set the resulting action ----------
8863 UserEvent *user = (UserEvent *)&event;
8864 int id = user->value1;
8866 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8867 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8868 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8869 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8874 case EVENT_KEYPRESS:
8876 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8878 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8879 key == KSYM_BackSpace ||
8880 key == KSYM_Back ? ACTION_BACK :
8881 key == KSYM_Return ||
8883 key == KSYM_space ? ACTION_NEXT :
8888 case EVENT_KEYRELEASE:
8889 key_joystick_mapping = 0;
8892 case EVENT_BUTTONPRESS:
8893 case EVENT_BUTTONRELEASE:
8895 ButtonEvent *button = (ButtonEvent *)&event;
8897 motion_status = FALSE;
8899 if (button->type == EVENT_BUTTONPRESS)
8900 button_status = button->button;
8902 button_status = MB_RELEASED;
8904 if (HandleGadgets(button->x, button->y, button_status))
8906 // do not handle this button event anymore
8910 button->x += video.screen_xoffset;
8911 button->y += video.screen_yoffset;
8913 x = button->x * overlay.grid_xsize / video.screen_width;
8914 y = button->y * overlay.grid_ysize / video.screen_height;
8916 if (button->type == EVENT_BUTTONPRESS)
8919 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8920 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8922 set_grid_button = TRUE;
8925 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8929 case EVENT_MOTIONNOTIFY:
8931 MotionEvent *motion = (MotionEvent *)&event;
8933 motion_status = TRUE;
8935 if (HandleGadgets(motion->x, motion->y, button_status))
8937 // do not handle this button event anymore
8941 motion->x += video.screen_xoffset;
8942 motion->y += video.screen_yoffset;
8944 x = motion->x * overlay.grid_xsize / video.screen_width;
8945 y = motion->y * overlay.grid_ysize / video.screen_height;
8947 set_grid_button = TRUE;
8949 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8953 case SDL_WINDOWEVENT:
8954 HandleWindowEvent((WindowEvent *) &event);
8956 // check if device has been rotated
8957 if (nr != GRID_ACTIVE_NR())
8959 nr = GRID_ACTIVE_NR();
8961 for (x = 0; x < MAX_GRID_XSIZE; x++)
8962 for (y = 0; y < MAX_GRID_YSIZE; y++)
8963 grid_button_old[x][y] = grid_button_tmp[x][y] =
8964 overlay.grid_button[x][y];
8969 case SDL_APP_WILLENTERBACKGROUND:
8970 case SDL_APP_DIDENTERBACKGROUND:
8971 case SDL_APP_WILLENTERFOREGROUND:
8972 case SDL_APP_DIDENTERFOREGROUND:
8973 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8977 HandleOtherEvents(&event);
8981 // ---------- perform action set by handling events ----------
8983 if (action == ACTION_ESCAPE)
8985 // abort and restore the old key bindings
8987 for (x = 0; x < MAX_GRID_XSIZE; x++)
8988 for (y = 0; y < MAX_GRID_YSIZE; y++)
8989 overlay.grid_button[x][y] = grid_button_old[x][y];
8991 FadeSkipNextFadeIn();
8995 else if (action == ACTION_BACK)
8997 // keep the configured key bindings and go to previous page
9003 FadeSkipNextFadeIn();
9008 else if (action == ACTION_NEXT)
9010 // keep the configured key bindings and go to next page
9014 // all virtual buttons configured
9022 if (action != ACTION_NONE && !finished)
9024 for (x = 0; x < MAX_GRID_XSIZE; x++)
9025 for (y = 0; y < MAX_GRID_YSIZE; y++)
9026 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9028 overlay.grid_button_highlight = grid_button[step_nr];
9030 // configure next virtual button
9034 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9035 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9036 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9039 if (set_grid_button)
9041 overlay.grid_button[x][y] =
9042 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9043 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9044 grid_button_tmp[x][y]);
9046 set_grid_button = FALSE;
9053 for (x = 0; x < MAX_GRID_XSIZE; x++)
9054 for (y = 0; y < MAX_GRID_YSIZE; y++)
9055 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9057 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9059 SetOverlayShowGrid(FALSE);
9064 void ConfigureVirtualButtons(void)
9066 boolean success = ConfigureVirtualButtonsMain();
9068 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9069 SCREEN_MASK_TOUCH2);
9073 int font_nr = FONT_TITLE_1;
9074 int font_height = getFontHeight(font_nr);
9075 int ypos1 = SYSIZE / 2 - font_height * 2;
9076 int ypos2 = SYSIZE / 2 - font_height * 1;
9077 unsigned int wait_frame_delay = 0;
9078 unsigned int wait_frame_delay_value = 2000;
9080 ResetDelayCounter(&wait_frame_delay);
9084 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9085 DrawTextSCentered(ypos2, font_nr, "configured!");
9087 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9094 void DrawSetupScreen(void)
9099 if (setup_mode == SETUP_MODE_INPUT)
9100 DrawSetupScreen_Input();
9101 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9102 DrawChooseTree(&scores_type_current);
9103 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9104 DrawChooseTree(&game_speed_current);
9105 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9106 DrawChooseTree(&scroll_delay_current);
9107 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9108 DrawChooseTree(&snapshot_mode_current);
9109 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9110 DrawChooseTree(&window_size_current);
9111 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9112 DrawChooseTree(&scaling_type_current);
9113 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9114 DrawChooseTree(&rendering_mode_current);
9115 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9116 DrawChooseTree(&vsync_mode_current);
9117 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9118 DrawChooseTree(&artwork.gfx_current);
9119 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9120 DrawChooseTree(&artwork.snd_current);
9121 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9122 DrawChooseTree(&artwork.mus_current);
9123 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9124 DrawChooseTree(&volume_simple_current);
9125 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9126 DrawChooseTree(&volume_loops_current);
9127 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9128 DrawChooseTree(&volume_music_current);
9129 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9130 DrawChooseTree(&touch_control_current);
9131 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9132 DrawChooseTree(&move_distance_current);
9133 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9134 DrawChooseTree(&drop_distance_current);
9135 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9136 DrawChooseTree(&transparency_current);
9137 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9138 DrawChooseTree(&grid_size_current[0][0]);
9139 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9140 DrawChooseTree(&grid_size_current[0][1]);
9141 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9142 DrawChooseTree(&grid_size_current[1][0]);
9143 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9144 DrawChooseTree(&grid_size_current[1][1]);
9146 DrawSetupScreen_Generic();
9148 PlayMenuSoundsAndMusic();
9151 void RedrawSetupScreenAfterFullscreenToggle(void)
9153 if (setup_mode == SETUP_MODE_GRAPHICS ||
9154 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9156 // update list selection from "setup.window_scaling_percent"
9157 execSetupGraphics_setWindowSizes(TRUE);
9163 void RedrawSetupScreenAfterScreenRotation(int nr)
9167 if (setup_mode == SETUP_MODE_TOUCH)
9169 // update virtual button settings (depending on screen orientation)
9172 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9174 // save already configured virtual buttons
9175 for (x = 0; x < MAX_GRID_XSIZE; x++)
9176 for (y = 0; y < MAX_GRID_YSIZE; y++)
9177 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9181 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9183 if (setup_mode == SETUP_MODE_INPUT)
9184 HandleSetupScreen_Input(mx, my, dx, dy, button);
9185 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9186 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9187 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9188 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9189 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9190 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9191 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9192 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9193 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9194 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9195 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9196 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9197 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9198 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9199 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9200 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9201 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9202 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9203 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9204 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9205 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9206 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9207 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9208 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9209 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9210 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9211 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9212 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9213 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9214 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9215 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9216 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9217 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9218 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9219 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9220 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9221 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9222 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9223 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9224 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9225 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9226 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9227 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9228 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9230 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9233 void HandleGameActions(void)
9235 if (setup.ask_on_game_over)
9238 if (game.restart_game_message != NULL)
9240 RequestRestartGame(game.restart_game_message);
9245 if (game_status != GAME_MODE_PLAYING)
9248 GameActions(); // main game loop
9250 if (tape.auto_play && !tape.playing)
9251 AutoPlayTapesContinue(); // continue automatically playing next tape
9255 // ---------- new screen button stuff --------------------------------------
9259 int gfx_unpressed, gfx_pressed;
9260 struct MenuPosInfo *pos;
9261 boolean *check_value;
9264 unsigned int event_mask;
9265 boolean is_touch_button;
9267 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9270 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9271 &menu.main.button.prev_level, NULL,
9272 SCREEN_CTRL_ID_PREV_LEVEL,
9274 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9275 FALSE, "previous level"
9278 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9279 &menu.main.button.next_level, NULL,
9280 SCREEN_CTRL_ID_NEXT_LEVEL,
9282 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9286 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9287 &menu.main.button.first_level, NULL,
9288 SCREEN_CTRL_ID_FIRST_LEVEL,
9291 FALSE, "first level"
9294 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9295 &menu.main.button.last_level, NULL,
9296 SCREEN_CTRL_ID_LAST_LEVEL,
9302 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9303 &menu.main.button.level_number, NULL,
9304 SCREEN_CTRL_ID_LEVEL_NUMBER,
9307 FALSE, "level number"
9310 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9311 &menu.setup.button.prev_player, NULL,
9312 SCREEN_CTRL_ID_PREV_PLAYER,
9314 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9315 FALSE, "previous player"
9318 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9319 &menu.setup.button.next_player, NULL,
9320 SCREEN_CTRL_ID_NEXT_PLAYER,
9322 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9323 FALSE, "next player"
9326 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9327 &menu.main.button.insert_solution, NULL,
9328 SCREEN_CTRL_ID_INSERT_SOLUTION,
9329 SCREEN_MASK_MAIN_HAS_SOLUTION,
9331 FALSE, "insert solution tape"
9334 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9335 &menu.main.button.play_solution, NULL,
9336 SCREEN_CTRL_ID_PLAY_SOLUTION,
9337 SCREEN_MASK_MAIN_HAS_SOLUTION,
9339 FALSE, "play solution tape"
9342 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9343 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9344 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9346 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9347 FALSE, "switch ECS/AGA chipset"
9350 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9351 &menu.setup.button.touch_back, NULL,
9352 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9355 TRUE, "previous page"
9358 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9359 &menu.setup.button.touch_next, NULL,
9360 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9366 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9367 &menu.setup.button.touch_back2, NULL,
9368 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9371 TRUE, "previous page"
9374 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9375 &menu.setup.button.touch_next2, NULL,
9376 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9385 int gfx_unpressed, gfx_pressed;
9389 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9392 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9393 -1, -1, // these values are not constant, but can change at runtime
9394 SCREEN_CTRL_ID_SCROLL_UP,
9398 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9399 -1, -1, // these values are not constant, but can change at runtime
9400 SCREEN_CTRL_ID_SCROLL_DOWN,
9407 int gfx_unpressed, gfx_pressed;
9413 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9416 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9417 -1, -1, // these values are not constant, but can change at runtime
9418 -1, -1, // these values are not constant, but can change at runtime
9419 GD_TYPE_SCROLLBAR_VERTICAL,
9420 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9421 "scroll level series vertically"
9433 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9436 IMG_SETUP_INPUT_TEXT,
9437 SCREEN_CTRL_ID_NETWORK_SERVER,
9438 -1, -1, // these values are not constant, but can change at runtime
9439 MAX_SETUP_TEXT_INPUT_LEN,
9440 network_server_hostname,
9441 "Network Server Hostname / IP"
9445 static void CreateScreenMenubuttons(void)
9447 struct GadgetInfo *gi;
9448 unsigned int event_mask;
9451 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9453 struct MenuPosInfo *pos = menubutton_info[i].pos;
9454 boolean is_touch_button = menubutton_info[i].is_touch_button;
9455 boolean is_check_button = menubutton_info[i].check_value != NULL;
9456 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9457 int gfx_unpressed, gfx_pressed;
9458 int x, y, width, height;
9459 int gd_x1, gd_x2, gd_y1, gd_y2;
9460 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9461 int id = menubutton_info[i].gadget_id;
9462 int type = GD_TYPE_NORMAL_BUTTON;
9463 boolean checked = FALSE;
9465 event_mask = menubutton_info[i].event_mask;
9467 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9468 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9470 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9471 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9473 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9474 gfx_pressed = menubutton_info[i].gfx_pressed;
9475 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9476 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9477 gd_x1 = graphic_info[gfx_unpressed].src_x;
9478 gd_y1 = graphic_info[gfx_unpressed].src_y;
9479 gd_x2 = graphic_info[gfx_pressed].src_x;
9480 gd_y2 = graphic_info[gfx_pressed].src_y;
9486 if (is_touch_button)
9488 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9489 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9492 if (is_check_button)
9494 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9495 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9496 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9497 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9499 type = GD_TYPE_CHECK_BUTTON;
9500 checked = *menubutton_info[i].check_value;
9503 gi = CreateGadget(GDI_CUSTOM_ID, id,
9504 GDI_CUSTOM_TYPE_ID, i,
9505 GDI_IMAGE_ID, gfx_unpressed,
9506 GDI_INFO_TEXT, menubutton_info[i].infotext,
9512 GDI_STATE, GD_BUTTON_UNPRESSED,
9513 GDI_CHECKED, checked,
9514 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9515 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9516 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9517 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9518 GDI_DIRECT_DRAW, FALSE,
9519 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9520 GDI_EVENT_MASK, event_mask,
9521 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9525 Fail("cannot create gadget");
9527 screen_gadget[id] = gi;
9531 static void CreateScreenScrollbuttons(void)
9533 struct GadgetInfo *gi;
9534 unsigned int event_mask;
9537 // these values are not constant, but can change at runtime
9538 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9539 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9540 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9541 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9543 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9545 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9546 int gfx_unpressed, gfx_pressed;
9547 int x, y, width, height;
9548 int gd_x1, gd_x2, gd_y1, gd_y2;
9549 int id = scrollbutton_info[i].gadget_id;
9551 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9553 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9554 y = mSY + scrollbutton_info[i].y;
9555 width = SC_SCROLLBUTTON_XSIZE;
9556 height = SC_SCROLLBUTTON_YSIZE;
9558 // correct scrollbar position if placed outside menu (playfield) area
9559 if (x > SX + SC_SCROLL_UP_XPOS)
9560 x = SX + SC_SCROLL_UP_XPOS;
9562 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9563 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9564 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9566 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9567 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9568 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9569 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9570 gd_x1 = graphic_info[gfx_unpressed].src_x;
9571 gd_y1 = graphic_info[gfx_unpressed].src_y;
9572 gd_x2 = graphic_info[gfx_pressed].src_x;
9573 gd_y2 = graphic_info[gfx_pressed].src_y;
9575 gi = CreateGadget(GDI_CUSTOM_ID, id,
9576 GDI_CUSTOM_TYPE_ID, i,
9577 GDI_IMAGE_ID, gfx_unpressed,
9578 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9583 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9584 GDI_STATE, GD_BUTTON_UNPRESSED,
9585 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9586 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9587 GDI_DIRECT_DRAW, FALSE,
9588 GDI_EVENT_MASK, event_mask,
9589 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9593 Fail("cannot create gadget");
9595 screen_gadget[id] = gi;
9599 static void CreateScreenScrollbars(void)
9603 // these values are not constant, but can change at runtime
9604 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9605 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9606 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9607 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9609 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9611 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9612 int gfx_unpressed, gfx_pressed;
9613 int x, y, width, height;
9614 int gd_x1, gd_x2, gd_y1, gd_y2;
9615 struct GadgetInfo *gi;
9616 int items_max, items_visible, item_position;
9617 unsigned int event_mask;
9618 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9619 int id = scrollbar_info[i].gadget_id;
9621 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9623 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9624 y = mSY + scrollbar_info[i].y;
9625 width = scrollbar_info[i].width;
9626 height = scrollbar_info[i].height;
9628 // correct scrollbar position if placed outside menu (playfield) area
9629 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9630 x = SX + SC_SCROLL_VERTICAL_XPOS;
9632 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9633 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9635 items_max = num_page_entries;
9636 items_visible = num_page_entries;
9639 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9640 gfx_pressed = scrollbar_info[i].gfx_pressed;
9641 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9642 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9643 gd_x1 = graphic_info[gfx_unpressed].src_x;
9644 gd_y1 = graphic_info[gfx_unpressed].src_y;
9645 gd_x2 = graphic_info[gfx_pressed].src_x;
9646 gd_y2 = graphic_info[gfx_pressed].src_y;
9648 gi = CreateGadget(GDI_CUSTOM_ID, id,
9649 GDI_CUSTOM_TYPE_ID, i,
9650 GDI_IMAGE_ID, gfx_unpressed,
9651 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9656 GDI_TYPE, scrollbar_info[i].type,
9657 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9658 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9659 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9660 GDI_WHEEL_AREA_X, SX,
9661 GDI_WHEEL_AREA_Y, SY,
9662 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9663 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9664 GDI_STATE, GD_BUTTON_UNPRESSED,
9665 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9666 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9667 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9668 GDI_DIRECT_DRAW, FALSE,
9669 GDI_EVENT_MASK, event_mask,
9670 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9674 Fail("cannot create gadget");
9676 screen_gadget[id] = gi;
9680 static void CreateScreenTextInputGadgets(void)
9684 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9686 int graphic = textinput_info[i].graphic;
9687 struct GraphicInfo *gd = &graphic_info[graphic];
9688 int gd_x1 = gd->src_x;
9689 int gd_y1 = gd->src_y;
9690 int gd_x2 = gd->src_x + gd->active_xoffset;
9691 int gd_y2 = gd->src_y + gd->active_yoffset;
9692 struct GadgetInfo *gi;
9693 unsigned int event_mask;
9694 int id = textinput_info[i].gadget_id;
9695 int x = textinput_info[i].x;
9696 int y = textinput_info[i].y;
9698 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9700 gi = CreateGadget(GDI_CUSTOM_ID, id,
9701 GDI_CUSTOM_TYPE_ID, i,
9702 GDI_INFO_TEXT, textinput_info[i].infotext,
9705 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9706 GDI_TEXT_VALUE, textinput_info[i].value,
9707 GDI_TEXT_SIZE, textinput_info[i].size,
9708 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9709 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9710 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9711 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9712 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9713 GDI_DESIGN_WIDTH, gd->width,
9714 GDI_EVENT_MASK, event_mask,
9715 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9716 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9720 Fail("cannot create gadget");
9722 screen_gadget[id] = gi;
9726 void CreateScreenGadgets(void)
9728 CreateScreenMenubuttons();
9730 CreateScreenScrollbuttons();
9731 CreateScreenScrollbars();
9733 CreateScreenTextInputGadgets();
9736 void FreeScreenGadgets(void)
9740 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9741 FreeGadget(screen_gadget[i]);
9744 static void MapScreenMenuGadgets(int screen_mask)
9748 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9749 if (screen_mask & menubutton_info[i].screen_mask)
9750 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9753 static void UnmapScreenMenuGadgets(int screen_mask)
9757 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9759 if (screen_mask & menubutton_info[i].screen_mask)
9761 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9763 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9764 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9765 screen_gadget[menubutton_info[i].gadget_id]->y,
9766 screen_gadget[menubutton_info[i].gadget_id]->width,
9767 screen_gadget[menubutton_info[i].gadget_id]->height);
9772 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9775 MapScreenMenuGadgets(screen_mask);
9777 UnmapScreenMenuGadgets(screen_mask);
9780 static void MapScreenGadgets(int num_entries)
9784 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9787 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9788 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9790 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9791 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9794 static void MapScreenTreeGadgets(TreeInfo *ti)
9796 MapScreenGadgets(numTreeInfoInGroup(ti));
9799 static void HandleScreenGadgets(struct GadgetInfo *gi)
9801 int id = gi->custom_id;
9802 int button = gi->event.button;
9803 int step = (button == MB_LEFTBUTTON ? 1 :
9804 button == MB_MIDDLEBUTTON ? 5 :
9805 button == MB_RIGHTBUTTON ? 10 : 1);
9809 case SCREEN_CTRL_ID_PREV_LEVEL:
9810 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9813 case SCREEN_CTRL_ID_NEXT_LEVEL:
9814 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9817 case SCREEN_CTRL_ID_FIRST_LEVEL:
9818 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9821 case SCREEN_CTRL_ID_LAST_LEVEL:
9822 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9825 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9826 CloseDoor(DOOR_CLOSE_2);
9827 SetGameStatus(GAME_MODE_LEVELNR);
9828 DrawChooseLevelNr();
9831 case SCREEN_CTRL_ID_PREV_PLAYER:
9832 HandleSetupScreen_Input_Player(step, -1);
9835 case SCREEN_CTRL_ID_NEXT_PLAYER:
9836 HandleSetupScreen_Input_Player(step, +1);
9839 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9840 InsertSolutionTape();
9843 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9847 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9848 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9852 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9853 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9854 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9855 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9856 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9859 case SCREEN_CTRL_ID_SCROLL_UP:
9860 if (game_status == GAME_MODE_NAMES)
9861 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9862 else if (game_status == GAME_MODE_LEVELS)
9863 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9864 else if (game_status == GAME_MODE_LEVELNR)
9865 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9866 else if (game_status == GAME_MODE_SETUP)
9867 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9868 else if (game_status == GAME_MODE_INFO)
9869 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9872 case SCREEN_CTRL_ID_SCROLL_DOWN:
9873 if (game_status == GAME_MODE_NAMES)
9874 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9875 else if (game_status == GAME_MODE_LEVELS)
9876 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9877 else if (game_status == GAME_MODE_LEVELNR)
9878 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9879 else if (game_status == GAME_MODE_SETUP)
9880 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9881 else if (game_status == GAME_MODE_INFO)
9882 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9885 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9886 if (game_status == GAME_MODE_NAMES)
9887 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9888 else if (game_status == GAME_MODE_LEVELS)
9889 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9890 else if (game_status == GAME_MODE_LEVELNR)
9891 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9892 else if (game_status == GAME_MODE_SETUP)
9893 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9894 else if (game_status == GAME_MODE_INFO)
9895 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9898 case SCREEN_CTRL_ID_NETWORK_SERVER:
9900 if (!strEqual(gi->textinput.value, ""))
9902 setString(&setup.network_server_hostname, gi->textinput.value);
9904 network.server_host = setup.network_server_hostname;
9908 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9910 network.server_host = NULL;
9913 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9914 network.server_host = NULL;
9916 execSetupGame_setNetworkServerText();
9928 void DumpScreenIdentifiers(void)
9932 Print("Active screen elements on current screen:\n");
9934 for (i = 0; main_controls[i].nr != -1; i++)
9936 struct MainControlInfo *mci = &main_controls[i];
9938 if (mci->button_graphic != -1)
9940 char *token = getTokenFromImageID(mci->button_graphic);
9942 Print("- '%s'\n", token);
9949 boolean DoScreenAction(int image_id)
9953 if (game_status != GAME_MODE_MAIN)
9956 for (i = 0; main_controls[i].nr != -1; i++)
9958 struct MainControlInfo *mci = &main_controls[i];
9959 struct MenuPosInfo *pos = mci->pos_button;
9961 if (mci->button_graphic == image_id)
9963 int x = mSX + pos->x;
9964 int y = mSY + pos->y;
9966 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9975 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9977 // get tree info node of newly added level or artwork set
9978 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9979 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9981 if (tree_node_new == NULL) // should not happen
9984 // if request dialog is active, do nothing
9985 if (game.request_active)
9988 if (game_status == GAME_MODE_MAIN &&
9989 tree_type == TREE_TYPE_LEVEL_DIR)
9991 // when adding new level set in main menu, select it as current level set
9993 // change current level set to newly added level set from zip file
9994 leveldir_current = tree_node_new;
9996 // change current level number to first level of newly added level set
9997 level_nr = leveldir_current->first_level;
9999 // redraw screen to reflect changed level set
10002 // save this level set and level number as last selected level set
10003 SaveLevelSetup_LastSeries();
10004 SaveLevelSetup_SeriesInfo();
10006 else if (game_status == GAME_MODE_LEVELS &&
10007 tree_type == TREE_TYPE_LEVEL_DIR)
10009 // when adding new level set in level set menu, set cursor and update screen
10011 leveldir_current = tree_node_new;
10013 DrawChooseTree(&leveldir_current);
10015 else if (game_status == GAME_MODE_SETUP)
10017 // when adding new artwork set in setup menu, set cursor and update screen
10019 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10020 tree_type == TREE_TYPE_GRAPHICS_DIR)
10022 artwork.gfx_current = tree_node_new;
10024 DrawChooseTree(&artwork.gfx_current);
10026 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10027 tree_type == TREE_TYPE_SOUNDS_DIR)
10029 artwork.snd_current = tree_node_new;
10031 DrawChooseTree(&artwork.snd_current);
10033 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10034 tree_type == TREE_TYPE_MUSIC_DIR)
10036 artwork.mus_current = tree_node_new;
10038 DrawChooseTree(&artwork.mus_current);
10043 static int UploadTapes(void)
10045 SetGameStatus(GAME_MODE_LOADING);
10047 FadeSetEnterScreen();
10048 FadeOut(REDRAW_ALL);
10050 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10052 FadeIn(REDRAW_ALL);
10054 DrawInitTextHead("Uploading tapes");
10056 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10057 global.autoplay_leveldir = "ALL";
10058 global.autoplay_all = TRUE;
10060 int num_tapes_uploaded = AutoPlayTapes();
10062 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10063 global.autoplay_leveldir = NULL;
10064 global.autoplay_all = FALSE;
10066 SetGameStatus(GAME_MODE_MAIN);
10070 return num_tapes_uploaded;
10073 static boolean OfferUploadTapes(void)
10075 if (!Request("Upload all your tapes to the high score server now?", REQ_ASK))
10078 int num_tapes_uploaded = UploadTapes();
10081 if (num_tapes_uploaded < 0)
10083 Request("Cannot upload tapes to score server!", REQ_CONFIRM);
10088 if (num_tapes_uploaded == 0)
10089 sprintf(message, "No tapes uploaded!");
10090 else if (num_tapes_uploaded == 1)
10091 sprintf(message, "1 tape uploaded!");
10093 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10095 Request(message, REQ_CONFIRM);
10097 // after all tapes have been uploaded, remove entry from setup menu
10098 setup.provide_uploading_tapes = FALSE;
10105 void CheckUploadTapes(void)
10107 if (!setup.ask_for_uploading_tapes)
10110 // after asking for uploading all tapes once, do not ask again
10111 setup.ask_for_uploading_tapes = FALSE;
10113 if (directoryExists(getTapeDir(NULL)))
10115 boolean tapes_uploaded = OfferUploadTapes();
10117 if (!tapes_uploaded)
10118 Request("You can upload your tapes from the setup menu later!",
10123 // if tapes directory does not exist yet, never offer uploading all tapes
10124 setup.provide_uploading_tapes = FALSE;