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 GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
317 static int info_mode = INFO_MODE_MAIN;
318 static int setup_mode = SETUP_MODE_MAIN;
320 static TreeInfo *window_sizes = NULL;
321 static TreeInfo *window_size_current = NULL;
323 static TreeInfo *scaling_types = NULL;
324 static TreeInfo *scaling_type_current = NULL;
326 static TreeInfo *rendering_modes = NULL;
327 static TreeInfo *rendering_mode_current = NULL;
329 static TreeInfo *vsync_modes = NULL;
330 static TreeInfo *vsync_mode_current = NULL;
332 static TreeInfo *scroll_delays = NULL;
333 static TreeInfo *scroll_delay_current = NULL;
335 static TreeInfo *snapshot_modes = NULL;
336 static TreeInfo *snapshot_mode_current = NULL;
338 static TreeInfo *scores_types = NULL;
339 static TreeInfo *scores_type_current = NULL;
341 static TreeInfo *game_speeds_normal = NULL;
342 static TreeInfo *game_speeds_extended = NULL;
343 static TreeInfo *game_speeds = NULL;
344 static TreeInfo *game_speed_current = NULL;
346 static TreeInfo *volumes_simple = NULL;
347 static TreeInfo *volume_simple_current = NULL;
349 static TreeInfo *volumes_loops = NULL;
350 static TreeInfo *volume_loops_current = NULL;
352 static TreeInfo *volumes_music = NULL;
353 static TreeInfo *volume_music_current = NULL;
355 static TreeInfo *touch_controls = NULL;
356 static TreeInfo *touch_control_current = NULL;
358 static TreeInfo *move_distances = NULL;
359 static TreeInfo *move_distance_current = NULL;
361 static TreeInfo *drop_distances = NULL;
362 static TreeInfo *drop_distance_current = NULL;
364 static TreeInfo *transparencies = NULL;
365 static TreeInfo *transparency_current = NULL;
367 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
368 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
370 static TreeInfo *player_name = NULL;
371 static TreeInfo *player_name_current = NULL;
373 static TreeInfo *level_number = NULL;
374 static TreeInfo *level_number_current = NULL;
376 static TreeInfo *score_entries = NULL;
377 static TreeInfo *score_entry_current = NULL;
379 static struct ValueTextInfo window_sizes_list[] =
384 { 100, "100 % (Default)" },
397 static struct StringValueTextInfo scaling_types_list[] =
399 { SCALING_QUALITY_NEAREST, "Off" },
400 { SCALING_QUALITY_LINEAR, "Linear" },
401 { SCALING_QUALITY_BEST, "Anisotropic" },
406 static struct StringValueTextInfo rendering_modes_list[] =
408 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
409 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
411 // this mode may work under certain conditions, but does not work on Windows
412 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
414 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
419 static struct StringValueTextInfo vsync_modes_list[] =
421 { STR_VSYNC_MODE_OFF, "Off" },
422 { STR_VSYNC_MODE_NORMAL, "Normal" },
423 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
428 static struct StringValueTextInfo scores_types_list[] =
430 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
431 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
432 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
437 static struct ValueTextInfo game_speeds_list_normal[] =
448 static struct ValueTextInfo game_speeds_list_extended[] =
450 { 1000, "1 fps (Extremely Slow)" },
455 { 29, "35 fps (Original Supaplex)" },
457 { 20, "50 fps (=== Normal Speed ===)" },
458 { 16, "60 fps (60 Hz VSync Speed)" },
459 { 14, "70 fps (Maximum Supaplex)" },
463 { 1, "1000 fps (Extremely Fast)" },
468 static struct ValueTextInfo *game_speeds_list;
470 static struct ValueTextInfo scroll_delays_list[] =
472 { 0, "0 Tiles (No Scroll Delay)" },
475 { 3, "3 Tiles (Default)" },
480 { 8, "8 Tiles (Maximum Scroll Delay)"},
485 static struct StringValueTextInfo snapshot_modes_list[] =
487 { STR_SNAPSHOT_MODE_OFF, "Off" },
488 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
489 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
490 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
495 static struct ValueTextInfo volumes_list[] =
515 static struct StringValueTextInfo touch_controls_list[] =
517 { TOUCH_CONTROL_OFF, "Off" },
518 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
519 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
520 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
525 static struct ValueTextInfo distances_list[] =
540 static struct ValueTextInfo transparencies_list[] =
542 { 0, "0 % (Opaque)" },
552 { 100, "100 % (Invisible)" },
557 static struct ValueTextInfo grid_sizes_list[] =
593 static int align_xoffset = 0;
594 static int align_yoffset = 0;
596 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
597 (s) <= GAME_MODE_SETUP ? (s) : \
598 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
600 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
601 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
603 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
604 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
605 (i) <= INFO_MODE_LEVELSET ? (i) : \
608 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
609 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
610 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
611 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
612 SETUP_MODE_CHOOSE_ARTWORK : \
613 SETUP_MODE_CHOOSE_OTHER)
615 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
616 menu.draw_xoffset[GAME_MODE_INFO] : \
617 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
618 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
619 menu.draw_yoffset[GAME_MODE_INFO] : \
620 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
621 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
622 menu.extra_spacing[GAME_MODE_INFO] : \
623 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
625 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
626 menu.draw_xoffset[GAME_MODE_SETUP] : \
627 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
628 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
629 menu.draw_yoffset[GAME_MODE_SETUP] : \
630 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
631 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
632 menu.extra_spacing[GAME_MODE_SETUP] : \
633 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
635 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
637 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
639 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
640 DRAW_XOFFSET_INFO(info_mode) : \
641 (s) == GAME_MODE_SETUP ? \
642 DRAW_XOFFSET_SETUP(setup_mode) : \
643 menu.draw_xoffset[DRAW_MODE(s)])
644 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
645 DRAW_YOFFSET_INFO(info_mode) : \
646 (s) == GAME_MODE_SETUP ? \
647 DRAW_YOFFSET_SETUP(setup_mode) : \
648 menu.draw_yoffset[DRAW_MODE(s)])
649 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
650 EXTRA_SPACING_INFO(info_mode) : \
651 (s) == GAME_MODE_SETUP ? \
652 EXTRA_SPACING_SETUP(setup_mode) : \
653 (s) == GAME_MODE_SCORES ? \
654 EXTRA_SPACING_SCORES(info_mode) : \
655 menu.extra_spacing[DRAW_MODE(s)])
657 #define mSX (SX + DRAW_XOFFSET(game_status))
658 #define mSY (SY + DRAW_YOFFSET(game_status))
660 #define amSX (mSX + align_xoffset)
661 #define amSY (mSY + align_yoffset)
663 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
664 menu.list_size[game_status] : \
665 MAX_MENU_ENTRIES_ON_SCREEN)
667 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
668 NUM_MENU_ENTRIES_ON_SCREEN)
671 // title display and control definitions
673 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
674 2 * MAX_NUM_TITLE_MESSAGES)
676 #define NO_DIRECT_LEVEL_SELECT (-1)
679 static int num_title_screens = 0;
681 struct TitleControlInfo
690 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
693 // credits screens definitions
695 static int num_credits_screens = 0;
696 static boolean use_global_credits_screens = FALSE;
699 // program info screens definitions
701 static int num_program_info_screens = 0;
704 // main menu display and control definitions
706 #define MAIN_CONTROL_NAME 0
707 #define MAIN_CONTROL_LEVELS 1
708 #define MAIN_CONTROL_SCORES 2
709 #define MAIN_CONTROL_EDITOR 3
710 #define MAIN_CONTROL_INFO 4
711 #define MAIN_CONTROL_GAME 5
712 #define MAIN_CONTROL_SETUP 6
713 #define MAIN_CONTROL_QUIT 7
714 #define MAIN_CONTROL_PREV_LEVEL 8
715 #define MAIN_CONTROL_NEXT_LEVEL 9
716 #define MAIN_CONTROL_FIRST_LEVEL 10
717 #define MAIN_CONTROL_LAST_LEVEL 11
718 #define MAIN_CONTROL_LEVEL_NUMBER 12
719 #define MAIN_CONTROL_LEVEL_INFO_1 13
720 #define MAIN_CONTROL_LEVEL_INFO_2 14
721 #define MAIN_CONTROL_LEVEL_NAME 15
722 #define MAIN_CONTROL_LEVEL_AUTHOR 16
723 #define MAIN_CONTROL_LEVEL_YEAR 17
724 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
725 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
726 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
727 #define MAIN_CONTROL_TITLE_1 21
728 #define MAIN_CONTROL_TITLE_2 22
729 #define MAIN_CONTROL_TITLE_3 23
731 static char str_main_text_name[10];
732 static char str_main_text_first_level[10];
733 static char str_main_text_last_level[10];
734 static char str_main_text_level_number[10];
736 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
738 static char *main_text_name = str_main_text_name;
739 static char *main_text_first_level = str_main_text_first_level;
740 static char *main_text_last_level = str_main_text_last_level;
741 static char *main_text_level_number = str_main_text_level_number;
742 static char *main_text_levels = "Levelset";
743 static char *main_text_scores = "Hall Of Fame";
744 static char *main_text_editor = "Level Creator";
745 static char *main_text_info = "Info Screen";
746 static char *main_text_game = "Start Game";
747 static char *main_text_setup = "Setup";
748 static char *main_text_quit = "Quit";
749 static char *main_text_level_name = level.name;
750 static char *main_text_level_author = level.author;
751 static char *main_text_level_year = NULL;
752 static char *main_text_level_imported_from = NULL;
753 static char *main_text_level_imported_by = NULL;
754 static char *main_text_level_tested_by = NULL;
755 static char *main_text_title_1 = NULL;
756 static char *main_text_title_2 = NULL;
757 static char *main_text_title_3 = NULL;
759 extern char debug_xsn_mode[];
761 struct MainControlInfo
765 struct MenuPosInfo *pos_button;
768 struct TextPosInfo *pos_text;
771 struct TextPosInfo *pos_input;
775 static struct MainControlInfo main_controls[] =
779 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
780 &menu.main.text.name, &main_text_name,
781 &menu.main.input.name, &setup.player_name,
785 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
786 &menu.main.text.levels, &main_text_levels,
791 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
792 &menu.main.text.scores, &main_text_scores,
797 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
798 &menu.main.text.editor, &main_text_editor,
803 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
804 &menu.main.text.info, &main_text_info,
809 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
810 &menu.main.text.game, &main_text_game,
815 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
816 &menu.main.text.setup, &main_text_setup,
821 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
822 &menu.main.text.quit, &main_text_quit,
826 MAIN_CONTROL_PREV_LEVEL,
832 MAIN_CONTROL_NEXT_LEVEL,
838 MAIN_CONTROL_FIRST_LEVEL,
840 &menu.main.text.first_level, &main_text_first_level,
844 MAIN_CONTROL_LAST_LEVEL,
846 &menu.main.text.last_level, &main_text_last_level,
850 MAIN_CONTROL_LEVEL_NUMBER,
852 &menu.main.text.level_number, &main_text_level_number,
856 MAIN_CONTROL_LEVEL_INFO_1,
858 &menu.main.text.level_info_1, NULL,
862 MAIN_CONTROL_LEVEL_INFO_2,
864 &menu.main.text.level_info_2, NULL,
868 MAIN_CONTROL_LEVEL_NAME,
870 &menu.main.text.level_name, &main_text_level_name,
874 MAIN_CONTROL_LEVEL_AUTHOR,
876 &menu.main.text.level_author, &main_text_level_author,
880 MAIN_CONTROL_LEVEL_YEAR,
882 &menu.main.text.level_year, &main_text_level_year,
886 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
888 &menu.main.text.level_imported_from, &main_text_level_imported_from,
892 MAIN_CONTROL_LEVEL_IMPORTED_BY,
894 &menu.main.text.level_imported_by, &main_text_level_imported_by,
898 MAIN_CONTROL_LEVEL_TESTED_BY,
900 &menu.main.text.level_tested_by, &main_text_level_tested_by,
904 MAIN_CONTROL_TITLE_1,
906 &menu.main.text.title_1, &main_text_title_1,
910 MAIN_CONTROL_TITLE_2,
912 &menu.main.text.title_2, &main_text_title_2,
916 MAIN_CONTROL_TITLE_3,
918 &menu.main.text.title_3, &main_text_title_3,
931 static int getTitleScreenGraphic(int nr, boolean initial)
933 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
936 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
938 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
942 static int getTitleScreenGameMode(boolean initial)
944 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
948 static int getTitleMessageGameMode(boolean initial)
950 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
953 static int getTitleAnimMode(struct TitleControlInfo *tci)
955 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
957 return base + tci->local_nr;
961 static int getTitleScreenBackground(boolean initial)
963 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
968 static int getTitleMessageBackground(int nr, boolean initial)
970 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
974 static int getTitleBackground(int nr, boolean initial, boolean is_image)
976 int base = (is_image ?
977 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
978 IMG_BACKGROUND_TITLESCREEN_1) :
979 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
980 IMG_BACKGROUND_TITLEMESSAGE_1));
981 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
982 IMG_BACKGROUND_TITLE);
983 int graphic_local = base + nr;
985 if (graphic_info[graphic_local].bitmap != NULL)
986 return graphic_local;
988 if (graphic_info[graphic_global].bitmap != NULL)
989 return graphic_global;
991 return IMG_UNDEFINED;
994 static int getTitleSound(struct TitleControlInfo *tci)
996 boolean is_image = tci->is_image;
997 int initial = tci->initial;
998 int nr = tci->local_nr;
999 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1000 int base = (is_image ?
1001 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
1002 SND_BACKGROUND_TITLESCREEN_1) :
1003 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1004 SND_BACKGROUND_TITLEMESSAGE_1));
1005 int sound_global = menu.sound[mode];
1006 int sound_local = base + nr;
1009 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
1010 nr, initial, is_image,
1011 sound_global, getSoundListEntry(sound_global)->filename,
1012 sound_local, getSoundListEntry(sound_local)->filename);
1015 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1018 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1019 return sound_global;
1021 return SND_UNDEFINED;
1024 static int getTitleMusic(struct TitleControlInfo *tci)
1026 boolean is_image = tci->is_image;
1027 int initial = tci->initial;
1028 int nr = tci->local_nr;
1029 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1030 int base = (is_image ?
1031 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1032 MUS_BACKGROUND_TITLESCREEN_1) :
1033 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1034 MUS_BACKGROUND_TITLEMESSAGE_1));
1035 int music_global = menu.music[mode];
1036 int music_local = base + nr;
1039 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1040 nr, initial, is_image,
1041 music_global, getMusicListEntry(music_global)->filename,
1042 music_local, getMusicListEntry(music_local)->filename);
1045 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1048 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1049 return music_global;
1051 return MUS_UNDEFINED;
1054 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1056 boolean is_image = tci->is_image;
1057 boolean initial = tci->initial;
1058 boolean first = tci->first;
1059 int nr = tci->local_nr;
1060 struct TitleMessageInfo tmi;
1061 struct TitleFadingInfo ti;
1063 tmi = (is_image ? (initial ? (first ?
1064 titlescreen_initial_first[nr] :
1065 titlescreen_initial[nr])
1067 titlescreen_first[nr] :
1069 : (initial ? (first ?
1070 titlemessage_initial_first[nr] :
1071 titlemessage_initial[nr])
1073 titlemessage_first[nr] :
1074 titlemessage[nr])));
1076 ti.fade_mode = tmi.fade_mode;
1077 ti.fade_delay = tmi.fade_delay;
1078 ti.post_delay = tmi.post_delay;
1079 ti.auto_delay = tmi.auto_delay;
1080 ti.auto_delay_unit = tmi.auto_delay_unit;
1085 static int compareTitleControlInfo(const void *object1, const void *object2)
1087 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1088 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1091 if (tci1->initial != tci2->initial)
1092 compare_result = (tci1->initial ? -1 : +1);
1093 else if (tci1->sort_priority != tci2->sort_priority)
1094 compare_result = tci1->sort_priority - tci2->sort_priority;
1095 else if (tci1->is_image != tci2->is_image)
1096 compare_result = (tci1->is_image ? -1 : +1);
1098 compare_result = tci1->local_nr - tci2->local_nr;
1100 return compare_result;
1103 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1105 int nr, int sort_priority)
1107 title_controls[num_title_screens].is_image = is_image;
1108 title_controls[num_title_screens].initial = initial;
1109 title_controls[num_title_screens].local_nr = nr;
1110 title_controls[num_title_screens].sort_priority = sort_priority;
1112 title_controls[num_title_screens].first = FALSE; // will be set later
1114 num_title_screens++;
1117 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1121 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1123 int graphic = getTitleScreenGraphic(i, initial);
1124 Bitmap *bitmap = graphic_info[graphic].bitmap;
1125 int sort_priority = graphic_info[graphic].sort_priority;
1128 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1131 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1133 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1134 char *filename = getLevelSetTitleMessageFilename(i, initial);
1135 int sort_priority = tmi->sort_priority;
1137 if (filename != NULL)
1138 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1142 static void InitializeTitleControls(boolean show_title_initial)
1144 num_title_screens = 0;
1146 // 1st step: initialize title screens for game start (only when starting)
1147 if (show_title_initial)
1148 InitializeTitleControls_CheckTitleInfo(TRUE);
1150 // 2nd step: initialize title screens for current level set
1151 InitializeTitleControls_CheckTitleInfo(FALSE);
1153 // sort title screens according to sort_priority and title number
1154 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1155 compareTitleControlInfo);
1157 // mark first title screen
1158 title_controls[0].first = TRUE;
1161 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1163 return (pos != NULL && pos->x != -1 && pos->y != -1);
1166 static boolean visibleTextPos(struct TextPosInfo *pos)
1168 return (pos != NULL && pos->x != -1 && pos->y != -1);
1171 static void InitializeMainControls(void)
1173 boolean local_team_mode = (!network.enabled && setup.team_mode);
1176 // set main control text values to dynamically determined values
1177 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1179 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1180 menu.main.text.first_level.size));
1181 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1182 menu.main.text.last_level.size));
1183 strcpy(main_text_level_number, int2str(level_nr,
1184 menu.main.text.level_number.size));
1186 main_text_level_year = leveldir_current->year;
1187 main_text_level_imported_from = leveldir_current->imported_from;
1188 main_text_level_imported_by = leveldir_current->imported_by;
1189 main_text_level_tested_by = leveldir_current->tested_by;
1191 main_text_title_1 = getConfigProgramTitleString();
1192 main_text_title_2 = getConfigProgramCopyrightString();
1193 main_text_title_3 = getConfigProgramCompanyString();
1195 // set main control screen positions to dynamically determined values
1196 for (i = 0; main_controls[i].nr != -1; i++)
1198 struct MainControlInfo *mci = &main_controls[i];
1200 struct MenuPosInfo *pos_button = mci->pos_button;
1201 struct TextPosInfo *pos_text = mci->pos_text;
1202 struct TextPosInfo *pos_input = mci->pos_input;
1203 char *text = (mci->text ? *mci->text : NULL);
1204 char *input = (mci->input ? *mci->input : NULL);
1205 int button_graphic = mci->button_graphic;
1206 int font_text = (pos_text ? pos_text->font : -1);
1207 int font_input = (pos_input ? pos_input->font : -1);
1209 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1210 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1211 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1212 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1213 int text_chars = (text != NULL ? strlen(text) : 0);
1214 int input_chars = (input != NULL ? strlen(input) : 0);
1217 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1219 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1220 int text_width = font_text_width * text_chars;
1221 int text_height = font_text_height;
1222 int input_width = font_input_width * input_chars;
1223 int input_height = font_input_height;
1225 if (nr == MAIN_CONTROL_NAME)
1227 menu.main.input.name.width = input_width;
1228 menu.main.input.name.height = input_height;
1231 if (pos_button != NULL) // (x/y may be -1/-1 here)
1233 pos_button->width = button_width;
1234 pos_button->height = button_height;
1237 if (pos_text != NULL) // (x/y may be -1/-1 here)
1239 // calculate text size -- needed for text alignment
1240 boolean calculate_text_size = (text != NULL);
1242 if (pos_text->width == -1 || calculate_text_size)
1243 pos_text->width = text_width;
1244 if (pos_text->height == -1 || calculate_text_size)
1245 pos_text->height = text_height;
1247 if (visibleMenuPos(pos_button))
1249 if (pos_text->x == -1)
1250 pos_text->x = pos_button->x + pos_button->width;
1251 if (pos_text->y == -1)
1253 pos_button->y + (pos_button->height - pos_text->height) / 2;
1257 if (pos_input != NULL) // (x/y may be -1/-1 here)
1259 if (visibleTextPos(pos_text))
1261 if (pos_input->x == -1)
1262 pos_input->x = pos_text->x + pos_text->width;
1263 if (pos_input->y == -1)
1264 pos_input->y = pos_text->y;
1267 if (pos_input->width == -1)
1268 pos_input->width = input_width;
1269 if (pos_input->height == -1)
1270 pos_input->height = input_height;
1275 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1276 int graphic, boolean pressed)
1278 struct GraphicInfo *g = &graphic_info[graphic];
1281 int xoffset = (pressed ? g->pressed_xoffset : 0);
1282 int yoffset = (pressed ? g->pressed_yoffset : 0);
1284 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1286 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1287 g->width, g->height, dst_x, dst_y);
1290 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1291 boolean active_input,
1292 boolean pressed_button)
1296 for (i = 0; main_controls[i].nr != -1; i++)
1298 struct MainControlInfo *mci = &main_controls[i];
1300 if (mci->nr == nr || nr == -1)
1302 struct MenuPosInfo *pos_button = mci->pos_button;
1303 struct TextPosInfo *pos_text = mci->pos_text;
1304 struct TextPosInfo *pos_input = mci->pos_input;
1305 char *text = (mci->text ? *mci->text : NULL);
1306 char *input = (mci->input ? *mci->input : NULL);
1307 int button_graphic = mci->button_graphic;
1308 int font_text = (pos_text ? pos_text->font : -1);
1309 int font_input = (pos_input ? pos_input->font : -1);
1313 button_graphic = BUTTON_ACTIVE(button_graphic);
1314 font_text = FONT_ACTIVE(font_text);
1319 font_input = FONT_ACTIVE(font_input);
1322 if (visibleMenuPos(pos_button))
1324 struct MenuPosInfo *pos = pos_button;
1325 int x = mSX + pos->x;
1326 int y = mSY + pos->y;
1328 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1329 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1332 if (visibleTextPos(pos_text) && text != NULL)
1334 struct TextPosInfo *pos = pos_text;
1335 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1336 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1339 // (check why/if this is needed)
1340 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1342 DrawText(x, y, text, font_text);
1345 if (visibleTextPos(pos_input) && input != NULL)
1347 struct TextPosInfo *pos = pos_input;
1348 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1349 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1352 // (check why/if this is needed)
1353 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1355 DrawText(x, y, input, font_input);
1361 static void DrawCursorAndText_Main(int nr, boolean active_text,
1362 boolean pressed_button)
1364 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1368 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1369 boolean pressed_button)
1371 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1375 static struct MainControlInfo *getMainControlInfo(int nr)
1379 for (i = 0; main_controls[i].nr != -1; i++)
1380 if (main_controls[i].nr == nr)
1381 return &main_controls[i];
1386 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1391 int rect_x = ALIGNED_TEXT_XPOS(rect);
1392 int rect_y = ALIGNED_TEXT_YPOS(rect);
1394 return (x >= rect_x && x < rect_x + rect->width &&
1395 y >= rect_y && y < rect_y + rect->height);
1398 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1403 int rect_x = ALIGNED_TEXT_XPOS(rect);
1404 int rect_y = ALIGNED_TEXT_YPOS(rect);
1407 Debug("screens:insideTextPosRect",
1408 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1409 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1410 (x >= rect_x && x < rect_x + rect->width &&
1411 y >= rect_y && y < rect_y + rect->height));
1414 return (x >= rect_x && x < rect_x + rect->width &&
1415 y >= rect_y && y < rect_y + rect->height);
1418 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1420 int rect_width = preview->xsize * preview->tile_size;
1421 int rect_height = preview->ysize * preview->tile_size;
1422 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1423 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1425 return (x >= rect_x && x < rect_x + rect_width &&
1426 y >= rect_y && y < rect_y + rect_height);
1429 static void AdjustScrollbar(int id, int items_max, int items_visible,
1432 struct GadgetInfo *gi = screen_gadget[id];
1434 if (item_position > items_max - items_visible)
1435 item_position = items_max - items_visible;
1437 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1438 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1439 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1442 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1444 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1448 static void clearMenuListArea(void)
1450 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1452 // correct scrollbar position if placed outside menu (playfield) area
1453 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1454 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1456 // clear menu list area, but not title or scrollbar
1457 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1458 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1461 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1463 static int cursor_array[MAX_LEV_FIELDY];
1464 int x = amSX + TILEX * xpos;
1465 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1470 cursor_array[ypos] = graphic;
1472 graphic = cursor_array[ypos];
1476 graphic = BUTTON_ACTIVE(graphic);
1478 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1479 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1482 static void initCursor(int ypos, int graphic)
1484 drawCursorExt(0, ypos, FALSE, graphic);
1487 static void drawCursor(int ypos, boolean active)
1489 drawCursorExt(0, ypos, active, -1);
1492 static void drawCursorXY(int xpos, int ypos, int graphic)
1494 drawCursorExt(xpos, ypos, FALSE, graphic);
1497 static void drawChooseTreeCursor(int ypos, boolean active)
1499 drawCursorExt(0, ypos, active, -1);
1502 static int getChooseTreeEditFont(boolean active)
1504 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1507 static int getChooseTreeEditXPos(int pos)
1509 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1510 int xoffset = (has_scrollbar ? -1 : 0);
1511 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1512 int sx = amSX + xpos * TILEX;
1513 int font_nr = getChooseTreeEditFont(FALSE);
1514 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1516 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1519 static int getChooseTreeEditYPos(int ypos_raw)
1521 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1522 int sy = amSY + ypos * TILEY;
1527 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1529 int sx = getChooseTreeEditXPos(POS_LEFT);
1530 int sy = getChooseTreeEditYPos(ypos_raw);
1531 int font_nr = getChooseTreeEditFont(active);
1533 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1536 static void DrawHeadline(void)
1538 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1539 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1542 static void DrawTitleScreenImage(int nr, boolean initial)
1544 int graphic = getTitleScreenGraphic(nr, initial);
1545 Bitmap *bitmap = graphic_info[graphic].bitmap;
1546 int width = graphic_info[graphic].width;
1547 int height = graphic_info[graphic].height;
1548 int src_x = graphic_info[graphic].src_x;
1549 int src_y = graphic_info[graphic].src_y;
1555 if (width > WIN_XSIZE)
1557 // image width too large for window => center image horizontally
1558 src_x = (width - WIN_XSIZE) / 2;
1562 if (height > WIN_YSIZE)
1564 // image height too large for window => center image vertically
1565 src_y = (height - WIN_YSIZE) / 2;
1569 // always display title screens centered
1570 dst_x = (WIN_XSIZE - width) / 2;
1571 dst_y = (WIN_YSIZE - height) / 2;
1573 SetDrawBackgroundMask(REDRAW_ALL);
1574 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1576 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1578 if (DrawingOnBackground(dst_x, dst_y))
1579 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1581 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1583 redraw_mask = REDRAW_ALL;
1586 static void DrawTitleScreenMessage(int nr, boolean initial)
1588 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1589 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1591 if (filename == NULL)
1594 // force TITLE font on title message screen
1595 SetFontStatus(getTitleMessageGameMode(initial));
1597 // if chars *and* width set to "-1", automatically determine width
1598 if (tmi->chars == -1 && tmi->width == -1)
1599 tmi->width = viewport.window[game_status].width;
1601 // if lines *and* height set to "-1", automatically determine height
1602 if (tmi->lines == -1 && tmi->height == -1)
1603 tmi->height = viewport.window[game_status].height;
1605 // if chars set to "-1", automatically determine by text and font width
1606 if (tmi->chars == -1)
1607 tmi->chars = tmi->width / getFontWidth(tmi->font);
1609 tmi->width = tmi->chars * getFontWidth(tmi->font);
1611 // if lines set to "-1", automatically determine by text and font height
1612 if (tmi->lines == -1)
1613 tmi->lines = tmi->height / getFontHeight(tmi->font);
1615 tmi->height = tmi->lines * getFontHeight(tmi->font);
1617 // if x set to "-1", automatically determine by width and alignment
1619 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1621 // if y set to "-1", automatically determine by height and alignment
1623 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1625 SetDrawBackgroundMask(REDRAW_ALL);
1626 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1628 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1630 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1631 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1632 tmi->autowrap, tmi->centered, tmi->parse_comments);
1637 static void DrawTitleScreen(void)
1639 KeyboardAutoRepeatOff();
1641 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1644 static boolean CheckTitleScreen(boolean levelset_has_changed)
1646 static boolean show_title_initial = TRUE;
1647 boolean show_titlescreen = FALSE;
1649 // needed to be able to skip title screen, if no image or message defined
1650 InitializeTitleControls(show_title_initial);
1652 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1653 show_titlescreen = TRUE;
1655 // show initial title images and messages only once at program start
1656 show_title_initial = FALSE;
1658 return (show_titlescreen && num_title_screens > 0);
1661 void DrawMainMenu(void)
1663 static LevelDirTree *leveldir_last_valid = NULL;
1664 boolean levelset_has_changed = FALSE;
1665 int fade_mask = REDRAW_FIELD;
1667 LimitScreenUpdates(FALSE);
1669 FadeSetLeaveScreen();
1671 // do not fade out here -- function may continue and fade on editor screen
1674 FadeMenuSoundsAndMusic();
1676 ExpireSoundLoops(FALSE);
1678 KeyboardAutoRepeatOn();
1680 audio.sound_deactivated = FALSE;
1684 // needed if last screen was the playing screen, invoked from level editor
1685 if (level_editor_test_game)
1687 CloseDoor(DOOR_CLOSE_ALL);
1689 SetGameStatus(GAME_MODE_EDITOR);
1696 // needed if last screen was the playing screen, invoked from hall of fame
1697 if (score_info_tape_play)
1699 CloseDoor(DOOR_CLOSE_ALL);
1701 SetGameStatus(GAME_MODE_SCOREINFO);
1703 DrawScoreInfo(scores.last_entry_nr);
1708 // leveldir_current may be invalid (level group, parent link, node copy)
1709 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1711 if (leveldir_current != leveldir_last_valid)
1713 UpdateLastPlayedLevels_TreeInfo();
1715 levelset_has_changed = TRUE;
1718 // store valid level series information
1719 leveldir_last_valid = leveldir_current;
1721 // needed if last screen (level choice) changed graphics, sounds or music
1722 ReloadCustomArtwork(0);
1724 if (CheckTitleScreen(levelset_has_changed))
1726 SetGameStatus(GAME_MODE_TITLE);
1733 if (redraw_mask & REDRAW_ALL)
1734 fade_mask = REDRAW_ALL;
1737 fade_mask = REDRAW_ALL;
1741 // needed if different viewport properties defined for menues
1742 ChangeViewportPropertiesIfNeeded();
1744 SetDrawtoField(DRAW_TO_BACKBUFFER);
1746 // level_nr may have been set to value over handicap with level editor
1747 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1748 level_nr = leveldir_current->handicap_level;
1750 LoadLevel(level_nr);
1751 LoadScore(level_nr);
1753 SaveLevelSetup_SeriesInfo();
1755 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1756 SetDrawDeactivationMask(REDRAW_NONE);
1757 SetDrawBackgroundMask(REDRAW_FIELD);
1759 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1762 if (fade_mask == REDRAW_ALL)
1763 RedrawGlobalBorder();
1768 InitializeMainControls();
1770 DrawCursorAndText_Main(-1, FALSE, FALSE);
1771 DrawPreviewLevelInitial();
1772 DrawNetworkPlayers();
1774 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1777 if (TAPE_IS_EMPTY(tape))
1779 DrawCompleteVideoDisplay();
1781 PlayMenuSoundsAndMusic();
1783 // create gadgets for main menu screen
1784 FreeScreenGadgets();
1785 CreateScreenGadgets();
1787 // may be required if audio buttons shown on tape and changed in setup menu
1789 CreateGameButtons();
1791 // map gadgets for main menu screen
1793 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1794 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1796 // copy actual game door content to door double buffer for OpenDoor()
1797 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1798 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1800 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1802 DrawMaskedBorder(fade_mask);
1807 // update screen area with special editor door
1808 redraw_mask |= REDRAW_ALL;
1811 SetMouseCursor(CURSOR_DEFAULT);
1813 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1815 SyncEmscriptenFilesystem();
1817 // needed once after program start or after user change
1818 CheckApiServerTasks();
1821 static void gotoTopLevelDir(void)
1823 // move upwards until inside (but not above) top level directory
1824 while (leveldir_current->node_parent &&
1825 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1827 // write a "path" into level tree for easy navigation to last level
1828 if (leveldir_current->node_parent->node_group->cl_first == -1)
1830 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1831 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1832 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1833 int cl_first, cl_cursor;
1835 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1836 cl_cursor = leveldir_pos - cl_first;
1838 leveldir_current->node_parent->node_group->cl_first = cl_first;
1839 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1842 leveldir_current = leveldir_current->node_parent;
1846 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1848 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1850 return (use_frame_counter ? video.frame_counter : Counter());
1853 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1854 struct TitleFadingInfo *fi)
1856 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1859 static void ResetTitleAutoDelay(unsigned int *counter_var,
1860 struct TitleFadingInfo *fi)
1862 *counter_var = getAutoDelayCounter(fi);
1865 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1867 static unsigned int title_delay = 0;
1868 static int title_screen_nr = 0;
1869 static int last_sound = -1, last_music = -1;
1870 boolean return_to_main_menu = FALSE;
1871 struct TitleControlInfo *tci;
1874 if (button == MB_MENU_INITIALIZE)
1877 title_screen_nr = 0;
1878 tci = &title_controls[title_screen_nr];
1880 SetAnimStatus(getTitleAnimMode(tci));
1882 last_sound = SND_UNDEFINED;
1883 last_music = MUS_UNDEFINED;
1885 if (num_title_screens != 0)
1887 FadeSetEnterScreen();
1889 // use individual title fading instead of global "enter screen" fading
1890 fading = getTitleFading(tci);
1893 if (game_status_last_screen == GAME_MODE_INFO)
1895 if (num_title_screens == 0)
1897 // switch game mode from title screen mode back to info screen mode
1898 SetGameStatus(GAME_MODE_INFO);
1900 // store that last screen was info screen, not main menu screen
1901 game_status_last_screen = GAME_MODE_INFO;
1903 DrawInfoScreen_NotAvailable("Title screen information:",
1904 "No title screen for this level set.");
1909 FadeMenuSoundsAndMusic();
1911 FadeOut(REDRAW_ALL);
1913 // title screens may have different window size
1914 ChangeViewportPropertiesIfNeeded();
1916 // only required to update logic for redrawing global border
1920 DrawTitleScreenImage(tci->local_nr, tci->initial);
1922 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1924 sound = getTitleSound(tci);
1925 music = getTitleMusic(tci);
1927 if (sound != last_sound)
1928 PlayMenuSoundExt(sound);
1929 if (music != last_music)
1930 PlayMenuMusicExt(music);
1935 SetMouseCursor(CURSOR_NONE);
1939 ResetTitleAutoDelay(&title_delay, &fading);
1944 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1945 button = MB_MENU_CHOICE;
1947 if (button == MB_MENU_LEAVE)
1949 return_to_main_menu = TRUE;
1951 else if (button == MB_MENU_CHOICE || dx)
1953 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1955 SetGameStatus(GAME_MODE_INFO);
1957 info_mode = INFO_MODE_MAIN;
1965 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
1967 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
1969 tci = &title_controls[title_screen_nr];
1971 SetAnimStatus(getTitleAnimMode(tci));
1973 sound = getTitleSound(tci);
1974 music = getTitleMusic(tci);
1976 if (last_sound != SND_UNDEFINED && sound != last_sound)
1977 FadeSound(last_sound);
1978 if (last_music != MUS_UNDEFINED && music != last_music)
1981 fading = getTitleFading(tci);
1983 FadeOut(REDRAW_ALL);
1986 DrawTitleScreenImage(tci->local_nr, tci->initial);
1988 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1990 sound = getTitleSound(tci);
1991 music = getTitleMusic(tci);
1993 if (sound != last_sound)
1994 PlayMenuSoundExt(sound);
1995 if (music != last_music)
1996 PlayMenuMusicExt(music);
2003 ResetTitleAutoDelay(&title_delay, &fading);
2007 FadeMenuSoundsAndMusic();
2009 return_to_main_menu = TRUE;
2013 if (return_to_main_menu)
2015 SetMouseCursor(CURSOR_DEFAULT);
2017 // force full menu screen redraw after displaying title screens
2018 redraw_mask = REDRAW_ALL;
2020 if (game_status_last_screen == GAME_MODE_INFO)
2022 SetGameStatus(GAME_MODE_INFO);
2024 info_mode = INFO_MODE_MAIN;
2028 else // default: return to main menu
2030 SetGameStatus(GAME_MODE_MAIN);
2037 static void HandleMainMenu_ToggleTeamMode(void)
2039 setup.team_mode = !setup.team_mode;
2041 InitializeMainControls();
2042 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2044 DrawPreviewPlayers();
2047 static void HandleMainMenu_SelectLevel(int step, int direction,
2048 int selected_level_nr)
2050 int old_level_nr = level_nr;
2053 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2054 new_level_nr = selected_level_nr;
2056 new_level_nr = old_level_nr + step * direction;
2058 if (new_level_nr < leveldir_current->first_level)
2059 new_level_nr = leveldir_current->first_level;
2060 if (new_level_nr > leveldir_current->last_level)
2061 new_level_nr = leveldir_current->last_level;
2063 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2065 // skipping levels is only allowed when trying to skip single level
2066 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2067 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
2069 leveldir_current->handicap_level++;
2070 SaveLevelSetup_SeriesInfo();
2073 new_level_nr = leveldir_current->handicap_level;
2076 if (new_level_nr != old_level_nr)
2078 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2080 PlaySound(SND_MENU_ITEM_SELECTING);
2082 level_nr = new_level_nr;
2084 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2085 int2str(level_nr, menu.main.text.level_number.size),
2086 mci->pos_text->font);
2088 LoadLevel(level_nr);
2089 DrawPreviewLevelInitial();
2093 DrawCompleteVideoDisplay();
2095 SaveLevelSetup_SeriesInfo();
2097 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2099 // force redraw of playfield area (may be reset at this point)
2100 redraw_mask |= REDRAW_FIELD;
2104 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2106 static int choice = MAIN_CONTROL_GAME;
2107 static boolean button_pressed_last = FALSE;
2108 boolean button_pressed = FALSE;
2110 int i = 0; // needed to prevent compiler warning due to bad code below
2112 if (button == MB_MENU_INITIALIZE)
2114 DrawCursorAndText_Main(choice, TRUE, FALSE);
2119 if (mx || my) // mouse input
2123 for (i = 0; main_controls[i].nr != -1; i++)
2125 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2126 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2127 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2129 pos = main_controls[i].nr;
2135 // check if level preview was clicked
2136 if (insidePreviewRect(&preview, mx - SX, my - SY))
2137 pos = MAIN_CONTROL_GAME;
2139 // handle pressed/unpressed state for active/inactive menu buttons
2140 // (if pos != -1, "i" contains index position corresponding to "pos")
2142 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2143 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2144 button_pressed = TRUE;
2146 if (button_pressed != button_pressed_last)
2148 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2151 PlaySound(SND_MENU_BUTTON_PRESSING);
2153 PlaySound(SND_MENU_BUTTON_RELEASING);
2156 else if (dx || dy) // keyboard input
2158 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2159 choice == MAIN_CONTROL_SETUP))
2160 button = MB_MENU_CHOICE;
2165 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2167 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2169 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2171 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2173 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2175 CloseDoor(DOOR_CLOSE_2);
2177 SetGameStatus(GAME_MODE_LEVELNR);
2179 DrawChooseLevelNr();
2181 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2187 PlaySound(SND_MENU_ITEM_ACTIVATING);
2189 DrawCursorAndText_Main(choice, FALSE, FALSE);
2190 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2196 if (choice == MAIN_CONTROL_NAME)
2198 // special case: cursor left or right pressed -- toggle team mode
2199 HandleMainMenu_ToggleTeamMode();
2201 else if (choice != MAIN_CONTROL_INFO &&
2202 choice != MAIN_CONTROL_SETUP)
2204 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2210 PlaySound(SND_MENU_ITEM_SELECTING);
2212 if (pos == MAIN_CONTROL_NAME)
2215 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2217 // special case: menu text "name/team" clicked -- toggle team mode
2218 HandleMainMenu_ToggleTeamMode();
2222 if (setup.multiple_users)
2224 CloseDoor(DOOR_CLOSE_2);
2226 SetGameStatus(GAME_MODE_NAMES);
2228 DrawChoosePlayerName();
2232 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2238 else if (pos == MAIN_CONTROL_LEVELS)
2242 CloseDoor(DOOR_CLOSE_2);
2244 SetGameStatus(GAME_MODE_LEVELS);
2246 SaveLevelSetup_LastSeries();
2247 SaveLevelSetup_SeriesInfo();
2249 // restore level set if chosen from "last played level set" menu
2250 RestoreLastPlayedLevels(&leveldir_current);
2252 if (setup.internal.choose_from_top_leveldir)
2255 DrawChooseLevelSet();
2258 else if (pos == MAIN_CONTROL_SCORES)
2260 CloseDoor(DOOR_CLOSE_2);
2262 SetGameStatus(GAME_MODE_SCORES);
2264 DrawHallOfFame(level_nr);
2266 else if (pos == MAIN_CONTROL_EDITOR)
2268 if (leveldir_current->readonly &&
2269 setup.editor.show_read_only_warning)
2270 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2272 CloseDoor(DOOR_CLOSE_ALL);
2274 SetGameStatus(GAME_MODE_EDITOR);
2276 FadeSetEnterScreen();
2280 else if (pos == MAIN_CONTROL_INFO)
2282 CloseDoor(DOOR_CLOSE_2);
2284 SetGameStatus(GAME_MODE_INFO);
2286 info_mode = INFO_MODE_MAIN;
2290 else if (pos == MAIN_CONTROL_GAME)
2292 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2294 else if (pos == MAIN_CONTROL_SETUP)
2296 CloseDoor(DOOR_CLOSE_2);
2298 SetGameStatus(GAME_MODE_SETUP);
2300 setup_mode = SETUP_MODE_MAIN;
2304 else if (pos == MAIN_CONTROL_QUIT)
2306 SaveLevelSetup_LastSeries();
2307 SaveLevelSetup_SeriesInfo();
2309 #if defined(PLATFORM_EMSCRIPTEN)
2310 Request("Close the browser window to quit!", REQ_CONFIRM);
2312 if (!setup.ask_on_quit_program ||
2313 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2314 SetGameStatus(GAME_MODE_QUIT);
2320 button_pressed_last = button_pressed;
2324 // ============================================================================
2325 // info screen functions
2326 // ============================================================================
2328 static struct TokenInfo *info_info;
2329 static int num_info_info; // number of info entries shown on screen
2330 static int max_info_info; // total number of info entries in list
2332 static void execInfoTitleScreen(void)
2334 info_mode = INFO_MODE_TITLE;
2339 static void execInfoElements(void)
2341 info_mode = INFO_MODE_ELEMENTS;
2346 static void execInfoMusic(void)
2348 info_mode = INFO_MODE_MUSIC;
2353 static void execInfoCredits(void)
2355 info_mode = INFO_MODE_CREDITS;
2360 static void execInfoProgram(void)
2362 info_mode = INFO_MODE_PROGRAM;
2367 static void execInfoVersion(void)
2369 info_mode = INFO_MODE_VERSION;
2374 static void execInfoLevelSet(void)
2376 info_mode = INFO_MODE_LEVELSET;
2381 static void execExitInfo(void)
2383 SetGameStatus(GAME_MODE_MAIN);
2388 static struct TokenInfo info_info_main[] =
2390 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2391 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2392 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2393 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2394 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2395 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2396 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2397 { TYPE_EMPTY, NULL, "" },
2398 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2403 static int getMenuTextFont(int type)
2405 if (type & (TYPE_SWITCH |
2419 static struct TokenInfo *setup_info;
2420 static struct TokenInfo setup_info_input[];
2422 static struct TokenInfo *menu_info;
2424 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2425 int screen_pos, int menu_info_pos_raw,
2428 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2429 struct TokenInfo *ti = &token_info[pos];
2430 int xpos = MENU_SCREEN_START_XPOS;
2431 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2432 int font_nr = getMenuTextFont(ti->type);
2434 if (setup_mode == SETUP_MODE_INPUT)
2435 font_nr = FONT_MENU_1;
2438 font_nr = FONT_ACTIVE(font_nr);
2440 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2442 if (ti->type & ~TYPE_SKIP_ENTRY)
2443 drawCursor(screen_pos, active);
2446 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2449 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2452 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2455 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2458 static char *window_size_text;
2459 static char *scaling_type_text;
2460 static char *network_server_text;
2462 static void drawSetupValue(int, int);
2464 static void drawMenuInfoList(int first_entry, int num_page_entries,
2465 int max_page_entries)
2469 if (first_entry + num_page_entries > max_page_entries)
2472 clearMenuListArea();
2474 for (i = 0; i < num_page_entries; i++)
2476 int menu_info_pos = first_entry + i;
2477 struct TokenInfo *si = &menu_info[menu_info_pos];
2478 void *value_ptr = si->value;
2480 // set some entries to "unchangeable" according to other variables
2481 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2482 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2483 (value_ptr == &setup.sound_music && !audio.music_available) ||
2484 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2485 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2486 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2487 si->type |= TYPE_GHOSTED;
2489 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2490 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2491 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2492 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2493 else if (si->type & ~TYPE_SKIP_ENTRY)
2494 initCursor(i, IMG_MENU_BUTTON);
2496 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2498 if (si->type & TYPE_STRING)
2502 if (value_ptr == &network_server_text)
2503 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2505 if (gadget_id != -1)
2507 struct GadgetInfo *gi = screen_gadget[gadget_id];
2508 int xpos = MENU_SCREEN_START_XPOS;
2509 int ypos = MENU_SCREEN_START_YPOS + i;
2510 int x = mSX + xpos * 32;
2511 int y = mSY + ypos * 32;
2513 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2517 if (si->type & TYPE_VALUE &&
2518 menu_info == setup_info)
2519 drawSetupValue(i, menu_info_pos);
2523 static void DrawInfoScreen_Main(void)
2525 int fade_mask = REDRAW_FIELD;
2528 if (redraw_mask & REDRAW_ALL)
2529 fade_mask = REDRAW_ALL;
2532 fade_mask = REDRAW_ALL;
2535 FadeMenuSoundsAndMusic();
2537 FreeScreenGadgets();
2538 CreateScreenGadgets();
2540 // (needed after displaying title screens which disable auto repeat)
2541 KeyboardAutoRepeatOn();
2543 FadeSetLeaveScreen();
2547 // needed if different viewport properties defined for info screen
2548 ChangeViewportPropertiesIfNeeded();
2550 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2554 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2556 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2558 info_info = info_info_main;
2560 // determine maximal number of info entries that can be displayed on screen
2562 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2565 // determine maximal number of info entries available for menu of info screen
2567 for (i = 0; info_info[i].type != 0; i++)
2570 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2572 MapScreenGadgets(max_info_info);
2574 PlayMenuSoundsAndMusic();
2576 DrawMaskedBorder(fade_mask);
2581 static void changeSetupValue(int, int, int);
2583 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2584 int mode, int num_page_entries,
2585 int max_page_entries)
2587 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2588 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2589 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2590 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2591 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2592 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2593 int *num_page_entries_last = num_page_entries_all_last[game_status];
2594 int *choice_store = choice_stores[game_status];
2595 int *first_entry_store = first_entry_stores[game_status];
2596 int choice = choice_store[mode]; // starts with 0
2597 int first_entry = first_entry_store[mode]; // starts with 0
2599 int y = choice - first_entry;
2601 boolean position_set_by_scrollbar = (dx == 999);
2602 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2605 if (button == MB_MENU_INITIALIZE)
2607 // check if number of menu page entries has changed (may happen by change
2608 // of custom artwork definition value for 'list_size' for this menu screen)
2609 // (in this case, the last menu position most probably has to be corrected)
2610 if (num_page_entries != num_page_entries_last[mode])
2612 choice_store[mode] = first_entry_store[mode] = 0;
2614 choice = first_entry = 0;
2617 num_page_entries_last[mode] = num_page_entries;
2620 // advance to first valid menu entry
2621 while (choice < num_page_entries &&
2622 menu_info[choice].type & TYPE_SKIP_ENTRY)
2625 if (position_set_by_scrollbar)
2626 first_entry = first_entry_store[mode] = dy;
2628 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2629 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2631 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2633 if (choice < first_entry)
2635 choice = first_entry;
2637 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2640 else if (choice > first_entry + num_page_entries - 1)
2642 choice = first_entry + num_page_entries - 1;
2644 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2648 choice_store[mode] = choice;
2650 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2654 else if (button == MB_MENU_LEAVE)
2656 PlaySound(SND_MENU_ITEM_SELECTING);
2658 for (i = 0; i < max_page_entries; i++)
2660 if (menu_info[i].type & TYPE_LEAVE_MENU)
2662 void (*menu_callback_function)(void) = menu_info[i].value;
2666 menu_callback_function();
2668 break; // absolutely needed because function changes 'menu_info'!
2675 if (mx || my) // mouse input
2677 x = (mx - mSX) / 32;
2678 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2680 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2682 // move cursor instead of scrolling when already at start/end of list
2683 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2685 else if (dy == +1 * SCROLL_LINE &&
2686 first_entry + num_page_entries == max_page_entries)
2689 // handle scrolling screen one line or page
2691 y + dy > num_page_entries - 1)
2693 boolean redraw = FALSE;
2695 if (ABS(dy) == SCROLL_PAGE)
2696 step = num_page_entries - 1;
2698 if (dy < 0 && first_entry > 0)
2700 // scroll page/line up
2702 first_entry -= step;
2703 if (first_entry < 0)
2708 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2710 // scroll page/line down
2712 first_entry += step;
2713 if (first_entry + num_page_entries > max_page_entries)
2714 first_entry = MAX(0, max_page_entries - num_page_entries);
2721 choice += first_entry - first_entry_store[mode];
2723 if (choice < first_entry)
2725 choice = first_entry;
2727 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2730 else if (choice > first_entry + num_page_entries - 1)
2732 choice = first_entry + num_page_entries - 1;
2734 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2737 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2741 if (choice < first_entry ||
2742 choice > first_entry + num_page_entries - 1)
2743 first_entry += SIGN(dy);
2746 first_entry_store[mode] = first_entry;
2747 choice_store[mode] = choice;
2749 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2751 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2753 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2754 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2762 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2764 if (menu_info[choice].type & menu_navigation_type ||
2765 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2766 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2767 menu_info[choice].type & TYPE_PLAYER)
2768 button = MB_MENU_CHOICE;
2773 // jump to next non-empty menu entry (up or down)
2774 while (first_entry + y > 0 &&
2775 first_entry + y < max_page_entries - 1 &&
2776 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2779 if (!IN_VIS_MENU(x, y))
2781 choice += y - y_old;
2783 if (choice < first_entry)
2784 first_entry = choice;
2785 else if (choice > first_entry + num_page_entries - 1)
2786 first_entry = choice - num_page_entries + 1;
2788 if (first_entry >= 0 &&
2789 first_entry + num_page_entries <= max_page_entries)
2791 first_entry_store[mode] = first_entry;
2793 if (choice < first_entry)
2794 choice = first_entry;
2795 else if (choice > first_entry + num_page_entries - 1)
2796 choice = first_entry + num_page_entries - 1;
2798 choice_store[mode] = choice;
2800 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2802 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2804 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2805 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2812 if (!anyScrollbarGadgetActive() &&
2813 IN_VIS_MENU(x, y) &&
2814 mx < mx_right_border &&
2815 y >= 0 && y < num_page_entries)
2819 if (first_entry + y != choice &&
2820 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2822 PlaySound(SND_MENU_ITEM_ACTIVATING);
2824 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2825 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2827 choice = choice_store[mode] = first_entry + y;
2831 PlaySound(SND_MENU_ITEM_SELECTING);
2833 for (i = 0; menu_info[i].type != 0; i++)
2835 if (menu_info[i].type & TYPE_LEAVE_MENU)
2837 void (*menu_callback_function)(void) = menu_info[i].value;
2841 menu_callback_function();
2843 // absolutely needed because function changes 'menu_info'!
2851 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2853 PlaySound(SND_MENU_ITEM_SELECTING);
2855 // when selecting key headline, execute function for key value change
2856 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2857 menu_info[first_entry + y + 1].type & TYPE_KEY)
2860 // when selecting string value, execute function for list selection
2861 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2862 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2865 // when selecting string value, execute function for text input gadget
2866 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2867 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2870 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2872 void (*menu_callback_function)(void) =
2873 menu_info[first_entry + y].value;
2875 FadeSetFromType(menu_info[first_entry + y].type);
2877 menu_callback_function();
2879 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2881 void (*gadget_callback_function)(void) =
2882 menu_info[first_entry + y].value;
2884 gadget_callback_function();
2886 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2887 menu_info == setup_info)
2889 changeSetupValue(y, first_entry + y, dx);
2895 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2897 menu_info = info_info;
2899 HandleMenuScreen(mx, my, dx, dy, button,
2900 info_mode, num_info_info, max_info_info);
2903 static int getMenuFontSpacing(int spacing_height, int font_nr)
2905 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2907 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2911 static int getMenuTextSpacing(int spacing_height, int font_nr)
2913 return (getMenuFontSpacing(spacing_height, font_nr) +
2914 EXTRA_SPACING(game_status));
2917 static int getMenuTextStep(int spacing_height, int font_nr)
2919 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2922 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2924 int font_title = MENU_INFO_FONT_TITLE;
2925 int font_error = FONT_TEXT_2;
2926 int font_foot = MENU_INFO_FONT_FOOT;
2927 int spacing_title = menu.headline1_spacing_info[info_mode];
2928 int ystep_title = getMenuTextStep(spacing_title, font_title);
2929 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2930 int ystart2 = ystart1 + ystep_title;
2931 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2933 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2935 FadeOut(REDRAW_FIELD);
2940 DrawTextSCentered(ystart1, font_title, text_title);
2941 DrawTextSCentered(ystart2, font_error, text_error);
2943 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
2945 FadeIn(REDRAW_FIELD);
2948 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2950 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2951 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2952 int font_title = MENU_INFO_FONT_TITLE;
2953 int font_foot = MENU_INFO_FONT_FOOT;
2954 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2955 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2956 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2957 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2958 int ystep = MENU_SCREEN_INFO_YSTEP;
2959 int element, action, direction;
2967 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2968 infoscreen_step[i] = infoscreen_frame[i] = 0;
2973 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2974 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
2980 while (helpanim_info[j].element != HELPANIM_LIST_END)
2982 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2987 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2996 j += infoscreen_step[i - start];
2998 element = helpanim_info[j].element;
2999 action = helpanim_info[j].action;
3000 direction = helpanim_info[j].direction;
3003 element = EL_UNKNOWN;
3005 if (action != -1 && direction != -1)
3006 graphic = el_act_dir2img(element, action, direction);
3007 else if (action != -1)
3008 graphic = el_act2img(element, action);
3009 else if (direction != -1)
3010 graphic = el_dir2img(element, direction);
3012 graphic = el2img(element);
3014 delay = helpanim_info[j++].delay;
3019 if (infoscreen_frame[i - start] == 0)
3022 infoscreen_frame[i - start] = delay - 1;
3026 sync_frame = delay - infoscreen_frame[i - start];
3027 infoscreen_frame[i - start]--;
3030 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3032 if (!infoscreen_frame[i - start])
3033 infoscreen_step[i - start] = 0;
3037 if (!infoscreen_frame[i - start])
3038 infoscreen_step[i - start]++;
3039 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3045 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
3047 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
3048 graphic, sync_frame, USE_MASKING);
3051 DrawInfoScreen_HelpText(element, action, direction, i - start);
3056 redraw_mask |= REDRAW_FIELD;
3061 static char *getHelpText(int element, int action, int direction)
3063 char token[MAX_LINE_LEN];
3065 strcpy(token, element_info[element].token_name);
3068 strcat(token, element_action_info[action].suffix);
3070 if (direction != -1)
3071 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3073 return getHashEntry(helptext_info, token);
3076 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3078 int font_nr = FONT_INFO_ELEMENTS;
3079 int font_width = getFontWidth(font_nr);
3080 int font_height = getFontHeight(font_nr);
3081 int yoffset = (TILEX - 2 * font_height) / 2;
3082 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3083 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
3084 int ystep = TILEY + 4;
3085 int pad_left = xstart - SX;
3086 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3087 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3088 int max_lines_per_text = 2;
3091 if (action != -1 && direction != -1) // element.action.direction
3092 text = getHelpText(element, action, direction);
3094 if (text == NULL && action != -1) // element.action
3095 text = getHelpText(element, action, -1);
3097 if (text == NULL && direction != -1) // element.direction
3098 text = getHelpText(element, -1, direction);
3100 if (text == NULL) // base element
3101 text = getHelpText(element, -1, -1);
3103 if (text == NULL) // not found
3104 text = "No description available";
3106 if (strlen(text) <= max_chars_per_line) // only one line of text
3107 ystart += getFontHeight(font_nr) / 2;
3109 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3110 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3111 TRUE, FALSE, FALSE);
3114 static void DrawInfoScreen_TitleScreen(void)
3116 SetGameStatus(GAME_MODE_TITLE);
3121 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3123 HandleTitleScreen(0, 0, dx, dy, button);
3126 static void DrawInfoScreen_Elements(void)
3128 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3130 FadeOut(REDRAW_FIELD);
3135 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3137 FadeIn(REDRAW_FIELD);
3140 void HandleInfoScreen_Elements(int dx, int dy, int button)
3142 static unsigned int info_delay = 0;
3143 static int num_anims;
3144 static int num_pages;
3146 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3149 if (button == MB_MENU_INITIALIZE)
3151 boolean new_element = TRUE;
3155 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3157 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3159 else if (new_element)
3162 new_element = FALSE;
3166 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3170 if (button == MB_MENU_LEAVE)
3172 PlaySound(SND_MENU_ITEM_SELECTING);
3174 info_mode = INFO_MODE_MAIN;
3179 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3181 if (button != MB_MENU_INITIALIZE)
3183 PlaySound(SND_MENU_ITEM_SELECTING);
3185 page += (dx < 0 ? -1 : +1);
3188 if (page < 0 || page >= num_pages)
3190 FadeMenuSoundsAndMusic();
3192 info_mode = INFO_MODE_MAIN;
3198 if (button != MB_MENU_INITIALIZE)
3199 FadeSetNextScreen();
3201 if (button != MB_MENU_INITIALIZE)
3202 FadeOut(REDRAW_FIELD);
3204 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3206 if (button != MB_MENU_INITIALIZE)
3207 FadeIn(REDRAW_FIELD);
3211 if (DelayReached(&info_delay, GameFrameDelay))
3212 if (page < num_pages)
3213 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3215 PlayMenuSoundIfLoop();
3219 static void DrawInfoScreen_Music(void)
3221 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3223 FadeOut(REDRAW_FIELD);
3230 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3232 FadeIn(REDRAW_FIELD);
3235 void HandleInfoScreen_Music(int dx, int dy, int button)
3237 static struct MusicFileInfo *list = NULL;
3238 int font_title = MENU_INFO_FONT_TITLE;
3239 int font_head = MENU_INFO_FONT_HEAD;
3240 int font_text = MENU_INFO_FONT_TEXT;
3241 int font_foot = MENU_INFO_FONT_FOOT;
3242 int spacing_title = menu.headline1_spacing_info[info_mode];
3243 int spacing_head = menu.headline2_spacing_info[info_mode];
3244 int ystep_title = getMenuTextStep(spacing_title, font_title);
3245 int ystep_head = getMenuTextStep(spacing_head, font_head);
3246 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3247 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3249 if (button == MB_MENU_INITIALIZE)
3251 list = music_file_info;
3255 FadeMenuSoundsAndMusic();
3260 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3261 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3267 if (button == MB_MENU_LEAVE)
3269 PlaySound(SND_MENU_ITEM_SELECTING);
3271 FadeMenuSoundsAndMusic();
3273 info_mode = INFO_MODE_MAIN;
3278 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3280 if (button != MB_MENU_INITIALIZE)
3282 PlaySound(SND_MENU_ITEM_SELECTING);
3285 list = (dx < 0 ? list->prev : list->next);
3290 FadeMenuSoundsAndMusic();
3292 info_mode = INFO_MODE_MAIN;
3298 FadeMenuSoundsAndMusic();
3300 if (list != music_file_info)
3301 FadeSetNextScreen();
3303 if (button != MB_MENU_INITIALIZE)
3304 FadeOut(REDRAW_FIELD);
3311 int sound = list->music;
3313 if (IS_LOOP_SOUND(sound))
3314 PlaySoundLoop(sound);
3318 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3322 int music = list->music;
3324 if (IS_LOOP_MUSIC(music))
3325 PlayMusicLoop(music);
3329 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3332 ystart += ystep_title;
3334 if (!strEqual(list->title, UNKNOWN_NAME))
3336 if (!strEqual(list->title_header, UNKNOWN_NAME))
3338 DrawTextSCentered(ystart, font_head, list->title_header);
3339 ystart += ystep_head;
3342 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3343 ystart += ystep_head;
3346 if (!strEqual(list->artist, UNKNOWN_NAME))
3348 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3349 DrawTextSCentered(ystart, font_head, list->artist_header);
3351 DrawTextSCentered(ystart, font_head, "by");
3353 ystart += ystep_head;
3355 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3356 ystart += ystep_head;
3359 if (!strEqual(list->album, UNKNOWN_NAME))
3361 if (!strEqual(list->album_header, UNKNOWN_NAME))
3362 DrawTextSCentered(ystart, font_head, list->album_header);
3364 DrawTextSCentered(ystart, font_head, "from the album");
3366 ystart += ystep_head;
3368 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3369 ystart += ystep_head;
3372 if (!strEqual(list->year, UNKNOWN_NAME))
3374 if (!strEqual(list->year_header, UNKNOWN_NAME))
3375 DrawTextSCentered(ystart, font_head, list->year_header);
3377 DrawTextSCentered(ystart, font_head, "from the year");
3379 ystart += ystep_head;
3381 DrawTextFCentered(ystart, font_text, "%s", list->year);
3382 ystart += ystep_head;
3385 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3387 if (button != MB_MENU_INITIALIZE)
3388 FadeIn(REDRAW_FIELD);
3391 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3392 PlaySoundLoop(list->music);
3395 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3397 int font_title = MENU_INFO_FONT_TITLE;
3398 int font_text = MENU_INFO_FONT_TEXT;
3399 int font_foot = MENU_INFO_FONT_FOOT;
3400 int spacing_title = menu.headline1_spacing_info[info_mode];
3401 int spacing_line = menu.line_spacing_info[info_mode];
3402 int ystep_title = getMenuTextStep(spacing_title, font_title);
3403 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3404 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3409 DrawTextSCentered(ystart, font_title, "Credits:");
3411 char *filename = getCreditsFilename(screen_nr, use_global_credits_screens);
3413 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3414 int chars = width / getFontWidth(font_text);
3415 int lines = height / getFontHeight(font_text);
3416 int padx = (width - chars * getFontWidth(font_text)) / 2;
3417 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3418 boolean autowrap = FALSE;
3419 boolean centered = TRUE;
3420 boolean parse_comments = TRUE;
3422 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3423 filename, font_text, chars, -1, lines, line_spacing, -1,
3424 autowrap, centered, parse_comments);
3426 boolean last_screen = (screen_nr == num_credits_screens - 1);
3427 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3429 DrawTextSCentered(ybottom, font_foot, text_foot);
3432 static void DrawInfoScreen_Credits(void)
3434 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3436 FadeMenuSoundsAndMusic();
3438 FadeOut(REDRAW_FIELD);
3440 HandleInfoScreen_Credits(0, 0, MB_MENU_INITIALIZE);
3442 FadeIn(REDRAW_FIELD);
3445 void HandleInfoScreen_Credits(int dx, int dy, int button)
3447 static int screen_nr = 0;
3449 if (button == MB_MENU_INITIALIZE)
3453 // determine number of (global or level set specific) credits screens
3454 for (i = 0; i < 2; i++)
3456 num_credits_screens = 0;
3457 use_global_credits_screens = i;
3459 while (getCreditsFilename(num_credits_screens,
3460 use_global_credits_screens) != NULL)
3461 num_credits_screens++;
3463 if (num_credits_screens > 0)
3467 if (num_credits_screens == 0)
3469 int font_title = MENU_INFO_FONT_TITLE;
3470 int font_foot = MENU_INFO_FONT_FOOT;
3471 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3472 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3477 DrawTextSCentered(ystart, font_title, "No credits for this level set.");
3478 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3485 DrawInfoScreen_CreditsScreen(screen_nr);
3487 else if (button == MB_MENU_LEAVE)
3489 PlaySound(SND_MENU_ITEM_SELECTING);
3491 info_mode = INFO_MODE_MAIN;
3496 else if (button == MB_MENU_CHOICE || dx)
3498 PlaySound(SND_MENU_ITEM_SELECTING);
3500 screen_nr += (dx < 0 ? -1 : +1);
3502 if (screen_nr < 0 || screen_nr >= num_credits_screens)
3504 FadeMenuSoundsAndMusic();
3506 info_mode = INFO_MODE_MAIN;
3512 FadeSetNextScreen();
3514 FadeOut(REDRAW_FIELD);
3516 DrawInfoScreen_CreditsScreen(screen_nr);
3518 FadeIn(REDRAW_FIELD);
3522 PlayMenuSoundIfLoop();
3526 static void DrawInfoScreen_ProgramScreen(int screen_nr)
3528 int font_title = MENU_INFO_FONT_TITLE;
3529 int font_text = MENU_INFO_FONT_TEXT;
3530 int font_foot = MENU_INFO_FONT_FOOT;
3531 int spacing_title = menu.headline1_spacing_info[info_mode];
3532 int spacing_line = menu.line_spacing_info[info_mode];
3533 int ystep_title = getMenuTextStep(spacing_title, font_title);
3534 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3535 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3540 DrawTextSCentered(ystart, font_title, "Program Information:");
3542 char *filename = getProgramInfoFilename(screen_nr);
3544 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART1;
3545 int chars = width / getFontWidth(font_text);
3546 int lines = height / getFontHeight(font_text);
3547 int padx = (width - chars * getFontWidth(font_text)) / 2;
3548 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3549 boolean autowrap = FALSE;
3550 boolean centered = TRUE;
3551 boolean parse_comments = TRUE;
3553 DrawTextFile(mSX + padx, mSY + MENU_SCREEN_INFO_YSTART1 + ystep_title,
3554 filename, font_text, chars, -1, lines, line_spacing, -1,
3555 autowrap, centered, parse_comments);
3557 boolean last_screen = (screen_nr == num_program_info_screens - 1);
3558 char *text_foot = (last_screen ? TEXT_INFO_MENU : TEXT_NEXT_PAGE);
3560 DrawTextSCentered(ybottom, font_foot, text_foot);
3563 static void DrawInfoScreen_Program(void)
3565 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3567 FadeMenuSoundsAndMusic();
3569 FadeOut(REDRAW_FIELD);
3571 HandleInfoScreen_Program(0, 0, MB_MENU_INITIALIZE);
3573 FadeIn(REDRAW_FIELD);
3576 void HandleInfoScreen_Program(int dx, int dy, int button)
3578 static int screen_nr = 0;
3580 if (button == MB_MENU_INITIALIZE)
3582 // determine number of program info screens
3583 num_program_info_screens = 0;
3585 while (getProgramInfoFilename(num_program_info_screens) != NULL)
3586 num_program_info_screens++;
3588 if (num_program_info_screens == 0)
3590 int font_title = MENU_INFO_FONT_TITLE;
3591 int font_foot = MENU_INFO_FONT_FOOT;
3592 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3593 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3598 DrawTextSCentered(ystart, font_title, "No program info available.");
3599 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3606 DrawInfoScreen_ProgramScreen(screen_nr);
3608 else if (button == MB_MENU_LEAVE)
3610 PlaySound(SND_MENU_ITEM_SELECTING);
3612 info_mode = INFO_MODE_MAIN;
3617 else if (button == MB_MENU_CHOICE || dx)
3619 PlaySound(SND_MENU_ITEM_SELECTING);
3621 screen_nr += (dx < 0 ? -1 : +1);
3623 if (screen_nr < 0 || screen_nr >= num_program_info_screens)
3625 FadeMenuSoundsAndMusic();
3627 info_mode = INFO_MODE_MAIN;
3633 FadeSetNextScreen();
3635 FadeOut(REDRAW_FIELD);
3637 DrawInfoScreen_ProgramScreen(screen_nr);
3639 FadeIn(REDRAW_FIELD);
3643 PlayMenuSoundIfLoop();
3647 static void DrawInfoScreen_Version(void)
3649 int font_title = MENU_INFO_FONT_TITLE;
3650 int font_head = MENU_INFO_FONT_HEAD;
3651 int font_text = MENU_INFO_FONT_TEXT;
3652 int font_foot = MENU_INFO_FONT_FOOT;
3653 int spacing_title = menu.headline1_spacing_info[info_mode];
3654 int spacing_head = menu.headline2_spacing_info[info_mode];
3655 int spacing_para = menu.paragraph_spacing_info[info_mode];
3656 int spacing_line = menu.line_spacing_info[info_mode];
3657 int xstep = getFontWidth(font_text);
3658 int ystep_title = getMenuTextStep(spacing_title, font_title);
3659 int ystep_head = getMenuTextStep(spacing_head, font_head);
3660 int ystep_para = getMenuTextStep(spacing_para, font_text);
3661 int ystep_line = getMenuTextStep(spacing_line, font_text);
3662 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3663 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3664 int xstart1 = mSX - SX + 2 * xstep;
3665 int xstart2 = mSX - SX + 18 * xstep;
3666 int xstart3 = mSX - SX + 28 * xstep;
3667 SDL_version sdl_version_compiled;
3668 const SDL_version *sdl_version_linked;
3669 int driver_name_len = 10;
3670 SDL_version sdl_version_linked_ext;
3671 const char *driver_name = NULL;
3673 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3675 FadeOut(REDRAW_FIELD);
3680 DrawTextSCentered(ystart, font_title, "Version Information:");
3681 ystart += ystep_title;
3683 DrawTextF(xstart1, ystart, font_head, "Name");
3684 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3685 ystart += ystep_line;
3687 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3689 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3690 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3691 ystart += ystep_line;
3693 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3694 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3695 ystart += ystep_line;
3699 DrawTextF(xstart1, ystart, font_head, "Version");
3700 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3701 ystart += ystep_line;
3704 DrawTextF(xstart1, ystart, font_head, "Platform");
3705 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3707 PLATFORM_XX_BIT_STRING);
3708 ystart += ystep_line;
3710 DrawTextF(xstart1, ystart, font_head, "Target");
3711 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3712 ystart += ystep_line;
3714 DrawTextF(xstart1, ystart, font_head, "Source date");
3715 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3716 ystart += ystep_line;
3718 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3719 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3720 ystart += ystep_para;
3722 DrawTextF(xstart1, ystart, font_head, "Library");
3723 DrawTextF(xstart2, ystart, font_head, "compiled");
3724 DrawTextF(xstart3, ystart, font_head, "linked");
3725 ystart += ystep_head;
3727 SDL_VERSION(&sdl_version_compiled);
3728 SDL_GetVersion(&sdl_version_linked_ext);
3729 sdl_version_linked = &sdl_version_linked_ext;
3731 DrawTextF(xstart1, ystart, font_text, "SDL");
3732 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3733 sdl_version_compiled.major,
3734 sdl_version_compiled.minor,
3735 sdl_version_compiled.patch);
3736 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3737 sdl_version_linked->major,
3738 sdl_version_linked->minor,
3739 sdl_version_linked->patch);
3740 ystart += ystep_line;
3742 SDL_IMAGE_VERSION(&sdl_version_compiled);
3743 sdl_version_linked = IMG_Linked_Version();
3745 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3746 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3747 sdl_version_compiled.major,
3748 sdl_version_compiled.minor,
3749 sdl_version_compiled.patch);
3750 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3751 sdl_version_linked->major,
3752 sdl_version_linked->minor,
3753 sdl_version_linked->patch);
3754 ystart += ystep_line;
3756 SDL_MIXER_VERSION(&sdl_version_compiled);
3757 sdl_version_linked = Mix_Linked_Version();
3759 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3760 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3761 sdl_version_compiled.major,
3762 sdl_version_compiled.minor,
3763 sdl_version_compiled.patch);
3764 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3765 sdl_version_linked->major,
3766 sdl_version_linked->minor,
3767 sdl_version_linked->patch);
3768 ystart += ystep_line;
3770 SDL_NET_VERSION(&sdl_version_compiled);
3771 sdl_version_linked = SDLNet_Linked_Version();
3773 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3774 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3775 sdl_version_compiled.major,
3776 sdl_version_compiled.minor,
3777 sdl_version_compiled.patch);
3778 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3779 sdl_version_linked->major,
3780 sdl_version_linked->minor,
3781 sdl_version_linked->patch);
3782 ystart += ystep_para;
3784 DrawTextF(xstart1, ystart, font_head, "Driver");
3785 DrawTextF(xstart2, ystart, font_head, "Requested");
3786 DrawTextF(xstart3, ystart, font_head, "Used");
3787 ystart += ystep_head;
3790 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3792 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3793 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3794 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3795 ystart += ystep_line;
3798 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3800 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3801 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3802 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3803 ystart += ystep_line;
3806 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3808 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3809 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3810 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3812 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3814 FadeIn(REDRAW_FIELD);
3817 void HandleInfoScreen_Version(int button)
3819 if (button == MB_MENU_LEAVE)
3821 PlaySound(SND_MENU_ITEM_SELECTING);
3823 info_mode = INFO_MODE_MAIN;
3828 else if (button == MB_MENU_CHOICE)
3830 PlaySound(SND_MENU_ITEM_SELECTING);
3832 FadeMenuSoundsAndMusic();
3834 info_mode = INFO_MODE_MAIN;
3839 PlayMenuSoundIfLoop();
3843 static void DrawInfoScreen_LevelSet(void)
3845 struct TitleMessageInfo *tmi = &readme;
3846 char *filename = getLevelSetInfoFilename();
3847 char *title = "Level Set Information:";
3848 int font_foot = MENU_INFO_FONT_FOOT;
3849 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3850 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3852 if (filename == NULL)
3854 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3859 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3861 FadeOut(REDRAW_FIELD);
3866 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3868 // if x position set to "-1", automatically determine by playfield width
3870 tmi->x = SXSIZE / 2;
3872 // if y position set to "-1", use static default value
3876 // if width set to "-1", automatically determine by playfield width
3877 if (tmi->width == -1)
3878 tmi->width = SXSIZE - 2 * TILEX;
3880 // if height set to "-1", automatically determine by playfield height
3881 if (tmi->height == -1)
3882 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3884 // if chars set to "-1", automatically determine by text and font width
3885 if (tmi->chars == -1)
3886 tmi->chars = tmi->width / getFontWidth(tmi->font);
3888 tmi->width = tmi->chars * getFontWidth(tmi->font);
3890 // if lines set to "-1", automatically determine by text and font height
3891 if (tmi->lines == -1)
3892 tmi->lines = tmi->height / getFontHeight(tmi->font);
3894 tmi->height = tmi->lines * getFontHeight(tmi->font);
3896 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3897 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3898 tmi->autowrap, tmi->centered, tmi->parse_comments);
3900 DrawTextSCentered(ybottom, font_foot, TEXT_INFO_MENU);
3902 FadeIn(REDRAW_FIELD);
3905 static void HandleInfoScreen_LevelSet(int button)
3907 if (button == MB_MENU_LEAVE)
3909 PlaySound(SND_MENU_ITEM_SELECTING);
3911 info_mode = INFO_MODE_MAIN;
3916 else if (button == MB_MENU_CHOICE)
3918 PlaySound(SND_MENU_ITEM_SELECTING);
3920 FadeMenuSoundsAndMusic();
3922 info_mode = INFO_MODE_MAIN;
3927 PlayMenuSoundIfLoop();
3931 static void DrawInfoScreen(void)
3933 if (info_mode == INFO_MODE_TITLE)
3934 DrawInfoScreen_TitleScreen();
3935 else if (info_mode == INFO_MODE_ELEMENTS)
3936 DrawInfoScreen_Elements();
3937 else if (info_mode == INFO_MODE_MUSIC)
3938 DrawInfoScreen_Music();
3939 else if (info_mode == INFO_MODE_CREDITS)
3940 DrawInfoScreen_Credits();
3941 else if (info_mode == INFO_MODE_PROGRAM)
3942 DrawInfoScreen_Program();
3943 else if (info_mode == INFO_MODE_VERSION)
3944 DrawInfoScreen_Version();
3945 else if (info_mode == INFO_MODE_LEVELSET)
3946 DrawInfoScreen_LevelSet();
3948 DrawInfoScreen_Main();
3950 if (info_mode != INFO_MODE_MAIN &&
3951 info_mode != INFO_MODE_TITLE &&
3952 info_mode != INFO_MODE_MUSIC)
3953 PlayMenuSoundsAndMusic();
3956 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3958 if (info_mode == INFO_MODE_TITLE)
3959 HandleInfoScreen_TitleScreen(dx, dy, button);
3960 else if (info_mode == INFO_MODE_ELEMENTS)
3961 HandleInfoScreen_Elements(dx, dy, button);
3962 else if (info_mode == INFO_MODE_MUSIC)
3963 HandleInfoScreen_Music(dx, dy, button);
3964 else if (info_mode == INFO_MODE_CREDITS)
3965 HandleInfoScreen_Credits(dx, dy, button);
3966 else if (info_mode == INFO_MODE_PROGRAM)
3967 HandleInfoScreen_Program(dx, dy, button);
3968 else if (info_mode == INFO_MODE_VERSION)
3969 HandleInfoScreen_Version(button);
3970 else if (info_mode == INFO_MODE_LEVELSET)
3971 HandleInfoScreen_LevelSet(button);
3973 HandleInfoScreen_Main(mx, my, dx, dy, button);
3977 // ============================================================================
3978 // type name functions
3979 // ============================================================================
3981 static TreeInfo *type_name_node = NULL;
3982 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
3983 static int type_name_nr = 0;
3985 static int getPlayerNameColor(char *name)
3987 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
3990 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
3993 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
3994 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
3995 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
3996 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
3997 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
3998 int font_width = getFontWidth(font_nr);
4000 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4002 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4004 pos->width = strlen(text) * font_width;
4005 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4007 DrawText(sx, sy, text, font_nr);
4010 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4012 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4014 *pos = *mci->pos_input;
4016 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4018 TreeInfo *ti = player_name_current;
4019 int first_entry = ti->cl_first;
4020 int entry_pos = first_entry + ti->cl_cursor;
4021 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4022 int xpos = MENU_SCREEN_START_XPOS;
4023 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4025 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4026 type_name_nr = entry_pos;
4028 strcpy(name, type_name_node->name);
4032 pos->width = MAX_PLAYER_NAME_LEN * 32;
4036 type_name_nr = user.nr;
4038 strcpy(name, setup.player_name);
4041 strcpy(type_name_last, name);
4043 if (strEqual(name, EMPTY_PLAYER_NAME))
4046 *xpos = strlen(name);
4049 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4051 // change name of edited user in global list of user names
4052 setString(&global.user_names[type_name_nr], name);
4054 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4056 TreeInfo *node = type_name_node;
4058 // change name of edited user in local menu tree structure
4059 setString(&node->name, name);
4060 setString(&node->name_sorting, name);
4062 node->color = getPlayerNameColor(name);
4063 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4067 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4070 boolean reset_setup = strEqual(name, "");
4071 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4072 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4075 strcpy(name, type_name_last);
4077 if (strEqual(name, ""))
4078 strcpy(name, EMPTY_PLAYER_NAME);
4080 setTypeNameValues_Name(name, pos);
4082 // if player name not changed, no further action required
4083 if (strEqual(name, type_name_last))
4086 // redraw player name before (possibly) opening request dialogs
4087 drawTypeNameText(name, pos, FALSE);
4089 int last_user_nr = user.nr;
4091 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4093 // save setup of currently active user (may differ from edited user)
4096 // temporarily change active user to edited user
4097 user.nr = type_name_nr;
4100 Request("Use current setup values for the new player?", REQ_ASK))
4102 // use current setup values for new user, but create new player UUID
4103 setup.player_uuid = getStringCopy(getUUID());
4107 // load setup for existing user (or start with defaults for new user)
4112 char *setup_filename = getSetupFilename();
4113 boolean setup_exists = fileExists(setup_filename);
4115 // change name of edited user in setup structure
4116 strcpy(setup.player_name, name);
4118 // save setup of edited user
4121 // change name of edited user on score server
4122 ApiRenamePlayerAsThread();
4124 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4128 if (Request("Reset setup values for this player?", REQ_ASK))
4130 // remove setup config file
4131 unlink(setup_filename);
4133 // set player name to default player name
4136 // update player name used by name typing functions
4137 strcpy(name, setup.player_name);
4139 setTypeNameValues_Name(name, pos);
4142 else if (remove_user && type_name_nr != 0)
4144 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4146 char *user_dir = getUserGameDataDir();
4147 char *user_dir_removed =
4148 getStringCat3WithSeparator(user_dir, "REMOVED",
4149 getCurrentTimestamp(), ".");
4151 if (rename(user_dir, user_dir_removed) != 0)
4152 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4154 checked_free(user_dir_removed);
4157 else if (create_user && type_name_nr != 0 && !setup_exists)
4159 if (Request("Create empty level set for the new player?", REQ_ASK))
4161 char *levelset_subdir = getNewUserLevelSubdir();
4163 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4165 AddUserLevelSetToLevelInfo(levelset_subdir);
4167 LevelDirTree *leveldir_current_last = leveldir_current;
4169 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4172 // set level number of newly created level set to default value
4173 LoadLevelSetup_SeriesInfo();
4175 // set newly created level set as current level set for new user
4176 SaveLevelSetup_LastSeries();
4177 SaveLevelSetup_SeriesInfo();
4179 leveldir_current = leveldir_current_last;
4183 Request("Creating new level set failed!", REQ_CONFIRM);
4188 // restore currently active user
4189 user.nr = last_user_nr;
4191 // restore setup of currently active user
4194 // restore last level set of currently active user
4195 LoadLevelSetup_LastSeries();
4196 LoadLevelSetup_SeriesInfo();
4200 static void HandleTypeNameExt(boolean initialize, Key key)
4202 static struct TextPosInfo pos_name = { 0 };
4203 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4204 static int xpos = 0;
4205 struct TextPosInfo *pos = &pos_name;
4206 char key_char = getValidConfigValueChar(getCharFromKey(key));
4207 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4208 boolean active = TRUE;
4212 getTypeNameValues(name, pos, &xpos);
4214 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4215 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4217 StartTextInput(sx, sy, pos->width, pos->height);
4219 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4221 name[xpos] = key_char;
4226 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4232 else if (key == KSYM_Return || key == KSYM_Escape)
4234 boolean changed = (key == KSYM_Return);
4238 setTypeNameValues(name, pos, changed);
4243 drawTypeNameText(name, pos, active);
4247 SetGameStatus(game_status_last_screen);
4249 if (game_status == GAME_MODE_MAIN)
4250 InitializeMainControls();
4254 static void DrawTypeName(void)
4256 HandleTypeNameExt(TRUE, 0);
4259 void HandleTypeName(Key key)
4261 HandleTypeNameExt(FALSE, key);
4265 // ============================================================================
4266 // tree menu functions
4267 // ============================================================================
4269 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4271 if (game_status != GAME_MODE_SETUP ||
4272 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4275 int max_text_size = 0;
4278 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4279 max_text_size = MAX(max_text_size, strlen(node->name));
4281 int num_entries = numTreeInfoInGroup(ti);
4282 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4283 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4284 int text_width = max_text_size * getFontWidth(font_nr);
4285 int button_width = SC_MENUBUTTON_XSIZE;
4286 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4287 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4288 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4289 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4290 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4291 int align_xoffset = MAX(0, align_xoffset_raw);
4293 return align_xoffset;
4296 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4298 if (game_status != GAME_MODE_SETUP ||
4299 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4302 int num_entries = numTreeInfoInGroup(ti);
4303 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4304 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4305 int font_height = getFontHeight(font_nr);
4306 int text_height = font_height * num_page_entries;
4307 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4308 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4309 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4310 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4311 int align_yoffset = MAX(0, align_yoffset_raw);
4313 return align_yoffset;
4316 static void DrawChooseTree(TreeInfo **ti_ptr)
4318 int fade_mask = REDRAW_FIELD;
4319 boolean restart_music = (game_status != game_status_last_screen &&
4320 game_status_last_screen != GAME_MODE_SCOREINFO);
4323 fade_mask = REDRAW_ALL;
4325 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4327 if (game_status == GAME_MODE_SETUP)
4331 else // GAME_MODE_LEVELS
4333 SetGameStatus(GAME_MODE_MAIN);
4343 FreeScreenGadgets();
4344 CreateScreenGadgets();
4347 FadeMenuSoundsAndMusic();
4351 // needed if different viewport properties defined for this screen
4352 ChangeViewportPropertiesIfNeeded();
4354 if (game_status == GAME_MODE_NAMES)
4355 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4356 else if (game_status == GAME_MODE_LEVELNR)
4357 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4358 else if (game_status == GAME_MODE_LEVELS)
4359 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4360 else if (game_status == GAME_MODE_SCORES)
4361 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4365 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4367 // map gadgets for high score screen
4368 if (game_status == GAME_MODE_SCORES)
4369 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4371 MapScreenTreeGadgets(*ti_ptr);
4373 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4375 DrawMaskedBorder(fade_mask);
4378 PlayMenuSoundsAndMusic();
4383 static int getChooseTreeFont(TreeInfo *node, boolean active)
4385 if (game_status == GAME_MODE_SCORES)
4386 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4388 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4391 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4393 int num_entries = numTreeInfoInGroup(ti);
4394 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4395 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4396 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4397 int first_entry = ti->cl_first;
4398 int entry_pos = first_entry + y;
4399 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4400 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4401 int font_nr = getChooseTreeFont(node, active);
4402 int font_xoffset = getFontDrawOffsetX(font_nr);
4403 int xpos = MENU_SCREEN_START_XPOS;
4404 int ypos = MENU_SCREEN_START_YPOS + y;
4405 int startdx = xpos * 32;
4406 int startdy = ypos * 32;
4407 int startx = amSX + startdx;
4408 int starty = amSY + startdy;
4409 int startx_text = startx + font_xoffset;
4410 int endx_text = amSX + screen_width;
4411 int max_text_size = endx_text - startx_text;
4412 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4413 char buffer[max_buffer_len + 1];
4415 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4417 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4418 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4419 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4420 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4421 int font_size_1 = getFontWidth(font_nr1);
4422 int font_size_3 = getFontWidth(font_nr3);
4423 int font_size_4 = getFontWidth(font_nr4);
4424 int text_size_1 = 4 * font_size_1;
4425 int text_size_4 = 5 * font_size_4;
4426 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4428 int dx3 = text_size_1;
4429 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4430 int num_dots = (dx4 - dx3) / font_size_3;
4431 int startx1 = startx + dx1;
4432 int startx3 = startx + dx3;
4433 int startx4 = startx + dx4;
4434 int pos = node->pos;
4435 char *pos_text = getHallOfFameRankText(pos, 3);
4438 DrawText(startx1, starty, pos_text, font_nr1);
4440 for (i = 0; i < num_dots; i++)
4441 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4443 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4444 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4446 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4450 strncpy(buffer, node->name, max_buffer_len);
4451 buffer[max_buffer_len] = '\0';
4453 DrawText(startx, starty, buffer, font_nr);
4457 static void drawChooseTreeHeadExt(int type, char *title_string)
4459 int yoffset_sets = MENU_TITLE1_YPOS;
4460 int yoffset_setup = 16;
4461 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4462 type == TREE_TYPE_LEVEL_DIR ||
4463 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4465 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4468 static void drawChooseTreeHead(TreeInfo *ti)
4470 drawChooseTreeHeadExt(ti->type, ti->infotext);
4473 static void drawChooseTreeList(TreeInfo *ti)
4475 int first_entry = ti->cl_first;
4476 int num_entries = numTreeInfoInGroup(ti);
4477 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4480 clearMenuListArea();
4482 for (i = 0; i < num_page_entries; i++)
4484 TreeInfo *node, *node_first;
4485 int entry_pos = first_entry + i;
4487 node_first = getTreeInfoFirstGroupEntry(ti);
4488 node = getTreeInfoFromPos(node_first, entry_pos);
4490 drawChooseTreeText(ti, i, FALSE);
4492 if (node->parent_link)
4493 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4494 else if (node->level_group)
4495 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4497 initCursor(i, IMG_MENU_BUTTON);
4499 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4500 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4502 if (game_status == GAME_MODE_NAMES)
4503 drawChooseTreeEdit(i, FALSE);
4506 redraw_mask |= REDRAW_FIELD;
4509 static void drawChooseTreeInfo(TreeInfo *ti)
4511 int entry_pos = ti->cl_first + ti->cl_cursor;
4512 int last_redraw_mask = redraw_mask;
4513 int ypos = MENU_TITLE2_YPOS;
4514 int font_nr = FONT_TITLE_2;
4517 if (ti->type == TREE_TYPE_LEVEL_NR)
4518 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4520 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4521 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4522 scores.last_level_nr);
4524 if (ti->type != TREE_TYPE_LEVEL_DIR)
4527 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4528 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4530 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4532 if (node->parent_link)
4533 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4534 node->node_parent->name);
4535 else if (node->level_group)
4536 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4538 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4539 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4540 node->levels, (node->levels > 1 ? "levels" : "level"),
4543 // let BackToFront() redraw only what is needed
4544 redraw_mask = last_redraw_mask;
4545 for (x = 0; x < SCR_FIELDX; x++)
4546 MarkTileDirty(x, 1);
4549 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4551 drawChooseTreeCursor(ti->cl_cursor, active);
4552 drawChooseTreeText(ti, ti->cl_cursor, active);
4555 static void drawChooseTreeScreen(TreeInfo *ti)
4557 drawChooseTreeHead(ti);
4558 drawChooseTreeList(ti);
4559 drawChooseTreeInfo(ti);
4560 drawChooseTreeCursorAndText(ti, TRUE);
4562 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4564 // scroll bar and buttons may just have been added after reloading scores
4565 if (game_status == GAME_MODE_SCORES)
4566 MapScreenTreeGadgets(ti);
4569 static void drawChooseTreeScreen_Scores_NotAvailable(void)
4571 // dirty workaround to use spacing definitions from info screen
4572 info_mode = INFO_MODE_TITLE;
4574 char *text_info = "HighScores of Level %d";
4575 char *text_title = "Score information:";
4576 char *text_error = "No scores for this level.";
4577 char *text_foot = "Press any key or button for main menu";
4578 int font_info = FONT_TITLE_2;
4579 int font_title = FONT_INITIAL_3;
4580 int font_error = FONT_INITIAL_4;
4581 int font_foot = FONT_INITIAL_2;
4582 int spacing_title = menu.headline1_spacing_info[INFO_MODE_TITLE];
4583 int ystep_title = getMenuTextStep(spacing_title, font_title);
4584 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
4585 int ystart2 = ystart1 + ystep_title;
4586 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4587 int ystart0 = MENU_TITLE2_YPOS;
4589 drawChooseTreeHeadExt(TREE_TYPE_SCORE_ENTRY, INFOTEXT_SCORE_ENTRY);
4590 DrawTextFCentered(ystart0, font_info, text_info, scores.last_level_nr);
4592 DrawTextSCentered(ystart1, font_title, text_title);
4593 DrawTextSCentered(ystart2, font_error, text_error);
4595 DrawTextSCentered(ybottom, font_foot, text_foot);
4598 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4600 int score_pos = scores.last_added;
4602 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4603 score_pos = scores.last_entry_nr;
4605 // set current tree entry to last added score entry
4606 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4608 // if that fails, set current tree entry to first entry (back link)
4609 if (*ti_ptr == NULL)
4610 *ti_ptr = score_entries->node_group;
4612 int num_entries = numTreeInfoInGroup(*ti_ptr);
4613 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4614 int pos_score = getPosFromTreeInfo(*ti_ptr);
4615 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4616 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4618 (*ti_ptr)->cl_first = pos_first;
4619 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4624 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4627 TreeInfo *ti = *ti_ptr;
4628 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4629 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4630 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4631 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4632 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4634 int y = (ti != NULL ? ti->cl_cursor : 0);
4635 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4636 int num_entries = numTreeInfoInGroup(ti);
4637 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4638 boolean position_set_by_scrollbar = (dx == 999);
4639 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
4640 boolean button_is_valid = (mx >= 0 && my >= 0);
4641 boolean button_screen_clicked = (button_action && button_is_valid);
4643 if (game_status == GAME_MODE_SCORES)
4645 if (server_scores.updated)
4647 // reload scores, using updated server score cache file
4648 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4650 server_scores.updated = FALSE;
4652 DrawHallOfFame_setScoreEntries();
4654 if (score_entries != NULL)
4656 ti = setHallOfFameActiveEntry(ti_ptr);
4658 if (button != MB_MENU_INITIALIZE)
4659 drawChooseTreeScreen(ti);
4663 if (score_entries == NULL)
4665 if (button == MB_MENU_INITIALIZE)
4667 drawChooseTreeScreen_Scores_NotAvailable();
4669 else if (button_screen_clicked)
4671 PlaySound(SND_MENU_ITEM_SELECTING);
4673 SetGameStatus(GAME_MODE_MAIN);
4682 if (button == MB_MENU_INITIALIZE)
4684 int num_entries = numTreeInfoInGroup(ti);
4685 int entry_pos = getPosFromTreeInfo(ti);
4687 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4688 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4690 if (game_status == GAME_MODE_SCORES)
4692 ti = setHallOfFameActiveEntry(ti_ptr);
4694 else if (ti->cl_first == -1)
4696 // only on initialization
4697 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4698 ti->cl_cursor = entry_pos - ti->cl_first;
4701 else if (ti->cl_cursor >= num_page_entries ||
4702 (num_entries > num_page_entries &&
4703 num_entries - ti->cl_first < num_page_entries))
4705 // only after change of list size (by custom graphic configuration)
4706 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4707 ti->cl_cursor = entry_pos - ti->cl_first;
4710 if (position_set_by_scrollbar)
4713 drawChooseTreeScreen(ti);
4717 else if (button == MB_MENU_LEAVE)
4719 if (game_status != GAME_MODE_SCORES)
4722 PlaySound(SND_MENU_ITEM_SELECTING);
4724 if (ti->node_parent)
4726 *ti_ptr = ti->node_parent;
4727 DrawChooseTree(ti_ptr);
4729 else if (game_status == GAME_MODE_SETUP)
4731 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4732 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4733 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4734 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4736 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4737 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4738 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4739 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4740 execSetupGraphics();
4741 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4742 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4743 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4745 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4746 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4747 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4748 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4749 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4750 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4751 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4752 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4759 if (game_status == GAME_MODE_LEVELNR)
4761 int new_level_nr = atoi(level_number_current->identifier);
4763 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4766 SetGameStatus(GAME_MODE_MAIN);
4774 if (mx || my) // mouse input
4776 x = (mx - amSX) / 32;
4777 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4779 if (game_status == GAME_MODE_NAMES)
4780 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4782 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4784 // move cursor instead of scrolling when already at start/end of list
4785 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4787 else if (dy == +1 * SCROLL_LINE &&
4788 ti->cl_first + num_page_entries == num_entries)
4791 // handle scrolling screen one line or page
4792 if (ti->cl_cursor + dy < 0 ||
4793 ti->cl_cursor + dy > num_page_entries - 1)
4795 boolean redraw = FALSE;
4797 if (ABS(dy) == SCROLL_PAGE)
4798 step = num_page_entries - 1;
4800 if (dy < 0 && ti->cl_first > 0)
4802 // scroll page/line up
4804 ti->cl_first -= step;
4805 if (ti->cl_first < 0)
4810 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4812 // scroll page/line down
4814 ti->cl_first += step;
4815 if (ti->cl_first + num_page_entries > num_entries)
4816 ti->cl_first = MAX(0, num_entries - num_page_entries);
4822 drawChooseTreeScreen(ti);
4827 // handle moving cursor one line
4828 y = ti->cl_cursor + dy;
4831 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
4833 HandleHallOfFame_SelectLevel(1, dx);
4839 TreeInfo *node_first, *node_cursor;
4840 int entry_pos = ti->cl_first + y;
4842 node_first = getTreeInfoFirstGroupEntry(ti);
4843 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4845 if (node_cursor->node_group)
4849 PlaySound(SND_MENU_ITEM_SELECTING);
4851 node_cursor->cl_first = ti->cl_first;
4852 node_cursor->cl_cursor = ti->cl_cursor;
4853 *ti_ptr = node_cursor->node_group;
4854 DrawChooseTree(ti_ptr);
4859 else if (dx == -1 && ti->node_parent)
4863 PlaySound(SND_MENU_ITEM_SELECTING);
4865 *ti_ptr = ti->node_parent;
4866 DrawChooseTree(ti_ptr);
4871 if (!anyScrollbarGadgetActive() &&
4872 IN_VIS_MENU(x, y) &&
4873 mx < mx_right_border &&
4874 y >= 0 && y < num_page_entries)
4878 if (game_status == GAME_MODE_NAMES)
4880 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4881 drawChooseTreeEdit(y, TRUE);
4884 if (y != ti->cl_cursor)
4886 PlaySound(SND_MENU_ITEM_ACTIVATING);
4888 drawChooseTreeCursorAndText(ti, FALSE);
4892 drawChooseTreeCursorAndText(ti, TRUE);
4894 drawChooseTreeInfo(ti);
4898 if (game_status == GAME_MODE_SETUP)
4900 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4901 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4902 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4903 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4905 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4906 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4907 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4908 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4909 execSetupGraphics();
4910 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4911 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4912 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4914 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4915 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4916 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4917 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4918 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4919 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4920 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4921 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4930 TreeInfo *node_first, *node_cursor;
4931 int entry_pos = ti->cl_first + y;
4933 PlaySound(SND_MENU_ITEM_SELECTING);
4935 node_first = getTreeInfoFirstGroupEntry(ti);
4936 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4938 if (node_cursor->node_group)
4942 node_cursor->cl_first = ti->cl_first;
4943 node_cursor->cl_cursor = ti->cl_cursor;
4944 *ti_ptr = node_cursor->node_group;
4945 DrawChooseTree(ti_ptr);
4947 else if (node_cursor->parent_link)
4949 if (game_status != GAME_MODE_SCORES)
4952 *ti_ptr = node_cursor->node_parent;
4953 DrawChooseTree(ti_ptr);
4957 if (game_status != GAME_MODE_SCORES)
4960 node_cursor->cl_first = ti->cl_first;
4961 node_cursor->cl_cursor = ti->cl_cursor;
4962 *ti_ptr = node_cursor;
4964 if (ti->type == TREE_TYPE_LEVEL_DIR)
4966 LoadLevelSetup_SeriesInfo();
4968 SaveLevelSetup_LastSeries();
4969 SaveLevelSetup_SeriesInfo();
4973 if (game_status == GAME_MODE_SETUP)
4975 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4976 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4977 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4978 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4980 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4981 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4982 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4983 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4984 execSetupGraphics();
4985 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4986 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4987 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4989 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4990 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4991 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4992 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4993 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4994 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4995 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4996 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5003 if (game_status == GAME_MODE_LEVELNR)
5005 int new_level_nr = atoi(level_number_current->identifier);
5007 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5009 else if (game_status == GAME_MODE_LEVELS)
5011 // store level set if chosen from "last played level set" menu
5012 StoreLastPlayedLevels(leveldir_current);
5014 else if (game_status == GAME_MODE_NAMES)
5016 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5018 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5025 // change active user to selected user
5026 user.nr = entry_pos;
5028 // save number of new active user
5031 // load setup of new active user
5034 // load last level set of new active user
5035 LoadLevelSetup_LastSeries();
5036 LoadLevelSetup_SeriesInfo();
5038 // update list of last played level sets
5039 UpdateLastPlayedLevels_TreeInfo();
5043 ToggleFullscreenIfNeeded();
5044 ChangeWindowScalingIfNeeded();
5046 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5047 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5048 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5050 else if (game_status == GAME_MODE_SCORES)
5052 if (game_status_last_screen == GAME_MODE_PLAYING &&
5053 setup.auto_play_next_level && setup.increment_levels &&
5054 scores.last_level_nr < leveldir_current->last_level &&
5057 StartGameActions(network.enabled, setup.autorecord,
5063 SetGameStatus(GAME_MODE_SCOREINFO);
5065 DrawScoreInfo(node_cursor->pos);
5071 SetGameStatus(GAME_MODE_MAIN);
5079 if (game_status == GAME_MODE_SCORES)
5080 PlayMenuSoundIfLoop();
5083 void DrawChoosePlayerName(void)
5087 if (player_name != NULL)
5089 freeTreeInfo(player_name);
5094 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5096 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5097 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5100 ti->node_top = &player_name;
5101 ti->sort_priority = 10000 + value;
5102 ti->color = getPlayerNameColor(global.user_names[i]);
5104 snprintf(identifier, sizeof(identifier), "%d", value);
5105 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5107 setString(&ti->identifier, identifier);
5108 setString(&ti->name, name);
5109 setString(&ti->name_sorting, name);
5111 pushTreeInfo(&player_name, ti);
5114 // sort player entries by player number
5115 sortTreeInfo(&player_name);
5117 // set current player entry to selected player entry
5118 player_name_current =
5119 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5121 // if that fails, set current player name to first available name
5122 if (player_name_current == NULL)
5123 player_name_current = player_name;
5125 DrawChooseTree(&player_name_current);
5128 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5130 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5133 void DrawChooseLevelSet(void)
5135 DrawChooseTree(&leveldir_current);
5138 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5140 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5143 void DrawChooseLevelNr(void)
5147 if (level_number != NULL)
5149 freeTreeInfo(level_number);
5151 level_number = NULL;
5154 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5156 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5157 char identifier[32], name[64];
5160 // temporarily load level info to get level name
5161 LoadLevelInfoOnly(i);
5163 ti->node_top = &level_number;
5164 ti->sort_priority = 10000 + value;
5165 ti->color = (level.no_level_file ? FC_BLUE :
5166 LevelStats_getSolved(i) ? FC_GREEN :
5167 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5169 snprintf(identifier, sizeof(identifier), "%d", value);
5170 snprintf(name, sizeof(name), "%03d: %s", value,
5171 (level.no_level_file ? "(no file)" : level.name));
5173 setString(&ti->identifier, identifier);
5174 setString(&ti->name, name);
5175 setString(&ti->name_sorting, name);
5177 pushTreeInfo(&level_number, ti);
5180 // sort level number values to start with lowest level number
5181 sortTreeInfo(&level_number);
5183 // set current level number to current level number
5184 level_number_current =
5185 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5187 // if that also fails, set current level number to first available level
5188 if (level_number_current == NULL)
5189 level_number_current = level_number;
5191 DrawChooseTree(&level_number_current);
5194 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5196 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5199 static void DrawHallOfFame_setScoreEntries(void)
5201 int max_empty_entries = 10; // at least show "top ten" list, if empty
5202 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5203 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5204 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5207 if (score_entries != NULL)
5209 freeTreeInfo(score_entries);
5211 score_entries = NULL;
5214 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5216 // do not add empty score entries if off-screen
5217 if (scores.entry[i].score == 0 &&
5218 scores.entry[i].time == 0 &&
5219 i >= min_score_entries)
5222 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5223 char identifier[32], name[64];
5226 ti->node_top = &score_entries;
5227 ti->sort_priority = 10000 + value;
5228 ti->color = FC_YELLOW;
5231 snprintf(identifier, sizeof(identifier), "%d", value);
5232 snprintf(name, sizeof(name), "%03d.", value + 1);
5234 setString(&ti->identifier, identifier);
5235 setString(&ti->name, name);
5236 setString(&ti->name_sorting, name);
5238 pushTreeInfo(&score_entries, ti);
5241 // sort score entries to start with highest score entry
5242 sortTreeInfo(&score_entries);
5244 // add top tree node to create back link to main menu
5245 score_entries = addTopTreeInfoNode(score_entries);
5247 // set current score entry to last added or highest score entry
5248 score_entry_current =
5249 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5251 // if that fails, set current score entry to first valid score entry
5252 if (score_entry_current == NULL)
5253 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5255 // ("score_entries" and "score_entry_current" may be NULL here)
5258 void DrawHallOfFame(int level_nr)
5260 scores.last_level_nr = level_nr;
5262 // (this is needed when called from GameEnd() after winning a game)
5263 KeyboardAutoRepeatOn();
5265 // (this is needed when called from GameEnd() after winning a game)
5266 SetDrawDeactivationMask(REDRAW_NONE);
5267 SetDrawBackgroundMask(REDRAW_FIELD);
5269 LoadLocalAndServerScore(level_nr, TRUE);
5271 DrawHallOfFame_setScoreEntries();
5273 if (scores.last_added >= 0)
5274 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5276 FadeSetEnterScreen();
5278 DrawChooseTree(&score_entry_current);
5281 static char *getHallOfFameRankText(int nr, int size)
5283 static char rank_text[10];
5284 boolean forced = (scores.force_last_added && nr == scores.last_added);
5285 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5287 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5292 static char *getHallOfFameTimeText(int nr)
5294 static char score_text[10];
5295 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5296 int mm = (time_seconds / 60) % 60;
5297 int ss = (time_seconds % 60);
5299 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5304 static char *getHallOfFameScoreText(int nr, int size)
5306 if (!level.rate_time_over_score)
5307 return int2str(scores.entry[nr].score, size); // show normal score
5308 else if (level.use_step_counter)
5309 return int2str(scores.entry[nr].time, size); // show number of steps
5311 return getHallOfFameTimeText(nr); // show playing time
5314 static void HandleHallOfFame_SelectLevel(int step, int direction)
5316 int old_level_nr = scores.last_level_nr;
5317 int new_level_nr = old_level_nr + step * direction;
5319 if (new_level_nr < leveldir_current->first_level)
5320 new_level_nr = leveldir_current->first_level;
5321 if (new_level_nr > leveldir_current->last_level)
5322 new_level_nr = leveldir_current->last_level;
5324 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5325 new_level_nr = leveldir_current->handicap_level;
5327 if (new_level_nr != old_level_nr)
5329 PlaySound(SND_MENU_ITEM_SELECTING);
5331 scores.last_level_nr = level_nr = new_level_nr;
5332 scores.last_entry_nr = 0;
5334 LoadLevel(level_nr);
5335 LoadLocalAndServerScore(level_nr, TRUE);
5337 DrawHallOfFame_setScoreEntries();
5339 if (game_status == GAME_MODE_SCORES)
5341 // force remapping optional gadgets (especially scroll bar)
5342 UnmapScreenTreeGadgets();
5344 // redraw complete high score screen, as sub-title has changed
5347 // redraw level selection buttons (which have just been erased)
5348 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5350 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5354 DrawScoreInfo_Content(scores.last_entry_nr);
5357 SaveLevelSetup_SeriesInfo();
5361 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5363 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5366 static void DrawScoreInfo_Content(int entry_nr)
5368 struct ScoreEntry *entry = &scores.entry[entry_nr];
5369 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5370 int font_title = MENU_INFO_FONT_TITLE;
5371 int font_head = MENU_INFO_FONT_HEAD;
5372 int font_text = MENU_INFO_FONT_TEXT;
5373 int font_foot = MENU_INFO_FONT_FOOT;
5374 int spacing_title = menu.headline1_spacing[GAME_MODE_SCOREINFO];
5375 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5376 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5377 int xstep = getFontWidth(font_text);
5378 int ystep_title = getMenuTextStep(spacing_title, font_title);
5379 int ystep_para = getMenuTextStep(spacing_para, font_text);
5380 int ystep_line = getMenuTextStep(spacing_line, font_text);
5381 int ystart = mSY - SY + menu.top_spacing[GAME_MODE_SCOREINFO];
5382 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5383 int xstart1 = mSX - SX + 2 * xstep;
5384 int xstart2 = mSX - SX + 13 * xstep;
5385 int select_x = SX + xstart1;
5386 int select_y1, select_y2;
5388 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5389 boolean play_visible = (entry->id != -1);
5390 int font_width = getFontWidth(font_text);
5391 int font_height = getFontHeight(font_text);
5392 int tape_date_width = getTextWidth(entry->tape_date, font_text);
5393 int pad_left = xstart2;
5394 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
5395 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5396 int max_lines_per_text = 5;
5401 // redraw score selection buttons (which have just been erased)
5402 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5404 if (score_entries == NULL)
5406 drawChooseTreeScreen_Scores_NotAvailable();
5411 drawChooseTreeHead(score_entries);
5412 drawChooseTreeInfo(score_entries);
5414 DrawTextSCentered(ystart, font_title, "Score Information:");
5415 ystart += ystep_title;
5417 DrawTextF(xstart1, ystart, font_head, "Level Set");
5418 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5419 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5420 TRUE, FALSE, FALSE);
5421 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5423 DrawTextF(xstart1, ystart, font_head, "Level");
5424 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5425 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5426 TRUE, FALSE, FALSE);
5427 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5429 select_y1 = SY + ystart;
5430 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5432 DrawTextF(xstart1, ystart, font_head, "Rank");
5433 DrawTextF(xstart2, ystart, font_text, pos_text);
5434 ystart += ystep_line;
5436 DrawTextF(xstart1, ystart, font_head, "Player");
5437 DrawTextF(xstart2, ystart, font_text, entry->name);
5438 ystart += ystep_line;
5440 if (level.use_step_counter)
5442 DrawTextF(xstart1, ystart, font_head, "Steps");
5443 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5444 ystart += ystep_line;
5448 DrawTextF(xstart1, ystart, font_head, "Time");
5449 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5450 ystart += ystep_line;
5453 if (!level.rate_time_over_score || entry->score > 0)
5455 DrawTextF(xstart1, ystart, font_head, "Score");
5456 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5457 ystart += ystep_line;
5460 ystart += ystep_line;
5462 play_x = SX + xstart2 + tape_date_width + font_width;
5463 play_y = SY + ystart + (font_height - play_height) / 2;
5465 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5466 DrawTextF(xstart2, ystart, font_text, entry->tape_date);
5467 ystart += ystep_line;
5469 DrawTextF(xstart1, ystart, font_head, "Platform");
5470 DrawTextF(xstart2, ystart, font_text, entry->platform);
5471 ystart += ystep_line;
5473 DrawTextF(xstart1, ystart, font_head, "Version");
5474 DrawTextF(xstart2, ystart, font_text, entry->version);
5475 ystart += ystep_line;
5477 DrawTextF(xstart1, ystart, font_head, "Country");
5478 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5479 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5480 TRUE, FALSE, FALSE);
5481 ystart += ystep_line;
5483 select_y2 = SY + ystart;
5485 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5487 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5488 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5491 static void DrawScoreInfo(int entry_nr)
5493 scores.last_entry_nr = entry_nr;
5494 score_info_tape_play = FALSE;
5496 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5500 FadeOut(REDRAW_FIELD);
5502 // needed if different viewport properties defined after playing score tape
5503 ChangeViewportPropertiesIfNeeded();
5505 DrawScoreInfo_Content(entry_nr);
5507 // map gadgets for score info screen
5508 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5510 FadeIn(REDRAW_FIELD);
5513 static void HandleScoreInfo_SelectScore(int step, int direction)
5515 int old_entry_nr = scores.last_entry_nr;
5516 int new_entry_nr = old_entry_nr + step * direction;
5517 int num_nodes = numTreeInfoInGroup(score_entry_current);
5518 int num_entries = num_nodes - 1; // score nodes only, without back link
5520 if (new_entry_nr < 0)
5522 if (new_entry_nr > num_entries - 1)
5523 new_entry_nr = num_entries - 1;
5525 if (new_entry_nr != old_entry_nr)
5527 scores.last_entry_nr = new_entry_nr;
5529 DrawScoreInfo_Content(new_entry_nr);
5533 static void HandleScoreInfo_PlayTape(void)
5535 if (!PlayScoreTape(scores.last_entry_nr))
5537 DrawScoreInfo_Content(scores.last_entry_nr);
5539 FadeIn(REDRAW_FIELD);
5543 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5545 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5546 boolean button_is_valid = (mx >= 0 && my >= 0);
5547 boolean button_screen_clicked = (button_action && button_is_valid);
5549 if (server_scores.updated)
5551 // reload scores, using updated server score cache file
5552 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5554 server_scores.updated = FALSE;
5556 DrawHallOfFame_setScoreEntries();
5558 DrawScoreInfo_Content(scores.last_entry_nr);
5561 if (button_screen_clicked)
5563 PlaySound(SND_MENU_ITEM_SELECTING);
5565 SetGameStatus(GAME_MODE_SCORES);
5567 DrawHallOfFame(level_nr);
5571 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5575 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5580 // ============================================================================
5581 // setup screen functions
5582 // ============================================================================
5584 static struct TokenInfo *setup_info;
5585 static int num_setup_info; // number of setup entries shown on screen
5586 static int max_setup_info; // total number of setup entries in list
5588 static char *window_size_text;
5589 static char *scaling_type_text;
5590 static char *rendering_mode_text;
5591 static char *vsync_mode_text;
5592 static char *scroll_delay_text;
5593 static char *snapshot_mode_text;
5594 static char *game_speed_text;
5595 static char *scores_type_text;
5596 static char *network_server_text;
5597 static char *graphics_set_name;
5598 static char *sounds_set_name;
5599 static char *music_set_name;
5600 static char *volume_simple_text;
5601 static char *volume_loops_text;
5602 static char *volume_music_text;
5603 static char *touch_controls_text;
5604 static char *move_distance_text;
5605 static char *drop_distance_text;
5606 static char *transparency_text;
5607 static char *grid_size_text[2][2];
5609 static void execSetupMain(void)
5611 setup_mode = SETUP_MODE_MAIN;
5616 static void execSetupGame_setScoresType(void)
5618 if (scores_types == NULL)
5622 for (i = 0; scores_types_list[i].value != NULL; i++)
5624 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5625 char identifier[32], name[32];
5626 char *value = scores_types_list[i].value;
5627 char *text = scores_types_list[i].text;
5629 ti->node_top = &scores_types;
5630 ti->sort_priority = i;
5632 sprintf(identifier, "%s", value);
5633 sprintf(name, "%s", text);
5635 setString(&ti->identifier, identifier);
5636 setString(&ti->name, name);
5637 setString(&ti->name_sorting, name);
5638 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5640 pushTreeInfo(&scores_types, ti);
5643 // sort scores type values to start with lowest scores type value
5644 sortTreeInfo(&scores_types);
5646 // set current scores type value to configured scores type value
5647 scores_type_current =
5648 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5650 // if that fails, set current scores type to reliable default value
5651 if (scores_type_current == NULL)
5652 scores_type_current =
5653 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5655 // if that also fails, set current scores type to first available value
5656 if (scores_type_current == NULL)
5657 scores_type_current = scores_types;
5660 setup.scores_in_highscore_list = scores_type_current->identifier;
5662 // needed for displaying scores type text instead of identifier
5663 scores_type_text = scores_type_current->name;
5666 static void execSetupGame_setGameSpeeds(boolean update_value)
5668 if (setup.game_speed_extended)
5670 game_speeds_list = game_speeds_list_extended;
5671 game_speeds = game_speeds_extended;
5675 game_speeds_list = game_speeds_list_normal;
5676 game_speeds = game_speeds_normal;
5679 if (game_speeds == NULL)
5683 for (i = 0; game_speeds_list[i].value != -1; i++)
5685 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5686 char identifier[32], name[32];
5687 int value = game_speeds_list[i].value;
5688 char *text = game_speeds_list[i].text;
5690 ti->node_top = &game_speeds;
5691 ti->sort_priority = 10000 - value;
5693 sprintf(identifier, "%d", value);
5694 sprintf(name, "%s", text);
5696 setString(&ti->identifier, identifier);
5697 setString(&ti->name, name);
5698 setString(&ti->name_sorting, name);
5699 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5701 pushTreeInfo(&game_speeds, ti);
5704 // sort game speed values to start with slowest game speed
5705 sortTreeInfo(&game_speeds);
5707 update_value = TRUE;
5712 // set current game speed to configured game speed value
5713 game_speed_current =
5714 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5716 // if that fails, set current game speed to reliable default value
5717 if (game_speed_current == NULL)
5718 game_speed_current =
5719 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5721 // if that also fails, set current game speed to first available speed
5722 if (game_speed_current == NULL)
5723 game_speed_current = game_speeds;
5725 if (setup.game_speed_extended)
5726 game_speeds_extended = game_speeds;
5728 game_speeds_normal = game_speeds;
5731 setup.game_frame_delay = atoi(game_speed_current->identifier);
5733 // needed for displaying game speed text instead of identifier
5734 game_speed_text = game_speed_current->name;
5737 static void execSetupGame_setScrollDelays(void)
5739 if (scroll_delays == NULL)
5743 for (i = 0; scroll_delays_list[i].value != -1; i++)
5745 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5746 char identifier[32], name[32];
5747 int value = scroll_delays_list[i].value;
5748 char *text = scroll_delays_list[i].text;
5750 ti->node_top = &scroll_delays;
5751 ti->sort_priority = value;
5753 sprintf(identifier, "%d", value);
5754 sprintf(name, "%s", text);
5756 setString(&ti->identifier, identifier);
5757 setString(&ti->name, name);
5758 setString(&ti->name_sorting, name);
5759 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5761 pushTreeInfo(&scroll_delays, ti);
5764 // sort scroll delay values to start with lowest scroll delay value
5765 sortTreeInfo(&scroll_delays);
5767 // set current scroll delay value to configured scroll delay value
5768 scroll_delay_current =
5769 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5771 // if that fails, set current scroll delay to reliable default value
5772 if (scroll_delay_current == NULL)
5773 scroll_delay_current =
5774 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5776 // if that also fails, set current scroll delay to first available value
5777 if (scroll_delay_current == NULL)
5778 scroll_delay_current = scroll_delays;
5781 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5783 // needed for displaying scroll delay text instead of identifier
5784 scroll_delay_text = scroll_delay_current->name;
5787 static void execSetupGame_setSnapshotModes(void)
5789 if (snapshot_modes == NULL)
5793 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5795 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5796 char identifier[32], name[32];
5797 char *value = snapshot_modes_list[i].value;
5798 char *text = snapshot_modes_list[i].text;
5800 ti->node_top = &snapshot_modes;
5801 ti->sort_priority = i;
5803 sprintf(identifier, "%s", value);
5804 sprintf(name, "%s", text);
5806 setString(&ti->identifier, identifier);
5807 setString(&ti->name, name);
5808 setString(&ti->name_sorting, name);
5809 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5811 pushTreeInfo(&snapshot_modes, ti);
5814 // sort snapshot mode values to start with lowest snapshot mode value
5815 sortTreeInfo(&snapshot_modes);
5817 // set current snapshot mode value to configured snapshot mode value
5818 snapshot_mode_current =
5819 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5821 // if that fails, set current snapshot mode to reliable default value
5822 if (snapshot_mode_current == NULL)
5823 snapshot_mode_current =
5824 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5826 // if that also fails, set current snapshot mode to first available value
5827 if (snapshot_mode_current == NULL)
5828 snapshot_mode_current = snapshot_modes;
5831 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5833 // needed for displaying snapshot mode text instead of identifier
5834 snapshot_mode_text = snapshot_mode_current->name;
5837 static void execSetupGame_setNetworkServerText(void)
5839 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5841 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5845 strncpy(network_server_hostname, setup.network_server_hostname,
5846 MAX_SETUP_TEXT_INPUT_LEN);
5847 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5850 // needed for displaying network server text instead of identifier
5851 network_server_text = network_server_hostname;
5854 static void execSetupGame(void)
5856 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5858 execSetupGame_setGameSpeeds(FALSE);
5859 execSetupGame_setScoresType();
5860 execSetupGame_setScrollDelays();
5861 execSetupGame_setSnapshotModes();
5863 execSetupGame_setNetworkServerText();
5865 if (!setup.provide_uploading_tapes)
5866 setHideSetupEntry(execOfferUploadTapes);
5868 setup_mode = SETUP_MODE_GAME;
5872 // check if vsync needs to be disabled for this game speed to work
5873 if (check_vsync_mode)
5874 DisableVsyncIfNeeded();
5877 static void execSetupChooseScoresType(void)
5879 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
5884 static void execSetupChooseGameSpeed(void)
5886 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5891 static void execSetupChooseScrollDelay(void)
5893 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5898 static void execSetupChooseSnapshotMode(void)
5900 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5905 static void execSetupEngines(void)
5907 setup_mode = SETUP_MODE_ENGINES;
5912 static void execSetupEditor(void)
5914 setup_mode = SETUP_MODE_EDITOR;
5919 static void execSetupGraphics_setWindowSizes(boolean update_list)
5921 if (window_sizes != NULL && update_list)
5923 freeTreeInfo(window_sizes);
5925 window_sizes = NULL;
5928 if (window_sizes == NULL)
5930 boolean current_window_size_found = FALSE;
5933 for (i = 0; window_sizes_list[i].value != -1; i++)
5935 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5936 char identifier[32], name[32];
5937 int value = window_sizes_list[i].value;
5938 char *text = window_sizes_list[i].text;
5940 ti->node_top = &window_sizes;
5941 ti->sort_priority = value;
5943 sprintf(identifier, "%d", value);
5944 sprintf(name, "%s", text);
5946 setString(&ti->identifier, identifier);
5947 setString(&ti->name, name);
5948 setString(&ti->name_sorting, name);
5949 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5951 pushTreeInfo(&window_sizes, ti);
5953 if (value == setup.window_scaling_percent)
5954 current_window_size_found = TRUE;
5957 if (!current_window_size_found)
5959 // add entry for non-preset window scaling value
5961 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5962 char identifier[32], name[32];
5963 int value = setup.window_scaling_percent;
5965 ti->node_top = &window_sizes;
5966 ti->sort_priority = value;
5968 sprintf(identifier, "%d", value);
5969 sprintf(name, "%d %% (Current)", value);
5971 setString(&ti->identifier, identifier);
5972 setString(&ti->name, name);
5973 setString(&ti->name_sorting, name);
5974 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5976 pushTreeInfo(&window_sizes, ti);
5979 // sort window size values to start with lowest window size value
5980 sortTreeInfo(&window_sizes);
5982 // set current window size value to configured window size value
5983 window_size_current =
5984 getTreeInfoFromIdentifier(window_sizes,
5985 i_to_a(setup.window_scaling_percent));
5987 // if that fails, set current window size to reliable default value
5988 if (window_size_current == NULL)
5989 window_size_current =
5990 getTreeInfoFromIdentifier(window_sizes,
5991 i_to_a(STD_WINDOW_SCALING_PERCENT));
5993 // if that also fails, set current window size to first available value
5994 if (window_size_current == NULL)
5995 window_size_current = window_sizes;
5998 setup.window_scaling_percent = atoi(window_size_current->identifier);
6000 // needed for displaying window size text instead of identifier
6001 window_size_text = window_size_current->name;
6004 static void execSetupGraphics_setScalingTypes(void)
6006 if (scaling_types == NULL)
6010 for (i = 0; scaling_types_list[i].value != NULL; i++)
6012 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6013 char identifier[32], name[32];
6014 char *value = scaling_types_list[i].value;
6015 char *text = scaling_types_list[i].text;
6017 ti->node_top = &scaling_types;
6018 ti->sort_priority = i;
6020 sprintf(identifier, "%s", value);
6021 sprintf(name, "%s", text);
6023 setString(&ti->identifier, identifier);
6024 setString(&ti->name, name);
6025 setString(&ti->name_sorting, name);
6026 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6028 pushTreeInfo(&scaling_types, ti);
6031 // sort scaling type values to start with lowest scaling type value
6032 sortTreeInfo(&scaling_types);
6034 // set current scaling type value to configured scaling type value
6035 scaling_type_current =
6036 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6038 // if that fails, set current scaling type to reliable default value
6039 if (scaling_type_current == NULL)
6040 scaling_type_current =
6041 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6043 // if that also fails, set current scaling type to first available value
6044 if (scaling_type_current == NULL)
6045 scaling_type_current = scaling_types;
6048 setup.window_scaling_quality = scaling_type_current->identifier;
6050 // needed for displaying scaling type text instead of identifier
6051 scaling_type_text = scaling_type_current->name;
6054 static void execSetupGraphics_setRenderingModes(void)
6056 if (rendering_modes == NULL)
6060 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6062 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6063 char identifier[32], name[32];
6064 char *value = rendering_modes_list[i].value;
6065 char *text = rendering_modes_list[i].text;
6067 ti->node_top = &rendering_modes;
6068 ti->sort_priority = i;
6070 sprintf(identifier, "%s", value);
6071 sprintf(name, "%s", text);
6073 setString(&ti->identifier, identifier);
6074 setString(&ti->name, name);
6075 setString(&ti->name_sorting, name);
6076 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6078 pushTreeInfo(&rendering_modes, ti);
6081 // sort rendering mode values to start with lowest rendering mode value
6082 sortTreeInfo(&rendering_modes);
6084 // set current rendering mode value to configured rendering mode value
6085 rendering_mode_current =
6086 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6088 // if that fails, set current rendering mode to reliable default value
6089 if (rendering_mode_current == NULL)
6090 rendering_mode_current =
6091 getTreeInfoFromIdentifier(rendering_modes,
6092 STR_SPECIAL_RENDERING_DEFAULT);
6094 // if that also fails, set current rendering mode to first available one
6095 if (rendering_mode_current == NULL)
6096 rendering_mode_current = rendering_modes;
6099 setup.screen_rendering_mode = rendering_mode_current->identifier;
6101 // needed for displaying rendering mode text instead of identifier
6102 rendering_mode_text = rendering_mode_current->name;
6105 static void execSetupGraphics_setVsyncModes(boolean update_value)
6107 if (vsync_modes == NULL)
6111 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6113 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6114 char identifier[32], name[32];
6115 char *value = vsync_modes_list[i].value;
6116 char *text = vsync_modes_list[i].text;
6118 ti->node_top = &vsync_modes;
6119 ti->sort_priority = i;
6121 sprintf(identifier, "%s", value);
6122 sprintf(name, "%s", text);
6124 setString(&ti->identifier, identifier);
6125 setString(&ti->name, name);
6126 setString(&ti->name_sorting, name);
6127 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6129 pushTreeInfo(&vsync_modes, ti);
6132 // sort vsync mode values to start with lowest vsync mode value
6133 sortTreeInfo(&vsync_modes);
6135 update_value = TRUE;
6140 // set current vsync mode value to configured vsync mode value
6141 vsync_mode_current =
6142 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6144 // if that fails, set current vsync mode to reliable default value
6145 if (vsync_mode_current == NULL)
6146 vsync_mode_current =
6147 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6149 // if that also fails, set current vsync mode to first available one
6150 if (vsync_mode_current == NULL)
6151 vsync_mode_current = vsync_modes;
6154 setup.vsync_mode = vsync_mode_current->identifier;
6156 // needed for displaying vsync mode text instead of identifier
6157 vsync_mode_text = vsync_mode_current->name;
6160 static void execSetupGraphics(void)
6162 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6164 // update "setup.window_scaling_percent" from list selection
6165 // (in this case, window scaling was changed on setup screen)
6166 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6167 execSetupGraphics_setWindowSizes(FALSE);
6169 // update "setup.vsync_mode" from list selection
6170 // (in this case, vsync mode was changed on setup screen)
6171 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6172 execSetupGraphics_setVsyncModes(FALSE);
6174 // update list selection from "setup.window_scaling_percent"
6175 // (window scaling may have changed by resizing the window)
6176 execSetupGraphics_setWindowSizes(TRUE);
6178 // update list selection from "setup.vsync_mode"
6179 // (vsync_mode may have changed by re-creating the renderer)
6180 execSetupGraphics_setVsyncModes(TRUE);
6182 execSetupGraphics_setScalingTypes();
6183 execSetupGraphics_setRenderingModes();
6185 setup_mode = SETUP_MODE_GRAPHICS;
6189 // check if game speed is high enough for 60 Hz vsync to work
6190 if (check_game_speed)
6191 ModifyGameSpeedIfNeeded();
6193 // window scaling may have changed at this point
6194 ChangeWindowScalingIfNeeded();
6196 // window scaling quality may have changed at this point
6197 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6198 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6200 // screen rendering mode may have changed at this point
6201 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6203 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6204 int video_vsync_mode = video.vsync_mode;
6206 // screen vsync mode may have changed at this point
6207 ChangeVsyncModeIfNeeded();
6209 // check if setting vsync mode to selected value failed
6210 if (setup_vsync_mode != video_vsync_mode &&
6211 setup_vsync_mode != video.vsync_mode)
6213 // changing vsync mode to selected value failed -- reset displayed value
6214 execSetupGraphics_setVsyncModes(TRUE);
6216 Request("Setting VSync failed!", REQ_CONFIRM);
6222 static void execSetupChooseWindowSize(void)
6224 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6229 static void execSetupChooseScalingType(void)
6231 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6236 static void execSetupChooseRenderingMode(void)
6238 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6243 static void execSetupChooseVsyncMode(void)
6245 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6250 static void execSetupChooseVolumeSimple(void)
6252 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6257 static void execSetupChooseVolumeLoops(void)
6259 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6264 static void execSetupChooseVolumeMusic(void)
6266 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6271 static void execSetupSound(void)
6273 if (volumes_simple == NULL)
6275 boolean current_volume_simple_found = FALSE;
6278 for (i = 0; volumes_list[i].value != -1; i++)
6280 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6281 char identifier[32], name[32];
6282 int value = volumes_list[i].value;
6283 char *text = volumes_list[i].text;
6285 ti->node_top = &volumes_simple;
6286 ti->sort_priority = value;
6288 sprintf(identifier, "%d", value);
6289 sprintf(name, "%s", text);
6291 setString(&ti->identifier, identifier);
6292 setString(&ti->name, name);
6293 setString(&ti->name_sorting, name);
6294 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6296 pushTreeInfo(&volumes_simple, ti);
6298 if (value == setup.volume_simple)
6299 current_volume_simple_found = TRUE;
6302 if (!current_volume_simple_found)
6304 // add entry for non-preset volume value
6306 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6307 char identifier[32], name[32];
6308 int value = setup.volume_simple;
6310 ti->node_top = &volumes_simple;
6311 ti->sort_priority = value;
6313 sprintf(identifier, "%d", value);
6314 sprintf(name, "%d %% (Current)", value);
6316 setString(&ti->identifier, identifier);
6317 setString(&ti->name, name);
6318 setString(&ti->name_sorting, name);
6319 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6321 pushTreeInfo(&volumes_simple, ti);
6324 // sort volume values to start with lowest volume value
6325 sortTreeInfo(&volumes_simple);
6327 // set current volume value to configured volume value
6328 volume_simple_current =
6329 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6331 // if that fails, set current volume to reliable default value
6332 if (volume_simple_current == NULL)
6333 volume_simple_current =
6334 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6336 // if that also fails, set current volume to first available value
6337 if (volume_simple_current == NULL)
6338 volume_simple_current = volumes_simple;
6341 if (volumes_loops == NULL)
6343 boolean current_volume_loops_found = FALSE;
6346 for (i = 0; volumes_list[i].value != -1; i++)
6348 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6349 char identifier[32], name[32];
6350 int value = volumes_list[i].value;
6351 char *text = volumes_list[i].text;
6353 ti->node_top = &volumes_loops;
6354 ti->sort_priority = value;
6356 sprintf(identifier, "%d", value);
6357 sprintf(name, "%s", text);
6359 setString(&ti->identifier, identifier);
6360 setString(&ti->name, name);
6361 setString(&ti->name_sorting, name);
6362 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6364 pushTreeInfo(&volumes_loops, ti);
6366 if (value == setup.volume_loops)
6367 current_volume_loops_found = TRUE;
6370 if (!current_volume_loops_found)
6372 // add entry for non-preset volume value
6374 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6375 char identifier[32], name[32];
6376 int value = setup.volume_loops;
6378 ti->node_top = &volumes_loops;
6379 ti->sort_priority = value;
6381 sprintf(identifier, "%d", value);
6382 sprintf(name, "%d %% (Current)", value);
6384 setString(&ti->identifier, identifier);
6385 setString(&ti->name, name);
6386 setString(&ti->name_sorting, name);
6387 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6389 pushTreeInfo(&volumes_loops, ti);
6392 // sort volume values to start with lowest volume value
6393 sortTreeInfo(&volumes_loops);
6395 // set current volume value to configured volume value
6396 volume_loops_current =
6397 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6399 // if that fails, set current volume to reliable default value
6400 if (volume_loops_current == NULL)
6401 volume_loops_current =
6402 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6404 // if that also fails, set current volume to first available value
6405 if (volume_loops_current == NULL)
6406 volume_loops_current = volumes_loops;
6409 if (volumes_music == NULL)
6411 boolean current_volume_music_found = FALSE;
6414 for (i = 0; volumes_list[i].value != -1; i++)
6416 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6417 char identifier[32], name[32];
6418 int value = volumes_list[i].value;
6419 char *text = volumes_list[i].text;
6421 ti->node_top = &volumes_music;
6422 ti->sort_priority = value;
6424 sprintf(identifier, "%d", value);
6425 sprintf(name, "%s", text);
6427 setString(&ti->identifier, identifier);
6428 setString(&ti->name, name);
6429 setString(&ti->name_sorting, name);
6430 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6432 pushTreeInfo(&volumes_music, ti);
6434 if (value == setup.volume_music)
6435 current_volume_music_found = TRUE;
6438 if (!current_volume_music_found)
6440 // add entry for non-preset volume value
6442 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6443 char identifier[32], name[32];
6444 int value = setup.volume_music;
6446 ti->node_top = &volumes_music;
6447 ti->sort_priority = value;
6449 sprintf(identifier, "%d", value);
6450 sprintf(name, "%d %% (Current)", value);
6452 setString(&ti->identifier, identifier);
6453 setString(&ti->name, name);
6454 setString(&ti->name_sorting, name);
6455 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6457 pushTreeInfo(&volumes_music, ti);
6460 // sort volume values to start with lowest volume value
6461 sortTreeInfo(&volumes_music);
6463 // set current volume value to configured volume value
6464 volume_music_current =
6465 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6467 // if that fails, set current volume to reliable default value
6468 if (volume_music_current == NULL)
6469 volume_music_current =
6470 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6472 // if that also fails, set current volume to first available value
6473 if (volume_music_current == NULL)
6474 volume_music_current = volumes_music;
6477 setup.volume_simple = atoi(volume_simple_current->identifier);
6478 setup.volume_loops = atoi(volume_loops_current->identifier);
6479 setup.volume_music = atoi(volume_music_current->identifier);
6481 // needed for displaying volume text instead of identifier
6482 volume_simple_text = volume_simple_current->name;
6483 volume_loops_text = volume_loops_current->name;
6484 volume_music_text = volume_music_current->name;
6486 setup_mode = SETUP_MODE_SOUND;
6491 static void execSetupChooseTouchControls(void)
6493 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6498 static void execSetupChooseMoveDistance(void)
6500 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6505 static void execSetupChooseDropDistance(void)
6507 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6512 static void execSetupChooseTransparency(void)
6514 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6519 static void execSetupChooseGridXSize_0(void)
6521 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6526 static void execSetupChooseGridYSize_0(void)
6528 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6533 static void execSetupChooseGridXSize_1(void)
6535 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6540 static void execSetupChooseGridYSize_1(void)
6542 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6547 static void execSetupConfigureVirtualButtons(void)
6549 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6551 ConfigureVirtualButtons();
6553 setup_mode = SETUP_MODE_TOUCH;
6558 static void execSetupTouch(void)
6562 if (touch_controls == NULL)
6564 for (i = 0; touch_controls_list[i].value != NULL; i++)
6566 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6567 char identifier[32], name[32];
6568 char *value = touch_controls_list[i].value;
6569 char *text = touch_controls_list[i].text;
6571 ti->node_top = &touch_controls;
6572 ti->sort_priority = i;
6574 sprintf(identifier, "%s", value);
6575 sprintf(name, "%s", text);
6577 setString(&ti->identifier, identifier);
6578 setString(&ti->name, name);
6579 setString(&ti->name_sorting, name);
6580 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6582 pushTreeInfo(&touch_controls, ti);
6585 // sort touch control values to start with lowest touch control value
6586 sortTreeInfo(&touch_controls);
6588 // set current touch control value to configured touch control value
6589 touch_control_current =
6590 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6592 // if that fails, set current touch control to reliable default value
6593 if (touch_control_current == NULL)
6594 touch_control_current =
6595 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6597 // if that also fails, set current touch control to first available value
6598 if (touch_control_current == NULL)
6599 touch_control_current = touch_controls;
6602 if (move_distances == NULL)
6604 for (i = 0; distances_list[i].value != -1; i++)
6606 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6607 char identifier[32], name[32];
6608 int value = distances_list[i].value;
6609 char *text = distances_list[i].text;
6611 ti->node_top = &move_distances;
6612 ti->sort_priority = value;
6614 sprintf(identifier, "%d", value);
6615 sprintf(name, "%s", text);
6617 setString(&ti->identifier, identifier);
6618 setString(&ti->name, name);
6619 setString(&ti->name_sorting, name);
6620 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6622 pushTreeInfo(&move_distances, ti);
6625 // sort distance values to start with lowest distance value
6626 sortTreeInfo(&move_distances);
6628 // set current distance value to configured distance value
6629 move_distance_current =
6630 getTreeInfoFromIdentifier(move_distances,
6631 i_to_a(setup.touch.move_distance));
6633 // if that fails, set current distance to reliable default value
6634 if (move_distance_current == NULL)
6635 move_distance_current =
6636 getTreeInfoFromIdentifier(move_distances,
6637 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6639 // if that also fails, set current distance to first available value
6640 if (move_distance_current == NULL)
6641 move_distance_current = move_distances;
6644 if (drop_distances == NULL)
6646 for (i = 0; distances_list[i].value != -1; i++)
6648 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6649 char identifier[32], name[32];
6650 int value = distances_list[i].value;
6651 char *text = distances_list[i].text;
6653 ti->node_top = &drop_distances;
6654 ti->sort_priority = value;
6656 sprintf(identifier, "%d", value);
6657 sprintf(name, "%s", text);
6659 setString(&ti->identifier, identifier);
6660 setString(&ti->name, name);
6661 setString(&ti->name_sorting, name);
6662 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6664 pushTreeInfo(&drop_distances, ti);
6667 // sort distance values to start with lowest distance value
6668 sortTreeInfo(&drop_distances);
6670 // set current distance value to configured distance value
6671 drop_distance_current =
6672 getTreeInfoFromIdentifier(drop_distances,
6673 i_to_a(setup.touch.drop_distance));
6675 // if that fails, set current distance to reliable default value
6676 if (drop_distance_current == NULL)
6677 drop_distance_current =
6678 getTreeInfoFromIdentifier(drop_distances,
6679 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6681 // if that also fails, set current distance to first available value
6682 if (drop_distance_current == NULL)
6683 drop_distance_current = drop_distances;
6686 if (transparencies == NULL)
6688 for (i = 0; transparencies_list[i].value != -1; i++)
6690 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6691 char identifier[32], name[32];
6692 int value = transparencies_list[i].value;
6693 char *text = transparencies_list[i].text;
6695 ti->node_top = &transparencies;
6696 ti->sort_priority = value;
6698 sprintf(identifier, "%d", value);
6699 sprintf(name, "%s", text);
6701 setString(&ti->identifier, identifier);
6702 setString(&ti->name, name);
6703 setString(&ti->name_sorting, name);
6704 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6706 pushTreeInfo(&transparencies, ti);
6709 // sort transparency values to start with lowest transparency value
6710 sortTreeInfo(&transparencies);
6712 // set current transparency value to configured transparency value
6713 transparency_current =
6714 getTreeInfoFromIdentifier(transparencies,
6715 i_to_a(setup.touch.transparency));
6717 // if that fails, set current transparency to reliable default value
6718 if (transparency_current == NULL)
6719 transparency_current =
6720 getTreeInfoFromIdentifier(transparencies,
6721 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6723 // if that also fails, set current transparency to first available value
6724 if (transparency_current == NULL)
6725 transparency_current = transparencies;
6728 for (i = 0; i < 2; i++)
6730 for (j = 0; j < 2; j++)
6732 if (grid_sizes[i][j] == NULL)
6734 for (k = 0; grid_sizes_list[k].value != -1; k++)
6736 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6737 char identifier[32], name[32];
6738 int value = grid_sizes_list[k].value;
6739 char *text = grid_sizes_list[k].text;
6741 ti->node_top = &grid_sizes[i][j];
6742 ti->sort_priority = value;
6744 sprintf(identifier, "%d", value);
6745 sprintf(name, "%s", text);
6747 setString(&ti->identifier, identifier);
6748 setString(&ti->name, name);
6749 setString(&ti->name_sorting, name);
6750 setString(&ti->infotext,
6753 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6754 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6756 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6757 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6759 pushTreeInfo(&grid_sizes[i][j], ti);
6762 // sort grid size values to start with lowest grid size value
6763 sortTreeInfo(&grid_sizes[i][j]);
6765 // set current grid size value to configured grid size value
6766 grid_size_current[i][j] =
6767 getTreeInfoFromIdentifier(grid_sizes[i][j],
6769 setup.touch.grid_xsize[i] :
6770 setup.touch.grid_ysize[i]));
6772 // if that fails, set current grid size to reliable default value
6773 if (grid_size_current[i][j] == NULL)
6774 grid_size_current[i][j] =
6775 getTreeInfoFromIdentifier(grid_sizes[i][j],
6777 DEFAULT_GRID_XSIZE(i) :
6778 DEFAULT_GRID_YSIZE(i)));
6780 // if that also fails, set current grid size to first available value
6781 if (grid_size_current[i][j] == NULL)
6782 grid_size_current[i][j] = grid_sizes[i][j];
6787 setup.touch.control_type = touch_control_current->identifier;
6788 setup.touch.move_distance = atoi(move_distance_current->identifier);
6789 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6790 setup.touch.transparency = atoi(transparency_current->identifier);
6792 for (i = 0; i < 2; i++)
6794 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6795 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6797 if (i == GRID_ACTIVE_NR())
6799 overlay.grid_xsize = setup.touch.grid_xsize[i];
6800 overlay.grid_ysize = setup.touch.grid_ysize[i];
6804 // needed for displaying value text instead of identifier
6805 touch_controls_text = touch_control_current->name;
6806 move_distance_text = move_distance_current->name;
6807 drop_distance_text = drop_distance_current->name;
6808 transparency_text = transparency_current->name;
6810 for (i = 0; i < 2; i++)
6811 for (j = 0; j < 2; j++)
6812 grid_size_text[i][j] = grid_size_current[i][j]->name;
6814 setup_mode = SETUP_MODE_TOUCH;
6819 static void execSetupArtwork(void)
6821 static ArtworkDirTree *gfx_last_valid = NULL;
6822 static ArtworkDirTree *snd_last_valid = NULL;
6823 static ArtworkDirTree *mus_last_valid = NULL;
6825 // current artwork directory may be invalid (level group, parent link)
6826 if (!validLevelSeries(artwork.gfx_current))
6827 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6828 if (!validLevelSeries(artwork.snd_current))
6829 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6830 if (!validLevelSeries(artwork.mus_current))
6831 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6833 // store valid artwork directory information
6834 gfx_last_valid = artwork.gfx_current;
6835 snd_last_valid = artwork.snd_current;
6836 mus_last_valid = artwork.mus_current;
6839 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6840 artwork.gfx_current->subdir,
6841 artwork.gfx_current->fullpath,
6842 artwork.gfx_current->basepath);
6845 setup.graphics_set = artwork.gfx_current->identifier;
6846 setup.sounds_set = artwork.snd_current->identifier;
6847 setup.music_set = artwork.mus_current->identifier;
6849 // needed if last screen (setup choice) changed graphics, sounds or music
6850 ReloadCustomArtwork(0);
6852 // needed for displaying artwork name instead of artwork identifier
6853 graphics_set_name = artwork.gfx_current->name;
6854 sounds_set_name = artwork.snd_current->name;
6855 music_set_name = artwork.mus_current->name;
6857 setup_mode = SETUP_MODE_ARTWORK;
6862 static void execSetupChooseGraphics(void)
6864 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6869 static void execSetupChooseSounds(void)
6871 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6876 static void execSetupChooseMusic(void)
6878 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6883 static void execSetupInput(void)
6885 setup_mode = SETUP_MODE_INPUT;
6890 static void execSetupShortcuts(void)
6892 setup_mode = SETUP_MODE_SHORTCUTS;
6897 static void execSetupShortcuts1(void)
6899 setup_mode = SETUP_MODE_SHORTCUTS_1;
6904 static void execSetupShortcuts2(void)
6906 setup_mode = SETUP_MODE_SHORTCUTS_2;
6911 static void execSetupShortcuts3(void)
6913 setup_mode = SETUP_MODE_SHORTCUTS_3;
6918 static void execSetupShortcuts4(void)
6920 setup_mode = SETUP_MODE_SHORTCUTS_4;
6925 static void execSetupShortcuts5(void)
6927 setup_mode = SETUP_MODE_SHORTCUTS_5;
6932 static void execExitSetup(void)
6934 SetGameStatus(GAME_MODE_MAIN);
6939 static void execSaveAndExitSetup(void)
6945 static void execGadgetNetworkServer(void)
6947 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6948 struct GadgetInfo *gi = screen_gadget[gadget_id];
6950 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6951 network_server_hostname[0] = '\0';
6953 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6957 ClickOnGadget(gi, MB_LEFTBUTTON);
6960 static void execOfferUploadTapes(void)
6965 static void ToggleNetworkModeIfNeeded(void)
6967 int font_title = FONT_TITLE_1;
6968 int font_foot = FC_BLUE;
6969 int ystart = mSY - SY + 16;
6970 int ybottom = mSY - SY + SYSIZE - 20;
6971 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6973 if (setup.network_mode == network.enabled)
6976 network.enabled = setup.network_mode;
6978 FadeOut(REDRAW_ALL);
6982 DrawTextSCentered(ystart, font_title, text);
6986 if (network.enabled)
6987 InitNetworkServer();
6989 DisconnectFromNetworkServer();
6991 DrawTextSCentered(ybottom, font_foot,
6992 "Press any key or button for setup menu");
6994 WaitForEventToContinue();
6999 static void ToggleGameSpeedsListIfNeeded(void)
7001 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7003 if (setup.game_speed_extended == using_game_speeds_extended)
7006 // try to match similar values when changing game speeds list
7007 if (setup.game_speed_extended)
7008 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7009 setup.game_frame_delay == 30 ? 29 :
7010 setup.game_frame_delay);
7012 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7013 setup.game_frame_delay == 16 ? 15 :
7014 setup.game_frame_delay >= 29 ? 30 :
7015 setup.game_frame_delay <= 10 ? 10 :
7016 setup.game_frame_delay);
7018 execSetupGame_setGameSpeeds(TRUE);
7023 static void ToggleUseApiServerIfNeeded(void)
7025 if (runtime.use_api_server == setup.use_api_server)
7028 runtime.use_api_server = setup.use_api_server;
7030 if (runtime.use_api_server)
7031 CheckApiServerTasks();
7034 static void ModifyGameSpeedIfNeeded(void)
7036 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7037 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7041 char *game_speed_text = "Fast";
7042 int game_speed_value = 15;
7044 if (setup.game_speed_extended)
7046 game_speed_text = "60 fps";
7047 game_speed_value = 16;
7050 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7052 // set game speed to existing list value that is fast enough for vsync
7053 setup.game_frame_delay = game_speed_value;
7055 execSetupGame_setGameSpeeds(TRUE);
7057 Request(message, REQ_CONFIRM);
7060 static void DisableVsyncIfNeeded(void)
7062 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7063 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7064 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7067 // disable vsync for the selected game speed to work
7068 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7070 execSetupGraphics_setVsyncModes(TRUE);
7072 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7078 void *related_value;
7079 } hide_related_entry_list[] =
7081 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7082 { &setup.scores_in_highscore_list, &scores_type_text },
7084 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7085 { &setup.game_frame_delay, &game_speed_text },
7087 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7088 { &setup.scroll_delay_value, &scroll_delay_text },
7090 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7091 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7093 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7094 { &setup.window_scaling_percent, &window_size_text },
7096 { &setup.window_scaling_quality, execSetupChooseScalingType },
7097 { &setup.window_scaling_quality, &scaling_type_text },
7099 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7100 { &setup.screen_rendering_mode, &rendering_mode_text },
7102 { &setup.vsync_mode, execSetupChooseVsyncMode },
7103 { &setup.vsync_mode, &vsync_mode_text },
7105 { &setup.graphics_set, execSetupChooseGraphics },
7106 { &setup.graphics_set, &graphics_set_name },
7108 { &setup.sounds_set, execSetupChooseSounds },
7109 { &setup.sounds_set, &sounds_set_name },
7111 { &setup.music_set, execSetupChooseMusic },
7112 { &setup.music_set, &music_set_name },
7114 { &setup.volume_simple, execSetupChooseVolumeSimple },
7115 { &setup.volume_simple, &volume_simple_text },
7117 { &setup.volume_loops, execSetupChooseVolumeLoops },
7118 { &setup.volume_loops, &volume_loops_text },
7120 { &setup.volume_music, execSetupChooseVolumeMusic },
7121 { &setup.volume_music, &volume_music_text },
7123 { &setup.touch.control_type, execSetupChooseTouchControls },
7124 { &setup.touch.control_type, &touch_controls_text },
7126 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7127 { &setup.touch.move_distance, &move_distance_text },
7129 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7130 { &setup.touch.drop_distance, &drop_distance_text },
7132 { &setup.touch.transparency, execSetupChooseTransparency },
7133 { &setup.touch.transparency, &transparency_text },
7135 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7136 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7138 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7139 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7141 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7142 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7144 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7145 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7147 { &setup.internal.menu_game, execSetupGame },
7148 { &setup.internal.menu_engines, execSetupEngines },
7149 { &setup.internal.menu_editor, execSetupEditor },
7150 { &setup.internal.menu_graphics, execSetupGraphics },
7151 { &setup.internal.menu_sound, execSetupSound },
7152 { &setup.internal.menu_artwork, execSetupArtwork },
7153 { &setup.internal.menu_input, execSetupInput },
7154 { &setup.internal.menu_touch, execSetupTouch },
7155 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7156 { &setup.internal.menu_exit, execExitSetup },
7157 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7162 void setHideRelatedSetupEntries(void)
7166 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7167 if (hideSetupEntry(hide_related_entry_list[i].value))
7168 setHideSetupEntry(hide_related_entry_list[i].related_value);
7171 static struct TokenInfo setup_info_main[] =
7173 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7174 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7175 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7176 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7177 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7178 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7179 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7180 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7181 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7182 { TYPE_EMPTY, NULL, "" },
7183 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7184 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7189 static struct TokenInfo setup_info_game[] =
7191 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7192 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7193 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7194 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7195 { TYPE_STRING, &network_server_text, "" },
7196 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7197 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7198 { TYPE_STRING, &scores_type_text, "" },
7199 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7200 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7201 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7202 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7203 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
7204 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
7205 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7206 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7207 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7208 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7209 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7210 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7211 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7212 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
7213 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7214 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7215 { TYPE_STRING, &game_speed_text, "" },
7216 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7218 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7219 { TYPE_STRING, &scroll_delay_text, "" },
7221 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7222 { TYPE_STRING, &snapshot_mode_text, "" },
7223 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7224 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7225 { TYPE_EMPTY, NULL, "" },
7226 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7231 static struct TokenInfo setup_info_engines[] =
7233 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7234 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7235 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7236 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7237 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7238 { TYPE_EMPTY, NULL, "" },
7239 { TYPE_HEADLINE, NULL, "Supaplex" },
7240 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7241 { TYPE_EMPTY, NULL, "" },
7242 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7247 static struct TokenInfo setup_info_editor[] =
7250 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7251 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7252 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7253 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7254 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7255 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7256 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7257 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7258 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7259 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7261 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7262 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7264 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7266 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7267 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7268 { TYPE_EMPTY, NULL, "" },
7270 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7271 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7272 { TYPE_EMPTY, NULL, "" },
7274 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7275 { TYPE_EMPTY, NULL, "" },
7276 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7277 { TYPE_EMPTY, NULL, "" },
7278 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7283 static struct TokenInfo setup_info_graphics[] =
7285 #if !defined(PLATFORM_ANDROID)
7286 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7287 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7288 { TYPE_STRING, &window_size_text, "" },
7289 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7290 { TYPE_STRING, &scaling_type_text, "" },
7291 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7292 { TYPE_STRING, &rendering_mode_text, "" },
7295 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7296 { TYPE_STRING, &scroll_delay_text, "" },
7298 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7299 { TYPE_STRING, &vsync_mode_text, "" },
7300 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7301 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7302 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7303 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7304 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7305 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7306 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7307 { TYPE_EMPTY, NULL, "" },
7308 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7313 static struct TokenInfo setup_info_sound[] =
7315 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7316 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7317 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7318 { TYPE_EMPTY, NULL, "" },
7319 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7320 { TYPE_STRING, &volume_simple_text, "" },
7321 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7322 { TYPE_STRING, &volume_loops_text, "" },
7323 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7324 { TYPE_STRING, &volume_music_text, "" },
7325 { TYPE_EMPTY, NULL, "" },
7326 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7331 static struct TokenInfo setup_info_artwork[] =
7333 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7334 { TYPE_STRING, &graphics_set_name, "" },
7335 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7336 { TYPE_STRING, &sounds_set_name, "" },
7337 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7338 { TYPE_STRING, &music_set_name, "" },
7339 { TYPE_EMPTY, NULL, "" },
7340 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7341 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7342 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7343 { TYPE_EMPTY, NULL, "" },
7344 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7349 static struct TokenInfo setup_info_input[] =
7351 { TYPE_SWITCH, NULL, "Player:" },
7352 { TYPE_SWITCH, NULL, "Device:" },
7353 { TYPE_SWITCH, NULL, "" },
7354 { TYPE_SKIPPABLE, NULL, "" },
7355 { TYPE_EMPTY, NULL, "" },
7356 { TYPE_EMPTY, NULL, "" },
7357 { TYPE_EMPTY, NULL, "" },
7358 { TYPE_EMPTY, NULL, "" },
7359 { TYPE_EMPTY, NULL, "" },
7360 { TYPE_EMPTY, NULL, "" },
7361 { TYPE_EMPTY, NULL, "" },
7362 { TYPE_EMPTY, NULL, "" },
7363 { TYPE_SKIPPABLE, NULL, "" },
7364 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7369 static struct TokenInfo setup_info_touch[] =
7371 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7372 { TYPE_STRING, &touch_controls_text, "" },
7373 { TYPE_EMPTY, NULL, "" },
7374 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7379 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7381 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7382 { TYPE_STRING, &touch_controls_text, "" },
7383 { TYPE_EMPTY, NULL, "" },
7384 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7385 { TYPE_STRING, &grid_size_text[0][0], "" },
7386 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7387 { TYPE_STRING, &grid_size_text[0][1], "" },
7388 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7389 { TYPE_STRING, &transparency_text, "" },
7390 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7391 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7392 { TYPE_EMPTY, NULL, "" },
7393 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7394 { TYPE_EMPTY, NULL, "" },
7395 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7400 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7402 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7403 { TYPE_STRING, &touch_controls_text, "" },
7404 { TYPE_EMPTY, NULL, "" },
7405 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7406 { TYPE_STRING, &grid_size_text[1][0], "" },
7407 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7408 { TYPE_STRING, &grid_size_text[1][1], "" },
7409 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7410 { TYPE_STRING, &transparency_text, "" },
7411 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7412 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7413 { TYPE_EMPTY, NULL, "" },
7414 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7415 { TYPE_EMPTY, NULL, "" },
7416 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7421 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7423 setup_info_touch_virtual_buttons_0,
7424 setup_info_touch_virtual_buttons_1
7427 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7429 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7430 { TYPE_STRING, &touch_controls_text, "" },
7431 { TYPE_EMPTY, NULL, "" },
7432 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7433 { TYPE_STRING, &move_distance_text, "" },
7434 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7435 { TYPE_STRING, &drop_distance_text, "" },
7436 { TYPE_EMPTY, NULL, "" },
7437 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7442 static struct TokenInfo setup_info_shortcuts[] =
7444 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7445 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7446 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7447 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7448 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7449 { TYPE_EMPTY, NULL, "" },
7450 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7455 static struct TokenInfo setup_info_shortcuts_1[] =
7457 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7458 { TYPE_KEY, &setup.shortcut.save_game, "" },
7459 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7460 { TYPE_KEY, &setup.shortcut.load_game, "" },
7461 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7462 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7463 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7464 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7465 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7466 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7467 { TYPE_EMPTY, NULL, "" },
7468 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7469 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7470 { TYPE_EMPTY, NULL, "" },
7471 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7476 static struct TokenInfo setup_info_shortcuts_2[] =
7478 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7479 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7480 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7481 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7482 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7483 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7484 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7485 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7486 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7487 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7488 { TYPE_EMPTY, NULL, "" },
7489 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7494 static struct TokenInfo setup_info_shortcuts_3[] =
7496 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7497 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7498 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7499 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7500 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7501 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7502 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7503 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7504 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7505 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7506 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7507 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7508 { TYPE_EMPTY, NULL, "" },
7509 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7514 static struct TokenInfo setup_info_shortcuts_4[] =
7516 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7517 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7518 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7519 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7520 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7521 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7522 { TYPE_EMPTY, NULL, "" },
7523 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7528 static struct TokenInfo setup_info_shortcuts_5[] =
7530 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7531 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7532 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7533 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7534 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7535 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7536 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7537 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7538 { TYPE_EMPTY, NULL, "" },
7539 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7544 static Key getSetupKey(void)
7546 Key key = KSYM_UNDEFINED;
7547 boolean got_key_event = FALSE;
7549 while (!got_key_event)
7553 if (NextValidEvent(&event))
7557 case EVENT_KEYPRESS:
7559 key = GetEventKey((KeyEvent *)&event, TRUE);
7561 // press 'Escape' or 'Enter' to keep the existing key binding
7562 if (key == KSYM_Escape || key == KSYM_Return)
7563 key = KSYM_UNDEFINED; // keep old value
7565 got_key_event = TRUE;
7569 case EVENT_KEYRELEASE:
7570 key_joystick_mapping = 0;
7574 HandleOtherEvents(&event);
7585 static int getSetupValueFont(int type, void *value)
7587 if (type & TYPE_GHOSTED)
7588 return FONT_OPTION_OFF;
7589 else if (type & TYPE_KEY)
7590 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7591 else if (type & TYPE_STRING)
7592 return FONT_VALUE_2;
7593 else if (type & TYPE_ECS_AGA)
7594 return FONT_VALUE_1;
7595 else if (type & TYPE_BOOLEAN_STYLE)
7596 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7597 else if (type & TYPE_YES_NO_AUTO)
7598 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7599 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7600 else if (type & TYPE_PLAYER)
7601 return FONT_VALUE_1;
7603 return FONT_VALUE_1;
7606 static int getSetupValueFontNarrow(int type, int font_nr)
7608 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7609 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7610 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7614 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7616 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7617 struct TokenInfo *si = &setup_info[si_pos];
7618 boolean font_draw_xoffset_modified = FALSE;
7619 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7620 int font_draw_xoffset_old = -1;
7621 int xoffset = (scrollbar_needed ? -1 : 0);
7622 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7623 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7624 int xpos = menu_screen_value_xpos;
7625 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7626 int startx = mSX + xpos * 32;
7627 int starty = mSY + ypos * 32;
7628 int type = si->type;
7629 void *value = si->value;
7630 char *value_string = getSetupValue(type, value);
7631 int font_nr_default = getSetupValueFont(type, value);
7632 int font_width_default = getFontWidth(font_nr_default);
7633 int font_nr = font_nr_default;
7636 if (value_string == NULL)
7639 if (type & TYPE_KEY)
7641 xpos = MENU_SCREEN_START_XPOS;
7643 if (type & TYPE_QUERY)
7644 value_string = "<press key>";
7646 else if (type & TYPE_STRING)
7648 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7650 xpos = MENU_SCREEN_START_XPOS;
7652 if (strlen(value_string) > max_value_len)
7653 value_string[max_value_len] = '\0';
7655 else if (type & TYPE_YES_NO_AUTO)
7657 xpos = menu_screen_value_xpos - 1;
7659 else if (type & TYPE_PLAYER)
7661 int displayed_player_nr = *(int *)value + 1;
7663 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7666 startx = mSX + xpos * 32;
7667 starty = mSY + ypos * 32;
7669 // special check if right-side setup values moved left due to scrollbar
7670 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7672 int max_menu_text_length = 26; // maximum text length for classic menu
7673 int font_xoffset = getFontDrawOffsetX(font_nr);
7674 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7675 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7676 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7677 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7679 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7681 // when using narrow font, left-shifting text "auto" not needed
7682 if (type & TYPE_YES_NO_AUTO)
7686 startx = mSX + xpos * 32;
7688 font_nr = getSetupValueFontNarrow(type, font_nr);
7692 // downward compatibility correction for Juergen Bonhagen's menu settings
7693 if (setup_mode != SETUP_MODE_INPUT)
7695 int max_menu_text_length_big = (menu_screen_value_xpos -
7696 MENU_SCREEN_START_XPOS);
7697 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7698 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7699 int font1_xoffset = getFontDrawOffsetX(font_nr);
7700 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7701 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7702 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7703 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7704 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7705 boolean correct_font_draw_xoffset = FALSE;
7707 if (xpos == MENU_SCREEN_START_XPOS &&
7708 startx + font1_xoffset < text_startx + text_font_xoffset)
7709 correct_font_draw_xoffset = TRUE;
7711 if (xpos == menu_screen_value_xpos &&
7712 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7713 correct_font_draw_xoffset = TRUE;
7715 // check if setup value would overlap with setup text when printed
7716 // (this can happen for extreme/wrong values for font draw offset)
7717 if (correct_font_draw_xoffset)
7719 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7720 font_draw_xoffset_modified = TRUE;
7722 if (type & TYPE_KEY)
7723 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7724 else if (!(type & TYPE_STRING))
7725 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7726 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7730 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7731 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7733 DrawText(startx, starty, value_string, font_nr);
7735 if (type & TYPE_PLAYER)
7737 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7738 int player_nr = *(int *)value;
7739 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7740 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7741 int startx2 = startx + xoff;
7742 int starty2 = starty + yoff;
7744 if (DrawingOnBackground(startx2, starty2))
7745 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7747 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7748 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7751 if (font_draw_xoffset_modified)
7752 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7755 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7757 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7758 struct TokenInfo *si = &setup_info[si_pos];
7760 if (si->type & TYPE_BOOLEAN_STYLE)
7762 *(boolean *)si->value ^= TRUE;
7764 else if (si->type & TYPE_YES_NO_AUTO)
7768 (*(int *)si->value == AUTO ? TRUE :
7769 *(int *)si->value == TRUE ? FALSE : AUTO) :
7770 (*(int *)si->value == TRUE ? AUTO :
7771 *(int *)si->value == AUTO ? FALSE : TRUE));
7773 else if (si->type & TYPE_KEY)
7777 si->type |= TYPE_QUERY;
7778 drawSetupValue(screen_pos, setup_info_pos_raw);
7779 si->type &= ~TYPE_QUERY;
7781 key = getSetupKey();
7782 if (key != KSYM_UNDEFINED)
7783 *(Key *)si->value = key;
7785 else if (si->type & TYPE_PLAYER)
7787 int player_nr = *(int *)si->value;
7792 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7794 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7797 drawSetupValue(screen_pos, setup_info_pos_raw);
7799 // fullscreen state may have changed at this point
7800 if (si->value == &setup.fullscreen)
7801 ToggleFullscreenIfNeeded();
7803 // network mode may have changed at this point
7804 if (si->value == &setup.network_mode)
7805 ToggleNetworkModeIfNeeded();
7807 // API server mode may have changed at this point
7808 if (si->value == &setup.use_api_server)
7809 ToggleUseApiServerIfNeeded();
7811 // game speed list may have changed at this point
7812 if (si->value == &setup.game_speed_extended)
7813 ToggleGameSpeedsListIfNeeded();
7816 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7818 static struct TokenInfo *setup_info_final = NULL;
7823 // determine maximum list size of target list
7824 while (setup_info_orig[list_size++].type != 0);
7826 // free, allocate and clear memory for target list
7827 checked_free(setup_info_final);
7828 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7830 // copy setup info list without setup entries marked as hidden
7831 for (i = 0; setup_info_orig[i].type != 0; i++)
7833 // skip setup entries configured to be hidden
7834 if (hideSetupEntry(setup_info_orig[i].value))
7837 // skip skippable setup entries if screen is lower than usual
7838 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7839 setup_info_orig[i].type == TYPE_SKIPPABLE)
7842 setup_info_final[list_pos++] = setup_info_orig[i];
7845 return setup_info_final;
7848 static void DrawSetupScreen_Generic(void)
7850 int fade_mask = REDRAW_FIELD;
7851 boolean redraw_all = FALSE;
7852 char *title_string = NULL;
7856 fade_mask = REDRAW_ALL;
7859 FadeMenuSoundsAndMusic();
7861 FreeScreenGadgets();
7862 CreateScreenGadgets();
7864 if (redraw_mask & REDRAW_ALL)
7869 // needed if different viewport properties defined for setup screen
7870 ChangeViewportPropertiesIfNeeded();
7872 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7876 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7878 if (setup_mode == SETUP_MODE_MAIN)
7880 setup_info = setup_info_main;
7881 title_string = STR_SETUP_MAIN;
7883 else if (setup_mode == SETUP_MODE_GAME)
7885 setup_info = setup_info_game;
7886 title_string = STR_SETUP_GAME;
7888 else if (setup_mode == SETUP_MODE_ENGINES)
7890 setup_info = setup_info_engines;
7891 title_string = STR_SETUP_ENGINES;
7893 else if (setup_mode == SETUP_MODE_EDITOR)
7895 setup_info = setup_info_editor;
7896 title_string = STR_SETUP_EDITOR;
7898 else if (setup_mode == SETUP_MODE_GRAPHICS)
7900 setup_info = setup_info_graphics;
7901 title_string = STR_SETUP_GRAPHICS;
7903 else if (setup_mode == SETUP_MODE_SOUND)
7905 setup_info = setup_info_sound;
7906 title_string = STR_SETUP_SOUND;
7908 else if (setup_mode == SETUP_MODE_ARTWORK)
7910 setup_info = setup_info_artwork;
7911 title_string = STR_SETUP_ARTWORK;
7913 else if (setup_mode == SETUP_MODE_TOUCH)
7915 setup_info = setup_info_touch;
7916 title_string = STR_SETUP_TOUCH;
7918 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7919 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7920 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7921 setup_info = setup_info_touch_wipe_gestures;
7923 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7925 setup_info = setup_info_shortcuts;
7926 title_string = STR_SETUP_SHORTCUTS;
7928 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7930 setup_info = setup_info_shortcuts_1;
7931 title_string = STR_SETUP_SHORTCUTS;
7933 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7935 setup_info = setup_info_shortcuts_2;
7936 title_string = STR_SETUP_SHORTCUTS;
7938 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7940 setup_info = setup_info_shortcuts_3;
7941 title_string = STR_SETUP_SHORTCUTS;
7943 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7945 setup_info = setup_info_shortcuts_4;
7946 title_string = STR_SETUP_SHORTCUTS;
7948 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7950 setup_info = setup_info_shortcuts_5;
7951 title_string = STR_SETUP_SHORTCUTS;
7954 // use modified setup info without setup entries marked as hidden
7955 setup_info = getSetupInfoFinal(setup_info);
7957 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7959 // determine maximal number of setup entries that can be displayed on screen
7961 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7964 // determine maximal number of setup entries available for this setup screen
7966 for (i = 0; setup_info[i].type != 0; i++)
7969 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7971 MapScreenGadgets(max_setup_info);
7974 redraw_mask = fade_mask = REDRAW_ALL;
7976 DrawMaskedBorder(fade_mask);
7981 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7983 menu_info = setup_info;
7985 HandleMenuScreen(mx, my, dx, dy, button,
7986 setup_mode, num_setup_info, max_setup_info);
7989 static void DrawSetupScreen_Input(void)
7993 FadeOut(REDRAW_FIELD);
7997 setup_info = getSetupInfoFinal(setup_info_input);
7999 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8001 for (i = 0; setup_info[i].type != 0; i++)
8003 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8004 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8005 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8006 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8007 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8008 initCursor(i, IMG_MENU_BUTTON);
8010 DrawCursorAndText_Setup(i, -1, FALSE);
8013 // create gadgets for setup input menu screen
8014 FreeScreenGadgets();
8015 CreateScreenGadgets();
8017 // map gadgets for setup input menu screen
8018 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8020 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8022 FadeIn(REDRAW_FIELD);
8025 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8027 if (device_name == NULL)
8030 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8033 if (strlen(device_name) > 1)
8035 char c1 = device_name[strlen(device_name) - 1];
8036 char c2 = device_name[strlen(device_name) - 2];
8038 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8039 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8042 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8043 strlen(device_name));
8046 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8049 static struct SetupKeyboardInfo custom_key;
8056 { &custom_key.left, "Axis/Pad Left" },
8057 { &custom_key.right, "Axis/Pad Right" },
8058 { &custom_key.up, "Axis/Pad Up" },
8059 { &custom_key.down, "Axis/Pad Down" },
8060 { &custom_key.snap, "Button 1/A/X" },
8061 { &custom_key.drop, "Button 2/B/Y" }
8063 static char *joystick_name[MAX_PLAYERS] =
8070 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8071 int font_nr_info = FONT_MENU_1;
8072 int font_nr_name = FONT_VALUE_OLD;
8073 int font_nr_on = FONT_VALUE_1;
8074 int font_nr_off = FONT_VALUE_OLD;
8077 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8079 font_nr_info = FONT_MENU_2;
8080 font_nr_on = FONT_VALUE_NARROW;
8081 font_nr_off = FONT_VALUE_OLD_NARROW;
8084 custom_key = setup.input[player_nr].key;
8086 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8087 FONT_INPUT_1_ACTIVE);
8089 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8091 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8092 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8094 if (setup.input[player_nr].use_joystick)
8096 char *device_name = setup.input[player_nr].joy.device_name;
8097 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8098 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8099 char *text = joystick_name[joystick_nr];
8100 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8102 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8103 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8107 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8108 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8111 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8112 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8116 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8117 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8118 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8119 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8121 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8122 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8123 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8124 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8125 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8126 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8128 for (i = 0; i < 6; i++)
8130 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8132 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8134 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8135 (setup.input[player_nr].use_joystick ?
8137 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8141 static int input_player_nr = 0;
8143 static void HandleSetupScreen_Input_Player(int step, int direction)
8145 int old_player_nr = input_player_nr;
8148 new_player_nr = old_player_nr + step * direction;
8149 if (new_player_nr < 0)
8151 if (new_player_nr > MAX_PLAYERS - 1)
8152 new_player_nr = MAX_PLAYERS - 1;
8154 if (new_player_nr != old_player_nr)
8156 input_player_nr = new_player_nr;
8158 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8162 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8164 static int choice = 0;
8167 int pos_start = SETUPINPUT_SCREEN_POS_START;
8168 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8169 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8170 int pos_end = SETUPINPUT_SCREEN_POS_END;
8172 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8176 for (i = 0; setup_info_input[i].type != 0; i++)
8178 // adjust menu structure according to skipped setup entries
8179 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8187 if (button == MB_MENU_INITIALIZE)
8189 // input setup menu may have changed size due to graphics configuration
8190 if (choice >= pos_empty1)
8193 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8195 DrawCursorAndText_Setup(choice, -1, TRUE);
8199 else if (button == MB_MENU_LEAVE)
8201 setup_mode = SETUP_MODE_MAIN;
8208 if (mx || my) // mouse input
8210 x = (mx - mSX) / 32;
8211 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8213 else if (dx || dy) // keyboard input
8215 if (dx && choice == 0)
8216 x = (dx < 0 ? 10 : 12);
8217 else if ((dx && choice == 1) ||
8218 (dx == -1 && choice == pos_end))
8219 button = MB_MENU_CHOICE;
8223 if (y >= pos_empty1 && y <= pos_empty2)
8224 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8227 if (y == 0 && dx != 0 && button)
8229 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8231 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8232 y >= pos_start && y <= pos_end &&
8233 !(y >= pos_empty1 && y <= pos_empty2))
8239 DrawCursorAndText_Setup(choice, -1, FALSE);
8240 DrawCursorAndText_Setup(y, -1, TRUE);
8242 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8251 char *device_name = setup.input[input_player_nr].joy.device_name;
8253 if (!setup.input[input_player_nr].use_joystick)
8255 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8257 setJoystickDeviceToNr(device_name, new_device_nr);
8258 setup.input[input_player_nr].use_joystick = TRUE;
8262 int device_nr = getJoystickNrFromDeviceName(device_name);
8263 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8265 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8266 setup.input[input_player_nr].use_joystick = FALSE;
8268 setJoystickDeviceToNr(device_name, new_device_nr);
8271 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8275 if (setup.input[input_player_nr].use_joystick)
8276 ConfigureJoystick(input_player_nr);
8278 CustomizeKeyboard(input_player_nr);
8280 else if (y == pos_end)
8286 setup_mode = SETUP_MODE_MAIN;
8293 static boolean CustomizeKeyboardMain(int player_nr)
8297 boolean finished = FALSE;
8298 static struct SetupKeyboardInfo custom_key;
8303 } customize_step[] =
8305 { &custom_key.left, "Move Left" },
8306 { &custom_key.right, "Move Right" },
8307 { &custom_key.up, "Move Up" },
8308 { &custom_key.down, "Move Down" },
8309 { &custom_key.snap, "Snap Field" },
8310 { &custom_key.drop, "Drop Element" }
8312 int font_nr_old = FONT_VALUE_OLD;
8313 int font_nr_new = FONT_VALUE_1;
8314 boolean success = FALSE;
8316 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8318 font_nr_old = FONT_VALUE_OLD_NARROW;
8319 font_nr_new = FONT_VALUE_NARROW;
8322 // read existing key bindings from player setup
8323 custom_key = setup.input[player_nr].key;
8326 FadeOut(REDRAW_FIELD);
8330 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8333 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8334 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8335 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8336 "Key:", FONT_INPUT_1_ACTIVE);
8337 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8338 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8340 FadeIn(REDRAW_FIELD);
8346 if (NextValidEvent(&event))
8350 case EVENT_KEYPRESS:
8352 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8354 // press 'Escape' to abort and keep the old key bindings
8355 if (key == KSYM_Escape)
8357 FadeSkipNextFadeIn();
8364 // press 'Enter' to keep the existing key binding
8365 if (key == KSYM_Return)
8366 key = *customize_step[step_nr].key;
8368 // check if key already used
8369 for (i = 0; i < step_nr; i++)
8370 if (*customize_step[i].key == key)
8375 // got new key binding
8376 *customize_step[step_nr].key = key;
8377 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8379 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8380 getKeyNameFromKey(key), font_nr_new);
8383 // un-highlight last query
8384 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8385 customize_step[step_nr - 1].text, FONT_MENU_1);
8386 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8387 "Key:", FONT_MENU_1);
8389 // all keys configured
8398 // query next key binding
8399 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8400 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8401 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8402 "Key:", FONT_INPUT_1_ACTIVE);
8403 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8404 getKeyNameFromKey(*customize_step[step_nr].key),
8409 case EVENT_KEYRELEASE:
8410 key_joystick_mapping = 0;
8414 HandleOtherEvents(&event);
8422 // write new key bindings back to player setup, if successfully finished
8424 setup.input[player_nr].key = custom_key;
8429 void CustomizeKeyboard(int player_nr)
8431 boolean success = CustomizeKeyboardMain(player_nr);
8435 int font_nr = FONT_TITLE_1;
8436 int font_height = getFontHeight(font_nr);
8437 int ypos1 = SYSIZE / 2 - font_height * 2;
8438 int ypos2 = SYSIZE / 2 - font_height * 1;
8439 unsigned int wait_frame_delay = 0;
8440 unsigned int wait_frame_delay_value = 2000;
8442 ResetDelayCounter(&wait_frame_delay);
8446 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8447 DrawTextSCentered(ypos2, font_nr, "configured!");
8449 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8455 DrawSetupScreen_Input();
8458 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8460 #define MARKER_BUTTON 1
8461 #define MARKER_AXIS_X 2
8462 #define MARKER_AXIS_Y 3
8464 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8466 static boolean bitmaps_initialized = FALSE;
8467 boolean screen_initialized = FALSE;
8468 static Bitmap *controller, *button, *axis_x, *axis_y;
8470 boolean success = TRUE;
8471 boolean done = FALSE, next = FALSE;
8473 int alpha = 200, alpha_step = -1;
8474 int alpha_ticks = 0;
8475 char mapping[4096], temp[256];
8476 int font_name = MENU_SETUP_FONT_TITLE;
8477 int font_info = MENU_SETUP_FONT_TEXT;
8478 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8479 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8480 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8481 int ystep_name = getMenuTextStep(spacing_name, font_name);
8482 int ystep_line = getMenuTextStep(spacing_line, font_info);
8483 int ystep_para = getMenuTextStep(spacing_para, font_info);
8491 int axis, button, hat, hat_value;
8494 *step, *prev_step, steps[] =
8496 { 356, 155, MARKER_BUTTON, "a", },
8497 { 396, 122, MARKER_BUTTON, "b", },
8498 { 320, 125, MARKER_BUTTON, "x", },
8499 { 358, 95, MARKER_BUTTON, "y", },
8500 { 162, 125, MARKER_BUTTON, "back", },
8501 { 216, 125, MARKER_BUTTON, "guide", },
8502 { 271, 125, MARKER_BUTTON, "start", },
8503 { 110, 200, MARKER_BUTTON, "dpleft", },
8504 { 146, 228, MARKER_BUTTON, "dpdown", },
8505 { 178, 200, MARKER_BUTTON, "dpright", },
8506 { 146, 172, MARKER_BUTTON, "dpup", },
8507 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8508 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8509 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8510 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8511 { 73, 141, MARKER_BUTTON, "leftstick", },
8512 { 282, 210, MARKER_BUTTON, "rightstick", },
8513 { 73, 141, MARKER_AXIS_X, "leftx", },
8514 { 73, 141, MARKER_AXIS_Y, "lefty", },
8515 { 282, 210, MARKER_AXIS_X, "rightx", },
8516 { 282, 210, MARKER_AXIS_Y, "righty", },
8519 unsigned int event_frame_delay = 0;
8520 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
8522 ResetDelayCounter(&event_frame_delay);
8524 if (!bitmaps_initialized)
8526 controller = LoadCustomImage("joystick/controller.png");
8527 button = LoadCustomImage("joystick/button.png");
8528 axis_x = LoadCustomImage("joystick/axis_x.png");
8529 axis_y = LoadCustomImage("joystick/axis_y.png");
8531 bitmaps_initialized = TRUE;
8534 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8537 // print info about the joystick we are watching
8538 Debug("joystick", "watching joystick %d: (%s)",
8539 SDL_JoystickInstanceID(joystick), name);
8540 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8541 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8542 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8545 // initialize mapping with GUID and name
8546 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8548 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8549 temp, name, SDL_GetPlatform());
8551 // loop through all steps (buttons and axes), getting joystick events
8552 for (i = 0; i < SDL_arraysize(steps) && !done;)
8554 Bitmap *marker = button; // initialize with reliable default value
8557 strcpy(step->mapping, mapping);
8561 step->hat_value = -1;
8563 marker = (step->marker == MARKER_BUTTON ? button :
8564 step->marker == MARKER_AXIS_X ? axis_x :
8565 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8569 while (!done && !next)
8571 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8572 alpha_ticks = SDL_GetTicks();
8579 else if (alpha < 128)
8585 int controller_x = SX + (SXSIZE - controller->width) / 2;
8586 int controller_y = SY + ystep_line;
8588 int marker_x = controller_x + step->x;
8589 int marker_y = controller_y + step->y;
8591 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8592 int ystart2 = ystart1 + ystep_name + ystep_line;
8596 DrawTextSCentered(ystart1, font_name, name);
8598 DrawTextSCentered(ystart2, font_info,
8599 "Press buttons and move axes on");
8600 ystart2 += ystep_line;
8601 DrawTextSCentered(ystart2, font_info,
8602 "your controller when indicated.");
8603 ystart2 += ystep_line;
8604 DrawTextSCentered(ystart2, font_info,
8605 "(Your controller may look different.)");
8606 ystart2 += ystep_para;
8608 #if defined(PLATFORM_ANDROID)
8609 DrawTextSCentered(ystart2, font_info,
8610 "To correct a mistake,");
8611 ystart2 += ystep_line;
8612 DrawTextSCentered(ystart2, font_info,
8613 "press the 'back' button.");
8614 ystart2 += ystep_line;
8615 DrawTextSCentered(ystart2, font_info,
8616 "To skip a button or axis,");
8617 ystart2 += ystep_line;
8618 DrawTextSCentered(ystart2, font_info,
8619 "press the 'menu' button.");
8621 DrawTextSCentered(ystart2, font_info,
8622 "To correct a mistake,");
8623 ystart2 += ystep_line;
8624 DrawTextSCentered(ystart2, font_info,
8625 "press the 'backspace' key.");
8626 ystart2 += ystep_line;
8627 DrawTextSCentered(ystart2, font_info,
8628 "To skip a button or axis,");
8629 ystart2 += ystep_line;
8630 DrawTextSCentered(ystart2, font_info,
8631 "press the 'return' key.");
8632 ystart2 += ystep_line;
8633 DrawTextSCentered(ystart2, font_info,
8634 "To exit, press the 'escape' key.");
8637 BlitBitmapMasked(controller, drawto, 0, 0,
8638 controller->width, controller->height,
8639 controller_x, controller_y);
8641 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8642 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8644 BlitBitmapMasked(marker, drawto, 0, 0,
8645 marker->width, marker->height,
8646 marker_x, marker_y);
8648 if (!screen_initialized)
8649 FadeIn(REDRAW_FIELD);
8653 screen_initialized = TRUE;
8655 while (NextValidEvent(&event))
8659 case SDL_JOYAXISMOTION:
8660 if (event.jaxis.value > 20000 ||
8661 event.jaxis.value < -20000)
8663 for (j = 0; j < i; j++)
8664 if (steps[j].axis == event.jaxis.axis)
8669 if (step->marker != MARKER_AXIS_X &&
8670 step->marker != MARKER_AXIS_Y)
8673 step->axis = event.jaxis.axis;
8674 strcat(mapping, step->field);
8675 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8676 strcat(mapping, temp);
8684 case SDL_JOYHATMOTION:
8685 // ignore centering; we're probably just coming back
8686 // to the center from the previous item we set
8687 if (event.jhat.value == SDL_HAT_CENTERED)
8690 for (j = 0; j < i; j++)
8691 if (steps[j].hat == event.jhat.hat &&
8692 steps[j].hat_value == event.jhat.value)
8697 step->hat = event.jhat.hat;
8698 step->hat_value = event.jhat.value;
8699 strcat(mapping, step->field);
8700 snprintf(temp, sizeof(temp), ":h%u.%u,",
8701 event.jhat.hat, event.jhat.value );
8702 strcat(mapping, temp);
8709 case SDL_JOYBALLMOTION:
8712 case SDL_JOYBUTTONUP:
8713 for (j = 0; j < i; j++)
8714 if (steps[j].button == event.jbutton.button)
8719 step->button = event.jbutton.button;
8720 strcat(mapping, step->field);
8721 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8722 strcat(mapping, temp);
8729 case SDL_FINGERDOWN:
8730 case SDL_MOUSEBUTTONDOWN:
8738 if (event.key.keysym.sym == KSYM_BackSpace ||
8739 event.key.keysym.sym == KSYM_Back)
8751 prev_step = &steps[i - 1];
8752 strcpy(mapping, prev_step->mapping);
8759 if (event.key.keysym.sym == KSYM_space ||
8760 event.key.keysym.sym == KSYM_Return ||
8761 event.key.keysym.sym == KSYM_Menu)
8770 if (event.key.keysym.sym == KSYM_Escape)
8780 program.exit_function(0);
8787 // do not handle events for longer than standard frame delay period
8788 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8797 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8800 // activate mapping for this game
8801 SDL_GameControllerAddMapping(mapping);
8803 // save mapping to personal mappings
8804 SaveSetup_AddGameControllerMapping(mapping);
8807 // wait until the last pending event was removed from event queue
8808 while (NextValidEvent(&event));
8813 static int ConfigureJoystickMain(int player_nr)
8815 char *device_name = setup.input[player_nr].joy.device_name;
8816 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8817 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8818 int success = FALSE;
8821 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8822 return JOYSTICK_NOT_AVAILABLE;
8824 if (!joystick_active || !setup.input[player_nr].use_joystick)
8825 return JOYSTICK_NOT_AVAILABLE;
8828 FadeOut(REDRAW_FIELD);
8830 // close all joystick devices (potentially opened as game controllers)
8831 for (i = 0; i < SDL_NumJoysticks(); i++)
8832 SDLCloseJoystick(i);
8834 // open joystick device as plain joystick to configure as game controller
8835 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8837 // as the joystick was successfully opened before, this should not happen
8838 if (joystick == NULL)
8841 // create new game controller mapping (buttons and axes) for joystick device
8842 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8844 // close joystick (and maybe re-open as configured game controller later)
8845 SDL_JoystickClose(joystick);
8847 // re-open all joystick devices (potentially as game controllers)
8848 for (i = 0; i < SDL_NumJoysticks(); i++)
8851 // clear all joystick input actions for all joystick devices
8852 SDLClearJoystickState();
8854 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8857 void ConfigureJoystick(int player_nr)
8859 boolean state = ConfigureJoystickMain(player_nr);
8861 if (state != JOYSTICK_NOT_CONFIGURED)
8863 boolean success = (state == JOYSTICK_CONFIGURED);
8864 char message1[MAX_OUTPUT_LINESIZE + 1];
8865 char *message2 = (success ? "configured!" : "not available!");
8866 char *device_name = setup.input[player_nr].joy.device_name;
8867 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8868 int font_nr = FONT_TITLE_1;
8869 int font_height = getFontHeight(font_nr);
8870 int ypos1 = SYSIZE / 2 - font_height * 2;
8871 int ypos2 = SYSIZE / 2 - font_height * 1;
8872 unsigned int wait_frame_delay = 0;
8873 unsigned int wait_frame_delay_value = 2000;
8875 ResetDelayCounter(&wait_frame_delay);
8879 sprintf(message1, "Joystick %d", nr);
8881 DrawTextSCentered(ypos1, font_nr, message1);
8882 DrawTextSCentered(ypos2, font_nr, message2);
8884 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8890 DrawSetupScreen_Input();
8893 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8895 if (y < video.screen_height / 3)
8897 // remap touch gadgets to access upper part of the screen
8898 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8899 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8901 else if (y > 2 * video.screen_height / 3)
8903 // remap touch gadgets to access lower part of the screen
8904 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8905 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8909 static boolean ConfigureVirtualButtonsMain(void)
8911 static char *customize_step_text[] =
8920 char grid_button[] =
8922 CHAR_GRID_BUTTON_LEFT,
8923 CHAR_GRID_BUTTON_RIGHT,
8924 CHAR_GRID_BUTTON_UP,
8925 CHAR_GRID_BUTTON_DOWN,
8926 CHAR_GRID_BUTTON_SNAP,
8927 CHAR_GRID_BUTTON_DROP
8936 int font_nr = FONT_INPUT_1_ACTIVE;
8937 int font_height = getFontHeight(font_nr);
8938 int ypos1 = SYSIZE / 2 - font_height * 2;
8939 int ypos2 = SYSIZE / 2 - font_height * 1;
8940 boolean success = FALSE;
8941 boolean finished = FALSE;
8943 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8944 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8945 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8946 boolean set_grid_button = FALSE;
8947 int nr = GRID_ACTIVE_NR();
8950 for (x = 0; x < MAX_GRID_XSIZE; x++)
8951 for (y = 0; y < MAX_GRID_YSIZE; y++)
8952 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8954 overlay.grid_button_highlight = grid_button[step_nr];
8959 FadeOut(REDRAW_FIELD);
8963 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8964 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8965 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8967 FadeIn(REDRAW_FIELD);
8969 SetOverlayShowGrid(TRUE);
8971 // map gadgets for setup touch buttons menu screen
8972 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8978 while (NextValidEvent(&event))
8980 int action = ACTION_NONE;
8982 // ---------- handle events and set the resulting action ----------
8988 UserEvent *user = (UserEvent *)&event;
8989 int id = user->value1;
8991 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8992 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8993 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8994 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8999 case EVENT_KEYPRESS:
9001 Key key = GetEventKey((KeyEvent *)&event, FALSE);
9003 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9004 key == KSYM_BackSpace ||
9005 key == KSYM_Back ? ACTION_BACK :
9006 key == KSYM_Return ||
9008 key == KSYM_space ? ACTION_NEXT :
9013 case EVENT_KEYRELEASE:
9014 key_joystick_mapping = 0;
9017 case EVENT_BUTTONPRESS:
9018 case EVENT_BUTTONRELEASE:
9020 ButtonEvent *button = (ButtonEvent *)&event;
9022 motion_status = FALSE;
9024 if (button->type == EVENT_BUTTONPRESS)
9025 button_status = button->button;
9027 button_status = MB_RELEASED;
9029 if (HandleGadgets(button->x, button->y, button_status))
9031 // do not handle this button event anymore
9035 button->x += video.screen_xoffset;
9036 button->y += video.screen_yoffset;
9038 x = button->x * overlay.grid_xsize / video.screen_width;
9039 y = button->y * overlay.grid_ysize / video.screen_height;
9041 if (button->type == EVENT_BUTTONPRESS)
9044 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9045 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9047 set_grid_button = TRUE;
9050 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9054 case EVENT_MOTIONNOTIFY:
9056 MotionEvent *motion = (MotionEvent *)&event;
9058 motion_status = TRUE;
9060 if (HandleGadgets(motion->x, motion->y, button_status))
9062 // do not handle this button event anymore
9066 motion->x += video.screen_xoffset;
9067 motion->y += video.screen_yoffset;
9069 x = motion->x * overlay.grid_xsize / video.screen_width;
9070 y = motion->y * overlay.grid_ysize / video.screen_height;
9072 set_grid_button = TRUE;
9074 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9078 case SDL_WINDOWEVENT:
9079 HandleWindowEvent((WindowEvent *) &event);
9081 // check if device has been rotated
9082 if (nr != GRID_ACTIVE_NR())
9084 nr = GRID_ACTIVE_NR();
9086 for (x = 0; x < MAX_GRID_XSIZE; x++)
9087 for (y = 0; y < MAX_GRID_YSIZE; y++)
9088 grid_button_old[x][y] = grid_button_tmp[x][y] =
9089 overlay.grid_button[x][y];
9094 case SDL_APP_WILLENTERBACKGROUND:
9095 case SDL_APP_DIDENTERBACKGROUND:
9096 case SDL_APP_WILLENTERFOREGROUND:
9097 case SDL_APP_DIDENTERFOREGROUND:
9098 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9102 HandleOtherEvents(&event);
9106 // ---------- perform action set by handling events ----------
9108 if (action == ACTION_ESCAPE)
9110 // abort and restore the old key bindings
9112 for (x = 0; x < MAX_GRID_XSIZE; x++)
9113 for (y = 0; y < MAX_GRID_YSIZE; y++)
9114 overlay.grid_button[x][y] = grid_button_old[x][y];
9116 FadeSkipNextFadeIn();
9120 else if (action == ACTION_BACK)
9122 // keep the configured key bindings and go to previous page
9128 FadeSkipNextFadeIn();
9133 else if (action == ACTION_NEXT)
9135 // keep the configured key bindings and go to next page
9139 // all virtual buttons configured
9147 if (action != ACTION_NONE && !finished)
9149 for (x = 0; x < MAX_GRID_XSIZE; x++)
9150 for (y = 0; y < MAX_GRID_YSIZE; y++)
9151 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9153 overlay.grid_button_highlight = grid_button[step_nr];
9155 // configure next virtual button
9159 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9160 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9161 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9164 if (set_grid_button)
9166 overlay.grid_button[x][y] =
9167 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9168 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9169 grid_button_tmp[x][y]);
9171 set_grid_button = FALSE;
9178 for (x = 0; x < MAX_GRID_XSIZE; x++)
9179 for (y = 0; y < MAX_GRID_YSIZE; y++)
9180 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9182 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9184 SetOverlayShowGrid(FALSE);
9189 void ConfigureVirtualButtons(void)
9191 boolean success = ConfigureVirtualButtonsMain();
9193 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9194 SCREEN_MASK_TOUCH2);
9198 int font_nr = FONT_TITLE_1;
9199 int font_height = getFontHeight(font_nr);
9200 int ypos1 = SYSIZE / 2 - font_height * 2;
9201 int ypos2 = SYSIZE / 2 - font_height * 1;
9202 unsigned int wait_frame_delay = 0;
9203 unsigned int wait_frame_delay_value = 2000;
9205 ResetDelayCounter(&wait_frame_delay);
9209 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9210 DrawTextSCentered(ypos2, font_nr, "configured!");
9212 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
9219 void DrawSetupScreen(void)
9224 if (setup_mode == SETUP_MODE_INPUT)
9225 DrawSetupScreen_Input();
9226 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9227 DrawChooseTree(&scores_type_current);
9228 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9229 DrawChooseTree(&game_speed_current);
9230 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9231 DrawChooseTree(&scroll_delay_current);
9232 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9233 DrawChooseTree(&snapshot_mode_current);
9234 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9235 DrawChooseTree(&window_size_current);
9236 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9237 DrawChooseTree(&scaling_type_current);
9238 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9239 DrawChooseTree(&rendering_mode_current);
9240 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9241 DrawChooseTree(&vsync_mode_current);
9242 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9243 DrawChooseTree(&artwork.gfx_current);
9244 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9245 DrawChooseTree(&artwork.snd_current);
9246 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9247 DrawChooseTree(&artwork.mus_current);
9248 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9249 DrawChooseTree(&volume_simple_current);
9250 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9251 DrawChooseTree(&volume_loops_current);
9252 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9253 DrawChooseTree(&volume_music_current);
9254 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9255 DrawChooseTree(&touch_control_current);
9256 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9257 DrawChooseTree(&move_distance_current);
9258 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9259 DrawChooseTree(&drop_distance_current);
9260 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9261 DrawChooseTree(&transparency_current);
9262 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9263 DrawChooseTree(&grid_size_current[0][0]);
9264 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9265 DrawChooseTree(&grid_size_current[0][1]);
9266 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9267 DrawChooseTree(&grid_size_current[1][0]);
9268 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9269 DrawChooseTree(&grid_size_current[1][1]);
9271 DrawSetupScreen_Generic();
9273 PlayMenuSoundsAndMusic();
9276 void RedrawSetupScreenAfterFullscreenToggle(void)
9278 if (setup_mode == SETUP_MODE_GRAPHICS ||
9279 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9281 // update list selection from "setup.window_scaling_percent"
9282 execSetupGraphics_setWindowSizes(TRUE);
9288 void RedrawSetupScreenAfterScreenRotation(int nr)
9292 if (setup_mode == SETUP_MODE_TOUCH)
9294 // update virtual button settings (depending on screen orientation)
9297 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9299 // save already configured virtual buttons
9300 for (x = 0; x < MAX_GRID_XSIZE; x++)
9301 for (y = 0; y < MAX_GRID_YSIZE; y++)
9302 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9306 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9308 if (setup_mode == SETUP_MODE_INPUT)
9309 HandleSetupScreen_Input(mx, my, dx, dy, button);
9310 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9311 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9312 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9313 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9314 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9315 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9316 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9317 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9318 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9319 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9320 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9321 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9322 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9323 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9324 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9325 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9326 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9327 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9328 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9329 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9330 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9331 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9332 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9333 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9334 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9335 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9336 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9337 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9338 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9339 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9340 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9341 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9342 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9343 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9344 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9345 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9346 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9347 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9348 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9349 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9350 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9351 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9352 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9353 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9355 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9358 void HandleGameActions(void)
9360 if (setup.ask_on_game_over)
9363 if (game.restart_game_message != NULL)
9365 RequestRestartGame(game.restart_game_message);
9370 if (game_status != GAME_MODE_PLAYING)
9373 GameActions(); // main game loop
9375 if (tape.auto_play && !tape.playing)
9376 AutoPlayTapesContinue(); // continue automatically playing next tape
9380 // ---------- new screen button stuff --------------------------------------
9384 int gfx_unpressed, gfx_pressed;
9385 struct MenuPosInfo *pos;
9386 boolean *check_value;
9389 unsigned int event_mask;
9390 boolean is_touch_button;
9392 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9395 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
9396 &menu.main.button.prev_level, NULL,
9397 SCREEN_CTRL_ID_PREV_LEVEL,
9399 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9400 FALSE, "previous level"
9403 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
9404 &menu.main.button.next_level, NULL,
9405 SCREEN_CTRL_ID_NEXT_LEVEL,
9407 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9411 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE,
9412 &menu.scores.button.prev_level, NULL,
9413 SCREEN_CTRL_ID_PREV_LEVEL2,
9414 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9415 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9416 FALSE, "previous level"
9419 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE,
9420 &menu.scores.button.next_level, NULL,
9421 SCREEN_CTRL_ID_NEXT_LEVEL2,
9422 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9423 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9427 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE,
9428 &menu.scores.button.prev_score, NULL,
9429 SCREEN_CTRL_ID_PREV_SCORE,
9430 SCREEN_MASK_SCORES_INFO,
9431 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9432 FALSE, "previous score"
9435 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE,
9436 &menu.scores.button.next_score, NULL,
9437 SCREEN_CTRL_ID_NEXT_SCORE,
9438 SCREEN_MASK_SCORES_INFO,
9439 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9443 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE,
9444 &menu.scores.button.play_tape, NULL,
9445 SCREEN_CTRL_ID_PLAY_TAPE,
9446 SCREEN_MASK_SCORES_INFO,
9451 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
9452 &menu.main.button.first_level, NULL,
9453 SCREEN_CTRL_ID_FIRST_LEVEL,
9456 FALSE, "first level"
9459 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
9460 &menu.main.button.last_level, NULL,
9461 SCREEN_CTRL_ID_LAST_LEVEL,
9467 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
9468 &menu.main.button.level_number, NULL,
9469 SCREEN_CTRL_ID_LEVEL_NUMBER,
9472 FALSE, "level number"
9475 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
9476 &menu.setup.button.prev_player, NULL,
9477 SCREEN_CTRL_ID_PREV_PLAYER,
9479 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9480 FALSE, "previous player"
9483 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
9484 &menu.setup.button.next_player, NULL,
9485 SCREEN_CTRL_ID_NEXT_PLAYER,
9487 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9488 FALSE, "next player"
9491 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
9492 &menu.main.button.insert_solution, NULL,
9493 SCREEN_CTRL_ID_INSERT_SOLUTION,
9494 SCREEN_MASK_MAIN_HAS_SOLUTION,
9496 FALSE, "insert solution tape"
9499 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
9500 &menu.main.button.play_solution, NULL,
9501 SCREEN_CTRL_ID_PLAY_SOLUTION,
9502 SCREEN_MASK_MAIN_HAS_SOLUTION,
9504 FALSE, "play solution tape"
9507 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
9508 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9509 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9511 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9512 FALSE, "switch ECS/AGA chipset"
9515 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
9516 &menu.setup.button.touch_back, NULL,
9517 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9520 TRUE, "previous page"
9523 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
9524 &menu.setup.button.touch_next, NULL,
9525 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9531 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
9532 &menu.setup.button.touch_back2, NULL,
9533 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9536 TRUE, "previous page"
9539 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
9540 &menu.setup.button.touch_next2, NULL,
9541 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9550 int gfx_unpressed, gfx_pressed;
9554 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9557 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9558 -1, -1, // these values are not constant, but can change at runtime
9559 SCREEN_CTRL_ID_SCROLL_UP,
9563 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9564 -1, -1, // these values are not constant, but can change at runtime
9565 SCREEN_CTRL_ID_SCROLL_DOWN,
9572 int gfx_unpressed, gfx_pressed;
9578 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9581 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9582 -1, -1, // these values are not constant, but can change at runtime
9583 -1, -1, // these values are not constant, but can change at runtime
9584 GD_TYPE_SCROLLBAR_VERTICAL,
9585 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9586 "scroll level series vertically"
9598 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9601 IMG_SETUP_INPUT_TEXT,
9602 SCREEN_CTRL_ID_NETWORK_SERVER,
9603 -1, -1, // these values are not constant, but can change at runtime
9604 MAX_SETUP_TEXT_INPUT_LEN,
9605 network_server_hostname,
9606 "Network Server Hostname / IP"
9610 static void CreateScreenMenubuttons(void)
9612 struct GadgetInfo *gi;
9613 unsigned int event_mask;
9616 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9618 struct MenuPosInfo *pos = menubutton_info[i].pos;
9619 int screen_mask = menubutton_info[i].screen_mask;
9620 boolean is_touch_button = menubutton_info[i].is_touch_button;
9621 boolean is_check_button = menubutton_info[i].check_value != NULL;
9622 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9623 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9624 menubutton_info[i].gfx_unpressed);
9625 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9626 int gfx_unpressed, gfx_pressed;
9627 int x, y, width, height;
9628 int gd_x1, gd_x2, gd_y1, gd_y2;
9629 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9630 int id = menubutton_info[i].gadget_id;
9631 int type = GD_TYPE_NORMAL_BUTTON;
9632 boolean checked = FALSE;
9634 event_mask = menubutton_info[i].event_mask;
9636 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9637 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9639 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9640 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9642 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9643 gfx_pressed = menubutton_info[i].gfx_pressed;
9644 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9645 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9646 gd_x1 = graphic_info[gfx_unpressed].src_x;
9647 gd_y1 = graphic_info[gfx_unpressed].src_y;
9648 gd_x2 = graphic_info[gfx_pressed].src_x;
9649 gd_y2 = graphic_info[gfx_pressed].src_y;
9655 if (has_gfx_pressed)
9657 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9658 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9661 if (is_check_button)
9663 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9664 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9665 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9666 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9668 type = GD_TYPE_CHECK_BUTTON;
9669 checked = *menubutton_info[i].check_value;
9672 if (is_score_button)
9674 // if x/y set to -1, dynamically place buttons next to title text
9675 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9678 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9679 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9680 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9681 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9684 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
9685 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
9688 gi = CreateGadget(GDI_CUSTOM_ID, id,
9689 GDI_CUSTOM_TYPE_ID, i,
9690 GDI_IMAGE_ID, gfx_unpressed,
9691 GDI_INFO_TEXT, menubutton_info[i].infotext,
9697 GDI_STATE, GD_BUTTON_UNPRESSED,
9698 GDI_CHECKED, checked,
9699 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9700 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9701 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9702 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9703 GDI_DIRECT_DRAW, FALSE,
9704 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9705 GDI_EVENT_MASK, event_mask,
9706 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9710 Fail("cannot create gadget");
9712 screen_gadget[id] = gi;
9716 static void CreateScreenScrollbuttons(void)
9718 struct GadgetInfo *gi;
9719 unsigned int event_mask;
9722 // these values are not constant, but can change at runtime
9723 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9724 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9725 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9726 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9728 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9730 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9731 int gfx_unpressed, gfx_pressed;
9732 int x, y, width, height;
9733 int gd_x1, gd_x2, gd_y1, gd_y2;
9734 int id = scrollbutton_info[i].gadget_id;
9736 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9738 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9739 y = mSY + scrollbutton_info[i].y;
9740 width = SC_SCROLLBUTTON_XSIZE;
9741 height = SC_SCROLLBUTTON_YSIZE;
9743 // correct scrollbar position if placed outside menu (playfield) area
9744 if (x > SX + SC_SCROLL_UP_XPOS)
9745 x = SX + SC_SCROLL_UP_XPOS;
9747 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9748 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9749 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9751 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9752 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9753 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9754 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9755 gd_x1 = graphic_info[gfx_unpressed].src_x;
9756 gd_y1 = graphic_info[gfx_unpressed].src_y;
9757 gd_x2 = graphic_info[gfx_pressed].src_x;
9758 gd_y2 = graphic_info[gfx_pressed].src_y;
9760 gi = CreateGadget(GDI_CUSTOM_ID, id,
9761 GDI_CUSTOM_TYPE_ID, i,
9762 GDI_IMAGE_ID, gfx_unpressed,
9763 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9768 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9769 GDI_STATE, GD_BUTTON_UNPRESSED,
9770 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9771 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9772 GDI_DIRECT_DRAW, FALSE,
9773 GDI_EVENT_MASK, event_mask,
9774 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9778 Fail("cannot create gadget");
9780 screen_gadget[id] = gi;
9784 static void CreateScreenScrollbars(void)
9788 // these values are not constant, but can change at runtime
9789 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9790 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9791 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9792 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9794 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9796 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9797 int gfx_unpressed, gfx_pressed;
9798 int x, y, width, height;
9799 int gd_x1, gd_x2, gd_y1, gd_y2;
9800 struct GadgetInfo *gi;
9801 int items_max, items_visible, item_position;
9802 unsigned int event_mask;
9803 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9804 int id = scrollbar_info[i].gadget_id;
9806 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9808 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9809 y = mSY + scrollbar_info[i].y;
9810 width = scrollbar_info[i].width;
9811 height = scrollbar_info[i].height;
9813 // correct scrollbar position if placed outside menu (playfield) area
9814 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9815 x = SX + SC_SCROLL_VERTICAL_XPOS;
9817 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9818 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9820 items_max = num_page_entries;
9821 items_visible = num_page_entries;
9824 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9825 gfx_pressed = scrollbar_info[i].gfx_pressed;
9826 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9827 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9828 gd_x1 = graphic_info[gfx_unpressed].src_x;
9829 gd_y1 = graphic_info[gfx_unpressed].src_y;
9830 gd_x2 = graphic_info[gfx_pressed].src_x;
9831 gd_y2 = graphic_info[gfx_pressed].src_y;
9833 gi = CreateGadget(GDI_CUSTOM_ID, id,
9834 GDI_CUSTOM_TYPE_ID, i,
9835 GDI_IMAGE_ID, gfx_unpressed,
9836 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9841 GDI_TYPE, scrollbar_info[i].type,
9842 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9843 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9844 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9845 GDI_WHEEL_AREA_X, SX,
9846 GDI_WHEEL_AREA_Y, SY,
9847 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9848 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9849 GDI_STATE, GD_BUTTON_UNPRESSED,
9850 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9851 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9852 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9853 GDI_DIRECT_DRAW, FALSE,
9854 GDI_EVENT_MASK, event_mask,
9855 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9859 Fail("cannot create gadget");
9861 screen_gadget[id] = gi;
9865 static void CreateScreenTextInputGadgets(void)
9869 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9871 int graphic = textinput_info[i].graphic;
9872 struct GraphicInfo *gd = &graphic_info[graphic];
9873 int gd_x1 = gd->src_x;
9874 int gd_y1 = gd->src_y;
9875 int gd_x2 = gd->src_x + gd->active_xoffset;
9876 int gd_y2 = gd->src_y + gd->active_yoffset;
9877 struct GadgetInfo *gi;
9878 unsigned int event_mask;
9879 int id = textinput_info[i].gadget_id;
9880 int x = textinput_info[i].x;
9881 int y = textinput_info[i].y;
9883 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9885 gi = CreateGadget(GDI_CUSTOM_ID, id,
9886 GDI_CUSTOM_TYPE_ID, i,
9887 GDI_INFO_TEXT, textinput_info[i].infotext,
9890 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9891 GDI_TEXT_VALUE, textinput_info[i].value,
9892 GDI_TEXT_SIZE, textinput_info[i].size,
9893 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9894 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9895 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9896 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9897 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9898 GDI_DESIGN_WIDTH, gd->width,
9899 GDI_EVENT_MASK, event_mask,
9900 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9901 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9905 Fail("cannot create gadget");
9907 screen_gadget[id] = gi;
9911 void CreateScreenGadgets(void)
9913 CreateScreenMenubuttons();
9915 CreateScreenScrollbuttons();
9916 CreateScreenScrollbars();
9918 CreateScreenTextInputGadgets();
9921 void FreeScreenGadgets(void)
9925 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9926 FreeGadget(screen_gadget[i]);
9929 static void RedrawScreenMenuGadgets(int screen_mask)
9933 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9934 if (screen_mask & menubutton_info[i].screen_mask)
9935 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
9938 static void MapScreenMenuGadgets(int screen_mask)
9942 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9943 if (screen_mask & menubutton_info[i].screen_mask)
9944 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9947 static void UnmapScreenMenuGadgets(int screen_mask)
9951 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9953 if (screen_mask & menubutton_info[i].screen_mask)
9955 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9957 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9958 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9959 screen_gadget[menubutton_info[i].gadget_id]->y,
9960 screen_gadget[menubutton_info[i].gadget_id]->width,
9961 screen_gadget[menubutton_info[i].gadget_id]->height);
9966 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9969 MapScreenMenuGadgets(screen_mask);
9971 UnmapScreenMenuGadgets(screen_mask);
9974 static void MapScreenGadgets(int num_entries)
9978 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9981 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9982 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9984 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9985 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9988 static void UnmapScreenGadgets()
9992 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9993 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9995 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9996 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9999 static void MapScreenTreeGadgets(TreeInfo *ti)
10001 MapScreenGadgets(numTreeInfoInGroup(ti));
10004 static void UnmapScreenTreeGadgets(void)
10006 UnmapScreenGadgets();
10009 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10011 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10012 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10013 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10014 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10016 if (pos_1->x == -1 && pos_1->y == -1)
10017 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10019 if (pos_2->x == -1 && pos_2->y == -1)
10020 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10023 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10025 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10026 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10028 // set gadget position dynamically, pre-defined or off-screen
10029 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10030 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10032 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10033 MapGadget(gi); // (needed if deactivated on last score page)
10036 static void HandleScreenGadgets(struct GadgetInfo *gi)
10038 int id = gi->custom_id;
10039 int button = gi->event.button;
10040 int step = (button == MB_LEFTBUTTON ? 1 :
10041 button == MB_MIDDLEBUTTON ? 5 :
10042 button == MB_RIGHTBUTTON ? 10 : 1);
10046 case SCREEN_CTRL_ID_PREV_LEVEL:
10047 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10050 case SCREEN_CTRL_ID_NEXT_LEVEL:
10051 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10054 case SCREEN_CTRL_ID_PREV_LEVEL2:
10055 HandleHallOfFame_SelectLevel(step, -1);
10058 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10059 HandleHallOfFame_SelectLevel(step, +1);
10062 case SCREEN_CTRL_ID_PREV_SCORE:
10063 HandleScoreInfo_SelectScore(step, -1);
10066 case SCREEN_CTRL_ID_NEXT_SCORE:
10067 HandleScoreInfo_SelectScore(step, +1);
10070 case SCREEN_CTRL_ID_PLAY_TAPE:
10071 HandleScoreInfo_PlayTape();
10074 case SCREEN_CTRL_ID_FIRST_LEVEL:
10075 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10078 case SCREEN_CTRL_ID_LAST_LEVEL:
10079 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10082 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10083 CloseDoor(DOOR_CLOSE_2);
10084 SetGameStatus(GAME_MODE_LEVELNR);
10085 DrawChooseLevelNr();
10088 case SCREEN_CTRL_ID_PREV_PLAYER:
10089 HandleSetupScreen_Input_Player(step, -1);
10092 case SCREEN_CTRL_ID_NEXT_PLAYER:
10093 HandleSetupScreen_Input_Player(step, +1);
10096 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10097 InsertSolutionTape();
10100 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10101 PlaySolutionTape();
10104 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10105 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10109 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10110 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10111 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10112 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10113 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10116 case SCREEN_CTRL_ID_SCROLL_UP:
10117 if (game_status == GAME_MODE_NAMES)
10118 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10119 else if (game_status == GAME_MODE_LEVELS)
10120 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10121 else if (game_status == GAME_MODE_LEVELNR)
10122 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10123 else if (game_status == GAME_MODE_SETUP)
10124 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10125 else if (game_status == GAME_MODE_INFO)
10126 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10127 else if (game_status == GAME_MODE_SCORES)
10128 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10131 case SCREEN_CTRL_ID_SCROLL_DOWN:
10132 if (game_status == GAME_MODE_NAMES)
10133 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10134 else if (game_status == GAME_MODE_LEVELS)
10135 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10136 else if (game_status == GAME_MODE_LEVELNR)
10137 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10138 else if (game_status == GAME_MODE_SETUP)
10139 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10140 else if (game_status == GAME_MODE_INFO)
10141 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10142 else if (game_status == GAME_MODE_SCORES)
10143 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10146 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10147 if (game_status == GAME_MODE_NAMES)
10148 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10149 else if (game_status == GAME_MODE_LEVELS)
10150 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10151 else if (game_status == GAME_MODE_LEVELNR)
10152 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10153 else if (game_status == GAME_MODE_SETUP)
10154 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10155 else if (game_status == GAME_MODE_INFO)
10156 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10157 else if (game_status == GAME_MODE_SCORES)
10158 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10161 case SCREEN_CTRL_ID_NETWORK_SERVER:
10163 if (!strEqual(gi->textinput.value, ""))
10165 setString(&setup.network_server_hostname, gi->textinput.value);
10167 network.server_host = setup.network_server_hostname;
10171 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10173 network.server_host = NULL;
10176 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10177 network.server_host = NULL;
10179 execSetupGame_setNetworkServerText();
10191 void DumpScreenIdentifiers(void)
10195 Print("Active screen elements on current screen:\n");
10197 for (i = 0; main_controls[i].nr != -1; i++)
10199 struct MainControlInfo *mci = &main_controls[i];
10201 if (mci->button_graphic != -1)
10203 char *token = getTokenFromImageID(mci->button_graphic);
10205 Print("- '%s'\n", token);
10212 boolean DoScreenAction(int image_id)
10216 if (game_status != GAME_MODE_MAIN)
10219 for (i = 0; main_controls[i].nr != -1; i++)
10221 struct MainControlInfo *mci = &main_controls[i];
10222 struct MenuPosInfo *pos = mci->pos_button;
10224 if (mci->button_graphic == image_id)
10226 int x = mSX + pos->x;
10227 int y = mSY + pos->y;
10229 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10238 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10240 // get tree info node of newly added level or artwork set
10241 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10242 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10244 if (tree_node_new == NULL) // should not happen
10247 // if request dialog is active, do nothing
10248 if (game.request_active)
10251 if (game_status == GAME_MODE_MAIN &&
10252 tree_type == TREE_TYPE_LEVEL_DIR)
10254 // when adding new level set in main menu, select it as current level set
10256 // change current level set to newly added level set from zip file
10257 leveldir_current = tree_node_new;
10259 // change current level number to first level of newly added level set
10260 level_nr = leveldir_current->first_level;
10262 // redraw screen to reflect changed level set
10265 // save this level set and level number as last selected level set
10266 SaveLevelSetup_LastSeries();
10267 SaveLevelSetup_SeriesInfo();
10269 else if (game_status == GAME_MODE_LEVELS &&
10270 tree_type == TREE_TYPE_LEVEL_DIR)
10272 // when adding new level set in level set menu, set cursor and update screen
10274 leveldir_current = tree_node_new;
10276 DrawChooseTree(&leveldir_current);
10278 else if (game_status == GAME_MODE_SETUP)
10280 // when adding new artwork set in setup menu, set cursor and update screen
10282 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10283 tree_type == TREE_TYPE_GRAPHICS_DIR)
10285 artwork.gfx_current = tree_node_new;
10287 DrawChooseTree(&artwork.gfx_current);
10289 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10290 tree_type == TREE_TYPE_SOUNDS_DIR)
10292 artwork.snd_current = tree_node_new;
10294 DrawChooseTree(&artwork.snd_current);
10296 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10297 tree_type == TREE_TYPE_MUSIC_DIR)
10299 artwork.mus_current = tree_node_new;
10301 DrawChooseTree(&artwork.mus_current);
10306 static int UploadTapes(void)
10308 SetGameStatus(GAME_MODE_LOADING);
10310 FadeSetEnterScreen();
10311 FadeOut(REDRAW_ALL);
10313 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10315 FadeIn(REDRAW_ALL);
10317 DrawInitTextHead("Uploading tapes");
10319 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10320 global.autoplay_leveldir = "ALL";
10321 global.autoplay_all = TRUE;
10323 int num_tapes_uploaded = AutoPlayTapes();
10325 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10326 global.autoplay_leveldir = NULL;
10327 global.autoplay_all = FALSE;
10329 SetGameStatus(GAME_MODE_MAIN);
10333 return num_tapes_uploaded;
10336 static boolean OfferUploadTapes(void)
10338 if (!Request(setup.has_remaining_tapes ?
10339 "Upload missing tapes to the high score server now?" :
10340 "Upload all your tapes to the high score server now?", REQ_ASK))
10343 int num_tapes_uploaded = UploadTapes();
10346 if (num_tapes_uploaded < 0)
10348 num_tapes_uploaded = -num_tapes_uploaded - 1;
10350 if (num_tapes_uploaded == 0)
10351 sprintf(message, "Upload failed! No tapes uploaded!");
10352 else if (num_tapes_uploaded == 1)
10353 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10355 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10356 num_tapes_uploaded);
10358 Request(message, REQ_CONFIRM);
10360 // if uploading tapes failed, add tape upload entry to setup menu
10361 setup.provide_uploading_tapes = TRUE;
10362 setup.has_remaining_tapes = TRUE;
10364 SaveSetup_ServerSetup();
10369 if (num_tapes_uploaded == 0)
10370 sprintf(message, "No tapes uploaded!");
10371 else if (num_tapes_uploaded == 1)
10372 sprintf(message, "1 tape uploaded!");
10374 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10376 Request(message, REQ_CONFIRM);
10378 if (num_tapes_uploaded > 0)
10379 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10381 // after all tapes have been uploaded, remove entry from setup menu
10382 setup.provide_uploading_tapes = FALSE;
10383 setup.has_remaining_tapes = FALSE;
10385 SaveSetup_ServerSetup();
10390 static void CheckUploadTapes(void)
10392 if (!setup.ask_for_uploading_tapes)
10395 // after asking for uploading tapes, do not ask again
10396 setup.ask_for_uploading_tapes = FALSE;
10397 setup.ask_for_remaining_tapes = FALSE;
10399 if (directoryExists(getTapeDir(NULL)))
10401 boolean tapes_uploaded = OfferUploadTapes();
10403 if (!tapes_uploaded)
10405 Request(setup.has_remaining_tapes ?
10406 "You can upload missing tapes from the setup menu later!" :
10407 "You can upload your tapes from the setup menu later!",
10413 // if tapes directory does not exist yet, never offer uploading all tapes
10414 setup.provide_uploading_tapes = FALSE;
10417 SaveSetup_ServerSetup();
10420 static void UpgradePlayerUUID(void)
10422 ApiResetUUIDAsThread(getUUID());
10425 static void CheckUpgradePlayerUUID(void)
10427 if (setup.player_version > 1)
10430 UpgradePlayerUUID();
10433 void CheckApiServerTasks(void)
10435 // check if the player's UUID has to be upgraded
10436 CheckUpgradePlayerUUID();
10438 // check if there are any tapes to be uploaded
10439 CheckUploadTapes();