1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
27 #define DEBUG_JOYSTICKS 0
30 // screens on the info screen
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 // screens on the setup screen
43 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
44 // (should also match corresponding entries in src/conf_gfx.c)
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_ENGINES 2
48 #define SETUP_MODE_EDITOR 3
49 #define SETUP_MODE_GRAPHICS 4
50 #define SETUP_MODE_SOUND 5
51 #define SETUP_MODE_ARTWORK 6
52 #define SETUP_MODE_INPUT 7
53 #define SETUP_MODE_TOUCH 8
54 #define SETUP_MODE_SHORTCUTS 9
55 #define SETUP_MODE_SHORTCUTS_1 10
56 #define SETUP_MODE_SHORTCUTS_2 11
57 #define SETUP_MODE_SHORTCUTS_3 12
58 #define SETUP_MODE_SHORTCUTS_4 13
59 #define SETUP_MODE_SHORTCUTS_5 14
61 // sub-screens on the setup screen (generic)
62 #define SETUP_MODE_CHOOSE_ARTWORK 15
63 #define SETUP_MODE_CHOOSE_OTHER 16
65 // sub-screens on the setup screen (specific)
66 #define SETUP_MODE_CHOOSE_SCORES_TYPE 17
67 #define SETUP_MODE_CHOOSE_GAME_SPEED 18
68 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 19
69 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 20
70 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 21
71 #define SETUP_MODE_CHOOSE_SCALING_TYPE 22
72 #define SETUP_MODE_CHOOSE_RENDERING 23
73 #define SETUP_MODE_CHOOSE_VSYNC 24
74 #define SETUP_MODE_CHOOSE_GRAPHICS 25
75 #define SETUP_MODE_CHOOSE_SOUNDS 26
76 #define SETUP_MODE_CHOOSE_MUSIC 27
77 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 28
78 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 29
79 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 30
80 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 31
81 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 33
83 #define SETUP_MODE_CHOOSE_TRANSPARENCY 34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 36
86 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 37
87 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 38
88 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 39
90 #define MAX_SETUP_MODES 40
92 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
94 // setup screen titles
95 #define STR_SETUP_MAIN "Setup"
96 #define STR_SETUP_GAME "Game & Menu"
97 #define STR_SETUP_ENGINES "Game Engines"
98 #define STR_SETUP_EDITOR "Editor"
99 #define STR_SETUP_GRAPHICS "Graphics"
100 #define STR_SETUP_SOUND "Sound & Music"
101 #define STR_SETUP_ARTWORK "Custom Artwork"
102 #define STR_SETUP_INPUT "Input Devices"
103 #define STR_SETUP_TOUCH "Touch Controls"
104 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
105 #define STR_SETUP_EXIT "Exit"
106 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
108 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
109 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
110 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
111 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
112 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
113 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
114 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
115 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
116 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
117 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
118 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
119 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
120 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
121 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
122 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
125 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
126 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
128 // other screen text constants
129 #define STR_CHOOSE_TREE_EDIT "Edit"
130 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
131 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
133 // for input setup functions
134 #define SETUPINPUT_SCREEN_POS_START 0
135 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
136 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
137 #define SETUPINPUT_SCREEN_POS_END 13
139 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
140 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
142 #define MAX_SETUP_TEXT_INPUT_LEN 28
144 // for various menu stuff
145 #define MENU_SCREEN_START_XPOS 1
146 #define MENU_SCREEN_START_YPOS 2
147 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
148 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
149 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
150 #define MENU_TITLE1_YPOS 8
151 #define MENU_TITLE2_YPOS 46
152 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
153 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
154 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
155 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
156 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
158 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
159 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
160 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
161 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
162 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
163 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
164 MENU_INFO_FONT_TITLE))
165 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
166 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
167 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
168 MENU_SCREEN_INFO_YSTART2 - \
170 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
171 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
172 MENU_SCREEN_INFO_YSTEP)
173 #define NUM_INFO_ELEMENTS_FROM_CONF \
174 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
175 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
176 MAX_MENU_ENTRIES_ON_SCREEN)
177 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
178 MAX_INFO_ELEMENTS_ON_SCREEN), \
179 NUM_INFO_ELEMENTS_FROM_CONF)
180 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
181 #define MAX_MENU_TEXT_LENGTH_BIG 13
182 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
184 // screen gadget identifiers
185 #define SCREEN_CTRL_ID_PREV_LEVEL 0
186 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
187 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
188 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
189 #define SCREEN_CTRL_ID_FIRST_LEVEL 4
190 #define SCREEN_CTRL_ID_LAST_LEVEL 5
191 #define SCREEN_CTRL_ID_LEVEL_NUMBER 6
192 #define SCREEN_CTRL_ID_PREV_PLAYER 7
193 #define SCREEN_CTRL_ID_NEXT_PLAYER 8
194 #define SCREEN_CTRL_ID_INSERT_SOLUTION 9
195 #define SCREEN_CTRL_ID_PLAY_SOLUTION 10
196 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 11
197 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 12
198 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 13
199 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 14
200 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 15
201 #define SCREEN_CTRL_ID_SCROLL_UP 16
202 #define SCREEN_CTRL_ID_SCROLL_DOWN 17
203 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 18
204 #define SCREEN_CTRL_ID_NETWORK_SERVER 19
206 #define NUM_SCREEN_GADGETS 20
208 #define NUM_SCREEN_MENUBUTTONS 16
209 #define NUM_SCREEN_SCROLLBUTTONS 2
210 #define NUM_SCREEN_SCROLLBARS 1
211 #define NUM_SCREEN_TEXTINPUT 1
213 #define SCREEN_MASK_MAIN (1 << 0)
214 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
215 #define SCREEN_MASK_INPUT (1 << 2)
216 #define SCREEN_MASK_TOUCH (1 << 3)
217 #define SCREEN_MASK_TOUCH2 (1 << 4)
218 #define SCREEN_MASK_SCORES (1 << 5)
220 // graphic position and size values for buttons and scrollbars
221 #define SC_MENUBUTTON_XSIZE TILEX
222 #define SC_MENUBUTTON_YSIZE TILEY
224 #define SC_SCROLLBUTTON_XSIZE TILEX
225 #define SC_SCROLLBUTTON_YSIZE TILEY
227 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
229 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
230 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
231 SC_SCROLLBUTTON_YSIZE)
233 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
234 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
236 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
237 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
238 SC_SCROLLBUTTON_YSIZE)
240 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
241 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
242 SC_SCROLL_VERTICAL_YSIZE)
244 #define SC_BORDER_SIZE 14
247 // forward declarations of internal functions
248 static void HandleScreenGadgets(struct GadgetInfo *);
249 static void HandleSetupScreen_Generic(int, int, int, int, int);
250 static void HandleSetupScreen_Input(int, int, int, int, int);
251 static void CustomizeKeyboard(int);
252 static void ConfigureJoystick(int);
253 static void ConfigureVirtualButtons(void);
254 static void execSetupGame(void);
255 static void execSetupEngines(void);
256 static void execSetupGraphics(void);
257 static void execSetupSound(void);
258 static void execSetupTouch(void);
259 static void execSetupArtwork(void);
260 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
262 static void DrawChoosePlayerName(void);
263 static void DrawChooseLevelSet(void);
264 static void DrawChooseLevelNr(void);
265 static void DrawScoreInfo(int);
266 static void DrawInfoScreen(void);
267 static void DrawSetupScreen(void);
268 static void DrawTypeName(void);
270 static void DrawInfoScreen_NotAvailable(char *, char *);
271 static void DrawInfoScreen_HelpAnim(int, int, boolean);
272 static void DrawInfoScreen_HelpText(int, int, int, int);
273 static void HandleInfoScreen_Main(int, int, int, int, int);
274 static void HandleInfoScreen_TitleScreen(int);
275 static void HandleInfoScreen_Elements(int);
276 static void HandleInfoScreen_Music(int);
277 static void HandleInfoScreen_Credits(int);
278 static void HandleInfoScreen_Program(int);
279 static void HandleInfoScreen_Version(int);
281 static void ModifyGameSpeedIfNeeded(void);
282 static void DisableVsyncIfNeeded(void);
284 static void RedrawScreenMenuGadgets(int);
285 static void MapScreenMenuGadgets(int);
286 static void UnmapScreenMenuGadgets(int);
287 static void MapScreenGadgets(int);
288 static void UnmapScreenGadgets(void);
289 static void MapScreenTreeGadgets(TreeInfo *);
290 static void UnmapScreenTreeGadgets(void);
292 static void UpdateScreenMenuGadgets(int, boolean);
294 static boolean OfferUploadTapes(void);
295 static void execOfferUploadTapes(void);
297 static void DrawHallOfFame_setScoreEntries(void);
298 static void HandleHallOfFame_SelectLevel(int, int);
299 static char *getHallOfFameRankText(int);
300 static char *getHallOfFameScoreText(int);
302 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
304 static int info_mode = INFO_MODE_MAIN;
305 static int setup_mode = SETUP_MODE_MAIN;
307 static TreeInfo *window_sizes = NULL;
308 static TreeInfo *window_size_current = NULL;
310 static TreeInfo *scaling_types = NULL;
311 static TreeInfo *scaling_type_current = NULL;
313 static TreeInfo *rendering_modes = NULL;
314 static TreeInfo *rendering_mode_current = NULL;
316 static TreeInfo *vsync_modes = NULL;
317 static TreeInfo *vsync_mode_current = NULL;
319 static TreeInfo *scroll_delays = NULL;
320 static TreeInfo *scroll_delay_current = NULL;
322 static TreeInfo *snapshot_modes = NULL;
323 static TreeInfo *snapshot_mode_current = NULL;
325 static TreeInfo *scores_types = NULL;
326 static TreeInfo *scores_type_current = NULL;
328 static TreeInfo *game_speeds_normal = NULL;
329 static TreeInfo *game_speeds_extended = NULL;
330 static TreeInfo *game_speeds = NULL;
331 static TreeInfo *game_speed_current = NULL;
333 static TreeInfo *volumes_simple = NULL;
334 static TreeInfo *volume_simple_current = NULL;
336 static TreeInfo *volumes_loops = NULL;
337 static TreeInfo *volume_loops_current = NULL;
339 static TreeInfo *volumes_music = NULL;
340 static TreeInfo *volume_music_current = NULL;
342 static TreeInfo *touch_controls = NULL;
343 static TreeInfo *touch_control_current = NULL;
345 static TreeInfo *move_distances = NULL;
346 static TreeInfo *move_distance_current = NULL;
348 static TreeInfo *drop_distances = NULL;
349 static TreeInfo *drop_distance_current = NULL;
351 static TreeInfo *transparencies = NULL;
352 static TreeInfo *transparency_current = NULL;
354 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
355 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
357 static TreeInfo *player_name = NULL;
358 static TreeInfo *player_name_current = NULL;
360 static TreeInfo *level_number = NULL;
361 static TreeInfo *level_number_current = NULL;
363 static TreeInfo *score_entries = NULL;
364 static TreeInfo *score_entry_current = NULL;
366 static struct ValueTextInfo window_sizes_list[] =
371 { 100, "100 % (Default)" },
384 static struct StringValueTextInfo scaling_types_list[] =
386 { SCALING_QUALITY_NEAREST, "Off" },
387 { SCALING_QUALITY_LINEAR, "Linear" },
388 { SCALING_QUALITY_BEST, "Anisotropic" },
393 static struct StringValueTextInfo rendering_modes_list[] =
395 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
396 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
398 // this mode may work under certain conditions, but does not work on Windows
399 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
401 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
406 static struct StringValueTextInfo vsync_modes_list[] =
408 { STR_VSYNC_MODE_OFF, "Off" },
409 { STR_VSYNC_MODE_NORMAL, "Normal" },
410 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
415 static struct StringValueTextInfo scores_types_list[] =
417 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
418 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
419 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
424 static struct ValueTextInfo game_speeds_list_normal[] =
435 static struct ValueTextInfo game_speeds_list_extended[] =
437 { 1000, "1 fps (Extremely Slow)" },
442 { 29, "35 fps (Original Supaplex)" },
444 { 20, "50 fps (=== Normal Speed ===)" },
445 { 16, "60 fps (60 Hz VSync Speed)" },
446 { 14, "70 fps (Maximum Supaplex)" },
450 { 1, "1000 fps (Extremely Fast)" },
455 static struct ValueTextInfo *game_speeds_list;
457 static struct ValueTextInfo scroll_delays_list[] =
459 { 0, "0 Tiles (No Scroll Delay)" },
462 { 3, "3 Tiles (Default)" },
467 { 8, "8 Tiles (Maximum Scroll Delay)"},
472 static struct StringValueTextInfo snapshot_modes_list[] =
474 { STR_SNAPSHOT_MODE_OFF, "Off" },
475 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
476 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
477 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
482 static struct ValueTextInfo volumes_list[] =
502 static struct StringValueTextInfo touch_controls_list[] =
504 { TOUCH_CONTROL_OFF, "Off" },
505 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
506 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
507 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
512 static struct ValueTextInfo distances_list[] =
527 static struct ValueTextInfo transparencies_list[] =
529 { 0, "0 % (Opaque)" },
539 { 100, "100 % (Invisible)" },
544 static struct ValueTextInfo grid_sizes_list[] =
580 static int align_xoffset = 0;
581 static int align_yoffset = 0;
583 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
584 (s) <= GAME_MODE_SETUP ? (s) : \
585 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
587 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
588 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
590 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
591 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
592 (i) <= INFO_MODE_LEVELSET ? (i) : \
595 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
596 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
597 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
598 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
599 SETUP_MODE_CHOOSE_ARTWORK : \
600 SETUP_MODE_CHOOSE_OTHER)
602 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
603 menu.draw_xoffset[GAME_MODE_INFO] : \
604 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
605 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
606 menu.draw_yoffset[GAME_MODE_INFO] : \
607 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
608 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
609 menu.extra_spacing[GAME_MODE_INFO] : \
610 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
612 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
613 menu.draw_xoffset[GAME_MODE_SETUP] : \
614 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
615 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
616 menu.draw_yoffset[GAME_MODE_SETUP] : \
617 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
618 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
619 menu.extra_spacing[GAME_MODE_SETUP] : \
620 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
622 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
624 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
626 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
627 DRAW_XOFFSET_INFO(info_mode) : \
628 (s) == GAME_MODE_SETUP ? \
629 DRAW_XOFFSET_SETUP(setup_mode) : \
630 menu.draw_xoffset[DRAW_MODE(s)])
631 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
632 DRAW_YOFFSET_INFO(info_mode) : \
633 (s) == GAME_MODE_SETUP ? \
634 DRAW_YOFFSET_SETUP(setup_mode) : \
635 menu.draw_yoffset[DRAW_MODE(s)])
636 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
637 EXTRA_SPACING_INFO(info_mode) : \
638 (s) == GAME_MODE_SETUP ? \
639 EXTRA_SPACING_SETUP(setup_mode) : \
640 (s) == GAME_MODE_SCORES ? \
641 EXTRA_SPACING_SCORES(info_mode) : \
642 menu.extra_spacing[DRAW_MODE(s)])
644 #define mSX (SX + DRAW_XOFFSET(game_status))
645 #define mSY (SY + DRAW_YOFFSET(game_status))
647 #define amSX (mSX + align_xoffset)
648 #define amSY (mSY + align_yoffset)
650 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
651 menu.list_size[game_status] : \
652 MAX_MENU_ENTRIES_ON_SCREEN)
654 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
655 NUM_MENU_ENTRIES_ON_SCREEN)
658 // title display and control definitions
660 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
661 2 * MAX_NUM_TITLE_MESSAGES)
663 #define NO_DIRECT_LEVEL_SELECT (-1)
666 static int num_title_screens = 0;
668 struct TitleControlInfo
677 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
679 // main menu display and control definitions
681 #define MAIN_CONTROL_NAME 0
682 #define MAIN_CONTROL_LEVELS 1
683 #define MAIN_CONTROL_SCORES 2
684 #define MAIN_CONTROL_EDITOR 3
685 #define MAIN_CONTROL_INFO 4
686 #define MAIN_CONTROL_GAME 5
687 #define MAIN_CONTROL_SETUP 6
688 #define MAIN_CONTROL_QUIT 7
689 #define MAIN_CONTROL_PREV_LEVEL 8
690 #define MAIN_CONTROL_NEXT_LEVEL 9
691 #define MAIN_CONTROL_FIRST_LEVEL 10
692 #define MAIN_CONTROL_LAST_LEVEL 11
693 #define MAIN_CONTROL_LEVEL_NUMBER 12
694 #define MAIN_CONTROL_LEVEL_INFO_1 13
695 #define MAIN_CONTROL_LEVEL_INFO_2 14
696 #define MAIN_CONTROL_LEVEL_NAME 15
697 #define MAIN_CONTROL_LEVEL_AUTHOR 16
698 #define MAIN_CONTROL_LEVEL_YEAR 17
699 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
700 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
701 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
702 #define MAIN_CONTROL_TITLE_1 21
703 #define MAIN_CONTROL_TITLE_2 22
704 #define MAIN_CONTROL_TITLE_3 23
706 static char str_main_text_name[10];
707 static char str_main_text_first_level[10];
708 static char str_main_text_last_level[10];
709 static char str_main_text_level_number[10];
711 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
713 static char *main_text_name = str_main_text_name;
714 static char *main_text_first_level = str_main_text_first_level;
715 static char *main_text_last_level = str_main_text_last_level;
716 static char *main_text_level_number = str_main_text_level_number;
717 static char *main_text_levels = "Levelset";
718 static char *main_text_scores = "Hall Of Fame";
719 static char *main_text_editor = "Level Creator";
720 static char *main_text_info = "Info Screen";
721 static char *main_text_game = "Start Game";
722 static char *main_text_setup = "Setup";
723 static char *main_text_quit = "Quit";
724 static char *main_text_level_name = level.name;
725 static char *main_text_level_author = level.author;
726 static char *main_text_level_year = NULL;
727 static char *main_text_level_imported_from = NULL;
728 static char *main_text_level_imported_by = NULL;
729 static char *main_text_level_tested_by = NULL;
730 static char *main_text_title_1 = NULL;
731 static char *main_text_title_2 = NULL;
732 static char *main_text_title_3 = NULL;
734 extern char debug_xsn_mode[];
736 struct MainControlInfo
740 struct MenuPosInfo *pos_button;
743 struct TextPosInfo *pos_text;
746 struct TextPosInfo *pos_input;
750 static struct MainControlInfo main_controls[] =
754 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
755 &menu.main.text.name, &main_text_name,
756 &menu.main.input.name, &setup.player_name,
760 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
761 &menu.main.text.levels, &main_text_levels,
766 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
767 &menu.main.text.scores, &main_text_scores,
772 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
773 &menu.main.text.editor, &main_text_editor,
778 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
779 &menu.main.text.info, &main_text_info,
784 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
785 &menu.main.text.game, &main_text_game,
790 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
791 &menu.main.text.setup, &main_text_setup,
796 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
797 &menu.main.text.quit, &main_text_quit,
801 MAIN_CONTROL_PREV_LEVEL,
807 MAIN_CONTROL_NEXT_LEVEL,
813 MAIN_CONTROL_FIRST_LEVEL,
815 &menu.main.text.first_level, &main_text_first_level,
819 MAIN_CONTROL_LAST_LEVEL,
821 &menu.main.text.last_level, &main_text_last_level,
825 MAIN_CONTROL_LEVEL_NUMBER,
827 &menu.main.text.level_number, &main_text_level_number,
831 MAIN_CONTROL_LEVEL_INFO_1,
833 &menu.main.text.level_info_1, NULL,
837 MAIN_CONTROL_LEVEL_INFO_2,
839 &menu.main.text.level_info_2, NULL,
843 MAIN_CONTROL_LEVEL_NAME,
845 &menu.main.text.level_name, &main_text_level_name,
849 MAIN_CONTROL_LEVEL_AUTHOR,
851 &menu.main.text.level_author, &main_text_level_author,
855 MAIN_CONTROL_LEVEL_YEAR,
857 &menu.main.text.level_year, &main_text_level_year,
861 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
863 &menu.main.text.level_imported_from, &main_text_level_imported_from,
867 MAIN_CONTROL_LEVEL_IMPORTED_BY,
869 &menu.main.text.level_imported_by, &main_text_level_imported_by,
873 MAIN_CONTROL_LEVEL_TESTED_BY,
875 &menu.main.text.level_tested_by, &main_text_level_tested_by,
879 MAIN_CONTROL_TITLE_1,
881 &menu.main.text.title_1, &main_text_title_1,
885 MAIN_CONTROL_TITLE_2,
887 &menu.main.text.title_2, &main_text_title_2,
891 MAIN_CONTROL_TITLE_3,
893 &menu.main.text.title_3, &main_text_title_3,
906 static int getTitleScreenGraphic(int nr, boolean initial)
908 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
911 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
913 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
917 static int getTitleScreenGameMode(boolean initial)
919 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
923 static int getTitleMessageGameMode(boolean initial)
925 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
928 static int getTitleAnimMode(struct TitleControlInfo *tci)
930 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
932 return base + tci->local_nr;
936 static int getTitleScreenBackground(boolean initial)
938 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
943 static int getTitleMessageBackground(int nr, boolean initial)
945 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
949 static int getTitleBackground(int nr, boolean initial, boolean is_image)
951 int base = (is_image ?
952 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
953 IMG_BACKGROUND_TITLESCREEN_1) :
954 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
955 IMG_BACKGROUND_TITLEMESSAGE_1));
956 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
957 IMG_BACKGROUND_TITLE);
958 int graphic_local = base + nr;
960 if (graphic_info[graphic_local].bitmap != NULL)
961 return graphic_local;
963 if (graphic_info[graphic_global].bitmap != NULL)
964 return graphic_global;
966 return IMG_UNDEFINED;
969 static int getTitleSound(struct TitleControlInfo *tci)
971 boolean is_image = tci->is_image;
972 int initial = tci->initial;
973 int nr = tci->local_nr;
974 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
975 int base = (is_image ?
976 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
977 SND_BACKGROUND_TITLESCREEN_1) :
978 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
979 SND_BACKGROUND_TITLEMESSAGE_1));
980 int sound_global = menu.sound[mode];
981 int sound_local = base + nr;
984 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
985 nr, initial, is_image,
986 sound_global, getSoundListEntry(sound_global)->filename,
987 sound_local, getSoundListEntry(sound_local)->filename);
990 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
993 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
996 return SND_UNDEFINED;
999 static int getTitleMusic(struct TitleControlInfo *tci)
1001 boolean is_image = tci->is_image;
1002 int initial = tci->initial;
1003 int nr = tci->local_nr;
1004 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1005 int base = (is_image ?
1006 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1007 MUS_BACKGROUND_TITLESCREEN_1) :
1008 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1009 MUS_BACKGROUND_TITLEMESSAGE_1));
1010 int music_global = menu.music[mode];
1011 int music_local = base + nr;
1014 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1015 nr, initial, is_image,
1016 music_global, getMusicListEntry(music_global)->filename,
1017 music_local, getMusicListEntry(music_local)->filename);
1020 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1023 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1024 return music_global;
1026 return MUS_UNDEFINED;
1029 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1031 boolean is_image = tci->is_image;
1032 boolean initial = tci->initial;
1033 boolean first = tci->first;
1034 int nr = tci->local_nr;
1035 struct TitleMessageInfo tmi;
1036 struct TitleFadingInfo ti;
1038 tmi = (is_image ? (initial ? (first ?
1039 titlescreen_initial_first[nr] :
1040 titlescreen_initial[nr])
1042 titlescreen_first[nr] :
1044 : (initial ? (first ?
1045 titlemessage_initial_first[nr] :
1046 titlemessage_initial[nr])
1048 titlemessage_first[nr] :
1049 titlemessage[nr])));
1051 ti.fade_mode = tmi.fade_mode;
1052 ti.fade_delay = tmi.fade_delay;
1053 ti.post_delay = tmi.post_delay;
1054 ti.auto_delay = tmi.auto_delay;
1055 ti.auto_delay_unit = tmi.auto_delay_unit;
1060 static int compareTitleControlInfo(const void *object1, const void *object2)
1062 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1063 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1066 if (tci1->initial != tci2->initial)
1067 compare_result = (tci1->initial ? -1 : +1);
1068 else if (tci1->sort_priority != tci2->sort_priority)
1069 compare_result = tci1->sort_priority - tci2->sort_priority;
1070 else if (tci1->is_image != tci2->is_image)
1071 compare_result = (tci1->is_image ? -1 : +1);
1073 compare_result = tci1->local_nr - tci2->local_nr;
1075 return compare_result;
1078 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1080 int nr, int sort_priority)
1082 title_controls[num_title_screens].is_image = is_image;
1083 title_controls[num_title_screens].initial = initial;
1084 title_controls[num_title_screens].local_nr = nr;
1085 title_controls[num_title_screens].sort_priority = sort_priority;
1087 title_controls[num_title_screens].first = FALSE; // will be set later
1089 num_title_screens++;
1092 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1096 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1098 int graphic = getTitleScreenGraphic(i, initial);
1099 Bitmap *bitmap = graphic_info[graphic].bitmap;
1100 int sort_priority = graphic_info[graphic].sort_priority;
1103 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1106 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1108 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1109 char *filename = getLevelSetTitleMessageFilename(i, initial);
1110 int sort_priority = tmi->sort_priority;
1112 if (filename != NULL)
1113 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1117 static void InitializeTitleControls(boolean show_title_initial)
1119 num_title_screens = 0;
1121 // 1st step: initialize title screens for game start (only when starting)
1122 if (show_title_initial)
1123 InitializeTitleControls_CheckTitleInfo(TRUE);
1125 // 2nd step: initialize title screens for current level set
1126 InitializeTitleControls_CheckTitleInfo(FALSE);
1128 // sort title screens according to sort_priority and title number
1129 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1130 compareTitleControlInfo);
1132 // mark first title screen
1133 title_controls[0].first = TRUE;
1136 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1138 return (pos != NULL && pos->x != -1 && pos->y != -1);
1141 static boolean visibleTextPos(struct TextPosInfo *pos)
1143 return (pos != NULL && pos->x != -1 && pos->y != -1);
1146 static void InitializeMainControls(void)
1148 boolean local_team_mode = (!network.enabled && setup.team_mode);
1151 // set main control text values to dynamically determined values
1152 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1154 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1155 menu.main.text.first_level.size));
1156 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1157 menu.main.text.last_level.size));
1158 strcpy(main_text_level_number, int2str(level_nr,
1159 menu.main.text.level_number.size));
1161 main_text_level_year = leveldir_current->year;
1162 main_text_level_imported_from = leveldir_current->imported_from;
1163 main_text_level_imported_by = leveldir_current->imported_by;
1164 main_text_level_tested_by = leveldir_current->tested_by;
1166 main_text_title_1 = getConfigProgramTitleString();
1167 main_text_title_2 = getConfigProgramCopyrightString();
1168 main_text_title_3 = getConfigProgramCompanyString();
1170 // set main control screen positions to dynamically determined values
1171 for (i = 0; main_controls[i].nr != -1; i++)
1173 struct MainControlInfo *mci = &main_controls[i];
1175 struct MenuPosInfo *pos_button = mci->pos_button;
1176 struct TextPosInfo *pos_text = mci->pos_text;
1177 struct TextPosInfo *pos_input = mci->pos_input;
1178 char *text = (mci->text ? *mci->text : NULL);
1179 char *input = (mci->input ? *mci->input : NULL);
1180 int button_graphic = mci->button_graphic;
1181 int font_text = (pos_text ? pos_text->font : -1);
1182 int font_input = (pos_input ? pos_input->font : -1);
1184 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1185 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1186 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1187 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1188 int text_chars = (text != NULL ? strlen(text) : 0);
1189 int input_chars = (input != NULL ? strlen(input) : 0);
1192 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1194 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1195 int text_width = font_text_width * text_chars;
1196 int text_height = font_text_height;
1197 int input_width = font_input_width * input_chars;
1198 int input_height = font_input_height;
1200 if (nr == MAIN_CONTROL_NAME)
1202 menu.main.input.name.width = input_width;
1203 menu.main.input.name.height = input_height;
1206 if (pos_button != NULL) // (x/y may be -1/-1 here)
1208 pos_button->width = button_width;
1209 pos_button->height = button_height;
1212 if (pos_text != NULL) // (x/y may be -1/-1 here)
1214 // calculate text size -- needed for text alignment
1215 boolean calculate_text_size = (text != NULL);
1217 if (pos_text->width == -1 || calculate_text_size)
1218 pos_text->width = text_width;
1219 if (pos_text->height == -1 || calculate_text_size)
1220 pos_text->height = text_height;
1222 if (visibleMenuPos(pos_button))
1224 if (pos_text->x == -1)
1225 pos_text->x = pos_button->x + pos_button->width;
1226 if (pos_text->y == -1)
1228 pos_button->y + (pos_button->height - pos_text->height) / 2;
1232 if (pos_input != NULL) // (x/y may be -1/-1 here)
1234 if (visibleTextPos(pos_text))
1236 if (pos_input->x == -1)
1237 pos_input->x = pos_text->x + pos_text->width;
1238 if (pos_input->y == -1)
1239 pos_input->y = pos_text->y;
1242 if (pos_input->width == -1)
1243 pos_input->width = input_width;
1244 if (pos_input->height == -1)
1245 pos_input->height = input_height;
1250 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1251 int graphic, boolean pressed)
1253 struct GraphicInfo *g = &graphic_info[graphic];
1256 int xoffset = (pressed ? g->pressed_xoffset : 0);
1257 int yoffset = (pressed ? g->pressed_yoffset : 0);
1259 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1261 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1262 g->width, g->height, dst_x, dst_y);
1265 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1266 boolean active_input,
1267 boolean pressed_button)
1271 for (i = 0; main_controls[i].nr != -1; i++)
1273 struct MainControlInfo *mci = &main_controls[i];
1275 if (mci->nr == nr || nr == -1)
1277 struct MenuPosInfo *pos_button = mci->pos_button;
1278 struct TextPosInfo *pos_text = mci->pos_text;
1279 struct TextPosInfo *pos_input = mci->pos_input;
1280 char *text = (mci->text ? *mci->text : NULL);
1281 char *input = (mci->input ? *mci->input : NULL);
1282 int button_graphic = mci->button_graphic;
1283 int font_text = (pos_text ? pos_text->font : -1);
1284 int font_input = (pos_input ? pos_input->font : -1);
1288 button_graphic = BUTTON_ACTIVE(button_graphic);
1289 font_text = FONT_ACTIVE(font_text);
1294 font_input = FONT_ACTIVE(font_input);
1297 if (visibleMenuPos(pos_button))
1299 struct MenuPosInfo *pos = pos_button;
1300 int x = mSX + pos->x;
1301 int y = mSY + pos->y;
1303 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1304 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1307 if (visibleTextPos(pos_text) && text != NULL)
1309 struct TextPosInfo *pos = pos_text;
1310 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1311 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1314 // (check why/if this is needed)
1315 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1317 DrawText(x, y, text, font_text);
1320 if (visibleTextPos(pos_input) && input != NULL)
1322 struct TextPosInfo *pos = pos_input;
1323 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1324 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1327 // (check why/if this is needed)
1328 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1330 DrawText(x, y, input, font_input);
1336 static void DrawCursorAndText_Main(int nr, boolean active_text,
1337 boolean pressed_button)
1339 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1343 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1344 boolean pressed_button)
1346 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1350 static struct MainControlInfo *getMainControlInfo(int nr)
1354 for (i = 0; main_controls[i].nr != -1; i++)
1355 if (main_controls[i].nr == nr)
1356 return &main_controls[i];
1361 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1366 int rect_x = ALIGNED_TEXT_XPOS(rect);
1367 int rect_y = ALIGNED_TEXT_YPOS(rect);
1369 return (x >= rect_x && x < rect_x + rect->width &&
1370 y >= rect_y && y < rect_y + rect->height);
1373 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1378 int rect_x = ALIGNED_TEXT_XPOS(rect);
1379 int rect_y = ALIGNED_TEXT_YPOS(rect);
1382 Debug("screens:insideTextPosRect",
1383 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1384 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1385 (x >= rect_x && x < rect_x + rect->width &&
1386 y >= rect_y && y < rect_y + rect->height));
1389 return (x >= rect_x && x < rect_x + rect->width &&
1390 y >= rect_y && y < rect_y + rect->height);
1393 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1395 int rect_width = preview->xsize * preview->tile_size;
1396 int rect_height = preview->ysize * preview->tile_size;
1397 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1398 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1400 return (x >= rect_x && x < rect_x + rect_width &&
1401 y >= rect_y && y < rect_y + rect_height);
1404 static void AdjustScrollbar(int id, int items_max, int items_visible,
1407 struct GadgetInfo *gi = screen_gadget[id];
1409 if (item_position > items_max - items_visible)
1410 item_position = items_max - items_visible;
1412 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1413 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1414 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1417 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1419 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1423 static void clearMenuListArea(void)
1425 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1427 // correct scrollbar position if placed outside menu (playfield) area
1428 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1429 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1431 // clear menu list area, but not title or scrollbar
1432 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1433 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1436 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1438 static int cursor_array[MAX_LEV_FIELDY];
1439 int x = amSX + TILEX * xpos;
1440 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1445 cursor_array[ypos] = graphic;
1447 graphic = cursor_array[ypos];
1451 graphic = BUTTON_ACTIVE(graphic);
1453 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1454 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1457 static void initCursor(int ypos, int graphic)
1459 drawCursorExt(0, ypos, FALSE, graphic);
1462 static void drawCursor(int ypos, boolean active)
1464 drawCursorExt(0, ypos, active, -1);
1467 static void drawCursorXY(int xpos, int ypos, int graphic)
1469 drawCursorExt(xpos, ypos, FALSE, graphic);
1472 static void drawChooseTreeCursor(int ypos, boolean active)
1474 drawCursorExt(0, ypos, active, -1);
1477 static int getChooseTreeEditFont(boolean active)
1479 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1482 static int getChooseTreeEditXPos(int pos)
1484 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1485 int xoffset = (has_scrollbar ? -1 : 0);
1486 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1487 int sx = amSX + xpos * TILEX;
1488 int font_nr = getChooseTreeEditFont(FALSE);
1489 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1491 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1494 static int getChooseTreeEditYPos(int ypos_raw)
1496 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1497 int sy = amSY + ypos * TILEY;
1502 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1504 int sx = getChooseTreeEditXPos(POS_LEFT);
1505 int sy = getChooseTreeEditYPos(ypos_raw);
1506 int font_nr = getChooseTreeEditFont(active);
1508 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1511 static void DrawHeadline(void)
1513 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1514 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1517 static void DrawTitleScreenImage(int nr, boolean initial)
1519 int graphic = getTitleScreenGraphic(nr, initial);
1520 Bitmap *bitmap = graphic_info[graphic].bitmap;
1521 int width = graphic_info[graphic].width;
1522 int height = graphic_info[graphic].height;
1523 int src_x = graphic_info[graphic].src_x;
1524 int src_y = graphic_info[graphic].src_y;
1530 if (width > WIN_XSIZE)
1532 // image width too large for window => center image horizontally
1533 src_x = (width - WIN_XSIZE) / 2;
1537 if (height > WIN_YSIZE)
1539 // image height too large for window => center image vertically
1540 src_y = (height - WIN_YSIZE) / 2;
1544 // always display title screens centered
1545 dst_x = (WIN_XSIZE - width) / 2;
1546 dst_y = (WIN_YSIZE - height) / 2;
1548 SetDrawBackgroundMask(REDRAW_ALL);
1549 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1551 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1553 if (DrawingOnBackground(dst_x, dst_y))
1554 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1556 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1558 redraw_mask = REDRAW_ALL;
1561 static void DrawTitleScreenMessage(int nr, boolean initial)
1563 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1564 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1566 if (filename == NULL)
1569 // force TITLE font on title message screen
1570 SetFontStatus(getTitleMessageGameMode(initial));
1572 // if chars *and* width set to "-1", automatically determine width
1573 if (tmi->chars == -1 && tmi->width == -1)
1574 tmi->width = viewport.window[game_status].width;
1576 // if lines *and* height set to "-1", automatically determine height
1577 if (tmi->lines == -1 && tmi->height == -1)
1578 tmi->height = viewport.window[game_status].height;
1580 // if chars set to "-1", automatically determine by text and font width
1581 if (tmi->chars == -1)
1582 tmi->chars = tmi->width / getFontWidth(tmi->font);
1584 tmi->width = tmi->chars * getFontWidth(tmi->font);
1586 // if lines set to "-1", automatically determine by text and font height
1587 if (tmi->lines == -1)
1588 tmi->lines = tmi->height / getFontHeight(tmi->font);
1590 tmi->height = tmi->lines * getFontHeight(tmi->font);
1592 // if x set to "-1", automatically determine by width and alignment
1594 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1596 // if y set to "-1", automatically determine by height and alignment
1598 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1600 SetDrawBackgroundMask(REDRAW_ALL);
1601 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1603 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1605 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1606 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1607 tmi->autowrap, tmi->centered, tmi->parse_comments);
1612 static void DrawTitleScreen(void)
1614 KeyboardAutoRepeatOff();
1616 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1619 static boolean CheckTitleScreen(boolean levelset_has_changed)
1621 static boolean show_title_initial = TRUE;
1622 boolean show_titlescreen = FALSE;
1624 // needed to be able to skip title screen, if no image or message defined
1625 InitializeTitleControls(show_title_initial);
1627 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1628 show_titlescreen = TRUE;
1630 // show initial title images and messages only once at program start
1631 show_title_initial = FALSE;
1633 return (show_titlescreen && num_title_screens > 0);
1636 void DrawMainMenu(void)
1638 static LevelDirTree *leveldir_last_valid = NULL;
1639 boolean levelset_has_changed = FALSE;
1640 int fade_mask = REDRAW_FIELD;
1642 LimitScreenUpdates(FALSE);
1644 FadeSetLeaveScreen();
1646 // do not fade out here -- function may continue and fade on editor screen
1649 FadeMenuSoundsAndMusic();
1651 ExpireSoundLoops(FALSE);
1653 KeyboardAutoRepeatOn();
1655 audio.sound_deactivated = FALSE;
1659 // needed if last screen was the playing screen, invoked from level editor
1660 if (level_editor_test_game)
1662 CloseDoor(DOOR_CLOSE_ALL);
1664 SetGameStatus(GAME_MODE_EDITOR);
1671 // leveldir_current may be invalid (level group, parent link, node copy)
1672 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1674 if (leveldir_current != leveldir_last_valid)
1676 UpdateLastPlayedLevels_TreeInfo();
1678 levelset_has_changed = TRUE;
1681 // store valid level series information
1682 leveldir_last_valid = leveldir_current;
1684 init_last = init; // switch to new busy animation
1686 // needed if last screen (level choice) changed graphics, sounds or music
1687 ReloadCustomArtwork(0);
1689 if (CheckTitleScreen(levelset_has_changed))
1691 SetGameStatus(GAME_MODE_TITLE);
1698 if (redraw_mask & REDRAW_ALL)
1699 fade_mask = REDRAW_ALL;
1702 fade_mask = REDRAW_ALL;
1706 // needed if different viewport properties defined for menues
1707 ChangeViewportPropertiesIfNeeded();
1709 SetDrawtoField(DRAW_TO_BACKBUFFER);
1711 // level_nr may have been set to value over handicap with level editor
1712 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1713 level_nr = leveldir_current->handicap_level;
1715 LoadLevel(level_nr);
1716 LoadScore(level_nr);
1718 SaveLevelSetup_SeriesInfo();
1720 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1721 SetDrawDeactivationMask(REDRAW_NONE);
1722 SetDrawBackgroundMask(REDRAW_FIELD);
1724 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1727 if (fade_mask == REDRAW_ALL)
1728 RedrawGlobalBorder();
1733 InitializeMainControls();
1735 DrawCursorAndText_Main(-1, FALSE, FALSE);
1736 DrawPreviewLevelInitial();
1737 DrawNetworkPlayers();
1739 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1742 if (TAPE_IS_EMPTY(tape))
1744 DrawCompleteVideoDisplay();
1746 PlayMenuSoundsAndMusic();
1748 // create gadgets for main menu screen
1749 FreeScreenGadgets();
1750 CreateScreenGadgets();
1752 // may be required if audio buttons shown on tape and changed in setup menu
1754 CreateGameButtons();
1756 // map gadgets for main menu screen
1758 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1759 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1761 // copy actual game door content to door double buffer for OpenDoor()
1762 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1763 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1765 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1767 DrawMaskedBorder(fade_mask);
1772 // update screen area with special editor door
1773 redraw_mask |= REDRAW_ALL;
1776 SetMouseCursor(CURSOR_DEFAULT);
1778 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1780 SyncEmscriptenFilesystem();
1782 // needed once after program start or after user change
1783 CheckApiServerTasks();
1786 static void gotoTopLevelDir(void)
1788 // move upwards until inside (but not above) top level directory
1789 while (leveldir_current->node_parent &&
1790 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1792 // write a "path" into level tree for easy navigation to last level
1793 if (leveldir_current->node_parent->node_group->cl_first == -1)
1795 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1796 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1797 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1798 int cl_first, cl_cursor;
1800 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1801 cl_cursor = leveldir_pos - cl_first;
1803 leveldir_current->node_parent->node_group->cl_first = cl_first;
1804 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1807 leveldir_current = leveldir_current->node_parent;
1811 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1813 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1815 return (use_frame_counter ? video.frame_counter : Counter());
1818 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1819 struct TitleFadingInfo *fi)
1821 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1824 static void ResetTitleAutoDelay(unsigned int *counter_var,
1825 struct TitleFadingInfo *fi)
1827 *counter_var = getAutoDelayCounter(fi);
1830 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1832 static unsigned int title_delay = 0;
1833 static int title_screen_nr = 0;
1834 static int last_sound = -1, last_music = -1;
1835 boolean return_to_main_menu = FALSE;
1836 struct TitleControlInfo *tci;
1839 if (button == MB_MENU_INITIALIZE)
1842 title_screen_nr = 0;
1843 tci = &title_controls[title_screen_nr];
1845 SetAnimStatus(getTitleAnimMode(tci));
1847 last_sound = SND_UNDEFINED;
1848 last_music = MUS_UNDEFINED;
1850 if (num_title_screens != 0)
1852 FadeSetEnterScreen();
1854 // use individual title fading instead of global "enter screen" fading
1855 fading = getTitleFading(tci);
1858 if (game_status_last_screen == GAME_MODE_INFO)
1860 if (num_title_screens == 0)
1862 // switch game mode from title screen mode back to info screen mode
1863 SetGameStatus(GAME_MODE_INFO);
1865 // store that last screen was info screen, not main menu screen
1866 game_status_last_screen = GAME_MODE_INFO;
1868 DrawInfoScreen_NotAvailable("Title screen information:",
1869 "No title screen for this level set.");
1874 FadeMenuSoundsAndMusic();
1876 FadeOut(REDRAW_ALL);
1878 // title screens may have different window size
1879 ChangeViewportPropertiesIfNeeded();
1881 // only required to update logic for redrawing global border
1885 DrawTitleScreenImage(tci->local_nr, tci->initial);
1887 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1889 sound = getTitleSound(tci);
1890 music = getTitleMusic(tci);
1892 if (sound != last_sound)
1893 PlayMenuSoundExt(sound);
1894 if (music != last_music)
1895 PlayMenuMusicExt(music);
1900 SetMouseCursor(CURSOR_NONE);
1904 ResetTitleAutoDelay(&title_delay, &fading);
1909 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1910 button = MB_MENU_CHOICE;
1912 if (button == MB_MENU_LEAVE)
1914 return_to_main_menu = TRUE;
1916 else if (button == MB_MENU_CHOICE)
1918 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1920 SetGameStatus(GAME_MODE_INFO);
1922 info_mode = INFO_MODE_MAIN;
1931 if (title_screen_nr < num_title_screens)
1933 tci = &title_controls[title_screen_nr];
1935 SetAnimStatus(getTitleAnimMode(tci));
1937 sound = getTitleSound(tci);
1938 music = getTitleMusic(tci);
1940 if (last_sound != SND_UNDEFINED && sound != last_sound)
1941 FadeSound(last_sound);
1942 if (last_music != MUS_UNDEFINED && music != last_music)
1945 fading = getTitleFading(tci);
1947 FadeOut(REDRAW_ALL);
1950 DrawTitleScreenImage(tci->local_nr, tci->initial);
1952 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1954 sound = getTitleSound(tci);
1955 music = getTitleMusic(tci);
1957 if (sound != last_sound)
1958 PlayMenuSoundExt(sound);
1959 if (music != last_music)
1960 PlayMenuMusicExt(music);
1967 ResetTitleAutoDelay(&title_delay, &fading);
1971 FadeMenuSoundsAndMusic();
1973 return_to_main_menu = TRUE;
1977 if (return_to_main_menu)
1979 SetMouseCursor(CURSOR_DEFAULT);
1981 // force full menu screen redraw after displaying title screens
1982 redraw_mask = REDRAW_ALL;
1984 if (game_status_last_screen == GAME_MODE_INFO)
1986 SetGameStatus(GAME_MODE_INFO);
1988 info_mode = INFO_MODE_MAIN;
1992 else // default: return to main menu
1994 SetGameStatus(GAME_MODE_MAIN);
2001 static void HandleMainMenu_ToggleTeamMode(void)
2003 setup.team_mode = !setup.team_mode;
2005 InitializeMainControls();
2006 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2008 DrawPreviewPlayers();
2011 static void HandleMainMenu_SelectLevel(int step, int direction,
2012 int selected_level_nr)
2014 int old_level_nr = level_nr;
2017 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2018 new_level_nr = selected_level_nr;
2020 new_level_nr = old_level_nr + step * direction;
2022 if (new_level_nr < leveldir_current->first_level)
2023 new_level_nr = leveldir_current->first_level;
2024 if (new_level_nr > leveldir_current->last_level)
2025 new_level_nr = leveldir_current->last_level;
2027 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2029 // skipping levels is only allowed when trying to skip single level
2030 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2031 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2033 leveldir_current->handicap_level++;
2034 SaveLevelSetup_SeriesInfo();
2037 new_level_nr = leveldir_current->handicap_level;
2040 if (new_level_nr != old_level_nr)
2042 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2044 PlaySound(SND_MENU_ITEM_SELECTING);
2046 level_nr = new_level_nr;
2048 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2049 int2str(level_nr, menu.main.text.level_number.size),
2050 mci->pos_text->font);
2052 LoadLevel(level_nr);
2053 DrawPreviewLevelInitial();
2057 DrawCompleteVideoDisplay();
2059 SaveLevelSetup_SeriesInfo();
2061 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2063 // force redraw of playfield area (may be reset at this point)
2064 redraw_mask |= REDRAW_FIELD;
2068 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2070 static int choice = MAIN_CONTROL_GAME;
2071 static boolean button_pressed_last = FALSE;
2072 boolean button_pressed = FALSE;
2074 int i = 0; // needed to prevent compiler warning due to bad code below
2076 if (button == MB_MENU_INITIALIZE)
2078 DrawCursorAndText_Main(choice, TRUE, FALSE);
2083 if (mx || my) // mouse input
2087 for (i = 0; main_controls[i].nr != -1; i++)
2089 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2090 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2091 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2093 pos = main_controls[i].nr;
2099 // check if level preview was clicked
2100 if (insidePreviewRect(&preview, mx - SX, my - SY))
2101 pos = MAIN_CONTROL_GAME;
2103 // handle pressed/unpressed state for active/inactive menu buttons
2104 // (if pos != -1, "i" contains index position corresponding to "pos")
2106 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2107 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2108 button_pressed = TRUE;
2110 if (button_pressed != button_pressed_last)
2112 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2115 PlaySound(SND_MENU_BUTTON_PRESSING);
2117 PlaySound(SND_MENU_BUTTON_RELEASING);
2120 else if (dx || dy) // keyboard input
2122 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2123 choice == MAIN_CONTROL_SETUP))
2124 button = MB_MENU_CHOICE;
2129 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2131 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2133 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2135 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2137 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2139 CloseDoor(DOOR_CLOSE_2);
2141 SetGameStatus(GAME_MODE_LEVELNR);
2143 DrawChooseLevelNr();
2145 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2151 PlaySound(SND_MENU_ITEM_ACTIVATING);
2153 DrawCursorAndText_Main(choice, FALSE, FALSE);
2154 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2160 if (choice == MAIN_CONTROL_NAME)
2162 // special case: cursor left or right pressed -- toggle team mode
2163 HandleMainMenu_ToggleTeamMode();
2165 else if (choice != MAIN_CONTROL_INFO &&
2166 choice != MAIN_CONTROL_SETUP)
2168 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2174 PlaySound(SND_MENU_ITEM_SELECTING);
2176 if (pos == MAIN_CONTROL_NAME)
2179 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2181 // special case: menu text "name/team" clicked -- toggle team mode
2182 HandleMainMenu_ToggleTeamMode();
2186 if (setup.multiple_users)
2188 CloseDoor(DOOR_CLOSE_2);
2190 SetGameStatus(GAME_MODE_NAMES);
2192 DrawChoosePlayerName();
2196 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2202 else if (pos == MAIN_CONTROL_LEVELS)
2206 CloseDoor(DOOR_CLOSE_2);
2208 SetGameStatus(GAME_MODE_LEVELS);
2210 SaveLevelSetup_LastSeries();
2211 SaveLevelSetup_SeriesInfo();
2213 // restore level set if chosen from "last played level set" menu
2214 RestoreLastPlayedLevels(&leveldir_current);
2216 if (setup.internal.choose_from_top_leveldir)
2219 DrawChooseLevelSet();
2222 else if (pos == MAIN_CONTROL_SCORES)
2224 CloseDoor(DOOR_CLOSE_2);
2226 SetGameStatus(GAME_MODE_SCORES);
2228 DrawHallOfFame(level_nr);
2230 else if (pos == MAIN_CONTROL_EDITOR)
2232 if (leveldir_current->readonly &&
2233 setup.editor.show_read_only_warning)
2234 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2236 CloseDoor(DOOR_CLOSE_ALL);
2238 SetGameStatus(GAME_MODE_EDITOR);
2240 FadeSetEnterScreen();
2244 else if (pos == MAIN_CONTROL_INFO)
2246 CloseDoor(DOOR_CLOSE_2);
2248 SetGameStatus(GAME_MODE_INFO);
2250 info_mode = INFO_MODE_MAIN;
2254 else if (pos == MAIN_CONTROL_GAME)
2256 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2258 else if (pos == MAIN_CONTROL_SETUP)
2260 CloseDoor(DOOR_CLOSE_2);
2262 SetGameStatus(GAME_MODE_SETUP);
2264 setup_mode = SETUP_MODE_MAIN;
2268 else if (pos == MAIN_CONTROL_QUIT)
2270 SaveLevelSetup_LastSeries();
2271 SaveLevelSetup_SeriesInfo();
2273 #if defined(PLATFORM_EMSCRIPTEN)
2274 Request("Close the browser window to quit!", REQ_CONFIRM);
2276 if (!setup.ask_on_quit_program ||
2277 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2278 SetGameStatus(GAME_MODE_QUIT);
2284 button_pressed_last = button_pressed;
2288 // ============================================================================
2289 // info screen functions
2290 // ============================================================================
2292 static struct TokenInfo *info_info;
2293 static int num_info_info; // number of info entries shown on screen
2294 static int max_info_info; // total number of info entries in list
2296 static void execInfoTitleScreen(void)
2298 info_mode = INFO_MODE_TITLE;
2303 static void execInfoElements(void)
2305 info_mode = INFO_MODE_ELEMENTS;
2310 static void execInfoMusic(void)
2312 info_mode = INFO_MODE_MUSIC;
2317 static void execInfoCredits(void)
2319 info_mode = INFO_MODE_CREDITS;
2324 static void execInfoProgram(void)
2326 info_mode = INFO_MODE_PROGRAM;
2331 static void execInfoVersion(void)
2333 info_mode = INFO_MODE_VERSION;
2338 static void execInfoLevelSet(void)
2340 info_mode = INFO_MODE_LEVELSET;
2345 static void execExitInfo(void)
2347 SetGameStatus(GAME_MODE_MAIN);
2352 static struct TokenInfo info_info_main[] =
2354 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2355 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2356 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2357 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2358 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2359 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2360 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2361 { TYPE_EMPTY, NULL, "" },
2362 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2367 static int getMenuTextFont(int type)
2369 if (type & (TYPE_SWITCH |
2383 static struct TokenInfo *setup_info;
2384 static struct TokenInfo setup_info_input[];
2386 static struct TokenInfo *menu_info;
2388 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2389 int screen_pos, int menu_info_pos_raw,
2392 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2393 struct TokenInfo *ti = &token_info[pos];
2394 int xpos = MENU_SCREEN_START_XPOS;
2395 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2396 int font_nr = getMenuTextFont(ti->type);
2398 if (setup_mode == SETUP_MODE_INPUT)
2399 font_nr = FONT_MENU_1;
2402 font_nr = FONT_ACTIVE(font_nr);
2404 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2406 if (ti->type & ~TYPE_SKIP_ENTRY)
2407 drawCursor(screen_pos, active);
2410 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2413 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2416 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2419 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2422 static char *window_size_text;
2423 static char *scaling_type_text;
2424 static char *network_server_text;
2426 static void drawSetupValue(int, int);
2428 static void drawMenuInfoList(int first_entry, int num_page_entries,
2429 int max_page_entries)
2433 if (first_entry + num_page_entries > max_page_entries)
2436 clearMenuListArea();
2438 for (i = 0; i < num_page_entries; i++)
2440 int menu_info_pos = first_entry + i;
2441 struct TokenInfo *si = &menu_info[menu_info_pos];
2442 void *value_ptr = si->value;
2444 // set some entries to "unchangeable" according to other variables
2445 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2446 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2447 (value_ptr == &setup.sound_music && !audio.music_available) ||
2448 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2449 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2450 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2451 si->type |= TYPE_GHOSTED;
2453 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2454 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2455 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2456 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2457 else if (si->type & ~TYPE_SKIP_ENTRY)
2458 initCursor(i, IMG_MENU_BUTTON);
2460 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2462 if (si->type & TYPE_STRING)
2466 if (value_ptr == &network_server_text)
2467 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2469 if (gadget_id != -1)
2471 struct GadgetInfo *gi = screen_gadget[gadget_id];
2472 int xpos = MENU_SCREEN_START_XPOS;
2473 int ypos = MENU_SCREEN_START_YPOS + i;
2474 int x = mSX + xpos * 32;
2475 int y = mSY + ypos * 32;
2477 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2481 if (si->type & TYPE_VALUE &&
2482 menu_info == setup_info)
2483 drawSetupValue(i, menu_info_pos);
2487 static void DrawInfoScreen_Main(void)
2489 int fade_mask = REDRAW_FIELD;
2492 if (redraw_mask & REDRAW_ALL)
2493 fade_mask = REDRAW_ALL;
2496 fade_mask = REDRAW_ALL;
2499 FadeMenuSoundsAndMusic();
2501 FreeScreenGadgets();
2502 CreateScreenGadgets();
2504 // (needed after displaying title screens which disable auto repeat)
2505 KeyboardAutoRepeatOn();
2507 FadeSetLeaveScreen();
2511 // needed if different viewport properties defined for info screen
2512 ChangeViewportPropertiesIfNeeded();
2514 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2518 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2520 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2522 info_info = info_info_main;
2524 // determine maximal number of info entries that can be displayed on screen
2526 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2529 // determine maximal number of info entries available for menu of info screen
2531 for (i = 0; info_info[i].type != 0; i++)
2534 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2536 MapScreenGadgets(max_info_info);
2538 PlayMenuSoundsAndMusic();
2540 DrawMaskedBorder(fade_mask);
2545 static void changeSetupValue(int, int, int);
2547 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2548 int mode, int num_page_entries,
2549 int max_page_entries)
2551 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2552 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2553 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2554 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2555 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2556 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2557 int *num_page_entries_last = num_page_entries_all_last[game_status];
2558 int *choice_store = choice_stores[game_status];
2559 int *first_entry_store = first_entry_stores[game_status];
2560 int choice = choice_store[mode]; // starts with 0
2561 int first_entry = first_entry_store[mode]; // starts with 0
2563 int y = choice - first_entry;
2565 boolean position_set_by_scrollbar = (dx == 999);
2566 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2569 if (button == MB_MENU_INITIALIZE)
2571 // check if number of menu page entries has changed (may happen by change
2572 // of custom artwork definition value for 'list_size' for this menu screen)
2573 // (in this case, the last menu position most probably has to be corrected)
2574 if (num_page_entries != num_page_entries_last[mode])
2576 choice_store[mode] = first_entry_store[mode] = 0;
2578 choice = first_entry = 0;
2581 num_page_entries_last[mode] = num_page_entries;
2584 // advance to first valid menu entry
2585 while (choice < num_page_entries &&
2586 menu_info[choice].type & TYPE_SKIP_ENTRY)
2589 if (position_set_by_scrollbar)
2590 first_entry = first_entry_store[mode] = dy;
2592 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2593 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2595 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2597 if (choice < first_entry)
2599 choice = first_entry;
2601 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2604 else if (choice > first_entry + num_page_entries - 1)
2606 choice = first_entry + num_page_entries - 1;
2608 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2612 choice_store[mode] = choice;
2614 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2618 else if (button == MB_MENU_LEAVE)
2620 PlaySound(SND_MENU_ITEM_SELECTING);
2622 for (i = 0; i < max_page_entries; i++)
2624 if (menu_info[i].type & TYPE_LEAVE_MENU)
2626 void (*menu_callback_function)(void) = menu_info[i].value;
2630 menu_callback_function();
2632 break; // absolutely needed because function changes 'menu_info'!
2639 if (mx || my) // mouse input
2641 x = (mx - mSX) / 32;
2642 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2644 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2646 // move cursor instead of scrolling when already at start/end of list
2647 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2649 else if (dy == +1 * SCROLL_LINE &&
2650 first_entry + num_page_entries == max_page_entries)
2653 // handle scrolling screen one line or page
2655 y + dy > num_page_entries - 1)
2657 boolean redraw = FALSE;
2659 if (ABS(dy) == SCROLL_PAGE)
2660 step = num_page_entries - 1;
2662 if (dy < 0 && first_entry > 0)
2664 // scroll page/line up
2666 first_entry -= step;
2667 if (first_entry < 0)
2672 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2674 // scroll page/line down
2676 first_entry += step;
2677 if (first_entry + num_page_entries > max_page_entries)
2678 first_entry = MAX(0, max_page_entries - num_page_entries);
2685 choice += first_entry - first_entry_store[mode];
2687 if (choice < first_entry)
2689 choice = first_entry;
2691 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2694 else if (choice > first_entry + num_page_entries - 1)
2696 choice = first_entry + num_page_entries - 1;
2698 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2701 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2705 if (choice < first_entry ||
2706 choice > first_entry + num_page_entries - 1)
2707 first_entry += SIGN(dy);
2710 first_entry_store[mode] = first_entry;
2711 choice_store[mode] = choice;
2713 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2715 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2717 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2718 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2726 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2728 if (menu_info[choice].type & menu_navigation_type ||
2729 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2730 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2731 menu_info[choice].type & TYPE_PLAYER)
2732 button = MB_MENU_CHOICE;
2737 // jump to next non-empty menu entry (up or down)
2738 while (first_entry + y > 0 &&
2739 first_entry + y < max_page_entries - 1 &&
2740 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2743 if (!IN_VIS_MENU(x, y))
2745 choice += y - y_old;
2747 if (choice < first_entry)
2748 first_entry = choice;
2749 else if (choice > first_entry + num_page_entries - 1)
2750 first_entry = choice - num_page_entries + 1;
2752 if (first_entry >= 0 &&
2753 first_entry + num_page_entries <= max_page_entries)
2755 first_entry_store[mode] = first_entry;
2757 if (choice < first_entry)
2758 choice = first_entry;
2759 else if (choice > first_entry + num_page_entries - 1)
2760 choice = first_entry + num_page_entries - 1;
2762 choice_store[mode] = choice;
2764 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2766 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2768 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2769 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2776 if (!anyScrollbarGadgetActive() &&
2777 IN_VIS_MENU(x, y) &&
2778 mx < mx_right_border &&
2779 y >= 0 && y < num_page_entries)
2783 if (first_entry + y != choice &&
2784 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2786 PlaySound(SND_MENU_ITEM_ACTIVATING);
2788 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2789 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2791 choice = choice_store[mode] = first_entry + y;
2795 PlaySound(SND_MENU_ITEM_SELECTING);
2797 for (i = 0; menu_info[i].type != 0; i++)
2799 if (menu_info[i].type & TYPE_LEAVE_MENU)
2801 void (*menu_callback_function)(void) = menu_info[i].value;
2805 menu_callback_function();
2807 // absolutely needed because function changes 'menu_info'!
2815 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2817 PlaySound(SND_MENU_ITEM_SELECTING);
2819 // when selecting key headline, execute function for key value change
2820 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2821 menu_info[first_entry + y + 1].type & TYPE_KEY)
2824 // when selecting string value, execute function for list selection
2825 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2826 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2829 // when selecting string value, execute function for text input gadget
2830 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2831 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2834 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2836 void (*menu_callback_function)(void) =
2837 menu_info[first_entry + y].value;
2839 FadeSetFromType(menu_info[first_entry + y].type);
2841 menu_callback_function();
2843 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2845 void (*gadget_callback_function)(void) =
2846 menu_info[first_entry + y].value;
2848 gadget_callback_function();
2850 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2851 menu_info == setup_info)
2853 changeSetupValue(y, first_entry + y, dx);
2859 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2861 menu_info = info_info;
2863 HandleMenuScreen(mx, my, dx, dy, button,
2864 info_mode, num_info_info, max_info_info);
2867 static int getMenuFontSpacing(int spacing_height, int font_nr)
2869 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2871 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2875 static int getMenuTextSpacing(int spacing_height, int font_nr)
2877 return (getMenuFontSpacing(spacing_height, font_nr) +
2878 EXTRA_SPACING(game_status));
2881 static int getMenuTextStep(int spacing_height, int font_nr)
2883 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2886 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2888 int font_title = MENU_INFO_FONT_TITLE;
2889 int font_error = FONT_TEXT_2;
2890 int font_foot = MENU_INFO_FONT_FOOT;
2891 int spacing_title = menu.headline1_spacing_info[info_mode];
2892 int ystep_title = getMenuTextStep(spacing_title, font_title);
2893 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2894 int ystart2 = ystart1 + ystep_title;
2895 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2897 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2899 FadeOut(REDRAW_FIELD);
2904 DrawTextSCentered(ystart1, font_title, text_title);
2905 DrawTextSCentered(ystart2, font_error, text_error);
2907 DrawTextSCentered(ybottom, font_foot,
2908 "Press any key or button for info menu");
2910 FadeIn(REDRAW_FIELD);
2913 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2915 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2916 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2917 int font_title = MENU_INFO_FONT_TITLE;
2918 int font_foot = MENU_INFO_FONT_FOOT;
2919 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2920 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2921 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2922 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2923 int ystep = MENU_SCREEN_INFO_YSTEP;
2924 int element, action, direction;
2932 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2933 infoscreen_step[i] = infoscreen_frame[i] = 0;
2938 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2940 DrawTextSCentered(ybottom, font_foot,
2941 "Press any key or button for next page");
2947 while (helpanim_info[j].element != HELPANIM_LIST_END)
2949 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2954 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2963 j += infoscreen_step[i - start];
2965 element = helpanim_info[j].element;
2966 action = helpanim_info[j].action;
2967 direction = helpanim_info[j].direction;
2970 element = EL_UNKNOWN;
2972 if (action != -1 && direction != -1)
2973 graphic = el_act_dir2img(element, action, direction);
2974 else if (action != -1)
2975 graphic = el_act2img(element, action);
2976 else if (direction != -1)
2977 graphic = el_dir2img(element, direction);
2979 graphic = el2img(element);
2981 delay = helpanim_info[j++].delay;
2986 if (infoscreen_frame[i - start] == 0)
2989 infoscreen_frame[i - start] = delay - 1;
2993 sync_frame = delay - infoscreen_frame[i - start];
2994 infoscreen_frame[i - start]--;
2997 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2999 if (!infoscreen_frame[i - start])
3000 infoscreen_step[i - start] = 0;
3004 if (!infoscreen_frame[i - start])
3005 infoscreen_step[i - start]++;
3006 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3012 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3014 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3015 graphic, sync_frame, USE_MASKING);
3018 DrawInfoScreen_HelpText(element, action, direction, i - start);
3023 redraw_mask |= REDRAW_FIELD;
3028 static char *getHelpText(int element, int action, int direction)
3030 char token[MAX_LINE_LEN];
3032 strcpy(token, element_info[element].token_name);
3035 strcat(token, element_action_info[action].suffix);
3037 if (direction != -1)
3038 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3040 return getHashEntry(helptext_info, token);
3043 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3045 int font_nr = FONT_INFO_ELEMENTS;
3046 int font_width = getFontWidth(font_nr);
3047 int font_height = getFontHeight(font_nr);
3048 int yoffset = (TILEX - 2 * font_height) / 2;
3049 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3050 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3051 int ystep = TILEY + 4;
3052 int pad_left = xstart - SX;
3053 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3054 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3055 int max_lines_per_text = 2;
3058 if (action != -1 && direction != -1) // element.action.direction
3059 text = getHelpText(element, action, direction);
3061 if (text == NULL && action != -1) // element.action
3062 text = getHelpText(element, action, -1);
3064 if (text == NULL && direction != -1) // element.direction
3065 text = getHelpText(element, -1, direction);
3067 if (text == NULL) // base element
3068 text = getHelpText(element, -1, -1);
3070 if (text == NULL) // not found
3071 text = "No description available";
3073 if (strlen(text) <= max_chars_per_line) // only one line of text
3074 ystart += getFontHeight(font_nr) / 2;
3076 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3077 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3078 TRUE, FALSE, FALSE);
3081 static void DrawInfoScreen_TitleScreen(void)
3083 SetGameStatus(GAME_MODE_TITLE);
3088 void HandleInfoScreen_TitleScreen(int button)
3090 HandleTitleScreen(0, 0, 0, 0, button);
3093 static void DrawInfoScreen_Elements(void)
3095 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3097 FadeOut(REDRAW_FIELD);
3102 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3104 FadeIn(REDRAW_FIELD);
3107 void HandleInfoScreen_Elements(int button)
3109 static unsigned int info_delay = 0;
3110 static int num_anims;
3111 static int num_pages;
3113 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3116 if (button == MB_MENU_INITIALIZE)
3118 boolean new_element = TRUE;
3122 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3124 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3126 else if (new_element)
3129 new_element = FALSE;
3133 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3137 if (button == MB_MENU_LEAVE)
3139 PlaySound(SND_MENU_ITEM_SELECTING);
3141 info_mode = INFO_MODE_MAIN;
3146 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3148 if (button != MB_MENU_INITIALIZE)
3150 PlaySound(SND_MENU_ITEM_SELECTING);
3155 if (page >= num_pages)
3157 FadeMenuSoundsAndMusic();
3159 info_mode = INFO_MODE_MAIN;
3166 FadeSetNextScreen();
3168 if (button != MB_MENU_INITIALIZE)
3169 FadeOut(REDRAW_FIELD);
3171 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3173 if (button != MB_MENU_INITIALIZE)
3174 FadeIn(REDRAW_FIELD);
3178 if (DelayReached(&info_delay, GameFrameDelay))
3179 if (page < num_pages)
3180 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3182 PlayMenuSoundIfLoop();
3186 static void DrawInfoScreen_Music(void)
3188 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3190 FadeOut(REDRAW_FIELD);
3197 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3199 FadeIn(REDRAW_FIELD);
3202 void HandleInfoScreen_Music(int button)
3204 static struct MusicFileInfo *list = NULL;
3205 int font_title = MENU_INFO_FONT_TITLE;
3206 int font_head = MENU_INFO_FONT_HEAD;
3207 int font_text = MENU_INFO_FONT_TEXT;
3208 int font_foot = MENU_INFO_FONT_FOOT;
3209 int spacing_title = menu.headline1_spacing_info[info_mode];
3210 int spacing_head = menu.headline2_spacing_info[info_mode];
3211 int ystep_title = getMenuTextStep(spacing_title, font_title);
3212 int ystep_head = getMenuTextStep(spacing_head, font_head);
3213 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3214 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3216 if (button == MB_MENU_INITIALIZE)
3218 list = music_file_info;
3222 FadeMenuSoundsAndMusic();
3227 DrawTextSCentered(ystart, font_title,
3228 "No music info for this level set.");
3230 DrawTextSCentered(ybottom, font_foot,
3231 "Press any key or button for info menu");
3237 if (button == MB_MENU_LEAVE)
3239 PlaySound(SND_MENU_ITEM_SELECTING);
3241 FadeMenuSoundsAndMusic();
3243 info_mode = INFO_MODE_MAIN;
3248 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3250 if (button != MB_MENU_INITIALIZE)
3252 PlaySound(SND_MENU_ITEM_SELECTING);
3260 FadeMenuSoundsAndMusic();
3262 info_mode = INFO_MODE_MAIN;
3268 FadeMenuSoundsAndMusic();
3270 if (list != music_file_info)
3271 FadeSetNextScreen();
3273 if (button != MB_MENU_INITIALIZE)
3274 FadeOut(REDRAW_FIELD);
3281 int sound = list->music;
3283 if (IS_LOOP_SOUND(sound))
3284 PlaySoundLoop(sound);
3288 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3292 int music = list->music;
3294 if (IS_LOOP_MUSIC(music))
3295 PlayMusicLoop(music);
3299 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3302 ystart += ystep_title;
3304 if (!strEqual(list->title, UNKNOWN_NAME))
3306 if (!strEqual(list->title_header, UNKNOWN_NAME))
3308 DrawTextSCentered(ystart, font_head, list->title_header);
3309 ystart += ystep_head;
3312 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3313 ystart += ystep_head;
3316 if (!strEqual(list->artist, UNKNOWN_NAME))
3318 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3319 DrawTextSCentered(ystart, font_head, list->artist_header);
3321 DrawTextSCentered(ystart, font_head, "by");
3323 ystart += ystep_head;
3325 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3326 ystart += ystep_head;
3329 if (!strEqual(list->album, UNKNOWN_NAME))
3331 if (!strEqual(list->album_header, UNKNOWN_NAME))
3332 DrawTextSCentered(ystart, font_head, list->album_header);
3334 DrawTextSCentered(ystart, font_head, "from the album");
3336 ystart += ystep_head;
3338 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3339 ystart += ystep_head;
3342 if (!strEqual(list->year, UNKNOWN_NAME))
3344 if (!strEqual(list->year_header, UNKNOWN_NAME))
3345 DrawTextSCentered(ystart, font_head, list->year_header);
3347 DrawTextSCentered(ystart, font_head, "from the year");
3349 ystart += ystep_head;
3351 DrawTextFCentered(ystart, font_text, "%s", list->year);
3352 ystart += ystep_head;
3355 DrawTextSCentered(ybottom, FONT_TEXT_4,
3356 "Press any key or button for next page");
3358 if (button != MB_MENU_INITIALIZE)
3359 FadeIn(REDRAW_FIELD);
3362 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3363 PlaySoundLoop(list->music);
3366 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3368 int font_title = MENU_INFO_FONT_TITLE;
3369 int font_head = MENU_INFO_FONT_HEAD;
3370 int font_text = MENU_INFO_FONT_TEXT;
3371 int font_foot = MENU_INFO_FONT_FOOT;
3372 int spacing_title = menu.headline1_spacing_info[info_mode];
3373 int spacing_head = menu.headline2_spacing_info[info_mode];
3374 int spacing_para = menu.paragraph_spacing_info[info_mode];
3375 int spacing_line = menu.line_spacing_info[info_mode];
3376 int ystep_title = getMenuTextStep(spacing_title, font_title);
3377 int ystep_head = getMenuTextStep(spacing_head, font_head);
3378 int ystep_para = getMenuTextStep(spacing_para, font_text);
3379 int ystep_line = getMenuTextStep(spacing_line, font_text);
3380 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3381 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3386 DrawTextSCentered(ystart, font_title, "Credits:");
3387 ystart += ystep_title;
3391 DrawTextSCentered(ystart, font_head,
3392 "Special thanks to");
3393 ystart += ystep_head;
3394 DrawTextSCentered(ystart, font_text,
3396 ystart += ystep_head;
3397 DrawTextSCentered(ystart, font_head,
3399 ystart += ystep_head;
3400 DrawTextSCentered(ystart, font_text,
3401 "\"Boulder Dash\"");
3402 ystart += ystep_head;
3403 DrawTextSCentered(ystart, font_head,
3405 ystart += ystep_head;
3406 DrawTextSCentered(ystart, font_text,
3408 ystart += ystep_head;
3409 DrawTextSCentered(ystart, font_head,
3411 ystart += ystep_head;
3412 DrawTextSCentered(ystart, font_text,
3413 "First Star Software");
3415 else if (screen_nr == 1)
3417 DrawTextSCentered(ystart, font_head,
3418 "Special thanks to");
3419 ystart += ystep_head;
3420 DrawTextSCentered(ystart, font_text,
3421 "Klaus Heinz & Volker Wertich");
3422 ystart += ystep_head;
3423 DrawTextSCentered(ystart, font_head,
3425 ystart += ystep_head;
3426 DrawTextSCentered(ystart, font_text,
3427 "\"Emerald Mine\"");
3428 ystart += ystep_head;
3429 DrawTextSCentered(ystart, font_head,
3431 ystart += ystep_head;
3432 DrawTextSCentered(ystart, font_text,
3434 ystart += ystep_head;
3435 DrawTextSCentered(ystart, font_head,
3437 ystart += ystep_head;
3438 DrawTextSCentered(ystart, font_text,
3441 else if (screen_nr == 2)
3443 DrawTextSCentered(ystart, font_head,
3444 "Special thanks to");
3445 ystart += ystep_head;
3446 DrawTextSCentered(ystart, font_text,
3447 "Michael Stopp & Philip Jespersen");
3448 ystart += ystep_head;
3449 DrawTextSCentered(ystart, font_head,
3451 ystart += ystep_head;
3452 DrawTextSCentered(ystart, font_text,
3454 ystart += ystep_head;
3455 DrawTextSCentered(ystart, font_head,
3457 ystart += ystep_head;
3458 DrawTextSCentered(ystart, font_text,
3460 ystart += ystep_head;
3461 DrawTextSCentered(ystart, font_head,
3463 ystart += ystep_head;
3464 DrawTextSCentered(ystart, font_text,
3465 "Digital Integration");
3467 else if (screen_nr == 3)
3469 DrawTextSCentered(ystart, font_head,
3470 "Special thanks to");
3471 ystart += ystep_head;
3472 DrawTextSCentered(ystart, font_text,
3473 "Hiroyuki Imabayashi");
3474 ystart += ystep_head;
3475 DrawTextSCentered(ystart, font_head,
3477 ystart += ystep_head;
3478 DrawTextSCentered(ystart, font_text,
3480 ystart += ystep_head;
3481 DrawTextSCentered(ystart, font_head,
3483 ystart += ystep_head;
3484 DrawTextSCentered(ystart, font_text,
3486 ystart += ystep_head;
3487 DrawTextSCentered(ystart, font_head,
3489 ystart += ystep_head;
3490 DrawTextSCentered(ystart, font_text,
3493 else if (screen_nr == 4)
3495 DrawTextSCentered(ystart, font_head,
3496 "Special thanks to");
3497 ystart += ystep_head;
3498 DrawTextSCentered(ystart, font_text,
3500 ystart += ystep_head;
3501 DrawTextSCentered(ystart, font_head,
3503 ystart += ystep_head;
3504 DrawTextSCentered(ystart, font_text,
3505 "J\xfcrgen Bonhagen");
3506 ystart += ystep_head;
3507 DrawTextSCentered(ystart, font_head,
3508 "for the continuous creation");
3509 ystart += ystep_line;
3510 DrawTextSCentered(ystart, font_head,
3511 "of outstanding level sets");
3513 else if (screen_nr == 5)
3515 DrawTextSCentered(ystart, font_head,
3517 ystart += ystep_head;
3518 DrawTextSCentered(ystart, font_text,
3520 ystart += ystep_head;
3521 DrawTextSCentered(ystart, font_head,
3522 "for ideas and inspiration by");
3523 ystart += ystep_head;
3524 DrawTextSCentered(ystart, font_text,
3526 ystart += ystep_para;
3528 DrawTextSCentered(ystart, font_head,
3530 ystart += ystep_head;
3531 DrawTextSCentered(ystart, font_text,
3533 ystart += ystep_head;
3534 DrawTextSCentered(ystart, font_head,
3535 "for ideas and inspiration by");
3536 ystart += ystep_head;
3537 DrawTextSCentered(ystart, font_text,
3540 else if (screen_nr == 6)
3542 DrawTextSCentered(ystart, font_head,
3544 ystart += ystep_head;
3545 DrawTextSCentered(ystart, font_text,
3547 ystart += ystep_head;
3548 DrawTextSCentered(ystart, font_head,
3549 "for the code base used for the");
3550 ystart += ystep_line;
3551 DrawTextSCentered(ystart, font_head,
3552 "native Emerald Mine engine");
3554 else if (screen_nr == 7)
3556 DrawTextSCentered(ystart, font_head,
3558 ystart += ystep_head;
3559 DrawTextSCentered(ystart, font_text,
3561 ystart += ystep_head;
3562 DrawTextSCentered(ystart, font_head,
3563 "for the initial DOS port");
3564 ystart += ystep_para;
3566 DrawTextSCentered(ystart, font_head,
3568 ystart += ystep_head;
3569 DrawTextSCentered(ystart, font_text,
3571 ystart += ystep_head;
3572 DrawTextSCentered(ystart, font_head,
3573 "for some additional toons");
3575 else if (screen_nr == 8)
3577 DrawTextSCentered(ystart, font_head,
3578 "And not to forget:");
3579 ystart += ystep_head;
3580 DrawTextSCentered(ystart, font_head,
3582 ystart += ystep_head;
3583 DrawTextSCentered(ystart, font_text,
3584 "All those who contributed");
3585 ystart += ystep_line;
3586 DrawTextSCentered(ystart, font_text,
3587 "levels to this game");
3588 ystart += ystep_line;
3589 DrawTextSCentered(ystart, font_text,
3593 DrawTextSCentered(ybottom, font_foot,
3594 "Press any key or button for next page");
3597 static void DrawInfoScreen_Credits(void)
3599 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3601 FadeMenuSoundsAndMusic();
3603 FadeOut(REDRAW_FIELD);
3605 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3607 FadeIn(REDRAW_FIELD);
3610 void HandleInfoScreen_Credits(int button)
3612 static int screen_nr = 0;
3613 int num_screens = 9;
3615 if (button == MB_MENU_INITIALIZE)
3619 // DrawInfoScreen_CreditsScreen(screen_nr);
3622 if (button == MB_MENU_LEAVE)
3624 PlaySound(SND_MENU_ITEM_SELECTING);
3626 info_mode = INFO_MODE_MAIN;
3631 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3633 if (button != MB_MENU_INITIALIZE)
3635 PlaySound(SND_MENU_ITEM_SELECTING);
3640 if (screen_nr >= num_screens)
3642 FadeMenuSoundsAndMusic();
3644 info_mode = INFO_MODE_MAIN;
3651 FadeSetNextScreen();
3653 if (button != MB_MENU_INITIALIZE)
3654 FadeOut(REDRAW_FIELD);
3656 DrawInfoScreen_CreditsScreen(screen_nr);
3658 if (button != MB_MENU_INITIALIZE)
3659 FadeIn(REDRAW_FIELD);
3663 PlayMenuSoundIfLoop();
3667 static void DrawInfoScreen_Program(void)
3669 int font_title = MENU_INFO_FONT_TITLE;
3670 int font_head = MENU_INFO_FONT_HEAD;
3671 int font_text = MENU_INFO_FONT_TEXT;
3672 int font_foot = MENU_INFO_FONT_FOOT;
3673 int spacing_title = menu.headline1_spacing_info[info_mode];
3674 int spacing_head = menu.headline2_spacing_info[info_mode];
3675 int spacing_para = menu.paragraph_spacing_info[info_mode];
3676 int spacing_line = menu.line_spacing_info[info_mode];
3677 int ystep_title = getMenuTextStep(spacing_title, font_title);
3678 int ystep_head = getMenuTextStep(spacing_head, font_head);
3679 int ystep_para = getMenuTextStep(spacing_para, font_text);
3680 int ystep_line = getMenuTextStep(spacing_line, font_text);
3681 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3682 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3684 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3686 FadeOut(REDRAW_FIELD);
3691 DrawTextSCentered(ystart, font_title, "Program Information:");
3692 ystart += ystep_title;
3694 DrawTextSCentered(ystart, font_head,
3695 "This game is Freeware!");
3696 ystart += ystep_head;
3697 DrawTextSCentered(ystart, font_head,
3698 "If you like it, send e-mail to:");
3699 ystart += ystep_head;
3700 DrawTextSCentered(ystart, font_text,
3701 setup.internal.program_email);
3702 ystart += ystep_para;
3704 DrawTextSCentered(ystart, font_head,
3705 "More information and levels:");
3706 ystart += ystep_head;
3707 DrawTextSCentered(ystart, font_text,
3708 setup.internal.program_website);
3709 ystart += ystep_para;
3711 DrawTextSCentered(ystart, font_head,
3712 "If you have created new levels,");
3713 ystart += ystep_line;
3714 DrawTextSCentered(ystart, font_head,
3715 "send them to me to include them!");
3716 ystart += ystep_head;
3717 DrawTextSCentered(ystart, font_head,
3720 DrawTextSCentered(ybottom, font_foot,
3721 "Press any key or button for info menu");
3723 FadeIn(REDRAW_FIELD);
3726 void HandleInfoScreen_Program(int button)
3728 if (button == MB_MENU_LEAVE)
3730 PlaySound(SND_MENU_ITEM_SELECTING);
3732 info_mode = INFO_MODE_MAIN;
3737 else if (button == MB_MENU_CHOICE)
3739 PlaySound(SND_MENU_ITEM_SELECTING);
3741 FadeMenuSoundsAndMusic();
3743 info_mode = INFO_MODE_MAIN;
3748 PlayMenuSoundIfLoop();
3752 static void DrawInfoScreen_Version(void)
3754 int font_title = MENU_INFO_FONT_TITLE;
3755 int font_head = MENU_INFO_FONT_HEAD;
3756 int font_text = MENU_INFO_FONT_TEXT;
3757 int font_foot = MENU_INFO_FONT_FOOT;
3758 int spacing_title = menu.headline1_spacing_info[info_mode];
3759 int spacing_head = menu.headline2_spacing_info[info_mode];
3760 int spacing_para = menu.paragraph_spacing_info[info_mode];
3761 int spacing_line = menu.line_spacing_info[info_mode];
3762 int xstep = getFontWidth(font_text);
3763 int ystep_title = getMenuTextStep(spacing_title, font_title);
3764 int ystep_head = getMenuTextStep(spacing_head, font_head);
3765 int ystep_para = getMenuTextStep(spacing_para, font_text);
3766 int ystep_line = getMenuTextStep(spacing_line, font_text);
3767 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3768 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3769 int xstart1 = mSX - SX + 2 * xstep;
3770 int xstart2 = mSX - SX + 18 * xstep;
3771 int xstart3 = mSX - SX + 28 * xstep;
3772 SDL_version sdl_version_compiled;
3773 const SDL_version *sdl_version_linked;
3774 int driver_name_len = 10;
3775 SDL_version sdl_version_linked_ext;
3776 const char *driver_name = NULL;
3778 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3780 FadeOut(REDRAW_FIELD);
3785 DrawTextSCentered(ystart, font_title, "Version Information:");
3786 ystart += ystep_title;
3788 DrawTextF(xstart1, ystart, font_head, "Name");
3789 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3790 ystart += ystep_line;
3792 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3794 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3795 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3796 ystart += ystep_line;
3798 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3799 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3800 ystart += ystep_line;
3804 DrawTextF(xstart1, ystart, font_head, "Version");
3805 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3806 ystart += ystep_line;
3809 DrawTextF(xstart1, ystart, font_head, "Platform");
3810 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3812 PLATFORM_XX_BIT_STRING);
3813 ystart += ystep_line;
3815 DrawTextF(xstart1, ystart, font_head, "Target");
3816 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3817 ystart += ystep_line;
3819 DrawTextF(xstart1, ystart, font_head, "Source date");
3820 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3821 ystart += ystep_line;
3823 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3824 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3825 ystart += ystep_para;
3827 DrawTextF(xstart1, ystart, font_head, "Library");
3828 DrawTextF(xstart2, ystart, font_head, "compiled");
3829 DrawTextF(xstart3, ystart, font_head, "linked");
3830 ystart += ystep_head;
3832 SDL_VERSION(&sdl_version_compiled);
3833 SDL_GetVersion(&sdl_version_linked_ext);
3834 sdl_version_linked = &sdl_version_linked_ext;
3836 DrawTextF(xstart1, ystart, font_text, "SDL");
3837 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3838 sdl_version_compiled.major,
3839 sdl_version_compiled.minor,
3840 sdl_version_compiled.patch);
3841 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3842 sdl_version_linked->major,
3843 sdl_version_linked->minor,
3844 sdl_version_linked->patch);
3845 ystart += ystep_line;
3847 SDL_IMAGE_VERSION(&sdl_version_compiled);
3848 sdl_version_linked = IMG_Linked_Version();
3850 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3851 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3852 sdl_version_compiled.major,
3853 sdl_version_compiled.minor,
3854 sdl_version_compiled.patch);
3855 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3856 sdl_version_linked->major,
3857 sdl_version_linked->minor,
3858 sdl_version_linked->patch);
3859 ystart += ystep_line;
3861 SDL_MIXER_VERSION(&sdl_version_compiled);
3862 sdl_version_linked = Mix_Linked_Version();
3864 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3865 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3866 sdl_version_compiled.major,
3867 sdl_version_compiled.minor,
3868 sdl_version_compiled.patch);
3869 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3870 sdl_version_linked->major,
3871 sdl_version_linked->minor,
3872 sdl_version_linked->patch);
3873 ystart += ystep_line;
3875 SDL_NET_VERSION(&sdl_version_compiled);
3876 sdl_version_linked = SDLNet_Linked_Version();
3878 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3879 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3880 sdl_version_compiled.major,
3881 sdl_version_compiled.minor,
3882 sdl_version_compiled.patch);
3883 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3884 sdl_version_linked->major,
3885 sdl_version_linked->minor,
3886 sdl_version_linked->patch);
3887 ystart += ystep_para;
3889 DrawTextF(xstart1, ystart, font_head, "Driver");
3890 DrawTextF(xstart2, ystart, font_head, "Requested");
3891 DrawTextF(xstart3, ystart, font_head, "Used");
3892 ystart += ystep_head;
3895 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3897 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3898 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3899 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3900 ystart += ystep_line;
3903 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3905 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3906 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3907 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3908 ystart += ystep_line;
3911 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3913 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3914 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3915 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3917 DrawTextSCentered(ybottom, font_foot,
3918 "Press any key or button for info menu");
3920 FadeIn(REDRAW_FIELD);
3923 void HandleInfoScreen_Version(int button)
3925 if (button == MB_MENU_LEAVE)
3927 PlaySound(SND_MENU_ITEM_SELECTING);
3929 info_mode = INFO_MODE_MAIN;
3934 else if (button == MB_MENU_CHOICE)
3936 PlaySound(SND_MENU_ITEM_SELECTING);
3938 FadeMenuSoundsAndMusic();
3940 info_mode = INFO_MODE_MAIN;
3945 PlayMenuSoundIfLoop();
3949 static void DrawInfoScreen_LevelSet(void)
3951 struct TitleMessageInfo *tmi = &readme;
3952 char *filename = getLevelSetInfoFilename();
3953 char *title = "Level Set Information:";
3954 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3955 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3957 if (filename == NULL)
3959 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3964 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3966 FadeOut(REDRAW_FIELD);
3971 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3973 // if x position set to "-1", automatically determine by playfield width
3975 tmi->x = SXSIZE / 2;
3977 // if y position set to "-1", use static default value
3981 // if width set to "-1", automatically determine by playfield width
3982 if (tmi->width == -1)
3983 tmi->width = SXSIZE - 2 * TILEX;
3985 // if height set to "-1", automatically determine by playfield height
3986 if (tmi->height == -1)
3987 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3989 // if chars set to "-1", automatically determine by text and font width
3990 if (tmi->chars == -1)
3991 tmi->chars = tmi->width / getFontWidth(tmi->font);
3993 tmi->width = tmi->chars * getFontWidth(tmi->font);
3995 // if lines set to "-1", automatically determine by text and font height
3996 if (tmi->lines == -1)
3997 tmi->lines = tmi->height / getFontHeight(tmi->font);
3999 tmi->height = tmi->lines * getFontHeight(tmi->font);
4001 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
4002 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
4003 tmi->autowrap, tmi->centered, tmi->parse_comments);
4005 DrawTextSCentered(ybottom, FONT_TEXT_4,
4006 "Press any key or button for info menu");
4008 FadeIn(REDRAW_FIELD);
4011 static void HandleInfoScreen_LevelSet(int button)
4013 if (button == MB_MENU_LEAVE)
4015 PlaySound(SND_MENU_ITEM_SELECTING);
4017 info_mode = INFO_MODE_MAIN;
4022 else if (button == MB_MENU_CHOICE)
4024 PlaySound(SND_MENU_ITEM_SELECTING);
4026 FadeMenuSoundsAndMusic();
4028 info_mode = INFO_MODE_MAIN;
4033 PlayMenuSoundIfLoop();
4037 static void DrawInfoScreen(void)
4039 if (info_mode == INFO_MODE_TITLE)
4040 DrawInfoScreen_TitleScreen();
4041 else if (info_mode == INFO_MODE_ELEMENTS)
4042 DrawInfoScreen_Elements();
4043 else if (info_mode == INFO_MODE_MUSIC)
4044 DrawInfoScreen_Music();
4045 else if (info_mode == INFO_MODE_CREDITS)
4046 DrawInfoScreen_Credits();
4047 else if (info_mode == INFO_MODE_PROGRAM)
4048 DrawInfoScreen_Program();
4049 else if (info_mode == INFO_MODE_VERSION)
4050 DrawInfoScreen_Version();
4051 else if (info_mode == INFO_MODE_LEVELSET)
4052 DrawInfoScreen_LevelSet();
4054 DrawInfoScreen_Main();
4056 if (info_mode != INFO_MODE_MAIN &&
4057 info_mode != INFO_MODE_TITLE &&
4058 info_mode != INFO_MODE_MUSIC)
4059 PlayMenuSoundsAndMusic();
4062 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4064 if (info_mode == INFO_MODE_TITLE)
4065 HandleInfoScreen_TitleScreen(button);
4066 else if (info_mode == INFO_MODE_ELEMENTS)
4067 HandleInfoScreen_Elements(button);
4068 else if (info_mode == INFO_MODE_MUSIC)
4069 HandleInfoScreen_Music(button);
4070 else if (info_mode == INFO_MODE_CREDITS)
4071 HandleInfoScreen_Credits(button);
4072 else if (info_mode == INFO_MODE_PROGRAM)
4073 HandleInfoScreen_Program(button);
4074 else if (info_mode == INFO_MODE_VERSION)
4075 HandleInfoScreen_Version(button);
4076 else if (info_mode == INFO_MODE_LEVELSET)
4077 HandleInfoScreen_LevelSet(button);
4079 HandleInfoScreen_Main(mx, my, dx, dy, button);
4083 // ============================================================================
4084 // rename player API functions
4085 // ============================================================================
4087 struct ApiRenamePlayerThreadData
4093 static void *CreateThreadData_ApiRenamePlayer(void)
4095 struct ApiRenamePlayerThreadData *data =
4096 checked_malloc(sizeof(struct ApiRenamePlayerThreadData));
4098 data->player_name = getStringCopy(setup.player_name);
4099 data->player_uuid = getStringCopy(setup.player_uuid);
4104 static void FreeThreadData_ApiRenamePlayer(void *data_raw)
4106 struct ApiRenamePlayerThreadData *data = data_raw;
4108 checked_free(data->player_name);
4109 checked_free(data->player_uuid);
4113 static boolean SetRequest_ApiRenamePlayer(struct HttpRequest *request,
4116 struct ApiRenamePlayerThreadData *data = data_raw;
4117 char *player_name_raw = data->player_name;
4118 char *player_uuid_raw = data->player_uuid;
4120 request->hostname = setup.api_server_hostname;
4121 request->port = API_SERVER_PORT;
4122 request->method = API_SERVER_METHOD;
4123 request->uri = API_SERVER_URI_RENAME;
4125 char *player_name = getEscapedJSON(player_name_raw);
4126 char *player_uuid = getEscapedJSON(player_uuid_raw);
4128 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4131 " \"game_version\": \"%s\",\n"
4132 " \"game_platform\": \"%s\",\n"
4133 " \"name\": \"%s\",\n"
4134 " \"uuid\": \"%s\"\n"
4136 getPasswordJSON(setup.api_server_password),
4137 getProgramRealVersionString(),
4138 getProgramPlatformString(),
4142 checked_free(player_name);
4143 checked_free(player_uuid);
4145 ConvertHttpRequestBodyToServerEncoding(request);
4150 static void HandleResponse_ApiRenamePlayer(struct HttpResponse *response,
4153 // nothing to do here
4156 #if defined(PLATFORM_EMSCRIPTEN)
4157 static void Emscripten_ApiRenamePlayer_Loaded(unsigned handle, void *data_raw,
4158 void *buffer, unsigned int size)
4160 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4162 if (response != NULL)
4164 HandleResponse_ApiRenamePlayer(response, data_raw);
4166 checked_free(response);
4170 Error("server response too large to handle (%d bytes)", size);
4173 FreeThreadData_ApiRenamePlayer(data_raw);
4176 static void Emscripten_ApiRenamePlayer_Failed(unsigned handle, void *data_raw,
4177 int code, const char *status)
4179 Error("server failed to handle request: %d %s", code, status);
4181 FreeThreadData_ApiRenamePlayer(data_raw);
4184 static void Emscripten_ApiRenamePlayer_Progress(unsigned handle, void *data_raw,
4185 int bytes, int size)
4187 // nothing to do here
4190 static void Emscripten_ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4193 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4195 FreeThreadData_ApiRenamePlayer(data_raw);
4200 emscripten_async_wget2_data(request->uri,
4205 Emscripten_ApiRenamePlayer_Loaded,
4206 Emscripten_ApiRenamePlayer_Failed,
4207 Emscripten_ApiRenamePlayer_Progress);
4212 static void ApiRenamePlayer_HttpRequestExt(struct HttpRequest *request,
4213 struct HttpResponse *response,
4216 if (!SetRequest_ApiRenamePlayer(request, data_raw))
4219 if (!DoHttpRequest(request, response))
4221 Error("HTTP request failed: %s", GetHttpError());
4226 if (!HTTP_SUCCESS(response->status_code))
4228 Error("server failed to handle request: %d %s",
4229 response->status_code,
4230 response->status_text);
4235 HandleResponse_ApiRenamePlayer(response, data_raw);
4238 static void ApiRenamePlayer_HttpRequest(struct HttpRequest *request,
4239 struct HttpResponse *response,
4242 ApiRenamePlayer_HttpRequestExt(request, response, data_raw);
4244 FreeThreadData_ApiRenamePlayer(data_raw);
4248 static int ApiRenamePlayerThread(void *data_raw)
4250 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4251 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4253 program.api_thread_count++;
4255 #if defined(PLATFORM_EMSCRIPTEN)
4256 Emscripten_ApiRenamePlayer_HttpRequest(request, data_raw);
4258 ApiRenamePlayer_HttpRequest(request, response, data_raw);
4261 program.api_thread_count--;
4263 checked_free(request);
4264 checked_free(response);
4269 static void ApiRenamePlayerAsThread(void)
4271 struct ApiRenamePlayerThreadData *data = CreateThreadData_ApiRenamePlayer();
4273 ExecuteAsThread(ApiRenamePlayerThread,
4274 "ApiRenamePlayer", data,
4275 "rename player on server");
4279 // ============================================================================
4280 // reset player UUID API functions
4281 // ============================================================================
4283 struct ApiResetUUIDThreadData
4286 char *player_uuid_old;
4287 char *player_uuid_new;
4290 static void *CreateThreadData_ApiResetUUID(char *uuid_new)
4292 struct ApiResetUUIDThreadData *data =
4293 checked_malloc(sizeof(struct ApiResetUUIDThreadData));
4295 data->player_name = getStringCopy(setup.player_name);
4296 data->player_uuid_old = getStringCopy(setup.player_uuid);
4297 data->player_uuid_new = getStringCopy(uuid_new);
4302 static void FreeThreadData_ApiResetUUID(void *data_raw)
4304 struct ApiResetUUIDThreadData *data = data_raw;
4306 checked_free(data->player_name);
4307 checked_free(data->player_uuid_old);
4308 checked_free(data->player_uuid_new);
4312 static boolean SetRequest_ApiResetUUID(struct HttpRequest *request,
4315 struct ApiResetUUIDThreadData *data = data_raw;
4316 char *player_name_raw = data->player_name;
4317 char *player_uuid_old_raw = data->player_uuid_old;
4318 char *player_uuid_new_raw = data->player_uuid_new;
4320 request->hostname = setup.api_server_hostname;
4321 request->port = API_SERVER_PORT;
4322 request->method = API_SERVER_METHOD;
4323 request->uri = API_SERVER_URI_RESETUUID;
4325 char *player_name = getEscapedJSON(player_name_raw);
4326 char *player_uuid_old = getEscapedJSON(player_uuid_old_raw);
4327 char *player_uuid_new = getEscapedJSON(player_uuid_new_raw);
4329 snprintf(request->body, MAX_HTTP_BODY_SIZE,
4332 " \"game_version\": \"%s\",\n"
4333 " \"game_platform\": \"%s\",\n"
4334 " \"name\": \"%s\",\n"
4335 " \"uuid_old\": \"%s\",\n"
4336 " \"uuid_new\": \"%s\"\n"
4338 getPasswordJSON(setup.api_server_password),
4339 getProgramRealVersionString(),
4340 getProgramPlatformString(),
4345 checked_free(player_name);
4346 checked_free(player_uuid_old);
4347 checked_free(player_uuid_new);
4349 ConvertHttpRequestBodyToServerEncoding(request);
4354 static void HandleResponse_ApiResetUUID(struct HttpResponse *response,
4357 struct ApiResetUUIDThreadData *data = data_raw;
4359 // upgrade player UUID in server setup file
4360 setup.player_uuid = getStringCopy(data->player_uuid_new);
4361 setup.player_version = 2;
4363 SaveSetup_ServerSetup();
4366 #if defined(PLATFORM_EMSCRIPTEN)
4367 static void Emscripten_ApiResetUUID_Loaded(unsigned handle, void *data_raw,
4368 void *buffer, unsigned int size)
4370 struct HttpResponse *response = GetHttpResponseFromBuffer(buffer, size);
4372 if (response != NULL)
4374 HandleResponse_ApiResetUUID(response, data_raw);
4376 checked_free(response);
4380 Error("server response too large to handle (%d bytes)", size);
4383 FreeThreadData_ApiResetUUID(data_raw);
4386 static void Emscripten_ApiResetUUID_Failed(unsigned handle, void *data_raw,
4387 int code, const char *status)
4389 Error("server failed to handle request: %d %s", code, status);
4391 FreeThreadData_ApiResetUUID(data_raw);
4394 static void Emscripten_ApiResetUUID_Progress(unsigned handle, void *data_raw,
4395 int bytes, int size)
4397 // nothing to do here
4400 static void Emscripten_ApiResetUUID_HttpRequest(struct HttpRequest *request,
4403 if (!SetRequest_ApiResetUUID(request, data_raw))
4405 FreeThreadData_ApiResetUUID(data_raw);
4410 emscripten_async_wget2_data(request->uri,
4415 Emscripten_ApiResetUUID_Loaded,
4416 Emscripten_ApiResetUUID_Failed,
4417 Emscripten_ApiResetUUID_Progress);
4422 static void ApiResetUUID_HttpRequestExt(struct HttpRequest *request,
4423 struct HttpResponse *response,
4426 if (!SetRequest_ApiResetUUID(request, data_raw))
4429 if (!DoHttpRequest(request, response))
4431 Error("HTTP request failed: %s", GetHttpError());
4436 if (!HTTP_SUCCESS(response->status_code))
4438 Error("server failed to handle request: %d %s",
4439 response->status_code,
4440 response->status_text);
4445 HandleResponse_ApiResetUUID(response, data_raw);
4448 static void ApiResetUUID_HttpRequest(struct HttpRequest *request,
4449 struct HttpResponse *response,
4452 ApiResetUUID_HttpRequestExt(request, response, data_raw);
4454 FreeThreadData_ApiResetUUID(data_raw);
4458 static int ApiResetUUIDThread(void *data_raw)
4460 struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
4461 struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
4463 program.api_thread_count++;
4465 #if defined(PLATFORM_EMSCRIPTEN)
4466 Emscripten_ApiResetUUID_HttpRequest(request, data_raw);
4468 ApiResetUUID_HttpRequest(request, response, data_raw);
4471 program.api_thread_count--;
4473 checked_free(request);
4474 checked_free(response);
4479 static void ApiResetUUIDAsThread(char *uuid_new)
4481 struct ApiResetUUIDThreadData *data = CreateThreadData_ApiResetUUID(uuid_new);
4483 ExecuteAsThread(ApiResetUUIDThread,
4484 "ApiResetUUID", data,
4485 "reset UUID on server");
4489 // ============================================================================
4490 // type name functions
4491 // ============================================================================
4493 static TreeInfo *type_name_node = NULL;
4494 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4495 static int type_name_nr = 0;
4497 static int getPlayerNameColor(char *name)
4499 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4502 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4505 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4506 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4507 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4508 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4509 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4510 int font_width = getFontWidth(font_nr);
4512 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4514 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4516 pos->width = strlen(text) * font_width;
4517 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4519 DrawText(sx, sy, text, font_nr);
4522 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4524 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4526 *pos = *mci->pos_input;
4528 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4530 TreeInfo *ti = player_name_current;
4531 int first_entry = ti->cl_first;
4532 int entry_pos = first_entry + ti->cl_cursor;
4533 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4534 int xpos = MENU_SCREEN_START_XPOS;
4535 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4537 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4538 type_name_nr = entry_pos;
4540 strcpy(name, type_name_node->name);
4544 pos->width = MAX_PLAYER_NAME_LEN * 32;
4548 type_name_nr = user.nr;
4550 strcpy(name, setup.player_name);
4553 strcpy(type_name_last, name);
4555 if (strEqual(name, EMPTY_PLAYER_NAME))
4558 *xpos = strlen(name);
4561 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4563 // change name of edited user in global list of user names
4564 setString(&global.user_names[type_name_nr], name);
4566 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4568 TreeInfo *node = type_name_node;
4570 // change name of edited user in local menu tree structure
4571 setString(&node->name, name);
4572 setString(&node->name_sorting, name);
4574 node->color = getPlayerNameColor(name);
4575 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4579 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4582 boolean reset_setup = strEqual(name, "");
4583 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4584 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4587 strcpy(name, type_name_last);
4589 if (strEqual(name, ""))
4590 strcpy(name, EMPTY_PLAYER_NAME);
4592 setTypeNameValues_Name(name, pos);
4594 // if player name not changed, no further action required
4595 if (strEqual(name, type_name_last))
4598 // redraw player name before (possibly) opening request dialogs
4599 drawTypeNameText(name, pos, FALSE);
4601 int last_user_nr = user.nr;
4603 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4605 // save setup of currently active user (may differ from edited user)
4608 // temporarily change active user to edited user
4609 user.nr = type_name_nr;
4612 Request("Use current setup values for the new player?", REQ_ASK))
4614 // use current setup values for new user, but create new player UUID
4615 setup.player_uuid = getStringCopy(getUUID());
4619 // load setup for existing user (or start with defaults for new user)
4624 char *setup_filename = getSetupFilename();
4625 boolean setup_exists = fileExists(setup_filename);
4627 // change name of edited user in setup structure
4628 strcpy(setup.player_name, name);
4630 // save setup of edited user
4633 // change name of edited user on score server
4634 ApiRenamePlayerAsThread();
4636 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4640 if (Request("Reset setup values for this player?", REQ_ASK))
4642 // remove setup config file
4643 unlink(setup_filename);
4645 // set player name to default player name
4648 // update player name used by name typing functions
4649 strcpy(name, setup.player_name);
4651 setTypeNameValues_Name(name, pos);
4654 else if (remove_user && type_name_nr != 0)
4656 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4658 char *user_dir = getUserGameDataDir();
4659 char *user_dir_removed =
4660 getStringCat3WithSeparator(user_dir, "REMOVED",
4661 getCurrentTimestamp(), ".");
4663 if (rename(user_dir, user_dir_removed) != 0)
4664 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4666 checked_free(user_dir_removed);
4669 else if (create_user && type_name_nr != 0 && !setup_exists)
4671 if (Request("Create empty level set for the new player?", REQ_ASK))
4673 char *levelset_subdir = getNewUserLevelSubdir();
4675 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4677 AddUserLevelSetToLevelInfo(levelset_subdir);
4679 LevelDirTree *leveldir_current_last = leveldir_current;
4681 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4684 // set level number of newly created level set to default value
4685 LoadLevelSetup_SeriesInfo();
4687 // set newly created level set as current level set for new user
4688 SaveLevelSetup_LastSeries();
4689 SaveLevelSetup_SeriesInfo();
4691 leveldir_current = leveldir_current_last;
4695 Request("Creating new level set failed!", REQ_CONFIRM);
4700 // restore currently active user
4701 user.nr = last_user_nr;
4703 // restore setup of currently active user
4706 // restore last level set of currently active user
4707 LoadLevelSetup_LastSeries();
4708 LoadLevelSetup_SeriesInfo();
4712 static void HandleTypeNameExt(boolean initialize, Key key)
4714 static struct TextPosInfo pos_name = { 0 };
4715 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4716 static int xpos = 0;
4717 struct TextPosInfo *pos = &pos_name;
4718 char key_char = getValidConfigValueChar(getCharFromKey(key));
4719 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4720 boolean active = TRUE;
4724 getTypeNameValues(name, pos, &xpos);
4726 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4727 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4729 StartTextInput(sx, sy, pos->width, pos->height);
4731 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4733 name[xpos] = key_char;
4738 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4744 else if (key == KSYM_Return || key == KSYM_Escape)
4746 boolean changed = (key == KSYM_Return);
4750 setTypeNameValues(name, pos, changed);
4755 drawTypeNameText(name, pos, active);
4759 SetGameStatus(game_status_last_screen);
4761 if (game_status == GAME_MODE_MAIN)
4762 InitializeMainControls();
4766 static void DrawTypeName(void)
4768 HandleTypeNameExt(TRUE, 0);
4771 void HandleTypeName(Key key)
4773 HandleTypeNameExt(FALSE, key);
4777 // ============================================================================
4778 // tree menu functions
4779 // ============================================================================
4781 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4783 if (game_status != GAME_MODE_SETUP ||
4784 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4787 int max_text_size = 0;
4790 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4791 max_text_size = MAX(max_text_size, strlen(node->name));
4793 int num_entries = numTreeInfoInGroup(ti);
4794 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4795 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4796 int text_width = max_text_size * getFontWidth(font_nr);
4797 int button_width = SC_MENUBUTTON_XSIZE;
4798 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4799 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4800 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4801 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4802 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4803 int align_xoffset = MAX(0, align_xoffset_raw);
4805 return align_xoffset;
4808 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4810 if (game_status != GAME_MODE_SETUP ||
4811 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4814 int num_entries = numTreeInfoInGroup(ti);
4815 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4816 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4817 int font_height = getFontHeight(font_nr);
4818 int text_height = font_height * num_page_entries;
4819 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4820 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4821 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4822 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4823 int align_yoffset = MAX(0, align_yoffset_raw);
4825 return align_yoffset;
4828 static void DrawChooseTree(TreeInfo **ti_ptr)
4830 int fade_mask = REDRAW_FIELD;
4833 fade_mask = REDRAW_ALL;
4835 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4837 if (game_status == GAME_MODE_SETUP)
4841 else // GAME_MODE_LEVELS
4843 SetGameStatus(GAME_MODE_MAIN);
4853 FreeScreenGadgets();
4854 CreateScreenGadgets();
4856 if (game_status != game_status_last_screen)
4857 FadeMenuSoundsAndMusic();
4861 // needed if different viewport properties defined for this screen
4862 ChangeViewportPropertiesIfNeeded();
4864 if (game_status == GAME_MODE_NAMES)
4865 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4866 else if (game_status == GAME_MODE_LEVELNR)
4867 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4868 else if (game_status == GAME_MODE_LEVELS)
4869 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4870 else if (game_status == GAME_MODE_SCORES)
4871 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4875 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4877 // map gadgets for high score screen
4878 if (game_status == GAME_MODE_SCORES)
4879 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4881 MapScreenTreeGadgets(*ti_ptr);
4883 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4885 DrawMaskedBorder(fade_mask);
4887 if (game_status != game_status_last_screen)
4888 PlayMenuSoundsAndMusic();
4893 static int getChooseTreeFont(TreeInfo *node, boolean active)
4895 if (game_status == GAME_MODE_SCORES)
4896 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4898 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4901 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4903 int num_entries = numTreeInfoInGroup(ti);
4904 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4905 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4906 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4907 int first_entry = ti->cl_first;
4908 int entry_pos = first_entry + y;
4909 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4910 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4911 int font_nr = getChooseTreeFont(node, active);
4912 int font_xoffset = getFontDrawOffsetX(font_nr);
4913 int xpos = MENU_SCREEN_START_XPOS;
4914 int ypos = MENU_SCREEN_START_YPOS + y;
4915 int startdx = xpos * 32;
4916 int startdy = ypos * 32;
4917 int startx = amSX + startdx;
4918 int starty = amSY + startdy;
4919 int startx_text = startx + font_xoffset;
4920 int endx_text = amSX + screen_width;
4921 int max_text_size = endx_text - startx_text;
4922 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4923 char buffer[max_buffer_len + 1];
4925 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4927 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4928 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4929 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4930 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4931 int font_size_1 = getFontWidth(font_nr1);
4932 int font_size_3 = getFontWidth(font_nr3);
4933 int font_size_4 = getFontWidth(font_nr4);
4934 int text_size_1 = 3 * font_size_1;
4935 int text_size_4 = 5 * font_size_4;
4936 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4938 int dx2 = text_size_1;
4939 int dx3 = dx2 + font_size_1;
4940 int dx4 = screen_width - startdx - 2 * border - text_size_4;
4941 int num_dots = (dx4 - dx3) / font_size_3;
4942 int startx1 = startx + dx1;
4943 int startx2 = startx + dx2;
4944 int startx3 = startx + dx3;
4945 int startx4 = startx + dx4;
4946 int pos = node->pos;
4947 char *pos_text = getHallOfFameRankText(pos);
4948 char *dot_text = ".";
4951 DrawText(startx1, starty, pos_text, font_nr1);
4952 DrawText(startx2, starty, dot_text, font_nr1);
4954 for (i = 0; i < num_dots; i++)
4955 DrawText(startx3 + i * font_size_3, starty, dot_text, font_nr3);
4957 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4958 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4960 DrawText(startx4, starty, getHallOfFameScoreText(pos), font_nr4);
4964 strncpy(buffer, node->name, max_buffer_len);
4965 buffer[max_buffer_len] = '\0';
4967 DrawText(startx, starty, buffer, font_nr);
4971 static void drawChooseTreeHeadExt(int type, char *title_string)
4973 int yoffset_sets = MENU_TITLE1_YPOS;
4974 int yoffset_setup = 16;
4975 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4976 type == TREE_TYPE_LEVEL_DIR ||
4977 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4979 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4982 static void drawChooseTreeHead(TreeInfo *ti)
4984 drawChooseTreeHeadExt(ti->type, ti->infotext);
4987 static void drawChooseTreeList(TreeInfo *ti)
4989 int first_entry = ti->cl_first;
4990 int num_entries = numTreeInfoInGroup(ti);
4991 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4994 clearMenuListArea();
4996 for (i = 0; i < num_page_entries; i++)
4998 TreeInfo *node, *node_first;
4999 int entry_pos = first_entry + i;
5001 node_first = getTreeInfoFirstGroupEntry(ti);
5002 node = getTreeInfoFromPos(node_first, entry_pos);
5004 drawChooseTreeText(ti, i, FALSE);
5006 if (node->parent_link)
5007 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5008 else if (node->level_group)
5009 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5011 initCursor(i, IMG_MENU_BUTTON);
5013 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
5014 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5016 if (game_status == GAME_MODE_NAMES)
5017 drawChooseTreeEdit(i, FALSE);
5020 redraw_mask |= REDRAW_FIELD;
5023 static void drawChooseTreeInfo(TreeInfo *ti)
5025 int entry_pos = ti->cl_first + ti->cl_cursor;
5026 int last_redraw_mask = redraw_mask;
5027 int ypos = MENU_TITLE2_YPOS;
5028 int font_nr = FONT_TITLE_2;
5031 if (ti->type == TREE_TYPE_LEVEL_NR)
5032 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
5034 if (ti->type == TREE_TYPE_SCORE_ENTRY)
5035 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
5036 scores.last_level_nr);
5038 if (ti->type != TREE_TYPE_LEVEL_DIR)
5041 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
5042 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
5044 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
5046 if (node->parent_link)
5047 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
5048 node->node_parent->name);
5049 else if (node->level_group)
5050 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
5052 else if (ti->type == TREE_TYPE_LEVEL_DIR)
5053 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
5054 node->levels, (node->levels > 1 ? "levels" : "level"),
5057 // let BackToFront() redraw only what is needed
5058 redraw_mask = last_redraw_mask;
5059 for (x = 0; x < SCR_FIELDX; x++)
5060 MarkTileDirty(x, 1);
5063 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
5065 drawChooseTreeCursor(ti->cl_cursor, active);
5066 drawChooseTreeText(ti, ti->cl_cursor, active);
5069 static void drawChooseTreeScreen(TreeInfo *ti)
5071 drawChooseTreeHead(ti);
5072 drawChooseTreeList(ti);
5073 drawChooseTreeInfo(ti);
5074 drawChooseTreeCursorAndText(ti, TRUE);
5076 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
5078 // scroll bar and buttons may just have been added after reloading scores
5079 if (game_status == GAME_MODE_SCORES)
5080 MapScreenTreeGadgets(ti);
5083 static void drawChooseTreeScreen_Scores_NotAvailable(void)
5085 // dirty workaround to use spacing definitions from info screen
5086 info_mode = INFO_MODE_TITLE;
5088 char *text_info = "HighScores of Level %d";
5089 char *text_title = "Score information:";
5090 char *text_error = "No scores for this level.";
5091 char *text_foot = "Press any key or button for main menu";
5092 int font_info = FONT_TITLE_2;
5093 int font_title = FONT_INITIAL_3;
5094 int font_error = FONT_INITIAL_4;
5095 int font_foot = FONT_INITIAL_2;
5096 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
5097 int ystep_title = getMenuTextStep(spacing_title, font_title);
5098 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
5099 int ystart2 = ystart1 + ystep_title;
5100 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
5101 int ystart0 = MENU_TITLE2_YPOS;
5103 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
5104 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
5106 DrawTextSCentered(ystart1, font_title, text_title);
5107 DrawTextSCentered(ystart2, font_error, text_error);
5109 DrawTextSCentered(ybottom, font_foot, text_foot);
5112 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
5114 // set current tree entry to last added score entry
5115 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(scores.last_added));
5117 // if that fails, set current tree entry to first entry (back link)
5118 if (*ti_ptr == NULL)
5119 *ti_ptr = score_entries->node_group;
5121 int num_entries = numTreeInfoInGroup(*ti_ptr);
5122 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5123 int pos_score = getPosFromTreeInfo(*ti_ptr);
5124 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
5125 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
5127 (*ti_ptr)->cl_first = pos_first;
5128 (*ti_ptr)->cl_cursor = pos_score - pos_first;
5133 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
5136 TreeInfo *ti = *ti_ptr;
5137 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
5138 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
5139 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
5140 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
5141 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
5143 int y = (ti != NULL ? ti->cl_cursor : 0);
5144 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5145 int num_entries = numTreeInfoInGroup(ti);
5146 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
5147 boolean position_set_by_scrollbar = (dx == 999);
5148 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5149 boolean button_is_valid = (mx >= 0 && my >= 0);
5150 boolean button_screen_clicked = (button_action && button_is_valid);
5152 if (game_status == GAME_MODE_SCORES)
5154 if (server_scores.updated)
5156 // reload scores, using updated server score cache file
5157 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5159 server_scores.updated = FALSE;
5161 DrawHallOfFame_setScoreEntries();
5163 if (score_entries != NULL)
5165 ti = setHallOfFameActiveEntry(ti_ptr);
5167 if (button != MB_MENU_INITIALIZE)
5168 drawChooseTreeScreen(ti);
5172 if (score_entries == NULL)
5174 if (button == MB_MENU_INITIALIZE)
5176 drawChooseTreeScreen_Scores_NotAvailable();
5178 else if (button_screen_clicked)
5180 PlaySound(SND_MENU_ITEM_SELECTING);
5182 SetGameStatus(GAME_MODE_MAIN);
5191 if (button == MB_MENU_INITIALIZE)
5193 int num_entries = numTreeInfoInGroup(ti);
5194 int entry_pos = getPosFromTreeInfo(ti);
5196 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
5197 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
5199 if (game_status == GAME_MODE_SCORES)
5201 ti = setHallOfFameActiveEntry(ti_ptr);
5203 else if (ti->cl_first == -1)
5205 // only on initialization
5206 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5207 ti->cl_cursor = entry_pos - ti->cl_first;
5210 else if (ti->cl_cursor >= num_page_entries ||
5211 (num_entries > num_page_entries &&
5212 num_entries - ti->cl_first < num_page_entries))
5214 // only after change of list size (by custom graphic configuration)
5215 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
5216 ti->cl_cursor = entry_pos - ti->cl_first;
5219 if (position_set_by_scrollbar)
5222 drawChooseTreeScreen(ti);
5226 else if (button == MB_MENU_LEAVE)
5228 if (game_status != GAME_MODE_SCORES)
5231 PlaySound(SND_MENU_ITEM_SELECTING);
5233 if (ti->node_parent)
5235 *ti_ptr = ti->node_parent;
5236 DrawChooseTree(ti_ptr);
5238 else if (game_status == GAME_MODE_SETUP)
5240 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5241 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5242 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5243 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5245 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5246 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5247 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5248 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5249 execSetupGraphics();
5250 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5251 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5252 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5254 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5255 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5256 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5257 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5258 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5259 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5260 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5261 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5268 if (game_status == GAME_MODE_LEVELNR)
5270 int new_level_nr = atoi(level_number_current->identifier);
5272 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5275 SetGameStatus(GAME_MODE_MAIN);
5283 if (mx || my) // mouse input
5285 x = (mx - amSX) / 32;
5286 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5288 if (game_status == GAME_MODE_NAMES)
5289 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5291 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5293 // move cursor instead of scrolling when already at start/end of list
5294 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5296 else if (dy == +1 * SCROLL_LINE &&
5297 ti->cl_first + num_page_entries == num_entries)
5300 // handle scrolling screen one line or page
5301 if (ti->cl_cursor + dy < 0 ||
5302 ti->cl_cursor + dy > num_page_entries - 1)
5304 boolean redraw = FALSE;
5306 if (ABS(dy) == SCROLL_PAGE)
5307 step = num_page_entries - 1;
5309 if (dy < 0 && ti->cl_first > 0)
5311 // scroll page/line up
5313 ti->cl_first -= step;
5314 if (ti->cl_first < 0)
5319 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5321 // scroll page/line down
5323 ti->cl_first += step;
5324 if (ti->cl_first + num_page_entries > num_entries)
5325 ti->cl_first = MAX(0, num_entries - num_page_entries);
5331 drawChooseTreeScreen(ti);
5336 // handle moving cursor one line
5337 y = ti->cl_cursor + dy;
5340 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5342 HandleHallOfFame_SelectLevel(1, dx);
5348 TreeInfo *node_first, *node_cursor;
5349 int entry_pos = ti->cl_first + y;
5351 node_first = getTreeInfoFirstGroupEntry(ti);
5352 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5354 if (node_cursor->node_group)
5358 PlaySound(SND_MENU_ITEM_SELECTING);
5360 node_cursor->cl_first = ti->cl_first;
5361 node_cursor->cl_cursor = ti->cl_cursor;
5362 *ti_ptr = node_cursor->node_group;
5363 DrawChooseTree(ti_ptr);
5368 else if (dx == -1 && ti->node_parent)
5372 PlaySound(SND_MENU_ITEM_SELECTING);
5374 *ti_ptr = ti->node_parent;
5375 DrawChooseTree(ti_ptr);
5380 if (!anyScrollbarGadgetActive() &&
5381 IN_VIS_MENU(x, y) &&
5382 mx < mx_right_border &&
5383 y >= 0 && y < num_page_entries)
5387 if (game_status == GAME_MODE_NAMES)
5389 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5390 drawChooseTreeEdit(y, TRUE);
5393 if (y != ti->cl_cursor)
5395 PlaySound(SND_MENU_ITEM_ACTIVATING);
5397 drawChooseTreeCursorAndText(ti, FALSE);
5401 drawChooseTreeCursorAndText(ti, TRUE);
5403 drawChooseTreeInfo(ti);
5407 if (game_status == GAME_MODE_SETUP)
5409 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5410 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5411 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5412 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5414 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5415 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5416 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5417 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5418 execSetupGraphics();
5419 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5420 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5421 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5423 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5424 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5425 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5426 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5427 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5428 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5429 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5430 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5439 TreeInfo *node_first, *node_cursor;
5440 int entry_pos = ti->cl_first + y;
5442 PlaySound(SND_MENU_ITEM_SELECTING);
5444 node_first = getTreeInfoFirstGroupEntry(ti);
5445 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5447 if (node_cursor->node_group)
5451 node_cursor->cl_first = ti->cl_first;
5452 node_cursor->cl_cursor = ti->cl_cursor;
5453 *ti_ptr = node_cursor->node_group;
5454 DrawChooseTree(ti_ptr);
5456 else if (node_cursor->parent_link)
5458 if (game_status != GAME_MODE_SCORES)
5461 *ti_ptr = node_cursor->node_parent;
5462 DrawChooseTree(ti_ptr);
5466 if (game_status != GAME_MODE_SCORES)
5469 node_cursor->cl_first = ti->cl_first;
5470 node_cursor->cl_cursor = ti->cl_cursor;
5471 *ti_ptr = node_cursor;
5473 if (ti->type == TREE_TYPE_LEVEL_DIR)
5475 LoadLevelSetup_SeriesInfo();
5477 SaveLevelSetup_LastSeries();
5478 SaveLevelSetup_SeriesInfo();
5482 if (game_status == GAME_MODE_SETUP)
5484 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5485 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5486 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5487 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5489 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5490 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5491 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5492 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5493 execSetupGraphics();
5494 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5495 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5496 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5498 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5499 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5500 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5501 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5502 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5503 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5504 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5505 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5512 if (game_status == GAME_MODE_LEVELNR)
5514 int new_level_nr = atoi(level_number_current->identifier);
5516 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5518 else if (game_status == GAME_MODE_LEVELS)
5520 // store level set if chosen from "last played level set" menu
5521 StoreLastPlayedLevels(leveldir_current);
5523 else if (game_status == GAME_MODE_NAMES)
5525 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5527 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5534 // change active user to selected user
5535 user.nr = entry_pos;
5537 // save number of new active user
5540 // load setup of new active user
5543 // load last level set of new active user
5544 LoadLevelSetup_LastSeries();
5545 LoadLevelSetup_SeriesInfo();
5547 // update list of last played level sets
5548 UpdateLastPlayedLevels_TreeInfo();
5552 ToggleFullscreenIfNeeded();
5553 ChangeWindowScalingIfNeeded();
5555 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5556 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5557 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5559 else if (game_status == GAME_MODE_SCORES)
5561 if (game_status_last_screen == GAME_MODE_PLAYING &&
5562 setup.auto_play_next_level && setup.increment_levels &&
5563 scores.last_level_nr < leveldir_current->last_level &&
5566 StartGameActions(network.enabled, setup.autorecord,
5572 SetGameStatus(GAME_MODE_SCOREINFO);
5574 DrawScoreInfo(node_cursor->pos);
5580 SetGameStatus(GAME_MODE_MAIN);
5588 if (game_status == GAME_MODE_SCORES)
5589 PlayMenuSoundIfLoop();
5592 void DrawChoosePlayerName(void)
5596 if (player_name != NULL)
5598 freeTreeInfo(player_name);
5603 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5605 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5606 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5609 ti->node_top = &player_name;
5610 ti->sort_priority = 10000 + value;
5611 ti->color = getPlayerNameColor(global.user_names[i]);
5613 snprintf(identifier, sizeof(identifier), "%d", value);
5614 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5616 setString(&ti->identifier, identifier);
5617 setString(&ti->name, name);
5618 setString(&ti->name_sorting, name);
5620 pushTreeInfo(&player_name, ti);
5623 // sort player entries by player number
5624 sortTreeInfo(&player_name);
5626 // set current player entry to selected player entry
5627 player_name_current =
5628 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5630 // if that fails, set current player name to first available name
5631 if (player_name_current == NULL)
5632 player_name_current = player_name;
5634 DrawChooseTree(&player_name_current);
5637 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5639 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5642 void DrawChooseLevelSet(void)
5644 DrawChooseTree(&leveldir_current);
5647 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5649 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5652 void DrawChooseLevelNr(void)
5656 if (level_number != NULL)
5658 freeTreeInfo(level_number);
5660 level_number = NULL;
5663 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5665 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5666 char identifier[32], name[64];
5669 // temporarily load level info to get level name
5670 LoadLevelInfoOnly(i);
5672 ti->node_top = &level_number;
5673 ti->sort_priority = 10000 + value;
5674 ti->color = (level.no_level_file ? FC_BLUE :
5675 LevelStats_getSolved(i) ? FC_GREEN :
5676 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5678 snprintf(identifier, sizeof(identifier), "%d", value);
5679 snprintf(name, sizeof(name), "%03d: %s", value,
5680 (level.no_level_file ? "(no file)" : level.name));
5682 setString(&ti->identifier, identifier);
5683 setString(&ti->name, name);
5684 setString(&ti->name_sorting, name);
5686 pushTreeInfo(&level_number, ti);
5689 // sort level number values to start with lowest level number
5690 sortTreeInfo(&level_number);
5692 // set current level number to current level number
5693 level_number_current =
5694 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5696 // if that also fails, set current level number to first available level
5697 if (level_number_current == NULL)
5698 level_number_current = level_number;
5700 DrawChooseTree(&level_number_current);
5703 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5705 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5708 static void DrawHallOfFame_setScoreEntries(void)
5710 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5713 if (score_entries != NULL)
5715 freeTreeInfo(score_entries);
5717 score_entries = NULL;
5720 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5722 // do not add empty score entries
5723 if (scores.entry[i].score == 0 &&
5724 scores.entry[i].time == 0)
5727 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5728 char identifier[32], name[64];
5731 ti->node_top = &score_entries;
5732 ti->sort_priority = 10000 + value;
5733 ti->color = FC_YELLOW;
5736 snprintf(identifier, sizeof(identifier), "%d", value);
5737 snprintf(name, sizeof(name), "%03d.", value + 1);
5739 setString(&ti->identifier, identifier);
5740 setString(&ti->name, name);
5741 setString(&ti->name_sorting, name);
5743 pushTreeInfo(&score_entries, ti);
5746 // sort score entries to start with highest score entry
5747 sortTreeInfo(&score_entries);
5749 // add top tree node to create back link to main menu
5750 score_entries = addTopTreeInfoNode(score_entries);
5752 // set current score entry to last added or highest score entry
5753 score_entry_current =
5754 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5756 // if that fails, set current score entry to first valid score entry
5757 if (score_entry_current == NULL)
5758 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5760 // ("score_entries" and "score_entry_current" may be NULL here)
5763 void DrawHallOfFame(int level_nr)
5765 scores.last_level_nr = level_nr;
5767 // (this is needed when called from GameEnd() after winning a game)
5768 KeyboardAutoRepeatOn();
5770 // (this is needed when called from GameEnd() after winning a game)
5771 SetDrawDeactivationMask(REDRAW_NONE);
5772 SetDrawBackgroundMask(REDRAW_FIELD);
5774 LoadLocalAndServerScore(level_nr, TRUE);
5776 DrawHallOfFame_setScoreEntries();
5778 if (scores.last_added >= 0)
5779 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5781 FadeSetEnterScreen();
5783 DrawChooseTree(&score_entry_current);
5786 static char *getHallOfFameRankText(int nr)
5788 boolean forced = (scores.force_last_added && nr == scores.last_added);
5790 return (forced ? "???" : int2str(nr + 1, 3));
5793 static char *getHallOfFameTimeText(int nr)
5795 static char score_text[10];
5796 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5797 int mm = (time_seconds / 60) % 60;
5798 int ss = (time_seconds % 60);
5800 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5805 static char *getHallOfFameScoreText(int nr)
5807 if (!level.rate_time_over_score)
5808 return int2str(scores.entry[nr].score, 5); // show normal score
5809 else if (level.use_step_counter)
5810 return int2str(scores.entry[nr].time, 5); // show number of steps
5812 return getHallOfFameTimeText(nr); // show playing time
5815 static void HandleHallOfFame_SelectLevel(int step, int direction)
5817 int old_level_nr = scores.last_level_nr;
5818 int new_level_nr = old_level_nr + step * direction;
5820 if (new_level_nr < leveldir_current->first_level)
5821 new_level_nr = leveldir_current->first_level;
5822 if (new_level_nr > leveldir_current->last_level)
5823 new_level_nr = leveldir_current->last_level;
5825 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5826 new_level_nr = leveldir_current->handicap_level;
5828 if (new_level_nr != old_level_nr)
5830 PlaySound(SND_MENU_ITEM_SELECTING);
5832 scores.last_level_nr = level_nr = new_level_nr;
5834 LoadLocalAndServerScore(level_nr, TRUE);
5836 DrawHallOfFame_setScoreEntries();
5838 // force remapping optional gadgets (especially scroll bar)
5839 UnmapScreenTreeGadgets();
5841 // redraw complete high score screen, as sub-title has changed
5844 // redraw level selection buttons (which have just been erased)
5845 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5847 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5849 SaveLevelSetup_SeriesInfo();
5853 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5855 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5858 static void DrawScoreInfo(int entry_nr)
5860 struct ScoreEntry *entry = &scores.entry[entry_nr];
5861 char *pos_text = getHallOfFameRankText(entry_nr);
5862 int font_title = MENU_INFO_FONT_TITLE;
5863 int font_head = MENU_INFO_FONT_HEAD;
5864 int font_text = MENU_INFO_FONT_TEXT;
5865 int font_foot = MENU_INFO_FONT_FOOT;
5866 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5867 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5868 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5869 int xstep = getFontWidth(font_text);
5870 int ystep_title = getMenuTextStep(spacing_title, font_title);
5871 int ystep_para = getMenuTextStep(spacing_para, font_text);
5872 int ystep_line = getMenuTextStep(spacing_line, font_text);
5873 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5874 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5875 int xstart1 = mSX - SX + 2 * xstep;
5876 int xstart2 = mSX - SX + 14 * xstep;
5878 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5882 FadeOut(REDRAW_FIELD);
5886 drawChooseTreeHead(score_entries);
5887 drawChooseTreeInfo(score_entries);
5889 DrawTextSCentered(ystart, font_title, "Score Information:");
5890 ystart += ystep_title;
5892 DrawTextF(xstart1, ystart, font_head, "Level Set");
5893 DrawTextF(xstart2, ystart, font_text, leveldir_current->name);
5894 ystart += ystep_line;
5896 DrawTextF(xstart1, ystart, font_head, "Level Name");
5897 DrawTextF(xstart2, ystart, font_text, level.name);
5898 ystart += ystep_para;
5900 DrawTextF(xstart1, ystart, font_head, "Rank");
5901 DrawTextF(xstart2, ystart, font_text, pos_text);
5902 ystart += ystep_line;
5904 DrawTextF(xstart1, ystart, font_head, "Player");
5905 DrawTextF(xstart2, ystart, font_text, entry->name);
5906 ystart += ystep_line;
5908 if (level.use_step_counter)
5910 DrawTextF(xstart1, ystart, font_head, "Steps");
5911 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5912 ystart += ystep_line;
5916 DrawTextF(xstart1, ystart, font_head, "Time");
5917 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5918 ystart += ystep_line;
5921 if (!level.rate_time_over_score || entry->score > 0)
5923 DrawTextF(xstart1, ystart, font_head, "Score");
5924 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5925 ystart += ystep_line;
5928 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5930 FadeIn(REDRAW_FIELD);
5933 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5935 if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5937 PlaySound(SND_MENU_ITEM_SELECTING);
5939 SetGameStatus(GAME_MODE_SCORES);
5941 DrawHallOfFame(level_nr);
5946 // ============================================================================
5947 // setup screen functions
5948 // ============================================================================
5950 static struct TokenInfo *setup_info;
5951 static int num_setup_info; // number of setup entries shown on screen
5952 static int max_setup_info; // total number of setup entries in list
5954 static char *window_size_text;
5955 static char *scaling_type_text;
5956 static char *rendering_mode_text;
5957 static char *vsync_mode_text;
5958 static char *scroll_delay_text;
5959 static char *snapshot_mode_text;
5960 static char *game_speed_text;
5961 static char *scores_type_text;
5962 static char *network_server_text;
5963 static char *graphics_set_name;
5964 static char *sounds_set_name;
5965 static char *music_set_name;
5966 static char *volume_simple_text;
5967 static char *volume_loops_text;
5968 static char *volume_music_text;
5969 static char *touch_controls_text;
5970 static char *move_distance_text;
5971 static char *drop_distance_text;
5972 static char *transparency_text;
5973 static char *grid_size_text[2][2];
5975 static void execSetupMain(void)
5977 setup_mode = SETUP_MODE_MAIN;
5982 static void execSetupGame_setScoresType(void)
5984 if (scores_types == NULL)
5988 for (i = 0; scores_types_list[i].value != NULL; i++)
5990 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5991 char identifier[32], name[32];
5992 char *value = scores_types_list[i].value;
5993 char *text = scores_types_list[i].text;
5995 ti->node_top = &scores_types;
5996 ti->sort_priority = i;
5998 sprintf(identifier, "%s", value);
5999 sprintf(name, "%s", text);
6001 setString(&ti->identifier, identifier);
6002 setString(&ti->name, name);
6003 setString(&ti->name_sorting, name);
6004 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
6006 pushTreeInfo(&scores_types, ti);
6009 // sort scores type values to start with lowest scores type value
6010 sortTreeInfo(&scores_types);
6012 // set current scores type value to configured scores type value
6013 scores_type_current =
6014 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
6016 // if that fails, set current scores type to reliable default value
6017 if (scores_type_current == NULL)
6018 scores_type_current =
6019 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
6021 // if that also fails, set current scores type to first available value
6022 if (scores_type_current == NULL)
6023 scores_type_current = scores_types;
6026 setup.scores_in_highscore_list = scores_type_current->identifier;
6028 // needed for displaying scores type text instead of identifier
6029 scores_type_text = scores_type_current->name;
6032 static void execSetupGame_setGameSpeeds(boolean update_value)
6034 if (setup.game_speed_extended)
6036 game_speeds_list = game_speeds_list_extended;
6037 game_speeds = game_speeds_extended;
6041 game_speeds_list = game_speeds_list_normal;
6042 game_speeds = game_speeds_normal;
6045 if (game_speeds == NULL)
6049 for (i = 0; game_speeds_list[i].value != -1; i++)
6051 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6052 char identifier[32], name[32];
6053 int value = game_speeds_list[i].value;
6054 char *text = game_speeds_list[i].text;
6056 ti->node_top = &game_speeds;
6057 ti->sort_priority = 10000 - value;
6059 sprintf(identifier, "%d", value);
6060 sprintf(name, "%s", text);
6062 setString(&ti->identifier, identifier);
6063 setString(&ti->name, name);
6064 setString(&ti->name_sorting, name);
6065 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
6067 pushTreeInfo(&game_speeds, ti);
6070 // sort game speed values to start with slowest game speed
6071 sortTreeInfo(&game_speeds);
6073 update_value = TRUE;
6078 // set current game speed to configured game speed value
6079 game_speed_current =
6080 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6082 // if that fails, set current game speed to reliable default value
6083 if (game_speed_current == NULL)
6084 game_speed_current =
6085 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6087 // if that also fails, set current game speed to first available speed
6088 if (game_speed_current == NULL)
6089 game_speed_current = game_speeds;
6091 if (setup.game_speed_extended)
6092 game_speeds_extended = game_speeds;
6094 game_speeds_normal = game_speeds;
6097 setup.game_frame_delay = atoi(game_speed_current->identifier);
6099 // needed for displaying game speed text instead of identifier
6100 game_speed_text = game_speed_current->name;
6103 static void execSetupGame_setScrollDelays(void)
6105 if (scroll_delays == NULL)
6109 for (i = 0; scroll_delays_list[i].value != -1; i++)
6111 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6112 char identifier[32], name[32];
6113 int value = scroll_delays_list[i].value;
6114 char *text = scroll_delays_list[i].text;
6116 ti->node_top = &scroll_delays;
6117 ti->sort_priority = value;
6119 sprintf(identifier, "%d", value);
6120 sprintf(name, "%s", text);
6122 setString(&ti->identifier, identifier);
6123 setString(&ti->name, name);
6124 setString(&ti->name_sorting, name);
6125 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6127 pushTreeInfo(&scroll_delays, ti);
6130 // sort scroll delay values to start with lowest scroll delay value
6131 sortTreeInfo(&scroll_delays);
6133 // set current scroll delay value to configured scroll delay value
6134 scroll_delay_current =
6135 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
6137 // if that fails, set current scroll delay to reliable default value
6138 if (scroll_delay_current == NULL)
6139 scroll_delay_current =
6140 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6142 // if that also fails, set current scroll delay to first available value
6143 if (scroll_delay_current == NULL)
6144 scroll_delay_current = scroll_delays;
6147 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6149 // needed for displaying scroll delay text instead of identifier
6150 scroll_delay_text = scroll_delay_current->name;
6153 static void execSetupGame_setSnapshotModes(void)
6155 if (snapshot_modes == NULL)
6159 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6161 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6162 char identifier[32], name[32];
6163 char *value = snapshot_modes_list[i].value;
6164 char *text = snapshot_modes_list[i].text;
6166 ti->node_top = &snapshot_modes;
6167 ti->sort_priority = i;
6169 sprintf(identifier, "%s", value);
6170 sprintf(name, "%s", text);
6172 setString(&ti->identifier, identifier);
6173 setString(&ti->name, name);
6174 setString(&ti->name_sorting, name);
6175 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6177 pushTreeInfo(&snapshot_modes, ti);
6180 // sort snapshot mode values to start with lowest snapshot mode value
6181 sortTreeInfo(&snapshot_modes);
6183 // set current snapshot mode value to configured snapshot mode value
6184 snapshot_mode_current =
6185 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6187 // if that fails, set current snapshot mode to reliable default value
6188 if (snapshot_mode_current == NULL)
6189 snapshot_mode_current =
6190 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6192 // if that also fails, set current snapshot mode to first available value
6193 if (snapshot_mode_current == NULL)
6194 snapshot_mode_current = snapshot_modes;
6197 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6199 // needed for displaying snapshot mode text instead of identifier
6200 snapshot_mode_text = snapshot_mode_current->name;
6203 static void execSetupGame_setNetworkServerText(void)
6205 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6207 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6211 strncpy(network_server_hostname, setup.network_server_hostname,
6212 MAX_SETUP_TEXT_INPUT_LEN);
6213 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6216 // needed for displaying network server text instead of identifier
6217 network_server_text = network_server_hostname;
6220 static void execSetupGame(void)
6222 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6224 execSetupGame_setGameSpeeds(FALSE);
6225 execSetupGame_setScoresType();
6226 execSetupGame_setScrollDelays();
6227 execSetupGame_setSnapshotModes();
6229 execSetupGame_setNetworkServerText();
6231 if (!setup.provide_uploading_tapes)
6232 setHideSetupEntry(execOfferUploadTapes);
6234 setup_mode = SETUP_MODE_GAME;
6238 // check if vsync needs to be disabled for this game speed to work
6239 if (check_vsync_mode)
6240 DisableVsyncIfNeeded();
6243 static void execSetupChooseScoresType(void)
6245 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6250 static void execSetupChooseGameSpeed(void)
6252 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6257 static void execSetupChooseScrollDelay(void)
6259 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6264 static void execSetupChooseSnapshotMode(void)
6266 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6271 static void execSetupEngines(void)
6273 setup_mode = SETUP_MODE_ENGINES;
6278 static void execSetupEditor(void)
6280 setup_mode = SETUP_MODE_EDITOR;
6285 static void execSetupGraphics_setWindowSizes(boolean update_list)
6287 if (window_sizes != NULL && update_list)
6289 freeTreeInfo(window_sizes);
6291 window_sizes = NULL;
6294 if (window_sizes == NULL)
6296 boolean current_window_size_found = FALSE;
6299 for (i = 0; window_sizes_list[i].value != -1; i++)
6301 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6302 char identifier[32], name[32];
6303 int value = window_sizes_list[i].value;
6304 char *text = window_sizes_list[i].text;
6306 ti->node_top = &window_sizes;
6307 ti->sort_priority = value;
6309 sprintf(identifier, "%d", value);
6310 sprintf(name, "%s", text);
6312 setString(&ti->identifier, identifier);
6313 setString(&ti->name, name);
6314 setString(&ti->name_sorting, name);
6315 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6317 pushTreeInfo(&window_sizes, ti);
6319 if (value == setup.window_scaling_percent)
6320 current_window_size_found = TRUE;
6323 if (!current_window_size_found)
6325 // add entry for non-preset window scaling value
6327 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6328 char identifier[32], name[32];
6329 int value = setup.window_scaling_percent;
6331 ti->node_top = &window_sizes;
6332 ti->sort_priority = value;
6334 sprintf(identifier, "%d", value);
6335 sprintf(name, "%d %% (Current)", value);
6337 setString(&ti->identifier, identifier);
6338 setString(&ti->name, name);
6339 setString(&ti->name_sorting, name);
6340 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6342 pushTreeInfo(&window_sizes, ti);
6345 // sort window size values to start with lowest window size value
6346 sortTreeInfo(&window_sizes);
6348 // set current window size value to configured window size value
6349 window_size_current =
6350 getTreeInfoFromIdentifier(window_sizes,
6351 i_to_a(setup.window_scaling_percent));
6353 // if that fails, set current window size to reliable default value
6354 if (window_size_current == NULL)
6355 window_size_current =
6356 getTreeInfoFromIdentifier(window_sizes,
6357 i_to_a(STD_WINDOW_SCALING_PERCENT));
6359 // if that also fails, set current window size to first available value
6360 if (window_size_current == NULL)
6361 window_size_current = window_sizes;
6364 setup.window_scaling_percent = atoi(window_size_current->identifier);
6366 // needed for displaying window size text instead of identifier
6367 window_size_text = window_size_current->name;
6370 static void execSetupGraphics_setScalingTypes(void)
6372 if (scaling_types == NULL)
6376 for (i = 0; scaling_types_list[i].value != NULL; i++)
6378 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6379 char identifier[32], name[32];
6380 char *value = scaling_types_list[i].value;
6381 char *text = scaling_types_list[i].text;
6383 ti->node_top = &scaling_types;
6384 ti->sort_priority = i;
6386 sprintf(identifier, "%s", value);
6387 sprintf(name, "%s", text);
6389 setString(&ti->identifier, identifier);
6390 setString(&ti->name, name);
6391 setString(&ti->name_sorting, name);
6392 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6394 pushTreeInfo(&scaling_types, ti);
6397 // sort scaling type values to start with lowest scaling type value
6398 sortTreeInfo(&scaling_types);
6400 // set current scaling type value to configured scaling type value
6401 scaling_type_current =
6402 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6404 // if that fails, set current scaling type to reliable default value
6405 if (scaling_type_current == NULL)
6406 scaling_type_current =
6407 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6409 // if that also fails, set current scaling type to first available value
6410 if (scaling_type_current == NULL)
6411 scaling_type_current = scaling_types;
6414 setup.window_scaling_quality = scaling_type_current->identifier;
6416 // needed for displaying scaling type text instead of identifier
6417 scaling_type_text = scaling_type_current->name;
6420 static void execSetupGraphics_setRenderingModes(void)
6422 if (rendering_modes == NULL)
6426 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6428 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6429 char identifier[32], name[32];
6430 char *value = rendering_modes_list[i].value;
6431 char *text = rendering_modes_list[i].text;
6433 ti->node_top = &rendering_modes;
6434 ti->sort_priority = i;
6436 sprintf(identifier, "%s", value);
6437 sprintf(name, "%s", text);
6439 setString(&ti->identifier, identifier);
6440 setString(&ti->name, name);
6441 setString(&ti->name_sorting, name);
6442 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6444 pushTreeInfo(&rendering_modes, ti);
6447 // sort rendering mode values to start with lowest rendering mode value
6448 sortTreeInfo(&rendering_modes);
6450 // set current rendering mode value to configured rendering mode value
6451 rendering_mode_current =
6452 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6454 // if that fails, set current rendering mode to reliable default value
6455 if (rendering_mode_current == NULL)
6456 rendering_mode_current =
6457 getTreeInfoFromIdentifier(rendering_modes,
6458 STR_SPECIAL_RENDERING_DEFAULT);
6460 // if that also fails, set current rendering mode to first available one
6461 if (rendering_mode_current == NULL)
6462 rendering_mode_current = rendering_modes;
6465 setup.screen_rendering_mode = rendering_mode_current->identifier;
6467 // needed for displaying rendering mode text instead of identifier
6468 rendering_mode_text = rendering_mode_current->name;
6471 static void execSetupGraphics_setVsyncModes(boolean update_value)
6473 if (vsync_modes == NULL)
6477 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6479 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6480 char identifier[32], name[32];
6481 char *value = vsync_modes_list[i].value;
6482 char *text = vsync_modes_list[i].text;
6484 ti->node_top = &vsync_modes;
6485 ti->sort_priority = i;
6487 sprintf(identifier, "%s", value);
6488 sprintf(name, "%s", text);
6490 setString(&ti->identifier, identifier);
6491 setString(&ti->name, name);
6492 setString(&ti->name_sorting, name);
6493 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6495 pushTreeInfo(&vsync_modes, ti);
6498 // sort vsync mode values to start with lowest vsync mode value
6499 sortTreeInfo(&vsync_modes);
6501 update_value = TRUE;
6506 // set current vsync mode value to configured vsync mode value
6507 vsync_mode_current =
6508 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6510 // if that fails, set current vsync mode to reliable default value
6511 if (vsync_mode_current == NULL)
6512 vsync_mode_current =
6513 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6515 // if that also fails, set current vsync mode to first available one
6516 if (vsync_mode_current == NULL)
6517 vsync_mode_current = vsync_modes;
6520 setup.vsync_mode = vsync_mode_current->identifier;
6522 // needed for displaying vsync mode text instead of identifier
6523 vsync_mode_text = vsync_mode_current->name;
6526 static void execSetupGraphics(void)
6528 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6530 // update "setup.window_scaling_percent" from list selection
6531 // (in this case, window scaling was changed on setup screen)
6532 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6533 execSetupGraphics_setWindowSizes(FALSE);
6535 // update "setup.vsync_mode" from list selection
6536 // (in this case, vsync mode was changed on setup screen)
6537 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6538 execSetupGraphics_setVsyncModes(FALSE);
6540 // update list selection from "setup.window_scaling_percent"
6541 // (window scaling may have changed by resizing the window)
6542 execSetupGraphics_setWindowSizes(TRUE);
6544 // update list selection from "setup.vsync_mode"
6545 // (vsync_mode may have changed by re-creating the renderer)
6546 execSetupGraphics_setVsyncModes(TRUE);
6548 execSetupGraphics_setScalingTypes();
6549 execSetupGraphics_setRenderingModes();
6551 setup_mode = SETUP_MODE_GRAPHICS;
6555 // check if game speed is high enough for 60 Hz vsync to work
6556 if (check_game_speed)
6557 ModifyGameSpeedIfNeeded();
6559 // window scaling may have changed at this point
6560 ChangeWindowScalingIfNeeded();
6562 // window scaling quality may have changed at this point
6563 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6564 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6566 // screen rendering mode may have changed at this point
6567 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6569 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6570 int video_vsync_mode = video.vsync_mode;
6572 // screen vsync mode may have changed at this point
6573 ChangeVsyncModeIfNeeded();
6575 // check if setting vsync mode to selected value failed
6576 if (setup_vsync_mode != video_vsync_mode &&
6577 setup_vsync_mode != video.vsync_mode)
6579 // changing vsync mode to selected value failed -- reset displayed value
6580 execSetupGraphics_setVsyncModes(TRUE);
6582 Request("Setting VSync failed!", REQ_CONFIRM);
6588 static void execSetupChooseWindowSize(void)
6590 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6595 static void execSetupChooseScalingType(void)
6597 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6602 static void execSetupChooseRenderingMode(void)
6604 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6609 static void execSetupChooseVsyncMode(void)
6611 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6616 static void execSetupChooseVolumeSimple(void)
6618 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6623 static void execSetupChooseVolumeLoops(void)
6625 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6630 static void execSetupChooseVolumeMusic(void)
6632 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6637 static void execSetupSound(void)
6639 if (volumes_simple == NULL)
6641 boolean current_volume_simple_found = FALSE;
6644 for (i = 0; volumes_list[i].value != -1; i++)
6646 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6647 char identifier[32], name[32];
6648 int value = volumes_list[i].value;
6649 char *text = volumes_list[i].text;
6651 ti->node_top = &volumes_simple;
6652 ti->sort_priority = value;
6654 sprintf(identifier, "%d", value);
6655 sprintf(name, "%s", text);
6657 setString(&ti->identifier, identifier);
6658 setString(&ti->name, name);
6659 setString(&ti->name_sorting, name);
6660 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6662 pushTreeInfo(&volumes_simple, ti);
6664 if (value == setup.volume_simple)
6665 current_volume_simple_found = TRUE;
6668 if (!current_volume_simple_found)
6670 // add entry for non-preset volume value
6672 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6673 char identifier[32], name[32];
6674 int value = setup.volume_simple;
6676 ti->node_top = &volumes_simple;
6677 ti->sort_priority = value;
6679 sprintf(identifier, "%d", value);
6680 sprintf(name, "%d %% (Current)", value);
6682 setString(&ti->identifier, identifier);
6683 setString(&ti->name, name);
6684 setString(&ti->name_sorting, name);
6685 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6687 pushTreeInfo(&volumes_simple, ti);
6690 // sort volume values to start with lowest volume value
6691 sortTreeInfo(&volumes_simple);
6693 // set current volume value to configured volume value
6694 volume_simple_current =
6695 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6697 // if that fails, set current volume to reliable default value
6698 if (volume_simple_current == NULL)
6699 volume_simple_current =
6700 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6702 // if that also fails, set current volume to first available value
6703 if (volume_simple_current == NULL)
6704 volume_simple_current = volumes_simple;
6707 if (volumes_loops == NULL)
6709 boolean current_volume_loops_found = FALSE;
6712 for (i = 0; volumes_list[i].value != -1; i++)
6714 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6715 char identifier[32], name[32];
6716 int value = volumes_list[i].value;
6717 char *text = volumes_list[i].text;
6719 ti->node_top = &volumes_loops;
6720 ti->sort_priority = value;
6722 sprintf(identifier, "%d", value);
6723 sprintf(name, "%s", text);
6725 setString(&ti->identifier, identifier);
6726 setString(&ti->name, name);
6727 setString(&ti->name_sorting, name);
6728 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6730 pushTreeInfo(&volumes_loops, ti);
6732 if (value == setup.volume_loops)
6733 current_volume_loops_found = TRUE;
6736 if (!current_volume_loops_found)
6738 // add entry for non-preset volume value
6740 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6741 char identifier[32], name[32];
6742 int value = setup.volume_loops;
6744 ti->node_top = &volumes_loops;
6745 ti->sort_priority = value;
6747 sprintf(identifier, "%d", value);
6748 sprintf(name, "%d %% (Current)", value);
6750 setString(&ti->identifier, identifier);
6751 setString(&ti->name, name);
6752 setString(&ti->name_sorting, name);
6753 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6755 pushTreeInfo(&volumes_loops, ti);
6758 // sort volume values to start with lowest volume value
6759 sortTreeInfo(&volumes_loops);
6761 // set current volume value to configured volume value
6762 volume_loops_current =
6763 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6765 // if that fails, set current volume to reliable default value
6766 if (volume_loops_current == NULL)
6767 volume_loops_current =
6768 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6770 // if that also fails, set current volume to first available value
6771 if (volume_loops_current == NULL)
6772 volume_loops_current = volumes_loops;
6775 if (volumes_music == NULL)
6777 boolean current_volume_music_found = FALSE;
6780 for (i = 0; volumes_list[i].value != -1; i++)
6782 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6783 char identifier[32], name[32];
6784 int value = volumes_list[i].value;
6785 char *text = volumes_list[i].text;
6787 ti->node_top = &volumes_music;
6788 ti->sort_priority = value;
6790 sprintf(identifier, "%d", value);
6791 sprintf(name, "%s", text);
6793 setString(&ti->identifier, identifier);
6794 setString(&ti->name, name);
6795 setString(&ti->name_sorting, name);
6796 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6798 pushTreeInfo(&volumes_music, ti);
6800 if (value == setup.volume_music)
6801 current_volume_music_found = TRUE;
6804 if (!current_volume_music_found)
6806 // add entry for non-preset volume value
6808 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6809 char identifier[32], name[32];
6810 int value = setup.volume_music;
6812 ti->node_top = &volumes_music;
6813 ti->sort_priority = value;
6815 sprintf(identifier, "%d", value);
6816 sprintf(name, "%d %% (Current)", value);
6818 setString(&ti->identifier, identifier);
6819 setString(&ti->name, name);
6820 setString(&ti->name_sorting, name);
6821 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6823 pushTreeInfo(&volumes_music, ti);
6826 // sort volume values to start with lowest volume value
6827 sortTreeInfo(&volumes_music);
6829 // set current volume value to configured volume value
6830 volume_music_current =
6831 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6833 // if that fails, set current volume to reliable default value
6834 if (volume_music_current == NULL)
6835 volume_music_current =
6836 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6838 // if that also fails, set current volume to first available value
6839 if (volume_music_current == NULL)
6840 volume_music_current = volumes_music;
6843 setup.volume_simple = atoi(volume_simple_current->identifier);
6844 setup.volume_loops = atoi(volume_loops_current->identifier);
6845 setup.volume_music = atoi(volume_music_current->identifier);
6847 // needed for displaying volume text instead of identifier
6848 volume_simple_text = volume_simple_current->name;
6849 volume_loops_text = volume_loops_current->name;
6850 volume_music_text = volume_music_current->name;
6852 setup_mode = SETUP_MODE_SOUND;
6857 static void execSetupChooseTouchControls(void)
6859 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6864 static void execSetupChooseMoveDistance(void)
6866 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6871 static void execSetupChooseDropDistance(void)
6873 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6878 static void execSetupChooseTransparency(void)
6880 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6885 static void execSetupChooseGridXSize_0(void)
6887 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6892 static void execSetupChooseGridYSize_0(void)
6894 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6899 static void execSetupChooseGridXSize_1(void)
6901 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6906 static void execSetupChooseGridYSize_1(void)
6908 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6913 static void execSetupConfigureVirtualButtons(void)
6915 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6917 ConfigureVirtualButtons();
6919 setup_mode = SETUP_MODE_TOUCH;
6924 static void execSetupTouch(void)
6928 if (touch_controls == NULL)
6930 for (i = 0; touch_controls_list[i].value != NULL; i++)
6932 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6933 char identifier[32], name[32];
6934 char *value = touch_controls_list[i].value;
6935 char *text = touch_controls_list[i].text;
6937 ti->node_top = &touch_controls;
6938 ti->sort_priority = i;
6940 sprintf(identifier, "%s", value);
6941 sprintf(name, "%s", text);
6943 setString(&ti->identifier, identifier);
6944 setString(&ti->name, name);
6945 setString(&ti->name_sorting, name);
6946 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6948 pushTreeInfo(&touch_controls, ti);
6951 // sort touch control values to start with lowest touch control value
6952 sortTreeInfo(&touch_controls);
6954 // set current touch control value to configured touch control value
6955 touch_control_current =
6956 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6958 // if that fails, set current touch control to reliable default value
6959 if (touch_control_current == NULL)
6960 touch_control_current =
6961 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6963 // if that also fails, set current touch control to first available value
6964 if (touch_control_current == NULL)
6965 touch_control_current = touch_controls;
6968 if (move_distances == NULL)
6970 for (i = 0; distances_list[i].value != -1; i++)
6972 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6973 char identifier[32], name[32];
6974 int value = distances_list[i].value;
6975 char *text = distances_list[i].text;
6977 ti->node_top = &move_distances;
6978 ti->sort_priority = value;
6980 sprintf(identifier, "%d", value);
6981 sprintf(name, "%s", text);
6983 setString(&ti->identifier, identifier);
6984 setString(&ti->name, name);
6985 setString(&ti->name_sorting, name);
6986 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6988 pushTreeInfo(&move_distances, ti);
6991 // sort distance values to start with lowest distance value
6992 sortTreeInfo(&move_distances);
6994 // set current distance value to configured distance value
6995 move_distance_current =
6996 getTreeInfoFromIdentifier(move_distances,
6997 i_to_a(setup.touch.move_distance));
6999 // if that fails, set current distance to reliable default value
7000 if (move_distance_current == NULL)
7001 move_distance_current =
7002 getTreeInfoFromIdentifier(move_distances,
7003 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
7005 // if that also fails, set current distance to first available value
7006 if (move_distance_current == NULL)
7007 move_distance_current = move_distances;
7010 if (drop_distances == NULL)
7012 for (i = 0; distances_list[i].value != -1; i++)
7014 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7015 char identifier[32], name[32];
7016 int value = distances_list[i].value;
7017 char *text = distances_list[i].text;
7019 ti->node_top = &drop_distances;
7020 ti->sort_priority = value;
7022 sprintf(identifier, "%d", value);
7023 sprintf(name, "%s", text);
7025 setString(&ti->identifier, identifier);
7026 setString(&ti->name, name);
7027 setString(&ti->name_sorting, name);
7028 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
7030 pushTreeInfo(&drop_distances, ti);
7033 // sort distance values to start with lowest distance value
7034 sortTreeInfo(&drop_distances);
7036 // set current distance value to configured distance value
7037 drop_distance_current =
7038 getTreeInfoFromIdentifier(drop_distances,
7039 i_to_a(setup.touch.drop_distance));
7041 // if that fails, set current distance to reliable default value
7042 if (drop_distance_current == NULL)
7043 drop_distance_current =
7044 getTreeInfoFromIdentifier(drop_distances,
7045 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
7047 // if that also fails, set current distance to first available value
7048 if (drop_distance_current == NULL)
7049 drop_distance_current = drop_distances;
7052 if (transparencies == NULL)
7054 for (i = 0; transparencies_list[i].value != -1; i++)
7056 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7057 char identifier[32], name[32];
7058 int value = transparencies_list[i].value;
7059 char *text = transparencies_list[i].text;
7061 ti->node_top = &transparencies;
7062 ti->sort_priority = value;
7064 sprintf(identifier, "%d", value);
7065 sprintf(name, "%s", text);
7067 setString(&ti->identifier, identifier);
7068 setString(&ti->name, name);
7069 setString(&ti->name_sorting, name);
7070 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
7072 pushTreeInfo(&transparencies, ti);
7075 // sort transparency values to start with lowest transparency value
7076 sortTreeInfo(&transparencies);
7078 // set current transparency value to configured transparency value
7079 transparency_current =
7080 getTreeInfoFromIdentifier(transparencies,
7081 i_to_a(setup.touch.transparency));
7083 // if that fails, set current transparency to reliable default value
7084 if (transparency_current == NULL)
7085 transparency_current =
7086 getTreeInfoFromIdentifier(transparencies,
7087 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7089 // if that also fails, set current transparency to first available value
7090 if (transparency_current == NULL)
7091 transparency_current = transparencies;
7094 for (i = 0; i < 2; i++)
7096 for (j = 0; j < 2; j++)
7098 if (grid_sizes[i][j] == NULL)
7100 for (k = 0; grid_sizes_list[k].value != -1; k++)
7102 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7103 char identifier[32], name[32];
7104 int value = grid_sizes_list[k].value;
7105 char *text = grid_sizes_list[k].text;
7107 ti->node_top = &grid_sizes[i][j];
7108 ti->sort_priority = value;
7110 sprintf(identifier, "%d", value);
7111 sprintf(name, "%s", text);
7113 setString(&ti->identifier, identifier);
7114 setString(&ti->name, name);
7115 setString(&ti->name_sorting, name);
7116 setString(&ti->infotext,
7119 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7120 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7122 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7123 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7125 pushTreeInfo(&grid_sizes[i][j], ti);
7128 // sort grid size values to start with lowest grid size value
7129 sortTreeInfo(&grid_sizes[i][j]);
7131 // set current grid size value to configured grid size value
7132 grid_size_current[i][j] =
7133 getTreeInfoFromIdentifier(grid_sizes[i][j],
7135 setup.touch.grid_xsize[i] :
7136 setup.touch.grid_ysize[i]));
7138 // if that fails, set current grid size to reliable default value
7139 if (grid_size_current[i][j] == NULL)
7140 grid_size_current[i][j] =
7141 getTreeInfoFromIdentifier(grid_sizes[i][j],
7143 DEFAULT_GRID_XSIZE(i) :
7144 DEFAULT_GRID_YSIZE(i)));
7146 // if that also fails, set current grid size to first available value
7147 if (grid_size_current[i][j] == NULL)
7148 grid_size_current[i][j] = grid_sizes[i][j];
7153 setup.touch.control_type = touch_control_current->identifier;
7154 setup.touch.move_distance = atoi(move_distance_current->identifier);
7155 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7156 setup.touch.transparency = atoi(transparency_current->identifier);
7158 for (i = 0; i < 2; i++)
7160 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7161 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7163 if (i == GRID_ACTIVE_NR())
7165 overlay.grid_xsize = setup.touch.grid_xsize[i];
7166 overlay.grid_ysize = setup.touch.grid_ysize[i];
7170 // needed for displaying value text instead of identifier
7171 touch_controls_text = touch_control_current->name;
7172 move_distance_text = move_distance_current->name;
7173 drop_distance_text = drop_distance_current->name;
7174 transparency_text = transparency_current->name;
7176 for (i = 0; i < 2; i++)
7177 for (j = 0; j < 2; j++)
7178 grid_size_text[i][j] = grid_size_current[i][j]->name;
7180 setup_mode = SETUP_MODE_TOUCH;
7185 static void execSetupArtwork(void)
7187 static ArtworkDirTree *gfx_last_valid = NULL;
7188 static ArtworkDirTree *snd_last_valid = NULL;
7189 static ArtworkDirTree *mus_last_valid = NULL;
7191 // current artwork directory may be invalid (level group, parent link)
7192 if (!validLevelSeries(artwork.gfx_current))
7193 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7194 if (!validLevelSeries(artwork.snd_current))
7195 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7196 if (!validLevelSeries(artwork.mus_current))
7197 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7199 // store valid artwork directory information
7200 gfx_last_valid = artwork.gfx_current;
7201 snd_last_valid = artwork.snd_current;
7202 mus_last_valid = artwork.mus_current;
7205 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7206 artwork.gfx_current->subdir,
7207 artwork.gfx_current->fullpath,
7208 artwork.gfx_current->basepath);
7211 setup.graphics_set = artwork.gfx_current->identifier;
7212 setup.sounds_set = artwork.snd_current->identifier;
7213 setup.music_set = artwork.mus_current->identifier;
7215 // needed if last screen (setup choice) changed graphics, sounds or music
7216 ReloadCustomArtwork(0);
7218 // needed for displaying artwork name instead of artwork identifier
7219 graphics_set_name = artwork.gfx_current->name;
7220 sounds_set_name = artwork.snd_current->name;
7221 music_set_name = artwork.mus_current->name;
7223 setup_mode = SETUP_MODE_ARTWORK;
7228 static void execSetupChooseGraphics(void)
7230 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7235 static void execSetupChooseSounds(void)
7237 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7242 static void execSetupChooseMusic(void)
7244 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7249 static void execSetupInput(void)
7251 setup_mode = SETUP_MODE_INPUT;
7256 static void execSetupShortcuts(void)
7258 setup_mode = SETUP_MODE_SHORTCUTS;
7263 static void execSetupShortcuts1(void)
7265 setup_mode = SETUP_MODE_SHORTCUTS_1;
7270 static void execSetupShortcuts2(void)
7272 setup_mode = SETUP_MODE_SHORTCUTS_2;
7277 static void execSetupShortcuts3(void)
7279 setup_mode = SETUP_MODE_SHORTCUTS_3;
7284 static void execSetupShortcuts4(void)
7286 setup_mode = SETUP_MODE_SHORTCUTS_4;
7291 static void execSetupShortcuts5(void)
7293 setup_mode = SETUP_MODE_SHORTCUTS_5;
7298 static void execExitSetup(void)
7300 SetGameStatus(GAME_MODE_MAIN);
7305 static void execSaveAndExitSetup(void)
7311 static void execGadgetNetworkServer(void)
7313 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7314 struct GadgetInfo *gi = screen_gadget[gadget_id];
7316 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7317 network_server_hostname[0] = '\0';
7319 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7323 ClickOnGadget(gi, MB_LEFTBUTTON);
7326 static void execOfferUploadTapes(void)
7331 static void ToggleNetworkModeIfNeeded(void)
7333 int font_title = FONT_TITLE_1;
7334 int font_foot = FC_BLUE;
7335 int ystart = mSY - SY + 16;
7336 int ybottom = mSY - SY + SYSIZE - 20;
7337 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7339 if (setup.network_mode == network.enabled)
7342 network.enabled = setup.network_mode;
7344 FadeOut(REDRAW_ALL);
7348 DrawTextSCentered(ystart, font_title, text);
7352 if (network.enabled)
7353 InitNetworkServer();
7355 DisconnectFromNetworkServer();
7357 DrawTextSCentered(ybottom, font_foot,
7358 "Press any key or button for setup menu");
7360 WaitForEventToContinue();
7365 static void ToggleGameSpeedsListIfNeeded(void)
7367 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7369 if (setup.game_speed_extended == using_game_speeds_extended)
7372 // try to match similar values when changing game speeds list
7373 if (setup.game_speed_extended)
7374 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7375 setup.game_frame_delay == 30 ? 29 :
7376 setup.game_frame_delay);
7378 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7379 setup.game_frame_delay == 16 ? 15 :
7380 setup.game_frame_delay >= 29 ? 30 :
7381 setup.game_frame_delay <= 10 ? 10 :
7382 setup.game_frame_delay);
7384 execSetupGame_setGameSpeeds(TRUE);
7389 static void ToggleUseApiServerIfNeeded(void)
7391 if (runtime.use_api_server == setup.use_api_server)
7394 runtime.use_api_server = setup.use_api_server;
7396 if (runtime.use_api_server)
7397 CheckApiServerTasks();
7400 static void ModifyGameSpeedIfNeeded(void)
7402 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7403 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7407 char *game_speed_text = "Fast";
7408 int game_speed_value = 15;
7410 if (setup.game_speed_extended)
7412 game_speed_text = "60 fps";
7413 game_speed_value = 16;
7416 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7418 // set game speed to existing list value that is fast enough for vsync
7419 setup.game_frame_delay = game_speed_value;
7421 execSetupGame_setGameSpeeds(TRUE);
7423 Request(message, REQ_CONFIRM);
7426 static void DisableVsyncIfNeeded(void)
7428 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7429 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7430 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7433 // disable vsync for the selected game speed to work
7434 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7436 execSetupGraphics_setVsyncModes(TRUE);
7438 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7444 void *related_value;
7445 } hide_related_entry_list[] =
7447 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7448 { &setup.scores_in_highscore_list, &scores_type_text },
7450 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7451 { &setup.game_frame_delay, &game_speed_text },
7453 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7454 { &setup.scroll_delay_value, &scroll_delay_text },
7456 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7457 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7459 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7460 { &setup.window_scaling_percent, &window_size_text },
7462 { &setup.window_scaling_quality, execSetupChooseScalingType },
7463 { &setup.window_scaling_quality, &scaling_type_text },
7465 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7466 { &setup.screen_rendering_mode, &rendering_mode_text },
7468 { &setup.vsync_mode, execSetupChooseVsyncMode },
7469 { &setup.vsync_mode, &vsync_mode_text },
7471 { &setup.graphics_set, execSetupChooseGraphics },
7472 { &setup.graphics_set, &graphics_set_name },
7474 { &setup.sounds_set, execSetupChooseSounds },
7475 { &setup.sounds_set, &sounds_set_name },
7477 { &setup.music_set, execSetupChooseMusic },
7478 { &setup.music_set, &music_set_name },
7480 { &setup.volume_simple, execSetupChooseVolumeSimple },
7481 { &setup.volume_simple, &volume_simple_text },
7483 { &setup.volume_loops, execSetupChooseVolumeLoops },
7484 { &setup.volume_loops, &volume_loops_text },
7486 { &setup.volume_music, execSetupChooseVolumeMusic },
7487 { &setup.volume_music, &volume_music_text },
7489 { &setup.touch.control_type, execSetupChooseTouchControls },
7490 { &setup.touch.control_type, &touch_controls_text },
7492 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7493 { &setup.touch.move_distance, &move_distance_text },
7495 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7496 { &setup.touch.drop_distance, &drop_distance_text },
7498 { &setup.touch.transparency, execSetupChooseTransparency },
7499 { &setup.touch.transparency, &transparency_text },
7501 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7502 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7504 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7505 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7507 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7508 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7510 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7511 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7513 { &setup.internal.menu_game, execSetupGame },
7514 { &setup.internal.menu_engines, execSetupEngines },
7515 { &setup.internal.menu_editor, execSetupEditor },
7516 { &setup.internal.menu_graphics, execSetupGraphics },
7517 { &setup.internal.menu_sound, execSetupSound },
7518 { &setup.internal.menu_artwork, execSetupArtwork },
7519 { &setup.internal.menu_input, execSetupInput },
7520 { &setup.internal.menu_touch, execSetupTouch },
7521 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7522 { &setup.internal.menu_exit, execExitSetup },
7523 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7528 void setHideRelatedSetupEntries(void)
7532 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7533 if (hideSetupEntry(hide_related_entry_list[i].value))
7534 setHideSetupEntry(hide_related_entry_list[i].related_value);
7537 static struct TokenInfo setup_info_main[] =
7539 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7540 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7541 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7542 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7543 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7544 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7545 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7546 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7547 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7548 { TYPE_EMPTY, NULL, "" },
7549 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7550 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7555 static struct TokenInfo setup_info_game[] =
7557 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7558 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7559 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7560 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7561 { TYPE_STRING, &network_server_text, "" },
7562 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7563 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7564 { TYPE_STRING, &scores_type_text, "" },
7565 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7566 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7567 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7568 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7569 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7570 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7571 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7572 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7573 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7574 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7575 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7576 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7577 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7578 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7579 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7580 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7581 { TYPE_STRING, &game_speed_text, "" },
7582 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7584 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7585 { TYPE_STRING, &scroll_delay_text, "" },
7587 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7588 { TYPE_STRING, &snapshot_mode_text, "" },
7589 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7590 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7591 { TYPE_EMPTY, NULL, "" },
7592 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7597 static struct TokenInfo setup_info_engines[] =
7599 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7600 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7601 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7602 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7603 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7604 { TYPE_EMPTY, NULL, "" },
7605 { TYPE_HEADLINE, NULL, "Supaplex" },
7606 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7607 { TYPE_EMPTY, NULL, "" },
7608 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7613 static struct TokenInfo setup_info_editor[] =
7616 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7617 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7618 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7619 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7620 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7621 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7622 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7623 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7624 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7625 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7627 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7628 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7630 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7632 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7633 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7634 { TYPE_EMPTY, NULL, "" },
7636 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7637 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7638 { TYPE_EMPTY, NULL, "" },
7640 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7641 { TYPE_EMPTY, NULL, "" },
7642 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7643 { TYPE_EMPTY, NULL, "" },
7644 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7649 static struct TokenInfo setup_info_graphics[] =
7651 #if !defined(PLATFORM_ANDROID)
7652 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7653 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7654 { TYPE_STRING, &window_size_text, "" },
7655 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7656 { TYPE_STRING, &scaling_type_text, "" },
7657 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7658 { TYPE_STRING, &rendering_mode_text, "" },
7661 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7662 { TYPE_STRING, &scroll_delay_text, "" },
7664 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7665 { TYPE_STRING, &vsync_mode_text, "" },
7666 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7667 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7668 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7669 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7670 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7671 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7672 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7673 { TYPE_EMPTY, NULL, "" },
7674 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7679 static struct TokenInfo setup_info_sound[] =
7681 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7682 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7683 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7684 { TYPE_EMPTY, NULL, "" },
7685 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7686 { TYPE_STRING, &volume_simple_text, "" },
7687 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7688 { TYPE_STRING, &volume_loops_text, "" },
7689 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7690 { TYPE_STRING, &volume_music_text, "" },
7691 { TYPE_EMPTY, NULL, "" },
7692 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7697 static struct TokenInfo setup_info_artwork[] =
7699 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7700 { TYPE_STRING, &graphics_set_name, "" },
7701 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7702 { TYPE_STRING, &sounds_set_name, "" },
7703 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7704 { TYPE_STRING, &music_set_name, "" },
7705 { TYPE_EMPTY, NULL, "" },
7706 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7707 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7708 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7709 { TYPE_EMPTY, NULL, "" },
7710 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7715 static struct TokenInfo setup_info_input[] =
7717 { TYPE_SWITCH, NULL, "Player:" },
7718 { TYPE_SWITCH, NULL, "Device:" },
7719 { TYPE_SWITCH, NULL, "" },
7720 { TYPE_SKIPPABLE, NULL, "" },
7721 { TYPE_EMPTY, NULL, "" },
7722 { TYPE_EMPTY, NULL, "" },
7723 { TYPE_EMPTY, NULL, "" },
7724 { TYPE_EMPTY, NULL, "" },
7725 { TYPE_EMPTY, NULL, "" },
7726 { TYPE_EMPTY, NULL, "" },
7727 { TYPE_EMPTY, NULL, "" },
7728 { TYPE_EMPTY, NULL, "" },
7729 { TYPE_SKIPPABLE, NULL, "" },
7730 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7735 static struct TokenInfo setup_info_touch[] =
7737 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7738 { TYPE_STRING, &touch_controls_text, "" },
7739 { TYPE_EMPTY, NULL, "" },
7740 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7745 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7747 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7748 { TYPE_STRING, &touch_controls_text, "" },
7749 { TYPE_EMPTY, NULL, "" },
7750 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7751 { TYPE_STRING, &grid_size_text[0][0], "" },
7752 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7753 { TYPE_STRING, &grid_size_text[0][1], "" },
7754 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7755 { TYPE_STRING, &transparency_text, "" },
7756 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7757 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7758 { TYPE_EMPTY, NULL, "" },
7759 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7760 { TYPE_EMPTY, NULL, "" },
7761 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7766 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7768 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7769 { TYPE_STRING, &touch_controls_text, "" },
7770 { TYPE_EMPTY, NULL, "" },
7771 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7772 { TYPE_STRING, &grid_size_text[1][0], "" },
7773 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7774 { TYPE_STRING, &grid_size_text[1][1], "" },
7775 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7776 { TYPE_STRING, &transparency_text, "" },
7777 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7778 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7779 { TYPE_EMPTY, NULL, "" },
7780 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7781 { TYPE_EMPTY, NULL, "" },
7782 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7787 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7789 setup_info_touch_virtual_buttons_0,
7790 setup_info_touch_virtual_buttons_1
7793 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7795 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7796 { TYPE_STRING, &touch_controls_text, "" },
7797 { TYPE_EMPTY, NULL, "" },
7798 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7799 { TYPE_STRING, &move_distance_text, "" },
7800 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7801 { TYPE_STRING, &drop_distance_text, "" },
7802 { TYPE_EMPTY, NULL, "" },
7803 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7808 static struct TokenInfo setup_info_shortcuts[] =
7810 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7811 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7812 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7813 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7814 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7815 { TYPE_EMPTY, NULL, "" },
7816 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7821 static struct TokenInfo setup_info_shortcuts_1[] =
7823 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7824 { TYPE_KEY, &setup.shortcut.save_game, "" },
7825 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7826 { TYPE_KEY, &setup.shortcut.load_game, "" },
7827 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7828 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7829 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7830 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7831 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7832 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7833 { TYPE_EMPTY, NULL, "" },
7834 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7835 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7836 { TYPE_EMPTY, NULL, "" },
7837 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7842 static struct TokenInfo setup_info_shortcuts_2[] =
7844 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7845 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7846 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7847 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7848 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7849 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7850 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7851 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7852 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7853 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7854 { TYPE_EMPTY, NULL, "" },
7855 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7860 static struct TokenInfo setup_info_shortcuts_3[] =
7862 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7863 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7864 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7865 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7866 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7867 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7868 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7869 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7870 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7871 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7872 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7873 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7874 { TYPE_EMPTY, NULL, "" },
7875 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7880 static struct TokenInfo setup_info_shortcuts_4[] =
7882 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7883 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7884 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7885 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7886 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7887 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7888 { TYPE_EMPTY, NULL, "" },
7889 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7894 static struct TokenInfo setup_info_shortcuts_5[] =
7896 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7897 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7898 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7899 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7900 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7901 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7902 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7903 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7904 { TYPE_EMPTY, NULL, "" },
7905 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7910 static Key getSetupKey(void)
7912 Key key = KSYM_UNDEFINED;
7913 boolean got_key_event = FALSE;
7915 while (!got_key_event)
7919 if (NextValidEvent(&event))
7923 case EVENT_KEYPRESS:
7925 key = GetEventKey((KeyEvent *)&event, TRUE);
7927 // press 'Escape' or 'Enter' to keep the existing key binding
7928 if (key == KSYM_Escape || key == KSYM_Return)
7929 key = KSYM_UNDEFINED; // keep old value
7931 got_key_event = TRUE;
7935 case EVENT_KEYRELEASE:
7936 key_joystick_mapping = 0;
7940 HandleOtherEvents(&event);
7951 static int getSetupValueFont(int type, void *value)
7953 if (type & TYPE_GHOSTED)
7954 return FONT_OPTION_OFF;
7955 else if (type & TYPE_KEY)
7956 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7957 else if (type & TYPE_STRING)
7958 return FONT_VALUE_2;
7959 else if (type & TYPE_ECS_AGA)
7960 return FONT_VALUE_1;
7961 else if (type & TYPE_BOOLEAN_STYLE)
7962 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7963 else if (type & TYPE_YES_NO_AUTO)
7964 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7965 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7966 else if (type & TYPE_PLAYER)
7967 return FONT_VALUE_1;
7969 return FONT_VALUE_1;
7972 static int getSetupValueFontNarrow(int type, int font_nr)
7974 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7975 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7976 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7980 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7982 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7983 struct TokenInfo *si = &setup_info[si_pos];
7984 boolean font_draw_xoffset_modified = FALSE;
7985 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7986 int font_draw_xoffset_old = -1;
7987 int xoffset = (scrollbar_needed ? -1 : 0);
7988 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7989 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7990 int xpos = menu_screen_value_xpos;
7991 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7992 int startx = mSX + xpos * 32;
7993 int starty = mSY + ypos * 32;
7994 int type = si->type;
7995 void *value = si->value;
7996 char *value_string = getSetupValue(type, value);
7997 int font_nr_default = getSetupValueFont(type, value);
7998 int font_width_default = getFontWidth(font_nr_default);
7999 int font_nr = font_nr_default;
8002 if (value_string == NULL)
8005 if (type & TYPE_KEY)
8007 xpos = MENU_SCREEN_START_XPOS;
8009 if (type & TYPE_QUERY)
8010 value_string = "<press key>";
8012 else if (type & TYPE_STRING)
8014 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
8016 xpos = MENU_SCREEN_START_XPOS;
8018 if (strlen(value_string) > max_value_len)
8019 value_string[max_value_len] = '\0';
8021 else if (type & TYPE_YES_NO_AUTO)
8023 xpos = menu_screen_value_xpos - 1;
8025 else if (type & TYPE_PLAYER)
8027 int displayed_player_nr = *(int *)value + 1;
8029 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
8032 startx = mSX + xpos * 32;
8033 starty = mSY + ypos * 32;
8035 // special check if right-side setup values moved left due to scrollbar
8036 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
8038 int max_menu_text_length = 26; // maximum text length for classic menu
8039 int font_xoffset = getFontDrawOffsetX(font_nr);
8040 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8041 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8042 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8043 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
8045 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
8047 // when using narrow font, left-shifting text "auto" not needed
8048 if (type & TYPE_YES_NO_AUTO)
8052 startx = mSX + xpos * 32;
8054 font_nr = getSetupValueFontNarrow(type, font_nr);
8058 // downward compatibility correction for Juergen Bonhagen's menu settings
8059 if (setup_mode != SETUP_MODE_INPUT)
8061 int max_menu_text_length_big = (menu_screen_value_xpos -
8062 MENU_SCREEN_START_XPOS);
8063 int max_menu_text_length_medium = max_menu_text_length_big * 2;
8064 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
8065 int font1_xoffset = getFontDrawOffsetX(font_nr);
8066 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
8067 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
8068 int text_font_nr = getMenuTextFont(FONT_MENU_2);
8069 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
8070 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8071 boolean correct_font_draw_xoffset = FALSE;
8073 if (xpos == MENU_SCREEN_START_XPOS &&
8074 startx + font1_xoffset < text_startx + text_font_xoffset)
8075 correct_font_draw_xoffset = TRUE;
8077 if (xpos == menu_screen_value_xpos &&
8078 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8079 correct_font_draw_xoffset = TRUE;
8081 // check if setup value would overlap with setup text when printed
8082 // (this can happen for extreme/wrong values for font draw offset)
8083 if (correct_font_draw_xoffset)
8085 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8086 font_draw_xoffset_modified = TRUE;
8088 if (type & TYPE_KEY)
8089 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8090 else if (!(type & TYPE_STRING))
8091 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8092 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8096 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
8097 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
8099 DrawText(startx, starty, value_string, font_nr);
8101 if (type & TYPE_PLAYER)
8103 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8104 int player_nr = *(int *)value;
8105 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8106 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8107 int startx2 = startx + xoff;
8108 int starty2 = starty + yoff;
8110 if (DrawingOnBackground(startx2, starty2))
8111 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8113 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8114 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8117 if (font_draw_xoffset_modified)
8118 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8121 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8123 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8124 struct TokenInfo *si = &setup_info[si_pos];
8126 if (si->type & TYPE_BOOLEAN_STYLE)
8128 *(boolean *)si->value ^= TRUE;
8130 else if (si->type & TYPE_YES_NO_AUTO)
8134 (*(int *)si->value == AUTO ? TRUE :
8135 *(int *)si->value == TRUE ? FALSE : AUTO) :
8136 (*(int *)si->value == TRUE ? AUTO :
8137 *(int *)si->value == AUTO ? FALSE : TRUE));
8139 else if (si->type & TYPE_KEY)
8143 si->type |= TYPE_QUERY;
8144 drawSetupValue(screen_pos, setup_info_pos_raw);
8145 si->type &= ~TYPE_QUERY;
8147 key = getSetupKey();
8148 if (key != KSYM_UNDEFINED)
8149 *(Key *)si->value = key;
8151 else if (si->type & TYPE_PLAYER)
8153 int player_nr = *(int *)si->value;
8158 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8160 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8163 drawSetupValue(screen_pos, setup_info_pos_raw);
8165 // fullscreen state may have changed at this point
8166 if (si->value == &setup.fullscreen)
8167 ToggleFullscreenIfNeeded();
8169 // network mode may have changed at this point
8170 if (si->value == &setup.network_mode)
8171 ToggleNetworkModeIfNeeded();
8173 // API server mode may have changed at this point
8174 if (si->value == &setup.use_api_server)
8175 ToggleUseApiServerIfNeeded();
8177 // game speed list may have changed at this point
8178 if (si->value == &setup.game_speed_extended)
8179 ToggleGameSpeedsListIfNeeded();
8182 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8184 static struct TokenInfo *setup_info_final = NULL;
8189 // determine maximum list size of target list
8190 while (setup_info_orig[list_size++].type != 0);
8192 // free, allocate and clear memory for target list
8193 checked_free(setup_info_final);
8194 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8196 // copy setup info list without setup entries marked as hidden
8197 for (i = 0; setup_info_orig[i].type != 0; i++)
8199 // skip setup entries configured to be hidden
8200 if (hideSetupEntry(setup_info_orig[i].value))
8203 // skip skippable setup entries if screen is lower than usual
8204 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8205 setup_info_orig[i].type == TYPE_SKIPPABLE)
8208 setup_info_final[list_pos++] = setup_info_orig[i];
8211 return setup_info_final;
8214 static void DrawSetupScreen_Generic(void)
8216 int fade_mask = REDRAW_FIELD;
8217 boolean redraw_all = FALSE;
8218 char *title_string = NULL;
8222 fade_mask = REDRAW_ALL;
8225 FadeMenuSoundsAndMusic();
8227 FreeScreenGadgets();
8228 CreateScreenGadgets();
8230 if (redraw_mask & REDRAW_ALL)
8235 // needed if different viewport properties defined for setup screen
8236 ChangeViewportPropertiesIfNeeded();
8238 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8242 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8244 if (setup_mode == SETUP_MODE_MAIN)
8246 setup_info = setup_info_main;
8247 title_string = STR_SETUP_MAIN;
8249 else if (setup_mode == SETUP_MODE_GAME)
8251 setup_info = setup_info_game;
8252 title_string = STR_SETUP_GAME;
8254 else if (setup_mode == SETUP_MODE_ENGINES)
8256 setup_info = setup_info_engines;
8257 title_string = STR_SETUP_ENGINES;
8259 else if (setup_mode == SETUP_MODE_EDITOR)
8261 setup_info = setup_info_editor;
8262 title_string = STR_SETUP_EDITOR;
8264 else if (setup_mode == SETUP_MODE_GRAPHICS)
8266 setup_info = setup_info_graphics;
8267 title_string = STR_SETUP_GRAPHICS;
8269 else if (setup_mode == SETUP_MODE_SOUND)
8271 setup_info = setup_info_sound;
8272 title_string = STR_SETUP_SOUND;
8274 else if (setup_mode == SETUP_MODE_ARTWORK)
8276 setup_info = setup_info_artwork;
8277 title_string = STR_SETUP_ARTWORK;
8279 else if (setup_mode == SETUP_MODE_TOUCH)
8281 setup_info = setup_info_touch;
8282 title_string = STR_SETUP_TOUCH;
8284 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8285 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8286 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8287 setup_info = setup_info_touch_wipe_gestures;
8289 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8291 setup_info = setup_info_shortcuts;
8292 title_string = STR_SETUP_SHORTCUTS;
8294 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8296 setup_info = setup_info_shortcuts_1;
8297 title_string = STR_SETUP_SHORTCUTS;
8299 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8301 setup_info = setup_info_shortcuts_2;
8302 title_string = STR_SETUP_SHORTCUTS;
8304 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8306 setup_info = setup_info_shortcuts_3;
8307 title_string = STR_SETUP_SHORTCUTS;
8309 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8311 setup_info = setup_info_shortcuts_4;
8312 title_string = STR_SETUP_SHORTCUTS;
8314 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8316 setup_info = setup_info_shortcuts_5;
8317 title_string = STR_SETUP_SHORTCUTS;
8320 // use modified setup info without setup entries marked as hidden
8321 setup_info = getSetupInfoFinal(setup_info);
8323 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8325 // determine maximal number of setup entries that can be displayed on screen
8327 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8330 // determine maximal number of setup entries available for this setup screen
8332 for (i = 0; setup_info[i].type != 0; i++)
8335 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8337 MapScreenGadgets(max_setup_info);
8340 redraw_mask = fade_mask = REDRAW_ALL;
8342 DrawMaskedBorder(fade_mask);
8347 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8349 menu_info = setup_info;
8351 HandleMenuScreen(mx, my, dx, dy, button,
8352 setup_mode, num_setup_info, max_setup_info);
8355 static void DrawSetupScreen_Input(void)
8359 FadeOut(REDRAW_FIELD);
8363 setup_info = getSetupInfoFinal(setup_info_input);
8365 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8367 for (i = 0; setup_info[i].type != 0; i++)
8369 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8370 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8371 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8372 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8373 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8374 initCursor(i, IMG_MENU_BUTTON);
8376 DrawCursorAndText_Setup(i, -1, FALSE);
8379 // create gadgets for setup input menu screen
8380 FreeScreenGadgets();
8381 CreateScreenGadgets();
8383 // map gadgets for setup input menu screen
8384 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8386 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8388 FadeIn(REDRAW_FIELD);
8391 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8393 if (device_name == NULL)
8396 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8399 if (strlen(device_name) > 1)
8401 char c1 = device_name[strlen(device_name) - 1];
8402 char c2 = device_name[strlen(device_name) - 2];
8404 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8405 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8408 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8409 strlen(device_name));
8412 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8415 static struct SetupKeyboardInfo custom_key;
8422 { &custom_key.left, "Axis/Pad Left" },
8423 { &custom_key.right, "Axis/Pad Right" },
8424 { &custom_key.up, "Axis/Pad Up" },
8425 { &custom_key.down, "Axis/Pad Down" },
8426 { &custom_key.snap, "Button 1/A/X" },
8427 { &custom_key.drop, "Button 2/B/Y" }
8429 static char *joystick_name[MAX_PLAYERS] =
8436 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8437 int font_nr_info = FONT_MENU_1;
8438 int font_nr_name = FONT_VALUE_OLD;
8439 int font_nr_on = FONT_VALUE_1;
8440 int font_nr_off = FONT_VALUE_OLD;
8443 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8445 font_nr_info = FONT_MENU_2;
8446 font_nr_on = FONT_VALUE_NARROW;
8447 font_nr_off = FONT_VALUE_OLD_NARROW;
8450 custom_key = setup.input[player_nr].key;
8452 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8453 FONT_INPUT_1_ACTIVE);
8455 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8457 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8458 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8460 if (setup.input[player_nr].use_joystick)
8462 char *device_name = setup.input[player_nr].joy.device_name;
8463 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8464 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8465 char *text = joystick_name[joystick_nr];
8466 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8468 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8469 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8473 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8474 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8477 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8478 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8482 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8483 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8484 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8485 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8487 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8488 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8489 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8490 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8491 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8492 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8494 for (i = 0; i < 6; i++)
8496 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8498 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8500 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8501 (setup.input[player_nr].use_joystick ?
8503 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8507 static int input_player_nr = 0;
8509 static void HandleSetupScreen_Input_Player(int step, int direction)
8511 int old_player_nr = input_player_nr;
8514 new_player_nr = old_player_nr + step * direction;
8515 if (new_player_nr < 0)
8517 if (new_player_nr > MAX_PLAYERS - 1)
8518 new_player_nr = MAX_PLAYERS - 1;
8520 if (new_player_nr != old_player_nr)
8522 input_player_nr = new_player_nr;
8524 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8528 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8530 static int choice = 0;
8533 int pos_start = SETUPINPUT_SCREEN_POS_START;
8534 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8535 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8536 int pos_end = SETUPINPUT_SCREEN_POS_END;
8538 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8542 for (i = 0; setup_info_input[i].type != 0; i++)
8544 // adjust menu structure according to skipped setup entries
8545 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8553 if (button == MB_MENU_INITIALIZE)
8555 // input setup menu may have changed size due to graphics configuration
8556 if (choice >= pos_empty1)
8559 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8561 DrawCursorAndText_Setup(choice, -1, TRUE);
8565 else if (button == MB_MENU_LEAVE)
8567 setup_mode = SETUP_MODE_MAIN;
8574 if (mx || my) // mouse input
8576 x = (mx - mSX) / 32;
8577 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8579 else if (dx || dy) // keyboard input
8581 if (dx && choice == 0)
8582 x = (dx < 0 ? 10 : 12);
8583 else if ((dx && choice == 1) ||
8584 (dx == -1 && choice == pos_end))
8585 button = MB_MENU_CHOICE;
8589 if (y >= pos_empty1 && y <= pos_empty2)
8590 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8593 if (y == 0 && dx != 0 && button)
8595 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8597 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8598 y >= pos_start && y <= pos_end &&
8599 !(y >= pos_empty1 && y <= pos_empty2))
8605 DrawCursorAndText_Setup(choice, -1, FALSE);
8606 DrawCursorAndText_Setup(y, -1, TRUE);
8608 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8617 char *device_name = setup.input[input_player_nr].joy.device_name;
8619 if (!setup.input[input_player_nr].use_joystick)
8621 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8623 setJoystickDeviceToNr(device_name, new_device_nr);
8624 setup.input[input_player_nr].use_joystick = TRUE;
8628 int device_nr = getJoystickNrFromDeviceName(device_name);
8629 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8631 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8632 setup.input[input_player_nr].use_joystick = FALSE;
8634 setJoystickDeviceToNr(device_name, new_device_nr);
8637 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8641 if (setup.input[input_player_nr].use_joystick)
8642 ConfigureJoystick(input_player_nr);
8644 CustomizeKeyboard(input_player_nr);
8646 else if (y == pos_end)
8652 setup_mode = SETUP_MODE_MAIN;
8659 static boolean CustomizeKeyboardMain(int player_nr)
8663 boolean finished = FALSE;
8664 static struct SetupKeyboardInfo custom_key;
8669 } customize_step[] =
8671 { &custom_key.left, "Move Left" },
8672 { &custom_key.right, "Move Right" },
8673 { &custom_key.up, "Move Up" },
8674 { &custom_key.down, "Move Down" },
8675 { &custom_key.snap, "Snap Field" },
8676 { &custom_key.drop, "Drop Element" }
8678 int font_nr_old = FONT_VALUE_OLD;
8679 int font_nr_new = FONT_VALUE_1;
8680 boolean success = FALSE;
8682 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8684 font_nr_old = FONT_VALUE_OLD_NARROW;
8685 font_nr_new = FONT_VALUE_NARROW;
8688 // read existing key bindings from player setup
8689 custom_key = setup.input[player_nr].key;
8692 FadeOut(REDRAW_FIELD);
8696 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8699 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8700 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8701 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8702 "Key:", FONT_INPUT_1_ACTIVE);
8703 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8704 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8706 FadeIn(REDRAW_FIELD);
8712 if (NextValidEvent(&event))
8716 case EVENT_KEYPRESS:
8718 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8720 // press 'Escape' to abort and keep the old key bindings
8721 if (key == KSYM_Escape)
8723 FadeSkipNextFadeIn();
8730 // press 'Enter' to keep the existing key binding
8731 if (key == KSYM_Return)
8732 key = *customize_step[step_nr].key;
8734 // check if key already used
8735 for (i = 0; i < step_nr; i++)
8736 if (*customize_step[i].key == key)
8741 // got new key binding
8742 *customize_step[step_nr].key = key;
8743 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8745 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8746 getKeyNameFromKey(key), font_nr_new);
8749 // un-highlight last query
8750 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8751 customize_step[step_nr - 1].text, FONT_MENU_1);
8752 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8753 "Key:", FONT_MENU_1);
8755 // all keys configured
8764 // query next key binding
8765 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8766 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8767 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8768 "Key:", FONT_INPUT_1_ACTIVE);
8769 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8770 getKeyNameFromKey(*customize_step[step_nr].key),
8775 case EVENT_KEYRELEASE:
8776 key_joystick_mapping = 0;
8780 HandleOtherEvents(&event);
8788 // write new key bindings back to player setup, if successfully finished
8790 setup.input[player_nr].key = custom_key;
8795 void CustomizeKeyboard(int player_nr)
8797 boolean success = CustomizeKeyboardMain(player_nr);
8801 int font_nr = FONT_TITLE_1;
8802 int font_height = getFontHeight(font_nr);
8803 int ypos1 = SYSIZE / 2 - font_height * 2;
8804 int ypos2 = SYSIZE / 2 - font_height * 1;
8805 unsigned int wait_frame_delay = 0;
8806 unsigned int wait_frame_delay_value = 2000;
8808 ResetDelayCounter(&wait_frame_delay);
8812 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8813 DrawTextSCentered(ypos2, font_nr, "configured!");
8815 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8821 DrawSetupScreen_Input();
8824 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8826 #define MARKER_BUTTON 1
8827 #define MARKER_AXIS_X 2
8828 #define MARKER_AXIS_Y 3
8830 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8832 static boolean bitmaps_initialized = FALSE;
8833 boolean screen_initialized = FALSE;
8834 static Bitmap *controller, *button, *axis_x, *axis_y;
8836 boolean success = TRUE;
8837 boolean done = FALSE, next = FALSE;
8839 int alpha = 200, alpha_step = -1;
8840 int alpha_ticks = 0;
8841 char mapping[4096], temp[256];
8842 int font_name = MENU_SETUP_FONT_TITLE;
8843 int font_info = MENU_SETUP_FONT_TEXT;
8844 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8845 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8846 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8847 int ystep_name = getMenuTextStep(spacing_name, font_name);
8848 int ystep_line = getMenuTextStep(spacing_line, font_info);
8849 int ystep_para = getMenuTextStep(spacing_para, font_info);
8857 int axis, button, hat, hat_value;
8860 *step, *prev_step, steps[] =
8862 { 356, 155, MARKER_BUTTON, "a", },
8863 { 396, 122, MARKER_BUTTON, "b", },
8864 { 320, 125, MARKER_BUTTON, "x", },
8865 { 358, 95, MARKER_BUTTON, "y", },
8866 { 162, 125, MARKER_BUTTON, "back", },
8867 { 216, 125, MARKER_BUTTON, "guide", },
8868 { 271, 125, MARKER_BUTTON, "start", },
8869 { 110, 200, MARKER_BUTTON, "dpleft", },
8870 { 146, 228, MARKER_BUTTON, "dpdown", },
8871 { 178, 200, MARKER_BUTTON, "dpright", },
8872 { 146, 172, MARKER_BUTTON, "dpup", },
8873 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8874 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8875 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8876 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8877 { 73, 141, MARKER_BUTTON, "leftstick", },
8878 { 282, 210, MARKER_BUTTON, "rightstick", },
8879 { 73, 141, MARKER_AXIS_X, "leftx", },
8880 { 73, 141, MARKER_AXIS_Y, "lefty", },
8881 { 282, 210, MARKER_AXIS_X, "rightx", },
8882 { 282, 210, MARKER_AXIS_Y, "righty", },
8885 unsigned int event_frame_delay = 0;
8886 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8888 ResetDelayCounter(&event_frame_delay);
8890 if (!bitmaps_initialized)
8892 controller = LoadCustomImage("joystick/controller.png");
8893 button = LoadCustomImage("joystick/button.png");
8894 axis_x = LoadCustomImage("joystick/axis_x.png");
8895 axis_y = LoadCustomImage("joystick/axis_y.png");
8897 bitmaps_initialized = TRUE;
8900 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8903 // print info about the joystick we are watching
8904 Debug("joystick", "watching joystick %d: (%s)",
8905 SDL_JoystickInstanceID(joystick), name);
8906 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8907 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8908 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8911 // initialize mapping with GUID and name
8912 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8914 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8915 temp, name, SDL_GetPlatform());
8917 // loop through all steps (buttons and axes), getting joystick events
8918 for (i = 0; i < SDL_arraysize(steps) && !done;)
8920 Bitmap *marker = button; // initialize with reliable default value
8923 strcpy(step->mapping, mapping);
8927 step->hat_value = -1;
8929 marker = (step->marker == MARKER_BUTTON ? button :
8930 step->marker == MARKER_AXIS_X ? axis_x :
8931 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8935 while (!done && !next)
8937 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8938 alpha_ticks = SDL_GetTicks();
8945 else if (alpha < 128)
8951 int controller_x = SX + (SXSIZE - controller->width) / 2;
8952 int controller_y = SY + ystep_line;
8954 int marker_x = controller_x + step->x;
8955 int marker_y = controller_y + step->y;
8957 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8958 int ystart2 = ystart1 + ystep_name + ystep_line;
8962 DrawTextSCentered(ystart1, font_name, name);
8964 DrawTextSCentered(ystart2, font_info,
8965 "Press buttons and move axes on");
8966 ystart2 += ystep_line;
8967 DrawTextSCentered(ystart2, font_info,
8968 "your controller when indicated.");
8969 ystart2 += ystep_line;
8970 DrawTextSCentered(ystart2, font_info,
8971 "(Your controller may look different.)");
8972 ystart2 += ystep_para;
8974 #if defined(PLATFORM_ANDROID)
8975 DrawTextSCentered(ystart2, font_info,
8976 "To correct a mistake,");
8977 ystart2 += ystep_line;
8978 DrawTextSCentered(ystart2, font_info,
8979 "press the 'back' button.");
8980 ystart2 += ystep_line;
8981 DrawTextSCentered(ystart2, font_info,
8982 "To skip a button or axis,");
8983 ystart2 += ystep_line;
8984 DrawTextSCentered(ystart2, font_info,
8985 "press the 'menu' button.");
8987 DrawTextSCentered(ystart2, font_info,
8988 "To correct a mistake,");
8989 ystart2 += ystep_line;
8990 DrawTextSCentered(ystart2, font_info,
8991 "press the 'backspace' key.");
8992 ystart2 += ystep_line;
8993 DrawTextSCentered(ystart2, font_info,
8994 "To skip a button or axis,");
8995 ystart2 += ystep_line;
8996 DrawTextSCentered(ystart2, font_info,
8997 "press the 'return' key.");
8998 ystart2 += ystep_line;
8999 DrawTextSCentered(ystart2, font_info,
9000 "To exit, press the 'escape' key.");
9003 BlitBitmapMasked(controller, drawto, 0, 0,
9004 controller->width, controller->height,
9005 controller_x, controller_y);
9007 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
9008 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
9010 BlitBitmapMasked(marker, drawto, 0, 0,
9011 marker->width, marker->height,
9012 marker_x, marker_y);
9014 if (!screen_initialized)
9015 FadeIn(REDRAW_FIELD);
9019 screen_initialized = TRUE;
9021 while (NextValidEvent(&event))
9025 case SDL_JOYAXISMOTION:
9026 if (event.jaxis.value > 20000 ||
9027 event.jaxis.value < -20000)
9029 for (j = 0; j < i; j++)
9030 if (steps[j].axis == event.jaxis.axis)
9035 if (step->marker != MARKER_AXIS_X &&
9036 step->marker != MARKER_AXIS_Y)
9039 step->axis = event.jaxis.axis;
9040 strcat(mapping, step->field);
9041 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
9042 strcat(mapping, temp);
9050 case SDL_JOYHATMOTION:
9051 // ignore centering; we're probably just coming back
9052 // to the center from the previous item we set
9053 if (event.jhat.value == SDL_HAT_CENTERED)
9056 for (j = 0; j < i; j++)
9057 if (steps[j].hat == event.jhat.hat &&
9058 steps[j].hat_value == event.jhat.value)
9063 step->hat = event.jhat.hat;
9064 step->hat_value = event.jhat.value;
9065 strcat(mapping, step->field);
9066 snprintf(temp, sizeof(temp), ":h%u.%u,",
9067 event.jhat.hat, event.jhat.value );
9068 strcat(mapping, temp);
9075 case SDL_JOYBALLMOTION:
9078 case SDL_JOYBUTTONUP:
9079 for (j = 0; j < i; j++)
9080 if (steps[j].button == event.jbutton.button)
9085 step->button = event.jbutton.button;
9086 strcat(mapping, step->field);
9087 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9088 strcat(mapping, temp);
9095 case SDL_FINGERDOWN:
9096 case SDL_MOUSEBUTTONDOWN:
9104 if (event.key.keysym.sym == KSYM_BackSpace ||
9105 event.key.keysym.sym == KSYM_Back)
9117 prev_step = &steps[i - 1];
9118 strcpy(mapping, prev_step->mapping);
9125 if (event.key.keysym.sym == KSYM_space ||
9126 event.key.keysym.sym == KSYM_Return ||
9127 event.key.keysym.sym == KSYM_Menu)
9136 if (event.key.keysym.sym == KSYM_Escape)
9146 program.exit_function(0);
9153 // do not handle events for longer than standard frame delay period
9154 if (DelayReached(&event_frame_delay, event_frame_delay_value))
9163 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9166 // activate mapping for this game
9167 SDL_GameControllerAddMapping(mapping);
9169 // save mapping to personal mappings
9170 SaveSetup_AddGameControllerMapping(mapping);
9173 // wait until the last pending event was removed from event queue
9174 while (NextValidEvent(&event));
9179 static int ConfigureJoystickMain(int player_nr)
9181 char *device_name = setup.input[player_nr].joy.device_name;
9182 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9183 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9184 int success = FALSE;
9187 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9188 return JOYSTICK_NOT_AVAILABLE;
9190 if (!joystick_active || !setup.input[player_nr].use_joystick)
9191 return JOYSTICK_NOT_AVAILABLE;
9194 FadeOut(REDRAW_FIELD);
9196 // close all joystick devices (potentially opened as game controllers)
9197 for (i = 0; i < SDL_NumJoysticks(); i++)
9198 SDLCloseJoystick(i);
9200 // open joystick device as plain joystick to configure as game controller
9201 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9203 // as the joystick was successfully opened before, this should not happen
9204 if (joystick == NULL)
9207 // create new game controller mapping (buttons and axes) for joystick device
9208 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9210 // close joystick (and maybe re-open as configured game controller later)
9211 SDL_JoystickClose(joystick);
9213 // re-open all joystick devices (potentially as game controllers)
9214 for (i = 0; i < SDL_NumJoysticks(); i++)
9217 // clear all joystick input actions for all joystick devices
9218 SDLClearJoystickState();
9220 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9223 void ConfigureJoystick(int player_nr)
9225 boolean state = ConfigureJoystickMain(player_nr);
9227 if (state != JOYSTICK_NOT_CONFIGURED)
9229 boolean success = (state == JOYSTICK_CONFIGURED);
9230 char message1[MAX_OUTPUT_LINESIZE + 1];
9231 char *message2 = (success ? "configured!" : "not available!");
9232 char *device_name = setup.input[player_nr].joy.device_name;
9233 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9234 int font_nr = FONT_TITLE_1;
9235 int font_height = getFontHeight(font_nr);
9236 int ypos1 = SYSIZE / 2 - font_height * 2;
9237 int ypos2 = SYSIZE / 2 - font_height * 1;
9238 unsigned int wait_frame_delay = 0;
9239 unsigned int wait_frame_delay_value = 2000;
9241 ResetDelayCounter(&wait_frame_delay);
9245 sprintf(message1, "Joystick %d", nr);
9247 DrawTextSCentered(ypos1, font_nr, message1);
9248 DrawTextSCentered(ypos2, font_nr, message2);
9250 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9256 DrawSetupScreen_Input();
9259 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9261 if (y < video.screen_height / 3)
9263 // remap touch gadgets to access upper part of the screen
9264 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9265 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9267 else if (y > 2 * video.screen_height / 3)
9269 // remap touch gadgets to access lower part of the screen
9270 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9271 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9275 static boolean ConfigureVirtualButtonsMain(void)
9277 static char *customize_step_text[] =
9286 char grid_button[] =
9288 CHAR_GRID_BUTTON_LEFT,
9289 CHAR_GRID_BUTTON_RIGHT,
9290 CHAR_GRID_BUTTON_UP,
9291 CHAR_GRID_BUTTON_DOWN,
9292 CHAR_GRID_BUTTON_SNAP,
9293 CHAR_GRID_BUTTON_DROP
9302 int font_nr = FONT_INPUT_1_ACTIVE;
9303 int font_height = getFontHeight(font_nr);
9304 int ypos1 = SYSIZE / 2 - font_height * 2;
9305 int ypos2 = SYSIZE / 2 - font_height * 1;
9306 boolean success = FALSE;
9307 boolean finished = FALSE;
9309 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9310 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9311 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9312 boolean set_grid_button = FALSE;
9313 int nr = GRID_ACTIVE_NR();
9316 for (x = 0; x < MAX_GRID_XSIZE; x++)
9317 for (y = 0; y < MAX_GRID_YSIZE; y++)
9318 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9320 overlay.grid_button_highlight = grid_button[step_nr];
9325 FadeOut(REDRAW_FIELD);
9329 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9330 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9331 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9333 FadeIn(REDRAW_FIELD);
9335 SetOverlayShowGrid(TRUE);
9337 // map gadgets for setup touch buttons menu screen
9338 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9344 while (NextValidEvent(&event))
9346 int action = ACTION_NONE;
9348 // ---------- handle events and set the resulting action ----------
9354 UserEvent *user = (UserEvent *)&event;
9355 int id = user->value1;
9357 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9358 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9359 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9360 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9365 case EVENT_KEYPRESS:
9367 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9369 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9370 key == KSYM_BackSpace ||
9371 key == KSYM_Back ? ACTION_BACK :
9372 key == KSYM_Return ||
9374 key == KSYM_space ? ACTION_NEXT :
9379 case EVENT_KEYRELEASE:
9380 key_joystick_mapping = 0;
9383 case EVENT_BUTTONPRESS:
9384 case EVENT_BUTTONRELEASE:
9386 ButtonEvent *button = (ButtonEvent *)&event;
9388 motion_status = FALSE;
9390 if (button->type == EVENT_BUTTONPRESS)
9391 button_status = button->button;
9393 button_status = MB_RELEASED;
9395 if (HandleGadgets(button->x, button->y, button_status))
9397 // do not handle this button event anymore
9401 button->x += video.screen_xoffset;
9402 button->y += video.screen_yoffset;
9404 x = button->x * overlay.grid_xsize / video.screen_width;
9405 y = button->y * overlay.grid_ysize / video.screen_height;
9407 if (button->type == EVENT_BUTTONPRESS)
9410 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9411 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9413 set_grid_button = TRUE;
9416 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9420 case EVENT_MOTIONNOTIFY:
9422 MotionEvent *motion = (MotionEvent *)&event;
9424 motion_status = TRUE;
9426 if (HandleGadgets(motion->x, motion->y, button_status))
9428 // do not handle this button event anymore
9432 motion->x += video.screen_xoffset;
9433 motion->y += video.screen_yoffset;
9435 x = motion->x * overlay.grid_xsize / video.screen_width;
9436 y = motion->y * overlay.grid_ysize / video.screen_height;
9438 set_grid_button = TRUE;
9440 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9444 case SDL_WINDOWEVENT:
9445 HandleWindowEvent((WindowEvent *) &event);
9447 // check if device has been rotated
9448 if (nr != GRID_ACTIVE_NR())
9450 nr = GRID_ACTIVE_NR();
9452 for (x = 0; x < MAX_GRID_XSIZE; x++)
9453 for (y = 0; y < MAX_GRID_YSIZE; y++)
9454 grid_button_old[x][y] = grid_button_tmp[x][y] =
9455 overlay.grid_button[x][y];
9460 case SDL_APP_WILLENTERBACKGROUND:
9461 case SDL_APP_DIDENTERBACKGROUND:
9462 case SDL_APP_WILLENTERFOREGROUND:
9463 case SDL_APP_DIDENTERFOREGROUND:
9464 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9468 HandleOtherEvents(&event);
9472 // ---------- perform action set by handling events ----------
9474 if (action == ACTION_ESCAPE)
9476 // abort and restore the old key bindings
9478 for (x = 0; x < MAX_GRID_XSIZE; x++)
9479 for (y = 0; y < MAX_GRID_YSIZE; y++)
9480 overlay.grid_button[x][y] = grid_button_old[x][y];
9482 FadeSkipNextFadeIn();
9486 else if (action == ACTION_BACK)
9488 // keep the configured key bindings and go to previous page
9494 FadeSkipNextFadeIn();
9499 else if (action == ACTION_NEXT)
9501 // keep the configured key bindings and go to next page
9505 // all virtual buttons configured
9513 if (action != ACTION_NONE && !finished)
9515 for (x = 0; x < MAX_GRID_XSIZE; x++)
9516 for (y = 0; y < MAX_GRID_YSIZE; y++)
9517 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9519 overlay.grid_button_highlight = grid_button[step_nr];
9521 // configure next virtual button
9525 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9526 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9527 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9530 if (set_grid_button)
9532 overlay.grid_button[x][y] =
9533 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9534 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9535 grid_button_tmp[x][y]);
9537 set_grid_button = FALSE;
9544 for (x = 0; x < MAX_GRID_XSIZE; x++)
9545 for (y = 0; y < MAX_GRID_YSIZE; y++)
9546 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9548 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9550 SetOverlayShowGrid(FALSE);
9555 void ConfigureVirtualButtons(void)
9557 boolean success = ConfigureVirtualButtonsMain();
9559 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9560 SCREEN_MASK_TOUCH2);
9564 int font_nr = FONT_TITLE_1;
9565 int font_height = getFontHeight(font_nr);
9566 int ypos1 = SYSIZE / 2 - font_height * 2;
9567 int ypos2 = SYSIZE / 2 - font_height * 1;
9568 unsigned int wait_frame_delay = 0;
9569 unsigned int wait_frame_delay_value = 2000;
9571 ResetDelayCounter(&wait_frame_delay);
9575 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9576 DrawTextSCentered(ypos2, font_nr, "configured!");
9578 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9585 void DrawSetupScreen(void)
9590 if (setup_mode == SETUP_MODE_INPUT)
9591 DrawSetupScreen_Input();
9592 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9593 DrawChooseTree(&scores_type_current);
9594 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9595 DrawChooseTree(&game_speed_current);
9596 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9597 DrawChooseTree(&scroll_delay_current);
9598 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9599 DrawChooseTree(&snapshot_mode_current);
9600 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9601 DrawChooseTree(&window_size_current);
9602 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9603 DrawChooseTree(&scaling_type_current);
9604 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9605 DrawChooseTree(&rendering_mode_current);
9606 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9607 DrawChooseTree(&vsync_mode_current);
9608 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9609 DrawChooseTree(&artwork.gfx_current);
9610 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9611 DrawChooseTree(&artwork.snd_current);
9612 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9613 DrawChooseTree(&artwork.mus_current);
9614 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9615 DrawChooseTree(&volume_simple_current);
9616 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9617 DrawChooseTree(&volume_loops_current);
9618 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9619 DrawChooseTree(&volume_music_current);
9620 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9621 DrawChooseTree(&touch_control_current);
9622 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9623 DrawChooseTree(&move_distance_current);
9624 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9625 DrawChooseTree(&drop_distance_current);
9626 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9627 DrawChooseTree(&transparency_current);
9628 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9629 DrawChooseTree(&grid_size_current[0][0]);
9630 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9631 DrawChooseTree(&grid_size_current[0][1]);
9632 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9633 DrawChooseTree(&grid_size_current[1][0]);
9634 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9635 DrawChooseTree(&grid_size_current[1][1]);
9637 DrawSetupScreen_Generic();
9639 PlayMenuSoundsAndMusic();
9642 void RedrawSetupScreenAfterFullscreenToggle(void)
9644 if (setup_mode == SETUP_MODE_GRAPHICS ||
9645 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9647 // update list selection from "setup.window_scaling_percent"
9648 execSetupGraphics_setWindowSizes(TRUE);
9654 void RedrawSetupScreenAfterScreenRotation(int nr)
9658 if (setup_mode == SETUP_MODE_TOUCH)
9660 // update virtual button settings (depending on screen orientation)
9663 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9665 // save already configured virtual buttons
9666 for (x = 0; x < MAX_GRID_XSIZE; x++)
9667 for (y = 0; y < MAX_GRID_YSIZE; y++)
9668 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9672 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9674 if (setup_mode == SETUP_MODE_INPUT)
9675 HandleSetupScreen_Input(mx, my, dx, dy, button);
9676 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9677 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9678 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9679 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9680 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9681 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9682 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9683 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9684 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9685 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9686 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9687 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9688 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9689 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9690 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9691 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9692 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9693 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9694 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9695 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9696 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9697 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9698 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9699 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9700 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9701 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9702 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9703 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9704 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9705 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9706 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9707 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9708 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9709 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9710 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9711 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9712 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9713 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9714 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9715 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9716 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9717 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9718 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9719 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9721 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9724 void HandleGameActions(void)
9726 if (setup.ask_on_game_over)
9729 if (game.restart_game_message != NULL)
9731 RequestRestartGame(game.restart_game_message);
9736 if (game_status != GAME_MODE_PLAYING)
9739 GameActions(); // main game loop
9741 if (tape.auto_play && !tape.playing)
9742 AutoPlayTapesContinue(); // continue automatically playing next tape
9746 // ---------- new screen button stuff --------------------------------------
9750 int gfx_unpressed, gfx_pressed;
9751 struct MenuPosInfo *pos;
9752 boolean *check_value;
9755 unsigned int event_mask;
9756 boolean is_touch_button;
9758 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9761 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9762 &menu.main.button.prev_level, NULL,
9763 SCREEN_CTRL_ID_PREV_LEVEL,
9765 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9766 FALSE, "previous level"
9769 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9770 &menu.main.button.next_level, NULL,
9771 SCREEN_CTRL_ID_NEXT_LEVEL,
9773 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9777 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9778 &menu.scores.button.prev_level, NULL,
9779 SCREEN_CTRL_ID_PREV_LEVEL2,
9781 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9782 FALSE, "previous level"
9785 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9786 &menu.scores.button.next_level, NULL,
9787 SCREEN_CTRL_ID_NEXT_LEVEL2,
9789 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9793 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9794 &menu.main.button.first_level, NULL,
9795 SCREEN_CTRL_ID_FIRST_LEVEL,
9798 FALSE, "first level"
9801 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9802 &menu.main.button.last_level, NULL,
9803 SCREEN_CTRL_ID_LAST_LEVEL,
9809 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9810 &menu.main.button.level_number, NULL,
9811 SCREEN_CTRL_ID_LEVEL_NUMBER,
9814 FALSE, "level number"
9817 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9818 &menu.setup.button.prev_player, NULL,
9819 SCREEN_CTRL_ID_PREV_PLAYER,
9821 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9822 FALSE, "previous player"
9825 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9826 &menu.setup.button.next_player, NULL,
9827 SCREEN_CTRL_ID_NEXT_PLAYER,
9829 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9830 FALSE, "next player"
9833 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9834 &menu.main.button.insert_solution, NULL,
9835 SCREEN_CTRL_ID_INSERT_SOLUTION,
9836 SCREEN_MASK_MAIN_HAS_SOLUTION,
9838 FALSE, "insert solution tape"
9841 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9842 &menu.main.button.play_solution, NULL,
9843 SCREEN_CTRL_ID_PLAY_SOLUTION,
9844 SCREEN_MASK_MAIN_HAS_SOLUTION,
9846 FALSE, "play solution tape"
9849 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9850 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9851 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9853 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9854 FALSE, "switch ECS/AGA chipset"
9857 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9858 &menu.setup.button.touch_back, NULL,
9859 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9862 TRUE, "previous page"
9865 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9866 &menu.setup.button.touch_next, NULL,
9867 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9873 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9874 &menu.setup.button.touch_back2, NULL,
9875 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9878 TRUE, "previous page"
9881 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9882 &menu.setup.button.touch_next2, NULL,
9883 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9892 int gfx_unpressed, gfx_pressed;
9896 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9899 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9900 -1, -1, // these values are not constant, but can change at runtime
9901 SCREEN_CTRL_ID_SCROLL_UP,
9905 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9906 -1, -1, // these values are not constant, but can change at runtime
9907 SCREEN_CTRL_ID_SCROLL_DOWN,
9914 int gfx_unpressed, gfx_pressed;
9920 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9923 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9924 -1, -1, // these values are not constant, but can change at runtime
9925 -1, -1, // these values are not constant, but can change at runtime
9926 GD_TYPE_SCROLLBAR_VERTICAL,
9927 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9928 "scroll level series vertically"
9940 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9943 IMG_SETUP_INPUT_TEXT,
9944 SCREEN_CTRL_ID_NETWORK_SERVER,
9945 -1, -1, // these values are not constant, but can change at runtime
9946 MAX_SETUP_TEXT_INPUT_LEN,
9947 network_server_hostname,
9948 "Network Server Hostname / IP"
9952 static void CreateScreenMenubuttons(void)
9954 struct GadgetInfo *gi;
9955 unsigned int event_mask;
9958 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9960 struct MenuPosInfo *pos = menubutton_info[i].pos;
9961 int screen_mask = menubutton_info[i].screen_mask;
9962 boolean is_touch_button = menubutton_info[i].is_touch_button;
9963 boolean is_check_button = menubutton_info[i].check_value != NULL;
9964 boolean is_score_button = (screen_mask == SCREEN_MASK_SCORES);
9965 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9966 int gfx_unpressed, gfx_pressed;
9967 int x, y, width, height;
9968 int gd_x1, gd_x2, gd_y1, gd_y2;
9969 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9970 int id = menubutton_info[i].gadget_id;
9971 int type = GD_TYPE_NORMAL_BUTTON;
9972 boolean checked = FALSE;
9974 event_mask = menubutton_info[i].event_mask;
9976 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9977 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9979 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9980 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9982 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9983 gfx_pressed = menubutton_info[i].gfx_pressed;
9984 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9985 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9986 gd_x1 = graphic_info[gfx_unpressed].src_x;
9987 gd_y1 = graphic_info[gfx_unpressed].src_y;
9988 gd_x2 = graphic_info[gfx_pressed].src_x;
9989 gd_y2 = graphic_info[gfx_pressed].src_y;
9995 if (is_touch_button)
9997 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9998 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
10001 if (is_check_button)
10003 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
10004 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
10005 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
10006 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
10008 type = GD_TYPE_CHECK_BUTTON;
10009 checked = *menubutton_info[i].check_value;
10012 if (is_score_button)
10014 // if x/y set to -1, dynamically place buttons next to title text
10015 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10018 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10019 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10020 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10021 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10024 y = mSY + MENU_TITLE1_YPOS;
10027 gi = CreateGadget(GDI_CUSTOM_ID, id,
10028 GDI_CUSTOM_TYPE_ID, i,
10029 GDI_IMAGE_ID, gfx_unpressed,
10030 GDI_INFO_TEXT, menubutton_info[i].infotext,
10034 GDI_HEIGHT, height,
10036 GDI_STATE, GD_BUTTON_UNPRESSED,
10037 GDI_CHECKED, checked,
10038 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10039 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10040 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
10041 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
10042 GDI_DIRECT_DRAW, FALSE,
10043 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10044 GDI_EVENT_MASK, event_mask,
10045 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10049 Fail("cannot create gadget");
10051 screen_gadget[id] = gi;
10055 static void CreateScreenScrollbuttons(void)
10057 struct GadgetInfo *gi;
10058 unsigned int event_mask;
10061 // these values are not constant, but can change at runtime
10062 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10063 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10064 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10065 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10067 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10069 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10070 int gfx_unpressed, gfx_pressed;
10071 int x, y, width, height;
10072 int gd_x1, gd_x2, gd_y1, gd_y2;
10073 int id = scrollbutton_info[i].gadget_id;
10075 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10077 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10078 y = mSY + scrollbutton_info[i].y;
10079 width = SC_SCROLLBUTTON_XSIZE;
10080 height = SC_SCROLLBUTTON_YSIZE;
10082 // correct scrollbar position if placed outside menu (playfield) area
10083 if (x > SX + SC_SCROLL_UP_XPOS)
10084 x = SX + SC_SCROLL_UP_XPOS;
10086 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10087 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10088 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10090 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10091 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10092 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10093 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10094 gd_x1 = graphic_info[gfx_unpressed].src_x;
10095 gd_y1 = graphic_info[gfx_unpressed].src_y;
10096 gd_x2 = graphic_info[gfx_pressed].src_x;
10097 gd_y2 = graphic_info[gfx_pressed].src_y;
10099 gi = CreateGadget(GDI_CUSTOM_ID, id,
10100 GDI_CUSTOM_TYPE_ID, i,
10101 GDI_IMAGE_ID, gfx_unpressed,
10102 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10106 GDI_HEIGHT, height,
10107 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10108 GDI_STATE, GD_BUTTON_UNPRESSED,
10109 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10110 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10111 GDI_DIRECT_DRAW, FALSE,
10112 GDI_EVENT_MASK, event_mask,
10113 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10117 Fail("cannot create gadget");
10119 screen_gadget[id] = gi;
10123 static void CreateScreenScrollbars(void)
10127 // these values are not constant, but can change at runtime
10128 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10129 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10130 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10131 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10133 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10135 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10136 int gfx_unpressed, gfx_pressed;
10137 int x, y, width, height;
10138 int gd_x1, gd_x2, gd_y1, gd_y2;
10139 struct GadgetInfo *gi;
10140 int items_max, items_visible, item_position;
10141 unsigned int event_mask;
10142 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10143 int id = scrollbar_info[i].gadget_id;
10145 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10147 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10148 y = mSY + scrollbar_info[i].y;
10149 width = scrollbar_info[i].width;
10150 height = scrollbar_info[i].height;
10152 // correct scrollbar position if placed outside menu (playfield) area
10153 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10154 x = SX + SC_SCROLL_VERTICAL_XPOS;
10156 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10157 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10159 items_max = num_page_entries;
10160 items_visible = num_page_entries;
10163 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10164 gfx_pressed = scrollbar_info[i].gfx_pressed;
10165 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10166 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10167 gd_x1 = graphic_info[gfx_unpressed].src_x;
10168 gd_y1 = graphic_info[gfx_unpressed].src_y;
10169 gd_x2 = graphic_info[gfx_pressed].src_x;
10170 gd_y2 = graphic_info[gfx_pressed].src_y;
10172 gi = CreateGadget(GDI_CUSTOM_ID, id,
10173 GDI_CUSTOM_TYPE_ID, i,
10174 GDI_IMAGE_ID, gfx_unpressed,
10175 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10179 GDI_HEIGHT, height,
10180 GDI_TYPE, scrollbar_info[i].type,
10181 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10182 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10183 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10184 GDI_WHEEL_AREA_X, SX,
10185 GDI_WHEEL_AREA_Y, SY,
10186 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10187 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
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_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10192 GDI_DIRECT_DRAW, FALSE,
10193 GDI_EVENT_MASK, event_mask,
10194 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10198 Fail("cannot create gadget");
10200 screen_gadget[id] = gi;
10204 static void CreateScreenTextInputGadgets(void)
10208 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10210 int graphic = textinput_info[i].graphic;
10211 struct GraphicInfo *gd = &graphic_info[graphic];
10212 int gd_x1 = gd->src_x;
10213 int gd_y1 = gd->src_y;
10214 int gd_x2 = gd->src_x + gd->active_xoffset;
10215 int gd_y2 = gd->src_y + gd->active_yoffset;
10216 struct GadgetInfo *gi;
10217 unsigned int event_mask;
10218 int id = textinput_info[i].gadget_id;
10219 int x = textinput_info[i].x;
10220 int y = textinput_info[i].y;
10222 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10224 gi = CreateGadget(GDI_CUSTOM_ID, id,
10225 GDI_CUSTOM_TYPE_ID, i,
10226 GDI_INFO_TEXT, textinput_info[i].infotext,
10229 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10230 GDI_TEXT_VALUE, textinput_info[i].value,
10231 GDI_TEXT_SIZE, textinput_info[i].size,
10232 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10233 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10234 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10235 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10236 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10237 GDI_DESIGN_WIDTH, gd->width,
10238 GDI_EVENT_MASK, event_mask,
10239 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10240 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10244 Fail("cannot create gadget");
10246 screen_gadget[id] = gi;
10250 void CreateScreenGadgets(void)
10252 CreateScreenMenubuttons();
10254 CreateScreenScrollbuttons();
10255 CreateScreenScrollbars();
10257 CreateScreenTextInputGadgets();
10260 void FreeScreenGadgets(void)
10264 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10265 FreeGadget(screen_gadget[i]);
10268 static void RedrawScreenMenuGadgets(int screen_mask)
10272 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10273 if (screen_mask & menubutton_info[i].screen_mask)
10274 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10277 static void MapScreenMenuGadgets(int screen_mask)
10281 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10282 if (screen_mask & menubutton_info[i].screen_mask)
10283 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10286 static void UnmapScreenMenuGadgets(int screen_mask)
10290 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10292 if (screen_mask & menubutton_info[i].screen_mask)
10294 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10296 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10297 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10298 screen_gadget[menubutton_info[i].gadget_id]->y,
10299 screen_gadget[menubutton_info[i].gadget_id]->width,
10300 screen_gadget[menubutton_info[i].gadget_id]->height);
10305 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10308 MapScreenMenuGadgets(screen_mask);
10310 UnmapScreenMenuGadgets(screen_mask);
10313 static void MapScreenGadgets(int num_entries)
10317 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10320 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10321 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10323 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10324 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10327 static void UnmapScreenGadgets()
10331 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10332 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10334 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10335 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10338 static void MapScreenTreeGadgets(TreeInfo *ti)
10340 MapScreenGadgets(numTreeInfoInGroup(ti));
10343 static void UnmapScreenTreeGadgets(void)
10345 UnmapScreenGadgets();
10348 static void HandleScreenGadgets(struct GadgetInfo *gi)
10350 int id = gi->custom_id;
10351 int button = gi->event.button;
10352 int step = (button == MB_LEFTBUTTON ? 1 :
10353 button == MB_MIDDLEBUTTON ? 5 :
10354 button == MB_RIGHTBUTTON ? 10 : 1);
10358 case SCREEN_CTRL_ID_PREV_LEVEL:
10359 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10362 case SCREEN_CTRL_ID_NEXT_LEVEL:
10363 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10366 case SCREEN_CTRL_ID_PREV_LEVEL2:
10367 HandleHallOfFame_SelectLevel(step, -1);
10370 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10371 HandleHallOfFame_SelectLevel(step, +1);
10374 case SCREEN_CTRL_ID_FIRST_LEVEL:
10375 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10378 case SCREEN_CTRL_ID_LAST_LEVEL:
10379 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10382 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10383 CloseDoor(DOOR_CLOSE_2);
10384 SetGameStatus(GAME_MODE_LEVELNR);
10385 DrawChooseLevelNr();
10388 case SCREEN_CTRL_ID_PREV_PLAYER:
10389 HandleSetupScreen_Input_Player(step, -1);
10392 case SCREEN_CTRL_ID_NEXT_PLAYER:
10393 HandleSetupScreen_Input_Player(step, +1);
10396 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10397 InsertSolutionTape();
10400 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10401 PlaySolutionTape();
10404 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10405 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10409 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10410 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10411 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10412 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10413 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10416 case SCREEN_CTRL_ID_SCROLL_UP:
10417 if (game_status == GAME_MODE_NAMES)
10418 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10419 else if (game_status == GAME_MODE_LEVELS)
10420 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10421 else if (game_status == GAME_MODE_LEVELNR)
10422 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10423 else if (game_status == GAME_MODE_SETUP)
10424 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10425 else if (game_status == GAME_MODE_INFO)
10426 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10427 else if (game_status == GAME_MODE_SCORES)
10428 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10431 case SCREEN_CTRL_ID_SCROLL_DOWN:
10432 if (game_status == GAME_MODE_NAMES)
10433 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10434 else if (game_status == GAME_MODE_LEVELS)
10435 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10436 else if (game_status == GAME_MODE_LEVELNR)
10437 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10438 else if (game_status == GAME_MODE_SETUP)
10439 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10440 else if (game_status == GAME_MODE_INFO)
10441 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10442 else if (game_status == GAME_MODE_SCORES)
10443 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10446 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10447 if (game_status == GAME_MODE_NAMES)
10448 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10449 else if (game_status == GAME_MODE_LEVELS)
10450 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10451 else if (game_status == GAME_MODE_LEVELNR)
10452 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10453 else if (game_status == GAME_MODE_SETUP)
10454 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10455 else if (game_status == GAME_MODE_INFO)
10456 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10457 else if (game_status == GAME_MODE_SCORES)
10458 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10461 case SCREEN_CTRL_ID_NETWORK_SERVER:
10463 if (!strEqual(gi->textinput.value, ""))
10465 setString(&setup.network_server_hostname, gi->textinput.value);
10467 network.server_host = setup.network_server_hostname;
10471 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10473 network.server_host = NULL;
10476 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10477 network.server_host = NULL;
10479 execSetupGame_setNetworkServerText();
10491 void DumpScreenIdentifiers(void)
10495 Print("Active screen elements on current screen:\n");
10497 for (i = 0; main_controls[i].nr != -1; i++)
10499 struct MainControlInfo *mci = &main_controls[i];
10501 if (mci->button_graphic != -1)
10503 char *token = getTokenFromImageID(mci->button_graphic);
10505 Print("- '%s'\n", token);
10512 boolean DoScreenAction(int image_id)
10516 if (game_status != GAME_MODE_MAIN)
10519 for (i = 0; main_controls[i].nr != -1; i++)
10521 struct MainControlInfo *mci = &main_controls[i];
10522 struct MenuPosInfo *pos = mci->pos_button;
10524 if (mci->button_graphic == image_id)
10526 int x = mSX + pos->x;
10527 int y = mSY + pos->y;
10529 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10538 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10540 // get tree info node of newly added level or artwork set
10541 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10542 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10544 if (tree_node_new == NULL) // should not happen
10547 // if request dialog is active, do nothing
10548 if (game.request_active)
10551 if (game_status == GAME_MODE_MAIN &&
10552 tree_type == TREE_TYPE_LEVEL_DIR)
10554 // when adding new level set in main menu, select it as current level set
10556 // change current level set to newly added level set from zip file
10557 leveldir_current = tree_node_new;
10559 // change current level number to first level of newly added level set
10560 level_nr = leveldir_current->first_level;
10562 // redraw screen to reflect changed level set
10565 // save this level set and level number as last selected level set
10566 SaveLevelSetup_LastSeries();
10567 SaveLevelSetup_SeriesInfo();
10569 else if (game_status == GAME_MODE_LEVELS &&
10570 tree_type == TREE_TYPE_LEVEL_DIR)
10572 // when adding new level set in level set menu, set cursor and update screen
10574 leveldir_current = tree_node_new;
10576 DrawChooseTree(&leveldir_current);
10578 else if (game_status == GAME_MODE_SETUP)
10580 // when adding new artwork set in setup menu, set cursor and update screen
10582 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10583 tree_type == TREE_TYPE_GRAPHICS_DIR)
10585 artwork.gfx_current = tree_node_new;
10587 DrawChooseTree(&artwork.gfx_current);
10589 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10590 tree_type == TREE_TYPE_SOUNDS_DIR)
10592 artwork.snd_current = tree_node_new;
10594 DrawChooseTree(&artwork.snd_current);
10596 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10597 tree_type == TREE_TYPE_MUSIC_DIR)
10599 artwork.mus_current = tree_node_new;
10601 DrawChooseTree(&artwork.mus_current);
10606 static int UploadTapes(void)
10608 SetGameStatus(GAME_MODE_LOADING);
10610 FadeSetEnterScreen();
10611 FadeOut(REDRAW_ALL);
10613 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10615 FadeIn(REDRAW_ALL);
10617 DrawInitTextHead("Uploading tapes");
10619 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10620 global.autoplay_leveldir = "ALL";
10621 global.autoplay_all = TRUE;
10623 int num_tapes_uploaded = AutoPlayTapes();
10625 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10626 global.autoplay_leveldir = NULL;
10627 global.autoplay_all = FALSE;
10629 SetGameStatus(GAME_MODE_MAIN);
10633 return num_tapes_uploaded;
10636 static boolean OfferUploadTapes(void)
10638 if (!Request(setup.has_remaining_tapes ?
10639 "Upload missing tapes to the high score server now?" :
10640 "Upload all your tapes to the high score server now?", REQ_ASK))
10643 int num_tapes_uploaded = UploadTapes();
10646 if (num_tapes_uploaded < 0)
10648 num_tapes_uploaded = -num_tapes_uploaded - 1;
10650 if (num_tapes_uploaded == 0)
10651 sprintf(message, "Upload failed! No tapes uploaded!");
10652 else if (num_tapes_uploaded == 1)
10653 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10655 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10656 num_tapes_uploaded);
10658 Request(message, REQ_CONFIRM);
10660 // if uploading tapes failed, add tape upload entry to setup menu
10661 setup.provide_uploading_tapes = TRUE;
10662 setup.has_remaining_tapes = TRUE;
10664 SaveSetup_ServerSetup();
10669 if (num_tapes_uploaded == 0)
10670 sprintf(message, "No tapes uploaded!");
10671 else if (num_tapes_uploaded == 1)
10672 sprintf(message, "1 tape uploaded!");
10674 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10676 Request(message, REQ_CONFIRM);
10678 if (num_tapes_uploaded > 0)
10679 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10681 // after all tapes have been uploaded, remove entry from setup menu
10682 setup.provide_uploading_tapes = FALSE;
10683 setup.has_remaining_tapes = FALSE;
10685 SaveSetup_ServerSetup();
10690 static void CheckUploadTapes(void)
10692 if (!setup.ask_for_uploading_tapes)
10695 // after asking for uploading tapes, do not ask again
10696 setup.ask_for_uploading_tapes = FALSE;
10697 setup.ask_for_remaining_tapes = FALSE;
10699 if (directoryExists(getTapeDir(NULL)))
10701 boolean tapes_uploaded = OfferUploadTapes();
10703 if (!tapes_uploaded)
10705 Request(setup.has_remaining_tapes ?
10706 "You can upload missing tapes from the setup menu later!" :
10707 "You can upload your tapes from the setup menu later!",
10713 // if tapes directory does not exist yet, never offer uploading all tapes
10714 setup.provide_uploading_tapes = FALSE;
10717 SaveSetup_ServerSetup();
10720 static void UpgradePlayerUUID(void)
10722 ApiResetUUIDAsThread(getUUID());
10725 static void CheckUpgradePlayerUUID(void)
10727 if (setup.player_version > 1)
10730 UpgradePlayerUUID();
10733 void CheckApiServerTasks(void)
10735 // check if the player's UUID has to be upgraded
10736 CheckUpgradePlayerUUID();
10738 // check if there are any tapes to be uploaded
10739 CheckUploadTapes();