1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
27 #define DEBUG_JOYSTICKS 0
30 // screens on the info screen
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 // screens on the setup screen
43 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
44 // (should also match corresponding entries in src/conf_gfx.c)
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_ENGINES 2
48 #define SETUP_MODE_EDITOR 3
49 #define SETUP_MODE_GRAPHICS 4
50 #define SETUP_MODE_SOUND 5
51 #define SETUP_MODE_ARTWORK 6
52 #define SETUP_MODE_INPUT 7
53 #define SETUP_MODE_TOUCH 8
54 #define SETUP_MODE_SHORTCUTS 9
55 #define SETUP_MODE_SHORTCUTS_1 10
56 #define SETUP_MODE_SHORTCUTS_2 11
57 #define SETUP_MODE_SHORTCUTS_3 12
58 #define SETUP_MODE_SHORTCUTS_4 13
59 #define SETUP_MODE_SHORTCUTS_5 14
61 // sub-screens on the setup screen (generic)
62 #define SETUP_MODE_CHOOSE_ARTWORK 15
63 #define SETUP_MODE_CHOOSE_OTHER 16
65 // sub-screens on the setup screen (specific)
66 #define SETUP_MODE_CHOOSE_GAME_SPEED 17
67 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 18
68 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 19
69 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 20
70 #define SETUP_MODE_CHOOSE_SCALING_TYPE 21
71 #define SETUP_MODE_CHOOSE_RENDERING 22
72 #define SETUP_MODE_CHOOSE_VSYNC 23
73 #define SETUP_MODE_CHOOSE_GRAPHICS 24
74 #define SETUP_MODE_CHOOSE_SOUNDS 25
75 #define SETUP_MODE_CHOOSE_MUSIC 26
76 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 27
77 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 28
78 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 29
79 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 30
80 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 31
81 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_TRANSPARENCY 33
83 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 34
84 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 36
86 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 37
87 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 38
89 #define MAX_SETUP_MODES 39
91 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
93 // setup screen titles
94 #define STR_SETUP_MAIN "Setup"
95 #define STR_SETUP_GAME "Game & Menu"
96 #define STR_SETUP_ENGINES "Game Engines"
97 #define STR_SETUP_EDITOR "Editor"
98 #define STR_SETUP_GRAPHICS "Graphics"
99 #define STR_SETUP_SOUND "Sound & Music"
100 #define STR_SETUP_ARTWORK "Custom Artwork"
101 #define STR_SETUP_INPUT "Input Devices"
102 #define STR_SETUP_TOUCH "Touch Controls"
103 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
104 #define STR_SETUP_EXIT "Exit"
105 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
107 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
108 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
109 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
110 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
111 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
112 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
113 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
114 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
115 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
116 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
117 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
118 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
119 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
120 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
121 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
122 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
126 // other screen text constants
127 #define STR_CHOOSE_TREE_EDIT "Edit"
128 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
129 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
131 // for input setup functions
132 #define SETUPINPUT_SCREEN_POS_START 0
133 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
134 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
135 #define SETUPINPUT_SCREEN_POS_END 13
137 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
138 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
140 #define MAX_SETUP_TEXT_INPUT_LEN 28
142 // for various menu stuff
143 #define MENU_SCREEN_START_XPOS 1
144 #define MENU_SCREEN_START_YPOS 2
145 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
146 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
147 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
148 #define MENU_TITLE1_YPOS 8
149 #define MENU_TITLE2_YPOS 46
150 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
151 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
152 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
153 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
154 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
155 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
156 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
159 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
160 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
161 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
162 MENU_INFO_FONT_TITLE))
163 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
164 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
165 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
166 MENU_SCREEN_INFO_YSTART2 - \
168 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
169 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
170 MENU_SCREEN_INFO_YSTEP)
171 #define NUM_INFO_ELEMENTS_FROM_CONF \
172 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
173 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
174 MAX_MENU_ENTRIES_ON_SCREEN)
175 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
176 MAX_INFO_ELEMENTS_ON_SCREEN), \
177 NUM_INFO_ELEMENTS_FROM_CONF)
178 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
179 #define MAX_MENU_TEXT_LENGTH_BIG 13
180 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
182 // screen gadget identifiers
183 #define SCREEN_CTRL_ID_PREV_LEVEL 0
184 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
185 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
186 #define SCREEN_CTRL_ID_LAST_LEVEL 3
187 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
188 #define SCREEN_CTRL_ID_PREV_PLAYER 5
189 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
190 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
191 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
192 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
193 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
194 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
195 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
196 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
197 #define SCREEN_CTRL_ID_SCROLL_UP 14
198 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
199 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
200 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
202 #define NUM_SCREEN_GADGETS 18
204 #define NUM_SCREEN_MENUBUTTONS 14
205 #define NUM_SCREEN_SCROLLBUTTONS 2
206 #define NUM_SCREEN_SCROLLBARS 1
207 #define NUM_SCREEN_TEXTINPUT 1
209 #define SCREEN_MASK_MAIN (1 << 0)
210 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
211 #define SCREEN_MASK_INPUT (1 << 2)
212 #define SCREEN_MASK_TOUCH (1 << 3)
213 #define SCREEN_MASK_TOUCH2 (1 << 4)
215 // graphic position and size values for buttons and scrollbars
216 #define SC_MENUBUTTON_XSIZE TILEX
217 #define SC_MENUBUTTON_YSIZE TILEY
219 #define SC_SCROLLBUTTON_XSIZE TILEX
220 #define SC_SCROLLBUTTON_YSIZE TILEY
222 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
224 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
225 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
226 SC_SCROLLBUTTON_YSIZE)
228 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
229 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
231 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
232 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
233 SC_SCROLLBUTTON_YSIZE)
235 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
236 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
237 SC_SCROLL_VERTICAL_YSIZE)
239 #define SC_BORDER_SIZE 14
242 // forward declarations of internal functions
243 static void HandleScreenGadgets(struct GadgetInfo *);
244 static void HandleSetupScreen_Generic(int, int, int, int, int);
245 static void HandleSetupScreen_Input(int, int, int, int, int);
246 static void CustomizeKeyboard(int);
247 static void ConfigureJoystick(int);
248 static void ConfigureVirtualButtons(void);
249 static void execSetupGame(void);
250 static void execSetupEngines(void);
251 static void execSetupGraphics(void);
252 static void execSetupSound(void);
253 static void execSetupTouch(void);
254 static void execSetupArtwork(void);
255 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
257 static void DrawChoosePlayerName(void);
258 static void DrawChooseLevelSet(void);
259 static void DrawChooseLevelNr(void);
260 static void DrawInfoScreen(void);
261 static void DrawSetupScreen(void);
262 static void DrawTypeName(void);
264 static void DrawInfoScreen_NotAvailable(char *, char *);
265 static void DrawInfoScreen_HelpAnim(int, int, boolean);
266 static void DrawInfoScreen_HelpText(int, int, int, int);
267 static void HandleInfoScreen_Main(int, int, int, int, int);
268 static void HandleInfoScreen_TitleScreen(int);
269 static void HandleInfoScreen_Elements(int);
270 static void HandleInfoScreen_Music(int);
271 static void HandleInfoScreen_Credits(int);
272 static void HandleInfoScreen_Program(int);
273 static void HandleInfoScreen_Version(int);
275 static void ModifyGameSpeedIfNeeded(void);
276 static void DisableVsyncIfNeeded(void);
278 static void MapScreenMenuGadgets(int);
279 static void UnmapScreenMenuGadgets(int);
280 static void MapScreenGadgets(int);
281 static void MapScreenTreeGadgets(TreeInfo *);
283 static void UpdateScreenMenuGadgets(int, boolean);
285 static boolean OfferUploadTapes(void);
287 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
289 static int info_mode = INFO_MODE_MAIN;
290 static int setup_mode = SETUP_MODE_MAIN;
292 static TreeInfo *window_sizes = NULL;
293 static TreeInfo *window_size_current = NULL;
295 static TreeInfo *scaling_types = NULL;
296 static TreeInfo *scaling_type_current = NULL;
298 static TreeInfo *rendering_modes = NULL;
299 static TreeInfo *rendering_mode_current = NULL;
301 static TreeInfo *vsync_modes = NULL;
302 static TreeInfo *vsync_mode_current = NULL;
304 static TreeInfo *scroll_delays = NULL;
305 static TreeInfo *scroll_delay_current = NULL;
307 static TreeInfo *snapshot_modes = NULL;
308 static TreeInfo *snapshot_mode_current = NULL;
310 static TreeInfo *game_speeds_normal = NULL;
311 static TreeInfo *game_speeds_extended = NULL;
312 static TreeInfo *game_speeds = NULL;
313 static TreeInfo *game_speed_current = NULL;
315 static TreeInfo *volumes_simple = NULL;
316 static TreeInfo *volume_simple_current = NULL;
318 static TreeInfo *volumes_loops = NULL;
319 static TreeInfo *volume_loops_current = NULL;
321 static TreeInfo *volumes_music = NULL;
322 static TreeInfo *volume_music_current = NULL;
324 static TreeInfo *touch_controls = NULL;
325 static TreeInfo *touch_control_current = NULL;
327 static TreeInfo *move_distances = NULL;
328 static TreeInfo *move_distance_current = NULL;
330 static TreeInfo *drop_distances = NULL;
331 static TreeInfo *drop_distance_current = NULL;
333 static TreeInfo *transparencies = NULL;
334 static TreeInfo *transparency_current = NULL;
336 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
337 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
339 static TreeInfo *player_name = NULL;
340 static TreeInfo *player_name_current = NULL;
342 static TreeInfo *level_number = NULL;
343 static TreeInfo *level_number_current = NULL;
345 static struct ValueTextInfo window_sizes_list[] =
350 { 100, "100 % (Default)" },
363 static struct StringValueTextInfo scaling_types_list[] =
365 { SCALING_QUALITY_NEAREST, "Off" },
366 { SCALING_QUALITY_LINEAR, "Linear" },
367 { SCALING_QUALITY_BEST, "Anisotropic" },
372 static struct StringValueTextInfo rendering_modes_list[] =
374 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
375 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
377 // this mode may work under certain conditions, but does not work on Windows
378 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
380 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
385 static struct StringValueTextInfo vsync_modes_list[] =
387 { STR_VSYNC_MODE_OFF, "Off" },
388 { STR_VSYNC_MODE_NORMAL, "Normal" },
389 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
394 static struct ValueTextInfo game_speeds_list_normal[] =
405 static struct ValueTextInfo game_speeds_list_extended[] =
407 { 1000, "1 fps (Extremely Slow)" },
412 { 29, "35 fps (Original Supaplex)" },
414 { 20, "50 fps (=== Normal Speed ===)" },
415 { 16, "60 fps (60 Hz VSync Speed)" },
416 { 14, "70 fps (Maximum Supaplex)" },
420 { 1, "1000 fps (Extremely Fast)" },
425 static struct ValueTextInfo *game_speeds_list;
427 static struct ValueTextInfo scroll_delays_list[] =
429 { 0, "0 Tiles (No Scroll Delay)" },
432 { 3, "3 Tiles (Default)" },
437 { 8, "8 Tiles (Maximum Scroll Delay)"},
442 static struct StringValueTextInfo snapshot_modes_list[] =
444 { STR_SNAPSHOT_MODE_OFF, "Off" },
445 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
446 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
447 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
452 static struct ValueTextInfo volumes_list[] =
472 static struct StringValueTextInfo touch_controls_list[] =
474 { TOUCH_CONTROL_OFF, "Off" },
475 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
476 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
477 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
482 static struct ValueTextInfo distances_list[] =
497 static struct ValueTextInfo transparencies_list[] =
499 { 0, "0 % (Opaque)" },
509 { 100, "100 % (Invisible)" },
514 static struct ValueTextInfo grid_sizes_list[] =
550 static int align_xoffset = 0;
551 static int align_yoffset = 0;
553 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
554 (s) <= GAME_MODE_SETUP ? (s) : \
555 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
557 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
558 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
560 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
561 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
562 (i) <= INFO_MODE_LEVELSET ? (i) : \
565 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
566 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
567 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
568 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
569 SETUP_MODE_CHOOSE_ARTWORK : \
570 SETUP_MODE_CHOOSE_OTHER)
572 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
573 menu.draw_xoffset[GAME_MODE_INFO] : \
574 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
575 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
576 menu.draw_yoffset[GAME_MODE_INFO] : \
577 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
578 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
579 menu.extra_spacing[GAME_MODE_INFO] : \
580 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
582 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
583 menu.draw_xoffset[GAME_MODE_SETUP] : \
584 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
585 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
586 menu.draw_yoffset[GAME_MODE_SETUP] : \
587 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
588 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
589 menu.extra_spacing[GAME_MODE_SETUP] : \
590 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
592 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
593 DRAW_XOFFSET_INFO(info_mode) : \
594 (s) == GAME_MODE_SETUP ? \
595 DRAW_XOFFSET_SETUP(setup_mode) : \
596 menu.draw_xoffset[DRAW_MODE(s)])
597 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
598 DRAW_YOFFSET_INFO(info_mode) : \
599 (s) == GAME_MODE_SETUP ? \
600 DRAW_YOFFSET_SETUP(setup_mode) : \
601 menu.draw_yoffset[DRAW_MODE(s)])
602 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
603 EXTRA_SPACING_INFO(info_mode) : \
604 (s) == GAME_MODE_SETUP ? \
605 EXTRA_SPACING_SETUP(setup_mode) : \
606 menu.extra_spacing[DRAW_MODE(s)])
608 #define mSX (SX + DRAW_XOFFSET(game_status))
609 #define mSY (SY + DRAW_YOFFSET(game_status))
611 #define amSX (mSX + align_xoffset)
612 #define amSY (mSY + align_yoffset)
614 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
615 menu.list_size[game_status] : \
616 MAX_MENU_ENTRIES_ON_SCREEN)
618 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
619 NUM_MENU_ENTRIES_ON_SCREEN)
622 // title display and control definitions
624 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
625 2 * MAX_NUM_TITLE_MESSAGES)
627 #define NO_DIRECT_LEVEL_SELECT (-1)
630 static int num_title_screens = 0;
632 struct TitleControlInfo
641 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
643 // main menu display and control definitions
645 #define MAIN_CONTROL_NAME 0
646 #define MAIN_CONTROL_LEVELS 1
647 #define MAIN_CONTROL_SCORES 2
648 #define MAIN_CONTROL_EDITOR 3
649 #define MAIN_CONTROL_INFO 4
650 #define MAIN_CONTROL_GAME 5
651 #define MAIN_CONTROL_SETUP 6
652 #define MAIN_CONTROL_QUIT 7
653 #define MAIN_CONTROL_PREV_LEVEL 8
654 #define MAIN_CONTROL_NEXT_LEVEL 9
655 #define MAIN_CONTROL_FIRST_LEVEL 10
656 #define MAIN_CONTROL_LAST_LEVEL 11
657 #define MAIN_CONTROL_LEVEL_NUMBER 12
658 #define MAIN_CONTROL_LEVEL_INFO_1 13
659 #define MAIN_CONTROL_LEVEL_INFO_2 14
660 #define MAIN_CONTROL_LEVEL_NAME 15
661 #define MAIN_CONTROL_LEVEL_AUTHOR 16
662 #define MAIN_CONTROL_LEVEL_YEAR 17
663 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
664 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
665 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
666 #define MAIN_CONTROL_TITLE_1 21
667 #define MAIN_CONTROL_TITLE_2 22
668 #define MAIN_CONTROL_TITLE_3 23
670 static char str_main_text_name[10];
671 static char str_main_text_first_level[10];
672 static char str_main_text_last_level[10];
673 static char str_main_text_level_number[10];
675 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
677 static char *main_text_name = str_main_text_name;
678 static char *main_text_first_level = str_main_text_first_level;
679 static char *main_text_last_level = str_main_text_last_level;
680 static char *main_text_level_number = str_main_text_level_number;
681 static char *main_text_levels = "Levelset";
682 static char *main_text_scores = "Hall Of Fame";
683 static char *main_text_editor = "Level Creator";
684 static char *main_text_info = "Info Screen";
685 static char *main_text_game = "Start Game";
686 static char *main_text_setup = "Setup";
687 static char *main_text_quit = "Quit";
688 static char *main_text_level_name = level.name;
689 static char *main_text_level_author = level.author;
690 static char *main_text_level_year = NULL;
691 static char *main_text_level_imported_from = NULL;
692 static char *main_text_level_imported_by = NULL;
693 static char *main_text_level_tested_by = NULL;
694 static char *main_text_title_1 = NULL;
695 static char *main_text_title_2 = NULL;
696 static char *main_text_title_3 = NULL;
698 extern char debug_xsn_mode[];
700 struct MainControlInfo
704 struct MenuPosInfo *pos_button;
707 struct TextPosInfo *pos_text;
710 struct TextPosInfo *pos_input;
714 static struct MainControlInfo main_controls[] =
718 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
719 &menu.main.text.name, &main_text_name,
720 &menu.main.input.name, &setup.player_name,
724 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
725 &menu.main.text.levels, &main_text_levels,
730 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
731 &menu.main.text.scores, &main_text_scores,
736 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
737 &menu.main.text.editor, &main_text_editor,
742 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
743 &menu.main.text.info, &main_text_info,
748 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
749 &menu.main.text.game, &main_text_game,
754 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
755 &menu.main.text.setup, &main_text_setup,
760 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
761 &menu.main.text.quit, &main_text_quit,
765 MAIN_CONTROL_PREV_LEVEL,
771 MAIN_CONTROL_NEXT_LEVEL,
777 MAIN_CONTROL_FIRST_LEVEL,
779 &menu.main.text.first_level, &main_text_first_level,
783 MAIN_CONTROL_LAST_LEVEL,
785 &menu.main.text.last_level, &main_text_last_level,
789 MAIN_CONTROL_LEVEL_NUMBER,
791 &menu.main.text.level_number, &main_text_level_number,
795 MAIN_CONTROL_LEVEL_INFO_1,
797 &menu.main.text.level_info_1, NULL,
801 MAIN_CONTROL_LEVEL_INFO_2,
803 &menu.main.text.level_info_2, NULL,
807 MAIN_CONTROL_LEVEL_NAME,
809 &menu.main.text.level_name, &main_text_level_name,
813 MAIN_CONTROL_LEVEL_AUTHOR,
815 &menu.main.text.level_author, &main_text_level_author,
819 MAIN_CONTROL_LEVEL_YEAR,
821 &menu.main.text.level_year, &main_text_level_year,
825 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
827 &menu.main.text.level_imported_from, &main_text_level_imported_from,
831 MAIN_CONTROL_LEVEL_IMPORTED_BY,
833 &menu.main.text.level_imported_by, &main_text_level_imported_by,
837 MAIN_CONTROL_LEVEL_TESTED_BY,
839 &menu.main.text.level_tested_by, &main_text_level_tested_by,
843 MAIN_CONTROL_TITLE_1,
845 &menu.main.text.title_1, &main_text_title_1,
849 MAIN_CONTROL_TITLE_2,
851 &menu.main.text.title_2, &main_text_title_2,
855 MAIN_CONTROL_TITLE_3,
857 &menu.main.text.title_3, &main_text_title_3,
870 static int getTitleScreenGraphic(int nr, boolean initial)
872 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
875 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
877 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
881 static int getTitleScreenGameMode(boolean initial)
883 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
887 static int getTitleMessageGameMode(boolean initial)
889 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
892 static int getTitleAnimMode(struct TitleControlInfo *tci)
894 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
896 return base + tci->local_nr;
900 static int getTitleScreenBackground(boolean initial)
902 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
907 static int getTitleMessageBackground(int nr, boolean initial)
909 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
913 static int getTitleBackground(int nr, boolean initial, boolean is_image)
915 int base = (is_image ?
916 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
917 IMG_BACKGROUND_TITLESCREEN_1) :
918 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
919 IMG_BACKGROUND_TITLEMESSAGE_1));
920 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
921 IMG_BACKGROUND_TITLE);
922 int graphic_local = base + nr;
924 if (graphic_info[graphic_local].bitmap != NULL)
925 return graphic_local;
927 if (graphic_info[graphic_global].bitmap != NULL)
928 return graphic_global;
930 return IMG_UNDEFINED;
933 static int getTitleSound(struct TitleControlInfo *tci)
935 boolean is_image = tci->is_image;
936 int initial = tci->initial;
937 int nr = tci->local_nr;
938 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
939 int base = (is_image ?
940 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
941 SND_BACKGROUND_TITLESCREEN_1) :
942 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
943 SND_BACKGROUND_TITLEMESSAGE_1));
944 int sound_global = menu.sound[mode];
945 int sound_local = base + nr;
948 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
949 nr, initial, is_image,
950 sound_global, getSoundListEntry(sound_global)->filename,
951 sound_local, getSoundListEntry(sound_local)->filename);
954 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
957 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
960 return SND_UNDEFINED;
963 static int getTitleMusic(struct TitleControlInfo *tci)
965 boolean is_image = tci->is_image;
966 int initial = tci->initial;
967 int nr = tci->local_nr;
968 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
969 int base = (is_image ?
970 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
971 MUS_BACKGROUND_TITLESCREEN_1) :
972 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
973 MUS_BACKGROUND_TITLEMESSAGE_1));
974 int music_global = menu.music[mode];
975 int music_local = base + nr;
978 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
979 nr, initial, is_image,
980 music_global, getMusicListEntry(music_global)->filename,
981 music_local, getMusicListEntry(music_local)->filename);
984 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
987 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
990 return MUS_UNDEFINED;
993 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
995 boolean is_image = tci->is_image;
996 boolean initial = tci->initial;
997 boolean first = tci->first;
998 int nr = tci->local_nr;
999 struct TitleMessageInfo tmi;
1000 struct TitleFadingInfo ti;
1002 tmi = (is_image ? (initial ? (first ?
1003 titlescreen_initial_first[nr] :
1004 titlescreen_initial[nr])
1006 titlescreen_first[nr] :
1008 : (initial ? (first ?
1009 titlemessage_initial_first[nr] :
1010 titlemessage_initial[nr])
1012 titlemessage_first[nr] :
1013 titlemessage[nr])));
1015 ti.fade_mode = tmi.fade_mode;
1016 ti.fade_delay = tmi.fade_delay;
1017 ti.post_delay = tmi.post_delay;
1018 ti.auto_delay = tmi.auto_delay;
1019 ti.auto_delay_unit = tmi.auto_delay_unit;
1024 static int compareTitleControlInfo(const void *object1, const void *object2)
1026 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1027 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1030 if (tci1->initial != tci2->initial)
1031 compare_result = (tci1->initial ? -1 : +1);
1032 else if (tci1->sort_priority != tci2->sort_priority)
1033 compare_result = tci1->sort_priority - tci2->sort_priority;
1034 else if (tci1->is_image != tci2->is_image)
1035 compare_result = (tci1->is_image ? -1 : +1);
1037 compare_result = tci1->local_nr - tci2->local_nr;
1039 return compare_result;
1042 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1044 int nr, int sort_priority)
1046 title_controls[num_title_screens].is_image = is_image;
1047 title_controls[num_title_screens].initial = initial;
1048 title_controls[num_title_screens].local_nr = nr;
1049 title_controls[num_title_screens].sort_priority = sort_priority;
1051 title_controls[num_title_screens].first = FALSE; // will be set later
1053 num_title_screens++;
1056 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1060 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1062 int graphic = getTitleScreenGraphic(i, initial);
1063 Bitmap *bitmap = graphic_info[graphic].bitmap;
1064 int sort_priority = graphic_info[graphic].sort_priority;
1067 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1070 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1072 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1073 char *filename = getLevelSetTitleMessageFilename(i, initial);
1074 int sort_priority = tmi->sort_priority;
1076 if (filename != NULL)
1077 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1081 static void InitializeTitleControls(boolean show_title_initial)
1083 num_title_screens = 0;
1085 // 1st step: initialize title screens for game start (only when starting)
1086 if (show_title_initial)
1087 InitializeTitleControls_CheckTitleInfo(TRUE);
1089 // 2nd step: initialize title screens for current level set
1090 InitializeTitleControls_CheckTitleInfo(FALSE);
1092 // sort title screens according to sort_priority and title number
1093 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1094 compareTitleControlInfo);
1096 // mark first title screen
1097 title_controls[0].first = TRUE;
1100 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1102 return (pos != NULL && pos->x != -1 && pos->y != -1);
1105 static boolean visibleTextPos(struct TextPosInfo *pos)
1107 return (pos != NULL && pos->x != -1 && pos->y != -1);
1110 static void InitializeMainControls(void)
1112 boolean local_team_mode = (!network.enabled && setup.team_mode);
1115 // set main control text values to dynamically determined values
1116 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1118 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1119 menu.main.text.first_level.size));
1120 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1121 menu.main.text.last_level.size));
1122 strcpy(main_text_level_number, int2str(level_nr,
1123 menu.main.text.level_number.size));
1125 main_text_level_year = leveldir_current->year;
1126 main_text_level_imported_from = leveldir_current->imported_from;
1127 main_text_level_imported_by = leveldir_current->imported_by;
1128 main_text_level_tested_by = leveldir_current->tested_by;
1130 main_text_title_1 = getConfigProgramTitleString();
1131 main_text_title_2 = getConfigProgramCopyrightString();
1132 main_text_title_3 = getConfigProgramCompanyString();
1134 // set main control screen positions to dynamically determined values
1135 for (i = 0; main_controls[i].nr != -1; i++)
1137 struct MainControlInfo *mci = &main_controls[i];
1139 struct MenuPosInfo *pos_button = mci->pos_button;
1140 struct TextPosInfo *pos_text = mci->pos_text;
1141 struct TextPosInfo *pos_input = mci->pos_input;
1142 char *text = (mci->text ? *mci->text : NULL);
1143 char *input = (mci->input ? *mci->input : NULL);
1144 int button_graphic = mci->button_graphic;
1145 int font_text = (pos_text ? pos_text->font : -1);
1146 int font_input = (pos_input ? pos_input->font : -1);
1148 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1149 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1150 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1151 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1152 int text_chars = (text != NULL ? strlen(text) : 0);
1153 int input_chars = (input != NULL ? strlen(input) : 0);
1156 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1158 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1159 int text_width = font_text_width * text_chars;
1160 int text_height = font_text_height;
1161 int input_width = font_input_width * input_chars;
1162 int input_height = font_input_height;
1164 if (nr == MAIN_CONTROL_NAME)
1166 menu.main.input.name.width = input_width;
1167 menu.main.input.name.height = input_height;
1170 if (pos_button != NULL) // (x/y may be -1/-1 here)
1172 pos_button->width = button_width;
1173 pos_button->height = button_height;
1176 if (pos_text != NULL) // (x/y may be -1/-1 here)
1178 // calculate text size -- needed for text alignment
1179 boolean calculate_text_size = (text != NULL);
1181 if (pos_text->width == -1 || calculate_text_size)
1182 pos_text->width = text_width;
1183 if (pos_text->height == -1 || calculate_text_size)
1184 pos_text->height = text_height;
1186 if (visibleMenuPos(pos_button))
1188 if (pos_text->x == -1)
1189 pos_text->x = pos_button->x + pos_button->width;
1190 if (pos_text->y == -1)
1192 pos_button->y + (pos_button->height - pos_text->height) / 2;
1196 if (pos_input != NULL) // (x/y may be -1/-1 here)
1198 if (visibleTextPos(pos_text))
1200 if (pos_input->x == -1)
1201 pos_input->x = pos_text->x + pos_text->width;
1202 if (pos_input->y == -1)
1203 pos_input->y = pos_text->y;
1206 if (pos_input->width == -1)
1207 pos_input->width = input_width;
1208 if (pos_input->height == -1)
1209 pos_input->height = input_height;
1214 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1215 int graphic, boolean pressed)
1217 struct GraphicInfo *g = &graphic_info[graphic];
1220 int xoffset = (pressed ? g->pressed_xoffset : 0);
1221 int yoffset = (pressed ? g->pressed_yoffset : 0);
1223 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1225 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1226 g->width, g->height, dst_x, dst_y);
1229 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1230 boolean active_input,
1231 boolean pressed_button)
1235 for (i = 0; main_controls[i].nr != -1; i++)
1237 struct MainControlInfo *mci = &main_controls[i];
1239 if (mci->nr == nr || nr == -1)
1241 struct MenuPosInfo *pos_button = mci->pos_button;
1242 struct TextPosInfo *pos_text = mci->pos_text;
1243 struct TextPosInfo *pos_input = mci->pos_input;
1244 char *text = (mci->text ? *mci->text : NULL);
1245 char *input = (mci->input ? *mci->input : NULL);
1246 int button_graphic = mci->button_graphic;
1247 int font_text = (pos_text ? pos_text->font : -1);
1248 int font_input = (pos_input ? pos_input->font : -1);
1252 button_graphic = BUTTON_ACTIVE(button_graphic);
1253 font_text = FONT_ACTIVE(font_text);
1258 font_input = FONT_ACTIVE(font_input);
1261 if (visibleMenuPos(pos_button))
1263 struct MenuPosInfo *pos = pos_button;
1264 int x = mSX + pos->x;
1265 int y = mSY + pos->y;
1267 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1268 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1271 if (visibleTextPos(pos_text) && text != NULL)
1273 struct TextPosInfo *pos = pos_text;
1274 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1275 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1278 // (check why/if this is needed)
1279 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1281 DrawText(x, y, text, font_text);
1284 if (visibleTextPos(pos_input) && input != NULL)
1286 struct TextPosInfo *pos = pos_input;
1287 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1288 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1291 // (check why/if this is needed)
1292 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1294 DrawText(x, y, input, font_input);
1300 static void DrawCursorAndText_Main(int nr, boolean active_text,
1301 boolean pressed_button)
1303 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1307 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1308 boolean pressed_button)
1310 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1314 static struct MainControlInfo *getMainControlInfo(int nr)
1318 for (i = 0; main_controls[i].nr != -1; i++)
1319 if (main_controls[i].nr == nr)
1320 return &main_controls[i];
1325 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1330 int rect_x = ALIGNED_TEXT_XPOS(rect);
1331 int rect_y = ALIGNED_TEXT_YPOS(rect);
1333 return (x >= rect_x && x < rect_x + rect->width &&
1334 y >= rect_y && y < rect_y + rect->height);
1337 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1342 int rect_x = ALIGNED_TEXT_XPOS(rect);
1343 int rect_y = ALIGNED_TEXT_YPOS(rect);
1346 Debug("screens:insideTextPosRect",
1347 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1348 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1349 (x >= rect_x && x < rect_x + rect->width &&
1350 y >= rect_y && y < rect_y + rect->height));
1353 return (x >= rect_x && x < rect_x + rect->width &&
1354 y >= rect_y && y < rect_y + rect->height);
1357 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1359 int rect_width = preview->xsize * preview->tile_size;
1360 int rect_height = preview->ysize * preview->tile_size;
1361 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1362 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1364 return (x >= rect_x && x < rect_x + rect_width &&
1365 y >= rect_y && y < rect_y + rect_height);
1368 static void AdjustScrollbar(int id, int items_max, int items_visible,
1371 struct GadgetInfo *gi = screen_gadget[id];
1373 if (item_position > items_max - items_visible)
1374 item_position = items_max - items_visible;
1376 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1377 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1378 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1381 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1383 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1387 static void clearMenuListArea(void)
1389 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1391 // correct scrollbar position if placed outside menu (playfield) area
1392 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1393 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1395 // clear menu list area, but not title or scrollbar
1396 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1397 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1400 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1402 static int cursor_array[MAX_LEV_FIELDY];
1403 int x = amSX + TILEX * xpos;
1404 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1409 cursor_array[ypos] = graphic;
1411 graphic = cursor_array[ypos];
1415 graphic = BUTTON_ACTIVE(graphic);
1417 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1418 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1421 static void initCursor(int ypos, int graphic)
1423 drawCursorExt(0, ypos, FALSE, graphic);
1426 static void drawCursor(int ypos, boolean active)
1428 drawCursorExt(0, ypos, active, -1);
1431 static void drawCursorXY(int xpos, int ypos, int graphic)
1433 drawCursorExt(xpos, ypos, FALSE, graphic);
1436 static void drawChooseTreeCursor(int ypos, boolean active)
1438 drawCursorExt(0, ypos, active, -1);
1441 static int getChooseTreeEditFont(boolean active)
1443 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1446 static int getChooseTreeEditXPos(int pos)
1448 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1449 int xoffset = (has_scrollbar ? -1 : 0);
1450 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1451 int sx = amSX + xpos * TILEX;
1452 int font_nr = getChooseTreeEditFont(FALSE);
1453 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1455 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1458 static int getChooseTreeEditYPos(int ypos_raw)
1460 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1461 int sy = amSY + ypos * TILEY;
1466 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1468 int sx = getChooseTreeEditXPos(POS_LEFT);
1469 int sy = getChooseTreeEditYPos(ypos_raw);
1470 int font_nr = getChooseTreeEditFont(active);
1472 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1475 static void DrawHeadline(void)
1477 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1478 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1481 static void DrawTitleScreenImage(int nr, boolean initial)
1483 int graphic = getTitleScreenGraphic(nr, initial);
1484 Bitmap *bitmap = graphic_info[graphic].bitmap;
1485 int width = graphic_info[graphic].width;
1486 int height = graphic_info[graphic].height;
1487 int src_x = graphic_info[graphic].src_x;
1488 int src_y = graphic_info[graphic].src_y;
1494 if (width > WIN_XSIZE)
1496 // image width too large for window => center image horizontally
1497 src_x = (width - WIN_XSIZE) / 2;
1501 if (height > WIN_YSIZE)
1503 // image height too large for window => center image vertically
1504 src_y = (height - WIN_YSIZE) / 2;
1508 // always display title screens centered
1509 dst_x = (WIN_XSIZE - width) / 2;
1510 dst_y = (WIN_YSIZE - height) / 2;
1512 SetDrawBackgroundMask(REDRAW_ALL);
1513 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1515 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1517 if (DrawingOnBackground(dst_x, dst_y))
1518 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1520 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1522 redraw_mask = REDRAW_ALL;
1525 static void DrawTitleScreenMessage(int nr, boolean initial)
1527 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1528 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1530 if (filename == NULL)
1533 // force TITLE font on title message screen
1534 SetFontStatus(getTitleMessageGameMode(initial));
1536 // if chars *and* width set to "-1", automatically determine width
1537 if (tmi->chars == -1 && tmi->width == -1)
1538 tmi->width = viewport.window[game_status].width;
1540 // if lines *and* height set to "-1", automatically determine height
1541 if (tmi->lines == -1 && tmi->height == -1)
1542 tmi->height = viewport.window[game_status].height;
1544 // if chars set to "-1", automatically determine by text and font width
1545 if (tmi->chars == -1)
1546 tmi->chars = tmi->width / getFontWidth(tmi->font);
1548 tmi->width = tmi->chars * getFontWidth(tmi->font);
1550 // if lines set to "-1", automatically determine by text and font height
1551 if (tmi->lines == -1)
1552 tmi->lines = tmi->height / getFontHeight(tmi->font);
1554 tmi->height = tmi->lines * getFontHeight(tmi->font);
1556 // if x set to "-1", automatically determine by width and alignment
1558 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1560 // if y set to "-1", automatically determine by height and alignment
1562 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1564 SetDrawBackgroundMask(REDRAW_ALL);
1565 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1567 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1569 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1570 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1571 tmi->autowrap, tmi->centered, tmi->parse_comments);
1576 static void DrawTitleScreen(void)
1578 KeyboardAutoRepeatOff();
1580 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1583 static boolean CheckTitleScreen(boolean levelset_has_changed)
1585 static boolean show_title_initial = TRUE;
1586 boolean show_titlescreen = FALSE;
1588 // needed to be able to skip title screen, if no image or message defined
1589 InitializeTitleControls(show_title_initial);
1591 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1592 show_titlescreen = TRUE;
1594 // show initial title images and messages only once at program start
1595 show_title_initial = FALSE;
1597 return (show_titlescreen && num_title_screens > 0);
1600 void DrawMainMenu(void)
1602 static LevelDirTree *leveldir_last_valid = NULL;
1603 boolean levelset_has_changed = FALSE;
1604 int fade_mask = REDRAW_FIELD;
1606 LimitScreenUpdates(FALSE);
1608 FadeSetLeaveScreen();
1610 // do not fade out here -- function may continue and fade on editor screen
1613 FadeMenuSoundsAndMusic();
1615 ExpireSoundLoops(FALSE);
1617 KeyboardAutoRepeatOn();
1619 audio.sound_deactivated = FALSE;
1623 // needed if last screen was the playing screen, invoked from level editor
1624 if (level_editor_test_game)
1626 CloseDoor(DOOR_CLOSE_ALL);
1628 SetGameStatus(GAME_MODE_EDITOR);
1635 // leveldir_current may be invalid (level group, parent link, node copy)
1636 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1638 if (leveldir_current != leveldir_last_valid)
1640 UpdateLastPlayedLevels_TreeInfo();
1642 levelset_has_changed = TRUE;
1645 // store valid level series information
1646 leveldir_last_valid = leveldir_current;
1648 init_last = init; // switch to new busy animation
1650 // needed if last screen (level choice) changed graphics, sounds or music
1651 ReloadCustomArtwork(0);
1653 if (CheckTitleScreen(levelset_has_changed))
1655 SetGameStatus(GAME_MODE_TITLE);
1662 if (redraw_mask & REDRAW_ALL)
1663 fade_mask = REDRAW_ALL;
1666 fade_mask = REDRAW_ALL;
1670 // needed if different viewport properties defined for menues
1671 ChangeViewportPropertiesIfNeeded();
1673 SetDrawtoField(DRAW_TO_BACKBUFFER);
1675 // level_nr may have been set to value over handicap with level editor
1676 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1677 level_nr = leveldir_current->handicap_level;
1679 LoadLevel(level_nr);
1680 LoadScore(level_nr);
1682 SaveLevelSetup_SeriesInfo();
1684 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1685 SetDrawDeactivationMask(REDRAW_NONE);
1686 SetDrawBackgroundMask(REDRAW_FIELD);
1688 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1691 if (fade_mask == REDRAW_ALL)
1692 RedrawGlobalBorder();
1697 InitializeMainControls();
1699 DrawCursorAndText_Main(-1, FALSE, FALSE);
1700 DrawPreviewLevelInitial();
1701 DrawNetworkPlayers();
1703 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1706 if (TAPE_IS_EMPTY(tape))
1708 DrawCompleteVideoDisplay();
1710 PlayMenuSoundsAndMusic();
1712 // create gadgets for main menu screen
1713 FreeScreenGadgets();
1714 CreateScreenGadgets();
1716 // may be required if audio buttons shown on tape and changed in setup menu
1718 CreateGameButtons();
1720 // map gadgets for main menu screen
1722 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1723 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1725 // copy actual game door content to door double buffer for OpenDoor()
1726 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1727 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1729 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1731 DrawMaskedBorder(fade_mask);
1736 // update screen area with special editor door
1737 redraw_mask |= REDRAW_ALL;
1740 SetMouseCursor(CURSOR_DEFAULT);
1742 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1744 SyncEmscriptenFilesystem();
1747 static void gotoTopLevelDir(void)
1749 // move upwards until inside (but not above) top level directory
1750 while (leveldir_current->node_parent &&
1751 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1753 // write a "path" into level tree for easy navigation to last level
1754 if (leveldir_current->node_parent->node_group->cl_first == -1)
1756 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1757 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1758 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1759 int cl_first, cl_cursor;
1761 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1762 cl_cursor = leveldir_pos - cl_first;
1764 leveldir_current->node_parent->node_group->cl_first = cl_first;
1765 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1768 leveldir_current = leveldir_current->node_parent;
1772 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1774 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1776 return (use_frame_counter ? video.frame_counter : Counter());
1779 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1780 struct TitleFadingInfo *fi)
1782 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1785 static void ResetTitleAutoDelay(unsigned int *counter_var,
1786 struct TitleFadingInfo *fi)
1788 *counter_var = getAutoDelayCounter(fi);
1791 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1793 static unsigned int title_delay = 0;
1794 static int title_screen_nr = 0;
1795 static int last_sound = -1, last_music = -1;
1796 boolean return_to_main_menu = FALSE;
1797 struct TitleControlInfo *tci;
1800 if (button == MB_MENU_INITIALIZE)
1803 title_screen_nr = 0;
1804 tci = &title_controls[title_screen_nr];
1806 SetAnimStatus(getTitleAnimMode(tci));
1808 last_sound = SND_UNDEFINED;
1809 last_music = MUS_UNDEFINED;
1811 if (num_title_screens != 0)
1813 FadeSetEnterScreen();
1815 // use individual title fading instead of global "enter screen" fading
1816 fading = getTitleFading(tci);
1819 if (game_status_last_screen == GAME_MODE_INFO)
1821 if (num_title_screens == 0)
1823 // switch game mode from title screen mode back to info screen mode
1824 SetGameStatus(GAME_MODE_INFO);
1826 // store that last screen was info screen, not main menu screen
1827 game_status_last_screen = GAME_MODE_INFO;
1829 DrawInfoScreen_NotAvailable("Title screen information:",
1830 "No title screen for this level set.");
1835 FadeMenuSoundsAndMusic();
1837 FadeOut(REDRAW_ALL);
1839 // title screens may have different window size
1840 ChangeViewportPropertiesIfNeeded();
1842 // only required to update logic for redrawing global border
1846 DrawTitleScreenImage(tci->local_nr, tci->initial);
1848 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1850 sound = getTitleSound(tci);
1851 music = getTitleMusic(tci);
1853 if (sound != last_sound)
1854 PlayMenuSoundExt(sound);
1855 if (music != last_music)
1856 PlayMenuMusicExt(music);
1861 SetMouseCursor(CURSOR_NONE);
1865 ResetTitleAutoDelay(&title_delay, &fading);
1870 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1871 button = MB_MENU_CHOICE;
1873 if (button == MB_MENU_LEAVE)
1875 return_to_main_menu = TRUE;
1877 else if (button == MB_MENU_CHOICE)
1879 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1881 SetGameStatus(GAME_MODE_INFO);
1883 info_mode = INFO_MODE_MAIN;
1892 if (title_screen_nr < num_title_screens)
1894 tci = &title_controls[title_screen_nr];
1896 SetAnimStatus(getTitleAnimMode(tci));
1898 sound = getTitleSound(tci);
1899 music = getTitleMusic(tci);
1901 if (last_sound != SND_UNDEFINED && sound != last_sound)
1902 FadeSound(last_sound);
1903 if (last_music != MUS_UNDEFINED && music != last_music)
1906 fading = getTitleFading(tci);
1908 FadeOut(REDRAW_ALL);
1911 DrawTitleScreenImage(tci->local_nr, tci->initial);
1913 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1915 sound = getTitleSound(tci);
1916 music = getTitleMusic(tci);
1918 if (sound != last_sound)
1919 PlayMenuSoundExt(sound);
1920 if (music != last_music)
1921 PlayMenuMusicExt(music);
1928 ResetTitleAutoDelay(&title_delay, &fading);
1932 FadeMenuSoundsAndMusic();
1934 return_to_main_menu = TRUE;
1938 if (return_to_main_menu)
1940 SetMouseCursor(CURSOR_DEFAULT);
1942 // force full menu screen redraw after displaying title screens
1943 redraw_mask = REDRAW_ALL;
1945 if (game_status_last_screen == GAME_MODE_INFO)
1947 SetGameStatus(GAME_MODE_INFO);
1949 info_mode = INFO_MODE_MAIN;
1953 else // default: return to main menu
1955 SetGameStatus(GAME_MODE_MAIN);
1962 static void HandleMainMenu_ToggleTeamMode(void)
1964 setup.team_mode = !setup.team_mode;
1966 InitializeMainControls();
1967 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
1969 DrawPreviewPlayers();
1972 static void HandleMainMenu_SelectLevel(int step, int direction,
1973 int selected_level_nr)
1975 int old_level_nr = level_nr;
1978 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1979 new_level_nr = selected_level_nr;
1981 new_level_nr = old_level_nr + step * direction;
1983 if (new_level_nr < leveldir_current->first_level)
1984 new_level_nr = leveldir_current->first_level;
1985 if (new_level_nr > leveldir_current->last_level)
1986 new_level_nr = leveldir_current->last_level;
1988 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1990 // skipping levels is only allowed when trying to skip single level
1991 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1992 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1994 leveldir_current->handicap_level++;
1995 SaveLevelSetup_SeriesInfo();
1998 new_level_nr = leveldir_current->handicap_level;
2001 if (new_level_nr != old_level_nr)
2003 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2005 PlaySound(SND_MENU_ITEM_SELECTING);
2007 level_nr = new_level_nr;
2009 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2010 int2str(level_nr, menu.main.text.level_number.size),
2011 mci->pos_text->font);
2013 LoadLevel(level_nr);
2014 DrawPreviewLevelInitial();
2018 DrawCompleteVideoDisplay();
2020 SaveLevelSetup_SeriesInfo();
2022 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2024 // force redraw of playfield area (may be reset at this point)
2025 redraw_mask |= REDRAW_FIELD;
2029 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2031 static int choice = MAIN_CONTROL_GAME;
2032 static boolean button_pressed_last = FALSE;
2033 boolean button_pressed = FALSE;
2035 int i = 0; // needed to prevent compiler warning due to bad code below
2037 if (button == MB_MENU_INITIALIZE)
2039 DrawCursorAndText_Main(choice, TRUE, FALSE);
2044 if (mx || my) // mouse input
2048 for (i = 0; main_controls[i].nr != -1; i++)
2050 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2051 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2052 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2054 pos = main_controls[i].nr;
2060 // check if level preview was clicked
2061 if (insidePreviewRect(&preview, mx - SX, my - SY))
2062 pos = MAIN_CONTROL_GAME;
2064 // handle pressed/unpressed state for active/inactive menu buttons
2065 // (if pos != -1, "i" contains index position corresponding to "pos")
2067 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2068 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2069 button_pressed = TRUE;
2071 if (button_pressed != button_pressed_last)
2073 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2076 PlaySound(SND_MENU_BUTTON_PRESSING);
2078 PlaySound(SND_MENU_BUTTON_RELEASING);
2081 else if (dx || dy) // keyboard input
2083 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2084 choice == MAIN_CONTROL_SETUP))
2085 button = MB_MENU_CHOICE;
2090 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2092 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2094 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2096 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2098 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2100 CloseDoor(DOOR_CLOSE_2);
2102 SetGameStatus(GAME_MODE_LEVELNR);
2104 DrawChooseLevelNr();
2106 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2112 PlaySound(SND_MENU_ITEM_ACTIVATING);
2114 DrawCursorAndText_Main(choice, FALSE, FALSE);
2115 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2121 if (choice == MAIN_CONTROL_NAME)
2123 // special case: cursor left or right pressed -- toggle team mode
2124 HandleMainMenu_ToggleTeamMode();
2126 else if (choice != MAIN_CONTROL_INFO &&
2127 choice != MAIN_CONTROL_SETUP)
2129 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2135 PlaySound(SND_MENU_ITEM_SELECTING);
2137 if (pos == MAIN_CONTROL_NAME)
2140 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2142 // special case: menu text "name/team" clicked -- toggle team mode
2143 HandleMainMenu_ToggleTeamMode();
2147 if (setup.multiple_users)
2149 CloseDoor(DOOR_CLOSE_2);
2151 SetGameStatus(GAME_MODE_NAMES);
2153 DrawChoosePlayerName();
2157 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2163 else if (pos == MAIN_CONTROL_LEVELS)
2167 CloseDoor(DOOR_CLOSE_2);
2169 SetGameStatus(GAME_MODE_LEVELS);
2171 SaveLevelSetup_LastSeries();
2172 SaveLevelSetup_SeriesInfo();
2174 // restore level set if chosen from "last played level set" menu
2175 RestoreLastPlayedLevels(&leveldir_current);
2177 if (setup.internal.choose_from_top_leveldir)
2180 DrawChooseLevelSet();
2183 else if (pos == MAIN_CONTROL_SCORES)
2185 CloseDoor(DOOR_CLOSE_2);
2187 SetGameStatus(GAME_MODE_SCORES);
2189 DrawHallOfFame(level_nr);
2191 else if (pos == MAIN_CONTROL_EDITOR)
2193 if (leveldir_current->readonly &&
2194 setup.editor.show_read_only_warning)
2195 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2197 CloseDoor(DOOR_CLOSE_ALL);
2199 SetGameStatus(GAME_MODE_EDITOR);
2201 FadeSetEnterScreen();
2205 else if (pos == MAIN_CONTROL_INFO)
2207 CloseDoor(DOOR_CLOSE_2);
2209 SetGameStatus(GAME_MODE_INFO);
2211 info_mode = INFO_MODE_MAIN;
2215 else if (pos == MAIN_CONTROL_GAME)
2217 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2219 else if (pos == MAIN_CONTROL_SETUP)
2221 CloseDoor(DOOR_CLOSE_2);
2223 SetGameStatus(GAME_MODE_SETUP);
2225 setup_mode = SETUP_MODE_MAIN;
2229 else if (pos == MAIN_CONTROL_QUIT)
2231 SaveLevelSetup_LastSeries();
2232 SaveLevelSetup_SeriesInfo();
2234 if (!setup.ask_on_quit_program ||
2235 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2236 SetGameStatus(GAME_MODE_QUIT);
2241 button_pressed_last = button_pressed;
2245 // ============================================================================
2246 // info screen functions
2247 // ============================================================================
2249 static struct TokenInfo *info_info;
2250 static int num_info_info; // number of info entries shown on screen
2251 static int max_info_info; // total number of info entries in list
2253 static void execInfoTitleScreen(void)
2255 info_mode = INFO_MODE_TITLE;
2260 static void execInfoElements(void)
2262 info_mode = INFO_MODE_ELEMENTS;
2267 static void execInfoMusic(void)
2269 info_mode = INFO_MODE_MUSIC;
2274 static void execInfoCredits(void)
2276 info_mode = INFO_MODE_CREDITS;
2281 static void execInfoProgram(void)
2283 info_mode = INFO_MODE_PROGRAM;
2288 static void execInfoVersion(void)
2290 info_mode = INFO_MODE_VERSION;
2295 static void execInfoLevelSet(void)
2297 info_mode = INFO_MODE_LEVELSET;
2302 static void execExitInfo(void)
2304 SetGameStatus(GAME_MODE_MAIN);
2309 static struct TokenInfo info_info_main[] =
2311 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2312 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2313 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2314 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2315 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2316 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2317 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2318 { TYPE_EMPTY, NULL, "" },
2319 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2324 static int getMenuTextFont(int type)
2326 if (type & (TYPE_SWITCH |
2340 static struct TokenInfo *setup_info;
2341 static struct TokenInfo setup_info_input[];
2343 static struct TokenInfo *menu_info;
2345 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2346 int screen_pos, int menu_info_pos_raw,
2349 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2350 struct TokenInfo *ti = &token_info[pos];
2351 int xpos = MENU_SCREEN_START_XPOS;
2352 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2353 int font_nr = getMenuTextFont(ti->type);
2355 if (setup_mode == SETUP_MODE_INPUT)
2356 font_nr = FONT_MENU_1;
2359 font_nr = FONT_ACTIVE(font_nr);
2361 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2363 if (ti->type & ~TYPE_SKIP_ENTRY)
2364 drawCursor(screen_pos, active);
2367 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2370 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2373 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2376 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2379 static char *window_size_text;
2380 static char *scaling_type_text;
2381 static char *network_server_text;
2383 static void drawSetupValue(int, int);
2385 static void drawMenuInfoList(int first_entry, int num_page_entries,
2386 int max_page_entries)
2390 if (first_entry + num_page_entries > max_page_entries)
2393 clearMenuListArea();
2395 for (i = 0; i < num_page_entries; i++)
2397 int menu_info_pos = first_entry + i;
2398 struct TokenInfo *si = &menu_info[menu_info_pos];
2399 void *value_ptr = si->value;
2401 // set some entries to "unchangeable" according to other variables
2402 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2403 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2404 (value_ptr == &setup.sound_music && !audio.music_available) ||
2405 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2406 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2407 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2408 si->type |= TYPE_GHOSTED;
2410 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2411 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2412 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2413 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2414 else if (si->type & ~TYPE_SKIP_ENTRY)
2415 initCursor(i, IMG_MENU_BUTTON);
2417 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2419 if (si->type & TYPE_STRING)
2423 if (value_ptr == &network_server_text)
2424 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2426 if (gadget_id != -1)
2428 struct GadgetInfo *gi = screen_gadget[gadget_id];
2429 int xpos = MENU_SCREEN_START_XPOS;
2430 int ypos = MENU_SCREEN_START_YPOS + i;
2431 int x = mSX + xpos * 32;
2432 int y = mSY + ypos * 32;
2434 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2438 if (si->type & TYPE_VALUE &&
2439 menu_info == setup_info)
2440 drawSetupValue(i, menu_info_pos);
2444 static void DrawInfoScreen_Main(void)
2446 int fade_mask = REDRAW_FIELD;
2449 if (redraw_mask & REDRAW_ALL)
2450 fade_mask = REDRAW_ALL;
2453 fade_mask = REDRAW_ALL;
2456 FadeMenuSoundsAndMusic();
2458 FreeScreenGadgets();
2459 CreateScreenGadgets();
2461 // (needed after displaying title screens which disable auto repeat)
2462 KeyboardAutoRepeatOn();
2464 FadeSetLeaveScreen();
2468 // needed if different viewport properties defined for info screen
2469 ChangeViewportPropertiesIfNeeded();
2471 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2475 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2477 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2479 info_info = info_info_main;
2481 // determine maximal number of info entries that can be displayed on screen
2483 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2486 // determine maximal number of info entries available for menu of info screen
2488 for (i = 0; info_info[i].type != 0; i++)
2491 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2493 MapScreenGadgets(max_info_info);
2495 PlayMenuSoundsAndMusic();
2497 DrawMaskedBorder(fade_mask);
2502 static void changeSetupValue(int, int, int);
2504 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2505 int mode, int num_page_entries,
2506 int max_page_entries)
2508 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2509 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2510 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2511 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2512 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2513 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2514 int *num_page_entries_last = num_page_entries_all_last[game_status];
2515 int *choice_store = choice_stores[game_status];
2516 int *first_entry_store = first_entry_stores[game_status];
2517 int choice = choice_store[mode]; // starts with 0
2518 int first_entry = first_entry_store[mode]; // starts with 0
2520 int y = choice - first_entry;
2522 boolean position_set_by_scrollbar = (dx == 999);
2523 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2526 if (button == MB_MENU_INITIALIZE)
2528 // check if number of menu page entries has changed (may happen by change
2529 // of custom artwork definition value for 'list_size' for this menu screen)
2530 // (in this case, the last menu position most probably has to be corrected)
2531 if (num_page_entries != num_page_entries_last[mode])
2533 choice_store[mode] = first_entry_store[mode] = 0;
2535 choice = first_entry = 0;
2538 num_page_entries_last[mode] = num_page_entries;
2541 // advance to first valid menu entry
2542 while (choice < num_page_entries &&
2543 menu_info[choice].type & TYPE_SKIP_ENTRY)
2546 if (position_set_by_scrollbar)
2547 first_entry = first_entry_store[mode] = dy;
2549 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2550 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2552 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2554 if (choice < first_entry)
2556 choice = first_entry;
2558 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2561 else if (choice > first_entry + num_page_entries - 1)
2563 choice = first_entry + num_page_entries - 1;
2565 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2569 choice_store[mode] = choice;
2571 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2575 else if (button == MB_MENU_LEAVE)
2577 PlaySound(SND_MENU_ITEM_SELECTING);
2579 for (i = 0; i < max_page_entries; i++)
2581 if (menu_info[i].type & TYPE_LEAVE_MENU)
2583 void (*menu_callback_function)(void) = menu_info[i].value;
2587 menu_callback_function();
2589 break; // absolutely needed because function changes 'menu_info'!
2596 if (mx || my) // mouse input
2598 x = (mx - mSX) / 32;
2599 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2601 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2603 // move cursor instead of scrolling when already at start/end of list
2604 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2606 else if (dy == +1 * SCROLL_LINE &&
2607 first_entry + num_page_entries == max_page_entries)
2610 // handle scrolling screen one line or page
2612 y + dy > num_page_entries - 1)
2614 boolean redraw = FALSE;
2616 if (ABS(dy) == SCROLL_PAGE)
2617 step = num_page_entries - 1;
2619 if (dy < 0 && first_entry > 0)
2621 // scroll page/line up
2623 first_entry -= step;
2624 if (first_entry < 0)
2629 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2631 // scroll page/line down
2633 first_entry += step;
2634 if (first_entry + num_page_entries > max_page_entries)
2635 first_entry = MAX(0, max_page_entries - num_page_entries);
2642 choice += first_entry - first_entry_store[mode];
2644 if (choice < first_entry)
2646 choice = first_entry;
2648 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2651 else if (choice > first_entry + num_page_entries - 1)
2653 choice = first_entry + num_page_entries - 1;
2655 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2658 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2662 if (choice < first_entry ||
2663 choice > first_entry + num_page_entries - 1)
2664 first_entry += SIGN(dy);
2667 first_entry_store[mode] = first_entry;
2668 choice_store[mode] = choice;
2670 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2672 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2674 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2675 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2683 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2685 if (menu_info[choice].type & menu_navigation_type ||
2686 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2687 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2688 menu_info[choice].type & TYPE_PLAYER)
2689 button = MB_MENU_CHOICE;
2694 // jump to next non-empty menu entry (up or down)
2695 while (first_entry + y > 0 &&
2696 first_entry + y < max_page_entries - 1 &&
2697 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2700 if (!IN_VIS_MENU(x, y))
2702 choice += y - y_old;
2704 if (choice < first_entry)
2705 first_entry = choice;
2706 else if (choice > first_entry + num_page_entries - 1)
2707 first_entry = choice - num_page_entries + 1;
2709 if (first_entry >= 0 &&
2710 first_entry + num_page_entries <= max_page_entries)
2712 first_entry_store[mode] = first_entry;
2714 if (choice < first_entry)
2715 choice = first_entry;
2716 else if (choice > first_entry + num_page_entries - 1)
2717 choice = first_entry + num_page_entries - 1;
2719 choice_store[mode] = choice;
2721 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2723 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2725 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2726 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2733 if (!anyScrollbarGadgetActive() &&
2734 IN_VIS_MENU(x, y) &&
2735 mx < mx_right_border &&
2736 y >= 0 && y < num_page_entries)
2740 if (first_entry + y != choice &&
2741 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2743 PlaySound(SND_MENU_ITEM_ACTIVATING);
2745 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2746 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2748 choice = choice_store[mode] = first_entry + y;
2752 PlaySound(SND_MENU_ITEM_SELECTING);
2754 for (i = 0; menu_info[i].type != 0; i++)
2756 if (menu_info[i].type & TYPE_LEAVE_MENU)
2758 void (*menu_callback_function)(void) = menu_info[i].value;
2762 menu_callback_function();
2764 // absolutely needed because function changes 'menu_info'!
2772 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2774 PlaySound(SND_MENU_ITEM_SELECTING);
2776 // when selecting key headline, execute function for key value change
2777 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2778 menu_info[first_entry + y + 1].type & TYPE_KEY)
2781 // when selecting string value, execute function for list selection
2782 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2783 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2786 // when selecting string value, execute function for text input gadget
2787 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2788 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2791 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2793 void (*menu_callback_function)(void) =
2794 menu_info[first_entry + y].value;
2796 FadeSetFromType(menu_info[first_entry + y].type);
2798 menu_callback_function();
2800 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2802 void (*gadget_callback_function)(void) =
2803 menu_info[first_entry + y].value;
2805 gadget_callback_function();
2807 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2808 menu_info == setup_info)
2810 changeSetupValue(y, first_entry + y, dx);
2816 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2818 menu_info = info_info;
2820 HandleMenuScreen(mx, my, dx, dy, button,
2821 info_mode, num_info_info, max_info_info);
2824 static int getMenuFontSpacing(int spacing_height, int font_nr)
2826 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2828 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2832 static int getMenuTextSpacing(int spacing_height, int font_nr)
2834 return (getMenuFontSpacing(spacing_height, font_nr) +
2835 EXTRA_SPACING(game_status));
2838 static int getMenuTextStep(int spacing_height, int font_nr)
2840 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2843 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2845 int font_title = MENU_INFO_FONT_TITLE;
2846 int font_error = FONT_TEXT_2;
2847 int font_foot = MENU_INFO_FONT_FOOT;
2848 int spacing_title = menu.headline1_spacing_info[info_mode];
2849 int ystep_title = getMenuTextStep(spacing_title, font_title);
2850 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2851 int ystart2 = ystart1 + ystep_title;
2852 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2854 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2856 FadeOut(REDRAW_FIELD);
2861 DrawTextSCentered(ystart1, font_title, text_title);
2862 DrawTextSCentered(ystart2, font_error, text_error);
2864 DrawTextSCentered(ybottom, font_foot,
2865 "Press any key or button for info menu");
2867 FadeIn(REDRAW_FIELD);
2870 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2872 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2873 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2874 int font_title = MENU_INFO_FONT_TITLE;
2875 int font_foot = MENU_INFO_FONT_FOOT;
2876 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2877 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2878 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2879 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2880 int ystep = MENU_SCREEN_INFO_YSTEP;
2881 int element, action, direction;
2889 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2890 infoscreen_step[i] = infoscreen_frame[i] = 0;
2895 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2897 DrawTextSCentered(ybottom, font_foot,
2898 "Press any key or button for next page");
2904 while (helpanim_info[j].element != HELPANIM_LIST_END)
2906 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2911 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2920 j += infoscreen_step[i - start];
2922 element = helpanim_info[j].element;
2923 action = helpanim_info[j].action;
2924 direction = helpanim_info[j].direction;
2927 element = EL_UNKNOWN;
2929 if (action != -1 && direction != -1)
2930 graphic = el_act_dir2img(element, action, direction);
2931 else if (action != -1)
2932 graphic = el_act2img(element, action);
2933 else if (direction != -1)
2934 graphic = el_dir2img(element, direction);
2936 graphic = el2img(element);
2938 delay = helpanim_info[j++].delay;
2943 if (infoscreen_frame[i - start] == 0)
2946 infoscreen_frame[i - start] = delay - 1;
2950 sync_frame = delay - infoscreen_frame[i - start];
2951 infoscreen_frame[i - start]--;
2954 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2956 if (!infoscreen_frame[i - start])
2957 infoscreen_step[i - start] = 0;
2961 if (!infoscreen_frame[i - start])
2962 infoscreen_step[i - start]++;
2963 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2969 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2971 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2972 graphic, sync_frame, USE_MASKING);
2975 DrawInfoScreen_HelpText(element, action, direction, i - start);
2980 redraw_mask |= REDRAW_FIELD;
2985 static char *getHelpText(int element, int action, int direction)
2987 char token[MAX_LINE_LEN];
2989 strcpy(token, element_info[element].token_name);
2992 strcat(token, element_action_info[action].suffix);
2994 if (direction != -1)
2995 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2997 return getHashEntry(helptext_info, token);
3000 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3002 int font_nr = FONT_INFO_ELEMENTS;
3003 int font_width = getFontWidth(font_nr);
3004 int font_height = getFontHeight(font_nr);
3005 int yoffset = (TILEX - 2 * font_height) / 2;
3006 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3007 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3008 int ystep = TILEY + 4;
3009 int pad_left = xstart - SX;
3010 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3011 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3012 int max_lines_per_text = 2;
3015 if (action != -1 && direction != -1) // element.action.direction
3016 text = getHelpText(element, action, direction);
3018 if (text == NULL && action != -1) // element.action
3019 text = getHelpText(element, action, -1);
3021 if (text == NULL && direction != -1) // element.direction
3022 text = getHelpText(element, -1, direction);
3024 if (text == NULL) // base element
3025 text = getHelpText(element, -1, -1);
3027 if (text == NULL) // not found
3028 text = "No description available";
3030 if (strlen(text) <= max_chars_per_line) // only one line of text
3031 ystart += getFontHeight(font_nr) / 2;
3033 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3034 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3035 TRUE, FALSE, FALSE);
3038 static void DrawInfoScreen_TitleScreen(void)
3040 SetGameStatus(GAME_MODE_TITLE);
3045 void HandleInfoScreen_TitleScreen(int button)
3047 HandleTitleScreen(0, 0, 0, 0, button);
3050 static void DrawInfoScreen_Elements(void)
3052 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3054 FadeOut(REDRAW_FIELD);
3059 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3061 FadeIn(REDRAW_FIELD);
3064 void HandleInfoScreen_Elements(int button)
3066 static unsigned int info_delay = 0;
3067 static int num_anims;
3068 static int num_pages;
3070 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3073 if (button == MB_MENU_INITIALIZE)
3075 boolean new_element = TRUE;
3079 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3081 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3083 else if (new_element)
3086 new_element = FALSE;
3090 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3094 if (button == MB_MENU_LEAVE)
3096 PlaySound(SND_MENU_ITEM_SELECTING);
3098 info_mode = INFO_MODE_MAIN;
3103 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3105 if (button != MB_MENU_INITIALIZE)
3107 PlaySound(SND_MENU_ITEM_SELECTING);
3112 if (page >= num_pages)
3114 FadeMenuSoundsAndMusic();
3116 info_mode = INFO_MODE_MAIN;
3123 FadeSetNextScreen();
3125 if (button != MB_MENU_INITIALIZE)
3126 FadeOut(REDRAW_FIELD);
3128 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3130 if (button != MB_MENU_INITIALIZE)
3131 FadeIn(REDRAW_FIELD);
3135 if (DelayReached(&info_delay, GameFrameDelay))
3136 if (page < num_pages)
3137 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3139 PlayMenuSoundIfLoop();
3143 static void DrawInfoScreen_Music(void)
3145 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3147 FadeOut(REDRAW_FIELD);
3154 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3156 FadeIn(REDRAW_FIELD);
3159 void HandleInfoScreen_Music(int button)
3161 static struct MusicFileInfo *list = NULL;
3162 int font_title = MENU_INFO_FONT_TITLE;
3163 int font_head = MENU_INFO_FONT_HEAD;
3164 int font_text = MENU_INFO_FONT_TEXT;
3165 int font_foot = MENU_INFO_FONT_FOOT;
3166 int spacing_title = menu.headline1_spacing_info[info_mode];
3167 int spacing_head = menu.headline2_spacing_info[info_mode];
3168 int ystep_title = getMenuTextStep(spacing_title, font_title);
3169 int ystep_head = getMenuTextStep(spacing_head, font_head);
3170 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3171 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3173 if (button == MB_MENU_INITIALIZE)
3175 list = music_file_info;
3179 FadeMenuSoundsAndMusic();
3184 DrawTextSCentered(ystart, font_title,
3185 "No music info for this level set.");
3187 DrawTextSCentered(ybottom, font_foot,
3188 "Press any key or button for info menu");
3194 if (button == MB_MENU_LEAVE)
3196 PlaySound(SND_MENU_ITEM_SELECTING);
3198 FadeMenuSoundsAndMusic();
3200 info_mode = INFO_MODE_MAIN;
3205 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3207 if (button != MB_MENU_INITIALIZE)
3209 PlaySound(SND_MENU_ITEM_SELECTING);
3217 FadeMenuSoundsAndMusic();
3219 info_mode = INFO_MODE_MAIN;
3225 FadeMenuSoundsAndMusic();
3227 if (list != music_file_info)
3228 FadeSetNextScreen();
3230 if (button != MB_MENU_INITIALIZE)
3231 FadeOut(REDRAW_FIELD);
3238 int sound = list->music;
3240 if (sound_info[sound].loop)
3241 PlaySoundLoop(sound);
3245 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3249 int music = list->music;
3251 if (music_info[music].loop)
3252 PlayMusicLoop(music);
3256 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3259 ystart += ystep_title;
3261 if (!strEqual(list->title, UNKNOWN_NAME))
3263 if (!strEqual(list->title_header, UNKNOWN_NAME))
3265 DrawTextSCentered(ystart, font_head, list->title_header);
3266 ystart += ystep_head;
3269 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3270 ystart += ystep_head;
3273 if (!strEqual(list->artist, UNKNOWN_NAME))
3275 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3276 DrawTextSCentered(ystart, font_head, list->artist_header);
3278 DrawTextSCentered(ystart, font_head, "by");
3280 ystart += ystep_head;
3282 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3283 ystart += ystep_head;
3286 if (!strEqual(list->album, UNKNOWN_NAME))
3288 if (!strEqual(list->album_header, UNKNOWN_NAME))
3289 DrawTextSCentered(ystart, font_head, list->album_header);
3291 DrawTextSCentered(ystart, font_head, "from the album");
3293 ystart += ystep_head;
3295 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3296 ystart += ystep_head;
3299 if (!strEqual(list->year, UNKNOWN_NAME))
3301 if (!strEqual(list->year_header, UNKNOWN_NAME))
3302 DrawTextSCentered(ystart, font_head, list->year_header);
3304 DrawTextSCentered(ystart, font_head, "from the year");
3306 ystart += ystep_head;
3308 DrawTextFCentered(ystart, font_text, "%s", list->year);
3309 ystart += ystep_head;
3312 DrawTextSCentered(ybottom, FONT_TEXT_4,
3313 "Press any key or button for next page");
3315 if (button != MB_MENU_INITIALIZE)
3316 FadeIn(REDRAW_FIELD);
3319 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3320 PlaySoundLoop(list->music);
3323 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3325 int font_title = MENU_INFO_FONT_TITLE;
3326 int font_head = MENU_INFO_FONT_HEAD;
3327 int font_text = MENU_INFO_FONT_TEXT;
3328 int font_foot = MENU_INFO_FONT_FOOT;
3329 int spacing_title = menu.headline1_spacing_info[info_mode];
3330 int spacing_head = menu.headline2_spacing_info[info_mode];
3331 int spacing_para = menu.paragraph_spacing_info[info_mode];
3332 int spacing_line = menu.line_spacing_info[info_mode];
3333 int ystep_title = getMenuTextStep(spacing_title, font_title);
3334 int ystep_head = getMenuTextStep(spacing_head, font_head);
3335 int ystep_para = getMenuTextStep(spacing_para, font_text);
3336 int ystep_line = getMenuTextStep(spacing_line, font_text);
3337 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3338 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3343 DrawTextSCentered(ystart, font_title, "Credits:");
3344 ystart += ystep_title;
3348 DrawTextSCentered(ystart, font_head,
3349 "Special thanks to");
3350 ystart += ystep_head;
3351 DrawTextSCentered(ystart, font_text,
3353 ystart += ystep_head;
3354 DrawTextSCentered(ystart, font_head,
3356 ystart += ystep_head;
3357 DrawTextSCentered(ystart, font_text,
3358 "\"Boulder Dash\"");
3359 ystart += ystep_head;
3360 DrawTextSCentered(ystart, font_head,
3362 ystart += ystep_head;
3363 DrawTextSCentered(ystart, font_text,
3365 ystart += ystep_head;
3366 DrawTextSCentered(ystart, font_head,
3368 ystart += ystep_head;
3369 DrawTextSCentered(ystart, font_text,
3370 "First Star Software");
3372 else if (screen_nr == 1)
3374 DrawTextSCentered(ystart, font_head,
3375 "Special thanks to");
3376 ystart += ystep_head;
3377 DrawTextSCentered(ystart, font_text,
3378 "Klaus Heinz & Volker Wertich");
3379 ystart += ystep_head;
3380 DrawTextSCentered(ystart, font_head,
3382 ystart += ystep_head;
3383 DrawTextSCentered(ystart, font_text,
3384 "\"Emerald Mine\"");
3385 ystart += ystep_head;
3386 DrawTextSCentered(ystart, font_head,
3388 ystart += ystep_head;
3389 DrawTextSCentered(ystart, font_text,
3391 ystart += ystep_head;
3392 DrawTextSCentered(ystart, font_head,
3394 ystart += ystep_head;
3395 DrawTextSCentered(ystart, font_text,
3398 else if (screen_nr == 2)
3400 DrawTextSCentered(ystart, font_head,
3401 "Special thanks to");
3402 ystart += ystep_head;
3403 DrawTextSCentered(ystart, font_text,
3404 "Michael Stopp & Philip Jespersen");
3405 ystart += ystep_head;
3406 DrawTextSCentered(ystart, font_head,
3408 ystart += ystep_head;
3409 DrawTextSCentered(ystart, font_text,
3411 ystart += ystep_head;
3412 DrawTextSCentered(ystart, font_head,
3414 ystart += ystep_head;
3415 DrawTextSCentered(ystart, font_text,
3417 ystart += ystep_head;
3418 DrawTextSCentered(ystart, font_head,
3420 ystart += ystep_head;
3421 DrawTextSCentered(ystart, font_text,
3422 "Digital Integration");
3424 else if (screen_nr == 3)
3426 DrawTextSCentered(ystart, font_head,
3427 "Special thanks to");
3428 ystart += ystep_head;
3429 DrawTextSCentered(ystart, font_text,
3430 "Hiroyuki Imabayashi");
3431 ystart += ystep_head;
3432 DrawTextSCentered(ystart, font_head,
3434 ystart += ystep_head;
3435 DrawTextSCentered(ystart, font_text,
3437 ystart += ystep_head;
3438 DrawTextSCentered(ystart, font_head,
3440 ystart += ystep_head;
3441 DrawTextSCentered(ystart, font_text,
3443 ystart += ystep_head;
3444 DrawTextSCentered(ystart, font_head,
3446 ystart += ystep_head;
3447 DrawTextSCentered(ystart, font_text,
3450 else if (screen_nr == 4)
3452 DrawTextSCentered(ystart, font_head,
3453 "Special thanks to");
3454 ystart += ystep_head;
3455 DrawTextSCentered(ystart, font_text,
3457 ystart += ystep_head;
3458 DrawTextSCentered(ystart, font_head,
3460 ystart += ystep_head;
3461 DrawTextSCentered(ystart, font_text,
3462 "J\xfcrgen Bonhagen");
3463 ystart += ystep_head;
3464 DrawTextSCentered(ystart, font_head,
3465 "for the continuous creation");
3466 ystart += ystep_line;
3467 DrawTextSCentered(ystart, font_head,
3468 "of outstanding level sets");
3470 else if (screen_nr == 5)
3472 DrawTextSCentered(ystart, font_head,
3474 ystart += ystep_head;
3475 DrawTextSCentered(ystart, font_text,
3477 ystart += ystep_head;
3478 DrawTextSCentered(ystart, font_head,
3479 "for ideas and inspiration by");
3480 ystart += ystep_head;
3481 DrawTextSCentered(ystart, font_text,
3483 ystart += ystep_para;
3485 DrawTextSCentered(ystart, font_head,
3487 ystart += ystep_head;
3488 DrawTextSCentered(ystart, font_text,
3490 ystart += ystep_head;
3491 DrawTextSCentered(ystart, font_head,
3492 "for ideas and inspiration by");
3493 ystart += ystep_head;
3494 DrawTextSCentered(ystart, font_text,
3497 else if (screen_nr == 6)
3499 DrawTextSCentered(ystart, font_head,
3501 ystart += ystep_head;
3502 DrawTextSCentered(ystart, font_text,
3504 ystart += ystep_head;
3505 DrawTextSCentered(ystart, font_head,
3506 "for the code base used for the");
3507 ystart += ystep_line;
3508 DrawTextSCentered(ystart, font_head,
3509 "native Emerald Mine engine");
3511 else if (screen_nr == 7)
3513 DrawTextSCentered(ystart, font_head,
3515 ystart += ystep_head;
3516 DrawTextSCentered(ystart, font_text,
3518 ystart += ystep_head;
3519 DrawTextSCentered(ystart, font_head,
3520 "for the initial DOS port");
3521 ystart += ystep_para;
3523 DrawTextSCentered(ystart, font_head,
3525 ystart += ystep_head;
3526 DrawTextSCentered(ystart, font_text,
3528 ystart += ystep_head;
3529 DrawTextSCentered(ystart, font_head,
3530 "for some additional toons");
3532 else if (screen_nr == 8)
3534 DrawTextSCentered(ystart, font_head,
3535 "And not to forget:");
3536 ystart += ystep_head;
3537 DrawTextSCentered(ystart, font_head,
3539 ystart += ystep_head;
3540 DrawTextSCentered(ystart, font_text,
3541 "All those who contributed");
3542 ystart += ystep_line;
3543 DrawTextSCentered(ystart, font_text,
3544 "levels to this game");
3545 ystart += ystep_line;
3546 DrawTextSCentered(ystart, font_text,
3550 DrawTextSCentered(ybottom, font_foot,
3551 "Press any key or button for next page");
3554 static void DrawInfoScreen_Credits(void)
3556 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3558 FadeMenuSoundsAndMusic();
3560 FadeOut(REDRAW_FIELD);
3562 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3564 FadeIn(REDRAW_FIELD);
3567 void HandleInfoScreen_Credits(int button)
3569 static int screen_nr = 0;
3570 int num_screens = 9;
3572 if (button == MB_MENU_INITIALIZE)
3576 // DrawInfoScreen_CreditsScreen(screen_nr);
3579 if (button == MB_MENU_LEAVE)
3581 PlaySound(SND_MENU_ITEM_SELECTING);
3583 info_mode = INFO_MODE_MAIN;
3588 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3590 if (button != MB_MENU_INITIALIZE)
3592 PlaySound(SND_MENU_ITEM_SELECTING);
3597 if (screen_nr >= num_screens)
3599 FadeMenuSoundsAndMusic();
3601 info_mode = INFO_MODE_MAIN;
3608 FadeSetNextScreen();
3610 if (button != MB_MENU_INITIALIZE)
3611 FadeOut(REDRAW_FIELD);
3613 DrawInfoScreen_CreditsScreen(screen_nr);
3615 if (button != MB_MENU_INITIALIZE)
3616 FadeIn(REDRAW_FIELD);
3620 PlayMenuSoundIfLoop();
3624 static void DrawInfoScreen_Program(void)
3626 int font_title = MENU_INFO_FONT_TITLE;
3627 int font_head = MENU_INFO_FONT_HEAD;
3628 int font_text = MENU_INFO_FONT_TEXT;
3629 int font_foot = MENU_INFO_FONT_FOOT;
3630 int spacing_title = menu.headline1_spacing_info[info_mode];
3631 int spacing_head = menu.headline2_spacing_info[info_mode];
3632 int spacing_para = menu.paragraph_spacing_info[info_mode];
3633 int spacing_line = menu.line_spacing_info[info_mode];
3634 int ystep_title = getMenuTextStep(spacing_title, font_title);
3635 int ystep_head = getMenuTextStep(spacing_head, font_head);
3636 int ystep_para = getMenuTextStep(spacing_para, font_text);
3637 int ystep_line = getMenuTextStep(spacing_line, font_text);
3638 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3639 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3641 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3643 FadeOut(REDRAW_FIELD);
3648 DrawTextSCentered(ystart, font_title, "Program Information:");
3649 ystart += ystep_title;
3651 DrawTextSCentered(ystart, font_head,
3652 "This game is Freeware!");
3653 ystart += ystep_head;
3654 DrawTextSCentered(ystart, font_head,
3655 "If you like it, send e-mail to:");
3656 ystart += ystep_head;
3657 DrawTextSCentered(ystart, font_text,
3658 setup.internal.program_email);
3659 ystart += ystep_para;
3661 DrawTextSCentered(ystart, font_head,
3662 "More information and levels:");
3663 ystart += ystep_head;
3664 DrawTextSCentered(ystart, font_text,
3665 setup.internal.program_website);
3666 ystart += ystep_para;
3668 DrawTextSCentered(ystart, font_head,
3669 "If you have created new levels,");
3670 ystart += ystep_line;
3671 DrawTextSCentered(ystart, font_head,
3672 "send them to me to include them!");
3673 ystart += ystep_head;
3674 DrawTextSCentered(ystart, font_head,
3677 DrawTextSCentered(ybottom, font_foot,
3678 "Press any key or button for info menu");
3680 FadeIn(REDRAW_FIELD);
3683 void HandleInfoScreen_Program(int button)
3685 if (button == MB_MENU_LEAVE)
3687 PlaySound(SND_MENU_ITEM_SELECTING);
3689 info_mode = INFO_MODE_MAIN;
3694 else if (button == MB_MENU_CHOICE)
3696 PlaySound(SND_MENU_ITEM_SELECTING);
3698 FadeMenuSoundsAndMusic();
3700 info_mode = INFO_MODE_MAIN;
3705 PlayMenuSoundIfLoop();
3709 static void DrawInfoScreen_Version(void)
3711 int font_title = MENU_INFO_FONT_TITLE;
3712 int font_head = MENU_INFO_FONT_HEAD;
3713 int font_text = MENU_INFO_FONT_TEXT;
3714 int font_foot = MENU_INFO_FONT_FOOT;
3715 int spacing_title = menu.headline1_spacing_info[info_mode];
3716 int spacing_head = menu.headline2_spacing_info[info_mode];
3717 int spacing_para = menu.paragraph_spacing_info[info_mode];
3718 int spacing_line = menu.line_spacing_info[info_mode];
3719 int xstep = getFontWidth(font_text);
3720 int ystep_title = getMenuTextStep(spacing_title, font_title);
3721 int ystep_head = getMenuTextStep(spacing_head, font_head);
3722 int ystep_para = getMenuTextStep(spacing_para, font_text);
3723 int ystep_line = getMenuTextStep(spacing_line, font_text);
3724 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3725 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3726 int xstart1 = mSX - SX + 2 * xstep;
3727 int xstart2 = mSX - SX + 18 * xstep;
3728 int xstart3 = mSX - SX + 28 * xstep;
3729 SDL_version sdl_version_compiled;
3730 const SDL_version *sdl_version_linked;
3731 int driver_name_len = 10;
3732 SDL_version sdl_version_linked_ext;
3733 const char *driver_name = NULL;
3735 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3737 FadeOut(REDRAW_FIELD);
3742 DrawTextSCentered(ystart, font_title, "Version Information:");
3743 ystart += ystep_title;
3745 DrawTextF(xstart1, ystart, font_head, "Name");
3746 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3747 ystart += ystep_line;
3749 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3751 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3752 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3753 ystart += ystep_line;
3755 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3756 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3757 ystart += ystep_line;
3761 DrawTextF(xstart1, ystart, font_head, "Version");
3762 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3763 ystart += ystep_line;
3766 DrawTextF(xstart1, ystart, font_head, "Platform");
3767 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3769 PLATFORM_XX_BIT_STRING);
3770 ystart += ystep_line;
3772 DrawTextF(xstart1, ystart, font_head, "Target");
3773 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3774 ystart += ystep_line;
3776 DrawTextF(xstart1, ystart, font_head, "Source date");
3777 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3778 ystart += ystep_line;
3780 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3781 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3782 ystart += ystep_para;
3784 DrawTextF(xstart1, ystart, font_head, "Library");
3785 DrawTextF(xstart2, ystart, font_head, "compiled");
3786 DrawTextF(xstart3, ystart, font_head, "linked");
3787 ystart += ystep_head;
3789 SDL_VERSION(&sdl_version_compiled);
3790 SDL_GetVersion(&sdl_version_linked_ext);
3791 sdl_version_linked = &sdl_version_linked_ext;
3793 DrawTextF(xstart1, ystart, font_text, "SDL");
3794 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3795 sdl_version_compiled.major,
3796 sdl_version_compiled.minor,
3797 sdl_version_compiled.patch);
3798 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3799 sdl_version_linked->major,
3800 sdl_version_linked->minor,
3801 sdl_version_linked->patch);
3802 ystart += ystep_line;
3804 SDL_IMAGE_VERSION(&sdl_version_compiled);
3805 sdl_version_linked = IMG_Linked_Version();
3807 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3808 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3809 sdl_version_compiled.major,
3810 sdl_version_compiled.minor,
3811 sdl_version_compiled.patch);
3812 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3813 sdl_version_linked->major,
3814 sdl_version_linked->minor,
3815 sdl_version_linked->patch);
3816 ystart += ystep_line;
3818 SDL_MIXER_VERSION(&sdl_version_compiled);
3819 sdl_version_linked = Mix_Linked_Version();
3821 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3822 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3823 sdl_version_compiled.major,
3824 sdl_version_compiled.minor,
3825 sdl_version_compiled.patch);
3826 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3827 sdl_version_linked->major,
3828 sdl_version_linked->minor,
3829 sdl_version_linked->patch);
3830 ystart += ystep_line;
3832 SDL_NET_VERSION(&sdl_version_compiled);
3833 sdl_version_linked = SDLNet_Linked_Version();
3835 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3836 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3837 sdl_version_compiled.major,
3838 sdl_version_compiled.minor,
3839 sdl_version_compiled.patch);
3840 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3841 sdl_version_linked->major,
3842 sdl_version_linked->minor,
3843 sdl_version_linked->patch);
3844 ystart += ystep_para;
3846 DrawTextF(xstart1, ystart, font_head, "Driver");
3847 DrawTextF(xstart2, ystart, font_head, "Requested");
3848 DrawTextF(xstart3, ystart, font_head, "Used");
3849 ystart += ystep_head;
3852 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3854 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3855 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3856 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3857 ystart += ystep_line;
3860 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3862 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3863 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3864 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3865 ystart += ystep_line;
3868 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3870 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3871 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3872 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3874 DrawTextSCentered(ybottom, font_foot,
3875 "Press any key or button for info menu");
3877 FadeIn(REDRAW_FIELD);
3880 void HandleInfoScreen_Version(int button)
3882 if (button == MB_MENU_LEAVE)
3884 PlaySound(SND_MENU_ITEM_SELECTING);
3886 info_mode = INFO_MODE_MAIN;
3891 else if (button == MB_MENU_CHOICE)
3893 PlaySound(SND_MENU_ITEM_SELECTING);
3895 FadeMenuSoundsAndMusic();
3897 info_mode = INFO_MODE_MAIN;
3902 PlayMenuSoundIfLoop();
3906 static void DrawInfoScreen_LevelSet(void)
3908 struct TitleMessageInfo *tmi = &readme;
3909 char *filename = getLevelSetInfoFilename();
3910 char *title = "Level Set Information:";
3911 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3912 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3914 if (filename == NULL)
3916 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3921 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3923 FadeOut(REDRAW_FIELD);
3928 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3930 // if x position set to "-1", automatically determine by playfield width
3932 tmi->x = SXSIZE / 2;
3934 // if y position set to "-1", use static default value
3938 // if width set to "-1", automatically determine by playfield width
3939 if (tmi->width == -1)
3940 tmi->width = SXSIZE - 2 * TILEX;
3942 // if height set to "-1", automatically determine by playfield height
3943 if (tmi->height == -1)
3944 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3946 // if chars set to "-1", automatically determine by text and font width
3947 if (tmi->chars == -1)
3948 tmi->chars = tmi->width / getFontWidth(tmi->font);
3950 tmi->width = tmi->chars * getFontWidth(tmi->font);
3952 // if lines set to "-1", automatically determine by text and font height
3953 if (tmi->lines == -1)
3954 tmi->lines = tmi->height / getFontHeight(tmi->font);
3956 tmi->height = tmi->lines * getFontHeight(tmi->font);
3958 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3959 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3960 tmi->autowrap, tmi->centered, tmi->parse_comments);
3962 DrawTextSCentered(ybottom, FONT_TEXT_4,
3963 "Press any key or button for info menu");
3965 FadeIn(REDRAW_FIELD);
3968 static void HandleInfoScreen_LevelSet(int button)
3970 if (button == MB_MENU_LEAVE)
3972 PlaySound(SND_MENU_ITEM_SELECTING);
3974 info_mode = INFO_MODE_MAIN;
3979 else if (button == MB_MENU_CHOICE)
3981 PlaySound(SND_MENU_ITEM_SELECTING);
3983 FadeMenuSoundsAndMusic();
3985 info_mode = INFO_MODE_MAIN;
3990 PlayMenuSoundIfLoop();
3994 static void DrawInfoScreen(void)
3996 if (info_mode == INFO_MODE_TITLE)
3997 DrawInfoScreen_TitleScreen();
3998 else if (info_mode == INFO_MODE_ELEMENTS)
3999 DrawInfoScreen_Elements();
4000 else if (info_mode == INFO_MODE_MUSIC)
4001 DrawInfoScreen_Music();
4002 else if (info_mode == INFO_MODE_CREDITS)
4003 DrawInfoScreen_Credits();
4004 else if (info_mode == INFO_MODE_PROGRAM)
4005 DrawInfoScreen_Program();
4006 else if (info_mode == INFO_MODE_VERSION)
4007 DrawInfoScreen_Version();
4008 else if (info_mode == INFO_MODE_LEVELSET)
4009 DrawInfoScreen_LevelSet();
4011 DrawInfoScreen_Main();
4013 if (info_mode != INFO_MODE_MAIN &&
4014 info_mode != INFO_MODE_TITLE &&
4015 info_mode != INFO_MODE_MUSIC)
4016 PlayMenuSoundsAndMusic();
4019 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4021 if (info_mode == INFO_MODE_TITLE)
4022 HandleInfoScreen_TitleScreen(button);
4023 else if (info_mode == INFO_MODE_ELEMENTS)
4024 HandleInfoScreen_Elements(button);
4025 else if (info_mode == INFO_MODE_MUSIC)
4026 HandleInfoScreen_Music(button);
4027 else if (info_mode == INFO_MODE_CREDITS)
4028 HandleInfoScreen_Credits(button);
4029 else if (info_mode == INFO_MODE_PROGRAM)
4030 HandleInfoScreen_Program(button);
4031 else if (info_mode == INFO_MODE_VERSION)
4032 HandleInfoScreen_Version(button);
4033 else if (info_mode == INFO_MODE_LEVELSET)
4034 HandleInfoScreen_LevelSet(button);
4036 HandleInfoScreen_Main(mx, my, dx, dy, button);
4040 // ============================================================================
4041 // change name functions
4042 // ============================================================================
4044 static void RenamePlayerOnServerExt(struct HttpRequest *request,
4045 struct HttpResponse *response,
4046 char *player_name_raw,
4047 char *player_uuid_raw)
4049 request->hostname = setup.api_server_hostname;
4050 request->port = API_SERVER_PORT;
4051 request->method = API_SERVER_METHOD;
4052 request->uri = API_SERVER_URI_RENAME;
4054 char *player_name = getEscapedJSON(player_name_raw);
4055 char *player_uuid = getEscapedJSON(player_uuid_raw);
4057 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4060 " \"game_version\": \"%s\",\n"
4061 " \"name\": \"%s\",\n"
4062 " \"uuid\": \"%s\"\n"
4064 getPasswordJSON(setup.api_server_password),
4065 getProgramRealVersionString(),
4069 checked_free(player_name);
4070 checked_free(player_uuid);
4072 ConvertHttpRequestBodyToServerEncoding(request);
4074 if (!DoHttpRequest(request, response))
4076 Error("HTTP request failed: %s", GetHttpError());
4081 if (!HTTP_SUCCESS(response->status_code))
4083 Error("server failed to handle request: %d %s",
4084 response->status_code,
4085 response->status_text);
4091 static void RenamePlayerOnServer(char *player_name, char *player_uuid)
4093 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4094 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4096 RenamePlayerOnServerExt(request, response, player_name, player_uuid);
4098 checked_free(request);
4099 checked_free(response);
4102 struct RenamePlayerOnServerThreadData
4108 static int RenamePlayerOnServerThread(void *data_raw)
4110 struct RenamePlayerOnServerThreadData *data = data_raw;
4112 RenamePlayerOnServer(data->player_name, data->player_uuid);
4114 checked_free(data->player_name);
4115 checked_free(data->player_uuid);
4121 static void RenamePlayerOnServerAsThread(void)
4123 struct RenamePlayerOnServerThreadData *data =
4124 checked_malloc(sizeof(struct RenamePlayerOnServerThreadData));
4126 data->player_name = getStringCopy(setup.player_name);
4127 data->player_uuid = getStringCopy(setup.player_uuid);
4129 ExecuteAsThread(RenamePlayerOnServerThread,
4130 "RenamePlayerOnServer", data,
4131 "rename player on server");
4135 // ============================================================================
4136 // type name functions
4137 // ============================================================================
4139 static TreeInfo *type_name_node = NULL;
4140 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4141 static int type_name_nr = 0;
4143 static int getPlayerNameColor(char *name)
4145 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4148 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4151 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4152 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4153 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4154 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4155 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4156 int font_width = getFontWidth(font_nr);
4158 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4160 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4162 pos->width = strlen(text) * font_width;
4163 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4165 DrawText(sx, sy, text, font_nr);
4168 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4170 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4172 *pos = *mci->pos_input;
4174 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4176 TreeInfo *ti = player_name_current;
4177 int first_entry = ti->cl_first;
4178 int entry_pos = first_entry + ti->cl_cursor;
4179 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4180 int xpos = MENU_SCREEN_START_XPOS;
4181 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4183 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4184 type_name_nr = entry_pos;
4186 strcpy(name, type_name_node->name);
4190 pos->width = MAX_PLAYER_NAME_LEN * 32;
4194 type_name_nr = user.nr;
4196 strcpy(name, setup.player_name);
4199 strcpy(type_name_last, name);
4201 if (strEqual(name, EMPTY_PLAYER_NAME))
4204 *xpos = strlen(name);
4207 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4209 // change name of edited user in global list of user names
4210 setString(&global.user_names[type_name_nr], name);
4212 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4214 TreeInfo *node = type_name_node;
4216 // change name of edited user in local menu tree structure
4217 setString(&node->name, name);
4218 setString(&node->name_sorting, name);
4220 node->color = getPlayerNameColor(name);
4221 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4225 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4228 boolean reset_setup = strEqual(name, "");
4229 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4230 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4233 strcpy(name, type_name_last);
4235 if (strEqual(name, ""))
4236 strcpy(name, EMPTY_PLAYER_NAME);
4238 setTypeNameValues_Name(name, pos);
4240 // if player name not changed, no further action required
4241 if (strEqual(name, type_name_last))
4244 // redraw player name before (possibly) opening request dialogs
4245 drawTypeNameText(name, pos, FALSE);
4247 int last_user_nr = user.nr;
4249 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4251 // save setup of currently active user (may differ from edited user)
4254 // temporarily change active user to edited user
4255 user.nr = type_name_nr;
4257 // load setup of edited user (unless creating user with current setup)
4259 !Request("Use current setup values for the new player?", REQ_ASK))
4263 char *setup_filename = getSetupFilename();
4264 boolean setup_exists = fileExists(setup_filename);
4266 // change name of edited user in setup structure
4267 strcpy(setup.player_name, name);
4269 // save setup of edited user
4272 // change name of edited user on score server
4273 RenamePlayerOnServerAsThread();
4275 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4279 if (Request("Reset setup values for this player?", REQ_ASK))
4281 // remove setup config file
4282 unlink(setup_filename);
4284 // set player name to default player name
4287 // update player name used by name typing functions
4288 strcpy(name, setup.player_name);
4290 setTypeNameValues_Name(name, pos);
4293 else if (remove_user && type_name_nr != 0)
4295 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4297 char *user_dir = getUserGameDataDir();
4298 char *user_dir_removed =
4299 getStringCat3WithSeparator(user_dir, "REMOVED",
4300 getCurrentTimestamp(), ".");
4302 if (rename(user_dir, user_dir_removed) != 0)
4303 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4305 checked_free(user_dir_removed);
4308 else if (create_user && type_name_nr != 0 && !setup_exists)
4310 if (Request("Create empty level set for the new player?", REQ_ASK))
4312 char *levelset_subdir = getNewUserLevelSubdir();
4314 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4316 AddUserLevelSetToLevelInfo(levelset_subdir);
4318 LevelDirTree *leveldir_current_last = leveldir_current;
4320 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4323 // set level number of newly created level set to default value
4324 LoadLevelSetup_SeriesInfo();
4326 // set newly created level set as current level set for new user
4327 SaveLevelSetup_LastSeries();
4328 SaveLevelSetup_SeriesInfo();
4330 leveldir_current = leveldir_current_last;
4334 Request("Creating new level set failed!", REQ_CONFIRM);
4339 // restore currently active user
4340 user.nr = last_user_nr;
4342 // restore setup of currently active user
4345 // restore last level set of currently active user
4346 LoadLevelSetup_LastSeries();
4347 LoadLevelSetup_SeriesInfo();
4351 static void HandleTypeNameExt(boolean initialize, Key key)
4353 static struct TextPosInfo pos_name = { 0 };
4354 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4355 static int xpos = 0;
4356 struct TextPosInfo *pos = &pos_name;
4357 char key_char = getValidConfigValueChar(getCharFromKey(key));
4358 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4359 boolean active = TRUE;
4363 getTypeNameValues(name, pos, &xpos);
4365 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4366 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4368 StartTextInput(sx, sy, pos->width, pos->height);
4370 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4372 name[xpos] = key_char;
4377 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4383 else if (key == KSYM_Return || key == KSYM_Escape)
4385 boolean changed = (key == KSYM_Return);
4389 setTypeNameValues(name, pos, changed);
4394 drawTypeNameText(name, pos, active);
4398 SetGameStatus(game_status_last_screen);
4400 if (game_status == GAME_MODE_MAIN)
4401 InitializeMainControls();
4405 static void DrawTypeName(void)
4407 HandleTypeNameExt(TRUE, 0);
4410 void HandleTypeName(Key key)
4412 HandleTypeNameExt(FALSE, key);
4416 // ============================================================================
4417 // tree menu functions
4418 // ============================================================================
4420 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4422 if (game_status != GAME_MODE_SETUP ||
4423 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4426 int max_text_size = 0;
4429 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4430 max_text_size = MAX(max_text_size, strlen(node->name));
4432 int num_entries = numTreeInfoInGroup(ti);
4433 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4434 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4435 int text_width = max_text_size * getFontWidth(font_nr);
4436 int button_width = SC_MENUBUTTON_XSIZE;
4437 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4438 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4439 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4440 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4441 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4442 int align_xoffset = MAX(0, align_xoffset_raw);
4444 return align_xoffset;
4447 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4449 if (game_status != GAME_MODE_SETUP ||
4450 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4453 int num_entries = numTreeInfoInGroup(ti);
4454 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4455 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4456 int font_height = getFontHeight(font_nr);
4457 int text_height = font_height * num_page_entries;
4458 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4459 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4460 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4461 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4462 int align_yoffset = MAX(0, align_yoffset_raw);
4464 return align_yoffset;
4467 static void DrawChooseTree(TreeInfo **ti_ptr)
4469 int fade_mask = REDRAW_FIELD;
4472 fade_mask = REDRAW_ALL;
4474 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4476 if (game_status == GAME_MODE_SETUP)
4480 else // GAME_MODE_LEVELS
4482 SetGameStatus(GAME_MODE_MAIN);
4492 FreeScreenGadgets();
4493 CreateScreenGadgets();
4497 // needed if different viewport properties defined for choosing level (set)
4498 ChangeViewportPropertiesIfNeeded();
4500 if (game_status == GAME_MODE_NAMES)
4501 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4502 else if (game_status == GAME_MODE_LEVELNR)
4503 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4504 else if (game_status == GAME_MODE_LEVELS)
4505 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4509 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4511 MapScreenTreeGadgets(*ti_ptr);
4512 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4514 DrawMaskedBorder(fade_mask);
4519 static void drawChooseTreeText(int y, boolean active, TreeInfo *ti)
4521 int num_entries = numTreeInfoInGroup(ti);
4522 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4523 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4524 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4525 int first_entry = ti->cl_first;
4526 int entry_pos = first_entry + y;
4527 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4528 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4529 int font_color = MENU_CHOOSE_TREE_COLOR(node, active);
4530 int font_nr = MENU_CHOOSE_TREE_FONT(font_color);
4531 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4532 int xpos = MENU_SCREEN_START_XPOS;
4533 int ypos = MENU_SCREEN_START_YPOS + y;
4534 int startx = amSX + xpos * 32;
4535 int starty = amSY + ypos * 32;
4536 int startx_text = startx + font_xoffset;
4537 int endx_text = amSX + screen_width;
4538 int max_text_size = endx_text - startx_text;
4539 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4540 char buffer[max_buffer_len + 1];
4542 strncpy(buffer, node->name, max_buffer_len);
4543 buffer[max_buffer_len] = '\0';
4545 DrawText(startx, starty, buffer, font_nr);
4548 static void drawChooseTreeList(int first_entry, int num_page_entries,
4552 char *title_string = NULL;
4553 int yoffset_sets = MENU_TITLE1_YPOS;
4554 int yoffset_setup = 16;
4555 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4556 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4558 title_string = ti->infotext;
4560 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4562 clearMenuListArea();
4564 for (i = 0; i < num_page_entries; i++)
4566 TreeInfo *node, *node_first;
4567 int entry_pos = first_entry + i;
4569 node_first = getTreeInfoFirstGroupEntry(ti);
4570 node = getTreeInfoFromPos(node_first, entry_pos);
4572 drawChooseTreeText(i, FALSE, ti);
4574 if (node->parent_link)
4575 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4576 else if (node->level_group)
4577 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4579 initCursor(i, IMG_MENU_BUTTON);
4581 if (game_status == GAME_MODE_NAMES)
4582 drawChooseTreeEdit(i, FALSE);
4585 redraw_mask |= REDRAW_FIELD;
4588 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4590 TreeInfo *node, *node_first;
4591 int x, last_redraw_mask = redraw_mask;
4592 int ypos = MENU_TITLE2_YPOS;
4593 int font_nr = FONT_TITLE_2;
4595 if (ti->type == TREE_TYPE_LEVEL_NR)
4596 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4598 if (ti->type != TREE_TYPE_LEVEL_DIR)
4601 node_first = getTreeInfoFirstGroupEntry(ti);
4602 node = getTreeInfoFromPos(node_first, entry_pos);
4604 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4606 if (node->parent_link)
4607 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4608 node->node_parent->name);
4609 else if (node->level_group)
4610 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4612 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4613 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4614 node->levels, (node->levels > 1 ? "levels" : "level"),
4617 // let BackToFront() redraw only what is needed
4618 redraw_mask = last_redraw_mask;
4619 for (x = 0; x < SCR_FIELDX; x++)
4620 MarkTileDirty(x, 1);
4623 static void drawChooseTreeCursorAndText(int y, boolean active, TreeInfo *ti)
4625 drawChooseTreeCursor(y, active);
4626 drawChooseTreeText(y, active, ti);
4629 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4632 TreeInfo *ti = *ti_ptr;
4633 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4634 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4635 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4636 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4637 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4639 int y = ti->cl_cursor;
4640 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4641 int num_entries = numTreeInfoInGroup(ti);
4642 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4643 boolean position_set_by_scrollbar = (dx == 999);
4645 if (button == MB_MENU_INITIALIZE)
4647 int num_entries = numTreeInfoInGroup(ti);
4648 int entry_pos = getPosFromTreeInfo(ti);
4650 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4651 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4653 if (ti->cl_first == -1)
4655 // only on initialization
4656 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4657 ti->cl_cursor = entry_pos - ti->cl_first;
4659 else if (ti->cl_cursor >= num_page_entries ||
4660 (num_entries > num_page_entries &&
4661 num_entries - ti->cl_first < num_page_entries))
4663 // only after change of list size (by custom graphic configuration)
4664 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4665 ti->cl_cursor = entry_pos - ti->cl_first;
4668 if (position_set_by_scrollbar)
4671 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4674 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4675 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4676 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4680 else if (button == MB_MENU_LEAVE)
4684 PlaySound(SND_MENU_ITEM_SELECTING);
4686 if (ti->node_parent)
4688 *ti_ptr = ti->node_parent;
4689 DrawChooseTree(ti_ptr);
4691 else if (game_status == GAME_MODE_SETUP)
4693 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4694 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4695 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4697 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4698 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4699 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4700 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4701 execSetupGraphics();
4702 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4703 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4704 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4706 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4707 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4708 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4709 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4710 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4711 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4712 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4713 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4720 if (game_status == GAME_MODE_LEVELNR)
4722 int new_level_nr = atoi(level_number_current->identifier);
4724 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4727 SetGameStatus(GAME_MODE_MAIN);
4735 if (mx || my) // mouse input
4737 x = (mx - amSX) / 32;
4738 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4740 if (game_status == GAME_MODE_NAMES)
4741 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4743 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4745 // move cursor instead of scrolling when already at start/end of list
4746 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4748 else if (dy == +1 * SCROLL_LINE &&
4749 ti->cl_first + num_page_entries == num_entries)
4752 // handle scrolling screen one line or page
4753 if (ti->cl_cursor + dy < 0 ||
4754 ti->cl_cursor + dy > num_page_entries - 1)
4756 boolean redraw = FALSE;
4758 if (ABS(dy) == SCROLL_PAGE)
4759 step = num_page_entries - 1;
4761 if (dy < 0 && ti->cl_first > 0)
4763 // scroll page/line up
4765 ti->cl_first -= step;
4766 if (ti->cl_first < 0)
4771 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4773 // scroll page/line down
4775 ti->cl_first += step;
4776 if (ti->cl_first + num_page_entries > num_entries)
4777 ti->cl_first = MAX(0, num_entries - num_page_entries);
4784 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4785 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4786 drawChooseTreeCursorAndText(ti->cl_cursor, TRUE, ti);
4788 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4795 // handle moving cursor one line
4796 y = ti->cl_cursor + dy;
4801 TreeInfo *node_first, *node_cursor;
4802 int entry_pos = ti->cl_first + y;
4804 node_first = getTreeInfoFirstGroupEntry(ti);
4805 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4807 if (node_cursor->node_group)
4811 PlaySound(SND_MENU_ITEM_SELECTING);
4813 node_cursor->cl_first = ti->cl_first;
4814 node_cursor->cl_cursor = ti->cl_cursor;
4815 *ti_ptr = node_cursor->node_group;
4816 DrawChooseTree(ti_ptr);
4821 else if (dx == -1 && ti->node_parent)
4825 PlaySound(SND_MENU_ITEM_SELECTING);
4827 *ti_ptr = ti->node_parent;
4828 DrawChooseTree(ti_ptr);
4833 if (!anyScrollbarGadgetActive() &&
4834 IN_VIS_MENU(x, y) &&
4835 mx < mx_right_border &&
4836 y >= 0 && y < num_page_entries)
4840 if (game_status == GAME_MODE_NAMES)
4842 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4843 drawChooseTreeEdit(y, TRUE);
4846 if (y != ti->cl_cursor)
4848 PlaySound(SND_MENU_ITEM_ACTIVATING);
4850 drawChooseTreeCursorAndText(ti->cl_cursor, FALSE, ti);
4851 drawChooseTreeCursorAndText(y, TRUE, ti);
4852 drawChooseTreeInfo(ti->cl_first + y, ti);
4858 if (game_status == GAME_MODE_SETUP)
4860 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4861 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4862 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4864 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4865 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4866 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4867 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4868 execSetupGraphics();
4869 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4870 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4871 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4873 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4874 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4875 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4876 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4877 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4878 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4879 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4880 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4889 TreeInfo *node_first, *node_cursor;
4890 int entry_pos = ti->cl_first + y;
4892 PlaySound(SND_MENU_ITEM_SELECTING);
4894 node_first = getTreeInfoFirstGroupEntry(ti);
4895 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4897 if (node_cursor->node_group)
4901 node_cursor->cl_first = ti->cl_first;
4902 node_cursor->cl_cursor = ti->cl_cursor;
4903 *ti_ptr = node_cursor->node_group;
4904 DrawChooseTree(ti_ptr);
4906 else if (node_cursor->parent_link)
4910 *ti_ptr = node_cursor->node_parent;
4911 DrawChooseTree(ti_ptr);
4917 node_cursor->cl_first = ti->cl_first;
4918 node_cursor->cl_cursor = ti->cl_cursor;
4919 *ti_ptr = node_cursor;
4921 if (ti->type == TREE_TYPE_LEVEL_DIR)
4923 LoadLevelSetup_SeriesInfo();
4925 SaveLevelSetup_LastSeries();
4926 SaveLevelSetup_SeriesInfo();
4930 if (game_status == GAME_MODE_SETUP)
4932 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4933 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4934 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4936 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4937 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4938 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4939 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4940 execSetupGraphics();
4941 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4942 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4943 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4945 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4946 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4947 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4948 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4949 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4950 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4951 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4952 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4959 if (game_status == GAME_MODE_LEVELNR)
4961 int new_level_nr = atoi(level_number_current->identifier);
4963 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4965 else if (game_status == GAME_MODE_LEVELS)
4967 // store level set if chosen from "last played level set" menu
4968 StoreLastPlayedLevels(leveldir_current);
4970 else if (game_status == GAME_MODE_NAMES)
4972 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4974 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
4981 // change active user to selected user
4982 user.nr = entry_pos;
4984 // save number of new active user
4987 // load setup of new active user
4990 // load last level set of new active user
4991 LoadLevelSetup_LastSeries();
4992 LoadLevelSetup_SeriesInfo();
4994 // update list of last played level sets
4995 UpdateLastPlayedLevels_TreeInfo();
4999 ToggleFullscreenIfNeeded();
5000 ChangeWindowScalingIfNeeded();
5002 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5003 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5004 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5007 SetGameStatus(GAME_MODE_MAIN);
5016 void DrawChoosePlayerName(void)
5020 FadeMenuSoundsAndMusic();
5022 if (player_name != NULL)
5024 freeTreeInfo(player_name);
5029 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5031 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5032 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5035 ti->node_top = &player_name;
5036 ti->sort_priority = 10000 + value;
5037 ti->color = getPlayerNameColor(global.user_names[i]);
5039 snprintf(identifier, sizeof(identifier), "%d", value);
5040 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5042 setString(&ti->identifier, identifier);
5043 setString(&ti->name, name);
5044 setString(&ti->name_sorting, name);
5046 pushTreeInfo(&player_name, ti);
5049 // sort player entries by player number
5050 sortTreeInfo(&player_name);
5052 // set current player entry to selected player entry
5053 player_name_current =
5054 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5056 // if that fails, set current player name to first available name
5057 if (player_name_current == NULL)
5058 player_name_current = player_name;
5060 DrawChooseTree(&player_name_current);
5062 PlayMenuSoundsAndMusic();
5065 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5067 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5070 void DrawChooseLevelSet(void)
5072 FadeMenuSoundsAndMusic();
5074 DrawChooseTree(&leveldir_current);
5076 PlayMenuSoundsAndMusic();
5079 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5081 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5084 void DrawChooseLevelNr(void)
5088 FadeMenuSoundsAndMusic();
5090 if (level_number != NULL)
5092 freeTreeInfo(level_number);
5094 level_number = NULL;
5097 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5099 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5100 char identifier[32], name[64];
5103 // temporarily load level info to get level name
5104 LoadLevelInfoOnly(i);
5106 ti->node_top = &level_number;
5107 ti->sort_priority = 10000 + value;
5108 ti->color = (level.no_level_file ? FC_BLUE :
5109 LevelStats_getSolved(i) ? FC_GREEN :
5110 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5112 snprintf(identifier, sizeof(identifier), "%d", value);
5113 snprintf(name, sizeof(name), "%03d: %s", value,
5114 (level.no_level_file ? "(no file)" : level.name));
5116 setString(&ti->identifier, identifier);
5117 setString(&ti->name, name);
5118 setString(&ti->name_sorting, name);
5120 pushTreeInfo(&level_number, ti);
5123 // sort level number values to start with lowest level number
5124 sortTreeInfo(&level_number);
5126 // set current level number to current level number
5127 level_number_current =
5128 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5130 // if that also fails, set current level number to first available level
5131 if (level_number_current == NULL)
5132 level_number_current = level_number;
5134 DrawChooseTree(&level_number_current);
5136 PlayMenuSoundsAndMusic();
5139 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5141 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5144 void DrawHallOfFame(int level_nr)
5146 int fade_mask = REDRAW_FIELD;
5149 fade_mask = REDRAW_ALL;
5152 FadeMenuSoundsAndMusic();
5154 // (this is needed when called from GameEnd() after winning a game)
5155 KeyboardAutoRepeatOn();
5157 // (this is needed when called from GameEnd() after winning a game)
5158 SetDrawDeactivationMask(REDRAW_NONE);
5159 SetDrawBackgroundMask(REDRAW_FIELD);
5161 LoadLocalAndServerScore(level_nr, TRUE);
5163 if (scores.last_added >= 0)
5164 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5166 FadeSetEnterScreen();
5170 // needed if different viewport properties defined for scores
5171 ChangeViewportPropertiesIfNeeded();
5173 PlayMenuSoundsAndMusic();
5175 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5177 HandleHallOfFame(level_nr, 0, 0, 0, MB_MENU_INITIALIZE);
5179 DrawMaskedBorder(fade_mask);
5184 static int getHallOfFameFirstEntry(int first_entry, int step)
5187 first_entry = scores.last_added - (NUM_MENU_ENTRIES_ON_SCREEN + 1) / 2 + 1;
5189 first_entry += step;
5191 if (first_entry < 0)
5193 else if (first_entry > MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN)
5194 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
5199 static char *getHallOfFameScoreText(int nr)
5201 if (!level.rate_time_over_score)
5202 return int2str(scores.entry[nr].score, 5); // show normal score
5204 if (level.use_step_counter)
5205 return int2str(scores.entry[nr].time, 5); // show number of steps
5207 static char score_text[10];
5208 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5209 int mm = (time_seconds / 60) % 60;
5210 int ss = (time_seconds % 60);
5212 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5217 static void drawHallOfFameList(int level_nr, int first_entry)
5221 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5224 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
5225 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
5226 "HighScores of Level %d", level_nr);
5228 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5230 int entry = first_entry + i;
5231 boolean active = (entry == scores.last_added);
5232 boolean forced = (scores.force_last_added && active);
5233 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
5234 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
5235 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
5236 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
5237 int dxoff = getFontDrawOffsetX(font_nr1);
5238 int dx1 = 3 * getFontWidth(font_nr1);
5239 int dx2 = dx1 + getFontWidth(font_nr1);
5240 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
5241 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
5242 int sy = mSY + 64 + i * 32;
5243 char *pos_text = (forced ? "???" : int2str(entry + 1, 3));
5245 DrawText(mSX, sy, pos_text, font_nr1);
5246 DrawText(mSX + dx1, sy, ".", font_nr1);
5248 for (j = 0; j < num_dots; j++)
5249 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
5251 if (!strEqual(scores.entry[entry].name, EMPTY_PLAYER_NAME))
5252 DrawText(mSX + dx2, sy, scores.entry[entry].name, font_nr2);
5254 DrawText(mSX + dx3, sy, getHallOfFameScoreText(entry), font_nr4);
5257 redraw_mask |= REDRAW_FIELD;
5260 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5262 static int level_nr = 0;
5263 static int first_entry = 0;
5264 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5266 if (button == MB_MENU_INITIALIZE)
5270 if (server_scores.updated)
5272 // reload scores, using updated server score cache file
5273 LoadLocalAndServerScore(level_nr, FALSE);
5275 server_scores.updated = FALSE;
5278 first_entry = getHallOfFameFirstEntry(0, 0);
5280 drawHallOfFameList(level_nr, first_entry);
5285 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
5286 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
5290 first_entry = getHallOfFameFirstEntry(first_entry, -step);
5292 drawHallOfFameList(level_nr, first_entry);
5296 first_entry = getHallOfFameFirstEntry(first_entry, step);
5298 drawHallOfFameList(level_nr, first_entry);
5300 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5302 PlaySound(SND_MENU_ITEM_SELECTING);
5304 FadeSound(SND_BACKGROUND_SCORES);
5306 if (button == MB_MENU_CHOICE &&
5307 game_status_last_screen == GAME_MODE_PLAYING &&
5308 setup.auto_play_next_level && setup.increment_levels &&
5309 level_nr < leveldir_current->last_level &&
5312 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
5316 SetGameStatus(GAME_MODE_MAIN);
5321 else if (server_scores.updated)
5323 // reload scores, using updated server score cache file
5324 LoadLocalAndServerScore(level_nr, FALSE);
5326 server_scores.updated = FALSE;
5328 first_entry = getHallOfFameFirstEntry(0, 0);
5330 drawHallOfFameList(level_nr, first_entry);
5333 if (game_status == GAME_MODE_SCORES)
5334 PlayMenuSoundIfLoop();
5338 // ============================================================================
5339 // setup screen functions
5340 // ============================================================================
5342 static struct TokenInfo *setup_info;
5343 static int num_setup_info; // number of setup entries shown on screen
5344 static int max_setup_info; // total number of setup entries in list
5346 static char *window_size_text;
5347 static char *scaling_type_text;
5348 static char *rendering_mode_text;
5349 static char *vsync_mode_text;
5350 static char *scroll_delay_text;
5351 static char *snapshot_mode_text;
5352 static char *game_speed_text;
5353 static char *network_server_text;
5354 static char *graphics_set_name;
5355 static char *sounds_set_name;
5356 static char *music_set_name;
5357 static char *volume_simple_text;
5358 static char *volume_loops_text;
5359 static char *volume_music_text;
5360 static char *touch_controls_text;
5361 static char *move_distance_text;
5362 static char *drop_distance_text;
5363 static char *transparency_text;
5364 static char *grid_size_text[2][2];
5366 static void execSetupMain(void)
5368 setup_mode = SETUP_MODE_MAIN;
5373 static void execSetupGame_setGameSpeeds(boolean update_value)
5375 if (setup.game_speed_extended)
5377 game_speeds_list = game_speeds_list_extended;
5378 game_speeds = game_speeds_extended;
5382 game_speeds_list = game_speeds_list_normal;
5383 game_speeds = game_speeds_normal;
5386 if (game_speeds == NULL)
5390 for (i = 0; game_speeds_list[i].value != -1; i++)
5392 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5393 char identifier[32], name[32];
5394 int value = game_speeds_list[i].value;
5395 char *text = game_speeds_list[i].text;
5397 ti->node_top = &game_speeds;
5398 ti->sort_priority = 10000 - value;
5400 sprintf(identifier, "%d", value);
5401 sprintf(name, "%s", text);
5403 setString(&ti->identifier, identifier);
5404 setString(&ti->name, name);
5405 setString(&ti->name_sorting, name);
5406 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5408 pushTreeInfo(&game_speeds, ti);
5411 // sort game speed values to start with slowest game speed
5412 sortTreeInfo(&game_speeds);
5414 update_value = TRUE;
5419 // set current game speed to configured game speed value
5420 game_speed_current =
5421 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5423 // if that fails, set current game speed to reliable default value
5424 if (game_speed_current == NULL)
5425 game_speed_current =
5426 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5428 // if that also fails, set current game speed to first available speed
5429 if (game_speed_current == NULL)
5430 game_speed_current = game_speeds;
5432 if (setup.game_speed_extended)
5433 game_speeds_extended = game_speeds;
5435 game_speeds_normal = game_speeds;
5438 setup.game_frame_delay = atoi(game_speed_current->identifier);
5440 // needed for displaying game speed text instead of identifier
5441 game_speed_text = game_speed_current->name;
5444 static void execSetupGame_setScrollDelays(void)
5446 if (scroll_delays == NULL)
5450 for (i = 0; scroll_delays_list[i].value != -1; i++)
5452 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5453 char identifier[32], name[32];
5454 int value = scroll_delays_list[i].value;
5455 char *text = scroll_delays_list[i].text;
5457 ti->node_top = &scroll_delays;
5458 ti->sort_priority = value;
5460 sprintf(identifier, "%d", value);
5461 sprintf(name, "%s", text);
5463 setString(&ti->identifier, identifier);
5464 setString(&ti->name, name);
5465 setString(&ti->name_sorting, name);
5466 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5468 pushTreeInfo(&scroll_delays, ti);
5471 // sort scroll delay values to start with lowest scroll delay value
5472 sortTreeInfo(&scroll_delays);
5474 // set current scroll delay value to configured scroll delay value
5475 scroll_delay_current =
5476 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5478 // if that fails, set current scroll delay to reliable default value
5479 if (scroll_delay_current == NULL)
5480 scroll_delay_current =
5481 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5483 // if that also fails, set current scroll delay to first available value
5484 if (scroll_delay_current == NULL)
5485 scroll_delay_current = scroll_delays;
5488 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5490 // needed for displaying scroll delay text instead of identifier
5491 scroll_delay_text = scroll_delay_current->name;
5494 static void execSetupGame_setSnapshotModes(void)
5496 if (snapshot_modes == NULL)
5500 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5502 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5503 char identifier[32], name[32];
5504 char *value = snapshot_modes_list[i].value;
5505 char *text = snapshot_modes_list[i].text;
5507 ti->node_top = &snapshot_modes;
5508 ti->sort_priority = i;
5510 sprintf(identifier, "%s", value);
5511 sprintf(name, "%s", text);
5513 setString(&ti->identifier, identifier);
5514 setString(&ti->name, name);
5515 setString(&ti->name_sorting, name);
5516 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5518 pushTreeInfo(&snapshot_modes, ti);
5521 // sort snapshot mode values to start with lowest snapshot mode value
5522 sortTreeInfo(&snapshot_modes);
5524 // set current snapshot mode value to configured snapshot mode value
5525 snapshot_mode_current =
5526 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5528 // if that fails, set current snapshot mode to reliable default value
5529 if (snapshot_mode_current == NULL)
5530 snapshot_mode_current =
5531 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5533 // if that also fails, set current snapshot mode to first available value
5534 if (snapshot_mode_current == NULL)
5535 snapshot_mode_current = snapshot_modes;
5538 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5540 // needed for displaying snapshot mode text instead of identifier
5541 snapshot_mode_text = snapshot_mode_current->name;
5544 static void execSetupGame_setNetworkServerText(void)
5546 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5548 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5552 strncpy(network_server_hostname, setup.network_server_hostname,
5553 MAX_SETUP_TEXT_INPUT_LEN);
5554 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5557 // needed for displaying network server text instead of identifier
5558 network_server_text = network_server_hostname;
5561 static void execSetupGame(void)
5563 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5565 execSetupGame_setGameSpeeds(FALSE);
5566 execSetupGame_setScrollDelays();
5567 execSetupGame_setSnapshotModes();
5569 execSetupGame_setNetworkServerText();
5571 setup_mode = SETUP_MODE_GAME;
5575 // check if vsync needs to be disabled for this game speed to work
5576 if (check_vsync_mode)
5577 DisableVsyncIfNeeded();
5580 static void execSetupChooseGameSpeed(void)
5582 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5587 static void execSetupChooseScrollDelay(void)
5589 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5594 static void execSetupChooseSnapshotMode(void)
5596 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5601 static void execSetupEngines(void)
5603 setup_mode = SETUP_MODE_ENGINES;
5608 static void execSetupEditor(void)
5610 setup_mode = SETUP_MODE_EDITOR;
5615 static void execSetupGraphics_setWindowSizes(boolean update_list)
5617 if (window_sizes != NULL && update_list)
5619 freeTreeInfo(window_sizes);
5621 window_sizes = NULL;
5624 if (window_sizes == NULL)
5626 boolean current_window_size_found = FALSE;
5629 for (i = 0; window_sizes_list[i].value != -1; i++)
5631 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5632 char identifier[32], name[32];
5633 int value = window_sizes_list[i].value;
5634 char *text = window_sizes_list[i].text;
5636 ti->node_top = &window_sizes;
5637 ti->sort_priority = value;
5639 sprintf(identifier, "%d", value);
5640 sprintf(name, "%s", text);
5642 setString(&ti->identifier, identifier);
5643 setString(&ti->name, name);
5644 setString(&ti->name_sorting, name);
5645 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5647 pushTreeInfo(&window_sizes, ti);
5649 if (value == setup.window_scaling_percent)
5650 current_window_size_found = TRUE;
5653 if (!current_window_size_found)
5655 // add entry for non-preset window scaling value
5657 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5658 char identifier[32], name[32];
5659 int value = setup.window_scaling_percent;
5661 ti->node_top = &window_sizes;
5662 ti->sort_priority = value;
5664 sprintf(identifier, "%d", value);
5665 sprintf(name, "%d %% (Current)", value);
5667 setString(&ti->identifier, identifier);
5668 setString(&ti->name, name);
5669 setString(&ti->name_sorting, name);
5670 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5672 pushTreeInfo(&window_sizes, ti);
5675 // sort window size values to start with lowest window size value
5676 sortTreeInfo(&window_sizes);
5678 // set current window size value to configured window size value
5679 window_size_current =
5680 getTreeInfoFromIdentifier(window_sizes,
5681 i_to_a(setup.window_scaling_percent));
5683 // if that fails, set current window size to reliable default value
5684 if (window_size_current == NULL)
5685 window_size_current =
5686 getTreeInfoFromIdentifier(window_sizes,
5687 i_to_a(STD_WINDOW_SCALING_PERCENT));
5689 // if that also fails, set current window size to first available value
5690 if (window_size_current == NULL)
5691 window_size_current = window_sizes;
5694 setup.window_scaling_percent = atoi(window_size_current->identifier);
5696 // needed for displaying window size text instead of identifier
5697 window_size_text = window_size_current->name;
5700 static void execSetupGraphics_setScalingTypes(void)
5702 if (scaling_types == NULL)
5706 for (i = 0; scaling_types_list[i].value != NULL; i++)
5708 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5709 char identifier[32], name[32];
5710 char *value = scaling_types_list[i].value;
5711 char *text = scaling_types_list[i].text;
5713 ti->node_top = &scaling_types;
5714 ti->sort_priority = i;
5716 sprintf(identifier, "%s", value);
5717 sprintf(name, "%s", text);
5719 setString(&ti->identifier, identifier);
5720 setString(&ti->name, name);
5721 setString(&ti->name_sorting, name);
5722 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5724 pushTreeInfo(&scaling_types, ti);
5727 // sort scaling type values to start with lowest scaling type value
5728 sortTreeInfo(&scaling_types);
5730 // set current scaling type value to configured scaling type value
5731 scaling_type_current =
5732 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5734 // if that fails, set current scaling type to reliable default value
5735 if (scaling_type_current == NULL)
5736 scaling_type_current =
5737 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5739 // if that also fails, set current scaling type to first available value
5740 if (scaling_type_current == NULL)
5741 scaling_type_current = scaling_types;
5744 setup.window_scaling_quality = scaling_type_current->identifier;
5746 // needed for displaying scaling type text instead of identifier
5747 scaling_type_text = scaling_type_current->name;
5750 static void execSetupGraphics_setRenderingModes(void)
5752 if (rendering_modes == NULL)
5756 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5758 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5759 char identifier[32], name[32];
5760 char *value = rendering_modes_list[i].value;
5761 char *text = rendering_modes_list[i].text;
5763 ti->node_top = &rendering_modes;
5764 ti->sort_priority = i;
5766 sprintf(identifier, "%s", value);
5767 sprintf(name, "%s", text);
5769 setString(&ti->identifier, identifier);
5770 setString(&ti->name, name);
5771 setString(&ti->name_sorting, name);
5772 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5774 pushTreeInfo(&rendering_modes, ti);
5777 // sort rendering mode values to start with lowest rendering mode value
5778 sortTreeInfo(&rendering_modes);
5780 // set current rendering mode value to configured rendering mode value
5781 rendering_mode_current =
5782 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5784 // if that fails, set current rendering mode to reliable default value
5785 if (rendering_mode_current == NULL)
5786 rendering_mode_current =
5787 getTreeInfoFromIdentifier(rendering_modes,
5788 STR_SPECIAL_RENDERING_DEFAULT);
5790 // if that also fails, set current rendering mode to first available one
5791 if (rendering_mode_current == NULL)
5792 rendering_mode_current = rendering_modes;
5795 setup.screen_rendering_mode = rendering_mode_current->identifier;
5797 // needed for displaying rendering mode text instead of identifier
5798 rendering_mode_text = rendering_mode_current->name;
5801 static void execSetupGraphics_setVsyncModes(boolean update_value)
5803 if (vsync_modes == NULL)
5807 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5809 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5810 char identifier[32], name[32];
5811 char *value = vsync_modes_list[i].value;
5812 char *text = vsync_modes_list[i].text;
5814 ti->node_top = &vsync_modes;
5815 ti->sort_priority = i;
5817 sprintf(identifier, "%s", value);
5818 sprintf(name, "%s", text);
5820 setString(&ti->identifier, identifier);
5821 setString(&ti->name, name);
5822 setString(&ti->name_sorting, name);
5823 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5825 pushTreeInfo(&vsync_modes, ti);
5828 // sort vsync mode values to start with lowest vsync mode value
5829 sortTreeInfo(&vsync_modes);
5831 update_value = TRUE;
5836 // set current vsync mode value to configured vsync mode value
5837 vsync_mode_current =
5838 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5840 // if that fails, set current vsync mode to reliable default value
5841 if (vsync_mode_current == NULL)
5842 vsync_mode_current =
5843 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5845 // if that also fails, set current vsync mode to first available one
5846 if (vsync_mode_current == NULL)
5847 vsync_mode_current = vsync_modes;
5850 setup.vsync_mode = vsync_mode_current->identifier;
5852 // needed for displaying vsync mode text instead of identifier
5853 vsync_mode_text = vsync_mode_current->name;
5856 static void execSetupGraphics(void)
5858 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5860 // update "setup.window_scaling_percent" from list selection
5861 // (in this case, window scaling was changed on setup screen)
5862 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5863 execSetupGraphics_setWindowSizes(FALSE);
5865 // update "setup.vsync_mode" from list selection
5866 // (in this case, vsync mode was changed on setup screen)
5867 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5868 execSetupGraphics_setVsyncModes(FALSE);
5870 // update list selection from "setup.window_scaling_percent"
5871 // (window scaling may have changed by resizing the window)
5872 execSetupGraphics_setWindowSizes(TRUE);
5874 // update list selection from "setup.vsync_mode"
5875 // (vsync_mode may have changed by re-creating the renderer)
5876 execSetupGraphics_setVsyncModes(TRUE);
5878 execSetupGraphics_setScalingTypes();
5879 execSetupGraphics_setRenderingModes();
5881 setup_mode = SETUP_MODE_GRAPHICS;
5885 // check if game speed is high enough for 60 Hz vsync to work
5886 if (check_game_speed)
5887 ModifyGameSpeedIfNeeded();
5889 // window scaling may have changed at this point
5890 ChangeWindowScalingIfNeeded();
5892 // window scaling quality may have changed at this point
5893 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5894 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5896 // screen rendering mode may have changed at this point
5897 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5899 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
5900 int video_vsync_mode = video.vsync_mode;
5902 // screen vsync mode may have changed at this point
5903 ChangeVsyncModeIfNeeded();
5905 // check if setting vsync mode to selected value failed
5906 if (setup_vsync_mode != video_vsync_mode &&
5907 setup_vsync_mode != video.vsync_mode)
5909 // changing vsync mode to selected value failed -- reset displayed value
5910 execSetupGraphics_setVsyncModes(TRUE);
5912 Request("Setting VSync failed!", REQ_CONFIRM);
5918 static void execSetupChooseWindowSize(void)
5920 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5925 static void execSetupChooseScalingType(void)
5927 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5932 static void execSetupChooseRenderingMode(void)
5934 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5939 static void execSetupChooseVsyncMode(void)
5941 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5946 static void execSetupChooseVolumeSimple(void)
5948 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5953 static void execSetupChooseVolumeLoops(void)
5955 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5960 static void execSetupChooseVolumeMusic(void)
5962 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5967 static void execSetupSound(void)
5969 if (volumes_simple == NULL)
5971 boolean current_volume_simple_found = FALSE;
5974 for (i = 0; volumes_list[i].value != -1; i++)
5976 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5977 char identifier[32], name[32];
5978 int value = volumes_list[i].value;
5979 char *text = volumes_list[i].text;
5981 ti->node_top = &volumes_simple;
5982 ti->sort_priority = value;
5984 sprintf(identifier, "%d", value);
5985 sprintf(name, "%s", text);
5987 setString(&ti->identifier, identifier);
5988 setString(&ti->name, name);
5989 setString(&ti->name_sorting, name);
5990 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5992 pushTreeInfo(&volumes_simple, ti);
5994 if (value == setup.volume_simple)
5995 current_volume_simple_found = TRUE;
5998 if (!current_volume_simple_found)
6000 // add entry for non-preset volume value
6002 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6003 char identifier[32], name[32];
6004 int value = setup.volume_simple;
6006 ti->node_top = &volumes_simple;
6007 ti->sort_priority = value;
6009 sprintf(identifier, "%d", value);
6010 sprintf(name, "%d %% (Current)", value);
6012 setString(&ti->identifier, identifier);
6013 setString(&ti->name, name);
6014 setString(&ti->name_sorting, name);
6015 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6017 pushTreeInfo(&volumes_simple, ti);
6020 // sort volume values to start with lowest volume value
6021 sortTreeInfo(&volumes_simple);
6023 // set current volume value to configured volume value
6024 volume_simple_current =
6025 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6027 // if that fails, set current volume to reliable default value
6028 if (volume_simple_current == NULL)
6029 volume_simple_current =
6030 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6032 // if that also fails, set current volume to first available value
6033 if (volume_simple_current == NULL)
6034 volume_simple_current = volumes_simple;
6037 if (volumes_loops == NULL)
6039 boolean current_volume_loops_found = FALSE;
6042 for (i = 0; volumes_list[i].value != -1; i++)
6044 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6045 char identifier[32], name[32];
6046 int value = volumes_list[i].value;
6047 char *text = volumes_list[i].text;
6049 ti->node_top = &volumes_loops;
6050 ti->sort_priority = value;
6052 sprintf(identifier, "%d", value);
6053 sprintf(name, "%s", text);
6055 setString(&ti->identifier, identifier);
6056 setString(&ti->name, name);
6057 setString(&ti->name_sorting, name);
6058 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6060 pushTreeInfo(&volumes_loops, ti);
6062 if (value == setup.volume_loops)
6063 current_volume_loops_found = TRUE;
6066 if (!current_volume_loops_found)
6068 // add entry for non-preset volume value
6070 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6071 char identifier[32], name[32];
6072 int value = setup.volume_loops;
6074 ti->node_top = &volumes_loops;
6075 ti->sort_priority = value;
6077 sprintf(identifier, "%d", value);
6078 sprintf(name, "%d %% (Current)", value);
6080 setString(&ti->identifier, identifier);
6081 setString(&ti->name, name);
6082 setString(&ti->name_sorting, name);
6083 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6085 pushTreeInfo(&volumes_loops, ti);
6088 // sort volume values to start with lowest volume value
6089 sortTreeInfo(&volumes_loops);
6091 // set current volume value to configured volume value
6092 volume_loops_current =
6093 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6095 // if that fails, set current volume to reliable default value
6096 if (volume_loops_current == NULL)
6097 volume_loops_current =
6098 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6100 // if that also fails, set current volume to first available value
6101 if (volume_loops_current == NULL)
6102 volume_loops_current = volumes_loops;
6105 if (volumes_music == NULL)
6107 boolean current_volume_music_found = FALSE;
6110 for (i = 0; volumes_list[i].value != -1; i++)
6112 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6113 char identifier[32], name[32];
6114 int value = volumes_list[i].value;
6115 char *text = volumes_list[i].text;
6117 ti->node_top = &volumes_music;
6118 ti->sort_priority = value;
6120 sprintf(identifier, "%d", value);
6121 sprintf(name, "%s", text);
6123 setString(&ti->identifier, identifier);
6124 setString(&ti->name, name);
6125 setString(&ti->name_sorting, name);
6126 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6128 pushTreeInfo(&volumes_music, ti);
6130 if (value == setup.volume_music)
6131 current_volume_music_found = TRUE;
6134 if (!current_volume_music_found)
6136 // add entry for non-preset volume value
6138 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6139 char identifier[32], name[32];
6140 int value = setup.volume_music;
6142 ti->node_top = &volumes_music;
6143 ti->sort_priority = value;
6145 sprintf(identifier, "%d", value);
6146 sprintf(name, "%d %% (Current)", value);
6148 setString(&ti->identifier, identifier);
6149 setString(&ti->name, name);
6150 setString(&ti->name_sorting, name);
6151 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6153 pushTreeInfo(&volumes_music, ti);
6156 // sort volume values to start with lowest volume value
6157 sortTreeInfo(&volumes_music);
6159 // set current volume value to configured volume value
6160 volume_music_current =
6161 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6163 // if that fails, set current volume to reliable default value
6164 if (volume_music_current == NULL)
6165 volume_music_current =
6166 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6168 // if that also fails, set current volume to first available value
6169 if (volume_music_current == NULL)
6170 volume_music_current = volumes_music;
6173 setup.volume_simple = atoi(volume_simple_current->identifier);
6174 setup.volume_loops = atoi(volume_loops_current->identifier);
6175 setup.volume_music = atoi(volume_music_current->identifier);
6177 // needed for displaying volume text instead of identifier
6178 volume_simple_text = volume_simple_current->name;
6179 volume_loops_text = volume_loops_current->name;
6180 volume_music_text = volume_music_current->name;
6182 setup_mode = SETUP_MODE_SOUND;
6187 static void execSetupChooseTouchControls(void)
6189 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6194 static void execSetupChooseMoveDistance(void)
6196 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6201 static void execSetupChooseDropDistance(void)
6203 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6208 static void execSetupChooseTransparency(void)
6210 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6215 static void execSetupChooseGridXSize_0(void)
6217 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6222 static void execSetupChooseGridYSize_0(void)
6224 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6229 static void execSetupChooseGridXSize_1(void)
6231 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6236 static void execSetupChooseGridYSize_1(void)
6238 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6243 static void execSetupConfigureVirtualButtons(void)
6245 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6247 ConfigureVirtualButtons();
6249 setup_mode = SETUP_MODE_TOUCH;
6254 static void execSetupTouch(void)
6258 if (touch_controls == NULL)
6260 for (i = 0; touch_controls_list[i].value != NULL; i++)
6262 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6263 char identifier[32], name[32];
6264 char *value = touch_controls_list[i].value;
6265 char *text = touch_controls_list[i].text;
6267 ti->node_top = &touch_controls;
6268 ti->sort_priority = i;
6270 sprintf(identifier, "%s", value);
6271 sprintf(name, "%s", text);
6273 setString(&ti->identifier, identifier);
6274 setString(&ti->name, name);
6275 setString(&ti->name_sorting, name);
6276 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6278 pushTreeInfo(&touch_controls, ti);
6281 // sort touch control values to start with lowest touch control value
6282 sortTreeInfo(&touch_controls);
6284 // set current touch control value to configured touch control value
6285 touch_control_current =
6286 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6288 // if that fails, set current touch control to reliable default value
6289 if (touch_control_current == NULL)
6290 touch_control_current =
6291 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6293 // if that also fails, set current touch control to first available value
6294 if (touch_control_current == NULL)
6295 touch_control_current = touch_controls;
6298 if (move_distances == NULL)
6300 for (i = 0; distances_list[i].value != -1; i++)
6302 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6303 char identifier[32], name[32];
6304 int value = distances_list[i].value;
6305 char *text = distances_list[i].text;
6307 ti->node_top = &move_distances;
6308 ti->sort_priority = value;
6310 sprintf(identifier, "%d", value);
6311 sprintf(name, "%s", text);
6313 setString(&ti->identifier, identifier);
6314 setString(&ti->name, name);
6315 setString(&ti->name_sorting, name);
6316 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6318 pushTreeInfo(&move_distances, ti);
6321 // sort distance values to start with lowest distance value
6322 sortTreeInfo(&move_distances);
6324 // set current distance value to configured distance value
6325 move_distance_current =
6326 getTreeInfoFromIdentifier(move_distances,
6327 i_to_a(setup.touch.move_distance));
6329 // if that fails, set current distance to reliable default value
6330 if (move_distance_current == NULL)
6331 move_distance_current =
6332 getTreeInfoFromIdentifier(move_distances,
6333 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6335 // if that also fails, set current distance to first available value
6336 if (move_distance_current == NULL)
6337 move_distance_current = move_distances;
6340 if (drop_distances == NULL)
6342 for (i = 0; distances_list[i].value != -1; i++)
6344 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6345 char identifier[32], name[32];
6346 int value = distances_list[i].value;
6347 char *text = distances_list[i].text;
6349 ti->node_top = &drop_distances;
6350 ti->sort_priority = value;
6352 sprintf(identifier, "%d", value);
6353 sprintf(name, "%s", text);
6355 setString(&ti->identifier, identifier);
6356 setString(&ti->name, name);
6357 setString(&ti->name_sorting, name);
6358 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6360 pushTreeInfo(&drop_distances, ti);
6363 // sort distance values to start with lowest distance value
6364 sortTreeInfo(&drop_distances);
6366 // set current distance value to configured distance value
6367 drop_distance_current =
6368 getTreeInfoFromIdentifier(drop_distances,
6369 i_to_a(setup.touch.drop_distance));
6371 // if that fails, set current distance to reliable default value
6372 if (drop_distance_current == NULL)
6373 drop_distance_current =
6374 getTreeInfoFromIdentifier(drop_distances,
6375 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6377 // if that also fails, set current distance to first available value
6378 if (drop_distance_current == NULL)
6379 drop_distance_current = drop_distances;
6382 if (transparencies == NULL)
6384 for (i = 0; transparencies_list[i].value != -1; i++)
6386 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6387 char identifier[32], name[32];
6388 int value = transparencies_list[i].value;
6389 char *text = transparencies_list[i].text;
6391 ti->node_top = &transparencies;
6392 ti->sort_priority = value;
6394 sprintf(identifier, "%d", value);
6395 sprintf(name, "%s", text);
6397 setString(&ti->identifier, identifier);
6398 setString(&ti->name, name);
6399 setString(&ti->name_sorting, name);
6400 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6402 pushTreeInfo(&transparencies, ti);
6405 // sort transparency values to start with lowest transparency value
6406 sortTreeInfo(&transparencies);
6408 // set current transparency value to configured transparency value
6409 transparency_current =
6410 getTreeInfoFromIdentifier(transparencies,
6411 i_to_a(setup.touch.transparency));
6413 // if that fails, set current transparency to reliable default value
6414 if (transparency_current == NULL)
6415 transparency_current =
6416 getTreeInfoFromIdentifier(transparencies,
6417 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6419 // if that also fails, set current transparency to first available value
6420 if (transparency_current == NULL)
6421 transparency_current = transparencies;
6424 for (i = 0; i < 2; i++)
6426 for (j = 0; j < 2; j++)
6428 if (grid_sizes[i][j] == NULL)
6430 for (k = 0; grid_sizes_list[k].value != -1; k++)
6432 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6433 char identifier[32], name[32];
6434 int value = grid_sizes_list[k].value;
6435 char *text = grid_sizes_list[k].text;
6437 ti->node_top = &grid_sizes[i][j];
6438 ti->sort_priority = value;
6440 sprintf(identifier, "%d", value);
6441 sprintf(name, "%s", text);
6443 setString(&ti->identifier, identifier);
6444 setString(&ti->name, name);
6445 setString(&ti->name_sorting, name);
6446 setString(&ti->infotext,
6449 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6450 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6452 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6453 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6455 pushTreeInfo(&grid_sizes[i][j], ti);
6458 // sort grid size values to start with lowest grid size value
6459 sortTreeInfo(&grid_sizes[i][j]);
6461 // set current grid size value to configured grid size value
6462 grid_size_current[i][j] =
6463 getTreeInfoFromIdentifier(grid_sizes[i][j],
6465 setup.touch.grid_xsize[i] :
6466 setup.touch.grid_ysize[i]));
6468 // if that fails, set current grid size to reliable default value
6469 if (grid_size_current[i][j] == NULL)
6470 grid_size_current[i][j] =
6471 getTreeInfoFromIdentifier(grid_sizes[i][j],
6473 DEFAULT_GRID_XSIZE(i) :
6474 DEFAULT_GRID_YSIZE(i)));
6476 // if that also fails, set current grid size to first available value
6477 if (grid_size_current[i][j] == NULL)
6478 grid_size_current[i][j] = grid_sizes[i][j];
6483 setup.touch.control_type = touch_control_current->identifier;
6484 setup.touch.move_distance = atoi(move_distance_current->identifier);
6485 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6486 setup.touch.transparency = atoi(transparency_current->identifier);
6488 for (i = 0; i < 2; i++)
6490 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6491 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6493 if (i == GRID_ACTIVE_NR())
6495 overlay.grid_xsize = setup.touch.grid_xsize[i];
6496 overlay.grid_ysize = setup.touch.grid_ysize[i];
6500 // needed for displaying value text instead of identifier
6501 touch_controls_text = touch_control_current->name;
6502 move_distance_text = move_distance_current->name;
6503 drop_distance_text = drop_distance_current->name;
6504 transparency_text = transparency_current->name;
6506 for (i = 0; i < 2; i++)
6507 for (j = 0; j < 2; j++)
6508 grid_size_text[i][j] = grid_size_current[i][j]->name;
6510 setup_mode = SETUP_MODE_TOUCH;
6515 static void execSetupArtwork(void)
6517 static ArtworkDirTree *gfx_last_valid = NULL;
6518 static ArtworkDirTree *snd_last_valid = NULL;
6519 static ArtworkDirTree *mus_last_valid = NULL;
6521 // current artwork directory may be invalid (level group, parent link)
6522 if (!validLevelSeries(artwork.gfx_current))
6523 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6524 if (!validLevelSeries(artwork.snd_current))
6525 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6526 if (!validLevelSeries(artwork.mus_current))
6527 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6529 // store valid artwork directory information
6530 gfx_last_valid = artwork.gfx_current;
6531 snd_last_valid = artwork.snd_current;
6532 mus_last_valid = artwork.mus_current;
6535 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6536 artwork.gfx_current->subdir,
6537 artwork.gfx_current->fullpath,
6538 artwork.gfx_current->basepath);
6541 setup.graphics_set = artwork.gfx_current->identifier;
6542 setup.sounds_set = artwork.snd_current->identifier;
6543 setup.music_set = artwork.mus_current->identifier;
6545 // needed if last screen (setup choice) changed graphics, sounds or music
6546 ReloadCustomArtwork(0);
6548 // needed for displaying artwork name instead of artwork identifier
6549 graphics_set_name = artwork.gfx_current->name;
6550 sounds_set_name = artwork.snd_current->name;
6551 music_set_name = artwork.mus_current->name;
6553 setup_mode = SETUP_MODE_ARTWORK;
6558 static void execSetupChooseGraphics(void)
6560 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6565 static void execSetupChooseSounds(void)
6567 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6572 static void execSetupChooseMusic(void)
6574 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6579 static void execSetupInput(void)
6581 setup_mode = SETUP_MODE_INPUT;
6586 static void execSetupShortcuts(void)
6588 setup_mode = SETUP_MODE_SHORTCUTS;
6593 static void execSetupShortcuts1(void)
6595 setup_mode = SETUP_MODE_SHORTCUTS_1;
6600 static void execSetupShortcuts2(void)
6602 setup_mode = SETUP_MODE_SHORTCUTS_2;
6607 static void execSetupShortcuts3(void)
6609 setup_mode = SETUP_MODE_SHORTCUTS_3;
6614 static void execSetupShortcuts4(void)
6616 setup_mode = SETUP_MODE_SHORTCUTS_4;
6621 static void execSetupShortcuts5(void)
6623 setup_mode = SETUP_MODE_SHORTCUTS_5;
6628 static void execExitSetup(void)
6630 SetGameStatus(GAME_MODE_MAIN);
6635 static void execSaveAndExitSetup(void)
6641 static void execGadgetNetworkServer(void)
6643 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6644 struct GadgetInfo *gi = screen_gadget[gadget_id];
6646 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6647 network_server_hostname[0] = '\0';
6649 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6653 ClickOnGadget(gi, MB_LEFTBUTTON);
6656 static void execOfferUploadTapes(void)
6661 static void ToggleNetworkModeIfNeeded(void)
6663 int font_title = FONT_TITLE_1;
6664 int font_foot = FC_BLUE;
6665 int ystart = mSY - SY + 16;
6666 int ybottom = mSY - SY + SYSIZE - 20;
6667 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6669 if (setup.network_mode == network.enabled)
6672 network.enabled = setup.network_mode;
6674 FadeOut(REDRAW_ALL);
6678 DrawTextSCentered(ystart, font_title, text);
6682 if (network.enabled)
6683 InitNetworkServer();
6685 DisconnectFromNetworkServer();
6687 DrawTextSCentered(ybottom, font_foot,
6688 "Press any key or button for setup menu");
6690 WaitForEventToContinue();
6695 static void ToggleGameSpeedsListIfNeeded(void)
6697 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6699 if (setup.game_speed_extended == using_game_speeds_extended)
6702 // try to match similar values when changing game speeds list
6703 if (setup.game_speed_extended)
6704 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6705 setup.game_frame_delay == 30 ? 29 :
6706 setup.game_frame_delay);
6708 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6709 setup.game_frame_delay == 16 ? 15 :
6710 setup.game_frame_delay >= 29 ? 30 :
6711 setup.game_frame_delay <= 10 ? 10 :
6712 setup.game_frame_delay);
6714 execSetupGame_setGameSpeeds(TRUE);
6719 static void ModifyGameSpeedIfNeeded(void)
6721 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6722 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6726 char *game_speed_text = "Fast";
6727 int game_speed_value = 15;
6729 if (setup.game_speed_extended)
6731 game_speed_text = "60 fps";
6732 game_speed_value = 16;
6735 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6737 // set game speed to existing list value that is fast enough for vsync
6738 setup.game_frame_delay = game_speed_value;
6740 execSetupGame_setGameSpeeds(TRUE);
6742 Request(message, REQ_CONFIRM);
6745 static void DisableVsyncIfNeeded(void)
6747 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6748 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6749 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6752 // disable vsync for the selected game speed to work
6753 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6755 execSetupGraphics_setVsyncModes(TRUE);
6757 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6763 void *related_value;
6764 } hide_related_entry_list[] =
6766 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6767 { &setup.game_frame_delay, &game_speed_text },
6769 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6770 { &setup.scroll_delay_value, &scroll_delay_text },
6772 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6773 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6775 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6776 { &setup.window_scaling_percent, &window_size_text },
6778 { &setup.window_scaling_quality, execSetupChooseScalingType },
6779 { &setup.window_scaling_quality, &scaling_type_text },
6781 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6782 { &setup.screen_rendering_mode, &rendering_mode_text },
6784 { &setup.vsync_mode, execSetupChooseVsyncMode },
6785 { &setup.vsync_mode, &vsync_mode_text },
6787 { &setup.graphics_set, execSetupChooseGraphics },
6788 { &setup.graphics_set, &graphics_set_name },
6790 { &setup.sounds_set, execSetupChooseSounds },
6791 { &setup.sounds_set, &sounds_set_name },
6793 { &setup.music_set, execSetupChooseMusic },
6794 { &setup.music_set, &music_set_name },
6796 { &setup.volume_simple, execSetupChooseVolumeSimple },
6797 { &setup.volume_simple, &volume_simple_text },
6799 { &setup.volume_loops, execSetupChooseVolumeLoops },
6800 { &setup.volume_loops, &volume_loops_text },
6802 { &setup.volume_music, execSetupChooseVolumeMusic },
6803 { &setup.volume_music, &volume_music_text },
6805 { &setup.touch.control_type, execSetupChooseTouchControls },
6806 { &setup.touch.control_type, &touch_controls_text },
6808 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6809 { &setup.touch.move_distance, &move_distance_text },
6811 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6812 { &setup.touch.drop_distance, &drop_distance_text },
6814 { &setup.touch.transparency, execSetupChooseTransparency },
6815 { &setup.touch.transparency, &transparency_text },
6817 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6818 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6820 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6821 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6823 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6824 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6826 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6827 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6829 { &setup.internal.menu_game, execSetupGame },
6830 { &setup.internal.menu_engines, execSetupEngines },
6831 { &setup.internal.menu_editor, execSetupEditor },
6832 { &setup.internal.menu_graphics, execSetupGraphics },
6833 { &setup.internal.menu_sound, execSetupSound },
6834 { &setup.internal.menu_artwork, execSetupArtwork },
6835 { &setup.internal.menu_input, execSetupInput },
6836 { &setup.internal.menu_touch, execSetupTouch },
6837 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6838 { &setup.internal.menu_exit, execExitSetup },
6839 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6844 void setHideRelatedSetupEntries(void)
6848 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6849 if (hideSetupEntry(hide_related_entry_list[i].value))
6850 setHideSetupEntry(hide_related_entry_list[i].related_value);
6853 static struct TokenInfo setup_info_main[] =
6855 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6856 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6857 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6858 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6859 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6860 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6861 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6862 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6863 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6864 { TYPE_EMPTY, NULL, "" },
6865 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6866 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6871 static struct TokenInfo setup_info_game[] =
6873 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6874 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6875 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6876 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6877 { TYPE_STRING, &network_server_text, "" },
6878 { TYPE_SWITCH, &setup.api_server, "Use Highscore Server:" },
6879 { TYPE_SWITCH, &setup.only_show_local_scores, "Only Show Local Scores:" },
6880 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload All Tapes to Server" },
6881 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
6882 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6883 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6884 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6885 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6886 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6887 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6888 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
6889 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
6890 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6891 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
6892 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
6893 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6894 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6895 { TYPE_STRING, &game_speed_text, "" },
6896 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6898 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6899 { TYPE_STRING, &scroll_delay_text, "" },
6901 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6902 { TYPE_STRING, &snapshot_mode_text, "" },
6903 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
6904 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
6905 { TYPE_EMPTY, NULL, "" },
6906 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6911 static struct TokenInfo setup_info_engines[] =
6913 { TYPE_HEADLINE, NULL, "Emerald Mine" },
6914 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
6915 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
6916 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
6917 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
6918 { TYPE_EMPTY, NULL, "" },
6919 { TYPE_HEADLINE, NULL, "Supaplex" },
6920 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
6921 { TYPE_EMPTY, NULL, "" },
6922 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6927 static struct TokenInfo setup_info_editor[] =
6930 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6931 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6932 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6933 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6934 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6935 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6936 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6937 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6938 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6939 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6941 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6942 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6944 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6946 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6947 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6948 { TYPE_EMPTY, NULL, "" },
6950 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6951 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6952 { TYPE_EMPTY, NULL, "" },
6954 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6955 { TYPE_EMPTY, NULL, "" },
6956 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
6957 { TYPE_EMPTY, NULL, "" },
6958 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6963 static struct TokenInfo setup_info_graphics[] =
6965 #if !defined(PLATFORM_ANDROID)
6966 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6967 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6968 { TYPE_STRING, &window_size_text, "" },
6969 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6970 { TYPE_STRING, &scaling_type_text, "" },
6971 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6972 { TYPE_STRING, &rendering_mode_text, "" },
6975 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6976 { TYPE_STRING, &scroll_delay_text, "" },
6978 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6979 { TYPE_STRING, &vsync_mode_text, "" },
6980 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6981 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6982 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6983 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6984 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6985 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6986 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
6987 { TYPE_EMPTY, NULL, "" },
6988 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6993 static struct TokenInfo setup_info_sound[] =
6995 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6996 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6997 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6998 { TYPE_EMPTY, NULL, "" },
6999 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7000 { TYPE_STRING, &volume_simple_text, "" },
7001 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7002 { TYPE_STRING, &volume_loops_text, "" },
7003 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7004 { TYPE_STRING, &volume_music_text, "" },
7005 { TYPE_EMPTY, NULL, "" },
7006 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7011 static struct TokenInfo setup_info_artwork[] =
7013 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7014 { TYPE_STRING, &graphics_set_name, "" },
7015 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7016 { TYPE_STRING, &sounds_set_name, "" },
7017 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7018 { TYPE_STRING, &music_set_name, "" },
7019 { TYPE_EMPTY, NULL, "" },
7020 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7021 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7022 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7023 { TYPE_EMPTY, NULL, "" },
7024 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7029 static struct TokenInfo setup_info_input[] =
7031 { TYPE_SWITCH, NULL, "Player:" },
7032 { TYPE_SWITCH, NULL, "Device:" },
7033 { TYPE_SWITCH, NULL, "" },
7034 { TYPE_SKIPPABLE, NULL, "" },
7035 { TYPE_EMPTY, NULL, "" },
7036 { TYPE_EMPTY, NULL, "" },
7037 { TYPE_EMPTY, NULL, "" },
7038 { TYPE_EMPTY, NULL, "" },
7039 { TYPE_EMPTY, NULL, "" },
7040 { TYPE_EMPTY, NULL, "" },
7041 { TYPE_EMPTY, NULL, "" },
7042 { TYPE_EMPTY, NULL, "" },
7043 { TYPE_SKIPPABLE, NULL, "" },
7044 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7049 static struct TokenInfo setup_info_touch[] =
7051 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7052 { TYPE_STRING, &touch_controls_text, "" },
7053 { TYPE_EMPTY, NULL, "" },
7054 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7059 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7061 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7062 { TYPE_STRING, &touch_controls_text, "" },
7063 { TYPE_EMPTY, NULL, "" },
7064 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7065 { TYPE_STRING, &grid_size_text[0][0], "" },
7066 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7067 { TYPE_STRING, &grid_size_text[0][1], "" },
7068 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7069 { TYPE_STRING, &transparency_text, "" },
7070 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7071 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7072 { TYPE_EMPTY, NULL, "" },
7073 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7074 { TYPE_EMPTY, NULL, "" },
7075 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7080 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7082 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7083 { TYPE_STRING, &touch_controls_text, "" },
7084 { TYPE_EMPTY, NULL, "" },
7085 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7086 { TYPE_STRING, &grid_size_text[1][0], "" },
7087 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7088 { TYPE_STRING, &grid_size_text[1][1], "" },
7089 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7090 { TYPE_STRING, &transparency_text, "" },
7091 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7092 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7093 { TYPE_EMPTY, NULL, "" },
7094 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7095 { TYPE_EMPTY, NULL, "" },
7096 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7101 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7103 setup_info_touch_virtual_buttons_0,
7104 setup_info_touch_virtual_buttons_1
7107 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7109 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7110 { TYPE_STRING, &touch_controls_text, "" },
7111 { TYPE_EMPTY, NULL, "" },
7112 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7113 { TYPE_STRING, &move_distance_text, "" },
7114 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7115 { TYPE_STRING, &drop_distance_text, "" },
7116 { TYPE_EMPTY, NULL, "" },
7117 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7122 static struct TokenInfo setup_info_shortcuts[] =
7124 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7125 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7126 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7127 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7128 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7129 { TYPE_EMPTY, NULL, "" },
7130 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7135 static struct TokenInfo setup_info_shortcuts_1[] =
7137 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7138 { TYPE_KEY, &setup.shortcut.save_game, "" },
7139 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7140 { TYPE_KEY, &setup.shortcut.load_game, "" },
7141 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7142 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7143 { TYPE_EMPTY, NULL, "" },
7144 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7145 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7146 { TYPE_EMPTY, NULL, "" },
7147 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7152 static struct TokenInfo setup_info_shortcuts_2[] =
7154 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7155 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7156 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7157 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7158 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7159 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7160 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7161 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7162 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7163 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7164 { TYPE_EMPTY, NULL, "" },
7165 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7170 static struct TokenInfo setup_info_shortcuts_3[] =
7172 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7173 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7174 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7175 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7176 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7177 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7178 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7179 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7180 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7181 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7182 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7183 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7184 { TYPE_EMPTY, NULL, "" },
7185 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7190 static struct TokenInfo setup_info_shortcuts_4[] =
7192 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7193 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7194 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7195 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7196 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7197 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7198 { TYPE_EMPTY, NULL, "" },
7199 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7204 static struct TokenInfo setup_info_shortcuts_5[] =
7206 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7207 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7208 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7209 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7210 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7211 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7212 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7213 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7214 { TYPE_EMPTY, NULL, "" },
7215 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7220 static Key getSetupKey(void)
7222 Key key = KSYM_UNDEFINED;
7223 boolean got_key_event = FALSE;
7225 while (!got_key_event)
7229 if (NextValidEvent(&event))
7233 case EVENT_KEYPRESS:
7235 key = GetEventKey((KeyEvent *)&event, TRUE);
7237 // press 'Escape' or 'Enter' to keep the existing key binding
7238 if (key == KSYM_Escape || key == KSYM_Return)
7239 key = KSYM_UNDEFINED; // keep old value
7241 got_key_event = TRUE;
7245 case EVENT_KEYRELEASE:
7246 key_joystick_mapping = 0;
7250 HandleOtherEvents(&event);
7261 static int getSetupValueFont(int type, void *value)
7263 if (type & TYPE_GHOSTED)
7264 return FONT_OPTION_OFF;
7265 else if (type & TYPE_KEY)
7266 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7267 else if (type & TYPE_STRING)
7268 return FONT_VALUE_2;
7269 else if (type & TYPE_ECS_AGA)
7270 return FONT_VALUE_1;
7271 else if (type & TYPE_BOOLEAN_STYLE)
7272 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7273 else if (type & TYPE_YES_NO_AUTO)
7274 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7275 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7276 else if (type & TYPE_PLAYER)
7277 return FONT_VALUE_1;
7279 return FONT_VALUE_1;
7282 static int getSetupValueFontNarrow(int type, int font_nr)
7284 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7285 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7286 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7290 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7292 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7293 struct TokenInfo *si = &setup_info[si_pos];
7294 boolean font_draw_xoffset_modified = FALSE;
7295 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7296 int font_draw_xoffset_old = -1;
7297 int xoffset = (scrollbar_needed ? -1 : 0);
7298 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7299 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7300 int xpos = menu_screen_value_xpos;
7301 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7302 int startx = mSX + xpos * 32;
7303 int starty = mSY + ypos * 32;
7304 int type = si->type;
7305 void *value = si->value;
7306 char *value_string = getSetupValue(type, value);
7307 int font_nr_default = getSetupValueFont(type, value);
7308 int font_width_default = getFontWidth(font_nr_default);
7309 int font_nr = font_nr_default;
7312 if (value_string == NULL)
7315 if (type & TYPE_KEY)
7317 xpos = MENU_SCREEN_START_XPOS;
7319 if (type & TYPE_QUERY)
7320 value_string = "<press key>";
7322 else if (type & TYPE_STRING)
7324 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7326 xpos = MENU_SCREEN_START_XPOS;
7328 if (strlen(value_string) > max_value_len)
7329 value_string[max_value_len] = '\0';
7331 else if (type & TYPE_YES_NO_AUTO)
7333 xpos = menu_screen_value_xpos - 1;
7335 else if (type & TYPE_PLAYER)
7337 int displayed_player_nr = *(int *)value + 1;
7339 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7342 startx = mSX + xpos * 32;
7343 starty = mSY + ypos * 32;
7345 // special check if right-side setup values moved left due to scrollbar
7346 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7348 int max_menu_text_length = 26; // maximum text length for classic menu
7349 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7350 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7351 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7352 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7353 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7355 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7357 // when using narrow font, left-shifting text "auto" not needed
7358 if (type & TYPE_YES_NO_AUTO)
7362 startx = mSX + xpos * 32;
7364 font_nr = getSetupValueFontNarrow(type, font_nr);
7368 // downward compatibility correction for Juergen Bonhagen's menu settings
7369 if (setup_mode != SETUP_MODE_INPUT)
7371 int max_menu_text_length_big = (menu_screen_value_xpos -
7372 MENU_SCREEN_START_XPOS);
7373 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7374 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7375 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7376 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
7377 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7378 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7379 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7380 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7381 boolean correct_font_draw_xoffset = FALSE;
7383 if (xpos == MENU_SCREEN_START_XPOS &&
7384 startx + font1_xoffset < text_startx + text_font_xoffset)
7385 correct_font_draw_xoffset = TRUE;
7387 if (xpos == menu_screen_value_xpos &&
7388 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7389 correct_font_draw_xoffset = TRUE;
7391 // check if setup value would overlap with setup text when printed
7392 // (this can happen for extreme/wrong values for font draw offset)
7393 if (correct_font_draw_xoffset)
7395 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
7396 font_draw_xoffset_modified = TRUE;
7398 if (type & TYPE_KEY)
7399 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7400 else if (!(type & TYPE_STRING))
7401 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7402 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7406 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7407 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7409 DrawText(startx, starty, value_string, font_nr);
7411 if (type & TYPE_PLAYER)
7413 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7414 int player_nr = *(int *)value;
7415 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7416 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7417 int startx2 = startx + xoff;
7418 int starty2 = starty + yoff;
7420 if (DrawingOnBackground(startx2, starty2))
7421 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7423 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7424 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7427 if (font_draw_xoffset_modified)
7428 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7431 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7433 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7434 struct TokenInfo *si = &setup_info[si_pos];
7436 if (si->type & TYPE_BOOLEAN_STYLE)
7438 *(boolean *)si->value ^= TRUE;
7440 else if (si->type & TYPE_YES_NO_AUTO)
7444 (*(int *)si->value == AUTO ? TRUE :
7445 *(int *)si->value == TRUE ? FALSE : AUTO) :
7446 (*(int *)si->value == TRUE ? AUTO :
7447 *(int *)si->value == AUTO ? FALSE : TRUE));
7449 else if (si->type & TYPE_KEY)
7453 si->type |= TYPE_QUERY;
7454 drawSetupValue(screen_pos, setup_info_pos_raw);
7455 si->type &= ~TYPE_QUERY;
7457 key = getSetupKey();
7458 if (key != KSYM_UNDEFINED)
7459 *(Key *)si->value = key;
7461 else if (si->type & TYPE_PLAYER)
7463 int player_nr = *(int *)si->value;
7468 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7470 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7473 drawSetupValue(screen_pos, setup_info_pos_raw);
7475 // fullscreen state may have changed at this point
7476 if (si->value == &setup.fullscreen)
7477 ToggleFullscreenIfNeeded();
7479 // network mode may have changed at this point
7480 if (si->value == &setup.network_mode)
7481 ToggleNetworkModeIfNeeded();
7483 // API server mode may have changed at this point
7484 if (si->value == &setup.api_server)
7485 runtime.api_server = setup.api_server;
7487 // game speed list may have changed at this point
7488 if (si->value == &setup.game_speed_extended)
7489 ToggleGameSpeedsListIfNeeded();
7492 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7494 static struct TokenInfo *setup_info_final = NULL;
7499 // determine maximum list size of target list
7500 while (setup_info_orig[list_size++].type != 0);
7502 // free, allocate and clear memory for target list
7503 checked_free(setup_info_final);
7504 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7506 // copy setup info list without setup entries marked as hidden
7507 for (i = 0; setup_info_orig[i].type != 0; i++)
7509 // skip setup entries configured to be hidden
7510 if (hideSetupEntry(setup_info_orig[i].value))
7513 // skip skippable setup entries if screen is lower than usual
7514 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7515 setup_info_orig[i].type == TYPE_SKIPPABLE)
7518 setup_info_final[list_pos++] = setup_info_orig[i];
7521 return setup_info_final;
7524 static void DrawSetupScreen_Generic(void)
7526 int fade_mask = REDRAW_FIELD;
7527 boolean redraw_all = FALSE;
7528 char *title_string = NULL;
7532 fade_mask = REDRAW_ALL;
7535 FadeMenuSoundsAndMusic();
7537 FreeScreenGadgets();
7538 CreateScreenGadgets();
7540 if (redraw_mask & REDRAW_ALL)
7545 // needed if different viewport properties defined for setup screen
7546 ChangeViewportPropertiesIfNeeded();
7548 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7552 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7554 if (setup_mode == SETUP_MODE_MAIN)
7556 setup_info = setup_info_main;
7557 title_string = STR_SETUP_MAIN;
7559 else if (setup_mode == SETUP_MODE_GAME)
7561 setup_info = setup_info_game;
7562 title_string = STR_SETUP_GAME;
7564 else if (setup_mode == SETUP_MODE_ENGINES)
7566 setup_info = setup_info_engines;
7567 title_string = STR_SETUP_ENGINES;
7569 else if (setup_mode == SETUP_MODE_EDITOR)
7571 setup_info = setup_info_editor;
7572 title_string = STR_SETUP_EDITOR;
7574 else if (setup_mode == SETUP_MODE_GRAPHICS)
7576 setup_info = setup_info_graphics;
7577 title_string = STR_SETUP_GRAPHICS;
7579 else if (setup_mode == SETUP_MODE_SOUND)
7581 setup_info = setup_info_sound;
7582 title_string = STR_SETUP_SOUND;
7584 else if (setup_mode == SETUP_MODE_ARTWORK)
7586 setup_info = setup_info_artwork;
7587 title_string = STR_SETUP_ARTWORK;
7589 else if (setup_mode == SETUP_MODE_TOUCH)
7591 setup_info = setup_info_touch;
7592 title_string = STR_SETUP_TOUCH;
7594 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7595 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7596 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7597 setup_info = setup_info_touch_wipe_gestures;
7599 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7601 setup_info = setup_info_shortcuts;
7602 title_string = STR_SETUP_SHORTCUTS;
7604 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7606 setup_info = setup_info_shortcuts_1;
7607 title_string = STR_SETUP_SHORTCUTS;
7609 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7611 setup_info = setup_info_shortcuts_2;
7612 title_string = STR_SETUP_SHORTCUTS;
7614 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7616 setup_info = setup_info_shortcuts_3;
7617 title_string = STR_SETUP_SHORTCUTS;
7619 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7621 setup_info = setup_info_shortcuts_4;
7622 title_string = STR_SETUP_SHORTCUTS;
7624 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7626 setup_info = setup_info_shortcuts_5;
7627 title_string = STR_SETUP_SHORTCUTS;
7630 // use modified setup info without setup entries marked as hidden
7631 setup_info = getSetupInfoFinal(setup_info);
7633 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7635 // determine maximal number of setup entries that can be displayed on screen
7637 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7640 // determine maximal number of setup entries available for this setup screen
7642 for (i = 0; setup_info[i].type != 0; i++)
7645 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7647 MapScreenGadgets(max_setup_info);
7650 redraw_mask = fade_mask = REDRAW_ALL;
7652 DrawMaskedBorder(fade_mask);
7657 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7659 menu_info = setup_info;
7661 HandleMenuScreen(mx, my, dx, dy, button,
7662 setup_mode, num_setup_info, max_setup_info);
7665 static void DrawSetupScreen_Input(void)
7669 FadeOut(REDRAW_FIELD);
7673 setup_info = getSetupInfoFinal(setup_info_input);
7675 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7677 for (i = 0; setup_info[i].type != 0; i++)
7679 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7680 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7681 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7682 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7683 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7684 initCursor(i, IMG_MENU_BUTTON);
7686 DrawCursorAndText_Setup(i, -1, FALSE);
7689 // create gadgets for setup input menu screen
7690 FreeScreenGadgets();
7691 CreateScreenGadgets();
7693 // map gadgets for setup input menu screen
7694 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7696 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7698 FadeIn(REDRAW_FIELD);
7701 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7703 if (device_name == NULL)
7706 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7709 if (strlen(device_name) > 1)
7711 char c1 = device_name[strlen(device_name) - 1];
7712 char c2 = device_name[strlen(device_name) - 2];
7714 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7715 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7718 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7719 strlen(device_name));
7722 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7725 static struct SetupKeyboardInfo custom_key;
7732 { &custom_key.left, "Axis/Pad Left" },
7733 { &custom_key.right, "Axis/Pad Right" },
7734 { &custom_key.up, "Axis/Pad Up" },
7735 { &custom_key.down, "Axis/Pad Down" },
7736 { &custom_key.snap, "Button 1/A/X" },
7737 { &custom_key.drop, "Button 2/B/Y" }
7739 static char *joystick_name[MAX_PLAYERS] =
7746 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7747 int font_nr_info = FONT_MENU_1;
7748 int font_nr_name = FONT_VALUE_OLD;
7749 int font_nr_on = FONT_VALUE_1;
7750 int font_nr_off = FONT_VALUE_OLD;
7753 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7755 font_nr_info = FONT_MENU_2;
7756 font_nr_on = FONT_VALUE_NARROW;
7757 font_nr_off = FONT_VALUE_OLD_NARROW;
7760 custom_key = setup.input[player_nr].key;
7762 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7763 FONT_INPUT_1_ACTIVE);
7765 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7767 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7768 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7770 if (setup.input[player_nr].use_joystick)
7772 char *device_name = setup.input[player_nr].joy.device_name;
7773 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7774 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7775 char *text = joystick_name[joystick_nr];
7776 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7778 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7779 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7783 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7784 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7787 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7788 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7792 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7793 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7794 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7795 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7797 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7798 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7799 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7800 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7801 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7802 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7804 for (i = 0; i < 6; i++)
7806 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7808 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7810 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7811 (setup.input[player_nr].use_joystick ?
7813 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7817 static int input_player_nr = 0;
7819 static void HandleSetupScreen_Input_Player(int step, int direction)
7821 int old_player_nr = input_player_nr;
7824 new_player_nr = old_player_nr + step * direction;
7825 if (new_player_nr < 0)
7827 if (new_player_nr > MAX_PLAYERS - 1)
7828 new_player_nr = MAX_PLAYERS - 1;
7830 if (new_player_nr != old_player_nr)
7832 input_player_nr = new_player_nr;
7834 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7838 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7840 static int choice = 0;
7843 int pos_start = SETUPINPUT_SCREEN_POS_START;
7844 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7845 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7846 int pos_end = SETUPINPUT_SCREEN_POS_END;
7848 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7852 for (i = 0; setup_info_input[i].type != 0; i++)
7854 // adjust menu structure according to skipped setup entries
7855 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7863 if (button == MB_MENU_INITIALIZE)
7865 // input setup menu may have changed size due to graphics configuration
7866 if (choice >= pos_empty1)
7869 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7871 DrawCursorAndText_Setup(choice, -1, TRUE);
7875 else if (button == MB_MENU_LEAVE)
7877 setup_mode = SETUP_MODE_MAIN;
7884 if (mx || my) // mouse input
7886 x = (mx - mSX) / 32;
7887 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7889 else if (dx || dy) // keyboard input
7891 if (dx && choice == 0)
7892 x = (dx < 0 ? 10 : 12);
7893 else if ((dx && choice == 1) ||
7894 (dx == -1 && choice == pos_end))
7895 button = MB_MENU_CHOICE;
7899 if (y >= pos_empty1 && y <= pos_empty2)
7900 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7903 if (y == 0 && dx != 0 && button)
7905 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7907 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7908 y >= pos_start && y <= pos_end &&
7909 !(y >= pos_empty1 && y <= pos_empty2))
7915 DrawCursorAndText_Setup(choice, -1, FALSE);
7916 DrawCursorAndText_Setup(y, -1, TRUE);
7918 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7927 char *device_name = setup.input[input_player_nr].joy.device_name;
7929 if (!setup.input[input_player_nr].use_joystick)
7931 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7933 setJoystickDeviceToNr(device_name, new_device_nr);
7934 setup.input[input_player_nr].use_joystick = TRUE;
7938 int device_nr = getJoystickNrFromDeviceName(device_name);
7939 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7941 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7942 setup.input[input_player_nr].use_joystick = FALSE;
7944 setJoystickDeviceToNr(device_name, new_device_nr);
7947 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7951 if (setup.input[input_player_nr].use_joystick)
7952 ConfigureJoystick(input_player_nr);
7954 CustomizeKeyboard(input_player_nr);
7956 else if (y == pos_end)
7962 setup_mode = SETUP_MODE_MAIN;
7969 static boolean CustomizeKeyboardMain(int player_nr)
7973 boolean finished = FALSE;
7974 static struct SetupKeyboardInfo custom_key;
7979 } customize_step[] =
7981 { &custom_key.left, "Move Left" },
7982 { &custom_key.right, "Move Right" },
7983 { &custom_key.up, "Move Up" },
7984 { &custom_key.down, "Move Down" },
7985 { &custom_key.snap, "Snap Field" },
7986 { &custom_key.drop, "Drop Element" }
7988 int font_nr_old = FONT_VALUE_OLD;
7989 int font_nr_new = FONT_VALUE_1;
7990 boolean success = FALSE;
7992 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7994 font_nr_old = FONT_VALUE_OLD_NARROW;
7995 font_nr_new = FONT_VALUE_NARROW;
7998 // read existing key bindings from player setup
7999 custom_key = setup.input[player_nr].key;
8002 FadeOut(REDRAW_FIELD);
8006 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8009 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8010 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8011 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8012 "Key:", FONT_INPUT_1_ACTIVE);
8013 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8014 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8016 FadeIn(REDRAW_FIELD);
8022 if (NextValidEvent(&event))
8026 case EVENT_KEYPRESS:
8028 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8030 // press 'Escape' to abort and keep the old key bindings
8031 if (key == KSYM_Escape)
8033 FadeSkipNextFadeIn();
8040 // press 'Enter' to keep the existing key binding
8041 if (key == KSYM_Return)
8042 key = *customize_step[step_nr].key;
8044 // check if key already used
8045 for (i = 0; i < step_nr; i++)
8046 if (*customize_step[i].key == key)
8051 // got new key binding
8052 *customize_step[step_nr].key = key;
8053 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8055 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8056 getKeyNameFromKey(key), font_nr_new);
8059 // un-highlight last query
8060 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8061 customize_step[step_nr - 1].text, FONT_MENU_1);
8062 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8063 "Key:", FONT_MENU_1);
8065 // all keys configured
8074 // query next key binding
8075 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8076 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8077 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8078 "Key:", FONT_INPUT_1_ACTIVE);
8079 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8080 getKeyNameFromKey(*customize_step[step_nr].key),
8085 case EVENT_KEYRELEASE:
8086 key_joystick_mapping = 0;
8090 HandleOtherEvents(&event);
8098 // write new key bindings back to player setup, if successfully finished
8100 setup.input[player_nr].key = custom_key;
8105 void CustomizeKeyboard(int player_nr)
8107 boolean success = CustomizeKeyboardMain(player_nr);
8111 int font_nr = FONT_TITLE_1;
8112 int font_height = getFontHeight(font_nr);
8113 int ypos1 = SYSIZE / 2 - font_height * 2;
8114 int ypos2 = SYSIZE / 2 - font_height * 1;
8115 unsigned int wait_frame_delay = 0;
8116 unsigned int wait_frame_delay_value = 2000;
8118 ResetDelayCounter(&wait_frame_delay);
8122 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8123 DrawTextSCentered(ypos2, font_nr, "configured!");
8125 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8131 DrawSetupScreen_Input();
8134 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8136 #define MARKER_BUTTON 1
8137 #define MARKER_AXIS_X 2
8138 #define MARKER_AXIS_Y 3
8140 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8142 static boolean bitmaps_initialized = FALSE;
8143 boolean screen_initialized = FALSE;
8144 static Bitmap *controller, *button, *axis_x, *axis_y;
8146 boolean success = TRUE;
8147 boolean done = FALSE, next = FALSE;
8149 int alpha = 200, alpha_step = -1;
8150 int alpha_ticks = 0;
8151 char mapping[4096], temp[256];
8152 int font_name = MENU_SETUP_FONT_TITLE;
8153 int font_info = MENU_SETUP_FONT_TEXT;
8154 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8155 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8156 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8157 int ystep_name = getMenuTextStep(spacing_name, font_name);
8158 int ystep_line = getMenuTextStep(spacing_line, font_info);
8159 int ystep_para = getMenuTextStep(spacing_para, font_info);
8167 int axis, button, hat, hat_value;
8170 *step, *prev_step, steps[] =
8172 { 356, 155, MARKER_BUTTON, "a", },
8173 { 396, 122, MARKER_BUTTON, "b", },
8174 { 320, 125, MARKER_BUTTON, "x", },
8175 { 358, 95, MARKER_BUTTON, "y", },
8176 { 162, 125, MARKER_BUTTON, "back", },
8177 { 216, 125, MARKER_BUTTON, "guide", },
8178 { 271, 125, MARKER_BUTTON, "start", },
8179 { 110, 200, MARKER_BUTTON, "dpleft", },
8180 { 146, 228, MARKER_BUTTON, "dpdown", },
8181 { 178, 200, MARKER_BUTTON, "dpright", },
8182 { 146, 172, MARKER_BUTTON, "dpup", },
8183 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8184 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8185 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8186 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8187 { 73, 141, MARKER_BUTTON, "leftstick", },
8188 { 282, 210, MARKER_BUTTON, "rightstick", },
8189 { 73, 141, MARKER_AXIS_X, "leftx", },
8190 { 73, 141, MARKER_AXIS_Y, "lefty", },
8191 { 282, 210, MARKER_AXIS_X, "rightx", },
8192 { 282, 210, MARKER_AXIS_Y, "righty", },
8195 unsigned int event_frame_delay = 0;
8196 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8198 ResetDelayCounter(&event_frame_delay);
8200 if (!bitmaps_initialized)
8202 controller = LoadCustomImage("joystick/controller.png");
8203 button = LoadCustomImage("joystick/button.png");
8204 axis_x = LoadCustomImage("joystick/axis_x.png");
8205 axis_y = LoadCustomImage("joystick/axis_y.png");
8207 bitmaps_initialized = TRUE;
8210 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8213 // print info about the joystick we are watching
8214 Debug("joystick", "watching joystick %d: (%s)",
8215 SDL_JoystickInstanceID(joystick), name);
8216 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8217 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8218 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8221 // initialize mapping with GUID and name
8222 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8224 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8225 temp, name, SDL_GetPlatform());
8227 // loop through all steps (buttons and axes), getting joystick events
8228 for (i = 0; i < SDL_arraysize(steps) && !done;)
8230 Bitmap *marker = button; // initialize with reliable default value
8233 strcpy(step->mapping, mapping);
8237 step->hat_value = -1;
8239 marker = (step->marker == MARKER_BUTTON ? button :
8240 step->marker == MARKER_AXIS_X ? axis_x :
8241 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8245 while (!done && !next)
8247 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8248 alpha_ticks = SDL_GetTicks();
8255 else if (alpha < 128)
8261 int controller_x = SX + (SXSIZE - controller->width) / 2;
8262 int controller_y = SY + ystep_line;
8264 int marker_x = controller_x + step->x;
8265 int marker_y = controller_y + step->y;
8267 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8268 int ystart2 = ystart1 + ystep_name + ystep_line;
8272 DrawTextSCentered(ystart1, font_name, name);
8274 DrawTextSCentered(ystart2, font_info,
8275 "Press buttons and move axes on");
8276 ystart2 += ystep_line;
8277 DrawTextSCentered(ystart2, font_info,
8278 "your controller when indicated.");
8279 ystart2 += ystep_line;
8280 DrawTextSCentered(ystart2, font_info,
8281 "(Your controller may look different.)");
8282 ystart2 += ystep_para;
8284 #if defined(PLATFORM_ANDROID)
8285 DrawTextSCentered(ystart2, font_info,
8286 "To correct a mistake,");
8287 ystart2 += ystep_line;
8288 DrawTextSCentered(ystart2, font_info,
8289 "press the 'back' button.");
8290 ystart2 += ystep_line;
8291 DrawTextSCentered(ystart2, font_info,
8292 "To skip a button or axis,");
8293 ystart2 += ystep_line;
8294 DrawTextSCentered(ystart2, font_info,
8295 "press the 'menu' button.");
8297 DrawTextSCentered(ystart2, font_info,
8298 "To correct a mistake,");
8299 ystart2 += ystep_line;
8300 DrawTextSCentered(ystart2, font_info,
8301 "press the 'backspace' key.");
8302 ystart2 += ystep_line;
8303 DrawTextSCentered(ystart2, font_info,
8304 "To skip a button or axis,");
8305 ystart2 += ystep_line;
8306 DrawTextSCentered(ystart2, font_info,
8307 "press the 'return' key.");
8308 ystart2 += ystep_line;
8309 DrawTextSCentered(ystart2, font_info,
8310 "To exit, press the 'escape' key.");
8313 BlitBitmapMasked(controller, drawto, 0, 0,
8314 controller->width, controller->height,
8315 controller_x, controller_y);
8317 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8318 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8320 BlitBitmapMasked(marker, drawto, 0, 0,
8321 marker->width, marker->height,
8322 marker_x, marker_y);
8324 if (!screen_initialized)
8325 FadeIn(REDRAW_FIELD);
8329 screen_initialized = TRUE;
8331 while (NextValidEvent(&event))
8335 case SDL_JOYAXISMOTION:
8336 if (event.jaxis.value > 20000 ||
8337 event.jaxis.value < -20000)
8339 for (j = 0; j < i; j++)
8340 if (steps[j].axis == event.jaxis.axis)
8345 if (step->marker != MARKER_AXIS_X &&
8346 step->marker != MARKER_AXIS_Y)
8349 step->axis = event.jaxis.axis;
8350 strcat(mapping, step->field);
8351 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8352 strcat(mapping, temp);
8360 case SDL_JOYHATMOTION:
8361 // ignore centering; we're probably just coming back
8362 // to the center from the previous item we set
8363 if (event.jhat.value == SDL_HAT_CENTERED)
8366 for (j = 0; j < i; j++)
8367 if (steps[j].hat == event.jhat.hat &&
8368 steps[j].hat_value == event.jhat.value)
8373 step->hat = event.jhat.hat;
8374 step->hat_value = event.jhat.value;
8375 strcat(mapping, step->field);
8376 snprintf(temp, sizeof(temp), ":h%u.%u,",
8377 event.jhat.hat, event.jhat.value );
8378 strcat(mapping, temp);
8385 case SDL_JOYBALLMOTION:
8388 case SDL_JOYBUTTONUP:
8389 for (j = 0; j < i; j++)
8390 if (steps[j].button == event.jbutton.button)
8395 step->button = event.jbutton.button;
8396 strcat(mapping, step->field);
8397 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8398 strcat(mapping, temp);
8405 case SDL_FINGERDOWN:
8406 case SDL_MOUSEBUTTONDOWN:
8414 if (event.key.keysym.sym == KSYM_BackSpace ||
8415 event.key.keysym.sym == KSYM_Back)
8427 prev_step = &steps[i - 1];
8428 strcpy(mapping, prev_step->mapping);
8435 if (event.key.keysym.sym == KSYM_space ||
8436 event.key.keysym.sym == KSYM_Return ||
8437 event.key.keysym.sym == KSYM_Menu)
8446 if (event.key.keysym.sym == KSYM_Escape)
8456 program.exit_function(0);
8463 // do not handle events for longer than standard frame delay period
8464 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8473 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8476 // activate mapping for this game
8477 SDL_GameControllerAddMapping(mapping);
8479 // save mapping to personal mappings
8480 SaveSetup_AddGameControllerMapping(mapping);
8483 // wait until the last pending event was removed from event queue
8484 while (NextValidEvent(&event));
8489 static int ConfigureJoystickMain(int player_nr)
8491 char *device_name = setup.input[player_nr].joy.device_name;
8492 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8493 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8494 int success = FALSE;
8497 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8498 return JOYSTICK_NOT_AVAILABLE;
8500 if (!joystick_active || !setup.input[player_nr].use_joystick)
8501 return JOYSTICK_NOT_AVAILABLE;
8504 FadeOut(REDRAW_FIELD);
8506 // close all joystick devices (potentially opened as game controllers)
8507 for (i = 0; i < SDL_NumJoysticks(); i++)
8508 SDLCloseJoystick(i);
8510 // open joystick device as plain joystick to configure as game controller
8511 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8513 // as the joystick was successfully opened before, this should not happen
8514 if (joystick == NULL)
8517 // create new game controller mapping (buttons and axes) for joystick device
8518 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8520 // close joystick (and maybe re-open as configured game controller later)
8521 SDL_JoystickClose(joystick);
8523 // re-open all joystick devices (potentially as game controllers)
8524 for (i = 0; i < SDL_NumJoysticks(); i++)
8527 // clear all joystick input actions for all joystick devices
8528 SDLClearJoystickState();
8530 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8533 void ConfigureJoystick(int player_nr)
8535 boolean state = ConfigureJoystickMain(player_nr);
8537 if (state != JOYSTICK_NOT_CONFIGURED)
8539 boolean success = (state == JOYSTICK_CONFIGURED);
8540 char message1[MAX_OUTPUT_LINESIZE + 1];
8541 char *message2 = (success ? "configured!" : "not available!");
8542 char *device_name = setup.input[player_nr].joy.device_name;
8543 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8544 int font_nr = FONT_TITLE_1;
8545 int font_height = getFontHeight(font_nr);
8546 int ypos1 = SYSIZE / 2 - font_height * 2;
8547 int ypos2 = SYSIZE / 2 - font_height * 1;
8548 unsigned int wait_frame_delay = 0;
8549 unsigned int wait_frame_delay_value = 2000;
8551 ResetDelayCounter(&wait_frame_delay);
8555 sprintf(message1, "Joystick %d", nr);
8557 DrawTextSCentered(ypos1, font_nr, message1);
8558 DrawTextSCentered(ypos2, font_nr, message2);
8560 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8566 DrawSetupScreen_Input();
8569 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8571 if (y < video.screen_height / 3)
8573 // remap touch gadgets to access upper part of the screen
8574 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8575 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8577 else if (y > 2 * video.screen_height / 3)
8579 // remap touch gadgets to access lower part of the screen
8580 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8581 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8585 static boolean ConfigureVirtualButtonsMain(void)
8587 static char *customize_step_text[] =
8596 char grid_button[] =
8598 CHAR_GRID_BUTTON_LEFT,
8599 CHAR_GRID_BUTTON_RIGHT,
8600 CHAR_GRID_BUTTON_UP,
8601 CHAR_GRID_BUTTON_DOWN,
8602 CHAR_GRID_BUTTON_SNAP,
8603 CHAR_GRID_BUTTON_DROP
8612 int font_nr = FONT_INPUT_1_ACTIVE;
8613 int font_height = getFontHeight(font_nr);
8614 int ypos1 = SYSIZE / 2 - font_height * 2;
8615 int ypos2 = SYSIZE / 2 - font_height * 1;
8616 boolean success = FALSE;
8617 boolean finished = FALSE;
8619 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8620 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8621 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8622 boolean set_grid_button = FALSE;
8623 int nr = GRID_ACTIVE_NR();
8626 for (x = 0; x < MAX_GRID_XSIZE; x++)
8627 for (y = 0; y < MAX_GRID_YSIZE; y++)
8628 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8630 overlay.grid_button_highlight = grid_button[step_nr];
8635 FadeOut(REDRAW_FIELD);
8639 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8640 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8641 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8643 FadeIn(REDRAW_FIELD);
8645 SetOverlayShowGrid(TRUE);
8647 // map gadgets for setup touch buttons menu screen
8648 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8654 while (NextValidEvent(&event))
8656 int action = ACTION_NONE;
8658 // ---------- handle events and set the resulting action ----------
8664 UserEvent *user = (UserEvent *)&event;
8665 int id = user->value1;
8667 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8668 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8669 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8670 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8675 case EVENT_KEYPRESS:
8677 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8679 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8680 key == KSYM_BackSpace ||
8681 key == KSYM_Back ? ACTION_BACK :
8682 key == KSYM_Return ||
8684 key == KSYM_space ? ACTION_NEXT :
8689 case EVENT_KEYRELEASE:
8690 key_joystick_mapping = 0;
8693 case EVENT_BUTTONPRESS:
8694 case EVENT_BUTTONRELEASE:
8696 ButtonEvent *button = (ButtonEvent *)&event;
8698 motion_status = FALSE;
8700 if (button->type == EVENT_BUTTONPRESS)
8701 button_status = button->button;
8703 button_status = MB_RELEASED;
8705 if (HandleGadgets(button->x, button->y, button_status))
8707 // do not handle this button event anymore
8711 button->x += video.screen_xoffset;
8712 button->y += video.screen_yoffset;
8714 x = button->x * overlay.grid_xsize / video.screen_width;
8715 y = button->y * overlay.grid_ysize / video.screen_height;
8717 if (button->type == EVENT_BUTTONPRESS)
8720 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8721 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8723 set_grid_button = TRUE;
8726 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8730 case EVENT_MOTIONNOTIFY:
8732 MotionEvent *motion = (MotionEvent *)&event;
8734 motion_status = TRUE;
8736 if (HandleGadgets(motion->x, motion->y, button_status))
8738 // do not handle this button event anymore
8742 motion->x += video.screen_xoffset;
8743 motion->y += video.screen_yoffset;
8745 x = motion->x * overlay.grid_xsize / video.screen_width;
8746 y = motion->y * overlay.grid_ysize / video.screen_height;
8748 set_grid_button = TRUE;
8750 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8754 case SDL_WINDOWEVENT:
8755 HandleWindowEvent((WindowEvent *) &event);
8757 // check if device has been rotated
8758 if (nr != GRID_ACTIVE_NR())
8760 nr = GRID_ACTIVE_NR();
8762 for (x = 0; x < MAX_GRID_XSIZE; x++)
8763 for (y = 0; y < MAX_GRID_YSIZE; y++)
8764 grid_button_old[x][y] = grid_button_tmp[x][y] =
8765 overlay.grid_button[x][y];
8770 case SDL_APP_WILLENTERBACKGROUND:
8771 case SDL_APP_DIDENTERBACKGROUND:
8772 case SDL_APP_WILLENTERFOREGROUND:
8773 case SDL_APP_DIDENTERFOREGROUND:
8774 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8778 HandleOtherEvents(&event);
8782 // ---------- perform action set by handling events ----------
8784 if (action == ACTION_ESCAPE)
8786 // abort and restore the old key bindings
8788 for (x = 0; x < MAX_GRID_XSIZE; x++)
8789 for (y = 0; y < MAX_GRID_YSIZE; y++)
8790 overlay.grid_button[x][y] = grid_button_old[x][y];
8792 FadeSkipNextFadeIn();
8796 else if (action == ACTION_BACK)
8798 // keep the configured key bindings and go to previous page
8804 FadeSkipNextFadeIn();
8809 else if (action == ACTION_NEXT)
8811 // keep the configured key bindings and go to next page
8815 // all virtual buttons configured
8823 if (action != ACTION_NONE && !finished)
8825 for (x = 0; x < MAX_GRID_XSIZE; x++)
8826 for (y = 0; y < MAX_GRID_YSIZE; y++)
8827 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8829 overlay.grid_button_highlight = grid_button[step_nr];
8831 // configure next virtual button
8835 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8836 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8837 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8840 if (set_grid_button)
8842 overlay.grid_button[x][y] =
8843 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8844 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8845 grid_button_tmp[x][y]);
8847 set_grid_button = FALSE;
8854 for (x = 0; x < MAX_GRID_XSIZE; x++)
8855 for (y = 0; y < MAX_GRID_YSIZE; y++)
8856 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8858 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8860 SetOverlayShowGrid(FALSE);
8865 void ConfigureVirtualButtons(void)
8867 boolean success = ConfigureVirtualButtonsMain();
8869 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8870 SCREEN_MASK_TOUCH2);
8874 int font_nr = FONT_TITLE_1;
8875 int font_height = getFontHeight(font_nr);
8876 int ypos1 = SYSIZE / 2 - font_height * 2;
8877 int ypos2 = SYSIZE / 2 - font_height * 1;
8878 unsigned int wait_frame_delay = 0;
8879 unsigned int wait_frame_delay_value = 2000;
8881 ResetDelayCounter(&wait_frame_delay);
8885 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8886 DrawTextSCentered(ypos2, font_nr, "configured!");
8888 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8895 void DrawSetupScreen(void)
8900 if (setup_mode == SETUP_MODE_INPUT)
8901 DrawSetupScreen_Input();
8902 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8903 DrawChooseTree(&game_speed_current);
8904 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8905 DrawChooseTree(&scroll_delay_current);
8906 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8907 DrawChooseTree(&snapshot_mode_current);
8908 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8909 DrawChooseTree(&window_size_current);
8910 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8911 DrawChooseTree(&scaling_type_current);
8912 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8913 DrawChooseTree(&rendering_mode_current);
8914 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8915 DrawChooseTree(&vsync_mode_current);
8916 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8917 DrawChooseTree(&artwork.gfx_current);
8918 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8919 DrawChooseTree(&artwork.snd_current);
8920 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8921 DrawChooseTree(&artwork.mus_current);
8922 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8923 DrawChooseTree(&volume_simple_current);
8924 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8925 DrawChooseTree(&volume_loops_current);
8926 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8927 DrawChooseTree(&volume_music_current);
8928 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8929 DrawChooseTree(&touch_control_current);
8930 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8931 DrawChooseTree(&move_distance_current);
8932 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8933 DrawChooseTree(&drop_distance_current);
8934 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8935 DrawChooseTree(&transparency_current);
8936 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8937 DrawChooseTree(&grid_size_current[0][0]);
8938 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8939 DrawChooseTree(&grid_size_current[0][1]);
8940 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8941 DrawChooseTree(&grid_size_current[1][0]);
8942 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8943 DrawChooseTree(&grid_size_current[1][1]);
8945 DrawSetupScreen_Generic();
8947 PlayMenuSoundsAndMusic();
8950 void RedrawSetupScreenAfterFullscreenToggle(void)
8952 if (setup_mode == SETUP_MODE_GRAPHICS ||
8953 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8955 // update list selection from "setup.window_scaling_percent"
8956 execSetupGraphics_setWindowSizes(TRUE);
8962 void RedrawSetupScreenAfterScreenRotation(int nr)
8966 if (setup_mode == SETUP_MODE_TOUCH)
8968 // update virtual button settings (depending on screen orientation)
8971 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8973 // save already configured virtual buttons
8974 for (x = 0; x < MAX_GRID_XSIZE; x++)
8975 for (y = 0; y < MAX_GRID_YSIZE; y++)
8976 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8980 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8982 if (setup_mode == SETUP_MODE_INPUT)
8983 HandleSetupScreen_Input(mx, my, dx, dy, button);
8984 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8985 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8986 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8987 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8988 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8989 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8990 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8991 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8992 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8993 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8994 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8995 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8996 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8997 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8998 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8999 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9000 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9001 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9002 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9003 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9004 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9005 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9006 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9007 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9008 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9009 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9010 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9011 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9012 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9013 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9014 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9015 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9016 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9017 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9018 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9019 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9020 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9021 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9022 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9023 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9024 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9025 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9027 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9030 void HandleGameActions(void)
9032 if (setup.ask_on_game_over)
9035 if (game.restart_game_message != NULL)
9037 RequestRestartGame(game.restart_game_message);
9042 if (game_status != GAME_MODE_PLAYING)
9045 GameActions(); // main game loop
9047 if (tape.auto_play && !tape.playing)
9048 AutoPlayTapesContinue(); // continue automatically playing next tape
9052 // ---------- new screen button stuff --------------------------------------
9056 int gfx_unpressed, gfx_pressed;
9057 struct MenuPosInfo *pos;
9058 boolean *check_value;
9061 unsigned int event_mask;
9062 boolean is_touch_button;
9064 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9067 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9068 &menu.main.button.prev_level, NULL,
9069 SCREEN_CTRL_ID_PREV_LEVEL,
9071 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9072 FALSE, "previous level"
9075 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9076 &menu.main.button.next_level, NULL,
9077 SCREEN_CTRL_ID_NEXT_LEVEL,
9079 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9083 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9084 &menu.main.button.first_level, NULL,
9085 SCREEN_CTRL_ID_FIRST_LEVEL,
9088 FALSE, "first level"
9091 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9092 &menu.main.button.last_level, NULL,
9093 SCREEN_CTRL_ID_LAST_LEVEL,
9099 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9100 &menu.main.button.level_number, NULL,
9101 SCREEN_CTRL_ID_LEVEL_NUMBER,
9104 FALSE, "level number"
9107 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9108 &menu.setup.button.prev_player, NULL,
9109 SCREEN_CTRL_ID_PREV_PLAYER,
9111 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9112 FALSE, "previous player"
9115 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9116 &menu.setup.button.next_player, NULL,
9117 SCREEN_CTRL_ID_NEXT_PLAYER,
9119 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9120 FALSE, "next player"
9123 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9124 &menu.main.button.insert_solution, NULL,
9125 SCREEN_CTRL_ID_INSERT_SOLUTION,
9126 SCREEN_MASK_MAIN_HAS_SOLUTION,
9128 FALSE, "insert solution tape"
9131 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9132 &menu.main.button.play_solution, NULL,
9133 SCREEN_CTRL_ID_PLAY_SOLUTION,
9134 SCREEN_MASK_MAIN_HAS_SOLUTION,
9136 FALSE, "play solution tape"
9139 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9140 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9141 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9143 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9144 FALSE, "switch ECS/AGA chipset"
9147 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9148 &menu.setup.button.touch_back, NULL,
9149 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9152 TRUE, "previous page"
9155 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9156 &menu.setup.button.touch_next, NULL,
9157 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9163 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9164 &menu.setup.button.touch_back2, NULL,
9165 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9168 TRUE, "previous page"
9171 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9172 &menu.setup.button.touch_next2, NULL,
9173 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9182 int gfx_unpressed, gfx_pressed;
9186 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9189 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9190 -1, -1, // these values are not constant, but can change at runtime
9191 SCREEN_CTRL_ID_SCROLL_UP,
9195 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9196 -1, -1, // these values are not constant, but can change at runtime
9197 SCREEN_CTRL_ID_SCROLL_DOWN,
9204 int gfx_unpressed, gfx_pressed;
9210 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9213 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9214 -1, -1, // these values are not constant, but can change at runtime
9215 -1, -1, // these values are not constant, but can change at runtime
9216 GD_TYPE_SCROLLBAR_VERTICAL,
9217 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9218 "scroll level series vertically"
9230 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9233 IMG_SETUP_INPUT_TEXT,
9234 SCREEN_CTRL_ID_NETWORK_SERVER,
9235 -1, -1, // these values are not constant, but can change at runtime
9236 MAX_SETUP_TEXT_INPUT_LEN,
9237 network_server_hostname,
9238 "Network Server Hostname / IP"
9242 static void CreateScreenMenubuttons(void)
9244 struct GadgetInfo *gi;
9245 unsigned int event_mask;
9248 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9250 struct MenuPosInfo *pos = menubutton_info[i].pos;
9251 boolean is_touch_button = menubutton_info[i].is_touch_button;
9252 boolean is_check_button = menubutton_info[i].check_value != NULL;
9253 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9254 int gfx_unpressed, gfx_pressed;
9255 int x, y, width, height;
9256 int gd_x1, gd_x2, gd_y1, gd_y2;
9257 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9258 int id = menubutton_info[i].gadget_id;
9259 int type = GD_TYPE_NORMAL_BUTTON;
9260 boolean checked = FALSE;
9262 event_mask = menubutton_info[i].event_mask;
9264 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9265 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9267 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9268 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9270 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9271 gfx_pressed = menubutton_info[i].gfx_pressed;
9272 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9273 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9274 gd_x1 = graphic_info[gfx_unpressed].src_x;
9275 gd_y1 = graphic_info[gfx_unpressed].src_y;
9276 gd_x2 = graphic_info[gfx_pressed].src_x;
9277 gd_y2 = graphic_info[gfx_pressed].src_y;
9283 if (is_touch_button)
9285 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9286 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9289 if (is_check_button)
9291 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9292 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9293 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9294 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9296 type = GD_TYPE_CHECK_BUTTON;
9297 checked = *menubutton_info[i].check_value;
9300 gi = CreateGadget(GDI_CUSTOM_ID, id,
9301 GDI_CUSTOM_TYPE_ID, i,
9302 GDI_IMAGE_ID, gfx_unpressed,
9303 GDI_INFO_TEXT, menubutton_info[i].infotext,
9309 GDI_STATE, GD_BUTTON_UNPRESSED,
9310 GDI_CHECKED, checked,
9311 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9312 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9313 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9314 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9315 GDI_DIRECT_DRAW, FALSE,
9316 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9317 GDI_EVENT_MASK, event_mask,
9318 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9322 Fail("cannot create gadget");
9324 screen_gadget[id] = gi;
9328 static void CreateScreenScrollbuttons(void)
9330 struct GadgetInfo *gi;
9331 unsigned int event_mask;
9334 // these values are not constant, but can change at runtime
9335 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9336 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9337 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9338 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9340 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9342 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9343 int gfx_unpressed, gfx_pressed;
9344 int x, y, width, height;
9345 int gd_x1, gd_x2, gd_y1, gd_y2;
9346 int id = scrollbutton_info[i].gadget_id;
9348 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9350 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9351 y = mSY + scrollbutton_info[i].y;
9352 width = SC_SCROLLBUTTON_XSIZE;
9353 height = SC_SCROLLBUTTON_YSIZE;
9355 // correct scrollbar position if placed outside menu (playfield) area
9356 if (x > SX + SC_SCROLL_UP_XPOS)
9357 x = SX + SC_SCROLL_UP_XPOS;
9359 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9360 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9361 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9363 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9364 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9365 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9366 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9367 gd_x1 = graphic_info[gfx_unpressed].src_x;
9368 gd_y1 = graphic_info[gfx_unpressed].src_y;
9369 gd_x2 = graphic_info[gfx_pressed].src_x;
9370 gd_y2 = graphic_info[gfx_pressed].src_y;
9372 gi = CreateGadget(GDI_CUSTOM_ID, id,
9373 GDI_CUSTOM_TYPE_ID, i,
9374 GDI_IMAGE_ID, gfx_unpressed,
9375 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9380 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9381 GDI_STATE, GD_BUTTON_UNPRESSED,
9382 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9383 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9384 GDI_DIRECT_DRAW, FALSE,
9385 GDI_EVENT_MASK, event_mask,
9386 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9390 Fail("cannot create gadget");
9392 screen_gadget[id] = gi;
9396 static void CreateScreenScrollbars(void)
9400 // these values are not constant, but can change at runtime
9401 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9402 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9403 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9404 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9406 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9408 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9409 int gfx_unpressed, gfx_pressed;
9410 int x, y, width, height;
9411 int gd_x1, gd_x2, gd_y1, gd_y2;
9412 struct GadgetInfo *gi;
9413 int items_max, items_visible, item_position;
9414 unsigned int event_mask;
9415 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9416 int id = scrollbar_info[i].gadget_id;
9418 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9420 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9421 y = mSY + scrollbar_info[i].y;
9422 width = scrollbar_info[i].width;
9423 height = scrollbar_info[i].height;
9425 // correct scrollbar position if placed outside menu (playfield) area
9426 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9427 x = SX + SC_SCROLL_VERTICAL_XPOS;
9429 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9430 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9432 items_max = num_page_entries;
9433 items_visible = num_page_entries;
9436 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9437 gfx_pressed = scrollbar_info[i].gfx_pressed;
9438 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9439 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9440 gd_x1 = graphic_info[gfx_unpressed].src_x;
9441 gd_y1 = graphic_info[gfx_unpressed].src_y;
9442 gd_x2 = graphic_info[gfx_pressed].src_x;
9443 gd_y2 = graphic_info[gfx_pressed].src_y;
9445 gi = CreateGadget(GDI_CUSTOM_ID, id,
9446 GDI_CUSTOM_TYPE_ID, i,
9447 GDI_IMAGE_ID, gfx_unpressed,
9448 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9453 GDI_TYPE, scrollbar_info[i].type,
9454 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9455 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9456 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9457 GDI_WHEEL_AREA_X, SX,
9458 GDI_WHEEL_AREA_Y, SY,
9459 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9460 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9461 GDI_STATE, GD_BUTTON_UNPRESSED,
9462 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9463 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9464 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9465 GDI_DIRECT_DRAW, FALSE,
9466 GDI_EVENT_MASK, event_mask,
9467 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9471 Fail("cannot create gadget");
9473 screen_gadget[id] = gi;
9477 static void CreateScreenTextInputGadgets(void)
9481 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9483 int graphic = textinput_info[i].graphic;
9484 struct GraphicInfo *gd = &graphic_info[graphic];
9485 int gd_x1 = gd->src_x;
9486 int gd_y1 = gd->src_y;
9487 int gd_x2 = gd->src_x + gd->active_xoffset;
9488 int gd_y2 = gd->src_y + gd->active_yoffset;
9489 struct GadgetInfo *gi;
9490 unsigned int event_mask;
9491 int id = textinput_info[i].gadget_id;
9492 int x = textinput_info[i].x;
9493 int y = textinput_info[i].y;
9495 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9497 gi = CreateGadget(GDI_CUSTOM_ID, id,
9498 GDI_CUSTOM_TYPE_ID, i,
9499 GDI_INFO_TEXT, textinput_info[i].infotext,
9502 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9503 GDI_TEXT_VALUE, textinput_info[i].value,
9504 GDI_TEXT_SIZE, textinput_info[i].size,
9505 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9506 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9507 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9508 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9509 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9510 GDI_DESIGN_WIDTH, gd->width,
9511 GDI_EVENT_MASK, event_mask,
9512 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9513 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9517 Fail("cannot create gadget");
9519 screen_gadget[id] = gi;
9523 void CreateScreenGadgets(void)
9525 CreateScreenMenubuttons();
9527 CreateScreenScrollbuttons();
9528 CreateScreenScrollbars();
9530 CreateScreenTextInputGadgets();
9533 void FreeScreenGadgets(void)
9537 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9538 FreeGadget(screen_gadget[i]);
9541 static void MapScreenMenuGadgets(int screen_mask)
9545 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9546 if (screen_mask & menubutton_info[i].screen_mask)
9547 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9550 static void UnmapScreenMenuGadgets(int screen_mask)
9554 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9556 if (screen_mask & menubutton_info[i].screen_mask)
9558 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9560 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9561 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9562 screen_gadget[menubutton_info[i].gadget_id]->y,
9563 screen_gadget[menubutton_info[i].gadget_id]->width,
9564 screen_gadget[menubutton_info[i].gadget_id]->height);
9569 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9572 MapScreenMenuGadgets(screen_mask);
9574 UnmapScreenMenuGadgets(screen_mask);
9577 static void MapScreenGadgets(int num_entries)
9581 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9584 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9585 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9587 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9588 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9591 static void MapScreenTreeGadgets(TreeInfo *ti)
9593 MapScreenGadgets(numTreeInfoInGroup(ti));
9596 static void HandleScreenGadgets(struct GadgetInfo *gi)
9598 int id = gi->custom_id;
9599 int button = gi->event.button;
9600 int step = (button == MB_LEFTBUTTON ? 1 :
9601 button == MB_MIDDLEBUTTON ? 5 :
9602 button == MB_RIGHTBUTTON ? 10 : 1);
9606 case SCREEN_CTRL_ID_PREV_LEVEL:
9607 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9610 case SCREEN_CTRL_ID_NEXT_LEVEL:
9611 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9614 case SCREEN_CTRL_ID_FIRST_LEVEL:
9615 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9618 case SCREEN_CTRL_ID_LAST_LEVEL:
9619 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9622 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9623 CloseDoor(DOOR_CLOSE_2);
9624 SetGameStatus(GAME_MODE_LEVELNR);
9625 DrawChooseLevelNr();
9628 case SCREEN_CTRL_ID_PREV_PLAYER:
9629 HandleSetupScreen_Input_Player(step, -1);
9632 case SCREEN_CTRL_ID_NEXT_PLAYER:
9633 HandleSetupScreen_Input_Player(step, +1);
9636 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9637 InsertSolutionTape();
9640 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9644 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9645 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9649 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9650 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9651 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9652 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9653 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9656 case SCREEN_CTRL_ID_SCROLL_UP:
9657 if (game_status == GAME_MODE_NAMES)
9658 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9659 else if (game_status == GAME_MODE_LEVELS)
9660 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9661 else if (game_status == GAME_MODE_LEVELNR)
9662 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9663 else if (game_status == GAME_MODE_SETUP)
9664 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9665 else if (game_status == GAME_MODE_INFO)
9666 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9669 case SCREEN_CTRL_ID_SCROLL_DOWN:
9670 if (game_status == GAME_MODE_NAMES)
9671 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9672 else if (game_status == GAME_MODE_LEVELS)
9673 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9674 else if (game_status == GAME_MODE_LEVELNR)
9675 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9676 else if (game_status == GAME_MODE_SETUP)
9677 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9678 else if (game_status == GAME_MODE_INFO)
9679 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9682 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9683 if (game_status == GAME_MODE_NAMES)
9684 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9685 else if (game_status == GAME_MODE_LEVELS)
9686 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9687 else if (game_status == GAME_MODE_LEVELNR)
9688 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9689 else if (game_status == GAME_MODE_SETUP)
9690 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9691 else if (game_status == GAME_MODE_INFO)
9692 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9695 case SCREEN_CTRL_ID_NETWORK_SERVER:
9697 if (!strEqual(gi->textinput.value, ""))
9699 setString(&setup.network_server_hostname, gi->textinput.value);
9701 network.server_host = setup.network_server_hostname;
9705 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9707 network.server_host = NULL;
9710 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9711 network.server_host = NULL;
9713 execSetupGame_setNetworkServerText();
9725 void DumpScreenIdentifiers(void)
9729 Print("Active screen elements on current screen:\n");
9731 for (i = 0; main_controls[i].nr != -1; i++)
9733 struct MainControlInfo *mci = &main_controls[i];
9735 if (mci->button_graphic != -1)
9737 char *token = getTokenFromImageID(mci->button_graphic);
9739 Print("- '%s'\n", token);
9746 boolean DoScreenAction(int image_id)
9750 if (game_status != GAME_MODE_MAIN)
9753 for (i = 0; main_controls[i].nr != -1; i++)
9755 struct MainControlInfo *mci = &main_controls[i];
9756 struct MenuPosInfo *pos = mci->pos_button;
9758 if (mci->button_graphic == image_id)
9760 int x = mSX + pos->x;
9761 int y = mSY + pos->y;
9763 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9772 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9774 // get tree info node of newly added level or artwork set
9775 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9776 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9778 if (tree_node_new == NULL) // should not happen
9781 // if request dialog is active, do nothing
9782 if (game.request_active)
9785 if (game_status == GAME_MODE_MAIN &&
9786 tree_type == TREE_TYPE_LEVEL_DIR)
9788 // when adding new level set in main menu, select it as current level set
9790 // change current level set to newly added level set from zip file
9791 leveldir_current = tree_node_new;
9793 // change current level number to first level of newly added level set
9794 level_nr = leveldir_current->first_level;
9796 // redraw screen to reflect changed level set
9799 // save this level set and level number as last selected level set
9800 SaveLevelSetup_LastSeries();
9801 SaveLevelSetup_SeriesInfo();
9803 else if (game_status == GAME_MODE_LEVELS &&
9804 tree_type == TREE_TYPE_LEVEL_DIR)
9806 // when adding new level set in level set menu, set cursor and update screen
9808 leveldir_current = tree_node_new;
9810 DrawChooseTree(&leveldir_current);
9812 else if (game_status == GAME_MODE_SETUP)
9814 // when adding new artwork set in setup menu, set cursor and update screen
9816 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9817 tree_type == TREE_TYPE_GRAPHICS_DIR)
9819 artwork.gfx_current = tree_node_new;
9821 DrawChooseTree(&artwork.gfx_current);
9823 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9824 tree_type == TREE_TYPE_SOUNDS_DIR)
9826 artwork.snd_current = tree_node_new;
9828 DrawChooseTree(&artwork.snd_current);
9830 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9831 tree_type == TREE_TYPE_MUSIC_DIR)
9833 artwork.mus_current = tree_node_new;
9835 DrawChooseTree(&artwork.mus_current);
9840 static int UploadTapes(void)
9842 SetGameStatus(GAME_MODE_LOADING);
9844 FadeSetEnterScreen();
9845 FadeOut(REDRAW_ALL);
9847 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
9851 DrawInitTextHead("Uploading tapes");
9853 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
9854 global.autoplay_leveldir = "ALL";
9855 global.autoplay_all = TRUE;
9857 int num_tapes_uploaded = AutoPlayTapes();
9859 global.autoplay_mode = AUTOPLAY_MODE_NONE;
9860 global.autoplay_leveldir = NULL;
9861 global.autoplay_all = FALSE;
9863 SetGameStatus(GAME_MODE_MAIN);
9867 return num_tapes_uploaded;
9870 static boolean OfferUploadTapes(void)
9872 if (!Request("Upload all your tapes to the high score server now?", REQ_ASK))
9875 int num_tapes_uploaded = UploadTapes();
9878 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
9880 Request(message, REQ_CONFIRM);
9882 return (num_tapes_uploaded > 0);
9885 void CheckUploadTapes(void)
9887 if (!setup.ask_for_uploading_tapes)
9890 if (directoryExists(getTapeDir(NULL)))
9892 boolean tapes_uploaded = OfferUploadTapes();
9894 if (!tapes_uploaded)
9895 Request("You can upload your tapes from the setup menu later!",
9899 setup.ask_for_uploading_tapes = FALSE;