1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://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_EDITOR 2
48 #define SETUP_MODE_GRAPHICS 3
49 #define SETUP_MODE_SOUND 4
50 #define SETUP_MODE_ARTWORK 5
51 #define SETUP_MODE_INPUT 6
52 #define SETUP_MODE_TOUCH 7
53 #define SETUP_MODE_SHORTCUTS 8
54 #define SETUP_MODE_SHORTCUTS_1 9
55 #define SETUP_MODE_SHORTCUTS_2 10
56 #define SETUP_MODE_SHORTCUTS_3 11
57 #define SETUP_MODE_SHORTCUTS_4 12
58 #define SETUP_MODE_SHORTCUTS_5 13
60 /* sub-screens on the setup screen (generic) */
61 #define SETUP_MODE_CHOOSE_ARTWORK 14
62 #define SETUP_MODE_CHOOSE_OTHER 15
64 /* sub-screens on the setup screen (specific) */
65 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
66 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
67 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
68 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
69 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
70 #define SETUP_MODE_CHOOSE_RENDERING 21
71 #define SETUP_MODE_CHOOSE_VSYNC 22
72 #define SETUP_MODE_CHOOSE_GRAPHICS 23
73 #define SETUP_MODE_CHOOSE_SOUNDS 24
74 #define SETUP_MODE_CHOOSE_MUSIC 25
75 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 26
76 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 27
77 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 28
78 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 29
79 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 30
80 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 31
81 #define SETUP_MODE_CHOOSE_TRANSPARENCY 32
82 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 33
83 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 36
86 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 37
88 #define MAX_SETUP_MODES 38
90 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
92 /* setup screen titles */
93 #define STR_SETUP_MAIN "Setup"
94 #define STR_SETUP_GAME "Game & Menu"
95 #define STR_SETUP_EDITOR "Editor"
96 #define STR_SETUP_GRAPHICS "Graphics"
97 #define STR_SETUP_SOUND "Sound & Music"
98 #define STR_SETUP_ARTWORK "Custom Artwork"
99 #define STR_SETUP_INPUT "Input Devices"
100 #define STR_SETUP_TOUCH "Touch Controls"
101 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
102 #define STR_SETUP_EXIT "Exit"
103 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
105 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
106 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
107 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
108 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
109 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
110 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
111 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
112 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
113 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
114 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
115 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
116 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
117 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
118 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
119 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
120 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
121 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
122 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
124 /* for input setup functions */
125 #define SETUPINPUT_SCREEN_POS_START 0
126 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
127 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
128 #define SETUPINPUT_SCREEN_POS_END 13
130 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
131 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
133 #define MAX_SETUP_TEXT_INPUT_LEN 28
135 /* for various menu stuff */
136 #define MENU_SCREEN_START_XPOS 1
137 #define MENU_SCREEN_START_YPOS 2
138 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
139 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
140 #define MENU_TITLE1_YPOS 8
141 #define MENU_TITLE2_YPOS 46
142 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
143 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
144 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
145 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
146 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
147 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
148 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
149 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
150 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
151 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
152 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
153 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
154 MENU_INFO_FONT_TITLE))
155 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
156 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
157 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
158 MENU_SCREEN_INFO_YSTART2 - \
160 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
161 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
162 MENU_SCREEN_INFO_YSTEP)
163 #define NUM_INFO_ELEMENTS_FROM_CONF \
164 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
165 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
166 MAX_MENU_ENTRIES_ON_SCREEN)
167 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
168 MAX_INFO_ELEMENTS_ON_SCREEN), \
169 NUM_INFO_ELEMENTS_FROM_CONF)
170 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
171 #define MAX_MENU_TEXT_LENGTH_BIG 13
172 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
174 /* screen gadget identifiers */
175 #define SCREEN_CTRL_ID_PREV_LEVEL 0
176 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
177 #define SCREEN_CTRL_ID_PREV_PLAYER 2
178 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
179 #define SCREEN_CTRL_ID_INSERT_SOLUTION 4
180 #define SCREEN_CTRL_ID_PLAY_SOLUTION 5
181 #define SCREEN_CTRL_ID_SCROLL_UP 6
182 #define SCREEN_CTRL_ID_SCROLL_DOWN 7
183 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 8
184 #define SCREEN_CTRL_ID_NETWORK_SERVER 9
186 #define NUM_SCREEN_GADGETS 10
188 #define NUM_SCREEN_MENUBUTTONS 6
189 #define NUM_SCREEN_SCROLLBUTTONS 2
190 #define NUM_SCREEN_SCROLLBARS 1
191 #define NUM_SCREEN_TEXTINPUT 1
193 #define SCREEN_MASK_MAIN (1 << 0)
194 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
195 #define SCREEN_MASK_INPUT (1 << 2)
197 /* graphic position and size values for buttons and scrollbars */
198 #define SC_MENUBUTTON_XSIZE TILEX
199 #define SC_MENUBUTTON_YSIZE TILEY
201 #define SC_SCROLLBUTTON_XSIZE TILEX
202 #define SC_SCROLLBUTTON_YSIZE TILEY
204 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
206 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
207 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
208 SC_SCROLLBUTTON_YSIZE)
210 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
211 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
213 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
214 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
215 SC_SCROLLBUTTON_YSIZE)
217 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
218 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
219 SC_SCROLL_VERTICAL_YSIZE)
221 #define SC_BORDER_SIZE 14
224 /* forward declarations of internal functions */
225 static void HandleScreenGadgets(struct GadgetInfo *);
226 static void HandleSetupScreen_Generic(int, int, int, int, int);
227 static void HandleSetupScreen_Input(int, int, int, int, int);
228 static void CustomizeKeyboard(int);
229 static void ConfigureJoystick(int);
230 static void ConfigureVirtualButtons(void);
231 static void execSetupGame(void);
232 static void execSetupGraphics(void);
233 static void execSetupSound(void);
234 static void execSetupTouch(void);
235 static void execSetupArtwork(void);
236 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
238 static void DrawChooseLevelSet(void);
239 static void DrawChooseLevelNr(void);
240 static void DrawInfoScreen(void);
241 static void DrawSetupScreen(void);
243 static void DrawInfoScreen_NotAvailable(char *, char *);
244 static void DrawInfoScreen_HelpAnim(int, int, boolean);
245 static void DrawInfoScreen_HelpText(int, int, int, int);
246 static void HandleInfoScreen_Main(int, int, int, int, int);
247 static void HandleInfoScreen_TitleScreen(int);
248 static void HandleInfoScreen_Elements(int);
249 static void HandleInfoScreen_Music(int);
250 static void HandleInfoScreen_Credits(int);
251 static void HandleInfoScreen_Program(int);
252 static void HandleInfoScreen_Version(int);
254 static void MapScreenMenuGadgets(int);
255 static void MapScreenGadgets(int);
256 static void MapScreenTreeGadgets(TreeInfo *);
258 static void UpdateScreenMenuGadgets(int, boolean);
260 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
262 static int info_mode = INFO_MODE_MAIN;
263 static int setup_mode = SETUP_MODE_MAIN;
265 static TreeInfo *window_sizes = NULL;
266 static TreeInfo *window_size_current = NULL;
268 static TreeInfo *scaling_types = NULL;
269 static TreeInfo *scaling_type_current = NULL;
271 static TreeInfo *rendering_modes = NULL;
272 static TreeInfo *rendering_mode_current = NULL;
274 static TreeInfo *vsync_modes = NULL;
275 static TreeInfo *vsync_mode_current = NULL;
277 static TreeInfo *scroll_delays = NULL;
278 static TreeInfo *scroll_delay_current = NULL;
280 static TreeInfo *snapshot_modes = NULL;
281 static TreeInfo *snapshot_mode_current = NULL;
283 static TreeInfo *game_speeds = NULL;
284 static TreeInfo *game_speed_current = NULL;
286 static TreeInfo *volumes_simple = NULL;
287 static TreeInfo *volume_simple_current = NULL;
289 static TreeInfo *volumes_loops = NULL;
290 static TreeInfo *volume_loops_current = NULL;
292 static TreeInfo *volumes_music = NULL;
293 static TreeInfo *volume_music_current = NULL;
295 static TreeInfo *touch_controls = NULL;
296 static TreeInfo *touch_control_current = NULL;
298 static TreeInfo *move_distances = NULL;
299 static TreeInfo *move_distance_current = NULL;
301 static TreeInfo *drop_distances = NULL;
302 static TreeInfo *drop_distance_current = NULL;
304 static TreeInfo *transparencies = NULL;
305 static TreeInfo *transparency_current = NULL;
307 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
308 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
310 static TreeInfo *level_number = NULL;
311 static TreeInfo *level_number_current = NULL;
317 } window_sizes_list[] =
322 { 100, "100 % (Default)" },
339 } scaling_types_list[] =
341 { SCALING_QUALITY_NEAREST, "Off" },
342 { SCALING_QUALITY_LINEAR, "Linear" },
343 { SCALING_QUALITY_BEST, "Anisotropic" },
352 } rendering_modes_list[] =
354 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
355 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
357 // this mode may work under certain conditions, but does not work on Windows
358 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
360 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
369 } vsync_modes_list[] =
371 { STR_VSYNC_MODE_OFF, "Off" },
372 { STR_VSYNC_MODE_NORMAL, "Normal" },
373 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
382 } game_speeds_list[] =
391 { 1000, "1/1s (Extremely Slow)" },
396 { 29, "1/35s (Original Supaplex)" },
398 { 20, "1/50s (Normal Speed)" },
399 { 14, "1/70s (Maximum Supaplex)" },
403 { 1, "1/1000s (Extremely Fast)" },
413 } scroll_delays_list[] =
415 { 0, "0 Tiles (No Scroll Delay)" },
418 { 3, "3 Tiles (Default)" },
423 { 8, "8 Tiles (Maximum Scroll Delay)"},
432 } snapshot_modes_list[] =
434 { STR_SNAPSHOT_MODE_OFF, "Off" },
435 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
436 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
437 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
470 } touch_controls_list[] =
472 { TOUCH_CONTROL_OFF, "Off" },
473 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
474 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
475 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
503 } transparencies_list[] =
505 { 0, "0 % (Opaque)" },
515 { 100, "100 % (Invisible)" },
524 } grid_sizes_list[] =
560 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
561 (s) <= GAME_MODE_SETUP ? (s) : \
562 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
563 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
565 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
566 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
567 (i) <= INFO_MODE_LEVELSET ? (i) : \
570 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
571 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
572 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
573 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
574 SETUP_MODE_CHOOSE_ARTWORK : \
575 SETUP_MODE_CHOOSE_OTHER)
577 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
578 menu.draw_xoffset[GAME_MODE_INFO] : \
579 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
580 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
581 menu.draw_yoffset[GAME_MODE_INFO] : \
582 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
583 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
584 menu.extra_spacing[GAME_MODE_INFO] : \
585 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
587 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
588 menu.draw_xoffset[GAME_MODE_SETUP] : \
589 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
590 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
591 menu.draw_yoffset[GAME_MODE_SETUP] : \
592 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
593 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
594 menu.extra_spacing[GAME_MODE_SETUP] : \
595 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
597 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
598 DRAW_XOFFSET_INFO(info_mode) : \
599 (s) == GAME_MODE_SETUP ? \
600 DRAW_XOFFSET_SETUP(setup_mode) : \
601 menu.draw_xoffset[DRAW_MODE(s)])
602 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
603 DRAW_YOFFSET_INFO(info_mode) : \
604 (s) == GAME_MODE_SETUP ? \
605 DRAW_YOFFSET_SETUP(setup_mode) : \
606 menu.draw_yoffset[DRAW_MODE(s)])
607 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
608 EXTRA_SPACING_INFO(info_mode) : \
609 (s) == GAME_MODE_SETUP ? \
610 EXTRA_SPACING_SETUP(setup_mode) : \
611 menu.extra_spacing[DRAW_MODE(s)])
613 #define mSX (SX + DRAW_XOFFSET(game_status))
614 #define mSY (SY + DRAW_YOFFSET(game_status))
616 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
617 menu.list_size[game_status] : \
618 MAX_MENU_ENTRIES_ON_SCREEN)
620 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
621 NUM_MENU_ENTRIES_ON_SCREEN)
624 /* title display and control definitions */
626 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
627 2 * MAX_NUM_TITLE_MESSAGES)
629 #define NO_DIRECT_LEVEL_SELECT (-1)
632 static int num_title_screens = 0;
634 struct TitleControlInfo
643 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
645 /* main menu display and control definitions */
647 #define MAIN_CONTROL_NAME 0
648 #define MAIN_CONTROL_LEVELS 1
649 #define MAIN_CONTROL_SCORES 2
650 #define MAIN_CONTROL_EDITOR 3
651 #define MAIN_CONTROL_INFO 4
652 #define MAIN_CONTROL_GAME 5
653 #define MAIN_CONTROL_SETUP 6
654 #define MAIN_CONTROL_QUIT 7
655 #define MAIN_CONTROL_PREV_LEVEL 8
656 #define MAIN_CONTROL_NEXT_LEVEL 9
657 #define MAIN_CONTROL_FIRST_LEVEL 10
658 #define MAIN_CONTROL_LAST_LEVEL 11
659 #define MAIN_CONTROL_LEVEL_NUMBER 12
660 #define MAIN_CONTROL_LEVEL_INFO_1 13
661 #define MAIN_CONTROL_LEVEL_INFO_2 14
662 #define MAIN_CONTROL_LEVEL_NAME 15
663 #define MAIN_CONTROL_LEVEL_AUTHOR 16
664 #define MAIN_CONTROL_LEVEL_YEAR 17
665 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
666 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
667 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
668 #define MAIN_CONTROL_TITLE_1 21
669 #define MAIN_CONTROL_TITLE_2 22
670 #define MAIN_CONTROL_TITLE_3 23
672 static char str_main_text_name[10];
673 static char str_main_text_first_level[10];
674 static char str_main_text_last_level[10];
675 static char str_main_text_level_number[10];
677 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
679 static char *main_text_name = str_main_text_name;
680 static char *main_text_first_level = str_main_text_first_level;
681 static char *main_text_last_level = str_main_text_last_level;
682 static char *main_text_level_number = str_main_text_level_number;
683 static char *main_text_levels = "Levelset";
684 static char *main_text_scores = "Hall Of Fame";
685 static char *main_text_editor = "Level Creator";
686 static char *main_text_info = "Info Screen";
687 static char *main_text_game = "Start Game";
688 static char *main_text_setup = "Setup";
689 static char *main_text_quit = "Quit";
690 static char *main_text_level_name = level.name;
691 static char *main_text_level_author = level.author;
692 static char *main_text_level_year = NULL;
693 static char *main_text_level_imported_from = NULL;
694 static char *main_text_level_imported_by = NULL;
695 static char *main_text_level_tested_by = NULL;
696 static char *main_text_title_1 = NULL;
697 static char *main_text_title_2 = NULL;
698 static char *main_text_title_3 = NULL;
700 struct MainControlInfo
704 struct MenuPosInfo *pos_button;
707 struct TextPosInfo *pos_text;
710 struct TextPosInfo *pos_input;
714 static struct MainControlInfo main_controls[] =
718 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
719 &menu.main.text.name, &main_text_name,
720 &menu.main.input.name, &setup.player_name,
724 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
725 &menu.main.text.levels, &main_text_levels,
730 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
731 &menu.main.text.scores, &main_text_scores,
736 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
737 &menu.main.text.editor, &main_text_editor,
742 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
743 &menu.main.text.info, &main_text_info,
748 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
749 &menu.main.text.game, &main_text_game,
754 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
755 &menu.main.text.setup, &main_text_setup,
760 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
761 &menu.main.text.quit, &main_text_quit,
765 /* (these two buttons are real gadgets) */
767 MAIN_CONTROL_PREV_LEVEL,
768 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
773 MAIN_CONTROL_NEXT_LEVEL,
774 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
780 MAIN_CONTROL_FIRST_LEVEL,
781 &menu.main.button.first_level, IMG_MENU_BUTTON_FIRST_LEVEL,
782 &menu.main.text.first_level, &main_text_first_level,
786 MAIN_CONTROL_LAST_LEVEL,
787 &menu.main.button.last_level, IMG_MENU_BUTTON_LAST_LEVEL,
788 &menu.main.text.last_level, &main_text_last_level,
792 MAIN_CONTROL_LEVEL_NUMBER,
793 &menu.main.button.level_number, IMG_MENU_BUTTON_LEVEL_NUMBER,
794 &menu.main.text.level_number, &main_text_level_number,
798 MAIN_CONTROL_LEVEL_INFO_1,
800 &menu.main.text.level_info_1, NULL,
804 MAIN_CONTROL_LEVEL_INFO_2,
806 &menu.main.text.level_info_2, NULL,
810 MAIN_CONTROL_LEVEL_NAME,
812 &menu.main.text.level_name, &main_text_level_name,
816 MAIN_CONTROL_LEVEL_AUTHOR,
818 &menu.main.text.level_author, &main_text_level_author,
822 MAIN_CONTROL_LEVEL_YEAR,
824 &menu.main.text.level_year, &main_text_level_year,
828 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
830 &menu.main.text.level_imported_from, &main_text_level_imported_from,
834 MAIN_CONTROL_LEVEL_IMPORTED_BY,
836 &menu.main.text.level_imported_by, &main_text_level_imported_by,
840 MAIN_CONTROL_LEVEL_TESTED_BY,
842 &menu.main.text.level_tested_by, &main_text_level_tested_by,
846 MAIN_CONTROL_TITLE_1,
848 &menu.main.text.title_1, &main_text_title_1,
852 MAIN_CONTROL_TITLE_2,
854 &menu.main.text.title_2, &main_text_title_2,
858 MAIN_CONTROL_TITLE_3,
860 &menu.main.text.title_3, &main_text_title_3,
873 static int getTitleScreenGraphic(int nr, boolean initial)
875 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
878 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
880 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
884 static int getTitleScreenGameMode(boolean initial)
886 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
890 static int getTitleMessageGameMode(boolean initial)
892 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
895 static int getTitleAnimMode(struct TitleControlInfo *tci)
897 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
899 return base + tci->local_nr;
903 static int getTitleScreenBackground(boolean initial)
905 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
910 static int getTitleMessageBackground(int nr, boolean initial)
912 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
916 static int getTitleBackground(int nr, boolean initial, boolean is_image)
918 int base = (is_image ?
919 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
920 IMG_BACKGROUND_TITLESCREEN_1) :
921 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
922 IMG_BACKGROUND_TITLEMESSAGE_1));
923 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
924 IMG_BACKGROUND_TITLE);
925 int graphic_local = base + nr;
927 if (graphic_info[graphic_local].bitmap != NULL)
928 return graphic_local;
930 if (graphic_info[graphic_global].bitmap != NULL)
931 return graphic_global;
933 return IMG_UNDEFINED;
936 static int getTitleSound(struct TitleControlInfo *tci)
938 boolean is_image = tci->is_image;
939 int initial = tci->initial;
940 int nr = tci->local_nr;
941 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
942 int base = (is_image ?
943 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
944 SND_BACKGROUND_TITLESCREEN_1) :
945 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
946 SND_BACKGROUND_TITLEMESSAGE_1));
947 int sound_global = menu.sound[mode];
948 int sound_local = base + nr;
951 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
952 nr, initial, is_image,
953 sound_global, getSoundListEntry(sound_global)->filename,
954 sound_local, getSoundListEntry(sound_local)->filename);
957 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
960 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
963 return SND_UNDEFINED;
966 static int getTitleMusic(struct TitleControlInfo *tci)
968 boolean is_image = tci->is_image;
969 int initial = tci->initial;
970 int nr = tci->local_nr;
971 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
972 int base = (is_image ?
973 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
974 MUS_BACKGROUND_TITLESCREEN_1) :
975 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
976 MUS_BACKGROUND_TITLEMESSAGE_1));
977 int music_global = menu.music[mode];
978 int music_local = base + nr;
981 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
982 nr, initial, is_image,
983 music_global, getMusicListEntry(music_global)->filename,
984 music_local, getMusicListEntry(music_local)->filename);
987 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
990 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
993 return MUS_UNDEFINED;
996 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
998 boolean is_image = tci->is_image;
999 boolean initial = tci->initial;
1000 boolean first = tci->first;
1001 int nr = tci->local_nr;
1002 struct TitleMessageInfo tmi;
1003 struct TitleFadingInfo ti;
1005 tmi = (is_image ? (initial ? (first ?
1006 titlescreen_initial_first[nr] :
1007 titlescreen_initial[nr])
1009 titlescreen_first[nr] :
1011 : (initial ? (first ?
1012 titlemessage_initial_first[nr] :
1013 titlemessage_initial[nr])
1015 titlemessage_first[nr] :
1016 titlemessage[nr])));
1018 ti.fade_mode = tmi.fade_mode;
1019 ti.fade_delay = tmi.fade_delay;
1020 ti.post_delay = tmi.post_delay;
1021 ti.auto_delay = tmi.auto_delay;
1026 static int compareTitleControlInfo(const void *object1, const void *object2)
1028 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1029 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1032 if (tci1->initial != tci2->initial)
1033 compare_result = (tci1->initial ? -1 : +1);
1034 else if (tci1->sort_priority != tci2->sort_priority)
1035 compare_result = tci1->sort_priority - tci2->sort_priority;
1036 else if (tci1->is_image != tci2->is_image)
1037 compare_result = (tci1->is_image ? -1 : +1);
1039 compare_result = tci1->local_nr - tci2->local_nr;
1041 return compare_result;
1044 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1046 int nr, int sort_priority)
1048 title_controls[num_title_screens].is_image = is_image;
1049 title_controls[num_title_screens].initial = initial;
1050 title_controls[num_title_screens].local_nr = nr;
1051 title_controls[num_title_screens].sort_priority = sort_priority;
1053 title_controls[num_title_screens].first = FALSE; /* will be set later */
1055 num_title_screens++;
1058 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1062 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1064 int graphic = getTitleScreenGraphic(i, initial);
1065 Bitmap *bitmap = graphic_info[graphic].bitmap;
1066 int sort_priority = graphic_info[graphic].sort_priority;
1069 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1072 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1074 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1075 char *filename = getLevelSetTitleMessageFilename(i, initial);
1076 int sort_priority = tmi->sort_priority;
1078 if (filename != NULL)
1079 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1083 static void InitializeTitleControls(boolean show_title_initial)
1085 num_title_screens = 0;
1087 /* 1st step: initialize title screens for game start (only when starting) */
1088 if (show_title_initial)
1089 InitializeTitleControls_CheckTitleInfo(TRUE);
1091 /* 2nd step: initialize title screens for current level set */
1092 InitializeTitleControls_CheckTitleInfo(FALSE);
1094 /* sort title screens according to sort_priority and title number */
1095 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1096 compareTitleControlInfo);
1098 /* mark first title screen */
1099 title_controls[0].first = TRUE;
1102 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1104 return (pos != NULL && pos->x != -1 && pos->y != -1);
1107 static boolean visibleTextPos(struct TextPosInfo *pos)
1109 return (pos != NULL && pos->x != -1 && pos->y != -1);
1112 static void InitializeMainControls(void)
1114 boolean local_team_mode = (!network.enabled && setup.team_mode);
1117 /* set main control text values to dynamically determined values */
1118 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1120 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1121 menu.main.text.first_level.size));
1122 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1123 menu.main.text.last_level.size));
1124 strcpy(main_text_level_number, int2str(level_nr,
1125 menu.main.text.level_number.size));
1127 main_text_level_year = leveldir_current->year;
1128 main_text_level_imported_from = leveldir_current->imported_from;
1129 main_text_level_imported_by = leveldir_current->imported_by;
1130 main_text_level_tested_by = leveldir_current->tested_by;
1132 main_text_title_1 = getConfigProgramTitleString();
1133 main_text_title_2 = getConfigProgramCopyrightString();
1134 main_text_title_3 = getConfigProgramCompanyString();
1136 /* set main control screen positions to dynamically determined values */
1137 for (i = 0; main_controls[i].nr != -1; i++)
1139 struct MainControlInfo *mci = &main_controls[i];
1141 struct MenuPosInfo *pos_button = mci->pos_button;
1142 struct TextPosInfo *pos_text = mci->pos_text;
1143 struct TextPosInfo *pos_input = mci->pos_input;
1144 char *text = (mci->text ? *mci->text : NULL);
1145 char *input = (mci->input ? *mci->input : NULL);
1146 int button_graphic = mci->button_graphic;
1147 int font_text = (pos_text ? pos_text->font : -1);
1148 int font_input = (pos_input ? pos_input->font : -1);
1150 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1151 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1152 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1153 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1154 int text_chars = (text != NULL ? strlen(text) : 0);
1155 int input_chars = (input != NULL ? strlen(input) : 0);
1158 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1160 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1161 int text_width = font_text_width * text_chars;
1162 int text_height = font_text_height;
1163 int input_width = font_input_width * input_chars;
1164 int input_height = font_input_height;
1166 if (nr == MAIN_CONTROL_NAME)
1168 menu.main.input.name.width = input_width;
1169 menu.main.input.name.height = input_height;
1172 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1174 pos_button->width = button_width;
1175 pos_button->height = button_height;
1178 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1180 /* calculate text size -- needed for text alignment */
1181 boolean calculate_text_size = (text != NULL);
1183 if (pos_text->width == -1 || calculate_text_size)
1184 pos_text->width = text_width;
1185 if (pos_text->height == -1 || calculate_text_size)
1186 pos_text->height = text_height;
1188 if (visibleMenuPos(pos_button))
1190 if (pos_text->x == -1)
1191 pos_text->x = pos_button->x + pos_button->width;
1192 if (pos_text->y == -1)
1194 pos_button->y + (pos_button->height - pos_text->height) / 2;
1198 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1200 if (visibleTextPos(pos_text))
1202 if (pos_input->x == -1)
1203 pos_input->x = pos_text->x + pos_text->width;
1204 if (pos_input->y == -1)
1205 pos_input->y = pos_text->y;
1208 if (pos_input->width == -1)
1209 pos_input->width = input_width;
1210 if (pos_input->height == -1)
1211 pos_input->height = input_height;
1216 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1217 int graphic, boolean pressed)
1219 struct GraphicInfo *g = &graphic_info[graphic];
1222 int xoffset = (pressed ? g->pressed_xoffset : 0);
1223 int yoffset = (pressed ? g->pressed_yoffset : 0);
1225 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1227 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1228 g->width, g->height, dst_x, dst_y);
1231 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1232 boolean active_input,
1233 boolean pressed_button)
1237 for (i = 0; main_controls[i].nr != -1; i++)
1239 struct MainControlInfo *mci = &main_controls[i];
1241 if (mci->nr == nr || nr == -1)
1243 struct MenuPosInfo *pos_button = mci->pos_button;
1244 struct TextPosInfo *pos_text = mci->pos_text;
1245 struct TextPosInfo *pos_input = mci->pos_input;
1246 char *text = (mci->text ? *mci->text : NULL);
1247 char *input = (mci->input ? *mci->input : NULL);
1248 int button_graphic = mci->button_graphic;
1249 int font_text = (pos_text ? pos_text->font : -1);
1250 int font_input = (pos_input ? pos_input->font : -1);
1254 button_graphic = BUTTON_ACTIVE(button_graphic);
1255 font_text = FONT_ACTIVE(font_text);
1260 font_input = FONT_ACTIVE(font_input);
1263 if (visibleMenuPos(pos_button))
1265 struct MenuPosInfo *pos = pos_button;
1266 int x = mSX + pos->x;
1267 int y = mSY + pos->y;
1269 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1270 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1273 if (visibleTextPos(pos_text) && text != NULL)
1275 struct TextPosInfo *pos = pos_text;
1276 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1277 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1280 /* (check why/if this is needed) */
1281 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1283 DrawText(x, y, text, font_text);
1286 if (visibleTextPos(pos_input) && input != NULL)
1288 struct TextPosInfo *pos = pos_input;
1289 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1290 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1293 /* (check why/if this is needed) */
1294 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1296 DrawText(x, y, input, font_input);
1302 static void DrawCursorAndText_Main(int nr, boolean active_text,
1303 boolean pressed_button)
1305 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1309 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1310 boolean pressed_button)
1312 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1316 static struct MainControlInfo *getMainControlInfo(int nr)
1320 for (i = 0; main_controls[i].nr != -1; i++)
1321 if (main_controls[i].nr == nr)
1322 return &main_controls[i];
1327 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1332 int rect_x = ALIGNED_TEXT_XPOS(rect);
1333 int rect_y = ALIGNED_TEXT_YPOS(rect);
1335 return (x >= rect_x && x < rect_x + rect->width &&
1336 y >= rect_y && y < rect_y + rect->height);
1339 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1344 int rect_x = ALIGNED_TEXT_XPOS(rect);
1345 int rect_y = ALIGNED_TEXT_YPOS(rect);
1348 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1349 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1350 (x >= rect_x && x < rect_x + rect->width &&
1351 y >= rect_y && y < rect_y + rect->height));
1354 return (x >= rect_x && x < rect_x + rect->width &&
1355 y >= rect_y && y < rect_y + rect->height);
1358 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1360 int rect_width = preview->xsize * preview->tile_size;
1361 int rect_height = preview->ysize * preview->tile_size;
1362 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1363 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1365 return (x >= rect_x && x < rect_x + rect_width &&
1366 y >= rect_y && y < rect_y + rect_height);
1369 static void AdjustScrollbar(int id, int items_max, int items_visible,
1372 struct GadgetInfo *gi = screen_gadget[id];
1374 if (item_position > items_max - items_visible)
1375 item_position = items_max - items_visible;
1377 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1378 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1379 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1382 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1384 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1388 static void clearMenuListArea(void)
1390 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1392 /* correct scrollbar position if placed outside menu (playfield) area */
1393 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1394 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1396 /* clear menu list area, but not title or scrollbar */
1397 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1398 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1401 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1403 static int cursor_array[MAX_LEV_FIELDY];
1404 int x = mSX + TILEX * xpos;
1405 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1410 cursor_array[ypos] = graphic;
1412 graphic = cursor_array[ypos];
1416 graphic = BUTTON_ACTIVE(graphic);
1418 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1419 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1422 static void initCursor(int ypos, int graphic)
1424 drawCursorExt(0, ypos, FALSE, graphic);
1427 static void drawCursor(int ypos, boolean active)
1429 drawCursorExt(0, ypos, active, -1);
1432 static void drawCursorXY(int xpos, int ypos, int graphic)
1434 drawCursorExt(xpos, ypos, FALSE, graphic);
1437 static void drawChooseTreeCursor(int ypos, boolean active)
1439 drawCursorExt(0, ypos, active, -1);
1442 static void DrawHeadline(void)
1444 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1445 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1448 static void DrawTitleScreenImage(int nr, boolean initial)
1450 int graphic = getTitleScreenGraphic(nr, initial);
1451 Bitmap *bitmap = graphic_info[graphic].bitmap;
1452 int width = graphic_info[graphic].width;
1453 int height = graphic_info[graphic].height;
1454 int src_x = graphic_info[graphic].src_x;
1455 int src_y = graphic_info[graphic].src_y;
1461 if (width > WIN_XSIZE)
1463 /* image width too large for window => center image horizontally */
1464 src_x = (width - WIN_XSIZE) / 2;
1468 if (height > WIN_YSIZE)
1470 /* image height too large for window => center image vertically */
1471 src_y = (height - WIN_YSIZE) / 2;
1475 /* always display title screens centered */
1476 dst_x = (WIN_XSIZE - width) / 2;
1477 dst_y = (WIN_YSIZE - height) / 2;
1479 SetDrawBackgroundMask(REDRAW_ALL);
1480 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1482 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1484 if (DrawingOnBackground(dst_x, dst_y))
1485 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1487 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1489 redraw_mask = REDRAW_ALL;
1492 static void DrawTitleScreenMessage(int nr, boolean initial)
1494 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1495 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1497 if (filename == NULL)
1500 /* force TITLE font on title message screen */
1501 SetFontStatus(getTitleMessageGameMode(initial));
1503 /* if chars *and* width set to "-1", automatically determine width */
1504 if (tmi->chars == -1 && tmi->width == -1)
1505 tmi->width = viewport.window[game_status].width;
1507 /* if lines *and* height set to "-1", automatically determine height */
1508 if (tmi->lines == -1 && tmi->height == -1)
1509 tmi->height = viewport.window[game_status].height;
1511 /* if chars set to "-1", automatically determine by text and font width */
1512 if (tmi->chars == -1)
1513 tmi->chars = tmi->width / getFontWidth(tmi->font);
1515 tmi->width = tmi->chars * getFontWidth(tmi->font);
1517 /* if lines set to "-1", automatically determine by text and font height */
1518 if (tmi->lines == -1)
1519 tmi->lines = tmi->height / getFontHeight(tmi->font);
1521 tmi->height = tmi->lines * getFontHeight(tmi->font);
1523 /* if x set to "-1", automatically determine by width and alignment */
1525 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1527 /* if y set to "-1", automatically determine by height and alignment */
1529 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1531 SetDrawBackgroundMask(REDRAW_ALL);
1532 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1534 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1536 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1537 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1538 tmi->autowrap, tmi->centered, tmi->parse_comments);
1543 static void DrawTitleScreen(void)
1545 KeyboardAutoRepeatOff();
1547 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1550 static boolean CheckTitleScreen(boolean levelset_has_changed)
1552 static boolean show_title_initial = TRUE;
1553 boolean show_titlescreen = FALSE;
1555 /* needed to be able to skip title screen, if no image or message defined */
1556 InitializeTitleControls(show_title_initial);
1558 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1559 show_titlescreen = TRUE;
1561 /* show initial title images and messages only once at program start */
1562 show_title_initial = FALSE;
1564 return (show_titlescreen && num_title_screens > 0);
1567 void DrawMainMenu(void)
1569 static LevelDirTree *leveldir_last_valid = NULL;
1570 boolean levelset_has_changed = FALSE;
1571 int fade_mask = REDRAW_FIELD;
1573 LimitScreenUpdates(FALSE);
1575 FadeSetLeaveScreen();
1577 /* do not fade out here -- function may continue and fade on editor screen */
1580 FadeMenuSoundsAndMusic();
1582 ExpireSoundLoops(FALSE);
1584 KeyboardAutoRepeatOn();
1586 audio.sound_deactivated = FALSE;
1590 /* needed if last screen was the playing screen, invoked from level editor */
1591 if (level_editor_test_game)
1593 CloseDoor(DOOR_CLOSE_ALL);
1595 SetGameStatus(GAME_MODE_EDITOR);
1602 /* needed if last screen was the setup screen and fullscreen state changed */
1603 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1604 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1606 /* leveldir_current may be invalid (level group, parent link) */
1607 if (!validLevelSeries(leveldir_current))
1608 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1610 if (leveldir_current != leveldir_last_valid)
1611 levelset_has_changed = TRUE;
1613 /* store valid level series information */
1614 leveldir_last_valid = leveldir_current;
1616 init_last = init; /* switch to new busy animation */
1618 /* needed if last screen (level choice) changed graphics, sounds or music */
1619 ReloadCustomArtwork(0);
1621 if (CheckTitleScreen(levelset_has_changed))
1623 SetGameStatus(GAME_MODE_TITLE);
1630 if (redraw_mask & REDRAW_ALL)
1631 fade_mask = REDRAW_ALL;
1633 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
1634 fade_mask = REDRAW_ALL;
1638 /* needed if different viewport properties defined for menues */
1639 ChangeViewportPropertiesIfNeeded();
1641 SetDrawtoField(DRAW_TO_BACKBUFFER);
1643 /* level_nr may have been set to value over handicap with level editor */
1644 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1645 level_nr = leveldir_current->handicap_level;
1647 LoadLevel(level_nr);
1648 LoadScore(level_nr);
1650 SaveLevelSetup_SeriesInfo();
1652 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1653 SetDrawDeactivationMask(REDRAW_NONE);
1654 SetDrawBackgroundMask(REDRAW_FIELD);
1656 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1659 if (fade_mask == REDRAW_ALL)
1660 RedrawGlobalBorder();
1665 InitializeMainControls();
1667 DrawCursorAndText_Main(-1, FALSE, FALSE);
1668 DrawPreviewLevelInitial();
1669 DrawNetworkPlayers();
1671 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1674 if (TAPE_IS_EMPTY(tape))
1676 DrawCompleteVideoDisplay();
1678 PlayMenuSoundsAndMusic();
1680 /* create gadgets for main menu screen */
1681 FreeScreenGadgets();
1682 CreateScreenGadgets();
1684 /* may be required if audio buttons shown on tape and changed in setup menu */
1686 CreateGameButtons();
1688 /* map gadgets for main menu screen */
1690 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1691 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1693 /* copy actual game door content to door double buffer for OpenDoor() */
1694 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1695 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1697 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1699 DrawMaskedBorder(fade_mask);
1704 /* update screen area with special editor door */
1705 redraw_mask |= REDRAW_ALL;
1708 SetMouseCursor(CURSOR_DEFAULT);
1710 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1713 static void gotoTopLevelDir(void)
1715 /* move upwards until inside (but not above) top level directory */
1716 while (leveldir_current->node_parent &&
1717 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1719 /* write a "path" into level tree for easy navigation to last level */
1720 if (leveldir_current->node_parent->node_group->cl_first == -1)
1722 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1723 int leveldir_pos = posTreeInfo(leveldir_current);
1724 int num_page_entries;
1725 int cl_first, cl_cursor;
1727 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1728 num_page_entries = num_leveldirs;
1730 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1732 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1733 cl_cursor = leveldir_pos - cl_first;
1735 leveldir_current->node_parent->node_group->cl_first = cl_first;
1736 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1739 leveldir_current = leveldir_current->node_parent;
1743 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1745 static unsigned int title_delay = 0;
1746 static int title_screen_nr = 0;
1747 static int last_sound = -1, last_music = -1;
1748 boolean return_to_main_menu = FALSE;
1749 struct TitleControlInfo *tci;
1752 if (button == MB_MENU_INITIALIZE)
1755 title_screen_nr = 0;
1756 tci = &title_controls[title_screen_nr];
1758 SetAnimStatus(getTitleAnimMode(tci));
1760 last_sound = SND_UNDEFINED;
1761 last_music = MUS_UNDEFINED;
1763 if (num_title_screens != 0)
1765 FadeSetEnterScreen();
1767 /* use individual title fading instead of global "enter screen" fading */
1768 fading = getTitleFading(tci);
1771 if (game_status_last_screen == GAME_MODE_INFO)
1773 if (num_title_screens == 0)
1775 /* switch game mode from title screen mode back to info screen mode */
1776 SetGameStatus(GAME_MODE_INFO);
1778 /* store that last screen was info screen, not main menu screen */
1779 game_status_last_screen = GAME_MODE_INFO;
1781 DrawInfoScreen_NotAvailable("Title screen information:",
1782 "No title screen for this level set.");
1786 FadeMenuSoundsAndMusic();
1789 FadeOut(REDRAW_ALL);
1791 /* title screens may have different window size */
1792 ChangeViewportPropertiesIfNeeded();
1794 /* only required to update logic for redrawing global border */
1798 DrawTitleScreenImage(tci->local_nr, tci->initial);
1800 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1802 sound = getTitleSound(tci);
1803 music = getTitleMusic(tci);
1805 if (sound != last_sound)
1806 PlayMenuSoundExt(sound);
1807 if (music != last_music)
1808 PlayMenuMusicExt(music);
1813 SetMouseCursor(CURSOR_NONE);
1817 DelayReached(&title_delay, 0); /* reset delay counter */
1822 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1823 button = MB_MENU_CHOICE;
1825 if (button == MB_MENU_LEAVE)
1827 return_to_main_menu = TRUE;
1829 else if (button == MB_MENU_CHOICE)
1831 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1833 SetGameStatus(GAME_MODE_INFO);
1835 info_mode = INFO_MODE_MAIN;
1844 if (title_screen_nr < num_title_screens)
1846 tci = &title_controls[title_screen_nr];
1848 SetAnimStatus(getTitleAnimMode(tci));
1850 sound = getTitleSound(tci);
1851 music = getTitleMusic(tci);
1853 if (last_sound != SND_UNDEFINED && sound != last_sound)
1854 FadeSound(last_sound);
1855 if (last_music != MUS_UNDEFINED && music != last_music)
1858 fading = getTitleFading(tci);
1860 FadeOut(REDRAW_ALL);
1863 DrawTitleScreenImage(tci->local_nr, tci->initial);
1865 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1867 sound = getTitleSound(tci);
1868 music = getTitleMusic(tci);
1870 if (sound != last_sound)
1871 PlayMenuSoundExt(sound);
1872 if (music != last_music)
1873 PlayMenuMusicExt(music);
1880 DelayReached(&title_delay, 0); /* reset delay counter */
1884 FadeMenuSoundsAndMusic();
1886 return_to_main_menu = TRUE;
1890 if (return_to_main_menu)
1892 SetMouseCursor(CURSOR_DEFAULT);
1894 /* force full menu screen redraw after displaying title screens */
1895 redraw_mask = REDRAW_ALL;
1897 if (game_status_last_screen == GAME_MODE_INFO)
1899 SetGameStatus(GAME_MODE_INFO);
1901 info_mode = INFO_MODE_MAIN;
1905 else /* default: return to main menu */
1907 SetGameStatus(GAME_MODE_MAIN);
1914 static void HandleMainMenu_SelectLevel(int step, int direction,
1915 int selected_level_nr)
1917 int old_level_nr = level_nr;
1920 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1921 new_level_nr = selected_level_nr;
1923 new_level_nr = old_level_nr + step * direction;
1925 if (new_level_nr < leveldir_current->first_level)
1926 new_level_nr = leveldir_current->first_level;
1927 if (new_level_nr > leveldir_current->last_level)
1928 new_level_nr = leveldir_current->last_level;
1930 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1932 /* skipping levels is only allowed when trying to skip single level */
1933 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1934 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1936 leveldir_current->handicap_level++;
1937 SaveLevelSetup_SeriesInfo();
1940 new_level_nr = leveldir_current->handicap_level;
1943 if (new_level_nr != old_level_nr)
1945 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1947 PlaySound(SND_MENU_ITEM_SELECTING);
1949 level_nr = new_level_nr;
1951 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1952 int2str(level_nr, menu.main.text.level_number.size),
1953 mci->pos_text->font);
1955 LoadLevel(level_nr);
1956 DrawPreviewLevelInitial();
1960 DrawCompleteVideoDisplay();
1962 SaveLevelSetup_SeriesInfo();
1964 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1966 /* needed because DrawPreviewLevelInitial() takes some time */
1968 /* SyncDisplay(); */
1972 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1974 static int choice = MAIN_CONTROL_GAME;
1975 static boolean button_pressed_last = FALSE;
1976 boolean button_pressed = FALSE;
1980 if (button == MB_MENU_INITIALIZE)
1982 DrawCursorAndText_Main(choice, TRUE, FALSE);
1987 if (mx || my) /* mouse input */
1991 for (i = 0; main_controls[i].nr != -1; i++)
1993 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1994 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1995 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1997 pos = main_controls[i].nr;
2003 /* check if level preview was clicked */
2004 if (insidePreviewRect(&preview, mx - SX, my - SY))
2005 pos = MAIN_CONTROL_GAME;
2007 // handle pressed/unpressed state for active/inactive menu buttons
2008 // (if pos != -1, "i" contains index position corresponding to "pos")
2010 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2011 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2012 button_pressed = TRUE;
2014 if (button_pressed != button_pressed_last)
2016 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2019 PlaySound(SND_MENU_BUTTON_PRESSING);
2021 PlaySound(SND_MENU_BUTTON_RELEASING);
2024 else if (dx || dy) /* keyboard input */
2026 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2027 choice == MAIN_CONTROL_SETUP))
2028 button = MB_MENU_CHOICE;
2033 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2035 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2037 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2039 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2041 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2043 CloseDoor(DOOR_CLOSE_2);
2045 SetGameStatus(GAME_MODE_LEVELNR);
2047 DrawChooseLevelNr();
2049 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2055 PlaySound(SND_MENU_ITEM_ACTIVATING);
2057 DrawCursorAndText_Main(choice, FALSE, FALSE);
2058 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2064 if (choice != MAIN_CONTROL_INFO &&
2065 choice != MAIN_CONTROL_SETUP)
2066 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2071 PlaySound(SND_MENU_ITEM_SELECTING);
2073 if (pos == MAIN_CONTROL_NAME)
2075 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2077 HandleTypeName(strlen(setup.player_name), 0);
2079 else if (pos == MAIN_CONTROL_LEVELS)
2083 CloseDoor(DOOR_CLOSE_2);
2085 SetGameStatus(GAME_MODE_LEVELS);
2087 SaveLevelSetup_LastSeries();
2088 SaveLevelSetup_SeriesInfo();
2090 if (setup.internal.choose_from_top_leveldir)
2093 DrawChooseLevelSet();
2096 else if (pos == MAIN_CONTROL_SCORES)
2098 CloseDoor(DOOR_CLOSE_2);
2100 SetGameStatus(GAME_MODE_SCORES);
2102 DrawHallOfFame(level_nr, -1);
2104 else if (pos == MAIN_CONTROL_EDITOR)
2106 if (leveldir_current->readonly &&
2107 !strEqual(setup.player_name, "Artsoft"))
2108 Request("This level is read only!", REQ_CONFIRM);
2110 CloseDoor(DOOR_CLOSE_2);
2112 SetGameStatus(GAME_MODE_EDITOR);
2114 FadeSetEnterScreen();
2118 else if (pos == MAIN_CONTROL_INFO)
2120 CloseDoor(DOOR_CLOSE_2);
2122 SetGameStatus(GAME_MODE_INFO);
2124 info_mode = INFO_MODE_MAIN;
2128 else if (pos == MAIN_CONTROL_GAME)
2130 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2132 else if (pos == MAIN_CONTROL_SETUP)
2134 CloseDoor(DOOR_CLOSE_2);
2136 SetGameStatus(GAME_MODE_SETUP);
2138 setup_mode = SETUP_MODE_MAIN;
2142 else if (pos == MAIN_CONTROL_QUIT)
2144 SaveLevelSetup_LastSeries();
2145 SaveLevelSetup_SeriesInfo();
2147 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2148 SetGameStatus(GAME_MODE_QUIT);
2153 button_pressed_last = button_pressed;
2157 /* ========================================================================= */
2158 /* info screen functions */
2159 /* ========================================================================= */
2161 static struct TokenInfo *info_info;
2162 static int num_info_info; /* number of info entries shown on screen */
2163 static int max_info_info; /* total number of info entries in list */
2165 static void execInfoTitleScreen(void)
2167 info_mode = INFO_MODE_TITLE;
2172 static void execInfoElements(void)
2174 info_mode = INFO_MODE_ELEMENTS;
2179 static void execInfoMusic(void)
2181 info_mode = INFO_MODE_MUSIC;
2186 static void execInfoCredits(void)
2188 info_mode = INFO_MODE_CREDITS;
2193 static void execInfoProgram(void)
2195 info_mode = INFO_MODE_PROGRAM;
2200 static void execInfoVersion(void)
2202 info_mode = INFO_MODE_VERSION;
2207 static void execInfoLevelSet(void)
2209 info_mode = INFO_MODE_LEVELSET;
2214 static void execExitInfo(void)
2216 SetGameStatus(GAME_MODE_MAIN);
2221 static struct TokenInfo info_info_main[] =
2223 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2224 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2225 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2226 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2227 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2228 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2229 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2230 { TYPE_EMPTY, NULL, "" },
2231 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2236 static int getMenuTextFont(int type)
2238 if (type & (TYPE_SWITCH |
2252 static struct TokenInfo *setup_info;
2253 static struct TokenInfo setup_info_input[];
2255 static struct TokenInfo *menu_info;
2257 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2258 int screen_pos, int menu_info_pos_raw,
2261 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2262 struct TokenInfo *ti = &token_info[pos];
2263 int xpos = MENU_SCREEN_START_XPOS;
2264 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2265 int font_nr = getMenuTextFont(ti->type);
2267 if (setup_mode == SETUP_MODE_INPUT)
2268 font_nr = FONT_MENU_1;
2271 font_nr = FONT_ACTIVE(font_nr);
2273 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2275 if (ti->type & ~TYPE_SKIP_ENTRY)
2276 drawCursor(screen_pos, active);
2279 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2282 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2285 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2288 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2291 static char *window_size_text;
2292 static char *scaling_type_text;
2293 static char *network_server_text;
2295 static void drawSetupValue(int, int);
2297 static void drawMenuInfoList(int first_entry, int num_page_entries,
2298 int max_page_entries)
2302 if (first_entry + num_page_entries > max_page_entries)
2305 clearMenuListArea();
2307 for (i = 0; i < num_page_entries; i++)
2309 int menu_info_pos = first_entry + i;
2310 struct TokenInfo *si = &menu_info[menu_info_pos];
2311 void *value_ptr = si->value;
2313 /* set some entries to "unchangeable" according to other variables */
2314 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2315 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2316 (value_ptr == &setup.sound_music && !audio.music_available) ||
2317 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2318 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2319 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2320 si->type |= TYPE_GHOSTED;
2322 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2323 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2324 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2325 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2326 else if (si->type & ~TYPE_SKIP_ENTRY)
2327 initCursor(i, IMG_MENU_BUTTON);
2329 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2331 if (si->type & TYPE_STRING)
2335 if (value_ptr == &network_server_text)
2336 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2338 if (gadget_id != -1)
2340 struct GadgetInfo *gi = screen_gadget[gadget_id];
2341 int xpos = MENU_SCREEN_START_XPOS;
2342 int ypos = MENU_SCREEN_START_YPOS + i;
2343 int x = mSX + xpos * 32;
2344 int y = mSY + ypos * 32;
2346 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2350 if (si->type & TYPE_VALUE &&
2351 menu_info == setup_info)
2352 drawSetupValue(i, menu_info_pos);
2356 static void DrawInfoScreen_Main(void)
2358 int fade_mask = REDRAW_FIELD;
2361 if (redraw_mask & REDRAW_ALL)
2362 fade_mask = REDRAW_ALL;
2364 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2365 fade_mask = REDRAW_ALL;
2368 FadeMenuSoundsAndMusic();
2370 FreeScreenGadgets();
2371 CreateScreenGadgets();
2373 /* (needed after displaying title screens which disable auto repeat) */
2374 KeyboardAutoRepeatOn();
2376 FadeSetLeaveScreen();
2380 /* needed if different viewport properties defined for info screen */
2381 ChangeViewportPropertiesIfNeeded();
2383 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2387 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2389 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2391 info_info = info_info_main;
2393 // determine maximal number of info entries that can be displayed on screen
2395 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2398 // determine maximal number of info entries available for menu of info screen
2400 for (i = 0; info_info[i].type != 0; i++)
2403 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2405 MapScreenGadgets(max_info_info);
2407 PlayMenuSoundsAndMusic();
2409 DrawMaskedBorder(fade_mask);
2414 static void changeSetupValue(int, int, int);
2416 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2417 int mode, int num_page_entries,
2418 int max_page_entries)
2420 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2421 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2422 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2423 int *num_page_entries_last = num_page_entries_all_last[game_status];
2424 int *choice_store = choice_stores[game_status];
2425 int *first_entry_store = first_entry_stores[game_status];
2426 int choice = choice_store[mode]; /* starts with 0 */
2427 int first_entry = first_entry_store[mode]; /* starts with 0 */
2429 int y = choice - first_entry;
2431 boolean position_set_by_scrollbar = (dx == 999);
2432 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2435 if (button == MB_MENU_INITIALIZE)
2437 // check if number of menu page entries has changed (may happen by change
2438 // of custom artwork definition value for 'list_size' for this menu screen)
2439 // (in this case, the last menu position most probably has to be corrected)
2440 if (num_page_entries != num_page_entries_last[mode])
2442 choice_store[mode] = first_entry_store[mode] = 0;
2444 choice = first_entry = 0;
2447 num_page_entries_last[mode] = num_page_entries;
2450 /* advance to first valid menu entry */
2451 while (choice < num_page_entries &&
2452 menu_info[choice].type & TYPE_SKIP_ENTRY)
2455 if (position_set_by_scrollbar)
2456 first_entry = first_entry_store[mode] = dy;
2458 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2459 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2461 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2463 if (choice < first_entry)
2465 choice = first_entry;
2467 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2470 else if (choice > first_entry + num_page_entries - 1)
2472 choice = first_entry + num_page_entries - 1;
2474 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2478 choice_store[mode] = choice;
2480 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2484 else if (button == MB_MENU_LEAVE)
2486 PlaySound(SND_MENU_ITEM_SELECTING);
2488 for (i = 0; i < max_page_entries; i++)
2490 if (menu_info[i].type & TYPE_LEAVE_MENU)
2492 void (*menu_callback_function)(void) = menu_info[i].value;
2496 menu_callback_function();
2498 break; /* absolutely needed because function changes 'menu_info'! */
2505 if (mx || my) /* mouse input */
2507 x = (mx - mSX) / 32;
2508 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2510 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2512 /* move cursor instead of scrolling when already at start/end of list */
2513 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2515 else if (dy == +1 * SCROLL_LINE &&
2516 first_entry + num_page_entries == max_page_entries)
2519 /* handle scrolling screen one line or page */
2521 y + dy > num_page_entries - 1)
2523 boolean redraw = FALSE;
2525 if (ABS(dy) == SCROLL_PAGE)
2526 step = num_page_entries - 1;
2528 if (dy < 0 && first_entry > 0)
2530 /* scroll page/line up */
2532 first_entry -= step;
2533 if (first_entry < 0)
2538 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2540 /* scroll page/line down */
2542 first_entry += step;
2543 if (first_entry + num_page_entries > max_page_entries)
2544 first_entry = MAX(0, max_page_entries - num_page_entries);
2551 choice += first_entry - first_entry_store[mode];
2553 if (choice < first_entry)
2555 choice = first_entry;
2557 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2560 else if (choice > first_entry + num_page_entries - 1)
2562 choice = first_entry + num_page_entries - 1;
2564 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2567 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2571 if (choice < first_entry ||
2572 choice > first_entry + num_page_entries - 1)
2573 first_entry += SIGN(dy);
2576 first_entry_store[mode] = first_entry;
2577 choice_store[mode] = choice;
2579 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2581 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2583 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2584 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2592 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2594 if (menu_info[choice].type & menu_navigation_type ||
2595 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2596 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2597 menu_info[choice].type & TYPE_PLAYER)
2598 button = MB_MENU_CHOICE;
2603 /* jump to next non-empty menu entry (up or down) */
2604 while (first_entry + y > 0 &&
2605 first_entry + y < max_page_entries - 1 &&
2606 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2609 if (!IN_VIS_MENU(x, y))
2611 choice += y - y_old;
2613 if (choice < first_entry)
2614 first_entry = choice;
2615 else if (choice > first_entry + num_page_entries - 1)
2616 first_entry = choice - num_page_entries + 1;
2618 if (first_entry >= 0 &&
2619 first_entry + num_page_entries <= max_page_entries)
2621 first_entry_store[mode] = first_entry;
2623 if (choice < first_entry)
2624 choice = first_entry;
2625 else if (choice > first_entry + num_page_entries - 1)
2626 choice = first_entry + num_page_entries - 1;
2628 choice_store[mode] = choice;
2630 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2632 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2634 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2635 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2642 if (!anyScrollbarGadgetActive() &&
2643 IN_VIS_MENU(x, y) &&
2644 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2645 y >= 0 && y < num_page_entries)
2649 if (first_entry + y != choice &&
2650 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2652 PlaySound(SND_MENU_ITEM_ACTIVATING);
2654 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2655 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2657 choice = choice_store[mode] = first_entry + y;
2661 PlaySound(SND_MENU_ITEM_SELECTING);
2663 for (i = 0; menu_info[i].type != 0; i++)
2665 if (menu_info[i].type & TYPE_LEAVE_MENU)
2667 void (*menu_callback_function)(void) = menu_info[i].value;
2671 menu_callback_function();
2673 /* absolutely needed because function changes 'menu_info'! */
2681 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2683 PlaySound(SND_MENU_ITEM_SELECTING);
2685 /* when selecting key headline, execute function for key value change */
2686 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2687 menu_info[first_entry + y + 1].type & TYPE_KEY)
2690 /* when selecting string value, execute function for list selection */
2691 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2692 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2695 /* when selecting string value, execute function for text input gadget */
2696 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2697 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2700 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2702 void (*menu_callback_function)(void) =
2703 menu_info[first_entry + y].value;
2705 FadeSetFromType(menu_info[first_entry + y].type);
2707 menu_callback_function();
2709 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2711 void (*gadget_callback_function)(void) =
2712 menu_info[first_entry + y].value;
2714 gadget_callback_function();
2716 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2717 menu_info == setup_info)
2719 changeSetupValue(y, first_entry + y, dx);
2725 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2727 menu_info = info_info;
2729 HandleMenuScreen(mx, my, dx, dy, button,
2730 info_mode, num_info_info, max_info_info);
2733 static int getMenuFontSpacing(int spacing_height, int font_nr)
2735 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2737 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2741 static int getMenuTextSpacing(int spacing_height, int font_nr)
2743 return (getMenuFontSpacing(spacing_height, font_nr) +
2744 EXTRA_SPACING(game_status));
2747 static int getMenuTextStep(int spacing_height, int font_nr)
2749 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2752 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2754 int font_title = MENU_INFO_FONT_TITLE;
2755 int font_error = FONT_TEXT_2;
2756 int font_foot = MENU_INFO_FONT_FOOT;
2757 int spacing_title = menu.headline1_spacing_info[info_mode];
2758 int ystep_title = getMenuTextStep(spacing_title, font_title);
2759 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2760 int ystart2 = ystart1 + ystep_title;
2761 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2763 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2765 FadeOut(REDRAW_FIELD);
2770 DrawTextSCentered(ystart1, font_title, text_title);
2771 DrawTextSCentered(ystart2, font_error, text_error);
2773 DrawTextSCentered(ybottom, font_foot,
2774 "Press any key or button for info menu");
2776 FadeIn(REDRAW_FIELD);
2779 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2781 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2782 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2783 int font_title = MENU_INFO_FONT_TITLE;
2784 int font_foot = MENU_INFO_FONT_FOOT;
2785 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2786 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2787 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2788 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2789 int ystep = MENU_SCREEN_INFO_YSTEP;
2790 int element, action, direction;
2798 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2799 infoscreen_step[i] = infoscreen_frame[i] = 0;
2804 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2806 DrawTextSCentered(ybottom, font_foot,
2807 "Press any key or button for next page");
2813 while (helpanim_info[j].element != HELPANIM_LIST_END)
2815 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2820 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2829 j += infoscreen_step[i - start];
2831 element = helpanim_info[j].element;
2832 action = helpanim_info[j].action;
2833 direction = helpanim_info[j].direction;
2836 element = EL_UNKNOWN;
2838 if (action != -1 && direction != -1)
2839 graphic = el_act_dir2img(element, action, direction);
2840 else if (action != -1)
2841 graphic = el_act2img(element, action);
2842 else if (direction != -1)
2843 graphic = el_dir2img(element, direction);
2845 graphic = el2img(element);
2847 delay = helpanim_info[j++].delay;
2852 if (infoscreen_frame[i - start] == 0)
2855 infoscreen_frame[i - start] = delay - 1;
2859 sync_frame = delay - infoscreen_frame[i - start];
2860 infoscreen_frame[i - start]--;
2863 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2865 if (!infoscreen_frame[i - start])
2866 infoscreen_step[i - start] = 0;
2870 if (!infoscreen_frame[i - start])
2871 infoscreen_step[i - start]++;
2872 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2878 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2880 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2881 graphic, sync_frame, USE_MASKING);
2884 DrawInfoScreen_HelpText(element, action, direction, i - start);
2889 redraw_mask |= REDRAW_FIELD;
2894 static char *getHelpText(int element, int action, int direction)
2896 char token[MAX_LINE_LEN];
2898 strcpy(token, element_info[element].token_name);
2901 strcat(token, element_action_info[action].suffix);
2903 if (direction != -1)
2904 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2906 return getHashEntry(helptext_info, token);
2909 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2911 int font_nr = FONT_INFO_ELEMENTS;
2912 int font_width = getFontWidth(font_nr);
2913 int font_height = getFontHeight(font_nr);
2914 int yoffset = (TILEX - 2 * font_height) / 2;
2915 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2916 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2917 int ystep = TILEY + 4;
2918 int pad_left = xstart - SX;
2919 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2920 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2921 int max_lines_per_text = 2;
2924 if (action != -1 && direction != -1) /* element.action.direction */
2925 text = getHelpText(element, action, direction);
2927 if (text == NULL && action != -1) /* element.action */
2928 text = getHelpText(element, action, -1);
2930 if (text == NULL && direction != -1) /* element.direction */
2931 text = getHelpText(element, -1, direction);
2933 if (text == NULL) /* base element */
2934 text = getHelpText(element, -1, -1);
2936 if (text == NULL) /* not found */
2937 text = "No description available";
2939 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2940 ystart += getFontHeight(font_nr) / 2;
2942 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2943 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2944 TRUE, FALSE, FALSE);
2947 static void DrawInfoScreen_TitleScreen(void)
2949 SetGameStatus(GAME_MODE_TITLE);
2954 void HandleInfoScreen_TitleScreen(int button)
2956 HandleTitleScreen(0, 0, 0, 0, button);
2959 static void DrawInfoScreen_Elements(void)
2961 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2963 FadeOut(REDRAW_FIELD);
2968 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2970 FadeIn(REDRAW_FIELD);
2973 void HandleInfoScreen_Elements(int button)
2975 static unsigned int info_delay = 0;
2976 static int num_anims;
2977 static int num_pages;
2979 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2982 if (button == MB_MENU_INITIALIZE)
2984 boolean new_element = TRUE;
2988 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2990 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2992 else if (new_element)
2995 new_element = FALSE;
2999 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3003 if (button == MB_MENU_LEAVE)
3005 PlaySound(SND_MENU_ITEM_SELECTING);
3007 info_mode = INFO_MODE_MAIN;
3012 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3014 if (button != MB_MENU_INITIALIZE)
3016 PlaySound(SND_MENU_ITEM_SELECTING);
3021 if (page >= num_pages)
3023 FadeMenuSoundsAndMusic();
3025 info_mode = INFO_MODE_MAIN;
3032 FadeSetNextScreen();
3034 if (button != MB_MENU_INITIALIZE)
3035 FadeOut(REDRAW_FIELD);
3037 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3039 if (button != MB_MENU_INITIALIZE)
3040 FadeIn(REDRAW_FIELD);
3044 if (DelayReached(&info_delay, GameFrameDelay))
3045 if (page < num_pages)
3046 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3048 PlayMenuSoundIfLoop();
3052 static void DrawInfoScreen_Music(void)
3054 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3056 FadeOut(REDRAW_FIELD);
3063 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3065 FadeIn(REDRAW_FIELD);
3068 void HandleInfoScreen_Music(int button)
3070 static struct MusicFileInfo *list = NULL;
3071 int font_title = MENU_INFO_FONT_TITLE;
3072 int font_head = MENU_INFO_FONT_HEAD;
3073 int font_text = MENU_INFO_FONT_TEXT;
3074 int font_foot = MENU_INFO_FONT_FOOT;
3075 int spacing_title = menu.headline1_spacing_info[info_mode];
3076 int spacing_head = menu.headline2_spacing_info[info_mode];
3077 int ystep_title = getMenuTextStep(spacing_title, font_title);
3078 int ystep_head = getMenuTextStep(spacing_head, font_head);
3079 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3080 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3082 if (button == MB_MENU_INITIALIZE)
3084 list = music_file_info;
3088 FadeMenuSoundsAndMusic();
3093 DrawTextSCentered(ystart, font_title,
3094 "No music info for this level set.");
3096 DrawTextSCentered(ybottom, font_foot,
3097 "Press any key or button for info menu");
3103 if (button == MB_MENU_LEAVE)
3105 PlaySound(SND_MENU_ITEM_SELECTING);
3107 FadeMenuSoundsAndMusic();
3109 info_mode = INFO_MODE_MAIN;
3114 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3116 if (button != MB_MENU_INITIALIZE)
3118 PlaySound(SND_MENU_ITEM_SELECTING);
3126 FadeMenuSoundsAndMusic();
3128 info_mode = INFO_MODE_MAIN;
3134 FadeMenuSoundsAndMusic();
3136 if (list != music_file_info)
3137 FadeSetNextScreen();
3139 if (button != MB_MENU_INITIALIZE)
3140 FadeOut(REDRAW_FIELD);
3147 int sound = list->music;
3149 if (sound_info[sound].loop)
3150 PlaySoundLoop(sound);
3154 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3158 int music = list->music;
3160 if (music_info[music].loop)
3161 PlayMusicLoop(music);
3165 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3168 ystart += ystep_title;
3170 if (!strEqual(list->title, UNKNOWN_NAME))
3172 if (!strEqual(list->title_header, UNKNOWN_NAME))
3174 DrawTextSCentered(ystart, font_head, list->title_header);
3175 ystart += ystep_head;
3178 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3179 ystart += ystep_head;
3182 if (!strEqual(list->artist, UNKNOWN_NAME))
3184 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3185 DrawTextSCentered(ystart, font_head, list->artist_header);
3187 DrawTextSCentered(ystart, font_head, "by");
3189 ystart += ystep_head;
3191 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3192 ystart += ystep_head;
3195 if (!strEqual(list->album, UNKNOWN_NAME))
3197 if (!strEqual(list->album_header, UNKNOWN_NAME))
3198 DrawTextSCentered(ystart, font_head, list->album_header);
3200 DrawTextSCentered(ystart, font_head, "from the album");
3202 ystart += ystep_head;
3204 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3205 ystart += ystep_head;
3208 if (!strEqual(list->year, UNKNOWN_NAME))
3210 if (!strEqual(list->year_header, UNKNOWN_NAME))
3211 DrawTextSCentered(ystart, font_head, list->year_header);
3213 DrawTextSCentered(ystart, font_head, "from the year");
3215 ystart += ystep_head;
3217 DrawTextFCentered(ystart, font_text, "%s", list->year);
3218 ystart += ystep_head;
3221 DrawTextSCentered(ybottom, FONT_TEXT_4,
3222 "Press any key or button for next page");
3224 if (button != MB_MENU_INITIALIZE)
3225 FadeIn(REDRAW_FIELD);
3228 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3229 PlaySoundLoop(list->music);
3232 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3234 int font_title = MENU_INFO_FONT_TITLE;
3235 int font_head = MENU_INFO_FONT_HEAD;
3236 int font_text = MENU_INFO_FONT_TEXT;
3237 int font_foot = MENU_INFO_FONT_FOOT;
3238 int spacing_title = menu.headline1_spacing_info[info_mode];
3239 int spacing_head = menu.headline2_spacing_info[info_mode];
3240 int spacing_para = menu.paragraph_spacing_info[info_mode];
3241 int spacing_line = menu.line_spacing_info[info_mode];
3242 int ystep_title = getMenuTextStep(spacing_title, font_title);
3243 int ystep_head = getMenuTextStep(spacing_head, font_head);
3244 int ystep_para = getMenuTextStep(spacing_para, font_text);
3245 int ystep_line = getMenuTextStep(spacing_line, font_text);
3246 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3247 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3252 DrawTextSCentered(ystart, font_title, "Credits:");
3253 ystart += ystep_title;
3257 DrawTextSCentered(ystart, font_head,
3258 "Special thanks to");
3259 ystart += ystep_head;
3260 DrawTextSCentered(ystart, font_text,
3262 ystart += ystep_head;
3263 DrawTextSCentered(ystart, font_head,
3265 ystart += ystep_head;
3266 DrawTextSCentered(ystart, font_text,
3267 "\"Boulder Dash\"");
3268 ystart += ystep_head;
3269 DrawTextSCentered(ystart, font_head,
3271 ystart += ystep_head;
3272 DrawTextSCentered(ystart, font_text,
3274 ystart += ystep_head;
3275 DrawTextSCentered(ystart, font_head,
3277 ystart += ystep_head;
3278 DrawTextSCentered(ystart, font_text,
3279 "First Star Software");
3281 else if (screen_nr == 1)
3283 DrawTextSCentered(ystart, font_head,
3284 "Special thanks to");
3285 ystart += ystep_head;
3286 DrawTextSCentered(ystart, font_text,
3287 "Klaus Heinz & Volker Wertich");
3288 ystart += ystep_head;
3289 DrawTextSCentered(ystart, font_head,
3291 ystart += ystep_head;
3292 DrawTextSCentered(ystart, font_text,
3293 "\"Emerald Mine\"");
3294 ystart += ystep_head;
3295 DrawTextSCentered(ystart, font_head,
3297 ystart += ystep_head;
3298 DrawTextSCentered(ystart, font_text,
3300 ystart += ystep_head;
3301 DrawTextSCentered(ystart, font_head,
3303 ystart += ystep_head;
3304 DrawTextSCentered(ystart, font_text,
3307 else if (screen_nr == 2)
3309 DrawTextSCentered(ystart, font_head,
3310 "Special thanks to");
3311 ystart += ystep_head;
3312 DrawTextSCentered(ystart, font_text,
3313 "Michael Stopp & Philip Jespersen");
3314 ystart += ystep_head;
3315 DrawTextSCentered(ystart, font_head,
3317 ystart += ystep_head;
3318 DrawTextSCentered(ystart, font_text,
3320 ystart += ystep_head;
3321 DrawTextSCentered(ystart, font_head,
3323 ystart += ystep_head;
3324 DrawTextSCentered(ystart, font_text,
3326 ystart += ystep_head;
3327 DrawTextSCentered(ystart, font_head,
3329 ystart += ystep_head;
3330 DrawTextSCentered(ystart, font_text,
3331 "Digital Integration");
3333 else if (screen_nr == 3)
3335 DrawTextSCentered(ystart, font_head,
3336 "Special thanks to");
3337 ystart += ystep_head;
3338 DrawTextSCentered(ystart, font_text,
3339 "Hiroyuki Imabayashi");
3340 ystart += ystep_head;
3341 DrawTextSCentered(ystart, font_head,
3343 ystart += ystep_head;
3344 DrawTextSCentered(ystart, font_text,
3346 ystart += ystep_head;
3347 DrawTextSCentered(ystart, font_head,
3349 ystart += ystep_head;
3350 DrawTextSCentered(ystart, font_text,
3352 ystart += ystep_head;
3353 DrawTextSCentered(ystart, font_head,
3355 ystart += ystep_head;
3356 DrawTextSCentered(ystart, font_text,
3359 else if (screen_nr == 4)
3361 DrawTextSCentered(ystart, font_head,
3362 "Special thanks to");
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,
3371 "J\xfcrgen Bonhagen");
3372 ystart += ystep_head;
3373 DrawTextSCentered(ystart, font_head,
3374 "for the continuous creation");
3375 ystart += ystep_line;
3376 DrawTextSCentered(ystart, font_head,
3377 "of outstanding level sets");
3379 else if (screen_nr == 5)
3381 DrawTextSCentered(ystart, font_head,
3383 ystart += ystep_head;
3384 DrawTextSCentered(ystart, font_text,
3386 ystart += ystep_head;
3387 DrawTextSCentered(ystart, font_head,
3388 "for ideas and inspiration by");
3389 ystart += ystep_head;
3390 DrawTextSCentered(ystart, font_text,
3392 ystart += ystep_para;
3394 DrawTextSCentered(ystart, font_head,
3396 ystart += ystep_head;
3397 DrawTextSCentered(ystart, font_text,
3399 ystart += ystep_head;
3400 DrawTextSCentered(ystart, font_head,
3401 "for ideas and inspiration by");
3402 ystart += ystep_head;
3403 DrawTextSCentered(ystart, font_text,
3406 else if (screen_nr == 6)
3408 DrawTextSCentered(ystart, font_head,
3410 ystart += ystep_head;
3411 DrawTextSCentered(ystart, font_text,
3413 ystart += ystep_head;
3414 DrawTextSCentered(ystart, font_head,
3415 "for the code base used for the");
3416 ystart += ystep_line;
3417 DrawTextSCentered(ystart, font_head,
3418 "native Emerald Mine engine");
3420 else if (screen_nr == 7)
3422 DrawTextSCentered(ystart, font_head,
3424 ystart += ystep_head;
3425 DrawTextSCentered(ystart, font_text,
3427 ystart += ystep_head;
3428 DrawTextSCentered(ystart, font_head,
3429 "for the initial DOS port");
3430 ystart += ystep_para;
3432 DrawTextSCentered(ystart, font_head,
3434 ystart += ystep_head;
3435 DrawTextSCentered(ystart, font_text,
3437 ystart += ystep_head;
3438 DrawTextSCentered(ystart, font_head,
3439 "for some additional toons");
3441 else if (screen_nr == 8)
3443 DrawTextSCentered(ystart, font_head,
3444 "And not to forget:");
3445 ystart += ystep_head;
3446 DrawTextSCentered(ystart, font_head,
3448 ystart += ystep_head;
3449 DrawTextSCentered(ystart, font_text,
3450 "All those who contributed");
3451 ystart += ystep_line;
3452 DrawTextSCentered(ystart, font_text,
3453 "levels to this game");
3454 ystart += ystep_line;
3455 DrawTextSCentered(ystart, font_text,
3459 DrawTextSCentered(ybottom, font_foot,
3460 "Press any key or button for next page");
3463 static void DrawInfoScreen_Credits(void)
3465 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3467 FadeMenuSoundsAndMusic();
3469 FadeOut(REDRAW_FIELD);
3471 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3473 FadeIn(REDRAW_FIELD);
3476 void HandleInfoScreen_Credits(int button)
3478 static int screen_nr = 0;
3479 int num_screens = 9;
3481 if (button == MB_MENU_INITIALIZE)
3485 // DrawInfoScreen_CreditsScreen(screen_nr);
3488 if (button == MB_MENU_LEAVE)
3490 PlaySound(SND_MENU_ITEM_SELECTING);
3492 info_mode = INFO_MODE_MAIN;
3497 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3499 if (button != MB_MENU_INITIALIZE)
3501 PlaySound(SND_MENU_ITEM_SELECTING);
3506 if (screen_nr >= num_screens)
3508 FadeMenuSoundsAndMusic();
3510 info_mode = INFO_MODE_MAIN;
3517 FadeSetNextScreen();
3519 if (button != MB_MENU_INITIALIZE)
3520 FadeOut(REDRAW_FIELD);
3522 DrawInfoScreen_CreditsScreen(screen_nr);
3524 if (button != MB_MENU_INITIALIZE)
3525 FadeIn(REDRAW_FIELD);
3529 PlayMenuSoundIfLoop();
3533 static void DrawInfoScreen_Program(void)
3535 int font_title = MENU_INFO_FONT_TITLE;
3536 int font_head = MENU_INFO_FONT_HEAD;
3537 int font_text = MENU_INFO_FONT_TEXT;
3538 int font_foot = MENU_INFO_FONT_FOOT;
3539 int spacing_title = menu.headline1_spacing_info[info_mode];
3540 int spacing_head = menu.headline2_spacing_info[info_mode];
3541 int spacing_para = menu.paragraph_spacing_info[info_mode];
3542 int spacing_line = menu.line_spacing_info[info_mode];
3543 int ystep_title = getMenuTextStep(spacing_title, font_title);
3544 int ystep_head = getMenuTextStep(spacing_head, font_head);
3545 int ystep_para = getMenuTextStep(spacing_para, font_text);
3546 int ystep_line = getMenuTextStep(spacing_line, font_text);
3547 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3548 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3550 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3552 FadeOut(REDRAW_FIELD);
3557 DrawTextSCentered(ystart, font_title, "Program Information:");
3558 ystart += ystep_title;
3560 DrawTextSCentered(ystart, font_head,
3561 "This game is Freeware!");
3562 ystart += ystep_head;
3563 DrawTextSCentered(ystart, font_head,
3564 "If you like it, send e-mail to:");
3565 ystart += ystep_head;
3566 DrawTextSCentered(ystart, font_text,
3567 setup.internal.program_email);
3568 ystart += ystep_para;
3570 DrawTextSCentered(ystart, font_head,
3571 "More information and levels:");
3572 ystart += ystep_head;
3573 DrawTextSCentered(ystart, font_text,
3574 setup.internal.program_website);
3575 ystart += ystep_para;
3577 DrawTextSCentered(ystart, font_head,
3578 "If you have created new levels,");
3579 ystart += ystep_line;
3580 DrawTextSCentered(ystart, font_head,
3581 "send them to me to include them!");
3582 ystart += ystep_head;
3583 DrawTextSCentered(ystart, font_head,
3586 DrawTextSCentered(ybottom, font_foot,
3587 "Press any key or button for info menu");
3589 FadeIn(REDRAW_FIELD);
3592 void HandleInfoScreen_Program(int button)
3594 if (button == MB_MENU_LEAVE)
3596 PlaySound(SND_MENU_ITEM_SELECTING);
3598 info_mode = INFO_MODE_MAIN;
3603 else if (button == MB_MENU_CHOICE)
3605 PlaySound(SND_MENU_ITEM_SELECTING);
3607 FadeMenuSoundsAndMusic();
3609 info_mode = INFO_MODE_MAIN;
3614 PlayMenuSoundIfLoop();
3618 static void DrawInfoScreen_Version(void)
3620 int font_title = MENU_INFO_FONT_TITLE;
3621 int font_head = MENU_INFO_FONT_HEAD;
3622 int font_text = MENU_INFO_FONT_TEXT;
3623 int font_foot = MENU_INFO_FONT_FOOT;
3624 int spacing_title = menu.headline1_spacing_info[info_mode];
3625 int spacing_head = menu.headline2_spacing_info[info_mode];
3626 int spacing_para = menu.paragraph_spacing_info[info_mode];
3627 int spacing_line = menu.line_spacing_info[info_mode];
3628 int xstep = getFontWidth(font_text);
3629 int ystep_title = getMenuTextStep(spacing_title, font_title);
3630 int ystep_head = getMenuTextStep(spacing_head, font_head);
3631 int ystep_para = getMenuTextStep(spacing_para, font_text);
3632 int ystep_line = getMenuTextStep(spacing_line, font_text);
3633 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3634 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3635 int xstart1 = mSX - SX + 2 * xstep;
3636 int xstart2 = mSX - SX + 18 * xstep;
3637 int xstart3 = mSX - SX + 28 * xstep;
3638 SDL_version sdl_version_compiled;
3639 const SDL_version *sdl_version_linked;
3640 int driver_name_len = 10;
3641 #if defined(TARGET_SDL2)
3642 SDL_version sdl_version_linked_ext;
3643 const char *driver_name = NULL;
3645 char driver_name[driver_name_len];
3648 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3650 FadeOut(REDRAW_FIELD);
3655 DrawTextSCentered(ystart, font_title, "Version Information:");
3656 ystart += ystep_title;
3658 DrawTextF(xstart1, ystart, font_head, "Name");
3659 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3660 ystart += ystep_line;
3662 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3664 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3665 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3666 ystart += ystep_line;
3668 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3669 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3670 ystart += ystep_line;
3674 DrawTextF(xstart1, ystart, font_head, "Version");
3675 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3676 ystart += ystep_line;
3679 DrawTextF(xstart1, ystart, font_head, "Platform");
3680 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3681 ystart += ystep_line;
3683 DrawTextF(xstart1, ystart, font_head, "Target");
3684 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3685 ystart += ystep_line;
3687 DrawTextF(xstart1, ystart, font_head, "Source date");
3688 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3689 ystart += ystep_para;
3691 DrawTextF(xstart1, ystart, font_head, "Library");
3692 DrawTextF(xstart2, ystart, font_head, "compiled");
3693 DrawTextF(xstart3, ystart, font_head, "linked");
3694 ystart += ystep_head;
3696 SDL_VERSION(&sdl_version_compiled);
3697 #if defined(TARGET_SDL2)
3698 SDL_GetVersion(&sdl_version_linked_ext);
3699 sdl_version_linked = &sdl_version_linked_ext;
3701 sdl_version_linked = SDL_Linked_Version();
3704 DrawTextF(xstart1, ystart, font_text, "SDL");
3705 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3706 sdl_version_compiled.major,
3707 sdl_version_compiled.minor,
3708 sdl_version_compiled.patch);
3709 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3710 sdl_version_linked->major,
3711 sdl_version_linked->minor,
3712 sdl_version_linked->patch);
3713 ystart += ystep_line;
3715 SDL_IMAGE_VERSION(&sdl_version_compiled);
3716 sdl_version_linked = IMG_Linked_Version();
3718 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3719 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3720 sdl_version_compiled.major,
3721 sdl_version_compiled.minor,
3722 sdl_version_compiled.patch);
3723 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3724 sdl_version_linked->major,
3725 sdl_version_linked->minor,
3726 sdl_version_linked->patch);
3727 ystart += ystep_line;
3729 SDL_MIXER_VERSION(&sdl_version_compiled);
3730 sdl_version_linked = Mix_Linked_Version();
3732 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3733 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3734 sdl_version_compiled.major,
3735 sdl_version_compiled.minor,
3736 sdl_version_compiled.patch);
3737 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3738 sdl_version_linked->major,
3739 sdl_version_linked->minor,
3740 sdl_version_linked->patch);
3741 ystart += ystep_line;
3743 SDL_NET_VERSION(&sdl_version_compiled);
3744 sdl_version_linked = SDLNet_Linked_Version();
3746 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3747 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3748 sdl_version_compiled.major,
3749 sdl_version_compiled.minor,
3750 sdl_version_compiled.patch);
3751 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3752 sdl_version_linked->major,
3753 sdl_version_linked->minor,
3754 sdl_version_linked->patch);
3755 ystart += ystep_para;
3757 DrawTextF(xstart1, ystart, font_head, "Driver");
3758 DrawTextF(xstart2, ystart, font_head, "Requested");
3759 DrawTextF(xstart3, ystart, font_head, "Used");
3760 ystart += ystep_head;
3762 #if defined(TARGET_SDL2)
3763 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3765 SDL_VideoDriverName(driver_name, driver_name_len);
3768 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3769 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3770 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3771 ystart += ystep_line;
3773 #if defined(TARGET_SDL2)
3774 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3776 SDL_AudioDriverName(driver_name, driver_name_len);
3779 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3780 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3781 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3783 DrawTextSCentered(ybottom, font_foot,
3784 "Press any key or button for info menu");
3786 FadeIn(REDRAW_FIELD);
3789 void HandleInfoScreen_Version(int button)
3791 if (button == MB_MENU_LEAVE)
3793 PlaySound(SND_MENU_ITEM_SELECTING);
3795 info_mode = INFO_MODE_MAIN;
3800 else if (button == MB_MENU_CHOICE)
3802 PlaySound(SND_MENU_ITEM_SELECTING);
3804 FadeMenuSoundsAndMusic();
3806 info_mode = INFO_MODE_MAIN;
3811 PlayMenuSoundIfLoop();
3815 static void DrawInfoScreen_LevelSet(void)
3817 struct TitleMessageInfo *tmi = &readme;
3818 char *filename = getLevelSetInfoFilename();
3819 char *title = "Level Set Information:";
3820 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3821 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3823 if (filename == NULL)
3825 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3830 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3832 FadeOut(REDRAW_FIELD);
3837 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3839 /* if x position set to "-1", automatically determine by playfield width */
3841 tmi->x = SXSIZE / 2;
3843 /* if y position set to "-1", use static default value */
3847 /* if width set to "-1", automatically determine by playfield width */
3848 if (tmi->width == -1)
3849 tmi->width = SXSIZE - 2 * TILEX;
3851 /* if height set to "-1", automatically determine by playfield height */
3852 if (tmi->height == -1)
3853 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3855 /* if chars set to "-1", automatically determine by text and font width */
3856 if (tmi->chars == -1)
3857 tmi->chars = tmi->width / getFontWidth(tmi->font);
3859 tmi->width = tmi->chars * getFontWidth(tmi->font);
3861 /* if lines set to "-1", automatically determine by text and font height */
3862 if (tmi->lines == -1)
3863 tmi->lines = tmi->height / getFontHeight(tmi->font);
3865 tmi->height = tmi->lines * getFontHeight(tmi->font);
3867 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3868 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3869 tmi->autowrap, tmi->centered, tmi->parse_comments);
3871 DrawTextSCentered(ybottom, FONT_TEXT_4,
3872 "Press any key or button for info menu");
3874 FadeIn(REDRAW_FIELD);
3877 static void HandleInfoScreen_LevelSet(int button)
3879 if (button == MB_MENU_LEAVE)
3881 PlaySound(SND_MENU_ITEM_SELECTING);
3883 info_mode = INFO_MODE_MAIN;
3888 else if (button == MB_MENU_CHOICE)
3890 PlaySound(SND_MENU_ITEM_SELECTING);
3892 FadeMenuSoundsAndMusic();
3894 info_mode = INFO_MODE_MAIN;
3899 PlayMenuSoundIfLoop();
3903 static void DrawInfoScreen(void)
3905 if (info_mode == INFO_MODE_TITLE)
3906 DrawInfoScreen_TitleScreen();
3907 else if (info_mode == INFO_MODE_ELEMENTS)
3908 DrawInfoScreen_Elements();
3909 else if (info_mode == INFO_MODE_MUSIC)
3910 DrawInfoScreen_Music();
3911 else if (info_mode == INFO_MODE_CREDITS)
3912 DrawInfoScreen_Credits();
3913 else if (info_mode == INFO_MODE_PROGRAM)
3914 DrawInfoScreen_Program();
3915 else if (info_mode == INFO_MODE_VERSION)
3916 DrawInfoScreen_Version();
3917 else if (info_mode == INFO_MODE_LEVELSET)
3918 DrawInfoScreen_LevelSet();
3920 DrawInfoScreen_Main();
3922 if (info_mode != INFO_MODE_MAIN &&
3923 info_mode != INFO_MODE_TITLE &&
3924 info_mode != INFO_MODE_MUSIC)
3925 PlayMenuSoundsAndMusic();
3928 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3930 if (info_mode == INFO_MODE_TITLE)
3931 HandleInfoScreen_TitleScreen(button);
3932 else if (info_mode == INFO_MODE_ELEMENTS)
3933 HandleInfoScreen_Elements(button);
3934 else if (info_mode == INFO_MODE_MUSIC)
3935 HandleInfoScreen_Music(button);
3936 else if (info_mode == INFO_MODE_CREDITS)
3937 HandleInfoScreen_Credits(button);
3938 else if (info_mode == INFO_MODE_PROGRAM)
3939 HandleInfoScreen_Program(button);
3940 else if (info_mode == INFO_MODE_VERSION)
3941 HandleInfoScreen_Version(button);
3942 else if (info_mode == INFO_MODE_LEVELSET)
3943 HandleInfoScreen_LevelSet(button);
3945 HandleInfoScreen_Main(mx, my, dx, dy, button);
3949 /* ========================================================================= */
3950 /* type name functions */
3951 /* ========================================================================= */
3953 void HandleTypeName(int newxpos, Key key)
3955 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3956 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3957 struct TextPosInfo *pos = mci->pos_input;
3958 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3959 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3960 static int xpos = 0;
3961 int font_nr = pos->font;
3962 int font_active_nr = FONT_ACTIVE(font_nr);
3963 int font_width = getFontWidth(font_active_nr);
3964 char key_char = getValidConfigValueChar(getCharFromKey(key));
3965 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3966 boolean is_active = TRUE;
3968 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3972 strcpy(last_player_name, setup.player_name);
3976 StartTextInput(startx, starty, pos->width, pos->height);
3978 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3980 setup.player_name[xpos] = key_char;
3981 setup.player_name[xpos + 1] = 0;
3985 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3989 setup.player_name[xpos] = 0;
3991 else if (key == KSYM_Return && xpos > 0)
3997 SetGameStatus(GAME_MODE_MAIN);
3999 else if (key == KSYM_Escape)
4001 strcpy(setup.player_name, last_player_name);
4005 SetGameStatus(GAME_MODE_MAIN);
4010 pos->width = (strlen(setup.player_name) + 1) * font_width;
4011 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4013 DrawText(startx, starty, setup.player_name, font_active_nr);
4014 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
4018 pos->width = strlen(setup.player_name) * font_width;
4019 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4021 DrawText(startx, starty, setup.player_name, font_nr);
4028 /* ========================================================================= */
4029 /* tree menu functions */
4030 /* ========================================================================= */
4032 static void DrawChooseTree(TreeInfo **ti_ptr)
4034 int fade_mask = REDRAW_FIELD;
4036 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4037 fade_mask = REDRAW_ALL;
4039 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4041 SetGameStatus(GAME_MODE_MAIN);
4050 FreeScreenGadgets();
4051 CreateScreenGadgets();
4055 /* needed if different viewport properties defined for choosing level (set) */
4056 ChangeViewportPropertiesIfNeeded();
4058 if (game_status == GAME_MODE_LEVELNR)
4059 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4060 else if (game_status == GAME_MODE_LEVELS)
4061 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4065 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4067 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4068 MapScreenTreeGadgets(*ti_ptr);
4070 DrawMaskedBorder(fade_mask);
4075 static void drawChooseTreeList(int first_entry, int num_page_entries,
4079 char *title_string = NULL;
4080 int yoffset_sets = MENU_TITLE1_YPOS;
4081 int yoffset_setup = 16;
4082 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4083 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4085 title_string = ti->infotext;
4087 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4089 clearMenuListArea();
4091 for (i = 0; i < num_page_entries; i++)
4093 TreeInfo *node, *node_first;
4094 int entry_pos = first_entry + i;
4095 int xpos = MENU_SCREEN_START_XPOS;
4096 int ypos = MENU_SCREEN_START_YPOS + i;
4097 int startx = mSX + xpos * 32;
4098 int starty = mSY + ypos * 32;
4099 int font_nr = FONT_TEXT_1;
4100 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4101 int startx_text = startx + font_xoffset;
4102 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4103 int text_size = startx_scrollbar - startx_text;
4104 int max_buffer_len = text_size / getFontWidth(font_nr);
4105 char buffer[max_buffer_len + 1];
4107 node_first = getTreeInfoFirstGroupEntry(ti);
4108 node = getTreeInfoFromPos(node_first, entry_pos);
4110 strncpy(buffer, node->name, max_buffer_len);
4111 buffer[max_buffer_len] = '\0';
4113 DrawText(startx, starty, buffer, font_nr + node->color);
4115 if (node->parent_link)
4116 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4117 else if (node->level_group)
4118 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4120 initCursor(i, IMG_MENU_BUTTON);
4123 redraw_mask |= REDRAW_FIELD;
4126 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4128 TreeInfo *node, *node_first;
4129 int x, last_redraw_mask = redraw_mask;
4130 int ypos = MENU_TITLE2_YPOS;
4131 int font_nr = FONT_TITLE_2;
4133 if (ti->type == TREE_TYPE_LEVEL_NR)
4134 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4136 if (ti->type != TREE_TYPE_LEVEL_DIR)
4139 node_first = getTreeInfoFirstGroupEntry(ti);
4140 node = getTreeInfoFromPos(node_first, entry_pos);
4142 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4144 if (node->parent_link)
4145 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4146 node->node_parent->name);
4147 else if (node->level_group)
4148 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4150 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4151 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4152 node->levels, (node->levels > 1 ? "levels" : "level"),
4155 /* let BackToFront() redraw only what is needed */
4156 redraw_mask = last_redraw_mask;
4157 for (x = 0; x < SCR_FIELDX; x++)
4158 MarkTileDirty(x, 1);
4161 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4164 TreeInfo *ti = *ti_ptr;
4166 int y = ti->cl_cursor;
4167 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4168 int num_entries = numTreeInfoInGroup(ti);
4169 int num_page_entries;
4170 boolean position_set_by_scrollbar = (dx == 999);
4172 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4173 num_page_entries = num_entries;
4175 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4177 if (button == MB_MENU_INITIALIZE)
4179 int num_entries = numTreeInfoInGroup(ti);
4180 int entry_pos = posTreeInfo(ti);
4182 if (ti->cl_first == -1)
4184 /* only on initialization */
4185 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4186 ti->cl_cursor = entry_pos - ti->cl_first;
4188 else if (ti->cl_cursor >= num_page_entries ||
4189 (num_entries > num_page_entries &&
4190 num_entries - ti->cl_first < num_page_entries))
4192 /* only after change of list size (by custom graphic configuration) */
4193 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4194 ti->cl_cursor = entry_pos - ti->cl_first;
4197 if (position_set_by_scrollbar)
4200 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4203 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4204 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4205 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4209 else if (button == MB_MENU_LEAVE)
4213 PlaySound(SND_MENU_ITEM_SELECTING);
4215 if (ti->node_parent)
4217 *ti_ptr = ti->node_parent;
4218 DrawChooseTree(ti_ptr);
4220 else if (game_status == GAME_MODE_SETUP)
4222 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4223 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4224 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4226 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4227 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4228 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4229 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4230 execSetupGraphics();
4231 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4232 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4233 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4235 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4236 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4237 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4238 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4239 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4240 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4241 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4242 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4249 if (game_status == GAME_MODE_LEVELNR)
4251 int new_level_nr = atoi(level_number_current->identifier);
4253 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4256 SetGameStatus(GAME_MODE_MAIN);
4264 if (mx || my) /* mouse input */
4266 x = (mx - mSX) / 32;
4267 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4269 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4271 /* move cursor instead of scrolling when already at start/end of list */
4272 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4274 else if (dy == +1 * SCROLL_LINE &&
4275 ti->cl_first + num_page_entries == num_entries)
4278 /* handle scrolling screen one line or page */
4279 if (ti->cl_cursor + dy < 0 ||
4280 ti->cl_cursor + dy > num_page_entries - 1)
4282 boolean redraw = FALSE;
4284 if (ABS(dy) == SCROLL_PAGE)
4285 step = num_page_entries - 1;
4287 if (dy < 0 && ti->cl_first > 0)
4289 /* scroll page/line up */
4291 ti->cl_first -= step;
4292 if (ti->cl_first < 0)
4297 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4299 /* scroll page/line down */
4301 ti->cl_first += step;
4302 if (ti->cl_first + num_page_entries > num_entries)
4303 ti->cl_first = MAX(0, num_entries - num_page_entries);
4310 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4311 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4312 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4314 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4321 /* handle moving cursor one line */
4322 y = ti->cl_cursor + dy;
4327 TreeInfo *node_first, *node_cursor;
4328 int entry_pos = ti->cl_first + y;
4330 node_first = getTreeInfoFirstGroupEntry(ti);
4331 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4333 if (node_cursor->node_group)
4337 PlaySound(SND_MENU_ITEM_SELECTING);
4339 node_cursor->cl_first = ti->cl_first;
4340 node_cursor->cl_cursor = ti->cl_cursor;
4341 *ti_ptr = node_cursor->node_group;
4342 DrawChooseTree(ti_ptr);
4347 else if (dx == -1 && ti->node_parent)
4351 PlaySound(SND_MENU_ITEM_SELECTING);
4353 *ti_ptr = ti->node_parent;
4354 DrawChooseTree(ti_ptr);
4359 if (!anyScrollbarGadgetActive() &&
4360 IN_VIS_MENU(x, y) &&
4361 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4362 y >= 0 && y < num_page_entries)
4366 if (y != ti->cl_cursor)
4368 PlaySound(SND_MENU_ITEM_ACTIVATING);
4370 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4371 drawChooseTreeCursor(y, TRUE);
4372 drawChooseTreeInfo(ti->cl_first + y, ti);
4378 if (game_status == GAME_MODE_SETUP)
4380 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4381 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4382 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4384 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4385 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4386 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4387 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4388 execSetupGraphics();
4389 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4390 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4391 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4393 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4394 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4395 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4396 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4397 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4398 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4399 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4400 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4409 TreeInfo *node_first, *node_cursor;
4410 int entry_pos = ti->cl_first + y;
4412 PlaySound(SND_MENU_ITEM_SELECTING);
4414 node_first = getTreeInfoFirstGroupEntry(ti);
4415 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4417 if (node_cursor->node_group)
4421 node_cursor->cl_first = ti->cl_first;
4422 node_cursor->cl_cursor = ti->cl_cursor;
4423 *ti_ptr = node_cursor->node_group;
4424 DrawChooseTree(ti_ptr);
4426 else if (node_cursor->parent_link)
4430 *ti_ptr = node_cursor->node_parent;
4431 DrawChooseTree(ti_ptr);
4437 node_cursor->cl_first = ti->cl_first;
4438 node_cursor->cl_cursor = ti->cl_cursor;
4439 *ti_ptr = node_cursor;
4441 if (ti->type == TREE_TYPE_LEVEL_DIR)
4443 LoadLevelSetup_SeriesInfo();
4445 SaveLevelSetup_LastSeries();
4446 SaveLevelSetup_SeriesInfo();
4450 if (game_status == GAME_MODE_SETUP)
4452 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4453 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4454 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4456 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4457 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4458 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4459 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4460 execSetupGraphics();
4461 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4462 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4463 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4465 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4466 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4467 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4468 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4469 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4470 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4471 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4472 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4479 if (game_status == GAME_MODE_LEVELNR)
4481 int new_level_nr = atoi(level_number_current->identifier);
4483 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4486 SetGameStatus(GAME_MODE_MAIN);
4495 void DrawChooseLevelSet(void)
4497 FadeMenuSoundsAndMusic();
4499 DrawChooseTree(&leveldir_current);
4501 PlayMenuSoundsAndMusic();
4504 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4506 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4509 void DrawChooseLevelNr(void)
4513 FadeMenuSoundsAndMusic();
4515 if (level_number != NULL)
4517 freeTreeInfo(level_number);
4519 level_number = NULL;
4522 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4524 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4525 char identifier[32], name[32];
4528 /* temporarily load level info to get level name */
4529 LoadLevelInfoOnly(i);
4531 ti->node_top = &level_number;
4532 ti->sort_priority = 10000 + value;
4533 ti->color = (level.no_level_file ? FC_BLUE :
4534 LevelStats_getSolved(i) ? FC_GREEN :
4535 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4537 snprintf(identifier, sizeof(identifier), "%d", value);
4538 snprintf(name, sizeof(name), "%03d: %s", value,
4539 (level.no_level_file ? "(no file)" : level.name));
4541 setString(&ti->identifier, identifier);
4542 setString(&ti->name, name);
4543 setString(&ti->name_sorting, name);
4545 pushTreeInfo(&level_number, ti);
4548 /* sort level number values to start with lowest level number */
4549 sortTreeInfo(&level_number);
4551 /* set current level number to current level number */
4552 level_number_current =
4553 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4555 /* if that also fails, set current level number to first available level */
4556 if (level_number_current == NULL)
4557 level_number_current = level_number;
4559 DrawChooseTree(&level_number_current);
4561 PlayMenuSoundsAndMusic();
4564 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4566 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4569 void DrawHallOfFame(int level_nr, int highlight_position)
4571 int fade_mask = REDRAW_FIELD;
4573 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4574 fade_mask = REDRAW_ALL;
4577 FadeMenuSoundsAndMusic();
4579 /* (this is needed when called from GameEnd() after winning a game) */
4580 KeyboardAutoRepeatOn();
4582 /* (this is needed when called from GameEnd() after winning a game) */
4583 SetDrawDeactivationMask(REDRAW_NONE);
4584 SetDrawBackgroundMask(REDRAW_FIELD);
4586 if (highlight_position < 0)
4587 LoadScore(level_nr);
4589 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4591 FadeSetEnterScreen();
4595 /* needed if different viewport properties defined for scores */
4596 ChangeViewportPropertiesIfNeeded();
4598 PlayMenuSoundsAndMusic();
4600 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4602 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4604 DrawMaskedBorder(fade_mask);
4609 static void drawHallOfFameList(int level_nr, int first_entry,
4610 int highlight_position)
4614 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4617 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4618 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4619 "HighScores of Level %d", level_nr);
4621 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4623 int entry = first_entry + i;
4624 boolean active = (entry == highlight_position);
4625 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4626 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4627 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4628 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4629 int dxoff = getFontDrawOffsetX(font_nr1);
4630 int dx1 = 3 * getFontWidth(font_nr1);
4631 int dx2 = dx1 + getFontWidth(font_nr1);
4632 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4633 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4634 int sy = mSY + 64 + i * 32;
4636 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4637 DrawText(mSX + dx1, sy, ".", font_nr1);
4639 for (j = 0; j < num_dots; j++)
4640 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4642 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4643 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4645 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4648 redraw_mask |= REDRAW_FIELD;
4651 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4653 static int level_nr = 0;
4654 static int first_entry = 0;
4655 static int highlight_position = 0;
4656 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4658 if (button == MB_MENU_INITIALIZE)
4662 highlight_position = my;
4664 drawHallOfFameList(level_nr, first_entry, highlight_position);
4669 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4670 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4674 if (first_entry > 0)
4676 first_entry -= step;
4677 if (first_entry < 0)
4680 drawHallOfFameList(level_nr, first_entry, highlight_position);
4685 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4687 first_entry += step;
4688 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4689 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4691 drawHallOfFameList(level_nr, first_entry, highlight_position);
4694 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4696 PlaySound(SND_MENU_ITEM_SELECTING);
4698 FadeSound(SND_BACKGROUND_SCORES);
4700 if (game_status_last_screen == GAME_MODE_PLAYING &&
4701 setup.auto_play_next_level && setup.increment_levels &&
4704 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4708 SetGameStatus(GAME_MODE_MAIN);
4714 if (game_status == GAME_MODE_SCORES)
4715 PlayMenuSoundIfLoop();
4719 /* ========================================================================= */
4720 /* setup screen functions */
4721 /* ========================================================================= */
4723 static struct TokenInfo *setup_info;
4724 static int num_setup_info; /* number of setup entries shown on screen */
4725 static int max_setup_info; /* total number of setup entries in list */
4727 static char *window_size_text;
4728 static char *scaling_type_text;
4729 static char *rendering_mode_text;
4730 static char *vsync_mode_text;
4731 static char *scroll_delay_text;
4732 static char *snapshot_mode_text;
4733 static char *game_speed_text;
4734 static char *network_server_text;
4735 static char *graphics_set_name;
4736 static char *sounds_set_name;
4737 static char *music_set_name;
4738 static char *volume_simple_text;
4739 static char *volume_loops_text;
4740 static char *volume_music_text;
4741 static char *touch_controls_text;
4742 static char *move_distance_text;
4743 static char *drop_distance_text;
4744 static char *transparency_text;
4745 static char *grid_size_text[2][2];
4747 static void execSetupMain(void)
4749 setup_mode = SETUP_MODE_MAIN;
4754 static void execSetupGame_setGameSpeeds(void)
4756 if (game_speeds == NULL)
4760 for (i = 0; game_speeds_list[i].value != -1; i++)
4762 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4763 char identifier[32], name[32];
4764 int value = game_speeds_list[i].value;
4765 char *text = game_speeds_list[i].text;
4767 ti->node_top = &game_speeds;
4768 ti->sort_priority = 10000 - value;
4770 sprintf(identifier, "%d", value);
4771 sprintf(name, "%s", text);
4773 setString(&ti->identifier, identifier);
4774 setString(&ti->name, name);
4775 setString(&ti->name_sorting, name);
4776 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4778 pushTreeInfo(&game_speeds, ti);
4781 /* sort game speed values to start with slowest game speed */
4782 sortTreeInfo(&game_speeds);
4784 /* set current game speed to configured game speed value */
4785 game_speed_current =
4786 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4788 /* if that fails, set current game speed to reliable default value */
4789 if (game_speed_current == NULL)
4790 game_speed_current =
4791 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4793 /* if that also fails, set current game speed to first available speed */
4794 if (game_speed_current == NULL)
4795 game_speed_current = game_speeds;
4798 setup.game_frame_delay = atoi(game_speed_current->identifier);
4800 /* needed for displaying game speed text instead of identifier */
4801 game_speed_text = game_speed_current->name;
4804 static void execSetupGame_setScrollDelays(void)
4806 if (scroll_delays == NULL)
4810 for (i = 0; scroll_delays_list[i].value != -1; i++)
4812 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4813 char identifier[32], name[32];
4814 int value = scroll_delays_list[i].value;
4815 char *text = scroll_delays_list[i].text;
4817 ti->node_top = &scroll_delays;
4818 ti->sort_priority = value;
4820 sprintf(identifier, "%d", value);
4821 sprintf(name, "%s", text);
4823 setString(&ti->identifier, identifier);
4824 setString(&ti->name, name);
4825 setString(&ti->name_sorting, name);
4826 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4828 pushTreeInfo(&scroll_delays, ti);
4831 /* sort scroll delay values to start with lowest scroll delay value */
4832 sortTreeInfo(&scroll_delays);
4834 /* set current scroll delay value to configured scroll delay value */
4835 scroll_delay_current =
4836 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4838 /* if that fails, set current scroll delay to reliable default value */
4839 if (scroll_delay_current == NULL)
4840 scroll_delay_current =
4841 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4843 /* if that also fails, set current scroll delay to first available value */
4844 if (scroll_delay_current == NULL)
4845 scroll_delay_current = scroll_delays;
4848 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4850 /* needed for displaying scroll delay text instead of identifier */
4851 scroll_delay_text = scroll_delay_current->name;
4854 static void execSetupGame_setSnapshotModes(void)
4856 if (snapshot_modes == NULL)
4860 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4862 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4863 char identifier[32], name[32];
4864 char *value = snapshot_modes_list[i].value;
4865 char *text = snapshot_modes_list[i].text;
4867 ti->node_top = &snapshot_modes;
4868 ti->sort_priority = i;
4870 sprintf(identifier, "%s", value);
4871 sprintf(name, "%s", text);
4873 setString(&ti->identifier, identifier);
4874 setString(&ti->name, name);
4875 setString(&ti->name_sorting, name);
4876 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4878 pushTreeInfo(&snapshot_modes, ti);
4881 /* sort snapshot mode values to start with lowest snapshot mode value */
4882 sortTreeInfo(&snapshot_modes);
4884 /* set current snapshot mode value to configured snapshot mode value */
4885 snapshot_mode_current =
4886 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4888 /* if that fails, set current snapshot mode to reliable default value */
4889 if (snapshot_mode_current == NULL)
4890 snapshot_mode_current =
4891 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4893 /* if that also fails, set current snapshot mode to first available value */
4894 if (snapshot_mode_current == NULL)
4895 snapshot_mode_current = snapshot_modes;
4898 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4900 /* needed for displaying snapshot mode text instead of identifier */
4901 snapshot_mode_text = snapshot_mode_current->name;
4904 static void execSetupGame_setNetworkServerText(void)
4906 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
4908 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
4912 strncpy(network_server_hostname, setup.network_server_hostname,
4913 MAX_SETUP_TEXT_INPUT_LEN);
4914 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
4917 /* needed for displaying network server text instead of identifier */
4918 network_server_text = network_server_hostname;
4921 static void execSetupGame(void)
4923 execSetupGame_setGameSpeeds();
4924 execSetupGame_setScrollDelays();
4925 execSetupGame_setSnapshotModes();
4927 execSetupGame_setNetworkServerText();
4929 setup_mode = SETUP_MODE_GAME;
4934 static void execSetupChooseGameSpeed(void)
4936 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4941 static void execSetupChooseScrollDelay(void)
4943 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4948 static void execSetupChooseSnapshotMode(void)
4950 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4955 static void execSetupEditor(void)
4957 setup_mode = SETUP_MODE_EDITOR;
4962 static void execSetupGraphics_setWindowSizes(boolean update_list)
4964 if (window_sizes != NULL && update_list)
4966 freeTreeInfo(window_sizes);
4968 window_sizes = NULL;
4971 if (window_sizes == NULL)
4973 boolean current_window_size_found = FALSE;
4976 for (i = 0; window_sizes_list[i].value != -1; i++)
4978 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4979 char identifier[32], name[32];
4980 int value = window_sizes_list[i].value;
4981 char *text = window_sizes_list[i].text;
4983 ti->node_top = &window_sizes;
4984 ti->sort_priority = value;
4986 sprintf(identifier, "%d", value);
4987 sprintf(name, "%s", text);
4989 setString(&ti->identifier, identifier);
4990 setString(&ti->name, name);
4991 setString(&ti->name_sorting, name);
4992 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4994 pushTreeInfo(&window_sizes, ti);
4996 if (value == setup.window_scaling_percent)
4997 current_window_size_found = TRUE;
5000 if (!current_window_size_found)
5002 // add entry for non-preset window scaling value
5004 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5005 char identifier[32], name[32];
5006 int value = setup.window_scaling_percent;
5008 ti->node_top = &window_sizes;
5009 ti->sort_priority = value;
5011 sprintf(identifier, "%d", value);
5012 sprintf(name, "%d %% (Current)", value);
5014 setString(&ti->identifier, identifier);
5015 setString(&ti->name, name);
5016 setString(&ti->name_sorting, name);
5017 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5019 pushTreeInfo(&window_sizes, ti);
5022 /* sort window size values to start with lowest window size value */
5023 sortTreeInfo(&window_sizes);
5025 /* set current window size value to configured window size value */
5026 window_size_current =
5027 getTreeInfoFromIdentifier(window_sizes,
5028 i_to_a(setup.window_scaling_percent));
5030 /* if that fails, set current window size to reliable default value */
5031 if (window_size_current == NULL)
5032 window_size_current =
5033 getTreeInfoFromIdentifier(window_sizes,
5034 i_to_a(STD_WINDOW_SCALING_PERCENT));
5036 /* if that also fails, set current window size to first available value */
5037 if (window_size_current == NULL)
5038 window_size_current = window_sizes;
5041 setup.window_scaling_percent = atoi(window_size_current->identifier);
5043 /* needed for displaying window size text instead of identifier */
5044 window_size_text = window_size_current->name;
5047 static void execSetupGraphics_setScalingTypes(void)
5049 if (scaling_types == NULL)
5053 for (i = 0; scaling_types_list[i].value != NULL; i++)
5055 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5056 char identifier[32], name[32];
5057 char *value = scaling_types_list[i].value;
5058 char *text = scaling_types_list[i].text;
5060 ti->node_top = &scaling_types;
5061 ti->sort_priority = i;
5063 sprintf(identifier, "%s", value);
5064 sprintf(name, "%s", text);
5066 setString(&ti->identifier, identifier);
5067 setString(&ti->name, name);
5068 setString(&ti->name_sorting, name);
5069 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5071 pushTreeInfo(&scaling_types, ti);
5074 /* sort scaling type values to start with lowest scaling type value */
5075 sortTreeInfo(&scaling_types);
5077 /* set current scaling type value to configured scaling type value */
5078 scaling_type_current =
5079 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5081 /* if that fails, set current scaling type to reliable default value */
5082 if (scaling_type_current == NULL)
5083 scaling_type_current =
5084 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5086 /* if that also fails, set current scaling type to first available value */
5087 if (scaling_type_current == NULL)
5088 scaling_type_current = scaling_types;
5091 setup.window_scaling_quality = scaling_type_current->identifier;
5093 /* needed for displaying scaling type text instead of identifier */
5094 scaling_type_text = scaling_type_current->name;
5097 static void execSetupGraphics_setRenderingModes(void)
5099 if (rendering_modes == NULL)
5103 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5105 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5106 char identifier[32], name[32];
5107 char *value = rendering_modes_list[i].value;
5108 char *text = rendering_modes_list[i].text;
5110 ti->node_top = &rendering_modes;
5111 ti->sort_priority = i;
5113 sprintf(identifier, "%s", value);
5114 sprintf(name, "%s", text);
5116 setString(&ti->identifier, identifier);
5117 setString(&ti->name, name);
5118 setString(&ti->name_sorting, name);
5119 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5121 pushTreeInfo(&rendering_modes, ti);
5124 /* sort rendering mode values to start with lowest rendering mode value */
5125 sortTreeInfo(&rendering_modes);
5127 /* set current rendering mode value to configured rendering mode value */
5128 rendering_mode_current =
5129 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5131 /* if that fails, set current rendering mode to reliable default value */
5132 if (rendering_mode_current == NULL)
5133 rendering_mode_current =
5134 getTreeInfoFromIdentifier(rendering_modes,
5135 STR_SPECIAL_RENDERING_DEFAULT);
5137 /* if that also fails, set current rendering mode to first available one */
5138 if (rendering_mode_current == NULL)
5139 rendering_mode_current = rendering_modes;
5142 setup.screen_rendering_mode = rendering_mode_current->identifier;
5144 /* needed for displaying rendering mode text instead of identifier */
5145 rendering_mode_text = rendering_mode_current->name;
5148 static void execSetupGraphics_setVsyncModes(void)
5150 if (vsync_modes == NULL)
5154 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5156 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5157 char identifier[32], name[32];
5158 char *value = vsync_modes_list[i].value;
5159 char *text = vsync_modes_list[i].text;
5161 ti->node_top = &vsync_modes;
5162 ti->sort_priority = i;
5164 sprintf(identifier, "%s", value);
5165 sprintf(name, "%s", text);
5167 setString(&ti->identifier, identifier);
5168 setString(&ti->name, name);
5169 setString(&ti->name_sorting, name);
5170 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5172 pushTreeInfo(&vsync_modes, ti);
5175 /* sort vsync mode values to start with lowest vsync mode value */
5176 sortTreeInfo(&vsync_modes);
5178 /* set current vsync mode value to configured vsync mode value */
5179 vsync_mode_current =
5180 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5182 /* if that fails, set current vsync mode to reliable default value */
5183 if (vsync_mode_current == NULL)
5184 vsync_mode_current =
5185 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5187 /* if that also fails, set current vsync mode to first available one */
5188 if (vsync_mode_current == NULL)
5189 vsync_mode_current = vsync_modes;
5192 setup.vsync_mode = vsync_mode_current->identifier;
5194 /* needed for displaying vsync mode text instead of identifier */
5195 vsync_mode_text = vsync_mode_current->name;
5198 static void execSetupGraphics(void)
5200 // update "setup.window_scaling_percent" from list selection
5201 // (in this case, window scaling was changed on setup screen)
5202 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5203 execSetupGraphics_setWindowSizes(FALSE);
5205 // update list selection from "setup.window_scaling_percent"
5206 // (window scaling may have changed by resizing the window)
5207 execSetupGraphics_setWindowSizes(TRUE);
5209 execSetupGraphics_setScalingTypes();
5210 execSetupGraphics_setRenderingModes();
5211 execSetupGraphics_setVsyncModes();
5213 setup_mode = SETUP_MODE_GRAPHICS;
5217 #if defined(TARGET_SDL2)
5218 // window scaling may have changed at this point
5219 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5221 // window scaling quality may have changed at this point
5222 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5223 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5225 // screen rendering mode may have changed at this point
5226 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5228 // screen vsync mode may have changed at this point
5229 SDLSetScreenVsyncMode(setup.vsync_mode);
5233 static void execSetupChooseWindowSize(void)
5235 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5240 static void execSetupChooseScalingType(void)
5242 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5247 static void execSetupChooseRenderingMode(void)
5249 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5254 static void execSetupChooseVsyncMode(void)
5256 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5261 static void execSetupChooseVolumeSimple(void)
5263 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5268 static void execSetupChooseVolumeLoops(void)
5270 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5275 static void execSetupChooseVolumeMusic(void)
5277 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5282 static void execSetupSound(void)
5284 if (volumes_simple == NULL)
5286 boolean current_volume_simple_found = FALSE;
5289 for (i = 0; volumes_list[i].value != -1; i++)
5291 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5292 char identifier[32], name[32];
5293 int value = volumes_list[i].value;
5294 char *text = volumes_list[i].text;
5296 ti->node_top = &volumes_simple;
5297 ti->sort_priority = value;
5299 sprintf(identifier, "%d", value);
5300 sprintf(name, "%s", text);
5302 setString(&ti->identifier, identifier);
5303 setString(&ti->name, name);
5304 setString(&ti->name_sorting, name);
5305 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5307 pushTreeInfo(&volumes_simple, ti);
5309 if (value == setup.volume_simple)
5310 current_volume_simple_found = TRUE;
5313 if (!current_volume_simple_found)
5315 // add entry for non-preset volume value
5317 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5318 char identifier[32], name[32];
5319 int value = setup.volume_simple;
5321 ti->node_top = &volumes_simple;
5322 ti->sort_priority = value;
5324 sprintf(identifier, "%d", value);
5325 sprintf(name, "%d %% (Current)", value);
5327 setString(&ti->identifier, identifier);
5328 setString(&ti->name, name);
5329 setString(&ti->name_sorting, name);
5330 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5332 pushTreeInfo(&volumes_simple, ti);
5335 /* sort volume values to start with lowest volume value */
5336 sortTreeInfo(&volumes_simple);
5338 /* set current volume value to configured volume value */
5339 volume_simple_current =
5340 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5342 /* if that fails, set current volume to reliable default value */
5343 if (volume_simple_current == NULL)
5344 volume_simple_current =
5345 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5347 /* if that also fails, set current volume to first available value */
5348 if (volume_simple_current == NULL)
5349 volume_simple_current = volumes_simple;
5352 if (volumes_loops == NULL)
5354 boolean current_volume_loops_found = FALSE;
5357 for (i = 0; volumes_list[i].value != -1; i++)
5359 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5360 char identifier[32], name[32];
5361 int value = volumes_list[i].value;
5362 char *text = volumes_list[i].text;
5364 ti->node_top = &volumes_loops;
5365 ti->sort_priority = value;
5367 sprintf(identifier, "%d", value);
5368 sprintf(name, "%s", text);
5370 setString(&ti->identifier, identifier);
5371 setString(&ti->name, name);
5372 setString(&ti->name_sorting, name);
5373 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5375 pushTreeInfo(&volumes_loops, ti);
5377 if (value == setup.volume_loops)
5378 current_volume_loops_found = TRUE;
5381 if (!current_volume_loops_found)
5383 // add entry for non-preset volume value
5385 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5386 char identifier[32], name[32];
5387 int value = setup.volume_loops;
5389 ti->node_top = &volumes_loops;
5390 ti->sort_priority = value;
5392 sprintf(identifier, "%d", value);
5393 sprintf(name, "%d %% (Current)", value);
5395 setString(&ti->identifier, identifier);
5396 setString(&ti->name, name);
5397 setString(&ti->name_sorting, name);
5398 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5400 pushTreeInfo(&volumes_loops, ti);
5403 /* sort volume values to start with lowest volume value */
5404 sortTreeInfo(&volumes_loops);
5406 /* set current volume value to configured volume value */
5407 volume_loops_current =
5408 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5410 /* if that fails, set current volume to reliable default value */
5411 if (volume_loops_current == NULL)
5412 volume_loops_current =
5413 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5415 /* if that also fails, set current volume to first available value */
5416 if (volume_loops_current == NULL)
5417 volume_loops_current = volumes_loops;
5420 if (volumes_music == NULL)
5422 boolean current_volume_music_found = FALSE;
5425 for (i = 0; volumes_list[i].value != -1; i++)
5427 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5428 char identifier[32], name[32];
5429 int value = volumes_list[i].value;
5430 char *text = volumes_list[i].text;
5432 ti->node_top = &volumes_music;
5433 ti->sort_priority = value;
5435 sprintf(identifier, "%d", value);
5436 sprintf(name, "%s", text);
5438 setString(&ti->identifier, identifier);
5439 setString(&ti->name, name);
5440 setString(&ti->name_sorting, name);
5441 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5443 pushTreeInfo(&volumes_music, ti);
5445 if (value == setup.volume_music)
5446 current_volume_music_found = TRUE;
5449 if (!current_volume_music_found)
5451 // add entry for non-preset volume value
5453 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5454 char identifier[32], name[32];
5455 int value = setup.volume_music;
5457 ti->node_top = &volumes_music;
5458 ti->sort_priority = value;
5460 sprintf(identifier, "%d", value);
5461 sprintf(name, "%d %% (Current)", value);
5463 setString(&ti->identifier, identifier);
5464 setString(&ti->name, name);
5465 setString(&ti->name_sorting, name);
5466 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5468 pushTreeInfo(&volumes_music, ti);
5471 /* sort volume values to start with lowest volume value */
5472 sortTreeInfo(&volumes_music);
5474 /* set current volume value to configured volume value */
5475 volume_music_current =
5476 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5478 /* if that fails, set current volume to reliable default value */
5479 if (volume_music_current == NULL)
5480 volume_music_current =
5481 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5483 /* if that also fails, set current volume to first available value */
5484 if (volume_music_current == NULL)
5485 volume_music_current = volumes_music;
5488 setup.volume_simple = atoi(volume_simple_current->identifier);
5489 setup.volume_loops = atoi(volume_loops_current->identifier);
5490 setup.volume_music = atoi(volume_music_current->identifier);
5492 /* needed for displaying volume text instead of identifier */
5493 volume_simple_text = volume_simple_current->name;
5494 volume_loops_text = volume_loops_current->name;
5495 volume_music_text = volume_music_current->name;
5497 setup_mode = SETUP_MODE_SOUND;
5502 static void execSetupChooseTouchControls(void)
5504 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5509 static void execSetupChooseMoveDistance(void)
5511 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5516 static void execSetupChooseDropDistance(void)
5518 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5523 static void execSetupChooseTransparency(void)
5525 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5530 static void execSetupChooseGridXSize_0(void)
5532 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5537 static void execSetupChooseGridYSize_0(void)
5539 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5544 static void execSetupChooseGridXSize_1(void)
5546 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5551 static void execSetupChooseGridYSize_1(void)
5553 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5558 static void execSetupConfigureVirtualButtons(void)
5560 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5562 ConfigureVirtualButtons();
5564 setup_mode = SETUP_MODE_TOUCH;
5569 static void execSetupTouch(void)
5573 if (touch_controls == NULL)
5575 for (i = 0; touch_controls_list[i].value != NULL; i++)
5577 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5578 char identifier[32], name[32];
5579 char *value = touch_controls_list[i].value;
5580 char *text = touch_controls_list[i].text;
5582 ti->node_top = &touch_controls;
5583 ti->sort_priority = i;
5585 sprintf(identifier, "%s", value);
5586 sprintf(name, "%s", text);
5588 setString(&ti->identifier, identifier);
5589 setString(&ti->name, name);
5590 setString(&ti->name_sorting, name);
5591 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5593 pushTreeInfo(&touch_controls, ti);
5596 /* sort touch control values to start with lowest touch control value */
5597 sortTreeInfo(&touch_controls);
5599 /* set current touch control value to configured touch control value */
5600 touch_control_current =
5601 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5603 /* if that fails, set current touch control to reliable default value */
5604 if (touch_control_current == NULL)
5605 touch_control_current =
5606 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5608 /* if that also fails, set current touch control to first available value */
5609 if (touch_control_current == NULL)
5610 touch_control_current = touch_controls;
5613 if (move_distances == NULL)
5615 for (i = 0; distances_list[i].value != -1; i++)
5617 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5618 char identifier[32], name[32];
5619 int value = distances_list[i].value;
5620 char *text = distances_list[i].text;
5622 ti->node_top = &move_distances;
5623 ti->sort_priority = value;
5625 sprintf(identifier, "%d", value);
5626 sprintf(name, "%s", text);
5628 setString(&ti->identifier, identifier);
5629 setString(&ti->name, name);
5630 setString(&ti->name_sorting, name);
5631 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5633 pushTreeInfo(&move_distances, ti);
5636 /* sort distance values to start with lowest distance value */
5637 sortTreeInfo(&move_distances);
5639 /* set current distance value to configured distance value */
5640 move_distance_current =
5641 getTreeInfoFromIdentifier(move_distances,
5642 i_to_a(setup.touch.move_distance));
5644 /* if that fails, set current distance to reliable default value */
5645 if (move_distance_current == NULL)
5646 move_distance_current =
5647 getTreeInfoFromIdentifier(move_distances,
5648 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5650 /* if that also fails, set current distance to first available value */
5651 if (move_distance_current == NULL)
5652 move_distance_current = move_distances;
5655 if (drop_distances == NULL)
5657 for (i = 0; distances_list[i].value != -1; i++)
5659 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5660 char identifier[32], name[32];
5661 int value = distances_list[i].value;
5662 char *text = distances_list[i].text;
5664 ti->node_top = &drop_distances;
5665 ti->sort_priority = value;
5667 sprintf(identifier, "%d", value);
5668 sprintf(name, "%s", text);
5670 setString(&ti->identifier, identifier);
5671 setString(&ti->name, name);
5672 setString(&ti->name_sorting, name);
5673 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5675 pushTreeInfo(&drop_distances, ti);
5678 /* sort distance values to start with lowest distance value */
5679 sortTreeInfo(&drop_distances);
5681 /* set current distance value to configured distance value */
5682 drop_distance_current =
5683 getTreeInfoFromIdentifier(drop_distances,
5684 i_to_a(setup.touch.drop_distance));
5686 /* if that fails, set current distance to reliable default value */
5687 if (drop_distance_current == NULL)
5688 drop_distance_current =
5689 getTreeInfoFromIdentifier(drop_distances,
5690 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5692 /* if that also fails, set current distance to first available value */
5693 if (drop_distance_current == NULL)
5694 drop_distance_current = drop_distances;
5697 if (transparencies == NULL)
5699 for (i = 0; transparencies_list[i].value != -1; i++)
5701 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5702 char identifier[32], name[32];
5703 int value = transparencies_list[i].value;
5704 char *text = transparencies_list[i].text;
5706 ti->node_top = &transparencies;
5707 ti->sort_priority = value;
5709 sprintf(identifier, "%d", value);
5710 sprintf(name, "%s", text);
5712 setString(&ti->identifier, identifier);
5713 setString(&ti->name, name);
5714 setString(&ti->name_sorting, name);
5715 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5717 pushTreeInfo(&transparencies, ti);
5720 /* sort transparency values to start with lowest transparency value */
5721 sortTreeInfo(&transparencies);
5723 /* set current transparency value to configured transparency value */
5724 transparency_current =
5725 getTreeInfoFromIdentifier(transparencies,
5726 i_to_a(setup.touch.transparency));
5728 /* if that fails, set current transparency to reliable default value */
5729 if (transparency_current == NULL)
5730 transparency_current =
5731 getTreeInfoFromIdentifier(transparencies,
5732 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5734 /* if that also fails, set current transparency to first available value */
5735 if (transparency_current == NULL)
5736 transparency_current = transparencies;
5739 for (i = 0; i < 2; i++)
5741 for (j = 0; j < 2; j++)
5743 if (grid_sizes[i][j] == NULL)
5745 for (k = 0; grid_sizes_list[k].value != -1; k++)
5747 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5748 char identifier[32], name[32];
5749 int value = grid_sizes_list[k].value;
5750 char *text = grid_sizes_list[k].text;
5752 ti->node_top = &grid_sizes[i][j];
5753 ti->sort_priority = value;
5755 sprintf(identifier, "%d", value);
5756 sprintf(name, "%s", text);
5758 setString(&ti->identifier, identifier);
5759 setString(&ti->name, name);
5760 setString(&ti->name_sorting, name);
5761 setString(&ti->infotext,
5764 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5765 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5767 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5768 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5770 pushTreeInfo(&grid_sizes[i][j], ti);
5773 /* sort grid size values to start with lowest grid size value */
5774 sortTreeInfo(&grid_sizes[i][j]);
5776 /* set current grid size value to configured grid size value */
5777 grid_size_current[i][j] =
5778 getTreeInfoFromIdentifier(grid_sizes[i][j],
5780 setup.touch.grid_xsize[i] :
5781 setup.touch.grid_ysize[i]));
5783 /* if that fails, set current grid size to reliable default value */
5784 if (grid_size_current[i][j] == NULL)
5785 grid_size_current[i][j] =
5786 getTreeInfoFromIdentifier(grid_sizes[i][j],
5788 DEFAULT_GRID_XSIZE(i) :
5789 DEFAULT_GRID_YSIZE(i)));
5791 /* if that also fails, set current grid size to first available value */
5792 if (grid_size_current[i][j] == NULL)
5793 grid_size_current[i][j] = grid_sizes[i][j];
5798 setup.touch.control_type = touch_control_current->identifier;
5799 setup.touch.move_distance = atoi(move_distance_current->identifier);
5800 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5801 setup.touch.transparency = atoi(transparency_current->identifier);
5803 for (i = 0; i < 2; i++)
5805 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5806 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5808 if (i == GRID_ACTIVE_NR())
5810 overlay.grid_xsize = setup.touch.grid_xsize[i];
5811 overlay.grid_ysize = setup.touch.grid_ysize[i];
5815 /* needed for displaying value text instead of identifier */
5816 touch_controls_text = touch_control_current->name;
5817 move_distance_text = move_distance_current->name;
5818 drop_distance_text = drop_distance_current->name;
5819 transparency_text = transparency_current->name;
5821 for (i = 0; i < 2; i++)
5822 for (j = 0; j < 2; j++)
5823 grid_size_text[i][j] = grid_size_current[i][j]->name;
5825 setup_mode = SETUP_MODE_TOUCH;
5830 static void execSetupArtwork(void)
5833 printf("::: '%s', '%s', '%s'\n",
5834 artwork.gfx_current->subdir,
5835 artwork.gfx_current->fullpath,
5836 artwork.gfx_current->basepath);
5839 setup.graphics_set = artwork.gfx_current->identifier;
5840 setup.sounds_set = artwork.snd_current->identifier;
5841 setup.music_set = artwork.mus_current->identifier;
5843 /* needed if last screen (setup choice) changed graphics, sounds or music */
5844 ReloadCustomArtwork(0);
5846 /* needed for displaying artwork name instead of artwork identifier */
5847 graphics_set_name = artwork.gfx_current->name;
5848 sounds_set_name = artwork.snd_current->name;
5849 music_set_name = artwork.mus_current->name;
5851 setup_mode = SETUP_MODE_ARTWORK;
5856 static void execSetupChooseGraphics(void)
5858 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5863 static void execSetupChooseSounds(void)
5865 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5870 static void execSetupChooseMusic(void)
5872 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5877 static void execSetupInput(void)
5879 setup_mode = SETUP_MODE_INPUT;
5884 static void execSetupShortcuts(void)
5886 setup_mode = SETUP_MODE_SHORTCUTS;
5891 static void execSetupShortcuts1(void)
5893 setup_mode = SETUP_MODE_SHORTCUTS_1;
5898 static void execSetupShortcuts2(void)
5900 setup_mode = SETUP_MODE_SHORTCUTS_2;
5905 static void execSetupShortcuts3(void)
5907 setup_mode = SETUP_MODE_SHORTCUTS_3;
5912 static void execSetupShortcuts4(void)
5914 setup_mode = SETUP_MODE_SHORTCUTS_4;
5919 static void execSetupShortcuts5(void)
5921 setup_mode = SETUP_MODE_SHORTCUTS_5;
5926 static void execExitSetup(void)
5928 SetGameStatus(GAME_MODE_MAIN);
5933 static void execSaveAndExitSetup(void)
5939 static void execGadgetNetworkServer(void)
5941 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
5942 struct GadgetInfo *gi = screen_gadget[gadget_id];
5944 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5945 network_server_hostname[0] = '\0';
5947 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
5951 ClickOnGadget(gi, MB_LEFTBUTTON);
5954 static void ToggleNetworkModeIfNeeded(void)
5956 int font_title = FONT_TITLE_1;
5957 int font_foot = FC_BLUE;
5958 int ystart = mSY - SY + 16;
5959 int ybottom = mSY - SY + SYSIZE - 20;
5960 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
5962 if (setup.network_mode == network.enabled)
5965 network.enabled = setup.network_mode;
5967 FadeOut(REDRAW_ALL);
5971 DrawTextSCentered(ystart, font_title, text);
5975 if (network.enabled)
5976 InitNetworkServer();
5978 DisconnectFromNetworkServer();
5980 DrawTextSCentered(ybottom, font_foot,
5981 "Press any key or button for setup menu");
5983 WaitForEventToContinue();
5991 void *related_value;
5992 } hide_related_entry_list[] =
5994 { &setup.game_frame_delay, execSetupChooseGameSpeed },
5995 { &setup.game_frame_delay, &game_speed_text },
5997 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
5998 { &setup.scroll_delay_value, &scroll_delay_text },
6000 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6001 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6003 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6004 { &setup.window_scaling_percent, &window_size_text },
6006 { &setup.window_scaling_quality, execSetupChooseScalingType },
6007 { &setup.window_scaling_quality, &scaling_type_text },
6009 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6010 { &setup.screen_rendering_mode, &rendering_mode_text },
6012 { &setup.vsync_mode, execSetupChooseVsyncMode },
6013 { &setup.vsync_mode, &vsync_mode_text },
6015 { &setup.graphics_set, execSetupChooseGraphics },
6016 { &setup.graphics_set, &graphics_set_name },
6018 { &setup.sounds_set, execSetupChooseSounds },
6019 { &setup.sounds_set, &sounds_set_name },
6021 { &setup.music_set, execSetupChooseMusic },
6022 { &setup.music_set, &music_set_name },
6024 { &setup.volume_simple, execSetupChooseVolumeSimple },
6025 { &setup.volume_simple, &volume_simple_text },
6027 { &setup.volume_loops, execSetupChooseVolumeLoops },
6028 { &setup.volume_loops, &volume_loops_text },
6030 { &setup.volume_music, execSetupChooseVolumeMusic },
6031 { &setup.volume_music, &volume_music_text },
6033 { &setup.touch.control_type, execSetupChooseTouchControls },
6034 { &setup.touch.control_type, &touch_controls_text },
6036 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6037 { &setup.touch.move_distance, &move_distance_text },
6039 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6040 { &setup.touch.drop_distance, &drop_distance_text },
6042 { &setup.touch.transparency, execSetupChooseTransparency },
6043 { &setup.touch.transparency, &transparency_text },
6045 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6046 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6048 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6049 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6051 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6052 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6054 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6055 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6060 void setHideRelatedSetupEntries(void)
6064 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6065 if (hideSetupEntry(hide_related_entry_list[i].value))
6066 setHideSetupEntry(hide_related_entry_list[i].related_value);
6069 static struct TokenInfo setup_info_main[] =
6071 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6072 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6073 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6074 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6075 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6076 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6077 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6078 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6079 { TYPE_EMPTY, NULL, "" },
6080 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6081 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6086 static struct TokenInfo setup_info_game[] =
6088 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6089 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6090 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6091 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6092 { TYPE_STRING, &network_server_text, "" },
6093 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6094 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6095 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6096 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6097 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6098 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6099 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
6100 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6101 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6102 { TYPE_STRING, &game_speed_text, "" },
6104 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6105 { TYPE_STRING, &scroll_delay_text, "" },
6107 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6108 { TYPE_STRING, &snapshot_mode_text, "" },
6109 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6110 { TYPE_EMPTY, NULL, "" },
6111 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6116 static struct TokenInfo setup_info_editor[] =
6119 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6120 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6121 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6122 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6123 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6124 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6125 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6126 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6127 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6128 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6130 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6131 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6133 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6135 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6136 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6137 { TYPE_EMPTY, NULL, "" },
6139 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6140 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6141 { TYPE_EMPTY, NULL, "" },
6143 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6144 { TYPE_EMPTY, NULL, "" },
6145 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6150 static struct TokenInfo setup_info_graphics[] =
6152 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
6153 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6154 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6155 { TYPE_STRING, &window_size_text, "" },
6156 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6157 { TYPE_STRING, &scaling_type_text, "" },
6158 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6159 { TYPE_STRING, &rendering_mode_text, "" },
6162 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6163 { TYPE_STRING, &scroll_delay_text, "" },
6165 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6166 { TYPE_STRING, &vsync_mode_text, "" },
6167 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6168 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6169 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6170 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6171 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6172 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
6173 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
6174 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6175 { TYPE_EMPTY, NULL, "" },
6176 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6181 static struct TokenInfo setup_info_sound[] =
6183 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6184 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6185 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6186 { TYPE_EMPTY, NULL, "" },
6187 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6188 { TYPE_STRING, &volume_simple_text, "" },
6189 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6190 { TYPE_STRING, &volume_loops_text, "" },
6191 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6192 { TYPE_STRING, &volume_music_text, "" },
6193 { TYPE_EMPTY, NULL, "" },
6194 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6199 static struct TokenInfo setup_info_artwork[] =
6201 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6202 { TYPE_STRING, &graphics_set_name, "" },
6203 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6204 { TYPE_STRING, &sounds_set_name, "" },
6205 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6206 { TYPE_STRING, &music_set_name, "" },
6207 { TYPE_EMPTY, NULL, "" },
6208 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6209 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6210 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6211 { TYPE_EMPTY, NULL, "" },
6212 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6217 static struct TokenInfo setup_info_input[] =
6219 { TYPE_SWITCH, NULL, "Player:" },
6220 { TYPE_SWITCH, NULL, "Device:" },
6221 { TYPE_SWITCH, NULL, "" },
6222 { TYPE_SKIPPABLE, NULL, "" },
6223 { TYPE_EMPTY, NULL, "" },
6224 { TYPE_EMPTY, NULL, "" },
6225 { TYPE_EMPTY, NULL, "" },
6226 { TYPE_EMPTY, NULL, "" },
6227 { TYPE_EMPTY, NULL, "" },
6228 { TYPE_EMPTY, NULL, "" },
6229 { TYPE_EMPTY, NULL, "" },
6230 { TYPE_EMPTY, NULL, "" },
6231 { TYPE_SKIPPABLE, NULL, "" },
6232 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6237 static struct TokenInfo setup_info_touch[] =
6239 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6240 { TYPE_STRING, &touch_controls_text, "" },
6241 { TYPE_EMPTY, NULL, "" },
6242 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6247 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6249 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6250 { TYPE_STRING, &touch_controls_text, "" },
6251 { TYPE_EMPTY, NULL, "" },
6252 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6253 { TYPE_STRING, &grid_size_text[0][0], "" },
6254 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6255 { TYPE_STRING, &grid_size_text[0][1], "" },
6256 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6257 { TYPE_STRING, &transparency_text, "" },
6258 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6259 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6260 { TYPE_EMPTY, NULL, "" },
6261 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6262 { TYPE_EMPTY, NULL, "" },
6263 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6268 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6270 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6271 { TYPE_STRING, &touch_controls_text, "" },
6272 { TYPE_EMPTY, NULL, "" },
6273 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6274 { TYPE_STRING, &grid_size_text[1][0], "" },
6275 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6276 { TYPE_STRING, &grid_size_text[1][1], "" },
6277 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6278 { TYPE_STRING, &transparency_text, "" },
6279 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6280 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6281 { TYPE_EMPTY, NULL, "" },
6282 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6283 { TYPE_EMPTY, NULL, "" },
6284 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6289 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6291 setup_info_touch_virtual_buttons_0,
6292 setup_info_touch_virtual_buttons_1
6295 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6297 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6298 { TYPE_STRING, &touch_controls_text, "" },
6299 { TYPE_EMPTY, NULL, "" },
6300 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6301 { TYPE_STRING, &move_distance_text, "" },
6302 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6303 { TYPE_STRING, &drop_distance_text, "" },
6304 { TYPE_EMPTY, NULL, "" },
6305 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6310 static struct TokenInfo setup_info_shortcuts[] =
6312 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6313 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6314 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6315 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6316 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6317 { TYPE_EMPTY, NULL, "" },
6318 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6323 static struct TokenInfo setup_info_shortcuts_1[] =
6325 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6326 { TYPE_KEY, &setup.shortcut.save_game, "" },
6327 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6328 { TYPE_KEY, &setup.shortcut.load_game, "" },
6329 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6330 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6331 { TYPE_EMPTY, NULL, "" },
6332 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6333 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6334 { TYPE_EMPTY, NULL, "" },
6335 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6340 static struct TokenInfo setup_info_shortcuts_2[] =
6342 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6343 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6344 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6345 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6346 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6347 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6348 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6349 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6350 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6351 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6352 { TYPE_EMPTY, NULL, "" },
6353 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6358 static struct TokenInfo setup_info_shortcuts_3[] =
6360 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6361 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6362 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6363 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6364 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6365 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6366 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6367 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6368 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6369 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6370 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6371 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6372 { TYPE_EMPTY, NULL, "" },
6373 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6378 static struct TokenInfo setup_info_shortcuts_4[] =
6380 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6381 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6382 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6383 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6384 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6385 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6386 { TYPE_EMPTY, NULL, "" },
6387 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6392 static struct TokenInfo setup_info_shortcuts_5[] =
6394 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6395 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6396 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6397 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6398 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6399 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6400 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6401 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6402 { TYPE_EMPTY, NULL, "" },
6403 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6408 static Key getSetupKey(void)
6410 Key key = KSYM_UNDEFINED;
6411 boolean got_key_event = FALSE;
6413 while (!got_key_event)
6417 if (NextValidEvent(&event))
6421 case EVENT_KEYPRESS:
6423 key = GetEventKey((KeyEvent *)&event, TRUE);
6425 /* press 'Escape' or 'Enter' to keep the existing key binding */
6426 if (key == KSYM_Escape || key == KSYM_Return)
6427 key = KSYM_UNDEFINED; /* keep old value */
6429 got_key_event = TRUE;
6433 case EVENT_KEYRELEASE:
6434 key_joystick_mapping = 0;
6438 HandleOtherEvents(&event);
6449 static int getSetupValueFont(int type, void *value)
6451 if (type & TYPE_GHOSTED)
6452 return FONT_OPTION_OFF;
6453 else if (type & TYPE_KEY)
6454 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6455 else if (type & TYPE_STRING)
6456 return FONT_VALUE_2;
6457 else if (type & TYPE_ECS_AGA)
6458 return FONT_VALUE_1;
6459 else if (type & TYPE_BOOLEAN_STYLE)
6460 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6461 else if (type & TYPE_YES_NO_AUTO)
6462 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6463 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6464 else if (type & TYPE_PLAYER)
6465 return FONT_VALUE_1;
6467 return FONT_VALUE_1;
6470 static int getSetupValueFontNarrow(int type, int font_nr)
6472 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6473 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6474 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6478 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6480 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6481 struct TokenInfo *si = &setup_info[si_pos];
6482 boolean font_draw_xoffset_modified = FALSE;
6483 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6484 int font_draw_xoffset_old = -1;
6485 int xoffset = (scrollbar_needed ? -1 : 0);
6486 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6487 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6488 int xpos = menu_screen_value_xpos;
6489 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6490 int startx = mSX + xpos * 32;
6491 int starty = mSY + ypos * 32;
6492 int font_nr, font_nr_default, font_width_default;
6493 int type = si->type;
6494 void *value = si->value;
6495 char *value_string = getSetupValue(type, value);
6498 if (value_string == NULL)
6501 if (type & TYPE_KEY)
6503 xpos = MENU_SCREEN_START_XPOS;
6505 if (type & TYPE_QUERY)
6506 value_string = "<press key>";
6508 else if (type & TYPE_STRING)
6510 int max_value_len = (SCR_FIELDX - 2) * 2;
6512 xpos = MENU_SCREEN_START_XPOS;
6514 if (strlen(value_string) > max_value_len)
6515 value_string[max_value_len] = '\0';
6517 else if (type & TYPE_YES_NO_AUTO)
6519 xpos = menu_screen_value_xpos - 1;
6521 else if (type & TYPE_PLAYER)
6523 int displayed_player_nr = *(int *)value + 1;
6525 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6528 startx = mSX + xpos * 32;
6529 starty = mSY + ypos * 32;
6530 font_nr_default = getSetupValueFont(type, value);
6531 font_width_default = getFontWidth(font_nr_default);
6533 font_nr = font_nr_default;
6535 // special check if right-side setup values moved left due to scrollbar
6536 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6538 int max_menu_text_length = 26; // maximum text length for classic menu
6539 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6540 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6541 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6542 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6543 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6545 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6548 startx = mSX + xpos * 32;
6550 font_nr = getSetupValueFontNarrow(type, font_nr);
6554 /* downward compatibility correction for Juergen Bonhagen's menu settings */
6555 if (setup_mode != SETUP_MODE_INPUT)
6557 int max_menu_text_length_big = (menu_screen_value_xpos -
6558 MENU_SCREEN_START_XPOS);
6559 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6560 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
6561 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6562 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6563 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6564 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6565 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6566 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6567 boolean correct_font_draw_xoffset = FALSE;
6569 if (xpos == MENU_SCREEN_START_XPOS &&
6570 startx + font1_xoffset < text_startx + text_font_xoffset)
6571 correct_font_draw_xoffset = TRUE;
6573 if (xpos == menu_screen_value_xpos &&
6574 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6575 correct_font_draw_xoffset = TRUE;
6577 /* check if setup value would overlap with setup text when printed */
6578 /* (this can happen for extreme/wrong values for font draw offset) */
6579 if (correct_font_draw_xoffset)
6581 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6582 font_draw_xoffset_modified = TRUE;
6584 if (type & TYPE_KEY)
6585 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6586 else if (!(type & TYPE_STRING))
6587 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6588 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6592 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6593 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6595 DrawText(startx, starty, value_string, font_nr);
6597 if (type & TYPE_PLAYER)
6599 int player_nr = *(int *)value;
6600 int xoff = getFontWidth(font_nr);
6602 DrawFixedGraphicThruMaskExt(drawto, startx + xoff, starty,
6603 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6606 if (font_draw_xoffset_modified)
6607 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6610 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6612 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6613 struct TokenInfo *si = &setup_info[si_pos];
6615 if (si->type & TYPE_BOOLEAN_STYLE)
6617 *(boolean *)si->value ^= TRUE;
6619 else if (si->type & TYPE_YES_NO_AUTO)
6623 (*(int *)si->value == AUTO ? TRUE :
6624 *(int *)si->value == TRUE ? FALSE : AUTO) :
6625 (*(int *)si->value == TRUE ? AUTO :
6626 *(int *)si->value == AUTO ? FALSE : TRUE));
6628 else if (si->type & TYPE_KEY)
6632 si->type |= TYPE_QUERY;
6633 drawSetupValue(screen_pos, setup_info_pos_raw);
6634 si->type &= ~TYPE_QUERY;
6636 key = getSetupKey();
6637 if (key != KSYM_UNDEFINED)
6638 *(Key *)si->value = key;
6640 else if (si->type & TYPE_PLAYER)
6642 int player_nr = *(int *)si->value;
6647 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6649 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6652 drawSetupValue(screen_pos, setup_info_pos_raw);
6654 // fullscreen state may have changed at this point
6655 if (si->value == &setup.fullscreen)
6656 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6658 // network mode may have changed at this point
6659 if (si->value == &setup.network_mode)
6660 ToggleNetworkModeIfNeeded();
6663 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6665 static struct TokenInfo *setup_info_final = NULL;
6670 /* determine maximum list size of target list */
6671 while (setup_info_orig[list_size++].type != 0);
6673 /* free, allocate and clear memory for target list */
6674 checked_free(setup_info_final);
6675 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6677 /* copy setup info list without setup entries marked as hidden */
6678 for (i = 0; setup_info_orig[i].type != 0; i++)
6680 /* skip setup entries configured to be hidden */
6681 if (hideSetupEntry(setup_info_orig[i].value))
6684 /* skip skippable setup entries if screen is lower than usual */
6685 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6686 setup_info_orig[i].type == TYPE_SKIPPABLE)
6689 setup_info_final[list_pos++] = setup_info_orig[i];
6692 return setup_info_final;
6695 static void DrawSetupScreen_Generic(void)
6697 int fade_mask = REDRAW_FIELD;
6698 boolean redraw_all = FALSE;
6699 char *title_string = NULL;
6702 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
6703 fade_mask = REDRAW_ALL;
6706 FadeMenuSoundsAndMusic();
6708 FreeScreenGadgets();
6709 CreateScreenGadgets();
6711 if (redraw_mask & REDRAW_ALL)
6716 /* needed if different viewport properties defined for setup screen */
6717 ChangeViewportPropertiesIfNeeded();
6719 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6723 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6725 if (setup_mode == SETUP_MODE_MAIN)
6727 setup_info = setup_info_main;
6728 title_string = STR_SETUP_MAIN;
6730 else if (setup_mode == SETUP_MODE_GAME)
6732 setup_info = setup_info_game;
6733 title_string = STR_SETUP_GAME;
6735 else if (setup_mode == SETUP_MODE_EDITOR)
6737 setup_info = setup_info_editor;
6738 title_string = STR_SETUP_EDITOR;
6740 else if (setup_mode == SETUP_MODE_GRAPHICS)
6742 setup_info = setup_info_graphics;
6743 title_string = STR_SETUP_GRAPHICS;
6745 else if (setup_mode == SETUP_MODE_SOUND)
6747 setup_info = setup_info_sound;
6748 title_string = STR_SETUP_SOUND;
6750 else if (setup_mode == SETUP_MODE_ARTWORK)
6752 setup_info = setup_info_artwork;
6753 title_string = STR_SETUP_ARTWORK;
6755 else if (setup_mode == SETUP_MODE_TOUCH)
6757 setup_info = setup_info_touch;
6758 title_string = STR_SETUP_TOUCH;
6760 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6761 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6762 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6763 setup_info = setup_info_touch_wipe_gestures;
6765 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6767 setup_info = setup_info_shortcuts;
6768 title_string = STR_SETUP_SHORTCUTS;
6770 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6772 setup_info = setup_info_shortcuts_1;
6773 title_string = STR_SETUP_SHORTCUTS;
6775 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6777 setup_info = setup_info_shortcuts_2;
6778 title_string = STR_SETUP_SHORTCUTS;
6780 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6782 setup_info = setup_info_shortcuts_3;
6783 title_string = STR_SETUP_SHORTCUTS;
6785 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6787 setup_info = setup_info_shortcuts_4;
6788 title_string = STR_SETUP_SHORTCUTS;
6790 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6792 setup_info = setup_info_shortcuts_5;
6793 title_string = STR_SETUP_SHORTCUTS;
6796 /* use modified setup info without setup entries marked as hidden */
6797 setup_info = getSetupInfoFinal(setup_info);
6799 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6801 // determine maximal number of setup entries that can be displayed on screen
6803 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6806 // determine maximal number of setup entries available for this setup screen
6808 for (i = 0; setup_info[i].type != 0; i++)
6811 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6813 MapScreenGadgets(max_setup_info);
6816 redraw_mask = fade_mask = REDRAW_ALL;
6818 DrawMaskedBorder(fade_mask);
6823 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6825 menu_info = setup_info;
6827 HandleMenuScreen(mx, my, dx, dy, button,
6828 setup_mode, num_setup_info, max_setup_info);
6831 static void DrawSetupScreen_Input(void)
6835 FadeOut(REDRAW_FIELD);
6839 setup_info = getSetupInfoFinal(setup_info_input);
6841 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6843 for (i = 0; setup_info[i].type != 0; i++)
6845 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6846 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6847 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6848 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6849 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6850 initCursor(i, IMG_MENU_BUTTON);
6852 DrawCursorAndText_Setup(i, -1, FALSE);
6855 /* create gadgets for setup input menu screen */
6856 FreeScreenGadgets();
6857 CreateScreenGadgets();
6859 /* map gadgets for setup input menu screen */
6860 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6862 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6864 FadeIn(REDRAW_FIELD);
6867 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6869 if (device_name == NULL)
6872 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6875 if (strlen(device_name) > 1)
6877 char c1 = device_name[strlen(device_name) - 1];
6878 char c2 = device_name[strlen(device_name) - 2];
6880 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6881 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6884 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6885 strlen(device_name));
6888 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6891 static struct SetupKeyboardInfo custom_key;
6898 { &custom_key.left, "Axis/Pad Left" },
6899 { &custom_key.right, "Axis/Pad Right" },
6900 { &custom_key.up, "Axis/Pad Up" },
6901 { &custom_key.down, "Axis/Pad Down" },
6902 { &custom_key.snap, "Button 1/A/X" },
6903 { &custom_key.drop, "Button 2/B/Y" }
6905 static char *joystick_name[MAX_PLAYERS] =
6912 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6913 int font_nr_info = FONT_MENU_1;
6914 int font_nr_name = FONT_VALUE_OLD;
6915 int font_nr_on = FONT_VALUE_1;
6916 int font_nr_off = FONT_VALUE_OLD;
6919 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6921 font_nr_info = FONT_MENU_2;
6922 font_nr_on = FONT_VALUE_NARROW;
6923 font_nr_off = FONT_VALUE_OLD_NARROW;
6926 custom_key = setup.input[player_nr].key;
6928 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6929 FONT_INPUT_1_ACTIVE);
6931 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6933 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6934 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6936 if (setup.input[player_nr].use_joystick)
6938 char *device_name = setup.input[player_nr].joy.device_name;
6939 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6940 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6941 char *text = joystick_name[joystick_nr];
6942 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
6944 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6945 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
6949 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
6950 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
6953 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
6954 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
6958 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
6959 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
6960 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
6961 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
6963 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
6964 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
6965 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
6966 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
6967 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
6968 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
6970 for (i = 0; i < 6; i++)
6972 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
6974 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6976 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6977 (setup.input[player_nr].use_joystick ?
6979 getKeyNameFromKey(*custom[i].key)), font_nr_on);
6983 static int input_player_nr = 0;
6985 static void HandleSetupScreen_Input_Player(int step, int direction)
6987 int old_player_nr = input_player_nr;
6990 new_player_nr = old_player_nr + step * direction;
6991 if (new_player_nr < 0)
6993 if (new_player_nr > MAX_PLAYERS - 1)
6994 new_player_nr = MAX_PLAYERS - 1;
6996 if (new_player_nr != old_player_nr)
6998 input_player_nr = new_player_nr;
7000 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7004 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7006 static int choice = 0;
7009 int pos_start = SETUPINPUT_SCREEN_POS_START;
7010 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7011 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7012 int pos_end = SETUPINPUT_SCREEN_POS_END;
7014 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7018 for (i = 0; setup_info_input[i].type != 0; i++)
7020 /* adjust menu structure according to skipped setup entries */
7021 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7029 if (button == MB_MENU_INITIALIZE)
7031 /* input setup menu may have changed size due to graphics configuration */
7032 if (choice >= pos_empty1)
7035 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7037 DrawCursorAndText_Setup(choice, -1, TRUE);
7041 else if (button == MB_MENU_LEAVE)
7043 setup_mode = SETUP_MODE_MAIN;
7050 if (mx || my) /* mouse input */
7052 x = (mx - mSX) / 32;
7053 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7055 else if (dx || dy) /* keyboard input */
7057 if (dx && choice == 0)
7058 x = (dx < 0 ? 10 : 12);
7059 else if ((dx && choice == 1) ||
7060 (dx == -1 && choice == pos_end))
7061 button = MB_MENU_CHOICE;
7065 if (y >= pos_empty1 && y <= pos_empty2)
7066 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7069 if (y == 0 && dx != 0 && button)
7071 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7073 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7074 y >= pos_start && y <= pos_end &&
7075 !(y >= pos_empty1 && y <= pos_empty2))
7081 DrawCursorAndText_Setup(choice, -1, FALSE);
7082 DrawCursorAndText_Setup(y, -1, TRUE);
7084 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7093 char *device_name = setup.input[input_player_nr].joy.device_name;
7095 if (!setup.input[input_player_nr].use_joystick)
7097 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7099 setJoystickDeviceToNr(device_name, new_device_nr);
7100 setup.input[input_player_nr].use_joystick = TRUE;
7104 int device_nr = getJoystickNrFromDeviceName(device_name);
7105 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7107 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7108 setup.input[input_player_nr].use_joystick = FALSE;
7110 setJoystickDeviceToNr(device_name, new_device_nr);
7113 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7117 if (setup.input[input_player_nr].use_joystick)
7118 ConfigureJoystick(input_player_nr);
7120 CustomizeKeyboard(input_player_nr);
7122 else if (y == pos_end)
7128 setup_mode = SETUP_MODE_MAIN;
7135 static boolean CustomizeKeyboardMain(int player_nr)
7139 boolean finished = FALSE;
7140 static struct SetupKeyboardInfo custom_key;
7145 } customize_step[] =
7147 { &custom_key.left, "Move Left" },
7148 { &custom_key.right, "Move Right" },
7149 { &custom_key.up, "Move Up" },
7150 { &custom_key.down, "Move Down" },
7151 { &custom_key.snap, "Snap Field" },
7152 { &custom_key.drop, "Drop Element" }
7154 int font_nr_old = FONT_VALUE_OLD;
7155 int font_nr_new = FONT_VALUE_1;
7156 boolean success = FALSE;
7158 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7160 font_nr_old = FONT_VALUE_OLD_NARROW;
7161 font_nr_new = FONT_VALUE_NARROW;
7164 /* read existing key bindings from player setup */
7165 custom_key = setup.input[player_nr].key;
7168 FadeOut(REDRAW_FIELD);
7172 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7175 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7176 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7177 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7178 "Key:", FONT_INPUT_1_ACTIVE);
7179 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7180 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7182 FadeIn(REDRAW_FIELD);
7188 if (NextValidEvent(&event))
7192 case EVENT_KEYPRESS:
7194 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7196 /* press 'Escape' to abort and keep the old key bindings */
7197 if (key == KSYM_Escape)
7199 FadeSkipNextFadeIn();
7206 /* press 'Enter' to keep the existing key binding */
7207 if (key == KSYM_Return)
7208 key = *customize_step[step_nr].key;
7210 /* check if key already used */
7211 for (i = 0; i < step_nr; i++)
7212 if (*customize_step[i].key == key)
7217 /* got new key binding */
7218 *customize_step[step_nr].key = key;
7219 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7221 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7222 getKeyNameFromKey(key), font_nr_new);
7225 /* un-highlight last query */
7226 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7227 customize_step[step_nr - 1].text, FONT_MENU_1);
7228 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7229 "Key:", FONT_MENU_1);
7231 /* all keys configured */
7240 /* query next key binding */
7241 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7242 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7243 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7244 "Key:", FONT_INPUT_1_ACTIVE);
7245 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7246 getKeyNameFromKey(*customize_step[step_nr].key),
7251 case EVENT_KEYRELEASE:
7252 key_joystick_mapping = 0;
7256 HandleOtherEvents(&event);
7264 /* write new key bindings back to player setup, if successfully finished */
7266 setup.input[player_nr].key = custom_key;
7271 void CustomizeKeyboard(int player_nr)
7273 boolean success = CustomizeKeyboardMain(player_nr);
7277 int font_nr = FONT_TITLE_1;
7278 int font_height = getFontHeight(font_nr);
7279 int ypos1 = SYSIZE / 2 - font_height * 2;
7280 int ypos2 = SYSIZE / 2 - font_height * 1;
7281 unsigned int wait_frame_delay = 0;
7282 unsigned int wait_frame_delay_value = 2000;
7284 ResetDelayCounter(&wait_frame_delay);
7288 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7289 DrawTextSCentered(ypos2, font_nr, "configured!");
7291 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7297 DrawSetupScreen_Input();
7300 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
7302 #define MARKER_BUTTON 1
7303 #define MARKER_AXIS_X 2
7304 #define MARKER_AXIS_Y 3
7306 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7308 #if defined(TARGET_SDL2)
7309 static boolean bitmaps_initialized = FALSE;
7310 boolean screen_initialized = FALSE;
7311 static Bitmap *controller, *button, *axis_x, *axis_y;
7313 boolean success = TRUE;
7314 boolean done = FALSE, next = FALSE;
7316 int alpha = 200, alpha_step = -1;
7317 int alpha_ticks = 0;
7318 char mapping[4096], temp[4096];
7319 int font_name = MENU_SETUP_FONT_TITLE;
7320 int font_info = MENU_SETUP_FONT_TEXT;
7321 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7322 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7323 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7324 int ystep_name = getMenuTextStep(spacing_name, font_name);
7325 int ystep_line = getMenuTextStep(spacing_line, font_info);
7326 int ystep_para = getMenuTextStep(spacing_para, font_info);
7334 int axis, button, hat, hat_value;
7337 *step, *prev_step, steps[] =
7339 { 356, 155, MARKER_BUTTON, "a", },
7340 { 396, 122, MARKER_BUTTON, "b", },
7341 { 320, 125, MARKER_BUTTON, "x", },
7342 { 358, 95, MARKER_BUTTON, "y", },
7343 { 162, 125, MARKER_BUTTON, "back", },
7344 { 216, 125, MARKER_BUTTON, "guide", },
7345 { 271, 125, MARKER_BUTTON, "start", },
7346 { 110, 200, MARKER_BUTTON, "dpleft", },
7347 { 146, 228, MARKER_BUTTON, "dpdown", },
7348 { 178, 200, MARKER_BUTTON, "dpright", },
7349 { 146, 172, MARKER_BUTTON, "dpup", },
7350 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7351 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7352 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7353 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7354 { 73, 141, MARKER_BUTTON, "leftstick", },
7355 { 282, 210, MARKER_BUTTON, "rightstick", },
7356 { 73, 141, MARKER_AXIS_X, "leftx", },
7357 { 73, 141, MARKER_AXIS_Y, "lefty", },
7358 { 282, 210, MARKER_AXIS_X, "rightx", },
7359 { 282, 210, MARKER_AXIS_Y, "righty", },
7362 unsigned int event_frame_delay = 0;
7363 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7365 ResetDelayCounter(&event_frame_delay);
7367 if (!bitmaps_initialized)
7369 controller = LoadCustomImage("joystick/controller.png");
7370 button = LoadCustomImage("joystick/button.png");
7371 axis_x = LoadCustomImage("joystick/axis_x.png");
7372 axis_y = LoadCustomImage("joystick/axis_y.png");
7374 bitmaps_initialized = TRUE;
7377 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7380 /* print info about the joystick we are watching */
7381 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7382 SDL_JoystickInstanceID(joystick), name);
7383 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7384 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7385 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7388 /* initialize mapping with GUID and name */
7389 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7391 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7392 temp, name, SDL_GetPlatform());
7394 /* loop through all steps (buttons and axes), getting joystick events */
7395 for (i = 0; i < SDL_arraysize(steps) && !done;)
7397 Bitmap *marker = button; /* initialize with reliable default value */
7400 strcpy(step->mapping, mapping);
7404 step->hat_value = -1;
7406 marker = (step->marker == MARKER_BUTTON ? button :
7407 step->marker == MARKER_AXIS_X ? axis_x :
7408 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7412 while (!done && !next)
7414 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7415 alpha_ticks = SDL_GetTicks();
7422 else if (alpha < 128)
7428 int controller_x = SX + (SXSIZE - controller->width) / 2;
7429 int controller_y = SY + ystep_line;
7431 int marker_x = controller_x + step->x;
7432 int marker_y = controller_y + step->y;
7434 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7435 int ystart2 = ystart1 + ystep_name + ystep_line;
7439 DrawTextSCentered(ystart1, font_name, name);
7441 DrawTextSCentered(ystart2, font_info,
7442 "Press buttons and move axes on");
7443 ystart2 += ystep_line;
7444 DrawTextSCentered(ystart2, font_info,
7445 "your controller when indicated.");
7446 ystart2 += ystep_line;
7447 DrawTextSCentered(ystart2, font_info,
7448 "(Your controller may look different.)");
7449 ystart2 += ystep_para;
7451 #if defined(PLATFORM_ANDROID)
7452 DrawTextSCentered(ystart2, font_info,
7453 "To correct a mistake,");
7454 ystart2 += ystep_line;
7455 DrawTextSCentered(ystart2, font_info,
7456 "press the 'back' button.");
7457 ystart2 += ystep_line;
7458 DrawTextSCentered(ystart2, font_info,
7459 "To skip a button or axis,");
7460 ystart2 += ystep_line;
7461 DrawTextSCentered(ystart2, font_info,
7462 "press the 'menu' button.");
7464 DrawTextSCentered(ystart2, font_info,
7465 "To correct a mistake,");
7466 ystart2 += ystep_line;
7467 DrawTextSCentered(ystart2, font_info,
7468 "press the 'backspace' key.");
7469 ystart2 += ystep_line;
7470 DrawTextSCentered(ystart2, font_info,
7471 "To skip a button or axis,");
7472 ystart2 += ystep_line;
7473 DrawTextSCentered(ystart2, font_info,
7474 "press the 'return' key.");
7475 ystart2 += ystep_line;
7476 DrawTextSCentered(ystart2, font_info,
7477 "To exit, press the 'escape' key.");
7480 BlitBitmapMasked(controller, drawto, 0, 0,
7481 controller->width, controller->height,
7482 controller_x, controller_y);
7484 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7485 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7487 BlitBitmapMasked(marker, drawto, 0, 0,
7488 marker->width, marker->height,
7489 marker_x, marker_y);
7491 if (!screen_initialized)
7492 FadeIn(REDRAW_FIELD);
7496 screen_initialized = TRUE;
7498 while (NextValidEvent(&event))
7502 case SDL_JOYAXISMOTION:
7503 if (event.jaxis.value > 20000 ||
7504 event.jaxis.value < -20000)
7506 for (j = 0; j < i; j++)
7507 if (steps[j].axis == event.jaxis.axis)
7512 if (step->marker != MARKER_AXIS_X &&
7513 step->marker != MARKER_AXIS_Y)
7516 step->axis = event.jaxis.axis;
7517 strcat(mapping, step->field);
7518 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7519 strcat(mapping, temp);
7527 case SDL_JOYHATMOTION:
7528 /* ignore centering; we're probably just coming back
7529 to the center from the previous item we set */
7530 if (event.jhat.value == SDL_HAT_CENTERED)
7533 for (j = 0; j < i; j++)
7534 if (steps[j].hat == event.jhat.hat &&
7535 steps[j].hat_value == event.jhat.value)
7540 step->hat = event.jhat.hat;
7541 step->hat_value = event.jhat.value;
7542 strcat(mapping, step->field);
7543 snprintf(temp, sizeof(temp), ":h%u.%u,",
7544 event.jhat.hat, event.jhat.value );
7545 strcat(mapping, temp);
7552 case SDL_JOYBALLMOTION:
7555 case SDL_JOYBUTTONUP:
7556 for (j = 0; j < i; j++)
7557 if (steps[j].button == event.jbutton.button)
7562 step->button = event.jbutton.button;
7563 strcat(mapping, step->field);
7564 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7565 strcat(mapping, temp);
7572 case SDL_FINGERDOWN:
7573 case SDL_MOUSEBUTTONDOWN:
7574 /* skip this step */
7581 if (event.key.keysym.sym == KSYM_BackSpace ||
7582 event.key.keysym.sym == KSYM_Back)
7593 /* undo this step */
7594 prev_step = &steps[i - 1];
7595 strcpy(mapping, prev_step->mapping);
7602 if (event.key.keysym.sym == KSYM_space ||
7603 event.key.keysym.sym == KSYM_Return ||
7604 event.key.keysym.sym == KSYM_Menu)
7606 /* skip this step */
7613 if (event.key.keysym.sym == KSYM_Escape)
7623 program.exit_function(0);
7630 // do not handle events for longer than standard frame delay period
7631 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7640 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7643 // activate mapping for this game
7644 SDL_GameControllerAddMapping(mapping);
7646 // save mapping to personal mappings
7647 SaveSetup_AddGameControllerMapping(mapping);
7650 /* wait until the last pending event was removed from event queue */
7651 while (NextValidEvent(&event));
7659 static int ConfigureJoystickMain(int player_nr)
7661 char *device_name = setup.input[player_nr].joy.device_name;
7662 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7663 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7664 int success = FALSE;
7667 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7668 return JOYSTICK_NOT_AVAILABLE;
7670 if (!joystick_active || !setup.input[player_nr].use_joystick)
7671 return JOYSTICK_NOT_AVAILABLE;
7674 FadeOut(REDRAW_FIELD);
7676 // close all joystick devices (potentially opened as game controllers)
7677 for (i = 0; i < SDL_NumJoysticks(); i++)
7678 SDLCloseJoystick(i);
7680 // open joystick device as plain joystick to configure as game controller
7681 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7683 // as the joystick was successfully opened before, this should not happen
7684 if (joystick == NULL)
7687 // create new game controller mapping (buttons and axes) for joystick device
7688 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7690 // close joystick (and maybe re-open as configured game controller later)
7691 SDL_JoystickClose(joystick);
7693 // re-open all joystick devices (potentially as game controllers)
7694 for (i = 0; i < SDL_NumJoysticks(); i++)
7697 // clear all joystick input actions for all joystick devices
7698 SDLClearJoystickState();
7700 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7703 void ConfigureJoystick(int player_nr)
7705 boolean state = ConfigureJoystickMain(player_nr);
7707 if (state != JOYSTICK_NOT_CONFIGURED)
7709 boolean success = (state == JOYSTICK_CONFIGURED);
7710 char message1[MAX_OUTPUT_LINESIZE + 1];
7711 char *message2 = (success ? "configured!" : "not available!");
7712 char *device_name = setup.input[player_nr].joy.device_name;
7713 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7714 int font_nr = FONT_TITLE_1;
7715 int font_height = getFontHeight(font_nr);
7716 int ypos1 = SYSIZE / 2 - font_height * 2;
7717 int ypos2 = SYSIZE / 2 - font_height * 1;
7718 unsigned int wait_frame_delay = 0;
7719 unsigned int wait_frame_delay_value = 2000;
7721 ResetDelayCounter(&wait_frame_delay);
7725 sprintf(message1, "Joystick %d", nr);
7727 DrawTextSCentered(ypos1, font_nr, message1);
7728 DrawTextSCentered(ypos2, font_nr, message2);
7730 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7736 DrawSetupScreen_Input();
7739 static boolean ConfigureVirtualButtonsMain(void)
7741 static char *customize_step_text[] =
7750 char grid_button[] =
7752 CHAR_GRID_BUTTON_LEFT,
7753 CHAR_GRID_BUTTON_RIGHT,
7754 CHAR_GRID_BUTTON_UP,
7755 CHAR_GRID_BUTTON_DOWN,
7756 CHAR_GRID_BUTTON_SNAP,
7757 CHAR_GRID_BUTTON_DROP
7759 int font_nr = FONT_INPUT_1_ACTIVE;
7760 int font_height = getFontHeight(font_nr);
7761 int ypos1 = SYSIZE / 2 - font_height * 2;
7762 int ypos2 = SYSIZE / 2 - font_height * 1;
7763 boolean success = FALSE;
7764 boolean finished = FALSE;
7766 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7767 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7768 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7769 boolean set_grid_button = FALSE;
7770 int nr = GRID_ACTIVE_NR();
7773 for (x = 0; x < MAX_GRID_XSIZE; x++)
7774 for (y = 0; y < MAX_GRID_YSIZE; y++)
7775 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7777 overlay.grid_button_highlight = grid_button[step_nr];
7780 FadeOut(REDRAW_FIELD);
7784 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7785 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7786 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7788 FadeIn(REDRAW_FIELD);
7790 SetOverlayShowGrid(TRUE);
7796 while (NextValidEvent(&event))
7800 case EVENT_KEYPRESS:
7802 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7804 /* press 'Escape' to abort and keep the old key bindings */
7805 if (key == KSYM_Escape)
7807 for (x = 0; x < MAX_GRID_XSIZE; x++)
7808 for (y = 0; y < MAX_GRID_YSIZE; y++)
7809 overlay.grid_button[x][y] = grid_button_old[x][y];
7811 FadeSkipNextFadeIn();
7818 /* press 'Enter' to keep the existing key binding */
7819 if (key == KSYM_Return ||
7820 #if defined(TARGET_SDL2)
7827 else if (key == KSYM_BackSpace
7828 #if defined(TARGET_SDL2)
7836 FadeSkipNextFadeIn();
7850 /* all virtual buttons configured */
7859 for (x = 0; x < MAX_GRID_XSIZE; x++)
7860 for (y = 0; y < MAX_GRID_YSIZE; y++)
7861 grid_button_tmp[x][y] = overlay.grid_button[x][y];
7863 overlay.grid_button_highlight = grid_button[step_nr];
7865 /* query next virtual button */
7869 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7870 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7871 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7875 case EVENT_KEYRELEASE:
7876 key_joystick_mapping = 0;
7879 case EVENT_BUTTONPRESS:
7880 case EVENT_BUTTONRELEASE:
7882 ButtonEvent *button = (ButtonEvent *)&event;
7884 button->x += video.screen_xoffset;
7885 button->y += video.screen_yoffset;
7887 x = button->x * overlay.grid_xsize / video.screen_width;
7888 y = button->y * overlay.grid_ysize / video.screen_height;
7890 if (button->type == EVENT_BUTTONPRESS)
7892 button_status = button->button;
7895 (overlay.grid_button[x][y] != grid_button[step_nr] ?
7896 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
7898 set_grid_button = TRUE;
7902 button_status = MB_RELEASED;
7907 case EVENT_MOTIONNOTIFY:
7909 MotionEvent *motion = (MotionEvent *)&event;
7911 motion->x += video.screen_xoffset;
7912 motion->y += video.screen_yoffset;
7914 x = motion->x * overlay.grid_xsize / video.screen_width;
7915 y = motion->y * overlay.grid_ysize / video.screen_height;
7917 set_grid_button = TRUE;
7921 #if defined(TARGET_SDL2)
7922 case SDL_WINDOWEVENT:
7923 HandleWindowEvent((WindowEvent *) &event);
7925 // check if device has been rotated
7926 if (nr != GRID_ACTIVE_NR())
7928 nr = GRID_ACTIVE_NR();
7930 for (x = 0; x < MAX_GRID_XSIZE; x++)
7931 for (y = 0; y < MAX_GRID_YSIZE; y++)
7932 grid_button_old[x][y] = grid_button_tmp[x][y] =
7933 overlay.grid_button[x][y];
7938 case SDL_APP_WILLENTERBACKGROUND:
7939 case SDL_APP_DIDENTERBACKGROUND:
7940 case SDL_APP_WILLENTERFOREGROUND:
7941 case SDL_APP_DIDENTERFOREGROUND:
7942 HandlePauseResumeEvent((PauseResumeEvent *) &event);
7947 HandleOtherEvents(&event);
7951 if (set_grid_button)
7953 overlay.grid_button[x][y] =
7954 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
7955 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
7956 grid_button_tmp[x][y]);
7958 set_grid_button = FALSE;
7965 for (x = 0; x < MAX_GRID_XSIZE; x++)
7966 for (y = 0; y < MAX_GRID_YSIZE; y++)
7967 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7969 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
7971 SetOverlayShowGrid(FALSE);
7976 void ConfigureVirtualButtons(void)
7978 boolean success = ConfigureVirtualButtonsMain();
7982 int font_nr = FONT_TITLE_1;
7983 int font_height = getFontHeight(font_nr);
7984 int ypos1 = SYSIZE / 2 - font_height * 2;
7985 int ypos2 = SYSIZE / 2 - font_height * 1;
7986 unsigned int wait_frame_delay = 0;
7987 unsigned int wait_frame_delay_value = 2000;
7989 ResetDelayCounter(&wait_frame_delay);
7993 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
7994 DrawTextSCentered(ypos2, font_nr, "configured!");
7996 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8003 void DrawSetupScreen(void)
8005 if (setup_mode == SETUP_MODE_INPUT)
8006 DrawSetupScreen_Input();
8007 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8008 DrawChooseTree(&game_speed_current);
8009 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8010 DrawChooseTree(&scroll_delay_current);
8011 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8012 DrawChooseTree(&snapshot_mode_current);
8013 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8014 DrawChooseTree(&window_size_current);
8015 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8016 DrawChooseTree(&scaling_type_current);
8017 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8018 DrawChooseTree(&rendering_mode_current);
8019 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8020 DrawChooseTree(&vsync_mode_current);
8021 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8022 DrawChooseTree(&artwork.gfx_current);
8023 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8024 DrawChooseTree(&artwork.snd_current);
8025 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8026 DrawChooseTree(&artwork.mus_current);
8027 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8028 DrawChooseTree(&volume_simple_current);
8029 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8030 DrawChooseTree(&volume_loops_current);
8031 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8032 DrawChooseTree(&volume_music_current);
8033 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8034 DrawChooseTree(&touch_control_current);
8035 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8036 DrawChooseTree(&move_distance_current);
8037 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8038 DrawChooseTree(&drop_distance_current);
8039 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8040 DrawChooseTree(&transparency_current);
8041 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8042 DrawChooseTree(&grid_size_current[0][0]);
8043 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8044 DrawChooseTree(&grid_size_current[0][1]);
8045 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8046 DrawChooseTree(&grid_size_current[1][0]);
8047 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8048 DrawChooseTree(&grid_size_current[1][1]);
8050 DrawSetupScreen_Generic();
8052 PlayMenuSoundsAndMusic();
8055 void RedrawSetupScreenAfterFullscreenToggle(void)
8057 if (setup_mode == SETUP_MODE_GRAPHICS ||
8058 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8060 // update list selection from "setup.window_scaling_percent"
8061 execSetupGraphics_setWindowSizes(TRUE);
8067 void RedrawSetupScreenAfterScreenRotation(int nr)
8071 if (setup_mode == SETUP_MODE_TOUCH)
8073 // update virtual button settings (depending on screen orientation)
8076 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8078 // save already configured virtual buttons
8079 for (x = 0; x < MAX_GRID_XSIZE; x++)
8080 for (y = 0; y < MAX_GRID_YSIZE; y++)
8081 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8085 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8087 if (setup_mode == SETUP_MODE_INPUT)
8088 HandleSetupScreen_Input(mx, my, dx, dy, button);
8089 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8090 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8091 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8092 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8093 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8094 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8095 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8096 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8097 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8098 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8099 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8100 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8101 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8102 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8103 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8104 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8105 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8106 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8107 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8108 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8109 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8110 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8111 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8112 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8113 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8114 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8115 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8116 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8117 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8118 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8119 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8120 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8121 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8122 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8123 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8124 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8125 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8126 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8127 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8128 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8129 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8130 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8132 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8135 void HandleGameActions(void)
8137 if (game.restart_game_message != NULL)
8138 RequestRestartGame(game.restart_game_message);
8140 if (game_status != GAME_MODE_PLAYING)
8143 GameActions(); /* main game loop */
8145 if (tape.auto_play && !tape.playing)
8146 AutoPlayTape(); /* continue automatically playing next tape */
8150 /* ---------- new screen button stuff -------------------------------------- */
8152 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
8156 case SCREEN_CTRL_ID_PREV_LEVEL:
8157 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
8158 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
8161 case SCREEN_CTRL_ID_NEXT_LEVEL:
8162 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
8163 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
8166 case SCREEN_CTRL_ID_PREV_PLAYER:
8167 *x = mSX + TILEX * 10;
8168 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
8171 case SCREEN_CTRL_ID_NEXT_PLAYER:
8172 *x = mSX + TILEX * 12;
8173 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
8176 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8177 *x = mSX + GDI_ACTIVE_POS(menu.main.button.insert_solution.x);
8178 *y = mSY + GDI_ACTIVE_POS(menu.main.button.insert_solution.y);
8181 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8182 *x = mSX + GDI_ACTIVE_POS(menu.main.button.play_solution.x);
8183 *y = mSY + GDI_ACTIVE_POS(menu.main.button.play_solution.y);
8187 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
8193 int gfx_unpressed, gfx_pressed;
8194 void (*get_gadget_position)(int *, int *, int);
8198 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8201 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8202 getScreenMenuButtonPos,
8203 SCREEN_CTRL_ID_PREV_LEVEL,
8208 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8209 getScreenMenuButtonPos,
8210 SCREEN_CTRL_ID_NEXT_LEVEL,
8215 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8216 getScreenMenuButtonPos,
8217 SCREEN_CTRL_ID_PREV_PLAYER,
8222 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8223 getScreenMenuButtonPos,
8224 SCREEN_CTRL_ID_NEXT_PLAYER,
8229 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8230 getScreenMenuButtonPos,
8231 SCREEN_CTRL_ID_INSERT_SOLUTION,
8232 SCREEN_MASK_MAIN_HAS_SOLUTION,
8233 "insert solution tape"
8236 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8237 getScreenMenuButtonPos,
8238 SCREEN_CTRL_ID_PLAY_SOLUTION,
8239 SCREEN_MASK_MAIN_HAS_SOLUTION,
8240 "play solution tape"
8246 int gfx_unpressed, gfx_pressed;
8250 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8253 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8254 -1, -1, /* these values are not constant, but can change at runtime */
8255 SCREEN_CTRL_ID_SCROLL_UP,
8259 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8260 -1, -1, /* these values are not constant, but can change at runtime */
8261 SCREEN_CTRL_ID_SCROLL_DOWN,
8268 int gfx_unpressed, gfx_pressed;
8274 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8277 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8278 -1, -1, /* these values are not constant, but can change at runtime */
8279 -1, -1, /* these values are not constant, but can change at runtime */
8280 GD_TYPE_SCROLLBAR_VERTICAL,
8281 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8282 "scroll level series vertically"
8294 } textinput_info[NUM_SCREEN_TEXTINPUT] =
8297 IMG_SETUP_INPUT_TEXT,
8298 SCREEN_CTRL_ID_NETWORK_SERVER,
8299 -1, -1, /* these values are not constant, but can change at runtime */
8300 MAX_SETUP_TEXT_INPUT_LEN,
8301 network_server_hostname,
8302 "Network Server Hostname / IP"
8306 static void CreateScreenMenubuttons(void)
8308 struct GadgetInfo *gi;
8309 unsigned int event_mask;
8312 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8314 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8315 int gfx_unpressed, gfx_pressed;
8316 int x, y, width, height;
8317 int gd_x1, gd_x2, gd_y1, gd_y2;
8318 int id = menubutton_info[i].gadget_id;
8320 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8321 event_mask = GD_EVENT_RELEASED;
8323 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8325 menubutton_info[i].get_gadget_position(&x, &y, id);
8327 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8329 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8330 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8334 width = SC_MENUBUTTON_XSIZE;
8335 height = SC_MENUBUTTON_YSIZE;
8338 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8339 gfx_pressed = menubutton_info[i].gfx_pressed;
8340 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8341 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8342 gd_x1 = graphic_info[gfx_unpressed].src_x;
8343 gd_y1 = graphic_info[gfx_unpressed].src_y;
8344 gd_x2 = graphic_info[gfx_pressed].src_x;
8345 gd_y2 = graphic_info[gfx_pressed].src_y;
8347 gi = CreateGadget(GDI_CUSTOM_ID, id,
8348 GDI_CUSTOM_TYPE_ID, i,
8349 GDI_IMAGE_ID, gfx_unpressed,
8350 GDI_INFO_TEXT, menubutton_info[i].infotext,
8355 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8356 GDI_STATE, GD_BUTTON_UNPRESSED,
8357 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8358 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8359 GDI_DIRECT_DRAW, FALSE,
8360 GDI_EVENT_MASK, event_mask,
8361 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8365 Error(ERR_EXIT, "cannot create gadget");
8367 screen_gadget[id] = gi;
8371 static void CreateScreenScrollbuttons(void)
8373 struct GadgetInfo *gi;
8374 unsigned int event_mask;
8377 /* these values are not constant, but can change at runtime */
8378 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8379 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8380 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8381 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8383 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8385 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8386 int gfx_unpressed, gfx_pressed;
8387 int x, y, width, height;
8388 int gd_x1, gd_x2, gd_y1, gd_y2;
8389 int id = scrollbutton_info[i].gadget_id;
8391 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8393 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8394 y = mSY + scrollbutton_info[i].y;
8395 width = SC_SCROLLBUTTON_XSIZE;
8396 height = SC_SCROLLBUTTON_YSIZE;
8398 /* correct scrollbar position if placed outside menu (playfield) area */
8399 if (x > SX + SC_SCROLL_UP_XPOS)
8400 x = SX + SC_SCROLL_UP_XPOS;
8402 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8403 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8404 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8406 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8407 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8408 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8409 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8410 gd_x1 = graphic_info[gfx_unpressed].src_x;
8411 gd_y1 = graphic_info[gfx_unpressed].src_y;
8412 gd_x2 = graphic_info[gfx_pressed].src_x;
8413 gd_y2 = graphic_info[gfx_pressed].src_y;
8415 gi = CreateGadget(GDI_CUSTOM_ID, id,
8416 GDI_CUSTOM_TYPE_ID, i,
8417 GDI_IMAGE_ID, gfx_unpressed,
8418 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8423 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8424 GDI_STATE, GD_BUTTON_UNPRESSED,
8425 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8426 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8427 GDI_DIRECT_DRAW, FALSE,
8428 GDI_EVENT_MASK, event_mask,
8429 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8433 Error(ERR_EXIT, "cannot create gadget");
8435 screen_gadget[id] = gi;
8439 static void CreateScreenScrollbars(void)
8443 /* these values are not constant, but can change at runtime */
8444 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8445 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8446 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8447 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8449 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8451 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8452 int gfx_unpressed, gfx_pressed;
8453 int x, y, width, height;
8454 int gd_x1, gd_x2, gd_y1, gd_y2;
8455 struct GadgetInfo *gi;
8456 int items_max, items_visible, item_position;
8457 unsigned int event_mask;
8458 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8459 int id = scrollbar_info[i].gadget_id;
8461 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8463 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8464 y = mSY + scrollbar_info[i].y;
8465 width = scrollbar_info[i].width;
8466 height = scrollbar_info[i].height;
8468 /* correct scrollbar position if placed outside menu (playfield) area */
8469 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8470 x = SX + SC_SCROLL_VERTICAL_XPOS;
8472 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8473 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8475 items_max = num_page_entries;
8476 items_visible = num_page_entries;
8479 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8480 gfx_pressed = scrollbar_info[i].gfx_pressed;
8481 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8482 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8483 gd_x1 = graphic_info[gfx_unpressed].src_x;
8484 gd_y1 = graphic_info[gfx_unpressed].src_y;
8485 gd_x2 = graphic_info[gfx_pressed].src_x;
8486 gd_y2 = graphic_info[gfx_pressed].src_y;
8488 gi = CreateGadget(GDI_CUSTOM_ID, id,
8489 GDI_CUSTOM_TYPE_ID, i,
8490 GDI_IMAGE_ID, gfx_unpressed,
8491 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8496 GDI_TYPE, scrollbar_info[i].type,
8497 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8498 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8499 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8500 GDI_WHEEL_AREA_X, SX,
8501 GDI_WHEEL_AREA_Y, SY,
8502 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8503 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8504 GDI_STATE, GD_BUTTON_UNPRESSED,
8505 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8506 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8507 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8508 GDI_DIRECT_DRAW, FALSE,
8509 GDI_EVENT_MASK, event_mask,
8510 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8514 Error(ERR_EXIT, "cannot create gadget");
8516 screen_gadget[id] = gi;
8520 static void CreateScreenTextInputGadgets(void)
8524 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
8526 int graphic = textinput_info[i].graphic;
8527 struct GraphicInfo *gd = &graphic_info[graphic];
8528 int gd_x1 = gd->src_x;
8529 int gd_y1 = gd->src_y;
8530 int gd_x2 = gd->src_x + gd->active_xoffset;
8531 int gd_y2 = gd->src_y + gd->active_yoffset;
8532 struct GadgetInfo *gi;
8533 unsigned int event_mask;
8534 int id = textinput_info[i].gadget_id;
8535 int x = textinput_info[i].x;
8536 int y = textinput_info[i].y;
8538 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
8540 gi = CreateGadget(GDI_CUSTOM_ID, id,
8541 GDI_CUSTOM_TYPE_ID, i,
8542 GDI_INFO_TEXT, textinput_info[i].infotext,
8545 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
8546 GDI_TEXT_VALUE, textinput_info[i].value,
8547 GDI_TEXT_SIZE, textinput_info[i].size,
8548 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
8549 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
8550 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8551 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8552 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8553 GDI_DESIGN_WIDTH, gd->width,
8554 GDI_EVENT_MASK, event_mask,
8555 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8556 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
8560 Error(ERR_EXIT, "cannot create gadget");
8562 screen_gadget[id] = gi;
8566 void CreateScreenGadgets(void)
8568 CreateScreenMenubuttons();
8570 CreateScreenScrollbuttons();
8571 CreateScreenScrollbars();
8573 CreateScreenTextInputGadgets();
8576 void FreeScreenGadgets(void)
8580 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8581 FreeGadget(screen_gadget[i]);
8584 void MapScreenMenuGadgets(int screen_mask)
8588 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8589 if (screen_mask & menubutton_info[i].screen_mask)
8590 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8593 static void UnmapScreenMenuGadgets(int screen_mask)
8597 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8599 if (screen_mask & menubutton_info[i].screen_mask)
8601 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8603 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8604 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8605 screen_gadget[menubutton_info[i].gadget_id]->y,
8606 screen_gadget[menubutton_info[i].gadget_id]->width,
8607 screen_gadget[menubutton_info[i].gadget_id]->height);
8612 void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8615 MapScreenMenuGadgets(screen_mask);
8617 UnmapScreenMenuGadgets(screen_mask);
8620 void MapScreenGadgets(int num_entries)
8624 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8627 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8628 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8630 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8631 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8634 void MapScreenTreeGadgets(TreeInfo *ti)
8636 MapScreenGadgets(numTreeInfoInGroup(ti));
8639 static void HandleScreenGadgets(struct GadgetInfo *gi)
8641 int id = gi->custom_id;
8642 int button = gi->event.button;
8643 int step = (button == MB_LEFTBUTTON ? 1 :
8644 button == MB_MIDDLEBUTTON ? 5 :
8645 button == MB_RIGHTBUTTON ? 10 : 1);
8649 case SCREEN_CTRL_ID_PREV_LEVEL:
8650 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8653 case SCREEN_CTRL_ID_NEXT_LEVEL:
8654 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8657 case SCREEN_CTRL_ID_PREV_PLAYER:
8658 HandleSetupScreen_Input_Player(step, -1);
8661 case SCREEN_CTRL_ID_NEXT_PLAYER:
8662 HandleSetupScreen_Input_Player(step, +1);
8665 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8666 InsertSolutionTape();
8669 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8673 case SCREEN_CTRL_ID_SCROLL_UP:
8674 if (game_status == GAME_MODE_LEVELS)
8675 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8676 else if (game_status == GAME_MODE_LEVELNR)
8677 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8678 else if (game_status == GAME_MODE_SETUP)
8679 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8680 else if (game_status == GAME_MODE_INFO)
8681 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8684 case SCREEN_CTRL_ID_SCROLL_DOWN:
8685 if (game_status == GAME_MODE_LEVELS)
8686 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8687 else if (game_status == GAME_MODE_LEVELNR)
8688 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8689 else if (game_status == GAME_MODE_SETUP)
8690 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8691 else if (game_status == GAME_MODE_INFO)
8692 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8695 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8696 if (game_status == GAME_MODE_LEVELS)
8697 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8698 else if (game_status == GAME_MODE_LEVELNR)
8699 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8700 else if (game_status == GAME_MODE_SETUP)
8701 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8702 else if (game_status == GAME_MODE_INFO)
8703 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8706 case SCREEN_CTRL_ID_NETWORK_SERVER:
8708 if (!strEqual(gi->textinput.value, ""))
8710 setString(&setup.network_server_hostname, gi->textinput.value);
8712 network.server_host = setup.network_server_hostname;
8716 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
8718 network.server_host = NULL;
8721 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
8722 network.server_host = NULL;
8724 execSetupGame_setNetworkServerText();
8736 void DumpScreenIdentifiers(void)
8740 Print("Active screen elements on current screen:\n");
8742 for (i = 0; main_controls[i].nr != -1; i++)
8744 struct MainControlInfo *mci = &main_controls[i];
8746 if (mci->button_graphic != -1)
8748 char *token = getTokenFromImageID(mci->button_graphic);
8750 Print("- '%s'\n", token);
8757 boolean DoScreenAction(int image_id)
8761 if (game_status != GAME_MODE_MAIN)
8764 for (i = 0; main_controls[i].nr != -1; i++)
8766 struct MainControlInfo *mci = &main_controls[i];
8767 struct MenuPosInfo *pos = mci->pos_button;
8769 if (mci->button_graphic == image_id)
8771 int x = mSX + pos->x;
8772 int y = mSY + pos->y;
8774 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);