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"
28 #define DEBUG_JOYSTICKS 0
31 // screens on the info screen
32 #define INFO_MODE_MAIN 0
33 #define INFO_MODE_TITLE 1
34 #define INFO_MODE_ELEMENTS 2
35 #define INFO_MODE_MUSIC 3
36 #define INFO_MODE_CREDITS 4
37 #define INFO_MODE_PROGRAM 5
38 #define INFO_MODE_VERSION 6
39 #define INFO_MODE_LEVELSET 7
41 #define MAX_INFO_MODES 8
43 // screens on the setup screen
44 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
45 // (should also match corresponding entries in src/conf_gfx.c)
46 #define SETUP_MODE_MAIN 0
47 #define SETUP_MODE_GAME 1
48 #define SETUP_MODE_ENGINES 2
49 #define SETUP_MODE_EDITOR 3
50 #define SETUP_MODE_GRAPHICS 4
51 #define SETUP_MODE_SOUND 5
52 #define SETUP_MODE_ARTWORK 6
53 #define SETUP_MODE_INPUT 7
54 #define SETUP_MODE_TOUCH 8
55 #define SETUP_MODE_SHORTCUTS 9
56 #define SETUP_MODE_SHORTCUTS_1 10
57 #define SETUP_MODE_SHORTCUTS_2 11
58 #define SETUP_MODE_SHORTCUTS_3 12
59 #define SETUP_MODE_SHORTCUTS_4 13
60 #define SETUP_MODE_SHORTCUTS_5 14
62 // sub-screens on the setup screen (generic)
63 #define SETUP_MODE_CHOOSE_ARTWORK 15
64 #define SETUP_MODE_CHOOSE_OTHER 16
66 // sub-screens on the setup screen (specific)
67 #define SETUP_MODE_CHOOSE_SCORES_TYPE 17
68 #define SETUP_MODE_CHOOSE_GAME_SPEED 18
69 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 19
70 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 20
71 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 21
72 #define SETUP_MODE_CHOOSE_SCALING_TYPE 22
73 #define SETUP_MODE_CHOOSE_RENDERING 23
74 #define SETUP_MODE_CHOOSE_VSYNC 24
75 #define SETUP_MODE_CHOOSE_GRAPHICS 25
76 #define SETUP_MODE_CHOOSE_SOUNDS 26
77 #define SETUP_MODE_CHOOSE_MUSIC 27
78 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 28
79 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 29
80 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 30
81 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 31
82 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 32
83 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 33
84 #define SETUP_MODE_CHOOSE_TRANSPARENCY 34
85 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 35
86 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 36
87 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 37
88 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 38
89 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 39
91 #define MAX_SETUP_MODES 40
93 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
95 // setup screen titles
96 #define STR_SETUP_MAIN "Setup"
97 #define STR_SETUP_GAME "Game & Menu"
98 #define STR_SETUP_ENGINES "Game Engines"
99 #define STR_SETUP_EDITOR "Editor"
100 #define STR_SETUP_GRAPHICS "Graphics"
101 #define STR_SETUP_SOUND "Sound & Music"
102 #define STR_SETUP_ARTWORK "Custom Artwork"
103 #define STR_SETUP_INPUT "Input Devices"
104 #define STR_SETUP_TOUCH "Touch Controls"
105 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
106 #define STR_SETUP_EXIT "Exit"
107 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
109 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
110 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
111 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
112 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
113 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
114 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
115 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
116 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
117 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
118 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
119 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
120 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
121 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
122 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
123 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
124 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
125 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
126 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
127 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
129 // other screen text constants
130 #define STR_CHOOSE_TREE_EDIT "Edit"
131 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
132 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
134 #define TEXT_NEXT_PAGE "Press any key or button for next page"
135 #define TEXT_INFO_MENU "Press any key or button for info menu"
137 // for input setup functions
138 #define SETUPINPUT_SCREEN_POS_START 0
139 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
140 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
141 #define SETUPINPUT_SCREEN_POS_END 13
143 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
144 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
146 #define MAX_SETUP_TEXT_INPUT_LEN 28
148 // for various menu stuff
149 #define MENU_SCREEN_START_XPOS 1
150 #define MENU_SCREEN_START_YPOS 2
151 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
152 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
153 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
154 #define MENU_TITLE1_YPOS 8
155 #define MENU_TITLE2_YPOS 46
156 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
157 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
158 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
159 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
160 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
161 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
162 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
163 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
164 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
165 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
166 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
167 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
168 MENU_INFO_FONT_TITLE))
169 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
170 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
171 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
172 MENU_SCREEN_INFO_YSTART2 - \
174 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
175 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
176 MENU_SCREEN_INFO_YSTEP)
177 #define NUM_INFO_ELEMENTS_FROM_CONF \
178 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
179 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
180 MAX_MENU_ENTRIES_ON_SCREEN)
181 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
182 MAX_INFO_ELEMENTS_ON_SCREEN), \
183 NUM_INFO_ELEMENTS_FROM_CONF)
184 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
185 #define MAX_MENU_TEXT_LENGTH_BIG 13
186 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
188 // screen gadget identifiers
189 #define SCREEN_CTRL_ID_PREV_LEVEL 0
190 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
191 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
192 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
193 #define SCREEN_CTRL_ID_PREV_SCORE 4
194 #define SCREEN_CTRL_ID_NEXT_SCORE 5
195 #define SCREEN_CTRL_ID_PLAY_TAPE 6
196 #define SCREEN_CTRL_ID_FIRST_LEVEL 7
197 #define SCREEN_CTRL_ID_LAST_LEVEL 8
198 #define SCREEN_CTRL_ID_LEVEL_NUMBER 9
199 #define SCREEN_CTRL_ID_PREV_PLAYER 10
200 #define SCREEN_CTRL_ID_NEXT_PLAYER 11
201 #define SCREEN_CTRL_ID_INSERT_SOLUTION 12
202 #define SCREEN_CTRL_ID_PLAY_SOLUTION 13
203 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 14
204 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 15
205 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 16
206 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 17
207 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 18
209 #define NUM_SCREEN_MENUBUTTONS 19
211 #define SCREEN_CTRL_ID_SCROLL_UP 19
212 #define SCREEN_CTRL_ID_SCROLL_DOWN 20
213 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 21
214 #define SCREEN_CTRL_ID_NETWORK_SERVER 22
216 #define NUM_SCREEN_GADGETS 23
218 #define NUM_SCREEN_SCROLLBUTTONS 2
219 #define NUM_SCREEN_SCROLLBARS 1
220 #define NUM_SCREEN_TEXTINPUT 1
222 #define SCREEN_MASK_MAIN (1 << 0)
223 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
224 #define SCREEN_MASK_INPUT (1 << 2)
225 #define SCREEN_MASK_TOUCH (1 << 3)
226 #define SCREEN_MASK_TOUCH2 (1 << 4)
227 #define SCREEN_MASK_SCORES (1 << 5)
228 #define SCREEN_MASK_SCORES_INFO (1 << 6)
230 // graphic position and size values for buttons and scrollbars
231 #define SC_MENUBUTTON_XSIZE TILEX
232 #define SC_MENUBUTTON_YSIZE TILEY
234 #define SC_SCROLLBUTTON_XSIZE TILEX
235 #define SC_SCROLLBUTTON_YSIZE TILEY
237 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
239 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
240 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
241 SC_SCROLLBUTTON_YSIZE)
243 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
244 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
246 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
247 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
248 SC_SCROLLBUTTON_YSIZE)
250 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
251 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
252 SC_SCROLL_VERTICAL_YSIZE)
254 #define SC_BORDER_SIZE 14
257 // forward declarations of internal functions
258 static void HandleScreenGadgets(struct GadgetInfo *);
259 static void HandleSetupScreen_Generic(int, int, int, int, int);
260 static void HandleSetupScreen_Input(int, int, int, int, int);
261 static void CustomizeKeyboard(int);
262 static void ConfigureJoystick(int);
263 static void ConfigureVirtualButtons(void);
264 static void execSetupGame(void);
265 static void execSetupEngines(void);
266 static void execSetupGraphics(void);
267 static void execSetupSound(void);
268 static void execSetupTouch(void);
269 static void execSetupArtwork(void);
270 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
272 static void DrawChoosePlayerName(void);
273 static void DrawChooseLevelSet(void);
274 static void DrawChooseLevelNr(void);
275 static void DrawScoreInfo(int);
276 static void DrawScoreInfo_Content(int);
277 static void DrawInfoScreen(void);
278 static void DrawSetupScreen(void);
279 static void DrawTypeName(void);
281 static void DrawInfoScreen_NotAvailable(char *, char *);
282 static void DrawInfoScreen_HelpAnim(int, int, boolean);
283 static void DrawInfoScreen_HelpText(int, int, int, int);
284 static void HandleInfoScreen_Main(int, int, int, int, int);
285 static void HandleInfoScreen_TitleScreen(int, int, int);
286 static void HandleInfoScreen_Elements(int, int, int);
287 static void HandleInfoScreen_Music(int, int, int);
288 static void HandleInfoScreen_Credits(int, int, int);
289 static void HandleInfoScreen_Program(int, int, int);
290 static void HandleInfoScreen_Version(int);
292 static void ModifyGameSpeedIfNeeded(void);
293 static void DisableVsyncIfNeeded(void);
295 static void RedrawScreenMenuGadgets(int);
296 static void MapScreenMenuGadgets(int);
297 static void UnmapScreenMenuGadgets(int);
298 static void MapScreenGadgets(int);
299 static void UnmapScreenGadgets(void);
300 static void MapScreenTreeGadgets(TreeInfo *);
301 static void UnmapScreenTreeGadgets(void);
303 static void UpdateScreenMenuGadgets(int, boolean);
304 static void AdjustScoreInfoButtons_SelectScore(int, int, int);
305 static void AdjustScoreInfoButtons_PlayTape(int, int, boolean);
307 static boolean OfferUploadTapes(void);
308 static void execOfferUploadTapes(void);
310 static void DrawHallOfFame_setScoreEntries(void);
311 static void HandleHallOfFame_SelectLevel(int, int);
312 static char *getHallOfFameRankText(int, int);
313 static char *getHallOfFameScoreText(int, int);
315 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *);
317 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
319 static int info_mode = INFO_MODE_MAIN;
320 static int setup_mode = SETUP_MODE_MAIN;
322 static TreeInfo *window_sizes = NULL;
323 static TreeInfo *window_size_current = NULL;
325 static TreeInfo *scaling_types = NULL;
326 static TreeInfo *scaling_type_current = NULL;
328 static TreeInfo *rendering_modes = NULL;
329 static TreeInfo *rendering_mode_current = NULL;
331 static TreeInfo *vsync_modes = NULL;
332 static TreeInfo *vsync_mode_current = NULL;
334 static TreeInfo *scroll_delays = NULL;
335 static TreeInfo *scroll_delay_current = NULL;
337 static TreeInfo *snapshot_modes = NULL;
338 static TreeInfo *snapshot_mode_current = NULL;
340 static TreeInfo *scores_types = NULL;
341 static TreeInfo *scores_type_current = NULL;
343 static TreeInfo *game_speeds_normal = NULL;
344 static TreeInfo *game_speeds_extended = NULL;
345 static TreeInfo *game_speeds = NULL;
346 static TreeInfo *game_speed_current = NULL;
348 static TreeInfo *volumes_simple = NULL;
349 static TreeInfo *volume_simple_current = NULL;
351 static TreeInfo *volumes_loops = NULL;
352 static TreeInfo *volume_loops_current = NULL;
354 static TreeInfo *volumes_music = NULL;
355 static TreeInfo *volume_music_current = NULL;
357 static TreeInfo *touch_controls = NULL;
358 static TreeInfo *touch_control_current = NULL;
360 static TreeInfo *move_distances = NULL;
361 static TreeInfo *move_distance_current = NULL;
363 static TreeInfo *drop_distances = NULL;
364 static TreeInfo *drop_distance_current = NULL;
366 static TreeInfo *transparencies = NULL;
367 static TreeInfo *transparency_current = NULL;
369 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
370 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
372 static TreeInfo *player_name = NULL;
373 static TreeInfo *player_name_current = NULL;
375 static TreeInfo *level_number = NULL;
376 static TreeInfo *level_number_current = NULL;
378 static TreeInfo *score_entries = NULL;
379 static TreeInfo *score_entry_current = NULL;
381 static struct ValueTextInfo window_sizes_list[] =
386 { 100, "100 % (Default)" },
399 static struct StringValueTextInfo scaling_types_list[] =
401 { SCALING_QUALITY_NEAREST, "Off" },
402 { SCALING_QUALITY_LINEAR, "Linear" },
403 { SCALING_QUALITY_BEST, "Anisotropic" },
408 static struct StringValueTextInfo rendering_modes_list[] =
410 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
411 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
413 // this mode may work under certain conditions, but does not work on Windows
414 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
416 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
421 static struct StringValueTextInfo vsync_modes_list[] =
423 { STR_VSYNC_MODE_OFF, "Off" },
424 { STR_VSYNC_MODE_NORMAL, "Normal" },
425 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
430 static struct StringValueTextInfo scores_types_list[] =
432 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
433 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
434 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
439 static struct ValueTextInfo game_speeds_list_normal[] =
450 static struct ValueTextInfo game_speeds_list_extended[] =
452 { 1000, "1 fps (Extremely Slow)" },
457 { 29, "35 fps (Original Supaplex)" },
459 { 20, "50 fps (=== Normal Speed ===)" },
460 { 16, "60 fps (60 Hz VSync Speed)" },
461 { 14, "70 fps (Maximum Supaplex)" },
465 { 1, "1000 fps (Extremely Fast)" },
470 static struct ValueTextInfo *game_speeds_list;
472 static struct ValueTextInfo scroll_delays_list[] =
474 { 0, "0 Tiles (No Scroll Delay)" },
477 { 3, "3 Tiles (Default)" },
482 { 8, "8 Tiles (Maximum Scroll Delay)"},
487 static struct StringValueTextInfo snapshot_modes_list[] =
489 { STR_SNAPSHOT_MODE_OFF, "Off" },
490 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
491 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
492 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
497 static struct ValueTextInfo volumes_list[] =
517 static struct StringValueTextInfo touch_controls_list[] =
519 { TOUCH_CONTROL_OFF, "Off" },
520 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
521 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
522 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
527 static struct ValueTextInfo distances_list[] =
542 static struct ValueTextInfo transparencies_list[] =
544 { 0, "0 % (Opaque)" },
554 { 100, "100 % (Invisible)" },
559 static struct ValueTextInfo grid_sizes_list[] =
595 static int align_xoffset = 0;
596 static int align_yoffset = 0;
598 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
599 (s) <= GAME_MODE_SETUP ? (s) : \
600 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
602 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
603 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
605 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
606 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
607 (i) <= INFO_MODE_LEVELSET ? (i) : \
610 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
611 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
612 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
613 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
614 SETUP_MODE_CHOOSE_ARTWORK : \
615 SETUP_MODE_CHOOSE_OTHER)
617 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
618 menu.draw_xoffset[GAME_MODE_INFO] : \
619 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
620 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
621 menu.draw_yoffset[GAME_MODE_INFO] : \
622 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
623 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
624 menu.extra_spacing[GAME_MODE_INFO] : \
625 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
627 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
628 menu.draw_xoffset[GAME_MODE_SETUP] : \
629 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
630 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
631 menu.draw_yoffset[GAME_MODE_SETUP] : \
632 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
633 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
634 menu.extra_spacing[GAME_MODE_SETUP] : \
635 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
637 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
639 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
641 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
642 DRAW_XOFFSET_INFO(info_mode) : \
643 (s) == GAME_MODE_SETUP ? \
644 DRAW_XOFFSET_SETUP(setup_mode) : \
645 menu.draw_xoffset[DRAW_MODE(s)])
646 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
647 DRAW_YOFFSET_INFO(info_mode) : \
648 (s) == GAME_MODE_SETUP ? \
649 DRAW_YOFFSET_SETUP(setup_mode) : \
650 menu.draw_yoffset[DRAW_MODE(s)])
651 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
652 EXTRA_SPACING_INFO(info_mode) : \
653 (s) == GAME_MODE_SETUP ? \
654 EXTRA_SPACING_SETUP(setup_mode) : \
655 (s) == GAME_MODE_SCORES ? \
656 EXTRA_SPACING_SCORES(info_mode) : \
657 menu.extra_spacing[DRAW_MODE(s)])
659 #define mSX (SX + DRAW_XOFFSET(game_status))
660 #define mSY (SY + DRAW_YOFFSET(game_status))
662 #define amSX (mSX + align_xoffset)
663 #define amSY (mSY + align_yoffset)
665 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
666 menu.list_size[game_status] : \
667 MAX_MENU_ENTRIES_ON_SCREEN)
669 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
670 NUM_MENU_ENTRIES_ON_SCREEN)
673 // title display and control definitions
675 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
676 2 * MAX_NUM_TITLE_MESSAGES)
678 #define NO_DIRECT_LEVEL_SELECT (-1)
681 static int num_title_screens = 0;
683 struct TitleControlInfo
692 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
695 // credits screens definitions
697 static int num_credits_screens = 0;
698 static boolean use_global_credits_screens = FALSE;
701 // program info screens definitions
703 static int num_program_info_screens = 0;
706 // main menu display and control definitions
708 #define MAIN_CONTROL_NAME 0
709 #define MAIN_CONTROL_LEVELS 1
710 #define MAIN_CONTROL_SCORES 2
711 #define MAIN_CONTROL_EDITOR 3
712 #define MAIN_CONTROL_INFO 4
713 #define MAIN_CONTROL_GAME 5
714 #define MAIN_CONTROL_SETUP 6
715 #define MAIN_CONTROL_QUIT 7
716 #define MAIN_CONTROL_PREV_LEVEL 8
717 #define MAIN_CONTROL_NEXT_LEVEL 9
718 #define MAIN_CONTROL_FIRST_LEVEL 10
719 #define MAIN_CONTROL_LAST_LEVEL 11
720 #define MAIN_CONTROL_LEVEL_NUMBER 12
721 #define MAIN_CONTROL_LEVEL_INFO_1 13
722 #define MAIN_CONTROL_LEVEL_INFO_2 14
723 #define MAIN_CONTROL_LEVEL_NAME 15
724 #define MAIN_CONTROL_LEVEL_AUTHOR 16
725 #define MAIN_CONTROL_LEVEL_YEAR 17
726 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
727 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
728 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
729 #define MAIN_CONTROL_TITLE_1 21
730 #define MAIN_CONTROL_TITLE_2 22
731 #define MAIN_CONTROL_TITLE_3 23
733 static char str_main_text_name[10];
734 static char str_main_text_first_level[10];
735 static char str_main_text_last_level[10];
736 static char str_main_text_level_number[10];
738 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
740 static char *main_text_name = str_main_text_name;
741 static char *main_text_first_level = str_main_text_first_level;
742 static char *main_text_last_level = str_main_text_last_level;
743 static char *main_text_level_number = str_main_text_level_number;
744 static char *main_text_levels = "Levelset";
745 static char *main_text_scores = "Hall Of Fame";
746 static char *main_text_editor = "Level Creator";
747 static char *main_text_info = "Info Screen";
748 static char *main_text_game = "Start Game";
749 static char *main_text_setup = "Setup";
750 static char *main_text_quit = "Quit";
751 static char *main_text_level_name = level.name;
752 static char *main_text_level_author = level.author;
753 static char *main_text_level_year = NULL;
754 static char *main_text_level_imported_from = NULL;
755 static char *main_text_level_imported_by = NULL;
756 static char *main_text_level_tested_by = NULL;
757 static char *main_text_title_1 = NULL;
758 static char *main_text_title_2 = NULL;
759 static char *main_text_title_3 = NULL;
761 extern char debug_xsn_mode[];
763 struct MainControlInfo
767 struct MenuPosInfo *pos_button;
770 struct TextPosInfo *pos_text;
773 struct TextPosInfo *pos_input;
777 static struct MainControlInfo main_controls[] =
781 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
782 &menu.main.text.name, &main_text_name,
783 &menu.main.input.name, &setup.player_name,
787 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
788 &menu.main.text.levels, &main_text_levels,
793 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
794 &menu.main.text.scores, &main_text_scores,
799 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
800 &menu.main.text.editor, &main_text_editor,
805 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
806 &menu.main.text.info, &main_text_info,
811 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
812 &menu.main.text.game, &main_text_game,
817 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
818 &menu.main.text.setup, &main_text_setup,
823 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
824 &menu.main.text.quit, &main_text_quit,
828 MAIN_CONTROL_PREV_LEVEL,
834 MAIN_CONTROL_NEXT_LEVEL,
840 MAIN_CONTROL_FIRST_LEVEL,
842 &menu.main.text.first_level, &main_text_first_level,
846 MAIN_CONTROL_LAST_LEVEL,
848 &menu.main.text.last_level, &main_text_last_level,
852 MAIN_CONTROL_LEVEL_NUMBER,
854 &menu.main.text.level_number, &main_text_level_number,
858 MAIN_CONTROL_LEVEL_INFO_1,
860 &menu.main.text.level_info_1, NULL,
864 MAIN_CONTROL_LEVEL_INFO_2,
866 &menu.main.text.level_info_2, NULL,
870 MAIN_CONTROL_LEVEL_NAME,
872 &menu.main.text.level_name, &main_text_level_name,
876 MAIN_CONTROL_LEVEL_AUTHOR,
878 &menu.main.text.level_author, &main_text_level_author,
882 MAIN_CONTROL_LEVEL_YEAR,
884 &menu.main.text.level_year, &main_text_level_year,
888 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
890 &menu.main.text.level_imported_from, &main_text_level_imported_from,
894 MAIN_CONTROL_LEVEL_IMPORTED_BY,
896 &menu.main.text.level_imported_by, &main_text_level_imported_by,
900 MAIN_CONTROL_LEVEL_TESTED_BY,
902 &menu.main.text.level_tested_by, &main_text_level_tested_by,
906 MAIN_CONTROL_TITLE_1,
908 &menu.main.text.title_1, &main_text_title_1,
912 MAIN_CONTROL_TITLE_2,
914 &menu.main.text.title_2, &main_text_title_2,
918 MAIN_CONTROL_TITLE_3,
920 &menu.main.text.title_3, &main_text_title_3,
933 static int getTitleScreenGraphic(int nr, boolean initial)
935 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
938 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
940 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
944 static int getTitleScreenGameMode(boolean initial)
946 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
950 static int getTitleMessageGameMode(boolean initial)
952 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
955 static int getTitleAnimMode(struct TitleControlInfo *tci)
957 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
959 return base + tci->local_nr;
963 static int getTitleScreenBackground(boolean initial)
965 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
970 static int getTitleMessageBackground(int nr, boolean initial)
972 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
976 static int getTitleBackground(int nr, boolean initial, boolean is_image)
978 int base = (is_image ?
979 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
980 IMG_BACKGROUND_TITLESCREEN_1) :
981 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
982 IMG_BACKGROUND_TITLEMESSAGE_1));
983 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
984 IMG_BACKGROUND_TITLE);
985 int graphic_local = base + nr;
987 if (graphic_info[graphic_local].bitmap != NULL)
988 return graphic_local;
990 if (graphic_info[graphic_global].bitmap != NULL)
991 return graphic_global;
993 return IMG_UNDEFINED;
996 static int getTitleSound(struct TitleControlInfo *tci)
998 boolean is_image = tci->is_image;
999 int initial = tci->initial;
1000 int nr = tci->local_nr;
1001 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1002 int base = (is_image ?
1003 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
1004 SND_BACKGROUND_TITLESCREEN_1) :
1005 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1006 SND_BACKGROUND_TITLEMESSAGE_1));
1007 int sound_global = menu.sound[mode];
1008 int sound_local = base + nr;
1011 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
1012 nr, initial, is_image,
1013 sound_global, getSoundListEntry(sound_global)->filename,
1014 sound_local, getSoundListEntry(sound_local)->filename);
1017 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1020 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1021 return sound_global;
1023 return SND_UNDEFINED;
1026 static int getTitleMusic(struct TitleControlInfo *tci)
1028 boolean is_image = tci->is_image;
1029 int initial = tci->initial;
1030 int nr = tci->local_nr;
1031 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1032 int base = (is_image ?
1033 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1034 MUS_BACKGROUND_TITLESCREEN_1) :
1035 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1036 MUS_BACKGROUND_TITLEMESSAGE_1));
1037 int music_global = menu.music[mode];
1038 int music_local = base + nr;
1041 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1042 nr, initial, is_image,
1043 music_global, getMusicListEntry(music_global)->filename,
1044 music_local, getMusicListEntry(music_local)->filename);
1047 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1050 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1051 return music_global;
1053 return MUS_UNDEFINED;
1056 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1058 boolean is_image = tci->is_image;
1059 boolean initial = tci->initial;
1060 boolean first = tci->first;
1061 int nr = tci->local_nr;
1062 struct TitleMessageInfo tmi;
1063 struct TitleFadingInfo ti;
1065 tmi = (is_image ? (initial ? (first ?
1066 titlescreen_initial_first[nr] :
1067 titlescreen_initial[nr])
1069 titlescreen_first[nr] :
1071 : (initial ? (first ?
1072 titlemessage_initial_first[nr] :
1073 titlemessage_initial[nr])
1075 titlemessage_first[nr] :
1076 titlemessage[nr])));
1078 ti.fade_mode = tmi.fade_mode;
1079 ti.fade_delay = tmi.fade_delay;
1080 ti.post_delay = tmi.post_delay;
1081 ti.auto_delay = tmi.auto_delay;
1082 ti.auto_delay_unit = tmi.auto_delay_unit;
1087 static int compareTitleControlInfo(const void *object1, const void *object2)
1089 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1090 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1093 if (tci1->initial != tci2->initial)
1094 compare_result = (tci1->initial ? -1 : +1);
1095 else if (tci1->sort_priority != tci2->sort_priority)
1096 compare_result = tci1->sort_priority - tci2->sort_priority;
1097 else if (tci1->is_image != tci2->is_image)
1098 compare_result = (tci1->is_image ? -1 : +1);
1100 compare_result = tci1->local_nr - tci2->local_nr;
1102 return compare_result;
1105 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1107 int nr, int sort_priority)
1109 title_controls[num_title_screens].is_image = is_image;
1110 title_controls[num_title_screens].initial = initial;
1111 title_controls[num_title_screens].local_nr = nr;
1112 title_controls[num_title_screens].sort_priority = sort_priority;
1114 title_controls[num_title_screens].first = FALSE; // will be set later
1116 num_title_screens++;
1119 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1123 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1125 int graphic = getTitleScreenGraphic(i, initial);
1126 Bitmap *bitmap = graphic_info[graphic].bitmap;
1127 int sort_priority = graphic_info[graphic].sort_priority;
1130 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1133 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1135 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1136 char *filename = getLevelSetTitleMessageFilename(i, initial);
1137 int sort_priority = tmi->sort_priority;
1139 if (filename != NULL)
1140 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1144 static void InitializeTitleControls(boolean show_title_initial)
1146 num_title_screens = 0;
1148 // 1st step: initialize title screens for game start (only when starting)
1149 if (show_title_initial)
1150 InitializeTitleControls_CheckTitleInfo(TRUE);
1152 // 2nd step: initialize title screens for current level set
1153 InitializeTitleControls_CheckTitleInfo(FALSE);
1155 // sort title screens according to sort_priority and title number
1156 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1157 compareTitleControlInfo);
1159 // mark first title screen
1160 title_controls[0].first = TRUE;
1163 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1165 return (pos != NULL && pos->x != -1 && pos->y != -1);
1168 static boolean visibleTextPos(struct TextPosInfo *pos)
1170 return (pos != NULL && pos->x != -1 && pos->y != -1);
1173 static void InitializeMainControls(void)
1175 boolean local_team_mode = (!network.enabled && setup.team_mode);
1178 // set main control text values to dynamically determined values
1179 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1181 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1182 menu.main.text.first_level.size));
1183 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1184 menu.main.text.last_level.size));
1185 strcpy(main_text_level_number, int2str(level_nr,
1186 menu.main.text.level_number.size));
1188 main_text_level_year = leveldir_current->year;
1189 main_text_level_imported_from = leveldir_current->imported_from;
1190 main_text_level_imported_by = leveldir_current->imported_by;
1191 main_text_level_tested_by = leveldir_current->tested_by;
1193 main_text_title_1 = getConfigProgramTitleString();
1194 main_text_title_2 = getConfigProgramCopyrightString();
1195 main_text_title_3 = getConfigProgramCompanyString();
1197 // set main control screen positions to dynamically determined values
1198 for (i = 0; main_controls[i].nr != -1; i++)
1200 struct MainControlInfo *mci = &main_controls[i];
1202 struct MenuPosInfo *pos_button = mci->pos_button;
1203 struct TextPosInfo *pos_text = mci->pos_text;
1204 struct TextPosInfo *pos_input = mci->pos_input;
1205 char *text = (mci->text ? *mci->text : NULL);
1206 char *input = (mci->input ? *mci->input : NULL);
1207 int button_graphic = mci->button_graphic;
1208 int font_text = (pos_text ? pos_text->font : -1);
1209 int font_input = (pos_input ? pos_input->font : -1);
1211 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1212 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1213 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1214 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1215 int text_chars = (text != NULL ? strlen(text) : 0);
1216 int input_chars = (input != NULL ? strlen(input) : 0);
1219 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1221 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1222 int text_width = font_text_width * text_chars;
1223 int text_height = font_text_height;
1224 int input_width = font_input_width * input_chars;
1225 int input_height = font_input_height;
1227 if (nr == MAIN_CONTROL_NAME)
1229 menu.main.input.name.width = input_width;
1230 menu.main.input.name.height = input_height;
1233 if (pos_button != NULL) // (x/y may be -1/-1 here)
1235 pos_button->width = button_width;
1236 pos_button->height = button_height;
1239 if (pos_text != NULL) // (x/y may be -1/-1 here)
1241 // calculate text size -- needed for text alignment
1242 boolean calculate_text_size = (text != NULL);
1244 if (pos_text->width == -1 || calculate_text_size)
1245 pos_text->width = text_width;
1246 if (pos_text->height == -1 || calculate_text_size)
1247 pos_text->height = text_height;
1249 if (visibleMenuPos(pos_button))
1251 if (pos_text->x == -1)
1252 pos_text->x = pos_button->x + pos_button->width;
1253 if (pos_text->y == -1)
1255 pos_button->y + (pos_button->height - pos_text->height) / 2;
1259 if (pos_input != NULL) // (x/y may be -1/-1 here)
1261 if (visibleTextPos(pos_text))
1263 if (pos_input->x == -1)
1264 pos_input->x = pos_text->x + pos_text->width;
1265 if (pos_input->y == -1)
1266 pos_input->y = pos_text->y;
1269 if (pos_input->width == -1)
1270 pos_input->width = input_width;
1271 if (pos_input->height == -1)
1272 pos_input->height = input_height;
1277 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1278 int graphic, boolean pressed)
1280 struct GraphicInfo *g = &graphic_info[graphic];
1283 int xoffset = (pressed ? g->pressed_xoffset : 0);
1284 int yoffset = (pressed ? g->pressed_yoffset : 0);
1286 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1288 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1289 g->width, g->height, dst_x, dst_y);
1292 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1293 boolean active_input,
1294 boolean pressed_button)
1298 for (i = 0; main_controls[i].nr != -1; i++)
1300 struct MainControlInfo *mci = &main_controls[i];
1302 if (mci->nr == nr || nr == -1)
1304 struct MenuPosInfo *pos_button = mci->pos_button;
1305 struct TextPosInfo *pos_text = mci->pos_text;
1306 struct TextPosInfo *pos_input = mci->pos_input;
1307 char *text = (mci->text ? *mci->text : NULL);
1308 char *input = (mci->input ? *mci->input : NULL);
1309 int button_graphic = mci->button_graphic;
1310 int font_text = (pos_text ? pos_text->font : -1);
1311 int font_input = (pos_input ? pos_input->font : -1);
1315 button_graphic = BUTTON_ACTIVE(button_graphic);
1316 font_text = FONT_ACTIVE(font_text);
1321 font_input = FONT_ACTIVE(font_input);
1324 if (visibleMenuPos(pos_button))
1326 struct MenuPosInfo *pos = pos_button;
1327 int x = mSX + pos->x;
1328 int y = mSY + pos->y;
1330 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1331 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1334 if (visibleTextPos(pos_text) && text != NULL)
1336 struct TextPosInfo *pos = pos_text;
1337 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1338 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1341 // (check why/if this is needed)
1342 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1344 DrawText(x, y, text, font_text);
1347 if (visibleTextPos(pos_input) && input != NULL)
1349 struct TextPosInfo *pos = pos_input;
1350 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1351 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1354 // (check why/if this is needed)
1355 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1357 DrawText(x, y, input, font_input);
1363 static void DrawCursorAndText_Main(int nr, boolean active_text,
1364 boolean pressed_button)
1366 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1370 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1371 boolean pressed_button)
1373 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1377 static struct MainControlInfo *getMainControlInfo(int nr)
1381 for (i = 0; main_controls[i].nr != -1; i++)
1382 if (main_controls[i].nr == nr)
1383 return &main_controls[i];
1388 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1393 int rect_x = ALIGNED_TEXT_XPOS(rect);
1394 int rect_y = ALIGNED_TEXT_YPOS(rect);
1396 return (x >= rect_x && x < rect_x + rect->width &&
1397 y >= rect_y && y < rect_y + rect->height);
1400 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1405 int rect_x = ALIGNED_TEXT_XPOS(rect);
1406 int rect_y = ALIGNED_TEXT_YPOS(rect);
1409 Debug("screens:insideTextPosRect",
1410 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1411 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1412 (x >= rect_x && x < rect_x + rect->width &&
1413 y >= rect_y && y < rect_y + rect->height));
1416 return (x >= rect_x && x < rect_x + rect->width &&
1417 y >= rect_y && y < rect_y + rect->height);
1420 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1422 int rect_width = preview->xsize * preview->tile_size;
1423 int rect_height = preview->ysize * preview->tile_size;
1424 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1425 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1427 return (x >= rect_x && x < rect_x + rect_width &&
1428 y >= rect_y && y < rect_y + rect_height);
1431 static void AdjustScrollbar(int id, int items_max, int items_visible,
1434 struct GadgetInfo *gi = screen_gadget[id];
1436 if (item_position > items_max - items_visible)
1437 item_position = items_max - items_visible;
1439 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1440 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1441 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1444 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1446 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1450 static void clearMenuListArea(void)
1452 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1454 // correct scrollbar position if placed outside menu (playfield) area
1455 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1456 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1458 // clear menu list area, but not title or scrollbar
1459 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1460 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1463 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1465 static int cursor_array[MAX_LEV_FIELDY];
1466 int x = amSX + TILEX * xpos;
1467 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1472 cursor_array[ypos] = graphic;
1474 graphic = cursor_array[ypos];
1478 graphic = BUTTON_ACTIVE(graphic);
1480 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1481 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1484 static void initCursor(int ypos, int graphic)
1486 drawCursorExt(0, ypos, FALSE, graphic);
1489 static void drawCursor(int ypos, boolean active)
1491 drawCursorExt(0, ypos, active, -1);
1494 static void drawCursorXY(int xpos, int ypos, int graphic)
1496 drawCursorExt(xpos, ypos, FALSE, graphic);
1499 static void drawChooseTreeCursor(int ypos, boolean active)
1501 drawCursorExt(0, ypos, active, -1);
1504 static int getChooseTreeEditFont(boolean active)
1506 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1509 static int getChooseTreeEditXPos(int pos)
1511 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1512 int xoffset = (has_scrollbar ? -1 : 0);
1513 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1514 int sx = amSX + xpos * TILEX;
1515 int font_nr = getChooseTreeEditFont(FALSE);
1516 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1518 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1521 static int getChooseTreeEditYPos(int ypos_raw)
1523 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1524 int sy = amSY + ypos * TILEY;
1529 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1531 int sx = getChooseTreeEditXPos(POS_LEFT);
1532 int sy = getChooseTreeEditYPos(ypos_raw);
1533 int font_nr = getChooseTreeEditFont(active);
1535 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1538 static void DrawHeadline(void)
1540 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1541 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1544 static void DrawTitleScreenImage(int nr, boolean initial)
1546 int graphic = getTitleScreenGraphic(nr, initial);
1547 Bitmap *bitmap = graphic_info[graphic].bitmap;
1548 int width = graphic_info[graphic].width;
1549 int height = graphic_info[graphic].height;
1550 int src_x = graphic_info[graphic].src_x;
1551 int src_y = graphic_info[graphic].src_y;
1557 if (width > WIN_XSIZE)
1559 // image width too large for window => center image horizontally
1560 src_x = (width - WIN_XSIZE) / 2;
1564 if (height > WIN_YSIZE)
1566 // image height too large for window => center image vertically
1567 src_y = (height - WIN_YSIZE) / 2;
1571 // always display title screens centered
1572 dst_x = (WIN_XSIZE - width) / 2;
1573 dst_y = (WIN_YSIZE - height) / 2;
1575 SetDrawBackgroundMask(REDRAW_ALL);
1576 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1578 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1580 if (DrawingOnBackground(dst_x, dst_y))
1581 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1583 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1585 redraw_mask = REDRAW_ALL;
1588 static void DrawTitleScreenMessage(int nr, boolean initial)
1590 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1591 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1593 if (filename == NULL)
1596 // force TITLE font on title message screen
1597 SetFontStatus(getTitleMessageGameMode(initial));
1599 // if chars *and* width set to "-1", automatically determine width
1600 if (tmi->chars == -1 && tmi->width == -1)
1601 tmi->width = viewport.window[game_status].width;
1603 // if lines *and* height set to "-1", automatically determine height
1604 if (tmi->lines == -1 && tmi->height == -1)
1605 tmi->height = viewport.window[game_status].height;
1607 // if chars set to "-1", automatically determine by text and font width
1608 if (tmi->chars == -1)
1609 tmi->chars = tmi->width / getFontWidth(tmi->font);
1611 tmi->width = tmi->chars * getFontWidth(tmi->font);
1613 // if lines set to "-1", automatically determine by text and font height
1614 if (tmi->lines == -1)
1615 tmi->lines = tmi->height / getFontHeight(tmi->font);
1617 tmi->height = tmi->lines * getFontHeight(tmi->font);
1619 // if x set to "-1", automatically determine by width and alignment
1621 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1623 // if y set to "-1", automatically determine by height and alignment
1625 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1627 SetDrawBackgroundMask(REDRAW_ALL);
1628 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1630 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1632 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1633 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1634 tmi->autowrap, tmi->centered, tmi->parse_comments);
1639 static void DrawTitleScreen(void)
1641 KeyboardAutoRepeatOff();
1643 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1646 static boolean CheckTitleScreen(boolean levelset_has_changed)
1648 static boolean show_title_initial = TRUE;
1649 boolean show_titlescreen = FALSE;
1651 // needed to be able to skip title screen, if no image or message defined
1652 InitializeTitleControls(show_title_initial);
1654 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1655 show_titlescreen = TRUE;
1657 // show initial title images and messages only once at program start
1658 show_title_initial = FALSE;
1660 return (show_titlescreen && num_title_screens > 0);
1663 void DrawMainMenu(void)
1665 static LevelDirTree *leveldir_last_valid = NULL;
1666 boolean levelset_has_changed = FALSE;
1667 int fade_mask = REDRAW_FIELD;
1669 LimitScreenUpdates(FALSE);
1671 FadeSetLeaveScreen();
1673 // do not fade out here -- function may continue and fade on editor screen
1676 FadeMenuSoundsAndMusic();
1678 ExpireSoundLoops(FALSE);
1680 KeyboardAutoRepeatOn();
1682 audio.sound_deactivated = FALSE;
1686 // needed if last screen was the playing screen, invoked from level editor
1687 if (level_editor_test_game)
1689 CloseDoor(DOOR_CLOSE_ALL);
1691 SetGameStatus(GAME_MODE_EDITOR);
1698 // needed if last screen was the playing screen, invoked from hall of fame
1699 if (score_info_tape_play)
1701 CloseDoor(DOOR_CLOSE_ALL);
1703 SetGameStatus(GAME_MODE_SCOREINFO);
1705 DrawScoreInfo(scores.last_entry_nr);
1710 // leveldir_current may be invalid (level group, parent link, node copy)
1711 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1713 if (leveldir_current != leveldir_last_valid)
1715 UpdateLastPlayedLevels_TreeInfo();
1717 levelset_has_changed = TRUE;
1720 // store valid level series information
1721 leveldir_last_valid = leveldir_current;
1723 // needed if last screen (level choice) changed graphics, sounds or music
1724 ReloadCustomArtwork(0);
1726 if (CheckTitleScreen(levelset_has_changed))
1728 SetGameStatus(GAME_MODE_TITLE);
1735 if (redraw_mask & REDRAW_ALL)
1736 fade_mask = REDRAW_ALL;
1739 fade_mask = REDRAW_ALL;
1743 // needed if different viewport properties defined for menues
1744 ChangeViewportPropertiesIfNeeded();
1746 SetDrawtoField(DRAW_TO_BACKBUFFER);
1748 // level_nr may have been set to value over handicap with level editor
1749 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1750 level_nr = leveldir_current->handicap_level;
1752 LoadLevel(level_nr);
1753 LoadScore(level_nr);
1755 SaveLevelSetup_SeriesInfo();
1757 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1758 SetDrawDeactivationMask(REDRAW_NONE);
1759 SetDrawBackgroundMask(REDRAW_FIELD);
1761 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1764 if (fade_mask == REDRAW_ALL)
1765 RedrawGlobalBorder();
1770 InitializeMainControls();
1772 DrawCursorAndText_Main(-1, FALSE, FALSE);
1773 DrawPreviewLevelInitial();
1774 DrawNetworkPlayers();
1776 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1779 if (TAPE_IS_EMPTY(tape))
1781 DrawCompleteVideoDisplay();
1783 PlayMenuSoundsAndMusic();
1785 // create gadgets for main menu screen
1786 FreeScreenGadgets();
1787 CreateScreenGadgets();
1789 // may be required if audio buttons shown on tape and changed in setup menu
1791 CreateGameButtons();
1793 // map gadgets for main menu screen
1795 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1796 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1798 // copy actual game door content to door double buffer for OpenDoor()
1799 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1800 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1802 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1804 DrawMaskedBorder(fade_mask);
1809 // update screen area with special editor door
1810 redraw_mask |= REDRAW_ALL;
1813 SetMouseCursor(CURSOR_DEFAULT);
1815 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1817 SyncEmscriptenFilesystem();
1819 // needed once after program start or after user change
1820 CheckApiServerTasks();
1823 static void gotoTopLevelDir(void)
1825 // move upwards until inside (but not above) top level directory
1826 while (leveldir_current->node_parent &&
1827 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1829 // write a "path" into level tree for easy navigation to last level
1830 if (leveldir_current->node_parent->node_group->cl_first == -1)
1832 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1833 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1834 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1835 int cl_first, cl_cursor;
1837 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1838 cl_cursor = leveldir_pos - cl_first;
1840 leveldir_current->node_parent->node_group->cl_first = cl_first;
1841 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1844 leveldir_current = leveldir_current->node_parent;
1848 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1850 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1852 return (use_frame_counter ? video.frame_counter : Counter());
1855 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1856 struct TitleFadingInfo *fi)
1858 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1861 static void ResetTitleAutoDelay(unsigned int *counter_var,
1862 struct TitleFadingInfo *fi)
1864 *counter_var = getAutoDelayCounter(fi);
1867 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1869 static unsigned int title_delay = 0;
1870 static int title_screen_nr = 0;
1871 static int last_sound = -1, last_music = -1;
1872 boolean return_to_main_menu = FALSE;
1873 struct TitleControlInfo *tci;
1876 if (button == MB_MENU_INITIALIZE)
1879 title_screen_nr = 0;
1880 tci = &title_controls[title_screen_nr];
1882 SetAnimStatus(getTitleAnimMode(tci));
1884 last_sound = SND_UNDEFINED;
1885 last_music = MUS_UNDEFINED;
1887 if (num_title_screens != 0)
1889 FadeSetEnterScreen();
1891 // use individual title fading instead of global "enter screen" fading
1892 fading = getTitleFading(tci);
1895 if (game_status_last_screen == GAME_MODE_INFO)
1897 if (num_title_screens == 0)
1899 // switch game mode from title screen mode back to info screen mode
1900 SetGameStatus(GAME_MODE_INFO);
1902 // store that last screen was info screen, not main menu screen
1903 game_status_last_screen = GAME_MODE_INFO;
1905 DrawInfoScreen_NotAvailable("Title screen information:",
1906 "No title screen for this level set.");
1911 FadeMenuSoundsAndMusic();
1913 FadeOut(REDRAW_ALL);
1915 // title screens may have different window size
1916 ChangeViewportPropertiesIfNeeded();
1918 // only required to update logic for redrawing global border
1922 DrawTitleScreenImage(tci->local_nr, tci->initial);
1924 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1926 sound = getTitleSound(tci);
1927 music = getTitleMusic(tci);
1929 if (sound != last_sound)
1930 PlayMenuSoundExt(sound);
1931 if (music != last_music)
1932 PlayMenuMusicExt(music);
1937 SetMouseCursor(CURSOR_NONE);
1941 ResetTitleAutoDelay(&title_delay, &fading);
1946 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1947 button = MB_MENU_CHOICE;
1949 if (button == MB_MENU_LEAVE)
1951 return_to_main_menu = TRUE;
1953 else if (button == MB_MENU_CHOICE || dx)
1955 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1957 SetGameStatus(GAME_MODE_INFO);
1959 info_mode = INFO_MODE_MAIN;
1967 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
1969 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
1971 tci = &title_controls[title_screen_nr];
1973 SetAnimStatus(getTitleAnimMode(tci));
1975 sound = getTitleSound(tci);
1976 music = getTitleMusic(tci);
1978 if (last_sound != SND_UNDEFINED && sound != last_sound)
1979 FadeSound(last_sound);
1980 if (last_music != MUS_UNDEFINED && music != last_music)
1983 fading = getTitleFading(tci);
1985 FadeOut(REDRAW_ALL);
1988 DrawTitleScreenImage(tci->local_nr, tci->initial);
1990 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1992 sound = getTitleSound(tci);
1993 music = getTitleMusic(tci);
1995 if (sound != last_sound)
1996 PlayMenuSoundExt(sound);
1997 if (music != last_music)
1998 PlayMenuMusicExt(music);
2005 ResetTitleAutoDelay(&title_delay, &fading);
2009 FadeMenuSoundsAndMusic();
2011 return_to_main_menu = TRUE;
2015 if (return_to_main_menu)
2017 SetMouseCursor(CURSOR_DEFAULT);
2019 // force full menu screen redraw after displaying title screens
2020 redraw_mask = REDRAW_ALL;
2022 if (game_status_last_screen == GAME_MODE_INFO)
2024 SetGameStatus(GAME_MODE_INFO);
2026 info_mode = INFO_MODE_MAIN;
2030 else // default: return to main menu
2032 SetGameStatus(GAME_MODE_MAIN);
2039 static void HandleMainMenu_ToggleTeamMode(void)
2041 setup.team_mode = !setup.team_mode;
2043 InitializeMainControls();
2044 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2046 DrawPreviewPlayers();
2049 static void HandleMainMenu_SelectLevel(int step, int direction,
2050 int selected_level_nr)
2052 int old_level_nr = level_nr;
2055 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2056 new_level_nr = selected_level_nr;
2058 new_level_nr = old_level_nr + step * direction;
2060 if (new_level_nr < leveldir_current->first_level)
2061 new_level_nr = leveldir_current->first_level;
2062 if (new_level_nr > leveldir_current->last_level)
2063 new_level_nr = leveldir_current->last_level;
2065 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2067 // skipping levels is only allowed when trying to skip single level
2068 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2069 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2071 leveldir_current->handicap_level++;
2072 SaveLevelSetup_SeriesInfo();
2075 new_level_nr = leveldir_current->handicap_level;
2078 if (new_level_nr != old_level_nr)
2080 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2082 PlaySound(SND_MENU_ITEM_SELECTING);
2084 level_nr = new_level_nr;
2086 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2087 int2str(level_nr, menu.main.text.level_number.size),
2088 mci->pos_text->font);
2090 LoadLevel(level_nr);
2091 DrawPreviewLevelInitial();
2095 DrawCompleteVideoDisplay();
2097 SaveLevelSetup_SeriesInfo();
2099 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2101 // force redraw of playfield area (may be reset at this point)
2102 redraw_mask |= REDRAW_FIELD;
2106 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2108 static int choice = MAIN_CONTROL_GAME;
2109 static boolean button_pressed_last = FALSE;
2110 boolean button_pressed = FALSE;
2112 int i = 0; // needed to prevent compiler warning due to bad code below
2114 if (button == MB_MENU_INITIALIZE)
2116 DrawCursorAndText_Main(choice, TRUE, FALSE);
2121 if (mx || my) // mouse input
2125 for (i = 0; main_controls[i].nr != -1; i++)
2127 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2128 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2129 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2131 pos = main_controls[i].nr;
2137 // check if level preview was clicked
2138 if (insidePreviewRect(&preview, mx - SX, my - SY))
2139 pos = MAIN_CONTROL_GAME;
2141 // handle pressed/unpressed state for active/inactive menu buttons
2142 // (if pos != -1, "i" contains index position corresponding to "pos")
2144 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2145 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2146 button_pressed = TRUE;
2148 if (button_pressed != button_pressed_last)
2150 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2153 PlaySound(SND_MENU_BUTTON_PRESSING);
2155 PlaySound(SND_MENU_BUTTON_RELEASING);
2158 else if (dx || dy) // keyboard input
2160 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2161 choice == MAIN_CONTROL_SETUP))
2162 button = MB_MENU_CHOICE;
2167 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2169 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2171 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2173 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2175 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2177 CloseDoor(DOOR_CLOSE_2);
2179 SetGameStatus(GAME_MODE_LEVELNR);
2181 DrawChooseLevelNr();
2183 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2189 PlaySound(SND_MENU_ITEM_ACTIVATING);
2191 DrawCursorAndText_Main(choice, FALSE, FALSE);
2192 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2198 if (choice == MAIN_CONTROL_NAME)
2200 // special case: cursor left or right pressed -- toggle team mode
2201 HandleMainMenu_ToggleTeamMode();
2203 else if (choice != MAIN_CONTROL_INFO &&
2204 choice != MAIN_CONTROL_SETUP)
2206 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2212 PlaySound(SND_MENU_ITEM_SELECTING);
2214 if (pos == MAIN_CONTROL_NAME)
2217 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2219 // special case: menu text "name/team" clicked -- toggle team mode
2220 HandleMainMenu_ToggleTeamMode();
2224 if (setup.multiple_users)
2226 CloseDoor(DOOR_CLOSE_2);
2228 SetGameStatus(GAME_MODE_NAMES);
2230 DrawChoosePlayerName();
2234 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2240 else if (pos == MAIN_CONTROL_LEVELS)
2244 CloseDoor(DOOR_CLOSE_2);
2246 SetGameStatus(GAME_MODE_LEVELS);
2248 SaveLevelSetup_LastSeries();
2249 SaveLevelSetup_SeriesInfo();
2251 // restore level set if chosen from "last played level set" menu
2252 RestoreLastPlayedLevels(&leveldir_current);
2254 if (setup.internal.choose_from_top_leveldir)
2257 DrawChooseLevelSet();
2260 else if (pos == MAIN_CONTROL_SCORES)
2262 CloseDoor(DOOR_CLOSE_2);
2264 SetGameStatus(GAME_MODE_SCORES);
2266 DrawHallOfFame(level_nr);
2268 else if (pos == MAIN_CONTROL_EDITOR)
2270 if (leveldir_current->readonly &&
2271 setup.editor.show_read_only_warning)
2272 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2274 CloseDoor(DOOR_CLOSE_ALL);
2276 SetGameStatus(GAME_MODE_EDITOR);
2278 FadeSetEnterScreen();
2282 else if (pos == MAIN_CONTROL_INFO)
2284 CloseDoor(DOOR_CLOSE_2);
2286 SetGameStatus(GAME_MODE_INFO);
2288 info_mode = INFO_MODE_MAIN;
2292 else if (pos == MAIN_CONTROL_GAME)
2294 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2296 else if (pos == MAIN_CONTROL_SETUP)
2298 CloseDoor(DOOR_CLOSE_2);
2300 SetGameStatus(GAME_MODE_SETUP);
2302 setup_mode = SETUP_MODE_MAIN;
2306 else if (pos == MAIN_CONTROL_QUIT)
2308 SaveLevelSetup_LastSeries();
2309 SaveLevelSetup_SeriesInfo();
2311 #if defined(PLATFORM_EMSCRIPTEN)
2312 Request("Close the browser window to quit!", REQ_CONFIRM);
2314 if (!setup.ask_on_quit_program ||
2315 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2316 SetGameStatus(GAME_MODE_QUIT);
2322 button_pressed_last = button_pressed;
2326 // ============================================================================
2327 // info screen functions
2328 // ============================================================================
2330 static struct TokenInfo *info_info;
2331 static int num_info_info; // number of info entries shown on screen
2332 static int max_info_info; // total number of info entries in list
2334 static void execInfoTitleScreen(void)
2336 info_mode = INFO_MODE_TITLE;
2341 static void execInfoElements(void)
2343 info_mode = INFO_MODE_ELEMENTS;
2348 static void execInfoMusic(void)
2350 info_mode = INFO_MODE_MUSIC;
2355 static void execInfoCredits(void)
2357 info_mode = INFO_MODE_CREDITS;
2362 static void execInfoProgram(void)
2364 info_mode = INFO_MODE_PROGRAM;
2369 static void execInfoVersion(void)
2371 info_mode = INFO_MODE_VERSION;
2376 static void execInfoLevelSet(void)
2378 info_mode = INFO_MODE_LEVELSET;
2383 static void execExitInfo(void)
2385 SetGameStatus(GAME_MODE_MAIN);
2390 static struct TokenInfo info_info_main[] =
2392 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2393 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2394 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2395 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2396 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2397 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2398 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2399 { TYPE_EMPTY, NULL, "" },
2400 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2405 static int getMenuTextFont(int type)
2407 if (type & (TYPE_SWITCH |
2421 static struct TokenInfo *setup_info;
2422 static struct TokenInfo setup_info_input[];
2424 static struct TokenInfo *menu_info;
2426 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2427 int screen_pos, int menu_info_pos_raw,
2430 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2431 struct TokenInfo *ti = &token_info[pos];
2432 int xpos = MENU_SCREEN_START_XPOS;
2433 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2434 int font_nr = getMenuTextFont(ti->type);
2436 if (setup_mode == SETUP_MODE_INPUT)
2437 font_nr = FONT_MENU_1;
2440 font_nr = FONT_ACTIVE(font_nr);
2442 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2444 if (ti->type & ~TYPE_SKIP_ENTRY)
2445 drawCursor(screen_pos, active);
2448 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2451 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2454 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2457 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2460 static char *window_size_text;
2461 static char *scaling_type_text;
2462 static char *network_server_text;
2464 static void drawSetupValue(int, int);
2466 static void drawMenuInfoList(int first_entry, int num_page_entries,
2467 int max_page_entries)
2471 if (first_entry + num_page_entries > max_page_entries)
2474 clearMenuListArea();
2476 for (i = 0; i < num_page_entries; i++)
2478 int menu_info_pos = first_entry + i;
2479 struct TokenInfo *si = &menu_info[menu_info_pos];
2480 void *value_ptr = si->value;
2482 // set some entries to "unchangeable" according to other variables
2483 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2484 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2485 (value_ptr == &setup.sound_music && !audio.music_available) ||
2486 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2487 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2488 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2489 si->type |= TYPE_GHOSTED;
2491 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2492 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2493 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2494 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2495 else if (si->type & ~TYPE_SKIP_ENTRY)
2496 initCursor(i, IMG_MENU_BUTTON);
2498 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2500 if (si->type & TYPE_STRING)
2504 if (value_ptr == &network_server_text)
2505 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2507 if (gadget_id != -1)
2509 struct GadgetInfo *gi = screen_gadget[gadget_id];
2510 int xpos = MENU_SCREEN_START_XPOS;
2511 int ypos = MENU_SCREEN_START_YPOS + i;
2512 int x = mSX + xpos * 32;
2513 int y = mSY + ypos * 32;
2515 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2519 if (si->type & TYPE_VALUE &&
2520 menu_info == setup_info)
2521 drawSetupValue(i, menu_info_pos);
2525 static void DrawInfoScreen_Main(void)
2527 int fade_mask = REDRAW_FIELD;
2530 if (redraw_mask & REDRAW_ALL)
2531 fade_mask = REDRAW_ALL;
2534 fade_mask = REDRAW_ALL;
2537 FadeMenuSoundsAndMusic();
2539 FreeScreenGadgets();
2540 CreateScreenGadgets();
2542 // (needed after displaying title screens which disable auto repeat)
2543 KeyboardAutoRepeatOn();
2545 FadeSetLeaveScreen();
2549 // needed if different viewport properties defined for info screen
2550 ChangeViewportPropertiesIfNeeded();
2552 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2556 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2558 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2560 info_info = info_info_main;
2562 // use modified info screen info without info screen entries marked as hidden
2563 info_info = getSetupInfoFinal(info_info);
2565 // determine maximal number of info entries that can be displayed on screen
2567 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2570 // determine maximal number of info entries available for menu of info screen
2572 for (i = 0; info_info[i].type != 0; i++)
2575 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2577 MapScreenGadgets(max_info_info);
2579 PlayMenuSoundsAndMusic();
2581 DrawMaskedBorder(fade_mask);
2586 static void changeSetupValue(int, int, int);
2588 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2589 int mode, int num_page_entries,
2590 int max_page_entries)
2592 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2593 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2594 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2595 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2596 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2597 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2598 int *num_page_entries_last = num_page_entries_all_last[game_status];
2599 int *choice_store = choice_stores[game_status];
2600 int *first_entry_store = first_entry_stores[game_status];
2601 int choice = choice_store[mode]; // starts with 0
2602 int first_entry = first_entry_store[mode]; // starts with 0
2604 int y = choice - first_entry;
2606 boolean position_set_by_scrollbar = (dx == 999);
2607 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2610 if (button == MB_MENU_INITIALIZE)
2612 // check if number of menu page entries has changed (may happen by change
2613 // of custom artwork definition value for 'list_size' for this menu screen)
2614 // (in this case, the last menu position most probably has to be corrected)
2615 if (num_page_entries != num_page_entries_last[mode])
2617 choice_store[mode] = first_entry_store[mode] = 0;
2619 choice = first_entry = 0;
2622 num_page_entries_last[mode] = num_page_entries;
2625 // advance to first valid menu entry
2626 while (choice < num_page_entries &&
2627 menu_info[choice].type & TYPE_SKIP_ENTRY)
2630 if (position_set_by_scrollbar)
2631 first_entry = first_entry_store[mode] = dy;
2633 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2634 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2636 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2638 if (choice < first_entry)
2640 choice = first_entry;
2642 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2645 else if (choice > first_entry + num_page_entries - 1)
2647 choice = first_entry + num_page_entries - 1;
2649 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2653 choice_store[mode] = choice;
2655 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2659 else if (button == MB_MENU_LEAVE)
2661 PlaySound(SND_MENU_ITEM_SELECTING);
2663 for (i = 0; i < max_page_entries; i++)
2665 if (menu_info[i].type & TYPE_LEAVE_MENU)
2667 void (*menu_callback_function)(void) = menu_info[i].value;
2671 menu_callback_function();
2673 break; // absolutely needed because function changes 'menu_info'!
2680 if (mx || my) // mouse input
2682 x = (mx - mSX) / 32;
2683 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2685 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2687 // move cursor instead of scrolling when already at start/end of list
2688 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2690 else if (dy == +1 * SCROLL_LINE &&
2691 first_entry + num_page_entries == max_page_entries)
2694 // handle scrolling screen one line or page
2696 y + dy > num_page_entries - 1)
2698 boolean redraw = FALSE;
2700 if (ABS(dy) == SCROLL_PAGE)
2701 step = num_page_entries - 1;
2703 if (dy < 0 && first_entry > 0)
2705 // scroll page/line up
2707 first_entry -= step;
2708 if (first_entry < 0)
2713 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2715 // scroll page/line down
2717 first_entry += step;
2718 if (first_entry + num_page_entries > max_page_entries)
2719 first_entry = MAX(0, max_page_entries - num_page_entries);
2726 choice += first_entry - first_entry_store[mode];
2728 if (choice < first_entry)
2730 choice = first_entry;
2732 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2735 else if (choice > first_entry + num_page_entries - 1)
2737 choice = first_entry + num_page_entries - 1;
2739 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2742 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2746 if (choice < first_entry ||
2747 choice > first_entry + num_page_entries - 1)
2748 first_entry += SIGN(dy);
2751 first_entry_store[mode] = first_entry;
2752 choice_store[mode] = choice;
2754 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2756 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2758 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2759 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2767 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2769 if (menu_info[choice].type & menu_navigation_type ||
2770 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2771 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2772 menu_info[choice].type & TYPE_PLAYER)
2773 button = MB_MENU_CHOICE;
2778 // jump to next non-empty menu entry (up or down)
2779 while (first_entry + y > 0 &&
2780 first_entry + y < max_page_entries - 1 &&
2781 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2784 if (!IN_VIS_MENU(x, y))
2786 choice += y - y_old;
2788 if (choice < first_entry)
2789 first_entry = choice;
2790 else if (choice > first_entry + num_page_entries - 1)
2791 first_entry = choice - num_page_entries + 1;
2793 if (first_entry >= 0 &&
2794 first_entry + num_page_entries <= max_page_entries)
2796 first_entry_store[mode] = first_entry;
2798 if (choice < first_entry)
2799 choice = first_entry;
2800 else if (choice > first_entry + num_page_entries - 1)
2801 choice = first_entry + num_page_entries - 1;
2803 choice_store[mode] = choice;
2805 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2807 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2809 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2810 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2817 if (!anyScrollbarGadgetActive() &&
2818 IN_VIS_MENU(x, y) &&
2819 mx < mx_right_border &&
2820 y >= 0 && y < num_page_entries)
2824 if (first_entry + y != choice &&
2825 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2827 PlaySound(SND_MENU_ITEM_ACTIVATING);
2829 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2830 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2832 choice = choice_store[mode] = first_entry + y;
2836 PlaySound(SND_MENU_ITEM_SELECTING);
2838 for (i = 0; menu_info[i].type != 0; i++)
2840 if (menu_info[i].type & TYPE_LEAVE_MENU)
2842 void (*menu_callback_function)(void) = menu_info[i].value;
2846 menu_callback_function();
2848 // absolutely needed because function changes 'menu_info'!
2856 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2858 PlaySound(SND_MENU_ITEM_SELECTING);
2860 // when selecting key headline, execute function for key value change
2861 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2862 menu_info[first_entry + y + 1].type & TYPE_KEY)
2865 // when selecting string value, execute function for list selection
2866 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2867 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2870 // when selecting string value, execute function for text input gadget
2871 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2872 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2875 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2877 void (*menu_callback_function)(void) =
2878 menu_info[first_entry + y].value;
2880 FadeSetFromType(menu_info[first_entry + y].type);
2882 menu_callback_function();
2884 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2886 void (*gadget_callback_function)(void) =
2887 menu_info[first_entry + y].value;
2889 gadget_callback_function();
2891 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2892 menu_info == setup_info)
2894 changeSetupValue(y, first_entry + y, dx);
2900 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2902 menu_info = info_info;
2904 HandleMenuScreen(mx, my, dx, dy, button,
2905 info_mode, num_info_info, max_info_info);
2908 static int getMenuFontSpacing(int spacing_height, int font_nr)
2910 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2912 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2916 static int getMenuTextSpacing(int spacing_height, int font_nr)
2918 return (getMenuFontSpacing(spacing_height, font_nr) +
2919 EXTRA_SPACING(game_status));
2922 static int getMenuTextStep(int spacing_height, int font_nr)
2924 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2927 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2929 int font_title = MENU_INFO_FONT_TITLE;
2930 int font_error = FONT_TEXT_2;
2931 int font_foot = MENU_INFO_FONT_FOOT;
2932 int spacing_title = menu.headline1_spacing_info[info_mode];
2933 int ystep_title = getMenuTextStep(spacing_title, font_title);
2934 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2935 int ystart2 = ystart1 + ystep_title;
2936 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2938 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2940 FadeOut(REDRAW_FIELD);
2945 DrawTextSCentered(ystart1, font_title, text_title);
2946 DrawTextSCentered(ystart2, font_error, text_error);
2948 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
2950 FadeIn(REDRAW_FIELD);
2953 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2955 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2956 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2957 int font_title = MENU_INFO_FONT_TITLE;
2958 int font_foot = MENU_INFO_FONT_FOOT;
2959 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2960 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2961 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2962 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2963 int ystep = MENU_SCREEN_INFO_YSTEP;
2964 int element, action, direction;
2972 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2973 infoscreen_step[i] = infoscreen_frame[i] = 0;
2978 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2979 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
2985 while (helpanim_info[j].element != HELPANIM_LIST_END)
2987 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2992 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3001 j += infoscreen_step[i - start];
3003 element = helpanim_info[j].element;
3004 action = helpanim_info[j].action;
3005 direction = helpanim_info[j].direction;
3008 element = EL_UNKNOWN;
3010 if (action != -1 && direction != -1)
3011 graphic = el_act_dir2img(element, action, direction);
3012 else if (action != -1)
3013 graphic = el_act2img(element, action);
3014 else if (direction != -1)
3015 graphic = el_dir2img(element, direction);
3017 graphic = el2img(element);
3019 delay = helpanim_info[j++].delay;
3024 if (infoscreen_frame[i - start] == 0)
3027 infoscreen_frame[i - start] = delay - 1;
3031 sync_frame = delay - infoscreen_frame[i - start];
3032 infoscreen_frame[i - start]--;
3035 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3037 if (!infoscreen_frame[i - start])
3038 infoscreen_step[i - start] = 0;
3042 if (!infoscreen_frame[i - start])
3043 infoscreen_step[i - start]++;
3044 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3050 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3052 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3053 graphic, sync_frame, USE_MASKING);
3056 DrawInfoScreen_HelpText(element, action, direction, i - start);
3061 redraw_mask |= REDRAW_FIELD;
3066 static char *getHelpText(int element, int action, int direction)
3068 char token[MAX_LINE_LEN];
3070 strcpy(token, element_info[element].token_name);
3073 strcat(token, element_action_info[action].suffix);
3075 if (direction != -1)
3076 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3078 return getHashEntry(helptext_info, token);
3081 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3083 int font_nr = FONT_INFO_ELEMENTS;
3084 int font_width = getFontWidth(font_nr);
3085 int font_height = getFontHeight(font_nr);
3086 int yoffset = (TILEX - 2 * font_height) / 2;
3087 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3088 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3089 int ystep = TILEY + 4;
3090 int pad_left = xstart - SX;
3091 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3092 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3093 int max_lines_per_text = 2;
3096 if (action != -1 && direction != -1) // element.action.direction
3097 text = getHelpText(element, action, direction);
3099 if (text == NULL && action != -1) // element.action
3100 text = getHelpText(element, action, -1);
3102 if (text == NULL && direction != -1) // element.direction
3103 text = getHelpText(element, -1, direction);
3105 if (text == NULL) // base element
3106 text = getHelpText(element, -1, -1);
3108 if (text == NULL) // not found
3109 text = "No description available";
3111 if (strlen(text) <= max_chars_per_line) // only one line of text
3112 ystart += getFontHeight(font_nr) / 2;
3114 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3115 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3116 TRUE, FALSE, FALSE);
3119 static void DrawInfoScreen_TitleScreen(void)
3121 SetGameStatus(GAME_MODE_TITLE);
3126 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3128 HandleTitleScreen(0, 0, dx, dy, button);
3131 static void DrawInfoScreen_Elements(void)
3133 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3135 FadeOut(REDRAW_FIELD);
3140 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3142 FadeIn(REDRAW_FIELD);
3145 void HandleInfoScreen_Elements(int dx, int dy, int button)
3147 static unsigned int info_delay = 0;
3148 static int num_anims;
3149 static int num_pages;
3151 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3154 if (button == MB_MENU_INITIALIZE)
3156 boolean new_element = TRUE;
3160 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3162 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3164 else if (new_element)
3167 new_element = FALSE;
3171 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3175 if (button == MB_MENU_LEAVE)
3177 PlaySound(SND_MENU_ITEM_SELECTING);
3179 info_mode = INFO_MODE_MAIN;
3184 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3186 if (button != MB_MENU_INITIALIZE)
3188 PlaySound(SND_MENU_ITEM_SELECTING);
3190 page += (dx < 0 ? -1 : +1);
3193 if (page < 0 || page >= num_pages)
3195 FadeMenuSoundsAndMusic();
3197 info_mode = INFO_MODE_MAIN;
3203 if (button != MB_MENU_INITIALIZE)
3204 FadeSetNextScreen();
3206 if (button != MB_MENU_INITIALIZE)
3207 FadeOut(REDRAW_FIELD);
3209 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3211 if (button != MB_MENU_INITIALIZE)
3212 FadeIn(REDRAW_FIELD);
3216 if (DelayReached(&info_delay, GameFrameDelay))
3217 if (page < num_pages)
3218 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3220 PlayMenuSoundIfLoop();
3224 static void DrawInfoScreen_Music(void)
3226 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3228 FadeOut(REDRAW_FIELD);
3235 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3237 FadeIn(REDRAW_FIELD);
3240 void HandleInfoScreen_Music(int dx, int dy, int button)
3242 static struct MusicFileInfo *list = NULL;
3243 int font_title = MENU_INFO_FONT_TITLE;
3244 int font_head = MENU_INFO_FONT_HEAD;
3245 int font_text = MENU_INFO_FONT_TEXT;
3246 int font_foot = MENU_INFO_FONT_FOOT;
3247 int spacing_title = menu.headline1_spacing_info[info_mode];
3248 int spacing_head = menu.headline2_spacing_info[info_mode];
3249 int ystep_title = getMenuTextStep(spacing_title, font_title);
3250 int ystep_head = getMenuTextStep(spacing_head, font_head);
3251 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3252 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3254 if (button == MB_MENU_INITIALIZE)
3256 list = music_file_info;
3260 FadeMenuSoundsAndMusic();
3265 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3266 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3272 if (button == MB_MENU_LEAVE)
3274 PlaySound(SND_MENU_ITEM_SELECTING);
3276 FadeMenuSoundsAndMusic();
3278 info_mode = INFO_MODE_MAIN;
3283 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3285 if (button != MB_MENU_INITIALIZE)
3287 PlaySound(SND_MENU_ITEM_SELECTING);
3290 list = (dx < 0 ? list->prev : list->next);
3295 FadeMenuSoundsAndMusic();
3297 info_mode = INFO_MODE_MAIN;
3303 FadeMenuSoundsAndMusic();
3305 if (list != music_file_info)
3306 FadeSetNextScreen();
3308 if (button != MB_MENU_INITIALIZE)
3309 FadeOut(REDRAW_FIELD);
3316 int sound = list->music;
3318 if (IS_LOOP_SOUND(sound))
3319 PlaySoundLoop(sound);
3323 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3327 int music = list->music;
3329 if (IS_LOOP_MUSIC(music))
3330 PlayMusicLoop(music);
3334 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3337 ystart += ystep_title;
3339 if (!strEqual(list->title, UNKNOWN_NAME))
3341 if (!strEqual(list->title_header, UNKNOWN_NAME))
3343 DrawTextSCentered(ystart, font_head, list->title_header);
3344 ystart += ystep_head;
3347 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3348 ystart += ystep_head;
3351 if (!strEqual(list->artist, UNKNOWN_NAME))
3353 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3354 DrawTextSCentered(ystart, font_head, list->artist_header);
3356 DrawTextSCentered(ystart, font_head, "by");
3358 ystart += ystep_head;
3360 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3361 ystart += ystep_head;
3364 if (!strEqual(list->album, UNKNOWN_NAME))
3366 if (!strEqual(list->album_header, UNKNOWN_NAME))
3367 DrawTextSCentered(ystart, font_head, list->album_header);
3369 DrawTextSCentered(ystart, font_head, "from the album");
3371 ystart += ystep_head;
3373 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3374 ystart += ystep_head;
3377 if (!strEqual(list->year, UNKNOWN_NAME))
3379 if (!strEqual(list->year_header, UNKNOWN_NAME))
3380 DrawTextSCentered(ystart, font_head, list->year_header);
3382 DrawTextSCentered(ystart, font_head, "from the year");
3384 ystart += ystep_head;
3386 DrawTextFCentered(ystart, font_text, "%s", list->year);
3387 ystart += ystep_head;
3390 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3392 if (button != MB_MENU_INITIALIZE)
3393 FadeIn(REDRAW_FIELD);
3396 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3397 PlaySoundLoop(list->music);
3400 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3402 int font_title = MENU_INFO_FONT_TITLE;
3403 int font_text = MENU_INFO_FONT_TEXT;
3404 int font_foot = MENU_INFO_FONT_FOOT;
3405 int spacing_title = menu.headline1_spacing_info[info_mode];
3406 int spacing_line = menu.line_spacing_info[info_mode];
3407 int ystep_title = getMenuTextStep(spacing_title, font_title);
3408 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3409 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3414 DrawTextSCentered(ystart, font_title, "Credits:");
3416 char *filename = getCreditsFilename(screen_nr, use_global_credits_screens);
3418 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3419 int chars = width / getFontWidth(font_text);
3420 int lines = height / getFontHeight(font_text);
3421 int padx = (width - chars * getFontWidth(font_text)) / 2;
3422 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3423 boolean autowrap = FALSE;
3424 boolean centered = TRUE;
3425 boolean parse_comments = TRUE;
3427 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3428 filename, font_text, chars, -1, lines, line_spacing, -1,
3429 autowrap, centered, parse_comments);
3431 boolean last_screen = (screen_nr == num_credits_screens - 1);
3432 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3434 DrawTextSCentered(ybottom, font_foot, text_foot);
3437 static void DrawInfoScreen_Credits(void)
3439 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3441 FadeMenuSoundsAndMusic();
3443 FadeOut(REDRAW_FIELD);
3445 HandleInfoScreen_Credits(0, 0, MB_MENU_INITIALIZE);
3447 FadeIn(REDRAW_FIELD);
3450 void HandleInfoScreen_Credits(int dx, int dy, int button)
3452 static int screen_nr = 0;
3454 if (button == MB_MENU_INITIALIZE)
3458 // determine number of (global or level set specific) credits screens
3459 for (i = 0; i < 2; i++)
3461 num_credits_screens = 0;
3462 use_global_credits_screens = i;
3464 while (getCreditsFilename(num_credits_screens,
3465 use_global_credits_screens) != NULL)
3466 num_credits_screens++;
3468 if (num_credits_screens > 0)
3472 if (num_credits_screens == 0)
3474 int font_title = MENU_INFO_FONT_TITLE;
3475 int font_foot = MENU_INFO_FONT_FOOT;
3476 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3477 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3482 DrawTextSCentered(ystart, font_title, "No credits for this level set.");
3483 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3490 DrawInfoScreen_CreditsScreen(screen_nr);
3492 else if (button == MB_MENU_LEAVE)
3494 PlaySound(SND_MENU_ITEM_SELECTING);
3496 info_mode = INFO_MODE_MAIN;
3501 else if (button == MB_MENU_CHOICE || dx)
3503 PlaySound(SND_MENU_ITEM_SELECTING);
3505 screen_nr += (dx < 0 ? -1 : +1);
3507 if (screen_nr < 0 || screen_nr >= num_credits_screens)
3509 FadeMenuSoundsAndMusic();
3511 info_mode = INFO_MODE_MAIN;
3517 FadeSetNextScreen();
3519 FadeOut(REDRAW_FIELD);
3521 DrawInfoScreen_CreditsScreen(screen_nr);
3523 FadeIn(REDRAW_FIELD);
3527 PlayMenuSoundIfLoop();
3531 static void DrawInfoScreen_ProgramScreen(int screen_nr)
3533 int font_title = MENU_INFO_FONT_TITLE;
3534 int font_text = MENU_INFO_FONT_TEXT;
3535 int font_foot = MENU_INFO_FONT_FOOT;
3536 int spacing_title = menu.headline1_spacing_info[info_mode];
3537 int spacing_line = menu.line_spacing_info[info_mode];
3538 int ystep_title = getMenuTextStep(spacing_title, font_title);
3539 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3540 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3545 DrawTextSCentered(ystart, font_title, "Program Information:");
3547 char *filename = getProgramInfoFilename(screen_nr);
3549 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3550 int chars = width / getFontWidth(font_text);
3551 int lines = height / getFontHeight(font_text);
3552 int padx = (width - chars * getFontWidth(font_text)) / 2;
3553 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3554 boolean autowrap = FALSE;
3555 boolean centered = TRUE;
3556 boolean parse_comments = TRUE;
3558 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3559 filename, font_text, chars, -1, lines, line_spacing, -1,
3560 autowrap, centered, parse_comments);
3562 boolean last_screen = (screen_nr == num_program_info_screens - 1);
3563 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3565 DrawTextSCentered(ybottom, font_foot, text_foot);
3568 static void DrawInfoScreen_Program(void)
3570 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3572 FadeMenuSoundsAndMusic();
3574 FadeOut(REDRAW_FIELD);
3576 HandleInfoScreen_Program(0, 0, MB_MENU_INITIALIZE);
3578 FadeIn(REDRAW_FIELD);
3581 void HandleInfoScreen_Program(int dx, int dy, int button)
3583 static int screen_nr = 0;
3585 if (button == MB_MENU_INITIALIZE)
3587 // determine number of program info screens
3588 num_program_info_screens = 0;
3590 while (getProgramInfoFilename(num_program_info_screens) != NULL)
3591 num_program_info_screens++;
3593 if (num_program_info_screens == 0)
3595 int font_title = MENU_INFO_FONT_TITLE;
3596 int font_foot = MENU_INFO_FONT_FOOT;
3597 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3598 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3603 DrawTextSCentered(ystart, font_title, "No program info available.");
3604 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3611 DrawInfoScreen_ProgramScreen(screen_nr);
3613 else if (button == MB_MENU_LEAVE)
3615 PlaySound(SND_MENU_ITEM_SELECTING);
3617 info_mode = INFO_MODE_MAIN;
3622 else if (button == MB_MENU_CHOICE || dx)
3624 PlaySound(SND_MENU_ITEM_SELECTING);
3626 screen_nr += (dx < 0 ? -1 : +1);
3628 if (screen_nr < 0 || screen_nr >= num_program_info_screens)
3630 FadeMenuSoundsAndMusic();
3632 info_mode = INFO_MODE_MAIN;
3638 FadeSetNextScreen();
3640 FadeOut(REDRAW_FIELD);
3642 DrawInfoScreen_ProgramScreen(screen_nr);
3644 FadeIn(REDRAW_FIELD);
3648 PlayMenuSoundIfLoop();
3652 static void DrawInfoScreen_Version(void)
3654 int font_title = MENU_INFO_FONT_TITLE;
3655 int font_head = MENU_INFO_FONT_HEAD;
3656 int font_text = MENU_INFO_FONT_TEXT;
3657 int font_foot = MENU_INFO_FONT_FOOT;
3658 int spacing_title = menu.headline1_spacing_info[info_mode];
3659 int spacing_head = menu.headline2_spacing_info[info_mode];
3660 int spacing_para = menu.paragraph_spacing_info[info_mode];
3661 int spacing_line = menu.line_spacing_info[info_mode];
3662 int xstep = getFontWidth(font_text);
3663 int ystep_title = getMenuTextStep(spacing_title, font_title);
3664 int ystep_head = getMenuTextStep(spacing_head, font_head);
3665 int ystep_para = getMenuTextStep(spacing_para, font_text);
3666 int ystep_line = getMenuTextStep(spacing_line, font_text);
3667 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3668 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3669 int xstart1 = mSX - SX + 2 * xstep;
3670 int xstart2 = mSX - SX + 18 * xstep;
3671 int xstart3 = mSX - SX + 28 * xstep;
3672 SDL_version sdl_version_compiled;
3673 const SDL_version *sdl_version_linked;
3674 int driver_name_len = 10;
3675 SDL_version sdl_version_linked_ext;
3676 const char *driver_name = NULL;
3678 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3680 FadeOut(REDRAW_FIELD);
3685 DrawTextSCentered(ystart, font_title, "Version Information:");
3686 ystart += ystep_title;
3688 DrawTextF(xstart1, ystart, font_head, "Name");
3689 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3690 ystart += ystep_line;
3692 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3694 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3695 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3696 ystart += ystep_line;
3698 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3699 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3700 ystart += ystep_line;
3704 DrawTextF(xstart1, ystart, font_head, "Version");
3705 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3706 ystart += ystep_line;
3709 DrawTextF(xstart1, ystart, font_head, "Platform");
3710 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3712 PLATFORM_XX_BIT_STRING);
3713 ystart += ystep_line;
3715 DrawTextF(xstart1, ystart, font_head, "Target");
3716 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3717 ystart += ystep_line;
3719 DrawTextF(xstart1, ystart, font_head, "Source date");
3720 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3721 ystart += ystep_line;
3723 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3724 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3725 ystart += ystep_para;
3727 DrawTextF(xstart1, ystart, font_head, "Library");
3728 DrawTextF(xstart2, ystart, font_head, "compiled");
3729 DrawTextF(xstart3, ystart, font_head, "linked");
3730 ystart += ystep_head;
3732 SDL_VERSION(&sdl_version_compiled);
3733 SDL_GetVersion(&sdl_version_linked_ext);
3734 sdl_version_linked = &sdl_version_linked_ext;
3736 DrawTextF(xstart1, ystart, font_text, "SDL");
3737 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3738 sdl_version_compiled.major,
3739 sdl_version_compiled.minor,
3740 sdl_version_compiled.patch);
3741 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3742 sdl_version_linked->major,
3743 sdl_version_linked->minor,
3744 sdl_version_linked->patch);
3745 ystart += ystep_line;
3747 SDL_IMAGE_VERSION(&sdl_version_compiled);
3748 sdl_version_linked = IMG_Linked_Version();
3750 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3751 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3752 sdl_version_compiled.major,
3753 sdl_version_compiled.minor,
3754 sdl_version_compiled.patch);
3755 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3756 sdl_version_linked->major,
3757 sdl_version_linked->minor,
3758 sdl_version_linked->patch);
3759 ystart += ystep_line;
3761 SDL_MIXER_VERSION(&sdl_version_compiled);
3762 sdl_version_linked = Mix_Linked_Version();
3764 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3765 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3766 sdl_version_compiled.major,
3767 sdl_version_compiled.minor,
3768 sdl_version_compiled.patch);
3769 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3770 sdl_version_linked->major,
3771 sdl_version_linked->minor,
3772 sdl_version_linked->patch);
3773 ystart += ystep_line;
3775 SDL_NET_VERSION(&sdl_version_compiled);
3776 sdl_version_linked = SDLNet_Linked_Version();
3778 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3779 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3780 sdl_version_compiled.major,
3781 sdl_version_compiled.minor,
3782 sdl_version_compiled.patch);
3783 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3784 sdl_version_linked->major,
3785 sdl_version_linked->minor,
3786 sdl_version_linked->patch);
3787 ystart += ystep_para;
3789 DrawTextF(xstart1, ystart, font_head, "Driver");
3790 DrawTextF(xstart2, ystart, font_head, "Requested");
3791 DrawTextF(xstart3, ystart, font_head, "Used");
3792 ystart += ystep_head;
3795 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3797 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3798 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3799 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3800 ystart += ystep_line;
3803 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3805 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3806 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3807 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3808 ystart += ystep_line;
3811 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3813 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3814 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3815 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3817 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3819 FadeIn(REDRAW_FIELD);
3822 void HandleInfoScreen_Version(int button)
3824 if (button == MB_MENU_LEAVE)
3826 PlaySound(SND_MENU_ITEM_SELECTING);
3828 info_mode = INFO_MODE_MAIN;
3833 else if (button == MB_MENU_CHOICE)
3835 PlaySound(SND_MENU_ITEM_SELECTING);
3837 FadeMenuSoundsAndMusic();
3839 info_mode = INFO_MODE_MAIN;
3844 PlayMenuSoundIfLoop();
3848 static void DrawInfoScreen_LevelSet(void)
3850 struct TitleMessageInfo *tmi = &readme;
3851 char *filename = getLevelSetInfoFilename();
3852 char *title = "Level Set Information:";
3853 int font_foot = MENU_INFO_FONT_FOOT;
3854 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3855 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3857 if (filename == NULL)
3859 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3864 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3866 FadeOut(REDRAW_FIELD);
3871 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3873 // if x position set to "-1", automatically determine by playfield width
3875 tmi->x = SXSIZE / 2;
3877 // if y position set to "-1", use static default value
3881 // if width set to "-1", automatically determine by playfield width
3882 if (tmi->width == -1)
3883 tmi->width = SXSIZE - 2 * TILEX;
3885 // if height set to "-1", automatically determine by playfield height
3886 if (tmi->height == -1)
3887 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3889 // if chars set to "-1", automatically determine by text and font width
3890 if (tmi->chars == -1)
3891 tmi->chars = tmi->width / getFontWidth(tmi->font);
3893 tmi->width = tmi->chars * getFontWidth(tmi->font);
3895 // if lines set to "-1", automatically determine by text and font height
3896 if (tmi->lines == -1)
3897 tmi->lines = tmi->height / getFontHeight(tmi->font);
3899 tmi->height = tmi->lines * getFontHeight(tmi->font);
3901 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3902 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3903 tmi->autowrap, tmi->centered, tmi->parse_comments);
3905 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3907 FadeIn(REDRAW_FIELD);
3910 static void HandleInfoScreen_LevelSet(int button)
3912 if (button == MB_MENU_LEAVE)
3914 PlaySound(SND_MENU_ITEM_SELECTING);
3916 info_mode = INFO_MODE_MAIN;
3921 else if (button == MB_MENU_CHOICE)
3923 PlaySound(SND_MENU_ITEM_SELECTING);
3925 FadeMenuSoundsAndMusic();
3927 info_mode = INFO_MODE_MAIN;
3932 PlayMenuSoundIfLoop();
3936 static void DrawInfoScreen(void)
3938 if (info_mode == INFO_MODE_TITLE)
3939 DrawInfoScreen_TitleScreen();
3940 else if (info_mode == INFO_MODE_ELEMENTS)
3941 DrawInfoScreen_Elements();
3942 else if (info_mode == INFO_MODE_MUSIC)
3943 DrawInfoScreen_Music();
3944 else if (info_mode == INFO_MODE_CREDITS)
3945 DrawInfoScreen_Credits();
3946 else if (info_mode == INFO_MODE_PROGRAM)
3947 DrawInfoScreen_Program();
3948 else if (info_mode == INFO_MODE_VERSION)
3949 DrawInfoScreen_Version();
3950 else if (info_mode == INFO_MODE_LEVELSET)
3951 DrawInfoScreen_LevelSet();
3953 DrawInfoScreen_Main();
3955 if (info_mode != INFO_MODE_MAIN &&
3956 info_mode != INFO_MODE_TITLE &&
3957 info_mode != INFO_MODE_MUSIC)
3958 PlayMenuSoundsAndMusic();
3961 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3963 if (info_mode == INFO_MODE_TITLE)
3964 HandleInfoScreen_TitleScreen(dx, dy, button);
3965 else if (info_mode == INFO_MODE_ELEMENTS)
3966 HandleInfoScreen_Elements(dx, dy, button);
3967 else if (info_mode == INFO_MODE_MUSIC)
3968 HandleInfoScreen_Music(dx, dy, button);
3969 else if (info_mode == INFO_MODE_CREDITS)
3970 HandleInfoScreen_Credits(dx, dy, button);
3971 else if (info_mode == INFO_MODE_PROGRAM)
3972 HandleInfoScreen_Program(dx, dy, button);
3973 else if (info_mode == INFO_MODE_VERSION)
3974 HandleInfoScreen_Version(button);
3975 else if (info_mode == INFO_MODE_LEVELSET)
3976 HandleInfoScreen_LevelSet(button);
3978 HandleInfoScreen_Main(mx, my, dx, dy, button);
3982 // ============================================================================
3983 // type name functions
3984 // ============================================================================
3986 static TreeInfo *type_name_node = NULL;
3987 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
3988 static int type_name_nr = 0;
3990 static int getPlayerNameColor(char *name)
3992 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
3995 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
3998 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
3999 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4000 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4001 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4002 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4003 int font_width = getFontWidth(font_nr);
4005 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4007 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4009 pos->width = strlen(text) * font_width;
4010 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4012 DrawText(sx, sy, text, font_nr);
4015 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4017 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4019 *pos = *mci->pos_input;
4021 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4023 TreeInfo *ti = player_name_current;
4024 int first_entry = ti->cl_first;
4025 int entry_pos = first_entry + ti->cl_cursor;
4026 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4027 int xpos = MENU_SCREEN_START_XPOS;
4028 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4030 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4031 type_name_nr = entry_pos;
4033 strcpy(name, type_name_node->name);
4037 pos->width = MAX_PLAYER_NAME_LEN * 32;
4041 type_name_nr = user.nr;
4043 strcpy(name, setup.player_name);
4046 strcpy(type_name_last, name);
4048 if (strEqual(name, EMPTY_PLAYER_NAME))
4051 *xpos = strlen(name);
4054 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4056 // change name of edited user in global list of user names
4057 setString(&global.user_names[type_name_nr], name);
4059 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4061 TreeInfo *node = type_name_node;
4063 // change name of edited user in local menu tree structure
4064 setString(&node->name, name);
4065 setString(&node->name_sorting, name);
4067 node->color = getPlayerNameColor(name);
4068 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4072 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4075 boolean reset_setup = strEqual(name, "");
4076 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4077 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4080 strcpy(name, type_name_last);
4082 if (strEqual(name, ""))
4083 strcpy(name, EMPTY_PLAYER_NAME);
4085 setTypeNameValues_Name(name, pos);
4087 // if player name not changed, no further action required
4088 if (strEqual(name, type_name_last))
4091 // redraw player name before (possibly) opening request dialogs
4092 drawTypeNameText(name, pos, FALSE);
4094 int last_user_nr = user.nr;
4096 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4098 // save setup of currently active user (may differ from edited user)
4101 // temporarily change active user to edited user
4102 user.nr = type_name_nr;
4105 Request("Use current setup values for the new player?", REQ_ASK))
4107 // use current setup values for new user, but create new player UUID
4108 setup.player_uuid = getStringCopy(getUUID());
4112 // load setup for existing user (or start with defaults for new user)
4117 char *setup_filename = getSetupFilename();
4118 boolean setup_exists = fileExists(setup_filename);
4120 // change name of edited user in setup structure
4121 strcpy(setup.player_name, name);
4123 // save setup of edited user
4126 // change name of edited user on score server
4127 ApiRenamePlayerAsThread();
4129 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4133 if (Request("Reset setup values for this player?", REQ_ASK))
4135 // remove setup config file
4136 unlink(setup_filename);
4138 // set player name to default player name
4141 // update player name used by name typing functions
4142 strcpy(name, setup.player_name);
4144 setTypeNameValues_Name(name, pos);
4147 else if (remove_user && type_name_nr != 0)
4149 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4151 char *user_dir = getUserGameDataDir();
4152 char *user_dir_removed =
4153 getStringCat3WithSeparator(user_dir, "REMOVED",
4154 getCurrentTimestamp(), ".");
4156 if (rename(user_dir, user_dir_removed) != 0)
4157 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4159 checked_free(user_dir_removed);
4162 else if (create_user && type_name_nr != 0 && !setup_exists)
4164 if (Request("Create empty level set for the new player?", REQ_ASK))
4166 char *levelset_subdir = getNewUserLevelSubdir();
4168 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4170 AddUserLevelSetToLevelInfo(levelset_subdir);
4172 LevelDirTree *leveldir_current_last = leveldir_current;
4174 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4177 // set level number of newly created level set to default value
4178 LoadLevelSetup_SeriesInfo();
4180 // set newly created level set as current level set for new user
4181 SaveLevelSetup_LastSeries();
4182 SaveLevelSetup_SeriesInfo();
4184 leveldir_current = leveldir_current_last;
4188 Request("Creating new level set failed!", REQ_CONFIRM);
4193 // restore currently active user
4194 user.nr = last_user_nr;
4196 // restore setup of currently active user
4199 // restore last level set of currently active user
4200 LoadLevelSetup_LastSeries();
4201 LoadLevelSetup_SeriesInfo();
4205 static void HandleTypeNameExt(boolean initialize, Key key)
4207 static struct TextPosInfo pos_name = { 0 };
4208 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4209 static int xpos = 0;
4210 struct TextPosInfo *pos = &pos_name;
4211 char key_char = getValidConfigValueChar(getCharFromKey(key));
4212 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4213 boolean active = TRUE;
4217 getTypeNameValues(name, pos, &xpos);
4219 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4220 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4222 StartTextInput(sx, sy, pos->width, pos->height);
4224 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4226 name[xpos] = key_char;
4231 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4237 else if (key == KSYM_Return || key == KSYM_Escape)
4239 boolean changed = (key == KSYM_Return);
4243 setTypeNameValues(name, pos, changed);
4248 drawTypeNameText(name, pos, active);
4252 SetGameStatus(game_status_last_screen);
4254 if (game_status == GAME_MODE_MAIN)
4255 InitializeMainControls();
4259 static void DrawTypeName(void)
4261 HandleTypeNameExt(TRUE, 0);
4264 void HandleTypeName(Key key)
4266 HandleTypeNameExt(FALSE, key);
4270 // ============================================================================
4271 // tree menu functions
4272 // ============================================================================
4274 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4276 if (game_status != GAME_MODE_SETUP ||
4277 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4280 int max_text_size = 0;
4283 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4284 max_text_size = MAX(max_text_size, strlen(node->name));
4286 int num_entries = numTreeInfoInGroup(ti);
4287 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4288 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4289 int text_width = max_text_size * getFontWidth(font_nr);
4290 int button_width = SC_MENUBUTTON_XSIZE;
4291 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4292 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4293 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4294 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4295 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4296 int align_xoffset = MAX(0, align_xoffset_raw);
4298 return align_xoffset;
4301 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4303 if (game_status != GAME_MODE_SETUP ||
4304 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4307 int num_entries = numTreeInfoInGroup(ti);
4308 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4309 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4310 int font_height = getFontHeight(font_nr);
4311 int text_height = font_height * num_page_entries;
4312 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4313 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4314 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4315 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4316 int align_yoffset = MAX(0, align_yoffset_raw);
4318 return align_yoffset;
4321 static void DrawChooseTree(TreeInfo **ti_ptr)
4323 int fade_mask = REDRAW_FIELD;
4324 boolean restart_music = (game_status != game_status_last_screen &&
4325 game_status_last_screen != GAME_MODE_SCOREINFO);
4328 fade_mask = REDRAW_ALL;
4330 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4332 if (game_status == GAME_MODE_SETUP)
4336 else // GAME_MODE_LEVELS
4338 SetGameStatus(GAME_MODE_MAIN);
4348 FreeScreenGadgets();
4349 CreateScreenGadgets();
4352 FadeMenuSoundsAndMusic();
4356 // needed if different viewport properties defined for this screen
4357 ChangeViewportPropertiesIfNeeded();
4359 if (game_status == GAME_MODE_NAMES)
4360 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4361 else if (game_status == GAME_MODE_LEVELNR)
4362 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4363 else if (game_status == GAME_MODE_LEVELS)
4364 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4365 else if (game_status == GAME_MODE_SCORES)
4366 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4370 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4372 // map gadgets for high score screen
4373 if (game_status == GAME_MODE_SCORES)
4374 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4376 MapScreenTreeGadgets(*ti_ptr);
4378 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4380 DrawMaskedBorder(fade_mask);
4383 PlayMenuSoundsAndMusic();
4388 static int getChooseTreeFont(TreeInfo *node, boolean active)
4390 if (game_status == GAME_MODE_SCORES)
4391 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4393 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4396 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4398 int num_entries = numTreeInfoInGroup(ti);
4399 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4400 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4401 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4402 int first_entry = ti->cl_first;
4403 int entry_pos = first_entry + y;
4404 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4405 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4406 int font_nr = getChooseTreeFont(node, active);
4407 int font_xoffset = getFontDrawOffsetX(font_nr);
4408 int xpos = MENU_SCREEN_START_XPOS;
4409 int ypos = MENU_SCREEN_START_YPOS + y;
4410 int startdx = xpos * 32;
4411 int startdy = ypos * 32;
4412 int startx = amSX + startdx;
4413 int starty = amSY + startdy;
4414 int startx_text = startx + font_xoffset;
4415 int endx_text = amSX + screen_width;
4416 int max_text_size = endx_text - startx_text;
4417 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4418 char buffer[max_buffer_len + 1];
4420 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4422 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4423 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4424 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4425 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4426 int font_size_1 = getFontWidth(font_nr1);
4427 int font_size_3 = getFontWidth(font_nr3);
4428 int font_size_4 = getFontWidth(font_nr4);
4429 int text_size_1 = 4 * font_size_1;
4430 int text_size_4 = 5 * font_size_4;
4431 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4433 int dx3 = text_size_1;
4434 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4435 int num_dots = (dx4 - dx3) / font_size_3;
4436 int startx1 = startx + dx1;
4437 int startx3 = startx + dx3;
4438 int startx4 = startx + dx4;
4439 int pos = node->pos;
4440 char *pos_text = getHallOfFameRankText(pos, 3);
4443 DrawText(startx1, starty, pos_text, font_nr1);
4445 for (i = 0; i < num_dots; i++)
4446 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4448 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4449 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4451 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4455 strncpy(buffer, node->name, max_buffer_len);
4456 buffer[max_buffer_len] = '\0';
4458 DrawText(startx, starty, buffer, font_nr);
4462 static void drawChooseTreeHeadExt(int type, char *title_string)
4464 int yoffset_sets = MENU_TITLE1_YPOS;
4465 int yoffset_setup = 16;
4466 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4467 type == TREE_TYPE_LEVEL_DIR ||
4468 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4470 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4473 static void drawChooseTreeHead(TreeInfo *ti)
4475 drawChooseTreeHeadExt(ti->type, ti->infotext);
4478 static void drawChooseTreeList(TreeInfo *ti)
4480 int first_entry = ti->cl_first;
4481 int num_entries = numTreeInfoInGroup(ti);
4482 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4485 clearMenuListArea();
4487 for (i = 0; i < num_page_entries; i++)
4489 TreeInfo *node, *node_first;
4490 int entry_pos = first_entry + i;
4492 node_first = getTreeInfoFirstGroupEntry(ti);
4493 node = getTreeInfoFromPos(node_first, entry_pos);
4495 drawChooseTreeText(ti, i, FALSE);
4497 if (node->parent_link)
4498 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4499 else if (node->level_group)
4500 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4502 initCursor(i, IMG_MENU_BUTTON);
4504 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4505 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4507 if (game_status == GAME_MODE_NAMES)
4508 drawChooseTreeEdit(i, FALSE);
4511 redraw_mask |= REDRAW_FIELD;
4514 static void drawChooseTreeInfo(TreeInfo *ti)
4516 int entry_pos = ti->cl_first + ti->cl_cursor;
4517 int last_redraw_mask = redraw_mask;
4518 int ypos = MENU_TITLE2_YPOS;
4519 int font_nr = FONT_TITLE_2;
4522 if (ti->type == TREE_TYPE_LEVEL_NR)
4523 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4525 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4526 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4527 scores.last_level_nr);
4529 if (ti->type != TREE_TYPE_LEVEL_DIR)
4532 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4533 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4535 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4537 if (node->parent_link)
4538 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4539 node->node_parent->name);
4540 else if (node->level_group)
4541 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4543 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4544 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4545 node->levels, (node->levels > 1 ? "levels" : "level"),
4548 // let BackToFront() redraw only what is needed
4549 redraw_mask = last_redraw_mask;
4550 for (x = 0; x < SCR_FIELDX; x++)
4551 MarkTileDirty(x, 1);
4554 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4556 drawChooseTreeCursor(ti->cl_cursor, active);
4557 drawChooseTreeText(ti, ti->cl_cursor, active);
4560 static void drawChooseTreeScreen(TreeInfo *ti)
4562 drawChooseTreeHead(ti);
4563 drawChooseTreeList(ti);
4564 drawChooseTreeInfo(ti);
4565 drawChooseTreeCursorAndText(ti, TRUE);
4567 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4569 // scroll bar and buttons may just have been added after reloading scores
4570 if (game_status == GAME_MODE_SCORES)
4571 MapScreenTreeGadgets(ti);
4574 static void drawChooseTreeScreen_Scores_NotAvailable(void)
4576 // dirty workaround to use spacing definitions from info screen
4577 info_mode = INFO_MODE_TITLE;
4579 char *text_info = "HighScores of Level %d";
4580 char *text_title = "Score information:";
4581 char *text_error = "No scores for this level.";
4582 char *text_foot = "Press any key or button for main menu";
4583 int font_info = FONT_TITLE_2;
4584 int font_title = FONT_INITIAL_3;
4585 int font_error = FONT_INITIAL_4;
4586 int font_foot = FONT_INITIAL_2;
4587 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
4588 int ystep_title = getMenuTextStep(spacing_title, font_title);
4589 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
4590 int ystart2 = ystart1 + ystep_title;
4591 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4592 int ystart0 = MENU_TITLE2_YPOS;
4594 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
4595 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
4597 DrawTextSCentered(ystart1, font_title, text_title);
4598 DrawTextSCentered(ystart2, font_error, text_error);
4600 DrawTextSCentered(ybottom, font_foot, text_foot);
4603 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4605 int score_pos = scores.last_added;
4607 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4608 score_pos = scores.last_entry_nr;
4610 // set current tree entry to last added score entry
4611 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4613 // if that fails, set current tree entry to first entry (back link)
4614 if (*ti_ptr == NULL)
4615 *ti_ptr = score_entries->node_group;
4617 int num_entries = numTreeInfoInGroup(*ti_ptr);
4618 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4619 int pos_score = getPosFromTreeInfo(*ti_ptr);
4620 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4621 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4623 (*ti_ptr)->cl_first = pos_first;
4624 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4629 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4632 TreeInfo *ti = *ti_ptr;
4633 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4634 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4635 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4636 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4637 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4639 int y = (ti != NULL ? ti->cl_cursor : 0);
4640 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4641 int num_entries = numTreeInfoInGroup(ti);
4642 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4643 boolean position_set_by_scrollbar = (dx == 999);
4644 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
4645 boolean button_is_valid = (mx >= 0 && my >= 0);
4646 boolean button_screen_clicked = (button_action && button_is_valid);
4648 if (game_status == GAME_MODE_SCORES)
4650 if (server_scores.updated)
4652 // reload scores, using updated server score cache file
4653 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4655 server_scores.updated = FALSE;
4657 DrawHallOfFame_setScoreEntries();
4659 if (score_entries != NULL)
4661 ti = setHallOfFameActiveEntry(ti_ptr);
4663 if (button != MB_MENU_INITIALIZE)
4664 drawChooseTreeScreen(ti);
4668 if (score_entries == NULL)
4670 if (button == MB_MENU_INITIALIZE)
4672 drawChooseTreeScreen_Scores_NotAvailable();
4674 else if (button_screen_clicked)
4676 PlaySound(SND_MENU_ITEM_SELECTING);
4678 SetGameStatus(GAME_MODE_MAIN);
4687 if (button == MB_MENU_INITIALIZE)
4689 int num_entries = numTreeInfoInGroup(ti);
4690 int entry_pos = getPosFromTreeInfo(ti);
4692 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4693 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4695 if (game_status == GAME_MODE_SCORES)
4697 ti = setHallOfFameActiveEntry(ti_ptr);
4699 else if (ti->cl_first == -1)
4701 // only on initialization
4702 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4703 ti->cl_cursor = entry_pos - ti->cl_first;
4706 else if (ti->cl_cursor >= num_page_entries ||
4707 (num_entries > num_page_entries &&
4708 num_entries - ti->cl_first < num_page_entries))
4710 // only after change of list size (by custom graphic configuration)
4711 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4712 ti->cl_cursor = entry_pos - ti->cl_first;
4715 if (position_set_by_scrollbar)
4718 drawChooseTreeScreen(ti);
4722 else if (button == MB_MENU_LEAVE)
4724 if (game_status != GAME_MODE_SCORES)
4727 PlaySound(SND_MENU_ITEM_SELECTING);
4729 if (ti->node_parent)
4731 *ti_ptr = ti->node_parent;
4732 DrawChooseTree(ti_ptr);
4734 else if (game_status == GAME_MODE_SETUP)
4736 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4737 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4738 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4739 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4741 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4742 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4743 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4744 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4745 execSetupGraphics();
4746 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4747 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4748 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4750 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4751 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4752 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4753 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4754 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4755 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4756 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4757 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4764 if (game_status == GAME_MODE_LEVELNR)
4766 int new_level_nr = atoi(level_number_current->identifier);
4768 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4771 SetGameStatus(GAME_MODE_MAIN);
4779 if (mx || my) // mouse input
4781 scores.was_just_playing = FALSE;
4783 x = (mx - amSX) / 32;
4784 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4786 if (game_status == GAME_MODE_NAMES)
4787 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4789 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4791 scores.was_just_playing = FALSE;
4793 // move cursor instead of scrolling when already at start/end of list
4794 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4796 else if (dy == +1 * SCROLL_LINE &&
4797 ti->cl_first + num_page_entries == num_entries)
4800 // handle scrolling screen one line or page
4801 if (ti->cl_cursor + dy < 0 ||
4802 ti->cl_cursor + dy > num_page_entries - 1)
4804 boolean redraw = FALSE;
4806 if (ABS(dy) == SCROLL_PAGE)
4807 step = num_page_entries - 1;
4809 if (dy < 0 && ti->cl_first > 0)
4811 // scroll page/line up
4813 ti->cl_first -= step;
4814 if (ti->cl_first < 0)
4819 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4821 // scroll page/line down
4823 ti->cl_first += step;
4824 if (ti->cl_first + num_page_entries > num_entries)
4825 ti->cl_first = MAX(0, num_entries - num_page_entries);
4831 drawChooseTreeScreen(ti);
4836 // handle moving cursor one line
4837 y = ti->cl_cursor + dy;
4840 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
4842 HandleHallOfFame_SelectLevel(1, dx);
4848 TreeInfo *node_first, *node_cursor;
4849 int entry_pos = ti->cl_first + y;
4851 node_first = getTreeInfoFirstGroupEntry(ti);
4852 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4854 if (node_cursor->node_group)
4858 PlaySound(SND_MENU_ITEM_SELECTING);
4860 node_cursor->cl_first = ti->cl_first;
4861 node_cursor->cl_cursor = ti->cl_cursor;
4862 *ti_ptr = node_cursor->node_group;
4863 DrawChooseTree(ti_ptr);
4868 else if (dx == -1 && ti->node_parent)
4872 PlaySound(SND_MENU_ITEM_SELECTING);
4874 *ti_ptr = ti->node_parent;
4875 DrawChooseTree(ti_ptr);
4880 if (!anyScrollbarGadgetActive() &&
4881 IN_VIS_MENU(x, y) &&
4882 mx < mx_right_border &&
4883 y >= 0 && y < num_page_entries)
4887 if (game_status == GAME_MODE_NAMES)
4889 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4890 drawChooseTreeEdit(y, TRUE);
4893 if (y != ti->cl_cursor)
4895 PlaySound(SND_MENU_ITEM_ACTIVATING);
4897 drawChooseTreeCursorAndText(ti, FALSE);
4901 drawChooseTreeCursorAndText(ti, TRUE);
4903 drawChooseTreeInfo(ti);
4907 if (game_status == GAME_MODE_SETUP)
4909 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4910 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4911 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4912 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4914 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4915 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4916 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4917 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4918 execSetupGraphics();
4919 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4920 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4921 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4923 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4924 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4925 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4926 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4927 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4928 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4929 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4930 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4939 TreeInfo *node_first, *node_cursor;
4940 int entry_pos = ti->cl_first + y;
4942 PlaySound(SND_MENU_ITEM_SELECTING);
4944 node_first = getTreeInfoFirstGroupEntry(ti);
4945 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4947 if (node_cursor->node_group)
4951 node_cursor->cl_first = ti->cl_first;
4952 node_cursor->cl_cursor = ti->cl_cursor;
4953 *ti_ptr = node_cursor->node_group;
4954 DrawChooseTree(ti_ptr);
4956 else if (node_cursor->parent_link)
4958 if (game_status != GAME_MODE_SCORES)
4961 *ti_ptr = node_cursor->node_parent;
4962 DrawChooseTree(ti_ptr);
4966 if (game_status != GAME_MODE_SCORES)
4969 node_cursor->cl_first = ti->cl_first;
4970 node_cursor->cl_cursor = ti->cl_cursor;
4971 *ti_ptr = node_cursor;
4973 if (ti->type == TREE_TYPE_LEVEL_DIR)
4975 LoadLevelSetup_SeriesInfo();
4977 SaveLevelSetup_LastSeries();
4978 SaveLevelSetup_SeriesInfo();
4982 if (game_status == GAME_MODE_SETUP)
4984 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4985 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4986 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4987 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4989 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4990 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4991 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4992 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4993 execSetupGraphics();
4994 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4995 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4996 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4998 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4999 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5000 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5001 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5002 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5003 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5004 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5005 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5012 if (game_status == GAME_MODE_LEVELNR)
5014 int new_level_nr = atoi(level_number_current->identifier);
5016 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5018 else if (game_status == GAME_MODE_LEVELS)
5020 // store level set if chosen from "last played level set" menu
5021 StoreLastPlayedLevels(leveldir_current);
5023 else if (game_status == GAME_MODE_NAMES)
5025 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5027 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5034 // change active user to selected user
5035 user.nr = entry_pos;
5037 // save number of new active user
5040 // load setup of new active user
5043 // load last level set of new active user
5044 LoadLevelSetup_LastSeries();
5045 LoadLevelSetup_SeriesInfo();
5047 // update list of last played level sets
5048 UpdateLastPlayedLevels_TreeInfo();
5052 ToggleFullscreenIfNeeded();
5053 ChangeWindowScalingIfNeeded();
5055 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5056 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5057 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5059 else if (game_status == GAME_MODE_SCORES)
5061 if (setup.auto_play_next_level && setup.increment_levels &&
5062 scores.last_level_nr < leveldir_current->last_level &&
5063 scores.was_just_playing &&
5066 StartGameActions(network.enabled, setup.autorecord,
5070 else if (!scores.was_just_playing)
5072 SetGameStatus(GAME_MODE_SCOREINFO);
5074 DrawScoreInfo(node_cursor->pos);
5080 SetGameStatus(GAME_MODE_MAIN);
5088 if (game_status == GAME_MODE_SCORES)
5089 PlayMenuSoundIfLoop();
5092 void DrawChoosePlayerName(void)
5096 if (player_name != NULL)
5098 freeTreeInfo(player_name);
5103 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5105 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5106 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5109 ti->node_top = &player_name;
5110 ti->sort_priority = 10000 + value;
5111 ti->color = getPlayerNameColor(global.user_names[i]);
5113 snprintf(identifier, sizeof(identifier), "%d", value);
5114 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5116 setString(&ti->identifier, identifier);
5117 setString(&ti->name, name);
5118 setString(&ti->name_sorting, name);
5120 pushTreeInfo(&player_name, ti);
5123 // sort player entries by player number
5124 sortTreeInfo(&player_name);
5126 // set current player entry to selected player entry
5127 player_name_current =
5128 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5130 // if that fails, set current player name to first available name
5131 if (player_name_current == NULL)
5132 player_name_current = player_name;
5134 DrawChooseTree(&player_name_current);
5137 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5139 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5142 void DrawChooseLevelSet(void)
5144 DrawChooseTree(&leveldir_current);
5147 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5149 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5152 void DrawChooseLevelNr(void)
5156 if (level_number != NULL)
5158 freeTreeInfo(level_number);
5160 level_number = NULL;
5163 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5165 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5166 char identifier[32], name[64];
5169 // temporarily load level info to get level name
5170 LoadLevelInfoOnly(i);
5172 ti->node_top = &level_number;
5173 ti->sort_priority = 10000 + value;
5174 ti->color = (level.no_level_file ? FC_BLUE :
5175 LevelStats_getSolved(i) ? FC_GREEN :
5176 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5178 snprintf(identifier, sizeof(identifier), "%d", value);
5179 snprintf(name, sizeof(name), "%03d: %s", value,
5180 (level.no_level_file ? "(no file)" : level.name));
5182 setString(&ti->identifier, identifier);
5183 setString(&ti->name, name);
5184 setString(&ti->name_sorting, name);
5186 pushTreeInfo(&level_number, ti);
5189 // sort level number values to start with lowest level number
5190 sortTreeInfo(&level_number);
5192 // set current level number to current level number
5193 level_number_current =
5194 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5196 // if that also fails, set current level number to first available level
5197 if (level_number_current == NULL)
5198 level_number_current = level_number;
5200 DrawChooseTree(&level_number_current);
5203 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5205 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5208 static void DrawHallOfFame_setScoreEntries(void)
5210 int max_empty_entries = 10; // at least show "top ten" list, if empty
5211 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5212 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5213 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5216 if (score_entries != NULL)
5218 freeTreeInfo(score_entries);
5220 score_entries = NULL;
5223 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5225 // do not add empty score entries if off-screen
5226 if (scores.entry[i].score == 0 &&
5227 scores.entry[i].time == 0 &&
5228 i >= min_score_entries)
5231 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5232 char identifier[32], name[64];
5235 ti->node_top = &score_entries;
5236 ti->sort_priority = 10000 + value;
5237 ti->color = FC_YELLOW;
5240 snprintf(identifier, sizeof(identifier), "%d", value);
5241 snprintf(name, sizeof(name), "%03d.", value + 1);
5243 setString(&ti->identifier, identifier);
5244 setString(&ti->name, name);
5245 setString(&ti->name_sorting, name);
5247 pushTreeInfo(&score_entries, ti);
5250 // sort score entries to start with highest score entry
5251 sortTreeInfo(&score_entries);
5253 // add top tree node to create back link to main menu
5254 score_entries = addTopTreeInfoNode(score_entries);
5256 // set current score entry to last added or highest score entry
5257 score_entry_current =
5258 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5260 // if that fails, set current score entry to first valid score entry
5261 if (score_entry_current == NULL)
5262 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5264 // ("score_entries" and "score_entry_current" may be NULL here)
5267 void DrawHallOfFame(int level_nr)
5269 scores.last_level_nr = level_nr;
5270 scores.was_just_playing = (game_status_last_screen == GAME_MODE_PLAYING);
5272 // (this is needed when called from GameEnd() after winning a game)
5273 KeyboardAutoRepeatOn();
5275 // (this is needed when called from GameEnd() after winning a game)
5276 SetDrawDeactivationMask(REDRAW_NONE);
5277 SetDrawBackgroundMask(REDRAW_FIELD);
5279 LoadLocalAndServerScore(level_nr, TRUE);
5281 DrawHallOfFame_setScoreEntries();
5283 if (scores.last_added >= 0)
5284 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5286 FadeSetEnterScreen();
5288 DrawChooseTree(&score_entry_current);
5291 static char *getHallOfFameRankText(int nr, int size)
5293 static char rank_text[10];
5294 boolean forced = (scores.force_last_added && nr == scores.last_added);
5295 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5297 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5302 static char *getHallOfFameTimeText(int nr)
5304 static char score_text[10];
5305 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5306 int mm = (time_seconds / 60) % 60;
5307 int ss = (time_seconds % 60);
5309 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5314 static char *getHallOfFameScoreText(int nr, int size)
5316 if (!level.rate_time_over_score)
5317 return int2str(scores.entry[nr].score, size); // show normal score
5318 else if (level.use_step_counter)
5319 return int2str(scores.entry[nr].time, size); // show number of steps
5321 return getHallOfFameTimeText(nr); // show playing time
5324 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5326 static char tape_date[MAX_ISO_DATE_LEN + 1];
5329 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5330 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5331 return entry->tape_date;
5333 for (i = 0, j = 0; i < 8; i++, j++)
5335 tape_date[j] = entry->tape_basename[i];
5337 if (i == 3 || i == 5)
5338 tape_date[++j] = '-';
5341 tape_date[MAX_ISO_DATE_LEN] = '\0';
5346 static void HandleHallOfFame_SelectLevel(int step, int direction)
5348 int old_level_nr = scores.last_level_nr;
5349 int new_level_nr = old_level_nr + step * direction;
5351 if (new_level_nr < leveldir_current->first_level)
5352 new_level_nr = leveldir_current->first_level;
5353 if (new_level_nr > leveldir_current->last_level)
5354 new_level_nr = leveldir_current->last_level;
5356 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5357 new_level_nr = leveldir_current->handicap_level;
5359 if (new_level_nr != old_level_nr)
5361 PlaySound(SND_MENU_ITEM_SELECTING);
5363 scores.last_level_nr = level_nr = new_level_nr;
5364 scores.last_entry_nr = 0;
5366 LoadLevel(level_nr);
5367 LoadLocalAndServerScore(level_nr, TRUE);
5369 DrawHallOfFame_setScoreEntries();
5371 if (game_status == GAME_MODE_SCORES)
5373 // force remapping optional gadgets (especially scroll bar)
5374 UnmapScreenTreeGadgets();
5376 // redraw complete high score screen, as sub-title has changed
5379 // redraw level selection buttons (which have just been erased)
5380 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5382 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5386 DrawScoreInfo_Content(scores.last_entry_nr);
5389 SaveLevelSetup_SeriesInfo();
5393 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5395 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5398 static void DrawScoreInfo_Content(int entry_nr)
5400 struct ScoreEntry *entry = &scores.entry[entry_nr];
5401 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5402 char *tape_date = getHallOfFameTapeDateText(entry);
5403 int font_title = MENU_INFO_FONT_TITLE;
5404 int font_head = MENU_INFO_FONT_HEAD;
5405 int font_text = MENU_INFO_FONT_TEXT;
5406 int font_foot = MENU_INFO_FONT_FOOT;
5407 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5408 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5409 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5410 int xstep = getFontWidth(font_text);
5411 int ystep_title = getMenuTextStep(spacing_title, font_title);
5412 int ystep_para = getMenuTextStep(spacing_para, font_text);
5413 int ystep_line = getMenuTextStep(spacing_line, font_text);
5414 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5415 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5416 int xstart1 = mSX - SX + 2 * xstep;
5417 int xstart2 = mSX - SX + 13 * xstep;
5418 int select_x = SX + xstart1;
5419 int select_y1, select_y2;
5421 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5422 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5423 int font_width = getFontWidth(font_text);
5424 int font_height = getFontHeight(font_text);
5425 int tape_date_width = getTextWidth(tape_date, font_text);
5426 int pad_left = xstart2;
5427 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
5428 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5429 int max_lines_per_text = 5;
5434 // redraw score selection buttons (which have just been erased)
5435 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5437 if (score_entries == NULL)
5439 drawChooseTreeScreen_Scores_NotAvailable();
5444 drawChooseTreeHead(score_entries);
5445 drawChooseTreeInfo(score_entries);
5447 DrawTextSCentered(ystart, font_title, "Score Information:");
5448 ystart += ystep_title;
5450 DrawTextF(xstart1, ystart, font_head, "Level Set");
5451 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5452 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5453 TRUE, FALSE, FALSE);
5454 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5456 DrawTextF(xstart1, ystart, font_head, "Level");
5457 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5458 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5459 TRUE, FALSE, FALSE);
5460 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5462 select_y1 = SY + ystart;
5463 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5465 DrawTextF(xstart1, ystart, font_head, "Rank");
5466 DrawTextF(xstart2, ystart, font_text, pos_text);
5467 ystart += ystep_line;
5469 DrawTextF(xstart1, ystart, font_head, "Player");
5470 DrawTextF(xstart2, ystart, font_text, entry->name);
5471 ystart += ystep_line;
5473 if (level.use_step_counter)
5475 DrawTextF(xstart1, ystart, font_head, "Steps");
5476 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5477 ystart += ystep_line;
5481 DrawTextF(xstart1, ystart, font_head, "Time");
5482 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5483 ystart += ystep_line;
5486 if (!level.rate_time_over_score || entry->score > 0)
5488 DrawTextF(xstart1, ystart, font_head, "Score");
5489 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5490 ystart += ystep_line;
5493 ystart += ystep_line;
5495 play_x = SX + xstart2 + tape_date_width + font_width;
5496 play_y = SY + ystart + (font_height - play_height) / 2;
5498 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5499 DrawTextF(xstart2, ystart, font_text, tape_date);
5500 ystart += ystep_line;
5502 DrawTextF(xstart1, ystart, font_head, "Platform");
5503 DrawTextF(xstart2, ystart, font_text, entry->platform);
5504 ystart += ystep_line;
5506 DrawTextF(xstart1, ystart, font_head, "Version");
5507 DrawTextF(xstart2, ystart, font_text, entry->version);
5508 ystart += ystep_line;
5510 DrawTextF(xstart1, ystart, font_head, "Country");
5511 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5512 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5513 TRUE, FALSE, FALSE);
5514 ystart += ystep_line;
5516 select_y2 = SY + ystart;
5518 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5520 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5521 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5524 static void DrawScoreInfo(int entry_nr)
5526 scores.last_entry_nr = entry_nr;
5527 score_info_tape_play = FALSE;
5531 FadeOut(REDRAW_FIELD);
5533 // needed if different viewport properties defined after playing score tape
5534 ChangeViewportPropertiesIfNeeded();
5536 // needed if different background image defined after playing score tape
5537 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5538 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5540 DrawScoreInfo_Content(entry_nr);
5542 // map gadgets for score info screen
5543 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5545 FadeIn(REDRAW_FIELD);
5548 static void HandleScoreInfo_SelectScore(int step, int direction)
5550 int old_entry_nr = scores.last_entry_nr;
5551 int new_entry_nr = old_entry_nr + step * direction;
5552 int num_nodes = numTreeInfoInGroup(score_entry_current);
5553 int num_entries = num_nodes - 1; // score nodes only, without back link
5555 if (new_entry_nr < 0)
5557 if (new_entry_nr > num_entries - 1)
5558 new_entry_nr = num_entries - 1;
5560 if (new_entry_nr != old_entry_nr)
5562 scores.last_entry_nr = new_entry_nr;
5564 DrawScoreInfo_Content(new_entry_nr);
5568 static void HandleScoreInfo_PlayTape(void)
5570 if (!PlayScoreTape(scores.last_entry_nr))
5572 DrawScoreInfo_Content(scores.last_entry_nr);
5574 FadeIn(REDRAW_FIELD);
5578 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5580 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5581 boolean button_is_valid = (mx >= 0 && my >= 0);
5582 boolean button_screen_clicked = (button_action && button_is_valid);
5584 if (server_scores.updated)
5586 // reload scores, using updated server score cache file
5587 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5589 server_scores.updated = FALSE;
5591 DrawHallOfFame_setScoreEntries();
5593 DrawScoreInfo_Content(scores.last_entry_nr);
5596 if (button_screen_clicked)
5598 PlaySound(SND_MENU_ITEM_SELECTING);
5600 SetGameStatus(GAME_MODE_SCORES);
5602 DrawHallOfFame(scores.last_level_nr);
5606 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5610 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5615 // ============================================================================
5616 // setup screen functions
5617 // ============================================================================
5619 static struct TokenInfo *setup_info;
5620 static int num_setup_info; // number of setup entries shown on screen
5621 static int max_setup_info; // total number of setup entries in list
5623 static char *window_size_text;
5624 static char *scaling_type_text;
5625 static char *rendering_mode_text;
5626 static char *vsync_mode_text;
5627 static char *scroll_delay_text;
5628 static char *snapshot_mode_text;
5629 static char *game_speed_text;
5630 static char *scores_type_text;
5631 static char *network_server_text;
5632 static char *graphics_set_name;
5633 static char *sounds_set_name;
5634 static char *music_set_name;
5635 static char *volume_simple_text;
5636 static char *volume_loops_text;
5637 static char *volume_music_text;
5638 static char *touch_controls_text;
5639 static char *move_distance_text;
5640 static char *drop_distance_text;
5641 static char *transparency_text;
5642 static char *grid_size_text[2][2];
5644 static void execSetupMain(void)
5646 setup_mode = SETUP_MODE_MAIN;
5651 static void execSetupGame_setScoresType(void)
5653 if (scores_types == NULL)
5657 for (i = 0; scores_types_list[i].value != NULL; i++)
5659 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5660 char identifier[32], name[32];
5661 char *value = scores_types_list[i].value;
5662 char *text = scores_types_list[i].text;
5664 ti->node_top = &scores_types;
5665 ti->sort_priority = i;
5667 sprintf(identifier, "%s", value);
5668 sprintf(name, "%s", text);
5670 setString(&ti->identifier, identifier);
5671 setString(&ti->name, name);
5672 setString(&ti->name_sorting, name);
5673 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5675 pushTreeInfo(&scores_types, ti);
5678 // sort scores type values to start with lowest scores type value
5679 sortTreeInfo(&scores_types);
5681 // set current scores type value to configured scores type value
5682 scores_type_current =
5683 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5685 // if that fails, set current scores type to reliable default value
5686 if (scores_type_current == NULL)
5687 scores_type_current =
5688 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5690 // if that also fails, set current scores type to first available value
5691 if (scores_type_current == NULL)
5692 scores_type_current = scores_types;
5695 setup.scores_in_highscore_list = scores_type_current->identifier;
5697 // needed for displaying scores type text instead of identifier
5698 scores_type_text = scores_type_current->name;
5701 static void execSetupGame_setGameSpeeds(boolean update_value)
5703 if (setup.game_speed_extended)
5705 game_speeds_list = game_speeds_list_extended;
5706 game_speeds = game_speeds_extended;
5710 game_speeds_list = game_speeds_list_normal;
5711 game_speeds = game_speeds_normal;
5714 if (game_speeds == NULL)
5718 for (i = 0; game_speeds_list[i].value != -1; i++)
5720 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5721 char identifier[32], name[32];
5722 int value = game_speeds_list[i].value;
5723 char *text = game_speeds_list[i].text;
5725 ti->node_top = &game_speeds;
5726 ti->sort_priority = 10000 - value;
5728 sprintf(identifier, "%d", value);
5729 sprintf(name, "%s", text);
5731 setString(&ti->identifier, identifier);
5732 setString(&ti->name, name);
5733 setString(&ti->name_sorting, name);
5734 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5736 pushTreeInfo(&game_speeds, ti);
5739 // sort game speed values to start with slowest game speed
5740 sortTreeInfo(&game_speeds);
5742 update_value = TRUE;
5747 // set current game speed to configured game speed value
5748 game_speed_current =
5749 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5751 // if that fails, set current game speed to reliable default value
5752 if (game_speed_current == NULL)
5753 game_speed_current =
5754 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5756 // if that also fails, set current game speed to first available speed
5757 if (game_speed_current == NULL)
5758 game_speed_current = game_speeds;
5760 if (setup.game_speed_extended)
5761 game_speeds_extended = game_speeds;
5763 game_speeds_normal = game_speeds;
5766 setup.game_frame_delay = atoi(game_speed_current->identifier);
5768 // needed for displaying game speed text instead of identifier
5769 game_speed_text = game_speed_current->name;
5772 static void execSetupGame_setScrollDelays(void)
5774 if (scroll_delays == NULL)
5778 for (i = 0; scroll_delays_list[i].value != -1; i++)
5780 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5781 char identifier[32], name[32];
5782 int value = scroll_delays_list[i].value;
5783 char *text = scroll_delays_list[i].text;
5785 ti->node_top = &scroll_delays;
5786 ti->sort_priority = value;
5788 sprintf(identifier, "%d", value);
5789 sprintf(name, "%s", text);
5791 setString(&ti->identifier, identifier);
5792 setString(&ti->name, name);
5793 setString(&ti->name_sorting, name);
5794 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5796 pushTreeInfo(&scroll_delays, ti);
5799 // sort scroll delay values to start with lowest scroll delay value
5800 sortTreeInfo(&scroll_delays);
5802 // set current scroll delay value to configured scroll delay value
5803 scroll_delay_current =
5804 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5806 // if that fails, set current scroll delay to reliable default value
5807 if (scroll_delay_current == NULL)
5808 scroll_delay_current =
5809 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5811 // if that also fails, set current scroll delay to first available value
5812 if (scroll_delay_current == NULL)
5813 scroll_delay_current = scroll_delays;
5816 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5818 // needed for displaying scroll delay text instead of identifier
5819 scroll_delay_text = scroll_delay_current->name;
5822 static void execSetupGame_setSnapshotModes(void)
5824 if (snapshot_modes == NULL)
5828 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5830 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5831 char identifier[32], name[32];
5832 char *value = snapshot_modes_list[i].value;
5833 char *text = snapshot_modes_list[i].text;
5835 ti->node_top = &snapshot_modes;
5836 ti->sort_priority = i;
5838 sprintf(identifier, "%s", value);
5839 sprintf(name, "%s", text);
5841 setString(&ti->identifier, identifier);
5842 setString(&ti->name, name);
5843 setString(&ti->name_sorting, name);
5844 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5846 pushTreeInfo(&snapshot_modes, ti);
5849 // sort snapshot mode values to start with lowest snapshot mode value
5850 sortTreeInfo(&snapshot_modes);
5852 // set current snapshot mode value to configured snapshot mode value
5853 snapshot_mode_current =
5854 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5856 // if that fails, set current snapshot mode to reliable default value
5857 if (snapshot_mode_current == NULL)
5858 snapshot_mode_current =
5859 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5861 // if that also fails, set current snapshot mode to first available value
5862 if (snapshot_mode_current == NULL)
5863 snapshot_mode_current = snapshot_modes;
5866 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5868 // needed for displaying snapshot mode text instead of identifier
5869 snapshot_mode_text = snapshot_mode_current->name;
5872 static void execSetupGame_setNetworkServerText(void)
5874 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5876 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5880 strncpy(network_server_hostname, setup.network_server_hostname,
5881 MAX_SETUP_TEXT_INPUT_LEN);
5882 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5885 // needed for displaying network server text instead of identifier
5886 network_server_text = network_server_hostname;
5889 static void execSetupGame(void)
5891 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5893 execSetupGame_setGameSpeeds(FALSE);
5894 execSetupGame_setScoresType();
5895 execSetupGame_setScrollDelays();
5896 execSetupGame_setSnapshotModes();
5898 execSetupGame_setNetworkServerText();
5900 if (!setup.provide_uploading_tapes)
5901 setHideSetupEntry(execOfferUploadTapes);
5903 setup_mode = SETUP_MODE_GAME;
5907 // check if vsync needs to be disabled for this game speed to work
5908 if (check_vsync_mode)
5909 DisableVsyncIfNeeded();
5912 static void execSetupChooseScoresType(void)
5914 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
5919 static void execSetupChooseGameSpeed(void)
5921 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5926 static void execSetupChooseScrollDelay(void)
5928 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5933 static void execSetupChooseSnapshotMode(void)
5935 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5940 static void execSetupEngines(void)
5942 setup_mode = SETUP_MODE_ENGINES;
5947 static void execSetupEditor(void)
5949 setup_mode = SETUP_MODE_EDITOR;
5954 static void execSetupGraphics_setWindowSizes(boolean update_list)
5956 if (window_sizes != NULL && update_list)
5958 freeTreeInfo(window_sizes);
5960 window_sizes = NULL;
5963 if (window_sizes == NULL)
5965 boolean current_window_size_found = FALSE;
5968 for (i = 0; window_sizes_list[i].value != -1; i++)
5970 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5971 char identifier[32], name[32];
5972 int value = window_sizes_list[i].value;
5973 char *text = window_sizes_list[i].text;
5975 ti->node_top = &window_sizes;
5976 ti->sort_priority = value;
5978 sprintf(identifier, "%d", value);
5979 sprintf(name, "%s", text);
5981 setString(&ti->identifier, identifier);
5982 setString(&ti->name, name);
5983 setString(&ti->name_sorting, name);
5984 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5986 pushTreeInfo(&window_sizes, ti);
5988 if (value == setup.window_scaling_percent)
5989 current_window_size_found = TRUE;
5992 if (!current_window_size_found)
5994 // add entry for non-preset window scaling value
5996 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5997 char identifier[32], name[32];
5998 int value = setup.window_scaling_percent;
6000 ti->node_top = &window_sizes;
6001 ti->sort_priority = value;
6003 sprintf(identifier, "%d", value);
6004 sprintf(name, "%d %% (Current)", value);
6006 setString(&ti->identifier, identifier);
6007 setString(&ti->name, name);
6008 setString(&ti->name_sorting, name);
6009 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6011 pushTreeInfo(&window_sizes, ti);
6014 // sort window size values to start with lowest window size value
6015 sortTreeInfo(&window_sizes);
6017 // set current window size value to configured window size value
6018 window_size_current =
6019 getTreeInfoFromIdentifier(window_sizes,
6020 i_to_a(setup.window_scaling_percent));
6022 // if that fails, set current window size to reliable default value
6023 if (window_size_current == NULL)
6024 window_size_current =
6025 getTreeInfoFromIdentifier(window_sizes,
6026 i_to_a(STD_WINDOW_SCALING_PERCENT));
6028 // if that also fails, set current window size to first available value
6029 if (window_size_current == NULL)
6030 window_size_current = window_sizes;
6033 setup.window_scaling_percent = atoi(window_size_current->identifier);
6035 // needed for displaying window size text instead of identifier
6036 window_size_text = window_size_current->name;
6039 static void execSetupGraphics_setScalingTypes(void)
6041 if (scaling_types == NULL)
6045 for (i = 0; scaling_types_list[i].value != NULL; i++)
6047 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6048 char identifier[32], name[32];
6049 char *value = scaling_types_list[i].value;
6050 char *text = scaling_types_list[i].text;
6052 ti->node_top = &scaling_types;
6053 ti->sort_priority = i;
6055 sprintf(identifier, "%s", value);
6056 sprintf(name, "%s", text);
6058 setString(&ti->identifier, identifier);
6059 setString(&ti->name, name);
6060 setString(&ti->name_sorting, name);
6061 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6063 pushTreeInfo(&scaling_types, ti);
6066 // sort scaling type values to start with lowest scaling type value
6067 sortTreeInfo(&scaling_types);
6069 // set current scaling type value to configured scaling type value
6070 scaling_type_current =
6071 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6073 // if that fails, set current scaling type to reliable default value
6074 if (scaling_type_current == NULL)
6075 scaling_type_current =
6076 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6078 // if that also fails, set current scaling type to first available value
6079 if (scaling_type_current == NULL)
6080 scaling_type_current = scaling_types;
6083 setup.window_scaling_quality = scaling_type_current->identifier;
6085 // needed for displaying scaling type text instead of identifier
6086 scaling_type_text = scaling_type_current->name;
6089 static void execSetupGraphics_setRenderingModes(void)
6091 if (rendering_modes == NULL)
6095 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6097 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6098 char identifier[32], name[32];
6099 char *value = rendering_modes_list[i].value;
6100 char *text = rendering_modes_list[i].text;
6102 ti->node_top = &rendering_modes;
6103 ti->sort_priority = i;
6105 sprintf(identifier, "%s", value);
6106 sprintf(name, "%s", text);
6108 setString(&ti->identifier, identifier);
6109 setString(&ti->name, name);
6110 setString(&ti->name_sorting, name);
6111 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6113 pushTreeInfo(&rendering_modes, ti);
6116 // sort rendering mode values to start with lowest rendering mode value
6117 sortTreeInfo(&rendering_modes);
6119 // set current rendering mode value to configured rendering mode value
6120 rendering_mode_current =
6121 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6123 // if that fails, set current rendering mode to reliable default value
6124 if (rendering_mode_current == NULL)
6125 rendering_mode_current =
6126 getTreeInfoFromIdentifier(rendering_modes,
6127 STR_SPECIAL_RENDERING_DEFAULT);
6129 // if that also fails, set current rendering mode to first available one
6130 if (rendering_mode_current == NULL)
6131 rendering_mode_current = rendering_modes;
6134 setup.screen_rendering_mode = rendering_mode_current->identifier;
6136 // needed for displaying rendering mode text instead of identifier
6137 rendering_mode_text = rendering_mode_current->name;
6140 static void execSetupGraphics_setVsyncModes(boolean update_value)
6142 if (vsync_modes == NULL)
6146 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6148 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6149 char identifier[32], name[32];
6150 char *value = vsync_modes_list[i].value;
6151 char *text = vsync_modes_list[i].text;
6153 ti->node_top = &vsync_modes;
6154 ti->sort_priority = i;
6156 sprintf(identifier, "%s", value);
6157 sprintf(name, "%s", text);
6159 setString(&ti->identifier, identifier);
6160 setString(&ti->name, name);
6161 setString(&ti->name_sorting, name);
6162 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6164 pushTreeInfo(&vsync_modes, ti);
6167 // sort vsync mode values to start with lowest vsync mode value
6168 sortTreeInfo(&vsync_modes);
6170 update_value = TRUE;
6175 // set current vsync mode value to configured vsync mode value
6176 vsync_mode_current =
6177 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6179 // if that fails, set current vsync mode to reliable default value
6180 if (vsync_mode_current == NULL)
6181 vsync_mode_current =
6182 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6184 // if that also fails, set current vsync mode to first available one
6185 if (vsync_mode_current == NULL)
6186 vsync_mode_current = vsync_modes;
6189 setup.vsync_mode = vsync_mode_current->identifier;
6191 // needed for displaying vsync mode text instead of identifier
6192 vsync_mode_text = vsync_mode_current->name;
6195 static void execSetupGraphics(void)
6197 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6199 // update "setup.window_scaling_percent" from list selection
6200 // (in this case, window scaling was changed on setup screen)
6201 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6202 execSetupGraphics_setWindowSizes(FALSE);
6204 // update "setup.vsync_mode" from list selection
6205 // (in this case, vsync mode was changed on setup screen)
6206 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6207 execSetupGraphics_setVsyncModes(FALSE);
6209 // update list selection from "setup.window_scaling_percent"
6210 // (window scaling may have changed by resizing the window)
6211 execSetupGraphics_setWindowSizes(TRUE);
6213 // update list selection from "setup.vsync_mode"
6214 // (vsync_mode may have changed by re-creating the renderer)
6215 execSetupGraphics_setVsyncModes(TRUE);
6217 execSetupGraphics_setScalingTypes();
6218 execSetupGraphics_setRenderingModes();
6220 setup_mode = SETUP_MODE_GRAPHICS;
6224 // check if game speed is high enough for 60 Hz vsync to work
6225 if (check_game_speed)
6226 ModifyGameSpeedIfNeeded();
6228 // window scaling may have changed at this point
6229 ChangeWindowScalingIfNeeded();
6231 // window scaling quality may have changed at this point
6232 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6233 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6235 // screen rendering mode may have changed at this point
6236 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6238 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6239 int video_vsync_mode = video.vsync_mode;
6241 // screen vsync mode may have changed at this point
6242 ChangeVsyncModeIfNeeded();
6244 // check if setting vsync mode to selected value failed
6245 if (setup_vsync_mode != video_vsync_mode &&
6246 setup_vsync_mode != video.vsync_mode)
6248 // changing vsync mode to selected value failed -- reset displayed value
6249 execSetupGraphics_setVsyncModes(TRUE);
6251 Request("Setting VSync failed!", REQ_CONFIRM);
6257 static void execSetupChooseWindowSize(void)
6259 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6264 static void execSetupChooseScalingType(void)
6266 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6271 static void execSetupChooseRenderingMode(void)
6273 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6278 static void execSetupChooseVsyncMode(void)
6280 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6285 static void execSetupChooseVolumeSimple(void)
6287 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6292 static void execSetupChooseVolumeLoops(void)
6294 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6299 static void execSetupChooseVolumeMusic(void)
6301 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6306 static void execSetupSound(void)
6308 if (volumes_simple == NULL)
6310 boolean current_volume_simple_found = FALSE;
6313 for (i = 0; volumes_list[i].value != -1; i++)
6315 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6316 char identifier[32], name[32];
6317 int value = volumes_list[i].value;
6318 char *text = volumes_list[i].text;
6320 ti->node_top = &volumes_simple;
6321 ti->sort_priority = value;
6323 sprintf(identifier, "%d", value);
6324 sprintf(name, "%s", text);
6326 setString(&ti->identifier, identifier);
6327 setString(&ti->name, name);
6328 setString(&ti->name_sorting, name);
6329 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6331 pushTreeInfo(&volumes_simple, ti);
6333 if (value == setup.volume_simple)
6334 current_volume_simple_found = TRUE;
6337 if (!current_volume_simple_found)
6339 // add entry for non-preset volume value
6341 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6342 char identifier[32], name[32];
6343 int value = setup.volume_simple;
6345 ti->node_top = &volumes_simple;
6346 ti->sort_priority = value;
6348 sprintf(identifier, "%d", value);
6349 sprintf(name, "%d %% (Current)", value);
6351 setString(&ti->identifier, identifier);
6352 setString(&ti->name, name);
6353 setString(&ti->name_sorting, name);
6354 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6356 pushTreeInfo(&volumes_simple, ti);
6359 // sort volume values to start with lowest volume value
6360 sortTreeInfo(&volumes_simple);
6362 // set current volume value to configured volume value
6363 volume_simple_current =
6364 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6366 // if that fails, set current volume to reliable default value
6367 if (volume_simple_current == NULL)
6368 volume_simple_current =
6369 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6371 // if that also fails, set current volume to first available value
6372 if (volume_simple_current == NULL)
6373 volume_simple_current = volumes_simple;
6376 if (volumes_loops == NULL)
6378 boolean current_volume_loops_found = FALSE;
6381 for (i = 0; volumes_list[i].value != -1; i++)
6383 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6384 char identifier[32], name[32];
6385 int value = volumes_list[i].value;
6386 char *text = volumes_list[i].text;
6388 ti->node_top = &volumes_loops;
6389 ti->sort_priority = value;
6391 sprintf(identifier, "%d", value);
6392 sprintf(name, "%s", text);
6394 setString(&ti->identifier, identifier);
6395 setString(&ti->name, name);
6396 setString(&ti->name_sorting, name);
6397 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6399 pushTreeInfo(&volumes_loops, ti);
6401 if (value == setup.volume_loops)
6402 current_volume_loops_found = TRUE;
6405 if (!current_volume_loops_found)
6407 // add entry for non-preset volume value
6409 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6410 char identifier[32], name[32];
6411 int value = setup.volume_loops;
6413 ti->node_top = &volumes_loops;
6414 ti->sort_priority = value;
6416 sprintf(identifier, "%d", value);
6417 sprintf(name, "%d %% (Current)", value);
6419 setString(&ti->identifier, identifier);
6420 setString(&ti->name, name);
6421 setString(&ti->name_sorting, name);
6422 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6424 pushTreeInfo(&volumes_loops, ti);
6427 // sort volume values to start with lowest volume value
6428 sortTreeInfo(&volumes_loops);
6430 // set current volume value to configured volume value
6431 volume_loops_current =
6432 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6434 // if that fails, set current volume to reliable default value
6435 if (volume_loops_current == NULL)
6436 volume_loops_current =
6437 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6439 // if that also fails, set current volume to first available value
6440 if (volume_loops_current == NULL)
6441 volume_loops_current = volumes_loops;
6444 if (volumes_music == NULL)
6446 boolean current_volume_music_found = FALSE;
6449 for (i = 0; volumes_list[i].value != -1; i++)
6451 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6452 char identifier[32], name[32];
6453 int value = volumes_list[i].value;
6454 char *text = volumes_list[i].text;
6456 ti->node_top = &volumes_music;
6457 ti->sort_priority = value;
6459 sprintf(identifier, "%d", value);
6460 sprintf(name, "%s", text);
6462 setString(&ti->identifier, identifier);
6463 setString(&ti->name, name);
6464 setString(&ti->name_sorting, name);
6465 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6467 pushTreeInfo(&volumes_music, ti);
6469 if (value == setup.volume_music)
6470 current_volume_music_found = TRUE;
6473 if (!current_volume_music_found)
6475 // add entry for non-preset volume value
6477 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6478 char identifier[32], name[32];
6479 int value = setup.volume_music;
6481 ti->node_top = &volumes_music;
6482 ti->sort_priority = value;
6484 sprintf(identifier, "%d", value);
6485 sprintf(name, "%d %% (Current)", value);
6487 setString(&ti->identifier, identifier);
6488 setString(&ti->name, name);
6489 setString(&ti->name_sorting, name);
6490 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6492 pushTreeInfo(&volumes_music, ti);
6495 // sort volume values to start with lowest volume value
6496 sortTreeInfo(&volumes_music);
6498 // set current volume value to configured volume value
6499 volume_music_current =
6500 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6502 // if that fails, set current volume to reliable default value
6503 if (volume_music_current == NULL)
6504 volume_music_current =
6505 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6507 // if that also fails, set current volume to first available value
6508 if (volume_music_current == NULL)
6509 volume_music_current = volumes_music;
6512 setup.volume_simple = atoi(volume_simple_current->identifier);
6513 setup.volume_loops = atoi(volume_loops_current->identifier);
6514 setup.volume_music = atoi(volume_music_current->identifier);
6516 // needed for displaying volume text instead of identifier
6517 volume_simple_text = volume_simple_current->name;
6518 volume_loops_text = volume_loops_current->name;
6519 volume_music_text = volume_music_current->name;
6521 setup_mode = SETUP_MODE_SOUND;
6526 static void execSetupChooseTouchControls(void)
6528 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6533 static void execSetupChooseMoveDistance(void)
6535 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6540 static void execSetupChooseDropDistance(void)
6542 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6547 static void execSetupChooseTransparency(void)
6549 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6554 static void execSetupChooseGridXSize_0(void)
6556 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6561 static void execSetupChooseGridYSize_0(void)
6563 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6568 static void execSetupChooseGridXSize_1(void)
6570 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6575 static void execSetupChooseGridYSize_1(void)
6577 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6582 static void execSetupConfigureVirtualButtons(void)
6584 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6586 ConfigureVirtualButtons();
6588 setup_mode = SETUP_MODE_TOUCH;
6593 static void execSetupTouch(void)
6597 if (touch_controls == NULL)
6599 for (i = 0; touch_controls_list[i].value != NULL; i++)
6601 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6602 char identifier[32], name[32];
6603 char *value = touch_controls_list[i].value;
6604 char *text = touch_controls_list[i].text;
6606 ti->node_top = &touch_controls;
6607 ti->sort_priority = i;
6609 sprintf(identifier, "%s", value);
6610 sprintf(name, "%s", text);
6612 setString(&ti->identifier, identifier);
6613 setString(&ti->name, name);
6614 setString(&ti->name_sorting, name);
6615 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6617 pushTreeInfo(&touch_controls, ti);
6620 // sort touch control values to start with lowest touch control value
6621 sortTreeInfo(&touch_controls);
6623 // set current touch control value to configured touch control value
6624 touch_control_current =
6625 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6627 // if that fails, set current touch control to reliable default value
6628 if (touch_control_current == NULL)
6629 touch_control_current =
6630 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6632 // if that also fails, set current touch control to first available value
6633 if (touch_control_current == NULL)
6634 touch_control_current = touch_controls;
6637 if (move_distances == NULL)
6639 for (i = 0; distances_list[i].value != -1; i++)
6641 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6642 char identifier[32], name[32];
6643 int value = distances_list[i].value;
6644 char *text = distances_list[i].text;
6646 ti->node_top = &move_distances;
6647 ti->sort_priority = value;
6649 sprintf(identifier, "%d", value);
6650 sprintf(name, "%s", text);
6652 setString(&ti->identifier, identifier);
6653 setString(&ti->name, name);
6654 setString(&ti->name_sorting, name);
6655 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6657 pushTreeInfo(&move_distances, ti);
6660 // sort distance values to start with lowest distance value
6661 sortTreeInfo(&move_distances);
6663 // set current distance value to configured distance value
6664 move_distance_current =
6665 getTreeInfoFromIdentifier(move_distances,
6666 i_to_a(setup.touch.move_distance));
6668 // if that fails, set current distance to reliable default value
6669 if (move_distance_current == NULL)
6670 move_distance_current =
6671 getTreeInfoFromIdentifier(move_distances,
6672 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6674 // if that also fails, set current distance to first available value
6675 if (move_distance_current == NULL)
6676 move_distance_current = move_distances;
6679 if (drop_distances == NULL)
6681 for (i = 0; distances_list[i].value != -1; i++)
6683 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6684 char identifier[32], name[32];
6685 int value = distances_list[i].value;
6686 char *text = distances_list[i].text;
6688 ti->node_top = &drop_distances;
6689 ti->sort_priority = value;
6691 sprintf(identifier, "%d", value);
6692 sprintf(name, "%s", text);
6694 setString(&ti->identifier, identifier);
6695 setString(&ti->name, name);
6696 setString(&ti->name_sorting, name);
6697 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6699 pushTreeInfo(&drop_distances, ti);
6702 // sort distance values to start with lowest distance value
6703 sortTreeInfo(&drop_distances);
6705 // set current distance value to configured distance value
6706 drop_distance_current =
6707 getTreeInfoFromIdentifier(drop_distances,
6708 i_to_a(setup.touch.drop_distance));
6710 // if that fails, set current distance to reliable default value
6711 if (drop_distance_current == NULL)
6712 drop_distance_current =
6713 getTreeInfoFromIdentifier(drop_distances,
6714 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6716 // if that also fails, set current distance to first available value
6717 if (drop_distance_current == NULL)
6718 drop_distance_current = drop_distances;
6721 if (transparencies == NULL)
6723 for (i = 0; transparencies_list[i].value != -1; i++)
6725 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6726 char identifier[32], name[32];
6727 int value = transparencies_list[i].value;
6728 char *text = transparencies_list[i].text;
6730 ti->node_top = &transparencies;
6731 ti->sort_priority = value;
6733 sprintf(identifier, "%d", value);
6734 sprintf(name, "%s", text);
6736 setString(&ti->identifier, identifier);
6737 setString(&ti->name, name);
6738 setString(&ti->name_sorting, name);
6739 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6741 pushTreeInfo(&transparencies, ti);
6744 // sort transparency values to start with lowest transparency value
6745 sortTreeInfo(&transparencies);
6747 // set current transparency value to configured transparency value
6748 transparency_current =
6749 getTreeInfoFromIdentifier(transparencies,
6750 i_to_a(setup.touch.transparency));
6752 // if that fails, set current transparency to reliable default value
6753 if (transparency_current == NULL)
6754 transparency_current =
6755 getTreeInfoFromIdentifier(transparencies,
6756 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6758 // if that also fails, set current transparency to first available value
6759 if (transparency_current == NULL)
6760 transparency_current = transparencies;
6763 for (i = 0; i < 2; i++)
6765 for (j = 0; j < 2; j++)
6767 if (grid_sizes[i][j] == NULL)
6769 for (k = 0; grid_sizes_list[k].value != -1; k++)
6771 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6772 char identifier[32], name[32];
6773 int value = grid_sizes_list[k].value;
6774 char *text = grid_sizes_list[k].text;
6776 ti->node_top = &grid_sizes[i][j];
6777 ti->sort_priority = value;
6779 sprintf(identifier, "%d", value);
6780 sprintf(name, "%s", text);
6782 setString(&ti->identifier, identifier);
6783 setString(&ti->name, name);
6784 setString(&ti->name_sorting, name);
6785 setString(&ti->infotext,
6788 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6789 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6791 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6792 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6794 pushTreeInfo(&grid_sizes[i][j], ti);
6797 // sort grid size values to start with lowest grid size value
6798 sortTreeInfo(&grid_sizes[i][j]);
6800 // set current grid size value to configured grid size value
6801 grid_size_current[i][j] =
6802 getTreeInfoFromIdentifier(grid_sizes[i][j],
6804 setup.touch.grid_xsize[i] :
6805 setup.touch.grid_ysize[i]));
6807 // if that fails, set current grid size to reliable default value
6808 if (grid_size_current[i][j] == NULL)
6809 grid_size_current[i][j] =
6810 getTreeInfoFromIdentifier(grid_sizes[i][j],
6812 DEFAULT_GRID_XSIZE(i) :
6813 DEFAULT_GRID_YSIZE(i)));
6815 // if that also fails, set current grid size to first available value
6816 if (grid_size_current[i][j] == NULL)
6817 grid_size_current[i][j] = grid_sizes[i][j];
6822 setup.touch.control_type = touch_control_current->identifier;
6823 setup.touch.move_distance = atoi(move_distance_current->identifier);
6824 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6825 setup.touch.transparency = atoi(transparency_current->identifier);
6827 for (i = 0; i < 2; i++)
6829 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6830 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6832 if (i == GRID_ACTIVE_NR())
6834 overlay.grid_xsize = setup.touch.grid_xsize[i];
6835 overlay.grid_ysize = setup.touch.grid_ysize[i];
6839 // needed for displaying value text instead of identifier
6840 touch_controls_text = touch_control_current->name;
6841 move_distance_text = move_distance_current->name;
6842 drop_distance_text = drop_distance_current->name;
6843 transparency_text = transparency_current->name;
6845 for (i = 0; i < 2; i++)
6846 for (j = 0; j < 2; j++)
6847 grid_size_text[i][j] = grid_size_current[i][j]->name;
6849 setup_mode = SETUP_MODE_TOUCH;
6854 static void execSetupArtwork(void)
6856 static ArtworkDirTree *gfx_last_valid = NULL;
6857 static ArtworkDirTree *snd_last_valid = NULL;
6858 static ArtworkDirTree *mus_last_valid = NULL;
6860 // current artwork directory may be invalid (level group, parent link)
6861 if (!validLevelSeries(artwork.gfx_current))
6862 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6863 if (!validLevelSeries(artwork.snd_current))
6864 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6865 if (!validLevelSeries(artwork.mus_current))
6866 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6868 // store valid artwork directory information
6869 gfx_last_valid = artwork.gfx_current;
6870 snd_last_valid = artwork.snd_current;
6871 mus_last_valid = artwork.mus_current;
6874 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6875 artwork.gfx_current->subdir,
6876 artwork.gfx_current->fullpath,
6877 artwork.gfx_current->basepath);
6880 setup.graphics_set = artwork.gfx_current->identifier;
6881 setup.sounds_set = artwork.snd_current->identifier;
6882 setup.music_set = artwork.mus_current->identifier;
6884 // needed if last screen (setup choice) changed graphics, sounds or music
6885 ReloadCustomArtwork(0);
6887 // needed for displaying artwork name instead of artwork identifier
6888 graphics_set_name = artwork.gfx_current->name;
6889 sounds_set_name = artwork.snd_current->name;
6890 music_set_name = artwork.mus_current->name;
6892 setup_mode = SETUP_MODE_ARTWORK;
6897 static void execSetupChooseGraphics(void)
6899 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6904 static void execSetupChooseSounds(void)
6906 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6911 static void execSetupChooseMusic(void)
6913 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6918 static void execSetupInput(void)
6920 setup_mode = SETUP_MODE_INPUT;
6925 static void execSetupShortcuts(void)
6927 setup_mode = SETUP_MODE_SHORTCUTS;
6932 static void execSetupShortcuts1(void)
6934 setup_mode = SETUP_MODE_SHORTCUTS_1;
6939 static void execSetupShortcuts2(void)
6941 setup_mode = SETUP_MODE_SHORTCUTS_2;
6946 static void execSetupShortcuts3(void)
6948 setup_mode = SETUP_MODE_SHORTCUTS_3;
6953 static void execSetupShortcuts4(void)
6955 setup_mode = SETUP_MODE_SHORTCUTS_4;
6960 static void execSetupShortcuts5(void)
6962 setup_mode = SETUP_MODE_SHORTCUTS_5;
6967 static void execExitSetup(void)
6969 SetGameStatus(GAME_MODE_MAIN);
6974 static void execSaveAndExitSetup(void)
6980 static void execGadgetNetworkServer(void)
6982 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6983 struct GadgetInfo *gi = screen_gadget[gadget_id];
6985 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6986 network_server_hostname[0] = '\0';
6988 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6992 ClickOnGadget(gi, MB_LEFTBUTTON);
6995 static void execOfferUploadTapes(void)
7000 static void ToggleNetworkModeIfNeeded(void)
7002 int font_title = FONT_TITLE_1;
7003 int font_foot = FC_BLUE;
7004 int ystart = mSY - SY + 16;
7005 int ybottom = mSY - SY + SYSIZE - 20;
7006 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7008 if (setup.network_mode == network.enabled)
7011 network.enabled = setup.network_mode;
7013 FadeOut(REDRAW_ALL);
7017 DrawTextSCentered(ystart, font_title, text);
7021 if (network.enabled)
7022 InitNetworkServer();
7024 DisconnectFromNetworkServer();
7026 DrawTextSCentered(ybottom, font_foot,
7027 "Press any key or button for setup menu");
7029 WaitForEventToContinue();
7034 static void ToggleGameSpeedsListIfNeeded(void)
7036 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7038 if (setup.game_speed_extended == using_game_speeds_extended)
7041 // try to match similar values when changing game speeds list
7042 if (setup.game_speed_extended)
7043 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7044 setup.game_frame_delay == 30 ? 29 :
7045 setup.game_frame_delay);
7047 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7048 setup.game_frame_delay == 16 ? 15 :
7049 setup.game_frame_delay >= 29 ? 30 :
7050 setup.game_frame_delay <= 10 ? 10 :
7051 setup.game_frame_delay);
7053 execSetupGame_setGameSpeeds(TRUE);
7058 static void ToggleUseApiServerIfNeeded(void)
7060 if (runtime.use_api_server == setup.use_api_server)
7063 runtime.use_api_server = setup.use_api_server;
7065 if (runtime.use_api_server)
7066 CheckApiServerTasks();
7069 static void ModifyGameSpeedIfNeeded(void)
7071 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7072 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7076 char *game_speed_text = "Fast";
7077 int game_speed_value = 15;
7079 if (setup.game_speed_extended)
7081 game_speed_text = "60 fps";
7082 game_speed_value = 16;
7085 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7087 // set game speed to existing list value that is fast enough for vsync
7088 setup.game_frame_delay = game_speed_value;
7090 execSetupGame_setGameSpeeds(TRUE);
7092 Request(message, REQ_CONFIRM);
7095 static void DisableVsyncIfNeeded(void)
7097 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7098 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7099 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7102 // disable vsync for the selected game speed to work
7103 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7105 execSetupGraphics_setVsyncModes(TRUE);
7107 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7113 void *related_value;
7114 } hide_related_entry_list[] =
7116 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7117 { &setup.scores_in_highscore_list, &scores_type_text },
7119 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7120 { &setup.game_frame_delay, &game_speed_text },
7122 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7123 { &setup.scroll_delay_value, &scroll_delay_text },
7125 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7126 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7128 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7129 { &setup.window_scaling_percent, &window_size_text },
7131 { &setup.window_scaling_quality, execSetupChooseScalingType },
7132 { &setup.window_scaling_quality, &scaling_type_text },
7134 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7135 { &setup.screen_rendering_mode, &rendering_mode_text },
7137 { &setup.vsync_mode, execSetupChooseVsyncMode },
7138 { &setup.vsync_mode, &vsync_mode_text },
7140 { &setup.graphics_set, execSetupChooseGraphics },
7141 { &setup.graphics_set, &graphics_set_name },
7143 { &setup.sounds_set, execSetupChooseSounds },
7144 { &setup.sounds_set, &sounds_set_name },
7146 { &setup.music_set, execSetupChooseMusic },
7147 { &setup.music_set, &music_set_name },
7149 { &setup.volume_simple, execSetupChooseVolumeSimple },
7150 { &setup.volume_simple, &volume_simple_text },
7152 { &setup.volume_loops, execSetupChooseVolumeLoops },
7153 { &setup.volume_loops, &volume_loops_text },
7155 { &setup.volume_music, execSetupChooseVolumeMusic },
7156 { &setup.volume_music, &volume_music_text },
7158 { &setup.touch.control_type, execSetupChooseTouchControls },
7159 { &setup.touch.control_type, &touch_controls_text },
7161 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7162 { &setup.touch.move_distance, &move_distance_text },
7164 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7165 { &setup.touch.drop_distance, &drop_distance_text },
7167 { &setup.touch.transparency, execSetupChooseTransparency },
7168 { &setup.touch.transparency, &transparency_text },
7170 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7171 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7173 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7174 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7176 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7177 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7179 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7180 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7182 { &setup.internal.menu_game, execSetupGame },
7183 { &setup.internal.menu_engines, execSetupEngines },
7184 { &setup.internal.menu_editor, execSetupEditor },
7185 { &setup.internal.menu_graphics, execSetupGraphics },
7186 { &setup.internal.menu_sound, execSetupSound },
7187 { &setup.internal.menu_artwork, execSetupArtwork },
7188 { &setup.internal.menu_input, execSetupInput },
7189 { &setup.internal.menu_touch, execSetupTouch },
7190 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7191 { &setup.internal.menu_exit, execExitSetup },
7192 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7194 { &setup.internal.info_title, execInfoTitleScreen },
7195 { &setup.internal.info_elements, execInfoElements },
7196 { &setup.internal.info_music, execInfoMusic },
7197 { &setup.internal.info_credits, execInfoCredits },
7198 { &setup.internal.info_program, execInfoProgram },
7199 { &setup.internal.info_version, execInfoVersion },
7200 { &setup.internal.info_levelset, execInfoLevelSet },
7201 { &setup.internal.info_exit, execExitInfo },
7206 void setHideRelatedSetupEntries(void)
7210 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7211 if (hideSetupEntry(hide_related_entry_list[i].value))
7212 setHideSetupEntry(hide_related_entry_list[i].related_value);
7215 static struct TokenInfo setup_info_main[] =
7217 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7218 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7219 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7220 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7221 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7222 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7223 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7224 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7225 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7226 { TYPE_EMPTY, NULL, "" },
7227 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7228 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7233 static struct TokenInfo setup_info_game[] =
7235 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7236 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7237 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7238 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7239 { TYPE_STRING, &network_server_text, "" },
7240 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7241 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7242 { TYPE_STRING, &scores_type_text, "" },
7243 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7244 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7245 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7246 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7247 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7248 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7249 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7250 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7251 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7252 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7253 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7254 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7255 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7256 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7257 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7258 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7259 { TYPE_STRING, &game_speed_text, "" },
7260 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7262 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7263 { TYPE_STRING, &scroll_delay_text, "" },
7265 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7266 { TYPE_STRING, &snapshot_mode_text, "" },
7267 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7268 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7269 { TYPE_EMPTY, NULL, "" },
7270 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7275 static struct TokenInfo setup_info_engines[] =
7277 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7278 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7279 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7280 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7281 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7282 { TYPE_EMPTY, NULL, "" },
7283 { TYPE_HEADLINE, NULL, "Supaplex" },
7284 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7285 { TYPE_EMPTY, NULL, "" },
7286 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7291 static struct TokenInfo setup_info_editor[] =
7294 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7295 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7296 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7297 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7298 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7299 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7300 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7301 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7302 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7303 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7305 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7306 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7308 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7310 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7311 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7312 { TYPE_EMPTY, NULL, "" },
7314 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7315 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7316 { TYPE_EMPTY, NULL, "" },
7318 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7319 { TYPE_EMPTY, NULL, "" },
7320 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7321 { TYPE_EMPTY, NULL, "" },
7322 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7327 static struct TokenInfo setup_info_graphics[] =
7329 #if !defined(PLATFORM_ANDROID)
7330 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7331 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7332 { TYPE_STRING, &window_size_text, "" },
7333 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7334 { TYPE_STRING, &scaling_type_text, "" },
7335 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7336 { TYPE_STRING, &rendering_mode_text, "" },
7339 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7340 { TYPE_STRING, &scroll_delay_text, "" },
7342 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7343 { TYPE_STRING, &vsync_mode_text, "" },
7344 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7345 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7346 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7347 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7348 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7349 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7350 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7351 { TYPE_EMPTY, NULL, "" },
7352 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7357 static struct TokenInfo setup_info_sound[] =
7359 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7360 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7361 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7362 { TYPE_EMPTY, NULL, "" },
7363 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7364 { TYPE_STRING, &volume_simple_text, "" },
7365 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7366 { TYPE_STRING, &volume_loops_text, "" },
7367 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7368 { TYPE_STRING, &volume_music_text, "" },
7369 { TYPE_EMPTY, NULL, "" },
7370 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7375 static struct TokenInfo setup_info_artwork[] =
7377 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7378 { TYPE_STRING, &graphics_set_name, "" },
7379 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7380 { TYPE_STRING, &sounds_set_name, "" },
7381 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7382 { TYPE_STRING, &music_set_name, "" },
7383 { TYPE_EMPTY, NULL, "" },
7384 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7385 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7386 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7387 { TYPE_EMPTY, NULL, "" },
7388 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7393 static struct TokenInfo setup_info_input[] =
7395 { TYPE_SWITCH, NULL, "Player:" },
7396 { TYPE_SWITCH, NULL, "Device:" },
7397 { TYPE_SWITCH, NULL, "" },
7398 { TYPE_SKIPPABLE, NULL, "" },
7399 { TYPE_EMPTY, NULL, "" },
7400 { TYPE_EMPTY, NULL, "" },
7401 { TYPE_EMPTY, NULL, "" },
7402 { TYPE_EMPTY, NULL, "" },
7403 { TYPE_EMPTY, NULL, "" },
7404 { TYPE_EMPTY, NULL, "" },
7405 { TYPE_EMPTY, NULL, "" },
7406 { TYPE_EMPTY, NULL, "" },
7407 { TYPE_SKIPPABLE, NULL, "" },
7408 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7413 static struct TokenInfo setup_info_touch[] =
7415 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7416 { TYPE_STRING, &touch_controls_text, "" },
7417 { TYPE_EMPTY, NULL, "" },
7418 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7423 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7425 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7426 { TYPE_STRING, &touch_controls_text, "" },
7427 { TYPE_EMPTY, NULL, "" },
7428 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7429 { TYPE_STRING, &grid_size_text[0][0], "" },
7430 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7431 { TYPE_STRING, &grid_size_text[0][1], "" },
7432 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7433 { TYPE_STRING, &transparency_text, "" },
7434 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7435 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7436 { TYPE_EMPTY, NULL, "" },
7437 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7438 { TYPE_EMPTY, NULL, "" },
7439 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7444 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7446 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7447 { TYPE_STRING, &touch_controls_text, "" },
7448 { TYPE_EMPTY, NULL, "" },
7449 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7450 { TYPE_STRING, &grid_size_text[1][0], "" },
7451 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7452 { TYPE_STRING, &grid_size_text[1][1], "" },
7453 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7454 { TYPE_STRING, &transparency_text, "" },
7455 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7456 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7457 { TYPE_EMPTY, NULL, "" },
7458 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7459 { TYPE_EMPTY, NULL, "" },
7460 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7465 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7467 setup_info_touch_virtual_buttons_0,
7468 setup_info_touch_virtual_buttons_1
7471 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7473 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7474 { TYPE_STRING, &touch_controls_text, "" },
7475 { TYPE_EMPTY, NULL, "" },
7476 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7477 { TYPE_STRING, &move_distance_text, "" },
7478 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7479 { TYPE_STRING, &drop_distance_text, "" },
7480 { TYPE_EMPTY, NULL, "" },
7481 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7486 static struct TokenInfo setup_info_shortcuts[] =
7488 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7489 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7490 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7491 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7492 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7493 { TYPE_EMPTY, NULL, "" },
7494 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7499 static struct TokenInfo setup_info_shortcuts_1[] =
7501 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7502 { TYPE_KEY, &setup.shortcut.save_game, "" },
7503 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7504 { TYPE_KEY, &setup.shortcut.load_game, "" },
7505 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7506 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7507 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7508 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7509 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7510 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7511 { TYPE_EMPTY, NULL, "" },
7512 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7513 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7514 { TYPE_EMPTY, NULL, "" },
7515 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7520 static struct TokenInfo setup_info_shortcuts_2[] =
7522 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7523 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7524 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7525 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7526 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7527 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7528 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7529 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7530 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7531 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7532 { TYPE_EMPTY, NULL, "" },
7533 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7538 static struct TokenInfo setup_info_shortcuts_3[] =
7540 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7541 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7542 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7543 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7544 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7545 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7546 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7547 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7548 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7549 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7550 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7551 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7552 { TYPE_EMPTY, NULL, "" },
7553 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7558 static struct TokenInfo setup_info_shortcuts_4[] =
7560 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7561 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7562 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7563 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7564 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7565 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7566 { TYPE_EMPTY, NULL, "" },
7567 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7572 static struct TokenInfo setup_info_shortcuts_5[] =
7574 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7575 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7576 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7577 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7578 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7579 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7580 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7581 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7582 { TYPE_EMPTY, NULL, "" },
7583 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7588 static Key getSetupKey(void)
7590 Key key = KSYM_UNDEFINED;
7591 boolean got_key_event = FALSE;
7593 while (!got_key_event)
7597 if (NextValidEvent(&event))
7601 case EVENT_KEYPRESS:
7603 key = GetEventKey((KeyEvent *)&event, TRUE);
7605 // press 'Escape' or 'Enter' to keep the existing key binding
7606 if (key == KSYM_Escape || key == KSYM_Return)
7607 key = KSYM_UNDEFINED; // keep old value
7609 got_key_event = TRUE;
7613 case EVENT_KEYRELEASE:
7614 key_joystick_mapping = 0;
7618 HandleOtherEvents(&event);
7629 static int getSetupValueFont(int type, void *value)
7631 if (type & TYPE_GHOSTED)
7632 return FONT_OPTION_OFF;
7633 else if (type & TYPE_KEY)
7634 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7635 else if (type & TYPE_STRING)
7636 return FONT_VALUE_2;
7637 else if (type & TYPE_ECS_AGA)
7638 return FONT_VALUE_1;
7639 else if (type & TYPE_BOOLEAN_STYLE)
7640 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7641 else if (type & TYPE_YES_NO_AUTO)
7642 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7643 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7644 else if (type & TYPE_PLAYER)
7645 return FONT_VALUE_1;
7647 return FONT_VALUE_1;
7650 static int getSetupValueFontNarrow(int type, int font_nr)
7652 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7653 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7654 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7658 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7660 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7661 struct TokenInfo *si = &setup_info[si_pos];
7662 boolean font_draw_xoffset_modified = FALSE;
7663 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7664 int font_draw_xoffset_old = -1;
7665 int xoffset = (scrollbar_needed ? -1 : 0);
7666 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7667 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7668 int xpos = menu_screen_value_xpos;
7669 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7670 int startx = mSX + xpos * 32;
7671 int starty = mSY + ypos * 32;
7672 int type = si->type;
7673 void *value = si->value;
7674 char *value_string = getSetupValue(type, value);
7675 int font_nr_default = getSetupValueFont(type, value);
7676 int font_width_default = getFontWidth(font_nr_default);
7677 int font_nr = font_nr_default;
7680 if (value_string == NULL)
7683 if (type & TYPE_KEY)
7685 xpos = MENU_SCREEN_START_XPOS;
7687 if (type & TYPE_QUERY)
7688 value_string = "<press key>";
7690 else if (type & TYPE_STRING)
7692 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7694 xpos = MENU_SCREEN_START_XPOS;
7696 if (strlen(value_string) > max_value_len)
7697 value_string[max_value_len] = '\0';
7699 else if (type & TYPE_YES_NO_AUTO)
7701 xpos = menu_screen_value_xpos - 1;
7703 else if (type & TYPE_PLAYER)
7705 int displayed_player_nr = *(int *)value + 1;
7707 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7710 startx = mSX + xpos * 32;
7711 starty = mSY + ypos * 32;
7713 // special check if right-side setup values moved left due to scrollbar
7714 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7716 int max_menu_text_length = 26; // maximum text length for classic menu
7717 int font_xoffset = getFontDrawOffsetX(font_nr);
7718 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7719 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7720 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7721 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7723 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7725 // when using narrow font, left-shifting text "auto" not needed
7726 if (type & TYPE_YES_NO_AUTO)
7730 startx = mSX + xpos * 32;
7732 font_nr = getSetupValueFontNarrow(type, font_nr);
7736 // downward compatibility correction for Juergen Bonhagen's menu settings
7737 if (setup_mode != SETUP_MODE_INPUT)
7739 int max_menu_text_length_big = (menu_screen_value_xpos -
7740 MENU_SCREEN_START_XPOS);
7741 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7742 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7743 int font1_xoffset = getFontDrawOffsetX(font_nr);
7744 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7745 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7746 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7747 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7748 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7749 boolean correct_font_draw_xoffset = FALSE;
7751 if (xpos == MENU_SCREEN_START_XPOS &&
7752 startx + font1_xoffset < text_startx + text_font_xoffset)
7753 correct_font_draw_xoffset = TRUE;
7755 if (xpos == menu_screen_value_xpos &&
7756 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7757 correct_font_draw_xoffset = TRUE;
7759 // check if setup value would overlap with setup text when printed
7760 // (this can happen for extreme/wrong values for font draw offset)
7761 if (correct_font_draw_xoffset)
7763 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7764 font_draw_xoffset_modified = TRUE;
7766 if (type & TYPE_KEY)
7767 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7768 else if (!(type & TYPE_STRING))
7769 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7770 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7774 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7775 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7777 DrawText(startx, starty, value_string, font_nr);
7779 if (type & TYPE_PLAYER)
7781 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7782 int player_nr = *(int *)value;
7783 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7784 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7785 int startx2 = startx + xoff;
7786 int starty2 = starty + yoff;
7788 if (DrawingOnBackground(startx2, starty2))
7789 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7791 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7792 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7795 if (font_draw_xoffset_modified)
7796 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7799 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7801 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7802 struct TokenInfo *si = &setup_info[si_pos];
7804 if (si->type & TYPE_BOOLEAN_STYLE)
7806 *(boolean *)si->value ^= TRUE;
7808 else if (si->type & TYPE_YES_NO_AUTO)
7812 (*(int *)si->value == AUTO ? TRUE :
7813 *(int *)si->value == TRUE ? FALSE : AUTO) :
7814 (*(int *)si->value == TRUE ? AUTO :
7815 *(int *)si->value == AUTO ? FALSE : TRUE));
7817 else if (si->type & TYPE_KEY)
7821 si->type |= TYPE_QUERY;
7822 drawSetupValue(screen_pos, setup_info_pos_raw);
7823 si->type &= ~TYPE_QUERY;
7825 key = getSetupKey();
7826 if (key != KSYM_UNDEFINED)
7827 *(Key *)si->value = key;
7829 else if (si->type & TYPE_PLAYER)
7831 int player_nr = *(int *)si->value;
7836 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7838 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7841 drawSetupValue(screen_pos, setup_info_pos_raw);
7843 // fullscreen state may have changed at this point
7844 if (si->value == &setup.fullscreen)
7845 ToggleFullscreenIfNeeded();
7847 // network mode may have changed at this point
7848 if (si->value == &setup.network_mode)
7849 ToggleNetworkModeIfNeeded();
7851 // API server mode may have changed at this point
7852 if (si->value == &setup.use_api_server)
7853 ToggleUseApiServerIfNeeded();
7855 // game speed list may have changed at this point
7856 if (si->value == &setup.game_speed_extended)
7857 ToggleGameSpeedsListIfNeeded();
7860 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7862 static struct TokenInfo *setup_info_final = NULL;
7867 // determine maximum list size of target list
7868 while (setup_info_orig[list_size++].type != 0);
7870 // free, allocate and clear memory for target list
7871 checked_free(setup_info_final);
7872 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7874 // copy setup info list without setup entries marked as hidden
7875 for (i = 0; setup_info_orig[i].type != 0; i++)
7877 // skip setup entries configured to be hidden
7878 if (hideSetupEntry(setup_info_orig[i].value))
7881 // skip skippable setup entries if screen is lower than usual
7882 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7883 setup_info_orig[i].type == TYPE_SKIPPABLE)
7886 setup_info_final[list_pos++] = setup_info_orig[i];
7889 return setup_info_final;
7892 static void DrawSetupScreen_Generic(void)
7894 int fade_mask = REDRAW_FIELD;
7895 boolean redraw_all = FALSE;
7896 char *title_string = NULL;
7900 fade_mask = REDRAW_ALL;
7903 FadeMenuSoundsAndMusic();
7905 FreeScreenGadgets();
7906 CreateScreenGadgets();
7908 if (redraw_mask & REDRAW_ALL)
7913 // needed if different viewport properties defined for setup screen
7914 ChangeViewportPropertiesIfNeeded();
7916 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7920 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7922 if (setup_mode == SETUP_MODE_MAIN)
7924 setup_info = setup_info_main;
7925 title_string = STR_SETUP_MAIN;
7927 else if (setup_mode == SETUP_MODE_GAME)
7929 setup_info = setup_info_game;
7930 title_string = STR_SETUP_GAME;
7932 else if (setup_mode == SETUP_MODE_ENGINES)
7934 setup_info = setup_info_engines;
7935 title_string = STR_SETUP_ENGINES;
7937 else if (setup_mode == SETUP_MODE_EDITOR)
7939 setup_info = setup_info_editor;
7940 title_string = STR_SETUP_EDITOR;
7942 else if (setup_mode == SETUP_MODE_GRAPHICS)
7944 setup_info = setup_info_graphics;
7945 title_string = STR_SETUP_GRAPHICS;
7947 else if (setup_mode == SETUP_MODE_SOUND)
7949 setup_info = setup_info_sound;
7950 title_string = STR_SETUP_SOUND;
7952 else if (setup_mode == SETUP_MODE_ARTWORK)
7954 setup_info = setup_info_artwork;
7955 title_string = STR_SETUP_ARTWORK;
7957 else if (setup_mode == SETUP_MODE_TOUCH)
7959 setup_info = setup_info_touch;
7960 title_string = STR_SETUP_TOUCH;
7962 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7963 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7964 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7965 setup_info = setup_info_touch_wipe_gestures;
7967 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7969 setup_info = setup_info_shortcuts;
7970 title_string = STR_SETUP_SHORTCUTS;
7972 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7974 setup_info = setup_info_shortcuts_1;
7975 title_string = STR_SETUP_SHORTCUTS;
7977 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7979 setup_info = setup_info_shortcuts_2;
7980 title_string = STR_SETUP_SHORTCUTS;
7982 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7984 setup_info = setup_info_shortcuts_3;
7985 title_string = STR_SETUP_SHORTCUTS;
7987 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7989 setup_info = setup_info_shortcuts_4;
7990 title_string = STR_SETUP_SHORTCUTS;
7992 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7994 setup_info = setup_info_shortcuts_5;
7995 title_string = STR_SETUP_SHORTCUTS;
7998 // use modified setup info without setup entries marked as hidden
7999 setup_info = getSetupInfoFinal(setup_info);
8001 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8003 // determine maximal number of setup entries that can be displayed on screen
8005 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8008 // determine maximal number of setup entries available for this setup screen
8010 for (i = 0; setup_info[i].type != 0; i++)
8013 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8015 MapScreenGadgets(max_setup_info);
8018 redraw_mask = fade_mask = REDRAW_ALL;
8020 DrawMaskedBorder(fade_mask);
8025 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8027 menu_info = setup_info;
8029 HandleMenuScreen(mx, my, dx, dy, button,
8030 setup_mode, num_setup_info, max_setup_info);
8033 static void DrawSetupScreen_Input(void)
8037 FadeOut(REDRAW_FIELD);
8041 setup_info = getSetupInfoFinal(setup_info_input);
8043 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8045 for (i = 0; setup_info[i].type != 0; i++)
8047 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8048 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8049 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8050 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8051 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8052 initCursor(i, IMG_MENU_BUTTON);
8054 DrawCursorAndText_Setup(i, -1, FALSE);
8057 // create gadgets for setup input menu screen
8058 FreeScreenGadgets();
8059 CreateScreenGadgets();
8061 // map gadgets for setup input menu screen
8062 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8064 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8066 FadeIn(REDRAW_FIELD);
8069 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8071 if (device_name == NULL)
8074 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8077 if (strlen(device_name) > 1)
8079 char c1 = device_name[strlen(device_name) - 1];
8080 char c2 = device_name[strlen(device_name) - 2];
8082 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8083 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8086 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8087 strlen(device_name));
8090 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8093 static struct SetupKeyboardInfo custom_key;
8100 { &custom_key.left, "Axis/Pad Left" },
8101 { &custom_key.right, "Axis/Pad Right" },
8102 { &custom_key.up, "Axis/Pad Up" },
8103 { &custom_key.down, "Axis/Pad Down" },
8104 { &custom_key.snap, "Button 1/A/X" },
8105 { &custom_key.drop, "Button 2/B/Y" }
8107 static char *joystick_name[MAX_PLAYERS] =
8114 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8115 int font_nr_info = FONT_MENU_1;
8116 int font_nr_name = FONT_VALUE_OLD;
8117 int font_nr_on = FONT_VALUE_1;
8118 int font_nr_off = FONT_VALUE_OLD;
8121 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8123 font_nr_info = FONT_MENU_2;
8124 font_nr_on = FONT_VALUE_NARROW;
8125 font_nr_off = FONT_VALUE_OLD_NARROW;
8128 custom_key = setup.input[player_nr].key;
8130 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8131 FONT_INPUT_1_ACTIVE);
8133 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8135 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8136 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8138 if (setup.input[player_nr].use_joystick)
8140 char *device_name = setup.input[player_nr].joy.device_name;
8141 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8142 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8143 char *text = joystick_name[joystick_nr];
8144 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8146 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8147 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8151 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8152 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8155 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8156 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8160 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8161 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8162 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8163 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8165 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8166 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8167 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8168 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8169 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8170 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8172 for (i = 0; i < 6; i++)
8174 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8176 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8178 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8179 (setup.input[player_nr].use_joystick ?
8181 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8185 static int input_player_nr = 0;
8187 static void HandleSetupScreen_Input_Player(int step, int direction)
8189 int old_player_nr = input_player_nr;
8192 new_player_nr = old_player_nr + step * direction;
8193 if (new_player_nr < 0)
8195 if (new_player_nr > MAX_PLAYERS - 1)
8196 new_player_nr = MAX_PLAYERS - 1;
8198 if (new_player_nr != old_player_nr)
8200 input_player_nr = new_player_nr;
8202 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8206 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8208 static int choice = 0;
8211 int pos_start = SETUPINPUT_SCREEN_POS_START;
8212 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8213 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8214 int pos_end = SETUPINPUT_SCREEN_POS_END;
8216 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8220 for (i = 0; setup_info_input[i].type != 0; i++)
8222 // adjust menu structure according to skipped setup entries
8223 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8231 if (button == MB_MENU_INITIALIZE)
8233 // input setup menu may have changed size due to graphics configuration
8234 if (choice >= pos_empty1)
8237 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8239 DrawCursorAndText_Setup(choice, -1, TRUE);
8243 else if (button == MB_MENU_LEAVE)
8245 setup_mode = SETUP_MODE_MAIN;
8252 if (mx || my) // mouse input
8254 x = (mx - mSX) / 32;
8255 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8257 else if (dx || dy) // keyboard input
8259 if (dx && choice == 0)
8260 x = (dx < 0 ? 10 : 12);
8261 else if ((dx && choice == 1) ||
8262 (dx == -1 && choice == pos_end))
8263 button = MB_MENU_CHOICE;
8267 if (y >= pos_empty1 && y <= pos_empty2)
8268 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8271 if (y == 0 && dx != 0 && button)
8273 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8275 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8276 y >= pos_start && y <= pos_end &&
8277 !(y >= pos_empty1 && y <= pos_empty2))
8283 DrawCursorAndText_Setup(choice, -1, FALSE);
8284 DrawCursorAndText_Setup(y, -1, TRUE);
8286 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8295 char *device_name = setup.input[input_player_nr].joy.device_name;
8297 if (!setup.input[input_player_nr].use_joystick)
8299 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8301 setJoystickDeviceToNr(device_name, new_device_nr);
8302 setup.input[input_player_nr].use_joystick = TRUE;
8306 int device_nr = getJoystickNrFromDeviceName(device_name);
8307 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8309 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8310 setup.input[input_player_nr].use_joystick = FALSE;
8312 setJoystickDeviceToNr(device_name, new_device_nr);
8315 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8319 if (setup.input[input_player_nr].use_joystick)
8320 ConfigureJoystick(input_player_nr);
8322 CustomizeKeyboard(input_player_nr);
8324 else if (y == pos_end)
8330 setup_mode = SETUP_MODE_MAIN;
8337 static boolean CustomizeKeyboardMain(int player_nr)
8341 boolean finished = FALSE;
8342 static struct SetupKeyboardInfo custom_key;
8347 } customize_step[] =
8349 { &custom_key.left, "Move Left" },
8350 { &custom_key.right, "Move Right" },
8351 { &custom_key.up, "Move Up" },
8352 { &custom_key.down, "Move Down" },
8353 { &custom_key.snap, "Snap Field" },
8354 { &custom_key.drop, "Drop Element" }
8356 int font_nr_old = FONT_VALUE_OLD;
8357 int font_nr_new = FONT_VALUE_1;
8358 boolean success = FALSE;
8360 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8362 font_nr_old = FONT_VALUE_OLD_NARROW;
8363 font_nr_new = FONT_VALUE_NARROW;
8366 // read existing key bindings from player setup
8367 custom_key = setup.input[player_nr].key;
8370 FadeOut(REDRAW_FIELD);
8374 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8377 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8378 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8379 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8380 "Key:", FONT_INPUT_1_ACTIVE);
8381 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8382 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8384 FadeIn(REDRAW_FIELD);
8390 if (NextValidEvent(&event))
8394 case EVENT_KEYPRESS:
8396 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8398 // press 'Escape' to abort and keep the old key bindings
8399 if (key == KSYM_Escape)
8401 FadeSkipNextFadeIn();
8408 // press 'Enter' to keep the existing key binding
8409 if (key == KSYM_Return)
8410 key = *customize_step[step_nr].key;
8412 // check if key already used
8413 for (i = 0; i < step_nr; i++)
8414 if (*customize_step[i].key == key)
8419 // got new key binding
8420 *customize_step[step_nr].key = key;
8421 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8423 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8424 getKeyNameFromKey(key), font_nr_new);
8427 // un-highlight last query
8428 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8429 customize_step[step_nr - 1].text, FONT_MENU_1);
8430 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8431 "Key:", FONT_MENU_1);
8433 // all keys configured
8442 // query next key binding
8443 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8444 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8445 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8446 "Key:", FONT_INPUT_1_ACTIVE);
8447 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8448 getKeyNameFromKey(*customize_step[step_nr].key),
8453 case EVENT_KEYRELEASE:
8454 key_joystick_mapping = 0;
8458 HandleOtherEvents(&event);
8466 // write new key bindings back to player setup, if successfully finished
8468 setup.input[player_nr].key = custom_key;
8473 void CustomizeKeyboard(int player_nr)
8475 boolean success = CustomizeKeyboardMain(player_nr);
8479 int font_nr = FONT_TITLE_1;
8480 int font_height = getFontHeight(font_nr);
8481 int ypos1 = SYSIZE / 2 - font_height * 2;
8482 int ypos2 = SYSIZE / 2 - font_height * 1;
8483 unsigned int wait_frame_delay = 0;
8484 unsigned int wait_frame_delay_value = 2000;
8486 ResetDelayCounter(&wait_frame_delay);
8490 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8491 DrawTextSCentered(ypos2, font_nr, "configured!");
8493 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8499 DrawSetupScreen_Input();
8502 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8504 #define MARKER_BUTTON 1
8505 #define MARKER_AXIS_X 2
8506 #define MARKER_AXIS_Y 3
8508 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8510 static boolean bitmaps_initialized = FALSE;
8511 boolean screen_initialized = FALSE;
8512 static Bitmap *controller, *button, *axis_x, *axis_y;
8514 boolean success = TRUE;
8515 boolean done = FALSE, next = FALSE;
8517 int alpha = 200, alpha_step = -1;
8518 int alpha_ticks = 0;
8519 char mapping[4096], temp[256];
8520 int font_name = MENU_SETUP_FONT_TITLE;
8521 int font_info = MENU_SETUP_FONT_TEXT;
8522 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8523 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8524 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8525 int ystep_name = getMenuTextStep(spacing_name, font_name);
8526 int ystep_line = getMenuTextStep(spacing_line, font_info);
8527 int ystep_para = getMenuTextStep(spacing_para, font_info);
8535 int axis, button, hat, hat_value;
8538 *step, *prev_step, steps[] =
8540 { 356, 155, MARKER_BUTTON, "a", },
8541 { 396, 122, MARKER_BUTTON, "b", },
8542 { 320, 125, MARKER_BUTTON, "x", },
8543 { 358, 95, MARKER_BUTTON, "y", },
8544 { 162, 125, MARKER_BUTTON, "back", },
8545 { 216, 125, MARKER_BUTTON, "guide", },
8546 { 271, 125, MARKER_BUTTON, "start", },
8547 { 110, 200, MARKER_BUTTON, "dpleft", },
8548 { 146, 228, MARKER_BUTTON, "dpdown", },
8549 { 178, 200, MARKER_BUTTON, "dpright", },
8550 { 146, 172, MARKER_BUTTON, "dpup", },
8551 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8552 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8553 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8554 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8555 { 73, 141, MARKER_BUTTON, "leftstick", },
8556 { 282, 210, MARKER_BUTTON, "rightstick", },
8557 { 73, 141, MARKER_AXIS_X, "leftx", },
8558 { 73, 141, MARKER_AXIS_Y, "lefty", },
8559 { 282, 210, MARKER_AXIS_X, "rightx", },
8560 { 282, 210, MARKER_AXIS_Y, "righty", },
8563 unsigned int event_frame_delay = 0;
8564 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8566 ResetDelayCounter(&event_frame_delay);
8568 if (!bitmaps_initialized)
8570 controller = LoadCustomImage("joystick/controller.png");
8571 button = LoadCustomImage("joystick/button.png");
8572 axis_x = LoadCustomImage("joystick/axis_x.png");
8573 axis_y = LoadCustomImage("joystick/axis_y.png");
8575 bitmaps_initialized = TRUE;
8578 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8581 // print info about the joystick we are watching
8582 Debug("joystick", "watching joystick %d: (%s)",
8583 SDL_JoystickInstanceID(joystick), name);
8584 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8585 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8586 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8589 // initialize mapping with GUID and name
8590 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8592 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8593 temp, name, SDL_GetPlatform());
8595 // loop through all steps (buttons and axes), getting joystick events
8596 for (i = 0; i < SDL_arraysize(steps) && !done;)
8598 Bitmap *marker = button; // initialize with reliable default value
8601 strcpy(step->mapping, mapping);
8605 step->hat_value = -1;
8607 marker = (step->marker == MARKER_BUTTON ? button :
8608 step->marker == MARKER_AXIS_X ? axis_x :
8609 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8613 while (!done && !next)
8615 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8616 alpha_ticks = SDL_GetTicks();
8623 else if (alpha < 128)
8629 int controller_x = SX + (SXSIZE - controller->width) / 2;
8630 int controller_y = SY + ystep_line;
8632 int marker_x = controller_x + step->x;
8633 int marker_y = controller_y + step->y;
8635 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8636 int ystart2 = ystart1 + ystep_name + ystep_line;
8640 DrawTextSCentered(ystart1, font_name, name);
8642 DrawTextSCentered(ystart2, font_info,
8643 "Press buttons and move axes on");
8644 ystart2 += ystep_line;
8645 DrawTextSCentered(ystart2, font_info,
8646 "your controller when indicated.");
8647 ystart2 += ystep_line;
8648 DrawTextSCentered(ystart2, font_info,
8649 "(Your controller may look different.)");
8650 ystart2 += ystep_para;
8652 #if defined(PLATFORM_ANDROID)
8653 DrawTextSCentered(ystart2, font_info,
8654 "To correct a mistake,");
8655 ystart2 += ystep_line;
8656 DrawTextSCentered(ystart2, font_info,
8657 "press the 'back' button.");
8658 ystart2 += ystep_line;
8659 DrawTextSCentered(ystart2, font_info,
8660 "To skip a button or axis,");
8661 ystart2 += ystep_line;
8662 DrawTextSCentered(ystart2, font_info,
8663 "press the 'menu' button.");
8665 DrawTextSCentered(ystart2, font_info,
8666 "To correct a mistake,");
8667 ystart2 += ystep_line;
8668 DrawTextSCentered(ystart2, font_info,
8669 "press the 'backspace' key.");
8670 ystart2 += ystep_line;
8671 DrawTextSCentered(ystart2, font_info,
8672 "To skip a button or axis,");
8673 ystart2 += ystep_line;
8674 DrawTextSCentered(ystart2, font_info,
8675 "press the 'return' key.");
8676 ystart2 += ystep_line;
8677 DrawTextSCentered(ystart2, font_info,
8678 "To exit, press the 'escape' key.");
8681 BlitBitmapMasked(controller, drawto, 0, 0,
8682 controller->width, controller->height,
8683 controller_x, controller_y);
8685 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8686 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8688 BlitBitmapMasked(marker, drawto, 0, 0,
8689 marker->width, marker->height,
8690 marker_x, marker_y);
8692 if (!screen_initialized)
8693 FadeIn(REDRAW_FIELD);
8697 screen_initialized = TRUE;
8699 while (NextValidEvent(&event))
8703 case SDL_JOYAXISMOTION:
8704 if (event.jaxis.value > 20000 ||
8705 event.jaxis.value < -20000)
8707 for (j = 0; j < i; j++)
8708 if (steps[j].axis == event.jaxis.axis)
8713 if (step->marker != MARKER_AXIS_X &&
8714 step->marker != MARKER_AXIS_Y)
8717 step->axis = event.jaxis.axis;
8718 strcat(mapping, step->field);
8719 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8720 strcat(mapping, temp);
8728 case SDL_JOYHATMOTION:
8729 // ignore centering; we're probably just coming back
8730 // to the center from the previous item we set
8731 if (event.jhat.value == SDL_HAT_CENTERED)
8734 for (j = 0; j < i; j++)
8735 if (steps[j].hat == event.jhat.hat &&
8736 steps[j].hat_value == event.jhat.value)
8741 step->hat = event.jhat.hat;
8742 step->hat_value = event.jhat.value;
8743 strcat(mapping, step->field);
8744 snprintf(temp, sizeof(temp), ":h%u.%u,",
8745 event.jhat.hat, event.jhat.value );
8746 strcat(mapping, temp);
8753 case SDL_JOYBALLMOTION:
8756 case SDL_JOYBUTTONUP:
8757 for (j = 0; j < i; j++)
8758 if (steps[j].button == event.jbutton.button)
8763 step->button = event.jbutton.button;
8764 strcat(mapping, step->field);
8765 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8766 strcat(mapping, temp);
8773 case SDL_FINGERDOWN:
8774 case SDL_MOUSEBUTTONDOWN:
8782 if (event.key.keysym.sym == KSYM_BackSpace ||
8783 event.key.keysym.sym == KSYM_Back)
8795 prev_step = &steps[i - 1];
8796 strcpy(mapping, prev_step->mapping);
8803 if (event.key.keysym.sym == KSYM_space ||
8804 event.key.keysym.sym == KSYM_Return ||
8805 event.key.keysym.sym == KSYM_Menu)
8814 if (event.key.keysym.sym == KSYM_Escape)
8824 program.exit_function(0);
8831 // do not handle events for longer than standard frame delay period
8832 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8841 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8844 // activate mapping for this game
8845 SDL_GameControllerAddMapping(mapping);
8847 // save mapping to personal mappings
8848 SaveSetup_AddGameControllerMapping(mapping);
8851 // wait until the last pending event was removed from event queue
8852 while (NextValidEvent(&event));
8857 static int ConfigureJoystickMain(int player_nr)
8859 char *device_name = setup.input[player_nr].joy.device_name;
8860 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8861 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8862 int success = FALSE;
8865 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8866 return JOYSTICK_NOT_AVAILABLE;
8868 if (!joystick_active || !setup.input[player_nr].use_joystick)
8869 return JOYSTICK_NOT_AVAILABLE;
8872 FadeOut(REDRAW_FIELD);
8874 // close all joystick devices (potentially opened as game controllers)
8875 for (i = 0; i < SDL_NumJoysticks(); i++)
8876 SDLCloseJoystick(i);
8878 // open joystick device as plain joystick to configure as game controller
8879 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8881 // as the joystick was successfully opened before, this should not happen
8882 if (joystick == NULL)
8885 // create new game controller mapping (buttons and axes) for joystick device
8886 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8888 // close joystick (and maybe re-open as configured game controller later)
8889 SDL_JoystickClose(joystick);
8891 // re-open all joystick devices (potentially as game controllers)
8892 for (i = 0; i < SDL_NumJoysticks(); i++)
8895 // clear all joystick input actions for all joystick devices
8896 SDLClearJoystickState();
8898 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8901 void ConfigureJoystick(int player_nr)
8903 boolean state = ConfigureJoystickMain(player_nr);
8905 if (state != JOYSTICK_NOT_CONFIGURED)
8907 boolean success = (state == JOYSTICK_CONFIGURED);
8908 char message1[MAX_OUTPUT_LINESIZE + 1];
8909 char *message2 = (success ? "configured!" : "not available!");
8910 char *device_name = setup.input[player_nr].joy.device_name;
8911 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8912 int font_nr = FONT_TITLE_1;
8913 int font_height = getFontHeight(font_nr);
8914 int ypos1 = SYSIZE / 2 - font_height * 2;
8915 int ypos2 = SYSIZE / 2 - font_height * 1;
8916 unsigned int wait_frame_delay = 0;
8917 unsigned int wait_frame_delay_value = 2000;
8919 ResetDelayCounter(&wait_frame_delay);
8923 sprintf(message1, "Joystick %d", nr);
8925 DrawTextSCentered(ypos1, font_nr, message1);
8926 DrawTextSCentered(ypos2, font_nr, message2);
8928 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8934 DrawSetupScreen_Input();
8937 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8939 if (y < video.screen_height / 3)
8941 // remap touch gadgets to access upper part of the screen
8942 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8943 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8945 else if (y > 2 * video.screen_height / 3)
8947 // remap touch gadgets to access lower part of the screen
8948 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8949 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8953 static boolean ConfigureVirtualButtonsMain(void)
8955 static char *customize_step_text[] =
8964 char grid_button[] =
8966 CHAR_GRID_BUTTON_LEFT,
8967 CHAR_GRID_BUTTON_RIGHT,
8968 CHAR_GRID_BUTTON_UP,
8969 CHAR_GRID_BUTTON_DOWN,
8970 CHAR_GRID_BUTTON_SNAP,
8971 CHAR_GRID_BUTTON_DROP
8980 int font_nr = FONT_INPUT_1_ACTIVE;
8981 int font_height = getFontHeight(font_nr);
8982 int ypos1 = SYSIZE / 2 - font_height * 2;
8983 int ypos2 = SYSIZE / 2 - font_height * 1;
8984 boolean success = FALSE;
8985 boolean finished = FALSE;
8987 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8988 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8989 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8990 boolean set_grid_button = FALSE;
8991 int nr = GRID_ACTIVE_NR();
8994 for (x = 0; x < MAX_GRID_XSIZE; x++)
8995 for (y = 0; y < MAX_GRID_YSIZE; y++)
8996 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8998 overlay.grid_button_highlight = grid_button[step_nr];
9003 FadeOut(REDRAW_FIELD);
9007 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9008 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9009 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9011 FadeIn(REDRAW_FIELD);
9013 SetOverlayShowGrid(TRUE);
9015 // map gadgets for setup touch buttons menu screen
9016 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9022 while (NextValidEvent(&event))
9024 int action = ACTION_NONE;
9026 // ---------- handle events and set the resulting action ----------
9032 UserEvent *user = (UserEvent *)&event;
9033 int id = user->value1;
9035 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9036 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9037 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9038 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9043 case EVENT_KEYPRESS:
9045 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9047 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9048 key == KSYM_BackSpace ||
9049 key == KSYM_Back ? ACTION_BACK :
9050 key == KSYM_Return ||
9052 key == KSYM_space ? ACTION_NEXT :
9057 case EVENT_KEYRELEASE:
9058 key_joystick_mapping = 0;
9061 case EVENT_BUTTONPRESS:
9062 case EVENT_BUTTONRELEASE:
9064 ButtonEvent *button = (ButtonEvent *)&event;
9066 motion_status = FALSE;
9068 if (button->type == EVENT_BUTTONPRESS)
9069 button_status = button->button;
9071 button_status = MB_RELEASED;
9073 if (HandleGadgets(button->x, button->y, button_status))
9075 // do not handle this button event anymore
9079 button->x += video.screen_xoffset;
9080 button->y += video.screen_yoffset;
9082 x = button->x * overlay.grid_xsize / video.screen_width;
9083 y = button->y * overlay.grid_ysize / video.screen_height;
9085 if (button->type == EVENT_BUTTONPRESS)
9088 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9089 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9091 set_grid_button = TRUE;
9094 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9098 case EVENT_MOTIONNOTIFY:
9100 MotionEvent *motion = (MotionEvent *)&event;
9102 motion_status = TRUE;
9104 if (HandleGadgets(motion->x, motion->y, button_status))
9106 // do not handle this button event anymore
9110 motion->x += video.screen_xoffset;
9111 motion->y += video.screen_yoffset;
9113 x = motion->x * overlay.grid_xsize / video.screen_width;
9114 y = motion->y * overlay.grid_ysize / video.screen_height;
9116 set_grid_button = TRUE;
9118 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9122 case SDL_WINDOWEVENT:
9123 HandleWindowEvent((WindowEvent *) &event);
9125 // check if device has been rotated
9126 if (nr != GRID_ACTIVE_NR())
9128 nr = GRID_ACTIVE_NR();
9130 for (x = 0; x < MAX_GRID_XSIZE; x++)
9131 for (y = 0; y < MAX_GRID_YSIZE; y++)
9132 grid_button_old[x][y] = grid_button_tmp[x][y] =
9133 overlay.grid_button[x][y];
9138 case SDL_APP_WILLENTERBACKGROUND:
9139 case SDL_APP_DIDENTERBACKGROUND:
9140 case SDL_APP_WILLENTERFOREGROUND:
9141 case SDL_APP_DIDENTERFOREGROUND:
9142 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9146 HandleOtherEvents(&event);
9150 // ---------- perform action set by handling events ----------
9152 if (action == ACTION_ESCAPE)
9154 // abort and restore the old key bindings
9156 for (x = 0; x < MAX_GRID_XSIZE; x++)
9157 for (y = 0; y < MAX_GRID_YSIZE; y++)
9158 overlay.grid_button[x][y] = grid_button_old[x][y];
9160 FadeSkipNextFadeIn();
9164 else if (action == ACTION_BACK)
9166 // keep the configured key bindings and go to previous page
9172 FadeSkipNextFadeIn();
9177 else if (action == ACTION_NEXT)
9179 // keep the configured key bindings and go to next page
9183 // all virtual buttons configured
9191 if (action != ACTION_NONE && !finished)
9193 for (x = 0; x < MAX_GRID_XSIZE; x++)
9194 for (y = 0; y < MAX_GRID_YSIZE; y++)
9195 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9197 overlay.grid_button_highlight = grid_button[step_nr];
9199 // configure next virtual button
9203 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9204 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9205 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9208 if (set_grid_button)
9210 overlay.grid_button[x][y] =
9211 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9212 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9213 grid_button_tmp[x][y]);
9215 set_grid_button = FALSE;
9222 for (x = 0; x < MAX_GRID_XSIZE; x++)
9223 for (y = 0; y < MAX_GRID_YSIZE; y++)
9224 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9226 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9228 SetOverlayShowGrid(FALSE);
9233 void ConfigureVirtualButtons(void)
9235 boolean success = ConfigureVirtualButtonsMain();
9237 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9238 SCREEN_MASK_TOUCH2);
9242 int font_nr = FONT_TITLE_1;
9243 int font_height = getFontHeight(font_nr);
9244 int ypos1 = SYSIZE / 2 - font_height * 2;
9245 int ypos2 = SYSIZE / 2 - font_height * 1;
9246 unsigned int wait_frame_delay = 0;
9247 unsigned int wait_frame_delay_value = 2000;
9249 ResetDelayCounter(&wait_frame_delay);
9253 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9254 DrawTextSCentered(ypos2, font_nr, "configured!");
9256 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9263 void DrawSetupScreen(void)
9268 if (setup_mode == SETUP_MODE_INPUT)
9269 DrawSetupScreen_Input();
9270 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9271 DrawChooseTree(&scores_type_current);
9272 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9273 DrawChooseTree(&game_speed_current);
9274 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9275 DrawChooseTree(&scroll_delay_current);
9276 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9277 DrawChooseTree(&snapshot_mode_current);
9278 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9279 DrawChooseTree(&window_size_current);
9280 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9281 DrawChooseTree(&scaling_type_current);
9282 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9283 DrawChooseTree(&rendering_mode_current);
9284 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9285 DrawChooseTree(&vsync_mode_current);
9286 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9287 DrawChooseTree(&artwork.gfx_current);
9288 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9289 DrawChooseTree(&artwork.snd_current);
9290 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9291 DrawChooseTree(&artwork.mus_current);
9292 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9293 DrawChooseTree(&volume_simple_current);
9294 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9295 DrawChooseTree(&volume_loops_current);
9296 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9297 DrawChooseTree(&volume_music_current);
9298 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9299 DrawChooseTree(&touch_control_current);
9300 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9301 DrawChooseTree(&move_distance_current);
9302 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9303 DrawChooseTree(&drop_distance_current);
9304 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9305 DrawChooseTree(&transparency_current);
9306 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9307 DrawChooseTree(&grid_size_current[0][0]);
9308 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9309 DrawChooseTree(&grid_size_current[0][1]);
9310 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9311 DrawChooseTree(&grid_size_current[1][0]);
9312 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9313 DrawChooseTree(&grid_size_current[1][1]);
9315 DrawSetupScreen_Generic();
9317 PlayMenuSoundsAndMusic();
9320 void RedrawSetupScreenAfterFullscreenToggle(void)
9322 if (setup_mode == SETUP_MODE_GRAPHICS ||
9323 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9325 // update list selection from "setup.window_scaling_percent"
9326 execSetupGraphics_setWindowSizes(TRUE);
9332 void RedrawSetupScreenAfterScreenRotation(int nr)
9336 if (setup_mode == SETUP_MODE_TOUCH)
9338 // update virtual button settings (depending on screen orientation)
9341 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9343 // save already configured virtual buttons
9344 for (x = 0; x < MAX_GRID_XSIZE; x++)
9345 for (y = 0; y < MAX_GRID_YSIZE; y++)
9346 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9350 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9352 if (setup_mode == SETUP_MODE_INPUT)
9353 HandleSetupScreen_Input(mx, my, dx, dy, button);
9354 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9355 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9356 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9357 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9358 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9359 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9360 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9361 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9362 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9363 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9364 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9365 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9366 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9367 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9368 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9369 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9370 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9371 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9372 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9373 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9374 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9375 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9376 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9377 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9378 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9379 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9380 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9381 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9382 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9383 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9384 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9385 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9386 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9387 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9388 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9389 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9390 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9391 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9392 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9393 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9394 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9395 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9396 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9397 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9399 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9402 void HandleGameActions(void)
9404 if (setup.ask_on_game_over)
9407 if (game.restart_game_message != NULL)
9409 RequestRestartGame(game.restart_game_message);
9414 if (game_status != GAME_MODE_PLAYING)
9417 GameActions(); // main game loop
9419 if (tape.auto_play && !tape.playing)
9420 AutoPlayTapesContinue(); // continue automatically playing next tape
9424 // ---------- new screen button stuff --------------------------------------
9428 int gfx_unpressed, gfx_pressed;
9429 struct MenuPosInfo *pos;
9430 boolean *check_value;
9433 unsigned int event_mask;
9434 boolean is_touch_button;
9436 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9439 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9440 &menu.main.button.prev_level, NULL,
9441 SCREEN_CTRL_ID_PREV_LEVEL,
9443 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9444 FALSE, "previous level"
9447 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9448 &menu.main.button.next_level, NULL,
9449 SCREEN_CTRL_ID_NEXT_LEVEL,
9451 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9455 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9456 &menu.scores.button.prev_level, NULL,
9457 SCREEN_CTRL_ID_PREV_LEVEL2,
9458 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9459 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9460 FALSE, "previous level"
9463 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9464 &menu.scores.button.next_level, NULL,
9465 SCREEN_CTRL_ID_NEXT_LEVEL2,
9466 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9467 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9471 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9472 &menu.scores.button.prev_score, NULL,
9473 SCREEN_CTRL_ID_PREV_SCORE,
9474 SCREEN_MASK_SCORES_INFO,
9475 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9476 FALSE, "previous score"
9479 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9480 &menu.scores.button.next_score, NULL,
9481 SCREEN_CTRL_ID_NEXT_SCORE,
9482 SCREEN_MASK_SCORES_INFO,
9483 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9487 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE,
9488 &menu.scores.button.play_tape, NULL,
9489 SCREEN_CTRL_ID_PLAY_TAPE,
9490 SCREEN_MASK_SCORES_INFO,
9495 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9496 &menu.main.button.first_level, NULL,
9497 SCREEN_CTRL_ID_FIRST_LEVEL,
9500 FALSE, "first level"
9503 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9504 &menu.main.button.last_level, NULL,
9505 SCREEN_CTRL_ID_LAST_LEVEL,
9511 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9512 &menu.main.button.level_number, NULL,
9513 SCREEN_CTRL_ID_LEVEL_NUMBER,
9516 FALSE, "level number"
9519 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9520 &menu.setup.button.prev_player, NULL,
9521 SCREEN_CTRL_ID_PREV_PLAYER,
9523 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9524 FALSE, "previous player"
9527 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9528 &menu.setup.button.next_player, NULL,
9529 SCREEN_CTRL_ID_NEXT_PLAYER,
9531 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9532 FALSE, "next player"
9535 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9536 &menu.main.button.insert_solution, NULL,
9537 SCREEN_CTRL_ID_INSERT_SOLUTION,
9538 SCREEN_MASK_MAIN_HAS_SOLUTION,
9540 FALSE, "insert solution tape"
9543 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9544 &menu.main.button.play_solution, NULL,
9545 SCREEN_CTRL_ID_PLAY_SOLUTION,
9546 SCREEN_MASK_MAIN_HAS_SOLUTION,
9548 FALSE, "play solution tape"
9551 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9552 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9553 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9555 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9556 FALSE, "switch ECS/AGA chipset"
9559 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9560 &menu.setup.button.touch_back, NULL,
9561 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9564 TRUE, "previous page"
9567 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9568 &menu.setup.button.touch_next, NULL,
9569 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9575 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9576 &menu.setup.button.touch_back2, NULL,
9577 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9580 TRUE, "previous page"
9583 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9584 &menu.setup.button.touch_next2, NULL,
9585 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9594 int gfx_unpressed, gfx_pressed;
9598 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9601 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9602 -1, -1, // these values are not constant, but can change at runtime
9603 SCREEN_CTRL_ID_SCROLL_UP,
9607 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9608 -1, -1, // these values are not constant, but can change at runtime
9609 SCREEN_CTRL_ID_SCROLL_DOWN,
9616 int gfx_unpressed, gfx_pressed;
9622 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9625 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9626 -1, -1, // these values are not constant, but can change at runtime
9627 -1, -1, // these values are not constant, but can change at runtime
9628 GD_TYPE_SCROLLBAR_VERTICAL,
9629 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9630 "scroll level series vertically"
9642 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9645 IMG_SETUP_INPUT_TEXT,
9646 SCREEN_CTRL_ID_NETWORK_SERVER,
9647 -1, -1, // these values are not constant, but can change at runtime
9648 MAX_SETUP_TEXT_INPUT_LEN,
9649 network_server_hostname,
9650 "Network Server Hostname / IP"
9654 static void CreateScreenMenubuttons(void)
9656 struct GadgetInfo *gi;
9657 unsigned int event_mask;
9660 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9662 struct MenuPosInfo *pos = menubutton_info[i].pos;
9663 int screen_mask = menubutton_info[i].screen_mask;
9664 boolean is_touch_button = menubutton_info[i].is_touch_button;
9665 boolean is_check_button = menubutton_info[i].check_value != NULL;
9666 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9667 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9668 menubutton_info[i].gfx_unpressed);
9669 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9670 int gfx_unpressed, gfx_pressed;
9671 int x, y, width, height;
9672 int gd_x1, gd_x2, gd_y1, gd_y2;
9673 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9674 int id = menubutton_info[i].gadget_id;
9675 int type = GD_TYPE_NORMAL_BUTTON;
9676 boolean checked = FALSE;
9678 event_mask = menubutton_info[i].event_mask;
9680 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9681 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9683 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9684 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9686 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9687 gfx_pressed = menubutton_info[i].gfx_pressed;
9688 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9689 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9690 gd_x1 = graphic_info[gfx_unpressed].src_x;
9691 gd_y1 = graphic_info[gfx_unpressed].src_y;
9692 gd_x2 = graphic_info[gfx_pressed].src_x;
9693 gd_y2 = graphic_info[gfx_pressed].src_y;
9699 if (has_gfx_pressed)
9701 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9702 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9705 if (is_check_button)
9707 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9708 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9709 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9710 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9712 type = GD_TYPE_CHECK_BUTTON;
9713 checked = *menubutton_info[i].check_value;
9716 if (is_score_button)
9718 // if x/y set to -1, dynamically place buttons next to title text
9719 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9722 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9723 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9724 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9725 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9728 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
9729 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
9732 gi = CreateGadget(GDI_CUSTOM_ID, id,
9733 GDI_CUSTOM_TYPE_ID, i,
9734 GDI_IMAGE_ID, gfx_unpressed,
9735 GDI_INFO_TEXT, menubutton_info[i].infotext,
9741 GDI_STATE, GD_BUTTON_UNPRESSED,
9742 GDI_CHECKED, checked,
9743 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9744 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9745 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9746 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9747 GDI_DIRECT_DRAW, FALSE,
9748 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9749 GDI_EVENT_MASK, event_mask,
9750 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9754 Fail("cannot create gadget");
9756 screen_gadget[id] = gi;
9760 static void CreateScreenScrollbuttons(void)
9762 struct GadgetInfo *gi;
9763 unsigned int event_mask;
9766 // these values are not constant, but can change at runtime
9767 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9768 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9769 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9770 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9772 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9774 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9775 int gfx_unpressed, gfx_pressed;
9776 int x, y, width, height;
9777 int gd_x1, gd_x2, gd_y1, gd_y2;
9778 int id = scrollbutton_info[i].gadget_id;
9780 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9782 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9783 y = mSY + scrollbutton_info[i].y;
9784 width = SC_SCROLLBUTTON_XSIZE;
9785 height = SC_SCROLLBUTTON_YSIZE;
9787 // correct scrollbar position if placed outside menu (playfield) area
9788 if (x > SX + SC_SCROLL_UP_XPOS)
9789 x = SX + SC_SCROLL_UP_XPOS;
9791 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9792 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9793 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9795 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9796 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9797 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9798 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9799 gd_x1 = graphic_info[gfx_unpressed].src_x;
9800 gd_y1 = graphic_info[gfx_unpressed].src_y;
9801 gd_x2 = graphic_info[gfx_pressed].src_x;
9802 gd_y2 = graphic_info[gfx_pressed].src_y;
9804 gi = CreateGadget(GDI_CUSTOM_ID, id,
9805 GDI_CUSTOM_TYPE_ID, i,
9806 GDI_IMAGE_ID, gfx_unpressed,
9807 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9812 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9813 GDI_STATE, GD_BUTTON_UNPRESSED,
9814 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9815 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9816 GDI_DIRECT_DRAW, FALSE,
9817 GDI_EVENT_MASK, event_mask,
9818 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9822 Fail("cannot create gadget");
9824 screen_gadget[id] = gi;
9828 static void CreateScreenScrollbars(void)
9832 // these values are not constant, but can change at runtime
9833 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9834 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9835 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9836 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9838 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9840 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9841 int gfx_unpressed, gfx_pressed;
9842 int x, y, width, height;
9843 int gd_x1, gd_x2, gd_y1, gd_y2;
9844 struct GadgetInfo *gi;
9845 int items_max, items_visible, item_position;
9846 unsigned int event_mask;
9847 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9848 int id = scrollbar_info[i].gadget_id;
9850 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9852 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9853 y = mSY + scrollbar_info[i].y;
9854 width = scrollbar_info[i].width;
9855 height = scrollbar_info[i].height;
9857 // correct scrollbar position if placed outside menu (playfield) area
9858 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9859 x = SX + SC_SCROLL_VERTICAL_XPOS;
9861 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9862 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9864 items_max = num_page_entries;
9865 items_visible = num_page_entries;
9868 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9869 gfx_pressed = scrollbar_info[i].gfx_pressed;
9870 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9871 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9872 gd_x1 = graphic_info[gfx_unpressed].src_x;
9873 gd_y1 = graphic_info[gfx_unpressed].src_y;
9874 gd_x2 = graphic_info[gfx_pressed].src_x;
9875 gd_y2 = graphic_info[gfx_pressed].src_y;
9877 gi = CreateGadget(GDI_CUSTOM_ID, id,
9878 GDI_CUSTOM_TYPE_ID, i,
9879 GDI_IMAGE_ID, gfx_unpressed,
9880 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9885 GDI_TYPE, scrollbar_info[i].type,
9886 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9887 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9888 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9889 GDI_WHEEL_AREA_X, SX,
9890 GDI_WHEEL_AREA_Y, SY,
9891 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9892 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9893 GDI_STATE, GD_BUTTON_UNPRESSED,
9894 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9895 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9896 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9897 GDI_DIRECT_DRAW, FALSE,
9898 GDI_EVENT_MASK, event_mask,
9899 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9903 Fail("cannot create gadget");
9905 screen_gadget[id] = gi;
9909 static void CreateScreenTextInputGadgets(void)
9913 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9915 int graphic = textinput_info[i].graphic;
9916 struct GraphicInfo *gd = &graphic_info[graphic];
9917 int gd_x1 = gd->src_x;
9918 int gd_y1 = gd->src_y;
9919 int gd_x2 = gd->src_x + gd->active_xoffset;
9920 int gd_y2 = gd->src_y + gd->active_yoffset;
9921 struct GadgetInfo *gi;
9922 unsigned int event_mask;
9923 int id = textinput_info[i].gadget_id;
9924 int x = textinput_info[i].x;
9925 int y = textinput_info[i].y;
9927 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9929 gi = CreateGadget(GDI_CUSTOM_ID, id,
9930 GDI_CUSTOM_TYPE_ID, i,
9931 GDI_INFO_TEXT, textinput_info[i].infotext,
9934 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9935 GDI_TEXT_VALUE, textinput_info[i].value,
9936 GDI_TEXT_SIZE, textinput_info[i].size,
9937 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9938 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9939 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9940 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9941 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9942 GDI_DESIGN_WIDTH, gd->width,
9943 GDI_EVENT_MASK, event_mask,
9944 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9945 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9949 Fail("cannot create gadget");
9951 screen_gadget[id] = gi;
9955 void CreateScreenGadgets(void)
9957 CreateScreenMenubuttons();
9959 CreateScreenScrollbuttons();
9960 CreateScreenScrollbars();
9962 CreateScreenTextInputGadgets();
9965 void FreeScreenGadgets(void)
9969 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9970 FreeGadget(screen_gadget[i]);
9973 static void RedrawScreenMenuGadgets(int screen_mask)
9977 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9978 if (screen_mask & menubutton_info[i].screen_mask)
9979 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
9982 static void MapScreenMenuGadgets(int screen_mask)
9986 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9987 if (screen_mask & menubutton_info[i].screen_mask)
9988 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9991 static void UnmapScreenMenuGadgets(int screen_mask)
9995 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9997 if (screen_mask & menubutton_info[i].screen_mask)
9999 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10001 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10002 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10003 screen_gadget[menubutton_info[i].gadget_id]->y,
10004 screen_gadget[menubutton_info[i].gadget_id]->width,
10005 screen_gadget[menubutton_info[i].gadget_id]->height);
10010 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10013 MapScreenMenuGadgets(screen_mask);
10015 UnmapScreenMenuGadgets(screen_mask);
10018 static void MapScreenGadgets(int num_entries)
10022 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10025 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10026 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10028 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10029 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10032 static void UnmapScreenGadgets()
10036 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10037 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10039 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10040 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10043 static void MapScreenTreeGadgets(TreeInfo *ti)
10045 MapScreenGadgets(numTreeInfoInGroup(ti));
10048 static void UnmapScreenTreeGadgets(void)
10050 UnmapScreenGadgets();
10053 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10055 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10056 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10057 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10058 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10060 if (pos_1->x == -1 && pos_1->y == -1)
10061 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10063 if (pos_2->x == -1 && pos_2->y == -1)
10064 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10067 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10069 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10070 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10072 // set gadget position dynamically, pre-defined or off-screen
10073 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10074 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10076 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10077 MapGadget(gi); // (needed if deactivated on last score page)
10080 static void HandleScreenGadgets(struct GadgetInfo *gi)
10082 int id = gi->custom_id;
10083 int button = gi->event.button;
10084 int step = (button == MB_LEFTBUTTON ? 1 :
10085 button == MB_MIDDLEBUTTON ? 5 :
10086 button == MB_RIGHTBUTTON ? 10 : 1);
10090 case SCREEN_CTRL_ID_PREV_LEVEL:
10091 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10094 case SCREEN_CTRL_ID_NEXT_LEVEL:
10095 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10098 case SCREEN_CTRL_ID_PREV_LEVEL2:
10099 HandleHallOfFame_SelectLevel(step, -1);
10102 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10103 HandleHallOfFame_SelectLevel(step, +1);
10106 case SCREEN_CTRL_ID_PREV_SCORE:
10107 HandleScoreInfo_SelectScore(step, -1);
10110 case SCREEN_CTRL_ID_NEXT_SCORE:
10111 HandleScoreInfo_SelectScore(step, +1);
10114 case SCREEN_CTRL_ID_PLAY_TAPE:
10115 HandleScoreInfo_PlayTape();
10118 case SCREEN_CTRL_ID_FIRST_LEVEL:
10119 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10122 case SCREEN_CTRL_ID_LAST_LEVEL:
10123 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10126 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10127 CloseDoor(DOOR_CLOSE_2);
10128 SetGameStatus(GAME_MODE_LEVELNR);
10129 DrawChooseLevelNr();
10132 case SCREEN_CTRL_ID_PREV_PLAYER:
10133 HandleSetupScreen_Input_Player(step, -1);
10136 case SCREEN_CTRL_ID_NEXT_PLAYER:
10137 HandleSetupScreen_Input_Player(step, +1);
10140 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10141 InsertSolutionTape();
10144 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10145 PlaySolutionTape();
10148 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10149 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10153 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10154 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10155 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10156 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10157 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10160 case SCREEN_CTRL_ID_SCROLL_UP:
10161 if (game_status == GAME_MODE_NAMES)
10162 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10163 else if (game_status == GAME_MODE_LEVELS)
10164 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10165 else if (game_status == GAME_MODE_LEVELNR)
10166 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10167 else if (game_status == GAME_MODE_SETUP)
10168 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10169 else if (game_status == GAME_MODE_INFO)
10170 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10171 else if (game_status == GAME_MODE_SCORES)
10172 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10175 case SCREEN_CTRL_ID_SCROLL_DOWN:
10176 if (game_status == GAME_MODE_NAMES)
10177 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10178 else if (game_status == GAME_MODE_LEVELS)
10179 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10180 else if (game_status == GAME_MODE_LEVELNR)
10181 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10182 else if (game_status == GAME_MODE_SETUP)
10183 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10184 else if (game_status == GAME_MODE_INFO)
10185 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10186 else if (game_status == GAME_MODE_SCORES)
10187 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10190 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10191 if (game_status == GAME_MODE_NAMES)
10192 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10193 else if (game_status == GAME_MODE_LEVELS)
10194 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10195 else if (game_status == GAME_MODE_LEVELNR)
10196 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10197 else if (game_status == GAME_MODE_SETUP)
10198 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10199 else if (game_status == GAME_MODE_INFO)
10200 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10201 else if (game_status == GAME_MODE_SCORES)
10202 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10205 case SCREEN_CTRL_ID_NETWORK_SERVER:
10207 if (!strEqual(gi->textinput.value, ""))
10209 setString(&setup.network_server_hostname, gi->textinput.value);
10211 network.server_host = setup.network_server_hostname;
10215 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10217 network.server_host = NULL;
10220 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10221 network.server_host = NULL;
10223 execSetupGame_setNetworkServerText();
10235 void DumpScreenIdentifiers(void)
10239 Print("Active screen elements on current screen:\n");
10241 for (i = 0; main_controls[i].nr != -1; i++)
10243 struct MainControlInfo *mci = &main_controls[i];
10245 if (mci->button_graphic != -1)
10247 char *token = getTokenFromImageID(mci->button_graphic);
10249 Print("- '%s'\n", token);
10256 boolean DoScreenAction(int image_id)
10260 if (game_status != GAME_MODE_MAIN)
10263 for (i = 0; main_controls[i].nr != -1; i++)
10265 struct MainControlInfo *mci = &main_controls[i];
10266 struct MenuPosInfo *pos = mci->pos_button;
10268 if (mci->button_graphic == image_id)
10270 int x = mSX + pos->x;
10271 int y = mSY + pos->y;
10273 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10282 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10284 // get tree info node of newly added level or artwork set
10285 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10286 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10288 if (tree_node_new == NULL) // should not happen
10291 // if request dialog is active, do nothing
10292 if (game.request_active)
10295 if (game_status == GAME_MODE_MAIN &&
10296 tree_type == TREE_TYPE_LEVEL_DIR)
10298 // when adding new level set in main menu, select it as current level set
10300 // change current level set to newly added level set from zip file
10301 leveldir_current = tree_node_new;
10303 // change current level number to first level of newly added level set
10304 level_nr = leveldir_current->first_level;
10306 // redraw screen to reflect changed level set
10309 // save this level set and level number as last selected level set
10310 SaveLevelSetup_LastSeries();
10311 SaveLevelSetup_SeriesInfo();
10313 else if (game_status == GAME_MODE_LEVELS &&
10314 tree_type == TREE_TYPE_LEVEL_DIR)
10316 // when adding new level set in level set menu, set cursor and update screen
10318 leveldir_current = tree_node_new;
10320 DrawChooseTree(&leveldir_current);
10322 else if (game_status == GAME_MODE_SETUP)
10324 // when adding new artwork set in setup menu, set cursor and update screen
10326 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10327 tree_type == TREE_TYPE_GRAPHICS_DIR)
10329 artwork.gfx_current = tree_node_new;
10331 DrawChooseTree(&artwork.gfx_current);
10333 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10334 tree_type == TREE_TYPE_SOUNDS_DIR)
10336 artwork.snd_current = tree_node_new;
10338 DrawChooseTree(&artwork.snd_current);
10340 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10341 tree_type == TREE_TYPE_MUSIC_DIR)
10343 artwork.mus_current = tree_node_new;
10345 DrawChooseTree(&artwork.mus_current);
10350 static int UploadTapes(void)
10352 SetGameStatus(GAME_MODE_LOADING);
10354 FadeSetEnterScreen();
10355 FadeOut(REDRAW_ALL);
10357 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10359 FadeIn(REDRAW_ALL);
10361 DrawInitTextHead("Uploading tapes");
10363 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10364 global.autoplay_leveldir = "ALL";
10365 global.autoplay_all = TRUE;
10367 int num_tapes_uploaded = AutoPlayTapes();
10369 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10370 global.autoplay_leveldir = NULL;
10371 global.autoplay_all = FALSE;
10373 SetGameStatus(GAME_MODE_MAIN);
10377 return num_tapes_uploaded;
10380 static boolean OfferUploadTapes(void)
10382 if (!Request(setup.has_remaining_tapes ?
10383 "Upload missing tapes to the high score server now?" :
10384 "Upload all your tapes to the high score server now?", REQ_ASK))
10387 int num_tapes_uploaded = UploadTapes();
10390 if (num_tapes_uploaded < 0)
10392 num_tapes_uploaded = -num_tapes_uploaded - 1;
10394 if (num_tapes_uploaded == 0)
10395 sprintf(message, "Upload failed! No tapes uploaded!");
10396 else if (num_tapes_uploaded == 1)
10397 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10399 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10400 num_tapes_uploaded);
10402 Request(message, REQ_CONFIRM);
10404 // if uploading tapes failed, add tape upload entry to setup menu
10405 setup.provide_uploading_tapes = TRUE;
10406 setup.has_remaining_tapes = TRUE;
10408 SaveSetup_ServerSetup();
10413 if (num_tapes_uploaded == 0)
10414 sprintf(message, "No tapes uploaded!");
10415 else if (num_tapes_uploaded == 1)
10416 sprintf(message, "1 tape uploaded!");
10418 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10420 Request(message, REQ_CONFIRM);
10422 if (num_tapes_uploaded > 0)
10423 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10425 // after all tapes have been uploaded, remove entry from setup menu
10426 setup.provide_uploading_tapes = FALSE;
10427 setup.has_remaining_tapes = FALSE;
10429 SaveSetup_ServerSetup();
10434 static void CheckUploadTapes(void)
10436 if (!setup.ask_for_uploading_tapes)
10439 // after asking for uploading tapes, do not ask again
10440 setup.ask_for_uploading_tapes = FALSE;
10441 setup.ask_for_remaining_tapes = FALSE;
10443 if (directoryExists(getTapeDir(NULL)))
10445 boolean tapes_uploaded = OfferUploadTapes();
10447 if (!tapes_uploaded)
10449 Request(setup.has_remaining_tapes ?
10450 "You can upload missing tapes from the setup menu later!" :
10451 "You can upload your tapes from the setup menu later!",
10457 // if tapes directory does not exist yet, never offer uploading all tapes
10458 setup.provide_uploading_tapes = FALSE;
10461 SaveSetup_ServerSetup();
10464 static void UpgradePlayerUUID(void)
10466 ApiResetUUIDAsThread(getUUID());
10469 static void CheckUpgradePlayerUUID(void)
10471 if (setup.player_version > 1)
10474 UpgradePlayerUUID();
10477 void CheckApiServerTasks(void)
10479 // check if the player's UUID has to be upgraded
10480 CheckUpgradePlayerUUID();
10482 // check if there are any tapes to be uploaded
10483 CheckUploadTapes();