1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
27 #define DEBUG_JOYSTICKS 0
30 // screens on the info screen
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 // screens on the setup screen
43 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
44 // (should also match corresponding entries in src/conf_gfx.c)
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_ENGINES 2
48 #define SETUP_MODE_EDITOR 3
49 #define SETUP_MODE_GRAPHICS 4
50 #define SETUP_MODE_SOUND 5
51 #define SETUP_MODE_ARTWORK 6
52 #define SETUP_MODE_INPUT 7
53 #define SETUP_MODE_TOUCH 8
54 #define SETUP_MODE_SHORTCUTS 9
55 #define SETUP_MODE_SHORTCUTS_1 10
56 #define SETUP_MODE_SHORTCUTS_2 11
57 #define SETUP_MODE_SHORTCUTS_3 12
58 #define SETUP_MODE_SHORTCUTS_4 13
59 #define SETUP_MODE_SHORTCUTS_5 14
61 // sub-screens on the setup screen (generic)
62 #define SETUP_MODE_CHOOSE_ARTWORK 15
63 #define SETUP_MODE_CHOOSE_OTHER 16
65 // sub-screens on the setup screen (specific)
66 #define SETUP_MODE_CHOOSE_SCORES_TYPE 17
67 #define SETUP_MODE_CHOOSE_GAME_SPEED 18
68 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 19
69 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 20
70 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 21
71 #define SETUP_MODE_CHOOSE_SCALING_TYPE 22
72 #define SETUP_MODE_CHOOSE_RENDERING 23
73 #define SETUP_MODE_CHOOSE_VSYNC 24
74 #define SETUP_MODE_CHOOSE_GRAPHICS 25
75 #define SETUP_MODE_CHOOSE_SOUNDS 26
76 #define SETUP_MODE_CHOOSE_MUSIC 27
77 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 28
78 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 29
79 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 30
80 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 31
81 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 33
83 #define SETUP_MODE_CHOOSE_TRANSPARENCY 34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 36
86 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 37
87 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 38
88 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 39
90 #define MAX_SETUP_MODES 40
92 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
94 // setup screen titles
95 #define STR_SETUP_MAIN "Setup"
96 #define STR_SETUP_GAME "Game & Menu"
97 #define STR_SETUP_ENGINES "Game Engines"
98 #define STR_SETUP_EDITOR "Editor"
99 #define STR_SETUP_GRAPHICS "Graphics"
100 #define STR_SETUP_SOUND "Sound & Music"
101 #define STR_SETUP_ARTWORK "Custom Artwork"
102 #define STR_SETUP_INPUT "Input Devices"
103 #define STR_SETUP_TOUCH "Touch Controls"
104 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
105 #define STR_SETUP_EXIT "Exit"
106 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
108 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
109 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
110 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
111 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
112 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
113 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
114 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
115 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
116 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
117 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
118 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
119 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
120 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
121 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
122 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
125 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
126 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
128 // other screen text constants
129 #define STR_CHOOSE_TREE_EDIT "Edit"
130 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
131 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
133 // for input setup functions
134 #define SETUPINPUT_SCREEN_POS_START 0
135 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
136 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
137 #define SETUPINPUT_SCREEN_POS_END 13
139 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
140 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
142 #define MAX_SETUP_TEXT_INPUT_LEN 28
144 // for various menu stuff
145 #define MENU_SCREEN_START_XPOS 1
146 #define MENU_SCREEN_START_YPOS 2
147 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
148 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
149 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
150 #define MENU_TITLE1_YPOS 8
151 #define MENU_TITLE2_YPOS 46
152 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
153 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
154 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
155 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
156 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
159 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
160 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
161 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
162 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
163 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
164 MENU_INFO_FONT_TITLE))
165 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
166 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
167 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
168 MENU_SCREEN_INFO_YSTART2 - \
170 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
171 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
172 MENU_SCREEN_INFO_YSTEP)
173 #define NUM_INFO_ELEMENTS_FROM_CONF \
174 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
175 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
176 MAX_MENU_ENTRIES_ON_SCREEN)
177 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
178 MAX_INFO_ELEMENTS_ON_SCREEN), \
179 NUM_INFO_ELEMENTS_FROM_CONF)
180 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
181 #define MAX_MENU_TEXT_LENGTH_BIG 13
182 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
184 // screen gadget identifiers
185 #define SCREEN_CTRL_ID_PREV_LEVEL 0
186 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
187 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
188 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
189 #define SCREEN_CTRL_ID_FIRST_LEVEL 4
190 #define SCREEN_CTRL_ID_LAST_LEVEL 5
191 #define SCREEN_CTRL_ID_LEVEL_NUMBER 6
192 #define SCREEN_CTRL_ID_PREV_PLAYER 7
193 #define SCREEN_CTRL_ID_NEXT_PLAYER 8
194 #define SCREEN_CTRL_ID_INSERT_SOLUTION 9
195 #define SCREEN_CTRL_ID_PLAY_SOLUTION 10
196 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 11
197 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 12
198 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 13
199 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 14
200 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 15
201 #define SCREEN_CTRL_ID_SCROLL_UP 16
202 #define SCREEN_CTRL_ID_SCROLL_DOWN 17
203 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 18
204 #define SCREEN_CTRL_ID_NETWORK_SERVER 19
206 #define NUM_SCREEN_GADGETS 20
208 #define NUM_SCREEN_MENUBUTTONS 16
209 #define NUM_SCREEN_SCROLLBUTTONS 2
210 #define NUM_SCREEN_SCROLLBARS 1
211 #define NUM_SCREEN_TEXTINPUT 1
213 #define SCREEN_MASK_MAIN (1 << 0)
214 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
215 #define SCREEN_MASK_INPUT (1 << 2)
216 #define SCREEN_MASK_TOUCH (1 << 3)
217 #define SCREEN_MASK_TOUCH2 (1 << 4)
218 #define SCREEN_MASK_SCORES (1 << 5)
220 // graphic position and size values for buttons and scrollbars
221 #define SC_MENUBUTTON_XSIZE TILEX
222 #define SC_MENUBUTTON_YSIZE TILEY
224 #define SC_SCROLLBUTTON_XSIZE TILEX
225 #define SC_SCROLLBUTTON_YSIZE TILEY
227 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
229 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
230 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
231 SC_SCROLLBUTTON_YSIZE)
233 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
234 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
236 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
237 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
238 SC_SCROLLBUTTON_YSIZE)
240 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
241 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
242 SC_SCROLL_VERTICAL_YSIZE)
244 #define SC_BORDER_SIZE 14
247 // forward declarations of internal functions
248 static void HandleScreenGadgets(struct GadgetInfo *);
249 static void HandleSetupScreen_Generic(int, int, int, int, int);
250 static void HandleSetupScreen_Input(int, int, int, int, int);
251 static void CustomizeKeyboard(int);
252 static void ConfigureJoystick(int);
253 static void ConfigureVirtualButtons(void);
254 static void execSetupGame(void);
255 static void execSetupEngines(void);
256 static void execSetupGraphics(void);
257 static void execSetupSound(void);
258 static void execSetupTouch(void);
259 static void execSetupArtwork(void);
260 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
262 static void DrawChoosePlayerName(void);
263 static void DrawChooseLevelSet(void);
264 static void DrawChooseLevelNr(void);
265 static void DrawScoreInfo(int);
266 static void DrawInfoScreen(void);
267 static void DrawSetupScreen(void);
268 static void DrawTypeName(void);
270 static void DrawInfoScreen_NotAvailable(char *, char *);
271 static void DrawInfoScreen_HelpAnim(int, int, boolean);
272 static void DrawInfoScreen_HelpText(int, int, int, int);
273 static void HandleInfoScreen_Main(int, int, int, int, int);
274 static void HandleInfoScreen_TitleScreen(int);
275 static void HandleInfoScreen_Elements(int);
276 static void HandleInfoScreen_Music(int);
277 static void HandleInfoScreen_Credits(int);
278 static void HandleInfoScreen_Program(int);
279 static void HandleInfoScreen_Version(int);
281 static void ModifyGameSpeedIfNeeded(void);
282 static void DisableVsyncIfNeeded(void);
284 static void RedrawScreenMenuGadgets(int);
285 static void MapScreenMenuGadgets(int);
286 static void UnmapScreenMenuGadgets(int);
287 static void MapScreenGadgets(int);
288 static void UnmapScreenGadgets(void);
289 static void MapScreenTreeGadgets(TreeInfo *);
290 static void UnmapScreenTreeGadgets(void);
292 static void UpdateScreenMenuGadgets(int, boolean);
294 static boolean OfferUploadTapes(void);
295 static void execOfferUploadTapes(void);
297 static void DrawHallOfFame_setScoreEntries(void);
298 static void HandleHallOfFame_SelectLevel(int, int);
299 static char *getHallOfFameRankText(int);
300 static char *getHallOfFameScoreText(int);
302 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
304 static int info_mode = INFO_MODE_MAIN;
305 static int setup_mode = SETUP_MODE_MAIN;
307 static TreeInfo *window_sizes = NULL;
308 static TreeInfo *window_size_current = NULL;
310 static TreeInfo *scaling_types = NULL;
311 static TreeInfo *scaling_type_current = NULL;
313 static TreeInfo *rendering_modes = NULL;
314 static TreeInfo *rendering_mode_current = NULL;
316 static TreeInfo *vsync_modes = NULL;
317 static TreeInfo *vsync_mode_current = NULL;
319 static TreeInfo *scroll_delays = NULL;
320 static TreeInfo *scroll_delay_current = NULL;
322 static TreeInfo *snapshot_modes = NULL;
323 static TreeInfo *snapshot_mode_current = NULL;
325 static TreeInfo *scores_types = NULL;
326 static TreeInfo *scores_type_current = NULL;
328 static TreeInfo *game_speeds_normal = NULL;
329 static TreeInfo *game_speeds_extended = NULL;
330 static TreeInfo *game_speeds = NULL;
331 static TreeInfo *game_speed_current = NULL;
333 static TreeInfo *volumes_simple = NULL;
334 static TreeInfo *volume_simple_current = NULL;
336 static TreeInfo *volumes_loops = NULL;
337 static TreeInfo *volume_loops_current = NULL;
339 static TreeInfo *volumes_music = NULL;
340 static TreeInfo *volume_music_current = NULL;
342 static TreeInfo *touch_controls = NULL;
343 static TreeInfo *touch_control_current = NULL;
345 static TreeInfo *move_distances = NULL;
346 static TreeInfo *move_distance_current = NULL;
348 static TreeInfo *drop_distances = NULL;
349 static TreeInfo *drop_distance_current = NULL;
351 static TreeInfo *transparencies = NULL;
352 static TreeInfo *transparency_current = NULL;
354 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
355 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
357 static TreeInfo *player_name = NULL;
358 static TreeInfo *player_name_current = NULL;
360 static TreeInfo *level_number = NULL;
361 static TreeInfo *level_number_current = NULL;
363 static TreeInfo *score_entries = NULL;
364 static TreeInfo *score_entry_current = NULL;
366 static struct ValueTextInfo window_sizes_list[] =
371 { 100, "100 % (Default)" },
384 static struct StringValueTextInfo scaling_types_list[] =
386 { SCALING_QUALITY_NEAREST, "Off" },
387 { SCALING_QUALITY_LINEAR, "Linear" },
388 { SCALING_QUALITY_BEST, "Anisotropic" },
393 static struct StringValueTextInfo rendering_modes_list[] =
395 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
396 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
398 // this mode may work under certain conditions, but does not work on Windows
399 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
401 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
406 static struct StringValueTextInfo vsync_modes_list[] =
408 { STR_VSYNC_MODE_OFF, "Off" },
409 { STR_VSYNC_MODE_NORMAL, "Normal" },
410 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
415 static struct StringValueTextInfo scores_types_list[] =
417 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
418 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
419 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
424 static struct ValueTextInfo game_speeds_list_normal[] =
435 static struct ValueTextInfo game_speeds_list_extended[] =
437 { 1000, "1 fps (Extremely Slow)" },
442 { 29, "35 fps (Original Supaplex)" },
444 { 20, "50 fps (=== Normal Speed ===)" },
445 { 16, "60 fps (60 Hz VSync Speed)" },
446 { 14, "70 fps (Maximum Supaplex)" },
450 { 1, "1000 fps (Extremely Fast)" },
455 static struct ValueTextInfo *game_speeds_list;
457 static struct ValueTextInfo scroll_delays_list[] =
459 { 0, "0 Tiles (No Scroll Delay)" },
462 { 3, "3 Tiles (Default)" },
467 { 8, "8 Tiles (Maximum Scroll Delay)"},
472 static struct StringValueTextInfo snapshot_modes_list[] =
474 { STR_SNAPSHOT_MODE_OFF, "Off" },
475 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
476 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
477 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
482 static struct ValueTextInfo volumes_list[] =
502 static struct StringValueTextInfo touch_controls_list[] =
504 { TOUCH_CONTROL_OFF, "Off" },
505 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
506 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
507 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
512 static struct ValueTextInfo distances_list[] =
527 static struct ValueTextInfo transparencies_list[] =
529 { 0, "0 % (Opaque)" },
539 { 100, "100 % (Invisible)" },
544 static struct ValueTextInfo grid_sizes_list[] =
580 static int align_xoffset = 0;
581 static int align_yoffset = 0;
583 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
584 (s) <= GAME_MODE_SETUP ? (s) : \
585 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
587 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
588 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
590 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
591 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
592 (i) <= INFO_MODE_LEVELSET ? (i) : \
595 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
596 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
597 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
598 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
599 SETUP_MODE_CHOOSE_ARTWORK : \
600 SETUP_MODE_CHOOSE_OTHER)
602 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
603 menu.draw_xoffset[GAME_MODE_INFO] : \
604 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
605 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
606 menu.draw_yoffset[GAME_MODE_INFO] : \
607 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
608 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
609 menu.extra_spacing[GAME_MODE_INFO] : \
610 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
612 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
613 menu.draw_xoffset[GAME_MODE_SETUP] : \
614 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
615 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
616 menu.draw_yoffset[GAME_MODE_SETUP] : \
617 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
618 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
619 menu.extra_spacing[GAME_MODE_SETUP] : \
620 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
622 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
624 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
626 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
627 DRAW_XOFFSET_INFO(info_mode) : \
628 (s) == GAME_MODE_SETUP ? \
629 DRAW_XOFFSET_SETUP(setup_mode) : \
630 menu.draw_xoffset[DRAW_MODE(s)])
631 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
632 DRAW_YOFFSET_INFO(info_mode) : \
633 (s) == GAME_MODE_SETUP ? \
634 DRAW_YOFFSET_SETUP(setup_mode) : \
635 menu.draw_yoffset[DRAW_MODE(s)])
636 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
637 EXTRA_SPACING_INFO(info_mode) : \
638 (s) == GAME_MODE_SETUP ? \
639 EXTRA_SPACING_SETUP(setup_mode) : \
640 (s) == GAME_MODE_SCORES ? \
641 EXTRA_SPACING_SCORES(info_mode) : \
642 menu.extra_spacing[DRAW_MODE(s)])
644 #define mSX (SX + DRAW_XOFFSET(game_status))
645 #define mSY (SY + DRAW_YOFFSET(game_status))
647 #define amSX (mSX + align_xoffset)
648 #define amSY (mSY + align_yoffset)
650 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
651 menu.list_size[game_status] : \
652 MAX_MENU_ENTRIES_ON_SCREEN)
654 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
655 NUM_MENU_ENTRIES_ON_SCREEN)
658 // title display and control definitions
660 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
661 2 * MAX_NUM_TITLE_MESSAGES)
663 #define NO_DIRECT_LEVEL_SELECT (-1)
666 static int num_title_screens = 0;
668 struct TitleControlInfo
677 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
679 // main menu display and control definitions
681 #define MAIN_CONTROL_NAME 0
682 #define MAIN_CONTROL_LEVELS 1
683 #define MAIN_CONTROL_SCORES 2
684 #define MAIN_CONTROL_EDITOR 3
685 #define MAIN_CONTROL_INFO 4
686 #define MAIN_CONTROL_GAME 5
687 #define MAIN_CONTROL_SETUP 6
688 #define MAIN_CONTROL_QUIT 7
689 #define MAIN_CONTROL_PREV_LEVEL 8
690 #define MAIN_CONTROL_NEXT_LEVEL 9
691 #define MAIN_CONTROL_FIRST_LEVEL 10
692 #define MAIN_CONTROL_LAST_LEVEL 11
693 #define MAIN_CONTROL_LEVEL_NUMBER 12
694 #define MAIN_CONTROL_LEVEL_INFO_1 13
695 #define MAIN_CONTROL_LEVEL_INFO_2 14
696 #define MAIN_CONTROL_LEVEL_NAME 15
697 #define MAIN_CONTROL_LEVEL_AUTHOR 16
698 #define MAIN_CONTROL_LEVEL_YEAR 17
699 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
700 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
701 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
702 #define MAIN_CONTROL_TITLE_1 21
703 #define MAIN_CONTROL_TITLE_2 22
704 #define MAIN_CONTROL_TITLE_3 23
706 static char str_main_text_name[10];
707 static char str_main_text_first_level[10];
708 static char str_main_text_last_level[10];
709 static char str_main_text_level_number[10];
711 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
713 static char *main_text_name = str_main_text_name;
714 static char *main_text_first_level = str_main_text_first_level;
715 static char *main_text_last_level = str_main_text_last_level;
716 static char *main_text_level_number = str_main_text_level_number;
717 static char *main_text_levels = "Levelset";
718 static char *main_text_scores = "Hall Of Fame";
719 static char *main_text_editor = "Level Creator";
720 static char *main_text_info = "Info Screen";
721 static char *main_text_game = "Start Game";
722 static char *main_text_setup = "Setup";
723 static char *main_text_quit = "Quit";
724 static char *main_text_level_name = level.name;
725 static char *main_text_level_author = level.author;
726 static char *main_text_level_year = NULL;
727 static char *main_text_level_imported_from = NULL;
728 static char *main_text_level_imported_by = NULL;
729 static char *main_text_level_tested_by = NULL;
730 static char *main_text_title_1 = NULL;
731 static char *main_text_title_2 = NULL;
732 static char *main_text_title_3 = NULL;
734 extern char debug_xsn_mode[];
736 struct MainControlInfo
740 struct MenuPosInfo *pos_button;
743 struct TextPosInfo *pos_text;
746 struct TextPosInfo *pos_input;
750 static struct MainControlInfo main_controls[] =
754 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
755 &menu.main.text.name, &main_text_name,
756 &menu.main.input.name, &setup.player_name,
760 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
761 &menu.main.text.levels, &main_text_levels,
766 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
767 &menu.main.text.scores, &main_text_scores,
772 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
773 &menu.main.text.editor, &main_text_editor,
778 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
779 &menu.main.text.info, &main_text_info,
784 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
785 &menu.main.text.game, &main_text_game,
790 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
791 &menu.main.text.setup, &main_text_setup,
796 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
797 &menu.main.text.quit, &main_text_quit,
801 MAIN_CONTROL_PREV_LEVEL,
807 MAIN_CONTROL_NEXT_LEVEL,
813 MAIN_CONTROL_FIRST_LEVEL,
815 &menu.main.text.first_level, &main_text_first_level,
819 MAIN_CONTROL_LAST_LEVEL,
821 &menu.main.text.last_level, &main_text_last_level,
825 MAIN_CONTROL_LEVEL_NUMBER,
827 &menu.main.text.level_number, &main_text_level_number,
831 MAIN_CONTROL_LEVEL_INFO_1,
833 &menu.main.text.level_info_1, NULL,
837 MAIN_CONTROL_LEVEL_INFO_2,
839 &menu.main.text.level_info_2, NULL,
843 MAIN_CONTROL_LEVEL_NAME,
845 &menu.main.text.level_name, &main_text_level_name,
849 MAIN_CONTROL_LEVEL_AUTHOR,
851 &menu.main.text.level_author, &main_text_level_author,
855 MAIN_CONTROL_LEVEL_YEAR,
857 &menu.main.text.level_year, &main_text_level_year,
861 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
863 &menu.main.text.level_imported_from, &main_text_level_imported_from,
867 MAIN_CONTROL_LEVEL_IMPORTED_BY,
869 &menu.main.text.level_imported_by, &main_text_level_imported_by,
873 MAIN_CONTROL_LEVEL_TESTED_BY,
875 &menu.main.text.level_tested_by, &main_text_level_tested_by,
879 MAIN_CONTROL_TITLE_1,
881 &menu.main.text.title_1, &main_text_title_1,
885 MAIN_CONTROL_TITLE_2,
887 &menu.main.text.title_2, &main_text_title_2,
891 MAIN_CONTROL_TITLE_3,
893 &menu.main.text.title_3, &main_text_title_3,
906 static int getTitleScreenGraphic(int nr, boolean initial)
908 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
911 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
913 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
917 static int getTitleScreenGameMode(boolean initial)
919 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
923 static int getTitleMessageGameMode(boolean initial)
925 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
928 static int getTitleAnimMode(struct TitleControlInfo *tci)
930 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
932 return base + tci->local_nr;
936 static int getTitleScreenBackground(boolean initial)
938 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
943 static int getTitleMessageBackground(int nr, boolean initial)
945 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
949 static int getTitleBackground(int nr, boolean initial, boolean is_image)
951 int base = (is_image ?
952 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
953 IMG_BACKGROUND_TITLESCREEN_1) :
954 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
955 IMG_BACKGROUND_TITLEMESSAGE_1));
956 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
957 IMG_BACKGROUND_TITLE);
958 int graphic_local = base + nr;
960 if (graphic_info[graphic_local].bitmap != NULL)
961 return graphic_local;
963 if (graphic_info[graphic_global].bitmap != NULL)
964 return graphic_global;
966 return IMG_UNDEFINED;
969 static int getTitleSound(struct TitleControlInfo *tci)
971 boolean is_image = tci->is_image;
972 int initial = tci->initial;
973 int nr = tci->local_nr;
974 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
975 int base = (is_image ?
976 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
977 SND_BACKGROUND_TITLESCREEN_1) :
978 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
979 SND_BACKGROUND_TITLEMESSAGE_1));
980 int sound_global = menu.sound[mode];
981 int sound_local = base + nr;
984 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
985 nr, initial, is_image,
986 sound_global, getSoundListEntry(sound_global)->filename,
987 sound_local, getSoundListEntry(sound_local)->filename);
990 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
993 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
996 return SND_UNDEFINED;
999 static int getTitleMusic(struct TitleControlInfo *tci)
1001 boolean is_image = tci->is_image;
1002 int initial = tci->initial;
1003 int nr = tci->local_nr;
1004 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1005 int base = (is_image ?
1006 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1007 MUS_BACKGROUND_TITLESCREEN_1) :
1008 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1009 MUS_BACKGROUND_TITLEMESSAGE_1));
1010 int music_global = menu.music[mode];
1011 int music_local = base + nr;
1014 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1015 nr, initial, is_image,
1016 music_global, getMusicListEntry(music_global)->filename,
1017 music_local, getMusicListEntry(music_local)->filename);
1020 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1023 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1024 return music_global;
1026 return MUS_UNDEFINED;
1029 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1031 boolean is_image = tci->is_image;
1032 boolean initial = tci->initial;
1033 boolean first = tci->first;
1034 int nr = tci->local_nr;
1035 struct TitleMessageInfo tmi;
1036 struct TitleFadingInfo ti;
1038 tmi = (is_image ? (initial ? (first ?
1039 titlescreen_initial_first[nr] :
1040 titlescreen_initial[nr])
1042 titlescreen_first[nr] :
1044 : (initial ? (first ?
1045 titlemessage_initial_first[nr] :
1046 titlemessage_initial[nr])
1048 titlemessage_first[nr] :
1049 titlemessage[nr])));
1051 ti.fade_mode = tmi.fade_mode;
1052 ti.fade_delay = tmi.fade_delay;
1053 ti.post_delay = tmi.post_delay;
1054 ti.auto_delay = tmi.auto_delay;
1055 ti.auto_delay_unit = tmi.auto_delay_unit;
1060 static int compareTitleControlInfo(const void *object1, const void *object2)
1062 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1063 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1066 if (tci1->initial != tci2->initial)
1067 compare_result = (tci1->initial ? -1 : +1);
1068 else if (tci1->sort_priority != tci2->sort_priority)
1069 compare_result = tci1->sort_priority - tci2->sort_priority;
1070 else if (tci1->is_image != tci2->is_image)
1071 compare_result = (tci1->is_image ? -1 : +1);
1073 compare_result = tci1->local_nr - tci2->local_nr;
1075 return compare_result;
1078 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1080 int nr, int sort_priority)
1082 title_controls[num_title_screens].is_image = is_image;
1083 title_controls[num_title_screens].initial = initial;
1084 title_controls[num_title_screens].local_nr = nr;
1085 title_controls[num_title_screens].sort_priority = sort_priority;
1087 title_controls[num_title_screens].first = FALSE; // will be set later
1089 num_title_screens++;
1092 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1096 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1098 int graphic = getTitleScreenGraphic(i, initial);
1099 Bitmap *bitmap = graphic_info[graphic].bitmap;
1100 int sort_priority = graphic_info[graphic].sort_priority;
1103 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1106 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1108 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1109 char *filename = getLevelSetTitleMessageFilename(i, initial);
1110 int sort_priority = tmi->sort_priority;
1112 if (filename != NULL)
1113 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1117 static void InitializeTitleControls(boolean show_title_initial)
1119 num_title_screens = 0;
1121 // 1st step: initialize title screens for game start (only when starting)
1122 if (show_title_initial)
1123 InitializeTitleControls_CheckTitleInfo(TRUE);
1125 // 2nd step: initialize title screens for current level set
1126 InitializeTitleControls_CheckTitleInfo(FALSE);
1128 // sort title screens according to sort_priority and title number
1129 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1130 compareTitleControlInfo);
1132 // mark first title screen
1133 title_controls[0].first = TRUE;
1136 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1138 return (pos != NULL && pos->x != -1 && pos->y != -1);
1141 static boolean visibleTextPos(struct TextPosInfo *pos)
1143 return (pos != NULL && pos->x != -1 && pos->y != -1);
1146 static void InitializeMainControls(void)
1148 boolean local_team_mode = (!network.enabled && setup.team_mode);
1151 // set main control text values to dynamically determined values
1152 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1154 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1155 menu.main.text.first_level.size));
1156 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1157 menu.main.text.last_level.size));
1158 strcpy(main_text_level_number, int2str(level_nr,
1159 menu.main.text.level_number.size));
1161 main_text_level_year = leveldir_current->year;
1162 main_text_level_imported_from = leveldir_current->imported_from;
1163 main_text_level_imported_by = leveldir_current->imported_by;
1164 main_text_level_tested_by = leveldir_current->tested_by;
1166 main_text_title_1 = getConfigProgramTitleString();
1167 main_text_title_2 = getConfigProgramCopyrightString();
1168 main_text_title_3 = getConfigProgramCompanyString();
1170 // set main control screen positions to dynamically determined values
1171 for (i = 0; main_controls[i].nr != -1; i++)
1173 struct MainControlInfo *mci = &main_controls[i];
1175 struct MenuPosInfo *pos_button = mci->pos_button;
1176 struct TextPosInfo *pos_text = mci->pos_text;
1177 struct TextPosInfo *pos_input = mci->pos_input;
1178 char *text = (mci->text ? *mci->text : NULL);
1179 char *input = (mci->input ? *mci->input : NULL);
1180 int button_graphic = mci->button_graphic;
1181 int font_text = (pos_text ? pos_text->font : -1);
1182 int font_input = (pos_input ? pos_input->font : -1);
1184 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1185 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1186 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1187 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1188 int text_chars = (text != NULL ? strlen(text) : 0);
1189 int input_chars = (input != NULL ? strlen(input) : 0);
1192 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1194 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1195 int text_width = font_text_width * text_chars;
1196 int text_height = font_text_height;
1197 int input_width = font_input_width * input_chars;
1198 int input_height = font_input_height;
1200 if (nr == MAIN_CONTROL_NAME)
1202 menu.main.input.name.width = input_width;
1203 menu.main.input.name.height = input_height;
1206 if (pos_button != NULL) // (x/y may be -1/-1 here)
1208 pos_button->width = button_width;
1209 pos_button->height = button_height;
1212 if (pos_text != NULL) // (x/y may be -1/-1 here)
1214 // calculate text size -- needed for text alignment
1215 boolean calculate_text_size = (text != NULL);
1217 if (pos_text->width == -1 || calculate_text_size)
1218 pos_text->width = text_width;
1219 if (pos_text->height == -1 || calculate_text_size)
1220 pos_text->height = text_height;
1222 if (visibleMenuPos(pos_button))
1224 if (pos_text->x == -1)
1225 pos_text->x = pos_button->x + pos_button->width;
1226 if (pos_text->y == -1)
1228 pos_button->y + (pos_button->height - pos_text->height) / 2;
1232 if (pos_input != NULL) // (x/y may be -1/-1 here)
1234 if (visibleTextPos(pos_text))
1236 if (pos_input->x == -1)
1237 pos_input->x = pos_text->x + pos_text->width;
1238 if (pos_input->y == -1)
1239 pos_input->y = pos_text->y;
1242 if (pos_input->width == -1)
1243 pos_input->width = input_width;
1244 if (pos_input->height == -1)
1245 pos_input->height = input_height;
1250 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1251 int graphic, boolean pressed)
1253 struct GraphicInfo *g = &graphic_info[graphic];
1256 int xoffset = (pressed ? g->pressed_xoffset : 0);
1257 int yoffset = (pressed ? g->pressed_yoffset : 0);
1259 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1261 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1262 g->width, g->height, dst_x, dst_y);
1265 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1266 boolean active_input,
1267 boolean pressed_button)
1271 for (i = 0; main_controls[i].nr != -1; i++)
1273 struct MainControlInfo *mci = &main_controls[i];
1275 if (mci->nr == nr || nr == -1)
1277 struct MenuPosInfo *pos_button = mci->pos_button;
1278 struct TextPosInfo *pos_text = mci->pos_text;
1279 struct TextPosInfo *pos_input = mci->pos_input;
1280 char *text = (mci->text ? *mci->text : NULL);
1281 char *input = (mci->input ? *mci->input : NULL);
1282 int button_graphic = mci->button_graphic;
1283 int font_text = (pos_text ? pos_text->font : -1);
1284 int font_input = (pos_input ? pos_input->font : -1);
1288 button_graphic = BUTTON_ACTIVE(button_graphic);
1289 font_text = FONT_ACTIVE(font_text);
1294 font_input = FONT_ACTIVE(font_input);
1297 if (visibleMenuPos(pos_button))
1299 struct MenuPosInfo *pos = pos_button;
1300 int x = mSX + pos->x;
1301 int y = mSY + pos->y;
1303 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1304 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1307 if (visibleTextPos(pos_text) && text != NULL)
1309 struct TextPosInfo *pos = pos_text;
1310 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1311 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1314 // (check why/if this is needed)
1315 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1317 DrawText(x, y, text, font_text);
1320 if (visibleTextPos(pos_input) && input != NULL)
1322 struct TextPosInfo *pos = pos_input;
1323 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1324 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1327 // (check why/if this is needed)
1328 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1330 DrawText(x, y, input, font_input);
1336 static void DrawCursorAndText_Main(int nr, boolean active_text,
1337 boolean pressed_button)
1339 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1343 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1344 boolean pressed_button)
1346 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1350 static struct MainControlInfo *getMainControlInfo(int nr)
1354 for (i = 0; main_controls[i].nr != -1; i++)
1355 if (main_controls[i].nr == nr)
1356 return &main_controls[i];
1361 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1366 int rect_x = ALIGNED_TEXT_XPOS(rect);
1367 int rect_y = ALIGNED_TEXT_YPOS(rect);
1369 return (x >= rect_x && x < rect_x + rect->width &&
1370 y >= rect_y && y < rect_y + rect->height);
1373 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1378 int rect_x = ALIGNED_TEXT_XPOS(rect);
1379 int rect_y = ALIGNED_TEXT_YPOS(rect);
1382 Debug("screens:insideTextPosRect",
1383 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1384 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1385 (x >= rect_x && x < rect_x + rect->width &&
1386 y >= rect_y && y < rect_y + rect->height));
1389 return (x >= rect_x && x < rect_x + rect->width &&
1390 y >= rect_y && y < rect_y + rect->height);
1393 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1395 int rect_width = preview->xsize * preview->tile_size;
1396 int rect_height = preview->ysize * preview->tile_size;
1397 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1398 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1400 return (x >= rect_x && x < rect_x + rect_width &&
1401 y >= rect_y && y < rect_y + rect_height);
1404 static void AdjustScrollbar(int id, int items_max, int items_visible,
1407 struct GadgetInfo *gi = screen_gadget[id];
1409 if (item_position > items_max - items_visible)
1410 item_position = items_max - items_visible;
1412 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1413 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1414 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1417 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1419 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1423 static void clearMenuListArea(void)
1425 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1427 // correct scrollbar position if placed outside menu (playfield) area
1428 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1429 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1431 // clear menu list area, but not title or scrollbar
1432 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1433 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1436 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1438 static int cursor_array[MAX_LEV_FIELDY];
1439 int x = amSX + TILEX * xpos;
1440 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1445 cursor_array[ypos] = graphic;
1447 graphic = cursor_array[ypos];
1451 graphic = BUTTON_ACTIVE(graphic);
1453 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1454 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1457 static void initCursor(int ypos, int graphic)
1459 drawCursorExt(0, ypos, FALSE, graphic);
1462 static void drawCursor(int ypos, boolean active)
1464 drawCursorExt(0, ypos, active, -1);
1467 static void drawCursorXY(int xpos, int ypos, int graphic)
1469 drawCursorExt(xpos, ypos, FALSE, graphic);
1472 static void drawChooseTreeCursor(int ypos, boolean active)
1474 drawCursorExt(0, ypos, active, -1);
1477 static int getChooseTreeEditFont(boolean active)
1479 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1482 static int getChooseTreeEditXPos(int pos)
1484 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1485 int xoffset = (has_scrollbar ? -1 : 0);
1486 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1487 int sx = amSX + xpos * TILEX;
1488 int font_nr = getChooseTreeEditFont(FALSE);
1489 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1491 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1494 static int getChooseTreeEditYPos(int ypos_raw)
1496 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1497 int sy = amSY + ypos * TILEY;
1502 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1504 int sx = getChooseTreeEditXPos(POS_LEFT);
1505 int sy = getChooseTreeEditYPos(ypos_raw);
1506 int font_nr = getChooseTreeEditFont(active);
1508 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1511 static void DrawHeadline(void)
1513 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1514 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1517 static void DrawTitleScreenImage(int nr, boolean initial)
1519 int graphic = getTitleScreenGraphic(nr, initial);
1520 Bitmap *bitmap = graphic_info[graphic].bitmap;
1521 int width = graphic_info[graphic].width;
1522 int height = graphic_info[graphic].height;
1523 int src_x = graphic_info[graphic].src_x;
1524 int src_y = graphic_info[graphic].src_y;
1530 if (width > WIN_XSIZE)
1532 // image width too large for window => center image horizontally
1533 src_x = (width - WIN_XSIZE) / 2;
1537 if (height > WIN_YSIZE)
1539 // image height too large for window => center image vertically
1540 src_y = (height - WIN_YSIZE) / 2;
1544 // always display title screens centered
1545 dst_x = (WIN_XSIZE - width) / 2;
1546 dst_y = (WIN_YSIZE - height) / 2;
1548 SetDrawBackgroundMask(REDRAW_ALL);
1549 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1551 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1553 if (DrawingOnBackground(dst_x, dst_y))
1554 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1556 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1558 redraw_mask = REDRAW_ALL;
1561 static void DrawTitleScreenMessage(int nr, boolean initial)
1563 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1564 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1566 if (filename == NULL)
1569 // force TITLE font on title message screen
1570 SetFontStatus(getTitleMessageGameMode(initial));
1572 // if chars *and* width set to "-1", automatically determine width
1573 if (tmi->chars == -1 && tmi->width == -1)
1574 tmi->width = viewport.window[game_status].width;
1576 // if lines *and* height set to "-1", automatically determine height
1577 if (tmi->lines == -1 && tmi->height == -1)
1578 tmi->height = viewport.window[game_status].height;
1580 // if chars set to "-1", automatically determine by text and font width
1581 if (tmi->chars == -1)
1582 tmi->chars = tmi->width / getFontWidth(tmi->font);
1584 tmi->width = tmi->chars * getFontWidth(tmi->font);
1586 // if lines set to "-1", automatically determine by text and font height
1587 if (tmi->lines == -1)
1588 tmi->lines = tmi->height / getFontHeight(tmi->font);
1590 tmi->height = tmi->lines * getFontHeight(tmi->font);
1592 // if x set to "-1", automatically determine by width and alignment
1594 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1596 // if y set to "-1", automatically determine by height and alignment
1598 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1600 SetDrawBackgroundMask(REDRAW_ALL);
1601 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1603 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1605 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1606 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1607 tmi->autowrap, tmi->centered, tmi->parse_comments);
1612 static void DrawTitleScreen(void)
1614 KeyboardAutoRepeatOff();
1616 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1619 static boolean CheckTitleScreen(boolean levelset_has_changed)
1621 static boolean show_title_initial = TRUE;
1622 boolean show_titlescreen = FALSE;
1624 // needed to be able to skip title screen, if no image or message defined
1625 InitializeTitleControls(show_title_initial);
1627 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1628 show_titlescreen = TRUE;
1630 // show initial title images and messages only once at program start
1631 show_title_initial = FALSE;
1633 return (show_titlescreen && num_title_screens > 0);
1636 void DrawMainMenu(void)
1638 static LevelDirTree *leveldir_last_valid = NULL;
1639 boolean levelset_has_changed = FALSE;
1640 int fade_mask = REDRAW_FIELD;
1642 LimitScreenUpdates(FALSE);
1644 FadeSetLeaveScreen();
1646 // do not fade out here -- function may continue and fade on editor screen
1649 FadeMenuSoundsAndMusic();
1651 ExpireSoundLoops(FALSE);
1653 KeyboardAutoRepeatOn();
1655 audio.sound_deactivated = FALSE;
1659 // needed if last screen was the playing screen, invoked from level editor
1660 if (level_editor_test_game)
1662 CloseDoor(DOOR_CLOSE_ALL);
1664 SetGameStatus(GAME_MODE_EDITOR);
1671 // leveldir_current may be invalid (level group, parent link, node copy)
1672 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1674 if (leveldir_current != leveldir_last_valid)
1676 UpdateLastPlayedLevels_TreeInfo();
1678 levelset_has_changed = TRUE;
1681 // store valid level series information
1682 leveldir_last_valid = leveldir_current;
1684 init_last = init; // switch to new busy animation
1686 // needed if last screen (level choice) changed graphics, sounds or music
1687 ReloadCustomArtwork(0);
1689 if (CheckTitleScreen(levelset_has_changed))
1691 SetGameStatus(GAME_MODE_TITLE);
1698 if (redraw_mask & REDRAW_ALL)
1699 fade_mask = REDRAW_ALL;
1702 fade_mask = REDRAW_ALL;
1706 // needed if different viewport properties defined for menues
1707 ChangeViewportPropertiesIfNeeded();
1709 SetDrawtoField(DRAW_TO_BACKBUFFER);
1711 // level_nr may have been set to value over handicap with level editor
1712 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1713 level_nr = leveldir_current->handicap_level;
1715 LoadLevel(level_nr);
1716 LoadScore(level_nr);
1718 SaveLevelSetup_SeriesInfo();
1720 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1721 SetDrawDeactivationMask(REDRAW_NONE);
1722 SetDrawBackgroundMask(REDRAW_FIELD);
1724 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1727 if (fade_mask == REDRAW_ALL)
1728 RedrawGlobalBorder();
1733 InitializeMainControls();
1735 DrawCursorAndText_Main(-1, FALSE, FALSE);
1736 DrawPreviewLevelInitial();
1737 DrawNetworkPlayers();
1739 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1742 if (TAPE_IS_EMPTY(tape))
1744 DrawCompleteVideoDisplay();
1746 PlayMenuSoundsAndMusic();
1748 // create gadgets for main menu screen
1749 FreeScreenGadgets();
1750 CreateScreenGadgets();
1752 // may be required if audio buttons shown on tape and changed in setup menu
1754 CreateGameButtons();
1756 // map gadgets for main menu screen
1758 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1759 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1761 // copy actual game door content to door double buffer for OpenDoor()
1762 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1763 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1765 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1767 DrawMaskedBorder(fade_mask);
1772 // update screen area with special editor door
1773 redraw_mask |= REDRAW_ALL;
1776 SetMouseCursor(CURSOR_DEFAULT);
1778 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1780 SyncEmscriptenFilesystem();
1782 // needed once after program start or after user change
1783 CheckApiServerTasks();
1786 static void gotoTopLevelDir(void)
1788 // move upwards until inside (but not above) top level directory
1789 while (leveldir_current->node_parent &&
1790 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1792 // write a "path" into level tree for easy navigation to last level
1793 if (leveldir_current->node_parent->node_group->cl_first == -1)
1795 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1796 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1797 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1798 int cl_first, cl_cursor;
1800 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1801 cl_cursor = leveldir_pos - cl_first;
1803 leveldir_current->node_parent->node_group->cl_first = cl_first;
1804 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1807 leveldir_current = leveldir_current->node_parent;
1811 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1813 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1815 return (use_frame_counter ? video.frame_counter : Counter());
1818 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1819 struct TitleFadingInfo *fi)
1821 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1824 static void ResetTitleAutoDelay(unsigned int *counter_var,
1825 struct TitleFadingInfo *fi)
1827 *counter_var = getAutoDelayCounter(fi);
1830 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1832 static unsigned int title_delay = 0;
1833 static int title_screen_nr = 0;
1834 static int last_sound = -1, last_music = -1;
1835 boolean return_to_main_menu = FALSE;
1836 struct TitleControlInfo *tci;
1839 if (button == MB_MENU_INITIALIZE)
1842 title_screen_nr = 0;
1843 tci = &title_controls[title_screen_nr];
1845 SetAnimStatus(getTitleAnimMode(tci));
1847 last_sound = SND_UNDEFINED;
1848 last_music = MUS_UNDEFINED;
1850 if (num_title_screens != 0)
1852 FadeSetEnterScreen();
1854 // use individual title fading instead of global "enter screen" fading
1855 fading = getTitleFading(tci);
1858 if (game_status_last_screen == GAME_MODE_INFO)
1860 if (num_title_screens == 0)
1862 // switch game mode from title screen mode back to info screen mode
1863 SetGameStatus(GAME_MODE_INFO);
1865 // store that last screen was info screen, not main menu screen
1866 game_status_last_screen = GAME_MODE_INFO;
1868 DrawInfoScreen_NotAvailable("Title screen information:",
1869 "No title screen for this level set.");
1874 FadeMenuSoundsAndMusic();
1876 FadeOut(REDRAW_ALL);
1878 // title screens may have different window size
1879 ChangeViewportPropertiesIfNeeded();
1881 // only required to update logic for redrawing global border
1885 DrawTitleScreenImage(tci->local_nr, tci->initial);
1887 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1889 sound = getTitleSound(tci);
1890 music = getTitleMusic(tci);
1892 if (sound != last_sound)
1893 PlayMenuSoundExt(sound);
1894 if (music != last_music)
1895 PlayMenuMusicExt(music);
1900 SetMouseCursor(CURSOR_NONE);
1904 ResetTitleAutoDelay(&title_delay, &fading);
1909 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1910 button = MB_MENU_CHOICE;
1912 if (button == MB_MENU_LEAVE)
1914 return_to_main_menu = TRUE;
1916 else if (button == MB_MENU_CHOICE)
1918 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1920 SetGameStatus(GAME_MODE_INFO);
1922 info_mode = INFO_MODE_MAIN;
1931 if (title_screen_nr < num_title_screens)
1933 tci = &title_controls[title_screen_nr];
1935 SetAnimStatus(getTitleAnimMode(tci));
1937 sound = getTitleSound(tci);
1938 music = getTitleMusic(tci);
1940 if (last_sound != SND_UNDEFINED && sound != last_sound)
1941 FadeSound(last_sound);
1942 if (last_music != MUS_UNDEFINED && music != last_music)
1945 fading = getTitleFading(tci);
1947 FadeOut(REDRAW_ALL);
1950 DrawTitleScreenImage(tci->local_nr, tci->initial);
1952 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1954 sound = getTitleSound(tci);
1955 music = getTitleMusic(tci);
1957 if (sound != last_sound)
1958 PlayMenuSoundExt(sound);
1959 if (music != last_music)
1960 PlayMenuMusicExt(music);
1967 ResetTitleAutoDelay(&title_delay, &fading);
1971 FadeMenuSoundsAndMusic();
1973 return_to_main_menu = TRUE;
1977 if (return_to_main_menu)
1979 SetMouseCursor(CURSOR_DEFAULT);
1981 // force full menu screen redraw after displaying title screens
1982 redraw_mask = REDRAW_ALL;
1984 if (game_status_last_screen == GAME_MODE_INFO)
1986 SetGameStatus(GAME_MODE_INFO);
1988 info_mode = INFO_MODE_MAIN;
1992 else // default: return to main menu
1994 SetGameStatus(GAME_MODE_MAIN);
2001 static void HandleMainMenu_ToggleTeamMode(void)
2003 setup.team_mode = !setup.team_mode;
2005 InitializeMainControls();
2006 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2008 DrawPreviewPlayers();
2011 static void HandleMainMenu_SelectLevel(int step, int direction,
2012 int selected_level_nr)
2014 int old_level_nr = level_nr;
2017 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2018 new_level_nr = selected_level_nr;
2020 new_level_nr = old_level_nr + step * direction;
2022 if (new_level_nr < leveldir_current->first_level)
2023 new_level_nr = leveldir_current->first_level;
2024 if (new_level_nr > leveldir_current->last_level)
2025 new_level_nr = leveldir_current->last_level;
2027 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2029 // skipping levels is only allowed when trying to skip single level
2030 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2031 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2033 leveldir_current->handicap_level++;
2034 SaveLevelSetup_SeriesInfo();
2037 new_level_nr = leveldir_current->handicap_level;
2040 if (new_level_nr != old_level_nr)
2042 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2044 PlaySound(SND_MENU_ITEM_SELECTING);
2046 level_nr = new_level_nr;
2048 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2049 int2str(level_nr, menu.main.text.level_number.size),
2050 mci->pos_text->font);
2052 LoadLevel(level_nr);
2053 DrawPreviewLevelInitial();
2057 DrawCompleteVideoDisplay();
2059 SaveLevelSetup_SeriesInfo();
2061 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2063 // force redraw of playfield area (may be reset at this point)
2064 redraw_mask |= REDRAW_FIELD;
2068 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2070 static int choice = MAIN_CONTROL_GAME;
2071 static boolean button_pressed_last = FALSE;
2072 boolean button_pressed = FALSE;
2074 int i = 0; // needed to prevent compiler warning due to bad code below
2076 if (button == MB_MENU_INITIALIZE)
2078 DrawCursorAndText_Main(choice, TRUE, FALSE);
2083 if (mx || my) // mouse input
2087 for (i = 0; main_controls[i].nr != -1; i++)
2089 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2090 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2091 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2093 pos = main_controls[i].nr;
2099 // check if level preview was clicked
2100 if (insidePreviewRect(&preview, mx - SX, my - SY))
2101 pos = MAIN_CONTROL_GAME;
2103 // handle pressed/unpressed state for active/inactive menu buttons
2104 // (if pos != -1, "i" contains index position corresponding to "pos")
2106 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2107 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2108 button_pressed = TRUE;
2110 if (button_pressed != button_pressed_last)
2112 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2115 PlaySound(SND_MENU_BUTTON_PRESSING);
2117 PlaySound(SND_MENU_BUTTON_RELEASING);
2120 else if (dx || dy) // keyboard input
2122 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2123 choice == MAIN_CONTROL_SETUP))
2124 button = MB_MENU_CHOICE;
2129 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2131 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2133 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2135 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2137 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2139 CloseDoor(DOOR_CLOSE_2);
2141 SetGameStatus(GAME_MODE_LEVELNR);
2143 DrawChooseLevelNr();
2145 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2151 PlaySound(SND_MENU_ITEM_ACTIVATING);
2153 DrawCursorAndText_Main(choice, FALSE, FALSE);
2154 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2160 if (choice == MAIN_CONTROL_NAME)
2162 // special case: cursor left or right pressed -- toggle team mode
2163 HandleMainMenu_ToggleTeamMode();
2165 else if (choice != MAIN_CONTROL_INFO &&
2166 choice != MAIN_CONTROL_SETUP)
2168 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2174 PlaySound(SND_MENU_ITEM_SELECTING);
2176 if (pos == MAIN_CONTROL_NAME)
2179 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2181 // special case: menu text "name/team" clicked -- toggle team mode
2182 HandleMainMenu_ToggleTeamMode();
2186 if (setup.multiple_users)
2188 CloseDoor(DOOR_CLOSE_2);
2190 SetGameStatus(GAME_MODE_NAMES);
2192 DrawChoosePlayerName();
2196 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2202 else if (pos == MAIN_CONTROL_LEVELS)
2206 CloseDoor(DOOR_CLOSE_2);
2208 SetGameStatus(GAME_MODE_LEVELS);
2210 SaveLevelSetup_LastSeries();
2211 SaveLevelSetup_SeriesInfo();
2213 // restore level set if chosen from "last played level set" menu
2214 RestoreLastPlayedLevels(&leveldir_current);
2216 if (setup.internal.choose_from_top_leveldir)
2219 DrawChooseLevelSet();
2222 else if (pos == MAIN_CONTROL_SCORES)
2224 CloseDoor(DOOR_CLOSE_2);
2226 SetGameStatus(GAME_MODE_SCORES);
2228 DrawHallOfFame(level_nr);
2230 else if (pos == MAIN_CONTROL_EDITOR)
2232 if (leveldir_current->readonly &&
2233 setup.editor.show_read_only_warning)
2234 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2236 CloseDoor(DOOR_CLOSE_ALL);
2238 SetGameStatus(GAME_MODE_EDITOR);
2240 FadeSetEnterScreen();
2244 else if (pos == MAIN_CONTROL_INFO)
2246 CloseDoor(DOOR_CLOSE_2);
2248 SetGameStatus(GAME_MODE_INFO);
2250 info_mode = INFO_MODE_MAIN;
2254 else if (pos == MAIN_CONTROL_GAME)
2256 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2258 else if (pos == MAIN_CONTROL_SETUP)
2260 CloseDoor(DOOR_CLOSE_2);
2262 SetGameStatus(GAME_MODE_SETUP);
2264 setup_mode = SETUP_MODE_MAIN;
2268 else if (pos == MAIN_CONTROL_QUIT)
2270 SaveLevelSetup_LastSeries();
2271 SaveLevelSetup_SeriesInfo();
2273 #if defined(PLATFORM_EMSCRIPTEN)
2274 Request("Close the browser window to quit!", REQ_CONFIRM);
2276 if (!setup.ask_on_quit_program ||
2277 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2278 SetGameStatus(GAME_MODE_QUIT);
2284 button_pressed_last = button_pressed;
2288 // ============================================================================
2289 // info screen functions
2290 // ============================================================================
2292 static struct TokenInfo *info_info;
2293 static int num_info_info; // number of info entries shown on screen
2294 static int max_info_info; // total number of info entries in list
2296 static void execInfoTitleScreen(void)
2298 info_mode = INFO_MODE_TITLE;
2303 static void execInfoElements(void)
2305 info_mode = INFO_MODE_ELEMENTS;
2310 static void execInfoMusic(void)
2312 info_mode = INFO_MODE_MUSIC;
2317 static void execInfoCredits(void)
2319 info_mode = INFO_MODE_CREDITS;
2324 static void execInfoProgram(void)
2326 info_mode = INFO_MODE_PROGRAM;
2331 static void execInfoVersion(void)
2333 info_mode = INFO_MODE_VERSION;
2338 static void execInfoLevelSet(void)
2340 info_mode = INFO_MODE_LEVELSET;
2345 static void execExitInfo(void)
2347 SetGameStatus(GAME_MODE_MAIN);
2352 static struct TokenInfo info_info_main[] =
2354 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2355 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2356 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2357 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2358 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2359 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2360 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2361 { TYPE_EMPTY, NULL, "" },
2362 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2367 static int getMenuTextFont(int type)
2369 if (type & (TYPE_SWITCH |
2383 static struct TokenInfo *setup_info;
2384 static struct TokenInfo setup_info_input[];
2386 static struct TokenInfo *menu_info;
2388 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2389 int screen_pos, int menu_info_pos_raw,
2392 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2393 struct TokenInfo *ti = &token_info[pos];
2394 int xpos = MENU_SCREEN_START_XPOS;
2395 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2396 int font_nr = getMenuTextFont(ti->type);
2398 if (setup_mode == SETUP_MODE_INPUT)
2399 font_nr = FONT_MENU_1;
2402 font_nr = FONT_ACTIVE(font_nr);
2404 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2406 if (ti->type & ~TYPE_SKIP_ENTRY)
2407 drawCursor(screen_pos, active);
2410 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2413 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2416 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2419 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2422 static char *window_size_text;
2423 static char *scaling_type_text;
2424 static char *network_server_text;
2426 static void drawSetupValue(int, int);
2428 static void drawMenuInfoList(int first_entry, int num_page_entries,
2429 int max_page_entries)
2433 if (first_entry + num_page_entries > max_page_entries)
2436 clearMenuListArea();
2438 for (i = 0; i < num_page_entries; i++)
2440 int menu_info_pos = first_entry + i;
2441 struct TokenInfo *si = &menu_info[menu_info_pos];
2442 void *value_ptr = si->value;
2444 // set some entries to "unchangeable" according to other variables
2445 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2446 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2447 (value_ptr == &setup.sound_music && !audio.music_available) ||
2448 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2449 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2450 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2451 si->type |= TYPE_GHOSTED;
2453 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2454 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2455 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2456 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2457 else if (si->type & ~TYPE_SKIP_ENTRY)
2458 initCursor(i, IMG_MENU_BUTTON);
2460 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2462 if (si->type & TYPE_STRING)
2466 if (value_ptr == &network_server_text)
2467 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2469 if (gadget_id != -1)
2471 struct GadgetInfo *gi = screen_gadget[gadget_id];
2472 int xpos = MENU_SCREEN_START_XPOS;
2473 int ypos = MENU_SCREEN_START_YPOS + i;
2474 int x = mSX + xpos * 32;
2475 int y = mSY + ypos * 32;
2477 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2481 if (si->type & TYPE_VALUE &&
2482 menu_info == setup_info)
2483 drawSetupValue(i, menu_info_pos);
2487 static void DrawInfoScreen_Main(void)
2489 int fade_mask = REDRAW_FIELD;
2492 if (redraw_mask & REDRAW_ALL)
2493 fade_mask = REDRAW_ALL;
2496 fade_mask = REDRAW_ALL;
2499 FadeMenuSoundsAndMusic();
2501 FreeScreenGadgets();
2502 CreateScreenGadgets();
2504 // (needed after displaying title screens which disable auto repeat)
2505 KeyboardAutoRepeatOn();
2507 FadeSetLeaveScreen();
2511 // needed if different viewport properties defined for info screen
2512 ChangeViewportPropertiesIfNeeded();
2514 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2518 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2520 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2522 info_info = info_info_main;
2524 // determine maximal number of info entries that can be displayed on screen
2526 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2529 // determine maximal number of info entries available for menu of info screen
2531 for (i = 0; info_info[i].type != 0; i++)
2534 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2536 MapScreenGadgets(max_info_info);
2538 PlayMenuSoundsAndMusic();
2540 DrawMaskedBorder(fade_mask);
2545 static void changeSetupValue(int, int, int);
2547 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2548 int mode, int num_page_entries,
2549 int max_page_entries)
2551 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2552 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2553 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2554 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2555 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2556 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2557 int *num_page_entries_last = num_page_entries_all_last[game_status];
2558 int *choice_store = choice_stores[game_status];
2559 int *first_entry_store = first_entry_stores[game_status];
2560 int choice = choice_store[mode]; // starts with 0
2561 int first_entry = first_entry_store[mode]; // starts with 0
2563 int y = choice - first_entry;
2565 boolean position_set_by_scrollbar = (dx == 999);
2566 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2569 if (button == MB_MENU_INITIALIZE)
2571 // check if number of menu page entries has changed (may happen by change
2572 // of custom artwork definition value for 'list_size' for this menu screen)
2573 // (in this case, the last menu position most probably has to be corrected)
2574 if (num_page_entries != num_page_entries_last[mode])
2576 choice_store[mode] = first_entry_store[mode] = 0;
2578 choice = first_entry = 0;
2581 num_page_entries_last[mode] = num_page_entries;
2584 // advance to first valid menu entry
2585 while (choice < num_page_entries &&
2586 menu_info[choice].type & TYPE_SKIP_ENTRY)
2589 if (position_set_by_scrollbar)
2590 first_entry = first_entry_store[mode] = dy;
2592 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2593 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2595 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2597 if (choice < first_entry)
2599 choice = first_entry;
2601 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2604 else if (choice > first_entry + num_page_entries - 1)
2606 choice = first_entry + num_page_entries - 1;
2608 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2612 choice_store[mode] = choice;
2614 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2618 else if (button == MB_MENU_LEAVE)
2620 PlaySound(SND_MENU_ITEM_SELECTING);
2622 for (i = 0; i < max_page_entries; i++)
2624 if (menu_info[i].type & TYPE_LEAVE_MENU)
2626 void (*menu_callback_function)(void) = menu_info[i].value;
2630 menu_callback_function();
2632 break; // absolutely needed because function changes 'menu_info'!
2639 if (mx || my) // mouse input
2641 x = (mx - mSX) / 32;
2642 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2644 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2646 // move cursor instead of scrolling when already at start/end of list
2647 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2649 else if (dy == +1 * SCROLL_LINE &&
2650 first_entry + num_page_entries == max_page_entries)
2653 // handle scrolling screen one line or page
2655 y + dy > num_page_entries - 1)
2657 boolean redraw = FALSE;
2659 if (ABS(dy) == SCROLL_PAGE)
2660 step = num_page_entries - 1;
2662 if (dy < 0 && first_entry > 0)
2664 // scroll page/line up
2666 first_entry -= step;
2667 if (first_entry < 0)
2672 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2674 // scroll page/line down
2676 first_entry += step;
2677 if (first_entry + num_page_entries > max_page_entries)
2678 first_entry = MAX(0, max_page_entries - num_page_entries);
2685 choice += first_entry - first_entry_store[mode];
2687 if (choice < first_entry)
2689 choice = first_entry;
2691 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2694 else if (choice > first_entry + num_page_entries - 1)
2696 choice = first_entry + num_page_entries - 1;
2698 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2701 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2705 if (choice < first_entry ||
2706 choice > first_entry + num_page_entries - 1)
2707 first_entry += SIGN(dy);
2710 first_entry_store[mode] = first_entry;
2711 choice_store[mode] = choice;
2713 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2715 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2717 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2718 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2726 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2728 if (menu_info[choice].type & menu_navigation_type ||
2729 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2730 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2731 menu_info[choice].type & TYPE_PLAYER)
2732 button = MB_MENU_CHOICE;
2737 // jump to next non-empty menu entry (up or down)
2738 while (first_entry + y > 0 &&
2739 first_entry + y < max_page_entries - 1 &&
2740 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2743 if (!IN_VIS_MENU(x, y))
2745 choice += y - y_old;
2747 if (choice < first_entry)
2748 first_entry = choice;
2749 else if (choice > first_entry + num_page_entries - 1)
2750 first_entry = choice - num_page_entries + 1;
2752 if (first_entry >= 0 &&
2753 first_entry + num_page_entries <= max_page_entries)
2755 first_entry_store[mode] = first_entry;
2757 if (choice < first_entry)
2758 choice = first_entry;
2759 else if (choice > first_entry + num_page_entries - 1)
2760 choice = first_entry + num_page_entries - 1;
2762 choice_store[mode] = choice;
2764 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2766 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2768 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2769 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2776 if (!anyScrollbarGadgetActive() &&
2777 IN_VIS_MENU(x, y) &&
2778 mx < mx_right_border &&
2779 y >= 0 && y < num_page_entries)
2783 if (first_entry + y != choice &&
2784 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2786 PlaySound(SND_MENU_ITEM_ACTIVATING);
2788 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2789 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2791 choice = choice_store[mode] = first_entry + y;
2795 PlaySound(SND_MENU_ITEM_SELECTING);
2797 for (i = 0; menu_info[i].type != 0; i++)
2799 if (menu_info[i].type & TYPE_LEAVE_MENU)
2801 void (*menu_callback_function)(void) = menu_info[i].value;
2805 menu_callback_function();
2807 // absolutely needed because function changes 'menu_info'!
2815 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2817 PlaySound(SND_MENU_ITEM_SELECTING);
2819 // when selecting key headline, execute function for key value change
2820 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2821 menu_info[first_entry + y + 1].type & TYPE_KEY)
2824 // when selecting string value, execute function for list selection
2825 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2826 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2829 // when selecting string value, execute function for text input gadget
2830 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2831 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2834 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2836 void (*menu_callback_function)(void) =
2837 menu_info[first_entry + y].value;
2839 FadeSetFromType(menu_info[first_entry + y].type);
2841 menu_callback_function();
2843 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2845 void (*gadget_callback_function)(void) =
2846 menu_info[first_entry + y].value;
2848 gadget_callback_function();
2850 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2851 menu_info == setup_info)
2853 changeSetupValue(y, first_entry + y, dx);
2859 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2861 menu_info = info_info;
2863 HandleMenuScreen(mx, my, dx, dy, button,
2864 info_mode, num_info_info, max_info_info);
2867 static int getMenuFontSpacing(int spacing_height, int font_nr)
2869 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2871 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2875 static int getMenuTextSpacing(int spacing_height, int font_nr)
2877 return (getMenuFontSpacing(spacing_height, font_nr) +
2878 EXTRA_SPACING(game_status));
2881 static int getMenuTextStep(int spacing_height, int font_nr)
2883 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2886 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2888 int font_title = MENU_INFO_FONT_TITLE;
2889 int font_error = FONT_TEXT_2;
2890 int font_foot = MENU_INFO_FONT_FOOT;
2891 int spacing_title = menu.headline1_spacing_info[info_mode];
2892 int ystep_title = getMenuTextStep(spacing_title, font_title);
2893 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2894 int ystart2 = ystart1 + ystep_title;
2895 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2897 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2899 FadeOut(REDRAW_FIELD);
2904 DrawTextSCentered(ystart1, font_title, text_title);
2905 DrawTextSCentered(ystart2, font_error, text_error);
2907 DrawTextSCentered(ybottom, font_foot,
2908 "Press any key or button for info menu");
2910 FadeIn(REDRAW_FIELD);
2913 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2915 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2916 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2917 int font_title = MENU_INFO_FONT_TITLE;
2918 int font_foot = MENU_INFO_FONT_FOOT;
2919 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2920 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2921 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2922 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2923 int ystep = MENU_SCREEN_INFO_YSTEP;
2924 int element, action, direction;
2932 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2933 infoscreen_step[i] = infoscreen_frame[i] = 0;
2938 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2940 DrawTextSCentered(ybottom, font_foot,
2941 "Press any key or button for next page");
2947 while (helpanim_info[j].element != HELPANIM_LIST_END)
2949 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2954 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2963 j += infoscreen_step[i - start];
2965 element = helpanim_info[j].element;
2966 action = helpanim_info[j].action;
2967 direction = helpanim_info[j].direction;
2970 element = EL_UNKNOWN;
2972 if (action != -1 && direction != -1)
2973 graphic = el_act_dir2img(element, action, direction);
2974 else if (action != -1)
2975 graphic = el_act2img(element, action);
2976 else if (direction != -1)
2977 graphic = el_dir2img(element, direction);
2979 graphic = el2img(element);
2981 delay = helpanim_info[j++].delay;
2986 if (infoscreen_frame[i - start] == 0)
2989 infoscreen_frame[i - start] = delay - 1;
2993 sync_frame = delay - infoscreen_frame[i - start];
2994 infoscreen_frame[i - start]--;
2997 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2999 if (!infoscreen_frame[i - start])
3000 infoscreen_step[i - start] = 0;
3004 if (!infoscreen_frame[i - start])
3005 infoscreen_step[i - start]++;
3006 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3012 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3014 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3015 graphic, sync_frame, USE_MASKING);
3018 DrawInfoScreen_HelpText(element, action, direction, i - start);
3023 redraw_mask |= REDRAW_FIELD;
3028 static char *getHelpText(int element, int action, int direction)
3030 char token[MAX_LINE_LEN];
3032 strcpy(token, element_info[element].token_name);
3035 strcat(token, element_action_info[action].suffix);
3037 if (direction != -1)
3038 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3040 return getHashEntry(helptext_info, token);
3043 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3045 int font_nr = FONT_INFO_ELEMENTS;
3046 int font_width = getFontWidth(font_nr);
3047 int font_height = getFontHeight(font_nr);
3048 int yoffset = (TILEX - 2 * font_height) / 2;
3049 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3050 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3051 int ystep = TILEY + 4;
3052 int pad_left = xstart - SX;
3053 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3054 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3055 int max_lines_per_text = 2;
3058 if (action != -1 && direction != -1) // element.action.direction
3059 text = getHelpText(element, action, direction);
3061 if (text == NULL && action != -1) // element.action
3062 text = getHelpText(element, action, -1);
3064 if (text == NULL && direction != -1) // element.direction
3065 text = getHelpText(element, -1, direction);
3067 if (text == NULL) // base element
3068 text = getHelpText(element, -1, -1);
3070 if (text == NULL) // not found
3071 text = "No description available";
3073 if (strlen(text) <= max_chars_per_line) // only one line of text
3074 ystart += getFontHeight(font_nr) / 2;
3076 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3077 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3078 TRUE, FALSE, FALSE);
3081 static void DrawInfoScreen_TitleScreen(void)
3083 SetGameStatus(GAME_MODE_TITLE);
3088 void HandleInfoScreen_TitleScreen(int button)
3090 HandleTitleScreen(0, 0, 0, 0, button);
3093 static void DrawInfoScreen_Elements(void)
3095 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3097 FadeOut(REDRAW_FIELD);
3102 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3104 FadeIn(REDRAW_FIELD);
3107 void HandleInfoScreen_Elements(int button)
3109 static unsigned int info_delay = 0;
3110 static int num_anims;
3111 static int num_pages;
3113 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3116 if (button == MB_MENU_INITIALIZE)
3118 boolean new_element = TRUE;
3122 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3124 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3126 else if (new_element)
3129 new_element = FALSE;
3133 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3137 if (button == MB_MENU_LEAVE)
3139 PlaySound(SND_MENU_ITEM_SELECTING);
3141 info_mode = INFO_MODE_MAIN;
3146 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3148 if (button != MB_MENU_INITIALIZE)
3150 PlaySound(SND_MENU_ITEM_SELECTING);
3155 if (page >= num_pages)
3157 FadeMenuSoundsAndMusic();
3159 info_mode = INFO_MODE_MAIN;
3166 FadeSetNextScreen();
3168 if (button != MB_MENU_INITIALIZE)
3169 FadeOut(REDRAW_FIELD);
3171 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3173 if (button != MB_MENU_INITIALIZE)
3174 FadeIn(REDRAW_FIELD);
3178 if (DelayReached(&info_delay, GameFrameDelay))
3179 if (page < num_pages)
3180 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3182 PlayMenuSoundIfLoop();
3186 static void DrawInfoScreen_Music(void)
3188 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3190 FadeOut(REDRAW_FIELD);
3197 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3199 FadeIn(REDRAW_FIELD);
3202 void HandleInfoScreen_Music(int button)
3204 static struct MusicFileInfo *list = NULL;
3205 int font_title = MENU_INFO_FONT_TITLE;
3206 int font_head = MENU_INFO_FONT_HEAD;
3207 int font_text = MENU_INFO_FONT_TEXT;
3208 int font_foot = MENU_INFO_FONT_FOOT;
3209 int spacing_title = menu.headline1_spacing_info[info_mode];
3210 int spacing_head = menu.headline2_spacing_info[info_mode];
3211 int ystep_title = getMenuTextStep(spacing_title, font_title);
3212 int ystep_head = getMenuTextStep(spacing_head, font_head);
3213 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3214 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3216 if (button == MB_MENU_INITIALIZE)
3218 list = music_file_info;
3222 FadeMenuSoundsAndMusic();
3227 DrawTextSCentered(ystart, font_title,
3228 "No music info for this level set.");
3230 DrawTextSCentered(ybottom, font_foot,
3231 "Press any key or button for info menu");
3237 if (button == MB_MENU_LEAVE)
3239 PlaySound(SND_MENU_ITEM_SELECTING);
3241 FadeMenuSoundsAndMusic();
3243 info_mode = INFO_MODE_MAIN;
3248 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3250 if (button != MB_MENU_INITIALIZE)
3252 PlaySound(SND_MENU_ITEM_SELECTING);
3260 FadeMenuSoundsAndMusic();
3262 info_mode = INFO_MODE_MAIN;
3268 FadeMenuSoundsAndMusic();
3270 if (list != music_file_info)
3271 FadeSetNextScreen();
3273 if (button != MB_MENU_INITIALIZE)
3274 FadeOut(REDRAW_FIELD);
3281 int sound = list->music;
3283 if (IS_LOOP_SOUND(sound))
3284 PlaySoundLoop(sound);
3288 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3292 int music = list->music;
3294 if (IS_LOOP_MUSIC(music))
3295 PlayMusicLoop(music);
3299 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3302 ystart += ystep_title;
3304 if (!strEqual(list->title, UNKNOWN_NAME))
3306 if (!strEqual(list->title_header, UNKNOWN_NAME))
3308 DrawTextSCentered(ystart, font_head, list->title_header);
3309 ystart += ystep_head;
3312 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3313 ystart += ystep_head;
3316 if (!strEqual(list->artist, UNKNOWN_NAME))
3318 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3319 DrawTextSCentered(ystart, font_head, list->artist_header);
3321 DrawTextSCentered(ystart, font_head, "by");
3323 ystart += ystep_head;
3325 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3326 ystart += ystep_head;
3329 if (!strEqual(list->album, UNKNOWN_NAME))
3331 if (!strEqual(list->album_header, UNKNOWN_NAME))
3332 DrawTextSCentered(ystart, font_head, list->album_header);
3334 DrawTextSCentered(ystart, font_head, "from the album");
3336 ystart += ystep_head;
3338 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3339 ystart += ystep_head;
3342 if (!strEqual(list->year, UNKNOWN_NAME))
3344 if (!strEqual(list->year_header, UNKNOWN_NAME))
3345 DrawTextSCentered(ystart, font_head, list->year_header);
3347 DrawTextSCentered(ystart, font_head, "from the year");
3349 ystart += ystep_head;
3351 DrawTextFCentered(ystart, font_text, "%s", list->year);
3352 ystart += ystep_head;
3355 DrawTextSCentered(ybottom, FONT_TEXT_4,
3356 "Press any key or button for next page");
3358 if (button != MB_MENU_INITIALIZE)
3359 FadeIn(REDRAW_FIELD);
3362 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3363 PlaySoundLoop(list->music);
3366 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3368 int font_title = MENU_INFO_FONT_TITLE;
3369 int font_head = MENU_INFO_FONT_HEAD;
3370 int font_text = MENU_INFO_FONT_TEXT;
3371 int font_foot = MENU_INFO_FONT_FOOT;
3372 int spacing_title = menu.headline1_spacing_info[info_mode];
3373 int spacing_head = menu.headline2_spacing_info[info_mode];
3374 int spacing_para = menu.paragraph_spacing_info[info_mode];
3375 int spacing_line = menu.line_spacing_info[info_mode];
3376 int ystep_title = getMenuTextStep(spacing_title, font_title);
3377 int ystep_head = getMenuTextStep(spacing_head, font_head);
3378 int ystep_para = getMenuTextStep(spacing_para, font_text);
3379 int ystep_line = getMenuTextStep(spacing_line, font_text);
3380 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3381 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3386 DrawTextSCentered(ystart, font_title, "Credits:");
3387 ystart += ystep_title;
3391 DrawTextSCentered(ystart, font_head,
3392 "Special thanks to");
3393 ystart += ystep_head;
3394 DrawTextSCentered(ystart, font_text,
3396 ystart += ystep_head;
3397 DrawTextSCentered(ystart, font_head,
3399 ystart += ystep_head;
3400 DrawTextSCentered(ystart, font_text,
3401 "\"Boulder Dash\"");
3402 ystart += ystep_head;
3403 DrawTextSCentered(ystart, font_head,
3405 ystart += ystep_head;
3406 DrawTextSCentered(ystart, font_text,
3408 ystart += ystep_head;
3409 DrawTextSCentered(ystart, font_head,
3411 ystart += ystep_head;
3412 DrawTextSCentered(ystart, font_text,
3413 "First Star Software");
3415 else if (screen_nr == 1)
3417 DrawTextSCentered(ystart, font_head,
3418 "Special thanks to");
3419 ystart += ystep_head;
3420 DrawTextSCentered(ystart, font_text,
3421 "Klaus Heinz & Volker Wertich");
3422 ystart += ystep_head;
3423 DrawTextSCentered(ystart, font_head,
3425 ystart += ystep_head;
3426 DrawTextSCentered(ystart, font_text,
3427 "\"Emerald Mine\"");
3428 ystart += ystep_head;
3429 DrawTextSCentered(ystart, font_head,
3431 ystart += ystep_head;
3432 DrawTextSCentered(ystart, font_text,
3434 ystart += ystep_head;
3435 DrawTextSCentered(ystart, font_head,
3437 ystart += ystep_head;
3438 DrawTextSCentered(ystart, font_text,
3441 else if (screen_nr == 2)
3443 DrawTextSCentered(ystart, font_head,
3444 "Special thanks to");
3445 ystart += ystep_head;
3446 DrawTextSCentered(ystart, font_text,
3447 "Michael Stopp & Philip Jespersen");
3448 ystart += ystep_head;
3449 DrawTextSCentered(ystart, font_head,
3451 ystart += ystep_head;
3452 DrawTextSCentered(ystart, font_text,
3454 ystart += ystep_head;
3455 DrawTextSCentered(ystart, font_head,
3457 ystart += ystep_head;
3458 DrawTextSCentered(ystart, font_text,
3460 ystart += ystep_head;
3461 DrawTextSCentered(ystart, font_head,
3463 ystart += ystep_head;
3464 DrawTextSCentered(ystart, font_text,
3465 "Digital Integration");
3467 else if (screen_nr == 3)
3469 DrawTextSCentered(ystart, font_head,
3470 "Special thanks to");
3471 ystart += ystep_head;
3472 DrawTextSCentered(ystart, font_text,
3473 "Hiroyuki Imabayashi");
3474 ystart += ystep_head;
3475 DrawTextSCentered(ystart, font_head,
3477 ystart += ystep_head;
3478 DrawTextSCentered(ystart, font_text,
3480 ystart += ystep_head;
3481 DrawTextSCentered(ystart, font_head,
3483 ystart += ystep_head;
3484 DrawTextSCentered(ystart, font_text,
3486 ystart += ystep_head;
3487 DrawTextSCentered(ystart, font_head,
3489 ystart += ystep_head;
3490 DrawTextSCentered(ystart, font_text,
3493 else if (screen_nr == 4)
3495 DrawTextSCentered(ystart, font_head,
3496 "Special thanks to");
3497 ystart += ystep_head;
3498 DrawTextSCentered(ystart, font_text,
3500 ystart += ystep_head;
3501 DrawTextSCentered(ystart, font_head,
3503 ystart += ystep_head;
3504 DrawTextSCentered(ystart, font_text,
3505 "J\xfcrgen Bonhagen");
3506 ystart += ystep_head;
3507 DrawTextSCentered(ystart, font_head,
3508 "for the continuous creation");
3509 ystart += ystep_line;
3510 DrawTextSCentered(ystart, font_head,
3511 "of outstanding level sets");
3513 else if (screen_nr == 5)
3515 DrawTextSCentered(ystart, font_head,
3517 ystart += ystep_head;
3518 DrawTextSCentered(ystart, font_text,
3520 ystart += ystep_head;
3521 DrawTextSCentered(ystart, font_head,
3522 "for ideas and inspiration by");
3523 ystart += ystep_head;
3524 DrawTextSCentered(ystart, font_text,
3526 ystart += ystep_para;
3528 DrawTextSCentered(ystart, font_head,
3530 ystart += ystep_head;
3531 DrawTextSCentered(ystart, font_text,
3533 ystart += ystep_head;
3534 DrawTextSCentered(ystart, font_head,
3535 "for ideas and inspiration by");
3536 ystart += ystep_head;
3537 DrawTextSCentered(ystart, font_text,
3540 else if (screen_nr == 6)
3542 DrawTextSCentered(ystart, font_head,
3544 ystart += ystep_head;
3545 DrawTextSCentered(ystart, font_text,
3547 ystart += ystep_head;
3548 DrawTextSCentered(ystart, font_head,
3549 "for the code base used for the");
3550 ystart += ystep_line;
3551 DrawTextSCentered(ystart, font_head,
3552 "native Emerald Mine engine");
3554 else if (screen_nr == 7)
3556 DrawTextSCentered(ystart, font_head,
3558 ystart += ystep_head;
3559 DrawTextSCentered(ystart, font_text,
3561 ystart += ystep_head;
3562 DrawTextSCentered(ystart, font_head,
3563 "for the initial DOS port");
3564 ystart += ystep_para;
3566 DrawTextSCentered(ystart, font_head,
3568 ystart += ystep_head;
3569 DrawTextSCentered(ystart, font_text,
3571 ystart += ystep_head;
3572 DrawTextSCentered(ystart, font_head,
3573 "for some additional toons");
3575 else if (screen_nr == 8)
3577 DrawTextSCentered(ystart, font_head,
3578 "And not to forget:");
3579 ystart += ystep_head;
3580 DrawTextSCentered(ystart, font_head,
3582 ystart += ystep_head;
3583 DrawTextSCentered(ystart, font_text,
3584 "All those who contributed");
3585 ystart += ystep_line;
3586 DrawTextSCentered(ystart, font_text,
3587 "levels to this game");
3588 ystart += ystep_line;
3589 DrawTextSCentered(ystart, font_text,
3593 DrawTextSCentered(ybottom, font_foot,
3594 "Press any key or button for next page");
3597 static void DrawInfoScreen_Credits(void)
3599 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3601 FadeMenuSoundsAndMusic();
3603 FadeOut(REDRAW_FIELD);
3605 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3607 FadeIn(REDRAW_FIELD);
3610 void HandleInfoScreen_Credits(int button)
3612 static int screen_nr = 0;
3613 int num_screens = 9;
3615 if (button == MB_MENU_INITIALIZE)
3619 // DrawInfoScreen_CreditsScreen(screen_nr);
3622 if (button == MB_MENU_LEAVE)
3624 PlaySound(SND_MENU_ITEM_SELECTING);
3626 info_mode = INFO_MODE_MAIN;
3631 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3633 if (button != MB_MENU_INITIALIZE)
3635 PlaySound(SND_MENU_ITEM_SELECTING);
3640 if (screen_nr >= num_screens)
3642 FadeMenuSoundsAndMusic();
3644 info_mode = INFO_MODE_MAIN;
3651 FadeSetNextScreen();
3653 if (button != MB_MENU_INITIALIZE)
3654 FadeOut(REDRAW_FIELD);
3656 DrawInfoScreen_CreditsScreen(screen_nr);
3658 if (button != MB_MENU_INITIALIZE)
3659 FadeIn(REDRAW_FIELD);
3663 PlayMenuSoundIfLoop();
3667 static void DrawInfoScreen_Program(void)
3669 int font_title = MENU_INFO_FONT_TITLE;
3670 int font_head = MENU_INFO_FONT_HEAD;
3671 int font_text = MENU_INFO_FONT_TEXT;
3672 int font_foot = MENU_INFO_FONT_FOOT;
3673 int spacing_title = menu.headline1_spacing_info[info_mode];
3674 int spacing_head = menu.headline2_spacing_info[info_mode];
3675 int spacing_para = menu.paragraph_spacing_info[info_mode];
3676 int spacing_line = menu.line_spacing_info[info_mode];
3677 int ystep_title = getMenuTextStep(spacing_title, font_title);
3678 int ystep_head = getMenuTextStep(spacing_head, font_head);
3679 int ystep_para = getMenuTextStep(spacing_para, font_text);
3680 int ystep_line = getMenuTextStep(spacing_line, font_text);
3681 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3682 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3684 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3686 FadeOut(REDRAW_FIELD);
3691 DrawTextSCentered(ystart, font_title, "Program Information:");
3692 ystart += ystep_title;
3694 DrawTextSCentered(ystart, font_head,
3695 "This game is Freeware!");
3696 ystart += ystep_head;
3697 DrawTextSCentered(ystart, font_head,
3698 "If you like it, send e-mail to:");
3699 ystart += ystep_head;
3700 DrawTextSCentered(ystart, font_text,
3701 setup.internal.program_email);
3702 ystart += ystep_para;
3704 DrawTextSCentered(ystart, font_head,
3705 "More information and levels:");
3706 ystart += ystep_head;
3707 DrawTextSCentered(ystart, font_text,
3708 setup.internal.program_website);
3709 ystart += ystep_para;
3711 DrawTextSCentered(ystart, font_head,
3712 "If you have created new levels,");
3713 ystart += ystep_line;
3714 DrawTextSCentered(ystart, font_head,
3715 "send them to me to include them!");
3716 ystart += ystep_head;
3717 DrawTextSCentered(ystart, font_head,
3720 DrawTextSCentered(ybottom, font_foot,
3721 "Press any key or button for info menu");
3723 FadeIn(REDRAW_FIELD);
3726 void HandleInfoScreen_Program(int button)
3728 if (button == MB_MENU_LEAVE)
3730 PlaySound(SND_MENU_ITEM_SELECTING);
3732 info_mode = INFO_MODE_MAIN;
3737 else if (button == MB_MENU_CHOICE)
3739 PlaySound(SND_MENU_ITEM_SELECTING);
3741 FadeMenuSoundsAndMusic();
3743 info_mode = INFO_MODE_MAIN;
3748 PlayMenuSoundIfLoop();
3752 static void DrawInfoScreen_Version(void)
3754 int font_title = MENU_INFO_FONT_TITLE;
3755 int font_head = MENU_INFO_FONT_HEAD;
3756 int font_text = MENU_INFO_FONT_TEXT;
3757 int font_foot = MENU_INFO_FONT_FOOT;
3758 int spacing_title = menu.headline1_spacing_info[info_mode];
3759 int spacing_head = menu.headline2_spacing_info[info_mode];
3760 int spacing_para = menu.paragraph_spacing_info[info_mode];
3761 int spacing_line = menu.line_spacing_info[info_mode];
3762 int xstep = getFontWidth(font_text);
3763 int ystep_title = getMenuTextStep(spacing_title, font_title);
3764 int ystep_head = getMenuTextStep(spacing_head, font_head);
3765 int ystep_para = getMenuTextStep(spacing_para, font_text);
3766 int ystep_line = getMenuTextStep(spacing_line, font_text);
3767 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3768 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3769 int xstart1 = mSX - SX + 2 * xstep;
3770 int xstart2 = mSX - SX + 18 * xstep;
3771 int xstart3 = mSX - SX + 28 * xstep;
3772 SDL_version sdl_version_compiled;
3773 const SDL_version *sdl_version_linked;
3774 int driver_name_len = 10;
3775 SDL_version sdl_version_linked_ext;
3776 const char *driver_name = NULL;
3778 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3780 FadeOut(REDRAW_FIELD);
3785 DrawTextSCentered(ystart, font_title, "Version Information:");
3786 ystart += ystep_title;
3788 DrawTextF(xstart1, ystart, font_head, "Name");
3789 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3790 ystart += ystep_line;
3792 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3794 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3795 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3796 ystart += ystep_line;
3798 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3799 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3800 ystart += ystep_line;
3804 DrawTextF(xstart1, ystart, font_head, "Version");
3805 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3806 ystart += ystep_line;
3809 DrawTextF(xstart1, ystart, font_head, "Platform");
3810 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3812 PLATFORM_XX_BIT_STRING);
3813 ystart += ystep_line;
3815 DrawTextF(xstart1, ystart, font_head, "Target");
3816 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3817 ystart += ystep_line;
3819 DrawTextF(xstart1, ystart, font_head, "Source date");
3820 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3821 ystart += ystep_line;
3823 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3824 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3825 ystart += ystep_para;
3827 DrawTextF(xstart1, ystart, font_head, "Library");
3828 DrawTextF(xstart2, ystart, font_head, "compiled");
3829 DrawTextF(xstart3, ystart, font_head, "linked");
3830 ystart += ystep_head;
3832 SDL_VERSION(&sdl_version_compiled);
3833 SDL_GetVersion(&sdl_version_linked_ext);
3834 sdl_version_linked = &sdl_version_linked_ext;
3836 DrawTextF(xstart1, ystart, font_text, "SDL");
3837 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3838 sdl_version_compiled.major,
3839 sdl_version_compiled.minor,
3840 sdl_version_compiled.patch);
3841 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3842 sdl_version_linked->major,
3843 sdl_version_linked->minor,
3844 sdl_version_linked->patch);
3845 ystart += ystep_line;
3847 SDL_IMAGE_VERSION(&sdl_version_compiled);
3848 sdl_version_linked = IMG_Linked_Version();
3850 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3851 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3852 sdl_version_compiled.major,
3853 sdl_version_compiled.minor,
3854 sdl_version_compiled.patch);
3855 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3856 sdl_version_linked->major,
3857 sdl_version_linked->minor,
3858 sdl_version_linked->patch);
3859 ystart += ystep_line;
3861 SDL_MIXER_VERSION(&sdl_version_compiled);
3862 sdl_version_linked = Mix_Linked_Version();
3864 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3865 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3866 sdl_version_compiled.major,
3867 sdl_version_compiled.minor,
3868 sdl_version_compiled.patch);
3869 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3870 sdl_version_linked->major,
3871 sdl_version_linked->minor,
3872 sdl_version_linked->patch);
3873 ystart += ystep_line;
3875 SDL_NET_VERSION(&sdl_version_compiled);
3876 sdl_version_linked = SDLNet_Linked_Version();
3878 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3879 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3880 sdl_version_compiled.major,
3881 sdl_version_compiled.minor,
3882 sdl_version_compiled.patch);
3883 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3884 sdl_version_linked->major,
3885 sdl_version_linked->minor,
3886 sdl_version_linked->patch);
3887 ystart += ystep_para;
3889 DrawTextF(xstart1, ystart, font_head, "Driver");
3890 DrawTextF(xstart2, ystart, font_head, "Requested");
3891 DrawTextF(xstart3, ystart, font_head, "Used");
3892 ystart += ystep_head;
3895 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3897 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3898 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3899 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3900 ystart += ystep_line;
3903 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3905 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3906 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3907 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3908 ystart += ystep_line;
3911 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3913 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3914 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3915 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3917 DrawTextSCentered(ybottom, font_foot,
3918 "Press any key or button for info menu");
3920 FadeIn(REDRAW_FIELD);
3923 void HandleInfoScreen_Version(int button)
3925 if (button == MB_MENU_LEAVE)
3927 PlaySound(SND_MENU_ITEM_SELECTING);
3929 info_mode = INFO_MODE_MAIN;
3934 else if (button == MB_MENU_CHOICE)
3936 PlaySound(SND_MENU_ITEM_SELECTING);
3938 FadeMenuSoundsAndMusic();
3940 info_mode = INFO_MODE_MAIN;
3945 PlayMenuSoundIfLoop();
3949 static void DrawInfoScreen_LevelSet(void)
3951 struct TitleMessageInfo *tmi = &readme;
3952 char *filename = getLevelSetInfoFilename();
3953 char *title = "Level Set Information:";
3954 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3955 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3957 if (filename == NULL)
3959 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3964 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3966 FadeOut(REDRAW_FIELD);
3971 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3973 // if x position set to "-1", automatically determine by playfield width
3975 tmi->x = SXSIZE / 2;
3977 // if y position set to "-1", use static default value
3981 // if width set to "-1", automatically determine by playfield width
3982 if (tmi->width == -1)
3983 tmi->width = SXSIZE - 2 * TILEX;
3985 // if height set to "-1", automatically determine by playfield height
3986 if (tmi->height == -1)
3987 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3989 // if chars set to "-1", automatically determine by text and font width
3990 if (tmi->chars == -1)
3991 tmi->chars = tmi->width / getFontWidth(tmi->font);
3993 tmi->width = tmi->chars * getFontWidth(tmi->font);
3995 // if lines set to "-1", automatically determine by text and font height
3996 if (tmi->lines == -1)
3997 tmi->lines = tmi->height / getFontHeight(tmi->font);
3999 tmi->height = tmi->lines * getFontHeight(tmi->font);
4001 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
4002 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
4003 tmi->autowrap, tmi->centered, tmi->parse_comments);
4005 DrawTextSCentered(ybottom, FONT_TEXT_4,
4006 "Press any key or button for info menu");
4008 FadeIn(REDRAW_FIELD);
4011 static void HandleInfoScreen_LevelSet(int button)
4013 if (button == MB_MENU_LEAVE)
4015 PlaySound(SND_MENU_ITEM_SELECTING);
4017 info_mode = INFO_MODE_MAIN;
4022 else if (button == MB_MENU_CHOICE)
4024 PlaySound(SND_MENU_ITEM_SELECTING);
4026 FadeMenuSoundsAndMusic();
4028 info_mode = INFO_MODE_MAIN;
4033 PlayMenuSoundIfLoop();
4037 static void DrawInfoScreen(void)
4039 if (info_mode == INFO_MODE_TITLE)
4040 DrawInfoScreen_TitleScreen();
4041 else if (info_mode == INFO_MODE_ELEMENTS)
4042 DrawInfoScreen_Elements();
4043 else if (info_mode == INFO_MODE_MUSIC)
4044 DrawInfoScreen_Music();
4045 else if (info_mode == INFO_MODE_CREDITS)
4046 DrawInfoScreen_Credits();
4047 else if (info_mode == INFO_MODE_PROGRAM)
4048 DrawInfoScreen_Program();
4049 else if (info_mode == INFO_MODE_VERSION)
4050 DrawInfoScreen_Version();
4051 else if (info_mode == INFO_MODE_LEVELSET)
4052 DrawInfoScreen_LevelSet();
4054 DrawInfoScreen_Main();
4056 if (info_mode != INFO_MODE_MAIN &&
4057 info_mode != INFO_MODE_TITLE &&
4058 info_mode != INFO_MODE_MUSIC)
4059 PlayMenuSoundsAndMusic();
4062 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4064 if (info_mode == INFO_MODE_TITLE)
4065 HandleInfoScreen_TitleScreen(button);
4066 else if (info_mode == INFO_MODE_ELEMENTS)
4067 HandleInfoScreen_Elements(button);
4068 else if (info_mode == INFO_MODE_MUSIC)
4069 HandleInfoScreen_Music(button);
4070 else if (info_mode == INFO_MODE_CREDITS)
4071 HandleInfoScreen_Credits(button);
4072 else if (info_mode == INFO_MODE_PROGRAM)
4073 HandleInfoScreen_Program(button);
4074 else if (info_mode == INFO_MODE_VERSION)
4075 HandleInfoScreen_Version(button);
4076 else if (info_mode == INFO_MODE_LEVELSET)
4077 HandleInfoScreen_LevelSet(button);
4079 HandleInfoScreen_Main(mx, my, dx, dy, button);
4083 // ============================================================================
4084 // rename player API functions
4085 // ============================================================================
4087 struct ApiRenamePlayerThreadData
4093 static void *CreateThreadData_ApiRenamePlayer(void)
4095 struct ApiRenamePlayerThreadData *data =
4096 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4098 data->player_name = getStringCopy(setup.player_name);
4099 data->player_uuid = getStringCopy(setup.player_uuid);
4104 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4106 struct ApiRenamePlayerThreadData *data = data_raw;
4108 checked_free(data->player_name);
4109 checked_free(data->player_uuid);
4113 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4116 struct ApiRenamePlayerThreadData *data = data_raw;
4117 char *player_name_raw = data->player_name;
4118 char *player_uuid_raw = data->player_uuid;
4120 request->hostname = setup.api_server_hostname;
4121 request->port = API_SERVER_PORT;
4122 request->method = API_SERVER_METHOD;
4123 request->uri = API_SERVER_URI_RENAME;
4125 char *player_name = getEscapedJSON(player_name_raw);
4126 char *player_uuid = getEscapedJSON(player_uuid_raw);
4128 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4131 " \"game_version\": \"%s\",\n"
4132 " \"game_platform\": \"%s\",\n"
4133 " \"name\": \"%s\",\n"
4134 " \"uuid\": \"%s\"\n"
4136 getPasswordJSON(setup.api_server_password),
4137 getProgramRealVersionString(),
4138 getProgramPlatformString(),
4142 checked_free(player_name);
4143 checked_free(player_uuid);
4145 ConvertHttpRequestBodyToServerEncoding(request);
4150 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4153 // nothing to do here
4156 #if defined(PLATFORM_EMSCRIPTEN)
4157 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4158 void *buffer, unsigned int size)
4160 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4162 if (response != NULL)
4164 HandleResponse_ApiRenamePlayer(response, data_raw);
4166 checked_free(response);
4170 Error("server response too large to handle (%d bytes)", size);
4173 FreeThreadData_ApiRenamePlayer(data_raw);
4176 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4177 int code, const char *status)
4179 Error("server failed to handle request: %d %s", code, status);
4181 FreeThreadData_ApiRenamePlayer(data_raw);
4184 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4185 int bytes, int size)
4187 // nothing to do here
4190 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4193 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4195 FreeThreadData_ApiRenamePlayer(data_raw);
4200 emscripten_async_wget2_data(request->uri,
4205 Emscripten_ApiRenamePlayer_Loaded,
4206 Emscripten_ApiRenamePlayer_Failed,
4207 Emscripten_ApiRenamePlayer_Progress);
4212 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4213 struct HttpResponse *response,
4216 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4219 if (!DoHttpRequest(request, response))
4221 Error("HTTP request failed: %s", GetHttpError());
4226 if (!HTTP_SUCCESS(response->status_code))
4228 Error("server failed to handle request: %d %s",
4229 response->status_code,
4230 response->status_text);
4235 HandleResponse_ApiRenamePlayer(response, data_raw);
4238 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4239 struct HttpResponse *response,
4242 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4244 FreeThreadData_ApiRenamePlayer(data_raw);
4248 static int ApiRenamePlayerThread(void *data_raw)
4250 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4251 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4253 program.api_thread_count++;
4255 #if defined(PLATFORM_EMSCRIPTEN)
4256 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4258 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4261 program.api_thread_count--;
4263 checked_free(request);
4264 checked_free(response);
4269 static void ApiRenamePlayerAsThread(void)
4271 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4273 ExecuteAsThread(ApiRenamePlayerThread,
4274 "ApiRenamePlayer", data,
4275 "rename player on server");
4279 // ============================================================================
4280 // reset player UUID API functions
4281 // ============================================================================
4283 struct ApiResetUUIDThreadData
4286 char *player_uuid_old;
4287 char *player_uuid_new;
4290 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4292 struct ApiResetUUIDThreadData *data =
4293 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4295 data->player_name = getStringCopy(setup.player_name);
4296 data->player_uuid_old = getStringCopy(setup.player_uuid);
4297 data->player_uuid_new = getStringCopy(uuid_new);
4302 static void FreeThreadData_ApiResetUUID(void *data_raw)
4304 struct ApiResetUUIDThreadData *data = data_raw;
4306 checked_free(data->player_name);
4307 checked_free(data->player_uuid_old);
4308 checked_free(data->player_uuid_new);
4312 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4315 struct ApiResetUUIDThreadData *data = data_raw;
4316 char *player_name_raw = data->player_name;
4317 char *player_uuid_old_raw = data->player_uuid_old;
4318 char *player_uuid_new_raw = data->player_uuid_new;
4320 request->hostname = setup.api_server_hostname;
4321 request->port = API_SERVER_PORT;
4322 request->method = API_SERVER_METHOD;
4323 request->uri = API_SERVER_URI_RESETUUID;
4325 char *player_name = getEscapedJSON(player_name_raw);
4326 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4327 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4329 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4332 " \"game_version\": \"%s\",\n"
4333 " \"game_platform\": \"%s\",\n"
4334 " \"name\": \"%s\",\n"
4335 " \"uuid_old\": \"%s\",\n"
4336 " \"uuid_new\": \"%s\"\n"
4338 getPasswordJSON(setup.api_server_password),
4339 getProgramRealVersionString(),
4340 getProgramPlatformString(),
4345 checked_free(player_name);
4346 checked_free(player_uuid_old);
4347 checked_free(player_uuid_new);
4349 ConvertHttpRequestBodyToServerEncoding(request);
4354 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4357 struct ApiResetUUIDThreadData *data = data_raw;
4359 // upgrade player UUID in server setup file
4360 setup.player_uuid = getStringCopy(data->player_uuid_new);
4361 setup.player_version = 2;
4363 SaveSetup_ServerSetup();
4366 #if defined(PLATFORM_EMSCRIPTEN)
4367 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4368 void *buffer, unsigned int size)
4370 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4372 if (response != NULL)
4374 HandleResponse_ApiResetUUID(response, data_raw);
4376 checked_free(response);
4380 Error("server response too large to handle (%d bytes)", size);
4383 FreeThreadData_ApiResetUUID(data_raw);
4386 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4387 int code, const char *status)
4389 Error("server failed to handle request: %d %s", code, status);
4391 FreeThreadData_ApiResetUUID(data_raw);
4394 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4395 int bytes, int size)
4397 // nothing to do here
4400 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4403 if (!SetRequest_ApiResetUUID(request, data_raw))
4405 FreeThreadData_ApiResetUUID(data_raw);
4410 emscripten_async_wget2_data(request->uri,
4415 Emscripten_ApiResetUUID_Loaded,
4416 Emscripten_ApiResetUUID_Failed,
4417 Emscripten_ApiResetUUID_Progress);
4422 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4423 struct HttpResponse *response,
4426 if (!SetRequest_ApiResetUUID(request, data_raw))
4429 if (!DoHttpRequest(request, response))
4431 Error("HTTP request failed: %s", GetHttpError());
4436 if (!HTTP_SUCCESS(response->status_code))
4438 Error("server failed to handle request: %d %s",
4439 response->status_code,
4440 response->status_text);
4445 HandleResponse_ApiResetUUID(response, data_raw);
4448 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4449 struct HttpResponse *response,
4452 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4454 FreeThreadData_ApiResetUUID(data_raw);
4458 static int ApiResetUUIDThread(void *data_raw)
4460 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4461 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4463 program.api_thread_count++;
4465 #if defined(PLATFORM_EMSCRIPTEN)
4466 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4468 ApiResetUUID_HttpRequest(request, response, data_raw);
4471 program.api_thread_count--;
4473 checked_free(request);
4474 checked_free(response);
4479 static void ApiResetUUIDAsThread(char *uuid_new)
4481 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4483 ExecuteAsThread(ApiResetUUIDThread,
4484 "ApiResetUUID", data,
4485 "reset UUID on server");
4489 // ============================================================================
4490 // type name functions
4491 // ============================================================================
4493 static TreeInfo *type_name_node = NULL;
4494 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4495 static int type_name_nr = 0;
4497 static int getPlayerNameColor(char *name)
4499 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4502 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4505 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4506 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4507 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4508 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4509 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4510 int font_width = getFontWidth(font_nr);
4512 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4514 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4516 pos->width = strlen(text) * font_width;
4517 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4519 DrawText(sx, sy, text, font_nr);
4522 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4524 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4526 *pos = *mci->pos_input;
4528 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4530 TreeInfo *ti = player_name_current;
4531 int first_entry = ti->cl_first;
4532 int entry_pos = first_entry + ti->cl_cursor;
4533 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4534 int xpos = MENU_SCREEN_START_XPOS;
4535 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4537 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4538 type_name_nr = entry_pos;
4540 strcpy(name, type_name_node->name);
4544 pos->width = MAX_PLAYER_NAME_LEN * 32;
4548 type_name_nr = user.nr;
4550 strcpy(name, setup.player_name);
4553 strcpy(type_name_last, name);
4555 if (strEqual(name, EMPTY_PLAYER_NAME))
4558 *xpos = strlen(name);
4561 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4563 // change name of edited user in global list of user names
4564 setString(&global.user_names[type_name_nr], name);
4566 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4568 TreeInfo *node = type_name_node;
4570 // change name of edited user in local menu tree structure
4571 setString(&node->name, name);
4572 setString(&node->name_sorting, name);
4574 node->color = getPlayerNameColor(name);
4575 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4579 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4582 boolean reset_setup = strEqual(name, "");
4583 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4584 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4587 strcpy(name, type_name_last);
4589 if (strEqual(name, ""))
4590 strcpy(name, EMPTY_PLAYER_NAME);
4592 setTypeNameValues_Name(name, pos);
4594 // if player name not changed, no further action required
4595 if (strEqual(name, type_name_last))
4598 // redraw player name before (possibly) opening request dialogs
4599 drawTypeNameText(name, pos, FALSE);
4601 int last_user_nr = user.nr;
4603 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4605 // save setup of currently active user (may differ from edited user)
4608 // temporarily change active user to edited user
4609 user.nr = type_name_nr;
4612 Request("Use current setup values for the new player?", REQ_ASK))
4614 // use current setup values for new user, but create new player UUID
4615 setup.player_uuid = getStringCopy(getUUID());
4619 // load setup for existing user (or start with defaults for new user)
4624 char *setup_filename = getSetupFilename();
4625 boolean setup_exists = fileExists(setup_filename);
4627 // change name of edited user in setup structure
4628 strcpy(setup.player_name, name);
4630 // save setup of edited user
4633 // change name of edited user on score server
4634 ApiRenamePlayerAsThread();
4636 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4640 if (Request("Reset setup values for this player?", REQ_ASK))
4642 // remove setup config file
4643 unlink(setup_filename);
4645 // set player name to default player name
4648 // update player name used by name typing functions
4649 strcpy(name, setup.player_name);
4651 setTypeNameValues_Name(name, pos);
4654 else if (remove_user && type_name_nr != 0)
4656 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4658 char *user_dir = getUserGameDataDir();
4659 char *user_dir_removed =
4660 getStringCat3WithSeparator(user_dir, "REMOVED",
4661 getCurrentTimestamp(), ".");
4663 if (rename(user_dir, user_dir_removed) != 0)
4664 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4666 checked_free(user_dir_removed);
4669 else if (create_user && type_name_nr != 0 && !setup_exists)
4671 if (Request("Create empty level set for the new player?", REQ_ASK))
4673 char *levelset_subdir = getNewUserLevelSubdir();
4675 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4677 AddUserLevelSetToLevelInfo(levelset_subdir);
4679 LevelDirTree *leveldir_current_last = leveldir_current;
4681 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4684 // set level number of newly created level set to default value
4685 LoadLevelSetup_SeriesInfo();
4687 // set newly created level set as current level set for new user
4688 SaveLevelSetup_LastSeries();
4689 SaveLevelSetup_SeriesInfo();
4691 leveldir_current = leveldir_current_last;
4695 Request("Creating new level set failed!", REQ_CONFIRM);
4700 // restore currently active user
4701 user.nr = last_user_nr;
4703 // restore setup of currently active user
4706 // restore last level set of currently active user
4707 LoadLevelSetup_LastSeries();
4708 LoadLevelSetup_SeriesInfo();
4712 static void HandleTypeNameExt(boolean initialize, Key key)
4714 static struct TextPosInfo pos_name = { 0 };
4715 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4716 static int xpos = 0;
4717 struct TextPosInfo *pos = &pos_name;
4718 char key_char = getValidConfigValueChar(getCharFromKey(key));
4719 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4720 boolean active = TRUE;
4724 getTypeNameValues(name, pos, &xpos);
4726 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4727 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4729 StartTextInput(sx, sy, pos->width, pos->height);
4731 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4733 name[xpos] = key_char;
4738 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4744 else if (key == KSYM_Return || key == KSYM_Escape)
4746 boolean changed = (key == KSYM_Return);
4750 setTypeNameValues(name, pos, changed);
4755 drawTypeNameText(name, pos, active);
4759 SetGameStatus(game_status_last_screen);
4761 if (game_status == GAME_MODE_MAIN)
4762 InitializeMainControls();
4766 static void DrawTypeName(void)
4768 HandleTypeNameExt(TRUE, 0);
4771 void HandleTypeName(Key key)
4773 HandleTypeNameExt(FALSE, key);
4777 // ============================================================================
4778 // tree menu functions
4779 // ============================================================================
4781 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4783 if (game_status != GAME_MODE_SETUP ||
4784 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4787 int max_text_size = 0;
4790 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4791 max_text_size = MAX(max_text_size, strlen(node->name));
4793 int num_entries = numTreeInfoInGroup(ti);
4794 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4795 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4796 int text_width = max_text_size * getFontWidth(font_nr);
4797 int button_width = SC_MENUBUTTON_XSIZE;
4798 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4799 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4800 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4801 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4802 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4803 int align_xoffset = MAX(0, align_xoffset_raw);
4805 return align_xoffset;
4808 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4810 if (game_status != GAME_MODE_SETUP ||
4811 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4814 int num_entries = numTreeInfoInGroup(ti);
4815 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4816 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4817 int font_height = getFontHeight(font_nr);
4818 int text_height = font_height * num_page_entries;
4819 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4820 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4821 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4822 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4823 int align_yoffset = MAX(0, align_yoffset_raw);
4825 return align_yoffset;
4828 static void DrawChooseTree(TreeInfo **ti_ptr)
4830 int fade_mask = REDRAW_FIELD;
4833 fade_mask = REDRAW_ALL;
4835 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4837 if (game_status == GAME_MODE_SETUP)
4841 else // GAME_MODE_LEVELS
4843 SetGameStatus(GAME_MODE_MAIN);
4853 FreeScreenGadgets();
4854 CreateScreenGadgets();
4856 if (game_status != game_status_last_screen)
4857 FadeMenuSoundsAndMusic();
4861 // needed if different viewport properties defined for this screen
4862 ChangeViewportPropertiesIfNeeded();
4864 if (game_status == GAME_MODE_NAMES)
4865 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4866 else if (game_status == GAME_MODE_LEVELNR)
4867 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4868 else if (game_status == GAME_MODE_LEVELS)
4869 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4870 else if (game_status == GAME_MODE_SCORES)
4871 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4875 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4877 // map gadgets for high score screen
4878 if (game_status == GAME_MODE_SCORES)
4879 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4881 MapScreenTreeGadgets(*ti_ptr);
4883 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4885 DrawMaskedBorder(fade_mask);
4887 if (game_status != game_status_last_screen)
4888 PlayMenuSoundsAndMusic();
4893 static int getChooseTreeFont(TreeInfo *node, boolean active)
4895 if (game_status == GAME_MODE_SCORES)
4896 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4898 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4901 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4903 int num_entries = numTreeInfoInGroup(ti);
4904 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4905 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4906 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4907 int first_entry = ti->cl_first;
4908 int entry_pos = first_entry + y;
4909 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4910 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4911 int font_nr = getChooseTreeFont(node, active);
4912 int font_xoffset = getFontDrawOffsetX(font_nr);
4913 int xpos = MENU_SCREEN_START_XPOS;
4914 int ypos = MENU_SCREEN_START_YPOS + y;
4915 int startdx = xpos * 32;
4916 int startdy = ypos * 32;
4917 int startx = amSX + startdx;
4918 int starty = amSY + startdy;
4919 int startx_text = startx + font_xoffset;
4920 int endx_text = amSX + screen_width;
4921 int max_text_size = endx_text - startx_text;
4922 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4923 char buffer[max_buffer_len + 1];
4925 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4927 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4928 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4929 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4930 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4931 int font_size_1 = getFontWidth(font_nr1);
4932 int font_size_3 = getFontWidth(font_nr3);
4933 int font_size_4 = getFontWidth(font_nr4);
4934 int text_size_1 = 3 * font_size_1;
4935 int text_size_4 = 5 * font_size_4;
4936 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4938 int dx2 = text_size_1;
4939 int dx3 = dx2 + font_size_1;
4940 int dx4 = screen_width - startdx - 2 * border - text_size_4;
4941 int num_dots = (dx4 - dx3) / font_size_3;
4942 int startx1 = startx + dx1;
4943 int startx2 = startx + dx2;
4944 int startx3 = startx + dx3;
4945 int startx4 = startx + dx4;
4946 int pos = node->pos;
4947 char *pos_text = getHallOfFameRankText(pos);
4948 char *dot_text = ".";
4951 DrawText(startx1, starty, pos_text, font_nr1);
4952 DrawText(startx2, starty, dot_text, font_nr1);
4954 for (i = 0; i < num_dots; i++)
4955 DrawText(startx3 + i * font_size_3, starty, dot_text, font_nr3);
4957 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4958 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4960 DrawText(startx4, starty, getHallOfFameScoreText(pos), font_nr4);
4964 strncpy(buffer, node->name, max_buffer_len);
4965 buffer[max_buffer_len] = '\0';
4967 DrawText(startx, starty, buffer, font_nr);
4971 static void drawChooseTreeHeadExt(int type, char *title_string)
4973 int yoffset_sets = MENU_TITLE1_YPOS;
4974 int yoffset_setup = 16;
4975 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4976 type == TREE_TYPE_LEVEL_DIR ||
4977 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4979 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4982 static void drawChooseTreeHead(TreeInfo *ti)
4984 drawChooseTreeHeadExt(ti->type, ti->infotext);
4987 static void drawChooseTreeList(TreeInfo *ti)
4989 int first_entry = ti->cl_first;
4990 int num_entries = numTreeInfoInGroup(ti);
4991 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4994 clearMenuListArea();
4996 for (i = 0; i < num_page_entries; i++)
4998 TreeInfo *node, *node_first;
4999 int entry_pos = first_entry + i;
5001 node_first = getTreeInfoFirstGroupEntry(ti);
5002 node = getTreeInfoFromPos(node_first, entry_pos);
5004 drawChooseTreeText(ti, i, FALSE);
5006 if (node->parent_link)
5007 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5008 else if (node->level_group)
5009 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5011 initCursor(i, IMG_MENU_BUTTON);
5013 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
5014 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5016 if (game_status == GAME_MODE_NAMES)
5017 drawChooseTreeEdit(i, FALSE);
5020 redraw_mask |= REDRAW_FIELD;
5023 static void drawChooseTreeInfo(TreeInfo *ti)
5025 int entry_pos = ti->cl_first + ti->cl_cursor;
5026 int last_redraw_mask = redraw_mask;
5027 int ypos = MENU_TITLE2_YPOS;
5028 int font_nr = FONT_TITLE_2;
5031 if (ti->type == TREE_TYPE_LEVEL_NR)
5032 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
5034 if (ti->type == TREE_TYPE_SCORE_ENTRY)
5035 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
5036 scores.last_level_nr);
5038 if (ti->type != TREE_TYPE_LEVEL_DIR)
5041 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
5042 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
5044 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
5046 if (node->parent_link)
5047 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
5048 node->node_parent->name);
5049 else if (node->level_group)
5050 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
5052 else if (ti->type == TREE_TYPE_LEVEL_DIR)
5053 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
5054 node->levels, (node->levels > 1 ? "levels" : "level"),
5057 // let BackToFront() redraw only what is needed
5058 redraw_mask = last_redraw_mask;
5059 for (x = 0; x < SCR_FIELDX; x++)
5060 MarkTileDirty(x, 1);
5063 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
5065 drawChooseTreeCursor(ti->cl_cursor, active);
5066 drawChooseTreeText(ti, ti->cl_cursor, active);
5069 static void drawChooseTreeScreen(TreeInfo *ti)
5071 drawChooseTreeHead(ti);
5072 drawChooseTreeList(ti);
5073 drawChooseTreeInfo(ti);
5074 drawChooseTreeCursorAndText(ti, TRUE);
5076 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
5078 // scroll bar and buttons may just have been added after reloading scores
5079 if (game_status == GAME_MODE_SCORES)
5080 MapScreenTreeGadgets(ti);
5083 static void drawChooseTreeScreen_Scores_NotAvailable(void)
5085 // dirty workaround to use spacing definitions from info screen
5086 info_mode = INFO_MODE_TITLE;
5088 char *text_info = "HighScores of Level %d";
5089 char *text_title = "Score information:";
5090 char *text_error = "No scores for this level.";
5091 char *text_foot = "Press any key or button for main menu";
5092 int font_info = FONT_TITLE_2;
5093 int font_title = FONT_INITIAL_3;
5094 int font_error = FONT_INITIAL_4;
5095 int font_foot = FONT_INITIAL_2;
5096 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
5097 int ystep_title = getMenuTextStep(spacing_title, font_title);
5098 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
5099 int ystart2 = ystart1 + ystep_title;
5100 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
5101 int ystart0 = MENU_TITLE2_YPOS;
5103 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
5104 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
5106 DrawTextSCentered(ystart1, font_title, text_title);
5107 DrawTextSCentered(ystart2, font_error, text_error);
5109 DrawTextSCentered(ybottom, font_foot, text_foot);
5112 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
5114 // set current tree entry to last added score entry
5115 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(scores.last_added));
5117 // if that fails, set current tree entry to first entry (back link)
5118 if (*ti_ptr == NULL)
5119 *ti_ptr = score_entries->node_group;
5121 int num_entries = numTreeInfoInGroup(*ti_ptr);
5122 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5123 int pos_score = getPosFromTreeInfo(*ti_ptr);
5124 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5125 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5127 (*ti_ptr)->cl_first = pos_first;
5128 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5133 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5136 TreeInfo *ti = *ti_ptr;
5137 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5138 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5139 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5140 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5141 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5143 int y = (ti != NULL ? ti->cl_cursor : 0);
5144 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5145 int num_entries = numTreeInfoInGroup(ti);
5146 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5147 boolean position_set_by_scrollbar = (dx == 999);
5148 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5149 boolean button_is_valid = (mx >= 0 && my >= 0);
5150 boolean button_screen_clicked = (button_action && button_is_valid);
5152 if (game_status == GAME_MODE_SCORES)
5154 if (server_scores.updated)
5156 // reload scores, using updated server score cache file
5157 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5159 server_scores.updated = FALSE;
5161 DrawHallOfFame_setScoreEntries();
5163 if (score_entries != NULL)
5165 ti = setHallOfFameActiveEntry(ti_ptr);
5167 if (button != MB_MENU_INITIALIZE)
5168 drawChooseTreeScreen(ti);
5172 if (score_entries == NULL)
5174 if (button == MB_MENU_INITIALIZE)
5176 drawChooseTreeScreen_Scores_NotAvailable();
5178 else if (button_screen_clicked)
5180 PlaySound(SND_MENU_ITEM_SELECTING);
5182 SetGameStatus(GAME_MODE_MAIN);
5191 if (button == MB_MENU_INITIALIZE)
5193 int num_entries = numTreeInfoInGroup(ti);
5194 int entry_pos = getPosFromTreeInfo(ti);
5196 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5197 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5199 if (game_status == GAME_MODE_SCORES)
5201 ti = setHallOfFameActiveEntry(ti_ptr);
5203 else if (ti->cl_first == -1)
5205 // only on initialization
5206 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5207 ti->cl_cursor = entry_pos - ti->cl_first;
5210 else if (ti->cl_cursor >= num_page_entries ||
5211 (num_entries > num_page_entries &&
5212 num_entries - ti->cl_first < num_page_entries))
5214 // only after change of list size (by custom graphic configuration)
5215 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5216 ti->cl_cursor = entry_pos - ti->cl_first;
5219 if (position_set_by_scrollbar)
5222 drawChooseTreeScreen(ti);
5226 else if (button == MB_MENU_LEAVE)
5228 if (game_status != GAME_MODE_SCORES)
5231 PlaySound(SND_MENU_ITEM_SELECTING);
5233 if (ti->node_parent)
5235 *ti_ptr = ti->node_parent;
5236 DrawChooseTree(ti_ptr);
5238 else if (game_status == GAME_MODE_SETUP)
5240 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5241 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5242 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5243 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5245 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5246 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5247 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5248 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5249 execSetupGraphics();
5250 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5251 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5252 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5254 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5255 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5256 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5257 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5258 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5259 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5260 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5261 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5268 if (game_status == GAME_MODE_LEVELNR)
5270 int new_level_nr = atoi(level_number_current->identifier);
5272 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5275 SetGameStatus(GAME_MODE_MAIN);
5283 if (mx || my) // mouse input
5285 x = (mx - amSX) / 32;
5286 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5288 if (game_status == GAME_MODE_NAMES)
5289 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5291 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5293 // move cursor instead of scrolling when already at start/end of list
5294 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5296 else if (dy == +1 * SCROLL_LINE &&
5297 ti->cl_first + num_page_entries == num_entries)
5300 // handle scrolling screen one line or page
5301 if (ti->cl_cursor + dy < 0 ||
5302 ti->cl_cursor + dy > num_page_entries - 1)
5304 boolean redraw = FALSE;
5306 if (ABS(dy) == SCROLL_PAGE)
5307 step = num_page_entries - 1;
5309 if (dy < 0 && ti->cl_first > 0)
5311 // scroll page/line up
5313 ti->cl_first -= step;
5314 if (ti->cl_first < 0)
5319 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5321 // scroll page/line down
5323 ti->cl_first += step;
5324 if (ti->cl_first + num_page_entries > num_entries)
5325 ti->cl_first = MAX(0, num_entries - num_page_entries);
5331 drawChooseTreeScreen(ti);
5336 // handle moving cursor one line
5337 y = ti->cl_cursor + dy;
5340 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5342 HandleHallOfFame_SelectLevel(1, dx);
5348 TreeInfo *node_first, *node_cursor;
5349 int entry_pos = ti->cl_first + y;
5351 node_first = getTreeInfoFirstGroupEntry(ti);
5352 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5354 if (node_cursor->node_group)
5358 PlaySound(SND_MENU_ITEM_SELECTING);
5360 node_cursor->cl_first = ti->cl_first;
5361 node_cursor->cl_cursor = ti->cl_cursor;
5362 *ti_ptr = node_cursor->node_group;
5363 DrawChooseTree(ti_ptr);
5368 else if (dx == -1 && ti->node_parent)
5372 PlaySound(SND_MENU_ITEM_SELECTING);
5374 *ti_ptr = ti->node_parent;
5375 DrawChooseTree(ti_ptr);
5380 if (!anyScrollbarGadgetActive() &&
5381 IN_VIS_MENU(x, y) &&
5382 mx < mx_right_border &&
5383 y >= 0 && y < num_page_entries)
5387 if (game_status == GAME_MODE_NAMES)
5389 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5390 drawChooseTreeEdit(y, TRUE);
5393 if (y != ti->cl_cursor)
5395 PlaySound(SND_MENU_ITEM_ACTIVATING);
5397 drawChooseTreeCursorAndText(ti, FALSE);
5401 drawChooseTreeCursorAndText(ti, TRUE);
5403 drawChooseTreeInfo(ti);
5407 if (game_status == GAME_MODE_SETUP)
5409 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5410 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5411 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5412 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5414 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5415 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5416 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5417 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5418 execSetupGraphics();
5419 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5420 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5421 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5423 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5424 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5425 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5426 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5427 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5428 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5429 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5430 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5439 TreeInfo *node_first, *node_cursor;
5440 int entry_pos = ti->cl_first + y;
5442 PlaySound(SND_MENU_ITEM_SELECTING);
5444 node_first = getTreeInfoFirstGroupEntry(ti);
5445 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5447 if (node_cursor->node_group)
5451 node_cursor->cl_first = ti->cl_first;
5452 node_cursor->cl_cursor = ti->cl_cursor;
5453 *ti_ptr = node_cursor->node_group;
5454 DrawChooseTree(ti_ptr);
5456 else if (node_cursor->parent_link)
5458 if (game_status != GAME_MODE_SCORES)
5461 *ti_ptr = node_cursor->node_parent;
5462 DrawChooseTree(ti_ptr);
5466 if (game_status != GAME_MODE_SCORES)
5469 node_cursor->cl_first = ti->cl_first;
5470 node_cursor->cl_cursor = ti->cl_cursor;
5471 *ti_ptr = node_cursor;
5473 if (ti->type == TREE_TYPE_LEVEL_DIR)
5475 LoadLevelSetup_SeriesInfo();
5477 SaveLevelSetup_LastSeries();
5478 SaveLevelSetup_SeriesInfo();
5482 if (game_status == GAME_MODE_SETUP)
5484 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5485 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5486 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5487 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5489 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5490 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5491 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5492 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5493 execSetupGraphics();
5494 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5495 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5496 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5498 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5499 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5500 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5501 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5502 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5503 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5504 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5505 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5512 if (game_status == GAME_MODE_LEVELNR)
5514 int new_level_nr = atoi(level_number_current->identifier);
5516 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5518 else if (game_status == GAME_MODE_LEVELS)
5520 // store level set if chosen from "last played level set" menu
5521 StoreLastPlayedLevels(leveldir_current);
5523 else if (game_status == GAME_MODE_NAMES)
5525 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5527 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5534 // change active user to selected user
5535 user.nr = entry_pos;
5537 // save number of new active user
5540 // load setup of new active user
5543 // load last level set of new active user
5544 LoadLevelSetup_LastSeries();
5545 LoadLevelSetup_SeriesInfo();
5547 // update list of last played level sets
5548 UpdateLastPlayedLevels_TreeInfo();
5552 ToggleFullscreenIfNeeded();
5553 ChangeWindowScalingIfNeeded();
5555 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5556 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5557 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5559 else if (game_status == GAME_MODE_SCORES)
5561 if (game_status_last_screen == GAME_MODE_PLAYING &&
5562 setup.auto_play_next_level && setup.increment_levels &&
5563 scores.last_level_nr < leveldir_current->last_level &&
5566 StartGameActions(network.enabled, setup.autorecord,
5572 SetGameStatus(GAME_MODE_SCOREINFO);
5574 DrawScoreInfo(node_cursor->pos);
5580 SetGameStatus(GAME_MODE_MAIN);
5588 if (game_status == GAME_MODE_SCORES)
5589 PlayMenuSoundIfLoop();
5592 void DrawChoosePlayerName(void)
5596 if (player_name != NULL)
5598 freeTreeInfo(player_name);
5603 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5605 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5606 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5609 ti->node_top = &player_name;
5610 ti->sort_priority = 10000 + value;
5611 ti->color = getPlayerNameColor(global.user_names[i]);
5613 snprintf(identifier, sizeof(identifier), "%d", value);
5614 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5616 setString(&ti->identifier, identifier);
5617 setString(&ti->name, name);
5618 setString(&ti->name_sorting, name);
5620 pushTreeInfo(&player_name, ti);
5623 // sort player entries by player number
5624 sortTreeInfo(&player_name);
5626 // set current player entry to selected player entry
5627 player_name_current =
5628 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5630 // if that fails, set current player name to first available name
5631 if (player_name_current == NULL)
5632 player_name_current = player_name;
5634 DrawChooseTree(&player_name_current);
5637 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5639 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5642 void DrawChooseLevelSet(void)
5644 DrawChooseTree(&leveldir_current);
5647 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5649 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5652 void DrawChooseLevelNr(void)
5656 if (level_number != NULL)
5658 freeTreeInfo(level_number);
5660 level_number = NULL;
5663 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5665 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5666 char identifier[32], name[64];
5669 // temporarily load level info to get level name
5670 LoadLevelInfoOnly(i);
5672 ti->node_top = &level_number;
5673 ti->sort_priority = 10000 + value;
5674 ti->color = (level.no_level_file ? FC_BLUE :
5675 LevelStats_getSolved(i) ? FC_GREEN :
5676 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5678 snprintf(identifier, sizeof(identifier), "%d", value);
5679 snprintf(name, sizeof(name), "%03d: %s", value,
5680 (level.no_level_file ? "(no file)" : level.name));
5682 setString(&ti->identifier, identifier);
5683 setString(&ti->name, name);
5684 setString(&ti->name_sorting, name);
5686 pushTreeInfo(&level_number, ti);
5689 // sort level number values to start with lowest level number
5690 sortTreeInfo(&level_number);
5692 // set current level number to current level number
5693 level_number_current =
5694 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5696 // if that also fails, set current level number to first available level
5697 if (level_number_current == NULL)
5698 level_number_current = level_number;
5700 DrawChooseTree(&level_number_current);
5703 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5705 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5708 static void DrawHallOfFame_setScoreEntries(void)
5710 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5713 if (score_entries != NULL)
5715 freeTreeInfo(score_entries);
5717 score_entries = NULL;
5720 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5722 // do not add empty score entries
5723 if (scores.entry[i].score == 0 &&
5724 scores.entry[i].time == 0)
5727 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5728 char identifier[32], name[64];
5731 ti->node_top = &score_entries;
5732 ti->sort_priority = 10000 + value;
5733 ti->color = FC_YELLOW;
5736 snprintf(identifier, sizeof(identifier), "%d", value);
5737 snprintf(name, sizeof(name), "%03d.", value + 1);
5739 setString(&ti->identifier, identifier);
5740 setString(&ti->name, name);
5741 setString(&ti->name_sorting, name);
5743 pushTreeInfo(&score_entries, ti);
5746 // sort score entries to start with highest score entry
5747 sortTreeInfo(&score_entries);
5749 // add top tree node to create back link to main menu
5750 score_entries = addTopTreeInfoNode(score_entries);
5752 // set current score entry to last added or highest score entry
5753 score_entry_current =
5754 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5756 // if that fails, set current score entry to first valid score entry
5757 if (score_entry_current == NULL)
5758 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5760 // ("score_entries" and "score_entry_current" may be NULL here)
5763 void DrawHallOfFame(int level_nr)
5765 scores.last_level_nr = level_nr;
5767 // (this is needed when called from GameEnd() after winning a game)
5768 KeyboardAutoRepeatOn();
5770 // (this is needed when called from GameEnd() after winning a game)
5771 SetDrawDeactivationMask(REDRAW_NONE);
5772 SetDrawBackgroundMask(REDRAW_FIELD);
5774 LoadLocalAndServerScore(level_nr, TRUE);
5776 DrawHallOfFame_setScoreEntries();
5778 if (scores.last_added >= 0)
5779 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5781 FadeSetEnterScreen();
5783 DrawChooseTree(&score_entry_current);
5786 static char *getHallOfFameRankText(int nr)
5788 boolean forced = (scores.force_last_added && nr == scores.last_added);
5790 return (forced ? "???" : int2str(nr + 1, 3));
5793 static char *getHallOfFameTimeText(int nr)
5795 static char score_text[10];
5796 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5797 int mm = (time_seconds / 60) % 60;
5798 int ss = (time_seconds % 60);
5800 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5805 static char *getHallOfFameScoreText(int nr)
5807 if (!level.rate_time_over_score)
5808 return int2str(scores.entry[nr].score, 5); // show normal score
5809 else if (level.use_step_counter)
5810 return int2str(scores.entry[nr].time, 5); // show number of steps
5812 return getHallOfFameTimeText(nr); // show playing time
5815 static void HandleHallOfFame_SelectLevel(int step, int direction)
5817 int old_level_nr = scores.last_level_nr;
5818 int new_level_nr = old_level_nr + step * direction;
5820 if (new_level_nr < leveldir_current->first_level)
5821 new_level_nr = leveldir_current->first_level;
5822 if (new_level_nr > leveldir_current->last_level)
5823 new_level_nr = leveldir_current->last_level;
5825 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5826 new_level_nr = leveldir_current->handicap_level;
5828 if (new_level_nr != old_level_nr)
5830 PlaySound(SND_MENU_ITEM_SELECTING);
5832 scores.last_level_nr = level_nr = new_level_nr;
5834 LoadLocalAndServerScore(level_nr, TRUE);
5836 DrawHallOfFame_setScoreEntries();
5838 // force remapping optional gadgets (especially scroll bar)
5839 UnmapScreenTreeGadgets();
5841 // redraw complete high score screen, as sub-title has changed
5844 // redraw level selection buttons (which have just been erased)
5845 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5847 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5849 SaveLevelSetup_SeriesInfo();
5853 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5855 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5858 static void DrawScoreInfo_Content(int entry_nr)
5860 struct ScoreEntry *entry = &scores.entry[entry_nr];
5861 char *pos_text = getHallOfFameRankText(entry_nr);
5862 int font_title = MENU_INFO_FONT_TITLE;
5863 int font_head = MENU_INFO_FONT_HEAD;
5864 int font_text = MENU_INFO_FONT_TEXT;
5865 int font_foot = MENU_INFO_FONT_FOOT;
5866 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5867 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5868 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5869 int xstep = getFontWidth(font_text);
5870 int ystep_title = getMenuTextStep(spacing_title, font_title);
5871 int ystep_para = getMenuTextStep(spacing_para, font_text);
5872 int ystep_line = getMenuTextStep(spacing_line, font_text);
5873 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5874 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5875 int xstart1 = mSX - SX + 2 * xstep;
5876 int xstart2 = mSX - SX + 14 * xstep;
5880 drawChooseTreeHead(score_entries);
5881 drawChooseTreeInfo(score_entries);
5883 DrawTextSCentered(ystart, font_title, "Score Information:");
5884 ystart += ystep_title;
5886 DrawTextF(xstart1, ystart, font_head, "Level Set");
5887 DrawTextF(xstart2, ystart, font_text, leveldir_current->name);
5888 ystart += ystep_line;
5890 DrawTextF(xstart1, ystart, font_head, "Level Name");
5891 DrawTextF(xstart2, ystart, font_text, level.name);
5892 ystart += ystep_para;
5894 DrawTextF(xstart1, ystart, font_head, "Rank");
5895 DrawTextF(xstart2, ystart, font_text, pos_text);
5896 ystart += ystep_line;
5898 DrawTextF(xstart1, ystart, font_head, "Player");
5899 DrawTextF(xstart2, ystart, font_text, entry->name);
5900 ystart += ystep_line;
5902 if (level.use_step_counter)
5904 DrawTextF(xstart1, ystart, font_head, "Steps");
5905 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5906 ystart += ystep_line;
5910 DrawTextF(xstart1, ystart, font_head, "Time");
5911 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5912 ystart += ystep_line;
5915 if (!level.rate_time_over_score || entry->score > 0)
5917 DrawTextF(xstart1, ystart, font_head, "Score");
5918 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5919 ystart += ystep_line;
5922 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5925 static void DrawScoreInfo(int entry_nr)
5927 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5931 FadeOut(REDRAW_FIELD);
5933 DrawScoreInfo_Content(entry_nr);
5935 FadeIn(REDRAW_FIELD);
5938 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5940 if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5942 PlaySound(SND_MENU_ITEM_SELECTING);
5944 SetGameStatus(GAME_MODE_SCORES);
5946 DrawHallOfFame(level_nr);
5951 // ============================================================================
5952 // setup screen functions
5953 // ============================================================================
5955 static struct TokenInfo *setup_info;
5956 static int num_setup_info; // number of setup entries shown on screen
5957 static int max_setup_info; // total number of setup entries in list
5959 static char *window_size_text;
5960 static char *scaling_type_text;
5961 static char *rendering_mode_text;
5962 static char *vsync_mode_text;
5963 static char *scroll_delay_text;
5964 static char *snapshot_mode_text;
5965 static char *game_speed_text;
5966 static char *scores_type_text;
5967 static char *network_server_text;
5968 static char *graphics_set_name;
5969 static char *sounds_set_name;
5970 static char *music_set_name;
5971 static char *volume_simple_text;
5972 static char *volume_loops_text;
5973 static char *volume_music_text;
5974 static char *touch_controls_text;
5975 static char *move_distance_text;
5976 static char *drop_distance_text;
5977 static char *transparency_text;
5978 static char *grid_size_text[2][2];
5980 static void execSetupMain(void)
5982 setup_mode = SETUP_MODE_MAIN;
5987 static void execSetupGame_setScoresType(void)
5989 if (scores_types == NULL)
5993 for (i = 0; scores_types_list[i].value != NULL; i++)
5995 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5996 char identifier[32], name[32];
5997 char *value = scores_types_list[i].value;
5998 char *text = scores_types_list[i].text;
6000 ti->node_top = &scores_types;
6001 ti->sort_priority = i;
6003 sprintf(identifier, "%s", value);
6004 sprintf(name, "%s", text);
6006 setString(&ti->identifier, identifier);
6007 setString(&ti->name, name);
6008 setString(&ti->name_sorting, name);
6009 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
6011 pushTreeInfo(&scores_types, ti);
6014 // sort scores type values to start with lowest scores type value
6015 sortTreeInfo(&scores_types);
6017 // set current scores type value to configured scores type value
6018 scores_type_current =
6019 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
6021 // if that fails, set current scores type to reliable default value
6022 if (scores_type_current == NULL)
6023 scores_type_current =
6024 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
6026 // if that also fails, set current scores type to first available value
6027 if (scores_type_current == NULL)
6028 scores_type_current = scores_types;
6031 setup.scores_in_highscore_list = scores_type_current->identifier;
6033 // needed for displaying scores type text instead of identifier
6034 scores_type_text = scores_type_current->name;
6037 static void execSetupGame_setGameSpeeds(boolean update_value)
6039 if (setup.game_speed_extended)
6041 game_speeds_list = game_speeds_list_extended;
6042 game_speeds = game_speeds_extended;
6046 game_speeds_list = game_speeds_list_normal;
6047 game_speeds = game_speeds_normal;
6050 if (game_speeds == NULL)
6054 for (i = 0; game_speeds_list[i].value != -1; i++)
6056 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6057 char identifier[32], name[32];
6058 int value = game_speeds_list[i].value;
6059 char *text = game_speeds_list[i].text;
6061 ti->node_top = &game_speeds;
6062 ti->sort_priority = 10000 - value;
6064 sprintf(identifier, "%d", value);
6065 sprintf(name, "%s", text);
6067 setString(&ti->identifier, identifier);
6068 setString(&ti->name, name);
6069 setString(&ti->name_sorting, name);
6070 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
6072 pushTreeInfo(&game_speeds, ti);
6075 // sort game speed values to start with slowest game speed
6076 sortTreeInfo(&game_speeds);
6078 update_value = TRUE;
6083 // set current game speed to configured game speed value
6084 game_speed_current =
6085 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6087 // if that fails, set current game speed to reliable default value
6088 if (game_speed_current == NULL)
6089 game_speed_current =
6090 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6092 // if that also fails, set current game speed to first available speed
6093 if (game_speed_current == NULL)
6094 game_speed_current = game_speeds;
6096 if (setup.game_speed_extended)
6097 game_speeds_extended = game_speeds;
6099 game_speeds_normal = game_speeds;
6102 setup.game_frame_delay = atoi(game_speed_current->identifier);
6104 // needed for displaying game speed text instead of identifier
6105 game_speed_text = game_speed_current->name;
6108 static void execSetupGame_setScrollDelays(void)
6110 if (scroll_delays == NULL)
6114 for (i = 0; scroll_delays_list[i].value != -1; i++)
6116 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6117 char identifier[32], name[32];
6118 int value = scroll_delays_list[i].value;
6119 char *text = scroll_delays_list[i].text;
6121 ti->node_top = &scroll_delays;
6122 ti->sort_priority = value;
6124 sprintf(identifier, "%d", value);
6125 sprintf(name, "%s", text);
6127 setString(&ti->identifier, identifier);
6128 setString(&ti->name, name);
6129 setString(&ti->name_sorting, name);
6130 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6132 pushTreeInfo(&scroll_delays, ti);
6135 // sort scroll delay values to start with lowest scroll delay value
6136 sortTreeInfo(&scroll_delays);
6138 // set current scroll delay value to configured scroll delay value
6139 scroll_delay_current =
6140 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6142 // if that fails, set current scroll delay to reliable default value
6143 if (scroll_delay_current == NULL)
6144 scroll_delay_current =
6145 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6147 // if that also fails, set current scroll delay to first available value
6148 if (scroll_delay_current == NULL)
6149 scroll_delay_current = scroll_delays;
6152 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6154 // needed for displaying scroll delay text instead of identifier
6155 scroll_delay_text = scroll_delay_current->name;
6158 static void execSetupGame_setSnapshotModes(void)
6160 if (snapshot_modes == NULL)
6164 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6166 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6167 char identifier[32], name[32];
6168 char *value = snapshot_modes_list[i].value;
6169 char *text = snapshot_modes_list[i].text;
6171 ti->node_top = &snapshot_modes;
6172 ti->sort_priority = i;
6174 sprintf(identifier, "%s", value);
6175 sprintf(name, "%s", text);
6177 setString(&ti->identifier, identifier);
6178 setString(&ti->name, name);
6179 setString(&ti->name_sorting, name);
6180 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6182 pushTreeInfo(&snapshot_modes, ti);
6185 // sort snapshot mode values to start with lowest snapshot mode value
6186 sortTreeInfo(&snapshot_modes);
6188 // set current snapshot mode value to configured snapshot mode value
6189 snapshot_mode_current =
6190 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6192 // if that fails, set current snapshot mode to reliable default value
6193 if (snapshot_mode_current == NULL)
6194 snapshot_mode_current =
6195 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6197 // if that also fails, set current snapshot mode to first available value
6198 if (snapshot_mode_current == NULL)
6199 snapshot_mode_current = snapshot_modes;
6202 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6204 // needed for displaying snapshot mode text instead of identifier
6205 snapshot_mode_text = snapshot_mode_current->name;
6208 static void execSetupGame_setNetworkServerText(void)
6210 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6212 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6216 strncpy(network_server_hostname, setup.network_server_hostname,
6217 MAX_SETUP_TEXT_INPUT_LEN);
6218 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6221 // needed for displaying network server text instead of identifier
6222 network_server_text = network_server_hostname;
6225 static void execSetupGame(void)
6227 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6229 execSetupGame_setGameSpeeds(FALSE);
6230 execSetupGame_setScoresType();
6231 execSetupGame_setScrollDelays();
6232 execSetupGame_setSnapshotModes();
6234 execSetupGame_setNetworkServerText();
6236 if (!setup.provide_uploading_tapes)
6237 setHideSetupEntry(execOfferUploadTapes);
6239 setup_mode = SETUP_MODE_GAME;
6243 // check if vsync needs to be disabled for this game speed to work
6244 if (check_vsync_mode)
6245 DisableVsyncIfNeeded();
6248 static void execSetupChooseScoresType(void)
6250 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6255 static void execSetupChooseGameSpeed(void)
6257 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6262 static void execSetupChooseScrollDelay(void)
6264 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6269 static void execSetupChooseSnapshotMode(void)
6271 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6276 static void execSetupEngines(void)
6278 setup_mode = SETUP_MODE_ENGINES;
6283 static void execSetupEditor(void)
6285 setup_mode = SETUP_MODE_EDITOR;
6290 static void execSetupGraphics_setWindowSizes(boolean update_list)
6292 if (window_sizes != NULL && update_list)
6294 freeTreeInfo(window_sizes);
6296 window_sizes = NULL;
6299 if (window_sizes == NULL)
6301 boolean current_window_size_found = FALSE;
6304 for (i = 0; window_sizes_list[i].value != -1; i++)
6306 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6307 char identifier[32], name[32];
6308 int value = window_sizes_list[i].value;
6309 char *text = window_sizes_list[i].text;
6311 ti->node_top = &window_sizes;
6312 ti->sort_priority = value;
6314 sprintf(identifier, "%d", value);
6315 sprintf(name, "%s", text);
6317 setString(&ti->identifier, identifier);
6318 setString(&ti->name, name);
6319 setString(&ti->name_sorting, name);
6320 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6322 pushTreeInfo(&window_sizes, ti);
6324 if (value == setup.window_scaling_percent)
6325 current_window_size_found = TRUE;
6328 if (!current_window_size_found)
6330 // add entry for non-preset window scaling value
6332 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6333 char identifier[32], name[32];
6334 int value = setup.window_scaling_percent;
6336 ti->node_top = &window_sizes;
6337 ti->sort_priority = value;
6339 sprintf(identifier, "%d", value);
6340 sprintf(name, "%d %% (Current)", value);
6342 setString(&ti->identifier, identifier);
6343 setString(&ti->name, name);
6344 setString(&ti->name_sorting, name);
6345 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6347 pushTreeInfo(&window_sizes, ti);
6350 // sort window size values to start with lowest window size value
6351 sortTreeInfo(&window_sizes);
6353 // set current window size value to configured window size value
6354 window_size_current =
6355 getTreeInfoFromIdentifier(window_sizes,
6356 i_to_a(setup.window_scaling_percent));
6358 // if that fails, set current window size to reliable default value
6359 if (window_size_current == NULL)
6360 window_size_current =
6361 getTreeInfoFromIdentifier(window_sizes,
6362 i_to_a(STD_WINDOW_SCALING_PERCENT));
6364 // if that also fails, set current window size to first available value
6365 if (window_size_current == NULL)
6366 window_size_current = window_sizes;
6369 setup.window_scaling_percent = atoi(window_size_current->identifier);
6371 // needed for displaying window size text instead of identifier
6372 window_size_text = window_size_current->name;
6375 static void execSetupGraphics_setScalingTypes(void)
6377 if (scaling_types == NULL)
6381 for (i = 0; scaling_types_list[i].value != NULL; i++)
6383 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6384 char identifier[32], name[32];
6385 char *value = scaling_types_list[i].value;
6386 char *text = scaling_types_list[i].text;
6388 ti->node_top = &scaling_types;
6389 ti->sort_priority = i;
6391 sprintf(identifier, "%s", value);
6392 sprintf(name, "%s", text);
6394 setString(&ti->identifier, identifier);
6395 setString(&ti->name, name);
6396 setString(&ti->name_sorting, name);
6397 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6399 pushTreeInfo(&scaling_types, ti);
6402 // sort scaling type values to start with lowest scaling type value
6403 sortTreeInfo(&scaling_types);
6405 // set current scaling type value to configured scaling type value
6406 scaling_type_current =
6407 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6409 // if that fails, set current scaling type to reliable default value
6410 if (scaling_type_current == NULL)
6411 scaling_type_current =
6412 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6414 // if that also fails, set current scaling type to first available value
6415 if (scaling_type_current == NULL)
6416 scaling_type_current = scaling_types;
6419 setup.window_scaling_quality = scaling_type_current->identifier;
6421 // needed for displaying scaling type text instead of identifier
6422 scaling_type_text = scaling_type_current->name;
6425 static void execSetupGraphics_setRenderingModes(void)
6427 if (rendering_modes == NULL)
6431 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6433 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6434 char identifier[32], name[32];
6435 char *value = rendering_modes_list[i].value;
6436 char *text = rendering_modes_list[i].text;
6438 ti->node_top = &rendering_modes;
6439 ti->sort_priority = i;
6441 sprintf(identifier, "%s", value);
6442 sprintf(name, "%s", text);
6444 setString(&ti->identifier, identifier);
6445 setString(&ti->name, name);
6446 setString(&ti->name_sorting, name);
6447 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6449 pushTreeInfo(&rendering_modes, ti);
6452 // sort rendering mode values to start with lowest rendering mode value
6453 sortTreeInfo(&rendering_modes);
6455 // set current rendering mode value to configured rendering mode value
6456 rendering_mode_current =
6457 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6459 // if that fails, set current rendering mode to reliable default value
6460 if (rendering_mode_current == NULL)
6461 rendering_mode_current =
6462 getTreeInfoFromIdentifier(rendering_modes,
6463 STR_SPECIAL_RENDERING_DEFAULT);
6465 // if that also fails, set current rendering mode to first available one
6466 if (rendering_mode_current == NULL)
6467 rendering_mode_current = rendering_modes;
6470 setup.screen_rendering_mode = rendering_mode_current->identifier;
6472 // needed for displaying rendering mode text instead of identifier
6473 rendering_mode_text = rendering_mode_current->name;
6476 static void execSetupGraphics_setVsyncModes(boolean update_value)
6478 if (vsync_modes == NULL)
6482 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6484 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6485 char identifier[32], name[32];
6486 char *value = vsync_modes_list[i].value;
6487 char *text = vsync_modes_list[i].text;
6489 ti->node_top = &vsync_modes;
6490 ti->sort_priority = i;
6492 sprintf(identifier, "%s", value);
6493 sprintf(name, "%s", text);
6495 setString(&ti->identifier, identifier);
6496 setString(&ti->name, name);
6497 setString(&ti->name_sorting, name);
6498 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6500 pushTreeInfo(&vsync_modes, ti);
6503 // sort vsync mode values to start with lowest vsync mode value
6504 sortTreeInfo(&vsync_modes);
6506 update_value = TRUE;
6511 // set current vsync mode value to configured vsync mode value
6512 vsync_mode_current =
6513 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6515 // if that fails, set current vsync mode to reliable default value
6516 if (vsync_mode_current == NULL)
6517 vsync_mode_current =
6518 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6520 // if that also fails, set current vsync mode to first available one
6521 if (vsync_mode_current == NULL)
6522 vsync_mode_current = vsync_modes;
6525 setup.vsync_mode = vsync_mode_current->identifier;
6527 // needed for displaying vsync mode text instead of identifier
6528 vsync_mode_text = vsync_mode_current->name;
6531 static void execSetupGraphics(void)
6533 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6535 // update "setup.window_scaling_percent" from list selection
6536 // (in this case, window scaling was changed on setup screen)
6537 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6538 execSetupGraphics_setWindowSizes(FALSE);
6540 // update "setup.vsync_mode" from list selection
6541 // (in this case, vsync mode was changed on setup screen)
6542 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6543 execSetupGraphics_setVsyncModes(FALSE);
6545 // update list selection from "setup.window_scaling_percent"
6546 // (window scaling may have changed by resizing the window)
6547 execSetupGraphics_setWindowSizes(TRUE);
6549 // update list selection from "setup.vsync_mode"
6550 // (vsync_mode may have changed by re-creating the renderer)
6551 execSetupGraphics_setVsyncModes(TRUE);
6553 execSetupGraphics_setScalingTypes();
6554 execSetupGraphics_setRenderingModes();
6556 setup_mode = SETUP_MODE_GRAPHICS;
6560 // check if game speed is high enough for 60 Hz vsync to work
6561 if (check_game_speed)
6562 ModifyGameSpeedIfNeeded();
6564 // window scaling may have changed at this point
6565 ChangeWindowScalingIfNeeded();
6567 // window scaling quality may have changed at this point
6568 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6569 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6571 // screen rendering mode may have changed at this point
6572 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6574 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6575 int video_vsync_mode = video.vsync_mode;
6577 // screen vsync mode may have changed at this point
6578 ChangeVsyncModeIfNeeded();
6580 // check if setting vsync mode to selected value failed
6581 if (setup_vsync_mode != video_vsync_mode &&
6582 setup_vsync_mode != video.vsync_mode)
6584 // changing vsync mode to selected value failed -- reset displayed value
6585 execSetupGraphics_setVsyncModes(TRUE);
6587 Request("Setting VSync failed!", REQ_CONFIRM);
6593 static void execSetupChooseWindowSize(void)
6595 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6600 static void execSetupChooseScalingType(void)
6602 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6607 static void execSetupChooseRenderingMode(void)
6609 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6614 static void execSetupChooseVsyncMode(void)
6616 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6621 static void execSetupChooseVolumeSimple(void)
6623 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6628 static void execSetupChooseVolumeLoops(void)
6630 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6635 static void execSetupChooseVolumeMusic(void)
6637 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6642 static void execSetupSound(void)
6644 if (volumes_simple == NULL)
6646 boolean current_volume_simple_found = FALSE;
6649 for (i = 0; volumes_list[i].value != -1; i++)
6651 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6652 char identifier[32], name[32];
6653 int value = volumes_list[i].value;
6654 char *text = volumes_list[i].text;
6656 ti->node_top = &volumes_simple;
6657 ti->sort_priority = value;
6659 sprintf(identifier, "%d", value);
6660 sprintf(name, "%s", text);
6662 setString(&ti->identifier, identifier);
6663 setString(&ti->name, name);
6664 setString(&ti->name_sorting, name);
6665 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6667 pushTreeInfo(&volumes_simple, ti);
6669 if (value == setup.volume_simple)
6670 current_volume_simple_found = TRUE;
6673 if (!current_volume_simple_found)
6675 // add entry for non-preset volume value
6677 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6678 char identifier[32], name[32];
6679 int value = setup.volume_simple;
6681 ti->node_top = &volumes_simple;
6682 ti->sort_priority = value;
6684 sprintf(identifier, "%d", value);
6685 sprintf(name, "%d %% (Current)", value);
6687 setString(&ti->identifier, identifier);
6688 setString(&ti->name, name);
6689 setString(&ti->name_sorting, name);
6690 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6692 pushTreeInfo(&volumes_simple, ti);
6695 // sort volume values to start with lowest volume value
6696 sortTreeInfo(&volumes_simple);
6698 // set current volume value to configured volume value
6699 volume_simple_current =
6700 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6702 // if that fails, set current volume to reliable default value
6703 if (volume_simple_current == NULL)
6704 volume_simple_current =
6705 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6707 // if that also fails, set current volume to first available value
6708 if (volume_simple_current == NULL)
6709 volume_simple_current = volumes_simple;
6712 if (volumes_loops == NULL)
6714 boolean current_volume_loops_found = FALSE;
6717 for (i = 0; volumes_list[i].value != -1; i++)
6719 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6720 char identifier[32], name[32];
6721 int value = volumes_list[i].value;
6722 char *text = volumes_list[i].text;
6724 ti->node_top = &volumes_loops;
6725 ti->sort_priority = value;
6727 sprintf(identifier, "%d", value);
6728 sprintf(name, "%s", text);
6730 setString(&ti->identifier, identifier);
6731 setString(&ti->name, name);
6732 setString(&ti->name_sorting, name);
6733 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6735 pushTreeInfo(&volumes_loops, ti);
6737 if (value == setup.volume_loops)
6738 current_volume_loops_found = TRUE;
6741 if (!current_volume_loops_found)
6743 // add entry for non-preset volume value
6745 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6746 char identifier[32], name[32];
6747 int value = setup.volume_loops;
6749 ti->node_top = &volumes_loops;
6750 ti->sort_priority = value;
6752 sprintf(identifier, "%d", value);
6753 sprintf(name, "%d %% (Current)", value);
6755 setString(&ti->identifier, identifier);
6756 setString(&ti->name, name);
6757 setString(&ti->name_sorting, name);
6758 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6760 pushTreeInfo(&volumes_loops, ti);
6763 // sort volume values to start with lowest volume value
6764 sortTreeInfo(&volumes_loops);
6766 // set current volume value to configured volume value
6767 volume_loops_current =
6768 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6770 // if that fails, set current volume to reliable default value
6771 if (volume_loops_current == NULL)
6772 volume_loops_current =
6773 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6775 // if that also fails, set current volume to first available value
6776 if (volume_loops_current == NULL)
6777 volume_loops_current = volumes_loops;
6780 if (volumes_music == NULL)
6782 boolean current_volume_music_found = FALSE;
6785 for (i = 0; volumes_list[i].value != -1; i++)
6787 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6788 char identifier[32], name[32];
6789 int value = volumes_list[i].value;
6790 char *text = volumes_list[i].text;
6792 ti->node_top = &volumes_music;
6793 ti->sort_priority = value;
6795 sprintf(identifier, "%d", value);
6796 sprintf(name, "%s", text);
6798 setString(&ti->identifier, identifier);
6799 setString(&ti->name, name);
6800 setString(&ti->name_sorting, name);
6801 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6803 pushTreeInfo(&volumes_music, ti);
6805 if (value == setup.volume_music)
6806 current_volume_music_found = TRUE;
6809 if (!current_volume_music_found)
6811 // add entry for non-preset volume value
6813 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6814 char identifier[32], name[32];
6815 int value = setup.volume_music;
6817 ti->node_top = &volumes_music;
6818 ti->sort_priority = value;
6820 sprintf(identifier, "%d", value);
6821 sprintf(name, "%d %% (Current)", value);
6823 setString(&ti->identifier, identifier);
6824 setString(&ti->name, name);
6825 setString(&ti->name_sorting, name);
6826 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6828 pushTreeInfo(&volumes_music, ti);
6831 // sort volume values to start with lowest volume value
6832 sortTreeInfo(&volumes_music);
6834 // set current volume value to configured volume value
6835 volume_music_current =
6836 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6838 // if that fails, set current volume to reliable default value
6839 if (volume_music_current == NULL)
6840 volume_music_current =
6841 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6843 // if that also fails, set current volume to first available value
6844 if (volume_music_current == NULL)
6845 volume_music_current = volumes_music;
6848 setup.volume_simple = atoi(volume_simple_current->identifier);
6849 setup.volume_loops = atoi(volume_loops_current->identifier);
6850 setup.volume_music = atoi(volume_music_current->identifier);
6852 // needed for displaying volume text instead of identifier
6853 volume_simple_text = volume_simple_current->name;
6854 volume_loops_text = volume_loops_current->name;
6855 volume_music_text = volume_music_current->name;
6857 setup_mode = SETUP_MODE_SOUND;
6862 static void execSetupChooseTouchControls(void)
6864 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6869 static void execSetupChooseMoveDistance(void)
6871 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6876 static void execSetupChooseDropDistance(void)
6878 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6883 static void execSetupChooseTransparency(void)
6885 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6890 static void execSetupChooseGridXSize_0(void)
6892 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6897 static void execSetupChooseGridYSize_0(void)
6899 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6904 static void execSetupChooseGridXSize_1(void)
6906 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6911 static void execSetupChooseGridYSize_1(void)
6913 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6918 static void execSetupConfigureVirtualButtons(void)
6920 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6922 ConfigureVirtualButtons();
6924 setup_mode = SETUP_MODE_TOUCH;
6929 static void execSetupTouch(void)
6933 if (touch_controls == NULL)
6935 for (i = 0; touch_controls_list[i].value != NULL; i++)
6937 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6938 char identifier[32], name[32];
6939 char *value = touch_controls_list[i].value;
6940 char *text = touch_controls_list[i].text;
6942 ti->node_top = &touch_controls;
6943 ti->sort_priority = i;
6945 sprintf(identifier, "%s", value);
6946 sprintf(name, "%s", text);
6948 setString(&ti->identifier, identifier);
6949 setString(&ti->name, name);
6950 setString(&ti->name_sorting, name);
6951 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6953 pushTreeInfo(&touch_controls, ti);
6956 // sort touch control values to start with lowest touch control value
6957 sortTreeInfo(&touch_controls);
6959 // set current touch control value to configured touch control value
6960 touch_control_current =
6961 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6963 // if that fails, set current touch control to reliable default value
6964 if (touch_control_current == NULL)
6965 touch_control_current =
6966 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6968 // if that also fails, set current touch control to first available value
6969 if (touch_control_current == NULL)
6970 touch_control_current = touch_controls;
6973 if (move_distances == NULL)
6975 for (i = 0; distances_list[i].value != -1; i++)
6977 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6978 char identifier[32], name[32];
6979 int value = distances_list[i].value;
6980 char *text = distances_list[i].text;
6982 ti->node_top = &move_distances;
6983 ti->sort_priority = value;
6985 sprintf(identifier, "%d", value);
6986 sprintf(name, "%s", text);
6988 setString(&ti->identifier, identifier);
6989 setString(&ti->name, name);
6990 setString(&ti->name_sorting, name);
6991 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6993 pushTreeInfo(&move_distances, ti);
6996 // sort distance values to start with lowest distance value
6997 sortTreeInfo(&move_distances);
6999 // set current distance value to configured distance value
7000 move_distance_current =
7001 getTreeInfoFromIdentifier(move_distances,
7002 i_to_a(setup.touch.move_distance));
7004 // if that fails, set current distance to reliable default value
7005 if (move_distance_current == NULL)
7006 move_distance_current =
7007 getTreeInfoFromIdentifier(move_distances,
7008 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
7010 // if that also fails, set current distance to first available value
7011 if (move_distance_current == NULL)
7012 move_distance_current = move_distances;
7015 if (drop_distances == NULL)
7017 for (i = 0; distances_list[i].value != -1; i++)
7019 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7020 char identifier[32], name[32];
7021 int value = distances_list[i].value;
7022 char *text = distances_list[i].text;
7024 ti->node_top = &drop_distances;
7025 ti->sort_priority = value;
7027 sprintf(identifier, "%d", value);
7028 sprintf(name, "%s", text);
7030 setString(&ti->identifier, identifier);
7031 setString(&ti->name, name);
7032 setString(&ti->name_sorting, name);
7033 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
7035 pushTreeInfo(&drop_distances, ti);
7038 // sort distance values to start with lowest distance value
7039 sortTreeInfo(&drop_distances);
7041 // set current distance value to configured distance value
7042 drop_distance_current =
7043 getTreeInfoFromIdentifier(drop_distances,
7044 i_to_a(setup.touch.drop_distance));
7046 // if that fails, set current distance to reliable default value
7047 if (drop_distance_current == NULL)
7048 drop_distance_current =
7049 getTreeInfoFromIdentifier(drop_distances,
7050 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
7052 // if that also fails, set current distance to first available value
7053 if (drop_distance_current == NULL)
7054 drop_distance_current = drop_distances;
7057 if (transparencies == NULL)
7059 for (i = 0; transparencies_list[i].value != -1; i++)
7061 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7062 char identifier[32], name[32];
7063 int value = transparencies_list[i].value;
7064 char *text = transparencies_list[i].text;
7066 ti->node_top = &transparencies;
7067 ti->sort_priority = value;
7069 sprintf(identifier, "%d", value);
7070 sprintf(name, "%s", text);
7072 setString(&ti->identifier, identifier);
7073 setString(&ti->name, name);
7074 setString(&ti->name_sorting, name);
7075 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
7077 pushTreeInfo(&transparencies, ti);
7080 // sort transparency values to start with lowest transparency value
7081 sortTreeInfo(&transparencies);
7083 // set current transparency value to configured transparency value
7084 transparency_current =
7085 getTreeInfoFromIdentifier(transparencies,
7086 i_to_a(setup.touch.transparency));
7088 // if that fails, set current transparency to reliable default value
7089 if (transparency_current == NULL)
7090 transparency_current =
7091 getTreeInfoFromIdentifier(transparencies,
7092 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7094 // if that also fails, set current transparency to first available value
7095 if (transparency_current == NULL)
7096 transparency_current = transparencies;
7099 for (i = 0; i < 2; i++)
7101 for (j = 0; j < 2; j++)
7103 if (grid_sizes[i][j] == NULL)
7105 for (k = 0; grid_sizes_list[k].value != -1; k++)
7107 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7108 char identifier[32], name[32];
7109 int value = grid_sizes_list[k].value;
7110 char *text = grid_sizes_list[k].text;
7112 ti->node_top = &grid_sizes[i][j];
7113 ti->sort_priority = value;
7115 sprintf(identifier, "%d", value);
7116 sprintf(name, "%s", text);
7118 setString(&ti->identifier, identifier);
7119 setString(&ti->name, name);
7120 setString(&ti->name_sorting, name);
7121 setString(&ti->infotext,
7124 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7125 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7127 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7128 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7130 pushTreeInfo(&grid_sizes[i][j], ti);
7133 // sort grid size values to start with lowest grid size value
7134 sortTreeInfo(&grid_sizes[i][j]);
7136 // set current grid size value to configured grid size value
7137 grid_size_current[i][j] =
7138 getTreeInfoFromIdentifier(grid_sizes[i][j],
7140 setup.touch.grid_xsize[i] :
7141 setup.touch.grid_ysize[i]));
7143 // if that fails, set current grid size to reliable default value
7144 if (grid_size_current[i][j] == NULL)
7145 grid_size_current[i][j] =
7146 getTreeInfoFromIdentifier(grid_sizes[i][j],
7148 DEFAULT_GRID_XSIZE(i) :
7149 DEFAULT_GRID_YSIZE(i)));
7151 // if that also fails, set current grid size to first available value
7152 if (grid_size_current[i][j] == NULL)
7153 grid_size_current[i][j] = grid_sizes[i][j];
7158 setup.touch.control_type = touch_control_current->identifier;
7159 setup.touch.move_distance = atoi(move_distance_current->identifier);
7160 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7161 setup.touch.transparency = atoi(transparency_current->identifier);
7163 for (i = 0; i < 2; i++)
7165 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7166 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7168 if (i == GRID_ACTIVE_NR())
7170 overlay.grid_xsize = setup.touch.grid_xsize[i];
7171 overlay.grid_ysize = setup.touch.grid_ysize[i];
7175 // needed for displaying value text instead of identifier
7176 touch_controls_text = touch_control_current->name;
7177 move_distance_text = move_distance_current->name;
7178 drop_distance_text = drop_distance_current->name;
7179 transparency_text = transparency_current->name;
7181 for (i = 0; i < 2; i++)
7182 for (j = 0; j < 2; j++)
7183 grid_size_text[i][j] = grid_size_current[i][j]->name;
7185 setup_mode = SETUP_MODE_TOUCH;
7190 static void execSetupArtwork(void)
7192 static ArtworkDirTree *gfx_last_valid = NULL;
7193 static ArtworkDirTree *snd_last_valid = NULL;
7194 static ArtworkDirTree *mus_last_valid = NULL;
7196 // current artwork directory may be invalid (level group, parent link)
7197 if (!validLevelSeries(artwork.gfx_current))
7198 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7199 if (!validLevelSeries(artwork.snd_current))
7200 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7201 if (!validLevelSeries(artwork.mus_current))
7202 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7204 // store valid artwork directory information
7205 gfx_last_valid = artwork.gfx_current;
7206 snd_last_valid = artwork.snd_current;
7207 mus_last_valid = artwork.mus_current;
7210 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7211 artwork.gfx_current->subdir,
7212 artwork.gfx_current->fullpath,
7213 artwork.gfx_current->basepath);
7216 setup.graphics_set = artwork.gfx_current->identifier;
7217 setup.sounds_set = artwork.snd_current->identifier;
7218 setup.music_set = artwork.mus_current->identifier;
7220 // needed if last screen (setup choice) changed graphics, sounds or music
7221 ReloadCustomArtwork(0);
7223 // needed for displaying artwork name instead of artwork identifier
7224 graphics_set_name = artwork.gfx_current->name;
7225 sounds_set_name = artwork.snd_current->name;
7226 music_set_name = artwork.mus_current->name;
7228 setup_mode = SETUP_MODE_ARTWORK;
7233 static void execSetupChooseGraphics(void)
7235 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7240 static void execSetupChooseSounds(void)
7242 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7247 static void execSetupChooseMusic(void)
7249 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7254 static void execSetupInput(void)
7256 setup_mode = SETUP_MODE_INPUT;
7261 static void execSetupShortcuts(void)
7263 setup_mode = SETUP_MODE_SHORTCUTS;
7268 static void execSetupShortcuts1(void)
7270 setup_mode = SETUP_MODE_SHORTCUTS_1;
7275 static void execSetupShortcuts2(void)
7277 setup_mode = SETUP_MODE_SHORTCUTS_2;
7282 static void execSetupShortcuts3(void)
7284 setup_mode = SETUP_MODE_SHORTCUTS_3;
7289 static void execSetupShortcuts4(void)
7291 setup_mode = SETUP_MODE_SHORTCUTS_4;
7296 static void execSetupShortcuts5(void)
7298 setup_mode = SETUP_MODE_SHORTCUTS_5;
7303 static void execExitSetup(void)
7305 SetGameStatus(GAME_MODE_MAIN);
7310 static void execSaveAndExitSetup(void)
7316 static void execGadgetNetworkServer(void)
7318 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7319 struct GadgetInfo *gi = screen_gadget[gadget_id];
7321 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7322 network_server_hostname[0] = '\0';
7324 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7328 ClickOnGadget(gi, MB_LEFTBUTTON);
7331 static void execOfferUploadTapes(void)
7336 static void ToggleNetworkModeIfNeeded(void)
7338 int font_title = FONT_TITLE_1;
7339 int font_foot = FC_BLUE;
7340 int ystart = mSY - SY + 16;
7341 int ybottom = mSY - SY + SYSIZE - 20;
7342 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7344 if (setup.network_mode == network.enabled)
7347 network.enabled = setup.network_mode;
7349 FadeOut(REDRAW_ALL);
7353 DrawTextSCentered(ystart, font_title, text);
7357 if (network.enabled)
7358 InitNetworkServer();
7360 DisconnectFromNetworkServer();
7362 DrawTextSCentered(ybottom, font_foot,
7363 "Press any key or button for setup menu");
7365 WaitForEventToContinue();
7370 static void ToggleGameSpeedsListIfNeeded(void)
7372 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7374 if (setup.game_speed_extended == using_game_speeds_extended)
7377 // try to match similar values when changing game speeds list
7378 if (setup.game_speed_extended)
7379 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7380 setup.game_frame_delay == 30 ? 29 :
7381 setup.game_frame_delay);
7383 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7384 setup.game_frame_delay == 16 ? 15 :
7385 setup.game_frame_delay >= 29 ? 30 :
7386 setup.game_frame_delay <= 10 ? 10 :
7387 setup.game_frame_delay);
7389 execSetupGame_setGameSpeeds(TRUE);
7394 static void ToggleUseApiServerIfNeeded(void)
7396 if (runtime.use_api_server == setup.use_api_server)
7399 runtime.use_api_server = setup.use_api_server;
7401 if (runtime.use_api_server)
7402 CheckApiServerTasks();
7405 static void ModifyGameSpeedIfNeeded(void)
7407 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7408 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7412 char *game_speed_text = "Fast";
7413 int game_speed_value = 15;
7415 if (setup.game_speed_extended)
7417 game_speed_text = "60 fps";
7418 game_speed_value = 16;
7421 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7423 // set game speed to existing list value that is fast enough for vsync
7424 setup.game_frame_delay = game_speed_value;
7426 execSetupGame_setGameSpeeds(TRUE);
7428 Request(message, REQ_CONFIRM);
7431 static void DisableVsyncIfNeeded(void)
7433 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7434 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7435 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7438 // disable vsync for the selected game speed to work
7439 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7441 execSetupGraphics_setVsyncModes(TRUE);
7443 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7449 void *related_value;
7450 } hide_related_entry_list[] =
7452 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7453 { &setup.scores_in_highscore_list, &scores_type_text },
7455 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7456 { &setup.game_frame_delay, &game_speed_text },
7458 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7459 { &setup.scroll_delay_value, &scroll_delay_text },
7461 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7462 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7464 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7465 { &setup.window_scaling_percent, &window_size_text },
7467 { &setup.window_scaling_quality, execSetupChooseScalingType },
7468 { &setup.window_scaling_quality, &scaling_type_text },
7470 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7471 { &setup.screen_rendering_mode, &rendering_mode_text },
7473 { &setup.vsync_mode, execSetupChooseVsyncMode },
7474 { &setup.vsync_mode, &vsync_mode_text },
7476 { &setup.graphics_set, execSetupChooseGraphics },
7477 { &setup.graphics_set, &graphics_set_name },
7479 { &setup.sounds_set, execSetupChooseSounds },
7480 { &setup.sounds_set, &sounds_set_name },
7482 { &setup.music_set, execSetupChooseMusic },
7483 { &setup.music_set, &music_set_name },
7485 { &setup.volume_simple, execSetupChooseVolumeSimple },
7486 { &setup.volume_simple, &volume_simple_text },
7488 { &setup.volume_loops, execSetupChooseVolumeLoops },
7489 { &setup.volume_loops, &volume_loops_text },
7491 { &setup.volume_music, execSetupChooseVolumeMusic },
7492 { &setup.volume_music, &volume_music_text },
7494 { &setup.touch.control_type, execSetupChooseTouchControls },
7495 { &setup.touch.control_type, &touch_controls_text },
7497 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7498 { &setup.touch.move_distance, &move_distance_text },
7500 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7501 { &setup.touch.drop_distance, &drop_distance_text },
7503 { &setup.touch.transparency, execSetupChooseTransparency },
7504 { &setup.touch.transparency, &transparency_text },
7506 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7507 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7509 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7510 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7512 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7513 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7515 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7516 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7518 { &setup.internal.menu_game, execSetupGame },
7519 { &setup.internal.menu_engines, execSetupEngines },
7520 { &setup.internal.menu_editor, execSetupEditor },
7521 { &setup.internal.menu_graphics, execSetupGraphics },
7522 { &setup.internal.menu_sound, execSetupSound },
7523 { &setup.internal.menu_artwork, execSetupArtwork },
7524 { &setup.internal.menu_input, execSetupInput },
7525 { &setup.internal.menu_touch, execSetupTouch },
7526 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7527 { &setup.internal.menu_exit, execExitSetup },
7528 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7533 void setHideRelatedSetupEntries(void)
7537 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7538 if (hideSetupEntry(hide_related_entry_list[i].value))
7539 setHideSetupEntry(hide_related_entry_list[i].related_value);
7542 static struct TokenInfo setup_info_main[] =
7544 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7545 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7546 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7547 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7548 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7549 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7550 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7551 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7552 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7553 { TYPE_EMPTY, NULL, "" },
7554 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7555 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7560 static struct TokenInfo setup_info_game[] =
7562 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7563 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7564 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7565 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7566 { TYPE_STRING, &network_server_text, "" },
7567 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7568 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7569 { TYPE_STRING, &scores_type_text, "" },
7570 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7571 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7572 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7573 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7574 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7575 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7576 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7577 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7578 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7579 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7580 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7581 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7582 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7583 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7584 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7585 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7586 { TYPE_STRING, &game_speed_text, "" },
7587 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7589 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7590 { TYPE_STRING, &scroll_delay_text, "" },
7592 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7593 { TYPE_STRING, &snapshot_mode_text, "" },
7594 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7595 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7596 { TYPE_EMPTY, NULL, "" },
7597 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7602 static struct TokenInfo setup_info_engines[] =
7604 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7605 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7606 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7607 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7608 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7609 { TYPE_EMPTY, NULL, "" },
7610 { TYPE_HEADLINE, NULL, "Supaplex" },
7611 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7612 { TYPE_EMPTY, NULL, "" },
7613 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7618 static struct TokenInfo setup_info_editor[] =
7621 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7622 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7623 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7624 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7625 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7626 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7627 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7628 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7629 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7630 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7632 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7633 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7635 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7637 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7638 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7639 { TYPE_EMPTY, NULL, "" },
7641 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7642 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7643 { TYPE_EMPTY, NULL, "" },
7645 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7646 { TYPE_EMPTY, NULL, "" },
7647 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7648 { TYPE_EMPTY, NULL, "" },
7649 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7654 static struct TokenInfo setup_info_graphics[] =
7656 #if !defined(PLATFORM_ANDROID)
7657 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7658 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7659 { TYPE_STRING, &window_size_text, "" },
7660 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7661 { TYPE_STRING, &scaling_type_text, "" },
7662 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7663 { TYPE_STRING, &rendering_mode_text, "" },
7666 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7667 { TYPE_STRING, &scroll_delay_text, "" },
7669 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7670 { TYPE_STRING, &vsync_mode_text, "" },
7671 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7672 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7673 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7674 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7675 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7676 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7677 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7678 { TYPE_EMPTY, NULL, "" },
7679 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7684 static struct TokenInfo setup_info_sound[] =
7686 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7687 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7688 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7689 { TYPE_EMPTY, NULL, "" },
7690 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7691 { TYPE_STRING, &volume_simple_text, "" },
7692 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7693 { TYPE_STRING, &volume_loops_text, "" },
7694 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7695 { TYPE_STRING, &volume_music_text, "" },
7696 { TYPE_EMPTY, NULL, "" },
7697 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7702 static struct TokenInfo setup_info_artwork[] =
7704 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7705 { TYPE_STRING, &graphics_set_name, "" },
7706 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7707 { TYPE_STRING, &sounds_set_name, "" },
7708 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7709 { TYPE_STRING, &music_set_name, "" },
7710 { TYPE_EMPTY, NULL, "" },
7711 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7712 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7713 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7714 { TYPE_EMPTY, NULL, "" },
7715 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7720 static struct TokenInfo setup_info_input[] =
7722 { TYPE_SWITCH, NULL, "Player:" },
7723 { TYPE_SWITCH, NULL, "Device:" },
7724 { TYPE_SWITCH, NULL, "" },
7725 { TYPE_SKIPPABLE, NULL, "" },
7726 { TYPE_EMPTY, NULL, "" },
7727 { TYPE_EMPTY, NULL, "" },
7728 { TYPE_EMPTY, NULL, "" },
7729 { TYPE_EMPTY, NULL, "" },
7730 { TYPE_EMPTY, NULL, "" },
7731 { TYPE_EMPTY, NULL, "" },
7732 { TYPE_EMPTY, NULL, "" },
7733 { TYPE_EMPTY, NULL, "" },
7734 { TYPE_SKIPPABLE, NULL, "" },
7735 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7740 static struct TokenInfo setup_info_touch[] =
7742 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7743 { TYPE_STRING, &touch_controls_text, "" },
7744 { TYPE_EMPTY, NULL, "" },
7745 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7750 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7752 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7753 { TYPE_STRING, &touch_controls_text, "" },
7754 { TYPE_EMPTY, NULL, "" },
7755 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7756 { TYPE_STRING, &grid_size_text[0][0], "" },
7757 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7758 { TYPE_STRING, &grid_size_text[0][1], "" },
7759 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7760 { TYPE_STRING, &transparency_text, "" },
7761 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7762 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7763 { TYPE_EMPTY, NULL, "" },
7764 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7765 { TYPE_EMPTY, NULL, "" },
7766 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7771 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7773 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7774 { TYPE_STRING, &touch_controls_text, "" },
7775 { TYPE_EMPTY, NULL, "" },
7776 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7777 { TYPE_STRING, &grid_size_text[1][0], "" },
7778 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7779 { TYPE_STRING, &grid_size_text[1][1], "" },
7780 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7781 { TYPE_STRING, &transparency_text, "" },
7782 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7783 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7784 { TYPE_EMPTY, NULL, "" },
7785 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7786 { TYPE_EMPTY, NULL, "" },
7787 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7792 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7794 setup_info_touch_virtual_buttons_0,
7795 setup_info_touch_virtual_buttons_1
7798 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7800 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7801 { TYPE_STRING, &touch_controls_text, "" },
7802 { TYPE_EMPTY, NULL, "" },
7803 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7804 { TYPE_STRING, &move_distance_text, "" },
7805 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7806 { TYPE_STRING, &drop_distance_text, "" },
7807 { TYPE_EMPTY, NULL, "" },
7808 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7813 static struct TokenInfo setup_info_shortcuts[] =
7815 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7816 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7817 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7818 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7819 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7820 { TYPE_EMPTY, NULL, "" },
7821 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7826 static struct TokenInfo setup_info_shortcuts_1[] =
7828 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7829 { TYPE_KEY, &setup.shortcut.save_game, "" },
7830 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7831 { TYPE_KEY, &setup.shortcut.load_game, "" },
7832 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7833 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7834 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7835 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7836 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7837 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7838 { TYPE_EMPTY, NULL, "" },
7839 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7840 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7841 { TYPE_EMPTY, NULL, "" },
7842 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7847 static struct TokenInfo setup_info_shortcuts_2[] =
7849 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7850 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7851 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7852 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7853 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7854 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7855 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7856 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7857 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7858 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7859 { TYPE_EMPTY, NULL, "" },
7860 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7865 static struct TokenInfo setup_info_shortcuts_3[] =
7867 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7868 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7869 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7870 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7871 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7872 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7873 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7874 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7875 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7876 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7877 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7878 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7879 { TYPE_EMPTY, NULL, "" },
7880 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7885 static struct TokenInfo setup_info_shortcuts_4[] =
7887 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7888 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7889 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7890 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7891 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7892 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7893 { TYPE_EMPTY, NULL, "" },
7894 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7899 static struct TokenInfo setup_info_shortcuts_5[] =
7901 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7902 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7903 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7904 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7905 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7906 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7907 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7908 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7909 { TYPE_EMPTY, NULL, "" },
7910 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7915 static Key getSetupKey(void)
7917 Key key = KSYM_UNDEFINED;
7918 boolean got_key_event = FALSE;
7920 while (!got_key_event)
7924 if (NextValidEvent(&event))
7928 case EVENT_KEYPRESS:
7930 key = GetEventKey((KeyEvent *)&event, TRUE);
7932 // press 'Escape' or 'Enter' to keep the existing key binding
7933 if (key == KSYM_Escape || key == KSYM_Return)
7934 key = KSYM_UNDEFINED; // keep old value
7936 got_key_event = TRUE;
7940 case EVENT_KEYRELEASE:
7941 key_joystick_mapping = 0;
7945 HandleOtherEvents(&event);
7956 static int getSetupValueFont(int type, void *value)
7958 if (type & TYPE_GHOSTED)
7959 return FONT_OPTION_OFF;
7960 else if (type & TYPE_KEY)
7961 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7962 else if (type & TYPE_STRING)
7963 return FONT_VALUE_2;
7964 else if (type & TYPE_ECS_AGA)
7965 return FONT_VALUE_1;
7966 else if (type & TYPE_BOOLEAN_STYLE)
7967 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7968 else if (type & TYPE_YES_NO_AUTO)
7969 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7970 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7971 else if (type & TYPE_PLAYER)
7972 return FONT_VALUE_1;
7974 return FONT_VALUE_1;
7977 static int getSetupValueFontNarrow(int type, int font_nr)
7979 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7980 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7981 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7985 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7987 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7988 struct TokenInfo *si = &setup_info[si_pos];
7989 boolean font_draw_xoffset_modified = FALSE;
7990 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7991 int font_draw_xoffset_old = -1;
7992 int xoffset = (scrollbar_needed ? -1 : 0);
7993 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7994 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7995 int xpos = menu_screen_value_xpos;
7996 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7997 int startx = mSX + xpos * 32;
7998 int starty = mSY + ypos * 32;
7999 int type = si->type;
8000 void *value = si->value;
8001 char *value_string = getSetupValue(type, value);
8002 int font_nr_default = getSetupValueFont(type, value);
8003 int font_width_default = getFontWidth(font_nr_default);
8004 int font_nr = font_nr_default;
8007 if (value_string == NULL)
8010 if (type & TYPE_KEY)
8012 xpos = MENU_SCREEN_START_XPOS;
8014 if (type & TYPE_QUERY)
8015 value_string = "<press key>";
8017 else if (type & TYPE_STRING)
8019 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
8021 xpos = MENU_SCREEN_START_XPOS;
8023 if (strlen(value_string) > max_value_len)
8024 value_string[max_value_len] = '\0';
8026 else if (type & TYPE_YES_NO_AUTO)
8028 xpos = menu_screen_value_xpos - 1;
8030 else if (type & TYPE_PLAYER)
8032 int displayed_player_nr = *(int *)value + 1;
8034 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
8037 startx = mSX + xpos * 32;
8038 starty = mSY + ypos * 32;
8040 // special check if right-side setup values moved left due to scrollbar
8041 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
8043 int max_menu_text_length = 26; // maximum text length for classic menu
8044 int font_xoffset = getFontDrawOffsetX(font_nr);
8045 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8046 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8047 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8048 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
8050 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
8052 // when using narrow font, left-shifting text "auto" not needed
8053 if (type & TYPE_YES_NO_AUTO)
8057 startx = mSX + xpos * 32;
8059 font_nr = getSetupValueFontNarrow(type, font_nr);
8063 // downward compatibility correction for Juergen Bonhagen's menu settings
8064 if (setup_mode != SETUP_MODE_INPUT)
8066 int max_menu_text_length_big = (menu_screen_value_xpos -
8067 MENU_SCREEN_START_XPOS);
8068 int max_menu_text_length_medium = max_menu_text_length_big * 2;
8069 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
8070 int font1_xoffset = getFontDrawOffsetX(font_nr);
8071 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
8072 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8073 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8074 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8075 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8076 boolean correct_font_draw_xoffset = FALSE;
8078 if (xpos == MENU_SCREEN_START_XPOS &&
8079 startx + font1_xoffset < text_startx + text_font_xoffset)
8080 correct_font_draw_xoffset = TRUE;
8082 if (xpos == menu_screen_value_xpos &&
8083 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8084 correct_font_draw_xoffset = TRUE;
8086 // check if setup value would overlap with setup text when printed
8087 // (this can happen for extreme/wrong values for font draw offset)
8088 if (correct_font_draw_xoffset)
8090 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8091 font_draw_xoffset_modified = TRUE;
8093 if (type & TYPE_KEY)
8094 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8095 else if (!(type & TYPE_STRING))
8096 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8097 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8101 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
8102 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
8104 DrawText(startx, starty, value_string, font_nr);
8106 if (type & TYPE_PLAYER)
8108 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8109 int player_nr = *(int *)value;
8110 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8111 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8112 int startx2 = startx + xoff;
8113 int starty2 = starty + yoff;
8115 if (DrawingOnBackground(startx2, starty2))
8116 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8118 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8119 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8122 if (font_draw_xoffset_modified)
8123 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8126 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8128 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8129 struct TokenInfo *si = &setup_info[si_pos];
8131 if (si->type & TYPE_BOOLEAN_STYLE)
8133 *(boolean *)si->value ^= TRUE;
8135 else if (si->type & TYPE_YES_NO_AUTO)
8139 (*(int *)si->value == AUTO ? TRUE :
8140 *(int *)si->value == TRUE ? FALSE : AUTO) :
8141 (*(int *)si->value == TRUE ? AUTO :
8142 *(int *)si->value == AUTO ? FALSE : TRUE));
8144 else if (si->type & TYPE_KEY)
8148 si->type |= TYPE_QUERY;
8149 drawSetupValue(screen_pos, setup_info_pos_raw);
8150 si->type &= ~TYPE_QUERY;
8152 key = getSetupKey();
8153 if (key != KSYM_UNDEFINED)
8154 *(Key *)si->value = key;
8156 else if (si->type & TYPE_PLAYER)
8158 int player_nr = *(int *)si->value;
8163 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8165 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8168 drawSetupValue(screen_pos, setup_info_pos_raw);
8170 // fullscreen state may have changed at this point
8171 if (si->value == &setup.fullscreen)
8172 ToggleFullscreenIfNeeded();
8174 // network mode may have changed at this point
8175 if (si->value == &setup.network_mode)
8176 ToggleNetworkModeIfNeeded();
8178 // API server mode may have changed at this point
8179 if (si->value == &setup.use_api_server)
8180 ToggleUseApiServerIfNeeded();
8182 // game speed list may have changed at this point
8183 if (si->value == &setup.game_speed_extended)
8184 ToggleGameSpeedsListIfNeeded();
8187 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8189 static struct TokenInfo *setup_info_final = NULL;
8194 // determine maximum list size of target list
8195 while (setup_info_orig[list_size++].type != 0);
8197 // free, allocate and clear memory for target list
8198 checked_free(setup_info_final);
8199 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8201 // copy setup info list without setup entries marked as hidden
8202 for (i = 0; setup_info_orig[i].type != 0; i++)
8204 // skip setup entries configured to be hidden
8205 if (hideSetupEntry(setup_info_orig[i].value))
8208 // skip skippable setup entries if screen is lower than usual
8209 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8210 setup_info_orig[i].type == TYPE_SKIPPABLE)
8213 setup_info_final[list_pos++] = setup_info_orig[i];
8216 return setup_info_final;
8219 static void DrawSetupScreen_Generic(void)
8221 int fade_mask = REDRAW_FIELD;
8222 boolean redraw_all = FALSE;
8223 char *title_string = NULL;
8227 fade_mask = REDRAW_ALL;
8230 FadeMenuSoundsAndMusic();
8232 FreeScreenGadgets();
8233 CreateScreenGadgets();
8235 if (redraw_mask & REDRAW_ALL)
8240 // needed if different viewport properties defined for setup screen
8241 ChangeViewportPropertiesIfNeeded();
8243 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8247 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8249 if (setup_mode == SETUP_MODE_MAIN)
8251 setup_info = setup_info_main;
8252 title_string = STR_SETUP_MAIN;
8254 else if (setup_mode == SETUP_MODE_GAME)
8256 setup_info = setup_info_game;
8257 title_string = STR_SETUP_GAME;
8259 else if (setup_mode == SETUP_MODE_ENGINES)
8261 setup_info = setup_info_engines;
8262 title_string = STR_SETUP_ENGINES;
8264 else if (setup_mode == SETUP_MODE_EDITOR)
8266 setup_info = setup_info_editor;
8267 title_string = STR_SETUP_EDITOR;
8269 else if (setup_mode == SETUP_MODE_GRAPHICS)
8271 setup_info = setup_info_graphics;
8272 title_string = STR_SETUP_GRAPHICS;
8274 else if (setup_mode == SETUP_MODE_SOUND)
8276 setup_info = setup_info_sound;
8277 title_string = STR_SETUP_SOUND;
8279 else if (setup_mode == SETUP_MODE_ARTWORK)
8281 setup_info = setup_info_artwork;
8282 title_string = STR_SETUP_ARTWORK;
8284 else if (setup_mode == SETUP_MODE_TOUCH)
8286 setup_info = setup_info_touch;
8287 title_string = STR_SETUP_TOUCH;
8289 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8290 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8291 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8292 setup_info = setup_info_touch_wipe_gestures;
8294 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8296 setup_info = setup_info_shortcuts;
8297 title_string = STR_SETUP_SHORTCUTS;
8299 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8301 setup_info = setup_info_shortcuts_1;
8302 title_string = STR_SETUP_SHORTCUTS;
8304 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8306 setup_info = setup_info_shortcuts_2;
8307 title_string = STR_SETUP_SHORTCUTS;
8309 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8311 setup_info = setup_info_shortcuts_3;
8312 title_string = STR_SETUP_SHORTCUTS;
8314 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8316 setup_info = setup_info_shortcuts_4;
8317 title_string = STR_SETUP_SHORTCUTS;
8319 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8321 setup_info = setup_info_shortcuts_5;
8322 title_string = STR_SETUP_SHORTCUTS;
8325 // use modified setup info without setup entries marked as hidden
8326 setup_info = getSetupInfoFinal(setup_info);
8328 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8330 // determine maximal number of setup entries that can be displayed on screen
8332 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8335 // determine maximal number of setup entries available for this setup screen
8337 for (i = 0; setup_info[i].type != 0; i++)
8340 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8342 MapScreenGadgets(max_setup_info);
8345 redraw_mask = fade_mask = REDRAW_ALL;
8347 DrawMaskedBorder(fade_mask);
8352 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8354 menu_info = setup_info;
8356 HandleMenuScreen(mx, my, dx, dy, button,
8357 setup_mode, num_setup_info, max_setup_info);
8360 static void DrawSetupScreen_Input(void)
8364 FadeOut(REDRAW_FIELD);
8368 setup_info = getSetupInfoFinal(setup_info_input);
8370 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8372 for (i = 0; setup_info[i].type != 0; i++)
8374 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8375 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8376 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8377 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8378 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8379 initCursor(i, IMG_MENU_BUTTON);
8381 DrawCursorAndText_Setup(i, -1, FALSE);
8384 // create gadgets for setup input menu screen
8385 FreeScreenGadgets();
8386 CreateScreenGadgets();
8388 // map gadgets for setup input menu screen
8389 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8391 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8393 FadeIn(REDRAW_FIELD);
8396 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8398 if (device_name == NULL)
8401 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8404 if (strlen(device_name) > 1)
8406 char c1 = device_name[strlen(device_name) - 1];
8407 char c2 = device_name[strlen(device_name) - 2];
8409 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8410 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8413 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8414 strlen(device_name));
8417 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8420 static struct SetupKeyboardInfo custom_key;
8427 { &custom_key.left, "Axis/Pad Left" },
8428 { &custom_key.right, "Axis/Pad Right" },
8429 { &custom_key.up, "Axis/Pad Up" },
8430 { &custom_key.down, "Axis/Pad Down" },
8431 { &custom_key.snap, "Button 1/A/X" },
8432 { &custom_key.drop, "Button 2/B/Y" }
8434 static char *joystick_name[MAX_PLAYERS] =
8441 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8442 int font_nr_info = FONT_MENU_1;
8443 int font_nr_name = FONT_VALUE_OLD;
8444 int font_nr_on = FONT_VALUE_1;
8445 int font_nr_off = FONT_VALUE_OLD;
8448 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8450 font_nr_info = FONT_MENU_2;
8451 font_nr_on = FONT_VALUE_NARROW;
8452 font_nr_off = FONT_VALUE_OLD_NARROW;
8455 custom_key = setup.input[player_nr].key;
8457 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8458 FONT_INPUT_1_ACTIVE);
8460 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8462 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8463 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8465 if (setup.input[player_nr].use_joystick)
8467 char *device_name = setup.input[player_nr].joy.device_name;
8468 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8469 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8470 char *text = joystick_name[joystick_nr];
8471 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8473 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8474 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8478 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8479 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8482 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8483 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8487 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8488 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8489 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8490 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8492 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8493 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8494 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8495 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8496 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8497 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8499 for (i = 0; i < 6; i++)
8501 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8503 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8505 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8506 (setup.input[player_nr].use_joystick ?
8508 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8512 static int input_player_nr = 0;
8514 static void HandleSetupScreen_Input_Player(int step, int direction)
8516 int old_player_nr = input_player_nr;
8519 new_player_nr = old_player_nr + step * direction;
8520 if (new_player_nr < 0)
8522 if (new_player_nr > MAX_PLAYERS - 1)
8523 new_player_nr = MAX_PLAYERS - 1;
8525 if (new_player_nr != old_player_nr)
8527 input_player_nr = new_player_nr;
8529 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8533 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8535 static int choice = 0;
8538 int pos_start = SETUPINPUT_SCREEN_POS_START;
8539 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8540 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8541 int pos_end = SETUPINPUT_SCREEN_POS_END;
8543 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8547 for (i = 0; setup_info_input[i].type != 0; i++)
8549 // adjust menu structure according to skipped setup entries
8550 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8558 if (button == MB_MENU_INITIALIZE)
8560 // input setup menu may have changed size due to graphics configuration
8561 if (choice >= pos_empty1)
8564 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8566 DrawCursorAndText_Setup(choice, -1, TRUE);
8570 else if (button == MB_MENU_LEAVE)
8572 setup_mode = SETUP_MODE_MAIN;
8579 if (mx || my) // mouse input
8581 x = (mx - mSX) / 32;
8582 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8584 else if (dx || dy) // keyboard input
8586 if (dx && choice == 0)
8587 x = (dx < 0 ? 10 : 12);
8588 else if ((dx && choice == 1) ||
8589 (dx == -1 && choice == pos_end))
8590 button = MB_MENU_CHOICE;
8594 if (y >= pos_empty1 && y <= pos_empty2)
8595 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8598 if (y == 0 && dx != 0 && button)
8600 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8602 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8603 y >= pos_start && y <= pos_end &&
8604 !(y >= pos_empty1 && y <= pos_empty2))
8610 DrawCursorAndText_Setup(choice, -1, FALSE);
8611 DrawCursorAndText_Setup(y, -1, TRUE);
8613 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8622 char *device_name = setup.input[input_player_nr].joy.device_name;
8624 if (!setup.input[input_player_nr].use_joystick)
8626 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8628 setJoystickDeviceToNr(device_name, new_device_nr);
8629 setup.input[input_player_nr].use_joystick = TRUE;
8633 int device_nr = getJoystickNrFromDeviceName(device_name);
8634 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8636 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8637 setup.input[input_player_nr].use_joystick = FALSE;
8639 setJoystickDeviceToNr(device_name, new_device_nr);
8642 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8646 if (setup.input[input_player_nr].use_joystick)
8647 ConfigureJoystick(input_player_nr);
8649 CustomizeKeyboard(input_player_nr);
8651 else if (y == pos_end)
8657 setup_mode = SETUP_MODE_MAIN;
8664 static boolean CustomizeKeyboardMain(int player_nr)
8668 boolean finished = FALSE;
8669 static struct SetupKeyboardInfo custom_key;
8674 } customize_step[] =
8676 { &custom_key.left, "Move Left" },
8677 { &custom_key.right, "Move Right" },
8678 { &custom_key.up, "Move Up" },
8679 { &custom_key.down, "Move Down" },
8680 { &custom_key.snap, "Snap Field" },
8681 { &custom_key.drop, "Drop Element" }
8683 int font_nr_old = FONT_VALUE_OLD;
8684 int font_nr_new = FONT_VALUE_1;
8685 boolean success = FALSE;
8687 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8689 font_nr_old = FONT_VALUE_OLD_NARROW;
8690 font_nr_new = FONT_VALUE_NARROW;
8693 // read existing key bindings from player setup
8694 custom_key = setup.input[player_nr].key;
8697 FadeOut(REDRAW_FIELD);
8701 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8704 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8705 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8706 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8707 "Key:", FONT_INPUT_1_ACTIVE);
8708 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8709 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8711 FadeIn(REDRAW_FIELD);
8717 if (NextValidEvent(&event))
8721 case EVENT_KEYPRESS:
8723 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8725 // press 'Escape' to abort and keep the old key bindings
8726 if (key == KSYM_Escape)
8728 FadeSkipNextFadeIn();
8735 // press 'Enter' to keep the existing key binding
8736 if (key == KSYM_Return)
8737 key = *customize_step[step_nr].key;
8739 // check if key already used
8740 for (i = 0; i < step_nr; i++)
8741 if (*customize_step[i].key == key)
8746 // got new key binding
8747 *customize_step[step_nr].key = key;
8748 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8750 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8751 getKeyNameFromKey(key), font_nr_new);
8754 // un-highlight last query
8755 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8756 customize_step[step_nr - 1].text, FONT_MENU_1);
8757 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8758 "Key:", FONT_MENU_1);
8760 // all keys configured
8769 // query next key binding
8770 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8771 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8772 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8773 "Key:", FONT_INPUT_1_ACTIVE);
8774 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8775 getKeyNameFromKey(*customize_step[step_nr].key),
8780 case EVENT_KEYRELEASE:
8781 key_joystick_mapping = 0;
8785 HandleOtherEvents(&event);
8793 // write new key bindings back to player setup, if successfully finished
8795 setup.input[player_nr].key = custom_key;
8800 void CustomizeKeyboard(int player_nr)
8802 boolean success = CustomizeKeyboardMain(player_nr);
8806 int font_nr = FONT_TITLE_1;
8807 int font_height = getFontHeight(font_nr);
8808 int ypos1 = SYSIZE / 2 - font_height * 2;
8809 int ypos2 = SYSIZE / 2 - font_height * 1;
8810 unsigned int wait_frame_delay = 0;
8811 unsigned int wait_frame_delay_value = 2000;
8813 ResetDelayCounter(&wait_frame_delay);
8817 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8818 DrawTextSCentered(ypos2, font_nr, "configured!");
8820 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8826 DrawSetupScreen_Input();
8829 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8831 #define MARKER_BUTTON 1
8832 #define MARKER_AXIS_X 2
8833 #define MARKER_AXIS_Y 3
8835 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8837 static boolean bitmaps_initialized = FALSE;
8838 boolean screen_initialized = FALSE;
8839 static Bitmap *controller, *button, *axis_x, *axis_y;
8841 boolean success = TRUE;
8842 boolean done = FALSE, next = FALSE;
8844 int alpha = 200, alpha_step = -1;
8845 int alpha_ticks = 0;
8846 char mapping[4096], temp[256];
8847 int font_name = MENU_SETUP_FONT_TITLE;
8848 int font_info = MENU_SETUP_FONT_TEXT;
8849 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8850 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8851 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8852 int ystep_name = getMenuTextStep(spacing_name, font_name);
8853 int ystep_line = getMenuTextStep(spacing_line, font_info);
8854 int ystep_para = getMenuTextStep(spacing_para, font_info);
8862 int axis, button, hat, hat_value;
8865 *step, *prev_step, steps[] =
8867 { 356, 155, MARKER_BUTTON, "a", },
8868 { 396, 122, MARKER_BUTTON, "b", },
8869 { 320, 125, MARKER_BUTTON, "x", },
8870 { 358, 95, MARKER_BUTTON, "y", },
8871 { 162, 125, MARKER_BUTTON, "back", },
8872 { 216, 125, MARKER_BUTTON, "guide", },
8873 { 271, 125, MARKER_BUTTON, "start", },
8874 { 110, 200, MARKER_BUTTON, "dpleft", },
8875 { 146, 228, MARKER_BUTTON, "dpdown", },
8876 { 178, 200, MARKER_BUTTON, "dpright", },
8877 { 146, 172, MARKER_BUTTON, "dpup", },
8878 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8879 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8880 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8881 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8882 { 73, 141, MARKER_BUTTON, "leftstick", },
8883 { 282, 210, MARKER_BUTTON, "rightstick", },
8884 { 73, 141, MARKER_AXIS_X, "leftx", },
8885 { 73, 141, MARKER_AXIS_Y, "lefty", },
8886 { 282, 210, MARKER_AXIS_X, "rightx", },
8887 { 282, 210, MARKER_AXIS_Y, "righty", },
8890 unsigned int event_frame_delay = 0;
8891 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8893 ResetDelayCounter(&event_frame_delay);
8895 if (!bitmaps_initialized)
8897 controller = LoadCustomImage("joystick/controller.png");
8898 button = LoadCustomImage("joystick/button.png");
8899 axis_x = LoadCustomImage("joystick/axis_x.png");
8900 axis_y = LoadCustomImage("joystick/axis_y.png");
8902 bitmaps_initialized = TRUE;
8905 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8908 // print info about the joystick we are watching
8909 Debug("joystick", "watching joystick %d: (%s)",
8910 SDL_JoystickInstanceID(joystick), name);
8911 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8912 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8913 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8916 // initialize mapping with GUID and name
8917 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8919 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8920 temp, name, SDL_GetPlatform());
8922 // loop through all steps (buttons and axes), getting joystick events
8923 for (i = 0; i < SDL_arraysize(steps) && !done;)
8925 Bitmap *marker = button; // initialize with reliable default value
8928 strcpy(step->mapping, mapping);
8932 step->hat_value = -1;
8934 marker = (step->marker == MARKER_BUTTON ? button :
8935 step->marker == MARKER_AXIS_X ? axis_x :
8936 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8940 while (!done && !next)
8942 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8943 alpha_ticks = SDL_GetTicks();
8950 else if (alpha < 128)
8956 int controller_x = SX + (SXSIZE - controller->width) / 2;
8957 int controller_y = SY + ystep_line;
8959 int marker_x = controller_x + step->x;
8960 int marker_y = controller_y + step->y;
8962 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8963 int ystart2 = ystart1 + ystep_name + ystep_line;
8967 DrawTextSCentered(ystart1, font_name, name);
8969 DrawTextSCentered(ystart2, font_info,
8970 "Press buttons and move axes on");
8971 ystart2 += ystep_line;
8972 DrawTextSCentered(ystart2, font_info,
8973 "your controller when indicated.");
8974 ystart2 += ystep_line;
8975 DrawTextSCentered(ystart2, font_info,
8976 "(Your controller may look different.)");
8977 ystart2 += ystep_para;
8979 #if defined(PLATFORM_ANDROID)
8980 DrawTextSCentered(ystart2, font_info,
8981 "To correct a mistake,");
8982 ystart2 += ystep_line;
8983 DrawTextSCentered(ystart2, font_info,
8984 "press the 'back' button.");
8985 ystart2 += ystep_line;
8986 DrawTextSCentered(ystart2, font_info,
8987 "To skip a button or axis,");
8988 ystart2 += ystep_line;
8989 DrawTextSCentered(ystart2, font_info,
8990 "press the 'menu' button.");
8992 DrawTextSCentered(ystart2, font_info,
8993 "To correct a mistake,");
8994 ystart2 += ystep_line;
8995 DrawTextSCentered(ystart2, font_info,
8996 "press the 'backspace' key.");
8997 ystart2 += ystep_line;
8998 DrawTextSCentered(ystart2, font_info,
8999 "To skip a button or axis,");
9000 ystart2 += ystep_line;
9001 DrawTextSCentered(ystart2, font_info,
9002 "press the 'return' key.");
9003 ystart2 += ystep_line;
9004 DrawTextSCentered(ystart2, font_info,
9005 "To exit, press the 'escape' key.");
9008 BlitBitmapMasked(controller, drawto, 0, 0,
9009 controller->width, controller->height,
9010 controller_x, controller_y);
9012 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
9013 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
9015 BlitBitmapMasked(marker, drawto, 0, 0,
9016 marker->width, marker->height,
9017 marker_x, marker_y);
9019 if (!screen_initialized)
9020 FadeIn(REDRAW_FIELD);
9024 screen_initialized = TRUE;
9026 while (NextValidEvent(&event))
9030 case SDL_JOYAXISMOTION:
9031 if (event.jaxis.value > 20000 ||
9032 event.jaxis.value < -20000)
9034 for (j = 0; j < i; j++)
9035 if (steps[j].axis == event.jaxis.axis)
9040 if (step->marker != MARKER_AXIS_X &&
9041 step->marker != MARKER_AXIS_Y)
9044 step->axis = event.jaxis.axis;
9045 strcat(mapping, step->field);
9046 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
9047 strcat(mapping, temp);
9055 case SDL_JOYHATMOTION:
9056 // ignore centering; we're probably just coming back
9057 // to the center from the previous item we set
9058 if (event.jhat.value == SDL_HAT_CENTERED)
9061 for (j = 0; j < i; j++)
9062 if (steps[j].hat == event.jhat.hat &&
9063 steps[j].hat_value == event.jhat.value)
9068 step->hat = event.jhat.hat;
9069 step->hat_value = event.jhat.value;
9070 strcat(mapping, step->field);
9071 snprintf(temp, sizeof(temp), ":h%u.%u,",
9072 event.jhat.hat, event.jhat.value );
9073 strcat(mapping, temp);
9080 case SDL_JOYBALLMOTION:
9083 case SDL_JOYBUTTONUP:
9084 for (j = 0; j < i; j++)
9085 if (steps[j].button == event.jbutton.button)
9090 step->button = event.jbutton.button;
9091 strcat(mapping, step->field);
9092 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9093 strcat(mapping, temp);
9100 case SDL_FINGERDOWN:
9101 case SDL_MOUSEBUTTONDOWN:
9109 if (event.key.keysym.sym == KSYM_BackSpace ||
9110 event.key.keysym.sym == KSYM_Back)
9122 prev_step = &steps[i - 1];
9123 strcpy(mapping, prev_step->mapping);
9130 if (event.key.keysym.sym == KSYM_space ||
9131 event.key.keysym.sym == KSYM_Return ||
9132 event.key.keysym.sym == KSYM_Menu)
9141 if (event.key.keysym.sym == KSYM_Escape)
9151 program.exit_function(0);
9158 // do not handle events for longer than standard frame delay period
9159 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9168 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9171 // activate mapping for this game
9172 SDL_GameControllerAddMapping(mapping);
9174 // save mapping to personal mappings
9175 SaveSetup_AddGameControllerMapping(mapping);
9178 // wait until the last pending event was removed from event queue
9179 while (NextValidEvent(&event));
9184 static int ConfigureJoystickMain(int player_nr)
9186 char *device_name = setup.input[player_nr].joy.device_name;
9187 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9188 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9189 int success = FALSE;
9192 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9193 return JOYSTICK_NOT_AVAILABLE;
9195 if (!joystick_active || !setup.input[player_nr].use_joystick)
9196 return JOYSTICK_NOT_AVAILABLE;
9199 FadeOut(REDRAW_FIELD);
9201 // close all joystick devices (potentially opened as game controllers)
9202 for (i = 0; i < SDL_NumJoysticks(); i++)
9203 SDLCloseJoystick(i);
9205 // open joystick device as plain joystick to configure as game controller
9206 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9208 // as the joystick was successfully opened before, this should not happen
9209 if (joystick == NULL)
9212 // create new game controller mapping (buttons and axes) for joystick device
9213 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9215 // close joystick (and maybe re-open as configured game controller later)
9216 SDL_JoystickClose(joystick);
9218 // re-open all joystick devices (potentially as game controllers)
9219 for (i = 0; i < SDL_NumJoysticks(); i++)
9222 // clear all joystick input actions for all joystick devices
9223 SDLClearJoystickState();
9225 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9228 void ConfigureJoystick(int player_nr)
9230 boolean state = ConfigureJoystickMain(player_nr);
9232 if (state != JOYSTICK_NOT_CONFIGURED)
9234 boolean success = (state == JOYSTICK_CONFIGURED);
9235 char message1[MAX_OUTPUT_LINESIZE + 1];
9236 char *message2 = (success ? "configured!" : "not available!");
9237 char *device_name = setup.input[player_nr].joy.device_name;
9238 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9239 int font_nr = FONT_TITLE_1;
9240 int font_height = getFontHeight(font_nr);
9241 int ypos1 = SYSIZE / 2 - font_height * 2;
9242 int ypos2 = SYSIZE / 2 - font_height * 1;
9243 unsigned int wait_frame_delay = 0;
9244 unsigned int wait_frame_delay_value = 2000;
9246 ResetDelayCounter(&wait_frame_delay);
9250 sprintf(message1, "Joystick %d", nr);
9252 DrawTextSCentered(ypos1, font_nr, message1);
9253 DrawTextSCentered(ypos2, font_nr, message2);
9255 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9261 DrawSetupScreen_Input();
9264 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9266 if (y < video.screen_height / 3)
9268 // remap touch gadgets to access upper part of the screen
9269 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9270 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9272 else if (y > 2 * video.screen_height / 3)
9274 // remap touch gadgets to access lower part of the screen
9275 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9276 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9280 static boolean ConfigureVirtualButtonsMain(void)
9282 static char *customize_step_text[] =
9291 char grid_button[] =
9293 CHAR_GRID_BUTTON_LEFT,
9294 CHAR_GRID_BUTTON_RIGHT,
9295 CHAR_GRID_BUTTON_UP,
9296 CHAR_GRID_BUTTON_DOWN,
9297 CHAR_GRID_BUTTON_SNAP,
9298 CHAR_GRID_BUTTON_DROP
9307 int font_nr = FONT_INPUT_1_ACTIVE;
9308 int font_height = getFontHeight(font_nr);
9309 int ypos1 = SYSIZE / 2 - font_height * 2;
9310 int ypos2 = SYSIZE / 2 - font_height * 1;
9311 boolean success = FALSE;
9312 boolean finished = FALSE;
9314 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9315 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9316 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9317 boolean set_grid_button = FALSE;
9318 int nr = GRID_ACTIVE_NR();
9321 for (x = 0; x < MAX_GRID_XSIZE; x++)
9322 for (y = 0; y < MAX_GRID_YSIZE; y++)
9323 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9325 overlay.grid_button_highlight = grid_button[step_nr];
9330 FadeOut(REDRAW_FIELD);
9334 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9335 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9336 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9338 FadeIn(REDRAW_FIELD);
9340 SetOverlayShowGrid(TRUE);
9342 // map gadgets for setup touch buttons menu screen
9343 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9349 while (NextValidEvent(&event))
9351 int action = ACTION_NONE;
9353 // ---------- handle events and set the resulting action ----------
9359 UserEvent *user = (UserEvent *)&event;
9360 int id = user->value1;
9362 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9363 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9364 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9365 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9370 case EVENT_KEYPRESS:
9372 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9374 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9375 key == KSYM_BackSpace ||
9376 key == KSYM_Back ? ACTION_BACK :
9377 key == KSYM_Return ||
9379 key == KSYM_space ? ACTION_NEXT :
9384 case EVENT_KEYRELEASE:
9385 key_joystick_mapping = 0;
9388 case EVENT_BUTTONPRESS:
9389 case EVENT_BUTTONRELEASE:
9391 ButtonEvent *button = (ButtonEvent *)&event;
9393 motion_status = FALSE;
9395 if (button->type == EVENT_BUTTONPRESS)
9396 button_status = button->button;
9398 button_status = MB_RELEASED;
9400 if (HandleGadgets(button->x, button->y, button_status))
9402 // do not handle this button event anymore
9406 button->x += video.screen_xoffset;
9407 button->y += video.screen_yoffset;
9409 x = button->x * overlay.grid_xsize / video.screen_width;
9410 y = button->y * overlay.grid_ysize / video.screen_height;
9412 if (button->type == EVENT_BUTTONPRESS)
9415 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9416 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9418 set_grid_button = TRUE;
9421 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9425 case EVENT_MOTIONNOTIFY:
9427 MotionEvent *motion = (MotionEvent *)&event;
9429 motion_status = TRUE;
9431 if (HandleGadgets(motion->x, motion->y, button_status))
9433 // do not handle this button event anymore
9437 motion->x += video.screen_xoffset;
9438 motion->y += video.screen_yoffset;
9440 x = motion->x * overlay.grid_xsize / video.screen_width;
9441 y = motion->y * overlay.grid_ysize / video.screen_height;
9443 set_grid_button = TRUE;
9445 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9449 case SDL_WINDOWEVENT:
9450 HandleWindowEvent((WindowEvent *) &event);
9452 // check if device has been rotated
9453 if (nr != GRID_ACTIVE_NR())
9455 nr = GRID_ACTIVE_NR();
9457 for (x = 0; x < MAX_GRID_XSIZE; x++)
9458 for (y = 0; y < MAX_GRID_YSIZE; y++)
9459 grid_button_old[x][y] = grid_button_tmp[x][y] =
9460 overlay.grid_button[x][y];
9465 case SDL_APP_WILLENTERBACKGROUND:
9466 case SDL_APP_DIDENTERBACKGROUND:
9467 case SDL_APP_WILLENTERFOREGROUND:
9468 case SDL_APP_DIDENTERFOREGROUND:
9469 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9473 HandleOtherEvents(&event);
9477 // ---------- perform action set by handling events ----------
9479 if (action == ACTION_ESCAPE)
9481 // abort and restore the old key bindings
9483 for (x = 0; x < MAX_GRID_XSIZE; x++)
9484 for (y = 0; y < MAX_GRID_YSIZE; y++)
9485 overlay.grid_button[x][y] = grid_button_old[x][y];
9487 FadeSkipNextFadeIn();
9491 else if (action == ACTION_BACK)
9493 // keep the configured key bindings and go to previous page
9499 FadeSkipNextFadeIn();
9504 else if (action == ACTION_NEXT)
9506 // keep the configured key bindings and go to next page
9510 // all virtual buttons configured
9518 if (action != ACTION_NONE && !finished)
9520 for (x = 0; x < MAX_GRID_XSIZE; x++)
9521 for (y = 0; y < MAX_GRID_YSIZE; y++)
9522 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9524 overlay.grid_button_highlight = grid_button[step_nr];
9526 // configure next virtual button
9530 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9531 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9532 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9535 if (set_grid_button)
9537 overlay.grid_button[x][y] =
9538 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9539 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9540 grid_button_tmp[x][y]);
9542 set_grid_button = FALSE;
9549 for (x = 0; x < MAX_GRID_XSIZE; x++)
9550 for (y = 0; y < MAX_GRID_YSIZE; y++)
9551 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9553 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9555 SetOverlayShowGrid(FALSE);
9560 void ConfigureVirtualButtons(void)
9562 boolean success = ConfigureVirtualButtonsMain();
9564 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9565 SCREEN_MASK_TOUCH2);
9569 int font_nr = FONT_TITLE_1;
9570 int font_height = getFontHeight(font_nr);
9571 int ypos1 = SYSIZE / 2 - font_height * 2;
9572 int ypos2 = SYSIZE / 2 - font_height * 1;
9573 unsigned int wait_frame_delay = 0;
9574 unsigned int wait_frame_delay_value = 2000;
9576 ResetDelayCounter(&wait_frame_delay);
9580 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9581 DrawTextSCentered(ypos2, font_nr, "configured!");
9583 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9590 void DrawSetupScreen(void)
9595 if (setup_mode == SETUP_MODE_INPUT)
9596 DrawSetupScreen_Input();
9597 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9598 DrawChooseTree(&scores_type_current);
9599 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9600 DrawChooseTree(&game_speed_current);
9601 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9602 DrawChooseTree(&scroll_delay_current);
9603 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9604 DrawChooseTree(&snapshot_mode_current);
9605 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9606 DrawChooseTree(&window_size_current);
9607 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9608 DrawChooseTree(&scaling_type_current);
9609 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9610 DrawChooseTree(&rendering_mode_current);
9611 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9612 DrawChooseTree(&vsync_mode_current);
9613 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9614 DrawChooseTree(&artwork.gfx_current);
9615 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9616 DrawChooseTree(&artwork.snd_current);
9617 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9618 DrawChooseTree(&artwork.mus_current);
9619 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9620 DrawChooseTree(&volume_simple_current);
9621 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9622 DrawChooseTree(&volume_loops_current);
9623 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9624 DrawChooseTree(&volume_music_current);
9625 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9626 DrawChooseTree(&touch_control_current);
9627 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9628 DrawChooseTree(&move_distance_current);
9629 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9630 DrawChooseTree(&drop_distance_current);
9631 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9632 DrawChooseTree(&transparency_current);
9633 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9634 DrawChooseTree(&grid_size_current[0][0]);
9635 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9636 DrawChooseTree(&grid_size_current[0][1]);
9637 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9638 DrawChooseTree(&grid_size_current[1][0]);
9639 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9640 DrawChooseTree(&grid_size_current[1][1]);
9642 DrawSetupScreen_Generic();
9644 PlayMenuSoundsAndMusic();
9647 void RedrawSetupScreenAfterFullscreenToggle(void)
9649 if (setup_mode == SETUP_MODE_GRAPHICS ||
9650 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9652 // update list selection from "setup.window_scaling_percent"
9653 execSetupGraphics_setWindowSizes(TRUE);
9659 void RedrawSetupScreenAfterScreenRotation(int nr)
9663 if (setup_mode == SETUP_MODE_TOUCH)
9665 // update virtual button settings (depending on screen orientation)
9668 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9670 // save already configured virtual buttons
9671 for (x = 0; x < MAX_GRID_XSIZE; x++)
9672 for (y = 0; y < MAX_GRID_YSIZE; y++)
9673 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9677 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9679 if (setup_mode == SETUP_MODE_INPUT)
9680 HandleSetupScreen_Input(mx, my, dx, dy, button);
9681 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9682 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9683 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9684 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9685 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9686 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9687 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9688 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9689 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9690 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9691 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9692 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9693 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9694 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9695 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9696 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9697 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9698 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9699 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9700 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9701 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9702 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9703 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9704 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9705 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9706 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9707 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9708 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9709 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9710 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9711 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9712 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9713 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9714 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9715 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9716 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9717 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9718 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9719 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9720 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9721 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9722 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9723 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9724 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9726 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9729 void HandleGameActions(void)
9731 if (setup.ask_on_game_over)
9734 if (game.restart_game_message != NULL)
9736 RequestRestartGame(game.restart_game_message);
9741 if (game_status != GAME_MODE_PLAYING)
9744 GameActions(); // main game loop
9746 if (tape.auto_play && !tape.playing)
9747 AutoPlayTapesContinue(); // continue automatically playing next tape
9751 // ---------- new screen button stuff --------------------------------------
9755 int gfx_unpressed, gfx_pressed;
9756 struct MenuPosInfo *pos;
9757 boolean *check_value;
9760 unsigned int event_mask;
9761 boolean is_touch_button;
9763 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9766 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9767 &menu.main.button.prev_level, NULL,
9768 SCREEN_CTRL_ID_PREV_LEVEL,
9770 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9771 FALSE, "previous level"
9774 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9775 &menu.main.button.next_level, NULL,
9776 SCREEN_CTRL_ID_NEXT_LEVEL,
9778 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9782 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9783 &menu.scores.button.prev_level, NULL,
9784 SCREEN_CTRL_ID_PREV_LEVEL2,
9786 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9787 FALSE, "previous level"
9790 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9791 &menu.scores.button.next_level, NULL,
9792 SCREEN_CTRL_ID_NEXT_LEVEL2,
9794 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9798 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9799 &menu.main.button.first_level, NULL,
9800 SCREEN_CTRL_ID_FIRST_LEVEL,
9803 FALSE, "first level"
9806 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9807 &menu.main.button.last_level, NULL,
9808 SCREEN_CTRL_ID_LAST_LEVEL,
9814 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9815 &menu.main.button.level_number, NULL,
9816 SCREEN_CTRL_ID_LEVEL_NUMBER,
9819 FALSE, "level number"
9822 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9823 &menu.setup.button.prev_player, NULL,
9824 SCREEN_CTRL_ID_PREV_PLAYER,
9826 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9827 FALSE, "previous player"
9830 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9831 &menu.setup.button.next_player, NULL,
9832 SCREEN_CTRL_ID_NEXT_PLAYER,
9834 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9835 FALSE, "next player"
9838 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9839 &menu.main.button.insert_solution, NULL,
9840 SCREEN_CTRL_ID_INSERT_SOLUTION,
9841 SCREEN_MASK_MAIN_HAS_SOLUTION,
9843 FALSE, "insert solution tape"
9846 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9847 &menu.main.button.play_solution, NULL,
9848 SCREEN_CTRL_ID_PLAY_SOLUTION,
9849 SCREEN_MASK_MAIN_HAS_SOLUTION,
9851 FALSE, "play solution tape"
9854 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9855 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9856 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9858 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9859 FALSE, "switch ECS/AGA chipset"
9862 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9863 &menu.setup.button.touch_back, NULL,
9864 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9867 TRUE, "previous page"
9870 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9871 &menu.setup.button.touch_next, NULL,
9872 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9878 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9879 &menu.setup.button.touch_back2, NULL,
9880 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9883 TRUE, "previous page"
9886 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9887 &menu.setup.button.touch_next2, NULL,
9888 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9897 int gfx_unpressed, gfx_pressed;
9901 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9904 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9905 -1, -1, // these values are not constant, but can change at runtime
9906 SCREEN_CTRL_ID_SCROLL_UP,
9910 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9911 -1, -1, // these values are not constant, but can change at runtime
9912 SCREEN_CTRL_ID_SCROLL_DOWN,
9919 int gfx_unpressed, gfx_pressed;
9925 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9928 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9929 -1, -1, // these values are not constant, but can change at runtime
9930 -1, -1, // these values are not constant, but can change at runtime
9931 GD_TYPE_SCROLLBAR_VERTICAL,
9932 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9933 "scroll level series vertically"
9945 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9948 IMG_SETUP_INPUT_TEXT,
9949 SCREEN_CTRL_ID_NETWORK_SERVER,
9950 -1, -1, // these values are not constant, but can change at runtime
9951 MAX_SETUP_TEXT_INPUT_LEN,
9952 network_server_hostname,
9953 "Network Server Hostname / IP"
9957 static void CreateScreenMenubuttons(void)
9959 struct GadgetInfo *gi;
9960 unsigned int event_mask;
9963 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9965 struct MenuPosInfo *pos = menubutton_info[i].pos;
9966 int screen_mask = menubutton_info[i].screen_mask;
9967 boolean is_touch_button = menubutton_info[i].is_touch_button;
9968 boolean is_check_button = menubutton_info[i].check_value != NULL;
9969 boolean is_score_button = (screen_mask == SCREEN_MASK_SCORES);
9970 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9971 int gfx_unpressed, gfx_pressed;
9972 int x, y, width, height;
9973 int gd_x1, gd_x2, gd_y1, gd_y2;
9974 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9975 int id = menubutton_info[i].gadget_id;
9976 int type = GD_TYPE_NORMAL_BUTTON;
9977 boolean checked = FALSE;
9979 event_mask = menubutton_info[i].event_mask;
9981 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9982 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9984 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9985 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9987 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9988 gfx_pressed = menubutton_info[i].gfx_pressed;
9989 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9990 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9991 gd_x1 = graphic_info[gfx_unpressed].src_x;
9992 gd_y1 = graphic_info[gfx_unpressed].src_y;
9993 gd_x2 = graphic_info[gfx_pressed].src_x;
9994 gd_y2 = graphic_info[gfx_pressed].src_y;
10000 if (is_touch_button)
10002 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
10003 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
10006 if (is_check_button)
10008 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
10009 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
10010 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
10011 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
10013 type = GD_TYPE_CHECK_BUTTON;
10014 checked = *menubutton_info[i].check_value;
10017 if (is_score_button)
10019 // if x/y set to -1, dynamically place buttons next to title text
10020 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10023 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10024 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10025 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10026 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10029 y = mSY + MENU_TITLE1_YPOS;
10032 gi = CreateGadget(GDI_CUSTOM_ID, id,
10033 GDI_CUSTOM_TYPE_ID, i,
10034 GDI_IMAGE_ID, gfx_unpressed,
10035 GDI_INFO_TEXT, menubutton_info[i].infotext,
10039 GDI_HEIGHT, height,
10041 GDI_STATE, GD_BUTTON_UNPRESSED,
10042 GDI_CHECKED, checked,
10043 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10044 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10045 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
10046 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
10047 GDI_DIRECT_DRAW, FALSE,
10048 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10049 GDI_EVENT_MASK, event_mask,
10050 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10054 Fail("cannot create gadget");
10056 screen_gadget[id] = gi;
10060 static void CreateScreenScrollbuttons(void)
10062 struct GadgetInfo *gi;
10063 unsigned int event_mask;
10066 // these values are not constant, but can change at runtime
10067 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10068 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10069 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10070 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10072 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10074 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10075 int gfx_unpressed, gfx_pressed;
10076 int x, y, width, height;
10077 int gd_x1, gd_x2, gd_y1, gd_y2;
10078 int id = scrollbutton_info[i].gadget_id;
10080 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10082 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10083 y = mSY + scrollbutton_info[i].y;
10084 width = SC_SCROLLBUTTON_XSIZE;
10085 height = SC_SCROLLBUTTON_YSIZE;
10087 // correct scrollbar position if placed outside menu (playfield) area
10088 if (x > SX + SC_SCROLL_UP_XPOS)
10089 x = SX + SC_SCROLL_UP_XPOS;
10091 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10092 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10093 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10095 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10096 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10097 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10098 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10099 gd_x1 = graphic_info[gfx_unpressed].src_x;
10100 gd_y1 = graphic_info[gfx_unpressed].src_y;
10101 gd_x2 = graphic_info[gfx_pressed].src_x;
10102 gd_y2 = graphic_info[gfx_pressed].src_y;
10104 gi = CreateGadget(GDI_CUSTOM_ID, id,
10105 GDI_CUSTOM_TYPE_ID, i,
10106 GDI_IMAGE_ID, gfx_unpressed,
10107 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10111 GDI_HEIGHT, height,
10112 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10113 GDI_STATE, GD_BUTTON_UNPRESSED,
10114 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10115 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10116 GDI_DIRECT_DRAW, FALSE,
10117 GDI_EVENT_MASK, event_mask,
10118 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10122 Fail("cannot create gadget");
10124 screen_gadget[id] = gi;
10128 static void CreateScreenScrollbars(void)
10132 // these values are not constant, but can change at runtime
10133 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10134 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10135 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10136 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10138 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10140 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10141 int gfx_unpressed, gfx_pressed;
10142 int x, y, width, height;
10143 int gd_x1, gd_x2, gd_y1, gd_y2;
10144 struct GadgetInfo *gi;
10145 int items_max, items_visible, item_position;
10146 unsigned int event_mask;
10147 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10148 int id = scrollbar_info[i].gadget_id;
10150 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10152 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10153 y = mSY + scrollbar_info[i].y;
10154 width = scrollbar_info[i].width;
10155 height = scrollbar_info[i].height;
10157 // correct scrollbar position if placed outside menu (playfield) area
10158 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10159 x = SX + SC_SCROLL_VERTICAL_XPOS;
10161 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10162 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10164 items_max = num_page_entries;
10165 items_visible = num_page_entries;
10168 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10169 gfx_pressed = scrollbar_info[i].gfx_pressed;
10170 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10171 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10172 gd_x1 = graphic_info[gfx_unpressed].src_x;
10173 gd_y1 = graphic_info[gfx_unpressed].src_y;
10174 gd_x2 = graphic_info[gfx_pressed].src_x;
10175 gd_y2 = graphic_info[gfx_pressed].src_y;
10177 gi = CreateGadget(GDI_CUSTOM_ID, id,
10178 GDI_CUSTOM_TYPE_ID, i,
10179 GDI_IMAGE_ID, gfx_unpressed,
10180 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10184 GDI_HEIGHT, height,
10185 GDI_TYPE, scrollbar_info[i].type,
10186 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10187 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10188 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10189 GDI_WHEEL_AREA_X, SX,
10190 GDI_WHEEL_AREA_Y, SY,
10191 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10192 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10193 GDI_STATE, GD_BUTTON_UNPRESSED,
10194 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10195 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10196 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10197 GDI_DIRECT_DRAW, FALSE,
10198 GDI_EVENT_MASK, event_mask,
10199 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10203 Fail("cannot create gadget");
10205 screen_gadget[id] = gi;
10209 static void CreateScreenTextInputGadgets(void)
10213 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10215 int graphic = textinput_info[i].graphic;
10216 struct GraphicInfo *gd = &graphic_info[graphic];
10217 int gd_x1 = gd->src_x;
10218 int gd_y1 = gd->src_y;
10219 int gd_x2 = gd->src_x + gd->active_xoffset;
10220 int gd_y2 = gd->src_y + gd->active_yoffset;
10221 struct GadgetInfo *gi;
10222 unsigned int event_mask;
10223 int id = textinput_info[i].gadget_id;
10224 int x = textinput_info[i].x;
10225 int y = textinput_info[i].y;
10227 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10229 gi = CreateGadget(GDI_CUSTOM_ID, id,
10230 GDI_CUSTOM_TYPE_ID, i,
10231 GDI_INFO_TEXT, textinput_info[i].infotext,
10234 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10235 GDI_TEXT_VALUE, textinput_info[i].value,
10236 GDI_TEXT_SIZE, textinput_info[i].size,
10237 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10238 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10239 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10240 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10241 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10242 GDI_DESIGN_WIDTH, gd->width,
10243 GDI_EVENT_MASK, event_mask,
10244 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10245 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10249 Fail("cannot create gadget");
10251 screen_gadget[id] = gi;
10255 void CreateScreenGadgets(void)
10257 CreateScreenMenubuttons();
10259 CreateScreenScrollbuttons();
10260 CreateScreenScrollbars();
10262 CreateScreenTextInputGadgets();
10265 void FreeScreenGadgets(void)
10269 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10270 FreeGadget(screen_gadget[i]);
10273 static void RedrawScreenMenuGadgets(int screen_mask)
10277 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10278 if (screen_mask & menubutton_info[i].screen_mask)
10279 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10282 static void MapScreenMenuGadgets(int screen_mask)
10286 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10287 if (screen_mask & menubutton_info[i].screen_mask)
10288 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10291 static void UnmapScreenMenuGadgets(int screen_mask)
10295 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10297 if (screen_mask & menubutton_info[i].screen_mask)
10299 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10301 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10302 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10303 screen_gadget[menubutton_info[i].gadget_id]->y,
10304 screen_gadget[menubutton_info[i].gadget_id]->width,
10305 screen_gadget[menubutton_info[i].gadget_id]->height);
10310 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10313 MapScreenMenuGadgets(screen_mask);
10315 UnmapScreenMenuGadgets(screen_mask);
10318 static void MapScreenGadgets(int num_entries)
10322 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10325 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10326 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10328 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10329 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10332 static void UnmapScreenGadgets()
10336 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10337 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10339 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10340 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10343 static void MapScreenTreeGadgets(TreeInfo *ti)
10345 MapScreenGadgets(numTreeInfoInGroup(ti));
10348 static void UnmapScreenTreeGadgets(void)
10350 UnmapScreenGadgets();
10353 static void HandleScreenGadgets(struct GadgetInfo *gi)
10355 int id = gi->custom_id;
10356 int button = gi->event.button;
10357 int step = (button == MB_LEFTBUTTON ? 1 :
10358 button == MB_MIDDLEBUTTON ? 5 :
10359 button == MB_RIGHTBUTTON ? 10 : 1);
10363 case SCREEN_CTRL_ID_PREV_LEVEL:
10364 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10367 case SCREEN_CTRL_ID_NEXT_LEVEL:
10368 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10371 case SCREEN_CTRL_ID_PREV_LEVEL2:
10372 HandleHallOfFame_SelectLevel(step, -1);
10375 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10376 HandleHallOfFame_SelectLevel(step, +1);
10379 case SCREEN_CTRL_ID_FIRST_LEVEL:
10380 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10383 case SCREEN_CTRL_ID_LAST_LEVEL:
10384 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10387 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10388 CloseDoor(DOOR_CLOSE_2);
10389 SetGameStatus(GAME_MODE_LEVELNR);
10390 DrawChooseLevelNr();
10393 case SCREEN_CTRL_ID_PREV_PLAYER:
10394 HandleSetupScreen_Input_Player(step, -1);
10397 case SCREEN_CTRL_ID_NEXT_PLAYER:
10398 HandleSetupScreen_Input_Player(step, +1);
10401 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10402 InsertSolutionTape();
10405 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10406 PlaySolutionTape();
10409 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10410 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10414 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10415 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10416 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10417 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10418 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10421 case SCREEN_CTRL_ID_SCROLL_UP:
10422 if (game_status == GAME_MODE_NAMES)
10423 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10424 else if (game_status == GAME_MODE_LEVELS)
10425 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10426 else if (game_status == GAME_MODE_LEVELNR)
10427 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10428 else if (game_status == GAME_MODE_SETUP)
10429 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10430 else if (game_status == GAME_MODE_INFO)
10431 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10432 else if (game_status == GAME_MODE_SCORES)
10433 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10436 case SCREEN_CTRL_ID_SCROLL_DOWN:
10437 if (game_status == GAME_MODE_NAMES)
10438 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10439 else if (game_status == GAME_MODE_LEVELS)
10440 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10441 else if (game_status == GAME_MODE_LEVELNR)
10442 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10443 else if (game_status == GAME_MODE_SETUP)
10444 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10445 else if (game_status == GAME_MODE_INFO)
10446 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10447 else if (game_status == GAME_MODE_SCORES)
10448 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10451 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10452 if (game_status == GAME_MODE_NAMES)
10453 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10454 else if (game_status == GAME_MODE_LEVELS)
10455 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10456 else if (game_status == GAME_MODE_LEVELNR)
10457 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10458 else if (game_status == GAME_MODE_SETUP)
10459 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10460 else if (game_status == GAME_MODE_INFO)
10461 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10462 else if (game_status == GAME_MODE_SCORES)
10463 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10466 case SCREEN_CTRL_ID_NETWORK_SERVER:
10468 if (!strEqual(gi->textinput.value, ""))
10470 setString(&setup.network_server_hostname, gi->textinput.value);
10472 network.server_host = setup.network_server_hostname;
10476 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10478 network.server_host = NULL;
10481 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10482 network.server_host = NULL;
10484 execSetupGame_setNetworkServerText();
10496 void DumpScreenIdentifiers(void)
10500 Print("Active screen elements on current screen:\n");
10502 for (i = 0; main_controls[i].nr != -1; i++)
10504 struct MainControlInfo *mci = &main_controls[i];
10506 if (mci->button_graphic != -1)
10508 char *token = getTokenFromImageID(mci->button_graphic);
10510 Print("- '%s'\n", token);
10517 boolean DoScreenAction(int image_id)
10521 if (game_status != GAME_MODE_MAIN)
10524 for (i = 0; main_controls[i].nr != -1; i++)
10526 struct MainControlInfo *mci = &main_controls[i];
10527 struct MenuPosInfo *pos = mci->pos_button;
10529 if (mci->button_graphic == image_id)
10531 int x = mSX + pos->x;
10532 int y = mSY + pos->y;
10534 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10543 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10545 // get tree info node of newly added level or artwork set
10546 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10547 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10549 if (tree_node_new == NULL) // should not happen
10552 // if request dialog is active, do nothing
10553 if (game.request_active)
10556 if (game_status == GAME_MODE_MAIN &&
10557 tree_type == TREE_TYPE_LEVEL_DIR)
10559 // when adding new level set in main menu, select it as current level set
10561 // change current level set to newly added level set from zip file
10562 leveldir_current = tree_node_new;
10564 // change current level number to first level of newly added level set
10565 level_nr = leveldir_current->first_level;
10567 // redraw screen to reflect changed level set
10570 // save this level set and level number as last selected level set
10571 SaveLevelSetup_LastSeries();
10572 SaveLevelSetup_SeriesInfo();
10574 else if (game_status == GAME_MODE_LEVELS &&
10575 tree_type == TREE_TYPE_LEVEL_DIR)
10577 // when adding new level set in level set menu, set cursor and update screen
10579 leveldir_current = tree_node_new;
10581 DrawChooseTree(&leveldir_current);
10583 else if (game_status == GAME_MODE_SETUP)
10585 // when adding new artwork set in setup menu, set cursor and update screen
10587 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10588 tree_type == TREE_TYPE_GRAPHICS_DIR)
10590 artwork.gfx_current = tree_node_new;
10592 DrawChooseTree(&artwork.gfx_current);
10594 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10595 tree_type == TREE_TYPE_SOUNDS_DIR)
10597 artwork.snd_current = tree_node_new;
10599 DrawChooseTree(&artwork.snd_current);
10601 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10602 tree_type == TREE_TYPE_MUSIC_DIR)
10604 artwork.mus_current = tree_node_new;
10606 DrawChooseTree(&artwork.mus_current);
10611 static int UploadTapes(void)
10613 SetGameStatus(GAME_MODE_LOADING);
10615 FadeSetEnterScreen();
10616 FadeOut(REDRAW_ALL);
10618 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10620 FadeIn(REDRAW_ALL);
10622 DrawInitTextHead("Uploading tapes");
10624 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10625 global.autoplay_leveldir = "ALL";
10626 global.autoplay_all = TRUE;
10628 int num_tapes_uploaded = AutoPlayTapes();
10630 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10631 global.autoplay_leveldir = NULL;
10632 global.autoplay_all = FALSE;
10634 SetGameStatus(GAME_MODE_MAIN);
10638 return num_tapes_uploaded;
10641 static boolean OfferUploadTapes(void)
10643 if (!Request(setup.has_remaining_tapes ?
10644 "Upload missing tapes to the high score server now?" :
10645 "Upload all your tapes to the high score server now?", REQ_ASK))
10648 int num_tapes_uploaded = UploadTapes();
10651 if (num_tapes_uploaded < 0)
10653 num_tapes_uploaded = -num_tapes_uploaded - 1;
10655 if (num_tapes_uploaded == 0)
10656 sprintf(message, "Upload failed! No tapes uploaded!");
10657 else if (num_tapes_uploaded == 1)
10658 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10660 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10661 num_tapes_uploaded);
10663 Request(message, REQ_CONFIRM);
10665 // if uploading tapes failed, add tape upload entry to setup menu
10666 setup.provide_uploading_tapes = TRUE;
10667 setup.has_remaining_tapes = TRUE;
10669 SaveSetup_ServerSetup();
10674 if (num_tapes_uploaded == 0)
10675 sprintf(message, "No tapes uploaded!");
10676 else if (num_tapes_uploaded == 1)
10677 sprintf(message, "1 tape uploaded!");
10679 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10681 Request(message, REQ_CONFIRM);
10683 if (num_tapes_uploaded > 0)
10684 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10686 // after all tapes have been uploaded, remove entry from setup menu
10687 setup.provide_uploading_tapes = FALSE;
10688 setup.has_remaining_tapes = FALSE;
10690 SaveSetup_ServerSetup();
10695 static void CheckUploadTapes(void)
10697 if (!setup.ask_for_uploading_tapes)
10700 // after asking for uploading tapes, do not ask again
10701 setup.ask_for_uploading_tapes = FALSE;
10702 setup.ask_for_remaining_tapes = FALSE;
10704 if (directoryExists(getTapeDir(NULL)))
10706 boolean tapes_uploaded = OfferUploadTapes();
10708 if (!tapes_uploaded)
10710 Request(setup.has_remaining_tapes ?
10711 "You can upload missing tapes from the setup menu later!" :
10712 "You can upload your tapes from the setup menu later!",
10718 // if tapes directory does not exist yet, never offer uploading all tapes
10719 setup.provide_uploading_tapes = FALSE;
10722 SaveSetup_ServerSetup();
10725 static void UpgradePlayerUUID(void)
10727 ApiResetUUIDAsThread(getUUID());
10730 static void CheckUpgradePlayerUUID(void)
10732 if (setup.player_version > 1)
10735 UpgradePlayerUUID();
10738 void CheckApiServerTasks(void)
10740 // check if the player's UUID has to be upgraded
10741 CheckUpgradePlayerUUID();
10743 // check if there are any tapes to be uploaded
10744 CheckUploadTapes();