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 void HandleHallOfFame_SelectLevelOrScore(int, int);
300 static char *getHallOfFameRankText(int);
301 static char *getHallOfFameScoreText(int);
303 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
305 static int info_mode = INFO_MODE_MAIN;
306 static int setup_mode = SETUP_MODE_MAIN;
308 static TreeInfo *window_sizes = NULL;
309 static TreeInfo *window_size_current = NULL;
311 static TreeInfo *scaling_types = NULL;
312 static TreeInfo *scaling_type_current = NULL;
314 static TreeInfo *rendering_modes = NULL;
315 static TreeInfo *rendering_mode_current = NULL;
317 static TreeInfo *vsync_modes = NULL;
318 static TreeInfo *vsync_mode_current = NULL;
320 static TreeInfo *scroll_delays = NULL;
321 static TreeInfo *scroll_delay_current = NULL;
323 static TreeInfo *snapshot_modes = NULL;
324 static TreeInfo *snapshot_mode_current = NULL;
326 static TreeInfo *scores_types = NULL;
327 static TreeInfo *scores_type_current = NULL;
329 static TreeInfo *game_speeds_normal = NULL;
330 static TreeInfo *game_speeds_extended = NULL;
331 static TreeInfo *game_speeds = NULL;
332 static TreeInfo *game_speed_current = NULL;
334 static TreeInfo *volumes_simple = NULL;
335 static TreeInfo *volume_simple_current = NULL;
337 static TreeInfo *volumes_loops = NULL;
338 static TreeInfo *volume_loops_current = NULL;
340 static TreeInfo *volumes_music = NULL;
341 static TreeInfo *volume_music_current = NULL;
343 static TreeInfo *touch_controls = NULL;
344 static TreeInfo *touch_control_current = NULL;
346 static TreeInfo *move_distances = NULL;
347 static TreeInfo *move_distance_current = NULL;
349 static TreeInfo *drop_distances = NULL;
350 static TreeInfo *drop_distance_current = NULL;
352 static TreeInfo *transparencies = NULL;
353 static TreeInfo *transparency_current = NULL;
355 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
356 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
358 static TreeInfo *player_name = NULL;
359 static TreeInfo *player_name_current = NULL;
361 static TreeInfo *level_number = NULL;
362 static TreeInfo *level_number_current = NULL;
364 static TreeInfo *score_entries = NULL;
365 static TreeInfo *score_entry_current = NULL;
367 static struct ValueTextInfo window_sizes_list[] =
372 { 100, "100 % (Default)" },
385 static struct StringValueTextInfo scaling_types_list[] =
387 { SCALING_QUALITY_NEAREST, "Off" },
388 { SCALING_QUALITY_LINEAR, "Linear" },
389 { SCALING_QUALITY_BEST, "Anisotropic" },
394 static struct StringValueTextInfo rendering_modes_list[] =
396 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
397 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
399 // this mode may work under certain conditions, but does not work on Windows
400 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
402 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
407 static struct StringValueTextInfo vsync_modes_list[] =
409 { STR_VSYNC_MODE_OFF, "Off" },
410 { STR_VSYNC_MODE_NORMAL, "Normal" },
411 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
416 static struct StringValueTextInfo scores_types_list[] =
418 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
419 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
420 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
425 static struct ValueTextInfo game_speeds_list_normal[] =
436 static struct ValueTextInfo game_speeds_list_extended[] =
438 { 1000, "1 fps (Extremely Slow)" },
443 { 29, "35 fps (Original Supaplex)" },
445 { 20, "50 fps (=== Normal Speed ===)" },
446 { 16, "60 fps (60 Hz VSync Speed)" },
447 { 14, "70 fps (Maximum Supaplex)" },
451 { 1, "1000 fps (Extremely Fast)" },
456 static struct ValueTextInfo *game_speeds_list;
458 static struct ValueTextInfo scroll_delays_list[] =
460 { 0, "0 Tiles (No Scroll Delay)" },
463 { 3, "3 Tiles (Default)" },
468 { 8, "8 Tiles (Maximum Scroll Delay)"},
473 static struct StringValueTextInfo snapshot_modes_list[] =
475 { STR_SNAPSHOT_MODE_OFF, "Off" },
476 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
477 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
478 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
483 static struct ValueTextInfo volumes_list[] =
503 static struct StringValueTextInfo touch_controls_list[] =
505 { TOUCH_CONTROL_OFF, "Off" },
506 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
507 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
508 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
513 static struct ValueTextInfo distances_list[] =
528 static struct ValueTextInfo transparencies_list[] =
530 { 0, "0 % (Opaque)" },
540 { 100, "100 % (Invisible)" },
545 static struct ValueTextInfo grid_sizes_list[] =
581 static int align_xoffset = 0;
582 static int align_yoffset = 0;
584 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
585 (s) <= GAME_MODE_SETUP ? (s) : \
586 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
588 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
589 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
591 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
592 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
593 (i) <= INFO_MODE_LEVELSET ? (i) : \
596 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
597 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
598 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
599 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
600 SETUP_MODE_CHOOSE_ARTWORK : \
601 SETUP_MODE_CHOOSE_OTHER)
603 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
604 menu.draw_xoffset[GAME_MODE_INFO] : \
605 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
606 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
607 menu.draw_yoffset[GAME_MODE_INFO] : \
608 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
609 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
610 menu.extra_spacing[GAME_MODE_INFO] : \
611 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
613 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
614 menu.draw_xoffset[GAME_MODE_SETUP] : \
615 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
616 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
617 menu.draw_yoffset[GAME_MODE_SETUP] : \
618 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
619 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
620 menu.extra_spacing[GAME_MODE_SETUP] : \
621 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
623 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
625 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
627 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
628 DRAW_XOFFSET_INFO(info_mode) : \
629 (s) == GAME_MODE_SETUP ? \
630 DRAW_XOFFSET_SETUP(setup_mode) : \
631 menu.draw_xoffset[DRAW_MODE(s)])
632 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
633 DRAW_YOFFSET_INFO(info_mode) : \
634 (s) == GAME_MODE_SETUP ? \
635 DRAW_YOFFSET_SETUP(setup_mode) : \
636 menu.draw_yoffset[DRAW_MODE(s)])
637 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
638 EXTRA_SPACING_INFO(info_mode) : \
639 (s) == GAME_MODE_SETUP ? \
640 EXTRA_SPACING_SETUP(setup_mode) : \
641 (s) == GAME_MODE_SCORES ? \
642 EXTRA_SPACING_SCORES(info_mode) : \
643 menu.extra_spacing[DRAW_MODE(s)])
645 #define mSX (SX + DRAW_XOFFSET(game_status))
646 #define mSY (SY + DRAW_YOFFSET(game_status))
648 #define amSX (mSX + align_xoffset)
649 #define amSY (mSY + align_yoffset)
651 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
652 menu.list_size[game_status] : \
653 MAX_MENU_ENTRIES_ON_SCREEN)
655 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
656 NUM_MENU_ENTRIES_ON_SCREEN)
659 // title display and control definitions
661 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
662 2 * MAX_NUM_TITLE_MESSAGES)
664 #define NO_DIRECT_LEVEL_SELECT (-1)
667 static int num_title_screens = 0;
669 struct TitleControlInfo
678 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
680 // main menu display and control definitions
682 #define MAIN_CONTROL_NAME 0
683 #define MAIN_CONTROL_LEVELS 1
684 #define MAIN_CONTROL_SCORES 2
685 #define MAIN_CONTROL_EDITOR 3
686 #define MAIN_CONTROL_INFO 4
687 #define MAIN_CONTROL_GAME 5
688 #define MAIN_CONTROL_SETUP 6
689 #define MAIN_CONTROL_QUIT 7
690 #define MAIN_CONTROL_PREV_LEVEL 8
691 #define MAIN_CONTROL_NEXT_LEVEL 9
692 #define MAIN_CONTROL_FIRST_LEVEL 10
693 #define MAIN_CONTROL_LAST_LEVEL 11
694 #define MAIN_CONTROL_LEVEL_NUMBER 12
695 #define MAIN_CONTROL_LEVEL_INFO_1 13
696 #define MAIN_CONTROL_LEVEL_INFO_2 14
697 #define MAIN_CONTROL_LEVEL_NAME 15
698 #define MAIN_CONTROL_LEVEL_AUTHOR 16
699 #define MAIN_CONTROL_LEVEL_YEAR 17
700 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
701 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
702 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
703 #define MAIN_CONTROL_TITLE_1 21
704 #define MAIN_CONTROL_TITLE_2 22
705 #define MAIN_CONTROL_TITLE_3 23
707 static char str_main_text_name[10];
708 static char str_main_text_first_level[10];
709 static char str_main_text_last_level[10];
710 static char str_main_text_level_number[10];
712 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
714 static char *main_text_name = str_main_text_name;
715 static char *main_text_first_level = str_main_text_first_level;
716 static char *main_text_last_level = str_main_text_last_level;
717 static char *main_text_level_number = str_main_text_level_number;
718 static char *main_text_levels = "Levelset";
719 static char *main_text_scores = "Hall Of Fame";
720 static char *main_text_editor = "Level Creator";
721 static char *main_text_info = "Info Screen";
722 static char *main_text_game = "Start Game";
723 static char *main_text_setup = "Setup";
724 static char *main_text_quit = "Quit";
725 static char *main_text_level_name = level.name;
726 static char *main_text_level_author = level.author;
727 static char *main_text_level_year = NULL;
728 static char *main_text_level_imported_from = NULL;
729 static char *main_text_level_imported_by = NULL;
730 static char *main_text_level_tested_by = NULL;
731 static char *main_text_title_1 = NULL;
732 static char *main_text_title_2 = NULL;
733 static char *main_text_title_3 = NULL;
735 extern char debug_xsn_mode[];
737 struct MainControlInfo
741 struct MenuPosInfo *pos_button;
744 struct TextPosInfo *pos_text;
747 struct TextPosInfo *pos_input;
751 static struct MainControlInfo main_controls[] =
755 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
756 &menu.main.text.name, &main_text_name,
757 &menu.main.input.name, &setup.player_name,
761 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
762 &menu.main.text.levels, &main_text_levels,
767 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
768 &menu.main.text.scores, &main_text_scores,
773 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
774 &menu.main.text.editor, &main_text_editor,
779 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
780 &menu.main.text.info, &main_text_info,
785 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
786 &menu.main.text.game, &main_text_game,
791 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
792 &menu.main.text.setup, &main_text_setup,
797 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
798 &menu.main.text.quit, &main_text_quit,
802 MAIN_CONTROL_PREV_LEVEL,
808 MAIN_CONTROL_NEXT_LEVEL,
814 MAIN_CONTROL_FIRST_LEVEL,
816 &menu.main.text.first_level, &main_text_first_level,
820 MAIN_CONTROL_LAST_LEVEL,
822 &menu.main.text.last_level, &main_text_last_level,
826 MAIN_CONTROL_LEVEL_NUMBER,
828 &menu.main.text.level_number, &main_text_level_number,
832 MAIN_CONTROL_LEVEL_INFO_1,
834 &menu.main.text.level_info_1, NULL,
838 MAIN_CONTROL_LEVEL_INFO_2,
840 &menu.main.text.level_info_2, NULL,
844 MAIN_CONTROL_LEVEL_NAME,
846 &menu.main.text.level_name, &main_text_level_name,
850 MAIN_CONTROL_LEVEL_AUTHOR,
852 &menu.main.text.level_author, &main_text_level_author,
856 MAIN_CONTROL_LEVEL_YEAR,
858 &menu.main.text.level_year, &main_text_level_year,
862 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
864 &menu.main.text.level_imported_from, &main_text_level_imported_from,
868 MAIN_CONTROL_LEVEL_IMPORTED_BY,
870 &menu.main.text.level_imported_by, &main_text_level_imported_by,
874 MAIN_CONTROL_LEVEL_TESTED_BY,
876 &menu.main.text.level_tested_by, &main_text_level_tested_by,
880 MAIN_CONTROL_TITLE_1,
882 &menu.main.text.title_1, &main_text_title_1,
886 MAIN_CONTROL_TITLE_2,
888 &menu.main.text.title_2, &main_text_title_2,
892 MAIN_CONTROL_TITLE_3,
894 &menu.main.text.title_3, &main_text_title_3,
907 static int getTitleScreenGraphic(int nr, boolean initial)
909 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
912 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
914 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
918 static int getTitleScreenGameMode(boolean initial)
920 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
924 static int getTitleMessageGameMode(boolean initial)
926 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
929 static int getTitleAnimMode(struct TitleControlInfo *tci)
931 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
933 return base + tci->local_nr;
937 static int getTitleScreenBackground(boolean initial)
939 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
944 static int getTitleMessageBackground(int nr, boolean initial)
946 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
950 static int getTitleBackground(int nr, boolean initial, boolean is_image)
952 int base = (is_image ?
953 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
954 IMG_BACKGROUND_TITLESCREEN_1) :
955 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
956 IMG_BACKGROUND_TITLEMESSAGE_1));
957 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
958 IMG_BACKGROUND_TITLE);
959 int graphic_local = base + nr;
961 if (graphic_info[graphic_local].bitmap != NULL)
962 return graphic_local;
964 if (graphic_info[graphic_global].bitmap != NULL)
965 return graphic_global;
967 return IMG_UNDEFINED;
970 static int getTitleSound(struct TitleControlInfo *tci)
972 boolean is_image = tci->is_image;
973 int initial = tci->initial;
974 int nr = tci->local_nr;
975 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
976 int base = (is_image ?
977 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
978 SND_BACKGROUND_TITLESCREEN_1) :
979 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
980 SND_BACKGROUND_TITLEMESSAGE_1));
981 int sound_global = menu.sound[mode];
982 int sound_local = base + nr;
985 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
986 nr, initial, is_image,
987 sound_global, getSoundListEntry(sound_global)->filename,
988 sound_local, getSoundListEntry(sound_local)->filename);
991 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
994 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
997 return SND_UNDEFINED;
1000 static int getTitleMusic(struct TitleControlInfo *tci)
1002 boolean is_image = tci->is_image;
1003 int initial = tci->initial;
1004 int nr = tci->local_nr;
1005 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1006 int base = (is_image ?
1007 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1008 MUS_BACKGROUND_TITLESCREEN_1) :
1009 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1010 MUS_BACKGROUND_TITLEMESSAGE_1));
1011 int music_global = menu.music[mode];
1012 int music_local = base + nr;
1015 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1016 nr, initial, is_image,
1017 music_global, getMusicListEntry(music_global)->filename,
1018 music_local, getMusicListEntry(music_local)->filename);
1021 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1024 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1025 return music_global;
1027 return MUS_UNDEFINED;
1030 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1032 boolean is_image = tci->is_image;
1033 boolean initial = tci->initial;
1034 boolean first = tci->first;
1035 int nr = tci->local_nr;
1036 struct TitleMessageInfo tmi;
1037 struct TitleFadingInfo ti;
1039 tmi = (is_image ? (initial ? (first ?
1040 titlescreen_initial_first[nr] :
1041 titlescreen_initial[nr])
1043 titlescreen_first[nr] :
1045 : (initial ? (first ?
1046 titlemessage_initial_first[nr] :
1047 titlemessage_initial[nr])
1049 titlemessage_first[nr] :
1050 titlemessage[nr])));
1052 ti.fade_mode = tmi.fade_mode;
1053 ti.fade_delay = tmi.fade_delay;
1054 ti.post_delay = tmi.post_delay;
1055 ti.auto_delay = tmi.auto_delay;
1056 ti.auto_delay_unit = tmi.auto_delay_unit;
1061 static int compareTitleControlInfo(const void *object1, const void *object2)
1063 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1064 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1067 if (tci1->initial != tci2->initial)
1068 compare_result = (tci1->initial ? -1 : +1);
1069 else if (tci1->sort_priority != tci2->sort_priority)
1070 compare_result = tci1->sort_priority - tci2->sort_priority;
1071 else if (tci1->is_image != tci2->is_image)
1072 compare_result = (tci1->is_image ? -1 : +1);
1074 compare_result = tci1->local_nr - tci2->local_nr;
1076 return compare_result;
1079 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1081 int nr, int sort_priority)
1083 title_controls[num_title_screens].is_image = is_image;
1084 title_controls[num_title_screens].initial = initial;
1085 title_controls[num_title_screens].local_nr = nr;
1086 title_controls[num_title_screens].sort_priority = sort_priority;
1088 title_controls[num_title_screens].first = FALSE; // will be set later
1090 num_title_screens++;
1093 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1097 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1099 int graphic = getTitleScreenGraphic(i, initial);
1100 Bitmap *bitmap = graphic_info[graphic].bitmap;
1101 int sort_priority = graphic_info[graphic].sort_priority;
1104 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1107 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1109 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1110 char *filename = getLevelSetTitleMessageFilename(i, initial);
1111 int sort_priority = tmi->sort_priority;
1113 if (filename != NULL)
1114 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1118 static void InitializeTitleControls(boolean show_title_initial)
1120 num_title_screens = 0;
1122 // 1st step: initialize title screens for game start (only when starting)
1123 if (show_title_initial)
1124 InitializeTitleControls_CheckTitleInfo(TRUE);
1126 // 2nd step: initialize title screens for current level set
1127 InitializeTitleControls_CheckTitleInfo(FALSE);
1129 // sort title screens according to sort_priority and title number
1130 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1131 compareTitleControlInfo);
1133 // mark first title screen
1134 title_controls[0].first = TRUE;
1137 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1139 return (pos != NULL && pos->x != -1 && pos->y != -1);
1142 static boolean visibleTextPos(struct TextPosInfo *pos)
1144 return (pos != NULL && pos->x != -1 && pos->y != -1);
1147 static void InitializeMainControls(void)
1149 boolean local_team_mode = (!network.enabled && setup.team_mode);
1152 // set main control text values to dynamically determined values
1153 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1155 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1156 menu.main.text.first_level.size));
1157 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1158 menu.main.text.last_level.size));
1159 strcpy(main_text_level_number, int2str(level_nr,
1160 menu.main.text.level_number.size));
1162 main_text_level_year = leveldir_current->year;
1163 main_text_level_imported_from = leveldir_current->imported_from;
1164 main_text_level_imported_by = leveldir_current->imported_by;
1165 main_text_level_tested_by = leveldir_current->tested_by;
1167 main_text_title_1 = getConfigProgramTitleString();
1168 main_text_title_2 = getConfigProgramCopyrightString();
1169 main_text_title_3 = getConfigProgramCompanyString();
1171 // set main control screen positions to dynamically determined values
1172 for (i = 0; main_controls[i].nr != -1; i++)
1174 struct MainControlInfo *mci = &main_controls[i];
1176 struct MenuPosInfo *pos_button = mci->pos_button;
1177 struct TextPosInfo *pos_text = mci->pos_text;
1178 struct TextPosInfo *pos_input = mci->pos_input;
1179 char *text = (mci->text ? *mci->text : NULL);
1180 char *input = (mci->input ? *mci->input : NULL);
1181 int button_graphic = mci->button_graphic;
1182 int font_text = (pos_text ? pos_text->font : -1);
1183 int font_input = (pos_input ? pos_input->font : -1);
1185 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1186 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1187 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1188 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1189 int text_chars = (text != NULL ? strlen(text) : 0);
1190 int input_chars = (input != NULL ? strlen(input) : 0);
1193 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1195 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1196 int text_width = font_text_width * text_chars;
1197 int text_height = font_text_height;
1198 int input_width = font_input_width * input_chars;
1199 int input_height = font_input_height;
1201 if (nr == MAIN_CONTROL_NAME)
1203 menu.main.input.name.width = input_width;
1204 menu.main.input.name.height = input_height;
1207 if (pos_button != NULL) // (x/y may be -1/-1 here)
1209 pos_button->width = button_width;
1210 pos_button->height = button_height;
1213 if (pos_text != NULL) // (x/y may be -1/-1 here)
1215 // calculate text size -- needed for text alignment
1216 boolean calculate_text_size = (text != NULL);
1218 if (pos_text->width == -1 || calculate_text_size)
1219 pos_text->width = text_width;
1220 if (pos_text->height == -1 || calculate_text_size)
1221 pos_text->height = text_height;
1223 if (visibleMenuPos(pos_button))
1225 if (pos_text->x == -1)
1226 pos_text->x = pos_button->x + pos_button->width;
1227 if (pos_text->y == -1)
1229 pos_button->y + (pos_button->height - pos_text->height) / 2;
1233 if (pos_input != NULL) // (x/y may be -1/-1 here)
1235 if (visibleTextPos(pos_text))
1237 if (pos_input->x == -1)
1238 pos_input->x = pos_text->x + pos_text->width;
1239 if (pos_input->y == -1)
1240 pos_input->y = pos_text->y;
1243 if (pos_input->width == -1)
1244 pos_input->width = input_width;
1245 if (pos_input->height == -1)
1246 pos_input->height = input_height;
1251 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1252 int graphic, boolean pressed)
1254 struct GraphicInfo *g = &graphic_info[graphic];
1257 int xoffset = (pressed ? g->pressed_xoffset : 0);
1258 int yoffset = (pressed ? g->pressed_yoffset : 0);
1260 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1262 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1263 g->width, g->height, dst_x, dst_y);
1266 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1267 boolean active_input,
1268 boolean pressed_button)
1272 for (i = 0; main_controls[i].nr != -1; i++)
1274 struct MainControlInfo *mci = &main_controls[i];
1276 if (mci->nr == nr || nr == -1)
1278 struct MenuPosInfo *pos_button = mci->pos_button;
1279 struct TextPosInfo *pos_text = mci->pos_text;
1280 struct TextPosInfo *pos_input = mci->pos_input;
1281 char *text = (mci->text ? *mci->text : NULL);
1282 char *input = (mci->input ? *mci->input : NULL);
1283 int button_graphic = mci->button_graphic;
1284 int font_text = (pos_text ? pos_text->font : -1);
1285 int font_input = (pos_input ? pos_input->font : -1);
1289 button_graphic = BUTTON_ACTIVE(button_graphic);
1290 font_text = FONT_ACTIVE(font_text);
1295 font_input = FONT_ACTIVE(font_input);
1298 if (visibleMenuPos(pos_button))
1300 struct MenuPosInfo *pos = pos_button;
1301 int x = mSX + pos->x;
1302 int y = mSY + pos->y;
1304 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1305 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1308 if (visibleTextPos(pos_text) && text != NULL)
1310 struct TextPosInfo *pos = pos_text;
1311 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1312 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1315 // (check why/if this is needed)
1316 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1318 DrawText(x, y, text, font_text);
1321 if (visibleTextPos(pos_input) && input != NULL)
1323 struct TextPosInfo *pos = pos_input;
1324 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1325 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1328 // (check why/if this is needed)
1329 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1331 DrawText(x, y, input, font_input);
1337 static void DrawCursorAndText_Main(int nr, boolean active_text,
1338 boolean pressed_button)
1340 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1344 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1345 boolean pressed_button)
1347 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1351 static struct MainControlInfo *getMainControlInfo(int nr)
1355 for (i = 0; main_controls[i].nr != -1; i++)
1356 if (main_controls[i].nr == nr)
1357 return &main_controls[i];
1362 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1367 int rect_x = ALIGNED_TEXT_XPOS(rect);
1368 int rect_y = ALIGNED_TEXT_YPOS(rect);
1370 return (x >= rect_x && x < rect_x + rect->width &&
1371 y >= rect_y && y < rect_y + rect->height);
1374 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1379 int rect_x = ALIGNED_TEXT_XPOS(rect);
1380 int rect_y = ALIGNED_TEXT_YPOS(rect);
1383 Debug("screens:insideTextPosRect",
1384 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1385 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1386 (x >= rect_x && x < rect_x + rect->width &&
1387 y >= rect_y && y < rect_y + rect->height));
1390 return (x >= rect_x && x < rect_x + rect->width &&
1391 y >= rect_y && y < rect_y + rect->height);
1394 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1396 int rect_width = preview->xsize * preview->tile_size;
1397 int rect_height = preview->ysize * preview->tile_size;
1398 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1399 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1401 return (x >= rect_x && x < rect_x + rect_width &&
1402 y >= rect_y && y < rect_y + rect_height);
1405 static void AdjustScrollbar(int id, int items_max, int items_visible,
1408 struct GadgetInfo *gi = screen_gadget[id];
1410 if (item_position > items_max - items_visible)
1411 item_position = items_max - items_visible;
1413 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1414 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1415 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1418 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1420 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1424 static void clearMenuListArea(void)
1426 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1428 // correct scrollbar position if placed outside menu (playfield) area
1429 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1430 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1432 // clear menu list area, but not title or scrollbar
1433 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1434 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1437 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1439 static int cursor_array[MAX_LEV_FIELDY];
1440 int x = amSX + TILEX * xpos;
1441 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1446 cursor_array[ypos] = graphic;
1448 graphic = cursor_array[ypos];
1452 graphic = BUTTON_ACTIVE(graphic);
1454 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1455 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1458 static void initCursor(int ypos, int graphic)
1460 drawCursorExt(0, ypos, FALSE, graphic);
1463 static void drawCursor(int ypos, boolean active)
1465 drawCursorExt(0, ypos, active, -1);
1468 static void drawCursorXY(int xpos, int ypos, int graphic)
1470 drawCursorExt(xpos, ypos, FALSE, graphic);
1473 static void drawChooseTreeCursor(int ypos, boolean active)
1475 drawCursorExt(0, ypos, active, -1);
1478 static int getChooseTreeEditFont(boolean active)
1480 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1483 static int getChooseTreeEditXPos(int pos)
1485 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1486 int xoffset = (has_scrollbar ? -1 : 0);
1487 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1488 int sx = amSX + xpos * TILEX;
1489 int font_nr = getChooseTreeEditFont(FALSE);
1490 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1492 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1495 static int getChooseTreeEditYPos(int ypos_raw)
1497 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1498 int sy = amSY + ypos * TILEY;
1503 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1505 int sx = getChooseTreeEditXPos(POS_LEFT);
1506 int sy = getChooseTreeEditYPos(ypos_raw);
1507 int font_nr = getChooseTreeEditFont(active);
1509 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1512 static void DrawHeadline(void)
1514 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1515 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1518 static void DrawTitleScreenImage(int nr, boolean initial)
1520 int graphic = getTitleScreenGraphic(nr, initial);
1521 Bitmap *bitmap = graphic_info[graphic].bitmap;
1522 int width = graphic_info[graphic].width;
1523 int height = graphic_info[graphic].height;
1524 int src_x = graphic_info[graphic].src_x;
1525 int src_y = graphic_info[graphic].src_y;
1531 if (width > WIN_XSIZE)
1533 // image width too large for window => center image horizontally
1534 src_x = (width - WIN_XSIZE) / 2;
1538 if (height > WIN_YSIZE)
1540 // image height too large for window => center image vertically
1541 src_y = (height - WIN_YSIZE) / 2;
1545 // always display title screens centered
1546 dst_x = (WIN_XSIZE - width) / 2;
1547 dst_y = (WIN_YSIZE - height) / 2;
1549 SetDrawBackgroundMask(REDRAW_ALL);
1550 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1552 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1554 if (DrawingOnBackground(dst_x, dst_y))
1555 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1557 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1559 redraw_mask = REDRAW_ALL;
1562 static void DrawTitleScreenMessage(int nr, boolean initial)
1564 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1565 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1567 if (filename == NULL)
1570 // force TITLE font on title message screen
1571 SetFontStatus(getTitleMessageGameMode(initial));
1573 // if chars *and* width set to "-1", automatically determine width
1574 if (tmi->chars == -1 && tmi->width == -1)
1575 tmi->width = viewport.window[game_status].width;
1577 // if lines *and* height set to "-1", automatically determine height
1578 if (tmi->lines == -1 && tmi->height == -1)
1579 tmi->height = viewport.window[game_status].height;
1581 // if chars set to "-1", automatically determine by text and font width
1582 if (tmi->chars == -1)
1583 tmi->chars = tmi->width / getFontWidth(tmi->font);
1585 tmi->width = tmi->chars * getFontWidth(tmi->font);
1587 // if lines set to "-1", automatically determine by text and font height
1588 if (tmi->lines == -1)
1589 tmi->lines = tmi->height / getFontHeight(tmi->font);
1591 tmi->height = tmi->lines * getFontHeight(tmi->font);
1593 // if x set to "-1", automatically determine by width and alignment
1595 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1597 // if y set to "-1", automatically determine by height and alignment
1599 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1601 SetDrawBackgroundMask(REDRAW_ALL);
1602 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1604 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1606 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1607 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1608 tmi->autowrap, tmi->centered, tmi->parse_comments);
1613 static void DrawTitleScreen(void)
1615 KeyboardAutoRepeatOff();
1617 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1620 static boolean CheckTitleScreen(boolean levelset_has_changed)
1622 static boolean show_title_initial = TRUE;
1623 boolean show_titlescreen = FALSE;
1625 // needed to be able to skip title screen, if no image or message defined
1626 InitializeTitleControls(show_title_initial);
1628 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1629 show_titlescreen = TRUE;
1631 // show initial title images and messages only once at program start
1632 show_title_initial = FALSE;
1634 return (show_titlescreen && num_title_screens > 0);
1637 void DrawMainMenu(void)
1639 static LevelDirTree *leveldir_last_valid = NULL;
1640 boolean levelset_has_changed = FALSE;
1641 int fade_mask = REDRAW_FIELD;
1643 LimitScreenUpdates(FALSE);
1645 FadeSetLeaveScreen();
1647 // do not fade out here -- function may continue and fade on editor screen
1650 FadeMenuSoundsAndMusic();
1652 ExpireSoundLoops(FALSE);
1654 KeyboardAutoRepeatOn();
1656 audio.sound_deactivated = FALSE;
1660 // needed if last screen was the playing screen, invoked from level editor
1661 if (level_editor_test_game)
1663 CloseDoor(DOOR_CLOSE_ALL);
1665 SetGameStatus(GAME_MODE_EDITOR);
1672 // leveldir_current may be invalid (level group, parent link, node copy)
1673 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1675 if (leveldir_current != leveldir_last_valid)
1677 UpdateLastPlayedLevels_TreeInfo();
1679 levelset_has_changed = TRUE;
1682 // store valid level series information
1683 leveldir_last_valid = leveldir_current;
1685 init_last = init; // switch to new busy animation
1687 // needed if last screen (level choice) changed graphics, sounds or music
1688 ReloadCustomArtwork(0);
1690 if (CheckTitleScreen(levelset_has_changed))
1692 SetGameStatus(GAME_MODE_TITLE);
1699 if (redraw_mask & REDRAW_ALL)
1700 fade_mask = REDRAW_ALL;
1703 fade_mask = REDRAW_ALL;
1707 // needed if different viewport properties defined for menues
1708 ChangeViewportPropertiesIfNeeded();
1710 SetDrawtoField(DRAW_TO_BACKBUFFER);
1712 // level_nr may have been set to value over handicap with level editor
1713 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1714 level_nr = leveldir_current->handicap_level;
1716 LoadLevel(level_nr);
1717 LoadScore(level_nr);
1719 SaveLevelSetup_SeriesInfo();
1721 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1722 SetDrawDeactivationMask(REDRAW_NONE);
1723 SetDrawBackgroundMask(REDRAW_FIELD);
1725 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1728 if (fade_mask == REDRAW_ALL)
1729 RedrawGlobalBorder();
1734 InitializeMainControls();
1736 DrawCursorAndText_Main(-1, FALSE, FALSE);
1737 DrawPreviewLevelInitial();
1738 DrawNetworkPlayers();
1740 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1743 if (TAPE_IS_EMPTY(tape))
1745 DrawCompleteVideoDisplay();
1747 PlayMenuSoundsAndMusic();
1749 // create gadgets for main menu screen
1750 FreeScreenGadgets();
1751 CreateScreenGadgets();
1753 // may be required if audio buttons shown on tape and changed in setup menu
1755 CreateGameButtons();
1757 // map gadgets for main menu screen
1759 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1760 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1762 // copy actual game door content to door double buffer for OpenDoor()
1763 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1764 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1766 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1768 DrawMaskedBorder(fade_mask);
1773 // update screen area with special editor door
1774 redraw_mask |= REDRAW_ALL;
1777 SetMouseCursor(CURSOR_DEFAULT);
1779 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1781 SyncEmscriptenFilesystem();
1783 // needed once after program start or after user change
1784 CheckApiServerTasks();
1787 static void gotoTopLevelDir(void)
1789 // move upwards until inside (but not above) top level directory
1790 while (leveldir_current->node_parent &&
1791 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1793 // write a "path" into level tree for easy navigation to last level
1794 if (leveldir_current->node_parent->node_group->cl_first == -1)
1796 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1797 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1798 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1799 int cl_first, cl_cursor;
1801 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1802 cl_cursor = leveldir_pos - cl_first;
1804 leveldir_current->node_parent->node_group->cl_first = cl_first;
1805 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1808 leveldir_current = leveldir_current->node_parent;
1812 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1814 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1816 return (use_frame_counter ? video.frame_counter : Counter());
1819 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1820 struct TitleFadingInfo *fi)
1822 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1825 static void ResetTitleAutoDelay(unsigned int *counter_var,
1826 struct TitleFadingInfo *fi)
1828 *counter_var = getAutoDelayCounter(fi);
1831 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1833 static unsigned int title_delay = 0;
1834 static int title_screen_nr = 0;
1835 static int last_sound = -1, last_music = -1;
1836 boolean return_to_main_menu = FALSE;
1837 struct TitleControlInfo *tci;
1840 if (button == MB_MENU_INITIALIZE)
1843 title_screen_nr = 0;
1844 tci = &title_controls[title_screen_nr];
1846 SetAnimStatus(getTitleAnimMode(tci));
1848 last_sound = SND_UNDEFINED;
1849 last_music = MUS_UNDEFINED;
1851 if (num_title_screens != 0)
1853 FadeSetEnterScreen();
1855 // use individual title fading instead of global "enter screen" fading
1856 fading = getTitleFading(tci);
1859 if (game_status_last_screen == GAME_MODE_INFO)
1861 if (num_title_screens == 0)
1863 // switch game mode from title screen mode back to info screen mode
1864 SetGameStatus(GAME_MODE_INFO);
1866 // store that last screen was info screen, not main menu screen
1867 game_status_last_screen = GAME_MODE_INFO;
1869 DrawInfoScreen_NotAvailable("Title screen information:",
1870 "No title screen for this level set.");
1875 FadeMenuSoundsAndMusic();
1877 FadeOut(REDRAW_ALL);
1879 // title screens may have different window size
1880 ChangeViewportPropertiesIfNeeded();
1882 // only required to update logic for redrawing global border
1886 DrawTitleScreenImage(tci->local_nr, tci->initial);
1888 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1890 sound = getTitleSound(tci);
1891 music = getTitleMusic(tci);
1893 if (sound != last_sound)
1894 PlayMenuSoundExt(sound);
1895 if (music != last_music)
1896 PlayMenuMusicExt(music);
1901 SetMouseCursor(CURSOR_NONE);
1905 ResetTitleAutoDelay(&title_delay, &fading);
1910 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1911 button = MB_MENU_CHOICE;
1913 if (button == MB_MENU_LEAVE)
1915 return_to_main_menu = TRUE;
1917 else if (button == MB_MENU_CHOICE)
1919 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1921 SetGameStatus(GAME_MODE_INFO);
1923 info_mode = INFO_MODE_MAIN;
1932 if (title_screen_nr < num_title_screens)
1934 tci = &title_controls[title_screen_nr];
1936 SetAnimStatus(getTitleAnimMode(tci));
1938 sound = getTitleSound(tci);
1939 music = getTitleMusic(tci);
1941 if (last_sound != SND_UNDEFINED && sound != last_sound)
1942 FadeSound(last_sound);
1943 if (last_music != MUS_UNDEFINED && music != last_music)
1946 fading = getTitleFading(tci);
1948 FadeOut(REDRAW_ALL);
1951 DrawTitleScreenImage(tci->local_nr, tci->initial);
1953 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1955 sound = getTitleSound(tci);
1956 music = getTitleMusic(tci);
1958 if (sound != last_sound)
1959 PlayMenuSoundExt(sound);
1960 if (music != last_music)
1961 PlayMenuMusicExt(music);
1968 ResetTitleAutoDelay(&title_delay, &fading);
1972 FadeMenuSoundsAndMusic();
1974 return_to_main_menu = TRUE;
1978 if (return_to_main_menu)
1980 SetMouseCursor(CURSOR_DEFAULT);
1982 // force full menu screen redraw after displaying title screens
1983 redraw_mask = REDRAW_ALL;
1985 if (game_status_last_screen == GAME_MODE_INFO)
1987 SetGameStatus(GAME_MODE_INFO);
1989 info_mode = INFO_MODE_MAIN;
1993 else // default: return to main menu
1995 SetGameStatus(GAME_MODE_MAIN);
2002 static void HandleMainMenu_ToggleTeamMode(void)
2004 setup.team_mode = !setup.team_mode;
2006 InitializeMainControls();
2007 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2009 DrawPreviewPlayers();
2012 static void HandleMainMenu_SelectLevel(int step, int direction,
2013 int selected_level_nr)
2015 int old_level_nr = level_nr;
2018 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2019 new_level_nr = selected_level_nr;
2021 new_level_nr = old_level_nr + step * direction;
2023 if (new_level_nr < leveldir_current->first_level)
2024 new_level_nr = leveldir_current->first_level;
2025 if (new_level_nr > leveldir_current->last_level)
2026 new_level_nr = leveldir_current->last_level;
2028 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2030 // skipping levels is only allowed when trying to skip single level
2031 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2032 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2034 leveldir_current->handicap_level++;
2035 SaveLevelSetup_SeriesInfo();
2038 new_level_nr = leveldir_current->handicap_level;
2041 if (new_level_nr != old_level_nr)
2043 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2045 PlaySound(SND_MENU_ITEM_SELECTING);
2047 level_nr = new_level_nr;
2049 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2050 int2str(level_nr, menu.main.text.level_number.size),
2051 mci->pos_text->font);
2053 LoadLevel(level_nr);
2054 DrawPreviewLevelInitial();
2058 DrawCompleteVideoDisplay();
2060 SaveLevelSetup_SeriesInfo();
2062 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2064 // force redraw of playfield area (may be reset at this point)
2065 redraw_mask |= REDRAW_FIELD;
2069 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2071 static int choice = MAIN_CONTROL_GAME;
2072 static boolean button_pressed_last = FALSE;
2073 boolean button_pressed = FALSE;
2075 int i = 0; // needed to prevent compiler warning due to bad code below
2077 if (button == MB_MENU_INITIALIZE)
2079 DrawCursorAndText_Main(choice, TRUE, FALSE);
2084 if (mx || my) // mouse input
2088 for (i = 0; main_controls[i].nr != -1; i++)
2090 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2091 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2092 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2094 pos = main_controls[i].nr;
2100 // check if level preview was clicked
2101 if (insidePreviewRect(&preview, mx - SX, my - SY))
2102 pos = MAIN_CONTROL_GAME;
2104 // handle pressed/unpressed state for active/inactive menu buttons
2105 // (if pos != -1, "i" contains index position corresponding to "pos")
2107 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2108 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2109 button_pressed = TRUE;
2111 if (button_pressed != button_pressed_last)
2113 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2116 PlaySound(SND_MENU_BUTTON_PRESSING);
2118 PlaySound(SND_MENU_BUTTON_RELEASING);
2121 else if (dx || dy) // keyboard input
2123 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2124 choice == MAIN_CONTROL_SETUP))
2125 button = MB_MENU_CHOICE;
2130 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2132 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2134 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2136 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2138 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2140 CloseDoor(DOOR_CLOSE_2);
2142 SetGameStatus(GAME_MODE_LEVELNR);
2144 DrawChooseLevelNr();
2146 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2152 PlaySound(SND_MENU_ITEM_ACTIVATING);
2154 DrawCursorAndText_Main(choice, FALSE, FALSE);
2155 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2161 if (choice == MAIN_CONTROL_NAME)
2163 // special case: cursor left or right pressed -- toggle team mode
2164 HandleMainMenu_ToggleTeamMode();
2166 else if (choice != MAIN_CONTROL_INFO &&
2167 choice != MAIN_CONTROL_SETUP)
2169 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2175 PlaySound(SND_MENU_ITEM_SELECTING);
2177 if (pos == MAIN_CONTROL_NAME)
2180 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2182 // special case: menu text "name/team" clicked -- toggle team mode
2183 HandleMainMenu_ToggleTeamMode();
2187 if (setup.multiple_users)
2189 CloseDoor(DOOR_CLOSE_2);
2191 SetGameStatus(GAME_MODE_NAMES);
2193 DrawChoosePlayerName();
2197 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2203 else if (pos == MAIN_CONTROL_LEVELS)
2207 CloseDoor(DOOR_CLOSE_2);
2209 SetGameStatus(GAME_MODE_LEVELS);
2211 SaveLevelSetup_LastSeries();
2212 SaveLevelSetup_SeriesInfo();
2214 // restore level set if chosen from "last played level set" menu
2215 RestoreLastPlayedLevels(&leveldir_current);
2217 if (setup.internal.choose_from_top_leveldir)
2220 DrawChooseLevelSet();
2223 else if (pos == MAIN_CONTROL_SCORES)
2225 CloseDoor(DOOR_CLOSE_2);
2227 SetGameStatus(GAME_MODE_SCORES);
2229 DrawHallOfFame(level_nr);
2231 else if (pos == MAIN_CONTROL_EDITOR)
2233 if (leveldir_current->readonly &&
2234 setup.editor.show_read_only_warning)
2235 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2237 CloseDoor(DOOR_CLOSE_ALL);
2239 SetGameStatus(GAME_MODE_EDITOR);
2241 FadeSetEnterScreen();
2245 else if (pos == MAIN_CONTROL_INFO)
2247 CloseDoor(DOOR_CLOSE_2);
2249 SetGameStatus(GAME_MODE_INFO);
2251 info_mode = INFO_MODE_MAIN;
2255 else if (pos == MAIN_CONTROL_GAME)
2257 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2259 else if (pos == MAIN_CONTROL_SETUP)
2261 CloseDoor(DOOR_CLOSE_2);
2263 SetGameStatus(GAME_MODE_SETUP);
2265 setup_mode = SETUP_MODE_MAIN;
2269 else if (pos == MAIN_CONTROL_QUIT)
2271 SaveLevelSetup_LastSeries();
2272 SaveLevelSetup_SeriesInfo();
2274 #if defined(PLATFORM_EMSCRIPTEN)
2275 Request("Close the browser window to quit!", REQ_CONFIRM);
2277 if (!setup.ask_on_quit_program ||
2278 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2279 SetGameStatus(GAME_MODE_QUIT);
2285 button_pressed_last = button_pressed;
2289 // ============================================================================
2290 // info screen functions
2291 // ============================================================================
2293 static struct TokenInfo *info_info;
2294 static int num_info_info; // number of info entries shown on screen
2295 static int max_info_info; // total number of info entries in list
2297 static void execInfoTitleScreen(void)
2299 info_mode = INFO_MODE_TITLE;
2304 static void execInfoElements(void)
2306 info_mode = INFO_MODE_ELEMENTS;
2311 static void execInfoMusic(void)
2313 info_mode = INFO_MODE_MUSIC;
2318 static void execInfoCredits(void)
2320 info_mode = INFO_MODE_CREDITS;
2325 static void execInfoProgram(void)
2327 info_mode = INFO_MODE_PROGRAM;
2332 static void execInfoVersion(void)
2334 info_mode = INFO_MODE_VERSION;
2339 static void execInfoLevelSet(void)
2341 info_mode = INFO_MODE_LEVELSET;
2346 static void execExitInfo(void)
2348 SetGameStatus(GAME_MODE_MAIN);
2353 static struct TokenInfo info_info_main[] =
2355 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2356 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2357 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2358 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2359 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2360 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2361 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2362 { TYPE_EMPTY, NULL, "" },
2363 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2368 static int getMenuTextFont(int type)
2370 if (type & (TYPE_SWITCH |
2384 static struct TokenInfo *setup_info;
2385 static struct TokenInfo setup_info_input[];
2387 static struct TokenInfo *menu_info;
2389 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2390 int screen_pos, int menu_info_pos_raw,
2393 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2394 struct TokenInfo *ti = &token_info[pos];
2395 int xpos = MENU_SCREEN_START_XPOS;
2396 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2397 int font_nr = getMenuTextFont(ti->type);
2399 if (setup_mode == SETUP_MODE_INPUT)
2400 font_nr = FONT_MENU_1;
2403 font_nr = FONT_ACTIVE(font_nr);
2405 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2407 if (ti->type & ~TYPE_SKIP_ENTRY)
2408 drawCursor(screen_pos, active);
2411 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2414 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2417 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2420 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2423 static char *window_size_text;
2424 static char *scaling_type_text;
2425 static char *network_server_text;
2427 static void drawSetupValue(int, int);
2429 static void drawMenuInfoList(int first_entry, int num_page_entries,
2430 int max_page_entries)
2434 if (first_entry + num_page_entries > max_page_entries)
2437 clearMenuListArea();
2439 for (i = 0; i < num_page_entries; i++)
2441 int menu_info_pos = first_entry + i;
2442 struct TokenInfo *si = &menu_info[menu_info_pos];
2443 void *value_ptr = si->value;
2445 // set some entries to "unchangeable" according to other variables
2446 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2447 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2448 (value_ptr == &setup.sound_music && !audio.music_available) ||
2449 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2450 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2451 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2452 si->type |= TYPE_GHOSTED;
2454 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2455 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2456 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2457 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2458 else if (si->type & ~TYPE_SKIP_ENTRY)
2459 initCursor(i, IMG_MENU_BUTTON);
2461 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2463 if (si->type & TYPE_STRING)
2467 if (value_ptr == &network_server_text)
2468 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2470 if (gadget_id != -1)
2472 struct GadgetInfo *gi = screen_gadget[gadget_id];
2473 int xpos = MENU_SCREEN_START_XPOS;
2474 int ypos = MENU_SCREEN_START_YPOS + i;
2475 int x = mSX + xpos * 32;
2476 int y = mSY + ypos * 32;
2478 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2482 if (si->type & TYPE_VALUE &&
2483 menu_info == setup_info)
2484 drawSetupValue(i, menu_info_pos);
2488 static void DrawInfoScreen_Main(void)
2490 int fade_mask = REDRAW_FIELD;
2493 if (redraw_mask & REDRAW_ALL)
2494 fade_mask = REDRAW_ALL;
2497 fade_mask = REDRAW_ALL;
2500 FadeMenuSoundsAndMusic();
2502 FreeScreenGadgets();
2503 CreateScreenGadgets();
2505 // (needed after displaying title screens which disable auto repeat)
2506 KeyboardAutoRepeatOn();
2508 FadeSetLeaveScreen();
2512 // needed if different viewport properties defined for info screen
2513 ChangeViewportPropertiesIfNeeded();
2515 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2519 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2521 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2523 info_info = info_info_main;
2525 // determine maximal number of info entries that can be displayed on screen
2527 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2530 // determine maximal number of info entries available for menu of info screen
2532 for (i = 0; info_info[i].type != 0; i++)
2535 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2537 MapScreenGadgets(max_info_info);
2539 PlayMenuSoundsAndMusic();
2541 DrawMaskedBorder(fade_mask);
2546 static void changeSetupValue(int, int, int);
2548 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2549 int mode, int num_page_entries,
2550 int max_page_entries)
2552 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2553 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2554 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2555 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2556 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2557 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2558 int *num_page_entries_last = num_page_entries_all_last[game_status];
2559 int *choice_store = choice_stores[game_status];
2560 int *first_entry_store = first_entry_stores[game_status];
2561 int choice = choice_store[mode]; // starts with 0
2562 int first_entry = first_entry_store[mode]; // starts with 0
2564 int y = choice - first_entry;
2566 boolean position_set_by_scrollbar = (dx == 999);
2567 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2570 if (button == MB_MENU_INITIALIZE)
2572 // check if number of menu page entries has changed (may happen by change
2573 // of custom artwork definition value for 'list_size' for this menu screen)
2574 // (in this case, the last menu position most probably has to be corrected)
2575 if (num_page_entries != num_page_entries_last[mode])
2577 choice_store[mode] = first_entry_store[mode] = 0;
2579 choice = first_entry = 0;
2582 num_page_entries_last[mode] = num_page_entries;
2585 // advance to first valid menu entry
2586 while (choice < num_page_entries &&
2587 menu_info[choice].type & TYPE_SKIP_ENTRY)
2590 if (position_set_by_scrollbar)
2591 first_entry = first_entry_store[mode] = dy;
2593 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2594 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2596 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2598 if (choice < first_entry)
2600 choice = first_entry;
2602 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2605 else if (choice > first_entry + num_page_entries - 1)
2607 choice = first_entry + num_page_entries - 1;
2609 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2613 choice_store[mode] = choice;
2615 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2619 else if (button == MB_MENU_LEAVE)
2621 PlaySound(SND_MENU_ITEM_SELECTING);
2623 for (i = 0; i < max_page_entries; i++)
2625 if (menu_info[i].type & TYPE_LEAVE_MENU)
2627 void (*menu_callback_function)(void) = menu_info[i].value;
2631 menu_callback_function();
2633 break; // absolutely needed because function changes 'menu_info'!
2640 if (mx || my) // mouse input
2642 x = (mx - mSX) / 32;
2643 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2645 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2647 // move cursor instead of scrolling when already at start/end of list
2648 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2650 else if (dy == +1 * SCROLL_LINE &&
2651 first_entry + num_page_entries == max_page_entries)
2654 // handle scrolling screen one line or page
2656 y + dy > num_page_entries - 1)
2658 boolean redraw = FALSE;
2660 if (ABS(dy) == SCROLL_PAGE)
2661 step = num_page_entries - 1;
2663 if (dy < 0 && first_entry > 0)
2665 // scroll page/line up
2667 first_entry -= step;
2668 if (first_entry < 0)
2673 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2675 // scroll page/line down
2677 first_entry += step;
2678 if (first_entry + num_page_entries > max_page_entries)
2679 first_entry = MAX(0, max_page_entries - num_page_entries);
2686 choice += first_entry - first_entry_store[mode];
2688 if (choice < first_entry)
2690 choice = first_entry;
2692 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2695 else if (choice > first_entry + num_page_entries - 1)
2697 choice = first_entry + num_page_entries - 1;
2699 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2702 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2706 if (choice < first_entry ||
2707 choice > first_entry + num_page_entries - 1)
2708 first_entry += SIGN(dy);
2711 first_entry_store[mode] = first_entry;
2712 choice_store[mode] = choice;
2714 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2716 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2718 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2719 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2727 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2729 if (menu_info[choice].type & menu_navigation_type ||
2730 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2731 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2732 menu_info[choice].type & TYPE_PLAYER)
2733 button = MB_MENU_CHOICE;
2738 // jump to next non-empty menu entry (up or down)
2739 while (first_entry + y > 0 &&
2740 first_entry + y < max_page_entries - 1 &&
2741 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2744 if (!IN_VIS_MENU(x, y))
2746 choice += y - y_old;
2748 if (choice < first_entry)
2749 first_entry = choice;
2750 else if (choice > first_entry + num_page_entries - 1)
2751 first_entry = choice - num_page_entries + 1;
2753 if (first_entry >= 0 &&
2754 first_entry + num_page_entries <= max_page_entries)
2756 first_entry_store[mode] = first_entry;
2758 if (choice < first_entry)
2759 choice = first_entry;
2760 else if (choice > first_entry + num_page_entries - 1)
2761 choice = first_entry + num_page_entries - 1;
2763 choice_store[mode] = choice;
2765 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2767 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2769 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2770 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2777 if (!anyScrollbarGadgetActive() &&
2778 IN_VIS_MENU(x, y) &&
2779 mx < mx_right_border &&
2780 y >= 0 && y < num_page_entries)
2784 if (first_entry + y != choice &&
2785 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2787 PlaySound(SND_MENU_ITEM_ACTIVATING);
2789 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2790 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2792 choice = choice_store[mode] = first_entry + y;
2796 PlaySound(SND_MENU_ITEM_SELECTING);
2798 for (i = 0; menu_info[i].type != 0; i++)
2800 if (menu_info[i].type & TYPE_LEAVE_MENU)
2802 void (*menu_callback_function)(void) = menu_info[i].value;
2806 menu_callback_function();
2808 // absolutely needed because function changes 'menu_info'!
2816 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2818 PlaySound(SND_MENU_ITEM_SELECTING);
2820 // when selecting key headline, execute function for key value change
2821 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2822 menu_info[first_entry + y + 1].type & TYPE_KEY)
2825 // when selecting string value, execute function for list selection
2826 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2827 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2830 // when selecting string value, execute function for text input gadget
2831 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2832 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2835 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2837 void (*menu_callback_function)(void) =
2838 menu_info[first_entry + y].value;
2840 FadeSetFromType(menu_info[first_entry + y].type);
2842 menu_callback_function();
2844 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2846 void (*gadget_callback_function)(void) =
2847 menu_info[first_entry + y].value;
2849 gadget_callback_function();
2851 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2852 menu_info == setup_info)
2854 changeSetupValue(y, first_entry + y, dx);
2860 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2862 menu_info = info_info;
2864 HandleMenuScreen(mx, my, dx, dy, button,
2865 info_mode, num_info_info, max_info_info);
2868 static int getMenuFontSpacing(int spacing_height, int font_nr)
2870 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2872 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2876 static int getMenuTextSpacing(int spacing_height, int font_nr)
2878 return (getMenuFontSpacing(spacing_height, font_nr) +
2879 EXTRA_SPACING(game_status));
2882 static int getMenuTextStep(int spacing_height, int font_nr)
2884 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2887 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2889 int font_title = MENU_INFO_FONT_TITLE;
2890 int font_error = FONT_TEXT_2;
2891 int font_foot = MENU_INFO_FONT_FOOT;
2892 int spacing_title = menu.headline1_spacing_info[info_mode];
2893 int ystep_title = getMenuTextStep(spacing_title, font_title);
2894 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2895 int ystart2 = ystart1 + ystep_title;
2896 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2898 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2900 FadeOut(REDRAW_FIELD);
2905 DrawTextSCentered(ystart1, font_title, text_title);
2906 DrawTextSCentered(ystart2, font_error, text_error);
2908 DrawTextSCentered(ybottom, font_foot,
2909 "Press any key or button for info menu");
2911 FadeIn(REDRAW_FIELD);
2914 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2916 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2917 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2918 int font_title = MENU_INFO_FONT_TITLE;
2919 int font_foot = MENU_INFO_FONT_FOOT;
2920 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2921 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2922 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2923 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2924 int ystep = MENU_SCREEN_INFO_YSTEP;
2925 int element, action, direction;
2933 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2934 infoscreen_step[i] = infoscreen_frame[i] = 0;
2939 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2941 DrawTextSCentered(ybottom, font_foot,
2942 "Press any key or button for next page");
2948 while (helpanim_info[j].element != HELPANIM_LIST_END)
2950 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2955 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2964 j += infoscreen_step[i - start];
2966 element = helpanim_info[j].element;
2967 action = helpanim_info[j].action;
2968 direction = helpanim_info[j].direction;
2971 element = EL_UNKNOWN;
2973 if (action != -1 && direction != -1)
2974 graphic = el_act_dir2img(element, action, direction);
2975 else if (action != -1)
2976 graphic = el_act2img(element, action);
2977 else if (direction != -1)
2978 graphic = el_dir2img(element, direction);
2980 graphic = el2img(element);
2982 delay = helpanim_info[j++].delay;
2987 if (infoscreen_frame[i - start] == 0)
2990 infoscreen_frame[i - start] = delay - 1;
2994 sync_frame = delay - infoscreen_frame[i - start];
2995 infoscreen_frame[i - start]--;
2998 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3000 if (!infoscreen_frame[i - start])
3001 infoscreen_step[i - start] = 0;
3005 if (!infoscreen_frame[i - start])
3006 infoscreen_step[i - start]++;
3007 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3013 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3015 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3016 graphic, sync_frame, USE_MASKING);
3019 DrawInfoScreen_HelpText(element, action, direction, i - start);
3024 redraw_mask |= REDRAW_FIELD;
3029 static char *getHelpText(int element, int action, int direction)
3031 char token[MAX_LINE_LEN];
3033 strcpy(token, element_info[element].token_name);
3036 strcat(token, element_action_info[action].suffix);
3038 if (direction != -1)
3039 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3041 return getHashEntry(helptext_info, token);
3044 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3046 int font_nr = FONT_INFO_ELEMENTS;
3047 int font_width = getFontWidth(font_nr);
3048 int font_height = getFontHeight(font_nr);
3049 int yoffset = (TILEX - 2 * font_height) / 2;
3050 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3051 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3052 int ystep = TILEY + 4;
3053 int pad_left = xstart - SX;
3054 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3055 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3056 int max_lines_per_text = 2;
3059 if (action != -1 && direction != -1) // element.action.direction
3060 text = getHelpText(element, action, direction);
3062 if (text == NULL && action != -1) // element.action
3063 text = getHelpText(element, action, -1);
3065 if (text == NULL && direction != -1) // element.direction
3066 text = getHelpText(element, -1, direction);
3068 if (text == NULL) // base element
3069 text = getHelpText(element, -1, -1);
3071 if (text == NULL) // not found
3072 text = "No description available";
3074 if (strlen(text) <= max_chars_per_line) // only one line of text
3075 ystart += getFontHeight(font_nr) / 2;
3077 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3078 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3079 TRUE, FALSE, FALSE);
3082 static void DrawInfoScreen_TitleScreen(void)
3084 SetGameStatus(GAME_MODE_TITLE);
3089 void HandleInfoScreen_TitleScreen(int button)
3091 HandleTitleScreen(0, 0, 0, 0, button);
3094 static void DrawInfoScreen_Elements(void)
3096 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3098 FadeOut(REDRAW_FIELD);
3103 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3105 FadeIn(REDRAW_FIELD);
3108 void HandleInfoScreen_Elements(int button)
3110 static unsigned int info_delay = 0;
3111 static int num_anims;
3112 static int num_pages;
3114 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3117 if (button == MB_MENU_INITIALIZE)
3119 boolean new_element = TRUE;
3123 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3125 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3127 else if (new_element)
3130 new_element = FALSE;
3134 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3138 if (button == MB_MENU_LEAVE)
3140 PlaySound(SND_MENU_ITEM_SELECTING);
3142 info_mode = INFO_MODE_MAIN;
3147 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3149 if (button != MB_MENU_INITIALIZE)
3151 PlaySound(SND_MENU_ITEM_SELECTING);
3156 if (page >= num_pages)
3158 FadeMenuSoundsAndMusic();
3160 info_mode = INFO_MODE_MAIN;
3167 FadeSetNextScreen();
3169 if (button != MB_MENU_INITIALIZE)
3170 FadeOut(REDRAW_FIELD);
3172 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3174 if (button != MB_MENU_INITIALIZE)
3175 FadeIn(REDRAW_FIELD);
3179 if (DelayReached(&info_delay, GameFrameDelay))
3180 if (page < num_pages)
3181 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3183 PlayMenuSoundIfLoop();
3187 static void DrawInfoScreen_Music(void)
3189 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3191 FadeOut(REDRAW_FIELD);
3198 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3200 FadeIn(REDRAW_FIELD);
3203 void HandleInfoScreen_Music(int button)
3205 static struct MusicFileInfo *list = NULL;
3206 int font_title = MENU_INFO_FONT_TITLE;
3207 int font_head = MENU_INFO_FONT_HEAD;
3208 int font_text = MENU_INFO_FONT_TEXT;
3209 int font_foot = MENU_INFO_FONT_FOOT;
3210 int spacing_title = menu.headline1_spacing_info[info_mode];
3211 int spacing_head = menu.headline2_spacing_info[info_mode];
3212 int ystep_title = getMenuTextStep(spacing_title, font_title);
3213 int ystep_head = getMenuTextStep(spacing_head, font_head);
3214 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3215 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3217 if (button == MB_MENU_INITIALIZE)
3219 list = music_file_info;
3223 FadeMenuSoundsAndMusic();
3228 DrawTextSCentered(ystart, font_title,
3229 "No music info for this level set.");
3231 DrawTextSCentered(ybottom, font_foot,
3232 "Press any key or button for info menu");
3238 if (button == MB_MENU_LEAVE)
3240 PlaySound(SND_MENU_ITEM_SELECTING);
3242 FadeMenuSoundsAndMusic();
3244 info_mode = INFO_MODE_MAIN;
3249 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3251 if (button != MB_MENU_INITIALIZE)
3253 PlaySound(SND_MENU_ITEM_SELECTING);
3261 FadeMenuSoundsAndMusic();
3263 info_mode = INFO_MODE_MAIN;
3269 FadeMenuSoundsAndMusic();
3271 if (list != music_file_info)
3272 FadeSetNextScreen();
3274 if (button != MB_MENU_INITIALIZE)
3275 FadeOut(REDRAW_FIELD);
3282 int sound = list->music;
3284 if (IS_LOOP_SOUND(sound))
3285 PlaySoundLoop(sound);
3289 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3293 int music = list->music;
3295 if (IS_LOOP_MUSIC(music))
3296 PlayMusicLoop(music);
3300 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3303 ystart += ystep_title;
3305 if (!strEqual(list->title, UNKNOWN_NAME))
3307 if (!strEqual(list->title_header, UNKNOWN_NAME))
3309 DrawTextSCentered(ystart, font_head, list->title_header);
3310 ystart += ystep_head;
3313 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3314 ystart += ystep_head;
3317 if (!strEqual(list->artist, UNKNOWN_NAME))
3319 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3320 DrawTextSCentered(ystart, font_head, list->artist_header);
3322 DrawTextSCentered(ystart, font_head, "by");
3324 ystart += ystep_head;
3326 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3327 ystart += ystep_head;
3330 if (!strEqual(list->album, UNKNOWN_NAME))
3332 if (!strEqual(list->album_header, UNKNOWN_NAME))
3333 DrawTextSCentered(ystart, font_head, list->album_header);
3335 DrawTextSCentered(ystart, font_head, "from the album");
3337 ystart += ystep_head;
3339 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3340 ystart += ystep_head;
3343 if (!strEqual(list->year, UNKNOWN_NAME))
3345 if (!strEqual(list->year_header, UNKNOWN_NAME))
3346 DrawTextSCentered(ystart, font_head, list->year_header);
3348 DrawTextSCentered(ystart, font_head, "from the year");
3350 ystart += ystep_head;
3352 DrawTextFCentered(ystart, font_text, "%s", list->year);
3353 ystart += ystep_head;
3356 DrawTextSCentered(ybottom, FONT_TEXT_4,
3357 "Press any key or button for next page");
3359 if (button != MB_MENU_INITIALIZE)
3360 FadeIn(REDRAW_FIELD);
3363 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3364 PlaySoundLoop(list->music);
3367 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3369 int font_title = MENU_INFO_FONT_TITLE;
3370 int font_head = MENU_INFO_FONT_HEAD;
3371 int font_text = MENU_INFO_FONT_TEXT;
3372 int font_foot = MENU_INFO_FONT_FOOT;
3373 int spacing_title = menu.headline1_spacing_info[info_mode];
3374 int spacing_head = menu.headline2_spacing_info[info_mode];
3375 int spacing_para = menu.paragraph_spacing_info[info_mode];
3376 int spacing_line = menu.line_spacing_info[info_mode];
3377 int ystep_title = getMenuTextStep(spacing_title, font_title);
3378 int ystep_head = getMenuTextStep(spacing_head, font_head);
3379 int ystep_para = getMenuTextStep(spacing_para, font_text);
3380 int ystep_line = getMenuTextStep(spacing_line, font_text);
3381 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3382 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3387 DrawTextSCentered(ystart, font_title, "Credits:");
3388 ystart += ystep_title;
3392 DrawTextSCentered(ystart, font_head,
3393 "Special thanks to");
3394 ystart += ystep_head;
3395 DrawTextSCentered(ystart, font_text,
3397 ystart += ystep_head;
3398 DrawTextSCentered(ystart, font_head,
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_text,
3402 "\"Boulder Dash\"");
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_head,
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_text,
3409 ystart += ystep_head;
3410 DrawTextSCentered(ystart, font_head,
3412 ystart += ystep_head;
3413 DrawTextSCentered(ystart, font_text,
3414 "First Star Software");
3416 else if (screen_nr == 1)
3418 DrawTextSCentered(ystart, font_head,
3419 "Special thanks to");
3420 ystart += ystep_head;
3421 DrawTextSCentered(ystart, font_text,
3422 "Klaus Heinz & Volker Wertich");
3423 ystart += ystep_head;
3424 DrawTextSCentered(ystart, font_head,
3426 ystart += ystep_head;
3427 DrawTextSCentered(ystart, font_text,
3428 "\"Emerald Mine\"");
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_head,
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_text,
3435 ystart += ystep_head;
3436 DrawTextSCentered(ystart, font_head,
3438 ystart += ystep_head;
3439 DrawTextSCentered(ystart, font_text,
3442 else if (screen_nr == 2)
3444 DrawTextSCentered(ystart, font_head,
3445 "Special thanks to");
3446 ystart += ystep_head;
3447 DrawTextSCentered(ystart, font_text,
3448 "Michael Stopp & Philip Jespersen");
3449 ystart += ystep_head;
3450 DrawTextSCentered(ystart, font_head,
3452 ystart += ystep_head;
3453 DrawTextSCentered(ystart, font_text,
3455 ystart += ystep_head;
3456 DrawTextSCentered(ystart, font_head,
3458 ystart += ystep_head;
3459 DrawTextSCentered(ystart, font_text,
3461 ystart += ystep_head;
3462 DrawTextSCentered(ystart, font_head,
3464 ystart += ystep_head;
3465 DrawTextSCentered(ystart, font_text,
3466 "Digital Integration");
3468 else if (screen_nr == 3)
3470 DrawTextSCentered(ystart, font_head,
3471 "Special thanks to");
3472 ystart += ystep_head;
3473 DrawTextSCentered(ystart, font_text,
3474 "Hiroyuki Imabayashi");
3475 ystart += ystep_head;
3476 DrawTextSCentered(ystart, font_head,
3478 ystart += ystep_head;
3479 DrawTextSCentered(ystart, font_text,
3481 ystart += ystep_head;
3482 DrawTextSCentered(ystart, font_head,
3484 ystart += ystep_head;
3485 DrawTextSCentered(ystart, font_text,
3487 ystart += ystep_head;
3488 DrawTextSCentered(ystart, font_head,
3490 ystart += ystep_head;
3491 DrawTextSCentered(ystart, font_text,
3494 else if (screen_nr == 4)
3496 DrawTextSCentered(ystart, font_head,
3497 "Special thanks to");
3498 ystart += ystep_head;
3499 DrawTextSCentered(ystart, font_text,
3501 ystart += ystep_head;
3502 DrawTextSCentered(ystart, font_head,
3504 ystart += ystep_head;
3505 DrawTextSCentered(ystart, font_text,
3506 "J\xfcrgen Bonhagen");
3507 ystart += ystep_head;
3508 DrawTextSCentered(ystart, font_head,
3509 "for the continuous creation");
3510 ystart += ystep_line;
3511 DrawTextSCentered(ystart, font_head,
3512 "of outstanding level sets");
3514 else if (screen_nr == 5)
3516 DrawTextSCentered(ystart, font_head,
3518 ystart += ystep_head;
3519 DrawTextSCentered(ystart, font_text,
3521 ystart += ystep_head;
3522 DrawTextSCentered(ystart, font_head,
3523 "for ideas and inspiration by");
3524 ystart += ystep_head;
3525 DrawTextSCentered(ystart, font_text,
3527 ystart += ystep_para;
3529 DrawTextSCentered(ystart, font_head,
3531 ystart += ystep_head;
3532 DrawTextSCentered(ystart, font_text,
3534 ystart += ystep_head;
3535 DrawTextSCentered(ystart, font_head,
3536 "for ideas and inspiration by");
3537 ystart += ystep_head;
3538 DrawTextSCentered(ystart, font_text,
3541 else if (screen_nr == 6)
3543 DrawTextSCentered(ystart, font_head,
3545 ystart += ystep_head;
3546 DrawTextSCentered(ystart, font_text,
3548 ystart += ystep_head;
3549 DrawTextSCentered(ystart, font_head,
3550 "for the code base used for the");
3551 ystart += ystep_line;
3552 DrawTextSCentered(ystart, font_head,
3553 "native Emerald Mine engine");
3555 else if (screen_nr == 7)
3557 DrawTextSCentered(ystart, font_head,
3559 ystart += ystep_head;
3560 DrawTextSCentered(ystart, font_text,
3562 ystart += ystep_head;
3563 DrawTextSCentered(ystart, font_head,
3564 "for the initial DOS port");
3565 ystart += ystep_para;
3567 DrawTextSCentered(ystart, font_head,
3569 ystart += ystep_head;
3570 DrawTextSCentered(ystart, font_text,
3572 ystart += ystep_head;
3573 DrawTextSCentered(ystart, font_head,
3574 "for some additional toons");
3576 else if (screen_nr == 8)
3578 DrawTextSCentered(ystart, font_head,
3579 "And not to forget:");
3580 ystart += ystep_head;
3581 DrawTextSCentered(ystart, font_head,
3583 ystart += ystep_head;
3584 DrawTextSCentered(ystart, font_text,
3585 "All those who contributed");
3586 ystart += ystep_line;
3587 DrawTextSCentered(ystart, font_text,
3588 "levels to this game");
3589 ystart += ystep_line;
3590 DrawTextSCentered(ystart, font_text,
3594 DrawTextSCentered(ybottom, font_foot,
3595 "Press any key or button for next page");
3598 static void DrawInfoScreen_Credits(void)
3600 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3602 FadeMenuSoundsAndMusic();
3604 FadeOut(REDRAW_FIELD);
3606 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3608 FadeIn(REDRAW_FIELD);
3611 void HandleInfoScreen_Credits(int button)
3613 static int screen_nr = 0;
3614 int num_screens = 9;
3616 if (button == MB_MENU_INITIALIZE)
3620 // DrawInfoScreen_CreditsScreen(screen_nr);
3623 if (button == MB_MENU_LEAVE)
3625 PlaySound(SND_MENU_ITEM_SELECTING);
3627 info_mode = INFO_MODE_MAIN;
3632 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3634 if (button != MB_MENU_INITIALIZE)
3636 PlaySound(SND_MENU_ITEM_SELECTING);
3641 if (screen_nr >= num_screens)
3643 FadeMenuSoundsAndMusic();
3645 info_mode = INFO_MODE_MAIN;
3652 FadeSetNextScreen();
3654 if (button != MB_MENU_INITIALIZE)
3655 FadeOut(REDRAW_FIELD);
3657 DrawInfoScreen_CreditsScreen(screen_nr);
3659 if (button != MB_MENU_INITIALIZE)
3660 FadeIn(REDRAW_FIELD);
3664 PlayMenuSoundIfLoop();
3668 static void DrawInfoScreen_Program(void)
3670 int font_title = MENU_INFO_FONT_TITLE;
3671 int font_head = MENU_INFO_FONT_HEAD;
3672 int font_text = MENU_INFO_FONT_TEXT;
3673 int font_foot = MENU_INFO_FONT_FOOT;
3674 int spacing_title = menu.headline1_spacing_info[info_mode];
3675 int spacing_head = menu.headline2_spacing_info[info_mode];
3676 int spacing_para = menu.paragraph_spacing_info[info_mode];
3677 int spacing_line = menu.line_spacing_info[info_mode];
3678 int ystep_title = getMenuTextStep(spacing_title, font_title);
3679 int ystep_head = getMenuTextStep(spacing_head, font_head);
3680 int ystep_para = getMenuTextStep(spacing_para, font_text);
3681 int ystep_line = getMenuTextStep(spacing_line, font_text);
3682 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3683 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3685 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3687 FadeOut(REDRAW_FIELD);
3692 DrawTextSCentered(ystart, font_title, "Program Information:");
3693 ystart += ystep_title;
3695 DrawTextSCentered(ystart, font_head,
3696 "This game is Freeware!");
3697 ystart += ystep_head;
3698 DrawTextSCentered(ystart, font_head,
3699 "If you like it, send e-mail to:");
3700 ystart += ystep_head;
3701 DrawTextSCentered(ystart, font_text,
3702 setup.internal.program_email);
3703 ystart += ystep_para;
3705 DrawTextSCentered(ystart, font_head,
3706 "More information and levels:");
3707 ystart += ystep_head;
3708 DrawTextSCentered(ystart, font_text,
3709 setup.internal.program_website);
3710 ystart += ystep_para;
3712 DrawTextSCentered(ystart, font_head,
3713 "If you have created new levels,");
3714 ystart += ystep_line;
3715 DrawTextSCentered(ystart, font_head,
3716 "send them to me to include them!");
3717 ystart += ystep_head;
3718 DrawTextSCentered(ystart, font_head,
3721 DrawTextSCentered(ybottom, font_foot,
3722 "Press any key or button for info menu");
3724 FadeIn(REDRAW_FIELD);
3727 void HandleInfoScreen_Program(int button)
3729 if (button == MB_MENU_LEAVE)
3731 PlaySound(SND_MENU_ITEM_SELECTING);
3733 info_mode = INFO_MODE_MAIN;
3738 else if (button == MB_MENU_CHOICE)
3740 PlaySound(SND_MENU_ITEM_SELECTING);
3742 FadeMenuSoundsAndMusic();
3744 info_mode = INFO_MODE_MAIN;
3749 PlayMenuSoundIfLoop();
3753 static void DrawInfoScreen_Version(void)
3755 int font_title = MENU_INFO_FONT_TITLE;
3756 int font_head = MENU_INFO_FONT_HEAD;
3757 int font_text = MENU_INFO_FONT_TEXT;
3758 int font_foot = MENU_INFO_FONT_FOOT;
3759 int spacing_title = menu.headline1_spacing_info[info_mode];
3760 int spacing_head = menu.headline2_spacing_info[info_mode];
3761 int spacing_para = menu.paragraph_spacing_info[info_mode];
3762 int spacing_line = menu.line_spacing_info[info_mode];
3763 int xstep = getFontWidth(font_text);
3764 int ystep_title = getMenuTextStep(spacing_title, font_title);
3765 int ystep_head = getMenuTextStep(spacing_head, font_head);
3766 int ystep_para = getMenuTextStep(spacing_para, font_text);
3767 int ystep_line = getMenuTextStep(spacing_line, font_text);
3768 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3769 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3770 int xstart1 = mSX - SX + 2 * xstep;
3771 int xstart2 = mSX - SX + 18 * xstep;
3772 int xstart3 = mSX - SX + 28 * xstep;
3773 SDL_version sdl_version_compiled;
3774 const SDL_version *sdl_version_linked;
3775 int driver_name_len = 10;
3776 SDL_version sdl_version_linked_ext;
3777 const char *driver_name = NULL;
3779 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3781 FadeOut(REDRAW_FIELD);
3786 DrawTextSCentered(ystart, font_title, "Version Information:");
3787 ystart += ystep_title;
3789 DrawTextF(xstart1, ystart, font_head, "Name");
3790 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3791 ystart += ystep_line;
3793 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3795 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3796 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3797 ystart += ystep_line;
3799 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3800 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3801 ystart += ystep_line;
3805 DrawTextF(xstart1, ystart, font_head, "Version");
3806 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3807 ystart += ystep_line;
3810 DrawTextF(xstart1, ystart, font_head, "Platform");
3811 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3813 PLATFORM_XX_BIT_STRING);
3814 ystart += ystep_line;
3816 DrawTextF(xstart1, ystart, font_head, "Target");
3817 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3818 ystart += ystep_line;
3820 DrawTextF(xstart1, ystart, font_head, "Source date");
3821 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3822 ystart += ystep_line;
3824 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3825 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3826 ystart += ystep_para;
3828 DrawTextF(xstart1, ystart, font_head, "Library");
3829 DrawTextF(xstart2, ystart, font_head, "compiled");
3830 DrawTextF(xstart3, ystart, font_head, "linked");
3831 ystart += ystep_head;
3833 SDL_VERSION(&sdl_version_compiled);
3834 SDL_GetVersion(&sdl_version_linked_ext);
3835 sdl_version_linked = &sdl_version_linked_ext;
3837 DrawTextF(xstart1, ystart, font_text, "SDL");
3838 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3839 sdl_version_compiled.major,
3840 sdl_version_compiled.minor,
3841 sdl_version_compiled.patch);
3842 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3843 sdl_version_linked->major,
3844 sdl_version_linked->minor,
3845 sdl_version_linked->patch);
3846 ystart += ystep_line;
3848 SDL_IMAGE_VERSION(&sdl_version_compiled);
3849 sdl_version_linked = IMG_Linked_Version();
3851 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3852 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3853 sdl_version_compiled.major,
3854 sdl_version_compiled.minor,
3855 sdl_version_compiled.patch);
3856 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3857 sdl_version_linked->major,
3858 sdl_version_linked->minor,
3859 sdl_version_linked->patch);
3860 ystart += ystep_line;
3862 SDL_MIXER_VERSION(&sdl_version_compiled);
3863 sdl_version_linked = Mix_Linked_Version();
3865 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3866 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3867 sdl_version_compiled.major,
3868 sdl_version_compiled.minor,
3869 sdl_version_compiled.patch);
3870 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3871 sdl_version_linked->major,
3872 sdl_version_linked->minor,
3873 sdl_version_linked->patch);
3874 ystart += ystep_line;
3876 SDL_NET_VERSION(&sdl_version_compiled);
3877 sdl_version_linked = SDLNet_Linked_Version();
3879 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3880 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3881 sdl_version_compiled.major,
3882 sdl_version_compiled.minor,
3883 sdl_version_compiled.patch);
3884 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3885 sdl_version_linked->major,
3886 sdl_version_linked->minor,
3887 sdl_version_linked->patch);
3888 ystart += ystep_para;
3890 DrawTextF(xstart1, ystart, font_head, "Driver");
3891 DrawTextF(xstart2, ystart, font_head, "Requested");
3892 DrawTextF(xstart3, ystart, font_head, "Used");
3893 ystart += ystep_head;
3896 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3898 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3899 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3900 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3901 ystart += ystep_line;
3904 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3906 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3907 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3908 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3909 ystart += ystep_line;
3912 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3914 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3915 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3916 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3918 DrawTextSCentered(ybottom, font_foot,
3919 "Press any key or button for info menu");
3921 FadeIn(REDRAW_FIELD);
3924 void HandleInfoScreen_Version(int button)
3926 if (button == MB_MENU_LEAVE)
3928 PlaySound(SND_MENU_ITEM_SELECTING);
3930 info_mode = INFO_MODE_MAIN;
3935 else if (button == MB_MENU_CHOICE)
3937 PlaySound(SND_MENU_ITEM_SELECTING);
3939 FadeMenuSoundsAndMusic();
3941 info_mode = INFO_MODE_MAIN;
3946 PlayMenuSoundIfLoop();
3950 static void DrawInfoScreen_LevelSet(void)
3952 struct TitleMessageInfo *tmi = &readme;
3953 char *filename = getLevelSetInfoFilename();
3954 char *title = "Level Set Information:";
3955 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3956 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3958 if (filename == NULL)
3960 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3965 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3967 FadeOut(REDRAW_FIELD);
3972 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3974 // if x position set to "-1", automatically determine by playfield width
3976 tmi->x = SXSIZE / 2;
3978 // if y position set to "-1", use static default value
3982 // if width set to "-1", automatically determine by playfield width
3983 if (tmi->width == -1)
3984 tmi->width = SXSIZE - 2 * TILEX;
3986 // if height set to "-1", automatically determine by playfield height
3987 if (tmi->height == -1)
3988 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3990 // if chars set to "-1", automatically determine by text and font width
3991 if (tmi->chars == -1)
3992 tmi->chars = tmi->width / getFontWidth(tmi->font);
3994 tmi->width = tmi->chars * getFontWidth(tmi->font);
3996 // if lines set to "-1", automatically determine by text and font height
3997 if (tmi->lines == -1)
3998 tmi->lines = tmi->height / getFontHeight(tmi->font);
4000 tmi->height = tmi->lines * getFontHeight(tmi->font);
4002 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
4003 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
4004 tmi->autowrap, tmi->centered, tmi->parse_comments);
4006 DrawTextSCentered(ybottom, FONT_TEXT_4,
4007 "Press any key or button for info menu");
4009 FadeIn(REDRAW_FIELD);
4012 static void HandleInfoScreen_LevelSet(int button)
4014 if (button == MB_MENU_LEAVE)
4016 PlaySound(SND_MENU_ITEM_SELECTING);
4018 info_mode = INFO_MODE_MAIN;
4023 else if (button == MB_MENU_CHOICE)
4025 PlaySound(SND_MENU_ITEM_SELECTING);
4027 FadeMenuSoundsAndMusic();
4029 info_mode = INFO_MODE_MAIN;
4034 PlayMenuSoundIfLoop();
4038 static void DrawInfoScreen(void)
4040 if (info_mode == INFO_MODE_TITLE)
4041 DrawInfoScreen_TitleScreen();
4042 else if (info_mode == INFO_MODE_ELEMENTS)
4043 DrawInfoScreen_Elements();
4044 else if (info_mode == INFO_MODE_MUSIC)
4045 DrawInfoScreen_Music();
4046 else if (info_mode == INFO_MODE_CREDITS)
4047 DrawInfoScreen_Credits();
4048 else if (info_mode == INFO_MODE_PROGRAM)
4049 DrawInfoScreen_Program();
4050 else if (info_mode == INFO_MODE_VERSION)
4051 DrawInfoScreen_Version();
4052 else if (info_mode == INFO_MODE_LEVELSET)
4053 DrawInfoScreen_LevelSet();
4055 DrawInfoScreen_Main();
4057 if (info_mode != INFO_MODE_MAIN &&
4058 info_mode != INFO_MODE_TITLE &&
4059 info_mode != INFO_MODE_MUSIC)
4060 PlayMenuSoundsAndMusic();
4063 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4065 if (info_mode == INFO_MODE_TITLE)
4066 HandleInfoScreen_TitleScreen(button);
4067 else if (info_mode == INFO_MODE_ELEMENTS)
4068 HandleInfoScreen_Elements(button);
4069 else if (info_mode == INFO_MODE_MUSIC)
4070 HandleInfoScreen_Music(button);
4071 else if (info_mode == INFO_MODE_CREDITS)
4072 HandleInfoScreen_Credits(button);
4073 else if (info_mode == INFO_MODE_PROGRAM)
4074 HandleInfoScreen_Program(button);
4075 else if (info_mode == INFO_MODE_VERSION)
4076 HandleInfoScreen_Version(button);
4077 else if (info_mode == INFO_MODE_LEVELSET)
4078 HandleInfoScreen_LevelSet(button);
4080 HandleInfoScreen_Main(mx, my, dx, dy, button);
4084 // ============================================================================
4085 // rename player API functions
4086 // ============================================================================
4088 struct ApiRenamePlayerThreadData
4094 static void *CreateThreadData_ApiRenamePlayer(void)
4096 struct ApiRenamePlayerThreadData *data =
4097 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4099 data->player_name = getStringCopy(setup.player_name);
4100 data->player_uuid = getStringCopy(setup.player_uuid);
4105 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4107 struct ApiRenamePlayerThreadData *data = data_raw;
4109 checked_free(data->player_name);
4110 checked_free(data->player_uuid);
4114 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4117 struct ApiRenamePlayerThreadData *data = data_raw;
4118 char *player_name_raw = data->player_name;
4119 char *player_uuid_raw = data->player_uuid;
4121 request->hostname = setup.api_server_hostname;
4122 request->port = API_SERVER_PORT;
4123 request->method = API_SERVER_METHOD;
4124 request->uri = API_SERVER_URI_RENAME;
4126 char *player_name = getEscapedJSON(player_name_raw);
4127 char *player_uuid = getEscapedJSON(player_uuid_raw);
4129 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4132 " \"game_version\": \"%s\",\n"
4133 " \"game_platform\": \"%s\",\n"
4134 " \"name\": \"%s\",\n"
4135 " \"uuid\": \"%s\"\n"
4137 getPasswordJSON(setup.api_server_password),
4138 getProgramRealVersionString(),
4139 getProgramPlatformString(),
4143 checked_free(player_name);
4144 checked_free(player_uuid);
4146 ConvertHttpRequestBodyToServerEncoding(request);
4151 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4154 // nothing to do here
4157 #if defined(PLATFORM_EMSCRIPTEN)
4158 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4159 void *buffer, unsigned int size)
4161 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4163 if (response != NULL)
4165 HandleResponse_ApiRenamePlayer(response, data_raw);
4167 checked_free(response);
4171 Error("server response too large to handle (%d bytes)", size);
4174 FreeThreadData_ApiRenamePlayer(data_raw);
4177 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4178 int code, const char *status)
4180 Error("server failed to handle request: %d %s", code, status);
4182 FreeThreadData_ApiRenamePlayer(data_raw);
4185 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4186 int bytes, int size)
4188 // nothing to do here
4191 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4194 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4196 FreeThreadData_ApiRenamePlayer(data_raw);
4201 emscripten_async_wget2_data(request->uri,
4206 Emscripten_ApiRenamePlayer_Loaded,
4207 Emscripten_ApiRenamePlayer_Failed,
4208 Emscripten_ApiRenamePlayer_Progress);
4213 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4214 struct HttpResponse *response,
4217 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4220 if (!DoHttpRequest(request, response))
4222 Error("HTTP request failed: %s", GetHttpError());
4227 if (!HTTP_SUCCESS(response->status_code))
4229 Error("server failed to handle request: %d %s",
4230 response->status_code,
4231 response->status_text);
4236 HandleResponse_ApiRenamePlayer(response, data_raw);
4239 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4240 struct HttpResponse *response,
4243 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4245 FreeThreadData_ApiRenamePlayer(data_raw);
4249 static int ApiRenamePlayerThread(void *data_raw)
4251 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4252 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4254 program.api_thread_count++;
4256 #if defined(PLATFORM_EMSCRIPTEN)
4257 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4259 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4262 program.api_thread_count--;
4264 checked_free(request);
4265 checked_free(response);
4270 static void ApiRenamePlayerAsThread(void)
4272 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4274 ExecuteAsThread(ApiRenamePlayerThread,
4275 "ApiRenamePlayer", data,
4276 "rename player on server");
4280 // ============================================================================
4281 // reset player UUID API functions
4282 // ============================================================================
4284 struct ApiResetUUIDThreadData
4287 char *player_uuid_old;
4288 char *player_uuid_new;
4291 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4293 struct ApiResetUUIDThreadData *data =
4294 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4296 data->player_name = getStringCopy(setup.player_name);
4297 data->player_uuid_old = getStringCopy(setup.player_uuid);
4298 data->player_uuid_new = getStringCopy(uuid_new);
4303 static void FreeThreadData_ApiResetUUID(void *data_raw)
4305 struct ApiResetUUIDThreadData *data = data_raw;
4307 checked_free(data->player_name);
4308 checked_free(data->player_uuid_old);
4309 checked_free(data->player_uuid_new);
4313 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4316 struct ApiResetUUIDThreadData *data = data_raw;
4317 char *player_name_raw = data->player_name;
4318 char *player_uuid_old_raw = data->player_uuid_old;
4319 char *player_uuid_new_raw = data->player_uuid_new;
4321 request->hostname = setup.api_server_hostname;
4322 request->port = API_SERVER_PORT;
4323 request->method = API_SERVER_METHOD;
4324 request->uri = API_SERVER_URI_RESETUUID;
4326 char *player_name = getEscapedJSON(player_name_raw);
4327 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4328 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4330 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4333 " \"game_version\": \"%s\",\n"
4334 " \"game_platform\": \"%s\",\n"
4335 " \"name\": \"%s\",\n"
4336 " \"uuid_old\": \"%s\",\n"
4337 " \"uuid_new\": \"%s\"\n"
4339 getPasswordJSON(setup.api_server_password),
4340 getProgramRealVersionString(),
4341 getProgramPlatformString(),
4346 checked_free(player_name);
4347 checked_free(player_uuid_old);
4348 checked_free(player_uuid_new);
4350 ConvertHttpRequestBodyToServerEncoding(request);
4355 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4358 struct ApiResetUUIDThreadData *data = data_raw;
4360 // upgrade player UUID in server setup file
4361 setup.player_uuid = getStringCopy(data->player_uuid_new);
4362 setup.player_version = 2;
4364 SaveSetup_ServerSetup();
4367 #if defined(PLATFORM_EMSCRIPTEN)
4368 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4369 void *buffer, unsigned int size)
4371 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4373 if (response != NULL)
4375 HandleResponse_ApiResetUUID(response, data_raw);
4377 checked_free(response);
4381 Error("server response too large to handle (%d bytes)", size);
4384 FreeThreadData_ApiResetUUID(data_raw);
4387 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4388 int code, const char *status)
4390 Error("server failed to handle request: %d %s", code, status);
4392 FreeThreadData_ApiResetUUID(data_raw);
4395 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4396 int bytes, int size)
4398 // nothing to do here
4401 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4404 if (!SetRequest_ApiResetUUID(request, data_raw))
4406 FreeThreadData_ApiResetUUID(data_raw);
4411 emscripten_async_wget2_data(request->uri,
4416 Emscripten_ApiResetUUID_Loaded,
4417 Emscripten_ApiResetUUID_Failed,
4418 Emscripten_ApiResetUUID_Progress);
4423 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4424 struct HttpResponse *response,
4427 if (!SetRequest_ApiResetUUID(request, data_raw))
4430 if (!DoHttpRequest(request, response))
4432 Error("HTTP request failed: %s", GetHttpError());
4437 if (!HTTP_SUCCESS(response->status_code))
4439 Error("server failed to handle request: %d %s",
4440 response->status_code,
4441 response->status_text);
4446 HandleResponse_ApiResetUUID(response, data_raw);
4449 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4450 struct HttpResponse *response,
4453 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4455 FreeThreadData_ApiResetUUID(data_raw);
4459 static int ApiResetUUIDThread(void *data_raw)
4461 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4462 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4464 program.api_thread_count++;
4466 #if defined(PLATFORM_EMSCRIPTEN)
4467 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4469 ApiResetUUID_HttpRequest(request, response, data_raw);
4472 program.api_thread_count--;
4474 checked_free(request);
4475 checked_free(response);
4480 static void ApiResetUUIDAsThread(char *uuid_new)
4482 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4484 ExecuteAsThread(ApiResetUUIDThread,
4485 "ApiResetUUID", data,
4486 "reset UUID on server");
4490 // ============================================================================
4491 // type name functions
4492 // ============================================================================
4494 static TreeInfo *type_name_node = NULL;
4495 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4496 static int type_name_nr = 0;
4498 static int getPlayerNameColor(char *name)
4500 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4503 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4506 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4507 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4508 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4509 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4510 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4511 int font_width = getFontWidth(font_nr);
4513 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4515 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4517 pos->width = strlen(text) * font_width;
4518 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4520 DrawText(sx, sy, text, font_nr);
4523 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4525 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4527 *pos = *mci->pos_input;
4529 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4531 TreeInfo *ti = player_name_current;
4532 int first_entry = ti->cl_first;
4533 int entry_pos = first_entry + ti->cl_cursor;
4534 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4535 int xpos = MENU_SCREEN_START_XPOS;
4536 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4538 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4539 type_name_nr = entry_pos;
4541 strcpy(name, type_name_node->name);
4545 pos->width = MAX_PLAYER_NAME_LEN * 32;
4549 type_name_nr = user.nr;
4551 strcpy(name, setup.player_name);
4554 strcpy(type_name_last, name);
4556 if (strEqual(name, EMPTY_PLAYER_NAME))
4559 *xpos = strlen(name);
4562 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4564 // change name of edited user in global list of user names
4565 setString(&global.user_names[type_name_nr], name);
4567 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4569 TreeInfo *node = type_name_node;
4571 // change name of edited user in local menu tree structure
4572 setString(&node->name, name);
4573 setString(&node->name_sorting, name);
4575 node->color = getPlayerNameColor(name);
4576 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4580 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4583 boolean reset_setup = strEqual(name, "");
4584 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4585 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4588 strcpy(name, type_name_last);
4590 if (strEqual(name, ""))
4591 strcpy(name, EMPTY_PLAYER_NAME);
4593 setTypeNameValues_Name(name, pos);
4595 // if player name not changed, no further action required
4596 if (strEqual(name, type_name_last))
4599 // redraw player name before (possibly) opening request dialogs
4600 drawTypeNameText(name, pos, FALSE);
4602 int last_user_nr = user.nr;
4604 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4606 // save setup of currently active user (may differ from edited user)
4609 // temporarily change active user to edited user
4610 user.nr = type_name_nr;
4613 Request("Use current setup values for the new player?", REQ_ASK))
4615 // use current setup values for new user, but create new player UUID
4616 setup.player_uuid = getStringCopy(getUUID());
4620 // load setup for existing user (or start with defaults for new user)
4625 char *setup_filename = getSetupFilename();
4626 boolean setup_exists = fileExists(setup_filename);
4628 // change name of edited user in setup structure
4629 strcpy(setup.player_name, name);
4631 // save setup of edited user
4634 // change name of edited user on score server
4635 ApiRenamePlayerAsThread();
4637 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4641 if (Request("Reset setup values for this player?", REQ_ASK))
4643 // remove setup config file
4644 unlink(setup_filename);
4646 // set player name to default player name
4649 // update player name used by name typing functions
4650 strcpy(name, setup.player_name);
4652 setTypeNameValues_Name(name, pos);
4655 else if (remove_user && type_name_nr != 0)
4657 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4659 char *user_dir = getUserGameDataDir();
4660 char *user_dir_removed =
4661 getStringCat3WithSeparator(user_dir, "REMOVED",
4662 getCurrentTimestamp(), ".");
4664 if (rename(user_dir, user_dir_removed) != 0)
4665 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4667 checked_free(user_dir_removed);
4670 else if (create_user && type_name_nr != 0 && !setup_exists)
4672 if (Request("Create empty level set for the new player?", REQ_ASK))
4674 char *levelset_subdir = getNewUserLevelSubdir();
4676 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4678 AddUserLevelSetToLevelInfo(levelset_subdir);
4680 LevelDirTree *leveldir_current_last = leveldir_current;
4682 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4685 // set level number of newly created level set to default value
4686 LoadLevelSetup_SeriesInfo();
4688 // set newly created level set as current level set for new user
4689 SaveLevelSetup_LastSeries();
4690 SaveLevelSetup_SeriesInfo();
4692 leveldir_current = leveldir_current_last;
4696 Request("Creating new level set failed!", REQ_CONFIRM);
4701 // restore currently active user
4702 user.nr = last_user_nr;
4704 // restore setup of currently active user
4707 // restore last level set of currently active user
4708 LoadLevelSetup_LastSeries();
4709 LoadLevelSetup_SeriesInfo();
4713 static void HandleTypeNameExt(boolean initialize, Key key)
4715 static struct TextPosInfo pos_name = { 0 };
4716 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4717 static int xpos = 0;
4718 struct TextPosInfo *pos = &pos_name;
4719 char key_char = getValidConfigValueChar(getCharFromKey(key));
4720 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4721 boolean active = TRUE;
4725 getTypeNameValues(name, pos, &xpos);
4727 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4728 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4730 StartTextInput(sx, sy, pos->width, pos->height);
4732 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4734 name[xpos] = key_char;
4739 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4745 else if (key == KSYM_Return || key == KSYM_Escape)
4747 boolean changed = (key == KSYM_Return);
4751 setTypeNameValues(name, pos, changed);
4756 drawTypeNameText(name, pos, active);
4760 SetGameStatus(game_status_last_screen);
4762 if (game_status == GAME_MODE_MAIN)
4763 InitializeMainControls();
4767 static void DrawTypeName(void)
4769 HandleTypeNameExt(TRUE, 0);
4772 void HandleTypeName(Key key)
4774 HandleTypeNameExt(FALSE, key);
4778 // ============================================================================
4779 // tree menu functions
4780 // ============================================================================
4782 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4784 if (game_status != GAME_MODE_SETUP ||
4785 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4788 int max_text_size = 0;
4791 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4792 max_text_size = MAX(max_text_size, strlen(node->name));
4794 int num_entries = numTreeInfoInGroup(ti);
4795 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4796 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4797 int text_width = max_text_size * getFontWidth(font_nr);
4798 int button_width = SC_MENUBUTTON_XSIZE;
4799 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4800 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4801 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4802 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4803 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4804 int align_xoffset = MAX(0, align_xoffset_raw);
4806 return align_xoffset;
4809 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4811 if (game_status != GAME_MODE_SETUP ||
4812 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4815 int num_entries = numTreeInfoInGroup(ti);
4816 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4817 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4818 int font_height = getFontHeight(font_nr);
4819 int text_height = font_height * num_page_entries;
4820 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4821 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4822 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4823 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4824 int align_yoffset = MAX(0, align_yoffset_raw);
4826 return align_yoffset;
4829 static void DrawChooseTree(TreeInfo **ti_ptr)
4831 int fade_mask = REDRAW_FIELD;
4834 fade_mask = REDRAW_ALL;
4836 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4838 if (game_status == GAME_MODE_SETUP)
4842 else // GAME_MODE_LEVELS
4844 SetGameStatus(GAME_MODE_MAIN);
4854 FreeScreenGadgets();
4855 CreateScreenGadgets();
4857 if (game_status != game_status_last_screen)
4858 FadeMenuSoundsAndMusic();
4862 // needed if different viewport properties defined for this screen
4863 ChangeViewportPropertiesIfNeeded();
4865 if (game_status == GAME_MODE_NAMES)
4866 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4867 else if (game_status == GAME_MODE_LEVELNR)
4868 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4869 else if (game_status == GAME_MODE_LEVELS)
4870 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4871 else if (game_status == GAME_MODE_SCORES)
4872 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4876 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4878 // map gadgets for high score screen
4879 if (game_status == GAME_MODE_SCORES)
4880 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4882 MapScreenTreeGadgets(*ti_ptr);
4884 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4886 DrawMaskedBorder(fade_mask);
4888 if (game_status != game_status_last_screen)
4889 PlayMenuSoundsAndMusic();
4894 static int getChooseTreeFont(TreeInfo *node, boolean active)
4896 if (game_status == GAME_MODE_SCORES)
4897 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4899 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4902 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4904 int num_entries = numTreeInfoInGroup(ti);
4905 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4906 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4907 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4908 int first_entry = ti->cl_first;
4909 int entry_pos = first_entry + y;
4910 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4911 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4912 int font_nr = getChooseTreeFont(node, active);
4913 int font_xoffset = getFontDrawOffsetX(font_nr);
4914 int xpos = MENU_SCREEN_START_XPOS;
4915 int ypos = MENU_SCREEN_START_YPOS + y;
4916 int startdx = xpos * 32;
4917 int startdy = ypos * 32;
4918 int startx = amSX + startdx;
4919 int starty = amSY + startdy;
4920 int startx_text = startx + font_xoffset;
4921 int endx_text = amSX + screen_width;
4922 int max_text_size = endx_text - startx_text;
4923 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4924 char buffer[max_buffer_len + 1];
4926 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4928 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4929 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4930 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4931 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4932 int font_size_1 = getFontWidth(font_nr1);
4933 int font_size_3 = getFontWidth(font_nr3);
4934 int font_size_4 = getFontWidth(font_nr4);
4935 int text_size_1 = 3 * font_size_1;
4936 int text_size_4 = 5 * font_size_4;
4937 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4939 int dx2 = text_size_1;
4940 int dx3 = dx2 + font_size_1;
4941 int dx4 = screen_width - startdx - 2 * border - text_size_4;
4942 int num_dots = (dx4 - dx3) / font_size_3;
4943 int startx1 = startx + dx1;
4944 int startx2 = startx + dx2;
4945 int startx3 = startx + dx3;
4946 int startx4 = startx + dx4;
4947 int pos = node->pos;
4948 char *pos_text = getHallOfFameRankText(pos);
4949 char *dot_text = ".";
4952 DrawText(startx1, starty, pos_text, font_nr1);
4953 DrawText(startx2, starty, dot_text, font_nr1);
4955 for (i = 0; i < num_dots; i++)
4956 DrawText(startx3 + i * font_size_3, starty, dot_text, font_nr3);
4958 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4959 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4961 DrawText(startx4, starty, getHallOfFameScoreText(pos), font_nr4);
4965 strncpy(buffer, node->name, max_buffer_len);
4966 buffer[max_buffer_len] = '\0';
4968 DrawText(startx, starty, buffer, font_nr);
4972 static void drawChooseTreeHeadExt(int type, char *title_string)
4974 int yoffset_sets = MENU_TITLE1_YPOS;
4975 int yoffset_setup = 16;
4976 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4977 type == TREE_TYPE_LEVEL_DIR ||
4978 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4980 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4983 static void drawChooseTreeHead(TreeInfo *ti)
4985 drawChooseTreeHeadExt(ti->type, ti->infotext);
4988 static void drawChooseTreeList(TreeInfo *ti)
4990 int first_entry = ti->cl_first;
4991 int num_entries = numTreeInfoInGroup(ti);
4992 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4995 clearMenuListArea();
4997 for (i = 0; i < num_page_entries; i++)
4999 TreeInfo *node, *node_first;
5000 int entry_pos = first_entry + i;
5002 node_first = getTreeInfoFirstGroupEntry(ti);
5003 node = getTreeInfoFromPos(node_first, entry_pos);
5005 drawChooseTreeText(ti, i, FALSE);
5007 if (node->parent_link)
5008 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5009 else if (node->level_group)
5010 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5012 initCursor(i, IMG_MENU_BUTTON);
5014 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
5015 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5017 if (game_status == GAME_MODE_NAMES)
5018 drawChooseTreeEdit(i, FALSE);
5021 redraw_mask |= REDRAW_FIELD;
5024 static void drawChooseTreeInfo(TreeInfo *ti)
5026 int entry_pos = ti->cl_first + ti->cl_cursor;
5027 int last_redraw_mask = redraw_mask;
5028 int ypos = MENU_TITLE2_YPOS;
5029 int font_nr = FONT_TITLE_2;
5032 if (ti->type == TREE_TYPE_LEVEL_NR)
5033 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
5035 if (ti->type == TREE_TYPE_SCORE_ENTRY)
5036 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
5037 scores.last_level_nr);
5039 if (ti->type != TREE_TYPE_LEVEL_DIR)
5042 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
5043 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
5045 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
5047 if (node->parent_link)
5048 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
5049 node->node_parent->name);
5050 else if (node->level_group)
5051 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
5053 else if (ti->type == TREE_TYPE_LEVEL_DIR)
5054 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
5055 node->levels, (node->levels > 1 ? "levels" : "level"),
5058 // let BackToFront() redraw only what is needed
5059 redraw_mask = last_redraw_mask;
5060 for (x = 0; x < SCR_FIELDX; x++)
5061 MarkTileDirty(x, 1);
5064 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
5066 drawChooseTreeCursor(ti->cl_cursor, active);
5067 drawChooseTreeText(ti, ti->cl_cursor, active);
5070 static void drawChooseTreeScreen(TreeInfo *ti)
5072 drawChooseTreeHead(ti);
5073 drawChooseTreeList(ti);
5074 drawChooseTreeInfo(ti);
5075 drawChooseTreeCursorAndText(ti, TRUE);
5077 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
5079 // scroll bar and buttons may just have been added after reloading scores
5080 if (game_status == GAME_MODE_SCORES)
5081 MapScreenTreeGadgets(ti);
5084 static void drawChooseTreeScreen_Scores_NotAvailable(void)
5086 // dirty workaround to use spacing definitions from info screen
5087 info_mode = INFO_MODE_TITLE;
5089 char *text_info = "HighScores of Level %d";
5090 char *text_title = "Score information:";
5091 char *text_error = "No scores for this level.";
5092 char *text_foot = "Press any key or button for main menu";
5093 int font_info = FONT_TITLE_2;
5094 int font_title = FONT_INITIAL_3;
5095 int font_error = FONT_INITIAL_4;
5096 int font_foot = FONT_INITIAL_2;
5097 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
5098 int ystep_title = getMenuTextStep(spacing_title, font_title);
5099 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
5100 int ystart2 = ystart1 + ystep_title;
5101 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
5102 int ystart0 = MENU_TITLE2_YPOS;
5104 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
5105 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
5107 DrawTextSCentered(ystart1, font_title, text_title);
5108 DrawTextSCentered(ystart2, font_error, text_error);
5110 DrawTextSCentered(ybottom, font_foot, text_foot);
5113 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
5115 // set current tree entry to last added score entry
5116 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(scores.last_added));
5118 // if that fails, set current tree entry to first entry (back link)
5119 if (*ti_ptr == NULL)
5120 *ti_ptr = score_entries->node_group;
5122 int num_entries = numTreeInfoInGroup(*ti_ptr);
5123 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5124 int pos_score = getPosFromTreeInfo(*ti_ptr);
5125 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5126 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5128 (*ti_ptr)->cl_first = pos_first;
5129 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5134 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5137 TreeInfo *ti = *ti_ptr;
5138 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5139 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5140 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5141 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5142 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5144 int y = (ti != NULL ? ti->cl_cursor : 0);
5145 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5146 int num_entries = numTreeInfoInGroup(ti);
5147 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5148 boolean position_set_by_scrollbar = (dx == 999);
5149 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5150 boolean button_is_valid = (mx >= 0 && my >= 0);
5151 boolean button_screen_clicked = (button_action && button_is_valid);
5153 if (game_status == GAME_MODE_SCORES)
5155 if (server_scores.updated)
5157 // reload scores, using updated server score cache file
5158 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5160 server_scores.updated = FALSE;
5162 DrawHallOfFame_setScoreEntries();
5164 if (score_entries != NULL)
5166 ti = setHallOfFameActiveEntry(ti_ptr);
5168 if (button != MB_MENU_INITIALIZE)
5169 drawChooseTreeScreen(ti);
5173 if (score_entries == NULL)
5175 if (button == MB_MENU_INITIALIZE)
5177 drawChooseTreeScreen_Scores_NotAvailable();
5179 else if (button_screen_clicked)
5181 PlaySound(SND_MENU_ITEM_SELECTING);
5183 SetGameStatus(GAME_MODE_MAIN);
5192 if (button == MB_MENU_INITIALIZE)
5194 int num_entries = numTreeInfoInGroup(ti);
5195 int entry_pos = getPosFromTreeInfo(ti);
5197 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5198 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5200 if (game_status == GAME_MODE_SCORES)
5202 ti = setHallOfFameActiveEntry(ti_ptr);
5204 else if (ti->cl_first == -1)
5206 // only on initialization
5207 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5208 ti->cl_cursor = entry_pos - ti->cl_first;
5211 else if (ti->cl_cursor >= num_page_entries ||
5212 (num_entries > num_page_entries &&
5213 num_entries - ti->cl_first < num_page_entries))
5215 // only after change of list size (by custom graphic configuration)
5216 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5217 ti->cl_cursor = entry_pos - ti->cl_first;
5220 if (position_set_by_scrollbar)
5223 drawChooseTreeScreen(ti);
5227 else if (button == MB_MENU_LEAVE)
5229 if (game_status != GAME_MODE_SCORES)
5232 PlaySound(SND_MENU_ITEM_SELECTING);
5234 if (ti->node_parent)
5236 *ti_ptr = ti->node_parent;
5237 DrawChooseTree(ti_ptr);
5239 else if (game_status == GAME_MODE_SETUP)
5241 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5242 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5243 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5244 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5246 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5247 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5248 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5249 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5250 execSetupGraphics();
5251 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5252 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5253 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5255 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5256 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5257 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5258 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5259 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5260 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5261 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5262 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5269 if (game_status == GAME_MODE_LEVELNR)
5271 int new_level_nr = atoi(level_number_current->identifier);
5273 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5276 SetGameStatus(GAME_MODE_MAIN);
5284 if (mx || my) // mouse input
5286 x = (mx - amSX) / 32;
5287 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5289 if (game_status == GAME_MODE_NAMES)
5290 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5292 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5294 // move cursor instead of scrolling when already at start/end of list
5295 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5297 else if (dy == +1 * SCROLL_LINE &&
5298 ti->cl_first + num_page_entries == num_entries)
5301 // handle scrolling screen one line or page
5302 if (ti->cl_cursor + dy < 0 ||
5303 ti->cl_cursor + dy > num_page_entries - 1)
5305 boolean redraw = FALSE;
5307 if (ABS(dy) == SCROLL_PAGE)
5308 step = num_page_entries - 1;
5310 if (dy < 0 && ti->cl_first > 0)
5312 // scroll page/line up
5314 ti->cl_first -= step;
5315 if (ti->cl_first < 0)
5320 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5322 // scroll page/line down
5324 ti->cl_first += step;
5325 if (ti->cl_first + num_page_entries > num_entries)
5326 ti->cl_first = MAX(0, num_entries - num_page_entries);
5332 drawChooseTreeScreen(ti);
5337 // handle moving cursor one line
5338 y = ti->cl_cursor + dy;
5341 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5343 HandleHallOfFame_SelectLevel(1, dx);
5349 TreeInfo *node_first, *node_cursor;
5350 int entry_pos = ti->cl_first + y;
5352 node_first = getTreeInfoFirstGroupEntry(ti);
5353 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5355 if (node_cursor->node_group)
5359 PlaySound(SND_MENU_ITEM_SELECTING);
5361 node_cursor->cl_first = ti->cl_first;
5362 node_cursor->cl_cursor = ti->cl_cursor;
5363 *ti_ptr = node_cursor->node_group;
5364 DrawChooseTree(ti_ptr);
5369 else if (dx == -1 && ti->node_parent)
5373 PlaySound(SND_MENU_ITEM_SELECTING);
5375 *ti_ptr = ti->node_parent;
5376 DrawChooseTree(ti_ptr);
5381 if (!anyScrollbarGadgetActive() &&
5382 IN_VIS_MENU(x, y) &&
5383 mx < mx_right_border &&
5384 y >= 0 && y < num_page_entries)
5388 if (game_status == GAME_MODE_NAMES)
5390 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5391 drawChooseTreeEdit(y, TRUE);
5394 if (y != ti->cl_cursor)
5396 PlaySound(SND_MENU_ITEM_ACTIVATING);
5398 drawChooseTreeCursorAndText(ti, FALSE);
5402 drawChooseTreeCursorAndText(ti, TRUE);
5404 drawChooseTreeInfo(ti);
5408 if (game_status == GAME_MODE_SETUP)
5410 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5411 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5412 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5413 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5415 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5416 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5417 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5418 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5419 execSetupGraphics();
5420 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5421 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5422 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5424 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5425 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5426 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5427 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5428 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5429 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5430 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5431 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5440 TreeInfo *node_first, *node_cursor;
5441 int entry_pos = ti->cl_first + y;
5443 PlaySound(SND_MENU_ITEM_SELECTING);
5445 node_first = getTreeInfoFirstGroupEntry(ti);
5446 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5448 if (node_cursor->node_group)
5452 node_cursor->cl_first = ti->cl_first;
5453 node_cursor->cl_cursor = ti->cl_cursor;
5454 *ti_ptr = node_cursor->node_group;
5455 DrawChooseTree(ti_ptr);
5457 else if (node_cursor->parent_link)
5459 if (game_status != GAME_MODE_SCORES)
5462 *ti_ptr = node_cursor->node_parent;
5463 DrawChooseTree(ti_ptr);
5467 if (game_status != GAME_MODE_SCORES)
5470 node_cursor->cl_first = ti->cl_first;
5471 node_cursor->cl_cursor = ti->cl_cursor;
5472 *ti_ptr = node_cursor;
5474 if (ti->type == TREE_TYPE_LEVEL_DIR)
5476 LoadLevelSetup_SeriesInfo();
5478 SaveLevelSetup_LastSeries();
5479 SaveLevelSetup_SeriesInfo();
5483 if (game_status == GAME_MODE_SETUP)
5485 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5486 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5487 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5488 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5490 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5491 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5492 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5493 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5494 execSetupGraphics();
5495 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5496 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5497 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5499 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5500 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5501 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5502 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5503 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5504 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5505 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5506 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5513 if (game_status == GAME_MODE_LEVELNR)
5515 int new_level_nr = atoi(level_number_current->identifier);
5517 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5519 else if (game_status == GAME_MODE_LEVELS)
5521 // store level set if chosen from "last played level set" menu
5522 StoreLastPlayedLevels(leveldir_current);
5524 else if (game_status == GAME_MODE_NAMES)
5526 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5528 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5535 // change active user to selected user
5536 user.nr = entry_pos;
5538 // save number of new active user
5541 // load setup of new active user
5544 // load last level set of new active user
5545 LoadLevelSetup_LastSeries();
5546 LoadLevelSetup_SeriesInfo();
5548 // update list of last played level sets
5549 UpdateLastPlayedLevels_TreeInfo();
5553 ToggleFullscreenIfNeeded();
5554 ChangeWindowScalingIfNeeded();
5556 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5557 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5558 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5560 else if (game_status == GAME_MODE_SCORES)
5562 if (game_status_last_screen == GAME_MODE_PLAYING &&
5563 setup.auto_play_next_level && setup.increment_levels &&
5564 scores.last_level_nr < leveldir_current->last_level &&
5567 StartGameActions(network.enabled, setup.autorecord,
5573 SetGameStatus(GAME_MODE_SCOREINFO);
5575 DrawScoreInfo(node_cursor->pos);
5581 SetGameStatus(GAME_MODE_MAIN);
5589 if (game_status == GAME_MODE_SCORES)
5590 PlayMenuSoundIfLoop();
5593 void DrawChoosePlayerName(void)
5597 if (player_name != NULL)
5599 freeTreeInfo(player_name);
5604 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5606 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5607 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5610 ti->node_top = &player_name;
5611 ti->sort_priority = 10000 + value;
5612 ti->color = getPlayerNameColor(global.user_names[i]);
5614 snprintf(identifier, sizeof(identifier), "%d", value);
5615 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5617 setString(&ti->identifier, identifier);
5618 setString(&ti->name, name);
5619 setString(&ti->name_sorting, name);
5621 pushTreeInfo(&player_name, ti);
5624 // sort player entries by player number
5625 sortTreeInfo(&player_name);
5627 // set current player entry to selected player entry
5628 player_name_current =
5629 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5631 // if that fails, set current player name to first available name
5632 if (player_name_current == NULL)
5633 player_name_current = player_name;
5635 DrawChooseTree(&player_name_current);
5638 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5640 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5643 void DrawChooseLevelSet(void)
5645 DrawChooseTree(&leveldir_current);
5648 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5650 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5653 void DrawChooseLevelNr(void)
5657 if (level_number != NULL)
5659 freeTreeInfo(level_number);
5661 level_number = NULL;
5664 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5666 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5667 char identifier[32], name[64];
5670 // temporarily load level info to get level name
5671 LoadLevelInfoOnly(i);
5673 ti->node_top = &level_number;
5674 ti->sort_priority = 10000 + value;
5675 ti->color = (level.no_level_file ? FC_BLUE :
5676 LevelStats_getSolved(i) ? FC_GREEN :
5677 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5679 snprintf(identifier, sizeof(identifier), "%d", value);
5680 snprintf(name, sizeof(name), "%03d: %s", value,
5681 (level.no_level_file ? "(no file)" : level.name));
5683 setString(&ti->identifier, identifier);
5684 setString(&ti->name, name);
5685 setString(&ti->name_sorting, name);
5687 pushTreeInfo(&level_number, ti);
5690 // sort level number values to start with lowest level number
5691 sortTreeInfo(&level_number);
5693 // set current level number to current level number
5694 level_number_current =
5695 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5697 // if that also fails, set current level number to first available level
5698 if (level_number_current == NULL)
5699 level_number_current = level_number;
5701 DrawChooseTree(&level_number_current);
5704 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5706 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5709 static void DrawHallOfFame_setScoreEntries(void)
5711 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5714 if (score_entries != NULL)
5716 freeTreeInfo(score_entries);
5718 score_entries = NULL;
5721 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5723 // do not add empty score entries
5724 if (scores.entry[i].score == 0 &&
5725 scores.entry[i].time == 0)
5728 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5729 char identifier[32], name[64];
5732 ti->node_top = &score_entries;
5733 ti->sort_priority = 10000 + value;
5734 ti->color = FC_YELLOW;
5737 snprintf(identifier, sizeof(identifier), "%d", value);
5738 snprintf(name, sizeof(name), "%03d.", value + 1);
5740 setString(&ti->identifier, identifier);
5741 setString(&ti->name, name);
5742 setString(&ti->name_sorting, name);
5744 pushTreeInfo(&score_entries, ti);
5747 // sort score entries to start with highest score entry
5748 sortTreeInfo(&score_entries);
5750 // add top tree node to create back link to main menu
5751 score_entries = addTopTreeInfoNode(score_entries);
5753 // set current score entry to last added or highest score entry
5754 score_entry_current =
5755 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5757 // if that fails, set current score entry to first valid score entry
5758 if (score_entry_current == NULL)
5759 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5761 // ("score_entries" and "score_entry_current" may be NULL here)
5764 void DrawHallOfFame(int level_nr)
5766 scores.last_level_nr = level_nr;
5768 // (this is needed when called from GameEnd() after winning a game)
5769 KeyboardAutoRepeatOn();
5771 // (this is needed when called from GameEnd() after winning a game)
5772 SetDrawDeactivationMask(REDRAW_NONE);
5773 SetDrawBackgroundMask(REDRAW_FIELD);
5775 LoadLocalAndServerScore(level_nr, TRUE);
5777 DrawHallOfFame_setScoreEntries();
5779 if (scores.last_added >= 0)
5780 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5782 FadeSetEnterScreen();
5784 DrawChooseTree(&score_entry_current);
5787 static char *getHallOfFameRankText(int nr)
5789 boolean forced = (scores.force_last_added && nr == scores.last_added);
5791 return (forced ? "???" : int2str(nr + 1, 3));
5794 static char *getHallOfFameTimeText(int nr)
5796 static char score_text[10];
5797 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5798 int mm = (time_seconds / 60) % 60;
5799 int ss = (time_seconds % 60);
5801 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5806 static char *getHallOfFameScoreText(int nr)
5808 if (!level.rate_time_over_score)
5809 return int2str(scores.entry[nr].score, 5); // show normal score
5810 else if (level.use_step_counter)
5811 return int2str(scores.entry[nr].time, 5); // show number of steps
5813 return getHallOfFameTimeText(nr); // show playing time
5816 static void HandleHallOfFame_SelectLevel(int step, int direction)
5818 int old_level_nr = scores.last_level_nr;
5819 int new_level_nr = old_level_nr + step * direction;
5821 if (new_level_nr < leveldir_current->first_level)
5822 new_level_nr = leveldir_current->first_level;
5823 if (new_level_nr > leveldir_current->last_level)
5824 new_level_nr = leveldir_current->last_level;
5826 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5827 new_level_nr = leveldir_current->handicap_level;
5829 if (new_level_nr != old_level_nr)
5831 PlaySound(SND_MENU_ITEM_SELECTING);
5833 scores.last_level_nr = level_nr = new_level_nr;
5835 LoadLevel(level_nr);
5836 LoadLocalAndServerScore(level_nr, TRUE);
5838 DrawHallOfFame_setScoreEntries();
5840 // force remapping optional gadgets (especially scroll bar)
5841 UnmapScreenTreeGadgets();
5843 // redraw complete high score screen, as sub-title has changed
5846 // redraw level selection buttons (which have just been erased)
5847 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5849 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5851 SaveLevelSetup_SeriesInfo();
5855 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5857 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5860 static void DrawScoreInfo_Content(int entry_nr)
5862 struct ScoreEntry *entry = &scores.entry[entry_nr];
5863 char *pos_text = getHallOfFameRankText(entry_nr);
5864 int font_title = MENU_INFO_FONT_TITLE;
5865 int font_head = MENU_INFO_FONT_HEAD;
5866 int font_text = MENU_INFO_FONT_TEXT;
5867 int font_foot = MENU_INFO_FONT_FOOT;
5868 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5869 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5870 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5871 int xstep = getFontWidth(font_text);
5872 int ystep_title = getMenuTextStep(spacing_title, font_title);
5873 int ystep_para = getMenuTextStep(spacing_para, font_text);
5874 int ystep_line = getMenuTextStep(spacing_line, font_text);
5875 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5876 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5877 int xstart1 = mSX - SX + 2 * xstep;
5878 int xstart2 = mSX - SX + 13 * xstep;
5879 int font_width = getFontWidth(font_text);
5880 int font_height = getFontHeight(font_text);
5881 int pad_left = xstart2;
5882 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
5883 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5884 int max_lines_per_text = 5;
5889 // redraw score selection buttons (which have just been erased)
5890 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5892 drawChooseTreeHead(score_entries);
5893 drawChooseTreeInfo(score_entries);
5895 DrawTextSCentered(ystart, font_title, "Score Information:");
5896 ystart += ystep_title;
5898 DrawTextF(xstart1, ystart, font_head, "Level Set");
5899 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5900 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5901 TRUE, FALSE, FALSE);
5902 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5904 DrawTextF(xstart1, ystart, font_head, "Level");
5905 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5906 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5907 TRUE, FALSE, FALSE);
5908 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5910 DrawTextF(xstart1, ystart, font_head, "Rank");
5911 DrawTextF(xstart2, ystart, font_text, pos_text);
5912 ystart += ystep_line;
5914 DrawTextF(xstart1, ystart, font_head, "Player");
5915 DrawTextF(xstart2, ystart, font_text, entry->name);
5916 ystart += ystep_line;
5918 DrawTextF(xstart1, ystart, font_head, "Platform");
5919 DrawTextF(xstart2, ystart, font_text, entry->platform);
5920 ystart += ystep_line;
5922 DrawTextF(xstart1, ystart, font_head, "Version");
5923 DrawTextF(xstart2, ystart, font_text, entry->version);
5924 ystart += ystep_line;
5926 DrawTextF(xstart1, ystart, font_head, "Country");
5927 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5928 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5929 TRUE, FALSE, FALSE);
5930 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5932 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5933 DrawTextF(xstart2, ystart, font_text, entry->tape_date);
5934 ystart += ystep_line;
5936 if (level.use_step_counter)
5938 DrawTextF(xstart1, ystart, font_head, "Steps");
5939 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5940 ystart += ystep_line;
5944 DrawTextF(xstart1, ystart, font_head, "Time");
5945 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5946 ystart += ystep_line;
5949 if (!level.rate_time_over_score || entry->score > 0)
5951 DrawTextF(xstart1, ystart, font_head, "Score");
5952 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5953 ystart += ystep_line;
5956 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5959 static void DrawScoreInfo(int entry_nr)
5961 scores.last_entry_nr = entry_nr;
5963 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5967 FadeOut(REDRAW_FIELD);
5969 // map gadgets for score info screen
5970 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
5972 DrawScoreInfo_Content(entry_nr);
5974 FadeIn(REDRAW_FIELD);
5977 static void HandleScoreInfo_SelectScore(int step, int direction)
5979 int old_entry_nr = scores.last_entry_nr;
5980 int new_entry_nr = old_entry_nr + step * direction;
5981 int num_nodes = numTreeInfoInGroup(score_entry_current);
5982 int num_entries = num_nodes - 1; // score nodes only, without back link
5984 if (new_entry_nr < 0)
5986 if (new_entry_nr > num_entries - 1)
5987 new_entry_nr = num_entries - 1;
5989 if (new_entry_nr != old_entry_nr)
5991 scores.last_entry_nr = new_entry_nr;
5993 DrawScoreInfo_Content(new_entry_nr);
5997 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5999 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
6000 boolean button_is_valid = (mx >= 0 && my >= 0);
6001 boolean button_screen_clicked = (button_action && button_is_valid);
6003 if (button_screen_clicked)
6005 PlaySound(SND_MENU_ITEM_SELECTING);
6007 SetGameStatus(GAME_MODE_SCORES);
6009 DrawHallOfFame(level_nr);
6013 HandleScoreInfo_SelectScore(1, SIGN(dx ? dx : dy));
6017 static void HandleHallOfFame_SelectLevelOrScore(int step, int direction)
6019 if (game_status == GAME_MODE_SCORES)
6020 HandleHallOfFame_SelectLevel(step, direction);
6022 HandleScoreInfo_SelectScore(step, direction);
6026 // ============================================================================
6027 // setup screen functions
6028 // ============================================================================
6030 static struct TokenInfo *setup_info;
6031 static int num_setup_info; // number of setup entries shown on screen
6032 static int max_setup_info; // total number of setup entries in list
6034 static char *window_size_text;
6035 static char *scaling_type_text;
6036 static char *rendering_mode_text;
6037 static char *vsync_mode_text;
6038 static char *scroll_delay_text;
6039 static char *snapshot_mode_text;
6040 static char *game_speed_text;
6041 static char *scores_type_text;
6042 static char *network_server_text;
6043 static char *graphics_set_name;
6044 static char *sounds_set_name;
6045 static char *music_set_name;
6046 static char *volume_simple_text;
6047 static char *volume_loops_text;
6048 static char *volume_music_text;
6049 static char *touch_controls_text;
6050 static char *move_distance_text;
6051 static char *drop_distance_text;
6052 static char *transparency_text;
6053 static char *grid_size_text[2][2];
6055 static void execSetupMain(void)
6057 setup_mode = SETUP_MODE_MAIN;
6062 static void execSetupGame_setScoresType(void)
6064 if (scores_types == NULL)
6068 for (i = 0; scores_types_list[i].value != NULL; i++)
6070 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6071 char identifier[32], name[32];
6072 char *value = scores_types_list[i].value;
6073 char *text = scores_types_list[i].text;
6075 ti->node_top = &scores_types;
6076 ti->sort_priority = i;
6078 sprintf(identifier, "%s", value);
6079 sprintf(name, "%s", text);
6081 setString(&ti->identifier, identifier);
6082 setString(&ti->name, name);
6083 setString(&ti->name_sorting, name);
6084 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
6086 pushTreeInfo(&scores_types, ti);
6089 // sort scores type values to start with lowest scores type value
6090 sortTreeInfo(&scores_types);
6092 // set current scores type value to configured scores type value
6093 scores_type_current =
6094 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
6096 // if that fails, set current scores type to reliable default value
6097 if (scores_type_current == NULL)
6098 scores_type_current =
6099 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
6101 // if that also fails, set current scores type to first available value
6102 if (scores_type_current == NULL)
6103 scores_type_current = scores_types;
6106 setup.scores_in_highscore_list = scores_type_current->identifier;
6108 // needed for displaying scores type text instead of identifier
6109 scores_type_text = scores_type_current->name;
6112 static void execSetupGame_setGameSpeeds(boolean update_value)
6114 if (setup.game_speed_extended)
6116 game_speeds_list = game_speeds_list_extended;
6117 game_speeds = game_speeds_extended;
6121 game_speeds_list = game_speeds_list_normal;
6122 game_speeds = game_speeds_normal;
6125 if (game_speeds == NULL)
6129 for (i = 0; game_speeds_list[i].value != -1; i++)
6131 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6132 char identifier[32], name[32];
6133 int value = game_speeds_list[i].value;
6134 char *text = game_speeds_list[i].text;
6136 ti->node_top = &game_speeds;
6137 ti->sort_priority = 10000 - value;
6139 sprintf(identifier, "%d", value);
6140 sprintf(name, "%s", text);
6142 setString(&ti->identifier, identifier);
6143 setString(&ti->name, name);
6144 setString(&ti->name_sorting, name);
6145 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
6147 pushTreeInfo(&game_speeds, ti);
6150 // sort game speed values to start with slowest game speed
6151 sortTreeInfo(&game_speeds);
6153 update_value = TRUE;
6158 // set current game speed to configured game speed value
6159 game_speed_current =
6160 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6162 // if that fails, set current game speed to reliable default value
6163 if (game_speed_current == NULL)
6164 game_speed_current =
6165 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6167 // if that also fails, set current game speed to first available speed
6168 if (game_speed_current == NULL)
6169 game_speed_current = game_speeds;
6171 if (setup.game_speed_extended)
6172 game_speeds_extended = game_speeds;
6174 game_speeds_normal = game_speeds;
6177 setup.game_frame_delay = atoi(game_speed_current->identifier);
6179 // needed for displaying game speed text instead of identifier
6180 game_speed_text = game_speed_current->name;
6183 static void execSetupGame_setScrollDelays(void)
6185 if (scroll_delays == NULL)
6189 for (i = 0; scroll_delays_list[i].value != -1; i++)
6191 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6192 char identifier[32], name[32];
6193 int value = scroll_delays_list[i].value;
6194 char *text = scroll_delays_list[i].text;
6196 ti->node_top = &scroll_delays;
6197 ti->sort_priority = value;
6199 sprintf(identifier, "%d", value);
6200 sprintf(name, "%s", text);
6202 setString(&ti->identifier, identifier);
6203 setString(&ti->name, name);
6204 setString(&ti->name_sorting, name);
6205 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6207 pushTreeInfo(&scroll_delays, ti);
6210 // sort scroll delay values to start with lowest scroll delay value
6211 sortTreeInfo(&scroll_delays);
6213 // set current scroll delay value to configured scroll delay value
6214 scroll_delay_current =
6215 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6217 // if that fails, set current scroll delay to reliable default value
6218 if (scroll_delay_current == NULL)
6219 scroll_delay_current =
6220 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6222 // if that also fails, set current scroll delay to first available value
6223 if (scroll_delay_current == NULL)
6224 scroll_delay_current = scroll_delays;
6227 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6229 // needed for displaying scroll delay text instead of identifier
6230 scroll_delay_text = scroll_delay_current->name;
6233 static void execSetupGame_setSnapshotModes(void)
6235 if (snapshot_modes == NULL)
6239 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6241 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6242 char identifier[32], name[32];
6243 char *value = snapshot_modes_list[i].value;
6244 char *text = snapshot_modes_list[i].text;
6246 ti->node_top = &snapshot_modes;
6247 ti->sort_priority = i;
6249 sprintf(identifier, "%s", value);
6250 sprintf(name, "%s", text);
6252 setString(&ti->identifier, identifier);
6253 setString(&ti->name, name);
6254 setString(&ti->name_sorting, name);
6255 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6257 pushTreeInfo(&snapshot_modes, ti);
6260 // sort snapshot mode values to start with lowest snapshot mode value
6261 sortTreeInfo(&snapshot_modes);
6263 // set current snapshot mode value to configured snapshot mode value
6264 snapshot_mode_current =
6265 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6267 // if that fails, set current snapshot mode to reliable default value
6268 if (snapshot_mode_current == NULL)
6269 snapshot_mode_current =
6270 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6272 // if that also fails, set current snapshot mode to first available value
6273 if (snapshot_mode_current == NULL)
6274 snapshot_mode_current = snapshot_modes;
6277 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6279 // needed for displaying snapshot mode text instead of identifier
6280 snapshot_mode_text = snapshot_mode_current->name;
6283 static void execSetupGame_setNetworkServerText(void)
6285 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6287 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6291 strncpy(network_server_hostname, setup.network_server_hostname,
6292 MAX_SETUP_TEXT_INPUT_LEN);
6293 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6296 // needed for displaying network server text instead of identifier
6297 network_server_text = network_server_hostname;
6300 static void execSetupGame(void)
6302 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6304 execSetupGame_setGameSpeeds(FALSE);
6305 execSetupGame_setScoresType();
6306 execSetupGame_setScrollDelays();
6307 execSetupGame_setSnapshotModes();
6309 execSetupGame_setNetworkServerText();
6311 if (!setup.provide_uploading_tapes)
6312 setHideSetupEntry(execOfferUploadTapes);
6314 setup_mode = SETUP_MODE_GAME;
6318 // check if vsync needs to be disabled for this game speed to work
6319 if (check_vsync_mode)
6320 DisableVsyncIfNeeded();
6323 static void execSetupChooseScoresType(void)
6325 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6330 static void execSetupChooseGameSpeed(void)
6332 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6337 static void execSetupChooseScrollDelay(void)
6339 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6344 static void execSetupChooseSnapshotMode(void)
6346 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6351 static void execSetupEngines(void)
6353 setup_mode = SETUP_MODE_ENGINES;
6358 static void execSetupEditor(void)
6360 setup_mode = SETUP_MODE_EDITOR;
6365 static void execSetupGraphics_setWindowSizes(boolean update_list)
6367 if (window_sizes != NULL && update_list)
6369 freeTreeInfo(window_sizes);
6371 window_sizes = NULL;
6374 if (window_sizes == NULL)
6376 boolean current_window_size_found = FALSE;
6379 for (i = 0; window_sizes_list[i].value != -1; i++)
6381 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6382 char identifier[32], name[32];
6383 int value = window_sizes_list[i].value;
6384 char *text = window_sizes_list[i].text;
6386 ti->node_top = &window_sizes;
6387 ti->sort_priority = value;
6389 sprintf(identifier, "%d", value);
6390 sprintf(name, "%s", text);
6392 setString(&ti->identifier, identifier);
6393 setString(&ti->name, name);
6394 setString(&ti->name_sorting, name);
6395 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6397 pushTreeInfo(&window_sizes, ti);
6399 if (value == setup.window_scaling_percent)
6400 current_window_size_found = TRUE;
6403 if (!current_window_size_found)
6405 // add entry for non-preset window scaling value
6407 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6408 char identifier[32], name[32];
6409 int value = setup.window_scaling_percent;
6411 ti->node_top = &window_sizes;
6412 ti->sort_priority = value;
6414 sprintf(identifier, "%d", value);
6415 sprintf(name, "%d %% (Current)", value);
6417 setString(&ti->identifier, identifier);
6418 setString(&ti->name, name);
6419 setString(&ti->name_sorting, name);
6420 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6422 pushTreeInfo(&window_sizes, ti);
6425 // sort window size values to start with lowest window size value
6426 sortTreeInfo(&window_sizes);
6428 // set current window size value to configured window size value
6429 window_size_current =
6430 getTreeInfoFromIdentifier(window_sizes,
6431 i_to_a(setup.window_scaling_percent));
6433 // if that fails, set current window size to reliable default value
6434 if (window_size_current == NULL)
6435 window_size_current =
6436 getTreeInfoFromIdentifier(window_sizes,
6437 i_to_a(STD_WINDOW_SCALING_PERCENT));
6439 // if that also fails, set current window size to first available value
6440 if (window_size_current == NULL)
6441 window_size_current = window_sizes;
6444 setup.window_scaling_percent = atoi(window_size_current->identifier);
6446 // needed for displaying window size text instead of identifier
6447 window_size_text = window_size_current->name;
6450 static void execSetupGraphics_setScalingTypes(void)
6452 if (scaling_types == NULL)
6456 for (i = 0; scaling_types_list[i].value != NULL; i++)
6458 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6459 char identifier[32], name[32];
6460 char *value = scaling_types_list[i].value;
6461 char *text = scaling_types_list[i].text;
6463 ti->node_top = &scaling_types;
6464 ti->sort_priority = i;
6466 sprintf(identifier, "%s", value);
6467 sprintf(name, "%s", text);
6469 setString(&ti->identifier, identifier);
6470 setString(&ti->name, name);
6471 setString(&ti->name_sorting, name);
6472 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6474 pushTreeInfo(&scaling_types, ti);
6477 // sort scaling type values to start with lowest scaling type value
6478 sortTreeInfo(&scaling_types);
6480 // set current scaling type value to configured scaling type value
6481 scaling_type_current =
6482 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6484 // if that fails, set current scaling type to reliable default value
6485 if (scaling_type_current == NULL)
6486 scaling_type_current =
6487 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6489 // if that also fails, set current scaling type to first available value
6490 if (scaling_type_current == NULL)
6491 scaling_type_current = scaling_types;
6494 setup.window_scaling_quality = scaling_type_current->identifier;
6496 // needed for displaying scaling type text instead of identifier
6497 scaling_type_text = scaling_type_current->name;
6500 static void execSetupGraphics_setRenderingModes(void)
6502 if (rendering_modes == NULL)
6506 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6508 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6509 char identifier[32], name[32];
6510 char *value = rendering_modes_list[i].value;
6511 char *text = rendering_modes_list[i].text;
6513 ti->node_top = &rendering_modes;
6514 ti->sort_priority = i;
6516 sprintf(identifier, "%s", value);
6517 sprintf(name, "%s", text);
6519 setString(&ti->identifier, identifier);
6520 setString(&ti->name, name);
6521 setString(&ti->name_sorting, name);
6522 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6524 pushTreeInfo(&rendering_modes, ti);
6527 // sort rendering mode values to start with lowest rendering mode value
6528 sortTreeInfo(&rendering_modes);
6530 // set current rendering mode value to configured rendering mode value
6531 rendering_mode_current =
6532 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6534 // if that fails, set current rendering mode to reliable default value
6535 if (rendering_mode_current == NULL)
6536 rendering_mode_current =
6537 getTreeInfoFromIdentifier(rendering_modes,
6538 STR_SPECIAL_RENDERING_DEFAULT);
6540 // if that also fails, set current rendering mode to first available one
6541 if (rendering_mode_current == NULL)
6542 rendering_mode_current = rendering_modes;
6545 setup.screen_rendering_mode = rendering_mode_current->identifier;
6547 // needed for displaying rendering mode text instead of identifier
6548 rendering_mode_text = rendering_mode_current->name;
6551 static void execSetupGraphics_setVsyncModes(boolean update_value)
6553 if (vsync_modes == NULL)
6557 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6559 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6560 char identifier[32], name[32];
6561 char *value = vsync_modes_list[i].value;
6562 char *text = vsync_modes_list[i].text;
6564 ti->node_top = &vsync_modes;
6565 ti->sort_priority = i;
6567 sprintf(identifier, "%s", value);
6568 sprintf(name, "%s", text);
6570 setString(&ti->identifier, identifier);
6571 setString(&ti->name, name);
6572 setString(&ti->name_sorting, name);
6573 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6575 pushTreeInfo(&vsync_modes, ti);
6578 // sort vsync mode values to start with lowest vsync mode value
6579 sortTreeInfo(&vsync_modes);
6581 update_value = TRUE;
6586 // set current vsync mode value to configured vsync mode value
6587 vsync_mode_current =
6588 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6590 // if that fails, set current vsync mode to reliable default value
6591 if (vsync_mode_current == NULL)
6592 vsync_mode_current =
6593 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6595 // if that also fails, set current vsync mode to first available one
6596 if (vsync_mode_current == NULL)
6597 vsync_mode_current = vsync_modes;
6600 setup.vsync_mode = vsync_mode_current->identifier;
6602 // needed for displaying vsync mode text instead of identifier
6603 vsync_mode_text = vsync_mode_current->name;
6606 static void execSetupGraphics(void)
6608 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6610 // update "setup.window_scaling_percent" from list selection
6611 // (in this case, window scaling was changed on setup screen)
6612 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6613 execSetupGraphics_setWindowSizes(FALSE);
6615 // update "setup.vsync_mode" from list selection
6616 // (in this case, vsync mode was changed on setup screen)
6617 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6618 execSetupGraphics_setVsyncModes(FALSE);
6620 // update list selection from "setup.window_scaling_percent"
6621 // (window scaling may have changed by resizing the window)
6622 execSetupGraphics_setWindowSizes(TRUE);
6624 // update list selection from "setup.vsync_mode"
6625 // (vsync_mode may have changed by re-creating the renderer)
6626 execSetupGraphics_setVsyncModes(TRUE);
6628 execSetupGraphics_setScalingTypes();
6629 execSetupGraphics_setRenderingModes();
6631 setup_mode = SETUP_MODE_GRAPHICS;
6635 // check if game speed is high enough for 60 Hz vsync to work
6636 if (check_game_speed)
6637 ModifyGameSpeedIfNeeded();
6639 // window scaling may have changed at this point
6640 ChangeWindowScalingIfNeeded();
6642 // window scaling quality may have changed at this point
6643 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6644 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6646 // screen rendering mode may have changed at this point
6647 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6649 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6650 int video_vsync_mode = video.vsync_mode;
6652 // screen vsync mode may have changed at this point
6653 ChangeVsyncModeIfNeeded();
6655 // check if setting vsync mode to selected value failed
6656 if (setup_vsync_mode != video_vsync_mode &&
6657 setup_vsync_mode != video.vsync_mode)
6659 // changing vsync mode to selected value failed -- reset displayed value
6660 execSetupGraphics_setVsyncModes(TRUE);
6662 Request("Setting VSync failed!", REQ_CONFIRM);
6668 static void execSetupChooseWindowSize(void)
6670 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6675 static void execSetupChooseScalingType(void)
6677 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6682 static void execSetupChooseRenderingMode(void)
6684 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6689 static void execSetupChooseVsyncMode(void)
6691 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6696 static void execSetupChooseVolumeSimple(void)
6698 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6703 static void execSetupChooseVolumeLoops(void)
6705 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6710 static void execSetupChooseVolumeMusic(void)
6712 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6717 static void execSetupSound(void)
6719 if (volumes_simple == NULL)
6721 boolean current_volume_simple_found = FALSE;
6724 for (i = 0; volumes_list[i].value != -1; i++)
6726 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6727 char identifier[32], name[32];
6728 int value = volumes_list[i].value;
6729 char *text = volumes_list[i].text;
6731 ti->node_top = &volumes_simple;
6732 ti->sort_priority = value;
6734 sprintf(identifier, "%d", value);
6735 sprintf(name, "%s", text);
6737 setString(&ti->identifier, identifier);
6738 setString(&ti->name, name);
6739 setString(&ti->name_sorting, name);
6740 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6742 pushTreeInfo(&volumes_simple, ti);
6744 if (value == setup.volume_simple)
6745 current_volume_simple_found = TRUE;
6748 if (!current_volume_simple_found)
6750 // add entry for non-preset volume value
6752 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6753 char identifier[32], name[32];
6754 int value = setup.volume_simple;
6756 ti->node_top = &volumes_simple;
6757 ti->sort_priority = value;
6759 sprintf(identifier, "%d", value);
6760 sprintf(name, "%d %% (Current)", value);
6762 setString(&ti->identifier, identifier);
6763 setString(&ti->name, name);
6764 setString(&ti->name_sorting, name);
6765 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6767 pushTreeInfo(&volumes_simple, ti);
6770 // sort volume values to start with lowest volume value
6771 sortTreeInfo(&volumes_simple);
6773 // set current volume value to configured volume value
6774 volume_simple_current =
6775 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6777 // if that fails, set current volume to reliable default value
6778 if (volume_simple_current == NULL)
6779 volume_simple_current =
6780 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6782 // if that also fails, set current volume to first available value
6783 if (volume_simple_current == NULL)
6784 volume_simple_current = volumes_simple;
6787 if (volumes_loops == NULL)
6789 boolean current_volume_loops_found = FALSE;
6792 for (i = 0; volumes_list[i].value != -1; i++)
6794 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6795 char identifier[32], name[32];
6796 int value = volumes_list[i].value;
6797 char *text = volumes_list[i].text;
6799 ti->node_top = &volumes_loops;
6800 ti->sort_priority = value;
6802 sprintf(identifier, "%d", value);
6803 sprintf(name, "%s", text);
6805 setString(&ti->identifier, identifier);
6806 setString(&ti->name, name);
6807 setString(&ti->name_sorting, name);
6808 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6810 pushTreeInfo(&volumes_loops, ti);
6812 if (value == setup.volume_loops)
6813 current_volume_loops_found = TRUE;
6816 if (!current_volume_loops_found)
6818 // add entry for non-preset volume value
6820 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6821 char identifier[32], name[32];
6822 int value = setup.volume_loops;
6824 ti->node_top = &volumes_loops;
6825 ti->sort_priority = value;
6827 sprintf(identifier, "%d", value);
6828 sprintf(name, "%d %% (Current)", value);
6830 setString(&ti->identifier, identifier);
6831 setString(&ti->name, name);
6832 setString(&ti->name_sorting, name);
6833 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6835 pushTreeInfo(&volumes_loops, ti);
6838 // sort volume values to start with lowest volume value
6839 sortTreeInfo(&volumes_loops);
6841 // set current volume value to configured volume value
6842 volume_loops_current =
6843 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6845 // if that fails, set current volume to reliable default value
6846 if (volume_loops_current == NULL)
6847 volume_loops_current =
6848 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6850 // if that also fails, set current volume to first available value
6851 if (volume_loops_current == NULL)
6852 volume_loops_current = volumes_loops;
6855 if (volumes_music == NULL)
6857 boolean current_volume_music_found = FALSE;
6860 for (i = 0; volumes_list[i].value != -1; i++)
6862 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6863 char identifier[32], name[32];
6864 int value = volumes_list[i].value;
6865 char *text = volumes_list[i].text;
6867 ti->node_top = &volumes_music;
6868 ti->sort_priority = value;
6870 sprintf(identifier, "%d", value);
6871 sprintf(name, "%s", text);
6873 setString(&ti->identifier, identifier);
6874 setString(&ti->name, name);
6875 setString(&ti->name_sorting, name);
6876 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6878 pushTreeInfo(&volumes_music, ti);
6880 if (value == setup.volume_music)
6881 current_volume_music_found = TRUE;
6884 if (!current_volume_music_found)
6886 // add entry for non-preset volume value
6888 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6889 char identifier[32], name[32];
6890 int value = setup.volume_music;
6892 ti->node_top = &volumes_music;
6893 ti->sort_priority = value;
6895 sprintf(identifier, "%d", value);
6896 sprintf(name, "%d %% (Current)", value);
6898 setString(&ti->identifier, identifier);
6899 setString(&ti->name, name);
6900 setString(&ti->name_sorting, name);
6901 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6903 pushTreeInfo(&volumes_music, ti);
6906 // sort volume values to start with lowest volume value
6907 sortTreeInfo(&volumes_music);
6909 // set current volume value to configured volume value
6910 volume_music_current =
6911 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6913 // if that fails, set current volume to reliable default value
6914 if (volume_music_current == NULL)
6915 volume_music_current =
6916 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6918 // if that also fails, set current volume to first available value
6919 if (volume_music_current == NULL)
6920 volume_music_current = volumes_music;
6923 setup.volume_simple = atoi(volume_simple_current->identifier);
6924 setup.volume_loops = atoi(volume_loops_current->identifier);
6925 setup.volume_music = atoi(volume_music_current->identifier);
6927 // needed for displaying volume text instead of identifier
6928 volume_simple_text = volume_simple_current->name;
6929 volume_loops_text = volume_loops_current->name;
6930 volume_music_text = volume_music_current->name;
6932 setup_mode = SETUP_MODE_SOUND;
6937 static void execSetupChooseTouchControls(void)
6939 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6944 static void execSetupChooseMoveDistance(void)
6946 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6951 static void execSetupChooseDropDistance(void)
6953 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6958 static void execSetupChooseTransparency(void)
6960 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6965 static void execSetupChooseGridXSize_0(void)
6967 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6972 static void execSetupChooseGridYSize_0(void)
6974 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6979 static void execSetupChooseGridXSize_1(void)
6981 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6986 static void execSetupChooseGridYSize_1(void)
6988 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6993 static void execSetupConfigureVirtualButtons(void)
6995 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6997 ConfigureVirtualButtons();
6999 setup_mode = SETUP_MODE_TOUCH;
7004 static void execSetupTouch(void)
7008 if (touch_controls == NULL)
7010 for (i = 0; touch_controls_list[i].value != NULL; i++)
7012 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7013 char identifier[32], name[32];
7014 char *value = touch_controls_list[i].value;
7015 char *text = touch_controls_list[i].text;
7017 ti->node_top = &touch_controls;
7018 ti->sort_priority = i;
7020 sprintf(identifier, "%s", value);
7021 sprintf(name, "%s", text);
7023 setString(&ti->identifier, identifier);
7024 setString(&ti->name, name);
7025 setString(&ti->name_sorting, name);
7026 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
7028 pushTreeInfo(&touch_controls, ti);
7031 // sort touch control values to start with lowest touch control value
7032 sortTreeInfo(&touch_controls);
7034 // set current touch control value to configured touch control value
7035 touch_control_current =
7036 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
7038 // if that fails, set current touch control to reliable default value
7039 if (touch_control_current == NULL)
7040 touch_control_current =
7041 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
7043 // if that also fails, set current touch control to first available value
7044 if (touch_control_current == NULL)
7045 touch_control_current = touch_controls;
7048 if (move_distances == NULL)
7050 for (i = 0; distances_list[i].value != -1; i++)
7052 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7053 char identifier[32], name[32];
7054 int value = distances_list[i].value;
7055 char *text = distances_list[i].text;
7057 ti->node_top = &move_distances;
7058 ti->sort_priority = value;
7060 sprintf(identifier, "%d", value);
7061 sprintf(name, "%s", text);
7063 setString(&ti->identifier, identifier);
7064 setString(&ti->name, name);
7065 setString(&ti->name_sorting, name);
7066 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
7068 pushTreeInfo(&move_distances, ti);
7071 // sort distance values to start with lowest distance value
7072 sortTreeInfo(&move_distances);
7074 // set current distance value to configured distance value
7075 move_distance_current =
7076 getTreeInfoFromIdentifier(move_distances,
7077 i_to_a(setup.touch.move_distance));
7079 // if that fails, set current distance to reliable default value
7080 if (move_distance_current == NULL)
7081 move_distance_current =
7082 getTreeInfoFromIdentifier(move_distances,
7083 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
7085 // if that also fails, set current distance to first available value
7086 if (move_distance_current == NULL)
7087 move_distance_current = move_distances;
7090 if (drop_distances == NULL)
7092 for (i = 0; distances_list[i].value != -1; i++)
7094 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7095 char identifier[32], name[32];
7096 int value = distances_list[i].value;
7097 char *text = distances_list[i].text;
7099 ti->node_top = &drop_distances;
7100 ti->sort_priority = value;
7102 sprintf(identifier, "%d", value);
7103 sprintf(name, "%s", text);
7105 setString(&ti->identifier, identifier);
7106 setString(&ti->name, name);
7107 setString(&ti->name_sorting, name);
7108 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
7110 pushTreeInfo(&drop_distances, ti);
7113 // sort distance values to start with lowest distance value
7114 sortTreeInfo(&drop_distances);
7116 // set current distance value to configured distance value
7117 drop_distance_current =
7118 getTreeInfoFromIdentifier(drop_distances,
7119 i_to_a(setup.touch.drop_distance));
7121 // if that fails, set current distance to reliable default value
7122 if (drop_distance_current == NULL)
7123 drop_distance_current =
7124 getTreeInfoFromIdentifier(drop_distances,
7125 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
7127 // if that also fails, set current distance to first available value
7128 if (drop_distance_current == NULL)
7129 drop_distance_current = drop_distances;
7132 if (transparencies == NULL)
7134 for (i = 0; transparencies_list[i].value != -1; i++)
7136 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7137 char identifier[32], name[32];
7138 int value = transparencies_list[i].value;
7139 char *text = transparencies_list[i].text;
7141 ti->node_top = &transparencies;
7142 ti->sort_priority = value;
7144 sprintf(identifier, "%d", value);
7145 sprintf(name, "%s", text);
7147 setString(&ti->identifier, identifier);
7148 setString(&ti->name, name);
7149 setString(&ti->name_sorting, name);
7150 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
7152 pushTreeInfo(&transparencies, ti);
7155 // sort transparency values to start with lowest transparency value
7156 sortTreeInfo(&transparencies);
7158 // set current transparency value to configured transparency value
7159 transparency_current =
7160 getTreeInfoFromIdentifier(transparencies,
7161 i_to_a(setup.touch.transparency));
7163 // if that fails, set current transparency to reliable default value
7164 if (transparency_current == NULL)
7165 transparency_current =
7166 getTreeInfoFromIdentifier(transparencies,
7167 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7169 // if that also fails, set current transparency to first available value
7170 if (transparency_current == NULL)
7171 transparency_current = transparencies;
7174 for (i = 0; i < 2; i++)
7176 for (j = 0; j < 2; j++)
7178 if (grid_sizes[i][j] == NULL)
7180 for (k = 0; grid_sizes_list[k].value != -1; k++)
7182 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7183 char identifier[32], name[32];
7184 int value = grid_sizes_list[k].value;
7185 char *text = grid_sizes_list[k].text;
7187 ti->node_top = &grid_sizes[i][j];
7188 ti->sort_priority = value;
7190 sprintf(identifier, "%d", value);
7191 sprintf(name, "%s", text);
7193 setString(&ti->identifier, identifier);
7194 setString(&ti->name, name);
7195 setString(&ti->name_sorting, name);
7196 setString(&ti->infotext,
7199 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7200 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7202 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7203 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7205 pushTreeInfo(&grid_sizes[i][j], ti);
7208 // sort grid size values to start with lowest grid size value
7209 sortTreeInfo(&grid_sizes[i][j]);
7211 // set current grid size value to configured grid size value
7212 grid_size_current[i][j] =
7213 getTreeInfoFromIdentifier(grid_sizes[i][j],
7215 setup.touch.grid_xsize[i] :
7216 setup.touch.grid_ysize[i]));
7218 // if that fails, set current grid size to reliable default value
7219 if (grid_size_current[i][j] == NULL)
7220 grid_size_current[i][j] =
7221 getTreeInfoFromIdentifier(grid_sizes[i][j],
7223 DEFAULT_GRID_XSIZE(i) :
7224 DEFAULT_GRID_YSIZE(i)));
7226 // if that also fails, set current grid size to first available value
7227 if (grid_size_current[i][j] == NULL)
7228 grid_size_current[i][j] = grid_sizes[i][j];
7233 setup.touch.control_type = touch_control_current->identifier;
7234 setup.touch.move_distance = atoi(move_distance_current->identifier);
7235 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7236 setup.touch.transparency = atoi(transparency_current->identifier);
7238 for (i = 0; i < 2; i++)
7240 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7241 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7243 if (i == GRID_ACTIVE_NR())
7245 overlay.grid_xsize = setup.touch.grid_xsize[i];
7246 overlay.grid_ysize = setup.touch.grid_ysize[i];
7250 // needed for displaying value text instead of identifier
7251 touch_controls_text = touch_control_current->name;
7252 move_distance_text = move_distance_current->name;
7253 drop_distance_text = drop_distance_current->name;
7254 transparency_text = transparency_current->name;
7256 for (i = 0; i < 2; i++)
7257 for (j = 0; j < 2; j++)
7258 grid_size_text[i][j] = grid_size_current[i][j]->name;
7260 setup_mode = SETUP_MODE_TOUCH;
7265 static void execSetupArtwork(void)
7267 static ArtworkDirTree *gfx_last_valid = NULL;
7268 static ArtworkDirTree *snd_last_valid = NULL;
7269 static ArtworkDirTree *mus_last_valid = NULL;
7271 // current artwork directory may be invalid (level group, parent link)
7272 if (!validLevelSeries(artwork.gfx_current))
7273 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7274 if (!validLevelSeries(artwork.snd_current))
7275 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7276 if (!validLevelSeries(artwork.mus_current))
7277 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7279 // store valid artwork directory information
7280 gfx_last_valid = artwork.gfx_current;
7281 snd_last_valid = artwork.snd_current;
7282 mus_last_valid = artwork.mus_current;
7285 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7286 artwork.gfx_current->subdir,
7287 artwork.gfx_current->fullpath,
7288 artwork.gfx_current->basepath);
7291 setup.graphics_set = artwork.gfx_current->identifier;
7292 setup.sounds_set = artwork.snd_current->identifier;
7293 setup.music_set = artwork.mus_current->identifier;
7295 // needed if last screen (setup choice) changed graphics, sounds or music
7296 ReloadCustomArtwork(0);
7298 // needed for displaying artwork name instead of artwork identifier
7299 graphics_set_name = artwork.gfx_current->name;
7300 sounds_set_name = artwork.snd_current->name;
7301 music_set_name = artwork.mus_current->name;
7303 setup_mode = SETUP_MODE_ARTWORK;
7308 static void execSetupChooseGraphics(void)
7310 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7315 static void execSetupChooseSounds(void)
7317 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7322 static void execSetupChooseMusic(void)
7324 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7329 static void execSetupInput(void)
7331 setup_mode = SETUP_MODE_INPUT;
7336 static void execSetupShortcuts(void)
7338 setup_mode = SETUP_MODE_SHORTCUTS;
7343 static void execSetupShortcuts1(void)
7345 setup_mode = SETUP_MODE_SHORTCUTS_1;
7350 static void execSetupShortcuts2(void)
7352 setup_mode = SETUP_MODE_SHORTCUTS_2;
7357 static void execSetupShortcuts3(void)
7359 setup_mode = SETUP_MODE_SHORTCUTS_3;
7364 static void execSetupShortcuts4(void)
7366 setup_mode = SETUP_MODE_SHORTCUTS_4;
7371 static void execSetupShortcuts5(void)
7373 setup_mode = SETUP_MODE_SHORTCUTS_5;
7378 static void execExitSetup(void)
7380 SetGameStatus(GAME_MODE_MAIN);
7385 static void execSaveAndExitSetup(void)
7391 static void execGadgetNetworkServer(void)
7393 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7394 struct GadgetInfo *gi = screen_gadget[gadget_id];
7396 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7397 network_server_hostname[0] = '\0';
7399 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7403 ClickOnGadget(gi, MB_LEFTBUTTON);
7406 static void execOfferUploadTapes(void)
7411 static void ToggleNetworkModeIfNeeded(void)
7413 int font_title = FONT_TITLE_1;
7414 int font_foot = FC_BLUE;
7415 int ystart = mSY - SY + 16;
7416 int ybottom = mSY - SY + SYSIZE - 20;
7417 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7419 if (setup.network_mode == network.enabled)
7422 network.enabled = setup.network_mode;
7424 FadeOut(REDRAW_ALL);
7428 DrawTextSCentered(ystart, font_title, text);
7432 if (network.enabled)
7433 InitNetworkServer();
7435 DisconnectFromNetworkServer();
7437 DrawTextSCentered(ybottom, font_foot,
7438 "Press any key or button for setup menu");
7440 WaitForEventToContinue();
7445 static void ToggleGameSpeedsListIfNeeded(void)
7447 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7449 if (setup.game_speed_extended == using_game_speeds_extended)
7452 // try to match similar values when changing game speeds list
7453 if (setup.game_speed_extended)
7454 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7455 setup.game_frame_delay == 30 ? 29 :
7456 setup.game_frame_delay);
7458 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7459 setup.game_frame_delay == 16 ? 15 :
7460 setup.game_frame_delay >= 29 ? 30 :
7461 setup.game_frame_delay <= 10 ? 10 :
7462 setup.game_frame_delay);
7464 execSetupGame_setGameSpeeds(TRUE);
7469 static void ToggleUseApiServerIfNeeded(void)
7471 if (runtime.use_api_server == setup.use_api_server)
7474 runtime.use_api_server = setup.use_api_server;
7476 if (runtime.use_api_server)
7477 CheckApiServerTasks();
7480 static void ModifyGameSpeedIfNeeded(void)
7482 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7483 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7487 char *game_speed_text = "Fast";
7488 int game_speed_value = 15;
7490 if (setup.game_speed_extended)
7492 game_speed_text = "60 fps";
7493 game_speed_value = 16;
7496 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7498 // set game speed to existing list value that is fast enough for vsync
7499 setup.game_frame_delay = game_speed_value;
7501 execSetupGame_setGameSpeeds(TRUE);
7503 Request(message, REQ_CONFIRM);
7506 static void DisableVsyncIfNeeded(void)
7508 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7509 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7510 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7513 // disable vsync for the selected game speed to work
7514 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7516 execSetupGraphics_setVsyncModes(TRUE);
7518 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7524 void *related_value;
7525 } hide_related_entry_list[] =
7527 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7528 { &setup.scores_in_highscore_list, &scores_type_text },
7530 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7531 { &setup.game_frame_delay, &game_speed_text },
7533 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7534 { &setup.scroll_delay_value, &scroll_delay_text },
7536 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7537 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7539 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7540 { &setup.window_scaling_percent, &window_size_text },
7542 { &setup.window_scaling_quality, execSetupChooseScalingType },
7543 { &setup.window_scaling_quality, &scaling_type_text },
7545 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7546 { &setup.screen_rendering_mode, &rendering_mode_text },
7548 { &setup.vsync_mode, execSetupChooseVsyncMode },
7549 { &setup.vsync_mode, &vsync_mode_text },
7551 { &setup.graphics_set, execSetupChooseGraphics },
7552 { &setup.graphics_set, &graphics_set_name },
7554 { &setup.sounds_set, execSetupChooseSounds },
7555 { &setup.sounds_set, &sounds_set_name },
7557 { &setup.music_set, execSetupChooseMusic },
7558 { &setup.music_set, &music_set_name },
7560 { &setup.volume_simple, execSetupChooseVolumeSimple },
7561 { &setup.volume_simple, &volume_simple_text },
7563 { &setup.volume_loops, execSetupChooseVolumeLoops },
7564 { &setup.volume_loops, &volume_loops_text },
7566 { &setup.volume_music, execSetupChooseVolumeMusic },
7567 { &setup.volume_music, &volume_music_text },
7569 { &setup.touch.control_type, execSetupChooseTouchControls },
7570 { &setup.touch.control_type, &touch_controls_text },
7572 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7573 { &setup.touch.move_distance, &move_distance_text },
7575 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7576 { &setup.touch.drop_distance, &drop_distance_text },
7578 { &setup.touch.transparency, execSetupChooseTransparency },
7579 { &setup.touch.transparency, &transparency_text },
7581 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7582 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7584 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7585 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7587 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7588 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7590 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7591 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7593 { &setup.internal.menu_game, execSetupGame },
7594 { &setup.internal.menu_engines, execSetupEngines },
7595 { &setup.internal.menu_editor, execSetupEditor },
7596 { &setup.internal.menu_graphics, execSetupGraphics },
7597 { &setup.internal.menu_sound, execSetupSound },
7598 { &setup.internal.menu_artwork, execSetupArtwork },
7599 { &setup.internal.menu_input, execSetupInput },
7600 { &setup.internal.menu_touch, execSetupTouch },
7601 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7602 { &setup.internal.menu_exit, execExitSetup },
7603 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7608 void setHideRelatedSetupEntries(void)
7612 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7613 if (hideSetupEntry(hide_related_entry_list[i].value))
7614 setHideSetupEntry(hide_related_entry_list[i].related_value);
7617 static struct TokenInfo setup_info_main[] =
7619 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7620 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7621 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7622 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7623 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7624 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7625 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7626 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7627 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7628 { TYPE_EMPTY, NULL, "" },
7629 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7630 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7635 static struct TokenInfo setup_info_game[] =
7637 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7638 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7639 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7640 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7641 { TYPE_STRING, &network_server_text, "" },
7642 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7643 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7644 { TYPE_STRING, &scores_type_text, "" },
7645 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7646 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7647 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7648 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7649 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7650 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7651 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7652 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7653 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7654 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7655 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7656 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7657 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7658 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7659 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7660 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7661 { TYPE_STRING, &game_speed_text, "" },
7662 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7664 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7665 { TYPE_STRING, &scroll_delay_text, "" },
7667 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7668 { TYPE_STRING, &snapshot_mode_text, "" },
7669 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7670 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7671 { TYPE_EMPTY, NULL, "" },
7672 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7677 static struct TokenInfo setup_info_engines[] =
7679 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7680 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7681 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7682 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7683 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7684 { TYPE_EMPTY, NULL, "" },
7685 { TYPE_HEADLINE, NULL, "Supaplex" },
7686 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7687 { TYPE_EMPTY, NULL, "" },
7688 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7693 static struct TokenInfo setup_info_editor[] =
7696 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7697 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7698 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7699 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7700 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7701 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7702 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7703 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7704 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7705 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7707 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7708 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7710 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7712 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7713 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7714 { TYPE_EMPTY, NULL, "" },
7716 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7717 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7718 { TYPE_EMPTY, NULL, "" },
7720 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7721 { TYPE_EMPTY, NULL, "" },
7722 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7723 { TYPE_EMPTY, NULL, "" },
7724 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7729 static struct TokenInfo setup_info_graphics[] =
7731 #if !defined(PLATFORM_ANDROID)
7732 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7733 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7734 { TYPE_STRING, &window_size_text, "" },
7735 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7736 { TYPE_STRING, &scaling_type_text, "" },
7737 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7738 { TYPE_STRING, &rendering_mode_text, "" },
7741 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7742 { TYPE_STRING, &scroll_delay_text, "" },
7744 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7745 { TYPE_STRING, &vsync_mode_text, "" },
7746 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7747 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7748 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7749 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7750 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7751 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7752 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7753 { TYPE_EMPTY, NULL, "" },
7754 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7759 static struct TokenInfo setup_info_sound[] =
7761 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7762 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7763 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7764 { TYPE_EMPTY, NULL, "" },
7765 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7766 { TYPE_STRING, &volume_simple_text, "" },
7767 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7768 { TYPE_STRING, &volume_loops_text, "" },
7769 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7770 { TYPE_STRING, &volume_music_text, "" },
7771 { TYPE_EMPTY, NULL, "" },
7772 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7777 static struct TokenInfo setup_info_artwork[] =
7779 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7780 { TYPE_STRING, &graphics_set_name, "" },
7781 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7782 { TYPE_STRING, &sounds_set_name, "" },
7783 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7784 { TYPE_STRING, &music_set_name, "" },
7785 { TYPE_EMPTY, NULL, "" },
7786 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7787 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7788 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7789 { TYPE_EMPTY, NULL, "" },
7790 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7795 static struct TokenInfo setup_info_input[] =
7797 { TYPE_SWITCH, NULL, "Player:" },
7798 { TYPE_SWITCH, NULL, "Device:" },
7799 { TYPE_SWITCH, NULL, "" },
7800 { TYPE_SKIPPABLE, NULL, "" },
7801 { TYPE_EMPTY, NULL, "" },
7802 { TYPE_EMPTY, NULL, "" },
7803 { TYPE_EMPTY, NULL, "" },
7804 { TYPE_EMPTY, NULL, "" },
7805 { TYPE_EMPTY, NULL, "" },
7806 { TYPE_EMPTY, NULL, "" },
7807 { TYPE_EMPTY, NULL, "" },
7808 { TYPE_EMPTY, NULL, "" },
7809 { TYPE_SKIPPABLE, NULL, "" },
7810 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7815 static struct TokenInfo setup_info_touch[] =
7817 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7818 { TYPE_STRING, &touch_controls_text, "" },
7819 { TYPE_EMPTY, NULL, "" },
7820 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7825 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7827 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7828 { TYPE_STRING, &touch_controls_text, "" },
7829 { TYPE_EMPTY, NULL, "" },
7830 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7831 { TYPE_STRING, &grid_size_text[0][0], "" },
7832 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7833 { TYPE_STRING, &grid_size_text[0][1], "" },
7834 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7835 { TYPE_STRING, &transparency_text, "" },
7836 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7837 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7838 { TYPE_EMPTY, NULL, "" },
7839 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7840 { TYPE_EMPTY, NULL, "" },
7841 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7846 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7848 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7849 { TYPE_STRING, &touch_controls_text, "" },
7850 { TYPE_EMPTY, NULL, "" },
7851 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7852 { TYPE_STRING, &grid_size_text[1][0], "" },
7853 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7854 { TYPE_STRING, &grid_size_text[1][1], "" },
7855 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7856 { TYPE_STRING, &transparency_text, "" },
7857 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7858 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7859 { TYPE_EMPTY, NULL, "" },
7860 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7861 { TYPE_EMPTY, NULL, "" },
7862 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7867 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7869 setup_info_touch_virtual_buttons_0,
7870 setup_info_touch_virtual_buttons_1
7873 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7875 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7876 { TYPE_STRING, &touch_controls_text, "" },
7877 { TYPE_EMPTY, NULL, "" },
7878 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7879 { TYPE_STRING, &move_distance_text, "" },
7880 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7881 { TYPE_STRING, &drop_distance_text, "" },
7882 { TYPE_EMPTY, NULL, "" },
7883 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7888 static struct TokenInfo setup_info_shortcuts[] =
7890 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7891 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7892 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7893 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7894 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7895 { TYPE_EMPTY, NULL, "" },
7896 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7901 static struct TokenInfo setup_info_shortcuts_1[] =
7903 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7904 { TYPE_KEY, &setup.shortcut.save_game, "" },
7905 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7906 { TYPE_KEY, &setup.shortcut.load_game, "" },
7907 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7908 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7909 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7910 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7911 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7912 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7913 { TYPE_EMPTY, NULL, "" },
7914 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7915 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7916 { TYPE_EMPTY, NULL, "" },
7917 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7922 static struct TokenInfo setup_info_shortcuts_2[] =
7924 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7925 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7926 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7927 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7928 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7929 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7930 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7931 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7932 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7933 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7934 { TYPE_EMPTY, NULL, "" },
7935 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7940 static struct TokenInfo setup_info_shortcuts_3[] =
7942 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7943 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7944 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7945 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7946 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7947 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7948 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7949 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7950 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7951 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7952 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7953 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7954 { TYPE_EMPTY, NULL, "" },
7955 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7960 static struct TokenInfo setup_info_shortcuts_4[] =
7962 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7963 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7964 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7965 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7966 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7967 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7968 { TYPE_EMPTY, NULL, "" },
7969 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7974 static struct TokenInfo setup_info_shortcuts_5[] =
7976 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7977 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7978 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7979 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7980 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7981 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7982 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7983 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7984 { TYPE_EMPTY, NULL, "" },
7985 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7990 static Key getSetupKey(void)
7992 Key key = KSYM_UNDEFINED;
7993 boolean got_key_event = FALSE;
7995 while (!got_key_event)
7999 if (NextValidEvent(&event))
8003 case EVENT_KEYPRESS:
8005 key = GetEventKey((KeyEvent *)&event, TRUE);
8007 // press 'Escape' or 'Enter' to keep the existing key binding
8008 if (key == KSYM_Escape || key == KSYM_Return)
8009 key = KSYM_UNDEFINED; // keep old value
8011 got_key_event = TRUE;
8015 case EVENT_KEYRELEASE:
8016 key_joystick_mapping = 0;
8020 HandleOtherEvents(&event);
8031 static int getSetupValueFont(int type, void *value)
8033 if (type & TYPE_GHOSTED)
8034 return FONT_OPTION_OFF;
8035 else if (type & TYPE_KEY)
8036 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
8037 else if (type & TYPE_STRING)
8038 return FONT_VALUE_2;
8039 else if (type & TYPE_ECS_AGA)
8040 return FONT_VALUE_1;
8041 else if (type & TYPE_BOOLEAN_STYLE)
8042 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
8043 else if (type & TYPE_YES_NO_AUTO)
8044 return (*(int *)value == AUTO ? FONT_OPTION_ON :
8045 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
8046 else if (type & TYPE_PLAYER)
8047 return FONT_VALUE_1;
8049 return FONT_VALUE_1;
8052 static int getSetupValueFontNarrow(int type, int font_nr)
8054 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
8055 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
8056 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
8060 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
8062 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8063 struct TokenInfo *si = &setup_info[si_pos];
8064 boolean font_draw_xoffset_modified = FALSE;
8065 boolean scrollbar_needed = (num_setup_info < max_setup_info);
8066 int font_draw_xoffset_old = -1;
8067 int xoffset = (scrollbar_needed ? -1 : 0);
8068 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
8069 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
8070 int xpos = menu_screen_value_xpos;
8071 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
8072 int startx = mSX + xpos * 32;
8073 int starty = mSY + ypos * 32;
8074 int type = si->type;
8075 void *value = si->value;
8076 char *value_string = getSetupValue(type, value);
8077 int font_nr_default = getSetupValueFont(type, value);
8078 int font_width_default = getFontWidth(font_nr_default);
8079 int font_nr = font_nr_default;
8082 if (value_string == NULL)
8085 if (type & TYPE_KEY)
8087 xpos = MENU_SCREEN_START_XPOS;
8089 if (type & TYPE_QUERY)
8090 value_string = "<press key>";
8092 else if (type & TYPE_STRING)
8094 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
8096 xpos = MENU_SCREEN_START_XPOS;
8098 if (strlen(value_string) > max_value_len)
8099 value_string[max_value_len] = '\0';
8101 else if (type & TYPE_YES_NO_AUTO)
8103 xpos = menu_screen_value_xpos - 1;
8105 else if (type & TYPE_PLAYER)
8107 int displayed_player_nr = *(int *)value + 1;
8109 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
8112 startx = mSX + xpos * 32;
8113 starty = mSY + ypos * 32;
8115 // special check if right-side setup values moved left due to scrollbar
8116 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
8118 int max_menu_text_length = 26; // maximum text length for classic menu
8119 int font_xoffset = getFontDrawOffsetX(font_nr);
8120 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8121 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8122 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8123 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
8125 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
8127 // when using narrow font, left-shifting text "auto" not needed
8128 if (type & TYPE_YES_NO_AUTO)
8132 startx = mSX + xpos * 32;
8134 font_nr = getSetupValueFontNarrow(type, font_nr);
8138 // downward compatibility correction for Juergen Bonhagen's menu settings
8139 if (setup_mode != SETUP_MODE_INPUT)
8141 int max_menu_text_length_big = (menu_screen_value_xpos -
8142 MENU_SCREEN_START_XPOS);
8143 int max_menu_text_length_medium = max_menu_text_length_big * 2;
8144 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
8145 int font1_xoffset = getFontDrawOffsetX(font_nr);
8146 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
8147 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8148 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8149 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8150 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8151 boolean correct_font_draw_xoffset = FALSE;
8153 if (xpos == MENU_SCREEN_START_XPOS &&
8154 startx + font1_xoffset < text_startx + text_font_xoffset)
8155 correct_font_draw_xoffset = TRUE;
8157 if (xpos == menu_screen_value_xpos &&
8158 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8159 correct_font_draw_xoffset = TRUE;
8161 // check if setup value would overlap with setup text when printed
8162 // (this can happen for extreme/wrong values for font draw offset)
8163 if (correct_font_draw_xoffset)
8165 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8166 font_draw_xoffset_modified = TRUE;
8168 if (type & TYPE_KEY)
8169 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8170 else if (!(type & TYPE_STRING))
8171 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8172 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8176 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
8177 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
8179 DrawText(startx, starty, value_string, font_nr);
8181 if (type & TYPE_PLAYER)
8183 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8184 int player_nr = *(int *)value;
8185 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8186 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8187 int startx2 = startx + xoff;
8188 int starty2 = starty + yoff;
8190 if (DrawingOnBackground(startx2, starty2))
8191 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8193 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8194 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8197 if (font_draw_xoffset_modified)
8198 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8201 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8203 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8204 struct TokenInfo *si = &setup_info[si_pos];
8206 if (si->type & TYPE_BOOLEAN_STYLE)
8208 *(boolean *)si->value ^= TRUE;
8210 else if (si->type & TYPE_YES_NO_AUTO)
8214 (*(int *)si->value == AUTO ? TRUE :
8215 *(int *)si->value == TRUE ? FALSE : AUTO) :
8216 (*(int *)si->value == TRUE ? AUTO :
8217 *(int *)si->value == AUTO ? FALSE : TRUE));
8219 else if (si->type & TYPE_KEY)
8223 si->type |= TYPE_QUERY;
8224 drawSetupValue(screen_pos, setup_info_pos_raw);
8225 si->type &= ~TYPE_QUERY;
8227 key = getSetupKey();
8228 if (key != KSYM_UNDEFINED)
8229 *(Key *)si->value = key;
8231 else if (si->type & TYPE_PLAYER)
8233 int player_nr = *(int *)si->value;
8238 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8240 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8243 drawSetupValue(screen_pos, setup_info_pos_raw);
8245 // fullscreen state may have changed at this point
8246 if (si->value == &setup.fullscreen)
8247 ToggleFullscreenIfNeeded();
8249 // network mode may have changed at this point
8250 if (si->value == &setup.network_mode)
8251 ToggleNetworkModeIfNeeded();
8253 // API server mode may have changed at this point
8254 if (si->value == &setup.use_api_server)
8255 ToggleUseApiServerIfNeeded();
8257 // game speed list may have changed at this point
8258 if (si->value == &setup.game_speed_extended)
8259 ToggleGameSpeedsListIfNeeded();
8262 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8264 static struct TokenInfo *setup_info_final = NULL;
8269 // determine maximum list size of target list
8270 while (setup_info_orig[list_size++].type != 0);
8272 // free, allocate and clear memory for target list
8273 checked_free(setup_info_final);
8274 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8276 // copy setup info list without setup entries marked as hidden
8277 for (i = 0; setup_info_orig[i].type != 0; i++)
8279 // skip setup entries configured to be hidden
8280 if (hideSetupEntry(setup_info_orig[i].value))
8283 // skip skippable setup entries if screen is lower than usual
8284 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8285 setup_info_orig[i].type == TYPE_SKIPPABLE)
8288 setup_info_final[list_pos++] = setup_info_orig[i];
8291 return setup_info_final;
8294 static void DrawSetupScreen_Generic(void)
8296 int fade_mask = REDRAW_FIELD;
8297 boolean redraw_all = FALSE;
8298 char *title_string = NULL;
8302 fade_mask = REDRAW_ALL;
8305 FadeMenuSoundsAndMusic();
8307 FreeScreenGadgets();
8308 CreateScreenGadgets();
8310 if (redraw_mask & REDRAW_ALL)
8315 // needed if different viewport properties defined for setup screen
8316 ChangeViewportPropertiesIfNeeded();
8318 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8322 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8324 if (setup_mode == SETUP_MODE_MAIN)
8326 setup_info = setup_info_main;
8327 title_string = STR_SETUP_MAIN;
8329 else if (setup_mode == SETUP_MODE_GAME)
8331 setup_info = setup_info_game;
8332 title_string = STR_SETUP_GAME;
8334 else if (setup_mode == SETUP_MODE_ENGINES)
8336 setup_info = setup_info_engines;
8337 title_string = STR_SETUP_ENGINES;
8339 else if (setup_mode == SETUP_MODE_EDITOR)
8341 setup_info = setup_info_editor;
8342 title_string = STR_SETUP_EDITOR;
8344 else if (setup_mode == SETUP_MODE_GRAPHICS)
8346 setup_info = setup_info_graphics;
8347 title_string = STR_SETUP_GRAPHICS;
8349 else if (setup_mode == SETUP_MODE_SOUND)
8351 setup_info = setup_info_sound;
8352 title_string = STR_SETUP_SOUND;
8354 else if (setup_mode == SETUP_MODE_ARTWORK)
8356 setup_info = setup_info_artwork;
8357 title_string = STR_SETUP_ARTWORK;
8359 else if (setup_mode == SETUP_MODE_TOUCH)
8361 setup_info = setup_info_touch;
8362 title_string = STR_SETUP_TOUCH;
8364 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8365 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8366 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8367 setup_info = setup_info_touch_wipe_gestures;
8369 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8371 setup_info = setup_info_shortcuts;
8372 title_string = STR_SETUP_SHORTCUTS;
8374 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8376 setup_info = setup_info_shortcuts_1;
8377 title_string = STR_SETUP_SHORTCUTS;
8379 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8381 setup_info = setup_info_shortcuts_2;
8382 title_string = STR_SETUP_SHORTCUTS;
8384 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8386 setup_info = setup_info_shortcuts_3;
8387 title_string = STR_SETUP_SHORTCUTS;
8389 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8391 setup_info = setup_info_shortcuts_4;
8392 title_string = STR_SETUP_SHORTCUTS;
8394 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8396 setup_info = setup_info_shortcuts_5;
8397 title_string = STR_SETUP_SHORTCUTS;
8400 // use modified setup info without setup entries marked as hidden
8401 setup_info = getSetupInfoFinal(setup_info);
8403 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8405 // determine maximal number of setup entries that can be displayed on screen
8407 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8410 // determine maximal number of setup entries available for this setup screen
8412 for (i = 0; setup_info[i].type != 0; i++)
8415 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8417 MapScreenGadgets(max_setup_info);
8420 redraw_mask = fade_mask = REDRAW_ALL;
8422 DrawMaskedBorder(fade_mask);
8427 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8429 menu_info = setup_info;
8431 HandleMenuScreen(mx, my, dx, dy, button,
8432 setup_mode, num_setup_info, max_setup_info);
8435 static void DrawSetupScreen_Input(void)
8439 FadeOut(REDRAW_FIELD);
8443 setup_info = getSetupInfoFinal(setup_info_input);
8445 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8447 for (i = 0; setup_info[i].type != 0; i++)
8449 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8450 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8451 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8452 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8453 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8454 initCursor(i, IMG_MENU_BUTTON);
8456 DrawCursorAndText_Setup(i, -1, FALSE);
8459 // create gadgets for setup input menu screen
8460 FreeScreenGadgets();
8461 CreateScreenGadgets();
8463 // map gadgets for setup input menu screen
8464 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8466 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8468 FadeIn(REDRAW_FIELD);
8471 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8473 if (device_name == NULL)
8476 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8479 if (strlen(device_name) > 1)
8481 char c1 = device_name[strlen(device_name) - 1];
8482 char c2 = device_name[strlen(device_name) - 2];
8484 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8485 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8488 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8489 strlen(device_name));
8492 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8495 static struct SetupKeyboardInfo custom_key;
8502 { &custom_key.left, "Axis/Pad Left" },
8503 { &custom_key.right, "Axis/Pad Right" },
8504 { &custom_key.up, "Axis/Pad Up" },
8505 { &custom_key.down, "Axis/Pad Down" },
8506 { &custom_key.snap, "Button 1/A/X" },
8507 { &custom_key.drop, "Button 2/B/Y" }
8509 static char *joystick_name[MAX_PLAYERS] =
8516 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8517 int font_nr_info = FONT_MENU_1;
8518 int font_nr_name = FONT_VALUE_OLD;
8519 int font_nr_on = FONT_VALUE_1;
8520 int font_nr_off = FONT_VALUE_OLD;
8523 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8525 font_nr_info = FONT_MENU_2;
8526 font_nr_on = FONT_VALUE_NARROW;
8527 font_nr_off = FONT_VALUE_OLD_NARROW;
8530 custom_key = setup.input[player_nr].key;
8532 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8533 FONT_INPUT_1_ACTIVE);
8535 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8537 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8538 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8540 if (setup.input[player_nr].use_joystick)
8542 char *device_name = setup.input[player_nr].joy.device_name;
8543 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8544 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8545 char *text = joystick_name[joystick_nr];
8546 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8548 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8549 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8553 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8554 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8557 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8558 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8562 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8563 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8564 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8565 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8567 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8568 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8569 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8570 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8571 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8572 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8574 for (i = 0; i < 6; i++)
8576 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8578 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8580 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8581 (setup.input[player_nr].use_joystick ?
8583 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8587 static int input_player_nr = 0;
8589 static void HandleSetupScreen_Input_Player(int step, int direction)
8591 int old_player_nr = input_player_nr;
8594 new_player_nr = old_player_nr + step * direction;
8595 if (new_player_nr < 0)
8597 if (new_player_nr > MAX_PLAYERS - 1)
8598 new_player_nr = MAX_PLAYERS - 1;
8600 if (new_player_nr != old_player_nr)
8602 input_player_nr = new_player_nr;
8604 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8608 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8610 static int choice = 0;
8613 int pos_start = SETUPINPUT_SCREEN_POS_START;
8614 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8615 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8616 int pos_end = SETUPINPUT_SCREEN_POS_END;
8618 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8622 for (i = 0; setup_info_input[i].type != 0; i++)
8624 // adjust menu structure according to skipped setup entries
8625 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8633 if (button == MB_MENU_INITIALIZE)
8635 // input setup menu may have changed size due to graphics configuration
8636 if (choice >= pos_empty1)
8639 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8641 DrawCursorAndText_Setup(choice, -1, TRUE);
8645 else if (button == MB_MENU_LEAVE)
8647 setup_mode = SETUP_MODE_MAIN;
8654 if (mx || my) // mouse input
8656 x = (mx - mSX) / 32;
8657 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8659 else if (dx || dy) // keyboard input
8661 if (dx && choice == 0)
8662 x = (dx < 0 ? 10 : 12);
8663 else if ((dx && choice == 1) ||
8664 (dx == -1 && choice == pos_end))
8665 button = MB_MENU_CHOICE;
8669 if (y >= pos_empty1 && y <= pos_empty2)
8670 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8673 if (y == 0 && dx != 0 && button)
8675 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8677 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8678 y >= pos_start && y <= pos_end &&
8679 !(y >= pos_empty1 && y <= pos_empty2))
8685 DrawCursorAndText_Setup(choice, -1, FALSE);
8686 DrawCursorAndText_Setup(y, -1, TRUE);
8688 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8697 char *device_name = setup.input[input_player_nr].joy.device_name;
8699 if (!setup.input[input_player_nr].use_joystick)
8701 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8703 setJoystickDeviceToNr(device_name, new_device_nr);
8704 setup.input[input_player_nr].use_joystick = TRUE;
8708 int device_nr = getJoystickNrFromDeviceName(device_name);
8709 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8711 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8712 setup.input[input_player_nr].use_joystick = FALSE;
8714 setJoystickDeviceToNr(device_name, new_device_nr);
8717 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8721 if (setup.input[input_player_nr].use_joystick)
8722 ConfigureJoystick(input_player_nr);
8724 CustomizeKeyboard(input_player_nr);
8726 else if (y == pos_end)
8732 setup_mode = SETUP_MODE_MAIN;
8739 static boolean CustomizeKeyboardMain(int player_nr)
8743 boolean finished = FALSE;
8744 static struct SetupKeyboardInfo custom_key;
8749 } customize_step[] =
8751 { &custom_key.left, "Move Left" },
8752 { &custom_key.right, "Move Right" },
8753 { &custom_key.up, "Move Up" },
8754 { &custom_key.down, "Move Down" },
8755 { &custom_key.snap, "Snap Field" },
8756 { &custom_key.drop, "Drop Element" }
8758 int font_nr_old = FONT_VALUE_OLD;
8759 int font_nr_new = FONT_VALUE_1;
8760 boolean success = FALSE;
8762 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8764 font_nr_old = FONT_VALUE_OLD_NARROW;
8765 font_nr_new = FONT_VALUE_NARROW;
8768 // read existing key bindings from player setup
8769 custom_key = setup.input[player_nr].key;
8772 FadeOut(REDRAW_FIELD);
8776 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8779 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8780 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8781 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8782 "Key:", FONT_INPUT_1_ACTIVE);
8783 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8784 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8786 FadeIn(REDRAW_FIELD);
8792 if (NextValidEvent(&event))
8796 case EVENT_KEYPRESS:
8798 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8800 // press 'Escape' to abort and keep the old key bindings
8801 if (key == KSYM_Escape)
8803 FadeSkipNextFadeIn();
8810 // press 'Enter' to keep the existing key binding
8811 if (key == KSYM_Return)
8812 key = *customize_step[step_nr].key;
8814 // check if key already used
8815 for (i = 0; i < step_nr; i++)
8816 if (*customize_step[i].key == key)
8821 // got new key binding
8822 *customize_step[step_nr].key = key;
8823 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8825 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8826 getKeyNameFromKey(key), font_nr_new);
8829 // un-highlight last query
8830 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8831 customize_step[step_nr - 1].text, FONT_MENU_1);
8832 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8833 "Key:", FONT_MENU_1);
8835 // all keys configured
8844 // query next key binding
8845 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8846 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8847 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8848 "Key:", FONT_INPUT_1_ACTIVE);
8849 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8850 getKeyNameFromKey(*customize_step[step_nr].key),
8855 case EVENT_KEYRELEASE:
8856 key_joystick_mapping = 0;
8860 HandleOtherEvents(&event);
8868 // write new key bindings back to player setup, if successfully finished
8870 setup.input[player_nr].key = custom_key;
8875 void CustomizeKeyboard(int player_nr)
8877 boolean success = CustomizeKeyboardMain(player_nr);
8881 int font_nr = FONT_TITLE_1;
8882 int font_height = getFontHeight(font_nr);
8883 int ypos1 = SYSIZE / 2 - font_height * 2;
8884 int ypos2 = SYSIZE / 2 - font_height * 1;
8885 unsigned int wait_frame_delay = 0;
8886 unsigned int wait_frame_delay_value = 2000;
8888 ResetDelayCounter(&wait_frame_delay);
8892 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8893 DrawTextSCentered(ypos2, font_nr, "configured!");
8895 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8901 DrawSetupScreen_Input();
8904 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8906 #define MARKER_BUTTON 1
8907 #define MARKER_AXIS_X 2
8908 #define MARKER_AXIS_Y 3
8910 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8912 static boolean bitmaps_initialized = FALSE;
8913 boolean screen_initialized = FALSE;
8914 static Bitmap *controller, *button, *axis_x, *axis_y;
8916 boolean success = TRUE;
8917 boolean done = FALSE, next = FALSE;
8919 int alpha = 200, alpha_step = -1;
8920 int alpha_ticks = 0;
8921 char mapping[4096], temp[256];
8922 int font_name = MENU_SETUP_FONT_TITLE;
8923 int font_info = MENU_SETUP_FONT_TEXT;
8924 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8925 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8926 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8927 int ystep_name = getMenuTextStep(spacing_name, font_name);
8928 int ystep_line = getMenuTextStep(spacing_line, font_info);
8929 int ystep_para = getMenuTextStep(spacing_para, font_info);
8937 int axis, button, hat, hat_value;
8940 *step, *prev_step, steps[] =
8942 { 356, 155, MARKER_BUTTON, "a", },
8943 { 396, 122, MARKER_BUTTON, "b", },
8944 { 320, 125, MARKER_BUTTON, "x", },
8945 { 358, 95, MARKER_BUTTON, "y", },
8946 { 162, 125, MARKER_BUTTON, "back", },
8947 { 216, 125, MARKER_BUTTON, "guide", },
8948 { 271, 125, MARKER_BUTTON, "start", },
8949 { 110, 200, MARKER_BUTTON, "dpleft", },
8950 { 146, 228, MARKER_BUTTON, "dpdown", },
8951 { 178, 200, MARKER_BUTTON, "dpright", },
8952 { 146, 172, MARKER_BUTTON, "dpup", },
8953 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8954 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8955 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8956 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8957 { 73, 141, MARKER_BUTTON, "leftstick", },
8958 { 282, 210, MARKER_BUTTON, "rightstick", },
8959 { 73, 141, MARKER_AXIS_X, "leftx", },
8960 { 73, 141, MARKER_AXIS_Y, "lefty", },
8961 { 282, 210, MARKER_AXIS_X, "rightx", },
8962 { 282, 210, MARKER_AXIS_Y, "righty", },
8965 unsigned int event_frame_delay = 0;
8966 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8968 ResetDelayCounter(&event_frame_delay);
8970 if (!bitmaps_initialized)
8972 controller = LoadCustomImage("joystick/controller.png");
8973 button = LoadCustomImage("joystick/button.png");
8974 axis_x = LoadCustomImage("joystick/axis_x.png");
8975 axis_y = LoadCustomImage("joystick/axis_y.png");
8977 bitmaps_initialized = TRUE;
8980 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8983 // print info about the joystick we are watching
8984 Debug("joystick", "watching joystick %d: (%s)",
8985 SDL_JoystickInstanceID(joystick), name);
8986 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8987 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8988 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8991 // initialize mapping with GUID and name
8992 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8994 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8995 temp, name, SDL_GetPlatform());
8997 // loop through all steps (buttons and axes), getting joystick events
8998 for (i = 0; i < SDL_arraysize(steps) && !done;)
9000 Bitmap *marker = button; // initialize with reliable default value
9003 strcpy(step->mapping, mapping);
9007 step->hat_value = -1;
9009 marker = (step->marker == MARKER_BUTTON ? button :
9010 step->marker == MARKER_AXIS_X ? axis_x :
9011 step->marker == MARKER_AXIS_Y ? axis_y : marker);
9015 while (!done && !next)
9017 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
9018 alpha_ticks = SDL_GetTicks();
9025 else if (alpha < 128)
9031 int controller_x = SX + (SXSIZE - controller->width) / 2;
9032 int controller_y = SY + ystep_line;
9034 int marker_x = controller_x + step->x;
9035 int marker_y = controller_y + step->y;
9037 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
9038 int ystart2 = ystart1 + ystep_name + ystep_line;
9042 DrawTextSCentered(ystart1, font_name, name);
9044 DrawTextSCentered(ystart2, font_info,
9045 "Press buttons and move axes on");
9046 ystart2 += ystep_line;
9047 DrawTextSCentered(ystart2, font_info,
9048 "your controller when indicated.");
9049 ystart2 += ystep_line;
9050 DrawTextSCentered(ystart2, font_info,
9051 "(Your controller may look different.)");
9052 ystart2 += ystep_para;
9054 #if defined(PLATFORM_ANDROID)
9055 DrawTextSCentered(ystart2, font_info,
9056 "To correct a mistake,");
9057 ystart2 += ystep_line;
9058 DrawTextSCentered(ystart2, font_info,
9059 "press the 'back' button.");
9060 ystart2 += ystep_line;
9061 DrawTextSCentered(ystart2, font_info,
9062 "To skip a button or axis,");
9063 ystart2 += ystep_line;
9064 DrawTextSCentered(ystart2, font_info,
9065 "press the 'menu' button.");
9067 DrawTextSCentered(ystart2, font_info,
9068 "To correct a mistake,");
9069 ystart2 += ystep_line;
9070 DrawTextSCentered(ystart2, font_info,
9071 "press the 'backspace' key.");
9072 ystart2 += ystep_line;
9073 DrawTextSCentered(ystart2, font_info,
9074 "To skip a button or axis,");
9075 ystart2 += ystep_line;
9076 DrawTextSCentered(ystart2, font_info,
9077 "press the 'return' key.");
9078 ystart2 += ystep_line;
9079 DrawTextSCentered(ystart2, font_info,
9080 "To exit, press the 'escape' key.");
9083 BlitBitmapMasked(controller, drawto, 0, 0,
9084 controller->width, controller->height,
9085 controller_x, controller_y);
9087 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
9088 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
9090 BlitBitmapMasked(marker, drawto, 0, 0,
9091 marker->width, marker->height,
9092 marker_x, marker_y);
9094 if (!screen_initialized)
9095 FadeIn(REDRAW_FIELD);
9099 screen_initialized = TRUE;
9101 while (NextValidEvent(&event))
9105 case SDL_JOYAXISMOTION:
9106 if (event.jaxis.value > 20000 ||
9107 event.jaxis.value < -20000)
9109 for (j = 0; j < i; j++)
9110 if (steps[j].axis == event.jaxis.axis)
9115 if (step->marker != MARKER_AXIS_X &&
9116 step->marker != MARKER_AXIS_Y)
9119 step->axis = event.jaxis.axis;
9120 strcat(mapping, step->field);
9121 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
9122 strcat(mapping, temp);
9130 case SDL_JOYHATMOTION:
9131 // ignore centering; we're probably just coming back
9132 // to the center from the previous item we set
9133 if (event.jhat.value == SDL_HAT_CENTERED)
9136 for (j = 0; j < i; j++)
9137 if (steps[j].hat == event.jhat.hat &&
9138 steps[j].hat_value == event.jhat.value)
9143 step->hat = event.jhat.hat;
9144 step->hat_value = event.jhat.value;
9145 strcat(mapping, step->field);
9146 snprintf(temp, sizeof(temp), ":h%u.%u,",
9147 event.jhat.hat, event.jhat.value );
9148 strcat(mapping, temp);
9155 case SDL_JOYBALLMOTION:
9158 case SDL_JOYBUTTONUP:
9159 for (j = 0; j < i; j++)
9160 if (steps[j].button == event.jbutton.button)
9165 step->button = event.jbutton.button;
9166 strcat(mapping, step->field);
9167 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9168 strcat(mapping, temp);
9175 case SDL_FINGERDOWN:
9176 case SDL_MOUSEBUTTONDOWN:
9184 if (event.key.keysym.sym == KSYM_BackSpace ||
9185 event.key.keysym.sym == KSYM_Back)
9197 prev_step = &steps[i - 1];
9198 strcpy(mapping, prev_step->mapping);
9205 if (event.key.keysym.sym == KSYM_space ||
9206 event.key.keysym.sym == KSYM_Return ||
9207 event.key.keysym.sym == KSYM_Menu)
9216 if (event.key.keysym.sym == KSYM_Escape)
9226 program.exit_function(0);
9233 // do not handle events for longer than standard frame delay period
9234 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9243 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9246 // activate mapping for this game
9247 SDL_GameControllerAddMapping(mapping);
9249 // save mapping to personal mappings
9250 SaveSetup_AddGameControllerMapping(mapping);
9253 // wait until the last pending event was removed from event queue
9254 while (NextValidEvent(&event));
9259 static int ConfigureJoystickMain(int player_nr)
9261 char *device_name = setup.input[player_nr].joy.device_name;
9262 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9263 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9264 int success = FALSE;
9267 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9268 return JOYSTICK_NOT_AVAILABLE;
9270 if (!joystick_active || !setup.input[player_nr].use_joystick)
9271 return JOYSTICK_NOT_AVAILABLE;
9274 FadeOut(REDRAW_FIELD);
9276 // close all joystick devices (potentially opened as game controllers)
9277 for (i = 0; i < SDL_NumJoysticks(); i++)
9278 SDLCloseJoystick(i);
9280 // open joystick device as plain joystick to configure as game controller
9281 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9283 // as the joystick was successfully opened before, this should not happen
9284 if (joystick == NULL)
9287 // create new game controller mapping (buttons and axes) for joystick device
9288 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9290 // close joystick (and maybe re-open as configured game controller later)
9291 SDL_JoystickClose(joystick);
9293 // re-open all joystick devices (potentially as game controllers)
9294 for (i = 0; i < SDL_NumJoysticks(); i++)
9297 // clear all joystick input actions for all joystick devices
9298 SDLClearJoystickState();
9300 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9303 void ConfigureJoystick(int player_nr)
9305 boolean state = ConfigureJoystickMain(player_nr);
9307 if (state != JOYSTICK_NOT_CONFIGURED)
9309 boolean success = (state == JOYSTICK_CONFIGURED);
9310 char message1[MAX_OUTPUT_LINESIZE + 1];
9311 char *message2 = (success ? "configured!" : "not available!");
9312 char *device_name = setup.input[player_nr].joy.device_name;
9313 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9314 int font_nr = FONT_TITLE_1;
9315 int font_height = getFontHeight(font_nr);
9316 int ypos1 = SYSIZE / 2 - font_height * 2;
9317 int ypos2 = SYSIZE / 2 - font_height * 1;
9318 unsigned int wait_frame_delay = 0;
9319 unsigned int wait_frame_delay_value = 2000;
9321 ResetDelayCounter(&wait_frame_delay);
9325 sprintf(message1, "Joystick %d", nr);
9327 DrawTextSCentered(ypos1, font_nr, message1);
9328 DrawTextSCentered(ypos2, font_nr, message2);
9330 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9336 DrawSetupScreen_Input();
9339 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9341 if (y < video.screen_height / 3)
9343 // remap touch gadgets to access upper part of the screen
9344 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9345 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9347 else if (y > 2 * video.screen_height / 3)
9349 // remap touch gadgets to access lower part of the screen
9350 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9351 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9355 static boolean ConfigureVirtualButtonsMain(void)
9357 static char *customize_step_text[] =
9366 char grid_button[] =
9368 CHAR_GRID_BUTTON_LEFT,
9369 CHAR_GRID_BUTTON_RIGHT,
9370 CHAR_GRID_BUTTON_UP,
9371 CHAR_GRID_BUTTON_DOWN,
9372 CHAR_GRID_BUTTON_SNAP,
9373 CHAR_GRID_BUTTON_DROP
9382 int font_nr = FONT_INPUT_1_ACTIVE;
9383 int font_height = getFontHeight(font_nr);
9384 int ypos1 = SYSIZE / 2 - font_height * 2;
9385 int ypos2 = SYSIZE / 2 - font_height * 1;
9386 boolean success = FALSE;
9387 boolean finished = FALSE;
9389 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9390 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9391 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9392 boolean set_grid_button = FALSE;
9393 int nr = GRID_ACTIVE_NR();
9396 for (x = 0; x < MAX_GRID_XSIZE; x++)
9397 for (y = 0; y < MAX_GRID_YSIZE; y++)
9398 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9400 overlay.grid_button_highlight = grid_button[step_nr];
9405 FadeOut(REDRAW_FIELD);
9409 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9410 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9411 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9413 FadeIn(REDRAW_FIELD);
9415 SetOverlayShowGrid(TRUE);
9417 // map gadgets for setup touch buttons menu screen
9418 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9424 while (NextValidEvent(&event))
9426 int action = ACTION_NONE;
9428 // ---------- handle events and set the resulting action ----------
9434 UserEvent *user = (UserEvent *)&event;
9435 int id = user->value1;
9437 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9438 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9439 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9440 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9445 case EVENT_KEYPRESS:
9447 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9449 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9450 key == KSYM_BackSpace ||
9451 key == KSYM_Back ? ACTION_BACK :
9452 key == KSYM_Return ||
9454 key == KSYM_space ? ACTION_NEXT :
9459 case EVENT_KEYRELEASE:
9460 key_joystick_mapping = 0;
9463 case EVENT_BUTTONPRESS:
9464 case EVENT_BUTTONRELEASE:
9466 ButtonEvent *button = (ButtonEvent *)&event;
9468 motion_status = FALSE;
9470 if (button->type == EVENT_BUTTONPRESS)
9471 button_status = button->button;
9473 button_status = MB_RELEASED;
9475 if (HandleGadgets(button->x, button->y, button_status))
9477 // do not handle this button event anymore
9481 button->x += video.screen_xoffset;
9482 button->y += video.screen_yoffset;
9484 x = button->x * overlay.grid_xsize / video.screen_width;
9485 y = button->y * overlay.grid_ysize / video.screen_height;
9487 if (button->type == EVENT_BUTTONPRESS)
9490 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9491 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9493 set_grid_button = TRUE;
9496 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9500 case EVENT_MOTIONNOTIFY:
9502 MotionEvent *motion = (MotionEvent *)&event;
9504 motion_status = TRUE;
9506 if (HandleGadgets(motion->x, motion->y, button_status))
9508 // do not handle this button event anymore
9512 motion->x += video.screen_xoffset;
9513 motion->y += video.screen_yoffset;
9515 x = motion->x * overlay.grid_xsize / video.screen_width;
9516 y = motion->y * overlay.grid_ysize / video.screen_height;
9518 set_grid_button = TRUE;
9520 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9524 case SDL_WINDOWEVENT:
9525 HandleWindowEvent((WindowEvent *) &event);
9527 // check if device has been rotated
9528 if (nr != GRID_ACTIVE_NR())
9530 nr = GRID_ACTIVE_NR();
9532 for (x = 0; x < MAX_GRID_XSIZE; x++)
9533 for (y = 0; y < MAX_GRID_YSIZE; y++)
9534 grid_button_old[x][y] = grid_button_tmp[x][y] =
9535 overlay.grid_button[x][y];
9540 case SDL_APP_WILLENTERBACKGROUND:
9541 case SDL_APP_DIDENTERBACKGROUND:
9542 case SDL_APP_WILLENTERFOREGROUND:
9543 case SDL_APP_DIDENTERFOREGROUND:
9544 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9548 HandleOtherEvents(&event);
9552 // ---------- perform action set by handling events ----------
9554 if (action == ACTION_ESCAPE)
9556 // abort and restore the old key bindings
9558 for (x = 0; x < MAX_GRID_XSIZE; x++)
9559 for (y = 0; y < MAX_GRID_YSIZE; y++)
9560 overlay.grid_button[x][y] = grid_button_old[x][y];
9562 FadeSkipNextFadeIn();
9566 else if (action == ACTION_BACK)
9568 // keep the configured key bindings and go to previous page
9574 FadeSkipNextFadeIn();
9579 else if (action == ACTION_NEXT)
9581 // keep the configured key bindings and go to next page
9585 // all virtual buttons configured
9593 if (action != ACTION_NONE && !finished)
9595 for (x = 0; x < MAX_GRID_XSIZE; x++)
9596 for (y = 0; y < MAX_GRID_YSIZE; y++)
9597 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9599 overlay.grid_button_highlight = grid_button[step_nr];
9601 // configure next virtual button
9605 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9606 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9607 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9610 if (set_grid_button)
9612 overlay.grid_button[x][y] =
9613 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9614 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9615 grid_button_tmp[x][y]);
9617 set_grid_button = FALSE;
9624 for (x = 0; x < MAX_GRID_XSIZE; x++)
9625 for (y = 0; y < MAX_GRID_YSIZE; y++)
9626 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9628 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9630 SetOverlayShowGrid(FALSE);
9635 void ConfigureVirtualButtons(void)
9637 boolean success = ConfigureVirtualButtonsMain();
9639 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9640 SCREEN_MASK_TOUCH2);
9644 int font_nr = FONT_TITLE_1;
9645 int font_height = getFontHeight(font_nr);
9646 int ypos1 = SYSIZE / 2 - font_height * 2;
9647 int ypos2 = SYSIZE / 2 - font_height * 1;
9648 unsigned int wait_frame_delay = 0;
9649 unsigned int wait_frame_delay_value = 2000;
9651 ResetDelayCounter(&wait_frame_delay);
9655 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9656 DrawTextSCentered(ypos2, font_nr, "configured!");
9658 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9665 void DrawSetupScreen(void)
9670 if (setup_mode == SETUP_MODE_INPUT)
9671 DrawSetupScreen_Input();
9672 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9673 DrawChooseTree(&scores_type_current);
9674 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9675 DrawChooseTree(&game_speed_current);
9676 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9677 DrawChooseTree(&scroll_delay_current);
9678 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9679 DrawChooseTree(&snapshot_mode_current);
9680 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9681 DrawChooseTree(&window_size_current);
9682 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9683 DrawChooseTree(&scaling_type_current);
9684 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9685 DrawChooseTree(&rendering_mode_current);
9686 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9687 DrawChooseTree(&vsync_mode_current);
9688 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9689 DrawChooseTree(&artwork.gfx_current);
9690 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9691 DrawChooseTree(&artwork.snd_current);
9692 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9693 DrawChooseTree(&artwork.mus_current);
9694 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9695 DrawChooseTree(&volume_simple_current);
9696 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9697 DrawChooseTree(&volume_loops_current);
9698 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9699 DrawChooseTree(&volume_music_current);
9700 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9701 DrawChooseTree(&touch_control_current);
9702 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9703 DrawChooseTree(&move_distance_current);
9704 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9705 DrawChooseTree(&drop_distance_current);
9706 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9707 DrawChooseTree(&transparency_current);
9708 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9709 DrawChooseTree(&grid_size_current[0][0]);
9710 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9711 DrawChooseTree(&grid_size_current[0][1]);
9712 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9713 DrawChooseTree(&grid_size_current[1][0]);
9714 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9715 DrawChooseTree(&grid_size_current[1][1]);
9717 DrawSetupScreen_Generic();
9719 PlayMenuSoundsAndMusic();
9722 void RedrawSetupScreenAfterFullscreenToggle(void)
9724 if (setup_mode == SETUP_MODE_GRAPHICS ||
9725 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9727 // update list selection from "setup.window_scaling_percent"
9728 execSetupGraphics_setWindowSizes(TRUE);
9734 void RedrawSetupScreenAfterScreenRotation(int nr)
9738 if (setup_mode == SETUP_MODE_TOUCH)
9740 // update virtual button settings (depending on screen orientation)
9743 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9745 // save already configured virtual buttons
9746 for (x = 0; x < MAX_GRID_XSIZE; x++)
9747 for (y = 0; y < MAX_GRID_YSIZE; y++)
9748 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9752 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9754 if (setup_mode == SETUP_MODE_INPUT)
9755 HandleSetupScreen_Input(mx, my, dx, dy, button);
9756 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9757 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9758 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9759 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9760 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9761 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9762 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9763 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9764 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9765 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9766 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9767 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9768 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9769 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9770 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9771 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9772 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9773 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9774 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9775 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9776 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9777 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9778 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9779 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9780 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9781 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9782 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9783 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9784 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9785 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9786 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9787 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9788 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9789 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9790 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9791 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9792 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9793 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9794 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9795 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9796 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9797 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9798 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9799 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9801 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9804 void HandleGameActions(void)
9806 if (setup.ask_on_game_over)
9809 if (game.restart_game_message != NULL)
9811 RequestRestartGame(game.restart_game_message);
9816 if (game_status != GAME_MODE_PLAYING)
9819 GameActions(); // main game loop
9821 if (tape.auto_play && !tape.playing)
9822 AutoPlayTapesContinue(); // continue automatically playing next tape
9826 // ---------- new screen button stuff --------------------------------------
9830 int gfx_unpressed, gfx_pressed;
9831 struct MenuPosInfo *pos;
9832 boolean *check_value;
9835 unsigned int event_mask;
9836 boolean is_touch_button;
9838 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9841 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9842 &menu.main.button.prev_level, NULL,
9843 SCREEN_CTRL_ID_PREV_LEVEL,
9845 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9846 FALSE, "previous level"
9849 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9850 &menu.main.button.next_level, NULL,
9851 SCREEN_CTRL_ID_NEXT_LEVEL,
9853 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9857 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9858 &menu.scores.button.prev_level, NULL,
9859 SCREEN_CTRL_ID_PREV_LEVEL2,
9861 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9862 FALSE, "previous level"
9865 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9866 &menu.scores.button.next_level, NULL,
9867 SCREEN_CTRL_ID_NEXT_LEVEL2,
9869 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9873 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9874 &menu.main.button.first_level, NULL,
9875 SCREEN_CTRL_ID_FIRST_LEVEL,
9878 FALSE, "first level"
9881 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9882 &menu.main.button.last_level, NULL,
9883 SCREEN_CTRL_ID_LAST_LEVEL,
9889 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9890 &menu.main.button.level_number, NULL,
9891 SCREEN_CTRL_ID_LEVEL_NUMBER,
9894 FALSE, "level number"
9897 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9898 &menu.setup.button.prev_player, NULL,
9899 SCREEN_CTRL_ID_PREV_PLAYER,
9901 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9902 FALSE, "previous player"
9905 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9906 &menu.setup.button.next_player, NULL,
9907 SCREEN_CTRL_ID_NEXT_PLAYER,
9909 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9910 FALSE, "next player"
9913 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9914 &menu.main.button.insert_solution, NULL,
9915 SCREEN_CTRL_ID_INSERT_SOLUTION,
9916 SCREEN_MASK_MAIN_HAS_SOLUTION,
9918 FALSE, "insert solution tape"
9921 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9922 &menu.main.button.play_solution, NULL,
9923 SCREEN_CTRL_ID_PLAY_SOLUTION,
9924 SCREEN_MASK_MAIN_HAS_SOLUTION,
9926 FALSE, "play solution tape"
9929 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9930 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9931 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9933 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9934 FALSE, "switch ECS/AGA chipset"
9937 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9938 &menu.setup.button.touch_back, NULL,
9939 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9942 TRUE, "previous page"
9945 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9946 &menu.setup.button.touch_next, NULL,
9947 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9953 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9954 &menu.setup.button.touch_back2, NULL,
9955 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9958 TRUE, "previous page"
9961 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9962 &menu.setup.button.touch_next2, NULL,
9963 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9972 int gfx_unpressed, gfx_pressed;
9976 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9979 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9980 -1, -1, // these values are not constant, but can change at runtime
9981 SCREEN_CTRL_ID_SCROLL_UP,
9985 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9986 -1, -1, // these values are not constant, but can change at runtime
9987 SCREEN_CTRL_ID_SCROLL_DOWN,
9994 int gfx_unpressed, gfx_pressed;
10000 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
10003 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
10004 -1, -1, // these values are not constant, but can change at runtime
10005 -1, -1, // these values are not constant, but can change at runtime
10006 GD_TYPE_SCROLLBAR_VERTICAL,
10007 SCREEN_CTRL_ID_SCROLL_VERTICAL,
10008 "scroll level series vertically"
10020 } textinput_info[NUM_SCREEN_TEXTINPUT] =
10023 IMG_SETUP_INPUT_TEXT,
10024 SCREEN_CTRL_ID_NETWORK_SERVER,
10025 -1, -1, // these values are not constant, but can change at runtime
10026 MAX_SETUP_TEXT_INPUT_LEN,
10027 network_server_hostname,
10028 "Network Server Hostname / IP"
10032 static void CreateScreenMenubuttons(void)
10034 struct GadgetInfo *gi;
10035 unsigned int event_mask;
10038 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10040 struct MenuPosInfo *pos = menubutton_info[i].pos;
10041 int screen_mask = menubutton_info[i].screen_mask;
10042 boolean is_touch_button = menubutton_info[i].is_touch_button;
10043 boolean is_check_button = menubutton_info[i].check_value != NULL;
10044 boolean is_score_button = (screen_mask == SCREEN_MASK_SCORES);
10045 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10046 int gfx_unpressed, gfx_pressed;
10047 int x, y, width, height;
10048 int gd_x1, gd_x2, gd_y1, gd_y2;
10049 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
10050 int id = menubutton_info[i].gadget_id;
10051 int type = GD_TYPE_NORMAL_BUTTON;
10052 boolean checked = FALSE;
10054 event_mask = menubutton_info[i].event_mask;
10056 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
10057 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
10059 width = graphic_info[menubutton_info[i].gfx_pressed].width;
10060 height = graphic_info[menubutton_info[i].gfx_pressed].height;
10062 gfx_unpressed = menubutton_info[i].gfx_unpressed;
10063 gfx_pressed = menubutton_info[i].gfx_pressed;
10064 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10065 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10066 gd_x1 = graphic_info[gfx_unpressed].src_x;
10067 gd_y1 = graphic_info[gfx_unpressed].src_y;
10068 gd_x2 = graphic_info[gfx_pressed].src_x;
10069 gd_y2 = graphic_info[gfx_pressed].src_y;
10075 if (is_touch_button)
10077 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
10078 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
10081 if (is_check_button)
10083 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
10084 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
10085 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
10086 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
10088 type = GD_TYPE_CHECK_BUTTON;
10089 checked = *menubutton_info[i].check_value;
10092 if (is_score_button)
10094 // if x/y set to -1, dynamically place buttons next to title text
10095 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10098 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10099 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10100 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10101 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10104 y = mSY + MENU_TITLE1_YPOS;
10107 gi = CreateGadget(GDI_CUSTOM_ID, id,
10108 GDI_CUSTOM_TYPE_ID, i,
10109 GDI_IMAGE_ID, gfx_unpressed,
10110 GDI_INFO_TEXT, menubutton_info[i].infotext,
10114 GDI_HEIGHT, height,
10116 GDI_STATE, GD_BUTTON_UNPRESSED,
10117 GDI_CHECKED, checked,
10118 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10119 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10120 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
10121 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
10122 GDI_DIRECT_DRAW, FALSE,
10123 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10124 GDI_EVENT_MASK, event_mask,
10125 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10129 Fail("cannot create gadget");
10131 screen_gadget[id] = gi;
10135 static void CreateScreenScrollbuttons(void)
10137 struct GadgetInfo *gi;
10138 unsigned int event_mask;
10141 // these values are not constant, but can change at runtime
10142 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10143 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10144 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10145 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10147 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10149 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10150 int gfx_unpressed, gfx_pressed;
10151 int x, y, width, height;
10152 int gd_x1, gd_x2, gd_y1, gd_y2;
10153 int id = scrollbutton_info[i].gadget_id;
10155 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10157 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10158 y = mSY + scrollbutton_info[i].y;
10159 width = SC_SCROLLBUTTON_XSIZE;
10160 height = SC_SCROLLBUTTON_YSIZE;
10162 // correct scrollbar position if placed outside menu (playfield) area
10163 if (x > SX + SC_SCROLL_UP_XPOS)
10164 x = SX + SC_SCROLL_UP_XPOS;
10166 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10167 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10168 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10170 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10171 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10172 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10173 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10174 gd_x1 = graphic_info[gfx_unpressed].src_x;
10175 gd_y1 = graphic_info[gfx_unpressed].src_y;
10176 gd_x2 = graphic_info[gfx_pressed].src_x;
10177 gd_y2 = graphic_info[gfx_pressed].src_y;
10179 gi = CreateGadget(GDI_CUSTOM_ID, id,
10180 GDI_CUSTOM_TYPE_ID, i,
10181 GDI_IMAGE_ID, gfx_unpressed,
10182 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10186 GDI_HEIGHT, height,
10187 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10188 GDI_STATE, GD_BUTTON_UNPRESSED,
10189 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10190 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10191 GDI_DIRECT_DRAW, FALSE,
10192 GDI_EVENT_MASK, event_mask,
10193 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10197 Fail("cannot create gadget");
10199 screen_gadget[id] = gi;
10203 static void CreateScreenScrollbars(void)
10207 // these values are not constant, but can change at runtime
10208 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10209 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10210 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10211 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10213 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10215 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10216 int gfx_unpressed, gfx_pressed;
10217 int x, y, width, height;
10218 int gd_x1, gd_x2, gd_y1, gd_y2;
10219 struct GadgetInfo *gi;
10220 int items_max, items_visible, item_position;
10221 unsigned int event_mask;
10222 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10223 int id = scrollbar_info[i].gadget_id;
10225 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10227 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10228 y = mSY + scrollbar_info[i].y;
10229 width = scrollbar_info[i].width;
10230 height = scrollbar_info[i].height;
10232 // correct scrollbar position if placed outside menu (playfield) area
10233 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10234 x = SX + SC_SCROLL_VERTICAL_XPOS;
10236 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10237 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10239 items_max = num_page_entries;
10240 items_visible = num_page_entries;
10243 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10244 gfx_pressed = scrollbar_info[i].gfx_pressed;
10245 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10246 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10247 gd_x1 = graphic_info[gfx_unpressed].src_x;
10248 gd_y1 = graphic_info[gfx_unpressed].src_y;
10249 gd_x2 = graphic_info[gfx_pressed].src_x;
10250 gd_y2 = graphic_info[gfx_pressed].src_y;
10252 gi = CreateGadget(GDI_CUSTOM_ID, id,
10253 GDI_CUSTOM_TYPE_ID, i,
10254 GDI_IMAGE_ID, gfx_unpressed,
10255 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10259 GDI_HEIGHT, height,
10260 GDI_TYPE, scrollbar_info[i].type,
10261 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10262 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10263 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10264 GDI_WHEEL_AREA_X, SX,
10265 GDI_WHEEL_AREA_Y, SY,
10266 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10267 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10268 GDI_STATE, GD_BUTTON_UNPRESSED,
10269 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10270 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10271 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10272 GDI_DIRECT_DRAW, FALSE,
10273 GDI_EVENT_MASK, event_mask,
10274 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10278 Fail("cannot create gadget");
10280 screen_gadget[id] = gi;
10284 static void CreateScreenTextInputGadgets(void)
10288 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10290 int graphic = textinput_info[i].graphic;
10291 struct GraphicInfo *gd = &graphic_info[graphic];
10292 int gd_x1 = gd->src_x;
10293 int gd_y1 = gd->src_y;
10294 int gd_x2 = gd->src_x + gd->active_xoffset;
10295 int gd_y2 = gd->src_y + gd->active_yoffset;
10296 struct GadgetInfo *gi;
10297 unsigned int event_mask;
10298 int id = textinput_info[i].gadget_id;
10299 int x = textinput_info[i].x;
10300 int y = textinput_info[i].y;
10302 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10304 gi = CreateGadget(GDI_CUSTOM_ID, id,
10305 GDI_CUSTOM_TYPE_ID, i,
10306 GDI_INFO_TEXT, textinput_info[i].infotext,
10309 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10310 GDI_TEXT_VALUE, textinput_info[i].value,
10311 GDI_TEXT_SIZE, textinput_info[i].size,
10312 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10313 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10314 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10315 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10316 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10317 GDI_DESIGN_WIDTH, gd->width,
10318 GDI_EVENT_MASK, event_mask,
10319 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10320 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10324 Fail("cannot create gadget");
10326 screen_gadget[id] = gi;
10330 void CreateScreenGadgets(void)
10332 CreateScreenMenubuttons();
10334 CreateScreenScrollbuttons();
10335 CreateScreenScrollbars();
10337 CreateScreenTextInputGadgets();
10340 void FreeScreenGadgets(void)
10344 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10345 FreeGadget(screen_gadget[i]);
10348 static void RedrawScreenMenuGadgets(int screen_mask)
10352 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10353 if (screen_mask & menubutton_info[i].screen_mask)
10354 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10357 static void MapScreenMenuGadgets(int screen_mask)
10361 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10362 if (screen_mask & menubutton_info[i].screen_mask)
10363 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10366 static void UnmapScreenMenuGadgets(int screen_mask)
10370 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10372 if (screen_mask & menubutton_info[i].screen_mask)
10374 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10376 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10377 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10378 screen_gadget[menubutton_info[i].gadget_id]->y,
10379 screen_gadget[menubutton_info[i].gadget_id]->width,
10380 screen_gadget[menubutton_info[i].gadget_id]->height);
10385 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10388 MapScreenMenuGadgets(screen_mask);
10390 UnmapScreenMenuGadgets(screen_mask);
10393 static void MapScreenGadgets(int num_entries)
10397 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10400 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10401 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10403 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10404 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10407 static void UnmapScreenGadgets()
10411 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10412 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10414 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10415 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10418 static void MapScreenTreeGadgets(TreeInfo *ti)
10420 MapScreenGadgets(numTreeInfoInGroup(ti));
10423 static void UnmapScreenTreeGadgets(void)
10425 UnmapScreenGadgets();
10428 static void HandleScreenGadgets(struct GadgetInfo *gi)
10430 int id = gi->custom_id;
10431 int button = gi->event.button;
10432 int step = (button == MB_LEFTBUTTON ? 1 :
10433 button == MB_MIDDLEBUTTON ? 5 :
10434 button == MB_RIGHTBUTTON ? 10 : 1);
10438 case SCREEN_CTRL_ID_PREV_LEVEL:
10439 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10442 case SCREEN_CTRL_ID_NEXT_LEVEL:
10443 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10446 case SCREEN_CTRL_ID_PREV_LEVEL2:
10447 HandleHallOfFame_SelectLevelOrScore(step, -1);
10450 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10451 HandleHallOfFame_SelectLevelOrScore(step, +1);
10454 case SCREEN_CTRL_ID_FIRST_LEVEL:
10455 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10458 case SCREEN_CTRL_ID_LAST_LEVEL:
10459 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10462 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10463 CloseDoor(DOOR_CLOSE_2);
10464 SetGameStatus(GAME_MODE_LEVELNR);
10465 DrawChooseLevelNr();
10468 case SCREEN_CTRL_ID_PREV_PLAYER:
10469 HandleSetupScreen_Input_Player(step, -1);
10472 case SCREEN_CTRL_ID_NEXT_PLAYER:
10473 HandleSetupScreen_Input_Player(step, +1);
10476 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10477 InsertSolutionTape();
10480 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10481 PlaySolutionTape();
10484 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10485 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10489 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10490 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10491 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10492 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10493 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10496 case SCREEN_CTRL_ID_SCROLL_UP:
10497 if (game_status == GAME_MODE_NAMES)
10498 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10499 else if (game_status == GAME_MODE_LEVELS)
10500 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10501 else if (game_status == GAME_MODE_LEVELNR)
10502 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10503 else if (game_status == GAME_MODE_SETUP)
10504 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10505 else if (game_status == GAME_MODE_INFO)
10506 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10507 else if (game_status == GAME_MODE_SCORES)
10508 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10511 case SCREEN_CTRL_ID_SCROLL_DOWN:
10512 if (game_status == GAME_MODE_NAMES)
10513 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10514 else if (game_status == GAME_MODE_LEVELS)
10515 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10516 else if (game_status == GAME_MODE_LEVELNR)
10517 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10518 else if (game_status == GAME_MODE_SETUP)
10519 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10520 else if (game_status == GAME_MODE_INFO)
10521 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10522 else if (game_status == GAME_MODE_SCORES)
10523 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10526 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10527 if (game_status == GAME_MODE_NAMES)
10528 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10529 else if (game_status == GAME_MODE_LEVELS)
10530 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10531 else if (game_status == GAME_MODE_LEVELNR)
10532 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10533 else if (game_status == GAME_MODE_SETUP)
10534 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10535 else if (game_status == GAME_MODE_INFO)
10536 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10537 else if (game_status == GAME_MODE_SCORES)
10538 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10541 case SCREEN_CTRL_ID_NETWORK_SERVER:
10543 if (!strEqual(gi->textinput.value, ""))
10545 setString(&setup.network_server_hostname, gi->textinput.value);
10547 network.server_host = setup.network_server_hostname;
10551 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10553 network.server_host = NULL;
10556 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10557 network.server_host = NULL;
10559 execSetupGame_setNetworkServerText();
10571 void DumpScreenIdentifiers(void)
10575 Print("Active screen elements on current screen:\n");
10577 for (i = 0; main_controls[i].nr != -1; i++)
10579 struct MainControlInfo *mci = &main_controls[i];
10581 if (mci->button_graphic != -1)
10583 char *token = getTokenFromImageID(mci->button_graphic);
10585 Print("- '%s'\n", token);
10592 boolean DoScreenAction(int image_id)
10596 if (game_status != GAME_MODE_MAIN)
10599 for (i = 0; main_controls[i].nr != -1; i++)
10601 struct MainControlInfo *mci = &main_controls[i];
10602 struct MenuPosInfo *pos = mci->pos_button;
10604 if (mci->button_graphic == image_id)
10606 int x = mSX + pos->x;
10607 int y = mSY + pos->y;
10609 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10618 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10620 // get tree info node of newly added level or artwork set
10621 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10622 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10624 if (tree_node_new == NULL) // should not happen
10627 // if request dialog is active, do nothing
10628 if (game.request_active)
10631 if (game_status == GAME_MODE_MAIN &&
10632 tree_type == TREE_TYPE_LEVEL_DIR)
10634 // when adding new level set in main menu, select it as current level set
10636 // change current level set to newly added level set from zip file
10637 leveldir_current = tree_node_new;
10639 // change current level number to first level of newly added level set
10640 level_nr = leveldir_current->first_level;
10642 // redraw screen to reflect changed level set
10645 // save this level set and level number as last selected level set
10646 SaveLevelSetup_LastSeries();
10647 SaveLevelSetup_SeriesInfo();
10649 else if (game_status == GAME_MODE_LEVELS &&
10650 tree_type == TREE_TYPE_LEVEL_DIR)
10652 // when adding new level set in level set menu, set cursor and update screen
10654 leveldir_current = tree_node_new;
10656 DrawChooseTree(&leveldir_current);
10658 else if (game_status == GAME_MODE_SETUP)
10660 // when adding new artwork set in setup menu, set cursor and update screen
10662 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10663 tree_type == TREE_TYPE_GRAPHICS_DIR)
10665 artwork.gfx_current = tree_node_new;
10667 DrawChooseTree(&artwork.gfx_current);
10669 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10670 tree_type == TREE_TYPE_SOUNDS_DIR)
10672 artwork.snd_current = tree_node_new;
10674 DrawChooseTree(&artwork.snd_current);
10676 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10677 tree_type == TREE_TYPE_MUSIC_DIR)
10679 artwork.mus_current = tree_node_new;
10681 DrawChooseTree(&artwork.mus_current);
10686 static int UploadTapes(void)
10688 SetGameStatus(GAME_MODE_LOADING);
10690 FadeSetEnterScreen();
10691 FadeOut(REDRAW_ALL);
10693 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10695 FadeIn(REDRAW_ALL);
10697 DrawInitTextHead("Uploading tapes");
10699 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10700 global.autoplay_leveldir = "ALL";
10701 global.autoplay_all = TRUE;
10703 int num_tapes_uploaded = AutoPlayTapes();
10705 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10706 global.autoplay_leveldir = NULL;
10707 global.autoplay_all = FALSE;
10709 SetGameStatus(GAME_MODE_MAIN);
10713 return num_tapes_uploaded;
10716 static boolean OfferUploadTapes(void)
10718 if (!Request(setup.has_remaining_tapes ?
10719 "Upload missing tapes to the high score server now?" :
10720 "Upload all your tapes to the high score server now?", REQ_ASK))
10723 int num_tapes_uploaded = UploadTapes();
10726 if (num_tapes_uploaded < 0)
10728 num_tapes_uploaded = -num_tapes_uploaded - 1;
10730 if (num_tapes_uploaded == 0)
10731 sprintf(message, "Upload failed! No tapes uploaded!");
10732 else if (num_tapes_uploaded == 1)
10733 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10735 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10736 num_tapes_uploaded);
10738 Request(message, REQ_CONFIRM);
10740 // if uploading tapes failed, add tape upload entry to setup menu
10741 setup.provide_uploading_tapes = TRUE;
10742 setup.has_remaining_tapes = TRUE;
10744 SaveSetup_ServerSetup();
10749 if (num_tapes_uploaded == 0)
10750 sprintf(message, "No tapes uploaded!");
10751 else if (num_tapes_uploaded == 1)
10752 sprintf(message, "1 tape uploaded!");
10754 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10756 Request(message, REQ_CONFIRM);
10758 if (num_tapes_uploaded > 0)
10759 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10761 // after all tapes have been uploaded, remove entry from setup menu
10762 setup.provide_uploading_tapes = FALSE;
10763 setup.has_remaining_tapes = FALSE;
10765 SaveSetup_ServerSetup();
10770 static void CheckUploadTapes(void)
10772 if (!setup.ask_for_uploading_tapes)
10775 // after asking for uploading tapes, do not ask again
10776 setup.ask_for_uploading_tapes = FALSE;
10777 setup.ask_for_remaining_tapes = FALSE;
10779 if (directoryExists(getTapeDir(NULL)))
10781 boolean tapes_uploaded = OfferUploadTapes();
10783 if (!tapes_uploaded)
10785 Request(setup.has_remaining_tapes ?
10786 "You can upload missing tapes from the setup menu later!" :
10787 "You can upload your tapes from the setup menu later!",
10793 // if tapes directory does not exist yet, never offer uploading all tapes
10794 setup.provide_uploading_tapes = FALSE;
10797 SaveSetup_ServerSetup();
10800 static void UpgradePlayerUUID(void)
10802 ApiResetUUIDAsThread(getUUID());
10805 static void CheckUpgradePlayerUUID(void)
10807 if (setup.player_version > 1)
10810 UpgradePlayerUUID();
10813 void CheckApiServerTasks(void)
10815 // check if the player's UUID has to be upgraded
10816 CheckUpgradePlayerUUID();
10818 // check if there are any tapes to be uploaded
10819 CheckUploadTapes();