1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
27 #define DEBUG_JOYSTICKS 0
30 // screens on the info screen
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 // screens on the setup screen
43 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
44 // (should also match corresponding entries in src/conf_gfx.c)
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_ENGINES 2
48 #define SETUP_MODE_EDITOR 3
49 #define SETUP_MODE_GRAPHICS 4
50 #define SETUP_MODE_SOUND 5
51 #define SETUP_MODE_ARTWORK 6
52 #define SETUP_MODE_INPUT 7
53 #define SETUP_MODE_TOUCH 8
54 #define SETUP_MODE_SHORTCUTS 9
55 #define SETUP_MODE_SHORTCUTS_1 10
56 #define SETUP_MODE_SHORTCUTS_2 11
57 #define SETUP_MODE_SHORTCUTS_3 12
58 #define SETUP_MODE_SHORTCUTS_4 13
59 #define SETUP_MODE_SHORTCUTS_5 14
61 // sub-screens on the setup screen (generic)
62 #define SETUP_MODE_CHOOSE_ARTWORK 15
63 #define SETUP_MODE_CHOOSE_OTHER 16
65 // sub-screens on the setup screen (specific)
66 #define SETUP_MODE_CHOOSE_GAME_SPEED 17
67 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 18
68 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 19
69 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 20
70 #define SETUP_MODE_CHOOSE_SCALING_TYPE 21
71 #define SETUP_MODE_CHOOSE_RENDERING 22
72 #define SETUP_MODE_CHOOSE_VSYNC 23
73 #define SETUP_MODE_CHOOSE_GRAPHICS 24
74 #define SETUP_MODE_CHOOSE_SOUNDS 25
75 #define SETUP_MODE_CHOOSE_MUSIC 26
76 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 27
77 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 28
78 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 29
79 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 30
80 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 31
81 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_TRANSPARENCY 33
83 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 34
84 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 36
86 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 37
87 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 38
89 #define MAX_SETUP_MODES 39
91 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
93 // setup screen titles
94 #define STR_SETUP_MAIN "Setup"
95 #define STR_SETUP_GAME "Game & Menu"
96 #define STR_SETUP_ENGINES "Game Engines"
97 #define STR_SETUP_EDITOR "Editor"
98 #define STR_SETUP_GRAPHICS "Graphics"
99 #define STR_SETUP_SOUND "Sound & Music"
100 #define STR_SETUP_ARTWORK "Custom Artwork"
101 #define STR_SETUP_INPUT "Input Devices"
102 #define STR_SETUP_TOUCH "Touch Controls"
103 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
104 #define STR_SETUP_EXIT "Exit"
105 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
107 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
108 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
109 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
110 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
111 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
112 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
113 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
114 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
115 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
116 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
117 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
118 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
119 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
120 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
121 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
122 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
126 // other screen text constants
127 #define STR_CHOOSE_TREE_EDIT "Edit"
129 // for input setup functions
130 #define SETUPINPUT_SCREEN_POS_START 0
131 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
132 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
133 #define SETUPINPUT_SCREEN_POS_END 13
135 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
136 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
138 #define MAX_SETUP_TEXT_INPUT_LEN 28
140 // for various menu stuff
141 #define MENU_SCREEN_START_XPOS 1
142 #define MENU_SCREEN_START_YPOS 2
143 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
144 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
145 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
146 #define MENU_TITLE1_YPOS 8
147 #define MENU_TITLE2_YPOS 46
148 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
149 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
150 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
151 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
152 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
153 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
154 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
155 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
156 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
157 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
158 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
159 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
160 MENU_INFO_FONT_TITLE))
161 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
162 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
163 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
164 MENU_SCREEN_INFO_YSTART2 - \
166 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
167 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
168 MENU_SCREEN_INFO_YSTEP)
169 #define NUM_INFO_ELEMENTS_FROM_CONF \
170 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
171 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
172 MAX_MENU_ENTRIES_ON_SCREEN)
173 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
174 MAX_INFO_ELEMENTS_ON_SCREEN), \
175 NUM_INFO_ELEMENTS_FROM_CONF)
176 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
177 #define MAX_MENU_TEXT_LENGTH_BIG 13
178 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
180 // screen gadget identifiers
181 #define SCREEN_CTRL_ID_PREV_LEVEL 0
182 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
183 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
184 #define SCREEN_CTRL_ID_LAST_LEVEL 3
185 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
186 #define SCREEN_CTRL_ID_PREV_PLAYER 5
187 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
188 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
189 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
190 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
191 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
192 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
193 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
194 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
195 #define SCREEN_CTRL_ID_SCROLL_UP 14
196 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
197 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
198 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
200 #define NUM_SCREEN_GADGETS 18
202 #define NUM_SCREEN_MENUBUTTONS 14
203 #define NUM_SCREEN_SCROLLBUTTONS 2
204 #define NUM_SCREEN_SCROLLBARS 1
205 #define NUM_SCREEN_TEXTINPUT 1
207 #define SCREEN_MASK_MAIN (1 << 0)
208 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
209 #define SCREEN_MASK_INPUT (1 << 2)
210 #define SCREEN_MASK_TOUCH (1 << 3)
211 #define SCREEN_MASK_TOUCH2 (1 << 4)
213 // graphic position and size values for buttons and scrollbars
214 #define SC_MENUBUTTON_XSIZE TILEX
215 #define SC_MENUBUTTON_YSIZE TILEY
217 #define SC_SCROLLBUTTON_XSIZE TILEX
218 #define SC_SCROLLBUTTON_YSIZE TILEY
220 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
222 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
223 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
224 SC_SCROLLBUTTON_YSIZE)
226 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
227 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
229 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
230 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
231 SC_SCROLLBUTTON_YSIZE)
233 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
234 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
235 SC_SCROLL_VERTICAL_YSIZE)
237 #define SC_BORDER_SIZE 14
240 // forward declarations of internal functions
241 static void HandleScreenGadgets(struct GadgetInfo *);
242 static void HandleSetupScreen_Generic(int, int, int, int, int);
243 static void HandleSetupScreen_Input(int, int, int, int, int);
244 static void CustomizeKeyboard(int);
245 static void ConfigureJoystick(int);
246 static void ConfigureVirtualButtons(void);
247 static void execSetupGame(void);
248 static void execSetupEngines(void);
249 static void execSetupGraphics(void);
250 static void execSetupSound(void);
251 static void execSetupTouch(void);
252 static void execSetupArtwork(void);
253 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
255 static void DrawChoosePlayerName(void);
256 static void DrawChooseLevelSet(void);
257 static void DrawChooseLevelNr(void);
258 static void DrawInfoScreen(void);
259 static void DrawSetupScreen(void);
260 static void DrawTypeName(void);
262 static void DrawInfoScreen_NotAvailable(char *, char *);
263 static void DrawInfoScreen_HelpAnim(int, int, boolean);
264 static void DrawInfoScreen_HelpText(int, int, int, int);
265 static void HandleInfoScreen_Main(int, int, int, int, int);
266 static void HandleInfoScreen_TitleScreen(int);
267 static void HandleInfoScreen_Elements(int);
268 static void HandleInfoScreen_Music(int);
269 static void HandleInfoScreen_Credits(int);
270 static void HandleInfoScreen_Program(int);
271 static void HandleInfoScreen_Version(int);
273 static void ModifyGameSpeedIfNeeded(void);
274 static void DisableVsyncIfNeeded(void);
276 static void MapScreenMenuGadgets(int);
277 static void UnmapScreenMenuGadgets(int);
278 static void MapScreenGadgets(int);
279 static void MapScreenTreeGadgets(TreeInfo *);
281 static void UpdateScreenMenuGadgets(int, boolean);
283 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
285 static int info_mode = INFO_MODE_MAIN;
286 static int setup_mode = SETUP_MODE_MAIN;
288 static TreeInfo *window_sizes = NULL;
289 static TreeInfo *window_size_current = NULL;
291 static TreeInfo *scaling_types = NULL;
292 static TreeInfo *scaling_type_current = NULL;
294 static TreeInfo *rendering_modes = NULL;
295 static TreeInfo *rendering_mode_current = NULL;
297 static TreeInfo *vsync_modes = NULL;
298 static TreeInfo *vsync_mode_current = NULL;
300 static TreeInfo *scroll_delays = NULL;
301 static TreeInfo *scroll_delay_current = NULL;
303 static TreeInfo *snapshot_modes = NULL;
304 static TreeInfo *snapshot_mode_current = NULL;
306 static TreeInfo *game_speeds_normal = NULL;
307 static TreeInfo *game_speeds_extended = NULL;
308 static TreeInfo *game_speeds = NULL;
309 static TreeInfo *game_speed_current = NULL;
311 static TreeInfo *volumes_simple = NULL;
312 static TreeInfo *volume_simple_current = NULL;
314 static TreeInfo *volumes_loops = NULL;
315 static TreeInfo *volume_loops_current = NULL;
317 static TreeInfo *volumes_music = NULL;
318 static TreeInfo *volume_music_current = NULL;
320 static TreeInfo *touch_controls = NULL;
321 static TreeInfo *touch_control_current = NULL;
323 static TreeInfo *move_distances = NULL;
324 static TreeInfo *move_distance_current = NULL;
326 static TreeInfo *drop_distances = NULL;
327 static TreeInfo *drop_distance_current = NULL;
329 static TreeInfo *transparencies = NULL;
330 static TreeInfo *transparency_current = NULL;
332 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
333 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
335 static TreeInfo *player_name = NULL;
336 static TreeInfo *player_name_current = NULL;
338 static TreeInfo *level_number = NULL;
339 static TreeInfo *level_number_current = NULL;
341 static struct ValueTextInfo window_sizes_list[] =
346 { 100, "100 % (Default)" },
359 static struct StringValueTextInfo scaling_types_list[] =
361 { SCALING_QUALITY_NEAREST, "Off" },
362 { SCALING_QUALITY_LINEAR, "Linear" },
363 { SCALING_QUALITY_BEST, "Anisotropic" },
368 static struct StringValueTextInfo rendering_modes_list[] =
370 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
371 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
373 // this mode may work under certain conditions, but does not work on Windows
374 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
376 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
381 static struct StringValueTextInfo vsync_modes_list[] =
383 { STR_VSYNC_MODE_OFF, "Off" },
384 { STR_VSYNC_MODE_NORMAL, "Normal" },
385 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
390 static struct ValueTextInfo game_speeds_list_normal[] =
401 static struct ValueTextInfo game_speeds_list_extended[] =
403 { 1000, "1 fps (Extremely Slow)" },
408 { 29, "35 fps (Original Supaplex)" },
410 { 20, "50 fps (=== Normal Speed ===)" },
411 { 16, "60 fps (60 Hz VSync Speed)" },
412 { 14, "70 fps (Maximum Supaplex)" },
416 { 1, "1000 fps (Extremely Fast)" },
421 static struct ValueTextInfo *game_speeds_list;
423 static struct ValueTextInfo scroll_delays_list[] =
425 { 0, "0 Tiles (No Scroll Delay)" },
428 { 3, "3 Tiles (Default)" },
433 { 8, "8 Tiles (Maximum Scroll Delay)"},
438 static struct StringValueTextInfo snapshot_modes_list[] =
440 { STR_SNAPSHOT_MODE_OFF, "Off" },
441 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
442 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
443 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
448 static struct ValueTextInfo volumes_list[] =
468 static struct StringValueTextInfo touch_controls_list[] =
470 { TOUCH_CONTROL_OFF, "Off" },
471 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
472 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
473 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
478 static struct ValueTextInfo distances_list[] =
493 static struct ValueTextInfo transparencies_list[] =
495 { 0, "0 % (Opaque)" },
505 { 100, "100 % (Invisible)" },
510 static struct ValueTextInfo grid_sizes_list[] =
546 static int align_xoffset = 0;
547 static int align_yoffset = 0;
549 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
550 (s) <= GAME_MODE_SETUP ? (s) : \
551 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
553 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
554 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
556 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
557 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
558 (i) <= INFO_MODE_LEVELSET ? (i) : \
561 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
562 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
563 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
564 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
565 SETUP_MODE_CHOOSE_ARTWORK : \
566 SETUP_MODE_CHOOSE_OTHER)
568 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
569 menu.draw_xoffset[GAME_MODE_INFO] : \
570 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
571 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
572 menu.draw_yoffset[GAME_MODE_INFO] : \
573 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
574 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
575 menu.extra_spacing[GAME_MODE_INFO] : \
576 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
578 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
579 menu.draw_xoffset[GAME_MODE_SETUP] : \
580 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
581 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
582 menu.draw_yoffset[GAME_MODE_SETUP] : \
583 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
584 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
585 menu.extra_spacing[GAME_MODE_SETUP] : \
586 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
588 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
589 DRAW_XOFFSET_INFO(info_mode) : \
590 (s) == GAME_MODE_SETUP ? \
591 DRAW_XOFFSET_SETUP(setup_mode) : \
592 menu.draw_xoffset[DRAW_MODE(s)])
593 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
594 DRAW_YOFFSET_INFO(info_mode) : \
595 (s) == GAME_MODE_SETUP ? \
596 DRAW_YOFFSET_SETUP(setup_mode) : \
597 menu.draw_yoffset[DRAW_MODE(s)])
598 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
599 EXTRA_SPACING_INFO(info_mode) : \
600 (s) == GAME_MODE_SETUP ? \
601 EXTRA_SPACING_SETUP(setup_mode) : \
602 menu.extra_spacing[DRAW_MODE(s)])
604 #define mSX (SX + DRAW_XOFFSET(game_status))
605 #define mSY (SY + DRAW_YOFFSET(game_status))
607 #define amSX (mSX + align_xoffset)
608 #define amSY (mSY + align_yoffset)
610 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
611 menu.list_size[game_status] : \
612 MAX_MENU_ENTRIES_ON_SCREEN)
614 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
615 NUM_MENU_ENTRIES_ON_SCREEN)
618 // title display and control definitions
620 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
621 2 * MAX_NUM_TITLE_MESSAGES)
623 #define NO_DIRECT_LEVEL_SELECT (-1)
626 static int num_title_screens = 0;
628 struct TitleControlInfo
637 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
639 // main menu display and control definitions
641 #define MAIN_CONTROL_NAME 0
642 #define MAIN_CONTROL_LEVELS 1
643 #define MAIN_CONTROL_SCORES 2
644 #define MAIN_CONTROL_EDITOR 3
645 #define MAIN_CONTROL_INFO 4
646 #define MAIN_CONTROL_GAME 5
647 #define MAIN_CONTROL_SETUP 6
648 #define MAIN_CONTROL_QUIT 7
649 #define MAIN_CONTROL_PREV_LEVEL 8
650 #define MAIN_CONTROL_NEXT_LEVEL 9
651 #define MAIN_CONTROL_FIRST_LEVEL 10
652 #define MAIN_CONTROL_LAST_LEVEL 11
653 #define MAIN_CONTROL_LEVEL_NUMBER 12
654 #define MAIN_CONTROL_LEVEL_INFO_1 13
655 #define MAIN_CONTROL_LEVEL_INFO_2 14
656 #define MAIN_CONTROL_LEVEL_NAME 15
657 #define MAIN_CONTROL_LEVEL_AUTHOR 16
658 #define MAIN_CONTROL_LEVEL_YEAR 17
659 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
660 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
661 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
662 #define MAIN_CONTROL_TITLE_1 21
663 #define MAIN_CONTROL_TITLE_2 22
664 #define MAIN_CONTROL_TITLE_3 23
666 static char str_main_text_name[10];
667 static char str_main_text_first_level[10];
668 static char str_main_text_last_level[10];
669 static char str_main_text_level_number[10];
671 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
673 static char *main_text_name = str_main_text_name;
674 static char *main_text_first_level = str_main_text_first_level;
675 static char *main_text_last_level = str_main_text_last_level;
676 static char *main_text_level_number = str_main_text_level_number;
677 static char *main_text_levels = "Levelset";
678 static char *main_text_scores = "Hall Of Fame";
679 static char *main_text_editor = "Level Creator";
680 static char *main_text_info = "Info Screen";
681 static char *main_text_game = "Start Game";
682 static char *main_text_setup = "Setup";
683 static char *main_text_quit = "Quit";
684 static char *main_text_level_name = level.name;
685 static char *main_text_level_author = level.author;
686 static char *main_text_level_year = NULL;
687 static char *main_text_level_imported_from = NULL;
688 static char *main_text_level_imported_by = NULL;
689 static char *main_text_level_tested_by = NULL;
690 static char *main_text_title_1 = NULL;
691 static char *main_text_title_2 = NULL;
692 static char *main_text_title_3 = NULL;
694 extern char debug_xsn_mode[];
696 struct MainControlInfo
700 struct MenuPosInfo *pos_button;
703 struct TextPosInfo *pos_text;
706 struct TextPosInfo *pos_input;
710 static struct MainControlInfo main_controls[] =
714 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
715 &menu.main.text.name, &main_text_name,
716 &menu.main.input.name, &setup.player_name,
720 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
721 &menu.main.text.levels, &main_text_levels,
726 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
727 &menu.main.text.scores, &main_text_scores,
732 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
733 &menu.main.text.editor, &main_text_editor,
738 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
739 &menu.main.text.info, &main_text_info,
744 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
745 &menu.main.text.game, &main_text_game,
750 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
751 &menu.main.text.setup, &main_text_setup,
756 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
757 &menu.main.text.quit, &main_text_quit,
761 MAIN_CONTROL_PREV_LEVEL,
767 MAIN_CONTROL_NEXT_LEVEL,
773 MAIN_CONTROL_FIRST_LEVEL,
775 &menu.main.text.first_level, &main_text_first_level,
779 MAIN_CONTROL_LAST_LEVEL,
781 &menu.main.text.last_level, &main_text_last_level,
785 MAIN_CONTROL_LEVEL_NUMBER,
787 &menu.main.text.level_number, &main_text_level_number,
791 MAIN_CONTROL_LEVEL_INFO_1,
793 &menu.main.text.level_info_1, NULL,
797 MAIN_CONTROL_LEVEL_INFO_2,
799 &menu.main.text.level_info_2, NULL,
803 MAIN_CONTROL_LEVEL_NAME,
805 &menu.main.text.level_name, &main_text_level_name,
809 MAIN_CONTROL_LEVEL_AUTHOR,
811 &menu.main.text.level_author, &main_text_level_author,
815 MAIN_CONTROL_LEVEL_YEAR,
817 &menu.main.text.level_year, &main_text_level_year,
821 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
823 &menu.main.text.level_imported_from, &main_text_level_imported_from,
827 MAIN_CONTROL_LEVEL_IMPORTED_BY,
829 &menu.main.text.level_imported_by, &main_text_level_imported_by,
833 MAIN_CONTROL_LEVEL_TESTED_BY,
835 &menu.main.text.level_tested_by, &main_text_level_tested_by,
839 MAIN_CONTROL_TITLE_1,
841 &menu.main.text.title_1, &main_text_title_1,
845 MAIN_CONTROL_TITLE_2,
847 &menu.main.text.title_2, &main_text_title_2,
851 MAIN_CONTROL_TITLE_3,
853 &menu.main.text.title_3, &main_text_title_3,
866 static int getTitleScreenGraphic(int nr, boolean initial)
868 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
871 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
873 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
877 static int getTitleScreenGameMode(boolean initial)
879 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
883 static int getTitleMessageGameMode(boolean initial)
885 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
888 static int getTitleAnimMode(struct TitleControlInfo *tci)
890 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
892 return base + tci->local_nr;
896 static int getTitleScreenBackground(boolean initial)
898 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
903 static int getTitleMessageBackground(int nr, boolean initial)
905 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
909 static int getTitleBackground(int nr, boolean initial, boolean is_image)
911 int base = (is_image ?
912 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
913 IMG_BACKGROUND_TITLESCREEN_1) :
914 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
915 IMG_BACKGROUND_TITLEMESSAGE_1));
916 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
917 IMG_BACKGROUND_TITLE);
918 int graphic_local = base + nr;
920 if (graphic_info[graphic_local].bitmap != NULL)
921 return graphic_local;
923 if (graphic_info[graphic_global].bitmap != NULL)
924 return graphic_global;
926 return IMG_UNDEFINED;
929 static int getTitleSound(struct TitleControlInfo *tci)
931 boolean is_image = tci->is_image;
932 int initial = tci->initial;
933 int nr = tci->local_nr;
934 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
935 int base = (is_image ?
936 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
937 SND_BACKGROUND_TITLESCREEN_1) :
938 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
939 SND_BACKGROUND_TITLEMESSAGE_1));
940 int sound_global = menu.sound[mode];
941 int sound_local = base + nr;
944 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
945 nr, initial, is_image,
946 sound_global, getSoundListEntry(sound_global)->filename,
947 sound_local, getSoundListEntry(sound_local)->filename);
950 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
953 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
956 return SND_UNDEFINED;
959 static int getTitleMusic(struct TitleControlInfo *tci)
961 boolean is_image = tci->is_image;
962 int initial = tci->initial;
963 int nr = tci->local_nr;
964 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
965 int base = (is_image ?
966 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
967 MUS_BACKGROUND_TITLESCREEN_1) :
968 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
969 MUS_BACKGROUND_TITLEMESSAGE_1));
970 int music_global = menu.music[mode];
971 int music_local = base + nr;
974 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
975 nr, initial, is_image,
976 music_global, getMusicListEntry(music_global)->filename,
977 music_local, getMusicListEntry(music_local)->filename);
980 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
983 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
986 return MUS_UNDEFINED;
989 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
991 boolean is_image = tci->is_image;
992 boolean initial = tci->initial;
993 boolean first = tci->first;
994 int nr = tci->local_nr;
995 struct TitleMessageInfo tmi;
996 struct TitleFadingInfo ti;
998 tmi = (is_image ? (initial ? (first ?
999 titlescreen_initial_first[nr] :
1000 titlescreen_initial[nr])
1002 titlescreen_first[nr] :
1004 : (initial ? (first ?
1005 titlemessage_initial_first[nr] :
1006 titlemessage_initial[nr])
1008 titlemessage_first[nr] :
1009 titlemessage[nr])));
1011 ti.fade_mode = tmi.fade_mode;
1012 ti.fade_delay = tmi.fade_delay;
1013 ti.post_delay = tmi.post_delay;
1014 ti.auto_delay = tmi.auto_delay;
1015 ti.auto_delay_unit = tmi.auto_delay_unit;
1020 static int compareTitleControlInfo(const void *object1, const void *object2)
1022 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1023 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1026 if (tci1->initial != tci2->initial)
1027 compare_result = (tci1->initial ? -1 : +1);
1028 else if (tci1->sort_priority != tci2->sort_priority)
1029 compare_result = tci1->sort_priority - tci2->sort_priority;
1030 else if (tci1->is_image != tci2->is_image)
1031 compare_result = (tci1->is_image ? -1 : +1);
1033 compare_result = tci1->local_nr - tci2->local_nr;
1035 return compare_result;
1038 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1040 int nr, int sort_priority)
1042 title_controls[num_title_screens].is_image = is_image;
1043 title_controls[num_title_screens].initial = initial;
1044 title_controls[num_title_screens].local_nr = nr;
1045 title_controls[num_title_screens].sort_priority = sort_priority;
1047 title_controls[num_title_screens].first = FALSE; // will be set later
1049 num_title_screens++;
1052 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1056 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1058 int graphic = getTitleScreenGraphic(i, initial);
1059 Bitmap *bitmap = graphic_info[graphic].bitmap;
1060 int sort_priority = graphic_info[graphic].sort_priority;
1063 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1066 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1068 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1069 char *filename = getLevelSetTitleMessageFilename(i, initial);
1070 int sort_priority = tmi->sort_priority;
1072 if (filename != NULL)
1073 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1077 static void InitializeTitleControls(boolean show_title_initial)
1079 num_title_screens = 0;
1081 // 1st step: initialize title screens for game start (only when starting)
1082 if (show_title_initial)
1083 InitializeTitleControls_CheckTitleInfo(TRUE);
1085 // 2nd step: initialize title screens for current level set
1086 InitializeTitleControls_CheckTitleInfo(FALSE);
1088 // sort title screens according to sort_priority and title number
1089 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1090 compareTitleControlInfo);
1092 // mark first title screen
1093 title_controls[0].first = TRUE;
1096 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1098 return (pos != NULL && pos->x != -1 && pos->y != -1);
1101 static boolean visibleTextPos(struct TextPosInfo *pos)
1103 return (pos != NULL && pos->x != -1 && pos->y != -1);
1106 static void InitializeMainControls(void)
1108 boolean local_team_mode = (!network.enabled && setup.team_mode);
1111 // set main control text values to dynamically determined values
1112 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1114 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1115 menu.main.text.first_level.size));
1116 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1117 menu.main.text.last_level.size));
1118 strcpy(main_text_level_number, int2str(level_nr,
1119 menu.main.text.level_number.size));
1121 main_text_level_year = leveldir_current->year;
1122 main_text_level_imported_from = leveldir_current->imported_from;
1123 main_text_level_imported_by = leveldir_current->imported_by;
1124 main_text_level_tested_by = leveldir_current->tested_by;
1126 main_text_title_1 = getConfigProgramTitleString();
1127 main_text_title_2 = getConfigProgramCopyrightString();
1128 main_text_title_3 = getConfigProgramCompanyString();
1130 // set main control screen positions to dynamically determined values
1131 for (i = 0; main_controls[i].nr != -1; i++)
1133 struct MainControlInfo *mci = &main_controls[i];
1135 struct MenuPosInfo *pos_button = mci->pos_button;
1136 struct TextPosInfo *pos_text = mci->pos_text;
1137 struct TextPosInfo *pos_input = mci->pos_input;
1138 char *text = (mci->text ? *mci->text : NULL);
1139 char *input = (mci->input ? *mci->input : NULL);
1140 int button_graphic = mci->button_graphic;
1141 int font_text = (pos_text ? pos_text->font : -1);
1142 int font_input = (pos_input ? pos_input->font : -1);
1144 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1145 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1146 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1147 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1148 int text_chars = (text != NULL ? strlen(text) : 0);
1149 int input_chars = (input != NULL ? strlen(input) : 0);
1152 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1154 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1155 int text_width = font_text_width * text_chars;
1156 int text_height = font_text_height;
1157 int input_width = font_input_width * input_chars;
1158 int input_height = font_input_height;
1160 if (nr == MAIN_CONTROL_NAME)
1162 menu.main.input.name.width = input_width;
1163 menu.main.input.name.height = input_height;
1166 if (pos_button != NULL) // (x/y may be -1/-1 here)
1168 pos_button->width = button_width;
1169 pos_button->height = button_height;
1172 if (pos_text != NULL) // (x/y may be -1/-1 here)
1174 // calculate text size -- needed for text alignment
1175 boolean calculate_text_size = (text != NULL);
1177 if (pos_text->width == -1 || calculate_text_size)
1178 pos_text->width = text_width;
1179 if (pos_text->height == -1 || calculate_text_size)
1180 pos_text->height = text_height;
1182 if (visibleMenuPos(pos_button))
1184 if (pos_text->x == -1)
1185 pos_text->x = pos_button->x + pos_button->width;
1186 if (pos_text->y == -1)
1188 pos_button->y + (pos_button->height - pos_text->height) / 2;
1192 if (pos_input != NULL) // (x/y may be -1/-1 here)
1194 if (visibleTextPos(pos_text))
1196 if (pos_input->x == -1)
1197 pos_input->x = pos_text->x + pos_text->width;
1198 if (pos_input->y == -1)
1199 pos_input->y = pos_text->y;
1202 if (pos_input->width == -1)
1203 pos_input->width = input_width;
1204 if (pos_input->height == -1)
1205 pos_input->height = input_height;
1210 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1211 int graphic, boolean pressed)
1213 struct GraphicInfo *g = &graphic_info[graphic];
1216 int xoffset = (pressed ? g->pressed_xoffset : 0);
1217 int yoffset = (pressed ? g->pressed_yoffset : 0);
1219 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1221 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1222 g->width, g->height, dst_x, dst_y);
1225 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1226 boolean active_input,
1227 boolean pressed_button)
1231 for (i = 0; main_controls[i].nr != -1; i++)
1233 struct MainControlInfo *mci = &main_controls[i];
1235 if (mci->nr == nr || nr == -1)
1237 struct MenuPosInfo *pos_button = mci->pos_button;
1238 struct TextPosInfo *pos_text = mci->pos_text;
1239 struct TextPosInfo *pos_input = mci->pos_input;
1240 char *text = (mci->text ? *mci->text : NULL);
1241 char *input = (mci->input ? *mci->input : NULL);
1242 int button_graphic = mci->button_graphic;
1243 int font_text = (pos_text ? pos_text->font : -1);
1244 int font_input = (pos_input ? pos_input->font : -1);
1248 button_graphic = BUTTON_ACTIVE(button_graphic);
1249 font_text = FONT_ACTIVE(font_text);
1254 font_input = FONT_ACTIVE(font_input);
1257 if (visibleMenuPos(pos_button))
1259 struct MenuPosInfo *pos = pos_button;
1260 int x = mSX + pos->x;
1261 int y = mSY + pos->y;
1263 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1264 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1267 if (visibleTextPos(pos_text) && text != NULL)
1269 struct TextPosInfo *pos = pos_text;
1270 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1271 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1274 // (check why/if this is needed)
1275 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1277 DrawText(x, y, text, font_text);
1280 if (visibleTextPos(pos_input) && input != NULL)
1282 struct TextPosInfo *pos = pos_input;
1283 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1284 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1287 // (check why/if this is needed)
1288 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1290 DrawText(x, y, input, font_input);
1296 static void DrawCursorAndText_Main(int nr, boolean active_text,
1297 boolean pressed_button)
1299 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1303 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1304 boolean pressed_button)
1306 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1310 static struct MainControlInfo *getMainControlInfo(int nr)
1314 for (i = 0; main_controls[i].nr != -1; i++)
1315 if (main_controls[i].nr == nr)
1316 return &main_controls[i];
1321 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1326 int rect_x = ALIGNED_TEXT_XPOS(rect);
1327 int rect_y = ALIGNED_TEXT_YPOS(rect);
1329 return (x >= rect_x && x < rect_x + rect->width &&
1330 y >= rect_y && y < rect_y + rect->height);
1333 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1338 int rect_x = ALIGNED_TEXT_XPOS(rect);
1339 int rect_y = ALIGNED_TEXT_YPOS(rect);
1342 Debug("screens:insideTextPosRect",
1343 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1344 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1345 (x >= rect_x && x < rect_x + rect->width &&
1346 y >= rect_y && y < rect_y + rect->height));
1349 return (x >= rect_x && x < rect_x + rect->width &&
1350 y >= rect_y && y < rect_y + rect->height);
1353 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1355 int rect_width = preview->xsize * preview->tile_size;
1356 int rect_height = preview->ysize * preview->tile_size;
1357 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1358 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1360 return (x >= rect_x && x < rect_x + rect_width &&
1361 y >= rect_y && y < rect_y + rect_height);
1364 static void AdjustScrollbar(int id, int items_max, int items_visible,
1367 struct GadgetInfo *gi = screen_gadget[id];
1369 if (item_position > items_max - items_visible)
1370 item_position = items_max - items_visible;
1372 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1373 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1374 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1377 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1379 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1383 static void clearMenuListArea(void)
1385 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1387 // correct scrollbar position if placed outside menu (playfield) area
1388 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1389 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1391 // clear menu list area, but not title or scrollbar
1392 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1393 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1396 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1398 static int cursor_array[MAX_LEV_FIELDY];
1399 int x = amSX + TILEX * xpos;
1400 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1405 cursor_array[ypos] = graphic;
1407 graphic = cursor_array[ypos];
1411 graphic = BUTTON_ACTIVE(graphic);
1413 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1414 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1417 static void initCursor(int ypos, int graphic)
1419 drawCursorExt(0, ypos, FALSE, graphic);
1422 static void drawCursor(int ypos, boolean active)
1424 drawCursorExt(0, ypos, active, -1);
1427 static void drawCursorXY(int xpos, int ypos, int graphic)
1429 drawCursorExt(xpos, ypos, FALSE, graphic);
1432 static void drawChooseTreeCursor(int ypos, boolean active)
1434 drawCursorExt(0, ypos, active, -1);
1437 static int getChooseTreeEditFont(boolean active)
1439 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1442 static int getChooseTreeEditXPos(int pos)
1444 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1445 int xoffset = (has_scrollbar ? -1 : 0);
1446 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1447 int sx = amSX + xpos * TILEX;
1448 int font_nr = getChooseTreeEditFont(FALSE);
1449 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1451 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1454 static int getChooseTreeEditYPos(int ypos_raw)
1456 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1457 int sy = amSY + ypos * TILEY;
1462 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1464 int sx = getChooseTreeEditXPos(POS_LEFT);
1465 int sy = getChooseTreeEditYPos(ypos_raw);
1466 int font_nr = getChooseTreeEditFont(active);
1468 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1471 static void DrawHeadline(void)
1473 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1474 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1477 static void DrawTitleScreenImage(int nr, boolean initial)
1479 int graphic = getTitleScreenGraphic(nr, initial);
1480 Bitmap *bitmap = graphic_info[graphic].bitmap;
1481 int width = graphic_info[graphic].width;
1482 int height = graphic_info[graphic].height;
1483 int src_x = graphic_info[graphic].src_x;
1484 int src_y = graphic_info[graphic].src_y;
1490 if (width > WIN_XSIZE)
1492 // image width too large for window => center image horizontally
1493 src_x = (width - WIN_XSIZE) / 2;
1497 if (height > WIN_YSIZE)
1499 // image height too large for window => center image vertically
1500 src_y = (height - WIN_YSIZE) / 2;
1504 // always display title screens centered
1505 dst_x = (WIN_XSIZE - width) / 2;
1506 dst_y = (WIN_YSIZE - height) / 2;
1508 SetDrawBackgroundMask(REDRAW_ALL);
1509 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1511 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1513 if (DrawingOnBackground(dst_x, dst_y))
1514 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1516 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1518 redraw_mask = REDRAW_ALL;
1521 static void DrawTitleScreenMessage(int nr, boolean initial)
1523 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1524 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1526 if (filename == NULL)
1529 // force TITLE font on title message screen
1530 SetFontStatus(getTitleMessageGameMode(initial));
1532 // if chars *and* width set to "-1", automatically determine width
1533 if (tmi->chars == -1 && tmi->width == -1)
1534 tmi->width = viewport.window[game_status].width;
1536 // if lines *and* height set to "-1", automatically determine height
1537 if (tmi->lines == -1 && tmi->height == -1)
1538 tmi->height = viewport.window[game_status].height;
1540 // if chars set to "-1", automatically determine by text and font width
1541 if (tmi->chars == -1)
1542 tmi->chars = tmi->width / getFontWidth(tmi->font);
1544 tmi->width = tmi->chars * getFontWidth(tmi->font);
1546 // if lines set to "-1", automatically determine by text and font height
1547 if (tmi->lines == -1)
1548 tmi->lines = tmi->height / getFontHeight(tmi->font);
1550 tmi->height = tmi->lines * getFontHeight(tmi->font);
1552 // if x set to "-1", automatically determine by width and alignment
1554 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1556 // if y set to "-1", automatically determine by height and alignment
1558 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1560 SetDrawBackgroundMask(REDRAW_ALL);
1561 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1563 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1565 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1566 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1567 tmi->autowrap, tmi->centered, tmi->parse_comments);
1572 static void DrawTitleScreen(void)
1574 KeyboardAutoRepeatOff();
1576 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1579 static boolean CheckTitleScreen(boolean levelset_has_changed)
1581 static boolean show_title_initial = TRUE;
1582 boolean show_titlescreen = FALSE;
1584 // needed to be able to skip title screen, if no image or message defined
1585 InitializeTitleControls(show_title_initial);
1587 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1588 show_titlescreen = TRUE;
1590 // show initial title images and messages only once at program start
1591 show_title_initial = FALSE;
1593 return (show_titlescreen && num_title_screens > 0);
1596 void DrawMainMenu(void)
1598 static LevelDirTree *leveldir_last_valid = NULL;
1599 boolean levelset_has_changed = FALSE;
1600 int fade_mask = REDRAW_FIELD;
1602 LimitScreenUpdates(FALSE);
1604 FadeSetLeaveScreen();
1606 // do not fade out here -- function may continue and fade on editor screen
1609 FadeMenuSoundsAndMusic();
1611 ExpireSoundLoops(FALSE);
1613 KeyboardAutoRepeatOn();
1615 audio.sound_deactivated = FALSE;
1619 // needed if last screen was the playing screen, invoked from level editor
1620 if (level_editor_test_game)
1622 CloseDoor(DOOR_CLOSE_ALL);
1624 SetGameStatus(GAME_MODE_EDITOR);
1631 // leveldir_current may be invalid (level group, parent link)
1632 if (!validLevelSeries(leveldir_current))
1633 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1635 if (leveldir_current != leveldir_last_valid)
1636 levelset_has_changed = TRUE;
1638 // store valid level series information
1639 leveldir_last_valid = leveldir_current;
1641 init_last = init; // switch to new busy animation
1643 // needed if last screen (level choice) changed graphics, sounds or music
1644 ReloadCustomArtwork(0);
1646 if (CheckTitleScreen(levelset_has_changed))
1648 SetGameStatus(GAME_MODE_TITLE);
1655 if (redraw_mask & REDRAW_ALL)
1656 fade_mask = REDRAW_ALL;
1659 fade_mask = REDRAW_ALL;
1663 // needed if different viewport properties defined for menues
1664 ChangeViewportPropertiesIfNeeded();
1666 SetDrawtoField(DRAW_TO_BACKBUFFER);
1668 // level_nr may have been set to value over handicap with level editor
1669 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1670 level_nr = leveldir_current->handicap_level;
1672 LoadLevel(level_nr);
1673 LoadScore(level_nr);
1675 SaveLevelSetup_SeriesInfo();
1677 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1678 SetDrawDeactivationMask(REDRAW_NONE);
1679 SetDrawBackgroundMask(REDRAW_FIELD);
1681 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1684 if (fade_mask == REDRAW_ALL)
1685 RedrawGlobalBorder();
1690 InitializeMainControls();
1692 DrawCursorAndText_Main(-1, FALSE, FALSE);
1693 DrawPreviewLevelInitial();
1694 DrawNetworkPlayers();
1696 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1699 if (TAPE_IS_EMPTY(tape))
1701 DrawCompleteVideoDisplay();
1703 PlayMenuSoundsAndMusic();
1705 // create gadgets for main menu screen
1706 FreeScreenGadgets();
1707 CreateScreenGadgets();
1709 // may be required if audio buttons shown on tape and changed in setup menu
1711 CreateGameButtons();
1713 // map gadgets for main menu screen
1715 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1716 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1718 // copy actual game door content to door double buffer for OpenDoor()
1719 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1720 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1722 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1724 DrawMaskedBorder(fade_mask);
1729 // update screen area with special editor door
1730 redraw_mask |= REDRAW_ALL;
1733 SetMouseCursor(CURSOR_DEFAULT);
1735 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1738 static void gotoTopLevelDir(void)
1740 // move upwards until inside (but not above) top level directory
1741 while (leveldir_current->node_parent &&
1742 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1744 // write a "path" into level tree for easy navigation to last level
1745 if (leveldir_current->node_parent->node_group->cl_first == -1)
1747 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1748 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1749 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1750 int cl_first, cl_cursor;
1752 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1753 cl_cursor = leveldir_pos - cl_first;
1755 leveldir_current->node_parent->node_group->cl_first = cl_first;
1756 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1759 leveldir_current = leveldir_current->node_parent;
1763 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1765 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1767 return (use_frame_counter ? video.frame_counter : Counter());
1770 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1771 struct TitleFadingInfo *fi)
1773 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1776 static void ResetTitleAutoDelay(unsigned int *counter_var,
1777 struct TitleFadingInfo *fi)
1779 *counter_var = getAutoDelayCounter(fi);
1782 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1784 static unsigned int title_delay = 0;
1785 static int title_screen_nr = 0;
1786 static int last_sound = -1, last_music = -1;
1787 boolean return_to_main_menu = FALSE;
1788 struct TitleControlInfo *tci;
1791 if (button == MB_MENU_INITIALIZE)
1794 title_screen_nr = 0;
1795 tci = &title_controls[title_screen_nr];
1797 SetAnimStatus(getTitleAnimMode(tci));
1799 last_sound = SND_UNDEFINED;
1800 last_music = MUS_UNDEFINED;
1802 if (num_title_screens != 0)
1804 FadeSetEnterScreen();
1806 // use individual title fading instead of global "enter screen" fading
1807 fading = getTitleFading(tci);
1810 if (game_status_last_screen == GAME_MODE_INFO)
1812 if (num_title_screens == 0)
1814 // switch game mode from title screen mode back to info screen mode
1815 SetGameStatus(GAME_MODE_INFO);
1817 // store that last screen was info screen, not main menu screen
1818 game_status_last_screen = GAME_MODE_INFO;
1820 DrawInfoScreen_NotAvailable("Title screen information:",
1821 "No title screen for this level set.");
1826 FadeMenuSoundsAndMusic();
1828 FadeOut(REDRAW_ALL);
1830 // title screens may have different window size
1831 ChangeViewportPropertiesIfNeeded();
1833 // only required to update logic for redrawing global border
1837 DrawTitleScreenImage(tci->local_nr, tci->initial);
1839 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1841 sound = getTitleSound(tci);
1842 music = getTitleMusic(tci);
1844 if (sound != last_sound)
1845 PlayMenuSoundExt(sound);
1846 if (music != last_music)
1847 PlayMenuMusicExt(music);
1852 SetMouseCursor(CURSOR_NONE);
1856 ResetTitleAutoDelay(&title_delay, &fading);
1861 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1862 button = MB_MENU_CHOICE;
1864 if (button == MB_MENU_LEAVE)
1866 return_to_main_menu = TRUE;
1868 else if (button == MB_MENU_CHOICE)
1870 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1872 SetGameStatus(GAME_MODE_INFO);
1874 info_mode = INFO_MODE_MAIN;
1883 if (title_screen_nr < num_title_screens)
1885 tci = &title_controls[title_screen_nr];
1887 SetAnimStatus(getTitleAnimMode(tci));
1889 sound = getTitleSound(tci);
1890 music = getTitleMusic(tci);
1892 if (last_sound != SND_UNDEFINED && sound != last_sound)
1893 FadeSound(last_sound);
1894 if (last_music != MUS_UNDEFINED && music != last_music)
1897 fading = getTitleFading(tci);
1899 FadeOut(REDRAW_ALL);
1902 DrawTitleScreenImage(tci->local_nr, tci->initial);
1904 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1906 sound = getTitleSound(tci);
1907 music = getTitleMusic(tci);
1909 if (sound != last_sound)
1910 PlayMenuSoundExt(sound);
1911 if (music != last_music)
1912 PlayMenuMusicExt(music);
1919 ResetTitleAutoDelay(&title_delay, &fading);
1923 FadeMenuSoundsAndMusic();
1925 return_to_main_menu = TRUE;
1929 if (return_to_main_menu)
1931 SetMouseCursor(CURSOR_DEFAULT);
1933 // force full menu screen redraw after displaying title screens
1934 redraw_mask = REDRAW_ALL;
1936 if (game_status_last_screen == GAME_MODE_INFO)
1938 SetGameStatus(GAME_MODE_INFO);
1940 info_mode = INFO_MODE_MAIN;
1944 else // default: return to main menu
1946 SetGameStatus(GAME_MODE_MAIN);
1953 static void HandleMainMenu_SelectLevel(int step, int direction,
1954 int selected_level_nr)
1956 int old_level_nr = level_nr;
1959 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1960 new_level_nr = selected_level_nr;
1962 new_level_nr = old_level_nr + step * direction;
1964 if (new_level_nr < leveldir_current->first_level)
1965 new_level_nr = leveldir_current->first_level;
1966 if (new_level_nr > leveldir_current->last_level)
1967 new_level_nr = leveldir_current->last_level;
1969 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1971 // skipping levels is only allowed when trying to skip single level
1972 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1973 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1975 leveldir_current->handicap_level++;
1976 SaveLevelSetup_SeriesInfo();
1979 new_level_nr = leveldir_current->handicap_level;
1982 if (new_level_nr != old_level_nr)
1984 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1986 PlaySound(SND_MENU_ITEM_SELECTING);
1988 level_nr = new_level_nr;
1990 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1991 int2str(level_nr, menu.main.text.level_number.size),
1992 mci->pos_text->font);
1994 LoadLevel(level_nr);
1995 DrawPreviewLevelInitial();
1999 DrawCompleteVideoDisplay();
2001 SaveLevelSetup_SeriesInfo();
2003 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2005 // force redraw of playfield area (may be reset at this point)
2006 redraw_mask |= REDRAW_FIELD;
2010 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2012 static int choice = MAIN_CONTROL_GAME;
2013 static boolean button_pressed_last = FALSE;
2014 boolean button_pressed = FALSE;
2016 int i = 0; // needed to prevent compiler warning due to bad code below
2018 if (button == MB_MENU_INITIALIZE)
2020 DrawCursorAndText_Main(choice, TRUE, FALSE);
2025 if (mx || my) // mouse input
2029 for (i = 0; main_controls[i].nr != -1; i++)
2031 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2032 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2033 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2035 pos = main_controls[i].nr;
2041 // check if level preview was clicked
2042 if (insidePreviewRect(&preview, mx - SX, my - SY))
2043 pos = MAIN_CONTROL_GAME;
2045 // handle pressed/unpressed state for active/inactive menu buttons
2046 // (if pos != -1, "i" contains index position corresponding to "pos")
2048 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2049 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2050 button_pressed = TRUE;
2052 if (button_pressed != button_pressed_last)
2054 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2057 PlaySound(SND_MENU_BUTTON_PRESSING);
2059 PlaySound(SND_MENU_BUTTON_RELEASING);
2062 else if (dx || dy) // keyboard input
2064 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2065 choice == MAIN_CONTROL_SETUP))
2066 button = MB_MENU_CHOICE;
2071 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2073 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2075 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2077 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2079 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2081 CloseDoor(DOOR_CLOSE_2);
2083 SetGameStatus(GAME_MODE_LEVELNR);
2085 DrawChooseLevelNr();
2087 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2093 PlaySound(SND_MENU_ITEM_ACTIVATING);
2095 DrawCursorAndText_Main(choice, FALSE, FALSE);
2096 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2102 if (choice != MAIN_CONTROL_INFO &&
2103 choice != MAIN_CONTROL_SETUP)
2104 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2109 PlaySound(SND_MENU_ITEM_SELECTING);
2111 if (pos == MAIN_CONTROL_NAME)
2114 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2116 // special case: menu text "name/team" clicked -- toggle team mode
2117 setup.team_mode = !setup.team_mode;
2119 InitializeMainControls();
2120 DrawCursorAndText_Main(choice, TRUE, FALSE);
2122 DrawPreviewPlayers();
2126 if (setup.multiple_users)
2128 CloseDoor(DOOR_CLOSE_2);
2130 SetGameStatus(GAME_MODE_NAMES);
2132 DrawChoosePlayerName();
2136 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2142 else if (pos == MAIN_CONTROL_LEVELS)
2146 CloseDoor(DOOR_CLOSE_2);
2148 SetGameStatus(GAME_MODE_LEVELS);
2150 SaveLevelSetup_LastSeries();
2151 SaveLevelSetup_SeriesInfo();
2153 if (setup.internal.choose_from_top_leveldir)
2156 DrawChooseLevelSet();
2159 else if (pos == MAIN_CONTROL_SCORES)
2161 CloseDoor(DOOR_CLOSE_2);
2163 SetGameStatus(GAME_MODE_SCORES);
2165 DrawHallOfFame(level_nr, -1);
2167 else if (pos == MAIN_CONTROL_EDITOR)
2169 if (leveldir_current->readonly &&
2170 !strEqual(setup.player_name, "Artsoft"))
2171 Request("This level is read only!", REQ_CONFIRM);
2173 CloseDoor(DOOR_CLOSE_2);
2175 SetGameStatus(GAME_MODE_EDITOR);
2177 FadeSetEnterScreen();
2181 else if (pos == MAIN_CONTROL_INFO)
2183 CloseDoor(DOOR_CLOSE_2);
2185 SetGameStatus(GAME_MODE_INFO);
2187 info_mode = INFO_MODE_MAIN;
2191 else if (pos == MAIN_CONTROL_GAME)
2193 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2195 else if (pos == MAIN_CONTROL_SETUP)
2197 CloseDoor(DOOR_CLOSE_2);
2199 SetGameStatus(GAME_MODE_SETUP);
2201 setup_mode = SETUP_MODE_MAIN;
2205 else if (pos == MAIN_CONTROL_QUIT)
2207 SaveLevelSetup_LastSeries();
2208 SaveLevelSetup_SeriesInfo();
2210 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2211 SetGameStatus(GAME_MODE_QUIT);
2216 button_pressed_last = button_pressed;
2220 // ============================================================================
2221 // info screen functions
2222 // ============================================================================
2224 static struct TokenInfo *info_info;
2225 static int num_info_info; // number of info entries shown on screen
2226 static int max_info_info; // total number of info entries in list
2228 static void execInfoTitleScreen(void)
2230 info_mode = INFO_MODE_TITLE;
2235 static void execInfoElements(void)
2237 info_mode = INFO_MODE_ELEMENTS;
2242 static void execInfoMusic(void)
2244 info_mode = INFO_MODE_MUSIC;
2249 static void execInfoCredits(void)
2251 info_mode = INFO_MODE_CREDITS;
2256 static void execInfoProgram(void)
2258 info_mode = INFO_MODE_PROGRAM;
2263 static void execInfoVersion(void)
2265 info_mode = INFO_MODE_VERSION;
2270 static void execInfoLevelSet(void)
2272 info_mode = INFO_MODE_LEVELSET;
2277 static void execExitInfo(void)
2279 SetGameStatus(GAME_MODE_MAIN);
2284 static struct TokenInfo info_info_main[] =
2286 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2287 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2288 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2289 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2290 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2291 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2292 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2293 { TYPE_EMPTY, NULL, "" },
2294 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2299 static int getMenuTextFont(int type)
2301 if (type & (TYPE_SWITCH |
2315 static struct TokenInfo *setup_info;
2316 static struct TokenInfo setup_info_input[];
2318 static struct TokenInfo *menu_info;
2320 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2321 int screen_pos, int menu_info_pos_raw,
2324 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2325 struct TokenInfo *ti = &token_info[pos];
2326 int xpos = MENU_SCREEN_START_XPOS;
2327 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2328 int font_nr = getMenuTextFont(ti->type);
2330 if (setup_mode == SETUP_MODE_INPUT)
2331 font_nr = FONT_MENU_1;
2334 font_nr = FONT_ACTIVE(font_nr);
2336 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2338 if (ti->type & ~TYPE_SKIP_ENTRY)
2339 drawCursor(screen_pos, active);
2342 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2345 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2348 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2351 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2354 static char *window_size_text;
2355 static char *scaling_type_text;
2356 static char *network_server_text;
2358 static void drawSetupValue(int, int);
2360 static void drawMenuInfoList(int first_entry, int num_page_entries,
2361 int max_page_entries)
2365 if (first_entry + num_page_entries > max_page_entries)
2368 clearMenuListArea();
2370 for (i = 0; i < num_page_entries; i++)
2372 int menu_info_pos = first_entry + i;
2373 struct TokenInfo *si = &menu_info[menu_info_pos];
2374 void *value_ptr = si->value;
2376 // set some entries to "unchangeable" according to other variables
2377 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2378 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2379 (value_ptr == &setup.sound_music && !audio.music_available) ||
2380 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2381 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2382 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2383 si->type |= TYPE_GHOSTED;
2385 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2386 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2387 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2388 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2389 else if (si->type & ~TYPE_SKIP_ENTRY)
2390 initCursor(i, IMG_MENU_BUTTON);
2392 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2394 if (si->type & TYPE_STRING)
2398 if (value_ptr == &network_server_text)
2399 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2401 if (gadget_id != -1)
2403 struct GadgetInfo *gi = screen_gadget[gadget_id];
2404 int xpos = MENU_SCREEN_START_XPOS;
2405 int ypos = MENU_SCREEN_START_YPOS + i;
2406 int x = mSX + xpos * 32;
2407 int y = mSY + ypos * 32;
2409 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2413 if (si->type & TYPE_VALUE &&
2414 menu_info == setup_info)
2415 drawSetupValue(i, menu_info_pos);
2419 static void DrawInfoScreen_Main(void)
2421 int fade_mask = REDRAW_FIELD;
2424 if (redraw_mask & REDRAW_ALL)
2425 fade_mask = REDRAW_ALL;
2428 fade_mask = REDRAW_ALL;
2431 FadeMenuSoundsAndMusic();
2433 FreeScreenGadgets();
2434 CreateScreenGadgets();
2436 // (needed after displaying title screens which disable auto repeat)
2437 KeyboardAutoRepeatOn();
2439 FadeSetLeaveScreen();
2443 // needed if different viewport properties defined for info screen
2444 ChangeViewportPropertiesIfNeeded();
2446 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2450 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2452 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2454 info_info = info_info_main;
2456 // determine maximal number of info entries that can be displayed on screen
2458 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2461 // determine maximal number of info entries available for menu of info screen
2463 for (i = 0; info_info[i].type != 0; i++)
2466 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2468 MapScreenGadgets(max_info_info);
2470 PlayMenuSoundsAndMusic();
2472 DrawMaskedBorder(fade_mask);
2477 static void changeSetupValue(int, int, int);
2479 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2480 int mode, int num_page_entries,
2481 int max_page_entries)
2483 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2484 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2485 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2486 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2487 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2488 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2489 int *num_page_entries_last = num_page_entries_all_last[game_status];
2490 int *choice_store = choice_stores[game_status];
2491 int *first_entry_store = first_entry_stores[game_status];
2492 int choice = choice_store[mode]; // starts with 0
2493 int first_entry = first_entry_store[mode]; // starts with 0
2495 int y = choice - first_entry;
2497 boolean position_set_by_scrollbar = (dx == 999);
2498 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2501 if (button == MB_MENU_INITIALIZE)
2503 // check if number of menu page entries has changed (may happen by change
2504 // of custom artwork definition value for 'list_size' for this menu screen)
2505 // (in this case, the last menu position most probably has to be corrected)
2506 if (num_page_entries != num_page_entries_last[mode])
2508 choice_store[mode] = first_entry_store[mode] = 0;
2510 choice = first_entry = 0;
2513 num_page_entries_last[mode] = num_page_entries;
2516 // advance to first valid menu entry
2517 while (choice < num_page_entries &&
2518 menu_info[choice].type & TYPE_SKIP_ENTRY)
2521 if (position_set_by_scrollbar)
2522 first_entry = first_entry_store[mode] = dy;
2524 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2525 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2527 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2529 if (choice < first_entry)
2531 choice = first_entry;
2533 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2536 else if (choice > first_entry + num_page_entries - 1)
2538 choice = first_entry + num_page_entries - 1;
2540 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2544 choice_store[mode] = choice;
2546 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2550 else if (button == MB_MENU_LEAVE)
2552 PlaySound(SND_MENU_ITEM_SELECTING);
2554 for (i = 0; i < max_page_entries; i++)
2556 if (menu_info[i].type & TYPE_LEAVE_MENU)
2558 void (*menu_callback_function)(void) = menu_info[i].value;
2562 menu_callback_function();
2564 break; // absolutely needed because function changes 'menu_info'!
2571 if (mx || my) // mouse input
2573 x = (mx - mSX) / 32;
2574 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2576 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2578 // move cursor instead of scrolling when already at start/end of list
2579 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2581 else if (dy == +1 * SCROLL_LINE &&
2582 first_entry + num_page_entries == max_page_entries)
2585 // handle scrolling screen one line or page
2587 y + dy > num_page_entries - 1)
2589 boolean redraw = FALSE;
2591 if (ABS(dy) == SCROLL_PAGE)
2592 step = num_page_entries - 1;
2594 if (dy < 0 && first_entry > 0)
2596 // scroll page/line up
2598 first_entry -= step;
2599 if (first_entry < 0)
2604 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2606 // scroll page/line down
2608 first_entry += step;
2609 if (first_entry + num_page_entries > max_page_entries)
2610 first_entry = MAX(0, max_page_entries - num_page_entries);
2617 choice += first_entry - first_entry_store[mode];
2619 if (choice < first_entry)
2621 choice = first_entry;
2623 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2626 else if (choice > first_entry + num_page_entries - 1)
2628 choice = first_entry + num_page_entries - 1;
2630 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2633 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2637 if (choice < first_entry ||
2638 choice > first_entry + num_page_entries - 1)
2639 first_entry += SIGN(dy);
2642 first_entry_store[mode] = first_entry;
2643 choice_store[mode] = choice;
2645 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2647 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2649 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2650 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2658 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2660 if (menu_info[choice].type & menu_navigation_type ||
2661 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2662 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2663 menu_info[choice].type & TYPE_PLAYER)
2664 button = MB_MENU_CHOICE;
2669 // jump to next non-empty menu entry (up or down)
2670 while (first_entry + y > 0 &&
2671 first_entry + y < max_page_entries - 1 &&
2672 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2675 if (!IN_VIS_MENU(x, y))
2677 choice += y - y_old;
2679 if (choice < first_entry)
2680 first_entry = choice;
2681 else if (choice > first_entry + num_page_entries - 1)
2682 first_entry = choice - num_page_entries + 1;
2684 if (first_entry >= 0 &&
2685 first_entry + num_page_entries <= max_page_entries)
2687 first_entry_store[mode] = first_entry;
2689 if (choice < first_entry)
2690 choice = first_entry;
2691 else if (choice > first_entry + num_page_entries - 1)
2692 choice = first_entry + num_page_entries - 1;
2694 choice_store[mode] = choice;
2696 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2698 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2700 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2701 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2708 if (!anyScrollbarGadgetActive() &&
2709 IN_VIS_MENU(x, y) &&
2710 mx < mx_right_border &&
2711 y >= 0 && y < num_page_entries)
2715 if (first_entry + y != choice &&
2716 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2718 PlaySound(SND_MENU_ITEM_ACTIVATING);
2720 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2721 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2723 choice = choice_store[mode] = first_entry + y;
2727 PlaySound(SND_MENU_ITEM_SELECTING);
2729 for (i = 0; menu_info[i].type != 0; i++)
2731 if (menu_info[i].type & TYPE_LEAVE_MENU)
2733 void (*menu_callback_function)(void) = menu_info[i].value;
2737 menu_callback_function();
2739 // absolutely needed because function changes 'menu_info'!
2747 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2749 PlaySound(SND_MENU_ITEM_SELECTING);
2751 // when selecting key headline, execute function for key value change
2752 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2753 menu_info[first_entry + y + 1].type & TYPE_KEY)
2756 // when selecting string value, execute function for list selection
2757 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2758 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2761 // when selecting string value, execute function for text input gadget
2762 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2763 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2766 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2768 void (*menu_callback_function)(void) =
2769 menu_info[first_entry + y].value;
2771 FadeSetFromType(menu_info[first_entry + y].type);
2773 menu_callback_function();
2775 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2777 void (*gadget_callback_function)(void) =
2778 menu_info[first_entry + y].value;
2780 gadget_callback_function();
2782 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2783 menu_info == setup_info)
2785 changeSetupValue(y, first_entry + y, dx);
2791 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2793 menu_info = info_info;
2795 HandleMenuScreen(mx, my, dx, dy, button,
2796 info_mode, num_info_info, max_info_info);
2799 static int getMenuFontSpacing(int spacing_height, int font_nr)
2801 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2803 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2807 static int getMenuTextSpacing(int spacing_height, int font_nr)
2809 return (getMenuFontSpacing(spacing_height, font_nr) +
2810 EXTRA_SPACING(game_status));
2813 static int getMenuTextStep(int spacing_height, int font_nr)
2815 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2818 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2820 int font_title = MENU_INFO_FONT_TITLE;
2821 int font_error = FONT_TEXT_2;
2822 int font_foot = MENU_INFO_FONT_FOOT;
2823 int spacing_title = menu.headline1_spacing_info[info_mode];
2824 int ystep_title = getMenuTextStep(spacing_title, font_title);
2825 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2826 int ystart2 = ystart1 + ystep_title;
2827 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2829 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2831 FadeOut(REDRAW_FIELD);
2836 DrawTextSCentered(ystart1, font_title, text_title);
2837 DrawTextSCentered(ystart2, font_error, text_error);
2839 DrawTextSCentered(ybottom, font_foot,
2840 "Press any key or button for info menu");
2842 FadeIn(REDRAW_FIELD);
2845 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2847 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2848 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2849 int font_title = MENU_INFO_FONT_TITLE;
2850 int font_foot = MENU_INFO_FONT_FOOT;
2851 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2852 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2853 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2854 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2855 int ystep = MENU_SCREEN_INFO_YSTEP;
2856 int element, action, direction;
2864 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2865 infoscreen_step[i] = infoscreen_frame[i] = 0;
2870 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2872 DrawTextSCentered(ybottom, font_foot,
2873 "Press any key or button for next page");
2879 while (helpanim_info[j].element != HELPANIM_LIST_END)
2881 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2886 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2895 j += infoscreen_step[i - start];
2897 element = helpanim_info[j].element;
2898 action = helpanim_info[j].action;
2899 direction = helpanim_info[j].direction;
2902 element = EL_UNKNOWN;
2904 if (action != -1 && direction != -1)
2905 graphic = el_act_dir2img(element, action, direction);
2906 else if (action != -1)
2907 graphic = el_act2img(element, action);
2908 else if (direction != -1)
2909 graphic = el_dir2img(element, direction);
2911 graphic = el2img(element);
2913 delay = helpanim_info[j++].delay;
2918 if (infoscreen_frame[i - start] == 0)
2921 infoscreen_frame[i - start] = delay - 1;
2925 sync_frame = delay - infoscreen_frame[i - start];
2926 infoscreen_frame[i - start]--;
2929 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2931 if (!infoscreen_frame[i - start])
2932 infoscreen_step[i - start] = 0;
2936 if (!infoscreen_frame[i - start])
2937 infoscreen_step[i - start]++;
2938 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2944 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2946 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2947 graphic, sync_frame, USE_MASKING);
2950 DrawInfoScreen_HelpText(element, action, direction, i - start);
2955 redraw_mask |= REDRAW_FIELD;
2960 static char *getHelpText(int element, int action, int direction)
2962 char token[MAX_LINE_LEN];
2964 strcpy(token, element_info[element].token_name);
2967 strcat(token, element_action_info[action].suffix);
2969 if (direction != -1)
2970 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2972 return getHashEntry(helptext_info, token);
2975 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2977 int font_nr = FONT_INFO_ELEMENTS;
2978 int font_width = getFontWidth(font_nr);
2979 int font_height = getFontHeight(font_nr);
2980 int yoffset = (TILEX - 2 * font_height) / 2;
2981 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2982 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2983 int ystep = TILEY + 4;
2984 int pad_left = xstart - SX;
2985 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2986 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2987 int max_lines_per_text = 2;
2990 if (action != -1 && direction != -1) // element.action.direction
2991 text = getHelpText(element, action, direction);
2993 if (text == NULL && action != -1) // element.action
2994 text = getHelpText(element, action, -1);
2996 if (text == NULL && direction != -1) // element.direction
2997 text = getHelpText(element, -1, direction);
2999 if (text == NULL) // base element
3000 text = getHelpText(element, -1, -1);
3002 if (text == NULL) // not found
3003 text = "No description available";
3005 if (strlen(text) <= max_chars_per_line) // only one line of text
3006 ystart += getFontHeight(font_nr) / 2;
3008 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3009 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3010 TRUE, FALSE, FALSE);
3013 static void DrawInfoScreen_TitleScreen(void)
3015 SetGameStatus(GAME_MODE_TITLE);
3020 void HandleInfoScreen_TitleScreen(int button)
3022 HandleTitleScreen(0, 0, 0, 0, button);
3025 static void DrawInfoScreen_Elements(void)
3027 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3029 FadeOut(REDRAW_FIELD);
3034 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
3036 FadeIn(REDRAW_FIELD);
3039 void HandleInfoScreen_Elements(int button)
3041 static unsigned int info_delay = 0;
3042 static int num_anims;
3043 static int num_pages;
3045 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3048 if (button == MB_MENU_INITIALIZE)
3050 boolean new_element = TRUE;
3054 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3056 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3058 else if (new_element)
3061 new_element = FALSE;
3065 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3069 if (button == MB_MENU_LEAVE)
3071 PlaySound(SND_MENU_ITEM_SELECTING);
3073 info_mode = INFO_MODE_MAIN;
3078 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3080 if (button != MB_MENU_INITIALIZE)
3082 PlaySound(SND_MENU_ITEM_SELECTING);
3087 if (page >= num_pages)
3089 FadeMenuSoundsAndMusic();
3091 info_mode = INFO_MODE_MAIN;
3098 FadeSetNextScreen();
3100 if (button != MB_MENU_INITIALIZE)
3101 FadeOut(REDRAW_FIELD);
3103 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3105 if (button != MB_MENU_INITIALIZE)
3106 FadeIn(REDRAW_FIELD);
3110 if (DelayReached(&info_delay, GameFrameDelay))
3111 if (page < num_pages)
3112 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3114 PlayMenuSoundIfLoop();
3118 static void DrawInfoScreen_Music(void)
3120 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3122 FadeOut(REDRAW_FIELD);
3129 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3131 FadeIn(REDRAW_FIELD);
3134 void HandleInfoScreen_Music(int button)
3136 static struct MusicFileInfo *list = NULL;
3137 int font_title = MENU_INFO_FONT_TITLE;
3138 int font_head = MENU_INFO_FONT_HEAD;
3139 int font_text = MENU_INFO_FONT_TEXT;
3140 int font_foot = MENU_INFO_FONT_FOOT;
3141 int spacing_title = menu.headline1_spacing_info[info_mode];
3142 int spacing_head = menu.headline2_spacing_info[info_mode];
3143 int ystep_title = getMenuTextStep(spacing_title, font_title);
3144 int ystep_head = getMenuTextStep(spacing_head, font_head);
3145 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3146 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3148 if (button == MB_MENU_INITIALIZE)
3150 list = music_file_info;
3154 FadeMenuSoundsAndMusic();
3159 DrawTextSCentered(ystart, font_title,
3160 "No music info for this level set.");
3162 DrawTextSCentered(ybottom, font_foot,
3163 "Press any key or button for info menu");
3169 if (button == MB_MENU_LEAVE)
3171 PlaySound(SND_MENU_ITEM_SELECTING);
3173 FadeMenuSoundsAndMusic();
3175 info_mode = INFO_MODE_MAIN;
3180 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3182 if (button != MB_MENU_INITIALIZE)
3184 PlaySound(SND_MENU_ITEM_SELECTING);
3192 FadeMenuSoundsAndMusic();
3194 info_mode = INFO_MODE_MAIN;
3200 FadeMenuSoundsAndMusic();
3202 if (list != music_file_info)
3203 FadeSetNextScreen();
3205 if (button != MB_MENU_INITIALIZE)
3206 FadeOut(REDRAW_FIELD);
3213 int sound = list->music;
3215 if (sound_info[sound].loop)
3216 PlaySoundLoop(sound);
3220 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3224 int music = list->music;
3226 if (music_info[music].loop)
3227 PlayMusicLoop(music);
3231 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3234 ystart += ystep_title;
3236 if (!strEqual(list->title, UNKNOWN_NAME))
3238 if (!strEqual(list->title_header, UNKNOWN_NAME))
3240 DrawTextSCentered(ystart, font_head, list->title_header);
3241 ystart += ystep_head;
3244 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3245 ystart += ystep_head;
3248 if (!strEqual(list->artist, UNKNOWN_NAME))
3250 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3251 DrawTextSCentered(ystart, font_head, list->artist_header);
3253 DrawTextSCentered(ystart, font_head, "by");
3255 ystart += ystep_head;
3257 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3258 ystart += ystep_head;
3261 if (!strEqual(list->album, UNKNOWN_NAME))
3263 if (!strEqual(list->album_header, UNKNOWN_NAME))
3264 DrawTextSCentered(ystart, font_head, list->album_header);
3266 DrawTextSCentered(ystart, font_head, "from the album");
3268 ystart += ystep_head;
3270 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3271 ystart += ystep_head;
3274 if (!strEqual(list->year, UNKNOWN_NAME))
3276 if (!strEqual(list->year_header, UNKNOWN_NAME))
3277 DrawTextSCentered(ystart, font_head, list->year_header);
3279 DrawTextSCentered(ystart, font_head, "from the year");
3281 ystart += ystep_head;
3283 DrawTextFCentered(ystart, font_text, "%s", list->year);
3284 ystart += ystep_head;
3287 DrawTextSCentered(ybottom, FONT_TEXT_4,
3288 "Press any key or button for next page");
3290 if (button != MB_MENU_INITIALIZE)
3291 FadeIn(REDRAW_FIELD);
3294 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3295 PlaySoundLoop(list->music);
3298 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3300 int font_title = MENU_INFO_FONT_TITLE;
3301 int font_head = MENU_INFO_FONT_HEAD;
3302 int font_text = MENU_INFO_FONT_TEXT;
3303 int font_foot = MENU_INFO_FONT_FOOT;
3304 int spacing_title = menu.headline1_spacing_info[info_mode];
3305 int spacing_head = menu.headline2_spacing_info[info_mode];
3306 int spacing_para = menu.paragraph_spacing_info[info_mode];
3307 int spacing_line = menu.line_spacing_info[info_mode];
3308 int ystep_title = getMenuTextStep(spacing_title, font_title);
3309 int ystep_head = getMenuTextStep(spacing_head, font_head);
3310 int ystep_para = getMenuTextStep(spacing_para, font_text);
3311 int ystep_line = getMenuTextStep(spacing_line, font_text);
3312 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3313 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3318 DrawTextSCentered(ystart, font_title, "Credits:");
3319 ystart += ystep_title;
3323 DrawTextSCentered(ystart, font_head,
3324 "Special thanks to");
3325 ystart += ystep_head;
3326 DrawTextSCentered(ystart, font_text,
3328 ystart += ystep_head;
3329 DrawTextSCentered(ystart, font_head,
3331 ystart += ystep_head;
3332 DrawTextSCentered(ystart, font_text,
3333 "\"Boulder Dash\"");
3334 ystart += ystep_head;
3335 DrawTextSCentered(ystart, font_head,
3337 ystart += ystep_head;
3338 DrawTextSCentered(ystart, font_text,
3340 ystart += ystep_head;
3341 DrawTextSCentered(ystart, font_head,
3343 ystart += ystep_head;
3344 DrawTextSCentered(ystart, font_text,
3345 "First Star Software");
3347 else if (screen_nr == 1)
3349 DrawTextSCentered(ystart, font_head,
3350 "Special thanks to");
3351 ystart += ystep_head;
3352 DrawTextSCentered(ystart, font_text,
3353 "Klaus Heinz & Volker Wertich");
3354 ystart += ystep_head;
3355 DrawTextSCentered(ystart, font_head,
3357 ystart += ystep_head;
3358 DrawTextSCentered(ystart, font_text,
3359 "\"Emerald Mine\"");
3360 ystart += ystep_head;
3361 DrawTextSCentered(ystart, font_head,
3363 ystart += ystep_head;
3364 DrawTextSCentered(ystart, font_text,
3366 ystart += ystep_head;
3367 DrawTextSCentered(ystart, font_head,
3369 ystart += ystep_head;
3370 DrawTextSCentered(ystart, font_text,
3373 else if (screen_nr == 2)
3375 DrawTextSCentered(ystart, font_head,
3376 "Special thanks to");
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_text,
3379 "Michael Stopp & Philip Jespersen");
3380 ystart += ystep_head;
3381 DrawTextSCentered(ystart, font_head,
3383 ystart += ystep_head;
3384 DrawTextSCentered(ystart, font_text,
3386 ystart += ystep_head;
3387 DrawTextSCentered(ystart, font_head,
3389 ystart += ystep_head;
3390 DrawTextSCentered(ystart, font_text,
3392 ystart += ystep_head;
3393 DrawTextSCentered(ystart, font_head,
3395 ystart += ystep_head;
3396 DrawTextSCentered(ystart, font_text,
3397 "Digital Integration");
3399 else if (screen_nr == 3)
3401 DrawTextSCentered(ystart, font_head,
3402 "Special thanks to");
3403 ystart += ystep_head;
3404 DrawTextSCentered(ystart, font_text,
3405 "Hiroyuki Imabayashi");
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_head,
3409 ystart += ystep_head;
3410 DrawTextSCentered(ystart, font_text,
3412 ystart += ystep_head;
3413 DrawTextSCentered(ystart, font_head,
3415 ystart += ystep_head;
3416 DrawTextSCentered(ystart, font_text,
3418 ystart += ystep_head;
3419 DrawTextSCentered(ystart, font_head,
3421 ystart += ystep_head;
3422 DrawTextSCentered(ystart, font_text,
3425 else if (screen_nr == 4)
3427 DrawTextSCentered(ystart, font_head,
3428 "Special thanks to");
3429 ystart += ystep_head;
3430 DrawTextSCentered(ystart, font_text,
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_head,
3435 ystart += ystep_head;
3436 DrawTextSCentered(ystart, font_text,
3437 "J\xfcrgen Bonhagen");
3438 ystart += ystep_head;
3439 DrawTextSCentered(ystart, font_head,
3440 "for the continuous creation");
3441 ystart += ystep_line;
3442 DrawTextSCentered(ystart, font_head,
3443 "of outstanding level sets");
3445 else if (screen_nr == 5)
3447 DrawTextSCentered(ystart, font_head,
3449 ystart += ystep_head;
3450 DrawTextSCentered(ystart, font_text,
3452 ystart += ystep_head;
3453 DrawTextSCentered(ystart, font_head,
3454 "for ideas and inspiration by");
3455 ystart += ystep_head;
3456 DrawTextSCentered(ystart, font_text,
3458 ystart += ystep_para;
3460 DrawTextSCentered(ystart, font_head,
3462 ystart += ystep_head;
3463 DrawTextSCentered(ystart, font_text,
3465 ystart += ystep_head;
3466 DrawTextSCentered(ystart, font_head,
3467 "for ideas and inspiration by");
3468 ystart += ystep_head;
3469 DrawTextSCentered(ystart, font_text,
3472 else if (screen_nr == 6)
3474 DrawTextSCentered(ystart, font_head,
3476 ystart += ystep_head;
3477 DrawTextSCentered(ystart, font_text,
3479 ystart += ystep_head;
3480 DrawTextSCentered(ystart, font_head,
3481 "for the code base used for the");
3482 ystart += ystep_line;
3483 DrawTextSCentered(ystart, font_head,
3484 "native Emerald Mine engine");
3486 else if (screen_nr == 7)
3488 DrawTextSCentered(ystart, font_head,
3490 ystart += ystep_head;
3491 DrawTextSCentered(ystart, font_text,
3493 ystart += ystep_head;
3494 DrawTextSCentered(ystart, font_head,
3495 "for the initial DOS port");
3496 ystart += ystep_para;
3498 DrawTextSCentered(ystart, font_head,
3500 ystart += ystep_head;
3501 DrawTextSCentered(ystart, font_text,
3503 ystart += ystep_head;
3504 DrawTextSCentered(ystart, font_head,
3505 "for some additional toons");
3507 else if (screen_nr == 8)
3509 DrawTextSCentered(ystart, font_head,
3510 "And not to forget:");
3511 ystart += ystep_head;
3512 DrawTextSCentered(ystart, font_head,
3514 ystart += ystep_head;
3515 DrawTextSCentered(ystart, font_text,
3516 "All those who contributed");
3517 ystart += ystep_line;
3518 DrawTextSCentered(ystart, font_text,
3519 "levels to this game");
3520 ystart += ystep_line;
3521 DrawTextSCentered(ystart, font_text,
3525 DrawTextSCentered(ybottom, font_foot,
3526 "Press any key or button for next page");
3529 static void DrawInfoScreen_Credits(void)
3531 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3533 FadeMenuSoundsAndMusic();
3535 FadeOut(REDRAW_FIELD);
3537 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3539 FadeIn(REDRAW_FIELD);
3542 void HandleInfoScreen_Credits(int button)
3544 static int screen_nr = 0;
3545 int num_screens = 9;
3547 if (button == MB_MENU_INITIALIZE)
3551 // DrawInfoScreen_CreditsScreen(screen_nr);
3554 if (button == MB_MENU_LEAVE)
3556 PlaySound(SND_MENU_ITEM_SELECTING);
3558 info_mode = INFO_MODE_MAIN;
3563 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3565 if (button != MB_MENU_INITIALIZE)
3567 PlaySound(SND_MENU_ITEM_SELECTING);
3572 if (screen_nr >= num_screens)
3574 FadeMenuSoundsAndMusic();
3576 info_mode = INFO_MODE_MAIN;
3583 FadeSetNextScreen();
3585 if (button != MB_MENU_INITIALIZE)
3586 FadeOut(REDRAW_FIELD);
3588 DrawInfoScreen_CreditsScreen(screen_nr);
3590 if (button != MB_MENU_INITIALIZE)
3591 FadeIn(REDRAW_FIELD);
3595 PlayMenuSoundIfLoop();
3599 static void DrawInfoScreen_Program(void)
3601 int font_title = MENU_INFO_FONT_TITLE;
3602 int font_head = MENU_INFO_FONT_HEAD;
3603 int font_text = MENU_INFO_FONT_TEXT;
3604 int font_foot = MENU_INFO_FONT_FOOT;
3605 int spacing_title = menu.headline1_spacing_info[info_mode];
3606 int spacing_head = menu.headline2_spacing_info[info_mode];
3607 int spacing_para = menu.paragraph_spacing_info[info_mode];
3608 int spacing_line = menu.line_spacing_info[info_mode];
3609 int ystep_title = getMenuTextStep(spacing_title, font_title);
3610 int ystep_head = getMenuTextStep(spacing_head, font_head);
3611 int ystep_para = getMenuTextStep(spacing_para, font_text);
3612 int ystep_line = getMenuTextStep(spacing_line, font_text);
3613 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3614 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3616 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3618 FadeOut(REDRAW_FIELD);
3623 DrawTextSCentered(ystart, font_title, "Program Information:");
3624 ystart += ystep_title;
3626 DrawTextSCentered(ystart, font_head,
3627 "This game is Freeware!");
3628 ystart += ystep_head;
3629 DrawTextSCentered(ystart, font_head,
3630 "If you like it, send e-mail to:");
3631 ystart += ystep_head;
3632 DrawTextSCentered(ystart, font_text,
3633 setup.internal.program_email);
3634 ystart += ystep_para;
3636 DrawTextSCentered(ystart, font_head,
3637 "More information and levels:");
3638 ystart += ystep_head;
3639 DrawTextSCentered(ystart, font_text,
3640 setup.internal.program_website);
3641 ystart += ystep_para;
3643 DrawTextSCentered(ystart, font_head,
3644 "If you have created new levels,");
3645 ystart += ystep_line;
3646 DrawTextSCentered(ystart, font_head,
3647 "send them to me to include them!");
3648 ystart += ystep_head;
3649 DrawTextSCentered(ystart, font_head,
3652 DrawTextSCentered(ybottom, font_foot,
3653 "Press any key or button for info menu");
3655 FadeIn(REDRAW_FIELD);
3658 void HandleInfoScreen_Program(int button)
3660 if (button == MB_MENU_LEAVE)
3662 PlaySound(SND_MENU_ITEM_SELECTING);
3664 info_mode = INFO_MODE_MAIN;
3669 else if (button == MB_MENU_CHOICE)
3671 PlaySound(SND_MENU_ITEM_SELECTING);
3673 FadeMenuSoundsAndMusic();
3675 info_mode = INFO_MODE_MAIN;
3680 PlayMenuSoundIfLoop();
3684 static void DrawInfoScreen_Version(void)
3686 int font_title = MENU_INFO_FONT_TITLE;
3687 int font_head = MENU_INFO_FONT_HEAD;
3688 int font_text = MENU_INFO_FONT_TEXT;
3689 int font_foot = MENU_INFO_FONT_FOOT;
3690 int spacing_title = menu.headline1_spacing_info[info_mode];
3691 int spacing_head = menu.headline2_spacing_info[info_mode];
3692 int spacing_para = menu.paragraph_spacing_info[info_mode];
3693 int spacing_line = menu.line_spacing_info[info_mode];
3694 int xstep = getFontWidth(font_text);
3695 int ystep_title = getMenuTextStep(spacing_title, font_title);
3696 int ystep_head = getMenuTextStep(spacing_head, font_head);
3697 int ystep_para = getMenuTextStep(spacing_para, font_text);
3698 int ystep_line = getMenuTextStep(spacing_line, font_text);
3699 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3700 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3701 int xstart1 = mSX - SX + 2 * xstep;
3702 int xstart2 = mSX - SX + 18 * xstep;
3703 int xstart3 = mSX - SX + 28 * xstep;
3704 SDL_version sdl_version_compiled;
3705 const SDL_version *sdl_version_linked;
3706 int driver_name_len = 10;
3707 SDL_version sdl_version_linked_ext;
3708 const char *driver_name = NULL;
3710 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3712 FadeOut(REDRAW_FIELD);
3717 DrawTextSCentered(ystart, font_title, "Version Information:");
3718 ystart += ystep_title;
3720 DrawTextF(xstart1, ystart, font_head, "Name");
3721 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3722 ystart += ystep_line;
3724 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3726 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3727 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3728 ystart += ystep_line;
3730 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3731 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3732 ystart += ystep_line;
3736 DrawTextF(xstart1, ystart, font_head, "Version");
3737 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3738 ystart += ystep_line;
3741 DrawTextF(xstart1, ystart, font_head, "Platform");
3742 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3744 PLATFORM_XX_BIT_STRING);
3745 ystart += ystep_line;
3747 DrawTextF(xstart1, ystart, font_head, "Target");
3748 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3749 ystart += ystep_line;
3751 DrawTextF(xstart1, ystart, font_head, "Source date");
3752 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3753 ystart += ystep_line;
3755 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3756 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3757 ystart += ystep_para;
3759 DrawTextF(xstart1, ystart, font_head, "Library");
3760 DrawTextF(xstart2, ystart, font_head, "compiled");
3761 DrawTextF(xstart3, ystart, font_head, "linked");
3762 ystart += ystep_head;
3764 SDL_VERSION(&sdl_version_compiled);
3765 SDL_GetVersion(&sdl_version_linked_ext);
3766 sdl_version_linked = &sdl_version_linked_ext;
3768 DrawTextF(xstart1, ystart, font_text, "SDL");
3769 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3770 sdl_version_compiled.major,
3771 sdl_version_compiled.minor,
3772 sdl_version_compiled.patch);
3773 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3774 sdl_version_linked->major,
3775 sdl_version_linked->minor,
3776 sdl_version_linked->patch);
3777 ystart += ystep_line;
3779 SDL_IMAGE_VERSION(&sdl_version_compiled);
3780 sdl_version_linked = IMG_Linked_Version();
3782 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3783 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3784 sdl_version_compiled.major,
3785 sdl_version_compiled.minor,
3786 sdl_version_compiled.patch);
3787 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3788 sdl_version_linked->major,
3789 sdl_version_linked->minor,
3790 sdl_version_linked->patch);
3791 ystart += ystep_line;
3793 SDL_MIXER_VERSION(&sdl_version_compiled);
3794 sdl_version_linked = Mix_Linked_Version();
3796 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3797 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3798 sdl_version_compiled.major,
3799 sdl_version_compiled.minor,
3800 sdl_version_compiled.patch);
3801 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3802 sdl_version_linked->major,
3803 sdl_version_linked->minor,
3804 sdl_version_linked->patch);
3805 ystart += ystep_line;
3807 SDL_NET_VERSION(&sdl_version_compiled);
3808 sdl_version_linked = SDLNet_Linked_Version();
3810 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3811 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3812 sdl_version_compiled.major,
3813 sdl_version_compiled.minor,
3814 sdl_version_compiled.patch);
3815 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3816 sdl_version_linked->major,
3817 sdl_version_linked->minor,
3818 sdl_version_linked->patch);
3819 ystart += ystep_para;
3821 DrawTextF(xstart1, ystart, font_head, "Driver");
3822 DrawTextF(xstart2, ystart, font_head, "Requested");
3823 DrawTextF(xstart3, ystart, font_head, "Used");
3824 ystart += ystep_head;
3827 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3829 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3830 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3831 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3832 ystart += ystep_line;
3835 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3837 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3838 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3839 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3840 ystart += ystep_line;
3843 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3845 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3846 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3847 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3849 DrawTextSCentered(ybottom, font_foot,
3850 "Press any key or button for info menu");
3852 FadeIn(REDRAW_FIELD);
3855 void HandleInfoScreen_Version(int button)
3857 if (button == MB_MENU_LEAVE)
3859 PlaySound(SND_MENU_ITEM_SELECTING);
3861 info_mode = INFO_MODE_MAIN;
3866 else if (button == MB_MENU_CHOICE)
3868 PlaySound(SND_MENU_ITEM_SELECTING);
3870 FadeMenuSoundsAndMusic();
3872 info_mode = INFO_MODE_MAIN;
3877 PlayMenuSoundIfLoop();
3881 static void DrawInfoScreen_LevelSet(void)
3883 struct TitleMessageInfo *tmi = &readme;
3884 char *filename = getLevelSetInfoFilename();
3885 char *title = "Level Set Information:";
3886 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3887 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3889 if (filename == NULL)
3891 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3896 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3898 FadeOut(REDRAW_FIELD);
3903 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3905 // if x position set to "-1", automatically determine by playfield width
3907 tmi->x = SXSIZE / 2;
3909 // if y position set to "-1", use static default value
3913 // if width set to "-1", automatically determine by playfield width
3914 if (tmi->width == -1)
3915 tmi->width = SXSIZE - 2 * TILEX;
3917 // if height set to "-1", automatically determine by playfield height
3918 if (tmi->height == -1)
3919 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3921 // if chars set to "-1", automatically determine by text and font width
3922 if (tmi->chars == -1)
3923 tmi->chars = tmi->width / getFontWidth(tmi->font);
3925 tmi->width = tmi->chars * getFontWidth(tmi->font);
3927 // if lines set to "-1", automatically determine by text and font height
3928 if (tmi->lines == -1)
3929 tmi->lines = tmi->height / getFontHeight(tmi->font);
3931 tmi->height = tmi->lines * getFontHeight(tmi->font);
3933 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3934 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3935 tmi->autowrap, tmi->centered, tmi->parse_comments);
3937 DrawTextSCentered(ybottom, FONT_TEXT_4,
3938 "Press any key or button for info menu");
3940 FadeIn(REDRAW_FIELD);
3943 static void HandleInfoScreen_LevelSet(int button)
3945 if (button == MB_MENU_LEAVE)
3947 PlaySound(SND_MENU_ITEM_SELECTING);
3949 info_mode = INFO_MODE_MAIN;
3954 else if (button == MB_MENU_CHOICE)
3956 PlaySound(SND_MENU_ITEM_SELECTING);
3958 FadeMenuSoundsAndMusic();
3960 info_mode = INFO_MODE_MAIN;
3965 PlayMenuSoundIfLoop();
3969 static void DrawInfoScreen(void)
3971 if (info_mode == INFO_MODE_TITLE)
3972 DrawInfoScreen_TitleScreen();
3973 else if (info_mode == INFO_MODE_ELEMENTS)
3974 DrawInfoScreen_Elements();
3975 else if (info_mode == INFO_MODE_MUSIC)
3976 DrawInfoScreen_Music();
3977 else if (info_mode == INFO_MODE_CREDITS)
3978 DrawInfoScreen_Credits();
3979 else if (info_mode == INFO_MODE_PROGRAM)
3980 DrawInfoScreen_Program();
3981 else if (info_mode == INFO_MODE_VERSION)
3982 DrawInfoScreen_Version();
3983 else if (info_mode == INFO_MODE_LEVELSET)
3984 DrawInfoScreen_LevelSet();
3986 DrawInfoScreen_Main();
3988 if (info_mode != INFO_MODE_MAIN &&
3989 info_mode != INFO_MODE_TITLE &&
3990 info_mode != INFO_MODE_MUSIC)
3991 PlayMenuSoundsAndMusic();
3994 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3996 if (info_mode == INFO_MODE_TITLE)
3997 HandleInfoScreen_TitleScreen(button);
3998 else if (info_mode == INFO_MODE_ELEMENTS)
3999 HandleInfoScreen_Elements(button);
4000 else if (info_mode == INFO_MODE_MUSIC)
4001 HandleInfoScreen_Music(button);
4002 else if (info_mode == INFO_MODE_CREDITS)
4003 HandleInfoScreen_Credits(button);
4004 else if (info_mode == INFO_MODE_PROGRAM)
4005 HandleInfoScreen_Program(button);
4006 else if (info_mode == INFO_MODE_VERSION)
4007 HandleInfoScreen_Version(button);
4008 else if (info_mode == INFO_MODE_LEVELSET)
4009 HandleInfoScreen_LevelSet(button);
4011 HandleInfoScreen_Main(mx, my, dx, dy, button);
4015 // ============================================================================
4016 // type name functions
4017 // ============================================================================
4019 static TreeInfo *type_name_node = NULL;
4020 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4021 static int type_name_nr = 0;
4023 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4026 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4027 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4028 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4029 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4030 int font_width = getFontWidth(font_nr);
4032 DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
4034 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4036 pos->width = strlen(text) * font_width;
4037 sx = mSX + ALIGNED_TEXT_XPOS(pos);
4039 DrawText(sx, sy, text, font_nr);
4042 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4044 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4046 *pos = *mci->pos_input;
4048 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4050 TreeInfo *ti = player_name_current;
4051 int first_entry = ti->cl_first;
4052 int entry_pos = first_entry + ti->cl_cursor;
4053 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4054 int xpos = MENU_SCREEN_START_XPOS;
4055 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4056 int font_width = getFontWidth(pos->font);
4058 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4059 type_name_nr = entry_pos;
4061 strcpy(name, type_name_node->name);
4063 pos->x = xpos * font_width;
4064 pos->y = ypos * font_width;
4065 pos->width = MAX_PLAYER_NAME_LEN * font_width;
4069 type_name_nr = user.nr;
4071 strcpy(name, setup.player_name);
4074 strcpy(type_name_last, name);
4076 if (strEqual(name, EMPTY_PLAYER_NAME))
4079 *xpos = strlen(name);
4082 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4084 // change name of edited user in global list of user names
4085 setString(&global.user_names[type_name_nr], name);
4087 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4089 TreeInfo *node = type_name_node;
4091 // change name of edited user in local menu tree structure
4092 setString(&node->name, name);
4093 setString(&node->name_sorting, name);
4095 node->color = (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4096 pos->font = (node->color == FC_RED ? FONT_INPUT_1 : FONT_VALUE_OLD);
4100 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4103 boolean reset_setup = strEqual(name, "");
4104 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4107 strcpy(name, type_name_last);
4109 if (strEqual(name, ""))
4110 strcpy(name, EMPTY_PLAYER_NAME);
4112 // if player name not changed, no further action required
4113 if (strEqual(name, type_name_last))
4116 setTypeNameValues_Name(name, pos);
4118 // redraw player name before (possibly) opening request dialogs
4119 drawTypeNameText(name, pos, FALSE);
4121 int last_user_nr = user.nr;
4123 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4125 // save setup of currently active user (may differ from edited user)
4128 // temporarily change active user to edited user
4129 user.nr = type_name_nr;
4131 // load setup of edited user
4135 // change name of edited user in setup structure
4136 strcpy(setup.player_name, name);
4138 // save setup of edited user
4141 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4145 if (Request("Reset setup values for this player?", REQ_ASK))
4147 // remove setup config file
4148 unlink(getSetupFilename());
4150 // set player name to default player name
4153 // update player name used by name typing functions
4154 strcpy(name, setup.player_name);
4156 setTypeNameValues_Name(name, pos);
4158 Request("Setup values reset to default values!", REQ_CONFIRM);
4161 else if (remove_user && type_name_nr != 0)
4163 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4165 char *user_dir = getUserGameDataDir();
4166 char *user_dir_removed =
4167 getStringCat3WithSeparator(user_dir, "REMOVED",
4168 getCurrentTimestamp(), ".");
4170 if (rename(user_dir, user_dir_removed) == 0)
4171 Request("Player settings and tapes removed!", REQ_CONFIRM);
4173 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4175 checked_free(user_dir_removed);
4179 // restore currently active user
4180 user.nr = last_user_nr;
4182 // restore setup of currently active user
4187 static void HandleTypeNameExt(boolean initialize, Key key)
4189 static struct TextPosInfo pos_name = { 0 };
4190 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4191 static int xpos = 0;
4192 struct TextPosInfo *pos = &pos_name;
4193 char key_char = getValidConfigValueChar(getCharFromKey(key));
4194 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4195 boolean active = TRUE;
4199 getTypeNameValues(name, pos, &xpos);
4201 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4202 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4204 StartTextInput(sx, sy, pos->width, pos->height);
4206 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4208 name[xpos] = key_char;
4213 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4219 else if (key == KSYM_Return)
4221 setTypeNameValues(name, pos, TRUE);
4225 else if (key == KSYM_Escape)
4227 setTypeNameValues(name, pos, FALSE);
4232 drawTypeNameText(name, pos, active);
4238 SetGameStatus(game_status_last_screen);
4240 if (game_status == GAME_MODE_MAIN)
4241 InitializeMainControls();
4245 static void DrawTypeName(void)
4247 HandleTypeNameExt(TRUE, 0);
4250 void HandleTypeName(Key key)
4252 HandleTypeNameExt(FALSE, key);
4256 // ============================================================================
4257 // tree menu functions
4258 // ============================================================================
4260 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4262 if (game_status != GAME_MODE_SETUP ||
4263 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4266 int max_text_size = 0;
4269 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4270 max_text_size = MAX(max_text_size, strlen(node->name));
4272 int num_entries = numTreeInfoInGroup(ti);
4273 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4274 int text_width = max_text_size * getFontWidth(FONT_TEXT_1);
4275 int button_width = SC_MENUBUTTON_XSIZE;
4276 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4277 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4278 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4279 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4280 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4281 int align_xoffset = MAX(0, align_xoffset_raw);
4283 return align_xoffset;
4286 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4288 if (game_status != GAME_MODE_SETUP ||
4289 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4292 int num_entries = numTreeInfoInGroup(ti);
4293 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4294 int font_height = getFontHeight(FONT_TEXT_1);
4295 int text_height = font_height * num_page_entries;
4296 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4297 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4298 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4299 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4300 int align_yoffset = MAX(0, align_yoffset_raw);
4302 return align_yoffset;
4305 static void DrawChooseTree(TreeInfo **ti_ptr)
4307 int fade_mask = REDRAW_FIELD;
4310 fade_mask = REDRAW_ALL;
4312 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4314 SetGameStatus(GAME_MODE_MAIN);
4323 FreeScreenGadgets();
4324 CreateScreenGadgets();
4328 // needed if different viewport properties defined for choosing level (set)
4329 ChangeViewportPropertiesIfNeeded();
4331 if (game_status == GAME_MODE_NAMES)
4332 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4333 else if (game_status == GAME_MODE_LEVELNR)
4334 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4335 else if (game_status == GAME_MODE_LEVELS)
4336 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4340 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4342 MapScreenTreeGadgets(*ti_ptr);
4343 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4345 DrawMaskedBorder(fade_mask);
4350 static void drawChooseTreeList(int first_entry, int num_page_entries,
4353 int num_entries = numTreeInfoInGroup(ti);
4354 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4355 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4356 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4357 int font_nr = FONT_TEXT_1;
4358 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4360 char *title_string = NULL;
4361 int yoffset_sets = MENU_TITLE1_YPOS;
4362 int yoffset_setup = 16;
4363 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4364 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4366 title_string = ti->infotext;
4368 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4370 clearMenuListArea();
4372 for (i = 0; i < num_page_entries; i++)
4374 TreeInfo *node, *node_first;
4375 int entry_pos = first_entry + i;
4376 int xpos = MENU_SCREEN_START_XPOS;
4377 int ypos = MENU_SCREEN_START_YPOS + i;
4378 int startx = amSX + xpos * 32;
4379 int starty = amSY + ypos * 32;
4380 int startx_text = startx + font_xoffset;
4381 int endx_text = amSX + screen_width;
4382 int max_text_size = endx_text - startx_text;
4383 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4384 char buffer[max_buffer_len + 1];
4386 node_first = getTreeInfoFirstGroupEntry(ti);
4387 node = getTreeInfoFromPos(node_first, entry_pos);
4389 strncpy(buffer, node->name, max_buffer_len);
4390 buffer[max_buffer_len] = '\0';
4392 DrawText(startx, starty, buffer, font_nr + node->color);
4394 if (node->parent_link)
4395 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4396 else if (node->level_group)
4397 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4399 initCursor(i, IMG_MENU_BUTTON);
4401 if (game_status == GAME_MODE_NAMES)
4402 drawChooseTreeEdit(i, FALSE);
4405 redraw_mask |= REDRAW_FIELD;
4408 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4410 TreeInfo *node, *node_first;
4411 int x, last_redraw_mask = redraw_mask;
4412 int ypos = MENU_TITLE2_YPOS;
4413 int font_nr = FONT_TITLE_2;
4415 if (ti->type == TREE_TYPE_LEVEL_NR)
4416 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4418 if (ti->type != TREE_TYPE_LEVEL_DIR)
4421 node_first = getTreeInfoFirstGroupEntry(ti);
4422 node = getTreeInfoFromPos(node_first, entry_pos);
4424 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4426 if (node->parent_link)
4427 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4428 node->node_parent->name);
4429 else if (node->level_group)
4430 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4432 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4433 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4434 node->levels, (node->levels > 1 ? "levels" : "level"),
4437 // let BackToFront() redraw only what is needed
4438 redraw_mask = last_redraw_mask;
4439 for (x = 0; x < SCR_FIELDX; x++)
4440 MarkTileDirty(x, 1);
4443 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4446 TreeInfo *ti = *ti_ptr;
4447 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4448 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4449 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4450 int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT);
4451 int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT);
4453 int y = ti->cl_cursor;
4454 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4455 int num_entries = numTreeInfoInGroup(ti);
4456 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4457 boolean position_set_by_scrollbar = (dx == 999);
4459 if (button == MB_MENU_INITIALIZE)
4461 int num_entries = numTreeInfoInGroup(ti);
4462 int entry_pos = getPosFromTreeInfo(ti);
4464 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4465 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4467 if (ti->cl_first == -1)
4469 // only on initialization
4470 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4471 ti->cl_cursor = entry_pos - ti->cl_first;
4473 else if (ti->cl_cursor >= num_page_entries ||
4474 (num_entries > num_page_entries &&
4475 num_entries - ti->cl_first < num_page_entries))
4477 // only after change of list size (by custom graphic configuration)
4478 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4479 ti->cl_cursor = entry_pos - ti->cl_first;
4482 if (position_set_by_scrollbar)
4485 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4488 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4489 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4490 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4494 else if (button == MB_MENU_LEAVE)
4498 PlaySound(SND_MENU_ITEM_SELECTING);
4500 if (ti->node_parent)
4502 *ti_ptr = ti->node_parent;
4503 DrawChooseTree(ti_ptr);
4505 else if (game_status == GAME_MODE_SETUP)
4507 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4508 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4509 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4511 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4512 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4513 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4514 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4515 execSetupGraphics();
4516 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4517 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4518 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4520 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4521 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4522 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4523 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4524 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4525 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4526 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4527 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4534 if (game_status == GAME_MODE_LEVELNR)
4536 int new_level_nr = atoi(level_number_current->identifier);
4538 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4541 SetGameStatus(GAME_MODE_MAIN);
4549 if (mx || my) // mouse input
4551 x = (mx - amSX) / 32;
4552 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4554 if (game_status == GAME_MODE_NAMES)
4555 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4557 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4559 // move cursor instead of scrolling when already at start/end of list
4560 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4562 else if (dy == +1 * SCROLL_LINE &&
4563 ti->cl_first + num_page_entries == num_entries)
4566 // handle scrolling screen one line or page
4567 if (ti->cl_cursor + dy < 0 ||
4568 ti->cl_cursor + dy > num_page_entries - 1)
4570 boolean redraw = FALSE;
4572 if (ABS(dy) == SCROLL_PAGE)
4573 step = num_page_entries - 1;
4575 if (dy < 0 && ti->cl_first > 0)
4577 // scroll page/line up
4579 ti->cl_first -= step;
4580 if (ti->cl_first < 0)
4585 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4587 // scroll page/line down
4589 ti->cl_first += step;
4590 if (ti->cl_first + num_page_entries > num_entries)
4591 ti->cl_first = MAX(0, num_entries - num_page_entries);
4598 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4599 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4600 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4602 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4609 // handle moving cursor one line
4610 y = ti->cl_cursor + dy;
4615 TreeInfo *node_first, *node_cursor;
4616 int entry_pos = ti->cl_first + y;
4618 node_first = getTreeInfoFirstGroupEntry(ti);
4619 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4621 if (node_cursor->node_group)
4625 PlaySound(SND_MENU_ITEM_SELECTING);
4627 node_cursor->cl_first = ti->cl_first;
4628 node_cursor->cl_cursor = ti->cl_cursor;
4629 *ti_ptr = node_cursor->node_group;
4630 DrawChooseTree(ti_ptr);
4635 else if (dx == -1 && ti->node_parent)
4639 PlaySound(SND_MENU_ITEM_SELECTING);
4641 *ti_ptr = ti->node_parent;
4642 DrawChooseTree(ti_ptr);
4647 if (!anyScrollbarGadgetActive() &&
4648 IN_VIS_MENU(x, y) &&
4649 mx < mx_right_border &&
4650 y >= 0 && y < num_page_entries)
4654 if (game_status == GAME_MODE_NAMES)
4656 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4657 drawChooseTreeEdit(y, TRUE);
4660 if (y != ti->cl_cursor)
4662 PlaySound(SND_MENU_ITEM_ACTIVATING);
4664 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4665 drawChooseTreeCursor(y, TRUE);
4666 drawChooseTreeInfo(ti->cl_first + y, ti);
4672 if (game_status == GAME_MODE_SETUP)
4674 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4675 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4676 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4678 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4679 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4680 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4681 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4682 execSetupGraphics();
4683 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4684 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4685 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4687 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4688 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4689 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4690 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4691 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4692 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4693 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4694 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4703 TreeInfo *node_first, *node_cursor;
4704 int entry_pos = ti->cl_first + y;
4706 PlaySound(SND_MENU_ITEM_SELECTING);
4708 node_first = getTreeInfoFirstGroupEntry(ti);
4709 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4711 if (node_cursor->node_group)
4715 node_cursor->cl_first = ti->cl_first;
4716 node_cursor->cl_cursor = ti->cl_cursor;
4717 *ti_ptr = node_cursor->node_group;
4718 DrawChooseTree(ti_ptr);
4720 else if (node_cursor->parent_link)
4724 *ti_ptr = node_cursor->node_parent;
4725 DrawChooseTree(ti_ptr);
4731 node_cursor->cl_first = ti->cl_first;
4732 node_cursor->cl_cursor = ti->cl_cursor;
4733 *ti_ptr = node_cursor;
4735 if (ti->type == TREE_TYPE_LEVEL_DIR)
4737 LoadLevelSetup_SeriesInfo();
4739 SaveLevelSetup_LastSeries();
4740 SaveLevelSetup_SeriesInfo();
4744 if (game_status == GAME_MODE_SETUP)
4746 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4747 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4748 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4750 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4751 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4752 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4753 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4754 execSetupGraphics();
4755 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4756 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4757 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4759 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4760 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4761 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4762 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4763 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4764 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4765 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4766 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4773 if (game_status == GAME_MODE_LEVELNR)
4775 int new_level_nr = atoi(level_number_current->identifier);
4777 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4779 else if (game_status == GAME_MODE_NAMES)
4781 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4783 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
4790 // change active user to selected user
4791 user.nr = entry_pos;
4793 // save number of new active user
4796 // load setup of new active user
4799 // load last level set of new active user
4800 LoadLevelSetup_LastSeries();
4801 LoadLevelSetup_SeriesInfo();
4805 ToggleFullscreenIfNeeded();
4806 ChangeWindowScalingIfNeeded();
4808 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
4809 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
4810 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
4813 SetGameStatus(GAME_MODE_MAIN);
4822 void DrawChoosePlayerName(void)
4826 FadeMenuSoundsAndMusic();
4828 if (player_name != NULL)
4830 freeTreeInfo(player_name);
4835 for (i = 0; i < MAX_PLAYER_NAMES; i++)
4837 boolean team_mode = (!network.enabled && setup.team_mode);
4838 int tree_type = (team_mode ? TREE_TYPE_PLAYER_TEAM : TREE_TYPE_PLAYER_NAME);
4839 TreeInfo *ti = newTreeInfo_setDefaults(tree_type);
4840 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
4843 ti->node_top = &player_name;
4844 ti->sort_priority = 10000 + value;
4847 if (strEqual(global.user_names[i], EMPTY_PLAYER_NAME))
4848 ti->color = FC_BLUE;
4850 snprintf(identifier, sizeof(identifier), "%d", value);
4851 snprintf(name, sizeof(name), "%s", global.user_names[i]);
4853 setString(&ti->identifier, identifier);
4854 setString(&ti->name, name);
4855 setString(&ti->name_sorting, name);
4857 pushTreeInfo(&player_name, ti);
4860 // sort player entries by player number
4861 sortTreeInfo(&player_name);
4863 // set current player entry to selected player entry
4864 player_name_current =
4865 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
4867 // if that fails, set current player name to first available name
4868 if (player_name_current == NULL)
4869 player_name_current = player_name;
4871 DrawChooseTree(&player_name_current);
4873 PlayMenuSoundsAndMusic();
4876 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
4878 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
4881 void DrawChooseLevelSet(void)
4883 FadeMenuSoundsAndMusic();
4885 DrawChooseTree(&leveldir_current);
4887 PlayMenuSoundsAndMusic();
4890 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4892 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4895 void DrawChooseLevelNr(void)
4899 FadeMenuSoundsAndMusic();
4901 if (level_number != NULL)
4903 freeTreeInfo(level_number);
4905 level_number = NULL;
4908 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4910 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4911 char identifier[32], name[64];
4914 // temporarily load level info to get level name
4915 LoadLevelInfoOnly(i);
4917 ti->node_top = &level_number;
4918 ti->sort_priority = 10000 + value;
4919 ti->color = (level.no_level_file ? FC_BLUE :
4920 LevelStats_getSolved(i) ? FC_GREEN :
4921 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4923 snprintf(identifier, sizeof(identifier), "%d", value);
4924 snprintf(name, sizeof(name), "%03d: %s", value,
4925 (level.no_level_file ? "(no file)" : level.name));
4927 setString(&ti->identifier, identifier);
4928 setString(&ti->name, name);
4929 setString(&ti->name_sorting, name);
4931 pushTreeInfo(&level_number, ti);
4934 // sort level number values to start with lowest level number
4935 sortTreeInfo(&level_number);
4937 // set current level number to current level number
4938 level_number_current =
4939 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4941 // if that also fails, set current level number to first available level
4942 if (level_number_current == NULL)
4943 level_number_current = level_number;
4945 DrawChooseTree(&level_number_current);
4947 PlayMenuSoundsAndMusic();
4950 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4952 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4955 void DrawHallOfFame(int level_nr, int highlight_position)
4957 int fade_mask = REDRAW_FIELD;
4960 fade_mask = REDRAW_ALL;
4963 FadeMenuSoundsAndMusic();
4965 // (this is needed when called from GameEnd() after winning a game)
4966 KeyboardAutoRepeatOn();
4968 // (this is needed when called from GameEnd() after winning a game)
4969 SetDrawDeactivationMask(REDRAW_NONE);
4970 SetDrawBackgroundMask(REDRAW_FIELD);
4972 if (highlight_position < 0)
4973 LoadScore(level_nr);
4975 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4977 FadeSetEnterScreen();
4981 // needed if different viewport properties defined for scores
4982 ChangeViewportPropertiesIfNeeded();
4984 PlayMenuSoundsAndMusic();
4986 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4988 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4990 DrawMaskedBorder(fade_mask);
4995 static void drawHallOfFameList(int level_nr, int first_entry,
4996 int highlight_position)
5000 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5003 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
5004 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
5005 "HighScores of Level %d", level_nr);
5007 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5009 int entry = first_entry + i;
5010 boolean active = (entry == highlight_position);
5011 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
5012 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
5013 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
5014 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
5015 int dxoff = getFontDrawOffsetX(font_nr1);
5016 int dx1 = 3 * getFontWidth(font_nr1);
5017 int dx2 = dx1 + getFontWidth(font_nr1);
5018 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
5019 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
5020 int sy = mSY + 64 + i * 32;
5022 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
5023 DrawText(mSX + dx1, sy, ".", font_nr1);
5025 for (j = 0; j < num_dots; j++)
5026 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
5028 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
5029 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
5031 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
5034 redraw_mask |= REDRAW_FIELD;
5037 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5039 static int level_nr = 0;
5040 static int first_entry = 0;
5041 static int highlight_position = 0;
5042 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5044 if (button == MB_MENU_INITIALIZE)
5048 highlight_position = my;
5050 drawHallOfFameList(level_nr, first_entry, highlight_position);
5055 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
5056 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
5060 if (first_entry > 0)
5062 first_entry -= step;
5063 if (first_entry < 0)
5066 drawHallOfFameList(level_nr, first_entry, highlight_position);
5071 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
5073 first_entry += step;
5074 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
5075 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
5077 drawHallOfFameList(level_nr, first_entry, highlight_position);
5080 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
5082 PlaySound(SND_MENU_ITEM_SELECTING);
5084 FadeSound(SND_BACKGROUND_SCORES);
5086 if (button == MB_MENU_CHOICE &&
5087 game_status_last_screen == GAME_MODE_PLAYING &&
5088 setup.auto_play_next_level && setup.increment_levels &&
5089 level_nr < leveldir_current->last_level &&
5092 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
5096 SetGameStatus(GAME_MODE_MAIN);
5102 if (game_status == GAME_MODE_SCORES)
5103 PlayMenuSoundIfLoop();
5107 // ============================================================================
5108 // setup screen functions
5109 // ============================================================================
5111 static struct TokenInfo *setup_info;
5112 static int num_setup_info; // number of setup entries shown on screen
5113 static int max_setup_info; // total number of setup entries in list
5115 static char *window_size_text;
5116 static char *scaling_type_text;
5117 static char *rendering_mode_text;
5118 static char *vsync_mode_text;
5119 static char *scroll_delay_text;
5120 static char *snapshot_mode_text;
5121 static char *game_speed_text;
5122 static char *network_server_text;
5123 static char *graphics_set_name;
5124 static char *sounds_set_name;
5125 static char *music_set_name;
5126 static char *volume_simple_text;
5127 static char *volume_loops_text;
5128 static char *volume_music_text;
5129 static char *touch_controls_text;
5130 static char *move_distance_text;
5131 static char *drop_distance_text;
5132 static char *transparency_text;
5133 static char *grid_size_text[2][2];
5135 static void execSetupMain(void)
5137 setup_mode = SETUP_MODE_MAIN;
5142 static void execSetupGame_setGameSpeeds(boolean update_value)
5144 if (setup.game_speed_extended)
5146 game_speeds_list = game_speeds_list_extended;
5147 game_speeds = game_speeds_extended;
5151 game_speeds_list = game_speeds_list_normal;
5152 game_speeds = game_speeds_normal;
5155 if (game_speeds == NULL)
5159 for (i = 0; game_speeds_list[i].value != -1; i++)
5161 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5162 char identifier[32], name[32];
5163 int value = game_speeds_list[i].value;
5164 char *text = game_speeds_list[i].text;
5166 ti->node_top = &game_speeds;
5167 ti->sort_priority = 10000 - value;
5169 sprintf(identifier, "%d", value);
5170 sprintf(name, "%s", text);
5172 setString(&ti->identifier, identifier);
5173 setString(&ti->name, name);
5174 setString(&ti->name_sorting, name);
5175 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5177 pushTreeInfo(&game_speeds, ti);
5180 // sort game speed values to start with slowest game speed
5181 sortTreeInfo(&game_speeds);
5183 update_value = TRUE;
5188 // set current game speed to configured game speed value
5189 game_speed_current =
5190 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5192 // if that fails, set current game speed to reliable default value
5193 if (game_speed_current == NULL)
5194 game_speed_current =
5195 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5197 // if that also fails, set current game speed to first available speed
5198 if (game_speed_current == NULL)
5199 game_speed_current = game_speeds;
5201 if (setup.game_speed_extended)
5202 game_speeds_extended = game_speeds;
5204 game_speeds_normal = game_speeds;
5207 setup.game_frame_delay = atoi(game_speed_current->identifier);
5209 // needed for displaying game speed text instead of identifier
5210 game_speed_text = game_speed_current->name;
5213 static void execSetupGame_setScrollDelays(void)
5215 if (scroll_delays == NULL)
5219 for (i = 0; scroll_delays_list[i].value != -1; i++)
5221 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5222 char identifier[32], name[32];
5223 int value = scroll_delays_list[i].value;
5224 char *text = scroll_delays_list[i].text;
5226 ti->node_top = &scroll_delays;
5227 ti->sort_priority = value;
5229 sprintf(identifier, "%d", value);
5230 sprintf(name, "%s", text);
5232 setString(&ti->identifier, identifier);
5233 setString(&ti->name, name);
5234 setString(&ti->name_sorting, name);
5235 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5237 pushTreeInfo(&scroll_delays, ti);
5240 // sort scroll delay values to start with lowest scroll delay value
5241 sortTreeInfo(&scroll_delays);
5243 // set current scroll delay value to configured scroll delay value
5244 scroll_delay_current =
5245 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5247 // if that fails, set current scroll delay to reliable default value
5248 if (scroll_delay_current == NULL)
5249 scroll_delay_current =
5250 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5252 // if that also fails, set current scroll delay to first available value
5253 if (scroll_delay_current == NULL)
5254 scroll_delay_current = scroll_delays;
5257 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5259 // needed for displaying scroll delay text instead of identifier
5260 scroll_delay_text = scroll_delay_current->name;
5263 static void execSetupGame_setSnapshotModes(void)
5265 if (snapshot_modes == NULL)
5269 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5271 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5272 char identifier[32], name[32];
5273 char *value = snapshot_modes_list[i].value;
5274 char *text = snapshot_modes_list[i].text;
5276 ti->node_top = &snapshot_modes;
5277 ti->sort_priority = i;
5279 sprintf(identifier, "%s", value);
5280 sprintf(name, "%s", text);
5282 setString(&ti->identifier, identifier);
5283 setString(&ti->name, name);
5284 setString(&ti->name_sorting, name);
5285 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5287 pushTreeInfo(&snapshot_modes, ti);
5290 // sort snapshot mode values to start with lowest snapshot mode value
5291 sortTreeInfo(&snapshot_modes);
5293 // set current snapshot mode value to configured snapshot mode value
5294 snapshot_mode_current =
5295 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5297 // if that fails, set current snapshot mode to reliable default value
5298 if (snapshot_mode_current == NULL)
5299 snapshot_mode_current =
5300 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5302 // if that also fails, set current snapshot mode to first available value
5303 if (snapshot_mode_current == NULL)
5304 snapshot_mode_current = snapshot_modes;
5307 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5309 // needed for displaying snapshot mode text instead of identifier
5310 snapshot_mode_text = snapshot_mode_current->name;
5313 static void execSetupGame_setNetworkServerText(void)
5315 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5317 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5321 strncpy(network_server_hostname, setup.network_server_hostname,
5322 MAX_SETUP_TEXT_INPUT_LEN);
5323 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5326 // needed for displaying network server text instead of identifier
5327 network_server_text = network_server_hostname;
5330 static void execSetupGame(void)
5332 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5334 execSetupGame_setGameSpeeds(FALSE);
5335 execSetupGame_setScrollDelays();
5336 execSetupGame_setSnapshotModes();
5338 execSetupGame_setNetworkServerText();
5340 setup_mode = SETUP_MODE_GAME;
5344 // check if vsync needs to be disabled for this game speed to work
5345 if (check_vsync_mode)
5346 DisableVsyncIfNeeded();
5349 static void execSetupChooseGameSpeed(void)
5351 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5356 static void execSetupChooseScrollDelay(void)
5358 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5363 static void execSetupChooseSnapshotMode(void)
5365 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5370 static void execSetupEngines(void)
5372 setup_mode = SETUP_MODE_ENGINES;
5377 static void execSetupEditor(void)
5379 setup_mode = SETUP_MODE_EDITOR;
5384 static void execSetupGraphics_setWindowSizes(boolean update_list)
5386 if (window_sizes != NULL && update_list)
5388 freeTreeInfo(window_sizes);
5390 window_sizes = NULL;
5393 if (window_sizes == NULL)
5395 boolean current_window_size_found = FALSE;
5398 for (i = 0; window_sizes_list[i].value != -1; i++)
5400 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5401 char identifier[32], name[32];
5402 int value = window_sizes_list[i].value;
5403 char *text = window_sizes_list[i].text;
5405 ti->node_top = &window_sizes;
5406 ti->sort_priority = value;
5408 sprintf(identifier, "%d", value);
5409 sprintf(name, "%s", text);
5411 setString(&ti->identifier, identifier);
5412 setString(&ti->name, name);
5413 setString(&ti->name_sorting, name);
5414 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5416 pushTreeInfo(&window_sizes, ti);
5418 if (value == setup.window_scaling_percent)
5419 current_window_size_found = TRUE;
5422 if (!current_window_size_found)
5424 // add entry for non-preset window scaling value
5426 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5427 char identifier[32], name[32];
5428 int value = setup.window_scaling_percent;
5430 ti->node_top = &window_sizes;
5431 ti->sort_priority = value;
5433 sprintf(identifier, "%d", value);
5434 sprintf(name, "%d %% (Current)", value);
5436 setString(&ti->identifier, identifier);
5437 setString(&ti->name, name);
5438 setString(&ti->name_sorting, name);
5439 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5441 pushTreeInfo(&window_sizes, ti);
5444 // sort window size values to start with lowest window size value
5445 sortTreeInfo(&window_sizes);
5447 // set current window size value to configured window size value
5448 window_size_current =
5449 getTreeInfoFromIdentifier(window_sizes,
5450 i_to_a(setup.window_scaling_percent));
5452 // if that fails, set current window size to reliable default value
5453 if (window_size_current == NULL)
5454 window_size_current =
5455 getTreeInfoFromIdentifier(window_sizes,
5456 i_to_a(STD_WINDOW_SCALING_PERCENT));
5458 // if that also fails, set current window size to first available value
5459 if (window_size_current == NULL)
5460 window_size_current = window_sizes;
5463 setup.window_scaling_percent = atoi(window_size_current->identifier);
5465 // needed for displaying window size text instead of identifier
5466 window_size_text = window_size_current->name;
5469 static void execSetupGraphics_setScalingTypes(void)
5471 if (scaling_types == NULL)
5475 for (i = 0; scaling_types_list[i].value != NULL; i++)
5477 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5478 char identifier[32], name[32];
5479 char *value = scaling_types_list[i].value;
5480 char *text = scaling_types_list[i].text;
5482 ti->node_top = &scaling_types;
5483 ti->sort_priority = i;
5485 sprintf(identifier, "%s", value);
5486 sprintf(name, "%s", text);
5488 setString(&ti->identifier, identifier);
5489 setString(&ti->name, name);
5490 setString(&ti->name_sorting, name);
5491 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5493 pushTreeInfo(&scaling_types, ti);
5496 // sort scaling type values to start with lowest scaling type value
5497 sortTreeInfo(&scaling_types);
5499 // set current scaling type value to configured scaling type value
5500 scaling_type_current =
5501 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5503 // if that fails, set current scaling type to reliable default value
5504 if (scaling_type_current == NULL)
5505 scaling_type_current =
5506 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5508 // if that also fails, set current scaling type to first available value
5509 if (scaling_type_current == NULL)
5510 scaling_type_current = scaling_types;
5513 setup.window_scaling_quality = scaling_type_current->identifier;
5515 // needed for displaying scaling type text instead of identifier
5516 scaling_type_text = scaling_type_current->name;
5519 static void execSetupGraphics_setRenderingModes(void)
5521 if (rendering_modes == NULL)
5525 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5527 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5528 char identifier[32], name[32];
5529 char *value = rendering_modes_list[i].value;
5530 char *text = rendering_modes_list[i].text;
5532 ti->node_top = &rendering_modes;
5533 ti->sort_priority = i;
5535 sprintf(identifier, "%s", value);
5536 sprintf(name, "%s", text);
5538 setString(&ti->identifier, identifier);
5539 setString(&ti->name, name);
5540 setString(&ti->name_sorting, name);
5541 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5543 pushTreeInfo(&rendering_modes, ti);
5546 // sort rendering mode values to start with lowest rendering mode value
5547 sortTreeInfo(&rendering_modes);
5549 // set current rendering mode value to configured rendering mode value
5550 rendering_mode_current =
5551 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5553 // if that fails, set current rendering mode to reliable default value
5554 if (rendering_mode_current == NULL)
5555 rendering_mode_current =
5556 getTreeInfoFromIdentifier(rendering_modes,
5557 STR_SPECIAL_RENDERING_DEFAULT);
5559 // if that also fails, set current rendering mode to first available one
5560 if (rendering_mode_current == NULL)
5561 rendering_mode_current = rendering_modes;
5564 setup.screen_rendering_mode = rendering_mode_current->identifier;
5566 // needed for displaying rendering mode text instead of identifier
5567 rendering_mode_text = rendering_mode_current->name;
5570 static void execSetupGraphics_setVsyncModes(boolean update_value)
5572 if (vsync_modes == NULL)
5576 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5578 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5579 char identifier[32], name[32];
5580 char *value = vsync_modes_list[i].value;
5581 char *text = vsync_modes_list[i].text;
5583 ti->node_top = &vsync_modes;
5584 ti->sort_priority = i;
5586 sprintf(identifier, "%s", value);
5587 sprintf(name, "%s", text);
5589 setString(&ti->identifier, identifier);
5590 setString(&ti->name, name);
5591 setString(&ti->name_sorting, name);
5592 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5594 pushTreeInfo(&vsync_modes, ti);
5597 // sort vsync mode values to start with lowest vsync mode value
5598 sortTreeInfo(&vsync_modes);
5600 update_value = TRUE;
5605 // set current vsync mode value to configured vsync mode value
5606 vsync_mode_current =
5607 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5609 // if that fails, set current vsync mode to reliable default value
5610 if (vsync_mode_current == NULL)
5611 vsync_mode_current =
5612 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5614 // if that also fails, set current vsync mode to first available one
5615 if (vsync_mode_current == NULL)
5616 vsync_mode_current = vsync_modes;
5619 setup.vsync_mode = vsync_mode_current->identifier;
5621 // needed for displaying vsync mode text instead of identifier
5622 vsync_mode_text = vsync_mode_current->name;
5625 static void execSetupGraphics(void)
5627 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5629 // update "setup.window_scaling_percent" from list selection
5630 // (in this case, window scaling was changed on setup screen)
5631 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5632 execSetupGraphics_setWindowSizes(FALSE);
5634 // update "setup.vsync_mode" from list selection
5635 // (in this case, vsync mode was changed on setup screen)
5636 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5637 execSetupGraphics_setVsyncModes(FALSE);
5639 // update list selection from "setup.window_scaling_percent"
5640 // (window scaling may have changed by resizing the window)
5641 execSetupGraphics_setWindowSizes(TRUE);
5643 // update list selection from "setup.vsync_mode"
5644 // (vsync_mode may have changed by re-creating the renderer)
5645 execSetupGraphics_setVsyncModes(TRUE);
5647 execSetupGraphics_setScalingTypes();
5648 execSetupGraphics_setRenderingModes();
5650 setup_mode = SETUP_MODE_GRAPHICS;
5654 // check if game speed is high enough for 60 Hz vsync to work
5655 if (check_game_speed)
5656 ModifyGameSpeedIfNeeded();
5658 // window scaling may have changed at this point
5659 ChangeWindowScalingIfNeeded();
5661 // window scaling quality may have changed at this point
5662 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5663 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5665 // screen rendering mode may have changed at this point
5666 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5668 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
5669 int video_vsync_mode = video.vsync_mode;
5671 // screen vsync mode may have changed at this point
5672 ChangeVsyncModeIfNeeded();
5674 // check if setting vsync mode to selected value failed
5675 if (setup_vsync_mode != video_vsync_mode &&
5676 setup_vsync_mode != video.vsync_mode)
5678 // changing vsync mode to selected value failed -- reset displayed value
5679 execSetupGraphics_setVsyncModes(TRUE);
5681 Request("Setting VSync failed!", REQ_CONFIRM);
5687 static void execSetupChooseWindowSize(void)
5689 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5694 static void execSetupChooseScalingType(void)
5696 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5701 static void execSetupChooseRenderingMode(void)
5703 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5708 static void execSetupChooseVsyncMode(void)
5710 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5715 static void execSetupChooseVolumeSimple(void)
5717 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5722 static void execSetupChooseVolumeLoops(void)
5724 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5729 static void execSetupChooseVolumeMusic(void)
5731 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5736 static void execSetupSound(void)
5738 if (volumes_simple == NULL)
5740 boolean current_volume_simple_found = FALSE;
5743 for (i = 0; volumes_list[i].value != -1; i++)
5745 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5746 char identifier[32], name[32];
5747 int value = volumes_list[i].value;
5748 char *text = volumes_list[i].text;
5750 ti->node_top = &volumes_simple;
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_VOLUME_SIMPLE);
5761 pushTreeInfo(&volumes_simple, ti);
5763 if (value == setup.volume_simple)
5764 current_volume_simple_found = TRUE;
5767 if (!current_volume_simple_found)
5769 // add entry for non-preset volume value
5771 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5772 char identifier[32], name[32];
5773 int value = setup.volume_simple;
5775 ti->node_top = &volumes_simple;
5776 ti->sort_priority = value;
5778 sprintf(identifier, "%d", value);
5779 sprintf(name, "%d %% (Current)", value);
5781 setString(&ti->identifier, identifier);
5782 setString(&ti->name, name);
5783 setString(&ti->name_sorting, name);
5784 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5786 pushTreeInfo(&volumes_simple, ti);
5789 // sort volume values to start with lowest volume value
5790 sortTreeInfo(&volumes_simple);
5792 // set current volume value to configured volume value
5793 volume_simple_current =
5794 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5796 // if that fails, set current volume to reliable default value
5797 if (volume_simple_current == NULL)
5798 volume_simple_current =
5799 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5801 // if that also fails, set current volume to first available value
5802 if (volume_simple_current == NULL)
5803 volume_simple_current = volumes_simple;
5806 if (volumes_loops == NULL)
5808 boolean current_volume_loops_found = FALSE;
5811 for (i = 0; volumes_list[i].value != -1; i++)
5813 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5814 char identifier[32], name[32];
5815 int value = volumes_list[i].value;
5816 char *text = volumes_list[i].text;
5818 ti->node_top = &volumes_loops;
5819 ti->sort_priority = value;
5821 sprintf(identifier, "%d", value);
5822 sprintf(name, "%s", text);
5824 setString(&ti->identifier, identifier);
5825 setString(&ti->name, name);
5826 setString(&ti->name_sorting, name);
5827 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5829 pushTreeInfo(&volumes_loops, ti);
5831 if (value == setup.volume_loops)
5832 current_volume_loops_found = TRUE;
5835 if (!current_volume_loops_found)
5837 // add entry for non-preset volume value
5839 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5840 char identifier[32], name[32];
5841 int value = setup.volume_loops;
5843 ti->node_top = &volumes_loops;
5844 ti->sort_priority = value;
5846 sprintf(identifier, "%d", value);
5847 sprintf(name, "%d %% (Current)", value);
5849 setString(&ti->identifier, identifier);
5850 setString(&ti->name, name);
5851 setString(&ti->name_sorting, name);
5852 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5854 pushTreeInfo(&volumes_loops, ti);
5857 // sort volume values to start with lowest volume value
5858 sortTreeInfo(&volumes_loops);
5860 // set current volume value to configured volume value
5861 volume_loops_current =
5862 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5864 // if that fails, set current volume to reliable default value
5865 if (volume_loops_current == NULL)
5866 volume_loops_current =
5867 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5869 // if that also fails, set current volume to first available value
5870 if (volume_loops_current == NULL)
5871 volume_loops_current = volumes_loops;
5874 if (volumes_music == NULL)
5876 boolean current_volume_music_found = FALSE;
5879 for (i = 0; volumes_list[i].value != -1; i++)
5881 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5882 char identifier[32], name[32];
5883 int value = volumes_list[i].value;
5884 char *text = volumes_list[i].text;
5886 ti->node_top = &volumes_music;
5887 ti->sort_priority = value;
5889 sprintf(identifier, "%d", value);
5890 sprintf(name, "%s", text);
5892 setString(&ti->identifier, identifier);
5893 setString(&ti->name, name);
5894 setString(&ti->name_sorting, name);
5895 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5897 pushTreeInfo(&volumes_music, ti);
5899 if (value == setup.volume_music)
5900 current_volume_music_found = TRUE;
5903 if (!current_volume_music_found)
5905 // add entry for non-preset volume value
5907 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5908 char identifier[32], name[32];
5909 int value = setup.volume_music;
5911 ti->node_top = &volumes_music;
5912 ti->sort_priority = value;
5914 sprintf(identifier, "%d", value);
5915 sprintf(name, "%d %% (Current)", value);
5917 setString(&ti->identifier, identifier);
5918 setString(&ti->name, name);
5919 setString(&ti->name_sorting, name);
5920 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5922 pushTreeInfo(&volumes_music, ti);
5925 // sort volume values to start with lowest volume value
5926 sortTreeInfo(&volumes_music);
5928 // set current volume value to configured volume value
5929 volume_music_current =
5930 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5932 // if that fails, set current volume to reliable default value
5933 if (volume_music_current == NULL)
5934 volume_music_current =
5935 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5937 // if that also fails, set current volume to first available value
5938 if (volume_music_current == NULL)
5939 volume_music_current = volumes_music;
5942 setup.volume_simple = atoi(volume_simple_current->identifier);
5943 setup.volume_loops = atoi(volume_loops_current->identifier);
5944 setup.volume_music = atoi(volume_music_current->identifier);
5946 // needed for displaying volume text instead of identifier
5947 volume_simple_text = volume_simple_current->name;
5948 volume_loops_text = volume_loops_current->name;
5949 volume_music_text = volume_music_current->name;
5951 setup_mode = SETUP_MODE_SOUND;
5956 static void execSetupChooseTouchControls(void)
5958 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5963 static void execSetupChooseMoveDistance(void)
5965 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5970 static void execSetupChooseDropDistance(void)
5972 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5977 static void execSetupChooseTransparency(void)
5979 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5984 static void execSetupChooseGridXSize_0(void)
5986 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5991 static void execSetupChooseGridYSize_0(void)
5993 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5998 static void execSetupChooseGridXSize_1(void)
6000 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6005 static void execSetupChooseGridYSize_1(void)
6007 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6012 static void execSetupConfigureVirtualButtons(void)
6014 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6016 ConfigureVirtualButtons();
6018 setup_mode = SETUP_MODE_TOUCH;
6023 static void execSetupTouch(void)
6027 if (touch_controls == NULL)
6029 for (i = 0; touch_controls_list[i].value != NULL; i++)
6031 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6032 char identifier[32], name[32];
6033 char *value = touch_controls_list[i].value;
6034 char *text = touch_controls_list[i].text;
6036 ti->node_top = &touch_controls;
6037 ti->sort_priority = i;
6039 sprintf(identifier, "%s", value);
6040 sprintf(name, "%s", text);
6042 setString(&ti->identifier, identifier);
6043 setString(&ti->name, name);
6044 setString(&ti->name_sorting, name);
6045 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6047 pushTreeInfo(&touch_controls, ti);
6050 // sort touch control values to start with lowest touch control value
6051 sortTreeInfo(&touch_controls);
6053 // set current touch control value to configured touch control value
6054 touch_control_current =
6055 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6057 // if that fails, set current touch control to reliable default value
6058 if (touch_control_current == NULL)
6059 touch_control_current =
6060 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6062 // if that also fails, set current touch control to first available value
6063 if (touch_control_current == NULL)
6064 touch_control_current = touch_controls;
6067 if (move_distances == NULL)
6069 for (i = 0; distances_list[i].value != -1; i++)
6071 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6072 char identifier[32], name[32];
6073 int value = distances_list[i].value;
6074 char *text = distances_list[i].text;
6076 ti->node_top = &move_distances;
6077 ti->sort_priority = value;
6079 sprintf(identifier, "%d", value);
6080 sprintf(name, "%s", text);
6082 setString(&ti->identifier, identifier);
6083 setString(&ti->name, name);
6084 setString(&ti->name_sorting, name);
6085 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6087 pushTreeInfo(&move_distances, ti);
6090 // sort distance values to start with lowest distance value
6091 sortTreeInfo(&move_distances);
6093 // set current distance value to configured distance value
6094 move_distance_current =
6095 getTreeInfoFromIdentifier(move_distances,
6096 i_to_a(setup.touch.move_distance));
6098 // if that fails, set current distance to reliable default value
6099 if (move_distance_current == NULL)
6100 move_distance_current =
6101 getTreeInfoFromIdentifier(move_distances,
6102 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6104 // if that also fails, set current distance to first available value
6105 if (move_distance_current == NULL)
6106 move_distance_current = move_distances;
6109 if (drop_distances == NULL)
6111 for (i = 0; distances_list[i].value != -1; i++)
6113 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6114 char identifier[32], name[32];
6115 int value = distances_list[i].value;
6116 char *text = distances_list[i].text;
6118 ti->node_top = &drop_distances;
6119 ti->sort_priority = value;
6121 sprintf(identifier, "%d", 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_DROP_DISTANCE);
6129 pushTreeInfo(&drop_distances, ti);
6132 // sort distance values to start with lowest distance value
6133 sortTreeInfo(&drop_distances);
6135 // set current distance value to configured distance value
6136 drop_distance_current =
6137 getTreeInfoFromIdentifier(drop_distances,
6138 i_to_a(setup.touch.drop_distance));
6140 // if that fails, set current distance to reliable default value
6141 if (drop_distance_current == NULL)
6142 drop_distance_current =
6143 getTreeInfoFromIdentifier(drop_distances,
6144 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6146 // if that also fails, set current distance to first available value
6147 if (drop_distance_current == NULL)
6148 drop_distance_current = drop_distances;
6151 if (transparencies == NULL)
6153 for (i = 0; transparencies_list[i].value != -1; i++)
6155 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6156 char identifier[32], name[32];
6157 int value = transparencies_list[i].value;
6158 char *text = transparencies_list[i].text;
6160 ti->node_top = &transparencies;
6161 ti->sort_priority = value;
6163 sprintf(identifier, "%d", value);
6164 sprintf(name, "%s", text);
6166 setString(&ti->identifier, identifier);
6167 setString(&ti->name, name);
6168 setString(&ti->name_sorting, name);
6169 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6171 pushTreeInfo(&transparencies, ti);
6174 // sort transparency values to start with lowest transparency value
6175 sortTreeInfo(&transparencies);
6177 // set current transparency value to configured transparency value
6178 transparency_current =
6179 getTreeInfoFromIdentifier(transparencies,
6180 i_to_a(setup.touch.transparency));
6182 // if that fails, set current transparency to reliable default value
6183 if (transparency_current == NULL)
6184 transparency_current =
6185 getTreeInfoFromIdentifier(transparencies,
6186 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6188 // if that also fails, set current transparency to first available value
6189 if (transparency_current == NULL)
6190 transparency_current = transparencies;
6193 for (i = 0; i < 2; i++)
6195 for (j = 0; j < 2; j++)
6197 if (grid_sizes[i][j] == NULL)
6199 for (k = 0; grid_sizes_list[k].value != -1; k++)
6201 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6202 char identifier[32], name[32];
6203 int value = grid_sizes_list[k].value;
6204 char *text = grid_sizes_list[k].text;
6206 ti->node_top = &grid_sizes[i][j];
6207 ti->sort_priority = value;
6209 sprintf(identifier, "%d", value);
6210 sprintf(name, "%s", text);
6212 setString(&ti->identifier, identifier);
6213 setString(&ti->name, name);
6214 setString(&ti->name_sorting, name);
6215 setString(&ti->infotext,
6218 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6219 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6221 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6222 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6224 pushTreeInfo(&grid_sizes[i][j], ti);
6227 // sort grid size values to start with lowest grid size value
6228 sortTreeInfo(&grid_sizes[i][j]);
6230 // set current grid size value to configured grid size value
6231 grid_size_current[i][j] =
6232 getTreeInfoFromIdentifier(grid_sizes[i][j],
6234 setup.touch.grid_xsize[i] :
6235 setup.touch.grid_ysize[i]));
6237 // if that fails, set current grid size to reliable default value
6238 if (grid_size_current[i][j] == NULL)
6239 grid_size_current[i][j] =
6240 getTreeInfoFromIdentifier(grid_sizes[i][j],
6242 DEFAULT_GRID_XSIZE(i) :
6243 DEFAULT_GRID_YSIZE(i)));
6245 // if that also fails, set current grid size to first available value
6246 if (grid_size_current[i][j] == NULL)
6247 grid_size_current[i][j] = grid_sizes[i][j];
6252 setup.touch.control_type = touch_control_current->identifier;
6253 setup.touch.move_distance = atoi(move_distance_current->identifier);
6254 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6255 setup.touch.transparency = atoi(transparency_current->identifier);
6257 for (i = 0; i < 2; i++)
6259 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6260 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6262 if (i == GRID_ACTIVE_NR())
6264 overlay.grid_xsize = setup.touch.grid_xsize[i];
6265 overlay.grid_ysize = setup.touch.grid_ysize[i];
6269 // needed for displaying value text instead of identifier
6270 touch_controls_text = touch_control_current->name;
6271 move_distance_text = move_distance_current->name;
6272 drop_distance_text = drop_distance_current->name;
6273 transparency_text = transparency_current->name;
6275 for (i = 0; i < 2; i++)
6276 for (j = 0; j < 2; j++)
6277 grid_size_text[i][j] = grid_size_current[i][j]->name;
6279 setup_mode = SETUP_MODE_TOUCH;
6284 static void execSetupArtwork(void)
6287 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6288 artwork.gfx_current->subdir,
6289 artwork.gfx_current->fullpath,
6290 artwork.gfx_current->basepath);
6293 setup.graphics_set = artwork.gfx_current->identifier;
6294 setup.sounds_set = artwork.snd_current->identifier;
6295 setup.music_set = artwork.mus_current->identifier;
6297 // needed if last screen (setup choice) changed graphics, sounds or music
6298 ReloadCustomArtwork(0);
6300 // needed for displaying artwork name instead of artwork identifier
6301 graphics_set_name = artwork.gfx_current->name;
6302 sounds_set_name = artwork.snd_current->name;
6303 music_set_name = artwork.mus_current->name;
6305 setup_mode = SETUP_MODE_ARTWORK;
6310 static void execSetupChooseGraphics(void)
6312 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
6317 static void execSetupChooseSounds(void)
6319 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
6324 static void execSetupChooseMusic(void)
6326 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
6331 static void execSetupInput(void)
6333 setup_mode = SETUP_MODE_INPUT;
6338 static void execSetupShortcuts(void)
6340 setup_mode = SETUP_MODE_SHORTCUTS;
6345 static void execSetupShortcuts1(void)
6347 setup_mode = SETUP_MODE_SHORTCUTS_1;
6352 static void execSetupShortcuts2(void)
6354 setup_mode = SETUP_MODE_SHORTCUTS_2;
6359 static void execSetupShortcuts3(void)
6361 setup_mode = SETUP_MODE_SHORTCUTS_3;
6366 static void execSetupShortcuts4(void)
6368 setup_mode = SETUP_MODE_SHORTCUTS_4;
6373 static void execSetupShortcuts5(void)
6375 setup_mode = SETUP_MODE_SHORTCUTS_5;
6380 static void execExitSetup(void)
6382 SetGameStatus(GAME_MODE_MAIN);
6387 static void execSaveAndExitSetup(void)
6393 static void execGadgetNetworkServer(void)
6395 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6396 struct GadgetInfo *gi = screen_gadget[gadget_id];
6398 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6399 network_server_hostname[0] = '\0';
6401 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6405 ClickOnGadget(gi, MB_LEFTBUTTON);
6408 static void ToggleNetworkModeIfNeeded(void)
6410 int font_title = FONT_TITLE_1;
6411 int font_foot = FC_BLUE;
6412 int ystart = mSY - SY + 16;
6413 int ybottom = mSY - SY + SYSIZE - 20;
6414 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6416 if (setup.network_mode == network.enabled)
6419 network.enabled = setup.network_mode;
6421 FadeOut(REDRAW_ALL);
6425 DrawTextSCentered(ystart, font_title, text);
6429 if (network.enabled)
6430 InitNetworkServer();
6432 DisconnectFromNetworkServer();
6434 DrawTextSCentered(ybottom, font_foot,
6435 "Press any key or button for setup menu");
6437 WaitForEventToContinue();
6442 static void ToggleGameSpeedsListIfNeeded(void)
6444 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6446 if (setup.game_speed_extended == using_game_speeds_extended)
6449 // try to match similar values when changing game speeds list
6450 if (setup.game_speed_extended)
6451 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6452 setup.game_frame_delay == 30 ? 29 :
6453 setup.game_frame_delay);
6455 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6456 setup.game_frame_delay == 16 ? 15 :
6457 setup.game_frame_delay >= 29 ? 30 :
6458 setup.game_frame_delay <= 10 ? 10 :
6459 setup.game_frame_delay);
6461 execSetupGame_setGameSpeeds(TRUE);
6466 static void ModifyGameSpeedIfNeeded(void)
6468 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6469 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6473 char *game_speed_text = "Fast";
6474 int game_speed_value = 15;
6476 if (setup.game_speed_extended)
6478 game_speed_text = "60 fps";
6479 game_speed_value = 16;
6482 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6484 // set game speed to existing list value that is fast enough for vsync
6485 setup.game_frame_delay = game_speed_value;
6487 execSetupGame_setGameSpeeds(TRUE);
6489 Request(message, REQ_CONFIRM);
6492 static void DisableVsyncIfNeeded(void)
6494 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6495 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6496 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6499 // disable vsync for the selected game speed to work
6500 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6502 execSetupGraphics_setVsyncModes(TRUE);
6504 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6510 void *related_value;
6511 } hide_related_entry_list[] =
6513 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6514 { &setup.game_frame_delay, &game_speed_text },
6516 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6517 { &setup.scroll_delay_value, &scroll_delay_text },
6519 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6520 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6522 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6523 { &setup.window_scaling_percent, &window_size_text },
6525 { &setup.window_scaling_quality, execSetupChooseScalingType },
6526 { &setup.window_scaling_quality, &scaling_type_text },
6528 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6529 { &setup.screen_rendering_mode, &rendering_mode_text },
6531 { &setup.vsync_mode, execSetupChooseVsyncMode },
6532 { &setup.vsync_mode, &vsync_mode_text },
6534 { &setup.graphics_set, execSetupChooseGraphics },
6535 { &setup.graphics_set, &graphics_set_name },
6537 { &setup.sounds_set, execSetupChooseSounds },
6538 { &setup.sounds_set, &sounds_set_name },
6540 { &setup.music_set, execSetupChooseMusic },
6541 { &setup.music_set, &music_set_name },
6543 { &setup.volume_simple, execSetupChooseVolumeSimple },
6544 { &setup.volume_simple, &volume_simple_text },
6546 { &setup.volume_loops, execSetupChooseVolumeLoops },
6547 { &setup.volume_loops, &volume_loops_text },
6549 { &setup.volume_music, execSetupChooseVolumeMusic },
6550 { &setup.volume_music, &volume_music_text },
6552 { &setup.touch.control_type, execSetupChooseTouchControls },
6553 { &setup.touch.control_type, &touch_controls_text },
6555 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6556 { &setup.touch.move_distance, &move_distance_text },
6558 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6559 { &setup.touch.drop_distance, &drop_distance_text },
6561 { &setup.touch.transparency, execSetupChooseTransparency },
6562 { &setup.touch.transparency, &transparency_text },
6564 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6565 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6567 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6568 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6570 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6571 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6573 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6574 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6576 { &setup.internal.menu_game, execSetupGame },
6577 { &setup.internal.menu_engines, execSetupEngines },
6578 { &setup.internal.menu_editor, execSetupEditor },
6579 { &setup.internal.menu_graphics, execSetupGraphics },
6580 { &setup.internal.menu_sound, execSetupSound },
6581 { &setup.internal.menu_artwork, execSetupArtwork },
6582 { &setup.internal.menu_input, execSetupInput },
6583 { &setup.internal.menu_touch, execSetupTouch },
6584 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6585 { &setup.internal.menu_exit, execExitSetup },
6586 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6591 void setHideRelatedSetupEntries(void)
6595 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6596 if (hideSetupEntry(hide_related_entry_list[i].value))
6597 setHideSetupEntry(hide_related_entry_list[i].related_value);
6600 static struct TokenInfo setup_info_main[] =
6602 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6603 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6604 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6605 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6606 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6607 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6608 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6609 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6610 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6611 { TYPE_EMPTY, NULL, "" },
6612 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6613 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6618 static struct TokenInfo setup_info_game[] =
6620 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6621 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6622 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6623 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6624 { TYPE_STRING, &network_server_text, "" },
6625 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
6626 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6627 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6628 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6629 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6630 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6631 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6632 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
6633 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6634 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6635 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6636 { TYPE_STRING, &game_speed_text, "" },
6637 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6639 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6640 { TYPE_STRING, &scroll_delay_text, "" },
6642 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6643 { TYPE_STRING, &snapshot_mode_text, "" },
6644 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6645 { TYPE_EMPTY, NULL, "" },
6646 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6651 static struct TokenInfo setup_info_engines[] =
6653 { TYPE_HEADLINE, NULL, "Emerald Mine" },
6654 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
6655 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
6656 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
6657 { TYPE_EMPTY, NULL, "" },
6658 { TYPE_HEADLINE, NULL, "Supaplex" },
6659 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
6660 { TYPE_EMPTY, NULL, "" },
6661 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6666 static struct TokenInfo setup_info_editor[] =
6669 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6670 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6671 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6672 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6673 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6674 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6675 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6676 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6677 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6678 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6680 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6681 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6683 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6685 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6686 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6687 { TYPE_EMPTY, NULL, "" },
6689 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6690 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6691 { TYPE_EMPTY, NULL, "" },
6693 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6694 { TYPE_EMPTY, NULL, "" },
6695 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6700 static struct TokenInfo setup_info_graphics[] =
6702 #if !defined(PLATFORM_ANDROID)
6703 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6704 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6705 { TYPE_STRING, &window_size_text, "" },
6706 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6707 { TYPE_STRING, &scaling_type_text, "" },
6708 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6709 { TYPE_STRING, &rendering_mode_text, "" },
6712 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6713 { TYPE_STRING, &scroll_delay_text, "" },
6715 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6716 { TYPE_STRING, &vsync_mode_text, "" },
6717 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6718 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6719 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6720 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6721 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6722 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6723 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
6724 { TYPE_EMPTY, NULL, "" },
6725 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6730 static struct TokenInfo setup_info_sound[] =
6732 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6733 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6734 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6735 { TYPE_EMPTY, NULL, "" },
6736 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6737 { TYPE_STRING, &volume_simple_text, "" },
6738 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6739 { TYPE_STRING, &volume_loops_text, "" },
6740 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6741 { TYPE_STRING, &volume_music_text, "" },
6742 { TYPE_EMPTY, NULL, "" },
6743 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6748 static struct TokenInfo setup_info_artwork[] =
6750 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6751 { TYPE_STRING, &graphics_set_name, "" },
6752 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6753 { TYPE_STRING, &sounds_set_name, "" },
6754 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6755 { TYPE_STRING, &music_set_name, "" },
6756 { TYPE_EMPTY, NULL, "" },
6757 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6758 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6759 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6760 { TYPE_EMPTY, NULL, "" },
6761 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6766 static struct TokenInfo setup_info_input[] =
6768 { TYPE_SWITCH, NULL, "Player:" },
6769 { TYPE_SWITCH, NULL, "Device:" },
6770 { TYPE_SWITCH, NULL, "" },
6771 { TYPE_SKIPPABLE, NULL, "" },
6772 { TYPE_EMPTY, NULL, "" },
6773 { TYPE_EMPTY, NULL, "" },
6774 { TYPE_EMPTY, NULL, "" },
6775 { TYPE_EMPTY, NULL, "" },
6776 { TYPE_EMPTY, NULL, "" },
6777 { TYPE_EMPTY, NULL, "" },
6778 { TYPE_EMPTY, NULL, "" },
6779 { TYPE_EMPTY, NULL, "" },
6780 { TYPE_SKIPPABLE, NULL, "" },
6781 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6786 static struct TokenInfo setup_info_touch[] =
6788 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6789 { TYPE_STRING, &touch_controls_text, "" },
6790 { TYPE_EMPTY, NULL, "" },
6791 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6796 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6798 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6799 { TYPE_STRING, &touch_controls_text, "" },
6800 { TYPE_EMPTY, NULL, "" },
6801 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6802 { TYPE_STRING, &grid_size_text[0][0], "" },
6803 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6804 { TYPE_STRING, &grid_size_text[0][1], "" },
6805 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6806 { TYPE_STRING, &transparency_text, "" },
6807 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6808 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6809 { TYPE_EMPTY, NULL, "" },
6810 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6811 { TYPE_EMPTY, NULL, "" },
6812 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6817 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6819 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6820 { TYPE_STRING, &touch_controls_text, "" },
6821 { TYPE_EMPTY, NULL, "" },
6822 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6823 { TYPE_STRING, &grid_size_text[1][0], "" },
6824 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6825 { TYPE_STRING, &grid_size_text[1][1], "" },
6826 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6827 { TYPE_STRING, &transparency_text, "" },
6828 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6829 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6830 { TYPE_EMPTY, NULL, "" },
6831 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6832 { TYPE_EMPTY, NULL, "" },
6833 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6838 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6840 setup_info_touch_virtual_buttons_0,
6841 setup_info_touch_virtual_buttons_1
6844 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6846 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6847 { TYPE_STRING, &touch_controls_text, "" },
6848 { TYPE_EMPTY, NULL, "" },
6849 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6850 { TYPE_STRING, &move_distance_text, "" },
6851 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6852 { TYPE_STRING, &drop_distance_text, "" },
6853 { TYPE_EMPTY, NULL, "" },
6854 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6859 static struct TokenInfo setup_info_shortcuts[] =
6861 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6862 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6863 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6864 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6865 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6866 { TYPE_EMPTY, NULL, "" },
6867 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6872 static struct TokenInfo setup_info_shortcuts_1[] =
6874 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6875 { TYPE_KEY, &setup.shortcut.save_game, "" },
6876 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6877 { TYPE_KEY, &setup.shortcut.load_game, "" },
6878 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6879 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6880 { TYPE_EMPTY, NULL, "" },
6881 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6882 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6883 { TYPE_EMPTY, NULL, "" },
6884 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6889 static struct TokenInfo setup_info_shortcuts_2[] =
6891 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6892 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6893 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6894 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6895 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6896 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6897 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6898 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6899 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6900 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6901 { TYPE_EMPTY, NULL, "" },
6902 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6907 static struct TokenInfo setup_info_shortcuts_3[] =
6909 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6910 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6911 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6912 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6913 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6914 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6915 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6916 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6917 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6918 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6919 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6920 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6921 { TYPE_EMPTY, NULL, "" },
6922 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6927 static struct TokenInfo setup_info_shortcuts_4[] =
6929 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6930 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6931 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6932 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6933 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6934 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6935 { TYPE_EMPTY, NULL, "" },
6936 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6941 static struct TokenInfo setup_info_shortcuts_5[] =
6943 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6944 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6945 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6946 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6947 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6948 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6949 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6950 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6951 { TYPE_EMPTY, NULL, "" },
6952 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6957 static Key getSetupKey(void)
6959 Key key = KSYM_UNDEFINED;
6960 boolean got_key_event = FALSE;
6962 while (!got_key_event)
6966 if (NextValidEvent(&event))
6970 case EVENT_KEYPRESS:
6972 key = GetEventKey((KeyEvent *)&event, TRUE);
6974 // press 'Escape' or 'Enter' to keep the existing key binding
6975 if (key == KSYM_Escape || key == KSYM_Return)
6976 key = KSYM_UNDEFINED; // keep old value
6978 got_key_event = TRUE;
6982 case EVENT_KEYRELEASE:
6983 key_joystick_mapping = 0;
6987 HandleOtherEvents(&event);
6998 static int getSetupValueFont(int type, void *value)
7000 if (type & TYPE_GHOSTED)
7001 return FONT_OPTION_OFF;
7002 else if (type & TYPE_KEY)
7003 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7004 else if (type & TYPE_STRING)
7005 return FONT_VALUE_2;
7006 else if (type & TYPE_ECS_AGA)
7007 return FONT_VALUE_1;
7008 else if (type & TYPE_BOOLEAN_STYLE)
7009 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7010 else if (type & TYPE_YES_NO_AUTO)
7011 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7012 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7013 else if (type & TYPE_PLAYER)
7014 return FONT_VALUE_1;
7016 return FONT_VALUE_1;
7019 static int getSetupValueFontNarrow(int type, int font_nr)
7021 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7022 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7023 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7027 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7029 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7030 struct TokenInfo *si = &setup_info[si_pos];
7031 boolean font_draw_xoffset_modified = FALSE;
7032 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7033 int font_draw_xoffset_old = -1;
7034 int xoffset = (scrollbar_needed ? -1 : 0);
7035 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7036 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7037 int xpos = menu_screen_value_xpos;
7038 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7039 int startx = mSX + xpos * 32;
7040 int starty = mSY + ypos * 32;
7041 int type = si->type;
7042 void *value = si->value;
7043 char *value_string = getSetupValue(type, value);
7044 int font_nr_default = getSetupValueFont(type, value);
7045 int font_width_default = getFontWidth(font_nr_default);
7046 int font_nr = font_nr_default;
7049 if (value_string == NULL)
7052 if (type & TYPE_KEY)
7054 xpos = MENU_SCREEN_START_XPOS;
7056 if (type & TYPE_QUERY)
7057 value_string = "<press key>";
7059 else if (type & TYPE_STRING)
7061 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7063 xpos = MENU_SCREEN_START_XPOS;
7065 if (strlen(value_string) > max_value_len)
7066 value_string[max_value_len] = '\0';
7068 else if (type & TYPE_YES_NO_AUTO)
7070 xpos = menu_screen_value_xpos - 1;
7072 else if (type & TYPE_PLAYER)
7074 int displayed_player_nr = *(int *)value + 1;
7076 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7079 startx = mSX + xpos * 32;
7080 starty = mSY + ypos * 32;
7082 // special check if right-side setup values moved left due to scrollbar
7083 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7085 int max_menu_text_length = 26; // maximum text length for classic menu
7086 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7087 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7088 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7089 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7090 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7092 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7094 // when using narrow font, left-shifting text "auto" not needed
7095 if (type & TYPE_YES_NO_AUTO)
7099 startx = mSX + xpos * 32;
7101 font_nr = getSetupValueFontNarrow(type, font_nr);
7105 // downward compatibility correction for Juergen Bonhagen's menu settings
7106 if (setup_mode != SETUP_MODE_INPUT)
7108 int max_menu_text_length_big = (menu_screen_value_xpos -
7109 MENU_SCREEN_START_XPOS);
7110 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7111 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7112 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
7113 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
7114 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7115 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7116 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
7117 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7118 boolean correct_font_draw_xoffset = FALSE;
7120 if (xpos == MENU_SCREEN_START_XPOS &&
7121 startx + font1_xoffset < text_startx + text_font_xoffset)
7122 correct_font_draw_xoffset = TRUE;
7124 if (xpos == menu_screen_value_xpos &&
7125 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7126 correct_font_draw_xoffset = TRUE;
7128 // check if setup value would overlap with setup text when printed
7129 // (this can happen for extreme/wrong values for font draw offset)
7130 if (correct_font_draw_xoffset)
7132 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
7133 font_draw_xoffset_modified = TRUE;
7135 if (type & TYPE_KEY)
7136 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7137 else if (!(type & TYPE_STRING))
7138 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7139 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7143 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7144 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7146 DrawText(startx, starty, value_string, font_nr);
7148 if (type & TYPE_PLAYER)
7150 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7151 int player_nr = *(int *)value;
7152 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7153 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7154 int startx2 = startx + xoff;
7155 int starty2 = starty + yoff;
7157 if (DrawingOnBackground(startx2, starty2))
7158 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7160 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7161 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7164 if (font_draw_xoffset_modified)
7165 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7168 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7170 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7171 struct TokenInfo *si = &setup_info[si_pos];
7173 if (si->type & TYPE_BOOLEAN_STYLE)
7175 *(boolean *)si->value ^= TRUE;
7177 else if (si->type & TYPE_YES_NO_AUTO)
7181 (*(int *)si->value == AUTO ? TRUE :
7182 *(int *)si->value == TRUE ? FALSE : AUTO) :
7183 (*(int *)si->value == TRUE ? AUTO :
7184 *(int *)si->value == AUTO ? FALSE : TRUE));
7186 else if (si->type & TYPE_KEY)
7190 si->type |= TYPE_QUERY;
7191 drawSetupValue(screen_pos, setup_info_pos_raw);
7192 si->type &= ~TYPE_QUERY;
7194 key = getSetupKey();
7195 if (key != KSYM_UNDEFINED)
7196 *(Key *)si->value = key;
7198 else if (si->type & TYPE_PLAYER)
7200 int player_nr = *(int *)si->value;
7205 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7207 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7210 drawSetupValue(screen_pos, setup_info_pos_raw);
7212 // fullscreen state may have changed at this point
7213 if (si->value == &setup.fullscreen)
7214 ToggleFullscreenIfNeeded();
7216 // network mode may have changed at this point
7217 if (si->value == &setup.network_mode)
7218 ToggleNetworkModeIfNeeded();
7220 // game speed list may have changed at this point
7221 if (si->value == &setup.game_speed_extended)
7222 ToggleGameSpeedsListIfNeeded();
7225 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7227 static struct TokenInfo *setup_info_final = NULL;
7232 // determine maximum list size of target list
7233 while (setup_info_orig[list_size++].type != 0);
7235 // free, allocate and clear memory for target list
7236 checked_free(setup_info_final);
7237 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7239 // copy setup info list without setup entries marked as hidden
7240 for (i = 0; setup_info_orig[i].type != 0; i++)
7242 // skip setup entries configured to be hidden
7243 if (hideSetupEntry(setup_info_orig[i].value))
7246 // skip skippable setup entries if screen is lower than usual
7247 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
7248 setup_info_orig[i].type == TYPE_SKIPPABLE)
7251 setup_info_final[list_pos++] = setup_info_orig[i];
7254 return setup_info_final;
7257 static void DrawSetupScreen_Generic(void)
7259 int fade_mask = REDRAW_FIELD;
7260 boolean redraw_all = FALSE;
7261 char *title_string = NULL;
7265 fade_mask = REDRAW_ALL;
7268 FadeMenuSoundsAndMusic();
7270 FreeScreenGadgets();
7271 CreateScreenGadgets();
7273 if (redraw_mask & REDRAW_ALL)
7278 // needed if different viewport properties defined for setup screen
7279 ChangeViewportPropertiesIfNeeded();
7281 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7285 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
7287 if (setup_mode == SETUP_MODE_MAIN)
7289 setup_info = setup_info_main;
7290 title_string = STR_SETUP_MAIN;
7292 else if (setup_mode == SETUP_MODE_GAME)
7294 setup_info = setup_info_game;
7295 title_string = STR_SETUP_GAME;
7297 else if (setup_mode == SETUP_MODE_ENGINES)
7299 setup_info = setup_info_engines;
7300 title_string = STR_SETUP_ENGINES;
7302 else if (setup_mode == SETUP_MODE_EDITOR)
7304 setup_info = setup_info_editor;
7305 title_string = STR_SETUP_EDITOR;
7307 else if (setup_mode == SETUP_MODE_GRAPHICS)
7309 setup_info = setup_info_graphics;
7310 title_string = STR_SETUP_GRAPHICS;
7312 else if (setup_mode == SETUP_MODE_SOUND)
7314 setup_info = setup_info_sound;
7315 title_string = STR_SETUP_SOUND;
7317 else if (setup_mode == SETUP_MODE_ARTWORK)
7319 setup_info = setup_info_artwork;
7320 title_string = STR_SETUP_ARTWORK;
7322 else if (setup_mode == SETUP_MODE_TOUCH)
7324 setup_info = setup_info_touch;
7325 title_string = STR_SETUP_TOUCH;
7327 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
7328 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
7329 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
7330 setup_info = setup_info_touch_wipe_gestures;
7332 else if (setup_mode == SETUP_MODE_SHORTCUTS)
7334 setup_info = setup_info_shortcuts;
7335 title_string = STR_SETUP_SHORTCUTS;
7337 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7339 setup_info = setup_info_shortcuts_1;
7340 title_string = STR_SETUP_SHORTCUTS;
7342 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7344 setup_info = setup_info_shortcuts_2;
7345 title_string = STR_SETUP_SHORTCUTS;
7347 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7349 setup_info = setup_info_shortcuts_3;
7350 title_string = STR_SETUP_SHORTCUTS;
7352 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7354 setup_info = setup_info_shortcuts_4;
7355 title_string = STR_SETUP_SHORTCUTS;
7357 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7359 setup_info = setup_info_shortcuts_5;
7360 title_string = STR_SETUP_SHORTCUTS;
7363 // use modified setup info without setup entries marked as hidden
7364 setup_info = getSetupInfoFinal(setup_info);
7366 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7368 // determine maximal number of setup entries that can be displayed on screen
7370 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7373 // determine maximal number of setup entries available for this setup screen
7375 for (i = 0; setup_info[i].type != 0; i++)
7378 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7380 MapScreenGadgets(max_setup_info);
7383 redraw_mask = fade_mask = REDRAW_ALL;
7385 DrawMaskedBorder(fade_mask);
7390 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7392 menu_info = setup_info;
7394 HandleMenuScreen(mx, my, dx, dy, button,
7395 setup_mode, num_setup_info, max_setup_info);
7398 static void DrawSetupScreen_Input(void)
7402 FadeOut(REDRAW_FIELD);
7406 setup_info = getSetupInfoFinal(setup_info_input);
7408 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7410 for (i = 0; setup_info[i].type != 0; i++)
7412 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7413 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7414 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7415 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7416 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7417 initCursor(i, IMG_MENU_BUTTON);
7419 DrawCursorAndText_Setup(i, -1, FALSE);
7422 // create gadgets for setup input menu screen
7423 FreeScreenGadgets();
7424 CreateScreenGadgets();
7426 // map gadgets for setup input menu screen
7427 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7429 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7431 FadeIn(REDRAW_FIELD);
7434 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7436 if (device_name == NULL)
7439 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7442 if (strlen(device_name) > 1)
7444 char c1 = device_name[strlen(device_name) - 1];
7445 char c2 = device_name[strlen(device_name) - 2];
7447 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7448 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7451 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7452 strlen(device_name));
7455 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7458 static struct SetupKeyboardInfo custom_key;
7465 { &custom_key.left, "Axis/Pad Left" },
7466 { &custom_key.right, "Axis/Pad Right" },
7467 { &custom_key.up, "Axis/Pad Up" },
7468 { &custom_key.down, "Axis/Pad Down" },
7469 { &custom_key.snap, "Button 1/A/X" },
7470 { &custom_key.drop, "Button 2/B/Y" }
7472 static char *joystick_name[MAX_PLAYERS] =
7479 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7480 int font_nr_info = FONT_MENU_1;
7481 int font_nr_name = FONT_VALUE_OLD;
7482 int font_nr_on = FONT_VALUE_1;
7483 int font_nr_off = FONT_VALUE_OLD;
7486 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7488 font_nr_info = FONT_MENU_2;
7489 font_nr_on = FONT_VALUE_NARROW;
7490 font_nr_off = FONT_VALUE_OLD_NARROW;
7493 custom_key = setup.input[player_nr].key;
7495 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7496 FONT_INPUT_1_ACTIVE);
7498 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7500 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7501 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7503 if (setup.input[player_nr].use_joystick)
7505 char *device_name = setup.input[player_nr].joy.device_name;
7506 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7507 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7508 char *text = joystick_name[joystick_nr];
7509 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7511 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7512 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7516 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7517 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7520 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7521 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7525 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7526 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7527 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7528 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7530 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7531 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7532 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7533 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7534 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7535 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7537 for (i = 0; i < 6; i++)
7539 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7541 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7543 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7544 (setup.input[player_nr].use_joystick ?
7546 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7550 static int input_player_nr = 0;
7552 static void HandleSetupScreen_Input_Player(int step, int direction)
7554 int old_player_nr = input_player_nr;
7557 new_player_nr = old_player_nr + step * direction;
7558 if (new_player_nr < 0)
7560 if (new_player_nr > MAX_PLAYERS - 1)
7561 new_player_nr = MAX_PLAYERS - 1;
7563 if (new_player_nr != old_player_nr)
7565 input_player_nr = new_player_nr;
7567 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7571 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7573 static int choice = 0;
7576 int pos_start = SETUPINPUT_SCREEN_POS_START;
7577 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7578 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7579 int pos_end = SETUPINPUT_SCREEN_POS_END;
7581 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7585 for (i = 0; setup_info_input[i].type != 0; i++)
7587 // adjust menu structure according to skipped setup entries
7588 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7596 if (button == MB_MENU_INITIALIZE)
7598 // input setup menu may have changed size due to graphics configuration
7599 if (choice >= pos_empty1)
7602 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7604 DrawCursorAndText_Setup(choice, -1, TRUE);
7608 else if (button == MB_MENU_LEAVE)
7610 setup_mode = SETUP_MODE_MAIN;
7617 if (mx || my) // mouse input
7619 x = (mx - mSX) / 32;
7620 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7622 else if (dx || dy) // keyboard input
7624 if (dx && choice == 0)
7625 x = (dx < 0 ? 10 : 12);
7626 else if ((dx && choice == 1) ||
7627 (dx == -1 && choice == pos_end))
7628 button = MB_MENU_CHOICE;
7632 if (y >= pos_empty1 && y <= pos_empty2)
7633 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7636 if (y == 0 && dx != 0 && button)
7638 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7640 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7641 y >= pos_start && y <= pos_end &&
7642 !(y >= pos_empty1 && y <= pos_empty2))
7648 DrawCursorAndText_Setup(choice, -1, FALSE);
7649 DrawCursorAndText_Setup(y, -1, TRUE);
7651 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7660 char *device_name = setup.input[input_player_nr].joy.device_name;
7662 if (!setup.input[input_player_nr].use_joystick)
7664 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7666 setJoystickDeviceToNr(device_name, new_device_nr);
7667 setup.input[input_player_nr].use_joystick = TRUE;
7671 int device_nr = getJoystickNrFromDeviceName(device_name);
7672 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7674 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7675 setup.input[input_player_nr].use_joystick = FALSE;
7677 setJoystickDeviceToNr(device_name, new_device_nr);
7680 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7684 if (setup.input[input_player_nr].use_joystick)
7685 ConfigureJoystick(input_player_nr);
7687 CustomizeKeyboard(input_player_nr);
7689 else if (y == pos_end)
7695 setup_mode = SETUP_MODE_MAIN;
7702 static boolean CustomizeKeyboardMain(int player_nr)
7706 boolean finished = FALSE;
7707 static struct SetupKeyboardInfo custom_key;
7712 } customize_step[] =
7714 { &custom_key.left, "Move Left" },
7715 { &custom_key.right, "Move Right" },
7716 { &custom_key.up, "Move Up" },
7717 { &custom_key.down, "Move Down" },
7718 { &custom_key.snap, "Snap Field" },
7719 { &custom_key.drop, "Drop Element" }
7721 int font_nr_old = FONT_VALUE_OLD;
7722 int font_nr_new = FONT_VALUE_1;
7723 boolean success = FALSE;
7725 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7727 font_nr_old = FONT_VALUE_OLD_NARROW;
7728 font_nr_new = FONT_VALUE_NARROW;
7731 // read existing key bindings from player setup
7732 custom_key = setup.input[player_nr].key;
7735 FadeOut(REDRAW_FIELD);
7739 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7742 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7743 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7744 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7745 "Key:", FONT_INPUT_1_ACTIVE);
7746 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7747 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7749 FadeIn(REDRAW_FIELD);
7755 if (NextValidEvent(&event))
7759 case EVENT_KEYPRESS:
7761 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7763 // press 'Escape' to abort and keep the old key bindings
7764 if (key == KSYM_Escape)
7766 FadeSkipNextFadeIn();
7773 // press 'Enter' to keep the existing key binding
7774 if (key == KSYM_Return)
7775 key = *customize_step[step_nr].key;
7777 // check if key already used
7778 for (i = 0; i < step_nr; i++)
7779 if (*customize_step[i].key == key)
7784 // got new key binding
7785 *customize_step[step_nr].key = key;
7786 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7788 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7789 getKeyNameFromKey(key), font_nr_new);
7792 // un-highlight last query
7793 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7794 customize_step[step_nr - 1].text, FONT_MENU_1);
7795 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7796 "Key:", FONT_MENU_1);
7798 // all keys configured
7807 // query next key binding
7808 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7809 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7810 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7811 "Key:", FONT_INPUT_1_ACTIVE);
7812 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7813 getKeyNameFromKey(*customize_step[step_nr].key),
7818 case EVENT_KEYRELEASE:
7819 key_joystick_mapping = 0;
7823 HandleOtherEvents(&event);
7831 // write new key bindings back to player setup, if successfully finished
7833 setup.input[player_nr].key = custom_key;
7838 void CustomizeKeyboard(int player_nr)
7840 boolean success = CustomizeKeyboardMain(player_nr);
7844 int font_nr = FONT_TITLE_1;
7845 int font_height = getFontHeight(font_nr);
7846 int ypos1 = SYSIZE / 2 - font_height * 2;
7847 int ypos2 = SYSIZE / 2 - font_height * 1;
7848 unsigned int wait_frame_delay = 0;
7849 unsigned int wait_frame_delay_value = 2000;
7851 ResetDelayCounter(&wait_frame_delay);
7855 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7856 DrawTextSCentered(ypos2, font_nr, "configured!");
7858 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7864 DrawSetupScreen_Input();
7867 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
7869 #define MARKER_BUTTON 1
7870 #define MARKER_AXIS_X 2
7871 #define MARKER_AXIS_Y 3
7873 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7875 static boolean bitmaps_initialized = FALSE;
7876 boolean screen_initialized = FALSE;
7877 static Bitmap *controller, *button, *axis_x, *axis_y;
7879 boolean success = TRUE;
7880 boolean done = FALSE, next = FALSE;
7882 int alpha = 200, alpha_step = -1;
7883 int alpha_ticks = 0;
7884 char mapping[4096], temp[256];
7885 int font_name = MENU_SETUP_FONT_TITLE;
7886 int font_info = MENU_SETUP_FONT_TEXT;
7887 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7888 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7889 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7890 int ystep_name = getMenuTextStep(spacing_name, font_name);
7891 int ystep_line = getMenuTextStep(spacing_line, font_info);
7892 int ystep_para = getMenuTextStep(spacing_para, font_info);
7900 int axis, button, hat, hat_value;
7903 *step, *prev_step, steps[] =
7905 { 356, 155, MARKER_BUTTON, "a", },
7906 { 396, 122, MARKER_BUTTON, "b", },
7907 { 320, 125, MARKER_BUTTON, "x", },
7908 { 358, 95, MARKER_BUTTON, "y", },
7909 { 162, 125, MARKER_BUTTON, "back", },
7910 { 216, 125, MARKER_BUTTON, "guide", },
7911 { 271, 125, MARKER_BUTTON, "start", },
7912 { 110, 200, MARKER_BUTTON, "dpleft", },
7913 { 146, 228, MARKER_BUTTON, "dpdown", },
7914 { 178, 200, MARKER_BUTTON, "dpright", },
7915 { 146, 172, MARKER_BUTTON, "dpup", },
7916 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7917 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7918 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7919 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7920 { 73, 141, MARKER_BUTTON, "leftstick", },
7921 { 282, 210, MARKER_BUTTON, "rightstick", },
7922 { 73, 141, MARKER_AXIS_X, "leftx", },
7923 { 73, 141, MARKER_AXIS_Y, "lefty", },
7924 { 282, 210, MARKER_AXIS_X, "rightx", },
7925 { 282, 210, MARKER_AXIS_Y, "righty", },
7928 unsigned int event_frame_delay = 0;
7929 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7931 ResetDelayCounter(&event_frame_delay);
7933 if (!bitmaps_initialized)
7935 controller = LoadCustomImage("joystick/controller.png");
7936 button = LoadCustomImage("joystick/button.png");
7937 axis_x = LoadCustomImage("joystick/axis_x.png");
7938 axis_y = LoadCustomImage("joystick/axis_y.png");
7940 bitmaps_initialized = TRUE;
7943 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7946 // print info about the joystick we are watching
7947 Debug("joystick", "watching joystick %d: (%s)",
7948 SDL_JoystickInstanceID(joystick), name);
7949 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
7950 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7951 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7954 // initialize mapping with GUID and name
7955 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7957 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7958 temp, name, SDL_GetPlatform());
7960 // loop through all steps (buttons and axes), getting joystick events
7961 for (i = 0; i < SDL_arraysize(steps) && !done;)
7963 Bitmap *marker = button; // initialize with reliable default value
7966 strcpy(step->mapping, mapping);
7970 step->hat_value = -1;
7972 marker = (step->marker == MARKER_BUTTON ? button :
7973 step->marker == MARKER_AXIS_X ? axis_x :
7974 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7978 while (!done && !next)
7980 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7981 alpha_ticks = SDL_GetTicks();
7988 else if (alpha < 128)
7994 int controller_x = SX + (SXSIZE - controller->width) / 2;
7995 int controller_y = SY + ystep_line;
7997 int marker_x = controller_x + step->x;
7998 int marker_y = controller_y + step->y;
8000 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8001 int ystart2 = ystart1 + ystep_name + ystep_line;
8005 DrawTextSCentered(ystart1, font_name, name);
8007 DrawTextSCentered(ystart2, font_info,
8008 "Press buttons and move axes on");
8009 ystart2 += ystep_line;
8010 DrawTextSCentered(ystart2, font_info,
8011 "your controller when indicated.");
8012 ystart2 += ystep_line;
8013 DrawTextSCentered(ystart2, font_info,
8014 "(Your controller may look different.)");
8015 ystart2 += ystep_para;
8017 #if defined(PLATFORM_ANDROID)
8018 DrawTextSCentered(ystart2, font_info,
8019 "To correct a mistake,");
8020 ystart2 += ystep_line;
8021 DrawTextSCentered(ystart2, font_info,
8022 "press the 'back' button.");
8023 ystart2 += ystep_line;
8024 DrawTextSCentered(ystart2, font_info,
8025 "To skip a button or axis,");
8026 ystart2 += ystep_line;
8027 DrawTextSCentered(ystart2, font_info,
8028 "press the 'menu' button.");
8030 DrawTextSCentered(ystart2, font_info,
8031 "To correct a mistake,");
8032 ystart2 += ystep_line;
8033 DrawTextSCentered(ystart2, font_info,
8034 "press the 'backspace' key.");
8035 ystart2 += ystep_line;
8036 DrawTextSCentered(ystart2, font_info,
8037 "To skip a button or axis,");
8038 ystart2 += ystep_line;
8039 DrawTextSCentered(ystart2, font_info,
8040 "press the 'return' key.");
8041 ystart2 += ystep_line;
8042 DrawTextSCentered(ystart2, font_info,
8043 "To exit, press the 'escape' key.");
8046 BlitBitmapMasked(controller, drawto, 0, 0,
8047 controller->width, controller->height,
8048 controller_x, controller_y);
8050 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8051 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8053 BlitBitmapMasked(marker, drawto, 0, 0,
8054 marker->width, marker->height,
8055 marker_x, marker_y);
8057 if (!screen_initialized)
8058 FadeIn(REDRAW_FIELD);
8062 screen_initialized = TRUE;
8064 while (NextValidEvent(&event))
8068 case SDL_JOYAXISMOTION:
8069 if (event.jaxis.value > 20000 ||
8070 event.jaxis.value < -20000)
8072 for (j = 0; j < i; j++)
8073 if (steps[j].axis == event.jaxis.axis)
8078 if (step->marker != MARKER_AXIS_X &&
8079 step->marker != MARKER_AXIS_Y)
8082 step->axis = event.jaxis.axis;
8083 strcat(mapping, step->field);
8084 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8085 strcat(mapping, temp);
8093 case SDL_JOYHATMOTION:
8094 // ignore centering; we're probably just coming back
8095 // to the center from the previous item we set
8096 if (event.jhat.value == SDL_HAT_CENTERED)
8099 for (j = 0; j < i; j++)
8100 if (steps[j].hat == event.jhat.hat &&
8101 steps[j].hat_value == event.jhat.value)
8106 step->hat = event.jhat.hat;
8107 step->hat_value = event.jhat.value;
8108 strcat(mapping, step->field);
8109 snprintf(temp, sizeof(temp), ":h%u.%u,",
8110 event.jhat.hat, event.jhat.value );
8111 strcat(mapping, temp);
8118 case SDL_JOYBALLMOTION:
8121 case SDL_JOYBUTTONUP:
8122 for (j = 0; j < i; j++)
8123 if (steps[j].button == event.jbutton.button)
8128 step->button = event.jbutton.button;
8129 strcat(mapping, step->field);
8130 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8131 strcat(mapping, temp);
8138 case SDL_FINGERDOWN:
8139 case SDL_MOUSEBUTTONDOWN:
8147 if (event.key.keysym.sym == KSYM_BackSpace ||
8148 event.key.keysym.sym == KSYM_Back)
8160 prev_step = &steps[i - 1];
8161 strcpy(mapping, prev_step->mapping);
8168 if (event.key.keysym.sym == KSYM_space ||
8169 event.key.keysym.sym == KSYM_Return ||
8170 event.key.keysym.sym == KSYM_Menu)
8179 if (event.key.keysym.sym == KSYM_Escape)
8189 program.exit_function(0);
8196 // do not handle events for longer than standard frame delay period
8197 if (DelayReached(&event_frame_delay, event_frame_delay_value))
8206 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8209 // activate mapping for this game
8210 SDL_GameControllerAddMapping(mapping);
8212 // save mapping to personal mappings
8213 SaveSetup_AddGameControllerMapping(mapping);
8216 // wait until the last pending event was removed from event queue
8217 while (NextValidEvent(&event));
8222 static int ConfigureJoystickMain(int player_nr)
8224 char *device_name = setup.input[player_nr].joy.device_name;
8225 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8226 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8227 int success = FALSE;
8230 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8231 return JOYSTICK_NOT_AVAILABLE;
8233 if (!joystick_active || !setup.input[player_nr].use_joystick)
8234 return JOYSTICK_NOT_AVAILABLE;
8237 FadeOut(REDRAW_FIELD);
8239 // close all joystick devices (potentially opened as game controllers)
8240 for (i = 0; i < SDL_NumJoysticks(); i++)
8241 SDLCloseJoystick(i);
8243 // open joystick device as plain joystick to configure as game controller
8244 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
8246 // as the joystick was successfully opened before, this should not happen
8247 if (joystick == NULL)
8250 // create new game controller mapping (buttons and axes) for joystick device
8251 success = ConfigureJoystickMapButtonsAndAxes(joystick);
8253 // close joystick (and maybe re-open as configured game controller later)
8254 SDL_JoystickClose(joystick);
8256 // re-open all joystick devices (potentially as game controllers)
8257 for (i = 0; i < SDL_NumJoysticks(); i++)
8260 // clear all joystick input actions for all joystick devices
8261 SDLClearJoystickState();
8263 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
8266 void ConfigureJoystick(int player_nr)
8268 boolean state = ConfigureJoystickMain(player_nr);
8270 if (state != JOYSTICK_NOT_CONFIGURED)
8272 boolean success = (state == JOYSTICK_CONFIGURED);
8273 char message1[MAX_OUTPUT_LINESIZE + 1];
8274 char *message2 = (success ? "configured!" : "not available!");
8275 char *device_name = setup.input[player_nr].joy.device_name;
8276 int nr = getJoystickNrFromDeviceName(device_name) + 1;
8277 int font_nr = FONT_TITLE_1;
8278 int font_height = getFontHeight(font_nr);
8279 int ypos1 = SYSIZE / 2 - font_height * 2;
8280 int ypos2 = SYSIZE / 2 - font_height * 1;
8281 unsigned int wait_frame_delay = 0;
8282 unsigned int wait_frame_delay_value = 2000;
8284 ResetDelayCounter(&wait_frame_delay);
8288 sprintf(message1, "Joystick %d", nr);
8290 DrawTextSCentered(ypos1, font_nr, message1);
8291 DrawTextSCentered(ypos2, font_nr, message2);
8293 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8299 DrawSetupScreen_Input();
8302 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
8304 if (y < video.screen_height / 3)
8306 // remap touch gadgets to access upper part of the screen
8307 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8308 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8310 else if (y > 2 * video.screen_height / 3)
8312 // remap touch gadgets to access lower part of the screen
8313 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8314 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
8318 static boolean ConfigureVirtualButtonsMain(void)
8320 static char *customize_step_text[] =
8329 char grid_button[] =
8331 CHAR_GRID_BUTTON_LEFT,
8332 CHAR_GRID_BUTTON_RIGHT,
8333 CHAR_GRID_BUTTON_UP,
8334 CHAR_GRID_BUTTON_DOWN,
8335 CHAR_GRID_BUTTON_SNAP,
8336 CHAR_GRID_BUTTON_DROP
8345 int font_nr = FONT_INPUT_1_ACTIVE;
8346 int font_height = getFontHeight(font_nr);
8347 int ypos1 = SYSIZE / 2 - font_height * 2;
8348 int ypos2 = SYSIZE / 2 - font_height * 1;
8349 boolean success = FALSE;
8350 boolean finished = FALSE;
8352 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8353 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8354 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8355 boolean set_grid_button = FALSE;
8356 int nr = GRID_ACTIVE_NR();
8359 for (x = 0; x < MAX_GRID_XSIZE; x++)
8360 for (y = 0; y < MAX_GRID_YSIZE; y++)
8361 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8363 overlay.grid_button_highlight = grid_button[step_nr];
8368 FadeOut(REDRAW_FIELD);
8372 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8373 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8374 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8376 FadeIn(REDRAW_FIELD);
8378 SetOverlayShowGrid(TRUE);
8380 // map gadgets for setup touch buttons menu screen
8381 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8387 while (NextValidEvent(&event))
8389 int action = ACTION_NONE;
8391 // ---------- handle events and set the resulting action ----------
8397 UserEvent *user = (UserEvent *)&event;
8398 int id = user->value1;
8400 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8401 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8402 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8403 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8408 case EVENT_KEYPRESS:
8410 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8412 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8413 key == KSYM_BackSpace ||
8414 key == KSYM_Back ? ACTION_BACK :
8415 key == KSYM_Return ||
8417 key == KSYM_space ? ACTION_NEXT :
8422 case EVENT_KEYRELEASE:
8423 key_joystick_mapping = 0;
8426 case EVENT_BUTTONPRESS:
8427 case EVENT_BUTTONRELEASE:
8429 ButtonEvent *button = (ButtonEvent *)&event;
8431 motion_status = FALSE;
8433 if (button->type == EVENT_BUTTONPRESS)
8434 button_status = button->button;
8436 button_status = MB_RELEASED;
8438 if (HandleGadgets(button->x, button->y, button_status))
8440 // do not handle this button event anymore
8444 button->x += video.screen_xoffset;
8445 button->y += video.screen_yoffset;
8447 x = button->x * overlay.grid_xsize / video.screen_width;
8448 y = button->y * overlay.grid_ysize / video.screen_height;
8450 if (button->type == EVENT_BUTTONPRESS)
8453 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8454 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8456 set_grid_button = TRUE;
8459 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8463 case EVENT_MOTIONNOTIFY:
8465 MotionEvent *motion = (MotionEvent *)&event;
8467 motion_status = TRUE;
8469 if (HandleGadgets(motion->x, motion->y, button_status))
8471 // do not handle this button event anymore
8475 motion->x += video.screen_xoffset;
8476 motion->y += video.screen_yoffset;
8478 x = motion->x * overlay.grid_xsize / video.screen_width;
8479 y = motion->y * overlay.grid_ysize / video.screen_height;
8481 set_grid_button = TRUE;
8483 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8487 case SDL_WINDOWEVENT:
8488 HandleWindowEvent((WindowEvent *) &event);
8490 // check if device has been rotated
8491 if (nr != GRID_ACTIVE_NR())
8493 nr = GRID_ACTIVE_NR();
8495 for (x = 0; x < MAX_GRID_XSIZE; x++)
8496 for (y = 0; y < MAX_GRID_YSIZE; y++)
8497 grid_button_old[x][y] = grid_button_tmp[x][y] =
8498 overlay.grid_button[x][y];
8503 case SDL_APP_WILLENTERBACKGROUND:
8504 case SDL_APP_DIDENTERBACKGROUND:
8505 case SDL_APP_WILLENTERFOREGROUND:
8506 case SDL_APP_DIDENTERFOREGROUND:
8507 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8511 HandleOtherEvents(&event);
8515 // ---------- perform action set by handling events ----------
8517 if (action == ACTION_ESCAPE)
8519 // abort and restore the old key bindings
8521 for (x = 0; x < MAX_GRID_XSIZE; x++)
8522 for (y = 0; y < MAX_GRID_YSIZE; y++)
8523 overlay.grid_button[x][y] = grid_button_old[x][y];
8525 FadeSkipNextFadeIn();
8529 else if (action == ACTION_BACK)
8531 // keep the configured key bindings and go to previous page
8537 FadeSkipNextFadeIn();
8542 else if (action == ACTION_NEXT)
8544 // keep the configured key bindings and go to next page
8548 // all virtual buttons configured
8556 if (action != ACTION_NONE && !finished)
8558 for (x = 0; x < MAX_GRID_XSIZE; x++)
8559 for (y = 0; y < MAX_GRID_YSIZE; y++)
8560 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8562 overlay.grid_button_highlight = grid_button[step_nr];
8564 // configure next virtual button
8568 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8569 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8570 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8573 if (set_grid_button)
8575 overlay.grid_button[x][y] =
8576 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8577 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8578 grid_button_tmp[x][y]);
8580 set_grid_button = FALSE;
8587 for (x = 0; x < MAX_GRID_XSIZE; x++)
8588 for (y = 0; y < MAX_GRID_YSIZE; y++)
8589 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8591 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8593 SetOverlayShowGrid(FALSE);
8598 void ConfigureVirtualButtons(void)
8600 boolean success = ConfigureVirtualButtonsMain();
8602 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8603 SCREEN_MASK_TOUCH2);
8607 int font_nr = FONT_TITLE_1;
8608 int font_height = getFontHeight(font_nr);
8609 int ypos1 = SYSIZE / 2 - font_height * 2;
8610 int ypos2 = SYSIZE / 2 - font_height * 1;
8611 unsigned int wait_frame_delay = 0;
8612 unsigned int wait_frame_delay_value = 2000;
8614 ResetDelayCounter(&wait_frame_delay);
8618 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8619 DrawTextSCentered(ypos2, font_nr, "configured!");
8621 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8628 void DrawSetupScreen(void)
8633 if (setup_mode == SETUP_MODE_INPUT)
8634 DrawSetupScreen_Input();
8635 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8636 DrawChooseTree(&game_speed_current);
8637 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8638 DrawChooseTree(&scroll_delay_current);
8639 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8640 DrawChooseTree(&snapshot_mode_current);
8641 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8642 DrawChooseTree(&window_size_current);
8643 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8644 DrawChooseTree(&scaling_type_current);
8645 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8646 DrawChooseTree(&rendering_mode_current);
8647 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8648 DrawChooseTree(&vsync_mode_current);
8649 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8650 DrawChooseTree(&artwork.gfx_current);
8651 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8652 DrawChooseTree(&artwork.snd_current);
8653 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8654 DrawChooseTree(&artwork.mus_current);
8655 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8656 DrawChooseTree(&volume_simple_current);
8657 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8658 DrawChooseTree(&volume_loops_current);
8659 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8660 DrawChooseTree(&volume_music_current);
8661 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8662 DrawChooseTree(&touch_control_current);
8663 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8664 DrawChooseTree(&move_distance_current);
8665 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8666 DrawChooseTree(&drop_distance_current);
8667 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8668 DrawChooseTree(&transparency_current);
8669 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8670 DrawChooseTree(&grid_size_current[0][0]);
8671 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8672 DrawChooseTree(&grid_size_current[0][1]);
8673 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8674 DrawChooseTree(&grid_size_current[1][0]);
8675 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8676 DrawChooseTree(&grid_size_current[1][1]);
8678 DrawSetupScreen_Generic();
8680 PlayMenuSoundsAndMusic();
8683 void RedrawSetupScreenAfterFullscreenToggle(void)
8685 if (setup_mode == SETUP_MODE_GRAPHICS ||
8686 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8688 // update list selection from "setup.window_scaling_percent"
8689 execSetupGraphics_setWindowSizes(TRUE);
8695 void RedrawSetupScreenAfterScreenRotation(int nr)
8699 if (setup_mode == SETUP_MODE_TOUCH)
8701 // update virtual button settings (depending on screen orientation)
8704 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8706 // save already configured virtual buttons
8707 for (x = 0; x < MAX_GRID_XSIZE; x++)
8708 for (y = 0; y < MAX_GRID_YSIZE; y++)
8709 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8713 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8715 if (setup_mode == SETUP_MODE_INPUT)
8716 HandleSetupScreen_Input(mx, my, dx, dy, button);
8717 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8718 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8719 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8720 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8721 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8722 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8723 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8724 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8725 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8726 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8727 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8728 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8729 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8730 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8731 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8732 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8733 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8734 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8735 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8736 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8737 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8738 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8739 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8740 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8741 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8742 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8743 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8744 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8745 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8746 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8747 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8748 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8749 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8750 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8751 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8752 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8753 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8754 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8755 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8756 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8757 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8758 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8760 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8763 void HandleGameActions(void)
8765 if (setup.ask_on_game_over)
8768 if (game.restart_game_message != NULL)
8770 RequestRestartGame(game.restart_game_message);
8775 if (game_status != GAME_MODE_PLAYING)
8778 GameActions(); // main game loop
8780 if (tape.auto_play && !tape.playing)
8781 AutoPlayTapes(); // continue automatically playing next tape
8785 // ---------- new screen button stuff --------------------------------------
8789 int gfx_unpressed, gfx_pressed;
8790 struct MenuPosInfo *pos;
8791 boolean *check_value;
8794 unsigned int event_mask;
8795 boolean is_touch_button;
8797 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8800 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8801 &menu.main.button.prev_level, NULL,
8802 SCREEN_CTRL_ID_PREV_LEVEL,
8804 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8805 FALSE, "previous level"
8808 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8809 &menu.main.button.next_level, NULL,
8810 SCREEN_CTRL_ID_NEXT_LEVEL,
8812 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8816 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
8817 &menu.main.button.first_level, NULL,
8818 SCREEN_CTRL_ID_FIRST_LEVEL,
8821 FALSE, "first level"
8824 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
8825 &menu.main.button.last_level, NULL,
8826 SCREEN_CTRL_ID_LAST_LEVEL,
8832 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
8833 &menu.main.button.level_number, NULL,
8834 SCREEN_CTRL_ID_LEVEL_NUMBER,
8837 FALSE, "level number"
8840 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8841 &menu.setup.button.prev_player, NULL,
8842 SCREEN_CTRL_ID_PREV_PLAYER,
8844 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8845 FALSE, "previous player"
8848 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8849 &menu.setup.button.next_player, NULL,
8850 SCREEN_CTRL_ID_NEXT_PLAYER,
8852 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8853 FALSE, "next player"
8856 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8857 &menu.main.button.insert_solution, NULL,
8858 SCREEN_CTRL_ID_INSERT_SOLUTION,
8859 SCREEN_MASK_MAIN_HAS_SOLUTION,
8861 FALSE, "insert solution tape"
8864 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8865 &menu.main.button.play_solution, NULL,
8866 SCREEN_CTRL_ID_PLAY_SOLUTION,
8867 SCREEN_MASK_MAIN_HAS_SOLUTION,
8869 FALSE, "play solution tape"
8872 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
8873 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
8874 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
8876 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
8877 FALSE, "switch ECS/AGA chipset"
8880 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
8881 &menu.setup.button.touch_back, NULL,
8882 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
8885 TRUE, "previous page"
8888 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
8889 &menu.setup.button.touch_next, NULL,
8890 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
8896 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
8897 &menu.setup.button.touch_back2, NULL,
8898 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
8901 TRUE, "previous page"
8904 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
8905 &menu.setup.button.touch_next2, NULL,
8906 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
8915 int gfx_unpressed, gfx_pressed;
8919 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8922 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8923 -1, -1, // these values are not constant, but can change at runtime
8924 SCREEN_CTRL_ID_SCROLL_UP,
8928 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8929 -1, -1, // these values are not constant, but can change at runtime
8930 SCREEN_CTRL_ID_SCROLL_DOWN,
8937 int gfx_unpressed, gfx_pressed;
8943 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8946 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8947 -1, -1, // these values are not constant, but can change at runtime
8948 -1, -1, // these values are not constant, but can change at runtime
8949 GD_TYPE_SCROLLBAR_VERTICAL,
8950 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8951 "scroll level series vertically"
8963 } textinput_info[NUM_SCREEN_TEXTINPUT] =
8966 IMG_SETUP_INPUT_TEXT,
8967 SCREEN_CTRL_ID_NETWORK_SERVER,
8968 -1, -1, // these values are not constant, but can change at runtime
8969 MAX_SETUP_TEXT_INPUT_LEN,
8970 network_server_hostname,
8971 "Network Server Hostname / IP"
8975 static void CreateScreenMenubuttons(void)
8977 struct GadgetInfo *gi;
8978 unsigned int event_mask;
8981 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8983 struct MenuPosInfo *pos = menubutton_info[i].pos;
8984 boolean is_touch_button = menubutton_info[i].is_touch_button;
8985 boolean is_check_button = menubutton_info[i].check_value != NULL;
8986 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8987 int gfx_unpressed, gfx_pressed;
8988 int x, y, width, height;
8989 int gd_x1, gd_x2, gd_y1, gd_y2;
8990 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
8991 int id = menubutton_info[i].gadget_id;
8992 int type = GD_TYPE_NORMAL_BUTTON;
8993 boolean checked = FALSE;
8995 event_mask = menubutton_info[i].event_mask;
8997 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
8998 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9000 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9001 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9003 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9004 gfx_pressed = menubutton_info[i].gfx_pressed;
9005 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9006 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9007 gd_x1 = graphic_info[gfx_unpressed].src_x;
9008 gd_y1 = graphic_info[gfx_unpressed].src_y;
9009 gd_x2 = graphic_info[gfx_pressed].src_x;
9010 gd_y2 = graphic_info[gfx_pressed].src_y;
9016 if (is_touch_button)
9018 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9019 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9022 if (is_check_button)
9024 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9025 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9026 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9027 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9029 type = GD_TYPE_CHECK_BUTTON;
9030 checked = *menubutton_info[i].check_value;
9033 gi = CreateGadget(GDI_CUSTOM_ID, id,
9034 GDI_CUSTOM_TYPE_ID, i,
9035 GDI_IMAGE_ID, gfx_unpressed,
9036 GDI_INFO_TEXT, menubutton_info[i].infotext,
9042 GDI_STATE, GD_BUTTON_UNPRESSED,
9043 GDI_CHECKED, checked,
9044 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9045 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9046 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
9047 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
9048 GDI_DIRECT_DRAW, FALSE,
9049 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9050 GDI_EVENT_MASK, event_mask,
9051 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9055 Fail("cannot create gadget");
9057 screen_gadget[id] = gi;
9061 static void CreateScreenScrollbuttons(void)
9063 struct GadgetInfo *gi;
9064 unsigned int event_mask;
9067 // these values are not constant, but can change at runtime
9068 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9069 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9070 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9071 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9073 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9075 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9076 int gfx_unpressed, gfx_pressed;
9077 int x, y, width, height;
9078 int gd_x1, gd_x2, gd_y1, gd_y2;
9079 int id = scrollbutton_info[i].gadget_id;
9081 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9083 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9084 y = mSY + scrollbutton_info[i].y;
9085 width = SC_SCROLLBUTTON_XSIZE;
9086 height = SC_SCROLLBUTTON_YSIZE;
9088 // correct scrollbar position if placed outside menu (playfield) area
9089 if (x > SX + SC_SCROLL_UP_XPOS)
9090 x = SX + SC_SCROLL_UP_XPOS;
9092 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9093 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9094 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9096 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9097 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9098 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9099 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9100 gd_x1 = graphic_info[gfx_unpressed].src_x;
9101 gd_y1 = graphic_info[gfx_unpressed].src_y;
9102 gd_x2 = graphic_info[gfx_pressed].src_x;
9103 gd_y2 = graphic_info[gfx_pressed].src_y;
9105 gi = CreateGadget(GDI_CUSTOM_ID, id,
9106 GDI_CUSTOM_TYPE_ID, i,
9107 GDI_IMAGE_ID, gfx_unpressed,
9108 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
9113 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
9114 GDI_STATE, GD_BUTTON_UNPRESSED,
9115 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9116 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9117 GDI_DIRECT_DRAW, FALSE,
9118 GDI_EVENT_MASK, event_mask,
9119 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9123 Fail("cannot create gadget");
9125 screen_gadget[id] = gi;
9129 static void CreateScreenScrollbars(void)
9133 // these values are not constant, but can change at runtime
9134 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
9135 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
9136 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
9137 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
9139 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9141 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9142 int gfx_unpressed, gfx_pressed;
9143 int x, y, width, height;
9144 int gd_x1, gd_x2, gd_y1, gd_y2;
9145 struct GadgetInfo *gi;
9146 int items_max, items_visible, item_position;
9147 unsigned int event_mask;
9148 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
9149 int id = scrollbar_info[i].gadget_id;
9151 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9153 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
9154 y = mSY + scrollbar_info[i].y;
9155 width = scrollbar_info[i].width;
9156 height = scrollbar_info[i].height;
9158 // correct scrollbar position if placed outside menu (playfield) area
9159 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
9160 x = SX + SC_SCROLL_VERTICAL_XPOS;
9162 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
9163 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
9165 items_max = num_page_entries;
9166 items_visible = num_page_entries;
9169 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
9170 gfx_pressed = scrollbar_info[i].gfx_pressed;
9171 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9172 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9173 gd_x1 = graphic_info[gfx_unpressed].src_x;
9174 gd_y1 = graphic_info[gfx_unpressed].src_y;
9175 gd_x2 = graphic_info[gfx_pressed].src_x;
9176 gd_y2 = graphic_info[gfx_pressed].src_y;
9178 gi = CreateGadget(GDI_CUSTOM_ID, id,
9179 GDI_CUSTOM_TYPE_ID, i,
9180 GDI_IMAGE_ID, gfx_unpressed,
9181 GDI_INFO_TEXT, scrollbar_info[i].infotext,
9186 GDI_TYPE, scrollbar_info[i].type,
9187 GDI_SCROLLBAR_ITEMS_MAX, items_max,
9188 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9189 GDI_SCROLLBAR_ITEM_POSITION, item_position,
9190 GDI_WHEEL_AREA_X, SX,
9191 GDI_WHEEL_AREA_Y, SY,
9192 GDI_WHEEL_AREA_WIDTH, SXSIZE,
9193 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
9194 GDI_STATE, GD_BUTTON_UNPRESSED,
9195 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9196 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9197 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
9198 GDI_DIRECT_DRAW, FALSE,
9199 GDI_EVENT_MASK, event_mask,
9200 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9204 Fail("cannot create gadget");
9206 screen_gadget[id] = gi;
9210 static void CreateScreenTextInputGadgets(void)
9214 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
9216 int graphic = textinput_info[i].graphic;
9217 struct GraphicInfo *gd = &graphic_info[graphic];
9218 int gd_x1 = gd->src_x;
9219 int gd_y1 = gd->src_y;
9220 int gd_x2 = gd->src_x + gd->active_xoffset;
9221 int gd_y2 = gd->src_y + gd->active_yoffset;
9222 struct GadgetInfo *gi;
9223 unsigned int event_mask;
9224 int id = textinput_info[i].gadget_id;
9225 int x = textinput_info[i].x;
9226 int y = textinput_info[i].y;
9228 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
9230 gi = CreateGadget(GDI_CUSTOM_ID, id,
9231 GDI_CUSTOM_TYPE_ID, i,
9232 GDI_INFO_TEXT, textinput_info[i].infotext,
9235 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
9236 GDI_TEXT_VALUE, textinput_info[i].value,
9237 GDI_TEXT_SIZE, textinput_info[i].size,
9238 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
9239 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
9240 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9241 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9242 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9243 GDI_DESIGN_WIDTH, gd->width,
9244 GDI_EVENT_MASK, event_mask,
9245 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9246 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
9250 Fail("cannot create gadget");
9252 screen_gadget[id] = gi;
9256 void CreateScreenGadgets(void)
9258 CreateScreenMenubuttons();
9260 CreateScreenScrollbuttons();
9261 CreateScreenScrollbars();
9263 CreateScreenTextInputGadgets();
9266 void FreeScreenGadgets(void)
9270 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
9271 FreeGadget(screen_gadget[i]);
9274 static void MapScreenMenuGadgets(int screen_mask)
9278 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9279 if (screen_mask & menubutton_info[i].screen_mask)
9280 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9283 static void UnmapScreenMenuGadgets(int screen_mask)
9287 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9289 if (screen_mask & menubutton_info[i].screen_mask)
9291 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
9293 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
9294 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
9295 screen_gadget[menubutton_info[i].gadget_id]->y,
9296 screen_gadget[menubutton_info[i].gadget_id]->width,
9297 screen_gadget[menubutton_info[i].gadget_id]->height);
9302 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
9305 MapScreenMenuGadgets(screen_mask);
9307 UnmapScreenMenuGadgets(screen_mask);
9310 static void MapScreenGadgets(int num_entries)
9314 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
9317 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9318 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
9320 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
9321 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
9324 static void MapScreenTreeGadgets(TreeInfo *ti)
9326 MapScreenGadgets(numTreeInfoInGroup(ti));
9329 static void HandleScreenGadgets(struct GadgetInfo *gi)
9331 int id = gi->custom_id;
9332 int button = gi->event.button;
9333 int step = (button == MB_LEFTBUTTON ? 1 :
9334 button == MB_MIDDLEBUTTON ? 5 :
9335 button == MB_RIGHTBUTTON ? 10 : 1);
9339 case SCREEN_CTRL_ID_PREV_LEVEL:
9340 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9343 case SCREEN_CTRL_ID_NEXT_LEVEL:
9344 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9347 case SCREEN_CTRL_ID_FIRST_LEVEL:
9348 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9351 case SCREEN_CTRL_ID_LAST_LEVEL:
9352 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9355 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9356 CloseDoor(DOOR_CLOSE_2);
9357 SetGameStatus(GAME_MODE_LEVELNR);
9358 DrawChooseLevelNr();
9361 case SCREEN_CTRL_ID_PREV_PLAYER:
9362 HandleSetupScreen_Input_Player(step, -1);
9365 case SCREEN_CTRL_ID_NEXT_PLAYER:
9366 HandleSetupScreen_Input_Player(step, +1);
9369 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9370 InsertSolutionTape();
9373 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9377 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9378 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9382 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9383 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9384 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9385 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9386 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9389 case SCREEN_CTRL_ID_SCROLL_UP:
9390 if (game_status == GAME_MODE_NAMES)
9391 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9392 else if (game_status == GAME_MODE_LEVELS)
9393 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9394 else if (game_status == GAME_MODE_LEVELNR)
9395 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9396 else if (game_status == GAME_MODE_SETUP)
9397 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9398 else if (game_status == GAME_MODE_INFO)
9399 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9402 case SCREEN_CTRL_ID_SCROLL_DOWN:
9403 if (game_status == GAME_MODE_NAMES)
9404 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9405 else if (game_status == GAME_MODE_LEVELS)
9406 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9407 else if (game_status == GAME_MODE_LEVELNR)
9408 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9409 else if (game_status == GAME_MODE_SETUP)
9410 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9411 else if (game_status == GAME_MODE_INFO)
9412 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9415 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9416 if (game_status == GAME_MODE_NAMES)
9417 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9418 else if (game_status == GAME_MODE_LEVELS)
9419 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9420 else if (game_status == GAME_MODE_LEVELNR)
9421 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9422 else if (game_status == GAME_MODE_SETUP)
9423 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9424 else if (game_status == GAME_MODE_INFO)
9425 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9428 case SCREEN_CTRL_ID_NETWORK_SERVER:
9430 if (!strEqual(gi->textinput.value, ""))
9432 setString(&setup.network_server_hostname, gi->textinput.value);
9434 network.server_host = setup.network_server_hostname;
9438 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9440 network.server_host = NULL;
9443 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9444 network.server_host = NULL;
9446 execSetupGame_setNetworkServerText();
9458 void DumpScreenIdentifiers(void)
9462 Print("Active screen elements on current screen:\n");
9464 for (i = 0; main_controls[i].nr != -1; i++)
9466 struct MainControlInfo *mci = &main_controls[i];
9468 if (mci->button_graphic != -1)
9470 char *token = getTokenFromImageID(mci->button_graphic);
9472 Print("- '%s'\n", token);
9479 boolean DoScreenAction(int image_id)
9483 if (game_status != GAME_MODE_MAIN)
9486 for (i = 0; main_controls[i].nr != -1; i++)
9488 struct MainControlInfo *mci = &main_controls[i];
9489 struct MenuPosInfo *pos = mci->pos_button;
9491 if (mci->button_graphic == image_id)
9493 int x = mSX + pos->x;
9494 int y = mSY + pos->y;
9496 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9505 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9507 // get tree info node of newly added level or artwork set
9508 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9509 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9511 if (tree_node_new == NULL) // should not happen
9514 // if request dialog is active, do nothing
9515 if (game.request_active)
9518 if (game_status == GAME_MODE_MAIN &&
9519 tree_type == TREE_TYPE_LEVEL_DIR)
9521 // when adding new level set in main menu, select it as current level set
9523 // change current level set to newly added level set from zip file
9524 leveldir_current = tree_node_new;
9526 // change current level number to first level of newly added level set
9527 level_nr = leveldir_current->first_level;
9529 // redraw screen to reflect changed level set
9532 // save this level set and level number as last selected level set
9533 SaveLevelSetup_LastSeries();
9534 SaveLevelSetup_SeriesInfo();
9536 else if (game_status == GAME_MODE_LEVELS &&
9537 tree_type == TREE_TYPE_LEVEL_DIR)
9539 // when adding new level set in level set menu, set cursor and update screen
9541 leveldir_current = tree_node_new;
9543 DrawChooseTree(&leveldir_current);
9545 else if (game_status == GAME_MODE_SETUP)
9547 // when adding new artwork set in setup menu, set cursor and update screen
9549 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9550 tree_type == TREE_TYPE_GRAPHICS_DIR)
9552 artwork.gfx_current = tree_node_new;
9554 DrawChooseTree(&artwork.gfx_current);
9556 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9557 tree_type == TREE_TYPE_SOUNDS_DIR)
9559 artwork.snd_current = tree_node_new;
9561 DrawChooseTree(&artwork.snd_current);
9563 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9564 tree_type == TREE_TYPE_MUSIC_DIR)
9566 artwork.mus_current = tree_node_new;
9568 DrawChooseTree(&artwork.mus_current);